Sfoglia il codice sorgente

hal: remove struct TaskContext from riscv64

Commit cc4c9378f47b ("hal: remove dependency of TaskContext for
TrapContext") has removed all usages of TaskContext. Remove this struct
completely.

We don't care about loongarch64 at all so keep it there... x86 will pick
this soon.

Signed-off-by: greatbridf <greatbridf@icloud.com>
greatbridf 1 settimana fa
parent
commit
1f9d2468f6

+ 0 - 41
crates/eonix_hal/eonix_hal_traits/src/context.rs

@@ -1,41 +0,0 @@
-#[doc(notable_trait)]
-pub trait RawTaskContext: Sized {
-    /// Creates a new instance of the task context with interrupt enabled and the program
-    /// counter and stack pointer set to zero (a.k.a. some invalid state).
-    ///
-    /// Using the created context without setting the program counter and stack pointer
-    /// will result in undefined behavior.
-    fn new() -> Self;
-
-    fn set_program_counter(&mut self, pc: usize);
-    fn set_stack_pointer(&mut self, sp: usize);
-
-    fn is_interrupt_enabled(&self) -> bool;
-    fn set_interrupt_enabled(&mut self, is_enabled: bool);
-
-    /// Sets the instruction pointer to the given function and prepares the context
-    /// to call it with the given argument.
-    fn call(&mut self, func: unsafe extern "C" fn(usize) -> !, arg: usize);
-
-    /// Switch the execution context from `from` to `to`.
-    ///
-    /// # Safety
-    /// This function is unsafe because it performs a context switch, which can lead to
-    /// undefined behavior if the contexts are not properly set up.
-    unsafe extern "C" fn switch(from: &mut Self, to: &mut Self);
-
-    /// Switches the execution context to `to` where we will not return.
-    ///
-    /// # Safety
-    /// This function is unsafe because it performs a context switch that does not return.
-    /// The caller must ensure that the `to` context is properly set up and that it will not
-    /// return to the caller.
-    unsafe extern "C" fn switch_to_noreturn(to: &mut Self) -> ! {
-        let mut from_ctx = Self::new();
-        unsafe {
-            Self::switch(&mut from_ctx, to);
-        }
-
-        unreachable!("We should never return from `switch_to_noreturn()`");
-    }
-}

+ 0 - 1
crates/eonix_hal/eonix_hal_traits/src/lib.rs

@@ -1,7 +1,6 @@
 #![no_std]
 #![feature(doc_notable_trait)]
 
-pub mod context;
 pub mod fault;
 pub mod fpu;
 pub mod mm;

+ 0 - 111
crates/eonix_hal/src/arch/riscv64/context.rs

@@ -1,111 +0,0 @@
-use core::arch::naked_asm;
-use eonix_hal_traits::context::RawTaskContext;
-use riscv::register::sstatus::Sstatus;
-
-#[repr(C)]
-#[derive(Debug)]
-pub struct TaskContext {
-    // s0-11
-    s: [u64; 12],
-    sp: u64,
-    ra: u64,
-    sstatus: Sstatus,
-}
-
-impl RawTaskContext for TaskContext {
-    fn new() -> Self {
-        Self::new()
-    }
-
-    fn set_program_counter(&mut self, pc: usize) {
-        self.ra = pc as u64;
-    }
-
-    fn set_stack_pointer(&mut self, sp: usize) {
-        self.sp = sp as u64;
-    }
-
-    fn is_interrupt_enabled(&self) -> bool {
-        self.sstatus.sie()
-    }
-
-    fn set_interrupt_enabled(&mut self, is_enabled: bool) {
-        self.sstatus.set_sie(is_enabled);
-    }
-
-    fn call(&mut self, func: unsafe extern "C" fn(usize) -> !, arg: usize) {
-        self.s[0] = func as u64;
-        self.s[1] = arg as u64;
-
-        self.set_program_counter(Self::do_call as usize);
-    }
-
-    #[unsafe(naked)]
-    unsafe extern "C" fn switch(from: &mut Self, to: &mut Self) {
-        // Input arguments `from` and `to` will be in `a0` (x10) and `a1` (x11).
-        naked_asm!(
-            // Save current task's callee-saved registers to `from` context
-            "sd   s0, 0(a0)",
-            "sd   s1, 8(a0)",
-            "sd   s2, 16(a0)",
-            "sd   s3, 24(a0)",
-            "sd   s4, 32(a0)",
-            "sd   s5, 40(a0)",
-            "sd   s6, 48(a0)",
-            "sd   s7, 56(a0)",
-            "sd   s8, 64(a0)",
-            "sd   s9, 72(a0)",
-            "sd  s10, 80(a0)",
-            "sd  s11, 88(a0)",
-            "sd   sp, 96(a0)",
-            "sd   ra, 104(a0)",
-            "csrr t0, sstatus",
-            "sd   t0, 112(a0)",
-            "",
-            "ld   s0, 0(a1)",
-            "ld   s1, 8(a1)",
-            "ld   s2, 16(a1)",
-            "ld   s3, 24(a1)",
-            "ld   s4, 32(a1)",
-            "ld   s5, 40(a1)",
-            "ld   s6, 48(a1)",
-            "ld   s7, 56(a1)",
-            "ld   s8, 64(a1)",
-            "ld   s9, 72(a1)",
-            "ld  s10, 80(a1)",
-            "ld  s11, 88(a1)",
-            "ld   sp, 96(a1)",
-            "ld   ra, 104(a1)",
-            "ld   t0, 112(a1)",
-            "csrw sstatus, t0",
-            "ret",
-        );
-    }
-}
-
-impl TaskContext {
-    pub const fn new() -> Self {
-        Self {
-            s: [0; 12],
-            sp: 0,
-            ra: 0,
-            sstatus: Sstatus::from_bits((1 << 13) | (1 << 18)), // FS = Initial, SUM = 1.
-        }
-    }
-
-    #[unsafe(naked)]
-    /// Maximum of 5 arguments supported.
-    unsafe extern "C" fn do_call() -> ! {
-        naked_asm!(
-            "mv   t0, s0", // Function pointer in s0.
-            "mv   a0, s1", // Args
-            "mv   a1, s2",
-            "mv   a2, s3",
-            "mv   a3, s4",
-            "mv   a4, s5",
-            "mv   fp, zero", // Set frame pointer to 0.
-            "mv   ra, zero",
-            "jr   t0",
-        );
-    }
-}

+ 1 - 2
crates/eonix_hal/src/arch/riscv64/mod.rs

@@ -1,12 +1,11 @@
 pub mod bootstrap;
 mod config;
 pub mod console;
-pub mod context;
 pub mod cpu;
 pub mod fdt;
 pub mod fence;
 pub mod fpu;
 pub mod interrupt;
 pub mod mm;
-pub mod trap;
 pub mod time;
+pub mod trap;

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

@@ -9,7 +9,6 @@ use core::ptr::NonNull;
 
 use captured::{_captured_trap_entry, _captured_trap_return};
 use default::_default_trap_entry;
-use eonix_hal_traits::context::RawTaskContext;
 use eonix_hal_traits::trap::{IrqState as IrqStateTrait, TrapReturn};
 use riscv::asm::sfence_vma_all;
 use riscv::register::sstatus::{self, Sstatus};

+ 0 - 1
crates/eonix_hal/src/context.rs

@@ -1 +0,0 @@
-pub use crate::arch::context::TaskContext;

+ 0 - 1
crates/eonix_hal/src/lib.rs

@@ -6,7 +6,6 @@
 pub(crate) mod arch;
 
 pub mod bootstrap;
-pub mod context;
 pub mod mm;
 pub mod trap;