]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | |
2 | /****************************************************************************** | |
3 | * | |
4 | * Module Name: exoparg3 - AML execution - opcodes with 3 arguments | |
5 | * | |
6 | *****************************************************************************/ | |
7 | ||
8 | /* | |
9 | * Copyright (C) 2000 - 2005, R. Byron Moore | |
10 | * All rights reserved. | |
11 | * | |
12 | * Redistribution and use in source and binary forms, with or without | |
13 | * modification, are permitted provided that the following conditions | |
14 | * are met: | |
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. | |
26 | * | |
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. | |
30 | * | |
31 | * NO WARRANTY | |
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. | |
43 | */ | |
44 | ||
45 | ||
46 | #include <acpi/acpi.h> | |
47 | #include <acpi/acinterp.h> | |
48 | #include <acpi/acparser.h> | |
49 | #include <acpi/amlcode.h> | |
50 | ||
51 | ||
52 | #define _COMPONENT ACPI_EXECUTER | |
53 | ACPI_MODULE_NAME ("exoparg3") | |
54 | ||
55 | ||
56 | /*! | |
57 | * Naming convention for AML interpreter execution routines. | |
58 | * | |
59 | * The routines that begin execution of AML opcodes are named with a common | |
60 | * convention based upon the number of arguments, the number of target operands, | |
61 | * and whether or not a value is returned: | |
62 | * | |
63 | * AcpiExOpcode_xA_yT_zR | |
64 | * | |
65 | * Where: | |
66 | * | |
67 | * xA - ARGUMENTS: The number of arguments (input operands) that are | |
68 | * required for this opcode type (1 through 6 args). | |
69 | * yT - TARGETS: The number of targets (output operands) that are required | |
70 | * for this opcode type (0, 1, or 2 targets). | |
71 | * zR - RETURN VALUE: Indicates whether this opcode type returns a value | |
72 | * as the function return (0 or 1). | |
73 | * | |
74 | * The AcpiExOpcode* functions are called via the Dispatcher component with | |
75 | * fully resolved operands. | |
76 | !*/ | |
77 | ||
78 | ||
79 | /******************************************************************************* | |
80 | * | |
81 | * FUNCTION: acpi_ex_opcode_3A_0T_0R | |
82 | * | |
83 | * PARAMETERS: walk_state - Current walk state | |
84 | * | |
85 | * RETURN: Status | |
86 | * | |
87 | * DESCRIPTION: Execute Triadic operator (3 operands) | |
88 | * | |
89 | ******************************************************************************/ | |
90 | ||
91 | acpi_status | |
92 | acpi_ex_opcode_3A_0T_0R ( | |
93 | struct acpi_walk_state *walk_state) | |
94 | { | |
95 | union acpi_operand_object **operand = &walk_state->operands[0]; | |
96 | struct acpi_signal_fatal_info *fatal; | |
97 | acpi_status status = AE_OK; | |
98 | ||
99 | ||
100 | ACPI_FUNCTION_TRACE_STR ("ex_opcode_3A_0T_0R", acpi_ps_get_opcode_name (walk_state->opcode)); | |
101 | ||
102 | ||
103 | switch (walk_state->opcode) { | |
104 | case AML_FATAL_OP: /* Fatal (fatal_type fatal_code fatal_arg) */ | |
105 | ||
106 | ACPI_DEBUG_PRINT ((ACPI_DB_INFO, | |
107 | "fatal_op: Type %X Code %X Arg %X <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n", | |
108 | (u32) operand[0]->integer.value, | |
109 | (u32) operand[1]->integer.value, | |
110 | (u32) operand[2]->integer.value)); | |
111 | ||
112 | fatal = ACPI_MEM_ALLOCATE (sizeof (struct acpi_signal_fatal_info)); | |
113 | if (fatal) { | |
114 | fatal->type = (u32) operand[0]->integer.value; | |
115 | fatal->code = (u32) operand[1]->integer.value; | |
116 | fatal->argument = (u32) operand[2]->integer.value; | |
117 | } | |
118 | ||
119 | /* | |
120 | * Always signal the OS! | |
121 | */ | |
122 | status = acpi_os_signal (ACPI_SIGNAL_FATAL, fatal); | |
123 | ||
124 | /* Might return while OS is shutting down, just continue */ | |
125 | ||
126 | ACPI_MEM_FREE (fatal); | |
127 | break; | |
128 | ||
129 | ||
130 | default: | |
131 | ||
132 | ACPI_REPORT_ERROR (("acpi_ex_opcode_3A_0T_0R: Unknown opcode %X\n", | |
133 | walk_state->opcode)); | |
134 | status = AE_AML_BAD_OPCODE; | |
135 | goto cleanup; | |
136 | } | |
137 | ||
138 | ||
139 | cleanup: | |
140 | ||
141 | return_ACPI_STATUS (status); | |
142 | } | |
143 | ||
144 | ||
145 | /******************************************************************************* | |
146 | * | |
147 | * FUNCTION: acpi_ex_opcode_3A_1T_1R | |
148 | * | |
149 | * PARAMETERS: walk_state - Current walk state | |
150 | * | |
151 | * RETURN: Status | |
152 | * | |
153 | * DESCRIPTION: Execute Triadic operator (3 operands) | |
154 | * | |
155 | ******************************************************************************/ | |
156 | ||
157 | acpi_status | |
158 | acpi_ex_opcode_3A_1T_1R ( | |
159 | struct acpi_walk_state *walk_state) | |
160 | { | |
161 | union acpi_operand_object **operand = &walk_state->operands[0]; | |
162 | union acpi_operand_object *return_desc = NULL; | |
163 | char *buffer; | |
164 | acpi_status status = AE_OK; | |
165 | acpi_native_uint index; | |
166 | acpi_size length; | |
167 | ||
168 | ||
169 | ACPI_FUNCTION_TRACE_STR ("ex_opcode_3A_1T_1R", acpi_ps_get_opcode_name (walk_state->opcode)); | |
170 | ||
171 | ||
172 | switch (walk_state->opcode) { | |
173 | case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */ | |
174 | ||
175 | /* | |
176 | * Create the return object. The Source operand is guaranteed to be | |
177 | * either a String or a Buffer, so just use its type. | |
178 | */ | |
179 | return_desc = acpi_ut_create_internal_object (ACPI_GET_OBJECT_TYPE (operand[0])); | |
180 | if (!return_desc) { | |
181 | status = AE_NO_MEMORY; | |
182 | goto cleanup; | |
183 | } | |
184 | ||
185 | /* Get the Integer values from the objects */ | |
186 | ||
187 | index = (acpi_native_uint) operand[1]->integer.value; | |
188 | length = (acpi_size) operand[2]->integer.value; | |
189 | ||
190 | /* | |
191 | * If the index is beyond the length of the String/Buffer, or if the | |
192 | * requested length is zero, return a zero-length String/Buffer | |
193 | */ | |
194 | if ((index < operand[0]->string.length) && | |
195 | (length > 0)) { | |
196 | /* Truncate request if larger than the actual String/Buffer */ | |
197 | ||
198 | if ((index + length) > | |
199 | operand[0]->string.length) { | |
200 | length = (acpi_size) operand[0]->string.length - index; | |
201 | } | |
202 | ||
203 | /* Allocate a new buffer for the String/Buffer */ | |
204 | ||
205 | buffer = ACPI_MEM_CALLOCATE ((acpi_size) length + 1); | |
206 | if (!buffer) { | |
207 | status = AE_NO_MEMORY; | |
208 | goto cleanup; | |
209 | } | |
210 | ||
211 | /* Copy the portion requested */ | |
212 | ||
213 | ACPI_MEMCPY (buffer, operand[0]->string.pointer + index, | |
214 | length); | |
215 | ||
216 | /* Set the length of the new String/Buffer */ | |
217 | ||
218 | return_desc->string.pointer = buffer; | |
219 | return_desc->string.length = (u32) length; | |
220 | } | |
221 | ||
222 | /* Mark buffer initialized */ | |
223 | ||
224 | return_desc->buffer.flags |= AOPOBJ_DATA_VALID; | |
225 | break; | |
226 | ||
227 | ||
228 | default: | |
229 | ||
230 | ACPI_REPORT_ERROR (("acpi_ex_opcode_3A_0T_0R: Unknown opcode %X\n", | |
231 | walk_state->opcode)); | |
232 | status = AE_AML_BAD_OPCODE; | |
233 | goto cleanup; | |
234 | } | |
235 | ||
236 | /* Store the result in the target */ | |
237 | ||
238 | status = acpi_ex_store (return_desc, operand[3], walk_state); | |
239 | ||
240 | cleanup: | |
241 | ||
242 | /* Delete return object on error */ | |
243 | ||
244 | if (ACPI_FAILURE (status)) { | |
245 | acpi_ut_remove_reference (return_desc); | |
246 | } | |
247 | ||
248 | /* Set the return object and exit */ | |
249 | ||
250 | if (!walk_state->result_obj) { | |
251 | walk_state->result_obj = return_desc; | |
252 | } | |
253 | return_ACPI_STATUS (status); | |
254 | } | |
255 | ||
256 |