Skip to content

Commit

Permalink
exit, createThread for zen
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Orru committed Jan 8, 2018
1 parent 5981707 commit 98a95cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
19 changes: 15 additions & 4 deletions std/os/zen.zig
Expand Up @@ -9,16 +9,23 @@ 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;
pub const SYS_exit = 0;
pub const SYS_createMailbox = 1;
pub const SYS_send = 2;
pub const SYS_receive = 3;
pub const SYS_map = 4;
pub const SYS_createThread = 5;


////////////////////
//// Syscalls ////
////////////////////

pub fn exit(status: i32) -> noreturn {
_ = syscall1(SYS_exit, @bitCast(usize, isize(status)));
unreachable;
}

pub fn createMailbox(id: u16) {
_ = syscall1(SYS_createMailbox, id);
}
Expand All @@ -35,6 +42,10 @@ 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;
}

pub fn createThread(function: fn()) -> u16 {
return u16(syscall1(SYS_createThread, @ptrToInt(function)));
}


/////////////////////////
//// Syscall stubs ////
Expand Down
5 changes: 2 additions & 3 deletions std/special/bootstrap.zig
Expand Up @@ -21,9 +21,8 @@ comptime {
}

extern fn zenMain() -> noreturn {
// TODO: call exit.
root.main() catch {};
while (true) {}
root.main() catch std.os.posix.exit(1);
std.os.posix.exit(0);
}

nakedcc fn _start() -> noreturn {
Expand Down

0 comments on commit 98a95cc

Please sign in to comment.