From 433a2169193a1c568b4d5e02f0604e51339b6085 Mon Sep 17 00:00:00 2001 From: Sebastian Sumpf Date: Thu, 20 Feb 2014 11:27:26 +0100 Subject: [PATCH] base: Fix stack pointer alignment for ARM After some research we found that the stack pointer on ARM platforms must be at least double word aligned (See: "Procedure Call Standard for the ARM Architecture" - 5.2.1.1). Since a 'call' on ARM will not result in a stack pointer change (like on x86), the current behavior resulted in a 4 Byte aligned stack only. Follow up to #1043 --- base/include/arm/cpu/consts.h | 27 +++++++++++++++++++++++++++ base/include/base/thread.h | 5 +++-- base/include/x86/cpu/consts.h | 9 +++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 base/include/arm/cpu/consts.h diff --git a/base/include/arm/cpu/consts.h b/base/include/arm/cpu/consts.h new file mode 100644 index 0000000000..39758f6ba5 --- /dev/null +++ b/base/include/arm/cpu/consts.h @@ -0,0 +1,27 @@ +/* + * \brief Constants definitions for the ARM architecture. + * \author Sebastian Sumpf + * \date 2014-02-20 + */ + +/* + * Copyright (C) 2011-2013 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _INCLUDE__ARM__CPU__CONSTS_H_ +#define _INCLUDE__ARM__CPU__CONSTS_H_ + +#include + +namespace Abi { + /** + * On ARM a call (or branch) will not change the stack pointer, so we do not + * need stack adjustment + */ + static constexpr Genode::size_t stack_adjustment() { return 0; } +} + +#endif /* _INCLUDE__ARM__CPU__CONSTS_H_ */ diff --git a/base/include/base/thread.h b/base/include/base/thread.h index 4f1799a7b4..7fbb96845a 100644 --- a/base/include/base/thread.h +++ b/base/include/base/thread.h @@ -59,6 +59,7 @@ #include #include #include +#include #include #include #include /* for 'Ram_dataspace_capability' type */ @@ -103,12 +104,12 @@ namespace Genode { * Top of stack * * The alignment matches an initial stack frame, which is - * sufficient for the AMD64 ABI (stack top + 8 is 16-byte + * sufficient for the AMD64 ABI (stack top + adjustment is 16-byte * aligned). */ addr_t stack_top() const { - return ((addr_t)_stack & ~0xf) - sizeof(addr_t); + return ((addr_t)_stack & ~0xf) - Abi::stack_adjustment(); } /** diff --git a/base/include/x86/cpu/consts.h b/base/include/x86/cpu/consts.h index 1b3d89b772..d8c6edef2a 100644 --- a/base/include/x86/cpu/consts.h +++ b/base/include/x86/cpu/consts.h @@ -14,6 +14,8 @@ #ifndef _INCLUDE__X86__CPU__CONSTS_H_ #define _INCLUDE__X86__CPU__CONSTS_H_ +#include + namespace X86 { enum Eflags_masks { @@ -32,4 +34,11 @@ namespace X86 { } +namespace Abi { + /** + * On x86 a call will result in a growth of the stack by machine word size + */ + static constexpr Genode::size_t stack_adjustment() { return sizeof(Genode::addr_t); } +} + #endif /* _INCLUDE__X86__CPU__CONSTS_H_ */