Q about stack alignment on PowerPC.

Sergei Organov osv at javad.ru
Mon Sep 25 10:22:00 UTC 2000


Joel Sherrill <joel.sherrill at OARcorp.com> writes:

[...]

> I would think it should be something like this to be correct:
> 
>  sp = ((unsigned32) stack_base + size) & ~CPU_STACK_ALIGNMENT;
>  sp -= CPU_MINIMUM_STACK_FRAME_SIZE;
> 
> CPU_STACK_ALIGNMENT has to be a power of 2.  The stack grows down
> so the "&" is just going to lower the top of the stack 0-15 bytes.
> 
> If this works for you, please send a real patch back and let me know.

The right code is, I believe,

  sp = ((unsigned32) stack_base + size) & ~(CPU_STACK_ALIGNMENT - 1);
  sp -= CPU_MINIMUM_STACK_FRAME_SIZE;

Unfortunately, I can't quickly check this on latest RTEMS. It works for RTEMS
3.0 though. Due to the same reason I can't send a patch relative to reasonably 
recent RTEMS sources.

BTW, does the latest RTEMS use dedicated interrupt stack on PowerPC? If so,
where the stack pointer is initialized? There was a separate peace of code in
earlier versions of RTEMS, but I can't find it in the latest snapshot.

BR,
Sergei.





More information about the users mailing list