Kernel: You can now disable APIC from the grub commandline

This commit is contained in:
Bananymous 2022-12-20 11:57:09 +02:00
parent 6732cabf20
commit 5e2680cade
4 changed files with 37 additions and 6 deletions

3
iso.sh
View File

@ -11,5 +11,8 @@ cat > isodir/boot/grub/grub.cfg << EOF
menuentry "banan-os" { menuentry "banan-os" {
multiboot /boot/banan-os.kernel multiboot /boot/banan-os.kernel
} }
menuentry "banan-os (no apic)" {
multiboot /boot/banan-os.kernel noapic
}
EOF EOF
grub-mkrescue -o banan-os.iso isodir grub-mkrescue -o banan-os.iso isodir

View File

@ -379,7 +379,7 @@ namespace APIC
return true; return true;
} }
void Initialize() void Initialize(bool force_pic)
{ {
for (uint32_t i = 0x00; i <= 0xFF; i++) for (uint32_t i = 0x00; i <= 0xFF; i++)
s_overrides[i] = i; s_overrides[i] = i;
@ -387,7 +387,12 @@ namespace APIC
PIC::MaskAll(); PIC::MaskAll();
PIC::Remap(); PIC::Remap();
if (!InitializeAPIC()) if (force_pic)
{
kprintln("Using PIC instead of APIC");
s_using_fallback_pic = true;
}
else if (!InitializeAPIC())
{ {
kprintln("Could not initialize APIC. Using PIC as fallback"); kprintln("Could not initialize APIC. Using PIC as fallback");
s_using_fallback_pic = true; s_using_fallback_pic = true;

View File

@ -5,7 +5,7 @@
namespace APIC namespace APIC
{ {
void Initialize(); void Initialize(bool force_pic = false);
void EOI(); void EOI();
void GetISR(uint32_t[8]); void GetISR(uint32_t[8]);
void EnableIRQ(uint8_t irq); void EnableIRQ(uint8_t irq);

View File

@ -1,3 +1,5 @@
#include <BAN/StringView.h>
#include <BAN/Vector.h>
#include <kernel/APIC.h> #include <kernel/APIC.h>
#include <kernel/GDT.h> #include <kernel/GDT.h>
#include <kernel/IDT.h> #include <kernel/IDT.h>
@ -18,10 +20,26 @@
#define DISABLE_INTERRUPTS() asm volatile("cli") #define DISABLE_INTERRUPTS() asm volatile("cli")
#define ENABLE_INTERRUPTS() asm volatile("sti") #define ENABLE_INTERRUPTS() asm volatile("sti")
multiboot_info_t* s_multiboot_info; multiboot_info_t* s_multiboot_info;
extern "C" using namespace BAN;
void kernel_main(multiboot_info_t* mbi, uint32_t magic)
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'; }));
ParsedCommandLine result;
result.force_pic = args.Has("noapic");
return result;
}
extern "C" void kernel_main(multiboot_info_t* mbi, uint32_t magic)
{ {
DISABLE_INTERRUPTS(); DISABLE_INTERRUPTS();
@ -43,7 +61,12 @@ void kernel_main(multiboot_info_t* mbi, uint32_t magic)
kmalloc_initialize(); kmalloc_initialize();
APIC::Initialize();
ParsedCommandLine cmdline;
if (mbi->flags & 0x02)
cmdline = ParseCommandLine((const char*)mbi->cmdline);
APIC::Initialize(cmdline.force_pic);
gdt_initialize(); gdt_initialize();
IDT::initialize(); IDT::initialize();