From 067d6e340be698b0e26b7732215a1969e0e683f3 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Wed, 28 Apr 2021 15:07:12 +0200 Subject: [PATCH] Refactoring --- src/boot/multiboot2.cc | 3 ++- src/boot/trampoline.cc | 4 ---- src/boucane.cc | 32 ++++++++++++++++++-------------- src/core/paging.cc | 10 +++++----- src/core/paging.hpp | 13 ++++++++----- src/drivers/framebuffer.cc | 2 +- src/drivers/psf.cc | 1 - src/include/boucane.hpp | 14 +++++++++++--- src/libs/string.cc | 3 --- 9 files changed, 45 insertions(+), 37 deletions(-) diff --git a/src/boot/multiboot2.cc b/src/boot/multiboot2.cc index 532012e..bac1adb 100644 --- a/src/boot/multiboot2.cc +++ b/src/boot/multiboot2.cc @@ -5,7 +5,7 @@ u32* mb2_find_tag(u32 *mb2_info_addr, char type){ PAGING_MAP(mb2_info_addr); - u32 size=(u32)mb2_info_addr[0]; + u32 size=(u32)mb2_info_addr[0]; // Todo: check for size for(u64 i=0;i16){ FB_CFG conf; @@ -36,7 +41,7 @@ extern "C" void boucane(u64 mb_info){ conf.width=fb_info.width; conf.height=fb_info.height; framebuffer_init(conf); - psf_init((void*)&res_binary_res_terminus_psf_start); + psf_init((void*)kvar_terminus_psf_start); __putchar=psf_putchar; } } @@ -44,6 +49,5 @@ extern "C" void boucane(u64 mb_info){ // Booting! printk("Booting Boucane v%d.%d.%d\n",VERSION_MAJOR,VERSION_MINOR, VERSION_PATH); - while(1); } \ No newline at end of file diff --git a/src/core/paging.cc b/src/core/paging.cc index da442bf..ae390ff 100644 --- a/src/core/paging.cc +++ b/src/core/paging.cc @@ -9,7 +9,7 @@ int kpages_next=1; // First page is for the pml4 u64* paging_allocate_table(){ u64 addr=(u64)kpages[kpages_next]; - u64* allocated=(u64*)(addr-kernel_vma); + u64* allocated=(u64*)(addr-kvar_kernel_vma); kpages_next++; return allocated; } @@ -29,17 +29,17 @@ void paging_enable() { // Allocate paging for the kernel (to not override the source // code during the next paging_allocate_table() calls) - paging_allocate_contiguous(userspace_pma/4096); + paging_allocate_contiguous(kvar_userspace_pma/4096); // Setting up new kernel address space for(u64 i=0;i<=0x10000000;i+=4096){ - paging_allocate_addr(kpages[0],kernel_vma+i,i, 0x3,0); // Identity map + paging_allocate_addr(kpages[0],kvar_kernel_vma+i,i, 0x3,0); // Identity map } // 4096 bytes stack - paging_allocate_addr(kpages[0],kernel_vma-4096,stack_pma,0x3,0); + paging_allocate_addr(kpages[0],kvar_kernel_vma-4096,kvar_stack_pma,0x3,0); // Load new pml4 - u64 kpage_phy=((u64)kpages[0]-kernel_vma); + u64 kpage_phy=((u64)kpages[0]-kvar_kernel_vma); asm volatile( "mov %0, %%rax \n\t" "mov %%rax, %%cr3 \n\t" diff --git a/src/core/paging.hpp b/src/core/paging.hpp index 01e45a7..5817765 100644 --- a/src/core/paging.hpp +++ b/src/core/paging.hpp @@ -2,6 +2,7 @@ #include "core/types.hpp" +#define MAX_TABLES 280 #define PAGING_MAX_PAGE (20*512) /** * Current number of page (from the beginning of the ram) used by the kernel that @@ -18,15 +19,17 @@ /// @brief Get page address that contain addr #define PAGE(addr) (addr&(~(0xFFF))) -#define PAGING_MAP(addr) paging_allocate_addr(kpages[0],(u64)(addr),(u64)(addr),PAGING_OPT_P|PAGING_OPT_RW,kernel_vma) -#define MAX_TABLES 280 +#define PAGING_MAP(addr) paging_allocate_addr(kpages[0],(u64)(addr),(u64)(addr),PAGING_OPT_P|PAGING_OPT_RW,kvar_kernel_vma) +#define PAGING_MAP_RANGE(addr, n) { \ + for(u64 i=0;i<(n);i++){ \ + paging_allocate_addr(kpages[0],((u64)(addr))+i,((u64)(addr))+i,PAGING_OPT_P|PAGING_OPT_RW,kvar_kernel_vma); \ +}} /// @brief All PAE table structures are allocated here extern u64 kpages[MAX_TABLES][512]; -/// cf boucane.hpp -extern u64 kernel_vma,stack_pma,userspace_pma; - +/// CF boucane.hpp +extern u64 kvar_kernel_vma,kvar_stack_pma,kvar_userspace_pma; /** * Setup and enable PAE paging diff --git a/src/drivers/framebuffer.cc b/src/drivers/framebuffer.cc index 2ac47db..4d5389c 100644 --- a/src/drivers/framebuffer.cc +++ b/src/drivers/framebuffer.cc @@ -7,11 +7,11 @@ FB_CFG fb_cfg; void framebuffer_init(FB_CFG config){ fb_cfg=config; + PAGING_MAP_RANGE(fb_cfg.location, fb_cfg.pitch*fb_cfg.height); } void framebuffer_draw(FB_PIXEL p){ u8 *pixel=(u8*)(fb_cfg.location+p.x*(fb_cfg.depth/8)+p.y*fb_cfg.pitch); - PAGING_MAP(pixel); pixel[0]=p.r; pixel[1]=p.g; pixel[2]=p.b; diff --git a/src/drivers/psf.cc b/src/drivers/psf.cc index 187d711..ce838e8 100644 --- a/src/drivers/psf.cc +++ b/src/drivers/psf.cc @@ -38,7 +38,6 @@ void psf_putchar(char c){ u8* glyph=(psf_status.psf_addr+psf_status.header.header_length+c*psf_status.header.glyph_size); FB_PIXEL pixel; for(int i=0;i