]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/EbcDxe: add EBC Debugger
authorPete Batard <pete@akeo.ie>
Wed, 16 Nov 2016 13:24:09 +0000 (21:24 +0800)
committerJiewen Yao <jiewen.yao@intel.com>
Wed, 23 Nov 2016 02:20:26 +0000 (10:20 +0800)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Pete Batard <pete@akeo.ie>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
34 files changed:
MdeModulePkg/MdeModulePkg.dsc
MdeModulePkg/Universal/EbcDxe/EbcDebugger.inf [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger.uni [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/Edb.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/Edb.h [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBranch.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreak.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreakpoint.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdExtIo.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdExtPci.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdGo.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdHelp.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdMemory.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdQuit.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdRegister.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdScope.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdStep.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdSymbol.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCommand.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCommand.h [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCommon.h [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbDisasm.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbDisasm.h [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbDisasmSupport.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbDisasmSupport.h [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbHook.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbHook.h [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSupport.h [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSupportFile.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSupportString.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSupportUI.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSymbol.c [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSymbol.h [new file with mode: 0644]
MdeModulePkg/Universal/EbcDxe/EbcDebuggerExtra.uni [new file with mode: 0644]

index ea75c8598404c375d0cb24991f3946e11dbed68a..bfecb3078737ae55a0f86c5ae1d3b7e16dcd44c8 100644 (file)
   MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf\r
   MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf\r
 \r
-[Components.IA32, Components.X64, Components.IPF]  \r
+[Components.IA32, Components.X64, Components.IPF, Components.AARCH64]\r
   MdeModulePkg/Universal/Network/UefiPxeBcDxe/UefiPxeBcDxe.inf\r
   MdeModulePkg/Universal/DebugSupportDxe/DebugSupportDxe.inf\r
   MdeModulePkg/Universal/EbcDxe/EbcDxe.inf\r
+  MdeModulePkg/Universal/EbcDxe/EbcDebugger.inf\r
 \r
 [Components.IA32, Components.X64, Components.Ebc]\r
   MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf {\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger.inf b/MdeModulePkg/Universal/EbcDxe/EbcDebugger.inf
new file mode 100644 (file)
index 0000000..7e01666
--- /dev/null
@@ -0,0 +1,120 @@
+## @file\r
+#  EFI Byte Code (EBC) Debugger.\r
+#\r
+#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
+#\r
+#  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
+#  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
+#\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = EbcDebugger\r
+  MODULE_UNI_FILE                = EbcDebugger.uni\r
+  FILE_GUID                      = 8296AF37-D183-4416-B3B6-19D2A80AD4A8\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = InitializeEbcDriver\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF AARCH64\r
+#\r
+\r
+[Sources]\r
+  EbcDebuggerHook.h\r
+  EbcInt.c\r
+  EbcInt.h\r
+  EbcExecute.c\r
+  EbcExecute.h\r
+  EbcDebugger/Edb.c\r
+  EbcDebugger/Edb.h\r
+  EbcDebugger/EdbCommon.h\r
+  EbcDebugger/EdbCmdBranch.c\r
+  EbcDebugger/EdbCmdBreak.c\r
+  EbcDebugger/EdbCmdBreakpoint.c\r
+  EbcDebugger/EdbCmdGo.c\r
+  EbcDebugger/EdbCmdHelp.c\r
+  EbcDebugger/EdbCmdMemory.c\r
+  EbcDebugger/EdbCmdRegister.c\r
+  EbcDebugger/EdbCmdQuit.c\r
+  EbcDebugger/EdbCmdScope.c\r
+  EbcDebugger/EdbCmdStep.c\r
+  EbcDebugger/EdbCmdSymbol.c\r
+  EbcDebugger/EdbCmdExtIo.c\r
+  EbcDebugger/EdbCmdExtPci.c\r
+  EbcDebugger/EdbCommand.c\r
+  EbcDebugger/EdbCommand.h\r
+  EbcDebugger/EdbDisasm.c\r
+  EbcDebugger/EdbDisasm.h\r
+  EbcDebugger/EdbDisasmSupport.c\r
+  EbcDebugger/EdbDisasmSupport.h\r
+  EbcDebugger/EdbSymbol.c\r
+  EbcDebugger/EdbSymbol.h\r
+  EbcDebugger/EdbHook.c\r
+  EbcDebugger/EdbHook.h\r
+  EbcDebugger/EdbSupport.h\r
+  EbcDebugger/EdbSupportUI.c\r
+  EbcDebugger/EdbSupportString.c\r
+  EbcDebugger/EdbSupportFile.c\r
+\r
+[Sources.Ia32]\r
+  Ia32/EbcSupport.c\r
+  Ia32/EbcLowLevel.nasm\r
+  Ia32/EbcLowLevel.S\r
+  Ia32/EbcLowLevel.asm\r
+\r
+[Sources.X64]\r
+  X64/EbcSupport.c\r
+  X64/EbcLowLevel.nasm\r
+  X64/EbcLowLevel.S\r
+  X64/EbcLowLevel.asm\r
+\r
+[Sources.IPF]\r
+  Ipf/EbcSupport.h\r
+  Ipf/EbcSupport.c\r
+  Ipf/EbcLowLevel.s\r
+\r
+[Sources.AARCH64]\r
+  AArch64/EbcSupport.c\r
+  AArch64/EbcLowLevel.S\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  DebugLib\r
+  BaseLib\r
+\r
+[Protocols]\r
+  gEfiDebugSupportProtocolGuid                  ## PRODUCES\r
+  gEfiEbcProtocolGuid                           ## PRODUCES\r
+  gEfiEbcVmTestProtocolGuid                     ## SOMETIMES_PRODUCES\r
+  gEfiEbcSimpleDebuggerProtocolGuid             ## SOMETIMES_CONSUMES\r
+  gEfiPciRootBridgeIoProtocolGuid               ## SOMETIMES_CONSUMES\r
+  gEfiSimpleFileSystemProtocolGuid              ## SOMETIMES_CONSUMES\r
+\r
+[Guids]\r
+  gEfiFileInfoGuid                              ## SOMETIMES_CONSUMES ## GUID\r
+  gEfiFileSystemInfoGuid                        ## SOMETIMES_CONSUMES ## GUID\r
+  gEfiFileSystemVolumeLabelInfoIdGuid           ## SOMETIMES_CONSUMES ## GUID\r
+  gEfiDebugImageInfoTableGuid                   ## SOMETIMES_CONSUMES ## GUID\r
+\r
+[Depex]\r
+  TRUE\r
+\r
+[UserExtensions.TianoCore."ExtraFiles"]\r
+  EbcDebuggerExtra.uni\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger.uni b/MdeModulePkg/Universal/EbcDxe/EbcDebugger.uni
new file mode 100644 (file)
index 0000000..2586274
--- /dev/null
@@ -0,0 +1,18 @@
+// /** @file\r
+// EFI Byte Code (EBC) Debugger.\r
+//\r
+// Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+//\r
+// 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
+// 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
+//\r
+// **/\r
+\r
+\r
+#string STR_MODULE_ABSTRACT             #language en-US "EFI Byte Code (EBC) Debugger application"\r
+\r
+#string STR_MODULE_DESCRIPTION          #language en-US "This application enables the debugging of EBC runtimes."\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/Edb.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/Edb.c
new file mode 100644 (file)
index 0000000..e0b85c7
--- /dev/null
@@ -0,0 +1,659 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  Ebc.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+#include <Uefi.h>\r
+#include "Edb.h"\r
+\r
+EFI_DEBUGGER_PRIVATE_DATA mDebuggerPrivate = {\r
+  EFI_DEBUGGER_SIGNATURE,                    // Signature\r
+  IsaEbc,                                    // Isa\r
+  (EBC_DEBUGGER_MAJOR_VERSION << 16) |\r
+    EBC_DEBUGGER_MINOR_VERSION,              // EfiDebuggerRevision\r
+  (VM_MAJOR_VERSION << 16) |\r
+    VM_MINOR_VERSION,                        // EbcVmRevision\r
+  NULL,                                      // DebugImageInfoTableHeader\r
+  NULL,                                      // Vol\r
+  NULL,                                      // PciRootBridgeIo\r
+  mDebuggerCommandSet,                       // DebuggerCommandSet\r
+  {0},                                       // DebuggerSymbolContext\r
+  0,                                         // DebuggerBreakpointCount\r
+  {{0}},                                     // DebuggerBreakpointContext\r
+  0,                                         // CallStackEntryCount\r
+  {{0}},                                     // CallStackEntry\r
+  0,                                         // TraceEntryCount\r
+  {{0}},                                     // TraceEntry\r
+  {0},                                       // StepContext\r
+  {0},                                       // GoTilContext\r
+  0,                                         // InstructionScope\r
+  EFI_DEBUG_DEFAULT_INSTRUCTION_NUMBER,      // InstructionNumber\r
+  EFI_DEBUG_FLAG_EBC_BOE | EFI_DEBUG_FLAG_EBC_BOT, // FeatureFlags\r
+  0,                                               // StatusFlags\r
+  FALSE,                                           // EnablePageBreak\r
+  NULL                                             // BreakEvent\r
+};\r
+\r
+CHAR16 *mExceptionStr[] = {\r
+  L"EXCEPT_EBC_UNDEFINED",\r
+  L"EXCEPT_EBC_DIVIDE_ERROR",\r
+  L"EXCEPT_EBC_DEBUG",\r
+  L"EXCEPT_EBC_BREAKPOINT",\r
+  L"EXCEPT_EBC_OVERFLOW",\r
+  L"EXCEPT_EBC_INVALID_OPCODE",\r
+  L"EXCEPT_EBC_STACK_FAULT",\r
+  L"EXCEPT_EBC_ALIGNMENT_CHECK",\r
+  L"EXCEPT_EBC_INSTRUCTION_ENCODING",\r
+  L"EXCEPT_EBC_BAD_BREAK",\r
+  L"EXCEPT_EBC_SINGLE_STEP",\r
+};\r
+\r
+VOID\r
+EdbClearAllBreakpoint (\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     BOOLEAN                   NeedRemove\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Clear all the breakpoint\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  NeedRemove      - Whether need to remove all the breakpoint\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  UINTN    Index;\r
+\r
+  //\r
+  // Patch all the breakpoint\r
+  //\r
+  for (Index = 0; (Index < DebuggerPrivate->DebuggerBreakpointCount) && (Index < EFI_DEBUGGER_BREAKPOINT_MAX); Index++) {\r
+    if (DebuggerPrivate->DebuggerBreakpointContext[Index].State) {\r
+      CopyMem (\r
+        (VOID *)(UINTN)DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress,\r
+        &DebuggerPrivate->DebuggerBreakpointContext[Index].OldInstruction,\r
+        sizeof(UINT16)\r
+        );\r
+    }\r
+  }\r
+\r
+  //\r
+  // Zero Breakpoint context, if need to remove all breakpoint\r
+  //\r
+  if (NeedRemove) {\r
+    DebuggerPrivate->DebuggerBreakpointCount = 0;\r
+    ZeroMem (DebuggerPrivate->DebuggerBreakpointContext, sizeof(DebuggerPrivate->DebuggerBreakpointContext));\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return ;\r
+}\r
+\r
+VOID\r
+EdbSetAllBreakpoint (\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Set all the breakpoint\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  UINTN    Index;\r
+  UINT16   Data16;\r
+\r
+  //\r
+  // Set all the breakpoint (BREAK(3) : 0x0300)\r
+  //\r
+  Data16 = 0x0300;\r
+  for (Index = 0; (Index < DebuggerPrivate->DebuggerBreakpointCount) && (Index < EFI_DEBUGGER_BREAKPOINT_MAX); Index++) {\r
+    if (DebuggerPrivate->DebuggerBreakpointContext[Index].State) {\r
+      CopyMem (\r
+        (VOID *)(UINTN)DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress,\r
+        &Data16,\r
+        sizeof(UINT16)\r
+        );\r
+    }\r
+  }\r
+\r
+  //\r
+  // Check if current break is caused by breakpoint set.\r
+  // If so, we need to patch memory back to let user see the real memory.\r
+  //\r
+  if (DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].BreakpointAddress != 0) {\r
+    CopyMem (\r
+      (VOID *)(UINTN)DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].BreakpointAddress,\r
+      &DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].OldInstruction,\r
+      sizeof(UINT16)\r
+      );\r
+    DebuggerPrivate->StatusFlags &= ~EFI_DEBUG_FLAG_EBC_B_BP;\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return ;\r
+}\r
+\r
+VOID\r
+EdbCheckBreakpoint (\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Check all the breakpoint, if match, then set status flag, and record current breakpoint.\r
+  Then clear all breakpoint to let user see a clean memory\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  UINT64   Address;\r
+  UINTN    Index;\r
+  UINT16   OldInstruction;\r
+  BOOLEAN  IsHitBreakpoint;\r
+\r
+  //\r
+  // Roll back IP for breakpoint instruction (BREAK(3) : 0x0300)\r
+  //\r
+  Address = SystemContext.SystemContextEbc->Ip - sizeof(UINT16);\r
+\r
+  //\r
+  // Check if the breakpoint is hit\r
+  //\r
+  IsHitBreakpoint = FALSE;\r
+  for (Index = 0; (Index < DebuggerPrivate->DebuggerBreakpointCount) && (Index < EFI_DEBUGGER_BREAKPOINT_MAX); Index++) {\r
+    if ((DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress == Address) &&\r
+        (DebuggerPrivate->DebuggerBreakpointContext[Index].State)) {\r
+      OldInstruction = (UINT16)DebuggerPrivate->DebuggerBreakpointContext[Index].OldInstruction;\r
+      IsHitBreakpoint = TRUE;\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (IsHitBreakpoint) {\r
+    //\r
+    // If hit, record current breakpoint\r
+    //\r
+    DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX] = DebuggerPrivate->DebuggerBreakpointContext[Index];\r
+    DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].State = TRUE;\r
+    //\r
+    // Update: IP and Instruction (NOTE: Since we not allow set breakpoint to BREAK 3, this update is safe)\r
+    //\r
+    SystemContext.SystemContextEbc->Ip = Address;\r
+    //\r
+    // Set Flags\r
+    //\r
+    DebuggerPrivate->StatusFlags |= EFI_DEBUG_FLAG_EBC_BP;\r
+  } else {\r
+    //\r
+    // If not hit, check whether current IP is in breakpoint list,\r
+    // because STEP will be triggered before execute the instruction.\r
+    // We should not patch it in de-init.\r
+    //\r
+    Address = SystemContext.SystemContextEbc->Ip;\r
+\r
+    //\r
+    // Check if the breakpoint is hit\r
+    //\r
+    IsHitBreakpoint = FALSE;\r
+    for (Index = 0; (Index < DebuggerPrivate->DebuggerBreakpointCount) && (Index < EFI_DEBUGGER_BREAKPOINT_MAX); Index++) {\r
+      if ((DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress == Address) &&\r
+          (DebuggerPrivate->DebuggerBreakpointContext[Index].State)) {\r
+        OldInstruction = (UINT16)DebuggerPrivate->DebuggerBreakpointContext[Index].OldInstruction;\r
+        IsHitBreakpoint = TRUE;\r
+        break;\r
+      }\r
+    }\r
+\r
+    if (IsHitBreakpoint) {\r
+      //\r
+      // If hit, record current breakpoint\r
+      //\r
+      DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX] = DebuggerPrivate->DebuggerBreakpointContext[Index];\r
+      DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX].State = TRUE;\r
+      //\r
+      // Do not set Breakpoint flag. We record the address here just let it not patch breakpoint address when de-init.\r
+      //\r
+    } else {\r
+      //\r
+      // Zero current breakpoint\r
+      //\r
+      ZeroMem (\r
+        &DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX],\r
+        sizeof(DebuggerPrivate->DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX])\r
+        );\r
+    }\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return ;\r
+}\r
+\r
+VOID\r
+EdbClearSymbol (\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  clear all the symbol\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  EFI_DEBUGGER_SYMBOL_CONTEXT *DebuggerSymbolContext;\r
+  EFI_DEBUGGER_SYMBOL_OBJECT  *Object;\r
+  UINTN                       ObjectIndex;\r
+  UINTN                       Index;\r
+\r
+  //\r
+  // Go throuth each object\r
+  //\r
+  DebuggerSymbolContext = &DebuggerPrivate->DebuggerSymbolContext;\r
+  for (ObjectIndex = 0; ObjectIndex < DebuggerSymbolContext->ObjectCount; ObjectIndex++) {\r
+    Object = &DebuggerSymbolContext->Object[ObjectIndex];\r
+    //\r
+    // Go throuth each entry\r
+    //\r
+    for (Index = 0; Index < Object->EntryCount; Index++) {\r
+      ZeroMem (&Object->Entry[Index], sizeof(Object->Entry[Index]));\r
+    }\r
+    ZeroMem (Object->Name, sizeof(Object->Name));\r
+    Object->EntryCount = 0;\r
+    Object->BaseAddress = 0;\r
+    Object->StartEntrypointRVA = 0;\r
+    Object->MainEntrypointRVA = 0;\r
+    //\r
+    // Free source buffer\r
+    //\r
+    for (Index = 0; Object->SourceBuffer[Index] != NULL; Index++) {\r
+      gBS->FreePool (Object->SourceBuffer[Index]);\r
+      Object->SourceBuffer[Index] = NULL;\r
+    }\r
+  }\r
+  DebuggerSymbolContext->ObjectCount = 0;\r
+\r
+  return ;\r
+}\r
+\r
+EFI_STATUS\r
+InitDebuggerPrivateData (\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  IN     BOOLEAN                   Initialized\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Initialize Debugger private data structure\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+  Initialized     - Whether the DebuggerPrivate data is initialized.\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  //\r
+  // clear STEP flag in any condition.\r
+  //\r
+  if (SystemContext.SystemContextEbc->Flags & VMFLAGS_STEP) {\r
+    SystemContext.SystemContextEbc->Flags &= ~VMFLAGS_STEP;\r
+  }\r
+\r
+  if (!Initialized) {\r
+    //\r
+    // Initialize everything\r
+    //\r
+    DebuggerPrivate->InstructionNumber = EFI_DEBUG_DEFAULT_INSTRUCTION_NUMBER;\r
+\r
+    DebuggerPrivate->DebuggerBreakpointCount = 0;\r
+    ZeroMem (DebuggerPrivate->DebuggerBreakpointContext, sizeof(DebuggerPrivate->DebuggerBreakpointContext));\r
+\r
+//    DebuggerPrivate->StatusFlags = 0;\r
+\r
+    DebuggerPrivate->DebuggerSymbolContext.DisplaySymbol = TRUE;\r
+    DebuggerPrivate->DebuggerSymbolContext.DisplayCodeOnly = FALSE;\r
+    DebuggerPrivate->DebuggerSymbolContext.ObjectCount = 0;\r
+  } else {\r
+    //\r
+    // Already initialized, just check Breakpoint here.\r
+    //\r
+    if (ExceptionType == EXCEPT_EBC_BREAKPOINT) {\r
+      EdbCheckBreakpoint (DebuggerPrivate, SystemContext);\r
+    }\r
+\r
+    //\r
+    // Clear all breakpoint\r
+    //\r
+    EdbClearAllBreakpoint (DebuggerPrivate, FALSE);\r
+  }\r
+\r
+  //\r
+  // Set Scope to currentl IP. (Note: Check Breakpoint may change Ip)\r
+  //\r
+  DebuggerPrivate->InstructionScope = SystemContext.SystemContextEbc->Ip;\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+DeinitDebuggerPrivateData (\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  IN     BOOLEAN                   Initialized\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  De-initialize Debugger private data structure\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+  Initialized     - Whether the DebuggerPrivate data is initialized.\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  if (!Initialized) {\r
+    //\r
+    // If it does not want initialized state, de-init everything\r
+    //\r
+    DebuggerPrivate->FeatureFlags = EFI_DEBUG_FLAG_EBC_BOE | EFI_DEBUG_FLAG_EBC_BOT;\r
+    DebuggerPrivate->CallStackEntryCount = 0;\r
+    DebuggerPrivate->TraceEntryCount = 0;\r
+    ZeroMem (DebuggerPrivate->CallStackEntry, sizeof(DebuggerPrivate->CallStackEntry));\r
+    ZeroMem (DebuggerPrivate->TraceEntry, sizeof(DebuggerPrivate->TraceEntry));\r
+\r
+    //\r
+    // Clear all breakpoint\r
+    //\r
+    EdbClearAllBreakpoint (DebuggerPrivate, TRUE);\r
+\r
+    //\r
+    // Clear symbol\r
+    //\r
+    EdbClearSymbol (DebuggerPrivate);\r
+  } else {\r
+    //\r
+    // If it wants to keep initialized state, just set breakpoint.\r
+    //\r
+    EdbSetAllBreakpoint (DebuggerPrivate);\r
+  }\r
+\r
+  //\r
+  // Clear Step context\r
+  //\r
+  ZeroMem (&mDebuggerPrivate.StepContext, sizeof(mDebuggerPrivate.StepContext));\r
+  DebuggerPrivate->StatusFlags = 0;\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+VOID\r
+PrintExceptionReason (\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  IN     BOOLEAN                   Initialized\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the reason of current break to EbcDebugger.\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+  Initialized     - Whether the DebuggerPrivate data is initialized.\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  //\r
+  // Print break status\r
+  //\r
+  if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_GT) == EFI_DEBUG_FLAG_EBC_GT) {\r
+    EDBPrint (L"Break on GoTil\n");\r
+  } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOC) == EFI_DEBUG_FLAG_EBC_BOC) {\r
+    EDBPrint (L"Break on CALL\n");\r
+  } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOCX) == EFI_DEBUG_FLAG_EBC_BOCX) {\r
+    EDBPrint (L"Break on CALLEX\n");\r
+  } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOR) == EFI_DEBUG_FLAG_EBC_BOR) {\r
+    EDBPrint (L"Break on RET\n");\r
+  } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOE) == EFI_DEBUG_FLAG_EBC_BOE) {\r
+    EDBPrint (L"Break on Entrypoint\n");\r
+  } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOT) == EFI_DEBUG_FLAG_EBC_BOT) {\r
+    EDBPrint (L"Break on Thunk\n");\r
+  } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_STEPOVER) == EFI_DEBUG_FLAG_EBC_STEPOVER) {\r
+    EDBPrint (L"Break on StepOver\n");\r
+  } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_STEPOUT) == EFI_DEBUG_FLAG_EBC_STEPOUT) {\r
+    EDBPrint (L"Break on StepOut\n");\r
+  } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BP) == EFI_DEBUG_FLAG_EBC_BP) {\r
+    EDBPrint (L"Break on Breakpoint\n");\r
+  } else if ((DebuggerPrivate->StatusFlags & EFI_DEBUG_FLAG_EBC_BOK) == EFI_DEBUG_FLAG_EBC_BOK) {\r
+    EDBPrint (L"Break on Key\n");\r
+  } else {\r
+    EDBPrint (L"Exception Type - %x", (UINTN)ExceptionType);\r
+    if ((ExceptionType >= EXCEPT_EBC_UNDEFINED) && (ExceptionType <= EXCEPT_EBC_STEP)) {\r
+      EDBPrint (L" (%s)\n", mExceptionStr[ExceptionType]);\r
+    } else {\r
+      EDBPrint (L"\n");\r
+    }\r
+  }\r
+\r
+  return ;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+EdbExceptionHandler (\r
+  IN     EFI_EXCEPTION_TYPE   ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT   SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The default Exception Callback for the VM interpreter.\r
+  In this function, we report status code, and print debug information\r
+  about EBC_CONTEXT, then dead loop.\r
+\r
+Arguments:\r
+\r
+  InterruptType - Interrupt type.\r
+  SystemContext - EBC system context.\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  CHAR16                  InputBuffer[EFI_DEBUG_INPUS_BUFFER_SIZE];\r
+  CHAR16                  *CommandArg;\r
+  EFI_DEBUGGER_COMMAND    DebuggerCommand;\r
+  EFI_DEBUG_STATUS        DebugStatus;\r
+  STATIC BOOLEAN          mInitialized = FALSE;\r
+\r
+  DEBUG ((DEBUG_ERROR, "Hello EBC Debugger!\n"));\r
+\r
+  if (!mInitialized) {\r
+    //\r
+    // Print version\r
+    //\r
+    EDBPrint (\r
+      L"EBC Interpreter Version - %d.%d\n",\r
+      (UINTN)VM_MAJOR_VERSION,\r
+      (UINTN)VM_MINOR_VERSION\r
+      );\r
+    EDBPrint (\r
+      L"EBC Debugger Version - %d.%d\n",\r
+      (UINTN)EBC_DEBUGGER_MAJOR_VERSION,\r
+      (UINTN)EBC_DEBUGGER_MINOR_VERSION\r
+      );\r
+  }\r
+  //\r
+  // Init Private Data\r
+  //\r
+  InitDebuggerPrivateData (&mDebuggerPrivate, ExceptionType, SystemContext, mInitialized);\r
+\r
+  //\r
+  // EDBPrint basic info\r
+  //\r
+  PrintExceptionReason (&mDebuggerPrivate, ExceptionType, SystemContext, mInitialized);\r
+\r
+  EdbShowDisasm (&mDebuggerPrivate, SystemContext);\r
+  // EFI_BREAKPOINT ();\r
+\r
+  if (!mInitialized) {\r
+    //\r
+    // Interactive with user\r
+    //\r
+    EDBPrint (L"\nPlease enter command now, \'h\' for help.\n");\r
+    EDBPrint (L"(Using <Command> -b <...> to enable page break.)\n");\r
+  }\r
+  mInitialized = TRUE;\r
+\r
+  //\r
+  // Dispatch each command\r
+  //\r
+  while (TRUE) {\r
+    //\r
+    // Get user input\r
+    //\r
+    Input (L"\n\r" EFI_DEBUG_PROMPT_STRING, InputBuffer, EFI_DEBUG_INPUS_BUFFER_SIZE);\r
+    EDBPrint (L"\n");\r
+\r
+    //\r
+    // Get command\r
+    //\r
+    DebuggerCommand = MatchDebuggerCommand (InputBuffer, &CommandArg);\r
+    if (DebuggerCommand == NULL) {\r
+      EDBPrint (L"ERROR: Command not found!\n");\r
+      continue;\r
+    }\r
+\r
+    //\r
+    // Check PageBreak;\r
+    //\r
+    if (CommandArg != NULL) {\r
+      if (StriCmp (CommandArg, L"-b") == 0) {\r
+        CommandArg = StrGetNextTokenLine (L" ");\r
+        mDebuggerPrivate.EnablePageBreak = TRUE;\r
+      }\r
+    }\r
+\r
+    //\r
+    // Dispatch command\r
+    //\r
+    DebugStatus = DebuggerCommand (CommandArg, &mDebuggerPrivate, ExceptionType, SystemContext);\r
+    mDebuggerPrivate.EnablePageBreak = FALSE;\r
+\r
+    //\r
+    // Check command return status\r
+    //\r
+    if (DebugStatus == EFI_DEBUG_RETURN) {\r
+      mInitialized = FALSE;\r
+      break;\r
+    } else if (DebugStatus == EFI_DEBUG_BREAK) {\r
+      break;\r
+    } else if (DebugStatus == EFI_DEBUG_CONTINUE) {\r
+      continue;\r
+    } else {\r
+      ASSERT (FALSE);\r
+    }\r
+  }\r
+\r
+  //\r
+  // Deinit Private Data\r
+  //\r
+  DeinitDebuggerPrivateData (&mDebuggerPrivate, ExceptionType, SystemContext, mInitialized);\r
+\r
+  DEBUG ((DEBUG_ERROR, "Goodbye EBC Debugger!\n"));\r
+\r
+  return;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/Edb.h b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/Edb.h
new file mode 100644 (file)
index 0000000..d366ca5
--- /dev/null
@@ -0,0 +1,62 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  Edb.h\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#ifndef _EFI_EDB_H_\r
+#define _EFI_EDB_H_\r
+\r
+#include <Uefi.h>\r
+#include "EdbCommon.h"\r
+\r
+#include "EbcInt.h"\r
+#include "EbcExecute.h"\r
+\r
+#define EBC_DEBUGGER_MAJOR_VERSION   1\r
+#define EBC_DEBUGGER_MINOR_VERSION   0\r
+\r
+#define EFI_DEBUG_RETURN    1\r
+#define EFI_DEBUG_BREAK     2\r
+#define EFI_DEBUG_CONTINUE  3\r
+\r
+//\r
+// Function\r
+//\r
+EFI_STATUS\r
+EfiDebuggerEntrypoint (\r
+  IN EFI_HANDLE                     ImageHandle,\r
+  IN EFI_SYSTEM_TABLE               *SystemTable\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+EdbExceptionHandler (\r
+  IN     EFI_EXCEPTION_TYPE   ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT   SystemContext\r
+  );\r
+\r
+extern EFI_DEBUGGER_PRIVATE_DATA mDebuggerPrivate;\r
+\r
+#include "EdbSupport.h"\r
+#include "EdbCommand.h"\r
+#include "EdbDisasm.h"\r
+#include "EdbDisasmSupport.h"\r
+#include "EdbSymbol.h"\r
+#include "EdbHook.h"\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBranch.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBranch.c
new file mode 100644 (file)
index 0000000..ab07f72
--- /dev/null
@@ -0,0 +1,336 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbCmdBranch.c\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#include "Edb.h"\r
+\r
+CHAR16 *mBranchTypeStr[] = {\r
+  L"(CALL)",\r
+  L"(CALLEX)",\r
+  L"(RET)",\r
+  L"(JMP)",\r
+  L"(JMP8)",\r
+};\r
+\r
+CHAR16 *\r
+EdbBranchTypeToStr (\r
+  IN EFI_DEBUGGER_BRANCH_TYPE  Type\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Comvert Branch Type to string\r
+\r
+Arguments:\r
+\r
+  Type            - Branch Type\r
+\r
+Returns:\r
+\r
+  String\r
+\r
+--*/\r
+{\r
+  if (Type < 0 || Type >= EfiDebuggerBranchTypeEbcMax) {\r
+    return L"(Unknown Type)";\r
+  }\r
+\r
+  return mBranchTypeStr [Type];\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerCallStack (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - CallStack\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  INTN                           Index;\r
+  UINTN                          SubIndex;\r
+  CHAR8                          *FuncName;\r
+  EFI_DEBUGGER_CALLSTACK_CONTEXT *CallStackEntry;\r
+  BOOLEAN                        ShowParameter;\r
+  UINTN                          ParameterNumber;\r
+\r
+  ShowParameter = FALSE;\r
+  ParameterNumber = EFI_DEBUGGER_CALL_DEFAULT_PARAMETER;\r
+\r
+  //\r
+  // Check argument\r
+  //\r
+  if (CommandArg != NULL) {\r
+    if (StriCmp (CommandArg, L"c") == 0) {\r
+      //\r
+      // Clear Call-Stack\r
+      //\r
+      DebuggerPrivate->CallStackEntryCount = 0;\r
+      ZeroMem (DebuggerPrivate->CallStackEntry, sizeof(DebuggerPrivate->CallStackEntry));\r
+      EDBPrint (L"Call-Stack is cleared\n");\r
+      return EFI_DEBUG_CONTINUE;\r
+    } else if (StriCmp (CommandArg, L"p") == 0) {\r
+      //\r
+      // Print Call-Stack with parameter\r
+      //\r
+      ShowParameter = TRUE;\r
+      CommandArg = StrGetNextTokenLine (L" ");\r
+      if (CommandArg != NULL) {\r
+        //\r
+        // Try to get the parameter number\r
+        //\r
+        ParameterNumber = Atoi (CommandArg);\r
+        if (ParameterNumber > 16) {\r
+          EDBPrint (L"Call-Stack argument Invalid\n");\r
+          return EFI_DEBUG_CONTINUE;\r
+        }\r
+      }\r
+    } else {\r
+      EDBPrint (L"Call-Stack argument Invalid\n");\r
+      return EFI_DEBUG_CONTINUE;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Check CallStack Entry Count\r
+  //\r
+  if (DebuggerPrivate->CallStackEntryCount == 0) {\r
+    EDBPrint (L"No Call-Stack\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  } else if (DebuggerPrivate->CallStackEntryCount > EFI_DEBUGGER_CALLSTACK_MAX) {\r
+    EDBPrint (L"Call-Stack Crash, re-initialize!\n");\r
+    DebuggerPrivate->CallStackEntryCount = 0;\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // Go through each CallStack entry and print\r
+  //\r
+  EDBPrint (L"Call-Stack (TOP):\n");\r
+  EDBPrint (L"         Caller             Callee        Name\n");\r
+  EDBPrint (L"  ================== ================== ========\n");\r
+//EDBPrint (L"  0x00000000FFFFFFFF 0xFFFFFFFF00000000 EfiMain\n");\r
+  for (Index = (INTN)(DebuggerPrivate->CallStackEntryCount - 1); Index >= 0; Index--) {\r
+    //\r
+    // Get CallStack and print\r
+    //\r
+    CallStackEntry = &DebuggerPrivate->CallStackEntry[Index];\r
+    EDBPrint (\r
+      L"  0x%016lx 0x%016lx",\r
+      CallStackEntry->SourceAddress,\r
+      CallStackEntry->DestAddress\r
+      );\r
+    FuncName = FindSymbolStr ((UINTN)CallStackEntry->DestAddress);\r
+    if (FuncName != NULL) {\r
+      EDBPrint (L" %a()", FuncName);\r
+    }\r
+    EDBPrint (L"\n");\r
+\r
+    if (ShowParameter) {\r
+      //\r
+      // Print parameter\r
+      //\r
+      if (sizeof(UINTN) == sizeof(UINT64)) {\r
+        EDBPrint (\r
+          L"    Parameter Address (0x%016lx) (\n",\r
+          CallStackEntry->ParameterAddr\r
+          );\r
+        if (ParameterNumber == 0) {\r
+          EDBPrint (L"        )\n");\r
+          continue;\r
+        }\r
+        //\r
+        // Print each parameter\r
+        //\r
+        for (SubIndex = 0; SubIndex < ParameterNumber - 1; SubIndex++) {\r
+          if (SubIndex % 2 == 0) {\r
+            EDBPrint (L"        ");\r
+          }\r
+          EDBPrint (\r
+            L"0x%016lx, ",\r
+            CallStackEntry->Parameter[SubIndex]\r
+            );\r
+          if (SubIndex % 2 == 1) {\r
+            EDBPrint (L"\n");\r
+          }\r
+        }\r
+        if (SubIndex % 2 == 0) {\r
+          EDBPrint (L"        ");\r
+        }\r
+        EDBPrint (\r
+          L"0x%016lx\n",\r
+          CallStackEntry->Parameter[SubIndex]\r
+          );\r
+        EDBPrint (L"        )\n");\r
+        //\r
+        // break only for parameter\r
+        //\r
+        if ((((DebuggerPrivate->CallStackEntryCount - Index) % (16 / ParameterNumber)) == 0) &&\r
+            (Index != 0)) {\r
+          if (SetPageBreak ()) {\r
+            break;\r
+          }\r
+        }\r
+      } else {\r
+        EDBPrint (\r
+          L"    Parameter Address (0x%08x) (\n",\r
+          CallStackEntry->ParameterAddr\r
+          );\r
+        if (ParameterNumber == 0) {\r
+          EDBPrint (L"        )\n");\r
+          continue;\r
+        }\r
+        //\r
+        // Print each parameter\r
+        //\r
+        for (SubIndex = 0; SubIndex < ParameterNumber - 1; SubIndex++) {\r
+          if (SubIndex % 4 == 0) {\r
+            EDBPrint (L"        ");\r
+          }\r
+          EDBPrint (\r
+            L"0x%08x, ",\r
+            CallStackEntry->Parameter[SubIndex]\r
+            );\r
+          if (SubIndex % 4 == 3) {\r
+            EDBPrint (L"\n");\r
+          }\r
+        }\r
+        if (SubIndex % 4 == 0) {\r
+          EDBPrint (L"        ");\r
+        }\r
+        EDBPrint (\r
+          L"0x%08x\n",\r
+          CallStackEntry->Parameter[SubIndex]\r
+          );\r
+        EDBPrint (L"        )\n");\r
+        //\r
+        // break only for parameter\r
+        //\r
+        if ((((DebuggerPrivate->CallStackEntryCount - Index) % (32 / ParameterNumber)) == 0) &&\r
+            (Index != 0)) {\r
+          if (SetPageBreak ()) {\r
+            break;\r
+          }\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerInstructionBranch (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - InstructionBranch\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  UINTN  Index;\r
+\r
+  //\r
+  // Check argument\r
+  //\r
+  if (CommandArg != NULL) {\r
+    if (StriCmp (CommandArg, L"c") == 0) {\r
+      //\r
+      // Clear Trace\r
+      //\r
+      DebuggerPrivate->TraceEntryCount = 0;\r
+      ZeroMem (DebuggerPrivate->TraceEntry, sizeof(DebuggerPrivate->TraceEntry));\r
+      EDBPrint (L"Instruction Trace is cleared\n");\r
+    } else {\r
+      EDBPrint (L"Trace argument Invalid\n");\r
+    }\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // Check Trace Entry Count\r
+  //\r
+  if (DebuggerPrivate->TraceEntryCount == 0) {\r
+    EDBPrint (L"No Instruction Trace\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  } else if (DebuggerPrivate->TraceEntryCount > EFI_DEBUGGER_TRACE_MAX) {\r
+    EDBPrint (L"Instruction Trace Crash, re-initialize!\n");\r
+    DebuggerPrivate->TraceEntryCount = 0;\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // Go through each Trace entry and print\r
+  //\r
+  EDBPrint (L"Instruction Trace (->Latest):\n");\r
+  EDBPrint (L"    Source Addr        Destination Addr   Type\n");\r
+  EDBPrint (L"  ================== ================== ========\n");\r
+//EDBPrint (L"  0x00000000FFFFFFFF 0xFFFFFFFF00000000  (CALLEX)\n");\r
+  for (Index = 0; Index < DebuggerPrivate->TraceEntryCount; Index++) {\r
+    EDBPrint (\r
+      L"  0x%016lx 0x%016lx  %s\n",\r
+      DebuggerPrivate->TraceEntry[Index].SourceAddress,\r
+      DebuggerPrivate->TraceEntry[Index].DestAddress,\r
+      EdbBranchTypeToStr (DebuggerPrivate->TraceEntry[Index].Type)\r
+      );\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreak.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreak.c
new file mode 100644 (file)
index 0000000..ab3c7d8
--- /dev/null
@@ -0,0 +1,327 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbCmdBreak.c\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#include "Edb.h"\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerBreakOnCALL (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - BreakOnCALL\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  //\r
+  // Check argument\r
+  //\r
+  if (CommandArg == NULL) {\r
+    if ((DebuggerPrivate->FeatureFlags & EFI_DEBUG_FLAG_EBC_BOC) == EFI_DEBUG_FLAG_EBC_BOC) {\r
+      EDBPrint (L"BOC on\n");\r
+    } else {\r
+      EDBPrint (L"BOC off\n");\r
+    }\r
+  } else if (StriCmp (CommandArg, L"on") == 0) {\r
+    DebuggerPrivate->FeatureFlags |= EFI_DEBUG_FLAG_EBC_BOC;\r
+    EDBPrint (L"BOC on\n");\r
+  } else if (StriCmp (CommandArg, L"off") == 0) {\r
+    DebuggerPrivate->FeatureFlags &= ~EFI_DEBUG_FLAG_EBC_B_BOC;\r
+    EDBPrint (L"BOC off\n");\r
+  } else {\r
+    EDBPrint (L"BOC - argument error\n");\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerBreakOnCALLEX (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - BreakOnCALLEX\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  //\r
+  // Check argument\r
+  //\r
+  if (CommandArg == NULL) {\r
+    if ((DebuggerPrivate->FeatureFlags & EFI_DEBUG_FLAG_EBC_BOCX) == EFI_DEBUG_FLAG_EBC_BOCX) {\r
+      EDBPrint (L"BOCX on\n");\r
+    } else {\r
+      EDBPrint (L"BOCX off\n");\r
+    }\r
+  } else if (StriCmp (CommandArg, L"on") == 0) {\r
+    DebuggerPrivate->FeatureFlags |= EFI_DEBUG_FLAG_EBC_BOCX;\r
+    EDBPrint (L"BOCX on\n");\r
+  } else if (StriCmp (CommandArg, L"off") == 0) {\r
+    DebuggerPrivate->FeatureFlags &= ~EFI_DEBUG_FLAG_EBC_B_BOCX;\r
+    EDBPrint (L"BOCX off\n");\r
+  } else {\r
+    EDBPrint (L"BOCX - argument error\n");\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerBreakOnRET (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - BreakOnRET\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  //\r
+  // Check argument\r
+  //\r
+  if (CommandArg == NULL) {\r
+    if ((DebuggerPrivate->FeatureFlags & EFI_DEBUG_FLAG_EBC_BOR) == EFI_DEBUG_FLAG_EBC_BOR) {\r
+      EDBPrint (L"BOR on\n");\r
+    } else {\r
+      EDBPrint (L"BOR off\n");\r
+    }\r
+  } else if (StriCmp (CommandArg, L"on") == 0) {\r
+    DebuggerPrivate->FeatureFlags |= EFI_DEBUG_FLAG_EBC_BOR;\r
+    EDBPrint (L"BOR on\n");\r
+  } else if (StriCmp (CommandArg, L"off") == 0) {\r
+    DebuggerPrivate->FeatureFlags &= ~EFI_DEBUG_FLAG_EBC_B_BOR;\r
+    EDBPrint (L"BOR off\n");\r
+  } else {\r
+    EDBPrint (L"BOR - argument error\n");\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerBreakOnEntrypoint (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - BreakOnEntrypoint\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  //\r
+  // Check argument\r
+  //\r
+  if (CommandArg == NULL) {\r
+    if ((DebuggerPrivate->FeatureFlags & EFI_DEBUG_FLAG_EBC_BOE) == EFI_DEBUG_FLAG_EBC_BOE) {\r
+      EDBPrint (L"BOE on\n");\r
+    } else {\r
+      EDBPrint (L"BOE off\n");\r
+    }\r
+  } else if (StriCmp (CommandArg, L"on") == 0) {\r
+    DebuggerPrivate->FeatureFlags |= EFI_DEBUG_FLAG_EBC_BOE;\r
+    EDBPrint (L"BOE on\n");\r
+  } else if (StriCmp (CommandArg, L"off") == 0) {\r
+    DebuggerPrivate->FeatureFlags &= ~EFI_DEBUG_FLAG_EBC_B_BOE;\r
+    EDBPrint (L"BOE off\n");\r
+  } else {\r
+    EDBPrint (L"BOE - argument error\n");\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerBreakOnThunk (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - BreakOnThunk\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  //\r
+  // Check argument\r
+  //\r
+  if (CommandArg == NULL) {\r
+    if ((DebuggerPrivate->FeatureFlags & EFI_DEBUG_FLAG_EBC_BOT) == EFI_DEBUG_FLAG_EBC_BOT) {\r
+      EDBPrint (L"BOT on\n");\r
+    } else {\r
+      EDBPrint (L"BOT off\n");\r
+    }\r
+  } else if (StriCmp (CommandArg, L"on") == 0) {\r
+    DebuggerPrivate->FeatureFlags |= EFI_DEBUG_FLAG_EBC_BOT;\r
+    EDBPrint (L"BOT on\n");\r
+  } else if (StriCmp (CommandArg, L"off") == 0) {\r
+    DebuggerPrivate->FeatureFlags &= ~EFI_DEBUG_FLAG_EBC_B_BOT;\r
+    EDBPrint (L"BOT off\n");\r
+  } else {\r
+    EDBPrint (L"BOT - argument error\n");\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerBreakOnKey (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - BreakOnKey\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  //\r
+  // Check argument\r
+  //\r
+  if (CommandArg == NULL) {\r
+    if ((DebuggerPrivate->FeatureFlags & EFI_DEBUG_FLAG_EBC_BOK) == EFI_DEBUG_FLAG_EBC_BOK) {\r
+      EDBPrint (L"BOK on\n");\r
+    } else {\r
+      EDBPrint (L"BOK off\n");\r
+    }\r
+  } else if (StriCmp (CommandArg, L"on") == 0) {\r
+    DebuggerPrivate->FeatureFlags |= EFI_DEBUG_FLAG_EBC_BOK;\r
+    EDBPrint (L"BOK on\n");\r
+  } else if (StriCmp (CommandArg, L"off") == 0) {\r
+    DebuggerPrivate->FeatureFlags &= ~EFI_DEBUG_FLAG_EBC_B_BOK;\r
+    EDBPrint (L"BOK off\n");\r
+  } else {\r
+    EDBPrint (L"BOK - argument error\n");\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreakpoint.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdBreakpoint.c
new file mode 100644 (file)
index 0000000..4be6dd4
--- /dev/null
@@ -0,0 +1,614 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbCmdBreakpoint.c\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#include "Edb.h"\r
+\r
+BOOLEAN\r
+IsEBCBREAK3 (\r
+  IN UINTN            Address\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Check whether current IP is EBC BREAK3 instruction\r
+\r
+Arguments:\r
+\r
+  Address   - EBC IP address.\r
+\r
+Returns:\r
+\r
+  TRUE  - Current IP is EBC BREAK3 instruction\r
+  FALSE - Current IP is not EBC BREAK3 instruction\r
+\r
+--*/\r
+{\r
+  if (GET_OPCODE(Address) != OPCODE_BREAK) {\r
+    return FALSE;\r
+  }\r
+\r
+  if (GET_OPERANDS (Address) != 3) {\r
+    return FALSE;\r
+  } else {\r
+    return TRUE;\r
+  }\r
+}\r
+\r
+BOOLEAN\r
+DebuggerBreakpointIsDuplicated (\r
+  IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN UINTN                     Address\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Check whether the Address is already set in breakpoint\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  Address         - Breakpoint Address\r
+\r
+Returns:\r
+\r
+  TRUE          - breakpoint is found\r
+  FALSE         - breakpoint is not found\r
+\r
+--*/\r
+{\r
+  UINTN  Index;\r
+\r
+  //\r
+  // Go through each breakpoint context\r
+  //\r
+  for (Index = 0; Index < DebuggerPrivate->DebuggerBreakpointCount; Index++) {\r
+    if (DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress == Address) {\r
+      //\r
+      // Found it\r
+      //\r
+      return TRUE;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Not found\r
+  //\r
+  return FALSE;\r
+}\r
+\r
+EFI_STATUS\r
+DebuggerBreakpointAdd (\r
+  IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN UINTN                     Address\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Add this breakpoint\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  Address         - Breakpoint Address\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS          - breakpoint added successfully\r
+  EFI_ALREADY_STARTED  - breakpoint is already added\r
+  EFI_OUT_OF_RESOURCES - all the breakpoint entries are used\r
+\r
+--*/\r
+{\r
+  //\r
+  // Check duplicated breakpoint\r
+  //\r
+  if (DebuggerBreakpointIsDuplicated (DebuggerPrivate, Address)) {\r
+    EDBPrint (L"Breakpoint duplicated!\n");\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+\r
+  //\r
+  // Check whether the address is a breakpoint 3 instruction\r
+  //\r
+  if (IsEBCBREAK3 (Address)) {\r
+    EDBPrint (L"Breakpoint can not be set on BREAK 3 instruction!\n");\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+\r
+  if (DebuggerPrivate->DebuggerBreakpointCount >= EFI_DEBUGGER_BREAKPOINT_MAX) {\r
+    EDBPrint (L"Breakpoint out of resource!\n");\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\r
+  // Set the breakpoint\r
+  //\r
+  DebuggerPrivate->DebuggerBreakpointContext[DebuggerPrivate->DebuggerBreakpointCount].BreakpointAddress = Address;\r
+  DebuggerPrivate->DebuggerBreakpointContext[DebuggerPrivate->DebuggerBreakpointCount].State = TRUE;\r
+  DebuggerPrivate->DebuggerBreakpointContext[DebuggerPrivate->DebuggerBreakpointCount].OldInstruction = 0;\r
+  CopyMem (\r
+    &DebuggerPrivate->DebuggerBreakpointContext[DebuggerPrivate->DebuggerBreakpointCount].OldInstruction,\r
+    (VOID *)Address,\r
+    sizeof(UINT16)\r
+    );\r
+\r
+  DebuggerPrivate->DebuggerBreakpointCount ++;\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+DebuggerBreakpointDel (\r
+  IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN UINTN                     Index\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Delete this breakpoint\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  Index           - Breakpoint Index\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS   - breakpoint deleted successfully\r
+  EFI_NOT_FOUND - breakpoint not found\r
+\r
+--*/\r
+{\r
+  UINTN    BpIndex;\r
+\r
+  if ((Index >= EFI_DEBUGGER_BREAKPOINT_MAX) ||\r
+      (Index >= DebuggerPrivate->DebuggerBreakpointCount)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  //\r
+  // Delete this breakpoint\r
+  //\r
+  for (BpIndex = Index; BpIndex < DebuggerPrivate->DebuggerBreakpointCount - 1; BpIndex++) {\r
+    DebuggerPrivate->DebuggerBreakpointContext[BpIndex] = DebuggerPrivate->DebuggerBreakpointContext[BpIndex + 1];\r
+  }\r
+  ZeroMem (\r
+    &DebuggerPrivate->DebuggerBreakpointContext[BpIndex],\r
+    sizeof(DebuggerPrivate->DebuggerBreakpointContext[BpIndex])\r
+    );\r
+\r
+  DebuggerPrivate->DebuggerBreakpointCount --;\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+DebuggerBreakpointDis (\r
+  IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN UINTN                     Index\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disable this breakpoint\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  Index           - Breakpoint Index\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS   - breakpoint disabled successfully\r
+  EFI_NOT_FOUND - breakpoint not found\r
+\r
+--*/\r
+{\r
+  if ((Index >= EFI_DEBUGGER_BREAKPOINT_MAX) ||\r
+      (Index >= DebuggerPrivate->DebuggerBreakpointCount)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  //\r
+  // Disable this breakpoint\r
+  //\r
+  DebuggerPrivate->DebuggerBreakpointContext[Index].State = FALSE;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+DebuggerBreakpointEn (\r
+  IN EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN UINTN                     Index\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Enable this breakpoint\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  Index           - Breakpoint Index\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS   - breakpoint enabled successfully\r
+  EFI_NOT_FOUND - breakpoint not found\r
+\r
+--*/\r
+{\r
+  if ((Index >= EFI_DEBUGGER_BREAKPOINT_MAX) ||\r
+      (Index >= DebuggerPrivate->DebuggerBreakpointCount)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  //\r
+  // Enable this breakpoint\r
+  //\r
+  DebuggerPrivate->DebuggerBreakpointContext[Index].State = TRUE;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerBreakpointList (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - BreakpointList\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  UINTN Index;\r
+\r
+  //\r
+  // Check breakpoint cound\r
+  //\r
+  if (DebuggerPrivate->DebuggerBreakpointCount == 0) {\r
+    EDBPrint (L"No Breakpoint\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  } else if (DebuggerPrivate->DebuggerBreakpointCount > EFI_DEBUGGER_BREAKPOINT_MAX) {\r
+    EDBPrint (L"Breakpoint too many!\n");\r
+    DebuggerPrivate->DebuggerBreakpointCount = 0;\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // Go through each breakpoint\r
+  //\r
+  EDBPrint (L"Breakpoint :\n");\r
+  EDBPrint (L" Index   Address            Status\n");\r
+  EDBPrint (L"======= ================== ========\n");\r
+//EDBPrint (L"   1    0xFFFFFFFF00000000    *\n");\r
+//EDBPrint (L"  12    0x00000000FFFFFFFF\n");\r
+  for (Index = 0; Index < DebuggerPrivate->DebuggerBreakpointCount; Index++) {\r
+    //\r
+    // Print the breakpoint\r
+    //\r
+    EDBPrint (L"  %2d    0x%016lx", Index, DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress);\r
+    if (DebuggerPrivate->DebuggerBreakpointContext[Index].State) {\r
+      EDBPrint (L"    *\n");\r
+    } else {\r
+      EDBPrint (L"\n");\r
+    }\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerBreakpointSet (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - BreakpointSet\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  UINTN      Address;\r
+  EFI_STATUS Status;\r
+\r
+  if (CommandArg == NULL) {\r
+    EDBPrint (L"BreakpointSet Argument error!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // Get breakpoint address\r
+  //\r
+  Status = Symboltoi (CommandArg, &Address);\r
+  if (EFI_ERROR (Status)) {\r
+    if (Status == EFI_NOT_FOUND) {\r
+      Address = Xtoi(CommandArg);\r
+    } else {\r
+      //\r
+      // Something wrong, let Symboltoi print error info.\r
+      //\r
+      EDBPrint (L"Command Argument error!\n");\r
+      return EFI_DEBUG_CONTINUE;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Add breakpoint\r
+  //\r
+  Status = DebuggerBreakpointAdd (DebuggerPrivate, Address);\r
+  if (EFI_ERROR(Status)) {\r
+    EDBPrint (L"BreakpointSet error!\n");\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerBreakpointClear (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - BreakpointClear\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  UINTN      Index;\r
+  EFI_STATUS Status;\r
+  UINTN      Address;\r
+  UINT16     OldInstruction;\r
+\r
+  if (CommandArg == NULL) {\r
+    EDBPrint (L"BreakpointClear Argument error!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  if (StriCmp (CommandArg, L"*") == 0) {\r
+    //\r
+    // delete all breakpoint\r
+    //\r
+    DebuggerPrivate->DebuggerBreakpointCount = 0;\r
+    ZeroMem (DebuggerPrivate->DebuggerBreakpointContext, sizeof(DebuggerPrivate->DebuggerBreakpointContext));\r
+    EDBPrint (L"All the Breakpoint is cleared\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // Get breakpoint index\r
+  //\r
+  Index = Atoi(CommandArg);\r
+\r
+  if ((Index >= EFI_DEBUGGER_BREAKPOINT_MAX) ||\r
+      (Index >= DebuggerPrivate->DebuggerBreakpointCount)) {\r
+    EDBPrint (L"BreakpointClear error!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  } else {\r
+    Address = (UINTN)DebuggerPrivate->DebuggerBreakpointContext[Index].BreakpointAddress;\r
+    OldInstruction = (UINT16)DebuggerPrivate->DebuggerBreakpointContext[Index].OldInstruction;\r
+  }\r
+\r
+  //\r
+  // Delete breakpoint\r
+  //\r
+  Status = DebuggerBreakpointDel (DebuggerPrivate, Index);\r
+  if (EFI_ERROR(Status)) {\r
+    EDBPrint (L"BreakpointClear error!\n");\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerBreakpointDisable (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - BreakpointDisable\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  UINTN      Index;\r
+  EFI_STATUS Status;\r
+\r
+  if (CommandArg == NULL) {\r
+    EDBPrint (L"BreakpointDisable Argument error!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  if (StriCmp (CommandArg, L"*") == 0) {\r
+    //\r
+    // disable all breakpoint\r
+    //\r
+    for (Index = 0; Index < DebuggerPrivate->DebuggerBreakpointCount; Index++) {\r
+      Status = DebuggerBreakpointDis (DebuggerPrivate, Index);\r
+    }\r
+    EDBPrint (L"All the Breakpoint is disabled\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // Get breakpoint index\r
+  //\r
+  Index = Atoi(CommandArg);\r
+\r
+  //\r
+  // Disable breakpoint\r
+  //\r
+  Status = DebuggerBreakpointDis (DebuggerPrivate, Index);\r
+  if (EFI_ERROR(Status)) {\r
+    EDBPrint (L"BreakpointDisable error!\n");\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerBreakpointEnable (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - BreakpointEnable\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  UINTN      Index;\r
+  EFI_STATUS Status;\r
+\r
+  if (CommandArg == NULL) {\r
+    EDBPrint (L"BreakpointEnable Argument error!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  if (StriCmp (CommandArg, L"*") == 0) {\r
+    //\r
+    // enable all breakpoint\r
+    //\r
+    for (Index = 0; Index < DebuggerPrivate->DebuggerBreakpointCount; Index++) {\r
+      Status = DebuggerBreakpointEn (DebuggerPrivate, Index);\r
+    }\r
+    EDBPrint (L"All the Breakpoint is enabled\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // Get breakpoint index\r
+  //\r
+  Index = Atoi(CommandArg);\r
+\r
+  //\r
+  // Enable breakpoint\r
+  //\r
+  Status = DebuggerBreakpointEn (DebuggerPrivate, Index);\r
+  if (EFI_ERROR(Status)) {\r
+    EDBPrint (L"BreakpointEnable error!\n");\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdExtIo.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdExtIo.c
new file mode 100644 (file)
index 0000000..5a3fe57
--- /dev/null
@@ -0,0 +1,219 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbCmdExtIo.c\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#include "Edb.h"\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerExtIoIB (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - IB\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  EDBPrint (L"Unsupported\n");\r
+  //\r
+  // TBD\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerExtIoIW (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - IW\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  EDBPrint (L"Unsupported\n");\r
+  //\r
+  // TBD\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerExtIoID (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - ID\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  EDBPrint (L"Unsupported\n");\r
+  //\r
+  // TBD\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerExtIoOB (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - OB\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  EDBPrint (L"Unsupported\n");\r
+  //\r
+  // TBD\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerExtIoOW (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - OW\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  EDBPrint (L"Unsupported\n");\r
+  //\r
+  // TBD\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerExtIoOD (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - OD\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  EDBPrint (L"Unsupported\n");\r
+  //\r
+  // TBD\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdExtPci.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdExtPci.c
new file mode 100644 (file)
index 0000000..adb29f8
--- /dev/null
@@ -0,0 +1,186 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbCmdExtPci.c\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#include "Edb.h"\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerExtPciPCIL (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - PCIL\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  EDBPrint (L"Unsupported\n");\r
+  //\r
+  // TBD\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerExtPciPCID (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - PCID\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  EDBPrint (L"Unsupported\n");\r
+  //\r
+  // TBD\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerExtPciCFGB (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - CFGB\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  EDBPrint (L"Unsupported\n");\r
+  //\r
+  // TBD\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerExtPciCFGW (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - CFGW\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  EDBPrint (L"Unsupported\n");\r
+  //\r
+  // TBD\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerExtPciCFGD (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - CFGD\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  EDBPrint (L"Unsupported\n");\r
+  //\r
+  // TBD\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdGo.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdGo.c
new file mode 100644 (file)
index 0000000..d5dee8a
--- /dev/null
@@ -0,0 +1,93 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbCmdGo.c\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#include "Edb.h"\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerGo (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - Go\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_BREAK    - formal return value\r
+  EFI_DEBUG_CONTINUE - something wrong\r
+\r
+--*/\r
+{\r
+  UINTN        Address;\r
+  CHAR16       *CommandStr;\r
+  EFI_STATUS   Status;\r
+\r
+  //\r
+  // Check argument\r
+  //\r
+  if (CommandArg != NULL) {\r
+    if (StriCmp (CommandArg, L"til") == 0) {\r
+      CommandStr = StrGetNextTokenLine (L" ");\r
+      if (CommandStr != NULL) {\r
+        //\r
+        // Enable GoTil break now\r
+        // set BreakAddress, and set feature flag.\r
+        //\r
+        Status = Symboltoi (CommandStr, &Address);\r
+        if (EFI_ERROR (Status)) {\r
+          if (Status == EFI_NOT_FOUND) {\r
+            Address = Xtoi(CommandStr);\r
+          } else {\r
+            //\r
+            // Something wrong, let Symboltoi print error info.\r
+            //\r
+            EDBPrint (L"Command Argument error!\n");\r
+            return EFI_DEBUG_CONTINUE;\r
+          }\r
+        }\r
+        DebuggerPrivate->GoTilContext.BreakAddress = Address;\r
+        DebuggerPrivate->FeatureFlags |= EFI_DEBUG_FLAG_EBC_GT;\r
+      } else {\r
+        EDBPrint (L"Command Argument error!\n");\r
+        return EFI_DEBUG_CONTINUE;\r
+      }\r
+    } else {\r
+      EDBPrint (L"Command Argument error!\n");\r
+      return EFI_DEBUG_CONTINUE;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_BREAK;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdHelp.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdHelp.c
new file mode 100644 (file)
index 0000000..ae5acd7
--- /dev/null
@@ -0,0 +1,86 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbCmdHelp.c\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#include "Edb.h"\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerHelp (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - Help\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  UINTN Index;\r
+\r
+  //\r
+  // if no argument, print all the command title\r
+  //\r
+  if (CommandArg == NULL) {\r
+    for (Index = 0; DebuggerPrivate->DebuggerCommandSet[Index].CommandName != NULL; Index++) {\r
+      EDBPrint (DebuggerPrivate->DebuggerCommandSet[Index].ClassName);\r
+      if (StrCmp (DebuggerPrivate->DebuggerCommandSet[Index].CommandTitle, L"") != 0) {\r
+        EDBPrint (L"  ");\r
+        EDBPrint (DebuggerPrivate->DebuggerCommandSet[Index].CommandTitle);\r
+      }\r
+    }\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // If there is argument, the argument should be command name.\r
+  // Find the command and print the detail information.\r
+  //\r
+  for (Index = 0; DebuggerPrivate->DebuggerCommandSet[Index].CommandName != NULL; Index++) {\r
+    if (StriCmp (CommandArg, DebuggerPrivate->DebuggerCommandSet[Index].CommandName) == 0) {\r
+      EDBPrint (DebuggerPrivate->DebuggerCommandSet[Index].CommandHelp);\r
+      EDBPrint (DebuggerPrivate->DebuggerCommandSet[Index].CommandSyntax);\r
+      return EFI_DEBUG_CONTINUE;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Command not found.\r
+  //\r
+  EDBPrint (L"No help info for this command\n");\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdMemory.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdMemory.c
new file mode 100644 (file)
index 0000000..65b220a
--- /dev/null
@@ -0,0 +1,683 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbCmdMemory.c\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#include "Edb.h"\r
+\r
+UINTN\r
+EdbDisplayMemoryUnit (\r
+  IN UINTN           Address,\r
+  IN EDB_DATA_WIDTH  Width\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Display memory unit\r
+\r
+Arguments:\r
+\r
+  Address         - Memory Address\r
+  Width           - Memory Width\r
+\r
+Returns:\r
+\r
+  Length of the memory unit\r
+\r
+--*/\r
+{\r
+  UINT8  Data8;\r
+  UINT16 Data16;\r
+  UINT32 Data32;\r
+  UINT64 Data64;\r
+\r
+  //\r
+  // Print accroding to width\r
+  //\r
+  switch (Width) {\r
+  case EdbWidthUint8:\r
+    CopyMem (&Data8, (VOID *)Address, sizeof(UINT8));\r
+    EDBPrint (L"%02x ", Data8);\r
+    return sizeof(UINT8);\r
+  case EdbWidthUint16:\r
+    CopyMem (&Data16, (VOID *)Address, sizeof(UINT16));\r
+    EDBPrint (L"%04x ", Data16);\r
+    return sizeof(UINT16);\r
+  case EdbWidthUint32:\r
+    CopyMem (&Data32, (VOID *)Address, sizeof(UINT32));\r
+    EDBPrint (L"%08x ", Data32);\r
+    return sizeof(UINT32);\r
+  case EdbWidthUint64:\r
+    CopyMem (&Data64, (VOID *)Address, sizeof(UINT64));\r
+    EDBPrint (L"%016lx ", Data64);\r
+    return sizeof(UINT64);\r
+  default:\r
+    ASSERT (FALSE);\r
+    break;\r
+  }\r
+\r
+  //\r
+  // something wrong\r
+  //\r
+  return 0;\r
+}\r
+\r
+VOID\r
+EdbDisplayMemory (\r
+  IN UINTN          Address,\r
+  IN UINTN          Count,\r
+  IN EDB_DATA_WIDTH Width\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Display memory\r
+\r
+Arguments:\r
+\r
+  Address         - Memory Address\r
+  Count           - Memory Count\r
+  Width           - Memory Width\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  UINTN  LineNumber;\r
+  UINTN  ByteNumber;\r
+  UINTN  LineIndex;\r
+  UINTN  ByteIndex;\r
+  UINTN  NumberInLine;\r
+\r
+  if (Count == 0) {\r
+    return ;\r
+  }\r
+\r
+  //\r
+  // Get line number and byte number\r
+  //\r
+  switch (Width) {\r
+  case EdbWidthUint8:\r
+    NumberInLine = 16;\r
+    break;\r
+  case EdbWidthUint16:\r
+    NumberInLine = 8;\r
+    break;\r
+  case EdbWidthUint32:\r
+    NumberInLine = 4;\r
+    break;\r
+  case EdbWidthUint64:\r
+    NumberInLine = 2;\r
+    break;\r
+  default:\r
+    return;\r
+  }\r
+\r
+  LineNumber = Count / NumberInLine;\r
+  ByteNumber = Count % NumberInLine;\r
+  if (ByteNumber == 0) {\r
+    LineNumber -= 1;\r
+    ByteNumber  = NumberInLine;\r
+  }\r
+\r
+  //\r
+  // Print each line\r
+  //\r
+  for (LineIndex = 0; LineIndex < LineNumber; LineIndex++) {\r
+\r
+    //\r
+    // Break check\r
+    //\r
+    if (((LineIndex % EFI_DEBUGGER_LINE_NUMBER_IN_PAGE) == 0) &&\r
+        (LineIndex != 0)) {\r
+      if (SetPageBreak ()) {\r
+        break;\r
+      }\r
+    }\r
+\r
+    EDBPrint (EDB_PRINT_ADDRESS_FORMAT, (UINTN)Address);\r
+    for (ByteIndex = 0; ByteIndex < NumberInLine; ByteIndex++) {\r
+      Address += EdbDisplayMemoryUnit (Address, Width);\r
+    }\r
+    EDBPrint (L"\n");\r
+  }\r
+\r
+  //\r
+  // Break check\r
+  //\r
+  if (((LineIndex % EFI_DEBUGGER_LINE_NUMBER_IN_PAGE) == 0) &&\r
+      (LineIndex != 0)) {\r
+    if (SetPageBreak ()) {\r
+      return;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Print last line\r
+  //\r
+  EDBPrint (EDB_PRINT_ADDRESS_FORMAT, (UINTN)Address);\r
+  for (ByteIndex = 0; ByteIndex < ByteNumber; ByteIndex++) {\r
+    Address += EdbDisplayMemoryUnit (Address, Width);\r
+  }\r
+\r
+  return ;\r
+}\r
+\r
+VOID\r
+EdbEnterMemory (\r
+  IN UINTN          Address,\r
+  IN VOID           *Value,\r
+  IN EDB_DATA_WIDTH Width\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Entry memory\r
+\r
+Arguments:\r
+\r
+  Address         - Memory Address\r
+  Value           - Memory Value\r
+  Width           - Memory Width\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  switch (Width) {\r
+  case EdbWidthUint8:\r
+    CopyMem ((VOID *)Address, Value, sizeof(UINT8));\r
+    break;\r
+  case EdbWidthUint16:\r
+    CopyMem ((VOID *)Address, Value, sizeof(UINT16));\r
+    break;\r
+  case EdbWidthUint32:\r
+    CopyMem ((VOID *)Address, Value, sizeof(UINT32));\r
+    break;\r
+  case EdbWidthUint64:\r
+    CopyMem ((VOID *)Address, Value, sizeof(UINT64));\r
+    break;\r
+  default:\r
+    break;\r
+  }\r
+\r
+  return ;\r
+}\r
+\r
+EFI_STATUS\r
+EdbGetMemoryAddressCount (\r
+  IN CHAR16    *CommandArg,\r
+  IN UINTN     *Address,\r
+  IN UINTN     *Count\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Get memory address and count\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  Address         - Memory Address\r
+  Count           - Memory Count\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - memory address and count are got\r
+  EFI_INVALID_PARAMETER - something wrong\r
+\r
+--*/\r
+{\r
+  CHAR16       *CommandStr;\r
+  UINTN        MemAddress;\r
+  EFI_STATUS   Status;\r
+\r
+  //\r
+  // Get Address\r
+  //\r
+  CommandStr = CommandArg;\r
+  if (CommandStr == NULL) {\r
+    EDBPrint (L"Memory: Address error!\n");\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  Status = Symboltoi (CommandStr, &MemAddress);\r
+  if (EFI_ERROR (Status)) {\r
+    if (Status == EFI_NOT_FOUND) {\r
+      MemAddress = Xtoi(CommandStr);\r
+    } else {\r
+      //\r
+      // Something wrong, let Symboltoi print error info.\r
+      //\r
+      EDBPrint (L"Command Argument error!\n");\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+  *Address = MemAddress;\r
+\r
+  //\r
+  // Get Count\r
+  //\r
+  CommandStr = StrGetNextTokenLine (L" ");\r
+  if (CommandStr == NULL) {\r
+    *Count = 1;\r
+  } else {\r
+    *Count = Xtoi(CommandStr);\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EdbGetMemoryAddressValue (\r
+  IN CHAR16    *CommandArg,\r
+  IN UINTN     *Address,\r
+  IN UINT64    *Value\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Get memory address and value\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  Address         - Memory Address\r
+  Value           - Memory Value\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - memory address and value are got\r
+  EFI_INVALID_PARAMETER - something wrong\r
+\r
+--*/\r
+{\r
+  CHAR16       *CommandStr;\r
+  UINTN        MemAddress;\r
+  EFI_STATUS   Status;\r
+\r
+  //\r
+  // Get Address\r
+  //\r
+  CommandStr = CommandArg;\r
+  if (CommandStr == NULL) {\r
+    EDBPrint (L"Memory: Address error!\n");\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  Status = Symboltoi (CommandStr, &MemAddress);\r
+  if (EFI_ERROR (Status)) {\r
+    if (Status == EFI_NOT_FOUND) {\r
+      MemAddress = Xtoi(CommandStr);\r
+    } else {\r
+      //\r
+      // Something wrong, let Symboltoi print error info.\r
+      //\r
+      EDBPrint (L"Command Argument error!\n");\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+  *Address = MemAddress;\r
+\r
+  //\r
+  // Get Value\r
+  //\r
+  CommandStr = StrGetNextTokenLine (L" ");\r
+  if (CommandStr == NULL) {\r
+    EDBPrint (L"Memory: Value error!\n");\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  *Value = LXtoi(CommandStr);\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerMemoryDisplay (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EDB_DATA_WIDTH            Width\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Display memory\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  Width           - Memory Width\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_RETURN   - formal return value\r
+\r
+--*/\r
+{\r
+  EFI_STATUS Status;\r
+  UINTN      Address;\r
+  UINTN      Count;\r
+\r
+  //\r
+  // Get memory address and count\r
+  //\r
+  Status = EdbGetMemoryAddressCount (CommandArg, &Address, &Count);\r
+  if (EFI_ERROR(Status)) {\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // Display memory\r
+  //\r
+  EdbDisplayMemory (Address, Count, Width);\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerMemoryEnter (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EDB_DATA_WIDTH            Width\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Enter memory\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  Width           - Memory Width\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_RETURN   - formal return value\r
+\r
+--*/\r
+{\r
+  EFI_STATUS Status;\r
+  UINTN      Address;\r
+  UINT64     Value;\r
+\r
+  //\r
+  // Get memory address and value\r
+  //\r
+  Status = EdbGetMemoryAddressValue (CommandArg, &Address, &Value);\r
+  if (EFI_ERROR(Status)) {\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // Enter memory\r
+  //\r
+  EdbEnterMemory (Address, &Value, Width);\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerMemoryDB (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - DB\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_RETURN   - formal return value\r
+\r
+--*/\r
+{\r
+  return DebuggerMemoryDisplay (CommandArg, EdbWidthUint8);\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerMemoryDW (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - DW\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_RETURN   - formal return value\r
+\r
+--*/\r
+{\r
+  return DebuggerMemoryDisplay (CommandArg, EdbWidthUint16);\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerMemoryDD (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - DD\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_RETURN   - formal return value\r
+\r
+--*/\r
+{\r
+  return DebuggerMemoryDisplay (CommandArg, EdbWidthUint32);\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerMemoryDQ (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - DQ\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_RETURN   - formal return value\r
+\r
+--*/\r
+{\r
+  return DebuggerMemoryDisplay (CommandArg, EdbWidthUint64);\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerMemoryEB (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - EB\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_RETURN   - formal return value\r
+\r
+--*/\r
+{\r
+  return DebuggerMemoryEnter (CommandArg, EdbWidthUint8);\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerMemoryEW (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - EW\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_RETURN   - formal return value\r
+\r
+--*/\r
+{\r
+  return DebuggerMemoryEnter (CommandArg, EdbWidthUint16);\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerMemoryED (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - ED\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_RETURN   - formal return value\r
+\r
+--*/\r
+{\r
+  return DebuggerMemoryEnter (CommandArg, EdbWidthUint32);\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerMemoryEQ (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - EQ\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_RETURN   - formal return value\r
+\r
+--*/\r
+{\r
+  return DebuggerMemoryEnter (CommandArg, EdbWidthUint64);\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdQuit.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdQuit.c
new file mode 100644 (file)
index 0000000..d3a7a6d
--- /dev/null
@@ -0,0 +1,50 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbCmdQuit.c\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#include "Edb.h"\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerQuit (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - Quit\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_RETURN   - formal return value\r
+\r
+--*/\r
+{\r
+  return EFI_DEBUG_RETURN;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdRegister.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdRegister.c
new file mode 100644 (file)
index 0000000..3d9fdae
--- /dev/null
@@ -0,0 +1,136 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbCmdRegister.c\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#include "Edb.h"\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerRegister (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - Register\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  CHAR16  *RegName;\r
+  CHAR16  *RegValStr;\r
+  UINT64  RegVal;\r
+\r
+  //\r
+  // Check Argument, NULL means print all register\r
+  //\r
+  if (CommandArg == 0) {\r
+    EDBPrint (\r
+      L"  R0 - 0x%016lx, R1 - 0x%016lx\n",\r
+      SystemContext.SystemContextEbc->R0,\r
+      SystemContext.SystemContextEbc->R1\r
+      );\r
+    EDBPrint (\r
+      L"  R2 - 0x%016lx, R3 - 0x%016lx\n",\r
+      SystemContext.SystemContextEbc->R2,\r
+      SystemContext.SystemContextEbc->R3\r
+      );\r
+    EDBPrint (\r
+      L"  R4 - 0x%016lx, R5 - 0x%016lx\n",\r
+      SystemContext.SystemContextEbc->R4,\r
+      SystemContext.SystemContextEbc->R5\r
+      );\r
+    EDBPrint (\r
+      L"  R6 - 0x%016lx, R7 - 0x%016lx\n",\r
+      SystemContext.SystemContextEbc->R6,\r
+      SystemContext.SystemContextEbc->R7\r
+      );\r
+    EDBPrint (\r
+      L"  Flags - 0x%016lx, ControlFlags - 0x%016lx\n",\r
+      SystemContext.SystemContextEbc->Flags,\r
+      SystemContext.SystemContextEbc->ControlFlags\r
+      );\r
+    EDBPrint (\r
+      L"  Ip - 0x%016lx\n",\r
+      SystemContext.SystemContextEbc->Ip\r
+      );\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // Get register name\r
+  //\r
+  RegName = CommandArg;\r
+  //\r
+  // Get register value\r
+  //\r
+  RegValStr = StrGetNextTokenLine (L" ");\r
+  if (RegValStr == NULL) {\r
+    EDBPrint (L"Invalid Register Value\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+  RegVal = LXtoi (RegValStr);\r
+\r
+  //\r
+  // Assign register value\r
+  //\r
+  if (StriCmp (RegName, L"R0") == 0) {\r
+    SystemContext.SystemContextEbc->R0 = RegVal;\r
+  } else if (StriCmp (RegName, L"R1") == 0) {\r
+    SystemContext.SystemContextEbc->R1 = RegVal;\r
+  } else if (StriCmp (RegName, L"R2") == 0) {\r
+    SystemContext.SystemContextEbc->R2 = RegVal;\r
+  } else if (StriCmp (RegName, L"R3") == 0) {\r
+    SystemContext.SystemContextEbc->R3 = RegVal;\r
+  } else if (StriCmp (RegName, L"R4") == 0) {\r
+    SystemContext.SystemContextEbc->R4 = RegVal;\r
+  } else if (StriCmp (RegName, L"R5") == 0) {\r
+    SystemContext.SystemContextEbc->R5 = RegVal;\r
+  } else if (StriCmp (RegName, L"R6") == 0) {\r
+    SystemContext.SystemContextEbc->R6 = RegVal;\r
+  } else if (StriCmp (RegName, L"R7") == 0) {\r
+    SystemContext.SystemContextEbc->R7 = RegVal;\r
+  } else if (StriCmp (RegName, L"Flags") == 0) {\r
+    SystemContext.SystemContextEbc->Flags = RegVal;\r
+  } else if (StriCmp (RegName, L"ControlFlags") == 0) {\r
+    SystemContext.SystemContextEbc->ControlFlags = RegVal;\r
+  } else if (StriCmp (RegName, L"Ip") == 0) {\r
+    SystemContext.SystemContextEbc->Ip = RegVal;\r
+  } else {\r
+    EDBPrint (L"Invalid Register - %s\n", RegName);\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdScope.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdScope.c
new file mode 100644 (file)
index 0000000..9b62c52
--- /dev/null
@@ -0,0 +1,123 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbCmdScope.c\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#include "Edb.h"\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerScope (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - Scope\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  EFI_STATUS   Status;\r
+  UINTN        Address;\r
+\r
+  if (CommandArg == NULL) {\r
+    EDBPrint (L"Scope: invalid Address\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // Load new scope\r
+  //\r
+  Status = Symboltoi (CommandArg, &Address);\r
+  if (EFI_ERROR (Status)) {\r
+    if (Status == EFI_NOT_FOUND) {\r
+      Address = Xtoi(CommandArg);\r
+    } else {\r
+      //\r
+      // Something wrong, let Symboltoi print error info.\r
+      //\r
+      EDBPrint (L"Command Argument error!\n");\r
+      return EFI_DEBUG_CONTINUE;\r
+    }\r
+  }\r
+  DebuggerPrivate->InstructionScope = Address;\r
+  EDBPrint (L"Scope: 0x%x\n", DebuggerPrivate->InstructionScope);\r
+  EdbShowDisasm (DebuggerPrivate, SystemContext);\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerList (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - List\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  if (CommandArg == NULL) {\r
+    EdbShowDisasm (DebuggerPrivate, SystemContext);\r
+  } else {\r
+    //\r
+    // Load new list number\r
+    //\r
+    DebuggerPrivate->InstructionNumber = Atoi(CommandArg);\r
+    EDBPrint (L"List Number: %d\n", DebuggerPrivate->InstructionNumber);\r
+    EdbShowDisasm (DebuggerPrivate, SystemContext);\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdStep.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdStep.c
new file mode 100644 (file)
index 0000000..186c88d
--- /dev/null
@@ -0,0 +1,198 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbCmdStep.c\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#include "Edb.h"\r
+\r
+BOOLEAN\r
+IsEBCCALL (\r
+  IN UINTN            Address\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Check whether current IP is EBC CALL instruction (NOTE: CALLEX is exclusive)\r
+\r
+Arguments:\r
+\r
+  Address   - EBC IP address.\r
+\r
+Returns:\r
+\r
+  TRUE  - Current IP is EBC CALL instruction\r
+  FALSE - Current IP is not EBC CALL instruction\r
+\r
+--*/\r
+{\r
+  if (GET_OPCODE(Address) != OPCODE_CALL) {\r
+    return FALSE;\r
+  }\r
+\r
+  if (GET_OPERANDS (Address) & OPERAND_M_NATIVE_CALL) {\r
+    return FALSE;\r
+  } else {\r
+    return TRUE;\r
+  }\r
+}\r
+\r
+BOOLEAN\r
+IsEBCRET (\r
+  IN UINTN            Address\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Check whether current IP is EBC RET instruction\r
+\r
+Arguments:\r
+\r
+  Address   - EBC IP address.\r
+\r
+Returns:\r
+\r
+  TRUE  - Current IP is EBC RET instruction\r
+  FALSE - Current IP is not EBC RET instruction\r
+\r
+--*/\r
+{\r
+  if (GET_OPCODE(Address) != OPCODE_RET) {\r
+    return FALSE;\r
+  }\r
+\r
+  if (GET_OPERANDS (Address) != 0) {\r
+    return FALSE;\r
+  } else {\r
+    return TRUE;\r
+  }\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerStepInto (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - StepInto\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  SystemContext.SystemContextEbc->Flags |= VMFLAGS_STEP;\r
+\r
+  return EFI_DEBUG_BREAK;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerStepOver (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - StepOver\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  if (IsEBCCALL((UINTN)SystemContext.SystemContextEbc->Ip)) {\r
+    //\r
+    // Check CALL (NOTE: CALLEX is exclusive)\r
+    //\r
+    DebuggerPrivate->FeatureFlags |= EFI_DEBUG_FLAG_EBC_STEPOVER;\r
+  } else {\r
+    //\r
+    // Other instruction including CALLEX\r
+    //\r
+    SystemContext.SystemContextEbc->Flags |= VMFLAGS_STEP;\r
+  }\r
+\r
+  return EFI_DEBUG_BREAK;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerStepOut (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - StepOut\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  if (IsEBCRET((UINTN)SystemContext.SystemContextEbc->Ip)) {\r
+    //\r
+    // Check RET\r
+    //\r
+    SystemContext.SystemContextEbc->Flags |= VMFLAGS_STEP;\r
+  } else {\r
+    //\r
+    // Other instruction\r
+    //\r
+    DebuggerPrivate->FeatureFlags |= EFI_DEBUG_FLAG_EBC_STEPOUT;\r
+  }\r
+\r
+  return EFI_DEBUG_BREAK;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdSymbol.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdSymbol.c
new file mode 100644 (file)
index 0000000..329a642
--- /dev/null
@@ -0,0 +1,952 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbCmdSymbol.c\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#include "Edb.h"\r
+\r
+CHAR16 *\r
+GetFileNameFromFullPath (\r
+  IN CHAR16   *FullPath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Get file name from full path\r
+\r
+Arguments:\r
+\r
+  FullPath        - full file path\r
+\r
+Returns:\r
+\r
+  file name\r
+\r
+--*/\r
+{\r
+  CHAR16   *FileName;\r
+  CHAR16   *TempFileName;\r
+\r
+  FileName = FullPath;\r
+  TempFileName = StrGetNewTokenLine (FullPath, L"\\");\r
+\r
+  while (TempFileName != NULL) {\r
+    FileName = TempFileName;\r
+    TempFileName = StrGetNextTokenLine (L"\\");\r
+    PatchForStrTokenBefore (TempFileName, L'\\');\r
+  }\r
+\r
+  return FileName;\r
+}\r
+\r
+CHAR16 *\r
+GetDirNameFromFullPath (\r
+  IN CHAR16   *FullPath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Get dir name from full path\r
+\r
+Arguments:\r
+\r
+  FullPath        - full file path\r
+\r
+Returns:\r
+\r
+  dir name\r
+\r
+--*/\r
+{\r
+  CHAR16   *FileName;\r
+\r
+  FileName = GetFileNameFromFullPath (FullPath);\r
+  if (FileName != FullPath) {\r
+    *(FileName - 1) = 0;\r
+    return FullPath;\r
+  }\r
+\r
+  return L"";\r
+}\r
+\r
+CHAR16 *\r
+ConstructFullPath (\r
+  IN CHAR16   *DirPath,\r
+  IN CHAR16   *FilePath,\r
+  IN UINTN    Size\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Construct full path accroding to dir and file path\r
+\r
+Arguments:\r
+\r
+  DirPath         - dir path\r
+  FilePath        - file path\r
+  Size            - dir max size\r
+\r
+Returns:\r
+\r
+  Full file name\r
+\r
+--*/\r
+{\r
+  UINTN DirPathSize;\r
+\r
+  DirPathSize = StrLen(DirPath);\r
+  *(DirPath + DirPathSize) = L'\\';\r
+  StrnCatS (DirPath, DirPathSize + Size + 1, FilePath, Size);\r
+\r
+  *(DirPath + DirPathSize + Size + 1) = 0;\r
+\r
+  return DirPath;\r
+}\r
+\r
+CHAR16 *mSymbolTypeStr[] = {\r
+  L"( F)",\r
+  L"(SF)",\r
+  L"(GV)",\r
+  L"(SV)",\r
+};\r
+\r
+CHAR16 *\r
+EdbSymbolTypeToStr (\r
+  IN EFI_DEBUGGER_SYMBOL_TYPE  Type\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Comvert Symbol Type to string\r
+\r
+Arguments:\r
+\r
+  Type            - Symbol Type\r
+\r
+Returns:\r
+\r
+  String\r
+\r
+--*/\r
+{\r
+  if (Type < 0 || Type >= EfiDebuggerSymbolTypeMax) {\r
+    return L"(?)";\r
+  }\r
+\r
+  return mSymbolTypeStr [Type];\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerDisplaySymbolAccrodingToAddress (\r
+  IN     UINTN                      Address,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Find the symbol accroding to address and display symbol\r
+\r
+Arguments:\r
+\r
+  Address         - SymbolAddress\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  EFI_DEBUGGER_SYMBOL_OBJECT *Object;\r
+  EFI_DEBUGGER_SYMBOL_ENTRY  *Entry;\r
+  UINTN                      CandidateAddress;\r
+\r
+  //\r
+  // Find the nearest symbol address\r
+  //\r
+  CandidateAddress = EbdFindSymbolAddress (Address, EdbMatchSymbolTypeNearestAddress, &Object, &Entry);\r
+  if (CandidateAddress == 0) {\r
+    EDBPrint (L"Symbole at Address not found!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  } else if (Address != CandidateAddress) {\r
+    EDBPrint (L"Symbole at Address not found, print nearest one!\n");\r
+  }\r
+\r
+  //\r
+  // Display symbol\r
+  //\r
+  EDBPrint (L"Symbol File Name: %s\n", Object->Name);\r
+  if (sizeof(UINTN) == sizeof(UINT64)) {\r
+    EDBPrint (L"        Address      Type  Symbol\n");\r
+    EDBPrint (L"  ================== ==== ========\n");\r
+//  EDBPrint (L"  0xFFFFFFFF00000000 ( F) TestMain\n");\r
+    EDBPrint (\r
+      L"  0x%016lx %s %a\n",\r
+      (UINT64)Entry->RVA + Object->BaseAddress,\r
+      EdbSymbolTypeToStr (Entry->Type),\r
+      Entry->Name\r
+      );\r
+  } else {\r
+    EDBPrint (L"   Address   Type  Symbol\n");\r
+    EDBPrint (L"  ========== ==== ========\n");\r
+//  EDBPrint (L"  0xFFFF0000 ( F) TestMain\n");\r
+    EDBPrint (\r
+      L"  0x%08x %s %a\n",\r
+      Entry->RVA + Object->BaseAddress,\r
+      EdbSymbolTypeToStr (Entry->Type),\r
+      Entry->Name\r
+      );\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerDisplaySymbolAccrodingToName (\r
+  IN     CHAR16                     *SymbolFileName,\r
+  IN     CHAR16                     *SymbolName,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Find the symbol accroding to name and display symbol\r
+\r
+Arguments:\r
+\r
+  SymbolFileName  - The Symbol File Name, NULL means for all\r
+  SymbolName      - The Symbol Name, NULL means for all\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  UINTN                      Index;\r
+  UINTN                      SubIndex;\r
+  EFI_DEBUGGER_SYMBOL_OBJECT *Object;\r
+  EFI_DEBUGGER_SYMBOL_ENTRY  *Entry;\r
+\r
+  if (DebuggerPrivate->DebuggerSymbolContext.ObjectCount == 0) {\r
+    EDBPrint (L"No Symbol File!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // Go throuth each symbol file\r
+  //\r
+  Object = DebuggerPrivate->DebuggerSymbolContext.Object;\r
+  for (Index = 0; Index < DebuggerPrivate->DebuggerSymbolContext.ObjectCount; Index++, Object++) {\r
+    if ((SymbolFileName != NULL) &&\r
+        (StriCmp (SymbolFileName, Object->Name) != 0)) {\r
+      continue;\r
+    }\r
+\r
+    //\r
+    // Break each symbol file\r
+    //\r
+    if (Index != 0) {\r
+      if (SetPageBreak ()) {\r
+        break;\r
+      }\r
+    }\r
+\r
+    EDBPrint (L"Symbol File Name: %s\n", Object->Name);\r
+    if (Object->EntryCount == 0) {\r
+      EDBPrint (L"No Symbol!\n");\r
+      continue;\r
+    }\r
+    Entry = Object->Entry;\r
+    if (sizeof(UINTN) == sizeof(UINT64)) {\r
+      EDBPrint (L"        Address      Type  Symbol\n");\r
+      EDBPrint (L"  ================== ==== ========\n");\r
+//    EDBPrint (L"  0xFFFFFFFF00000000 ( F) TestMain (EbcTest.obj)\n");\r
+    } else {\r
+      EDBPrint (L"   Address   Type  Symbol\n");\r
+      EDBPrint (L"  ========== ==== ========\n");\r
+//    EDBPrint (L"  0xFFFF0000 ( F) TestMain (EbcTest.obj)\n");\r
+    }\r
+\r
+    //\r
+    // Go through each symbol name\r
+    //\r
+    for (SubIndex = 0; SubIndex < Object->EntryCount; SubIndex++, Entry++) {\r
+      if ((SymbolName != NULL) &&\r
+          (StrCmpUnicodeAndAscii (SymbolName, Entry->Name) != 0)) {\r
+        continue;\r
+      }\r
+\r
+      //\r
+      // Break symbol\r
+      //\r
+      if (((SubIndex % EFI_DEBUGGER_LINE_NUMBER_IN_PAGE) == 0) &&\r
+          (SubIndex != 0)) {\r
+        if (SetPageBreak ()) {\r
+          break;\r
+        }\r
+      }\r
+\r
+      if (sizeof(UINTN) == sizeof(UINT64)) {\r
+        EDBPrint (\r
+          L"  0x%016lx %s %a (%a)\n",\r
+          (UINT64)Entry->RVA + Object->BaseAddress,\r
+          EdbSymbolTypeToStr (Entry->Type),\r
+          Entry->Name,\r
+          Entry->ObjName\r
+          );\r
+      } else {\r
+        EDBPrint (\r
+          L"  0x%08x %s %a (%a)\n",\r
+          Entry->RVA + Object->BaseAddress,\r
+          EdbSymbolTypeToStr (Entry->Type),\r
+          Entry->Name,\r
+          Entry->ObjName\r
+          );\r
+      }\r
+    }\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerListSymbol (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - ListSymbol\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  CHAR16                     *SymbolFileName;\r
+  CHAR16                     *SymbolName;\r
+  CHAR16                     *CommandStr;\r
+  UINTN                      Address;\r
+\r
+  SymbolFileName = NULL;\r
+  SymbolName = NULL;\r
+  CommandStr = CommandArg;\r
+\r
+  //\r
+  // display symbol according to address\r
+  //\r
+  if (CommandStr != NULL) {\r
+    if ((StriCmp (CommandStr, L"F") != 0) &&\r
+        (StriCmp (CommandStr, L"S") != 0)) {\r
+      Address = Xtoi (CommandStr);\r
+      return DebuggerDisplaySymbolAccrodingToAddress (Address, DebuggerPrivate);\r
+    }\r
+  }\r
+\r
+  //\r
+  // Get SymbolFileName\r
+  //\r
+  if (CommandStr != NULL) {\r
+    if (StriCmp (CommandStr, L"F") == 0) {\r
+      CommandStr = StrGetNextTokenLine (L" ");\r
+      if (CommandStr == NULL) {\r
+        EDBPrint (L"Symbol File Name missing!\n");\r
+        return EFI_DEBUG_CONTINUE;\r
+      } else {\r
+        SymbolFileName = CommandStr;\r
+        CommandStr = StrGetNextTokenLine (L" ");\r
+      }\r
+    }\r
+  }\r
+  //\r
+  // Get SymbolName\r
+  //\r
+  if (CommandStr != NULL) {\r
+    if (StriCmp (CommandStr, L"S") == 0) {\r
+      CommandStr = StrGetNextTokenLine (L" ");\r
+      if (CommandStr == NULL) {\r
+        EDBPrint (L"Symbol Name missing!\n");\r
+        return EFI_DEBUG_CONTINUE;\r
+      } else {\r
+        SymbolName = CommandStr;\r
+        CommandStr = StrGetNextTokenLine (L" ");\r
+      }\r
+    }\r
+  }\r
+  if (CommandStr != NULL) {\r
+    EDBPrint (L"Argument error!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // display symbol according to name\r
+  //\r
+  return DebuggerDisplaySymbolAccrodingToName (SymbolFileName, SymbolName, DebuggerPrivate);\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerLoadSymbol (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - LoadSymbol\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  UINTN      BufferSize;\r
+  VOID       *Buffer;\r
+  EFI_STATUS Status;\r
+  CHAR16     *FileName;\r
+  CHAR16     *CommandArg2;\r
+  BOOLEAN    IsLoadCode;\r
+  CHAR16     *DirName;\r
+  CHAR16     CodFile[EFI_DEBUGGER_SYMBOL_NAME_MAX];\r
+  CHAR16     *CodFileName;\r
+  UINTN      Index;\r
+\r
+  //\r
+  // Check the argument\r
+  //\r
+  if (CommandArg == NULL) {\r
+    EDBPrint (L"SymbolFile not found!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+  IsLoadCode = FALSE;\r
+  CommandArg2 = StrGetNextTokenLine (L" ");\r
+  if (CommandArg2 != NULL) {\r
+    if (StriCmp (CommandArg2, L"a") == 0) {\r
+      IsLoadCode = TRUE;\r
+    } else {\r
+      EDBPrint (L"Argument error!\n");\r
+      return EFI_DEBUG_CONTINUE;\r
+    }\r
+  }\r
+\r
+  if (StrLen (CommandArg) <= 4) {\r
+    EDBPrint (L"SymbolFile name error!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+  if (StriCmp (CommandArg + (StrLen (CommandArg) - 4), L".map") != 0) {\r
+    EDBPrint (L"SymbolFile name error!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // Read MAP file to memory\r
+  //\r
+  Status = ReadFileToBuffer (DebuggerPrivate, CommandArg, &BufferSize, &Buffer, TRUE);\r
+  if (EFI_ERROR(Status)) {\r
+    EDBPrint (L"SymbolFile read error!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  FileName = GetFileNameFromFullPath (CommandArg);\r
+  //\r
+  // Load Symbol\r
+  //\r
+  Status = EdbLoadSymbol (DebuggerPrivate, FileName, BufferSize, Buffer);\r
+  if (EFI_ERROR(Status)) {\r
+    EDBPrint (L"LoadSymbol error!\n");\r
+    gBS->FreePool (Buffer);\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+  gBS->FreePool (Buffer);\r
+\r
+  //\r
+  // Patch Symbol for RVA\r
+  //\r
+  Status = EdbPatchSymbolRVA (DebuggerPrivate, FileName, EdbEbcImageRvaSearchTypeLast);\r
+  if (EFI_ERROR(Status)) {\r
+    EDBPrint (L"PatchSymbol RVA  - %r! Using the RVA in symbol file.\n", Status);\r
+  } else {\r
+    DEBUG ((DEBUG_ERROR, "PatchSymbol RVA successfully!\n"));\r
+  }\r
+\r
+  if (!IsLoadCode) {\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // load each cod file\r
+  //\r
+  DirName = GetDirNameFromFullPath (CommandArg);\r
+  ZeroMem (CodFile, sizeof(CodFile));\r
+  if (StrCmp (DirName, L"") != 0) {\r
+    StrCpyS (CodFile, sizeof(CodFile), DirName);\r
+  } else {\r
+    DirName = L"\\";\r
+  }\r
+\r
+  //\r
+  // Go throuth each file under this dir\r
+  //\r
+  Index = 0;\r
+  CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);\r
+  while (CodFileName != NULL) {\r
+    ZeroMem (CodFile, sizeof(CodFile));\r
+    if (StrCmp (DirName, L"\\") != 0) {\r
+      StrCpyS (CodFile, sizeof(CodFile), DirName);\r
+    }\r
+\r
+    //\r
+    // read cod file to memory\r
+    //\r
+    Status = ReadFileToBuffer (DebuggerPrivate, ConstructFullPath (CodFile, CodFileName, EFI_DEBUGGER_SYMBOL_NAME_MAX - StrLen (CodFile) - 2), &BufferSize, &Buffer, FALSE);\r
+    if (EFI_ERROR(Status)) {\r
+      EDBPrint (L"CodeFile read error!\n");\r
+      CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);\r
+      continue;\r
+    }\r
+\r
+    //\r
+    // Load Code\r
+    //\r
+    Status = EdbLoadCode (DebuggerPrivate, FileName, CodFileName, BufferSize, Buffer);\r
+    if (EFI_ERROR (Status)) {\r
+      EDBPrint (L"LoadCode error!\n");\r
+      gBS->FreePool (Buffer);\r
+      CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);\r
+      continue;\r
+    }\r
+\r
+    //\r
+    // Record the buffer\r
+    //\r
+    Status = EdbAddCodeBuffer (DebuggerPrivate, FileName, CodFileName, BufferSize, Buffer);\r
+    if (EFI_ERROR (Status)) {\r
+      EDBPrint (L"AddCodeBuffer error!\n");\r
+      gBS->FreePool (Buffer);\r
+      CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);\r
+      continue;\r
+    }\r
+\r
+    //\r
+    // Get next file\r
+    //\r
+    CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerUnloadSymbol (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - UnloadSymbol\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  EFI_STATUS Status;\r
+  CHAR16     *FileName;\r
+  CHAR16     *DirName;\r
+  CHAR16     CodFile[EFI_DEBUGGER_SYMBOL_NAME_MAX];\r
+  CHAR16     *CodFileName;\r
+  UINTN      Index;\r
+  VOID       *BufferPtr;\r
+\r
+  //\r
+  // Check the argument\r
+  //\r
+  if (CommandArg == NULL) {\r
+    EDBPrint (L"SymbolFile not found!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  FileName = GetFileNameFromFullPath (CommandArg);\r
+\r
+  //\r
+  // Unload Code\r
+  //\r
+  DirName = GetDirNameFromFullPath (CommandArg);\r
+  ZeroMem (CodFile, sizeof(CodFile));\r
+  if (StrCmp (DirName, L"") != 0) {\r
+    StrCpyS (CodFile, sizeof(CodFile), DirName);\r
+  } else {\r
+    DirName = L"\\";\r
+  }\r
+\r
+  //\r
+  // Go through each file under this dir\r
+  //\r
+  Index = 0;\r
+  CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);\r
+  while (CodFileName != NULL) {\r
+    ZeroMem (CodFile, sizeof(CodFile));\r
+    if (StrCmp (DirName, L"\\") != 0) {\r
+      StrCpyS (CodFile, sizeof(CodFile), DirName);\r
+    }\r
+\r
+    //\r
+    // Unload Code\r
+    //\r
+    Status = EdbUnloadCode (DebuggerPrivate, FileName, CodFileName, &BufferPtr);\r
+    if (EFI_ERROR (Status)) {\r
+      EDBPrint (L"UnloadCode error!\n");\r
+      CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);\r
+      continue;\r
+    }\r
+\r
+    //\r
+    // Delete the code buffer\r
+    //\r
+    Status = EdbDeleteCodeBuffer (DebuggerPrivate, FileName, CodFileName, BufferPtr);\r
+    if (EFI_ERROR (Status)) {\r
+      EDBPrint (L"DeleteCodeBuffer error!\n");\r
+      CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);\r
+      continue;\r
+    }\r
+\r
+    //\r
+    // Get next file\r
+    //\r
+    CodFileName = GetFileNameUnderDir (DebuggerPrivate, DirName, L".cod", &Index);\r
+  }\r
+\r
+  //\r
+  // Unload Symbol\r
+  //\r
+  Status = EdbUnloadSymbol (DebuggerPrivate, FileName);\r
+  if (EFI_ERROR(Status)) {\r
+    EDBPrint (L"UnloadSymbol error!\n");\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerDisplaySymbol (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - DisplaySymbol\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  if (CommandArg == NULL) {\r
+    DebuggerPrivate->DebuggerSymbolContext.DisplaySymbol = !DebuggerPrivate->DebuggerSymbolContext.DisplaySymbol;\r
+    EdbShowDisasm (DebuggerPrivate, SystemContext);\r
+  } else if (StriCmp (CommandArg, L"on") == 0) {\r
+    DebuggerPrivate->DebuggerSymbolContext.DisplaySymbol = TRUE;\r
+    EdbShowDisasm (DebuggerPrivate, SystemContext);\r
+  } else if (StriCmp (CommandArg, L"off") == 0) {\r
+    DebuggerPrivate->DebuggerSymbolContext.DisplaySymbol = FALSE;\r
+    EdbShowDisasm (DebuggerPrivate, SystemContext);\r
+  } else {\r
+    EDBPrint (L"DisplaySymbol - argument error\n");\r
+  }\r
+\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerLoadCode (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - LoadCode\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  UINTN      BufferSize;\r
+  VOID       *Buffer;\r
+  EFI_STATUS Status;\r
+  CHAR16     *CommandArg2;\r
+  CHAR16     *FileName;\r
+  CHAR16     *MapFileName;\r
+\r
+  //\r
+  // Check the argument\r
+  //\r
+  if (CommandArg == NULL) {\r
+    EDBPrint (L"CodeFile not found!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+  CommandArg2 = StrGetNextTokenLine (L" ");\r
+  if (CommandArg2 == NULL) {\r
+    EDBPrint (L"SymbolFile not found!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  if (StrLen (CommandArg) <= 4) {\r
+    EDBPrint (L"CodeFile name error!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+  if (StriCmp (CommandArg + (StrLen (CommandArg) - 4), L".cod") != 0) {\r
+    EDBPrint (L"CodeFile name error!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+  if (StrLen (CommandArg2) <= 4) {\r
+    EDBPrint (L"SymbolFile name error!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+  if (StriCmp (CommandArg2 + (StrLen (CommandArg2) - 4), L".map") != 0) {\r
+    EDBPrint (L"SymbolFile name error!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // read cod file to memory\r
+  //\r
+  Status = ReadFileToBuffer (DebuggerPrivate, CommandArg, &BufferSize, &Buffer, TRUE);\r
+  if (EFI_ERROR(Status)) {\r
+    EDBPrint (L"CodeFile read error!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  FileName = GetFileNameFromFullPath (CommandArg);\r
+  MapFileName = GetFileNameFromFullPath (CommandArg2);\r
+  //\r
+  // Load Code\r
+  //\r
+  Status = EdbLoadCode (DebuggerPrivate, MapFileName, FileName, BufferSize, Buffer);\r
+  if (EFI_ERROR (Status)) {\r
+    EDBPrint (L"LoadCode error!\n");\r
+    gBS->FreePool (Buffer);\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // Record the buffer\r
+  //\r
+  Status = EdbAddCodeBuffer (DebuggerPrivate, MapFileName, FileName, BufferSize, Buffer);\r
+  if (EFI_ERROR (Status)) {\r
+    EDBPrint (L"AddCodeBuffer error!\n");\r
+    gBS->FreePool (Buffer);\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerUnloadCode (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - UnloadCode\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  CHAR16     *CommandArg2;\r
+  CHAR16     *FileName;\r
+  CHAR16     *MapFileName;\r
+  EFI_STATUS Status;\r
+  VOID       *BufferPtr;\r
+\r
+  //\r
+  // Check the argument\r
+  //\r
+  if (CommandArg == NULL) {\r
+    EDBPrint (L"CodeFile not found!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+  CommandArg2 = StrGetNextTokenLine (L" ");\r
+  if (CommandArg2 == NULL) {\r
+    EDBPrint (L"SymbolFile not found!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  FileName = GetFileNameFromFullPath (CommandArg);\r
+  MapFileName = GetFileNameFromFullPath (CommandArg2);\r
+\r
+  //\r
+  // Unload Code\r
+  //\r
+  Status = EdbUnloadCode (DebuggerPrivate, MapFileName, FileName, &BufferPtr);\r
+  if (EFI_ERROR (Status)) {\r
+    EDBPrint (L"UnloadCode error!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // Delete Code buffer\r
+  //\r
+  Status = EdbDeleteCodeBuffer (DebuggerPrivate, MapFileName, FileName, BufferPtr);\r
+  if (EFI_ERROR (Status)) {\r
+    EDBPrint (L"DeleteCodeBuffer error!\n");\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
+\r
+EFI_DEBUG_STATUS\r
+DebuggerDisplayCode (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  DebuggerCommand - DisplayCode\r
+\r
+Arguments:\r
+\r
+  CommandArg      - The argument for this command\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  InterruptType   - Interrupt type.\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_DEBUG_CONTINUE - formal return value\r
+\r
+--*/\r
+{\r
+  if (CommandArg == NULL) {\r
+    DebuggerPrivate->DebuggerSymbolContext.DisplayCodeOnly = !DebuggerPrivate->DebuggerSymbolContext.DisplayCodeOnly;\r
+    EdbShowDisasm (DebuggerPrivate, SystemContext);\r
+  } else if (StriCmp (CommandArg, L"on") == 0) {\r
+    DebuggerPrivate->DebuggerSymbolContext.DisplayCodeOnly = TRUE;\r
+    EdbShowDisasm (DebuggerPrivate, SystemContext);\r
+  } else if (StriCmp (CommandArg, L"off") == 0) {\r
+    DebuggerPrivate->DebuggerSymbolContext.DisplayCodeOnly = FALSE;\r
+    EdbShowDisasm (DebuggerPrivate, SystemContext);\r
+  } else {\r
+    EDBPrint (L"DisplayCode - argument error\n");\r
+  }\r
+\r
+  return EFI_DEBUG_CONTINUE;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCommand.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCommand.c
new file mode 100644 (file)
index 0000000..b72e2bf
--- /dev/null
@@ -0,0 +1,680 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbCommand.c\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#include "Edb.h"\r
+\r
+//\r
+// Debugger Command Table\r
+//\r
+EFI_DEBUGGER_COMMAND_SET  mDebuggerCommandSet[] = {\r
+  //\r
+  // Execution\r
+  //\r
+  {\r
+    L"G",\r
+    L"G/[F5]             - continue to run the program\n",\r
+    L"The go command is used to cause the debugger to not interrupt execution of the EBC image. The debugger will only break execution of the interpreter if an exception is encountered (including an EBC breakpoint).\n\n",\r
+    L"G [til <Address|Symbol>]\n"\r
+    L"  (No Argument) - It means continue run the program.\n"\r
+    L"  til           - It means continuing run the program till IP is the Address.\n"\r
+    L"  <Address>     - The hexical address user want to break at.\n"\r
+    L"  <Symbol>      - The symbol name for target address user want to break at. It has following format [MapFileName:]SymbolName\n",\r
+    L"Execution:\n",\r
+    {SCAN_F5, CHAR_NULL},\r
+    DebuggerGo\r
+  },\r
+  {\r
+    L"T",\r
+    L"T/[F8]             - step into\n",\r
+    L"The step into command will cause the EBC debugger to step a single instruction. If the instruction is a call to internal code (CALL), then the debugger will break at the new function CALL.\n\n",\r
+    L"T\n"\r
+    L"  (No Argument)\n",\r
+    L"",\r
+    {SCAN_F8, CHAR_NULL},\r
+    DebuggerStepInto\r
+  },\r
+  {\r
+    L"P",\r
+    L"P/[F10]            - step over\n",\r
+    L"The step over command will cause the EBC debugger to step a single instruction. If the instruction is a call to internal code (CALL), then the external call will be made and the debugger will break at the instruction following the CALL.\n\n",\r
+    L"P\n"\r
+    L"  (No Argument)\n",\r
+    L"",\r
+    {SCAN_F10, CHAR_NULL},\r
+    DebuggerStepOver\r
+  },\r
+  {\r
+    L"O",\r
+    L"O/[F11]            - step out\n",\r
+    L"The step out command causes the EBC debugger to step out function calls. The function will be executed, but the debugger will stop after the called function returns.\n\n",\r
+    L"O\n"\r
+    L"  (No Argument)\n",\r
+    L"",\r
+    {SCAN_F11, CHAR_NULL},\r
+    DebuggerStepOut\r
+  },\r
+  {\r
+    L"Q",\r
+    L"Q                  - reset the debugger to default value and go\n",\r
+    L"The quit command will reset the debugger to default value and go.\n\n",\r
+    L"Q\n"\r
+    L"  (No Argument)\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerQuit\r
+  },\r
+  //\r
+  // Break\r
+  //\r
+  {\r
+    L"BOC",\r
+    L"BO[C|CX|R|E|T|K]   - break on CALL/CALLEX/RET/Entrypoint/Native Thunk/Key\n",\r
+    L"Enabling break-on-call will cause the debugger to halt execution and display the debugger prompt prior to executing any EBC CALL (to EBC) instructions.\n\n",\r
+    L"BOC [on|off]\n"\r
+    L"  (No Argument) - show current state\n"\r
+    L"  on            - enable break-on-call\n"\r
+    L"  off           - disable break-on-call\n",\r
+    L"Break:\n",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerBreakOnCALL\r
+  },\r
+  {\r
+    L"BOCX",\r
+    L"",\r
+    L"Enabling break-on-callex will cause the debugger to halt execution and display the debugger prompt prior to executing EBC CALLEX (thunk out) instructions.\n\n",\r
+    L"BOCX [on|off]\n"\r
+    L"  (No Argument) - show current state\n"\r
+    L"  on            - enable break-on-callex\n"\r
+    L"  off           - disable break-on-callex\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerBreakOnCALLEX\r
+  },\r
+  {\r
+    L"BOR",\r
+    L"",\r
+    L"Enabling break-on-return will cause the debugger to halt execution and display the debugger prompt prior to executing EBC RET instructions.\n\n",\r
+    L"BOR [on|off]\n"\r
+    L"  (No Argument) - show current state\n"\r
+    L"  on            - enable break-on-return\n"\r
+    L"  off           - disable break-on-return\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerBreakOnRET\r
+  },\r
+  {\r
+    L"BOE",\r
+    L"",\r
+    L"Enabling break-on-entrypoint will cause the debugger to halt execution and display the debugger prompt prior to start a driver entry point. (Default is on)\n\n",\r
+    L"BOE [on|off]\n"\r
+    L"  (No Argument) - show current state\n"\r
+    L"  on            - enable break-on-entrypoint\n"\r
+    L"  off           - disable break-on-entrypoint\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerBreakOnEntrypoint\r
+  },\r
+  {\r
+    L"BOT",\r
+    L"",\r
+    L"Enabling break-on-thunk will cause the debugger to halt execution and display the debugger prompt prior to start native call EBC thunk. (Default is on)\n\n",\r
+    L"BOT [on|off]\n"\r
+    L"  (No Argument) - show current state\n"\r
+    L"  on            - enable break-on-thunk\n"\r
+    L"  off           - disable break-on-thunk\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerBreakOnThunk\r
+  },\r
+  {\r
+    L"BOK",\r
+    L"",\r
+    L"Enabling break-on-key will cause the debugger to halt execution and display the debugger prompt after press any key.\n\n",\r
+    L"BOK [on|off]\n"\r
+    L"  (No Argument) - show current state\n"\r
+    L"  on            - enable break-on-key\n"\r
+    L"  off           - disable break-on-key\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerBreakOnKey\r
+  },\r
+  {\r
+    L"BL",\r
+    L"B[L|P|C|D|E]       - breakpoint list/set/clear/disable/enable\n",\r
+    L"List Breakpoint\n\n",\r
+    L"BL\n"\r
+    L"  (No Argument) - show the state for current breakpoint\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerBreakpointList\r
+  },\r
+  {\r
+    L"BP",\r
+    L"",\r
+    L"Set Breakpoint\n\n",\r
+    L"BP <Address|Symbol>\n"\r
+    L"  <Address> - Hexical breakpoint address\n"\r
+    L"  <Symbol>  - Symbol name for breakpoint address. It has following format [MapFileName:]SymbolName.\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerBreakpointSet\r
+  },\r
+  {\r
+    L"BC",\r
+    L"",\r
+    L"Clear Breakpoint\n\n",\r
+    L"BC <Index>|*\n"\r
+    L"  <Index>   - Decimal breakpoint index, which can be got from BL command\n"\r
+    L"  *         - For all the breakpoint\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerBreakpointClear\r
+  },\r
+  {\r
+    L"BD",\r
+    L"",\r
+    L"Disable Breakpoint\n\n",\r
+    L"BD <Index>|*\n"\r
+    L"  <Index>   - Decimal breakpoint index, which can be got from BL command\n"\r
+    L"  *         - For all the breakpoint\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerBreakpointDisable\r
+  },\r
+  {\r
+    L"BE",\r
+    L"",\r
+    L"Enable Breakpoint\n\n",\r
+    L"BE <Index>|*\n"\r
+    L"  <Index>   - Decimal breakpoint index, which can be got from BL command\n"\r
+    L"  *         - For all the breakpoint\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerBreakpointEnable\r
+  },\r
+  //\r
+  // Information\r
+  //\r
+  {\r
+    L"K",\r
+    L"K                  - show/clear call-stack\n",\r
+    L"The call-stack command will show or clear the current call-stack.\n\n",\r
+    L"K [p [<ParameterNum>]|c]\n"\r
+    L"  (No Argument) - Show current call-stack\n"\r
+    L"  p             - Show current call-stack with parameters\n"\r
+    L"  ParameterNum  - Decimal call-stack parameters number, 8 by default, 16 as max\n"\r
+    L"  c             - Clear current call-stack\n",\r
+    L"Information:\n",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerCallStack\r
+  },\r
+  {\r
+    L"TRACE",\r
+    L"TRACE              - show/clear trace instruction branch\n",\r
+    L"The trace command will show or clear the latest instruction branch.\n\n",\r
+    L"TRACE [c]\n"\r
+    L"  (No Argument) - Show current instrcution branch\n"\r
+    L"  c             - Clear current instruction branch\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerInstructionBranch\r
+  },\r
+  {\r
+    L"R",\r
+    L"R/[F2]             - display/modify register\n",\r
+    L"The register command is used to display or modify the contents of EBC VM registers. (R0~R7, Flags, IP)\n\n",\r
+    L"R [<Register> <Value>]\n"\r
+    L"  (No Argument) - Display all registers\n"\r
+    L"  <Register>    - EBC VM register name (R0~R7, Flags, ControlFlags, and IP\n"\r
+    L"  <Value>       - The Hexical value of register\n",\r
+    L"",\r
+    {SCAN_F2, CHAR_NULL},\r
+    DebuggerRegister\r
+  },\r
+  {\r
+    L"L",\r
+    L"L/[F4]             - show/load instruction assembly count\n",\r
+    L"The list assembly command will disassemble instructions starting with the current EBC VM instruction pointer. (by default 5 instructions)\n\n",\r
+    L"L [<Count>]\n"\r
+    L"  (No Argument) - List current assembly code\n"\r
+    L"  Count         - The decimal instruction assembly count\n",\r
+    L"",\r
+    {SCAN_F4, CHAR_NULL},\r
+    DebuggerList\r
+  },\r
+  {\r
+    L"SCOPE",\r
+    L"SCOPE              - load scope address\n",\r
+    L"The scope command will disassemble instructions starting with the Scope. (by default current EBC VM IP)\n\n",\r
+    L"SCOPE <Address|Symbol>\n"\r
+    L"  <Address> - The Hexical address where user wants to see the assembly code\n"\r
+    L"  <Symbol>  - Symbol name for scope address. It has following format [MapFileName:]SymbolName.\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerScope\r
+  },\r
+  {\r
+    L"DB",\r
+    L"[D|E][B|W|D|Q]     - display/modify memory\n",\r
+    L"Display BYTES Memory\n\n",\r
+    L"DB <Address|Symbol> [<Count>]\n"\r
+    L"  <Address> - The hexical memory address\n"\r
+    L"  <Symbol>  - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"\r
+    L"  <Count>   - The hexical memory count (not set means 1)\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerMemoryDB\r
+  },\r
+  {\r
+    L"DW",\r
+    L"",\r
+    L"Display WORDS Memory\n\n",\r
+    L"DW <Address|Symbol> [<Count>]\n"\r
+    L"  <Address> - The hexical memory address\n"\r
+    L"  <Symbol>  - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"\r
+    L"  <Count>   - The hexical memory count (not set means 1)\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerMemoryDW\r
+  },\r
+  {\r
+    L"DD",\r
+    L"",\r
+    L"Display DWORDS Memory\n\n",\r
+    L"DD <Address|Symbol> [<Count>]\n"\r
+    L"  <Address> - The hexical memory address\n"\r
+    L"  <Symbol>  - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"\r
+    L"  <Count>   - The hexical memory count (not set means 1)\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerMemoryDD\r
+  },\r
+  {\r
+    L"DQ",\r
+    L"",\r
+    L"Display QWORDS Memory\n\n",\r
+    L"DQ <Address|Symbol> [<Count>]\n"\r
+    L"  <Address> - The hexical memory address\n"\r
+    L"  <Symbol>  - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"\r
+    L"  <Count>   - The hexical memory count (not set means 1)\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerMemoryDQ\r
+  },\r
+  {\r
+    L"EB",\r
+    L"",\r
+    L"Enter BYTES Memory\n\n",\r
+    L"EB <Address|Symbol> <Value>\n"\r
+    L"  <Address> - The hexical memory address\n"\r
+    L"  <Symbol>  - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"\r
+    L"  <Value>   - The hexical memory value\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerMemoryEB\r
+  },\r
+  {\r
+    L"EW",\r
+    L"",\r
+    L"Enter WORDS Memory\n\n",\r
+    L"EW <Address|Symbol> <Value>\n"\r
+    L"  <Address> - The hexical memory address\n"\r
+    L"  <Symbol>  - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"\r
+    L"  <Value>   - The hexical memory value\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerMemoryEW\r
+  },\r
+  {\r
+    L"ED",\r
+    L"",\r
+    L"Enter DWORDS Memory\n\n",\r
+    L"ED <Address|Symbol> <Value>\n"\r
+    L"  <Address> - The hexical memory address\n"\r
+    L"  <Symbol>  - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"\r
+    L"  <Value>   - The hexical memory value\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerMemoryED\r
+  },\r
+  {\r
+    L"EQ",\r
+    L"",\r
+    L"Enter QWORDS Memory\n\n",\r
+    L"EQ <Address|Symbol> <Value>\n"\r
+    L"  <Address> - The hexical memory address\n"\r
+    L"  <Symbol>  - Symbol name for memory address. It has following format [MapFileName:]SymbolName.\n"\r
+    L"  <Value>   - The hexical memory value\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerMemoryEQ\r
+  },\r
+  //\r
+  // Symbol\r
+  //\r
+  {\r
+    L"LN",\r
+    L"LN                 - list the symbol\n",\r
+    L"The show symbol command will list all the current symbol. It can list the symbol in one symbol file, or list the same symbol in all the files. It can also list the symbol according to nearest address.\n\n",\r
+    L"LN [[F <SymbolFile>] [S <Symbol>]] | <Address>\n"\r
+    L"  (No Argument)  - List all the symbol\n"\r
+    L"  F <SymbolFile> - List the symbol in this symbol file only\n"\r
+    L"  S <Symbol>     - List this symbol only\n"\r
+    L"  <Address>      - The hexical memory address, which user want to find the symbol for.\n",\r
+    L"Symbol:\n",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerListSymbol\r
+  },\r
+  {\r
+    L"LOADSYMBOL",\r
+    L"[UN]LOADSYMBOL     - load/unload the symbol file\n",\r
+    L"The load symbol command will load the ebc map file. Then it parses the function name and global variable, and the print real name when do the disassembly. (Symbol file name should be XXX.MAP)\n\n",\r
+    L"LOADSYMBOL <SymbolFile> [a]\n"\r
+    L"  SymbolFile - The EBC symbol file (Its name should be XXX.MAP)\n"\r
+    L"  a          - Automatically load code files in the same dir\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerLoadSymbol\r
+  },\r
+  {\r
+    L"UNLOADSYMBOL",\r
+    L"",\r
+    L"The unload symbol command will unload the ebc map and cod file. After that the name will not be print.\n\n",\r
+    L"UNLOADSYMBOL <SymbolFile>\n"\r
+    L"  SymbolFile - The EBC symbol file (Its name should be XXX.MAP)\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerUnloadSymbol\r
+  },\r
+  {\r
+    L"LOADCODE",\r
+    L"[UN]LOADCODE       - load/unload the code file\n",\r
+    L"The load code command will load the ebc cod file. Then it parses the cod file, and the print source code when do the disassembly. (Code file name should be XXX.COD)\n\n",\r
+    L"LOADCODE <CodeFile> <SymbolFile>\n"\r
+    L"  CodeFile   - The EBC code file (Its name should be XXX.COD)\n"\r
+    L"  SymbolFile - The EBC symbol file (Its name should be XXX.MAP)\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerLoadCode\r
+  },\r
+  {\r
+    L"UNLOADCODE",\r
+    L"",\r
+    L"The unload code command will unload the ebc cod file. After that the source code will not be print.\n\n",\r
+    L"UNLOADCODE <CodeFile> <SymbolFile>\n"\r
+    L"  CodeFile   - The EBC code file (Its name should be XXX.COD)\n"\r
+    L"  SymbolFile - The EBC symbol file (Its name should be XXX.MAP)\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerUnloadCode\r
+  },\r
+  {\r
+    L"DISPLAYSYMBOL",\r
+    L"DISPLAYSYMBOL/[F3] - disable/enable the symbol output\n",\r
+    L"",\r
+    L"The display symbol command will configure the symbol show or not-show when disassembly.\n\n"\r
+    L"DISPLAYSYMBOL [on|off]\n"\r
+    L"  (No Argument) - swtich symbol output state to another one\n"\r
+    L"  on            - enable symbol output\n"\r
+    L"  off           - disable symbol output\n",\r
+    L"",\r
+    {SCAN_F3, CHAR_NULL},\r
+    DebuggerDisplaySymbol\r
+  },\r
+  {\r
+    L"DISPLAYCODE",\r
+    L"DISPLAYCODE/[F6]   - disable/enable the source code only output\n",\r
+    L"",\r
+    L"The display code command will configure the source code only show or misc source code with assembly.\n\n"\r
+    L"DISPLAYCODE [on|off]\n"\r
+    L"  (No Argument) - swtich source only output state to another one\n"\r
+    L"  on            - enable source only output\n"\r
+    L"  off           - disable source only output\n",\r
+    L"",\r
+    {SCAN_F6, CHAR_NULL},\r
+    DebuggerDisplayCode\r
+  },\r
+  //\r
+  // Other\r
+  //\r
+  {\r
+    L"H",\r
+    L"",\r
+    L"The help command will print help information for each command\n\n",\r
+    L"H [<Command>]\n",\r
+    L"",\r
+    {SCAN_F1, CHAR_NULL},\r
+    DebuggerHelp\r
+  },\r
+/*\r
+  //\r
+  // Extended\r
+  //\r
+  {\r
+    L"!IB",\r
+    L"![I|O][B|W|D]      - display/modify IO\n",\r
+    L"",\r
+    L"!IB <Address>\n",\r
+    L"Extended:\n",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerExtIoIB\r
+  },\r
+  {\r
+    L"!IW",\r
+    L"",\r
+    L"",\r
+    L"!IW <Address>\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerExtIoIW\r
+  },\r
+  {\r
+    L"!ID",\r
+    L"",\r
+    L"",\r
+    L"!ID <Address>\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerExtIoID\r
+  },\r
+  {\r
+    L"!OB",\r
+    L"",\r
+    L"",\r
+    L"!OB <Address> <Value>\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerExtIoOB\r
+  },\r
+  {\r
+    L"!OW",\r
+    L"",\r
+    L"",\r
+    L"!OW <Address> <Value>\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerExtIoOW\r
+  },\r
+  {\r
+    L"!OD",\r
+    L"",\r
+    L"",\r
+    L"!OD <Address> <Value>\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerExtIoOD\r
+  },\r
+  {\r
+    L"!PCIL",\r
+    L"!PCIL              - list PCI device, with BAR\n",\r
+    L"",\r
+    L"!PCIL [B]\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerExtPciPCIL\r
+  },\r
+  {\r
+    L"!PCID",\r
+    L"!PCID              - show PCI space\n",\r
+    L"",\r
+    L"!PCID Bus Device Function [H|B|E]\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerExtPciPCID\r
+  },\r
+  {\r
+    L"!CFGB",\r
+    L"!CFG[B|W|D]        - show/modify PCI space",\r
+    L"",\r
+    L"!CFGB <Address> [<Value>]\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerExtPciCFGB\r
+  },\r
+  {\r
+    L"!CFGW",\r
+    L"",\r
+    L"",\r
+    L"!CFGW <Address> [<Value>]\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerExtPciCFGW\r
+  },\r
+  {\r
+    L"!CFGD",\r
+    L"",\r
+    L"",\r
+    L"!CFGD <Address> [<Value>]\n",\r
+    L"",\r
+    {SCAN_NULL, CHAR_NULL},\r
+    DebuggerExtPciCFGD\r
+  },\r
+*/\r
+  {\r
+    NULL,\r
+    NULL,\r
+    NULL,\r
+    NULL,\r
+    NULL,\r
+    {SCAN_NULL, CHAR_NULL},\r
+    NULL\r
+  },\r
+};\r
+\r
+EFI_DEBUGGER_COMMAND\r
+MatchDebuggerCommand (\r
+  IN CHAR16    *CommandName,\r
+  IN CHAR16    **CommandArg\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Find the command according to name\r
+\r
+Arguments:\r
+\r
+  CommandName   - Command Name\r
+  CommandArg    - Command Argument\r
+\r
+Returns:\r
+\r
+  Not NULL        - The DebuggerCommand is found successfully\r
+  NULL            - not found\r
+\r
+--*/\r
+{\r
+  UINTN  Index;\r
+  CHAR16 *Temp;\r
+\r
+  //\r
+  // Get Command Name\r
+  //\r
+  Temp = StrGetNewTokenLine (CommandName, L" ");\r
+  CommandName = Temp;\r
+  //\r
+  // Get Command Argument\r
+  //\r
+  Temp = StrGetNextTokenLine (L" ");\r
+  *CommandArg = Temp;\r
+\r
+  if (CommandName == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Go through each command, check the CommandName\r
+  //\r
+  for (Index = 0; mDebuggerCommandSet[Index].CommandName != NULL; Index++) {\r
+    if (StriCmp (CommandName, mDebuggerCommandSet[Index].CommandName) == 0) {\r
+      //\r
+      // Found\r
+      //\r
+      return mDebuggerCommandSet[Index].CommandFunc;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Not found\r
+  //\r
+  return NULL;\r
+}\r
+\r
+CHAR16 *\r
+GetCommandNameByKey (\r
+  IN EFI_INPUT_KEY CommandKey\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Find the command name according to the function key\r
+\r
+Arguments:\r
+\r
+  CommandKey    - Command Function Key\r
+\r
+Returns:\r
+\r
+  Not NULL        - The DebuggerName is found successfully\r
+  NULL            - not found\r
+\r
+--*/\r
+{\r
+  UINTN  Index;\r
+\r
+  //\r
+  // Go through each command, check the CommandKey\r
+  //\r
+  for (Index = 0; mDebuggerCommandSet[Index].CommandName != NULL; Index++) {\r
+    if ((mDebuggerCommandSet[Index].CommandKey.UnicodeChar == CommandKey.UnicodeChar) &&\r
+        (mDebuggerCommandSet[Index].CommandKey.ScanCode    == CommandKey.ScanCode)) {\r
+      //\r
+      // Found\r
+      //\r
+      return mDebuggerCommandSet[Index].CommandName;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Not found\r
+  //\r
+  return NULL;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCommand.h b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCommand.h
new file mode 100644 (file)
index 0000000..7acf4de
--- /dev/null
@@ -0,0 +1,106 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbCommand.h\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#ifndef _EFI_EDB_COMMAND_H_\r
+#define _EFI_EDB_COMMAND_H_\r
+\r
+typedef enum {\r
+  EdbWidthUint8,\r
+  EdbWidthUint16,\r
+  EdbWidthUint32,\r
+  EdbWidthUint64,\r
+  EdbWidthMax\r
+} EDB_DATA_WIDTH;\r
+\r
+EFI_DEBUGGER_COMMAND\r
+MatchDebuggerCommand (\r
+  IN CHAR16    *CommandName,\r
+  IN CHAR16    **CommandArg\r
+  );\r
+\r
+CHAR16 *\r
+GetCommandNameByKey (\r
+  IN EFI_INPUT_KEY CommandKey\r
+  );\r
+\r
+//\r
+// Definition for Command Table\r
+//\r
+#define EDB_COMMAND_DEFINE(func) \\r
+EFI_DEBUG_STATUS \\r
+func ( \\r
+  IN     CHAR16                    *CommandArg, \\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate, \\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType, \\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext \\r
+  )\r
+\r
+EDB_COMMAND_DEFINE (DebuggerCallStack);\r
+EDB_COMMAND_DEFINE (DebuggerInstructionBranch);\r
+EDB_COMMAND_DEFINE (DebuggerBreakOnCALL);\r
+EDB_COMMAND_DEFINE (DebuggerBreakOnCALLEX);\r
+EDB_COMMAND_DEFINE (DebuggerBreakOnRET);\r
+EDB_COMMAND_DEFINE (DebuggerBreakOnEntrypoint);\r
+EDB_COMMAND_DEFINE (DebuggerBreakOnThunk);\r
+EDB_COMMAND_DEFINE (DebuggerBreakOnKey);\r
+EDB_COMMAND_DEFINE (DebuggerBreakpointList);\r
+EDB_COMMAND_DEFINE (DebuggerBreakpointSet);\r
+EDB_COMMAND_DEFINE (DebuggerBreakpointClear);\r
+EDB_COMMAND_DEFINE (DebuggerBreakpointDisable);\r
+EDB_COMMAND_DEFINE (DebuggerBreakpointEnable);\r
+EDB_COMMAND_DEFINE (DebuggerGo);\r
+EDB_COMMAND_DEFINE (DebuggerHelp);\r
+EDB_COMMAND_DEFINE (DebuggerMemoryDB);\r
+EDB_COMMAND_DEFINE (DebuggerMemoryDW);\r
+EDB_COMMAND_DEFINE (DebuggerMemoryDD);\r
+EDB_COMMAND_DEFINE (DebuggerMemoryDQ);\r
+EDB_COMMAND_DEFINE (DebuggerMemoryEB);\r
+EDB_COMMAND_DEFINE (DebuggerMemoryEW);\r
+EDB_COMMAND_DEFINE (DebuggerMemoryED);\r
+EDB_COMMAND_DEFINE (DebuggerMemoryEQ);\r
+EDB_COMMAND_DEFINE (DebuggerQuit);\r
+EDB_COMMAND_DEFINE (DebuggerRegister);\r
+EDB_COMMAND_DEFINE (DebuggerScope);\r
+EDB_COMMAND_DEFINE (DebuggerList);\r
+EDB_COMMAND_DEFINE (DebuggerStepInto);\r
+EDB_COMMAND_DEFINE (DebuggerStepOver);\r
+EDB_COMMAND_DEFINE (DebuggerStepOut);\r
+EDB_COMMAND_DEFINE (DebuggerListSymbol);\r
+EDB_COMMAND_DEFINE (DebuggerLoadSymbol);\r
+EDB_COMMAND_DEFINE (DebuggerUnloadSymbol);\r
+EDB_COMMAND_DEFINE (DebuggerDisplaySymbol);\r
+EDB_COMMAND_DEFINE (DebuggerLoadCode);\r
+EDB_COMMAND_DEFINE (DebuggerUnloadCode);\r
+EDB_COMMAND_DEFINE (DebuggerDisplayCode);\r
+EDB_COMMAND_DEFINE (DebuggerExtIoIB);\r
+EDB_COMMAND_DEFINE (DebuggerExtIoIW);\r
+EDB_COMMAND_DEFINE (DebuggerExtIoID);\r
+EDB_COMMAND_DEFINE (DebuggerExtIoOB);\r
+EDB_COMMAND_DEFINE (DebuggerExtIoOW);\r
+EDB_COMMAND_DEFINE (DebuggerExtIoOD);\r
+EDB_COMMAND_DEFINE (DebuggerExtPciPCIL);\r
+EDB_COMMAND_DEFINE (DebuggerExtPciPCID);\r
+EDB_COMMAND_DEFINE (DebuggerExtPciCFGB);\r
+EDB_COMMAND_DEFINE (DebuggerExtPciCFGW);\r
+EDB_COMMAND_DEFINE (DebuggerExtPciCFGD);\r
+\r
+extern EFI_DEBUGGER_COMMAND_SET  mDebuggerCommandSet[];\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCommon.h b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCommon.h
new file mode 100644 (file)
index 0000000..8c9449c
--- /dev/null
@@ -0,0 +1,246 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbCommon.h\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#ifndef _EFI_EDB_COMMON_H_\r
+#define _EFI_EDB_COMMON_H_\r
+\r
+#include <Uefi.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Protocol/DebugSupport.h>\r
+#include <Protocol/PciRootBridgeIo.h>\r
+#include <Protocol/SimpleFileSystem.h>\r
+#include <Guid/FileInfo.h>\r
+#include <Guid/FileSystemInfo.h>\r
+#include <Guid/FileSystemVolumeLabelInfo.h>\r
+#include <Guid/DebugImageInfoTable.h>\r
+\r
+typedef UINTN EFI_DEBUG_STATUS;\r
+\r
+typedef struct _EFI_DEBUGGER_PRIVATE_DATA EFI_DEBUGGER_PRIVATE_DATA;\r
+\r
+//\r
+// Definition for Debugger Command\r
+//\r
+typedef\r
+EFI_DEBUG_STATUS\r
+(* EFI_DEBUGGER_COMMAND) (\r
+  IN     CHAR16                    *CommandArg,\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_EXCEPTION_TYPE        ExceptionType,\r
+  IN OUT EFI_SYSTEM_CONTEXT        SystemContext\r
+);\r
+\r
+typedef struct {\r
+  CHAR16                *CommandName;\r
+  CHAR16                *CommandTitle;\r
+  CHAR16                *CommandHelp;\r
+  CHAR16                *CommandSyntax;\r
+  CHAR16                *ClassName;\r
+  EFI_INPUT_KEY         CommandKey;\r
+  EFI_DEBUGGER_COMMAND  CommandFunc;\r
+} EFI_DEBUGGER_COMMAND_SET;\r
+\r
+//\r
+// Definition for Debugger Symbol\r
+//\r
+#define EFI_DEBUGGER_SYMBOL_NAME_MAX     256\r
+#define EFI_DEBUGGER_SYMBOL_ENTRY_MAX    512\r
+#define EFI_DEBUGGER_SYMBOL_OBJECT_MAX   32\r
+\r
+//\r
+// We have following SYMBOL data structure:\r
+//\r
+// SYMBOL_CONTEXT -> SYMBOL_OBJECT -> SYMBOL_ENTRY (FuncXXX, 0xXXX)\r
+//                                    SYMBOL_ENTRY (VarYYY,  0xYYY)\r
+//                                    SYMBOL_ENTRY\r
+//\r
+//                   SYMBOL_OBJECT -> SYMBOL_ENTRY\r
+//                                    SYMBOL_ENTRY\r
+//\r
+//                   SYMBOL_OBJECT -> SYMBOL_ENTRY\r
+//                                    SYMBOL_ENTRY\r
+//\r
+\r
+typedef enum {\r
+  EfiDebuggerSymbolFunction,\r
+  EfiDebuggerSymbolStaticFunction,\r
+  EfiDebuggerSymbolGlobalVariable,\r
+  EfiDebuggerSymbolStaticVariable,\r
+  EfiDebuggerSymbolTypeMax,\r
+} EFI_DEBUGGER_SYMBOL_TYPE;\r
+\r
+typedef struct {\r
+  CHAR8                      Name[EFI_DEBUGGER_SYMBOL_NAME_MAX];\r
+  UINTN                      RVA;\r
+  EFI_DEBUGGER_SYMBOL_TYPE   Type;\r
+  CHAR8                      ObjName[EFI_DEBUGGER_SYMBOL_NAME_MAX];\r
+  CHAR8                      *CodBuffer;\r
+  UINTN                      CodBufferSize;\r
+  UINTN                      FuncOffsetBase;\r
+  CHAR8                      *SourceBuffer;\r
+} EFI_DEBUGGER_SYMBOL_ENTRY;\r
+\r
+typedef struct {\r
+  CHAR16                     Name[EFI_DEBUGGER_SYMBOL_NAME_MAX];\r
+  UINTN                      EntryCount;\r
+  UINTN                      MaxEntryCount;\r
+  UINTN                      BaseAddress;\r
+  UINTN                      StartEntrypointRVA;\r
+  UINTN                      MainEntrypointRVA;\r
+  EFI_DEBUGGER_SYMBOL_ENTRY  *Entry;\r
+  VOID                       **SourceBuffer;\r
+} EFI_DEBUGGER_SYMBOL_OBJECT;\r
+\r
+typedef struct {\r
+  UINTN                       ObjectCount;\r
+  UINTN                       MaxObjectCount;\r
+  EFI_DEBUGGER_SYMBOL_OBJECT  *Object;\r
+  BOOLEAN                     DisplaySymbol;\r
+  BOOLEAN                     DisplayCodeOnly;\r
+} EFI_DEBUGGER_SYMBOL_CONTEXT;\r
+\r
+//\r
+// Definition for Debugger Breakpoint\r
+//\r
+#define EFI_DEBUGGER_BREAKPOINT_MAX    0x10\r
+\r
+typedef struct {\r
+  EFI_PHYSICAL_ADDRESS      BreakpointAddress;\r
+  UINT64                    OldInstruction;    // UINT64 is enough for an instruction\r
+  BOOLEAN                   State;\r
+} EFI_DEBUGGER_BREAKPOINT_CONTEXT;\r
+\r
+//\r
+// Definition for Debugger Call-Stack\r
+//\r
+#define EFI_DEBUGGER_CALLSTACK_MAX     0x10\r
+\r
+typedef enum {\r
+  EfiDebuggerBranchTypeEbcCall,\r
+  EfiDebuggerBranchTypeEbcCallEx,\r
+  EfiDebuggerBranchTypeEbcRet,\r
+  EfiDebuggerBranchTypeEbcJmp,\r
+  EfiDebuggerBranchTypeEbcJmp8,\r
+  EfiDebuggerBranchTypeEbcMax,\r
+} EFI_DEBUGGER_BRANCH_TYPE;\r
+\r
+#define EFI_DEBUGGER_CALL_MAX_PARAMETER      0x16\r
+#define EFI_DEBUGGER_CALL_DEFAULT_PARAMETER  0x8\r
+\r
+typedef struct {\r
+  EFI_PHYSICAL_ADDRESS      SourceAddress;\r
+  EFI_PHYSICAL_ADDRESS      DestAddress;\r
+  //\r
+  // We save all parameter here, because code may update the parameter as local variable.\r
+  //\r
+  UINTN                     ParameterAddr;\r
+  UINTN                     Parameter[EFI_DEBUGGER_CALL_MAX_PARAMETER];\r
+  EFI_DEBUGGER_BRANCH_TYPE  Type;\r
+} EFI_DEBUGGER_CALLSTACK_CONTEXT;\r
+\r
+//\r
+// Definition for Debugger Trace\r
+//\r
+#define EFI_DEBUGGER_TRACE_MAX         0x10\r
+\r
+typedef struct {\r
+  EFI_PHYSICAL_ADDRESS      SourceAddress;\r
+  EFI_PHYSICAL_ADDRESS      DestAddress;\r
+  EFI_DEBUGGER_BRANCH_TYPE  Type;\r
+} EFI_DEBUGGER_TRACE_CONTEXT;\r
+\r
+//\r
+// Definition for Debugger Step\r
+//\r
+typedef struct {\r
+  EFI_PHYSICAL_ADDRESS      BreakAddress;\r
+  EFI_PHYSICAL_ADDRESS      FramePointer;\r
+} EFI_DEBUGGER_STEP_CONTEXT;\r
+\r
+//\r
+// Definition for Debugger GoTil\r
+//\r
+typedef struct {\r
+  EFI_PHYSICAL_ADDRESS      BreakAddress;\r
+} EFI_DEBUGGER_GOTIL_CONTEXT;\r
+\r
+//\r
+// Definition for Debugger private data structure\r
+//\r
+#define EFI_DEBUGGER_SIGNATURE         SIGNATURE_32 ('e', 'd', 'b', '!')\r
+\r
+#define EFI_DEBUG_DEFAULT_INSTRUCTION_NUMBER  5\r
+\r
+#define EFI_DEBUG_BREAK_TIMER_INTERVAL        10000000   // 1 second\r
+\r
+#define EFI_DEBUG_FLAG_EBC            0x80000000\r
+#define EFI_DEBUG_FLAG_EBC_B_BOC      0x1\r
+#define EFI_DEBUG_FLAG_EBC_B_BOCX     0x2\r
+#define EFI_DEBUG_FLAG_EBC_B_BOR      0x4\r
+#define EFI_DEBUG_FLAG_EBC_B_BOE      0x8\r
+#define EFI_DEBUG_FLAG_EBC_B_BOT      0x10\r
+#define EFI_DEBUG_FLAG_EBC_B_STEPOVER 0x20\r
+#define EFI_DEBUG_FLAG_EBC_B_STEPOUT  0x40\r
+#define EFI_DEBUG_FLAG_EBC_B_BP       0x80\r
+#define EFI_DEBUG_FLAG_EBC_B_GT       0x100\r
+#define EFI_DEBUG_FLAG_EBC_B_BOK      0x200\r
+#define EFI_DEBUG_FLAG_EBC_BOC        (EFI_DEBUG_FLAG_EBC | EFI_DEBUG_FLAG_EBC_B_BOC)\r
+#define EFI_DEBUG_FLAG_EBC_BOCX       (EFI_DEBUG_FLAG_EBC | EFI_DEBUG_FLAG_EBC_B_BOCX)\r
+#define EFI_DEBUG_FLAG_EBC_BOR        (EFI_DEBUG_FLAG_EBC | EFI_DEBUG_FLAG_EBC_B_BOR)\r
+#define EFI_DEBUG_FLAG_EBC_BOE        (EFI_DEBUG_FLAG_EBC | EFI_DEBUG_FLAG_EBC_B_BOE)\r
+#define EFI_DEBUG_FLAG_EBC_BOT        (EFI_DEBUG_FLAG_EBC | EFI_DEBUG_FLAG_EBC_B_BOT)\r
+#define EFI_DEBUG_FLAG_EBC_STEPOVER   (EFI_DEBUG_FLAG_EBC | EFI_DEBUG_FLAG_EBC_B_STEPOVER)\r
+#define EFI_DEBUG_FLAG_EBC_STEPOUT    (EFI_DEBUG_FLAG_EBC | EFI_DEBUG_FLAG_EBC_B_STEPOUT)\r
+#define EFI_DEBUG_FLAG_EBC_BP         (EFI_DEBUG_FLAG_EBC | EFI_DEBUG_FLAG_EBC_B_BP)\r
+#define EFI_DEBUG_FLAG_EBC_GT         (EFI_DEBUG_FLAG_EBC | EFI_DEBUG_FLAG_EBC_B_GT)\r
+#define EFI_DEBUG_FLAG_EBC_BOK        (EFI_DEBUG_FLAG_EBC | EFI_DEBUG_FLAG_EBC_B_BOK)\r
+\r
+//\r
+// Debugger private data structure\r
+//\r
+typedef struct _EFI_DEBUGGER_PRIVATE_DATA {\r
+  UINT32                                      Signature;\r
+  EFI_INSTRUCTION_SET_ARCHITECTURE            Isa;\r
+  UINT32                                      EfiDebuggerRevision;\r
+  UINT32                                      EbcVmRevision;\r
+  EFI_DEBUG_IMAGE_INFO_TABLE_HEADER           *DebugImageInfoTableHeader;\r
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL             *Vol;\r
+  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL             *PciRootBridgeIo;\r
+  EFI_DEBUGGER_COMMAND_SET                    *DebuggerCommandSet;\r
+  EFI_DEBUGGER_SYMBOL_CONTEXT                 DebuggerSymbolContext;\r
+  UINTN                                       DebuggerBreakpointCount;\r
+  EFI_DEBUGGER_BREAKPOINT_CONTEXT             DebuggerBreakpointContext[EFI_DEBUGGER_BREAKPOINT_MAX + 1];\r
+  UINTN                                       CallStackEntryCount;\r
+  EFI_DEBUGGER_CALLSTACK_CONTEXT              CallStackEntry[EFI_DEBUGGER_CALLSTACK_MAX + 1];\r
+  UINTN                                       TraceEntryCount;\r
+  EFI_DEBUGGER_TRACE_CONTEXT                  TraceEntry[EFI_DEBUGGER_TRACE_MAX + 1];\r
+  EFI_DEBUGGER_STEP_CONTEXT                   StepContext;\r
+  EFI_DEBUGGER_GOTIL_CONTEXT                  GoTilContext;\r
+  EFI_PHYSICAL_ADDRESS                        InstructionScope;\r
+  UINTN                                       InstructionNumber;\r
+  UINT32                                      FeatureFlags;\r
+  UINT32                                      StatusFlags;\r
+  BOOLEAN                                     EnablePageBreak;\r
+  EFI_EVENT                                   BreakEvent;\r
+} EFI_DEBUGGER_PRIVATE_DATA;\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbDisasm.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbDisasm.c
new file mode 100644 (file)
index 0000000..52800f7
--- /dev/null
@@ -0,0 +1,1907 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbDisasm.c\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#include "Edb.h"\r
+\r
+//\r
+// Debugger Disasm definition\r
+//\r
+#define EDB_DISASM_DEFINE(func) \\r
+UINTN \\r
+func ( \\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress, \\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext, \\r
+  OUT    CHAR16                    **DisasmString \\r
+  )\r
+\r
+EDB_DISASM_DEFINE (EdbDisasmBREAK);\r
+EDB_DISASM_DEFINE (EdbDisasmJMP);\r
+EDB_DISASM_DEFINE (EdbDisasmJMP8);\r
+EDB_DISASM_DEFINE (EdbDisasmCALL);\r
+EDB_DISASM_DEFINE (EdbDisasmRET);\r
+EDB_DISASM_DEFINE (EdbDisasmCMP);\r
+EDB_DISASM_DEFINE (EdbDisasmUnsignedDataManip);\r
+EDB_DISASM_DEFINE (EdbDisasmSignedDataManip);\r
+EDB_DISASM_DEFINE (EdbDisasmMOVxx);\r
+EDB_DISASM_DEFINE (EdbDisasmMOVsnw);\r
+EDB_DISASM_DEFINE (EdbDisasmMOVsnd);\r
+EDB_DISASM_DEFINE (EdbDisasmLOADSP);\r
+EDB_DISASM_DEFINE (EdbDisasmSTORESP);\r
+EDB_DISASM_DEFINE (EdbDisasmPUSH);\r
+EDB_DISASM_DEFINE (EdbDisasmPOP);\r
+EDB_DISASM_DEFINE (EdbDisasmCMPI);\r
+EDB_DISASM_DEFINE (EdbDisasmPUSHn);\r
+EDB_DISASM_DEFINE (EdbDisasmPOPn);\r
+EDB_DISASM_DEFINE (EdbDisasmMOVI);\r
+EDB_DISASM_DEFINE (EdbDisasmMOVIn);\r
+EDB_DISASM_DEFINE (EdbDisasmMOVREL);\r
+\r
+//\r
+// Debugger Disasm Table\r
+//\r
+EDB_DISASM_INSTRUCTION mEdbDisasmInstructionTable[] = {\r
+  EdbDisasmBREAK,             // opcode 0x00 BREAK\r
+  EdbDisasmJMP,               // opcode 0x01 JMP\r
+  EdbDisasmJMP8,              // opcode 0x02 JMP8\r
+  EdbDisasmCALL,              // opcode 0x03 CALL\r
+  EdbDisasmRET,               // opcode 0x04 RET\r
+  EdbDisasmCMP,               // opcode 0x05 CMPEQ\r
+  EdbDisasmCMP,               // opcode 0x06 CMPLTE\r
+  EdbDisasmCMP,               // opcode 0x07 CMPGTE\r
+  EdbDisasmCMP,               // opcode 0x08 CMPULTE\r
+  EdbDisasmCMP,               // opcode 0x09 CMPUGTE\r
+  EdbDisasmUnsignedDataManip, // opcode 0x0A NOT\r
+  EdbDisasmSignedDataManip,   // opcode 0x0B NEG\r
+  EdbDisasmSignedDataManip,   // opcode 0x0C ADD\r
+  EdbDisasmSignedDataManip,   // opcode 0x0D SUB\r
+  EdbDisasmSignedDataManip,   // opcode 0x0E MUL\r
+  EdbDisasmUnsignedDataManip, // opcode 0x0F MULU\r
+  EdbDisasmSignedDataManip,   // opcode 0x10 DIV\r
+  EdbDisasmUnsignedDataManip, // opcode 0x11 DIVU\r
+  EdbDisasmSignedDataManip,   // opcode 0x12 MOD\r
+  EdbDisasmUnsignedDataManip, // opcode 0x13 MODU\r
+  EdbDisasmUnsignedDataManip, // opcode 0x14 AND\r
+  EdbDisasmUnsignedDataManip, // opcode 0x15 OR\r
+  EdbDisasmUnsignedDataManip, // opcode 0x16 XOR\r
+  EdbDisasmUnsignedDataManip, // opcode 0x17 SHL\r
+  EdbDisasmUnsignedDataManip, // opcode 0x18 SHR\r
+  EdbDisasmSignedDataManip,   // opcode 0x19 ASHR\r
+  EdbDisasmUnsignedDataManip, // opcode 0x1A EXTNDB\r
+  EdbDisasmUnsignedDataManip, // opcode 0x1B EXTNDW\r
+  EdbDisasmUnsignedDataManip, // opcode 0x1C EXTNDD\r
+  EdbDisasmMOVxx,             // opcode 0x1D MOVBW\r
+  EdbDisasmMOVxx,             // opcode 0x1E MOVWW\r
+  EdbDisasmMOVxx,             // opcode 0x1F MOVDW\r
+  EdbDisasmMOVxx,             // opcode 0x20 MOVQW\r
+  EdbDisasmMOVxx,             // opcode 0x21 MOVBD\r
+  EdbDisasmMOVxx,             // opcode 0x22 MOVWD\r
+  EdbDisasmMOVxx,             // opcode 0x23 MOVDD\r
+  EdbDisasmMOVxx,             // opcode 0x24 MOVQD\r
+  EdbDisasmMOVsnw,            // opcode 0x25 MOVSNW\r
+  EdbDisasmMOVsnd,            // opcode 0x26 MOVSND\r
+  NULL,                       // opcode 0x27\r
+  EdbDisasmMOVxx,             // opcode 0x28 MOVQQ\r
+  EdbDisasmLOADSP,            // opcode 0x29 LOADSP\r
+  EdbDisasmSTORESP,           // opcode 0x2A STORESP\r
+  EdbDisasmPUSH,              // opcode 0x2B PUSH\r
+  EdbDisasmPOP,               // opcode 0x2C POP\r
+  EdbDisasmCMPI,              // opcode 0x2D CMPIEQ\r
+  EdbDisasmCMPI,              // opcode 0x2E CMPILTE\r
+  EdbDisasmCMPI,              // opcode 0x2F CMPIGTE\r
+  EdbDisasmCMPI,              // opcode 0x30 CMPIULTE\r
+  EdbDisasmCMPI,              // opcode 0x31 CMPIUGTE\r
+  EdbDisasmMOVxx,             // opcode 0x32 MOVNW\r
+  EdbDisasmMOVxx,             // opcode 0x33 MOVND\r
+  NULL,                       // opcode 0x34\r
+  EdbDisasmPUSHn,             // opcode 0x35 PUSHN\r
+  EdbDisasmPOPn,              // opcode 0x36 POPN\r
+  EdbDisasmMOVI,              // opcode 0x37 MOVI\r
+  EdbDisasmMOVIn,             // opcode 0x38 MOVIN\r
+  EdbDisasmMOVREL,            // opcode 0x39 MOVREL\r
+};\r
+\r
+UINTN\r
+EdbDisasmBREAK (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisasmString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disasm instruction - BREAK\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - The instruction address\r
+  SystemContext      - EBC system context.\r
+  DisasmString       - The instruction string\r
+\r
+Returns:\r
+\r
+  Instruction length\r
+\r
+--*/\r
+{\r
+  ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_BREAK);\r
+\r
+  if (*(UINT8 *)(UINTN)(InstructionAddress + 1) > 6) {\r
+    return 0;\r
+  }\r
+\r
+  //\r
+  // Construct Disasm String\r
+  //\r
+  if (DisasmString != NULL) {\r
+    *DisasmString = EdbPreInstructionString ();\r
+\r
+    EdbPrintInstructionName (L"BREAK");\r
+    EdbPrintDatan (*(UINT8 *)(UINTN)(InstructionAddress + 1));\r
+\r
+    EdbPostInstructionString ();\r
+  }\r
+\r
+  return 2;\r
+}\r
+\r
+extern CONST UINT8                    mJMPLen[];\r
+\r
+UINTN\r
+EdbDisasmJMP (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisasmString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disasm instruction - JMP\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - The instruction address\r
+  SystemContext      - EBC system context.\r
+  DisasmString       - The instruction string\r
+\r
+Returns:\r
+\r
+  Instruction length\r
+\r
+--*/\r
+{\r
+  UINT8   Modifiers;\r
+  UINT8   Operands;\r
+  UINTN   Size;\r
+  UINT32  Data32;\r
+  UINT64  Data64;\r
+\r
+  ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_JMP);\r
+\r
+  Modifiers  = GET_MODIFIERS (InstructionAddress);\r
+  Operands   = GET_OPERANDS (InstructionAddress);\r
+  Size = (UINTN)mJMPLen[(Modifiers >> 6) & 0x03];\r
+\r
+  //\r
+  // Construct Disasm String\r
+  //\r
+  if (DisasmString != NULL) {\r
+    *DisasmString = EdbPreInstructionString ();\r
+\r
+    EdbPrintInstructionName (L"JMP");\r
+//    if (Modifiers & OPCODE_M_IMMDATA64) {\r
+//      EdbPrintInstructionName (L"64");\r
+//    } else {\r
+//      EdbPrintInstructionName (L"32");\r
+//    }\r
+    if (Modifiers & CONDITION_M_CONDITIONAL) {\r
+      if (Modifiers & JMP_M_CS) {\r
+        EdbPrintInstructionName (L"cs");\r
+      } else {\r
+        EdbPrintInstructionName (L"cc");\r
+      }\r
+    }\r
+\r
+    InstructionAddress += 2;\r
+    if (Modifiers & OPCODE_M_IMMDATA64) {\r
+      CopyMem (&Data64, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT64));\r
+      if (Modifiers & OPCODE_M_IMMDATA) {\r
+        EdbPrintData64 (Data64);\r
+      } else {\r
+        return 0;\r
+      }\r
+    } else {\r
+      CopyMem (&Data32, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT32));\r
+      EdbPrintRegister1 (Operands);\r
+\r
+      if ((Operands & OPERAND_M_INDIRECT1) == 0) {\r
+        if ((Modifiers & OPCODE_M_IMMDATA) == 0) {\r
+          Data32 = 0;\r
+        }\r
+        EdbPrintImmDatan (Data32);\r
+      } else {\r
+        EdbPrintRawIndexData32 (Data32);\r
+      }\r
+    }\r
+\r
+    EdbPostInstructionString ();\r
+  }\r
+\r
+  return Size;\r
+}\r
+\r
+UINTN\r
+EdbDisasmJMP8 (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisasmString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disasm instruction - JMP8\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - The instruction address\r
+  SystemContext      - EBC system context.\r
+  DisasmString       - The instruction string\r
+\r
+Returns:\r
+\r
+  Instruction length\r
+\r
+--*/\r
+{\r
+  UINT8   Modifiers;\r
+\r
+  ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_JMP8);\r
+  Modifiers  = GET_MODIFIERS (InstructionAddress);\r
+\r
+  //\r
+  // Construct Disasm String\r
+  //\r
+  if (DisasmString != NULL) {\r
+    *DisasmString = EdbPreInstructionString ();\r
+\r
+    EdbPrintInstructionName (L"JMP8");\r
+    if (Modifiers & CONDITION_M_CONDITIONAL) {\r
+      if (Modifiers & JMP_M_CS) {\r
+        EdbPrintInstructionName (L"cs");\r
+      } else {\r
+        EdbPrintInstructionName (L"cc");\r
+      }\r
+    }\r
+\r
+    EdbPrintData8 (*(UINT8 *)(UINTN)(InstructionAddress + 1));\r
+\r
+    EdbPostInstructionString ();\r
+  }\r
+\r
+  return 2;\r
+}\r
+\r
+UINTN\r
+EdbDisasmCALL (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisasmString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disasm instruction - CALL\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - The instruction address\r
+  SystemContext      - EBC system context.\r
+  DisasmString       - The instruction string\r
+\r
+Returns:\r
+\r
+  Instruction length\r
+\r
+--*/\r
+{\r
+  UINT8   Modifiers;\r
+  UINT8   Operands;\r
+  UINTN   Size;\r
+  UINT32  Data32;\r
+  UINT64  Data64;\r
+  UINT64  Ip;\r
+  UINTN   Result;\r
+  EFI_PHYSICAL_ADDRESS      SavedInstructionAddress;\r
+\r
+  ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_CALL);\r
+  SavedInstructionAddress = InstructionAddress;\r
+\r
+  Modifiers  = GET_MODIFIERS (InstructionAddress);\r
+  Operands   = GET_OPERANDS (InstructionAddress);\r
+  Size = (UINTN)mJMPLen[(Modifiers >> 6) & 0x03];\r
+\r
+  //\r
+  // Construct Disasm String\r
+  //\r
+  if (DisasmString != NULL) {\r
+    *DisasmString = EdbPreInstructionString ();\r
+\r
+    EdbPrintInstructionName (L"CALL");\r
+//    if (Modifiers & OPCODE_M_IMMDATA64) {\r
+//      EdbPrintInstructionName (L"64");\r
+//    } else {\r
+//      EdbPrintInstructionName (L"32");\r
+//    }\r
+    if (Operands & OPERAND_M_NATIVE_CALL) {\r
+      EdbPrintInstructionName (L"EX");\r
+    }\r
+//    if ((Operands & OPERAND_M_RELATIVE_ADDR) == 0) {\r
+//      EdbPrintInstructionName (L"a");\r
+//    }\r
+\r
+    InstructionAddress += 2;\r
+    if (Modifiers & OPCODE_M_IMMDATA64) {\r
+      CopyMem (&Data64, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT64));\r
+      Ip = Data64;\r
+      if (Modifiers & OPCODE_M_IMMDATA) {\r
+        Result = EdbFindAndPrintSymbol ((UINTN)Ip);\r
+        if (Result == 0) {\r
+          EdbPrintData64 (Data64);\r
+        }\r
+      } else {\r
+        return 0;\r
+      }\r
+    } else {\r
+      if (Modifiers & OPCODE_M_IMMDATA) {\r
+        CopyMem (&Data32, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT32));\r
+      } else {\r
+        Data32 = 0;\r
+      }\r
+\r
+      if ((Operands & OPERAND_M_OP1) == 0) {\r
+        Ip = (UINT64)Data32;\r
+      } else {\r
+        Ip = GetRegisterValue (SystemContext, (Operands & OPERAND_M_OP1));\r
+      }\r
+\r
+      if ((Operands & OPERAND_M_INDIRECT1) == 0) {\r
+        if (Operands & OPERAND_M_RELATIVE_ADDR) {\r
+          Result = EdbFindAndPrintSymbol ((UINTN)(SavedInstructionAddress + Ip + Size));\r
+        } else {\r
+          Result = EdbFindAndPrintSymbol ((UINTN)Ip);\r
+        }\r
+        if (Result == 0) {\r
+          EdbPrintRegister1 (Operands);\r
+          if (Modifiers & OPCODE_M_IMMDATA) {\r
+            EdbPrintImmData32 (Data32);\r
+          }\r
+        }\r
+      } else {\r
+        EdbPrintRegister1 (Operands);\r
+        if (Modifiers & OPCODE_M_IMMDATA) {\r
+          EdbPrintRawIndexData32 (Data32);\r
+        }\r
+      }\r
+    }\r
+\r
+    EdbPostInstructionString ();\r
+  }\r
+\r
+  return Size;\r
+}\r
+\r
+UINTN\r
+EdbDisasmRET (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisasmString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disasm instruction - RET\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - The instruction address\r
+  SystemContext      - EBC system context.\r
+  DisasmString       - The instruction string\r
+\r
+Returns:\r
+\r
+  Instruction length\r
+\r
+--*/\r
+{\r
+  ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_RET);\r
+\r
+  if (*(UINT8 *)(UINTN)(InstructionAddress + 1) != 0) {\r
+    return 0;\r
+  }\r
+\r
+  //\r
+  // Construct Disasm String\r
+  //\r
+  if (DisasmString != NULL) {\r
+    *DisasmString = EdbPreInstructionString ();\r
+\r
+    EdbPrintInstructionName (L"RET");\r
+\r
+    EdbPostInstructionString ();\r
+  }\r
+\r
+  return 2;\r
+}\r
+\r
+UINTN\r
+EdbDisasmCMP (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisasmString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disasm instruction - CMP\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - The instruction address\r
+  SystemContext      - EBC system context.\r
+  DisasmString       - The instruction string\r
+\r
+Returns:\r
+\r
+  Instruction length\r
+\r
+--*/\r
+{\r
+  UINT8  Opcode;\r
+  UINT8  Modifiers;\r
+  UINT8  Operands;\r
+  UINT16 Data16;\r
+  UINTN  Size;\r
+\r
+  ASSERT (\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_CMPEQ)   ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_CMPLTE)  ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_CMPGTE)  ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_CMPULTE) ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_CMPUGTE)\r
+    );\r
+\r
+  Opcode     = GET_OPCODE (InstructionAddress);\r
+  Modifiers  = GET_MODIFIERS (InstructionAddress);\r
+  Operands   = GET_OPERANDS (InstructionAddress);\r
+  if (Modifiers & OPCODE_M_IMMDATA) {\r
+    Size = 4;\r
+  } else {\r
+    Size = 2;\r
+  }\r
+\r
+  //\r
+  // Construct Disasm String\r
+  //\r
+  if (DisasmString != NULL) {\r
+    *DisasmString = EdbPreInstructionString ();\r
+\r
+    EdbPrintInstructionName (L"CMP");\r
+//    if (Modifiers & OPCODE_M_64BIT) {\r
+//      EdbPrintInstructionName (L"64");\r
+//    } else {\r
+//      EdbPrintInstructionName (L"32");\r
+//    }\r
+    switch (Opcode) {\r
+    case OPCODE_CMPEQ:\r
+      EdbPrintInstructionName (L"eq");\r
+      break;\r
+    case OPCODE_CMPLTE:\r
+      EdbPrintInstructionName (L"lte");\r
+      break;\r
+    case OPCODE_CMPGTE:\r
+      EdbPrintInstructionName (L"gte");\r
+      break;\r
+    case OPCODE_CMPULTE:\r
+      EdbPrintInstructionName (L"ulte");\r
+      break;\r
+    case OPCODE_CMPUGTE:\r
+      EdbPrintInstructionName (L"ugte");\r
+      break;\r
+    }\r
+\r
+    EdbPrintRegister1 (Operands);\r
+    InstructionAddress += 2;\r
+\r
+    EdbPrintComma ();\r
+    EdbPrintRegister2 (Operands);\r
+\r
+    if (Modifiers & OPCODE_M_IMMDATA) {\r
+      CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));\r
+      if (Operands & OPERAND_M_INDIRECT2) {\r
+        EdbPrintRawIndexData16 (Data16);\r
+      } else {\r
+        EdbPrintImmDatan (Data16);\r
+      }\r
+    }\r
+\r
+    EdbPostInstructionString ();\r
+  }\r
+\r
+  return Size;\r
+}\r
+\r
+UINTN\r
+EdbDisasmUnsignedDataManip (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisasmString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disasm instruction - Unsigned Data Manipulate\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - The instruction address\r
+  SystemContext      - EBC system context.\r
+  DisasmString       - The instruction string\r
+\r
+Returns:\r
+\r
+  Instruction length\r
+\r
+--*/\r
+{\r
+  UINT8  Modifiers;\r
+  UINT8  Opcode;\r
+  UINT8  Operands;\r
+  UINTN  Size;\r
+  UINT16 Data16;\r
+\r
+  ASSERT (\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_NOT)    ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_MULU)   ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_DIVU)   ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_MODU)   ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_AND)    ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_OR)     ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_XOR)    ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_SHL)    ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_SHR)    ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_EXTNDB) ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_EXTNDW) ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_EXTNDD)\r
+    );\r
+\r
+  Opcode     = GET_OPCODE (InstructionAddress);\r
+  Operands   = GET_OPERANDS (InstructionAddress);\r
+  Modifiers  = GET_MODIFIERS (InstructionAddress);\r
+  if (Modifiers & DATAMANIP_M_IMMDATA) {\r
+    Size = 4;\r
+  } else {\r
+    Size = 2;\r
+  }\r
+\r
+  //\r
+  // Construct Disasm String\r
+  //\r
+  if (DisasmString != NULL) {\r
+    *DisasmString = EdbPreInstructionString ();\r
+\r
+    switch (Opcode) {\r
+    case OPCODE_NOT:\r
+      EdbPrintInstructionName (L"NOT");\r
+      break;\r
+    case OPCODE_MULU:\r
+      EdbPrintInstructionName (L"MULU");\r
+      break;\r
+    case OPCODE_DIVU:\r
+      EdbPrintInstructionName (L"DIVU");\r
+      break;\r
+    case OPCODE_MODU:\r
+      EdbPrintInstructionName (L"MODU");\r
+      break;\r
+    case OPCODE_AND:\r
+      EdbPrintInstructionName (L"AND");\r
+      break;\r
+    case OPCODE_OR:\r
+      EdbPrintInstructionName (L"OR");\r
+      break;\r
+    case OPCODE_XOR:\r
+      EdbPrintInstructionName (L"XOR");\r
+      break;\r
+    case OPCODE_SHL:\r
+      EdbPrintInstructionName (L"SHL");\r
+      break;\r
+    case OPCODE_SHR:\r
+      EdbPrintInstructionName (L"SHR");\r
+      break;\r
+    case OPCODE_EXTNDB:\r
+      EdbPrintInstructionName (L"EXTNDB");\r
+      break;\r
+    case OPCODE_EXTNDW:\r
+      EdbPrintInstructionName (L"EXTNDW");\r
+      break;\r
+    case OPCODE_EXTNDD:\r
+      EdbPrintInstructionName (L"EXTNDD");\r
+      break;\r
+    }\r
+//    if (Modifiers & DATAMANIP_M_64) {\r
+//      EdbPrintInstructionName (L"64");\r
+//    } else {\r
+//      EdbPrintInstructionName (L"32");\r
+//    }\r
+\r
+    EdbPrintRegister1 (Operands);\r
+    EdbPrintComma ();\r
+    EdbPrintRegister2 (Operands);\r
+\r
+    InstructionAddress += 2;\r
+    if (Modifiers & DATAMANIP_M_IMMDATA) {\r
+      CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));\r
+      if (Operands & OPERAND_M_INDIRECT2) {\r
+        EdbPrintRawIndexData16 (Data16);\r
+      } else {\r
+        EdbPrintImmDatan (Data16);\r
+      }\r
+    }\r
+\r
+    EdbPostInstructionString ();\r
+  }\r
+\r
+  return Size;\r
+}\r
+\r
+UINTN\r
+EdbDisasmSignedDataManip (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisasmString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disasm instruction - Signed Data Manipulate\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - The instruction address\r
+  SystemContext      - EBC system context.\r
+  DisasmString       - The instruction string\r
+\r
+Returns:\r
+\r
+  Instruction length\r
+\r
+--*/\r
+{\r
+  UINT8  Modifiers;\r
+  UINT8  Opcode;\r
+  UINT8  Operands;\r
+  UINTN  Size;\r
+  UINT16 Data16;\r
+\r
+  ASSERT (\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_NEG)   ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_ADD)   ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_SUB)   ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_MUL)   ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_DIV)   ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_MOD)   ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_ASHR)\r
+    );\r
+\r
+  Opcode     = GET_OPCODE (InstructionAddress);\r
+  Operands   = GET_OPERANDS (InstructionAddress);\r
+  Modifiers  = GET_MODIFIERS (InstructionAddress);\r
+  if (Modifiers & DATAMANIP_M_IMMDATA) {\r
+    Size = 4;\r
+  } else {\r
+    Size = 2;\r
+  }\r
+\r
+  //\r
+  // Construct Disasm String\r
+  //\r
+  if (DisasmString != NULL) {\r
+    *DisasmString = EdbPreInstructionString ();\r
+\r
+    switch (Opcode) {\r
+    case OPCODE_NEG:\r
+      EdbPrintInstructionName (L"NEG");\r
+      break;\r
+    case OPCODE_ADD:\r
+      EdbPrintInstructionName (L"ADD");\r
+      break;\r
+    case OPCODE_SUB:\r
+      EdbPrintInstructionName (L"SUB");\r
+      break;\r
+    case OPCODE_MUL:\r
+      EdbPrintInstructionName (L"MUL");\r
+      break;\r
+    case OPCODE_DIV:\r
+      EdbPrintInstructionName (L"DIV");\r
+      break;\r
+    case OPCODE_MOD:\r
+      EdbPrintInstructionName (L"MOD");\r
+      break;\r
+    case OPCODE_ASHR:\r
+      EdbPrintInstructionName (L"ASHR");\r
+      break;\r
+    }\r
+//    if (Modifiers & DATAMANIP_M_64) {\r
+//      EdbPrintInstructionName (L"64");\r
+//    } else {\r
+//      EdbPrintInstructionName (L"32");\r
+//    }\r
+\r
+    EdbPrintRegister1 (Operands);\r
+    EdbPrintComma ();\r
+    EdbPrintRegister2 (Operands);\r
+\r
+    InstructionAddress += 2;\r
+    if (Modifiers & DATAMANIP_M_IMMDATA) {\r
+      CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));\r
+      if (Operands & OPERAND_M_INDIRECT2) {\r
+        EdbPrintRawIndexData16 (Data16);\r
+      } else {\r
+        EdbPrintImmDatan (Data16);\r
+      }\r
+    }\r
+\r
+    EdbPostInstructionString ();\r
+  }\r
+\r
+  return Size;\r
+}\r
+\r
+UINTN\r
+EdbDisasmMOVxx (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisasmString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disasm instruction - MOVxx\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - The instruction address\r
+  SystemContext      - EBC system context.\r
+  DisasmString       - The instruction string\r
+\r
+Returns:\r
+\r
+  Instruction length\r
+\r
+--*/\r
+{\r
+  UINT8   Modifiers;\r
+  UINT8   Opcode;\r
+  UINT8   Operands;\r
+  UINTN   Size;\r
+  UINT16  Data16;\r
+  UINT32  Data32;\r
+  UINT64  Data64;\r
+\r
+  ASSERT (\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_MOVBW)   ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_MOVWW)   ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_MOVDW)   ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_MOVQW)   ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_MOVBD)   ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_MOVWD)   ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_MOVDD)   ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_MOVQD)   ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_MOVQQ)   ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_MOVNW)   ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_MOVND)\r
+    );\r
+\r
+  Opcode     = GET_OPCODE (InstructionAddress);\r
+  Modifiers  = GET_MODIFIERS (InstructionAddress);\r
+  Operands   = GET_OPERANDS (InstructionAddress);\r
+  Size = 2;\r
+  if (Modifiers & (OPCODE_M_IMMED_OP1 | OPCODE_M_IMMED_OP2)) {\r
+    if ((Opcode <= OPCODE_MOVQW) || (Opcode == OPCODE_MOVNW)) {\r
+      if (Modifiers & OPCODE_M_IMMED_OP1) {\r
+        Size += 2;\r
+      }\r
+      if (Modifiers & OPCODE_M_IMMED_OP2) {\r
+        Size += 2;\r
+      }\r
+    } else if ((Opcode <= OPCODE_MOVQD) || (Opcode == OPCODE_MOVND)) {\r
+      if (Modifiers & OPCODE_M_IMMED_OP1) {\r
+        Size += 4;\r
+      }\r
+      if (Modifiers & OPCODE_M_IMMED_OP2) {\r
+        Size += 4;\r
+      }\r
+    } else if (Opcode == OPCODE_MOVQQ) {\r
+      if (Modifiers & OPCODE_M_IMMED_OP1) {\r
+        Size += 8;\r
+      }\r
+      if (Modifiers & OPCODE_M_IMMED_OP2) {\r
+        Size += 8;\r
+      }\r
+    }\r
+  }\r
+\r
+  //\r
+  // Construct Disasm String\r
+  //\r
+  if (DisasmString != NULL) {\r
+    *DisasmString = EdbPreInstructionString ();\r
+\r
+    EdbPrintInstructionName (L"MOV");\r
+    switch (Opcode) {\r
+    case OPCODE_MOVBW:\r
+      EdbPrintInstructionName (L"bw");\r
+      break;\r
+    case OPCODE_MOVWW:\r
+      EdbPrintInstructionName (L"ww");\r
+      break;\r
+    case OPCODE_MOVDW:\r
+      EdbPrintInstructionName (L"dw");\r
+      break;\r
+    case OPCODE_MOVQW:\r
+      EdbPrintInstructionName (L"qw");\r
+      break;\r
+    case OPCODE_MOVBD:\r
+      EdbPrintInstructionName (L"bd");\r
+      break;\r
+    case OPCODE_MOVWD:\r
+      EdbPrintInstructionName (L"wd");\r
+      break;\r
+    case OPCODE_MOVDD:\r
+      EdbPrintInstructionName (L"dd");\r
+      break;\r
+    case OPCODE_MOVQD:\r
+      EdbPrintInstructionName (L"qd");\r
+      break;\r
+    case OPCODE_MOVQQ:\r
+      EdbPrintInstructionName (L"qq");\r
+      break;\r
+    case OPCODE_MOVNW:\r
+      EdbPrintInstructionName (L"nw");\r
+      break;\r
+    case OPCODE_MOVND:\r
+      EdbPrintInstructionName (L"nd");\r
+      break;\r
+    }\r
+\r
+    EdbPrintRegister1 (Operands);\r
+\r
+    InstructionAddress += 2;\r
+    if (Modifiers & OPCODE_M_IMMED_OP1) {\r
+      if ((Opcode <= OPCODE_MOVQW) || (Opcode == OPCODE_MOVNW)) {\r
+        CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));\r
+        InstructionAddress += 2;\r
+        EdbPrintRawIndexData16 (Data16);\r
+      } else if ((Opcode <= OPCODE_MOVQD) || (Opcode == OPCODE_MOVND)) {\r
+        CopyMem (&Data32, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT32));\r
+        InstructionAddress += 4;\r
+        EdbPrintRawIndexData32 (Data32);\r
+      } else if (Opcode == OPCODE_MOVQQ) {\r
+        CopyMem (&Data64, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT64));\r
+        InstructionAddress += 8;\r
+        EdbPrintRawIndexData64 (Data64);\r
+      }\r
+    }\r
+\r
+    EdbPrintComma ();\r
+    EdbPrintRegister2 (Operands);\r
+\r
+    if (Modifiers & OPCODE_M_IMMED_OP2) {\r
+      if ((Opcode <= OPCODE_MOVQW) || (Opcode == OPCODE_MOVNW)) {\r
+        CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));\r
+        EdbPrintRawIndexData16 (Data16);\r
+      } else if ((Opcode <= OPCODE_MOVQD) || (Opcode == OPCODE_MOVND)) {\r
+        CopyMem (&Data32, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT32));\r
+        EdbPrintRawIndexData32 (Data32);\r
+      } else if (Opcode == OPCODE_MOVQQ) {\r
+        CopyMem (&Data64, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT64));\r
+        EdbPrintRawIndexData64 (Data64);\r
+      }\r
+    }\r
+\r
+    EdbPostInstructionString ();\r
+  }\r
+\r
+  return Size;\r
+}\r
+\r
+UINTN\r
+EdbDisasmMOVsnw (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisasmString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disasm instruction - MOVsnw\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - The instruction address\r
+  SystemContext      - EBC system context.\r
+  DisasmString       - The instruction string\r
+\r
+Returns:\r
+\r
+  Instruction length\r
+\r
+--*/\r
+{\r
+  UINT8  Modifiers;\r
+  UINT8  Operands;\r
+  UINTN  Size;\r
+  UINT16 Data16;\r
+\r
+  ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_MOVSNW);\r
+\r
+  Modifiers  = GET_MODIFIERS (InstructionAddress);\r
+  Operands   = GET_OPERANDS (InstructionAddress);\r
+  Size = 2;\r
+  if (Modifiers & OPCODE_M_IMMED_OP1) {\r
+    Size += 2;\r
+  }\r
+  if (Modifiers & OPCODE_M_IMMED_OP2) {\r
+    Size += 2;\r
+  }\r
+\r
+  //\r
+  // Construct Disasm String\r
+  //\r
+  if (DisasmString != NULL) {\r
+    *DisasmString = EdbPreInstructionString ();\r
+\r
+    EdbPrintInstructionName (L"MOVsnw");\r
+\r
+    EdbPrintRegister1 (Operands);\r
+\r
+    InstructionAddress += 2;\r
+    if (Modifiers & OPCODE_M_IMMED_OP1) {\r
+      CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));\r
+      InstructionAddress += 2;\r
+      EdbPrintRawIndexData16 (Data16);\r
+    }\r
+\r
+    EdbPrintComma ();\r
+    EdbPrintRegister2 (Operands);\r
+\r
+    if (Modifiers & OPCODE_M_IMMED_OP2) {\r
+      CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));\r
+      if (Operands & OPERAND_M_INDIRECT2) {\r
+        EdbPrintRawIndexData16 (Data16);\r
+      } else {\r
+        EdbPrintImmDatan (Data16);\r
+      }\r
+    }\r
+\r
+    EdbPostInstructionString ();\r
+  }\r
+\r
+  return Size;\r
+}\r
+\r
+UINTN\r
+EdbDisasmMOVsnd (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisasmString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disasm instruction - MOVsnd\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - The instruction address\r
+  SystemContext      - EBC system context.\r
+  DisasmString       - The instruction string\r
+\r
+Returns:\r
+\r
+  Instruction length\r
+\r
+--*/\r
+{\r
+  UINT8  Modifiers;\r
+  UINT8  Operands;\r
+  UINTN  Size;\r
+  UINT32 Data32;\r
+\r
+  ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_MOVSND);\r
+\r
+  Modifiers  = GET_MODIFIERS (InstructionAddress);\r
+  Operands   = GET_OPERANDS (InstructionAddress);\r
+  Size = 2;\r
+  if (Modifiers & OPCODE_M_IMMED_OP1) {\r
+    Size += 4;\r
+  }\r
+  if (Modifiers & OPCODE_M_IMMED_OP2) {\r
+    Size += 4;\r
+  }\r
+\r
+  //\r
+  // Construct Disasm String\r
+  //\r
+  if (DisasmString != NULL) {\r
+    *DisasmString = EdbPreInstructionString ();\r
+\r
+    EdbPrintInstructionName (L"MOVsnd");\r
+\r
+    EdbPrintRegister1 (Operands);\r
+\r
+    InstructionAddress += 2;\r
+    if (Modifiers & OPCODE_M_IMMED_OP1) {\r
+      CopyMem (&Data32, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT32));\r
+      InstructionAddress += 4;\r
+      EdbPrintRawIndexData32 (Data32);\r
+    }\r
+\r
+    EdbPrintComma ();\r
+    EdbPrintRegister2 (Operands);\r
+\r
+    if (Modifiers & OPCODE_M_IMMED_OP2) {\r
+      CopyMem (&Data32, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT32));\r
+      if (Operands & OPERAND_M_INDIRECT2) {\r
+        EdbPrintRawIndexData32 (Data32);\r
+      } else {\r
+        EdbPrintImmDatan (Data32);\r
+      }\r
+    }\r
+\r
+    EdbPostInstructionString ();\r
+  }\r
+\r
+  return Size;\r
+}\r
+\r
+UINTN\r
+EdbDisasmLOADSP (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisasmString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disasm instruction - LOADSP\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - The instruction address\r
+  SystemContext      - EBC system context.\r
+  DisasmString       - The instruction string\r
+\r
+Returns:\r
+\r
+  Instruction length\r
+\r
+--*/\r
+{\r
+  UINT8  Operands;\r
+\r
+  ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_LOADSP);\r
+\r
+  Operands   = GET_OPERANDS (InstructionAddress);\r
+\r
+  //\r
+  // Construct Disasm String\r
+  //\r
+  if (DisasmString != NULL) {\r
+    *DisasmString = EdbPreInstructionString ();\r
+\r
+    EdbPrintInstructionName (L"LOADSP");\r
+\r
+    EdbPrintDedicatedRegister1 (Operands);\r
+\r
+    EdbPrintRegister2 (Operands);\r
+\r
+    EdbPostInstructionString ();\r
+  }\r
+\r
+  return 2;\r
+}\r
+\r
+UINTN\r
+EdbDisasmSTORESP (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisasmString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disasm instruction - STORESP\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - The instruction address\r
+  SystemContext      - EBC system context.\r
+  DisasmString       - The instruction string\r
+\r
+Returns:\r
+\r
+  Instruction length\r
+\r
+--*/\r
+{\r
+  UINT8  Operands;\r
+\r
+  ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_STORESP);\r
+\r
+  Operands   = GET_OPERANDS (InstructionAddress);\r
+\r
+  //\r
+  // Construct Disasm String\r
+  //\r
+  if (DisasmString != NULL) {\r
+    *DisasmString = EdbPreInstructionString ();\r
+\r
+    EdbPrintInstructionName (L"STORESP");\r
+\r
+    EdbPrintRegister1 (Operands);\r
+\r
+    EdbPrintDedicatedRegister2 (Operands);\r
+\r
+    EdbPostInstructionString ();\r
+  }\r
+\r
+  return 2;\r
+}\r
+\r
+UINTN\r
+EdbDisasmPUSH (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisasmString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disasm instruction - PUSH\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - The instruction address\r
+  SystemContext      - EBC system context.\r
+  DisasmString       - The instruction string\r
+\r
+Returns:\r
+\r
+  Instruction length\r
+\r
+--*/\r
+{\r
+  UINT8  Modifiers;\r
+  UINT8  Operands;\r
+  UINTN  Size;\r
+  UINT16 Data16;\r
+\r
+  ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_PUSH);\r
+\r
+  Operands   = GET_OPERANDS (InstructionAddress);\r
+  Modifiers  = GET_MODIFIERS (InstructionAddress);\r
+  if (Modifiers & PUSHPOP_M_IMMDATA) {\r
+    Size = 4;\r
+  } else {\r
+    Size = 2;\r
+  }\r
+\r
+  //\r
+  // Construct Disasm String\r
+  //\r
+  if (DisasmString != NULL) {\r
+    *DisasmString = EdbPreInstructionString ();\r
+\r
+    EdbPrintInstructionName (L"PUSH");\r
+//    if (Modifiers & PUSHPOP_M_64) {\r
+//      EdbPrintInstructionName (L"64");\r
+//    } else {\r
+//      EdbPrintInstructionName (L"32");\r
+//    }\r
+\r
+    EdbPrintRegister1 (Operands);\r
+\r
+    InstructionAddress += 2;\r
+    if (Modifiers & PUSHPOP_M_IMMDATA) {\r
+      CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));\r
+      if (Operands & OPERAND_M_INDIRECT1) {\r
+        EdbPrintRawIndexData16 (Data16);\r
+      } else {\r
+        EdbPrintImmDatan (Data16);\r
+      }\r
+    }\r
+\r
+    EdbPostInstructionString ();\r
+  }\r
+\r
+  return Size;\r
+}\r
+\r
+UINTN\r
+EdbDisasmPOP (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisasmString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disasm instruction - POP\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - The instruction address\r
+  SystemContext      - EBC system context.\r
+  DisasmString       - The instruction string\r
+\r
+Returns:\r
+\r
+  Instruction length\r
+\r
+--*/\r
+{\r
+  UINT8  Modifiers;\r
+  UINT8  Operands;\r
+  UINTN  Size;\r
+  UINT16 Data16;\r
+\r
+  ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_POP);\r
+\r
+  Operands   = GET_OPERANDS (InstructionAddress);\r
+  Modifiers  = GET_MODIFIERS (InstructionAddress);\r
+  if (Modifiers & PUSHPOP_M_IMMDATA) {\r
+    Size = 4;\r
+  } else {\r
+    Size = 2;\r
+  }\r
+\r
+  //\r
+  // Construct Disasm String\r
+  //\r
+  if (DisasmString != NULL) {\r
+    *DisasmString = EdbPreInstructionString ();\r
+\r
+    EdbPrintInstructionName (L"POP");\r
+//    if (Modifiers & PUSHPOP_M_64) {\r
+//      EdbPrintInstructionName (L"64");\r
+//    } else {\r
+//      EdbPrintInstructionName (L"32");\r
+//    }\r
+\r
+    EdbPrintRegister1 (Operands);\r
+\r
+    InstructionAddress += 2;\r
+    if (Modifiers & PUSHPOP_M_IMMDATA) {\r
+      CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));\r
+      if (Operands & OPERAND_M_INDIRECT1) {\r
+        EdbPrintRawIndexData16 (Data16);\r
+      } else {\r
+        EdbPrintImmDatan (Data16);\r
+      }\r
+    }\r
+\r
+    EdbPostInstructionString ();\r
+  }\r
+\r
+  return Size;\r
+}\r
+\r
+UINTN\r
+EdbDisasmCMPI (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisasmString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disasm instruction - CMPI\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - The instruction address\r
+  SystemContext      - EBC system context.\r
+  DisasmString       - The instruction string\r
+\r
+Returns:\r
+\r
+  Instruction length\r
+\r
+--*/\r
+{\r
+  UINT8  Modifiers;\r
+  UINT8  Opcode;\r
+  UINT8  Operands;\r
+  UINT16 Data16;\r
+  UINT32 Data32;\r
+  UINTN  Size;\r
+\r
+  ASSERT (\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_CMPIEQ)   ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_CMPILTE)  ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_CMPIGTE)  ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_CMPIULTE) ||\r
+    (GET_OPCODE(InstructionAddress) == OPCODE_CMPIUGTE)\r
+    );\r
+\r
+  Modifiers  = GET_MODIFIERS (InstructionAddress);\r
+  Opcode     = GET_OPCODE (InstructionAddress);\r
+  Operands   = GET_OPERANDS (InstructionAddress);\r
+\r
+  if ((Operands & 0xE0) != 0) {\r
+    return 0;\r
+  }\r
+\r
+  Size = 2;\r
+  if (Operands & OPERAND_M_CMPI_INDEX) {\r
+    Size += 2;\r
+  }\r
+  if (Modifiers & OPCODE_M_CMPI32_DATA) {\r
+    Size += 4;\r
+  } else {\r
+    Size += 2;\r
+  }\r
+\r
+  //\r
+  // Construct Disasm String\r
+  //\r
+  if (DisasmString != NULL) {\r
+    *DisasmString = EdbPreInstructionString ();\r
+\r
+    EdbPrintInstructionName (L"CMPI");\r
+//    if (Modifiers & OPCODE_M_CMPI64) {\r
+//      EdbPrintInstructionName (L"64");\r
+//    } else {\r
+//      EdbPrintInstructionName (L"32");\r
+//    }\r
+    if (Modifiers & OPCODE_M_CMPI32_DATA) {\r
+      EdbPrintInstructionName (L"d");\r
+    } else {\r
+      EdbPrintInstructionName (L"w");\r
+    }\r
+    switch (Opcode) {\r
+    case OPCODE_CMPIEQ:\r
+      EdbPrintInstructionName (L"eq");\r
+      break;\r
+    case OPCODE_CMPILTE:\r
+      EdbPrintInstructionName (L"lte");\r
+      break;\r
+    case OPCODE_CMPIGTE:\r
+      EdbPrintInstructionName (L"gte");\r
+      break;\r
+    case OPCODE_CMPIULTE:\r
+      EdbPrintInstructionName (L"ulte");\r
+      break;\r
+    case OPCODE_CMPIUGTE:\r
+      EdbPrintInstructionName (L"ugte");\r
+      break;\r
+    }\r
+\r
+    EdbPrintRegister1 (Operands);\r
+\r
+    InstructionAddress += 2;\r
+    if (Operands & OPERAND_M_CMPI_INDEX) {\r
+      CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));\r
+      InstructionAddress += 2;\r
+      EdbPrintRawIndexData16 (Data16);\r
+    }\r
+\r
+    EdbPrintComma ();\r
+\r
+    if (Modifiers & OPCODE_M_CMPI32_DATA) {\r
+      CopyMem (&Data32, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT32));\r
+      EdbPrintDatan (Data32);\r
+    } else {\r
+      CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));\r
+      EdbPrintDatan (Data16);\r
+    }\r
+\r
+    EdbPostInstructionString ();\r
+  }\r
+\r
+  return Size;\r
+}\r
+\r
+UINTN\r
+EdbDisasmPUSHn (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisasmString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disasm instruction - PUSHn\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - The instruction address\r
+  SystemContext      - EBC system context.\r
+  DisasmString       - The instruction string\r
+\r
+Returns:\r
+\r
+  Instruction length\r
+\r
+--*/\r
+{\r
+  UINT8  Modifiers;\r
+  UINT8  Operands;\r
+  UINTN  Size;\r
+  UINT16 Data16;\r
+\r
+  ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_PUSHN);\r
+\r
+  Operands   = GET_OPERANDS (InstructionAddress);\r
+  Modifiers  = GET_MODIFIERS (InstructionAddress);\r
+  if (Modifiers & PUSHPOP_M_IMMDATA) {\r
+    Size = 4;\r
+  } else {\r
+    Size = 2;\r
+  }\r
+\r
+  //\r
+  // Construct Disasm String\r
+  //\r
+  if (DisasmString != NULL) {\r
+    *DisasmString = EdbPreInstructionString ();\r
+\r
+    EdbPrintInstructionName (L"PUSHn");\r
+\r
+    EdbPrintRegister1 (Operands);\r
+\r
+    InstructionAddress += 2;\r
+    if (Modifiers & PUSHPOP_M_IMMDATA) {\r
+      CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));\r
+      if (Operands & OPERAND_M_INDIRECT1) {\r
+        EdbPrintRawIndexData16 (Data16);\r
+      } else {\r
+        EdbPrintImmDatan (Data16);\r
+      }\r
+    }\r
+\r
+    EdbPostInstructionString ();\r
+  }\r
+\r
+  return Size;\r
+}\r
+\r
+UINTN\r
+EdbDisasmPOPn (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisasmString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disasm instruction - POPn\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - The instruction address\r
+  SystemContext      - EBC system context.\r
+  DisasmString       - The instruction string\r
+\r
+Returns:\r
+\r
+  Instruction length\r
+\r
+--*/\r
+{\r
+  UINT8  Modifiers;\r
+  UINT8  Operands;\r
+  UINTN  Size;\r
+  UINT16 Data16;\r
+\r
+  ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_POPN);\r
+\r
+  Operands   = GET_OPERANDS (InstructionAddress);\r
+  Modifiers  = GET_MODIFIERS (InstructionAddress);\r
+  if (Modifiers & PUSHPOP_M_IMMDATA) {\r
+    Size = 4;\r
+  } else {\r
+    Size = 2;\r
+  }\r
+\r
+  //\r
+  // Construct Disasm String\r
+  //\r
+  if (DisasmString != NULL) {\r
+    *DisasmString = EdbPreInstructionString ();\r
+\r
+    EdbPrintInstructionName (L"POPn");\r
+\r
+    EdbPrintRegister1 (Operands);\r
+\r
+    InstructionAddress += 2;\r
+    if (Modifiers & PUSHPOP_M_IMMDATA) {\r
+      CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));\r
+      if (Operands & OPERAND_M_INDIRECT1) {\r
+        EdbPrintRawIndexData16 (Data16);\r
+      } else {\r
+        EdbPrintImmDatan (Data16);\r
+      }\r
+    }\r
+\r
+    EdbPostInstructionString ();\r
+  }\r
+\r
+  return Size;\r
+}\r
+\r
+UINTN\r
+EdbDisasmMOVI (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisasmString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disasm instruction - MOVI\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - The instruction address\r
+  SystemContext      - EBC system context.\r
+  DisasmString       - The instruction string\r
+\r
+Returns:\r
+\r
+  Instruction length\r
+\r
+--*/\r
+{\r
+  UINT8  Modifiers;\r
+  UINT8  Operands;\r
+  UINTN  Size;\r
+  UINT16 Data16;\r
+  UINT32 Data32;\r
+  UINT64 Data64;\r
+\r
+  ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_MOVI);\r
+\r
+  Modifiers  = GET_MODIFIERS (InstructionAddress);\r
+  Operands   = GET_OPERANDS (InstructionAddress);\r
+\r
+  if (Operands & MOVI_M_IMMDATA) {\r
+    Size    = 4;\r
+  } else {\r
+    Size    = 2;\r
+  }\r
+  if ((Modifiers & MOVI_M_DATAWIDTH) == MOVI_DATAWIDTH16) {\r
+    Size += 2;\r
+  } else if ((Modifiers & MOVI_M_DATAWIDTH) == MOVI_DATAWIDTH32) {\r
+    Size += 4;\r
+  } else if ((Modifiers & MOVI_M_DATAWIDTH) == MOVI_DATAWIDTH64) {\r
+    Size += 8;\r
+  }\r
+\r
+  //\r
+  // Construct Disasm String\r
+  //\r
+  if (DisasmString != NULL) {\r
+    *DisasmString = EdbPreInstructionString ();\r
+\r
+    EdbPrintInstructionName (L"MOVI");\r
+    switch (Operands & MOVI_M_MOVEWIDTH) {\r
+    case MOVI_MOVEWIDTH8:\r
+      EdbPrintInstructionName (L"b");\r
+      break;\r
+    case MOVI_MOVEWIDTH16:\r
+      EdbPrintInstructionName (L"w");\r
+      break;\r
+    case MOVI_MOVEWIDTH32:\r
+      EdbPrintInstructionName (L"d");\r
+      break;\r
+    case MOVI_MOVEWIDTH64:\r
+      EdbPrintInstructionName (L"q");\r
+      break;\r
+    }\r
+    switch (Modifiers & MOVI_M_DATAWIDTH) {\r
+    case MOVI_DATAWIDTH16:\r
+      EdbPrintInstructionName (L"w");\r
+      break;\r
+    case MOVI_DATAWIDTH32:\r
+      EdbPrintInstructionName (L"d");\r
+      break;\r
+    case MOVI_DATAWIDTH64:\r
+      EdbPrintInstructionName (L"q");\r
+      break;\r
+    }\r
+\r
+    EdbPrintRegister1 (Operands);\r
+\r
+    InstructionAddress += 2;\r
+    if (Operands & MOVI_M_IMMDATA) {\r
+      CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));\r
+      InstructionAddress += 2;\r
+      EdbPrintRawIndexData16 (Data16);\r
+    }\r
+\r
+    EdbPrintComma ();\r
+\r
+    switch (Modifiers & MOVI_M_DATAWIDTH) {\r
+    case MOVI_DATAWIDTH16:\r
+      CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));\r
+      EdbPrintDatan (Data16);\r
+      break;\r
+    case MOVI_DATAWIDTH32:\r
+      CopyMem (&Data32, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT32));\r
+      EdbPrintDatan (Data32);\r
+      break;\r
+    case MOVI_DATAWIDTH64:\r
+      CopyMem (&Data64, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT64));\r
+      EdbPrintData64n (Data64);\r
+      break;\r
+    }\r
+\r
+    EdbPostInstructionString ();\r
+  }\r
+\r
+  return Size;\r
+}\r
+\r
+UINTN\r
+EdbDisasmMOVIn (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisasmString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disasm instruction - MOVIn\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - The instruction address\r
+  SystemContext      - EBC system context.\r
+  DisasmString       - The instruction string\r
+\r
+Returns:\r
+\r
+  Instruction length\r
+\r
+--*/\r
+{\r
+  UINT8  Modifiers;\r
+  UINT8  Operands;\r
+  UINTN  Size;\r
+  UINT16 Data16;\r
+  UINT32 Data32;\r
+  UINT64 Data64;\r
+\r
+  ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_MOVIN);\r
+\r
+  Modifiers  = GET_MODIFIERS (InstructionAddress);\r
+  Operands   = GET_OPERANDS (InstructionAddress);\r
+\r
+  if (Operands & MOVI_M_IMMDATA) {\r
+    Size    = 4;\r
+  } else {\r
+    Size    = 2;\r
+  }\r
+  if ((Modifiers & MOVI_M_DATAWIDTH) == MOVI_DATAWIDTH16) {\r
+    Size += 2;\r
+  } else if ((Modifiers & MOVI_M_DATAWIDTH) == MOVI_DATAWIDTH32) {\r
+    Size += 4;\r
+  } else if ((Modifiers & MOVI_M_DATAWIDTH) == MOVI_DATAWIDTH64) {\r
+    Size += 8;\r
+  }\r
+\r
+  //\r
+  // Construct Disasm String\r
+  //\r
+  if (DisasmString != NULL) {\r
+    *DisasmString = EdbPreInstructionString ();\r
+\r
+    EdbPrintInstructionName (L"MOVIn");\r
+    switch (Modifiers & MOVI_M_DATAWIDTH) {\r
+    case MOVI_DATAWIDTH16:\r
+      EdbPrintInstructionName (L"w");\r
+      break;\r
+    case MOVI_DATAWIDTH32:\r
+      EdbPrintInstructionName (L"d");\r
+      break;\r
+    case MOVI_DATAWIDTH64:\r
+      EdbPrintInstructionName (L"q");\r
+      break;\r
+    }\r
+\r
+    EdbPrintRegister1 (Operands);\r
+\r
+    InstructionAddress += 2;\r
+    if (Operands & MOVI_M_IMMDATA) {\r
+      CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));\r
+      InstructionAddress += 2;\r
+      EdbPrintRawIndexData16 (Data16);\r
+    }\r
+\r
+    EdbPrintComma ();\r
+\r
+    switch (Modifiers & MOVI_M_DATAWIDTH) {\r
+    case MOVI_DATAWIDTH16:\r
+      CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));\r
+      EdbPrintRawIndexData16 (Data16);\r
+      break;\r
+    case MOVI_DATAWIDTH32:\r
+      CopyMem (&Data32, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT32));\r
+      EdbPrintRawIndexData32 (Data32);\r
+      break;\r
+    case MOVI_DATAWIDTH64:\r
+      CopyMem (&Data64, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT64));\r
+      EdbPrintRawIndexData64 (Data64);\r
+      break;\r
+    }\r
+\r
+    EdbPostInstructionString ();\r
+  }\r
+\r
+  return Size;\r
+}\r
+\r
+UINTN\r
+EdbDisasmMOVREL (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisasmString\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Disasm instruction - MOVREL\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - The instruction address\r
+  SystemContext      - EBC system context.\r
+  DisasmString       - The instruction string\r
+\r
+Returns:\r
+\r
+  Instruction length\r
+\r
+--*/\r
+{\r
+  UINT8   Modifiers;\r
+  UINT8   Operands;\r
+  UINTN   Size;\r
+  UINT16  Data16;\r
+  UINT32  Data32;\r
+  UINT64  Data64;\r
+  UINTN   Result;\r
+  EFI_PHYSICAL_ADDRESS      SavedInstructionAddress;\r
+\r
+  ASSERT (GET_OPCODE(InstructionAddress) == OPCODE_MOVREL);\r
+  SavedInstructionAddress = InstructionAddress;\r
+\r
+  Modifiers  = GET_MODIFIERS (InstructionAddress);\r
+  Operands   = GET_OPERANDS (InstructionAddress);\r
+\r
+  if (Operands & MOVI_M_IMMDATA) {\r
+    Size    = 4;\r
+  } else {\r
+    Size    = 2;\r
+  }\r
+  if ((Modifiers & MOVI_M_DATAWIDTH) == MOVI_DATAWIDTH16) {\r
+    Size += 2;\r
+  } else if ((Modifiers & MOVI_M_DATAWIDTH) == MOVI_DATAWIDTH32) {\r
+    Size += 4;\r
+  } else if ((Modifiers & MOVI_M_DATAWIDTH) == MOVI_DATAWIDTH64) {\r
+    Size += 8;\r
+  } else {\r
+    return 0;\r
+  }\r
+\r
+  //\r
+  // Construct Disasm String\r
+  //\r
+  if (DisasmString != NULL) {\r
+    *DisasmString = EdbPreInstructionString ();\r
+\r
+    EdbPrintInstructionName (L"MOVrel");\r
+    switch (Modifiers & MOVI_M_DATAWIDTH) {\r
+    case MOVI_DATAWIDTH16:\r
+      EdbPrintInstructionName (L"w");\r
+      break;\r
+    case MOVI_DATAWIDTH32:\r
+      EdbPrintInstructionName (L"d");\r
+      break;\r
+    case MOVI_DATAWIDTH64:\r
+      EdbPrintInstructionName (L"q");\r
+      break;\r
+    }\r
+\r
+    EdbPrintRegister1 (Operands);\r
+\r
+    InstructionAddress += 2;\r
+    if (Operands & MOVI_M_IMMDATA) {\r
+      CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));\r
+      InstructionAddress += 2;\r
+      EdbPrintRawIndexData16 (Data16);\r
+    }\r
+\r
+    EdbPrintComma ();\r
+\r
+    switch (Modifiers & MOVI_M_DATAWIDTH) {\r
+    case MOVI_DATAWIDTH16:\r
+      CopyMem (&Data16, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT16));\r
+      Result = EdbFindAndPrintSymbol ((UINTN)(SavedInstructionAddress + Size + (INT16)Data16));\r
+      if (Result == 0) {\r
+        EdbPrintData16 (Data16);\r
+      }\r
+      break;\r
+    case MOVI_DATAWIDTH32:\r
+      CopyMem (&Data32, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT32));\r
+      Result = EdbFindAndPrintSymbol ((UINTN)(SavedInstructionAddress + Size + (INT32)Data32));\r
+      if (Result == 0) {\r
+        EdbPrintData32 (Data32);\r
+      }\r
+      break;\r
+    case MOVI_DATAWIDTH64:\r
+      CopyMem (&Data64, (VOID *)(UINTN)(InstructionAddress), sizeof(UINT64));\r
+      if (sizeof(UINTN) == sizeof(UINT64)) {\r
+        Result = EdbFindAndPrintSymbol ((UINTN)(SavedInstructionAddress + Size + (INT64)Data64));\r
+      } else {\r
+        Result = 0;\r
+      }\r
+      if (Result == 0) {\r
+        EdbPrintData64 (Data64);\r
+      }\r
+      break;\r
+    }\r
+\r
+    EdbPostInstructionString ();\r
+  }\r
+\r
+  return Size;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbDisasm.h b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbDisasm.h
new file mode 100644 (file)
index 0000000..1897e1c
--- /dev/null
@@ -0,0 +1,42 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbDisasm.h\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#ifndef _EFI_EDB_DISASM_H_\r
+#define _EFI_EDB_DISASM_H_\r
+\r
+#include <Uefi.h>\r
+\r
+//\r
+// Definition for instruction OPCODE, MODIFIER, and OPERAND\r
+//\r
+#define GET_OPCODE(Addr)       (UINT8)((*(UINT8 *)(UINTN)(Addr)) & 0x3F)\r
+#define GET_MODIFIERS(Addr)    (UINT8)((*(UINT8 *)(UINTN)(Addr)) & 0xC0)\r
+#define GET_OPCODE_BYTE(Addr)  (UINT8)(*(UINT8 *)(UINTN)(Addr))\r
+#define GET_OPERANDS(Addr)     (UINT8)(*(UINT8 *)(UINTN)((Addr) + 1))\r
+\r
+typedef\r
+UINTN\r
+(* EDB_DISASM_INSTRUCTION) (\r
+  IN     EFI_PHYSICAL_ADDRESS      InstructionAddress,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  OUT    CHAR16                    **DisAsmString\r
+  );\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbDisasmSupport.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbDisasmSupport.c
new file mode 100644 (file)
index 0000000..81e970e
--- /dev/null
@@ -0,0 +1,1461 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbDisasmSupport.c\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#include "Edb.h"\r
+\r
+extern EDB_DISASM_INSTRUCTION mEdbDisasmInstructionTable[];\r
+\r
+typedef struct {\r
+  CHAR16    Name[EDB_INSTRUCTION_NAME_MAX_LENGTH];\r
+  CHAR16    Content[EDB_INSTRUCTION_CONTENT_MAX_LENGTH];\r
+  CHAR16    Tail;\r
+} EDB_INSTRUCTION_STRING;\r
+\r
+EDB_INSTRUCTION_STRING mInstructionString;\r
+UINTN                  mInstructionNameOffset;\r
+UINTN                  mInstructionContentOffset;\r
+\r
+VOID\r
+EdbSetOffset (\r
+  IN UINTN InstructionNameOffset,\r
+  IN UINTN InstructionContentOffset\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Set offset for Instruction name and content\r
+\r
+Arguments:\r
+\r
+  InstructionNameOffset     - Instruction name offset\r
+  InstructionContentOffset  - Instruction content offset\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  mInstructionNameOffset = InstructionNameOffset;\r
+  mInstructionContentOffset = InstructionContentOffset;\r
+\r
+  return ;\r
+}\r
+\r
+CHAR16 *\r
+EdbPreInstructionString (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Pre instruction string construction\r
+\r
+Arguments:\r
+\r
+  None\r
+\r
+Returns:\r
+\r
+  Instruction string\r
+\r
+--*/\r
+{\r
+  ZeroMem (&mInstructionString, sizeof(mInstructionString));\r
+  mInstructionNameOffset    = 0;\r
+  mInstructionContentOffset = 0;\r
+\r
+  return (CHAR16 *)&mInstructionString;\r
+}\r
+\r
+CHAR16 *\r
+EdbPostInstructionString (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Post instruction string construction\r
+\r
+Arguments:\r
+\r
+  None\r
+\r
+Returns:\r
+\r
+  Instruction string\r
+\r
+--*/\r
+{\r
+  CHAR16 *Char;\r
+\r
+  for (Char = (CHAR16 *)&mInstructionString; Char < &mInstructionString.Tail; Char++) {\r
+    if (*Char == 0) {\r
+      *Char = L' ';\r
+    }\r
+  }\r
+  mInstructionString.Tail = 0;\r
+\r
+  mInstructionNameOffset    = 0;\r
+  mInstructionContentOffset = 0;\r
+\r
+  return (CHAR16 *)&mInstructionString;\r
+}\r
+\r
+BOOLEAN\r
+EdbGetNaturalIndex16 (\r
+  IN  UINT16  Data16,\r
+  OUT UINTN   *NaturalUnits,\r
+  OUT UINTN   *ConstantUnits\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Get Sign, NaturalUnits, and ConstantUnits of the WORD data\r
+\r
+Arguments:\r
+\r
+  Data16        - WORD data\r
+  NaturalUnits  - Natural Units of the WORD\r
+  ConstantUnits - Constant Units of the WORD\r
+\r
+Returns:\r
+\r
+  Sign value of WORD\r
+\r
+--*/\r
+{\r
+  BOOLEAN Sign;\r
+  UINTN   NaturalUnitBit;\r
+\r
+  Sign = (BOOLEAN)(Data16 >> 15);\r
+  NaturalUnitBit = (UINTN)((Data16 >> 12) & 0x7);\r
+  NaturalUnitBit *= 2;\r
+  Data16 = Data16 & 0xFFF;\r
+  *NaturalUnits = (UINTN)(Data16 & ((1 << NaturalUnitBit) - 1));\r
+  *ConstantUnits = (UINTN)((Data16 >> NaturalUnitBit) & ((1 << (12 - NaturalUnitBit)) - 1));\r
+\r
+  return Sign;\r
+}\r
+\r
+BOOLEAN\r
+EdbGetNaturalIndex32 (\r
+  IN  UINT32  Data32,\r
+  OUT UINTN   *NaturalUnits,\r
+  OUT UINTN   *ConstantUnits\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Get Sign, NaturalUnits, and ConstantUnits of the DWORD data\r
+\r
+Arguments:\r
+\r
+  Data32        - DWORD data\r
+  NaturalUnits  - Natural Units of the DWORD\r
+  ConstantUnits - Constant Units of the DWORD\r
+\r
+Returns:\r
+\r
+  Sign value of DWORD\r
+\r
+--*/\r
+{\r
+  BOOLEAN Sign;\r
+  UINTN   NaturalUnitBit;\r
+\r
+  Sign = (BOOLEAN)(Data32 >> 31);\r
+  NaturalUnitBit = (UINTN)((Data32 >> 28) & 0x7);\r
+  NaturalUnitBit *= 4;\r
+  Data32 = Data32 & 0xFFFFFFF;\r
+  *NaturalUnits = (UINTN)(Data32 & ((1 << NaturalUnitBit) - 1));\r
+  *ConstantUnits = (UINTN)((Data32 >> NaturalUnitBit) & ((1 << (28 - NaturalUnitBit)) - 1));\r
+\r
+  return Sign;\r
+}\r
+\r
+BOOLEAN\r
+EdbGetNaturalIndex64 (\r
+  IN  UINT64  Data64,\r
+  OUT UINT64  *NaturalUnits,\r
+  OUT UINT64  *ConstantUnits\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Get Sign, NaturalUnits, and ConstantUnits of the QWORD data\r
+\r
+Arguments:\r
+\r
+  Data64        - QWORD data\r
+  NaturalUnits  - Natural Units of the QWORD\r
+  ConstantUnits - Constant Units of the QWORD\r
+\r
+Returns:\r
+\r
+  Sign value of QWORD\r
+\r
+--*/\r
+{\r
+  BOOLEAN Sign;\r
+  UINTN   NaturalUnitBit;\r
+\r
+  Sign = (BOOLEAN)RShiftU64 (Data64, 63);\r
+  NaturalUnitBit = (UINTN)(RShiftU64 (Data64, 60) & 0x7);\r
+  NaturalUnitBit *= 8;\r
+  Data64 = RShiftU64 (LShiftU64 (Data64, 4), 4);\r
+  *NaturalUnits = (UINT64)(Data64 & (LShiftU64 (1, NaturalUnitBit) - 1));\r
+  *ConstantUnits = (UINT64)(RShiftU64 (Data64, NaturalUnitBit) & (LShiftU64 (1, (60 - NaturalUnitBit)) - 1));\r
+\r
+  return Sign;\r
+}\r
+\r
+UINT8\r
+EdbGetBitWidth (\r
+  IN UINT64  Value\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Get Bit Width of the value\r
+\r
+Arguments:\r
+\r
+  Value - data\r
+\r
+Returns:\r
+\r
+  Bit width\r
+\r
+--*/\r
+{\r
+  if (Value >= 10000000000000) {\r
+    return 14;\r
+  } else if (Value >= 1000000000000) {\r
+    return 13;\r
+  } else if (Value >= 100000000000) {\r
+    return 12;\r
+  } else if (Value >= 10000000000) {\r
+    return 11;\r
+  } else if (Value >= 1000000000) {\r
+    return 10;\r
+  } else if (Value >= 100000000) {\r
+    return 9;\r
+  } else if (Value >= 10000000) {\r
+    return 8;\r
+  } else if (Value >= 1000000) {\r
+    return 7;\r
+  } else if (Value >= 100000) {\r
+    return 6;\r
+  } else if (Value >= 10000) {\r
+    return 5;\r
+  } else if (Value >= 1000) {\r
+    return 4;\r
+  } else if (Value >= 100) {\r
+    return 3;\r
+  } else if (Value >= 10) {\r
+    return 2;\r
+  } else {\r
+    return 1;\r
+  }\r
+}\r
+\r
+UINTN\r
+EdbPrintInstructionName (\r
+  IN CHAR16                 *Name\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the instruction name\r
+\r
+Arguments:\r
+\r
+  Name - instruction name\r
+\r
+Returns:\r
+\r
+  Instruction name offset\r
+\r
+--*/\r
+{\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Name,\r
+    EDB_INSTRUCTION_NAME_MAX_SIZE,\r
+    mInstructionNameOffset,\r
+    L"%s",\r
+    Name\r
+    );\r
+  mInstructionNameOffset += StrLen (Name);\r
+\r
+  return mInstructionNameOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintRegister1 (\r
+  IN UINT8                  Operands\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print register 1 in operands\r
+\r
+Arguments:\r
+\r
+  Operands - instruction operands\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  if (Operands & OPERAND_M_INDIRECT1) {\r
+    EDBSPrintWithOffset (\r
+      mInstructionString.Content,\r
+      EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+      mInstructionContentOffset,\r
+      L"@"\r
+      );\r
+    mInstructionContentOffset += 1;\r
+  }\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Content,\r
+    EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+    mInstructionContentOffset,\r
+    L"R%d",\r
+    (UINTN)(Operands & OPERAND_M_OP1)\r
+    );\r
+  mInstructionContentOffset += 2;\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintRegister2 (\r
+  IN UINT8                  Operands\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print register 2 in operands\r
+\r
+Arguments:\r
+\r
+  Operands - instruction operands\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  if (Operands & OPERAND_M_INDIRECT2) {\r
+    EDBSPrintWithOffset (\r
+      mInstructionString.Content,\r
+      EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+      mInstructionContentOffset,\r
+      L"@"\r
+      );\r
+    mInstructionContentOffset += 1;\r
+  }\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Content,\r
+    EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+    mInstructionContentOffset,\r
+    L"R%d",\r
+    (UINTN)((Operands & OPERAND_M_OP2) >> 4)\r
+    );\r
+  mInstructionContentOffset += 2;\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintDedicatedRegister1 (\r
+  IN UINT8                  Operands\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print dedicated register 1 in operands\r
+\r
+Arguments:\r
+\r
+  Operands - instruction operands\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  switch (Operands & OPERAND_M_OP1) {\r
+  case 0:\r
+    EDBSPrintWithOffset (\r
+      mInstructionString.Content,\r
+      EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+      mInstructionContentOffset,\r
+      L"[FLAGS]"\r
+      );\r
+    mInstructionContentOffset += 7;\r
+    break;\r
+  case 1:\r
+    EDBSPrintWithOffset (\r
+      mInstructionString.Content,\r
+      EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+      mInstructionContentOffset,\r
+      L"[IP]"\r
+      );\r
+    mInstructionContentOffset += 4;\r
+    break;\r
+  }\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintDedicatedRegister2 (\r
+  IN UINT8                  Operands\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print dedicated register 2 in operands\r
+\r
+Arguments:\r
+\r
+  Operands - instruction operands\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  switch ((Operands & OPERAND_M_OP2) >> 4) {\r
+  case 0:\r
+    EDBSPrintWithOffset (\r
+      mInstructionString.Content,\r
+      EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+      mInstructionContentOffset,\r
+      L"[FLAGS]"\r
+      );\r
+    mInstructionContentOffset += 7;\r
+    break;\r
+  case 1:\r
+    EDBSPrintWithOffset (\r
+      mInstructionString.Content,\r
+      EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+      mInstructionContentOffset,\r
+      L"[IP]"\r
+      );\r
+    mInstructionContentOffset += 4;\r
+    break;\r
+  }\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintIndexData (\r
+  IN BOOLEAN                Sign,\r
+  IN UINTN                  NaturalUnits,\r
+  IN UINTN                  ConstantUnits\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the hexical UINTN index data to instruction content\r
+\r
+Arguments:\r
+\r
+  Sign          - Signed bit of UINTN data\r
+  NaturalUnits  - natural units of UINTN data\r
+  ConstantUnits - natural units of UINTN data\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Content,\r
+    EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+    mInstructionContentOffset,\r
+    L"(%s%d,%s%d)",\r
+    Sign ? L"-" : L"+",\r
+    NaturalUnits,\r
+    Sign ? L"-" : L"+",\r
+    ConstantUnits\r
+    );\r
+  mInstructionContentOffset  = mInstructionContentOffset + 5 + EdbGetBitWidth (NaturalUnits) + EdbGetBitWidth (ConstantUnits);\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintIndexData64 (\r
+  IN BOOLEAN                Sign,\r
+  IN UINT64                 NaturalUnits,\r
+  IN UINT64                 ConstantUnits\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the hexical QWORD index data to instruction content\r
+\r
+Arguments:\r
+\r
+  Sign          - Signed bit of QWORD data\r
+  NaturalUnits  - natural units of QWORD data\r
+  ConstantUnits - natural units of QWORD data\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Content,\r
+    EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+    mInstructionContentOffset,\r
+    L"(%s%ld,%s%ld)",\r
+    Sign ? L"-" : L"+",\r
+    NaturalUnits,\r
+    Sign ? L"-" : L"+",\r
+    ConstantUnits\r
+    );\r
+  mInstructionContentOffset  = mInstructionContentOffset + 5 + EdbGetBitWidth (NaturalUnits) + EdbGetBitWidth (ConstantUnits);\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintRawIndexData16 (\r
+  IN UINT16                 Data16\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the hexical WORD raw index data to instruction content\r
+\r
+Arguments:\r
+\r
+  Data16 - WORD data\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  BOOLEAN Sign;\r
+  UINTN   NaturalUnits;\r
+  UINTN   ConstantUnits;\r
+  UINTN   Offset;\r
+\r
+  Sign = EdbGetNaturalIndex16 (Data16, &NaturalUnits, &ConstantUnits);\r
+  Offset = EdbPrintIndexData (Sign, NaturalUnits, ConstantUnits);\r
+\r
+  return Offset;\r
+}\r
+\r
+UINTN\r
+EdbPrintRawIndexData32 (\r
+  IN UINT32                 Data32\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the hexical DWORD raw index data to instruction content\r
+\r
+Arguments:\r
+\r
+  Data32 - DWORD data\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  BOOLEAN Sign;\r
+  UINTN   NaturalUnits;\r
+  UINTN   ConstantUnits;\r
+  UINTN   Offset;\r
+\r
+  Sign = EdbGetNaturalIndex32 (Data32, &NaturalUnits, &ConstantUnits);\r
+  Offset = EdbPrintIndexData (Sign, NaturalUnits, ConstantUnits);\r
+\r
+  return Offset;\r
+}\r
+\r
+UINTN\r
+EdbPrintRawIndexData64 (\r
+  IN UINT64                 Data64\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the hexical QWORD raw index data to instruction content\r
+\r
+Arguments:\r
+\r
+  Data64 - QWORD data\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  BOOLEAN Sign;\r
+  UINT64  NaturalUnits;\r
+  UINT64  ConstantUnits;\r
+  UINTN   Offset;\r
+\r
+  Sign = EdbGetNaturalIndex64 (Data64, &NaturalUnits, &ConstantUnits);\r
+  Offset = EdbPrintIndexData64 (Sign, NaturalUnits, ConstantUnits);\r
+\r
+  return Offset;\r
+}\r
+\r
+UINTN\r
+EdbPrintImmData8 (\r
+  IN UINT8                  Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the hexical BYTE immediate data to instruction content\r
+\r
+Arguments:\r
+\r
+  Data - BYTE data\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Content,\r
+    EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+    mInstructionContentOffset,\r
+    L"(0x%02x)",\r
+    (UINTN)Data\r
+    );\r
+  mInstructionContentOffset  += 6;\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintImmData16 (\r
+  IN UINT16                 Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the hexical WORD immediate data to instruction content\r
+\r
+Arguments:\r
+\r
+  Data - WORD data\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Content,\r
+    EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+    mInstructionContentOffset,\r
+    L"(0x%04x)",\r
+    (UINTN)Data\r
+    );\r
+  mInstructionContentOffset  += 8;\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintImmData32 (\r
+  IN UINT32                 Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the hexical DWORD immediate data to instruction content\r
+\r
+Arguments:\r
+\r
+  Data - DWORD data\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Content,\r
+    EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+    mInstructionContentOffset,\r
+    L"(0x%08x)",\r
+    (UINTN)Data\r
+    );\r
+  mInstructionContentOffset  += 12;\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintImmData64 (\r
+  IN UINT64                 Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the hexical QWORD immediate data to instruction content\r
+\r
+Arguments:\r
+\r
+  Data - QWORD data\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Content,\r
+    EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+    mInstructionContentOffset,\r
+    L"(0x%016lx)",\r
+    Data\r
+    );\r
+  mInstructionContentOffset  += 20;\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintImmDatan (\r
+  IN UINTN                  Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the decimal UINTN immediate data to instruction content\r
+\r
+Arguments:\r
+\r
+  Data - UINTN data\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Content,\r
+    EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+    mInstructionContentOffset,\r
+    L"(%d)",\r
+    (UINTN)Data\r
+    );\r
+  mInstructionContentOffset  = mInstructionContentOffset + 2 + EdbGetBitWidth (Data);\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintImmData64n (\r
+  IN UINT64                 Data64\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the decimal QWORD immediate data to instruction content\r
+\r
+Arguments:\r
+\r
+  Data64 - QWORD data\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Content,\r
+    EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+    mInstructionContentOffset,\r
+    L"(%ld)",\r
+    Data64\r
+    );\r
+  mInstructionContentOffset  = mInstructionContentOffset + 2 + EdbGetBitWidth (Data64);\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintData8 (\r
+  IN UINT8                  Data8\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the hexical BYTE to instruction content\r
+\r
+Arguments:\r
+\r
+  Data8 - BYTE data\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Content,\r
+    EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+    mInstructionContentOffset,\r
+    L"0x%02x",\r
+    (UINTN)Data8\r
+    );\r
+  mInstructionContentOffset += 4;\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintData16 (\r
+  IN UINT16                 Data16\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the hexical WORD to instruction content\r
+\r
+Arguments:\r
+\r
+  Data16 - WORD data\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Content,\r
+    EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+    mInstructionContentOffset,\r
+    L"0x%04x",\r
+    (UINTN)Data16\r
+    );\r
+  mInstructionContentOffset += 6;\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintData32 (\r
+  IN UINT32                 Data32\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the hexical DWORD to instruction content\r
+\r
+Arguments:\r
+\r
+  Data32 - DWORD data\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Content,\r
+    EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+    mInstructionContentOffset,\r
+    L"0x%08x",\r
+    (UINTN)Data32\r
+    );\r
+  mInstructionContentOffset += 10;\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintData64 (\r
+  IN UINT64                 Data64\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the hexical QWORD to instruction content\r
+\r
+Arguments:\r
+\r
+  Data64 - QWORD data\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Content,\r
+    EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+    mInstructionContentOffset,\r
+    L"0x%016lx",\r
+    (UINT64)Data64\r
+    );\r
+  mInstructionContentOffset += 18;\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintDatan (\r
+  IN UINTN                  Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the decimal unsigned UINTN to instruction content\r
+\r
+Arguments:\r
+\r
+  Data - unsigned UINTN data\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Content,\r
+    EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+    mInstructionContentOffset,\r
+    L"%d",\r
+    (UINTN)Data\r
+    );\r
+  mInstructionContentOffset = mInstructionContentOffset + EdbGetBitWidth (Data);\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintData64n (\r
+  IN UINT64                 Data64\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the decimal unsigned QWORD to instruction content\r
+\r
+Arguments:\r
+\r
+  Data64 - unsigned QWORD data\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Content,\r
+    EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+    mInstructionContentOffset,\r
+    L"%ld",\r
+    Data64\r
+    );\r
+  mInstructionContentOffset = mInstructionContentOffset + EdbGetBitWidth (Data64);\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintData8s (\r
+  IN UINT8                  Data8\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the decimal signed BYTE to instruction content\r
+\r
+Arguments:\r
+\r
+  Data8 - signed BYTE data\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  BOOLEAN Sign;\r
+\r
+  Sign = (BOOLEAN)(Data8 >> 7);\r
+\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Content,\r
+    EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+    mInstructionContentOffset,\r
+    L"%s%d",\r
+    Sign ? L"-" : L"+",\r
+    (UINTN)(Data8 & 0x7F)\r
+    );\r
+  mInstructionContentOffset = mInstructionContentOffset + 1 + EdbGetBitWidth (Data8 & 0x7F);\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintData16s (\r
+  IN UINT16                 Data16\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the decimal signed WORD to instruction content\r
+\r
+Arguments:\r
+\r
+  Data16 - signed WORD data\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  BOOLEAN Sign;\r
+\r
+  Sign = (BOOLEAN)(Data16 >> 15);\r
+\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Content,\r
+    EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+    mInstructionContentOffset,\r
+    L"%s%d",\r
+    Sign ? L"-" : L"+",\r
+    (UINTN)(Data16 & 0x7FFF)\r
+    );\r
+  mInstructionContentOffset = mInstructionContentOffset + 1 + EdbGetBitWidth (Data16 & 0x7FFF);\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintData32s (\r
+  IN UINT32                 Data32\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the decimal signed DWORD to instruction content\r
+\r
+Arguments:\r
+\r
+  Data32 - signed DWORD data\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  BOOLEAN Sign;\r
+\r
+  Sign = (BOOLEAN)(Data32 >> 31);\r
+\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Content,\r
+    EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+    mInstructionContentOffset,\r
+    L"%s%d",\r
+    Sign ? L"-" : L"+",\r
+    (UINTN)(Data32 & 0x7FFFFFFF)\r
+    );\r
+  mInstructionContentOffset = mInstructionContentOffset + 1 + EdbGetBitWidth (Data32 & 0x7FFFFFFF);\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintData64s (\r
+  IN UINT64                 Data64\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the decimal signed QWORD to instruction content\r
+\r
+Arguments:\r
+\r
+  Data64 - signed QWORD data\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  BOOLEAN Sign;\r
+  INT64   Data64s;\r
+\r
+  Sign = (BOOLEAN)RShiftU64 (Data64, 63);\r
+  Data64s = (INT64)RShiftU64 (LShiftU64 (Data64, 1), 1);\r
+\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Content,\r
+    EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+    mInstructionContentOffset,\r
+    L"%s%ld",\r
+    Sign ? L"-" : L"+",\r
+    (UINT64)Data64s\r
+    );\r
+  mInstructionContentOffset = mInstructionContentOffset + 1 + EdbGetBitWidth (Data64s);\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbPrintComma (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the comma to instruction content\r
+\r
+Arguments:\r
+\r
+  None\r
+\r
+Returns:\r
+\r
+  Instruction content offset\r
+\r
+--*/\r
+{\r
+  EDBSPrintWithOffset (\r
+    mInstructionString.Content,\r
+    EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+    mInstructionContentOffset,\r
+    L", "\r
+    );\r
+  mInstructionContentOffset += 2;\r
+\r
+  return mInstructionContentOffset;\r
+}\r
+\r
+UINTN\r
+EdbFindAndPrintSymbol (\r
+  IN UINTN                  Address\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Find the symbol string according to address, then print it\r
+\r
+Arguments:\r
+\r
+  Address - instruction address\r
+\r
+Returns:\r
+\r
+  1 - symbol string is found and printed\r
+  0 - symbol string not found\r
+\r
+--*/\r
+{\r
+  CHAR8 *SymbolStr;\r
+\r
+  SymbolStr = FindSymbolStr (Address);\r
+  if (SymbolStr != NULL) {\r
+    EDBSPrintWithOffset (\r
+      mInstructionString.Content,\r
+      EDB_INSTRUCTION_CONTENT_MAX_SIZE,\r
+      mInstructionContentOffset,\r
+      L"[%a]",\r
+      SymbolStr\r
+      );\r
+    return 1;\r
+  }\r
+\r
+  return 0;\r
+}\r
+\r
+VOID\r
+EdbPrintRaw (\r
+  IN EFI_PHYSICAL_ADDRESS   InstructionAddress,\r
+  IN UINTN                  InstructionNumber\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the EBC byte code\r
+\r
+Arguments:\r
+\r
+  InstructionAddress - instruction address\r
+  InstructionNumber  - instruction number\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  UINTN  LineNumber;\r
+  UINTN  ByteNumber;\r
+  UINTN  LineIndex;\r
+  UINTN  ByteIndex;\r
+  CHAR8  *SymbolStr;\r
+\r
+  if (InstructionNumber == 0) {\r
+    return ;\r
+  }\r
+\r
+  LineNumber = InstructionNumber / EDB_BYTECODE_NUMBER_IN_LINE;\r
+  ByteNumber = InstructionNumber % EDB_BYTECODE_NUMBER_IN_LINE;\r
+  if (ByteNumber == 0) {\r
+    LineNumber -= 1;\r
+    ByteNumber  = EDB_BYTECODE_NUMBER_IN_LINE;\r
+  }\r
+\r
+  //\r
+  // Print Symbol\r
+  //\r
+  SymbolStr = FindSymbolStr ((UINTN)InstructionAddress);\r
+  if (SymbolStr != NULL) {\r
+    EDBPrint (L"[%a]:\n", SymbolStr);\r
+  }\r
+\r
+  for (LineIndex = 0; LineIndex < LineNumber; LineIndex++) {\r
+    EDBPrint (EDB_PRINT_ADDRESS_FORMAT, (UINTN)InstructionAddress);\r
+    for (ByteIndex = 0; ByteIndex < EDB_BYTECODE_NUMBER_IN_LINE; ByteIndex++) {\r
+      EDBPrint (L"%02x ", *(UINT8 *)(UINTN)InstructionAddress);\r
+      InstructionAddress += 1;\r
+    }\r
+    EDBPrint (L"\n");\r
+  }\r
+\r
+  EDBPrint (EDB_PRINT_ADDRESS_FORMAT, (UINTN)InstructionAddress);\r
+  for (ByteIndex = 0; ByteIndex < ByteNumber; ByteIndex++) {\r
+    EDBPrint (L"%02x ", *(UINT8 *)(UINTN)InstructionAddress);\r
+    InstructionAddress += 1;\r
+  }\r
+  for (ByteIndex = 0; ByteIndex < EDB_BYTECODE_NUMBER_IN_LINE - ByteNumber; ByteIndex++) {\r
+    EDBPrint (L"   ");\r
+  }\r
+\r
+  return ;\r
+}\r
+\r
+EFI_STATUS\r
+EdbShowDisasm (\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print the EBC asm code\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  SystemContext   - EBC system context.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - show disasm successfully\r
+\r
+--*/\r
+{\r
+  EFI_PHYSICAL_ADDRESS    InstructionAddress;\r
+  UINTN                   InstructionNumber;\r
+  UINTN                   InstructionLength;\r
+  UINT8                   Opcode;\r
+  CHAR16                  *InstructionString;\r
+//  UINTN                   Result;\r
+\r
+  InstructionAddress = DebuggerPrivate->InstructionScope;\r
+  for (InstructionNumber = 0; InstructionNumber < DebuggerPrivate->InstructionNumber; InstructionNumber++) {\r
+\r
+    //\r
+    // Break each 0x10 instruction\r
+    //\r
+    if (((InstructionNumber % EFI_DEBUGGER_LINE_NUMBER_IN_PAGE) == 0) &&\r
+        (InstructionNumber != 0)) {\r
+      if (SetPageBreak ()) {\r
+        break;\r
+      }\r
+    }\r
+\r
+    Opcode = GET_OPCODE(InstructionAddress);\r
+    if ((Opcode < OPCODE_MAX) && (mEdbDisasmInstructionTable[Opcode] != NULL)) {\r
+      InstructionLength = mEdbDisasmInstructionTable [Opcode] (InstructionAddress, SystemContext, &InstructionString);\r
+      if (InstructionLength != 0) {\r
+\r
+        //\r
+        // Print Source\r
+        //\r
+//        Result = EdbPrintSource ((UINTN)InstructionAddress, FALSE);\r
+\r
+        if (!DebuggerPrivate->DebuggerSymbolContext.DisplayCodeOnly) {\r
+\r
+          EdbPrintRaw (InstructionAddress, InstructionLength);\r
+          if (InstructionString != NULL) {\r
+            EDBPrint (L"%s\n", InstructionString);\r
+          } else {\r
+            EDBPrint (L"%s\n", L"<Unknown Instruction>");\r
+          }\r
+        }\r
+\r
+        EdbPrintSource ((UINTN)InstructionAddress, TRUE);\r
+\r
+        InstructionAddress += InstructionLength;\r
+      } else {\r
+        //\r
+        // Something wrong with OPCODE\r
+        //\r
+        EdbPrintRaw (InstructionAddress, EDB_BYTECODE_NUMBER_IN_LINE);\r
+        EDBPrint (L"%s\n", L"<Bad Instruction>");\r
+        break;\r
+      }\r
+    } else {\r
+      //\r
+      // Something wrong with OPCODE\r
+      //\r
+      EdbPrintRaw (InstructionAddress, EDB_BYTECODE_NUMBER_IN_LINE);\r
+      EDBPrint (L"%s\n", L"<Bad Instruction>");\r
+      break;\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+UINT64\r
+GetRegisterValue (\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  IN     UINT8                     Index\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Get register value accroding to the system context, and register index\r
+\r
+Arguments:\r
+\r
+  SystemContext   - EBC system context.\r
+  Index           - EBC register index\r
+\r
+Returns:\r
+\r
+  register value\r
+\r
+--*/\r
+{\r
+  switch (Index) {\r
+  case 0:\r
+    return SystemContext.SystemContextEbc->R0;\r
+  case 1:\r
+    return SystemContext.SystemContextEbc->R1;\r
+  case 2:\r
+    return SystemContext.SystemContextEbc->R2;\r
+  case 3:\r
+    return SystemContext.SystemContextEbc->R3;\r
+  case 4:\r
+    return SystemContext.SystemContextEbc->R4;\r
+  case 5:\r
+    return SystemContext.SystemContextEbc->R5;\r
+  case 6:\r
+    return SystemContext.SystemContextEbc->R6;\r
+  case 7:\r
+    return SystemContext.SystemContextEbc->R7;\r
+  default:\r
+    ASSERT (FALSE);\r
+    break;\r
+  }\r
+  return 0;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbDisasmSupport.h b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbDisasmSupport.h
new file mode 100644 (file)
index 0000000..f66261b
--- /dev/null
@@ -0,0 +1,241 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbDisasmSupport.h\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#ifndef _EFI_EDB_DISASM_SUPPORT_H_\r
+#define _EFI_EDB_DISASM_SUPPORT_H_\r
+\r
+#include <Uefi.h>\r
+\r
+#define EDB_BYTECODE_NUMBER_IN_LINE     5\r
+\r
+#ifdef EFI32\r
+#define EDB_PRINT_ADDRESS_FORMAT    L"%08x: "\r
+#else\r
+// To use 012l instead of 016l because space is not enough\r
+#define EDB_PRINT_ADDRESS_FORMAT    L"%012lx: "\r
+#endif\r
+\r
+#define OPCODE_MAX 0x40\r
+\r
+#define EDB_INSTRUCTION_NAME_MAX_LENGTH     10\r
+#define EDB_INSTRUCTION_NAME_MAX_SIZE       (EDB_INSTRUCTION_NAME_MAX_LENGTH * sizeof(CHAR16))\r
+#define EDB_INSTRUCTION_CONTENT_MAX_LENGTH  30\r
+#define EDB_INSTRUCTION_CONTENT_MAX_SIZE    (EDB_INSTRUCTION_CONTENT_MAX_LENGTH * sizeof(CHAR16))\r
+\r
+VOID\r
+EdbSetOffset (\r
+  IN UINTN InstructionNameOffset,\r
+  IN UINTN InstructionContentOffset\r
+  );\r
+\r
+CHAR16 *\r
+EdbPreInstructionString (\r
+  VOID\r
+  );\r
+\r
+CHAR16 *\r
+EdbPostInstructionString (\r
+  VOID\r
+  );\r
+\r
+UINTN\r
+EdbPrintInstructionName (\r
+  IN CHAR16                 *Name\r
+  );\r
+\r
+BOOLEAN\r
+EdbGetNaturalIndex16 (\r
+  IN  UINT16  Data16,\r
+  OUT UINTN   *NaturalUnits,\r
+  OUT UINTN   *ConstantUnits\r
+  );\r
+\r
+BOOLEAN\r
+EdbGetNaturalIndex32 (\r
+  IN  UINT32  Data32,\r
+  OUT UINTN   *NaturalUnits,\r
+  OUT UINTN   *ConstantUnits\r
+  );\r
+\r
+BOOLEAN\r
+EdbGetNaturalIndex64 (\r
+  IN  UINT64  Data64,\r
+  OUT UINT64  *NaturalUnits,\r
+  OUT UINT64  *ConstantUnits\r
+  );\r
+\r
+UINTN\r
+EdbPrintRawIndexData16 (\r
+  IN UINT16                 Data16\r
+  );\r
+\r
+UINTN\r
+EdbPrintRawIndexData32 (\r
+  IN UINT32                 Data32\r
+  );\r
+\r
+UINTN\r
+EdbPrintRawIndexData64 (\r
+  IN UINT64                 Data64\r
+  );\r
+\r
+UINTN\r
+EdbPrintRegister1 (\r
+  IN UINT8                  Operands\r
+  );\r
+\r
+UINTN\r
+EdbPrintRegister2 (\r
+  IN UINT8                  Operands\r
+  );\r
+\r
+UINTN\r
+EdbPrintDedicatedRegister1 (\r
+  IN UINT8                  Operands\r
+  );\r
+\r
+UINTN\r
+EdbPrintDedicatedRegister2 (\r
+  IN UINT8                  Operands\r
+  );\r
+\r
+UINTN\r
+EdbPrintIndexData (\r
+  IN BOOLEAN                Sign,\r
+  IN UINTN                  NaturalUnits,\r
+  IN UINTN                  ConstantUnits\r
+  );\r
+\r
+UINTN\r
+EdbPrintIndexData64 (\r
+  IN BOOLEAN                Sign,\r
+  IN UINT64                 NaturalUnits,\r
+  IN UINT64                 ConstantUnits\r
+  );\r
+\r
+UINTN\r
+EdbPrintImmData8 (\r
+  IN UINT8                  Data\r
+  );\r
+\r
+UINTN\r
+EdbPrintImmData16 (\r
+  IN UINT16                 Data\r
+  );\r
+\r
+UINTN\r
+EdbPrintImmData32 (\r
+  IN UINT32                 Data\r
+  );\r
+\r
+UINTN\r
+EdbPrintImmData64 (\r
+  IN UINT64                 Data\r
+  );\r
+\r
+UINTN\r
+EdbPrintImmDatan (\r
+  IN UINTN                  Data\r
+  );\r
+\r
+UINTN\r
+EdbPrintImmData64n (\r
+  IN UINT64                 Data64\r
+  );\r
+\r
+UINTN\r
+EdbPrintData8 (\r
+  IN UINT8                  Data8\r
+  );\r
+\r
+UINTN\r
+EdbPrintData16 (\r
+  IN UINT16                 Data16\r
+  );\r
+\r
+UINTN\r
+EdbPrintData32 (\r
+  IN UINT32                 Data32\r
+  );\r
+\r
+UINTN\r
+EdbPrintData64 (\r
+  IN UINT64                 Data64\r
+  );\r
+\r
+UINTN\r
+EdbPrintDatan (\r
+  IN UINTN                  Data\r
+  );\r
+\r
+UINTN\r
+EdbPrintData64n (\r
+  IN UINT64                 Data64\r
+  );\r
+\r
+UINTN\r
+EdbPrintData8s (\r
+  IN UINT8                  Data8\r
+  );\r
+\r
+UINTN\r
+EdbPrintData16s (\r
+  IN UINT16                 Data16\r
+  );\r
+\r
+UINTN\r
+EdbPrintData32s (\r
+  IN UINT32                 Data32\r
+  );\r
+\r
+UINTN\r
+EdbPrintData64s (\r
+  IN UINT64                 Data64\r
+  );\r
+\r
+UINTN\r
+EdbPrintComma (\r
+  VOID\r
+  );\r
+\r
+UINTN\r
+EdbFindAndPrintSymbol (\r
+  IN UINTN                  Address\r
+  );\r
+\r
+VOID\r
+EdbPrintRaw (\r
+  IN EFI_PHYSICAL_ADDRESS   InstructionAddress,\r
+  IN UINTN                  InstructionNumber\r
+  );\r
+\r
+EFI_STATUS\r
+EdbShowDisasm (\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext\r
+  );\r
+\r
+UINT64\r
+GetRegisterValue (\r
+  IN     EFI_SYSTEM_CONTEXT        SystemContext,\r
+  IN     UINT8                     Index\r
+  );\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbHook.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbHook.c
new file mode 100644 (file)
index 0000000..9196adb
--- /dev/null
@@ -0,0 +1,1003 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbHook.c\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#include "Edb.h"\r
+\r
+//\r
+// Hook support function\r
+//\r
+VOID\r
+EbcDebuggerCheckHookFlag (\r
+  IN VM_CONTEXT *VmPtr,\r
+  IN UINT32     Flag\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Check the Hook flag, and trigger exception if match.\r
+\r
+Arguments:\r
+\r
+  VmPtr        - EbcDebuggerCheckHookFlag\r
+  Flag         - Feature flag\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  if ((mDebuggerPrivate.FeatureFlags & Flag) == Flag) {\r
+    mDebuggerPrivate.StatusFlags = Flag;\r
+    EbcDebugSignalException (\r
+      EXCEPT_EBC_BREAKPOINT,\r
+      EXCEPTION_FLAG_NONE,\r
+      VmPtr\r
+      );\r
+  }\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerPushCallstackSource (\r
+  IN UINT64                   SourceEntry,\r
+  IN EFI_DEBUGGER_BRANCH_TYPE Type\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  It will record soruce address for Callstack entry.\r
+\r
+Arguments:\r
+\r
+  SourceEntry  - Source address\r
+  Type         - Branch type\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  if (mDebuggerPrivate.CallStackEntryCount > EFI_DEBUGGER_CALLSTACK_MAX) {\r
+    ASSERT (FALSE);\r
+    mDebuggerPrivate.CallStackEntryCount = EFI_DEBUGGER_CALLSTACK_MAX;\r
+  }\r
+  //\r
+  // Record the new callstack entry\r
+  //\r
+  mDebuggerPrivate.CallStackEntry[mDebuggerPrivate.CallStackEntryCount].SourceAddress = SourceEntry;\r
+  mDebuggerPrivate.CallStackEntry[mDebuggerPrivate.CallStackEntryCount].Type = Type;\r
+\r
+  //\r
+  // Do not change CallStackEntryCount\r
+  //\r
+\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerPushCallstackParameter (\r
+  IN UINT64                   ParameterAddress,\r
+  IN EFI_DEBUGGER_BRANCH_TYPE Type\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  It will record parameter for Callstack entry.\r
+\r
+Arguments:\r
+\r
+  ParameterAddress - The address for the parameter\r
+  Type             - Branch type\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  if (mDebuggerPrivate.CallStackEntryCount > EFI_DEBUGGER_CALLSTACK_MAX) {\r
+    ASSERT (FALSE);\r
+    mDebuggerPrivate.CallStackEntryCount = EFI_DEBUGGER_CALLSTACK_MAX;\r
+  }\r
+  //\r
+  // Record the new callstack parameter\r
+  //\r
+  mDebuggerPrivate.CallStackEntry[mDebuggerPrivate.CallStackEntryCount].ParameterAddr = (UINTN)ParameterAddress;\r
+  CopyMem (\r
+    mDebuggerPrivate.CallStackEntry[mDebuggerPrivate.CallStackEntryCount].Parameter,\r
+    (VOID *)(UINTN)ParameterAddress,\r
+    sizeof(mDebuggerPrivate.CallStackEntry[mDebuggerPrivate.CallStackEntryCount].Parameter)\r
+    );\r
+\r
+  //\r
+  // Do not change CallStackEntryCount\r
+  //\r
+\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerPushCallstackDest (\r
+  IN UINT64                   DestEntry,\r
+  IN EFI_DEBUGGER_BRANCH_TYPE Type\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  It will record source address for callstack entry.\r
+\r
+Arguments:\r
+\r
+  DestEntry    - Source address\r
+  Type         - Branch type\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  UINTN Index;\r
+\r
+  if (mDebuggerPrivate.CallStackEntryCount < EFI_DEBUGGER_CALLSTACK_MAX) {\r
+    //\r
+    // If there is empty entry for callstack, add it\r
+    //\r
+    ASSERT (mDebuggerPrivate.CallStackEntry[mDebuggerPrivate.CallStackEntryCount].Type == Type);\r
+    mDebuggerPrivate.CallStackEntry[mDebuggerPrivate.CallStackEntryCount].DestAddress = DestEntry;\r
+    mDebuggerPrivate.CallStackEntryCount ++;\r
+  } else {\r
+    //\r
+    // If there is no empty entry for callstack, throw the oldest one\r
+    //\r
+    ASSERT (mDebuggerPrivate.CallStackEntry[EFI_DEBUGGER_TRACE_MAX].Type == Type);\r
+    for (Index = 0; Index < EFI_DEBUGGER_CALLSTACK_MAX; Index++) {\r
+      mDebuggerPrivate.CallStackEntry[Index] = mDebuggerPrivate.CallStackEntry[Index + 1];\r
+    }\r
+    mDebuggerPrivate.CallStackEntry[EFI_DEBUGGER_CALLSTACK_MAX - 1].DestAddress = DestEntry;\r
+    mDebuggerPrivate.CallStackEntryCount = EFI_DEBUGGER_CALLSTACK_MAX;\r
+  }\r
+\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerPopCallstack (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  It will throw the newest Callstack entry.\r
+\r
+Arguments:\r
+\r
+  None\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  if ((mDebuggerPrivate.CallStackEntryCount > 0) &&\r
+      (mDebuggerPrivate.CallStackEntryCount <= EFI_DEBUGGER_CALLSTACK_MAX)) {\r
+    //\r
+    // Throw the newest one\r
+    //\r
+    mDebuggerPrivate.CallStackEntryCount --;\r
+    mDebuggerPrivate.CallStackEntry[mDebuggerPrivate.CallStackEntryCount].SourceAddress = 0;\r
+    mDebuggerPrivate.CallStackEntry[mDebuggerPrivate.CallStackEntryCount].DestAddress = 0;\r
+  } else if (mDebuggerPrivate.CallStackEntryCount == 0) {\r
+    //\r
+    // NOT assert here because it is reasonable, because when we start to build\r
+    // callstack, we do not know how many function already called.\r
+    //\r
+  } else {\r
+    ASSERT (FALSE);\r
+  }\r
+\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerPushTraceSourceEntry (\r
+  IN UINT64                   SourceEntry,\r
+  IN EFI_DEBUGGER_BRANCH_TYPE Type\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  It will record source address for trace entry.\r
+\r
+Arguments:\r
+\r
+  SourceEntry  - Source address\r
+  Type         - Branch type\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  if (mDebuggerPrivate.TraceEntryCount > EFI_DEBUGGER_TRACE_MAX) {\r
+    ASSERT (FALSE);\r
+    mDebuggerPrivate.TraceEntryCount = EFI_DEBUGGER_TRACE_MAX;\r
+  }\r
+  //\r
+  // Record the new trace entry\r
+  //\r
+  mDebuggerPrivate.TraceEntry[mDebuggerPrivate.TraceEntryCount].SourceAddress = SourceEntry;\r
+  mDebuggerPrivate.TraceEntry[mDebuggerPrivate.TraceEntryCount].Type = Type;\r
+\r
+  //\r
+  // Do not change TraceEntryCount\r
+  //\r
+\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerPushTraceDestEntry (\r
+  IN UINT64                   DestEntry,\r
+  IN EFI_DEBUGGER_BRANCH_TYPE Type\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  It will record destination address for trace entry.\r
+\r
+Arguments:\r
+\r
+  DestEntry    - Destination address\r
+  Type         - Branch type\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  UINTN Index;\r
+\r
+  if (mDebuggerPrivate.TraceEntryCount < EFI_DEBUGGER_TRACE_MAX) {\r
+    //\r
+    // If there is empty entry for trace, add it\r
+    //\r
+    ASSERT (mDebuggerPrivate.TraceEntry[mDebuggerPrivate.TraceEntryCount].Type == Type);\r
+    mDebuggerPrivate.TraceEntry[mDebuggerPrivate.TraceEntryCount].DestAddress = DestEntry;\r
+    mDebuggerPrivate.TraceEntryCount ++;\r
+  } else {\r
+    //\r
+    // If there is no empty entry for trace, throw the oldest one\r
+    //\r
+    ASSERT (mDebuggerPrivate.TraceEntry[EFI_DEBUGGER_TRACE_MAX].Type == Type);\r
+    for (Index = 0; Index < EFI_DEBUGGER_TRACE_MAX; Index++) {\r
+      mDebuggerPrivate.TraceEntry[Index] = mDebuggerPrivate.TraceEntry[Index + 1];\r
+    }\r
+    mDebuggerPrivate.TraceEntry[EFI_DEBUGGER_CALLSTACK_MAX - 1].DestAddress = DestEntry;\r
+    mDebuggerPrivate.TraceEntryCount = EFI_DEBUGGER_TRACE_MAX;\r
+  }\r
+\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerPushStepEntry (\r
+  IN UINT64                   Entry,\r
+  IN UINT64                   FramePtr,\r
+  IN UINT32                   Flag\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  It will record address for StepEntry, if STEPOVER or STEPOUT is enabled.\r
+\r
+Arguments:\r
+\r
+  Entry    - Break Address\r
+  FramePtr - Break Frame pointer\r
+  Flag     - for STEPOVER or STEPOUT\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  //\r
+  // Check StepOver\r
+  //\r
+  if ((Flag == EFI_DEBUG_FLAG_EBC_STEPOVER) &&\r
+      ((mDebuggerPrivate.FeatureFlags & EFI_DEBUG_FLAG_EBC_STEPOVER) == EFI_DEBUG_FLAG_EBC_STEPOVER)) {\r
+    mDebuggerPrivate.StepContext.BreakAddress = Entry;\r
+    mDebuggerPrivate.StepContext.FramePointer = FramePtr;\r
+    mDebuggerPrivate.FeatureFlags &= ~EFI_DEBUG_FLAG_EBC_B_STEPOVER;\r
+  }\r
+  //\r
+  // Check StepOut\r
+  //\r
+  if ((Flag == EFI_DEBUG_FLAG_EBC_STEPOUT) &&\r
+      ((mDebuggerPrivate.FeatureFlags & EFI_DEBUG_FLAG_EBC_STEPOUT) == EFI_DEBUG_FLAG_EBC_STEPOUT)) {\r
+    mDebuggerPrivate.StepContext.BreakAddress = Entry;\r
+    mDebuggerPrivate.StepContext.FramePointer = FramePtr;\r
+    mDebuggerPrivate.FeatureFlags &= ~EFI_DEBUG_FLAG_EBC_B_STEPOUT;\r
+  }\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+EbcDebuggerBreakEventFunc (\r
+  IN EFI_EVENT                Event,\r
+  IN VOID                     *Context\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  if ((mDebuggerPrivate.FeatureFlags & EFI_DEBUG_FLAG_EBC_BOK) != EFI_DEBUG_FLAG_EBC_BOK) {\r
+    return ;\r
+  }\r
+\r
+  Status = gBS->CheckEvent (gST->ConIn->WaitForKey);\r
+  if (Status == EFI_SUCCESS) {\r
+    mDebuggerPrivate.StatusFlags = EFI_DEBUG_FLAG_EBC_BOK;\r
+  }\r
+}\r
+\r
+//\r
+// Hook function implementation\r
+//\r
+VOID\r
+EbcDebuggerHookInit (\r
+  IN EFI_HANDLE                  Handle,\r
+  IN EFI_DEBUG_SUPPORT_PROTOCOL  *EbcDebugProtocol\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The hook in InitializeEbcDriver.\r
+  It will init the EbcDebuggerPrivate data structure.\r
+\r
+Arguments:\r
+\r
+  Handle           - The EbcDebugProtocol handle.\r
+  EbcDebugProtocol - The EbcDebugProtocol interface.\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                 Status;\r
+  UINTN                      Index;\r
+  EFI_DEBUGGER_SYMBOL_OBJECT *Object;\r
+  EFI_DEBUGGER_SYMBOL_ENTRY  *Entry;\r
+\r
+\r
+  //\r
+  // Register all exception handler\r
+  //\r
+  for (Index = EXCEPT_EBC_UNDEFINED; Index <= EXCEPT_EBC_STEP; Index++) {\r
+    EbcDebugProtocol->RegisterExceptionCallback (\r
+      EbcDebugProtocol,\r
+      0,\r
+      NULL,\r
+      Index\r
+      );\r
+    EbcDebugProtocol->RegisterExceptionCallback (\r
+      EbcDebugProtocol,\r
+      0,\r
+      EdbExceptionHandler,\r
+      Index\r
+      );\r
+  }\r
+\r
+  //\r
+  // Init Symbol\r
+  //\r
+  Object = AllocateZeroPool (sizeof(EFI_DEBUGGER_SYMBOL_OBJECT) * EFI_DEBUGGER_SYMBOL_OBJECT_MAX);\r
+  ASSERT (Object != NULL);\r
+  mDebuggerPrivate.DebuggerSymbolContext.Object = Object;\r
+  mDebuggerPrivate.DebuggerSymbolContext.ObjectCount = 0;\r
+  mDebuggerPrivate.DebuggerSymbolContext.MaxObjectCount = EFI_DEBUGGER_SYMBOL_OBJECT_MAX;\r
+  for (Index = 0; Index < EFI_DEBUGGER_SYMBOL_OBJECT_MAX; Index++) {\r
+    Entry = AllocateZeroPool (sizeof(EFI_DEBUGGER_SYMBOL_ENTRY) * EFI_DEBUGGER_SYMBOL_ENTRY_MAX);\r
+    ASSERT (Entry != NULL);\r
+    Object[Index].Entry = Entry;\r
+    Object[Index].MaxEntryCount = EFI_DEBUGGER_SYMBOL_ENTRY_MAX;\r
+    Object[Index].SourceBuffer = AllocateZeroPool (sizeof(VOID *) * (EFI_DEBUGGER_SYMBOL_ENTRY_MAX + 1));\r
+    ASSERT (Object[Index].SourceBuffer != NULL);\r
+  }\r
+\r
+  //\r
+  // locate PciRootBridgeIo\r
+  //\r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiPciRootBridgeIoProtocolGuid,\r
+                  NULL,\r
+                  (VOID**) &mDebuggerPrivate.PciRootBridgeIo\r
+                  );\r
+\r
+  //\r
+  // locate DebugImageInfoTable\r
+  //\r
+  Status = EfiGetSystemConfigurationTable (\r
+             &gEfiDebugImageInfoTableGuid,\r
+             (VOID**) &mDebuggerPrivate.DebugImageInfoTableHeader\r
+             );\r
+\r
+  //\r
+  // Create break event\r
+  //\r
+  Status = gBS->CreateEvent (\r
+                  EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
+                  TPL_CALLBACK,\r
+                  EbcDebuggerBreakEventFunc,\r
+                  NULL,\r
+                  &mDebuggerPrivate.BreakEvent\r
+                  );\r
+  Status = gBS->SetTimer (\r
+                  mDebuggerPrivate.BreakEvent,\r
+                  TimerPeriodic,\r
+                  EFI_DEBUG_BREAK_TIMER_INTERVAL\r
+                  );\r
+\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookUnload (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The hook in UnloadImage for EBC Interpreter.\r
+  It clean up the environment.\r
+\r
+Arguments:\r
+\r
+  None\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  UINTN                      Index;\r
+  UINTN                      SubIndex;\r
+  EFI_DEBUGGER_SYMBOL_OBJECT *Object;\r
+\r
+  //\r
+  // Close the break event\r
+  //\r
+  gBS->CloseEvent (mDebuggerPrivate.BreakEvent);\r
+\r
+  //\r
+  // Clean up the symbol\r
+  //\r
+  Object = mDebuggerPrivate.DebuggerSymbolContext.Object;\r
+  for (Index = 0; Index < EFI_DEBUGGER_SYMBOL_OBJECT_MAX; Index++) {\r
+    //\r
+    // Clean up Entry\r
+    //\r
+    gBS->FreePool (Object[Index].Entry);\r
+    Object[Index].Entry = NULL;\r
+    Object[Index].EntryCount = 0;\r
+    //\r
+    // Clean up source buffer\r
+    //\r
+    for (SubIndex = 0; Object[Index].SourceBuffer[SubIndex] != NULL; SubIndex++) {\r
+      gBS->FreePool (Object[Index].SourceBuffer[SubIndex]);\r
+      Object[Index].SourceBuffer[SubIndex] = NULL;\r
+    }\r
+    gBS->FreePool (Object[Index].SourceBuffer);\r
+    Object[Index].SourceBuffer = NULL;\r
+  }\r
+\r
+  //\r
+  // Clean up Object\r
+  //\r
+  gBS->FreePool (Object);\r
+  mDebuggerPrivate.DebuggerSymbolContext.Object = NULL;\r
+  mDebuggerPrivate.DebuggerSymbolContext.ObjectCount = 0;\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookEbcUnloadImage (\r
+  IN EFI_HANDLE                  Handle\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The hook in EbcUnloadImage.\r
+  Currently do nothing here.\r
+\r
+Arguments:\r
+\r
+  Handle           - The EbcImage handle.\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookExecuteEbcImageEntryPoint (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The hook in ExecuteEbcImageEntryPoint.\r
+  It will record the call-stack entry. (-1 means EbcImageEntryPoint call)\r
+  and trigger Exception if BOE enabled.\r
+\r
+Arguments:\r
+\r
+  VmPtr - pointer to VM context.\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  EbcDebuggerPushCallstackSource ((UINT64)(UINTN)-1, EfiDebuggerBranchTypeEbcCall);\r
+  EbcDebuggerPushCallstackParameter ((UINT64)(UINTN)VmPtr->Gpr[0], EfiDebuggerBranchTypeEbcCall);\r
+  EbcDebuggerPushCallstackDest ((UINT64)(UINTN)VmPtr->Ip, EfiDebuggerBranchTypeEbcCall);\r
+  EbcDebuggerCheckHookFlag (VmPtr, EFI_DEBUG_FLAG_EBC_BOE);\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookEbcInterpret (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The hook in ExecuteEbcImageEntryPoint.\r
+  It will record the call-stack entry. (-2 means EbcInterpret call)\r
+  and trigger Exception if BOT enabled.\r
+\r
+Arguments:\r
+\r
+  VmPtr - pointer to VM context.\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  EbcDebuggerPushCallstackSource ((UINT64)(UINTN)-2, EfiDebuggerBranchTypeEbcCall);\r
+  EbcDebuggerPushCallstackParameter ((UINT64)(UINTN)VmPtr->Gpr[0], EfiDebuggerBranchTypeEbcCall);\r
+  EbcDebuggerPushCallstackDest ((UINT64)(UINTN)VmPtr->Ip, EfiDebuggerBranchTypeEbcCall);\r
+  EbcDebuggerCheckHookFlag (VmPtr, EFI_DEBUG_FLAG_EBC_BOT);\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookExecuteStart (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The hook in EbcExecute, before ExecuteFunction.\r
+  It will trigger Exception if GoTil, StepOver, or StepOut hit.\r
+\r
+Arguments:\r
+\r
+  VmPtr - pointer to VM context.\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  EFI_TPL   CurrentTpl;\r
+\r
+  //\r
+  // Check Ip for GoTil\r
+  //\r
+  if (mDebuggerPrivate.GoTilContext.BreakAddress == (UINT64)(UINTN)VmPtr->Ip) {\r
+    mDebuggerPrivate.StatusFlags = EFI_DEBUG_FLAG_EBC_GT;\r
+    mDebuggerPrivate.GoTilContext.BreakAddress = 0;\r
+    EbcDebugSignalException (\r
+      EXCEPT_EBC_BREAKPOINT,\r
+      EXCEPTION_FLAG_NONE,\r
+      VmPtr\r
+      );\r
+    mDebuggerPrivate.StatusFlags &= ~EFI_DEBUG_FLAG_EBC_B_GT;\r
+    return ;\r
+  }\r
+  //\r
+  // Check ReturnAddress for StepOver\r
+  //\r
+  if ((mDebuggerPrivate.StepContext.BreakAddress == (UINT64)(UINTN)VmPtr->Ip) &&\r
+      (mDebuggerPrivate.StepContext.FramePointer == (UINT64)(UINTN)VmPtr->FramePtr)) {\r
+    mDebuggerPrivate.StatusFlags = EFI_DEBUG_FLAG_EBC_STEPOVER;\r
+    mDebuggerPrivate.StepContext.BreakAddress = 0;\r
+    mDebuggerPrivate.StepContext.FramePointer = 0;\r
+    EbcDebugSignalException (\r
+      EXCEPT_EBC_BREAKPOINT,\r
+      EXCEPTION_FLAG_NONE,\r
+      VmPtr\r
+      );\r
+    mDebuggerPrivate.StatusFlags &= ~EFI_DEBUG_FLAG_EBC_B_STEPOVER;\r
+  }\r
+  //\r
+  // Check FramePtr for StepOut\r
+  //\r
+  if (mDebuggerPrivate.StepContext.BreakAddress == (UINT64)(UINTN)VmPtr->FramePtr) {\r
+    mDebuggerPrivate.StatusFlags = EFI_DEBUG_FLAG_EBC_STEPOUT;\r
+    mDebuggerPrivate.StepContext.BreakAddress = 0;\r
+    mDebuggerPrivate.StepContext.FramePointer = 0;\r
+    EbcDebugSignalException (\r
+      EXCEPT_EBC_BREAKPOINT,\r
+      EXCEPTION_FLAG_NONE,\r
+      VmPtr\r
+      );\r
+    mDebuggerPrivate.StatusFlags &= ~EFI_DEBUG_FLAG_EBC_B_STEPOUT;\r
+  }\r
+  //\r
+  // Check Flags for BreakOnKey\r
+  //\r
+  if (mDebuggerPrivate.StatusFlags == EFI_DEBUG_FLAG_EBC_BOK) {\r
+    //\r
+    // Only break when the current TPL <= TPL_APPLICATION\r
+    //\r
+    CurrentTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+    gBS->RestoreTPL (CurrentTpl);\r
+    if (CurrentTpl <= TPL_APPLICATION) {\r
+      EbcDebugSignalException (\r
+        EXCEPT_EBC_BREAKPOINT,\r
+        EXCEPTION_FLAG_NONE,\r
+        VmPtr\r
+        );\r
+      mDebuggerPrivate.StatusFlags &= ~EFI_DEBUG_FLAG_EBC_B_BOK;\r
+    }\r
+  }\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookExecuteEnd (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The hook in EbcExecute, after ExecuteFunction.\r
+  It will record StepOut Entry if need.\r
+\r
+Arguments:\r
+\r
+  VmPtr - pointer to VM context.\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  UINTN  Address;\r
+\r
+  //\r
+  // Use FramePtr as checkpoint for StepOut\r
+  //\r
+  CopyMem (&Address, (VOID *)((UINTN)VmPtr->FramePtr), sizeof(Address));\r
+  EbcDebuggerPushStepEntry (Address, (UINT64)(UINTN)VmPtr->FramePtr, EFI_DEBUG_FLAG_EBC_STEPOUT);\r
+\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookCALLStart (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The hook in ExecuteCALL, before move IP.\r
+  It will trigger Exception if BOC enabled,\r
+  and record Callstack, and trace information.\r
+\r
+Arguments:\r
+\r
+  VmPtr - pointer to VM context.\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  EbcDebuggerCheckHookFlag (VmPtr, EFI_DEBUG_FLAG_EBC_BOC);\r
+  EbcDebuggerPushCallstackSource ((UINT64)(UINTN)VmPtr->Ip, EfiDebuggerBranchTypeEbcCall);\r
+  EbcDebuggerPushCallstackParameter ((UINT64)(UINTN)VmPtr->Gpr[0], EfiDebuggerBranchTypeEbcCall);\r
+  EbcDebuggerPushTraceSourceEntry ((UINT64)(UINTN)VmPtr->Ip, EfiDebuggerBranchTypeEbcCall);\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookCALLEnd (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The hook in ExecuteCALL, after move IP.\r
+  It will record Callstack, trace information\r
+  and record StepOver/StepOut Entry if need.\r
+\r
+Arguments:\r
+\r
+  VmPtr - pointer to VM context.\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  UINT64  Address;\r
+  UINTN   FramePtr;\r
+\r
+  EbcDebuggerPushCallstackDest ((UINT64)(UINTN)VmPtr->Ip, EfiDebuggerBranchTypeEbcCall);\r
+  EbcDebuggerPushTraceDestEntry ((UINT64)(UINTN)VmPtr->Ip, EfiDebuggerBranchTypeEbcCall);\r
+\r
+  //\r
+  // Get Old FramePtr\r
+  //\r
+  CopyMem (&FramePtr, (VOID *)((UINTN)VmPtr->FramePtr), sizeof(FramePtr));\r
+\r
+  //\r
+  // Use ReturnAddress as checkpoint for StepOver\r
+  //\r
+  CopyMem (&Address, (VOID *)(UINTN)VmPtr->Gpr[0], sizeof(Address));\r
+  EbcDebuggerPushStepEntry (Address, FramePtr, EFI_DEBUG_FLAG_EBC_STEPOVER);\r
+\r
+  //\r
+  // Use FramePtr as checkpoint for StepOut\r
+  //\r
+  Address = 0;\r
+  CopyMem (&Address, (VOID *)(FramePtr), sizeof(UINTN));\r
+  EbcDebuggerPushStepEntry (Address, FramePtr, EFI_DEBUG_FLAG_EBC_STEPOUT);\r
+\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookCALLEXStart (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The hook in ExecuteCALL, before call EbcLLCALLEX.\r
+  It will trigger Exception if BOCX enabled,\r
+  and record Callstack information.\r
+\r
+Arguments:\r
+\r
+  VmPtr - pointer to VM context.\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  EbcDebuggerCheckHookFlag (VmPtr, EFI_DEBUG_FLAG_EBC_BOCX);\r
+//  EbcDebuggerPushCallstackSource ((UINT64)(UINTN)VmPtr->Ip, EfiDebuggerBranchTypeEbcCallEx);\r
+//  EbcDebuggerPushCallstackParameter ((UINT64)(UINTN)VmPtr->R[0], EfiDebuggerBranchTypeEbcCallEx);\r
+  EbcDebuggerPushTraceSourceEntry ((UINT64)(UINTN)VmPtr->Ip, EfiDebuggerBranchTypeEbcCallEx);\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookCALLEXEnd (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The hook in ExecuteCALL, after call EbcLLCALLEX.\r
+  It will record trace information.\r
+\r
+Arguments:\r
+\r
+  VmPtr - pointer to VM context.\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+//  EbcDebuggerPushCallstackDest ((UINT64)(UINTN)VmPtr->Ip, EfiDebuggerBranchTypeEbcCallEx);\r
+  EbcDebuggerPushTraceDestEntry ((UINT64)(UINTN)VmPtr->Ip, EfiDebuggerBranchTypeEbcCallEx);\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookRETStart (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The hook in ExecuteRET, before move IP.\r
+  It will trigger Exception if BOR enabled,\r
+  and record Callstack, and trace information.\r
+\r
+Arguments:\r
+\r
+  VmPtr - pointer to VM context.\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  EbcDebuggerCheckHookFlag (VmPtr, EFI_DEBUG_FLAG_EBC_BOR);\r
+  EbcDebuggerPopCallstack ();\r
+  EbcDebuggerPushTraceSourceEntry ((UINT64)(UINTN)VmPtr->Ip, EfiDebuggerBranchTypeEbcRet);\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookRETEnd (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The hook in ExecuteRET, after move IP.\r
+  It will record trace information.\r
+\r
+Arguments:\r
+\r
+  VmPtr - pointer to VM context.\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  EbcDebuggerPushTraceDestEntry ((UINT64)(UINTN)VmPtr->Ip, EfiDebuggerBranchTypeEbcRet);\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookJMPStart (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The hook in ExecuteJMP, before move IP.\r
+  It will record trace information.\r
+\r
+Arguments:\r
+\r
+  VmPtr - pointer to VM context.\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  EbcDebuggerPushTraceSourceEntry ((UINT64)(UINTN)VmPtr->Ip, EfiDebuggerBranchTypeEbcJmp);\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookJMPEnd (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The hook in ExecuteJMP, after move IP.\r
+  It will record trace information.\r
+\r
+Arguments:\r
+\r
+  VmPtr - pointer to VM context.\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  EbcDebuggerPushTraceDestEntry ((UINT64)(UINTN)VmPtr->Ip, EfiDebuggerBranchTypeEbcJmp);\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookJMP8Start (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The hook in ExecuteJMP8, before move IP.\r
+  It will record trace information.\r
+\r
+Arguments:\r
+\r
+  VmPtr - pointer to VM context.\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  EbcDebuggerPushTraceSourceEntry ((UINT64)(UINTN)VmPtr->Ip, EfiDebuggerBranchTypeEbcJmp8);\r
+  return ;\r
+}\r
+\r
+VOID\r
+EbcDebuggerHookJMP8End (\r
+  IN VM_CONTEXT *VmPtr\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The hook in ExecuteJMP8, after move IP.\r
+  It will record trace information.\r
+\r
+Arguments:\r
+\r
+  VmPtr - pointer to VM context.\r
+\r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  EbcDebuggerPushTraceDestEntry ((UINT64)(UINTN)VmPtr->Ip, EfiDebuggerBranchTypeEbcJmp8);\r
+  return ;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbHook.h b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbHook.h
new file mode 100644 (file)
index 0000000..7cddd50
--- /dev/null
@@ -0,0 +1,27 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbHook.h\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#ifndef _EFI_EDB_HOOKER_H_\r
+#define _EFI_EDB_HOOKER_H_\r
+\r
+#include <Uefi.h>\r
+#include "EbcDebuggerHook.h"\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSupport.h b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSupport.h
new file mode 100644 (file)
index 0000000..7ad5860
--- /dev/null
@@ -0,0 +1,240 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbSupport.h\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#ifndef _EFI_EDB_SUPPORT_H_\r
+#define _EFI_EDB_SUPPORT_H_\r
+\r
+#include <Uefi.h>\r
+\r
+#define EFI_DEBUG_PROMPT_STRING      L"EDB > "\r
+#define EFI_DEBUG_PROMPT_COLUMN      5\r
+#define EFI_DEBUG_INPUS_BUFFER_SIZE  64\r
+\r
+#define EFI_DEBUGGER_LINE_NUMBER_IN_PAGE  0x10\r
+\r
+#define EFI_DEBUG_MAX_PRINT_BUFFER   (80 * 4)\r
+\r
+UINTN\r
+EFIAPI\r
+Xtoi (\r
+  CHAR16  *str\r
+  );\r
+\r
+UINT64\r
+EFIAPI\r
+LXtoi (\r
+  CHAR16  *str\r
+  );\r
+\r
+UINTN\r
+EFIAPI\r
+Atoi (\r
+  CHAR16  *str\r
+  );\r
+\r
+UINTN\r
+EFIAPI\r
+AsciiXtoi (\r
+  CHAR8  *str\r
+  );\r
+\r
+UINTN\r
+EFIAPI\r
+AsciiAtoi (\r
+  CHAR8  *str\r
+  );\r
+\r
+INTN\r
+EFIAPI\r
+StrCmpUnicodeAndAscii (\r
+  IN CHAR16   *String,\r
+  IN CHAR8    *String2\r
+  );\r
+\r
+INTN\r
+EFIAPI\r
+StriCmp (\r
+  IN CHAR16   *String,\r
+  IN CHAR16   *String2\r
+  );\r
+\r
+INTN\r
+EFIAPI\r
+StriCmpUnicodeAndAscii (\r
+  IN CHAR16   *String,\r
+  IN CHAR8    *String2\r
+  );\r
+\r
+BOOLEAN\r
+EFIAPI\r
+StrEndWith (\r
+  IN CHAR16                       *Str,\r
+  IN CHAR16                       *SubStr\r
+  );\r
+\r
+CHAR16 *\r
+EFIAPI\r
+StrDuplicate (\r
+  IN CHAR16   *Src\r
+  );\r
+\r
+CHAR16 *\r
+EFIAPI\r
+StrGetNewTokenLine (\r
+  IN CHAR16                       *String,\r
+  IN CHAR16                       *CharSet\r
+  );\r
+\r
+CHAR16 *\r
+EFIAPI\r
+StrGetNextTokenLine (\r
+  IN CHAR16                       *CharSet\r
+  );\r
+\r
+CHAR16 *\r
+EFIAPI\r
+StrGetNewTokenField (\r
+  IN CHAR16                       *String,\r
+  IN CHAR16                       *CharSet\r
+  );\r
+\r
+CHAR16 *\r
+EFIAPI\r
+StrGetNextTokenField (\r
+  IN CHAR16                       *CharSet\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+PatchForStrTokenAfter (\r
+  IN CHAR16    *Buffer,\r
+  IN CHAR16    Patch\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+PatchForStrTokenBefore (\r
+  IN CHAR16    *Buffer,\r
+  IN CHAR16    Patch\r
+  );\r
+\r
+CHAR8 *\r
+EFIAPI\r
+AsciiStrGetNewTokenLine (\r
+  IN CHAR8                       *String,\r
+  IN CHAR8                       *CharSet\r
+  );\r
+\r
+CHAR8 *\r
+EFIAPI\r
+AsciiStrGetNextTokenLine (\r
+  IN CHAR8                       *CharSet\r
+  );\r
+\r
+CHAR8 *\r
+EFIAPI\r
+AsciiStrGetNewTokenField (\r
+  IN CHAR8                       *String,\r
+  IN CHAR8                       *CharSet\r
+  );\r
+\r
+CHAR8 *\r
+EFIAPI\r
+AsciiStrGetNextTokenField (\r
+  IN CHAR8                       *CharSet\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+PatchForAsciiStrTokenAfter (\r
+  IN CHAR8    *Buffer,\r
+  IN CHAR8    Patch\r
+  );\r
+\r
+VOID\r
+EFIAPI\r
+PatchForAsciiStrTokenBefore (\r
+  IN CHAR8    *Buffer,\r
+  IN CHAR8    Patch\r
+  );\r
+\r
+//\r
+// Shell Library\r
+//\r
+VOID\r
+EFIAPI\r
+Input (\r
+  IN CHAR16    *Prompt OPTIONAL,\r
+  OUT CHAR16   *InStr,\r
+  IN UINTN     StrLen\r
+  );\r
+\r
+BOOLEAN\r
+EFIAPI\r
+SetPageBreak (\r
+  VOID\r
+  );\r
+\r
+UINTN\r
+EFIAPI\r
+EDBPrint (\r
+  IN CONST CHAR16  *Format,\r
+  ...\r
+  );\r
+\r
+UINTN\r
+EFIAPI\r
+EDBSPrint (\r
+  OUT CHAR16        *Buffer,\r
+  IN  INTN          BufferSize,\r
+  IN  CONST CHAR16  *Format,\r
+  ...\r
+  );\r
+\r
+UINTN\r
+EFIAPI\r
+EDBSPrintWithOffset (\r
+  OUT CHAR16        *Buffer,\r
+  IN  INTN          BufferSize,\r
+  IN  UINTN         Offset,\r
+  IN  CONST CHAR16  *Format,\r
+  ...\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ReadFileToBuffer (\r
+  IN  EFI_DEBUGGER_PRIVATE_DATA   *DebuggerPrivate,\r
+  IN  CHAR16                      *FileName,\r
+  OUT UINTN                       *BufferSize,\r
+  OUT VOID                        **Buffer,\r
+  IN  BOOLEAN                     ScanFs\r
+  );\r
+\r
+CHAR16 *\r
+EFIAPI\r
+GetFileNameUnderDir (\r
+  IN  EFI_DEBUGGER_PRIVATE_DATA   *DebuggerPrivate,\r
+  IN  CHAR16                      *DirName,\r
+  IN  CHAR16                      *FileName,\r
+  IN OUT UINTN                    *Index\r
+  );\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSupportFile.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSupportFile.c
new file mode 100644 (file)
index 0000000..617a5a8
--- /dev/null
@@ -0,0 +1,415 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbSupportFile.c\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#include "Edb.h"\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ReadFileFromVol (\r
+  IN  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL   *Vol,\r
+  IN  CHAR16                      *FileName,\r
+  OUT UINTN                       *BufferSize,\r
+  OUT VOID                        **Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Read a file.\r
+\r
+Arguments:\r
+\r
+  Vol             - File System Volume\r
+  FileName        - The file to be read.\r
+  BufferSize      - The file buffer size\r
+  Buffer          - The file buffer\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS    - read file successfully\r
+  EFI_NOT_FOUND  - file not found\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                        Status;\r
+  EFI_FILE_HANDLE                   RootDir;\r
+  EFI_FILE_HANDLE                   Handle;\r
+  UINTN                             FileInfoSize;\r
+  EFI_FILE_INFO                     *FileInfo;\r
+  UINTN                             TempBufferSize;\r
+  VOID                              *TempBuffer;\r
+\r
+  //\r
+  // Open the root directory\r
+  //\r
+  Status = Vol->OpenVolume (Vol, &RootDir);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Open the file\r
+  //\r
+  Status = RootDir->Open (\r
+                      RootDir,\r
+                      &Handle,\r
+                      FileName,\r
+                      EFI_FILE_MODE_READ,\r
+                      0\r
+                      );\r
+  if (EFI_ERROR (Status)) {\r
+    RootDir->Close (RootDir);\r
+    return Status;\r
+  }\r
+\r
+  RootDir->Close (RootDir);\r
+\r
+  //\r
+  // Get the file information\r
+  //\r
+  FileInfoSize = sizeof(EFI_FILE_INFO) + 1024;\r
+\r
+  FileInfo = AllocateZeroPool (FileInfoSize);\r
+  if (FileInfo == NULL) {\r
+    Handle->Close (Handle);\r
+    return Status;\r
+  }\r
+\r
+  Status = Handle->GetInfo (\r
+                     Handle,\r
+                     &gEfiFileInfoGuid,\r
+                     &FileInfoSize,\r
+                     FileInfo\r
+                     );\r
+  if (EFI_ERROR (Status)) {\r
+    Handle->Close (Handle);\r
+    gBS->FreePool (FileInfo);\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Allocate buffer for the file data. The last CHAR16 is for L'\0'\r
+  //\r
+  TempBufferSize = (UINTN) FileInfo->FileSize + sizeof(CHAR16);\r
+  TempBuffer = AllocateZeroPool (TempBufferSize);\r
+  if (TempBuffer == NULL) {\r
+    Handle->Close (Handle);\r
+    gBS->FreePool (FileInfo);\r
+    return Status;\r
+  }\r
+\r
+  gBS->FreePool (FileInfo);\r
+\r
+  //\r
+  // Read the file data to the buffer\r
+  //\r
+  Status = Handle->Read (\r
+                     Handle,\r
+                     &TempBufferSize,\r
+                     TempBuffer\r
+                     );\r
+  if (EFI_ERROR (Status)) {\r
+    Handle->Close (Handle);\r
+    gBS->FreePool (TempBuffer);\r
+    return Status;\r
+  }\r
+\r
+  Handle->Close (Handle);\r
+\r
+  *BufferSize = TempBufferSize;\r
+  *Buffer     = TempBuffer;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ReadFileToBuffer (\r
+  IN  EFI_DEBUGGER_PRIVATE_DATA   *DebuggerPrivate,\r
+  IN  CHAR16                      *FileName,\r
+  OUT UINTN                       *BufferSize,\r
+  OUT VOID                        **Buffer,\r
+  IN  BOOLEAN                     ScanFs\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Read a file.\r
+  If ScanFs is FLASE, it will use DebuggerPrivate->Vol as default Fs.\r
+  If ScanFs is TRUE, it will scan all FS and check the file.\r
+    If there is only one file match the name, it will be read.\r
+    If there is more than one file match the name, it will return Error.\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  FileName        - The file to be read.\r
+  BufferSize      - The file buffer size\r
+  Buffer          - The file buffer\r
+  ScanFs          - Need Scan all FS\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS    - read file successfully\r
+  EFI_NOT_FOUND  - file not found\r
+  EFI_NO_MAPPING - there is duplicated files found\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                        Status;\r
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL   *Vol;\r
+  UINTN                             TempBufferSize;\r
+  VOID                              *TempBuffer;\r
+  UINTN                             NoHandles;\r
+  EFI_HANDLE                        *HandleBuffer;\r
+  UINTN                             Index;\r
+\r
+  //\r
+  // Check parameters\r
+  //\r
+  if ((FileName == NULL) || (Buffer == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // not scan fs\r
+  //\r
+  if (!ScanFs) {\r
+    if (DebuggerPrivate->Vol == NULL) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    //\r
+    // Read file directly from Vol\r
+    //\r
+    return ReadFileFromVol (DebuggerPrivate->Vol, FileName, BufferSize, Buffer);\r
+  }\r
+\r
+  //\r
+  // need scan fs\r
+  //\r
+\r
+  //\r
+  // Get all Vol handle\r
+  //\r
+  Status = gBS->LocateHandleBuffer (\r
+                   ByProtocol,\r
+                   &gEfiSimpleFileSystemProtocolGuid,\r
+                   NULL,\r
+                   &NoHandles,\r
+                   &HandleBuffer\r
+                   );\r
+  if (EFI_ERROR (Status) && (NoHandles == 0)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  //\r
+  // Walk through each Vol\r
+  //\r
+  DebuggerPrivate->Vol = NULL;\r
+  *BufferSize = 0;\r
+  *Buffer     = NULL;\r
+  for (Index = 0; Index < NoHandles; Index++) {\r
+    Status = gBS->HandleProtocol (\r
+                    HandleBuffer[Index],\r
+                    &gEfiSimpleFileSystemProtocolGuid,\r
+                    (VOID**) &Vol\r
+                    );\r
+    if (EFI_ERROR(Status)) {\r
+      continue;\r
+    }\r
+\r
+    Status = ReadFileFromVol (Vol, FileName, &TempBufferSize, &TempBuffer);\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Read file OK, check duplication\r
+      //\r
+      if (DebuggerPrivate->Vol != NULL) {\r
+        //\r
+        // Find the duplicated file\r
+        //\r
+        gBS->FreePool (TempBuffer);\r
+        gBS->FreePool (*Buffer);\r
+        EDBPrint (L"Duplicated FileName found!\n");\r
+        return EFI_NO_MAPPING;\r
+      } else {\r
+        //\r
+        // Record value\r
+        //\r
+        DebuggerPrivate->Vol = Vol;\r
+        *BufferSize = TempBufferSize;\r
+        *Buffer     = TempBuffer;\r
+      }\r
+    }\r
+  }\r
+\r
+  //\r
+  // Scan Fs done\r
+  //\r
+  if (DebuggerPrivate->Vol == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+CHAR16 *\r
+EFIAPI\r
+GetFileNameUnderDir (\r
+  IN  EFI_DEBUGGER_PRIVATE_DATA   *DebuggerPrivate,\r
+  IN  CHAR16                      *DirName,\r
+  IN  CHAR16                      *FileName,\r
+  IN OUT UINTN                    *Index\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Get file name under this dir with index\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  DirName         - The dir to be read.\r
+  FileName        - The file name pattern under this dir\r
+  Index           - The file index under this dir\r
+\r
+Returns:\r
+\r
+  File Name which match the pattern and index.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                        Status;\r
+  EFI_FILE_HANDLE                   RootDir;\r
+  EFI_FILE_HANDLE                   Handle;\r
+  UINTN                             FileInfoSize;\r
+  EFI_FILE_INFO                     *FileInfo;\r
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL   *Vol;\r
+  VOID                              *TempName;\r
+  UINTN                             FileIndex;\r
+\r
+  if (DebuggerPrivate->Vol == NULL) {\r
+    Status = gBS->LocateProtocol (\r
+                    &gEfiSimpleFileSystemProtocolGuid,\r
+                    NULL,\r
+                    (VOID**) &DebuggerPrivate->Vol\r
+                    );\r
+    if (EFI_ERROR(Status)) {\r
+      return NULL;\r
+    }\r
+  }\r
+  Vol = DebuggerPrivate->Vol;\r
+\r
+  //\r
+  // Open the root directory\r
+  //\r
+  Status = Vol->OpenVolume (Vol, &RootDir);\r
+  if (EFI_ERROR (Status)) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Open the file\r
+  //\r
+  Status = RootDir->Open (\r
+                      RootDir,\r
+                      &Handle,\r
+                      DirName,\r
+                      EFI_FILE_MODE_READ,\r
+                      EFI_FILE_DIRECTORY\r
+                      );\r
+  if (EFI_ERROR (Status)) {\r
+    RootDir->Close (RootDir);\r
+    return NULL;\r
+  }\r
+  RootDir->Close (RootDir);\r
+\r
+  //\r
+  // Set Dir Position\r
+  //\r
+  Status = Handle->SetPosition (Handle, 0);\r
+  if (EFI_ERROR (Status)) {\r
+    Handle->Close (Handle);\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Get the file information\r
+  //\r
+  FileInfoSize = sizeof(EFI_FILE_INFO) + 1024;\r
+\r
+  FileInfo = AllocateZeroPool (FileInfoSize);\r
+  if (FileInfo == NULL) {\r
+    Handle->Close (Handle);\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Walk through each file in the directory\r
+  //\r
+  FileIndex = 0;\r
+  TempName = NULL;\r
+  while (TRUE) {\r
+    //\r
+    // Read a file entry\r
+    //\r
+    FileInfoSize = sizeof(EFI_FILE_INFO) + 1024;\r
+\r
+    Status = Handle->Read (\r
+                       Handle,\r
+                       &FileInfoSize,\r
+                       FileInfo\r
+                       );\r
+    if (EFI_ERROR (Status) || (FileInfoSize == 0)) {\r
+      break;\r
+    }\r
+\r
+    if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == 0) {\r
+      //\r
+      // This is a file\r
+      //\r
+\r
+      //\r
+      // Only deal with the EFI key file\r
+      //\r
+      if (!StrEndWith (FileInfo->FileName, FileName)) {\r
+        continue;\r
+      }\r
+\r
+      if (FileIndex == *Index) {\r
+        TempName = StrDuplicate (FileInfo->FileName);\r
+        *Index = *Index + 1;\r
+        break;\r
+      }\r
+      FileIndex ++;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Free resources\r
+  //\r
+  gBS->FreePool (FileInfo);\r
+  Handle->Close (Handle);\r
+\r
+  return TempName;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSupportString.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSupportString.c
new file mode 100644 (file)
index 0000000..558fe91
--- /dev/null
@@ -0,0 +1,991 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbSupportString.c\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#include "Edb.h"\r
+\r
+UINTN\r
+EFIAPI\r
+Xtoi (\r
+  CHAR16  *str\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Convert hex string to uint\r
+\r
+Arguments:\r
+\r
+  Str  -  The string\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  UINTN   u;\r
+  CHAR16  c;\r
+  UINTN   m;\r
+\r
+  ASSERT (str != NULL);\r
+\r
+  m = (UINTN) -1 >> 4;\r
+  //\r
+  // skip preceeding white space\r
+  //\r
+  while (*str && *str == ' ') {\r
+    str += 1;\r
+  }\r
+  //\r
+  // skip preceeding zeros\r
+  //\r
+  while (*str && *str == '0') {\r
+    str += 1;\r
+  }\r
+  //\r
+  // skip preceeding white space\r
+  //\r
+  if (*str && (*str == 'x' || *str == 'X')) {\r
+    str += 1;\r
+  }\r
+  //\r
+  // convert hex digits\r
+  //\r
+  u = 0;\r
+  c = *(str++);\r
+  while (c) {\r
+    if (c >= 'a' && c <= 'f') {\r
+      c -= 'a' - 'A';\r
+    }\r
+\r
+    if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')) {\r
+      if (u > m) {\r
+        return (UINTN) -1;\r
+      }\r
+\r
+      u = (u << 4) | (c - (c >= 'A' ? 'A' - 10 : '0'));\r
+    } else {\r
+      break;\r
+    }\r
+\r
+    c = *(str++);\r
+  }\r
+\r
+  return u;\r
+}\r
+\r
+UINT64\r
+EFIAPI\r
+LXtoi (\r
+  CHAR16  *str\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Convert hex string to uint\r
+\r
+Arguments:\r
+\r
+  Str  -  The string\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  UINT64  u;\r
+  CHAR16  c;\r
+  UINT64  m;\r
+\r
+  ASSERT (str != NULL);\r
+\r
+  m = RShiftU64 ((UINT64) -1, 4);\r
+  //\r
+  // skip preceeding white space\r
+  //\r
+  while (*str && *str == ' ') {\r
+    str += 1;\r
+  }\r
+  //\r
+  // skip preceeding zeros\r
+  //\r
+  while (*str && *str == '0') {\r
+    str += 1;\r
+  }\r
+  //\r
+  // skip preceeding white space\r
+  //\r
+  if (*str && (*str == 'x' || *str == 'X')) {\r
+    str += 1;\r
+  }\r
+  //\r
+  // convert hex digits\r
+  //\r
+  u = 0;\r
+  c = *(str++);\r
+  while (c) {\r
+    if (c >= 'a' && c <= 'f') {\r
+      c -= 'a' - 'A';\r
+    }\r
+\r
+    if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')) {\r
+      if (u > m) {\r
+        return (UINT64) -1;\r
+      }\r
+\r
+      u = LShiftU64 (u, 4);\r
+      u = u + (c - (c >= 'A' ? 'A' - 10 : '0'));\r
+    } else {\r
+      break;\r
+    }\r
+\r
+    c = *(str++);\r
+  }\r
+\r
+  return u;\r
+}\r
+\r
+UINTN\r
+EFIAPI\r
+Atoi (\r
+  CHAR16  *str\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Convert hex string to uint\r
+\r
+Arguments:\r
+\r
+  Str  -  The string\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  UINTN   u;\r
+  CHAR16  c;\r
+  UINTN   m;\r
+  UINTN   n;\r
+\r
+  ASSERT (str != NULL);\r
+\r
+  m = (UINTN) -1 / 10;\r
+  n = (UINTN) -1 % 10;\r
+  //\r
+  // skip preceeding white space\r
+  //\r
+  while (*str && *str == ' ') {\r
+    str += 1;\r
+  }\r
+  //\r
+  // convert digits\r
+  //\r
+  u = 0;\r
+  c = *(str++);\r
+  while (c) {\r
+    if (c >= '0' && c <= '9') {\r
+      if (u > m || (u == m && c - '0' > (INTN) n)) {\r
+        return (UINTN) -1;\r
+      }\r
+\r
+      u = (u * 10) + c - '0';\r
+    } else {\r
+      break;\r
+    }\r
+\r
+    c = *(str++);\r
+  }\r
+\r
+  return u;\r
+}\r
+\r
+UINTN\r
+EFIAPI\r
+AsciiXtoi (\r
+  CHAR8  *str\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Convert hex string to uint\r
+\r
+Arguments:\r
+\r
+  Str  -  The string\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  UINTN   u;\r
+  CHAR8   c;\r
+  UINTN   m;\r
+\r
+  ASSERT (str != NULL);\r
+\r
+  m = (UINTN) -1 >> 4;\r
+  //\r
+  // skip preceeding white space\r
+  //\r
+  while (*str && *str == ' ') {\r
+    str += 1;\r
+  }\r
+  //\r
+  // skip preceeding zeros\r
+  //\r
+  while (*str && *str == '0') {\r
+    str += 1;\r
+  }\r
+  //\r
+  // skip preceeding white space\r
+  //\r
+  if (*str && (*str == 'x' || *str == 'X')) {\r
+    str += 1;\r
+  }\r
+  //\r
+  // convert hex digits\r
+  //\r
+  u = 0;\r
+  c = *(str++);\r
+  while (c) {\r
+    if (c >= 'a' && c <= 'f') {\r
+      c -= 'a' - 'A';\r
+    }\r
+\r
+    if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')) {\r
+      if (u > m) {\r
+        return (UINTN) -1;\r
+      }\r
+\r
+      u = (u << 4) | (c - (c >= 'A' ? 'A' - 10 : '0'));\r
+    } else {\r
+      break;\r
+    }\r
+\r
+    c = *(str++);\r
+  }\r
+\r
+  return u;\r
+}\r
+\r
+UINTN\r
+EFIAPI\r
+AsciiAtoi (\r
+  CHAR8  *str\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Convert hex string to uint\r
+\r
+Arguments:\r
+\r
+  Str  -  The string\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  UINTN   u;\r
+  CHAR8   c;\r
+  UINTN   m;\r
+  UINTN   n;\r
+\r
+  ASSERT (str != NULL);\r
+\r
+  m = (UINTN) -1 / 10;\r
+  n = (UINTN) -1 % 10;\r
+  //\r
+  // skip preceeding white space\r
+  //\r
+  while (*str && *str == ' ') {\r
+    str += 1;\r
+  }\r
+  //\r
+  // convert digits\r
+  //\r
+  u = 0;\r
+  c = *(str++);\r
+  while (c) {\r
+    if (c >= '0' && c <= '9') {\r
+      if (u > m || (u == m && c - '0' > (INTN) n)) {\r
+        return (UINTN) -1;\r
+      }\r
+\r
+      u = (u * 10) + c - '0';\r
+    } else {\r
+      break;\r
+    }\r
+\r
+    c = *(str++);\r
+  }\r
+\r
+  return u;\r
+}\r
+\r
+STATIC\r
+CHAR16\r
+UnicodeToUpper (\r
+  IN      CHAR16                    Chr\r
+  )\r
+{\r
+  return (Chr >= L'a' && Chr <= L'z') ? Chr - (L'a' - L'A') : Chr;\r
+}\r
+\r
+STATIC\r
+CHAR8\r
+AsciiToUpper (\r
+  IN      CHAR8                     Chr\r
+  )\r
+{\r
+  return (Chr >= 'a' && Chr <= 'z') ? Chr - ('a' - 'A') : Chr;\r
+}\r
+\r
+INTN\r
+EFIAPI\r
+StrCmpUnicodeAndAscii (\r
+  IN CHAR16   *String,\r
+  IN CHAR8    *String2\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Compare the Unicode and Ascii string pointed by String to the string pointed by String2.\r
+\r
+Arguments:\r
+  String - Unicode String to process\r
+\r
+  String2 - Ascii string to process\r
+\r
+Returns:\r
+  Return a positive integer if String is lexicall greater than String2; Zero if\r
+  the two strings are identical; and a negative interger if String is lexically\r
+  less than String2.\r
+\r
+--*/\r
+{\r
+  while (*String) {\r
+    if (*String != (CHAR16)*String2) {\r
+      break;\r
+    }\r
+\r
+    String += 1;\r
+    String2 += 1;\r
+  }\r
+\r
+  return (*String - (CHAR16)*String2);\r
+}\r
+\r
+INTN\r
+EFIAPI\r
+StriCmp (\r
+  IN CHAR16   *String,\r
+  IN CHAR16   *String2\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Compare the Unicode string pointed by String to the string pointed by String2.\r
+\r
+Arguments:\r
+  String - Unicode String to process\r
+  String2 - Unicode string to process\r
+\r
+Returns:\r
+  Return a positive integer if String is lexically greater than String2; Zero if\r
+  the two strings are identical; and a negative integer if String is lexically\r
+  less than String2.\r
+\r
+--*/\r
+{\r
+  while ((*String != L'\0') &&\r
+         (UnicodeToUpper (*String) == UnicodeToUpper (*String2))) {\r
+    String++;\r
+    String2++;\r
+  }\r
+\r
+  return UnicodeToUpper (*String) - UnicodeToUpper (*String2);\r
+}\r
+\r
+INTN\r
+EFIAPI\r
+StriCmpUnicodeAndAscii (\r
+  IN CHAR16   *String,\r
+  IN CHAR8    *String2\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Compare the Unicode and Ascii string pointed by String to the string pointed by String2.\r
+\r
+Arguments:\r
+  String - Unicode String to process\r
+\r
+  String2 - Ascii string to process\r
+\r
+Returns:\r
+  Return a positive integer if String is lexically greater than String2; Zero if\r
+  the two strings are identical; and a negative integer if String is lexically\r
+  less than String2.\r
+\r
+--*/\r
+{\r
+  while ((*String != L'\0') &&\r
+         (UnicodeToUpper (*String) == (CHAR16)AsciiToUpper (*String2))) {\r
+    String++;\r
+    String2++;\r
+  }\r
+\r
+  return UnicodeToUpper (*String) - (CHAR16)AsciiToUpper (*String2);\r
+}\r
+\r
+BOOLEAN\r
+EFIAPI\r
+StrEndWith (\r
+  IN CHAR16                       *Str,\r
+  IN CHAR16                       *SubStr\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Verify if the string is end with the sub string.\r
+\r
+--*/\r
+{\r
+  CHAR16  *Temp;\r
+\r
+  if ((Str == NULL) || (SubStr == NULL) || (StrLen(Str) < StrLen(SubStr))) {\r
+    return FALSE;\r
+  }\r
+\r
+  Temp = Str + StrLen(Str) - StrLen(SubStr);\r
+\r
+  //\r
+  // Compare\r
+  //\r
+  if (StriCmp (Temp, SubStr) == 0) {\r
+    return TRUE;\r
+  } else {\r
+    return FALSE;\r
+  }\r
+}\r
+\r
+CHAR16 *\r
+EFIAPI\r
+StrDuplicate (\r
+  IN CHAR16   *Src\r
+  )\r
+// duplicate a string\r
+{\r
+  CHAR16      *Dest;\r
+  UINTN       Size;\r
+\r
+  Size = (StrLen(Src) + 1) * sizeof(CHAR16);\r
+  Dest = AllocateZeroPool (Size);\r
+  if (Dest) {\r
+    CopyMem (Dest, Src, Size);\r
+  }\r
+  return Dest;\r
+}\r
+\r
+\r
+CHAR16  *mLineBuffer          = NULL;\r
+CHAR16  *mFieldBuffer         = NULL;\r
+\r
+UINTN\r
+EFIAPI\r
+StrSpn (\r
+  IN CHAR16                       *String,\r
+  IN CHAR16                       *CharSet\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Find the first substring.\r
+\r
+--*/\r
+{\r
+  UINTN   Count;\r
+  CHAR16  *Str1;\r
+  CHAR16  *Str2;\r
+\r
+  Count = 0;\r
+\r
+  for (Str1 = String; *Str1 != L'\0'; Str1 ++) {\r
+    for (Str2 = CharSet; *Str2 != L'\0'; Str2 ++) {\r
+      if (*Str1 == *Str2) {\r
+        break;\r
+      }\r
+    }\r
+\r
+    if (*Str2 == L'\0') {\r
+      return Count;\r
+    }\r
+\r
+    Count ++;\r
+  }\r
+\r
+  return Count;\r
+}\r
+\r
+\r
+CHAR16 *\r
+EFIAPI\r
+StrBrk (\r
+  IN CHAR16                       *String,\r
+  IN CHAR16                       *CharSet\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Searches a string for the first occurrence of a character contained in a\r
+  specified buffer.\r
+\r
+--*/\r
+{\r
+  CHAR16  *Str1;\r
+  CHAR16  *Str2;\r
+\r
+  for (Str1 = String; *Str1 != L'\0'; Str1 ++) {\r
+    for (Str2 = CharSet; *Str2 != L'\0'; Str2 ++) {\r
+      if (*Str1 == *Str2) {\r
+        return (CHAR16 *) Str1;\r
+      }\r
+    }\r
+  }\r
+\r
+  return NULL;\r
+}\r
+\r
+CHAR16 *\r
+EFIAPI\r
+StrTokenLine (\r
+  IN CHAR16                       *String OPTIONAL,\r
+  IN CHAR16                       *CharSet\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Find the next token after one or more specified characters.\r
+\r
+--*/\r
+{\r
+  CHAR16  *Begin;\r
+  CHAR16  *End;\r
+\r
+  Begin = (String == NULL) ? mLineBuffer : String;\r
+  if (Begin == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  Begin += StrSpn (Begin, CharSet);\r
+  if (*Begin == L'\0') {\r
+    mLineBuffer = NULL;\r
+    return NULL;\r
+  }\r
+\r
+  End = StrBrk (Begin, CharSet);\r
+  if ((End != NULL) && (*End != L'\0')) {\r
+    *End = L'\0';\r
+    End ++;\r
+  }\r
+\r
+  mLineBuffer = End;\r
+  return Begin;\r
+}\r
+\r
+\r
+CHAR16 *\r
+EFIAPI\r
+StrTokenField (\r
+  IN CHAR16                       *String OPTIONAL,\r
+  IN CHAR16                       *CharSet\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Find the next token after one specificed characters.\r
+\r
+--*/\r
+{\r
+  CHAR16  *Begin;\r
+  CHAR16  *End;\r
+\r
+\r
+  Begin = (String == NULL) ? mFieldBuffer : String;\r
+  if (Begin == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  if (*Begin == L'\0') {\r
+    mFieldBuffer = NULL;\r
+    return NULL;\r
+  }\r
+\r
+  End = StrBrk (Begin, CharSet);\r
+  if ((End != NULL) && (*End != L'\0')) {\r
+    *End = L'\0';\r
+    End ++;\r
+  }\r
+\r
+  mFieldBuffer = End;\r
+  return Begin;\r
+}\r
+\r
+CHAR16 *\r
+EFIAPI\r
+StrGetNewTokenLine (\r
+  IN CHAR16                       *String,\r
+  IN CHAR16                       *CharSet\r
+  )\r
+{\r
+  return StrTokenLine (String, CharSet);\r
+}\r
+\r
+CHAR16 *\r
+EFIAPI\r
+StrGetNextTokenLine (\r
+  IN CHAR16                       *CharSet\r
+  )\r
+{\r
+  return StrTokenLine (NULL, CharSet);\r
+}\r
+\r
+CHAR16 *\r
+EFIAPI\r
+StrGetNewTokenField (\r
+  IN CHAR16                       *String,\r
+  IN CHAR16                       *CharSet\r
+  )\r
+{\r
+  return StrTokenField (String, CharSet);\r
+}\r
+\r
+CHAR16 *\r
+EFIAPI\r
+StrGetNextTokenField (\r
+  IN CHAR16                       *CharSet\r
+  )\r
+{\r
+  return StrTokenField (NULL, CharSet);\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+PatchForStrTokenAfter (\r
+  IN CHAR16    *Buffer,\r
+  IN CHAR16    Patch\r
+  )\r
+{\r
+  CHAR16 *Str;\r
+\r
+  if (Buffer == NULL) {\r
+    return ;\r
+  }\r
+\r
+  Str = Buffer;\r
+  while (*Str != 0) {\r
+    Str ++;\r
+  }\r
+  *Str = Patch;\r
+\r
+  while (*(Str ++)) {\r
+    if (*Str == 0) {\r
+      *Str = Patch;\r
+    } else {\r
+      break;\r
+    }\r
+  }\r
+\r
+  return ;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+PatchForStrTokenBefore (\r
+  IN CHAR16    *Buffer,\r
+  IN CHAR16    Patch\r
+  )\r
+{\r
+  CHAR16 *Str;\r
+\r
+  if (Buffer == NULL) {\r
+    return ;\r
+  }\r
+\r
+  Str = Buffer;\r
+  while (*(Str --)) {\r
+    if ((*Str == 0) || (*Str == Patch)) {\r
+      *Str = Patch;\r
+    } else {\r
+      break;\r
+    }\r
+  }\r
+\r
+  return ;\r
+}\r
+\r
+CHAR8  *mAsciiLineBuffer          = NULL;\r
+CHAR8  *mAsciiFieldBuffer         = NULL;\r
+\r
+UINTN\r
+EFIAPI\r
+AsciiStrSpn (\r
+  IN CHAR8                       *String,\r
+  IN CHAR8                       *CharSet\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Find the first substring.\r
+\r
+--*/\r
+{\r
+  UINTN   Count;\r
+  CHAR8  *Str1;\r
+  CHAR8  *Str2;\r
+\r
+  Count = 0;\r
+\r
+  for (Str1 = String; *Str1 != '\0'; Str1 ++) {\r
+    for (Str2 = CharSet; *Str2 != '\0'; Str2 ++) {\r
+      if (*Str1 == *Str2) {\r
+        break;\r
+      }\r
+    }\r
+\r
+    if (*Str2 == '\0') {\r
+      return Count;\r
+    }\r
+\r
+    Count ++;\r
+  }\r
+\r
+  return Count;\r
+}\r
+\r
+\r
+CHAR8 *\r
+EFIAPI\r
+AsciiStrBrk (\r
+  IN CHAR8                       *String,\r
+  IN CHAR8                       *CharSet\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Searches a string for the first occurrence of a character contained in a\r
+  specified buffer.\r
+\r
+--*/\r
+{\r
+  CHAR8  *Str1;\r
+  CHAR8  *Str2;\r
+\r
+  for (Str1 = String; *Str1 != '\0'; Str1 ++) {\r
+    for (Str2 = CharSet; *Str2 != '\0'; Str2 ++) {\r
+      if (*Str1 == *Str2) {\r
+        return (CHAR8 *) Str1;\r
+      }\r
+    }\r
+  }\r
+\r
+  return NULL;\r
+}\r
+\r
+CHAR8 *\r
+EFIAPI\r
+AsciiStrTokenLine (\r
+  IN CHAR8                       *String OPTIONAL,\r
+  IN CHAR8                       *CharSet\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Find the next token after one or more specified characters.\r
+\r
+--*/\r
+{\r
+  CHAR8  *Begin;\r
+  CHAR8  *End;\r
+\r
+  Begin = (String == NULL) ? mAsciiLineBuffer : String;\r
+  if (Begin == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  Begin += AsciiStrSpn (Begin, CharSet);\r
+  if (*Begin == '\0') {\r
+    mAsciiLineBuffer = NULL;\r
+    return NULL;\r
+  }\r
+\r
+  End = AsciiStrBrk (Begin, CharSet);\r
+  if ((End != NULL) && (*End != '\0')) {\r
+    *End = '\0';\r
+    End ++;\r
+  }\r
+\r
+  mAsciiLineBuffer = End;\r
+  return Begin;\r
+}\r
+\r
+\r
+CHAR8 *\r
+EFIAPI\r
+AsciiStrTokenField (\r
+  IN CHAR8                       *String OPTIONAL,\r
+  IN CHAR8                       *CharSet\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Find the next token after one specificed characters.\r
+\r
+--*/\r
+{\r
+  CHAR8  *Begin;\r
+  CHAR8  *End;\r
+\r
+\r
+  Begin = (String == NULL) ? mAsciiFieldBuffer : String;\r
+  if (Begin == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  if (*Begin == L'\0') {\r
+    mAsciiFieldBuffer = NULL;\r
+    return NULL;\r
+  }\r
+\r
+  End = AsciiStrBrk (Begin, CharSet);\r
+  if ((End != NULL) && (*End != '\0')) {\r
+    *End = '\0';\r
+    End ++;\r
+  }\r
+\r
+  mAsciiFieldBuffer = End;\r
+  return Begin;\r
+}\r
+\r
+CHAR8 *\r
+EFIAPI\r
+AsciiStrGetNewTokenLine (\r
+  IN CHAR8                       *String,\r
+  IN CHAR8                       *CharSet\r
+  )\r
+{\r
+  return AsciiStrTokenLine (String, CharSet);\r
+}\r
+\r
+CHAR8 *\r
+EFIAPI\r
+AsciiStrGetNextTokenLine (\r
+  IN CHAR8                       *CharSet\r
+  )\r
+{\r
+  return AsciiStrTokenLine (NULL, CharSet);\r
+}\r
+\r
+CHAR8 *\r
+EFIAPI\r
+AsciiStrGetNewTokenField (\r
+  IN CHAR8                       *String,\r
+  IN CHAR8                       *CharSet\r
+  )\r
+{\r
+  return AsciiStrTokenField (String, CharSet);\r
+}\r
+\r
+CHAR8 *\r
+EFIAPI\r
+AsciiStrGetNextTokenField (\r
+  IN CHAR8                       *CharSet\r
+  )\r
+{\r
+  return AsciiStrTokenField (NULL, CharSet);\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+PatchForAsciiStrTokenAfter (\r
+  IN CHAR8    *Buffer,\r
+  IN CHAR8    Patch\r
+  )\r
+{\r
+  CHAR8 *Str;\r
+\r
+  if (Buffer == NULL) {\r
+    return ;\r
+  }\r
+\r
+  Str = Buffer;\r
+  while (*Str != 0) {\r
+    Str ++;\r
+  }\r
+  *Str = Patch;\r
+\r
+  while (*(Str ++)) {\r
+    if (*Str == 0) {\r
+      *Str = Patch;\r
+    } else {\r
+      break;\r
+    }\r
+  }\r
+\r
+  return ;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+PatchForAsciiStrTokenBefore (\r
+  IN CHAR8    *Buffer,\r
+  IN CHAR8    Patch\r
+  )\r
+{\r
+  CHAR8 *Str;\r
+\r
+  if (Buffer == NULL) {\r
+    return ;\r
+  }\r
+\r
+  Str = Buffer;\r
+  while (*(Str --)) {\r
+    if ((*Str == 0) || (*Str == Patch)) {\r
+      *Str = Patch;\r
+    } else {\r
+      break;\r
+    }\r
+  }\r
+\r
+  return ;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSupportUI.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSupportUI.c
new file mode 100644 (file)
index 0000000..265e6c1
--- /dev/null
@@ -0,0 +1,708 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbSupportUI.c\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#include "Edb.h"\r
+\r
+VOID\r
+EFIAPI\r
+SetCursorPosition (\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *ConOut,\r
+  IN  UINTN                           Column,\r
+  IN  INTN                            Row,\r
+  IN  UINTN                           LineLength,\r
+  IN  UINTN                           TotalRow,\r
+  IN  CHAR16                          *Str,\r
+  IN  UINTN                           StrPos,\r
+  IN  UINTN                           Len\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+WaitForSingleEvent (\r
+  IN EFI_EVENT                  Event,\r
+  IN UINT64                     Timeout OPTIONAL\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Function waits for a given event to fire, or for an optional timeout to expire.\r
+\r
+Arguments:\r
+  Event            - The event to wait for\r
+\r
+  Timeout          - An optional timeout value in 100 ns units.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS       - Event fired before Timeout expired.\r
+  EFI_TIME_OUT     - Timout expired before Event fired..\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  UINTN       Index;\r
+  EFI_EVENT   TimerEvent;\r
+  EFI_EVENT   WaitList[2];\r
+\r
+  if (Timeout) {\r
+    //\r
+    // Create a timer event\r
+    //\r
+    Status = gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &TimerEvent);\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Set the timer event\r
+      //\r
+      gBS->SetTimer (\r
+            TimerEvent,\r
+            TimerRelative,\r
+            Timeout\r
+            );\r
+\r
+      //\r
+      // Wait for the original event or the timer\r
+      //\r
+      WaitList[0] = Event;\r
+      WaitList[1] = TimerEvent;\r
+      Status      = gBS->WaitForEvent (2, WaitList, &Index);\r
+      gBS->CloseEvent (TimerEvent);\r
+\r
+      //\r
+      // If the timer expired, change the return to timed out\r
+      //\r
+      if (!EFI_ERROR (Status) && Index == 1) {\r
+        Status = EFI_TIMEOUT;\r
+      }\r
+    }\r
+  } else {\r
+    //\r
+    // No timeout... just wait on the event\r
+    //\r
+    Status = gBS->WaitForEvent (1, &Event, &Index);\r
+    ASSERT (!EFI_ERROR (Status));\r
+    ASSERT (Index == 0);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ConMoveCursorBackward (\r
+  IN     UINTN                   LineLength,\r
+  IN OUT UINTN                   *Column,\r
+  IN OUT UINTN                   *Row\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Move the cursor position one character backward.\r
+\r
+Arguments:\r
+  LineLength       Length of a line. Get it by calling QueryMode\r
+  Column           Current column of the cursor position\r
+  Row              Current row of the cursor position\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  ASSERT (Column != NULL);\r
+  ASSERT (Row != NULL);\r
+  //\r
+  // If current column is 0, move to the last column of the previous line,\r
+  // otherwise, just decrement column.\r
+  //\r
+  if (*Column == 0) {\r
+    (*Column) = LineLength - 1;\r
+    //\r
+    //   if (*Row > 0) {\r
+    //\r
+    (*Row)--;\r
+    //\r
+    // }\r
+    //\r
+  } else {\r
+    (*Column)--;\r
+  }\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ConMoveCursorForward (\r
+  IN     UINTN                   LineLength,\r
+  IN     UINTN                   TotalRow,\r
+  IN OUT UINTN                   *Column,\r
+  IN OUT UINTN                   *Row\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Move the cursor position one character backward.\r
+\r
+Arguments:\r
+  LineLength       Length of a line. Get it by calling QueryMode\r
+  TotalRow         Total row of a screen, get by calling QueryMode\r
+  Column           Current column of the cursor position\r
+  Row              Current row of the cursor position\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  ASSERT (Column != NULL);\r
+  ASSERT (Row != NULL);\r
+  //\r
+  // If current column is at line end, move to the first column of the nest\r
+  // line, otherwise, just increment column.\r
+  //\r
+  (*Column)++;\r
+  if (*Column >= LineLength) {\r
+    (*Column) = 0;\r
+    if ((*Row) < TotalRow - 1) {\r
+      (*Row)++;\r
+    }\r
+  }\r
+}\r
+\r
+CHAR16 mBackupSpace[EFI_DEBUG_INPUS_BUFFER_SIZE];\r
+CHAR16 mInputBufferHistory[EFI_DEBUG_INPUS_BUFFER_SIZE];\r
+\r
+VOID\r
+EFIAPI\r
+Input (\r
+  IN CHAR16    *Prompt OPTIONAL,\r
+  OUT CHAR16   *InStr,\r
+  IN UINTN     StrLength\r
+  )\r
+{\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL     *ConOut;\r
+  EFI_SIMPLE_TEXT_INPUT_PROTOCOL      *ConIn;\r
+  BOOLEAN       Done;\r
+  UINTN         Column;\r
+  UINTN         Row;\r
+  UINTN         StartColumn;\r
+  UINTN         Update;\r
+  UINTN         Delete;\r
+  UINTN         Len;\r
+  UINTN         StrPos;\r
+  UINTN         Index;\r
+  UINTN         LineLength;\r
+  UINTN         TotalRow;\r
+  UINTN         SkipLength;\r
+  UINTN         OutputLength;\r
+  UINTN         TailRow;\r
+  UINTN         TailColumn;\r
+  EFI_INPUT_KEY Key;\r
+  BOOLEAN       InsertMode;\r
+  BOOLEAN       NeedAdjust;\r
+  UINTN         SubIndex;\r
+  CHAR16        *CommandStr;\r
+\r
+  ConOut = gST->ConOut;\r
+  ConIn = gST->ConIn;\r
+\r
+  ASSERT (ConOut != NULL);\r
+  ASSERT (ConIn != NULL);\r
+  ASSERT (InStr != NULL);\r
+\r
+  if (Prompt) {\r
+    ConOut->OutputString (ConOut, Prompt);\r
+  }\r
+  //\r
+  // Read a line from the console\r
+  //\r
+  Len           = 0;\r
+  StrPos        = 0;\r
+  OutputLength  = 0;\r
+  Update        = 0;\r
+  Delete        = 0;\r
+  InsertMode    = TRUE;\r
+  NeedAdjust    = FALSE;\r
+\r
+  //\r
+  // If buffer is not large enough to hold a CHAR16, do nothing.\r
+  //\r
+  if (StrLength < 1) {\r
+    return ;\r
+  }\r
+  //\r
+  // Get the screen setting and the current cursor location\r
+  //\r
+  StartColumn = ConOut->Mode->CursorColumn;\r
+  Column      = StartColumn;\r
+  Row         = ConOut->Mode->CursorRow;\r
+  ConOut->QueryMode (ConOut, ConOut->Mode->Mode, &LineLength, &TotalRow);\r
+  if (LineLength == 0) {\r
+    return ;\r
+  }\r
+\r
+  SetMem (InStr, StrLength * sizeof (CHAR16), 0);\r
+  Done = FALSE;\r
+  do {\r
+    //\r
+    // Read a key\r
+    //\r
+    WaitForSingleEvent (ConIn->WaitForKey, 0);\r
+    ConIn->ReadKeyStroke (ConIn, &Key);\r
+\r
+    switch (Key.UnicodeChar) {\r
+    case CHAR_CARRIAGE_RETURN:\r
+      //\r
+      // All done, print a newline at the end of the string\r
+      //\r
+      TailRow     = Row + (Len - StrPos + Column) / LineLength;\r
+      TailColumn  = (Len - StrPos + Column) % LineLength;\r
+      Done        = TRUE;\r
+      break;\r
+\r
+    case CHAR_BACKSPACE:\r
+      if (StrPos) {\r
+        //\r
+        // If not move back beyond string beginning, move all characters behind\r
+        // the current position one character forward\r
+        //\r
+        StrPos -= 1;\r
+        Update  = StrPos;\r
+        Delete  = 1;\r
+        CopyMem (InStr + StrPos, InStr + StrPos + 1, sizeof (CHAR16) * (Len - StrPos));\r
+\r
+        //\r
+        // Adjust the current column and row\r
+        //\r
+        ConMoveCursorBackward (LineLength, &Column, &Row);\r
+\r
+        NeedAdjust = TRUE;\r
+      }\r
+      break;\r
+\r
+    default:\r
+      if (Key.UnicodeChar >= ' ') {\r
+        //\r
+        // If we are at the buffer's end, drop the key\r
+        //\r
+        if (Len == StrLength - 1 && (InsertMode || StrPos == Len)) {\r
+          break;\r
+        }\r
+        //\r
+        // If in insert mode, move all characters behind the current position\r
+        // one character backward to make space for this character. Then store\r
+        // the character.\r
+        //\r
+        if (InsertMode) {\r
+          for (Index = Len; Index > StrPos; Index -= 1) {\r
+            InStr[Index] = InStr[Index - 1];\r
+          }\r
+        }\r
+\r
+        InStr[StrPos] = Key.UnicodeChar;\r
+        Update        = StrPos;\r
+\r
+        StrPos += 1;\r
+        OutputLength = 1;\r
+      }\r
+      break;\r
+\r
+    case 0:\r
+      switch (Key.ScanCode) {\r
+      case SCAN_DELETE:\r
+        //\r
+        // Move characters behind current position one character forward\r
+        //\r
+        if (Len) {\r
+          Update  = StrPos;\r
+          Delete  = 1;\r
+          CopyMem (InStr + StrPos, InStr + StrPos + 1, sizeof (CHAR16) * (Len - StrPos));\r
+\r
+          NeedAdjust = TRUE;\r
+        }\r
+        break;\r
+\r
+      case SCAN_LEFT:\r
+        //\r
+        // Adjust current cursor position\r
+        //\r
+        if (StrPos) {\r
+          StrPos -= 1;\r
+          ConMoveCursorBackward (LineLength, &Column, &Row);\r
+        }\r
+        break;\r
+\r
+      case SCAN_RIGHT:\r
+        //\r
+        // Adjust current cursor position\r
+        //\r
+        if (StrPos < Len) {\r
+          StrPos += 1;\r
+          ConMoveCursorForward (LineLength, TotalRow, &Column, &Row);\r
+        }\r
+        break;\r
+\r
+      case SCAN_HOME:\r
+        //\r
+        // Move current cursor position to the beginning of the command line\r
+        //\r
+        Row -= (StrPos + StartColumn) / LineLength;\r
+        Column  = StartColumn;\r
+        StrPos  = 0;\r
+        break;\r
+\r
+      case SCAN_END:\r
+        //\r
+        // Move current cursor position to the end of the command line\r
+        //\r
+        TailRow     = Row + (Len - StrPos + Column) / LineLength;\r
+        TailColumn  = (Len - StrPos + Column) % LineLength;\r
+        Row         = TailRow;\r
+        Column      = TailColumn;\r
+        StrPos      = Len;\r
+        break;\r
+\r
+      case SCAN_ESC:\r
+        //\r
+        // Prepare to clear the current command line\r
+        //\r
+        InStr[0]  = 0;\r
+        Update    = 0;\r
+        Delete    = Len;\r
+        Row -= (StrPos + StartColumn) / LineLength;\r
+        Column        = StartColumn;\r
+        OutputLength  = 0;\r
+\r
+        NeedAdjust = TRUE;\r
+        break;\r
+\r
+      case SCAN_INSERT:\r
+        //\r
+        // Toggle the SEnvInsertMode flag\r
+        //\r
+        InsertMode = (BOOLEAN)!InsertMode;\r
+        break;\r
+\r
+      case SCAN_UP:\r
+      case SCAN_DOWN:\r
+        //\r
+        // show history\r
+        //\r
+        CopyMem (InStr, mInputBufferHistory, StrLength * sizeof(CHAR16));\r
+        StrPos       = StrLen (mInputBufferHistory);\r
+        Update       = 0;\r
+        Delete       = 0;\r
+        OutputLength = 0;\r
+\r
+        TailRow      = Row + (StrPos + StartColumn) / LineLength;\r
+        TailColumn   = (StrPos + StartColumn) % LineLength;\r
+        Row          = TailRow;\r
+        Column       = TailColumn;\r
+        NeedAdjust   = FALSE;\r
+\r
+        ConOut->SetCursorPosition (ConOut, StartColumn, Row);\r
+        for (SubIndex = 0; SubIndex < EFI_DEBUG_INPUS_BUFFER_SIZE - (StartColumn - EFI_DEBUG_PROMPT_COLUMN); SubIndex++) {\r
+          mBackupSpace[SubIndex] = L' ';\r
+        }\r
+        EDBPrint (mBackupSpace);\r
+        SetMem (mBackupSpace, (EFI_DEBUG_INPUS_BUFFER_SIZE - (StartColumn - EFI_DEBUG_PROMPT_COLUMN)) * sizeof(CHAR16), 0);\r
+\r
+        ConOut->SetCursorPosition (ConOut, StartColumn, Row);\r
+        Len = StrPos;\r
+\r
+        break;\r
+\r
+      case SCAN_F1:\r
+      case SCAN_F2:\r
+      case SCAN_F3:\r
+      case SCAN_F4:\r
+      case SCAN_F5:\r
+      case SCAN_F6:\r
+      case SCAN_F7:\r
+      case SCAN_F8:\r
+      case SCAN_F9:\r
+      case SCAN_F10:\r
+      case SCAN_F11:\r
+      case SCAN_F12:\r
+        CommandStr = GetCommandNameByKey (Key);\r
+        if (CommandStr != NULL) {\r
+          StrnCpyS (InStr, StrLength, CommandStr, StrLength - 1);\r
+          return ;\r
+        }\r
+        break;\r
+      }\r
+    }\r
+\r
+    if (Done) {\r
+      break;\r
+    }\r
+    //\r
+    // If we need to update the output do so now\r
+    //\r
+    if (Update != -1) {\r
+      if (NeedAdjust) {\r
+        ConOut->SetCursorPosition (ConOut, Column, Row);\r
+        for (SubIndex = 0; SubIndex < EFI_DEBUG_INPUS_BUFFER_SIZE - (Column - EFI_DEBUG_PROMPT_COLUMN); SubIndex++) {\r
+          mBackupSpace[SubIndex] = L' ';\r
+        }\r
+        EDBPrint (mBackupSpace);\r
+        SetMem (mBackupSpace, (EFI_DEBUG_INPUS_BUFFER_SIZE - (Column - EFI_DEBUG_PROMPT_COLUMN)) * sizeof(CHAR16), 0);\r
+        ConOut->SetCursorPosition (ConOut, Column, Row);\r
+        NeedAdjust = FALSE;\r
+      }\r
+      EDBPrint (InStr + Update);\r
+      Len = StrLen (InStr);\r
+\r
+      if (Delete) {\r
+        SetMem (InStr + Len, Delete * sizeof (CHAR16), 0x00);\r
+      }\r
+\r
+      if (StrPos > Len) {\r
+        StrPos = Len;\r
+      }\r
+\r
+      Update = (UINTN) -1;\r
+\r
+      //\r
+      // After using print to reflect newly updates, if we're not using\r
+      // BACKSPACE and DELETE, we need to move the cursor position forward,\r
+      // so adjust row and column here.\r
+      //\r
+      if (Key.UnicodeChar != CHAR_BACKSPACE && !(Key.UnicodeChar == 0 && Key.ScanCode == SCAN_DELETE)) {\r
+        //\r
+        // Calulate row and column of the tail of current string\r
+        //\r
+        TailRow     = Row + (Len - StrPos + Column + OutputLength) / LineLength;\r
+        TailColumn  = (Len - StrPos + Column + OutputLength) % LineLength;\r
+\r
+        //\r
+        // If the tail of string reaches screen end, screen rolls up, so if\r
+        // Row does not equal TailRow, Row should be decremented\r
+        //\r
+        // (if we are recalling commands using UPPER and DOWN key, and if the\r
+        // old command is too long to fit the screen, TailColumn must be 79.\r
+        //\r
+        if (TailColumn == 0 && TailRow >= TotalRow && (UINTN) Row != TailRow) {\r
+          Row--;\r
+        }\r
+        //\r
+        // Calculate the cursor position after current operation. If cursor\r
+        // reaches line end, update both row and column, otherwise, only\r
+        // column will be changed.\r
+        //\r
+        if (Column + OutputLength >= LineLength) {\r
+          SkipLength = OutputLength - (LineLength - Column);\r
+\r
+          Row += SkipLength / LineLength + 1;\r
+          if ((UINTN) Row > TotalRow - 1) {\r
+            Row = TotalRow - 1;\r
+          }\r
+\r
+          Column = SkipLength % LineLength;\r
+        } else {\r
+          Column += OutputLength;\r
+        }\r
+      }\r
+\r
+      Delete = 0;\r
+    }\r
+    //\r
+    // Set the cursor position for this key\r
+    //\r
+    SetCursorPosition (ConOut, Column, Row, LineLength, TotalRow, InStr, StrPos, Len);\r
+  } while (!Done);\r
+\r
+  CopyMem (mInputBufferHistory, InStr, StrLength * sizeof(CHAR16));\r
+\r
+  //\r
+  // Return the data to the caller\r
+  //\r
+  return ;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+SetCursorPosition (\r
+  IN  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut,\r
+  IN  UINTN                           Column,\r
+  IN  INTN                            Row,\r
+  IN  UINTN                           LineLength,\r
+  IN  UINTN                           TotalRow,\r
+  IN  CHAR16                          *Str,\r
+  IN  UINTN                           StrPos,\r
+  IN  UINTN                           Len\r
+  )\r
+{\r
+  CHAR16  Backup;\r
+\r
+  ASSERT (ConOut != NULL);\r
+  ASSERT (Str != NULL);\r
+\r
+  Backup = 0;\r
+  if (Row >= 0) {\r
+    ConOut->SetCursorPosition (ConOut, Column, Row);\r
+    return ;\r
+  }\r
+\r
+  if (Len - StrPos > Column * Row) {\r
+    Backup                          = *(Str + StrPos + Column * Row);\r
+    *(Str + StrPos + Column * Row)  = 0;\r
+  }\r
+\r
+  EDBPrint (L"%s", Str + StrPos);\r
+  if (Len - StrPos > Column * Row) {\r
+    *(Str + StrPos + Column * Row) = Backup;\r
+  }\r
+\r
+  ConOut->SetCursorPosition (ConOut, 0, 0);\r
+}\r
+\r
+BOOLEAN\r
+EFIAPI\r
+SetPageBreak (\r
+  VOID\r
+  )\r
+{\r
+  EFI_INPUT_KEY Key;\r
+  CHAR16        Str[3];\r
+  BOOLEAN       OmitPrint;\r
+\r
+  //\r
+  // Check\r
+  //\r
+  if (!mDebuggerPrivate.EnablePageBreak) {\r
+    return FALSE;\r
+  }\r
+\r
+  gST->ConOut->OutputString (gST->ConOut, L"Press ENTER to continue, 'q' to exit:");\r
+\r
+  OmitPrint = FALSE;\r
+  //\r
+  // Wait for user input\r
+  //\r
+  Str[0]  = ' ';\r
+  Str[1]  = 0;\r
+  Str[2]  = 0;\r
+  for (;;) {\r
+    WaitForSingleEvent (gST->ConIn->WaitForKey, 0);\r
+    gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
+\r
+    //\r
+    // handle control keys\r
+    //\r
+    if (Key.UnicodeChar == CHAR_NULL) {\r
+      if (Key.ScanCode == SCAN_ESC) {\r
+        gST->ConOut->OutputString (gST->ConOut, L"\r\n");\r
+        OmitPrint = TRUE;\r
+        break;\r
+      }\r
+\r
+      continue;\r
+    }\r
+\r
+    if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
+      gST->ConOut->OutputString (gST->ConOut, L"\r\n");\r
+      break;\r
+    }\r
+    //\r
+    // Echo input\r
+    //\r
+    Str[1] = Key.UnicodeChar;\r
+    if (Str[1] == CHAR_BACKSPACE) {\r
+      continue;\r
+    }\r
+\r
+    gST->ConOut->OutputString (gST->ConOut, Str);\r
+\r
+    if ((Str[1] == L'q') || (Str[1] == L'Q')) {\r
+      OmitPrint = TRUE;\r
+    } else {\r
+      OmitPrint = FALSE;\r
+    }\r
+\r
+    Str[0] = CHAR_BACKSPACE;\r
+  }\r
+\r
+  return OmitPrint;\r
+}\r
+\r
+UINTN\r
+EFIAPI\r
+EDBPrint (\r
+  IN CONST CHAR16  *Format,\r
+  ...\r
+  )\r
+{\r
+  UINTN   Return;\r
+  VA_LIST Marker;\r
+  CHAR16  Buffer[EFI_DEBUG_MAX_PRINT_BUFFER];\r
+\r
+  VA_START (Marker, Format);\r
+  Return = UnicodeVSPrint (Buffer, sizeof (Buffer), Format, Marker);\r
+  VA_END (Marker);\r
+\r
+  if (gST->ConOut != NULL) {\r
+    //\r
+    // To be extra safe make sure ConOut has been initialized\r
+    //\r
+    gST->ConOut->OutputString (gST->ConOut, Buffer);\r
+  }\r
+\r
+  return Return;\r
+}\r
+\r
+UINTN\r
+EFIAPI\r
+EDBSPrint (\r
+  OUT CHAR16        *Buffer,\r
+  IN  INTN          BufferSize,\r
+  IN  CONST CHAR16  *Format,\r
+  ...\r
+  )\r
+{\r
+  UINTN   Return;\r
+  VA_LIST Marker;\r
+\r
+  ASSERT (BufferSize > 0);\r
+\r
+  VA_START (Marker, Format);\r
+  Return = UnicodeVSPrint (Buffer, (UINTN)BufferSize, Format, Marker);\r
+  VA_END (Marker);\r
+\r
+  return Return;\r
+}\r
+\r
+UINTN\r
+EFIAPI\r
+EDBSPrintWithOffset (\r
+  OUT CHAR16        *Buffer,\r
+  IN  INTN          BufferSize,\r
+  IN  UINTN         Offset,\r
+  IN  CONST CHAR16  *Format,\r
+  ...\r
+  )\r
+{\r
+  UINTN   Return;\r
+  VA_LIST Marker;\r
+\r
+  ASSERT (BufferSize - (Offset * sizeof(CHAR16)) > 0);\r
+\r
+  VA_START (Marker, Format);\r
+  Return = UnicodeVSPrint (Buffer + Offset, (UINTN)(BufferSize - (Offset * sizeof(CHAR16))), Format, Marker);\r
+  VA_END (Marker);\r
+\r
+  return Return;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSymbol.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSymbol.c
new file mode 100644 (file)
index 0000000..9573c43
--- /dev/null
@@ -0,0 +1,2669 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbSymbol.c\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#include "Edb.h"\r
+\r
+EFI_STATUS\r
+EdbLoadSymbolSingleEntry (\r
+  IN EFI_DEBUGGER_SYMBOL_OBJECT  *Object,\r
+  IN CHAR8                       *Name,\r
+  IN CHAR8                       *ObjName,\r
+  IN UINTN                       Address,\r
+  IN EFI_DEBUGGER_SYMBOL_TYPE    Type\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Load single symbol entry\r
+\r
+Arguments:\r
+\r
+  Object          - Symbol file object\r
+  Name            - Symbol name\r
+  ObjName         - Object name\r
+  Address         - Symbol address\r
+  Type            - Symbol type\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - add single symbol entry successfully\r
+\r
+--*/\r
+{\r
+  EFI_DEBUGGER_SYMBOL_ENTRY  *Entry;\r
+\r
+  //\r
+  // Check Count VS MaxCount\r
+  //\r
+  if (Object->EntryCount >= Object->MaxEntryCount) {\r
+    //\r
+    // reallocate (for codebuffer too)\r
+    // TBD\r
+    //\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Entry = &Object->Entry[Object->EntryCount];\r
+\r
+  //\r
+  // Print Debug info\r
+  //\r
+  if (sizeof (UINTN) == sizeof(UINT64)) {\r
+    DEBUG ((DEBUG_ERROR, "  Symbol: %a, Address: 0x%016lx (%d)\n", Name, (UINT64)Address, (UINTN)Type));\r
+  } else {\r
+    DEBUG ((DEBUG_ERROR, "  Symbol: %a, Address: 0x%08x (%d)\n", Name, Address, (UINTN)Type));\r
+  }\r
+\r
+  //\r
+  // Fill the entry - name, RVA, type\r
+  //\r
+  AsciiStrnCpyS (Entry->Name, sizeof(Entry->Name), Name, sizeof(Entry->Name) - 1);\r
+  if (ObjName != NULL) {\r
+    AsciiStrnCpyS (Entry->ObjName, sizeof(Entry->ObjName), ObjName, sizeof(Entry->ObjName) - 1);\r
+  }\r
+  Entry->RVA = Address % EFI_DEBUGGER_DEFAULT_LINK_IMAGEBASE;\r
+  Entry->Type = Type;\r
+\r
+  //\r
+  // Increase Count\r
+  //\r
+  Object->EntryCount++;\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+typedef enum {\r
+  EdbEbcMapParseStateUninitialized,\r
+  EdbEbcMapParseStateSymbolStart,\r
+  EdbEbcMapParseStateSeHandlerSymbol,\r
+  EdbEbcMapParseStateFunctionSymbol,\r
+  EdbEbcMapParseStateVarbssInitSymbol,\r
+  EdbEbcMapParseStateCrtSymbol,\r
+  EdbEbcMapParseStateVariableSymbol,\r
+  EdbEbcMapParseStateStaticFunctionSymbol,\r
+  EdbEbcMapParseStateMax,\r
+} EDB_EBC_MAP_PARSE_STATE;\r
+\r
+typedef enum {\r
+  EdbEbcSymbolParseStateUninitialized,\r
+  EdbEbcSymbolParseStateReadyForName,\r
+  EdbEbcSymbolParseStateReadyForRVA,\r
+  EdbEbcSymbolParseStateReadyForType,\r
+  EdbEbcSymbolParseStateReadyForObject,\r
+  EdbEbcSymbolParseStateMax,\r
+} EDB_EBC_SYMBOL_PARSE_STATE;\r
+\r
+/*++\r
+\r
+  The following code depends on the MAP file generated by IEC compiler (actually Microsoft linker).\r
+\r
+  Sample as follows: EbcTest.map\r
+===============================================================================\r
+  EbcTest\r
+\r
+ Timestamp is 45b02718 (Fri Jan 19 10:04:08 2007)\r
+\r
+ Preferred load address is 10000000\r
+\r
+ Start         Length     Name                   Class\r
+ 0001:00000000 00000370H .text                   CODE\r
+ 0002:00000000 00000030H _VARBSS_INIT            CODE\r
+ 0003:00000000 00000004H .CRT$TSA                DATA\r
+ 0003:00000004 00000004H .CRT$TSC                DATA\r
+ 0003:00000008 00000004H .CRT$X                  DATA\r
+ 0003:0000000c 00000008H .CRT$XCU                DATA\r
+ 0003:00000014 00000004H .CRT$Z                  DATA\r
+ 0003:00000020 0000001cH .rdata                  DATA\r
+ 0003:0000003c 00000000H .edata                  DATA\r
+ 0003:0000003c 00000056H .rdata$debug            DATA\r
+ 0004:00000000 00000070H .data                   DATA\r
+ 0004:00000070 00000020H .bss                    DATA\r
+\r
+  Address         Publics by Value              Rva+Base     Lib:Object\r
+\r
+ 0000:00000000       ___safe_se_handler_table   00000000     <absolute>\r
+ 0000:00000000       ___safe_se_handler_count   00000000     <absolute>\r
+ 0001:00000042       TestSubRoutine             10000442 f   EbcTest.obj\r
+ 0001:0000011a       EfiMain                    1000051a f   EbcTest.obj\r
+ 0001:00000200       TestSubRoutineSub          10000600 f   EbcTestSub.obj\r
+ 0001:00000220       EfiStart                   10000620 f   EbcLib:EbcLib.obj\r
+ 0002:00000000       varbss_init_C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest$c45b02717 10000800 f   EbcTest.obj\r
+ 0002:00000020       varbss_init_C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTestSub$c45af77f3 10000820 f   EbcTestSub.obj\r
+ 0003:00000000       CrtThunkBegin              10000a00     EbcLib:EbcLib.obj\r
+ 0003:00000004       CrtThunkEnd                10000a04     EbcLib:EbcLib.obj\r
+ 0003:00000008       CrtBegin                   10000a08     EbcLib:EbcLib.obj\r
+ 0003:00000014       CrtEnd                     10000a14     EbcLib:EbcLib.obj\r
+ 0004:00000070       TestStr                    10000c70     EbcTest.obj\r
+ 0004:00000078       TestVariable1              10000c78     EbcTest.obj\r
+ 0004:00000080       TestSubVariableSub         10000c80     EbcTestSub.obj\r
+\r
+ entry point at        0001:00000220\r
+\r
+ Static symbols\r
+\r
+ 0001:00000000       TestSubRoutine2            10000400 f   EbcTest.obj\r
+===============================================================================\r
+\r
+--*/\r
+EFI_STATUS\r
+EdbLoadSymbolEntryByIec (\r
+  IN EFI_DEBUGGER_SYMBOL_OBJECT  *Object,\r
+  IN UINTN                       BufferSize,\r
+  IN VOID                        *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Load symbol entry by Iec\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  Object          - Symbol file object\r
+  BufferSize      - Symbol file buffer size\r
+  Buffer          - Symbol file buffer\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - add symbol entry successfully\r
+\r
+--*/\r
+{\r
+  CHAR8                      *LineBuffer;\r
+  CHAR8                      *FieldBuffer;\r
+  EFI_DEBUGGER_SYMBOL_ENTRY  *Entry;\r
+  EDB_EBC_MAP_PARSE_STATE    MapParseState;\r
+  EDB_EBC_SYMBOL_PARSE_STATE SymbolParseState;\r
+  CHAR8                      *Name;\r
+  CHAR8                      *ObjName;\r
+  UINTN                      Address;\r
+  EFI_DEBUGGER_SYMBOL_TYPE   Type;\r
+\r
+  Entry = Object->Entry;\r
+\r
+  //\r
+  // Begin to parse the Buffer\r
+  //\r
+  LineBuffer = AsciiStrGetNewTokenLine (Buffer, "\n\r");\r
+  MapParseState = EdbEbcMapParseStateUninitialized;\r
+  //\r
+  // Check each line\r
+  //\r
+  while (LineBuffer != NULL) {\r
+    FieldBuffer = AsciiStrGetNewTokenField (LineBuffer, " ");\r
+    SymbolParseState = EdbEbcSymbolParseStateUninitialized;\r
+    //\r
+    // Init entry value\r
+    //\r
+    Name = NULL;\r
+    ObjName = NULL;\r
+    Address = 0;\r
+    Type = EfiDebuggerSymbolTypeMax;\r
+    //\r
+    // Check each field\r
+    //\r
+    while (FieldBuffer != NULL) {\r
+      if (AsciiStrCmp (FieldBuffer, "") == 0) {\r
+        FieldBuffer = AsciiStrGetNextTokenField (" ");\r
+        continue;\r
+      }\r
+      //\r
+      // check "Address"\r
+      //\r
+      if (AsciiStrCmp (FieldBuffer, "Address") == 0) {\r
+        MapParseState = EdbEbcMapParseStateSymbolStart;\r
+        break;\r
+      }\r
+      //\r
+      // check "Static"\r
+      //\r
+      if (AsciiStrCmp (FieldBuffer, "Static") == 0) {\r
+        MapParseState = EdbEbcMapParseStateStaticFunctionSymbol;\r
+        break;\r
+      }\r
+\r
+      if (MapParseState == EdbEbcMapParseStateUninitialized) {\r
+        //\r
+        // Do not parse anything until get "Address" or "Static"\r
+        //\r
+        break;\r
+      }\r
+      if (AsciiStrCmp (FieldBuffer, "entry") == 0) {\r
+        //\r
+        // Skip entry point\r
+        //\r
+        break;\r
+      }\r
+\r
+      //\r
+      // Now we start to parse this line for Name, Address, and Object\r
+      //\r
+      switch (SymbolParseState) {\r
+      case  EdbEbcSymbolParseStateUninitialized:\r
+        //\r
+        // Get the Address\r
+        //\r
+        SymbolParseState = EdbEbcSymbolParseStateReadyForName;\r
+        break;\r
+      case  EdbEbcSymbolParseStateReadyForName:\r
+        //\r
+        // Get the Name\r
+        //\r
+        if (AsciiStrnCmp (FieldBuffer, "___safe_se_handler", AsciiStrLen ("___safe_se_handler")) == 0) {\r
+          //\r
+          // skip SeHandler\r
+          //\r
+          MapParseState = EdbEbcMapParseStateSeHandlerSymbol;\r
+          goto ExitFieldParse;\r
+        } else if (AsciiStrnCmp (FieldBuffer, "varbss_init", AsciiStrLen ("varbss_init")) == 0) {\r
+          //\r
+          // check VarbssInit\r
+          //\r
+          MapParseState = EdbEbcMapParseStateVarbssInitSymbol;\r
+//          goto ExitFieldParse;\r
+          Name = FieldBuffer;\r
+          SymbolParseState = EdbEbcSymbolParseStateReadyForRVA;\r
+        } else if (AsciiStrnCmp (FieldBuffer, "Crt", AsciiStrLen ("Crt")) == 0) {\r
+          //\r
+          // check Crt\r
+          //\r
+          MapParseState = EdbEbcMapParseStateCrtSymbol;\r
+//          goto ExitFieldParse;\r
+          Name = FieldBuffer;\r
+          SymbolParseState = EdbEbcSymbolParseStateReadyForRVA;\r
+        } else {\r
+          //\r
+          // Now, it is normal function\r
+          //\r
+          switch (MapParseState) {\r
+          case EdbEbcMapParseStateSeHandlerSymbol:\r
+            MapParseState = EdbEbcMapParseStateFunctionSymbol;\r
+            break;\r
+          case EdbEbcMapParseStateCrtSymbol:\r
+            MapParseState = EdbEbcMapParseStateVariableSymbol;\r
+            break;\r
+          case EdbEbcMapParseStateFunctionSymbol:\r
+          case EdbEbcMapParseStateVariableSymbol:\r
+          case EdbEbcMapParseStateStaticFunctionSymbol:\r
+            break;\r
+          default:\r
+            ASSERT (FALSE);\r
+            break;\r
+          }\r
+          Name = FieldBuffer;\r
+          SymbolParseState = EdbEbcSymbolParseStateReadyForRVA;\r
+        }\r
+        break;\r
+      case  EdbEbcSymbolParseStateReadyForRVA:\r
+        //\r
+        // Get the RVA\r
+        //\r
+        Address = AsciiXtoi (FieldBuffer);\r
+        SymbolParseState = EdbEbcSymbolParseStateReadyForType;\r
+        break;\r
+      case  EdbEbcSymbolParseStateReadyForType:\r
+        //\r
+        // Get the Type. This is optional, only for "f".\r
+        //\r
+        if (AsciiStrCmp (FieldBuffer, "f") == 0) {\r
+          SymbolParseState = EdbEbcSymbolParseStateReadyForObject;\r
+          switch (MapParseState) {\r
+          case EdbEbcMapParseStateFunctionSymbol:\r
+          case EdbEbcMapParseStateVarbssInitSymbol:\r
+            Type = EfiDebuggerSymbolFunction;\r
+            break;\r
+          case EdbEbcMapParseStateStaticFunctionSymbol:\r
+            Type = EfiDebuggerSymbolStaticFunction;\r
+            break;\r
+          default:\r
+            ASSERT (FALSE);\r
+            break;\r
+          }\r
+          break;\r
+        }\r
+        //\r
+        // Else it should be Object.\r
+        // let it bypass here\r
+        //\r
+      case  EdbEbcSymbolParseStateReadyForObject:\r
+        switch (Type) {\r
+        case EfiDebuggerSymbolTypeMax:\r
+          switch (MapParseState) {\r
+          case EdbEbcMapParseStateVariableSymbol:\r
+          case EdbEbcMapParseStateCrtSymbol:\r
+            Type = EfiDebuggerSymbolGlobalVariable;\r
+            break;\r
+          case EdbEbcMapParseStateSeHandlerSymbol:\r
+            //\r
+            // do nothing here\r
+            //\r
+            break;\r
+          default:\r
+            ASSERT (FALSE);\r
+            break;\r
+          }\r
+          break;\r
+        case EfiDebuggerSymbolFunction:\r
+        case EfiDebuggerSymbolStaticFunction:\r
+          break;\r
+        default:\r
+          ASSERT (FALSE);\r
+          break;\r
+        }\r
+        //\r
+        // Get the Object\r
+        //\r
+        ObjName = FieldBuffer;\r
+        SymbolParseState = EdbEbcSymbolParseStateUninitialized;\r
+        break;\r
+      default:\r
+        ASSERT (FALSE);\r
+        break;\r
+      }\r
+\r
+      //\r
+      // Get the next field\r
+      //\r
+      FieldBuffer = AsciiStrGetNextTokenField (" ");\r
+    }\r
+\r
+    //\r
+    // Add the entry if we get everything.\r
+    //\r
+    if ((Name != NULL) && (Type != EfiDebuggerSymbolTypeMax)) {\r
+      EdbLoadSymbolSingleEntry (Object, Name, ObjName, Address, Type);\r
+    }\r
+\r
+ExitFieldParse:\r
+    //\r
+    // Get the next line\r
+    //\r
+    LineBuffer = AsciiStrGetNextTokenLine ("\n\r");\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EdbLoadSymbolEntry (\r
+  IN EFI_DEBUGGER_SYMBOL_OBJECT  *Object,\r
+  IN UINTN                       BufferSize,\r
+  IN VOID                        *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Load symbol entry\r
+\r
+Arguments:\r
+\r
+  Object          - Symbol file object\r
+  BufferSize      - Symbol file buffer size\r
+  Buffer          - Symbol file buffer\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - add symbol entry successfully\r
+\r
+--*/\r
+{\r
+  //\r
+  // MAP file format depends on the compiler (actually linker).\r
+  //\r
+  // It is possible to check the different MAP file format in this routine.\r
+  // Now only IEC is supported.\r
+  //\r
+  return EdbLoadSymbolEntryByIec (Object, BufferSize, Buffer);\r
+}\r
+\r
+EFI_DEBUGGER_SYMBOL_OBJECT *\r
+EdbFindSymbolFile (\r
+  IN EFI_DEBUGGER_PRIVATE_DATA   *DebuggerPrivate,\r
+  IN CHAR16                      *FileName,\r
+  IN OUT UINTN                   *Index OPTIONAL\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Find symbol file by name\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  FileName        - Symbol file name\r
+  Index           - Symbol file index\r
+\r
+Returns:\r
+\r
+  Object\r
+\r
+--*/\r
+{\r
+  UINTN ObjectIndex;\r
+\r
+  //\r
+  // Check each Object\r
+  //\r
+  for (ObjectIndex = 0; ObjectIndex < DebuggerPrivate->DebuggerSymbolContext.ObjectCount; ObjectIndex++) {\r
+    if (StrCmp (FileName, DebuggerPrivate->DebuggerSymbolContext.Object[ObjectIndex].Name) == 0) {\r
+      //\r
+      // Name match, found it\r
+      //\r
+      if (Index != NULL) {\r
+        *Index = ObjectIndex;\r
+      }\r
+      return &DebuggerPrivate->DebuggerSymbolContext.Object[ObjectIndex];\r
+    }\r
+  }\r
+\r
+  //\r
+  // Not found\r
+  //\r
+  return NULL;\r
+}\r
+\r
+UINTN\r
+EbdFindSymbolAddress (\r
+  IN UINTN                       Address,\r
+  IN EDB_MATCH_SYMBOL_TYPE       Type,\r
+  OUT EFI_DEBUGGER_SYMBOL_OBJECT **RetObject,\r
+  OUT EFI_DEBUGGER_SYMBOL_ENTRY  **RetEntry\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Find symbol by address\r
+\r
+Arguments:\r
+\r
+  Address         - Symbol address\r
+  Type            - Search type\r
+  RetObject       - Symbol object\r
+  RetEntry        - Symbol entry\r
+\r
+Returns:\r
+\r
+  Nearest symbol address\r
+\r
+--*/\r
+{\r
+  UINTN                      Index;\r
+  UINTN                      SubIndex;\r
+  UINTN                      CandidateLowerAddress;\r
+  UINTN                      CandidateUpperAddress;\r
+  EFI_DEBUGGER_SYMBOL_OBJECT *Object;\r
+  EFI_DEBUGGER_SYMBOL_ENTRY  *Entry;\r
+  EFI_DEBUGGER_SYMBOL_ENTRY  *LowEntry;\r
+  EFI_DEBUGGER_SYMBOL_ENTRY  *UpperEntry;\r
+  EFI_DEBUGGER_SYMBOL_OBJECT *LowObject;\r
+  EFI_DEBUGGER_SYMBOL_OBJECT *UpperObject;\r
+\r
+  if ((Type < 0) || (Type >= EdbMatchSymbolTypeMax)) {\r
+    return 0;\r
+  }\r
+\r
+  //\r
+  // Init\r
+  //\r
+  CandidateLowerAddress = 0;\r
+  CandidateUpperAddress = (UINTN)-1;\r
+  LowEntry = NULL;\r
+  UpperEntry = NULL;\r
+  LowObject = NULL;\r
+  UpperObject = NULL;\r
+\r
+  //\r
+  // Go through each object\r
+  //\r
+  Object = mDebuggerPrivate.DebuggerSymbolContext.Object;\r
+  for (Index = 0; Index < mDebuggerPrivate.DebuggerSymbolContext.ObjectCount; Index++, Object++) {\r
+    if (Object->EntryCount == 0) {\r
+      continue;\r
+    }\r
+    //\r
+    // Go through each entry\r
+    //\r
+    Entry = Object->Entry;\r
+    for (SubIndex = 0; SubIndex < Object->EntryCount; SubIndex++, Entry++) {\r
+      if (Address != Entry->RVA + Object->BaseAddress) {\r
+        //\r
+        // Check for nearest address\r
+        //\r
+        if (Address > Entry->RVA + Object->BaseAddress) {\r
+          //\r
+          // Record it if Current RVA < Address\r
+          //\r
+          if (CandidateLowerAddress < Entry->RVA + Object->BaseAddress) {\r
+            CandidateLowerAddress = Entry->RVA + Object->BaseAddress;\r
+            LowEntry = Entry;\r
+            LowObject = Object;\r
+          }\r
+        } else {\r
+          //\r
+          // Record it if Current RVA > Address\r
+          //\r
+          if (CandidateUpperAddress > Entry->RVA + Object->BaseAddress) {\r
+            CandidateUpperAddress = Entry->RVA + Object->BaseAddress;\r
+            UpperEntry = Entry;\r
+            UpperObject = Object;\r
+          }\r
+        }\r
+        continue;\r
+      }\r
+      //\r
+      // address match, return directly\r
+      //\r
+      *RetEntry = Entry;\r
+      *RetObject = Object;\r
+      return Address;\r
+    }\r
+  }\r
+\r
+  //\r
+  // No Match, provide latest symbol\r
+  //\r
+\r
+  if ((Address - CandidateLowerAddress) < EFI_DEBUGGER_MAX_SYMBOL_ADDRESS_DELTA_VALUE) {\r
+    //\r
+    // Check for lower address\r
+    //\r
+    if (((Type == EdbMatchSymbolTypeNearestAddress) &&\r
+         ((CandidateUpperAddress - Address) > (Address - CandidateLowerAddress))) ||\r
+        (Type == EdbMatchSymbolTypeLowerAddress)) {\r
+      //\r
+      // return nearest lower address\r
+      //\r
+      *RetEntry = LowEntry;\r
+      *RetObject = LowObject;\r
+      return CandidateLowerAddress;\r
+    }\r
+  }\r
+\r
+  if ((CandidateUpperAddress - Address) < EFI_DEBUGGER_MAX_SYMBOL_ADDRESS_DELTA_VALUE) {\r
+    //\r
+    // Check for upper address\r
+    //\r
+    if (((Type == EdbMatchSymbolTypeNearestAddress) &&\r
+         ((CandidateUpperAddress - Address) < (Address - CandidateLowerAddress))) ||\r
+        (Type == EdbMatchSymbolTypeUpperAddress)) {\r
+      //\r
+      // return nearest upper address\r
+      //\r
+      *RetEntry = UpperEntry;\r
+      *RetObject = UpperObject;\r
+      return CandidateUpperAddress;\r
+    }\r
+  }\r
+\r
+  //\r
+  // No match and nearest one, return NULL\r
+  //\r
+  return 0;\r
+}\r
+\r
+EFI_STATUS\r
+EdbUnloadSymbol (\r
+  IN EFI_DEBUGGER_PRIVATE_DATA   *DebuggerPrivate,\r
+  IN CHAR16                      *FileName\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Unload symbol file by name\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  FileName        - Symbol file name\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - unload symbol successfully\r
+\r
+--*/\r
+{\r
+  EFI_DEBUGGER_SYMBOL_OBJECT *Object;\r
+  UINTN                      ObjectIndex;\r
+  UINTN                      Index;\r
+  EFI_DEBUGGER_SYMBOL_ENTRY  *OldEntry;\r
+  UINTN                      OldEntryCount;\r
+  UINTN                      MaxEntryCount;\r
+  VOID                       **OldSourceBuffer;\r
+\r
+  //\r
+  // Find Symbol\r
+  //\r
+  Object = EdbFindSymbolFile (DebuggerPrivate, FileName, &ObjectIndex);\r
+  if (Object == NULL) {\r
+    EDBPrint (L"SymbolFile is not loaded!\n");\r
+    return EFI_DEBUG_CONTINUE;\r
+  }\r
+\r
+  //\r
+  // Record old data\r
+  //\r
+  Object = DebuggerPrivate->DebuggerSymbolContext.Object;\r
+  OldEntry = Object->Entry;\r
+  OldSourceBuffer = Object->SourceBuffer;\r
+  MaxEntryCount = Object->MaxEntryCount;\r
+  OldEntryCount = Object->EntryCount;\r
+\r
+  //\r
+  // Remove the matched Object\r
+  //\r
+  for (Index = ObjectIndex; Index < DebuggerPrivate->DebuggerSymbolContext.ObjectCount - 1; Index++) {\r
+    CopyMem (&Object[Index], &Object[Index + 1], sizeof(EFI_DEBUGGER_SYMBOL_OBJECT));\r
+  }\r
+  ZeroMem (&Object[Index], sizeof(Object[Index]));\r
+\r
+  //\r
+  // Move old data to new place\r
+  //\r
+  Object[Index].Entry = OldEntry;\r
+  Object[Index].SourceBuffer = OldSourceBuffer;\r
+  Object[Index].MaxEntryCount = MaxEntryCount;\r
+  DebuggerPrivate->DebuggerSymbolContext.ObjectCount --;\r
+\r
+  //\r
+  // Clean old entry data\r
+  //\r
+  for (Index = 0; Index < OldEntryCount; Index++) {\r
+    ZeroMem (&OldEntry[Index], sizeof(OldEntry[Index]));\r
+  }\r
+\r
+  //\r
+  // Free OldSourceBuffer\r
+  //\r
+  for (Index = 0; OldSourceBuffer[Index] != NULL; Index++) {\r
+    gBS->FreePool (OldSourceBuffer[Index]);\r
+    OldSourceBuffer[Index] = NULL;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EdbLoadSymbol (\r
+  IN EFI_DEBUGGER_PRIVATE_DATA   *DebuggerPrivate,\r
+  IN CHAR16                      *FileName,\r
+  IN UINTN                       BufferSize,\r
+  IN VOID                        *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Load symbol file by name\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  FileName        - Symbol file name\r
+  BufferSize      - Symbol file buffer size\r
+  Buffer          - Symbol file buffer\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - load symbol successfully\r
+\r
+--*/\r
+{\r
+  EFI_DEBUGGER_SYMBOL_OBJECT *Object;\r
+  EFI_STATUS                 Status;\r
+\r
+  //\r
+  // Check duplicated File\r
+  //\r
+  Object = EdbFindSymbolFile (DebuggerPrivate, FileName, NULL);\r
+  if (Object != NULL) {\r
+    Status = EdbUnloadSymbol (DebuggerPrivate, FileName);\r
+    if (EFI_ERROR(Status)) {\r
+      DEBUG ((DEBUG_ERROR, "Unload Duplicated Symbol File Error!\n"));\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Check Count VS MaxCount\r
+  //\r
+  if (DebuggerPrivate->DebuggerSymbolContext.ObjectCount >= DebuggerPrivate->DebuggerSymbolContext.MaxObjectCount) {\r
+    //\r
+    // reallocate\r
+    // TBD\r
+    //\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Object = &DebuggerPrivate->DebuggerSymbolContext.Object[DebuggerPrivate->DebuggerSymbolContext.ObjectCount];\r
+\r
+  //\r
+  // Init Object\r
+  //\r
+  Object->EntryCount = 0;\r
+  Object->MaxEntryCount = EFI_DEBUGGER_SYMBOL_ENTRY_MAX;\r
+\r
+  //\r
+  // Load SymbolEntry\r
+  //\r
+  DEBUG ((DEBUG_ERROR, "Symbol File: %s\n", FileName));\r
+  Status = EdbLoadSymbolEntry (Object, BufferSize, Buffer);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Fill Object value\r
+  //\r
+  StrnCpyS (Object->Name, sizeof(Object->Name) / sizeof(CHAR16),\r
+            FileName, (sizeof(Object->Name) / sizeof(CHAR16)) - 1);\r
+  Object->BaseAddress = 0;\r
+\r
+  //\r
+  // Increase the object count\r
+  //\r
+  DebuggerPrivate->DebuggerSymbolContext.ObjectCount ++;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+CHAR8 *\r
+GetPdbPath (\r
+  VOID *ImageBase\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Located PDB path name in PE image\r
+\r
+Arguments:\r
+\r
+  ImageBase - base of PE to search\r
+\r
+Returns:\r
+\r
+  Pointer into image at offset of PDB file name if PDB file name is found,\r
+  Otherwise a pointer to an empty string.\r
+\r
+--*/\r
+{\r
+  CHAR8                           *PdbPath;\r
+  UINT32                          DirCount;\r
+  EFI_IMAGE_DOS_HEADER            *DosHdr;\r
+  EFI_IMAGE_OPTIONAL_HEADER_UNION *NtHdr;\r
+  EFI_IMAGE_OPTIONAL_HEADER32     *OptionalHdr32;\r
+  EFI_IMAGE_OPTIONAL_HEADER64     *OptionalHdr64;\r
+  EFI_IMAGE_DATA_DIRECTORY        *DirectoryEntry;\r
+  EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *DebugEntry;\r
+  VOID                            *CodeViewEntryPointer;\r
+\r
+  //\r
+  // Init value\r
+  //\r
+  CodeViewEntryPointer  = NULL;\r
+  PdbPath               = NULL;\r
+  DosHdr                = ImageBase;\r
+\r
+  //\r
+  // Check magic\r
+  //\r
+  if (DosHdr->e_magic != EFI_IMAGE_DOS_SIGNATURE) {\r
+    return NULL;\r
+  }\r
+  NtHdr           = (EFI_IMAGE_OPTIONAL_HEADER_UNION *) ((UINT8 *) DosHdr + DosHdr->e_lfanew);\r
+  //\r
+  // Check Machine, filter for EBC\r
+  //\r
+  if (NtHdr->Pe32.FileHeader.Machine != EFI_IMAGE_MACHINE_EBC) {\r
+    //\r
+    // If not EBC, return NULL\r
+    //\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Get DirectoryEntry\r
+  // EBC spec says PE32+, but implementation uses PE32. So check dynamically here.\r
+  //\r
+  if (NtHdr->Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
+    OptionalHdr32   = (VOID *) &NtHdr->Pe32.OptionalHeader;\r
+    DirectoryEntry  = (EFI_IMAGE_DATA_DIRECTORY *) &(OptionalHdr32->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
+  } else if (NtHdr->Pe32Plus.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {\r
+    OptionalHdr64   = (VOID *) &NtHdr->Pe32Plus.OptionalHeader;\r
+    DirectoryEntry  = (EFI_IMAGE_DATA_DIRECTORY *) &(OptionalHdr64->DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
+  } else {\r
+    return NULL;\r
+  }\r
+  if (DirectoryEntry->VirtualAddress == 0) {\r
+    return NULL;\r
+  }\r
+  //\r
+  // Go through DirectoryEntry\r
+  //\r
+  for (DirCount = 0;\r
+       (DirCount < DirectoryEntry->Size / sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY)) && CodeViewEntryPointer == NULL;\r
+       DirCount++\r
+      ) {\r
+    DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) (DirectoryEntry->VirtualAddress + (UINTN) ImageBase + DirCount * sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY));\r
+    if (DebugEntry->Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {\r
+      //\r
+      // Match DebugEntry, only CODEVIEW_SIGNATURE_NB10 and CODEVIEW_SIGNATURE_RSDS are supported.\r
+      //\r
+      CodeViewEntryPointer = (VOID *) ((UINTN) DebugEntry->RVA + (UINTN) ImageBase);\r
+      switch (*(UINT32 *) CodeViewEntryPointer) {\r
+      case CODEVIEW_SIGNATURE_NB10:\r
+        PdbPath = (CHAR8 *) CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY);\r
+        break;\r
+      case CODEVIEW_SIGNATURE_RSDS:\r
+        PdbPath = (CHAR8 *) CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY);\r
+        break;\r
+      default:\r
+        break;\r
+      }\r
+    }\r
+  }\r
+\r
+  //\r
+  // Done successfully\r
+  //\r
+  return PdbPath;\r
+}\r
+\r
+BOOLEAN\r
+MatchPdbAndMap (\r
+  IN CHAR8   *PdbFileName,\r
+  IN CHAR16  *MapFileName\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Check whether PDB file and MAP file have same name\r
+\r
+Arguments:\r
+\r
+  PdbFileName - PDB file name\r
+  MapFileName - MAP file name\r
+\r
+Returns:\r
+\r
+  TRUE  - PDB and MAP file name match\r
+  FALSE - PDB and MAP file name not match\r
+\r
+--*/\r
+{\r
+  UINTN   PdbNameSize;\r
+  UINTN   MapNameSize;\r
+  CHAR8   *PurePdbFileName;\r
+  UINTN   Index;\r
+\r
+  //\r
+  // remove dir name\r
+  //\r
+  PurePdbFileName = PdbFileName;\r
+  for (Index = 0; PdbFileName[Index] != 0; Index++) {\r
+    if (PdbFileName[Index] == '\\') {\r
+      PurePdbFileName = &PdbFileName[Index + 1];\r
+    }\r
+  }\r
+  PdbFileName = PurePdbFileName;\r
+\r
+  //\r
+  // get size\r
+  //\r
+  PdbNameSize = AsciiStrLen (PdbFileName);\r
+  MapNameSize = StrLen (MapFileName);\r
+\r
+  if (PdbNameSize != MapNameSize) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // check the name\r
+  //\r
+  for (Index = 0; Index < MapNameSize - 4; Index++) {\r
+    if ((PdbFileName[Index] | 0x20) != (MapFileName[Index] | 0x20)) {\r
+      return FALSE;\r
+    }\r
+  }\r
+\r
+  return TRUE;\r
+}\r
+\r
+//\r
+// BUGBUG: work-around start\r
+//\r
+typedef struct {\r
+  EFI_DEBUG_IMAGE_INFO  *EfiDebugImageInfoTable;\r
+  volatile UINT32       UpdateStatus;\r
+  UINT32                TableSize;\r
+} EFI_DEBUG_IMAGE_INFO_TABLE_HEADER_OLD;\r
+\r
+EFI_DEBUG_IMAGE_INFO_TABLE_HEADER  mDebugImageInfoTableHeader;\r
+\r
+VOID\r
+EdbFixDebugImageInfoTable (\r
+  IN OUT EFI_DEBUG_IMAGE_INFO_TABLE_HEADER **DebugImageInfoTableHeader\r
+  )\r
+/*\r
+For compatibility consideration, we handle 2 cases:\r
+\r
+1) IA32:\r
+  Old:                          New:\r
+  +------------------------+    +------------------------+\r
+  | EfiDebugImageInfoTable |    | UpdateStatus           |\r
+  +------------------------+    +------------------------+\r
+  | UpdateStatus           |    | TableSize              |\r
+  +------------------------+    +------------------------+\r
+  | TableSize              |    | EfiDebugImageInfoTable |\r
+  +------------------------+    +------------------------+\r
+\r
+2) X64 and IPF:\r
+  Old:                          New:\r
+  +------------------------+    +------------------------+\r
+  | EfiDebugImageInfoTable |    | UpdateStatus           |\r
+  |                        |    +------------------------+\r
+  |                        |    | TableSize              |\r
+  +------------------------+    +------------------------+\r
+  | UpdateStatus           |    | EfiDebugImageInfoTable |\r
+  +------------------------+    |                        |\r
+  | TableSize              |    |                        |\r
+  +------------------------+    +------------------------+\r
+\r
+*/\r
+{\r
+  mDebugImageInfoTableHeader.EfiDebugImageInfoTable = ((EFI_DEBUG_IMAGE_INFO_TABLE_HEADER_OLD *)(*DebugImageInfoTableHeader))->EfiDebugImageInfoTable;\r
+  mDebugImageInfoTableHeader.UpdateStatus           = ((EFI_DEBUG_IMAGE_INFO_TABLE_HEADER_OLD *)(*DebugImageInfoTableHeader))->UpdateStatus;\r
+  mDebugImageInfoTableHeader.TableSize              = ((EFI_DEBUG_IMAGE_INFO_TABLE_HEADER_OLD *)(*DebugImageInfoTableHeader))->TableSize;\r
+\r
+  if ((*DebugImageInfoTableHeader)->UpdateStatus > 3) {\r
+    *DebugImageInfoTableHeader = &mDebugImageInfoTableHeader;\r
+    return ;\r
+  }\r
+\r
+  if ((*DebugImageInfoTableHeader)->TableSize % (EFI_PAGE_SIZE / (sizeof (VOID *))) != 0) {\r
+    *DebugImageInfoTableHeader = &mDebugImageInfoTableHeader;\r
+    return ;\r
+  }\r
+\r
+  return ;\r
+}\r
+//\r
+// BUGBUG: work-around end\r
+//\r
+\r
+EFI_STATUS\r
+EdbPatchSymbolRVA (\r
+  IN EFI_DEBUGGER_PRIVATE_DATA     *DebuggerPrivate,\r
+  IN CHAR16                        *FileName,\r
+  IN EDB_EBC_IMAGE_RVA_SEARCH_TYPE SearchType\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Patch symbol RVA\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  FileName        - Symbol file name\r
+  SearchType      - Search type for Object\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS   - Patch symbol RVA successfully\r
+  EFI_NOT_FOUND - Symbol RVA base not found\r
+\r
+--*/\r
+{\r
+  EFI_STATUS            Status;\r
+  UINTN                 ImageNumber;\r
+  EFI_DEBUG_IMAGE_INFO  *ImageTable;\r
+  CHAR8                 *PdbPath;\r
+  VOID                  *ImageBase;\r
+  VOID                  *CandidateImageBase;\r
+  EFI_DEBUGGER_SYMBOL_OBJECT *Object;\r
+\r
+  if (SearchType < 0 || SearchType >= EdbEbcImageRvaSearchTypeMax) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Get the related object\r
+  //\r
+  Object = EdbFindSymbolFile (DebuggerPrivate, FileName, NULL);\r
+  if (Object == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  //\r
+  // Try again to get DebugImageInfoTable\r
+  //\r
+  if (mDebuggerPrivate.DebugImageInfoTableHeader == NULL) {\r
+    Status = EfiGetSystemConfigurationTable (\r
+               &gEfiDebugImageInfoTableGuid,\r
+               (VOID **) &mDebuggerPrivate.DebugImageInfoTableHeader\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+      EDBPrint (L"DebugImageInfoTable not found!\n");\r
+      return Status;\r
+    }\r
+  }\r
+  DEBUG ((DEBUG_ERROR, "DebugImageInfoTableHeader: %x\n", mDebuggerPrivate.DebugImageInfoTableHeader));\r
+\r
+  //\r
+  // BUGBUG: work-around start\r
+  //\r
+  EdbFixDebugImageInfoTable (&mDebuggerPrivate.DebugImageInfoTableHeader);\r
+  //\r
+  // BUGBUG: work-around end\r
+  //\r
+\r
+  //\r
+  // Go through DebugImageInfoTable for each Image\r
+  //\r
+  CandidateImageBase = NULL;\r
+  ImageTable  = mDebuggerPrivate.DebugImageInfoTableHeader->EfiDebugImageInfoTable;\r
+  for (ImageNumber = 0; ImageNumber < mDebuggerPrivate.DebugImageInfoTableHeader->TableSize; ImageNumber++) {\r
+    if (ImageTable[ImageNumber].NormalImage == NULL) {\r
+      continue;\r
+    }\r
+    ImageBase = ImageTable[ImageNumber].NormalImage->LoadedImageProtocolInstance->ImageBase;\r
+    //\r
+    // Get PDB path\r
+    //\r
+    PdbPath   = GetPdbPath (ImageBase);\r
+    if (PdbPath == NULL) {\r
+      continue;\r
+    }\r
+    //\r
+    // Check PDB name\r
+    //\r
+    if (!MatchPdbAndMap (PdbPath, FileName)) {\r
+      continue;\r
+    }\r
+    DEBUG ((DEBUG_ERROR, "ImageBase: %x\n", ImageBase));\r
+\r
+    //\r
+    // Check SearchType\r
+    //\r
+    if (SearchType == EdbEbcImageRvaSearchTypeAny || SearchType == EdbEbcImageRvaSearchTypeFirst) {\r
+      //\r
+      // Assign base address and return\r
+      //\r
+      Object->BaseAddress = (UINTN)ImageBase;\r
+      return EFI_SUCCESS;\r
+    }\r
+\r
+    //\r
+    // Get CandidateImageBase for EdbEbcImageRvaSearchTypeLast\r
+    //\r
+    CandidateImageBase = ImageBase;\r
+  }\r
+\r
+  //\r
+  // Check EdbEbcImageRvaSearchTypeLast\r
+  //\r
+  if (SearchType == EdbEbcImageRvaSearchTypeLast) {\r
+    if (CandidateImageBase == NULL) {\r
+      return EFI_NOT_FOUND;\r
+    }\r
+    //\r
+    // Assign base address and return\r
+    //\r
+    Object->BaseAddress = (UINTN)CandidateImageBase;\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // No match\r
+  //\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+BOOLEAN\r
+MatchObjAndCod (\r
+  IN CHAR8   *ObjFileName,\r
+  IN CHAR16  *CodFileName\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Check whether OBJ file and COD file have same name\r
+\r
+Arguments:\r
+\r
+  ObjFileName - OBJ file name\r
+  CodFileName - COD file name\r
+\r
+Returns:\r
+\r
+  TRUE  - OBJ and COD file name match\r
+  FALSE - OBJ and COD file name not match\r
+\r
+--*/\r
+{\r
+  UINTN   ObjNameSize;\r
+  UINTN   CodNameSize;\r
+  CHAR8   *PureObjFileName;\r
+  UINTN   Index;\r
+\r
+  //\r
+  // remove library name\r
+  //\r
+  PureObjFileName = ObjFileName;\r
+  for (Index = 0; ObjFileName[Index] != 0; Index++) {\r
+    if (ObjFileName[Index] == ':') {\r
+      PureObjFileName = &ObjFileName[Index + 1];\r
+      break;\r
+    }\r
+  }\r
+  ObjFileName = PureObjFileName;\r
+\r
+  //\r
+  // get size\r
+  //\r
+  ObjNameSize = AsciiStrLen (ObjFileName);\r
+  CodNameSize = StrLen (CodFileName);\r
+\r
+  if (ObjNameSize != CodNameSize) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // check the name\r
+  //\r
+  for (Index = 0; Index < CodNameSize - 4; Index++) {\r
+    if ((ObjFileName[Index] | 0x20) != (CodFileName[Index] | 0x20)) {\r
+      return FALSE;\r
+    }\r
+  }\r
+\r
+  return TRUE;\r
+}\r
+\r
+typedef enum {\r
+  EdbEbcCodParseStateUninitialized,\r
+  EdbEbcCodParseStateSymbolInitialized,\r
+  EdbEbcCodParseStateSymbolStart,\r
+  EdbEbcCodParseStateSymbolEnd,\r
+  EdbEbcCodParseStateMax,\r
+} EDB_EBC_COD_PARSE_STATE;\r
+\r
+/*++\r
+\r
+  The following code depends on the COD file generated by IEC compiler.\r
+\r
+  Sample as follows: EbcTest.cod\r
+===============================================================================\r
+; -- Machine type EFI\r
+; mark_description "Intel(R) C Compiler for EFI Byte Code, Version 1.2 Build 20040123";\r
+; mark_description "XXX";\r
+;ident "Intel(R) C Compiler for EFI Byte Code, Version 1.2 Build 20040123"\r
+;ident "XXX"\r
+    .686P\r
+    .387\r
+_TEXT   SEGMENT PARA PUBLIC USE32 'CODE'\r
+_TEXT   ENDS\r
+_DATA   SEGMENT PARA PUBLIC USE32 'DATA'\r
+    ALIGN 010H\r
+_DATA   ENDS\r
+_BSS    SEGMENT PARA PUBLIC USE32 'BSS'\r
+    ALIGN 010H\r
+_BSS    ENDS\r
+_VARBSS SEGMENT PARA PUBLIC USE32 'BSS'\r
+    ALIGN 010H\r
+_VARBSS ENDS\r
+    ASSUME  CS:FLAT,DS:FLAT,SS:FLAT\r
+_DATA   SEGMENT PARA PUBLIC USE32 'DATA'\r
+TestVariable2   DD 000000003H,000000000H    ; u64\r
+_DATA   ENDS\r
+_DATA   SEGMENT PARA PUBLIC USE32 'DATA'\r
+_DATA   ENDS\r
+_TEXT   SEGMENT PARA PUBLIC USE32 'CODE'\r
+; -- Begin  EfiMain\r
+; mark_begin;\r
+    PUBLIC   EfiMain\r
+EfiMain  PROC NEAR\r
+$B3$1:; 11a\r
+$LN45:\r
+\r
+;117 ; {\r
+\r
+  0011a 60 00 70 80         MOVqw     R0, R0(+0,-112)         ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:117\r
+$LN46:\r
+\r
+;118 ;   UINT16 test = 0x1234;\r
+\r
+  0011e 77 58 58 00 34\r
+        12                  MOVIww    @R0(+0,+88), +4660      ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:118\r
+$LN47:\r
+\r
+;121 ;   EFI_STATUS  Status;\r
+;121 ;\r
+;121 ;   SystemTable->ConOut->OutputString (\r
+\r
+  00124 72 87 01 12         MOVnw     R7, @R0(+1,+128)        ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:121\r
+  00128 72 f7 85 21         MOVnw     R7, @R7(+5,+24)         ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:121\r
+$LN48:\r
+\r
+;122 ;                          SystemTable->ConOut,\r
+\r
+  0012c 72 84 01 12         MOVnw     R4, @R0(+1,+128)        ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:122\r
+  00130 72 c8 85 21         MOVnw     @R0, @R4(+5,+24)        ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:122\r
+  00134 b9 34 00 00 00\r
+        00                  MOVreld   R4, __STRING$1          ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:122\r
+  0013a b2 48 01 10         MOVnw     @R0(+1,+0), R4          ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:122\r
+  0013e 83 2f 01 00 00\r
+        10                  CALLEX    @R7(+1,+0)              ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:122\r
+$B3$2:; 144\r
+$LN49:\r
+\r
+;125 ;                          L"Hello EBC Test!\n\r"\r
+;125 ;                          );\r
+;125 ;   EFI_BREAKPOINT ();\r
+\r
+  00144 00 03               BREAK     3                       ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:125\r
+$B3$3:; 146\r
+$LN50:\r
+\r
+;126 ;   TestVariable1 = 6;\r
+\r
+  00146 b9 37 00 00 00\r
+        00                  MOVreld   R7, TestVariable1       ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:126\r
+  0014c 78 0f 06 00         MOVInw    @R7, (0,6)              ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:126\r
+$LN51:\r
+\r
+;127 ;   TestSubRoutineSub (1, 5);\r
+\r
+  00150 78 08 01 00         MOVInw    @R0, (0,1)              ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:127\r
+  00154 78 48 01 10 05\r
+        00                  MOVInw    @R0(1,0), (0,5)         ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:127\r
+  0015a 83 10 00 00 00\r
+        00                  CALL      TestSubRoutineSub       ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:127\r
+$B3$4:; 160\r
+$LN52:\r
+\r
+;129 ;\r
+;129 ;   SystemTable->ConOut->OutputString (\r
+\r
+  00160 72 87 01 12         MOVnw     R7, @R0(+1,+128)        ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:129\r
+  00164 72 f7 85 21         MOVnw     R7, @R7(+5,+24)         ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:129\r
+$LN53:\r
+\r
+;130 ;                          SystemTable->ConOut,\r
+\r
+  00168 72 84 01 12         MOVnw     R4, @R0(+1,+128)        ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:130\r
+  0016c 72 c8 85 21         MOVnw     @R0, @R4(+5,+24)        ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:130\r
+$LN54:\r
+\r
+;131 ;                          TestStr\r
+\r
+  00170 b9 34 00 00 00\r
+        00                  MOVreld   R4, TestStr             ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:131\r
+  00176 b2 c8 01 10         MOVnw     @R0(+1, +0), @R4        ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:131\r
+  0017a 83 2f 01 00 00\r
+        10                  CALLEX    @R7(+1,+0)              ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:131\r
+$B3$5:; 180\r
+$LN55:\r
+\r
+;134 ;                          );\r
+;134 ;\r
+;134 ;   test = test & 0xFF;\r
+\r
+  00180 de 88 58 00 58\r
+        00                  MOVww     @R0(+0,+88), @R0(+0,+88) ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:134\r
+$LN56:\r
+\r
+;139 ;   if (test != 0x34) {\r
+;139 ; //    EFI_BREAKPOINT ();\r
+;139 ;   }\r
+;139 ;\r
+;139 ;   Status = TestSubRoutine (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);\r
+\r
+  00186 78 08 01 00         MOVInw    @R0, (0,1)              ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:139\r
+  0018a 78 48 01 10 02\r
+        00                  MOVInw    @R0(1,0), (0,2)         ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:139\r
+  00190 78 48 02 10 03\r
+        00                  MOVInw    @R0(2,0), (0,3)         ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:139\r
+  00196 78 48 03 10 04\r
+        00                  MOVInw    @R0(3,0), (0,4)         ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:139\r
+  0019c 78 48 04 20 05\r
+        00                  MOVInw    @R0(4,0), (0,5)         ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:139\r
+  001a2 78 48 05 20 06\r
+        00                  MOVInw    @R0(5,0), (0,6)         ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:139\r
+  001a8 78 48 06 20 07\r
+        00                  MOVInw    @R0(6,0), (0,7)         ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:139\r
+  001ae 78 48 07 20 08\r
+        00                  MOVInw    @R0(7,0), (0,8)         ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:139\r
+  001b4 78 48 08 20 09\r
+        00                  MOVInw    @R0(8,0), (0,9)         ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:139\r
+  001ba 78 48 09 20 0a\r
+        00                  MOVInw    @R0(9,0), (0,10)        ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:139\r
+  001c0 83 10 00 00 00\r
+        00                  CALL      TestSubRoutine          ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:139\r
+$B3$10:; 1c6\r
+  001c6 b2 78 60 00         MOVnw     @R0(+0,+96), R7         ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:139\r
+$B3$6:; 1ca\r
+$LN57:\r
+  001ca f2 88 50 00 60\r
+        00                  MOVnw     @R0(+0,+80), @R0(+0,+96) ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:139\r
+$LN58:\r
+\r
+;141 ;\r
+;141 ;   SystemTable->ConOut->OutputString (\r
+\r
+  001d0 72 87 01 12         MOVnw     R7, @R0(+1,+128)        ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:141\r
+  001d4 72 f7 85 21         MOVnw     R7, @R7(+5,+24)         ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:141\r
+$LN59:\r
+\r
+;142 ;                          SystemTable->ConOut,\r
+\r
+  001d8 72 84 01 12         MOVnw     R4, @R0(+1,+128)        ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:142\r
+  001dc 72 c8 85 21         MOVnw     @R0, @R4(+5,+24)        ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:142\r
+  001e0 b9 34 00 00 00\r
+        00                  MOVreld   R4, __STRING$2          ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:142\r
+  001e6 b2 48 01 10         MOVnw     @R0(+1,+0), R4          ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:142\r
+  001ea 83 2f 01 00 00\r
+        10                  CALLEX    @R7(+1,+0)              ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:142\r
+$B3$7:; 1f0\r
+$LN60:\r
+\r
+;146 ;                          L"Goodbye EBC Test!\n\r"\r
+;146 ;                          );\r
+;146 ;\r
+;146 ;   return Status;\r
+\r
+  001f0 72 87 50 00         MOVnw     R7, @R0(+0,+80)         ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:146\r
+  001f4 60 00 70 00         MOVqw     R0, R0(+0,+112)         ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:146\r
+  001f8 04 00               RET                               ;C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest.c:146\r
+; mark_end;\r
+EfiMain ENDP\r
+_TEXT   ENDS\r
+_DATA   SEGMENT PARA PUBLIC USE32 'DATA'\r
+    DB 3 DUP (0)    ; pad\r
+__STRING$2  DW 71   ; u16\r
+    DW 111  ; u16\r
+    DW 111  ; u16\r
+    DW 100  ; u16\r
+    DW 98   ; u16\r
+    DW 121  ; u16\r
+    DW 101  ; u16\r
+    DW 32   ; u16\r
+    DW 69   ; u16\r
+    DW 66   ; u16\r
+    DW 67   ; u16\r
+    DW 32   ; u16\r
+    DW 84   ; u16\r
+    DW 101  ; u16\r
+    DW 115  ; u16\r
+    DW 116  ; u16\r
+    DW 33   ; u16\r
+    DW 10   ; u16\r
+    DW 13   ; u16\r
+    DW 0    ; u16\r
+__STRING$1  DW 72   ; u16\r
+    DW 101  ; u16\r
+    DW 108  ; u16\r
+    DW 108  ; u16\r
+    DW 111  ; u16\r
+    DW 32   ; u16\r
+    DW 69   ; u16\r
+    DW 66   ; u16\r
+    DW 67   ; u16\r
+    DW 32   ; u16\r
+    DW 84   ; u16\r
+    DW 101  ; u16\r
+    DW 115  ; u16\r
+    DW 116  ; u16\r
+    DW 33   ; u16\r
+    DW 10   ; u16\r
+    DW 13   ; u16\r
+    DW 0    ; u16\r
+_DATA   ENDS\r
+_DATA   SEGMENT PARA PUBLIC USE32 'DATA'\r
+_DATA   ENDS\r
+; -- End  EfiMain\r
+_DATA   SEGMENT PARA PUBLIC USE32 'DATA'\r
+__STRING$0  DW 55   ; u16\r
+    DW 56   ; u16\r
+    DW 57   ; u16\r
+    DW 52   ; u16\r
+    DW 53   ; u16\r
+    DW 54   ; u16\r
+    DW 49   ; u16\r
+    DW 50   ; u16\r
+    DW 51   ; u16\r
+    DW 13   ; u16\r
+    DW 10   ; u16\r
+    DW 0    ; u16\r
+_DATA   ENDS\r
+_VARBSS SEGMENT PARA PUBLIC USE32 'BSS'\r
+    PUBLIC TestStr\r
+TestStr DD 2 DUP (?)    ; pad\r
+    PUBLIC TestVariable1\r
+TestVariable1   DD 2 DUP (?)    ; pad\r
+_VARBSS ENDS\r
+_VARBSS_INIT    SEGMENT DWORD PUBLIC USE32 'CODE'\r
+; -- Begin varbss_init_C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest$c45b815d2\r
+    PUBLIC    varbss_init_C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest$c45b815d2\r
+varbss_init_C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest$c45b815d2 PROC NEAR\r
+  00000 b9 34 00 00 00\r
+        00                  MOVreld   R4, TestStr\r
+  00006 b9 35 00 00 00\r
+        00                  MOVreld   R5, __STRING$0\r
+  0000c 33 5c               MOVnd     @R4, R5\r
+  0000e b9 34 00 00 00\r
+        00                  MOVreld   R4, TestVariable1\r
+  00014 78 0c 04 00         MOVInw    @R4, (0,4)\r
+  00018 04 00               RET\r
+; -- End varbss_init_C:\efi_src\TIANO\Edk\Sample\Universal\Ebc\Dxe\EbcTest\EbcTest$c45b815d2\r
+_VARBSS_INIT    ENDS\r
+_DATA   SEGMENT PARA PUBLIC USE32 'DATA'\r
+_DATA   ENDS\r
+EXTRN   TestSubRoutineSub:PROC\r
+    END\r
+\r
+===============================================================================\r
+\r
+--*/\r
+CHAR8 *\r
+EdbLoadCodBySymbolByIec (\r
+  IN CHAR8                       *Name,\r
+  IN VOID                        *Buffer,\r
+  IN UINTN                       BufferSize,\r
+  OUT UINTN                      *CodeBufferSize,\r
+  OUT UINTN                      *FuncOffset\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Load code by symbol by Iec\r
+\r
+Arguments:\r
+\r
+  Name            - Symbol file name\r
+  BufferSize      - Symbol file buffer size\r
+  Buffer          - Symbol file buffer\r
+  CodeBufferSize  - Code buffer size\r
+  FuncOffset      - Code funcion offset\r
+\r
+Returns:\r
+\r
+  CodeBuffer\r
+\r
+--*/\r
+{\r
+  CHAR8                      *LineBuffer;\r
+  CHAR8                      *FieldBuffer;\r
+  VOID                       *BufferStart;\r
+  VOID                       *BufferEnd;\r
+  UINTN                      Offset;\r
+  EDB_EBC_COD_PARSE_STATE    CodParseState;\r
+  CHAR8                      Char[2] = {9, 0};\r
+\r
+  //\r
+  // Init\r
+  //\r
+  LineBuffer = AsciiStrGetNewTokenLine (Buffer, "\n\r");\r
+  Offset = (UINTN)-1;\r
+  BufferStart = NULL;\r
+  BufferEnd = NULL;\r
+  CodParseState = EdbEbcCodParseStateUninitialized;\r
+\r
+  //\r
+  // Check each line\r
+  //\r
+  while (LineBuffer != NULL) {\r
+    switch (CodParseState) {\r
+    case EdbEbcCodParseStateUninitialized:\r
+      //\r
+      // check mark_begin, begin to check line after this match\r
+      //\r
+      if (AsciiStrCmp (LineBuffer, "; mark_begin;") == 0) {\r
+        CodParseState = EdbEbcCodParseStateSymbolInitialized;\r
+      }\r
+      LineBuffer = AsciiStrGetNextTokenLine ("\n\r");\r
+      PatchForAsciiStrTokenBefore (LineBuffer, '\n');\r
+      break;\r
+\r
+    case EdbEbcCodParseStateSymbolInitialized:\r
+      //\r
+      // check mark_end, not check line after this match\r
+      //\r
+      if (AsciiStrCmp (LineBuffer, "; mark_end;") == 0) {\r
+        CodParseState = EdbEbcCodParseStateUninitialized;\r
+        LineBuffer = AsciiStrGetNextTokenLine ("\n\r");\r
+        PatchForAsciiStrTokenBefore (LineBuffer, '\n');\r
+        break;\r
+      }\r
+\r
+      //\r
+      // not check this line if the first char is as follows\r
+      //\r
+      if ((*LineBuffer == 0)   ||\r
+          (*LineBuffer == '$') ||\r
+          (*LineBuffer == ';') ||\r
+          (*LineBuffer == '_') ||\r
+          (*LineBuffer == ' ')) {\r
+        LineBuffer = AsciiStrGetNextTokenLine ("\n\r");\r
+        PatchForAsciiStrTokenBefore (LineBuffer, '\n');\r
+        break;\r
+      }\r
+\r
+      //\r
+      // get function name, function name is followed by char 0x09.\r
+      //\r
+      FieldBuffer = AsciiStrGetNewTokenField (LineBuffer, Char);\r
+      if (AsciiStriCmp (FieldBuffer, Name) == 0) {\r
+        BufferStart = FieldBuffer;\r
+        CodParseState = EdbEbcCodParseStateSymbolStart;\r
+      }\r
+      PatchForAsciiStrTokenAfter (FieldBuffer, 0x9);\r
+\r
+      //\r
+      // Get next line\r
+      //\r
+      LineBuffer = AsciiStrGetNextTokenLine ("\n\r");\r
+      PatchForAsciiStrTokenBefore (LineBuffer, '\n');\r
+      break;\r
+\r
+    case EdbEbcCodParseStateSymbolStart:\r
+      //\r
+      // check mark_end, if this match, means the function is found successfully.\r
+      //\r
+      if (AsciiStrCmp (LineBuffer, "; mark_end;") == 0) {\r
+        CodParseState = EdbEbcCodParseStateSymbolEnd;\r
+        //\r
+        // prepare CodeBufferSize, FuncOffset, and FuncStart to return\r
+        //\r
+        BufferEnd = LineBuffer + sizeof("; mark_end;") - 1;\r
+        *CodeBufferSize = (UINTN)BufferEnd - (UINTN)BufferStart;\r
+        *FuncOffset = Offset;\r
+        PatchForAsciiStrTokenAfter (LineBuffer, '\n');\r
+        return BufferStart;\r
+      }\r
+\r
+      //\r
+      // Get function offset\r
+      //\r
+      if ((Offset == (UINTN)-1) &&\r
+          (*LineBuffer == ' ')) {\r
+        FieldBuffer = AsciiStrGetNewTokenField (LineBuffer + 2, " ");\r
+        Offset = AsciiXtoi (FieldBuffer);\r
+        PatchForAsciiStrTokenAfter (FieldBuffer, ' ');\r
+      }\r
+\r
+      //\r
+      // Get next line\r
+      //\r
+      LineBuffer = AsciiStrGetNextTokenLine ("\n\r");\r
+      PatchForAsciiStrTokenBefore (LineBuffer, '\n');\r
+      break;\r
+\r
+    case EdbEbcCodParseStateSymbolEnd:\r
+      break;\r
+\r
+    default:\r
+      break;\r
+    }\r
+  }\r
+\r
+  //\r
+  // no function found\r
+  //\r
+  return NULL;\r
+}\r
+\r
+CHAR8 *\r
+EdbLoadCodBySymbol (\r
+  IN CHAR8                       *Name,\r
+  IN VOID                        *Buffer,\r
+  IN UINTN                       BufferSize,\r
+  OUT UINTN                      *CodeBufferSize,\r
+  OUT UINTN                      *FuncOffset\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Load code by symbol\r
+\r
+Arguments:\r
+\r
+  Name            - Symbol file name\r
+  BufferSize      - Symbol file buffer size\r
+  Buffer          - Symbol file buffer\r
+  CodeBufferSize  - Code buffer size\r
+  FuncOffset      - Code funcion offset\r
+\r
+Returns:\r
+\r
+  CodeBuffer\r
+\r
+--*/\r
+{\r
+  //\r
+  // COD file format depends on the compiler.\r
+  //\r
+  // It is possible to check the different COD file format in this routine.\r
+  // Now only IEC is supported.\r
+  //\r
+  return EdbLoadCodBySymbolByIec (Name, Buffer, BufferSize, CodeBufferSize, FuncOffset);\r
+}\r
+\r
+VOID *\r
+EdbFindCodeFromObject (\r
+  IN EFI_DEBUGGER_PRIVATE_DATA   *DebuggerPrivate,\r
+  IN EFI_DEBUGGER_SYMBOL_OBJECT  *Object,\r
+  IN CHAR16                      *FileName\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Find code from object\r
+\r
+Arguments:\r
+\r
+  Object          - Symbol object\r
+  FileName        - File name\r
+\r
+Returns:\r
+\r
+  CodeBuffer\r
+\r
+--*/\r
+{\r
+  UINTN                      EntryIndex;\r
+\r
+  //\r
+  // Go througn each Entry in this Object\r
+  //\r
+  for (EntryIndex = 0; EntryIndex < Object->EntryCount; EntryIndex++) {\r
+    //\r
+    // This check is for Function only\r
+    //\r
+    if ((Object->Entry[EntryIndex].Type != EfiDebuggerSymbolFunction) &&\r
+        (Object->Entry[EntryIndex].Type != EfiDebuggerSymbolStaticFunction)) {\r
+      continue;\r
+    }\r
+    //\r
+    // Skip match varbss_init function, because they has no source code\r
+    //\r
+    if (AsciiStrnCmp (Object->Entry[EntryIndex].Name, "varbss_init", sizeof("varbss_init") - 1) == 0) {\r
+      continue;\r
+    }\r
+    //\r
+    // check the name\r
+    //\r
+    if (!MatchObjAndCod (Object->Entry[EntryIndex].ObjName, FileName)) {\r
+      continue;\r
+    }\r
+    //\r
+    // found it, return source buffer\r
+    //\r
+    if (Object->Entry[EntryIndex].CodBuffer != NULL) {\r
+      return Object->Entry[EntryIndex].SourceBuffer;\r
+    }\r
+  }\r
+\r
+  //\r
+  // not found\r
+  //\r
+  return NULL;\r
+}\r
+\r
+EFI_STATUS\r
+EdbLoadCode (\r
+  IN EFI_DEBUGGER_PRIVATE_DATA   *DebuggerPrivate,\r
+  IN CHAR16                      *MapFileName,\r
+  IN CHAR16                      *FileName,\r
+  IN UINTN                       BufferSize,\r
+  IN VOID                        *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Load code\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  MapFileName     - Symbol file name\r
+  FileName        - Code file name\r
+  BufferSize      - Code file buffer size\r
+  Buffer          - Code file buffer\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - Code loaded successfully\r
+\r
+--*/\r
+{\r
+  EFI_DEBUGGER_SYMBOL_OBJECT *Object;\r
+  UINTN                      ObjectIndex;\r
+  UINTN                      EntryIndex;\r
+  VOID                       *SourceBuffer;\r
+  EFI_STATUS                 Status;\r
+\r
+  //\r
+  // Find Symbol\r
+  //\r
+  Object = EdbFindSymbolFile (DebuggerPrivate, MapFileName, &ObjectIndex);\r
+  if (Object == NULL) {\r
+    EDBPrint (L"SymbolFile is not loaded!\n");\r
+    return EFI_NOT_FOUND;\r
+  } else {\r
+    //\r
+    // Check duplicated File\r
+    //\r
+    SourceBuffer = EdbFindCodeFromObject (DebuggerPrivate, Object, FileName);\r
+    if (SourceBuffer != NULL) {\r
+      //\r
+      // unnload duplicated code\r
+      //\r
+      Status = EdbUnloadCode (DebuggerPrivate, MapFileName, FileName, &SourceBuffer);\r
+      if (EFI_ERROR(Status)) {\r
+        DEBUG ((DEBUG_ERROR, "Unload Duplicated Code File Error!\n"));\r
+        return Status;\r
+      }\r
+      Status = EdbDeleteCodeBuffer (DebuggerPrivate, MapFileName, FileName, SourceBuffer);\r
+      if (EFI_ERROR(Status)) {\r
+        DEBUG ((DEBUG_ERROR, "Delete Duplicated Code File Error!\n"));\r
+        return Status;\r
+      }\r
+    }\r
+  }\r
+\r
+  //\r
+  // Go through each SymbolEntry\r
+  //\r
+  for (EntryIndex = 0; EntryIndex < Object->EntryCount; EntryIndex++) {\r
+    //\r
+    // load symbol for function only\r
+    //\r
+    if ((Object->Entry[EntryIndex].Type != EfiDebuggerSymbolFunction) &&\r
+        (Object->Entry[EntryIndex].Type != EfiDebuggerSymbolStaticFunction)) {\r
+      continue;\r
+    }\r
+    //\r
+    // skip varbss_init\r
+    //\r
+    if (AsciiStrnCmp (Object->Entry[EntryIndex].Name, "varbss_init", sizeof("varbss_init") - 1) == 0) {\r
+      continue;\r
+    }\r
+    //\r
+    // Check the name\r
+    //\r
+    if (!MatchObjAndCod (Object->Entry[EntryIndex].ObjName, FileName)) {\r
+      continue;\r
+    }\r
+    //\r
+    // load code for this symbol\r
+    //\r
+    Object->Entry[EntryIndex].CodBuffer = EdbLoadCodBySymbol (\r
+                                            Object->Entry[EntryIndex].Name,\r
+                                            Buffer,\r
+                                            BufferSize,\r
+                                            &Object->Entry[EntryIndex].CodBufferSize,\r
+                                            &Object->Entry[EntryIndex].FuncOffsetBase\r
+                                            );\r
+    if (Object->Entry[EntryIndex].CodBuffer != NULL) {\r
+      Object->Entry[EntryIndex].SourceBuffer = Buffer;\r
+    }\r
+  }\r
+\r
+  //\r
+  // patch end '\0' for each code buffer\r
+  //\r
+  for (EntryIndex = 0; EntryIndex < Object->EntryCount; EntryIndex++) {\r
+    if (Object->Entry[EntryIndex].CodBuffer != NULL) {\r
+      *((UINT8 *)Object->Entry[EntryIndex].CodBuffer + Object->Entry[EntryIndex].CodBufferSize) = 0;\r
+      DEBUG ((DEBUG_ERROR, "  CodeSymbol: %a, FuncOffset: 0x05%x\n", Object->Entry[EntryIndex].Name, Object->Entry[EntryIndex].FuncOffsetBase));\r
+//      DEBUG ((DEBUG_ERROR, "  [CODE]:\n%a\n", Object->Entry[EntryIndex].CodBuffer));\r
+    }\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EdbUnloadCode (\r
+  IN EFI_DEBUGGER_PRIVATE_DATA   *DebuggerPrivate,\r
+  IN CHAR16                      *MapFileName,\r
+  IN CHAR16                      *FileName,\r
+  OUT VOID                       **Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Unload code\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  MapFileName     - Symbol file name\r
+  FileName        - Code file name\r
+  Buffer          - Code file buffer\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - Code unloaded successfully\r
+\r
+--*/\r
+{\r
+  EFI_DEBUGGER_SYMBOL_OBJECT *Object;\r
+  UINTN                      ObjectIndex;\r
+  UINTN                      EntryIndex;\r
+\r
+  //\r
+  // Find Symbol\r
+  //\r
+  Object = EdbFindSymbolFile (DebuggerPrivate, MapFileName, &ObjectIndex);\r
+  if (Object == NULL) {\r
+    EDBPrint (L"SymbolFile is not loaded!\n");\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  //\r
+  // Find code\r
+  //\r
+  *Buffer = EdbFindCodeFromObject (DebuggerPrivate, Object, FileName);\r
+  if (*Buffer == NULL) {\r
+    EDBPrint (L"CodeFile is not loaded!\n");\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  //\r
+  // go through each entry\r
+  //\r
+  for (EntryIndex = 0; EntryIndex < Object->EntryCount; EntryIndex++) {\r
+    if ((Object->Entry[EntryIndex].Type != EfiDebuggerSymbolFunction) &&\r
+        (Object->Entry[EntryIndex].Type != EfiDebuggerSymbolStaticFunction)) {\r
+      continue;\r
+    }\r
+    if (AsciiStrnCmp (Object->Entry[EntryIndex].Name, "varbss_init", sizeof("varbss_init") - 1) == 0) {\r
+      continue;\r
+    }\r
+    if (!MatchObjAndCod (Object->Entry[EntryIndex].ObjName, FileName)) {\r
+      continue;\r
+    }\r
+    //\r
+    // clean up the buffer\r
+    //\r
+    Object->Entry[EntryIndex].CodBuffer = NULL;\r
+    Object->Entry[EntryIndex].CodBufferSize = 0;\r
+    Object->Entry[EntryIndex].FuncOffsetBase = 0;\r
+    Object->Entry[EntryIndex].SourceBuffer = NULL;\r
+  }\r
+\r
+  //\r
+  // Done\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EdbAddCodeBuffer (\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     CHAR16                    *MapFileName,\r
+  IN     CHAR16                    *CodeFileName,\r
+  IN     UINTN                     SourceBufferSize,\r
+  IN     VOID                      *SourceBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Add code buffer\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  MapFileName     - Symbol file name\r
+  CodeFileName    - Code file name\r
+  SourceBufferSize- Code buffer size\r
+  SourceBuffer    - Code buffer\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - CodeBuffer added successfully\r
+\r
+--*/\r
+{\r
+  UINTN                      Index;\r
+  EFI_DEBUGGER_SYMBOL_OBJECT *Object;\r
+\r
+  //\r
+  // Find Symbol\r
+  //\r
+  Object = EdbFindSymbolFile (DebuggerPrivate, MapFileName, NULL);\r
+  if (Object == NULL) {\r
+    EDBPrint (L"SymbolFile is not loaded!\n");\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  //\r
+  // Add it to last entry\r
+  //\r
+  for (Index = 0; Object->SourceBuffer[Index] != NULL; Index++) {\r
+    ;\r
+  }\r
+  Object->SourceBuffer[Index] = SourceBuffer;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EdbDeleteCodeBuffer (\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     CHAR16                    *MapFileName,\r
+  IN     CHAR16                    *CodeFileName,\r
+  IN     VOID                      *SourceBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Delete code buffer\r
+\r
+Arguments:\r
+\r
+  DebuggerPrivate - EBC Debugger private data structure\r
+  MapFileName     - Symbol file name\r
+  CodeFileName    - Code file name\r
+  SourceBuffer    - Code buffer\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - CodeBuffer deleted successfully\r
+\r
+--*/\r
+{\r
+  UINTN                      Index;\r
+  EFI_DEBUGGER_SYMBOL_OBJECT *Object;\r
+\r
+  //\r
+  // Find Symbol\r
+  //\r
+  Object = EdbFindSymbolFile (DebuggerPrivate, MapFileName, NULL);\r
+  if (Object == NULL) {\r
+    EDBPrint (L"SymbolFile is not loaded!\n");\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  for (Index = 0; Object->SourceBuffer[Index] != NULL; Index++) {\r
+    //\r
+    // free the buffer if match\r
+    //\r
+    if (Object->SourceBuffer[Index] == SourceBuffer) {\r
+      gBS->FreePool (SourceBuffer);\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (Object->SourceBuffer[Index] == NULL) {\r
+    //\r
+    // not return NOT_FOUND\r
+    //\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // remove the entry\r
+  //\r
+  Object->SourceBuffer[Index] = NULL;\r
+  for (Index = Index + 1; Object->SourceBuffer[Index] != NULL; Index++) {\r
+    Object->SourceBuffer[Index - 1] = Object->SourceBuffer[Index];\r
+  }\r
+  Object->SourceBuffer[Index - 1] = NULL;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+CHAR8 *\r
+FindSymbolStr (\r
+  IN UINTN Address\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Find the symbol string according to address\r
+\r
+Arguments:\r
+\r
+  Address         - Symbol address\r
+\r
+Returns:\r
+\r
+  Symbol string\r
+\r
+--*/\r
+{\r
+  UINTN                       ObjectIndex;\r
+  EFI_DEBUGGER_SYMBOL_OBJECT  *Object;\r
+  UINTN                       EntryIndex;\r
+  EFI_DEBUGGER_SYMBOL_ENTRY   *Entry;\r
+\r
+  //\r
+  // need we display symbol\r
+  //\r
+  if (!mDebuggerPrivate.DebuggerSymbolContext.DisplaySymbol) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Go through each object and entry\r
+  //\r
+  Object = mDebuggerPrivate.DebuggerSymbolContext.Object;\r
+  for (ObjectIndex = 0; ObjectIndex < mDebuggerPrivate.DebuggerSymbolContext.ObjectCount; ObjectIndex++) {\r
+    Entry = Object[ObjectIndex].Entry;\r
+    for (EntryIndex = 0; EntryIndex < Object[ObjectIndex].EntryCount; EntryIndex++) {\r
+      //\r
+      // if Address match, return Name\r
+      //\r
+      if (Address == (Entry[EntryIndex].RVA + Object[ObjectIndex].BaseAddress)) {\r
+        return Entry[EntryIndex].Name;\r
+      }\r
+    }\r
+  }\r
+\r
+  //\r
+  // not found\r
+  //\r
+  return NULL;\r
+}\r
+\r
+UINTN\r
+EdbGetLineNumberAndOffsetFromThisLine (\r
+  IN VOID     *Line,\r
+  OUT UINTN   *Offset\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Get line number and offset from this line in code file\r
+\r
+Arguments:\r
+\r
+  Line            - Line buffer in code file\r
+  Offset          - Offset to functin entry\r
+\r
+Returns:\r
+\r
+  Line number\r
+\r
+--*/\r
+{\r
+  UINTN  LineNumber;\r
+  CHAR8  *LineBuffer;\r
+  CHAR8  *FieldBuffer;\r
+\r
+  LineNumber = (UINTN)-1;\r
+  LineBuffer = Line;\r
+  *Offset = (UINTN)-1;\r
+\r
+  while (LineBuffer != NULL) {\r
+    //\r
+    // Check candidate\r
+    //\r
+    if (*LineBuffer != ' ') {\r
+      return (UINTN)-1;\r
+    }\r
+\r
+    //\r
+    // Get Offset\r
+    //\r
+    if (*(LineBuffer + 2) != ' ') {\r
+      if (*Offset == (UINTN)-1) {\r
+        FieldBuffer = AsciiStrGetNewTokenField (LineBuffer + 2, " ");\r
+        *Offset = AsciiXtoi (FieldBuffer);\r
+        PatchForAsciiStrTokenAfter (FieldBuffer, ' ');\r
+      }\r
+    }\r
+\r
+    //\r
+    // 1. assembly instruction\r
+    //\r
+    FieldBuffer = AsciiStrGetNewTokenField (LineBuffer, ":");\r
+    //\r
+    // 2. file path\r
+    //\r
+    FieldBuffer = AsciiStrGetNextTokenField (":");\r
+    PatchForAsciiStrTokenBefore (FieldBuffer, ':');\r
+    if (FieldBuffer == NULL) {\r
+      //\r
+      // candidate found\r
+      //\r
+      LineNumber = 0;\r
+      LineBuffer = AsciiStrGetNextTokenLine ("\n");\r
+      PatchForAsciiStrTokenBefore (LineBuffer, '\n');\r
+      continue;\r
+    }\r
+    //\r
+    // 3. line number\r
+    //\r
+    FieldBuffer = AsciiStrGetNextTokenField (":");\r
+    PatchForAsciiStrTokenBefore (FieldBuffer, ':');\r
+    if (FieldBuffer == NULL) {\r
+      //\r
+      // impossible, TBD?\r
+      //\r
+      LineBuffer = AsciiStrGetNextTokenLine ("\n");\r
+      PatchForAsciiStrTokenBefore (LineBuffer, '\n');\r
+      continue;\r
+    }\r
+\r
+    LineNumber = AsciiAtoi (FieldBuffer);\r
+    //\r
+    // Not patch after\r
+    //\r
+\r
+    return LineNumber;\r
+  }\r
+\r
+  return (UINTN)-1;\r
+}\r
+\r
+typedef enum {\r
+  EdbEbcLineSearchTypeAny,\r
+  EdbEbcLineSearchTypeFirst,\r
+  EdbEbcLineSearchTypeLast,\r
+  EdbEbcLineSearchTypeMax,\r
+} EDB_EBC_LINE_SEARCH_TYPE;\r
+\r
+UINTN\r
+EdbGetLineNumberFromCode (\r
+  IN EFI_DEBUGGER_SYMBOL_ENTRY  *Entry,\r
+  IN UINTN                      FuncOffset,\r
+  IN EDB_EBC_LINE_SEARCH_TYPE   SearchType\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Get line number from this code file\r
+\r
+Arguments:\r
+\r
+  Entry           - Symbol entry\r
+  FuncOffset      - Offset to functin entry\r
+  SearchType      - Search type for the code\r
+\r
+Returns:\r
+\r
+  Line number\r
+\r
+--*/\r
+{\r
+  CHAR8  *LineBuffer;\r
+  UINTN  LineNumber;\r
+  UINTN  Offset;\r
+  UINTN  CandidateLineNumber;\r
+  UINTN  CandidateOffset;\r
+\r
+  if (SearchType < 0 || SearchType >= EdbEbcLineSearchTypeMax) {\r
+    return (UINTN)-1;\r
+  }\r
+\r
+  LineNumber = (UINTN)-1;\r
+  CandidateLineNumber = (UINTN)-1;\r
+  CandidateOffset = (UINTN)-1;\r
+  LineBuffer = AsciiStrGetNewTokenLine (Entry->CodBuffer, "\n");\r
+  while (LineBuffer != NULL) {\r
+    if (*LineBuffer != ' ') {\r
+      LineBuffer = AsciiStrGetNextTokenLine ("\n");\r
+      PatchForAsciiStrTokenBefore (LineBuffer, '\n');\r
+      continue;\r
+    }\r
+\r
+    //\r
+    // Get Info\r
+    //\r
+    LineNumber = EdbGetLineNumberAndOffsetFromThisLine (LineBuffer, &Offset);\r
+\r
+    //\r
+    // Check offset\r
+    //\r
+    if (Offset != FuncOffset) {\r
+      //\r
+      // Check last offset match\r
+      //\r
+      if (CandidateOffset == FuncOffset) {\r
+        if (SearchType == EdbEbcLineSearchTypeLast) {\r
+          PatchForAsciiStrTokenAfter (LineBuffer, '\n');\r
+          if (CandidateLineNumber != LineNumber) {\r
+            return CandidateLineNumber;\r
+          } else {\r
+            return (UINTN)-1;\r
+          }\r
+        } else {\r
+          //\r
+          // impossible, TBD?\r
+          //\r
+        }\r
+      }\r
+\r
+      LineBuffer = AsciiStrGetNextTokenLine ("\n");\r
+      PatchForAsciiStrTokenBefore (LineBuffer, '\n');\r
+      CandidateLineNumber = LineNumber;\r
+      continue;\r
+    }\r
+\r
+    //\r
+    // Offset match, more check\r
+    //\r
+    if (SearchType == EdbEbcLineSearchTypeAny) {\r
+      PatchForAsciiStrTokenAfter (LineBuffer, '\n');\r
+      return LineNumber;\r
+    }\r
+\r
+    if (SearchType == EdbEbcLineSearchTypeFirst) {\r
+      //\r
+      // Check last line\r
+      //\r
+      PatchForAsciiStrTokenAfter (LineBuffer, '\n');\r
+      if (CandidateLineNumber != LineNumber) {\r
+        return LineNumber;\r
+      } else {\r
+        return (UINTN)-1;\r
+      }\r
+    }\r
+\r
+    CandidateLineNumber = LineNumber;\r
+    CandidateOffset = Offset;\r
+\r
+    LineBuffer = AsciiStrGetNextTokenLine ("\n");\r
+    PatchForAsciiStrTokenBefore (LineBuffer, '\n');\r
+  }\r
+\r
+  //\r
+  // Check last offset match\r
+  //\r
+  if (CandidateOffset == FuncOffset) {\r
+    if (SearchType == EdbEbcLineSearchTypeLast) {\r
+      return CandidateLineNumber;\r
+    }\r
+  }\r
+\r
+  return (UINTN)-1;\r
+}\r
+\r
+VOID *\r
+EdbGetSourceStrFromCodeByLine (\r
+  IN EFI_DEBUGGER_SYMBOL_ENTRY  *Entry,\r
+  IN UINTN                      LineNumber,\r
+  IN VOID                       **FuncEnd\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Get the source string from this code file by line\r
+\r
+Arguments:\r
+\r
+  Entry           - Symbol entry\r
+  LineNumber      - line number\r
+  FuncEnd         - Function end\r
+\r
+Returns:\r
+\r
+  Funtion start\r
+\r
+--*/\r
+{\r
+  CHAR8  *LineBuffer;\r
+  CHAR8  *FieldBuffer;\r
+  VOID   *FuncStart;\r
+  UINTN  Number;\r
+\r
+  FuncStart = NULL;\r
+  LineBuffer = AsciiStrGetNewTokenLine (Entry->CodBuffer, "\n");\r
+  while (LineBuffer != NULL) {\r
+    if (*LineBuffer != ';') {\r
+      if (FuncStart != NULL) {\r
+        //\r
+        // Over\r
+        //\r
+        *FuncEnd = LineBuffer - 1;\r
+        PatchForAsciiStrTokenAfter (LineBuffer, '\n');\r
+        return FuncStart;\r
+      }\r
+      LineBuffer = AsciiStrGetNextTokenLine ("\n");\r
+      PatchForAsciiStrTokenBefore (LineBuffer, '\n');\r
+      continue;\r
+    }\r
+\r
+    //\r
+    // Check LineNumber\r
+    //\r
+    FieldBuffer = AsciiStrGetNewTokenField (LineBuffer + 1, " ");\r
+    Number = AsciiAtoi (FieldBuffer);\r
+    PatchForAsciiStrTokenAfter (FieldBuffer, ' ');\r
+    if (Number != LineNumber) {\r
+      LineBuffer = AsciiStrGetNextTokenLine ("\n");\r
+      PatchForAsciiStrTokenBefore (LineBuffer, '\n');\r
+      continue;\r
+    }\r
+\r
+    //\r
+    // Line match, get line number\r
+    //\r
+    if (FuncStart == NULL) {\r
+      FuncStart = LineBuffer;\r
+    }\r
+\r
+    LineBuffer = AsciiStrGetNextTokenLine ("\n");\r
+    PatchForAsciiStrTokenBefore (LineBuffer, '\n');\r
+  }\r
+\r
+  return NULL;\r
+}\r
+\r
+VOID *\r
+EdbGetSourceStrFromCode (\r
+  IN EFI_DEBUGGER_SYMBOL_ENTRY  *Entry,\r
+  IN UINTN                      FuncOffset,\r
+  IN VOID                       **FuncEnd\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Get source string from this code file\r
+\r
+Arguments:\r
+\r
+  Entry           - Symbol entry\r
+  FuncOffset      - Offset to functin entry\r
+  FuncEnd         - Function end\r
+\r
+Returns:\r
+\r
+  Funtion start\r
+\r
+--*/\r
+{\r
+  UINTN  LineNumber;\r
+\r
+  //\r
+  // Only search the last line, then display\r
+  //\r
+  LineNumber = EdbGetLineNumberFromCode (Entry, FuncOffset, EdbEbcLineSearchTypeLast);\r
+  if (LineNumber == (UINTN)-1) {\r
+    return NULL;\r
+  }\r
+\r
+  return EdbGetSourceStrFromCodeByLine (Entry, LineNumber, FuncEnd);\r
+}\r
+\r
+UINTN\r
+EdbPrintSource (\r
+  IN UINTN     Address,\r
+  IN BOOLEAN   IsPrint\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Print source\r
+\r
+Arguments:\r
+\r
+  Address         - Instruction address\r
+  IsPrint         - Whether need to print\r
+\r
+Returns:\r
+\r
+  1 - find the source\r
+  0 - not find the source\r
+\r
+--*/\r
+{\r
+  UINTN                      SymbolAddress;\r
+  EFI_DEBUGGER_SYMBOL_OBJECT *RetObject;\r
+  EFI_DEBUGGER_SYMBOL_ENTRY  *RetEntry;\r
+  UINTN                      FuncOffset;\r
+  UINT8                      *FuncStart;\r
+  UINT8                      *FuncEnd;\r
+  UINT8                      *FuncIndex;\r
+  CHAR8                      Buffer[EFI_DEBUG_MAX_PRINT_BUFFER];\r
+  UINTN                      BufferSize;\r
+\r
+  //\r
+  // need we display symbol\r
+  //\r
+  if (!mDebuggerPrivate.DebuggerSymbolContext.DisplaySymbol) {\r
+    return 0 ;\r
+  }\r
+\r
+  //\r
+  // find the symbol address\r
+  //\r
+  SymbolAddress = EbdFindSymbolAddress (\r
+                    Address,\r
+                    EdbMatchSymbolTypeLowerAddress,\r
+                    &RetObject,\r
+                    &RetEntry\r
+                    );\r
+  if (SymbolAddress == 0) {\r
+    return 0 ;\r
+  }\r
+\r
+  FuncOffset = Address - SymbolAddress + RetEntry->FuncOffsetBase;\r
+\r
+  //\r
+  // Get Func String\r
+  //\r
+  FuncStart = EdbGetSourceStrFromCode (RetEntry, FuncOffset, (VOID**) &FuncEnd);\r
+  if (FuncStart == NULL) {\r
+    return 0 ;\r
+  }\r
+\r
+  //\r
+  // check whether need to real print\r
+  //\r
+  if (!IsPrint) {\r
+    return 1;\r
+  }\r
+\r
+  *(UINT8 *)FuncEnd = 0;\r
+\r
+  //\r
+  // seperate buffer by \n, so that \r can be added.\r
+  //\r
+  FuncIndex = FuncStart;\r
+  while (*FuncIndex != 0) {\r
+    if (*FuncIndex == '\n') {\r
+      if ((FuncIndex - FuncStart) < (EFI_DEBUG_MAX_PRINT_BUFFER - 3)) {\r
+        BufferSize = FuncIndex - FuncStart;\r
+      } else {\r
+        BufferSize = EFI_DEBUG_MAX_PRINT_BUFFER - 3;\r
+      }\r
+      if (BufferSize != 0) {\r
+        CopyMem (Buffer, FuncStart, BufferSize);\r
+      }\r
+      Buffer[BufferSize] = 0;\r
+      EDBPrint (L"%a\n", Buffer);\r
+      FuncStart = FuncIndex + 1;\r
+      FuncIndex = FuncStart;\r
+    } else {\r
+      FuncIndex ++;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Patch the end\r
+  //\r
+  *(UINT8 *)FuncEnd = '\n';\r
+\r
+  return 1 ;\r
+}\r
+\r
+VOID\r
+GetMapfileAndSymbol (\r
+  IN CHAR16   *Symbol,\r
+  OUT CHAR16  **MapfileName,\r
+  OUT CHAR16  **SymbolName\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Get Mapfile and SymbolName from one symbol format: [MapFileName:]SymbolName\r
+\r
+Arguments:\r
+\r
+  Symbol          - whole Symbol name\r
+  MapfileName     - the mapfile name in the symbol\r
+  SymbolName      - the symbol name in the symbol\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  CHAR16  *Ch;\r
+\r
+  *MapfileName = NULL;\r
+  *SymbolName = Symbol;\r
+\r
+  for (Ch = Symbol; *Ch != 0; Ch++) {\r
+    //\r
+    // Find split char\r
+    //\r
+    if (*Ch == L':') {\r
+      *MapfileName = Symbol;\r
+      *Ch = 0;\r
+      *SymbolName = Ch + 1;\r
+      break;\r
+    }\r
+  }\r
+\r
+  return ;\r
+}\r
+\r
+EFI_STATUS\r
+Symboltoi (\r
+  IN CHAR16   *Symbol,\r
+  OUT UINTN   *Address\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Convert a symbol to an address\r
+\r
+Arguments:\r
+\r
+  Symbol          - Symbol name\r
+  Address         - Symbol address\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS    - symbol found and address returned.\r
+  EFI_NOT_FOUND  - symbol not found\r
+  EFI_NO_MAPPING - duplicated symbol not found\r
+\r
+--*/\r
+{\r
+  UINTN                       ObjectIndex;\r
+  EFI_DEBUGGER_SYMBOL_OBJECT  *Object;\r
+  UINTN                       EntryIndex;\r
+  EFI_DEBUGGER_SYMBOL_ENTRY   *Entry;\r
+  CHAR16                      *SymbolName;\r
+  CHAR16                      *MapfileName;\r
+\r
+  //\r
+  // Split one symbol to mapfile name and symbol name\r
+  //\r
+  GetMapfileAndSymbol (Symbol, &MapfileName, &SymbolName);\r
+\r
+  *Address = 0;\r
+  //\r
+  // Go through each object\r
+  //\r
+  Object = mDebuggerPrivate.DebuggerSymbolContext.Object;\r
+  for (ObjectIndex = 0; ObjectIndex < mDebuggerPrivate.DebuggerSymbolContext.ObjectCount; ObjectIndex++) {\r
+    //\r
+    // Check MapfileName\r
+    //\r
+    if ((MapfileName != NULL) && (StriCmp (Object[ObjectIndex].Name, MapfileName) != 0)) {\r
+      continue;\r
+    }\r
+    //\r
+    // Go through each entry\r
+    //\r
+    Entry = Object[ObjectIndex].Entry;\r
+    for (EntryIndex = 0; EntryIndex < Object[ObjectIndex].EntryCount; EntryIndex++) {\r
+      //\r
+      // Check SymbolName (case sensitive)\r
+      //\r
+      if (StrCmpUnicodeAndAscii (SymbolName, Entry[EntryIndex].Name) == 0) {\r
+        if ((*Address != 0) && (MapfileName == NULL)) {\r
+          //\r
+          // Find the duplicated symbol\r
+          //\r
+          EDBPrint (L"Duplicated Symbol found!\n");\r
+          return EFI_NO_MAPPING;\r
+        } else {\r
+          //\r
+          // record Address\r
+          //\r
+          *Address = (Entry[EntryIndex].RVA + Object[ObjectIndex].BaseAddress);\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  if (*Address == 0) {\r
+    //\r
+    // Not found\r
+    //\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSymbol.h b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSymbol.h
new file mode 100644 (file)
index 0000000..a9d49d2
--- /dev/null
@@ -0,0 +1,128 @@
+/*++\r
+\r
+Copyright (c) 2007, 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
+\r
+Module Name:\r
+\r
+  EdbSymbol.h\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#ifndef _EFI_EDB_SYMBOL_H_\r
+#define _EFI_EDB_SYMBOL_H_\r
+\r
+#include <Uefi.h>\r
+\r
+//\r
+// The default base address is 0x10000000\r
+//\r
+#define EFI_DEBUGGER_DEFAULT_LINK_IMAGEBASE  0x10000000\r
+\r
+#define EFI_DEBUGGER_MAX_SYMBOL_ADDRESS_DELTA_VALUE  0x100000 // 1 M delta\r
+\r
+typedef enum {\r
+  EdbMatchSymbolTypeSameAdderss,\r
+  EdbMatchSymbolTypeNearestAddress,\r
+  EdbMatchSymbolTypeLowerAddress,\r
+  EdbMatchSymbolTypeUpperAddress,\r
+  EdbMatchSymbolTypeMax,\r
+} EDB_MATCH_SYMBOL_TYPE;\r
+\r
+typedef enum {\r
+  EdbEbcImageRvaSearchTypeAny,\r
+  EdbEbcImageRvaSearchTypeFirst,\r
+  EdbEbcImageRvaSearchTypeLast,\r
+  EdbEbcImageRvaSearchTypeMax,\r
+} EDB_EBC_IMAGE_RVA_SEARCH_TYPE;\r
+\r
+UINTN\r
+EbdFindSymbolAddress (\r
+  IN UINTN                       Address,\r
+  IN EDB_MATCH_SYMBOL_TYPE       Type,\r
+  OUT EFI_DEBUGGER_SYMBOL_OBJECT **Object,\r
+  OUT EFI_DEBUGGER_SYMBOL_ENTRY  **Entry\r
+  );\r
+\r
+EFI_STATUS\r
+EdbLoadSymbol (\r
+  IN EFI_DEBUGGER_PRIVATE_DATA   *DebuggerPrivate,\r
+  IN CHAR16                      *FileName,\r
+  IN UINTN                       BufferSize,\r
+  IN VOID                        *Buffer\r
+  );\r
+\r
+EFI_STATUS\r
+EdbUnloadSymbol (\r
+  IN EFI_DEBUGGER_PRIVATE_DATA   *DebuggerPrivate,\r
+  IN CHAR16                      *FileName\r
+  );\r
+\r
+EFI_STATUS\r
+EdbPatchSymbolRVA (\r
+  IN EFI_DEBUGGER_PRIVATE_DATA     *DebuggerPrivate,\r
+  IN CHAR16                        *FileName,\r
+  IN EDB_EBC_IMAGE_RVA_SEARCH_TYPE SearchType\r
+  );\r
+\r
+EFI_STATUS\r
+EdbLoadCode (\r
+  IN EFI_DEBUGGER_PRIVATE_DATA   *DebuggerPrivate,\r
+  IN CHAR16                      *MapFileName,\r
+  IN CHAR16                      *FileName,\r
+  IN UINTN                       BufferSize,\r
+  IN VOID                        *Buffer\r
+  );\r
+\r
+EFI_STATUS\r
+EdbUnloadCode (\r
+  IN EFI_DEBUGGER_PRIVATE_DATA   *DebuggerPrivate,\r
+  IN CHAR16                      *MapFileName,\r
+  IN CHAR16                      *FileName,\r
+  OUT VOID                       **Buffer\r
+  );\r
+\r
+EFI_STATUS\r
+EdbAddCodeBuffer (\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     CHAR16                    *MapFileName,\r
+  IN     CHAR16                    *CodeFileName,\r
+  IN     UINTN                     SourceBufferSize,\r
+  IN     VOID                      *SourceBuffer\r
+  );\r
+\r
+EFI_STATUS\r
+EdbDeleteCodeBuffer (\r
+  IN     EFI_DEBUGGER_PRIVATE_DATA *DebuggerPrivate,\r
+  IN     CHAR16                    *MapFileName,\r
+  IN     CHAR16                    *CodeFileName,\r
+  IN     VOID                      *SourceBuffer\r
+  );\r
+\r
+CHAR8 *\r
+FindSymbolStr (\r
+  IN UINTN Address\r
+  );\r
+\r
+UINTN\r
+EdbPrintSource (\r
+  IN UINTN     Address,\r
+  IN BOOLEAN   IsPrint\r
+  );\r
+\r
+EFI_STATUS\r
+Symboltoi (\r
+  IN CHAR16   *Symbol,\r
+  OUT UINTN   *Address\r
+  );\r
+\r
+#endif\r
diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebuggerExtra.uni b/MdeModulePkg/Universal/EbcDxe/EbcDebuggerExtra.uni
new file mode 100644 (file)
index 0000000..539248d
--- /dev/null
@@ -0,0 +1,17 @@
+// /** @file\r
+// EFI Byte Code (EBC) Debugger\r
+//\r
+// Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+//\r
+// 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
+// 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
+//\r
+// **/\r
+\r
+#string STR_PROPERTIES_MODULE_NAME\r
+#language en-US\r
+"EFI Byte Code (EBC) Debugger"\r