Kernel: Rework scheduler/processor stacks.

This commit is contained in:
2024-04-02 12:34:42 +03:00
parent 5050047cef
commit 2106a9e373
7 changed files with 94 additions and 64 deletions

View File

@@ -4,40 +4,31 @@ read_ip:
popl %eax
jmp *%eax
# void start_thread(uint32_t sp, uint32_t ip)
.global start_thread
start_thread:
movl 8(%esp), %edi # ip
movl 4(%esp), %esp # sp
# void start_kernel_thread()
.global start_kernel_thread
start_kernel_thread:
call get_start_kernel_thread_sp
movl %eax, %esp
# STACK LAYOUT
# NULL
# thread ptr
# &Thread::on_exit
# data
# on_exit arg
# on_exit func
# entry arg
# entry func
xorl %ebp, %ebp
movl 4(%esp), %edi
movl 0(%esp), %esi
subl $12, %esp
pushl %edi
sti
call *%edi
call *%esi
addl $16, %esp
movl 4(%esp), %edi # &Thread::on_exit
movl 12(%esp), %edi
movl 8(%esp), %esi
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:
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
thread_userspace_trampoline:
ud2
subl $12, %esp
pushl %edi
call *%esi
addl $16, %esp

View File

@@ -26,17 +26,31 @@ isr_stub:
irq_stub:
pusha
leal 40(%esp), %eax // interrupt stack ptr
movl 32(%esp), %ebx // irq number
movl 32(%esp), %eax # interrupt number
subl $8, %esp
pushl %eax
call cpp_irq_handler
addl $12, %esp
popa
addl $8, %esp
iret
.global asm_reschedule_handler
asm_reschedule_handler:
pusha
movl %esp, %eax # interrupt registers ptr
leal 32(%esp), %ebx # interrupt stack ptr
subl $12, %esp
pushl %eax
pushl %ebx
call cpp_irq_handler
call cpp_reschedule_handler
addl $20, %esp
popa
addl $8, %esp
iret
// arguments in EAX, EBX, ECX, EDX, ESI, EDI
@@ -158,4 +172,3 @@ irq 28
irq 29
irq 30
irq 31
irq 32

View File

@@ -4,9 +4,12 @@ read_ip:
popq %rax
jmp *%rax
# void start_thread()
# void start_kernel_thread()
.global start_kernel_thread
start_kernel_thread:
call get_start_kernel_thread_sp
movq %rax, %rsp
# STACK LAYOUT
# on_exit arg
# on_exit func
@@ -15,6 +18,7 @@ start_kernel_thread:
movq 8(%rsp), %rdi
movq 0(%rsp), %rsi
sti
call *%rsi
movq 24(%rsp), %rdi