2022-08-22 19:16:34 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include "multiboot.h"
|
|
|
|
#include "bootstructure.h"
|
|
|
|
#define CHECK_FLAG(flags, bit) ((flags) & (1 <<(bit)))
|
|
|
|
|
|
|
|
|
2022-09-01 14:11:35 +00:00
|
|
|
extern "C" void prekernelSetup ( unsigned long magic, multiboot_info_t* mbi) {
|
2022-08-22 19:16:34 +00:00
|
|
|
|
|
|
|
// Create the bootInfoBlock at its location
|
|
|
|
BootInfoBlock* BIB = (BootInfoBlock*) BootInfoBlock_pptr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check Multiboot magic number
|
|
|
|
*/
|
|
|
|
if (magic != MULTIBOOT_BOOTLOADER_MAGIC)
|
|
|
|
{
|
|
|
|
BIB->MapIsInvalid = true;
|
|
|
|
return;
|
|
|
|
} else{
|
|
|
|
BIB->MapIsInvalid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* is boot device valid ? */
|
|
|
|
if (CHECK_FLAG (mbi->flags, 1))
|
|
|
|
{
|
|
|
|
BIB->bootDeviceID = mbi->boot_device;
|
2022-08-23 19:35:19 +00:00
|
|
|
} else{
|
|
|
|
BIB->bootDeviceID = 0x11111111;
|
2022-08-22 19:16:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Are mods_* valid? */
|
|
|
|
if(CHECK_FLAG ( mbi->flags, 3)){
|
|
|
|
multiboot_module_t *mod;
|
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
BIB->GrubModuleCount = mbi->mods_count;
|
|
|
|
|
|
|
|
|
|
|
|
for(i = 0, mod = (multiboot_module_t *) mbi->mods_addr; i < mbi->mods_count; i++ , mod++){
|
2022-08-23 19:35:19 +00:00
|
|
|
|
2022-08-22 19:16:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is the symbol table of a.out valid? */
|
|
|
|
if (CHECK_FLAG(mbi->flags, 4))
|
|
|
|
{
|
|
|
|
BIB->ValidSymbolTable = true;
|
|
|
|
multiboot_aout_symbol_table_t *multiboot_aout_sym = &(mbi->u.aout_sym);
|
|
|
|
|
|
|
|
} else{
|
|
|
|
BIB->ValidSymbolTable = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is the section header table of ELF valid? */
|
|
|
|
if (CHECK_FLAG(mbi->flags, 5))
|
|
|
|
{
|
|
|
|
BIB->ValidELFHeader = true;
|
|
|
|
multiboot_elf_section_header_table_t *multiboot_elf_sec = &(mbi->u.elf_sec);
|
|
|
|
|
|
|
|
}else{
|
|
|
|
BIB->ValidELFHeader = false;
|
|
|
|
}
|
|
|
|
/*
|
2022-08-23 19:35:19 +00:00
|
|
|
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))
|
|
|
|
{
|
2022-08-22 19:16:34 +00:00
|
|
|
BIB->PhysicalMemoryMapAvailable = true;
|
2022-08-23 19:35:19 +00:00
|
|
|
BIB->MemoryMap = (MemoryInfoBlock*) MemoryMapHeap_pptr;
|
2022-08-22 19:16:34 +00:00
|
|
|
multiboot_memory_map_t *mmap = (multiboot_memory_map_t*) (mbi->mmap_addr) ;
|
2022-08-23 19:35:19 +00:00
|
|
|
auto MemoryMapEnd = mbi->mmap_addr + mbi->mmap_length;
|
|
|
|
|
|
|
|
auto CurrentInfoBlock = BIB->MemoryMap;
|
|
|
|
|
2022-09-01 14:11:35 +00:00
|
|
|
uint32_t RAM_size = 0;
|
2022-08-23 19:35:19 +00:00
|
|
|
|
2022-09-01 14:11:35 +00:00
|
|
|
while((unsigned long) mmap < MemoryMapEnd){
|
|
|
|
BIB->map_size += sizeof(MemoryInfoBlock);
|
2022-08-23 19:35:19 +00:00
|
|
|
CurrentInfoBlock->Base_addr = mmap->addr;
|
|
|
|
CurrentInfoBlock->Memory_Size = mmap->len;
|
|
|
|
|
|
|
|
|
|
|
|
if(mmap->type == MULTIBOOT_MEMORY_AVAILABLE)
|
2022-09-01 14:11:35 +00:00
|
|
|
CurrentInfoBlock->type |= 0x1;
|
|
|
|
RAM_size += mmap->len;
|
2022-08-23 19:35:19 +00:00
|
|
|
if(mmap->type == MULTIBOOT_MEMORY_ACPI_RECLAIMABLE)
|
2022-09-01 14:11:35 +00:00
|
|
|
CurrentInfoBlock->type |= 0x2;
|
2022-08-23 19:35:19 +00:00
|
|
|
if(mmap->type == MULTIBOOT_MEMORY_RESERVED)
|
2022-09-01 14:11:35 +00:00
|
|
|
CurrentInfoBlock->type |= 0x4;
|
2022-08-23 19:35:19 +00:00
|
|
|
if(mmap->type == MULTIBOOT_MEMORY_NVS)
|
2022-09-01 14:11:35 +00:00
|
|
|
CurrentInfoBlock->type |= 0x8;
|
2022-08-23 19:35:19 +00:00
|
|
|
if(mmap->type == MULTIBOOT_MEMORY_BADRAM)
|
2022-09-01 14:11:35 +00:00
|
|
|
CurrentInfoBlock->type |= 0x10;
|
2022-08-23 19:35:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
// 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;
|
2022-09-01 14:11:35 +00:00
|
|
|
BIB->MemorySize = RAM_size;
|
2022-08-23 19:35:19 +00:00
|
|
|
} else
|
|
|
|
{
|
2022-08-22 19:16:34 +00:00
|
|
|
BIB->PhysicalMemoryMapAvailable = false;
|
2022-08-23 19:35:19 +00:00
|
|
|
}
|
2022-08-22 19:16:34 +00:00
|
|
|
|
|
|
|
/* Draw diagonal blue line */
|
|
|
|
if (CHECK_FLAG (mbi->flags, 12)){
|
|
|
|
BIB->EnabledVBE = true;
|
|
|
|
} else{
|
|
|
|
BIB->EnabledVBE;
|
|
|
|
}
|
|
|
|
}
|