public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 1/5] MdeModulePkg/EbcDxe: allow VmReadIndex##() to return a decoded index
@ 2017-01-24 12:30 Pete Batard
  2017-01-24 12:30 ` [PATCH 2/5] MdeModulePkg/EbcDxe: add ARM support Pete Batard
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Pete Batard @ 2017-01-24 12:30 UTC (permalink / raw)
  To: edk2-devel

* The VmReadIndex## function now take an optional pointer to an index
  pair structure which, when not NULL, is filled with the decoded const
  and natural values.
* This feature is needed by the ARM EBC VM.
* For now, the new parameters is set to NULL, so as not to change
  existing behaviour with current EBC VM platforms.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Pete Batard <pete@akeo.ie>
---
 MdeModulePkg/Universal/EbcDxe/EbcExecute.c | 116 +++++++++++++++++++++--------
 MdeModulePkg/Universal/EbcDxe/EbcExecute.h |   8 ++
 2 files changed, 93 insertions(+), 31 deletions(-)

diff --git a/MdeModulePkg/Universal/EbcDxe/EbcExecute.c b/MdeModulePkg/Universal/EbcDxe/EbcExecute.c
index e5d290a2fec6..2d21c3364e0d 100644
--- a/MdeModulePkg/Universal/EbcDxe/EbcExecute.c
+++ b/MdeModulePkg/Universal/EbcDxe/EbcExecute.c
@@ -61,6 +61,8 @@ UINT64
   @param  VmPtr             A pointer to VM context.
   @param  CodeOffset        Offset from IP of the location of the 16-bit index
                             to decode.
+  @param  IndexPtr          An optional pointer where the decoded index pair
+                            values can be written.
 
   @return The decoded offset.
 
@@ -68,7 +70,8 @@ UINT64
 INT16
 VmReadIndex16 (
   IN VM_CONTEXT     *VmPtr,
-  IN UINT32         CodeOffset
+  IN UINT32         CodeOffset,
+  OUT EBC_INDEX     *IndexPtr OPTIONAL
   );
 
 /**
@@ -77,6 +80,8 @@ VmReadIndex16 (
   @param  VmPtr             A pointer to VM context.
   @param  CodeOffset        Offset from IP of the location of the 32-bit index
                             to decode.
+  @param  IndexPtr          An optional pointer where the decoded index pair
+                            values can be written.
 
   @return Converted index per EBC VM specification.
 
@@ -84,7 +89,8 @@ VmReadIndex16 (
 INT32
 VmReadIndex32 (
   IN VM_CONTEXT     *VmPtr,
-  IN UINT32         CodeOffset
+  IN UINT32         CodeOffset,
+  OUT EBC_INDEX     *IndexPtr OPTIONAL
   );
 
 /**
@@ -93,6 +99,8 @@ VmReadIndex32 (
   @param  VmPtr             A pointer to VM context.s
   @param  CodeOffset        Offset from IP of the location of the 64-bit index
                             to decode.
+  @param  IndexPtr          An optional pointer where the decoded index pair
+                            values can be written.
 
   @return Converted index per EBC VM specification
 
@@ -100,7 +108,8 @@ VmReadIndex32 (
 INT64
 VmReadIndex64 (
   IN VM_CONTEXT     *VmPtr,
-  IN UINT32         CodeOffset
+  IN UINT32         CodeOffset,
+  OUT EBC_INDEX     *IndexPtr OPTIONAL
   );
 
 /**
@@ -1600,13 +1609,13 @@ ExecuteMOVxx (
       // Get one or both index values.
       //
       if ((Opcode & OPCODE_M_IMMED_OP1) != 0) {
-        Index16     = VmReadIndex16 (VmPtr, 2);
+        Index16     = VmReadIndex16 (VmPtr, 2, NULL);
         Index64Op1  = (INT64) Index16;
         Size += sizeof (UINT16);
       }
 
       if ((Opcode & OPCODE_M_IMMED_OP2) != 0) {
-        Index16     = VmReadIndex16 (VmPtr, Size);
+        Index16     = VmReadIndex16 (VmPtr, Size, NULL);
         Index64Op2  = (INT64) Index16;
         Size += sizeof (UINT16);
       }
@@ -1615,13 +1624,13 @@ ExecuteMOVxx (
       // MOVBD, MOVWD, MOVDD, MOVQD, and MOVND have 32-bit immediate index
       //
       if ((Opcode & OPCODE_M_IMMED_OP1) != 0) {
-        Index32     = VmReadIndex32 (VmPtr, 2);
+        Index32     = VmReadIndex32 (VmPtr, 2, NULL);
         Index64Op1  = (INT64) Index32;
         Size += sizeof (UINT32);
       }
 
       if ((Opcode & OPCODE_M_IMMED_OP2) != 0) {
-        Index32     = VmReadIndex32 (VmPtr, Size);
+        Index32     = VmReadIndex32 (VmPtr, Size, NULL);
         Index64Op2  = (INT64) Index32;
         Size += sizeof (UINT32);
       }
@@ -1630,12 +1639,12 @@ ExecuteMOVxx (
       // MOVqq -- only form with a 64-bit index
       //
       if ((Opcode & OPCODE_M_IMMED_OP1) != 0) {
-        Index64Op1 = VmReadIndex64 (VmPtr, 2);
+        Index64Op1 = VmReadIndex64 (VmPtr, 2, NULL);
         Size += sizeof (UINT64);
       }
 
       if ((Opcode & OPCODE_M_IMMED_OP2) != 0) {
-        Index64Op2 = VmReadIndex64 (VmPtr, Size);
+        Index64Op2 = VmReadIndex64 (VmPtr, Size, NULL);
         Size += sizeof (UINT64);
       }
     } else {
@@ -2042,7 +2051,7 @@ ExecuteJMP (
   //
   if ((Opcode & OPCODE_M_IMMDATA) != 0) {
     if (OPERAND1_INDIRECT (Operand)) {
-      Index32 = VmReadIndex32 (VmPtr, 2);
+      Index32 = VmReadIndex32 (VmPtr, 2, NULL);
     } else {
       Index32 = VmReadImmed32 (VmPtr, 2);
     }
@@ -2210,7 +2219,7 @@ ExecuteMOVI (
   // Get the index (16-bit) if present
   //
   if ((Operands & MOVI_M_IMMDATA) != 0) {
-    Index16 = VmReadIndex16 (VmPtr, 2);
+    Index16 = VmReadIndex16 (VmPtr, 2, NULL);
     Size    = 4;
   } else {
     Index16 = 0;
@@ -2329,7 +2338,7 @@ ExecuteMOVIn (
   // Get the operand1 index (16-bit) if present
   //
   if ((Operands & MOVI_M_IMMDATA) != 0) {
-    Index16 = VmReadIndex16 (VmPtr, 2);
+    Index16 = VmReadIndex16 (VmPtr, 2, NULL);
     Size    = 4;
   } else {
     Index16 = 0;
@@ -2339,15 +2348,15 @@ ExecuteMOVIn (
   // Extract the immediate data and convert to a 64-bit index.
   //
   if ((Opcode & MOVI_M_DATAWIDTH) == MOVI_DATAWIDTH16) {
-    ImmedIndex16  = VmReadIndex16 (VmPtr, Size);
+    ImmedIndex16  = VmReadIndex16 (VmPtr, Size, NULL);
     ImmedIndex64  = (INT64) ImmedIndex16;
     Size += 2;
   } else if ((Opcode & MOVI_M_DATAWIDTH) == MOVI_DATAWIDTH32) {
-    ImmedIndex32  = VmReadIndex32 (VmPtr, Size);
+    ImmedIndex32  = VmReadIndex32 (VmPtr, Size, NULL);
     ImmedIndex64  = (INT64) ImmedIndex32;
     Size += 4;
   } else if ((Opcode & MOVI_M_DATAWIDTH) == MOVI_DATAWIDTH64) {
-    ImmedIndex64 = VmReadIndex64 (VmPtr, Size);
+    ImmedIndex64 = VmReadIndex64 (VmPtr, Size, NULL);
     Size += 8;
   } else {
     //
@@ -2430,7 +2439,7 @@ ExecuteMOVREL (
   // Get the Operand 1 index (16-bit) if present
   //
   if ((Operands & MOVI_M_IMMDATA) != 0) {
-    Index16 = VmReadIndex16 (VmPtr, 2);
+    Index16 = VmReadIndex16 (VmPtr, 2, NULL);
     Size    = 4;
   } else {
     Index16 = 0;
@@ -2539,7 +2548,7 @@ ExecuteMOVsnw (
   Size = 2;
   if ((Opcode & OPCODE_M_IMMED_OP1) !=0) {
     if (OPERAND1_INDIRECT (Operands)) {
-      Op1Index = VmReadIndex16 (VmPtr, 2);
+      Op1Index = VmReadIndex16 (VmPtr, 2, NULL);
     } else {
       //
       // Illegal form operand1 direct with index:  MOVsnw R1 Index16, {@}R2
@@ -2557,7 +2566,7 @@ ExecuteMOVsnw (
 
   if ((Opcode & OPCODE_M_IMMED_OP2) != 0) {
     if (OPERAND2_INDIRECT (Operands)) {
-      Op2Index = VmReadIndex16 (VmPtr, Size);
+      Op2Index = VmReadIndex16 (VmPtr, Size, NULL);
     } else {
       Op2Index = VmReadImmed16 (VmPtr, Size);
     }
@@ -2632,7 +2641,7 @@ ExecuteMOVsnd (
   Size = 2;
   if ((Opcode & OPCODE_M_IMMED_OP1) != 0) {
     if (OPERAND1_INDIRECT (Operands)) {
-      Op1Index = VmReadIndex32 (VmPtr, 2);
+      Op1Index = VmReadIndex32 (VmPtr, 2, NULL);
     } else {
       //
       // Illegal form operand1 direct with index:  MOVsnd R1 Index16,..
@@ -2650,7 +2659,7 @@ ExecuteMOVsnd (
 
   if ((Opcode & OPCODE_M_IMMED_OP2) != 0) {
     if (OPERAND2_INDIRECT (Operands)) {
-      Op2Index = VmReadIndex32 (VmPtr, Size);
+      Op2Index = VmReadIndex32 (VmPtr, Size, NULL);
     } else {
       Op2Index = VmReadImmed32 (VmPtr, Size);
     }
@@ -2712,7 +2721,7 @@ ExecutePUSHn (
   //
   if ((Opcode & PUSHPOP_M_IMMDATA) != 0) {
     if (OPERAND1_INDIRECT (Operands)) {
-      Index16 = VmReadIndex16 (VmPtr, 2);
+      Index16 = VmReadIndex16 (VmPtr, 2, NULL);
     } else {
       Index16 = VmReadImmed16 (VmPtr, 2);
     }
@@ -2771,7 +2780,7 @@ ExecutePUSH (
   //
   if ((Opcode & PUSHPOP_M_IMMDATA) != 0) {
     if (OPERAND1_INDIRECT (Operands)) {
-      Index16 = VmReadIndex16 (VmPtr, 2);
+      Index16 = VmReadIndex16 (VmPtr, 2, NULL);
     } else {
       Index16 = VmReadImmed16 (VmPtr, 2);
     }
@@ -2846,7 +2855,7 @@ ExecutePOPn (
   //
   if ((Opcode & PUSHPOP_M_IMMDATA) != 0) {
     if (OPERAND1_INDIRECT (Operands)) {
-      Index16 = VmReadIndex16 (VmPtr, 2);
+      Index16 = VmReadIndex16 (VmPtr, 2, NULL);
     } else {
       Index16 = VmReadImmed16 (VmPtr, 2);
     }
@@ -2906,7 +2915,7 @@ ExecutePOP (
   //
   if ((Opcode & PUSHPOP_M_IMMDATA) != 0) {
     if (OPERAND1_INDIRECT (Operands)) {
-      Index16 = VmReadIndex16 (VmPtr, 2);
+      Index16 = VmReadIndex16 (VmPtr, 2, NULL);
     } else {
       Index16 = VmReadImmed16 (VmPtr, 2);
     }
@@ -3012,7 +3021,7 @@ ExecuteCALL (
       // If register operand is indirect, then the immediate data is an index
       //
       if (OPERAND1_INDIRECT (Operands)) {
-        Immed32 = VmReadIndex32 (VmPtr, 2);
+        Immed32 = VmReadIndex32 (VmPtr, 2, NULL);
       } else {
         Immed32 = VmReadImmed32 (VmPtr, 2);
       }
@@ -3196,7 +3205,7 @@ ExecuteCMP (
   //
   if ((Opcode & OPCODE_M_IMMDATA) != 0) {
     if (OPERAND2_INDIRECT (Operands)) {
-      Index16 = VmReadIndex16 (VmPtr, 2);
+      Index16 = VmReadIndex16 (VmPtr, 2, NULL);
     } else {
       Index16 = VmReadImmed16 (VmPtr, 2);
     }
@@ -3354,7 +3363,7 @@ ExecuteCMPI (
   //
   Size = 2;
   if ((Operands & OPERAND_M_CMPI_INDEX) != 0) {
-    Index16 = VmReadIndex16 (VmPtr, 2);
+    Index16 = VmReadIndex16 (VmPtr, 2, NULL);
     Size += 2;
   } else {
     Index16 = 0;
@@ -4187,7 +4196,7 @@ ExecuteDataManip (
     // Index16 if Ry is indirect, or Immed16 if Ry direct.
     //
     if (OPERAND2_INDIRECT (Operands)) {
-      Index16 = VmReadIndex16 (VmPtr, 2);
+      Index16 = VmReadIndex16 (VmPtr, 2, NULL);
     } else {
       Index16 = VmReadImmed16 (VmPtr, 2);
     }
@@ -4430,6 +4439,8 @@ ExecuteSTORESP (
   @param  VmPtr             A pointer to VM context.
   @param  CodeOffset        Offset from IP of the location of the 16-bit index
                             to decode.
+  @param  IndexPtr          An optional pointer where the decoded index pair
+                            values can be written.
 
   @return The decoded offset.
 
@@ -4437,7 +4448,8 @@ ExecuteSTORESP (
 INT16
 VmReadIndex16 (
   IN VM_CONTEXT     *VmPtr,
-  IN UINT32         CodeOffset
+  IN UINT32         CodeOffset,
+  OUT EBC_INDEX     *IndexPtr OPTIONAL
   )
 {
   UINT16  Index;
@@ -4491,6 +4503,18 @@ VmReadIndex16 (
     Offset = (INT16) ((INT32) Offset * -1);
   }
 
+  //
+  // Copy the decoded index values if requested
+  //
+  if (IndexPtr != NULL) {
+    IndexPtr->NaturalUnits = (INT64) NaturalUnits;
+    IndexPtr->ConstUnits = (INT64) ConstUnits;
+    if ((Index & 0x8000) != 0) {
+      IndexPtr->NaturalUnits = MultS64x64 (IndexPtr->NaturalUnits, -1);
+      IndexPtr->ConstUnits   = MultS64x64 (IndexPtr->ConstUnits, -1);
+    }
+  }
+
   return Offset;
 }
 
@@ -4501,6 +4525,8 @@ VmReadIndex16 (
   @param  VmPtr             A pointer to VM context.
   @param  CodeOffset        Offset from IP of the location of the 32-bit index
                             to decode.
+  @param  IndexPtr          An optional pointer where the decoded index pair
+                            values can be written.
 
   @return Converted index per EBC VM specification.
 
@@ -4508,7 +4534,8 @@ VmReadIndex16 (
 INT32
 VmReadIndex32 (
   IN VM_CONTEXT     *VmPtr,
-  IN UINT32         CodeOffset
+  IN UINT32         CodeOffset,
+  OUT EBC_INDEX     *IndexPtr OPTIONAL
   )
 {
   UINT32  Index;
@@ -4554,6 +4581,18 @@ VmReadIndex32 (
     Offset = Offset * -1;
   }
 
+  //
+  // Copy the decoded index values if requested
+  //
+  if (IndexPtr != NULL) {
+    IndexPtr->NaturalUnits = (INT64) NaturalUnits;
+    IndexPtr->ConstUnits = (INT64) ConstUnits;
+    if ((Index & 0x80000000) != 0) {
+      IndexPtr->NaturalUnits = MultS64x64 (IndexPtr->NaturalUnits, -1);
+      IndexPtr->ConstUnits   = MultS64x64 (IndexPtr->ConstUnits, -1);
+    }
+  }
+
   return Offset;
 }
 
@@ -4564,6 +4603,8 @@ VmReadIndex32 (
   @param  VmPtr             A pointer to VM context.s
   @param  CodeOffset        Offset from IP of the location of the 64-bit index
                             to decode.
+  @param  IndexPtr          An optional pointer where the decoded index pair
+                            values can be written.
 
   @return Converted index per EBC VM specification
 
@@ -4571,7 +4612,8 @@ VmReadIndex32 (
 INT64
 VmReadIndex64 (
   IN VM_CONTEXT     *VmPtr,
-  IN UINT32         CodeOffset
+  IN UINT32         CodeOffset,
+  OUT EBC_INDEX     *IndexPtr OPTIONAL
   )
 {
   UINT64  Index;
@@ -4617,6 +4659,18 @@ VmReadIndex64 (
     Offset = MultS64x64 (Offset, -1);
   }
 
+  //
+  // Copy the decoded index values if requested
+  //
+  if (IndexPtr != NULL) {
+    IndexPtr->NaturalUnits = (INT64) NaturalUnits;
+    IndexPtr->ConstUnits = (INT64) ConstUnits;
+    if ((Index & 0x8000000000000000ULL) != 0) {
+      IndexPtr->NaturalUnits = MultS64x64 (IndexPtr->NaturalUnits, -1);
+      IndexPtr->ConstUnits   = MultS64x64 (IndexPtr->ConstUnits, -1);
+    }
+  }
+
   return Offset;
 }
 
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcExecute.h b/MdeModulePkg/Universal/EbcDxe/EbcExecute.h
index b7489514b919..301c52666366 100644
--- a/MdeModulePkg/Universal/EbcDxe/EbcExecute.h
+++ b/MdeModulePkg/Universal/EbcDxe/EbcExecute.h
@@ -24,6 +24,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define IS_ALIGNED(addr, size)      !((UINT32) (addr) & (size - 1))
 
 //
+// EBC index pair
+//
+typedef struct {
+  UINT64 NaturalUnits;
+  UINT64 ConstUnits;
+} EBC_INDEX;
+
+//
 // Debug macro
 //
 #define EBCMSG(s) gST->ConOut->OutputString (gST->ConOut, s)
-- 
2.9.3.windows.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-01-24 12:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-24 12:30 [PATCH 1/5] MdeModulePkg/EbcDxe: allow VmReadIndex##() to return a decoded index Pete Batard
2017-01-24 12:30 ` [PATCH 2/5] MdeModulePkg/EbcDxe: add ARM support Pete Batard
2017-01-24 12:30 ` [PATCH 3/5] MdeModulePkg/EbcDxe: add a stack tracker for ARM EBC->native support Pete Batard
2017-01-24 12:30 ` [PATCH 4/5] MdeModulePkg/EbcDxe: add call signatures for ARM native->EBC support Pete Batard
2017-01-24 12:30 ` [PATCH 5/5] BaseTools: add scripts to generate EBC call signatures Pete Batard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox