From 04698ebd49f1d9eacccdcdfcff823d0d0966f7f5 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 27 Jun 2018 08:42:48 +0200 Subject: riscv: Properly align the thread stack Update #3433. --- cpukit/score/cpu/riscv/riscv-context-initialize.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cpukit/score/cpu/riscv/riscv-context-initialize.c b/cpukit/score/cpu/riscv/riscv-context-initialize.c index f558fbd591..609c683a03 100644 --- a/cpukit/score/cpu/riscv/riscv-context-initialize.c +++ b/cpukit/score/cpu/riscv/riscv-context-initialize.c @@ -1,4 +1,5 @@ /* + * Copyright (c) 2018 embedded brains GmbH * * Copyright (c) 2015 University of York. * Hesham Almatary @@ -33,6 +34,7 @@ #endif #include +#include #include void _CPU_Context_Initialize( @@ -45,12 +47,14 @@ void _CPU_Context_Initialize( void *tls_area ) { - uintptr_t stack = ((uintptr_t) stack_area_begin); + void *stack; - uintptr_t stack_high = stack + stack_area_size; + stack = _Addresses_Add_offset( stack_area_begin, stack_area_size ); + stack = _Addresses_Align_down( stack, CPU_STACK_ALIGNMENT ); /* Stack Pointer - sp/x2 */ - context->x[2] = stack_high; + context->x[2] = (uintptr_t) stack; + /* Frame Pointer - fp/x8 */ context->x[8] = stack_high; /* Return Address - ra/x1 */ -- cgit v1.2.3