VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware2/VBoxPkg/edk2.patch-idtgdt@ 29229

Last change on this file since 29229 was 29229, checked in by vboxsync, 15 years ago

attempt to fix EFI

File size: 7.0 KB
Line 
1Index: UefiCpuPkg/CpuDxe/CpuDxe.inf
2===================================================================
3--- UefiCpuPkg/CpuDxe/CpuDxe.inf (revision 9332)
4+++ UefiCpuPkg/CpuDxe/CpuDxe.inf (working copy)
5@@ -62,6 +62,9 @@
6 [Protocols]
7 gEfiCpuArchProtocolGuid
8
9+[Guids]
10+ gEfiEventVirtualAddressChangeGuid # ALWAYS_CONSUMED Create Event: EVENT_GROUP_GUID
11+
12 [Depex]
13 TRUE
14
15Index: UefiCpuPkg/CpuDxe/CpuGdt.c
16===================================================================
17--- UefiCpuPkg/CpuDxe/CpuGdt.c (revision 9332)
18+++ UefiCpuPkg/CpuDxe/CpuGdt.c (working copy)
19@@ -67,6 +67,9 @@
20 #error CPU type not supported for CPU GDT initialization!
21 #endif
22
23+VOID * Gdt;
24+UINT32 GdtSize;
25+
26 //
27 // Global descriptor table (GDT) Template
28 //
29@@ -161,6 +164,20 @@
30 },
31 };
32
33+VOID EFIAPI
34+LoadGdt(VOID* Gdt, UINT32 GdtSize)
35+{
36+ IA32_DESCRIPTOR gdtPtr;
37+
38+ //
39+ // Write GDT register
40+ //
41+ gdtPtr.Base = (UINT32)(UINTN)Gdt;
42+ gdtPtr.Limit = GdtSize - 1;
43+
44+ AsmWriteGdtr (&gdtPtr);
45+}
46+
47 /**
48 Initialize Global Descriptor Table
49
50@@ -169,27 +186,27 @@
51 InitGlobalDescriptorTable (
52 )
53 {
54- GDT_ENTRIES *gdt;
55- IA32_DESCRIPTOR gdtPtr;
56-
57 //
58 // Allocate Runtime Data for the GDT
59 //
60- gdt = AllocateRuntimePool (sizeof (GdtTemplate) + 8);
61- ASSERT (gdt != NULL);
62- gdt = ALIGN_POINTER (gdt, 8);
63+ GdtSize = sizeof (GdtTemplate);
64+#if 0
65+ Gdt = AllocateRuntimePool (GdtSize + 8);
66+ ASSERT (Gdt != NULL);
67+ Gdt = ALIGN_POINTER (Gdt, 8);
68+#else
69+ Gdt = (VOID*)(UINTN)HandyCpuPage;
70+#endif
71
72 //
73 // Initialize all GDT entries
74 //
75- CopyMem (gdt, &GdtTemplate, sizeof (GdtTemplate));
76+ CopyMem (Gdt, &GdtTemplate, GdtSize);
77
78 //
79 // Write GDT register
80 //
81- gdtPtr.Base = (UINT32)(UINTN)(VOID*) gdt;
82- gdtPtr.Limit = sizeof (GdtTemplate) - 1;
83- AsmWriteGdtr (&gdtPtr);
84+ LoadGdt(Gdt, GdtSize);
85
86 //
87 // Update selector (segment) registers base on new GDT
88@@ -197,4 +214,3 @@
89 SetCodeSelector ((UINT16)CPU_CODE_SEL);
90 SetDataSelectors ((UINT16)CPU_DATA_SEL);
91 }
92-
93Index: UefiCpuPkg/CpuDxe/CpuDxe.c
94===================================================================
95--- UefiCpuPkg/CpuDxe/CpuDxe.c (revision 9332)
96+++ UefiCpuPkg/CpuDxe/CpuDxe.c (working copy)
97@@ -14,11 +14,14 @@
98
99 #include "CpuDxe.h"
100
101+EFI_EVENT mEfiVirtualNotifyEvent;
102+EFI_PHYSICAL_ADDRESS HandyCpuPage;
103+IA32_IDT_GATE_DESCRIPTOR* Idt;
104+UINT32 IdtSize;
105+
106 //
107 // Global Variables
108 //
109-IA32_IDT_GATE_DESCRIPTOR gIdtTable[INTERRUPT_VECTOR_NUMBER] = { 0 };
110-
111 EFI_CPU_INTERRUPT_HANDLER ExternalVectorTable[0x100];
112 BOOLEAN InterruptState = FALSE;
113 EFI_HANDLE mCpuHandle = NULL;
114@@ -1004,8 +1007,6 @@
115 )
116 {
117 EFI_STATUS Status;
118- VOID *IdtPtrAlignmentBuffer;
119- IA32_DESCRIPTOR *IdtPtr;
120 UINTN Index;
121 UINTN CurrentHandler;
122
123@@ -1015,27 +1016,33 @@
124 // Intialize IDT
125 //
126 CurrentHandler = (UINTN)AsmIdtVector00;
127+
128+ //
129+ // Allocate Runtime Data for the IDT
130+ //
131+ IdtSize = INTERRUPT_VECTOR_NUMBER*sizeof(IA32_IDT_GATE_DESCRIPTOR);
132+#if 0
133+ Idt = AllocateRuntimePool (IdtSize + 16);
134+ ASSERT (Idt != NULL);
135+ Idt = ALIGN_POINTER (Idt, 16);
136+#else
137+ Idt = (VOID*)(UINTN)HandyCpuPage + 0x500;
138+#endif
139+
140 for (Index = 0; Index < INTERRUPT_VECTOR_NUMBER; Index ++, CurrentHandler += 0x08) {
141- gIdtTable[Index].Bits.OffsetLow = (UINT16)CurrentHandler;
142- gIdtTable[Index].Bits.Selector = AsmReadCs();
143- gIdtTable[Index].Bits.Reserved_0 = 0;
144- gIdtTable[Index].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;
145- gIdtTable[Index].Bits.OffsetHigh = (UINT16)(CurrentHandler >> 16);
146+ Idt[Index].Bits.OffsetLow = (UINT16)CurrentHandler;
147+ Idt[Index].Bits.Selector = AsmReadCs();
148+ Idt[Index].Bits.Reserved_0 = 0;
149+ Idt[Index].Bits.GateType = IA32_IDT_GATE_TYPE_INTERRUPT_32;
150+ Idt[Index].Bits.OffsetHigh = (UINT16)(CurrentHandler >> 16);
151 #if defined (MDE_CPU_X64)
152- gIdtTable[Index].Bits.OffsetUpper = (UINT32)(CurrentHandler >> 32);
153- gIdtTable[Index].Bits.Reserved_1 = 0;
154+ Idt[Index].Bits.OffsetUpper = (UINT32)(CurrentHandler >> 32);
155+ Idt[Index].Bits.Reserved_1 = 0;
156 #endif
157 }
158
159- //
160- // Load IDT Pointer
161- //
162- IdtPtrAlignmentBuffer = AllocatePool (sizeof (*IdtPtr) + 16);
163- IdtPtr = ALIGN_POINTER (IdtPtrAlignmentBuffer, 16);
164- IdtPtr->Base = (UINT32)(((UINTN)(VOID*) gIdtTable) & (BASE_4GB-1));
165- IdtPtr->Limit = sizeof (gIdtTable) - 1;
166- AsmWriteIdtr (IdtPtr);
167- FreePool (IdtPtrAlignmentBuffer);
168+ // Load IDT
169+ LoadIdt(Idt, IdtSize);
170
171 //
172 // Initialize Exception Handlers
173@@ -1052,7 +1059,50 @@
174
175 }
176
177+VOID EFIAPI
178+LoadIdt(VOID* Idt, UINT32 IdtSize)
179+{
180+ IA32_DESCRIPTOR IdtPtr;
181
182+ IdtPtr.Base = (UINT32)(((UINTN) Idt) & (BASE_4GB-1));
183+ IdtPtr.Limit = IdtSize - 1;
184+ AsmWriteIdtr (&IdtPtr);
185+}
186+
187+UINT32
188+EFIAPI
189+IoWrite32 (
190+ IN UINTN Port,
191+ IN UINT32 Value
192+ )
193+{
194+ __asm__ __volatile__ ("outl %0,%w1" : : "a" (Value), "d" ((UINT16)Port));
195+ return Value;
196+}
197+
198+VOID
199+EFIAPI
200+CpuLibVirtualNotifyEvent (
201+ IN EFI_EVENT Event,
202+ IN VOID *Context
203+ )
204+{
205+ EFI_RUNTIME_SERVICES * rs = (EFI_RUNTIME_SERVICES *)Context;
206+
207+ rs->ConvertPointer (0, (VOID **) &Gdt);
208+ rs->ConvertPointer (0, (VOID **) &Idt);
209+
210+ DisableInterrupts();
211+
212+ LoadIdt(Idt, IdtSize);
213+ LoadGdt(Gdt, GdtSize);
214+
215+ //IoWrite32(0xef11, 1);
216+}
217+
218+extern EFI_GUID gEfiEventVirtualAddressChangeGuid;
219+
220+
221 /**
222 Initialize the state information for the CPU Architectural Protocol.
223
224@@ -1073,6 +1123,17 @@
225 {
226 EFI_STATUS Status;
227
228+
229+ // Allocate handy page
230+ HandyCpuPage = 0xffffffff;
231+ Status = gBS->AllocatePages (
232+ AllocateMaxAddress,
233+ EfiReservedMemoryType,
234+ 1,
235+ &HandyCpuPage );
236+ ASSERT_EFI_ERROR (Status);
237+ ASSERT (HandyCpuPage != 0xffffffff);
238+
239 //
240 // Make sure interrupts are disabled
241 //
242@@ -1103,6 +1164,18 @@
243 //
244 RefreshGcdMemoryAttributes ();
245
246+
247+ // Register virtual address change notifier
248+#if 0
249+ gBS->CreateEventEx (
250+ EVT_NOTIFY_SIGNAL,
251+ TPL_NOTIFY,
252+ CpuLibVirtualNotifyEvent,
253+ SystemTable->RuntimeServices,
254+ &gEfiEventVirtualAddressChangeGuid,
255+ &mEfiVirtualNotifyEvent
256+ );
257+#endif
258+
259 return Status;
260 }
261-
262Index: UefiCpuPkg/CpuDxe/CpuDxe.h
263===================================================================
264--- UefiCpuPkg/CpuDxe/CpuDxe.h (revision 9332)
265+++ UefiCpuPkg/CpuDxe/CpuDxe.h (working copy)
266@@ -136,5 +136,17 @@
267 );
268
269
270+VOID EFIAPI
271+LoadGdt(VOID* Gdt, UINT32 GdtSize);
272+
273+VOID EFIAPI
274+LoadIdt(VOID* Idt, UINT32 IdtSize);
275+
276+extern EFI_PHYSICAL_ADDRESS HandyCpuPage;
277+extern VOID* Gdt;
278+extern UINT32 GdtSize;
279+extern IA32_IDT_GATE_DESCRIPTOR* Idt;
280+extern UINT32 IdtSize;
281+
282 #endif
283
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette