From d8354f40d1e45330d651a25b51a4c65044783a47 Mon Sep 17 00:00:00 2001 From: Fritz Stracke Date: Tue, 29 Jul 2025 15:15:40 +0200 Subject: [PATCH] feat: add stackpointer registers for EL2 and EL3 Signed-off-by: Fritz Stracke --- src/registers.rs | 4 ++++ src/registers/sp_el2.rs | 36 ++++++++++++++++++++++++++++++++++++ src/registers/sp_el3.rs | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 src/registers/sp_el2.rs create mode 100644 src/registers/sp_el3.rs diff --git a/src/registers.rs b/src/registers.rs index c4cf57f..1a26f7e 100644 --- a/src/registers.rs +++ b/src/registers.rs @@ -114,6 +114,8 @@ mod sctlr_el3; mod sp; mod sp_el0; mod sp_el1; +mod sp_el2; +mod sp_el3; mod spsel; mod spsr_el1; mod spsr_el2; @@ -242,6 +244,8 @@ pub use sctlr_el3::SCTLR_EL3; pub use sp::SP; pub use sp_el0::SP_EL0; pub use sp_el1::SP_EL1; +pub use sp_el2::SP_EL2; +pub use sp_el3::SP_EL3; pub use spsel::SPSel; pub use spsr_el1::SPSR_EL1; pub use spsr_el2::SPSR_EL2; diff --git a/src/registers/sp_el2.rs b/src/registers/sp_el2.rs new file mode 100644 index 0000000..4de4cee --- /dev/null +++ b/src/registers/sp_el2.rs @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: Apache-2.0 OR MIT +// +// Copyright (c) 2018-2023 by the author(s) +// +// Author(s): +// - Fritz Stracke + +//! The stack pointer - EL2 +//! +//! Holds the stack pointer associated with EL2. When executing at EL2, the value of SPSel.SP +//! determines the current stack pointer: +//! +//! SPSel.SP | current stack pointer +//! -------------------------------- +//! 0 | SP_EL0 +//! 1 | SP_EL2 + +use tock_registers::interfaces::{Readable, Writeable}; + +pub struct Reg; + +impl Readable for Reg { + type T = u64; + type R = (); + + sys_coproc_read_raw!(u64, "SP_EL2", "x"); +} + +impl Writeable for Reg { + type T = u64; + type R = (); + + sys_coproc_write_raw!(u64, "SP_EL2", "x"); +} + +pub const SP_EL2: Reg = Reg {}; diff --git a/src/registers/sp_el3.rs b/src/registers/sp_el3.rs new file mode 100644 index 0000000..33b9ec9 --- /dev/null +++ b/src/registers/sp_el3.rs @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: Apache-2.0 OR MIT +// +// Copyright (c) 2018-2023 by the author(s) +// +// Author(s): +// - Fritz Stracke + +//! The stack pointer - EL3 +//! +//! Holds the stack pointer associated with EL3. When executing at EL3, the value of SPSel.SP +//! determines the current stack pointer: +//! +//! SPSel.SP | current stack pointer +//! -------------------------------- +//! 0 | SP_EL0 +//! 1 | SP_EL3 + +use tock_registers::interfaces::{Readable, Writeable}; + +pub struct Reg; + +impl Readable for Reg { + type T = u64; + type R = (); + + sys_coproc_read_raw!(u64, "SP_EL3", "x"); +} + +impl Writeable for Reg { + type T = u64; + type R = (); + + sys_coproc_write_raw!(u64, "SP_EL3", "x"); +} + +pub const SP_EL3: Reg = Reg {};