Alloc testing

pull/38/head
E. Almqvist 3 years ago
parent c169f3ba86
commit 7159073627
  1. 4
      kernel/kernel.c
  2. 11
      kernel/memory.c
  3. 2
      kernel/memory.h

@ -35,6 +35,10 @@ void init() {
println("(2) THIS ALLOC SHOULD FAIL:", 0xc0);
block_alloc(2); // this should fail
println("(2) Freeing 2nd block, alloc after should succeed", DEFAULT_COLOR);
block_free(2);
block_alloc(2);
char* strbuf = "Concat test: ";
char* str2 = "Works!";
strbuf = strcat(strbuf, str2);

@ -15,6 +15,8 @@
#define CHECK_BITMAP(map, idx) ((map) & (1<<(idx)))
#define BM_FREE 0
static int bitmap = 0;
void mod_bitmap(uint bit, uint bflag) {
// create a bitmask that will be applied to the bitmap
@ -30,16 +32,19 @@ int block_alloc(uint blockidx) {
int block_bflag;
block_bflag = CHECK_BITMAP(bitmap, blockidx);
if( block_bflag == 0 ) { // check if block is free
if( block_bflag == BM_FREE ) { // check if block is free
println("Alloc!", DEFAULT_COLOR);
println(block_bflag, 0x8e);
mod_bitmap(blockidx, 1);
return 0; // placeholder
} else {
println("ERROR! Attemped to allocate non-free block.", 0x0c);
printint(block_bflag, 0x9c);
return -1;
}
}
void block_free(uint blockidx) {
println("Dealloc block...", DEFAULT_COLOR);
mod_bitmap(blockidx, BM_FREE);
}

@ -9,4 +9,4 @@
void mod_bitmap(uint bit, uint flag);
int block_alloc(uint blockidx);
int block_free(uint blockidx);
void block_free(uint blockidx);

Loading…
Cancel
Save