Skip to content

Commit

Permalink
kernel: utilities: add MachineRegister
Browse files Browse the repository at this point in the history
MachineRegister is a data type that represents exactly what can be
stored in a hardware-specific register. It has no additional semantic
information.
  • Loading branch information
bradjc committed Nov 22, 2024
1 parent 50f36b3 commit 31013aa
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions kernel/src/utilities/machine_register.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed under the Apache License, Version 2.0 or the MIT License.
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright Tock Contributors 2024.

//! Machine-specific register-sized type.
//!
//! This type holds exactly one machine register of data. This type should be
//! used when storing a value that is exactly the contents of a register with no
//! additional type information.
//!
//! Tock defines this as a custom type as there is currently (Nov 2024) no
//! suitable standard type for this purpose that is correct across all hardware
//! architectures Tock supports. The closest suitable type is `usize`. However,
//! `usize` only captures the size of data, not necessarily the full size of a
//! register. On many platforms these are the same, but on platforms with
//! ISA-level memory protection (e.g., CHERI), a register is larger than
//! `usize`.
use crate::utilities::capability_ptr::CapabilityPtr;

/// [`MachineRegister`] is a datatype that can hold exactly the contents of a
/// register with no additional semantic information.
///
/// We can define this as a [`CapabilityPtr`] as [`CapabilityPtr`] has the same
/// size.
///
/// [`MachineRegister`] is useful for identifying when data within the Tock
/// kernel has no semantic meaning other than being the size of a register. In
/// the future it may be possible, useful, or necessary to change the
/// implementation of [`MachineRegister`], however, the semantics will remain.
/// To reduce implementation complexity we simply use a type alias, but this
/// should not be construed as to suggest that [`MachineRegister`] will always
/// be implemented as a [`CapabilityPtr`].
pub type MachineRegister = CapabilityPtr;
1 change: 1 addition & 0 deletions kernel/src/utilities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod capability_ptr;
pub mod copy_slice;
pub mod helpers;
pub mod leasable_buffer;
pub mod machine_register;
pub mod math;
pub mod mut_imut_buffer;
pub mod peripheral_management;
Expand Down

0 comments on commit 31013aa

Please sign in to comment.