diff options
| author | Fabian Imhof <fabian.imhof@ost.ch> | 2025-04-17 14:15:39 +0000 |
|---|---|---|
| committer | Fabian Imhof <fabian.imhof@ost.ch> | 2025-04-17 14:15:39 +0000 |
| commit | 65718b1470a9b6bfac3520587263c5374f4a4419 (patch) | |
| tree | cfd952c4bec62cc5210faa0aacd10f3381026943 | |
| parent | 8975c5fe091150245fd58a0a42a83b4f41d454e0 (diff) | |
| parent | 576a7a95b2462ec4938de9fe344657ca04b2ba34 (diff) | |
| download | teachos-65718b1470a9b6bfac3520587263c5374f4a4419.tar.xz teachos-65718b1470a9b6bfac3520587263c5374f4a4419.zip | |
Merge branch 'syscall_interrupt_handler' into feat_inital_context_switching
4 files changed, 30 insertions, 7 deletions
diff --git a/arch/x86_64/include/arch/interrupt_handling/generic_interrupt_handler.hpp b/arch/x86_64/include/arch/interrupt_handling/generic_interrupt_handler.hpp index 6c1db12..309acbb 100644 --- a/arch/x86_64/include/arch/interrupt_handling/generic_interrupt_handler.hpp +++ b/arch/x86_64/include/arch/interrupt_handling/generic_interrupt_handler.hpp @@ -13,12 +13,12 @@ namespace teachos::arch::interrupt_handling */ struct [[gnu::packed]] interrupt_frame { - uint64_t error_code; ///< Error code pushed by some exceptions. - uint64_t ip; ///< Instruction pointer at the time of the interrupt. - uint64_t cs; ///< Code segment selector indicating privilege level. - uint64_t flags; ///< CPU flags (RFLAGS) storing processor state. - uint64_t sp; ///< Stack pointer at the time of the interrupt. - uint64_t ss; ///< Stack segment selector, usually unused in 64-bit mode. + // uint64_t error_code; ///< Error code pushed by some exceptions. + uint64_t ip; ///< Instruction pointer at the time of the interrupt. + uint64_t cs; ///< Code segment selector indicating privilege level. + uint64_t flags; ///< CPU flags (RFLAGS) storing processor state. + uint64_t sp; ///< Stack pointer at the time of the interrupt. + uint64_t ss; ///< Stack segment selector, usually unused in 64-bit mode. }; /** @@ -29,6 +29,14 @@ namespace teachos::arch::interrupt_handling [[gnu::interrupt]] auto generic_interrupt_handler(struct interrupt_frame * frame) -> void; + /** + * @brief Interrupt handler function for syscalls (INT 0x80). + * + * @param frame Pointer to the interrupt frame containing CPU state. + */ + [[gnu::interrupt]] + auto syscall_interrupt_handler(struct interrupt_frame * frame) -> void; + } // namespace teachos::arch::interrupt_handling #endif // TEACHOS_ARCH_X86_64_INTERRUPT_HANDLING_GENERIC_INTERRUPT_HANDLER_HPP diff --git a/arch/x86_64/src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.cpp b/arch/x86_64/src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.cpp index 80f01a8..c50ac1d 100644 --- a/arch/x86_64/src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.cpp +++ b/arch/x86_64/src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.cpp @@ -10,7 +10,7 @@ namespace teachos::arch::context_switching::interrupt_descriptor_table { /// @brief Amount of currently reserved interrupt indicies. /// See https://wiki.osdev.org/Interrupt_Descriptor_Table#IDT_items for more information. - constexpr uint8_t RESERVED_INTERRUPT_COUNT = 32U; + constexpr uint16_t RESERVED_INTERRUPT_COUNT = 256U; auto create_interrupt_descriptor_table() -> interrupt_descriptor_table { @@ -26,6 +26,11 @@ namespace teachos::arch::context_switching::interrupt_descriptor_table interrupt_descriptor_table.at(i) = {selector, ist, flags, offset}; } + interrupt_descriptor_table.at(0x80) = { + segment_selector{3U, segment_selector::REQUEST_LEVEL_USER}, ist_offset{0U}, + idt_flags{idt_flags::DESCRIPTOR_LEVEL_USER | idt_flags::INTERRUPT_GATE | idt_flags::PRESENT}, + uint64_t{reinterpret_cast<uint64_t>(interrupt_handling::syscall_interrupt_handler)}}; + return interrupt_descriptor_table; } } // namespace diff --git a/arch/x86_64/src/context_switching/main.cpp b/arch/x86_64/src/context_switching/main.cpp index 486a09f..7be286a 100644 --- a/arch/x86_64/src/context_switching/main.cpp +++ b/arch/x86_64/src/context_switching/main.cpp @@ -51,6 +51,9 @@ namespace teachos::arch::context_switching auto user_mode_main() -> void { kernel::cpu::validate_segment_registers(USER_DATA_SEGMENT_SELECTOR, USER_CODE_SEGMENT_SELECTOR); + + asm volatile("INT $0x80"); + video::vga::text::write("Successfully entered user mode!", video::vga::text::common_attributes::green_on_black); } diff --git a/arch/x86_64/src/interrupt_handling/generic_interrupt_handler.cpp b/arch/x86_64/src/interrupt_handling/generic_interrupt_handler.cpp index 4392b04..6075770 100644 --- a/arch/x86_64/src/interrupt_handling/generic_interrupt_handler.cpp +++ b/arch/x86_64/src/interrupt_handling/generic_interrupt_handler.cpp @@ -11,4 +11,11 @@ namespace teachos::arch::interrupt_handling (void)frame; video::vga::text::write("An Interrupt occurred.", video::vga::text::common_attributes::green_on_black); } + + [[gnu::interrupt]] [[gnu::section(".interrupt_text")]] + auto syscall_interrupt_handler(interrupt_frame * frame) -> void + { + (void)frame; + video::vga::text::write("A SYSCALL interrupt occurred.", video::vga::text::common_attributes::green_on_black); + } } // namespace teachos::arch::interrupt_handling |
