summaryrefslogtreecommitdiff
path: root/src/arch
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch')
-rw-r--r--src/arch/amd64/shim.c51
1 files changed, 17 insertions, 34 deletions
diff --git a/src/arch/amd64/shim.c b/src/arch/amd64/shim.c
index 3e9cfd7..8a9d146 100644
--- a/src/arch/amd64/shim.c
+++ b/src/arch/amd64/shim.c
@@ -22,49 +22,44 @@
// PAGE MAP LEVEL 4 ENTRY
struct pml4e {
uint64_t flags : 6;
- uint64_t _reserved : 6;
+ uint64_t : 6;
uint64_t address : 40;
- uint64_t _reserved_2 : 11;
+ uint64_t : 11;
uint64_t execute_disable : 1;
};
// PAGE DIRECTORY POINTER TABLE ENTRY
struct pdpte {
uint64_t flags : 6;
- uint64_t _reserved : 1;
+ uint64_t : 1;
uint64_t page_size : 1;
- uint64_t _reserved_2 : 2;
+ uint64_t : 4;
uint64_t address : 40;
- uint64_t _reserved_3 : 11;
+ uint64_t : 11;
uint64_t execute_disable : 1;
};
// PAGE DIRECTORY ENTRY
struct pde {
uint64_t flags : 6;
- uint64_t _reserved : 1;
+ uint64_t : 1;
uint64_t page_size : 1;
- uint64_t _reserved_2 : 2;
+ uint64_t : 4;
uint64_t address : 40;
- uint64_t _reserved_3 : 11;
+ uint64_t : 11;
uint64_t execute_disable : 1;
};
// PAGE TABLE ENTRY
struct pte {
uint64_t flags : 9;
- uint64_t _reserved : 3;
+ uint64_t : 3;
uint64_t address : 40;
- uint64_t _reserved_2 : 7;
+ uint64_t : 7;
uint64_t protection_key : 4;
uint64_t execute_disable : 1;
};
-struct pml4e pml4[512];
-struct pdpte pdpt[512];
-struct pde pd[512];
-struct pte pt[512];
-
static int get_maxphysaddr() {
uint32_t eax, ebx, ecx, edx;
__cpuid(0x80000008, eax, ebx, ecx, edx);
@@ -73,23 +68,11 @@ static int get_maxphysaddr() {
// entry point for amd64
void* amd64_shim(void *boot_info) {
- for (int i = 0; i < 512; i++) {
- pml4[i].flags = 0;
- }
- for (int i = 0; i < 512; i++) {
- pdpt[i].flags = 0;
- }
- for (int i = 0; i < 512; i++) {
- pd[i].flags = 0;
- }
- pml4[0].flags = F_PRESENT | F_WRITEABLE;
- pml4[0].address = (uint64_t)&pdpt;
- pdpt[0].flags = F_PRESENT | F_WRITEABLE;
- pdpt[0].address = (uint64_t)&pd;
- pd[0].flags = F_PRESENT | F_WRITEABLE;
- pd[0].address = (uint64_t)&pt;
- for (int i = 0; i < 512; i++) {
- pt[i].flags = F_PRESENT | F_WRITEABLE;
- pt[i].address = i * 4096;
- }
+ struct pml4e *pml4 = (struct pml4e *)0x1000;
+ struct pdpte *pdpt = (struct pdpte *)0x2000;
+ struct pde *pd = (struct pd *)0x3000;
+ struct pte *pt = (struct pt *)0x4000;
+ pd[1].flags = F_PRESENT | F_WRITEABLE;
+ pd[1].address = ((uint64_t)pt) >> 12;
+ __asm("invlpg 0x200000");
}