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
This commit is contained in:
Sebastian Sumpf 2014-02-20 11:27:26 +01:00 committed by Norman Feske
parent df066521a5
commit 433a216919
3 changed files with 39 additions and 2 deletions

View File

@ -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 <base/stdint.h>
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_ */

View File

@ -59,6 +59,7 @@
#include <base/lock.h>
#include <base/native_types.h>
#include <base/trace/logger.h>
#include <cpu/consts.h>
#include <util/string.h>
#include <util/bit_allocator.h>
#include <ram_session/ram_session.h> /* 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();
}
/**

View File

@ -14,6 +14,8 @@
#ifndef _INCLUDE__X86__CPU__CONSTS_H_
#define _INCLUDE__X86__CPU__CONSTS_H_
#include <base/stdint.h>
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_ */