From fde8a1ab65d5e33d90123a3aaa9b5c15e249689f Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Thu, 29 Apr 2021 08:49:41 +0200 Subject: Debug, add memory print driver --- 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 | 66 --------------------------------------------- src/drivers/psf.hpp | 31 --------------------- src/drivers/psftext.cc | 66 +++++++++++++++++++++++++++++++++++++++++++++ src/drivers/psftext.hpp | 31 +++++++++++++++++++++ src/drivers/vga_t.cc | 65 -------------------------------------------- src/drivers/vga_t.hpp | 35 ------------------------ src/drivers/vgatext.cc | 65 ++++++++++++++++++++++++++++++++++++++++++++ src/drivers/vgatext.hpp | 35 ++++++++++++++++++++++++ 13 files changed, 252 insertions(+), 200 deletions(-) create mode 100644 src/drivers/memtext.cc create mode 100644 src/drivers/memtext.hpp delete mode 100644 src/drivers/psf.cc delete mode 100644 src/drivers/psf.hpp create mode 100644 src/drivers/psftext.cc create mode 100644 src/drivers/psftext.hpp delete mode 100644 src/drivers/vga_t.cc delete mode 100644 src/drivers/vga_t.hpp create mode 100644 src/drivers/vgatext.cc create mode 100644 src/drivers/vgatext.hpp (limited to 'src/drivers') 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;ipsf_status.nline) - framebuffer_scrollup(psf_status.header.glyph_height); - return; - } - - 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>=1; - } - } - glyph+=psf_status.header.glyph_width/8; - } - psf_status.x++; - if(psf_status.x>psf_status.nchar){ - psf_status.y++; - psf_status.x=0; - if(psf_status.y>psf_status.nline) - framebuffer_scrollup(psf_status.header.glyph_height); - } -} \ No newline at end of file diff --git a/src/drivers/psf.hpp b/src/drivers/psf.hpp deleted file mode 100644 index 1163dee..0000000 --- a/src/drivers/psf.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include "include/boucane.hpp" - -#define PSF_MAGIC 0x864ab572 - -typedef struct PSF_HEADER { - u32 magic; - u32 version; - u32 header_length; - u32 flags; - u32 glyph_count; - u32 glyph_size; - u32 glyph_height; - u32 glyph_width; -} __attribute__((packed)) PSF_HEADER; - -typedef struct PSF_STATUS { - PSF_HEADER header; - u32 x,y; - u32 nline; - u32 nchar; - u8 bg,fg; - u8* psf_addr; -} __attribute__((packed)) PSF_STATUS; - - -extern PSF_HEADER psf_header; - -void psf_init(void* psf_addr); -void psf_putchar(char c); \ No newline at end of file diff --git a/src/drivers/psftext.cc b/src/drivers/psftext.cc new file mode 100644 index 0000000..da7e8c9 --- /dev/null +++ b/src/drivers/psftext.cc @@ -0,0 +1,66 @@ +#include "psftext.hpp" +#include "core/paging.hpp" +#include "libs/string.hpp" +#include "drivers/framebuffer.hpp" + +PSF_STATUS psf_status; + +void psftext_init(void* psf_addr){ + printk("Loading PSF font... "); + memcpy(psf_addr, &psf_status.header, sizeof(PSF_HEADER)); + if(psf_status.header.magic!=PSF_MAGIC){ + printk("Invalid PSF magic number. Abort.\n"); + return; + } + + printk("Flags %d Version %d Glyphs number %d Size %dx%d", + psf_status.header.flags, psf_status.header.version, + psf_status.header.glyph_count, psf_status.header.glyph_width, psf_status.header.glyph_height); + psf_status.x=0; + psf_status.y=0; + psf_status.psf_addr=(u8*)psf_addr; + psf_status.nline=fb_cfg.height/psf_status.header.glyph_height; + psf_status.nchar=fb_cfg.width/psf_status.header.glyph_width; + psf_status.bg=0; + psf_status.fg=200; + print("\n"); +} + +void psftext_putchar(char c){ + if(c=='\n'){ + psf_status.y++; + psf_status.x=0; + if(psf_status.y>psf_status.nline) + framebuffer_scrollup(psf_status.header.glyph_height); + return; + } + + 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>=1; + } + } + glyph+=psf_status.header.glyph_width/8; + } + psf_status.x++; + if(psf_status.x>psf_status.nchar){ + psf_status.y++; + psf_status.x=0; + if(psf_status.y>psf_status.nline) + framebuffer_scrollup(psf_status.header.glyph_height); + } +} \ No newline at end of file diff --git a/src/drivers/psftext.hpp b/src/drivers/psftext.hpp new file mode 100644 index 0000000..221a1e6 --- /dev/null +++ b/src/drivers/psftext.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include "boucane.hpp" + +#define PSF_MAGIC 0x864ab572 + +typedef struct PSF_HEADER { + u32 magic; + u32 version; + u32 header_length; + u32 flags; + u32 glyph_count; + u32 glyph_size; + u32 glyph_height; + u32 glyph_width; +} __attribute__((packed)) PSF_HEADER; + +typedef struct PSF_STATUS { + PSF_HEADER header; + u32 x,y; + u32 nline; + u32 nchar; + u8 bg,fg; + u8* psf_addr; +} __attribute__((packed)) PSF_STATUS; + + +extern PSF_HEADER psf_header; + +void psftext_init(void* psf_addr); +void psftext_putchar(char c); \ No newline at end of file diff --git a/src/drivers/vga_t.cc b/src/drivers/vga_t.cc deleted file mode 100644 index 0ff3f82..0000000 --- a/src/drivers/vga_t.cc +++ /dev/null @@ -1,65 +0,0 @@ -#include "vga_t.hpp" - -#include "include/boucane.hpp" - -#define MAX_COL 80 -#define MAX_LINE 25 - -VIDEO_STATE VS={ - (u8 *)0xB8000, - 0, - 0, - BLACK, - GRAY, -}; - -void vga_t_init(){ - PAGING_MAP(0xB8000); - PAGING_MAP(0xB8000+4096); -} - -void vga_t_putchar(char c){ - // Handle newline here - if(c=='\n'){ - VS.col=0; - VS.line+=1; - if(VS.line>=MAX_LINE){ - VS.line=MAX_LINE-1; - vga_t_scrollup(); - } - return; - } - - // Print char - VS.mem[VS.col*2+MAX_COL*VS.line*2]=c; - VS.mem[VS.col*2+MAX_COL*VS.line*2+1]=VS.fg|VS.bg<<4; - - // Refresh location - VS.col+=1; - if(VS.col>= MAX_COL){ - VS.col=0; - VS.line+=1; - if(VS.line>=MAX_LINE){ - VS.line=MAX_LINE-1; - vga_t_scrollup(); - } - } -} - -void vga_t_clear(){ - for(u8 i=0;i=MAX_LINE){ + VS.line=MAX_LINE-1; + vgatext_scrollup(); + } + return; + } + + // Print char + VS.mem[VS.col*2+MAX_COL*VS.line*2]=c; + VS.mem[VS.col*2+MAX_COL*VS.line*2+1]=VS.fg|VS.bg<<4; + + // Refresh location + VS.col+=1; + if(VS.col>= MAX_COL){ + VS.col=0; + VS.line+=1; + if(VS.line>=MAX_LINE){ + VS.line=MAX_LINE-1; + vgatext_scrollup(); + } + } +} + +void vgatext_clear(){ + for(u8 i=0;i