@@ -141,11 +141,30 @@ This "red zone" is reserved at the top of every task stack to guarantee ISR safe
141141Standard RISC-V calling convention applies:
142142
143143```c
144- /* Example: mo_task_spawn(entry, stack_size, mode) */
145- /* a0 = entry, a1 = stack_size, a2 = mode, return value in a0 */
146- int32_t result = mo_task_spawn(task_function, 2048, TASK_MODE_M);
144+ /* Application API - the only interface apps should use: */
145+ int32_t result = mo_task_spawn(task_function, 2048);
147146```
148147
148+ The `mo_task_spawn()` macro routes automatically based on build configuration:
149+ - `CONFIG_PRIVILEGED`: Direct kernel call → M-mode task
150+ - Otherwise: Syscall (`sys_task_spawn()`) → U-mode task
151+
152+ **Internal Architecture** (kernel developers only):
153+
154+ The implementation uses two internal functions declared in `include/private/task.h`:
155+ - `mo_task_spawn_kernel()`: Creates M-mode tasks (used by logger.c)
156+ - ` mo_task_spawn_user() ` : Creates U-mode tasks (used by main.c, syscall.c)
157+
158+ These are not exposed to applications. The public header only exposes the
159+ ` mo_task_spawn() ` macro, which provides the correct behavior transparently.
160+
161+ ** Security Model** :
162+ - ` mo_task_spawn_kernel() ` : Protected by defense-in-depth:
163+ - Runtime check rejects calls from syscall context (returns -1)
164+ - Hardware protection: CRITICAL_ENTER traps if called from U-mode
165+ - ` mo_task_spawn_user() ` : No privilege restrictions (creates restricted tasks)
166+ - ` mo_task_spawn() ` : Safe for applications - routes to appropriate implementation
167+
149168### System Call Interface
150169
151170Linmo provides system calls through the RISC-V trap mechanism for privilege
0 commit comments