Skip to content

Commit

Permalink
kernel: use MachineRegister for register contents
Browse files Browse the repository at this point in the history
These data types in Tock have no semantic meaning other than they are
exactly the size of a register. To express that in code we use the
MachineRegister type.
  • Loading branch information
bradjc committed Nov 25, 2024
1 parent 31013aa commit 01e0c33
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion kernel/src/grant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ use crate::processbuffer::{ReadOnlyProcessBuffer, ReadWriteProcessBuffer};
use crate::processbuffer::{ReadOnlyProcessBufferRef, ReadWriteProcessBufferRef};
use crate::upcall::{Upcall, UpcallError, UpcallId};
use crate::utilities::capability_ptr::CapabilityPtr;
use crate::utilities::machine_register::MachineRegister;
use crate::ErrorCode;

/// Tracks how many upcalls a grant instance supports automatically.
Expand Down Expand Up @@ -708,7 +709,7 @@ impl<'a> GrantKernelData<'a> {
#[repr(C)]
#[derive(Default)]
struct SavedUpcall {
appdata: CapabilityPtr,
appdata: MachineRegister,
fn_ptr: CapabilityPtr,
}

Expand Down
3 changes: 2 additions & 1 deletion kernel/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::storage_permissions;
use crate::syscall::{self, Syscall, SyscallReturn};
use crate::upcall::UpcallId;
use crate::utilities::capability_ptr::CapabilityPtr;
use crate::utilities::machine_register::MachineRegister;
use tock_tbf::types::CommandPermissions;

// Export all process related types via `kernel::process::`.
Expand Down Expand Up @@ -1084,7 +1085,7 @@ pub struct FunctionCall {
/// The third argument to the function.
pub argument2: usize,
/// The userdata provided by the process via `subscribe`
pub argument3: CapabilityPtr,
pub argument3: MachineRegister,
/// The PC of the function to execute.
pub pc: CapabilityPtr,
}
Expand Down
9 changes: 5 additions & 4 deletions kernel/src/syscall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ use core::fmt::Write;
use crate::errorcode::ErrorCode;
use crate::process;
use crate::utilities::capability_ptr::CapabilityPtr;
use crate::utilities::machine_register::MachineRegister;

pub use crate::syscall_driver::{CommandReturn, SyscallDriver};

Expand Down Expand Up @@ -158,7 +159,7 @@ pub enum Syscall {
/// Upcall pointer to the upcall function.
upcall_ptr: CapabilityPtr,
/// Userspace application data.
appdata: CapabilityPtr,
appdata: MachineRegister,
},

/// Structure representing an invocation of the Command system call class.
Expand Down Expand Up @@ -241,9 +242,9 @@ impl Syscall {
pub fn from_register_arguments(
syscall_number: u8,
r0: usize,
r1: CapabilityPtr,
r2: CapabilityPtr,
r3: CapabilityPtr,
r1: MachineRegister,
r2: MachineRegister,
r3: MachineRegister,
) -> Option<Syscall> {
match SyscallClass::try_from(syscall_number) {
Ok(SyscallClass::Yield) => Some(Syscall::Yield {
Expand Down
5 changes: 3 additions & 2 deletions kernel/src/upcall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::process;
use crate::process::ProcessId;
use crate::syscall::SyscallReturn;
use crate::utilities::capability_ptr::CapabilityPtr;
use crate::utilities::machine_register::MachineRegister;
use crate::ErrorCode;

/// Type to uniquely identify an upcall subscription across all drivers.
Expand Down Expand Up @@ -82,7 +83,7 @@ pub(crate) struct Upcall {
pub(crate) upcall_id: UpcallId,

/// The application data passed by the app when `subscribe()` was called.
pub(crate) appdata: CapabilityPtr,
pub(crate) appdata: MachineRegister,

/// A pointer to the first instruction of the function in the app that
/// corresponds to this upcall.
Expand All @@ -97,7 +98,7 @@ impl Upcall {
pub(crate) fn new(
process_id: ProcessId,
upcall_id: UpcallId,
appdata: CapabilityPtr,
appdata: MachineRegister,
fn_ptr: CapabilityPtr,
) -> Upcall {
Upcall {
Expand Down

0 comments on commit 01e0c33

Please sign in to comment.