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