diff --git a/kernel/boot/longmode.asm b/kernel/boot/longmode.asm index 2b9d1b8..ae5841c 100644 --- a/kernel/boot/longmode.asm +++ b/kernel/boot/longmode.asm @@ -198,6 +198,10 @@ paging_enable: ; Load Long Mode Global Descriptor Table lgdt [gdt_long_mode_pointer] + ;; Select 5th Segment in GDT. 5<<3 == 0x28 + ;mov ax, 0x0028 + ;ltr ax + ; Far jump to the 64-bit start code jmp 0x8:long_mode_start diff --git a/kernel/boot/startup.cc b/kernel/boot/startup.cc index 96c9e29..f7f3ede 100644 --- a/kernel/boot/startup.cc +++ b/kernel/boot/startup.cc @@ -16,9 +16,13 @@ extern "C" [[noreturn]] void kernel_init() { // Initialize PICs PIC::initialize(); - // Call global constructors + // Call global constructors CSU::initializer(); + //Select 5th Segment in GDT. 5<<3 == 0x28 + asm volatile ("mov $0x28, %ax"); + asm("ltr %ax"); + // Initialize ACPI if (!ACPI::init()) { DBG_VERBOSE << "No ACPI!"; diff --git a/kernel/interrupt/handlers.cc b/kernel/interrupt/handlers.cc index a277a6d..bad3fcc 100644 --- a/kernel/interrupt/handlers.cc +++ b/kernel/interrupt/handlers.cc @@ -110,17 +110,11 @@ extern "C" void handle_keyboard() { void initInterruptHandlers() { // Some handlers that are useful for debugging - IDT::set(Core::Interrupt::Vector::INVALID_OPCODE, - IDT::InterruptDescriptor::Returning(handle_invalid_opcode)); - IDT::set(Core::Interrupt::Vector::DOUBLE_FAULT, - IDT::InterruptDescriptor::DivergingWithError(handle_double_fault)); - IDT::set(Core::Interrupt::Vector::INVALID_TSS, - IDT::InterruptDescriptor::ReturningWithError(handle_invalid_tss)); - IDT::set(Core::Interrupt::Vector::GENERAL_PROTECTION_FAULT, - IDT::InterruptDescriptor::ReturningWithError( - handle_general_protection_fault)); - IDT::set(Core::Interrupt::Vector::PAGE_FAULT, - IDT::InterruptDescriptor::ReturningWithError(handle_page_fault)); + IDT::set(Core::Interrupt::Vector::INVALID_OPCODE , IDT::InterruptDescriptor::Returning(handle_invalid_opcode)); + IDT::set(Core::Interrupt::Vector::DOUBLE_FAULT , IDT::InterruptDescriptor::DivergingWithError(handle_double_fault)); + IDT::set(Core::Interrupt::Vector::INVALID_TSS , IDT::InterruptDescriptor::DivergingWithError(handle_invalid_tss)); + IDT::set(Core::Interrupt::Vector::GENERAL_PROTECTION_FAULT, IDT::InterruptDescriptor::DivergingWithError(handle_general_protection_fault)); + IDT::set(Core::Interrupt::Vector::PAGE_FAULT , IDT::InterruptDescriptor::DivergingWithError(handle_page_fault)); // TODO: Add more handlers here IDT::set(Core::Interrupt::Vector::KEYBOARD, diff --git a/kernel/main.cc b/kernel/main.cc index 03b036c..d9db9a6 100644 --- a/kernel/main.cc +++ b/kernel/main.cc @@ -40,7 +40,11 @@ extern "C" int main() { tout.setPos(33, 0); tout << OS_NAME << " (2.x)" << flush; - // Initialize IOAPIC + //// double faults correctly + //volatile uint16_t test1 = 0; + //volatile uint16_t test = 8/test1; + + // Initialize IOAPIC IOAPIC::init(); // Init timer (1000us = 1ms) diff --git a/tools/qemu.mk b/tools/qemu.mk index 08cb874..4a3db90 100644 --- a/tools/qemu.mk +++ b/tools/qemu.mk @@ -32,7 +32,7 @@ QEMUKERNEL ?= -kernel $(KERNEL) -initrd $(INITRD) KVMFLAGS = -enable-kvm -cpu host QEMUDBGFLAGS = -no-shutdown -no-reboot -GDB = gdb +GDB = cgdb ifneq ($(XDG_RUNTIME_DIR),) # We should prefer using domain sockets in a private directory GDBPORT ?= $(XDG_RUNTIME_DIR)/stubs-gdb.sock