From 26d7333417b912fad1f2e1f79d492cbeb50ad177 Mon Sep 17 00:00:00 2001
From: Vincent Ollivier This list is unstable and subject to change between versions of MOROS. Any reference to a slice in the arguments (like Each syscall is documented with its raw interface and its high-level Rust API
+wrapper. Any reference to a slice in the arguments (like Any negative number returned indicates that an error has occurred. In the
-higher level API, this will be typically converted to a MOROS Syscalls
&str
or &[u8]
) will be
-converted into a pointer and a length before the syscall is made.&str
or &[u8]
) will need to
+be converted into a pointer and a length for the raw syscall.Result
type.Option
or a Result
+type.
At the lowest level a syscalls follows the System V ABI convention with the
+syscall number set in the RAX
register, and its arguments in the RDI
,
+ RSI
, RDX
, and R8
registers. The RAX
register is used for the return
+value.
Hello world example in assembly:
+ +[bits 64]
+
+section .data
+msg: db "Hello, World!", 10
+len: equ $-msg
+
+global _start
+section .text
+_start:
+ mov rax, 4 ; syscall number for WRITE
+ mov rdi, 1 ; standard output
+ mov rsi, msg ; addr of string
+ mov rdx, len ; size of string
+ int 0x80
+
+ mov rax, 1 ; syscall number for EXIT
+ mov rdi, 0 ; no error
+ int 0x80
+
fn exit(code: usize)
+ fn exit(code: ExitCode)
Terminate the calling process.
+ The code can be one of the following:
+
+ pub enum ExitCode {
+ Success = 0,
+ Failure = 1,
+ UsageError = 64,
+ DataError = 65,
+ OpenError = 128,
+ ReadError = 129,
+ ExecError = 130,
+ PageFaultError = 200,
+ ShellExit = 255,
+}
+
+
+ The ExitCode
is converted to a usize
for the raw syscall.
+
SPAWN (0x02)
fn spawn(path: &str, args: &[&str]) -> isize
@@ -50,7 +98,7 @@ WRITE (0x04)
OPEN (0x05)
- fn open(path: &str, flags: usize) -> isize
+ fn open(path: &str, flags: u8) -> isize
Open a file and return a file handle.
@@ -82,12 +130,12 @@ CLOSE (0x06)
INFO (0x07)
- fn info(path: &str, info: &mut FileInfo) -> isize
+ fn info(path: &str) -> Option<FileInfo>
Get informations on a file.
- This syscall will set the following attributes of the given structure:
+ A FileInfo
will be returned when successful:
struct FileInfo {
kind: FileType,
@@ -97,6 +145,10 @@ INFO (0x07)
}
+ The raw syscall takes the pointer and the length of a mutable reference to a
+ FileInfo
that will be overwritten on success and returns an isize
to
+indicate the result of the operation.
+
DUP (0x08)
fn dup(old_handle: usize, new_handle: usize) -> isize
@@ -170,14 +222,18 @@ LISTEN (0x0E)
fn listen(handle: usize, port: u16) -> isize
- Listen for incoming connections on a socket.
+ Listen for incoming connections to a socket.
ACCEPT (0x0F)
- fn accept(handle: usize, addr: IpAddress) -> isize
+ fn accept(handle: usize) -> Result<IpAddress>
- Accept incoming connection on a socket.
+ Accept an incoming connection to a socket.
+
+ The raw syscall takes the pointer and the length of a mutable reference to an
+ IpAddress
that will be overwritten on success and returns an isize
+indicating the result of the operation.
ALLOC (0x10)
@@ -195,11 +251,12 @@ FREE (0x11)
KIND (0x12)
- fn kind(handle: usize) -> isize
+ fn kind(handle: usize) -> Option<FileType>
- This syscall will return a integer corresponding to the FileType
of the given
-file handle when successful:
+ Return the file type of a file handle.
+
+ A FileType
will be returned when successful:
enum FileType {
Dir = 0,
@@ -207,6 +264,9 @@ KIND (0x12)
Device = 2,
}
+
+ The raw syscall returns an isize
that will be converted a FileType
if the
+number is positive.