2025-05-29 03:19:50 +00:00
|
|
|
//Our own code, at this point...
|
2025-07-02 23:48:33 +00:00
|
|
|
//Output table:
|
|
|
|
|
//0: VGA
|
|
|
|
|
//1: COM1
|
|
|
|
|
#define OUTPUT_TYPE 1
|
2025-05-23 05:18:12 +00:00
|
|
|
#include <stdint.h>
|
2025-06-29 05:13:43 +00:00
|
|
|
#include "vga.h"
|
|
|
|
|
#include "io.h"
|
2025-06-08 05:27:41 +00:00
|
|
|
#include "kttools.h"
|
2025-06-09 02:44:17 +00:00
|
|
|
#include "kmultiboot.h"
|
2025-06-28 04:14:42 +00:00
|
|
|
#include "idt.h"
|
2025-07-02 23:48:33 +00:00
|
|
|
#include "serial.h"
|
2025-06-11 03:41:51 +00:00
|
|
|
void kern_main(uint32_t multiboot_magic, mb_info_t* multiboot_info)
|
2025-05-23 05:18:12 +00:00
|
|
|
{
|
2025-06-11 04:27:15 +00:00
|
|
|
//Hello C! Let's get to work in cleaning up our environment a bit and creating some safety.
|
|
|
|
|
//First interrupts.
|
2025-06-28 04:14:42 +00:00
|
|
|
setup_idt();
|
2025-07-02 23:48:33 +00:00
|
|
|
|
|
|
|
|
//Let's pick an output schema.
|
|
|
|
|
int (*outWriter)(char) = 0;
|
|
|
|
|
int comstatus = 1234;
|
|
|
|
|
switch(OUTPUT_TYPE) {
|
|
|
|
|
case 1:
|
|
|
|
|
comstatus = serial_init(COM1);
|
|
|
|
|
if(comstatus) {
|
|
|
|
|
//Fail...
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
outWriter = serial_send8;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
//VGA is selected or the selected option failed, falling back
|
|
|
|
|
if(outWriter == 0){
|
|
|
|
|
outWriter = vga_out;
|
|
|
|
|
vga_clear();
|
|
|
|
|
}
|
2025-06-08 05:27:41 +00:00
|
|
|
|
2025-07-02 23:48:33 +00:00
|
|
|
printf(outWriter, "Entry eax:%X\n", multiboot_magic);
|
2025-06-08 20:18:06 +00:00
|
|
|
|
|
|
|
|
if(multiboot_magic != 0x2BADB002) {
|
2025-07-02 23:48:33 +00:00
|
|
|
println(outWriter, writerState, "Bootloader not multiboot1 compliant! Needed for mmap, etc. Can't work without it, kthxbye!");
|
2025-06-08 20:18:06 +00:00
|
|
|
return;
|
|
|
|
|
} else {
|
2025-07-02 23:48:33 +00:00
|
|
|
println(outWriter, writerState, "Multiboot detected! Continuing...");
|
2025-06-08 20:18:06 +00:00
|
|
|
}
|
|
|
|
|
|
2025-07-02 23:48:33 +00:00
|
|
|
printf(outWriter, writerState, "MEM_LOWER:%X\n", multiboot_info->mem_lower);
|
|
|
|
|
printf(outWriter, writerState"MEM_UPPER:%X\n", multiboot_info->mem_upper);
|
2025-05-23 05:18:12 +00:00
|
|
|
}
|
|
|
|
|
|