forked from Bananymous/banan-os
Kernel: Improve multithreading support
We can now use arbitary BAN::function<void(...)> as the Thread. I also implemented multithreading for i386 since it was not done on the initial multithreading commit.
This commit is contained in:
38
kernel/arch/i386/Thread.S
Normal file
38
kernel/arch/i386/Thread.S
Normal file
@@ -0,0 +1,38 @@
|
||||
# uint32_t read_rip()
|
||||
.global read_rip
|
||||
read_rip:
|
||||
popl %eax
|
||||
jmp *%eax
|
||||
|
||||
exit_thread_trampoline:
|
||||
addl $16, %esp
|
||||
popl %eax
|
||||
pushl $0x696969
|
||||
pushl %eax
|
||||
ret
|
||||
|
||||
# void start_thread(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t rsp, uint32_t rbp, uint32_t rip)
|
||||
.global start_thread
|
||||
start_thread:
|
||||
movl %esp, %eax
|
||||
movl 28(%eax), %ecx
|
||||
movl 24(%eax), %ebp
|
||||
movl 20(%eax), %esp
|
||||
|
||||
pushl 16(%eax)
|
||||
pushl 12(%eax)
|
||||
pushl 8(%eax)
|
||||
pushl 4(%eax)
|
||||
pushl $exit_thread_trampoline
|
||||
|
||||
sti
|
||||
jmp *%ecx
|
||||
|
||||
# void continue_thread(uint32_t rsp, uint32_t rbp, uint32_t rip)
|
||||
.global continue_thread
|
||||
continue_thread:
|
||||
movl 12(%esp), %ecx
|
||||
movl 8(%esp), %ebp
|
||||
movl 4(%esp), %esp
|
||||
movl $0, %eax
|
||||
jmp *%ecx
|
||||
@@ -8,4 +8,5 @@ $(ARCHDIR)/boot.o \
|
||||
$(ARCHDIR)/IDT.o \
|
||||
$(ARCHDIR)/MMU.o \
|
||||
$(ARCHDIR)/SpinLock.o \
|
||||
$(ARCHDIR)/Thread.o \
|
||||
|
||||
32
kernel/arch/x86_64/Thread.S
Normal file
32
kernel/arch/x86_64/Thread.S
Normal file
@@ -0,0 +1,32 @@
|
||||
# uint64_t read_rip()
|
||||
.global read_rip
|
||||
read_rip:
|
||||
popq %rax
|
||||
jmp *%rax
|
||||
|
||||
.global get_thread_at_exit
|
||||
get_thread_at_exit:
|
||||
movq 8(%rdi), %rax
|
||||
ret
|
||||
|
||||
exit_thread_trampoline:
|
||||
movq 8(%rsp), %rdi
|
||||
ret
|
||||
|
||||
# void start_thread(uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t rsp, uint64_t rbp, uint64_t rip)
|
||||
.global start_thread
|
||||
start_thread:
|
||||
movq 8(%rsp), %rcx
|
||||
movq %r8, %rsp
|
||||
movq %r9, %rbp
|
||||
pushq $exit_thread_trampoline
|
||||
sti
|
||||
jmp *%rcx
|
||||
|
||||
# void continue_thread(uint64_t rsp, uint64_t rbp, uint64_t rip)
|
||||
.global continue_thread
|
||||
continue_thread:
|
||||
movq %rdi, %rsp
|
||||
movq %rsi, %rbp
|
||||
movq $0, %rax
|
||||
jmp *%rdx
|
||||
@@ -9,4 +9,5 @@ $(ARCHDIR)/IDT.o \
|
||||
$(ARCHDIR)/interrupts.o \
|
||||
$(ARCHDIR)/MMU.o \
|
||||
$(ARCHDIR)/SpinLock.o \
|
||||
$(ARCHDIR)/Thread.o \
|
||||
|
||||
Reference in New Issue
Block a user