Re: non preemptive multi tasker

From: Tauno Voipio (tauno.voipio_at_iki.fi.NOSPAM.invalid)
Date: 12/03/03

  • Next message: Ivan Van den Bossche: "Address spaces"
    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


  • Next message: Ivan Van den Bossche: "Address spaces"

    Relevant Pages

    • schedule() && prev/current (Was: [PATCH 3/3] Make get_current() __attribute__((const)))
      ... registers or on the stack. ... switch_towill save all registers on the stack ... before actually switching, then when it switches current, it will also switch ... goto need_resched_nonpreemptible; ...
      (Linux-Kernel)
    • Re: process mapping
      ... I have a C++ scheduler, and when a process scheduled, ... the EIP is remembered after executing wait on, ... with a single stack. ... part of your task switching. ...
      (comp.lang.asm.x86)
    • Re: Differences in unhandled exception handling between Windows 2000 and 2003?
      ... switching stacks in the middle of a function written in C when using inline ... assembler and call a C function after doing stack switching so that you're ... >> 2000) that we would always get a .DMP file when our application had any ... > Why not implement your own UnhandledException filter? ...
      (microsoft.public.win32.programmer.kernel)
    • Re: RFC: i386: kill !4KSTACKS
      ... >> the kernel, either directly or indirectly. ... > idea of switching back to the original stack when the Windows driver calls ... should we execute Windows driver code with IRQs ...
      (Linux-Kernel)
    • Re: New Moogerfooger
      ... MIDI buttons to synch the channel switching of the two amp heads in my ... other stack goes into other... ... ill have them on a bypass switch for the time being so I can kick them ...
      (alt.guitar)