Przeglądaj źródła

riscv64, trap: remove load_interrupt_stack impl

This is used only by Thread when we enter user execution context, when
we need to save the "interrupt stack" to the local CPU so we can get the
information needed to capture the trap.

We need to support nested captured trap returns. So instead of setting
that manually, we save the needed information when trap_return() is
called (since we have precisely the trap context needed) and restore it
after the trap is captured.

Signed-off-by: greatbridf <greatbridf@icloud.com>
greatbridf 6 miesięcy temu
rodzic
commit
3ab454f6df

+ 1 - 5
crates/eonix_hal/src/arch/riscv64/cpu.rs

@@ -59,11 +59,7 @@ impl CPU {
         sscratch::write(TRAP_SCRATCH.as_ptr() as usize);
     }
 
-    pub unsafe fn load_interrupt_stack(self: Pin<&mut Self>, sp: u64) {
-        TRAP_SCRATCH
-            .as_mut()
-            .set_trap_context(NonNull::new(sp as *mut _).unwrap());
-    }
+    pub unsafe fn load_interrupt_stack(self: Pin<&mut Self>, sp: u64) {}
 
     pub fn set_tls32(self: Pin<&mut Self>, _user_tls: &UserTLS) {
         // nothing

+ 8 - 0
crates/eonix_hal/src/arch/riscv64/trap/mod.rs

@@ -283,9 +283,15 @@ impl TrapReturn for TrapContext {
 
     unsafe fn trap_return(&mut self) {
         let irq_states = disable_irqs_save();
+
         let old_handler =
             core::mem::replace(&mut TRAP_SCRATCH.as_mut().handler, captured_trap_handler);
 
+        let old_trap_context = core::mem::replace(
+            &mut TRAP_SCRATCH.as_mut().trap_context,
+            Some(NonNull::from(&mut *self)),
+        );
+
         let mut to_ctx = TaskContext::new();
         to_ctx.set_program_counter(captured_trap_return as usize);
         to_ctx.set_stack_pointer(&raw mut *self as usize);
@@ -296,6 +302,8 @@ impl TrapReturn for TrapContext {
         }
 
         TRAP_SCRATCH.as_mut().handler = old_handler;
+        TRAP_SCRATCH.as_mut().trap_context = old_trap_context;
+
         irq_states.restore();
     }
 }

+ 0 - 8
src/kernel/task/thread.rs

@@ -429,14 +429,6 @@ impl Thread {
                     me.load_thread_area32();
                 }
 
-                unsafe {
-                    let trap_ctx_ptr: *const TrapContext = &raw const *me.trap_ctx.borrow();
-                    // SAFETY:
-                    CPU::local()
-                        .as_mut()
-                        .load_interrupt_stack(trap_ctx_ptr as u64);
-                }
-
                 let irq_state = disable_irqs_save();
 
                 let result = future.as_mut().poll(cx);