diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-05-02 23:31:46 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-05-02 23:31:46 +0800 |
| commit | 6907a90418ba856ff9331e6b4ba5d26b76034c2d (patch) | |
| tree | 420223afa8d8c9f4e0fab945ff01fea58a7d219a /na/arch/riscv/trap | |
| parent | 1146a45ccbbbf514787eba6082e7acbbbe8e81b8 (diff) | |
| download | lume-6907a90418ba856ff9331e6b4ba5d26b76034c2d.tar.gz lume-6907a90418ba856ff9331e6b4ba5d26b76034c2d.tar.xz | |
feat: add RISC-V configuration and memory management enhancements
Co-authored-by: Copilot <copilot@github.com>
Diffstat (limited to 'na/arch/riscv/trap')
| -rw-r--r-- | na/arch/riscv/trap/swtch.S | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/na/arch/riscv/trap/swtch.S b/na/arch/riscv/trap/swtch.S index 4393505..8be7904 100644 --- a/na/arch/riscv/trap/swtch.S +++ b/na/arch/riscv/trap/swtch.S @@ -1,11 +1,28 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ /* Copyright (C) 2026 Richard Qin */ +/* + * Context Switch & Kernel Thread Trampoline (RISC-V 64) + * + * context_switch: saves/restores callee-saved registers. + * kthread_entry_trampoline: entry point for newly created kernel threads. + * After context_switch loads the new Context, execution lands here via + * Context.ra = kthread_entry_trampoline. The entry function and argument + * are in s0 and s1 respectively, set by sched_init/create_tcb. + * + * The trampoline calls the MI-layer kthread_entry(entry, arg). + * + * Reference: docs/specs/scheduler.md ยง6 + */ + .section .text + +/* ======================================================================== + * void context_switch(Context* old_ctx, Context* next_ctx); + * a0 = old_ctx_ptr, a1 = next_ctx_ptr + * ======================================================================== */ .globl context_switch .align 2 -# void context_switch(Context* old_ctx, Context* next_ctx); -# a0 = old_ctx_ptr, a1 = next_ctx_ptr context_switch: sd ra, 0(a0) sd sp, 8(a0) @@ -37,4 +54,26 @@ context_switch: ld s10, 96(a1) ld s11, 104(a1) - ret
\ No newline at end of file + ret + +/* ======================================================================== + * kthread_entry_trampoline + * + * Reached via context_switch when a new kthread is first scheduled. + * Context was set up by create_tcb(): + * s0 = entry function pointer + * s1 = argument pointer + * + * Calls the MI-layer C++ function: + * void kthread_entry(void (*entry)(void*), void* arg); + * ======================================================================== */ + .globl kthread_entry_trampoline + .align 2 +kthread_entry_trampoline: + mv a0, s0 /* a0 = entry function */ + mv a1, s1 /* a1 = argument */ + call kthread_entry /* MI-layer C++ function */ + + /* kthread_entry should never return, but if it does: */ + wfi + j kthread_entry_trampoline + 12 /* loop on wfi */
\ No newline at end of file |
