diff --git a/src/arch/x86_64/e9.c b/src/arch/x86_64/e9.c new file mode 100644 index 00000000..932f86fb --- /dev/null +++ b/src/arch/x86_64/e9.c @@ -0,0 +1,12 @@ +#include + +void e9_putc(char c){ + outb(0xE9, c); +} + +void e9_puts(char* s){ + size_t len = strlen(s); + + for(uintmax_t i = 0; i < len; ++i) + outb(0xE9, s[i]); +} diff --git a/src/arch/x86_64/include/arch/e9.h b/src/arch/x86_64/include/arch/e9.h new file mode 100644 index 00000000..99b28579 --- /dev/null +++ b/src/arch/x86_64/include/arch/e9.h @@ -0,0 +1,7 @@ +#ifndef _E9_H_INCLUDE +#define _E9_H_INCLUDE + +void e9_putc(char c); +void e9_puts(char* s); + +#endif diff --git a/src/arch/x86_64/syscall.asm b/src/arch/x86_64/syscall.asm index 8f8e9b63..fd84f634 100644 --- a/src/arch/x86_64/syscall.asm +++ b/src/arch/x86_64/syscall.asm @@ -110,9 +110,11 @@ asm_syscall_entry: add qword [gs:0], 8 ; fix it sti - + ; assemble and save context needed for some system calls + + push qword 0x43 ; ss push qword [rsp+8] ; rsp push r11 ; old rflags @@ -151,22 +153,41 @@ asm_syscall_entry: ; set up context for calls that need it - cmp rax, 12 ; fork - + cmp rax, 12 ; fork + jne .not_fork mov rdi, rsp jmp .do_syscall - + .not_fork: .do_syscall: + ; DEBUG STUFF + ;mov r15,rax + ; END DEBUG STUFF + call [func_table + rax * 8] ; restore entry state + ; DEBUG STUFF + + ;push rax + ;push rdx + + ;mov rsi,rdx + ;mov rdi,r15 + ;extern syscalllogger + ;call syscalllogger + + ;pop rdx + ;pop rax + + ; DEBUG STUFF END + mov r11, 0x43 ; user data mov es,r11 mov ds,r11 diff --git a/src/arch/x86_64/syscalllog.c b/src/arch/x86_64/syscalllog.c new file mode 100644 index 00000000..b63b2d45 --- /dev/null +++ b/src/arch/x86_64/syscalllog.c @@ -0,0 +1,66 @@ +#include +#include +#include +#include + +static char* syscalls[] = { + "syscall_libc_log", + "syscall_mmap", + "syscall_arch_ctl", + "syscall_gettid", + "syscall_open", + "syscall_read", + "syscall_lseek", + "syscall_close", + "syscall_isatty", + "syscall_write", + "syscall_stat", + "syscall_fstat", + "syscall_fork", + "syscall_execve", + "syscall_waitpid", + "syscall_exit", + "syscall_dup", + "syscall_dup2", + "syscall_fcntl", + "syscall_getpid", + "syscall_getdirent", + "syscall_ioctl", + "syscall_chdir", + "syscall_fstatat", + "syscall_pipe2", + "syscall_mkdir", + "syscall_munmap", + "syscall_umask", + "syscall_poll", + "syscall_fchmodat", + "syscall_openat", + "syscall_chroot", + "syscall_mkdirat", + "syscall_clock_gettime", + "syscall_socket", + "syscall_bind", + "syscall_listen", + "syscall_connect", + "syscall_accept", + "syscall_nanosleep", + "syscall_fchmod", + "syscall_linkat" + +}; + +void syscalllogger(uint64_t num, uint64_t error){ + + e9_puts("syscall: "); + e9_puts(syscalls[num]); + e9_putc(':'); + char err[] = {'0', '0', '0', NULL}; + err[2] += error % 10; + error /= 10; + err[1] += error % 10; + error /= 10; + err[0] += error % 10; + e9_puts(err); + e9_putc('\n'); + +}