diff --git a/drivers/vga.c b/drivers/vga.c index 889c3bc..066c3b5 100644 --- a/drivers/vga.c +++ b/drivers/vga.c @@ -1,6 +1,7 @@ // VGA Graphics Library #include "vga.h" #include "../kernel/io.h" +#include "../kernel/memory.h" #include "../lib/str.h" #include "../lib/strf.h" @@ -17,6 +18,9 @@ void vga_init() { clear_screen(); set_cursor_pos(0, 0); + + // TODO: allocate VGA physical memory + // pm_mem_alloc(VGA_ADDRESS, VGA_ADDRESS_MAX); } /* diff --git a/kernel/kernel.c b/kernel/kernel.c index fb2ae98..b979f15 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -36,7 +36,7 @@ void init() { block_alloc(2); // this should fail println("(2) Freeing 2nd block, alloc after should succeed", DEFAULT_COLOR); - block_free(2); + block_free(2); // after this, allocation of 2nd block should work block_alloc(2); char* strbuf = "Concat test: "; diff --git a/kernel/memory.c b/kernel/memory.c index 752137e..ad6744c 100644 --- a/kernel/memory.c +++ b/kernel/memory.c @@ -15,9 +15,11 @@ #define CHECK_BITMAP(map, idx) ((map) & (1<<(idx))) -#define BM_FREE 0 +#define BLOCK_TO_MEMP(idx) idx + static int bitmap = 0; +static uint last_block; void mod_bitmap(uint bit, uint bflag) { // create a bitmask that will be applied to the bitmap int bitmask = 1 << bit; @@ -28,7 +30,7 @@ void mod_bitmap(uint bit, uint bflag) { } -int block_alloc(uint blockidx) { +int* block_alloc(uint blockidx) { int block_bflag; block_bflag = CHECK_BITMAP(bitmap, blockidx); @@ -36,6 +38,8 @@ int block_alloc(uint blockidx) { println("Alloc!", DEFAULT_COLOR); mod_bitmap(blockidx, 1); + last_block = blockidx; + return 0; // placeholder } else { println("ERROR! Attemped to allocate non-free block.", 0x0c); @@ -47,4 +51,11 @@ int block_alloc(uint blockidx) { void block_free(uint blockidx) { println("Dealloc block...", DEFAULT_COLOR); mod_bitmap(blockidx, BM_FREE); + last_block = blockidx; +} + +/* +int* pm_malloc(uint block_count) { + } +*/ diff --git a/kernel/memory.h b/kernel/memory.h index c4304f4..156de0a 100644 --- a/kernel/memory.h +++ b/kernel/memory.h @@ -4,9 +4,19 @@ #define MAX_BLOCK_COUNT 32 // placeholder #define MEMSIZE_TO_BLOCKS(n) ((n*1024)/BLOCK_SIZE) +#define BM_FREE 0 + +#define PM_MEM_START 0x000000 // start of memory +#define PM_MEM_END 0xb7000 // end of memory TODO: fix me/change or something + // void init_pmm(uint map_addr, uint bsize); // Initialize physical memory manager void mod_bitmap(uint bit, uint flag); -int block_alloc(uint blockidx); -void block_free(uint blockidx); +int* block_alloc(uint blockidx); // allocate a block +void block_free(uint blockidx); // free a block + +void pm_alloc_range(uint start, uint end, bool force); // allocate a range of memory + +int* pm_malloc(uint block_count); // allocate some blocks +void pm_free(int* p); // free a var (if allocated with pm_malloc)