exmisc.c revision 1.1.1.19 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: exmisc - ACPI AML (p-code) execution - specific opcodes
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1.1.19 christos /******************************************************************************
8 1.1.1.19 christos *
9 1.1.1.19 christos * 1. Copyright Notice
10 1.1.1.19 christos *
11 1.1.1.19 christos * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
12 1.1 jruoho * All rights reserved.
13 1.1 jruoho *
14 1.1.1.19 christos * 2. License
15 1.1.1.19 christos *
16 1.1.1.19 christos * 2.1. This is your license from Intel Corp. under its intellectual property
17 1.1.1.19 christos * rights. You may have additional license terms from the party that provided
18 1.1.1.19 christos * you this software, covering your right to use that party's intellectual
19 1.1.1.19 christos * property rights.
20 1.1.1.19 christos *
21 1.1.1.19 christos * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 1.1.1.19 christos * copy of the source code appearing in this file ("Covered Code") an
23 1.1.1.19 christos * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 1.1.1.19 christos * base code distributed originally by Intel ("Original Intel Code") to copy,
25 1.1.1.19 christos * make derivatives, distribute, use and display any portion of the Covered
26 1.1.1.19 christos * Code in any form, with the right to sublicense such rights; and
27 1.1.1.19 christos *
28 1.1.1.19 christos * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 1.1.1.19 christos * license (with the right to sublicense), under only those claims of Intel
30 1.1.1.19 christos * patents that are infringed by the Original Intel Code, to make, use, sell,
31 1.1.1.19 christos * offer to sell, and import the Covered Code and derivative works thereof
32 1.1.1.19 christos * solely to the minimum extent necessary to exercise the above copyright
33 1.1.1.19 christos * license, and in no event shall the patent license extend to any additions
34 1.1.1.19 christos * to or modifications of the Original Intel Code. No other license or right
35 1.1.1.19 christos * is granted directly or by implication, estoppel or otherwise;
36 1.1.1.19 christos *
37 1.1.1.19 christos * The above copyright and patent license is granted only if the following
38 1.1.1.19 christos * conditions are met:
39 1.1.1.19 christos *
40 1.1.1.19 christos * 3. Conditions
41 1.1.1.19 christos *
42 1.1.1.19 christos * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 1.1.1.19 christos * Redistribution of source code of any substantial portion of the Covered
44 1.1.1.19 christos * Code or modification with rights to further distribute source must include
45 1.1.1.19 christos * the above Copyright Notice, the above License, this list of Conditions,
46 1.1.1.19 christos * and the following Disclaimer and Export Compliance provision. In addition,
47 1.1.1.19 christos * Licensee must cause all Covered Code to which Licensee contributes to
48 1.1.1.19 christos * contain a file documenting the changes Licensee made to create that Covered
49 1.1.1.19 christos * Code and the date of any change. Licensee must include in that file the
50 1.1.1.19 christos * documentation of any changes made by any predecessor Licensee. Licensee
51 1.1.1.19 christos * must include a prominent statement that the modification is derived,
52 1.1.1.19 christos * directly or indirectly, from Original Intel Code.
53 1.1.1.19 christos *
54 1.1.1.19 christos * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 1.1.1.19 christos * Redistribution of source code of any substantial portion of the Covered
56 1.1.1.19 christos * Code or modification without rights to further distribute source must
57 1.1.1.19 christos * include the following Disclaimer and Export Compliance provision in the
58 1.1.1.19 christos * documentation and/or other materials provided with distribution. In
59 1.1.1.19 christos * addition, Licensee may not authorize further sublicense of source of any
60 1.1.1.19 christos * portion of the Covered Code, and must include terms to the effect that the
61 1.1.1.19 christos * license from Licensee to its licensee is limited to the intellectual
62 1.1.1.19 christos * property embodied in the software Licensee provides to its licensee, and
63 1.1.1.19 christos * not to intellectual property embodied in modifications its licensee may
64 1.1.1.19 christos * make.
65 1.1.1.19 christos *
66 1.1.1.19 christos * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 1.1.1.19 christos * substantial portion of the Covered Code or modification must reproduce the
68 1.1.1.19 christos * above Copyright Notice, and the following Disclaimer and Export Compliance
69 1.1.1.19 christos * provision in the documentation and/or other materials provided with the
70 1.1.1.19 christos * distribution.
71 1.1.1.19 christos *
72 1.1.1.19 christos * 3.4. Intel retains all right, title, and interest in and to the Original
73 1.1.1.19 christos * Intel Code.
74 1.1.1.19 christos *
75 1.1.1.19 christos * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 1.1.1.19 christos * Intel shall be used in advertising or otherwise to promote the sale, use or
77 1.1.1.19 christos * other dealings in products derived from or relating to the Covered Code
78 1.1.1.19 christos * without prior written authorization from Intel.
79 1.1.1.19 christos *
80 1.1.1.19 christos * 4. Disclaimer and Export Compliance
81 1.1.1.19 christos *
82 1.1.1.19 christos * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 1.1.1.19 christos * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 1.1.1.19 christos * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 1.1.1.19 christos * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 1.1.1.19 christos
87 1.1.1.19 christos * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 1.1.1.19 christos * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 1.1.1.19 christos * PARTICULAR PURPOSE.
90 1.1.1.19 christos *
91 1.1.1.19 christos * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 1.1.1.19 christos * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 1.1.1.19 christos * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 1.1.1.19 christos * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 1.1.1.19 christos * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 1.1.1.19 christos * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 1.1.1.19 christos * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 1.1.1.19 christos * LIMITED REMEDY.
99 1.1.1.19 christos *
100 1.1.1.19 christos * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 1.1.1.19 christos * software or system incorporating such software without first obtaining any
102 1.1.1.19 christos * required license or other approval from the U. S. Department of Commerce or
103 1.1.1.19 christos * any other agency or department of the United States Government. In the
104 1.1.1.19 christos * event Licensee exports any such software from the United States or
105 1.1.1.19 christos * re-exports any such software from a foreign destination, Licensee shall
106 1.1.1.19 christos * ensure that the distribution and export/re-export of the software is in
107 1.1.1.19 christos * compliance with all laws, regulations, orders, or other restrictions of the
108 1.1.1.19 christos * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 1.1.1.19 christos * any of its subsidiaries will export/re-export any technical data, process,
110 1.1.1.19 christos * software, or service, directly or indirectly, to any country for which the
111 1.1.1.19 christos * United States government or any agency thereof requires an export license,
112 1.1.1.19 christos * other governmental approval, or letter of assurance, without first obtaining
113 1.1.1.19 christos * such license, approval or letter.
114 1.1.1.19 christos *
115 1.1.1.19 christos *****************************************************************************
116 1.1.1.19 christos *
117 1.1.1.19 christos * Alternatively, you may choose to be licensed under the terms of the
118 1.1.1.19 christos * following license:
119 1.1.1.19 christos *
120 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
121 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
122 1.1.1.2 jruoho * are met:
123 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
124 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
125 1.1.1.2 jruoho * without modification.
126 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
127 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
128 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
129 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
130 1.1.1.2 jruoho * binary redistribution.
131 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
132 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
133 1.1.1.2 jruoho * from this software without specific prior written permission.
134 1.1.1.2 jruoho *
135 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
136 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
137 1.1.1.16 christos * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
138 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
139 1.1.1.19 christos * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
140 1.1.1.19 christos * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
141 1.1.1.19 christos * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
142 1.1.1.19 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
143 1.1.1.19 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
144 1.1.1.19 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
145 1.1.1.19 christos * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 1.1.1.19 christos *
147 1.1.1.19 christos * Alternatively, you may choose to be licensed under the terms of the
148 1.1.1.19 christos * GNU General Public License ("GPL") version 2 as published by the Free
149 1.1.1.19 christos * Software Foundation.
150 1.1.1.19 christos *
151 1.1.1.19 christos *****************************************************************************/
152 1.1 jruoho
153 1.1 jruoho #include "acpi.h"
154 1.1 jruoho #include "accommon.h"
155 1.1 jruoho #include "acinterp.h"
156 1.1 jruoho #include "amlcode.h"
157 1.1 jruoho
158 1.1 jruoho
159 1.1 jruoho #define _COMPONENT ACPI_EXECUTER
160 1.1 jruoho ACPI_MODULE_NAME ("exmisc")
161 1.1 jruoho
162 1.1 jruoho
163 1.1 jruoho /*******************************************************************************
164 1.1 jruoho *
165 1.1 jruoho * FUNCTION: AcpiExGetObjectReference
166 1.1 jruoho *
167 1.1 jruoho * PARAMETERS: ObjDesc - Create a reference to this object
168 1.1 jruoho * ReturnDesc - Where to store the reference
169 1.1 jruoho * WalkState - Current state
170 1.1 jruoho *
171 1.1 jruoho * RETURN: Status
172 1.1 jruoho *
173 1.1 jruoho * DESCRIPTION: Obtain and return a "reference" to the target object
174 1.1 jruoho * Common code for the RefOfOp and the CondRefOfOp.
175 1.1 jruoho *
176 1.1 jruoho ******************************************************************************/
177 1.1 jruoho
178 1.1 jruoho ACPI_STATUS
179 1.1 jruoho AcpiExGetObjectReference (
180 1.1 jruoho ACPI_OPERAND_OBJECT *ObjDesc,
181 1.1 jruoho ACPI_OPERAND_OBJECT **ReturnDesc,
182 1.1 jruoho ACPI_WALK_STATE *WalkState)
183 1.1 jruoho {
184 1.1 jruoho ACPI_OPERAND_OBJECT *ReferenceObj;
185 1.1 jruoho ACPI_OPERAND_OBJECT *ReferencedObj;
186 1.1 jruoho
187 1.1 jruoho
188 1.1 jruoho ACPI_FUNCTION_TRACE_PTR (ExGetObjectReference, ObjDesc);
189 1.1 jruoho
190 1.1 jruoho
191 1.1 jruoho *ReturnDesc = NULL;
192 1.1 jruoho
193 1.1 jruoho switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
194 1.1 jruoho {
195 1.1 jruoho case ACPI_DESC_TYPE_OPERAND:
196 1.1 jruoho
197 1.1 jruoho if (ObjDesc->Common.Type != ACPI_TYPE_LOCAL_REFERENCE)
198 1.1 jruoho {
199 1.1 jruoho return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
200 1.1 jruoho }
201 1.1 jruoho
202 1.1 jruoho /*
203 1.1 jruoho * Must be a reference to a Local or Arg
204 1.1 jruoho */
205 1.1 jruoho switch (ObjDesc->Reference.Class)
206 1.1 jruoho {
207 1.1 jruoho case ACPI_REFCLASS_LOCAL:
208 1.1 jruoho case ACPI_REFCLASS_ARG:
209 1.1 jruoho case ACPI_REFCLASS_DEBUG:
210 1.1 jruoho
211 1.1 jruoho /* The referenced object is the pseudo-node for the local/arg */
212 1.1 jruoho
213 1.1 jruoho ReferencedObj = ObjDesc->Reference.Object;
214 1.1 jruoho break;
215 1.1 jruoho
216 1.1 jruoho default:
217 1.1 jruoho
218 1.1.1.7 christos ACPI_ERROR ((AE_INFO, "Invalid Reference Class 0x%2.2X",
219 1.1 jruoho ObjDesc->Reference.Class));
220 1.1.1.7 christos return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
221 1.1 jruoho }
222 1.1 jruoho break;
223 1.1 jruoho
224 1.1 jruoho case ACPI_DESC_TYPE_NAMED:
225 1.1 jruoho /*
226 1.1 jruoho * A named reference that has already been resolved to a Node
227 1.1 jruoho */
228 1.1 jruoho ReferencedObj = ObjDesc;
229 1.1 jruoho break;
230 1.1 jruoho
231 1.1 jruoho default:
232 1.1 jruoho
233 1.1 jruoho ACPI_ERROR ((AE_INFO, "Invalid descriptor type 0x%X",
234 1.1 jruoho ACPI_GET_DESCRIPTOR_TYPE (ObjDesc)));
235 1.1 jruoho return_ACPI_STATUS (AE_TYPE);
236 1.1 jruoho }
237 1.1 jruoho
238 1.1 jruoho
239 1.1 jruoho /* Create a new reference object */
240 1.1 jruoho
241 1.1 jruoho ReferenceObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
242 1.1 jruoho if (!ReferenceObj)
243 1.1 jruoho {
244 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
245 1.1 jruoho }
246 1.1 jruoho
247 1.1 jruoho ReferenceObj->Reference.Class = ACPI_REFCLASS_REFOF;
248 1.1 jruoho ReferenceObj->Reference.Object = ReferencedObj;
249 1.1 jruoho *ReturnDesc = ReferenceObj;
250 1.1 jruoho
251 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
252 1.1 jruoho "Object %p Type [%s], returning Reference %p\n",
253 1.1 jruoho ObjDesc, AcpiUtGetObjectTypeName (ObjDesc), *ReturnDesc));
254 1.1 jruoho
255 1.1 jruoho return_ACPI_STATUS (AE_OK);
256 1.1 jruoho }
257 1.1 jruoho
258 1.1 jruoho
259 1.1 jruoho /*******************************************************************************
260 1.1 jruoho *
261 1.1 jruoho * FUNCTION: AcpiExDoMathOp
262 1.1 jruoho *
263 1.1 jruoho * PARAMETERS: Opcode - AML opcode
264 1.1 jruoho * Integer0 - Integer operand #0
265 1.1 jruoho * Integer1 - Integer operand #1
266 1.1 jruoho *
267 1.1 jruoho * RETURN: Integer result of the operation
268 1.1 jruoho *
269 1.1 jruoho * DESCRIPTION: Execute a math AML opcode. The purpose of having all of the
270 1.1 jruoho * math functions here is to prevent a lot of pointer dereferencing
271 1.1 jruoho * to obtain the operands.
272 1.1 jruoho *
273 1.1 jruoho ******************************************************************************/
274 1.1 jruoho
275 1.1 jruoho UINT64
276 1.1 jruoho AcpiExDoMathOp (
277 1.1 jruoho UINT16 Opcode,
278 1.1 jruoho UINT64 Integer0,
279 1.1 jruoho UINT64 Integer1)
280 1.1 jruoho {
281 1.1 jruoho
282 1.1 jruoho ACPI_FUNCTION_ENTRY ();
283 1.1 jruoho
284 1.1 jruoho
285 1.1 jruoho switch (Opcode)
286 1.1 jruoho {
287 1.1 jruoho case AML_ADD_OP: /* Add (Integer0, Integer1, Result) */
288 1.1 jruoho
289 1.1 jruoho return (Integer0 + Integer1);
290 1.1 jruoho
291 1.1 jruoho case AML_BIT_AND_OP: /* And (Integer0, Integer1, Result) */
292 1.1 jruoho
293 1.1 jruoho return (Integer0 & Integer1);
294 1.1 jruoho
295 1.1 jruoho case AML_BIT_NAND_OP: /* NAnd (Integer0, Integer1, Result) */
296 1.1 jruoho
297 1.1 jruoho return (~(Integer0 & Integer1));
298 1.1 jruoho
299 1.1 jruoho case AML_BIT_OR_OP: /* Or (Integer0, Integer1, Result) */
300 1.1 jruoho
301 1.1 jruoho return (Integer0 | Integer1);
302 1.1 jruoho
303 1.1 jruoho case AML_BIT_NOR_OP: /* NOr (Integer0, Integer1, Result) */
304 1.1 jruoho
305 1.1 jruoho return (~(Integer0 | Integer1));
306 1.1 jruoho
307 1.1 jruoho case AML_BIT_XOR_OP: /* XOr (Integer0, Integer1, Result) */
308 1.1 jruoho
309 1.1 jruoho return (Integer0 ^ Integer1);
310 1.1 jruoho
311 1.1 jruoho case AML_MULTIPLY_OP: /* Multiply (Integer0, Integer1, Result) */
312 1.1 jruoho
313 1.1 jruoho return (Integer0 * Integer1);
314 1.1 jruoho
315 1.1 jruoho case AML_SHIFT_LEFT_OP: /* ShiftLeft (Operand, ShiftCount, Result)*/
316 1.1 jruoho
317 1.1 jruoho /*
318 1.1 jruoho * We need to check if the shiftcount is larger than the integer bit
319 1.1 jruoho * width since the behavior of this is not well-defined in the C language.
320 1.1 jruoho */
321 1.1 jruoho if (Integer1 >= AcpiGbl_IntegerBitWidth)
322 1.1 jruoho {
323 1.1 jruoho return (0);
324 1.1 jruoho }
325 1.1 jruoho return (Integer0 << Integer1);
326 1.1 jruoho
327 1.1 jruoho case AML_SHIFT_RIGHT_OP: /* ShiftRight (Operand, ShiftCount, Result) */
328 1.1 jruoho
329 1.1 jruoho /*
330 1.1 jruoho * We need to check if the shiftcount is larger than the integer bit
331 1.1 jruoho * width since the behavior of this is not well-defined in the C language.
332 1.1 jruoho */
333 1.1 jruoho if (Integer1 >= AcpiGbl_IntegerBitWidth)
334 1.1 jruoho {
335 1.1 jruoho return (0);
336 1.1 jruoho }
337 1.1 jruoho return (Integer0 >> Integer1);
338 1.1 jruoho
339 1.1 jruoho case AML_SUBTRACT_OP: /* Subtract (Integer0, Integer1, Result) */
340 1.1 jruoho
341 1.1 jruoho return (Integer0 - Integer1);
342 1.1 jruoho
343 1.1 jruoho default:
344 1.1 jruoho
345 1.1 jruoho return (0);
346 1.1 jruoho }
347 1.1 jruoho }
348 1.1 jruoho
349 1.1 jruoho
350 1.1 jruoho /*******************************************************************************
351 1.1 jruoho *
352 1.1 jruoho * FUNCTION: AcpiExDoLogicalNumericOp
353 1.1 jruoho *
354 1.1 jruoho * PARAMETERS: Opcode - AML opcode
355 1.1 jruoho * Integer0 - Integer operand #0
356 1.1 jruoho * Integer1 - Integer operand #1
357 1.1 jruoho * LogicalResult - TRUE/FALSE result of the operation
358 1.1 jruoho *
359 1.1 jruoho * RETURN: Status
360 1.1 jruoho *
361 1.1 jruoho * DESCRIPTION: Execute a logical "Numeric" AML opcode. For these Numeric
362 1.1 jruoho * operators (LAnd and LOr), both operands must be integers.
363 1.1 jruoho *
364 1.1 jruoho * Note: cleanest machine code seems to be produced by the code
365 1.1 jruoho * below, rather than using statements of the form:
366 1.1 jruoho * Result = (Integer0 && Integer1);
367 1.1 jruoho *
368 1.1 jruoho ******************************************************************************/
369 1.1 jruoho
370 1.1 jruoho ACPI_STATUS
371 1.1 jruoho AcpiExDoLogicalNumericOp (
372 1.1 jruoho UINT16 Opcode,
373 1.1 jruoho UINT64 Integer0,
374 1.1 jruoho UINT64 Integer1,
375 1.1 jruoho BOOLEAN *LogicalResult)
376 1.1 jruoho {
377 1.1 jruoho ACPI_STATUS Status = AE_OK;
378 1.1 jruoho BOOLEAN LocalResult = FALSE;
379 1.1 jruoho
380 1.1 jruoho
381 1.1 jruoho ACPI_FUNCTION_TRACE (ExDoLogicalNumericOp);
382 1.1 jruoho
383 1.1 jruoho
384 1.1 jruoho switch (Opcode)
385 1.1 jruoho {
386 1.1.1.11 christos case AML_LOGICAL_AND_OP: /* LAnd (Integer0, Integer1) */
387 1.1 jruoho
388 1.1 jruoho if (Integer0 && Integer1)
389 1.1 jruoho {
390 1.1 jruoho LocalResult = TRUE;
391 1.1 jruoho }
392 1.1 jruoho break;
393 1.1 jruoho
394 1.1.1.11 christos case AML_LOGICAL_OR_OP: /* LOr (Integer0, Integer1) */
395 1.1 jruoho
396 1.1 jruoho if (Integer0 || Integer1)
397 1.1 jruoho {
398 1.1 jruoho LocalResult = TRUE;
399 1.1 jruoho }
400 1.1 jruoho break;
401 1.1 jruoho
402 1.1 jruoho default:
403 1.1.1.3 christos
404 1.1.1.12 christos ACPI_ERROR ((AE_INFO,
405 1.1.1.12 christos "Invalid numeric logical opcode: %X", Opcode));
406 1.1 jruoho Status = AE_AML_INTERNAL;
407 1.1 jruoho break;
408 1.1 jruoho }
409 1.1 jruoho
410 1.1 jruoho /* Return the logical result and status */
411 1.1 jruoho
412 1.1 jruoho *LogicalResult = LocalResult;
413 1.1 jruoho return_ACPI_STATUS (Status);
414 1.1 jruoho }
415 1.1 jruoho
416 1.1 jruoho
417 1.1 jruoho /*******************************************************************************
418 1.1 jruoho *
419 1.1 jruoho * FUNCTION: AcpiExDoLogicalOp
420 1.1 jruoho *
421 1.1 jruoho * PARAMETERS: Opcode - AML opcode
422 1.1 jruoho * Operand0 - operand #0
423 1.1 jruoho * Operand1 - operand #1
424 1.1 jruoho * LogicalResult - TRUE/FALSE result of the operation
425 1.1 jruoho *
426 1.1 jruoho * RETURN: Status
427 1.1 jruoho *
428 1.1 jruoho * DESCRIPTION: Execute a logical AML opcode. The purpose of having all of the
429 1.1 jruoho * functions here is to prevent a lot of pointer dereferencing
430 1.1 jruoho * to obtain the operands and to simplify the generation of the
431 1.1 jruoho * logical value. For the Numeric operators (LAnd and LOr), both
432 1.1 jruoho * operands must be integers. For the other logical operators,
433 1.1 jruoho * operands can be any combination of Integer/String/Buffer. The
434 1.1 jruoho * first operand determines the type to which the second operand
435 1.1 jruoho * will be converted.
436 1.1 jruoho *
437 1.1 jruoho * Note: cleanest machine code seems to be produced by the code
438 1.1 jruoho * below, rather than using statements of the form:
439 1.1 jruoho * Result = (Operand0 == Operand1);
440 1.1 jruoho *
441 1.1 jruoho ******************************************************************************/
442 1.1 jruoho
443 1.1 jruoho ACPI_STATUS
444 1.1 jruoho AcpiExDoLogicalOp (
445 1.1 jruoho UINT16 Opcode,
446 1.1 jruoho ACPI_OPERAND_OBJECT *Operand0,
447 1.1 jruoho ACPI_OPERAND_OBJECT *Operand1,
448 1.1 jruoho BOOLEAN *LogicalResult)
449 1.1 jruoho {
450 1.1 jruoho ACPI_OPERAND_OBJECT *LocalOperand1 = Operand1;
451 1.1 jruoho UINT64 Integer0;
452 1.1 jruoho UINT64 Integer1;
453 1.1 jruoho UINT32 Length0;
454 1.1 jruoho UINT32 Length1;
455 1.1 jruoho ACPI_STATUS Status = AE_OK;
456 1.1 jruoho BOOLEAN LocalResult = FALSE;
457 1.1 jruoho int Compare;
458 1.1 jruoho
459 1.1 jruoho
460 1.1 jruoho ACPI_FUNCTION_TRACE (ExDoLogicalOp);
461 1.1 jruoho
462 1.1 jruoho
463 1.1 jruoho /*
464 1.1.1.3 christos * Convert the second operand if necessary. The first operand
465 1.1 jruoho * determines the type of the second operand, (See the Data Types
466 1.1 jruoho * section of the ACPI 3.0+ specification.) Both object types are
467 1.1 jruoho * guaranteed to be either Integer/String/Buffer by the operand
468 1.1 jruoho * resolution mechanism.
469 1.1 jruoho */
470 1.1 jruoho switch (Operand0->Common.Type)
471 1.1 jruoho {
472 1.1 jruoho case ACPI_TYPE_INTEGER:
473 1.1.1.3 christos
474 1.1.1.9 christos Status = AcpiExConvertToInteger (Operand1, &LocalOperand1,
475 1.1.1.12 christos ACPI_IMPLICIT_CONVERSION);
476 1.1 jruoho break;
477 1.1 jruoho
478 1.1 jruoho case ACPI_TYPE_STRING:
479 1.1.1.3 christos
480 1.1.1.7 christos Status = AcpiExConvertToString (
481 1.1.1.7 christos Operand1, &LocalOperand1, ACPI_IMPLICIT_CONVERT_HEX);
482 1.1 jruoho break;
483 1.1 jruoho
484 1.1 jruoho case ACPI_TYPE_BUFFER:
485 1.1.1.3 christos
486 1.1 jruoho Status = AcpiExConvertToBuffer (Operand1, &LocalOperand1);
487 1.1 jruoho break;
488 1.1 jruoho
489 1.1 jruoho default:
490 1.1.1.3 christos
491 1.1.1.12 christos ACPI_ERROR ((AE_INFO,
492 1.1.1.12 christos "Invalid object type for logical operator: %X",
493 1.1.1.12 christos Operand0->Common.Type));
494 1.1 jruoho Status = AE_AML_INTERNAL;
495 1.1 jruoho break;
496 1.1 jruoho }
497 1.1 jruoho
498 1.1 jruoho if (ACPI_FAILURE (Status))
499 1.1 jruoho {
500 1.1 jruoho goto Cleanup;
501 1.1 jruoho }
502 1.1 jruoho
503 1.1 jruoho /*
504 1.1 jruoho * Two cases: 1) Both Integers, 2) Both Strings or Buffers
505 1.1 jruoho */
506 1.1 jruoho if (Operand0->Common.Type == ACPI_TYPE_INTEGER)
507 1.1 jruoho {
508 1.1 jruoho /*
509 1.1 jruoho * 1) Both operands are of type integer
510 1.1 jruoho * Note: LocalOperand1 may have changed above
511 1.1 jruoho */
512 1.1 jruoho Integer0 = Operand0->Integer.Value;
513 1.1 jruoho Integer1 = LocalOperand1->Integer.Value;
514 1.1 jruoho
515 1.1 jruoho switch (Opcode)
516 1.1 jruoho {
517 1.1.1.11 christos case AML_LOGICAL_EQUAL_OP: /* LEqual (Operand0, Operand1) */
518 1.1 jruoho
519 1.1 jruoho if (Integer0 == Integer1)
520 1.1 jruoho {
521 1.1 jruoho LocalResult = TRUE;
522 1.1 jruoho }
523 1.1 jruoho break;
524 1.1 jruoho
525 1.1.1.11 christos case AML_LOGICAL_GREATER_OP: /* LGreater (Operand0, Operand1) */
526 1.1 jruoho
527 1.1 jruoho if (Integer0 > Integer1)
528 1.1 jruoho {
529 1.1 jruoho LocalResult = TRUE;
530 1.1 jruoho }
531 1.1 jruoho break;
532 1.1 jruoho
533 1.1.1.11 christos case AML_LOGICAL_LESS_OP: /* LLess (Operand0, Operand1) */
534 1.1 jruoho
535 1.1 jruoho if (Integer0 < Integer1)
536 1.1 jruoho {
537 1.1 jruoho LocalResult = TRUE;
538 1.1 jruoho }
539 1.1 jruoho break;
540 1.1 jruoho
541 1.1 jruoho default:
542 1.1.1.3 christos
543 1.1.1.12 christos ACPI_ERROR ((AE_INFO,
544 1.1.1.12 christos "Invalid comparison opcode: %X", Opcode));
545 1.1 jruoho Status = AE_AML_INTERNAL;
546 1.1 jruoho break;
547 1.1 jruoho }
548 1.1 jruoho }
549 1.1 jruoho else
550 1.1 jruoho {
551 1.1 jruoho /*
552 1.1 jruoho * 2) Both operands are Strings or both are Buffers
553 1.1 jruoho * Note: Code below takes advantage of common Buffer/String
554 1.1 jruoho * object fields. LocalOperand1 may have changed above. Use
555 1.1 jruoho * memcmp to handle nulls in buffers.
556 1.1 jruoho */
557 1.1 jruoho Length0 = Operand0->Buffer.Length;
558 1.1 jruoho Length1 = LocalOperand1->Buffer.Length;
559 1.1 jruoho
560 1.1 jruoho /* Lexicographic compare: compare the data bytes */
561 1.1 jruoho
562 1.1.1.6 christos Compare = memcmp (Operand0->Buffer.Pointer,
563 1.1.1.7 christos LocalOperand1->Buffer.Pointer,
564 1.1.1.7 christos (Length0 > Length1) ? Length1 : Length0);
565 1.1 jruoho
566 1.1 jruoho switch (Opcode)
567 1.1 jruoho {
568 1.1.1.11 christos case AML_LOGICAL_EQUAL_OP: /* LEqual (Operand0, Operand1) */
569 1.1 jruoho
570 1.1 jruoho /* Length and all bytes must be equal */
571 1.1 jruoho
572 1.1 jruoho if ((Length0 == Length1) &&
573 1.1 jruoho (Compare == 0))
574 1.1 jruoho {
575 1.1 jruoho /* Length and all bytes match ==> TRUE */
576 1.1 jruoho
577 1.1 jruoho LocalResult = TRUE;
578 1.1 jruoho }
579 1.1 jruoho break;
580 1.1 jruoho
581 1.1.1.11 christos case AML_LOGICAL_GREATER_OP: /* LGreater (Operand0, Operand1) */
582 1.1 jruoho
583 1.1 jruoho if (Compare > 0)
584 1.1 jruoho {
585 1.1 jruoho LocalResult = TRUE;
586 1.1 jruoho goto Cleanup; /* TRUE */
587 1.1 jruoho }
588 1.1 jruoho if (Compare < 0)
589 1.1 jruoho {
590 1.1 jruoho goto Cleanup; /* FALSE */
591 1.1 jruoho }
592 1.1 jruoho
593 1.1 jruoho /* Bytes match (to shortest length), compare lengths */
594 1.1 jruoho
595 1.1 jruoho if (Length0 > Length1)
596 1.1 jruoho {
597 1.1 jruoho LocalResult = TRUE;
598 1.1 jruoho }
599 1.1 jruoho break;
600 1.1 jruoho
601 1.1.1.11 christos case AML_LOGICAL_LESS_OP: /* LLess (Operand0, Operand1) */
602 1.1 jruoho
603 1.1 jruoho if (Compare > 0)
604 1.1 jruoho {
605 1.1 jruoho goto Cleanup; /* FALSE */
606 1.1 jruoho }
607 1.1 jruoho if (Compare < 0)
608 1.1 jruoho {
609 1.1 jruoho LocalResult = TRUE;
610 1.1 jruoho goto Cleanup; /* TRUE */
611 1.1 jruoho }
612 1.1 jruoho
613 1.1 jruoho /* Bytes match (to shortest length), compare lengths */
614 1.1 jruoho
615 1.1 jruoho if (Length0 < Length1)
616 1.1 jruoho {
617 1.1 jruoho LocalResult = TRUE;
618 1.1 jruoho }
619 1.1 jruoho break;
620 1.1 jruoho
621 1.1 jruoho default:
622 1.1.1.3 christos
623 1.1.1.12 christos ACPI_ERROR ((AE_INFO,
624 1.1.1.12 christos "Invalid comparison opcode: %X", Opcode));
625 1.1 jruoho Status = AE_AML_INTERNAL;
626 1.1 jruoho break;
627 1.1 jruoho }
628 1.1 jruoho }
629 1.1 jruoho
630 1.1 jruoho Cleanup:
631 1.1 jruoho
632 1.1 jruoho /* New object was created if implicit conversion performed - delete */
633 1.1 jruoho
634 1.1 jruoho if (LocalOperand1 != Operand1)
635 1.1 jruoho {
636 1.1 jruoho AcpiUtRemoveReference (LocalOperand1);
637 1.1 jruoho }
638 1.1 jruoho
639 1.1 jruoho /* Return the logical result and status */
640 1.1 jruoho
641 1.1 jruoho *LogicalResult = LocalResult;
642 1.1 jruoho return_ACPI_STATUS (Status);
643 1.1 jruoho }
644