diff options
Diffstat (limited to 'kernel')
-rwxr-xr-x[-rw-r--r--] | kernel/entry.c | 34 | ||||
-rwxr-xr-x[-rw-r--r--] | kernel/kernel.h | 7 | ||||
-rwxr-xr-x[-rw-r--r--] | kernel/kernel.ld | 7 | ||||
-rwxr-xr-x[-rw-r--r--] | kernel/paging.c | 2 |
4 files changed, 24 insertions, 26 deletions
diff --git a/kernel/entry.c b/kernel/entry.c index 0b22ee7..19a711c 100644..100755 --- a/kernel/entry.c +++ b/kernel/entry.c @@ -24,30 +24,30 @@ void entry_main(uint32_t mb_magic, multiboot_info_t* mb_info) { // Create initial page tables. for(unsigned int i = 0; i < 1024; i++) { // Clear page directory. - entry_pagedir[i] = 0; + entry_map_p2[i] = 0; // Identity mapping of the current code. - entry_pagetable_low[i] = ((uint32_t)&addr_phys & 0xffc00000) | (i << 12) | P1_P | P1_W; + entry_map_p1[0][i] = ((uint32_t)&addr_phys & 0xffc00000) | (i << 12) | P1_P | P1_W; // Map kernelspace. if((i << 12) < ((uint32_t)&addr_virt_end & 0x003fffff)) { - entry_pagetable_high[i] = ((uint32_t)&addr_load_virt + (i << 12)) | P1_P | P1_W | P1_G; + entry_map_p1[1][i] = ((uint32_t)&addr_load_virt + (i << 12)) | P1_P | P1_W | P1_G; } else { - entry_pagetable_high[i] = 0; + entry_map_p1[1][i] = 0; } } - entry_pagetable_high[((uint32_t)&multiboot_info & 0x003ff000) >> 12] = (uint32_t)&entry_multiboot | P1_P | P1_W | P1_G; + entry_map_p1[1][((uint32_t)&multiboot_info & 0x003ff000) >> 12] = (uint32_t)&entry_multiboot_info | P1_P | P1_W | P1_G; - entry_pagedir[(uint32_t)&addr_phys >> 22] = (uint32_t)&entry_pagetable_low | P2_P | P2_W; - entry_pagedir[(uint32_t)&addr_virt >> 22] = (uint32_t)&entry_pagetable_high | P2_P | P2_W | P2_G; + entry_map_p2[(uint32_t)&addr_phys >> 22] = (uint32_t)&entry_map_p1[0] | P2_P | P2_W; + entry_map_p2[(uint32_t)&addr_virt >> 22] = (uint32_t)&entry_map_p1[1] | P2_P | P2_W | P2_G; // Map map_p1. - entry_pagedir[1022] = (uint32_t)&entry_pagedir | P2_P | P2_W | P2_G; + entry_map_p2[1022] = (uint32_t)&entry_map_p2 | P2_P | P2_W | P2_G; // Mapping stack to top without creating another page directory. - entry_pagetable_low[1023] = (uint32_t)&entry_stack | P1_P | P1_W | P1_G; - entry_pagedir[1023] = (uint32_t)&entry_pagetable_low | P2_P | P2_W | P2_G; + entry_map_p1[0][1023] = (uint32_t)&entry_stack | P1_P | P1_W | P1_G; + entry_map_p2[1023] = (uint32_t)&entry_map_p1[0] | P2_P | P2_W | P2_G; // Enable paging. asm volatile( @@ -55,7 +55,7 @@ void entry_main(uint32_t mb_magic, multiboot_info_t* mb_info) { "mov %%cr0, %0\n" "or $0x80000000, %0\n" "mov %0, %%cr0\n" - :: "r" (&entry_pagedir) : "%0" + :: "r" (&entry_map_p2) : "%0" ); // TODO: Check that segments are loaded and mapped right. @@ -90,25 +90,25 @@ unsigned int strcpy(char* source, char* target) { void entry_copy_multiboot(multiboot_info_t* mb_info) { // Copy multiboot structure. - memcpy(mb_info, &entry_multiboot, sizeof(multiboot_info_t)); - uint32_t low_p = (uint32_t)&entry_multiboot + sizeof(multiboot_info_t); + memcpy(mb_info, &entry_multiboot_info, sizeof(multiboot_info_t)); + uint32_t low_p = (uint32_t)&entry_multiboot_info + sizeof(multiboot_info_t); uint32_t high_p = (uint32_t)&multiboot_info + sizeof(multiboot_info_t); // Copy module structures. memcpy(mb_info->mods_addr, low_p, mb_info->mods_count * sizeof(multiboot_module_t)); - entry_multiboot.mods_addr = (multiboot_module_t*)high_p; + entry_multiboot_info.mods_addr = (multiboot_module_t*)high_p; multiboot_module_t* mods_addr = (multiboot_module_t*)low_p; low_p += mb_info->mods_count * sizeof(multiboot_module_t); high_p += mb_info->mods_count * sizeof(multiboot_module_t); // Copy strings. unsigned int s; - s = strcpy(entry_multiboot.cmdline, (char*)low_p); - entry_multiboot.cmdline = (char*)high_p; + s = strcpy(entry_multiboot_info.cmdline, (char*)low_p); + entry_multiboot_info.cmdline = (char*)high_p; low_p += s; high_p += s; - for(unsigned int i = 0; i < entry_multiboot.mods_count; i++) { + for(unsigned int i = 0; i < entry_multiboot_info.mods_count; i++) { s = strcpy(mods_addr[i].string, (char*)low_p); mods_addr[i].string = (char*)high_p; low_p += s; diff --git a/kernel/kernel.h b/kernel/kernel.h index 6793e7d..ac313b1 100644..100755 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -14,12 +14,11 @@ extern void addr_load_virt_end; extern void entry_stack; -extern multiboot_info_t entry_multiboot; +extern multiboot_info_t entry_multiboot_info; extern multiboot_info_t multiboot_info; -extern uint32_t entry_pagedir[]; -extern uint32_t entry_pagetable_low[]; -extern uint32_t entry_pagetable_high[]; +extern uint32_t entry_map_p2[]; +extern uint32_t entry_map_p1[2][1024]; extern volatile uint32_t map_p2[1024]; extern volatile union {uint32_t l[1024]; uint32_t b[1024][1024];} map_p1; diff --git a/kernel/kernel.ld b/kernel/kernel.ld index e377fbd..3054aec 100644..100755 --- a/kernel/kernel.ld +++ b/kernel/kernel.ld @@ -26,11 +26,10 @@ SECTIONS { . = ALIGN(0x1000); .bss_low : { - entry_pagedir = .; . += 0x1000; - entry_pagetable_low = .; . += 0x1000; - entry_pagetable_high = .; . += 0x1000; + entry_map_p2 = .; . += 0x1000; + entry_map_p1 = .; . += 0x2000; entry_stack = .; . += 0x1000; entry_stack_top = .; - entry_multiboot = .; . += 0x1000; + entry_multiboot_info = .; . += 0x1000; kernel/entry.o(.bss) } diff --git a/kernel/paging.c b/kernel/paging.c index 22da7e8..ca09936 100644..100755 --- a/kernel/paging.c +++ b/kernel/paging.c @@ -4,7 +4,7 @@ #define invlpg(page) asm volatile("invlpg (%0)" :: "r" (page)) void paging_reinit() { - map_p1.l[(uint32_t)&map_p2 >> 12] = (uint32_t)&entry_pagedir | P1_P | P1_W | P1_G; + map_p1.l[(uint32_t)&map_p2 >> 12] = (uint32_t)&entry_map_p2 | P1_P | P1_W | P1_G; invlpg(&map_p2); |