[ECOS] stack base pointer not align to 4 bytes

Xiaochen Zhou zhouxiaochen@h3c.com
Mon May 26 07:38:00 GMT 2008



>> 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



More information about the Ecos-discuss mailing list