From 9dc527b3be9d493dcf8cf1baf78477373eb5990d Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Mon, 26 Apr 2021 12:37:34 +0200 Subject: [PATCH] Enable psf font for framebuffer display --- src/Makefile | 8 +++-- src/boot/boot.S | 9 +++++ src/boot/multiboot2.cc | 9 +++++ src/boot/multiboot2.hpp | 19 +++++++++- src/boucane.cc | 53 +++++++++++++++++++++++---- src/core/paging.hpp | 3 ++ src/drivers/acpi.cc | 61 +++++++++++++++++++++---------- src/drivers/acpi.hpp | 16 ++++++++- src/drivers/framebuffer.cc | 70 +++++++++++------------------------- src/drivers/framebuffer.hpp | 43 ++++++++++------------ src/drivers/psf.cc | 67 ++++++++++++++++++++++++++++++++++ src/drivers/psf.hpp | 31 ++++++++++++++++ src/drivers/vga_t.cc | 58 ++++++++++++++++++++++++++++++ src/drivers/vga_t.hpp | 33 +++++++++++++++++ src/libs/stdio.cc | 5 ++- src/libs/stdio.hpp | 2 +- src/libs/string.cc | 8 +++-- src/libs/string.hpp | 2 +- src/res/terminus.psf | Bin 0 -> 8951 bytes 19 files changed, 386 insertions(+), 111 deletions(-) create mode 100644 src/drivers/psf.cc create mode 100644 src/drivers/psf.hpp create mode 100644 src/drivers/vga_t.cc create mode 100644 src/drivers/vga_t.hpp create mode 100644 src/res/terminus.psf diff --git a/src/Makefile b/src/Makefile index 6e6b5c2..32c8a7a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -9,11 +9,12 @@ BOOT_OBJ := $(addsuffix .o,$(basename $(shell find ./boot -name '*.cc' -o -name DRIVERS_OBJ := $(addsuffix .o,$(basename $(shell find ./drivers -name '*.cc' -o -name '*.S'))) LIBS_OBJ := $(addsuffix .o,$(basename $(shell find ./libs -name '*.cc' -o -name '*.S'))) CORE_OBJ := $(addsuffix .o,$(basename $(shell find ./core -name '*.cc' -o -name '*.S'))) +RES_OBJ := $(addsuffix .o,$(basename $(shell find ./res -type f))) all: $(EXEC) -$(EXEC): boot/boot.o $(BOOT_OBJ) $(DRIVERS_OBJ) $(LIBS_OBJ) $(CORE_OBJ) boucane.o - echo $(BOOT_OBJ) +$(EXEC): boot/boot.o $(BOOT_OBJ) $(DRIVERS_OBJ) $(LIBS_OBJ) $(CORE_OBJ) $(RES_OBJ) boucane.o + echo "Resource: $(RES_OBJ)" $(CC) -n -T $(LD_SCRIPT) -nostdlib -o $@ $^ %.o: %.S @@ -22,6 +23,9 @@ $(EXEC): boot/boot.o $(BOOT_OBJ) $(DRIVERS_OBJ) $(LIBS_OBJ) $(CORE_OBJ) boucane. %.o: %.cc $(CC) -c -o $@ $^ +%.o: %.psf + objcopy -I binary -O elf64-x86-64 --prefix-symbol res $^ $@ + clean: rm -f $(EXEC) find ./ -name "*.o" -delete diff --git a/src/boot/boot.S b/src/boot/boot.S index 029a67e..7f12eed 100644 --- a/src/boot/boot.S +++ b/src/boot/boot.S @@ -35,6 +35,15 @@ mb_header_start: .int 12 .int _start # ----------- End tag +# ----------- Ask framebuffer tag +.align 8 +.short 5 +.short 1 +.int 20 +.int 0 +.int 0 +.int 0 +# ----------- End framebuffer .align 8 .int 0x0 .int 0x8 diff --git a/src/boot/multiboot2.cc b/src/boot/multiboot2.cc index 1b661b8..d1a912d 100644 --- a/src/boot/multiboot2.cc +++ b/src/boot/multiboot2.cc @@ -52,4 +52,13 @@ char mb2_find_old_rsdp(u32* mb2_info_addr, u64 *return_addr, u32 *return_size){ return 1; } return 0; +} + +char mb2_find_framebuffer(u32* mb2_info_addr, FRAMEBUFFER *fb){ + u32* addr=mb2_find_tag(mb2_info_addr,8); + if(addr){ + memcpy(addr, fb, sizeof(FRAMEBUFFER)); + return 1; + } + return 0; } \ No newline at end of file diff --git a/src/boot/multiboot2.hpp b/src/boot/multiboot2.hpp index da12e5f..cc28109 100644 --- a/src/boot/multiboot2.hpp +++ b/src/boot/multiboot2.hpp @@ -2,7 +2,24 @@ #include "core/types.hpp" +typedef struct TAG_HEADER { + u32 type; + u32 size; +}__attribute__((packed)) TAG_HEADER; + +typedef struct FRAMEBUFFER { + TAG_HEADER header; + u64 addr; + u32 pitch; + u32 width; + u32 height; + u8 bpp; + u8 type; + u64 color_info_addr; +} __attribute__((packed)) FRAMEBUFFER; + u32* mb2_find_tag(u32 *mb2_info_addr, char type); char mb2_find_bootloader_name(u32* mb2_info_addr, char *return_name); char mb2_find_new_rsdp(u32* mb2_info_addr, u64 *return_addr, u32 *return_size); -char mb2_find_old_rsdp(u32* mb2_info_addr, u64 *return_addr, u32 *return_size); \ No newline at end of file +char mb2_find_old_rsdp(u32* mb2_info_addr, u64 *return_addr, u32 *return_size); +char mb2_find_framebuffer(u32* mb2_info_addr, FRAMEBUFFER *fb); \ No newline at end of file diff --git a/src/boucane.cc b/src/boucane.cc index 6541902..791c5cc 100644 --- a/src/boucane.cc +++ b/src/boucane.cc @@ -4,21 +4,60 @@ #include "core/paging.hpp" #include "core/apic.hpp" #include "drivers/acpi.hpp" - +#include "drivers/psf.hpp" +#include "drivers/framebuffer.hpp" +#include "libs/stdio.hpp" +#include "core/asm.hpp" extern u32 MB_INFO; +extern u64 res_binary_res_terminus_psf_start; + + + + + + + extern "C" void boucane(){ - clear(); - printk("Booting Boucane v%d.%d.%d\n",VERSION_MAJOR,VERSION_MINOR, VERSION_PATH); - idt_enable_interrupt(); + //clear(); + //printk("Booting Boucane v%d.%d.%d\n",VERSION_MAJOR,VERSION_MINOR, VERSION_PATH); + //idt_enable_interrupt(); paging_enable(); + + FRAMEBUFFER fb_info; + if(mb2_find_framebuffer((u32*)MB_INFO, &fb_info)){ + if(fb_info.bpp>16){ + FB_CFG conf; + conf.depth=fb_info.bpp; + conf.location=fb_info.addr; + conf.pitch=fb_info.pitch; + conf.width=fb_info.width; + conf.height=fb_info.height; + framebuffer_init(conf); + psf_init((void*)&res_binary_res_terminus_psf_start); + __putchar=psf_putchar; + } + } + printk("Booting Boucane v%d.%d.%d\n",VERSION_MAJOR,VERSION_MINOR, VERSION_PATH); + printk("Jean"); + + printk("Loic"); + //framebuffer_clear(); //apic_enable(); - u64 p; +/* u64 p; u32 size; if(mb2_find_old_rsdp((u32*)MB_INFO,&p,&size)){ - acpi_load_madt((void*)p); - } + acpi_init((void*)p); + }*/ + + //FRAMEBUFFER fb; + //if(mb2_find_framebuffer((u32*)MB_INFO, &fb)){ + //printk("Framebuffer found!"); + //framebuffer_init(fb.addr, fb.pitch, fb.bpp); + //__putchar=psf_print; + //printk("Hello"); + //} while(1); } \ No newline at end of file diff --git a/src/core/paging.hpp b/src/core/paging.hpp index 15d04ad..4bb668c 100644 --- a/src/core/paging.hpp +++ b/src/core/paging.hpp @@ -18,6 +18,9 @@ /// @brief Get page address that contain addr #define PAGE(addr) (addr&(~(0xFFF))) +#define PAGING_MAP(addr) paging_allocate_addr(kpml4,(u64)(addr),(u64)(addr),PAGING_OPT_P|PAGING_OPT_RW) + +extern u64* kpml4; /** * Setup and enable PAE paging diff --git a/src/drivers/acpi.cc b/src/drivers/acpi.cc index bb48ba4..9c25202 100644 --- a/src/drivers/acpi.cc +++ b/src/drivers/acpi.cc @@ -1,33 +1,40 @@ #include "acpi.hpp" #include "core/paging.hpp" -#include "drivers/framebuffer.hpp" #include "libs/stdio.hpp" #include "libs/string.hpp" -// TODO: ALL! +RSDP rsdp; +RSDT rsdt; +IOAPIC ioapic; +char acpi_init(void* rsdp_p){ + printk("Init ACPI... "); -char acpi_load_madt(void* rsdp_p){ // Load RSDP - RSDP rsdp; memcpy(rsdp_p, &rsdp, sizeof(rsdp)); if(rsdp.signature!=ACPI_RSDP_SIGNATURE){ printk("Invalid RSDP signature\n"); return 1; } if(acpi_checksum(rsdp_p, 20)){ - printk("Wrong RSDP Signature\n\n"); + printk("Wrong RSDP Signature\n"); return 1; } - printk("ACPI Revision %d detected!\n",rsdp.revision); + printk("ACPI Revision %d detected. ",rsdp.revision); - // Load RSDT - RSDT rsdt; + // Load sub tables + if(acpi_load_rsdt()) + return 1; + if(acpi_load_madt()) + return 1; + print("\n"); + return 0; +} - paging_allocate_addr(kpml4,(u64)rsdp.rsdt_addr,(u64)rsdp.rsdt_addr,PAGING_OPT_P|PAGING_OPT_RW); +char acpi_load_rsdt(){ + PAGING_MAP(rsdp.rsdt_addr); // Ensure page is accessible memcpy((void*)rsdp.rsdt_addr, &rsdt, sizeof(rsdt)); rsdt.first_entry_addr_ptr=rsdp.rsdt_addr+36; - if(rsdt.header.signature !=ACPI_RSDT_SIGNATURE){ printk("Invalid RSDT signature\n"); return 1; @@ -36,22 +43,38 @@ char acpi_load_madt(void* rsdp_p){ printk("Wrong RSDT Signature\n"); return 1; } + printk("RSDT loaded. "); + return 0; +} +char acpi_load_madt(){ + int n_entry=(rsdt.header.length-36)/4; // Locate MADT - for(int i=0;i<10;i++){ + for(int i=0;i=MAX_LINE){ - VS.line=MAX_LINE-1; - 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; - scrollup(); - } - } +void framebuffer_init(FB_CFG config){ + fb_cfg=config; } -void clear(){ - for(u8 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 new file mode 100644 index 0000000..1163dee --- /dev/null +++ b/src/drivers/psf.hpp @@ -0,0 +1,31 @@ +#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/vga_t.cc b/src/drivers/vga_t.cc new file mode 100644 index 0000000..6e50b40 --- /dev/null +++ b/src/drivers/vga_t.cc @@ -0,0 +1,58 @@ +#include "vga_t.hpp" + +#define MAX_COL 80 +#define MAX_LINE 25 + +VIDEO_STATE VS={ + (u8 *)0xB8000, + 0, + 0, + BLACK, + GRAY, +}; + +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 clear(){ + for(u8 i=0;iXsI`hNItmen4MWSR_23Xz=fzW_A8Q!qKK7fJc-E5#|VVjw-1Hq7{ z({>!kc{@(x_>p(wyeDzqah|QNs@}|`RjzJ}V98N7+bhlfL7PY`jV#6T$9K-XRb8Gz z+)1_TtMfkh+;eZ$eB?v{q{~!kJ8}M)f6;NG@xkLSl|GGrY=kYJ1*~&Lp#` z3C-nlabiB7pVNPNK24>H(^FH$#fztl!kc@TZ%d`pE55E0nS4I8_ED|&XsvQalOx*N zQfVEjHbLoBn-0clMm{sgxd{iYw5HZPq?M5R3I7dmGT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