Divided the kernel into seperate distinct phases
The first stage after GRUB will be Pre-Kernel. This stage will organize the information we receive from the bootloader. (in our case that will be grub) The second stage is for now called early_main. The program will at this point already be running in virtual higher-half / higher-quarter address space. The goal of the second stage is to set up the kernel in such a way that we are ready to jump in to usermode. The third stage is for now called kernel_main. This stage will jump us into usermode and load the startup programs. - Added a GRUB entry for tests - Started writing the pre-kernel stage - Removed knowledge of multiboot from early_main - Edited the linkerscript to link variables in pre-kernel to lower address space. ( from 1MB and up)
This commit is contained in:
@ -1,15 +1,13 @@
|
||||
#include "kernel.h"
|
||||
|
||||
extern "C" void early_main(unsigned long magic, unsigned long addr){
|
||||
|
||||
// Convert MBI address to higher quarter kernel space
|
||||
addr += KERNEL_BASE_ADDR;
|
||||
/**
|
||||
extern "C" void early_main()
|
||||
{
|
||||
/*
|
||||
* Initialize terminal interface
|
||||
* NOTE: This should be done later on , the magic value should be checked first.
|
||||
*/
|
||||
initGDT();
|
||||
|
||||
kterm_init();
|
||||
|
||||
init_serial();
|
||||
print_serial("Hello Higher half kernel!\n");
|
||||
|
||||
@ -17,110 +15,38 @@ extern "C" void early_main(unsigned long magic, unsigned long addr){
|
||||
// Enable interrupts
|
||||
asm volatile("STI");
|
||||
|
||||
|
||||
printf("DEBUG:\n Magic: 0x%x\n MBT_addr: 0x%x\n", magic, addr);
|
||||
/**
|
||||
* Check Multiboot magic number
|
||||
* NOTE: Printf call should not be a thing this early on ...
|
||||
*/
|
||||
if (magic != MULTIBOOT_BOOTLOADER_MAGIC){
|
||||
printf("Invalid magic number: 0x%x\n", magic);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
/*
|
||||
* Show a little banner for cuteness
|
||||
*/
|
||||
printf("|=== BarinkOS ===|\n");
|
||||
/**
|
||||
* Use the address given as an argument as the pointer
|
||||
* to a Multiboot information structure.
|
||||
*/
|
||||
multiboot_info_t* mbt = (multiboot_info_t*) (addr );
|
||||
|
||||
/**
|
||||
* Construct our own bootInfo structure
|
||||
*/
|
||||
BootInfo bootinfo = {};
|
||||
|
||||
|
||||
/*
|
||||
If we got a memory map from our bootloader we
|
||||
should be parsing it to find out the memory regions available.
|
||||
*/
|
||||
if (CHECK_FLAG(mbt->flags, 6))
|
||||
{
|
||||
|
||||
/*
|
||||
Setup Physical memory managment
|
||||
*/
|
||||
MemoryInfo meminfo = {};
|
||||
bootinfo.memory = &meminfo;
|
||||
|
||||
///mapMultibootMemoryMap(bootinfo.memory , mbt);
|
||||
printf("Memory size: 0x%x bytes\n", bootinfo.memory->TotalMemory );
|
||||
BootInfoBlock* BootInfo = (BootInfoBlock*) ( BootInfoBlock_pptr + 0xC0000000 );
|
||||
|
||||
/*
|
||||
PhysicalMemory memAlloc = PhysicalMemory{};
|
||||
memAlloc.setup(bootinfo.memory );
|
||||
*/
|
||||
printf("Bootloader information:\n");
|
||||
if( BootInfo->ValidELFHeader )
|
||||
{
|
||||
printf("- Valid ELF Header is available!\n");
|
||||
}
|
||||
|
||||
// TODO: FIX physical allocator
|
||||
/*
|
||||
Mark already in use sections
|
||||
*/
|
||||
|
||||
// Mark kernel memory as used
|
||||
printf("Kernel Begin Pointer: 0x%x, Kernel end pointer: 0x%x\n", &kernel_begin , &kernel_end );
|
||||
|
||||
|
||||
multiboot_memory_map_t *mmap = (multiboot_memory_map_t*) (mbt->mmap_addr + KERNEL_BASE_ADDR) ;
|
||||
if(BootInfo->EnabledVBE)
|
||||
{
|
||||
printf("- VBE graphics mode is available!\n");
|
||||
}
|
||||
|
||||
for (; (unsigned long) mmap < mbt->mmap_addr + mbt->mmap_length; mmap = (multiboot_memory_map_t *) ((unsigned long) mmap + mmap->size + sizeof(mmap->size))){
|
||||
if(BootInfo->ValidSymbolTable)
|
||||
{
|
||||
printf("- Valid Symbol Table available at 0x%x.\n Tab Size: %d, str Size: %d\n", BootInfo->SymbolTableAddr, BootInfo->SymbolTabSize, BootInfo->SymbolStrSize);
|
||||
}
|
||||
|
||||
if ( mmap->type == MULTIBOOT_MEMORY_AVAILABLE){
|
||||
|
||||
} else{
|
||||
printf("allocate region: 0x%x, size : 0x%x bytes\n", (unsigned) mmap->addr,(unsigned) mmap->len );
|
||||
// memAlloc.allocate_region((unsigned)mmap->addr , (unsigned)mmap->len);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
printf("allocate region: 0x%x, size : 0x%x bytes\n", &kernel_begin, &kernel_end - &kernel_begin );
|
||||
//memAlloc.allocate_region(kernel_end, kernel_end - kernel_begin);
|
||||
|
||||
// test alloc_block
|
||||
/*
|
||||
uint8_t* memory = (uint8_t*) memAlloc.allocate_block();
|
||||
printf("Got a new pointer: 0x%x\n", memory);
|
||||
|
||||
uint8_t* memory2 = (uint8_t*) memAlloc.allocate_block();
|
||||
printf("Got a new pointer: 0x%x\n", memory2);
|
||||
|
||||
|
||||
memAlloc.free_block((void*) memory);
|
||||
|
||||
uint8_t* newBlockPlse = (uint8_t*) memAlloc.allocate_block();
|
||||
*/
|
||||
|
||||
|
||||
|
||||
//memAlloc.free_block((void*) memory);
|
||||
//InitializePaging();
|
||||
//IdentityMap();
|
||||
//Enable();
|
||||
} else{
|
||||
printf("memory flag not set!");
|
||||
if(BootInfo->PhysicalMemoryMapAvailable)
|
||||
{
|
||||
printf("- Physical Memory Map available!\n");
|
||||
}
|
||||
|
||||
CheckMBT( (multiboot_info_t *) addr);
|
||||
asm volatile("mov %cr0, %eax ");
|
||||
asm volatile("or $1, %eax");
|
||||
asm volatile("mov %eax, %cr0");
|
||||
kernel_main(&bootinfo);
|
||||
kernel_main();
|
||||
|
||||
}
|
||||
|
||||
@ -151,9 +77,28 @@ void map_multiboot_info_structure(unsigned long addr){
|
||||
asm("movl %cr3, %ecx;" "movl %ecx, %cr3" );
|
||||
}
|
||||
|
||||
|
||||
extern "C" void kernel_main (BootInfo* bootinfo) {
|
||||
void PhysicalMemoryAllocatorTest(){
|
||||
#ifdef UNIT_TESTS
|
||||
// test alloc_block
|
||||
uint8_t* memory = (uint8_t*) memAlloc.allocate_block();
|
||||
printf("Got a new pointer: 0x%x\n", memory);
|
||||
|
||||
uint8_t* memory2 = (uint8_t*) memAlloc.allocate_block();
|
||||
printf("Got a new pointer: 0x%x\n", memory2);
|
||||
|
||||
memAlloc.free_block((void*) memory);
|
||||
uint8_t* newBlockPlse = (uint8_t*) memAlloc.allocate_block();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
extern "C" void kernel_main () {
|
||||
pit_initialise();
|
||||
|
||||
// Create a dummy BootInfo object
|
||||
// TODO: This should be done properly or the dependency should
|
||||
// be removed from the SuperVisorTerminal.
|
||||
BootInfo* bootinfo = {};
|
||||
|
||||
startSuperVisorTerminal(bootinfo);
|
||||
}
|
Reference in New Issue
Block a user