1 use core::{mem, slice}; 2 use core::ops::{Deref, DerefMut}; 3 4 use super::error::{Error, Result}; 5 6 macro_rules! syscall { 7 ($($name:ident($a:ident, $($b:ident, $($c:ident, $($d:ident, $($e:ident, $($f:ident, )?)?)?)?)?);)+) => { 8 $( 9 pub unsafe fn $name($a: usize, $($b: usize, $($c: usize, $($d: usize, $($e: usize, $($f: usize)?)?)?)?)?) -> Result<usize> { 10 let ret: usize; 11 12 asm!( 13 "ecall", 14 in("a7") $a, 15 $( 16 in("a0") $b, 17 $( 18 in("a1") $c, 19 $( 20 in("a2") $d, 21 $( 22 in("a3") $e, 23 $( 24 in("a4") $f, 25 )? 26 )? 27 )? 28 )? 29 )? 30 lateout("a0") ret, 31 options(nostack), 32 ); 33 34 Error::demux(ret) 35 } 36 )+ 37 }; 38 } 39 40 syscall! { 41 syscall0(a,); 42 syscall1(a, b,); 43 syscall2(a, b, c,); 44 syscall3(a, b, c, d,); 45 syscall4(a, b, c, d, e,); 46 syscall5(a, b, c, d, e, f,); 47 } 48 49 #[derive(Copy, Clone, Debug, Default)] 50 #[repr(C)] 51 pub struct IntRegisters { 52 //TODO 53 } 54 55 impl Deref for IntRegisters { 56 type Target = [u8]; deref(&self) -> &[u8]57 fn deref(&self) -> &[u8] { 58 unsafe { 59 slice::from_raw_parts(self as *const IntRegisters as *const u8, mem::size_of::<IntRegisters>()) 60 } 61 } 62 } 63 64 impl DerefMut for IntRegisters { deref_mut(&mut self) -> &mut [u8]65 fn deref_mut(&mut self) -> &mut [u8] { 66 unsafe { 67 slice::from_raw_parts_mut(self as *mut IntRegisters as *mut u8, mem::size_of::<IntRegisters>()) 68 } 69 } 70 } 71 72 #[derive(Clone, Copy, Debug, Default)] 73 #[repr(packed)] 74 pub struct FloatRegisters { 75 //TODO 76 } 77 78 impl Deref for FloatRegisters { 79 type Target = [u8]; deref(&self) -> &[u8]80 fn deref(&self) -> &[u8] { 81 unsafe { 82 slice::from_raw_parts(self as *const FloatRegisters as *const u8, mem::size_of::<FloatRegisters>()) 83 } 84 } 85 } 86 87 impl DerefMut for FloatRegisters { deref_mut(&mut self) -> &mut [u8]88 fn deref_mut(&mut self) -> &mut [u8] { 89 unsafe { 90 slice::from_raw_parts_mut(self as *mut FloatRegisters as *mut u8, mem::size_of::<FloatRegisters>()) 91 } 92 } 93 } 94