From 95e2f274e3720391cad13db477d5ad4cec4c8fe3 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Fri, 3 Dec 2021 09:44:52 +0100 Subject: [PATCH] Bitmap thing --- Makefile | 2 +- kernel/memory.c | 14 ++++++++++++-- kernel/memory.h | 9 +++++++-- kernel/sr_memory.asm | 0 lib/types.h | 1 + 5 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 kernel/sr_memory.asm create mode 100644 lib/types.h diff --git a/Makefile b/Makefile index f5935b7..bece67e 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ eos_grub.iso : kernel.bin grub/grub.cfg eos.iso: bootloader/bootloader.bin kernel.bin cat $^ > eos.iso -kernel.bin: kernel/kernel_entry.o kernel/enable_paging.o $(OBJ) +kernel.bin: kernel/kernel_entry.o kernel/sr_memory.o kernel/enable_paging.o $(OBJ) gcc -o $@ $^ -Wl,--oformat=binary -ffreestanding -nostdlib -shared -Ttext 0x1000 -m32 diff --git a/kernel/memory.c b/kernel/memory.c index bb577e4..236e93e 100644 --- a/kernel/memory.c +++ b/kernel/memory.c @@ -7,8 +7,18 @@ // i.e. : bit i of byte n define status of block 8n+i // block = 8n+i -int* alloc_cursor; // keep track of last location that was allocated (may improve speed) +// in 32-bit mode, we have access to 2^32 blocks +// 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 -void init_pmm(unsigned int map_addr, unsigned int bsize) { +int bitmap = 0; +enum bitmap_flag { + FREE, + ALLOC +}; + +void mod_bitmap(uint block, uint bit, uint bflag) { + } diff --git a/kernel/memory.h b/kernel/memory.h index 5d46f0b..93cfa77 100644 --- a/kernel/memory.h +++ b/kernel/memory.h @@ -1,5 +1,10 @@ -#define BLOCK_SIZE 4 // 32 bits = 4 bytes +#include "../lib/types.h" + +#define BLOCK_SIZE 1024 // 1 KiB #define MEMSIZE_TO_BLOCKS(n) ((n*1024)/BLOCK_SIZE) -void init_pmm(unsigned int map_addr, unsigned int bsize); // Initialize physical memory manager +enum bitmap_flag; + +// void init_pmm(uint map_addr, uint bsize); // Initialize physical memory manager +void mod_bitmap(uint block, uint bit, uint flag); diff --git a/kernel/sr_memory.asm b/kernel/sr_memory.asm new file mode 100644 index 0000000..e69de29 diff --git a/lib/types.h b/lib/types.h new file mode 100644 index 0000000..9113551 --- /dev/null +++ b/lib/types.h @@ -0,0 +1 @@ +typedef unsigned int uint;