[Prev][Next][Index][Thread]
context switching/timer handler
hello,
I am designing a preemptible kernel with the help fo oskit and running
into some problems with the timer_handler/context switihing.
below is the code for the timer_handler....
-------------------------------------------
void
timer_handler(struct trap_state *ts)
{
chronon++;
if ((started_init) && ((chronon % 10) == 0) && !IN_KERNEL) {
if (curthread != IdleTask) { //curthread is the thread running when
the interrupt ocurred
curthread->eax = ts->eax;
curthread->ebx = ts->ebx;
curthread->ecx = ts->ecx;
curthread->edx = ts->edx;
curthread->esi = ts->esi;
curthread->edi = ts->edi;
curthread->eip = ts->eip;
curthread->retaddr = ts->eip;
out_thread = curthread;
Dispatch(); //Dispatch sets the new value of curthread
//a global variable, according to
//the scheduling policy.
ts->eax = curthread->eax;
ts->ebx = curthread->ebx;
ts->ecx = curthread->ecx;
ts->edx = curthread->edx;
ts->esi = curthread->esi;
ts->edi = curthread->edi;
ts->eflags = curthread->eflags;
in_thread = curthread ;
}
ts->eip = (unsigned int) do_switch;
//do_switch saves and restores the stack
// pointer esp which is not done by oskit
}
return;
}
---------------------------------------------------------------------------
the code for do_switch is as follows:
Note : esp and ebp are at offsets 8 and 12 in the struct thread.......
and the return address at offset 40...
-------------------------------------------------------------------------
.text
.align 4
.globl do_switch
.globl in_thread
.globl out_thread
do_switch:
cli
movl out_thread, %eax //stores the old context in eax...
movl %esp, 8(%eax) //saves esp
movl %ebp, 12(%eax) //saves ebp
movl in_thread, %eax //stores the new context in eax
movl 8(%eax), %esp //sets the new esp value
movl 12(%eax), %ebp //sets the new ebp value
movl 40(%eax), %ebx
pushl %ebx //pushes the new return address on
// the stack
movl in_thread, %eax
movl 20(%eax), %ebx //set the eax and the ebx values.
movl 16(%eax), %eax
sti
ret //return to the return address of the
// the thread in_thread
-------------------------------------------------------------------------------
We plan to run some vision applications on the kernel.
On running an object tracking application (for which we use the bttv
driver ported on to oskit..) ; the kernel inexplicably crashes after
about a minute.....
The call to Dispatch() also occurs in all the system calls....
On disabling the timer_handler (ie simply returning from
timer_handler() without doing anything)....the application runs fine
(context switching happens during system calls like sem_wait etc.)
any pointers on what could be wrong will be appreciated.....
thanx in advance
Puneet