2022-12-20 11:57:09 +02:00
|
|
|
#include <BAN/StringView.h>
|
|
|
|
#include <BAN/Vector.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-10 00:33:03 +02:00
|
|
|
#include <kernel/IO.h>
|
2022-12-08 17:52:08 +02:00
|
|
|
#include <kernel/Keyboard.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>
|
2022-11-15 21:42:14 +02:00
|
|
|
#include <kernel/multiboot.h>
|
2022-11-15 00:32:07 +02:00
|
|
|
#include <kernel/panic.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
|
|
|
|
2022-12-20 11:57:09 +02:00
|
|
|
|
2022-11-15 21:42:14 +02:00
|
|
|
multiboot_info_t* s_multiboot_info;
|
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)
|
|
|
|
{
|
|
|
|
auto args = MUST(StringView(command_line).Split([](char c) { return c == ' ' || c == '\t'; }));
|
2022-12-20 14:01:04 +02:00
|
|
|
|
2022-12-20 11:57:09 +02:00
|
|
|
ParsedCommandLine result;
|
|
|
|
result.force_pic = args.Has("noapic");
|
|
|
|
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
|
|
|
|
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
|
|
|
{
|
|
|
|
dprintln("Could not initialize VESA");
|
|
|
|
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();
|
|
|
|
|
|
|
|
PIT::initialize();
|
2022-12-28 04:16:21 +02:00
|
|
|
kmalloc_initialize();
|
|
|
|
|
|
|
|
TTY* tty1 = new TTY;
|
|
|
|
tty1->SetCursorPosition(0, 2);
|
|
|
|
|
2022-12-13 21:34:50 +02:00
|
|
|
if (!Keyboard::initialize())
|
2022-12-13 10:42:49 +02:00
|
|
|
return;
|
2022-11-15 21:42:14 +02:00
|
|
|
|
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
|
|
|
}
|