diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-02-27 16:31:03 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-02-27 16:31:03 +0000 |
commit | 087496c688535e1717cd05d3f58635fb911abb4e (patch) | |
tree | b1a2ce334e5baa334bd2bb2073a2c7aa2ef14362 /nuttx/arch/mips/src/common/up_createstack.c | |
parent | 56bae3f8da4c6b9849323462f40a123c01df8608 (diff) | |
download | px4-nuttx-087496c688535e1717cd05d3f58635fb911abb4e.tar.gz px4-nuttx-087496c688535e1717cd05d3f58635fb911abb4e.tar.bz2 px4-nuttx-087496c688535e1717cd05d3f58635fb911abb4e.zip |
MIPS stack alignment fix for floating point from Helmut
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5681 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/arch/mips/src/common/up_createstack.c')
-rw-r--r-- | nuttx/arch/mips/src/common/up_createstack.c | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/nuttx/arch/mips/src/common/up_createstack.c b/nuttx/arch/mips/src/common/up_createstack.c index 722c1a35e..f72701042 100644 --- a/nuttx/arch/mips/src/common/up_createstack.c +++ b/nuttx/arch/mips/src/common/up_createstack.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/mips/src/common/up_createstack.c * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -52,6 +52,26 @@ #include "up_internal.h" /**************************************************************************** + * Pre-processor Macros + ****************************************************************************/ + +/* MIPS requires at least a 4-byte stack alignment. For floating point use, + * however, the stack must be aligned to 8-byte addresses. + */ + +#ifdef CONFIG_LIBC_FLOATINGPOINT +# define CONFIG_STACK_ALIGNMENT 8 +#else +# define CONFIG_STACK_ALIGNMENT 4 +#endif + +/* Stack alignment macros */ + +#define STACK_ALIGN_MASK (CONFIG_STACK_ALIGNMENT-1) +#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) +#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) + +/**************************************************************************** * Private Types ****************************************************************************/ @@ -107,21 +127,21 @@ int up_create_stack(struct tcb_s *tcb, size_t stack_size) size_t top_of_stack; size_t size_of_stack; - /* MIPS uses a push-down stack: the stack grows - * toward loweraddresses in memory. The stack pointer - * register, points to the lowest, valid work address - * (the "top" of the stack). Items on the stack are - * referenced as positive word offsets from sp. + /* MIPS uses a push-down stack: the stack grows toward lower + * addresses in memory. The stack pointer register points to the + * lowest, valid working address (the "top" of the stack). Items on + * the stack are referenced as positive word offsets from sp. */ top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4; - /* The MIPS stack must be aligned at word (4 byte) - * boundaries. If necessary top_of_stack must be rounded - * down to the next boundary + /* The MIPS stack must be aligned at word (4 byte) boundaries; for + * floating point use, the stack must be aligned to 8-byte addresses. + * If necessary top_of_stack must be rounded down to the next + * boundary to meet these alignment requirements. */ - top_of_stack &= ~3; + top_of_stack = STACK_ALIGN_DOWN(top_of_stack); size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4; /* Save the adjusted stack values in the struct tcb_s */ |