1
2 /******************************************************************************
3 *
4 * Module Name: exoparg6 - AML execution - opcodes with 6 arguments
5 *
6 *****************************************************************************/
7
8 /*
9 * Copyright (C) 2000 - 2004, 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 ("exoparg6")
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_do_match
82 *
83 * PARAMETERS: match_op - The AML match operand
84 * package_value - Value from the target package
85 * match_value - Value to be matched
86 *
87 * RETURN: TRUE if the match is successful, FALSE otherwise
88 *
89 * DESCRIPTION: Implements the low-level match for the ASL Match operator
90 *
91 ******************************************************************************/
92
93 u8
acpi_ex_do_match(u32 match_op,acpi_integer package_value,acpi_integer match_value)94 acpi_ex_do_match (
95 u32 match_op,
96 acpi_integer package_value,
97 acpi_integer match_value)
98 {
99
100 switch (match_op) {
101 case MATCH_MTR: /* always true */
102
103 break;
104
105
106 case MATCH_MEQ: /* true if equal */
107
108 if (package_value != match_value) {
109 return (FALSE);
110 }
111 break;
112
113
114 case MATCH_MLE: /* true if less than or equal */
115
116 if (package_value > match_value) {
117 return (FALSE);
118 }
119 break;
120
121
122 case MATCH_MLT: /* true if less than */
123
124 if (package_value >= match_value) {
125 return (FALSE);
126 }
127 break;
128
129
130 case MATCH_MGE: /* true if greater than or equal */
131
132 if (package_value < match_value) {
133 return (FALSE);
134 }
135 break;
136
137
138 case MATCH_MGT: /* true if greater than */
139
140 if (package_value <= match_value) {
141 return (FALSE);
142 }
143 break;
144
145
146 default: /* undefined */
147
148 return (FALSE);
149 }
150
151
152 return TRUE;
153 }
154
155
156 /*******************************************************************************
157 *
158 * FUNCTION: acpi_ex_opcode_6A_0T_1R
159 *
160 * PARAMETERS: walk_state - Current walk state
161 *
162 * RETURN: Status
163 *
164 * DESCRIPTION: Execute opcode with 6 arguments, no target, and a return value
165 *
166 ******************************************************************************/
167
168 acpi_status
acpi_ex_opcode_6A_0T_1R(struct acpi_walk_state * walk_state)169 acpi_ex_opcode_6A_0T_1R (
170 struct acpi_walk_state *walk_state)
171 {
172 union acpi_operand_object **operand = &walk_state->operands[0];
173 union acpi_operand_object *return_desc = NULL;
174 acpi_status status = AE_OK;
175 u32 index;
176 union acpi_operand_object *this_element;
177
178
179 ACPI_FUNCTION_TRACE_STR ("ex_opcode_6A_0T_1R", acpi_ps_get_opcode_name (walk_state->opcode));
180
181
182 switch (walk_state->opcode) {
183 case AML_MATCH_OP:
184 /*
185 * Match (search_package[0], match_op1[1], match_object1[2],
186 * match_op2[3], match_object2[4], start_index[5])
187 */
188
189 /* Validate match comparison sub-opcodes */
190
191 if ((operand[1]->integer.value > MAX_MATCH_OPERATOR) ||
192 (operand[3]->integer.value > MAX_MATCH_OPERATOR)) {
193 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "operation encoding out of range\n"));
194 status = AE_AML_OPERAND_VALUE;
195 goto cleanup;
196 }
197
198 index = (u32) operand[5]->integer.value;
199 if (index >= (u32) operand[0]->package.count) {
200 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Index beyond package end\n"));
201 status = AE_AML_PACKAGE_LIMIT;
202 goto cleanup;
203 }
204
205 return_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
206 if (!return_desc) {
207 status = AE_NO_MEMORY;
208 goto cleanup;
209
210 }
211
212 /* Default return value if no match found */
213
214 return_desc->integer.value = ACPI_INTEGER_MAX;
215
216 /*
217 * Examine each element until a match is found. Within the loop,
218 * "continue" signifies that the current element does not match
219 * and the next should be examined.
220 *
221 * Upon finding a match, the loop will terminate via "break" at
222 * the bottom. If it terminates "normally", match_value will be -1
223 * (its initial value) indicating that no match was found. When
224 * returned as a Number, this will produce the Ones value as specified.
225 */
226 for ( ; index < operand[0]->package.count; index++) {
227 this_element = operand[0]->package.elements[index];
228
229 /*
230 * Treat any NULL or non-numeric elements as non-matching.
231 */
232 if (!this_element ||
233 ACPI_GET_OBJECT_TYPE (this_element) != ACPI_TYPE_INTEGER) {
234 continue;
235 }
236
237 /*
238 * "continue" (proceed to next iteration of enclosing
239 * "for" loop) signifies a non-match.
240 */
241 if (!acpi_ex_do_match ((u32) operand[1]->integer.value,
242 this_element->integer.value, operand[2]->integer.value)) {
243 continue;
244 }
245
246 if (!acpi_ex_do_match ((u32) operand[3]->integer.value,
247 this_element->integer.value, operand[4]->integer.value)) {
248 continue;
249 }
250
251 /* Match found: Index is the return value */
252
253 return_desc->integer.value = index;
254 break;
255 }
256
257 break;
258
259
260 case AML_LOAD_TABLE_OP:
261
262 status = acpi_ex_load_table_op (walk_state, &return_desc);
263 break;
264
265
266 default:
267
268 ACPI_REPORT_ERROR (("acpi_ex_opcode_3A_0T_0R: Unknown opcode %X\n",
269 walk_state->opcode));
270 status = AE_AML_BAD_OPCODE;
271 goto cleanup;
272 }
273
274
275 walk_state->result_obj = return_desc;
276
277
278 cleanup:
279
280 /* Delete return object on error */
281
282 if (ACPI_FAILURE (status)) {
283 acpi_ut_remove_reference (return_desc);
284 }
285
286 return_ACPI_STATUS (status);
287 }
288