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 {
77 receiver: MailboxId,
88 type: usize,
99 payload: usize,
10 buffer: ?[]const u8,
1011
1112 pub fn from(mailbox_id: &const MailboxId) Message {
1213 return Message {
......@@ -14,6 +15,7 @@ pub const Message = struct {
1415 .receiver = *mailbox_id,
1516 .type = 0,
1617 .payload = 0,
18 .buffer = null,
1719 };
1820 }
1921
......@@ -23,16 +25,26 @@ pub const Message = struct {
2325 .receiver = *mailbox_id,
2426 .type = msg_type,
2527 .payload = 0,
28 .buffer = null,
2629 };
2730 }
2831
29 pub fn withData(mailbox_id: &const MailboxId, msg_type: usize, payload: usize) Message {
30 return Message {
31 .sender = MailboxId.This,
32 .receiver = *mailbox_id,
33 .type = msg_type,
34 .payload = payload,
35 };
32 pub fn as(self: &const Message, sender: &const MailboxId) Message {
33 var message = *self;
34 message.sender = *sender;
35 return message;
36 }
37
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;
3648 }
3749};
3850
......@@ -91,10 +103,8 @@ pub fn read(fd: i32, buf: &u8, count: usize) usize {
91103pub fn write(fd: i32, buf: &const u8, count: usize) usize {
92104 switch (fd) {
93105 STDOUT_FILENO, STDERR_FILENO => {
94 var i: usize = 0;
95 while (i < count) : (i += 1) {
96 send(Message.withData(Server.Terminal, 1, buf[i]));
97 }
106 send(Message.to(Server.Terminal, 1)
107 .data(buf[0..count]));
98108 },
99109 else => unreachable,
100110 }
......@@ -108,16 +118,12 @@ pub fn write(fd: i32, buf: &const u8, count: usize) usize {
108118
109119pub const Syscall = enum(usize) {
110120 exit = 0,
111 createPort = 1,
112 send = 2,
113 receive = 3,
114 subscribeIRQ = 4,
115 inb = 5,
116 map = 6,
117 createThread = 7,
118 createProcess = 8,
119 wait = 9,
120 portReady = 10,
121 send = 1,
122 receive = 2,
123 subscribeIRQ = 3,
124 inb = 4,
125 map = 5,
126 createThread = 6,
121127};
122128
123129
......@@ -130,13 +136,6 @@ pub fn exit(status: i32) noreturn {
130136 unreachable;
131137}
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
140139pub fn send(message: &const Message) void {
141140 _ = syscall1(Syscall.send, @ptrToInt(message));
142141}
......@@ -161,18 +160,6 @@ pub fn createThread(function: fn()void) u16 {
161160 return u16(syscall1(Syscall.createThread, @ptrToInt(function)));
162161}
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
176163/////////////////////////
177164//// Syscall stubs ////
178165/////////////////////////
std/special/bootstrap.zig-6
......@@ -13,17 +13,11 @@ comptime {
1313 @export("main", main, strong_linkage);
1414 } else if (builtin.os == builtin.Os.windows) {
1515 @export("WinMainCRTStartup", WinMainCRTStartup, strong_linkage);
16 } else if (builtin.os == builtin.Os.zen) {
17 @export("_start", zen_start, strong_linkage);
1816 } else {
1917 @export("_start", _start, strong_linkage);
2018 }
2119}
2220
23extern fn zen_start() noreturn {
24 std.os.posix.exit(@inlineCall(callMain));
25}
26
2721nakedcc fn _start() noreturn {
2822 switch (builtin.arch) {
2923 builtin.Arch.x86_64 => {