summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Core/DxeIplPeim/Ia32
diff options
context:
space:
mode:
authoryshang1 <yshang1@6f19259b-4bc3-4df7-8a09-765794883524>2007-09-28 08:22:33 +0000
committeryshang1 <yshang1@6f19259b-4bc3-4df7-8a09-765794883524>2007-09-28 08:22:33 +0000
commit5d582956c244d8b5cc03520f73b65a7d042e3720 (patch)
tree7defdd332887ae633db22b821ae77733aeba50d2 /MdeModulePkg/Core/DxeIplPeim/Ia32
parent3d7b0992fccc89cc049de91d02b4869ec81cf9fb (diff)
downloadedk2-platforms-5d582956c244d8b5cc03520f73b65a7d042e3720.tar.xz
Enable the 0-31 temporary IDT entries prior to activate the LongMode. If not enable the temporary IDT table, DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED may not work correctly till CPU DXE programs the IDT table.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3966 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg/Core/DxeIplPeim/Ia32')
-rw-r--r--MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c45
-rw-r--r--MdeModulePkg/Core/DxeIplPeim/Ia32/IdtVectorAsm.S88
-rw-r--r--MdeModulePkg/Core/DxeIplPeim/Ia32/IdtVectorAsm.asm95
-rw-r--r--MdeModulePkg/Core/DxeIplPeim/Ia32/VirtualMemory.h40
4 files changed, 267 insertions, 1 deletions
diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
index 63ee2af396..bdece76187 100644
--- a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
+++ b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c
@@ -46,6 +46,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST IA32_DESCRIPTOR gGdt = {
(UINTN) gGdtEntries
};
+GLOBAL_REMOVE_IF_UNREFERENCED IA32_DESCRIPTOR gLidtDescriptor = {
+ sizeof (X64_IDT_GATE_DESCRIPTOR) * 32 - 1,
+ 0
+};
+
VOID
HandOffToDxeCore (
IN EFI_PHYSICAL_ADDRESS DxeCoreEntryPoint,
@@ -57,6 +62,11 @@ HandOffToDxeCore (
EFI_PHYSICAL_ADDRESS BaseOfStack;
EFI_PHYSICAL_ADDRESS TopOfStack;
UINTN PageTables;
+ X64_IDT_GATE_DESCRIPTOR *IdtTable;
+ UINTN SizeOfTemplate;
+ VOID *TemplateBase;
+ EFI_PHYSICAL_ADDRESS VectorAddress;
+ UINT32 Index;
Status = PeiServicesAllocatePages (EfiBootServicesData, EFI_SIZE_TO_PAGES (STACK_SIZE), &BaseOfStack);
ASSERT_EFI_ERROR (Status);
@@ -95,7 +105,40 @@ HandOffToDxeCore (
ASSERT_EFI_ERROR (Status);
AsmWriteCr3 (PageTables);
- //
+
+
+ if (FeaturePcdGet (PcdDxeIplEnableIdt)) {
+ SizeOfTemplate = AsmGetVectorTemplatInfo (&TemplateBase);
+
+ Status = PeiServicesAllocatePages (
+ EfiBootServicesData,
+ EFI_SIZE_TO_PAGES((SizeOfTemplate + sizeof (X64_IDT_GATE_DESCRIPTOR)) * 32),
+ &VectorAddress
+ );
+
+ ASSERT_EFI_ERROR (Status);
+
+ IdtTable = (X64_IDT_GATE_DESCRIPTOR *) (UINTN) (VectorAddress + SizeOfTemplate * 32);
+ for (Index = 0; Index < 32; Index++) {
+ IdtTable[Index].Ia32IdtEntry.Bits.GateType = 0x8e;
+ IdtTable[Index].Ia32IdtEntry.Bits.Reserved_0 = 0;
+ IdtTable[Index].Ia32IdtEntry.Bits.Selector = SYS_CODE64_SEL;
+
+ IdtTable[Index].Ia32IdtEntry.Bits.OffsetLow = (UINT16) VectorAddress;
+ IdtTable[Index].Ia32IdtEntry.Bits.OffsetHigh = (UINT16) (VectorAddress >> 16);
+ IdtTable[Index].Offset32To63 = (UINT32) (VectorAddress >> 32);
+ IdtTable[Index].Reserved = 0;
+
+ CopyMem ((VOID *) (UINTN) VectorAddress, TemplateBase, SizeOfTemplate);
+ AsmVectorFixup ((VOID *) (UINTN) VectorAddress, (UINT8) Index);
+
+ VectorAddress += SizeOfTemplate;
+ }
+
+ gLidtDescriptor.Base = (UINTN) IdtTable;
+ AsmWriteIdtr (&gLidtDescriptor);
+ }
+ //
// Go to Long Mode. Interrupts will not get turned on until the CPU AP is loaded.
// Call x64 drivers passing in single argument, a pointer to the HOBs.
//
diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/IdtVectorAsm.S b/MdeModulePkg/Core/DxeIplPeim/Ia32/IdtVectorAsm.S
new file mode 100644
index 0000000000..cbfcf6126a
--- /dev/null
+++ b/MdeModulePkg/Core/DxeIplPeim/Ia32/IdtVectorAsm.S
@@ -0,0 +1,88 @@
+/*
+;-------------------------------------------------------------------------------
+;
+; Copyright (c) 2007, 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:
+;
+; IdtVectorAsm.S
+;
+; Abstract:
+;
+;
+;-------------------------------------------------------------------- --------
+*/
+
+ .text
+ .code32
+
+
+ .align 8
+ .globl ASM_PFX(AsmGetVectorTemplatInfo)
+ .globl ASM_PFX(AsmVectorFixup)
+/*
+;
+;-----------------------------------------------------------------------
+; Template of IDT Vector Handlers.
+;
+;-----------------------------------------------------------------------
+*/
+@VectorTemplateBase:
+ pushl %eax
+ .byte 0x6a # push #VectorNum
+@VectorNum:
+ .byte 0
+ movl CommonInterruptEntry, %eax
+ jmp *%eax
+@VectorTemplateEnd:
+
+
+ASM_PFX(AsmGetVectorTemplatInfo):
+ movl 4(%esp), %ecx
+ movl $@VectorTemplateBase, (%ecx)
+ movl $(@VectorTemplateEnd - @VectorTemplateBase), %eax
+ ret
+
+ASM_PFX(AsmVectorFixup):
+ movl 8(%esp), %eax
+ movl 4(%esp), %ecx
+ movb %al, (@VectorNum - @VectorTemplateBase)(%ecx)
+ ret
+
+/*
+; The follow algorithm is used for the common interrupt routine.
+
+;
+; +---------------------+ <-- 16-byte aligned ensured by processor
+; + Old SS +
+; +---------------------+
+; + Old RSP +
+; +---------------------+
+; + RFlags +
+; +---------------------+
+; + CS +
+; +---------------------+
+; + RIP +
+; +---------------------+
+; + Error Code +
+; +---------------------+
+; + Vector Number +
+; +---------------------+
+*/
+
+CommonInterruptEntry:
+ cli
+@@:
+ jmp @@
+
+
+
+
diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/IdtVectorAsm.asm b/MdeModulePkg/Core/DxeIplPeim/Ia32/IdtVectorAsm.asm
new file mode 100644
index 0000000000..46b49994a9
--- /dev/null
+++ b/MdeModulePkg/Core/DxeIplPeim/Ia32/IdtVectorAsm.asm
@@ -0,0 +1,95 @@
+;-------------------------------------------------------------------------------
+;
+; Copyright (c) 2007, 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:
+;
+; IdtVectorAsm.asm
+;
+; Abstract:
+;
+;
+;-------------------------------------------------------------------------------
+
+
+ .686p
+ .model flat,C
+ .code
+
+;
+;------------------------------------------------------------------------------
+; Generic IDT Vector Handlers for the Host.
+;
+;------------------------------------------------------------------------------
+
+ALIGN 8
+PUBLIC AsmGetVectorTemplatInfo
+PUBLIC AsmVectorFixup
+
+PUBLIC AsmVectorFixup
+
+@VectorTemplateBase:
+ push eax
+ db 6ah ; push #VectorNumber
+@VectorNum:
+ db 0
+ mov eax, CommonInterruptEntry
+ jmp eax
+@VectorTemplateEnd:
+
+
+AsmGetVectorTemplatInfo PROC
+ mov ecx, [esp + 4]
+ mov [ecx], @VectorTemplateBase
+ mov eax, (@VectorTemplateEnd - @VectorTemplateBase)
+ ret
+AsmGetVectorTemplatInfo ENDP
+
+
+AsmVectorFixup PROC
+ mov eax, dword ptr [esp + 8]
+ mov ecx, [esp + 4]
+ mov [ecx + (@VectorNum - @VectorTemplateBase)], al
+ ret
+AsmVectorFixup ENDP
+
+
+;---------------------------------------;
+; CommonInterruptEntry ;
+;---------------------------------------;
+; The follow algorithm is used for the common interrupt routine.
+
+;
+; +---------------------+ <-- 16-byte aligned ensured by processor
+; + Old SS +
+; +---------------------+
+; + Old RSP +
+; +---------------------+
+; + RFlags +
+; +---------------------+
+; + CS +
+; +---------------------+
+; + RIP +
+; +---------------------+
+; + Error Code +
+; +---------------------+
+; + Vector Number +
+; +---------------------+
+
+CommonInterruptEntry PROC
+ cli
+
+ jmp $
+CommonInterruptEntry ENDP
+
+END
+
+
diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/VirtualMemory.h b/MdeModulePkg/Core/DxeIplPeim/Ia32/VirtualMemory.h
index 89a7f2eceb..18fbcb907d 100644
--- a/MdeModulePkg/Core/DxeIplPeim/Ia32/VirtualMemory.h
+++ b/MdeModulePkg/Core/DxeIplPeim/Ia32/VirtualMemory.h
@@ -49,6 +49,12 @@ typedef union {
UINT64 Uint64;
} IA32_GDT;
+typedef struct {
+ IA32_IDT_GATE_DESCRIPTOR Ia32IdtEntry;
+ UINT32 Offset32To63;
+ UINT32 Reserved;
+} X64_IDT_GATE_DESCRIPTOR;
+
//
// Page-Map Level-4 Offset (PML4) and
// Page-Directory-Pointer Offset (PDPE) entries 4K & 2MB
@@ -104,4 +110,38 @@ CreateIdentityMappingPageTables (
)
;
+
+/**
+
+ Fix up the vector number in the vector code.
+
+ @param VectorBase Base address of the vector handler.
+
+ @param VectorNum Index of vector.
+
+**/
+VOID
+EFIAPI
+AsmVectorFixup (
+ VOID *VectorBase,
+ UINT8 VectorNum
+ );
+
+
+/**
+
+ Get the information of vector template.
+
+ @param TemplateBase Base address of the template code.
+
+ @return Size of the Template code.
+
+**/
+UINTN
+EFIAPI
+AsmGetVectorTemplatInfo (
+ OUT VOID **TemplateBase
+ );
+
+
#endif