execute ltr in position where it doesnt fault

This commit is contained in:
2025-11-23 21:06:14 +01:00
parent d0e6c1e607
commit a7b488f270
5 changed files with 20 additions and 14 deletions

View File

@@ -198,6 +198,10 @@ paging_enable:
; Load Long Mode Global Descriptor Table ; Load Long Mode Global Descriptor Table
lgdt [gdt_long_mode_pointer] 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 ; Far jump to the 64-bit start code
jmp 0x8:long_mode_start jmp 0x8:long_mode_start

View File

@@ -19,6 +19,10 @@ extern "C" [[noreturn]] void kernel_init() {
// Call global constructors // Call global constructors
CSU::initializer(); CSU::initializer();
//Select 5th Segment in GDT. 5<<3 == 0x28
asm volatile ("mov $0x28, %ax");
asm("ltr %ax");
// Initialize ACPI // Initialize ACPI
if (!ACPI::init()) { if (!ACPI::init()) {
DBG_VERBOSE << "No ACPI!"; DBG_VERBOSE << "No ACPI!";

View File

@@ -110,17 +110,11 @@ extern "C" void handle_keyboard() {
void initInterruptHandlers() { void initInterruptHandlers() {
// Some handlers that are useful for debugging // Some handlers that are useful for debugging
IDT::set(Core::Interrupt::Vector::INVALID_OPCODE, IDT::set(Core::Interrupt::Vector::INVALID_OPCODE , IDT::InterruptDescriptor::Returning(handle_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::DOUBLE_FAULT, IDT::set(Core::Interrupt::Vector::INVALID_TSS , IDT::InterruptDescriptor::DivergingWithError(handle_invalid_tss));
IDT::InterruptDescriptor::DivergingWithError(handle_double_fault)); IDT::set(Core::Interrupt::Vector::GENERAL_PROTECTION_FAULT, IDT::InterruptDescriptor::DivergingWithError(handle_general_protection_fault));
IDT::set(Core::Interrupt::Vector::INVALID_TSS, IDT::set(Core::Interrupt::Vector::PAGE_FAULT , IDT::InterruptDescriptor::DivergingWithError(handle_page_fault));
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));
// TODO: Add more handlers here // TODO: Add more handlers here
IDT::set(Core::Interrupt::Vector::KEYBOARD, IDT::set(Core::Interrupt::Vector::KEYBOARD,

View File

@@ -40,6 +40,10 @@ extern "C" int main() {
tout.setPos(33, 0); tout.setPos(33, 0);
tout << OS_NAME << " (2.x)" << flush; tout << OS_NAME << " (2.x)" << flush;
//// double faults correctly
//volatile uint16_t test1 = 0;
//volatile uint16_t test = 8/test1;
// Initialize IOAPIC // Initialize IOAPIC
IOAPIC::init(); IOAPIC::init();

View File

@@ -32,7 +32,7 @@ QEMUKERNEL ?= -kernel $(KERNEL) -initrd $(INITRD)
KVMFLAGS = -enable-kvm -cpu host KVMFLAGS = -enable-kvm -cpu host
QEMUDBGFLAGS = -no-shutdown -no-reboot QEMUDBGFLAGS = -no-shutdown -no-reboot
GDB = gdb GDB = cgdb
ifneq ($(XDG_RUNTIME_DIR),) ifneq ($(XDG_RUNTIME_DIR),)
# We should prefer using domain sockets in a private directory # We should prefer using domain sockets in a private directory
GDBPORT ?= $(XDG_RUNTIME_DIR)/stubs-gdb.sock GDBPORT ?= $(XDG_RUNTIME_DIR)/stubs-gdb.sock