diff --git a/kernel/kernel.c b/kernel/kernel.c index 11d23f3..b6be80e 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -20,12 +20,7 @@ void kernel_init() { char* subtitle = "A x86 operating system, licenced under GPL-2.0"; println(subtitle, DEFAULT_COLOR); - char* e820_addr = (char*)0x9820; - uint e820_count = &e820_addr; - if ( e820_count <= 0 ) { - println(":(", DEFAULT_COLOR); - } else { - println(":D", DEFAULT_COLOR); - } - + char* mem = (char*) get_phys_mem_size(); + println(mem, DEFAULT_COLOR); + } diff --git a/kernel/memory.c b/kernel/memory.c index fdef712..045997d 100644 --- a/kernel/memory.c +++ b/kernel/memory.c @@ -22,6 +22,12 @@ static int bitmap = 0; static uint last_block; + +uint get_phys_mem_size() { + uint e820_count = (uint) *BIOS_E820; + return e820_count; +} + void mod_bitmap(uint bit, uint bflag) { // create a bitmask that will be applied to the bitmap int bitmask = 1 << bit; @@ -31,7 +37,6 @@ void mod_bitmap(uint bit, uint bflag) { bitmap = (((bitmap & ~bitmask)) | (bflag << bit)); } - pointer block_alloc(uint blockidx) { int block_bflag; block_bflag = CHECK_BITMAP(bitmap, blockidx); diff --git a/kernel/memory.h b/kernel/memory.h index 75100a6..aff184e 100644 --- a/kernel/memory.h +++ b/kernel/memory.h @@ -1,5 +1,7 @@ #include "../lib/types.h" +#define BIOS_E820 (char*)0x9820 + #define BLOCK_SIZE 1024 // 1 KiB #define MAX_BLOCK_COUNT 32 // placeholder #define MEMSIZE_TO_BLOCKS(n) ((n*1024)/BLOCK_SIZE) @@ -23,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