Commit a7d066a3 authored by Jeremy Soller's avatar Jeremy Soller

Merge branch 'idiomatic-rust' into 'master'

Replace llvm_asm in x86_64 code with asm

See merge request !56
parents a0ea09ce 7f668b27
Pipeline #8169 failed with stages
in 52 seconds
......@@ -20,21 +20,6 @@ pub unsafe fn syscall1(mut a: usize, b: usize) -> Result<usize> {
Error::demux(a)
}
// Clobbers all registers - special for clone
pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result<usize> {
llvm_asm!("svc 0"
: "={x0}"(a)
: "{x8}"(a), "{x0}"(b)
: "memory",
"x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
"x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
"x16", "x17","x18", "x19", "x20", "x21", "x22", "x23",
"x24", "x25", "x26", "x27", "x28", "x29", "x30"
: "volatile");
Error::demux(a)
}
pub unsafe fn syscall2(mut a: usize, b: usize, c: usize) -> Result<usize> {
llvm_asm!("svc 0"
: "={x0}"(a)
......
......@@ -20,17 +20,6 @@ pub unsafe fn syscall1(mut a: usize, b: usize) -> Result<usize> {
Error::demux(a)
}
// Clobbers all registers - special for clone
pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result<usize> {
llvm_asm!("swi $$0"
: "={r0}"(a)
: "{r7}"(a), "{r0}"(b)
: "memory", "r0", "r1", "r2", "r3", "r4"
: "volatile");
Error::demux(a)
}
pub unsafe fn syscall2(mut a: usize, b: usize, c: usize) -> Result<usize> {
llvm_asm!("swi $$0"
: "={r0}"(a)
......
......@@ -8,11 +8,6 @@ pub unsafe fn syscall1(_a: usize, _b: usize) -> Result<usize> {
Err(Error::new(ENOSYS))
}
// Clobbers all registers - special for clone
pub unsafe fn syscall1_clobber(_a: usize, _b: usize) -> Result<usize> {
Err(Error::new(ENOSYS))
}
pub unsafe fn syscall2(_a: usize, _b: usize, _c: usize) -> Result<usize> {
Err(Error::new(ENOSYS))
}
......
......@@ -20,17 +20,6 @@ pub unsafe fn syscall1(mut a: usize, b: usize) -> Result<usize> {
Error::demux(a)
}
// Clobbers all registers - special for clone
pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result<usize> {
llvm_asm!("int 0x80"
: "={eax}"(a)
: "{eax}"(a), "{ebx}"(b)
: "memory", "ebx", "ecx", "edx", "esi", "edi"
: "intel", "volatile");
Error::demux(a)
}
pub unsafe fn syscall2(mut a: usize, b: usize, c: usize) -> Result<usize> {
llvm_asm!("int 0x80"
: "={eax}"(a)
......
use super::error::{Error, Result};
pub unsafe fn syscall0(mut a: usize) -> Result<usize> {
llvm_asm!("syscall"
: "={rax}"(a)
: "{rax}"(a)
: "rcx", "r11", "memory"
: "intel", "volatile");
Error::demux(a)
macro_rules! syscall {
($($name:ident($a:ident, $($b:ident, $($c:ident, $($d:ident, $($e:ident, $($f:ident, )?)?)?)?)?);)+) => {
$(
pub unsafe fn $name(mut $a: usize, $($b: usize, $($c: usize, $($d: usize, $($e: usize, $($f: usize)?)?)?)?)?) -> Result<usize> {
asm!(
"syscall",
inout("rax") $a,
$(
in("rdi") $b,
$(
in("rsi") $c,
$(
in("rdx") $d,
$(
in("r10") $e,
$(
in("r8") $f,
)?
)?
)?
)?
)?
out("rcx") _,
out("r11") _,
options(nostack),
);
Error::demux($a)
}
)+
};
}
pub unsafe fn syscall1(mut a: usize, b: usize) -> Result<usize> {
llvm_asm!("syscall"
: "={rax}"(a)
: "{rax}"(a), "{rdi}"(b)
: "rcx", "r11", "memory"
: "intel", "volatile");
Error::demux(a)
}
// Clobbers all registers - special for clone
pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result<usize> {
llvm_asm!("syscall"
: "={rax}"(a)
: "{rax}"(a), "{rdi}"(b)
: "memory", "rbx", "rcx", "rdx", "rsi", "rdi", "r8",
"r9", "r10", "r11", "r12", "r13", "r14", "r15"
: "intel", "volatile");
Error::demux(a)
}
pub unsafe fn syscall2(mut a: usize, b: usize, c: usize) -> Result<usize> {
llvm_asm!("syscall"
: "={rax}"(a)
: "{rax}"(a), "{rdi}"(b), "{rsi}"(c)
: "rcx", "r11", "memory"
: "intel", "volatile");
Error::demux(a)
}
pub unsafe fn syscall3(mut a: usize, b: usize, c: usize, d: usize) -> Result<usize> {
llvm_asm!("syscall"
: "={rax}"(a)
: "{rax}"(a), "{rdi}"(b), "{rsi}"(c), "{rdx}"(d)
: "rcx", "r11", "memory"
: "intel", "volatile");
Error::demux(a)
}
pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Result<usize> {
llvm_asm!("syscall"
: "={rax}"(a)
: "{rax}"(a), "{rdi}"(b), "{rsi}"(c), "{rdx}"(d), "{r10}"(e)
: "rcx", "r11", "memory"
: "intel", "volatile");
Error::demux(a)
}
pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize)
-> Result<usize> {
llvm_asm!("syscall"
: "={rax}"(a)
: "{rax}"(a), "{rdi}"(b), "{rsi}"(c), "{rdx}"(d), "{r10}"(e), "{r8}"(f)
: "rcx", "r11", "memory"
: "intel", "volatile");
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,);
}
......@@ -54,7 +54,7 @@ pub fn chmod<T: AsRef<[u8]>>(path: T, mode: usize) -> Result<usize> {
/// Produce a fork of the current process, or a new process thread
pub unsafe fn clone(flags: CloneFlags) -> Result<usize> {
syscall1_clobber(SYS_CLONE, flags.bits())
syscall1(SYS_CLONE, flags.bits())
}
/// Close a file
......
#![feature(asm)]
#![feature(llvm_asm)]
#![feature(const_fn)] // see https://github.com/rust-lang/rfcs/pull/2632
#![cfg_attr(not(test), no_std)]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment