1
2
3
4
5
6
7
8
9
10#include <acpi/acpi.h>
11#include "accommon.h"
12#include "acinterp.h"
13#include "amlcode.h"
14
15#define _COMPONENT ACPI_EXECUTER
16ACPI_MODULE_NAME("exmisc")
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32acpi_status
33acpi_ex_get_object_reference(union acpi_operand_object *obj_desc,
34 union acpi_operand_object **return_desc,
35 struct acpi_walk_state *walk_state)
36{
37 union acpi_operand_object *reference_obj;
38 union acpi_operand_object *referenced_obj;
39
40 ACPI_FUNCTION_TRACE_PTR(ex_get_object_reference, obj_desc);
41
42 *return_desc = NULL;
43
44 switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
45 case ACPI_DESC_TYPE_OPERAND:
46
47 if (obj_desc->common.type != ACPI_TYPE_LOCAL_REFERENCE) {
48 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
49 }
50
51
52
53
54 switch (obj_desc->reference.class) {
55 case ACPI_REFCLASS_LOCAL:
56 case ACPI_REFCLASS_ARG:
57 case ACPI_REFCLASS_DEBUG:
58
59
60
61 referenced_obj = obj_desc->reference.object;
62 break;
63
64 default:
65
66 ACPI_ERROR((AE_INFO, "Invalid Reference Class 0x%2.2X",
67 obj_desc->reference.class));
68 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
69 }
70 break;
71
72 case ACPI_DESC_TYPE_NAMED:
73
74
75
76 referenced_obj = obj_desc;
77 break;
78
79 default:
80
81 ACPI_ERROR((AE_INFO, "Invalid descriptor type 0x%X",
82 ACPI_GET_DESCRIPTOR_TYPE(obj_desc)));
83 return_ACPI_STATUS(AE_TYPE);
84 }
85
86
87
88 reference_obj =
89 acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_REFERENCE);
90 if (!reference_obj) {
91 return_ACPI_STATUS(AE_NO_MEMORY);
92 }
93
94 reference_obj->reference.class = ACPI_REFCLASS_REFOF;
95 reference_obj->reference.object = referenced_obj;
96 *return_desc = reference_obj;
97
98 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
99 "Object %p Type [%s], returning Reference %p\n",
100 obj_desc, acpi_ut_get_object_type_name(obj_desc),
101 *return_desc));
102
103 return_ACPI_STATUS(AE_OK);
104}
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122u64 acpi_ex_do_math_op(u16 opcode, u64 integer0, u64 integer1)
123{
124
125 ACPI_FUNCTION_ENTRY();
126
127 switch (opcode) {
128 case AML_ADD_OP:
129
130 return (integer0 + integer1);
131
132 case AML_BIT_AND_OP:
133
134 return (integer0 & integer1);
135
136 case AML_BIT_NAND_OP:
137
138 return (~(integer0 & integer1));
139
140 case AML_BIT_OR_OP:
141
142 return (integer0 | integer1);
143
144 case AML_BIT_NOR_OP:
145
146 return (~(integer0 | integer1));
147
148 case AML_BIT_XOR_OP:
149
150 return (integer0 ^ integer1);
151
152 case AML_MULTIPLY_OP:
153
154 return (integer0 * integer1);
155
156 case AML_SHIFT_LEFT_OP:
157
158
159
160
161
162 if (integer1 >= acpi_gbl_integer_bit_width) {
163 return (0);
164 }
165 return (integer0 << integer1);
166
167 case AML_SHIFT_RIGHT_OP:
168
169
170
171
172
173 if (integer1 >= acpi_gbl_integer_bit_width) {
174 return (0);
175 }
176 return (integer0 >> integer1);
177
178 case AML_SUBTRACT_OP:
179
180 return (integer0 - integer1);
181
182 default:
183
184 return (0);
185 }
186}
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208acpi_status
209acpi_ex_do_logical_numeric_op(u16 opcode,
210 u64 integer0, u64 integer1, u8 *logical_result)
211{
212 acpi_status status = AE_OK;
213 u8 local_result = FALSE;
214
215 ACPI_FUNCTION_TRACE(ex_do_logical_numeric_op);
216
217 switch (opcode) {
218 case AML_LOGICAL_AND_OP:
219
220 if (integer0 && integer1) {
221 local_result = TRUE;
222 }
223 break;
224
225 case AML_LOGICAL_OR_OP:
226
227 if (integer0 || integer1) {
228 local_result = TRUE;
229 }
230 break;
231
232 default:
233
234 ACPI_ERROR((AE_INFO,
235 "Invalid numeric logical opcode: %X", opcode));
236 status = AE_AML_INTERNAL;
237 break;
238 }
239
240
241
242 *logical_result = local_result;
243 return_ACPI_STATUS(status);
244}
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272acpi_status
273acpi_ex_do_logical_op(u16 opcode,
274 union acpi_operand_object *operand0,
275 union acpi_operand_object *operand1, u8 * logical_result)
276{
277 union acpi_operand_object *local_operand1 = operand1;
278 u64 integer0;
279 u64 integer1;
280 u32 length0;
281 u32 length1;
282 acpi_status status = AE_OK;
283 u8 local_result = FALSE;
284 int compare;
285
286 ACPI_FUNCTION_TRACE(ex_do_logical_op);
287
288
289
290
291
292
293
294
295 switch (operand0->common.type) {
296 case ACPI_TYPE_INTEGER:
297
298 status = acpi_ex_convert_to_integer(operand1, &local_operand1,
299 ACPI_IMPLICIT_CONVERSION);
300 break;
301
302 case ACPI_TYPE_STRING:
303
304 status =
305 acpi_ex_convert_to_string(operand1, &local_operand1,
306 ACPI_IMPLICIT_CONVERT_HEX);
307 break;
308
309 case ACPI_TYPE_BUFFER:
310
311 status = acpi_ex_convert_to_buffer(operand1, &local_operand1);
312 break;
313
314 default:
315
316 ACPI_ERROR((AE_INFO,
317 "Invalid object type for logical operator: %X",
318 operand0->common.type));
319 status = AE_AML_INTERNAL;
320 break;
321 }
322
323 if (ACPI_FAILURE(status)) {
324 goto cleanup;
325 }
326
327
328
329
330 if (operand0->common.type == ACPI_TYPE_INTEGER) {
331
332
333
334
335 integer0 = operand0->integer.value;
336 integer1 = local_operand1->integer.value;
337
338 switch (opcode) {
339 case AML_LOGICAL_EQUAL_OP:
340
341 if (integer0 == integer1) {
342 local_result = TRUE;
343 }
344 break;
345
346 case AML_LOGICAL_GREATER_OP:
347
348 if (integer0 > integer1) {
349 local_result = TRUE;
350 }
351 break;
352
353 case AML_LOGICAL_LESS_OP:
354
355 if (integer0 < integer1) {
356 local_result = TRUE;
357 }
358 break;
359
360 default:
361
362 ACPI_ERROR((AE_INFO,
363 "Invalid comparison opcode: %X", opcode));
364 status = AE_AML_INTERNAL;
365 break;
366 }
367 } else {
368
369
370
371
372
373
374 length0 = operand0->buffer.length;
375 length1 = local_operand1->buffer.length;
376
377
378
379 compare = memcmp(operand0->buffer.pointer,
380 local_operand1->buffer.pointer,
381 (length0 > length1) ? length1 : length0);
382
383 switch (opcode) {
384 case AML_LOGICAL_EQUAL_OP:
385
386
387
388 if ((length0 == length1) && (compare == 0)) {
389
390
391
392 local_result = TRUE;
393 }
394 break;
395
396 case AML_LOGICAL_GREATER_OP:
397
398 if (compare > 0) {
399 local_result = TRUE;
400 goto cleanup;
401 }
402 if (compare < 0) {
403 goto cleanup;
404 }
405
406
407
408 if (length0 > length1) {
409 local_result = TRUE;
410 }
411 break;
412
413 case AML_LOGICAL_LESS_OP:
414
415 if (compare > 0) {
416 goto cleanup;
417 }
418 if (compare < 0) {
419 local_result = TRUE;
420 goto cleanup;
421 }
422
423
424
425 if (length0 < length1) {
426 local_result = TRUE;
427 }
428 break;
429
430 default:
431
432 ACPI_ERROR((AE_INFO,
433 "Invalid comparison opcode: %X", opcode));
434 status = AE_AML_INTERNAL;
435 break;
436 }
437 }
438
439cleanup:
440
441
442
443 if (local_operand1 != operand1) {
444 acpi_ut_remove_reference(local_operand1);
445 }
446
447
448
449 *logical_result = local_result;
450 return_ACPI_STATUS(status);
451}
452