diff --git a/arch/arm/src/armv7-a/arm_cpuidlestack.c b/arch/arm/src/armv7-a/arm_cpuidlestack.c index bc23ebaa071..fdc211ca98c 100644 --- a/arch/arm/src/armv7-a/arm_cpuidlestack.c +++ b/arch/arm/src/armv7-a/arm_cpuidlestack.c @@ -123,7 +123,7 @@ int up_cpu_idlestack(int cpu, FAR struct tcb_s *tcb, size_t stack_size) tcb->adj_stack_size = SMP_STACK_SIZE; tcb->stack_alloc_ptr = (FAR void *)stack_alloc; - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; #endif return OK; diff --git a/arch/arm/src/common/arm_createstack.c b/arch/arm/src/common/arm_createstack.c index 14da833f932..ac5d63787e3 100644 --- a/arch/arm/src/common/arm_createstack.c +++ b/arch/arm/src/common/arm_createstack.c @@ -40,24 +40,6 @@ #include "arm_arch.h" #include "arm_internal.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* Configuration */ - -/* For use with EABI and floating point, the stack must be aligned to 8-byte - * addresses. - */ - -#define CONFIG_STACK_ALIGNMENT 8 - -/* 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) - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -156,16 +138,14 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) if (ttype == TCB_FLAG_TTYPE_KERNEL) { - tcb->stack_alloc_ptr = - kmm_memalign(CONFIG_STACK_ALIGNMENT, stack_size); + tcb->stack_alloc_ptr = kmm_memalign(STACK_ALIGNMENT, stack_size); } else #endif { /* Use the user-space allocator if this is a task or pthread */ - tcb->stack_alloc_ptr = - kumm_memalign(CONFIG_STACK_ALIGNMENT, stack_size); + tcb->stack_alloc_ptr = kumm_memalign(STACK_ALIGNMENT, stack_size); } #endif /* CONFIG_TLS_ALIGNED */ @@ -191,7 +171,7 @@ int up_create_stack(FAR struct tcb_s *tcb, size_t stack_size, uint8_t ttype) */ /* Since both stack_alloc_ptr and stack_size are in - * CONFIG_STACK_ALIGNMENT, and the stack ptr is decremented before + * STACK_ALIGNMENT, and the stack ptr is decremented before * the first write, we can directly save our variables to struct * tcb_s. */ diff --git a/arch/arm/src/common/arm_internal.h b/arch/arm/src/common/arm_internal.h index f3461595002..1c494459d7f 100644 --- a/arch/arm/src/common/arm_internal.h +++ b/arch/arm/src/common/arm_internal.h @@ -75,6 +75,18 @@ # define CONFIG_ARCH_INTERRUPTSTACK 0 #endif +/* For use with EABI and floating point, the stack must be aligned to 8-byte + * addresses. + */ + +#define STACK_ALIGNMENT 8 + +/* Stack alignment macros */ + +#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1) +#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) +#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) + /* Macros to handle saving and restoring interrupt state. In the current ARM * model, the state is always copied to and from the stack and TCB. In the * Cortex-M0/3 model, the state is copied from the stack to the TCB, but only diff --git a/arch/arm/src/common/arm_stackframe.c b/arch/arm/src/common/arm_stackframe.c index bf9bb9235f3..a92ebce5ab9 100644 --- a/arch/arm/src/common/arm_stackframe.c +++ b/arch/arm/src/common/arm_stackframe.c @@ -34,30 +34,6 @@ #include "arm_internal.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* For use with EABI and floating point, the stack must be aligned to 8-byte - * addresses. - */ - -#define CONFIG_STACK_ALIGNMENT 8 - -/* 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 Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -113,7 +89,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; + tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; tcb->adj_stack_size -= frame_size; /* And return the pointer to the allocated region */ diff --git a/arch/arm/src/common/arm_usestack.c b/arch/arm/src/common/arm_usestack.c index 879b36c0eb6..0afd21935b4 100644 --- a/arch/arm/src/common/arm_usestack.c +++ b/arch/arm/src/common/arm_usestack.c @@ -37,22 +37,6 @@ #include "arm_internal.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* For use with EABI and floating point, the stack must be aligned to 8-byte - * addresses. - */ - -#define CONFIG_STACK_ALIGNMENT 8 - -/* 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) - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -108,7 +92,7 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size) * Items on the stack are referenced as positive word offsets from sp. */ - /* We align all sizes and pointer to CONFIG_STACK_ALIGNMENT. + /* We align all sizes and pointer to STACK_ALIGNMENT. * Since the stack ptr is decremented before * the first write, we can directly save our variables to struct * tcb_s. diff --git a/arch/arm/src/common/arm_vfork.c b/arch/arm/src/common/arm_vfork.c index feb430293ea..10b38b10b75 100644 --- a/arch/arm/src/common/arm_vfork.c +++ b/arch/arm/src/common/arm_vfork.c @@ -38,16 +38,6 @@ #include "arm_vfork.h" #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* For use with EABI and floating point, the stack must be aligned to 8-byte - * addresses. - */ - -#define CONFIG_STACK_ALIGNMENT 8 - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/avr/src/avr/up_stackframe.c b/arch/avr/src/avr/up_stackframe.c index 687f105a87a..e279daccd82 100644 --- a/arch/avr/src/avr/up_stackframe.c +++ b/arch/avr/src/avr/up_stackframe.c @@ -34,28 +34,6 @@ #include "up_internal.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* Stack can be aligned to 1 byte */ - -#define CONFIG_STACK_ALIGNMENT 1 - -/* 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 Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -95,10 +73,6 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) { FAR void *ret; - /* Align the frame_size */ - - frame_size = STACK_ALIGN_UP(frame_size); - /* Is there already a stack allocated? Is it big enough? */ if (!tcb->stack_alloc_ptr || tcb->adj_stack_size <= frame_size) @@ -111,7 +85,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; + tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; tcb->adj_stack_size -= frame_size; /* And return the pointer to the allocated region */ diff --git a/arch/avr/src/avr32/avr32.h b/arch/avr/src/avr32/avr32.h index ff59ec81c19..d61a977a595 100644 --- a/arch/avr/src/avr32/avr32.h +++ b/arch/avr/src/avr32/avr32.h @@ -36,6 +36,18 @@ * Pre-processor Definitions ****************************************************************************/ +/* The AVR32 stack must be aligned at word (4 byte) boundaries. If necessary + * frame_size must be rounded up to the next boundary + */ + +#define STACK_ALIGNMENT 4 + +/* Stack alignment macros */ + +#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1) +#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) +#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) + /* Macros to handle saving and restore interrupt state. The state is copied * from the stack to the TCB, but only a referenced is passed to get the * state from the TCB. diff --git a/arch/avr/src/avr32/up_stackframe.c b/arch/avr/src/avr32/up_stackframe.c index b01ea527362..b7fe27ea585 100644 --- a/arch/avr/src/avr32/up_stackframe.c +++ b/arch/avr/src/avr32/up_stackframe.c @@ -34,30 +34,6 @@ #include "up_internal.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* The AVR32 stack must be aligned at word (4 byte) boundaries. If necessary - * frame_size must be rounded up to the next boundary - */ - -#define STACK_ALIGNMENT 4 - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (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 Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -113,7 +89,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; + tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; tcb->adj_stack_size -= frame_size; /* And return the pointer to the allocated region */ diff --git a/arch/ceva/src/common/up_createstack.c b/arch/ceva/src/common/up_createstack.c index 864f861a86e..f9e75137d46 100644 --- a/arch/ceva/src/common/up_createstack.c +++ b/arch/ceva/src/common/up_createstack.c @@ -47,11 +47,6 @@ # define HAVE_KERNEL_HEAP 1 #endif -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (sizeof(uint32_t) - 1) -#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/ceva/src/common/up_internal.h b/arch/ceva/src/common/up_internal.h index 44de254fc45..3f73246135d 100644 --- a/arch/ceva/src/common/up_internal.h +++ b/arch/ceva/src/common/up_internal.h @@ -71,6 +71,12 @@ # define USE_SERIALDRIVER 1 #endif +/* Stack alignment macros */ + +#define STACK_ALIGN_MASK (sizeof(uint32_t) - 1) +#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) +#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) + /* Linker defined section addresses */ #define _START_TEXT ((const void *)&_stext) diff --git a/arch/ceva/src/common/up_stackframe.c b/arch/ceva/src/common/up_stackframe.c index d17697c6834..12ce130af47 100644 --- a/arch/ceva/src/common/up_stackframe.c +++ b/arch/ceva/src/common/up_stackframe.c @@ -27,22 +27,7 @@ #include #include -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (sizeof(uint32_t) - 1) -#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ +#include "up_internal.h" /**************************************************************************** * Public Functions diff --git a/arch/ceva/src/common/up_usestack.c b/arch/ceva/src/common/up_usestack.c index 880edc233cb..85e18866292 100644 --- a/arch/ceva/src/common/up_usestack.c +++ b/arch/ceva/src/common/up_usestack.c @@ -32,15 +32,6 @@ #include "up_internal.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (sizeof(uint32_t) - 1) -#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/hc/src/common/up_internal.h b/arch/hc/src/common/up_internal.h index 3d1f6fdca81..56ec7fa7b1a 100644 --- a/arch/hc/src/common/up_internal.h +++ b/arch/hc/src/common/up_internal.h @@ -70,6 +70,18 @@ # define CONFIG_ARCH_INTERRUPTSTACK 0 #endif +/* The CPU12 stack should be aligned at half-word (2 byte) boundaries. If + * necessary frame_size must be rounded up to the next boundary + */ + +#define STACK_ALIGNMENT 2 + +/* Stack alignment macros */ + +#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1) +#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) +#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) + /* Macros to handle saving and restore interrupt state. In the current CPU12 * model, the state is copied from the stack to the TCB, but only * a referenced is passed to get the state from the TCB. diff --git a/arch/hc/src/common/up_stackframe.c b/arch/hc/src/common/up_stackframe.c index b57de5c3078..e103c84845c 100644 --- a/arch/hc/src/common/up_stackframe.c +++ b/arch/hc/src/common/up_stackframe.c @@ -34,30 +34,6 @@ #include "up_internal.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* The CPU12 stack should be aligned at half-word (2 byte) boundaries. If - * necessary frame_size must be rounded up to the next boundary - */ - -#define STACK_ALIGNMENT 2 - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (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 Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -113,7 +89,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; + tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; tcb->adj_stack_size -= frame_size; /* And return the pointer to the allocated region */ diff --git a/arch/hc/src/common/up_usestack.c b/arch/hc/src/common/up_usestack.c index 23eadfb7d65..a72f0e1c1ee 100644 --- a/arch/hc/src/common/up_usestack.c +++ b/arch/hc/src/common/up_usestack.c @@ -118,7 +118,7 @@ int up_use_stack(FAR struct tcb_s *tcb, FAR void *stack, size_t stack_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; return OK; diff --git a/arch/mips/src/common/mips_createstack.c b/arch/mips/src/common/mips_createstack.c index b16110f4ea8..118e88f3da7 100644 --- a/arch/mips/src/common/mips_createstack.c +++ b/arch/mips/src/common/mips_createstack.c @@ -39,34 +39,6 @@ #include "mips_arch.h" #include "mips_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 STACK_ALIGNMENT 8 -#else -# define STACK_ALIGNMENT 4 -#endif - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (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 Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/mips/src/common/mips_internal.h b/arch/mips/src/common/mips_internal.h index 79207cd9a34..adfdb208d07 100644 --- a/arch/mips/src/common/mips_internal.h +++ b/arch/mips/src/common/mips_internal.h @@ -69,6 +69,22 @@ # define CONFIG_ARCH_INTERRUPTSTACK 0 #endif +/* 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 STACK_ALIGNMENT 8 +#else +# define STACK_ALIGNMENT 4 +#endif + +/* Stack alignment macros */ + +#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1) +#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) +#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) + /* In the MIPS model, the state is copied from the stack to the TCB, but * only a referenced is passed to get the state from the TCB. */ diff --git a/arch/mips/src/common/mips_stackframe.c b/arch/mips/src/common/mips_stackframe.c index 3fdfcc4128f..743ca2d61af 100644 --- a/arch/mips/src/common/mips_stackframe.c +++ b/arch/mips/src/common/mips_stackframe.c @@ -33,34 +33,6 @@ #include "mips_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 STACK_ALIGNMENT 8 -#else -# define STACK_ALIGNMENT 4 -#endif - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (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 Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -116,7 +88,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; + tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; tcb->adj_stack_size -= frame_size; /* And return the pointer to the allocated region */ diff --git a/arch/mips/src/common/mips_usestack.c b/arch/mips/src/common/mips_usestack.c index a2223b66337..57a55d9b775 100644 --- a/arch/mips/src/common/mips_usestack.c +++ b/arch/mips/src/common/mips_usestack.c @@ -36,26 +36,6 @@ #include "mips_internal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* 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 STACK_ALIGNMENT 8 -#else -# define STACK_ALIGNMENT 4 -#endif - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1) -#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) -#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/mips/src/mips32/mips_vfork.c b/arch/mips/src/mips32/mips_vfork.c index 65aa6934ea4..e9e34af3757 100644 --- a/arch/mips/src/mips32/mips_vfork.c +++ b/arch/mips/src/mips32/mips_vfork.c @@ -38,18 +38,6 @@ #include "mips_vfork.h" #include "sched/sched.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#ifndef CONFIG_STACK_ALIGNMENT -# define CONFIG_STACK_ALIGNMENT 4 -#endif - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/misoc/src/lm32/lm32.h b/arch/misoc/src/lm32/lm32.h index 7715d30f42a..77a0e671a31 100644 --- a/arch/misoc/src/lm32/lm32.h +++ b/arch/misoc/src/lm32/lm32.h @@ -63,6 +63,22 @@ # endif #endif +/* LM32 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 STACK_ALIGNMENT 8 +#else +# define STACK_ALIGNMENT 4 +#endif + +/* Stack alignment macros */ + +#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1) +#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) +#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/arch/misoc/src/lm32/lm32_createstack.c b/arch/misoc/src/lm32/lm32_createstack.c index 87cdbccba0e..f8c674b9403 100644 --- a/arch/misoc/src/lm32/lm32_createstack.c +++ b/arch/misoc/src/lm32/lm32_createstack.c @@ -38,34 +38,6 @@ #include "lm32.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* LM32 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 STACK_ALIGNMENT 8 -#else -# define STACK_ALIGNMENT 4 -#endif - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (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 Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/misoc/src/lm32/lm32_stackframe.c b/arch/misoc/src/lm32/lm32_stackframe.c index f8fa3c8c292..bbcceb04327 100644 --- a/arch/misoc/src/lm32/lm32_stackframe.c +++ b/arch/misoc/src/lm32/lm32_stackframe.c @@ -33,26 +33,6 @@ #include "lm32.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* LM32 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 STACK_ALIGNMENT 8 -#else -# define STACK_ALIGNMENT 4 -#endif - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (STACK_ALIGNMENT-1) -#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) -#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -108,7 +88,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; + tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; tcb->adj_stack_size -= frame_size; /* And return the pointer to the allocated region */ diff --git a/arch/misoc/src/minerva/minerva.h b/arch/misoc/src/minerva/minerva.h index 6754ad1c019..b1abe955308 100644 --- a/arch/misoc/src/minerva/minerva.h +++ b/arch/misoc/src/minerva/minerva.h @@ -63,6 +63,22 @@ # endif #endif +/* MINERVA 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 STACK_ALIGNMENT 8 +#else +# define STACK_ALIGNMENT 4 +#endif + +/* Stack alignment macros */ + +#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1) +#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) +#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/arch/misoc/src/minerva/minerva_createstack.c b/arch/misoc/src/minerva/minerva_createstack.c index 1168eb1b7ec..6121fc07047 100644 --- a/arch/misoc/src/minerva/minerva_createstack.c +++ b/arch/misoc/src/minerva/minerva_createstack.c @@ -38,26 +38,6 @@ #include "minerva.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* MINERVA 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 STACK_ALIGNMENT 8 -#else -# define STACK_ALIGNMENT 4 -#endif - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (STACK_ALIGNMENT-1) -#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) -#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/misoc/src/minerva/minerva_stackframe.c b/arch/misoc/src/minerva/minerva_stackframe.c index 41cfaf0b964..f11472fec74 100644 --- a/arch/misoc/src/minerva/minerva_stackframe.c +++ b/arch/misoc/src/minerva/minerva_stackframe.c @@ -33,26 +33,6 @@ #include "minerva.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* MINERVA 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 STACK_ALIGNMENT 8 -#else -# define STACK_ALIGNMENT 4 -#endif - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (STACK_ALIGNMENT-1) -#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) -#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -108,7 +88,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; + tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; tcb->adj_stack_size -= frame_size; /* And return the pointer to the allocated region */ diff --git a/arch/or1k/src/common/up_createstack.c b/arch/or1k/src/common/up_createstack.c index 404a29aec06..b0df4133495 100644 --- a/arch/or1k/src/common/up_createstack.c +++ b/arch/or1k/src/common/up_createstack.c @@ -40,24 +40,6 @@ #include "up_arch.h" #include "up_internal.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* Configuration */ - -/* For use with EABI and floating point, the stack must be aligned to 8-byte - * addresses. - */ - -#define CONFIG_STACK_ALIGNMENT 8 - -/* 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) - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/or1k/src/common/up_internal.h b/arch/or1k/src/common/up_internal.h index 311ffb2421d..b8c336f5f71 100644 --- a/arch/or1k/src/common/up_internal.h +++ b/arch/or1k/src/common/up_internal.h @@ -72,6 +72,18 @@ # define CONFIG_ARCH_INTERRUPTSTACK 0 #endif +/* For use with EABI and floating point, the stack must be aligned to 8-byte + * addresses. + */ + +#define STACK_ALIGNMENT 8 + +/* Stack alignment macros */ + +#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1) +#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) +#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) + #define up_savestate(regs) up_copyfullstate(regs, (uint32_t*)CURRENT_REGS) #define up_restorestate(regs) up_copyfullstate((uint32_t*)CURRENT_REGS, regs) diff --git a/arch/or1k/src/common/up_stackframe.c b/arch/or1k/src/common/up_stackframe.c index c6e84853a5b..13dbff8ec10 100644 --- a/arch/or1k/src/common/up_stackframe.c +++ b/arch/or1k/src/common/up_stackframe.c @@ -34,22 +34,6 @@ #include "up_internal.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* For use with EABI and floating point, the stack must be aligned to 8-byte - * addresses. - */ - -#define CONFIG_STACK_ALIGNMENT 8 - -/* 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) - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -105,7 +89,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; + tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; tcb->adj_stack_size -= frame_size; /* And return the pointer to the allocated region */ diff --git a/arch/renesas/src/common/up_internal.h b/arch/renesas/src/common/up_internal.h index 9cd34721cbf..b9b343859db 100644 --- a/arch/renesas/src/common/up_internal.h +++ b/arch/renesas/src/common/up_internal.h @@ -75,6 +75,18 @@ # define CONFIG_ARCH_INTERRUPTSTACK 0 #endif +/* The SH stack must be aligned at word (4 byte) boundaries. If necessary + * frame_size must be rounded up to the next boundary + */ + +#define STACK_ALIGNMENT 4 + +/* Stack alignment macros */ + +#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1) +#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) +#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) + #define up_savestate(regs) up_copystate(regs, (uint32_t *)g_current_regs) /**************************************************************************** diff --git a/arch/renesas/src/common/up_stackframe.c b/arch/renesas/src/common/up_stackframe.c index ebc7eadce46..d5f9ae8c32f 100644 --- a/arch/renesas/src/common/up_stackframe.c +++ b/arch/renesas/src/common/up_stackframe.c @@ -33,30 +33,6 @@ #include "up_internal.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* The SH stack must be aligned at word (4 byte) boundaries. If necessary - * frame_size must be rounded up to the next boundary - */ - -#define STACK_ALIGNMENT 4 - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (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 Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -112,7 +88,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; + tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; tcb->adj_stack_size -= frame_size; /* And return a pointer to allocated memory */ diff --git a/arch/risc-v/src/common/riscv_createstack.c b/arch/risc-v/src/common/riscv_createstack.c index 1a206685160..f387beca640 100644 --- a/arch/risc-v/src/common/riscv_createstack.c +++ b/arch/risc-v/src/common/riscv_createstack.c @@ -39,28 +39,6 @@ #include "riscv_arch.h" #include "riscv_internal.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* RISC-V requires a 16-byte stack alignment. */ - -#define STACK_ALIGNMENT 16 - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (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 Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/risc-v/src/common/riscv_internal.h b/arch/risc-v/src/common/riscv_internal.h index c83173388ef..000727adbe0 100644 --- a/arch/risc-v/src/common/riscv_internal.h +++ b/arch/risc-v/src/common/riscv_internal.h @@ -46,6 +46,16 @@ #define INTSTACK_COLOR 0xdeadbeef #define HEAP_COLOR 'h' +/* RISC-V requires a 16-byte stack alignment. */ + +#define STACK_ALIGNMENT 16 + +/* Stack alignment macros */ + +#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1) +#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) +#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) + /* Format output with register width and hex */ #ifdef CONFIG_ARCH_RV32 diff --git a/arch/risc-v/src/common/riscv_stackframe.c b/arch/risc-v/src/common/riscv_stackframe.c index b69e52d920d..4535f15abb2 100644 --- a/arch/risc-v/src/common/riscv_stackframe.c +++ b/arch/risc-v/src/common/riscv_stackframe.c @@ -33,28 +33,6 @@ #include "riscv_internal.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* RISC-V requires a 16-byte stack alignment. */ - -#define STACK_ALIGNMENT 16 - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (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 Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -110,7 +88,7 @@ void *up_stack_frame(struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = (uint8_t *)tcb->stack_base_ptr + frame_size; + tcb->stack_base_ptr = (uint8_t *)tcb->stack_base_ptr + frame_size; tcb->adj_stack_size -= frame_size; /* And return the pointer to the allocated region */ diff --git a/arch/risc-v/src/common/riscv_usestack.c b/arch/risc-v/src/common/riscv_usestack.c index 959ff5c29b4..98d77010ae9 100644 --- a/arch/risc-v/src/common/riscv_usestack.c +++ b/arch/risc-v/src/common/riscv_usestack.c @@ -36,20 +36,6 @@ #include "riscv_internal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* RISC-V requires a 16-byte stack alignment. */ - -#define STACK_ALIGNMENT 16 - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1) -#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) -#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -123,7 +109,7 @@ int up_use_stack(struct tcb_s *tcb, void *stack, size_t stack_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; #if defined(CONFIG_STACK_COLORATION) diff --git a/arch/sim/src/sim/up_createstack.c b/arch/sim/src/sim/up_createstack.c index 666c21fe25d..558dbb14b76 100644 --- a/arch/sim/src/sim/up_createstack.c +++ b/arch/sim/src/sim/up_createstack.c @@ -35,22 +35,6 @@ #include "up_internal.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* Use a stack alignment of 16 bytes. If necessary frame_size must be - * rounded up to the next boundary - */ - -#define STACK_ALIGNMENT 16 - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (STACK_ALIGNMENT-1) -#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) -#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/sim/src/sim/up_internal.h b/arch/sim/src/sim/up_internal.h index b1e16b715b3..3784cc44937 100644 --- a/arch/sim/src/sim/up_internal.h +++ b/arch/sim/src/sim/up_internal.h @@ -55,6 +55,18 @@ # endif #endif +/* Use a stack alignment of 16 bytes. If necessary frame_size must be + * rounded up to the next boundary + */ + +#define STACK_ALIGNMENT 16 + +/* Stack alignment macros */ + +#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1) +#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) +#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) + /* Simulated Heap Definitions ***********************************************/ /* Size of the simulated heap */ diff --git a/arch/sim/src/sim/up_stackframe.c b/arch/sim/src/sim/up_stackframe.c index 5aae8bf8a7b..2640f16436a 100644 --- a/arch/sim/src/sim/up_stackframe.c +++ b/arch/sim/src/sim/up_stackframe.c @@ -32,21 +32,7 @@ #include #include -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* Use a stack alignment of 16 bytes. If necessary frame_size must be - * rounded up to the next boundary - */ - -#define STACK_ALIGNMENT 16 - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (STACK_ALIGNMENT-1) -#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) -#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) +#include "up_internal.h" /**************************************************************************** * Public Functions @@ -103,7 +89,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; + tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; tcb->adj_stack_size -= frame_size; /* And return a pointer to the allocated memory */ diff --git a/arch/sim/src/sim/up_usestack.c b/arch/sim/src/sim/up_usestack.c index 528d6c84680..0f45fbc9d56 100644 --- a/arch/sim/src/sim/up_usestack.c +++ b/arch/sim/src/sim/up_usestack.c @@ -34,22 +34,6 @@ #include "up_internal.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* Use a stack alignment of 16 bytes. If necessary frame_size must be - * rounded up to the next boundary - */ - -#define STACK_ALIGNMENT 16 - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (STACK_ALIGNMENT-1) -#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) -#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/sparc/src/common/up_createstack.c b/arch/sparc/src/common/up_createstack.c index c2b78467a74..df9cb57e224 100644 --- a/arch/sparc/src/common/up_createstack.c +++ b/arch/sparc/src/common/up_createstack.c @@ -37,30 +37,6 @@ #include "up_arch.h" #include "up_internal.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* sparc requires at least a 4-byte stack alignment. For floating point use, - * however, the stack must be aligned to 8-byte addresses. - */ - -#define STACK_ALIGNMENT 8 - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (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 Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/sparc/src/common/up_internal.h b/arch/sparc/src/common/up_internal.h index 7ef8367eb50..44dd6f3ab9b 100644 --- a/arch/sparc/src/common/up_internal.h +++ b/arch/sparc/src/common/up_internal.h @@ -80,6 +80,18 @@ # define CONFIG_ARCH_INTERRUPTSTACK 0 #endif +/* sparc requires at least a 4-byte stack alignment. For floating point use, + * however, the stack must be aligned to 8-byte addresses. + */ + +#define STACK_ALIGNMENT 8 + +/* Stack alignment macros */ + +#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1) +#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) +#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) + /* This is the value used to mark the stack for subsequent stack monitoring * logic. */ diff --git a/arch/sparc/src/common/up_stackframe.c b/arch/sparc/src/common/up_stackframe.c index dd2fc7267fe..bb32556250e 100644 --- a/arch/sparc/src/common/up_stackframe.c +++ b/arch/sparc/src/common/up_stackframe.c @@ -33,30 +33,6 @@ #include "up_internal.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* sparc requires at least a 4-byte stack alignment. For floating point use, - * however, the stack must be aligned to 8-byte addresses. - */ - -#define STACK_ALIGNMENT 8 - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (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 Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -113,7 +89,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; + tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; tcb->adj_stack_size -= frame_size; /* And return the pointer to the allocated region */ diff --git a/arch/sparc/src/common/up_usestack.c b/arch/sparc/src/common/up_usestack.c index e6a35139617..cfc63b7ffac 100644 --- a/arch/sparc/src/common/up_usestack.c +++ b/arch/sparc/src/common/up_usestack.c @@ -34,30 +34,6 @@ #include "up_internal.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* sparc requires at least a 4-byte stack alignment. For floating point use, - * however, the stack must be aligned to 8-byte addresses. - */ - -#define STACK_ALIGNMENT 8 - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (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 Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/x86/src/common/up_internal.h b/arch/x86/src/common/up_internal.h index 5dc27e8b0ed..06954b9ae88 100644 --- a/arch/x86/src/common/up_internal.h +++ b/arch/x86/src/common/up_internal.h @@ -70,6 +70,19 @@ # define CONFIG_ARCH_INTERRUPTSTACK 0 #endif +/* The initial stack point is aligned at word (4 byte) boundaries. If + * necessary frame_size must be rounded up to the next boundary to retain + * this alignment. + */ + +#define STACK_ALIGNMENT 4 + +/* Stack alignment macros */ + +#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1) +#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) +#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) + /* Macros to handle saving and restore interrupt state. In the current * model, the state is copied from the stack to the TCB, but only a * referenced is passed to get the state from the TCB. diff --git a/arch/x86/src/i486/up_stackframe.c b/arch/x86/src/i486/up_stackframe.c index ebd5b005fd5..b11d29e0753 100644 --- a/arch/x86/src/i486/up_stackframe.c +++ b/arch/x86/src/i486/up_stackframe.c @@ -34,31 +34,6 @@ #include "up_internal.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* The initial stack point is aligned at word (4 byte) boundaries. If - * necessary frame_size must be rounded up to the next boundary to retain - * this alignment. - */ - -#define STACK_ALIGNMENT 4 - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (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 Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -114,7 +89,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; + tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; tcb->adj_stack_size -= frame_size; /* And return the pointer to the allocated region */ diff --git a/arch/x86_64/src/common/up_internal.h b/arch/x86_64/src/common/up_internal.h index 9de8c2c606a..a0682f45567 100644 --- a/arch/x86_64/src/common/up_internal.h +++ b/arch/x86_64/src/common/up_internal.h @@ -89,6 +89,19 @@ # define CONFIG_ARCH_INTERRUPTSTACK 0 #endif +/* The initial stack point is aligned at 16 bytes boundaries. If + * necessary frame_size must be rounded up to the next boundary to retain + * this alignment. + */ + +#define STACK_ALIGNMENT 16 + +/* Stack alignment macros */ + +#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1) +#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) +#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) + /* Macros to handle saving and restore interrupt state. In the current * model, the state is copied from the stack to the TCB, but only a * referenced is passed to get the state from the TCB. diff --git a/arch/x86_64/src/intel64/up_stackframe.c b/arch/x86_64/src/intel64/up_stackframe.c index 2fc0b978229..ad7f978e9ea 100644 --- a/arch/x86_64/src/intel64/up_stackframe.c +++ b/arch/x86_64/src/intel64/up_stackframe.c @@ -34,31 +34,6 @@ #include "up_internal.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* The initial stack point is aligned at 16 bytes boundaries. If - * necessary frame_size must be rounded up to the next boundary to retain - * this alignment. - */ - -#define STACK_ALIGNMENT 16 - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (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 Function Prototypes - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -114,7 +89,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; + tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; tcb->adj_stack_size -= frame_size; /* And return the pointer to the allocated region */ diff --git a/arch/xtensa/src/common/xtensa.h b/arch/xtensa/src/common/xtensa.h index abe95c81f45..15dd5bd462c 100644 --- a/arch/xtensa/src/common/xtensa.h +++ b/arch/xtensa/src/common/xtensa.h @@ -81,6 +81,16 @@ # define INTSTACK_SIZE INTSTACK_ALIGNUP(CONFIG_ARCH_INTERRUPTSTACK) #endif +/* XTENSA requires at least a 16-byte stack alignment. */ + +#define STACK_ALIGNMENT 16 + +/* Stack alignment macros */ + +#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1) +#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) +#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) + /* An IDLE thread stack size for CPU0 must be defined */ #if !defined(CONFIG_IDLETHREAD_STACKSIZE) diff --git a/arch/xtensa/src/common/xtensa_checkstack.c b/arch/xtensa/src/common/xtensa_checkstack.c index addc33b9ef8..7fd4e5b80f0 100644 --- a/arch/xtensa/src/common/xtensa_checkstack.c +++ b/arch/xtensa/src/common/xtensa_checkstack.c @@ -39,14 +39,6 @@ #ifdef CONFIG_STACK_COLORATION -#define STACK_ALIGNMENT 16 - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (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 Function Prototypes ****************************************************************************/ diff --git a/arch/xtensa/src/common/xtensa_createstack.c b/arch/xtensa/src/common/xtensa_createstack.c index 321c47a7fb1..4dc601d227f 100644 --- a/arch/xtensa/src/common/xtensa_createstack.c +++ b/arch/xtensa/src/common/xtensa_createstack.c @@ -42,20 +42,6 @@ #include "xtensa.h" #include "xtensa_mm.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* XTENSA requires at least a 16-byte stack alignment. */ - -#define STACK_ALIGNMENT 16 - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1) -#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) -#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/xtensa/src/common/xtensa_stackframe.c b/arch/xtensa/src/common/xtensa_stackframe.c index b217f22a7bc..4ed4f38b8fa 100644 --- a/arch/xtensa/src/common/xtensa_stackframe.c +++ b/arch/xtensa/src/common/xtensa_stackframe.c @@ -33,20 +33,6 @@ #include "xtensa.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* XTENSA requires at least a 16-byte stack alignment. */ - -#define STACK_ALIGNMENT 16 - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1) -#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) -#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -102,7 +88,7 @@ void *up_stack_frame(struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = (uint8_t *)tcb->stack_base_ptr + frame_size; + tcb->stack_base_ptr = (uint8_t *)tcb->stack_base_ptr + frame_size; tcb->adj_stack_size -= frame_size; /* And return the pointer to the allocated region */ diff --git a/arch/xtensa/src/common/xtensa_usestack.c b/arch/xtensa/src/common/xtensa_usestack.c index a3a2d594645..baf8056162b 100644 --- a/arch/xtensa/src/common/xtensa_usestack.c +++ b/arch/xtensa/src/common/xtensa_usestack.c @@ -36,20 +36,6 @@ #include "xtensa.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* XTENSA requires at least a 16-byte stack alignment. */ - -#define STACK_ALIGNMENT 16 - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1) -#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) -#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/arch/xtensa/src/esp32/esp32_cpuidlestack.c b/arch/xtensa/src/esp32/esp32_cpuidlestack.c index 973d86b6b07..7a79b40fd85 100644 --- a/arch/xtensa/src/esp32/esp32_cpuidlestack.c +++ b/arch/xtensa/src/esp32/esp32_cpuidlestack.c @@ -98,7 +98,7 @@ int up_cpu_idlestack(int cpu, struct tcb_s *tcb, size_t stack_size) tcb->stack_alloc_ptr = g_cpu1_idlestack; tcb->adj_stack_size = CPU1_IDLETHREAD_STACKSIZE; - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; #if XCHAL_CP_NUM > 0 /* REVISIT: Does it make since to have co-processors enabled on the IDLE diff --git a/arch/z16/src/common/z16_internal.h b/arch/z16/src/common/z16_internal.h index 4f840e46f36..75db710f1f9 100644 --- a/arch/z16/src/common/z16_internal.h +++ b/arch/z16/src/common/z16_internal.h @@ -70,6 +70,18 @@ # define USE_SERIALDRIVER 1 #endif +/* Align the stack to word (4 byte) boundaries. This is probablya greater + * alignment than is required. + */ + +#define STACK_ALIGNMENT 4 + +/* Stack alignment macros */ + +#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1) +#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) +#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) + /* Macros for portability */ #define IN_INTERRUPT (g_current_regs != NULL) diff --git a/arch/z16/src/common/z16_stackframe.c b/arch/z16/src/common/z16_stackframe.c index 6b1e09dc83b..0cfba483e7a 100644 --- a/arch/z16/src/common/z16_stackframe.c +++ b/arch/z16/src/common/z16_stackframe.c @@ -34,22 +34,6 @@ #include "z16_internal.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* Align the stack to word (4 byte) boundaries. This is probablya greater - * alignment than is required. - */ - -#define STACK_ALIGNMENT 4 - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (STACK_ALIGNMENT-1) -#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) -#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -105,7 +89,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; + tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; tcb->adj_stack_size -= frame_size; /* And return a pointer to the allocated memory */ diff --git a/arch/z16/src/common/z16_usestack.c b/arch/z16/src/common/z16_usestack.c index cc5e3c5c942..be07ef1cbcc 100644 --- a/arch/z16/src/common/z16_usestack.c +++ b/arch/z16/src/common/z16_usestack.c @@ -117,7 +117,7 @@ int up_use_stack(FAR struct tcb_s *tcb, FAR void *stack, size_t stack_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = tcb->stack_alloc_ptr; + tcb->stack_base_ptr = tcb->stack_alloc_ptr; tcb->adj_stack_size = size_of_stack; return OK; diff --git a/arch/z80/src/common/z80_internal.h b/arch/z80/src/common/z80_internal.h index d323e51e2db..ae12dde58f6 100644 --- a/arch/z80/src/common/z80_internal.h +++ b/arch/z80/src/common/z80_internal.h @@ -61,6 +61,18 @@ # define USE_SERIALDRIVER 1 #endif +/* The Z80 stack does not need to be aligned. Here is is aligned at word + * (4 byte) boundary. + */ + +#define STACK_ALIGNMENT 4 + +/* Stack alignment macros */ + +#define STACK_ALIGN_MASK (STACK_ALIGNMENT - 1) +#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) +#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/arch/z80/src/common/z80_stackframe.c b/arch/z80/src/common/z80_stackframe.c index 37562009886..9bd2bd16059 100644 --- a/arch/z80/src/common/z80_stackframe.c +++ b/arch/z80/src/common/z80_stackframe.c @@ -33,22 +33,6 @@ #include "z80_internal.h" -/**************************************************************************** - * Pre-processor Macros - ****************************************************************************/ - -/* The Z80 stack does not need to be aligned. Here is is aligned at word - * (4 byte) boundary. - */ - -#define STACK_ALIGNMENT 4 - -/* Stack alignment macros */ - -#define STACK_ALIGN_MASK (STACK_ALIGNMENT-1) -#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) -#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -104,7 +88,7 @@ FAR void *up_stack_frame(FAR struct tcb_s *tcb, size_t frame_size) /* Save the adjusted stack values in the struct tcb_s */ - tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; + tcb->stack_base_ptr = (FAR uint8_t *)tcb->stack_base_ptr + frame_size; tcb->adj_stack_size -= frame_size; /* And return a pointer to the allocated memory */