diff --git a/drivers/vga.c b/drivers/vga.c index 8821fe7..a9f1782 100644 --- a/drivers/vga.c +++ b/drivers/vga.c @@ -11,7 +11,7 @@ static uint cursor_col = 0; void vga_init() { // Allocate VGA memory range - pm_alloc_range(VGA_ADDRESS, VGA_ADDRESS_MAX, true); // force alloc the VGA range + pm_malloc_range(VGA_ADDRESS, VGA_ADDRESS_MAX, true); // force alloc the VGA range // Disable cursor port_outb(0x3d4, 0x0a); diff --git a/drivers/vga.h b/drivers/vga.h index 0ba4f1f..2a7bc20 100644 --- a/drivers/vga.h +++ b/drivers/vga.h @@ -2,7 +2,7 @@ #define VGA_ADDRESS_MAX 0xb8fa0 #define DEFAULT_COLOR 0x07 -#define URGET_COLOR 0x0c +#define URGENT_COLOR 0x0c #define SUCCESS_COLOR 0x0a #define MAX_ROWS 25 diff --git a/kernel/memory.c b/kernel/memory.c index b83b26f..3299366 100644 --- a/kernel/memory.c +++ b/kernel/memory.c @@ -55,22 +55,23 @@ void block_free(uint blockidx) { last_block = blockidx; } -uint find_free(uint block_count) { - uint lower; - uint upper; +int find_free(uint block_count) { + int lowerb = -1; // if this function returns -1 + // then it has failed. // Loop through bitmap starting at last_block - for( lower = last_block; lower < MAX_BLOCK_COUNT - block_count; lower++ ) { + for( uint lower = last_block; lower < MAX_BLOCK_COUNT - block_count; lower++ ) { bool range_is_free = true; - for( upper = 0; upper < block_count; upper++ ) { + for( uint upper = 0; upper < block_count; upper++ ) { range_is_free &= CHECK_BITMAP(bitmap, lower+upper); // perform AND on each block (if free) } if(range_is_free) // if range is free + lowerb = (int)lower; break; // then stop searching } - return lower; // return the lower block index + return lowerb; // return the lower block index } bool check_block_range(uint start, uint end) { @@ -86,7 +87,7 @@ bool check_block_range(uint start, uint end) { return allowed; } -void pm_alloc_range(ulong start, ulong end, bool force) { +void pm_malloc_range(ulong start, ulong end, bool force) { uint idx_start; uint idx_end; @@ -110,5 +111,15 @@ void pm_alloc_range(ulong start, ulong end, bool force) { } pointer pm_malloc(uint block_count) { - + // find free block range and get lower offset + int lower; + lower = find_free(block_count); + + if( lower < 0 ) + println("--! OUT OF MEMORY !--", URGENT_COLOR); + // do some out-of-memory interupt + return 0x0; + + // allocate those blocks + // return pointer to start of first block } diff --git a/kernel/memory.h b/kernel/memory.h index f6fce88..1e5a7d7 100644 --- a/kernel/memory.h +++ b/kernel/memory.h @@ -16,10 +16,10 @@ void mod_bitmap(uint bit, uint flag); pointer block_alloc(uint blockidx); // allocate a block void block_free(uint blockidx); // free a block -uint find_free(uint block_count); +int find_free(uint block_count); bool check_block_range(uint start, uint end); -void pm_alloc_range(ulong start, ulong end, bool force); // allocate a range of memory +void pm_malloc_range(ulong start, ulong end, bool force); // allocate a range of memory pointer pm_malloc(uint block_count); // allocate some blocks void pm_free(int* p); // free a var (if allocated with pm_malloc)