exoparg3.c revision 1.1.1.5 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.5 christos * Copyright (C) 2000 - 2015, 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.2 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY 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 jruoho "FatalOp: Type %X Code %X Arg %X <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n",
109 1.1 jruoho (UINT32) Operand[0]->Integer.Value,
110 1.1 jruoho (UINT32) Operand[1]->Integer.Value,
111 1.1 jruoho (UINT32) Operand[2]->Integer.Value));
112 1.1 jruoho
113 1.1 jruoho Fatal = ACPI_ALLOCATE (sizeof (ACPI_SIGNAL_FATAL_INFO));
114 1.1 jruoho if (Fatal)
115 1.1 jruoho {
116 1.1 jruoho Fatal->Type = (UINT32) Operand[0]->Integer.Value;
117 1.1 jruoho Fatal->Code = (UINT32) Operand[1]->Integer.Value;
118 1.1 jruoho Fatal->Argument = (UINT32) Operand[2]->Integer.Value;
119 1.1 jruoho }
120 1.1 jruoho
121 1.1 jruoho /* Always signal the OS! */
122 1.1 jruoho
123 1.1 jruoho Status = AcpiOsSignal (ACPI_SIGNAL_FATAL, Fatal);
124 1.1 jruoho
125 1.1 jruoho /* Might return while OS is shutting down, just continue */
126 1.1 jruoho
127 1.1 jruoho ACPI_FREE (Fatal);
128 1.1.1.5 christos goto Cleanup;
129 1.1.1.5 christos
130 1.1.1.5 christos case AML_EXTERNAL_OP:
131 1.1.1.5 christos /*
132 1.1.1.5 christos * If the interpreter sees this opcode, just ignore it. The External
133 1.1.1.5 christos * op is intended for use by disassemblers in order to properly
134 1.1.1.5 christos * disassemble control method invocations. The opcode or group of
135 1.1.1.5 christos * opcodes should be surrounded by an "if (0)" clause to ensure that
136 1.1.1.5 christos * AML interpreters never see the opcode.
137 1.1.1.5 christos */
138 1.1.1.5 christos Status = AE_OK;
139 1.1.1.5 christos goto Cleanup;
140 1.1 jruoho
141 1.1 jruoho default:
142 1.1 jruoho
143 1.1 jruoho ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
144 1.1 jruoho WalkState->Opcode));
145 1.1 jruoho Status = AE_AML_BAD_OPCODE;
146 1.1 jruoho goto Cleanup;
147 1.1 jruoho }
148 1.1 jruoho
149 1.1 jruoho
150 1.1 jruoho Cleanup:
151 1.1 jruoho
152 1.1 jruoho return_ACPI_STATUS (Status);
153 1.1 jruoho }
154 1.1 jruoho
155 1.1 jruoho
156 1.1 jruoho /*******************************************************************************
157 1.1 jruoho *
158 1.1 jruoho * FUNCTION: AcpiExOpcode_3A_1T_1R
159 1.1 jruoho *
160 1.1 jruoho * PARAMETERS: WalkState - Current walk state
161 1.1 jruoho *
162 1.1 jruoho * RETURN: Status
163 1.1 jruoho *
164 1.1 jruoho * DESCRIPTION: Execute Triadic operator (3 operands)
165 1.1 jruoho *
166 1.1 jruoho ******************************************************************************/
167 1.1 jruoho
168 1.1 jruoho ACPI_STATUS
169 1.1 jruoho AcpiExOpcode_3A_1T_1R (
170 1.1 jruoho ACPI_WALK_STATE *WalkState)
171 1.1 jruoho {
172 1.1 jruoho ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
173 1.1 jruoho ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
174 1.1 jruoho char *Buffer = NULL;
175 1.1 jruoho ACPI_STATUS Status = AE_OK;
176 1.1 jruoho UINT64 Index;
177 1.1 jruoho ACPI_SIZE Length;
178 1.1 jruoho
179 1.1 jruoho
180 1.1 jruoho ACPI_FUNCTION_TRACE_STR (ExOpcode_3A_1T_1R,
181 1.1 jruoho AcpiPsGetOpcodeName (WalkState->Opcode));
182 1.1 jruoho
183 1.1 jruoho
184 1.1 jruoho switch (WalkState->Opcode)
185 1.1 jruoho {
186 1.1 jruoho case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */
187 1.1 jruoho /*
188 1.1.1.3 christos * Create the return object. The Source operand is guaranteed to be
189 1.1 jruoho * either a String or a Buffer, so just use its type.
190 1.1 jruoho */
191 1.1 jruoho ReturnDesc = AcpiUtCreateInternalObject (
192 1.1 jruoho (Operand[0])->Common.Type);
193 1.1 jruoho if (!ReturnDesc)
194 1.1 jruoho {
195 1.1 jruoho Status = AE_NO_MEMORY;
196 1.1 jruoho goto Cleanup;
197 1.1 jruoho }
198 1.1 jruoho
199 1.1 jruoho /* Get the Integer values from the objects */
200 1.1 jruoho
201 1.1 jruoho Index = Operand[1]->Integer.Value;
202 1.1 jruoho Length = (ACPI_SIZE) Operand[2]->Integer.Value;
203 1.1 jruoho
204 1.1 jruoho /*
205 1.1 jruoho * If the index is beyond the length of the String/Buffer, or if the
206 1.1 jruoho * requested length is zero, return a zero-length String/Buffer
207 1.1 jruoho */
208 1.1 jruoho if (Index >= Operand[0]->String.Length)
209 1.1 jruoho {
210 1.1 jruoho Length = 0;
211 1.1 jruoho }
212 1.1 jruoho
213 1.1 jruoho /* Truncate request if larger than the actual String/Buffer */
214 1.1 jruoho
215 1.1 jruoho else if ((Index + Length) > Operand[0]->String.Length)
216 1.1 jruoho {
217 1.1 jruoho Length = (ACPI_SIZE) Operand[0]->String.Length -
218 1.1 jruoho (ACPI_SIZE) Index;
219 1.1 jruoho }
220 1.1 jruoho
221 1.1 jruoho /* Strings always have a sub-pointer, not so for buffers */
222 1.1 jruoho
223 1.1 jruoho switch ((Operand[0])->Common.Type)
224 1.1 jruoho {
225 1.1 jruoho case ACPI_TYPE_STRING:
226 1.1 jruoho
227 1.1 jruoho /* Always allocate a new buffer for the String */
228 1.1 jruoho
229 1.1 jruoho Buffer = ACPI_ALLOCATE_ZEROED ((ACPI_SIZE) Length + 1);
230 1.1 jruoho if (!Buffer)
231 1.1 jruoho {
232 1.1 jruoho Status = AE_NO_MEMORY;
233 1.1 jruoho goto Cleanup;
234 1.1 jruoho }
235 1.1 jruoho break;
236 1.1 jruoho
237 1.1 jruoho case ACPI_TYPE_BUFFER:
238 1.1 jruoho
239 1.1 jruoho /* If the requested length is zero, don't allocate a buffer */
240 1.1 jruoho
241 1.1 jruoho if (Length > 0)
242 1.1 jruoho {
243 1.1 jruoho /* Allocate a new buffer for the Buffer */
244 1.1 jruoho
245 1.1 jruoho Buffer = ACPI_ALLOCATE_ZEROED (Length);
246 1.1 jruoho if (!Buffer)
247 1.1 jruoho {
248 1.1 jruoho Status = AE_NO_MEMORY;
249 1.1 jruoho goto Cleanup;
250 1.1 jruoho }
251 1.1 jruoho }
252 1.1 jruoho break;
253 1.1 jruoho
254 1.1 jruoho default: /* Should not happen */
255 1.1 jruoho
256 1.1 jruoho Status = AE_AML_OPERAND_TYPE;
257 1.1 jruoho goto Cleanup;
258 1.1 jruoho }
259 1.1 jruoho
260 1.1 jruoho if (Buffer)
261 1.1 jruoho {
262 1.1 jruoho /* We have a buffer, copy the portion requested */
263 1.1 jruoho
264 1.1 jruoho ACPI_MEMCPY (Buffer, Operand[0]->String.Pointer + Index,
265 1.1 jruoho Length);
266 1.1 jruoho }
267 1.1 jruoho
268 1.1 jruoho /* Set the length of the new String/Buffer */
269 1.1 jruoho
270 1.1 jruoho ReturnDesc->String.Pointer = Buffer;
271 1.1 jruoho ReturnDesc->String.Length = (UINT32) Length;
272 1.1 jruoho
273 1.1 jruoho /* Mark buffer initialized */
274 1.1 jruoho
275 1.1 jruoho ReturnDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
276 1.1 jruoho break;
277 1.1 jruoho
278 1.1 jruoho default:
279 1.1 jruoho
280 1.1 jruoho ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
281 1.1 jruoho WalkState->Opcode));
282 1.1 jruoho Status = AE_AML_BAD_OPCODE;
283 1.1 jruoho goto Cleanup;
284 1.1 jruoho }
285 1.1 jruoho
286 1.1 jruoho /* Store the result in the target */
287 1.1 jruoho
288 1.1 jruoho Status = AcpiExStore (ReturnDesc, Operand[3], WalkState);
289 1.1 jruoho
290 1.1 jruoho Cleanup:
291 1.1 jruoho
292 1.1 jruoho /* Delete return object on error */
293 1.1 jruoho
294 1.1 jruoho if (ACPI_FAILURE (Status) || WalkState->ResultObj)
295 1.1 jruoho {
296 1.1 jruoho AcpiUtRemoveReference (ReturnDesc);
297 1.1 jruoho WalkState->ResultObj = NULL;
298 1.1 jruoho }
299 1.1 jruoho
300 1.1 jruoho /* Set the return object and exit */
301 1.1 jruoho
302 1.1 jruoho else
303 1.1 jruoho {
304 1.1 jruoho WalkState->ResultObj = ReturnDesc;
305 1.1 jruoho }
306 1.1 jruoho return_ACPI_STATUS (Status);
307 1.1 jruoho }
308