From b12d582d4dd805e63972f6a9c8612518d8635889 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 13 Jan 2021 10:48:01 -0700 Subject: [PATCH 1/4] WIP: aarch64 --- src/arch/aarch64.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/arch/aarch64.rs b/src/arch/aarch64.rs index 23abe49..7ca4f8b 100644 --- a/src/arch/aarch64.rs +++ b/src/arch/aarch64.rs @@ -1,3 +1,6 @@ +use core::{mem, slice}; +use core::ops::{Deref, DerefMut}; + use super::error::{Error, Result}; pub unsafe fn syscall0(mut a: usize) -> Result { @@ -60,3 +63,47 @@ pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: Error::demux(a) } + +//TODO +#[derive(Copy, Clone, Debug, Default)] +#[repr(C)] +pub struct IntRegisters; + +impl Deref for IntRegisters { + type Target = [u8]; + fn deref(&self) -> &[u8] { + unsafe { + slice::from_raw_parts(self as *const IntRegisters as *const u8, mem::size_of::()) + } + } +} + +impl DerefMut for IntRegisters { + fn deref_mut(&mut self) -> &mut [u8] { + unsafe { + slice::from_raw_parts_mut(self as *mut IntRegisters as *mut u8, mem::size_of::()) + } + } +} + +//TODO +#[derive(Clone, Copy, Debug, Default)] +#[repr(packed)] +pub struct FloatRegisters; + +impl Deref for FloatRegisters { + type Target = [u8]; + fn deref(&self) -> &[u8] { + unsafe { + slice::from_raw_parts(self as *const FloatRegisters as *const u8, mem::size_of::()) + } + } +} + +impl DerefMut for FloatRegisters { + fn deref_mut(&mut self) -> &mut [u8] { + unsafe { + slice::from_raw_parts_mut(self as *mut FloatRegisters as *mut u8, mem::size_of::()) + } + } +} -- GitLab From 3029f094a49711ae70f50e0aa25beb894d65885c Mon Sep 17 00:00:00 2001 From: Robin Randhawa Date: Tue, 26 Jan 2021 18:28:41 +0000 Subject: [PATCH 2/4] aarch64: Cleanups and alignment with x86_64 macros --- src/arch/aarch64.rs | 84 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 82 insertions(+), 2 deletions(-) diff --git a/src/arch/aarch64.rs b/src/arch/aarch64.rs index 7ca4f8b..0a6c0db 100644 --- a/src/arch/aarch64.rs +++ b/src/arch/aarch64.rs @@ -3,6 +3,47 @@ use core::ops::{Deref, DerefMut}; use super::error::{Error, Result}; +macro_rules! syscall { + ($($name:ident($a:ident, $($b:ident, $($c:ident, $($d:ident, $($e:ident, $($f:ident, )?)?)?)?)?);)+) => { + $( + pub unsafe fn $name(mut $a: usize, $(mut $b: usize, $($c: usize, $($d: usize, $($e: usize, $($f: usize)?)?)?)?)?) -> Result { + asm!( + "svc 0", + in("x8") $a, + $( + inout("x0") $b, + $( + in("x1") $c, + $( + in("x2") $d, + $( + in("x3") $e, + $( + in("x4") $f, + )? + )? + )? + )? + )? + options(nostack), + ); + + Error::demux($a) + } + )+ + }; +} + +syscall! { + syscall0(a,); + syscall1(a, b,); + syscall2(a, b, c,); + syscall3(a, b, c, d,); + syscall4(a, b, c, d, e,); + syscall5(a, b, c, d, e, f,); +} + +/* pub unsafe fn syscall0(mut a: usize) -> Result { llvm_asm!("svc 0" : "={x0}"(a) @@ -63,11 +104,50 @@ pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: Error::demux(a) } +*/ -//TODO #[derive(Copy, Clone, Debug, Default)] #[repr(C)] -pub struct IntRegisters; +pub struct IntRegisters { + pub elr_el1: usize, + pub tpidr_el0: usize, + pub tpidrro_el0: usize, + pub spsr_el1: usize, + pub esr_el1: usize, + pub sp_el0: usize, // Shouldn't be used if interrupt occurred at EL1 + pub padding: usize, // To keep the struct even number aligned + pub x30: usize, + pub x29: usize, + pub x28: usize, + pub x27: usize, + pub x26: usize, + pub x25: usize, + pub x24: usize, + pub x23: usize, + pub x22: usize, + pub x21: usize, + pub x20: usize, + pub x19: usize, + pub x18: usize, + pub x17: usize, + pub x16: usize, + pub x15: usize, + pub x14: usize, + pub x13: usize, + pub x12: usize, + pub x11: usize, + pub x10: usize, + pub x9: usize, + pub x8: usize, + pub x7: usize, + pub x6: usize, + pub x5: usize, + pub x4: usize, + pub x3: usize, + pub x2: usize, + pub x1: usize, + pub x0: usize +} impl Deref for IntRegisters { type Target = [u8]; -- GitLab From 21cf9e31fc04805682caf5bda4162a45f41b2b83 Mon Sep 17 00:00:00 2001 From: Robin Randhawa Date: Wed, 27 Jan 2021 17:20:33 +0000 Subject: [PATCH 3/4] aarch64: Remove vestiges of old syscallX functions Now that they have been replaced by the more modern macro magic versions. --- src/arch/aarch64.rs | 63 --------------------------------------------- 1 file changed, 63 deletions(-) diff --git a/src/arch/aarch64.rs b/src/arch/aarch64.rs index 0a6c0db..4bb346e 100644 --- a/src/arch/aarch64.rs +++ b/src/arch/aarch64.rs @@ -43,69 +43,6 @@ syscall! { syscall5(a, b, c, d, e, f,); } -/* -pub unsafe fn syscall0(mut a: usize) -> Result { - llvm_asm!("svc 0" - : "={x0}"(a) - : "{x8}"(a) - : "x0", "x8" - : "volatile"); - - Error::demux(a) -} - -pub unsafe fn syscall1(mut a: usize, b: usize) -> Result { - llvm_asm!("svc 0" - : "={x0}"(a) - : "{x8}"(a), "{x0}"(b) - : "x0", "x8" - : "volatile"); - - Error::demux(a) -} - -pub unsafe fn syscall2(mut a: usize, b: usize, c: usize) -> Result { - llvm_asm!("svc 0" - : "={x0}"(a) - : "{x8}"(a), "{x0}"(b), "{x1}"(c) - : "x0", "x1", "x8" - : "volatile"); - - Error::demux(a) -} - -pub unsafe fn syscall3(mut a: usize, b: usize, c: usize, d: usize) -> Result { - llvm_asm!("svc 0" - : "={x0}"(a) - : "{x8}"(a), "{x0}"(b), "{x1}"(c), "{x2}"(d) - : "x0", "x1", "x2", "x8" - : "volatile"); - - Error::demux(a) -} - -pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Result { - llvm_asm!("svc 0" - : "={x0}"(a) - : "{x8}"(a), "{x0}"(b), "{x1}"(c), "{x2}"(d), "{x3}"(e) - : "x0", "x1", "x2", "x3", "x8" - : "volatile"); - - Error::demux(a) -} - -pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) - -> Result { - llvm_asm!("svc 0" - : "={x0}"(a) - : "{x8}"(a), "{x0}"(b), "{x1}"(c), "{x2}"(d), "{x3}"(e), "{x4}"(f) - : "x0", "x1", "x2", "x3", "x4", "x8" - : "volatile"); - - Error::demux(a) -} -*/ - #[derive(Copy, Clone, Debug, Default)] #[repr(C)] pub struct IntRegisters { -- GitLab From beb880b706c74ceb2d749ff9d0196079cfb7e53e Mon Sep 17 00:00:00 2001 From: Robin Randhawa Date: Wed, 27 Jan 2021 17:21:22 +0000 Subject: [PATCH 4/4] aarch64: Basic Floating point/SIMD definition --- src/arch/aarch64.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/arch/aarch64.rs b/src/arch/aarch64.rs index 4bb346e..60e2238 100644 --- a/src/arch/aarch64.rs +++ b/src/arch/aarch64.rs @@ -103,10 +103,13 @@ impl DerefMut for IntRegisters { } } -//TODO #[derive(Clone, Copy, Debug, Default)] #[repr(packed)] -pub struct FloatRegisters; +pub struct FloatRegisters { + pub fp_simd_regs: [u128; 32], + pub fpsr: u32, + pub fpcr: u32 +} impl Deref for FloatRegisters { type Target = [u8]; -- GitLab