Improve syscall definitions

- Allow constant id specification
- Define function signature in SYSCALL macro
- Move implementation into src/kernel/syscalls/*.cpp
This commit is contained in:
Justin C. Miller
2019-04-02 23:14:52 -07:00
parent 11a53e792f
commit 8375870af6
13 changed files with 173 additions and 97 deletions

View File

@@ -6,6 +6,7 @@ extern "C" {
int32_t fork();
void sleep(uint64_t til);
void debug();
void message(const char *msg);
int main(int, const char **);
}
@@ -15,6 +16,7 @@ int
main(int argc, const char **argv)
{
int32_t pid = getpid();
message("hello from nulldrv!");
//int32_t child = fork();
//debug();
for (int i = 1; i < 5; ++i)

View File

@@ -11,8 +11,8 @@ getpid:
push rbp
mov rbp, rsp
mov rax, 3 ; getpid syscall
syscall ; pid is now already in rax, so just return
mov rax, 0x02 ; getpid syscall
syscall ; pid is now already in rax, so just return
pop rbp
ret
@@ -22,7 +22,7 @@ debug:
push rbp
mov rbp, rsp
mov rax, 0 ; debug syscall
mov rax, 0x00 ; debug syscall
syscall
pop rbp
@@ -33,7 +33,7 @@ sleep:
push rbp
mov rbp, rsp
mov rax, 6 ; sleep syscall
mov rax, 0x21 ; sleep syscall
syscall
pop rbp
@@ -44,14 +44,26 @@ fork:
push rbp
mov rbp, rsp
mov rax, 0
mov rax, 0x00
syscall ; pid left in rax
pop rbp
ret
global message
message:
push rbp
mov rbp, rsp
; message should already be in rdi
mov rax, 0x10
syscall
pop rbp
ret
global _start
_start:
xor rbp, rbp ; Sentinel rbp