ReactOS  0.4.14-dev-297-g23e575c
exoparg3.c
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Module Name: exoparg3 - AML execution - opcodes with 3 arguments
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2019, Intel Corp.
9  * All rights reserved.
10  *
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.
25  *
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.
29  *
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.
42  */
43 
44 #include "acpi.h"
45 #include "accommon.h"
46 #include "acinterp.h"
47 #include "acparser.h"
48 #include "amlcode.h"
49 
50 
51 #define _COMPONENT ACPI_EXECUTER
52  ACPI_MODULE_NAME ("exoparg3")
53 
54 
55 
78 /*******************************************************************************
79  *
80  * FUNCTION: AcpiExOpcode_3A_0T_0R
81  *
82  * PARAMETERS: WalkState - Current walk state
83  *
84  * RETURN: Status
85  *
86  * DESCRIPTION: Execute Triadic operator (3 operands)
87  *
88  ******************************************************************************/
89 
92  ACPI_WALK_STATE *WalkState)
93 {
94  ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
97 
98 
99  ACPI_FUNCTION_TRACE_STR (ExOpcode_3A_0T_0R,
100  AcpiPsGetOpcodeName (WalkState->Opcode));
101 
102 
103  switch (WalkState->Opcode)
104  {
105  case AML_FATAL_OP: /* Fatal (FatalType FatalCode FatalArg) */
106 
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));
113 
115  if (Fatal)
116  {
117  Fatal->Type = (UINT32) Operand[0]->Integer.Value;
118  Fatal->Code = (UINT32) Operand[1]->Integer.Value;
119  Fatal->Argument = (UINT32) Operand[2]->Integer.Value;
120  }
121 
122  /* Always signal the OS! */
123 
125 
126  /* Might return while OS is shutting down, just continue */
127 
128  ACPI_FREE (Fatal);
129  goto Cleanup;
130 
131  case AML_EXTERNAL_OP:
132  /*
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.
139  */
140  ACPI_ERROR ((AE_INFO, "Executed External Op"));
141  Status = AE_OK;
142  goto Cleanup;
143 
144  default:
145 
146  ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
147  WalkState->Opcode));
148 
150  goto Cleanup;
151  }
152 
153 
154 Cleanup:
155 
157 }
158 
159 
160 /*******************************************************************************
161  *
162  * FUNCTION: AcpiExOpcode_3A_1T_1R
163  *
164  * PARAMETERS: WalkState - Current walk state
165  *
166  * RETURN: Status
167  *
168  * DESCRIPTION: Execute Triadic operator (3 operands)
169  *
170  ******************************************************************************/
171 
174  ACPI_WALK_STATE *WalkState)
175 {
176  ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
177  ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
178  char *Buffer = NULL;
180  UINT64 Index;
181  ACPI_SIZE Length;
182 
183 
184  ACPI_FUNCTION_TRACE_STR (ExOpcode_3A_1T_1R,
185  AcpiPsGetOpcodeName (WalkState->Opcode));
186 
187 
188  switch (WalkState->Opcode)
189  {
190  case AML_MID_OP: /* Mid (Source[0], Index[1], Length[2], Result[3]) */
191  /*
192  * Create the return object. The Source operand is guaranteed to be
193  * either a String or a Buffer, so just use its type.
194  */
195  ReturnDesc = AcpiUtCreateInternalObject (
196  (Operand[0])->Common.Type);
197  if (!ReturnDesc)
198  {
200  goto Cleanup;
201  }
202 
203  /* Get the Integer values from the objects */
204 
205  Index = Operand[1]->Integer.Value;
206  Length = (ACPI_SIZE) Operand[2]->Integer.Value;
207 
208  /*
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
211  */
212  if (Index >= Operand[0]->String.Length)
213  {
214  Length = 0;
215  }
216 
217  /* Truncate request if larger than the actual String/Buffer */
218 
219  else if ((Index + Length) > Operand[0]->String.Length)
220  {
221  Length =
222  (ACPI_SIZE) Operand[0]->String.Length - (ACPI_SIZE) Index;
223  }
224 
225  /* Strings always have a sub-pointer, not so for buffers */
226 
227  switch ((Operand[0])->Common.Type)
228  {
229  case ACPI_TYPE_STRING:
230 
231  /* Always allocate a new buffer for the String */
232 
233  Buffer = ACPI_ALLOCATE_ZEROED ((ACPI_SIZE) Length + 1);
234  if (!Buffer)
235  {
237  goto Cleanup;
238  }
239  break;
240 
241  case ACPI_TYPE_BUFFER:
242 
243  /* If the requested length is zero, don't allocate a buffer */
244 
245  if (Length > 0)
246  {
247  /* Allocate a new buffer for the Buffer */
248 
250  if (!Buffer)
251  {
253  goto Cleanup;
254  }
255  }
256  break;
257 
258  default: /* Should not happen */
259 
261  goto Cleanup;
262  }
263 
264  if (Buffer)
265  {
266  /* We have a buffer, copy the portion requested */
267 
268  memcpy (Buffer,
269  Operand[0]->String.Pointer + Index, Length);
270  }
271 
272  /* Set the length of the new String/Buffer */
273 
274  ReturnDesc->String.Pointer = Buffer;
275  ReturnDesc->String.Length = (UINT32) Length;
276 
277  /* Mark buffer initialized */
278 
279  ReturnDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
280  break;
281 
282  default:
283 
284  ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
285  WalkState->Opcode));
286 
288  goto Cleanup;
289  }
290 
291  /* Store the result in the target */
292 
293  Status = AcpiExStore (ReturnDesc, Operand[3], WalkState);
294 
295 Cleanup:
296 
297  /* Delete return object on error */
298 
299  if (ACPI_FAILURE (Status) || WalkState->ResultObj)
300  {
301  AcpiUtRemoveReference (ReturnDesc);
302  WalkState->ResultObj = NULL;
303  }
304  else
305  {
306  /* Set the return object and exit */
307 
308  WalkState->ResultObj = ReturnDesc;
309  }
310 
312 }
ACPI_STATUS AcpiExOpcode_3A_0T_0R(ACPI_WALK_STATE *WalkState)
Definition: exoparg3.c:91
#define ACPI_FREE(a)
Definition: actypes.h:386
#define ACPI_ALLOCATE_ZEROED(a)
Definition: actypes.h:385
const char * AcpiPsGetOpcodeName(UINT16 Opcode)
Definition: psopinfo.c:169
ACPI_STATUS AcpiExStore(ACPI_OPERAND_OBJECT *SourceDesc, ACPI_OPERAND_OBJECT *DestDesc, ACPI_WALK_STATE *WalkState)
Definition: exstore.c:91
#define AE_NO_MEMORY
Definition: acexcep.h:112
#define AML_MID_OP
Definition: amlcode.h:132
#define ACPI_TYPE_BUFFER
Definition: actypes.h:681
ACPI_STATUS AcpiOsSignal(UINT32 Function, void *Info)
Definition: osl.c:904
static WCHAR String[]
Definition: stringtable.c:55
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define AE_AML_OPERAND_TYPE
Definition: acexcep.h:182
#define AML_EXTERNAL_OP
Definition: amlcode.h:65
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define ACPI_ALLOCATE(a)
Definition: actypes.h:384
void Fatal(const char *filename, unsigned nLine, const char *pcLine, const char *pc, size_t errorlen, const char *format,...)
Definition: spec2def.c:811
unsigned int UINT32
#define ACPI_MODULE_NAME(Name)
Definition: acoutput.h:216
smooth NULL
Definition: ftsmooth.c:416
#define AE_INFO
Definition: acoutput.h:230
#define AE_AML_BAD_OPCODE
Definition: acexcep.h:180
Definition: bufpool.h:45
ACPI_OBJECT_BUFFER Buffer
Definition: acobject.h:519
union acpi_operand_object * ResultObj
Definition: acstruct.h:121
ACPI_STATUS AcpiExOpcode_3A_1T_1R(ACPI_WALK_STATE *WalkState)
Definition: exoparg3.c:173
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
static const UCHAR Index[8]
Definition: usbohci.c:18
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ACPI_OBJECT_INTEGER Integer
Definition: acobject.h:517
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static const WCHAR Cleanup[]
Definition: register.c:80
ACPI_OBJECT_STRING String
Definition: acobject.h:518
Status
Definition: gdiplustypes.h:24
union acpi_operand_object * Operands[ACPI_OBJ_NUM_OPERANDS+1]
Definition: acstruct.h:105
#define ACPI_DB_INFO
Definition: acoutput.h:153
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define AML_FATAL_OP
Definition: amlcode.h:178
#define ACPI_FUNCTION_TRACE_STR(a, b)
Definition: acoutput.h:483
void AcpiUtRemoveReference(ACPI_OPERAND_OBJECT *Object)
Definition: utdelete.c:784
#define ACPI_ERROR(plist)
Definition: acoutput.h:240
#define AOPOBJ_DATA_VALID
Definition: acobject.h:96
UINT16 Opcode
Definition: acstruct.h:78
#define ACPI_TYPE_STRING
Definition: actypes.h:680
#define AcpiUtCreateInternalObject(t)
Definition: acutils.h:654
unsigned long long UINT64
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define AE_OK
Definition: acexcep.h:97
#define ACPI_SIGNAL_FATAL
Definition: acpiosxf.h:73