kernel: add thread_wait, thread_block and mtx

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-08-12 14:59:34 -04:00
commit 9c50a1df92
Signed by: michaelsshaw
GPG key ID: 5A5E0FB20708A9E7
6 changed files with 49 additions and 3 deletions

View file

@ -138,9 +138,28 @@ _timer_handler:
.global sched_restore_state
sched_restore_state:
mov rsp, [rdi + 8] /* load RSP from thread->kstack_ptr */
pop_all
ret
mov rsp, [rdi + 8] /* load RSP from thread->kstack_ptr */
pop_all
ret
.global thread_wait
thread_wait:
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 */
.global _syscall_enter
_syscall_enter: