Re: non preemptive multi tasker
From: Tauno Voipio (tauno.voipio_at_iki.fi.NOSPAM.invalid)
Date: 12/03/03
- Previous message: Ilari Liusvaara: "Re: how to close ssh connection but continue in the background?"
- In reply to: smitha: "non preemptive multi tasker"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 03 Dec 2003 19:31:19 GMT
"smitha" <smithavbaba@yahoo.co.in> wrote in message
news:9559d5af.0312030159.427ef788@posting.google.com...
> hi..
> 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[1]; /* 4 byte words */
>
> } stack_t;
>
> sys_switch_thread_stacks:
> 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
> ret
>
> In this line1 will store the current esp in location in
> structure(stack_t*)
> void * saved_stack_pointer of currently active stack..
>
> In this line2 will store (void * saved_stack_pointer) of new stack to
esp.
> saved stack pointer is pointing to address of the function..
>
> But i can't figure out how the execution will return back to original
> function...
>
> 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.
HTH
Tauno Voipio
tauno voipio @ iki fi
- Previous message: Ilari Liusvaara: "Re: how to close ssh connection but continue in the background?"
- In reply to: smitha: "non preemptive multi tasker"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|