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 @@...@@ -3,44 +3,49 @@
3///////////////////////////3///////////////////////////
44
5pub const Message = struct {5pub const Message = struct {
6 from: MailboxId,6 sender: MailboxId,
7 to: MailboxId,7 receiver: MailboxId,
8 payload: usize,8 payload: usize,
99
10 pub fn from(mailbox_id: MailboxId) Message {10 pub fn withReceiver(mailbox_id: &const MailboxId) Message {
11 return Message {11 return Message {
12 .from = mailbox_id,12 .sender = undefined,
13 .to = undefined,13 .receiver = *mailbox_id,
14 .payload = undefined,14 .payload = undefined,
15 };15 };
16 }16 }
17};17};
1818
19pub const MailboxId = union(enum) {19pub const MailboxId = union(enum) {
20 Me,20 This,
21 Kernel,21 Kernel,
22 Port: u16,22 Port: u16,
23 //Thread: u16,23 //Thread: u16,
24};24};
2525
2626
27//////////////////////////////27///////////////////////////////////////
28//// Reserved mailboxes ////28//// Ports reserved for services ////
29//////////////////////////////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
34///////////////////////////37///////////////////////////
35//// Syscall numbers ////38//// Syscall numbers ////
36///////////////////////////39///////////////////////////
3740
38pub const SYS_exit = 0;41pub const Syscall = enum {
39pub const SYS_createPort = 1;42 exit = 0,
40pub const SYS_send = 2;43 createPort = 1,
41pub const SYS_receive = 3;44 send = 2,
42pub const SYS_map = 4;45 receive = 3,
43pub const SYS_createThread = 5;46 map = 4,
47 createThread = 5,
48};
4449
4550
46////////////////////51////////////////////
...@@ -48,28 +53,28 @@ pub const SYS_createThread = 5;...@@ -48,28 +53,28 @@ pub const SYS_createThread = 5;
48////////////////////53////////////////////
4954
50pub fn exit(status: i32) noreturn {55pub fn exit(status: i32) noreturn {
51 _ = syscall1(SYS_exit, @bitCast(usize, isize(status)));56 _ = syscall1(Syscall.exit, @bitCast(usize, isize(status)));
52 unreachable;57 unreachable;
53}58}
5459
55pub fn createPort(id: u16) void {60pub fn createPort(id: u16) void {
56 _ = syscall1(SYS_createPort, id);61 _ = syscall1(Syscall.createPort, id);
57}62}
5863
59pub fn send(message: &const Message) void {64pub fn send(message: &const Message) void {
60 _ = syscall1(SYS_send, @ptrToInt(message));65 _ = syscall1(Syscall.send, @ptrToInt(message));
61}66}
6267
63pub fn receive(destination: &Message) void {68pub fn receive(destination: &Message) void {
64 _ = syscall1(SYS_receive, @ptrToInt(destination));69 _ = syscall1(Syscall.receive, @ptrToInt(destination));
65}70}
6671
67pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool {72pub 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;
69}74}
7075
71pub fn createThread(function: fn()void) u16 {76pub fn createThread(function: fn()void) u16 {
72 return u16(syscall1(SYS_createThread, @ptrToInt(function)));77 return u16(syscall1(Syscall.createThread, @ptrToInt(function)));
73}78}
7479
7580
...@@ -77,20 +82,20 @@ pub fn createThread(function: fn()void) u16 {...@@ -77,20 +82,20 @@ pub fn createThread(function: fn()void) u16 {
77//// Syscall stubs ////82//// Syscall stubs ////
78/////////////////////////83/////////////////////////
7984
80pub inline fn syscall0(number: usize) usize {85inline fn syscall0(number: usize) usize {
81 return asm volatile ("int $0x80"86 return asm volatile ("int $0x80"
82 : [ret] "={eax}" (-> usize)87 : [ret] "={eax}" (-> usize)
83 : [number] "{eax}" (number));88 : [number] "{eax}" (number));
84}89}
8590
86pub inline fn syscall1(number: usize, arg1: usize) usize {91inline fn syscall1(number: usize, arg1: usize) usize {
87 return asm volatile ("int $0x80"92 return asm volatile ("int $0x80"
88 : [ret] "={eax}" (-> usize)93 : [ret] "={eax}" (-> usize)
89 : [number] "{eax}" (number),94 : [number] "{eax}" (number),
90 [arg1] "{ecx}" (arg1));95 [arg1] "{ecx}" (arg1));
91}96}
9297
93pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) usize {98inline fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
94 return asm volatile ("int $0x80"99 return asm volatile ("int $0x80"
95 : [ret] "={eax}" (-> usize)100 : [ret] "={eax}" (-> usize)
96 : [number] "{eax}" (number),101 : [number] "{eax}" (number),
...@@ -98,7 +103,7 @@ pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) usize {...@@ -98,7 +103,7 @@ pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
98 [arg2] "{edx}" (arg2));103 [arg2] "{edx}" (arg2));
99}104}
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 {
102 return asm volatile ("int $0x80"107 return asm volatile ("int $0x80"
103 : [ret] "={eax}" (-> usize)108 : [ret] "={eax}" (-> usize)
104 : [number] "{eax}" (number),109 : [number] "{eax}" (number),
...@@ -107,7 +112,7 @@ pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usi...@@ -107,7 +112,7 @@ pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usi
107 [arg3] "{ebx}" (arg3));112 [arg3] "{ebx}" (arg3));
108}113}
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 {
111 return asm volatile ("int $0x80"116 return asm volatile ("int $0x80"
112 : [ret] "={eax}" (-> usize)117 : [ret] "={eax}" (-> usize)
113 : [number] "{eax}" (number),118 : [number] "{eax}" (number),
...@@ -117,7 +122,7 @@ pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg...@@ -117,7 +122,7 @@ pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg
117 [arg4] "{esi}" (arg4));122 [arg4] "{esi}" (arg4));
118}123}
119124
120pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize,125inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize,
121 arg4: usize, arg5: usize) usize126 arg4: usize, arg5: usize) usize
122{127{
123 return asm volatile ("int $0x80"128 return asm volatile ("int $0x80"
...@@ -130,7 +135,7 @@ pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize,...@@ -130,7 +135,7 @@ pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize,
130 [arg5] "{edi}" (arg5));135 [arg5] "{edi}" (arg5));
131}136}
132137
133pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize,138inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize,
134 arg4: usize, arg5: usize, arg6: usize) usize139 arg4: usize, arg5: usize, arg6: usize) usize
135{140{
136 return asm volatile ("int $0x80"141 return asm volatile ("int $0x80"