Kernel: Implement syscalls for i686 and cleanup x86_64

This actually allows i686 to boot properly!
This commit is contained in:
2024-04-03 02:23:23 +03:00
parent 9e073e9fa0
commit 0dd74e3c9d
8 changed files with 120 additions and 48 deletions

View File

@@ -1,19 +1,31 @@
.global sys_fork_trampoline
sys_fork_trampoline:
ud2
subl $4, %esp
pushl %ebx
pushl %ebp
pushl %ebx
pushl %esi
pushl %edi
call read_ip
testl %eax, %eax
je .done
jz .reload_stack
movl %esp, %ebx
subl $8, %esp
pushl %eax
pushl %esp
pushl %ebx
call sys_fork
addl $16, %esp
.done:
popl %ebp
.done:
popl %edi
popl %esi
popl %ebx
addl $4, %esp
popl %ebp
ret
.reload_stack:
call get_thread_start_sp
movl %eax, %esp
xorl %eax, %eax
jmp .done

View File

@@ -7,7 +7,7 @@ read_ip:
# void start_kernel_thread()
.global start_kernel_thread
start_kernel_thread:
call get_start_kernel_thread_sp
call get_thread_start_sp
movl %eax, %esp
# STACK LAYOUT
@@ -32,3 +32,37 @@ start_kernel_thread:
pushl %edi
call *%esi
addl $16, %esp
.global start_userspace_thread
start_userspace_thread:
call get_thread_start_sp
movl %eax, %esp
# STACK LAYOUT
# entry
# argc
# argv
# envp
# userspace stack
call get_userspace_thread_stack_top
movw $(0x20 | 3), %bx
movw %bx, %ds
movw %bx, %es
movw %bx, %fs
movw %bx, %gs
xorw %bx, %bx
popl %edx
popl %esi
popl %edi
popl %ecx
pushl $(0x20 | 3)
pushl %eax
pushl $0x202
pushl $(0x18 | 3)
pushl %ecx
iret

View File

@@ -24,6 +24,22 @@
popw %gs
.endm
.macro pop_userspace_skip_eax
popl %edi
popl %esi
popl %ebp
addl $4, %esp
popl %ebx
popl %edx
popl %ecx
addl $4, %esp
popw %ds
popw %es
popw %fs
popw %gs
.endm
isr_stub:
push_userspace
load_kernel_segments
@@ -85,11 +101,12 @@ asm_reschedule_handler:
// arguments in EAX, EBX, ECX, EDX, ESI, EDI
.global syscall_asm
syscall_asm:
ud2
pusha
push_userspace
subl $8, %esp
pushl %esp
addl $36, (%esp)
addl $48, (%esp)
pushl %edi
pushl %esi
@@ -98,19 +115,12 @@ syscall_asm:
pushl %ebx
pushl %eax
load_kernel_segments
call cpp_syscall_handler
addl $36, %esp
addl $60, %esp
popl %edi
popl %esi
popl %ebp
addl $4, %esp
popl %ebx
popl %edx
popl %ecx
addl $4, %esp
pop_userspace_skip_eax
iret
.macro isr n

View File

@@ -6,13 +6,16 @@ sys_fork_trampoline:
pushq %r13
pushq %r14
pushq %r15
call read_ip
testq %rax, %rax
je .done
je .reload_stack
movq %rax, %rsi
movq %rsp, %rdi
call sys_fork
.done:
.done:
popq %r15
popq %r14
popq %r13
@@ -20,3 +23,9 @@ sys_fork_trampoline:
popq %rbp
popq %rbx
ret
.reload_stack:
call get_thread_start_sp
movq %rax, %rsp
xorq %rax, %rax
jmp .done

View File

@@ -7,7 +7,7 @@ read_ip:
# void start_kernel_thread()
.global start_kernel_thread
start_kernel_thread:
call get_start_kernel_thread_sp
call get_thread_start_sp
movq %rax, %rsp
# STACK LAYOUT
@@ -27,7 +27,7 @@ start_kernel_thread:
.global start_userspace_thread
start_userspace_thread:
call get_start_kernel_thread_sp
call get_thread_start_sp
movq %rax, %rsp
# STACK LAYOUT