diff --git a/Makefile b/Makefile index 5cbd34e..f5935b7 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ eos_grub.iso : kernel.bin grub/grub.cfg eos.iso: bootloader/bootloader.bin kernel.bin cat $^ > eos.iso -kernel.bin: kernel/kernel_entry.o $(OBJ) +kernel.bin: kernel/kernel_entry.o kernel/enable_paging.o $(OBJ) gcc -o $@ $^ -Wl,--oformat=binary -ffreestanding -nostdlib -shared -Ttext 0x1000 -m32 diff --git a/drivers/vga.c b/drivers/vga.c index 45096a0..7633266 100644 --- a/drivers/vga.c +++ b/drivers/vga.c @@ -13,9 +13,9 @@ void vga_init() { // Clear screen // clear_row(0); - // clear_screen(); + clear_screen(); - set_cursor_pos(0, 11); + set_cursor_pos(0, 0); } /* diff --git a/kernel/enable_paging.asm b/kernel/enable_paging.asm new file mode 100644 index 0000000..97bae70 --- /dev/null +++ b/kernel/enable_paging.asm @@ -0,0 +1,14 @@ +[bits 32] ; 32-bit mode + +PAGING_ENABLE equ 0x80000001 +PAGE_DIRECTORY equ 0x8000 ; TODO: change me to something good + +enable_paging_registers: + mov eax, PAGE_DIRECTORY ; Move the address of the page register (page directory) into eax + ; (Using eax as a middle-man register) + mov cr3, eax ; Put the address into the cr3 register (required by the MMU) + + mov eax, cr0 ; eax as a middle-man register (again) + or eax, PAGING_ENABLE ; perform the OR operation on eax (ex: 0b01 or 0b10 = 0b11) + ; This is needed to enable paging (set the flag as "enabled") + mov cr0, eax ; Move it into cr0 to finally enable paging diff --git a/kernel/kernel.c b/kernel/kernel.c index 07c8073..70a0a72 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -4,19 +4,16 @@ #include "../lib/str.h" #include "../lib/strf.h" -void display_status(char* status_text, unsigned int bg_color) { - clear_row(0); - set_cursor_pos(0, 0); - - print(status_text, bg_color | STATUS_TEXT_COLOR); -} - void init() { - display_status("Kernel loaded", 0x70); - vga_init(); // Initialize the screen first // i.e. clear the screen et cetera. + println("Kernel loaded", DEFAULT_COLOR); + + enable_paging(); + + + println(""); char* title = "eOS Version 0.2 2021"; println(title, DEFAULT_COLOR); diff --git a/kernel/paging.c b/kernel/paging.c index 97faaab..7b5dc52 100644 --- a/kernel/paging.c +++ b/kernel/paging.c @@ -1,4 +1,14 @@ #include "paging.h" +#include "../drivers/vga.h" + +void enable_paging() { + println("Enabling paging...", DEFAULT_COLOR); + + extern int enable_paging_registers(); // Call the assembly SR + enable_paging_registers(); + + return; +} // Page Entry struct struct page_entry { diff --git a/kernel/paging.h b/kernel/paging.h index 9fb6bc2..026f644 100644 --- a/kernel/paging.h +++ b/kernel/paging.h @@ -1,6 +1,8 @@ #define PAGE_SIZE 100 #define PAGE_TABLE_SIZE 128 +void enable_paging(); + struct page_entry; char** heap_alloc(unsigned int size); // Process heap allocation