2018-01-07 01:43:08 -08:00
|
|
|
//////////////////////////////
|
|
|
|
//// Reserved mailboxes ////
|
|
|
|
//////////////////////////////
|
|
|
|
|
|
|
|
pub const MBOX_TERMINAL = 1;
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////
|
|
|
|
//// Syscall numbers ////
|
|
|
|
///////////////////////////
|
|
|
|
|
2018-01-08 09:16:23 -08:00
|
|
|
pub const SYS_exit = 0;
|
|
|
|
pub const SYS_createMailbox = 1;
|
|
|
|
pub const SYS_send = 2;
|
|
|
|
pub const SYS_receive = 3;
|
|
|
|
pub const SYS_map = 4;
|
|
|
|
pub const SYS_createThread = 5;
|
2018-01-07 01:43:08 -08:00
|
|
|
|
|
|
|
|
|
|
|
////////////////////
|
|
|
|
//// Syscalls ////
|
|
|
|
////////////////////
|
|
|
|
|
2018-01-25 01:10:11 -08:00
|
|
|
pub fn exit(status: i32) noreturn {
|
2018-01-08 09:16:23 -08:00
|
|
|
_ = syscall1(SYS_exit, @bitCast(usize, isize(status)));
|
|
|
|
unreachable;
|
|
|
|
}
|
|
|
|
|
2018-01-25 01:10:11 -08:00
|
|
|
pub fn createMailbox(id: u16) void {
|
2018-01-07 01:43:08 -08:00
|
|
|
_ = syscall1(SYS_createMailbox, id);
|
|
|
|
}
|
|
|
|
|
2018-01-25 01:10:11 -08:00
|
|
|
pub fn send(mailbox_id: u16, data: usize) void {
|
2018-01-07 01:43:08 -08:00
|
|
|
_ = syscall2(SYS_send, mailbox_id, data);
|
|
|
|
}
|
|
|
|
|
2018-01-25 01:10:11 -08:00
|
|
|
pub fn receive(mailbox_id: u16) usize {
|
2018-01-07 01:43:08 -08:00
|
|
|
return syscall1(SYS_receive, mailbox_id);
|
|
|
|
}
|
|
|
|
|
2018-01-25 01:10:11 -08:00
|
|
|
pub fn map(v_addr: usize, p_addr: usize, size: usize, writable: bool) bool {
|
2018-01-07 01:43:08 -08:00
|
|
|
return syscall4(SYS_map, v_addr, p_addr, size, usize(writable)) != 0;
|
|
|
|
}
|
|
|
|
|
2018-01-29 07:57:27 -08:00
|
|
|
pub fn createThread(function: fn()void) u16 {
|
2018-01-08 09:16:23 -08:00
|
|
|
return u16(syscall1(SYS_createThread, @ptrToInt(function)));
|
|
|
|
}
|
|
|
|
|
2018-01-07 01:43:08 -08:00
|
|
|
|
|
|
|
/////////////////////////
|
|
|
|
//// Syscall stubs ////
|
|
|
|
/////////////////////////
|
|
|
|
|
2018-01-25 01:10:11 -08:00
|
|
|
pub inline fn syscall0(number: usize) usize {
|
2018-01-07 01:43:08 -08:00
|
|
|
return asm volatile ("int $0x80"
|
|
|
|
: [ret] "={eax}" (-> usize)
|
|
|
|
: [number] "{eax}" (number));
|
|
|
|
}
|
|
|
|
|
2018-01-25 01:10:11 -08:00
|
|
|
pub inline fn syscall1(number: usize, arg1: usize) usize {
|
2018-01-07 01:43:08 -08:00
|
|
|
return asm volatile ("int $0x80"
|
|
|
|
: [ret] "={eax}" (-> usize)
|
|
|
|
: [number] "{eax}" (number),
|
|
|
|
[arg1] "{ecx}" (arg1));
|
|
|
|
}
|
|
|
|
|
2018-01-25 01:10:11 -08:00
|
|
|
pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
|
2018-01-07 01:43:08 -08:00
|
|
|
return asm volatile ("int $0x80"
|
|
|
|
: [ret] "={eax}" (-> usize)
|
|
|
|
: [number] "{eax}" (number),
|
|
|
|
[arg1] "{ecx}" (arg1),
|
|
|
|
[arg2] "{edx}" (arg2));
|
|
|
|
}
|
|
|
|
|
2018-01-25 01:10:11 -08:00
|
|
|
pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
|
2018-01-07 01:43:08 -08:00
|
|
|
return asm volatile ("int $0x80"
|
|
|
|
: [ret] "={eax}" (-> usize)
|
|
|
|
: [number] "{eax}" (number),
|
|
|
|
[arg1] "{ecx}" (arg1),
|
|
|
|
[arg2] "{edx}" (arg2),
|
|
|
|
[arg3] "{ebx}" (arg3));
|
|
|
|
}
|
|
|
|
|
2018-01-25 01:10:11 -08:00
|
|
|
pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
|
2018-01-07 01:43:08 -08:00
|
|
|
return asm volatile ("int $0x80"
|
|
|
|
: [ret] "={eax}" (-> usize)
|
|
|
|
: [number] "{eax}" (number),
|
|
|
|
[arg1] "{ecx}" (arg1),
|
|
|
|
[arg2] "{edx}" (arg2),
|
|
|
|
[arg3] "{ebx}" (arg3),
|
|
|
|
[arg4] "{esi}" (arg4));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize,
|
2018-01-25 01:10:11 -08:00
|
|
|
arg4: usize, arg5: usize) usize
|
2018-01-07 01:43:08 -08:00
|
|
|
{
|
|
|
|
return asm volatile ("int $0x80"
|
|
|
|
: [ret] "={eax}" (-> usize)
|
|
|
|
: [number] "{eax}" (number),
|
|
|
|
[arg1] "{ecx}" (arg1),
|
|
|
|
[arg2] "{edx}" (arg2),
|
|
|
|
[arg3] "{ebx}" (arg3),
|
|
|
|
[arg4] "{esi}" (arg4),
|
|
|
|
[arg5] "{edi}" (arg5));
|
|
|
|
}
|