From 9649d1a10d0ea0bb85b2e3a62a6fd3f9b682f4a3 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Fri, 15 Apr 2022 21:59:48 +0200 Subject: [PATCH] TODO and stuff --- TODO.md | 21 +++++++++++++-------- drivers/vga.c | 6 +++--- kernel/kernel.c | 9 +++++++-- kernel/kernel.h | 1 + kernel/memory.c | 6 ++++++ kernel/memory.h | 2 ++ lib/conv.c | 31 ++++++++++++++++++------------- lib/math.c | 3 +++ lib/math.h | 2 ++ 9 files changed, 55 insertions(+), 26 deletions(-) diff --git a/TODO.md b/TODO.md index a971a00..8ba1c5a 100644 --- a/TODO.md +++ b/TODO.md @@ -1,9 +1,14 @@ -# TO DO - - Multiboot (read end of memory etc) - - String interpolation - - Screen scrolling +# TO DO + - Math lib: powf, log10, numlen + - Str lib: int\_to\_str + - Read and display e820 memory mapping + - (Random lib: random num from a to b?) + - Shell: input, execute -## Long term - - Get rust lang to work/switch to rust - - Shell? - - Improve memory management + - prog/time: show time + - prog/date: show date + - prog/mem: show amount of memory + - prog/bitmap: show phys bitmap + +# Long term + - Rust? diff --git a/drivers/vga.c b/drivers/vga.c index e45c91f..1838020 100644 --- a/drivers/vga.c +++ b/drivers/vga.c @@ -11,14 +11,14 @@ static uint cursor_col = 0; void vga_init() { // Disable cursor - port_outb(0x3d4, 0x0a); - port_outb(0x3d5, 0x20); + // port_outb(0x3d4, 0x0a); + // port_outb(0x3d5, 0x20); // Clear screen // clear_row(0); // clear_screen(); - set_cursor_pos(0, 0); + //set_cursor_pos(0, 0); } /* diff --git a/kernel/kernel.c b/kernel/kernel.c index 4f86a34..e601d7b 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -23,9 +23,14 @@ void kernel_init() { // Allocate VGA memory range pm_malloc_range(VGA_ADDRESS, VGA_ADDRESS_MAX, true); // force alloc the VGA range - // ENABLE PAGING // TODO: make this work // enable_paging(); - + + set_cursor_pos(0, 8); + print("E820 loaded entries: ", DEFAULT_COLOR); + uint entries = get_phys_mem_size(); + char* buf; + buf = int_to_str(entries, buf); + println(buf, DEFAULT_COLOR); } diff --git a/kernel/kernel.h b/kernel/kernel.h index bb40f83..43b2568 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -6,4 +6,5 @@ #define BANNER_COLOR 0x0f +void kernel_motd(); void kernel_init(); diff --git a/kernel/memory.c b/kernel/memory.c index f59362e..2147132 100644 --- a/kernel/memory.c +++ b/kernel/memory.c @@ -23,6 +23,12 @@ static int bitmap = 0; static uint last_block; +uint get_phys_mem_size() { + // TODO: read actual mappings + uint entry_count = (uint) *BIOS_E820; + return entry_count; +} + void mod_bitmap(uint bit, uint bflag) { // create a bitmask that will be applied to the bitmap int bitmask = 1 << bit; diff --git a/kernel/memory.h b/kernel/memory.h index d35cd0a..aff184e 100644 --- a/kernel/memory.h +++ b/kernel/memory.h @@ -25,3 +25,5 @@ void pm_malloc_range(ulong start, ulong end, bool force); // allocate a range of pointer pm_malloc(uint block_count); // allocate some blocks void pm_free(int* p); // free a var (if allocated with pm_malloc) + +uint get_phys_mem_size(); // physical memory size with e820 left by the bootloader diff --git a/lib/conv.c b/lib/conv.c index 8b5d82d..0fc918a 100644 --- a/lib/conv.c +++ b/lib/conv.c @@ -1,18 +1,23 @@ #include "conv.h" #include "../drivers/vga.h" -char* int_to_str(int i, char* buf) { - ulong num = (ulong)i; // convert to ulong - uint len = ulong_len(num); // number of digits - - *(buf+len) = '\0'; // add a "end-of-string" at the end +// char* int_to_str(int i, char* buf) { +// ulong num = (ulong)i; // convert to ulong +// uint len = ulong_len(num); // number of digits +// +// *(buf+len) = '\0'; // add a "end-of-string" at the end +// +// int j; +// for(j = 0; j < len; j++) { // iterate over each digit and assign it to the buffer +// // super dangerous memory write +// *(buf+j) = (char)(ndigit(num, len-1-j) + ASCII_OFFSET); // apply the ascii offset so that i becomes a char +// println(*(buf+j), 0xc0); +// } +// +// return buf; +// } - int j; - for(j = 0; j < len; j++) { // iterate over each digit and assign it to the buffer - // super dangerous memory write - *(buf+j) = (char)(ndigit(num, len-1-j) + ASCII_OFFSET); // apply the ascii offset so that i becomes a char - println(*(buf+j), 0xc0); - } - - return buf; +char* int_to_str(int i, char* buf) { + char* sign = (i < 0) ? "-" : "+"; + return (char*) sign; } diff --git a/lib/math.c b/lib/math.c index 58c09f4..b153a01 100644 --- a/lib/math.c +++ b/lib/math.c @@ -17,3 +17,6 @@ long square(uint num) { } return sum + 1; } + + +float powf(float n) {} diff --git a/lib/math.h b/lib/math.h index d5ee07a..c80ab75 100644 --- a/lib/math.h +++ b/lib/math.h @@ -2,3 +2,5 @@ long pow(int, uint); long square(uint); + +float powf(float);