From a24291b462094d8d50ab8b20972227fc5332405c Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Mon, 30 Jan 2023 21:49:24 +0800 Subject: [PATCH] xous: use `asm!()` macro for syscalls Previously we used externally-linked assembly in order to make syscalls. Now that `asm!()` is stable, use this macro. This will help to optimize IPC between programs and the kernel. Additionally, it resolves an unsoundness issue where we were filling in values on the stack and hoping that Rust didn't reorder the structs. Signed-off-by: Sean Cross --- xous-rs/src/arch/riscv/syscall.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/xous-rs/src/arch/riscv/syscall.rs b/xous-rs/src/arch/riscv/syscall.rs index 91227d1a5..49f5ca240 100644 --- a/xous-rs/src/arch/riscv/syscall.rs +++ b/xous-rs/src/arch/riscv/syscall.rs @@ -16,14 +16,21 @@ use crate::definitions::SysCallResult; use crate::syscall::SysCall; pub fn syscall(call: SysCall) -> SysCallResult { - let mut ret = crate::Result::Ok; - let args = call.as_args(); + let mut args = call.as_args(); unsafe { - _xous_syscall( - args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], &mut ret, + core::arch::asm!( + "ecall", + inlateout("a0") args[0], + inlateout("a1") args[1], + inlateout("a2") args[2], + inlateout("a3") args[3], + inlateout("a4") args[4], + inlateout("a5") args[5], + inlateout("a6") args[6], + inlateout("a7") args[7], ) }; - match ret { + match crate::definitions::Result::from_args(args) { crate::Result::Error(e) => Err(e), other => Ok(other), }