@@ -109,13 +109,14 @@ void hal_context_restore(jmp_buf env, int32_t val); /* Restore context + process
109109The ISR in ` boot.c ` performs a complete context save of all registers:
110110
111111```
112- Stack Frame Layout (128 bytes, offsets from sp):
112+ Stack Frame Layout (144 bytes, 33 words × 4 bytes, offsets from sp):
113113 0: ra, 4: gp, 8: tp, 12: t0, 16: t1, 20: t2
114- 24: s0, 28: s1, 32: a0, 36: a1, 40: a2, 44: a3
114+ 24: s0, 28: s1, 32: a0, 36: a1, 40: a2, 44: a3
115115 48: a4, 52: a5, 56: a6, 60: a7, 64: s2, 68: s3
116116 72: s4, 76: s5, 80: s6, 84: s7, 88: s8, 92: s9
117117 96: s10, 100:s11, 104:t3, 108: t4, 112: t5, 116: t6
118- 120: mcause, 124: mepc
118+ 120: mcause, 124: mepc, 128: mstatus
119+ 132-143: padding (12 bytes for 16-byte alignment)
119120```
120121
121122Why full context save in ISR?
@@ -128,7 +129,7 @@ Why full context save in ISR?
128129
129130Each task stack must reserve space for the ISR frame:
130131``` c
131- #define ISR_STACK_FRAME_SIZE 128 /* 32 registers × 4 bytes * /
132+ #define ISR_STACK_FRAME_SIZE 144 /* 33 words × 4 bytes, 16-byte aligned * /
132133```
133134
134135This "red zone" is reserved at the top of every task stack to guarantee ISR safety.
@@ -147,10 +148,20 @@ int32_t result = mo_task_spawn(task_function, 2048);
147148
148149### System Call Interface
149150
150- Linmo uses standard function calls (not trap instructions) for system services:
151- - Arguments passed in ` a0-a7 ` registers
152- - Return values in ` a0 `
153- - No special calling convention required
151+ Linmo provides system calls through the RISC-V trap mechanism for privilege
152+ boundary crossing. User mode tasks invoke system calls using the environment
153+ call instruction, which triggers a synchronous exception handled by the kernel.
154+
155+ System call convention:
156+ - Arguments passed in `a0-a7` registers before trap
157+ - System call number in `a7` register
158+ - Trap handler preserves all registers except return value
159+ - Return value delivered in `a0` register after trap return
160+ - Standard RISC-V calling convention maintained across privilege boundary
161+
162+ The trap-based interface allows user mode tasks to safely access kernel
163+ services without requiring privileged instruction execution. The kernel
164+ validates all parameters and mediates access to protected resources.
154165
155166### Task Entry Points
156167
@@ -174,9 +185,9 @@ Each task has its own stack with this layout:
174185
175186```
176187High Address
177- +------------------+ <- stack_base + stack_size
178- | ISR Red Zone | <- 128 bytes reserved for ISR
179- | (128 bytes) |
188+ +------------------+ <- stack_base + stack_size
189+ | ISR Red Zone | <- 144 bytes reserved for ISR
190+ | (144 bytes) |
180191+------------------+ <- Initial SP (16-byte aligned)
181192| |
182193| Task Stack | <- Grows downward
@@ -251,8 +262,8 @@ Minimal context (jmp_buf):
251262- 17 × 32-bit loads/stores = 68 bytes
252263- Essential for cooperative scheduling
253264
254- Full context (ISR):
255- - 32 × 32-bit loads/stores = 128 bytes
265+ Full context (ISR):
266+ - 33 × 32-bit loads/stores = 144 bytes (includes padding for alignment)
256267- Required for preemptive interrupts
257268
258269### Function Call Overhead
0 commit comments