arch: move some macros to public code.

Move stack alignment and kernel stack macros from architecture-specific internal
headers to public include/nuttx/irq.h. Consolidates duplicate definitions across
17 architecture families, reducing code duplication while enabling common code
to access these core alignment utilities without architecture dependencies.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
hujun5 2025-04-27 19:25:50 +08:00 committed by archer
parent 6a51857e90
commit 63e59e26c0
27 changed files with 13 additions and 148 deletions

View file

@ -38,12 +38,6 @@
* Pre-processor Definitions
****************************************************************************/
/* Aligned size of the kernel stack */
#ifdef CONFIG_ARCH_KERNEL_STACK
# define ARCH_KERNEL_STACKSIZE ((CONFIG_ARCH_KERNEL_STACKSIZE + 7) & ~7)
#endif
/* Using a 4KiB page size, each 1MiB section maps to a PTE containing
* 256*2KiB entries
*/

View file

@ -80,12 +80,6 @@
# define USE_SERIALDRIVER 1
#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)
/* Check if an interrupt stack size is configured */
#ifndef CONFIG_ARCH_INTERRUPTSTACK

View file

@ -40,12 +40,6 @@
* Pre-processor Definitions
****************************************************************************/
/* Aligned size of the kernel stack */
#ifdef CONFIG_ARCH_KERNEL_STACK
# define ARCH_KERNEL_STACKSIZE STACK_ALIGN_UP(CONFIG_ARCH_KERNEL_STACKSIZE)
#endif
/* Base address for address environment */
#if CONFIG_ARCH_TEXT_VBASE != 0

View file

@ -93,12 +93,6 @@
#define STACK_COLOR 0xdeaddead
#define HEAP_COLOR 'h'
/* 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)
#ifdef CONFIG_SMP
/* The size of interrupt and idle stack. This is the configured
* value aligned the 8-bytes as required by the ARM EABI.

View file

@ -38,12 +38,6 @@
* Pre-processor Definitions
****************************************************************************/
/* 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.

View file

@ -73,12 +73,6 @@
# 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 _stext

View file

@ -73,12 +73,6 @@
# define CONFIG_ARCH_INTERRUPTSTACK 0
#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)
#define getreg8(a) (*(volatile uint8_t *)(a))
#define putreg8(v,a) (*(volatile uint8_t *)(a) = (v))
#define getreg16(a) (*(volatile uint16_t *)(a))

View file

@ -71,12 +71,6 @@
# define CONFIG_ARCH_INTERRUPTSTACK 0
#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)
#define getreg8(a) (*(volatile uint8_t *)(a))
#define putreg8(v,a) (*(volatile uint8_t *)(a) = (v))
#define getreg16(a) (*(volatile uint16_t *)(a))

View file

@ -66,12 +66,6 @@
# endif
#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
****************************************************************************/

View file

@ -65,12 +65,6 @@
# endif
#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
****************************************************************************/

View file

@ -74,12 +74,6 @@
# define CONFIG_ARCH_INTERRUPTSTACK 0
#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)
#define or1k_savestate(regs) or1k_copyfullstate(regs, up_current_regs())
#define or1k_restorestate(regs) or1k_copyfullstate(up_current_regs(), regs)

View file

@ -77,12 +77,6 @@
# define CONFIG_ARCH_INTERRUPTSTACK 0
#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)
#define renesas_savestate(regs) renesas_copystate(regs, up_current_regs())
#define getreg8(a) (*(volatile uint8_t *)(a))

View file

@ -40,12 +40,6 @@
* Pre-processor Definitions
****************************************************************************/
/* Aligned size of the kernel stack */
#ifdef CONFIG_ARCH_KERNEL_STACK
# define ARCH_KERNEL_STACKSIZE STACK_ALIGN_UP(CONFIG_ARCH_KERNEL_STACKSIZE)
#endif
/* Base address for address environment */
#if CONFIG_ARCH_TEXT_VBASE != 0

View file

@ -26,6 +26,7 @@
#include <nuttx/config.h>
#include <nuttx/irq.h>
#include <arch/arch.h>
#include <arch/irq.h>
#include <arch/mode.h>

View file

@ -74,12 +74,6 @@
#define STACK_FRAME_SIZE __XSTR(STACK_ALIGNMENT)
/* 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)
/* Interrupt Stack macros */
#define INT_STACK_SIZE (STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK))

View file

@ -62,10 +62,6 @@
#define MTIMER_TIME_BASE (CONFIG_NUTTSBI_MTIME_BASE)
#define MTIMER_CMP_BASE (CONFIG_NUTTSBI_MTIMECMP_BASE)
#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)
/* Temporary stack placement and size */
#define TEMP_STACK_BASE (_ebss)

View file

@ -84,12 +84,6 @@
# define CONFIG_SIM_FB_INTERVAL_LINE 0
#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)
/* Simulated Heap Definitions ***********************************************/
/* Size of the simulated heap */

View file

@ -84,12 +84,6 @@
#define INTSTACK_SIZE (CONFIG_ARCH_INTERRUPTSTACK & ~STACK_ALIGN_MASK)
/* 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.
*/

View file

@ -85,12 +85,6 @@
# define USE_SERIALDRIVER 1
#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)
/* Check if an interrupt stack size is configured */
#ifndef CONFIG_ARCH_INTERRUPTSTACK

View file

@ -73,12 +73,6 @@
# define CONFIG_ARCH_INTERRUPTSTACK 0
#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)
#define getreg8(p) inb(p)
#define putreg8(v,p) outb(v,p)
#define getreg16(p) inw(p)

View file

@ -40,12 +40,6 @@
* Pre-processor Definitions
****************************************************************************/
/* Aligned size of the kernel stack */
#ifdef CONFIG_ARCH_KERNEL_STACK
# define ARCH_KERNEL_STACKSIZE STACK_ALIGN_UP(CONFIG_ARCH_KERNEL_STACKSIZE)
#endif
/* Base address for address environment */
#if CONFIG_ARCH_TEXT_VBASE != 0

View file

@ -94,12 +94,6 @@
# define CONFIG_ARCH_INTERRUPTSTACK 0
#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)
/* This is the value used to mark the stack for subsequent stack monitoring
* logic.
*/

View file

@ -51,12 +51,6 @@
# error x86_64 stack canaries requires TLS support !
#endif
/* Aligned size of the kernel stack */
#ifdef CONFIG_ARCH_KERNEL_STACK
# define ARCH_KERNEL_STACKSIZE STACK_ALIGN_UP(CONFIG_ARCH_KERNEL_STACKSIZE)
#endif
/****************************************************************************
* Public Functions
****************************************************************************/

View file

@ -84,12 +84,6 @@
# define INTSTACK_SIZE INTSTACK_ALIGNUP(CONFIG_ARCH_INTERRUPTSTACK)
#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)
/* An IDLE thread stack size for CPU0 must be defined */
#if !defined(CONFIG_IDLETHREAD_STACKSIZE)

View file

@ -72,12 +72,6 @@
# define USE_SERIALDRIVER 1
#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)
/* Macros for portability */
#define IN_INTERRUPT (up_current_regs() != NULL)

View file

@ -63,12 +63,6 @@
# define USE_SERIALDRIVER 1
#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)
/* Register access macros ***************************************************
*
* The register access mechanism provided in ez8.h differs from the useful in

View file

@ -98,6 +98,18 @@
while (0)
#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)
/* Aligned size of the kernel stack */
#ifdef CONFIG_ARCH_KERNEL_STACK
# define ARCH_KERNEL_STACKSIZE STACK_ALIGN_UP(CONFIG_ARCH_KERNEL_STACKSIZE)
#endif
/* Interrupt was handled by this device */
#define IRQ_HANDLED 0