From fde8a1ab65d5e33d90123a3aaa9b5c15e249689f Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Thu, 29 Apr 2021 08:49:41 +0200 Subject: [PATCH] Debug, add memory print driver --- src/boot/multiboot2.hpp | 2 +- src/boucane.cc | 21 +++++++++---- src/{include => }/boucane.hpp | 3 ++ src/core/apic.hpp | 2 +- src/core/paging.cc | 2 +- src/core/paging.hpp | 8 +++++ src/drivers/acpi.hpp | 2 +- src/drivers/framebuffer.cc | 2 +- src/drivers/framebuffer.hpp | 2 +- src/drivers/memtext.cc | 41 ++++++++++++++++++++++++++ src/drivers/memtext.hpp | 11 +++++++ src/drivers/{psf.cc => psftext.cc} | 6 ++-- src/drivers/{psf.hpp => psftext.hpp} | 6 ++-- src/drivers/{vga_t.cc => vgatext.cc} | 18 +++++------ src/drivers/{vga_t.hpp => vgatext.hpp} | 8 ++--- src/libs/stdio.cc | 6 ++-- src/libs/stdio.hpp | 4 +-- 17 files changed, 108 insertions(+), 36 deletions(-) rename src/{include => }/boucane.hpp (94%) create mode 100644 src/drivers/memtext.cc create mode 100644 src/drivers/memtext.hpp rename src/drivers/{psf.cc => psftext.cc} (95%) rename src/drivers/{psf.hpp => psftext.hpp} (84%) rename src/drivers/{vga_t.cc => vgatext.cc} (79%) rename src/drivers/{vga_t.hpp => vgatext.hpp} (83%) diff --git a/src/boot/multiboot2.hpp b/src/boot/multiboot2.hpp index db946a7..d36d593 100644 --- a/src/boot/multiboot2.hpp +++ b/src/boot/multiboot2.hpp @@ -1,7 +1,7 @@ #pragma once #include "core/types.hpp" -#include "include/boucane.hpp" +#include "boucane.hpp" typedef struct TAG_HEADER { u32 type; diff --git a/src/boucane.cc b/src/boucane.cc index b298e8a..5823a15 100644 --- a/src/boucane.cc +++ b/src/boucane.cc @@ -1,8 +1,12 @@ #include "boucane.hpp" +#include "core/paging.hpp" +#include "drivers/memtext.hpp" #include "core/idt.hpp" #include "boot/multiboot2.hpp" #include "drivers/framebuffer.hpp" -#include "drivers/psf.hpp" +#include "drivers/psftext.hpp" +#include "drivers/vgatext.hpp" +#include "libs/stdio.hpp" #include "libs/string.hpp" u64 kvar_kernel_vma; @@ -13,6 +17,8 @@ u64 kvar_bss_end; u64 kvar_terminus_psf_start; u64 kvar_terminus_psf_end; +void (*printk)(char *str,...)=printf; + extern "C" void boucane(u64 mb_info){ // Init linker variables asm volatile ("movq $__kernel_vma, %0":"=m"(kvar_kernel_vma)); @@ -26,11 +32,10 @@ extern "C" void boucane(u64 mb_info){ // Init data structures asm volatile ("call load_gdt"); paging_enable(); + memtext_init(); 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(fb_info.bpp>16){ @@ -41,8 +46,12 @@ extern "C" void boucane(u64 mb_info){ conf.width=fb_info.width; conf.height=fb_info.height; framebuffer_init(conf); - psf_init((void*)kvar_terminus_psf_start); - __putchar=psf_putchar; + psftext_init((void*)kvar_terminus_psf_start); + __putchar=psftext_putchar; + } + else{ + vgatext_init(); + __putchar=vgatext_putchar; } } diff --git a/src/include/boucane.hpp b/src/boucane.hpp similarity index 94% rename from src/include/boucane.hpp rename to src/boucane.hpp index fd75216..20145c5 100644 --- a/src/include/boucane.hpp +++ b/src/boucane.hpp @@ -24,3 +24,6 @@ extern u64 kvar_terminus_psf_end; // ---- Debug #define DUMP(var) asm volatile("push $0xABC; push %0; push $0xABC; _%=:; jmp _%="::"r"(var)) #define DUMP2(var1,var2) asm volatile("push $0xABC; push %0; push %1; push $0xABC; _%=:; jmp _%="::"a"(var1),"b"(var2)) + + +extern void (*printk)(char *str,...); \ No newline at end of file diff --git a/src/core/apic.hpp b/src/core/apic.hpp index a2670b3..1446edd 100644 --- a/src/core/apic.hpp +++ b/src/core/apic.hpp @@ -1,6 +1,6 @@ #pragma once -#include "include/boucane.hpp" +#include "boucane.hpp" void apic_enable(); \ No newline at end of file diff --git a/src/core/paging.cc b/src/core/paging.cc index ae390ff..c283c57 100644 --- a/src/core/paging.cc +++ b/src/core/paging.cc @@ -83,7 +83,7 @@ u64* paging_allocate_contiguous(int npages){ } } - printk("Could not allocate %d contigous pages. Kernel panic!",npages); + printk("Could not allocate %d contiguous pages. Kernel panic!",npages); while(1); return 0; } diff --git a/src/core/paging.hpp b/src/core/paging.hpp index 5817765..a3c2fec 100644 --- a/src/core/paging.hpp +++ b/src/core/paging.hpp @@ -25,11 +25,19 @@ paging_allocate_addr(kpages[0],((u64)(addr))+i,((u64)(addr))+i,PAGING_OPT_P|PAGING_OPT_RW,kvar_kernel_vma); \ }} + +#define PAGING_MAP2(addr,phy) paging_allocate_addr(kpages[0],(u64)(addr),(u64)(phy),PAGING_OPT_P|PAGING_OPT_RW,kvar_kernel_vma) +#define PAGING_MAP2_RANGE(addr, phy, n) { \ + for(u64 i=0;i<(n);i++){ \ + paging_allocate_addr(kpages[0],((u64)(addr))+i,((u64)(phy))+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 kvar_kernel_vma,kvar_stack_pma,kvar_userspace_pma; +extern void (*printk)(char *str,...); /** * Setup and enable PAE paging diff --git a/src/drivers/acpi.hpp b/src/drivers/acpi.hpp index 15374d8..3e5c410 100644 --- a/src/drivers/acpi.hpp +++ b/src/drivers/acpi.hpp @@ -1,6 +1,6 @@ #pragma once -#include "include/boucane.hpp" +#include "boucane.hpp" #define ACPI_RSDP_SIGNATURE 0x2052545020445352 #define ACPI_RSDT_SIGNATURE 0x54445352 diff --git a/src/drivers/framebuffer.cc b/src/drivers/framebuffer.cc index 4d5389c..9f90d84 100644 --- a/src/drivers/framebuffer.cc +++ b/src/drivers/framebuffer.cc @@ -22,7 +22,7 @@ void framebuffer_draw(FB_PIXEL p){ void framebuffer_scrollup(u32 npixel){ u64 start=fb_cfg.location+npixel*fb_cfg.pitch; u64 amount=fb_cfg.pitch*(fb_cfg.height-npixel); - memcpy((void*)start,(void*)fb_cfg.location,amount); + memcpy((void*)start,(void*)fb_cfg.location,amount); // TODO change because page fault can occurs } void framebuffer_clear(){ diff --git a/src/drivers/framebuffer.hpp b/src/drivers/framebuffer.hpp index 958a44b..4f5e0c1 100644 --- a/src/drivers/framebuffer.hpp +++ b/src/drivers/framebuffer.hpp @@ -1,6 +1,6 @@ #pragma once -#include "include/boucane.hpp" +#include "boucane.hpp" typedef struct { u32 pitch; diff --git a/src/drivers/memtext.cc b/src/drivers/memtext.cc new file mode 100644 index 0000000..b5371b1 --- /dev/null +++ b/src/drivers/memtext.cc @@ -0,0 +1,41 @@ +#include "memtext.hpp" +#include "core/paging.hpp" +#include "core/types.hpp" +#include "libs/string.hpp" + + + +char memtext_buffer[MEMTEXT_BUFFER_SIZE]; +u64 memtext_x=0; + +void memtext_init(){ + PAGING_MAP2_RANGE(MEMTEXT_ADDR_LOCATION,0x0,8); + u64* p_addr=(u64*)MEMTEXT_ADDR_LOCATION; + *p_addr=(u64)memtext_buffer; + + // Cleaning buffer + for(memtext_x=0;memtext_x=MEMTEXT_BUFFER_SIZE){ + memtext_scrollup(1); + memtext_buffer[memtext_x-1]=c; + return; + } + memtext_buffer[memtext_x]=c; + memtext_x++; +} + +void memtext_scrollup(u32 n){ + u64 start=(u64)memtext_buffer; + for(u64 i=0;i=MAX_LINE){ VS.line=MAX_LINE-1; - vga_t_scrollup(); + vgatext_scrollup(); } return; } @@ -41,18 +41,18 @@ void vga_t_putchar(char c){ VS.line+=1; if(VS.line>=MAX_LINE){ VS.line=MAX_LINE-1; - vga_t_scrollup(); + vgatext_scrollup(); } } } -void vga_t_clear(){ +void vgatext_clear(){ for(u8 i=0;i