| ... | ... | @@ -7,13 +7,21 @@ pub const Message = struct { |
| 7 | 7 | receiver: MailboxId, |
| 8 | 8 | payload: usize, |
| 9 | 9 | |
| 10 | | pub fn withReceiver(mailbox_id: &const MailboxId) Message { |
| 10 | pub fn from(mailbox_id: &const MailboxId) Message { |
| 11 | 11 | return Message { |
| 12 | 12 | .sender = undefined, |
| 13 | 13 | .receiver = *mailbox_id, |
| 14 | 14 | .payload = undefined, |
| 15 | 15 | }; |
| 16 | 16 | } |
| 17 | |
| 18 | pub fn to(mailbox_id: &const MailboxId, payload: usize) Message { |
| 19 | return Message { |
| 20 | .sender = MailboxId.This, |
| 21 | .receiver = *mailbox_id, |
| 22 | .payload = payload, |
| 23 | }; |
| 24 | } |
| 17 | 25 | }; |
| 18 | 26 | |
| 19 | 27 | pub const MailboxId = union(enum) { |
| ... | ... | @@ -29,11 +37,40 @@ pub const MailboxId = union(enum) { |
| 29 | 37 | /////////////////////////////////////// |
| 30 | 38 | |
| 31 | 39 | pub const Service = struct { |
| 32 | | pub const Terminal = MailboxId { .Port = 0 }; |
| 33 | | pub const Keyboard = MailboxId { .Port = 1 }; |
| 40 | pub const Keyboard = MailboxId { .Port = 0 }; |
| 41 | pub const Terminal = MailboxId { .Port = 1 }; |
| 34 | 42 | }; |
| 35 | 43 | |
| 36 | 44 | |
| 45 | //////////////////////// |
| 46 | //// POSIX things //// |
| 47 | //////////////////////// |
| 48 | |
| 49 | // Standard streams. |
| 50 | pub const STDIN_FILENO = 0; |
| 51 | pub const STDOUT_FILENO = 1; |
| 52 | pub const STDERR_FILENO = 2; |
| 53 | |
| 54 | // FIXME: let's borrow Linux's error numbers for now. |
| 55 | pub const getErrno = @import("linux/index.zig").getErrno; |
| 56 | use @import("linux/errno.zig"); |
| 57 | |
| 58 | // TODO: implement this correctly. |
| 59 | pub fn write(fd: i32, buf: &const u8, count: usize) usize { |
| 60 | switch (fd) { |
| 61 | STDIN_FILENO => unreachable, |
| 62 | STDOUT_FILENO, STDERR_FILENO => { |
| 63 | var i: usize = 0; |
| 64 | while (i < count) : (i += 1) { |
| 65 | send(Message.to(Service.Terminal, buf[i])); |
| 66 | } |
| 67 | }, |
| 68 | else => unreachable, |
| 69 | } |
| 70 | return count; |
| 71 | } |
| 72 | |
| 73 | |
| 37 | 74 | /////////////////////////// |
| 38 | 75 | //// Syscall numbers //// |
| 39 | 76 | /////////////////////////// |