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///////////////////////////
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
127//////////////////////////////
228//// Reserved mailboxes ////
329//////////////////////////////
430
5pub const MBOX_TERMINAL = 1;
31pub const MBOX_TERMINAL = MailboxId { .Port = 0 };
632
733
834///////////////////////////
935//// Syscall numbers ////
1036///////////////////////////
1137
12pub const SYS_exit = 0;
13pub const SYS_createMailbox = 1;
14pub const SYS_send = 2;
15pub const SYS_receive = 3;
16pub const SYS_map = 4;
38pub const SYS_exit = 0;
39pub const SYS_createPort = 1;
40pub const SYS_send = 2;
41pub const SYS_receive = 3;
42pub const SYS_map = 4;
1743pub const SYS_createThread = 5;
1844
1945
......@@ -26,16 +52,16 @@ pub fn exit(status: i32) noreturn {
2652 unreachable;
2753}
2854
29pub fn createMailbox(id: u16) void {
30 _ = syscall1(SYS_createMailbox, id);
55pub fn createPort(id: u16) void {
56 _ = syscall1(SYS_createPort, id);
3157}
3258
33pub fn send(mailbox_id: u16, data: usize) void {
34 _ = syscall2(SYS_send, mailbox_id, data);
59pub fn send(message: &const Message) void {
60 _ = syscall1(SYS_send, @ptrToInt(message));
3561}
3662
37pub fn receive(mailbox_id: u16) usize {
38 return syscall1(SYS_receive, mailbox_id);
63pub fn receive(destination: &Message) void {
64 _ = syscall1(SYS_receive, @ptrToInt(destination));
3965}
4066
4167pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool {