|
|
|
@ -55,16 +55,26 @@ void block_free(uint blockidx) { |
|
|
|
|
last_block = blockidx; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool check_block_range(uint start, uint end) { |
|
|
|
|
bool allowed = true;
|
|
|
|
|
|
|
|
|
|
uint idx; |
|
|
|
|
for(idx = start; idx <= end; idx++) { |
|
|
|
|
if( CHECK_BITMAP(bitmap, idx) != BM_FREE ) |
|
|
|
|
allowed = false; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return allowed; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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( uint lower = last_block; lower < MAX_BLOCK_COUNT - block_count; lower++ ) { |
|
|
|
|
bool range_is_free = true; |
|
|
|
|
for( uint upper = 0; upper < block_count; upper++ ) { |
|
|
|
|
range_is_free &= CHECK_BITMAP(bitmap, lower+upper); // perform AND on each block (if free)
|
|
|
|
|
} |
|
|
|
|
bool range_is_free = check_block_range(lower, lower + block_count - 1); |
|
|
|
|
|
|
|
|
|
if(range_is_free) // if range is free
|
|
|
|
|
lowerb = (int)lower; |
|
|
|
@ -74,19 +84,6 @@ int find_free(uint block_count) { |
|
|
|
|
return lowerb; // return the lower block index
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool check_block_range(uint start, uint end) { |
|
|
|
|
bool allowed = true;
|
|
|
|
|
|
|
|
|
|
uint idx; |
|
|
|
|
for(idx = start; idx <= end; idx++) { |
|
|
|
|
if( CHECK_BITMAP(bitmap, idx) != BM_FREE ) |
|
|
|
|
allowed = false; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return allowed; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void pm_malloc_range(ulong start, ulong end, bool force) { |
|
|
|
|
uint idx_start; |
|
|
|
|
uint idx_end; |
|
|
|
@ -105,7 +102,7 @@ void pm_malloc_range(ulong start, ulong end, bool force) { |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
} else { |
|
|
|
|
println("[ERROR] Tried to allocate memory range without permission!", 0x0c); |
|
|
|
|
println("[ERROR] Tried to allocate memory range without permission!", URGENT_COLOR); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -121,5 +118,10 @@ pointer pm_malloc(uint block_count) { |
|
|
|
|
return 0x0; |
|
|
|
|
|
|
|
|
|
// allocate those blocks
|
|
|
|
|
uint i; |
|
|
|
|
for( i = lower; i <= lower + block_count - 1; i++ ) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// return pointer to start of first block
|
|
|
|
|
} |
|
|
|
|