diff --git a/kernel/kernel.c b/kernel/kernel.c index 0c5103e5252b5e390c2c5136ab0b89922d74e798..02139bfa4c27edd939dd04d858611b0f3aaf1c2a 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -5,8 +5,8 @@ #include "drivers/display.h" #include "kernel/mem/frame.h" #include "mem/gdt.h" +#include "mem/paging.h" #include "x86.h" -#include <stdint.h> // These are defined in the linker script: kernel.ld extern void ld_kernel_start(); @@ -19,7 +19,10 @@ void kernel_main(multiboot_info_t *mbi) { gdt_init(); - frame_init(10); + uint_t available_ram = multiboot_get_RAM_in_KB(); + + frame_init(available_ram); + paging_init(available_ram); struct terminal_t term; @@ -27,6 +30,7 @@ void kernel_main(multiboot_info_t *mbi) { return; } + /*kprintf(&term, "Gonna crash %c\n", *((char *)stack_start));*/ kprintf(&term, "YoctOS started\n"); kprintf(&term, "VBE mode %dx%d %dbpp initialized (addr=0x%x,pitch=%d)\n", mbi->framebuffer_width, mbi->framebuffer_height, @@ -46,99 +50,70 @@ void kernel_main(multiboot_info_t *mbi) { } } - dbg_frame_allocator(&term); + if (term_set_colours(&term, GREEN, BLACK) != 0) { + return; + } + + kprintf(&term, "---------------------\n"); + char *ptr = (char *)multiboot_get_mod_contents(0); + + if (multiboot_get_mod_size(0)) { + while (*ptr) { + kprintf(&term, "%c", *ptr++); + } + } + kprintf(&term, "---------------------\n"); + + if (term_set_colours(&term, WHITE, BLACK) != 0) { + return; + } + + kprintf(&term, "\nVariable arguments with formatting test :\n"); + kprintf(&term, "Hello Mr. %c %s, %d is quite young! (0x%x)\n", 'X', "007", + -12345678, 0xDEADBEEF); + + kprintf(&term, "\nIBM Code Page 437 extended ASCII characters set:\n"); + display_charset(&term); - void *ptr = frame_alloc(); - void *ptr2 = frame_alloc(); - void *ptr3 = frame_alloc(); - void *ptr4 = frame_alloc(); + kprintf(&term, "\nColor tests:\n"); - kprintf(&term, "allocated address = 0x%x\n", ptr); - kprintf(&term, "another ptr = 0x%x\n", ptr2); - kprintf(&term, "another ptr = 0x%x\n", ptr3); - kprintf(&term, "another ptr = 0x%x\n", ptr4); + if (term_set_colours(&term, YELLOW, RED) != 0) { + return; + } - frame_free(ptr); - kprintf(&term, "Free'd first ptr"); + kprintf(&term, "Yellow text on red background\n"); - void *new = frame_alloc(); - kprintf(&term, "alloc after free, new ptr = 0x%x\n", new); + if (term_set_colours(&term, BLACK, LIGHT_BLUE) != 0) { + return; + } - frame_free(ptr3); - kprintf(&term, "Free'd third ptr"); + kprintf(&term, "Black text on light blue background\n"); + + if (term_set_colours(&term, WHITE, BLACK) != 0) { + return; + } - void *new3 = frame_alloc(); - kprintf(&term, "alloc after free, new3 ptr = 0x%x\n", new3); + uint8_t *pix = (uint8_t *)multiboot_get_mod_contents(1); + char *char_dim = multiboot_get_cmdline(1); + uint32_t dim[2] = {0}; - kprintf(&term, "Free total frames = %d\n", frame_total_free()); + char *token = strtok(char_dim, " "); + + int idx = 0; + + while (token) { + dim[idx] = atoi(token); + token = strtok(NULL, " "); + idx++; + } dbg_frame_allocator(&term); - /*kprintf(&term, "\n\n");*/ - /*dbg_frame_bmp(&term);*/ - /**/ - /*if (term_set_colours(&term, GREEN, BLACK) != 0) {*/ - /* return;*/ - /*}*/ - /**/ - /*kprintf(&term, "---------------------\n");*/ - /*char *ptr = (char *)multiboot_get_mod_contents(0);*/ - /**/ - /*if (multiboot_get_mod_size(0)) {*/ - /* while (*ptr) {*/ - /* kprintf(&term, "%c", *ptr++);*/ - /* }*/ - /*}*/ - /**/ - /*kprintf(&term, "---------------------\n");*/ - /**/ - /*if (term_set_colours(&term, WHITE, BLACK) != 0) {*/ - /* return;*/ - /*}*/ - /**/ - /*kprintf(&term, "\nVariable arguments with formatting test :\n");*/ - /*kprintf(&term, "Hello Mr. %c %s, %d is quite young! (0x%x)\n", 'X', - * "007",*/ - /* -12345678, 0xDEADBEEF);*/ - /**/ - /*kprintf(&term, "\nIBM Code Page 437 extended ASCII characters set:\n");*/ - /*display_charset(&term);*/ - /**/ - /*kprintf(&term, "\nColor tests:\n");*/ - /**/ - /*if (term_set_colours(&term, YELLOW, RED) != 0) {*/ - /* return;*/ - /*}*/ - /**/ - /*kprintf(&term, "Yellow text on red background\n");*/ - /**/ - /*if (term_set_colours(&term, BLACK, LIGHT_BLUE) != 0) {*/ - /* return;*/ - /*}*/ - /**/ - /*kprintf(&term, "Black text on light blue background\n");*/ - /**/ - /*if (term_set_colours(&term, WHITE, BLACK) != 0) {*/ - /* return;*/ - /*}*/ - /**/ - /*uint8_t *pix = (uint8_t *)multiboot_get_mod_contents(1);*/ - /*char *char_dim = multiboot_get_cmdline(1);*/ - /*uint32_t dim[2] = {0};*/ - /**/ - /*char *token = strtok(char_dim, " ");*/ - /**/ - /*int idx = 0;*/ - /**/ - /*while (token) {*/ - /* dim[idx] = atoi(token);*/ - /* token = strtok(NULL, " ");*/ - /* idx++;*/ - /*}*/ - - /*if (term_put_img(&term, dim[0], dim[1], term.cursor.x, term.cursor.y,*/ - /* pix) != 0) {*/ - /* return;*/ - /*}*/ + + if (term_put_img(&term, dim[0], dim[1], term.cursor.x, term.cursor.y, + pix) != 0) { + kprintf(&term, "An error occurred while displaying the image\n"); + return; + } halt(); }