syscall: syscall logging kinda

This commit is contained in:
Matheus
2022-10-22 23:39:38 -03:00
parent 4ef85eb2b3
commit f08e86bbc0
4 changed files with 110 additions and 4 deletions
+12
View File
@@ -0,0 +1,12 @@
#include <arch/io.h>
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]);
}
+7
View File
@@ -0,0 +1,7 @@
#ifndef _E9_H_INCLUDE
#define _E9_H_INCLUDE
void e9_putc(char c);
void e9_puts(char* s);
#endif
+25 -4
View File
@@ -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
+66
View File
@@ -0,0 +1,66 @@
#include <arch/e9.h>
#include <string.h>
#include <stdint.h>
#include <stddef.h>
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');
}