mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 14:53:47 +08:00
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:
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* arch/mips/src/common/up_createstack.c
|
* 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>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -51,6 +51,26 @@
|
|||||||
#include "up_arch.h"
|
#include "up_arch.h"
|
||||||
#include "up_internal.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
|
* 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 top_of_stack;
|
||||||
size_t size_of_stack;
|
size_t size_of_stack;
|
||||||
|
|
||||||
/* MIPS uses a push-down stack: the stack grows
|
/* MIPS uses a push-down stack: the stack grows toward lower
|
||||||
* toward loweraddresses in memory. The stack pointer
|
* addresses in memory. The stack pointer register points to the
|
||||||
* register, points to the lowest, valid work address
|
* lowest, valid working address (the "top" of the stack). Items on
|
||||||
* (the "top" of the stack). Items on the stack are
|
* the stack are referenced as positive word offsets from sp.
|
||||||
* referenced as positive word offsets from sp.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
|
top_of_stack = (uint32_t)tcb->stack_alloc_ptr + stack_size - 4;
|
||||||
|
|
||||||
/* The MIPS stack must be aligned at word (4 byte)
|
/* The MIPS stack must be aligned at word (4 byte) boundaries; for
|
||||||
* boundaries. If necessary top_of_stack must be rounded
|
* floating point use, the stack must be aligned to 8-byte addresses.
|
||||||
* down to the next boundary
|
* 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;
|
size_of_stack = top_of_stack - (uint32_t)tcb->stack_alloc_ptr + 4;
|
||||||
|
|
||||||
/* Save the adjusted stack values in the struct tcb_s */
|
/* Save the adjusted stack values in the struct tcb_s */
|
||||||
|
|||||||
Reference in New Issue
Block a user