kernel/arch/
mod.rs

1//! Architecture-specific code for Scarlet kernel
2//!
3//! This module contains architecture-specific implementations and definitions
4//! for the Scarlet kernel. Each architecture has its own set of files that
5//! implement the necessary functionality.
6//!
7
8/// Policy for whether user-mode should run with IRQs enabled immediately after
9/// returning from the kernel (e.g. `sret`/`eret`).
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum UserReturnIrqPolicy {
12    /// Do not change the interrupt state; honor the trapframe/arch default.
13    Inherit,
14    /// Ensure IRQs are enabled right after returning to user mode.
15    Enable,
16    /// Ensure IRQs are disabled right after returning to user mode.
17    Disable,
18}
19
20/// Options applied right before returning to user mode.
21#[derive(Debug, Clone, Copy, PartialEq, Eq)]
22pub struct UserEntryOptions {
23    pub irq_policy: UserReturnIrqPolicy,
24}
25
26impl Default for UserEntryOptions {
27    fn default() -> Self {
28        Self {
29            irq_policy: UserReturnIrqPolicy::Inherit,
30        }
31    }
32}
33
34/// Configure architecture-specific state for the upcoming return to user mode.
35///
36/// This is intended to be called immediately before the final trampoline/exit
37/// jump that performs `sret`/`eret`.
38pub fn configure_user_entry(trapframe: &mut Trapframe, options: UserEntryOptions) {
39    #[cfg(target_arch = "riscv64")]
40    {
41        riscv64::configure_user_entry(trapframe, options)
42    }
43    #[cfg(target_arch = "aarch64")]
44    {
45        aarch64::configure_user_entry(trapframe, options)
46    }
47}
48
49pub mod user_context;
50
51pub use user_context::{
52    init_from_fdt as init_user_context_from_fdt, user_fpu_enabled, user_vector_enabled,
53};
54
55#[cfg(target_arch = "riscv64")]
56pub mod riscv64;
57#[cfg(target_arch = "riscv64")]
58pub use riscv64::*;
59
60#[cfg(target_arch = "aarch64")]
61pub mod aarch64;
62#[cfg(target_arch = "aarch64")]
63pub use aarch64::*;
64
65// Re-export kernel context for architecture-independent use
66#[cfg(target_arch = "riscv64")]
67pub use riscv64::context::KernelContext;
68
69#[cfg(target_arch = "aarch64")]
70pub use aarch64::context::KernelContext;
71
72// Re-export FPU context and functions for architecture-independent use
73#[cfg(target_arch = "riscv64")]
74pub use riscv64::fpu;
75
76#[cfg(target_arch = "aarch64")]
77pub use aarch64::fpu;