2021-05-10 20:33:25 +00:00
|
|
|
#include "kernel.h"
|
2021-11-06 15:27:13 +00:00
|
|
|
#define GB2 262144
|
2021-12-20 20:53:57 +00:00
|
|
|
|
|
|
|
extern "C" void kernel_main (void);
|
|
|
|
|
2021-11-03 19:03:38 +00:00
|
|
|
extern "C" void early_main(unsigned long magic, unsigned long addr){
|
2021-12-29 15:15:18 +00:00
|
|
|
/**
|
|
|
|
* Initialize terminal interface
|
|
|
|
* NOTE: This should be done later on , the magic value should be checked first.
|
|
|
|
*/
|
2021-07-22 19:02:47 +00:00
|
|
|
kterm_init();
|
2021-10-23 11:26:15 +00:00
|
|
|
|
2021-12-29 15:15:18 +00:00
|
|
|
/**
|
|
|
|
* Check Multiboot magic number
|
|
|
|
* NOTE: Printf call should not be a thing this early on ...
|
|
|
|
*/
|
2021-07-22 19:02:47 +00:00
|
|
|
if (magic != MULTIBOOT_BOOTLOADER_MAGIC){
|
2021-10-23 11:26:15 +00:00
|
|
|
printf("Invalid magic number: 0x%x\n", magic);
|
2021-07-22 19:02:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-29 15:15:18 +00:00
|
|
|
/**
|
|
|
|
* Show a little banner for cuteness
|
|
|
|
*/
|
|
|
|
printf("|=== BarinkOS ===|\n");
|
2021-07-22 19:02:47 +00:00
|
|
|
|
2021-12-29 15:15:18 +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;
|
|
|
|
|
|
|
|
/*
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
printf("Preliminary results mmap scan:\n");
|
|
|
|
mapMultibootMemoryMap(mbt);
|
|
|
|
|
2021-11-06 15:27:13 +00:00
|
|
|
PhysicalMemoryManager_initialise( mbt->mmap_addr, GB2/* Seriously dangerous hardcoded memory value*/);
|
|
|
|
PhysicalMemoryManager_initialise_available_regions(mbt->mmap_addr, mbt->mmap_addr + mbt->mmap_length);
|
|
|
|
PhysicalMemoryManager_deinitialise_kernel();
|
2021-07-22 19:02:47 +00:00
|
|
|
}
|
2021-12-28 18:47:32 +00:00
|
|
|
|
2021-11-16 20:17:49 +00:00
|
|
|
initGDT();
|
2021-12-20 20:53:57 +00:00
|
|
|
init_idt();
|
|
|
|
// Enable interrupts
|
|
|
|
asm volatile("STI");
|
|
|
|
|
2021-07-22 21:14:58 +00:00
|
|
|
|
2021-12-28 18:47:32 +00:00
|
|
|
CheckMBT( (multiboot_info_t *) addr);
|
|
|
|
|
|
|
|
|
2021-12-20 20:53:57 +00:00
|
|
|
kernel_main();
|
2021-11-02 20:03:11 +00:00
|
|
|
|
2021-05-12 22:03:00 +00:00
|
|
|
}
|
|
|
|
|
2021-11-03 19:03:38 +00:00
|
|
|
extern "C" void kernel_main (void) {
|
2021-07-22 19:02:47 +00:00
|
|
|
init_serial();
|
2021-12-20 20:53:57 +00:00
|
|
|
pit_initialise();
|
|
|
|
|
2021-11-06 20:56:42 +00:00
|
|
|
while (true){
|
2021-12-28 18:47:32 +00:00
|
|
|
|
|
|
|
printf("SUPERVISOR:>$ " );
|
|
|
|
int characterCount = 0;
|
|
|
|
char command[10] = "";
|
|
|
|
|
|
|
|
// NOTE: lets just show a kernel prompt
|
|
|
|
uint8_t ScanCode = getKey();
|
|
|
|
while( ScanCode != 0x1C )
|
|
|
|
{
|
|
|
|
char character = getASCIIKey();
|
|
|
|
kterm_put(character );
|
|
|
|
// wHAT THE HELL
|
|
|
|
|
|
|
|
if( characterCount < 10 ){
|
|
|
|
command[characterCount] = character;
|
|
|
|
characterCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScanCode = getKey();
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
KeyHandled();
|
|
|
|
|
|
|
|
|
|
|
|
if ( strncmp("TIME", command , characterCount ) == 0 ) {
|
|
|
|
read_rtc();
|
|
|
|
printf( "UTC time: %02d-%02d-%02d %02d:%02d:%02d (Ticks: %06d)\n" ,year, month, day, hour, minute, second, pit_tick);
|
|
|
|
} else if(strncmp("TEST", command, characterCount) == 0){
|
|
|
|
// asm volatile ("MOV $4, %AX ; MOV $0, %BX ; DIV %BX"); // IRS 0
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
printf("Unknown command\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-18 20:14:26 +00:00
|
|
|
delay(1000);
|
2021-12-28 18:47:32 +00:00
|
|
|
}
|
|
|
|
|
2021-11-16 12:57:15 +00:00
|
|
|
|
2021-07-22 21:14:58 +00:00
|
|
|
|
2021-12-28 18:47:32 +00:00
|
|
|
|
2021-05-10 20:33:25 +00:00
|
|
|
}
|
2021-11-03 19:03:38 +00:00
|
|
|
|