diff --git a/arch/arm/include/arch.h b/arch/arm/include/arch.h index 031c1387077..45969081155 100644 --- a/arch/arm/include/arch.h +++ b/arch/arm/include/arch.h @@ -40,8 +40,6 @@ * Pre-processor Prototypes ****************************************************************************/ -#define up_getsp() (uintptr_t)__builtin_frame_address(0) - #ifdef CONFIG_PIC /* This identifies the register the is used by the processor as the PIC base diff --git a/arch/arm/include/irq.h b/arch/arm/include/irq.h index 16ad3d0004a..1fac0e1e55c 100644 --- a/arch/arm/include/irq.h +++ b/arch/arm/include/irq.h @@ -60,6 +60,12 @@ # include #endif +/**************************************************************************** + * Pre-processor Prototypes + ****************************************************************************/ + +#define up_getsp() (uintptr_t)__builtin_frame_address(0) + #ifndef __ASSEMBLY__ #ifdef __cplusplus diff --git a/arch/avr/include/avr/arch.h b/arch/avr/include/avr/arch.h index c7128471b0a..c717b68eda1 100644 --- a/arch/avr/include/avr/arch.h +++ b/arch/avr/include/avr/arch.h @@ -39,30 +39,6 @@ #ifndef __ASSEMBLY__ -/**************************************************************************** - * Inline functions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_getsp - ****************************************************************************/ - -static inline uint16_t up_getsp(void) -{ - uint8_t spl; - uint8_t sph; - - __asm__ __volatile__ - ( - "in %0, __SP_L__\n\t" - "in %1, __SP_H__\n" - : "=r" (spl), "=r" (sph) - : - ); - - return (uint16_t)sph << 8 | spl; -} - /**************************************************************************** * Public Variables ****************************************************************************/ diff --git a/arch/avr/include/avr/irq.h b/arch/avr/include/avr/irq.h index 2ed0a0afd07..67671b87dbc 100644 --- a/arch/avr/include/avr/irq.h +++ b/arch/avr/include/avr/irq.h @@ -147,6 +147,24 @@ static inline void putsreg(irqstate_t sreg) asm volatile ("out __SREG__, %s" : : "r" (sreg) :); } +/* Return the current value of the stack pointer */ + +static inline uint16_t up_getsp(void) +{ + uint8_t spl; + uint8_t sph; + + __asm__ __volatile__ + ( + "in %0, __SP_L__\n\t" + "in %1, __SP_H__\n" + : "=r" (spl), "=r" (sph) + : + ); + + return (uint16_t)sph << 8 | spl; +} + /* Interrupt enable/disable */ static inline void up_irq_enable() diff --git a/arch/avr/include/avr32/arch.h b/arch/avr/include/avr32/arch.h index b2bf008a1b6..610a3ee9f93 100644 --- a/arch/avr/include/avr32/arch.h +++ b/arch/avr/include/avr32/arch.h @@ -39,27 +39,6 @@ #ifndef __ASSEMBLY__ -/**************************************************************************** - * Inline functions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_getsp - ****************************************************************************/ - -static inline uint32_t up_getsp(void) -{ - uint32_t retval; - __asm__ __volatile__ - ( - "mov\t%0,sp\n\t" - : "=r" (retval) - : - ); - - return retval; -} - /**************************************************************************** * Public Variables ****************************************************************************/ diff --git a/arch/avr/include/avr32/irq.h b/arch/avr/include/avr32/irq.h index 8a9c1472f0f..67847fc2704 100644 --- a/arch/avr/include/avr32/irq.h +++ b/arch/avr/include/avr32/irq.h @@ -156,6 +156,21 @@ static inline uint32_t avr32_evba(void) return evba; } +/* Return the current value of the stack pointer */ + +static inline uint32_t up_getsp(void) +{ + uint32_t retval; + __asm__ __volatile__ + ( + "mov\t%0,sp\n\t" + : "=r" (retval) + : + ); + + return retval; +} + /* Return the current interrupt enable state and disable all interrupts */ static inline irqstate_t up_irq_save(void) diff --git a/arch/ceva/include/xc5/irq.h b/arch/ceva/include/xc5/irq.h index 7c40b8d413f..a95479492e4 100644 --- a/arch/ceva/include/xc5/irq.h +++ b/arch/ceva/include/xc5/irq.h @@ -231,6 +231,15 @@ static inline void setmodp(uint32_t modp_v) ); } +/* Return the current value of the stack pointer */ + +static inline uint32_t up_getsp(void) +{ + uint32_t sp; + __asm__ __volatile__("nop\nmov sp, %0" : "=r"(sp)); + return sp; +} + static inline void up_irq_disable(void) { setmodp(REG_MODP_DISABLE); @@ -253,17 +262,6 @@ static inline void up_irq_restore(irqstate_t flags) setmodp(flags); } -/**************************************************************************** - * Name: up_getsp - ****************************************************************************/ - -static inline uint32_t up_getsp(void) -{ - uint32_t sp; - __asm__ __volatile__("nop\nmov sp, %0" : "=r"(sp)); - return sp; -} - #endif /* __ASSEMBLY__ */ #endif /* __ARCH_CEVA_INCLUDE_XC5_IRQ_H */ diff --git a/arch/ceva/include/xm6/irq.h b/arch/ceva/include/xm6/irq.h index 41101a626da..c42d4a82493 100644 --- a/arch/ceva/include/xm6/irq.h +++ b/arch/ceva/include/xm6/irq.h @@ -221,6 +221,15 @@ static inline void setmoda(uint32_t moda) __asm__ __volatile__("nop #0x04\nnop\nmovp %0.ui, moda.ui" : : "r"(moda)); } +/* Return the current value of the stack pointer */ + +static inline uint32_t up_getsp(void) +{ + uint32_t sp; + __asm__ __volatile__("mov sp.ui, %0.ui" : "=r"(sp)); + return sp; +} + static inline void up_irq_disable(void) { setmoda(REG_MODA_DISABLE); @@ -243,17 +252,6 @@ static inline void up_irq_restore(irqstate_t flags) setmoda(flags); } -/**************************************************************************** - * Name: up_getsp - ****************************************************************************/ - -static inline uint32_t up_getsp(void) -{ - uint32_t sp; - __asm__ __volatile__("mov sp.ui, %0.ui" : "=r"(sp)); - return sp; -} - #endif /* __ASSEMBLY__ */ #endif /* __ARCH_CEVA_INCLUDE_XM6_IRQ_H */ diff --git a/arch/hc/include/arch.h b/arch/hc/include/arch.h index c7b718ef77e..9c9570585cf 100644 --- a/arch/hc/include/arch.h +++ b/arch/hc/include/arch.h @@ -35,25 +35,6 @@ * Pre-processor Definitions ****************************************************************************/ -/**************************************************************************** - * Inline functions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_getsp - ****************************************************************************/ - -static inline uint16_t up_getsp(void) -{ - uint16_t ret; - __asm__ - ( - "\tsts %0\n" - : "=m"(ret) : - ); - return ret; -} - /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/arch/hc/include/irq.h b/arch/hc/include/irq.h index 0de76dfa882..9ac8687b8d3 100644 --- a/arch/hc/include/irq.h +++ b/arch/hc/include/irq.h @@ -69,6 +69,23 @@ extern "C" #define EXTERN extern #endif +/**************************************************************************** + * Inline functions + ****************************************************************************/ + +/* Return the current value of the stack pointer */ + +static inline uint16_t up_getsp(void) +{ + uint16_t ret; + __asm__ + ( + "\tsts %0\n" + : "=m"(ret) : + ); + return ret; +} + /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/arch/mips/include/arch.h b/arch/mips/include/arch.h index 266d6225042..af47e2b5fec 100644 --- a/arch/mips/include/arch.h +++ b/arch/mips/include/arch.h @@ -35,25 +35,6 @@ * Pre-processor Definitions ****************************************************************************/ -/**************************************************************************** - * Inline functions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_getsp - ****************************************************************************/ - -static inline uint32_t up_getsp(void) -{ - register uint32_t sp; - __asm__ - ( - "\tadd %0, $0, $29\n" - : "=r"(sp) - ); - return sp; -} - /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/arch/mips/include/irq.h b/arch/mips/include/irq.h index ea289076c9b..9ba6381f36a 100644 --- a/arch/mips/include/irq.h +++ b/arch/mips/include/irq.h @@ -67,6 +67,23 @@ extern "C" #define EXTERN extern #endif +/**************************************************************************** + * Inline functions + ****************************************************************************/ + +/* Return the current value of the stack pointer */ + +static inline uint32_t up_getsp(void) +{ + register uint32_t sp; + __asm__ + ( + "\tadd %0, $0, $29\n" + : "=r"(sp) + ); + return sp; +} + /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/arch/misoc/include/arch.h b/arch/misoc/include/arch.h index 792f9337193..d00086bbfbd 100644 --- a/arch/misoc/include/arch.h +++ b/arch/misoc/include/arch.h @@ -29,23 +29,8 @@ * Included Files ****************************************************************************/ -#include - /**************************************************************************** * Inline functions ****************************************************************************/ -/**************************************************************************** - * Name: up_getsp - ****************************************************************************/ - -static inline uint32_t up_getsp(void) -{ - register uint32_t sp; - - __asm__ __volatile__("addi %0, sp, 0" : "=r" (sp)); - - return sp; -} - #endif /* __ARCH_MISOC_INCLUDE_ARCH_H */ diff --git a/arch/misoc/include/irq.h b/arch/misoc/include/irq.h index 721de62ac34..32a212630ce 100644 --- a/arch/misoc/include/irq.h +++ b/arch/misoc/include/irq.h @@ -57,6 +57,21 @@ extern "C" #define EXTERN extern #endif +/**************************************************************************** + * Inline functions + ****************************************************************************/ + +/* Return the current value of the stack pointer */ + +static inline uint32_t up_getsp(void) +{ + register uint32_t sp; + + __asm__ __volatile__("addi %0, sp, 0" : "=r" (sp)); + + return sp; +} + /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/arch/or1k/include/arch.h b/arch/or1k/include/arch.h index f27eaf522d2..d60ae6e5156 100644 --- a/arch/or1k/include/arch.h +++ b/arch/or1k/include/arch.h @@ -66,27 +66,6 @@ # endif #endif /* CONFIG_ARCH_ADDRENV */ -/**************************************************************************** - * Inline functions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_getsp - ****************************************************************************/ - -static inline uint32_t up_getsp(void) -{ - uint32_t sp; - - __asm__ - ( - "\tmov %0, sp\n\t" - : "=r"(sp) - ); - - return sp; -} - /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/arch/or1k/include/irq.h b/arch/or1k/include/irq.h index 330390035b5..11b0857cdfd 100644 --- a/arch/or1k/include/irq.h +++ b/arch/or1k/include/irq.h @@ -42,6 +42,25 @@ #include +/**************************************************************************** + * Inline functions + ****************************************************************************/ + +/* Return the current value of the stack pointer */ + +static inline uint32_t up_getsp(void) +{ + uint32_t sp; + + __asm__ + ( + "\tmov %0, sp\n\t" + : "=r"(sp) + ); + + return sp; +} + /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/arch/renesas/include/m16c/arch.h b/arch/renesas/include/m16c/arch.h index 33b2409cdc8..bf1541d1f3d 100644 --- a/arch/renesas/include/m16c/arch.h +++ b/arch/renesas/include/m16c/arch.h @@ -39,28 +39,6 @@ #ifndef __ASSEMBLY__ -/**************************************************************************** - * Inline functions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_getsp - ****************************************************************************/ - -static inline uint16_t up_getsp(void) -{ - uint16_t sp; - - __asm__ __volatile__ - ( - "\tstc sp, %0\n\t" - : "=r" (sp) - : - : "memory" - ); - return sp; -} - /**************************************************************************** * Public Variables ****************************************************************************/ diff --git a/arch/renesas/include/m16c/irq.h b/arch/renesas/include/m16c/irq.h index eb98f15fe14..5b66067746f 100644 --- a/arch/renesas/include/m16c/irq.h +++ b/arch/renesas/include/m16c/irq.h @@ -1,4 +1,4 @@ -/************************************************************************************ +/**************************************************************************** * arch/renesas/include/m16c/irq.h * * Licensed to the Apache Software Foundation (ASF) under one or more @@ -16,7 +16,7 @@ * License for the specific language governing permissions and limitations * under the License. * - ************************************************************************************/ + ****************************************************************************/ /* This file should never be included directly but, rather, * only indirectly through nuttx/irq.h @@ -25,20 +25,20 @@ #ifndef __ARCH_RENESAS_INCLUDE_M16C_IRQ_H #define __ARCH_RENESAS_INCLUDE_M16C_IRQ_H -/************************************************************************************ +/**************************************************************************** * Included Files - ************************************************************************************/ + ****************************************************************************/ #include #ifndef __ASSEMBLY__ # include #endif -/************************************************************************************ +/**************************************************************************** * Pre-processor Definitions - ************************************************************************************/ + ****************************************************************************/ -/* IRQ numbers **********************************************************************/ +/* IRQ numbers **************************************************************/ /* Fixed vector table */ @@ -219,9 +219,9 @@ #define XCPTCONTEXT_SIZE 22 -/************************************************************************************ +/**************************************************************************** * Public Types - ************************************************************************************/ + ****************************************************************************/ /* This struct defines the way the registers are stored. We need to save: */ @@ -251,9 +251,29 @@ struct xcptcontext }; #endif -/************************************************************************************ +/**************************************************************************** + * Inline functions + ****************************************************************************/ + +/* Return the current value of the stack pointer */ + +static inline uint16_t up_getsp(void) +{ + uint16_t sp; + + __asm__ __volatile__ + ( + "\tstc sp, %0\n\t" + : "=r" (sp) + : + : "memory" + ); + return sp; +} + +/**************************************************************************** * Public Data - ************************************************************************************/ + ****************************************************************************/ #ifndef __ASSEMBLY__ #ifdef __cplusplus @@ -264,9 +284,9 @@ extern "C" #define EXTERN extern #endif -/************************************************************************************ +/**************************************************************************** * Inline Functions - ************************************************************************************/ + ****************************************************************************/ #ifndef __ASSEMBLY__ @@ -323,9 +343,9 @@ static inline irqstate_t up_irq_enable(void) #endif -/************************************************************************************ +/**************************************************************************** * Public Functions Prototypes - ************************************************************************************/ + ****************************************************************************/ #undef EXTERN #ifdef __cplusplus diff --git a/arch/renesas/include/rx65n/arch.h b/arch/renesas/include/rx65n/arch.h index 9ba285b7e1d..2ee7623140b 100644 --- a/arch/renesas/include/rx65n/arch.h +++ b/arch/renesas/include/rx65n/arch.h @@ -39,29 +39,6 @@ #ifndef __ASSEMBLY__ -/**************************************************************************** - * Inline functions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_getsp - ****************************************************************************/ - -static inline uint16_t up_getsp(void) -{ - uint16_t sp; - - __asm__ __volatile__ - ( - "\tmvfc usp, %0\n\t" - : "=r" (sp) - : - :"memory" - ); - - return sp; -} - /**************************************************************************** * Public Variables ****************************************************************************/ diff --git a/arch/renesas/include/rx65n/irq.h b/arch/renesas/include/rx65n/irq.h index 991ccd8b08f..cb932c02065 100644 --- a/arch/renesas/include/rx65n/irq.h +++ b/arch/renesas/include/rx65n/irq.h @@ -1031,6 +1031,23 @@ static inline void __setsr(irqstate_t psw) __asm__ __volatile__("mvtc %0, psw": :"r"(psw)); } +/* Return the current value of the stack pointer */ + +static inline uint16_t up_getsp(void) +{ + uint16_t sp; + + __asm__ __volatile__ + ( + "\tmvfc usp, %0\n\t" + : "=r" (sp) + : + :"memory" + ); + + return sp; +} + /* Disable interrupts */ static inline void up_irq_disable(void) diff --git a/arch/renesas/include/sh1/arch.h b/arch/renesas/include/sh1/arch.h index c38ce88d51d..27cc262509e 100644 --- a/arch/renesas/include/sh1/arch.h +++ b/arch/renesas/include/sh1/arch.h @@ -39,28 +39,6 @@ #ifndef __ASSEMBLY__ -/**************************************************************************** - * Inline functions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_getsp - ****************************************************************************/ - -static inline uint32_t up_getsp(void) -{ - uint32_t sp; - - __asm__ __volatile__ - ( - "mov r15, %0\n\t" - : "=&z" (sp) - : - : "memory" - ); - return sp; -} - /**************************************************************************** * Public Variables ****************************************************************************/ diff --git a/arch/renesas/include/sh1/irq.h b/arch/renesas/include/sh1/irq.h index 112efa82cc5..d388e560eb6 100644 --- a/arch/renesas/include/sh1/irq.h +++ b/arch/renesas/include/sh1/irq.h @@ -507,6 +507,22 @@ static inline void __setsr(irqstate_t sr) __asm__ __volatile__ ("ldc %0, sr" : : "r" (sr)); } +/* Return the current value of the stack pointer */ + +static inline uint32_t up_getsp(void) +{ + uint32_t sp; + + __asm__ __volatile__ + ( + "mov r15, %0\n\t" + : "=&z" (sp) + : + : "memory" + ); + return sp; +} + /* Return the current interrupt enable state and disable interrupts */ static inline irqstate_t up_irq_save(void) diff --git a/arch/risc-v/include/arch.h b/arch/risc-v/include/arch.h index 1f75b49ac61..8435cd8f5db 100644 --- a/arch/risc-v/include/arch.h +++ b/arch/risc-v/include/arch.h @@ -78,29 +78,6 @@ # define ARCH_SPGTS (ARCH_PGT_MAX_LEVELS - 1) #endif -/**************************************************************************** - * Inline functions - ****************************************************************************/ - -#ifndef __ASSEMBLY__ - -/**************************************************************************** - * Name: up_getsp - ****************************************************************************/ - -static inline uintptr_t up_getsp(void) -{ - register uintptr_t sp; - __asm__ - ( - "\tadd %0, x0, x2\n" - : "=r"(sp) - ); - return sp; -} - -#endif - /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/arch/risc-v/include/irq.h b/arch/risc-v/include/irq.h index 23818a5efbe..7303344482e 100644 --- a/arch/risc-v/include/irq.h +++ b/arch/risc-v/include/irq.h @@ -568,6 +568,23 @@ struct xcptcontext #ifndef __ASSEMBLY__ +/**************************************************************************** + * Inline functions + ****************************************************************************/ + +/* Return the current value of the stack pointer */ + +static inline uintptr_t up_getsp(void) +{ + register uintptr_t sp; + __asm__ + ( + "\tadd %0, x0, x2\n" + : "=r"(sp) + ); + return sp; +} + /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/arch/sim/include/arch.h b/arch/sim/include/arch.h index c6314f3a161..eb6ba5fa05e 100644 --- a/arch/sim/include/arch.h +++ b/arch/sim/include/arch.h @@ -25,17 +25,4 @@ #ifndef __ARCH_SIM_INCLUDE_ARCH_H #define __ARCH_SIM_INCLUDE_ARCH_H -/**************************************************************************** - * Inline functions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_getsp - ****************************************************************************/ - -static inline uintptr_t up_getsp(void) -{ - return (uintptr_t)__builtin_frame_address(0); -} - #endif /* __ARCH_SIM_INCLUDE_ARCH_H */ diff --git a/arch/sim/include/irq.h b/arch/sim/include/irq.h index 3bd026eccc8..03c90b0c06a 100644 --- a/arch/sim/include/irq.h +++ b/arch/sim/include/irq.h @@ -69,6 +69,17 @@ extern "C" #define EXTERN extern #endif +/**************************************************************************** + * Inline functions + ****************************************************************************/ + +/* Return the current value of the stack pointer */ + +static inline uintptr_t up_getsp(void) +{ + return (uintptr_t)__builtin_frame_address(0); +} + /**************************************************************************** * Name: up_cpu_index * diff --git a/arch/sparc/include/arch.h b/arch/sparc/include/arch.h index 2be00b9c346..c3f6e519430 100644 --- a/arch/sparc/include/arch.h +++ b/arch/sparc/include/arch.h @@ -35,28 +35,6 @@ * Pre-processor Definitions ****************************************************************************/ -/**************************************************************************** - * Inline functions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_getsp - ****************************************************************************/ - -static inline uint32_t up_getsp(void) -{ - uint32_t retval; - - do - { - retval = 0; - __asm__ volatile("mov %%sp, %0" : "=r" (retval) : "0" (retval)); - } - while (0); - - return retval; -} - /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/arch/sparc/include/irq.h b/arch/sparc/include/irq.h index ab56c97527e..030da6f95bf 100644 --- a/arch/sparc/include/irq.h +++ b/arch/sparc/include/irq.h @@ -68,6 +68,26 @@ extern "C" #define EXTERN extern #endif +/**************************************************************************** + * Inline functions + ****************************************************************************/ + +/* Return the current value of the stack pointer */ + +static inline uint32_t up_getsp(void) +{ + uint32_t retval; + + do + { + retval = 0; + __asm__ volatile("mov %%sp, %0" : "=r" (retval) : "0" (retval)); + } + while (0); + + return retval; +} + /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/arch/x86/include/i486/arch.h b/arch/x86/include/i486/arch.h index b0539d97070..43f4daae374 100644 --- a/arch/x86/include/i486/arch.h +++ b/arch/x86/include/i486/arch.h @@ -349,64 +349,8 @@ begin_packed_struct struct idt_ptr_s uint32_t base; /* The address of the first GDT entry */ } end_packed_struct; -/**************************************************************************** - * Inline functions - ****************************************************************************/ - #ifndef __ASSEMBLY__ -/* Return stack pointer */ - -static inline uint32_t up_getsp(void) -{ - uint32_t regval; - - asm volatile( - "\tmovl %%esp, %0\n" - : "=rm" (regval) - : - : "memory"); - return regval; -} - -/* Get segment registers */ - -static inline uint32_t up_getds(void) -{ - uint32_t regval; - - asm volatile( - "\tmov %%ds, %0\n" - : "=rm" (regval) - : - : "memory"); - return regval; -} - -static inline uint32_t up_getcs(void) -{ - uint32_t regval; - - asm volatile( - "\tmov %%cs, %0\n" - : "=rm" (regval) - : - : "memory"); - return regval; -} - -static inline uint32_t up_getss(void) -{ - uint32_t regval; - - asm volatile( - "\tmov %%ss, %0\n" - : "=rm" (regval) - : - : "memory"); - return regval; -} - /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/arch/x86/include/i486/irq.h b/arch/x86/include/i486/irq.h index 8cf0fed130f..c0b46eb0b66 100644 --- a/arch/x86/include/i486/irq.h +++ b/arch/x86/include/i486/irq.h @@ -181,6 +181,58 @@ struct xcptcontext #ifndef __ASSEMBLY__ +/* Return stack pointer */ + +static inline uint32_t up_getsp(void) +{ + uint32_t regval; + + asm volatile( + "\tmovl %%esp, %0\n" + : "=rm" (regval) + : + : "memory"); + return regval; +} + +/* Get segment registers */ + +static inline uint32_t up_getds(void) +{ + uint32_t regval; + + asm volatile( + "\tmov %%ds, %0\n" + : "=rm" (regval) + : + : "memory"); + return regval; +} + +static inline uint32_t up_getcs(void) +{ + uint32_t regval; + + asm volatile( + "\tmov %%cs, %0\n" + : "=rm" (regval) + : + : "memory"); + return regval; +} + +static inline uint32_t up_getss(void) +{ + uint32_t regval; + + asm volatile( + "\tmov %%ss, %0\n" + : "=rm" (regval) + : + : "memory"); + return regval; +} + /* Name: up_irq_save, up_irq_restore, and friends. * * NOTE: This function should never be called from application code and, diff --git a/arch/x86_64/include/intel64/arch.h b/arch/x86_64/include/intel64/arch.h index 4b1f804e73a..e502bcde29b 100644 --- a/arch/x86_64/include/intel64/arch.h +++ b/arch/x86_64/include/intel64/arch.h @@ -347,198 +347,6 @@ begin_packed_struct struct ist_s uint16_t IOPB_OFFSET; /* IOPB_offset */ } end_packed_struct; -/**************************************************************************** - * Inline functions - ****************************************************************************/ - -static inline void setgdt(void *gdt, int size) -{ - struct gdt_ptr_s gdt_ptr; - gdt_ptr.limit = size; - gdt_ptr.base = (uintptr_t)gdt; - - asm volatile ("lgdt %0"::"m"(gdt_ptr):"memory"); -} - -static inline void setidt(void *idt, int size) -{ - struct idt_ptr_s idt_ptr; - idt_ptr.limit = size; - idt_ptr.base = (uintptr_t)idt; - - asm volatile ("lidt %0"::"m"(idt_ptr):"memory"); -} - -static inline uint64_t rdtsc(void) -{ - uint32_t lo; - uint32_t hi; - - asm volatile("rdtscp" : "=a" (lo), "=d" (hi)::"memory"); - return (uint64_t)lo | (((uint64_t)hi) << 32); -} - -static inline uint64_t _rdtsc(void) -{ - uint32_t lo; - uint32_t hi; - - asm volatile("rdtsc" : "=a" (lo), "=d" (hi)::"memory"); - return (uint64_t)lo | (((uint64_t)hi) << 32); -} - -static inline void set_pcid(uint64_t pcid) -{ - if (pcid < 4095) - { - asm volatile("mov %%cr3, %%rbx; andq $-4096, %%rbx; or %0, " - "%%rbx; mov %%rbx, %%cr3;" - ::"g"(pcid):"memory", "rbx", "rax"); - } -} - -static inline unsigned long read_msr(unsigned int msr) -{ - uint32_t low; - uint32_t high; - - asm volatile("rdmsr" : "=a" (low), "=d" (high) : "c" (msr)); - return low | ((unsigned long)high << 32); -} - -static inline void write_msr(unsigned int msr, unsigned long val) -{ - asm volatile("wrmsr" - : /* no output */ - : "c" (msr), "a" (val), "d" (val >> 32) - : "memory"); -} - -static inline uint64_t read_fsbase(void) -{ - uint64_t val; - asm volatile("rdfsbase %0" - : "=r" (val) - : /* no output */ - : "memory"); - - return val; -} - -static inline void write_fsbase(unsigned long val) -{ - asm volatile("wrfsbase %0" - : /* no output */ - : "r" (val) - : "memory"); -} - -static inline uint64_t read_gsbase(void) -{ - uint64_t val; - asm volatile("rdgsbase %0" - : "=r" (val) - : /* no output */ - : "memory"); - - return val; -} - -static inline void write_gsbase(unsigned long val) -{ - asm volatile("wrgsbase %0" - : /* no output */ - : "r" (val) - : "memory"); -} - -/* Return stack pointer */ - -static inline uint64_t up_getsp(void) -{ - uint64_t regval; - - asm volatile( - "\tmovq %%rsp, %0\n" - : "=rm" (regval) - : - : "memory"); - return regval; -} - -/* Get segment registers */ - -static inline uint32_t up_getds(void) -{ - uint32_t regval; - - asm volatile( - "\tmov %%ds, %0\n" - : "=rm" (regval) - : - : "memory"); - return regval; -} - -static inline uint32_t up_getcs(void) -{ - uint32_t regval; - - asm volatile( - "\tmov %%cs, %0\n" - : "=rm" (regval) - : - : "memory"); - return regval; -} - -static inline uint32_t up_getss(void) -{ - uint32_t regval; - - asm volatile( - "\tmov %%ss, %0\n" - : "=rm" (regval) - : - : "memory"); - return regval; -} - -static inline uint32_t up_getes(void) -{ - uint32_t regval; - - asm volatile( - "\tmov %%es, %0\n" - : "=rm" (regval) - : - : "memory"); - return regval; -} - -static inline uint32_t up_getfs(void) -{ - uint32_t regval; - - asm volatile( - "\tmov %%fs, %0\n" - : "=rm" (regval) - : - : "memory"); - return regval; -} - -static inline uint32_t up_getgs(void) -{ - uint32_t regval; - - asm volatile( - "\tmov %%gs, %0\n" - : "=rm" (regval) - : - : "memory"); - return regval; -} /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/arch/x86_64/include/intel64/irq.h b/arch/x86_64/include/intel64/irq.h index c93d04e8aab..4f843c43cb9 100644 --- a/arch/x86_64/include/intel64/irq.h +++ b/arch/x86_64/include/intel64/irq.h @@ -193,6 +193,195 @@ struct xcptcontext #ifndef __ASSEMBLY__ +static inline void setgdt(void *gdt, int size) +{ + struct gdt_ptr_s gdt_ptr; + gdt_ptr.limit = size; + gdt_ptr.base = (uintptr_t)gdt; + + asm volatile ("lgdt %0"::"m"(gdt_ptr):"memory"); +} + +static inline void setidt(void *idt, int size) +{ + struct idt_ptr_s idt_ptr; + idt_ptr.limit = size; + idt_ptr.base = (uintptr_t)idt; + + asm volatile ("lidt %0"::"m"(idt_ptr):"memory"); +} + +static inline uint64_t rdtsc(void) +{ + uint32_t lo; + uint32_t hi; + + asm volatile("rdtscp" : "=a" (lo), "=d" (hi)::"memory"); + return (uint64_t)lo | (((uint64_t)hi) << 32); +} + +static inline uint64_t _rdtsc(void) +{ + uint32_t lo; + uint32_t hi; + + asm volatile("rdtsc" : "=a" (lo), "=d" (hi)::"memory"); + return (uint64_t)lo | (((uint64_t)hi) << 32); +} + +static inline void set_pcid(uint64_t pcid) +{ + if (pcid < 4095) + { + asm volatile("mov %%cr3, %%rbx; andq $-4096, %%rbx; or %0, " + "%%rbx; mov %%rbx, %%cr3;" + ::"g"(pcid):"memory", "rbx", "rax"); + } +} + +static inline unsigned long read_msr(unsigned int msr) +{ + uint32_t low; + uint32_t high; + + asm volatile("rdmsr" : "=a" (low), "=d" (high) : "c" (msr)); + return low | ((unsigned long)high << 32); +} + +static inline void write_msr(unsigned int msr, unsigned long val) +{ + asm volatile("wrmsr" + : /* no output */ + : "c" (msr), "a" (val), "d" (val >> 32) + : "memory"); +} + +static inline uint64_t read_fsbase(void) +{ + uint64_t val; + asm volatile("rdfsbase %0" + : "=r" (val) + : /* no output */ + : "memory"); + + return val; +} + +static inline void write_fsbase(unsigned long val) +{ + asm volatile("wrfsbase %0" + : /* no output */ + : "r" (val) + : "memory"); +} + +static inline uint64_t read_gsbase(void) +{ + uint64_t val; + asm volatile("rdgsbase %0" + : "=r" (val) + : /* no output */ + : "memory"); + + return val; +} + +static inline void write_gsbase(unsigned long val) +{ + asm volatile("wrgsbase %0" + : /* no output */ + : "r" (val) + : "memory"); +} + +/* Return stack pointer */ + +static inline uint64_t up_getsp(void) +{ + uint64_t regval; + + asm volatile( + "\tmovq %%rsp, %0\n" + : "=rm" (regval) + : + : "memory"); + return regval; +} + +/* Get segment registers */ + +static inline uint32_t up_getds(void) +{ + uint32_t regval; + + asm volatile( + "\tmov %%ds, %0\n" + : "=rm" (regval) + : + : "memory"); + return regval; +} + +static inline uint32_t up_getcs(void) +{ + uint32_t regval; + + asm volatile( + "\tmov %%cs, %0\n" + : "=rm" (regval) + : + : "memory"); + return regval; +} + +static inline uint32_t up_getss(void) +{ + uint32_t regval; + + asm volatile( + "\tmov %%ss, %0\n" + : "=rm" (regval) + : + : "memory"); + return regval; +} + +static inline uint32_t up_getes(void) +{ + uint32_t regval; + + asm volatile( + "\tmov %%es, %0\n" + : "=rm" (regval) + : + : "memory"); + return regval; +} + +static inline uint32_t up_getfs(void) +{ + uint32_t regval; + + asm volatile( + "\tmov %%fs, %0\n" + : "=rm" (regval) + : + : "memory"); + return regval; +} + +static inline uint32_t up_getgs(void) +{ + uint32_t regval; + + asm volatile( + "\tmov %%gs, %0\n" + : "=rm" (regval) + : + : "memory"); + return regval; +} + /* Name: up_irq_save, up_irq_restore, and friends. * * NOTE: This function should never be called from application code and, diff --git a/arch/xtensa/include/arch.h b/arch/xtensa/include/arch.h index 9cabb928aa7..ceb5da2a570 100644 --- a/arch/xtensa/include/arch.h +++ b/arch/xtensa/include/arch.h @@ -39,28 +39,6 @@ * Pre-processor Definitions ****************************************************************************/ -/**************************************************************************** - * Inline functions - ****************************************************************************/ - -/**************************************************************************** - * Name: up_getsp - ****************************************************************************/ - -static inline uint32_t up_getsp(void) inline_function; -static inline uint32_t up_getsp(void) -{ - register uint32_t sp; - - __asm__ __volatile__ - ( - "mov %0, sp\n" - : "=r" (sp) - ); - - return sp; -} - /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/arch/xtensa/include/irq.h b/arch/xtensa/include/irq.h index b8cd7a91c41..fdad3b8211b 100644 --- a/arch/xtensa/include/irq.h +++ b/arch/xtensa/include/irq.h @@ -232,6 +232,21 @@ static inline void xtensa_setps(uint32_t ps) ); } +/* Return the current value of the stack pointer */ + +static inline uint32_t up_getsp(void) +{ + register uint32_t sp; + + __asm__ __volatile__ + ( + "mov %0, sp\n" + : "=r" (sp) + ); + + return sp; +} + /* Restore the value of the PS register */ static inline void up_irq_restore(uint32_t ps) diff --git a/arch/z16/include/arch.h b/arch/z16/include/arch.h index d3da587831a..2b0a81f56f8 100644 --- a/arch/z16/include/arch.h +++ b/arch/z16/include/arch.h @@ -59,10 +59,6 @@ extern "C" #define EXTERN extern #endif -/* Return the current value of the stack pointer */ - -chipreg_t up_getsp(void); - #undef EXTERN #ifdef __cplusplus } diff --git a/arch/z16/include/irq.h b/arch/z16/include/irq.h index e908e81a569..c153db24480 100644 --- a/arch/z16/include/irq.h +++ b/arch/z16/include/irq.h @@ -62,6 +62,10 @@ extern "C" #define EXTERN extern #endif +/* Return the current value of the stack pointer */ + +chipreg_t up_getsp(void); + /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/arch/z80/include/arch.h b/arch/z80/include/arch.h index ac3a93bc1bb..185945c5046 100644 --- a/arch/z80/include/arch.h +++ b/arch/z80/include/arch.h @@ -59,10 +59,6 @@ extern "C" #define EXTERN extern #endif -/* Return the current value of the stack pointer */ - -uintptr_t up_getsp(void); - #undef EXTERN #ifdef __cplusplus } diff --git a/arch/z80/include/irq.h b/arch/z80/include/irq.h index c92bf2e7495..91b5d06d19d 100644 --- a/arch/z80/include/irq.h +++ b/arch/z80/include/irq.h @@ -32,4 +32,25 @@ #include #include +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/* Return the current value of the stack pointer */ + +uintptr_t up_getsp(void); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + #endif /* __ARCH_Z80_INCLUDE_IRQ_H */