authorgravatar for andrea@orru.ioAndrea Orru <andrea@orru.io> 2018-03-14 22:07:17-07:00
committergravatar for andrea@orru.ioAndrea Orru <andrea@orru.io> 2018-03-14 22:07:17-07:00
log4fcf01adc57e35953aa9dde5006cf997c5b3518b
treef5090aa20c761b4ce7823a33220a16fe293cd4a1
parentefebb6d341306d508163e7bb5ded41f4bc0468d4

IPC structure updates


1 files changed, 38 insertions(+), 12 deletions(-)

std/os/zen.zig+38-12
...@@ -1,19 +1,45 @@...@@ -1,19 +1,45 @@
1///////////////////////////
2//// IPC structures ////
3///////////////////////////
4
5pub 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
19pub const MailboxId = union(enum) {
20 Me,
21 Kernel,
22 Port: u16,
23 //Thread: u16,
24};
25
26
1//////////////////////////////27//////////////////////////////
2//// Reserved mailboxes ////28//// Reserved mailboxes ////
3//////////////////////////////29//////////////////////////////
430
5pub const MBOX_TERMINAL = 1;31pub const MBOX_TERMINAL = MailboxId { .Port = 0 };
632
733
8///////////////////////////34///////////////////////////
9//// Syscall numbers ////35//// Syscall numbers ////
10///////////////////////////36///////////////////////////
1137
12pub const SYS_exit = 0;38pub const SYS_exit = 0;
13pub const SYS_createMailbox = 1;39pub const SYS_createPort = 1;
14pub const SYS_send = 2;40pub const SYS_send = 2;
15pub const SYS_receive = 3;41pub const SYS_receive = 3;
16pub const SYS_map = 4;42pub const SYS_map = 4;
17pub const SYS_createThread = 5;43pub const SYS_createThread = 5;
1844
1945
...@@ -26,16 +52,16 @@ pub fn exit(status: i32) noreturn {...@@ -26,16 +52,16 @@ pub fn exit(status: i32) noreturn {
26 unreachable;52 unreachable;
27}53}
2854
29pub fn createMailbox(id: u16) void {55pub fn createPort(id: u16) void {
30 _ = syscall1(SYS_createMailbox, id);56 _ = syscall1(SYS_createPort, id);
31}57}
3258
33pub fn send(mailbox_id: u16, data: usize) void {59pub fn send(message: &const Message) void {
34 _ = syscall2(SYS_send, mailbox_id, data);60 _ = syscall1(SYS_send, @ptrToInt(message));
35}61}
3662
37pub fn receive(mailbox_id: u16) usize {63pub fn receive(destination: &Message) void {
38 return syscall1(SYS_receive, mailbox_id);64 _ = syscall1(SYS_receive, @ptrToInt(destination));
39}65}
4066
41pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool {67pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool {