From 96babec22afe328dc35d681ae9a929ff16b9e1e9 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 26 Mar 2024 19:42:14 +0200 Subject: [PATCH] Kernel: Implement Thread trampolines for x86_32 --- kernel/arch/i686/Thread.S | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/kernel/arch/i686/Thread.S b/kernel/arch/i686/Thread.S index d0b6a04f..42fc4400 100644 --- a/kernel/arch/i686/Thread.S +++ b/kernel/arch/i686/Thread.S @@ -7,12 +7,35 @@ read_ip: # void start_thread(uint32_t sp, uint32_t ip) .global start_thread start_thread: - ud2 + movl 8(%esp), %edi # ip + movl 4(%esp), %esp # sp + + # STACK LAYOUT + # NULL + # thread ptr + # &Thread::on_exit + # data + + xorl %ebp, %ebp + + sti + call *%edi + + movl 4(%esp), %edi # &Thread::on_exit + + movl 8(%esp), %eax # thread ptr + movl %eax, (%esp) + + call *%edi + # void continue_thread(uint32_t sp, uint32_t ip) .global continue_thread continue_thread: - ud2 + movl 8(%esp), %edi # ip + movl 4(%esp), %esp # sp + xorl %eax, %eax + jmp *%edi # void thread_userspace_trampoline(uint32_t sp, uint32_t ip, int argc, char** argv, char** envp) .global thread_userspace_trampoline