--- /dev/null
+#******************************************************************************
+#*
+#* 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.
+#*
+#******************************************************************************
+
+.global _OrigVector
+.global _InterruptEntryStub
+.global _StubSize
+.global _CommonIdtEntry
+.global _FxStorSupport
+
+_AppEsp: .long 0x11111111 # ?
+_DebugEsp: .long 0x22222222 # ?
+_ExtraPush: .long 0x33333333 # ?
+_ExceptData: .long 0x44444444 # ?
+_Eflags: .long 0x55555555 # ?
+_OrigVector: .long 0x66666666 # ?
+_StubSize: .long _InterruptEntryStubEnd - _InterruptEntryStub
+
+.global _FxStorSupport
+_FxStorSupport:
+ push %ebx
+ mov $0x1,%eax
+ cpuid
+ mov %edx,%eax
+ and $0x1000000,%eax
+ shr $0x18,%eax
+ pop %ebx
+ ret
+
+.global _GetIdtr
+_GetIdtr:
+ push %ebp
+ mov %esp,%ebp
+ add $0xfffffff8,%esp
+ sidtl 0xfffffffa(%ebp)
+ mov 0xfffffffc(%ebp),%eax
+ leave
+ ret
+
+.global _WriteInterruptFlag
+_WriteInterruptFlag:
+ push %ebp
+ mov %esp,%ebp
+ pushf
+ pop %eax
+ and $0x200,%eax
+ shr $0x9,%eax
+ mov 0x8(%ebp),%ecx
+ or %ecx,%ecx
+ jne _WriteInterruptFlag+0x17
+ cli
+ jmp _WriteInterruptFlag+0x18
+ sti
+ leave
+ ret
+
+.global _Vect2Desc
+_Vect2Desc:
+ push %ebp
+ mov %esp,%ebp
+ mov 0xc(%ebp),%eax
+ mov 0x8(%ebp),%ecx
+ mov %ax,(%ecx)
+ movw $0x20,0x2(%ecx)
+ movw $0x8e00,0x4(%ecx)
+ shr $0x10,%eax
+ mov %ax,0x6(%ecx)
+ leave
+ ret
+
+.global _InterruptEntryStub
+_InterruptEntryStub:
+ mov %esp,0x0
+ mov $0x0,%esp
+ push $0x0
+ jmp _CommonIdtEntry
+.global _InterruptEntryStubEnd
+_InterruptEntryStubEnd:
+
+.global _CommonIdtEntry
+_CommonIdtEntry:
+ pusha
+ pushf
+ pop %eax
+ mov %eax,0x0
+ cmpl $0x8,0x0
+ jne _CommonIdtEntry+0x20
+ movl $0x1,0x0
+ jmp _CommonIdtEntry+0xa8
+ cmpl $0xa,0x0
+ jne _CommonIdtEntry+0x35
+ movl $0x1,0x0
+ jmp _CommonIdtEntry+0xa8
+ cmpl $0xb,0x0
+ jne _CommonIdtEntry+0x4a
+ movl $0x1,0x0
+ jmp _CommonIdtEntry+0xa8
+ cmpl $0xc,0x0
+ jne _CommonIdtEntry+0x5f
+ movl $0x1,0x0
+ jmp _CommonIdtEntry+0xa8
+ cmpl $0xd,0x0
+ jne _CommonIdtEntry+0x74
+ movl $0x1,0x0
+ jmp _CommonIdtEntry+0xa8
+ cmpl $0xe,0x0
+ jne _CommonIdtEntry+0x89
+ movl $0x1,0x0
+ jmp _CommonIdtEntry+0xa8
+ cmpl $0x11,0x0
+ jne _CommonIdtEntry+0x9e
+ movl $0x1,0x0
+ jmp _CommonIdtEntry+0xa8
+ movl $0x0,0x0
+ cmpl $0x1,0x0
+ jne _CommonIdtEntry+0xc8
+ mov 0x0,%eax
+ mov (%eax),%ebx
+ mov %ebx,0x0
+ add $0x4,%eax
+ mov %eax,0x0
+ jmp _CommonIdtEntry+0xd2
+ movl $0x0,0x0
+ mov 0xc(%esp),%eax
+ mov %eax,0x0
+ mov 0x0,%eax
+ add $0xc,%eax
+ mov %eax,0xc(%esp)
+ mov %ss,%eax
+ push %eax
+ mov 0x0,%eax
+ movzwl 0x4(%eax),%eax
+ push %eax
+ mov %ds,%eax
+ push %eax
+ mov %es,%eax
+ push %eax
+ mov %fs,%eax
+ push %eax
+ mov %gs,%eax
+ push %eax
+ mov 0x0,%eax
+ pushl (%eax)
+ push $0x0
+ push $0x0
+ sidtl (%esp)
+ push $0x0
+ push $0x0
+ sgdtl (%esp)
+ xor %eax,%eax
+ str %eax
+ push %eax
+ sldt %eax
+ push %eax
+ mov 0x0,%eax
+ pushl 0x8(%eax)
+ mov %cr4,%eax
+ or $0x208,%eax
+ mov %eax,%cr4
+ push %eax
+ mov %cr3,%eax
+ push %eax
+ mov %cr2,%eax
+ push %eax
+ push $0x0
+ mov %cr0,%eax
+ push %eax
+ mov %db7,%eax
+ push %eax
+ xor %eax,%eax
+ mov %eax,%db7
+ mov %db6,%eax
+ push %eax
+ xor %eax,%eax
+ mov %eax,%db6
+ mov %db3,%eax
+ push %eax
+ mov %db2,%eax
+ push %eax
+ mov %db1,%eax
+ push %eax
+ mov %db0,%eax
+ push %eax
+ sub $0x200,%esp
+ mov %esp,%edi
+ fxsave (%edi)
+ mov 0x0,%eax
+ push %eax
+ mov %esp,%eax
+ push %eax
+ mov 0x0,%eax
+ push %eax
+ call _CommonIdtEntry+0x184
+ add $0x8,%esp
+ add $0x4,%esp
+ mov %esp,%esi
+ fxrstor (%esi)
+ add $0x200,%esp
+ pop %eax
+ mov %eax,%db0
+ pop %eax
+ mov %eax,%db1
+ pop %eax
+ mov %eax,%db2
+ pop %eax
+ mov %eax,%db3
+ add $0x4,%esp
+ pop %eax
+ mov %eax,%db7
+ pop %eax
+ mov %eax,%cr0
+ add $0x4,%esp
+ pop %eax
+ mov %eax,%cr2
+ pop %eax
+ mov %eax,%cr3
+ pop %eax
+ mov %eax,%cr4
+ mov 0x0,%eax
+ popl 0x8(%eax)
+ add $0x18,%esp
+ popl (%eax)
+ pop %gs
+ pop %fs
+ pop %es
+ pop %ds
+ popl 0x4(%eax)
+ pop %ss
+ mov 0xc(%esp),%ebx
+ mov 0x0,%eax
+ add $0xc,%eax
+ cmp %eax,%ebx
+ je _CommonIdtEntry+0x202
+ mov 0x0,%eax
+ mov (%eax),%ecx
+ mov %ecx,(%ebx)
+ mov 0x4(%eax),%ecx
+ mov %ecx,0x4(%ebx)
+ mov 0x8(%eax),%ecx
+ mov %ecx,0x8(%ebx)
+ mov %ebx,%eax
+ mov %eax,0x0
+ mov 0x0,%eax
+ mov %eax,0xc(%esp)
+ cmpl $0x68,0x0
+ jne PhonyIretd+0xd
+ mov 0x0,%eax
+ mov 0x8(%eax),%ebx
+ and $0xfffffcff,%ebx
+ push %ebx
+ push %cs
+ push $0x0
+ iret
+
+PhonyIretd:
+ popa
+ mov 0x0,%esp
+ jmp *0x0
+ popa
+ mov 0x0,%esp
+ iret
--- /dev/null
+;******************************************************************************\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
+.586p\r
+.MODEL FLAT, C\r
+\r
+EXCPT32_DIVIDE_ERROR EQU 0\r
+EXCPT32_DEBUG EQU 1\r
+EXCPT32_NMI EQU 2\r
+EXCPT32_BREAKPOINT EQU 3\r
+EXCPT32_OVERFLOW EQU 4\r
+EXCPT32_BOUND EQU 5\r
+EXCPT32_INVALID_OPCODE EQU 6\r
+EXCPT32_DOUBLE_FAULT EQU 8\r
+EXCPT32_INVALID_TSS EQU 10\r
+EXCPT32_SEG_NOT_PRESENT EQU 11\r
+EXCPT32_STACK_FAULT EQU 12\r
+EXCPT32_GP_FAULT EQU 13\r
+EXCPT32_PAGE_FAULT EQU 14\r
+EXCPT32_FP_ERROR EQU 16\r
+EXCPT32_ALIGNMENT_CHECK EQU 17\r
+EXCPT32_MACHINE_CHECK EQU 18\r
+EXCPT32_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 [edi]\r
+FXSTOR_EDI MACRO\r
+ db 0fh, 0aeh, 00000111y ; mod = 00, reg/op = 000, r/m = 111 = [edi]\r
+ENDM\r
+\r
+;; fxrstor [esi]\r
+FXRSTOR_ESI MACRO\r
+ db 0fh, 0aeh, 00001110y ; mod = 00, reg/op = 001, r/m = 110 = [esi]\r
+ENDM\r
+.DATA\r
+\r
+public OrigVector, InterruptEntryStub, StubSize, CommonIdtEntry, FxStorSupport\r
+\r
+StubSize dd InterruptEntryStubEnd - InterruptEntryStub\r
+AppEsp dd 11111111h ; ?\r
+DebugEsp dd 22222222h ; ?\r
+ExtraPush dd 33333333h ; ?\r
+ExceptData dd 44444444h ; ?\r
+Eflags dd 55555555h ; ?\r
+OrigVector dd 66666666h ; ?\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 132 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 - 132 - 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
+;; 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
+;; } SYSTEM_CONTEXT_IA32; // 32 bit system context record\r
+\r
+\r
+align 16\r
+DebugStackEnd db "DbgStkEnd >>>>>>" ;; 16 byte long string - must be 16 bytes to preserve alignment\r
+ dd 1ffdh 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 dd ? ;; 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
+.CODE\r
+\r
+externdef InterruptDistrubutionHub:near\r
+\r
+;------------------------------------------------------------------------------\r
+; BOOLEAN\r
+; FxStorSupport (\r
+; void\r
+; )\r
+;\r
+; Abstract: Returns TRUE if FxStor instructions are supported\r
+;\r
+FxStorSupport PROC C PUBLIC\r
+\r
+;\r
+; cpuid corrupts ebx which must be preserved per the C calling convention\r
+;\r
+ push ebx\r
+ mov eax, 1\r
+ cpuid\r
+ mov eax, edx\r
+ and eax, FXSTOR_FLAG\r
+ shr eax, 24\r
+ pop ebx\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 C PUBLIC\r
+ LOCAL IdtrBuf:FWORD\r
+\r
+ sidt IdtrBuf\r
+ mov eax, DWORD PTR IdtrBuf + 2\r
+ ret\r
+GetIdtr ENDP\r
+\r
+\r
+;------------------------------------------------------------------------------\r
+; BOOLEAN\r
+; WriteInterruptFlag (\r
+; BOOLEAN NewState\r
+; )\r
+;\r
+; Abstract: Programs interrupt flag to the requested state and returns previous\r
+; state.\r
+;\r
+WriteInterruptFlag PROC C PUBLIC State:DWORD\r
+\r
+ pushfd\r
+ pop eax\r
+ and eax, 200h\r
+ shr eax, 9\r
+ mov ecx, State\r
+ .IF ecx == 0\r
+ cli\r
+ .ELSE\r
+ sti\r
+ .ENDIF\r
+ ret\r
+\r
+WriteInterruptFlag ENDP\r
+\r
+\r
+\r
+;------------------------------------------------------------------------------\r
+; void\r
+; Vect2Desc (\r
+; DESCRIPTOR * DestDesc,\r
+; void (*Vector) (void)\r
+; )\r
+;\r
+; Abstract: Encodes an IDT descriptor with the given physical address\r
+;\r
+Vect2Desc PROC C PUBLIC DestPtr:DWORD, Vector:DWORD\r
+\r
+ mov eax, Vector\r
+ mov ecx, DestPtr\r
+ mov word ptr [ecx], ax ; write bits 15..0 of offset\r
+ mov word ptr [ecx+2], 20h ; SYS_CODE_SEL from GDT\r
+ mov word ptr [ecx+4], 0e00h OR 8000h ; type = 386 interrupt gate, present\r
+ shr eax, 16\r
+ mov word ptr [ecx+6], ax ; write bits 31..16 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
+ 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
+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 AppEsp\r
+;; and switched stacks to the debug stack, where it pushed the vector number\r
+;;\r
+;; The application stack looks like this:\r
+;;\r
+;; ...\r
+;; (last application stack entry)\r
+;; eflags from interrupted task\r
+;; CS from interrupted task\r
+;; EIP from interrupted task\r
+;; Error code <-------------------- Only present for some exeption types\r
+;;\r
+;;\r
+\r
+\r
+;; The stub switched us to the debug stack and pushed the interrupt number.\r
+;;\r
+;; Next, construct the context record. It will be build on the debug stack by\r
+;; pushing the registers in the correct order so as to create the context structure\r
+;; on the debug stack. The context record must be built from the end back to the\r
+;; beginning because the stack grows down...\r
+;\r
+;; For reference, the context record looks like this:\r
+;;\r
+;; typedef\r
+;; struct {\r
+;; UINT32 ExceptionData;\r
+;; FX_SAVE_STATE 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
+;; } SYSTEM_CONTEXT_IA32; // 32 bit system context record\r
+\r
+;; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;\r
+ pushad\r
+\r
+;; Save interrupt state eflags register...\r
+ pushfd\r
+ pop eax\r
+ mov dword ptr Eflags, eax\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
+ .IF ExceptionNumber == EXCPT32_DOUBLE_FAULT\r
+ mov ExtraPush, 1\r
+ .ELSEIF ExceptionNumber == EXCPT32_INVALID_TSS\r
+ mov ExtraPush, 1\r
+ .ELSEIF ExceptionNumber == EXCPT32_SEG_NOT_PRESENT\r
+ mov ExtraPush, 1\r
+ .ELSEIF ExceptionNumber == EXCPT32_STACK_FAULT\r
+ mov ExtraPush, 1\r
+ .ELSEIF ExceptionNumber == EXCPT32_GP_FAULT\r
+ mov ExtraPush, 1\r
+ .ELSEIF ExceptionNumber == EXCPT32_PAGE_FAULT\r
+ mov ExtraPush, 1\r
+ .ELSEIF ExceptionNumber == EXCPT32_ALIGNMENT_CHECK\r
+ mov ExtraPush, 1\r
+ .ELSE\r
+ mov ExtraPush, 0\r
+ .ENDIF\r
+\r
+;; If there's some extra data, save it also, and modify the saved AppEsp to effectively\r
+;; pop this value off the application's stack.\r
+ .IF ExtraPush == 1\r
+ mov eax, AppEsp\r
+ mov ebx, [eax]\r
+ mov ExceptData, ebx\r
+ add eax, 4\r
+ mov AppEsp, eax\r
+ .ELSE\r
+ mov ExceptData, 0\r
+ .ENDIF\r
+\r
+;; The "pushad" above pushed the debug stack esp. Since what we're actually doing\r
+;; is building the context record on the debug stack, we need to save the pushed\r
+;; debug ESP, and replace it with the application's last stack entry...\r
+ mov eax, [esp + 12]\r
+ mov DebugEsp, eax\r
+ mov eax, AppEsp\r
+ add eax, 12\r
+ ; application stack has eflags, cs, & eip, so\r
+ ; last actual application stack entry is\r
+ ; 12 bytes into the application stack.\r
+ mov [esp + 12], eax\r
+\r
+;; continue building context record\r
+;; UINT32 Gs, Fs, Es, Ds, Cs, Ss; insure high 16 bits of each is zero\r
+ mov eax, ss\r
+ push eax\r
+\r
+ ; CS from application is one entry back in application stack\r
+ mov eax, AppEsp\r
+ movzx eax, word ptr [eax + 4]\r
+ push eax\r
+\r
+ mov eax, ds\r
+ push eax\r
+ mov eax, es\r
+ push eax\r
+ mov eax, fs\r
+ push eax\r
+ mov eax, gs\r
+ push eax\r
+\r
+;; UINT32 Eip;\r
+ ; Eip from application is on top of application stack\r
+ mov eax, AppEsp\r
+ push dword ptr [eax]\r
+\r
+;; UINT64 Gdtr, Idtr;\r
+ push 0\r
+ push 0\r
+ sidt fword ptr [esp]\r
+ push 0\r
+ push 0\r
+ sgdt fword ptr [esp]\r
+\r
+;; UINT32 Ldtr, Tr;\r
+ xor eax, eax\r
+ str ax\r
+ push eax\r
+ sldt ax\r
+ push eax\r
+\r
+;; UINT32 EFlags;\r
+;; Eflags from application is two entries back in application stack\r
+ mov eax, AppEsp\r
+ push dword ptr [eax + 8]\r
+\r
+;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;\r
+;; insure FXSAVE/FXRSTOR is enabled in CR4...\r
+;; ... while we're at it, make sure DE is also enabled...\r
+ mov eax, cr4\r
+ or eax, 208h\r
+ mov cr4, eax\r
+ push eax\r
+ mov eax, cr3\r
+ push eax\r
+ mov eax, cr2\r
+ push eax\r
+ push 0\r
+ mov eax, cr0\r
+ push eax\r
+\r
+;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
+ mov eax, dr7\r
+ push eax\r
+;; clear Dr7 while executing debugger itself\r
+ xor eax, eax\r
+ mov dr7, eax\r
+\r
+ mov eax, dr6\r
+ push eax\r
+;; insure all status bits in dr6 are clear...\r
+ xor eax, eax\r
+ mov dr6, eax\r
+\r
+ mov eax, dr3\r
+ push eax\r
+ mov eax, dr2\r
+ push eax\r
+ mov eax, dr1\r
+ push eax\r
+ mov eax, dr0\r
+ push eax\r
+\r
+;; FX_SAVE_STATE FxSaveState;\r
+ sub esp, 512\r
+ mov edi, esp\r
+ ; IMPORTANT!! The debug stack has been carefully constructed to\r
+ ; insure that esp and edi are 16 byte aligned when we get here.\r
+ ; They MUST be. If they are not, a GP fault will occur.\r
+ FXSTOR_EDI\r
+\r
+;; UINT32 ExceptionData;\r
+ mov eax, ExceptData\r
+ push eax\r
+\r
+; call to C code which will in turn call registered handler\r
+; pass in the vector number\r
+ mov eax, esp\r
+ push eax\r
+ mov eax, ExceptionNumber\r
+ push eax\r
+ call InterruptDistrubutionHub\r
+ add esp, 8\r
+\r
+; restore context...\r
+;; UINT32 ExceptionData;\r
+ add esp, 4\r
+\r
+;; FX_SAVE_STATE FxSaveState;\r
+ mov esi, esp\r
+ FXRSTOR_ESI\r
+ add esp, 512\r
+\r
+;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
+ pop eax\r
+ mov dr0, eax\r
+ pop eax\r
+ mov dr1, eax\r
+ pop eax\r
+ mov dr2, eax\r
+ pop eax\r
+ mov dr3, eax\r
+;; skip restore of dr6. We cleared dr6 during the context save.\r
+ add esp, 4\r
+ pop eax\r
+ mov dr7, eax\r
+\r
+;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;\r
+ pop eax\r
+ mov cr0, eax\r
+ add esp, 4\r
+ pop eax\r
+ mov cr2, eax\r
+ pop eax\r
+ mov cr3, eax\r
+ pop eax\r
+ mov cr4, eax\r
+\r
+;; UINT32 EFlags;\r
+ mov eax, AppEsp\r
+ pop dword ptr [eax + 8]\r
+\r
+;; UINT16 Ldtr, Tr;\r
+;; UINT64 Gdtr, Idtr;\r
+;; Best not let anyone mess with these particular registers...\r
+ add esp, 24\r
+\r
+;; UINT32 Eip;\r
+ pop dword ptr [eax]\r
+\r
+;; UINT32 SegGs, SegFs, SegEs, SegDs, SegCs, SegSs;\r
+;; NOTE - modified segment registers could hang the debugger... We\r
+;; could attempt to insulate ourselves against this possibility,\r
+;; but that poses risks as well.\r
+;;\r
+\r
+ pop gs\r
+ pop fs\r
+ pop es\r
+ pop ds\r
+ pop [eax + 4]\r
+ pop ss\r
+\r
+;; The next stuff to restore is the general purpose registers that were pushed\r
+;; using the pushad instruction.\r
+;;\r
+;; The value of ESP as stored in the context record is the application ESP\r
+;; including the 3 entries on the application stack caused by the exception\r
+;; itself. It may have been modified by the debug agent, so we need to\r
+;; determine if we need to relocate the application stack.\r
+\r
+ mov ebx, [esp + 12] ; move the potentially modified AppEsp into ebx\r
+ mov eax, AppEsp\r
+ add eax, 12\r
+ cmp ebx, eax\r
+ je NoAppStackMove\r
+\r
+ mov eax, AppEsp\r
+ mov ecx, [eax] ; EIP\r
+ mov [ebx], ecx\r
+\r
+ mov ecx, [eax + 4] ; CS\r
+ mov [ebx + 4], ecx\r
+\r
+ mov ecx, [eax + 8] ; EFLAGS\r
+ mov [ebx + 8], ecx\r
+\r
+ mov eax, ebx ; modify the saved AppEsp to the new AppEsp\r
+ 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
+ mov [esp + 12], eax\r
+\r
+ cmp ExceptionNumber, 068h\r
+ jne NoChain\r
+\r
+Chain:\r
+\r
+;; Restore eflags so when we chain, the flags will be exactly as if we were never here.\r
+;; We gin up the stack to do an iretd so we can get ALL the flags.\r
+ mov eax, AppEsp\r
+ mov ebx, [eax + 8]\r
+ and ebx, NOT 300h ; special handling for IF and TF\r
+ push ebx\r
+ push cs\r
+ push PhonyIretd\r
+ iretd\r
+PhonyIretd:\r
+\r
+;; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;\r
+ popad\r
+\r
+;; Switch back to application stack\r
+ mov esp, AppEsp\r
+\r
+;; Jump to original handler\r
+ jmp OrigVector\r
+\r
+NoChain:\r
+;; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;\r
+ popad\r
+\r
+;; Switch back to application stack\r
+ mov esp, AppEsp\r
+\r
+;; We're outa here...\r
+ iretd\r
+END\r
+\r
+\r
+\r
--- /dev/null
+/*++\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
+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
+// 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;\r
+\r
+#ifndef EFI_NT_EMULATOR\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 89 25 00000004 R mov AppEsp, esp ; save stack top\r
+ // 00000006 BC 00008014 R mov esp, offset DbgStkBot ; switch to debugger stack\r
+ // 0000000B 6A 00 push 0 ; push vector number - will be modified before installed\r
+ // 0000000D E9 db 0e9h ; jump rel32\r
+ // 0000000E 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[0x0c] = (UINT8) ExceptionType;\r
+\r
+ //\r
+ // fixup the jump target to point to the common entry\r
+ //\r
+ *(UINT32 *) &StubCopy[0x0e] = (UINT32) CommonIdtEntry - (UINT32) &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
+// TODO: ) - add argument and description to function comment\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)[0];\r
+ ((UINT16 *) &IdtEntryTable[ExceptionType].OrigVector)[1] = ((UINT16 *) &IdtEntryTable[ExceptionType].OrigDesc)[3];\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
+#endif\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
+// TODO: ) - add argument and description to function comment\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ Status = EFI_SUCCESS;\r
+\r
+#ifndef EFI_NT_EMULATOR\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
+#endif\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
+\r
+Returns: 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
+}\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
+\r
+Returns:\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
+\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
+\r
+Returns:\r
+\r
+ None\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
+\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
+ For IA32, this is a no-op since the instruction and data caches are coherent.\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+ None\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
+ 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 IA32 processor does not support FXSTOR/FXRSTOR instructions,\r
+ the context save will fail, so these processor's are not supported.\r
+\r
+--*/\r
+// TODO: EFI_OUT_OF_RESOURCES - add return value to function comment\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
+ None\r
+\r
+--*/\r
+// TODO: EFI_SUCCESS - add return value to function comment\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
+\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
+ IdtEntryTable[ExceptionType].RegisteredCallback (ExceptionType, ContextRecord);\r
+ } else {\r
+ OrigVector = IdtEntryTable[ExceptionType].OrigVector;\r
+ IdtEntryTable[ExceptionType].RegisteredCallback (ContextRecord);\r
+ }\r
+ }\r
+}\r
--- /dev/null
+/*++\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
+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
+#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 IsaIa32\r
+#define FF_FXSR (1 << 24)\r
+\r
+typedef UINT64 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
+ TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ None\r
+\r
+Returns:\r
+\r
+ TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+BOOLEAN\r
+FxStorSupport (\r
+ VOID\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ None\r
+\r
+Returns:\r
+\r
+ TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+DESCRIPTOR *\r
+GetIdtr (\r
+ VOID\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ None\r
+\r
+Returns:\r
+\r
+ TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+VOID\r
+Vect2Desc (\r
+ DESCRIPTOR * DestDesc,\r
+ VOID (*Vector) (VOID)\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ DestDesc - TODO: add argument description\r
+ ) - TODO: add argument description\r
+\r
+Returns:\r
+\r
+ TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+BOOLEAN\r
+WriteInterruptFlag (\r
+ BOOLEAN NewState\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ NewState - TODO: add argument description\r
+\r
+Returns:\r
+\r
+ TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+plInitializeDebugSupportDriver (\r
+ VOID\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ None\r
+\r
+Returns:\r
+\r
+ TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+plUnloadDebugSupportDriver (\r
+ IN EFI_HANDLE ImageHandle\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ ImageHandle - TODO: add argument description\r
+\r
+Returns:\r
+\r
+ TODO: add return values\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:\r
+\r
+ TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ This - TODO: add argument description\r
+ MaxProcessorIndex - TODO: add argument description\r
+\r
+Returns:\r
+\r
+ TODO: add return values\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
+\r
+ TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ This - TODO: add argument description\r
+ ProcessorIndex - TODO: add argument description\r
+ PeriodicCallback - TODO: add argument description\r
+\r
+Returns:\r
+\r
+ TODO: add return values\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
+\r
+ TODO: Add function description\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
+\r
+Returns:\r
+\r
+ TODO: add return values\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
+\r
+ TODO: Add function description\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
+\r
+Returns:\r
+\r
+ TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+#endif\r
+++ /dev/null
-#******************************************************************************
-#*
-#* 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.
-#*
-#******************************************************************************
-
-.global _OrigVector
-.global _InterruptEntryStub
-.global _StubSize
-.global _CommonIdtEntry
-.global _FxStorSupport
-
-_AppEsp: .long 0x11111111 # ?
-_DebugEsp: .long 0x22222222 # ?
-_ExtraPush: .long 0x33333333 # ?
-_ExceptData: .long 0x44444444 # ?
-_Eflags: .long 0x55555555 # ?
-_OrigVector: .long 0x66666666 # ?
-_StubSize: .long _InterruptEntryStubEnd - _InterruptEntryStub
-
-.global _FxStorSupport
-_FxStorSupport:
- push %ebx
- mov $0x1,%eax
- cpuid
- mov %edx,%eax
- and $0x1000000,%eax
- shr $0x18,%eax
- pop %ebx
- ret
-
-.global _GetIdtr
-_GetIdtr:
- push %ebp
- mov %esp,%ebp
- add $0xfffffff8,%esp
- sidtl 0xfffffffa(%ebp)
- mov 0xfffffffc(%ebp),%eax
- leave
- ret
-
-.global _WriteInterruptFlag
-_WriteInterruptFlag:
- push %ebp
- mov %esp,%ebp
- pushf
- pop %eax
- and $0x200,%eax
- shr $0x9,%eax
- mov 0x8(%ebp),%ecx
- or %ecx,%ecx
- jne _WriteInterruptFlag+0x17
- cli
- jmp _WriteInterruptFlag+0x18
- sti
- leave
- ret
-
-.global _Vect2Desc
-_Vect2Desc:
- push %ebp
- mov %esp,%ebp
- mov 0xc(%ebp),%eax
- mov 0x8(%ebp),%ecx
- mov %ax,(%ecx)
- movw $0x20,0x2(%ecx)
- movw $0x8e00,0x4(%ecx)
- shr $0x10,%eax
- mov %ax,0x6(%ecx)
- leave
- ret
-
-.global _InterruptEntryStub
-_InterruptEntryStub:
- mov %esp,0x0
- mov $0x0,%esp
- push $0x0
- jmp _CommonIdtEntry
-.global _InterruptEntryStubEnd
-_InterruptEntryStubEnd:
-
-.global _CommonIdtEntry
-_CommonIdtEntry:
- pusha
- pushf
- pop %eax
- mov %eax,0x0
- cmpl $0x8,0x0
- jne _CommonIdtEntry+0x20
- movl $0x1,0x0
- jmp _CommonIdtEntry+0xa8
- cmpl $0xa,0x0
- jne _CommonIdtEntry+0x35
- movl $0x1,0x0
- jmp _CommonIdtEntry+0xa8
- cmpl $0xb,0x0
- jne _CommonIdtEntry+0x4a
- movl $0x1,0x0
- jmp _CommonIdtEntry+0xa8
- cmpl $0xc,0x0
- jne _CommonIdtEntry+0x5f
- movl $0x1,0x0
- jmp _CommonIdtEntry+0xa8
- cmpl $0xd,0x0
- jne _CommonIdtEntry+0x74
- movl $0x1,0x0
- jmp _CommonIdtEntry+0xa8
- cmpl $0xe,0x0
- jne _CommonIdtEntry+0x89
- movl $0x1,0x0
- jmp _CommonIdtEntry+0xa8
- cmpl $0x11,0x0
- jne _CommonIdtEntry+0x9e
- movl $0x1,0x0
- jmp _CommonIdtEntry+0xa8
- movl $0x0,0x0
- cmpl $0x1,0x0
- jne _CommonIdtEntry+0xc8
- mov 0x0,%eax
- mov (%eax),%ebx
- mov %ebx,0x0
- add $0x4,%eax
- mov %eax,0x0
- jmp _CommonIdtEntry+0xd2
- movl $0x0,0x0
- mov 0xc(%esp),%eax
- mov %eax,0x0
- mov 0x0,%eax
- add $0xc,%eax
- mov %eax,0xc(%esp)
- mov %ss,%eax
- push %eax
- mov 0x0,%eax
- movzwl 0x4(%eax),%eax
- push %eax
- mov %ds,%eax
- push %eax
- mov %es,%eax
- push %eax
- mov %fs,%eax
- push %eax
- mov %gs,%eax
- push %eax
- mov 0x0,%eax
- pushl (%eax)
- push $0x0
- push $0x0
- sidtl (%esp)
- push $0x0
- push $0x0
- sgdtl (%esp)
- xor %eax,%eax
- str %eax
- push %eax
- sldt %eax
- push %eax
- mov 0x0,%eax
- pushl 0x8(%eax)
- mov %cr4,%eax
- or $0x208,%eax
- mov %eax,%cr4
- push %eax
- mov %cr3,%eax
- push %eax
- mov %cr2,%eax
- push %eax
- push $0x0
- mov %cr0,%eax
- push %eax
- mov %db7,%eax
- push %eax
- xor %eax,%eax
- mov %eax,%db7
- mov %db6,%eax
- push %eax
- xor %eax,%eax
- mov %eax,%db6
- mov %db3,%eax
- push %eax
- mov %db2,%eax
- push %eax
- mov %db1,%eax
- push %eax
- mov %db0,%eax
- push %eax
- sub $0x200,%esp
- mov %esp,%edi
- fxsave (%edi)
- mov 0x0,%eax
- push %eax
- mov %esp,%eax
- push %eax
- mov 0x0,%eax
- push %eax
- call _CommonIdtEntry+0x184
- add $0x8,%esp
- add $0x4,%esp
- mov %esp,%esi
- fxrstor (%esi)
- add $0x200,%esp
- pop %eax
- mov %eax,%db0
- pop %eax
- mov %eax,%db1
- pop %eax
- mov %eax,%db2
- pop %eax
- mov %eax,%db3
- add $0x4,%esp
- pop %eax
- mov %eax,%db7
- pop %eax
- mov %eax,%cr0
- add $0x4,%esp
- pop %eax
- mov %eax,%cr2
- pop %eax
- mov %eax,%cr3
- pop %eax
- mov %eax,%cr4
- mov 0x0,%eax
- popl 0x8(%eax)
- add $0x18,%esp
- popl (%eax)
- pop %gs
- pop %fs
- pop %es
- pop %ds
- popl 0x4(%eax)
- pop %ss
- mov 0xc(%esp),%ebx
- mov 0x0,%eax
- add $0xc,%eax
- cmp %eax,%ebx
- je _CommonIdtEntry+0x202
- mov 0x0,%eax
- mov (%eax),%ecx
- mov %ecx,(%ebx)
- mov 0x4(%eax),%ecx
- mov %ecx,0x4(%ebx)
- mov 0x8(%eax),%ecx
- mov %ecx,0x8(%ebx)
- mov %ebx,%eax
- mov %eax,0x0
- mov 0x0,%eax
- mov %eax,0xc(%esp)
- cmpl $0x68,0x0
- jne PhonyIretd+0xd
- mov 0x0,%eax
- mov 0x8(%eax),%ebx
- and $0xfffffcff,%ebx
- push %ebx
- push %cs
- push $0x0
- iret
-
-PhonyIretd:
- popa
- mov 0x0,%esp
- jmp *0x0
- popa
- mov 0x0,%esp
- iret
+++ /dev/null
-;******************************************************************************\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
-.586p\r
-.MODEL FLAT, C\r
-\r
-EXCPT32_DIVIDE_ERROR EQU 0\r
-EXCPT32_DEBUG EQU 1\r
-EXCPT32_NMI EQU 2\r
-EXCPT32_BREAKPOINT EQU 3\r
-EXCPT32_OVERFLOW EQU 4\r
-EXCPT32_BOUND EQU 5\r
-EXCPT32_INVALID_OPCODE EQU 6\r
-EXCPT32_DOUBLE_FAULT EQU 8\r
-EXCPT32_INVALID_TSS EQU 10\r
-EXCPT32_SEG_NOT_PRESENT EQU 11\r
-EXCPT32_STACK_FAULT EQU 12\r
-EXCPT32_GP_FAULT EQU 13\r
-EXCPT32_PAGE_FAULT EQU 14\r
-EXCPT32_FP_ERROR EQU 16\r
-EXCPT32_ALIGNMENT_CHECK EQU 17\r
-EXCPT32_MACHINE_CHECK EQU 18\r
-EXCPT32_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 [edi]\r
-FXSTOR_EDI MACRO\r
- db 0fh, 0aeh, 00000111y ; mod = 00, reg/op = 000, r/m = 111 = [edi]\r
-ENDM\r
-\r
-;; fxrstor [esi]\r
-FXRSTOR_ESI MACRO\r
- db 0fh, 0aeh, 00001110y ; mod = 00, reg/op = 001, r/m = 110 = [esi]\r
-ENDM\r
-.DATA\r
-\r
-public OrigVector, InterruptEntryStub, StubSize, CommonIdtEntry, FxStorSupport\r
-\r
-StubSize dd InterruptEntryStubEnd - InterruptEntryStub\r
-AppEsp dd 11111111h ; ?\r
-DebugEsp dd 22222222h ; ?\r
-ExtraPush dd 33333333h ; ?\r
-ExceptData dd 44444444h ; ?\r
-Eflags dd 55555555h ; ?\r
-OrigVector dd 66666666h ; ?\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 132 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 - 132 - 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
-;; 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
-;; } SYSTEM_CONTEXT_IA32; // 32 bit system context record\r
-\r
-\r
-align 16\r
-DebugStackEnd db "DbgStkEnd >>>>>>" ;; 16 byte long string - must be 16 bytes to preserve alignment\r
- dd 1ffdh 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 dd ? ;; 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
-.CODE\r
-\r
-externdef InterruptDistrubutionHub:near\r
-\r
-;------------------------------------------------------------------------------\r
-; BOOLEAN\r
-; FxStorSupport (\r
-; void\r
-; )\r
-;\r
-; Abstract: Returns TRUE if FxStor instructions are supported\r
-;\r
-FxStorSupport PROC C PUBLIC\r
-\r
-;\r
-; cpuid corrupts ebx which must be preserved per the C calling convention\r
-;\r
- push ebx\r
- mov eax, 1\r
- cpuid\r
- mov eax, edx\r
- and eax, FXSTOR_FLAG\r
- shr eax, 24\r
- pop ebx\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 C PUBLIC\r
- LOCAL IdtrBuf:FWORD\r
-\r
- sidt IdtrBuf\r
- mov eax, DWORD PTR IdtrBuf + 2\r
- ret\r
-GetIdtr ENDP\r
-\r
-\r
-;------------------------------------------------------------------------------\r
-; BOOLEAN\r
-; WriteInterruptFlag (\r
-; BOOLEAN NewState\r
-; )\r
-;\r
-; Abstract: Programs interrupt flag to the requested state and returns previous\r
-; state.\r
-;\r
-WriteInterruptFlag PROC C PUBLIC State:DWORD\r
-\r
- pushfd\r
- pop eax\r
- and eax, 200h\r
- shr eax, 9\r
- mov ecx, State\r
- .IF ecx == 0\r
- cli\r
- .ELSE\r
- sti\r
- .ENDIF\r
- ret\r
-\r
-WriteInterruptFlag ENDP\r
-\r
-\r
-\r
-;------------------------------------------------------------------------------\r
-; void\r
-; Vect2Desc (\r
-; DESCRIPTOR * DestDesc,\r
-; void (*Vector) (void)\r
-; )\r
-;\r
-; Abstract: Encodes an IDT descriptor with the given physical address\r
-;\r
-Vect2Desc PROC C PUBLIC DestPtr:DWORD, Vector:DWORD\r
-\r
- mov eax, Vector\r
- mov ecx, DestPtr\r
- mov word ptr [ecx], ax ; write bits 15..0 of offset\r
- mov word ptr [ecx+2], 20h ; SYS_CODE_SEL from GDT\r
- mov word ptr [ecx+4], 0e00h OR 8000h ; type = 386 interrupt gate, present\r
- shr eax, 16\r
- mov word ptr [ecx+6], ax ; write bits 31..16 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
- 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
-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 AppEsp\r
-;; and switched stacks to the debug stack, where it pushed the vector number\r
-;;\r
-;; The application stack looks like this:\r
-;;\r
-;; ...\r
-;; (last application stack entry)\r
-;; eflags from interrupted task\r
-;; CS from interrupted task\r
-;; EIP from interrupted task\r
-;; Error code <-------------------- Only present for some exeption types\r
-;;\r
-;;\r
-\r
-\r
-;; The stub switched us to the debug stack and pushed the interrupt number.\r
-;;\r
-;; Next, construct the context record. It will be build on the debug stack by\r
-;; pushing the registers in the correct order so as to create the context structure\r
-;; on the debug stack. The context record must be built from the end back to the\r
-;; beginning because the stack grows down...\r
-;\r
-;; For reference, the context record looks like this:\r
-;;\r
-;; typedef\r
-;; struct {\r
-;; UINT32 ExceptionData;\r
-;; FX_SAVE_STATE 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
-;; } SYSTEM_CONTEXT_IA32; // 32 bit system context record\r
-\r
-;; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;\r
- pushad\r
-\r
-;; Save interrupt state eflags register...\r
- pushfd\r
- pop eax\r
- mov dword ptr Eflags, eax\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
- .IF ExceptionNumber == EXCPT32_DOUBLE_FAULT\r
- mov ExtraPush, 1\r
- .ELSEIF ExceptionNumber == EXCPT32_INVALID_TSS\r
- mov ExtraPush, 1\r
- .ELSEIF ExceptionNumber == EXCPT32_SEG_NOT_PRESENT\r
- mov ExtraPush, 1\r
- .ELSEIF ExceptionNumber == EXCPT32_STACK_FAULT\r
- mov ExtraPush, 1\r
- .ELSEIF ExceptionNumber == EXCPT32_GP_FAULT\r
- mov ExtraPush, 1\r
- .ELSEIF ExceptionNumber == EXCPT32_PAGE_FAULT\r
- mov ExtraPush, 1\r
- .ELSEIF ExceptionNumber == EXCPT32_ALIGNMENT_CHECK\r
- mov ExtraPush, 1\r
- .ELSE\r
- mov ExtraPush, 0\r
- .ENDIF\r
-\r
-;; If there's some extra data, save it also, and modify the saved AppEsp to effectively\r
-;; pop this value off the application's stack.\r
- .IF ExtraPush == 1\r
- mov eax, AppEsp\r
- mov ebx, [eax]\r
- mov ExceptData, ebx\r
- add eax, 4\r
- mov AppEsp, eax\r
- .ELSE\r
- mov ExceptData, 0\r
- .ENDIF\r
-\r
-;; The "pushad" above pushed the debug stack esp. Since what we're actually doing\r
-;; is building the context record on the debug stack, we need to save the pushed\r
-;; debug ESP, and replace it with the application's last stack entry...\r
- mov eax, [esp + 12]\r
- mov DebugEsp, eax\r
- mov eax, AppEsp\r
- add eax, 12\r
- ; application stack has eflags, cs, & eip, so\r
- ; last actual application stack entry is\r
- ; 12 bytes into the application stack.\r
- mov [esp + 12], eax\r
-\r
-;; continue building context record\r
-;; UINT32 Gs, Fs, Es, Ds, Cs, Ss; insure high 16 bits of each is zero\r
- mov eax, ss\r
- push eax\r
-\r
- ; CS from application is one entry back in application stack\r
- mov eax, AppEsp\r
- movzx eax, word ptr [eax + 4]\r
- push eax\r
-\r
- mov eax, ds\r
- push eax\r
- mov eax, es\r
- push eax\r
- mov eax, fs\r
- push eax\r
- mov eax, gs\r
- push eax\r
-\r
-;; UINT32 Eip;\r
- ; Eip from application is on top of application stack\r
- mov eax, AppEsp\r
- push dword ptr [eax]\r
-\r
-;; UINT64 Gdtr, Idtr;\r
- push 0\r
- push 0\r
- sidt fword ptr [esp]\r
- push 0\r
- push 0\r
- sgdt fword ptr [esp]\r
-\r
-;; UINT32 Ldtr, Tr;\r
- xor eax, eax\r
- str ax\r
- push eax\r
- sldt ax\r
- push eax\r
-\r
-;; UINT32 EFlags;\r
-;; Eflags from application is two entries back in application stack\r
- mov eax, AppEsp\r
- push dword ptr [eax + 8]\r
-\r
-;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;\r
-;; insure FXSAVE/FXRSTOR is enabled in CR4...\r
-;; ... while we're at it, make sure DE is also enabled...\r
- mov eax, cr4\r
- or eax, 208h\r
- mov cr4, eax\r
- push eax\r
- mov eax, cr3\r
- push eax\r
- mov eax, cr2\r
- push eax\r
- push 0\r
- mov eax, cr0\r
- push eax\r
-\r
-;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
- mov eax, dr7\r
- push eax\r
-;; clear Dr7 while executing debugger itself\r
- xor eax, eax\r
- mov dr7, eax\r
-\r
- mov eax, dr6\r
- push eax\r
-;; insure all status bits in dr6 are clear...\r
- xor eax, eax\r
- mov dr6, eax\r
-\r
- mov eax, dr3\r
- push eax\r
- mov eax, dr2\r
- push eax\r
- mov eax, dr1\r
- push eax\r
- mov eax, dr0\r
- push eax\r
-\r
-;; FX_SAVE_STATE FxSaveState;\r
- sub esp, 512\r
- mov edi, esp\r
- ; IMPORTANT!! The debug stack has been carefully constructed to\r
- ; insure that esp and edi are 16 byte aligned when we get here.\r
- ; They MUST be. If they are not, a GP fault will occur.\r
- FXSTOR_EDI\r
-\r
-;; UINT32 ExceptionData;\r
- mov eax, ExceptData\r
- push eax\r
-\r
-; call to C code which will in turn call registered handler\r
-; pass in the vector number\r
- mov eax, esp\r
- push eax\r
- mov eax, ExceptionNumber\r
- push eax\r
- call InterruptDistrubutionHub\r
- add esp, 8\r
-\r
-; restore context...\r
-;; UINT32 ExceptionData;\r
- add esp, 4\r
-\r
-;; FX_SAVE_STATE FxSaveState;\r
- mov esi, esp\r
- FXRSTOR_ESI\r
- add esp, 512\r
-\r
-;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
- pop eax\r
- mov dr0, eax\r
- pop eax\r
- mov dr1, eax\r
- pop eax\r
- mov dr2, eax\r
- pop eax\r
- mov dr3, eax\r
-;; skip restore of dr6. We cleared dr6 during the context save.\r
- add esp, 4\r
- pop eax\r
- mov dr7, eax\r
-\r
-;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;\r
- pop eax\r
- mov cr0, eax\r
- add esp, 4\r
- pop eax\r
- mov cr2, eax\r
- pop eax\r
- mov cr3, eax\r
- pop eax\r
- mov cr4, eax\r
-\r
-;; UINT32 EFlags;\r
- mov eax, AppEsp\r
- pop dword ptr [eax + 8]\r
-\r
-;; UINT16 Ldtr, Tr;\r
-;; UINT64 Gdtr, Idtr;\r
-;; Best not let anyone mess with these particular registers...\r
- add esp, 24\r
-\r
-;; UINT32 Eip;\r
- pop dword ptr [eax]\r
-\r
-;; UINT32 SegGs, SegFs, SegEs, SegDs, SegCs, SegSs;\r
-;; NOTE - modified segment registers could hang the debugger... We\r
-;; could attempt to insulate ourselves against this possibility,\r
-;; but that poses risks as well.\r
-;;\r
-\r
- pop gs\r
- pop fs\r
- pop es\r
- pop ds\r
- pop [eax + 4]\r
- pop ss\r
-\r
-;; The next stuff to restore is the general purpose registers that were pushed\r
-;; using the pushad instruction.\r
-;;\r
-;; The value of ESP as stored in the context record is the application ESP\r
-;; including the 3 entries on the application stack caused by the exception\r
-;; itself. It may have been modified by the debug agent, so we need to\r
-;; determine if we need to relocate the application stack.\r
-\r
- mov ebx, [esp + 12] ; move the potentially modified AppEsp into ebx\r
- mov eax, AppEsp\r
- add eax, 12\r
- cmp ebx, eax\r
- je NoAppStackMove\r
-\r
- mov eax, AppEsp\r
- mov ecx, [eax] ; EIP\r
- mov [ebx], ecx\r
-\r
- mov ecx, [eax + 4] ; CS\r
- mov [ebx + 4], ecx\r
-\r
- mov ecx, [eax + 8] ; EFLAGS\r
- mov [ebx + 8], ecx\r
-\r
- mov eax, ebx ; modify the saved AppEsp to the new AppEsp\r
- 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
- mov [esp + 12], eax\r
-\r
- cmp ExceptionNumber, 068h\r
- jne NoChain\r
-\r
-Chain:\r
-\r
-;; Restore eflags so when we chain, the flags will be exactly as if we were never here.\r
-;; We gin up the stack to do an iretd so we can get ALL the flags.\r
- mov eax, AppEsp\r
- mov ebx, [eax + 8]\r
- and ebx, NOT 300h ; special handling for IF and TF\r
- push ebx\r
- push cs\r
- push PhonyIretd\r
- iretd\r
-PhonyIretd:\r
-\r
-;; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;\r
- popad\r
-\r
-;; Switch back to application stack\r
- mov esp, AppEsp\r
-\r
-;; Jump to original handler\r
- jmp OrigVector\r
-\r
-NoChain:\r
-;; UINT32 Edi, Esi, Ebp, Esp, Ebx, Edx, Ecx, Eax;\r
- popad\r
-\r
-;; Switch back to application stack\r
- mov esp, AppEsp\r
-\r
-;; We're outa here...\r
- iretd\r
-END\r
-\r
-\r
-\r
+++ /dev/null
-/*++\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
-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
-// 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;\r
-\r
-#ifndef EFI_NT_EMULATOR\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 89 25 00000004 R mov AppEsp, esp ; save stack top\r
- // 00000006 BC 00008014 R mov esp, offset DbgStkBot ; switch to debugger stack\r
- // 0000000B 6A 00 push 0 ; push vector number - will be modified before installed\r
- // 0000000D E9 db 0e9h ; jump rel32\r
- // 0000000E 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[0x0c] = (UINT8) ExceptionType;\r
-\r
- //\r
- // fixup the jump target to point to the common entry\r
- //\r
- *(UINT32 *) &StubCopy[0x0e] = (UINT32) CommonIdtEntry - (UINT32) &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
-// TODO: ) - add argument and description to function comment\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)[0];\r
- ((UINT16 *) &IdtEntryTable[ExceptionType].OrigVector)[1] = ((UINT16 *) &IdtEntryTable[ExceptionType].OrigDesc)[3];\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
-#endif\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
-// TODO: ) - add argument and description to function comment\r
-{\r
- EFI_STATUS Status;\r
-\r
- Status = EFI_SUCCESS;\r
-\r
-#ifndef EFI_NT_EMULATOR\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
-#endif\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
-\r
-Returns: 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
-}\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
-\r
-Returns:\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
-\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
-\r
-Returns:\r
-\r
- None\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
-\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
- For IA32, this is a no-op since the instruction and data caches are coherent.\r
-\r
-Arguments:\r
-\r
-Returns:\r
-\r
- None\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
- 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 IA32 processor does not support FXSTOR/FXRSTOR instructions,\r
- the context save will fail, so these processor's are not supported.\r
-\r
---*/\r
-// TODO: EFI_OUT_OF_RESOURCES - add return value to function comment\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
- None\r
-\r
---*/\r
-// TODO: EFI_SUCCESS - add return value to function comment\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
-\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
- IdtEntryTable[ExceptionType].RegisteredCallback (ExceptionType, ContextRecord);\r
- } else {\r
- OrigVector = IdtEntryTable[ExceptionType].OrigVector;\r
- IdtEntryTable[ExceptionType].RegisteredCallback (ContextRecord);\r
- }\r
- }\r
-}\r
+++ /dev/null
-/*++\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
-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
-#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 IsaIa32\r
-#define FF_FXSR (1 << 24)\r
-\r
-typedef UINT64 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
- TODO: Add function description\r
-\r
-Arguments:\r
-\r
- None\r
-\r
-Returns:\r
-\r
- TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-BOOLEAN\r
-FxStorSupport (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- TODO: Add function description\r
-\r
-Arguments:\r
-\r
- None\r
-\r
-Returns:\r
-\r
- TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-DESCRIPTOR *\r
-GetIdtr (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- TODO: Add function description\r
-\r
-Arguments:\r
-\r
- None\r
-\r
-Returns:\r
-\r
- TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-VOID\r
-Vect2Desc (\r
- DESCRIPTOR * DestDesc,\r
- VOID (*Vector) (VOID)\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- TODO: Add function description\r
-\r
-Arguments:\r
-\r
- DestDesc - TODO: add argument description\r
- ) - TODO: add argument description\r
-\r
-Returns:\r
-\r
- TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-BOOLEAN\r
-WriteInterruptFlag (\r
- BOOLEAN NewState\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- TODO: Add function description\r
-\r
-Arguments:\r
-\r
- NewState - TODO: add argument description\r
-\r
-Returns:\r
-\r
- TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-EFI_STATUS\r
-plInitializeDebugSupportDriver (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- TODO: Add function description\r
-\r
-Arguments:\r
-\r
- None\r
-\r
-Returns:\r
-\r
- TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-plUnloadDebugSupportDriver (\r
- IN EFI_HANDLE ImageHandle\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- TODO: Add function description\r
-\r
-Arguments:\r
-\r
- ImageHandle - TODO: add argument description\r
-\r
-Returns:\r
-\r
- TODO: add return values\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:\r
-\r
- TODO: Add function description\r
-\r
-Arguments:\r
-\r
- This - TODO: add argument description\r
- MaxProcessorIndex - TODO: add argument description\r
-\r
-Returns:\r
-\r
- TODO: add return values\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
-\r
- TODO: Add function description\r
-\r
-Arguments:\r
-\r
- This - TODO: add argument description\r
- ProcessorIndex - TODO: add argument description\r
- PeriodicCallback - TODO: add argument description\r
-\r
-Returns:\r
-\r
- TODO: add return values\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
-\r
- TODO: Add function description\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
-\r
-Returns:\r
-\r
- TODO: add return values\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
-\r
- TODO: Add function description\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
-\r
-Returns:\r
-\r
- TODO: add return values\r
-\r
---*/\r
-;\r
-\r
-#endif\r
// outputPath = "${DEST_DIR_OUTPUT}">\r
//\r
ele = doc.createElement("tool");\r
- ele.setAttribute("toolName", "${WORKSPACE_DIR}" + File.separatorChar + "Tools" + File.separatorChar + "Bin"\r
+ ele.setAttribute("toolName", "${WORKSPACE_DIR}" + File.separatorChar + "Tools" + File.separatorChar + "bin"\r
+ File.separatorChar + "GenCRC32Section");\r
ele.setAttribute("outputPath", "${DEST_DIR_OUTPUT}");\r
}\r
// project.setProperty("LIBS", propertyLibs.replaceAll("(\\\\)", "/"));\r
}\r
\r
+ /**\r
+ Return the name of the directory that corresponds to the architecture.\r
+ This is a translation from the XML Schema tag to a directory that\r
+ corresponds to our directory name coding convention.\r
+ \r
+ **/\r
+ private String archDir(String arch) {\r
+ return arch.replaceFirst("X64", "x64")\r
+ .replaceFirst("IPF", "Ipf")\r
+ .replaceFirst("IA32", "Ia32")\r
+ .replaceFirst("ARM", "Arm")\r
+ .replaceFirst("EBC", "Ebc");\r
+ }\r
+\r
/**\r
Generate the build source files elements for BaseName_build.xml. \r
\r
// Prepare the includes: PackageDependencies and Output debug direactory\r
//\r
Set<String> includes = new LinkedHashSet<String>();\r
+ String arch = project.getProperty("ARCH");\r
\r
//\r
// WORKSPACE\r
// Module iteself\r
//\r
includes.add("${MODULE_DIR}");\r
- includes.add("${MODULE_DIR}" + File.separatorChar + "${ARCH}");\r
+ includes.add("${MODULE_DIR}" + File.separatorChar + archDir(arch));\r
\r
//\r
// Packages in PackageDenpendencies\r
GlobalData.refreshPackageIdentification(packageDependencies[i]);\r
File packageFile = packageDependencies[i].getSpdFile();\r
includes.add(packageFile.getParent() + File.separatorChar + "Include");\r
- includes.add(packageFile.getParent() + File.separatorChar + "Include" + File.separatorChar + "${ARCH}");\r
+ includes.add(packageFile.getParent() + File.separatorChar + "Include" + File.separatorChar + archDir(arch));\r
}\r
\r
//\r
GlobalData.refreshPackageIdentification(libraryPackageDependencies[j]);\r
File packageFile = libraryPackageDependencies[j].getSpdFile();\r
includes.add(packageFile.getParent() + File.separatorChar + "Include");\r
- includes.add(packageFile.getParent() + File.separatorChar + "Include" + File.separatorChar + "${ARCH}");\r
+ includes.add(packageFile.getParent() + File.separatorChar + "Include" + File.separatorChar + archDir(arch));\r
}\r
SurfaceAreaQuery.pop();\r
}\r
// The package which the module belongs to\r
// TBD\r
includes.add(fpdModuleId.getModule().getPackage().getPackageDir() + File.separatorChar + "Include");\r
- includes.add(fpdModuleId.getModule().getPackage().getPackageDir() + File.separatorChar + "Include" + File.separatorChar + "${ARCH}");\r
+ includes.add(fpdModuleId.getModule().getPackage().getPackageDir() + File.separatorChar + "Include" + File.separatorChar + archDir(arch));\r
\r
//\r
// Debug files output directory\r