]> git.ameliathe1st.gay Git - voyage-au-centre-des-fichiers.git/commitdiff
Added support for haing multiple different syscalls (via a call jump table)
authorAmelia Coutard <eliottulio.coutard@gmail.com>
Wed, 1 Mar 2023 14:19:32 +0000 (15:19 +0100)
committerAmelia Coutard <eliottulio.coutard@gmail.com>
Wed, 1 Mar 2023 14:19:32 +0000 (15:19 +0100)
kernel/src/ring3.S
kernel/src/ring3.cpp
kernel/src/ring3.hpp
test_module/src/test.S

index 913772a967c4d4a49874bfd74bfc0dfed561f9a6..b0e4274535870c67fbe6ca0f34c975c97aabeb41 100644 (file)
@@ -20,16 +20,28 @@ ftl_to_userspace:
        mov $0x202, %r11 # EFLAGS
        sysretq
 
+.globl load_tss
+load_tss:
+       mov $GDT.TSS, %ax
+       ltr %ax
+       ret
+
 .globl syscall_64bit_handler
 syscall_64bit_handler:
        push %rcx
        mov %r10, %rcx
-       call syscall_64bit_handler_cpp
+       cmp $syscall_n, %rax
+       jae incorrect_syscall
+       callq *syscalls_call_table(, %rax, 8)
+       pop %rcx
+       sysretq
+incorrect_syscall:
+       call syscall_rax_error_handler
        pop %rcx
        sysretq
 
-.globl load_tss
-load_tss:
-       mov $GDT.TSS, %ax
-       ltr %ax
-       ret
+.section .rodata
+syscalls_call_table:
+       .quad syscall_print
+       .quad syscall_println
+.set syscall_n, 2
index d4eccbd0c6b1a138754f410fb9fc770d2145ab69..9cddf88c8b4811d5aeec2d59bdf7999ebe6d674b 100644 (file)
@@ -19,8 +19,6 @@ void os::set_ring0_stack(os::tss& tss, std::uint64_t stack) {
        tss.rsp0 = stack;
 }
 
-extern "C" void syscall_64bit_handler();
-
 void os::enable_syscalls() {
        // Enable bit 0 (SYSCALL Enable) of msr IA32_EFER.
        // This is required to enable syscall/sysret on x86_64 intel.
@@ -35,6 +33,15 @@ void os::enable_syscalls() {
        os::set_msr(0xC0000084, 0x00000000); // syscall flag mask, we don't want to change the flags for now.
 }
 
-extern "C" void syscall_64bit_handler_cpp(std::uint64_t v) {
-       os::printc((char)v);
+extern "C" void syscall_print(char v) {
+       os::printc(v);
+}
+
+extern "C" void syscall_println(char v) {
+       os::printc(v);
+       os::printc('\n');
+}
+
+extern "C" void syscall_rax_error_handler() {
+       os::assert(false, "Incorrect %rax for syscall.");
 }
index c1fc2e26286bd2f9bfb1da0fe4a700f904f9ee1c..54077c927f5b9e1c62efa51969a129bc2456ee6b 100644 (file)
@@ -35,9 +35,15 @@ struct __attribute__((packed)) tss {
        std::uint16_t iopb;
 };
 
-void set_ring0_stack(tss& tss, std::uint64_t stack);
+extern "C" void ftl_to_userspace(void* program, std::byte* stack);
 extern "C" void load_tss();
+extern "C" void syscall_64bit_handler();
+
+extern "C" void syscall_print(char c);
+extern "C" void syscall_println(char c);
+extern "C" void syscall_rax_error_handler();
+
+void set_ring0_stack(tss& tss, std::uint64_t stack);
 void enable_syscalls();
-extern "C" void ftl_to_userspace(void* program, std::byte* stack);
 
 } // namespace os
index 293166196ee23913f85b6e60e8fc820091f8cf93..1815f3d35ec60151d19d04a0ca4802225d64348c 100644 (file)
@@ -15,5 +15,6 @@
 
 .globl print
 print:
+       mov $0, %rax
        syscall
        ret