This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Re: stack base pointer not align to 4 bytes
- From: Xiaochen Zhou <zhouxiaochen at h3c dot com>
- To: "Paul D. DeRocco" <pderocco at ix dot netcom dot com>, eCos Discuss <ecos-discuss at ecos dot sourceware dot org>
- Date: Mon, 26 May 2008 15:38:13 +0800
- Subject: Re: [ECOS] stack base pointer not align to 4 bytes
- References: <PGEAIGBPLOMOJDAPCOJHKEBJKPAB.pderocco@ix.netcom.com>
>> From: Xiaochen Zhou
>>
>> Here is the modified kernel/current/include/thread.inl fiile to
>> check and asjust stack alignment automaticly:
>>
>> inline void Cyg_HardwareThread::attach_stack(CYG_ADDRESS
>> s_base_p, cyg_uint32 s_size_p)
>> {
>> CYG_ADDRESS s_base = s_base_p;
>> cyg_uint32 s_size = s_size_p;
>>
>> // Check and adjust stack alignment automaticly
>> if( 0 != ((sizeof(CYG_WORD)-1) & (cyg_uint32)s_base)) {
>> s_base += sizeof(cyg_uint32);
>> s_base &= ~(sizeof(CYG_WORD)-1);
>> s_size -= sizeof(cyg_uint32);
>> }
>> if( 0 != ((sizeof(CYG_WORD)-1) & (cyg_uint32)s_size)) {
>> s_size &= ~(sizeof(CYG_WORD)-1);
>> }
>>
>> ....
>> ....
>> ....
>> }
>
> It seems to me that this is the wrong place to fix this, because the need
> for a particular alignment is hardware-dependent. The comment on this
> function indicates that there is a macro that will be used instead, if the
> HAL defines it. That seems like the place to do this sort of thing.
>
> --
>
> Ciao, Paul D. DeRocco
> Paul mailto:pderocco@ix.netcom.com
>
>
The comment on the function point the codes below, it support stack grown up and down architecture.
// -------------------------------------------------------------------------
// Attach a stack to this thread. If there is a HAL defined macro to
// do this, then we use that, otherwise assume a falling stack.
inline void Cyg_HardwareThread::attach_stack()
{
.....
#ifdef HAL_THREAD_ATTACH_STACK
HAL_THREAD_ATTACH_STACK(stack_ptr, stack_base, stack_size);
#else
stack_ptr = stack_base + stack_size;
#endif
.....
}
Xiaochen Zhou
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss