This is the mail archive of the
mailing list for the eCos project.
Re: Thread stack alignment requirements for ARM
- From: Stanislav Meduna <stano at meduna dot org>
- To: ecos-devel at ecos dot sourceware dot org
- Cc: Michael Bergandi <mbergandi at gmail dot com>
- Date: Thu, 23 Jun 2011 09:26:29 +0200
- Subject: Re: Thread stack alignment requirements for ARM
- References: <BANLkTinA1-0RC8bVsR4Pp=z+CNKODiizbw@mail.gmail.com>
On 23.06.2011 04:37, Michael Bergandi wrote:
> According to the ARM site, they say that stacks should be 16 byte
> aligned. Then, they go on to say that there are a couple ways that
> stack alignment requirement can be managed. One of which was if you
> are running on an OS and the OS has taken steps to ensure the
> requirement is met, then the application need not worry about it. I
> don't think I fully understand what this means exactly.
HAL_THREAD_INIT_CONTEXT forces the alignment of the stack - see e.g.
register CYG_WORD _sp_ = ((CYG_WORD)_sparg_) &~15;
> Our particular target is the mx27 (ARM9). Out of habit, we make all
> the memory for the thread stacks in our applications 4 byte aligned.
> Is this enough? Is it really necessary?
Yes (but you are eventually wasting up to 12 bytes), no.
The linker script takes care of the sections and the
compiler and standard library (malloc) of the rest of the
It only matters if you are building some kind of compiler/
linker/dynamic loader functionality or if you are upcasting
some datatypes (such as int * to double *) - I got burned