From 5249a4cd383a3cb0f8bb9cbdc21df3dfa5d864b4 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Fri, 13 Feb 2004 18:44:42 +0000 Subject: [PATCH] Use "iq" instead of "ir" for the register constraint. "iq" means 'an integer constant or one of %ax,%bx,%cx, or %dx. The prior use of "ir" could cause GCC to attempt to use a 'low byte' accessor on a register that cannot be accessed that way, such as '%si' (e.g. %sil). I see no need to get fancy so I am just applying %iq to all the atomic instructions. It's good enough. Reported-by: YONETANI Tomokazu --- sys/cpu/i386/include/atomic.h | 62 ++++++----------------------------- sys/i386/include/atomic.h | 62 ++++++----------------------------- 2 files changed, 20 insertions(+), 104 deletions(-) diff --git a/sys/cpu/i386/include/atomic.h b/sys/cpu/i386/include/atomic.h index 9f6830e51a..377d9c60f3 100644 --- a/sys/cpu/i386/include/atomic.h +++ b/sys/cpu/i386/include/atomic.h @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/include/atomic.h,v 1.9.2.1 2000/07/07 00:38:47 obrien Exp $ - * $DragonFly: src/sys/cpu/i386/include/atomic.h,v 1.4 2003/07/20 03:55:25 dillon Exp $ + * $DragonFly: src/sys/cpu/i386/include/atomic.h,v 1.5 2004/02/13 18:44:42 dillon Exp $ */ #ifndef _MACHINE_ATOMIC_H_ #define _MACHINE_ATOMIC_H_ @@ -80,8 +80,12 @@ * atomic instructions are MP safe, the nonlocked instructions are * local-interrupt-safe (so we don't depend on C 'X |= Y' generating an * atomic instruction). + * + * +m - memory is read and written (=m - memory is only written) + * iq - integer constant or %ax/%bx/%cx/%dx (ir = int constant or any reg) + * (Note: byte instructions only work on %ax,%bx,%cx, or %dx). iq + * is good enough for our needs so don't get fancy. */ -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 9) /* egcs 1.1.2+ version */ #define ATOMIC_ASM(NAME, TYPE, OP, V) \ @@ -89,40 +93,19 @@ static __inline void \ atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\ { \ __asm __volatile(MPLOCKED OP \ - : "=m" (*p) \ - : "0" (*p), "ir" (V)); \ + : "+m" (*p) \ + : "iq" (V)); \ } \ static __inline void \ atomic_##NAME##_##TYPE##_nonlocked(volatile u_##TYPE *p, u_##TYPE v)\ { \ __asm __volatile(MPLOCKED OP \ - : "=m" (*p) \ - : "0" (*p), "ir" (V)); \ + : "+m" (*p) \ + : "iq" (V)); \ } -#else - -/* gcc <= 2.8 version */ -#define ATOMIC_ASM(NAME, TYPE, OP, V) \ -static __inline void \ -atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\ -{ \ - __asm __volatile(MPLOCKED OP \ - : "=m" (*p) \ - : "ir" (V)); \ -} \ -static __inline void \ -atomic_##NAME##_##TYPE##_nonlocked(volatile u_##TYPE *p, u_##TYPE v)\ -{ \ - __asm __volatile(OP \ - : "=m" (*p) \ - : "ir" (V)); \ -} -#endif #endif /* KLD_MODULE */ -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 9) - /* egcs 1.1.2+ version */ ATOMIC_ASM(set, char, "orb %b2,%0", v) ATOMIC_ASM(clear, char, "andb %b2,%0", ~v) @@ -144,29 +127,4 @@ ATOMIC_ASM(clear, long, "andl %2,%0", ~v) ATOMIC_ASM(add, long, "addl %2,%0", v) ATOMIC_ASM(subtract, long, "subl %2,%0", v) -#else - -/* gcc <= 2.8 version */ -ATOMIC_ASM(set, char, "orb %1,%0", v) -ATOMIC_ASM(clear, char, "andb %1,%0", ~v) -ATOMIC_ASM(add, char, "addb %1,%0", v) -ATOMIC_ASM(subtract, char, "subb %1,%0", v) - -ATOMIC_ASM(set, short, "orw %1,%0", v) -ATOMIC_ASM(clear, short, "andw %1,%0", ~v) -ATOMIC_ASM(add, short, "addw %1,%0", v) -ATOMIC_ASM(subtract, short, "subw %1,%0", v) - -ATOMIC_ASM(set, int, "orl %1,%0", v) -ATOMIC_ASM(clear, int, "andl %1,%0", ~v) -ATOMIC_ASM(add, int, "addl %1,%0", v) -ATOMIC_ASM(subtract, int, "subl %1,%0", v) - -ATOMIC_ASM(set, long, "orl %1,%0", v) -ATOMIC_ASM(clear, long, "andl %1,%0", ~v) -ATOMIC_ASM(add, long, "addl %1,%0", v) -ATOMIC_ASM(subtract, long, "subl %1,%0", v) - -#endif - #endif /* ! _MACHINE_ATOMIC_H_ */ diff --git a/sys/i386/include/atomic.h b/sys/i386/include/atomic.h index ae9f684ea5..ff625356ce 100644 --- a/sys/i386/include/atomic.h +++ b/sys/i386/include/atomic.h @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/include/atomic.h,v 1.9.2.1 2000/07/07 00:38:47 obrien Exp $ - * $DragonFly: src/sys/i386/include/Attic/atomic.h,v 1.4 2003/07/20 03:55:25 dillon Exp $ + * $DragonFly: src/sys/i386/include/Attic/atomic.h,v 1.5 2004/02/13 18:44:42 dillon Exp $ */ #ifndef _MACHINE_ATOMIC_H_ #define _MACHINE_ATOMIC_H_ @@ -80,8 +80,12 @@ * atomic instructions are MP safe, the nonlocked instructions are * local-interrupt-safe (so we don't depend on C 'X |= Y' generating an * atomic instruction). + * + * +m - memory is read and written (=m - memory is only written) + * iq - integer constant or %ax/%bx/%cx/%dx (ir = int constant or any reg) + * (Note: byte instructions only work on %ax,%bx,%cx, or %dx). iq + * is good enough for our needs so don't get fancy. */ -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 9) /* egcs 1.1.2+ version */ #define ATOMIC_ASM(NAME, TYPE, OP, V) \ @@ -89,40 +93,19 @@ static __inline void \ atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\ { \ __asm __volatile(MPLOCKED OP \ - : "=m" (*p) \ - : "0" (*p), "ir" (V)); \ + : "+m" (*p) \ + : "iq" (V)); \ } \ static __inline void \ atomic_##NAME##_##TYPE##_nonlocked(volatile u_##TYPE *p, u_##TYPE v)\ { \ __asm __volatile(MPLOCKED OP \ - : "=m" (*p) \ - : "0" (*p), "ir" (V)); \ + : "+m" (*p) \ + : "iq" (V)); \ } -#else - -/* gcc <= 2.8 version */ -#define ATOMIC_ASM(NAME, TYPE, OP, V) \ -static __inline void \ -atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v)\ -{ \ - __asm __volatile(MPLOCKED OP \ - : "=m" (*p) \ - : "ir" (V)); \ -} \ -static __inline void \ -atomic_##NAME##_##TYPE##_nonlocked(volatile u_##TYPE *p, u_##TYPE v)\ -{ \ - __asm __volatile(OP \ - : "=m" (*p) \ - : "ir" (V)); \ -} -#endif #endif /* KLD_MODULE */ -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 9) - /* egcs 1.1.2+ version */ ATOMIC_ASM(set, char, "orb %b2,%0", v) ATOMIC_ASM(clear, char, "andb %b2,%0", ~v) @@ -144,29 +127,4 @@ ATOMIC_ASM(clear, long, "andl %2,%0", ~v) ATOMIC_ASM(add, long, "addl %2,%0", v) ATOMIC_ASM(subtract, long, "subl %2,%0", v) -#else - -/* gcc <= 2.8 version */ -ATOMIC_ASM(set, char, "orb %1,%0", v) -ATOMIC_ASM(clear, char, "andb %1,%0", ~v) -ATOMIC_ASM(add, char, "addb %1,%0", v) -ATOMIC_ASM(subtract, char, "subb %1,%0", v) - -ATOMIC_ASM(set, short, "orw %1,%0", v) -ATOMIC_ASM(clear, short, "andw %1,%0", ~v) -ATOMIC_ASM(add, short, "addw %1,%0", v) -ATOMIC_ASM(subtract, short, "subw %1,%0", v) - -ATOMIC_ASM(set, int, "orl %1,%0", v) -ATOMIC_ASM(clear, int, "andl %1,%0", ~v) -ATOMIC_ASM(add, int, "addl %1,%0", v) -ATOMIC_ASM(subtract, int, "subl %1,%0", v) - -ATOMIC_ASM(set, long, "orl %1,%0", v) -ATOMIC_ASM(clear, long, "andl %1,%0", ~v) -ATOMIC_ASM(add, long, "addl %1,%0", v) -ATOMIC_ASM(subtract, long, "subl %1,%0", v) - -#endif - #endif /* ! _MACHINE_ATOMIC_H_ */ -- 2.41.0