Minor refactor & spelling fix

multiboot
E. Almqvist 3 years ago
parent 08fc2a739f
commit 0dcf0c3fa7
  1. 2
      drivers/vga.c
  2. 2
      drivers/vga.h
  3. 25
      kernel/memory.c
  4. 4
      kernel/memory.h

@ -11,7 +11,7 @@ static uint cursor_col = 0;
void vga_init() { void vga_init() {
// Allocate VGA memory range // 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 // Disable cursor
port_outb(0x3d4, 0x0a); port_outb(0x3d4, 0x0a);

@ -2,7 +2,7 @@
#define VGA_ADDRESS_MAX 0xb8fa0 #define VGA_ADDRESS_MAX 0xb8fa0
#define DEFAULT_COLOR 0x07 #define DEFAULT_COLOR 0x07
#define URGET_COLOR 0x0c #define URGENT_COLOR 0x0c
#define SUCCESS_COLOR 0x0a #define SUCCESS_COLOR 0x0a
#define MAX_ROWS 25 #define MAX_ROWS 25

@ -55,22 +55,23 @@ void block_free(uint blockidx) {
last_block = blockidx; last_block = blockidx;
} }
uint find_free(uint block_count) { int find_free(uint block_count) {
uint lower; int lowerb = -1; // if this function returns -1
uint upper; // then it has failed.
// Loop through bitmap starting at last_block // 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; 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) range_is_free &= CHECK_BITMAP(bitmap, lower+upper); // perform AND on each block (if free)
} }
if(range_is_free) // if range is free if(range_is_free) // if range is free
lowerb = (int)lower;
break; // then stop searching 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) { bool check_block_range(uint start, uint end) {
@ -86,7 +87,7 @@ bool check_block_range(uint start, uint end) {
return allowed; 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_start;
uint idx_end; uint idx_end;
@ -110,5 +111,15 @@ void pm_alloc_range(ulong start, ulong end, bool force) {
} }
pointer pm_malloc(uint block_count) { 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
} }

@ -16,10 +16,10 @@ void mod_bitmap(uint bit, uint flag);
pointer block_alloc(uint blockidx); // allocate a block pointer block_alloc(uint blockidx); // allocate a block
void block_free(uint blockidx); // free 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); 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 pointer pm_malloc(uint block_count); // allocate some blocks
void pm_free(int* p); // free a var (if allocated with pm_malloc) void pm_free(int* p); // free a var (if allocated with pm_malloc)

Loading…
Cancel
Save