From 01e0c337c6408b6f44430ea72c485388dd9590e2 Mon Sep 17 00:00:00 2001 From: Brad Campbell Date: Fri, 22 Nov 2024 14:02:02 -0500 Subject: [PATCH] kernel: use MachineRegister for register contents 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. --- kernel/src/grant.rs | 3 ++- kernel/src/process.rs | 3 ++- kernel/src/syscall.rs | 9 +++++---- kernel/src/upcall.rs | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/kernel/src/grant.rs b/kernel/src/grant.rs index d8522d9b5c..5696f189c8 100644 --- a/kernel/src/grant.rs +++ b/kernel/src/grant.rs @@ -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. @@ -708,7 +709,7 @@ impl<'a> GrantKernelData<'a> { #[repr(C)] #[derive(Default)] struct SavedUpcall { - appdata: CapabilityPtr, + appdata: MachineRegister, fn_ptr: CapabilityPtr, } diff --git a/kernel/src/process.rs b/kernel/src/process.rs index 3509fa7946..6d29446f3e 100644 --- a/kernel/src/process.rs +++ b/kernel/src/process.rs @@ -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::`. @@ -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, } diff --git a/kernel/src/syscall.rs b/kernel/src/syscall.rs index 97d84a3ca1..9b8844b920 100644 --- a/kernel/src/syscall.rs +++ b/kernel/src/syscall.rs @@ -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}; @@ -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. @@ -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 { match SyscallClass::try_from(syscall_number) { Ok(SyscallClass::Yield) => Some(Syscall::Yield { diff --git a/kernel/src/upcall.rs b/kernel/src/upcall.rs index 213f06aa25..a0eac5ed25 100644 --- a/kernel/src/upcall.rs +++ b/kernel/src/upcall.rs @@ -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. @@ -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. @@ -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 {