From: Pete Batard <pete@akeo.ie>
To: "edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Subject: [PATCH 1/2] MdeModulePkg/EbcDxe: add EBC Debugger
Date: Fri, 11 Nov 2016 15:51:05 +0000 [thread overview]
Message-ID: <78521ad1-d838-7542-fd92-e244973f4643@akeo.ie> (raw)
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 <pete@akeo.ie>
---
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
reply other threads:[~2016-11-11 15:51 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=78521ad1-d838-7542-fd92-e244973f4643@akeo.ie \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox