authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-03-20 16:16:08-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2018-03-20 16:16:08-04:00
log66fec3a3d726733b162761211dee58e896370e95
tree1faabb44b7fd41ab36360d619049b1639da0980b
parent1369fecccfcd7900ce0a78a67db96ed59957720a
parent43cdfa275ad75097d80abf1c4091f0b506fcb1e3
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #851 from zig-lang/zen_stdlib

Zen specific hacks

3 files changed, 34 insertions(+), 10 deletions(-)

std/os/index.zig+8
...@@ -115,6 +115,14 @@ pub fn getRandomBytes(buf: []u8) !void {...@@ -115,6 +115,14 @@ pub fn getRandomBytes(buf: []u8) !void {
115 };115 };
116 }116 }
117 },117 },
118 Os.zen => {
119 const randomness = []u8 {42, 1, 7, 12, 22, 17, 99, 16, 26, 87, 41, 45};
120 var i: usize = 0;
121 while (i < buf.len) : (i += 1) {
122 if (i > randomness.len) return error.Unknown;
123 buf[i] = randomness[i];
124 }
125 },
118 else => @compileError("Unsupported OS"),126 else => @compileError("Unsupported OS"),
119 }127 }
120}128}
std/os/zen.zig+22-8
...@@ -107,14 +107,17 @@ pub fn write(fd: i32, buf: &const u8, count: usize) usize {...@@ -107,14 +107,17 @@ pub fn write(fd: i32, buf: &const u8, count: usize) usize {
107///////////////////////////107///////////////////////////
108108
109pub const Syscall = enum(usize) {109pub const Syscall = enum(usize) {
110 exit = 0,110 exit = 0,
111 createPort = 1,111 createPort = 1,
112 send = 2,112 send = 2,
113 receive = 3,113 receive = 3,
114 subscribeIRQ = 4,114 subscribeIRQ = 4,
115 inb = 5,115 inb = 5,
116 map = 6,116 map = 6,
117 createThread = 7,117 createThread = 7,
118 createProcess = 8,
119 wait = 9,
120 portReady = 10,
118};121};
119122
120123
...@@ -158,6 +161,17 @@ pub fn createThread(function: fn()void) u16 {...@@ -158,6 +161,17 @@ pub fn createThread(function: fn()void) u16 {
158 return u16(syscall1(Syscall.createThread, @ptrToInt(function)));161 return u16(syscall1(Syscall.createThread, @ptrToInt(function)));
159}162}
160163
164pub fn createProcess(elf_addr: usize) u16 {
165 return u16(syscall1(Syscall.createProcess, elf_addr));
166}
167
168pub fn wait(tid: u16) void {
169 _ = syscall1(Syscall.wait, tid);
170}
171
172pub fn portReady(port: u16) bool {
173 return syscall1(Syscall.portReady, port) != 0;
174}
161175
162/////////////////////////176/////////////////////////
163//// Syscall stubs ////177//// Syscall stubs ////
std/special/bootstrap.zig+4-2
...@@ -84,8 +84,10 @@ fn callMain() u8 {...@@ -84,8 +84,10 @@ fn callMain() u8 {
84 builtin.TypeId.ErrorUnion => {84 builtin.TypeId.ErrorUnion => {
85 root.main() catch |err| {85 root.main() catch |err| {
86 std.debug.warn("error: {}\n", @errorName(err));86 std.debug.warn("error: {}\n", @errorName(err));
87 if (@errorReturnTrace()) |trace| {87 if (builtin.os != builtin.Os.zen) {
88 std.debug.dumpStackTrace(trace);88 if (@errorReturnTrace()) |trace| {
89 std.debug.dumpStackTrace(trace);
90 }
89 }91 }
90 return 1;92 return 1;
91 };93 };