2021-05-10 20:33:25 +00:00
# include "kernel.h"
2022-08-22 19:16:34 +00:00
extern " C " void early_main ( )
{
/*
2022-02-26 19:44:16 +00:00
* Initialize terminal interface
*/
2022-08-17 23:26:49 +00:00
initGDT ( ) ;
2022-08-22 19:16:34 +00:00
2022-02-26 19:44:16 +00:00
kterm_init ( ) ;
2022-08-22 19:16:34 +00:00
2022-08-17 23:26:49 +00:00
init_serial ( ) ;
2022-08-18 22:44:52 +00:00
print_serial ( " Hello Higher half kernel! \n " ) ;
init_idt ( ) ;
// Enable interrupts
asm volatile ( " STI " ) ;
2022-08-18 23:05:10 +00:00
2022-08-22 19:16:34 +00:00
/*
2022-02-26 19:44:16 +00:00
* Show a little banner for cuteness
*/
printf ( " |=== BarinkOS ===| \n " ) ;
2021-12-28 18:47:32 +00:00
2022-08-22 19:16:34 +00:00
BootInfoBlock * BootInfo = ( BootInfoBlock * ) ( BootInfoBlock_pptr + 0xC0000000 ) ;
2021-12-28 18:47:32 +00:00
2022-08-22 19:16:34 +00:00
printf ( " Bootloader information: \n " ) ;
if ( BootInfo - > ValidELFHeader )
{
printf ( " - Valid ELF Header is available! \n " ) ;
}
2022-02-26 19:44:16 +00:00
2022-08-22 19:16:34 +00:00
if ( BootInfo - > EnabledVBE )
{
printf ( " - VBE graphics mode is available! \n " ) ;
}
2022-02-26 19:44:16 +00:00
2022-08-22 19:16:34 +00:00
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 ) ;
}
2022-02-26 19:44:16 +00:00
2022-08-22 19:16:34 +00:00
if ( BootInfo - > PhysicalMemoryMapAvailable )
{
printf ( " - Physical Memory Map available! \n " ) ;
2022-02-26 19:44:16 +00:00
}
2022-08-21 19:15:15 +00:00
asm volatile ( " mov %cr0, %eax " ) ;
asm volatile ( " or $1, %eax " ) ;
asm volatile ( " mov %eax, %cr0 " ) ;
2022-08-22 19:16:34 +00:00
kernel_main ( ) ;
2022-02-26 19:44:16 +00:00
}
2021-11-03 19:03:38 +00:00
2022-08-19 21:44:38 +00:00
void map_multiboot_info_structure ( unsigned long addr ) {
// map the multiboot structure into virtual memory
// so we can gather the necessary data from it.
uint32_t pageDirectoryIndex = ( addr ) > > 22 ;
printf ( " pageDirectoryIndex: %d \n " , pageDirectoryIndex ) ;
uint32_t pageTableIndex = ( addr > > 12 ) & 0x1FFF ;
printf ( " PagTableIndex: %d \n " , pageTableIndex ) ;
printf ( " boot_page_directory addr: 0x%x \n " , & boot_page_directory ) ;
printf ( " boot_page_table addr: 0x%x \n " , & multiboot_page_table ) ;
uint32_t * current_page_directory = & boot_page_directory ;
uint32_t * needed_page_table = & multiboot_page_table - KERNEL_BASE_ADDR ;
// set the page tabel reference;
current_page_directory [ pageDirectoryIndex ] = ( uint32_t ) & multiboot_page_table - KERNEL_BASE_ADDR + 0x003 ;
// set the page reference;
needed_page_table [ pageTableIndex ] = addr | 0x003 ;
// Reload CR3 to force a flush
asm ( " movl %cr3, %ecx; " " movl %ecx, %cr3 " ) ;
}
2022-08-22 19:16:34 +00:00
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 ( ) {
2022-08-19 21:44:38 +00:00
pit_initialise ( ) ;
2022-08-22 19:16:34 +00:00
// Create a dummy BootInfo object
// TODO: This should be done properly or the dependency should
// be removed from the SuperVisorTerminal.
BootInfo * bootinfo = { } ;
2022-08-19 21:44:38 +00:00
startSuperVisorTerminal ( bootinfo ) ;
}