From 035da8e4499b0ef3b0417b3bbf9bd82c566ea220 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 25 Nov 2024 22:26:16 +0100 Subject: kernel: Don't tamper the 'ra' register on switch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As part of a shameful hack I was tampering with the 'ra' register as well as with the 'sepc' CSR. Since in the end we just assume 'sret' is in place at the end, let's be cleaner and leave 'ra' alone. Signed-off-by: Miquel Sabaté Solà --- include/fbos/sched.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/fbos/sched.h b/include/fbos/sched.h index 3d35f9f..00f3e70 100644 --- a/include/fbos/sched.h +++ b/include/fbos/sched.h @@ -33,9 +33,10 @@ extern struct task_struct tasks[4]; __kernel __always_inline void switch_to(int task_id) { asm volatile("csrc sstatus, %0\n\t" - "mv ra, %1\n\t" - "csrw sepc, ra" ::"r"(1 << 8), - "r"(tasks[task_id].entry_addr)); + "mv t0, %1\n\t" + "csrw sepc, t0" ::"r"(1 << 8), + "r"(tasks[task_id].entry_addr) + : "t0"); } #endif // __FBOS_SCHED_H_ -- cgit v1.2.3