Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- switchTask:
- cli #Clear interrupt flag, to prevent an interrupt from firing while task is switching
- mov 4(%esp), %eax # Move the top of the struct to eax
- mov 4(%eax), %ebx # EBX
- mov 8(%eax), %ecx # ECX
- mov 12(%eax), %edx # EDX
- mov 16(%eax), %esi # ESI
- mov 20(%eax), %edi # EDI
- mov 24(%eax), %esp # ESP
- push %eax # Save eax
- mov 32(%eax), %eax # Move EIP to EAX
- xchg (%esp), %eax # Move the new EIP value into esp, and eax is returned to its previous state
- mov 36(%eax), %ebp # EFLAGS
- push %ebp # Push the flags(stored in ebp)
- popf # Pop the value we just pushed into the flags register, restores interrupt flag, because each process is started with the interrupt flag on, and disabling it would kill the task system (secret info dont tell processes)
- mov 28(%eax), %ebp # EBP
- mov (%eax), %eax # Put EAX back
- push %eax
- mov $102, %ax
- mov %ax, (0xb8000) # put f at screen
- mov %ax, (0xb8002) # put f at screen
- mov %ax, (0xb8004) # put f at screen
- pop %eax
- sti
- ret # Return to the EIP in stack
- irq_common_stub:
- pushad
- mov ax, ds
- push eax
- mov ax, 0x10 ;0x10
- mov ds, ax
- mov es, ax
- mov fs, ax
- mov gs, ax
- mov eax, dr6
- push eax
- push esp ; At this point ESP is a pointer to where DS (and the rest
- ; of the interrupt handler state resides)
- ; Push ESP as 1st parameter as it's a
- ; pointer to a registers_t
- call irq_handler
- mov eax, [switch_task]
- cmp eax, 1
- je changeTasks
- add esp, 8 ; Remove the saved ESP on the stack. Efficient to just pop it
- ; into any register. You could have done: add esp, 4 as well
- pop ebx
- mov ds, bx
- mov es, bx
- mov fs, bx
- mov gs, bx
- popad
- add esp, 8
- sti
- iret
- changeTasks:
- mov eax, 1234567
- push eax
- mov eax, 0
- mov [switch_task], eax
- call store_global ; Set a global variable with C
- add esp, 72 ; "Pop" 18 values off the stack
- jmp irq_schedule ; Switch task
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement