diff options
author | Keith Packard <keithp@keithp.com> | 2016-12-17 20:58:36 -0800 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2016-12-17 21:04:33 -0800 |
commit | 89ecc32b90565ace078c4a84d4406a4d1f86821a (patch) | |
tree | 3b32f1d922380b3dfd25db75552a30dc84c24d41 /src/stm/ao_arch_funcs.h | |
parent | f650211f9e99e1d3d0ae13ae559dd1c082f71545 (diff) |
altos/arm: Align data so that gcc 5.4 doesn't do byte-accesses. Add -Wcast-align
Gcc 5.4.1 tracks alignment of data through assignments, so that a
uint32_t pointer which comes from byte-aligned uint8_t data:
extern uint8_t foo[];
uint32_t *q = (void *) foo;
Fetches and stores through this pointer are done bytewise. This is
slow (meh), but if q references a device register, things to bad very
quickly.
This patch works around this bug in the compiler by adding
__attribute__((aligned(4))) tags to some variables, or changing them
from uint8_t to uint32_t. Places doing this will now be caught as I've
added -Wcast-align to the compiler flags. That required adding (void
*) casts, after the relevant code was checked to make sure the
compiler could tell that the addresses were aligned.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/stm/ao_arch_funcs.h')
-rw-r--r-- | src/stm/ao_arch_funcs.h | 9 |
1 files changed, 2 insertions, 7 deletions
diff --git a/src/stm/ao_arch_funcs.h b/src/stm/ao_arch_funcs.h index 18ca20da..a9d0fa34 100644 --- a/src/stm/ao_arch_funcs.h +++ b/src/stm/ao_arch_funcs.h @@ -375,7 +375,7 @@ ao_arch_irq_check(void) { static inline void ao_arch_init_stack(struct ao_task *task, void *start) { - uint32_t *sp = (uint32_t *) (task->stack + AO_STACK_SIZE); + uint32_t *sp = (uint32_t *) ((void*) task->stack + AO_STACK_SIZE); uint32_t a = (uint32_t) start; int i; @@ -413,16 +413,11 @@ static inline void ao_arch_save_stack(void) { uint32_t *sp; asm("mov %0,sp" : "=&r" (sp) ); ao_cur_task->sp = (sp); - if ((uint8_t *) sp < &ao_cur_task->stack[0]) - ao_panic (AO_PANIC_STACK); } static inline void ao_arch_restore_stack(void) { - uint32_t sp; - sp = (uint32_t) ao_cur_task->sp; - /* Switch stacks */ - asm("mov sp, %0" : : "r" (sp) ); + asm("mov sp, %0" : : "r" (ao_cur_task->sp) ); /* Restore PRIMASK */ asm("pop {r0}"); |