| 71 | } |
| 72 | |
| 73 | void InitializeVirtualMemory() |
| 74 | { |
| 75 | IDT::RegisterInterruptHandler(14,PageFaultHandler); |
| 76 | memset(kernelPML4, 0, sizeof(pml4_t)); |
| 77 | memset(kernelPDPT, 0, sizeof(pdpt_t)); |
| 78 | memset(kernelHeapDir, 0, sizeof(page_dir_t)); |
| 79 | |
| 80 | SetPageFrame(&(kernelPML4[PML4_GET_INDEX(KERNEL_VIRTUAL_BASE)]),((uint64_t)kernelPDPT - KERNEL_VIRTUAL_BASE)); |
| 81 | kernelPML4[PML4_GET_INDEX(KERNEL_VIRTUAL_BASE)] |= 0x3; |
| 82 | kernelPML4[0] = kernelPML4[PML4_GET_INDEX(KERNEL_VIRTUAL_BASE)]; |
| 83 | |
| 84 | kernelPDPT[PDPT_GET_INDEX(KERNEL_VIRTUAL_BASE)] = ((uint64_t)kernelDir - KERNEL_VIRTUAL_BASE) | 0x3; |
| 85 | for(int j = 0; j < TABLES_PER_DIR; j++){ |
| 86 | kernelDir[j] = (PAGE_SIZE_2M * j) | 0x83; |
| 87 | } |
| 88 | |
| 89 | kernelPDPT[KERNEL_HEAP_PDPT_INDEX] = 0x3; |
| 90 | SetPageFrame(&(kernelPDPT[KERNEL_HEAP_PDPT_INDEX]), (uint64_t)kernelHeapDir - KERNEL_VIRTUAL_BASE); |
| 91 | |
| 92 | for(int i = 0; i < 4; i++){ |
| 93 | kernelPDPT[PDPT_GET_INDEX(IO_VIRTUAL_BASE) + i] = ((uint64_t)ioDirs[i] - KERNEL_VIRTUAL_BASE) | 0x3;//(PAGE_SIZE_1G * i) | 0x83; |
| 94 | for(int j = 0; j < TABLES_PER_DIR; j++){ |
| 95 | ioDirs[i][j] = (PAGE_SIZE_1G * i + PAGE_SIZE_2M * j) | (PDE_2M | PDE_WRITABLE | PDE_PRESENT | PDE_CACHE_DISABLED); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | kernelPDPT[0] = kernelPDPT[PDPT_GET_INDEX(KERNEL_VIRTUAL_BASE)]; // Its important that we identity map low memory for SMP |
| 100 | |
| 101 | for(int i = 0; i < TABLES_PER_DIR; i++){ |
| 102 | memset(&(kernelHeapDirTables[i]),0,sizeof(page_t)*PAGES_PER_TABLE); |
| 103 | } |
| 104 | |
| 105 | kernelPML4Phys = (uint64_t)kernelPML4 - KERNEL_VIRTUAL_BASE; |
| 106 | asm("mov %%rax, %%cr3" :: "a"((uint64_t)kernelPML4 - KERNEL_VIRTUAL_BASE)); |
| 107 | } |
| 108 | |
| 109 | address_space_t* CreateAddressSpace(){ |
| 110 | address_space_t* addressSpace = (address_space_t*)kmalloc(sizeof(address_space_t)); |
no test coverage detected