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