This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Powerpc stack initialization


On Mon, 2004-01-12 at 07:56, David POUTY wrote:
> I think there's a bug in stack initialization for PowerPC plateform in
> file vectors.S:
> - During '_start' a stack frame is created at the stack base for calls
> to C code.
> - In function 'cyg_hal_default_exception_vsr' 2 stacks frame are created
> (a null frame and one for C code) on the stack before calling the
> interrupt handler.
> 
> If CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK is defined to use
> the same stack for interrupt and threads then the stack is corrupted
> because there is only one frame free at the stack base.
> There's no problem if CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK
> is not defined because the 2 frames are created on the stack top.
> 
> So I propose the following patch:
> 
> Index: vectors.S
> ===================================================================
> RCS file:
> /cvs/ecos/ecos/packages/hal/powerpc/arch/current/src/vectors.S,v
> retrieving revision 1.32
> diff -u -r1.32 vectors.S
> --- vectors.S	8 Dec 2003 14:26:03 -0000	1.32
> +++ vectors.S	12 Jan 2004 14:20:33 -0000
> @@ -371,7 +371,10 @@
>          stw     r0,0(sp)                        # clear back chain
>          stw     r0,8(sp)                        # zero return pc
>          stwu    sp,-CYGARC_PPC_STACK_FRAME_SIZE(sp) # create new stack
> frame
> -
> +#ifdef CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK 
> +	stwu    sp,-CYGARC_PPC_STACK_FRAME_SIZE(sp) # create new stack
> frame
> +#endif
> +	
>          # Variant HALs may need to do something special before we
> continue
>          bl      hal_variant_init

I don't understand your patch/rationale.  This modification will only
affect the [interrupt] stack layout during system initialization.  It
should have no effect after the system is running since all threads
will be using their own stacks.

When CYGIMP_HAL_COMMON_INTERRUPTS_USE_INTERRUPT_STACK is defined, ISR 
and DSR routines are called using the interrupt stack (as opposed to
running these routines on the stack of the thread that was interrupted).
This stack is fully reset whenever such a change is made, so the patch
you propose would have no effect after threads start running.

n.b. this has been the default setting for many years and we've never
experienced a stack corruption problem on PowerPC systems that could
be explained this way.  I'm not saying that it's impossible for such
a problem to exist, rather that I'm sure we would have seen it by now.

Please feel free to explain your position (or critique mine!)


-- 
Gary Thomas <gary@mlbassoc.com>
MLB Associates


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]