aboutsummaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorFabian Imhof <fabian.imhof@ost.ch>2025-04-21 08:18:41 +0000
committerFabian Imhof <fabian.imhof@ost.ch>2025-04-21 08:18:41 +0000
commit0986058bb9ca5b4afd7c578c815dc3a4c08808a9 (patch)
tree7820b35df1d58ca5a7367a77a5e16d5d914382d5 /arch
parent5dc0e92a7211b44429c1a2e7efe19c146f5c4f9a (diff)
downloadteachos-0986058bb9ca5b4afd7c578c815dc3a4c08808a9.tar.xz
teachos-0986058bb9ca5b4afd7c578c815dc3a4c08808a9.zip
WIP syscall
Diffstat (limited to 'arch')
-rw-r--r--arch/x86_64/src/context_switching/interrupt_descriptor_table/interrupt_descriptor_table.cpp4
-rw-r--r--arch/x86_64/src/context_switching/main.cpp9
-rw-r--r--arch/x86_64/src/interrupt_handling/generic_interrupt_handler.cpp22
3 files changed, 31 insertions, 4 deletions
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 c50ac1d..c041198 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
@@ -27,8 +27,8 @@ namespace teachos::arch::context_switching::interrupt_descriptor_table
}
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},
+ segment_selector{1U, segment_selector::REQUEST_LEVEL_KERNEL}, ist_offset{0U},
+ idt_flags{idt_flags::DESCRIPTOR_LEVEL_USER | idt_flags::TRAP_GATE | idt_flags::PRESENT},
uint64_t{reinterpret_cast<uint64_t>(interrupt_handling::syscall_interrupt_handler)}};
return interrupt_descriptor_table;
diff --git a/arch/x86_64/src/context_switching/main.cpp b/arch/x86_64/src/context_switching/main.cpp
index 7be286a..faaf831 100644
--- a/arch/x86_64/src/context_switching/main.cpp
+++ b/arch/x86_64/src/context_switching/main.cpp
@@ -52,7 +52,14 @@ namespace teachos::arch::context_switching
{
kernel::cpu::validate_segment_registers(USER_DATA_SEGMENT_SELECTOR, USER_CODE_SEGMENT_SELECTOR);
- asm volatile("INT $0x80");
+ // TODO/INFO:
+ // https://stackoverflow.com/questions/46022184/osdev-syscall-sysret-and-sysenter-sysexit-instructions-enabling
+ // https://stackoverflow.com/questions/12806584/what-is-better-int-0x80-or-syscall-in-32-bit-code-on-linux
+ //
+ // People claim that SYSENTER is for 32-Bit, while SYSCALL is for 64-Bit!
+
+ // asm volatile("INT $0x80");
+ asm volatile("SYSCALL");
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 6075770..7afd87d 100644
--- a/arch/x86_64/src/interrupt_handling/generic_interrupt_handler.cpp
+++ b/arch/x86_64/src/interrupt_handling/generic_interrupt_handler.cpp
@@ -15,7 +15,27 @@ namespace teachos::arch::interrupt_handling
[[gnu::interrupt]] [[gnu::section(".interrupt_text")]]
auto syscall_interrupt_handler(interrupt_frame * frame) -> void
{
+ // RDI, RSI, RDX, RCX, R8, R9
+ // RDI -> SYSCALL number
+ // Others are arguments
+
+ // TODO: The registers are not available here. We need to set them up on the stack
+ // and access them via argument.
+
+ uint64_t syscall_number{};
+ asm volatile("mov %%rdi, %0" : "=r"(syscall_number));
+
+ // Handle system call based on the number
+ switch (syscall_number)
+ {
+ case 1:
+ video::vga::text::write("SYSCALL 1.", video::vga::text::common_attributes::green_on_black);
+ break;
+ default:
+ // Handle unknown syscall
+ break;
+ }
+
(void)frame;
- video::vga::text::write("A SYSCALL interrupt occurred.", video::vga::text::common_attributes::green_on_black);
}
} // namespace teachos::arch::interrupt_handling