]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add X64 support for DebugSupport driver.
authorklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 7 Dec 2006 08:31:19 +0000 (08:31 +0000)
committerklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 7 Dec 2006 08:31:19 +0000 (08:31 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2067 6f19259b-4bc3-4df7-8a09-765794883524

EdkModulePkg/EdkModulePkg.fpd
EdkModulePkg/Universal/DebugSupport/Dxe/DebugSupport.msa
EdkModulePkg/Universal/DebugSupport/Dxe/Ia32/AsmFuncs.asm
EdkModulePkg/Universal/DebugSupport/Dxe/Ia32/plDebugSupport.c
EdkModulePkg/Universal/DebugSupport/Dxe/Ia32/plDebugSupport.h
EdkModulePkg/Universal/DebugSupport/Dxe/ipf/plDebugSupport.c
EdkModulePkg/Universal/DebugSupport/Dxe/ipf/plDebugSupport.h [new file with mode: 0644]
EdkModulePkg/Universal/DebugSupport/Dxe/x64/AsmFuncs.asm [new file with mode: 0644]
EdkModulePkg/Universal/DebugSupport/Dxe/x64/plDebugSupport.c [new file with mode: 0644]
EdkModulePkg/Universal/DebugSupport/Dxe/x64/plDebugSupport.h [new file with mode: 0644]

index fe5201a58a89bba16a878660b6b637192cb548f7..78c46fd05477a43983bd190252e97220c054291c 100644 (file)
         <FfsFormatKey>BS_DRIVER</FfsFormatKey>\r
       </ModuleSaBuildOptions>\r
     </ModuleSA>\r
+    <ModuleSA SupArchList="X64" PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d" ModuleGuid="911D584C-35F7-4955-BEF9-B452769DDC3A">\r
+      <Libraries>\r
+        <Instance ModuleGuid="ff5c7a2c-ab7a-4366-8616-11c6e53247b6" PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+        <Instance ModuleGuid="27d67720-ea68-48ae-93da-a3a074c90e30" PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+        <Instance ModuleGuid="f1bbe03d-2f28-4dee-bec7-d98d7a30c36a" PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+        <Instance ModuleGuid="331deb15-454b-48d8-9b74-70d01f3f3556" PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+        <Instance ModuleGuid="3ddc3b12-99ea-4364-b315-6310a2050be5" PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+        <Instance ModuleGuid="bda39d3a-451b-4350-8266-81ab10fa0523" PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+        <Instance ModuleGuid="4674739d-3195-4fb2-8094-ac1d22d00194" PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+      </Libraries>\r
+      <PcdBuildDefinition>\r
+        <PcdData ItemType="FIXED_AT_BUILD">\r
+          <C_Name>PcdMaximumUnicodeStringLength</C_Name>\r
+          <Token>0x00000001</Token>\r
+          <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+          <DatumType>UINT32</DatumType>\r
+          <MaxDatumSize>4</MaxDatumSize>\r
+          <Value>1000000</Value>\r
+        </PcdData>\r
+        <PcdData ItemType="FIXED_AT_BUILD">\r
+          <C_Name>PcdMaximumAsciiStringLength</C_Name>\r
+          <Token>0x00000002</Token>\r
+          <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+          <DatumType>UINT32</DatumType>\r
+          <MaxDatumSize>4</MaxDatumSize>\r
+          <Value>1000000</Value>\r
+        </PcdData>\r
+        <PcdData ItemType="FIXED_AT_BUILD">\r
+          <C_Name>PcdMaximumLinkedListLength</C_Name>\r
+          <Token>0x00000003</Token>\r
+          <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+          <DatumType>UINT32</DatumType>\r
+          <MaxDatumSize>4</MaxDatumSize>\r
+          <Value>1000000</Value>\r
+        </PcdData>\r
+        <PcdData ItemType="FIXED_AT_BUILD">\r
+          <C_Name>PcdSpinLockTimeout</C_Name>\r
+          <Token>0x00000004</Token>\r
+          <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+          <DatumType>UINT32</DatumType>\r
+          <MaxDatumSize>4</MaxDatumSize>\r
+          <Value>10000000</Value>\r
+        </PcdData>\r
+        <PcdData ItemType="FIXED_AT_BUILD">\r
+          <C_Name>PcdReportStatusCodePropertyMask</C_Name>\r
+          <Token>0x00000007</Token>\r
+          <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+          <DatumType>UINT8</DatumType>\r
+          <MaxDatumSize>1</MaxDatumSize>\r
+          <Value>0x06</Value>\r
+        </PcdData>\r
+        <PcdData ItemType="FIXED_AT_BUILD">\r
+          <C_Name>PcdDebugPropertyMask</C_Name>\r
+          <Token>0x00000005</Token>\r
+          <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+          <DatumType>UINT8</DatumType>\r
+          <MaxDatumSize>1</MaxDatumSize>\r
+          <Value>0x0f</Value>\r
+        </PcdData>\r
+        <PcdData ItemType="FIXED_AT_BUILD">\r
+          <C_Name>PcdDebugClearMemoryValue</C_Name>\r
+          <Token>0x00000008</Token>\r
+          <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+          <DatumType>UINT8</DatumType>\r
+          <MaxDatumSize>1</MaxDatumSize>\r
+          <Value>0xAF</Value>\r
+        </PcdData>\r
+        <PcdData ItemType="FIXED_AT_BUILD">\r
+          <C_Name>PcdDebugPrintErrorLevel</C_Name>\r
+          <Token>0x00000006</Token>\r
+          <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+          <DatumType>UINT32</DatumType>\r
+          <MaxDatumSize>4</MaxDatumSize>\r
+          <Value>0x80000000</Value>\r
+        </PcdData>\r
+      </PcdBuildDefinition>\r
+      <ModuleSaBuildOptions>\r
+        <FvBinding>NULL</FvBinding>\r
+        <FfsFormatKey>BS_DRIVER</FfsFormatKey>\r
+      </ModuleSaBuildOptions>\r
+    </ModuleSA>\r
+    <ModuleSA SupArchList="IPF" PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d" ModuleGuid="911D584C-35F7-4955-BEF9-B452769DDC3A">\r
+      <Libraries>\r
+        <Instance ModuleGuid="ff5c7a2c-ab7a-4366-8616-11c6e53247b6" PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+        <Instance ModuleGuid="27d67720-ea68-48ae-93da-a3a074c90e30" PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+        <Instance ModuleGuid="f1bbe03d-2f28-4dee-bec7-d98d7a30c36a" PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+        <Instance ModuleGuid="331deb15-454b-48d8-9b74-70d01f3f3556" PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+        <Instance ModuleGuid="3ddc3b12-99ea-4364-b315-6310a2050be5" PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+        <Instance ModuleGuid="bda39d3a-451b-4350-8266-81ab10fa0523" PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+        <Instance ModuleGuid="4674739d-3195-4fb2-8094-ac1d22d00194" PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+      </Libraries>\r
+      <PcdBuildDefinition>\r
+        <PcdData ItemType="FIXED_AT_BUILD">\r
+          <C_Name>PcdMaximumUnicodeStringLength</C_Name>\r
+          <Token>0x00000001</Token>\r
+          <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+          <DatumType>UINT32</DatumType>\r
+          <MaxDatumSize>4</MaxDatumSize>\r
+          <Value>1000000</Value>\r
+        </PcdData>\r
+        <PcdData ItemType="FIXED_AT_BUILD">\r
+          <C_Name>PcdMaximumAsciiStringLength</C_Name>\r
+          <Token>0x00000002</Token>\r
+          <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+          <DatumType>UINT32</DatumType>\r
+          <MaxDatumSize>4</MaxDatumSize>\r
+          <Value>1000000</Value>\r
+        </PcdData>\r
+        <PcdData ItemType="FIXED_AT_BUILD">\r
+          <C_Name>PcdMaximumLinkedListLength</C_Name>\r
+          <Token>0x00000003</Token>\r
+          <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+          <DatumType>UINT32</DatumType>\r
+          <MaxDatumSize>4</MaxDatumSize>\r
+          <Value>1000000</Value>\r
+        </PcdData>\r
+        <PcdData ItemType="FIXED_AT_BUILD">\r
+          <C_Name>PcdSpinLockTimeout</C_Name>\r
+          <Token>0x00000004</Token>\r
+          <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+          <DatumType>UINT32</DatumType>\r
+          <MaxDatumSize>4</MaxDatumSize>\r
+          <Value>10000000</Value>\r
+        </PcdData>\r
+        <PcdData ItemType="FIXED_AT_BUILD">\r
+          <C_Name>PcdReportStatusCodePropertyMask</C_Name>\r
+          <Token>0x00000007</Token>\r
+          <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+          <DatumType>UINT8</DatumType>\r
+          <MaxDatumSize>1</MaxDatumSize>\r
+          <Value>0x06</Value>\r
+        </PcdData>\r
+        <PcdData ItemType="FIXED_AT_BUILD">\r
+          <C_Name>PcdDebugPropertyMask</C_Name>\r
+          <Token>0x00000005</Token>\r
+          <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+          <DatumType>UINT8</DatumType>\r
+          <MaxDatumSize>1</MaxDatumSize>\r
+          <Value>0x0f</Value>\r
+        </PcdData>\r
+        <PcdData ItemType="FIXED_AT_BUILD">\r
+          <C_Name>PcdDebugClearMemoryValue</C_Name>\r
+          <Token>0x00000008</Token>\r
+          <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+          <DatumType>UINT8</DatumType>\r
+          <MaxDatumSize>1</MaxDatumSize>\r
+          <Value>0xAF</Value>\r
+        </PcdData>\r
+        <PcdData ItemType="FIXED_AT_BUILD">\r
+          <C_Name>PcdDebugPrintErrorLevel</C_Name>\r
+          <Token>0x00000006</Token>\r
+          <TokenSpaceGuidCName>gEfiMdePkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+          <DatumType>UINT32</DatumType>\r
+          <MaxDatumSize>4</MaxDatumSize>\r
+          <Value>0x80000000</Value>\r
+        </PcdData>\r
+      </PcdBuildDefinition>\r
+      <ModuleSaBuildOptions>\r
+        <FvBinding>NULL</FvBinding>\r
+        <FfsFormatKey>BS_DRIVER</FfsFormatKey>\r
+      </ModuleSaBuildOptions>\r
+    </ModuleSA>\r
     <ModuleSA SupArchList="IA32" PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d" ModuleGuid="9E863906-A40F-4875-977F-5B93FF237FC6">\r
       <Libraries>\r
         <Instance ModuleGuid="ff5c7a2c-ab7a-4366-8616-11c6e53247b6" PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
index 70b6bf2ca0737092fb74523ee297d45658e77b10..fd6da0e20d08f9223237f677c0cc3e145b6d69a1 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>\r
-<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
   <MsaHeader>\r
     <ModuleName>DebugSupport</ModuleName>\r
     <ModuleType>DXE_DRIVER</ModuleType>\r
@@ -8,11 +8,11 @@
     <Abstract>Component description file for DebugSupport module.</Abstract>\r
     <Description>This driver installs DebugSupport protocol for the selected processor.</Description>\r
     <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
-    <License>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
-      THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+    <License>All rights reserved. This program and the accompanying materials
+      are licensed and made available under the terms and conditions of the BSD License
+      which accompanies this distribution.  The full text of the license may be found at
+      http://opensource.org/licenses/bsd-license.php
+      THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
       WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
     <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
   </MsaHeader>\r
@@ -37,6 +37,9 @@
     <LibraryClass Usage="ALWAYS_CONSUMED">\r
       <Keyword>UefiBootServicesTableLib</Keyword>\r
     </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED" SupArchList="IA32 X64 IPF EBC">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
   </LibraryClassDefinitions>\r
   <SourceFiles>\r
     <Filename>DebugSupport.c</Filename>\r
     <Filename SupArchList="IPF">ipf/common.i</Filename>\r
     <Filename SupArchList="IPF">ipf/ds64macros.i</Filename>\r
     <Filename SupArchList="IPF">ipf/plDebugSupport.c</Filename>\r
+    <Filename SupArchList="IPF">ipf/plDebugSupport.h</Filename>\r
+    <Filename SupArchList="X64">x64/AsmFuncs.asm</Filename>\r
+    <Filename SupArchList="X64">x64/plDebugSupport.h</Filename>\r
+    <Filename SupArchList="X64">x64/plDebugSupport.c</Filename>\r
   </SourceFiles>\r
   <PackageDependencies>\r
     <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
@@ -69,4 +76,4 @@
       <ModuleEntryPoint>InitializeDebugSupportDriver</ModuleEntryPoint>\r
     </Extern>\r
   </Externs>\r
-</ModuleSurfaceArea>\r
+</ModuleSurfaceArea>
\ No newline at end of file
index 1741ce83c07d1a1355c4c2dc8e1394b44c00a963..6dd114ba754bc929c9f41dfd8329585c051504d1 100644 (file)
@@ -79,16 +79,16 @@ OrigVector      dd      66666666h ; ?
 ;;\r
 ;; For reference, the context structure looks like this:\r
 ;;      struct {\r
-;;        UINT32        ExceptionData;\r
-;;        FX_SAVE_STATE FxSaveState;    // 512 bytes, must be 16 byte aligned\r
-;;        UINT32        Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
-;;        UINT32        Cr0, Cr1, Cr2, Cr3, Cr4;\r
-;;        UINT32        Ldtr, Tr;\r
-;;        UINT64        Gdtr, Idtr;\r
-;;        UINT32        EFlags;\r
-;;        UINT32        Eip;\r
-;;        UINT32        SegGs, SegFs, SegEs, SegDs, SegCs, SegSs;\r
-;;        UINT32        Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;\r
+;;        UINT32             ExceptionData;\r
+;;        FX_SAVE_STATE_IA32 FxSaveState;    // 512 bytes, must be 16 byte aligned\r
+;;        UINT32             Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
+;;        UINT32             Cr0, Cr1, 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
 \r
@@ -208,11 +208,11 @@ Vect2Desc       ENDP
 ;               copied and fixed up once for each IDT entry that is hooked.\r
 ;\r
 InterruptEntryStub::\r
-                mov     AppEsp, esp             ; save stack top\r
+                mov     AppEsp, esp                  ; save stack top\r
                 mov     esp, offset DebugStackBegin  ; switch to debugger stack\r
-                push    0                       ; push vector number - will be modified before installed\r
-                db      0e9h                    ; jump rel32\r
-                dd      0                       ; fixed up to relative address of CommonIdtEntry\r
+                push    0                            ; push vector number - will be modified before installed\r
+                db      0e9h                         ; jump rel32\r
+                dd      0                            ; fixed up to relative address of CommonIdtEntry\r
 InterruptEntryStubEnd:\r
 \r
 \r
@@ -251,16 +251,16 @@ CommonIdtEntry::
 ;;\r
 ;; typedef\r
 ;; struct {\r
-;;   UINT32        ExceptionData;\r
-;;   FX_SAVE_STATE FxSaveState;\r
-;;   UINT32        Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
-;;   UINT32        Cr0, Cr2, Cr3, Cr4;\r
-;;   UINT32        Ldtr, Tr;\r
-;;   UINT64        Gdtr, Idtr;\r
-;;   UINT32        EFlags;\r
-;;   UINT32        Eip;\r
-;;   UINT32        SegGs, SegFs, SegEs, SegDs, SegCs, SegSs;\r
-;;   UINT32        Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;\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
@@ -340,7 +340,7 @@ CommonIdtEntry::
                 mov     eax, AppEsp\r
                 push    dword ptr [eax]\r
 \r
-;; UINT64  Gdtr, Idtr;\r
+;; UINT32  Gdtr[2], Idtr[2];\r
                 push    0\r
                 push    0\r
                 sidt    fword ptr [esp]\r
@@ -397,7 +397,7 @@ CommonIdtEntry::
                 mov     eax, dr0\r
                 push    eax\r
 \r
-;; FX_SAVE_STATE FxSaveState;\r
+;; FX_SAVE_STATE_IA32 FxSaveState;\r
                 sub     esp, 512\r
                 mov     edi, esp\r
                 ; IMPORTANT!! The debug stack has been carefully constructed to\r
@@ -422,7 +422,7 @@ CommonIdtEntry::
 ;; UINT32  ExceptionData;\r
                 add     esp, 4\r
 \r
-;; FX_SAVE_STATE FxSaveState;\r
+;; FX_SAVE_STATE_IA32 FxSaveState;\r
                 mov     esi, esp\r
                 FXRSTOR_ESI\r
                 add     esp, 512\r
@@ -456,8 +456,8 @@ CommonIdtEntry::
                 mov     eax, AppEsp\r
                 pop     dword ptr [eax + 8]\r
 \r
-;; UINT16  Ldtr, Tr;\r
-;; UINT64  Gdtr, Idtr;\r
+;; UINT32  Ldtr, Tr;\r
+;; UINT32  Gdtr[2], Idtr[2];\r
 ;; Best not let anyone mess with these particular registers...\r
                 add     esp, 24\r
 \r
@@ -478,7 +478,7 @@ CommonIdtEntry::
                 pop     ss\r
 \r
 ;; The next stuff to restore is the general purpose registers that were pushed\r
-;; using the pushad instruction.\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
@@ -505,7 +505,7 @@ CommonIdtEntry::
                 mov     AppEsp, eax\r
 NoAppStackMove:\r
                 mov     eax, DebugEsp    ; restore the DebugEsp on the debug stack\r
-                                         ; so our popad will not cause a stack switch\r
+                                         ; so our "popad" will not cause a stack switch\r
                 mov     [esp + 12], eax\r
 \r
                 cmp     ExceptionNumber, 068h\r
index 2198192a0402cd0de8086b78b0312ca83bb8efcd..289158216cbd403703a64dc7a9d8722017446808 100644 (file)
@@ -1,6 +1,7 @@
-/*++\r
-\r
-Copyright (c) 2006, Intel Corporation                                                         \r
+/**@file\r
+  IA32 specific debug support functions\r
+  \r
+Copyright (c) 2006 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
@@ -9,17 +10,7 @@ http://opensource.org/licenses/bsd-license.php
 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
-    plDebugSupport.c\r
-\r
-Abstract:\r
-\r
-    IA32 specific debug support functions\r
-\r
-Revision History\r
-\r
---*/\r
+**/\r
 \r
 //\r
 // private header files\r
@@ -117,7 +108,6 @@ Returns:
   Other possibilities are passed through by CreateEntryStub\r
 \r
 --*/\r
-// TODO:    ) - add argument and description to function comment\r
 {\r
   BOOLEAN     OldIntFlagState;\r
   EFI_STATUS  Status;\r
@@ -199,7 +189,6 @@ Returns:
   Other possible return values are passed through from UnHookEntry and HookEntry.\r
 \r
 --*/\r
-// TODO:    ) - add argument and description to function comment\r
 {\r
   EFI_STATUS  Status;\r
 \r
@@ -246,12 +235,13 @@ GetMaximumProcessorIndex (
 Routine Description: This is a DebugSupport protocol member function.\r
 \r
 Arguments:\r
+  This              - The DebugSupport instance\r
+  MaxProcessorIndex - The maximuim supported processor index\r
 \r
-Returns: Always returns EFI_SUCCESS with *MaxProcessorIndex set to 0\r
+Returns:\r
+  Always returns EFI_SUCCESS with *MaxProcessorIndex set to 0\r
 \r
 --*/\r
-// TODO:    This - add argument and description to function comment\r
-// TODO:    MaxProcessorIndex - add argument and description to function comment\r
 {\r
   *MaxProcessorIndex = 0;\r
   return (EFI_SUCCESS);\r
@@ -269,13 +259,20 @@ RegisterPeriodicCallback (
 Routine Description: This is a DebugSupport protocol member function.\r
 \r
 Arguments:\r
+  This             - The DebugSupport instance\r
+  ProcessorIndex   - Which processor the callback applies to.\r
+  PeriodicCallback - Callback function\r
 \r
 Returns:\r
 \r
+  EFI_SUCCESS\r
+  EFI_INVALID_PARAMETER - requested uninstalling a handler from a vector that has\r
+                          no handler registered for it\r
+  EFI_ALREADY_STARTED   - requested install to a vector that already has a handler registered.\r
+\r
+  Other possible return values are passed through from UnHookEntry and HookEntry.\r
+\r
 --*/\r
-// TODO:    This - add argument and description to function comment\r
-// TODO:    ProcessorIndex - add argument and description to function comment\r
-// TODO:    PeriodicCallback - add argument and description to function comment\r
 {\r
   return ManageIdtEntryTable (PeriodicCallback, SYSTEM_TIMER_VECTOR);\r
 }\r
@@ -296,16 +293,21 @@ Routine Description:
   This code executes in boot services context.\r
 \r
 Arguments:\r
+  This             - The DebugSupport instance\r
+  ProcessorIndex   - Which processor the callback applies to.\r
+  NewCallback      - Callback function\r
+  ExceptionType    - Which exception to hook\r
 \r
 Returns:\r
 \r
-  None\r
+  EFI_SUCCESS\r
+  EFI_INVALID_PARAMETER - requested uninstalling a handler from a vector that has\r
+                          no handler registered for it\r
+  EFI_ALREADY_STARTED   - requested install to a vector that already has a handler registered.\r
+\r
+  Other possible return values are passed through from UnHookEntry and HookEntry.\r
 \r
 --*/\r
-// TODO:    This - add argument and description to function comment\r
-// TODO:    ProcessorIndex - add argument and description to function comment\r
-// TODO:    NewCallback - add argument and description to function comment\r
-// TODO:    ExceptionType - add argument and description to function comment\r
 {\r
   return ManageIdtEntryTable (NewCallback, ExceptionType);\r
 }\r
@@ -322,21 +324,21 @@ InvalidateInstructionCache (
 \r
 Routine Description:\r
   This is a DebugSupport protocol member function.\r
-  For IA32, this is a no-op since the instruction and data caches are coherent.\r
+  Calls assembly routine to flush cache.\r
 \r
 Arguments:\r
+  This             - The DebugSupport instance\r
+  ProcessorIndex   - Which processor the callback applies to.\r
+  Start            - Physical base of the memory range to be invalidated\r
+  Length           - mininum number of bytes in instruction cache to invalidate\r
 \r
 Returns:\r
 \r
-  None\r
+  EFI_SUCCESS - always return success\r
 \r
 --*/\r
-// TODO:    This - add argument and description to function comment\r
-// TODO:    ProcessorIndex - add argument and description to function comment\r
-// TODO:    Start - add argument and description to function comment\r
-// TODO:    Length - add argument and description to function comment\r
-// TODO:    EFI_SUCCESS - add return value to function comment\r
 {\r
+  AsmWbinvd ();\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -358,9 +360,9 @@ Returns:
   EFI_SUCCESS\r
   EFI_UNSUPPORTED - if IA32 processor does not support FXSTOR/FXRSTOR instructions,\r
                     the context save will fail, so these processor's are not supported.\r
+  EFI_OUT_OF_RESOURCES - not resource to finish initialization\r
 \r
 --*/\r
-// TODO:    EFI_OUT_OF_RESOURCES - add return value to function comment\r
 {\r
   if (!FxStorSupport ()) {\r
     return EFI_UNSUPPORTED;\r
@@ -393,10 +395,9 @@ Arguments:
 \r
 Returns:\r
 \r
-  None\r
+  EFI_SUCCESS - always return success\r
 \r
 --*/\r
-// TODO:    EFI_SUCCESS - add return value to function comment\r
 {\r
   EFI_EXCEPTION_TYPE  ExceptionType;\r
 \r
@@ -420,14 +421,14 @@ Routine Description: Common piece of code that invokes the registered handlers.
   This code executes in exception context so no efi calls are allowed.\r
 \r
 Arguments:\r
+  ExceptionType - exception type\r
+  ContextRecord - system context\r
 \r
 Returns:\r
 \r
   None\r
 \r
 --*/\r
-// TODO:    ExceptionType - add argument and description to function comment\r
-// TODO:    ContextRecord - add argument and description to function comment\r
 {\r
   if (IdtEntryTable[ExceptionType].RegisteredCallback != NULL) {\r
     if (ExceptionType != SYSTEM_TIMER_VECTOR) {\r
index abb6967deabd2e9f989b15510a2e935947403182..cb1a6c7c82344c6c8f5fc774047cd2d8dcb4a9a6 100644 (file)
@@ -1,4 +1,5 @@
-/*++\r
+/**@file\r
+  IA32 specific debug support macros, typedefs and prototypes.\r
 \r
 Copyright (c) 2006, Intel Corporation                                                         \r
 All rights reserved. This program and the accompanying materials                          \r
@@ -9,17 +10,7 @@ http://opensource.org/licenses/bsd-license.php
 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
-    plDebugSupport.h\r
-\r
-Abstract:\r
-\r
-    IA32 specific debug support macros, typedefs and prototypes.\r
-\r
-Revision History\r
-\r
---*/\r
+**/\r
 \r
 #ifndef _PLDEBUG_SUPPORT_H\r
 #define _PLDEBUG_SUPPORT_H\r
@@ -58,7 +49,7 @@ CommonIdtEntry (
 \r
 Routine Description:\r
 \r
-  TODO: Add function description\r
+  Generic IDT entry\r
 \r
 Arguments:\r
 \r
@@ -66,11 +57,12 @@ Arguments:
 \r
 Returns:\r
 \r
-  TODO: add return values\r
+  None\r
 \r
 --*/\r
 ;\r
 \r
+\r
 BOOLEAN\r
 FxStorSupport (\r
   VOID\r
@@ -79,7 +71,7 @@ FxStorSupport (
 \r
 Routine Description:\r
 \r
-  TODO: Add function description\r
+  Check whether FXSTOR is supported\r
 \r
 Arguments:\r
 \r
@@ -87,7 +79,8 @@ Arguments:
 \r
 Returns:\r
 \r
-  TODO: add return values\r
+  TRUE  - supported\r
+  FALSE - not supported\r
 \r
 --*/\r
 ;\r
@@ -100,7 +93,7 @@ GetIdtr (
 \r
 Routine Description:\r
 \r
-  TODO: Add function description\r
+  Return the physical address of IDTR\r
 \r
 Arguments:\r
 \r
@@ -108,7 +101,7 @@ Arguments:
 \r
 Returns:\r
 \r
-  TODO: add return values\r
+  The physical address of IDTR\r
 \r
 --*/\r
 ;\r
@@ -122,16 +115,16 @@ Vect2Desc (
 \r
 Routine Description:\r
 \r
-  TODO: Add function description\r
+  Encodes an IDT descriptor with the given physical address\r
 \r
 Arguments:\r
 \r
-  DestDesc  - TODO: add argument description\r
-  )         - TODO: add argument description\r
+  DestDesc  - The IDT descriptor address\r
+  Vector    - The interrupt vector entry\r
 \r
 Returns:\r
 \r
-  TODO: add return values\r
+  None\r
 \r
 --*/\r
 ;\r
@@ -144,15 +137,16 @@ WriteInterruptFlag (
 \r
 Routine Description:\r
 \r
-  TODO: Add function description\r
+  Programs interrupt flag to the requested state and returns previous\r
+  state.\r
 \r
 Arguments:\r
 \r
-  NewState  - TODO: add argument description\r
+  NewState  - New interrupt status\r
 \r
 Returns:\r
 \r
-  TODO: add return values\r
+  Old interrupt status\r
 \r
 --*/\r
 ;\r
@@ -164,16 +158,18 @@ plInitializeDebugSupportDriver (
 /*++\r
 \r
 Routine Description:\r
+  Initializes driver's handler registration database.\r
 \r
-  TODO: Add function description\r
+  This code executes in boot services context.\r
 \r
 Arguments:\r
-\r
   None\r
 \r
 Returns:\r
-\r
-  TODO: add return values\r
+  EFI_SUCCESS\r
+  EFI_UNSUPPORTED - if IA32 processor does not support FXSTOR/FXRSTOR instructions,\r
+                    the context save will fail, so these processor's are not supported.\r
+  EFI_OUT_OF_RESOURCES - not resource to finish initialization\r
 \r
 --*/\r
 ;\r
@@ -186,16 +182,18 @@ plUnloadDebugSupportDriver (
 /*++\r
 \r
 Routine Description:\r
+  This is the callback that is written to the LoadedImage protocol instance\r
+  on the image handle. It uninstalls all registered handlers and frees all entry\r
+  stub memory.\r
 \r
-  TODO: Add function description\r
+  This code executes in boot services context.\r
 \r
 Arguments:\r
-\r
-  ImageHandle - TODO: add argument description\r
+  ImageHandle - The image handle of the unload handler\r
 \r
 Returns:\r
 \r
-  TODO: add return values\r
+  EFI_SUCCESS - always return success\r
 \r
 --*/\r
 ;\r
@@ -211,18 +209,14 @@ GetMaximumProcessorIndex (
   )\r
 /*++\r
 \r
-Routine Description:\r
-\r
-  TODO: Add function description\r
+Routine Description: This is a DebugSupport protocol member function.\r
 \r
 Arguments:\r
-\r
-  This              - TODO: add argument description\r
-  MaxProcessorIndex - TODO: add argument description\r
+  This              - The DebugSupport instance\r
+  MaxProcessorIndex - The maximuim supported processor index\r
 \r
 Returns:\r
-\r
-  TODO: add return values\r
+  Always returns EFI_SUCCESS with *MaxProcessorIndex set to 0\r
 \r
 --*/\r
 ;\r
@@ -236,19 +230,21 @@ RegisterPeriodicCallback (
   )\r
 /*++\r
 \r
-Routine Description:\r
-\r
-  TODO: Add function description\r
+Routine Description: This is a DebugSupport protocol member function.\r
 \r
 Arguments:\r
-\r
-  This              - TODO: add argument description\r
-  ProcessorIndex    - TODO: add argument description\r
-  PeriodicCallback  - TODO: add argument description\r
+  This             - The DebugSupport instance\r
+  ProcessorIndex   - Which processor the callback applies to.\r
+  PeriodicCallback - Callback function\r
 \r
 Returns:\r
 \r
-  TODO: add return values\r
+  EFI_SUCCESS\r
+  EFI_INVALID_PARAMETER - requested uninstalling a handler from a vector that has\r
+                          no handler registered for it\r
+  EFI_ALREADY_STARTED   - requested install to a vector that already has a handler registered.\r
+\r
+  Other possible return values are passed through from UnHookEntry and HookEntry.\r
 \r
 --*/\r
 ;\r
@@ -264,19 +260,24 @@ RegisterExceptionCallback (
 /*++\r
 \r
 Routine Description:\r
+  This is a DebugSupport protocol member function.\r
 \r
-  TODO: Add function description\r
+  This code executes in boot services context.\r
 \r
 Arguments:\r
-\r
-  This            - TODO: add argument description\r
-  ProcessorIndex  - TODO: add argument description\r
-  NewCallback     - TODO: add argument description\r
-  ExceptionType   - TODO: add argument description\r
+  This             - The DebugSupport instance\r
+  ProcessorIndex   - Which processor the callback applies to.\r
+  NewCallback      - Callback function\r
+  ExceptionType    - Which exception to hook\r
 \r
 Returns:\r
 \r
-  TODO: add return values\r
+  EFI_SUCCESS\r
+  EFI_INVALID_PARAMETER - requested uninstalling a handler from a vector that has\r
+                          no handler registered for it\r
+  EFI_ALREADY_STARTED   - requested install to a vector that already has a handler registered.\r
+\r
+  Other possible return values are passed through from UnHookEntry and HookEntry.\r
 \r
 --*/\r
 ;\r
@@ -292,19 +293,18 @@ InvalidateInstructionCache (
 /*++\r
 \r
 Routine Description:\r
-\r
-  TODO: Add function description\r
+  This is a DebugSupport protocol member function.\r
+  Calls assembly routine to flush cache.\r
 \r
 Arguments:\r
-\r
-  This            - TODO: add argument description\r
-  ProcessorIndex  - TODO: add argument description\r
-  Start           - TODO: add argument description\r
-  Length          - TODO: add argument description\r
+  This             - The DebugSupport instance\r
+  ProcessorIndex   - Which processor the callback applies to.\r
+  Start            - Physical base of the memory range to be invalidated\r
+  Length           - mininum number of bytes in instruction cache to invalidate\r
 \r
 Returns:\r
 \r
-  TODO: add return values\r
+  EFI_SUCCESS - always return success\r
 \r
 --*/\r
 ;\r
index b79390a95f858421580c011cc1b8507568b166ad..513d71f62fb8455758e793887c59999e301f1306 100644 (file)
@@ -1,4 +1,5 @@
-/*++\r
+/**@file\r
+  IPF specific debug support functions\r
 \r
 Copyright (c) 2006, Intel Corporation                                                         \r
 All rights reserved. This program and the accompanying materials                          \r
@@ -9,32 +10,7 @@ http://opensource.org/licenses/bsd-license.php
 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
-    PlDebugSupport.c\r
-\r
-Abstract:\r
-\r
-    IPF specific debug support functions\r
-\r
-Revision History\r
-\r
---*/\r
-\r
-//\r
-// Master EFI header file\r
-//\r
-#include "Tiano.h"\r
-\r
-//\r
-// Common library header files\r
-//\r
-#include "EfiDriverLib.h"\r
-\r
-//\r
-// Produced protocols\r
-//\r
-#include EFI_PROTOCOL_DEFINITION (DebugSupport)\r
+**/\r
 \r
 //\r
 // private header files\r
@@ -148,14 +124,13 @@ Routine Description:
   used by the driver.  Must be public because it's referenced from DebugSuport.c\r
 \r
 Arguments:\r
-  IN EFI_HANDLE       ImageHandle\r
+  ImageHandle - Image handle\r
 \r
 Returns:\r
 \r
   EFI_STATUS - anything other than EFI_SUCCESS indicates the callback was not registered.\r
 \r
 --*/\r
-// TODO:    ImageHandle - add argument and description to function comment\r
 {\r
   EFI_EXCEPTION_TYPE  ExceptionType;\r
 \r
@@ -178,22 +153,20 @@ Routine Description:
   exception dispatcher.  Must be public because it's referenced from AsmFuncs.s.\r
 \r
 Arguments:\r
-  IN EFI_EXCEPTION_TYPE ExceptionType,\r
-  IN EFI_SYSTEM_CONTEXT Context\r
+  ExceptionType - Exception Type\r
+  Context       - System Context\r
 \r
 Returns:\r
 \r
   Nothing\r
   \r
 --*/\r
-// TODO:    ExceptionType - add argument and description to function comment\r
-// TODO:    Context - add argument and description to function comment\r
 {\r
   static BOOLEAN  InHandler = FALSE;\r
 \r
   DEBUG_CODE_BEGIN ();\r
     if (InHandler) {\r
-      EfiDebugPrint (EFI_D_GENERIC, "ERROR: Re-entered debugger!\n"\r
+      DEBUG ((EFI_D_INFO, "ERROR: Re-entered debugger!\n"\r
                                     "       ExceptionType == %X\n"\r
                                     "       Context       == %X\n"\r
                                     "       Context.SystemContextIpf->CrIip  == %X\n"\r
@@ -203,7 +176,7 @@ Returns:
                                     Context, \r
                                     Context.SystemContextIpf->CrIip,\r
                                     Context.SystemContextIpf->CrIpsr,\r
-                                    InHandler);\r
+                                    InHandler));\r
     }\r
   DEBUG_CODE_END ();\r
 \r
@@ -234,16 +207,14 @@ Routine Description:
   Given an integer number, return the physical address of the entry point in the IFT\r
   \r
 Arguments:\r
-  UINTN   HandlerIndex, \r
-  VOID    ** EntryPoint\r
+  HandlerIndex - Index of the Handler \r
+  EntryPoint   - IFT Entrypoint\r
 \r
 Returns:\r
 \r
   Nothing\r
   \r
 --*/\r
-// TODO:    HandlerIndex - add argument and description to function comment\r
-// TODO:    EntryPoint - add argument and description to function comment\r
 {\r
   UINT8 *TempPtr;\r
 \r
@@ -280,20 +251,17 @@ Routine Description:
   This is the worker function that installs and removes all handlers\r
   \r
 Arguments:\r
-  IN  EFI_EXCEPTION_TYPE           ExceptionType,\r
-  IN  BUNDLE                       NewBundles[NUM_BUNDLES_IN_STUB],\r
-  IN  VOID                         (*NewCallback) ()\r
+  ExceptionType  - Exception Type\r
+  NewBundles     - New Boundles\r
+  NewCallback    - New Callback\r
 \r
 Returns:\r
 \r
   EFI_STATUS - any return other than EFI_SUCCESS indicates the request was not\r
   satisfied.\r
+  EFI_ALEADY_STARTED - Ivt already hooked.\r
   \r
 --*/\r
-// TODO:    ExceptionType - add argument and description to function comment\r
-// TODO:    ] - add argument and description to function comment\r
-// TODO:    ) - add argument and description to function comment\r
-// TODO:    EFI_ALREADY_STARTED - add return value to function comment\r
 {\r
   BUNDLE  *B0Ptr;\r
   UINT64  InterruptFlags;\r
@@ -367,18 +335,15 @@ Routine Description:
   to store the ExceptionType and then call the common handler.\r
   \r
 Arguments:\r
-  IN  EFI_EXCEPTION_TYPE  ExceptionType,\r
-  IN  BUNDLE              NewBundles[4],\r
-  IN  VOID                (*NewCallback) ()\r
+  ExceptionType  - Exception Type\r
+  NewBundles     - New Boundles\r
+  NewCallback    - New Callback\r
 \r
 Returns:\r
 \r
   Nothing\r
     \r
 --*/\r
-// TODO:    ExceptionType - add argument and description to function comment\r
-// TODO:    ] - add argument and description to function comment\r
-// TODO:    ) - add argument and description to function comment\r
 {\r
   BUNDLE  *FixupBundle;\r
   BUNDLE  *B0Ptr;\r
@@ -422,14 +387,15 @@ Routine Description:
   Restores original IVT contents when unregistering a callback function\r
   \r
 Arguments:\r
-  IN  EFI_EXCEPTION_TYPE  ExceptionType,\r
+  ExceptionType  - Exception Type\r
+  NewBundles     - New Boundles\r
+  NewCallback    - New Callback\r
 \r
 Returns:\r
 \r
   Nothing\r
     \r
 --*/\r
-// TODO:    ExceptionType - add argument and description to function comment\r
 {\r
   BUNDLE  *B0Ptr;\r
 \r
@@ -460,14 +426,13 @@ Routine Description:
   Records new callback in IvtEntryTable.\r
   \r
 Arguments:\r
-  IN  VOID  (*NewCallback) ()\r
+  NewCallback    - New Callback\r
 \r
 Returns:\r
 \r
   Nothing\r
     \r
 --*/\r
-// TODO:    ) - add argument and description to function comment\r
 {\r
   VOID  *Start;\r
 \r
@@ -522,12 +487,13 @@ Routine Description: This is a DebugSupport protocol member function.  Hard
   coded to support only 1 processor for now.\r
 \r
 Arguments:\r
+  This              - The DebugSupport instance\r
+  MaxProcessorIndex - The maximuim supported processor index\r
 \r
-Returns: Always returns EFI_SUCCESS with *MaxProcessorIndex set to 0\r
+Returns:\r
+  Always returns EFI_SUCCESS with *MaxProcessorIndex set to 0\r
 \r
 --*/\r
-// TODO:    This - add argument and description to function comment\r
-// TODO:    MaxProcessorIndex - add argument and description to function comment\r
 {\r
   *MaxProcessorIndex = 0;\r
   return (EFI_SUCCESS);\r
@@ -546,18 +512,15 @@ Routine Description:
   DebugSupport protocol member function\r
 \r
 Arguments:\r
-  IN EFI_DEBUG_SUPPORT_PROTOCOL   *This,\r
-  IN UINTN                        ProcessorIndex,\r
-  IN EFI_PERIODIC_CALLBACK        NewPeriodicCallback\r
+  This             - The DebugSupport instance\r
+  ProcessorIndex   - Which processor the callback applies to.\r
+  PeriodicCallback - Callback function\r
 \r
 Returns:\r
 \r
   EFI_STATUS - anything other than EFI_SUCCESS indicates the callback was not registered.\r
 \r
 --*/\r
-// TODO:    This - add argument and description to function comment\r
-// TODO:    ProcessorIndex - add argument and description to function comment\r
-// TODO:    NewPeriodicCallback - add argument and description to function comment\r
 {\r
   return ManageIvtEntryTable (EXCEPT_IPF_EXTERNAL_INTERRUPT, NULL, NewPeriodicCallback);\r
 }\r
@@ -576,19 +539,16 @@ Routine Description:
   DebugSupport protocol member function\r
 \r
 Arguments:\r
-  IN EFI_DEBUG_SUPPORT_PROTOCOL   *This,\r
-  IN EFI_EXCEPTION_CALLBACK       NewCallback,\r
-  IN EFI_EXCEPTION_TYPE           ExceptionType\r
+  This             - The DebugSupport instance\r
+  ProcessorIndex   - Which processor the callback applies to.\r
+  NewCallback      - Callback function\r
+  ExceptionType    - Which exception to hook\r
 \r
 Returns:\r
 \r
   EFI_STATUS - anything other than EFI_SUCCESS indicates the callback was not registered.\r
 \r
 --*/\r
-// TODO:    This - add argument and description to function comment\r
-// TODO:    ProcessorIndex - add argument and description to function comment\r
-// TODO:    NewCallback - add argument and description to function comment\r
-// TODO:    ExceptionType - add argument and description to function comment\r
 {\r
   return ManageIvtEntryTable (\r
           ExceptionType,\r
@@ -611,15 +571,15 @@ Routine Description:
   DebugSupport protocol member function.  Calls assembly routine to flush cache.\r
 \r
 Arguments:\r
+  This             - The DebugSupport instance\r
+  ProcessorIndex   - Which processor the callback applies to.\r
+  Start            - Physical base of the memory range to be invalidated\r
+  Length           - mininum number of bytes in instruction cache to invalidate\r
 \r
 Returns:\r
   EFI_SUCCESS\r
 \r
 --*/\r
-// TODO:    This - add argument and description to function comment\r
-// TODO:    ProcessorIndex - add argument and description to function comment\r
-// TODO:    Start - add argument and description to function comment\r
-// TODO:    Length - add argument and description to function comment\r
 {\r
   InstructionCacheFlush (Start, Length);\r
   return (EFI_SUCCESS);\r
diff --git a/EdkModulePkg/Universal/DebugSupport/Dxe/ipf/plDebugSupport.h b/EdkModulePkg/Universal/DebugSupport/Dxe/ipf/plDebugSupport.h
new file mode 100644 (file)
index 0000000..10563ec
--- /dev/null
@@ -0,0 +1,297 @@
+/**@file\r
+  IPF specific debugsupport types, macros, and definitions.\r
+  \r
+Copyright (c) 2004 - 2006 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
+**/\r
+\r
+#ifndef _PLDEBUG_SUPPORT_H\r
+#define _PLDEBUG_SUPPORT_H\r
+\r
+\r
+#define DISABLE_INTERRUPTS  0UL\r
+\r
+//\r
+// The remaining definitions comprise the protocol members.\r
+//\r
+#define EFI_ISA IsaIpf\r
+\r
+//\r
+// processor specific functions that must be public\r
+//\r
+EFI_STATUS\r
+plInitializeDebugSupportDriver (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  IPF specific DebugSupport driver initialization.  Must be public because it's\r
+  referenced from DebugSupport.c\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+plUnloadDebugSupportDriver (\r
+  IN EFI_HANDLE                   ImageHandle\r
+  )\r
+/*++\r
+\r
+Routine Description:\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
+\r
+Arguments:\r
+  ImageHandle - Image handle\r
+\r
+Returns:\r
+\r
+  EFI_STATUS - anything other than EFI_SUCCESS indicates the callback was not registered.\r
+\r
+--*/\r
+;\r
+\r
+//\r
+// Assembly worker functions and data referenced from plDebugSupport.c\r
+//\r
+VOID  *\r
+GetIva (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  C callable function to obtain the current value of IVA\r
+\r
+Arguments:\r
+\r
+  None\r
+\r
+Returns:\r
+\r
+  Current value if IVA\r
+\r
+--*/\r
+;\r
+\r
+VOID\r
+HookStub (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  HookStub will be copied from it's loaded location into the IVT when\r
+  an IVT entry is hooked.\r
+\r
+Arguments:\r
+\r
+  None\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+;\r
+\r
+VOID\r
+ChainHandler (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Chains an interrupt handler\r
+\r
+Arguments:\r
+\r
+  None\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+;\r
+\r
+VOID\r
+UnchainHandler (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Unchains an interrupt handler\r
+\r
+Arguments:\r
+\r
+  None\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+;\r
+\r
+UINT64\r
+ProgramInterruptFlags (\r
+  IN UINT64                       NewInterruptState\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  C callable function to enable/disable interrupts\r
+\r
+Arguments:\r
+\r
+  NewInterruptState - New Interrupt State\r
+\r
+Returns:\r
+\r
+  Previous state of psr.ic\r
+\r
+--*/\r
+;\r
+\r
+VOID\r
+InstructionCacheFlush (\r
+  IN VOID    *StartAddress,\r
+  IN UINTN   SizeInBytes\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Flushes instruction cache for specified number of bytes\r
+\r
+Arguments:\r
+\r
+  StartAddress  - Cache Start Address\r
+  SizeInBytes   - Cache Size\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GetMaximumProcessorIndex (\r
+  IN EFI_DEBUG_SUPPORT_PROTOCOL   *This,\r
+  OUT UINTN                       *MaxProcessorIndex\r
+  )\r
+/*++\r
+\r
+Routine Description: This is a DebugSupport protocol member function.  Hard\r
+  coded to support only 1 processor for now.\r
+\r
+Arguments:\r
+  This              - The DebugSupport instance\r
+  MaxProcessorIndex - The maximuim supported processor index\r
+\r
+Returns:\r
+  Always returns EFI_SUCCESS with *MaxProcessorIndex set to 0\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+RegisterPeriodicCallback (\r
+  IN EFI_DEBUG_SUPPORT_PROTOCOL   *This,\r
+  IN UINTN                        ProcessorIndex,\r
+  IN EFI_PERIODIC_CALLBACK        PeriodicCallback\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  DebugSupport protocol member function\r
+\r
+Arguments:\r
+  This             - The DebugSupport instance\r
+  ProcessorIndex   - Which processor the callback applies to.\r
+  PeriodicCallback - Callback function\r
+\r
+Returns:\r
+\r
+  EFI_STATUS - anything other than EFI_SUCCESS indicates the callback was not registered.\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+RegisterExceptionCallback (\r
+  IN EFI_DEBUG_SUPPORT_PROTOCOL   *This,\r
+  IN UINTN                        ProcessorIndex,\r
+  IN EFI_EXCEPTION_CALLBACK       NewHandler,\r
+  IN EFI_EXCEPTION_TYPE           ExceptionType\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  DebugSupport protocol member function\r
+\r
+Arguments:\r
+  This             - The DebugSupport instance\r
+  ProcessorIndex   - Which processor the callback applies to.\r
+  NewCallback      - Callback function\r
+  ExceptionType    - Which exception to hook\r
+\r
+Returns:\r
+\r
+  EFI_STATUS - anything other than EFI_SUCCESS indicates the callback was not registered.\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InvalidateInstructionCache (\r
+  IN EFI_DEBUG_SUPPORT_PROTOCOL   *This,\r
+  IN UINTN                        ProcessorIndex,\r
+  IN VOID                         *Start,\r
+  IN UINTN                        Length\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  DebugSupport protocol member function.  Calls assembly routine to flush cache.\r
+\r
+Arguments:\r
+  This             - The DebugSupport instance\r
+  ProcessorIndex   - Which processor the callback applies to.\r
+  Start            - Physical base of the memory range to be invalidated\r
+  Length           - mininum number of bytes in instruction cache to invalidate\r
+\r
+Returns:\r
+  EFI_SUCCESS\r
+\r
+--*/\r
+;\r
+\r
+#endif\r
diff --git a/EdkModulePkg/Universal/DebugSupport/Dxe/x64/AsmFuncs.asm b/EdkModulePkg/Universal/DebugSupport/Dxe/x64/AsmFuncs.asm
new file mode 100644 (file)
index 0000000..10e998f
--- /dev/null
@@ -0,0 +1,655 @@
+;******************************************************************************\r
+;*\r
+;* Copyright (c) 2006, 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
+;******************************************************************************\r
+\r
+EXCPT64_DIVIDE_ERROR     EQU    0\r
+EXCPT64_DEBUG            EQU    1\r
+EXCPT64_NMI              EQU    2\r
+EXCPT64_BREAKPOINT       EQU    3\r
+EXCPT64_OVERFLOW         EQU    4\r
+EXCPT64_BOUND            EQU    5\r
+EXCPT64_INVALID_OPCODE   EQU    6\r
+EXCPT64_DOUBLE_FAULT     EQU    8\r
+EXCPT64_INVALID_TSS      EQU   10\r
+EXCPT64_SEG_NOT_PRESENT  EQU   11\r
+EXCPT64_STACK_FAULT      EQU   12\r
+EXCPT64_GP_FAULT         EQU   13\r
+EXCPT64_PAGE_FAULT       EQU   14\r
+EXCPT64_FP_ERROR         EQU   16\r
+EXCPT64_ALIGNMENT_CHECK  EQU   17\r
+EXCPT64_MACHINE_CHECK    EQU   18\r
+EXCPT64_SIMD             EQU   19\r
+\r
+FXSTOR_FLAG              EQU   01000000h         ; bit cpuid 24 of feature flags\r
+\r
+;; The FXSTOR and FXRSTOR commands are used for saving and restoring the x87,\r
+;; MMX, SSE, SSE2, etc registers.  The initialization of the debugsupport driver\r
+;; MUST check the CPUID feature flags to see that these instructions are available\r
+;; and fail to init if they are not.\r
+\r
+;; fxstor [rdi]\r
+FXSTOR_RDI               MACRO\r
+                         db 0fh, 0aeh, 00000111y ; mod = 00, reg/op = 000, r/m = 111 = [rdi]\r
+ENDM\r
+\r
+;; fxrstor [rsi]\r
+FXRSTOR_RSI              MACRO\r
+                         db 0fh, 0aeh, 00001110y ; mod = 00, reg/op = 001, r/m = 110 = [rsi]\r
+ENDM\r
+\r
+data SEGMENT\r
+\r
+public          OrigVector, InterruptEntryStub, StubSize, CommonIdtEntry, FxStorSupport\r
+\r
+StubSize        dd      InterruptEntryStubEnd - InterruptEntryStub\r
+AppRsp          dq      1111111111111111h ; ?\r
+DebugRsp        dq      2222222222222222h ; ?\r
+ExtraPush       dq      3333333333333333h ; ?\r
+ExceptData      dq      4444444444444444h ; ?\r
+Rflags          dq      5555555555555555h ; ?\r
+OrigVector      dq      6666666666666666h ; ?\r
+\r
+;; The declarations below define the memory region that will be used for the debug stack.\r
+;; The context record will be built by pushing register values onto this stack.\r
+;; It is imparitive that alignment be carefully managed, since the FXSTOR and\r
+;; FXRSTOR instructions will GP fault if their memory operand is not 16 byte aligned.\r
+;;\r
+;; The stub will switch stacks from the application stack to the debuger stack\r
+;; and pushes the exception number.\r
+;;\r
+;; Then we building the context record on the stack. Since the stack grows down,\r
+;; we push the fields of the context record from the back to the front.  There\r
+;; are 336 bytes of stack used prior allocating the 512 bytes of stack to be\r
+;; used as the memory buffer for the fxstor instruction. Therefore address of\r
+;; the buffer used for the FXSTOR instruction is &Eax - 336 - 512, which\r
+;; must be 16 byte aligned.\r
+;;\r
+;; We carefully locate the stack to make this happen.\r
+;;\r
+;; For reference, the context structure looks like this:\r
+;;      struct {\r
+;;        UINT64            ExceptionData;\r
+;;        FX_SAVE_STATE_X64 FxSaveState;    // 512 bytes, must be 16 byte aligned\r
+;;        UINT64            Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
+;;        UINT64            Cr0, Cr1, Cr2, Cr3, Cr4, Cr8;\r
+;;        UINT64            RFlags;\r
+;;        UINT64            Ldtr, Tr;\r
+;;        UINT64            Gdtr[2], Idtr[2];\r
+;;        UINT64            Rip;\r
+;;        UINT64            Gs, Fs, Es, Ds, Cs, Ss;\r
+;;        UINT64            Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax;\r
+;;        UINT64            R8, R9, R10, R11, R12, R13, R14, R15;\r
+;;      } SYSTEM_CONTEXT_X64;  // 64 bit system context record\r
+\r
+align           16\r
+DebugStackEnd   db      "DbgStkEnd >>>>>>"      ;; 16 byte long string - must be 16 bytes to preserve alignment\r
+                dd      1ffch dup (000000000h)  ;; 32K should be enough stack\r
+                                                ;;   This allocation is coocked to insure \r
+                                                ;;   that the the buffer for the FXSTORE instruction\r
+                                                ;;   will be 16 byte aligned also.\r
+                                                ;;\r
+ExceptionNumber dq      ?                       ;; first entry will be the vector number pushed by the stub\r
+\r
+DebugStackBegin db      "<<<< DbgStkBegin"      ;; initial debug ESP == DebugStackBegin, set in stub\r
+\r
+data ENDS\r
+\r
+text SEGMENT\r
+\r
+externdef InterruptDistrubutionHub:near\r
+\r
+;------------------------------------------------------------------------------\r
+;  VOID\r
+;  EfiWbinvd (\r
+;    VOID\r
+;    )\r
+;\r
+; Abstract: Writeback and invalidate cache\r
+;\r
+EfiWbinvd PROC    PUBLIC\r
+    wbinvd\r
+    ret\r
+EfiWbinvd ENDP\r
+\r
+;------------------------------------------------------------------------------\r
+; BOOLEAN\r
+; FxStorSupport (\r
+;   void\r
+;   )\r
+;\r
+; Abstract: Returns TRUE if FxStor instructions are supported\r
+;\r
+FxStorSupport   PROC    PUBLIC\r
+\r
+;\r
+; cpuid corrupts rbx which must be preserved per the C calling convention\r
+;\r
+                push    rbx\r
+                mov     rax, 1\r
+                cpuid\r
+                mov     eax, edx\r
+                and     rax, FXSTOR_FLAG\r
+                shr     rax, 24\r
+                pop     rbx\r
+                ret\r
+FxStorSupport   ENDP\r
+\r
+\r
+;------------------------------------------------------------------------------\r
+; DESCRIPTOR *\r
+; GetIdtr (\r
+;   void\r
+;   )\r
+;\r
+; Abstract: Returns physical address of IDTR\r
+;\r
+GetIdtr         PROC    PUBLIC\r
+                push    rbp\r
+                mov     rbp, rsp\r
+\r
+                sub     rsp, 8h\r
+                sidt    QWORD PTR [rbp - 6]\r
+                mov     rax, QWORD PTR [rbp - 4]\r
+\r
+                mov     rsp, rbp\r
+                pop     rbp\r
+                ret\r
+GetIdtr         ENDP\r
+\r
+\r
+;------------------------------------------------------------------------------\r
+; BOOLEAN\r
+; WriteInterruptFlag (\r
+;   BOOLEAN NewState // rcx\r
+;   )\r
+;\r
+; Abstract: Programs interrupt flag to the requested state and returns previous\r
+;           state.\r
+;\r
+WriteInterruptFlag  PROC PUBLIC\r
+\r
+                pushfq\r
+                pop     rax\r
+                and     rax, 200h\r
+                shr     rax, 9\r
+                cmp     rcx, 0\r
+                jnz     EnableIF\r
+                cli\r
+                ret\r
+EnableIF:\r
+                sti\r
+                ret\r
+\r
+WriteInterruptFlag  ENDP\r
+\r
+\r
+\r
+;------------------------------------------------------------------------------\r
+; void\r
+; Vect2Desc (\r
+;   DESCRIPTOR * DestDesc,  // rcx\r
+;   void (*Vector) (void)   // rdx\r
+;   )\r
+;\r
+; Abstract: Encodes an IDT descriptor with the given physical address\r
+;\r
+Vect2Desc       PROC    PUBLIC\r
+\r
+                mov     rax, rdx\r
+                mov     word ptr [rcx], ax                  ; write bits 15..0 of offset\r
+                mov     dx, cs\r
+                mov     word ptr [rcx+2], dx                ; SYS_CODE_SEL from GDT\r
+                mov     word ptr [rcx+4], 0e00h OR 8000h    ; type = 386 interrupt gate, present\r
+                shr     rax, 16\r
+                mov     word ptr [rcx+6], ax                ; write bits 31..16 of offset\r
+                shr     rax, 16\r
+                mov     dword ptr [rcx+8], eax              ; write bits 63..32 of offset\r
+\r
+                ret\r
+\r
+Vect2Desc       ENDP\r
+\r
+\r
+\r
+;------------------------------------------------------------------------------\r
+; InterruptEntryStub\r
+;\r
+; Abstract: This code is not a function, but is a small piece of code that is\r
+;               copied and fixed up once for each IDT entry that is hooked.\r
+;\r
+InterruptEntryStub::\r
+                push    0                       ; push vector number - will be modified before installed\r
+                db      0e9h                    ; jump rel32\r
+                dd      0                       ; fixed up to relative address of CommonIdtEntry\r
+InterruptEntryStubEnd:\r
+\r
+\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
+CommonIdtEntry::\r
+;;\r
+;; At this point, the stub has saved the current application stack esp into AppRsp\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
+;;              [16 bytes alignment, do not care it]\r
+;;              SS from interrupted task\r
+;;              RSP from interrupted task\r
+;;              rflags from interrupted task\r
+;;              CS from interrupted task\r
+;;              RIP from interrupted task\r
+;;              Error code <-------------------- Only present for some exeption types\r
+;;\r
+;;              Vector Number <----------------- pushed in our IDT Entry\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
+;;   UINT64            ExceptionData;\r
+;;   FX_SAVE_STATE_X64 FxSaveState;\r
+;;   UINT64            Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
+;;   UINT64            Cr0, Cr2, Cr3, Cr4, Cr8;\r
+;;   UINT64            RFlags;\r
+;;   UINT64            Ldtr, Tr;\r
+;;   UINT64            Gdtr[2], Idtr[2];\r
+;;   UINT64            Rip;\r
+;;   UINT64            Gs, Fs, Es, Ds, Cs, Ss;\r
+;;   UINT64            Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax;\r
+;;   UINT64            R8, R9, R10, R11, R12, R13, R14, R15;\r
+;; } SYSTEM_CONTEXT_X64;  // 64 bit system context record\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
+                mov     ExceptionNumber, rax             ; save vector number\r
+                pop     rax\r
+                add     rsp, 8                           ; pop vector number\r
+                mov     AppRsp, rsp                      ; save stack top\r
+                mov     rsp, offset DebugStackBegin      ; switch to debugger stack\r
+                sub     rsp, 8                           ; leave space for vector number\r
+\r
+;; UINT64  Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax;\r
+;; UINT64  R8, R9, R10, R11, R12, R13, R14, R15;\r
+                push    r15\r
+                push    r14\r
+                push    r13\r
+                push    r12\r
+                push    r11\r
+                push    r10\r
+                push    r9\r
+                push    r8\r
+                push    rax\r
+                push    rcx\r
+                push    rdx\r
+                push    rbx\r
+                push    rsp\r
+                push    rbp\r
+                push    rsi\r
+                push    rdi\r
+\r
+;; Save interrupt state rflags register...\r
+                pushfq\r
+                pop     rax\r
+                mov     qword ptr Rflags, rax\r
+\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
+                cmp     ExceptionNumber, EXCPT64_DOUBLE_FAULT\r
+                jz      ExtraPushOne\r
+                cmp     ExceptionNumber, EXCPT64_INVALID_TSS\r
+                jz      ExtraPushOne\r
+                cmp     ExceptionNumber, EXCPT64_SEG_NOT_PRESENT\r
+                jz      ExtraPushOne\r
+                cmp     ExceptionNumber, EXCPT64_STACK_FAULT\r
+                jz      ExtraPushOne\r
+                cmp     ExceptionNumber, EXCPT64_GP_FAULT\r
+                jz      ExtraPushOne\r
+                cmp     ExceptionNumber, EXCPT64_PAGE_FAULT\r
+                jz      ExtraPushOne\r
+                cmp     ExceptionNumber, EXCPT64_ALIGNMENT_CHECK\r
+                jz      ExtraPushOne\r
+                mov     ExtraPush, 0\r
+                mov     ExceptData, 0\r
+                jmp     ExtraPushDone\r
+ExtraPushOne:\r
+                mov     ExtraPush, 1\r
+\r
+;; If there's some extra data, save it also, and modify the saved AppRsp to effectively\r
+;; pop this value off the application's stack.\r
+                mov     rax, AppRsp\r
+                mov     rbx, [rax]\r
+                mov     ExceptData, rbx\r
+                add     rax, 8\r
+                mov     AppRsp, rax\r
+\r
+ExtraPushDone:\r
+\r
+;; The "push" above pushed the debug stack rsp.  Since what we're actually doing\r
+;; is building the context record on the debug stack, we need to save the pushed\r
+;; debug RSP, and replace it with the application's last stack entry...\r
+                mov     rax, [rsp + 24]\r
+                mov     DebugRsp, rax\r
+                mov     rax, 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
+                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
+                push    rax\r
+\r
+                ; CS from application is one entry back in application stack\r
+                mov     rax, AppRsp\r
+                movzx   rax, word ptr [rax + 8]\r
+                push    rax\r
+\r
+                mov     rax, ds\r
+                push    rax\r
+                mov     rax, es\r
+                push    rax\r
+                mov     rax, fs\r
+                push    rax\r
+                mov     rax, gs\r
+                push    rax\r
+\r
+;; UINT64  Rip;\r
+                ; Rip from application is on top of application stack\r
+                mov     rax, AppRsp\r
+                push    qword ptr [rax]\r
+\r
+;; UINT64  Gdtr[2], Idtr[2];\r
+                push    0\r
+                push    0\r
+                sidt    fword ptr [rsp]\r
+                push    0\r
+                push    0\r
+                sgdt    fword ptr [rsp]\r
+\r
+;; UINT64  Ldtr, Tr;\r
+                xor     rax, rax\r
+                str     ax\r
+                push    rax\r
+                sldt    ax\r
+                push    rax\r
+\r
+;; UINT64  RFlags;\r
+;; Rflags from application is two entries back in application stack\r
+                mov     rax, AppRsp\r
+                push    qword ptr [rax + 16]\r
+\r
+;; UINT64  Cr0, Cr1, Cr2, Cr3, Cr4, Cr8;\r
+;; insure FXSAVE/FXRSTOR is enabled in CR4...\r
+;; ... while we're at it, make sure DE is also enabled...\r
+                mov     rax, cr8\r
+                push    rax\r
+                mov     rax, cr4\r
+                or      rax, 208h\r
+                mov     cr4, rax\r
+                push    rax\r
+                mov     rax, cr3\r
+                push    rax\r
+                mov     rax, cr2\r
+                push    rax\r
+                push    0\r
+                mov     rax, cr0\r
+                push    rax\r
+\r
+;; UINT64  Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
+                mov     rax, dr7\r
+                push    rax\r
+;; clear Dr7 while executing debugger itself\r
+                xor     rax, rax\r
+                mov     dr7, rax\r
+\r
+                mov     rax, dr6\r
+                push    rax\r
+;; insure all status bits in dr6 are clear...\r
+                xor     rax, rax\r
+                mov     dr6, rax\r
+\r
+                mov     rax, dr3\r
+                push    rax\r
+                mov     rax, dr2\r
+                push    rax\r
+                mov     rax, dr1\r
+                push    rax\r
+                mov     rax, dr0\r
+                push    rax\r
+\r
+;; FX_SAVE_STATE_X64 FxSaveState;\r
+                sub     rsp, 512\r
+                mov     rdi, rsp\r
+                ; 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
+\r
+;; UINT64  ExceptionData;\r
+                mov     rax, 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
+                mov     rcx, ExceptionNumber\r
+                sub     rsp, 40\r
+                call    InterruptDistrubutionHub\r
+                add     rsp, 40\r
+\r
+; restore context...\r
+;; UINT64  ExceptionData;\r
+                add     rsp, 8\r
+\r
+;; FX_SAVE_STATE_X64 FxSaveState;\r
+                mov     rsi, rsp\r
+                FXRSTOR_RSI\r
+                add     rsp, 512\r
+\r
+;; UINT64  Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
+                pop     rax\r
+                mov     dr0, rax\r
+                pop     rax\r
+                mov     dr1, rax\r
+                pop     rax\r
+                mov     dr2, rax\r
+                pop     rax\r
+                mov     dr3, rax\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
+                add     rsp, 8\r
+                pop     rax\r
+                mov     cr2, rax\r
+                pop     rax\r
+                mov     cr3, rax\r
+                pop     rax\r
+                mov     cr4, rax\r
+                pop     rax\r
+                mov     cr8, rax\r
+\r
+;; UINT64  RFlags;\r
+                mov     rax, AppRsp\r
+                pop     qword ptr [rax + 16]\r
+\r
+;; UINT64  Ldtr, Tr;\r
+;; UINT64  Gdtr[2], Idtr[2];\r
+;; Best not let anyone mess with these particular registers...\r
+                add     rsp, 48\r
+\r
+;; UINT64  Rip;\r
+                pop     qword ptr [rax]\r
+\r
+;; UINT64  Gs, Fs, Es, Ds, Cs, Ss;\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     rax\r
+                ; mov     gs, rax\r
+                pop     rax\r
+                ; mov     fs, rax\r
+                pop     rax\r
+                mov     es, rax\r
+                pop     rax\r
+                mov     ds, rax\r
+                mov     rax, AppRsp\r
+                pop     qword ptr [rax + 8]\r
+                pop     rax\r
+                mov     ss, rax\r
+\r
+;; The next stuff to restore is the general purpose registers that were pushed\r
+;; using the "push" instruction.\r
+;;\r
+;; The value of RSP as stored in the context record is the application RSP\r
+;; including the 5 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     rbx, [rsp + 24]  ; move the potentially modified AppRsp into rbx\r
+                mov     rax, AppRsp\r
+                add     rax, 40\r
+                cmp     rbx, rax\r
+                je      NoAppStackMove\r
+\r
+                mov     rax, AppRsp\r
+                mov     rcx, [rax]       ; RIP\r
+                mov     [rbx], rcx\r
+\r
+                mov     rcx, [rax + 8]   ; CS\r
+                mov     [rbx + 8], rcx\r
+\r
+                mov     rcx, [rax + 16]  ; RFLAGS\r
+                mov     [rbx + 16], rcx\r
+\r
+                mov     rcx, [rax + 24]  ; RSP\r
+                mov     [rbx + 24], rcx\r
+\r
+                mov     rcx, [rax + 32]  ; SS\r
+                mov     [rbx + 32], rcx\r
+\r
+                mov     rax, rbx         ; modify the saved AppRsp to the new AppRsp\r
+                mov     AppRsp, rax\r
+NoAppStackMove:\r
+                mov     rax, DebugRsp    ; restore the DebugRsp on the debug stack\r
+                                         ; so our "pop" will not cause a stack switch\r
+                mov     [rsp + 24], rax\r
+\r
+                cmp     ExceptionNumber, 068h\r
+                jne     NoChain\r
+\r
+Chain:\r
+\r
+;; Restore rflags so when we chain, the flags will be exactly as if we were never here.\r
+;; We gin up the stack to do an iretq so we can get ALL the flags.\r
+                mov     rax, AppRsp\r
+                mov     rbx, [rax + 40]\r
+                push    rbx\r
+                mov     rax, ss\r
+                push    rax\r
+                mov     rax, rsp\r
+                add     rax, 16\r
+                push    rax\r
+                mov     rax, AppRsp\r
+                mov     rbx, [rax + 16]\r
+                and     rbx, NOT 300h ; special handling for IF and TF\r
+                push    rbx\r
+                mov     rax, cs\r
+                push    rax\r
+                mov     rax, offset PhonyIretq\r
+                push    rax\r
+                iretq\r
+PhonyIretq:\r
+\r
+;; UINT64  Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax;\r
+;; UINT64  R8, R9, R10, R11, R12, R13, R14, R15;\r
+                pop     rdi\r
+                pop     rsi\r
+                pop     rbp\r
+                pop     rsp\r
+                pop     rbx\r
+                pop     rdx\r
+                pop     rcx\r
+                pop     rax\r
+                pop     r8\r
+                pop     r9\r
+                pop     r10\r
+                pop     r11\r
+                pop     r12\r
+                pop     r13\r
+                pop     r14\r
+                pop     r15\r
+\r
+;; Switch back to application stack\r
+                mov     rsp, AppRsp\r
+\r
+;; Jump to original handler\r
+                jmp     OrigVector\r
+\r
+NoChain:\r
+;; UINT64  Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax;\r
+;; UINT64  R8, R9, R10, R11, R12, R13, R14, R15;\r
+                pop     rdi\r
+                pop     rsi\r
+                pop     rbp\r
+                pop     rsp\r
+                pop     rbx\r
+                pop     rdx\r
+                pop     rcx\r
+                pop     rax\r
+                pop     r8\r
+                pop     r9\r
+                pop     r10\r
+                pop     r11\r
+                pop     r12\r
+                pop     r13\r
+                pop     r14\r
+                pop     r15\r
+\r
+;; Switch back to application stack\r
+                mov     rsp, AppRsp\r
+\r
+;; We're outa here...\r
+                iretq\r
+text ENDS\r
+\r
+END\r
+\r
+\r
+\r
diff --git a/EdkModulePkg/Universal/DebugSupport/Dxe/x64/plDebugSupport.c b/EdkModulePkg/Universal/DebugSupport/Dxe/x64/plDebugSupport.c
new file mode 100644 (file)
index 0000000..b3580a4
--- /dev/null
@@ -0,0 +1,437 @@
+/**@file\r
+  X64 specific debug support functions\r
+\r
+Copyright (c) 2006 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
+**/\r
+\r
+//\r
+// private header files\r
+//\r
+#include "plDebugSupport.h"\r
+\r
+//\r
+// This the global main table to keep track of the interrupts\r
+//\r
+IDT_ENTRY   *IdtEntryTable  = NULL;\r
+DESCRIPTOR  NullDesc        = {0, 0};\r
+\r
+STATIC\r
+EFI_STATUS\r
+CreateEntryStub (\r
+  IN EFI_EXCEPTION_TYPE     ExceptionType,\r
+  OUT VOID                  **Stub\r
+  )\r
+/*++\r
+\r
+Routine Description: Allocate pool for a new IDT entry stub.  Copy the generic\r
+    stub into the new buffer and fixup the vector number and jump target address.\r
+\r
+Arguments:\r
+    ExceptionType - This is the exception type that the new stub will be created\r
+                    for.\r
+    Stub - On successful exit, *Stub contains the newly allocated entry stub.\r
+Returns:\r
+  Typically EFI_SUCCESS\r
+  other possibilities are passed through from AllocatePool\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT8       *StubCopy;\r
+\r
+  //\r
+  // First, allocate a new buffer and copy the stub code into it\r
+  //\r
+  Status = gBS->AllocatePool (EfiBootServicesData, StubSize, Stub);\r
+  if (Status == EFI_SUCCESS) {\r
+    StubCopy = *Stub;\r
+    gBS->CopyMem (StubCopy, InterruptEntryStub, StubSize);\r
+\r
+    //\r
+    // Next fixup the stub code for this vector\r
+    //\r
+\r
+    // The stub code looks like this:\r
+    //\r
+    //    00000000  6A 00               push    0                       ; push vector number - will be modified before installed\r
+    //    00000002  E9                  db      0e9h                    ; jump rel32\r
+    //    00000003  00000000            dd      0                       ; fixed up to relative address of CommonIdtEntry\r
+    //\r
+\r
+    //\r
+    // poke in the exception type so the second push pushes the exception type\r
+    //\r
+    StubCopy[0x1] = (UINT8) ExceptionType;\r
+\r
+    //\r
+    // fixup the jump target to point to the common entry\r
+    //\r
+    *(UINT32 *) &StubCopy[0x3] = (UINT32)((UINTN) CommonIdtEntry - (UINTN) &StubCopy[StubSize]);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+HookEntry (\r
+  IN EFI_EXCEPTION_TYPE            ExceptionType,\r
+  IN VOID                         (*NewCallback) ()\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Creates a nes entry stub.  Then saves the current IDT entry and replaces it\r
+  with an interrupt gate for the new entry point.  The IdtEntryTable is updated\r
+  with the new registered function.\r
+\r
+  This code executes in boot services context.  The stub entry executes in interrupt\r
+  context.\r
+\r
+Arguments:\r
+  ExceptionType - specifies which vector to hook.\r
+  NewCallback - a pointer to the new function to be registered.\r
+\r
+Returns:\r
+  EFI_SUCCESS\r
+  Other possibilities are passed through by CreateEntryStub\r
+\r
+--*/\r
+{\r
+  BOOLEAN     OldIntFlagState;\r
+  EFI_STATUS  Status;\r
+\r
+  Status = CreateEntryStub (ExceptionType, (VOID **) &IdtEntryTable[ExceptionType].StubEntry);\r
+  if (Status == EFI_SUCCESS) {\r
+    OldIntFlagState = WriteInterruptFlag (0);\r
+    ReadIdt (ExceptionType, &(IdtEntryTable[ExceptionType].OrigDesc));\r
+\r
+    ((UINT16 *) &IdtEntryTable[ExceptionType].OrigVector)[0]  = ((UINT16 *) &IdtEntryTable[ExceptionType].OrigDesc.Low)[0];\r
+    ((UINT16 *) &IdtEntryTable[ExceptionType].OrigVector)[1]  = ((UINT16 *) &IdtEntryTable[ExceptionType].OrigDesc.Low)[3];\r
+    ((UINT32 *) &IdtEntryTable[ExceptionType].OrigVector)[1]  = ((UINT32 *) &IdtEntryTable[ExceptionType].OrigDesc.High)[0];\r
+\r
+    Vect2Desc (&IdtEntryTable[ExceptionType].NewDesc, IdtEntryTable[ExceptionType].StubEntry);\r
+    IdtEntryTable[ExceptionType].RegisteredCallback = NewCallback;\r
+    WriteIdt (ExceptionType, &(IdtEntryTable[ExceptionType].NewDesc));\r
+    WriteInterruptFlag (OldIntFlagState);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+UnhookEntry (\r
+  IN EFI_EXCEPTION_TYPE           ExceptionType\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Undoes HookEntry. This code executes in boot services context.\r
+\r
+Arguments:\r
+  ExceptionType - specifies which entry to unhook\r
+\r
+Returns:\r
+  EFI_SUCCESS\r
+  Other values are passed through from FreePool\r
+\r
+--*/\r
+{\r
+  BOOLEAN     OldIntFlagState;\r
+  EFI_STATUS  Status;\r
+\r
+  OldIntFlagState = WriteInterruptFlag (0);\r
+  WriteIdt (ExceptionType, &(IdtEntryTable[ExceptionType].OrigDesc));\r
+  Status = gBS->FreePool ((VOID *) (UINTN) IdtEntryTable[ExceptionType].StubEntry);\r
+  ZeroMem (&IdtEntryTable[ExceptionType], sizeof (IDT_ENTRY));\r
+  WriteInterruptFlag (OldIntFlagState);\r
+\r
+  return (Status);\r
+}\r
+\r
+EFI_STATUS\r
+ManageIdtEntryTable (\r
+  VOID (*NewCallback)(),\r
+  EFI_EXCEPTION_TYPE ExceptionType\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  This is the main worker function that manages the state of the interrupt\r
+  handlers.  It both installs and uninstalls interrupt handlers based on the\r
+  value of NewCallback.  If NewCallback is NULL, then uninstall is indicated.\r
+  If NewCallback is non-NULL, then install is indicated.\r
+\r
+Arguments:\r
+  NewCallback - If non-NULL, NewCallback specifies the new handler to register.\r
+                If NULL, specifies that the previously registered handler should\r
+                    be uninstalled.\r
+  ExceptionType - Indicates which entry to manage\r
+\r
+Returns:\r
+  EFI_SUCCESS\r
+  EFI_INVALID_PARAMETER - requested uninstalling a handler from a vector that has\r
+                          no handler registered for it\r
+  EFI_ALREADY_STARTED   - requested install to a vector that already has a handler registered.\r
+\r
+  Other possible return values are passed through from UnHookEntry and HookEntry.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  Status = EFI_SUCCESS;\r
+\r
+  if (CompareDescriptor (&IdtEntryTable[ExceptionType].NewDesc, &NullDesc)) {\r
+    //\r
+    // we've already installed to this vector\r
+    //\r
+    if (NewCallback != NULL) {\r
+      //\r
+      // if the input handler is non-null, error\r
+      //\r
+      Status = EFI_ALREADY_STARTED;\r
+    } else {\r
+      Status = UnhookEntry (ExceptionType);\r
+    }\r
+  } else {\r
+    //\r
+    // no user handler installed on this vector\r
+    //\r
+    if (NewCallback == NULL) {\r
+      //\r
+      // if the input handler is null, error\r
+      //\r
+      Status = EFI_INVALID_PARAMETER;\r
+    } else {\r
+      Status = HookEntry (ExceptionType, NewCallback);\r
+    }\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+GetMaximumProcessorIndex (\r
+  IN EFI_DEBUG_SUPPORT_PROTOCOL       *This,\r
+  OUT UINTN                           *MaxProcessorIndex\r
+  )\r
+/*++\r
+\r
+Routine Description: This is a DebugSupport protocol member function.\r
+\r
+Arguments:\r
+  This              - The DebugSupport instance\r
+  MaxProcessorIndex - The maximuim supported processor index\r
+\r
+Returns:\r
+  Always returns EFI_SUCCESS with *MaxProcessorIndex set to 0\r
+\r
+--*/\r
+{\r
+  *MaxProcessorIndex = 0;\r
+  return (EFI_SUCCESS);\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+RegisterPeriodicCallback (\r
+  IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r
+  IN UINTN                      ProcessorIndex,\r
+  IN EFI_PERIODIC_CALLBACK      PeriodicCallback\r
+  )\r
+/*++\r
+\r
+Routine Description: This is a DebugSupport protocol member function.\r
+\r
+Arguments:\r
+  This             - The DebugSupport instance\r
+  ProcessorIndex   - Which processor the callback applies to.\r
+  PeriodicCallback - Callback function\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS\r
+  EFI_INVALID_PARAMETER - requested uninstalling a handler from a vector that has\r
+                          no handler registered for it\r
+  EFI_ALREADY_STARTED   - requested install to a vector that already has a handler registered.\r
+\r
+  Other possible return values are passed through from UnHookEntry and HookEntry.\r
+\r
+--*/\r
+{\r
+  return ManageIdtEntryTable (PeriodicCallback, SYSTEM_TIMER_VECTOR);\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+RegisterExceptionCallback (\r
+  IN EFI_DEBUG_SUPPORT_PROTOCOL *This,\r
+  IN UINTN                      ProcessorIndex,\r
+  IN EFI_EXCEPTION_CALLBACK     NewCallback,\r
+  IN EFI_EXCEPTION_TYPE         ExceptionType\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  This is a DebugSupport protocol member function.\r
+\r
+  This code executes in boot services context.\r
+\r
+Arguments:\r
+  This             - The DebugSupport instance\r
+  ProcessorIndex   - Which processor the callback applies to.\r
+  NewCallback      - Callback function\r
+  ExceptionType    - Which exception to hook\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS\r
+  EFI_INVALID_PARAMETER - requested uninstalling a handler from a vector that has\r
+                          no handler registered for it\r
+  EFI_ALREADY_STARTED   - requested install to a vector that already has a handler registered.\r
+\r
+  Other possible return values are passed through from UnHookEntry and HookEntry.\r
+\r
+--*/\r
+{\r
+  return ManageIdtEntryTable (NewCallback, ExceptionType);\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InvalidateInstructionCache (\r
+  IN EFI_DEBUG_SUPPORT_PROTOCOL       *This,\r
+  IN UINTN                            ProcessorIndex,\r
+  IN VOID                             *Start,\r
+  IN UINT64                           Length\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  This is a DebugSupport protocol member function.\r
+  Calls assembly routine to flush cache.\r
+\r
+Arguments:\r
+  This             - The DebugSupport instance\r
+  ProcessorIndex   - Which processor the callback applies to.\r
+  Start            - Physical base of the memory range to be invalidated\r
+  Length           - mininum number of bytes in instruction cache to invalidate\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - always return success\r
+\r
+--*/\r
+{\r
+  AsmWbinvd ();\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+plInitializeDebugSupportDriver (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Initializes driver's handler registration database.\r
+\r
+  This code executes in boot services context.\r
+\r
+Arguments:\r
+  None\r
+\r
+Returns:\r
+  EFI_SUCCESS\r
+  EFI_UNSUPPORTED - if X64 processor does not support FXSTOR/FXRSTOR instructions,\r
+                    the context save will fail, so these processor's are not supported.\r
+  EFI_OUT_OF_RESOURCES - not resource to finish initialization\r
+\r
+--*/\r
+{\r
+  if (!FxStorSupport ()) {\r
+    return EFI_UNSUPPORTED;\r
+  } else {\r
+    IdtEntryTable = AllocateZeroPool (sizeof (IDT_ENTRY) * NUM_IDT_ENTRIES);\r
+    if (IdtEntryTable != NULL) {\r
+      return EFI_SUCCESS;\r
+    } else {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+  }\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+plUnloadDebugSupportDriver (\r
+  IN EFI_HANDLE ImageHandle\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  This is the callback that is written to the LoadedImage protocol instance\r
+  on the image handle. It uninstalls all registered handlers and frees all entry\r
+  stub memory.\r
+\r
+  This code executes in boot services context.\r
+\r
+Arguments:\r
+  ImageHandle - The image handle of the unload handler\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - always return success\r
+\r
+--*/\r
+{\r
+  EFI_EXCEPTION_TYPE  ExceptionType;\r
+\r
+  for (ExceptionType = 0; ExceptionType < NUM_IDT_ENTRIES; ExceptionType++) {\r
+    ManageIdtEntryTable (NULL, ExceptionType);\r
+  }\r
+\r
+  gBS->FreePool (IdtEntryTable);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+VOID\r
+InterruptDistrubutionHub (\r
+  EFI_EXCEPTION_TYPE      ExceptionType,\r
+  EFI_SYSTEM_CONTEXT_IA32 *ContextRecord\r
+  )\r
+/*++\r
+\r
+Routine Description: Common piece of code that invokes the registered handlers.\r
+\r
+  This code executes in exception context so no efi calls are allowed.\r
+\r
+Arguments:\r
+  ExceptionType - exception type\r
+  ContextRecord - system context\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  if (IdtEntryTable[ExceptionType].RegisteredCallback != NULL) {\r
+    if (ExceptionType != SYSTEM_TIMER_VECTOR) {\r
+      IdtEntryTable[ExceptionType].RegisteredCallback (ExceptionType, ContextRecord);\r
+    } else {\r
+      OrigVector = IdtEntryTable[ExceptionType].OrigVector;\r
+      IdtEntryTable[ExceptionType].RegisteredCallback (ContextRecord);\r
+    }\r
+  }\r
+}\r
diff --git a/EdkModulePkg/Universal/DebugSupport/Dxe/x64/plDebugSupport.h b/EdkModulePkg/Universal/DebugSupport/Dxe/x64/plDebugSupport.h
new file mode 100644 (file)
index 0000000..68866a8
--- /dev/null
@@ -0,0 +1,315 @@
+/**@file\r
+  X64 specific debug support macros, typedefs and prototypes.\r
+\r
+Copyright (c) 2006, 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
+**/\r
+\r
+#ifndef _PLDEBUG_SUPPORT_H\r
+#define _PLDEBUG_SUPPORT_H\r
+\r
+#define NUM_IDT_ENTRIES                 0x78\r
+#define SYSTEM_TIMER_VECTOR             0x68\r
+#define VECTOR_ENTRY_PAGES              1\r
+#define CopyDescriptor(Dest, Src)       CopyMem ((Dest), (Src), sizeof (DESCRIPTOR))\r
+#define ZeroDescriptor(Dest)            CopyDescriptor ((Dest), &NullDesc)\r
+#define ReadIdt(Vector, Dest)           CopyDescriptor ((Dest), &((GetIdtr ())[(Vector)]))\r
+#define WriteIdt(Vector, Src)           CopyDescriptor (&((GetIdtr ())[(Vector)]), (Src))\r
+#define CompareDescriptor(Desc1, Desc2) CompareMem ((Desc1), (Desc2), sizeof (DESCRIPTOR))\r
+#define EFI_ISA                         IsaX64\r
+#define FF_FXSR                         (1 << 24)\r
+\r
+typedef struct {\r
+  UINT64 Low;\r
+  UINT64 High;\r
+} DESCRIPTOR;\r
+\r
+typedef struct {\r
+  DESCRIPTOR  OrigDesc;\r
+  VOID (*OrigVector) (VOID);\r
+  DESCRIPTOR  NewDesc;\r
+  VOID (*StubEntry) (VOID);\r
+  VOID (*RegisteredCallback) ();\r
+} IDT_ENTRY;\r
+\r
+extern EFI_SYSTEM_CONTEXT SystemContext;\r
+extern UINT8              InterruptEntryStub[];\r
+extern UINT32             StubSize;\r
+extern VOID (*OrigVector) (VOID);\r
+\r
+VOID\r
+CommonIdtEntry (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Generic IDT entry\r
+\r
+Arguments:\r
+\r
+  None\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+;\r
+\r
+\r
+BOOLEAN\r
+FxStorSupport (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Check whether FXSTOR is supported\r
+\r
+Arguments:\r
+\r
+  None\r
+\r
+Returns:\r
+\r
+  TRUE  - supported\r
+  FALSE - not supported\r
+\r
+--*/\r
+;\r
+\r
+DESCRIPTOR  *\r
+GetIdtr (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Return the physical address of IDTR\r
+\r
+Arguments:\r
+\r
+  None\r
+\r
+Returns:\r
+\r
+  The physical address of IDTR\r
+\r
+--*/\r
+;\r
+\r
+VOID\r
+Vect2Desc (\r
+  DESCRIPTOR * DestDesc,\r
+  VOID (*Vector) (VOID)\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Encodes an IDT descriptor with the given physical address\r
+\r
+Arguments:\r
+\r
+  DestDesc  - The IDT descriptor address\r
+  Vector    - The interrupt vector entry\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+;\r
+\r
+BOOLEAN\r
+WriteInterruptFlag (\r
+  BOOLEAN NewState\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Programs interrupt flag to the requested state and returns previous\r
+  state.\r
+\r
+Arguments:\r
+\r
+  NewState  - New interrupt status\r
+\r
+Returns:\r
+\r
+  Old interrupt status\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+plInitializeDebugSupportDriver (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Initializes driver's handler registration database.\r
+\r
+  This code executes in boot services context.\r
+\r
+Arguments:\r
+  None\r
+\r
+Returns:\r
+  EFI_SUCCESS\r
+  EFI_UNSUPPORTED - if X64 processor does not support FXSTOR/FXRSTOR instructions,\r
+                    the context save will fail, so these processor's are not supported.\r
+  EFI_OUT_OF_RESOURCES - not resource to finish initialization\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+plUnloadDebugSupportDriver (\r
+  IN EFI_HANDLE                       ImageHandle\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  This is the callback that is written to the LoadedImage protocol instance\r
+  on the image handle. It uninstalls all registered handlers and frees all entry\r
+  stub memory.\r
+\r
+  This code executes in boot services context.\r
+\r
+Arguments:\r
+  ImageHandle - The image handle of the unload handler\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - always return success\r
+\r
+--*/\r
+;\r
+\r
+//\r
+// DebugSupport protocol member functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+GetMaximumProcessorIndex (\r
+  IN EFI_DEBUG_SUPPORT_PROTOCOL       *This,\r
+  OUT UINTN                           *MaxProcessorIndex\r
+  )\r
+/*++\r
+\r
+Routine Description: This is a DebugSupport protocol member function.\r
+\r
+Arguments:\r
+  This              - The DebugSupport instance\r
+  MaxProcessorIndex - The maximuim supported processor index\r
+\r
+Returns:\r
+  Always returns EFI_SUCCESS with *MaxProcessorIndex set to 0\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+RegisterPeriodicCallback (\r
+  IN EFI_DEBUG_SUPPORT_PROTOCOL       *This,\r
+  IN UINTN                            ProcessorIndex,\r
+  IN EFI_PERIODIC_CALLBACK            PeriodicCallback\r
+  )\r
+/*++\r
+\r
+Routine Description: This is a DebugSupport protocol member function.\r
+\r
+Arguments:\r
+  This             - The DebugSupport instance\r
+  ProcessorIndex   - Which processor the callback applies to.\r
+  PeriodicCallback - Callback function\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS\r
+  EFI_INVALID_PARAMETER - requested uninstalling a handler from a vector that has\r
+                          no handler registered for it\r
+  EFI_ALREADY_STARTED   - requested install to a vector that already has a handler registered.\r
+\r
+  Other possible return values are passed through from UnHookEntry and HookEntry.\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+RegisterExceptionCallback (\r
+  IN EFI_DEBUG_SUPPORT_PROTOCOL       *This,\r
+  IN UINTN                            ProcessorIndex,\r
+  IN EFI_EXCEPTION_CALLBACK           NewCallback,\r
+  IN EFI_EXCEPTION_TYPE               ExceptionType\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  This is a DebugSupport protocol member function.\r
+\r
+  This code executes in boot services context.\r
+\r
+Arguments:\r
+  This             - The DebugSupport instance\r
+  ProcessorIndex   - Which processor the callback applies to.\r
+  NewCallback      - Callback function\r
+  ExceptionType    - Which exception to hook\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS\r
+  EFI_INVALID_PARAMETER - requested uninstalling a handler from a vector that has\r
+                          no handler registered for it\r
+  EFI_ALREADY_STARTED   - requested install to a vector that already has a handler registered.\r
+\r
+  Other possible return values are passed through from UnHookEntry and HookEntry.\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InvalidateInstructionCache (\r
+  IN EFI_DEBUG_SUPPORT_PROTOCOL       *This,\r
+  IN UINTN                            ProcessorIndex,\r
+  IN VOID                             *Start,\r
+  IN UINT64                           Length\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  This is a DebugSupport protocol member function.\r
+  Calls assembly routine to flush cache.\r
+\r
+Arguments:\r
+  This             - The DebugSupport instance\r
+  ProcessorIndex   - Which processor the callback applies to.\r
+  Start            - Physical base of the memory range to be invalidated\r
+  Length           - mininum number of bytes in instruction cache to invalidate\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - always return success\r
+\r
+--*/\r
+;\r
+\r
+#endif\r