From 3c49c1ed7d782c678c1712cc3af1fe78e3e4eba4 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Fri, 29 Oct 2021 10:04:22 +0200 Subject: [PATCH] Minor refactor, main is not init --- bootloader/bootloader.asm | 2 +- bootloader/pm/vga/print.asm | 2 +- drivers/vga.c | 12 +++++++++--- drivers/vga.h | 4 ++-- kernel/kernel.c | 13 +++++++++++-- kernel/kernel.h | 2 ++ kernel/kernel_entry.asm | 4 ++-- 7 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 kernel/kernel.h diff --git a/bootloader/bootloader.asm b/bootloader/bootloader.asm index 09432ff..520aa6f 100644 --- a/bootloader/bootloader.asm +++ b/bootloader/bootloader.asm @@ -87,7 +87,7 @@ load_kernel: stat_pm_init: db "Entering 32bit Protected Mode...", ASCII_END stat_kernel_load: db "Loading kernel into memory...", ASCII_END -stat_boot_success: db "Booting complete!", ASCII_END +stat_boot_success: db "Booting finished. Loading kernel...", ASCII_END BOOT_DRIVE: db 0 diff --git a/bootloader/pm/vga/print.asm b/bootloader/pm/vga/print.asm index 6d1031e..c444f9c 100644 --- a/bootloader/pm/vga/print.asm +++ b/bootloader/pm/vga/print.asm @@ -3,7 +3,7 @@ ; VGA base address: 0xb8000 ; Charpos = 0xb8000 + 2(row*80 + col) -vga_color_buf: db 0x0f ; Buffer to be changed so that we can choose colors! +vga_color_buf: db 0x7f ; Buffer to be changed so that we can choose colors! vga_print: pusha diff --git a/drivers/vga.c b/drivers/vga.c index 26b8b4f..45096a0 100644 --- a/drivers/vga.c +++ b/drivers/vga.c @@ -12,6 +12,7 @@ void vga_init() { port_outb(0x3d5, 0x20); // Clear screen + // clear_row(0); // clear_screen(); set_cursor_pos(0, 11); @@ -44,10 +45,15 @@ void set_cursor_pos(unsigned int col, unsigned int row) { /* Graphics Functions */ +void clear_row(unsigned int row) { + for( int c = 0; c < MAX_COLS; c++ ) + writechar(0x20, c, row, 0x0); +} + + void clear_screen() { - for( int c = 0; c < MAX_COLS; c++ ) - for( int r = 0; r < MAX_ROWS; r++ ) - writechar(0x20, c, r, 0x0); + for( int r = 0; r < MAX_ROWS; r++ ) + clear_row(r); } /* diff --git a/drivers/vga.h b/drivers/vga.h index 3a9365f..82c5af4 100644 --- a/drivers/vga.h +++ b/drivers/vga.h @@ -1,8 +1,7 @@ #define VGA_ADDRESS (char*)0xb8000 #define VGA_ADDRESS_MAX (char*)0xb8fa0 -// #define DEFAULT_COLOR 0x07 -#define DEFAULT_COLOR 0x0f +#define DEFAULT_COLOR 0x07 #define MAX_ROWS 25 #define MAX_COLS 80 @@ -14,6 +13,7 @@ enum align {LEFT, RIGHT, MIDDLE}; char* get_memory_charpos(unsigned int col, unsigned int row); void writechar(char c, unsigned int col, unsigned int row, int colorcode); void clear_screen(); +void clear_row(unsigned int row); void set_cursor_pos(); void print(); void println(); diff --git a/kernel/kernel.c b/kernel/kernel.c index 67a13cf..343a8da 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -1,9 +1,19 @@ +#include "kernel.h" #include "memory.h" #include "../drivers/vga.h" #include "../lib/str.h" #include "../lib/strf.h" -void main() { +void display_status(char* status_text) { + clear_row(0); + set_cursor_pos(0, 0); + + print(status_text, 0x7f); +} + +void init() { + display_status("Kernel loaded"); + vga_init(); // Initialize the screen first // i.e. clear the screen et cetera. @@ -21,6 +31,5 @@ void main() { char* strbuf = "Concat test: "; char* str2 = "Works!"; strbuf = strcat(strbuf, str2); - set_cursor_pos(0, 4); println(strbuf, DEFAULT_COLOR); } diff --git a/kernel/kernel.h b/kernel/kernel.h new file mode 100644 index 0000000..4ef9269 --- /dev/null +++ b/kernel/kernel.h @@ -0,0 +1,2 @@ +void init(); +void display_status(char*); diff --git a/kernel/kernel_entry.asm b/kernel/kernel_entry.asm index 3d2fa88..13b7cd7 100644 --- a/kernel/kernel_entry.asm +++ b/kernel/kernel_entry.asm @@ -1,5 +1,5 @@ [bits 32] -[extern main] +[extern init] -call main +call init jmp $