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 | |
| parent | 0fff2e6dc6fae82da1c7978918a490c25cc36f04 (diff) | |
syscalls
Diffstat (limited to 'xxx')
| -rw-r--r-- | xxx/GDT.asm | 81 | ||||
| -rw-r--r-- | xxx/int_default_handler.asm | 15 | ||||
| -rw-r--r-- | xxx/int_irq.asm | 155 | ||||
| -rw-r--r-- | xxx/int_kb_handler.asm | 24 | ||||
| -rw-r--r-- | xxx/int_mouse_handler.asm | 16 | ||||
| -rw-r--r-- | xxx/int_syscall_handler.asm | 256 | ||||
| -rw-r--r-- | xxx/read_eip.asm | 6 |
7 files changed, 553 insertions, 0 deletions
diff --git a/xxx/GDT.asm b/xxx/GDT.asm new file mode 100644 index 0000000..53458ba --- /dev/null +++ b/xxx/GDT.asm @@ -0,0 +1,81 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;; Miguel's FoolOS Helper Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; Global Descriptor Table +; we have the null descriptor and a code and data block for a start +; +; 0x08 code segment +; 0x10 data segment +; +; this file contains pure data +; +; +; +; + +;global gdt_descriptor +;global gdt_start + +gdt_start: + +gdt_null: ;null descriptor (2 x 4 bytes) + dd 0x0 + dd 0x0 + +gdt_code: + ; flags: + ; present: 1 / privilege: 00 / type: 1 + ; code: 1 / conforming: 0 / readable: 1 / accessed: 0 + ; granularity: 1 / 16-bit default: 1 / 64-bit seg: 0 / AVL: 0 + dw 0xffff ;limit + dw 0x0 ;base + db 0x0 ;base + db 10011010b ;flags + db 11001111b ;flags & seg.limit + db 0x0 ;base + +gdt_data: + ; flags: + ; code: 0 / expand down: 0 / writable: 1 / accessed: 0 + dw 0xffff + dw 0x0 + db 0x0 + db 10010010b + db 11001111b + db 0x0 + +gdt16_code: + ; flags: + ; present: 1 / privilege: 00 / type: 1 + ; code: 1 / conforming: 0 / readable: 1 / accessed: 0 + ; granularity: 1 / 16-bit default: 1 / 64-bit seg: 0 / AVL: 0 + dw 0xffff ;limit + dw 0x0 ;base + db 0x0 ;base + db 10011010b ;flags + db 10001111b ;flags & seg.limit + db 0x0 ;base + +gdt16_data: + ; flags: + ; code: 0 / expand down: 0 / writable: 1 / accessed: 0 + dw 0xffff + dw 0x0 + db 0x0 + db 10010010b + db 10001111b + db 0x0 + +gdt_end: + +gdt_descriptor: + dw gdt_end-gdt_start-1 + dd gdt_start + +CODE_SEG equ gdt_code - gdt_start +DATA_SEG equ gdt_data - gdt_start +CODE16_SEG equ gdt16_code - gdt_start +DATA16_SEG equ gdt16_data - gdt_start + + diff --git a/xxx/int_default_handler.asm b/xxx/int_default_handler.asm new file mode 100644 index 0000000..00aa1ac --- /dev/null +++ b/xxx/int_default_handler.asm @@ -0,0 +1,15 @@ +global int_default_handler +[extern int_default] + +[bits 32] +int_default_handler: + + pusha + + call int_default + + mov al, 0x20 ;Port number AND command number to Acknowledge IRQ + out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts + + popa + iret ;Interrupt-Return diff --git a/xxx/int_irq.asm b/xxx/int_irq.asm new file mode 100644 index 0000000..ac8eef8 --- /dev/null +++ b/xxx/int_irq.asm @@ -0,0 +1,155 @@ +global int_irq0 +global int_irq1 +global int_irq2 +global int_irq3 +global int_irq4 +global int_irq5 +global int_irq6 +global int_irq7 +global int_irq8 +global int_irq9 +global int_irq10 +global int_irq11 +global int_irq12 +global int_irq13 +global int_irq14 +global int_irq15 +global int_irq16 +global int_irq17 +global int_irq18 + +[extern exception_handle] +[extern exception_handle_0] +[extern exception_handle_1] +[extern exception_handle_2] +[extern exception_handle_3] +[extern exception_handle_4] +[extern exception_handle_5] +[extern exception_handle_6] +[extern exception_handle_7] +[extern exception_handle_8] +[extern exception_handle_9] +[extern exception_handle_10] +[extern exception_handle_11] +[extern exception_handle_12] +[extern exception_handle_13] +[extern exception_handle_14] +[extern exception_handle_15] +[extern exception_handle_16] +[extern exception_handle_17] +[extern exception_handle_18] + +[bits 32] +int_irq0: + + cli + call exception_handle_0 ;this will never return due to panic! + jmp $ + +int_irq1: + + cli + call exception_handle_1 ;this will never return due to panic! + jmp $ + +int_irq2: + + cli + call exception_handle_2 ;this will never return due to panic! + jmp $ + +int_irq3: + + cli + call exception_handle_3 ;this will never return due to panic! + jmp $ + +int_irq4: + + cli + call exception_handle_4 ;this will never return due to panic! + jmp $ + +int_irq5: + + cli + call exception_handle_5 ;this will never return due to panic! + jmp $ + +int_irq6: + + cli + call exception_handle_6 ;this will never return due to panic! + jmp $ + +int_irq7: + + cli + call exception_handle_7 ;this will never return due to panic! + jmp $ + +int_irq8: + + cli + call exception_handle_8 ;this will never return due to panic! + jmp $ + +int_irq9: + + cli + call exception_handle_9;this will never return due to panic! + jmp $ + +int_irq10: + + cli + call exception_handle_10;this will never return due to panic! + jmp $ + +int_irq11: + + cli + call exception_handle_11;this will never return due to panic! + jmp $ + +int_irq12: + + cli + call exception_handle_12 ;this will never return due to panic! + jmp $ + +int_irq13: + + cli + call exception_handle_13;this will never return due to panic! + jmp $ + +int_irq14: + + cli + call exception_handle_14 ;this will never return due to panic! + jmp $ + +int_irq15: + + cli + call exception_handle_15 ;this will never return due to panic! + jmp $ + +int_irq16: + + cli + call exception_handle_16 ;this will never return due to panic! + jmp $ + +int_irq17: + + cli + call exception_handle_17 ;this will never return due to panic! + jmp $ + +int_irq18: + + cli + call exception_handle_18;this will never return due to panic! + jmp $ diff --git a/xxx/int_kb_handler.asm b/xxx/int_kb_handler.asm new file mode 100644 index 0000000..cd1b32c --- /dev/null +++ b/xxx/int_kb_handler.asm @@ -0,0 +1,24 @@ +global int_kb_handler +[extern keyboard_handle] +[extern int_default] + +[bits 32] + +int_kb_handler: + + pusha + + mov eax,0x0 + in al,0x60 + + push eax + call keyboard_handle + + pop eax + + mov al, 0x20 ;Port number AND command number to Acknowledge IRQ + out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts + + popa + +iretd ;Interrupt-Return diff --git a/xxx/int_mouse_handler.asm b/xxx/int_mouse_handler.asm new file mode 100644 index 0000000..9816950 --- /dev/null +++ b/xxx/int_mouse_handler.asm @@ -0,0 +1,16 @@ +global int_mouse_handler +[extern mouse_handler] + +[bits 32] +int_mouse_handler: + pusha + + call mouse_handler + + mov al, 0x20 ; Port number AND command number to Acknowledge IRQ + out 0xa0, al ; came from slave + out 0x20, al ; Acknowledge IRQ, so we keep getting interrupts + + popa + + iret ;Interrupt-Return 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 diff --git a/xxx/read_eip.asm b/xxx/read_eip.asm new file mode 100644 index 0000000..3341943 --- /dev/null +++ b/xxx/read_eip.asm @@ -0,0 +1,6 @@ +; http://www.jamesmolloy.co.uk/tutorial_html/9.-Multitasking.html +[bits 32] +global read_eip +read_eip: + pop eax + jmp eax |
