Alloc stuff

pull/38/head
E. Almqvist 3 years ago
parent 7159073627
commit 9a564b7278
  1. 4
      drivers/vga.c
  2. 2
      kernel/kernel.c
  3. 15
      kernel/memory.c
  4. 14
      kernel/memory.h

@ -1,6 +1,7 @@
// VGA Graphics Library // VGA Graphics Library
#include "vga.h" #include "vga.h"
#include "../kernel/io.h" #include "../kernel/io.h"
#include "../kernel/memory.h"
#include "../lib/str.h" #include "../lib/str.h"
#include "../lib/strf.h" #include "../lib/strf.h"
@ -17,6 +18,9 @@ void vga_init() {
clear_screen(); clear_screen();
set_cursor_pos(0, 0); set_cursor_pos(0, 0);
// TODO: allocate VGA physical memory
// pm_mem_alloc(VGA_ADDRESS, VGA_ADDRESS_MAX);
} }
/* /*

@ -36,7 +36,7 @@ void init() {
block_alloc(2); // this should fail block_alloc(2); // this should fail
println("(2) Freeing 2nd block, alloc after should succeed", DEFAULT_COLOR); println("(2) Freeing 2nd block, alloc after should succeed", DEFAULT_COLOR);
block_free(2); block_free(2); // after this, allocation of 2nd block should work
block_alloc(2); block_alloc(2);
char* strbuf = "Concat test: "; char* strbuf = "Concat test: ";

@ -15,9 +15,11 @@
#define CHECK_BITMAP(map, idx) ((map) & (1<<(idx))) #define CHECK_BITMAP(map, idx) ((map) & (1<<(idx)))
#define BM_FREE 0 #define BLOCK_TO_MEMP(idx) idx
static int bitmap = 0; static int bitmap = 0;
static uint last_block;
void mod_bitmap(uint bit, uint bflag) { void mod_bitmap(uint bit, uint bflag) {
// create a bitmask that will be applied to the bitmap // create a bitmask that will be applied to the bitmap
int bitmask = 1 << bit; int bitmask = 1 << bit;
@ -28,7 +30,7 @@ void mod_bitmap(uint bit, uint bflag) {
} }
int block_alloc(uint blockidx) { int* block_alloc(uint blockidx) {
int block_bflag; int block_bflag;
block_bflag = CHECK_BITMAP(bitmap, blockidx); block_bflag = CHECK_BITMAP(bitmap, blockidx);
@ -36,6 +38,8 @@ int block_alloc(uint blockidx) {
println("Alloc!", DEFAULT_COLOR); println("Alloc!", DEFAULT_COLOR);
mod_bitmap(blockidx, 1); mod_bitmap(blockidx, 1);
last_block = blockidx;
return 0; // placeholder return 0; // placeholder
} else { } else {
println("ERROR! Attemped to allocate non-free block.", 0x0c); println("ERROR! Attemped to allocate non-free block.", 0x0c);
@ -47,4 +51,11 @@ int block_alloc(uint blockidx) {
void block_free(uint blockidx) { void block_free(uint blockidx) {
println("Dealloc block...", DEFAULT_COLOR); println("Dealloc block...", DEFAULT_COLOR);
mod_bitmap(blockidx, BM_FREE); mod_bitmap(blockidx, BM_FREE);
last_block = blockidx;
}
/*
int* pm_malloc(uint block_count) {
} }
*/

@ -4,9 +4,19 @@
#define MAX_BLOCK_COUNT 32 // placeholder #define MAX_BLOCK_COUNT 32 // placeholder
#define MEMSIZE_TO_BLOCKS(n) ((n*1024)/BLOCK_SIZE) #define MEMSIZE_TO_BLOCKS(n) ((n*1024)/BLOCK_SIZE)
#define BM_FREE 0
#define PM_MEM_START 0x000000 // start of memory
#define PM_MEM_END 0xb7000 // end of memory TODO: fix me/change or something
// void init_pmm(uint map_addr, uint bsize); // Initialize physical memory manager // void init_pmm(uint map_addr, uint bsize); // Initialize physical memory manager
void mod_bitmap(uint bit, uint flag); void mod_bitmap(uint bit, uint flag);
int block_alloc(uint blockidx); int* block_alloc(uint blockidx); // allocate a block
void block_free(uint blockidx); void block_free(uint blockidx); // free a block
void pm_alloc_range(uint start, uint end, bool force); // allocate a range of memory
int* pm_malloc(uint block_count); // allocate some blocks
void pm_free(int* p); // free a var (if allocated with pm_malloc)

Loading…
Cancel
Save