2021-05-10 20:33:25 +00:00
|
|
|
#include "kernel.h"
|
2021-10-23 11:26:15 +00:00
|
|
|
#include "arch/i386/gdt/gdtc.h"
|
2021-05-10 20:33:25 +00:00
|
|
|
extern "C" {
|
2021-05-12 22:03:00 +00:00
|
|
|
|
2021-07-22 19:02:47 +00:00
|
|
|
void early_main(unsigned long magic, unsigned long addr){
|
|
|
|
/** initialize terminal interface */
|
|
|
|
kterm_init();
|
2021-10-23 11:26:15 +00:00
|
|
|
|
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-10-23 11:26:15 +00:00
|
|
|
CheckMBT( (multiboot_info_t *) addr);
|
2021-07-22 19:02:47 +00:00
|
|
|
|
|
|
|
|
2021-10-23 11:26:15 +00:00
|
|
|
multiboot_info_t* mbt = (multiboot_info_t*) addr;
|
2021-07-22 19:02:47 +00:00
|
|
|
|
2021-10-23 11:26:15 +00:00
|
|
|
// Map the kernel
|
|
|
|
//initPhysicalMemoryManager();
|
2021-07-22 19:02:47 +00:00
|
|
|
|
|
|
|
// AAAAAH memory map, Yes please!
|
|
|
|
/* Are mmap_* valid? */
|
2021-10-23 11:26:15 +00:00
|
|
|
if (CHECK_FLAG(mbt->flags, 6)){
|
|
|
|
multiboot_memory_map_t *mmap = (multiboot_memory_map_t*) mbt->mmap_addr;
|
2021-11-02 20:03:11 +00:00
|
|
|
uint32_t memorySizeInBytes = 0;
|
|
|
|
uint32_t reservedMemoryInBytes = 0;
|
|
|
|
|
|
|
|
|
2021-07-22 19:02:47 +00:00
|
|
|
printf("mmap_addr = 0x%x, mmap_length = 0x%x\n",
|
2021-10-23 11:26:15 +00:00
|
|
|
(unsigned) mbt->mmap_addr, (unsigned) mbt->mmap_length);
|
2021-07-22 19:02:47 +00:00
|
|
|
|
2021-11-02 20:03:11 +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))){
|
|
|
|
if ( mmap->type == MULTIBOOT_MEMORY_AVAILABLE){
|
|
|
|
memorySizeInBytes += mmap->len;
|
|
|
|
} else {
|
|
|
|
reservedMemoryInBytes += mmap->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-22 19:02:47 +00:00
|
|
|
printf(
|
|
|
|
"size = 0x%x, base_addr = 0x%x%08x, length = 0x%x%08x, type = 0x%x\n",
|
|
|
|
(unsigned) mmap->size,
|
|
|
|
(unsigned) (mmap->addr >> 32),
|
|
|
|
(unsigned) (mmap->addr & 0xffffffff),
|
|
|
|
(unsigned) (mmap->len >> 32),
|
|
|
|
(unsigned) (mmap->len & 0xffffffff),
|
|
|
|
(unsigned) mmap->type);
|
|
|
|
|
|
|
|
}
|
2021-11-02 20:03:11 +00:00
|
|
|
uint32_t memorySizeInGiB = memorySizeInBytes / 1073741824;
|
|
|
|
|
|
|
|
printf("Available Memory: 0x%x bytes, 0x%x GiB\n", memorySizeInBytes, memorySizeInGiB );
|
|
|
|
printf("Reserved Memory: 0x%x bytes\n", reservedMemoryInBytes );
|
2021-07-22 19:02:47 +00:00
|
|
|
}
|
2021-11-02 20:03:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//int cpu_model = get_model();
|
|
|
|
//int local_apic = check_apic();
|
|
|
|
//printf( "CPU Model: %x, Local APIC: %D\n", cpu_model, local_apic);
|
|
|
|
|
|
|
|
|
|
|
|
/* Setup Paging and memory Managment*/
|
|
|
|
//MMU MemoryManagementUnit = MMU();
|
|
|
|
//MemoryManagementUnit.enable(); // Warning: Causes triple page fault
|
|
|
|
//printf("Pages available: %9d\n", pmm_available());
|
2021-07-22 19:02:47 +00:00
|
|
|
|
|
|
|
/* Draw diagonal blue line */
|
2021-11-02 20:03:11 +00:00
|
|
|
if (CHECK_FLAG (mbt->flags, 12)){
|
2021-07-22 19:02:47 +00:00
|
|
|
printf("Can draw!");
|
|
|
|
}
|
2021-07-22 21:14:58 +00:00
|
|
|
|
2021-11-02 20:03:11 +00:00
|
|
|
//setupGdt();
|
2021-07-22 21:14:58 +00:00
|
|
|
|
2021-11-02 20:03:11 +00:00
|
|
|
|
2021-05-12 22:03:00 +00:00
|
|
|
}
|
|
|
|
|
2021-05-10 20:33:25 +00:00
|
|
|
void kernel_main (void) {
|
2021-05-12 22:03:00 +00:00
|
|
|
|
2021-07-22 19:02:47 +00:00
|
|
|
init_serial();
|
|
|
|
|
2021-11-02 20:03:11 +00:00
|
|
|
while (false){
|
2021-05-28 21:20:13 +00:00
|
|
|
//Read time indefinetely
|
2021-05-18 20:14:26 +00:00
|
|
|
read_rtc();
|
2021-07-22 19:02:47 +00:00
|
|
|
printf( "UTC time: %02d-%02d-%02d %02d:%02d:%02d [ Formatted as YY-MM-DD h:mm:ss]\r" ,year, month, day, hour, minute, second);
|
2021-05-18 20:14:26 +00:00
|
|
|
delay(1000);
|
|
|
|
}
|
2021-07-22 21:14:58 +00:00
|
|
|
|
2021-05-10 20:33:25 +00:00
|
|
|
}
|
|
|
|
}
|