| ... | @@ -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, |
| 10 | | 11 | |
| 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 | } |
| 19 | | 21 | |
| ... | @@ -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 | } |
| 28 | | 31 | |
| 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 | }; |
| 38 | | 50 | |
| ... | @@ -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 { |
| 91 | pub fn write(fd: i32, buf: &const u8, count: usize) usize { | 103 | pub 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 { |
| 108 | | 118 | |
| 109 | pub const Syscall = enum(usize) { | 119 | pub 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 | }; |
| 122 | | 128 | |
| 123 | | 129 | |
| ... | @@ -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 | } |
| 132 | | 138 | |
| 133 | pub 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 | | | |
| 140 | pub fn send(message: &const Message) void { | 139 | pub 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 | } |
| 163 | | 162 | |
| 164 | pub fn createProcess(elf_addr: usize) u16 { | | |
| 165 | return u16(syscall1(Syscall.createProcess, elf_addr)); | | |
| 166 | } | | |
| 167 | | | |
| 168 | pub fn wait(tid: u16) void { | | |
| 169 | _ = syscall1(Syscall.wait, tid); | | |
| 170 | } | | |
| 171 | | | |
| 172 | pub fn portReady(port: u16) bool { | | |
| 173 | return syscall1(Syscall.portReady, port) != 0; | | |
| 174 | } | | |
| 175 | | | |
| 176 | ///////////////////////// | 163 | ///////////////////////// |
| 177 | //// Syscall stubs //// | 164 | //// Syscall stubs //// |
| 178 | ///////////////////////// | 165 | ///////////////////////// |