[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[MiNT] [patch] Line A for ColdFire



Hello.

I have tried to compile bash for ColdFire and it crashed because it uses ncurses, which uses ioctl(TIOCGWINSZ), which uses... Line A.

The Line A interface is problematic on ColdFire because all the opcodes conflict with the MAC instructions, and do not trigger any exception. I found a very simple solution: use the opcodes A92X instead of A00X. These opcodes are invalid on any ColdFire and trigger the standard Line A exception. Then the OS has to keep only the 4 lower bits. EmuTOS and FireTOS have already been patched to support this modified API on ColdFire, and it works well.

The attached patch adds support to the MiNTLib for this new Line A API for ColdFire. I have also included "memory" in the clobber lists to avoid any instruction reordering by GCC. This happens sometimes when compiling for ColdFire, that smells like a GCC bug.

Alan, please commit this patch to the MiNTLib.

--
Vincent Rivière
diff -aurN -x CVS mintlib.orig/include/mint/linea.h mintlib/include/mint/linea.h
--- mintlib.orig/include/mint/linea.h	2009-05-18 22:32:10.375000000 +0200
+++ mintlib/include/mint/linea.h	2010-07-06 21:09:03.171875000 +0200
@@ -757,6 +757,20 @@
 
 	/* Functions */
 
+#ifdef __mcoldfire__
+	// On ColdFire V4e, the standard Line A opcodes
+	// conflict with some valid MAC instructions.
+	// Fortunately, the following range is always invalid
+	// and triggers the standard Line A exception.
+	// The ColdFire OS will keep only the last 4 bits
+	#define LINEA_OPCODE_BASE 0xa920
+#else
+	#define LINEA_OPCODE_BASE 0xa000
+#endif
+	#define ASM_LINEA3(opcode) ".word	" #opcode
+	#define ASM_LINEA2(opcode) ASM_LINEA3(opcode)
+	#define ASM_LINEA(n) ASM_LINEA2(LINEA_OPCODE_BASE+n)
+
 #ifdef __GNUC_INLINE__
 
 #define linea0() 							\
@@ -767,10 +781,11 @@
 									\
 	__asm__ volatile						\
 	(								\
-		".word	0xA000"						\
+		ASM_LINEA(0x0)						\
 	: "=g"(__xaline), "=g"(__xfonts), "=g"(__xfuncs)  /* outputs */	\
 	: 						  /* inputs  */	\
 	: __CLOBBER_RETURN("a0") __CLOBBER_RETURN("a1") __CLOBBER_RETURN("a2") "d0", "d1", "d2"       /* clobbered regs */	\
+	  AND_MEMORY							\
 	);								\
 	__aline = __xaline;						\
 	__fonts = __xfonts;						\
@@ -781,10 +796,11 @@
 ({									\
 	__asm__ volatile						\
 	(								\
-		".word	0xA001"						\
+		ASM_LINEA(0x1)						\
 	: 						  /* outputs */	\
 	: 						  /* inputs  */	\
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	\
+	  AND_MEMORY							\
 	);								\
 })
 
@@ -793,10 +809,11 @@
 	register short retvalue __asm__ ("d0");				\
 	__asm__ volatile						\
 	(								\
-		".word	0xA002"						\
+		ASM_LINEA(0x2)						\
 	: "=g"(retvalue)				  /* outputs */	\
 	: 						  /* inputs  */	\
 	: __CLOBBER_RETURN("d0") "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	\
+	  AND_MEMORY							\
 	);								\
 	(int)retvalue;							\
 })
@@ -805,10 +822,11 @@
 ({									\
 	__asm__ volatile						\
 	(								\
-		".word	0xA003"						\
+		ASM_LINEA(0x3)						\
 	: 						  /* outputs */	\
 	: 						  /* inputs  */	\
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	\
+	  AND_MEMORY							\
 	);								\
 })
 
@@ -816,10 +834,11 @@
 ({									\
 	__asm__ volatile						\
 	(								\
-		".word	0xA004"						\
+		ASM_LINEA(0x4)						\
 	: 						  /* outputs */	\
 	: 						  /* inputs  */	\
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	\
+	  AND_MEMORY							\
 	);								\
 })
 
@@ -827,10 +846,11 @@
 ({									\
 	__asm__ volatile						\
 	(								\
-		".word	0xA005"						\
+		ASM_LINEA(0x5)						\
 	: 						  /* outputs */	\
 	: 						  /* inputs  */	\
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	\
+	  AND_MEMORY							\
 	);								\
 })
 
@@ -838,10 +858,11 @@
 ({									\
 	__asm__ volatile						\
 	(								\
-		".word	0xA006"						\
+		ASM_LINEA(0x6)						\
 	: 						  /* outputs */	\
 	: 						  /* inputs  */	\
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	\
+	  AND_MEMORY							\
 	);								\
 })
 
@@ -851,11 +872,12 @@
 	(								\
 		PUSH_SP("d2/a2/a6", 12)					\
  		"movl	%0,a6\n\t"					\
-		".word	0xA007\n\t"					\
+		ASM_LINEA(0x7) "\n\t"					\
 		POP_SP("d2/a2/a6", 12)					\
 	: 						  /* outputs */	\
 	: "r"(P)					  /* inputs  */	\
 	: "d0", "d1", "a0", "a1"	  	/* clobbered regs */	\
+	  AND_MEMORY							\
 	);								\
 })
 
@@ -863,10 +885,11 @@
 ({									\
 	__asm__ volatile						\
 	(								\
-		".word	0xA008"						\
+		ASM_LINEA(0x8)						\
 	: 						  /* outputs */	\
 	: 						  /* inputs  */	\
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	\
+	  AND_MEMORY							\
 	);								\
 })
 
@@ -874,10 +897,11 @@
 ({									\
 	__asm__ volatile						\
 	(								\
-		".word	0xA009"						\
+		ASM_LINEA(0x9)						\
 	: 						  /* outputs */	\
 	: 						  /* inputs  */	\
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	\
+	  AND_MEMORY							\
 	);								\
 })
 
@@ -885,10 +909,11 @@
 ({									\
 	__asm__ volatile						\
 	(								\
-		".word	0xA00A"						\
+		ASM_LINEA(0xa)						\
 	: 						  /* outputs */	\
 	: 						  /* inputs  */	\
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	\
+	  AND_MEMORY							\
 	);								\
 })
 
@@ -896,10 +921,11 @@
 ({									\
 	__asm__ volatile						\
 	(								\
-		".word	0xA00B"						\
+		ASM_LINEA(0xb)						\
 	: 						  /* outputs */	\
 	: 						  /* inputs  */	\
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	\
+	  AND_MEMORY							\
 	);								\
 })
 
@@ -909,11 +935,12 @@
 	(								\
  		"movl	%0,a2\n\t"					\
 		"movl	a6,sp@-\n\t"					\
-		".word	0xA00C\n\t"					\
+		ASM_LINEA(0xc) "\n\t"					\
 		"movl	sp@+,a6"					\
 	: 						  /* outputs */	\
 	: "g"(P)					  /* inputs  */	\
 	: "d0", "d1", "d2", "a0", "a1", "a2"	   /* clobbered regs */	\
+	  AND_MEMORY							\
 	);								\
 })
 
@@ -927,11 +954,12 @@
  		"movl	%2,a0\n\t"					\
  		"movl	%3,a2\n\t"					\
 		"movl	a6,sp@-\n\t"					\
-		".word	0xA00D\n\t"					\
+		ASM_LINEA(0xd) "\n\t"					\
 		"movl	sp@+,a6"					\
 	: 						  /* outputs */	\
 	: "g"(x), "g"(y), "g"(sd), "g"(ss)		  /* inputs  */	\
 	: "d0", "d1", "d2", "a0", "a1", "a2"	   /* clobbered regs */	\
+	  AND_MEMORY							\
 	);								\
 })
 
@@ -939,10 +967,11 @@
 ({									\
 	__asm__ volatile						\
 	(								\
-		".word	0xA00E"						\
+		ASM_LINEA(0xe)						\
 	: 						  /* outputs */	\
 	: 						  /* inputs  */	\
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	\
+	  AND_MEMORY							\
 	);								\
 })
 
@@ -950,10 +979,11 @@
 ({									\
 	__asm__ volatile						\
 	(								\
-		".word	0xA00F"						\
+		ASM_LINEA(0xf)						\
 	: 						  /* outputs */	\
 	: 						  /* inputs  */	\
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	\
+	  AND_MEMORY							\
 	);								\
 })
 
diff -aurN -x CVS mintlib.orig/mintlib/linea.c mintlib/mintlib/linea.c
--- mintlib.orig/mintlib/linea.c	2009-05-18 22:32:10.406250000 +0200
+++ mintlib/mintlib/linea.c	2010-07-06 21:17:52.453125000 +0200
@@ -14,10 +14,11 @@
 
         __asm__ volatile
         (
-		".word	0xA000"
+		ASM_LINEA(0x0)
         : "=g"(__xaline), "=g"(__xfonts), "=g"(__xfuncs)  /* outputs */
         :                                                 /* inputs  */
         : __CLOBBER_RETURN("a0") __CLOBBER_RETURN("a1") __CLOBBER_RETURN("a2") "d0", "d1", "d2"       /* clobbered regs */
+	  AND_MEMORY
         );
 
         __aline = __xaline;
@@ -29,10 +30,11 @@
 {									
 	__asm__ volatile
 	(
-		".word	0xA001"
+		ASM_LINEA(0x1)
 	: 						  /* outputs */	
 	: 						  /* inputs  */	
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	
+	  AND_MEMORY
 	);								
 }
 
@@ -42,10 +44,11 @@
 
 	__asm__ volatile						
 	(
-		".word	0xA002"
+		ASM_LINEA(0x2)
 	: "=r"(retvalue)				  /* outputs */	
 	: 						  /* inputs  */	
 	: __CLOBBER_RETURN("d0") "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	
+	  AND_MEMORY
 	);								
 
 	return (int) retvalue;
@@ -55,10 +58,11 @@
 {									
 	__asm__ volatile						
 	(
-		".word	0xA003"
+		ASM_LINEA(0x3)
 	: 						  /* outputs */	
 	: 						  /* inputs  */	
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	
+	  AND_MEMORY
 	);								
 }
 
@@ -66,10 +70,11 @@
 {									
 	__asm__ volatile						
 	(
-		".word	0xA004"
+		ASM_LINEA(0x4)
 	: 						  /* outputs */	
 	: 						  /* inputs  */	
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	
+	  AND_MEMORY
 	);								
 }
 
@@ -77,10 +82,11 @@
 {									
 	__asm__ volatile						
 	(
-		".word	0xA005"
+		ASM_LINEA(0x5)
 	: 						  /* outputs */	
 	: 						  /* inputs  */	
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	
+	  AND_MEMORY
 	);								
 }
 
@@ -88,10 +94,11 @@
 {									
 	__asm__ volatile						
 	(
-		".word	0xA006"
+		ASM_LINEA(0x6)
 	: 						  /* outputs */	
 	: 						  /* inputs  */	
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	
+	  AND_MEMORY
 	);								
 }
 
@@ -101,11 +108,12 @@
 	(
 		PUSH_SP("d2/a2/a6", 12)
  		"movl	%0,a6\n\t"
-		".word	0xA007\n\t"
+		ASM_LINEA(0x7) "\n\t"
 		POP_SP("d2/a2/a6", 12)
 	: 						  /* outputs */	
 	: "r"(P)					  /* inputs  */	
 	: "d0", "d1", "a0", "a1"		   /* clobbered regs */
+	  AND_MEMORY
 	);								
 }
 
@@ -113,10 +121,11 @@
 {									
 	__asm__ volatile						
 	(
-		".word	0xA008"
+		ASM_LINEA(0x8)
 	: 						  /* outputs */	
 	: 						  /* inputs  */	
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	
+	  AND_MEMORY
 	);								
 }
 
@@ -124,10 +133,11 @@
 {									
 	__asm__ volatile						
 	(
-		".word	0xA009"
+		ASM_LINEA(0x9)
 	: 						  /* outputs */	
 	: 						  /* inputs  */	
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	
+	  AND_MEMORY
 	);								
 }
 
@@ -135,10 +145,11 @@
 {
 	__asm__ volatile						
 	(
-		".word	0xA00A"
+		ASM_LINEA(0xa)
 	: 						  /* outputs */	
 	: 						  /* inputs  */	
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	
+	  AND_MEMORY
 	);								
 }
 
@@ -146,10 +157,11 @@
 {									
 	__asm__ volatile						
 	(
-		".word	0xA00B"
+		ASM_LINEA(0xb)
 	: 						  /* outputs */	
 	: 						  /* inputs  */	
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	
+	  AND_MEMORY
 	);								
 }
 
@@ -158,10 +170,11 @@
 	__asm__ volatile						
 	(
  		"movl	%0,a2\n\t"
-		".word	0xA00C"
+		ASM_LINEA(0xc)
 	: 						  /* outputs */	
 	: "r"(P)					  /* inputs  */	
 	: "d0", "d1", "d2", "a0", "a1", "a2"              /* clobbered regs */	
+	  AND_MEMORY
 	);								
 }
 
@@ -173,10 +186,11 @@
  		"movw	%1,d1\n\t"
  		"movl	%2,a0\n\t"
  		"movl	%3,a2\n\t"
-		".word	0xA00D"
+		ASM_LINEA(0xd)
 	: 						  /* outputs */	
 	: "r"((short)x), "r"((short)y), "r"(sd), "r"(ss)  /* inputs  */	
 	: "d0", "d1", "d2", "a0", "a1", "a2"              /* clobbered regs */	
+	  AND_MEMORY
 	);								
 }
 
@@ -184,10 +198,11 @@
 {									
 	__asm__ volatile						
 	(
-		".word	0xA00E"
+		ASM_LINEA(0xe)
 	: 						  /* outputs */	
 	: 						  /* inputs  */	
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	
+	  AND_MEMORY
 	);								
 }
 
@@ -195,9 +210,10 @@
 {									
 	__asm__ volatile						
 	(
-		".word	0xA00F"
+		ASM_LINEA(0xf)
 	: 						  /* outputs */	
 	: 						  /* inputs  */	
 	: "d0", "d1", "d2", "a0", "a1", "a2"       /* clobbered regs */	
+	  AND_MEMORY
 	);								
 }