Skip to contentSkip to conversation

Fix assembly constraints

x86 setup H. Peter Anvin 2 participants 2 messages Jul 13, 2007

lore
Share & tools
lore
#0 lore raw

Fix incorrect assembly constraints. In particular, fix memory constraints used inside push..pop, which can cause invalid operation since gcc may generate %esp-relative references.

Additionally:

outl() should have "dN" not "dn".

query_mca() shouldn't listen 16/32-bit registers in an 8-bit only context.

has_eflag(): the "mask" is only used well after both the stack pointer and the output registers have been touched; this requires the output registers to be earlyclobbers (=&) and the input to exclude memory (so "ri", not "g").

Thanks to Chuck Ebbert for prompting this review.

arch/i386/boot/boot.h +1 -1
index 0329c4f..dec70c9 100644
@@ -56,7 +56,7 @@ static inline u16 inw(u16 port)
 
 static inline void outl(u32 v, u16 port)
 {
-	asm volatile("outl %0,%1" : : "a" (v), "dn" (port));
+	asm volatile("outl %0,%1" : : "a" (v), "dN" (port));
 }
 static inline u32 inl(u32 port)
 {
arch/i386/boot/cpucheck.c +2 -2
index 8b0f447..991e8ce 100644
@@ -115,8 +115,8 @@ static int has_eflag(u32 mask)
 	    "pushfl ; "
 	    "popl %1 ; "
 	    "popfl"
-	    : "=r" (f0), "=r" (f1)
-	    : "g" (mask));
+	    : "=&r" (f0), "=&r" (f1)
+	    : "ri" (mask));
 
 	return !!((f0^f1) & mask);
 }
arch/i386/boot/mca.c +1 -1
index 9b68bd1..68222f2 100644
@@ -26,7 +26,7 @@ int query_mca(void)
 	    "setc %0 ; "
 	    "movw %%es, %1 ; "
 	    "popw %%es"
-	    : "=acdSDm" (err), "=acdSDm" (es), "=b" (bx)
+	    : "=acd" (err), "=acdSD" (es), "=b" (bx)
 	    : "a" (0xc000));
 
 	if (err)
arch/i386/boot/pm.c +1 -1
index 3fa53e1..1df025c 100644
@@ -65,7 +65,7 @@ static void move_kernel_around(void)
 			     "popw %%ds ; "
 			     "popw %%es"
 			     : "+c" (dwords)
-			     : "rm" (dst_seg), "rm" (src_seg)
+			     : "r" (dst_seg), "r" (src_seg)
 			     : "esi", "edi");
 
 		syssize -= paras;
arch/i386/boot/video.c +1 -1
index 3bb3573..027a2c9 100644
@@ -411,7 +411,7 @@ static void restore_screen(void)
 			     "1: rep;stosl ; "
 			     "popw %%es"
 			     : "+D" (dst), "+c" (npad)
-			     : "bdSm" (video_segment),
+			     : "bdS" (video_segment),
 			       "a" (0x07200720));
 	}
 
arch/i386/boot/voyager.c +1 -1
index 9221614..61c8fe0 100644
@@ -32,7 +32,7 @@ int query_voyager(void)
 	    "setc %0 ; "
 	    "movw %%es, %1 ; "
 	    "popw %%es"
-	    : "=qm" (err), "=rm" (es), "=D" (di)
+	    : "=q" (err), "=r" (es), "=D" (di)
 	    : "a" (0xffc0));
 
 	if (err)
#1 lore raw
Quoted 11 lines · H. Peter Anvin

Fix incorrect assembly constraints. In particular, fix memory constraints used inside push..pop, which can cause invalid operation since gcc may generate %esp-relative references.

Additionally:

outl() should have "dN" not "dn".

query_mca() shouldn't listen 16/32-bit registers in an 8-bit only context.

Quoted 7 lines

has_eflag(): the "mask" is only used well after both the stack pointer and the output registers have been touched; this requires the output registers to be earlyclobbers (=&) and the input to exclude memory (so "ri", not "g").

Thanks to Chuck Ebbert for prompting this review.

That was Etienne Lorrain (cc'd), not me. All I did was reply to Etienne's post and add cc:'s because the original only went to linux-kernel.

Quoted 84 lines
arch/i386/boot/boot.h +1 -1
index 0329c4f..dec70c9 100644
@@ -56,7 +56,7 @@ static inline u16 inw(u16 port)
 
 static inline void outl(u32 v, u16 port)
 {
-	asm volatile("outl %0,%1" : : "a" (v), "dn" (port));
+	asm volatile("outl %0,%1" : : "a" (v), "dN" (port));
 }
 static inline u32 inl(u32 port)
 {
arch/i386/boot/cpucheck.c +2 -2
index 8b0f447..991e8ce 100644
@@ -115,8 +115,8 @@ static int has_eflag(u32 mask)
 	    "pushfl ; "
 	    "popl %1 ; "
 	    "popfl"
-	    : "=r" (f0), "=r" (f1)
-	    : "g" (mask));
+	    : "=&r" (f0), "=&r" (f1)
+	    : "ri" (mask));
 
 	return !!((f0^f1) & mask);
 }
arch/i386/boot/mca.c +1 -1
index 9b68bd1..68222f2 100644
@@ -26,7 +26,7 @@ int query_mca(void)
 	    "setc %0 ; "
 	    "movw %%es, %1 ; "
 	    "popw %%es"
-	    : "=acdSDm" (err), "=acdSDm" (es), "=b" (bx)
+	    : "=acd" (err), "=acdSD" (es), "=b" (bx)
 	    : "a" (0xc000));
 
 	if (err)
arch/i386/boot/pm.c +1 -1
index 3fa53e1..1df025c 100644
@@ -65,7 +65,7 @@ static void move_kernel_around(void)
 			     "popw %%ds ; "
 			     "popw %%es"
 			     : "+c" (dwords)
-			     : "rm" (dst_seg), "rm" (src_seg)
+			     : "r" (dst_seg), "r" (src_seg)
 			     : "esi", "edi");
 
 		syssize -= paras;
arch/i386/boot/video.c +1 -1
index 3bb3573..027a2c9 100644
@@ -411,7 +411,7 @@ static void restore_screen(void)
 			     "1: rep;stosl ; "
 			     "popw %%es"
 			     : "+D" (dst), "+c" (npad)
-			     : "bdSm" (video_segment),
+			     : "bdS" (video_segment),
 			       "a" (0x07200720));
 	}
 
arch/i386/boot/voyager.c +1 -1
index 9221614..61c8fe0 100644
@@ -32,7 +32,7 @@ int query_voyager(void)
 	    "setc %0 ; "
 	    "movw %%es, %1 ; "
 	    "popw %%es"
-	    : "=qm" (err), "=rm" (es), "=D" (di)
+	    : "=q" (err), "=r" (es), "=D" (di)
 	    : "a" (0xffc0));
 
 	if (err)