Re: non preemptive multi tasker
From: Tauno Voipio (tauno.voipio_at_iki.fi.NOSPAM.invalid)
Date: Wed, 03 Dec 2003 19:31:19 GMT
"smitha" <firstname.lastname@example.org> wrote in message
> I am trying to develop a standalone embedded app that implements non
> preemptive multi tasker which use multiple stacks and switch between
> stacks at specified points.
> For that i go through PCthreads package which is using stack switching at
> assembly level.
> The piece of code switching the thread stack is as follows
> sys_switch_thread_stacks(stack_t * new,stack_t *current);
> where stack_t is defined as
> typedef struct STACK_HDR
> size_t elements;
> void * start_address;
> void * saved_stack_ptr;
> } stack_hdr_t;
> typedef struct STACK
> stack_hdr_t stack_hdr;
> unsigned int overrun_flag;
> unsigned int word; /* 4 byte words */
> } stack_t;
> pushl %ebp
> movl %esp, %ebp
> movl 12(%ebp), %eax
> 1 movl %esp, 8(%eax)
> movl 8(%ebp), %edx
> 2 movl 8(%edx), %esp
> popl %ebp
> In this line1 will store the current esp in location in
> void * saved_stack_pointer of currently active stack..
> In this line2 will store (void * saved_stack_pointer) of new stack to
> saved stack pointer is pointing to address of the function..
> But i can't figure out how the execution will return back to original
> Is there any other ways to implement the stack switching...
> Hoping ur help
1. A more appropriate group could be comp.arch.embedded, this has nothing
with Linux to do.
2. It is not sufficient to switch stacks: you have to switch the volatile
registers also. The register switching may be implemented with pushing all
registers, switching stacks and popping the new registers back.
3. The return address is in the stack. When the switcher returns, it gets to
the point after the call in the current thead.
tauno voipio @ iki fi