Initial import.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
bbahnsen
2006-04-21 22:54:32 +00:00
commit 878ddf1fc3
2651 changed files with 624620 additions and 0 deletions

View File

@@ -0,0 +1,151 @@
/*++
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
DebugSupport.c
Abstract:
Top level C file for debug support driver. Contains initialization function.
Revision History
--*/
//
// private header files
//
#include "plDebugSupport.h"
//
// This is a global that is the actual interface
//
EFI_DEBUG_SUPPORT_PROTOCOL gDebugSupportProtocolInterface = {
EFI_ISA,
GetMaximumProcessorIndex,
RegisterPeriodicCallback,
RegisterExceptionCallback,
InvalidateInstructionCache
};
//
// Driver Entry Point
//
EFI_STATUS
InitializeDebugSupportDriver (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
/*++
Routine Description:
Driver entry point. Checks to see there's not already a DebugSupport protocol
installed for the selected processor before installing protocol.
Arguments:
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
Returns:
EFI_STATUS
--*/
// TODO: ImageHandle - add argument and description to function comment
// TODO: SystemTable - add argument and description to function comment
{
EFI_LOADED_IMAGE_PROTOCOL *LoadedImageProtocolPtr;
EFI_STATUS Status;
EFI_HANDLE Handle;
EFI_HANDLE *HandlePtr;
UINTN NumHandles;
EFI_DEBUG_SUPPORT_PROTOCOL *DebugSupportProtocolPtr;
//
// Install Protocol Interface...
//
// First check to see that the debug support protocol for this processor
// type is not already installed
//
Status = gBS->LocateHandleBuffer (
ByProtocol,
&gEfiDebugSupportProtocolGuid,
NULL,
&NumHandles,
&HandlePtr
);
if (Status != EFI_NOT_FOUND) {
do {
NumHandles--;
Status = gBS->OpenProtocol (
HandlePtr[NumHandles],
&gEfiDebugSupportProtocolGuid,
(VOID **) &DebugSupportProtocolPtr,
ImageHandle,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (Status == EFI_SUCCESS && DebugSupportProtocolPtr->Isa == EFI_ISA) {
gBS->FreePool (HandlePtr);
Status = EFI_ALREADY_STARTED;
goto ErrExit;
}
} while (NumHandles > 0);
gBS->FreePool (HandlePtr);
}
//
// Get our image information and install platform specific unload handler
//
Status = gBS->OpenProtocol (
ImageHandle,
&gEfiLoadedImageProtocolGuid,
(VOID **) &LoadedImageProtocolPtr,
ImageHandle,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
ASSERT (!EFI_ERROR (Status));
if (Status != EFI_SUCCESS) {
goto ErrExit;
}
LoadedImageProtocolPtr->Unload = plUnloadDebugSupportDriver;
//
// Call hook for platform specific initialization
//
Status = plInitializeDebugSupportDriver ();
ASSERT (!EFI_ERROR (Status));
if (Status != EFI_SUCCESS) {
goto ErrExit;
}
//
// Install DebugSupport protocol to new handle
//
Handle = NULL;
Status = gBS->InstallProtocolInterface (
&Handle,
&gEfiDebugSupportProtocolGuid,
EFI_NATIVE_INTERFACE,
&gDebugSupportProtocolInterface
);
ASSERT (!EFI_ERROR (Status));
if (Status != EFI_SUCCESS) {
goto ErrExit;
}
ErrExit:
return Status;
}

View File

@@ -0,0 +1,26 @@
/*++
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
DebugSupport.dxs
Abstract:
Dependency expression source file.
--*/
#include <AutoGen.h>
#include <DxeDepex.h>
DEPENDENCY_START
TRUE
DEPENDENCY_END

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<ModuleBuildDescription xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.TianoCore.org/2006/Edk2.0 http://www.TianoCore.org/2006/Edk2.0/SurfaceArea.xsd">
<MbdHeader>
<BaseName>DebugSupport</BaseName>
<Guid>911D584C-35F7-4955-BEF9-B452769DDC3A</Guid>
<Version>0</Version>
<Description>FIX ME!</Description>
<Copyright>Copyright (c) 2004-2006, Intel Corporation</Copyright>
<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>
<Created>2006-03-12 17:09</Created>
<Modified>2006-03-19 15:19</Modified>
</MbdHeader>
<Libraries>
<Library>UefiBootServicesTableLib</Library>
<Library>BaseLib</Library>
<Library>UefiMemoryLib</Library>
<Library>UefiDriverEntryPoint</Library>
<Library>DxeReportStatusCodeLib</Library>
<Library>BaseDebugLibReportStatusCode</Library>
<Library>DxeMemoryAllocationLib</Library>
</Libraries>
<BuildOptions ToolChain="MSFT">
<ImageEntryPoint>_ModuleEntryPoint</ImageEntryPoint>
</BuildOptions>
</ModuleBuildDescription>

View File

@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-->
<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.TianoCore.org/2006/Edk2.0 http://www.TianoCore.org/2006/Edk2.0/SurfaceArea.xsd">
<MsaHeader>
<BaseName>DebugSupport</BaseName>
<ModuleType>DXE_DRIVER</ModuleType>
<ComponentType>BS_DRIVER</ComponentType>
<Guid>911D584C-35F7-4955-BEF9-B452769DDC3A</Guid>
<Version>0</Version>
<Abstract>Component description file for DiskIo module.</Abstract>
<Description>FIX ME!</Description>
<Copyright>Copyright (c) 2004-2006, Intel Corporation</Copyright>
<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>
<Specification>0</Specification>
<Created>2006-03-12 17:09</Created>
<Updated>2006-03-19 15:19</Updated>
</MsaHeader>
<LibraryClassDefinitions>
<LibraryClass Usage="ALWAYS_CONSUMED">DebugLib</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">UefiDriverEntryPoint</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">BaseMemoryLib</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">MemoryAllocationLib</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">UefiBootServicesTableLib</LibraryClass>
</LibraryClassDefinitions>
<SourceFiles>
<Filename>DebugSupport.c</Filename>
<Filename>DebugSupport.dxs</Filename>
<Arch ArchType="IA32">
<Filename>ia32\AsmFuncs.asm</Filename>
<Filename>ia32\plDebugSupport.c</Filename>
</Arch>
<Arch ArchType="IPF">
<Filename>ipf\AsmFuncs.s</Filename>
<Filename>ipf\common.i</Filename>
<Filename>ipf\ds64macros.i</Filename>
<Filename>ipf\plDebugSupport.c</Filename>
</Arch>
</SourceFiles>
<Includes>
<PackageName>MdePkg</PackageName>
<PackageName>EdkModulePkg</PackageName>
</Includes>
<Protocols>
<Protocol Usage="SOMETIMES_PRODUCED">DebugSupport</Protocol>
<Protocol Usage="ALWAYS_CONSUMED">LoadedImage</Protocol>
</Protocols>
<Externs>
<Extern>
<ModuleEntryPoint>InitializeDebugSupportDriver</ModuleEntryPoint>
</Extern>
</Externs>
</ModuleSurfaceArea>

View File

@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?><!-- Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.-->
<project basedir="." default="DebugSupport"><!--Apply external ANT tasks-->
<taskdef resource="GenBuild.tasks"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<property environment="env"/>
<property name="WORKSPACE_DIR" value="${env.WORKSPACE}"/>
<import file="${WORKSPACE_DIR}\Tools\Conf\BuildMacro.xml"/><!--MODULE_RELATIVE PATH is relative to PACKAGE_DIR-->
<property name="MODULE_RELATIVE_PATH" value="Universal\DebugSupport\Dxe"/>
<property name="MODULE_DIR" value="${PACKAGE_DIR}\${MODULE_RELATIVE_PATH}"/>
<property name="COMMON_FILE" value="${WORKSPACE_DIR}\Tools\Conf\Common.xml"/>
<target name="DebugSupport">
<GenBuild baseName="DebugSupport" mbdFilename="${MODULE_DIR}\DebugSupport.mbd" msaFilename="${MODULE_DIR}\DebugSupport.msa"/>
</target>
<target depends="DebugSupport_clean" name="clean"/>
<target depends="DebugSupport_cleanall" name="cleanall"/>
<target name="DebugSupport_clean">
<OutputDirSetup baseName="DebugSupport" mbdFilename="${MODULE_DIR}\DebugSupport.mbd" msaFilename="${MODULE_DIR}\DebugSupport.msa"/>
<if>
<available file="${DEST_DIR_OUTPUT}\DebugSupport_build.xml"/>
<then>
<ant antfile="${DEST_DIR_OUTPUT}\DebugSupport_build.xml" target="clean"/>
</then>
</if>
<delete dir="${DEST_DIR_OUTPUT}" excludes="*.xml"/>
</target>
<target name="DebugSupport_cleanall">
<OutputDirSetup baseName="DebugSupport" mbdFilename="${MODULE_DIR}\DebugSupport.mbd" msaFilename="${MODULE_DIR}\DebugSupport.msa"/>
<if>
<available file="${DEST_DIR_OUTPUT}\DebugSupport_build.xml"/>
<then>
<ant antfile="${DEST_DIR_OUTPUT}\DebugSupport_build.xml" target="cleanall"/>
</then>
</if>
<delete dir="${DEST_DIR_OUTPUT}"/>
<delete dir="${DEST_DIR_DEBUG}"/>
<delete>
<fileset dir="${BIN_DIR}" includes="**DebugSupport*"/>
</delete>
</target>
</project>

View File

@@ -0,0 +1,547 @@
;******************************************************************************
;*
;* Copyright (c) 2006, Intel Corporation
;* All rights reserved. This program and the accompanying materials
;* are licensed and made available under the terms and conditions of the BSD License
;* which accompanies this distribution. The full text of the license may be found at
;* http://opensource.org/licenses/bsd-license.php
;*
;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;*
;******************************************************************************
.586p
.MODEL FLAT, C
EXCPT32_DIVIDE_ERROR EQU 0
EXCPT32_DEBUG EQU 1
EXCPT32_NMI EQU 2
EXCPT32_BREAKPOINT EQU 3
EXCPT32_OVERFLOW EQU 4
EXCPT32_BOUND EQU 5
EXCPT32_INVALID_OPCODE EQU 6
EXCPT32_DOUBLE_FAULT EQU 8
EXCPT32_INVALID_TSS EQU 10
EXCPT32_SEG_NOT_PRESENT EQU 11
EXCPT32_STACK_FAULT EQU 12
EXCPT32_GP_FAULT EQU 13
EXCPT32_PAGE_FAULT EQU 14
EXCPT32_FP_ERROR EQU 16
EXCPT32_ALIGNMENT_CHECK EQU 17
EXCPT32_MACHINE_CHECK EQU 18
EXCPT32_SIMD EQU 19
FXSTOR_FLAG EQU 01000000h ; bit cpuid 24 of feature flags
;; The FXSTOR and FXRSTOR commands are used for saving and restoring the x87,
;; MMX, SSE, SSE2, etc registers. The initialization of the debugsupport driver
;; MUST check the CPUID feature flags to see that these instructions are available
;; and fail to init if they are not.
;; fxstor [edi]
FXSTOR_EDI MACRO
db 0fh, 0aeh, 00000111y ; mod = 00, reg/op = 000, r/m = 111 = [edi]
ENDM
;; fxrstor [esi]
FXRSTOR_ESI MACRO
db 0fh, 0aeh, 00001110y ; mod = 00, reg/op = 001, r/m = 110 = [esi]
ENDM
.DATA
public OrigVector, InterruptEntryStub, StubSize, CommonIdtEntry, FxStorSupport
StubSize dd InterruptEntryStubEnd - InterruptEntryStub
AppEsp dd 11111111h ; ?
DebugEsp dd 22222222h ; ?
ExtraPush dd 33333333h ; ?
ExceptData dd 44444444h ; ?
Eflags dd 55555555h ; ?
OrigVector dd 66666666h ; ?
;; The declarations below define the memory region that will be used for the debug stack.
;; The context record will be built by pushing register values onto this stack.
;; It is imparitive that alignment be carefully managed, since the FXSTOR and
;; FXRSTOR instructions will GP fault if their memory operand is not 16 byte aligned.
;;
;; The stub will switch stacks from the application stack to the debuger stack
;; and pushes the exception number.
;;
;; Then we building the context record on the stack. Since the stack grows down,
;; we push the fields of the context record from the back to the front. There
;; are 132 bytes of stack used prior allocating the 512 bytes of stack to be
;; used as the memory buffer for the fxstor instruction. Therefore address of
;; the buffer used for the FXSTOR instruction is &Eax - 132 - 512, which
;; must be 16 byte aligned.
;;
;; We carefully locate the stack to make this happen.
;;
;; For reference, the context structure looks like this:
;; struct {
;; UINT32 ExceptionData;
;; FX_SAVE_STATE FxSaveState; // 512 bytes, must be 16 byte aligned
;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
;; UINT32 Ldtr, Tr;
;; UINT64 Gdtr, Idtr;
;; UINT32 EFlags;
;; UINT32 Eip;
;; UINT32 SegGs, SegFs, SegEs, SegDs, SegCs, SegSs;
;; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;
;; } SYSTEM_CONTEXT_IA32; // 32 bit system context record
align 16
DebugStackEnd db "DbgStkEnd >>>>>>" ;; 16 byte long string - must be 16 bytes to preserve alignment
dd 1ffdh dup (000000000h) ;; 32K should be enough stack
;; This allocation is coocked to insure
;; that the the buffer for the FXSTORE instruction
;; will be 16 byte aligned also.
;;
ExceptionNumber dd ? ;; first entry will be the vector number pushed by the stub
DebugStackBegin db "<<<< DbgStkBegin" ;; initial debug ESP == DebugStackBegin, set in stub
.CODE
externdef InterruptDistrubutionHub:near
;------------------------------------------------------------------------------
; BOOLEAN
; FxStorSupport (
; void
; )
;
; Abstract: Returns TRUE if FxStor instructions are supported
;
FxStorSupport PROC C PUBLIC
;
; cpuid corrupts ebx which must be preserved per the C calling convention
;
push ebx
mov eax, 1
cpuid
mov eax, edx
and eax, FXSTOR_FLAG
shr eax, 24
pop ebx
ret
FxStorSupport ENDP
;------------------------------------------------------------------------------
; DESCRIPTOR *
; GetIdtr (
; void
; )
;
; Abstract: Returns physical address of IDTR
;
GetIdtr PROC C PUBLIC
LOCAL IdtrBuf:FWORD
sidt IdtrBuf
mov eax, DWORD PTR IdtrBuf + 2
ret
GetIdtr ENDP
;------------------------------------------------------------------------------
; BOOLEAN
; WriteInterruptFlag (
; BOOLEAN NewState
; )
;
; Abstract: Programs interrupt flag to the requested state and returns previous
; state.
;
WriteInterruptFlag PROC C PUBLIC State:DWORD
pushfd
pop eax
and eax, 200h
shr eax, 9
mov ecx, State
.IF ecx == 0
cli
.ELSE
sti
.ENDIF
ret
WriteInterruptFlag ENDP
;------------------------------------------------------------------------------
; void
; Vect2Desc (
; DESCRIPTOR * DestDesc,
; void (*Vector) (void)
; )
;
; Abstract: Encodes an IDT descriptor with the given physical address
;
Vect2Desc PROC C PUBLIC DestPtr:DWORD, Vector:DWORD
mov eax, Vector
mov ecx, DestPtr
mov word ptr [ecx], ax ; write bits 15..0 of offset
mov word ptr [ecx+2], 20h ; SYS_CODE_SEL from GDT
mov word ptr [ecx+4], 0e00h OR 8000h ; type = 386 interrupt gate, present
shr eax, 16
mov word ptr [ecx+6], ax ; write bits 31..16 of offset
ret
Vect2Desc ENDP
;------------------------------------------------------------------------------
; InterruptEntryStub
;
; Abstract: This code is not a function, but is a small piece of code that is
; copied and fixed up once for each IDT entry that is hooked.
;
InterruptEntryStub::
mov AppEsp, esp ; save stack top
mov esp, offset DebugStackBegin ; switch to debugger stack
push 0 ; push vector number - will be modified before installed
db 0e9h ; jump rel32
dd 0 ; fixed up to relative address of CommonIdtEntry
InterruptEntryStubEnd:
;------------------------------------------------------------------------------
; CommonIdtEntry
;
; Abstract: This code is not a function, but is the common part for all IDT
; vectors.
;
CommonIdtEntry::
;;
;; At this point, the stub has saved the current application stack esp into AppEsp
;; and switched stacks to the debug stack, where it pushed the vector number
;;
;; The application stack looks like this:
;;
;; ...
;; (last application stack entry)
;; eflags from interrupted task
;; CS from interrupted task
;; EIP from interrupted task
;; Error code <-------------------- Only present for some exeption types
;;
;;
;; The stub switched us to the debug stack and pushed the interrupt number.
;;
;; Next, construct the context record. It will be build on the debug stack by
;; pushing the registers in the correct order so as to create the context structure
;; on the debug stack. The context record must be built from the end back to the
;; beginning because the stack grows down...
;
;; For reference, the context record looks like this:
;;
;; typedef
;; struct {
;; UINT32 ExceptionData;
;; FX_SAVE_STATE FxSaveState;
;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
;; UINT32 Cr0, Cr2, Cr3, Cr4;
;; UINT32 Ldtr, Tr;
;; UINT64 Gdtr, Idtr;
;; UINT32 EFlags;
;; UINT32 Eip;
;; UINT32 SegGs, SegFs, SegEs, SegDs, SegCs, SegSs;
;; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;
;; } SYSTEM_CONTEXT_IA32; // 32 bit system context record
;; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;
pushad
;; Save interrupt state eflags register...
pushfd
pop eax
mov dword ptr Eflags, eax
;; We need to determine if any extra data was pushed by the exception, and if so, save it
;; To do this, we check the exception number pushed by the stub, and cache the
;; result in a variable since we'll need this again.
.IF ExceptionNumber == EXCPT32_DOUBLE_FAULT
mov ExtraPush, 1
.ELSEIF ExceptionNumber == EXCPT32_INVALID_TSS
mov ExtraPush, 1
.ELSEIF ExceptionNumber == EXCPT32_SEG_NOT_PRESENT
mov ExtraPush, 1
.ELSEIF ExceptionNumber == EXCPT32_STACK_FAULT
mov ExtraPush, 1
.ELSEIF ExceptionNumber == EXCPT32_GP_FAULT
mov ExtraPush, 1
.ELSEIF ExceptionNumber == EXCPT32_PAGE_FAULT
mov ExtraPush, 1
.ELSEIF ExceptionNumber == EXCPT32_ALIGNMENT_CHECK
mov ExtraPush, 1
.ELSE
mov ExtraPush, 0
.ENDIF
;; If there's some extra data, save it also, and modify the saved AppEsp to effectively
;; pop this value off the application's stack.
.IF ExtraPush == 1
mov eax, AppEsp
mov ebx, [eax]
mov ExceptData, ebx
add eax, 4
mov AppEsp, eax
.ELSE
mov ExceptData, 0
.ENDIF
;; The "pushad" above pushed the debug stack esp. Since what we're actually doing
;; is building the context record on the debug stack, we need to save the pushed
;; debug ESP, and replace it with the application's last stack entry...
mov eax, [esp + 12]
mov DebugEsp, eax
mov eax, AppEsp
add eax, 12
; application stack has eflags, cs, & eip, so
; last actual application stack entry is
; 12 bytes into the application stack.
mov [esp + 12], eax
;; continue building context record
;; UINT32 Gs, Fs, Es, Ds, Cs, Ss; insure high 16 bits of each is zero
mov eax, ss
push eax
; CS from application is one entry back in application stack
mov eax, AppEsp
movzx eax, word ptr [eax + 4]
push eax
mov eax, ds
push eax
mov eax, es
push eax
mov eax, fs
push eax
mov eax, gs
push eax
;; UINT32 Eip;
; Eip from application is on top of application stack
mov eax, AppEsp
push dword ptr [eax]
;; UINT64 Gdtr, Idtr;
push 0
push 0
sidt fword ptr [esp]
push 0
push 0
sgdt fword ptr [esp]
;; UINT32 Ldtr, Tr;
xor eax, eax
str ax
push eax
sldt ax
push eax
;; UINT32 EFlags;
;; Eflags from application is two entries back in application stack
mov eax, AppEsp
push dword ptr [eax + 8]
;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
;; insure FXSAVE/FXRSTOR is enabled in CR4...
;; ... while we're at it, make sure DE is also enabled...
mov eax, cr4
or eax, 208h
mov cr4, eax
push eax
mov eax, cr3
push eax
mov eax, cr2
push eax
push 0
mov eax, cr0
push eax
;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
mov eax, dr7
push eax
;; clear Dr7 while executing debugger itself
xor eax, eax
mov dr7, eax
mov eax, dr6
push eax
;; insure all status bits in dr6 are clear...
xor eax, eax
mov dr6, eax
mov eax, dr3
push eax
mov eax, dr2
push eax
mov eax, dr1
push eax
mov eax, dr0
push eax
;; FX_SAVE_STATE FxSaveState;
sub esp, 512
mov edi, esp
; IMPORTANT!! The debug stack has been carefully constructed to
; insure that esp and edi are 16 byte aligned when we get here.
; They MUST be. If they are not, a GP fault will occur.
FXSTOR_EDI
;; UINT32 ExceptionData;
mov eax, ExceptData
push eax
; call to C code which will in turn call registered handler
; pass in the vector number
mov eax, esp
push eax
mov eax, ExceptionNumber
push eax
call InterruptDistrubutionHub
add esp, 8
; restore context...
;; UINT32 ExceptionData;
add esp, 4
;; FX_SAVE_STATE FxSaveState;
mov esi, esp
FXRSTOR_ESI
add esp, 512
;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
pop eax
mov dr0, eax
pop eax
mov dr1, eax
pop eax
mov dr2, eax
pop eax
mov dr3, eax
;; skip restore of dr6. We cleared dr6 during the context save.
add esp, 4
pop eax
mov dr7, eax
;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
pop eax
mov cr0, eax
add esp, 4
pop eax
mov cr2, eax
pop eax
mov cr3, eax
pop eax
mov cr4, eax
;; UINT32 EFlags;
mov eax, AppEsp
pop dword ptr [eax + 8]
;; UINT16 Ldtr, Tr;
;; UINT64 Gdtr, Idtr;
;; Best not let anyone mess with these particular registers...
add esp, 24
;; UINT32 Eip;
pop dword ptr [eax]
;; UINT32 SegGs, SegFs, SegEs, SegDs, SegCs, SegSs;
;; NOTE - modified segment registers could hang the debugger... We
;; could attempt to insulate ourselves against this possibility,
;; but that poses risks as well.
;;
pop gs
pop fs
pop es
pop ds
pop [eax + 4]
pop ss
;; The next stuff to restore is the general purpose registers that were pushed
;; using the pushad instruction.
;;
;; The value of ESP as stored in the context record is the application ESP
;; including the 3 entries on the application stack caused by the exception
;; itself. It may have been modified by the debug agent, so we need to
;; determine if we need to relocate the application stack.
mov ebx, [esp + 12] ; move the potentially modified AppEsp into ebx
mov eax, AppEsp
add eax, 12
cmp ebx, eax
je NoAppStackMove
mov eax, AppEsp
mov ecx, [eax] ; EIP
mov [ebx], ecx
mov ecx, [eax + 4] ; CS
mov [ebx + 4], ecx
mov ecx, [eax + 8] ; EFLAGS
mov [ebx + 8], ecx
mov eax, ebx ; modify the saved AppEsp to the new AppEsp
mov AppEsp, eax
NoAppStackMove:
mov eax, DebugEsp ; restore the DebugEsp on the debug stack
; so our popad will not cause a stack switch
mov [esp + 12], eax
cmp ExceptionNumber, 068h
jne NoChain
Chain:
;; Restore eflags so when we chain, the flags will be exactly as if we were never here.
;; We gin up the stack to do an iretd so we can get ALL the flags.
mov eax, AppEsp
mov ebx, [eax + 8]
and ebx, NOT 300h ; special handling for IF and TF
push ebx
push cs
push PhonyIretd
iretd
PhonyIretd:
;; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;
popad
;; Switch back to application stack
mov esp, AppEsp
;; Jump to original handler
jmp OrigVector
NoChain:
;; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;
popad
;; Switch back to application stack
mov esp, AppEsp
;; We're outa here...
iretd
END

View File

@@ -0,0 +1,440 @@
/*++
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
plDebugSupport.c
Abstract:
IA32 specific debug support functions
Revision History
--*/
//
// private header files
//
#include "plDebugSupport.h"
//
// This the global main table to keep track of the interrupts
//
IDT_ENTRY *IdtEntryTable = NULL;
DESCRIPTOR NullDesc = 0;
#ifndef EFI_NT_EMULATOR
STATIC
EFI_STATUS
CreateEntryStub (
IN EFI_EXCEPTION_TYPE ExceptionType,
OUT VOID **Stub
)
/*++
Routine Description: Allocate pool for a new IDT entry stub. Copy the generic
stub into the new buffer and fixup the vector number and jump target address.
Arguments:
ExceptionType - This is the exception type that the new stub will be created
for.
Stub - On successful exit, *Stub contains the newly allocated entry stub.
Returns:
Typically EFI_SUCCESS
other possibilities are passed through from AllocatePool
--*/
{
EFI_STATUS Status;
UINT8 *StubCopy;
//
// First, allocate a new buffer and copy the stub code into it
//
Status = gBS->AllocatePool (EfiBootServicesData, StubSize, Stub);
if (Status == EFI_SUCCESS) {
StubCopy = *Stub;
gBS->CopyMem (StubCopy, InterruptEntryStub, StubSize);
//
// Next fixup the stub code for this vector
//
// The stub code looks like this:
//
// 00000000 89 25 00000004 R mov AppEsp, esp ; save stack top
// 00000006 BC 00008014 R mov esp, offset DbgStkBot ; switch to debugger stack
// 0000000B 6A 00 push 0 ; push vector number - will be modified before installed
// 0000000D E9 db 0e9h ; jump rel32
// 0000000E 00000000 dd 0 ; fixed up to relative address of CommonIdtEntry
//
//
// poke in the exception type so the second push pushes the exception type
//
StubCopy[0x0c] = (UINT8) ExceptionType;
//
// fixup the jump target to point to the common entry
//
*(UINT32 *) &StubCopy[0x0e] = (UINT32) CommonIdtEntry - (UINT32) &StubCopy[StubSize];
}
return Status;
}
STATIC
EFI_STATUS
HookEntry (
IN EFI_EXCEPTION_TYPE ExceptionType,
IN VOID (*NewCallback) ()
)
/*++
Routine Description:
Creates a nes entry stub. Then saves the current IDT entry and replaces it
with an interrupt gate for the new entry point. The IdtEntryTable is updated
with the new registered function.
This code executes in boot services context. The stub entry executes in interrupt
context.
Arguments:
ExceptionType - specifies which vector to hook.
NewCallback - a pointer to the new function to be registered.
Returns:
EFI_SUCCESS
Other possibilities are passed through by CreateEntryStub
--*/
// TODO: ) - add argument and description to function comment
{
BOOLEAN OldIntFlagState;
EFI_STATUS Status;
Status = CreateEntryStub (ExceptionType, (VOID **) &IdtEntryTable[ExceptionType].StubEntry);
if (Status == EFI_SUCCESS) {
OldIntFlagState = WriteInterruptFlag (0);
ReadIdt (ExceptionType, &(IdtEntryTable[ExceptionType].OrigDesc));
((UINT16 *) &IdtEntryTable[ExceptionType].OrigVector)[0] = ((UINT16 *) &IdtEntryTable[ExceptionType].OrigDesc)[0];
((UINT16 *) &IdtEntryTable[ExceptionType].OrigVector)[1] = ((UINT16 *) &IdtEntryTable[ExceptionType].OrigDesc)[3];
Vect2Desc (&IdtEntryTable[ExceptionType].NewDesc, IdtEntryTable[ExceptionType].StubEntry);
IdtEntryTable[ExceptionType].RegisteredCallback = NewCallback;
WriteIdt (ExceptionType, &(IdtEntryTable[ExceptionType].NewDesc));
WriteInterruptFlag (OldIntFlagState);
}
return Status;
}
STATIC
EFI_STATUS
UnhookEntry (
IN EFI_EXCEPTION_TYPE ExceptionType
)
/*++
Routine Description:
Undoes HookEntry. This code executes in boot services context.
Arguments:
ExceptionType - specifies which entry to unhook
Returns:
EFI_SUCCESS
Other values are passed through from FreePool
--*/
{
BOOLEAN OldIntFlagState;
EFI_STATUS Status;
OldIntFlagState = WriteInterruptFlag (0);
WriteIdt (ExceptionType, &(IdtEntryTable[ExceptionType].OrigDesc));
Status = gBS->FreePool ((VOID *) (UINTN) IdtEntryTable[ExceptionType].StubEntry);
ZeroMem (&IdtEntryTable[ExceptionType], sizeof (IDT_ENTRY));
WriteInterruptFlag (OldIntFlagState);
return (Status);
}
#endif
EFI_STATUS
ManageIdtEntryTable (
VOID (*NewCallback)(),
EFI_EXCEPTION_TYPE ExceptionType
)
/*++
Routine Description:
This is the main worker function that manages the state of the interrupt
handlers. It both installs and uninstalls interrupt handlers based on the
value of NewCallback. If NewCallback is NULL, then uninstall is indicated.
If NewCallback is non-NULL, then install is indicated.
Arguments:
NewCallback - If non-NULL, NewCallback specifies the new handler to register.
If NULL, specifies that the previously registered handler should
be uninstalled.
ExceptionType - Indicates which entry to manage
Returns:
EFI_SUCCESS
EFI_INVALID_PARAMETER - requested uninstalling a handler from a vector that has
no handler registered for it
EFI_ALREADY_STARTED - requested install to a vector that already has a handler registered.
Other possible return values are passed through from UnHookEntry and HookEntry.
--*/
// TODO: ) - add argument and description to function comment
{
EFI_STATUS Status;
Status = EFI_SUCCESS;
#ifndef EFI_NT_EMULATOR
if (CompareDescriptor (&IdtEntryTable[ExceptionType].NewDesc, &NullDesc)) {
//
// we've already installed to this vector
//
if (NewCallback != NULL) {
//
// if the input handler is non-null, error
//
Status = EFI_ALREADY_STARTED;
} else {
Status = UnhookEntry (ExceptionType);
}
} else {
//
// no user handler installed on this vector
//
if (NewCallback == NULL) {
//
// if the input handler is null, error
//
Status = EFI_INVALID_PARAMETER;
} else {
Status = HookEntry (ExceptionType, NewCallback);
}
}
#endif
return Status;
}
EFI_STATUS
EFIAPI
GetMaximumProcessorIndex (
IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
OUT UINTN *MaxProcessorIndex
)
/*++
Routine Description: This is a DebugSupport protocol member function.
Arguments:
Returns: Always returns EFI_SUCCESS with *MaxProcessorIndex set to 0
--*/
// TODO: This - add argument and description to function comment
// TODO: MaxProcessorIndex - add argument and description to function comment
{
*MaxProcessorIndex = 0;
return (EFI_SUCCESS);
}
EFI_STATUS
EFIAPI
RegisterPeriodicCallback (
IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
IN UINTN ProcessorIndex,
IN EFI_PERIODIC_CALLBACK PeriodicCallback
)
/*++
Routine Description: This is a DebugSupport protocol member function.
Arguments:
Returns:
--*/
// TODO: This - add argument and description to function comment
// TODO: ProcessorIndex - add argument and description to function comment
// TODO: PeriodicCallback - add argument and description to function comment
{
return ManageIdtEntryTable (PeriodicCallback, SYSTEM_TIMER_VECTOR);
}
EFI_STATUS
EFIAPI
RegisterExceptionCallback (
IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
IN UINTN ProcessorIndex,
IN EFI_EXCEPTION_CALLBACK NewCallback,
IN EFI_EXCEPTION_TYPE ExceptionType
)
/*++
Routine Description:
This is a DebugSupport protocol member function.
This code executes in boot services context.
Arguments:
Returns:
None
--*/
// TODO: This - add argument and description to function comment
// TODO: ProcessorIndex - add argument and description to function comment
// TODO: NewCallback - add argument and description to function comment
// TODO: ExceptionType - add argument and description to function comment
{
return ManageIdtEntryTable (NewCallback, ExceptionType);
}
EFI_STATUS
EFIAPI
InvalidateInstructionCache (
IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
IN UINTN ProcessorIndex,
IN VOID *Start,
IN UINT64 Length
)
/*++
Routine Description:
This is a DebugSupport protocol member function.
For IA32, this is a no-op since the instruction and data caches are coherent.
Arguments:
Returns:
None
--*/
// TODO: This - add argument and description to function comment
// TODO: ProcessorIndex - add argument and description to function comment
// TODO: Start - add argument and description to function comment
// TODO: Length - add argument and description to function comment
// TODO: EFI_SUCCESS - add return value to function comment
{
return EFI_SUCCESS;
}
EFI_STATUS
plInitializeDebugSupportDriver (
VOID
)
/*++
Routine Description:
Initializes driver's handler registration database.
This code executes in boot services context.
Arguments:
None
Returns:
EFI_SUCCESS
EFI_UNSUPPORTED - if IA32 processor does not support FXSTOR/FXRSTOR instructions,
the context save will fail, so these processor's are not supported.
--*/
// TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
{
if (!FxStorSupport ()) {
return EFI_UNSUPPORTED;
} else {
IdtEntryTable = AllocateZeroPool (sizeof (IDT_ENTRY) * NUM_IDT_ENTRIES);
if (IdtEntryTable != NULL) {
return EFI_SUCCESS;
} else {
return EFI_OUT_OF_RESOURCES;
}
}
}
EFI_STATUS
EFIAPI
plUnloadDebugSupportDriver (
IN EFI_HANDLE ImageHandle
)
/*++
Routine Description:
This is the callback that is written to the LoadedImage protocol instance
on the image handle. It uninstalls all registered handlers and frees all entry
stub memory.
This code executes in boot services context.
Arguments:
ImageHandle - The image handle of the unload handler
Returns:
None
--*/
// TODO: EFI_SUCCESS - add return value to function comment
{
EFI_EXCEPTION_TYPE ExceptionType;
for (ExceptionType = 0; ExceptionType < NUM_IDT_ENTRIES; ExceptionType++) {
ManageIdtEntryTable (NULL, ExceptionType);
}
gBS->FreePool (IdtEntryTable);
return EFI_SUCCESS;
}
VOID
InterruptDistrubutionHub (
EFI_EXCEPTION_TYPE ExceptionType,
EFI_SYSTEM_CONTEXT_IA32 *ContextRecord
)
/*++
Routine Description: Common piece of code that invokes the registered handlers.
This code executes in exception context so no efi calls are allowed.
Arguments:
Returns:
None
--*/
// TODO: ExceptionType - add argument and description to function comment
// TODO: ContextRecord - add argument and description to function comment
{
if (IdtEntryTable[ExceptionType].RegisteredCallback != NULL) {
if (ExceptionType != SYSTEM_TIMER_VECTOR) {
IdtEntryTable[ExceptionType].RegisteredCallback (ExceptionType, ContextRecord);
} else {
OrigVector = IdtEntryTable[ExceptionType].OrigVector;
IdtEntryTable[ExceptionType].RegisteredCallback (ContextRecord);
}
}
}

View File

@@ -0,0 +1,312 @@
/*++
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
plDebugSupport.h
Abstract:
IA32 specific debug support macros, typedefs and prototypes.
Revision History
--*/
#ifndef _PLDEBUG_SUPPORT_H
#define _PLDEBUG_SUPPORT_H
#define NUM_IDT_ENTRIES 0x78
#define SYSTEM_TIMER_VECTOR 0x68
#define VECTOR_ENTRY_PAGES 1
#define CopyDescriptor(Dest, Src) CopyMem ((Dest), (Src), sizeof (DESCRIPTOR))
#define ZeroDescriptor(Dest) CopyDescriptor ((Dest), &NullDesc)
#define ReadIdt(Vector, Dest) CopyDescriptor ((Dest), &((GetIdtr ())[(Vector)]))
#define WriteIdt(Vector, Src) CopyDescriptor (&((GetIdtr ())[(Vector)]), (Src))
#define CompareDescriptor(Desc1, Desc2) CompareMem ((Desc1), (Desc2), sizeof (DESCRIPTOR))
#define EFI_ISA IsaIa32
#define FF_FXSR (1 << 24)
typedef UINT64 DESCRIPTOR;
typedef struct {
DESCRIPTOR OrigDesc;
VOID (*OrigVector) (VOID);
DESCRIPTOR NewDesc;
VOID (*StubEntry) (VOID);
VOID (*RegisteredCallback) ();
} IDT_ENTRY;
extern EFI_SYSTEM_CONTEXT SystemContext;
extern UINT8 InterruptEntryStub[];
extern UINT32 StubSize;
extern VOID (*OrigVector) (VOID);
VOID
CommonIdtEntry (
VOID
)
/*++
Routine Description:
TODO: Add function description
Arguments:
None
Returns:
TODO: add return values
--*/
;
BOOLEAN
FxStorSupport (
VOID
)
/*++
Routine Description:
TODO: Add function description
Arguments:
None
Returns:
TODO: add return values
--*/
;
DESCRIPTOR *
GetIdtr (
VOID
)
/*++
Routine Description:
TODO: Add function description
Arguments:
None
Returns:
TODO: add return values
--*/
;
VOID
Vect2Desc (
DESCRIPTOR * DestDesc,
VOID (*Vector) (VOID)
)
/*++
Routine Description:
TODO: Add function description
Arguments:
DestDesc - TODO: add argument description
) - TODO: add argument description
Returns:
TODO: add return values
--*/
;
BOOLEAN
WriteInterruptFlag (
BOOLEAN NewState
)
/*++
Routine Description:
TODO: Add function description
Arguments:
NewState - TODO: add argument description
Returns:
TODO: add return values
--*/
;
EFI_STATUS
plInitializeDebugSupportDriver (
VOID
)
/*++
Routine Description:
TODO: Add function description
Arguments:
None
Returns:
TODO: add return values
--*/
;
EFI_STATUS
EFIAPI
plUnloadDebugSupportDriver (
IN EFI_HANDLE ImageHandle
)
/*++
Routine Description:
TODO: Add function description
Arguments:
ImageHandle - TODO: add argument description
Returns:
TODO: add return values
--*/
;
//
// DebugSupport protocol member functions
//
EFI_STATUS
EFIAPI
GetMaximumProcessorIndex (
IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
OUT UINTN *MaxProcessorIndex
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
MaxProcessorIndex - TODO: add argument description
Returns:
TODO: add return values
--*/
;
EFI_STATUS
EFIAPI
RegisterPeriodicCallback (
IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
IN UINTN ProcessorIndex,
IN EFI_PERIODIC_CALLBACK PeriodicCallback
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
ProcessorIndex - TODO: add argument description
PeriodicCallback - TODO: add argument description
Returns:
TODO: add return values
--*/
;
EFI_STATUS
EFIAPI
RegisterExceptionCallback (
IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
IN UINTN ProcessorIndex,
IN EFI_EXCEPTION_CALLBACK NewCallback,
IN EFI_EXCEPTION_TYPE ExceptionType
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
ProcessorIndex - TODO: add argument description
NewCallback - TODO: add argument description
ExceptionType - TODO: add argument description
Returns:
TODO: add return values
--*/
;
EFI_STATUS
EFIAPI
InvalidateInstructionCache (
IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
IN UINTN ProcessorIndex,
IN VOID *Start,
IN UINT64 Length
)
/*++
Routine Description:
TODO: Add function description
Arguments:
This - TODO: add argument description
ProcessorIndex - TODO: add argument description
Start - TODO: add argument description
Length - TODO: add argument description
Returns:
TODO: add return values
--*/
;
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,85 @@
//++
// Copyright (c) 2006, Intel Corporation
// All rights reserved. This program and the accompanying materials
// are licensed and made available under the terms and conditions of the BSD License
// which accompanies this distribution. The full text of the license may be found at
// http://opensource.org/licenses/bsd-license.php
//
// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
//
// Module Name:
//
// Ds64Macros.i
//
// Abstract:
//
// This is set of macros used in calculating offsets in the IVT
//
// Revision History:
//
//--
#define EXCPT_EXTERNAL_INTERRUPT 12
#define MASK_0_4 0x000000000000001F // mask bits 0 through 4
#define SLOT0 0
#define SLOT1 1
#define SLOT2 2
#define PSR_DT 17
#define PSR_TB 26
#define PSR_RT 27
#define PSR_IS 34
#define PSR_IT 36
#define PSR_IC 13
#define PSR_I 14
#define PSR_SS 40
#define PSR_BN 44
#define PSR_RI_MASK 0x60000000000
#define EXCPT_EXTERNAL_INTERRUPT 12
#define SCRATCH_REG0 r23
#define SCRATCH_REG1 r24
#define SCRATCH_REG2 r25
#define SCRATCH_REG3 r26
#define SCRATCH_REG4 r27
#define SCRATCH_REG5 r28
#define SCRATCH_REG6 r29
#define PR_REG r30
#define B0_REG r31
// EXT_INT_OFFSET is the offset of the external interrupt entry in the IVT
#define EXT_INT_ENTRY_OFFSET 0x03000
// PATCH_ENTRY_OFFSET is the offset into the IVT of the entry that is coopted (stolen)
// for use by the handler. The entire entry is restored when the handler is
// unloaded.
#define PATCH_ENTRY_OFFSET 0x03400
// PATCH_BUNDLES is the number of bundles actually in the patch
#define NUM_PATCH_BUNDLES ((EndPatchCode - PatchCode) / 0x10)
// A hard coded branch back into the external interrupt IVT entry's second bundle
// is put here, just in case the original bundle zero did not have a branch
// This is the last bundle in the reserved IVT entry
#define FAILSAFE_BRANCH_OFFSET (PATCH_ENTRY_OFFSET + 0x400 - 0x10)
// the original external interrupt IVT entry bundle zero is copied and relocated
// here... also in the reserved IVT entry
// This is the second-to-last bundle in the reserved IVT entry
#define RELOCATED_EXT_INT (PATCH_ENTRY_OFFSET + 0x400 - 0x20)
// The patch is actually stored at the end of IVT:PATCH_ENTRY. The PATCH_OFFSET
// is the offset into IVT where the patch is actually stored. It is carefully
// located so that when we run out of patch code, the next bundle is the
// relocated bundle 0 from the original external interrupt handler
#define PATCH_OFFSET (PATCH_ENTRY_OFFSET + 0x400 - ( EndPatchCode - PatchCode ) - 0x20)
#define PATCH_RETURN_OFFSET (PATCH_ENTRY_OFFSET + 0x400 - ( EndPatchCode - PatchCodeRet ) - 0x20)
// PATCH_BRANCH is used only in the new bundle that is placed at the beginning
// of the external interrupt IVT entry.
#define PATCH_BRANCH (PATCH_OFFSET - EXT_INT_ENTRY_OFFSET)

View File

@@ -0,0 +1,34 @@
//++
// Copyright (c) 2006, Intel Corporation
// All rights reserved. This program and the accompanying materials
// are licensed and made available under the terms and conditions of the BSD License
// which accompanies this distribution. The full text of the license may be found at
// http://opensource.org/licenses/bsd-license.php
//
// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
//
// Module Name:
//
// Common.i
//
// Abstract:
//
// This is set of useful macros
//
// Revision History:
//
//--
#define NESTED_SETUP(i,l,o,r) \
alloc loc1=ar##.##pfs,i,l,o,r ; \
mov loc0=b0 ;;
#define NESTED_RETURN \
mov b0=loc0 ; \
mov ar##.##pfs=loc1 ;; \
br##.##ret##.##dpnt b0 ;;
#define MASK(bp,value) (value << bp)

View File

@@ -0,0 +1,625 @@
/*++
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
PlDebugSupport.c
Abstract:
IPF specific debug support functions
Revision History
--*/
//
// Master EFI header file
//
#include "Tiano.h"
//
// Common library header files
//
#include "EfiDriverLib.h"
//
// Produced protocols
//
#include EFI_PROTOCOL_DEFINITION (DebugSupport)
//
// private header files
//
#include "plDebugSupport.h"
typedef struct {
UINT64 low;
UINT64 high;
} BUNDLE;
//
// number of bundles to swap in ivt
//
#define NUM_BUNDLES_IN_STUB 5
#define NUM_IVT_ENTRIES 64
typedef struct {
BUNDLE OrigBundles[NUM_BUNDLES_IN_STUB];
VOID (*RegisteredCallback) ();
} IVT_ENTRY;
STATIC
EFI_STATUS
ManageIvtEntryTable (
IN EFI_EXCEPTION_TYPE ExceptionType,
IN BUNDLE NewBundles[4],
IN VOID (*NewCallback) ()
);
STATIC
VOID
HookEntry (
IN EFI_EXCEPTION_TYPE ExceptionType,
IN BUNDLE NewBundles[4],
IN VOID (*NewCallback) ()
);
STATIC
VOID
UnhookEntry (
IN EFI_EXCEPTION_TYPE ExceptionType
);
STATIC
VOID
ChainExternalInterrupt (
IN VOID (*NewCallback) ()
);
STATIC
VOID
UnchainExternalInterrupt (
VOID
);
STATIC
VOID
GetHandlerEntryPoint (
UINTN HandlerIndex,
VOID **EntryPoint
);
IVT_ENTRY IvtEntryTable[NUM_IVT_ENTRIES];
//
// IPF context record is overallocated by 512 bytes to guarantee a 512 byte alignment exists
// within the buffer and still have a large enough buffer to hold a whole IPF context record.
//
UINT8 IpfContextBuf[sizeof (EFI_SYSTEM_CONTEXT_IPF) + 512];
//
// The PatchSaveBuffer is used to store the original bundles from the IVT where it is patched
// with the common handler.
//
UINT8 PatchSaveBuffer[0x400];
UINTN ExternalInterruptCount;
EFI_STATUS
plInitializeDebugSupportDriver (
VOID
)
/*++
Routine Description:
IPF specific DebugSupport driver initialization. Must be public because it's
referenced from DebugSupport.c
Arguments:
Returns:
EFI_SUCCESS
--*/
{
gBS->SetMem (IvtEntryTable, sizeof (IvtEntryTable), 0);
ExternalInterruptCount = 0;
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
plUnloadDebugSupportDriver (
IN EFI_HANDLE ImageHandle
)
/*++
Routine Description:
Unload handler that is called during UnloadImage() - deallocates pool memory
used by the driver. Must be public because it's referenced from DebugSuport.c
Arguments:
IN EFI_HANDLE ImageHandle
Returns:
EFI_STATUS - anything other than EFI_SUCCESS indicates the callback was not registered.
--*/
// TODO: ImageHandle - add argument and description to function comment
{
EFI_EXCEPTION_TYPE ExceptionType;
for (ExceptionType = 0; ExceptionType < NUM_IVT_ENTRIES; ExceptionType++) {
ManageIvtEntryTable (ExceptionType, NULL, NULL);
}
return EFI_SUCCESS;
}
VOID
CommonHandler (
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT Context
)
/*++
Routine Description:
C routine that is called for all registered exceptions. This is the main
exception dispatcher. Must be public because it's referenced from AsmFuncs.s.
Arguments:
IN EFI_EXCEPTION_TYPE ExceptionType,
IN EFI_SYSTEM_CONTEXT Context
Returns:
Nothing
--*/
// TODO: ExceptionType - add argument and description to function comment
// TODO: Context - add argument and description to function comment
{
static BOOLEAN InHandler = FALSE;
DEBUG_CODE (
if (InHandler) {
EfiDebugPrint (EFI_D_GENERIC, "ERROR: Re-entered debugger!\n"
" ExceptionType == %X\n"
" Context == %X\n"
" Context.SystemContextIpf->CrIip == %X\n"
" Context.SystemContextIpf->CrIpsr == %X\n"
" InHandler == %X\n",
ExceptionType,
Context,
Context.SystemContextIpf->CrIip,
Context.SystemContextIpf->CrIpsr,
InHandler);
}
)
ASSERT (!InHandler);
InHandler = TRUE;
if (IvtEntryTable[ExceptionType].RegisteredCallback != NULL) {
if (ExceptionType != EXCEPT_IPF_EXTERNAL_INTERRUPT) {
IvtEntryTable[ExceptionType].RegisteredCallback (ExceptionType, Context.SystemContextIpf);
} else {
IvtEntryTable[ExceptionType].RegisteredCallback (Context.SystemContextIpf);
}
} else {
ASSERT (0);
}
InHandler = FALSE;
}
STATIC
VOID
GetHandlerEntryPoint (
UINTN HandlerIndex,
VOID **EntryPoint
)
/*++
Routine Description:
Given an integer number, return the physical address of the entry point in the IFT
Arguments:
UINTN HandlerIndex,
VOID ** EntryPoint
Returns:
Nothing
--*/
// TODO: HandlerIndex - add argument and description to function comment
// TODO: EntryPoint - add argument and description to function comment
{
UINT8 *TempPtr;
//
// get base address of IVT
//
TempPtr = GetIva ();
if (HandlerIndex < 20) {
//
// first 20 provide 64 bundles per vector
//
TempPtr += 0x400 * HandlerIndex;
} else {
//
// the rest provide 16 bundles per vector
//
TempPtr += 0x5000 + 0x100 * (HandlerIndex - 20);
}
*EntryPoint = (VOID *) TempPtr;
}
STATIC
EFI_STATUS
ManageIvtEntryTable (
IN EFI_EXCEPTION_TYPE ExceptionType,
IN BUNDLE NewBundles[NUM_BUNDLES_IN_STUB],
IN VOID (*NewCallback) ()
)
/*++
Routine Description:
This is the worker function that installs and removes all handlers
Arguments:
IN EFI_EXCEPTION_TYPE ExceptionType,
IN BUNDLE NewBundles[NUM_BUNDLES_IN_STUB],
IN VOID (*NewCallback) ()
Returns:
EFI_STATUS - any return other than EFI_SUCCESS indicates the request was not
satisfied.
--*/
// TODO: ExceptionType - add argument and description to function comment
// TODO: ] - add argument and description to function comment
// TODO: ) - add argument and description to function comment
// TODO: EFI_ALREADY_STARTED - add return value to function comment
{
BUNDLE *B0Ptr;
UINT64 InterruptFlags;
EFI_TPL OldTpl;
//
// Get address of bundle 0
//
GetHandlerEntryPoint (ExceptionType, (VOID **) &B0Ptr);
if (IvtEntryTable[ExceptionType].RegisteredCallback != NULL) {
//
// we've already installed to this vector
//
if (NewCallback != NULL) {
//
// if the input handler is non-null, error
//
return EFI_ALREADY_STARTED;
} else {
//
// else remove the previously installed handler
//
OldTpl = gBS->RaiseTPL (EFI_TPL_HIGH_LEVEL);
InterruptFlags = ProgramInterruptFlags (DISABLE_INTERRUPTS);
if (ExceptionType == EXCEPT_IPF_EXTERNAL_INTERRUPT) {
UnchainExternalInterrupt ();
} else {
UnhookEntry (ExceptionType);
}
ProgramInterruptFlags (InterruptFlags);
gBS->RestoreTPL (OldTpl);
//
// re-init IvtEntryTable
//
gBS->SetMem (&IvtEntryTable[ExceptionType], sizeof (IVT_ENTRY), 0);
}
} else {
//
// no user handler installed on this vector
//
if (NewCallback != NULL) {
OldTpl = gBS->RaiseTPL (EFI_TPL_HIGH_LEVEL);
InterruptFlags = ProgramInterruptFlags (DISABLE_INTERRUPTS);
if (ExceptionType == EXCEPT_IPF_EXTERNAL_INTERRUPT) {
ChainExternalInterrupt (NewCallback);
} else {
HookEntry (ExceptionType, NewBundles, NewCallback);
}
ProgramInterruptFlags (InterruptFlags);
gBS->RestoreTPL (OldTpl);
}
}
return EFI_SUCCESS;
}
STATIC
VOID
HookEntry (
IN EFI_EXCEPTION_TYPE ExceptionType,
IN BUNDLE NewBundles[4],
IN VOID (*NewCallback) ()
)
/*++
Routine Description:
Saves original IVT contents and inserts a few new bundles which are fixed up
to store the ExceptionType and then call the common handler.
Arguments:
IN EFI_EXCEPTION_TYPE ExceptionType,
IN BUNDLE NewBundles[4],
IN VOID (*NewCallback) ()
Returns:
Nothing
--*/
// TODO: ExceptionType - add argument and description to function comment
// TODO: ] - add argument and description to function comment
// TODO: ) - add argument and description to function comment
{
BUNDLE *FixupBundle;
BUNDLE *B0Ptr;
//
// Get address of bundle 0
//
GetHandlerEntryPoint (ExceptionType, (VOID **) &B0Ptr);
//
// copy original bundles from IVT to IvtEntryTable so we can restore them later
//
gBS->CopyMem (
IvtEntryTable[ExceptionType].OrigBundles,
B0Ptr,
sizeof (BUNDLE) * NUM_BUNDLES_IN_STUB
);
//
// insert new B0
//
gBS->CopyMem (B0Ptr, NewBundles, sizeof (BUNDLE) * NUM_BUNDLES_IN_STUB);
//
// fixup IVT entry so it stores its index and whether or not to chain...
//
FixupBundle = B0Ptr + 2;
FixupBundle->high |= ExceptionType << 36;
InstructionCacheFlush (B0Ptr, 5);
IvtEntryTable[ExceptionType].RegisteredCallback = NewCallback;
}
STATIC
VOID
UnhookEntry (
IN EFI_EXCEPTION_TYPE ExceptionType
)
/*++
Routine Description:
Restores original IVT contents when unregistering a callback function
Arguments:
IN EFI_EXCEPTION_TYPE ExceptionType,
Returns:
Nothing
--*/
// TODO: ExceptionType - add argument and description to function comment
{
BUNDLE *B0Ptr;
//
// Get address of bundle 0
//
GetHandlerEntryPoint (ExceptionType, (VOID **) &B0Ptr);
//
// restore original bundles in IVT
//
gBS->CopyMem (
B0Ptr,
IvtEntryTable[ExceptionType].OrigBundles,
sizeof (BUNDLE) * NUM_BUNDLES_IN_STUB
);
InstructionCacheFlush (B0Ptr, 5);
}
STATIC
VOID
ChainExternalInterrupt (
IN VOID (*NewCallback) ()
)
/*++
Routine Description:
Sets up cache flush and calls assembly function to chain external interrupt.
Records new callback in IvtEntryTable.
Arguments:
IN VOID (*NewCallback) ()
Returns:
Nothing
--*/
// TODO: ) - add argument and description to function comment
{
VOID *Start;
Start = (VOID *) ((UINT8 *) GetIva () + 0x400 * EXCEPT_IPF_EXTERNAL_INTERRUPT + 0x400);
IvtEntryTable[EXCEPT_IPF_EXTERNAL_INTERRUPT].RegisteredCallback = NewCallback;
ChainHandler ();
InstructionCacheFlush (Start, 0x400);
}
STATIC
VOID
UnchainExternalInterrupt (
VOID
)
/*++
Routine Description:
Sets up cache flush and calls assembly function to restore external interrupt.
Removes registered callback from IvtEntryTable.
Arguments:
Nothing
Returns:
Nothing
--*/
{
VOID *Start;
Start = (VOID *) ((UINT8 *) GetIva () + 0x400 * EXCEPT_IPF_EXTERNAL_INTERRUPT + 0x400);
UnchainHandler ();
InstructionCacheFlush (Start, 0x400);
IvtEntryTable[EXCEPT_IPF_EXTERNAL_INTERRUPT].RegisteredCallback = NULL;
}
//
// The rest of the functions in this file are all member functions for the
// DebugSupport protocol
//
EFI_STATUS
EFIAPI
GetMaximumProcessorIndex (
IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
OUT UINTN *MaxProcessorIndex
)
/*++
Routine Description: This is a DebugSupport protocol member function. Hard
coded to support only 1 processor for now.
Arguments:
Returns: Always returns EFI_SUCCESS with *MaxProcessorIndex set to 0
--*/
// TODO: This - add argument and description to function comment
// TODO: MaxProcessorIndex - add argument and description to function comment
{
*MaxProcessorIndex = 0;
return (EFI_SUCCESS);
}
EFI_STATUS
EFIAPI
RegisterPeriodicCallback (
IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
IN UINTN ProcessorIndex,
IN EFI_PERIODIC_CALLBACK NewPeriodicCallback
)
/*++
Routine Description:
DebugSupport protocol member function
Arguments:
IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
IN UINTN ProcessorIndex,
IN EFI_PERIODIC_CALLBACK NewPeriodicCallback
Returns:
EFI_STATUS - anything other than EFI_SUCCESS indicates the callback was not registered.
--*/
// TODO: This - add argument and description to function comment
// TODO: ProcessorIndex - add argument and description to function comment
// TODO: NewPeriodicCallback - add argument and description to function comment
{
return ManageIvtEntryTable (EXCEPT_IPF_EXTERNAL_INTERRUPT, NULL, NewPeriodicCallback);
}
EFI_STATUS
EFIAPI
RegisterExceptionCallback (
IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
IN UINTN ProcessorIndex,
IN EFI_EXCEPTION_CALLBACK NewCallback,
IN EFI_EXCEPTION_TYPE ExceptionType
)
/*++
Routine Description:
DebugSupport protocol member function
Arguments:
IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
IN EFI_EXCEPTION_CALLBACK NewCallback,
IN EFI_EXCEPTION_TYPE ExceptionType
Returns:
EFI_STATUS - anything other than EFI_SUCCESS indicates the callback was not registered.
--*/
// TODO: This - add argument and description to function comment
// TODO: ProcessorIndex - add argument and description to function comment
// TODO: NewCallback - add argument and description to function comment
// TODO: ExceptionType - add argument and description to function comment
{
return ManageIvtEntryTable (
ExceptionType,
(BUNDLE *) ((EFI_PLABEL *) HookStub)->EntryPoint,
NewCallback
);
}
EFI_STATUS
EFIAPI
InvalidateInstructionCache (
IN EFI_DEBUG_SUPPORT_PROTOCOL *This,
IN UINTN ProcessorIndex,
IN VOID *Start,
IN UINTN Length
)
/*++
Routine Description:
DebugSupport protocol member function. Calls assembly routine to flush cache.
Arguments:
Returns:
EFI_SUCCESS
--*/
// TODO: This - add argument and description to function comment
// TODO: ProcessorIndex - add argument and description to function comment
// TODO: Start - add argument and description to function comment
// TODO: Length - add argument and description to function comment
{
InstructionCacheFlush (Start, Length);
return (EFI_SUCCESS);
}