More precise naming
This commit is contained in:
parent
52ef1aadcb
commit
9b7e4b535c
|
@ -3,44 +3,49 @@
|
|||
///////////////////////////
|
||||
|
||||
pub const Message = struct {
|
||||
from: MailboxId,
|
||||
to: MailboxId,
|
||||
payload: usize,
|
||||
sender: MailboxId,
|
||||
receiver: MailboxId,
|
||||
payload: usize,
|
||||
|
||||
pub fn from(mailbox_id: MailboxId) Message {
|
||||
pub fn withReceiver(mailbox_id: &const MailboxId) Message {
|
||||
return Message {
|
||||
.from = mailbox_id,
|
||||
.to = undefined,
|
||||
.payload = undefined,
|
||||
.sender = undefined,
|
||||
.receiver = *mailbox_id,
|
||||
.payload = undefined,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
pub const MailboxId = union(enum) {
|
||||
Me,
|
||||
This,
|
||||
Kernel,
|
||||
Port: u16,
|
||||
//Thread: u16,
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////
|
||||
//// Reserved mailboxes ////
|
||||
//////////////////////////////
|
||||
///////////////////////////////////////
|
||||
//// Ports reserved for services ////
|
||||
///////////////////////////////////////
|
||||
|
||||
pub const MBOX_TERMINAL = MailboxId { .Port = 0 };
|
||||
pub const Service = struct {
|
||||
pub const Terminal = MailboxId { .Port = 0 };
|
||||
pub const Keyboard = MailboxId { .Port = 1 };
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////
|
||||
//// Syscall numbers ////
|
||||
///////////////////////////
|
||||
|
||||
pub const SYS_exit = 0;
|
||||
pub const SYS_createPort = 1;
|
||||
pub const SYS_send = 2;
|
||||
pub const SYS_receive = 3;
|
||||
pub const SYS_map = 4;
|
||||
pub const SYS_createThread = 5;
|
||||
pub const Syscall = enum {
|
||||
exit = 0,
|
||||
createPort = 1,
|
||||
send = 2,
|
||||
receive = 3,
|
||||
map = 4,
|
||||
createThread = 5,
|
||||
};
|
||||
|
||||
|
||||
////////////////////
|
||||
|
@ -48,28 +53,28 @@ pub const SYS_createThread = 5;
|
|||
////////////////////
|
||||
|
||||
pub fn exit(status: i32) noreturn {
|
||||
_ = syscall1(SYS_exit, @bitCast(usize, isize(status)));
|
||||
_ = syscall1(Syscall.exit, @bitCast(usize, isize(status)));
|
||||
unreachable;
|
||||
}
|
||||
|
||||
pub fn createPort(id: u16) void {
|
||||
_ = syscall1(SYS_createPort, id);
|
||||
_ = syscall1(Syscall.createPort, id);
|
||||
}
|
||||
|
||||
pub fn send(message: &const Message) void {
|
||||
_ = syscall1(SYS_send, @ptrToInt(message));
|
||||
_ = syscall1(Syscall.send, @ptrToInt(message));
|
||||
}
|
||||
|
||||
pub fn receive(destination: &Message) void {
|
||||
_ = syscall1(SYS_receive, @ptrToInt(destination));
|
||||
_ = syscall1(Syscall.receive, @ptrToInt(destination));
|
||||
}
|
||||
|
||||
pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool {
|
||||
return syscall4(SYS_map, v_addr, p_addr, size, usize(writable)) != 0;
|
||||
return syscall4(Syscall.map, v_addr, p_addr, size, usize(writable)) != 0;
|
||||
}
|
||||
|
||||
pub fn createThread(function: fn()void) u16 {
|
||||
return u16(syscall1(SYS_createThread, @ptrToInt(function)));
|
||||
return u16(syscall1(Syscall.createThread, @ptrToInt(function)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -77,20 +82,20 @@ pub fn createThread(function: fn()void) u16 {
|
|||
//// Syscall stubs ////
|
||||
/////////////////////////
|
||||
|
||||
pub inline fn syscall0(number: usize) usize {
|
||||
inline fn syscall0(number: usize) usize {
|
||||
return asm volatile ("int $0x80"
|
||||
: [ret] "={eax}" (-> usize)
|
||||
: [number] "{eax}" (number));
|
||||
}
|
||||
|
||||
pub inline fn syscall1(number: usize, arg1: usize) usize {
|
||||
inline fn syscall1(number: usize, arg1: usize) usize {
|
||||
return asm volatile ("int $0x80"
|
||||
: [ret] "={eax}" (-> usize)
|
||||
: [number] "{eax}" (number),
|
||||
[arg1] "{ecx}" (arg1));
|
||||
}
|
||||
|
||||
pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
|
||||
inline fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
|
||||
return asm volatile ("int $0x80"
|
||||
: [ret] "={eax}" (-> usize)
|
||||
: [number] "{eax}" (number),
|
||||
|
@ -98,7 +103,7 @@ pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
|
|||
[arg2] "{edx}" (arg2));
|
||||
}
|
||||
|
||||
pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
|
||||
inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
|
||||
return asm volatile ("int $0x80"
|
||||
: [ret] "={eax}" (-> usize)
|
||||
: [number] "{eax}" (number),
|
||||
|
@ -107,7 +112,7 @@ pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usi
|
|||
[arg3] "{ebx}" (arg3));
|
||||
}
|
||||
|
||||
pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
|
||||
inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
|
||||
return asm volatile ("int $0x80"
|
||||
: [ret] "={eax}" (-> usize)
|
||||
: [number] "{eax}" (number),
|
||||
|
@ -117,7 +122,7 @@ pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg
|
|||
[arg4] "{esi}" (arg4));
|
||||
}
|
||||
|
||||
pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize,
|
||||
inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize,
|
||||
arg4: usize, arg5: usize) usize
|
||||
{
|
||||
return asm volatile ("int $0x80"
|
||||
|
@ -130,7 +135,7 @@ pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize,
|
|||
[arg5] "{edi}" (arg5));
|
||||
}
|
||||
|
||||
pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize,
|
||||
inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize,
|
||||
arg4: usize, arg5: usize, arg6: usize) usize
|
||||
{
|
||||
return asm volatile ("int $0x80"
|
||||
|
|
Loading…
Reference in New Issue
Block a user