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
-6
View File
@@ -38,12 +38,6 @@
* Pre-processor Definitions * 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 /* Using a 4KiB page size, each 1MiB section maps to a PTE containing
* 256*2KiB entries * 256*2KiB entries
*/ */
-6
View File
@@ -80,12 +80,6 @@
# define USE_SERIALDRIVER 1 # define USE_SERIALDRIVER 1
#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)
/* Check if an interrupt stack size is configured */ /* Check if an interrupt stack size is configured */
#ifndef CONFIG_ARCH_INTERRUPTSTACK #ifndef CONFIG_ARCH_INTERRUPTSTACK
-6
View File
@@ -40,12 +40,6 @@
* Pre-processor Definitions * 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 */ /* Base address for address environment */
#if CONFIG_ARCH_TEXT_VBASE != 0 #if CONFIG_ARCH_TEXT_VBASE != 0
-6
View File
@@ -93,12 +93,6 @@
#define STACK_COLOR 0xdeaddead #define STACK_COLOR 0xdeaddead
#define HEAP_COLOR 'h' #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 #ifdef CONFIG_SMP
/* The size of interrupt and idle stack. This is the configured /* The size of interrupt and idle stack. This is the configured
* value aligned the 8-bytes as required by the ARM EABI. * value aligned the 8-bytes as required by the ARM EABI.
-6
View File
@@ -38,12 +38,6 @@
* Pre-processor Definitions * 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 /* 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 * from the stack to the TCB, but only a referenced is passed to get the
* state from the TCB. * state from the TCB.
-6
View File
@@ -73,12 +73,6 @@
# define USE_SERIALDRIVER 1 # define USE_SERIALDRIVER 1
#endif #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 */ /* Linker defined section addresses */
#define _START_TEXT _stext #define _START_TEXT _stext
-6
View File
@@ -73,12 +73,6 @@
# define CONFIG_ARCH_INTERRUPTSTACK 0 # define CONFIG_ARCH_INTERRUPTSTACK 0
#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)
#define getreg8(a) (*(volatile uint8_t *)(a)) #define getreg8(a) (*(volatile uint8_t *)(a))
#define putreg8(v,a) (*(volatile uint8_t *)(a) = (v)) #define putreg8(v,a) (*(volatile uint8_t *)(a) = (v))
#define getreg16(a) (*(volatile uint16_t *)(a)) #define getreg16(a) (*(volatile uint16_t *)(a))
-6
View File
@@ -71,12 +71,6 @@
# define CONFIG_ARCH_INTERRUPTSTACK 0 # define CONFIG_ARCH_INTERRUPTSTACK 0
#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)
#define getreg8(a) (*(volatile uint8_t *)(a)) #define getreg8(a) (*(volatile uint8_t *)(a))
#define putreg8(v,a) (*(volatile uint8_t *)(a) = (v)) #define putreg8(v,a) (*(volatile uint8_t *)(a) = (v))
#define getreg16(a) (*(volatile uint16_t *)(a)) #define getreg16(a) (*(volatile uint16_t *)(a))
-6
View File
@@ -66,12 +66,6 @@
# endif # endif
#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 * Public Types
****************************************************************************/ ****************************************************************************/
-6
View File
@@ -65,12 +65,6 @@
# endif # endif
#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 * Public Types
****************************************************************************/ ****************************************************************************/
-6
View File
@@ -74,12 +74,6 @@
# define CONFIG_ARCH_INTERRUPTSTACK 0 # define CONFIG_ARCH_INTERRUPTSTACK 0
#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)
#define or1k_savestate(regs) or1k_copyfullstate(regs, up_current_regs()) #define or1k_savestate(regs) or1k_copyfullstate(regs, up_current_regs())
#define or1k_restorestate(regs) or1k_copyfullstate(up_current_regs(), regs) #define or1k_restorestate(regs) or1k_copyfullstate(up_current_regs(), regs)
@@ -77,12 +77,6 @@
# define CONFIG_ARCH_INTERRUPTSTACK 0 # define CONFIG_ARCH_INTERRUPTSTACK 0
#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)
#define renesas_savestate(regs) renesas_copystate(regs, up_current_regs()) #define renesas_savestate(regs) renesas_copystate(regs, up_current_regs())
#define getreg8(a) (*(volatile uint8_t *)(a)) #define getreg8(a) (*(volatile uint8_t *)(a))
-6
View File
@@ -40,12 +40,6 @@
* Pre-processor Definitions * 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 */ /* Base address for address environment */
#if CONFIG_ARCH_TEXT_VBASE != 0 #if CONFIG_ARCH_TEXT_VBASE != 0
@@ -26,6 +26,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <nuttx/irq.h>
#include <arch/arch.h> #include <arch/arch.h>
#include <arch/irq.h> #include <arch/irq.h>
#include <arch/mode.h> #include <arch/mode.h>
-6
View File
@@ -74,12 +74,6 @@
#define STACK_FRAME_SIZE __XSTR(STACK_ALIGNMENT) #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 */ /* Interrupt Stack macros */
#define INT_STACK_SIZE (STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK)) #define INT_STACK_SIZE (STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK))
-4
View File
@@ -62,10 +62,6 @@
#define MTIMER_TIME_BASE (CONFIG_NUTTSBI_MTIME_BASE) #define MTIMER_TIME_BASE (CONFIG_NUTTSBI_MTIME_BASE)
#define MTIMER_CMP_BASE (CONFIG_NUTTSBI_MTIMECMP_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 */ /* Temporary stack placement and size */
#define TEMP_STACK_BASE (_ebss) #define TEMP_STACK_BASE (_ebss)
-6
View File
@@ -84,12 +84,6 @@
# define CONFIG_SIM_FB_INTERVAL_LINE 0 # define CONFIG_SIM_FB_INTERVAL_LINE 0
#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)
/* Simulated Heap Definitions ***********************************************/ /* Simulated Heap Definitions ***********************************************/
/* Size of the simulated heap */ /* Size of the simulated heap */
-6
View File
@@ -84,12 +84,6 @@
#define INTSTACK_SIZE (CONFIG_ARCH_INTERRUPTSTACK & ~STACK_ALIGN_MASK) #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 /* This is the value used to mark the stack for subsequent stack monitoring
* logic. * logic.
*/ */
@@ -85,12 +85,6 @@
# define USE_SERIALDRIVER 1 # define USE_SERIALDRIVER 1
#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)
/* Check if an interrupt stack size is configured */ /* Check if an interrupt stack size is configured */
#ifndef CONFIG_ARCH_INTERRUPTSTACK #ifndef CONFIG_ARCH_INTERRUPTSTACK
-6
View File
@@ -73,12 +73,6 @@
# define CONFIG_ARCH_INTERRUPTSTACK 0 # define CONFIG_ARCH_INTERRUPTSTACK 0
#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)
#define getreg8(p) inb(p) #define getreg8(p) inb(p)
#define putreg8(v,p) outb(v,p) #define putreg8(v,p) outb(v,p)
#define getreg16(p) inw(p) #define getreg16(p) inw(p)
-6
View File
@@ -40,12 +40,6 @@
* Pre-processor Definitions * 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 */ /* Base address for address environment */
#if CONFIG_ARCH_TEXT_VBASE != 0 #if CONFIG_ARCH_TEXT_VBASE != 0
-6
View File
@@ -94,12 +94,6 @@
# define CONFIG_ARCH_INTERRUPTSTACK 0 # define CONFIG_ARCH_INTERRUPTSTACK 0
#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)
/* This is the value used to mark the stack for subsequent stack monitoring /* This is the value used to mark the stack for subsequent stack monitoring
* logic. * logic.
*/ */
@@ -51,12 +51,6 @@
# error x86_64 stack canaries requires TLS support ! # error x86_64 stack canaries requires TLS support !
#endif #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 * Public Functions
****************************************************************************/ ****************************************************************************/
-6
View File
@@ -84,12 +84,6 @@
# define INTSTACK_SIZE INTSTACK_ALIGNUP(CONFIG_ARCH_INTERRUPTSTACK) # define INTSTACK_SIZE INTSTACK_ALIGNUP(CONFIG_ARCH_INTERRUPTSTACK)
#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)
/* An IDLE thread stack size for CPU0 must be defined */ /* An IDLE thread stack size for CPU0 must be defined */
#if !defined(CONFIG_IDLETHREAD_STACKSIZE) #if !defined(CONFIG_IDLETHREAD_STACKSIZE)
-6
View File
@@ -72,12 +72,6 @@
# define USE_SERIALDRIVER 1 # define USE_SERIALDRIVER 1
#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)
/* Macros for portability */ /* Macros for portability */
#define IN_INTERRUPT (up_current_regs() != NULL) #define IN_INTERRUPT (up_current_regs() != NULL)
-6
View File
@@ -63,12 +63,6 @@
# define USE_SERIALDRIVER 1 # define USE_SERIALDRIVER 1
#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)
/* Register access macros *************************************************** /* Register access macros ***************************************************
* *
* The register access mechanism provided in ez8.h differs from the useful in * The register access mechanism provided in ez8.h differs from the useful in
+12
View File
@@ -98,6 +98,18 @@
while (0) while (0)
#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)
/* 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 */ /* Interrupt was handled by this device */
#define IRQ_HANDLED 0 #define IRQ_HANDLED 0