kernel: Add sleep_task

This commit is contained in:
Ry 2023-10-11 16:29:18 -07:00
parent c2960e8fd7
commit d61c54d985
3 changed files with 23 additions and 0 deletions

View File

@ -20,6 +20,7 @@ get_current_task_id: jmp [0x00000A1C]
get_unused_task_id: jmp [0x00000A20]
is_task_id_used: jmp [0x00000A24]
save_state_and_yield_task: jmp [0x00000A28]
sleep_task: jmp [0x00000A2C]
; memory jump table
allocate_memory: jmp [0x00000B10]

View File

@ -42,6 +42,7 @@ jump_table:
data.32 get_unused_task_id
data.32 is_task_id_used
data.32 save_state_and_yield_task
data.32 sleep_task
; memory jump table
org.pad 0x00000310

View File

@ -122,6 +122,27 @@ save_state_and_yield_task:
pop rfp
ret
; yield for at least the specified number of ms
; inputs:
; r0: minimum ms to yield for
; outputs:
; none
sleep_task:
push r0
push r1
in r1, 0x80000706
add r0, r1
sleep_task_loop:
call save_state_and_yield_task
in r1, 0x80000706
cmp r1, r0
iflt jmp sleep_task_loop
pop r1
pop r0
ret
; switch to the next task without adding the current task back into the queue
; this will automatically free the task's code and stack blocks
; inputs: