stack pointer usage

Ahmet Akkas akkas at lucent.com
Fri Jul 7 17:45:06 UTC 2000


Thanks Roy. Your information certainly helped me.

Ahmet Akkas


Roy Pollock wrote:
> 
> The stack pointer should be saved and restored in the _CPU_Context_switch
> routine along with the other non-temporary registers.
> 
> So the stack pointer used by the task is stored in the tasks context block
> when the task is not executing, and is identical to the a7 stack pointer
> when the task is executing.  (the contex block is structure
> Context_Control defined in the file cpu.h.  It is, IIRC, stored on the
> heap).
> 
> My knowledge of m68k assembly is pretty basic, but here's how it looks
> like it works.
> 
> RTEMS calls _CPU_Context_switch(from,to)
> where from and to are the threads to switch from and to
> at this point a7 is the stack pointer in the from task's context.
> Then it goes to the _CPU_Context_switch routine:
> 
> moval a7@(RUNCONTEXT_ARG),a0
> 
> which takes the first argument (from) off the stack and puts it in
> register a0.
> 
> movw sr,d1
> 
> saves the status register.
> 
> movml d1-d7/a2-a7,a0@
> saves all the registers, including the stack pointer, to the memory
> address pointed at by from.
> 
> moval a7@(HEIRCONTEXT_ARG),a0
> moves the second argument, two, from the current stack into a0.
> This is the address of the context block of the thread about to execute
> 
> movml a0@,d1-d7/a2-a7
> This restores _all_ the registers, including the stack pointer.
> The stack pointer has no been changed in the middle of the assembly
> language routine.  Then it restores the status register and returns.
> 
> Hope this answers your question,
> 
> Roy A. Pollock
> 
> On Fri, 7 Jul 2000, Ahmet Akkas wrote:
> 
> >
> > Hi everybody,
> >
> > In RTEMS, each task has its own stack. And I am just wondering
> > how stack pointer in the target architecture is set by task's
> > stack. For example, in m68k architecture a7 is the user stack
> > pointer. In the _CPU_Context_switch and _ISR_Handler assembly
> > routines, a7 user stack pointer is used and I did not see any
> > place where a7 gets the task's stack address. I am not OS person,
> > so I may have wrong interpretation of the RTEMS. But if somebody
> > gives me how RTEMS deals with stack pointer (interaction between
> > the stack pointer used in the architecture and task's stack),
> > I really appreciate it.
> >
> > Thanks a lot.
> >
> > Ahmet Akkas
> >



More information about the users mailing list