Multiboot Memory Map get copied to a "safe" place
This commit is contained in:
@ -5,6 +5,24 @@
|
||||
|
||||
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_NVS_MEMORY(MEM_TYPE) MEM_TYPE & 0x8
|
||||
#define IS_BADRAM_MEMORY(MEM_TYPE) MEM_TYPE & 0x10
|
||||
|
||||
struct MemoryInfoBlock {
|
||||
uint32_t Base_addr ;
|
||||
uint32_t Memory_Size;
|
||||
MemoryInfoBlock* next;
|
||||
uint8_t type;
|
||||
|
||||
};
|
||||
struct BootInfoBlock {
|
||||
bool MapIsInvalid;
|
||||
uint32_t bootDeviceID ;
|
||||
@ -21,8 +39,7 @@ struct BootInfoBlock {
|
||||
bool EnabledVBE;
|
||||
|
||||
bool PhysicalMemoryMapAvailable;
|
||||
MemoryInfoBlock* MemoryMap;
|
||||
|
||||
};
|
||||
|
||||
// Put the BootInfoBlock 1MB above the kernel.
|
||||
const uint32_t BootInfoBlock_pptr = kernel_end - 0xC0000000 + 0x1000;
|
||||
|
@ -25,6 +25,8 @@ extern "C" void testLauncher ( unsigned long magic, multiboot_info_t* mbi) {
|
||||
if (CHECK_FLAG (mbi->flags, 1))
|
||||
{
|
||||
BIB->bootDeviceID = mbi->boot_device;
|
||||
} else{
|
||||
BIB->bootDeviceID = 0x11111111;
|
||||
}
|
||||
|
||||
/* Are mods_* valid? */
|
||||
@ -36,7 +38,7 @@ extern "C" void testLauncher ( unsigned long magic, multiboot_info_t* mbi) {
|
||||
|
||||
|
||||
for(i = 0, mod = (multiboot_module_t *) mbi->mods_addr; i < mbi->mods_count; i++ , mod++){
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,29 +62,51 @@ extern "C" void testLauncher ( unsigned long magic, multiboot_info_t* mbi) {
|
||||
BIB->ValidELFHeader = false;
|
||||
}
|
||||
/*
|
||||
If we got a memory map from our bootloader we
|
||||
should be parsing it to find out the memory regions available.
|
||||
*/
|
||||
if (CHECK_FLAG(mbi->flags, 6))
|
||||
{
|
||||
If we got a memory map from our bootloader we
|
||||
should be parsing it to find out the memory regions available.
|
||||
*/
|
||||
if (CHECK_FLAG(mbi->flags, 6))
|
||||
{
|
||||
BIB->PhysicalMemoryMapAvailable = true;
|
||||
BIB->MemoryMap = (MemoryInfoBlock*) MemoryMapHeap_pptr;
|
||||
multiboot_memory_map_t *mmap = (multiboot_memory_map_t*) (mbi->mmap_addr) ;
|
||||
|
||||
for (; (unsigned long) mmap < mbi->mmap_addr + mbi->mmap_length; mmap = (multiboot_memory_map_t *) ((unsigned long) mmap + mmap->size + sizeof(mmap->size))){
|
||||
|
||||
if ( mmap->type == MULTIBOOT_MEMORY_AVAILABLE){
|
||||
|
||||
} else{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
auto MemoryMapEnd = mbi->mmap_addr + mbi->mmap_length;
|
||||
|
||||
} else{
|
||||
auto CurrentInfoBlock = BIB->MemoryMap;
|
||||
|
||||
|
||||
while((unsigned long) mmap < MemoryMapEnd){
|
||||
|
||||
CurrentInfoBlock->Base_addr = mmap->addr;
|
||||
CurrentInfoBlock->Memory_Size = mmap->len;
|
||||
|
||||
|
||||
if(mmap->type == MULTIBOOT_MEMORY_AVAILABLE)
|
||||
CurrentInfoBlock->type &= 0x1;
|
||||
if(mmap->type == MULTIBOOT_MEMORY_ACPI_RECLAIMABLE)
|
||||
CurrentInfoBlock->type &= 0x2;
|
||||
if(mmap->type == MULTIBOOT_MEMORY_RESERVED)
|
||||
CurrentInfoBlock->type &= 0x4;
|
||||
if(mmap->type == MULTIBOOT_MEMORY_NVS)
|
||||
CurrentInfoBlock->type &= 0x8;
|
||||
if(mmap->type == MULTIBOOT_MEMORY_BADRAM)
|
||||
CurrentInfoBlock->type &= 0x10;
|
||||
|
||||
|
||||
// continue to the next block
|
||||
mmap = (multiboot_memory_map_t *) ((unsigned long) mmap + mmap->size + sizeof(mmap->size));
|
||||
|
||||
CurrentInfoBlock->next = (MemoryInfoBlock*) ((uint32_t)CurrentInfoBlock) + sizeof(MemoryInfoBlock);
|
||||
CurrentInfoBlock = CurrentInfoBlock->next;
|
||||
|
||||
}
|
||||
|
||||
CurrentInfoBlock->next = (MemoryInfoBlock*) 0x0;
|
||||
|
||||
} else
|
||||
{
|
||||
BIB->PhysicalMemoryMapAvailable = false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw diagonal blue line */
|
||||
if (CHECK_FLAG (mbi->flags, 12)){
|
||||
|
Reference in New Issue
Block a user