Read stuff (e820)

rust
E. Almqvist 3 years ago
parent 46491733bf
commit c5d9350e81
  1. 11
      kernel/kernel.c
  2. 7
      kernel/memory.c
  3. 4
      kernel/memory.h

@ -20,12 +20,7 @@ void kernel_init() {
char* subtitle = "A x86 operating system, licenced under GPL-2.0"; char* subtitle = "A x86 operating system, licenced under GPL-2.0";
println(subtitle, DEFAULT_COLOR); println(subtitle, DEFAULT_COLOR);
char* e820_addr = (char*)0x9820; char* mem = (char*) get_phys_mem_size();
uint e820_count = &e820_addr; println(mem, DEFAULT_COLOR);
if ( e820_count <= 0 ) {
println(":(", DEFAULT_COLOR);
} else {
println(":D", DEFAULT_COLOR);
}
} }

@ -22,6 +22,12 @@
static int bitmap = 0; static int bitmap = 0;
static uint last_block; static uint last_block;
uint get_phys_mem_size() {
uint e820_count = (uint) *BIOS_E820;
return e820_count;
}
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;
@ -31,7 +37,6 @@ void mod_bitmap(uint bit, uint bflag) {
bitmap = (((bitmap & ~bitmask)) | (bflag << bit)); bitmap = (((bitmap & ~bitmask)) | (bflag << bit));
} }
pointer block_alloc(uint blockidx) { pointer block_alloc(uint blockidx) {
int block_bflag; int block_bflag;
block_bflag = CHECK_BITMAP(bitmap, blockidx); block_bflag = CHECK_BITMAP(bitmap, blockidx);

@ -1,5 +1,7 @@
#include "../lib/types.h" #include "../lib/types.h"
#define BIOS_E820 (char*)0x9820
#define BLOCK_SIZE 1024 // 1 KiB #define BLOCK_SIZE 1024 // 1 KiB
#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)
@ -23,3 +25,5 @@ void pm_malloc_range(ulong start, ulong end, bool force); // allocate a range of
pointer pm_malloc(uint block_count); // allocate some blocks pointer pm_malloc(uint block_count); // allocate some blocks
void pm_free(int* p); // free a var (if allocated with pm_malloc) void pm_free(int* p); // free a var (if allocated with pm_malloc)
uint get_phys_mem_size(); // physical memory size with e820 left by the bootloader

Loading…
Cancel
Save