Debian Codegraph @

source/components/executer/exoparg2.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /******************************************************************************
2 *
3 * Module Name: exoparg2 - AML execution - opcodes with 2 arguments
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2026, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44 #include "acpi.h"
45 #include "accommon.h"
46 #include "acparser.h"
47 #include "acinterp.h"
48 #include "acevents.h"
49 #include "amlcode.h"
50
51
52 #define _COMPONENT ACPI_EXECUTER
53 ACPI_MODULE_NAME ("exoparg2")
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: AcpiExOpcode_2A_0T_0R
82 *
83 * PARAMETERS: WalkState - Current walk state
84 *
85 * RETURN: Status
86 *
87 * DESCRIPTION: Execute opcode with two arguments, no target, and no return
88 * value.
89 *
90 * ALLOCATION: Deletes both operands
91 *
92 ******************************************************************************/
93
94 ACPI_STATUS
95 AcpiExOpcode_2A_0T_0R (
96 ACPI_WALK_STATE *WalkState)
97 {
98 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
99 ACPI_NAMESPACE_NODE *Node;
100 UINT32 Value;
101 ACPI_STATUS Status = AE_OK;
102
103
104 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_0T_0R,
105 AcpiPsGetOpcodeName (WalkState->Opcode));
106
107
108 /* Examine the opcode */
109
110 switch (WalkState->Opcode)
111 {
112 case AML_NOTIFY_OP: /* Notify (NotifyObject, NotifyValue) */
113
114 /* The first operand is a namespace node */
115
116 Node = (ACPI_NAMESPACE_NODE *) Operand[0];
117
118 /* Second value is the notify value */
119
120 Value = (UINT32) Operand[1]->Integer.Value;
121
122 /* Are notifies allowed on this object? */
123
124 if (!AcpiEvIsNotifyObject (Node))
125 {
126 ACPI_ERROR ((AE_INFO,
127 "Unexpected notify object type [%s]",
128 AcpiUtGetTypeName (Node->Type)));
129
130 Status = AE_AML_OPERAND_TYPE;
131 break;
132 }
133
134 /*
135 * Dispatch the notify to the appropriate handler
136 * NOTE: the request is queued for execution after this method
137 * completes. The notify handlers are NOT invoked synchronously
138 * from this thread -- because handlers may in turn run other
139 * control methods.
140 */
141 Status = AcpiEvQueueNotifyRequest (Node, Value);
142 break;
143
144 default:
145
146 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
147 WalkState->Opcode));
148 Status = AE_AML_BAD_OPCODE;
149 }
150
151 return_ACPI_STATUS (Status);
152 }
153
154
155 /*******************************************************************************
156 *
157 * FUNCTION: AcpiExOpcode_2A_2T_1R
158 *
159 * PARAMETERS: WalkState - Current walk state
160 *
161 * RETURN: Status
162 *
163 * DESCRIPTION: Execute a dyadic operator (2 operands) with 2 output targets
164 * and one implicit return value.
165 *
166 ******************************************************************************/
167
168 ACPI_STATUS
169 AcpiExOpcode_2A_2T_1R (
170 ACPI_WALK_STATE *WalkState)
171 {
172 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
173 ACPI_OPERAND_OBJECT *ReturnDesc1 = NULL;
174 ACPI_OPERAND_OBJECT *ReturnDesc2 = NULL;
•175 UINT64 ReturnValue1 = 0;
176 UINT64 ReturnValue2 = 0;
177 ACPI_STATUS Status;
178
179
180 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_2T_1R,
181 AcpiPsGetOpcodeName (WalkState->Opcode));
182
183
184 /* Execute the opcode */
185
186 switch (WalkState->Opcode)
187 {
188 case AML_DIVIDE_OP:
189
190 /* Divide (Dividend, Divisor, RemainderResult QuotientResult) */
191
192 ReturnDesc1 = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
193 if (!ReturnDesc1)
194 {
195 Status = AE_NO_MEMORY;
196 goto Cleanup;
197 }
198
199 ReturnDesc2 = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
200 if (!ReturnDesc2)
201 {
202 Status = AE_NO_MEMORY;
203 goto Cleanup;
204 }
205
206 /* Quotient to ReturnDesc1, remainder to ReturnDesc2 */
207
208 Status = AcpiUtDivide (
209 Operand[0]->Integer.Value,
210 Operand[1]->Integer.Value,
•211 &ReturnValue1, &ReturnValue2);
212 ReturnDesc1->Integer.Value = ReturnValue1;
213 ReturnDesc2->Integer.Value = ReturnValue2;
214
215 if (ACPI_FAILURE (Status))
216 {
217 goto Cleanup;
218 }
219 break;
220
221 default:
222
223 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
224 WalkState->Opcode));
225
226 Status = AE_AML_BAD_OPCODE;
227 goto Cleanup;
228 }
229
230 /* Store the results to the target reference operands */
231
232 Status = AcpiExStore (ReturnDesc2, Operand[2], WalkState);
233 if (ACPI_FAILURE (Status))
234 {
235 goto Cleanup;
236 }
237
238 Status = AcpiExStore (ReturnDesc1, Operand[3], WalkState);
239 if (ACPI_FAILURE (Status))
240 {
241 goto Cleanup;
242 }
243
244 Cleanup:
245 /*
246 * Since the remainder is not returned indirectly, remove a reference to
247 * it. Only the quotient is returned indirectly.
248 */
249 AcpiUtRemoveReference (ReturnDesc2);
250
251 if (ACPI_FAILURE (Status))
252 {
253 /* Delete the return object */
254
255 AcpiUtRemoveReference (ReturnDesc1);
256 }
257
258 /* Save return object (the remainder) on success */
259
260 else
261 {
262 WalkState->ResultObj = ReturnDesc1;
263 }
264
265 return_ACPI_STATUS (Status);
266 }
267
268
269 /*******************************************************************************
270 *
271 * FUNCTION: AcpiExOpcode_2A_1T_1R
272 *
273 * PARAMETERS: WalkState - Current walk state
274 *
275 * RETURN: Status
276 *
277 * DESCRIPTION: Execute opcode with two arguments, one target, and a return
278 * value.
279 *
280 ******************************************************************************/
281
282 ACPI_STATUS
283 AcpiExOpcode_2A_1T_1R (
284 ACPI_WALK_STATE *WalkState)
285 {
286 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
287 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
288 UINT64 Index;
•289 UINT64 ReturnValue = 0;
290 ACPI_STATUS Status = AE_OK;
291 ACPI_SIZE Length = 0;
292
293
294 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_1T_1R,
295 AcpiPsGetOpcodeName (WalkState->Opcode));
296
297
298 /* Execute the opcode */
299
300 if (WalkState->OpInfo->Flags & AML_MATH)
301 {
302 /* All simple math opcodes (add, etc.) */
303
304 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
305 if (!ReturnDesc)
306 {
307 Status = AE_NO_MEMORY;
308 goto Cleanup;
309 }
310
311 ReturnDesc->Integer.Value = AcpiExDoMathOp (
312 WalkState->Opcode,
313 Operand[0]->Integer.Value,
314 Operand[1]->Integer.Value);
315 goto StoreResultToTarget;
316 }
317
318 switch (WalkState->Opcode)
319 {
320 case AML_MOD_OP: /* Mod (Dividend, Divisor, RemainderResult (ACPI 2.0) */
321
322 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
323 if (!ReturnDesc)
324 {
325 Status = AE_NO_MEMORY;
326 goto Cleanup;
327 }
328
329 /* ReturnDesc will contain the remainder */
330
331 Status = AcpiUtDivide (
332 Operand[0]->Integer.Value,
333 Operand[1]->Integer.Value,
334 NULL,
•335 &ReturnValue);
336 ReturnDesc->Integer.Value = ReturnValue;
337 break;
338
339 case AML_CONCATENATE_OP: /* Concatenate (Data1, Data2, Result) */
340
341 Status = AcpiExDoConcatenate (
342 Operand[0], Operand[1], &ReturnDesc, WalkState);
343 break;
344
345 case AML_TO_STRING_OP: /* ToString (Buffer, Length, Result) (ACPI 2.0) */
346 /*
347 * Input object is guaranteed to be a buffer at this point (it may have
348 * been converted.) Copy the raw buffer data to a new object of
349 * type String.
350 */
351
352 /*
353 * Get the length of the new string. It is the smallest of:
354 * 1) Length of the input buffer
355 * 2) Max length as specified in the ToString operator
356 * 3) Length of input buffer up to a zero byte (null terminator)
357 *
358 * NOTE: A length of zero is ok, and will create a zero-length, null
359 * terminated string.
360 */
361 while ((Length < Operand[0]->Buffer.Length) && /* Length of input buffer */
362 (Length < Operand[1]->Integer.Value) && /* Length operand */
363 (Operand[0]->Buffer.Pointer[Length])) /* Null terminator */
364 {
365 Length++;
366 }
367
368 /* Allocate a new string object */
369
370 ReturnDesc = AcpiUtCreateStringObject (Length);
371 if (!ReturnDesc)
372 {
373 Status = AE_NO_MEMORY;
374 goto Cleanup;
375 }
376
377 /*
378 * Copy the raw buffer data with no transform.
379 * (NULL terminated already)
380 */
381 memcpy (ReturnDesc->String.Pointer,
382 Operand[0]->Buffer.Pointer, Length);
383 break;
384
385 case AML_CONCATENATE_TEMPLATE_OP:
386
387 /* ConcatenateResTemplate (Buffer, Buffer, Result) (ACPI 2.0) */
388
389 Status = AcpiExConcatTemplate (
390 Operand[0], Operand[1], &ReturnDesc, WalkState);
391 break;
392
393 case AML_INDEX_OP: /* Index (Source Index Result) */
394
395 /* Create the internal return object */
396
397 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
398 if (!ReturnDesc)
399 {
400 Status = AE_NO_MEMORY;
401 goto Cleanup;
402 }
403
404 /* Initialize the Index reference object */
405
406 Index = Operand[1]->Integer.Value;
407 ReturnDesc->Reference.Value = (UINT32) Index;
408 ReturnDesc->Reference.Class = ACPI_REFCLASS_INDEX;
409
410 /*
411 * At this point, the Source operand is a String, Buffer, or Package.
412 * Verify that the index is within range.
413 */
414 switch ((Operand[0])->Common.Type)
415 {
416 case ACPI_TYPE_STRING:
417
418 if (Index >= Operand[0]->String.Length)
419 {
420 Length = Operand[0]->String.Length;
421 Status = AE_AML_STRING_LIMIT;
422 }
423
424 ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
425 ReturnDesc->Reference.IndexPointer =
426 &(Operand[0]->Buffer.Pointer [Index]);
427 break;
428
429 case ACPI_TYPE_BUFFER:
430
431 if (Index >= Operand[0]->Buffer.Length)
432 {
433 Length = Operand[0]->Buffer.Length;
434 Status = AE_AML_BUFFER_LIMIT;
435 }
436
437 ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
438 ReturnDesc->Reference.IndexPointer =
439 &(Operand[0]->Buffer.Pointer [Index]);
440 break;
441
442 case ACPI_TYPE_PACKAGE:
443
444 if (Index >= Operand[0]->Package.Count)
445 {
446 Length = Operand[0]->Package.Count;
447 Status = AE_AML_PACKAGE_LIMIT;
448 }
449
450 ReturnDesc->Reference.TargetType = ACPI_TYPE_PACKAGE;
451 ReturnDesc->Reference.Where =
452 &Operand[0]->Package.Elements [Index];
453 break;
454
455 default:
456
457 ACPI_ERROR ((AE_INFO,
458 "Invalid object type: %X", (Operand[0])->Common.Type));
459 Status = AE_AML_INTERNAL;
460 goto Cleanup;
461 }
462
463 /* Failure means that the Index was beyond the end of the object */
464
465 if (ACPI_FAILURE (Status))
466 {
467 ACPI_BIOS_EXCEPTION ((AE_INFO, Status,
468 "Index (0x%X%8.8X) is beyond end of object (length 0x%X)",
469 ACPI_FORMAT_UINT64 (Index), (UINT32) Length));
470 goto Cleanup;
471 }
472
473 /*
474 * Save the target object and add a reference to it for the life
475 * of the index
476 */
477 ReturnDesc->Reference.Object = Operand[0];
478 AcpiUtAddReference (Operand[0]);
479
480 /* Store the reference to the Target */
481
482 Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
483
484 /* Return the reference */
485
486 WalkState->ResultObj = ReturnDesc;
487 goto Cleanup;
488
489 default:
490
491 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
492 WalkState->Opcode));
493 Status = AE_AML_BAD_OPCODE;
494 break;
495 }
496
497
498 StoreResultToTarget:
499
500 if (ACPI_SUCCESS (Status))
501 {
502 /*
503 * Store the result of the operation (which is now in ReturnDesc) into
504 * the Target descriptor.
505 */
506 Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
507 if (ACPI_FAILURE (Status))
508 {
509 goto Cleanup;
510 }
511
512 if (!WalkState->ResultObj)
513 {
514 WalkState->ResultObj = ReturnDesc;
515 }
516 }
517
518
519 Cleanup:
520
521 /* Delete return object on error */
522
523 if (ACPI_FAILURE (Status))
524 {
525 AcpiUtRemoveReference (ReturnDesc);
526 WalkState->ResultObj = NULL;
527 }
528
529 return_ACPI_STATUS (Status);
530 }
531
532
533 /*******************************************************************************
534 *
535 * FUNCTION: AcpiExOpcode_2A_0T_1R
536 *
537 * PARAMETERS: WalkState - Current walk state
538 *
539 * RETURN: Status
540 *
541 * DESCRIPTION: Execute opcode with 2 arguments, no target, and a return value
542 *
543 ******************************************************************************/
544
545 ACPI_STATUS
546 AcpiExOpcode_2A_0T_1R (
547 ACPI_WALK_STATE *WalkState)
548 {
549 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
550 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
551 ACPI_STATUS Status = AE_OK;
552 BOOLEAN LogicalResult = FALSE;
553
554
555 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_0T_1R,
556 AcpiPsGetOpcodeName (WalkState->Opcode));
557
558
559 /* Create the internal return object */
560
561 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
562 if (!ReturnDesc)
563 {
564 Status = AE_NO_MEMORY;
565 goto Cleanup;
566 }
567
568 /* Execute the Opcode */
569
570 if (WalkState->OpInfo->Flags & AML_LOGICAL_NUMERIC)
571 {
572 /* LogicalOp (Operand0, Operand1) */
573
574 Status = AcpiExDoLogicalNumericOp (WalkState->Opcode,
575 Operand[0]->Integer.Value, Operand[1]->Integer.Value,
576 &LogicalResult);
577 goto StoreLogicalResult;
578 }
579 else if (WalkState->OpInfo->Flags & AML_LOGICAL)
580 {
581 /* LogicalOp (Operand0, Operand1) */
582
583 Status = AcpiExDoLogicalOp (WalkState->Opcode, Operand[0],
584 Operand[1], &LogicalResult);
585 goto StoreLogicalResult;
586 }
587
588 switch (WalkState->Opcode)
589 {
590 case AML_ACQUIRE_OP: /* Acquire (MutexObject, Timeout) */
591
592 Status = AcpiExAcquireMutex (Operand[1], Operand[0], WalkState);
593 if (Status == AE_TIME)
594 {
595 LogicalResult = TRUE; /* TRUE = Acquire timed out */
596 Status = AE_OK;
597 }
598 break;
599
600
601 case AML_WAIT_OP: /* Wait (EventObject, Timeout) */
602
603 Status = AcpiExSystemWaitEvent (Operand[1], Operand[0]);
604 if (Status == AE_TIME)
605 {
606 LogicalResult = TRUE; /* TRUE, Wait timed out */
607 Status = AE_OK;
608 }
609 break;
610
611 default:
612
613 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
614 WalkState->Opcode));
615
616 Status = AE_AML_BAD_OPCODE;
617 goto Cleanup;
618 }
619
620
621 StoreLogicalResult:
622 /*
623 * Set return value to according to LogicalResult. logical TRUE (all ones)
624 * Default is FALSE (zero)
625 */
626 if (LogicalResult)
627 {
628 ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
629 }
630
631 Cleanup:
632
633 /* Delete return object on error */
634
635 if (ACPI_FAILURE (Status))
636 {
637 AcpiUtRemoveReference (ReturnDesc);
638 }
639
640 /* Save return object on success */
641
642 else
643 {
644 WalkState->ResultObj = ReturnDesc;
645 }
646
647 return_ACPI_STATUS (Status);
648 }