Skip to contentSkip to conversation

i386: add alternative_output() for altinstructions

PATCH New Chuck Ebbert 1 participant 1 message Jul 23, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i386: add alternative_output() for altinstructions

This patch adds alternative_output() for altinstructions that have output. Only one output is allowed.

It also cleans up the comments for alternative_input().

With this patch in place, I cleaned up the i387 save/restore in my local copy so it now looks like this:

===================================================================
static inline void restore_fpu( struct task_struct *tsk )

{
	alternative_input(
		"frstor %1 ; nop",
		"fxrstor %1",
		X86_FEATURE_FXSR,
		"m" (tsk->thread.i387.fxsave));
}
static inline void __save_init_fpu( struct task_struct *tsk )
{
	alternative_output(
		"fnsave %0 ; nop ; fwait ; nop",
		"fxsave %0 ; fnclex",
		X86_FEATURE_FXSR,
		"=m" (tsk->thread.i387.fxsave));
	tsk->thread_info->status &= ~TS_USEDFPU;
}

===================================================================

include/asm-i386/system.h +26 -5
Index: 2.6.13-rc3a/include/asm-i386/system.h
===================================================================
@@ -313,13 +313,13 @@
 
 /*
  * Alternative inline assembly with input.
- * 
- * Pecularities:
- * No memory clobber here. 
+ *
+ * Peculiarities:
+ * No memory clobber here.
  * Argument numbers start with 1.
  * Best is to use constraints that are fixed size (like (%1) ... "r")
- * If you use variable sized constraints like "m" or "g" in the 
- * replacement maake sure to pad to the worst case length.
+ * If you use variable sized constraints like "m" or "g" in the
+ * replacement make sure to pad to the worst case length.
  */
 #define alternative_input(oldinstr, newinstr, feature, input...)		\
 	asm volatile ("661:\n\t" oldinstr "\n662:\n"				\
@@ -336,6 +336,27 @@
 		      ".previous" :: "i" (feature), ##input)
 
 /*
+ * Alternative inline assembly with output.
+ *
+ * Same as alternative_input, except:
+ *	No inputs.
+ *	Only one output: 0.
+ */
+#define alternative_output(oldinstr, newinstr, feature, output...)		\
+	asm volatile ("661:\n\t" oldinstr "\n662:\n"				\
+		      ".section .altinstructions,\"a\"\n"			\
+		      "  .align 4\n"						\
+		      "  .long 661b\n"            /* label */			\
+		      "  .long 663f\n"		  /* new instruction */ 	\
+		      "  .byte %c1\n"             /* feature bit */		\
+		      "  .byte 662b-661b\n"       /* sourcelen */		\
+		      "  .byte 664f-663f\n"       /* replacementlen */ 		\
+		      ".previous\n"						\
+		      ".section .altinstr_replacement,\"ax\"\n"			\
+		      "663:\n\t" newinstr "\n664:\n"   /* replacement */ 	\
+		      ".previous" : output : "i" (feature))
+
+/*
  * Force strict CPU ordering.
  * And yes, this is required on UP too when we're talking
  * to devices.

__
Chuck