]> git.proxmox.com Git - mirror_edk2.git/commitdiff
code scrub:
authorvanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 16 Dec 2008 09:21:45 +0000 (09:21 +0000)
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 16 Dec 2008 09:21:45 +0000 (09:21 +0000)
1. updated functions header.
2. sync some comments for .S files.
3. fixed some error in AsmFuncs.S

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7044 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/DebugSupportDxe/DebugSupportDxe.inf
MdeModulePkg/Universal/DebugSupportDxe/Ia32/AsmFuncs.S
MdeModulePkg/Universal/DebugSupportDxe/Ia32/PlDebugSupport.c
MdeModulePkg/Universal/DebugSupportDxe/Ia32/PlDebugSupportIa32.c
MdeModulePkg/Universal/DebugSupportDxe/Ipf/AsmFuncs.s
MdeModulePkg/Universal/DebugSupportDxe/Ipf/Ds64Macros.i
MdeModulePkg/Universal/DebugSupportDxe/Ipf/PlDebugSupport.c
MdeModulePkg/Universal/DebugSupportDxe/Ipf/PlDebugSupport.h
MdeModulePkg/Universal/DebugSupportDxe/X64/AsmFuncs.S
MdeModulePkg/Universal/DebugSupportDxe/X64/AsmFuncs.asm
MdeModulePkg/Universal/DebugSupportDxe/X64/PlDebugSupportX64.c

index 41ed14d453b2979133e4f4eaa66be9c5395d1aad..9b424e31fed906f4ba90f23aaa9404642514f0e2 100644 (file)
@@ -1,7 +1,11 @@
 #/** @file\r
-# Component description file for DebugSupport module.\r
+# This driver installs Debug Support protocol for the selected processor.\r
+#\r
+# This driver provides the capabilities for debug-agent to gain control of the machine\r
+# when certain types of events occur, i.e. breakpoint, processor execptions, etc. It also\r
+# provides debug-agent to periodically gain control during operation of the machine to\r
+# check for asynchronous commands form the host.\r
 #\r
-# This driver installs DebugSupport protocol for the selected processor.\r
 # Copyright (c) 2006 - 2008, Intel Corporation\r
 #\r
 #  All rights reserved. This program and the accompanying materials\r
index b6f326d805a0735da86a7de5be55dbaec8f1cdcf..03fc6c98baa680fc8dbe061817591a12f4f4ffbf 100644 (file)
@@ -1,7 +1,7 @@
 #/**@file\r
 # Low leve IA32 specific debug support functions.\r
 #\r
-# Copyright (c) 2006, Intel Corporation\r
+# Copyright (c) 2006 - 2008, Intel Corporation. <BR>\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
 .globl ASM_PFX(CommonIdtEntry)\r
 .globl ASM_PFX(FxStorSupport)\r
 \r
+ASM_PFX(StubSize):       .long   ASM_PFX(InterruptEntryStubEnd) - ASM_PFX(InterruptEntryStub)\r
 ASM_PFX(AppEsp):         .long   0x11111111 # ?\r
 ASM_PFX(DebugEsp):       .long   0x22222222 # ?\r
 ASM_PFX(ExtraPush):      .long   0x33333333 # ?\r
 ASM_PFX(ExceptData):     .long   0x44444444 # ?\r
 ASM_PFX(Eflags):         .long   0x55555555 # ?\r
 ASM_PFX(OrigVector):     .long   0x66666666 # ?\r
-ASM_PFX(StubSize):       .long   ASM_PFX(InterruptEntryStubEnd) - ASM_PFX(InterruptEntryStub)\r
 \r
+#------------------------------------------------------------------------------\r
+# BOOLEAN\r
+# FxStorSupport (\r
+#   void\r
+#   )\r
+#\r
+# Abstract: Returns TRUE if FxStor instructions are supported\r
+#\r
 .globl ASM_PFX(FxStorSupport)\r
 ASM_PFX(FxStorSupport):\r
+#\r
+# cpuid corrupts ebx which must be preserved per the C calling convention\r
+#\r
         push   %ebx\r
         mov    $0x1,%eax\r
         cpuid\r
@@ -36,6 +47,15 @@ ASM_PFX(FxStorSupport):
         shr    $0x18,%eax\r
         pop    %ebx\r
         ret\r
+#------------------------------------------------------------------------------\r
+# void\r
+# Vect2Desc (\r
+#   DESCRIPTOR * DestDesc,\r
+#   void (*Vector) (void)\r
+#   )\r
+#\r
+# Abstract: Encodes an IDT descriptor with the given physical address\r
+#\r
 \r
 .globl ASM_PFX(Vect2Desc)\r
 ASM_PFX(Vect2Desc):\r
@@ -53,18 +73,68 @@ ASM_PFX(Vect2Desc):
 \r
 .globl ASM_PFX(InterruptEntryStub)\r
 ASM_PFX(InterruptEntryStub):\r
-        mov    %esp,0x0\r
-        mov    $0x0,%esp\r
-        push   $0x0\r
-        jmp    ASM_PFX(CommonIdtEntry)\r
+        mov    %esp,0x0                    # save stack top\r
+        mov    $0x0,%esp                   # switch to debugger stack\r
+        push   $0x0                        # push vector number - will be modified before installed\r
+        jmp    ASM_PFX(CommonIdtEntry)     # jump CommonIdtEntry\r
 .globl ASM_PFX(InterruptEntryStubEnd)\r
 ASM_PFX(InterruptEntryStubEnd):\r
 \r
+#------------------------------------------------------------------------------\r
+# CommonIdtEntry\r
+#\r
+# Abstract: This code is not a function, but is the common part for all IDT\r
+#               vectors.\r
+#\r
 .globl ASM_PFX(CommonIdtEntry)\r
 ASM_PFX(CommonIdtEntry):\r
+##\r
+## At this point, the stub has saved the current application stack esp into AppEsp\r
+## and switched stacks to the debug stack, where it pushed the vector number\r
+##\r
+## The application stack looks like this:\r
+##\r
+##              ...\r
+##              (last application stack entry)\r
+##              eflags from interrupted task\r
+##              CS from interrupted task\r
+##              EIP from interrupted task\r
+##              Error code <-------------------- Only present for some exeption types\r
+##\r
+##\r
+\r
+\r
+## The stub switched us to the debug stack and pushed the interrupt number.\r
+##\r
+## Next, construct the context record.  It will be build on the debug stack by\r
+## pushing the registers in the correct order so as to create the context structure\r
+## on the debug stack.  The context record must be built from the end back to the\r
+## beginning because the stack grows down...\r
+#\r
+## For reference, the context record looks like this:\r
+##\r
+## typedef\r
+## struct {\r
+##   UINT32             ExceptionData;\r
+##   FX_SAVE_STATE_IA32 FxSaveState;\r
+##   UINT32             Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
+##   UINT32             Cr0, Cr2, Cr3, Cr4;\r
+##   UINT32             EFlags;\r
+##   UINT32             Ldtr, Tr;\r
+##   UINT32             Gdtr[2], Idtr[2];\r
+##   UINT32             Eip;\r
+##   UINT32             Gs, Fs, Es, Ds, Cs, Ss;\r
+##   UINT32             Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;\r
+## } SYSTEM_CONTEXT_IA32;  // 32 bit system context record\r
+\r
+## UINT32  Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;\r
         pusha\r
+## Save interrupt state eflags register...\r
         pushf\r
         pop    %eax\r
+## We need to determine if any extra data was pushed by the exception, and if so, save it\r
+## To do this, we check the exception number pushed by the stub, and cache the\r
+## result in a variable since we'll need this again.\r
         mov    %eax,0x0\r
         cmpl   $0x8,0x0\r
         jne    ASM_PFX(CommonIdtEntry+0x20)\r
@@ -95,6 +165,9 @@ ASM_PFX(CommonIdtEntry):
         movl   $0x1,0x0\r
         jmp    ASM_PFX(CommonIdtEntry+0xa8)\r
         movl   $0x0,0x0\r
+## If there's some extra data, save it also, and modify the saved AppEsp to effectively\r
+## pop this value off the application's stack.\r
+\r
         cmpl   $0x1,0x0\r
         jne    ASM_PFX(CommonIdtEntry+0xc8)\r
         mov    0x0,%eax\r
@@ -104,13 +177,23 @@ ASM_PFX(CommonIdtEntry):
         mov    %eax,0x0\r
         jmp    ASM_PFX(CommonIdtEntry+0xd2)\r
         movl   $0x0,0x0\r
+## The "pushad" above pushed the debug stack esp.  Since what we're actually doing\r
+## is building the context record on the debug stack, we need to save the pushed\r
+## debug ESP, and replace it with the application's last stack entry...\r
         mov    0xc(%esp),%eax\r
         mov    %eax,0x0\r
         mov    0x0,%eax\r
         add    $0xc,%eax\r
+        # application stack has eflags, cs, & eip, so\r
+        # last actual application stack entry is\r
+        # 12 bytes into the application stack.\r
         mov    %eax,0xc(%esp)\r
+## continue building context record\r
+## UINT32  Gs, Fs, Es, Ds, Cs, Ss;  insure high 16 bits of each is zero\r
         mov    %ss,%eax\r
         push   %eax\r
+        \r
+        # CS from application is one entry back in application stack\r
         mov    0x0,%eax\r
         movzwl 0x4(%eax),%eax\r
         push   %eax\r
@@ -122,21 +205,35 @@ ASM_PFX(CommonIdtEntry):
         push   %eax\r
         mov    %gs,%eax\r
         push   %eax\r
+\r
+## UINT32  Eip;\r
+        # Eip from application is on top of application stack\r
         mov    0x0,%eax\r
         pushl  (%eax)\r
+\r
+## UINT32  Gdtr[2], Idtr[2];\r
         push   $0x0\r
         push   $0x0\r
         sidtl  (%esp)\r
         push   $0x0\r
         push   $0x0\r
         sgdtl  (%esp)\r
+\r
+## UINT32  Ldtr, Tr;\r
         xor    %eax,%eax\r
         str    %eax\r
         push   %eax\r
         sldt   %eax\r
         push   %eax\r
+\r
+## UINT32  EFlags;\r
+## Eflags from application is two entries back in application stack\r
         mov    0x0,%eax\r
         pushl  0x8(%eax)\r
+\r
+## UINT32  Cr0, Cr1, Cr2, Cr3, Cr4;\r
+## insure FXSAVE/FXRSTOR is enabled in CR4...\r
+## ... while we're at it, make sure DE is also enabled...\r
         mov    %cr4,%eax\r
         or     $0x208,%eax\r
         mov    %eax,%cr4\r
@@ -148,12 +245,18 @@ ASM_PFX(CommonIdtEntry):
         push   $0x0\r
         mov    %cr0,%eax\r
         push   %eax\r
+\r
+## UINT32  Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
         mov    %db7,%eax\r
         push   %eax\r
+\r
+## clear Dr7 while executing debugger itself\r
         xor    %eax,%eax\r
         mov    %eax,%db7\r
         mov    %db6,%eax\r
         push   %eax\r
+\r
+## insure all status bits in dr6 are clear...\r
         xor    %eax,%eax\r
         mov    %eax,%db6\r
         mov    %db3,%eax\r
@@ -164,21 +267,38 @@ ASM_PFX(CommonIdtEntry):
         push   %eax\r
         mov    %db0,%eax\r
         push   %eax\r
+\r
+## FX_SAVE_STATE_IA32 FxSaveState;\r
         sub    $0x200,%esp\r
         mov    %esp,%edi\r
+        # IMPORTANT!! The debug stack has been carefully constructed to\r
+        # insure that esp and edi are 16 byte aligned when we get here.\r
+        # They MUST be.  If they are not, a GP fault will occur.\r
         fxsave (%edi)\r
+\r
+## UINT32  ExceptionData;\r
         mov    0x0,%eax\r
         push   %eax\r
+\r
+# call to C code which will in turn call registered handler\r
+# pass in the vector number\r
         mov    %esp,%eax\r
         push   %eax\r
         mov    0x0,%eax\r
         push   %eax\r
         call   ASM_PFX(CommonIdtEntry+0x184)\r
         add    $0x8,%esp\r
+\r
+# restore context...\r
+## UINT32  ExceptionData;\r
         add    $0x4,%esp\r
+\r
+## FX_SAVE_STATE_IA32 FxSaveState;\r
         mov    %esp,%esi\r
         fxrstor (%esi)\r
         add    $0x200,%esp\r
+\r
+## UINT32  Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
         pop    %eax\r
         mov    %eax,%db0\r
         pop    %eax\r
@@ -187,9 +307,13 @@ ASM_PFX(CommonIdtEntry):
         mov    %eax,%db2\r
         pop    %eax\r
         mov    %eax,%db3\r
+\r
+## skip restore of dr6.  We cleared dr6 during the context save.\r
         add    $0x4,%esp\r
         pop    %eax\r
         mov    %eax,%db7\r
+\r
+## UINT32  Cr0, Cr1, Cr2, Cr3, Cr4;\r
         pop    %eax\r
         mov    %eax,%cr0\r
         add    $0x4,%esp\r
@@ -199,10 +323,25 @@ ASM_PFX(CommonIdtEntry):
         mov    %eax,%cr3\r
         pop    %eax\r
         mov    %eax,%cr4\r
+\r
+## UINT32  EFlags;\r
         mov    0x0,%eax\r
         popl   0x8(%eax)\r
+\r
+## UINT32  Ldtr, Tr;\r
+## UINT32  Gdtr[2], Idtr[2];\r
+## Best not let anyone mess with these particular registers...\r
         add    $0x18,%esp\r
+\r
+## UINT32  Eip;\r
         popl   (%eax)\r
+\r
+## UINT32  SegGs, SegFs, SegEs, SegDs, SegCs, SegSs;\r
+## NOTE - modified segment registers could hang the debugger...  We\r
+##        could attempt to insulate ourselves against this possibility,\r
+##        but that poses risks as well.\r
+##\r
+\r
         pop    %gs\r
         pop    %fs\r
         pop    %es\r
@@ -210,35 +349,56 @@ ASM_PFX(CommonIdtEntry):
         popl   0x4(%eax)\r
         pop    %ss\r
         mov    0xc(%esp),%ebx\r
-        mov    0x0,%eax\r
+\r
+## The next stuff to restore is the general purpose registers that were pushed\r
+## using the "pushad" instruction.\r
+##\r
+## The value of ESP as stored in the context record is the application ESP\r
+## including the 3 entries on the application stack caused by the exception\r
+## itself. It may have been modified by the debug agent, so we need to\r
+## determine if we need to relocate the application stack.\r
+\r
+        mov    0x0,%eax          # move the potentially modified AppEsp into ebx\r
         add    $0xc,%eax\r
         cmp    %eax,%ebx\r
         je     ASM_PFX(CommonIdtEntry+0x202)\r
         mov    0x0,%eax\r
-        mov    (%eax),%ecx\r
+        mov    (%eax),%ecx       # EIP\r
         mov    %ecx,(%ebx)\r
-        mov    0x4(%eax),%ecx\r
+        mov    0x4(%eax),%ecx    # CS\r
         mov    %ecx,0x4(%ebx)\r
-        mov    0x8(%eax),%ecx\r
+        mov    0x8(%eax),%ecx    # EFLAGS\r
         mov    %ecx,0x8(%ebx)\r
-        mov    %ebx,%eax\r
+       \r
+        mov    %ebx,%eax         # modify the saved AppEsp to the new AppEsp\r
         mov    %eax,0x0\r
-        mov    0x0,%eax\r
-        mov    %eax,0xc(%esp)\r
+        mov    0x0,%eax          # restore the DebugEsp on the debug stack\r
+                                      # so our "popad" will not cause a stack switch\r
+        mov    %eax,0xc(%esp)    \r
         cmpl   $0x68,0x0\r
         jne    PhonyIretd+0xd\r
+## Restore eflags so when we chain, the flags will be exactly as if we were never here.\r
+## We gin up the stack to do an iretd so we can get ALL the flags.\r
         mov    0x0,%eax\r
         mov    0x8(%eax),%ebx\r
-        and    $0xfffffcff,%ebx\r
+        and    $0xfffffcff,%ebx  # special handling for IF and TF\r
         push   %ebx\r
         push   %cs\r
         push   $0x0\r
         iret\r
 \r
 PhonyIretd:\r
+## UINT32  Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;\r
         popa\r
+\r
+## Switch back to application stack\r
         mov    0x0,%esp\r
         jmp    *0x0\r
+## Jump to original handler\r
+## UINT32  Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;\r
         popa\r
+## Switch back to application stack\r
         mov    0x0,%esp\r
+\r
+## We're outa here...\r
         iret\r
index 3c96f9b518436089c075e3348426ae5492236258..ed38d06cae947ec909fc4f75c6d137bb27a72b76 100644 (file)
@@ -1,5 +1,5 @@
 /** @file\r
-  Generic debug support functions for IA32/x64.\r
+  IA32/x64 generic functions to support Debug Support protocol.\r
 \r
 Copyright (c) 2006 - 2008, Intel Corporation\r
 All rights reserved. This program and the accompanying materials\r
@@ -90,11 +90,27 @@ HookEntry (
   //\r
   OldIntFlagState = SaveAndDisableInterrupts ();\r
 \r
+  //\r
+  // gets IDT Gate descriptor by index\r
+  //\r
   ReadIdtGateDescriptor (ExceptionType, &(IdtEntryTable[ExceptionType].OrigDesc));\r
+  //\r
+  // stores orignal interrupt handle \r
+  //\r
   IdtEntryTable[ExceptionType].OrigVector = (DEBUG_PROC) GetInterruptHandleFromIdt (&(IdtEntryTable[ExceptionType].OrigDesc));\r
 \r
+  // \r
+  // encodes new IDT Gate descriptor by stub entry \r
+  //\r
   Vect2Desc (&IdtEntryTable[ExceptionType].NewDesc, IdtEntryTable[ExceptionType].StubEntry);\r
+  //\r
+  // stores NewCallback\r
+  //\r
   IdtEntryTable[ExceptionType].RegisteredCallback = NewCallback;\r
+\r
+  //\r
+  // writes back new IDT Gate descriptor\r
+  //\r
   WriteIdtGateDescriptor (ExceptionType, &(IdtEntryTable[ExceptionType].NewDesc));\r
 \r
   //\r
@@ -214,6 +230,7 @@ RegisterExceptionCallback (
   return ManageIdtEntryTable (ExceptionCallback, ExceptionType);\r
 }\r
 \r
+\r
 /**\r
   Invalidates processor instruction cache for a memory range. Subsequent execution in this range\r
   causes a fresh memory fetch to retrieve code to be executed.                                  \r
@@ -244,6 +261,7 @@ InvalidateInstructionCache (
   Common piece of code that invokes the registered handlers.\r
 \r
   This code executes in exception context so no efi calls are allowed.\r
+  This code is called from assembly file.\r
 \r
   @param  ExceptionType     Exception type\r
   @param  ContextRecord     System context\r
index c75c0401522b8588d0dd3eef98a9380cf8948144..d2073f65fd29bb02c7fa6ed5b1b262815540d990 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
-  IA32 specific debug support functions\r
+  IA32 specific functions to support Debug Support protocol.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation\r
+Copyright (c) 2008, 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
index 03603eafa1c8b31a2eddfd9adf4a00c82211c26a..aa497707c413f999dd5190ac4e3f0d30f2149f95 100644 (file)
@@ -10,8 +10,6 @@
 /// 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: AsmFuncs.s\r
-///\r
 ///\r
 \r
 \r
index 5855545f01faca8f74272c02efac7052e98371cd..eb3f63d9aa265fb4ec4d51ef514b2647045a25c1 100644 (file)
@@ -10,8 +10,6 @@
 /// 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: Ds64Macros.i\r
-///\r
 ///\r
 \r
 \r
index d358b425deeb02a7ea945bcf6b4c4fb15c384508..1e1c89d5de9a62c150302e550f8e904da490e85d 100644 (file)
@@ -1,5 +1,5 @@
 /** @file\r
-  IPF specific debug support functions\r
+  IPF specific functions to support Debug Support protocol.\r
 \r
 Copyright (c) 2006 - 2008, Intel Corporation                                                         \r
 All rights reserved. This program and the accompanying materials                          \r
@@ -12,9 +12,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
-//\r
-// private header files\r
-//\r
 #include "PlDebugSupport.h"\r
 \r
 BOOLEAN  mInHandler = FALSE;\r
@@ -66,7 +63,9 @@ PlInitializeDebugSupportDriver (
 \r
 /**\r
   Unload handler that is called during UnloadImage() - deallocates pool memory\r
-  used by the driver.  Must be public because it's referenced from DebugSuport.c\r
+  used by the driver. \r
+\r
+  Must be public because it's referenced from DebugSuport.c\r
 \r
   @param  ImageHandle    The firmware allocated handle for the EFI image.\r
 \r
@@ -90,10 +89,12 @@ PlUnloadDebugSupportDriver (
 \r
 /**\r
   C routine that is called for all registered exceptions.  This is the main\r
-  exception dispatcher.  Must be public because it's referenced from AsmFuncs.s.\r
+  exception dispatcher. \r
+\r
+  Must be public because it's referenced from AsmFuncs.s.\r
 \r
-  @param  ExceptionType        Exception Type\r
-  @param  Context              System Context\r
+  @param  ExceptionType        Specifies which processor exception.\r
+  @param  Context              System Context.\r
 **/\r
 VOID\r
 CommonHandler (\r
@@ -170,12 +171,11 @@ GetHandlerEntryPoint (
 /**\r
   This is the worker function that uninstalls and removes all handlers.\r
 \r
-  @param  ExceptionType     Exception Type\r
-  @param  NewBundles        New Boundles\r
-  @param  NewCallback       New Callback\r
+  @param  ExceptionType     Specifies which processor exception.\r
+  @param  NewBundles        New Boundles.\r
+  @param  NewCallback       A pointer to the new function to be registered.\r
 \r
   @retval EFI_ALEADY_STARTED Ivt already hooked.\r
-  @retval others             Indicates the request was not satisfied.\r
   @retval EFI_SUCCESS        Successfully uninstalled.\r
 \r
 **/\r
@@ -248,9 +248,9 @@ ManageIvtEntryTable (
   Saves original IVT contents and inserts a few new bundles which are fixed up\r
   to store the ExceptionType and then call the common handler.\r
 \r
-  @param  ExceptionType      Exception Type\r
-  @param  NewBundles         New Boundles\r
-  @param  NewCallback        New Callback\r
+  @param  ExceptionType      Specifies which processor exception.\r
+  @param  NewBundles         New Boundles.\r
+  @param  NewCallback        A pointer to the new function to be hooked.\r
 \r
 **/\r
 VOID\r
@@ -294,7 +294,7 @@ HookEntry (
 /**\r
   Restores original IVT contents when unregistering a callback function.\r
 \r
-  @param  ExceptionType     Exception Type\r
+  @param  ExceptionType     Specifies which processor exception.\r
 \r
 **/\r
 VOID\r
@@ -324,7 +324,7 @@ UnhookEntry (
 \r
   Records new callback in IvtEntryTable.\r
 \r
-  @param  NewCallback     New Callback\r
+  @param  NewCallback     A pointer to the interrupt handle.\r
 \r
 **/\r
 VOID\r
@@ -358,19 +358,17 @@ UnchainExternalInterrupt (
   IvtEntryTable[EXCEPT_IPF_EXTERNAL_INTERRUPT].RegisteredCallback = NULL;\r
 }\r
 \r
-//\r
-// The rest of the functions in this file are all member functions for the\r
-// DebugSupport protocol\r
-//\r
-\r
 /**\r
-  This is a DebugSupport protocol member function, hard\r
-  coded to support only 1 processor for now.\r
-\r
-  @param  This                The DebugSupport instance\r
-  @param  MaxProcessorIndex   The maximuim supported processor index\r
+  Returns the maximum value that may be used for the ProcessorIndex parameter in\r
+  RegisterPeriodicCallback() and RegisterExceptionCallback().                   \r
+    \r
+  Hard coded to support only 1 processor for now.\r
 \r
-  @retval EFI_SUCCESS         Always returned with **MaxProcessorIndex set to 0.\r
+  @param  This                  A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.\r
+  @param  MaxProcessorIndex     Pointer to a caller-allocated UINTN in which the maximum supported\r
+                                processor index is returned. Always 0 returned.                                     \r
+                                \r
+  @retval EFI_SUCCESS           Always returned with **MaxProcessorIndex set to 0.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -385,15 +383,18 @@ GetMaximumProcessorIndex (
 }\r
 \r
 /**\r
-  DebugSupport protocol member function.\r
-\r
-  @param  This               The DebugSupport instance\r
-  @param  ProcessorIndex     Which processor the callback applies to.\r
-  @param  PeriodicCallback   Callback function\r
-\r
-  @retval EFI_SUCCESS        Indicates the callback was registered.\r
-  @retval others             Callback was not registered.\r
-\r
+  Registers a function to be called back periodically in interrupt context.\r
+    \r
+  @param  This                  A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.\r
+  @param  ProcessorIndex        Specifies which processor the callback function applies to.\r
+  @param  PeriodicCallback      A pointer to a function of type PERIODIC_CALLBACK that is the main\r
+                                periodic entry point of the debug agent.\r
+                                \r
+  @retval EFI_SUCCESS           The function completed successfully.  \r
+  @retval EFI_ALREADY_STARTED   Non-NULL PeriodicCallback parameter when a callback\r
+                                function was previously registered.                \r
+  @retval EFI_OUT_OF_RESOURCES  System has insufficient memory resources to register new callback                               \r
+                                function. \r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -407,16 +408,21 @@ RegisterPeriodicCallback (
 }\r
 \r
 /**\r
-  DebugSupport protocol member function.\r
-\r
-  @param  This              The DebugSupport instance\r
-  @param  ProcessorIndex    Which processor the callback applies to.\r
-  @param  NewCallback       Callback function\r
-  @param  ExceptionType     Which exception to hook\r
-\r
-  @retval EFI_SUCCESS        Indicates the callback was registered.\r
-  @retval others             Callback was not registered.\r
-\r
+  Registers a function to be called when a given processor exception occurs.\r
+\r
+  This code executes in boot services context.\r
+    \r
+  @param  This                  A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.\r
+  @param  ProcessorIndex        Specifies which processor the callback function applies to.\r
+  @param  ExceptionCallback     A pointer to a function of type EXCEPTION_CALLBACK that is called\r
+                                when the processor exception specified by ExceptionType occurs.  \r
+  @param  ExceptionType         Specifies which processor exception to hook.                       \r
+                                \r
+  @retval EFI_SUCCESS           The function completed successfully.  \r
+  @retval EFI_ALREADY_STARTED   Non-NULL PeriodicCallback parameter when a callback\r
+                                function was previously registered.                \r
+  @retval EFI_OUT_OF_RESOURCES  System has insufficient memory resources to register new callback                               \r
+                                function.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -435,14 +441,16 @@ RegisterExceptionCallback (
 }\r
 \r
 /**\r
-  DebugSupport protocol member function.  Calls assembly routine to flush cache.\r
-\r
-  @param  This              The DebugSupport instance\r
-  @param  ProcessorIndex    Which processor the callback applies to.\r
-  @param  Start             Physical base of the memory range to be invalidated\r
-  @param  Length            mininum number of bytes in instruction cache to invalidate\r
-\r
-  @retval EFI_SUCCESS       Always returned.\r
+  Invalidates processor instruction cache for a memory range. Subsequent execution in this range\r
+  causes a fresh memory fetch to retrieve code to be executed.                                  \r
+    \r
+  @param  This                  A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.\r
+  @param  ProcessorIndex        Specifies which processor's instruction cache is to be invalidated.\r
+  @param  Start                 Specifies the physical base of the memory range to be invalidated.                                \r
+  @param  Length                Specifies the minimum number of bytes in the processor's instruction\r
+                                cache to invalidate.                                                 \r
+                                \r
+  @retval EFI_SUCCESS           Always returned.\r
 \r
 **/\r
 EFI_STATUS\r
index e1e34a449caac6e47615b955d31fa1a64d1f72c6..9d556a17fe95f1418faa3a954d08008593d41e7c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
-  IPF specific debugsupport types, macros, and definitions.\r
+  IPF specific types, macros, and definitions for Debug Support Driver.\r
   \r
-Copyright (c) 2004 - 2006 Intel Corporation                                                         \r
+Copyright (c) 2004 - 2008, 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
@@ -50,7 +50,9 @@ PlInitializeDebugSupportDriver (
 \r
 /**\r
   Unload handler that is called during UnloadImage() - deallocates pool memory\r
-  used by the driver.  Must be public because it's referenced from DebugSuport.c\r
+  used by the driver. \r
+\r
+  Must be public because it's referenced from DebugSuport.c\r
 \r
   @param  ImageHandle    The firmware allocated handle for the EFI image.\r
 \r
@@ -75,7 +77,7 @@ GetIva (
   );\r
 \r
 /**\r
-  HookStub will be copied from it's loaded location into the IVT when\r
+  C callable function that HookStub will be copied from it's loaded location into the IVT when\r
   an IVT entry is hooked.\r
 \r
 **/\r
@@ -85,7 +87,7 @@ HookStub (
   );\r
 \r
 /**\r
-  Chains an interrupt handler.\r
+  C callable function to chain an interrupt handler.\r
 \r
 **/\r
 VOID\r
@@ -94,7 +96,7 @@ ChainHandler (
   );\r
 \r
 /**\r
-  Unchains an interrupt handler.\r
+  C callable function to unchain an interrupt handler.\r
 \r
 **/\r
 VOID\r
@@ -129,13 +131,16 @@ InstructionCacheFlush (
   );\r
 \r
 /**\r
-  This is a DebugSupport protocol member function, hard\r
-  coded to support only 1 processor for now.\r
-\r
-  @param  This                The DebugSupport instance\r
-  @param  MaxProcessorIndex   The maximuim supported processor index\r
+  Returns the maximum value that may be used for the ProcessorIndex parameter in\r
+  RegisterPeriodicCallback() and RegisterExceptionCallback().                   \r
+    \r
+  Hard coded to support only 1 processor for now.\r
 \r
-  @retval EFI_SUCCESS         Always returned with **MaxProcessorIndex set to 0.\r
+  @param  This                  A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.\r
+  @param  MaxProcessorIndex     Pointer to a caller-allocated UINTN in which the maximum supported\r
+                                processor index is returned. Always 0 returned.                                     \r
+                                \r
+  @retval EFI_SUCCESS           Always returned with **MaxProcessorIndex set to 0.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -146,15 +151,18 @@ GetMaximumProcessorIndex (
   );\r
 \r
 /**\r
-  DebugSupport protocol member function.\r
-\r
-  @param  This               The DebugSupport instance\r
-  @param  ProcessorIndex     Which processor the callback applies to.\r
-  @param  PeriodicCallback   Callback function\r
-\r
-  @retval EFI_SUCCESS        Indicates the callback was registered.\r
-  @retval others             Callback was not registered.\r
-\r
+  Registers a function to be called back periodically in interrupt context.\r
+    \r
+  @param  This                  A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.\r
+  @param  ProcessorIndex        Specifies which processor the callback function applies to.\r
+  @param  PeriodicCallback      A pointer to a function of type PERIODIC_CALLBACK that is the main\r
+                                periodic entry point of the debug agent.\r
+                                \r
+  @retval EFI_SUCCESS           The function completed successfully.  \r
+  @retval EFI_ALREADY_STARTED   Non-NULL PeriodicCallback parameter when a callback\r
+                                function was previously registered.                \r
+  @retval EFI_OUT_OF_RESOURCES  System has insufficient memory resources to register new callback                               \r
+                                function. \r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -165,16 +173,21 @@ RegisterPeriodicCallback (
   );\r
 \r
 /**\r
-  DebugSupport protocol member function.\r
-\r
-  @param  This              The DebugSupport instance\r
-  @param  ProcessorIndex    Which processor the callback applies to.\r
-  @param  NewCallback       Callback function\r
-  @param  ExceptionType     Which exception to hook\r
-\r
-  @retval EFI_SUCCESS        Indicates the callback was registered.\r
-  @retval others             Callback was not registered.\r
-\r
+  Registers a function to be called when a given processor exception occurs.\r
+\r
+  This code executes in boot services context.\r
+    \r
+  @param  This                  A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.\r
+  @param  ProcessorIndex        Specifies which processor the callback function applies to.\r
+  @param  ExceptionCallback     A pointer to a function of type EXCEPTION_CALLBACK that is called\r
+                                when the processor exception specified by ExceptionType occurs.  \r
+  @param  ExceptionType         Specifies which processor exception to hook.                       \r
+                                \r
+  @retval EFI_SUCCESS           The function completed successfully.  \r
+  @retval EFI_ALREADY_STARTED   Non-NULL PeriodicCallback parameter when a callback\r
+                                function was previously registered.                \r
+  @retval EFI_OUT_OF_RESOURCES  System has insufficient memory resources to register new callback                               \r
+                                function.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -186,14 +199,16 @@ RegisterExceptionCallback (
   );\r
 \r
 /**\r
-  DebugSupport protocol member function.  Calls assembly routine to flush cache.\r
-\r
-  @param  This              The DebugSupport instance\r
-  @param  ProcessorIndex    Which processor the callback applies to.\r
-  @param  Start             Physical base of the memory range to be invalidated\r
-  @param  Length            mininum number of bytes in instruction cache to invalidate\r
-\r
-  @retval EFI_SUCCESS       Always returned.\r
+  Invalidates processor instruction cache for a memory range. Subsequent execution in this range\r
+  causes a fresh memory fetch to retrieve code to be executed.                                  \r
+    \r
+  @param  This                  A pointer to the EFI_DEBUG_SUPPORT_PROTOCOL instance.\r
+  @param  ProcessorIndex        Specifies which processor's instruction cache is to be invalidated.\r
+  @param  Start                 Specifies the physical base of the memory range to be invalidated.                                \r
+  @param  Length                Specifies the minimum number of bytes in the processor's instruction\r
+                                cache to invalidate.                                                 \r
+                                \r
+  @retval EFI_SUCCESS           Always returned.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -207,10 +222,12 @@ InvalidateInstructionCache (
 \r
 /**\r
   C routine that is called for all registered exceptions.  This is the main\r
-  exception dispatcher.  Must be public because it's referenced from AsmFuncs.s.\r
+  exception dispatcher. \r
+\r
+  Must be public because it's referenced from AsmFuncs.s.\r
 \r
-  @param  ExceptionType        Exception Type\r
-  @param  Context              System Context\r
+  @param  ExceptionType        Specifies which processor exception.\r
+  @param  Context              System Context.\r
 **/\r
 VOID\r
 CommonHandler (\r
@@ -221,12 +238,11 @@ CommonHandler (
 /**\r
   This is the worker function that uninstalls and removes all handlers.\r
 \r
-  @param  ExceptionType     Exception Type\r
-  @param  NewBundles        New Boundles\r
-  @param  NewCallback       New Callback\r
+  @param  ExceptionType     Specifies which processor exception.\r
+  @param  NewBundles        New Boundles.\r
+  @param  NewCallback       A pointer to the new function to be registered.\r
 \r
   @retval EFI_ALEADY_STARTED Ivt already hooked.\r
-  @retval others             Indicates the request was not satisfied.\r
   @retval EFI_SUCCESS        Successfully uninstalled.\r
 \r
 **/\r
@@ -241,9 +257,9 @@ ManageIvtEntryTable (
   Saves original IVT contents and inserts a few new bundles which are fixed up\r
   to store the ExceptionType and then call the common handler.\r
 \r
-  @param  ExceptionType      Exception Type\r
-  @param  NewBundles         New Boundles\r
-  @param  NewCallback        New Callback\r
+  @param  ExceptionType      Specifies which processor exception.\r
+  @param  NewBundles         New Boundles.\r
+  @param  NewCallback        A pointer to the new function to be hooked.\r
 \r
 **/\r
 VOID\r
@@ -256,7 +272,7 @@ HookEntry (
 /**\r
   Restores original IVT contents when unregistering a callback function.\r
 \r
-  @param  ExceptionType     Exception Type\r
+  @param  ExceptionType     Specifies which processor exception.\r
 \r
 **/\r
 VOID\r
@@ -269,7 +285,7 @@ UnhookEntry (
 \r
   Records new callback in IvtEntryTable.\r
 \r
-  @param  NewCallback     New Callback.\r
+  @param  NewCallback     A pointer to the interrupt handle.\r
 \r
 **/\r
 VOID\r
index 864b6e41127126ecb887763668bbfa90dd9df8d3..7ac8a1a69ac2764d351cd5239da6dbaf1619089f 100644 (file)
@@ -14,7 +14,6 @@
 \r
 .intel_syntax noprefix\r
 \r
-\r
 .globl ASM_PFX(OrigVector)\r
 .globl ASM_PFX(InterruptEntryStub)\r
 .globl ASM_PFX(StubSize)\r
@@ -146,8 +145,6 @@ ASM_PFX(InterruptEntryStub):
 .globl ASM_PFX(InterruptEntryStubEnd)\r
 ASM_PFX(InterruptEntryStubEnd):\r
 \r
-        ret\r
-\r
 #------------------------------------------------------------------------------\r
 # CommonIdtEntry\r
 #\r
@@ -199,9 +196,6 @@ ASM_PFX(InterruptEntryStubEnd):
 ##   UINT64            R8, R9, R10, R11, R12, R13, R14, R15;\r
 ## } SYSTEM_CONTEXT_X64;  // 64\r
 ASM_PFX(CommonIdtEntry):\r
-\r
-        ret\r
-\r
 ## NOTE: we save rsp here to prevent compiler put rip reference cause error AppRsp\r
                 push    rax\r
                 mov     rax, qword ptr [rsp][8]          # save vector number\r
@@ -274,9 +268,10 @@ ExtraPushDone:
                 mov     rax, ASM_PFX(AppRsp)\r
                 add     rax, 40\r
                 # application stack has ss, rsp, rflags, cs, & rip, so\r
-                # last actual application stack entry is\r
-                # 40 bytes into the application stack.\r
+                # last actual application stack entry is 40 bytes\r
+                # into the application stack.\r
                 mov     [rsp + 24], rax\r
+\r
 ## continue building context record\r
 ## UINT64  Gs, Fs, Es, Ds, Cs, Ss;  insure high 16 bits of each is zero\r
                 mov     rax, ss\r
@@ -361,14 +356,14 @@ ExtraPushDone:
                 # IMPORTANT!! The debug stack has been carefully constructed to\r
                 # insure that rsp and rdi are 16 byte aligned when we get here.\r
                 # They MUST be.  If they are not, a GP fault will occur.\r
-           #     FXSTOR_RDI\r
-               .byte       0x0f\r
-               .byte       0xae\r
-               .byte       0x07\r
+          \r
+                #     FXSTOR_RDI\r
+                fxsave      [rdi]\r
 \r
 ## UINT64  ExceptionData;\r
                 mov     rax, ASM_PFX(ExceptData)\r
                 push    rax\r
+\r
 # call to C code which will in turn call registered handler\r
 # pass in the vector number\r
                 mov     rdx, rsp\r
@@ -379,14 +374,16 @@ ExtraPushDone:
 # restore context...\r
 ## UINT64  ExceptionData;\r
                 add     rsp, 8\r
+\r
 ## FX_SAVE_STATE_X64 FxSaveState;\r
                 mov     rsi, rsp\r
-            #    FXRSTOR_RSI\r
-               .byte       0x0f\r
-               .byte       0xae\r
-               .byte       0x0e\r
+            \r
+                #    FXRSTOR_RSI\r
+                fxrstor     [rsi]\r
+\r
                 add     rsp, 512\r
-;; UINT64  Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
+\r
+## UINT64  Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
                 pop     rax\r
                 mov     dr0, rax\r
                 pop     rax\r
@@ -395,10 +392,12 @@ ExtraPushDone:
                 mov     dr2, rax\r
                 pop     rax\r
                 mov     dr3, rax\r
+\r
 ## skip restore of dr6.  We cleared dr6 during the context save.\r
                 add     rsp, 8\r
                 pop     rax\r
                 mov     dr7, rax\r
+\r
 ## UINT64  Cr0, Cr1, Cr2, Cr3, Cr4, Cr8;\r
                 pop     rax\r
                 mov     cr0, rax\r
index d9ba0be1910654e24f4b019ae2b63cebc1a0624e..6b047066ca3d0b0295b0895e271d5f91ac8c09bd 100644 (file)
@@ -1,7 +1,7 @@
 ;/** @file\r
 ;  Low level x64 routines used by the debug support driver.\r
 ;\r
-;  Copyright (c) 2007 - 2008, Intel Corporation. <BR>\r
+;  Copyright (c) 2007 - 2008, 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
index d6173bb12f3fa5588403d4bccbc983cac6ceb490..3143bafee734a990960999ab904c6a1efb27ef7c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
-  X64 specific debug support functions\r
+  X64 specific functions to support Debug Support protocol.\r
 \r
-Copyright (c) 2006 - 2007, Intel Corporation\r
+Copyright (c) 2008, 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
@@ -103,7 +103,7 @@ CreateEntryStub (
 **/\r
 EFI_STATUS\r
 ManageIdtEntryTable (\r
-  VOID (*NewCallback)(),\r
+  VOID               (*NewCallback)(),\r
   EFI_EXCEPTION_TYPE ExceptionType\r
   )\r
 {\r