22
33#include " drivers/driver_commands.hpp"
44#include " nrf52833.h"
5- #include " scheduler/pending_process_callbacks.hpp"
65#include " scheduler/mpu.hpp"
6+ #include " scheduler/pending_process_callbacks.hpp"
7+ #include " userlib/system_call_type.hpp"
78#include " util.hpp"
89
910namespace edge {
@@ -22,6 +23,7 @@ void Scheduler::start_scheduler()
2223
2324 NVIC_SetPriority (PendSV_IRQn, 0x3 );
2425 NVIC_SetPriority (SysTick_IRQn, 0x1 );
26+
2527 MpuController::get ().initialize_mpu ();
2628 asm volatile (" CPSIE I" );
2729 asm volatile (" SVC #0" );
@@ -115,24 +117,12 @@ __attribute__((used)) void SysTick_Handler()
115117// I don't think there's any way to make this cleaner lol
116118__attribute__ ((used, naked)) USER_CODE void restore_regs ()
117119{
118- // Load fpscr first so we can avoid dirtying r0 after its popped
119- asm volatile (" ldr r0, [sp, #96]\n "
120- " vmsr fpscr, r0\n " );
121-
122- // Pop regs as usual
123- asm volatile (" pop {r0, r1, r2, r3, r12, lr}" );
124-
125- // Skip SP and RETPSR. SP will be loaded last
126- // RETPSR should be ignored because we already popped when returning from exception
127- asm volatile (" add sp, #8" );
128-
129- // Pop caller saved FP registers
130- asm volatile (" vpop {s0-s15}" );
131-
132- // Skip FPSCR and 2 reserved regs
133- asm volatile (" add sp, #12" );
120+ asm volatile (" svc %0" ::" I" (SystemCallType::RESTORE_REGS));
121+ }
134122
135- asm volatile (" ldr pc, [sp, #-84]" );
123+ void Scheduler::restore_current_task_regs (exception_stack_registers* regs)
124+ {
125+ __set_PSP (reinterpret_cast <unsigned >(®s[1 ]) + 4 );
136126}
137127
138128void Scheduler::yield_current_task ()
0 commit comments