thread: add kthreads

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-08-12 22:03:52 -04:00
commit 54803ed29b
Signed by: michaelsshaw
GPG key ID: 5A5E0FB20708A9E7
6 changed files with 79 additions and 36 deletions

View file

@ -142,24 +142,16 @@ sched_restore_state:
pop_all
ret
.global thread_wait
thread_wait:
.global reschedule
reschedule:
push_all
mov rax, qword ptr gs:[24] /* cur_thread */
mov [rax + 8], rsp /* save rsp to kstack_ptr */
mov qword ptr [rax + 32], 1 /* state = PROC_STATE_WAITING */
call sched_add_thread /* re-add to run queue */
call schedule
/* not reached */
.global thread_block
thread_block:
push_all
mov rax, qword ptr gs:[24] /* cur_thread */
mov [rax + 8], rsp /* save rsp to kstack_ptr */
mov qword ptr [rax + 32], 3 /* state = PROC_STATE_BLOCKED */
call schedule
/* not reached */
mov rax, gs:[0]
mov [rax + 8], rsp
mov [rax + 40], rdi
cmp rdi, 3
je 1f
call sched_add_thread
1: call schedule
.global _syscall_enter
_syscall_enter:
@ -215,6 +207,14 @@ fork_trampoline:
swapgs
sysretq
/* kthread entry: rdi=arg, rdx=fn */
/* argument are pre-set before the thread execution begins */
.global kthread_entry
kthread_entry:
call rdx
mov edi, 4
call reschedule
/* unreachable */
/* exceptions */
exception 0x00