From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id EF28E81EE6 for ; Tue, 24 Jan 2017 04:30:42 -0800 (PST) Received: by mail-wm0-x243.google.com with SMTP id d140so34440139wmd.2 for ; Tue, 24 Jan 2017 04:30:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akeo-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=z8sdgiHKX9lxcZcesiof5j2K5xacPW/CjMFnXMZWSKA=; b=fL94n+mq6aHIhlUI0t624tdyOGo8nUqa3KOJl2rgzgVYJKR/vvnFqpyHxxVVrPM1dM 188JTJX1PyHeda5sNICLWHStmqJBSa4C0kjwiBrTwsnIAFpDoqe0ILQg+BlQ8DKpliwL gJE5SDw1H0h6oJ7RnmirNd+3+GAp1YDVfuP7JCfCa1drgacmSJgNKh3qPcHPY8Z2vXAv +0BR3KG1m5+QG1uIQKQeDhjIlgHQ65uJ7T28798bsq+S1N8MuFs5SHfQw8fZBBX7UPnI wgOxRe9WGfI7npbT3LI3Gq5wvZhRYfOOFKupqGZGezK/ABgZJv1O7ZKJ9Le8lF8DljBN kxhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=z8sdgiHKX9lxcZcesiof5j2K5xacPW/CjMFnXMZWSKA=; b=QZkstSGuTaqtKUsefrYwKRCgEVQ7KKbhyTuUI6/dOqzaA0eLdx/PSNnLLgggaYxc+C k8XNh7R8lAh0IzrR+cGqO1cJzyHqp4DmiCUX7brp1/a8DLL3ioBBj8EK+pEzc7vG34vU CejbHhgQKXFNhsgvCSyNMLLRN6el4C+7AuQxCPWbDJg9IJO+xNcPz9fI7ZLeEKnsGtpr HM2x2KGEUKMZxwgRMWZfJcxNTKx1Y1mhTctyNRVMZ3rPoNlQyQrb1ty6LoGM+dNW4ZTq +tjV0XqgK62yYJ4YvJOe7OHtjdwu0fUHvdtcQKSkLj7hD2nbvDCMbZ3EwX55WwgBO103 iDsw== X-Gm-Message-State: AIkVDXK8Ft/BSIL3iWr2ELIGKgxRFeo302GC4KaErEOg6+v2s5dT0TPnkFvcQQa4z2sruw== X-Received: by 10.223.134.151 with SMTP id 23mr34301885wrx.0.1485261041102; Tue, 24 Jan 2017 04:30:41 -0800 (PST) Received: from localhost.localdomain ([84.203.39.43]) by smtp.gmail.com with ESMTPSA id a13sm26343669wma.0.2017.01.24.04.30.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Jan 2017 04:30:40 -0800 (PST) From: Pete Batard To: edk2-devel@lists.01.org Date: Tue, 24 Jan 2017 12:30:22 +0000 Message-Id: <20170124123026.5204-1-pete@akeo.ie> X-Mailer: git-send-email 2.9.3.windows.2 Subject: [PATCH 1/5] MdeModulePkg/EbcDxe: allow VmReadIndex##() to return a decoded index X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Jan 2017 12:30:43 -0000 * 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 --- 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