Merge pull request #851 from zig-lang/zen_stdlib

Zen specific hacks
This commit is contained in:
Andrew Kelley 2018-03-20 16:16:08 -04:00 committed by GitHub
commit 66fec3a3d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 10 deletions

View File

@ -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"),
}
}

View File

@ -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,
};
@ -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 ////

View File

@ -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;
};