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
This commit is contained in:
parent
753dfdba14
commit
75a1f693d1
|
@ -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
|
||||
|
@ -51,6 +51,26 @@
|
|||
#include "up_arch.h"
|
||||
#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 */
|
||||
|
|
Loading…
Reference in New Issue