X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FEbcDxe%2FEbcExecute.c;h=a4c51e9b0f614c73a16f2fdbaa75a876ad5ac822;hp=e4240c9b83a83b91abdb8da2ed2ccc10c208feb7;hb=6f0a3cd23e4a2322c58c7dbf0ef8e66a4a01c42c;hpb=ea7cb08c0afc7ad5dd9ed7176cd062385df8fa8b diff --git a/MdeModulePkg/Universal/EbcDxe/EbcExecute.c b/MdeModulePkg/Universal/EbcDxe/EbcExecute.c index e4240c9b83..a4c51e9b0f 100644 --- a/MdeModulePkg/Universal/EbcDxe/EbcExecute.c +++ b/MdeModulePkg/Universal/EbcDxe/EbcExecute.c @@ -1,8 +1,8 @@ /** @file Contains code that implements the virtual machine. -Copyright (c) 2006 - 2008, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -14,6 +14,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "EbcInt.h" #include "EbcExecute.h" +#include "EbcDebuggerHook.h" // @@ -49,13 +50,13 @@ UINT64 b14:12 - number of bits in this index assigned to natural units (=a) ba:11 - constant units = ConstUnits b0:a - natural units = NaturalUnits - + Given this info, the offset can be computed by: offset = sign_bit * (ConstUnits + NaturalUnits * sizeof(UINTN)) Max offset is achieved with index = 0x7FFF giving an offset of 0x27B (32-bit machine) or 0x477 (64-bit machine). - Min offset is achieved with index = + Min offset is achieved with index = @param VmPtr A pointer to VM context. @param CodeOffset Offset from IP of the location of the 16-bit index @@ -64,7 +65,6 @@ UINT64 @return The decoded offset. **/ -STATIC INT16 VmReadIndex16 ( IN VM_CONTEXT *VmPtr, @@ -81,7 +81,6 @@ VmReadIndex16 ( @return Converted index per EBC VM specification. **/ -STATIC INT32 VmReadIndex32 ( IN VM_CONTEXT *VmPtr, @@ -98,7 +97,6 @@ VmReadIndex32 ( @return Converted index per EBC VM specification **/ -STATIC INT64 VmReadIndex64 ( IN VM_CONTEXT *VmPtr, @@ -111,10 +109,9 @@ VmReadIndex64 ( @param VmPtr A pointer to VM context. @param Addr The memory address. - @return The 8-bit value from the memory adress. + @return The 8-bit value from the memory address. **/ -STATIC UINT8 VmReadMem8 ( IN VM_CONTEXT *VmPtr, @@ -127,10 +124,9 @@ VmReadMem8 ( @param VmPtr A pointer to VM context. @param Addr The memory address. - @return The 16-bit value from the memory adress. + @return The 16-bit value from the memory address. **/ -STATIC UINT16 VmReadMem16 ( IN VM_CONTEXT *VmPtr, @@ -143,10 +139,9 @@ VmReadMem16 ( @param VmPtr A pointer to VM context. @param Addr The memory address. - @return The 32-bit value from the memory adress. + @return The 32-bit value from the memory address. **/ -STATIC UINT32 VmReadMem32 ( IN VM_CONTEXT *VmPtr, @@ -159,10 +154,9 @@ VmReadMem32 ( @param VmPtr A pointer to VM context. @param Addr The memory address. - @return The 64-bit value from the memory adress. + @return The 64-bit value from the memory address. **/ -STATIC UINT64 VmReadMem64 ( IN VM_CONTEXT *VmPtr, @@ -178,7 +172,6 @@ VmReadMem64 ( @return The natural value at address Addr. **/ -STATIC UINTN VmReadMemN ( IN VM_CONTEXT *VmPtr, @@ -187,7 +180,7 @@ VmReadMemN ( /** Writes 8-bit data to memory address. - + This routine is called by the EBC data movement instructions that write to memory. Since these writes may be to the stack, which looks like (high address on top) this, @@ -197,18 +190,17 @@ VmReadMemN ( [EBC stack] we need to detect all attempts to write to the EBC entry point argument - stack area and adjust the address (which will initially point into the + stack area and adjust the address (which will initially point into the VM stack) to point into the EBC entry point arguments. @param VmPtr A pointer to a VM context. - @param Addr Adddress to write to. + @param Addr Address to write to. @param Data Value to write to Addr. - @retval EFI_SUCCESS The instruction is executed successfully. + @retval EFI_SUCCESS The instruction is executed successfully. @retval Other Some error occurs when writing data to the address. **/ -STATIC EFI_STATUS VmWriteMem8 ( IN VM_CONTEXT *VmPtr, @@ -218,7 +210,7 @@ VmWriteMem8 ( /** Writes 16-bit data to memory address. - + This routine is called by the EBC data movement instructions that write to memory. Since these writes may be to the stack, which looks like (high address on top) this, @@ -228,18 +220,17 @@ VmWriteMem8 ( [EBC stack] we need to detect all attempts to write to the EBC entry point argument - stack area and adjust the address (which will initially point into the + stack area and adjust the address (which will initially point into the VM stack) to point into the EBC entry point arguments. @param VmPtr A pointer to a VM context. - @param Addr Adddress to write to. + @param Addr Address to write to. @param Data Value to write to Addr. - @retval EFI_SUCCESS The instruction is executed successfully. + @retval EFI_SUCCESS The instruction is executed successfully. @retval Other Some error occurs when writing data to the address. **/ -STATIC EFI_STATUS VmWriteMem16 ( IN VM_CONTEXT *VmPtr, @@ -249,7 +240,7 @@ VmWriteMem16 ( /** Writes 32-bit data to memory address. - + This routine is called by the EBC data movement instructions that write to memory. Since these writes may be to the stack, which looks like (high address on top) this, @@ -259,18 +250,17 @@ VmWriteMem16 ( [EBC stack] we need to detect all attempts to write to the EBC entry point argument - stack area and adjust the address (which will initially point into the + stack area and adjust the address (which will initially point into the VM stack) to point into the EBC entry point arguments. @param VmPtr A pointer to a VM context. - @param Addr Adddress to write to. + @param Addr Address to write to. @param Data Value to write to Addr. - @retval EFI_SUCCESS The instruction is executed successfully. + @retval EFI_SUCCESS The instruction is executed successfully. @retval Other Some error occurs when writing data to the address. **/ -STATIC EFI_STATUS VmWriteMem32 ( IN VM_CONTEXT *VmPtr, @@ -279,7 +269,7 @@ VmWriteMem32 ( ); /** - Reads 16-bit unsinged data from the code stream. + Reads 16-bit unsigned data from the code stream. This routine provides the ability to read raw unsigned data from the code stream. @@ -290,7 +280,6 @@ VmWriteMem32 ( @return The raw unsigned 16-bit value from the code stream. **/ -STATIC UINT16 VmReadCode16 ( IN VM_CONTEXT *VmPtr, @@ -298,7 +287,7 @@ VmReadCode16 ( ); /** - Reads 32-bit unsinged data from the code stream. + Reads 32-bit unsigned data from the code stream. This routine provides the ability to read raw unsigned data from the code stream. @@ -309,7 +298,6 @@ VmReadCode16 ( @return The raw unsigned 32-bit value from the code stream. **/ -STATIC UINT32 VmReadCode32 ( IN VM_CONTEXT *VmPtr, @@ -317,7 +305,7 @@ VmReadCode32 ( ); /** - Reads 64-bit unsinged data from the code stream. + Reads 64-bit unsigned data from the code stream. This routine provides the ability to read raw unsigned data from the code stream. @@ -328,7 +316,6 @@ VmReadCode32 ( @return The raw unsigned 64-bit value from the code stream. **/ -STATIC UINT64 VmReadCode64 ( IN VM_CONTEXT *VmPtr, @@ -349,7 +336,6 @@ VmReadCode64 ( @return Signed data of the requested size from the specified address. **/ -STATIC INT8 VmReadImmed8 ( IN VM_CONTEXT *VmPtr, @@ -370,7 +356,6 @@ VmReadImmed8 ( @return Signed data of the requested size from the specified address. **/ -STATIC INT16 VmReadImmed16 ( IN VM_CONTEXT *VmPtr, @@ -391,7 +376,6 @@ VmReadImmed16 ( @return Signed data of the requested size from the specified address. **/ -STATIC INT32 VmReadImmed32 ( IN VM_CONTEXT *VmPtr, @@ -412,7 +396,6 @@ VmReadImmed32 ( @return Signed data of the requested size from the specified address. **/ -STATIC INT64 VmReadImmed64 ( IN VM_CONTEXT *VmPtr, @@ -438,7 +421,6 @@ VmReadImmed64 ( adjust for the stack gap and return the modified address. **/ -STATIC UINTN ConvertStackAddr ( IN VM_CONTEXT *VmPtr, @@ -459,11 +441,10 @@ ConvertStackAddr ( @param VmPtr A pointer to VM context. @param IsSignedOp Indicates whether the operand is signed or not. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteDataManip ( IN VM_CONTEXT *VmPtr, @@ -481,7 +462,6 @@ ExecuteDataManip ( @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteBREAK ( IN VM_CONTEXT *VmPtr @@ -493,7 +473,7 @@ ExecuteBREAK ( Instruction syntax: JMP64{cs|cc} Immed64 JMP32{cs|cc} {@}R1 {Immed32|Index32} - + Encoding: b0.7 - immediate data present b0.6 - 1 = 64 bit immediate data @@ -512,7 +492,6 @@ ExecuteBREAK ( @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteJMP ( IN VM_CONTEXT *VmPtr @@ -529,7 +508,6 @@ ExecuteJMP ( @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteJMP8 ( IN VM_CONTEXT *VmPtr @@ -551,7 +529,6 @@ ExecuteJMP8 ( @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteCALL ( IN VM_CONTEXT *VmPtr @@ -568,7 +545,6 @@ ExecuteCALL ( @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteRET ( IN VM_CONTEXT *VmPtr @@ -582,11 +558,10 @@ ExecuteRET ( @param VmPtr A pointer to a VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteCMP ( IN VM_CONTEXT *VmPtr @@ -600,11 +575,10 @@ ExecuteCMP ( @param VmPtr A pointer to a VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteCMPI ( IN VM_CONTEXT *VmPtr @@ -614,15 +588,15 @@ ExecuteCMPI ( Execute the MOVxx instructions. Instruction format: - + MOV[b|w|d|q|n]{w|d} {@}R1 {Index16|32}, {@}R2 {Index16|32} MOVqq {@}R1 {Index64}, {@}R2 {Index64} - + Copies contents of [R2] -> [R1], zero extending where required. - + First character indicates the size of the move. Second character indicates the size of the index(s). - + Invalid to have R1 direct with index. @param VmPtr A pointer to a VM context. @@ -631,7 +605,6 @@ ExecuteCMPI ( @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteMOVxx ( IN VM_CONTEXT *VmPtr @@ -641,24 +614,23 @@ ExecuteMOVxx ( Execute the EBC MOVI. Instruction syntax: - + MOVI[b|w|d|q][w|d|q] {@}R1 {Index16}, ImmData16|32|64 - + First variable character specifies the move size Second variable character specifies size of the immediate data - + Sign-extend the immediate data to the size of the operation, and zero-extend if storing to a register. - + Operand1 direct with index/immed is invalid. @param VmPtr A pointer to a VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteMOVI ( IN VM_CONTEXT *VmPtr @@ -669,16 +641,15 @@ ExecuteMOVI ( index value into a register or memory location. Instruction syntax: - + MOVIn[w|d|q] {@}R1 {Index16}, Index16|32|64 @param VmPtr A pointer to a VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteMOVIn ( IN VM_CONTEXT *VmPtr @@ -689,16 +660,15 @@ ExecuteMOVIn ( Dest <- Ip + ImmData Instruction syntax: - + MOVREL[w|d|q] {@}R1 {Index16}, ImmData16|32|64 @param VmPtr A pointer to a VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteMOVREL ( IN VM_CONTEXT *VmPtr @@ -715,7 +685,6 @@ ExecuteMOVREL ( @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecutePUSHn ( IN VM_CONTEXT *VmPtr @@ -732,7 +701,6 @@ ExecutePUSHn ( @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecutePUSH ( IN VM_CONTEXT *VmPtr @@ -749,7 +717,6 @@ ExecutePUSH ( @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecutePOPn ( IN VM_CONTEXT *VmPtr @@ -766,7 +733,6 @@ ExecutePOPn ( @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecutePOP ( IN VM_CONTEXT *VmPtr @@ -785,11 +751,10 @@ ExecutePOP ( @param VmPtr A pointer to VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteSignedDataManip ( IN VM_CONTEXT *VmPtr @@ -808,11 +773,10 @@ ExecuteSignedDataManip ( @param VmPtr A pointer to VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteUnsignedDataManip ( IN VM_CONTEXT *VmPtr @@ -826,11 +790,10 @@ ExecuteUnsignedDataManip ( @param VmPtr A pointer to a VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteLOADSP ( IN VM_CONTEXT *VmPtr @@ -844,11 +807,10 @@ ExecuteLOADSP ( @param VmPtr A pointer to a VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteSTORESP ( IN VM_CONTEXT *VmPtr @@ -861,19 +823,18 @@ ExecuteSTORESP ( is a register. Instruction syntax: - + MOVsnd {@}R1 {Indx32}, {@}R2 {Index32|Immed32} - + 0:7 1=>operand1 index present 0:6 1=>operand2 index present @param VmPtr A pointer to a VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteMOVsnd ( IN VM_CONTEXT *VmPtr @@ -886,19 +847,18 @@ ExecuteMOVsnd ( is a register. Instruction syntax: - + MOVsnw {@}R1 {Index16}, {@}R2 {Index16|Immed16} - + 0:7 1=>operand1 index present 0:6 1=>operand2 index present @param VmPtr A pointer to a VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteMOVsnw ( IN VM_CONTEXT *VmPtr @@ -920,7 +880,6 @@ ExecuteMOVsnw ( @return ~Op2 **/ -STATIC UINT64 ExecuteNOT ( IN VM_CONTEXT *VmPtr, @@ -941,7 +900,6 @@ ExecuteNOT ( @return Op2 * -1 **/ -STATIC UINT64 ExecuteNEG ( IN VM_CONTEXT *VmPtr, @@ -962,7 +920,6 @@ ExecuteNEG ( @return Op1 + Op2 **/ -STATIC UINT64 ExecuteADD ( IN VM_CONTEXT *VmPtr, @@ -983,7 +940,6 @@ ExecuteADD ( @return Op1 - Op2 **/ -STATIC UINT64 ExecuteSUB ( IN VM_CONTEXT *VmPtr, @@ -1004,7 +960,6 @@ ExecuteSUB ( @return Op1 * Op2 **/ -STATIC UINT64 ExecuteMUL ( IN VM_CONTEXT *VmPtr, @@ -1025,7 +980,6 @@ ExecuteMUL ( @return (unsigned)Op1 * (unsigned)Op2 **/ -STATIC UINT64 ExecuteMULU ( IN VM_CONTEXT *VmPtr, @@ -1046,7 +1000,6 @@ ExecuteMULU ( @return Op1 / Op2 **/ -STATIC UINT64 ExecuteDIV ( IN VM_CONTEXT *VmPtr, @@ -1067,7 +1020,6 @@ ExecuteDIV ( @return (unsigned)Op1 / (unsigned)Op2 **/ -STATIC UINT64 ExecuteDIVU ( IN VM_CONTEXT *VmPtr, @@ -1088,7 +1040,6 @@ ExecuteDIVU ( @return Op1 MODULUS Op2 **/ -STATIC UINT64 ExecuteMOD ( IN VM_CONTEXT *VmPtr, @@ -1109,7 +1060,6 @@ ExecuteMOD ( @return Op1 UNSIGNED_MODULUS Op2 **/ -STATIC UINT64 ExecuteMODU ( IN VM_CONTEXT *VmPtr, @@ -1130,7 +1080,6 @@ ExecuteMODU ( @return Op1 AND Op2 **/ -STATIC UINT64 ExecuteAND ( IN VM_CONTEXT *VmPtr, @@ -1151,7 +1100,6 @@ ExecuteAND ( @return Op1 OR Op2 **/ -STATIC UINT64 ExecuteOR ( IN VM_CONTEXT *VmPtr, @@ -1172,7 +1120,6 @@ ExecuteOR ( @return Op1 XOR Op2 **/ -STATIC UINT64 ExecuteXOR ( IN VM_CONTEXT *VmPtr, @@ -1193,7 +1140,6 @@ ExecuteXOR ( @return Op1 << Op2 **/ -STATIC UINT64 ExecuteSHL ( IN VM_CONTEXT *VmPtr, @@ -1214,7 +1160,6 @@ ExecuteSHL ( @return Op1 >> Op2 (unsigned operands) **/ -STATIC UINT64 ExecuteSHR ( IN VM_CONTEXT *VmPtr, @@ -1235,7 +1180,6 @@ ExecuteSHR ( @return Op1 >> Op2 (signed) **/ -STATIC UINT64 ExecuteASHR ( IN VM_CONTEXT *VmPtr, @@ -1256,7 +1200,6 @@ ExecuteASHR ( @return (INT64)(INT8)Op2 **/ -STATIC UINT64 ExecuteEXTNDB ( IN VM_CONTEXT *VmPtr, @@ -1277,7 +1220,6 @@ ExecuteEXTNDB ( @return (INT64)(INT16)Op2 **/ -STATIC UINT64 ExecuteEXTNDW ( IN VM_CONTEXT *VmPtr, @@ -1298,7 +1240,6 @@ ExecuteEXTNDW ( @return (INT64)(INT32)Op2 **/ -STATIC UINT64 ExecuteEXTNDD ( IN VM_CONTEXT *VmPtr, @@ -1310,7 +1251,7 @@ ExecuteEXTNDD ( // Once we retrieve the operands for the data manipulation instructions, // call these functions to perform the operation. // -STATIC CONST DATA_MANIP_EXEC_FUNCTION mDataManipDispatchTable[] = { +CONST DATA_MANIP_EXEC_FUNCTION mDataManipDispatchTable[] = { ExecuteNOT, ExecuteNEG, ExecuteADD, @@ -1332,7 +1273,7 @@ STATIC CONST DATA_MANIP_EXEC_FUNCTION mDataManipDispatchTable[] = { ExecuteEXTNDD, }; -STATIC CONST VM_TABLE_ENTRY mVmOpcodeTable[] = { +CONST VM_TABLE_ENTRY mVmOpcodeTable[] = { { ExecuteBREAK }, // opcode 0x00 { ExecuteJMP }, // opcode 0x01 { ExecuteJMP8 }, // opcode 0x02 @@ -1390,19 +1331,19 @@ STATIC CONST VM_TABLE_ENTRY mVmOpcodeTable[] = { { ExecutePOPn }, // opcode 0x36 { ExecuteMOVI }, // opcode 0x37 - mov immediate data { ExecuteMOVIn }, // opcode 0x38 - mov immediate natural - { ExecuteMOVREL } // opcode 0x39 - move data relative to PC + { ExecuteMOVREL }, // opcode 0x39 - move data relative to PC + { NULL }, // opcode 0x3a + { NULL }, // opcode 0x3b + { NULL }, // opcode 0x3c + { NULL }, // opcode 0x3d + { NULL }, // opcode 0x3e + { NULL } // opcode 0x3f }; // // Length of JMP instructions, depending on upper two bits of opcode. // -STATIC CONST UINT8 mJMPLen[] = { 2, 2, 6, 10 }; - -// -// Simple Debugger Protocol GUID -// -EFI_GUID mEbcSimpleDebuggerProtocolGuid = EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL_GUID; - +CONST UINT8 mJMPLen[] = { 2, 2, 6, 10 }; /** Given a pointer to a new VM context, execute one or more instructions. This @@ -1419,6 +1360,7 @@ EFI_GUID mEbcSimpleDebuggerProtocolGuid = EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL_GUID; **/ EFI_STATUS +EFIAPI EbcExecuteInstructions ( IN EFI_EBC_VM_TEST_PROTOCOL *This, IN VM_CONTEXT *VmPtr, @@ -1447,12 +1389,12 @@ EbcExecuteInstructions ( // call it if it's not null. // while (InstructionsLeft != 0) { - ExecFunc = (UINTN) mVmOpcodeTable[(*VmPtr->Ip & 0x3F)].ExecuteFunction; + ExecFunc = (UINTN) mVmOpcodeTable[(*VmPtr->Ip & OPCODE_M_OPCODE)].ExecuteFunction; if (ExecFunc == (UINTN) NULL) { EbcDebugSignalException (EXCEPT_EBC_INVALID_OPCODE, EXCEPTION_FLAG_FATAL, VmPtr); return EFI_UNSUPPORTED; } else { - mVmOpcodeTable[(*VmPtr->Ip & 0x3F)].ExecuteFunction (VmPtr); + mVmOpcodeTable[(*VmPtr->Ip & OPCODE_M_OPCODE)].ExecuteFunction (VmPtr); *InstructionCount = *InstructionCount + 1; } @@ -1499,14 +1441,14 @@ EbcExecute ( StackCorrupted = 1; } - VmPtr->FramePtr = (VOID *) ((UINT8 *) (UINTN) VmPtr->R[0] + 8); + VmPtr->FramePtr = (VOID *) ((UINT8 *) (UINTN) VmPtr->Gpr[0] + 8); // // Try to get the debug support for EBC // DEBUG_CODE_BEGIN (); Status = gBS->LocateProtocol ( - &mEbcSimpleDebuggerProtocolGuid, + &gEfiEbcSimpleDebuggerProtocolGuid, NULL, (VOID **) &EbcSimpleDebugger ); @@ -1537,14 +1479,6 @@ EbcExecute ( } DEBUG_CODE_END (); - // - // Verify the opcode is in range. Otherwise generate an exception. - // - if ((*VmPtr->Ip & OPCODE_M_OPCODE) >= (sizeof (mVmOpcodeTable) / sizeof (mVmOpcodeTable[0]))) { - EbcDebugSignalException (EXCEPT_EBC_INVALID_OPCODE, EXCEPTION_FLAG_FATAL, VmPtr); - Status = EFI_UNSUPPORTED; - goto Done; - } // // Use the opcode bits to index into the opcode dispatch table. If the // function pointer is null then generate an exception. @@ -1555,6 +1489,9 @@ EbcExecute ( Status = EFI_UNSUPPORTED; goto Done; } + + EbcDebuggerHookExecuteStart (VmPtr); + // // The EBC VM is a strongly ordered processor, so perform a fence operation before // and after each instruction is executed. @@ -1565,6 +1502,8 @@ EbcExecute ( MemoryFence (); + EbcDebuggerHookExecuteEnd (VmPtr); + // // If the step flag is set, signal an exception and continue. We don't // clear it here. Assuming the debugger is responsible for clearing it. @@ -1579,7 +1518,7 @@ EbcExecute ( EbcDebugSignalException (EXCEPT_EBC_STACK_FAULT, EXCEPTION_FLAG_FATAL, VmPtr); StackCorrupted = 1; } - if ((StackCorrupted == 0) && ((UINT64)VmPtr->R[0] <= (UINT64)(UINTN) VmPtr->StackTop)) { + if ((StackCorrupted == 0) && ((UINT64)VmPtr->Gpr[0] <= (UINT64)(UINTN) VmPtr->StackTop)) { EbcDebugSignalException (EXCEPT_EBC_STACK_FAULT, EXCEPTION_FLAG_FATAL, VmPtr); StackCorrupted = 1; } @@ -1596,15 +1535,15 @@ Done: Execute the MOVxx instructions. Instruction format: - + MOV[b|w|d|q|n]{w|d} {@}R1 {Index16|32}, {@}R2 {Index16|32} MOVqq {@}R1 {Index64}, {@}R2 {Index64} - + Copies contents of [R2] -> [R1], zero extending where required. - + First character indicates the size of the move. Second character indicates the size of the index(s). - + Invalid to have R1 direct with index. @param VmPtr A pointer to a VM context. @@ -1613,7 +1552,6 @@ Done: @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteMOVxx ( IN VM_CONTEXT *VmPtr @@ -1745,7 +1683,7 @@ ExecuteMOVxx ( // // Indirect form @R2. Compute address of operand2 // - Source = (UINTN) (VmPtr->R[OPERAND2_REGNUM (Operands)] + Index64Op2); + Source = (UINTN) (VmPtr->Gpr[OPERAND2_REGNUM (Operands)] + Index64Op2); // // Now get the data from the source. Always 0-extend and let the compiler // sign-extend where required. @@ -1781,7 +1719,7 @@ ExecuteMOVxx ( // // Not indirect source: MOVxx {@}Rx, Ry [Index] // - Data64 = VmPtr->R[OPERAND2_REGNUM (Operands)] + Index64Op2; + Data64 = (UINT64) (VmPtr->Gpr[OPERAND2_REGNUM (Operands)] + Index64Op2); // // Did Operand2 have an index? If so, treat as two signed values since // indexes are signed values. @@ -1817,7 +1755,7 @@ ExecuteMOVxx ( // // Reuse the Source variable to now be dest. // - Source = (UINTN) (VmPtr->R[OPERAND1_REGNUM (Operands)] + Index64Op1); + Source = (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index64Op1); // // Do the write based on the size // @@ -1865,7 +1803,7 @@ ExecuteMOVxx ( // Direct storage in register. Clear unused bits and store back to // register. // - VmPtr->R[OPERAND1_REGNUM (Operands)] = Data64 & DataMask; + VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = Data64 & DataMask; } // // Advance the instruction pointer @@ -1883,18 +1821,19 @@ ExecuteMOVxx ( @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteBREAK ( IN VM_CONTEXT *VmPtr ) { + EFI_STATUS Status; UINT8 Operands; VOID *EbcEntryPoint; VOID *Thunk; UINT64 U64EbcEntryPoint; INT32 Offset; + Thunk = NULL; Operands = GETOPERANDS (VmPtr); switch (Operands) { // @@ -1914,7 +1853,7 @@ ExecuteBREAK ( // 16-8 = Major version // 7-0 = Minor version // - VmPtr->R[7] = GetVmVersion (); + VmPtr->Gpr[7] = GetVmVersion (); break; // @@ -1944,26 +1883,29 @@ ExecuteBREAK ( // After we're done, *(UINT64 *)R7 will be the address of the new thunk. // case 5: - Offset = (INT32) VmReadMem32 (VmPtr, (UINTN) VmPtr->R[7]); - U64EbcEntryPoint = (UINT64) (VmPtr->R[7] + Offset + 4); + Offset = (INT32) VmReadMem32 (VmPtr, (UINTN) VmPtr->Gpr[7]); + U64EbcEntryPoint = (UINT64) (VmPtr->Gpr[7] + Offset + 4); EbcEntryPoint = (VOID *) (UINTN) U64EbcEntryPoint; // // Now create a new thunk // - EbcCreateThunks (VmPtr->ImageHandle, EbcEntryPoint, &Thunk, 0); + Status = EbcCreateThunks (VmPtr->ImageHandle, EbcEntryPoint, &Thunk, 0); + if (EFI_ERROR (Status)) { + return Status; + } // // Finally replace the EBC entry point memory with the thunk address // - VmWriteMem64 (VmPtr, (UINTN) VmPtr->R[7], (UINT64) (UINTN) Thunk); + VmWriteMem64 (VmPtr, (UINTN) VmPtr->Gpr[7], (UINT64) (UINTN) Thunk); break; // // Compiler setting version per value in R7 // case 6: - VmPtr->CompilerVersion = (UINT32) VmPtr->R[7]; + VmPtr->CompilerVersion = (UINT32) VmPtr->Gpr[7]; // // Check compiler version against VM version? // @@ -1990,7 +1932,7 @@ ExecuteBREAK ( Instruction syntax: JMP64{cs|cc} Immed64 JMP32{cs|cc} {@}R1 {Immed32|Index32} - + Encoding: b0.7 - immediate data present b0.6 - 1 = 64 bit immediate data @@ -2009,7 +1951,6 @@ ExecuteBREAK ( @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteJMP ( IN VM_CONTEXT *VmPtr @@ -2041,7 +1982,9 @@ ExecuteJMP ( ConditionFlag = (UINT8) VMFLAG_ISSET (VmPtr, VMFLAGS_CC); if ((Operand & CONDITION_M_CONDITIONAL) != 0) { if (CompareSet != ConditionFlag) { + EbcDebuggerHookJMPStart (VmPtr); VmPtr->Ip += Size; + EbcDebuggerHookJMPEnd (VmPtr); return EFI_SUCCESS; } } @@ -2066,7 +2009,7 @@ ExecuteJMP ( // 64-bit immediate data is full address. Read the immediate data, // check for alignment, and jump absolute. // - Data64 = VmReadImmed64 (VmPtr, 2); + Data64 = (UINT64) VmReadImmed64 (VmPtr, 2); if (!IS_ALIGNED ((UINTN) Data64, sizeof (UINT16))) { EbcDebugSignalException ( EXCEPT_EBC_ALIGNMENT_CHECK, @@ -2080,11 +2023,13 @@ ExecuteJMP ( // // Take jump -- relative or absolute // + EbcDebuggerHookJMPStart (VmPtr); if ((Operand & JMP_M_RELATIVE) != 0) { VmPtr->Ip += (UINTN) Data64 + Size; } else { VmPtr->Ip = (VMIP) (UINTN) Data64; } + EbcDebuggerHookJMPEnd (VmPtr); return EFI_SUCCESS; } @@ -2110,7 +2055,7 @@ ExecuteJMP ( if (OPERAND1_REGNUM (Operand) == 0) { Data64 = 0; } else { - Data64 = OPERAND1_REGDATA (VmPtr, Operand); + Data64 = (UINT64) OPERAND1_REGDATA (VmPtr, Operand); } // // Decode the forms @@ -2130,11 +2075,14 @@ ExecuteJMP ( return EFI_UNSUPPORTED; } + EbcDebuggerHookJMPStart (VmPtr); if ((Operand & JMP_M_RELATIVE) != 0) { VmPtr->Ip += (UINTN) Addr + Size; } else { VmPtr->Ip = (VMIP) Addr; } + EbcDebuggerHookJMPEnd (VmPtr); + } else { // // Form: JMP32 Rx {Immed32} @@ -2150,11 +2098,14 @@ ExecuteJMP ( return EFI_UNSUPPORTED; } + EbcDebuggerHookJMPStart (VmPtr); if ((Operand & JMP_M_RELATIVE) != 0) { VmPtr->Ip += (UINTN) Addr + Size; } else { VmPtr->Ip = (VMIP) Addr; } + EbcDebuggerHookJMPEnd (VmPtr); + } return EFI_SUCCESS; @@ -2172,7 +2123,6 @@ ExecuteJMP ( @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteJMP8 ( IN VM_CONTEXT *VmPtr @@ -2195,7 +2145,9 @@ ExecuteJMP8 ( // if ((Opcode & CONDITION_M_CONDITIONAL) != 0) { if (CompareSet != ConditionFlag) { + EbcDebuggerHookJMP8Start (VmPtr); VmPtr->Ip += 2; + EbcDebuggerHookJMP8End (VmPtr); return EFI_SUCCESS; } } @@ -2207,7 +2159,9 @@ ExecuteJMP8 ( // // Want to check for offset == -2 and then raise an exception? // + EbcDebuggerHookJMP8Start (VmPtr); VmPtr->Ip += (Offset * 2) + 2; + EbcDebuggerHookJMP8End (VmPtr); return EFI_SUCCESS; } @@ -2216,24 +2170,23 @@ ExecuteJMP8 ( Execute the EBC MOVI. Instruction syntax: - + MOVI[b|w|d|q][w|d|q] {@}R1 {Index16}, ImmData16|32|64 - + First variable character specifies the move size Second variable character specifies size of the immediate data - + Sign-extend the immediate data to the size of the operation, and zero-extend if storing to a register. - + Operand1 direct with index/immed is invalid. @param VmPtr A pointer to a VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteMOVI ( IN VM_CONTEXT *VmPtr @@ -2314,12 +2267,12 @@ ExecuteMOVI ( Mask64 = (UINT64)~0; } - VmPtr->R[OPERAND1_REGNUM (Operands)] = ImmData64 & Mask64; + VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = ImmData64 & Mask64; } else { // // Get the address then write back based on size of the move // - Op1 = (UINT64) VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16; + Op1 = (UINT64) VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16; if ((Operands & MOVI_M_MOVEWIDTH) == MOVI_MOVEWIDTH8) { VmWriteMem8 (VmPtr, (UINTN) Op1, (UINT8) ImmData64); } else if ((Operands & MOVI_M_MOVEWIDTH) == MOVI_MOVEWIDTH16) { @@ -2327,7 +2280,7 @@ ExecuteMOVI ( } else if ((Operands & MOVI_M_MOVEWIDTH) == MOVI_MOVEWIDTH32) { VmWriteMem32 (VmPtr, (UINTN) Op1, (UINT32) ImmData64); } else { - VmWriteMem64 (VmPtr, (UINTN) Op1, ImmData64); + VmWriteMem64 (VmPtr, (UINTN) Op1, (UINT64) ImmData64); } } // @@ -2343,16 +2296,15 @@ ExecuteMOVI ( index value into a register or memory location. Instruction syntax: - + MOVIn[w|d|q] {@}R1 {Index16}, Index16|32|64 @param VmPtr A pointer to a VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteMOVIn ( IN VM_CONTEXT *VmPtr @@ -2425,13 +2377,13 @@ ExecuteMOVIn ( return EFI_UNSUPPORTED; } - VmPtr->R[OPERAND1_REGNUM (Operands)] = ImmedIndex64; + VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = ImmedIndex64; } else { // // Get the address // - Op1 = (UINT64) VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16; - VmWriteMemN (VmPtr, (UINTN) Op1, (INTN) ImmedIndex64); + Op1 = (UINT64) VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16; + VmWriteMemN (VmPtr, (UINTN) Op1, (UINTN)(INTN) ImmedIndex64); } // // Advance the instruction pointer @@ -2446,16 +2398,15 @@ ExecuteMOVIn ( Dest <- Ip + ImmData Instruction syntax: - + MOVREL[w|d|q] {@}R1 {Index16}, ImmData16|32|64 @param VmPtr A pointer to a VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteMOVREL ( IN VM_CONTEXT *VmPtr @@ -2525,14 +2476,14 @@ ExecuteMOVREL ( return EFI_UNSUPPORTED; } - VmPtr->R[OPERAND1_REGNUM (Operands)] = (VM_REGISTER) Op2; + VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = (VM_REGISTER) Op2; } else { // // Get the address = [Rx] + Index16 // Write back the result. Always a natural size write, since // we're talking addresses here. // - Op1 = (UINT64) VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16; + Op1 = (UINT64) VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16; VmWriteMemN (VmPtr, (UINTN) Op1, (UINTN) Op2); } // @@ -2550,19 +2501,18 @@ ExecuteMOVREL ( is a register. Instruction syntax: - + MOVsnw {@}R1 {Index16}, {@}R2 {Index16|Immed16} - + 0:7 1=>operand1 index present 0:6 1=>operand2 index present @param VmPtr A pointer to a VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteMOVsnw ( IN VM_CONTEXT *VmPtr @@ -2617,17 +2567,17 @@ ExecuteMOVsnw ( // // Get the data from the source. // - Op2 = (INT64) ((INTN) (VmPtr->R[OPERAND2_REGNUM (Operands)] + Op2Index)); + Op2 = (UINT64)(INT64)(INTN)(VmPtr->Gpr[OPERAND2_REGNUM (Operands)] + Op2Index); if (OPERAND2_INDIRECT (Operands)) { - Op2 = (INT64) (INTN) VmReadMemN (VmPtr, (UINTN) Op2); + Op2 = (UINT64)(INT64)(INTN)VmReadMemN (VmPtr, (UINTN) Op2); } // // Now write back the result. // if (!OPERAND1_INDIRECT (Operands)) { - VmPtr->R[OPERAND1_REGNUM (Operands)] = Op2; + VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = Op2; } else { - VmWriteMemN (VmPtr, (UINTN) (VmPtr->R[OPERAND1_REGNUM (Operands)] + Op1Index), (UINTN) Op2); + VmWriteMemN (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Op1Index), (UINTN) Op2); } // // Advance the instruction pointer @@ -2644,19 +2594,18 @@ ExecuteMOVsnw ( is a register. Instruction syntax: - + MOVsnd {@}R1 {Indx32}, {@}R2 {Index32|Immed32} - + 0:7 1=>operand1 index present 0:6 1=>operand2 index present @param VmPtr A pointer to a VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteMOVsnd ( IN VM_CONTEXT *VmPtr @@ -2711,17 +2660,17 @@ ExecuteMOVsnd ( // // Get the data from the source. // - Op2 = (INT64) ((INTN) (VmPtr->R[OPERAND2_REGNUM (Operands)] + Op2Index)); + Op2 = (UINT64)(INT64)(INTN)(INT64)(VmPtr->Gpr[OPERAND2_REGNUM (Operands)] + Op2Index); if (OPERAND2_INDIRECT (Operands)) { - Op2 = (INT64) (INTN) VmReadMemN (VmPtr, (UINTN) Op2); + Op2 = (UINT64)(INT64)(INTN)(INT64)VmReadMemN (VmPtr, (UINTN) Op2); } // // Now write back the result. // if (!OPERAND1_INDIRECT (Operands)) { - VmPtr->R[OPERAND1_REGNUM (Operands)] = Op2; + VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = Op2; } else { - VmWriteMemN (VmPtr, (UINTN) (VmPtr->R[OPERAND1_REGNUM (Operands)] + Op1Index), (UINTN) Op2); + VmWriteMemN (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Op1Index), (UINTN) Op2); } // // Advance the instruction pointer @@ -2742,7 +2691,6 @@ ExecuteMOVsnd ( @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecutePUSHn ( IN VM_CONTEXT *VmPtr @@ -2778,15 +2726,15 @@ ExecutePUSHn ( // Get the data to push // if (OPERAND1_INDIRECT (Operands)) { - DataN = VmReadMemN (VmPtr, (UINTN) (VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16)); + DataN = VmReadMemN (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16)); } else { - DataN = (UINTN) (VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16); + DataN = (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16); } // // Adjust the stack down. // - VmPtr->R[0] -= sizeof (UINTN); - VmWriteMemN (VmPtr, (UINTN) VmPtr->R[0], DataN); + VmPtr->Gpr[0] -= sizeof (UINTN); + VmWriteMemN (VmPtr, (UINTN) VmPtr->Gpr[0], DataN); return EFI_SUCCESS; } @@ -2802,7 +2750,6 @@ ExecutePUSHn ( @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecutePUSH ( IN VM_CONTEXT *VmPtr @@ -2839,29 +2786,29 @@ ExecutePUSH ( // if ((Opcode & PUSHPOP_M_64) != 0) { if (OPERAND1_INDIRECT (Operands)) { - Data64 = VmReadMem64 (VmPtr, (UINTN) (VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16)); + Data64 = VmReadMem64 (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16)); } else { - Data64 = (UINT64) VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16; + Data64 = (UINT64) VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16; } // // Adjust the stack down, then write back the data // - VmPtr->R[0] -= sizeof (UINT64); - VmWriteMem64 (VmPtr, (UINTN) VmPtr->R[0], Data64); + VmPtr->Gpr[0] -= sizeof (UINT64); + VmWriteMem64 (VmPtr, (UINTN) VmPtr->Gpr[0], Data64); } else { // // 32-bit data // if (OPERAND1_INDIRECT (Operands)) { - Data32 = VmReadMem32 (VmPtr, (UINTN) (VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16)); + Data32 = VmReadMem32 (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16)); } else { - Data32 = (UINT32) VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16; + Data32 = (UINT32) VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16; } // // Adjust the stack down and write the data // - VmPtr->R[0] -= sizeof (UINT32); - VmWriteMem32 (VmPtr, (UINTN) VmPtr->R[0], Data32); + VmPtr->Gpr[0] -= sizeof (UINT32); + VmWriteMem32 (VmPtr, (UINTN) VmPtr->Gpr[0], Data32); } return EFI_SUCCESS; @@ -2879,7 +2826,6 @@ ExecutePUSH ( @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecutePOPn ( IN VM_CONTEXT *VmPtr @@ -2913,15 +2859,15 @@ ExecutePOPn ( // // Read the data off the stack, then adjust the stack pointer // - DataN = VmReadMemN (VmPtr, (UINTN) VmPtr->R[0]); - VmPtr->R[0] += sizeof (UINTN); + DataN = VmReadMemN (VmPtr, (UINTN) VmPtr->Gpr[0]); + VmPtr->Gpr[0] += sizeof (UINTN); // // Do the write-back // if (OPERAND1_INDIRECT (Operands)) { - VmWriteMemN (VmPtr, (UINTN) (VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16), DataN); + VmWriteMemN (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16), DataN); } else { - VmPtr->R[OPERAND1_REGNUM (Operands)] = (INT64) (UINT64) ((UINTN) DataN + Index16); + VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = (INT64) (UINT64) ((UINTN) DataN + Index16); } return EFI_SUCCESS; @@ -2939,7 +2885,6 @@ ExecutePOPn ( @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecutePOP ( IN VM_CONTEXT *VmPtr @@ -2978,29 +2923,29 @@ ExecutePOP ( // // Read the data off the stack, then adjust the stack pointer // - Data64 = VmReadMem64 (VmPtr, (UINTN) VmPtr->R[0]); - VmPtr->R[0] += sizeof (UINT64); + Data64 = VmReadMem64 (VmPtr, (UINTN) VmPtr->Gpr[0]); + VmPtr->Gpr[0] += sizeof (UINT64); // // Do the write-back // if (OPERAND1_INDIRECT (Operands)) { - VmWriteMem64 (VmPtr, (UINTN) (VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16), Data64); + VmWriteMem64 (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16), Data64); } else { - VmPtr->R[OPERAND1_REGNUM (Operands)] = Data64 + Index16; + VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = Data64 + Index16; } } else { // // 32-bit pop. Read it off the stack and adjust the stack pointer // - Data32 = (INT32) VmReadMem32 (VmPtr, (UINTN) VmPtr->R[0]); - VmPtr->R[0] += sizeof (UINT32); + Data32 = (INT32) VmReadMem32 (VmPtr, (UINTN) VmPtr->Gpr[0]); + VmPtr->Gpr[0] += sizeof (UINT32); // // Do the write-back // if (OPERAND1_INDIRECT (Operands)) { - VmWriteMem32 (VmPtr, (UINTN) (VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16), Data32); + VmWriteMem32 (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16), Data32); } else { - VmPtr->R[OPERAND1_REGNUM (Operands)] = (INT64) Data32 + Index16; + VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = (INT64) Data32 + Index16; } } @@ -3024,7 +2969,6 @@ ExecutePOP ( @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteCALL ( IN VM_CONTEXT *VmPtr @@ -3042,6 +2986,13 @@ ExecuteCALL ( // Opcode = GETOPCODE (VmPtr); Operands = GETOPERANDS (VmPtr); + + if (Operands & OPERAND_M_NATIVE_CALL) { + EbcDebuggerHookCALLEXStart (VmPtr); + } else { + EbcDebuggerHookCALLStart (VmPtr); + } + // // Assign these as well to avoid compiler warnings // @@ -3076,11 +3027,11 @@ ExecuteCALL ( // put our return address and frame pointer on the VM stack. // if ((Operands & OPERAND_M_NATIVE_CALL) == 0) { - VmPtr->R[0] -= 8; - VmWriteMemN (VmPtr, (UINTN) VmPtr->R[0], (UINTN) FramePtr); - VmPtr->FramePtr = (VOID *) (UINTN) VmPtr->R[0]; - VmPtr->R[0] -= 8; - VmWriteMem64 (VmPtr, (UINTN) VmPtr->R[0], (UINT64) (UINTN) (VmPtr->Ip + Size)); + VmPtr->Gpr[0] -= 8; + VmWriteMemN (VmPtr, (UINTN) VmPtr->Gpr[0], (UINTN) FramePtr); + VmPtr->FramePtr = (VOID *) (UINTN) VmPtr->Gpr[0]; + VmPtr->Gpr[0] -= 8; + VmWriteMem64 (VmPtr, (UINTN) VmPtr->Gpr[0], (UINT64) (UINTN) (VmPtr->Ip + Size)); } // // If 64-bit data, then absolute jump only @@ -3095,7 +3046,7 @@ ExecuteCALL ( // // Call external function, get the return value, and advance the IP // - EbcLLCALLEX (VmPtr, (UINTN) Immed64, (UINTN) VmPtr->R[0], FramePtr, Size); + EbcLLCALLEX (VmPtr, (UINTN) Immed64, (UINTN) VmPtr->Gpr[0], FramePtr, Size); } } else { // @@ -3104,7 +3055,7 @@ ExecuteCALL ( // Compiler should take care of upper bits if 32-bit machine. // if (OPERAND1_REGNUM (Operands) != 0) { - Immed64 = (UINT64) (UINTN) VmPtr->R[OPERAND1_REGNUM (Operands)]; + Immed64 = (UINT64) (UINTN) VmPtr->Gpr[OPERAND1_REGNUM (Operands)]; } // // Get final address @@ -3132,17 +3083,23 @@ ExecuteCALL ( // Native call. Relative or absolute? // if ((Operands & OPERAND_M_RELATIVE_ADDR) != 0) { - EbcLLCALLEX (VmPtr, (UINTN) (Immed64 + VmPtr->Ip + Size), (UINTN) VmPtr->R[0], FramePtr, Size); + EbcLLCALLEX (VmPtr, (UINTN) (Immed64 + VmPtr->Ip + Size), (UINTN) VmPtr->Gpr[0], FramePtr, Size); } else { if ((VmPtr->StopFlags & STOPFLAG_BREAK_ON_CALLEX) != 0) { CpuBreakpoint (); } - EbcLLCALLEX (VmPtr, (UINTN) Immed64, (UINTN) VmPtr->R[0], FramePtr, Size); + EbcLLCALLEX (VmPtr, (UINTN) Immed64, (UINTN) VmPtr->Gpr[0], FramePtr, Size); } } } + if (Operands & OPERAND_M_NATIVE_CALL) { + EbcDebuggerHookCALLEXEnd (VmPtr); + } else { + EbcDebuggerHookCALLEnd (VmPtr); + } + return EFI_SUCCESS; } @@ -3158,24 +3115,26 @@ ExecuteCALL ( @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteRET ( IN VM_CONTEXT *VmPtr ) { + + EbcDebuggerHookRETStart (VmPtr); + // // If we're at the top of the stack, then simply set the done // flag and return // - if (VmPtr->StackRetAddr == (UINT64) VmPtr->R[0]) { + if (VmPtr->StackRetAddr == (UINT64) VmPtr->Gpr[0]) { VmPtr->StopFlags |= STOPFLAG_APP_DONE; } else { // // Pull the return address off the VM app's stack and set the IP // to it // - if (!IS_ALIGNED ((UINTN) VmPtr->R[0], sizeof (UINT16))) { + if (!IS_ALIGNED ((UINTN) VmPtr->Gpr[0], sizeof (UINT16))) { EbcDebugSignalException ( EXCEPT_EBC_ALIGNMENT_CHECK, EXCEPTION_FLAG_FATAL, @@ -3185,12 +3144,15 @@ ExecuteRET ( // // Restore the IP and frame pointer from the stack // - VmPtr->Ip = (VMIP) (UINTN) VmReadMem64 (VmPtr, (UINTN) VmPtr->R[0]); - VmPtr->R[0] += 8; - VmPtr->FramePtr = (VOID *) VmReadMemN (VmPtr, (UINTN) VmPtr->R[0]); - VmPtr->R[0] += 8; + VmPtr->Ip = (VMIP) (UINTN) VmReadMem64 (VmPtr, (UINTN) VmPtr->Gpr[0]); + VmPtr->Gpr[0] += 8; + VmPtr->FramePtr = (VOID *) VmReadMemN (VmPtr, (UINTN) VmPtr->Gpr[0]); + VmPtr->Gpr[0] += 8; } + + EbcDebuggerHookRETEnd (VmPtr); + return EFI_SUCCESS; } @@ -3203,11 +3165,10 @@ ExecuteRET ( @param VmPtr A pointer to a VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteCMP ( IN VM_CONTEXT *VmPtr @@ -3229,7 +3190,7 @@ ExecuteCMP ( // // Get the register data we're going to compare to // - Op1 = VmPtr->R[OPERAND1_REGNUM (Operands)]; + Op1 = VmPtr->Gpr[OPERAND1_REGNUM (Operands)]; // // Get immediate data // @@ -3250,15 +3211,15 @@ ExecuteCMP ( // if (OPERAND2_INDIRECT (Operands)) { if ((Opcode & OPCODE_M_64BIT) != 0) { - Op2 = (INT64) VmReadMem64 (VmPtr, (UINTN) (VmPtr->R[OPERAND2_REGNUM (Operands)] + Index16)); + Op2 = (INT64) VmReadMem64 (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND2_REGNUM (Operands)] + Index16)); } else { // // 32-bit operations. 0-extend the values for all cases. // - Op2 = (INT64) (UINT64) ((UINT32) VmReadMem32 (VmPtr, (UINTN) (VmPtr->R[OPERAND2_REGNUM (Operands)] + Index16))); + Op2 = (INT64) (UINT64) ((UINT32) VmReadMem32 (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND2_REGNUM (Operands)] + Index16))); } } else { - Op2 = VmPtr->R[OPERAND2_REGNUM (Operands)] + Index16; + Op2 = VmPtr->Gpr[OPERAND2_REGNUM (Operands)] + Index16; } // // Now do the compare @@ -3347,7 +3308,7 @@ ExecuteCMP ( if (Flag != 0) { VMFLAG_SET (VmPtr, VMFLAGS_CC); } else { - VMFLAG_CLEAR (VmPtr, VMFLAGS_CC); + VMFLAG_CLEAR (VmPtr, (UINT64)VMFLAGS_CC); } // // Advance the IP @@ -3365,11 +3326,10 @@ ExecuteCMP ( @param VmPtr A pointer to a VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteCMPI ( IN VM_CONTEXT *VmPtr @@ -3402,7 +3362,7 @@ ExecuteCMPI ( // // Get operand1 data we're going to compare to // - Op1 = (INT64) VmPtr->R[OPERAND1_REGNUM (Operands)]; + Op1 = (INT64) VmPtr->Gpr[OPERAND1_REGNUM (Operands)]; if (OPERAND1_INDIRECT (Operands)) { // // Indirect operand1. Fetch 32 or 64-bit value based on compare size. @@ -3527,7 +3487,7 @@ ExecuteCMPI ( if (Flag != 0) { VMFLAG_SET (VmPtr, VMFLAGS_CC); } else { - VMFLAG_CLEAR (VmPtr, VMFLAGS_CC); + VMFLAG_CLEAR (VmPtr, (UINT64)VMFLAGS_CC); } // // Advance the IP @@ -3550,7 +3510,6 @@ ExecuteCMPI ( @return ~Op2 **/ -STATIC UINT64 ExecuteNOT ( IN VM_CONTEXT *VmPtr, @@ -3575,7 +3534,6 @@ ExecuteNOT ( @return Op2 * -1 **/ -STATIC UINT64 ExecuteNEG ( IN VM_CONTEXT *VmPtr, @@ -3600,7 +3558,6 @@ ExecuteNEG ( @return Op1 + Op2 **/ -STATIC UINT64 ExecuteADD ( IN VM_CONTEXT *VmPtr, @@ -3625,7 +3582,6 @@ ExecuteADD ( @return Op1 - Op2 **/ -STATIC UINT64 ExecuteSUB ( IN VM_CONTEXT *VmPtr, @@ -3654,7 +3610,6 @@ ExecuteSUB ( @return Op1 * Op2 **/ -STATIC UINT64 ExecuteMUL ( IN VM_CONTEXT *VmPtr, @@ -3683,7 +3638,6 @@ ExecuteMUL ( @return (unsigned)Op1 * (unsigned)Op2 **/ -STATIC UINT64 ExecuteMULU ( IN VM_CONTEXT *VmPtr, @@ -3712,7 +3666,6 @@ ExecuteMULU ( @return Op1 / Op2 **/ -STATIC UINT64 ExecuteDIV ( IN VM_CONTEXT *VmPtr, @@ -3756,7 +3709,6 @@ ExecuteDIV ( @return (unsigned)Op1 / (unsigned)Op2 **/ -STATIC UINT64 ExecuteDIVU ( IN VM_CONTEXT *VmPtr, @@ -3781,7 +3733,7 @@ ExecuteDIVU ( // Get the destination register // if ((*VmPtr->Ip & DATAMANIP_M_64) != 0) { - return (UINT64) (DivU64x64Remainder ((INT64)Op1, (INT64)Op2, &Remainder)); + return (UINT64) (DivU64x64Remainder (Op1, Op2, &Remainder)); } else { return (UINT64) ((UINT32) Op1 / (UINT32) Op2); } @@ -3802,7 +3754,6 @@ ExecuteDIVU ( @return Op1 MODULUS Op2 **/ -STATIC UINT64 ExecuteMOD ( IN VM_CONTEXT *VmPtr, @@ -3842,7 +3793,6 @@ ExecuteMOD ( @return Op1 UNSIGNED_MODULUS Op2 **/ -STATIC UINT64 ExecuteMODU ( IN VM_CONTEXT *VmPtr, @@ -3882,7 +3832,6 @@ ExecuteMODU ( @return Op1 AND Op2 **/ -STATIC UINT64 ExecuteAND ( IN VM_CONTEXT *VmPtr, @@ -3907,7 +3856,6 @@ ExecuteAND ( @return Op1 OR Op2 **/ -STATIC UINT64 ExecuteOR ( IN VM_CONTEXT *VmPtr, @@ -3932,7 +3880,6 @@ ExecuteOR ( @return Op1 XOR Op2 **/ -STATIC UINT64 ExecuteXOR ( IN VM_CONTEXT *VmPtr, @@ -3957,7 +3904,6 @@ ExecuteXOR ( @return Op1 << Op2 **/ -STATIC UINT64 ExecuteSHL ( IN VM_CONTEXT *VmPtr, @@ -3986,7 +3932,6 @@ ExecuteSHL ( @return Op1 >> Op2 (unsigned operands) **/ -STATIC UINT64 ExecuteSHR ( IN VM_CONTEXT *VmPtr, @@ -4015,7 +3960,6 @@ ExecuteSHR ( @return Op1 >> Op2 (signed) **/ -STATIC UINT64 ExecuteASHR ( IN VM_CONTEXT *VmPtr, @@ -4044,7 +3988,6 @@ ExecuteASHR ( @return (INT64)(INT8)Op2 **/ -STATIC UINT64 ExecuteEXTNDB ( IN VM_CONTEXT *VmPtr, @@ -4078,7 +4021,6 @@ ExecuteEXTNDB ( @return (INT64)(INT16)Op2 **/ -STATIC UINT64 ExecuteEXTNDW ( IN VM_CONTEXT *VmPtr, @@ -4119,7 +4061,6 @@ ExecuteEXTNDW ( @return (INT64)(INT32)Op2 **/ -STATIC UINT64 ExecuteEXTNDD ( IN VM_CONTEXT *VmPtr, @@ -4153,11 +4094,10 @@ ExecuteEXTNDD ( @param VmPtr A pointer to VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteSignedDataManip ( IN VM_CONTEXT *VmPtr @@ -4184,11 +4124,10 @@ ExecuteSignedDataManip ( @param VmPtr A pointer to VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteUnsignedDataManip ( IN VM_CONTEXT *VmPtr @@ -4216,11 +4155,10 @@ ExecuteUnsignedDataManip ( @param VmPtr A pointer to VM context. @param IsSignedOp Indicates whether the operand is signed or not. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteDataManip ( IN VM_CONTEXT *VmPtr, @@ -4233,6 +4171,7 @@ ExecuteDataManip ( UINT8 Size; UINT64 Op1; UINT64 Op2; + INTN DataManipDispatchTableIndex; // // Get opcode and operands @@ -4261,7 +4200,7 @@ ExecuteDataManip ( // // Now get operand2 (source). It's of format {@}R2 {Index16|Immed16} // - Op2 = (UINT64) VmPtr->R[OPERAND2_REGNUM (Operands)] + Index16; + Op2 = (UINT64) VmPtr->Gpr[OPERAND2_REGNUM (Operands)] + Index16; if (OPERAND2_INDIRECT (Operands)) { // // Indirect form: @R2 Index16. Fetch as 32- or 64-bit data @@ -4291,7 +4230,7 @@ ExecuteDataManip ( // Get operand1 (destination and sometimes also an actual operand) // of form {@}R1 // - Op1 = VmPtr->R[OPERAND1_REGNUM (Operands)]; + Op1 = (UINT64) VmPtr->Gpr[OPERAND1_REGNUM (Operands)]; if (OPERAND1_INDIRECT (Operands)) { if ((Opcode & DATAMANIP_M_64) != 0) { Op1 = VmReadMem64 (VmPtr, (UINTN) Op1); @@ -4314,9 +4253,9 @@ ExecuteDataManip ( // // Dispatch to the computation function // - if (((Opcode & OPCODE_M_OPCODE) - OPCODE_NOT) >= - (sizeof (mDataManipDispatchTable) / sizeof (mDataManipDispatchTable[0])) - ) { + DataManipDispatchTableIndex = (Opcode & OPCODE_M_OPCODE) - OPCODE_NOT; + if ((DataManipDispatchTableIndex < 0) || + (DataManipDispatchTableIndex >= ARRAY_SIZE (mDataManipDispatchTable))) { EbcDebugSignalException ( EXCEPT_EBC_INVALID_OPCODE, EXCEPTION_FLAG_ERROR, @@ -4328,13 +4267,13 @@ ExecuteDataManip ( VmPtr->Ip += Size; return EFI_UNSUPPORTED; } else { - Op2 = mDataManipDispatchTable[(Opcode & OPCODE_M_OPCODE) - OPCODE_NOT](VmPtr, Op1, Op2); + Op2 = mDataManipDispatchTable[DataManipDispatchTableIndex](VmPtr, Op1, Op2); } // // Write back the result. // if (OPERAND1_INDIRECT (Operands)) { - Op1 = VmPtr->R[OPERAND1_REGNUM (Operands)]; + Op1 = (UINT64) VmPtr->Gpr[OPERAND1_REGNUM (Operands)]; if ((Opcode & DATAMANIP_M_64) != 0) { VmWriteMem64 (VmPtr, (UINTN) Op1, Op2); } else { @@ -4345,9 +4284,9 @@ ExecuteDataManip ( // Storage back to a register. Write back, clearing upper bits (as per // the specification) if 32-bit operation. // - VmPtr->R[OPERAND1_REGNUM (Operands)] = Op2; + VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = Op2; if ((Opcode & DATAMANIP_M_64) == 0) { - VmPtr->R[OPERAND1_REGNUM (Operands)] &= 0xFFFFFFFF; + VmPtr->Gpr[OPERAND1_REGNUM (Operands)] &= 0xFFFFFFFF; } } // @@ -4366,11 +4305,10 @@ ExecuteDataManip ( @param VmPtr A pointer to a VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteLOADSP ( IN VM_CONTEXT *VmPtr @@ -4395,7 +4333,7 @@ ExecuteLOADSP ( // Spec states that this instruction will not modify reserved bits in // the flags register. // - VmPtr->Flags = (VmPtr->Flags &~VMFLAGS_ALL_VALID) | (VmPtr->R[OPERAND2_REGNUM (Operands)] & VMFLAGS_ALL_VALID); + VmPtr->Flags = (VmPtr->Flags &~VMFLAGS_ALL_VALID) | (VmPtr->Gpr[OPERAND2_REGNUM (Operands)] & VMFLAGS_ALL_VALID); break; default: @@ -4421,11 +4359,10 @@ ExecuteLOADSP ( @param VmPtr A pointer to a VM context. - @retval EFI_UNSUPPORTED The opcodes/operands is not supported. + @retval EFI_UNSUPPORTED The opcodes/operands is not supported. @retval EFI_SUCCESS The instruction is executed successfully. **/ -STATIC EFI_STATUS ExecuteSTORESP ( IN VM_CONTEXT *VmPtr @@ -4449,14 +4386,14 @@ ExecuteSTORESP ( // // Retrieve the value in the flags register, then clear reserved bits // - VmPtr->R[OPERAND1_REGNUM (Operands)] = (UINT64) (VmPtr->Flags & VMFLAGS_ALL_VALID); + VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = (UINT64) (VmPtr->Flags & VMFLAGS_ALL_VALID); break; // // Get IP -- address of following instruction // case 1: - VmPtr->R[OPERAND1_REGNUM (Operands)] = (UINT64) (UINTN) VmPtr->Ip + 2; + VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = (UINT64) (UINTN) VmPtr->Ip + 2; break; default: @@ -4482,13 +4419,13 @@ ExecuteSTORESP ( b14:12 - number of bits in this index assigned to natural units (=a) ba:11 - constant units = ConstUnits b0:a - natural units = NaturalUnits - + Given this info, the offset can be computed by: offset = sign_bit * (ConstUnits + NaturalUnits * sizeof(UINTN)) Max offset is achieved with index = 0x7FFF giving an offset of 0x27B (32-bit machine) or 0x477 (64-bit machine). - Min offset is achieved with index = + Min offset is achieved with index = @param VmPtr A pointer to VM context. @param CodeOffset Offset from IP of the location of the 16-bit index @@ -4497,7 +4434,6 @@ ExecuteSTORESP ( @return The decoded offset. **/ -STATIC INT16 VmReadIndex16 ( IN VM_CONTEXT *VmPtr, @@ -4569,7 +4505,6 @@ VmReadIndex16 ( @return Converted index per EBC VM specification. **/ -STATIC INT32 VmReadIndex32 ( IN VM_CONTEXT *VmPtr, @@ -4633,7 +4568,6 @@ VmReadIndex32 ( @return Converted index per EBC VM specification **/ -STATIC INT64 VmReadIndex64 ( IN VM_CONTEXT *VmPtr, @@ -4674,7 +4608,7 @@ VmReadIndex64 ( // ConstUnits = ARShiftU64 (((Index &~0xF000000000000000ULL) & Mask), (UINTN)NBits); - Offset = MultU64x64 (NaturalUnits, sizeof (UINTN)) + ConstUnits; + Offset = MultU64x64 ((UINT64) NaturalUnits, sizeof (UINTN)) + ConstUnits; // // Now set the sign @@ -4689,7 +4623,7 @@ VmReadIndex64 ( /** Writes 8-bit data to memory address. - + This routine is called by the EBC data movement instructions that write to memory. Since these writes may be to the stack, which looks like (high address on top) this, @@ -4699,18 +4633,17 @@ VmReadIndex64 ( [EBC stack] we need to detect all attempts to write to the EBC entry point argument - stack area and adjust the address (which will initially point into the + stack area and adjust the address (which will initially point into the VM stack) to point into the EBC entry point arguments. @param VmPtr A pointer to a VM context. - @param Addr Adddress to write to. + @param Addr Address to write to. @param Data Value to write to Addr. - @retval EFI_SUCCESS The instruction is executed successfully. + @retval EFI_SUCCESS The instruction is executed successfully. @retval Other Some error occurs when writing data to the address. **/ -STATIC EFI_STATUS VmWriteMem8 ( IN VM_CONTEXT *VmPtr, @@ -4728,7 +4661,7 @@ VmWriteMem8 ( /** Writes 16-bit data to memory address. - + This routine is called by the EBC data movement instructions that write to memory. Since these writes may be to the stack, which looks like (high address on top) this, @@ -4738,18 +4671,17 @@ VmWriteMem8 ( [EBC stack] we need to detect all attempts to write to the EBC entry point argument - stack area and adjust the address (which will initially point into the + stack area and adjust the address (which will initially point into the VM stack) to point into the EBC entry point arguments. @param VmPtr A pointer to a VM context. - @param Addr Adddress to write to. + @param Addr Address to write to. @param Data Value to write to Addr. - @retval EFI_SUCCESS The instruction is executed successfully. + @retval EFI_SUCCESS The instruction is executed successfully. @retval Other Some error occurs when writing data to the address. **/ -STATIC EFI_STATUS VmWriteMem16 ( IN VM_CONTEXT *VmPtr, @@ -4792,7 +4724,7 @@ VmWriteMem16 ( /** Writes 32-bit data to memory address. - + This routine is called by the EBC data movement instructions that write to memory. Since these writes may be to the stack, which looks like (high address on top) this, @@ -4802,18 +4734,17 @@ VmWriteMem16 ( [EBC stack] we need to detect all attempts to write to the EBC entry point argument - stack area and adjust the address (which will initially point into the + stack area and adjust the address (which will initially point into the VM stack) to point into the EBC entry point arguments. @param VmPtr A pointer to a VM context. - @param Addr Adddress to write to. + @param Addr Address to write to. @param Data Value to write to Addr. - @retval EFI_SUCCESS The instruction is executed successfully. + @retval EFI_SUCCESS The instruction is executed successfully. @retval Other Some error occurs when writing data to the address. **/ -STATIC EFI_STATUS VmWriteMem32 ( IN VM_CONTEXT *VmPtr, @@ -4856,7 +4787,7 @@ VmWriteMem32 ( /** Writes 64-bit data to memory address. - + This routine is called by the EBC data movement instructions that write to memory. Since these writes may be to the stack, which looks like (high address on top) this, @@ -4866,14 +4797,14 @@ VmWriteMem32 ( [EBC stack] we need to detect all attempts to write to the EBC entry point argument - stack area and adjust the address (which will initially point into the + stack area and adjust the address (which will initially point into the VM stack) to point into the EBC entry point arguments. @param VmPtr A pointer to a VM context. - @param Addr Adddress to write to. + @param Addr Address to write to. @param Data Value to write to Addr. - @retval EFI_SUCCESS The instruction is executed successfully. + @retval EFI_SUCCESS The instruction is executed successfully. @retval Other Some error occurs when writing data to the address. **/ @@ -4885,7 +4816,6 @@ VmWriteMem64 ( ) { EFI_STATUS Status; - UINT32 Data32; // // Convert the address if it's in the stack gap @@ -4907,8 +4837,7 @@ VmWriteMem64 ( } MemoryFence (); - Data32 = (UINT32) (((UINT32 *) &Data)[1]); - if ((Status = VmWriteMem32 (VmPtr, Addr + sizeof (UINT32), Data32)) != EFI_SUCCESS) { + if ((Status = VmWriteMem32 (VmPtr, Addr + sizeof (UINT32), (UINT32) RShiftU64(Data, 32))) != EFI_SUCCESS) { return Status; } @@ -4921,7 +4850,7 @@ VmWriteMem64 ( /** Writes UINTN data to memory address. - + This routine is called by the EBC data movement instructions that write to memory. Since these writes may be to the stack, which looks like (high address on top) this, @@ -4931,14 +4860,14 @@ VmWriteMem64 ( [EBC stack] we need to detect all attempts to write to the EBC entry point argument - stack area and adjust the address (which will initially point into the + stack area and adjust the address (which will initially point into the VM stack) to point into the EBC entry point arguments. @param VmPtr A pointer to a VM context. - @param Addr Adddress to write to. + @param Addr Address to write to. @param Data Value to write to Addr. - @retval EFI_SUCCESS The instruction is executed successfully. + @retval EFI_SUCCESS The instruction is executed successfully. @retval Other Some error occurs when writing data to the address. **/ @@ -4969,7 +4898,7 @@ VmWriteMemN ( MemoryFence (); Status = VmWriteMem32 (VmPtr, Addr + Index * sizeof (UINT32), (UINT32) Data); MemoryFence (); - Data = (UINTN)RShiftU64 ((UINT64)Data, 32); + Data = (UINTN) RShiftU64 ((UINT64)Data, 32); } } @@ -4991,7 +4920,6 @@ VmWriteMemN ( @return Signed data of the requested size from the specified address. **/ -STATIC INT8 VmReadImmed8 ( IN VM_CONTEXT *VmPtr, @@ -5018,7 +4946,6 @@ VmReadImmed8 ( @return Signed data of the requested size from the specified address. **/ -STATIC INT16 VmReadImmed16 ( IN VM_CONTEXT *VmPtr, @@ -5061,7 +4988,6 @@ VmReadImmed16 ( @return Signed data of the requested size from the specified address. **/ -STATIC INT32 VmReadImmed32 ( IN VM_CONTEXT *VmPtr, @@ -5079,8 +5005,8 @@ VmReadImmed32 ( // // Return unaligned data // - Data = (UINT32) VmReadCode16 (VmPtr, Offset); - Data |= (UINT32) (VmReadCode16 (VmPtr, Offset + 2) << 16); + Data = (UINT32) VmReadCode16 (VmPtr, Offset); + Data |= (UINT32)(VmReadCode16 (VmPtr, Offset + 2) << 16); return Data; } @@ -5099,7 +5025,6 @@ VmReadImmed32 ( @return Signed data of the requested size from the specified address. **/ -STATIC INT64 VmReadImmed64 ( IN VM_CONTEXT *VmPtr, @@ -5122,7 +5047,7 @@ VmReadImmed64 ( Ptr = (UINT8 *) &Data64; Data32 = VmReadCode32 (VmPtr, Offset); *(UINT32 *) Ptr = Data32; - Ptr += sizeof (Data32); + Ptr += sizeof (Data32); Data32 = VmReadCode32 (VmPtr, Offset + sizeof (UINT32)); *(UINT32 *) Ptr = Data32; return Data64; @@ -5130,7 +5055,7 @@ VmReadImmed64 ( /** - Reads 16-bit unsinged data from the code stream. + Reads 16-bit unsigned data from the code stream. This routine provides the ability to read raw unsigned data from the code stream. @@ -5141,7 +5066,6 @@ VmReadImmed64 ( @return The raw unsigned 16-bit value from the code stream. **/ -STATIC UINT16 VmReadCode16 ( IN VM_CONTEXT *VmPtr, @@ -5171,7 +5095,7 @@ VmReadCode16 ( /** - Reads 32-bit unsinged data from the code stream. + Reads 32-bit unsigned data from the code stream. This routine provides the ability to read raw unsigned data from the code stream. @@ -5182,7 +5106,6 @@ VmReadCode16 ( @return The raw unsigned 32-bit value from the code stream. **/ -STATIC UINT32 VmReadCode32 ( IN VM_CONTEXT *VmPtr, @@ -5206,7 +5129,7 @@ VmReadCode32 ( /** - Reads 64-bit unsinged data from the code stream. + Reads 64-bit unsigned data from the code stream. This routine provides the ability to read raw unsigned data from the code stream. @@ -5217,7 +5140,6 @@ VmReadCode32 ( @return The raw unsigned 64-bit value from the code stream. **/ -STATIC UINT64 VmReadCode64 ( IN VM_CONTEXT *VmPtr, @@ -5240,7 +5162,7 @@ VmReadCode64 ( Ptr = (UINT8 *) &Data64; Data32 = VmReadCode32 (VmPtr, Offset); *(UINT32 *) Ptr = Data32; - Ptr += sizeof (Data32); + Ptr += sizeof (Data32); Data32 = VmReadCode32 (VmPtr, Offset + sizeof (UINT32)); *(UINT32 *) Ptr = Data32; return Data64; @@ -5253,10 +5175,9 @@ VmReadCode64 ( @param VmPtr A pointer to VM context. @param Addr The memory address. - @return The 8-bit value from the memory adress. + @return The 8-bit value from the memory address. **/ -STATIC UINT8 VmReadMem8 ( IN VM_CONTEXT *VmPtr, @@ -5279,10 +5200,9 @@ VmReadMem8 ( @param VmPtr A pointer to VM context. @param Addr The memory address. - @return The 16-bit value from the memory adress. + @return The 16-bit value from the memory address. **/ -STATIC UINT16 VmReadMem16 ( IN VM_CONTEXT *VmPtr, @@ -5311,10 +5231,9 @@ VmReadMem16 ( @param VmPtr A pointer to VM context. @param Addr The memory address. - @return The 32-bit value from the memory adress. + @return The 32-bit value from the memory address. **/ -STATIC UINT32 VmReadMem32 ( IN VM_CONTEXT *VmPtr, @@ -5347,10 +5266,9 @@ VmReadMem32 ( @param VmPtr A pointer to VM context. @param Addr The memory address. - @return The 64-bit value from the memory adress. + @return The 64-bit value from the memory address. **/ -STATIC UINT64 VmReadMem64 ( IN VM_CONTEXT *VmPtr, @@ -5374,9 +5292,9 @@ VmReadMem64 ( // // Return unaligned data. Assume little endian. // - Data = (UINT64) VmReadMem32 (VmPtr, Addr); - Data32 = VmReadMem32 (VmPtr, Addr + sizeof (UINT32)); - *(UINT32 *) ((UINT32 *) &Data + 1) = Data32; + Data32 = VmReadMem32 (VmPtr, Addr); + Data = (UINT64) VmReadMem32 (VmPtr, Addr + sizeof (UINT32)); + Data = LShiftU64 (Data, 32) | Data32; return Data; } @@ -5400,7 +5318,6 @@ VmReadMem64 ( adjust for the stack gap and return the modified address. **/ -STATIC UINTN ConvertStackAddr ( IN VM_CONTEXT *VmPtr, @@ -5421,7 +5338,6 @@ ConvertStackAddr ( @return The natural value at address Addr. **/ -STATIC UINTN VmReadMemN ( IN VM_CONTEXT *VmPtr, @@ -5460,7 +5376,7 @@ VmReadMemN ( /** Returns the version of the EBC virtual machine. - + @return The 64-bit version of EBC virtual machine. **/