Skip to content

Commit

Permalink
feat: Add syscalls imports for Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumsheep committed Jul 20, 2020
1 parent 4b41d9a commit c28a632
Showing 1 changed file with 5 additions and 52 deletions.
57 changes: 5 additions & 52 deletions std/linux/syscalls.sn
Original file line number Diff line number Diff line change
@@ -1,53 +1,6 @@
#[target_os = "linux"]
fn syscall1<T1>(num: i32, arg1: T1) : i32 {
let res: i32;

asm("int $$0x80"
: "={ax}"(res),
"+{bx}"(arg1)
: "{ax}"(num)
: "cc", "memory");

return res;
}

#[target_os = "linux"]
fn syscall2<T1, T2>(num: i32, arg1: T1, arg2: T2) : i32 {
let res: i32;

asm("int $$0x80"
: "={ax}"(res),
"+{bx}"(arg1),
"+{cx}"(arg2)
: "{ax}"(num)
: "cc", "memory");

return res;
}

#[target_os = "linux"]
fn syscall3<T1, T2, T3>(num: i32, arg1: T1, arg2: T2, arg3: T3) : i32 {
let res: i32;

asm("int $$0x80"
: "={ax}"(res),
"+{bx}"(arg1),
"+{cx}"(arg2),
"+{dx}"(arg3)
: "{ax}"(num)
: "cc", "memory");

return res;
}

#[target_os = "linux"]
#[target_arch = "i386"]
fn exit(code: i32) {
syscall1<i32, i32>(1, code);
}

#[target_os = "linux"]
#[target_arch = "i386"]
fn write(fd: u32, buf: void*, count: u64) {
syscall3<u32, void*, u64>(4, fd, buf, count);
namespace linux {
namespace syscalls {
import "./i386/syscalls"
import "./x86_64/syscalls"
}
}

0 comments on commit c28a632

Please sign in to comment.