diff --git a/fox32os.def b/fox32os.def index 1df5b2b..28828a0 100644 --- a/fox32os.def +++ b/fox32os.def @@ -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] diff --git a/kernel/main.asm b/kernel/main.asm index e49937c..7aa2dd0 100644 --- a/kernel/main.asm +++ b/kernel/main.asm @@ -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 diff --git a/kernel/task.asm b/kernel/task.asm index 378b8fa..4c531f3 100644 --- a/kernel/task.asm +++ b/kernel/task.asm @@ -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: