| ... | ... | @@ -5,26 +5,39 @@ |
| 5 | 5 | pub const Message = struct { |
| 6 | 6 | sender: MailboxId, |
| 7 | 7 | receiver: MailboxId, |
| 8 | type: usize, |
| 8 | 9 | payload: usize, |
| 9 | 10 | |
| 10 | 11 | pub fn from(mailbox_id: &const MailboxId) Message { |
| 11 | 12 | return Message { |
| 12 | | .sender = undefined, |
| 13 | .sender = MailboxId.Undefined, |
| 13 | 14 | .receiver = *mailbox_id, |
| 14 | | .payload = undefined, |
| 15 | .type = 0, |
| 16 | .payload = 0, |
| 15 | 17 | }; |
| 16 | 18 | } |
| 17 | 19 | |
| 18 | | pub fn to(mailbox_id: &const MailboxId, payload: usize) Message { |
| 20 | pub fn to(mailbox_id: &const MailboxId, msg_type: usize) Message { |
| 19 | 21 | return Message { |
| 20 | 22 | .sender = MailboxId.This, |
| 21 | 23 | .receiver = *mailbox_id, |
| 24 | .type = msg_type, |
| 25 | .payload = 0, |
| 26 | }; |
| 27 | } |
| 28 | |
| 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, |
| 22 | 34 | .payload = payload, |
| 23 | 35 | }; |
| 24 | 36 | } |
| 25 | 37 | }; |
| 26 | 38 | |
| 27 | 39 | pub const MailboxId = union(enum) { |
| 40 | Undefined, |
| 28 | 41 | This, |
| 29 | 42 | Kernel, |
| 30 | 43 | Port: u16, |
| ... | ... | @@ -55,14 +68,32 @@ pub const STDERR_FILENO = 2; |
| 55 | 68 | pub const getErrno = @import("linux/index.zig").getErrno; |
| 56 | 69 | use @import("linux/errno.zig"); |
| 57 | 70 | |
| 71 | // TODO: implement this correctly. |
| 72 | pub fn read(fd: i32, buf: &u8, count: usize) usize { |
| 73 | switch (fd) { |
| 74 | STDIN_FILENO => { |
| 75 | var i: usize = 0; |
| 76 | while (i < count) : (i += 1) { |
| 77 | send(Message.to(Server.Keyboard, 0)); |
| 78 | |
| 79 | var message = Message.from(MailboxId.This); |
| 80 | receive(&message); |
| 81 | |
| 82 | buf[i] = u8(message.payload); |
| 83 | } |
| 84 | }, |
| 85 | else => unreachable, |
| 86 | } |
| 87 | return count; |
| 88 | } |
| 89 | |
| 58 | 90 | // TODO: implement this correctly. |
| 59 | 91 | pub fn write(fd: i32, buf: &const u8, count: usize) usize { |
| 60 | 92 | switch (fd) { |
| 61 | | STDIN_FILENO => unreachable, |
| 62 | 93 | STDOUT_FILENO, STDERR_FILENO => { |
| 63 | 94 | var i: usize = 0; |
| 64 | 95 | while (i < count) : (i += 1) { |
| 65 | | send(Message.to(Server.Terminal, buf[i])); |
| 96 | send(Message.withData(Server.Terminal, 1, buf[i])); |
| 66 | 97 | } |
| 67 | 98 | }, |
| 68 | 99 | else => unreachable, |