authorgravatar for andrea@orru.ioAndrea Orru <andrea@orru.io> 2018-04-11 00:31:32-07:00
committergravatar for andrea@orru.ioAndrea Orru <andrea@orru.io> 2018-04-11 00:31:32-07:00
logb01c5a95c468650f143e0ae96f6c3865852fdcda
tree385f3e37a8cf9c46c3cc2c7cb51f1e8e203e44a1
parent43cdfa275ad75097d80abf1c4091f0b506fcb1e3

Update zen library


2 files changed, 27 insertions(+), 46 deletions(-)

std/os/zen.zig+27-40
...@@ -7,6 +7,7 @@ pub const Message = struct {...@@ -7,6 +7,7 @@ pub const Message = struct {
7 receiver: MailboxId,7 receiver: MailboxId,
8 type: usize,8 type: usize,
9 payload: usize,9 payload: usize,
10 buffer: ?[]const u8,
1011
11 pub fn from(mailbox_id: &const MailboxId) Message {12 pub fn from(mailbox_id: &const MailboxId) Message {
12 return Message {13 return Message {
...@@ -14,6 +15,7 @@ pub const Message = struct {...@@ -14,6 +15,7 @@ pub const Message = struct {
14 .receiver = *mailbox_id,15 .receiver = *mailbox_id,
15 .type = 0,16 .type = 0,
16 .payload = 0,17 .payload = 0,
18 .buffer = null,
17 };19 };
18 }20 }
1921
...@@ -23,16 +25,26 @@ pub const Message = struct {...@@ -23,16 +25,26 @@ pub const Message = struct {
23 .receiver = *mailbox_id,25 .receiver = *mailbox_id,
24 .type = msg_type,26 .type = msg_type,
25 .payload = 0,27 .payload = 0,
28 .buffer = null,
26 };29 };
27 }30 }
2831
29 pub fn withData(mailbox_id: &const MailboxId, msg_type: usize, payload: usize) Message {32 pub fn as(self: &const Message, sender: &const MailboxId) Message {
30 return Message {33 var message = *self;
31 .sender = MailboxId.This,34 message.sender = *sender;
32 .receiver = *mailbox_id,35 return message;
33 .type = msg_type,36 }
34 .payload = payload,37
35 };38 pub fn data(self: &const Message, var_data: var) Message {
39 var message = *self;
40
41 if (@canImplicitCast([]const u8, var_data)) {
42 message.buffer = var_data;
43 } else {
44 message.payload = var_data;
45 }
46
47 return message;
36 }48 }
37};49};
3850
...@@ -91,10 +103,8 @@ pub fn read(fd: i32, buf: &u8, count: usize) usize {...@@ -91,10 +103,8 @@ pub fn read(fd: i32, buf: &u8, count: usize) usize {
91pub fn write(fd: i32, buf: &const u8, count: usize) usize {103pub fn write(fd: i32, buf: &const u8, count: usize) usize {
92 switch (fd) {104 switch (fd) {
93 STDOUT_FILENO, STDERR_FILENO => {105 STDOUT_FILENO, STDERR_FILENO => {
94 var i: usize = 0;106 send(Message.to(Server.Terminal, 1)
95 while (i < count) : (i += 1) {107 .data(buf[0..count]));
96 send(Message.withData(Server.Terminal, 1, buf[i]));
97 }
98 },108 },
99 else => unreachable,109 else => unreachable,
100 }110 }
...@@ -108,16 +118,12 @@ pub fn write(fd: i32, buf: &const u8, count: usize) usize {...@@ -108,16 +118,12 @@ pub fn write(fd: i32, buf: &const u8, count: usize) usize {
108118
109pub const Syscall = enum(usize) {119pub const Syscall = enum(usize) {
110 exit = 0,120 exit = 0,
111 createPort = 1,121 send = 1,
112 send = 2,122 receive = 2,
113 receive = 3,123 subscribeIRQ = 3,
114 subscribeIRQ = 4,124 inb = 4,
115 inb = 5,125 map = 5,
116 map = 6,126 createThread = 6,
117 createThread = 7,
118 createProcess = 8,
119 wait = 9,
120 portReady = 10,
121};127};
122128
123129
...@@ -130,13 +136,6 @@ pub fn exit(status: i32) noreturn {...@@ -130,13 +136,6 @@ pub fn exit(status: i32) noreturn {
130 unreachable;136 unreachable;
131}137}
132138
133pub fn createPort(mailbox_id: &const MailboxId) void {
134 _ = switch (*mailbox_id) {
135 MailboxId.Port => |id| syscall1(Syscall.createPort, id),
136 else => unreachable,
137 };
138}
139
140pub fn send(message: &const Message) void {139pub fn send(message: &const Message) void {
141 _ = syscall1(Syscall.send, @ptrToInt(message));140 _ = syscall1(Syscall.send, @ptrToInt(message));
142}141}
...@@ -161,18 +160,6 @@ pub fn createThread(function: fn()void) u16 {...@@ -161,18 +160,6 @@ pub fn createThread(function: fn()void) u16 {
161 return u16(syscall1(Syscall.createThread, @ptrToInt(function)));160 return u16(syscall1(Syscall.createThread, @ptrToInt(function)));
162}161}
163162
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}
175
176/////////////////////////163/////////////////////////
177//// Syscall stubs ////164//// Syscall stubs ////
178/////////////////////////165/////////////////////////
std/special/bootstrap.zig-6
...@@ -13,17 +13,11 @@ comptime {...@@ -13,17 +13,11 @@ comptime {
13 @export("main", main, strong_linkage);13 @export("main", main, strong_linkage);
14 } else if (builtin.os == builtin.Os.windows) {14 } else if (builtin.os == builtin.Os.windows) {
15 @export("WinMainCRTStartup", WinMainCRTStartup, strong_linkage);15 @export("WinMainCRTStartup", WinMainCRTStartup, strong_linkage);
16 } else if (builtin.os == builtin.Os.zen) {
17 @export("_start", zen_start, strong_linkage);
18 } else {16 } else {
19 @export("_start", _start, strong_linkage);17 @export("_start", _start, strong_linkage);
20 }18 }
21}19}
2220
23extern fn zen_start() noreturn {
24 std.os.posix.exit(@inlineCall(callMain));
25}
26
27nakedcc fn _start() noreturn {21nakedcc fn _start() noreturn {
28 switch (builtin.arch) {22 switch (builtin.arch) {
29 builtin.Arch.x86_64 => {23 builtin.Arch.x86_64 => {