exmisc.c revision 1.1.1.2 1 1.1 jruoho
2 1.1 jruoho /******************************************************************************
3 1.1 jruoho *
4 1.1 jruoho * Module Name: exmisc - ACPI AML (p-code) execution - specific opcodes
5 1.1 jruoho *
6 1.1 jruoho *****************************************************************************/
7 1.1 jruoho
8 1.1.1.2 jruoho /*
9 1.1.1.2 jruoho * Copyright (C) 2000 - 2011, Intel Corp.
10 1.1 jruoho * All rights reserved.
11 1.1 jruoho *
12 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
13 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
14 1.1.1.2 jruoho * are met:
15 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
16 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
17 1.1.1.2 jruoho * without modification.
18 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
20 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
21 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
22 1.1.1.2 jruoho * binary redistribution.
23 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
24 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
25 1.1.1.2 jruoho * from this software without specific prior written permission.
26 1.1.1.2 jruoho *
27 1.1.1.2 jruoho * Alternatively, this software may be distributed under the terms of the
28 1.1.1.2 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
29 1.1.1.2 jruoho * Software Foundation.
30 1.1.1.2 jruoho *
31 1.1.1.2 jruoho * NO WARRANTY
32 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 1.1.1.2 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 1.1.1.2 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1.1.2 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1.1.2 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1.1.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 1.1.1.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 1.1.1.2 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 1.1.1.2 jruoho * POSSIBILITY OF SUCH DAMAGES.
43 1.1.1.2 jruoho */
44 1.1 jruoho
45 1.1 jruoho #define __EXMISC_C__
46 1.1 jruoho
47 1.1 jruoho #include "acpi.h"
48 1.1 jruoho #include "accommon.h"
49 1.1 jruoho #include "acinterp.h"
50 1.1 jruoho #include "amlcode.h"
51 1.1 jruoho #include "amlresrc.h"
52 1.1 jruoho
53 1.1 jruoho
54 1.1 jruoho #define _COMPONENT ACPI_EXECUTER
55 1.1 jruoho ACPI_MODULE_NAME ("exmisc")
56 1.1 jruoho
57 1.1 jruoho
58 1.1 jruoho /*******************************************************************************
59 1.1 jruoho *
60 1.1 jruoho * FUNCTION: AcpiExGetObjectReference
61 1.1 jruoho *
62 1.1 jruoho * PARAMETERS: ObjDesc - Create a reference to this object
63 1.1 jruoho * ReturnDesc - Where to store the reference
64 1.1 jruoho * WalkState - Current state
65 1.1 jruoho *
66 1.1 jruoho * RETURN: Status
67 1.1 jruoho *
68 1.1 jruoho * DESCRIPTION: Obtain and return a "reference" to the target object
69 1.1 jruoho * Common code for the RefOfOp and the CondRefOfOp.
70 1.1 jruoho *
71 1.1 jruoho ******************************************************************************/
72 1.1 jruoho
73 1.1 jruoho ACPI_STATUS
74 1.1 jruoho AcpiExGetObjectReference (
75 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc,
76 1.1 jruoho ACPI_OPERAND_OBJECT **ReturnDesc,
77 1.1 jruoho ACPI_WALK_STATE *WalkState)
78 1.1 jruoho {
79 1.1 jruoho ACPI_OPERAND_OBJECT *ReferenceObj;
80 1.1 jruoho ACPI_OPERAND_OBJECT *ReferencedObj;
81 1.1 jruoho
82 1.1 jruoho
83 1.1 jruoho ACPI_FUNCTION_TRACE_PTR (ExGetObjectReference, ObjDesc);
84 1.1 jruoho
85 1.1 jruoho
86 1.1 jruoho *ReturnDesc = NULL;
87 1.1 jruoho
88 1.1 jruoho switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
89 1.1 jruoho {
90 1.1 jruoho case ACPI_DESC_TYPE_OPERAND:
91 1.1 jruoho
92 1.1 jruoho if (ObjDesc->Common.Type != ACPI_TYPE_LOCAL_REFERENCE)
93 1.1 jruoho {
94 1.1 jruoho return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
95 1.1 jruoho }
96 1.1 jruoho
97 1.1 jruoho /*
98 1.1 jruoho * Must be a reference to a Local or Arg
99 1.1 jruoho */
100 1.1 jruoho switch (ObjDesc->Reference.Class)
101 1.1 jruoho {
102 1.1 jruoho case ACPI_REFCLASS_LOCAL:
103 1.1 jruoho case ACPI_REFCLASS_ARG:
104 1.1 jruoho case ACPI_REFCLASS_DEBUG:
105 1.1 jruoho
106 1.1 jruoho /* The referenced object is the pseudo-node for the local/arg */
107 1.1 jruoho
108 1.1 jruoho ReferencedObj = ObjDesc->Reference.Object;
109 1.1 jruoho break;
110 1.1 jruoho
111 1.1 jruoho default:
112 1.1 jruoho
113 1.1 jruoho ACPI_ERROR ((AE_INFO, "Unknown Reference Class 0x%2.2X",
114 1.1 jruoho ObjDesc->Reference.Class));
115 1.1 jruoho return_ACPI_STATUS (AE_AML_INTERNAL);
116 1.1 jruoho }
117 1.1 jruoho break;
118 1.1 jruoho
119 1.1 jruoho
120 1.1 jruoho case ACPI_DESC_TYPE_NAMED:
121 1.1 jruoho
122 1.1 jruoho /*
123 1.1 jruoho * A named reference that has already been resolved to a Node
124 1.1 jruoho */
125 1.1 jruoho ReferencedObj = ObjDesc;
126 1.1 jruoho break;
127 1.1 jruoho
128 1.1 jruoho
129 1.1 jruoho default:
130 1.1 jruoho
131 1.1 jruoho ACPI_ERROR ((AE_INFO, "Invalid descriptor type 0x%X",
132 1.1 jruoho ACPI_GET_DESCRIPTOR_TYPE (ObjDesc)));
133 1.1 jruoho return_ACPI_STATUS (AE_TYPE);
134 1.1 jruoho }
135 1.1 jruoho
136 1.1 jruoho
137 1.1 jruoho /* Create a new reference object */
138 1.1 jruoho
139 1.1 jruoho ReferenceObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
140 1.1 jruoho if (!ReferenceObj)
141 1.1 jruoho {
142 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
143 1.1 jruoho }
144 1.1 jruoho
145 1.1 jruoho ReferenceObj->Reference.Class = ACPI_REFCLASS_REFOF;
146 1.1 jruoho ReferenceObj->Reference.Object = ReferencedObj;
147 1.1 jruoho *ReturnDesc = ReferenceObj;
148 1.1 jruoho
149 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
150 1.1 jruoho "Object %p Type [%s], returning Reference %p\n",
151 1.1 jruoho ObjDesc, AcpiUtGetObjectTypeName (ObjDesc), *ReturnDesc));
152 1.1 jruoho
153 1.1 jruoho return_ACPI_STATUS (AE_OK);
154 1.1 jruoho }
155 1.1 jruoho
156 1.1 jruoho
157 1.1 jruoho /*******************************************************************************
158 1.1 jruoho *
159 1.1 jruoho * FUNCTION: AcpiExConcatTemplate
160 1.1 jruoho *
161 1.1 jruoho * PARAMETERS: Operand0 - First source object
162 1.1 jruoho * Operand1 - Second source object
163 1.1 jruoho * ActualReturnDesc - Where to place the return object
164 1.1 jruoho * WalkState - Current walk state
165 1.1 jruoho *
166 1.1 jruoho * RETURN: Status
167 1.1 jruoho *
168 1.1 jruoho * DESCRIPTION: Concatenate two resource templates
169 1.1 jruoho *
170 1.1 jruoho ******************************************************************************/
171 1.1 jruoho
172 1.1 jruoho ACPI_STATUS
173 1.1 jruoho AcpiExConcatTemplate (
174 1.1 jruoho ACPI_OPERAND_OBJECT *Operand0,
175 1.1 jruoho ACPI_OPERAND_OBJECT *Operand1,
176 1.1 jruoho ACPI_OPERAND_OBJECT **ActualReturnDesc,
177 1.1 jruoho ACPI_WALK_STATE *WalkState)
178 1.1 jruoho {
179 1.1 jruoho ACPI_STATUS Status;
180 1.1 jruoho ACPI_OPERAND_OBJECT *ReturnDesc;
181 1.1 jruoho UINT8 *NewBuf;
182 1.1 jruoho UINT8 *EndTag;
183 1.1 jruoho ACPI_SIZE Length0;
184 1.1 jruoho ACPI_SIZE Length1;
185 1.1 jruoho ACPI_SIZE NewLength;
186 1.1 jruoho
187 1.1 jruoho
188 1.1 jruoho ACPI_FUNCTION_TRACE (ExConcatTemplate);
189 1.1 jruoho
190 1.1 jruoho
191 1.1 jruoho /*
192 1.1 jruoho * Find the EndTag descriptor in each resource template.
193 1.1 jruoho * Note1: returned pointers point TO the EndTag, not past it.
194 1.1 jruoho * Note2: zero-length buffers are allowed; treated like one EndTag
195 1.1 jruoho */
196 1.1 jruoho
197 1.1 jruoho /* Get the length of the first resource template */
198 1.1 jruoho
199 1.1 jruoho Status = AcpiUtGetResourceEndTag (Operand0, &EndTag);
200 1.1 jruoho if (ACPI_FAILURE (Status))
201 1.1 jruoho {
202 1.1 jruoho return_ACPI_STATUS (Status);
203 1.1 jruoho }
204 1.1 jruoho
205 1.1 jruoho Length0 = ACPI_PTR_DIFF (EndTag, Operand0->Buffer.Pointer);
206 1.1 jruoho
207 1.1 jruoho /* Get the length of the second resource template */
208 1.1 jruoho
209 1.1 jruoho Status = AcpiUtGetResourceEndTag (Operand1, &EndTag);
210 1.1 jruoho if (ACPI_FAILURE (Status))
211 1.1 jruoho {
212 1.1 jruoho return_ACPI_STATUS (Status);
213 1.1 jruoho }
214 1.1 jruoho
215 1.1 jruoho Length1 = ACPI_PTR_DIFF (EndTag, Operand1->Buffer.Pointer);
216 1.1 jruoho
217 1.1 jruoho /* Combine both lengths, minimum size will be 2 for EndTag */
218 1.1 jruoho
219 1.1 jruoho NewLength = Length0 + Length1 + sizeof (AML_RESOURCE_END_TAG);
220 1.1 jruoho
221 1.1 jruoho /* Create a new buffer object for the result (with one EndTag) */
222 1.1 jruoho
223 1.1 jruoho ReturnDesc = AcpiUtCreateBufferObject (NewLength);
224 1.1 jruoho if (!ReturnDesc)
225 1.1 jruoho {
226 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
227 1.1 jruoho }
228 1.1 jruoho
229 1.1 jruoho /*
230 1.1 jruoho * Copy the templates to the new buffer, 0 first, then 1 follows. One
231 1.1 jruoho * EndTag descriptor is copied from Operand1.
232 1.1 jruoho */
233 1.1 jruoho NewBuf = ReturnDesc->Buffer.Pointer;
234 1.1 jruoho ACPI_MEMCPY (NewBuf, Operand0->Buffer.Pointer, Length0);
235 1.1 jruoho ACPI_MEMCPY (NewBuf + Length0, Operand1->Buffer.Pointer, Length1);
236 1.1 jruoho
237 1.1 jruoho /* Insert EndTag and set the checksum to zero, means "ignore checksum" */
238 1.1 jruoho
239 1.1 jruoho NewBuf[NewLength - 1] = 0;
240 1.1 jruoho NewBuf[NewLength - 2] = ACPI_RESOURCE_NAME_END_TAG | 1;
241 1.1 jruoho
242 1.1 jruoho /* Return the completed resource template */
243 1.1 jruoho
244 1.1 jruoho *ActualReturnDesc = ReturnDesc;
245 1.1 jruoho return_ACPI_STATUS (AE_OK);
246 1.1 jruoho }
247 1.1 jruoho
248 1.1 jruoho
249 1.1 jruoho /*******************************************************************************
250 1.1 jruoho *
251 1.1 jruoho * FUNCTION: AcpiExDoConcatenate
252 1.1 jruoho *
253 1.1 jruoho * PARAMETERS: Operand0 - First source object
254 1.1 jruoho * Operand1 - Second source object
255 1.1 jruoho * ActualReturnDesc - Where to place the return object
256 1.1 jruoho * WalkState - Current walk state
257 1.1 jruoho *
258 1.1 jruoho * RETURN: Status
259 1.1 jruoho *
260 1.1 jruoho * DESCRIPTION: Concatenate two objects OF THE SAME TYPE.
261 1.1 jruoho *
262 1.1 jruoho ******************************************************************************/
263 1.1 jruoho
264 1.1 jruoho ACPI_STATUS
265 1.1 jruoho AcpiExDoConcatenate (
266 1.1 jruoho ACPI_OPERAND_OBJECT *Operand0,
267 1.1 jruoho ACPI_OPERAND_OBJECT *Operand1,
268 1.1 jruoho ACPI_OPERAND_OBJECT **ActualReturnDesc,
269 1.1 jruoho ACPI_WALK_STATE *WalkState)
270 1.1 jruoho {
271 1.1 jruoho ACPI_OPERAND_OBJECT *LocalOperand1 = Operand1;
272 1.1 jruoho ACPI_OPERAND_OBJECT *ReturnDesc;
273 1.1 jruoho char *NewBuf;
274 1.1 jruoho ACPI_STATUS Status;
275 1.1 jruoho
276 1.1 jruoho
277 1.1 jruoho ACPI_FUNCTION_TRACE (ExDoConcatenate);
278 1.1 jruoho
279 1.1 jruoho
280 1.1 jruoho /*
281 1.1 jruoho * Convert the second operand if necessary. The first operand
282 1.1 jruoho * determines the type of the second operand, (See the Data Types
283 1.1 jruoho * section of the ACPI specification.) Both object types are
284 1.1 jruoho * guaranteed to be either Integer/String/Buffer by the operand
285 1.1 jruoho * resolution mechanism.
286 1.1 jruoho */
287 1.1 jruoho switch (Operand0->Common.Type)
288 1.1 jruoho {
289 1.1 jruoho case ACPI_TYPE_INTEGER:
290 1.1 jruoho Status = AcpiExConvertToInteger (Operand1, &LocalOperand1, 16);
291 1.1 jruoho break;
292 1.1 jruoho
293 1.1 jruoho case ACPI_TYPE_STRING:
294 1.1 jruoho Status = AcpiExConvertToString (Operand1, &LocalOperand1,
295 1.1 jruoho ACPI_IMPLICIT_CONVERT_HEX);
296 1.1 jruoho break;
297 1.1 jruoho
298 1.1 jruoho case ACPI_TYPE_BUFFER:
299 1.1 jruoho Status = AcpiExConvertToBuffer (Operand1, &LocalOperand1);
300 1.1 jruoho break;
301 1.1 jruoho
302 1.1 jruoho default:
303 1.1 jruoho ACPI_ERROR ((AE_INFO, "Invalid object type: 0x%X",
304 1.1 jruoho Operand0->Common.Type));
305 1.1 jruoho Status = AE_AML_INTERNAL;
306 1.1 jruoho }
307 1.1 jruoho
308 1.1 jruoho if (ACPI_FAILURE (Status))
309 1.1 jruoho {
310 1.1 jruoho goto Cleanup;
311 1.1 jruoho }
312 1.1 jruoho
313 1.1 jruoho /*
314 1.1 jruoho * Both operands are now known to be the same object type
315 1.1 jruoho * (Both are Integer, String, or Buffer), and we can now perform the
316 1.1 jruoho * concatenation.
317 1.1 jruoho */
318 1.1 jruoho
319 1.1 jruoho /*
320 1.1 jruoho * There are three cases to handle:
321 1.1 jruoho *
322 1.1 jruoho * 1) Two Integers concatenated to produce a new Buffer
323 1.1 jruoho * 2) Two Strings concatenated to produce a new String
324 1.1 jruoho * 3) Two Buffers concatenated to produce a new Buffer
325 1.1 jruoho */
326 1.1 jruoho switch (Operand0->Common.Type)
327 1.1 jruoho {
328 1.1 jruoho case ACPI_TYPE_INTEGER:
329 1.1 jruoho
330 1.1 jruoho /* Result of two Integers is a Buffer */
331 1.1 jruoho /* Need enough buffer space for two integers */
332 1.1 jruoho
333 1.1 jruoho ReturnDesc = AcpiUtCreateBufferObject ((ACPI_SIZE)
334 1.1 jruoho ACPI_MUL_2 (AcpiGbl_IntegerByteWidth));
335 1.1 jruoho if (!ReturnDesc)
336 1.1 jruoho {
337 1.1 jruoho Status = AE_NO_MEMORY;
338 1.1 jruoho goto Cleanup;
339 1.1 jruoho }
340 1.1 jruoho
341 1.1 jruoho NewBuf = (char *) ReturnDesc->Buffer.Pointer;
342 1.1 jruoho
343 1.1 jruoho /* Copy the first integer, LSB first */
344 1.1 jruoho
345 1.1 jruoho ACPI_MEMCPY (NewBuf, &Operand0->Integer.Value,
346 1.1 jruoho AcpiGbl_IntegerByteWidth);
347 1.1 jruoho
348 1.1 jruoho /* Copy the second integer (LSB first) after the first */
349 1.1 jruoho
350 1.1 jruoho ACPI_MEMCPY (NewBuf + AcpiGbl_IntegerByteWidth,
351 1.1 jruoho &LocalOperand1->Integer.Value,
352 1.1 jruoho AcpiGbl_IntegerByteWidth);
353 1.1 jruoho break;
354 1.1 jruoho
355 1.1 jruoho case ACPI_TYPE_STRING:
356 1.1 jruoho
357 1.1 jruoho /* Result of two Strings is a String */
358 1.1 jruoho
359 1.1 jruoho ReturnDesc = AcpiUtCreateStringObject (
360 1.1 jruoho ((ACPI_SIZE) Operand0->String.Length +
361 1.1 jruoho LocalOperand1->String.Length));
362 1.1 jruoho if (!ReturnDesc)
363 1.1 jruoho {
364 1.1 jruoho Status = AE_NO_MEMORY;
365 1.1 jruoho goto Cleanup;
366 1.1 jruoho }
367 1.1 jruoho
368 1.1 jruoho NewBuf = ReturnDesc->String.Pointer;
369 1.1 jruoho
370 1.1 jruoho /* Concatenate the strings */
371 1.1 jruoho
372 1.1 jruoho ACPI_STRCPY (NewBuf, Operand0->String.Pointer);
373 1.1 jruoho ACPI_STRCPY (NewBuf + Operand0->String.Length,
374 1.1 jruoho LocalOperand1->String.Pointer);
375 1.1 jruoho break;
376 1.1 jruoho
377 1.1 jruoho case ACPI_TYPE_BUFFER:
378 1.1 jruoho
379 1.1 jruoho /* Result of two Buffers is a Buffer */
380 1.1 jruoho
381 1.1 jruoho ReturnDesc = AcpiUtCreateBufferObject (
382 1.1 jruoho ((ACPI_SIZE) Operand0->Buffer.Length +
383 1.1 jruoho LocalOperand1->Buffer.Length));
384 1.1 jruoho if (!ReturnDesc)
385 1.1 jruoho {
386 1.1 jruoho Status = AE_NO_MEMORY;
387 1.1 jruoho goto Cleanup;
388 1.1 jruoho }
389 1.1 jruoho
390 1.1 jruoho NewBuf = (char *) ReturnDesc->Buffer.Pointer;
391 1.1 jruoho
392 1.1 jruoho /* Concatenate the buffers */
393 1.1 jruoho
394 1.1 jruoho ACPI_MEMCPY (NewBuf, Operand0->Buffer.Pointer,
395 1.1 jruoho Operand0->Buffer.Length);
396 1.1 jruoho ACPI_MEMCPY (NewBuf + Operand0->Buffer.Length,
397 1.1 jruoho LocalOperand1->Buffer.Pointer,
398 1.1 jruoho LocalOperand1->Buffer.Length);
399 1.1 jruoho break;
400 1.1 jruoho
401 1.1 jruoho default:
402 1.1 jruoho
403 1.1 jruoho /* Invalid object type, should not happen here */
404 1.1 jruoho
405 1.1 jruoho ACPI_ERROR ((AE_INFO, "Invalid object type: 0x%X",
406 1.1 jruoho Operand0->Common.Type));
407 1.1 jruoho Status =AE_AML_INTERNAL;
408 1.1 jruoho goto Cleanup;
409 1.1 jruoho }
410 1.1 jruoho
411 1.1 jruoho *ActualReturnDesc = ReturnDesc;
412 1.1 jruoho
413 1.1 jruoho Cleanup:
414 1.1 jruoho if (LocalOperand1 != Operand1)
415 1.1 jruoho {
416 1.1 jruoho AcpiUtRemoveReference (LocalOperand1);
417 1.1 jruoho }
418 1.1 jruoho return_ACPI_STATUS (Status);
419 1.1 jruoho }
420 1.1 jruoho
421 1.1 jruoho
422 1.1 jruoho /*******************************************************************************
423 1.1 jruoho *
424 1.1 jruoho * FUNCTION: AcpiExDoMathOp
425 1.1 jruoho *
426 1.1 jruoho * PARAMETERS: Opcode - AML opcode
427 1.1 jruoho * Integer0 - Integer operand #0
428 1.1 jruoho * Integer1 - Integer operand #1
429 1.1 jruoho *
430 1.1 jruoho * RETURN: Integer result of the operation
431 1.1 jruoho *
432 1.1 jruoho * DESCRIPTION: Execute a math AML opcode. The purpose of having all of the
433 1.1 jruoho * math functions here is to prevent a lot of pointer dereferencing
434 1.1 jruoho * to obtain the operands.
435 1.1 jruoho *
436 1.1 jruoho ******************************************************************************/
437 1.1 jruoho
438 1.1 jruoho UINT64
439 1.1 jruoho AcpiExDoMathOp (
440 1.1 jruoho UINT16 Opcode,
441 1.1 jruoho UINT64 Integer0,
442 1.1 jruoho UINT64 Integer1)
443 1.1 jruoho {
444 1.1 jruoho
445 1.1 jruoho ACPI_FUNCTION_ENTRY ();
446 1.1 jruoho
447 1.1 jruoho
448 1.1 jruoho switch (Opcode)
449 1.1 jruoho {
450 1.1 jruoho case AML_ADD_OP: /* Add (Integer0, Integer1, Result) */
451 1.1 jruoho
452 1.1 jruoho return (Integer0 + Integer1);
453 1.1 jruoho
454 1.1 jruoho
455 1.1 jruoho case AML_BIT_AND_OP: /* And (Integer0, Integer1, Result) */
456 1.1 jruoho
457 1.1 jruoho return (Integer0 & Integer1);
458 1.1 jruoho
459 1.1 jruoho
460 1.1 jruoho case AML_BIT_NAND_OP: /* NAnd (Integer0, Integer1, Result) */
461 1.1 jruoho
462 1.1 jruoho return (~(Integer0 & Integer1));
463 1.1 jruoho
464 1.1 jruoho
465 1.1 jruoho case AML_BIT_OR_OP: /* Or (Integer0, Integer1, Result) */
466 1.1 jruoho
467 1.1 jruoho return (Integer0 | Integer1);
468 1.1 jruoho
469 1.1 jruoho
470 1.1 jruoho case AML_BIT_NOR_OP: /* NOr (Integer0, Integer1, Result) */
471 1.1 jruoho
472 1.1 jruoho return (~(Integer0 | Integer1));
473 1.1 jruoho
474 1.1 jruoho
475 1.1 jruoho case AML_BIT_XOR_OP: /* XOr (Integer0, Integer1, Result) */
476 1.1 jruoho
477 1.1 jruoho return (Integer0 ^ Integer1);
478 1.1 jruoho
479 1.1 jruoho
480 1.1 jruoho case AML_MULTIPLY_OP: /* Multiply (Integer0, Integer1, Result) */
481 1.1 jruoho
482 1.1 jruoho return (Integer0 * Integer1);
483 1.1 jruoho
484 1.1 jruoho
485 1.1 jruoho case AML_SHIFT_LEFT_OP: /* ShiftLeft (Operand, ShiftCount, Result)*/
486 1.1 jruoho
487 1.1 jruoho /*
488 1.1 jruoho * We need to check if the shiftcount is larger than the integer bit
489 1.1 jruoho * width since the behavior of this is not well-defined in the C language.
490 1.1 jruoho */
491 1.1 jruoho if (Integer1 >= AcpiGbl_IntegerBitWidth)
492 1.1 jruoho {
493 1.1 jruoho return (0);
494 1.1 jruoho }
495 1.1 jruoho return (Integer0 << Integer1);
496 1.1 jruoho
497 1.1 jruoho
498 1.1 jruoho case AML_SHIFT_RIGHT_OP: /* ShiftRight (Operand, ShiftCount, Result) */
499 1.1 jruoho
500 1.1 jruoho /*
501 1.1 jruoho * We need to check if the shiftcount is larger than the integer bit
502 1.1 jruoho * width since the behavior of this is not well-defined in the C language.
503 1.1 jruoho */
504 1.1 jruoho if (Integer1 >= AcpiGbl_IntegerBitWidth)
505 1.1 jruoho {
506 1.1 jruoho return (0);
507 1.1 jruoho }
508 1.1 jruoho return (Integer0 >> Integer1);
509 1.1 jruoho
510 1.1 jruoho
511 1.1 jruoho case AML_SUBTRACT_OP: /* Subtract (Integer0, Integer1, Result) */
512 1.1 jruoho
513 1.1 jruoho return (Integer0 - Integer1);
514 1.1 jruoho
515 1.1 jruoho default:
516 1.1 jruoho
517 1.1 jruoho return (0);
518 1.1 jruoho }
519 1.1 jruoho }
520 1.1 jruoho
521 1.1 jruoho
522 1.1 jruoho /*******************************************************************************
523 1.1 jruoho *
524 1.1 jruoho * FUNCTION: AcpiExDoLogicalNumericOp
525 1.1 jruoho *
526 1.1 jruoho * PARAMETERS: Opcode - AML opcode
527 1.1 jruoho * Integer0 - Integer operand #0
528 1.1 jruoho * Integer1 - Integer operand #1
529 1.1 jruoho * LogicalResult - TRUE/FALSE result of the operation
530 1.1 jruoho *
531 1.1 jruoho * RETURN: Status
532 1.1 jruoho *
533 1.1 jruoho * DESCRIPTION: Execute a logical "Numeric" AML opcode. For these Numeric
534 1.1 jruoho * operators (LAnd and LOr), both operands must be integers.
535 1.1 jruoho *
536 1.1 jruoho * Note: cleanest machine code seems to be produced by the code
537 1.1 jruoho * below, rather than using statements of the form:
538 1.1 jruoho * Result = (Integer0 && Integer1);
539 1.1 jruoho *
540 1.1 jruoho ******************************************************************************/
541 1.1 jruoho
542 1.1 jruoho ACPI_STATUS
543 1.1 jruoho AcpiExDoLogicalNumericOp (
544 1.1 jruoho UINT16 Opcode,
545 1.1 jruoho UINT64 Integer0,
546 1.1 jruoho UINT64 Integer1,
547 1.1 jruoho BOOLEAN *LogicalResult)
548 1.1 jruoho {
549 1.1 jruoho ACPI_STATUS Status = AE_OK;
550 1.1 jruoho BOOLEAN LocalResult = FALSE;
551 1.1 jruoho
552 1.1 jruoho
553 1.1 jruoho ACPI_FUNCTION_TRACE (ExDoLogicalNumericOp);
554 1.1 jruoho
555 1.1 jruoho
556 1.1 jruoho switch (Opcode)
557 1.1 jruoho {
558 1.1 jruoho case AML_LAND_OP: /* LAnd (Integer0, Integer1) */
559 1.1 jruoho
560 1.1 jruoho if (Integer0 && Integer1)
561 1.1 jruoho {
562 1.1 jruoho LocalResult = TRUE;
563 1.1 jruoho }
564 1.1 jruoho break;
565 1.1 jruoho
566 1.1 jruoho case AML_LOR_OP: /* LOr (Integer0, Integer1) */
567 1.1 jruoho
568 1.1 jruoho if (Integer0 || Integer1)
569 1.1 jruoho {
570 1.1 jruoho LocalResult = TRUE;
571 1.1 jruoho }
572 1.1 jruoho break;
573 1.1 jruoho
574 1.1 jruoho default:
575 1.1 jruoho Status = AE_AML_INTERNAL;
576 1.1 jruoho break;
577 1.1 jruoho }
578 1.1 jruoho
579 1.1 jruoho /* Return the logical result and status */
580 1.1 jruoho
581 1.1 jruoho *LogicalResult = LocalResult;
582 1.1 jruoho return_ACPI_STATUS (Status);
583 1.1 jruoho }
584 1.1 jruoho
585 1.1 jruoho
586 1.1 jruoho /*******************************************************************************
587 1.1 jruoho *
588 1.1 jruoho * FUNCTION: AcpiExDoLogicalOp
589 1.1 jruoho *
590 1.1 jruoho * PARAMETERS: Opcode - AML opcode
591 1.1 jruoho * Operand0 - operand #0
592 1.1 jruoho * Operand1 - operand #1
593 1.1 jruoho * LogicalResult - TRUE/FALSE result of the operation
594 1.1 jruoho *
595 1.1 jruoho * RETURN: Status
596 1.1 jruoho *
597 1.1 jruoho * DESCRIPTION: Execute a logical AML opcode. The purpose of having all of the
598 1.1 jruoho * functions here is to prevent a lot of pointer dereferencing
599 1.1 jruoho * to obtain the operands and to simplify the generation of the
600 1.1 jruoho * logical value. For the Numeric operators (LAnd and LOr), both
601 1.1 jruoho * operands must be integers. For the other logical operators,
602 1.1 jruoho * operands can be any combination of Integer/String/Buffer. The
603 1.1 jruoho * first operand determines the type to which the second operand
604 1.1 jruoho * will be converted.
605 1.1 jruoho *
606 1.1 jruoho * Note: cleanest machine code seems to be produced by the code
607 1.1 jruoho * below, rather than using statements of the form:
608 1.1 jruoho * Result = (Operand0 == Operand1);
609 1.1 jruoho *
610 1.1 jruoho ******************************************************************************/
611 1.1 jruoho
612 1.1 jruoho ACPI_STATUS
613 1.1 jruoho AcpiExDoLogicalOp (
614 1.1 jruoho UINT16 Opcode,
615 1.1 jruoho ACPI_OPERAND_OBJECT *Operand0,
616 1.1 jruoho ACPI_OPERAND_OBJECT *Operand1,
617 1.1 jruoho BOOLEAN *LogicalResult)
618 1.1 jruoho {
619 1.1 jruoho ACPI_OPERAND_OBJECT *LocalOperand1 = Operand1;
620 1.1 jruoho UINT64 Integer0;
621 1.1 jruoho UINT64 Integer1;
622 1.1 jruoho UINT32 Length0;
623 1.1 jruoho UINT32 Length1;
624 1.1 jruoho ACPI_STATUS Status = AE_OK;
625 1.1 jruoho BOOLEAN LocalResult = FALSE;
626 1.1 jruoho int Compare;
627 1.1 jruoho
628 1.1 jruoho
629 1.1 jruoho ACPI_FUNCTION_TRACE (ExDoLogicalOp);
630 1.1 jruoho
631 1.1 jruoho
632 1.1 jruoho /*
633 1.1 jruoho * Convert the second operand if necessary. The first operand
634 1.1 jruoho * determines the type of the second operand, (See the Data Types
635 1.1 jruoho * section of the ACPI 3.0+ specification.) Both object types are
636 1.1 jruoho * guaranteed to be either Integer/String/Buffer by the operand
637 1.1 jruoho * resolution mechanism.
638 1.1 jruoho */
639 1.1 jruoho switch (Operand0->Common.Type)
640 1.1 jruoho {
641 1.1 jruoho case ACPI_TYPE_INTEGER:
642 1.1 jruoho Status = AcpiExConvertToInteger (Operand1, &LocalOperand1, 16);
643 1.1 jruoho break;
644 1.1 jruoho
645 1.1 jruoho case ACPI_TYPE_STRING:
646 1.1 jruoho Status = AcpiExConvertToString (Operand1, &LocalOperand1,
647 1.1 jruoho ACPI_IMPLICIT_CONVERT_HEX);
648 1.1 jruoho break;
649 1.1 jruoho
650 1.1 jruoho case ACPI_TYPE_BUFFER:
651 1.1 jruoho Status = AcpiExConvertToBuffer (Operand1, &LocalOperand1);
652 1.1 jruoho break;
653 1.1 jruoho
654 1.1 jruoho default:
655 1.1 jruoho Status = AE_AML_INTERNAL;
656 1.1 jruoho break;
657 1.1 jruoho }
658 1.1 jruoho
659 1.1 jruoho if (ACPI_FAILURE (Status))
660 1.1 jruoho {
661 1.1 jruoho goto Cleanup;
662 1.1 jruoho }
663 1.1 jruoho
664 1.1 jruoho /*
665 1.1 jruoho * Two cases: 1) Both Integers, 2) Both Strings or Buffers
666 1.1 jruoho */
667 1.1 jruoho if (Operand0->Common.Type == ACPI_TYPE_INTEGER)
668 1.1 jruoho {
669 1.1 jruoho /*
670 1.1 jruoho * 1) Both operands are of type integer
671 1.1 jruoho * Note: LocalOperand1 may have changed above
672 1.1 jruoho */
673 1.1 jruoho Integer0 = Operand0->Integer.Value;
674 1.1 jruoho Integer1 = LocalOperand1->Integer.Value;
675 1.1 jruoho
676 1.1 jruoho switch (Opcode)
677 1.1 jruoho {
678 1.1 jruoho case AML_LEQUAL_OP: /* LEqual (Operand0, Operand1) */
679 1.1 jruoho
680 1.1 jruoho if (Integer0 == Integer1)
681 1.1 jruoho {
682 1.1 jruoho LocalResult = TRUE;
683 1.1 jruoho }
684 1.1 jruoho break;
685 1.1 jruoho
686 1.1 jruoho case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */
687 1.1 jruoho
688 1.1 jruoho if (Integer0 > Integer1)
689 1.1 jruoho {
690 1.1 jruoho LocalResult = TRUE;
691 1.1 jruoho }
692 1.1 jruoho break;
693 1.1 jruoho
694 1.1 jruoho case AML_LLESS_OP: /* LLess (Operand0, Operand1) */
695 1.1 jruoho
696 1.1 jruoho if (Integer0 < Integer1)
697 1.1 jruoho {
698 1.1 jruoho LocalResult = TRUE;
699 1.1 jruoho }
700 1.1 jruoho break;
701 1.1 jruoho
702 1.1 jruoho default:
703 1.1 jruoho Status = AE_AML_INTERNAL;
704 1.1 jruoho break;
705 1.1 jruoho }
706 1.1 jruoho }
707 1.1 jruoho else
708 1.1 jruoho {
709 1.1 jruoho /*
710 1.1 jruoho * 2) Both operands are Strings or both are Buffers
711 1.1 jruoho * Note: Code below takes advantage of common Buffer/String
712 1.1 jruoho * object fields. LocalOperand1 may have changed above. Use
713 1.1 jruoho * memcmp to handle nulls in buffers.
714 1.1 jruoho */
715 1.1 jruoho Length0 = Operand0->Buffer.Length;
716 1.1 jruoho Length1 = LocalOperand1->Buffer.Length;
717 1.1 jruoho
718 1.1 jruoho /* Lexicographic compare: compare the data bytes */
719 1.1 jruoho
720 1.1 jruoho Compare = ACPI_MEMCMP (Operand0->Buffer.Pointer,
721 1.1 jruoho LocalOperand1->Buffer.Pointer,
722 1.1 jruoho (Length0 > Length1) ? Length1 : Length0);
723 1.1 jruoho
724 1.1 jruoho switch (Opcode)
725 1.1 jruoho {
726 1.1 jruoho case AML_LEQUAL_OP: /* LEqual (Operand0, Operand1) */
727 1.1 jruoho
728 1.1 jruoho /* Length and all bytes must be equal */
729 1.1 jruoho
730 1.1 jruoho if ((Length0 == Length1) &&
731 1.1 jruoho (Compare == 0))
732 1.1 jruoho {
733 1.1 jruoho /* Length and all bytes match ==> TRUE */
734 1.1 jruoho
735 1.1 jruoho LocalResult = TRUE;
736 1.1 jruoho }
737 1.1 jruoho break;
738 1.1 jruoho
739 1.1 jruoho case AML_LGREATER_OP: /* LGreater (Operand0, Operand1) */
740 1.1 jruoho
741 1.1 jruoho if (Compare > 0)
742 1.1 jruoho {
743 1.1 jruoho LocalResult = TRUE;
744 1.1 jruoho goto Cleanup; /* TRUE */
745 1.1 jruoho }
746 1.1 jruoho if (Compare < 0)
747 1.1 jruoho {
748 1.1 jruoho goto Cleanup; /* FALSE */
749 1.1 jruoho }
750 1.1 jruoho
751 1.1 jruoho /* Bytes match (to shortest length), compare lengths */
752 1.1 jruoho
753 1.1 jruoho if (Length0 > Length1)
754 1.1 jruoho {
755 1.1 jruoho LocalResult = TRUE;
756 1.1 jruoho }
757 1.1 jruoho break;
758 1.1 jruoho
759 1.1 jruoho case AML_LLESS_OP: /* LLess (Operand0, Operand1) */
760 1.1 jruoho
761 1.1 jruoho if (Compare > 0)
762 1.1 jruoho {
763 1.1 jruoho goto Cleanup; /* FALSE */
764 1.1 jruoho }
765 1.1 jruoho if (Compare < 0)
766 1.1 jruoho {
767 1.1 jruoho LocalResult = TRUE;
768 1.1 jruoho goto Cleanup; /* TRUE */
769 1.1 jruoho }
770 1.1 jruoho
771 1.1 jruoho /* Bytes match (to shortest length), compare lengths */
772 1.1 jruoho
773 1.1 jruoho if (Length0 < Length1)
774 1.1 jruoho {
775 1.1 jruoho LocalResult = TRUE;
776 1.1 jruoho }
777 1.1 jruoho break;
778 1.1 jruoho
779 1.1 jruoho default:
780 1.1 jruoho Status = AE_AML_INTERNAL;
781 1.1 jruoho break;
782 1.1 jruoho }
783 1.1 jruoho }
784 1.1 jruoho
785 1.1 jruoho Cleanup:
786 1.1 jruoho
787 1.1 jruoho /* New object was created if implicit conversion performed - delete */
788 1.1 jruoho
789 1.1 jruoho if (LocalOperand1 != Operand1)
790 1.1 jruoho {
791 1.1 jruoho AcpiUtRemoveReference (LocalOperand1);
792 1.1 jruoho }
793 1.1 jruoho
794 1.1 jruoho /* Return the logical result and status */
795 1.1 jruoho
796 1.1 jruoho *LogicalResult = LocalResult;
797 1.1 jruoho return_ACPI_STATUS (Status);
798 1.1 jruoho }
799 1.1 jruoho
800 1.1 jruoho
801