diff options
Diffstat (limited to 'asm')
| -rw-r--r-- | asm/GDT.asm | 81 | ||||
| -rw-r--r-- | asm/asm.h | 27 | ||||
| -rw-r--r-- | asm/gdt.h | 1 | ||||
| -rw-r--r-- | asm/gdt.s (renamed from asm/helpers.s) | 14 | ||||
| -rw-r--r-- | asm/int.h | 28 | ||||
| -rw-r--r-- | asm/int.s | 135 | ||||
| -rw-r--r-- | asm/int_default_handler.asm | 15 | ||||
| -rw-r--r-- | asm/int_irq.asm | 155 | ||||
| -rw-r--r-- | asm/int_kb_handler.asm | 24 | ||||
| -rw-r--r-- | asm/int_mouse_handler.asm | 16 | ||||
| -rw-r--r-- | asm/int_syscall_handler.asm | 256 | ||||
| -rw-r--r-- | asm/mp.asm | 1 | ||||
| -rw-r--r-- | asm/mp.h | 1 | ||||
| -rw-r--r-- | asm/pic.asm | 4 | ||||
| -rw-r--r-- | asm/pic.h | 1 | ||||
| -rw-r--r-- | asm/pit.h | 6 | ||||
| -rw-r--r-- | asm/pit.s | 41 | ||||
| -rw-r--r-- | asm/read_eip.asm | 6 | ||||
| -rw-r--r-- | asm/start.h | 14 | ||||
| -rw-r--r-- | asm/start.s | 23 | ||||
| -rw-r--r-- | asm/syscall.h | 11 | ||||
| -rw-r--r-- | asm/syscall.s | 17 | ||||
| -rw-r--r-- | asm/task.s | 9 | ||||
| -rw-r--r-- | asm/usermode.h | 9 | ||||
| -rw-r--r-- | asm/usermode.s | 4 |
25 files changed, 183 insertions, 716 deletions
diff --git a/asm/GDT.asm b/asm/GDT.asm deleted file mode 100644 index 444c313..0000000 --- a/asm/GDT.asm +++ /dev/null @@ -1,81 +0,0 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;;;;; 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/asm/asm.h b/asm/asm.h deleted file mode 100644 index 8433e4e..0000000 --- a/asm/asm.h +++ /dev/null @@ -1,27 +0,0 @@ -void pic_setup(); - -void int_kb_handler(); -void int_mouse_handler(); -void int_default_handler(); - -void int_syscall_handler(); - -void int_irq0(); -void int_irq1(); -void int_irq2(); -void int_irq3(); -void int_irq4(); -void int_irq5(); -void int_irq6(); -void int_irq7(); -void int_irq8(); -void int_irq9(); -void int_irq10(); -void int_irq11(); -void int_irq12(); -void int_irq13(); -void int_irq14(); -void int_irq15(); -void int_irq16(); -void int_irq17(); -void int_irq18(); diff --git a/asm/gdt.h b/asm/gdt.h new file mode 100644 index 0000000..f5bcbd3 --- /dev/null +++ b/asm/gdt.h @@ -0,0 +1 @@ +void asm_setup_gdt(uint32_t addr, uint32_t size) diff --git a/asm/helpers.s b/asm/gdt.s index 135443d..698dcf6 100644 --- a/asm/helpers.s +++ b/asm/gdt.s @@ -1,9 +1,9 @@ //http://wiki.osdev.org/GDT_Tutorial -.global setup_gdt -.global tss_flush +.global asm_setup_gdt +//.global tss_flush // call as setup_gdt(GDT,sizeof(GDT)) -setup_gdt: +asm_setup_gdt: // re-fill gdt_descriptor with new GDT location and size movl 4(%esp),%eax @@ -32,10 +32,10 @@ setup_gdt: tss_flush: movw $0x2B,%ax # Load the index of our TSS structure - The index is - # 0x28, as it is the 5th selector and each is 8 bytes - # long, but we set the bottom two bits (making 0x2B) - # so that it has an RPL of 3, not zero. - ltr %ax # Load 0x2B into the task state register. + # 0x28, as it is the 5th selector and each is 8 bytes + # long, but we set the bottom two bits (making 0x2B) + # so that it has an RPL of 3, not zero. + ltr %ax # Load 0x2B into the task state register. ret @@ -14,4 +14,30 @@ void int12(); void int13(); void int14(); void int15(); -void int128(); + +void int128(); // syscalls +void int129(); // scheduler +void int255(); // unhandled + +void exc0(); +void exc1(); +void exc2(); +void exc3(); +void exc4(); +void exc5(); +void exc6(); +void exc7(); +void exc8(); +void exc9(); +void exc10(); +void exc11(); +void exc12(); +void exc13(); +void exc14(); +void exc15(); +void exc16(); +void exc17(); +void exc18(); + +void asm_mouse_handler(); +void asm_kb_handler(); @@ -17,11 +17,48 @@ .global int15 .global int128 +.global int129 +.global int255 + +.global exc0 +.global exc1 +.global exc2 +.global exc3 +.global exc4 +.global exc5 +.global exc6 +.global exc7 +.global exc8 +.global exc9 +.global exc10 +.global exc11 +.global exc12 +.global exc13 +.global exc14 +.global exc15 +.global exc16 +.global exc17 +.global exc18 //temporary .global asm_mouse_handler .global asm_kb_handler +asm_kb_handler: + push %eax + mov $0x0,%eax + in $0x60,%al + pop %eax + ret + +asm_mouse_handler: + push %eax + mov $0x0,%eax + in $0x60,%al + pop %eax + ret + +/////////////// // nothing to ack .macro ack0 @@ -44,17 +81,9 @@ pop %eax // load original .endm -// ignore return value -.macro ret0 - add $4,%esp -.endm -// put return value in %eax -.macro ret1 - pop %eax -.endm -.macro intx ack retx num func +.macro intx ack num func /* Once we arrived here the stack already contains 3x 32bit values, @@ -81,6 +110,8 @@ push $0x666 //make room for potential C functions 'return value'. //we use eax already for esp (so we can context switch) + push $0x0 //indicate if we want to return the value in ebx 0x0=NO + pusha //Push all standard registers 8 regs x 4bytes/32bit push %ds //Push data segment push %es //etc... @@ -103,42 +134,64 @@ pop %ds popa - \retx // potentially set return value to eax to return to the caller + cmp $0x0,(%esp) + je skip\num + pop %ebx + pop %ebx + jmp ret\num + skip\num: + add $8,%esp // potentially set return value to eax to return to the caller + ret\num: iret // pops the return instruction pointer, return code segment selector, and EFLAGS image from the stack .endm -int0: intx ack1 ret0 $0 interrupt_handler -int1: intx ack1 ret0 $1 interrupt_handler -int2: intx ack1 ret0 $2 interrupt_handler -int3: intx ack1 ret0 $3 interrupt_handler -int4: intx ack1 ret0 $4 interrupt_handler -int5: intx ack1 ret0 $5 interrupt_handler -int6: intx ack1 ret0 $6 interrupt_handler -int7: intx ack1 ret0 $7 interrupt_handler - -int8: intx ack2 ret0 $8 interrupt_handler -int9: intx ack2 ret0 $9 interrupt_handler -int10: intx ack2 ret0 $10 interrupt_handler -int11: intx ack2 ret0 $11 interrupt_handler -int12: intx ack2 ret0 $12 interrupt_handler -int13: intx ack2 ret0 $13 interrupt_handler -int14: intx ack2 ret0 $14 interrupt_handler -int15: intx ack2 ret0 $15 interrupt_handler - -int128: intx ack0 ret1 $128 interrupt_handler +.macro excx func + call \func + jmp . +.endm -asm_kb_handler: - push %eax - mov $0x0,%eax - in $0x60,%al - pop %eax - ret +int0: intx ack1 $0 interrupt_handler +int1: intx ack1 $1 interrupt_handler +int2: intx ack1 $2 interrupt_handler +int3: intx ack1 $3 interrupt_handler +int4: intx ack1 $4 interrupt_handler +int5: intx ack1 $5 interrupt_handler +int6: intx ack1 $6 interrupt_handler +int7: intx ack1 $7 interrupt_handler + +int8: intx ack2 $8 interrupt_handler +int9: intx ack2 $9 interrupt_handler +int10: intx ack2 $10 interrupt_handler +int11: intx ack2 $11 interrupt_handler +int12: intx ack2 $12 interrupt_handler +int13: intx ack2 $13 interrupt_handler +int14: intx ack2 $14 interrupt_handler +int15: intx ack2 $15 interrupt_handler + +int128: intx ack0 $128 interrupt_handler +int129: intx ack0 $129 interrupt_handler + +int255: intx ack0 $255 interrupt_handler + +exc0: excx exception_handle_0 +exc1: excx exception_handle_1 +exc2: excx exception_handle_2 +exc3: excx exception_handle_3 +exc4: excx exception_handle_4 +exc5: excx exception_handle_5 +exc6: excx exception_handle_6 +exc7: excx exception_handle_7 +exc8: excx exception_handle_8 +exc9: excx exception_handle_9 +exc10: excx exception_handle_10 +exc11: excx exception_handle_11 +exc12: excx exception_handle_12 +exc13: excx exception_handle_13 +exc14: excx exception_handle_14 +exc15: excx exception_handle_15 +exc16: excx exception_handle_16 +exc17: excx exception_handle_17 +exc18: excx exception_handle_18 -asm_mouse_handler: - push %eax - mov $0x0,%eax - in $0x60,%al - pop %eax - ret diff --git a/asm/int_default_handler.asm b/asm/int_default_handler.asm deleted file mode 100644 index 00aa1ac..0000000 --- a/asm/int_default_handler.asm +++ /dev/null @@ -1,15 +0,0 @@ -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/asm/int_irq.asm b/asm/int_irq.asm deleted file mode 100644 index ac8eef8..0000000 --- a/asm/int_irq.asm +++ /dev/null @@ -1,155 +0,0 @@ -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/asm/int_kb_handler.asm b/asm/int_kb_handler.asm deleted file mode 100644 index cd1b32c..0000000 --- a/asm/int_kb_handler.asm +++ /dev/null @@ -1,24 +0,0 @@ -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/asm/int_mouse_handler.asm b/asm/int_mouse_handler.asm deleted file mode 100644 index 9816950..0000000 --- a/asm/int_mouse_handler.asm +++ /dev/null @@ -1,16 +0,0 @@ -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/asm/int_syscall_handler.asm b/asm/int_syscall_handler.asm deleted file mode 100644 index 4031f3d..0000000 --- a/asm/int_syscall_handler.asm +++ /dev/null @@ -1,256 +0,0 @@ -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 @@ -38,6 +38,7 @@ boot_32_pm: mov eax, 1 ; semaphore xchg eax, [LLOCK] cmp eax,1 + hlt je $ jmp $ ; loop forever here diff --git a/asm/mp.h b/asm/mp.h new file mode 100644 index 0000000..d050012 --- /dev/null +++ b/asm/mp.h @@ -0,0 +1 @@ +void smp_go(); diff --git a/asm/pic.asm b/asm/pic.asm index 28b484c..901f854 100644 --- a/asm/pic.asm +++ b/asm/pic.asm @@ -4,7 +4,7 @@ [bits 32] -global pic_setup +global asm_pic_setup %define ICW_1 0x11 ; 00010001 binary. Enables initialization mode and we are sending ICW 4 @@ -17,7 +17,7 @@ global pic_setup %define IRQ_0 0x20 ; IRQs 0-7 mapped to use interrupts 0x20-0x27 %define IRQ_8 0x28 ; IRQs 8-15 mapped to use interrupts 0x28-0x36 -pic_setup: +asm_pic_setup: ; Send ICW 1 - Begin initialization ------------------------- diff --git a/asm/pic.h b/asm/pic.h new file mode 100644 index 0000000..0daea2a --- /dev/null +++ b/asm/pic.h @@ -0,0 +1 @@ +void asm_pic_setup(); @@ -16,10 +16,10 @@ #include <stdint.h> /** Init PIT - 25 times a second*/ -void pit_init(); +void asm_pit_init(); /** install this interrupt handler to your Interrupt Vector Table */ -void pit_interrupt_handler(); +void asm_pit_tick(); /** get number of ticks */ -uint32_t pit_get_ticks(); +uint32_t asm_pit_get_ticks(); @@ -1,16 +1,16 @@ -.global pit_init -.global pit_interrupt_handler -.global pit_get_ticks +.global asm_pit_init +.global asm_pit_tick +.global asm_pit_get_ticks ticks: .int 0 -pit_get_ticks: +asm_pit_get_ticks: mov (ticks),%eax ret -pit_interrupt_handler: +asm_pit_tick: push %eax // persist @@ -18,38 +18,11 @@ pit_interrupt_handler: mov $ticks, %eax incl (%eax) - // ACK IRQ - //mov $0x20,%al - //out %al,$0x20 - pop %eax // load original - /////// - - /* - pusha //Push all standard registers - push %ds //Push data segment - push %es //etc... - push %fs - push %gs - - mov %esp, %eax // remember current %esp - movl $stack_top, %esp // switch to our small scheduler stack - - push %eax // set original %esp as param and... - call task_switch_next // call scheduler - mov %eax, %esp // use %esp we got from scheduler - - pop %gs - pop %fs - pop %es - pop %ds - popa - - iret // pops the return instruction pointer, return code segment selector, and EFLAGS image from the stack -*/ ret -pit_init: + +asm_pit_init: // configure ticking 25 times a second // 1193180 / 25 = 47727.2 diff --git a/asm/read_eip.asm b/asm/read_eip.asm deleted file mode 100644 index 3341943..0000000 --- a/asm/read_eip.asm +++ /dev/null @@ -1,6 +0,0 @@ -; http://www.jamesmolloy.co.uk/tutorial_html/9.-Multitasking.html -[bits 32] -global read_eip -read_eip: - pop eax - jmp eax diff --git a/asm/start.h b/asm/start.h index ff30326..7b31b76 100644 --- a/asm/start.h +++ b/asm/start.h @@ -14,8 +14,20 @@ * The addresses for .smp and .multiboot are based on the assumption: * * 0x00000500 - 0x00007BFF : guaranteed free to use * * 0x00100000 - 0x00EFFFFF : free for use (if it exists) + * + * References + * ---------- + * * https://www.gnu.org/software/grub/manual/multiboot/multiboot.html#Boot-information-format + * * http://wiki.osdev.org/Bare_Bones */ -/** This will be called by a multiboot compilant boot-loader (i.e. grub2) */ +/** This will be called by a multiboot compilant boot-loader (i.e. grub2). + * Calls kernel_main() passing through eax and ebx: + * * eax - magic number + * * ebx - multiboot structure + * */ void _start(); +/** 16-bit entry point for application processors */ +void _start_smp(); + diff --git a/asm/start.s b/asm/start.s index bb12a7c..1d881b4 100644 --- a/asm/start.s +++ b/asm/start.s @@ -1,7 +1,9 @@ -# https://www.gnu.org/software/grub/manual/multiboot/multiboot.html#Boot-information-format -# http://wiki.osdev.org/Bare_Bones +.global _start +.global _start_smp +.global stack_top +.global stack_bottom -# Fill Multiboot Haeder, init stack and call kernel_main passing to params: +# Fill Multiboot Haeder, init stack and call kernel_main passing two params: # eax - magic number # ebx - multiboot structure @@ -16,7 +18,9 @@ # entry point for application processors at 0x7000 .section .smp .code16 -call smp_go # TODO: align later before going C +_start_smp: +jmp . +//call smp_go # TODO: align later before going C # Declare a header as in the Multiboot Standard. We put this into a special # section so we can force the header to be in the start of the final program. @@ -56,12 +60,8 @@ stack_top: # bootloader will jump to this position once the kernel has been loaded. It # doesn't make sense to return from this function as the bootloader is gone. .section .text -.global _start -.global stack_top -.global stack_bottom -.type _start, @function -_start: +_start: # To set up a stack, we simply set the esp register to point to the top of # our stack (as it grows downwards). @@ -73,10 +73,11 @@ _start: call kernel_main - # should never be reached - + # turn off interrupts and halt. + # this should never be reached cli hlt + .Lhang: jmp .Lhang diff --git a/asm/syscall.h b/asm/syscall.h deleted file mode 100644 index 2cadce4..0000000 --- a/asm/syscall.h +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Issue a System Call from Ring 3 / User Space - * - * Accepts up to 3 parameters. - * Check syscalls.h for details. - */ - -uint32_t syscall(uint32_t code, - uint32_t param_1, - uint32_t param_2, - uint32_t param_3); diff --git a/asm/syscall.s b/asm/syscall.s deleted file mode 100644 index 388b6fa..0000000 --- a/asm/syscall.s +++ /dev/null @@ -1,17 +0,0 @@ -.global syscall - -syscall: - - push %ebx // preserve (sysV abi convnetion) - - mov 0x8(%esp),%eax //syscall number - mov 0xC(%esp),%edx //p1 - mov 0x10(%esp),%ecx //p2 - mov 0x14(%esp),%ebx //p3 - - int $0x80 - mov %ebx, %eax // set as return value - - pop %ebx // preserve - ret - @@ -7,6 +7,7 @@ task_pusha: push $userfunc push $0x666 + push $0x0 pusha @@ -19,7 +20,7 @@ task_pusha: now stack looks like: - param // esp+68 + param // esp+72 returnaddy eflags @@ -44,7 +45,7 @@ task_pusha: */ - mov 68(%esp),%eax // get address of alternative stack where we want to simulate the pusha + mov 72(%esp),%eax // get address of alternative stack where we want to simulate the pusha happened mov (%esp),%ecx mov %ecx,(%eax) @@ -94,6 +95,9 @@ task_pusha: mov 60(%esp),%ecx mov %ecx,60(%eax) + mov 64(%esp),%ecx + mov %ecx,64(%eax) + pop %gs pop %fs pop %es @@ -105,5 +109,6 @@ task_pusha: pop %eax pop %eax pop %eax + pop %eax ret diff --git a/asm/usermode.h b/asm/usermode.h index 9b76db3..16597f2 100644 --- a/asm/usermode.h +++ b/asm/usermode.h @@ -1,7 +1,8 @@ -/* - * Switch to User Mode and returin to function given by pointer +/** + * @file + * Switch to User Mode and iret to function given by pointer * provide the address of a void func() that will be called without - * any params. + * any params via iret. */ -void usermode(uint32_t func); +void asm_usermode(uint32_t func); diff --git a/asm/usermode.s b/asm/usermode.s index 99cee49..71ecc1d 100644 --- a/asm/usermode.s +++ b/asm/usermode.s @@ -1,6 +1,6 @@ -.global usermode +.global asm_usermode -usermode: +asm_usermode: mov 0x4(%esp),%edx //get adress of passed : void func() //to be called in ring 3 |
