From 484bb4b02c5dc6ed952d45235b2fe999b645da00 Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Wed, 28 Feb 2024 23:45:23 +0000 Subject: [PATCH] crates/sel4: Improve types Signed-off-by: Nick Spinale --- crates/examples/root-task/spawn-thread/src/main.rs | 2 +- crates/sel4-capdl-initializer/core/src/arch/mod.rs | 6 +++--- crates/sel4/src/arch/arm/arch/aarch32/user_context.rs | 4 ++-- crates/sel4/src/arch/arm/arch/aarch64/user_context.rs | 4 ++-- crates/sel4/src/arch/riscv/user_context.rs | 4 ++-- crates/sel4/src/arch/x86/arch/x64/user_context.rs | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/examples/root-task/spawn-thread/src/main.rs b/crates/examples/root-task/spawn-thread/src/main.rs index a6a4866fd..a4c2bf887 100644 --- a/crates/examples/root-task/spawn-thread/src/main.rs +++ b/crates/examples/root-task/spawn-thread/src/main.rs @@ -119,7 +119,7 @@ fn create_user_context(f: SecondaryThreadFn) -> sel4::UserContext { ctx } -fn user_context_arg_mut(ctx: &mut sel4::UserContext, i: sel4::Word) -> &mut sel4::Word { +fn user_context_arg_mut(ctx: &mut sel4::UserContext, i: usize) -> &mut sel4::Word { cfg_if! { if #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] { ctx.gpr_a_mut(i) diff --git a/crates/sel4-capdl-initializer/core/src/arch/mod.rs b/crates/sel4-capdl-initializer/core/src/arch/mod.rs index a33521bd6..ba0492aab 100644 --- a/crates/sel4-capdl-initializer/core/src/arch/mod.rs +++ b/crates/sel4-capdl-initializer/core/src/arch/mod.rs @@ -37,7 +37,7 @@ mod imp { *regs.pc_mut() = extra.ip; *regs.sp_mut() = extra.sp; for (i, value) in extra.gprs.iter().enumerate() { - *regs.gpr_mut(i.try_into().unwrap()) = *value; + *regs.gpr_mut(i) = *value; } } } @@ -69,7 +69,7 @@ mod imp { *regs.pc_mut() = extra.ip; *regs.sp_mut() = extra.sp; for (i, value) in extra.gprs.iter().enumerate() { - *regs.gpr_a_mut(i.try_into().unwrap()) = *value; + *regs.gpr_a_mut(i) = *value; } } } @@ -115,7 +115,7 @@ mod imp { *regs.pc_mut() = extra.ip; *regs.sp_mut() = extra.sp; for (i, value) in extra.gprs.iter().enumerate() { - *regs.gpr_mut(i.try_into().unwrap()) = *value; + *regs.gpr_mut(i) = *value; } } } diff --git a/crates/sel4/src/arch/arm/arch/aarch32/user_context.rs b/crates/sel4/src/arch/arm/arch/aarch32/user_context.rs index b3ab9d527..f96610665 100644 --- a/crates/sel4/src/arch/arm/arch/aarch32/user_context.rs +++ b/crates/sel4/src/arch/arm/arch/aarch32/user_context.rs @@ -37,7 +37,7 @@ impl UserContext { &mut self.0.cpsr } - pub fn gpr(&self, ix: Word) -> &Word { + pub fn gpr(&self, ix: usize) -> &Word { match ix { 0 => &self.inner().r0, 1 => &self.inner().r1, @@ -57,7 +57,7 @@ impl UserContext { } } - pub fn gpr_mut(&mut self, ix: Word) -> &mut Word { + pub fn gpr_mut(&mut self, ix: usize) -> &mut Word { match ix { 0 => &mut self.inner_mut().r0, 1 => &mut self.inner_mut().r1, diff --git a/crates/sel4/src/arch/arm/arch/aarch64/user_context.rs b/crates/sel4/src/arch/arm/arch/aarch64/user_context.rs index 3f6b0ed15..46be13acd 100644 --- a/crates/sel4/src/arch/arm/arch/aarch64/user_context.rs +++ b/crates/sel4/src/arch/arm/arch/aarch64/user_context.rs @@ -38,7 +38,7 @@ impl UserContext { &mut self.0.spsr } - pub fn gpr(&self, ix: Word) -> &Word { + pub fn gpr(&self, ix: usize) -> &Word { match ix { 0 => &self.inner().x0, 1 => &self.inner().x1, @@ -75,7 +75,7 @@ impl UserContext { } } - pub fn gpr_mut(&mut self, ix: Word) -> &mut Word { + pub fn gpr_mut(&mut self, ix: usize) -> &mut Word { match ix { 0 => &mut self.inner_mut().x0, 1 => &mut self.inner_mut().x1, diff --git a/crates/sel4/src/arch/riscv/user_context.rs b/crates/sel4/src/arch/riscv/user_context.rs index 1c0c9da39..a02694420 100644 --- a/crates/sel4/src/arch/riscv/user_context.rs +++ b/crates/sel4/src/arch/riscv/user_context.rs @@ -29,7 +29,7 @@ impl UserContext { &mut self.0.sp } - pub fn gpr_a(&self, ix: Word) -> &Word { + pub fn gpr_a(&self, ix: usize) -> &Word { match ix { 0 => &self.inner().a0, 1 => &self.inner().a1, @@ -43,7 +43,7 @@ impl UserContext { } } - pub fn gpr_a_mut(&mut self, ix: Word) -> &mut Word { + pub fn gpr_a_mut(&mut self, ix: usize) -> &mut Word { match ix { 0 => &mut self.inner_mut().a0, 1 => &mut self.inner_mut().a1, diff --git a/crates/sel4/src/arch/x86/arch/x64/user_context.rs b/crates/sel4/src/arch/x86/arch/x64/user_context.rs index 543139a2a..7dc5b4be5 100644 --- a/crates/sel4/src/arch/x86/arch/x64/user_context.rs +++ b/crates/sel4/src/arch/x86/arch/x64/user_context.rs @@ -28,7 +28,7 @@ impl UserContext { &mut self.0.rsp } - pub fn gpr(&self, ix: Word) -> &Word { + pub fn gpr(&self, ix: usize) -> &Word { // TODO match ix { 0 => &self.inner().rdi, @@ -41,7 +41,7 @@ impl UserContext { } } - pub fn gpr_mut(&mut self, ix: Word) -> &mut Word { + pub fn gpr_mut(&mut self, ix: usize) -> &mut Word { match ix { 0 => &mut self.inner_mut().rdi, 1 => &mut self.inner_mut().rsi,