Using djgpp interrupt wrapper for task switching
Posted: Sun May 09, 2004 4:04 am
Hi!
I'm writing a small os for school, and the deadline is pretty close
.
I've got problems with task switching. My idea is to use the interrupt wrapper of djgpp to do this (the one created by _go32_dpmi_chain_protected_mode_interrupt_wrapper()). I chained on the timer interrupt. The code of the wrapper looks like this:
The wrapper calls my interrupt handler with the "call _rmih" instruction. What I tried to do then is to change the stack pointer pushed before the function call to point to the new task's stack. This is done like this:
The two push-es before the actual task are because of the eip addresses pushed by function calls.
At first I just tried to switch between two tasks. But the OS seems to run only the one that was the first. And no task switch occurs. I checked the addresses that are loaded (_new_stack) and they are correct.
My question is that could this work, and is it me doing something wrong? Or is this idea totally wrong?
Thanks for your answers.
I'm writing a small os for school, and the deadline is pretty close

I've got problems with task switching. My idea is to use the interrupt wrapper of djgpp to do this (the one created by _go32_dpmi_chain_protected_mode_interrupt_wrapper()). I chained on the timer interrupt. The code of the wrapper looks like this:
Code: Select all
push ds
push es
push fs
push gs
pusha
mov ax, _our_selector
mov ds, ax
incl _call_count
cmpl _in_this_handler, $0
jne bypass
movb _in_this_handler, $1
mov es, ax
mov fs, ax
mov gs, ax
mov ebx, _local_stack
cld
mov ecx, esp
mov dx, ss
mov ss, ax
mov esp, ebx
push edx
push ecx
call _rmih
pop eax
pop ebx
mov ss, bx
movb _in_this_handler, $0
bypass: popa
nop
pop gs
pop fs
pop es
pop ds
Code: Select all
_CtxSwitch:
popl %eax
popl %ecx
popl _old_stack
pushl _new_stack
pushl %ecx
pushl %eax
At first I just tried to switch between two tasks. But the OS seems to run only the one that was the first. And no task switch occurs. I checked the addresses that are loaded (_new_stack) and they are correct.
My question is that could this work, and is it me doing something wrong? Or is this idea totally wrong?
Thanks for your answers.