2 /******************************************************************************
4 * Module Name: exstorob - AML Interpreter object store support, store to object
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2004, R. Byron Moore
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
46 #include <acpi/acpi.h>
47 #include <acpi/acinterp.h>
50 #define _COMPONENT ACPI_EXECUTER
51 ACPI_MODULE_NAME ("exstorob")
54 /*******************************************************************************
56 * FUNCTION: acpi_ex_store_buffer_to_buffer
58 * PARAMETERS: source_desc - Source object to copy
59 * target_desc - Destination object of the copy
63 * DESCRIPTION: Copy a buffer object to another buffer object.
65 ******************************************************************************/
68 acpi_ex_store_buffer_to_buffer (
69 union acpi_operand_object
*source_desc
,
70 union acpi_operand_object
*target_desc
)
76 ACPI_FUNCTION_TRACE_PTR ("ex_store_buffer_to_buffer", source_desc
);
80 * We know that source_desc is a buffer by now
82 buffer
= (u8
*) source_desc
->buffer
.pointer
;
83 length
= source_desc
->buffer
.length
;
86 * If target is a buffer of length zero or is a static buffer,
87 * allocate a new buffer of the proper length
89 if ((target_desc
->buffer
.length
== 0) ||
90 (target_desc
->common
.flags
& AOPOBJ_STATIC_POINTER
)) {
91 target_desc
->buffer
.pointer
= ACPI_MEM_ALLOCATE (length
);
92 if (!target_desc
->buffer
.pointer
) {
93 return_ACPI_STATUS (AE_NO_MEMORY
);
96 target_desc
->common
.flags
&= ~AOPOBJ_STATIC_POINTER
;
97 target_desc
->buffer
.length
= length
;
101 * Buffer is a static allocation,
102 * only place what will fit in the buffer.
104 if (length
<= target_desc
->buffer
.length
) {
105 /* Clear existing buffer and copy in the new one */
107 ACPI_MEMSET (target_desc
->buffer
.pointer
, 0, target_desc
->buffer
.length
);
108 ACPI_MEMCPY (target_desc
->buffer
.pointer
, buffer
, length
);
112 * Truncate the source, copy only what will fit
114 ACPI_MEMCPY (target_desc
->buffer
.pointer
, buffer
, target_desc
->buffer
.length
);
116 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
117 "Truncating src buffer from %X to %X\n",
118 length
, target_desc
->buffer
.length
));
123 target_desc
->buffer
.flags
= source_desc
->buffer
.flags
;
124 return_ACPI_STATUS (AE_OK
);
128 /*******************************************************************************
130 * FUNCTION: acpi_ex_store_string_to_string
132 * PARAMETERS: source_desc - Source object to copy
133 * target_desc - Destination object of the copy
137 * DESCRIPTION: Copy a String object to another String object
139 ******************************************************************************/
142 acpi_ex_store_string_to_string (
143 union acpi_operand_object
*source_desc
,
144 union acpi_operand_object
*target_desc
)
150 ACPI_FUNCTION_TRACE_PTR ("ex_store_string_to_string", source_desc
);
154 * We know that source_desc is a string by now.
156 buffer
= (u8
*) source_desc
->string
.pointer
;
157 length
= source_desc
->string
.length
;
160 * Replace existing string value if it will fit and the string
161 * pointer is not a static pointer (part of an ACPI table)
163 if ((length
< target_desc
->string
.length
) &&
164 (!(target_desc
->common
.flags
& AOPOBJ_STATIC_POINTER
))) {
166 * String will fit in existing non-static buffer.
167 * Clear old string and copy in the new one
169 ACPI_MEMSET (target_desc
->string
.pointer
, 0, (acpi_size
) target_desc
->string
.length
+ 1);
170 ACPI_MEMCPY (target_desc
->string
.pointer
, buffer
, length
);
174 * Free the current buffer, then allocate a new buffer
175 * large enough to hold the value
177 if (target_desc
->string
.pointer
&&
178 (!(target_desc
->common
.flags
& AOPOBJ_STATIC_POINTER
))) {
180 * Only free if not a pointer into the DSDT
182 ACPI_MEM_FREE (target_desc
->string
.pointer
);
185 target_desc
->string
.pointer
= ACPI_MEM_CALLOCATE ((acpi_size
) length
+ 1);
186 if (!target_desc
->string
.pointer
) {
187 return_ACPI_STATUS (AE_NO_MEMORY
);
190 target_desc
->common
.flags
&= ~AOPOBJ_STATIC_POINTER
;
191 ACPI_MEMCPY (target_desc
->string
.pointer
, buffer
, length
);
194 /* Set the new target length */
196 target_desc
->string
.length
= length
;
197 return_ACPI_STATUS (AE_OK
);