diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2021-04-28 10:46:36 +0200 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2021-04-28 10:46:36 +0200 |
| commit | 152f14654bfb438d074833e3c8d5392d300f5095 (patch) | |
| tree | 633e4dad7153a1d01f7f24b8fd0386c6fe7848ca | |
| parent | f13b26eeb4f9afba3a1aed2516655b34139979aa (diff) | |
Debug trampoline and paging
| -rw-r--r-- | src/boot/boot.S | 12 | ||||
| -rw-r--r-- | src/boot/trampoline.cc | 13 | ||||
| -rw-r--r-- | src/boucane.cc | 21 | ||||
| -rw-r--r-- | src/core/paging.cc | 12 | ||||
| -rw-r--r-- | src/core/paging.hpp | 3 | ||||
| -rw-r--r-- | src/include/boucane.hpp | 7 |
6 files changed, 46 insertions, 22 deletions
diff --git a/src/boot/boot.S b/src/boot/boot.S index 73ee637..d8795d0 100644 --- a/src/boot/boot.S +++ b/src/boot/boot.S @@ -1,8 +1,6 @@ .globl _start -.globl MB_INFO .extern _bss_start .extern _bss_end -.extern higherhalf .section .multiboot @@ -35,7 +33,7 @@ mb_header_start: # ----------- End tag # ----------- Ask framebuffer tag .align 8 -.short 6 +.short 5 .short 1 .int 20 .int 0 @@ -55,6 +53,7 @@ MB_INFO: # Will contains the Multiboot2 information data structure address _start: mov %ebx, (MB_INFO) + # ----- Setup PAE Paging (identity on the first 10MB) mov $8192, %ecx # 8*4096/4 (8 tables of 4096 byte each divide by 4 because of movl) mov $0, %eax @@ -122,8 +121,12 @@ mov %ax, %gs mov %ax, %ss mov $__stack_pma, %esp -# Setup +# Setup +movq (MB_INFO), %rdi +mov $0xFFFFFFFF,%rax +and %rax, %rdi call trampoline +movq %rax, (MB_INFO) mov $__kernel_vma, %rsp # Zeroing the .bss section @@ -138,6 +141,7 @@ start_zeroing: end_zeroing: # Launch kernel +movq (MB_INFO), %rdi call boucane # GDT diff --git a/src/boot/trampoline.cc b/src/boot/trampoline.cc index b03bd43..a75b472 100644 --- a/src/boot/trampoline.cc +++ b/src/boot/trampoline.cc @@ -10,6 +10,10 @@ /// @brief Define where first PAE paging paging will be u64 trampoline_next_page; +/// @brief Ensure +#define MAX_MB_INFOS 4096 +u8 mb_infos[MAX_MB_INFOS]; + u64 trampoline_paging_allocate_table(){ for(u64 i=0;i<512;i++) ((u64*)trampoline_next_page)[i]=0; @@ -63,7 +67,12 @@ void trampoline_paging_allocate_addr(u64* pml4_table, u64 virt, u64 phy, u16 opt /** * Setup High-Half Kernel Paging */ -extern "C" void trampoline(){ +extern "C" u8* trampoline(u8* mb_infos_addr){ + // Save mb infos before anything else + for(int i=0;i<MAX_MB_INFOS;i++){ + mb_infos[i]=mb_infos_addr[i]; + } + u64 kernel_vma,stack_pma; asm("movq $__kernel_vma, %0":"=r"(kernel_vma)); asm("movq $__userspace_pma, %0":"=r"(trampoline_next_page)); @@ -91,4 +100,6 @@ extern "C" void trampoline(){ "movq %0, %%rax \n\t" "movq %%rax, %%cr3 \n\t" :: "r" (pml4)); + + return mb_infos; }
\ No newline at end of file diff --git a/src/boucane.cc b/src/boucane.cc index 0209281..1e58d65 100644 --- a/src/boucane.cc +++ b/src/boucane.cc @@ -9,18 +9,25 @@ #include "libs/stdio.hpp" #include "core/asm.hpp" +u64 kernel_vma,stack_pma,userspace_pma; -extern u32 MB_INFO; -extern u64 res_binary_res_terminus_psf_start; +extern "C" void boucane(u64 mb_info){ + // Init linker variables + asm volatile ("movq $__kernel_vma, %0":"=m"(kernel_vma)); + asm volatile ("movq $__userspace_pma, %0":"=m"(userspace_pma)); + asm volatile ("movq $__stack_pma, %0":"=m"(stack_pma)); + asm volatile ("call load_gdt"); -extern "C" void boucane(){ // Init data structures - LOAD_GDT(); paging_enable(); idt_enable_interrupt(); + // Looking for framebuffer + vga_t_init(); + vga_t_clear(); FRAMEBUFFER fb_info; - if(mb2_find_framebuffer((u32*)&MB_INFO, &fb_info)){ + + if(mb2_find_framebuffer((u32*)mb_info, &fb_info)){ if(fb_info.bpp>16){ FB_CFG conf; conf.depth=fb_info.bpp; @@ -33,8 +40,8 @@ extern "C" void boucane(){ __putchar=psf_putchar; } } - vga_t_init(); - vga_t_clear(); + + // Booting! printk("Booting Boucane v%d.%d.%d\n",VERSION_MAJOR,VERSION_MINOR, VERSION_PATH); diff --git a/src/core/paging.cc b/src/core/paging.cc index 73a5c63..da442bf 100644 --- a/src/core/paging.cc +++ b/src/core/paging.cc @@ -4,7 +4,6 @@ #include "libs/string.hpp" char paging_status[PAGING_MAX_PAGE / 8]; -u64 kernel_vma,stack_pma,userspace_pma; u64 kpages[MAX_TABLES][512] __attribute__((aligned(4096))); int kpages_next=1; // First page is for the pml4 @@ -16,10 +15,6 @@ u64* paging_allocate_table(){ } void paging_enable() { - // Init linker variables - asm("movq $__kernel_vma, %0":"=r"(kernel_vma)); - asm("movq $__userspace_pma, %0":"=r"(userspace_pma)); - asm("movq $__stack_pma, %0":"=r"(stack_pma)); // Init status for (int i = 0; i < PAGING_MAX_PAGE / 8; i++) { @@ -28,9 +23,10 @@ void paging_enable() { // Init tables for(int i=0;i<MAX_TABLES;i++){ - memset(kpages[i], 0, 512*64); + for(int j=0;j<512;j++) + kpages[i][j]=0; } - + // Allocate paging for the kernel (to not override the source // code during the next paging_allocate_table() calls) paging_allocate_contiguous(userspace_pma/4096); @@ -41,7 +37,7 @@ void paging_enable() { } // 4096 bytes stack paging_allocate_addr(kpages[0],kernel_vma-4096,stack_pma,0x3,0); - + // Load new pml4 u64 kpage_phy=((u64)kpages[0]-kernel_vma); asm volatile( diff --git a/src/core/paging.hpp b/src/core/paging.hpp index 089bd47..01e45a7 100644 --- a/src/core/paging.hpp +++ b/src/core/paging.hpp @@ -24,9 +24,10 @@ /// @brief All PAE table structures are allocated here extern u64 kpages[MAX_TABLES][512]; -/// @brief Various variables from the linker +/// cf boucane.hpp extern u64 kernel_vma,stack_pma,userspace_pma; + /** * Setup and enable PAE paging */ diff --git a/src/include/boucane.hpp b/src/include/boucane.hpp index f178f42..79975a3 100644 --- a/src/include/boucane.hpp +++ b/src/include/boucane.hpp @@ -10,4 +10,9 @@ #include "libs/stdio.hpp" #include "libs/string.hpp" -#define LOAD_GDT() asm("call load_gdt")
\ No newline at end of file +/// @brief Various variables from the linker +extern u64 kernel_vma,stack_pma,userspace_pma; + +/// @brief Binary references +extern u64 res_binary_res_terminus_psf_start; +extern u64 res_binary_res_terminus_psf_end; |
