2 /******************************************************************************
4 * Module Name: exoparg1 - AML execution - opcodes with 1 argument
7 *****************************************************************************/
10 * Copyright (C) 2000 - 2002, R. Byron Moore
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 #define _COMPONENT ACPI_EXECUTER
37 ACPI_MODULE_NAME ("exoparg1")
41 * Naming convention for AML interpreter execution routines.
43 * The routines that begin execution of AML opcodes are named with a common
44 * convention based upon the number of arguments, the number of target operands,
45 * and whether or not a value is returned:
47 * AcpiExOpcode_xA_yT_zR
51 * xA - ARGUMENTS: The number of arguments (input operands) that are
52 * required for this opcode type (1 through 6 args).
53 * yT - TARGETS: The number of targets (output operands) that are required
54 * for this opcode type (0, 1, or 2 targets).
55 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
56 * as the function return (0 or 1).
58 * The AcpiExOpcode* functions are called via the Dispatcher component with
59 * fully resolved operands.
62 /*******************************************************************************
64 * FUNCTION: Acpi_ex_opcode_1A_0T_0R
66 * PARAMETERS: Walk_state - Current state (contains AML opcode)
70 * DESCRIPTION: Execute Type 1 monadic operator with numeric operand on
73 ******************************************************************************/
76 acpi_ex_opcode_1A_0T_0R (
77 acpi_walk_state
*walk_state
)
79 acpi_operand_object
**operand
= &walk_state
->operands
[0];
80 acpi_status status
= AE_OK
;
83 ACPI_FUNCTION_TRACE_STR ("Ex_opcode_1A_0T_0R", acpi_ps_get_opcode_name (walk_state
->opcode
));
86 /* Examine the AML opcode */
88 switch (walk_state
->opcode
) {
89 case AML_RELEASE_OP
: /* Release (Mutex_object) */
91 status
= acpi_ex_release_mutex (operand
[0], walk_state
);
95 case AML_RESET_OP
: /* Reset (Event_object) */
97 status
= acpi_ex_system_reset_event (operand
[0]);
101 case AML_SIGNAL_OP
: /* Signal (Event_object) */
103 status
= acpi_ex_system_signal_event (operand
[0]);
107 case AML_SLEEP_OP
: /* Sleep (Msec_time) */
109 status
= acpi_ex_system_do_suspend ((u32
) operand
[0]->integer
.value
);
113 case AML_STALL_OP
: /* Stall (Usec_time) */
115 status
= acpi_ex_system_do_stall ((u32
) operand
[0]->integer
.value
);
119 case AML_UNLOAD_OP
: /* Unload (Handle) */
121 status
= acpi_ex_unload_table (operand
[0]);
125 default: /* Unknown opcode */
127 ACPI_REPORT_ERROR (("Acpi_ex_opcode_1A_0T_0R: Unknown opcode %X\n",
128 walk_state
->opcode
));
129 status
= AE_AML_BAD_OPCODE
;
133 return_ACPI_STATUS (status
);
137 /*******************************************************************************
139 * FUNCTION: Acpi_ex_opcode_1A_1T_0R
141 * PARAMETERS: Walk_state - Current state (contains AML opcode)
145 * DESCRIPTION: Execute opcode with one argument, one target, and no
148 ******************************************************************************/
151 acpi_ex_opcode_1A_1T_0R (
152 acpi_walk_state
*walk_state
)
154 acpi_status status
= AE_OK
;
155 acpi_operand_object
**operand
= &walk_state
->operands
[0];
158 ACPI_FUNCTION_TRACE_STR ("Ex_opcode_1A_1T_0R", acpi_ps_get_opcode_name (walk_state
->opcode
));
161 /* Examine the AML opcode */
163 switch (walk_state
->opcode
) {
166 status
= acpi_ex_load_op (operand
[0], operand
[1], walk_state
);
169 default: /* Unknown opcode */
171 ACPI_REPORT_ERROR (("Acpi_ex_opcode_1A_1T_0R: Unknown opcode %X\n",
172 walk_state
->opcode
));
173 status
= AE_AML_BAD_OPCODE
;
180 return_ACPI_STATUS (status
);
184 /*******************************************************************************
186 * FUNCTION: Acpi_ex_opcode_1A_1T_1R
188 * PARAMETERS: Walk_state - Current state (contains AML opcode)
192 * DESCRIPTION: Execute opcode with one argument, one target, and a
195 ******************************************************************************/
198 acpi_ex_opcode_1A_1T_1R (
199 acpi_walk_state
*walk_state
)
201 acpi_status status
= AE_OK
;
202 acpi_operand_object
**operand
= &walk_state
->operands
[0];
203 acpi_operand_object
*return_desc
= NULL
;
204 acpi_operand_object
*return_desc2
= NULL
;
211 ACPI_FUNCTION_TRACE_STR ("Ex_opcode_1A_1T_1R", acpi_ps_get_opcode_name (walk_state
->opcode
));
214 /* Examine the AML opcode */
216 switch (walk_state
->opcode
) {
218 case AML_FIND_SET_LEFT_BIT_OP
:
219 case AML_FIND_SET_RIGHT_BIT_OP
:
220 case AML_FROM_BCD_OP
:
222 case AML_COND_REF_OF_OP
:
224 /* Create a return object of type Integer for these opcodes */
226 return_desc
= acpi_ut_create_internal_object (ACPI_TYPE_INTEGER
);
228 status
= AE_NO_MEMORY
;
232 switch (walk_state
->opcode
) {
233 case AML_BIT_NOT_OP
: /* Not (Operand, Result) */
235 return_desc
->integer
.value
= ~operand
[0]->integer
.value
;
239 case AML_FIND_SET_LEFT_BIT_OP
: /* Find_set_left_bit (Operand, Result) */
241 return_desc
->integer
.value
= operand
[0]->integer
.value
;
244 * Acpi specification describes Integer type as a little
245 * endian unsigned value, so this boundary condition is valid.
247 for (temp32
= 0; return_desc
->integer
.value
&& temp32
< ACPI_INTEGER_BIT_SIZE
; ++temp32
) {
248 return_desc
->integer
.value
>>= 1;
251 return_desc
->integer
.value
= temp32
;
255 case AML_FIND_SET_RIGHT_BIT_OP
: /* Find_set_right_bit (Operand, Result) */
257 return_desc
->integer
.value
= operand
[0]->integer
.value
;
260 * The Acpi specification describes Integer type as a little
261 * endian unsigned value, so this boundary condition is valid.
263 for (temp32
= 0; return_desc
->integer
.value
&& temp32
< ACPI_INTEGER_BIT_SIZE
; ++temp32
) {
264 return_desc
->integer
.value
<<= 1;
267 /* Since the bit position is one-based, subtract from 33 (65) */
269 return_desc
->integer
.value
= temp32
== 0 ? 0 : (ACPI_INTEGER_BIT_SIZE
+ 1) - temp32
;
273 case AML_FROM_BCD_OP
: /* From_bcd (BCDValue, Result) */
276 * The 64-bit ACPI integer can hold 16 4-bit BCD integers
278 return_desc
->integer
.value
= 0;
279 for (i
= 0; i
< ACPI_MAX_BCD_DIGITS
; i
++) {
280 /* Get one BCD digit */
282 digit
= (acpi_integer
) ((operand
[0]->integer
.value
>> (i
* 4)) & 0xF);
284 /* Check the range of the digit */
287 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "BCD digit too large: %d\n",
289 status
= AE_AML_NUMERIC_OVERFLOW
;
294 /* Sum into the result with the appropriate power of 10 */
296 for (j
= 0; j
< i
; j
++) {
300 return_desc
->integer
.value
+= digit
;
306 case AML_TO_BCD_OP
: /* To_bcd (Operand, Result) */
308 if (operand
[0]->integer
.value
> ACPI_MAX_BCD_VALUE
) {
309 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "BCD overflow: %8.8X%8.8X\n",
310 ACPI_HIDWORD(operand
[0]->integer
.value
),
311 ACPI_LODWORD(operand
[0]->integer
.value
)));
312 status
= AE_AML_NUMERIC_OVERFLOW
;
316 return_desc
->integer
.value
= 0;
317 for (i
= 0; i
< ACPI_MAX_BCD_DIGITS
; i
++) {
318 /* Divide by nth factor of 10 */
321 digit
= operand
[0]->integer
.value
;
322 for (j
= 0; j
< i
; j
++) {
323 (void) acpi_ut_short_divide (&digit
, 10, &digit
, &temp32
);
326 /* Create the BCD digit from the remainder above */
329 return_desc
->integer
.value
+= ((acpi_integer
) temp32
<< (i
* 4));
335 case AML_COND_REF_OF_OP
: /* Cond_ref_of (Source_object, Result) */
338 * This op is a little strange because the internal return value is
339 * different than the return value stored in the result descriptor
340 * (There are really two return values)
342 if ((acpi_namespace_node
*) operand
[0] == acpi_gbl_root_node
) {
344 * This means that the object does not exist in the namespace,
347 return_desc
->integer
.value
= 0;
350 * Must delete the result descriptor since there is no reference
353 acpi_ut_remove_reference (operand
[1]);
357 /* Get the object reference, store it, and remove our reference */
359 status
= acpi_ex_get_object_reference (operand
[0], &return_desc2
, walk_state
);
360 if (ACPI_FAILURE (status
)) {
364 status
= acpi_ex_store (return_desc2
, operand
[1], walk_state
);
365 acpi_ut_remove_reference (return_desc2
);
367 /* The object exists in the namespace, return TRUE */
369 return_desc
->integer
.value
= ACPI_INTEGER_MAX
;
374 /* No other opcodes get here */
380 case AML_STORE_OP
: /* Store (Source, Target) */
383 * A store operand is typically a number, string, buffer or lvalue
384 * Be careful about deleting the source object,
385 * since the object itself may have been stored.
387 status
= acpi_ex_store (operand
[0], operand
[1], walk_state
);
388 if (ACPI_FAILURE (status
)) {
389 return_ACPI_STATUS (status
);
392 if (!walk_state
->result_obj
) {
394 * Normally, we would remove a reference on the Operand[0] parameter;
395 * But since it is being used as the internal return object
396 * (meaning we would normally increment it), the two cancel out,
397 * and we simply don't do anything.
399 walk_state
->result_obj
= operand
[0];
400 walk_state
->operands
[0] = NULL
; /* Prevent deletion */
402 return_ACPI_STATUS (status
);
408 case AML_COPY_OP
: /* Copy (Source, Target) */
410 status
= acpi_ut_copy_iobject_to_iobject (operand
[0], &return_desc
, walk_state
);
414 case AML_TO_DECSTRING_OP
: /* To_decimal_string (Data, Result) */
416 status
= acpi_ex_convert_to_string (operand
[0], &return_desc
, 10, ACPI_UINT32_MAX
, walk_state
);
420 case AML_TO_HEXSTRING_OP
: /* To_hex_string (Data, Result) */
422 status
= acpi_ex_convert_to_string (operand
[0], &return_desc
, 16, ACPI_UINT32_MAX
, walk_state
);
426 case AML_TO_BUFFER_OP
: /* To_buffer (Data, Result) */
428 status
= acpi_ex_convert_to_buffer (operand
[0], &return_desc
, walk_state
);
432 case AML_TO_INTEGER_OP
: /* To_integer (Data, Result) */
434 status
= acpi_ex_convert_to_integer (operand
[0], &return_desc
, walk_state
);
438 case AML_SHIFT_LEFT_BIT_OP
: /* Shift_left_bit (Source, Bit_num) */
439 case AML_SHIFT_RIGHT_BIT_OP
: /* Shift_right_bit (Source, Bit_num) */
442 * These are two obsolete opcodes
444 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "%s is obsolete and not implemented\n",
445 acpi_ps_get_opcode_name (walk_state
->opcode
)));
450 default: /* Unknown opcode */
452 ACPI_REPORT_ERROR (("Acpi_ex_opcode_1A_1T_1R: Unknown opcode %X\n",
453 walk_state
->opcode
));
454 status
= AE_AML_BAD_OPCODE
;
459 * Store the return value computed above into the target object
461 status
= acpi_ex_store (return_desc
, operand
[1], walk_state
);
466 if (!walk_state
->result_obj
) {
467 walk_state
->result_obj
= return_desc
;
470 /* Delete return object on error */
472 if (ACPI_FAILURE (status
)) {
473 acpi_ut_remove_reference (return_desc
);
476 return_ACPI_STATUS (status
);
480 /*******************************************************************************
482 * FUNCTION: Acpi_ex_opcode_1A_0T_1R
484 * PARAMETERS: Walk_state - Current state (contains AML opcode)
488 * DESCRIPTION: Execute opcode with one argument, no target, and a return value
490 ******************************************************************************/
493 acpi_ex_opcode_1A_0T_1R (
494 acpi_walk_state
*walk_state
)
496 acpi_operand_object
**operand
= &walk_state
->operands
[0];
497 acpi_operand_object
*temp_desc
;
498 acpi_operand_object
*return_desc
= NULL
;
499 acpi_status status
= AE_OK
;
504 ACPI_FUNCTION_TRACE_STR ("Ex_opcode_1A_0T_0R", acpi_ps_get_opcode_name (walk_state
->opcode
));
507 /* Examine the AML opcode */
509 switch (walk_state
->opcode
) {
510 case AML_LNOT_OP
: /* LNot (Operand) */
512 return_desc
= acpi_ut_create_internal_object (ACPI_TYPE_INTEGER
);
514 status
= AE_NO_MEMORY
;
518 return_desc
->integer
.value
= !operand
[0]->integer
.value
;
522 case AML_DECREMENT_OP
: /* Decrement (Operand) */
523 case AML_INCREMENT_OP
: /* Increment (Operand) */
526 * Since we are expecting a Reference operand, it
527 * can be either a NS Node or an internal object.
529 return_desc
= operand
[0];
530 if (ACPI_GET_DESCRIPTOR_TYPE (operand
[0]) == ACPI_DESC_TYPE_OPERAND
) {
531 /* Internal reference object - prevent deletion */
533 acpi_ut_add_reference (return_desc
);
537 * Convert the Return_desc Reference to a Number
538 * (This removes a reference on the Return_desc object)
540 status
= acpi_ex_resolve_operands (AML_LNOT_OP
, &return_desc
, walk_state
);
541 if (ACPI_FAILURE (status
)) {
542 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "%s: bad operand(s) %s\n",
543 acpi_ps_get_opcode_name (walk_state
->opcode
), acpi_format_exception(status
)));
549 * Return_desc is now guaranteed to be an Integer object
550 * Do the actual increment or decrement
552 if (AML_INCREMENT_OP
== walk_state
->opcode
) {
553 return_desc
->integer
.value
++;
556 return_desc
->integer
.value
--;
559 /* Store the result back in the original descriptor */
561 status
= acpi_ex_store (return_desc
, operand
[0], walk_state
);
565 case AML_TYPE_OP
: /* Object_type (Source_object) */
567 /* Get the type of the base object */
569 status
= acpi_ex_resolve_multiple (walk_state
, operand
[0], &type
, NULL
);
570 if (ACPI_FAILURE (status
)) {
574 /* Allocate a descriptor to hold the type. */
576 return_desc
= acpi_ut_create_internal_object (ACPI_TYPE_INTEGER
);
578 status
= AE_NO_MEMORY
;
582 return_desc
->integer
.value
= type
;
586 case AML_SIZE_OF_OP
: /* Size_of (Source_object) */
588 /* Get the base object */
590 status
= acpi_ex_resolve_multiple (walk_state
, operand
[0], &type
, &temp_desc
);
591 if (ACPI_FAILURE (status
)) {
596 * Type is guaranteed to be a buffer, string, or package at this
597 * point (even if the original operand was an object reference, it
598 * will be resolved and typechecked during operand resolution.)
601 case ACPI_TYPE_BUFFER
:
602 value
= temp_desc
->buffer
.length
;
605 case ACPI_TYPE_STRING
:
606 value
= temp_desc
->string
.length
;
609 case ACPI_TYPE_PACKAGE
:
610 value
= temp_desc
->package
.count
;
614 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Size_of, Not Buf/Str/Pkg - found type %s\n",
615 acpi_ut_get_type_name (type
)));
616 status
= AE_AML_OPERAND_TYPE
;
621 * Now that we have the size of the object, create a result
622 * object to hold the value
624 return_desc
= acpi_ut_create_internal_object (ACPI_TYPE_INTEGER
);
626 status
= AE_NO_MEMORY
;
630 return_desc
->integer
.value
= value
;
634 case AML_REF_OF_OP
: /* Ref_of (Source_object) */
636 status
= acpi_ex_get_object_reference (operand
[0], &return_desc
, walk_state
);
637 if (ACPI_FAILURE (status
)) {
643 case AML_DEREF_OF_OP
: /* Deref_of (Obj_reference | String) */
645 /* Check for a method local or argument, or standalone String */
647 if (ACPI_GET_DESCRIPTOR_TYPE (operand
[0]) != ACPI_DESC_TYPE_NAMED
) {
648 switch (ACPI_GET_OBJECT_TYPE (operand
[0])) {
649 case ACPI_TYPE_LOCAL_REFERENCE
:
651 * This is a Deref_of (Local_x | Arg_x)
653 * Must resolve/dereference the local/arg reference first
655 switch (operand
[0]->reference
.opcode
) {
659 /* Set Operand[0] to the value of the local/arg */
661 status
= acpi_ds_method_data_get_value (operand
[0]->reference
.opcode
,
662 operand
[0]->reference
.offset
, walk_state
, &temp_desc
);
663 if (ACPI_FAILURE (status
)) {
668 * Delete our reference to the input object and
669 * point to the object just retrieved
671 acpi_ut_remove_reference (operand
[0]);
672 operand
[0] = temp_desc
;
677 /* Get the object to which the reference refers */
679 temp_desc
= operand
[0]->reference
.object
;
680 acpi_ut_remove_reference (operand
[0]);
681 operand
[0] = temp_desc
;
686 /* Must be an Index op - handled below */
692 case ACPI_TYPE_STRING
:
695 * This is a Deref_of (String). The string is a reference to a named ACPI object.
697 * 1) Find the owning Node
698 * 2) Dereference the node to an actual object. Could be a Field, so we nee
699 * to resolve the node to a value.
701 status
= acpi_ns_get_node_by_path (operand
[0]->string
.pointer
,
702 walk_state
->scope_info
->scope
.node
, ACPI_NS_SEARCH_PARENT
,
703 ACPI_CAST_INDIRECT_PTR (acpi_namespace_node
, &return_desc
));
704 if (ACPI_FAILURE (status
)) {
708 status
= acpi_ex_resolve_node_to_value (
709 ACPI_CAST_INDIRECT_PTR (acpi_namespace_node
, &return_desc
), walk_state
);
715 status
= AE_AML_OPERAND_TYPE
;
720 /* Operand[0] may have changed from the code above */
722 if (ACPI_GET_DESCRIPTOR_TYPE (operand
[0]) == ACPI_DESC_TYPE_NAMED
) {
724 * This is a Deref_of (Object_reference)
725 * Get the actual object from the Node (This is the dereference).
726 * -- This case may only happen when a Local_x or Arg_x is dereferenced above.
728 return_desc
= acpi_ns_get_attached_object ((acpi_namespace_node
*) operand
[0]);
732 * This must be a reference object produced by either the Index() or
735 switch (operand
[0]->reference
.opcode
) {
739 * The target type for the Index operator must be
740 * either a Buffer or a Package
742 switch (operand
[0]->reference
.target_type
) {
743 case ACPI_TYPE_BUFFER_FIELD
:
745 temp_desc
= operand
[0]->reference
.object
;
748 * Create a new object that contains one element of the
749 * buffer -- the element pointed to by the index.
751 * NOTE: index into a buffer is NOT a pointer to a
752 * sub-buffer of the main buffer, it is only a pointer to a
753 * single element (byte) of the buffer!
755 return_desc
= acpi_ut_create_internal_object (ACPI_TYPE_INTEGER
);
757 status
= AE_NO_MEMORY
;
762 * Since we are returning the value of the buffer at the
763 * indexed location, we don't need to add an additional
764 * reference to the buffer itself.
766 return_desc
->integer
.value
=
767 temp_desc
->buffer
.pointer
[operand
[0]->reference
.offset
];
771 case ACPI_TYPE_PACKAGE
:
774 * Return the referenced element of the package. We must add
775 * another reference to the referenced object, however.
777 return_desc
= *(operand
[0]->reference
.where
);
780 * We can't return a NULL dereferenced value. This is
781 * an uninitialized package element and is thus a
784 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "NULL package element obj %p\n",
786 status
= AE_AML_UNINITIALIZED_ELEMENT
;
790 acpi_ut_add_reference (return_desc
);
796 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Unknown Index Target_type %X in obj %p\n",
797 operand
[0]->reference
.target_type
, operand
[0]));
798 status
= AE_AML_OPERAND_TYPE
;
806 return_desc
= operand
[0]->reference
.object
;
808 if (ACPI_GET_DESCRIPTOR_TYPE (return_desc
) == ACPI_DESC_TYPE_NAMED
) {
810 return_desc
= acpi_ns_get_attached_object ((acpi_namespace_node
*) return_desc
);
813 /* Add another reference to the object! */
815 acpi_ut_add_reference (return_desc
);
820 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
, "Unknown opcode in ref(%p) - %X\n",
821 operand
[0], operand
[0]->reference
.opcode
));
832 ACPI_REPORT_ERROR (("Acpi_ex_opcode_1A_0T_1R: Unknown opcode %X\n",
833 walk_state
->opcode
));
834 status
= AE_AML_BAD_OPCODE
;
841 /* Delete return object on error */
843 if (ACPI_FAILURE (status
)) {
844 acpi_ut_remove_reference (return_desc
);
847 walk_state
->result_obj
= return_desc
;
848 return_ACPI_STATUS (status
);