diff options
| author | Andrea Orru <andrea@orru.io> | 2018-01-07 04:43:08 -0500 |
|---|---|---|
| committer | Andrea Orru <andrea@orru.io> | 2018-01-07 04:43:08 -0500 |
| commit | 31828572249883f99fad307dc6b27df9d1678a8d (patch) | |
| tree | 6f68110ee33640786e23f117880333240aa25341 /std/os | |
| parent | ad438cfd40aba682a0bcd88ed607c2cbd378f647 (diff) | |
| download | zig-31828572249883f99fad307dc6b27df9d1678a8d.tar.gz zig-31828572249883f99fad307dc6b27df9d1678a8d.zip | |
Adding zen support
Diffstat (limited to 'std/os')
| -rw-r--r-- | std/os/index.zig | 2 | ||||
| -rw-r--r-- | std/os/zen.zig | 94 |
2 files changed, 96 insertions, 0 deletions
diff --git a/std/os/index.zig b/std/os/index.zig index c9a7def1bb..eb192d7d85 100644 --- a/std/os/index.zig +++ b/std/os/index.zig @@ -7,9 +7,11 @@ const os = this; pub const windows = @import("windows/index.zig"); pub const darwin = @import("darwin.zig"); pub const linux = @import("linux.zig"); +pub const zen = @import("zen.zig"); pub const posix = switch(builtin.os) { Os.linux => linux, Os.macosx, Os.ios => darwin, + Os.zen => zen, else => @compileError("Unsupported OS"), }; diff --git a/std/os/zen.zig b/std/os/zen.zig new file mode 100644 index 0000000000..ffc491e404 --- /dev/null +++ b/std/os/zen.zig @@ -0,0 +1,94 @@ +////////////////////////////// +//// Reserved mailboxes //// +////////////////////////////// + +pub const MBOX_TERMINAL = 1; + + +/////////////////////////// +//// Syscall numbers //// +/////////////////////////// + +pub const SYS_createMailbox = 0; +pub const SYS_send = 1; +pub const SYS_receive = 2; +pub const SYS_map = 3; + + +//////////////////// +//// Syscalls //// +//////////////////// + +pub fn createMailbox(id: u16) { + _ = syscall1(SYS_createMailbox, id); +} + +pub fn send(mailbox_id: u16, data: usize) { + _ = syscall2(SYS_send, mailbox_id, data); +} + +pub fn receive(mailbox_id: u16) -> usize { + return syscall1(SYS_receive, mailbox_id); +} + +pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) -> bool { + return syscall4(SYS_map, v_addr, p_addr, size, usize(writable)) != 0; +} + + +///////////////////////// +//// Syscall stubs //// +///////////////////////// + +pub inline fn syscall0(number: usize) -> usize { + return asm volatile ("int $0x80" + : [ret] "={eax}" (-> usize) + : [number] "{eax}" (number)); +} + +pub inline fn syscall1(number: usize, arg1: usize) -> usize { + return asm volatile ("int $0x80" + : [ret] "={eax}" (-> usize) + : [number] "{eax}" (number), + [arg1] "{ecx}" (arg1)); +} + +pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { + return asm volatile ("int $0x80" + : [ret] "={eax}" (-> usize) + : [number] "{eax}" (number), + [arg1] "{ecx}" (arg1), + [arg2] "{edx}" (arg2)); +} + +pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { + return asm volatile ("int $0x80" + : [ret] "={eax}" (-> usize) + : [number] "{eax}" (number), + [arg1] "{ecx}" (arg1), + [arg2] "{edx}" (arg2), + [arg3] "{ebx}" (arg3)); +} + +pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize { + return asm volatile ("int $0x80" + : [ret] "={eax}" (-> usize) + : [number] "{eax}" (number), + [arg1] "{ecx}" (arg1), + [arg2] "{edx}" (arg2), + [arg3] "{ebx}" (arg3), + [arg4] "{esi}" (arg4)); +} + +pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, + arg4: usize, arg5: usize) -> usize +{ + return asm volatile ("int $0x80" + : [ret] "={eax}" (-> usize) + : [number] "{eax}" (number), + [arg1] "{ecx}" (arg1), + [arg2] "{edx}" (arg2), + [arg3] "{ebx}" (arg3), + [arg4] "{esi}" (arg4), + [arg5] "{edi}" (arg5)); +} |
