Skip to content

Commit

Permalink
cpu/arm7_common: Silence -Wcast-align
Browse files Browse the repository at this point in the history
- Enforced that ISR_STACKSIZE is indeed a multiple of 4
- With this enforced, every cast that triggers a -Wcast-align warning is now
  a false positives, so those were silenced by (intermediately) casting to
  `uintptr_t`.
  • Loading branch information
maribu committed Sep 28, 2020
1 parent cc23822 commit 833afc0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cpu/arm7_common/arm_cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ __attribute__((used, section(".irq_stack"), aligned(4))) uint8_t irq_stack[ISR_S
__attribute__((used, section(".abt_stack"), aligned(4))) uint8_t abt_stack[ABT_STACKSIZE];
__attribute__((used, section(".svc_stack"), aligned(4))) uint8_t svc_stack[ISR_STACKSIZE];

#if (ISR_STACKSIZE % 4)
#error "ISR_STACKSIZE must be a multiple of 4"
#endif

void thread_yield_higher(void)
{
if (irq_is_in()) {
Expand Down Expand Up @@ -129,13 +133,14 @@ void *thread_isr_stack_pointer(void)
/* This function returns the number of bytes used on the ISR stack */
int thread_isr_stack_usage(void)
{
uint32_t *ptr = (uint32_t*) &irq_stack[0];
uint32_t *ptr = (uint32_t *)(uintptr_t)&irq_stack[0];
uint32_t *end = (uint32_t *)(uintptr_t)&irq_stack[ISR_STACKSIZE];

while(((*ptr) == STACK_CANARY_WORD) && (ptr < (uint32_t*) &irq_stack[ISR_STACKSIZE])) {
while(((*ptr) == STACK_CANARY_WORD) && (ptr < end)) {
++ptr;
}

ptrdiff_t num_used_words = (uint32_t*) &irq_stack[ISR_STACKSIZE] - ptr;
ptrdiff_t num_used_words = (uintptr_t)end - (uintptr_t)ptr;

return num_used_words;
}

0 comments on commit 833afc0

Please sign in to comment.