Debug & more stuff

pull/38/head
E. Almqvist 3 years ago
parent b7b9c9e975
commit 684785a49d
  1. 13
      kernel/kernel.c
  2. 14
      kernel/memory.c

@ -25,10 +25,15 @@ void init() {
println("0x1000", DEFAULT_COLOR);
*/
block_alloc(1);
block_alloc(1);
block_alloc(2);
block_alloc(2);
// Memory allocation testing
println("THESE ALLOC SHOULD WORK:", 0xa0);
for(int i=0; i < 4; i++) {
block_alloc(i);
}
println("(2) THIS ALLOC SHOULD FAIL:", 0xc0);
block_alloc(2); // this should fail
char* strbuf = "Concat test: ";
char* str2 = "Works!";

@ -12,29 +12,33 @@
// which is (2^32)*BLOCK_SIZE blocks
// and with a blocksize of 1024, we git around 4.3 trillion blocks
// which is more than enough
int bitmap = 0;
#define CHECK_BITMAP(map, idx) ((map) & (1<<(idx)))
int bitmap = 0;
void mod_bitmap(uint bit, uint bflag) {
// create a bitmask that will be applied to the bitmap
int bitmask = 1 << bit;
// apply the bitmask, resulting in the bit:n bit will bet
// apply the bitmask, resulting in the bit:n bit will set
// set to bflag
bitmap = (((bitmap & ~bitmask)) | (bflag << bit));
}
int block_alloc(uint blockidx) {
if( CHECK_BITMAP(bitmap, blockidx) == 1 ) { // check if block is free
int block_bflag;
block_bflag = CHECK_BITMAP(bitmap, blockidx);
if( block_bflag != 1 ) { // check if block is free
println("Alloc!", DEFAULT_COLOR);
println(block_bflag, 0x8e);
mod_bitmap(blockidx, 0);
mod_bitmap(blockidx, 1);
return 0; // placeholder
} else {
println("ERROR! Attemped to allocate non-free block.", 0x0c);
println(block_bflag, 0x9c);
return -1;
}
}

Loading…
Cancel
Save