diff options
| author | Andrea Orru <andrea@orru.io> | 2018-04-11 00:31:32 -0700 |
|---|---|---|
| committer | Andrea Orru <andrea@orru.io> | 2018-04-11 00:31:32 -0700 |
| commit | b01c5a95c468650f143e0ae96f6c3865852fdcda (patch) | |
| tree | 385f3e37a8cf9c46c3cc2c7cb51f1e8e203e44a1 /std | |
| parent | 43cdfa275ad75097d80abf1c4091f0b506fcb1e3 (diff) | |
| download | zig-b01c5a95c468650f143e0ae96f6c3865852fdcda.tar.gz zig-b01c5a95c468650f143e0ae96f6c3865852fdcda.zip | |
Update zen library
Diffstat (limited to 'std')
| -rw-r--r-- | std/os/zen.zig | 67 | ||||
| -rw-r--r-- | std/special/bootstrap.zig | 6 |
2 files changed, 27 insertions, 46 deletions
diff --git a/std/os/zen.zig b/std/os/zen.zig index 51528ca391..50d53dca5f 100644 --- a/std/os/zen.zig +++ b/std/os/zen.zig @@ -7,6 +7,7 @@ pub const Message = struct { receiver: MailboxId, type: usize, payload: usize, + buffer: ?[]const u8, pub fn from(mailbox_id: &const MailboxId) Message { return Message { @@ -14,6 +15,7 @@ pub const Message = struct { .receiver = *mailbox_id, .type = 0, .payload = 0, + .buffer = null, }; } @@ -23,16 +25,26 @@ pub const Message = struct { .receiver = *mailbox_id, .type = msg_type, .payload = 0, + .buffer = null, }; } - pub fn withData(mailbox_id: &const MailboxId, msg_type: usize, payload: usize) Message { - return Message { - .sender = MailboxId.This, - .receiver = *mailbox_id, - .type = msg_type, - .payload = payload, - }; + pub fn as(self: &const Message, sender: &const MailboxId) Message { + var message = *self; + message.sender = *sender; + return message; + } + + pub fn data(self: &const Message, var_data: var) Message { + var message = *self; + + if (@canImplicitCast([]const u8, var_data)) { + message.buffer = var_data; + } else { + message.payload = var_data; + } + + return message; } }; @@ -91,10 +103,8 @@ pub fn read(fd: i32, buf: &u8, count: usize) usize { pub fn write(fd: i32, buf: &const u8, count: usize) usize { switch (fd) { STDOUT_FILENO, STDERR_FILENO => { - var i: usize = 0; - while (i < count) : (i += 1) { - send(Message.withData(Server.Terminal, 1, buf[i])); - } + send(Message.to(Server.Terminal, 1) + .data(buf[0..count])); }, else => unreachable, } @@ -108,16 +118,12 @@ 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, - createProcess = 8, - wait = 9, - portReady = 10, + send = 1, + receive = 2, + subscribeIRQ = 3, + inb = 4, + map = 5, + createThread = 6, }; @@ -130,13 +136,6 @@ pub fn exit(status: i32) noreturn { unreachable; } -pub fn createPort(mailbox_id: &const MailboxId) void { - _ = switch (*mailbox_id) { - MailboxId.Port => |id| syscall1(Syscall.createPort, id), - else => unreachable, - }; -} - pub fn send(message: &const Message) void { _ = syscall1(Syscall.send, @ptrToInt(message)); } @@ -161,18 +160,6 @@ 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 //// ///////////////////////// diff --git a/std/special/bootstrap.zig b/std/special/bootstrap.zig index d2c22c13e1..d2b1af76a7 100644 --- a/std/special/bootstrap.zig +++ b/std/special/bootstrap.zig @@ -13,17 +13,11 @@ comptime { @export("main", main, strong_linkage); } else if (builtin.os == builtin.Os.windows) { @export("WinMainCRTStartup", WinMainCRTStartup, strong_linkage); - } else if (builtin.os == builtin.Os.zen) { - @export("_start", zen_start, strong_linkage); } else { @export("_start", _start, strong_linkage); } } -extern fn zen_start() noreturn { - std.os.posix.exit(@inlineCall(callMain)); -} - nakedcc fn _start() noreturn { switch (builtin.arch) { builtin.Arch.x86_64 => { |
