exoparg3.c revision 1.1.1.13 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: exoparg3 - AML execution - opcodes with 3 arguments
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1.1.2 jruoho /*
8 1.1.1.13 christos * Copyright (C) 2000 - 2021, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
12 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
13 1.1.1.2 jruoho * are met:
14 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2 jruoho * without modification.
17 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
21 1.1.1.2 jruoho * binary redistribution.
22 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
24 1.1.1.2 jruoho * from this software without specific prior written permission.
25 1.1.1.2 jruoho *
26 1.1.1.2 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2 jruoho * Software Foundation.
29 1.1.1.2 jruoho *
30 1.1.1.2 jruoho * NO WARRANTY
31 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.13 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2 jruoho */
43 1.1 jruoho
44 1.1 jruoho #include "acpi.h"
45 1.1 jruoho #include "accommon.h"
46 1.1 jruoho #include "acinterp.h"
47 1.1 jruoho #include "acparser.h"
48 1.1 jruoho #include "amlcode.h"
49 1.1 jruoho
50 1.1 jruoho
51 1.1 jruoho #define _COMPONENT ACPI_EXECUTER
52 1.1 jruoho ACPI_MODULE_NAME ("exoparg3")
53 1.1 jruoho
54 1.1 jruoho
55 1.1 jruoho /*!
56 1.1 jruoho * Naming convention for AML interpreter execution routines.
57 1.1 jruoho *
58 1.1 jruoho * The routines that begin execution of AML opcodes are named with a common
59 1.1 jruoho * convention based upon the number of arguments, the number of target operands,
60 1.1 jruoho * and whether or not a value is returned:
61 1.1 jruoho *
62 1.1 jruoho * AcpiExOpcode_xA_yT_zR
63 1.1 jruoho *
64 1.1 jruoho * Where:
65 1.1 jruoho *
66 1.1 jruoho * xA - ARGUMENTS: The number of arguments (input operands) that are
67 1.1 jruoho * required for this opcode type (1 through 6 args).
68 1.1 jruoho * yT - TARGETS: The number of targets (output operands) that are required
69 1.1 jruoho * for this opcode type (0, 1, or 2 targets).
70 1.1 jruoho * zR - RETURN VALUE: Indicates whether this opcode type returns a value
71 1.1 jruoho * as the function return (0 or 1).
72 1.1 jruoho *
73 1.1 jruoho * The AcpiExOpcode* functions are called via the Dispatcher component with
74 1.1 jruoho * fully resolved operands.
75 1.1 jruoho !*/
76 1.1 jruoho
77 1.1 jruoho
78 1.1 jruoho /*******************************************************************************
79 1.1 jruoho *
80 1.1 jruoho * FUNCTION: AcpiExOpcode_3A_0T_0R
81 1.1 jruoho *
82 1.1 jruoho * PARAMETERS: WalkState - Current walk state
83 1.1 jruoho *
84 1.1 jruoho * RETURN: Status
85 1.1 jruoho *
86 1.1 jruoho * DESCRIPTION: Execute Triadic operator (3 operands)
87 1.1 jruoho *
88 1.1 jruoho ******************************************************************************/
89 1.1 jruoho
90 1.1 jruoho ACPI_STATUS
91 1.1 jruoho AcpiExOpcode_3A_0T_0R (
92 1.1 jruoho ACPI_WALK_STATE *WalkState)
93 1.1 jruoho {
94 1.1 jruoho ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
95 1.1 jruoho ACPI_SIGNAL_FATAL_INFO *Fatal;
96 1.1 jruoho ACPI_STATUS Status = AE_OK;
97 1.1 jruoho
98 1.1 jruoho
99 1.1 jruoho ACPI_FUNCTION_TRACE_STR (ExOpcode_3A_0T_0R,
100 1.1 jruoho AcpiPsGetOpcodeName (WalkState->Opcode));
101 1.1 jruoho
102 1.1 jruoho
103 1.1 jruoho switch (WalkState->Opcode)
104 1.1 jruoho {
105 1.1 jruoho case AML_FATAL_OP: /* Fatal (FatalType FatalCode FatalArg) */
106 1.1 jruoho
107 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
108 1.1.1.7 christos "FatalOp: Type %X Code %X Arg %X "
109 1.1.1.7 christos "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n",
110 1.1 jruoho (UINT32) Operand[0]->Integer.Value,
111 1.1 jruoho (UINT32) Operand[1]->Integer.Value,
112 1.1 jruoho (UINT32) Operand[2]->Integer.Value));
113 1.1 jruoho
114 1.1 jruoho Fatal = ACPI_ALLOCATE (sizeof (ACPI_SIGNAL_FATAL_INFO));
115 1.1 jruoho if (Fatal)
116 1.1 jruoho {
117 1.1.1.7 christos Fatal->Type = (UINT32) Operand[0]->Integer.Value;
118 1.1.1.7 christos Fatal->Code = (UINT32) Operand[1]->Integer.Value;
119 1.1 jruoho Fatal->Argument = (UINT32) Operand[2]->Integer.Value;
120 1.1 jruoho }
121 1.1 jruoho
122 1.1 jruoho /* Always signal the OS! */
123 1.1 jruoho
124 1.1 jruoho Status = AcpiOsSignal (ACPI_SIGNAL_FATAL, Fatal);
125 1.1 jruoho
126 1.1 jruoho /* Might return while OS is shutting down, just continue */
127 1.1 jruoho
128 1.1 jruoho ACPI_FREE (Fatal);
129 1.1.1.5 christos goto Cleanup;
130 1.1.1.5 christos
131 1.1.1.5 christos case AML_EXTERNAL_OP:
132 1.1.1.5 christos /*
133 1.1.1.5 christos * If the interpreter sees this opcode, just ignore it. The External
134 1.1.1.5 christos * op is intended for use by disassemblers in order to properly
135 1.1.1.5 christos * disassemble control method invocations. The opcode or group of
136 1.1.1.5 christos * opcodes should be surrounded by an "if (0)" clause to ensure that
137 1.1.1.8 christos * AML interpreters never see the opcode. Thus, something is
138 1.1.1.8 christos * wrong if an external opcode ever gets here.
139 1.1.1.5 christos */
140 1.1.1.8 christos ACPI_ERROR ((AE_INFO, "Executed External Op"));
141 1.1.1.5 christos Status = AE_OK;
142 1.1.1.5 christos goto Cleanup;
143 1.1 jruoho
144 1.1 jruoho default:
145 1.1 jruoho
146 1.1 jruoho ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
147 1.1 jruoho WalkState->Opcode));
148 1.1.1.7 christos
149 1.1 jruoho Status = AE_AML_BAD_OPCODE;
150 1.1 jruoho goto Cleanup;
151 1.1 jruoho }
152 1.1 jruoho
153 1.1 jruoho
154 1.1 jruoho Cleanup:
155 1.1 jruoho
156 1.1 jruoho return_ACPI_STATUS (Status);
157 1.1 jruoho }
158 1.1 jruoho
159 1.1 jruoho
160 1.1 jruoho /*******************************************************************************
161 1.1 jruoho *
162 1.1 jruoho * FUNCTION: AcpiExOpcode_3A_1T_1R
163 1.1 jruoho *
164 1.1 jruoho * PARAMETERS: WalkState - Current walk state
165 1.1 jruoho *
166 1.1 jruoho * RETURN: Status
167 1.1 jruoho *
168 1.1 jruoho * DESCRIPTION: Execute Triadic operator (3 operands)
169 1.1 jruoho *
170 1.1 jruoho ******************************************************************************/
171 1.1 jruoho
172 1.1 jruoho ACPI_STATUS
173 1.1 jruoho AcpiExOpcode_3A_1T_1R (
174 1.1 jruoho ACPI_WALK_STATE *WalkState)
175 1.1 jruoho {
176 1.1 jruoho ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
177 1.1 jruoho ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
178 1.1 jruoho char *Buffer = NULL;
179 1.1 jruoho ACPI_STATUS Status = AE_OK;
180 1.1 jruoho UINT64 Index;
181 1.1 jruoho ACPI_SIZE Length;
182 1.1 jruoho
183 1.1 jruoho
184 1.1 jruoho ACPI_FUNCTION_TRACE_STR (ExOpcode_3A_1T_1R,
185 1.1 jruoho AcpiPsGetOpcodeName (WalkState->Opcode));
186 1.1 jruoho
187 1.1 jruoho
188 1.1 jruoho switch (WalkState->Opcode)
189 1.1 jruoho {
190 1.1 jruoho case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */
191 1.1 jruoho /*
192 1.1.1.3 christos * Create the return object. The Source operand is guaranteed to be
193 1.1 jruoho * either a String or a Buffer, so just use its type.
194 1.1 jruoho */
195 1.1 jruoho ReturnDesc = AcpiUtCreateInternalObject (
196 1.1.1.7 christos (Operand[0])->Common.Type);
197 1.1 jruoho if (!ReturnDesc)
198 1.1 jruoho {
199 1.1 jruoho Status = AE_NO_MEMORY;
200 1.1 jruoho goto Cleanup;
201 1.1 jruoho }
202 1.1 jruoho
203 1.1 jruoho /* Get the Integer values from the objects */
204 1.1 jruoho
205 1.1 jruoho Index = Operand[1]->Integer.Value;
206 1.1 jruoho Length = (ACPI_SIZE) Operand[2]->Integer.Value;
207 1.1 jruoho
208 1.1 jruoho /*
209 1.1 jruoho * If the index is beyond the length of the String/Buffer, or if the
210 1.1 jruoho * requested length is zero, return a zero-length String/Buffer
211 1.1 jruoho */
212 1.1 jruoho if (Index >= Operand[0]->String.Length)
213 1.1 jruoho {
214 1.1 jruoho Length = 0;
215 1.1 jruoho }
216 1.1 jruoho
217 1.1 jruoho /* Truncate request if larger than the actual String/Buffer */
218 1.1 jruoho
219 1.1 jruoho else if ((Index + Length) > Operand[0]->String.Length)
220 1.1 jruoho {
221 1.1.1.7 christos Length =
222 1.1.1.7 christos (ACPI_SIZE) Operand[0]->String.Length - (ACPI_SIZE) Index;
223 1.1 jruoho }
224 1.1 jruoho
225 1.1 jruoho /* Strings always have a sub-pointer, not so for buffers */
226 1.1 jruoho
227 1.1 jruoho switch ((Operand[0])->Common.Type)
228 1.1 jruoho {
229 1.1 jruoho case ACPI_TYPE_STRING:
230 1.1 jruoho
231 1.1 jruoho /* Always allocate a new buffer for the String */
232 1.1 jruoho
233 1.1 jruoho Buffer = ACPI_ALLOCATE_ZEROED ((ACPI_SIZE) Length + 1);
234 1.1 jruoho if (!Buffer)
235 1.1 jruoho {
236 1.1 jruoho Status = AE_NO_MEMORY;
237 1.1 jruoho goto Cleanup;
238 1.1 jruoho }
239 1.1 jruoho break;
240 1.1 jruoho
241 1.1 jruoho case ACPI_TYPE_BUFFER:
242 1.1 jruoho
243 1.1 jruoho /* If the requested length is zero, don't allocate a buffer */
244 1.1 jruoho
245 1.1 jruoho if (Length > 0)
246 1.1 jruoho {
247 1.1 jruoho /* Allocate a new buffer for the Buffer */
248 1.1 jruoho
249 1.1 jruoho Buffer = ACPI_ALLOCATE_ZEROED (Length);
250 1.1 jruoho if (!Buffer)
251 1.1 jruoho {
252 1.1 jruoho Status = AE_NO_MEMORY;
253 1.1 jruoho goto Cleanup;
254 1.1 jruoho }
255 1.1 jruoho }
256 1.1 jruoho break;
257 1.1 jruoho
258 1.1 jruoho default: /* Should not happen */
259 1.1 jruoho
260 1.1 jruoho Status = AE_AML_OPERAND_TYPE;
261 1.1 jruoho goto Cleanup;
262 1.1 jruoho }
263 1.1 jruoho
264 1.1 jruoho if (Buffer)
265 1.1 jruoho {
266 1.1 jruoho /* We have a buffer, copy the portion requested */
267 1.1 jruoho
268 1.1.1.7 christos memcpy (Buffer,
269 1.1.1.7 christos Operand[0]->String.Pointer + Index, Length);
270 1.1 jruoho }
271 1.1 jruoho
272 1.1 jruoho /* Set the length of the new String/Buffer */
273 1.1 jruoho
274 1.1 jruoho ReturnDesc->String.Pointer = Buffer;
275 1.1 jruoho ReturnDesc->String.Length = (UINT32) Length;
276 1.1 jruoho
277 1.1 jruoho /* Mark buffer initialized */
278 1.1 jruoho
279 1.1 jruoho ReturnDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
280 1.1 jruoho break;
281 1.1 jruoho
282 1.1 jruoho default:
283 1.1 jruoho
284 1.1 jruoho ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
285 1.1 jruoho WalkState->Opcode));
286 1.1.1.7 christos
287 1.1 jruoho Status = AE_AML_BAD_OPCODE;
288 1.1 jruoho goto Cleanup;
289 1.1 jruoho }
290 1.1 jruoho
291 1.1 jruoho /* Store the result in the target */
292 1.1 jruoho
293 1.1 jruoho Status = AcpiExStore (ReturnDesc, Operand[3], WalkState);
294 1.1 jruoho
295 1.1 jruoho Cleanup:
296 1.1 jruoho
297 1.1 jruoho /* Delete return object on error */
298 1.1 jruoho
299 1.1 jruoho if (ACPI_FAILURE (Status) || WalkState->ResultObj)
300 1.1 jruoho {
301 1.1 jruoho AcpiUtRemoveReference (ReturnDesc);
302 1.1 jruoho WalkState->ResultObj = NULL;
303 1.1 jruoho }
304 1.1 jruoho else
305 1.1 jruoho {
306 1.1.1.7 christos /* Set the return object and exit */
307 1.1.1.7 christos
308 1.1 jruoho WalkState->ResultObj = ReturnDesc;
309 1.1 jruoho }
310 1.1.1.7 christos
311 1.1 jruoho return_ACPI_STATUS (Status);
312 1.1 jruoho }
313