2021-05-10 20:33:25 +00:00
|
|
|
#include "kernel.h"
|
2021-12-20 20:53:57 +00:00
|
|
|
|
2022-08-17 23:26:49 +00:00
|
|
|
|
2022-02-26 19:44:16 +00:00
|
|
|
extern "C" void kernel_main (BootInfo* bootinfo) {
|
|
|
|
init_serial();
|
2022-08-17 23:26:49 +00:00
|
|
|
//pit_initialise();
|
2022-03-18 21:09:04 +00:00
|
|
|
|
2022-02-26 19:44:16 +00:00
|
|
|
startSuperVisorTerminal(bootinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" void early_main(unsigned long magic, unsigned long addr){
|
|
|
|
/**
|
|
|
|
* Initialize terminal interface
|
|
|
|
* NOTE: This should be done later on , the magic value should be checked first.
|
|
|
|
*/
|
2022-08-17 23:26:49 +00:00
|
|
|
initGDT();
|
2022-02-26 19:44:16 +00:00
|
|
|
kterm_init();
|
2022-08-17 23:26:49 +00:00
|
|
|
init_serial();
|
|
|
|
print_serial("Hello Higher half kernel!");
|
|
|
|
printf("DDDDDDDDDDDDDDDD");
|
|
|
|
return;
|
2022-02-26 19:44:16 +00:00
|
|
|
/**
|
|
|
|
* 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");
|
2022-08-17 23:26:49 +00:00
|
|
|
printf("Kernel Begin AT(0x%x)", kernel_begin);
|
2022-02-26 19:44:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 = {};
|
|
|
|
|
2021-12-20 20:53:57 +00:00
|
|
|
|
2022-02-26 19:44:16 +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(mbt->flags, 6))
|
|
|
|
{
|
2021-07-22 21:14:58 +00:00
|
|
|
|
2022-02-26 19:44:16 +00:00
|
|
|
/*
|
|
|
|
Setup Physical memory managment
|
|
|
|
*/
|
|
|
|
MemoryInfo meminfo = {};
|
|
|
|
bootinfo.memory = &meminfo;
|
|
|
|
|
|
|
|
mapMultibootMemoryMap(bootinfo.memory , mbt);
|
|
|
|
printf("Memory size: 0x%x bytes\n", bootinfo.memory->TotalMemory );
|
2021-12-28 18:47:32 +00:00
|
|
|
|
2022-02-26 19:44:16 +00:00
|
|
|
PhysicalMemory memAlloc = PhysicalMemory{};
|
|
|
|
memAlloc.setup(bootinfo.memory );
|
2021-12-28 18:47:32 +00:00
|
|
|
|
2022-02-26 19:44:16 +00:00
|
|
|
/*
|
|
|
|
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 );
|
2021-11-02 20:03:11 +00:00
|
|
|
|
2022-02-26 19:44:16 +00:00
|
|
|
multiboot_memory_map_t *mmap = (multiboot_memory_map_t*) mbt->mmap_addr;
|
2021-05-12 22:03:00 +00:00
|
|
|
|
2022-02-26 19:44:16 +00:00
|
|
|
for (; (unsigned long) mmap < mbt->mmap_addr + mbt->mmap_length; mmap = (multiboot_memory_map_t *) ((unsigned long) mmap + mmap->size + sizeof(mmap->size))){
|
2021-12-20 20:53:57 +00:00
|
|
|
|
2022-02-26 19:44:16 +00:00
|
|
|
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);
|
2021-12-28 18:47:32 +00:00
|
|
|
}
|
2022-02-26 19:44:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2022-08-15 17:51:22 +00:00
|
|
|
/*
|
2022-02-26 19:44:16 +00:00
|
|
|
uint8_t* memory = (uint8_t*) memAlloc.allocate_block();
|
|
|
|
printf("Got a new pointer: 0x%x\n", memory);
|
2021-12-28 18:47:32 +00:00
|
|
|
|
2022-02-26 19:44:16 +00:00
|
|
|
uint8_t* memory2 = (uint8_t*) memAlloc.allocate_block();
|
|
|
|
printf("Got a new pointer: 0x%x\n", memory2);
|
2021-12-28 18:47:32 +00:00
|
|
|
|
|
|
|
|
2022-02-26 19:44:16 +00:00
|
|
|
memAlloc.free_block((void*) memory);
|
2021-12-28 18:47:32 +00:00
|
|
|
|
2022-02-26 19:44:16 +00:00
|
|
|
uint8_t* newBlockPlse = (uint8_t*) memAlloc.allocate_block();
|
2022-08-15 17:51:22 +00:00
|
|
|
*/
|
2022-02-26 19:44:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-08-17 12:17:58 +00:00
|
|
|
//memAlloc.free_block((void*) memory);
|
|
|
|
//InitializePaging();
|
2022-08-17 23:26:49 +00:00
|
|
|
//IdentityMap();
|
|
|
|
//Enable();
|
2022-02-26 19:44:16 +00:00
|
|
|
}
|
|
|
|
|
2022-08-17 23:26:49 +00:00
|
|
|
//initGDT();
|
|
|
|
//init_idt();
|
2022-02-26 19:44:16 +00:00
|
|
|
// Enable interrupts
|
2022-08-17 23:26:49 +00:00
|
|
|
//asm volatile("STI");
|
2022-02-26 19:44:16 +00:00
|
|
|
|
|
|
|
|
2022-08-17 23:26:49 +00:00
|
|
|
//CheckMBT( (multiboot_info_t *) addr);
|
2021-11-16 12:57:15 +00:00
|
|
|
|
2021-12-28 18:47:32 +00:00
|
|
|
|
2022-02-26 19:44:16 +00:00
|
|
|
kernel_main(&bootinfo);
|
|
|
|
|
|
|
|
}
|
2021-11-03 19:03:38 +00:00
|
|
|
|