Skip to content

Commit

Permalink
Merge pull request #851 from zig-lang/zen_stdlib
Browse files Browse the repository at this point in the history
Zen specific hacks
  • Loading branch information
andrewrk committed Mar 20, 2018
2 parents 1369fec + 43cdfa2 commit 66fec3a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
8 changes: 8 additions & 0 deletions std/os/index.zig
Expand Up @@ -115,6 +115,14 @@ pub fn getRandomBytes(buf: []u8) !void {
};
}
},
Os.zen => {
const randomness = []u8 {42, 1, 7, 12, 22, 17, 99, 16, 26, 87, 41, 45};
var i: usize = 0;
while (i < buf.len) : (i += 1) {
if (i > randomness.len) return error.Unknown;
buf[i] = randomness[i];
}
},
else => @compileError("Unsupported OS"),
}
}
Expand Down
30 changes: 22 additions & 8 deletions std/os/zen.zig
Expand Up @@ -107,14 +107,17 @@ pub fn write(fd: i32, buf: &const u8, count: usize) usize {
///////////////////////////

pub const Syscall = enum(usize) {
exit = 0,
createPort = 1,
send = 2,
receive = 3,
subscribeIRQ = 4,
inb = 5,
map = 6,
createThread = 7,
exit = 0,
createPort = 1,
send = 2,
receive = 3,
subscribeIRQ = 4,
inb = 5,
map = 6,
createThread = 7,
createProcess = 8,
wait = 9,
portReady = 10,
};


Expand Down Expand Up @@ -158,6 +161,17 @@ pub fn createThread(function: fn()void) u16 {
return u16(syscall1(Syscall.createThread, @ptrToInt(function)));
}

pub fn createProcess(elf_addr: usize) u16 {
return u16(syscall1(Syscall.createProcess, elf_addr));
}

pub fn wait(tid: u16) void {
_ = syscall1(Syscall.wait, tid);
}

pub fn portReady(port: u16) bool {
return syscall1(Syscall.portReady, port) != 0;
}

/////////////////////////
//// Syscall stubs ////
Expand Down
6 changes: 4 additions & 2 deletions std/special/bootstrap.zig
Expand Up @@ -84,8 +84,10 @@ fn callMain() u8 {
builtin.TypeId.ErrorUnion => {
root.main() catch |err| {
std.debug.warn("error: {}\n", @errorName(err));
if (@errorReturnTrace()) |trace| {
std.debug.dumpStackTrace(trace);
if (builtin.os != builtin.Os.zen) {
if (@errorReturnTrace()) |trace| {
std.debug.dumpStackTrace(trace);
}
}
return 1;
};
Expand Down

0 comments on commit 66fec3a

Please sign in to comment.