Architectural Support: x86_64 (#37)
[lunaix-os.git] / lunaix-os / usr / libc / arch / x86_64 / trampoline.S
diff --git a/lunaix-os/usr/libc/arch/x86_64/trampoline.S b/lunaix-os/usr/libc/arch/x86_64/trampoline.S
new file mode 100644 (file)
index 0000000..86bdfd1
--- /dev/null
@@ -0,0 +1,36 @@
+#include <lunaix/syscallid.h>
+
+.section .text
+    /*
+    stack structure:
+
+        ...saved_state  \
+        void* sighand;   > struct siguctx
+        void* sigact;   /
+        int sig_num;    <--- %rsp
+    */
+    .global sigtrampoline
+    sigtrampoline:
+        movq %rsp, %rax
+        andq $-16, %rsp
+        pushq %rax
+        
+        movl (%rax), %edi      // signum
+        xorq %rsi, %rsi        // siginfo = NULL
+        leaq 4(%rax), %rdx     // (struct siguctx*)&sigact
+        call sig_dohandling
+        
+        movq $__SYSCALL_sigreturn, %rax
+        popq %rbx
+        int $33
+    
+    .global th_trampoline
+    th_trampoline:
+        movq (%rsp), %rax
+        movq 8(%rsp), %rdi
+
+        callq %rax
+
+        movq %rax, %rbx
+        movq $__SYSCALL_th_exit, %rax
+        int $33
\ No newline at end of file