[rtems commit] riscv: Properly align the thread stack

Sebastian Huber sebh at rtems.org
Fri Jun 29 09:59:17 UTC 2018


Module:    rtems
Branch:    master
Commit:    04698ebd49f1d9eacccdcdfcff823d0d0966f7f5
Changeset: http://git.rtems.org/rtems/commit/?id=04698ebd49f1d9eacccdcdfcff823d0d0966f7f5

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Jun 27 08:42:48 2018 +0200

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 f558fbd..609c683 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 <hesham at alumni.york.ac.uk>
@@ -33,6 +34,7 @@
 #endif
 
 #include <rtems/score/cpu.h>
+#include <rtems/score/address.h>
 #include <rtems/score/riscv-utility.h>
 
 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 */



More information about the vc mailing list