diff --git a/sys/SConscript b/sys/SConscript index 9ffc3a5..633ef55 100644 --- a/sys/SConscript +++ b/sys/SConscript @@ -41,6 +41,7 @@ src_common = [ "kern/palloc.c", "kern/printf.c", "kern/spinlock.c", + "kern/syscall.c", "kern/thread.c", "dev/ahci.c", "dev/console.c", diff --git a/sys/amd64/trap.c b/sys/amd64/trap.c index 5eafb05..346dd11 100644 --- a/sys/amd64/trap.c +++ b/sys/amd64/trap.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -147,7 +148,8 @@ trap_entry(TrapFrame *tf) Debug_Breakpoint(tf); return; case T_SYSCALL: - kprintf("Userlevel syscall\n"); + kprintf("Syscall %016llx\n", tf->rdi); + tf->rax = Syscall_Entry(tf->rdi, tf->rsi, tf->rdx, tf->rcx, tf->r8, tf->r9); return; default: return; diff --git a/sys/include/syscall.h b/sys/include/syscall.h new file mode 100644 index 0000000..28af8d9 --- /dev/null +++ b/sys/include/syscall.h @@ -0,0 +1,44 @@ + +#ifndef __SYS_SYSCALL_H__ +#define __SYS_SYSCALL_H__ + +#define SYSCALL_NULL 0x00 +#define SYSCALL_TIME 0x01 +#define SYSCALL_EXIT 0x02 +#define SYSCALL_SPAWN 0x03 +#define SYSCALL_GETPID 0x04 + +// Memory +#define SYSCALL_MMAP 0x08 +#define SYSCALL_MUNMAP 0x09 +#define SYSCALL_MPROTECT 0x0A + +// Stream +#define SYSCALL_READ 0x10 +#define SYSCALL_WRITE 0x11 +#define SYSCALL_FLUSH 0x12 + +// File +#define SYSCALL_OPEN 0x18 +#define SYSCALL_CLOSE 0x19 +#define SYSCALL_MOVE 0x1A +#define SYSCALL_DELETE 0x1B +#define SYSCALL_SETLENGTH 0x1C + +// Threading +#define SYSCALL_THREADCREATE 0x30 +#define SYSCALL_THREADEXIT 0x31 +#define SYSCALL_THREADSLEEP 0x32 + +// Network +#define SYSCALL_SOCKET 0x40 +#define SYSCALL_BIND 0x41 +#define SYSCALL_CONNECT 0x42 +#define SYSCALL_LISTEN 0x43 +#define SYSCALL_SHUTDOWN 0x44 + +uint64_t Syscall_Entry(uint64_t syscall, uint64_t a1, uint64_t a2, + uint64_t a3, uint64_t a4, uint64_t a5); + +#endif /* __SYS_SYSCALL_H__ */ + diff --git a/sys/kern/syscall.c b/sys/kern/syscall.c new file mode 100644 index 0000000..9e400c7 --- /dev/null +++ b/sys/kern/syscall.c @@ -0,0 +1,97 @@ + +#include +#include + +#include +#include + +uint64_t +Syscall_Time() +{ + NOT_IMPLEMENTED(); + return 0; +} + +uint64_t +Syscall_Exit(uint64_t status) +{ + NOT_IMPLEMENTED(); + return 0; +} + +uint64_t +Syscall_Spawn(uint64_t path) +{ + NOT_IMPLEMENTED(); + return 0; +} + +uint64_t +Syscall_GetPID() +{ + NOT_IMPLEMENTED(); + return 0; +} + +uint64_t +Syscall_MMap(uint64_t addr, uint64_t len, uint64_t prot) +{ + NOT_IMPLEMENTED(); + return 0; +} + +uint64_t +Syscall_MUnmap(uint64_t addr, uint64_t len) +{ + NOT_IMPLEMENTED(); + return 0; +} + +uint64_t +Syscall_MProtect(uint64_t addr, uint64_t len, uint64_t prot) +{ + NOT_IMPLEMENTED(); + return 0; +} + +uint64_t +Syscall_Read(uint64_t fd, uint64_t addr, uint64_t length) +{ + NOT_IMPLEMENTED(); + return 0; +} + +uint64_t +Syscall_Write(uint64_t fd, uint64_t addr, uint64_t length) +{ + NOT_IMPLEMENTED(); + return 0; +} + +uint64_t +Syscall_Entry(uint64_t syscall, uint64_t a1, uint64_t a2, + uint64_t a3, uint64_t a4, uint64_t a5) +{ + switch (syscall) + { + case SYSCALL_NULL: + return 0; + case SYSCALL_TIME: + return Syscall_Time(); + case SYSCALL_EXIT: + return Syscall_Exit(a1); + case SYSCALL_MMAP: + return Syscall_MMap(a1, a2, a3); + case SYSCALL_MUNMAP: + return Syscall_MUnmap(a1, a2); + case SYSCALL_MPROTECT: + return Syscall_MProtect(a1, a2, a3); + case SYSCALL_READ: + return Syscall_Read(a1, a2, a3); + case SYSCALL_WRITE: + return Syscall_Write(a1, a2, a3); + default: + return (uint64_t)-1; + } +} +