authorgravatar for andrea@orru.ioAndrea Orru <andrea@orru.io> 2018-03-18 14:45:23-04:00
committergravatar for andrea@orru.ioAndrea Orru <andrea@orru.io> 2018-03-18 14:45:23-04:00
log935f10502f9308b262c3d4b979a3fbe20baf670f
tree0d4b7716f0eb52eb30e02fd9c02036d0e62b73ec
parentdf3d2115b5e45eefb3898d89307b05505c2f5b5a

Message type, Undefined mailbox, read syscall, more constructors


1 files changed, 36 insertions(+), 5 deletions(-)

std/os/zen.zig+36-5
...@@ -5,26 +5,39 @@...@@ -5,26 +5,39 @@
5pub const Message = struct {5pub const Message = struct {
6 sender: MailboxId,6 sender: MailboxId,
7 receiver: MailboxId,7 receiver: MailboxId,
8 type: usize,
8 payload: usize,9 payload: usize,
910
10 pub fn from(mailbox_id: &const MailboxId) Message {11 pub fn from(mailbox_id: &const MailboxId) Message {
11 return Message {12 return Message {
12 .sender = undefined,13 .sender = MailboxId.Undefined,
13 .receiver = *mailbox_id,14 .receiver = *mailbox_id,
14 .payload = undefined,15 .type = 0,
16 .payload = 0,
15 };17 };
16 }18 }
1719
18 pub fn to(mailbox_id: &const MailboxId, payload: usize) Message {20 pub fn to(mailbox_id: &const MailboxId, msg_type: usize) Message {
19 return Message {21 return Message {
20 .sender = MailboxId.This,22 .sender = MailboxId.This,
21 .receiver = *mailbox_id,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 .payload = payload,34 .payload = payload,
23 };35 };
24 }36 }
25};37};
2638
27pub const MailboxId = union(enum) {39pub const MailboxId = union(enum) {
40 Undefined,
28 This,41 This,
29 Kernel,42 Kernel,
30 Port: u16,43 Port: u16,
...@@ -55,14 +68,32 @@ pub const STDERR_FILENO = 2;...@@ -55,14 +68,32 @@ pub const STDERR_FILENO = 2;
55pub const getErrno = @import("linux/index.zig").getErrno;68pub const getErrno = @import("linux/index.zig").getErrno;
56use @import("linux/errno.zig");69use @import("linux/errno.zig");
5770
71// TODO: implement this correctly.
72pub 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// TODO: implement this correctly.90// TODO: implement this correctly.
59pub fn write(fd: i32, buf: &const u8, count: usize) usize {91pub fn write(fd: i32, buf: &const u8, count: usize) usize {
60 switch (fd) {92 switch (fd) {
61 STDIN_FILENO => unreachable,
62 STDOUT_FILENO, STDERR_FILENO => {93 STDOUT_FILENO, STDERR_FILENO => {
63 var i: usize = 0;94 var i: usize = 0;
64 while (i < count) : (i += 1) {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 else => unreachable,99 else => unreachable,