1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: exoparg3 - AML execution - opcodes with 3 arguments
6 * Copyright (C) 2000 - 2020, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
16 #define _COMPONENT ACPI_EXECUTER
17 ACPI_MODULE_NAME("exoparg3")
20 * Naming convention for AML interpreter execution routines.
22 * The routines that begin execution of AML opcodes are named with a common
23 * convention based upon the number of arguments, the number of target operands,
24 * and whether or not a value is returned:
26 * AcpiExOpcode_xA_yT_zR
30 * xA - ARGUMENTS: The number of arguments (input operands) that are
31 * required for this opcode type (1 through 6 args).
32 * yT - TARGETS: The number of targets (output operands) that are required
33 * for this opcode type (0, 1, or 2 targets).
34 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
35 * as the function return (0 or 1).
37 * The AcpiExOpcode* functions are called via the Dispatcher component with
38 * fully resolved operands.
40 /*******************************************************************************
42 * FUNCTION: acpi_ex_opcode_3A_0T_0R
44 * PARAMETERS: walk_state - Current walk state
48 * DESCRIPTION: Execute Triadic operator (3 operands)
50 ******************************************************************************/
51 acpi_status
acpi_ex_opcode_3A_0T_0R(struct acpi_walk_state
*walk_state
)
53 union acpi_operand_object
**operand
= &walk_state
->operands
[0];
54 struct acpi_signal_fatal_info
*fatal
;
55 acpi_status status
= AE_OK
;
57 ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_0T_0R
,
58 acpi_ps_get_opcode_name(walk_state
->opcode
));
60 switch (walk_state
->opcode
) {
61 case AML_FATAL_OP
: /* Fatal (fatal_type fatal_code fatal_arg) */
63 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
64 "FatalOp: Type %X Code %X Arg %X "
65 "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n",
66 (u32
)operand
[0]->integer
.value
,
67 (u32
)operand
[1]->integer
.value
,
68 (u32
)operand
[2]->integer
.value
));
70 fatal
= ACPI_ALLOCATE(sizeof(struct acpi_signal_fatal_info
));
72 fatal
->type
= (u32
) operand
[0]->integer
.value
;
73 fatal
->code
= (u32
) operand
[1]->integer
.value
;
74 fatal
->argument
= (u32
) operand
[2]->integer
.value
;
77 /* Always signal the OS! */
79 status
= acpi_os_signal(ACPI_SIGNAL_FATAL
, fatal
);
81 /* Might return while OS is shutting down, just continue */
88 * If the interpreter sees this opcode, just ignore it. The External
89 * op is intended for use by disassemblers in order to properly
90 * disassemble control method invocations. The opcode or group of
91 * opcodes should be surrounded by an "if (0)" clause to ensure that
92 * AML interpreters never see the opcode. Thus, something is
93 * wrong if an external opcode ever gets here.
95 ACPI_ERROR((AE_INFO
, "Executed External Op"));
101 ACPI_ERROR((AE_INFO
, "Unknown AML opcode 0x%X",
102 walk_state
->opcode
));
104 status
= AE_AML_BAD_OPCODE
;
110 return_ACPI_STATUS(status
);
113 /*******************************************************************************
115 * FUNCTION: acpi_ex_opcode_3A_1T_1R
117 * PARAMETERS: walk_state - Current walk state
121 * DESCRIPTION: Execute Triadic operator (3 operands)
123 ******************************************************************************/
125 acpi_status
acpi_ex_opcode_3A_1T_1R(struct acpi_walk_state
*walk_state
)
127 union acpi_operand_object
**operand
= &walk_state
->operands
[0];
128 union acpi_operand_object
*return_desc
= NULL
;
130 acpi_status status
= AE_OK
;
134 ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_1T_1R
,
135 acpi_ps_get_opcode_name(walk_state
->opcode
));
137 switch (walk_state
->opcode
) {
138 case AML_MID_OP
: /* Mid (Source[0], Index[1], Length[2], Result[3]) */
140 * Create the return object. The Source operand is guaranteed to be
141 * either a String or a Buffer, so just use its type.
143 return_desc
= acpi_ut_create_internal_object((operand
[0])->
146 status
= AE_NO_MEMORY
;
150 /* Get the Integer values from the objects */
152 index
= operand
[1]->integer
.value
;
153 length
= (acpi_size
)operand
[2]->integer
.value
;
156 * If the index is beyond the length of the String/Buffer, or if the
157 * requested length is zero, return a zero-length String/Buffer
159 if (index
>= operand
[0]->string
.length
) {
163 /* Truncate request if larger than the actual String/Buffer */
165 else if ((index
+ length
) > operand
[0]->string
.length
) {
167 (acpi_size
)operand
[0]->string
.length
-
171 /* Strings always have a sub-pointer, not so for buffers */
173 switch ((operand
[0])->common
.type
) {
174 case ACPI_TYPE_STRING
:
176 /* Always allocate a new buffer for the String */
178 buffer
= ACPI_ALLOCATE_ZEROED((acpi_size
)length
+ 1);
180 status
= AE_NO_MEMORY
;
185 case ACPI_TYPE_BUFFER
:
187 /* If the requested length is zero, don't allocate a buffer */
191 /* Allocate a new buffer for the Buffer */
193 buffer
= ACPI_ALLOCATE_ZEROED(length
);
195 status
= AE_NO_MEMORY
;
201 default: /* Should not happen */
203 status
= AE_AML_OPERAND_TYPE
;
209 /* We have a buffer, copy the portion requested */
212 operand
[0]->string
.pointer
+ index
, length
);
215 /* Set the length of the new String/Buffer */
217 return_desc
->string
.pointer
= buffer
;
218 return_desc
->string
.length
= (u32
) length
;
220 /* Mark buffer initialized */
222 return_desc
->buffer
.flags
|= AOPOBJ_DATA_VALID
;
227 ACPI_ERROR((AE_INFO
, "Unknown AML opcode 0x%X",
228 walk_state
->opcode
));
230 status
= AE_AML_BAD_OPCODE
;
234 /* Store the result in the target */
236 status
= acpi_ex_store(return_desc
, operand
[3], walk_state
);
240 /* Delete return object on error */
242 if (ACPI_FAILURE(status
) || walk_state
->result_obj
) {
243 acpi_ut_remove_reference(return_desc
);
244 walk_state
->result_obj
= NULL
;
246 /* Set the return object and exit */
248 walk_state
->result_obj
= return_desc
;
251 return_ACPI_STATUS(status
);