| ... | ... | @@ -1,19 +1,45 @@ |
| 1 | /////////////////////////// |
| 2 | //// IPC structures //// |
| 3 | /////////////////////////// |
| 4 | |
| 5 | pub const Message = struct { |
| 6 | from: MailboxId, |
| 7 | to: MailboxId, |
| 8 | payload: usize, |
| 9 | |
| 10 | pub fn from(mailbox_id: MailboxId) Message { |
| 11 | return Message { |
| 12 | .from = mailbox_id, |
| 13 | .to = undefined, |
| 14 | .payload = undefined, |
| 15 | }; |
| 16 | } |
| 17 | }; |
| 18 | |
| 19 | pub const MailboxId = union(enum) { |
| 20 | Me, |
| 21 | Kernel, |
| 22 | Port: u16, |
| 23 | //Thread: u16, |
| 24 | }; |
| 25 | |
| 26 | |
| 1 | 27 | ////////////////////////////// |
| 2 | 28 | //// Reserved mailboxes //// |
| 3 | 29 | ////////////////////////////// |
| 4 | 30 | |
| 5 | | pub const MBOX_TERMINAL = 1; |
| 31 | pub const MBOX_TERMINAL = MailboxId { .Port = 0 }; |
| 6 | 32 | |
| 7 | 33 | |
| 8 | 34 | /////////////////////////// |
| 9 | 35 | //// Syscall numbers //// |
| 10 | 36 | /////////////////////////// |
| 11 | 37 | |
| 12 | | pub const SYS_exit = 0; |
| 13 | | pub const SYS_createMailbox = 1; |
| 14 | | pub const SYS_send = 2; |
| 15 | | pub const SYS_receive = 3; |
| 16 | | pub const SYS_map = 4; |
| 38 | pub const SYS_exit = 0; |
| 39 | pub const SYS_createPort = 1; |
| 40 | pub const SYS_send = 2; |
| 41 | pub const SYS_receive = 3; |
| 42 | pub const SYS_map = 4; |
| 17 | 43 | pub const SYS_createThread = 5; |
| 18 | 44 | |
| 19 | 45 | |
| ... | ... | @@ -26,16 +52,16 @@ pub fn exit(status: i32) noreturn { |
| 26 | 52 | unreachable; |
| 27 | 53 | } |
| 28 | 54 | |
| 29 | | pub fn createMailbox(id: u16) void { |
| 30 | | _ = syscall1(SYS_createMailbox, id); |
| 55 | pub fn createPort(id: u16) void { |
| 56 | _ = syscall1(SYS_createPort, id); |
| 31 | 57 | } |
| 32 | 58 | |
| 33 | | pub fn send(mailbox_id: u16, data: usize) void { |
| 34 | | _ = syscall2(SYS_send, mailbox_id, data); |
| 59 | pub fn send(message: &const Message) void { |
| 60 | _ = syscall1(SYS_send, @ptrToInt(message)); |
| 35 | 61 | } |
| 36 | 62 | |
| 37 | | pub fn receive(mailbox_id: u16) usize { |
| 38 | | return syscall1(SYS_receive, mailbox_id); |
| 63 | pub fn receive(destination: &Message) void { |
| 64 | _ = syscall1(SYS_receive, @ptrToInt(destination)); |
| 39 | 65 | } |
| 40 | 66 | |
| 41 | 67 | pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool { |