[ECOS] idle thread stack alignment problem

Nick Garnett nickg@ecoscentric.com
Sun Dec 21 23:16:00 GMT 2003


"Uwe Kindler" <uwe_kindler@web.de> writes:

> Hello,
> 
> in order to debug the serial driver for the EDOSK platform, I created a
> simple application with one single thread. As soon, as the common serial
> eCos driver calls cyg_drv_cond_wait my application crashs. (At least it does
> not respond to GDB anymore).  If only one thread is present,
> cyg_drv_cond_wait causes a thread switch to the idle thread. When I create a
> second thread with an empty while loop my application runs well. So there
> must be a problem with the idle thread. After hours of debugging I found
> that the idle thread stack starts at an odd address. But for the H8S
> architecture its is required that the SP is always even (word or longword
> size operands when using SP). When I changed the declaration of the idle
> thread stack in this way:
> 
> static short
> idle_thread_stack[CYGNUM_KERNEL_CPU_MAX][CYGNUM_KERNEL_THREADS_IDLE_STACK_SI
> ZE/2];
> 
> everything works fine without a crash.
> 
> Is there a way to change the alignment of the thread stack without changing
> the thread.cxx sourcecode? I did not found any other way then the one
> described above.

The usual approach is to not worry about the lower limit of the stack,
but to align the SP in HAL_THREAD_INIT_CONTEXT() when the thread is
intialized. The size of HAL_SavedRegisters should also be set such
that when it is pushed during exception/interrupt processing the
stack alignment is preserved.



-- 
Nick Garnett                    eCos Kernel Architect
http://www.ecoscentric.com      The eCos and RedBoot experts


-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss



More information about the Ecos-discuss mailing list