Loading...
1
2/******************************************************************************
3 *
4 * Module Name: exoparg3 - AML execution - opcodes with 3 arguments
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2011, Intel Corp.
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#include <acpi/acpi.h>
46#include "accommon.h"
47#include "acinterp.h"
48#include "acparser.h"
49#include "amlcode.h"
50
51#define _COMPONENT ACPI_EXECUTER
52ACPI_MODULE_NAME("exoparg3")
53
54/*!
55 * Naming convention for AML interpreter execution routines.
56 *
57 * The routines that begin execution of AML opcodes are named with a common
58 * convention based upon the number of arguments, the number of target operands,
59 * and whether or not a value is returned:
60 *
61 * AcpiExOpcode_xA_yT_zR
62 *
63 * Where:
64 *
65 * xA - ARGUMENTS: The number of arguments (input operands) that are
66 * required for this opcode type (1 through 6 args).
67 * yT - TARGETS: The number of targets (output operands) that are required
68 * for this opcode type (0, 1, or 2 targets).
69 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
70 * as the function return (0 or 1).
71 *
72 * The AcpiExOpcode* functions are called via the Dispatcher component with
73 * fully resolved operands.
74!*/
75/*******************************************************************************
76 *
77 * FUNCTION: acpi_ex_opcode_3A_0T_0R
78 *
79 * PARAMETERS: walk_state - Current walk state
80 *
81 * RETURN: Status
82 *
83 * DESCRIPTION: Execute Triadic operator (3 operands)
84 *
85 ******************************************************************************/
86acpi_status acpi_ex_opcode_3A_0T_0R(struct acpi_walk_state *walk_state)
87{
88 union acpi_operand_object **operand = &walk_state->operands[0];
89 struct acpi_signal_fatal_info *fatal;
90 acpi_status status = AE_OK;
91
92 ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_0T_0R,
93 acpi_ps_get_opcode_name(walk_state->opcode));
94
95 switch (walk_state->opcode) {
96 case AML_FATAL_OP: /* Fatal (fatal_type fatal_code fatal_arg) */
97
98 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
99 "FatalOp: Type %X Code %X Arg %X <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n",
100 (u32) operand[0]->integer.value,
101 (u32) operand[1]->integer.value,
102 (u32) operand[2]->integer.value));
103
104 fatal = ACPI_ALLOCATE(sizeof(struct acpi_signal_fatal_info));
105 if (fatal) {
106 fatal->type = (u32) operand[0]->integer.value;
107 fatal->code = (u32) operand[1]->integer.value;
108 fatal->argument = (u32) operand[2]->integer.value;
109 }
110
111 /* Always signal the OS! */
112
113 status = acpi_os_signal(ACPI_SIGNAL_FATAL, fatal);
114
115 /* Might return while OS is shutting down, just continue */
116
117 ACPI_FREE(fatal);
118 break;
119
120 default:
121
122 ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
123 walk_state->opcode));
124 status = AE_AML_BAD_OPCODE;
125 goto cleanup;
126 }
127
128 cleanup:
129
130 return_ACPI_STATUS(status);
131}
132
133/*******************************************************************************
134 *
135 * FUNCTION: acpi_ex_opcode_3A_1T_1R
136 *
137 * PARAMETERS: walk_state - Current walk state
138 *
139 * RETURN: Status
140 *
141 * DESCRIPTION: Execute Triadic operator (3 operands)
142 *
143 ******************************************************************************/
144
145acpi_status acpi_ex_opcode_3A_1T_1R(struct acpi_walk_state *walk_state)
146{
147 union acpi_operand_object **operand = &walk_state->operands[0];
148 union acpi_operand_object *return_desc = NULL;
149 char *buffer = NULL;
150 acpi_status status = AE_OK;
151 u64 index;
152 acpi_size length;
153
154 ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_1T_1R,
155 acpi_ps_get_opcode_name(walk_state->opcode));
156
157 switch (walk_state->opcode) {
158 case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */
159
160 /*
161 * Create the return object. The Source operand is guaranteed to be
162 * either a String or a Buffer, so just use its type.
163 */
164 return_desc = acpi_ut_create_internal_object((operand[0])->
165 common.type);
166 if (!return_desc) {
167 status = AE_NO_MEMORY;
168 goto cleanup;
169 }
170
171 /* Get the Integer values from the objects */
172
173 index = operand[1]->integer.value;
174 length = (acpi_size) operand[2]->integer.value;
175
176 /*
177 * If the index is beyond the length of the String/Buffer, or if the
178 * requested length is zero, return a zero-length String/Buffer
179 */
180 if (index >= operand[0]->string.length) {
181 length = 0;
182 }
183
184 /* Truncate request if larger than the actual String/Buffer */
185
186 else if ((index + length) > operand[0]->string.length) {
187 length = (acpi_size) operand[0]->string.length -
188 (acpi_size) index;
189 }
190
191 /* Strings always have a sub-pointer, not so for buffers */
192
193 switch ((operand[0])->common.type) {
194 case ACPI_TYPE_STRING:
195
196 /* Always allocate a new buffer for the String */
197
198 buffer = ACPI_ALLOCATE_ZEROED((acpi_size) length + 1);
199 if (!buffer) {
200 status = AE_NO_MEMORY;
201 goto cleanup;
202 }
203 break;
204
205 case ACPI_TYPE_BUFFER:
206
207 /* If the requested length is zero, don't allocate a buffer */
208
209 if (length > 0) {
210
211 /* Allocate a new buffer for the Buffer */
212
213 buffer = ACPI_ALLOCATE_ZEROED(length);
214 if (!buffer) {
215 status = AE_NO_MEMORY;
216 goto cleanup;
217 }
218 }
219 break;
220
221 default: /* Should not happen */
222
223 status = AE_AML_OPERAND_TYPE;
224 goto cleanup;
225 }
226
227 if (buffer) {
228
229 /* We have a buffer, copy the portion requested */
230
231 ACPI_MEMCPY(buffer, operand[0]->string.pointer + index,
232 length);
233 }
234
235 /* Set the length of the new String/Buffer */
236
237 return_desc->string.pointer = buffer;
238 return_desc->string.length = (u32) length;
239
240 /* Mark buffer initialized */
241
242 return_desc->buffer.flags |= AOPOBJ_DATA_VALID;
243 break;
244
245 default:
246
247 ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
248 walk_state->opcode));
249 status = AE_AML_BAD_OPCODE;
250 goto cleanup;
251 }
252
253 /* Store the result in the target */
254
255 status = acpi_ex_store(return_desc, operand[3], walk_state);
256
257 cleanup:
258
259 /* Delete return object on error */
260
261 if (ACPI_FAILURE(status) || walk_state->result_obj) {
262 acpi_ut_remove_reference(return_desc);
263 walk_state->result_obj = NULL;
264 }
265
266 /* Set the return object and exit */
267
268 else {
269 walk_state->result_obj = return_desc;
270 }
271 return_ACPI_STATUS(status);
272}
1// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2/******************************************************************************
3 *
4 * Module Name: exoparg3 - AML execution - opcodes with 3 arguments
5 *
6 * Copyright (C) 2000 - 2022, Intel Corp.
7 *
8 *****************************************************************************/
9
10#include <acpi/acpi.h>
11#include "accommon.h"
12#include "acinterp.h"
13#include "acparser.h"
14#include "amlcode.h"
15
16#define _COMPONENT ACPI_EXECUTER
17ACPI_MODULE_NAME("exoparg3")
18
19/*!
20 * Naming convention for AML interpreter execution routines.
21 *
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:
25 *
26 * AcpiExOpcode_xA_yT_zR
27 *
28 * Where:
29 *
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).
36 *
37 * The AcpiExOpcode* functions are called via the Dispatcher component with
38 * fully resolved operands.
39!*/
40/*******************************************************************************
41 *
42 * FUNCTION: acpi_ex_opcode_3A_0T_0R
43 *
44 * PARAMETERS: walk_state - Current walk state
45 *
46 * RETURN: Status
47 *
48 * DESCRIPTION: Execute Triadic operator (3 operands)
49 *
50 ******************************************************************************/
51acpi_status acpi_ex_opcode_3A_0T_0R(struct acpi_walk_state *walk_state)
52{
53 union acpi_operand_object **operand = &walk_state->operands[0];
54 struct acpi_signal_fatal_info *fatal;
55 acpi_status status = AE_OK;
56
57 ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_0T_0R,
58 acpi_ps_get_opcode_name(walk_state->opcode));
59
60 switch (walk_state->opcode) {
61 case AML_FATAL_OP: /* Fatal (fatal_type fatal_code fatal_arg) */
62
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));
69
70 fatal = ACPI_ALLOCATE(sizeof(struct acpi_signal_fatal_info));
71 if (fatal) {
72 fatal->type = (u32) operand[0]->integer.value;
73 fatal->code = (u32) operand[1]->integer.value;
74 fatal->argument = (u32) operand[2]->integer.value;
75 }
76
77 /* Always signal the OS! */
78
79 status = acpi_os_signal(ACPI_SIGNAL_FATAL, fatal);
80
81 /* Might return while OS is shutting down, just continue */
82
83 ACPI_FREE(fatal);
84 goto cleanup;
85
86 case AML_EXTERNAL_OP:
87 /*
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.
94 */
95 ACPI_ERROR((AE_INFO, "Executed External Op"));
96 status = AE_OK;
97 goto cleanup;
98
99 default:
100
101 ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
102 walk_state->opcode));
103
104 status = AE_AML_BAD_OPCODE;
105 goto cleanup;
106 }
107
108cleanup:
109
110 return_ACPI_STATUS(status);
111}
112
113/*******************************************************************************
114 *
115 * FUNCTION: acpi_ex_opcode_3A_1T_1R
116 *
117 * PARAMETERS: walk_state - Current walk state
118 *
119 * RETURN: Status
120 *
121 * DESCRIPTION: Execute Triadic operator (3 operands)
122 *
123 ******************************************************************************/
124
125acpi_status acpi_ex_opcode_3A_1T_1R(struct acpi_walk_state *walk_state)
126{
127 union acpi_operand_object **operand = &walk_state->operands[0];
128 union acpi_operand_object *return_desc = NULL;
129 char *buffer = NULL;
130 acpi_status status = AE_OK;
131 u64 index;
132 acpi_size length;
133
134 ACPI_FUNCTION_TRACE_STR(ex_opcode_3A_1T_1R,
135 acpi_ps_get_opcode_name(walk_state->opcode));
136
137 switch (walk_state->opcode) {
138 case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */
139 /*
140 * Create the return object. The Source operand is guaranteed to be
141 * either a String or a Buffer, so just use its type.
142 */
143 return_desc = acpi_ut_create_internal_object((operand[0])->
144 common.type);
145 if (!return_desc) {
146 status = AE_NO_MEMORY;
147 goto cleanup;
148 }
149
150 /* Get the Integer values from the objects */
151
152 index = operand[1]->integer.value;
153 length = (acpi_size)operand[2]->integer.value;
154
155 /*
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
158 */
159 if (index >= operand[0]->string.length) {
160 length = 0;
161 }
162
163 /* Truncate request if larger than the actual String/Buffer */
164
165 else if ((index + length) > operand[0]->string.length) {
166 length =
167 (acpi_size)operand[0]->string.length -
168 (acpi_size)index;
169 }
170
171 /* Strings always have a sub-pointer, not so for buffers */
172
173 switch ((operand[0])->common.type) {
174 case ACPI_TYPE_STRING:
175
176 /* Always allocate a new buffer for the String */
177
178 buffer = ACPI_ALLOCATE_ZEROED((acpi_size)length + 1);
179 if (!buffer) {
180 status = AE_NO_MEMORY;
181 goto cleanup;
182 }
183 break;
184
185 case ACPI_TYPE_BUFFER:
186
187 /* If the requested length is zero, don't allocate a buffer */
188
189 if (length > 0) {
190
191 /* Allocate a new buffer for the Buffer */
192
193 buffer = ACPI_ALLOCATE_ZEROED(length);
194 if (!buffer) {
195 status = AE_NO_MEMORY;
196 goto cleanup;
197 }
198 }
199 break;
200
201 default: /* Should not happen */
202
203 status = AE_AML_OPERAND_TYPE;
204 goto cleanup;
205 }
206
207 if (buffer) {
208
209 /* We have a buffer, copy the portion requested */
210
211 memcpy(buffer,
212 operand[0]->string.pointer + index, length);
213 }
214
215 /* Set the length of the new String/Buffer */
216
217 return_desc->string.pointer = buffer;
218 return_desc->string.length = (u32) length;
219
220 /* Mark buffer initialized */
221
222 return_desc->buffer.flags |= AOPOBJ_DATA_VALID;
223 break;
224
225 default:
226
227 ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
228 walk_state->opcode));
229
230 status = AE_AML_BAD_OPCODE;
231 goto cleanup;
232 }
233
234 /* Store the result in the target */
235
236 status = acpi_ex_store(return_desc, operand[3], walk_state);
237
238cleanup:
239
240 /* Delete return object on error */
241
242 if (ACPI_FAILURE(status) || walk_state->result_obj) {
243 acpi_ut_remove_reference(return_desc);
244 walk_state->result_obj = NULL;
245 } else {
246 /* Set the return object and exit */
247
248 walk_state->result_obj = return_desc;
249 }
250
251 return_ACPI_STATUS(status);
252}