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 C099A81E1A for ; Fri, 11 Nov 2016 07:51:04 -0800 (PST) Received: by mail-wm0-x243.google.com with SMTP id m203so8664225wma.3 for ; Fri, 11 Nov 2016 07:51:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akeo-ie.20150623.gappssmtp.com; s=20150623; h=from:subject:to:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=+mSxwTdvpz/aI95erfITtcvZ4j3mtCu9EwBX1//IZP4=; b=IRzmJ21d9IpBEyeHZIaYK0gY4aoNmvK9wAO9WKkLH6AiZPkMf6+b9dDnc3JMlRVF91 wu5fiY8qAFyiRWA3Z1Mtd6rtefAjQ+sL5vGVPUBsB12RnGnseP1iyGEXIhMMToSv9gsE k/MRoI951L/kd04nfO4lc8IjQgkY1KYmdsPu8W7bQ3b4dQ2wSBU36usvl4HugZ1LMwkZ +iEinhZ/NuTBdDKvrt+BKikaJq83BWFuEU0isyzIS3T3vWIJTZVaNOuKVXguQn02WcsV tcBjirM7JE8VaHxWOowFeh+EO9kTygmGhMjiJlBmSViVEP9rpm+nXHVI9OgeuHf1oEj9 Tauw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=+mSxwTdvpz/aI95erfITtcvZ4j3mtCu9EwBX1//IZP4=; b=dCtKtH3Qpl1RpY7PqlRKtQ/MGeUOtB9SBWLxtLtvq5E2+yzBu6jAsMu1+UBawbUdOC TGL00rILeIbfFYnPIluebY0/UnCH+PDf1XlbO+fZOCBmyGq1ZMHcy20pUymNjOsC2z8K 7t7RxulowxFB9nR4PFxf+y5ygPpxfRUNIO70S+6VUF4Y4Yne9aAn9uOeByaS/jcgFSof mdFXcS9zy3ga5RA28Q7lJOm8nIrAckNvG9Li3GYsk0zsZi67RtCSZxA85NlxpFh54RVt joAGDVLgPncI2h/F4u1E0bL/Rphg4LTbyVMvv3K3iYhp4i4gD7J3xXowB77OouBkebWM p3SA== X-Gm-Message-State: ABUngvc8Lzl8ctiMVHDkDOceH2OGY/doh88zM5adDLSufznF/HluSsbkg3Bsc5bBIasnUA== X-Received: by 10.28.16.70 with SMTP id 67mr11711264wmq.53.1478879466918; Fri, 11 Nov 2016 07:51:06 -0800 (PST) Received: from [10.0.0.101] ([84.203.32.71]) by smtp.googlemail.com with ESMTPSA id hy10sm12127560wjb.10.2016.11.11.07.51.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 Nov 2016 07:51:06 -0800 (PST) From: Pete Batard To: "edk2-devel@lists.01.org" Message-ID: <78521ad1-d838-7542-fd92-e244973f4643@akeo.ie> Date: Fri, 11 Nov 2016 15:51:05 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 Subject: [PATCH 1/2] MdeModulePkg/EbcDxe: add EBC Debugger 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: Fri, 11 Nov 2016 15:51:05 -0000 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit This patch introduces EbcDebuggerHook.h and inserts the required EBCDebugger references into the existing EBC source files. Since none of the introduced code is active, EbcDxe module compilation should be unaffected by this patch. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Pete Batard --- MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c | 7 ++ MdeModulePkg/Universal/EbcDxe/EbcDebuggerHook.h | 124 +++++++++++++++++++++ MdeModulePkg/Universal/EbcDxe/EbcDxe.inf | 3 +- MdeModulePkg/Universal/EbcDxe/EbcExecute.c | 67 +++++++++++ MdeModulePkg/Universal/EbcDxe/EbcInt.c | 10 ++ MdeModulePkg/Universal/EbcDxe/Ia32/EbcSupport.c | 11 +- MdeModulePkg/Universal/EbcDxe/Ipf/EbcSupport.c | 13 ++- MdeModulePkg/Universal/EbcDxe/X64/EbcSupport.c | 11 +- 8 files changed, 239 insertions(+), 7 deletions(-) create mode 100644 MdeModulePkg/Universal/EbcDxe/EbcDebuggerHook.h diff --git a/MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c b/MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c index c5cc76d..0b990c8 100644 --- a/MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c +++ b/MdeModulePkg/Universal/EbcDxe/AArch64/EbcSupport.c @@ -18,6 +18,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "EbcInt.h" #include "EbcExecute.h" +#include "EbcDebuggerHook.h" // // Amount of space that is not used in the stack @@ -225,6 +226,9 @@ EbcInterpret ( // // Begin executing the EBC code // + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookEbcInterpret (&VmContext); + ) EbcExecute (&VmContext); // @@ -336,6 +340,9 @@ ExecuteEbcImageEntryPoint ( // // Begin executing the EBC code // + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookExecuteEbcImageEntryPoint (&VmContext); + ) EbcExecute (&VmContext); // diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebuggerHook.h b/MdeModulePkg/Universal/EbcDxe/EbcDebuggerHook.h new file mode 100644 index 0000000..34e9815 --- /dev/null +++ b/MdeModulePkg/Universal/EbcDxe/EbcDebuggerHook.h @@ -0,0 +1,124 @@ +/*++ + +Copyright (c) 2007, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + + EbcDebuggerHook.h + +Abstract: + +--*/ + +#ifndef _EFI_EBC_DEBUGGER_HOOK_H_ +#define _EFI_EBC_DEBUGGER_HOOK_H_ + +#ifdef EFI_EBC_DEBUGGER_ENABLED +#define EFI_EBC_DEBUGGER_CODE(a) a +#else +#define EFI_EBC_DEBUGGER_CODE(a) +#endif + +// +// Hook in EbcInt.c +// +VOID +EbcDebuggerHookInit ( + IN EFI_HANDLE Handle, + IN EFI_DEBUG_SUPPORT_PROTOCOL *EbcDebugProtocol + ); + +VOID +EbcDebuggerHookUnload ( + VOID + ); + +VOID +EbcDebuggerHookEbcUnloadImage ( + IN EFI_HANDLE Handle + ); + +// +// Hook in EbcSupport.c +// +VOID +EbcDebuggerHookExecuteEbcImageEntryPoint ( + IN VM_CONTEXT *VmPtr + ); + +VOID +EbcDebuggerHookEbcInterpret ( + IN VM_CONTEXT *VmPtr + ); + +// +// Hook in EbcExecute.c +// +VOID +EbcDebuggerHookExecuteStart ( + IN VM_CONTEXT *VmPtr + ); + +VOID +EbcDebuggerHookExecuteEnd ( + IN VM_CONTEXT *VmPtr + ); + +VOID +EbcDebuggerHookCALLStart ( + IN VM_CONTEXT *VmPtr + ); + +VOID +EbcDebuggerHookCALLEnd ( + IN VM_CONTEXT *VmPtr + ); + +VOID +EbcDebuggerHookCALLEXStart ( + IN VM_CONTEXT *VmPtr + ); + +VOID +EbcDebuggerHookCALLEXEnd ( + IN VM_CONTEXT *VmPtr + ); + +VOID +EbcDebuggerHookRETStart ( + IN VM_CONTEXT *VmPtr + ); + +VOID +EbcDebuggerHookRETEnd ( + IN VM_CONTEXT *VmPtr + ); + +VOID +EbcDebuggerHookJMPStart ( + IN VM_CONTEXT *VmPtr + ); + +VOID +EbcDebuggerHookJMPEnd ( + IN VM_CONTEXT *VmPtr + ); + +VOID +EbcDebuggerHookJMP8Start ( + IN VM_CONTEXT *VmPtr + ); + +VOID +EbcDebuggerHookJMP8End ( + IN VM_CONTEXT *VmPtr + ); + +#endif diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDxe.inf b/MdeModulePkg/Universal/EbcDxe/EbcDxe.inf index e9a0b28..dc769f9 100644 --- a/MdeModulePkg/Universal/EbcDxe/EbcDxe.inf +++ b/MdeModulePkg/Universal/EbcDxe/EbcDxe.inf @@ -33,6 +33,7 @@ # [Sources] + EbcDebuggerHook.h EbcExecute.h EbcExecute.c EbcInt.h @@ -88,4 +89,4 @@ # EVENT_TYPE_PERIODIC_TIMER ## CONSUMES [UserExtensions.TianoCore."ExtraFiles"] - EbcDxeExtra.uni \ No newline at end of file + EbcDxeExtra.uni diff --git a/MdeModulePkg/Universal/EbcDxe/EbcExecute.c b/MdeModulePkg/Universal/EbcDxe/EbcExecute.c index d9c17f4..f71ecb8 100644 --- a/MdeModulePkg/Universal/EbcDxe/EbcExecute.c +++ b/MdeModulePkg/Universal/EbcDxe/EbcExecute.c @@ -14,6 +14,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "EbcInt.h" #include "EbcExecute.h" +#include "EbcDebuggerHook.h" // @@ -1488,6 +1489,10 @@ EbcExecute ( Status = EFI_UNSUPPORTED; goto Done; } + + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookExecuteStart (VmPtr); + ) // // The EBC VM is a strongly ordered processor, so perform a fence operation before // and after each instruction is executed. @@ -1498,6 +1503,9 @@ EbcExecute ( MemoryFence (); + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookExecuteEnd (VmPtr); + ) // // If the step flag is set, signal an exception and continue. We don't // clear it here. Assuming the debugger is responsible for clearing it. @@ -1976,7 +1984,13 @@ ExecuteJMP ( ConditionFlag = (UINT8) VMFLAG_ISSET (VmPtr, VMFLAGS_CC); if ((Operand & CONDITION_M_CONDITIONAL) != 0) { if (CompareSet != ConditionFlag) { + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookJMPStart (VmPtr); + ) VmPtr->Ip += Size; + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookJMPEnd (VmPtr); + ) return EFI_SUCCESS; } } @@ -2012,6 +2026,9 @@ ExecuteJMP ( return EFI_UNSUPPORTED; } + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookJMPStart (VmPtr); + ) // // Take jump -- relative or absolute // @@ -2020,6 +2037,9 @@ ExecuteJMP ( } else { VmPtr->Ip = (VMIP) (UINTN) Data64; } + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookJMPEnd (VmPtr); + ) return EFI_SUCCESS; } @@ -2065,11 +2085,17 @@ ExecuteJMP ( return EFI_UNSUPPORTED; } + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookJMPStart (VmPtr); + ) if ((Operand & JMP_M_RELATIVE) != 0) { VmPtr->Ip += (UINTN) Addr + Size; } else { VmPtr->Ip = (VMIP) Addr; } + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookJMPEnd (VmPtr); + ) } else { // // Form: JMP32 Rx {Immed32} @@ -2085,11 +2111,17 @@ ExecuteJMP ( return EFI_UNSUPPORTED; } + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookJMPStart (VmPtr); + ) if ((Operand & JMP_M_RELATIVE) != 0) { VmPtr->Ip += (UINTN) Addr + Size; } else { VmPtr->Ip = (VMIP) Addr; } + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookJMPEnd (VmPtr); + ) } return EFI_SUCCESS; @@ -2129,7 +2161,13 @@ ExecuteJMP8 ( // if ((Opcode & CONDITION_M_CONDITIONAL) != 0) { if (CompareSet != ConditionFlag) { + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookJMP8Start (VmPtr); + ) VmPtr->Ip += 2; + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookJMP8End (VmPtr); + ) return EFI_SUCCESS; } } @@ -2138,10 +2176,16 @@ ExecuteJMP8 ( // following instruction, and divided by 2. // Offset = VmReadImmed8 (VmPtr, 1); + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookJMP8Start (VmPtr); + ) // // Want to check for offset == -2 and then raise an exception? // VmPtr->Ip += (Offset * 2) + 2; + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookJMP8End (VmPtr); + ) return EFI_SUCCESS; } @@ -2966,6 +3010,15 @@ ExecuteCALL ( // Opcode = GETOPCODE (VmPtr); Operands = GETOPERANDS (VmPtr); + + EFI_EBC_DEBUGGER_CODE ( + if (Operands & OPERAND_M_NATIVE_CALL) { + EbcDebuggerHookCALLEXStart (VmPtr); + } else { + EbcDebuggerHookCALLStart (VmPtr); + } + ) + // // Assign these as well to avoid compiler warnings // @@ -3067,6 +3120,14 @@ ExecuteCALL ( } } + EFI_EBC_DEBUGGER_CODE ( + if (Operands & OPERAND_M_NATIVE_CALL) { + EbcDebuggerHookCALLEXEnd (VmPtr); + } else { + EbcDebuggerHookCALLEnd (VmPtr); + } + ) + return EFI_SUCCESS; } @@ -3087,6 +3148,9 @@ ExecuteRET ( IN VM_CONTEXT *VmPtr ) { + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookRETStart (VmPtr); + ) // // If we're at the top of the stack, then simply set the done // flag and return @@ -3114,6 +3178,9 @@ ExecuteRET ( VmPtr->Gpr[0] += 8; } + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookRETEnd (VmPtr); + ) return EFI_SUCCESS; } diff --git a/MdeModulePkg/Universal/EbcDxe/EbcInt.c b/MdeModulePkg/Universal/EbcDxe/EbcInt.c index 549e0dd..e5e95c3 100644 --- a/MdeModulePkg/Universal/EbcDxe/EbcInt.c +++ b/MdeModulePkg/Universal/EbcDxe/EbcInt.c @@ -16,6 +16,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "EbcInt.h" #include "EbcExecute.h" +#include "EbcDebuggerHook.h" // // We'll keep track of all thunks we create in a linked list. Each @@ -497,6 +498,10 @@ InitializeEbcDriver ( InitEbcVmTestProtocol (&ImageHandle); DEBUG_CODE_END (); + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookInit (ImageHandle, EbcDebugProtocol); + ) + return EFI_SUCCESS; ErrorExit: @@ -1094,6 +1099,11 @@ EbcUnloadImage ( // Now free up the image list element // FreePool (ImageList); + + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookEbcUnloadImage (ImageHandle); + ) + return EFI_SUCCESS; } diff --git a/MdeModulePkg/Universal/EbcDxe/Ia32/EbcSupport.c b/MdeModulePkg/Universal/EbcDxe/Ia32/EbcSupport.c index bddfbf6..3627ef7 100644 --- a/MdeModulePkg/Universal/EbcDxe/Ia32/EbcSupport.c +++ b/MdeModulePkg/Universal/EbcDxe/Ia32/EbcSupport.c @@ -15,6 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "EbcInt.h" #include "EbcExecute.h" +#include "EbcDebuggerHook.h" // // NOTE: This is the stack size allocated for the interpreter @@ -332,10 +333,13 @@ EbcInterpret ( // // Begin executing the EBC code // + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookEbcInterpret (&VmContext); + ) EbcExecute (&VmContext); // - // Return the value in R[7] unless there was an error + // Return the value in Gpr[7] unless there was an error // ReturnEBCStack(StackIndex); return (UINT64) VmContext.Gpr[7]; @@ -432,10 +436,13 @@ ExecuteEbcImageEntryPoint ( // // Begin executing the EBC code // + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookExecuteEbcImageEntryPoint (&VmContext); + ) EbcExecute (&VmContext); // - // Return the value in R[7] unless there was an error + // Return the value in Gpr[7] unless there was an error // ReturnEBCStack(StackIndex); return (UINT64) VmContext.Gpr[7]; diff --git a/MdeModulePkg/Universal/EbcDxe/Ipf/EbcSupport.c b/MdeModulePkg/Universal/EbcDxe/Ipf/EbcSupport.c index 23b6c1b..f99cb8a 100644 --- a/MdeModulePkg/Universal/EbcDxe/Ipf/EbcSupport.c +++ b/MdeModulePkg/Universal/EbcDxe/Ipf/EbcSupport.c @@ -16,6 +16,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "EbcInt.h" #include "EbcExecute.h" #include "EbcSupport.h" +#include "EbcDebuggerHook.h" /** Given raw bytes of Itanium based code, format them into a bundle and @@ -214,12 +215,17 @@ EbcInterpret ( PushU64 (&VmContext, 0); PushU64 (&VmContext, 0xDEADBEEFDEADBEEF); VmContext.StackRetAddr = (UINT64) VmContext.Gpr[0]; + // // Begin executing the EBC code // + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookEbcInterpret (&VmContext); + ) EbcExecute (&VmContext); + // - // Return the value in R[7] unless there was an error + // Return the value in Gpr[7] unless there was an error // ReturnEBCStack(StackIndex); return (UINT64) VmContext.Gpr[7]; @@ -334,10 +340,13 @@ ExecuteEbcImageEntryPoint ( // // Begin executing the EBC code // + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookExecuteEbcImageEntryPoint (&VmContext); + ) EbcExecute (&VmContext); // - // Return the value in R[7] unless there was an error + // Return the value in Gpr[7] unless there was an error // ReturnEBCStack(StackIndex); return (UINT64) VmContext.Gpr[7]; diff --git a/MdeModulePkg/Universal/EbcDxe/X64/EbcSupport.c b/MdeModulePkg/Universal/EbcDxe/X64/EbcSupport.c index bdde5e4..8b16987 100644 --- a/MdeModulePkg/Universal/EbcDxe/X64/EbcSupport.c +++ b/MdeModulePkg/Universal/EbcDxe/X64/EbcSupport.c @@ -15,6 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "EbcInt.h" #include "EbcExecute.h" +#include "EbcDebuggerHook.h" // // NOTE: This is the stack size allocated for the interpreter @@ -278,10 +279,13 @@ EbcInterpret ( // // Begin executing the EBC code // + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookEbcInterpret (&VmContext); + ) EbcExecute (&VmContext); // - // Return the value in R[7] unless there was an error + // Return the value in Gpr[7] unless there was an error // ReturnEBCStack(StackIndex); return (UINT64) VmContext.Gpr[7]; @@ -389,10 +393,13 @@ ExecuteEbcImageEntryPoint ( // // Begin executing the EBC code // + EFI_EBC_DEBUGGER_CODE ( + EbcDebuggerHookExecuteEbcImageEntryPoint (&VmContext); + ) EbcExecute (&VmContext); // - // Return the value in R[7] unless there was an error + // Return the value in Gpr[7] unless there was an error // ReturnEBCStack(StackIndex); return (UINT64) VmContext.Gpr[7]; -- 2.9.3.windows.2