From 9dc527b3be9d493dcf8cf1baf78477373eb5990d Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Mon, 26 Apr 2021 12:37:34 +0200 Subject: Enable psf font for framebuffer display --- src/drivers/acpi.cc | 61 +++++++++++++++++++++++++++------------ src/drivers/acpi.hpp | 16 ++++++++++- src/drivers/framebuffer.cc | 70 ++++++++++++++------------------------------- src/drivers/framebuffer.hpp | 53 +++++++++++++++------------------- src/drivers/psf.cc | 67 +++++++++++++++++++++++++++++++++++++++++++ src/drivers/psf.hpp | 31 ++++++++++++++++++++ src/drivers/vga_t.cc | 58 +++++++++++++++++++++++++++++++++++++ src/drivers/vga_t.hpp | 33 +++++++++++++++++++++ 8 files changed, 290 insertions(+), 99 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 (limited to 'src/drivers') 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;i