diff options
Diffstat (limited to 'sys/contrib/dev/acpica/Subsystem/Interpreter/amdyadic.c')
-rw-r--r-- | sys/contrib/dev/acpica/Subsystem/Interpreter/amdyadic.c | 386 |
1 files changed, 264 insertions, 122 deletions
diff --git a/sys/contrib/dev/acpica/Subsystem/Interpreter/amdyadic.c b/sys/contrib/dev/acpica/Subsystem/Interpreter/amdyadic.c index f0b87ec..c80d929 100644 --- a/sys/contrib/dev/acpica/Subsystem/Interpreter/amdyadic.c +++ b/sys/contrib/dev/acpica/Subsystem/Interpreter/amdyadic.c @@ -1,7 +1,7 @@ /****************************************************************************** * * Module Name: amdyadic - ACPI AML (p-code) execution for dyadic operators - * $Revision: 69 $ + * $Revision: 71 $ * *****************************************************************************/ @@ -9,7 +9,7 @@ * * 1. Copyright Notice * - * Some or all of this work - Copyright (c) 1999, 2000, Intel Corp. + * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp. * All rights reserved. * * 2. License @@ -130,7 +130,183 @@ MODULE_NAME ("amdyadic") -/***************************************************************************** +/******************************************************************************* + * + * FUNCTION: AcpiAmlDoConcatenate + * + * PARAMETERS: *ObjDesc - Object to be converted. Must be an + * Integer, Buffer, or String + * + * RETURN: Status + * + * DESCRIPTION: Concatenate two objects OF THE SAME TYPE. + * + ******************************************************************************/ + +ACPI_STATUS +AcpiAmlDoConcatenate ( + ACPI_OPERAND_OBJECT *ObjDesc, + ACPI_OPERAND_OBJECT *ObjDesc2, + ACPI_OPERAND_OBJECT **ActualRetDesc, + ACPI_WALK_STATE *WalkState) +{ + ACPI_STATUS Status; + UINT32 i; + ACPI_INTEGER ThisInteger; + ACPI_OPERAND_OBJECT *RetDesc; + NATIVE_CHAR *NewBuf; + UINT32 IntegerSize = sizeof (ACPI_INTEGER); + + + /* + * There are three cases to handle: + * 1) Two Integers concatenated to produce a buffer + * 2) Two Strings concatenated to produce a string + * 3) Two Buffers concatenated to produce a buffer + */ + switch (ObjDesc->Common.Type) + { + case ACPI_TYPE_INTEGER: + + /* Handle both ACPI 1.0 and ACPI 2.0 Integer widths */ + + if (WalkState->MethodNode->Flags & ANOBJ_DATA_WIDTH_32) + { + /* + * We are running a method that exists in a 32-bit ACPI table. + * Truncate the value to 32 bits by zeroing out the upper + * 32-bit field + */ + IntegerSize = sizeof (UINT32); + } + + /* Result of two integers is a buffer */ + + RetDesc = AcpiCmCreateInternalObject (ACPI_TYPE_BUFFER); + if (!RetDesc) + { + return (AE_NO_MEMORY); + } + + /* Need enough space for two integers */ + + RetDesc->Buffer.Length = IntegerSize * 2; + NewBuf = AcpiCmCallocate (RetDesc->Buffer.Length); + if (!NewBuf) + { + REPORT_ERROR + (("AmlExecDyadic2R/ConcatOp: Buffer allocation failure\n")); + Status = AE_NO_MEMORY; + goto Cleanup; + } + + RetDesc->Buffer.Pointer = (UINT8 *) NewBuf; + + /* Convert the first integer */ + + ThisInteger = ObjDesc->Integer.Value; + for (i = 0; i < IntegerSize; i++) + { + NewBuf[i] = (UINT8) ThisInteger; + ThisInteger >>= 8; + } + + /* Convert the second integer */ + + ThisInteger = ObjDesc2->Integer.Value; + for (; i < (IntegerSize * 2); i++) + { + NewBuf[i] = (UINT8) ThisInteger; + ThisInteger >>= 8; + } + + break; + + + case ACPI_TYPE_STRING: + + RetDesc = AcpiCmCreateInternalObject (ACPI_TYPE_STRING); + if (!RetDesc) + { + return (AE_NO_MEMORY); + } + + /* Operand1 is string */ + + NewBuf = AcpiCmAllocate (ObjDesc->String.Length + + ObjDesc2->String.Length + 1); + if (!NewBuf) + { + REPORT_ERROR + (("AmlExecDyadic2R/ConcatOp: String allocation failure\n")); + Status = AE_NO_MEMORY; + goto Cleanup; + } + + STRCPY (NewBuf, ObjDesc->String.Pointer); + STRCPY (NewBuf + ObjDesc->String.Length, + ObjDesc2->String.Pointer); + + /* Point the return object to the new string */ + + RetDesc->String.Pointer = NewBuf; + RetDesc->String.Length = ObjDesc->String.Length += + ObjDesc2->String.Length; + break; + + + case ACPI_TYPE_BUFFER: + + /* Operand1 is a buffer */ + + RetDesc = AcpiCmCreateInternalObject (ACPI_TYPE_BUFFER); + if (!RetDesc) + { + return (AE_NO_MEMORY); + } + + NewBuf = AcpiCmAllocate (ObjDesc->Buffer.Length + + ObjDesc2->Buffer.Length); + if (!NewBuf) + { + REPORT_ERROR + (("AmlExecDyadic2R/ConcatOp: Buffer allocation failure\n")); + Status = AE_NO_MEMORY; + goto Cleanup; + } + + MEMCPY (NewBuf, ObjDesc->Buffer.Pointer, + ObjDesc->Buffer.Length); + MEMCPY (NewBuf + ObjDesc->Buffer.Length, ObjDesc2->Buffer.Pointer, + ObjDesc2->Buffer.Length); + + /* + * Point the return object to the new buffer + */ + + RetDesc->Buffer.Pointer = (UINT8 *) NewBuf; + RetDesc->Buffer.Length = ObjDesc->Buffer.Length + + ObjDesc2->Buffer.Length; + break; + + default: + Status = AE_AML_INTERNAL; + RetDesc = NULL; + } + + + *ActualRetDesc = RetDesc; + return (AE_OK); + + +Cleanup: + + AcpiCmRemoveReference (RetDesc); + return (Status); +} + + +/******************************************************************************* * * FUNCTION: AcpiAmlExecDyadic1 * @@ -143,7 +319,7 @@ * * ALLOCATION: Deletes both operands * - ****************************************************************************/ + ******************************************************************************/ ACPI_STATUS AcpiAmlExecDyadic1 ( @@ -211,7 +387,7 @@ AcpiAmlExecDyadic1 ( /* Dispatch the notify to the appropriate handler */ - AcpiEvNotifyDispatch (Node, (UINT32) ValDesc->Number.Value); + AcpiEvNotifyDispatch (Node, (UINT32) ValDesc->Integer.Value); break; default: @@ -244,7 +420,7 @@ Cleanup: } -/***************************************************************************** +/******************************************************************************* * * FUNCTION: AcpiAmlExecDyadic2R * @@ -257,7 +433,7 @@ Cleanup: * * ALLOCATION: Deletes one operand descriptor -- other remains on stack * - ****************************************************************************/ + ******************************************************************************/ ACPI_STATUS AcpiAmlExecDyadic2R ( @@ -273,7 +449,6 @@ AcpiAmlExecDyadic2R ( ACPI_OPERAND_OBJECT *RetDesc2 = NULL; ACPI_STATUS Status = AE_OK; UINT32 NumOperands = 3; - NATIVE_CHAR *NewBuf; FUNCTION_TRACE_U32 ("AmlExecDyadic2R", Opcode); @@ -322,7 +497,7 @@ AcpiAmlExecDyadic2R ( case AML_SHIFT_RIGHT_OP: case AML_SUBTRACT_OP: - RetDesc = AcpiCmCreateInternalObject (ACPI_TYPE_NUMBER); + RetDesc = AcpiCmCreateInternalObject (ACPI_TYPE_INTEGER); if (!RetDesc) { Status = AE_NO_MEMORY; @@ -344,8 +519,8 @@ AcpiAmlExecDyadic2R ( case AML_ADD_OP: - RetDesc->Number.Value = ObjDesc->Number.Value + - ObjDesc2->Number.Value; + RetDesc->Integer.Value = ObjDesc->Integer.Value + + ObjDesc2->Integer.Value; break; @@ -353,8 +528,8 @@ AcpiAmlExecDyadic2R ( case AML_BIT_AND_OP: - RetDesc->Number.Value = ObjDesc->Number.Value & - ObjDesc2->Number.Value; + RetDesc->Integer.Value = ObjDesc->Integer.Value & + ObjDesc2->Integer.Value; break; @@ -362,8 +537,8 @@ AcpiAmlExecDyadic2R ( case AML_BIT_NAND_OP: - RetDesc->Number.Value = ~(ObjDesc->Number.Value & - ObjDesc2->Number.Value); + RetDesc->Integer.Value = ~(ObjDesc->Integer.Value & + ObjDesc2->Integer.Value); break; @@ -371,8 +546,8 @@ AcpiAmlExecDyadic2R ( case AML_BIT_OR_OP: - RetDesc->Number.Value = ObjDesc->Number.Value | - ObjDesc2->Number.Value; + RetDesc->Integer.Value = ObjDesc->Integer.Value | + ObjDesc2->Integer.Value; break; @@ -380,8 +555,8 @@ AcpiAmlExecDyadic2R ( case AML_BIT_NOR_OP: - RetDesc->Number.Value = ~(ObjDesc->Number.Value | - ObjDesc2->Number.Value); + RetDesc->Integer.Value = ~(ObjDesc->Integer.Value | + ObjDesc2->Integer.Value); break; @@ -389,16 +564,16 @@ AcpiAmlExecDyadic2R ( case AML_BIT_XOR_OP: - RetDesc->Number.Value = ObjDesc->Number.Value ^ - ObjDesc2->Number.Value; + RetDesc->Integer.Value = ObjDesc->Integer.Value ^ + ObjDesc2->Integer.Value; break; - /* DefDivide := DivideOp Dividend Divisor Remainder Quotient */ + /* DefDivide := DivideOp Dividend Divisor Remainder Quotient */ case AML_DIVIDE_OP: - if (!ObjDesc2->Number.Value) + if (!ObjDesc2->Integer.Value) { REPORT_ERROR (("AmlExecDyadic2R/DivideOp: Divide by zero\n")); @@ -407,7 +582,7 @@ AcpiAmlExecDyadic2R ( goto Cleanup; } - RetDesc2 = AcpiCmCreateInternalObject (ACPI_TYPE_NUMBER); + RetDesc2 = AcpiCmCreateInternalObject (ACPI_TYPE_INTEGER); if (!RetDesc2) { Status = AE_NO_MEMORY; @@ -416,13 +591,13 @@ AcpiAmlExecDyadic2R ( /* Remainder (modulo) */ - RetDesc->Number.Value = ACPI_MODULO (ObjDesc->Number.Value, - ObjDesc2->Number.Value); + RetDesc->Integer.Value = ACPI_MODULO (ObjDesc->Integer.Value, + ObjDesc2->Integer.Value); /* Result (what we used to call the quotient) */ - RetDesc2->Number.Value = ACPI_DIVIDE (ObjDesc->Number.Value, - ObjDesc2->Number.Value); + RetDesc2->Integer.Value = ACPI_DIVIDE (ObjDesc->Integer.Value, + ObjDesc2->Integer.Value); break; @@ -430,8 +605,8 @@ AcpiAmlExecDyadic2R ( case AML_MULTIPLY_OP: - RetDesc->Number.Value = ObjDesc->Number.Value * - ObjDesc2->Number.Value; + RetDesc->Integer.Value = ObjDesc->Integer.Value * + ObjDesc2->Integer.Value; break; @@ -439,8 +614,8 @@ AcpiAmlExecDyadic2R ( case AML_SHIFT_LEFT_OP: - RetDesc->Number.Value = ObjDesc->Number.Value << - ObjDesc2->Number.Value; + RetDesc->Integer.Value = ObjDesc->Integer.Value << + ObjDesc2->Integer.Value; break; @@ -448,8 +623,8 @@ AcpiAmlExecDyadic2R ( case AML_SHIFT_RIGHT_OP: - RetDesc->Number.Value = ObjDesc->Number.Value >> - ObjDesc2->Number.Value; + RetDesc->Integer.Value = ObjDesc->Integer.Value >> + ObjDesc2->Integer.Value; break; @@ -457,8 +632,8 @@ AcpiAmlExecDyadic2R ( case AML_SUBTRACT_OP: - RetDesc->Number.Value = ObjDesc->Number.Value - - ObjDesc2->Number.Value; + RetDesc->Integer.Value = ObjDesc->Integer.Value - + ObjDesc2->Integer.Value; break; @@ -466,89 +641,56 @@ AcpiAmlExecDyadic2R ( case AML_CONCAT_OP: - if (ObjDesc2->Common.Type != ObjDesc->Common.Type) - { - DEBUG_PRINT (ACPI_ERROR, - ("AmlExecDyadic2R/ConcatOp: operand type mismatch %X != %X\n", - ObjDesc->Common.Type, ObjDesc2->Common.Type)); - Status = AE_AML_OPERAND_TYPE; - goto Cleanup; - } - /* Both operands are now known to be the same */ + /* + * Convert the second operand if necessary. The first operand + * determines the type of the second operand, (See the Data Types + * section of the ACPI specification.) Both object types are + * guaranteed to be either Integer/String/Buffer by the operand + * resolution mechanism above. + */ - if (ACPI_TYPE_STRING == ObjDesc->Common.Type) + switch (ObjDesc->Common.Type) { - RetDesc = AcpiCmCreateInternalObject (ACPI_TYPE_STRING); - if (!RetDesc) - { - Status = AE_NO_MEMORY; - goto Cleanup; - } - - /* Operand1 is string */ - - NewBuf = AcpiCmAllocate (ObjDesc->String.Length + - ObjDesc2->String.Length + 1); - if (!NewBuf) - { - REPORT_ERROR - (("AmlExecDyadic2R/ConcatOp: String allocation failure\n")); - Status = AE_NO_MEMORY; - goto Cleanup; - } + case ACPI_TYPE_INTEGER: + Status = AcpiAmlConvertToInteger (&ObjDesc2, WalkState); + break; - STRCPY (NewBuf, ObjDesc->String.Pointer); - STRCPY (NewBuf + ObjDesc->String.Length, - ObjDesc2->String.Pointer); + case ACPI_TYPE_STRING: + Status = AcpiAmlConvertToString (&ObjDesc2, WalkState); + break; - /* Point the return object to the new string */ + case ACPI_TYPE_BUFFER: + Status = AcpiAmlConvertToBuffer (&ObjDesc2, WalkState); + break; - RetDesc->String.Pointer = NewBuf; - RetDesc->String.Length = ObjDesc->String.Length += - ObjDesc2->String.Length; + default: + Status = AE_AML_INTERNAL; } - else + if (ACPI_FAILURE (Status)) { - /* Operand1 is not a string ==> must be a buffer */ - - RetDesc = AcpiCmCreateInternalObject (ACPI_TYPE_BUFFER); - if (!RetDesc) - { - Status = AE_NO_MEMORY; - goto Cleanup; - } - - NewBuf = AcpiCmAllocate (ObjDesc->Buffer.Length + - ObjDesc2->Buffer.Length); - if (!NewBuf) - { - REPORT_ERROR - (("AmlExecDyadic2R/ConcatOp: Buffer allocation failure\n")); - Status = AE_NO_MEMORY; - goto Cleanup; - } - - MEMCPY (NewBuf, ObjDesc->Buffer.Pointer, - ObjDesc->Buffer.Length); - MEMCPY (NewBuf + ObjDesc->Buffer.Length, ObjDesc2->Buffer.Pointer, - ObjDesc2->Buffer.Length); + goto Cleanup; + } - /* - * Point the return object to the new buffer - */ - RetDesc->Buffer.Pointer = (UINT8 *) NewBuf; - RetDesc->Buffer.Length = ObjDesc->Buffer.Length + - ObjDesc2->Buffer.Length; + /* + * Both operands are now known to be the same object type + * (Both are Integer, String, or Buffer), and we can now perform the + * concatenation. + */ + Status = AcpiAmlDoConcatenate (ObjDesc, ObjDesc2, &RetDesc, WalkState); + if (ACPI_FAILURE (Status)) + { + goto Cleanup; } break; default: - REPORT_ERROR (("AcpiAmlExecDyadic2R: Unknown dyadic opcode %X\n", Opcode)); + REPORT_ERROR (("AcpiAmlExecDyadic2R: Unknown dyadic opcode %X\n", + Opcode)); Status = AE_AML_BAD_OPCODE; goto Cleanup; } @@ -612,7 +754,7 @@ Cleanup: } -/***************************************************************************** +/******************************************************************************* * * FUNCTION: AcpiAmlExecDyadic2S * @@ -624,7 +766,7 @@ Cleanup: * * ALLOCATION: Deletes one operand descriptor -- other remains on stack * - ****************************************************************************/ + ******************************************************************************/ ACPI_STATUS AcpiAmlExecDyadic2S ( @@ -665,7 +807,7 @@ AcpiAmlExecDyadic2S ( /* Create the internal return object */ - RetDesc = AcpiCmCreateInternalObject (ACPI_TYPE_NUMBER); + RetDesc = AcpiCmCreateInternalObject (ACPI_TYPE_INTEGER); if (!RetDesc) { Status = AE_NO_MEMORY; @@ -674,7 +816,7 @@ AcpiAmlExecDyadic2S ( /* Default return value is FALSE, operation did not time out */ - RetDesc->Number.Value = 0; + RetDesc->Integer.Value = 0; /* Examine the opcode */ @@ -713,7 +855,7 @@ AcpiAmlExecDyadic2S ( if (Status == AE_TIME) { - RetDesc->Number.Value = ACPI_INTEGER_MAX; /* TRUE, op timed out */ + RetDesc->Integer.Value = ACPI_INTEGER_MAX; /* TRUE, op timed out */ Status = AE_OK; } @@ -742,7 +884,7 @@ Cleanup: } -/***************************************************************************** +/******************************************************************************* * * FUNCTION: AcpiAmlExecDyadic2 * @@ -756,7 +898,7 @@ Cleanup: * ALLOCATION: Deletes one operand descriptor -- other remains on stack * containing result value * - ****************************************************************************/ + ******************************************************************************/ ACPI_STATUS AcpiAmlExecDyadic2 ( @@ -798,7 +940,7 @@ AcpiAmlExecDyadic2 ( /* Create the internal return object */ - RetDesc = AcpiCmCreateInternalObject (ACPI_TYPE_NUMBER); + RetDesc = AcpiCmCreateInternalObject (ACPI_TYPE_INTEGER); if (!RetDesc) { Status = AE_NO_MEMORY; @@ -817,8 +959,8 @@ AcpiAmlExecDyadic2 ( case AML_LAND_OP: - Lboolean = (BOOLEAN) (ObjDesc->Number.Value && - ObjDesc2->Number.Value); + Lboolean = (BOOLEAN) (ObjDesc->Integer.Value && + ObjDesc2->Integer.Value); break; @@ -826,8 +968,8 @@ AcpiAmlExecDyadic2 ( case AML_LEQUAL_OP: - Lboolean = (BOOLEAN) (ObjDesc->Number.Value == - ObjDesc2->Number.Value); + Lboolean = (BOOLEAN) (ObjDesc->Integer.Value == + ObjDesc2->Integer.Value); break; @@ -835,8 +977,8 @@ AcpiAmlExecDyadic2 ( case AML_LGREATER_OP: - Lboolean = (BOOLEAN) (ObjDesc->Number.Value > - ObjDesc2->Number.Value); + Lboolean = (BOOLEAN) (ObjDesc->Integer.Value > + ObjDesc2->Integer.Value); break; @@ -844,8 +986,8 @@ AcpiAmlExecDyadic2 ( case AML_LLESS_OP: - Lboolean = (BOOLEAN) (ObjDesc->Number.Value < - ObjDesc2->Number.Value); + Lboolean = (BOOLEAN) (ObjDesc->Integer.Value < + ObjDesc2->Integer.Value); break; @@ -853,8 +995,8 @@ AcpiAmlExecDyadic2 ( case AML_LOR_OP: - Lboolean = (BOOLEAN) (ObjDesc->Number.Value || - ObjDesc2->Number.Value); + Lboolean = (BOOLEAN) (ObjDesc->Integer.Value || + ObjDesc2->Integer.Value); break; @@ -871,11 +1013,11 @@ AcpiAmlExecDyadic2 ( if (Lboolean) { - RetDesc->Number.Value = ACPI_INTEGER_MAX; + RetDesc->Integer.Value = ACPI_INTEGER_MAX; } else { - RetDesc->Number.Value = 0; + RetDesc->Integer.Value = 0; } |