mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 00:14:22 +08:00
arch/risc-v: Fix stack alignment according to calling convention
The RISC-V Integer Calling Convention states that the stack pointer shall always be aligned to a 128-bit boundary upon procedure entry, both for RV32* and RV64* ISAs (exception to the RV32E ISA, which must follow a specific convention)
This commit is contained in:
committed by
Xiang Xiao
parent
91955be0e1
commit
7caebdd50f
@@ -150,16 +150,16 @@ exception_common:
|
|||||||
* Name: g_intstackalloc and g_intstacktop
|
* Name: g_intstackalloc and g_intstacktop
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
#if CONFIG_ARCH_INTERRUPTSTACK > 3
|
#if CONFIG_ARCH_INTERRUPTSTACK > 15
|
||||||
.bss
|
.bss
|
||||||
.align 4
|
.balign 16
|
||||||
.global g_intstackalloc
|
.global g_intstackalloc
|
||||||
.global g_intstacktop
|
.global g_intstacktop
|
||||||
.type g_intstackalloc, object
|
.type g_intstackalloc, object
|
||||||
.type g_intstacktop, object
|
.type g_intstacktop, object
|
||||||
g_intstackalloc:
|
g_intstackalloc:
|
||||||
.skip (CONFIG_ARCH_INTERRUPTSTACK & ~3)
|
.skip ((CONFIG_ARCH_INTERRUPTSTACK + 8) & ~15)
|
||||||
g_intstacktop:
|
g_intstacktop:
|
||||||
.size g_intstacktop, 0
|
.size g_intstacktop, 0
|
||||||
.size g_intstackalloc, (CONFIG_ARCH_INTERRUPTSTACK & ~3)
|
.size g_intstackalloc, (CONFIG_ARCH_INTERRUPTSTACK & ~15)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -264,16 +264,16 @@ exception_common:
|
|||||||
* Name: g_intstackalloc and g_intstacktop
|
* Name: g_intstackalloc and g_intstacktop
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
#if CONFIG_ARCH_INTERRUPTSTACK > 7
|
#if CONFIG_ARCH_INTERRUPTSTACK > 15
|
||||||
.bss
|
.bss
|
||||||
.align 8
|
.balign 16
|
||||||
.global g_intstackalloc
|
.global g_intstackalloc
|
||||||
.global g_intstacktop
|
.global g_intstacktop
|
||||||
.type g_intstackalloc, object
|
.type g_intstackalloc, object
|
||||||
.type g_intstacktop, object
|
.type g_intstacktop, object
|
||||||
g_intstackalloc:
|
g_intstackalloc:
|
||||||
.skip ((CONFIG_ARCH_INTERRUPTSTACK + 4) & ~7)
|
.skip ((CONFIG_ARCH_INTERRUPTSTACK + 8) & ~15)
|
||||||
g_intstacktop:
|
g_intstacktop:
|
||||||
.size g_intstacktop, 0
|
.size g_intstacktop, 0
|
||||||
.size g_intstackalloc, (CONFIG_ARCH_INTERRUPTSTACK & ~7)
|
.size g_intstackalloc, (CONFIG_ARCH_INTERRUPTSTACK & ~15)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -42,16 +42,9 @@
|
|||||||
* Pre-processor Macros
|
* Pre-processor Macros
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* RISC-V requires at least a 4-byte stack alignment.
|
/* RISC-V requires a 16-byte stack alignment. */
|
||||||
* For floating point use, however, the stack must be aligned to 8-byte
|
|
||||||
* addresses.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(CONFIG_LIBC_FLOATINGPOINT) || defined (CONFIG_ARCH_RV64GC)
|
#define STACK_ALIGNMENT 16
|
||||||
# define STACK_ALIGNMENT 8
|
|
||||||
#else
|
|
||||||
# define STACK_ALIGNMENT 4
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Stack alignment macros */
|
/* Stack alignment macros */
|
||||||
|
|
||||||
@@ -193,18 +186,16 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype)
|
|||||||
uintptr_t top_of_stack;
|
uintptr_t top_of_stack;
|
||||||
size_t size_of_stack;
|
size_t size_of_stack;
|
||||||
|
|
||||||
/* RISCV uses a push-down stack: the stack grows toward lower
|
/* RISC-V uses a push-down stack: the stack grows toward lower
|
||||||
* addresses in memory. The stack pointer register points to the
|
* addresses in memory. The stack pointer register points to the
|
||||||
* lowest, valid working address (the "top" of the stack). Items on
|
* lowest, valid working address (the "top" of the stack). Items on
|
||||||
* the stack are referenced as positive word offsets from sp.
|
* the stack are referenced as positive word offsets from SP.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
top_of_stack = (uintptr_t)tcb->stack_alloc_ptr + stack_size;
|
top_of_stack = (uintptr_t)tcb->stack_alloc_ptr + stack_size;
|
||||||
|
|
||||||
/* The RISC-V stack must be aligned at word (4 byte) boundaries; for
|
/* The RISC-V stack must be aligned at 128-bit (16-byte) boundaries.
|
||||||
* 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.
|
||||||
* If necessary top_of_stack must be rounded down to the next
|
|
||||||
* boundary to meet these alignment requirements.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
top_of_stack = STACK_ALIGN_DOWN(top_of_stack);
|
top_of_stack = STACK_ALIGN_DOWN(top_of_stack);
|
||||||
|
|||||||
@@ -37,16 +37,9 @@
|
|||||||
* Pre-processor Macros
|
* Pre-processor Macros
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* RISC-V requires at least a 4-byte stack alignment.
|
/* RISC-V requires a 16-byte stack alignment. */
|
||||||
* For floating point use, however, the stack must be aligned to 8-byte
|
|
||||||
* addresses.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(CONFIG_LIBC_FLOATINGPOINT) || defined (CONFIG_ARCH_RV64GC)
|
#define STACK_ALIGNMENT 16
|
||||||
# define STACK_ALIGNMENT 8
|
|
||||||
#else
|
|
||||||
# define STACK_ALIGNMENT 4
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Stack alignment macros */
|
/* Stack alignment macros */
|
||||||
|
|
||||||
|
|||||||
@@ -39,16 +39,9 @@
|
|||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* RISC-V requires at least a 4-byte stack alignment.
|
/* RISC-V requires a 16-byte stack alignment. */
|
||||||
* For floating point use, however, the stack must be aligned to 8-byte
|
|
||||||
* addresses.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if defined(CONFIG_LIBC_FLOATINGPOINT) || defined (CONFIG_ARCH_RV64GC)
|
#define STACK_ALIGNMENT 16
|
||||||
# define STACK_ALIGNMENT 8
|
|
||||||
#else
|
|
||||||
# define STACK_ALIGNMENT 4
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Stack alignment macros */
|
/* Stack alignment macros */
|
||||||
|
|
||||||
@@ -115,14 +108,13 @@ int up_use_stack(FAR struct tcb_s *tcb, FAR void *stack, size_t stack_size)
|
|||||||
/* RISC-V uses a push-down stack: the stack grows toward lower addresses in
|
/* RISC-V uses a push-down stack: the stack grows toward lower addresses in
|
||||||
* memory. The stack pointer register, points to the lowest, valid work
|
* memory. The stack pointer register, points to the lowest, valid work
|
||||||
* address (the "top" of the stack). Items on the stack are referenced
|
* address (the "top" of the stack). Items on the stack are referenced
|
||||||
* as positive word offsets from sp.
|
* as positive word offsets from SP.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
top_of_stack = (uintptr_t)tcb->stack_alloc_ptr + stack_size;
|
top_of_stack = (uintptr_t)tcb->stack_alloc_ptr + stack_size;
|
||||||
|
|
||||||
/* The RISC-V stack must be aligned at word (4 byte) or double word
|
/* The RISC-V stack must be aligned at 128-bit (16-byte) boundaries.
|
||||||
* (8 byte) boundaries. If necessary top_of_stack must be rounded down to
|
* If necessary top_of_stack must be rounded down to the next boundary.
|
||||||
* the next boundary.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
top_of_stack = STACK_ALIGN_DOWN(top_of_stack);
|
top_of_stack = STACK_ALIGN_DOWN(top_of_stack);
|
||||||
|
|||||||
@@ -42,14 +42,14 @@
|
|||||||
|
|
||||||
.section .noinit
|
.section .noinit
|
||||||
|
|
||||||
#if CONFIG_ARCH_INTERRUPTSTACK > 3
|
#if CONFIG_ARCH_INTERRUPTSTACK > 15
|
||||||
.align 4
|
.balign 16
|
||||||
.type g_intstackalloc, @object
|
.type g_intstackalloc, @object
|
||||||
.type g_intstacktop, @object
|
.type g_intstacktop, @object
|
||||||
g_intstackalloc:
|
g_intstackalloc:
|
||||||
.skip (CONFIG_ARCH_INTERRUPTSTACK & ~3)
|
.skip ((CONFIG_ARCH_INTERRUPTSTACK + 8) & ~15)
|
||||||
g_intstacktop:
|
g_intstacktop:
|
||||||
.size g_intstackalloc, (CONFIG_ARCH_INTERRUPTSTACK & ~3)
|
.size g_intstackalloc, (CONFIG_ARCH_INTERRUPTSTACK & ~15)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
@@ -201,16 +201,16 @@ exception_common:
|
|||||||
* Name: g_intstackalloc and g_intstacktop
|
* Name: g_intstackalloc and g_intstacktop
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
#if CONFIG_ARCH_INTERRUPTSTACK > 3
|
#if CONFIG_ARCH_INTERRUPTSTACK > 15
|
||||||
.bss
|
.bss
|
||||||
.align 4
|
.balign 16
|
||||||
.global g_intstackalloc
|
.global g_intstackalloc
|
||||||
.global g_intstacktop
|
.global g_intstacktop
|
||||||
.type g_intstackalloc, object
|
.type g_intstackalloc, object
|
||||||
.type g_intstacktop, object
|
.type g_intstacktop, object
|
||||||
g_intstackalloc:
|
g_intstackalloc:
|
||||||
.skip (CONFIG_ARCH_INTERRUPTSTACK & ~3)
|
.skip ((CONFIG_ARCH_INTERRUPTSTACK + 8) & ~15)
|
||||||
g_intstacktop:
|
g_intstacktop:
|
||||||
.size g_intstacktop, 0
|
.size g_intstacktop, 0
|
||||||
.size g_intstackalloc, (CONFIG_ARCH_INTERRUPTSTACK & ~3)
|
.size g_intstackalloc, (CONFIG_ARCH_INTERRUPTSTACK & ~15)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -242,24 +242,24 @@ normal_irq:
|
|||||||
* Name: g_intstackalloc and g_intstacktop
|
* Name: g_intstackalloc and g_intstacktop
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
#if CONFIG_ARCH_INTERRUPTSTACK > 7
|
#if CONFIG_ARCH_INTERRUPTSTACK > 15
|
||||||
.bss
|
.bss
|
||||||
.align 8
|
.balign 16
|
||||||
.global g_intstackalloc
|
.global g_intstackalloc
|
||||||
.global g_intstacktop
|
.global g_intstacktop
|
||||||
.type g_intstackalloc, object
|
.type g_intstackalloc, object
|
||||||
.type g_intstacktop, object
|
.type g_intstacktop, object
|
||||||
g_intstackalloc:
|
g_intstackalloc:
|
||||||
#ifndef CONFIG_SMP
|
#ifndef CONFIG_SMP
|
||||||
.skip ((CONFIG_ARCH_INTERRUPTSTACK + 4) & ~7)
|
.skip ((CONFIG_ARCH_INTERRUPTSTACK + 8) & ~15)
|
||||||
#else
|
#else
|
||||||
.skip (((CONFIG_ARCH_INTERRUPTSTACK * CONFIG_SMP_NCPUS) + 4) & ~7)
|
.skip (((CONFIG_ARCH_INTERRUPTSTACK * CONFIG_SMP_NCPUS) + 8) & ~15)
|
||||||
#endif
|
#endif
|
||||||
g_intstacktop:
|
g_intstacktop:
|
||||||
.size g_intstacktop, 0
|
.size g_intstacktop, 0
|
||||||
#ifndef CONFIG_SMP
|
#ifndef CONFIG_SMP
|
||||||
.size g_intstackalloc, (CONFIG_ARCH_INTERRUPTSTACK & ~7)
|
.size g_intstackalloc, (CONFIG_ARCH_INTERRUPTSTACK & ~15)
|
||||||
#else
|
#else
|
||||||
.size g_intstackalloc, ((CONFIG_ARCH_INTERRUPTSTACK * CONFIG_SMP_NCPUS) & ~7)
|
.size g_intstackalloc, ((CONFIG_ARCH_INTERRUPTSTACK * CONFIG_SMP_NCPUS) & ~15)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -188,16 +188,16 @@ exception_common:
|
|||||||
* Name: g_intstackalloc and g_intstacktop
|
* Name: g_intstackalloc and g_intstacktop
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
#if CONFIG_ARCH_INTERRUPTSTACK > 3
|
#if CONFIG_ARCH_INTERRUPTSTACK > 15
|
||||||
.bss
|
.bss
|
||||||
.align 4
|
.balign 16
|
||||||
.global g_intstackalloc
|
.global g_intstackalloc
|
||||||
.global g_intstacktop
|
.global g_intstacktop
|
||||||
.type g_intstackalloc, object
|
.type g_intstackalloc, object
|
||||||
.type g_intstacktop, object
|
.type g_intstacktop, object
|
||||||
g_intstackalloc:
|
g_intstackalloc:
|
||||||
.skip (CONFIG_ARCH_INTERRUPTSTACK & ~3)
|
.skip ((CONFIG_ARCH_INTERRUPTSTACK + 8) & ~15)
|
||||||
g_intstacktop:
|
g_intstacktop:
|
||||||
.size g_intstacktop, 0
|
.size g_intstacktop, 0
|
||||||
.size g_intstackalloc, (CONFIG_ARCH_INTERRUPTSTACK & ~3)
|
.size g_intstackalloc, (CONFIG_ARCH_INTERRUPTSTACK & ~15)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -41,10 +41,6 @@
|
|||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef CONFIG_STACK_ALIGNMENT
|
|
||||||
# define CONFIG_STACK_ALIGNMENT 4
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|||||||
Reference in New Issue
Block a user