diff options
| author | Miguel <m.i@gmx.at> | 2018-09-02 00:08:42 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-09-02 00:08:42 +0200 |
| commit | 8e3411139b27a3421e9ac75c13f14f99f6dd3137 (patch) | |
| tree | cf8b53ab02863117c310bde11ee4683e134cf1b2 /xxx/int_syscall_handler.asm | |
| parent | 0fff2e6dc6fae82da1c7978918a490c25cc36f04 (diff) | |
syscalls
Diffstat (limited to 'xxx/int_syscall_handler.asm')
| -rw-r--r-- | xxx/int_syscall_handler.asm | 256 |
1 files changed, 256 insertions, 0 deletions
diff --git a/xxx/int_syscall_handler.asm b/xxx/int_syscall_handler.asm new file mode 100644 index 0000000..4031f3d --- /dev/null +++ b/xxx/int_syscall_handler.asm @@ -0,0 +1,256 @@ +global int_syscall_handler +[extern task_fork] +[extern task_exit] +[extern task_wait] + + +[extern syscall_exit] +[extern syscall_write] +[extern syscall_read] +[extern syscall_readdir] +[extern syscall_execve] +[extern syscall_open] +[extern syscall_close] +[extern syscall_isatty] +[extern syscall_lseek] +[extern syscall_sbrk] +[extern syscall_stat] +[extern syscall_fork] +[extern syscall_poll] +[extern syscall_gettimeofday] +[extern syscall_unhandled] + +[bits 32] + +pid: dd 0x0 + +int_syscall_handler: + +cmp eax, 72 +je call_fork + +cmp eax, 60 +je call_exit + +cmp eax, 77 +je call_wait + + cli + + push ebx + push ecx + push edx + + cmp eax, 61 + je call_write + + cmp eax, 62 + je call_read + + cmp eax, 63 + je call_readdir + + cmp eax, 64 + je call_execve + + cmp eax, 65 + je call_open + + cmp eax, 66 + je call_close + + cmp eax, 68 + je call_isatty + + cmp eax, 69 + je call_lseek + + cmp eax, 70 + je call_sbrk + + cmp eax, 71 + je call_timeofday + + cmp eax, 74 + je call_stat + + cmp eax, 67 + je call_stat + + cmp eax, 79 + je call_stat + + cmp eax, 80 + je call_poll + + push eax + jmp call_unhandled + + +done: + + + +done_blocking: + + pop ebx + pop ecx + pop edx + + mov ebx,eax + + sti + + iret ;Interrupt-Return + +call_wait: + + cli + + pusha ;Push all standard registers + + mov ebx, esp ;save current stack pointer in esp + mov esp, 0x7000 ;now put the stack outside of virtual memory in kernel space! + + push ebx ;Push pointer to all the stuff we just pushed + + call task_wait ;Call C code + + mov esp, eax ;Replace the stack with what the C code gave us + + popa ;Put the standard registers back + + sti + + iretd ;Interrupt-Return + ;;;; + +call_exit: + + cli + + pusha ;Push all standard registers + + mov ebx, esp ;save current stack pointer in esp + mov esp, 0x7000 ;now put the stack outside of virtual memory in kernel space! + + push ebx ;Push pointer to all the stuff we just pushed + + call task_exit ;Call C code + + mov esp, eax ;Replace the stack with what the C code gave us + + popa ;Put the standard registers back + + sti + + iretd ;Interrupt-Return + ;;;; + +call_fork: + + pusha ;Push all standard registers + + push ds + push es + push fs + push gs + + mov ebx, esp ; pass it in + push ebx + call task_fork ;Call C code + pop ebx + + pop ds + pop es + pop fs + pop gs + + mov [pid],eax ; save return val, so it survives popa + + popa ;Put the standard registers back + + mov ebx,[pid] + + iretd ;Interrupt-Return + +call_timeofday: + call syscall_gettimeofday + jmp done + +call_stat: + call syscall_stat + jmp done + +call_write: + call syscall_write + jmp done + +call_open: + call syscall_open + jmp done + +call_readdir: + call syscall_readdir + jmp done + +call_close: + call syscall_close + jmp done + +call_isatty: + call syscall_isatty + jmp done + +call_lseek: + call syscall_lseek + jmp done + +call_sbrk: + call syscall_sbrk + jmp done + +call_poll: + call syscall_poll + jmp done + +call_unhandled: + call syscall_unhandled + jmp done ;this should never be called, since unhandled causes kernel panic + + + ;;; THIS CALLS NEED REENABLE INTERRUPTS BEFORE calling workers + ;; TODO: redesign this shit! +call_read: + + ;//mov al, 0x20 ;Port number AND command number to Acknowledge IRQ + ;//out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts + sti + + call syscall_read + + jmp done_blocking + +call_execve: + + pusha + + mov eax,esp + mov esp,0x7000 + + push ebx + push ecx + push edx + + mov ebx,eax + call syscall_execve + + pop eax + pop eax + pop eax + + mov esp,ebx + + popa + + jmp done |
