Broken bitmap

pull/38/head
E. Almqvist 3 years ago
parent 5654680f7e
commit 1c9a865f1c
  1. 5
      kernel/kernel.c
  2. 20
      kernel/memory.c
  3. 8
      kernel/memory.h

@ -25,6 +25,11 @@ void init() {
println("0x1000", DEFAULT_COLOR);
*/
block_alloc(1);
block_alloc(1);
block_alloc(2);
block_alloc(2);
char* strbuf = "Concat test: ";
char* str2 = "Works!";
strbuf = strcat(strbuf, str2);

@ -1,4 +1,5 @@
#include "memory.h"
#include "../drivers/vga.h"
// https://wiki.osdev.org/Page_Frame_Allocation
// page = block
@ -11,9 +12,11 @@
// 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;
int bitmap = 0;
void mod_bitmap(uint block, uint bit, uint bflag) {
#define CHECK_BITMAP(map, idx) ((map) & (1<<(idx)))
void mod_bitmap(uint bit, uint bflag) {
// create a bitmask that will be applied to the bitmap
int bitmask = 1 << bit;
@ -21,3 +24,16 @@ void mod_bitmap(uint block, uint bit, uint bflag) {
// set to bflag
bitmap = (((bitmap & ~bitmask)) | (bflag << bit));
}
int block_alloc(uint blockidx) {
if( CHECK_BITMAP(bitmap, blockidx) == 1 ) { // check if block is free
println("Alloc!", DEFAULT_COLOR);
mod_bitmap(blockidx, 0);
} else {
println("ERROR! Attemped to allocate non-free block.", 0x0c);
return -1;
}
}

@ -1,10 +1,12 @@
#include "../lib/types.h"
#define BLOCK_SIZE 1024 // 1 KiB
#define MAX_BLOCK_COUNT 32 // placeholder
#define MEMSIZE_TO_BLOCKS(n) ((n*1024)/BLOCK_SIZE)
enum bitmap_flag;
// void init_pmm(uint map_addr, uint bsize); // Initialize physical memory manager
void mod_bitmap(uint block, uint bit, uint flag);
void mod_bitmap(uint bit, uint flag);
int block_alloc(uint blockidx);
int block_free(uint blockidx);

Loading…
Cancel
Save