KERNEL: Physical Page Frame allocation
Rewriting the setup to allow for physical memory allocation again to work.
This commit is contained in:
@ -2,17 +2,12 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
extern "C" const uint32_t kernel_begin;
|
||||
extern "C" const uint32_t kernel_end;
|
||||
// Put the BootInfoBlock 1MB above the kernel.
|
||||
const uint32_t BootInfoBlock_pptr = (uint32_t)&kernel_end - 0xC0000000 + 0x1;
|
||||
const uint32_t MemoryMapHeap_pptr = BootInfoBlock_pptr + 0x1;
|
||||
|
||||
|
||||
#define IS_AVAILABLE_MEM(MEM_TYPE) MEM_TYPE & 0x1
|
||||
#define IS_ACPI_MEM(MEM_TYPE) MEM_TYPE & 0x2
|
||||
#define IS_RESERVED_MEM(MEM_TYPE) MEM_TYPE & 0x3
|
||||
#define IS_RESERVED_MEM(MEM_TYPE) MEM_TYPE & 0x4
|
||||
#define IS_NVS_MEMORY(MEM_TYPE) MEM_TYPE & 0x8
|
||||
#define IS_BADRAM_MEMORY(MEM_TYPE) MEM_TYPE & 0x10
|
||||
|
||||
@ -40,6 +35,11 @@ struct BootInfoBlock {
|
||||
|
||||
bool PhysicalMemoryMapAvailable;
|
||||
MemoryInfoBlock* MemoryMap;
|
||||
uint32_t map_size;
|
||||
uint32_t MemorySize ;
|
||||
|
||||
};
|
||||
|
||||
// TODO Put the BootInfoBlock 1MB above the kernel.
|
||||
const uint32_t BootInfoBlock_pptr = (uint32_t)&kernel_end - 0xC0000000 + 0x1;
|
||||
const uint32_t MemoryMapHeap_pptr = BootInfoBlock_pptr + sizeof(BootInfoBlock);
|
||||
|
@ -5,7 +5,7 @@
|
||||
#define CHECK_FLAG(flags, bit) ((flags) & (1 <<(bit)))
|
||||
|
||||
|
||||
extern "C" void testLauncher ( unsigned long magic, multiboot_info_t* mbi) {
|
||||
extern "C" void prekernelSetup ( unsigned long magic, multiboot_info_t* mbi) {
|
||||
|
||||
// Create the bootInfoBlock at its location
|
||||
BootInfoBlock* BIB = (BootInfoBlock*) BootInfoBlock_pptr;
|
||||
@ -74,23 +74,25 @@ if (CHECK_FLAG(mbi->flags, 6))
|
||||
|
||||
auto CurrentInfoBlock = BIB->MemoryMap;
|
||||
|
||||
|
||||
while((unsigned long) mmap < MemoryMapEnd){
|
||||
uint32_t RAM_size = 0;
|
||||
|
||||
while((unsigned long) mmap < MemoryMapEnd){
|
||||
BIB->map_size += sizeof(MemoryInfoBlock);
|
||||
CurrentInfoBlock->Base_addr = mmap->addr;
|
||||
CurrentInfoBlock->Memory_Size = mmap->len;
|
||||
|
||||
|
||||
if(mmap->type == MULTIBOOT_MEMORY_AVAILABLE)
|
||||
CurrentInfoBlock->type &= 0x1;
|
||||
CurrentInfoBlock->type |= 0x1;
|
||||
RAM_size += mmap->len;
|
||||
if(mmap->type == MULTIBOOT_MEMORY_ACPI_RECLAIMABLE)
|
||||
CurrentInfoBlock->type &= 0x2;
|
||||
CurrentInfoBlock->type |= 0x2;
|
||||
if(mmap->type == MULTIBOOT_MEMORY_RESERVED)
|
||||
CurrentInfoBlock->type &= 0x4;
|
||||
CurrentInfoBlock->type |= 0x4;
|
||||
if(mmap->type == MULTIBOOT_MEMORY_NVS)
|
||||
CurrentInfoBlock->type &= 0x8;
|
||||
CurrentInfoBlock->type |= 0x8;
|
||||
if(mmap->type == MULTIBOOT_MEMORY_BADRAM)
|
||||
CurrentInfoBlock->type &= 0x10;
|
||||
CurrentInfoBlock->type |= 0x10;
|
||||
|
||||
|
||||
// continue to the next block
|
||||
@ -102,7 +104,7 @@ if (CHECK_FLAG(mbi->flags, 6))
|
||||
}
|
||||
|
||||
CurrentInfoBlock->next = (MemoryInfoBlock*) 0x0;
|
||||
|
||||
BIB->MemorySize = RAM_size;
|
||||
} else
|
||||
{
|
||||
BIB->PhysicalMemoryMapAvailable = false;
|
||||
|
Reference in New Issue
Block a user