authorgravatar for andrea@orru.ioAndrea Orru <andrea@orru.io> 2018-03-15 02:22:03-07:00
committergravatar for andrea@orru.ioAndrea Orru <andrea@orru.io> 2018-03-15 02:22:03-07:00
log9b7e4b535c87c32d81fab88b92c967b04188212f
treeb717cdddd13c0263ec5de26d7d77d8dade0f1e4e
parent52ef1aadcb1e311ed65c7ae2054ae4b5b4e22364

More precise naming


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

std/os/zen.zig+36-31
......@@ -3,44 +3,49 @@
33///////////////////////////
44
55pub const Message = struct {
6 from: MailboxId,
7 to: MailboxId,
8 payload: usize,
6 sender: MailboxId,
7 receiver: MailboxId,
8 payload: usize,
99
10 pub fn from(mailbox_id: MailboxId) Message {
10 pub fn withReceiver(mailbox_id: &const MailboxId) Message {
1111 return Message {
12 .from = mailbox_id,
13 .to = undefined,
14 .payload = undefined,
12 .sender = undefined,
13 .receiver = *mailbox_id,
14 .payload = undefined,
1515 };
1616 }
1717};
1818
1919pub const MailboxId = union(enum) {
20 Me,
20 This,
2121 Kernel,
2222 Port: u16,
2323 //Thread: u16,
2424};
2525
2626
27//////////////////////////////
28//// Reserved mailboxes ////
29//////////////////////////////
27///////////////////////////////////////
28//// Ports reserved for services ////
29///////////////////////////////////////
3030
31pub const MBOX_TERMINAL = MailboxId { .Port = 0 };
31pub const Service = struct {
32 pub const Terminal = MailboxId { .Port = 0 };
33 pub const Keyboard = MailboxId { .Port = 1 };
34};
3235
3336
3437///////////////////////////
3538//// Syscall numbers ////
3639///////////////////////////
3740
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;
43pub const SYS_createThread = 5;
41pub const Syscall = enum {
42 exit = 0,
43 createPort = 1,
44 send = 2,
45 receive = 3,
46 map = 4,
47 createThread = 5,
48};
4449
4550
4651////////////////////
......@@ -48,28 +53,28 @@ pub const SYS_createThread = 5;
4853////////////////////
4954
5055pub fn exit(status: i32) noreturn {
51 _ = syscall1(SYS_exit, @bitCast(usize, isize(status)));
56 _ = syscall1(Syscall.exit, @bitCast(usize, isize(status)));
5257 unreachable;
5358}
5459
5560pub fn createPort(id: u16) void {
56 _ = syscall1(SYS_createPort, id);
61 _ = syscall1(Syscall.createPort, id);
5762}
5863
5964pub fn send(message: &const Message) void {
60 _ = syscall1(SYS_send, @ptrToInt(message));
65 _ = syscall1(Syscall.send, @ptrToInt(message));
6166}
6267
6368pub fn receive(destination: &Message) void {
64 _ = syscall1(SYS_receive, @ptrToInt(destination));
69 _ = syscall1(Syscall.receive, @ptrToInt(destination));
6570}
6671
6772pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool {
68 return syscall4(SYS_map, v_addr, p_addr, size, usize(writable)) != 0;
73 return syscall4(Syscall.map, v_addr, p_addr, size, usize(writable)) != 0;
6974}
7075
7176pub fn createThread(function: fn()void) u16 {
72 return u16(syscall1(SYS_createThread, @ptrToInt(function)));
77 return u16(syscall1(Syscall.createThread, @ptrToInt(function)));
7378}
7479
7580
......@@ -77,20 +82,20 @@ pub fn createThread(function: fn()void) u16 {
7782//// Syscall stubs ////
7883/////////////////////////
7984
80pub inline fn syscall0(number: usize) usize {
85inline fn syscall0(number: usize) usize {
8186 return asm volatile ("int $0x80"
8287 : [ret] "={eax}" (-> usize)
8388 : [number] "{eax}" (number));
8489}
8590
86pub inline fn syscall1(number: usize, arg1: usize) usize {
91inline fn syscall1(number: usize, arg1: usize) usize {
8792 return asm volatile ("int $0x80"
8893 : [ret] "={eax}" (-> usize)
8994 : [number] "{eax}" (number),
9095 [arg1] "{ecx}" (arg1));
9196}
9297
93pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
98inline fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
9499 return asm volatile ("int $0x80"
95100 : [ret] "={eax}" (-> usize)
96101 : [number] "{eax}" (number),
......@@ -98,7 +103,7 @@ pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
98103 [arg2] "{edx}" (arg2));
99104}
100105
101pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
106inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
102107 return asm volatile ("int $0x80"
103108 : [ret] "={eax}" (-> usize)
104109 : [number] "{eax}" (number),
......@@ -107,7 +112,7 @@ pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usi
107112 [arg3] "{ebx}" (arg3));
108113}
109114
110pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
115inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
111116 return asm volatile ("int $0x80"
112117 : [ret] "={eax}" (-> usize)
113118 : [number] "{eax}" (number),
......@@ -117,7 +122,7 @@ pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg
117122 [arg4] "{esi}" (arg4));
118123}
119124
120pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize,
125inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize,
121126 arg4: usize, arg5: usize) usize
122127{
123128 return asm volatile ("int $0x80"
......@@ -130,7 +135,7 @@ pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize,
130135 [arg5] "{edi}" (arg5));
131136}
132137
133pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize,
138inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize,
134139 arg4: usize, arg5: usize, arg6: usize) usize
135140{
136141 return asm volatile ("int $0x80"