diff options
| author | Miguel <m.i@gmx.at> | 2018-09-01 12:10:13 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-09-01 12:10:13 +0200 |
| commit | 51ab94a29f64de42e3dec3a3ef0ec6a94cda28a6 (patch) | |
| tree | c2cf5f0b31c2f80ac815dc366ece52a42983219f /asm | |
| parent | d52c3d119dbbbf2a9573e7698a878cf74afdd08c (diff) | |
working on new syscalls
Diffstat (limited to 'asm')
| -rw-r--r-- | asm/int.s | 128 | ||||
| -rw-r--r-- | asm/task.s | 12 |
2 files changed, 83 insertions, 57 deletions
@@ -18,6 +18,11 @@ .global int128 +//temporary +.global asm_mouse_handler +.global asm_kb_handler + + // nothing to ack .macro ack0 .endm @@ -39,9 +44,42 @@ pop %eax // load original .endm -.macro intx ack num func +// 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 + + /* + Once we arrived here the stack already contains 3x 32bit values, + which will be poped by 'iret' + + - eflags + - return code segment selector + - return instruction pointer - \ack + There are two possiblities concerning our stack position: + + a) if the interrupt occured while kernel code was executed we are + on the same stack and have no clue about the stack alignment + + b) if the interrupt occured while user code was executed the + configured tss.esp0 was used, in this case we are at the start + of the esp0 stack. + */ + + \ack //acknowledge interrupt + //also remember that we will get new interrupts only + //after iret or reenabling themn explicitly! + + push $0x666 //make room for potential C functions 'return value'. + //we use eax already for esp (so we can context switch) pusha //Push all standard registers 8 regs x 4bytes/32bit push %ds //Push data segment @@ -49,78 +87,58 @@ push %fs push %gs - mov %esp,%eax - - and $-16,%esp // padding to align stack on 16byte boundary before CALL - push \num - push \num + mov %esp,%eax // remember THIS stack position - push \num - push %eax // pass in original %esp + and $-16,%esp // padding to align stack on 16byte boundary before CALL + sub $8,%esp // ... + push \num // pass in this interrupt number + push %eax // pass in original %esp (saved just few lines before) call \func + mov %eax,%esp // use the %esp we got from c function - mov %eax,%esp // use %esp we got - - pop %gs - pop %fs + pop %gs // pop everything back... + pop %fs // ... pop %es pop %ds popa - iret // pops the return instruction pointer, return code segment selector, and EFLAGS image from the stack + \retx // potentially set return value to eax to return to the caller -.endm + iret // pops the return instruction pointer, return code segment selector, and EFLAGS image from the stack -int0: intx ack1 $0 pit_handler -int1: intx ack1 $1 kb_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 mouse_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 - -pit_handler: - call pit_interrupt_handler - push $0 - push 8(%esp) - push 16(%esp) - call interrupt_handler - add $12,%esp - ret +.endm -kb_handler: +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 + +asm_kb_handler: push %eax mov $0x0,%eax in $0x60,%al pop %eax - push $0 - push 8(%esp) - push 16(%esp) - call interrupt_handler - add $12,%esp ret -mouse_handler: +asm_mouse_handler: push %eax mov $0x0,%eax in $0x60,%al pop %eax - push $0 - push 8(%esp) - push 16(%esp) - call interrupt_handler - add $12,%esp ret @@ -6,6 +6,8 @@ task_pusha: push $0x8 // code segment push $userfunc + push $0x666 + pusha push %ds @@ -17,13 +19,15 @@ task_pusha: now stack looks like: - param // esp+64 + param // esp+68 returnaddy eflags code segment userfunc + 0x666 + eax // rest by popa ecx edx @@ -40,7 +44,7 @@ task_pusha: */ - mov 64(%esp),%eax // get address of alternative stack where we want to simulate the pusha + mov 68(%esp),%eax // get address of alternative stack where we want to simulate the pusha mov (%esp),%ecx mov %ecx,(%eax) @@ -87,6 +91,9 @@ task_pusha: mov 56(%esp),%ecx mov %ecx,56(%eax) + mov 60(%esp),%ecx + mov %ecx,60(%eax) + pop %gs pop %fs pop %es @@ -97,5 +104,6 @@ task_pusha: pop %eax pop %eax pop %eax + pop %eax ret |
