]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/EbcDxe/EbcExecute.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / EbcDxe / EbcExecute.c
index 31ff76d80d4237562ce81b5f6f2c1c348637c11f..1c4a4f5155c92ed7e5281989b3441b0515724f68 100644 (file)
@@ -1,19 +1,14 @@
 /** @file\r
   Contains code that implements the virtual machine.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include "EbcInt.h"\r
 #include "EbcExecute.h"\r
+#include "EbcDebuggerHook.h"\r
 \r
 \r
 //\r
@@ -49,13 +44,13 @@ UINT64
     b14:12  - number of bits in this index assigned to natural units (=a)\r
     ba:11   - constant units = ConstUnits\r
     b0:a    - natural units = NaturalUnits\r
-  \r
+\r
   Given this info, the offset can be computed by:\r
     offset = sign_bit * (ConstUnits + NaturalUnits * sizeof(UINTN))\r
 \r
   Max offset is achieved with index = 0x7FFF giving an offset of\r
   0x27B (32-bit machine) or 0x477 (64-bit machine).\r
-  Min offset is achieved with index = \r
+  Min offset is achieved with index =\r
 \r
   @param  VmPtr             A pointer to VM context.\r
   @param  CodeOffset        Offset from IP of the location of the 16-bit index\r
@@ -64,11 +59,10 @@ UINT64
   @return The decoded offset.\r
 \r
 **/\r
-STATIC\r
 INT16\r
 VmReadIndex16 (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT32     CodeOffset\r
+  IN VM_CONTEXT     *VmPtr,\r
+  IN UINT32         CodeOffset\r
   );\r
 \r
 /**\r
@@ -81,11 +75,10 @@ VmReadIndex16 (
   @return Converted index per EBC VM specification.\r
 \r
 **/\r
-STATIC\r
 INT32\r
 VmReadIndex32 (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT32     CodeOffset\r
+  IN VM_CONTEXT     *VmPtr,\r
+  IN UINT32         CodeOffset\r
   );\r
 \r
 /**\r
@@ -98,11 +91,10 @@ VmReadIndex32 (
   @return Converted index per EBC VM specification\r
 \r
 **/\r
-STATIC\r
 INT64\r
 VmReadIndex64 (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT32     CodeOffset\r
+  IN VM_CONTEXT     *VmPtr,\r
+  IN UINT32         CodeOffset\r
   );\r
 \r
 /**\r
@@ -111,14 +103,13 @@ VmReadIndex64 (
   @param  VmPtr             A pointer to VM context.\r
   @param  Addr              The memory address.\r
 \r
-  @return The 8-bit value from the memory adress.\r
+  @return The 8-bit value from the memory address.\r
 \r
 **/\r
-STATIC\r
 UINT8\r
 VmReadMem8 (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINTN      Addr\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINTN        Addr\r
   );\r
 \r
 /**\r
@@ -127,10 +118,9 @@ VmReadMem8 (
   @param  VmPtr             A pointer to VM context.\r
   @param  Addr              The memory address.\r
 \r
-  @return The 16-bit value from the memory adress.\r
+  @return The 16-bit value from the memory address.\r
 \r
 **/\r
-STATIC\r
 UINT16\r
 VmReadMem16 (\r
   IN VM_CONTEXT *VmPtr,\r
@@ -143,10 +133,9 @@ VmReadMem16 (
   @param  VmPtr             A pointer to VM context.\r
   @param  Addr              The memory address.\r
 \r
-  @return The 32-bit value from the memory adress.\r
+  @return The 32-bit value from the memory address.\r
 \r
 **/\r
-STATIC\r
 UINT32\r
 VmReadMem32 (\r
   IN VM_CONTEXT *VmPtr,\r
@@ -159,14 +148,13 @@ VmReadMem32 (
   @param  VmPtr             A pointer to VM context.\r
   @param  Addr              The memory address.\r
 \r
-  @return The 64-bit value from the memory adress.\r
+  @return The 64-bit value from the memory address.\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 VmReadMem64 (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINTN      Addr\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINTN        Addr\r
   );\r
 \r
 /**\r
@@ -178,16 +166,15 @@ VmReadMem64 (
   @return The natural value at address Addr.\r
 \r
 **/\r
-STATIC\r
 UINTN\r
 VmReadMemN (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINTN      Addr\r
+  IN VM_CONTEXT    *VmPtr,\r
+  IN UINTN         Addr\r
   );\r
 \r
 /**\r
   Writes 8-bit data to memory address.\r
-   \r
+\r
   This routine is called by the EBC data\r
   movement instructions that write to memory. Since these writes\r
   may be to the stack, which looks like (high address on top) this,\r
@@ -197,28 +184,27 @@ VmReadMemN (
   [EBC stack]\r
 \r
   we need to detect all attempts to write to the EBC entry point argument\r
-  stack area and adjust the address (which will initially point into the \r
+  stack area and adjust the address (which will initially point into the\r
   VM stack) to point into the EBC entry point arguments.\r
 \r
   @param  VmPtr             A pointer to a VM context.\r
-  @param  Addr              Adddress to write to.\r
+  @param  Addr              Address to write to.\r
   @param  Data              Value to write to Addr.\r
 \r
-  @retval EFI_SUCCESS       The instruction is executed successfully.  \r
+  @retval EFI_SUCCESS       The instruction is executed successfully.\r
   @retval Other             Some error occurs when writing data to the address.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 VmWriteMem8 (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINTN      Addr,\r
-  IN UINT8      Data\r
+  IN VM_CONTEXT    *VmPtr,\r
+  IN UINTN         Addr,\r
+  IN UINT8         Data\r
   );\r
 \r
 /**\r
   Writes 16-bit data to memory address.\r
-   \r
+\r
   This routine is called by the EBC data\r
   movement instructions that write to memory. Since these writes\r
   may be to the stack, which looks like (high address on top) this,\r
@@ -228,28 +214,27 @@ VmWriteMem8 (
   [EBC stack]\r
 \r
   we need to detect all attempts to write to the EBC entry point argument\r
-  stack area and adjust the address (which will initially point into the \r
+  stack area and adjust the address (which will initially point into the\r
   VM stack) to point into the EBC entry point arguments.\r
 \r
   @param  VmPtr             A pointer to a VM context.\r
-  @param  Addr              Adddress to write to.\r
+  @param  Addr              Address to write to.\r
   @param  Data              Value to write to Addr.\r
 \r
-  @retval EFI_SUCCESS       The instruction is executed successfully.  \r
+  @retval EFI_SUCCESS       The instruction is executed successfully.\r
   @retval Other             Some error occurs when writing data to the address.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 VmWriteMem16 (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINTN      Addr,\r
-  IN UINT16     Data\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINTN        Addr,\r
+  IN UINT16       Data\r
   );\r
 \r
 /**\r
   Writes 32-bit data to memory address.\r
-   \r
+\r
   This routine is called by the EBC data\r
   movement instructions that write to memory. Since these writes\r
   may be to the stack, which looks like (high address on top) this,\r
@@ -259,27 +244,26 @@ VmWriteMem16 (
   [EBC stack]\r
 \r
   we need to detect all attempts to write to the EBC entry point argument\r
-  stack area and adjust the address (which will initially point into the \r
+  stack area and adjust the address (which will initially point into the\r
   VM stack) to point into the EBC entry point arguments.\r
 \r
   @param  VmPtr             A pointer to a VM context.\r
-  @param  Addr              Adddress to write to.\r
+  @param  Addr              Address to write to.\r
   @param  Data              Value to write to Addr.\r
 \r
-  @retval EFI_SUCCESS       The instruction is executed successfully.  \r
+  @retval EFI_SUCCESS       The instruction is executed successfully.\r
   @retval Other             Some error occurs when writing data to the address.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 VmWriteMem32 (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINTN      Addr,\r
-  IN UINT32     Data\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINTN        Addr,\r
+  IN UINT32       Data\r
   );\r
 \r
 /**\r
-  Reads 16-bit unsinged data from the code stream.\r
+  Reads 16-bit unsigned data from the code stream.\r
 \r
   This routine provides the ability to read raw unsigned data from the code\r
   stream.\r
@@ -290,7 +274,6 @@ VmWriteMem32 (
   @return The raw unsigned 16-bit value from the code stream.\r
 \r
 **/\r
-STATIC\r
 UINT16\r
 VmReadCode16 (\r
   IN VM_CONTEXT *VmPtr,\r
@@ -298,7 +281,7 @@ VmReadCode16 (
   );\r
 \r
 /**\r
-  Reads 32-bit unsinged data from the code stream.\r
+  Reads 32-bit unsigned data from the code stream.\r
 \r
   This routine provides the ability to read raw unsigned data from the code\r
   stream.\r
@@ -309,7 +292,6 @@ VmReadCode16 (
   @return The raw unsigned 32-bit value from the code stream.\r
 \r
 **/\r
-STATIC\r
 UINT32\r
 VmReadCode32 (\r
   IN VM_CONTEXT *VmPtr,\r
@@ -317,7 +299,7 @@ VmReadCode32 (
   );\r
 \r
 /**\r
-  Reads 64-bit unsinged data from the code stream.\r
+  Reads 64-bit unsigned data from the code stream.\r
 \r
   This routine provides the ability to read raw unsigned data from the code\r
   stream.\r
@@ -328,7 +310,6 @@ VmReadCode32 (
   @return The raw unsigned 64-bit value from the code stream.\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 VmReadCode64 (\r
   IN VM_CONTEXT *VmPtr,\r
@@ -349,7 +330,6 @@ VmReadCode64 (
   @return Signed data of the requested size from the specified address.\r
 \r
 **/\r
-STATIC\r
 INT8\r
 VmReadImmed8 (\r
   IN VM_CONTEXT *VmPtr,\r
@@ -370,7 +350,6 @@ VmReadImmed8 (
   @return Signed data of the requested size from the specified address.\r
 \r
 **/\r
-STATIC\r
 INT16\r
 VmReadImmed16 (\r
   IN VM_CONTEXT *VmPtr,\r
@@ -391,7 +370,6 @@ VmReadImmed16 (
   @return Signed data of the requested size from the specified address.\r
 \r
 **/\r
-STATIC\r
 INT32\r
 VmReadImmed32 (\r
   IN VM_CONTEXT *VmPtr,\r
@@ -412,7 +390,6 @@ VmReadImmed32 (
   @return Signed data of the requested size from the specified address.\r
 \r
 **/\r
-STATIC\r
 INT64\r
 VmReadImmed64 (\r
   IN VM_CONTEXT *VmPtr,\r
@@ -438,11 +415,10 @@ VmReadImmed64 (
           adjust for the stack gap and return the modified address.\r
 \r
 **/\r
-STATIC\r
 UINTN\r
 ConvertStackAddr (\r
-  IN VM_CONTEXT   *VmPtr,\r
-  IN UINTN        Addr\r
+  IN VM_CONTEXT    *VmPtr,\r
+  IN UINTN         Addr\r
   );\r
 \r
 /**\r
@@ -459,11 +435,10 @@ ConvertStackAddr (
   @param  VmPtr             A pointer to VM context.\r
   @param  IsSignedOp        Indicates whether the operand is signed or not.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteDataManip (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -481,7 +456,6 @@ ExecuteDataManip (
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteBREAK (\r
   IN VM_CONTEXT *VmPtr\r
@@ -493,7 +467,7 @@ ExecuteBREAK (
   Instruction syntax:\r
     JMP64{cs|cc} Immed64\r
     JMP32{cs|cc} {@}R1 {Immed32|Index32}\r
-  \r
+\r
   Encoding:\r
     b0.7 -  immediate data present\r
     b0.6 -  1 = 64 bit immediate data\r
@@ -512,7 +486,6 @@ ExecuteBREAK (
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteJMP (\r
   IN VM_CONTEXT *VmPtr\r
@@ -529,7 +502,6 @@ ExecuteJMP (
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteJMP8 (\r
   IN VM_CONTEXT *VmPtr\r
@@ -551,7 +523,6 @@ ExecuteJMP8 (
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteCALL (\r
   IN VM_CONTEXT *VmPtr\r
@@ -568,7 +539,6 @@ ExecuteCALL (
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteRET (\r
   IN VM_CONTEXT *VmPtr\r
@@ -582,11 +552,10 @@ ExecuteRET (
 \r
   @param  VmPtr             A pointer to a VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteCMP (\r
   IN VM_CONTEXT *VmPtr\r
@@ -600,11 +569,10 @@ ExecuteCMP (
 \r
   @param  VmPtr             A pointer to a VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteCMPI (\r
   IN VM_CONTEXT *VmPtr\r
@@ -614,15 +582,15 @@ ExecuteCMPI (
   Execute the MOVxx instructions.\r
 \r
   Instruction format:\r
-    \r
+\r
     MOV[b|w|d|q|n]{w|d} {@}R1 {Index16|32}, {@}R2 {Index16|32}\r
     MOVqq {@}R1 {Index64}, {@}R2 {Index64}\r
-  \r
+\r
     Copies contents of [R2] -> [R1], zero extending where required.\r
-  \r
+\r
     First character indicates the size of the move.\r
     Second character indicates the size of the index(s).\r
-  \r
+\r
     Invalid to have R1 direct with index.\r
 \r
   @param  VmPtr             A pointer to a VM context.\r
@@ -631,7 +599,6 @@ ExecuteCMPI (
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteMOVxx (\r
   IN VM_CONTEXT *VmPtr\r
@@ -641,24 +608,23 @@ ExecuteMOVxx (
   Execute the EBC MOVI.\r
 \r
   Instruction syntax:\r
-  \r
+\r
     MOVI[b|w|d|q][w|d|q] {@}R1 {Index16}, ImmData16|32|64\r
-  \r
+\r
     First variable character specifies the move size\r
     Second variable character specifies size of the immediate data\r
-  \r
+\r
     Sign-extend the immediate data to the size of the operation, and zero-extend\r
     if storing to a register.\r
-  \r
+\r
     Operand1 direct with index/immed is invalid.\r
 \r
   @param  VmPtr             A pointer to a VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteMOVI (\r
   IN VM_CONTEXT *VmPtr\r
@@ -669,16 +635,15 @@ ExecuteMOVI (
   index value into a register or memory location.\r
 \r
   Instruction syntax:\r
-  \r
+\r
     MOVIn[w|d|q] {@}R1 {Index16}, Index16|32|64\r
 \r
   @param  VmPtr             A pointer to a VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteMOVIn (\r
   IN VM_CONTEXT *VmPtr\r
@@ -689,16 +654,15 @@ ExecuteMOVIn (
   Dest <- Ip + ImmData\r
 \r
   Instruction syntax:\r
-  \r
+\r
     MOVREL[w|d|q] {@}R1 {Index16}, ImmData16|32|64\r
 \r
   @param  VmPtr             A pointer to a VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteMOVREL (\r
   IN VM_CONTEXT *VmPtr\r
@@ -715,7 +679,6 @@ ExecuteMOVREL (
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecutePUSHn (\r
   IN VM_CONTEXT *VmPtr\r
@@ -732,7 +695,6 @@ ExecutePUSHn (
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecutePUSH (\r
   IN VM_CONTEXT *VmPtr\r
@@ -749,7 +711,6 @@ ExecutePUSH (
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecutePOPn (\r
   IN VM_CONTEXT *VmPtr\r
@@ -766,7 +727,6 @@ ExecutePOPn (
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecutePOP (\r
   IN VM_CONTEXT *VmPtr\r
@@ -785,14 +745,13 @@ ExecutePOP (
 \r
   @param  VmPtr             A pointer to VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteSignedDataManip (\r
-  IN VM_CONTEXT *VmPtr\r
+  IN VM_CONTEXT   *VmPtr\r
   );\r
 \r
 /**\r
@@ -808,14 +767,13 @@ ExecuteSignedDataManip (
 \r
   @param  VmPtr             A pointer to VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteUnsignedDataManip (\r
-  IN VM_CONTEXT *VmPtr\r
+  IN VM_CONTEXT   *VmPtr\r
   );\r
 \r
 /**\r
@@ -826,11 +784,10 @@ ExecuteUnsignedDataManip (
 \r
   @param  VmPtr             A pointer to a VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteLOADSP (\r
   IN VM_CONTEXT *VmPtr\r
@@ -844,11 +801,10 @@ ExecuteLOADSP (
 \r
   @param  VmPtr             A pointer to a VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteSTORESP (\r
   IN VM_CONTEXT *VmPtr\r
@@ -861,19 +817,18 @@ ExecuteSTORESP (
   is a register.\r
 \r
   Instruction syntax:\r
-  \r
+\r
     MOVsnd {@}R1 {Indx32}, {@}R2 {Index32|Immed32}\r
-  \r
+\r
     0:7 1=>operand1 index present\r
     0:6 1=>operand2 index present\r
 \r
   @param  VmPtr             A pointer to a VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteMOVsnd (\r
   IN VM_CONTEXT *VmPtr\r
@@ -886,19 +841,18 @@ ExecuteMOVsnd (
   is a register.\r
 \r
   Instruction syntax:\r
-  \r
+\r
     MOVsnw {@}R1 {Index16}, {@}R2 {Index16|Immed16}\r
-  \r
+\r
     0:7 1=>operand1 index present\r
     0:6 1=>operand2 index present\r
 \r
   @param  VmPtr             A pointer to a VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteMOVsnw (\r
   IN VM_CONTEXT *VmPtr\r
@@ -920,12 +874,11 @@ ExecuteMOVsnw (
   @return ~Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteNOT (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT64     Op1,\r
-  IN UINT64     Op2\r
+  IN VM_CONTEXT     *VmPtr,\r
+  IN UINT64         Op1,\r
+  IN UINT64         Op2\r
   );\r
 \r
 /**\r
@@ -941,12 +894,11 @@ ExecuteNOT (
   @return Op2 * -1\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteNEG (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT64     Op1,\r
-  IN UINT64     Op2\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINT64       Op1,\r
+  IN UINT64       Op2\r
   );\r
 \r
 /**\r
@@ -962,12 +914,11 @@ ExecuteNEG (
   @return Op1 + Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteADD (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT64     Op1,\r
-  IN UINT64     Op2\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINT64       Op1,\r
+  IN UINT64       Op2\r
   );\r
 \r
 /**\r
@@ -983,12 +934,11 @@ ExecuteADD (
   @return Op1 - Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteSUB (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT64     Op1,\r
-  IN UINT64     Op2\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINT64       Op1,\r
+  IN UINT64       Op2\r
   );\r
 \r
 /**\r
@@ -1004,12 +954,11 @@ ExecuteSUB (
   @return Op1 * Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteMUL (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT64     Op1,\r
-  IN UINT64     Op2\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINT64       Op1,\r
+  IN UINT64       Op2\r
   );\r
 \r
 /**\r
@@ -1025,12 +974,11 @@ ExecuteMUL (
   @return (unsigned)Op1 * (unsigned)Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteMULU (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT64     Op1,\r
-  IN UINT64     Op2\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINT64       Op1,\r
+  IN UINT64       Op2\r
   );\r
 \r
 /**\r
@@ -1046,12 +994,11 @@ ExecuteMULU (
   @return Op1 / Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteDIV (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT64     Op1,\r
-  IN UINT64     Op2\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINT64       Op1,\r
+  IN UINT64       Op2\r
   );\r
 \r
 /**\r
@@ -1067,12 +1014,11 @@ ExecuteDIV (
   @return (unsigned)Op1 / (unsigned)Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteDIVU (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT64     Op1,\r
-  IN UINT64     Op2\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINT64       Op1,\r
+  IN UINT64       Op2\r
   );\r
 \r
 /**\r
@@ -1088,12 +1034,11 @@ ExecuteDIVU (
   @return Op1 MODULUS Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteMOD (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT64     Op1,\r
-  IN UINT64     Op2\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINT64       Op1,\r
+  IN UINT64       Op2\r
   );\r
 \r
 /**\r
@@ -1109,12 +1054,11 @@ ExecuteMOD (
   @return Op1 UNSIGNED_MODULUS Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteMODU (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT64     Op1,\r
-  IN UINT64     Op2\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINT64       Op1,\r
+  IN UINT64       Op2\r
   );\r
 \r
 /**\r
@@ -1130,12 +1074,11 @@ ExecuteMODU (
   @return Op1 AND Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteAND (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT64     Op1,\r
-  IN UINT64     Op2\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINT64       Op1,\r
+  IN UINT64       Op2\r
   );\r
 \r
 /**\r
@@ -1151,12 +1094,11 @@ ExecuteAND (
   @return Op1 OR Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteOR (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT64     Op1,\r
-  IN UINT64     Op2\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINT64       Op1,\r
+  IN UINT64       Op2\r
   );\r
 \r
 /**\r
@@ -1172,12 +1114,11 @@ ExecuteOR (
   @return Op1 XOR Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteXOR (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT64     Op1,\r
-  IN UINT64     Op2\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINT64       Op1,\r
+  IN UINT64       Op2\r
   );\r
 \r
 /**\r
@@ -1193,12 +1134,11 @@ ExecuteXOR (
   @return Op1 << Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteSHL (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT64     Op1,\r
-  IN UINT64     Op2\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINT64       Op1,\r
+  IN UINT64       Op2\r
   );\r
 \r
 /**\r
@@ -1214,12 +1154,11 @@ ExecuteSHL (
   @return Op1 >> Op2  (unsigned operands)\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteSHR (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT64     Op1,\r
-  IN UINT64     Op2\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINT64       Op1,\r
+  IN UINT64       Op2\r
   );\r
 \r
 /**\r
@@ -1235,12 +1174,11 @@ ExecuteSHR (
   @return Op1 >> Op2 (signed)\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteASHR (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT64     Op1,\r
-  IN UINT64     Op2\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINT64       Op1,\r
+  IN UINT64       Op2\r
   );\r
 \r
 /**\r
@@ -1256,12 +1194,11 @@ ExecuteASHR (
   @return (INT64)(INT8)Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteEXTNDB (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT64     Op1,\r
-  IN UINT64     Op2\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINT64       Op1,\r
+  IN UINT64       Op2\r
   );\r
 \r
 /**\r
@@ -1277,12 +1214,11 @@ ExecuteEXTNDB (
   @return (INT64)(INT16)Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteEXTNDW (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT64     Op1,\r
-  IN UINT64     Op2\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINT64       Op1,\r
+  IN UINT64       Op2\r
   );\r
 \r
 /**\r
@@ -1298,19 +1234,18 @@ ExecuteEXTNDW (
   @return (INT64)(INT32)Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteEXTNDD (\r
-  IN VM_CONTEXT *VmPtr,\r
-  IN UINT64     Op1,\r
-  IN UINT64     Op2\r
+  IN VM_CONTEXT   *VmPtr,\r
+  IN UINT64       Op1,\r
+  IN UINT64       Op2\r
   );\r
 \r
 //\r
 // Once we retrieve the operands for the data manipulation instructions,\r
 // call these functions to perform the operation.\r
 //\r
-STATIC CONST DATA_MANIP_EXEC_FUNCTION mDataManipDispatchTable[] = {\r
+CONST DATA_MANIP_EXEC_FUNCTION mDataManipDispatchTable[] = {\r
   ExecuteNOT,\r
   ExecuteNEG,\r
   ExecuteADD,\r
@@ -1332,7 +1267,7 @@ STATIC CONST DATA_MANIP_EXEC_FUNCTION mDataManipDispatchTable[] = {
   ExecuteEXTNDD,\r
 };\r
 \r
-STATIC CONST VM_TABLE_ENTRY           mVmOpcodeTable[] = {\r
+CONST VM_TABLE_ENTRY           mVmOpcodeTable[] = {\r
   { ExecuteBREAK },             // opcode 0x00\r
   { ExecuteJMP },               // opcode 0x01\r
   { ExecuteJMP8 },              // opcode 0x02\r
@@ -1390,19 +1325,19 @@ STATIC CONST VM_TABLE_ENTRY           mVmOpcodeTable[] = {
   { ExecutePOPn },              // opcode 0x36\r
   { ExecuteMOVI },              // opcode 0x37 - mov immediate data\r
   { ExecuteMOVIn },             // opcode 0x38 - mov immediate natural\r
-  { ExecuteMOVREL }             // opcode 0x39 - move data relative to PC\r
+  { ExecuteMOVREL },            // opcode 0x39 - move data relative to PC\r
+  { NULL },                     // opcode 0x3a\r
+  { NULL },                     // opcode 0x3b\r
+  { NULL },                     // opcode 0x3c\r
+  { NULL },                     // opcode 0x3d\r
+  { NULL },                     // opcode 0x3e\r
+  { NULL }                      // opcode 0x3f\r
 };\r
 \r
 //\r
 // Length of JMP instructions, depending on upper two bits of opcode.\r
 //\r
-STATIC CONST UINT8                    mJMPLen[] = { 2, 2, 6, 10 };\r
-\r
-//\r
-// Simple Debugger Protocol GUID\r
-//\r
-EFI_GUID mEbcSimpleDebuggerProtocolGuid = EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL_GUID;\r
-\r
+CONST UINT8                    mJMPLen[] = { 2, 2, 6, 10 };\r
 \r
 /**\r
   Given a pointer to a new VM context, execute one or more instructions. This\r
@@ -1419,6 +1354,7 @@ EFI_GUID mEbcSimpleDebuggerProtocolGuid = EFI_EBC_SIMPLE_DEBUGGER_PROTOCOL_GUID;
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 EbcExecuteInstructions (\r
   IN EFI_EBC_VM_TEST_PROTOCOL *This,\r
   IN VM_CONTEXT               *VmPtr,\r
@@ -1447,12 +1383,12 @@ EbcExecuteInstructions (
   // call it if it's not null.\r
   //\r
   while (InstructionsLeft != 0) {\r
-    ExecFunc = (UINTN) mVmOpcodeTable[(*VmPtr->Ip & 0x3F)].ExecuteFunction;\r
+    ExecFunc = (UINTN) mVmOpcodeTable[(*VmPtr->Ip & OPCODE_M_OPCODE)].ExecuteFunction;\r
     if (ExecFunc == (UINTN) NULL) {\r
       EbcDebugSignalException (EXCEPT_EBC_INVALID_OPCODE, EXCEPTION_FLAG_FATAL, VmPtr);\r
       return EFI_UNSUPPORTED;\r
     } else {\r
-      mVmOpcodeTable[(*VmPtr->Ip & 0x3F)].ExecuteFunction (VmPtr);\r
+      mVmOpcodeTable[(*VmPtr->Ip & OPCODE_M_OPCODE)].ExecuteFunction (VmPtr);\r
       *InstructionCount = *InstructionCount + 1;\r
     }\r
 \r
@@ -1499,14 +1435,14 @@ EbcExecute (
     StackCorrupted = 1;\r
   }\r
 \r
-  VmPtr->FramePtr = (VOID *) ((UINT8 *) (UINTN) VmPtr->R[0] + 8);\r
+  VmPtr->FramePtr = (VOID *) ((UINT8 *) (UINTN) VmPtr->Gpr[0] + 8);\r
 \r
   //\r
   // Try to get the debug support for EBC\r
   //\r
   DEBUG_CODE_BEGIN ();\r
     Status = gBS->LocateProtocol (\r
-                    &mEbcSimpleDebuggerProtocolGuid,\r
+                    &gEfiEbcSimpleDebuggerProtocolGuid,\r
                     NULL,\r
                     (VOID **) &EbcSimpleDebugger\r
                     );\r
@@ -1537,14 +1473,6 @@ EbcExecute (
       }\r
     DEBUG_CODE_END ();\r
 \r
-    //\r
-    // Verify the opcode is in range. Otherwise generate an exception.\r
-    //\r
-    if ((*VmPtr->Ip & OPCODE_M_OPCODE) >= (sizeof (mVmOpcodeTable) / sizeof (mVmOpcodeTable[0]))) {\r
-      EbcDebugSignalException (EXCEPT_EBC_INVALID_OPCODE, EXCEPTION_FLAG_FATAL, VmPtr);\r
-      Status = EFI_UNSUPPORTED;\r
-      goto Done;\r
-    }\r
     //\r
     // Use the opcode bits to index into the opcode dispatch table. If the\r
     // function pointer is null then generate an exception.\r
@@ -1555,6 +1483,9 @@ EbcExecute (
       Status = EFI_UNSUPPORTED;\r
       goto Done;\r
     }\r
+\r
+    EbcDebuggerHookExecuteStart (VmPtr);\r
+\r
     //\r
     // The EBC VM is a strongly ordered processor, so perform a fence operation before\r
     // and after each instruction is executed.\r
@@ -1565,6 +1496,8 @@ EbcExecute (
 \r
     MemoryFence ();\r
 \r
+    EbcDebuggerHookExecuteEnd (VmPtr);\r
+\r
     //\r
     // If the step flag is set, signal an exception and continue. We don't\r
     // clear it here. Assuming the debugger is responsible for clearing it.\r
@@ -1579,7 +1512,7 @@ EbcExecute (
       EbcDebugSignalException (EXCEPT_EBC_STACK_FAULT, EXCEPTION_FLAG_FATAL, VmPtr);\r
       StackCorrupted = 1;\r
     }\r
-    if ((StackCorrupted == 0) && ((UINT64)VmPtr->R[0] <= (UINT64)(UINTN) VmPtr->StackTop)) {\r
+    if ((StackCorrupted == 0) && ((UINT64)VmPtr->Gpr[0] <= (UINT64)(UINTN) VmPtr->StackTop)) {\r
       EbcDebugSignalException (EXCEPT_EBC_STACK_FAULT, EXCEPTION_FLAG_FATAL, VmPtr);\r
       StackCorrupted = 1;\r
     }\r
@@ -1596,15 +1529,15 @@ Done:
   Execute the MOVxx instructions.\r
 \r
   Instruction format:\r
-    \r
+\r
     MOV[b|w|d|q|n]{w|d} {@}R1 {Index16|32}, {@}R2 {Index16|32}\r
     MOVqq {@}R1 {Index64}, {@}R2 {Index64}\r
-  \r
+\r
     Copies contents of [R2] -> [R1], zero extending where required.\r
-  \r
+\r
     First character indicates the size of the move.\r
     Second character indicates the size of the index(s).\r
-  \r
+\r
     Invalid to have R1 direct with index.\r
 \r
   @param  VmPtr             A pointer to a VM context.\r
@@ -1613,7 +1546,6 @@ Done:
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteMOVxx (\r
   IN VM_CONTEXT *VmPtr\r
@@ -1745,7 +1677,7 @@ ExecuteMOVxx (
     //\r
     // Indirect form @R2. Compute address of operand2\r
     //\r
-    Source = (UINTN) (VmPtr->R[OPERAND2_REGNUM (Operands)] + Index64Op2);\r
+    Source = (UINTN) (VmPtr->Gpr[OPERAND2_REGNUM (Operands)] + Index64Op2);\r
     //\r
     // Now get the data from the source. Always 0-extend and let the compiler\r
     // sign-extend where required.\r
@@ -1781,7 +1713,7 @@ ExecuteMOVxx (
     //\r
     // Not indirect source: MOVxx {@}Rx, Ry [Index]\r
     //\r
-    Data64 = VmPtr->R[OPERAND2_REGNUM (Operands)] + Index64Op2;\r
+    Data64 = (UINT64) (VmPtr->Gpr[OPERAND2_REGNUM (Operands)] + Index64Op2);\r
     //\r
     // Did Operand2 have an index? If so, treat as two signed values since\r
     // indexes are signed values.\r
@@ -1817,7 +1749,7 @@ ExecuteMOVxx (
     //\r
     // Reuse the Source variable to now be dest.\r
     //\r
-    Source = (UINTN) (VmPtr->R[OPERAND1_REGNUM (Operands)] + Index64Op1);\r
+    Source = (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index64Op1);\r
     //\r
     // Do the write based on the size\r
     //\r
@@ -1865,7 +1797,7 @@ ExecuteMOVxx (
     // Direct storage in register. Clear unused bits and store back to\r
     // register.\r
     //\r
-    VmPtr->R[OPERAND1_REGNUM (Operands)] = Data64 & DataMask;\r
+    VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = Data64 & DataMask;\r
   }\r
   //\r
   // Advance the instruction pointer\r
@@ -1883,18 +1815,19 @@ ExecuteMOVxx (
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteBREAK (\r
   IN VM_CONTEXT *VmPtr\r
   )\r
 {\r
+  EFI_STATUS  Status;\r
   UINT8       Operands;\r
   VOID        *EbcEntryPoint;\r
   VOID        *Thunk;\r
   UINT64      U64EbcEntryPoint;\r
   INT32       Offset;\r
 \r
+  Thunk = NULL;\r
   Operands = GETOPERANDS (VmPtr);\r
   switch (Operands) {\r
   //\r
@@ -1914,7 +1847,7 @@ ExecuteBREAK (
     //  16-8  = Major version\r
     //  7-0   = Minor version\r
     //\r
-    VmPtr->R[7] = GetVmVersion ();\r
+    VmPtr->Gpr[7] = GetVmVersion ();\r
     break;\r
 \r
   //\r
@@ -1944,26 +1877,29 @@ ExecuteBREAK (
   // After we're done, *(UINT64 *)R7 will be the address of the new thunk.\r
   //\r
   case 5:\r
-    Offset            = (INT32) VmReadMem32 (VmPtr, (UINTN) VmPtr->R[7]);\r
-    U64EbcEntryPoint  = (UINT64) (VmPtr->R[7] + Offset + 4);\r
+    Offset            = (INT32) VmReadMem32 (VmPtr, (UINTN) VmPtr->Gpr[7]);\r
+    U64EbcEntryPoint  = (UINT64) (VmPtr->Gpr[7] + Offset + 4);\r
     EbcEntryPoint     = (VOID *) (UINTN) U64EbcEntryPoint;\r
 \r
     //\r
     // Now create a new thunk\r
     //\r
-    EbcCreateThunks (VmPtr->ImageHandle, EbcEntryPoint, &Thunk, 0);\r
+    Status = EbcCreateThunks (VmPtr->ImageHandle, EbcEntryPoint, &Thunk, 0);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
 \r
     //\r
     // Finally replace the EBC entry point memory with the thunk address\r
     //\r
-    VmWriteMem64 (VmPtr, (UINTN) VmPtr->R[7], (UINT64) (UINTN) Thunk);\r
+    VmWriteMem64 (VmPtr, (UINTN) VmPtr->Gpr[7], (UINT64) (UINTN) Thunk);\r
     break;\r
 \r
   //\r
   // Compiler setting version per value in R7\r
   //\r
   case 6:\r
-    VmPtr->CompilerVersion = (UINT32) VmPtr->R[7];\r
+    VmPtr->CompilerVersion = (UINT32) VmPtr->Gpr[7];\r
     //\r
     // Check compiler version against VM version?\r
     //\r
@@ -1990,7 +1926,7 @@ ExecuteBREAK (
   Instruction syntax:\r
     JMP64{cs|cc} Immed64\r
     JMP32{cs|cc} {@}R1 {Immed32|Index32}\r
-  \r
+\r
   Encoding:\r
     b0.7 -  immediate data present\r
     b0.6 -  1 = 64 bit immediate data\r
@@ -2009,7 +1945,6 @@ ExecuteBREAK (
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteJMP (\r
   IN VM_CONTEXT *VmPtr\r
@@ -2041,7 +1976,9 @@ ExecuteJMP (
   ConditionFlag = (UINT8) VMFLAG_ISSET (VmPtr, VMFLAGS_CC);\r
   if ((Operand & CONDITION_M_CONDITIONAL) != 0) {\r
     if (CompareSet != ConditionFlag) {\r
+      EbcDebuggerHookJMPStart (VmPtr);\r
       VmPtr->Ip += Size;\r
+      EbcDebuggerHookJMPEnd (VmPtr);\r
       return EFI_SUCCESS;\r
     }\r
   }\r
@@ -2066,7 +2003,7 @@ ExecuteJMP (
     // 64-bit immediate data is full address. Read the immediate data,\r
     // check for alignment, and jump absolute.\r
     //\r
-    Data64 = VmReadImmed64 (VmPtr, 2);\r
+    Data64 = (UINT64) VmReadImmed64 (VmPtr, 2);\r
     if (!IS_ALIGNED ((UINTN) Data64, sizeof (UINT16))) {\r
       EbcDebugSignalException (\r
         EXCEPT_EBC_ALIGNMENT_CHECK,\r
@@ -2080,11 +2017,13 @@ ExecuteJMP (
     //\r
     // Take jump -- relative or absolute\r
     //\r
+    EbcDebuggerHookJMPStart (VmPtr);\r
     if ((Operand & JMP_M_RELATIVE) != 0) {\r
       VmPtr->Ip += (UINTN) Data64 + Size;\r
     } else {\r
       VmPtr->Ip = (VMIP) (UINTN) Data64;\r
     }\r
+    EbcDebuggerHookJMPEnd (VmPtr);\r
 \r
     return EFI_SUCCESS;\r
   }\r
@@ -2110,7 +2049,7 @@ ExecuteJMP (
   if (OPERAND1_REGNUM (Operand) == 0) {\r
     Data64 = 0;\r
   } else {\r
-    Data64 = OPERAND1_REGDATA (VmPtr, Operand);\r
+    Data64 = (UINT64) OPERAND1_REGDATA (VmPtr, Operand);\r
   }\r
   //\r
   // Decode the forms\r
@@ -2130,11 +2069,14 @@ ExecuteJMP (
       return EFI_UNSUPPORTED;\r
     }\r
 \r
+    EbcDebuggerHookJMPStart (VmPtr);\r
     if ((Operand & JMP_M_RELATIVE) != 0) {\r
       VmPtr->Ip += (UINTN) Addr + Size;\r
     } else {\r
       VmPtr->Ip = (VMIP) Addr;\r
     }\r
+    EbcDebuggerHookJMPEnd (VmPtr);\r
+\r
   } else {\r
     //\r
     // Form: JMP32 Rx {Immed32}\r
@@ -2150,11 +2092,14 @@ ExecuteJMP (
       return EFI_UNSUPPORTED;\r
     }\r
 \r
+    EbcDebuggerHookJMPStart (VmPtr);\r
     if ((Operand & JMP_M_RELATIVE) != 0) {\r
       VmPtr->Ip += (UINTN) Addr + Size;\r
     } else {\r
       VmPtr->Ip = (VMIP) Addr;\r
     }\r
+    EbcDebuggerHookJMPEnd (VmPtr);\r
+\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -2172,7 +2117,6 @@ ExecuteJMP (
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteJMP8 (\r
   IN VM_CONTEXT *VmPtr\r
@@ -2195,7 +2139,9 @@ ExecuteJMP8 (
   //\r
   if ((Opcode & CONDITION_M_CONDITIONAL) != 0) {\r
     if (CompareSet != ConditionFlag) {\r
+      EbcDebuggerHookJMP8Start (VmPtr);\r
       VmPtr->Ip += 2;\r
+      EbcDebuggerHookJMP8End (VmPtr);\r
       return EFI_SUCCESS;\r
     }\r
   }\r
@@ -2207,7 +2153,9 @@ ExecuteJMP8 (
   //\r
   // Want to check for offset == -2 and then raise an exception?\r
   //\r
+  EbcDebuggerHookJMP8Start (VmPtr);\r
   VmPtr->Ip += (Offset * 2) + 2;\r
+  EbcDebuggerHookJMP8End (VmPtr);\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -2216,24 +2164,23 @@ ExecuteJMP8 (
   Execute the EBC MOVI.\r
 \r
   Instruction syntax:\r
-  \r
+\r
     MOVI[b|w|d|q][w|d|q] {@}R1 {Index16}, ImmData16|32|64\r
-  \r
+\r
     First variable character specifies the move size\r
     Second variable character specifies size of the immediate data\r
-  \r
+\r
     Sign-extend the immediate data to the size of the operation, and zero-extend\r
     if storing to a register.\r
-  \r
+\r
     Operand1 direct with index/immed is invalid.\r
 \r
   @param  VmPtr             A pointer to a VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteMOVI (\r
   IN VM_CONTEXT *VmPtr\r
@@ -2314,12 +2261,12 @@ ExecuteMOVI (
       Mask64 = (UINT64)~0;\r
     }\r
 \r
-    VmPtr->R[OPERAND1_REGNUM (Operands)] = ImmData64 & Mask64;\r
+    VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = ImmData64 & Mask64;\r
   } else {\r
     //\r
     // Get the address then write back based on size of the move\r
     //\r
-    Op1 = (UINT64) VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16;\r
+    Op1 = (UINT64) VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16;\r
     if ((Operands & MOVI_M_MOVEWIDTH) == MOVI_MOVEWIDTH8) {\r
       VmWriteMem8 (VmPtr, (UINTN) Op1, (UINT8) ImmData64);\r
     } else if ((Operands & MOVI_M_MOVEWIDTH) == MOVI_MOVEWIDTH16) {\r
@@ -2327,7 +2274,7 @@ ExecuteMOVI (
     } else if ((Operands & MOVI_M_MOVEWIDTH) == MOVI_MOVEWIDTH32) {\r
       VmWriteMem32 (VmPtr, (UINTN) Op1, (UINT32) ImmData64);\r
     } else {\r
-      VmWriteMem64 (VmPtr, (UINTN) Op1, ImmData64);\r
+      VmWriteMem64 (VmPtr, (UINTN) Op1, (UINT64) ImmData64);\r
     }\r
   }\r
   //\r
@@ -2343,16 +2290,15 @@ ExecuteMOVI (
   index value into a register or memory location.\r
 \r
   Instruction syntax:\r
-  \r
+\r
     MOVIn[w|d|q] {@}R1 {Index16}, Index16|32|64\r
 \r
   @param  VmPtr             A pointer to a VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteMOVIn (\r
   IN VM_CONTEXT *VmPtr\r
@@ -2425,13 +2371,13 @@ ExecuteMOVIn (
       return EFI_UNSUPPORTED;\r
     }\r
 \r
-    VmPtr->R[OPERAND1_REGNUM (Operands)] = ImmedIndex64;\r
+    VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = ImmedIndex64;\r
   } else {\r
     //\r
     // Get the address\r
     //\r
-    Op1 = (UINT64) VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16;\r
-    VmWriteMemN (VmPtr, (UINTN) Op1, (INTN) ImmedIndex64);\r
+    Op1 = (UINT64) VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16;\r
+    VmWriteMemN (VmPtr, (UINTN) Op1, (UINTN)(INTN) ImmedIndex64);\r
   }\r
   //\r
   // Advance the instruction pointer\r
@@ -2446,16 +2392,15 @@ ExecuteMOVIn (
   Dest <- Ip + ImmData\r
 \r
   Instruction syntax:\r
-  \r
+\r
     MOVREL[w|d|q] {@}R1 {Index16}, ImmData16|32|64\r
 \r
   @param  VmPtr             A pointer to a VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteMOVREL (\r
   IN VM_CONTEXT *VmPtr\r
@@ -2525,14 +2470,14 @@ ExecuteMOVREL (
       return EFI_UNSUPPORTED;\r
     }\r
 \r
-    VmPtr->R[OPERAND1_REGNUM (Operands)] = (VM_REGISTER) Op2;\r
+    VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = (VM_REGISTER) Op2;\r
   } else {\r
     //\r
     // Get the address = [Rx] + Index16\r
     // Write back the result. Always a natural size write, since\r
     // we're talking addresses here.\r
     //\r
-    Op1 = (UINT64) VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16;\r
+    Op1 = (UINT64) VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16;\r
     VmWriteMemN (VmPtr, (UINTN) Op1, (UINTN) Op2);\r
   }\r
   //\r
@@ -2550,19 +2495,18 @@ ExecuteMOVREL (
   is a register.\r
 \r
   Instruction syntax:\r
-  \r
+\r
     MOVsnw {@}R1 {Index16}, {@}R2 {Index16|Immed16}\r
-  \r
+\r
     0:7 1=>operand1 index present\r
     0:6 1=>operand2 index present\r
 \r
   @param  VmPtr             A pointer to a VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteMOVsnw (\r
   IN VM_CONTEXT *VmPtr\r
@@ -2617,17 +2561,17 @@ ExecuteMOVsnw (
   //\r
   // Get the data from the source.\r
   //\r
-  Op2 = (INT64) ((INTN) (VmPtr->R[OPERAND2_REGNUM (Operands)] + Op2Index));\r
+  Op2 = (UINT64)(INT64)(INTN)(VmPtr->Gpr[OPERAND2_REGNUM (Operands)] + Op2Index);\r
   if (OPERAND2_INDIRECT (Operands)) {\r
-    Op2 = (INT64) (INTN) VmReadMemN (VmPtr, (UINTN) Op2);\r
+    Op2 = (UINT64)(INT64)(INTN)VmReadMemN (VmPtr, (UINTN) Op2);\r
   }\r
   //\r
   // Now write back the result.\r
   //\r
   if (!OPERAND1_INDIRECT (Operands)) {\r
-    VmPtr->R[OPERAND1_REGNUM (Operands)] = Op2;\r
+    VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = Op2;\r
   } else {\r
-    VmWriteMemN (VmPtr, (UINTN) (VmPtr->R[OPERAND1_REGNUM (Operands)] + Op1Index), (UINTN) Op2);\r
+    VmWriteMemN (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Op1Index), (UINTN) Op2);\r
   }\r
   //\r
   // Advance the instruction pointer\r
@@ -2644,19 +2588,18 @@ ExecuteMOVsnw (
   is a register.\r
 \r
   Instruction syntax:\r
-  \r
+\r
     MOVsnd {@}R1 {Indx32}, {@}R2 {Index32|Immed32}\r
-  \r
+\r
     0:7 1=>operand1 index present\r
     0:6 1=>operand2 index present\r
 \r
   @param  VmPtr             A pointer to a VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteMOVsnd (\r
   IN VM_CONTEXT *VmPtr\r
@@ -2711,17 +2654,17 @@ ExecuteMOVsnd (
   //\r
   // Get the data from the source.\r
   //\r
-  Op2 = (INT64) ((INTN) (VmPtr->R[OPERAND2_REGNUM (Operands)] + Op2Index));\r
+  Op2 = (UINT64)(INT64)(INTN)(INT64)(VmPtr->Gpr[OPERAND2_REGNUM (Operands)] + Op2Index);\r
   if (OPERAND2_INDIRECT (Operands)) {\r
-    Op2 = (INT64) (INTN) VmReadMemN (VmPtr, (UINTN) Op2);\r
+    Op2 = (UINT64)(INT64)(INTN)(INT64)VmReadMemN (VmPtr, (UINTN) Op2);\r
   }\r
   //\r
   // Now write back the result.\r
   //\r
   if (!OPERAND1_INDIRECT (Operands)) {\r
-    VmPtr->R[OPERAND1_REGNUM (Operands)] = Op2;\r
+    VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = Op2;\r
   } else {\r
-    VmWriteMemN (VmPtr, (UINTN) (VmPtr->R[OPERAND1_REGNUM (Operands)] + Op1Index), (UINTN) Op2);\r
+    VmWriteMemN (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Op1Index), (UINTN) Op2);\r
   }\r
   //\r
   // Advance the instruction pointer\r
@@ -2742,7 +2685,6 @@ ExecuteMOVsnd (
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecutePUSHn (\r
   IN VM_CONTEXT *VmPtr\r
@@ -2778,15 +2720,15 @@ ExecutePUSHn (
   // Get the data to push\r
   //\r
   if (OPERAND1_INDIRECT (Operands)) {\r
-    DataN = VmReadMemN (VmPtr, (UINTN) (VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16));\r
+    DataN = VmReadMemN (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16));\r
   } else {\r
-    DataN = (UINTN) (VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16);\r
+    DataN = (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16);\r
   }\r
   //\r
   // Adjust the stack down.\r
   //\r
-  VmPtr->R[0] -= sizeof (UINTN);\r
-  VmWriteMemN (VmPtr, (UINTN) VmPtr->R[0], DataN);\r
+  VmPtr->Gpr[0] -= sizeof (UINTN);\r
+  VmWriteMemN (VmPtr, (UINTN) VmPtr->Gpr[0], DataN);\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -2802,7 +2744,6 @@ ExecutePUSHn (
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecutePUSH (\r
   IN VM_CONTEXT *VmPtr\r
@@ -2839,29 +2780,29 @@ ExecutePUSH (
   //\r
   if ((Opcode & PUSHPOP_M_64) != 0) {\r
     if (OPERAND1_INDIRECT (Operands)) {\r
-      Data64 = VmReadMem64 (VmPtr, (UINTN) (VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16));\r
+      Data64 = VmReadMem64 (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16));\r
     } else {\r
-      Data64 = (UINT64) VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16;\r
+      Data64 = (UINT64) VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16;\r
     }\r
     //\r
     // Adjust the stack down, then write back the data\r
     //\r
-    VmPtr->R[0] -= sizeof (UINT64);\r
-    VmWriteMem64 (VmPtr, (UINTN) VmPtr->R[0], Data64);\r
+    VmPtr->Gpr[0] -= sizeof (UINT64);\r
+    VmWriteMem64 (VmPtr, (UINTN) VmPtr->Gpr[0], Data64);\r
   } else {\r
     //\r
     // 32-bit data\r
     //\r
     if (OPERAND1_INDIRECT (Operands)) {\r
-      Data32 = VmReadMem32 (VmPtr, (UINTN) (VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16));\r
+      Data32 = VmReadMem32 (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16));\r
     } else {\r
-      Data32 = (UINT32) VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16;\r
+      Data32 = (UINT32) VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16;\r
     }\r
     //\r
     // Adjust the stack down and write the data\r
     //\r
-    VmPtr->R[0] -= sizeof (UINT32);\r
-    VmWriteMem32 (VmPtr, (UINTN) VmPtr->R[0], Data32);\r
+    VmPtr->Gpr[0] -= sizeof (UINT32);\r
+    VmWriteMem32 (VmPtr, (UINTN) VmPtr->Gpr[0], Data32);\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -2879,7 +2820,6 @@ ExecutePUSH (
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecutePOPn (\r
   IN VM_CONTEXT *VmPtr\r
@@ -2913,15 +2853,15 @@ ExecutePOPn (
   //\r
   // Read the data off the stack, then adjust the stack pointer\r
   //\r
-  DataN = VmReadMemN (VmPtr, (UINTN) VmPtr->R[0]);\r
-  VmPtr->R[0] += sizeof (UINTN);\r
+  DataN = VmReadMemN (VmPtr, (UINTN) VmPtr->Gpr[0]);\r
+  VmPtr->Gpr[0] += sizeof (UINTN);\r
   //\r
   // Do the write-back\r
   //\r
   if (OPERAND1_INDIRECT (Operands)) {\r
-    VmWriteMemN (VmPtr, (UINTN) (VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16), DataN);\r
+    VmWriteMemN (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16), DataN);\r
   } else {\r
-    VmPtr->R[OPERAND1_REGNUM (Operands)] = (INT64) (UINT64) ((UINTN) DataN + Index16);\r
+    VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = (INT64) (UINT64) (UINTN) (DataN + Index16);\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -2939,7 +2879,6 @@ ExecutePOPn (
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecutePOP (\r
   IN VM_CONTEXT *VmPtr\r
@@ -2978,29 +2917,29 @@ ExecutePOP (
     //\r
     // Read the data off the stack, then adjust the stack pointer\r
     //\r
-    Data64 = VmReadMem64 (VmPtr, (UINTN) VmPtr->R[0]);\r
-    VmPtr->R[0] += sizeof (UINT64);\r
+    Data64 = VmReadMem64 (VmPtr, (UINTN) VmPtr->Gpr[0]);\r
+    VmPtr->Gpr[0] += sizeof (UINT64);\r
     //\r
     // Do the write-back\r
     //\r
     if (OPERAND1_INDIRECT (Operands)) {\r
-      VmWriteMem64 (VmPtr, (UINTN) (VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16), Data64);\r
+      VmWriteMem64 (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16), Data64);\r
     } else {\r
-      VmPtr->R[OPERAND1_REGNUM (Operands)] = Data64 + Index16;\r
+      VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = Data64 + Index16;\r
     }\r
   } else {\r
     //\r
     // 32-bit pop. Read it off the stack and adjust the stack pointer\r
     //\r
-    Data32 = (INT32) VmReadMem32 (VmPtr, (UINTN) VmPtr->R[0]);\r
-    VmPtr->R[0] += sizeof (UINT32);\r
+    Data32 = (INT32) VmReadMem32 (VmPtr, (UINTN) VmPtr->Gpr[0]);\r
+    VmPtr->Gpr[0] += sizeof (UINT32);\r
     //\r
     // Do the write-back\r
     //\r
     if (OPERAND1_INDIRECT (Operands)) {\r
-      VmWriteMem32 (VmPtr, (UINTN) (VmPtr->R[OPERAND1_REGNUM (Operands)] + Index16), Data32);\r
+      VmWriteMem32 (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND1_REGNUM (Operands)] + Index16), Data32);\r
     } else {\r
-      VmPtr->R[OPERAND1_REGNUM (Operands)] = (INT64) Data32 + Index16;\r
+      VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = (INT64) Data32 + Index16;\r
     }\r
   }\r
 \r
@@ -3024,7 +2963,6 @@ ExecutePOP (
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteCALL (\r
   IN VM_CONTEXT *VmPtr\r
@@ -3042,6 +2980,13 @@ ExecuteCALL (
   //\r
   Opcode    = GETOPCODE (VmPtr);\r
   Operands  = GETOPERANDS (VmPtr);\r
+\r
+  if ((Operands & OPERAND_M_NATIVE_CALL) != 0) {\r
+    EbcDebuggerHookCALLEXStart (VmPtr);\r
+  } else {\r
+    EbcDebuggerHookCALLStart (VmPtr);\r
+  }\r
+\r
   //\r
   // Assign these as well to avoid compiler warnings\r
   //\r
@@ -3076,11 +3021,11 @@ ExecuteCALL (
   // put our return address and frame pointer on the VM stack.\r
   //\r
   if ((Operands & OPERAND_M_NATIVE_CALL) == 0) {\r
-    VmPtr->R[0] -= 8;\r
-    VmWriteMemN (VmPtr, (UINTN) VmPtr->R[0], (UINTN) FramePtr);\r
-    VmPtr->FramePtr = (VOID *) (UINTN) VmPtr->R[0];\r
-    VmPtr->R[0] -= 8;\r
-    VmWriteMem64 (VmPtr, (UINTN) VmPtr->R[0], (UINT64) (UINTN) (VmPtr->Ip + Size));\r
+    VmPtr->Gpr[0] -= 8;\r
+    VmWriteMemN (VmPtr, (UINTN) VmPtr->Gpr[0], (UINTN) FramePtr);\r
+    VmPtr->FramePtr = (VOID *) (UINTN) VmPtr->Gpr[0];\r
+    VmPtr->Gpr[0] -= 8;\r
+    VmWriteMem64 (VmPtr, (UINTN) VmPtr->Gpr[0], (UINT64) (UINTN) (VmPtr->Ip + Size));\r
   }\r
   //\r
   // If 64-bit data, then absolute jump only\r
@@ -3095,7 +3040,7 @@ ExecuteCALL (
       //\r
       // Call external function, get the return value, and advance the IP\r
       //\r
-      EbcLLCALLEX (VmPtr, (UINTN) Immed64, (UINTN) VmPtr->R[0], FramePtr, Size);\r
+      EbcLLCALLEX (VmPtr, (UINTN) Immed64, (UINTN) VmPtr->Gpr[0], FramePtr, Size);\r
     }\r
   } else {\r
     //\r
@@ -3104,7 +3049,7 @@ ExecuteCALL (
     // Compiler should take care of upper bits if 32-bit machine.\r
     //\r
     if (OPERAND1_REGNUM (Operands) != 0) {\r
-      Immed64 = (UINT64) (UINTN) VmPtr->R[OPERAND1_REGNUM (Operands)];\r
+      Immed64 = (UINT64) (UINTN) VmPtr->Gpr[OPERAND1_REGNUM (Operands)];\r
     }\r
     //\r
     // Get final address\r
@@ -3132,17 +3077,23 @@ ExecuteCALL (
       // Native call. Relative or absolute?\r
       //\r
       if ((Operands & OPERAND_M_RELATIVE_ADDR) != 0) {\r
-        EbcLLCALLEX (VmPtr, (UINTN) (Immed64 + VmPtr->Ip + Size), (UINTN) VmPtr->R[0], FramePtr, Size);\r
+        EbcLLCALLEX (VmPtr, (UINTN) (Immed64 + VmPtr->Ip + Size), (UINTN) VmPtr->Gpr[0], FramePtr, Size);\r
       } else {\r
         if ((VmPtr->StopFlags & STOPFLAG_BREAK_ON_CALLEX) != 0) {\r
           CpuBreakpoint ();\r
         }\r
 \r
-        EbcLLCALLEX (VmPtr, (UINTN) Immed64, (UINTN) VmPtr->R[0], FramePtr, Size);\r
+        EbcLLCALLEX (VmPtr, (UINTN) Immed64, (UINTN) VmPtr->Gpr[0], FramePtr, Size);\r
       }\r
     }\r
   }\r
 \r
+  if ((Operands & OPERAND_M_NATIVE_CALL) != 0) {\r
+    EbcDebuggerHookCALLEXEnd (VmPtr);\r
+  } else {\r
+    EbcDebuggerHookCALLEnd (VmPtr);\r
+  }\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -3158,24 +3109,26 @@ ExecuteCALL (
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteRET (\r
   IN VM_CONTEXT *VmPtr\r
   )\r
 {\r
+\r
+  EbcDebuggerHookRETStart (VmPtr);\r
+\r
   //\r
   // If we're at the top of the stack, then simply set the done\r
   // flag and return\r
   //\r
-  if (VmPtr->StackRetAddr == (UINT64) VmPtr->R[0]) {\r
+  if (VmPtr->StackRetAddr == (UINT64) VmPtr->Gpr[0]) {\r
     VmPtr->StopFlags |= STOPFLAG_APP_DONE;\r
   } else {\r
     //\r
     // Pull the return address off the VM app's stack and set the IP\r
     // to it\r
     //\r
-    if (!IS_ALIGNED ((UINTN) VmPtr->R[0], sizeof (UINT16))) {\r
+    if (!IS_ALIGNED ((UINTN) VmPtr->Gpr[0], sizeof (UINT16))) {\r
       EbcDebugSignalException (\r
         EXCEPT_EBC_ALIGNMENT_CHECK,\r
         EXCEPTION_FLAG_FATAL,\r
@@ -3185,12 +3138,15 @@ ExecuteRET (
     //\r
     // Restore the IP and frame pointer from the stack\r
     //\r
-    VmPtr->Ip = (VMIP) (UINTN) VmReadMem64 (VmPtr, (UINTN) VmPtr->R[0]);\r
-    VmPtr->R[0] += 8;\r
-    VmPtr->FramePtr = (VOID *) VmReadMemN (VmPtr, (UINTN) VmPtr->R[0]);\r
-    VmPtr->R[0] += 8;\r
+    VmPtr->Ip = (VMIP) (UINTN) VmReadMem64 (VmPtr, (UINTN) VmPtr->Gpr[0]);\r
+    VmPtr->Gpr[0] += 8;\r
+    VmPtr->FramePtr = (VOID *) VmReadMemN (VmPtr, (UINTN) VmPtr->Gpr[0]);\r
+    VmPtr->Gpr[0] += 8;\r
   }\r
 \r
+\r
+  EbcDebuggerHookRETEnd (VmPtr);\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -3203,11 +3159,10 @@ ExecuteRET (
 \r
   @param  VmPtr             A pointer to a VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteCMP (\r
   IN VM_CONTEXT *VmPtr\r
@@ -3229,7 +3184,7 @@ ExecuteCMP (
   //\r
   // Get the register data we're going to compare to\r
   //\r
-  Op1 = VmPtr->R[OPERAND1_REGNUM (Operands)];\r
+  Op1 = VmPtr->Gpr[OPERAND1_REGNUM (Operands)];\r
   //\r
   // Get immediate data\r
   //\r
@@ -3250,15 +3205,15 @@ ExecuteCMP (
   //\r
   if (OPERAND2_INDIRECT (Operands)) {\r
     if ((Opcode & OPCODE_M_64BIT) != 0) {\r
-      Op2 = (INT64) VmReadMem64 (VmPtr, (UINTN) (VmPtr->R[OPERAND2_REGNUM (Operands)] + Index16));\r
+      Op2 = (INT64) VmReadMem64 (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND2_REGNUM (Operands)] + Index16));\r
     } else {\r
       //\r
       // 32-bit operations. 0-extend the values for all cases.\r
       //\r
-      Op2 = (INT64) (UINT64) ((UINT32) VmReadMem32 (VmPtr, (UINTN) (VmPtr->R[OPERAND2_REGNUM (Operands)] + Index16)));\r
+      Op2 = (INT64) (UINT64) ((UINT32) VmReadMem32 (VmPtr, (UINTN) (VmPtr->Gpr[OPERAND2_REGNUM (Operands)] + Index16)));\r
     }\r
   } else {\r
-    Op2 = VmPtr->R[OPERAND2_REGNUM (Operands)] + Index16;\r
+    Op2 = VmPtr->Gpr[OPERAND2_REGNUM (Operands)] + Index16;\r
   }\r
   //\r
   // Now do the compare\r
@@ -3347,7 +3302,7 @@ ExecuteCMP (
   if (Flag != 0) {\r
     VMFLAG_SET (VmPtr, VMFLAGS_CC);\r
   } else {\r
-    VMFLAG_CLEAR (VmPtr, VMFLAGS_CC);\r
+    VMFLAG_CLEAR (VmPtr, (UINT64)VMFLAGS_CC);\r
   }\r
   //\r
   // Advance the IP\r
@@ -3365,11 +3320,10 @@ ExecuteCMP (
 \r
   @param  VmPtr             A pointer to a VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteCMPI (\r
   IN VM_CONTEXT *VmPtr\r
@@ -3402,7 +3356,7 @@ ExecuteCMPI (
   //\r
   // Get operand1 data we're going to compare to\r
   //\r
-  Op1 = (INT64) VmPtr->R[OPERAND1_REGNUM (Operands)];\r
+  Op1 = (INT64) VmPtr->Gpr[OPERAND1_REGNUM (Operands)];\r
   if (OPERAND1_INDIRECT (Operands)) {\r
     //\r
     // Indirect operand1. Fetch 32 or 64-bit value based on compare size.\r
@@ -3527,7 +3481,7 @@ ExecuteCMPI (
   if (Flag != 0) {\r
     VMFLAG_SET (VmPtr, VMFLAGS_CC);\r
   } else {\r
-    VMFLAG_CLEAR (VmPtr, VMFLAGS_CC);\r
+    VMFLAG_CLEAR (VmPtr, (UINT64)VMFLAGS_CC);\r
   }\r
   //\r
   // Advance the IP\r
@@ -3550,7 +3504,6 @@ ExecuteCMPI (
   @return ~Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteNOT (\r
   IN VM_CONTEXT     *VmPtr,\r
@@ -3575,7 +3528,6 @@ ExecuteNOT (
   @return Op2 * -1\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteNEG (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -3600,7 +3552,6 @@ ExecuteNEG (
   @return Op1 + Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteADD (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -3625,7 +3576,6 @@ ExecuteADD (
   @return Op1 - Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteSUB (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -3636,7 +3586,7 @@ ExecuteSUB (
   if ((*VmPtr->Ip & DATAMANIP_M_64) != 0) {\r
     return (UINT64) ((INT64) ((INT64) Op1 - (INT64) Op2));\r
   } else {\r
-    return (UINT64) ((INT64) ((INT32) Op1 - (INT32) Op2));\r
+    return (UINT64) ((INT64) ((INT32) ((INT32) Op1 - (INT32) Op2)));\r
   }\r
 }\r
 \r
@@ -3654,7 +3604,6 @@ ExecuteSUB (
   @return Op1 * Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteMUL (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -3665,7 +3614,7 @@ ExecuteMUL (
   if ((*VmPtr->Ip & DATAMANIP_M_64) != 0) {\r
     return MultS64x64 ((INT64)Op1, (INT64)Op2);\r
   } else {\r
-    return (UINT64) ((INT64) ((INT32) Op1 * (INT32) Op2));\r
+    return (UINT64) ((INT64) ((INT32) ((INT32) Op1 * (INT32) Op2)));\r
   }\r
 }\r
 \r
@@ -3683,7 +3632,6 @@ ExecuteMUL (
   @return (unsigned)Op1 * (unsigned)Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteMULU (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -3694,7 +3642,7 @@ ExecuteMULU (
   if ((*VmPtr->Ip & DATAMANIP_M_64) != 0) {\r
     return MultU64x64 (Op1, Op2);\r
   } else {\r
-    return (UINT64) ((UINT32) Op1 * (UINT32) Op2);\r
+    return (UINT64) ((UINT32) ((UINT32) Op1 * (UINT32) Op2));\r
   }\r
 }\r
 \r
@@ -3712,7 +3660,6 @@ ExecuteMULU (
   @return Op1 / Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteDIV (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -3756,7 +3703,6 @@ ExecuteDIV (
   @return (unsigned)Op1 / (unsigned)Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteDIVU (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -3781,7 +3727,7 @@ ExecuteDIVU (
     // Get the destination register\r
     //\r
     if ((*VmPtr->Ip & DATAMANIP_M_64) != 0) {\r
-      return (UINT64) (DivU64x64Remainder ((INT64)Op1, (INT64)Op2, &Remainder));\r
+      return (UINT64) (DivU64x64Remainder (Op1, Op2, &Remainder));\r
     } else {\r
       return (UINT64) ((UINT32) Op1 / (UINT32) Op2);\r
     }\r
@@ -3802,7 +3748,6 @@ ExecuteDIVU (
   @return Op1 MODULUS Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteMOD (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -3842,7 +3787,6 @@ ExecuteMOD (
   @return Op1 UNSIGNED_MODULUS Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteMODU (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -3882,7 +3826,6 @@ ExecuteMODU (
   @return Op1 AND Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteAND (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -3907,7 +3850,6 @@ ExecuteAND (
   @return Op1 OR Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteOR (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -3932,7 +3874,6 @@ ExecuteOR (
   @return Op1 XOR Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteXOR (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -3957,7 +3898,6 @@ ExecuteXOR (
   @return Op1 << Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteSHL (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -3986,7 +3926,6 @@ ExecuteSHL (
   @return Op1 >> Op2  (unsigned operands)\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteSHR (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -4015,7 +3954,6 @@ ExecuteSHR (
   @return Op1 >> Op2 (signed)\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteASHR (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -4044,7 +3982,6 @@ ExecuteASHR (
   @return (INT64)(INT8)Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteEXTNDB (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -4078,7 +4015,6 @@ ExecuteEXTNDB (
   @return (INT64)(INT16)Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteEXTNDW (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -4119,7 +4055,6 @@ ExecuteEXTNDW (
   @return (INT64)(INT32)Op2\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 ExecuteEXTNDD (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -4153,11 +4088,10 @@ ExecuteEXTNDD (
 \r
   @param  VmPtr             A pointer to VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteSignedDataManip (\r
   IN VM_CONTEXT   *VmPtr\r
@@ -4184,11 +4118,10 @@ ExecuteSignedDataManip (
 \r
   @param  VmPtr             A pointer to VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteUnsignedDataManip (\r
   IN VM_CONTEXT   *VmPtr\r
@@ -4216,11 +4149,10 @@ ExecuteUnsignedDataManip (
   @param  VmPtr             A pointer to VM context.\r
   @param  IsSignedOp        Indicates whether the operand is signed or not.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteDataManip (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -4233,6 +4165,7 @@ ExecuteDataManip (
   UINT8   Size;\r
   UINT64  Op1;\r
   UINT64  Op2;\r
+  INTN    DataManipDispatchTableIndex;\r
 \r
   //\r
   // Get opcode and operands\r
@@ -4261,7 +4194,7 @@ ExecuteDataManip (
   //\r
   // Now get operand2 (source). It's of format {@}R2 {Index16|Immed16}\r
   //\r
-  Op2 = (UINT64) VmPtr->R[OPERAND2_REGNUM (Operands)] + Index16;\r
+  Op2 = (UINT64) VmPtr->Gpr[OPERAND2_REGNUM (Operands)] + Index16;\r
   if (OPERAND2_INDIRECT (Operands)) {\r
     //\r
     // Indirect form: @R2 Index16. Fetch as 32- or 64-bit data\r
@@ -4291,7 +4224,7 @@ ExecuteDataManip (
   // Get operand1 (destination and sometimes also an actual operand)\r
   // of form {@}R1\r
   //\r
-  Op1 = VmPtr->R[OPERAND1_REGNUM (Operands)];\r
+  Op1 = (UINT64) VmPtr->Gpr[OPERAND1_REGNUM (Operands)];\r
   if (OPERAND1_INDIRECT (Operands)) {\r
     if ((Opcode & DATAMANIP_M_64) != 0) {\r
       Op1 = VmReadMem64 (VmPtr, (UINTN) Op1);\r
@@ -4314,9 +4247,9 @@ ExecuteDataManip (
   //\r
   // Dispatch to the computation function\r
   //\r
-  if (((Opcode & OPCODE_M_OPCODE) - OPCODE_NOT) >=\r
-        (sizeof (mDataManipDispatchTable) / sizeof (mDataManipDispatchTable[0]))\r
-        ) {\r
+  DataManipDispatchTableIndex = (Opcode & OPCODE_M_OPCODE) - OPCODE_NOT;\r
+  if ((DataManipDispatchTableIndex < 0) ||\r
+      (DataManipDispatchTableIndex >= ARRAY_SIZE (mDataManipDispatchTable))) {\r
     EbcDebugSignalException (\r
       EXCEPT_EBC_INVALID_OPCODE,\r
       EXCEPTION_FLAG_ERROR,\r
@@ -4328,13 +4261,13 @@ ExecuteDataManip (
     VmPtr->Ip += Size;\r
     return EFI_UNSUPPORTED;\r
   } else {\r
-    Op2 = mDataManipDispatchTable[(Opcode & OPCODE_M_OPCODE) - OPCODE_NOT](VmPtr, Op1, Op2);\r
+    Op2 = mDataManipDispatchTable[DataManipDispatchTableIndex](VmPtr, Op1, Op2);\r
   }\r
   //\r
   // Write back the result.\r
   //\r
   if (OPERAND1_INDIRECT (Operands)) {\r
-    Op1 = VmPtr->R[OPERAND1_REGNUM (Operands)];\r
+    Op1 = (UINT64) VmPtr->Gpr[OPERAND1_REGNUM (Operands)];\r
     if ((Opcode & DATAMANIP_M_64) != 0) {\r
       VmWriteMem64 (VmPtr, (UINTN) Op1, Op2);\r
     } else {\r
@@ -4345,9 +4278,9 @@ ExecuteDataManip (
     // Storage back to a register. Write back, clearing upper bits (as per\r
     // the specification) if 32-bit operation.\r
     //\r
-    VmPtr->R[OPERAND1_REGNUM (Operands)] = Op2;\r
+    VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = Op2;\r
     if ((Opcode & DATAMANIP_M_64) == 0) {\r
-      VmPtr->R[OPERAND1_REGNUM (Operands)] &= 0xFFFFFFFF;\r
+      VmPtr->Gpr[OPERAND1_REGNUM (Operands)] &= 0xFFFFFFFF;\r
     }\r
   }\r
   //\r
@@ -4366,11 +4299,10 @@ ExecuteDataManip (
 \r
   @param  VmPtr             A pointer to a VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteLOADSP (\r
   IN VM_CONTEXT *VmPtr\r
@@ -4395,7 +4327,7 @@ ExecuteLOADSP (
     // Spec states that this instruction will not modify reserved bits in\r
     // the flags register.\r
     //\r
-    VmPtr->Flags = (VmPtr->Flags &~VMFLAGS_ALL_VALID) | (VmPtr->R[OPERAND2_REGNUM (Operands)] & VMFLAGS_ALL_VALID);\r
+    VmPtr->Flags = (VmPtr->Flags &~VMFLAGS_ALL_VALID) | (VmPtr->Gpr[OPERAND2_REGNUM (Operands)] & VMFLAGS_ALL_VALID);\r
     break;\r
 \r
   default:\r
@@ -4421,11 +4353,10 @@ ExecuteLOADSP (
 \r
   @param  VmPtr             A pointer to a VM context.\r
 \r
-  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.     \r
+  @retval EFI_UNSUPPORTED   The opcodes/operands is not supported.\r
   @retval EFI_SUCCESS       The instruction is executed successfully.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 ExecuteSTORESP (\r
   IN VM_CONTEXT *VmPtr\r
@@ -4449,14 +4380,14 @@ ExecuteSTORESP (
     //\r
     // Retrieve the value in the flags register, then clear reserved bits\r
     //\r
-    VmPtr->R[OPERAND1_REGNUM (Operands)] = (UINT64) (VmPtr->Flags & VMFLAGS_ALL_VALID);\r
+    VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = (UINT64) (VmPtr->Flags & VMFLAGS_ALL_VALID);\r
     break;\r
 \r
   //\r
   // Get IP -- address of following instruction\r
   //\r
   case 1:\r
-    VmPtr->R[OPERAND1_REGNUM (Operands)] = (UINT64) (UINTN) VmPtr->Ip + 2;\r
+    VmPtr->Gpr[OPERAND1_REGNUM (Operands)] = (UINT64) (UINTN) VmPtr->Ip + 2;\r
     break;\r
 \r
   default:\r
@@ -4482,13 +4413,13 @@ ExecuteSTORESP (
     b14:12  - number of bits in this index assigned to natural units (=a)\r
     ba:11   - constant units = ConstUnits\r
     b0:a    - natural units = NaturalUnits\r
-  \r
+\r
   Given this info, the offset can be computed by:\r
     offset = sign_bit * (ConstUnits + NaturalUnits * sizeof(UINTN))\r
 \r
   Max offset is achieved with index = 0x7FFF giving an offset of\r
   0x27B (32-bit machine) or 0x477 (64-bit machine).\r
-  Min offset is achieved with index = \r
+  Min offset is achieved with index =\r
 \r
   @param  VmPtr             A pointer to VM context.\r
   @param  CodeOffset        Offset from IP of the location of the 16-bit index\r
@@ -4497,7 +4428,6 @@ ExecuteSTORESP (
   @return The decoded offset.\r
 \r
 **/\r
-STATIC\r
 INT16\r
 VmReadIndex16 (\r
   IN VM_CONTEXT     *VmPtr,\r
@@ -4569,7 +4499,6 @@ VmReadIndex16 (
   @return Converted index per EBC VM specification.\r
 \r
 **/\r
-STATIC\r
 INT32\r
 VmReadIndex32 (\r
   IN VM_CONTEXT     *VmPtr,\r
@@ -4633,7 +4562,6 @@ VmReadIndex32 (
   @return Converted index per EBC VM specification\r
 \r
 **/\r
-STATIC\r
 INT64\r
 VmReadIndex64 (\r
   IN VM_CONTEXT     *VmPtr,\r
@@ -4674,7 +4602,7 @@ VmReadIndex64 (
   //\r
   ConstUnits = ARShiftU64 (((Index &~0xF000000000000000ULL) & Mask), (UINTN)NBits);\r
 \r
-  Offset  = MultU64x64 (NaturalUnits, sizeof (UINTN)) + ConstUnits;\r
+  Offset  = MultU64x64 ((UINT64) NaturalUnits, sizeof (UINTN)) + ConstUnits;\r
 \r
   //\r
   // Now set the sign\r
@@ -4689,7 +4617,7 @@ VmReadIndex64 (
 \r
 /**\r
   Writes 8-bit data to memory address.\r
-   \r
+\r
   This routine is called by the EBC data\r
   movement instructions that write to memory. Since these writes\r
   may be to the stack, which looks like (high address on top) this,\r
@@ -4699,18 +4627,17 @@ VmReadIndex64 (
   [EBC stack]\r
 \r
   we need to detect all attempts to write to the EBC entry point argument\r
-  stack area and adjust the address (which will initially point into the \r
+  stack area and adjust the address (which will initially point into the\r
   VM stack) to point into the EBC entry point arguments.\r
 \r
   @param  VmPtr             A pointer to a VM context.\r
-  @param  Addr              Adddress to write to.\r
+  @param  Addr              Address to write to.\r
   @param  Data              Value to write to Addr.\r
 \r
-  @retval EFI_SUCCESS       The instruction is executed successfully.  \r
+  @retval EFI_SUCCESS       The instruction is executed successfully.\r
   @retval Other             Some error occurs when writing data to the address.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 VmWriteMem8 (\r
   IN VM_CONTEXT    *VmPtr,\r
@@ -4728,7 +4655,7 @@ VmWriteMem8 (
 \r
 /**\r
   Writes 16-bit data to memory address.\r
-   \r
+\r
   This routine is called by the EBC data\r
   movement instructions that write to memory. Since these writes\r
   may be to the stack, which looks like (high address on top) this,\r
@@ -4738,18 +4665,17 @@ VmWriteMem8 (
   [EBC stack]\r
 \r
   we need to detect all attempts to write to the EBC entry point argument\r
-  stack area and adjust the address (which will initially point into the \r
+  stack area and adjust the address (which will initially point into the\r
   VM stack) to point into the EBC entry point arguments.\r
 \r
   @param  VmPtr             A pointer to a VM context.\r
-  @param  Addr              Adddress to write to.\r
+  @param  Addr              Address to write to.\r
   @param  Data              Value to write to Addr.\r
 \r
-  @retval EFI_SUCCESS       The instruction is executed successfully.  \r
+  @retval EFI_SUCCESS       The instruction is executed successfully.\r
   @retval Other             Some error occurs when writing data to the address.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 VmWriteMem16 (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -4792,7 +4718,7 @@ VmWriteMem16 (
 \r
 /**\r
   Writes 32-bit data to memory address.\r
-   \r
+\r
   This routine is called by the EBC data\r
   movement instructions that write to memory. Since these writes\r
   may be to the stack, which looks like (high address on top) this,\r
@@ -4802,18 +4728,17 @@ VmWriteMem16 (
   [EBC stack]\r
 \r
   we need to detect all attempts to write to the EBC entry point argument\r
-  stack area and adjust the address (which will initially point into the \r
+  stack area and adjust the address (which will initially point into the\r
   VM stack) to point into the EBC entry point arguments.\r
 \r
   @param  VmPtr             A pointer to a VM context.\r
-  @param  Addr              Adddress to write to.\r
+  @param  Addr              Address to write to.\r
   @param  Data              Value to write to Addr.\r
 \r
-  @retval EFI_SUCCESS       The instruction is executed successfully.  \r
+  @retval EFI_SUCCESS       The instruction is executed successfully.\r
   @retval Other             Some error occurs when writing data to the address.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 VmWriteMem32 (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -4856,7 +4781,7 @@ VmWriteMem32 (
 \r
 /**\r
   Writes 64-bit data to memory address.\r
-   \r
+\r
   This routine is called by the EBC data\r
   movement instructions that write to memory. Since these writes\r
   may be to the stack, which looks like (high address on top) this,\r
@@ -4866,14 +4791,14 @@ VmWriteMem32 (
   [EBC stack]\r
 \r
   we need to detect all attempts to write to the EBC entry point argument\r
-  stack area and adjust the address (which will initially point into the \r
+  stack area and adjust the address (which will initially point into the\r
   VM stack) to point into the EBC entry point arguments.\r
 \r
   @param  VmPtr             A pointer to a VM context.\r
-  @param  Addr              Adddress to write to.\r
+  @param  Addr              Address to write to.\r
   @param  Data              Value to write to Addr.\r
 \r
-  @retval EFI_SUCCESS       The instruction is executed successfully.  \r
+  @retval EFI_SUCCESS       The instruction is executed successfully.\r
   @retval Other             Some error occurs when writing data to the address.\r
 \r
 **/\r
@@ -4885,7 +4810,6 @@ VmWriteMem64 (
   )\r
 {\r
   EFI_STATUS  Status;\r
-  UINT32      Data32;\r
 \r
   //\r
   // Convert the address if it's in the stack gap\r
@@ -4907,8 +4831,7 @@ VmWriteMem64 (
     }\r
 \r
     MemoryFence ();\r
-    Data32 = (UINT32) (((UINT32 *) &Data)[1]);\r
-    if ((Status = VmWriteMem32 (VmPtr, Addr + sizeof (UINT32), Data32)) != EFI_SUCCESS) {\r
+    if ((Status = VmWriteMem32 (VmPtr, Addr + sizeof (UINT32), (UINT32) RShiftU64(Data, 32))) != EFI_SUCCESS) {\r
       return Status;\r
     }\r
 \r
@@ -4921,7 +4844,7 @@ VmWriteMem64 (
 \r
 /**\r
   Writes UINTN data to memory address.\r
-   \r
+\r
   This routine is called by the EBC data\r
   movement instructions that write to memory. Since these writes\r
   may be to the stack, which looks like (high address on top) this,\r
@@ -4931,14 +4854,14 @@ VmWriteMem64 (
   [EBC stack]\r
 \r
   we need to detect all attempts to write to the EBC entry point argument\r
-  stack area and adjust the address (which will initially point into the \r
+  stack area and adjust the address (which will initially point into the\r
   VM stack) to point into the EBC entry point arguments.\r
 \r
   @param  VmPtr             A pointer to a VM context.\r
-  @param  Addr              Adddress to write to.\r
+  @param  Addr              Address to write to.\r
   @param  Data              Value to write to Addr.\r
 \r
-  @retval EFI_SUCCESS       The instruction is executed successfully.  \r
+  @retval EFI_SUCCESS       The instruction is executed successfully.\r
   @retval Other             Some error occurs when writing data to the address.\r
 \r
 **/\r
@@ -4969,7 +4892,7 @@ VmWriteMemN (
       MemoryFence ();\r
       Status = VmWriteMem32 (VmPtr, Addr + Index * sizeof (UINT32), (UINT32) Data);\r
       MemoryFence ();\r
-      Data = (UINTN)RShiftU64 ((UINT64)Data, 32);\r
+      Data = (UINTN) RShiftU64 ((UINT64)Data, 32);\r
     }\r
   }\r
 \r
@@ -4991,7 +4914,6 @@ VmWriteMemN (
   @return Signed data of the requested size from the specified address.\r
 \r
 **/\r
-STATIC\r
 INT8\r
 VmReadImmed8 (\r
   IN VM_CONTEXT *VmPtr,\r
@@ -5018,7 +4940,6 @@ VmReadImmed8 (
   @return Signed data of the requested size from the specified address.\r
 \r
 **/\r
-STATIC\r
 INT16\r
 VmReadImmed16 (\r
   IN VM_CONTEXT *VmPtr,\r
@@ -5061,7 +4982,6 @@ VmReadImmed16 (
   @return Signed data of the requested size from the specified address.\r
 \r
 **/\r
-STATIC\r
 INT32\r
 VmReadImmed32 (\r
   IN VM_CONTEXT *VmPtr,\r
@@ -5079,8 +4999,8 @@ VmReadImmed32 (
   //\r
   // Return unaligned data\r
   //\r
-  Data = (UINT32) VmReadCode16 (VmPtr, Offset);\r
-  Data |= (UINT32) (VmReadCode16 (VmPtr, Offset + 2) << 16);\r
+  Data  = (UINT32) VmReadCode16 (VmPtr, Offset);\r
+  Data |= (UINT32)(VmReadCode16 (VmPtr, Offset + 2) << 16);\r
   return Data;\r
 }\r
 \r
@@ -5099,7 +5019,6 @@ VmReadImmed32 (
   @return Signed data of the requested size from the specified address.\r
 \r
 **/\r
-STATIC\r
 INT64\r
 VmReadImmed64 (\r
   IN VM_CONTEXT *VmPtr,\r
@@ -5122,7 +5041,7 @@ VmReadImmed64 (
   Ptr             = (UINT8 *) &Data64;\r
   Data32          = VmReadCode32 (VmPtr, Offset);\r
   *(UINT32 *) Ptr = Data32;\r
-  Ptr += sizeof (Data32);\r
+  Ptr            += sizeof (Data32);\r
   Data32          = VmReadCode32 (VmPtr, Offset + sizeof (UINT32));\r
   *(UINT32 *) Ptr = Data32;\r
   return Data64;\r
@@ -5130,7 +5049,7 @@ VmReadImmed64 (
 \r
 \r
 /**\r
-  Reads 16-bit unsinged data from the code stream.\r
+  Reads 16-bit unsigned data from the code stream.\r
 \r
   This routine provides the ability to read raw unsigned data from the code\r
   stream.\r
@@ -5141,7 +5060,6 @@ VmReadImmed64 (
   @return The raw unsigned 16-bit value from the code stream.\r
 \r
 **/\r
-STATIC\r
 UINT16\r
 VmReadCode16 (\r
   IN VM_CONTEXT *VmPtr,\r
@@ -5171,7 +5089,7 @@ VmReadCode16 (
 \r
 \r
 /**\r
-  Reads 32-bit unsinged data from the code stream.\r
+  Reads 32-bit unsigned data from the code stream.\r
 \r
   This routine provides the ability to read raw unsigned data from the code\r
   stream.\r
@@ -5182,7 +5100,6 @@ VmReadCode16 (
   @return The raw unsigned 32-bit value from the code stream.\r
 \r
 **/\r
-STATIC\r
 UINT32\r
 VmReadCode32 (\r
   IN VM_CONTEXT *VmPtr,\r
@@ -5206,7 +5123,7 @@ VmReadCode32 (
 \r
 \r
 /**\r
-  Reads 64-bit unsinged data from the code stream.\r
+  Reads 64-bit unsigned data from the code stream.\r
 \r
   This routine provides the ability to read raw unsigned data from the code\r
   stream.\r
@@ -5217,7 +5134,6 @@ VmReadCode32 (
   @return The raw unsigned 64-bit value from the code stream.\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 VmReadCode64 (\r
   IN VM_CONTEXT *VmPtr,\r
@@ -5240,7 +5156,7 @@ VmReadCode64 (
   Ptr             = (UINT8 *) &Data64;\r
   Data32          = VmReadCode32 (VmPtr, Offset);\r
   *(UINT32 *) Ptr = Data32;\r
-  Ptr += sizeof (Data32);\r
+  Ptr            += sizeof (Data32);\r
   Data32          = VmReadCode32 (VmPtr, Offset + sizeof (UINT32));\r
   *(UINT32 *) Ptr = Data32;\r
   return Data64;\r
@@ -5253,10 +5169,9 @@ VmReadCode64 (
   @param  VmPtr             A pointer to VM context.\r
   @param  Addr              The memory address.\r
 \r
-  @return The 8-bit value from the memory adress.\r
+  @return The 8-bit value from the memory address.\r
 \r
 **/\r
-STATIC\r
 UINT8\r
 VmReadMem8 (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -5279,10 +5194,9 @@ VmReadMem8 (
   @param  VmPtr             A pointer to VM context.\r
   @param  Addr              The memory address.\r
 \r
-  @return The 16-bit value from the memory adress.\r
+  @return The 16-bit value from the memory address.\r
 \r
 **/\r
-STATIC\r
 UINT16\r
 VmReadMem16 (\r
   IN VM_CONTEXT *VmPtr,\r
@@ -5311,10 +5225,9 @@ VmReadMem16 (
   @param  VmPtr             A pointer to VM context.\r
   @param  Addr              The memory address.\r
 \r
-  @return The 32-bit value from the memory adress.\r
+  @return The 32-bit value from the memory address.\r
 \r
 **/\r
-STATIC\r
 UINT32\r
 VmReadMem32 (\r
   IN VM_CONTEXT *VmPtr,\r
@@ -5347,10 +5260,9 @@ VmReadMem32 (
   @param  VmPtr             A pointer to VM context.\r
   @param  Addr              The memory address.\r
 \r
-  @return The 64-bit value from the memory adress.\r
+  @return The 64-bit value from the memory address.\r
 \r
 **/\r
-STATIC\r
 UINT64\r
 VmReadMem64 (\r
   IN VM_CONTEXT   *VmPtr,\r
@@ -5374,9 +5286,9 @@ VmReadMem64 (
   //\r
   // Return unaligned data. Assume little endian.\r
   //\r
-  Data    = (UINT64) VmReadMem32 (VmPtr, Addr);\r
-  Data32  = VmReadMem32 (VmPtr, Addr + sizeof (UINT32));\r
-  *(UINT32 *) ((UINT32 *) &Data + 1) = Data32;\r
+  Data32 = VmReadMem32 (VmPtr, Addr);\r
+  Data  = (UINT64) VmReadMem32 (VmPtr, Addr + sizeof (UINT32));\r
+  Data  = LShiftU64 (Data, 32) | Data32;\r
   return Data;\r
 }\r
 \r
@@ -5400,7 +5312,6 @@ VmReadMem64 (
           adjust for the stack gap and return the modified address.\r
 \r
 **/\r
-STATIC\r
 UINTN\r
 ConvertStackAddr (\r
   IN VM_CONTEXT    *VmPtr,\r
@@ -5421,7 +5332,6 @@ ConvertStackAddr (
   @return The natural value at address Addr.\r
 \r
 **/\r
-STATIC\r
 UINTN\r
 VmReadMemN (\r
   IN VM_CONTEXT    *VmPtr,\r
@@ -5460,7 +5370,7 @@ VmReadMemN (
 \r
 /**\r
   Returns the version of the EBC virtual machine.\r
-    \r
+\r
   @return The 64-bit version of EBC virtual machine.\r
 \r
 **/\r