This is the mail archive of the ecos-discuss@sourceware.org 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: stack base pointer not align to 4 bytes


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);
    }

    ....
    ....
    ....
}

Xiaochen Zhou

----- Original Message ----- 
From: "Chris Zimman" <czimman@bloomberg.com>
To: "Xiaochen Zhou" <zhouxiaochen@h3c.com>; <ecos-discuss@ecos.sourceware.org>
Sent: Friday, May 23, 2008 6:32 PM
Subject: RE: [ECOS] stack base pointer not align to 4 bytes


> If I change the line static char g_IC_Stack[IC_STACK_SIZE]; ---------->
> static int g_IC_Stack[IC_STACK_SIZE/4]; everything is OK.
> 
> I think this is my fault, but when I grep the eCos source tree, thera
> are many files using stack definition like me( for example:
> net/tcpip/current/src/ecos/support.c). And the kernel source
> code(Cyg_HardwareThread::attach_stack()) did not adjust the alignment
> automaticly.
> 
> My fault or eCos fault? Thanks!

It's not really a 'fault' either way, but if you have it declared as char,
it's definitely not guaranteed to be word aligned.  I think the examples you
point out in eCos are probably bugs, at least on platforms that need aligned
access.

An alternative means for specifying alignment is to use
__attribute__((aligned)), eg.

static char g_IC_Stack[IC_STACK_SIZE] __attribute__((aligned(4)));

--Chris


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

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


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