From 4dc79c4ee6d59bdef01b1f7f38eb176b3813d209 Mon Sep 17 00:00:00 2001 From: Braiden Vasco Date: Sun, 5 Nov 2017 07:32:32 +0000 Subject: [PATCH] Do not allocate in lower memory --- arch/config.h | 2 ++ arch/memory.c | 5 ++++- arch/paging.c | 2 -- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/config.h b/arch/config.h index 2080693..21e1568 100644 --- a/arch/config.h +++ b/arch/config.h @@ -1,6 +1,8 @@ #ifndef KERNELMQ_INCLUDED_CONFIG #define KERNELMQ_INCLUDED_CONFIG 1 +#define MEM_UPPER_BASE ((unsigned long)(1 * 1024 * 1024 * 1024)) // 1 MB + #define PAGE_DIR_SIZE 1024 #define PAGE_TABLE_SIZE 1024 diff --git a/arch/memory.c b/arch/memory.c index 1012d1e..e655464 100644 --- a/arch/memory.c +++ b/arch/memory.c @@ -14,6 +14,8 @@ void memory_initialize(const struct KernelMQ_Info *const kinfo) { kmemset(frames, 0, sizeof(frames)); + mark_used(0, MEM_UPPER_BASE - 1); + mark_used(kinfo->kernel_phys_base, kinfo->kernel_phys_limit); for (unsigned int i = 0; i < kinfo->modules_count; ++i) { @@ -35,6 +37,7 @@ unsigned long memory_alloc_page() { for (unsigned int i = 0; i < FRAMES_COUNT; ++i) { if (!frames[i]) { + frames[i] = 0xFF; return i * PAGE_SIZE; } } @@ -48,6 +51,6 @@ void mark_used(const unsigned long base, const unsigned long limit) const unsigned int end = limit / PAGE_SIZE; for (unsigned int i = start; i <= end; ++i) { - frames[i] = 1; + frames[i] = 0xFF; } } diff --git a/arch/paging.c b/arch/paging.c index 5ba2ad8..acf0a2f 100644 --- a/arch/paging.c +++ b/arch/paging.c @@ -4,8 +4,6 @@ #include -#define MEM_UPPER_BASE ((unsigned long)(1 * 1024 * 1024 * 1024)) // 1 MB - // i386 paging constants #define I386_VM_PRESENT 0x001 // Page is present #define I386_VM_WRITE 0x002 // Read/write access allowed