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-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-10-23 11:26:15 +00:00
|
|
|
for (mmap; (unsigned long) mmap < mbt->mmap_addr + mbt->mmap_length; mmap = (multiboot_memory_map_t *) ((unsigned long) mmap + mmap->size + sizeof(mmap->size))){
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw diagonal blue line */
|
|
|
|
if (CHECK_FLAG (mbi->flags, 12)){
|
|
|
|
printf("Can draw!");
|
|
|
|
}
|
2021-07-22 21:14:58 +00:00
|
|
|
|
|
|
|
int cpu_model = get_model();
|
|
|
|
int local_apic = check_apic();
|
|
|
|
printf( "CPU Model: %x, Local APIC: %D\n", cpu_model, local_apic);
|
|
|
|
|
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-05-10 20:33:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-05-18 20:14:26 +00:00
|
|
|
while (true){
|
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-05-28 21:20:13 +00:00
|
|
|
|
2021-05-10 20:33:25 +00:00
|
|
|
|
2021-07-22 21:14:58 +00:00
|
|
|
|
|
|
|
|
2021-05-10 20:33:25 +00:00
|
|
|
}
|
|
|
|
}
|