2019-06-27 18:57:54 +00:00
|
|
|
/************************
|
|
|
|
*** Team Kitty, 2019 ***
|
2019-07-17 01:04:04 +00:00
|
|
|
*** Sync ***
|
2019-06-27 18:57:54 +00:00
|
|
|
***********************/
|
2019-04-03 21:46:58 +00:00
|
|
|
|
2019-07-17 01:04:04 +00:00
|
|
|
/* This file contains the entry point
|
|
|
|
* to the kernel. This section consists
|
|
|
|
* mainly of bootloading functions.
|
|
|
|
*
|
|
|
|
* Graphics and memory will be setup
|
|
|
|
* at later stages.
|
|
|
|
*/
|
|
|
|
|
2019-06-25 21:31:26 +00:00
|
|
|
//#include <stdio.h>
|
2019-06-27 18:57:54 +00:00
|
|
|
#include <kernel.h>
|
2019-06-25 21:31:26 +00:00
|
|
|
#include <kernel/tty.h>
|
|
|
|
#include <kernel/serial.h>
|
2019-06-27 18:57:54 +00:00
|
|
|
#include <kernel/descriptor_tables.h>
|
2019-06-25 21:31:26 +00:00
|
|
|
|
|
|
|
void gdb_end() {} /* GDB Debugging stump */
|
|
|
|
|
2019-04-07 14:34:15 +00:00
|
|
|
int kernel_main(void) {
|
2019-06-25 21:31:26 +00:00
|
|
|
/* The kernel is started in 32-bit protected mode by the ASM. */
|
|
|
|
/* Here, we start by enabling the screen, then loading a GDT and IDT into the actual places they need to be. */
|
|
|
|
|
|
|
|
/* Black the screen out. */
|
2019-04-07 14:34:15 +00:00
|
|
|
screen_initialize();
|
|
|
|
|
2019-06-25 21:31:26 +00:00
|
|
|
/* Prepare the serial line for our debug output. */
|
2019-04-07 14:34:15 +00:00
|
|
|
init_serial();
|
2019-04-07 22:43:09 +00:00
|
|
|
serial_print(0x3F8, "[INFO] Serial ready.\r\n");
|
2019-06-25 21:31:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
serial_print(0x3F8, "[INFO] Beginning GDT subroutine.\r\n");
|
|
|
|
|
|
|
|
/* term_writes: writes a string to the terminal. */
|
|
|
|
term_writes("GDT...");
|
|
|
|
|
|
|
|
/* Prepares the Global Descriptor Table, called from gdt.c */
|
2019-04-07 15:36:51 +00:00
|
|
|
gdt_install();
|
2019-06-25 21:31:26 +00:00
|
|
|
|
|
|
|
/* puts: writes a line to the terminal. */
|
|
|
|
puts("GDT Ready.");
|
2019-04-07 22:43:09 +00:00
|
|
|
serial_print(0x3F8, "[INFO] GDT subroutine complete.\r\n");
|
2019-04-07 15:36:51 +00:00
|
|
|
|
2019-06-25 21:31:26 +00:00
|
|
|
/* Prepare the Interrupt Descriptor Table. */
|
2019-04-07 22:43:09 +00:00
|
|
|
serial_print(0x3F8, "[INFO] Beginning IDT subroutine.\r\n");
|
2019-06-25 21:31:26 +00:00
|
|
|
term_writes("IDT...");
|
2019-04-07 18:25:27 +00:00
|
|
|
idt_install();
|
2019-06-25 21:31:26 +00:00
|
|
|
puts("IDT Ready.");
|
2019-04-07 22:43:09 +00:00
|
|
|
serial_print(0x3F8, "[INFO] IDT subroutine complete.\r\n[INFO] Enabling interrupts.\r\n");
|
|
|
|
|
2019-06-25 21:31:26 +00:00
|
|
|
gdb_end(); /* The first important step. Waypoint it for gdb debugging. */
|
|
|
|
|
|
|
|
term_writes("Memory available:");
|
|
|
|
/* TODO: implement check_a20, which double-triple checks the state of the A20 line. */
|
|
|
|
|
|
|
|
//if(check_a20())
|
|
|
|
puts(" 4GB");
|
|
|
|
serial_print(0x3F8, "[INFO] A20 enabled. 4GB memory available.");
|
|
|
|
|
|
|
|
/* The first important thing: start the system clock immediately. */
|
2019-04-07 22:43:09 +00:00
|
|
|
serial_print(0x3F8, "[INFO] Starting System Clock.\r\n");
|
2019-06-25 21:31:26 +00:00
|
|
|
term_writes("Timer...");
|
2019-04-07 22:43:09 +00:00
|
|
|
timer_install();
|
2019-06-25 21:31:26 +00:00
|
|
|
puts("Timer Ready.");
|
2019-04-07 22:43:09 +00:00
|
|
|
|
2019-06-25 21:31:26 +00:00
|
|
|
serial_print(0x3F8, "[INFO] All subsystems ready. Printing message.\r\n");
|
|
|
|
|
|
|
|
/* Everything is ready; print a pretty message. */
|
2019-07-17 01:04:04 +00:00
|
|
|
term_setcolor(RED);
|
2019-06-25 21:31:26 +00:00
|
|
|
term_writes("\n(c)");
|
|
|
|
term_setcolor(GREEN);
|
2019-07-17 01:04:04 +00:00
|
|
|
term_writes(" Sync");
|
2019-06-25 21:31:26 +00:00
|
|
|
term_setcolor(WHITE);
|
2019-04-07 22:43:09 +00:00
|
|
|
term_writes(", 2019\n");
|
|
|
|
|
|
|
|
serial_print(0x3F8, "[INFO] All operations complete. Checking for other tasks...\r\n");
|
|
|
|
|
2019-06-25 21:31:26 +00:00
|
|
|
/* Here are a series of tests for the ANSI escape code and CSI implementations. */
|
|
|
|
term_writes("\x1b[BA"); /* Down a line, then A. */
|
|
|
|
|
|
|
|
|
|
|
|
/* A stub causing a Divide by Zero error. */
|
2019-06-27 18:57:54 +00:00
|
|
|
serial_print(0x3F8, "[DEBUG] Attempting a Divide by Zero error.\r\n");
|
|
|
|
char div = (5 / 0);
|
|
|
|
serial_print(0x3F8, "[DEBUG] Survived the error!\r\n");
|
2019-04-07 22:43:09 +00:00
|
|
|
|
2019-06-25 21:31:26 +00:00
|
|
|
gdb_end(); /* Everything is done. The last debug routine. */
|
|
|
|
return 0;
|
2019-04-03 21:46:58 +00:00
|
|
|
}
|
2019-06-25 21:31:26 +00:00
|
|
|
|