2023-01-10 21:28:59 +02:00
|
|
|
#include <BAN/Memory.h>
|
2022-12-19 11:33:07 +02:00
|
|
|
#include <kernel/APIC.h>
|
2022-11-15 00:32:07 +02:00
|
|
|
#include <kernel/GDT.h>
|
2022-11-16 19:49:09 +02:00
|
|
|
#include <kernel/IDT.h>
|
2022-12-30 19:38:21 +02:00
|
|
|
#include <kernel/Input.h>
|
2022-11-15 00:32:07 +02:00
|
|
|
#include <kernel/kmalloc.h>
|
2022-12-10 00:33:03 +02:00
|
|
|
#include <kernel/kprint.h>
|
2023-01-10 17:50:24 +02:00
|
|
|
#include <kernel/MMU.h>
|
2022-11-15 21:42:14 +02:00
|
|
|
#include <kernel/multiboot.h>
|
2022-12-28 04:17:06 +02:00
|
|
|
#include <kernel/Paging.h>
|
2022-12-07 02:41:18 +02:00
|
|
|
#include <kernel/PIC.h>
|
|
|
|
#include <kernel/PIT.h>
|
2022-12-13 10:41:36 +02:00
|
|
|
#include <kernel/RTC.h>
|
2022-12-10 00:33:03 +02:00
|
|
|
#include <kernel/Serial.h>
|
2022-12-13 21:34:50 +02:00
|
|
|
#include <kernel/Shell.h>
|
2022-12-23 15:55:45 +02:00
|
|
|
#include <kernel/TTY.h>
|
2022-12-15 19:05:07 +02:00
|
|
|
#include <kernel/VESA.h>
|
2022-11-12 21:04:47 +02:00
|
|
|
|
2022-11-15 00:32:07 +02:00
|
|
|
#define DISABLE_INTERRUPTS() asm volatile("cli")
|
|
|
|
#define ENABLE_INTERRUPTS() asm volatile("sti")
|
2022-11-12 21:04:47 +02:00
|
|
|
|
2023-01-10 17:50:24 +02:00
|
|
|
extern "C" const char g_kernel_cmdline[];
|
2022-11-14 00:27:11 +02:00
|
|
|
|
2022-12-20 11:57:09 +02:00
|
|
|
using namespace BAN;
|
|
|
|
|
|
|
|
struct ParsedCommandLine
|
|
|
|
{
|
|
|
|
bool force_pic = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
ParsedCommandLine ParseCommandLine(const char* command_line)
|
|
|
|
{
|
|
|
|
ParsedCommandLine result;
|
2022-12-28 04:17:46 +02:00
|
|
|
|
|
|
|
const char* start = command_line;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if (!*command_line || *command_line == ' ' || *command_line == '\t')
|
|
|
|
{
|
|
|
|
if (command_line - start == 6 && memcmp(start, "noapic", 6) == 0)
|
|
|
|
result.force_pic = true;
|
|
|
|
|
|
|
|
if (!*command_line)
|
|
|
|
break;
|
|
|
|
start = command_line + 1;
|
|
|
|
}
|
|
|
|
command_line++;
|
|
|
|
}
|
|
|
|
|
2022-12-20 11:57:09 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void kernel_main(multiboot_info_t* mbi, uint32_t magic)
|
2022-11-15 00:32:07 +02:00
|
|
|
{
|
|
|
|
DISABLE_INTERRUPTS();
|
2022-11-14 00:27:11 +02:00
|
|
|
|
2022-12-15 19:05:07 +02:00
|
|
|
Serial::initialize();
|
2022-12-07 02:41:18 +02:00
|
|
|
if (magic != 0x2BADB002)
|
2022-12-15 19:05:07 +02:00
|
|
|
{
|
|
|
|
dprintln("Invalid multiboot magic number");
|
2022-12-10 00:33:03 +02:00
|
|
|
return;
|
2022-12-15 19:05:07 +02:00
|
|
|
}
|
2022-12-07 02:41:18 +02:00
|
|
|
|
2023-01-09 14:56:20 +02:00
|
|
|
|
|
|
|
dprintln("hello from 64 bit protected mode!");
|
|
|
|
|
2022-12-28 04:17:06 +02:00
|
|
|
Paging::Initialize();
|
|
|
|
|
2023-01-09 14:56:20 +02:00
|
|
|
dprintln("paging enabled");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
2022-12-15 19:05:07 +02:00
|
|
|
s_multiboot_info = mbi;
|
|
|
|
|
2022-12-23 15:55:45 +02:00
|
|
|
if (!VESA::Initialize())
|
2022-12-15 19:05:07 +02:00
|
|
|
return;
|
2022-12-20 11:57:09 +02:00
|
|
|
|
|
|
|
ParsedCommandLine cmdline;
|
|
|
|
if (mbi->flags & 0x02)
|
|
|
|
cmdline = ParseCommandLine((const char*)mbi->cmdline);
|
|
|
|
|
|
|
|
APIC::Initialize(cmdline.force_pic);
|
2022-11-16 19:49:09 +02:00
|
|
|
gdt_initialize();
|
2022-12-07 02:41:18 +02:00
|
|
|
IDT::initialize();
|
|
|
|
|
2022-12-28 04:16:21 +02:00
|
|
|
kmalloc_initialize();
|
|
|
|
|
2023-01-04 19:22:23 +02:00
|
|
|
PIT::initialize();
|
2022-12-30 19:38:21 +02:00
|
|
|
if (!Input::initialize())
|
2022-12-13 10:42:49 +02:00
|
|
|
return;
|
2022-11-15 21:42:14 +02:00
|
|
|
|
2023-01-04 19:22:23 +02:00
|
|
|
TTY* tty1 = new TTY;
|
|
|
|
tty1->SetCursorPosition(0, 2);
|
|
|
|
|
2022-12-10 03:53:44 +02:00
|
|
|
ENABLE_INTERRUPTS();
|
2022-11-13 01:04:10 +02:00
|
|
|
|
2022-12-19 11:33:07 +02:00
|
|
|
kprintln("Hello from the kernel!");
|
|
|
|
|
2022-12-13 21:34:50 +02:00
|
|
|
auto& shell = Kernel::Shell::Get();
|
2022-12-23 15:55:45 +02:00
|
|
|
shell.SetTTY(tty1);
|
2022-12-13 21:34:50 +02:00
|
|
|
shell.Run();
|
2022-12-13 10:42:49 +02:00
|
|
|
|
2022-12-07 02:41:18 +02:00
|
|
|
for (;;)
|
|
|
|
{
|
2022-12-13 21:34:50 +02:00
|
|
|
asm("hlt");
|
2022-12-07 02:41:18 +02:00
|
|
|
}
|
2022-11-12 21:04:47 +02:00
|
|
|
}
|