Browse Source

Plan 9 from Bell Labs 2012-07-11

David du Colombier 11 years ago
parent
commit
8005a0667c

+ 1 - 1
sys/man/2/fmtinstall

@@ -266,7 +266,7 @@ and
 .IR fmtvprint
 may be called to
 help prepare output in custom conversion routines.
-However, these functions clear the width, precision, and flags.
+These functions will preserve width, precision, and flags.
 Both functions return 0 for success and \-1 for failure.
 .PP
 The functions

+ 0 - 0
sys/src/9/bitsy/arm.h


+ 0 - 3
sys/src/9/teg2/arm.s

@@ -67,9 +67,6 @@ label: \
 #define CPSMODE(m) WORD $(0xf1020000 | (m)) /* switch to mode m (PsrM*) */
 
 #define	CLREX	WORD	$0xf57ff01f
-#define	LDREX(fp,t)   WORD $(0xe<<28|0x01900f9f | (fp)<<16 | (t)<<12)
-/* `The order of operands is from left to right in dataflow order' - asm man */
-#define	STREX(f,tp,r) WORD $(0xe<<28|0x01800f90 | (tp)<<16 | (r)<<12 | (f)<<0)
 
 /* floating point */
 #define VMRS(fp, cpu) WORD $(0xeef00a10 | (fp)<<16 | (cpu)<<12) /* FP → arm */

+ 0 - 57
sys/src/9/teg2/atom.s

@@ -1,57 +0,0 @@
-#include "arm.s"
-
-/*
- * int cas(ulong *p, ulong ov, ulong nv);
- */
-
-TEXT	cas+0(SB),0,$0		/* r0 holds p */
-TEXT	casp+0(SB),0,$0		/* r0 holds p */
-	MOVW	ov+4(FP), R1
-	MOVW	nv+8(FP), R2
-	BARRIERS
-spincas:
-	LDREX(0,3)	/*	LDREX	0(R0),R3	*/
-	CMP.S	R3, R1
-	BNE	fail
-	STREX(2,0,4)	/*	STREX	0(R0),R2,R4	*/
-	CMP.S	$0, R4
-	BNE	spincas
-	BARRIERS
-	MOVW	$1, R0
-	RET
-fail:
-	CLREX
-	MOVW	$0, R0
-	RET
-
-TEXT _xinc(SB), $0	/* void	_xinc(long *); */
-TEXT ainc(SB), $0	/* long ainc(long *); */
-spinainc:
-	LDREX(0,3)	/*	LDREX	0(R0),R3	*/
-	ADD	$1,R3
-	STREX(3,0,4)	/*	STREX	0(R0),R3,R4	*/
-	CMP.S	$0, R4
-	BNE	spinainc
-	MOVW	R3, R0
-	RET
-
-TEXT _xdec(SB), $0	/* long _xdec(long *); */
-TEXT adec(SB), $0	/* long adec(long *); */
-spinadec:
-	LDREX(0,3)	/*	LDREX	0(R0),R3	*/
-	SUB	$1,R3
-	STREX(3,0,4)	/*	STREX	0(R0),R3,R4	*/
-	CMP.S	$0, R4
-	BNE	spinadec
-	MOVW	R3, R0
-	RET
-
-TEXT loadlinked(SB), $0	/* long loadlinked(long *); */
-	LDREX(0,0)	/*	LDREX	0(R0),R0	*/
-	RET
-
-TEXT storecond(SB), $0	/* int storecond(long *, long); */
-	MOVW	ov+4(FP), R3
-	STREX(3,0,0)	/*	STREX	0(R0),R3,R0	*/
-	RSB	$1, R0
-	RET

+ 2 - 2
sys/src/9/teg2/fpiarm.c

@@ -15,12 +15,12 @@
 #include	"arm.h"
 #include	"fpi.h"
 
+#define ARM7500			/* emulate old pre-VFP opcodes */
+
 /* undef this if correct kernel r13 isn't in Ureg;
  * check calculation in fpiarm below
  */
 
-#define ARM7500
-
 #define	REG(ur, x) (*(long*)(((char*)(ur))+roff[(x)]))
 #ifdef ARM7500
 #define	FR(ufp, x) (*(Internal*)(ufp)->regs[(x)&7])

+ 4 - 0
sys/src/9/teg2/l.s

@@ -11,6 +11,10 @@
 
 #include "arm.s"
 
+#define	LDREX(fp,t)   WORD $(0xe<<28|0x01900f9f | (fp)<<16 | (t)<<12)
+/* `The order of operands is from left to right in dataflow order' - asm man */
+#define	STREX(f,tp,r) WORD $(0xe<<28|0x01800f90 | (tp)<<16 | (r)<<12 | (f)<<0)
+
 #define MAXMB	(KiB-1)			/* last MB has vectors */
 #define TMPSTACK (DRAMSIZE - 64*MiB)	/* used only during cpu startup */
 /* tas/cas strex debugging limits; started at 10000 */

+ 0 - 1
sys/src/9/teg2/mkfile

@@ -47,7 +47,6 @@ OBJ=\
 	lexception.$O\
 	lproc.$O\
 	arch.$O\
-	atom.$O\
 	clock.$O\
 	clock-tegra.$O\
 	kbd.$O\

+ 22 - 6
sys/src/ape/lib/fmt/fmt.c

@@ -143,7 +143,13 @@ void*
 __fmtdispatch(Fmt *f, void *fmt, int isrunes)
 {
 	Rune rune, r;
-	int i, n;
+	int i, n, w, p;
+	ulong fl;
+	void *ret;
+
+	w = f->width;
+	p = f->prec;
+	fl = f->flags;
 
 	f->flags = 0;
 	f->width = f->prec = 0;
@@ -159,7 +165,8 @@ __fmtdispatch(Fmt *f, void *fmt, int isrunes)
 		f->r = r;
 		switch(r){
 		case '\0':
-			return nil;
+			ret = nil;
+			goto end;
 		case '.':
 			f->flags |= FmtWidth|FmtPrec;
 			continue;
@@ -213,9 +220,18 @@ __fmtdispatch(Fmt *f, void *fmt, int isrunes)
 			goto numflag;
 		}
 		n = (*fmtfmt(r))(f);
-		if(n < 0)
-			return nil;
-		if(n == 0)
-			return fmt;
+		if(n < 0){
+			ret = nil;
+			break;
+		}
+		if(n == 0){
+			ret = fmt;
+			break;
+		}
 	}
+end:
+	f->width = w;
+	f->prec = p;
+	f->flags = fl;
+	return ret;
 }

+ 2 - 13
sys/src/ape/lib/fmt/fmtprint.c

@@ -20,8 +20,7 @@
 
 /*
  * format a string into the output buffer
- * designed for formats which themselves call fmt,
- * but ignore any width flags
+ * designed for formats which themselves call fmt
  */
 int
 fmtprint(Fmt *f, char *fmt, ...)
@@ -29,19 +28,9 @@ fmtprint(Fmt *f, char *fmt, ...)
 	va_list va;
 	int n;
 
-	f->flags = 0;
-	f->width = 0;
-	f->prec = 0;
-	va = f->args;
 	va_start(f->args, fmt);
-	n = dofmt(f, fmt);
+	n = fmtvprint(f, fmt, va);
 	va_end(f->args);
-	f->flags = 0;
-	f->width = 0;
-	f->prec = 0;
-	f->args = va;
-	if(n >= 0)
-		return 0;
 	return n;
 }
 

+ 1 - 8
sys/src/ape/lib/fmt/fmtvprint.c

@@ -20,8 +20,7 @@
 
 /*
  * format a string into the output buffer
- * designed for formats which themselves call fmt,
- * but ignore any width flags
+ * designed for formats which themselves call fmt
  */
 int
 fmtvprint(Fmt *f, char *fmt, va_list args)
@@ -29,15 +28,9 @@ fmtvprint(Fmt *f, char *fmt, va_list args)
 	va_list va;
 	int n;
 
-	f->flags = 0;
-	f->width = 0;
-	f->prec = 0;
 	va = f->args;
 	f->args = args;
 	n = dofmt(f, fmt);
-	f->flags = 0;
-	f->width = 0;
-	f->prec = 0;
 	f->args = va;
 	if(n >= 0)
 		return 0;

+ 5 - 5
sys/src/libc/arm/atom.s

@@ -1,12 +1,12 @@
-/*
- * int cas(ulong *p, ulong ov, ulong nv);
- */
-
 #define	CLREX		WORD	$0xf57ff01f
 #define	LDREX(a,r)	WORD	$(0xe<<28|0x01900f9f | (a)<<16 | (r)<<12)
 /* `The order of operands is from left to right in dataflow order' - asm man */
 #define	STREX(v,a,r)	WORD	$(0xe<<28|0x01800f90 | (a)<<16 | (r)<<12 | (v)<<0)
 
+/*
+ * int cas(ulong *p, ulong ov, ulong nv);
+ */
+
 TEXT	cas+0(SB),0,$0		/* r0 holds p */
 TEXT	casp+0(SB),0,$0		/* r0 holds p */
 	MOVW	ov+4(FP), R1
@@ -21,7 +21,7 @@ spincas:
 	MOVW	$1, R0
 	RET
 fail:
-//	CLREX		/* fpiarm in pre-v7 ports needs to emulate this */
+	CLREX
 	MOVW	$0, R0
 	RET
 

+ 22 - 6
sys/src/libc/fmt/fmt.c

@@ -124,7 +124,13 @@ void*
 _fmtdispatch(Fmt *f, void *fmt, int isrunes)
 {
 	Rune rune, r;
-	int i, n;
+	int i, n, w, p;
+	ulong fl;
+	void *ret;
+
+	w = f->width;
+	p = f->prec;
+	fl = f->flags;
 
 	f->flags = 0;
 	f->width = f->prec = 0;
@@ -140,7 +146,8 @@ _fmtdispatch(Fmt *f, void *fmt, int isrunes)
 		f->r = r;
 		switch(r){
 		case '\0':
-			return nil;
+			ret = nil;
+			goto end;
 		case '.':
 			f->flags |= FmtWidth|FmtPrec;
 			continue;
@@ -194,9 +201,18 @@ _fmtdispatch(Fmt *f, void *fmt, int isrunes)
 			goto numflag;
 		}
 		n = (*fmtfmt(r))(f);
-		if(n < 0)
-			return nil;
-		if(n == 0)
-			return fmt;
+		if(n < 0){
+			ret = nil;
+			break;
+		}
+		if(n == 0){
+			ret = fmt;
+			break;
+		}
 	}
+end:
+	f->width = w;
+	f->prec = p;
+	f->flags = fl;
+	return ret;
 }

+ 4 - 15
sys/src/libc/fmt/fmtprint.c

@@ -5,8 +5,7 @@
 
 /*
  * format a string into the output buffer
- * designed for formats which themselves call fmt,
- * but ignore any width flags
+ * designed for formats which themselves call fmt
  */
 int
 fmtprint(Fmt *f, char *fmt, ...)
@@ -14,19 +13,9 @@ fmtprint(Fmt *f, char *fmt, ...)
 	va_list va;
 	int n;
 
-	f->flags = 0;
-	f->width = 0;
-	f->prec = 0;
-	va = f->args;
-	va_start(f->args, fmt);
-	n = dofmt(f, fmt);
-	va_end(f->args);
-	f->flags = 0;
-	f->width = 0;
-	f->prec = 0;
-	f->args = va;
-	if(n >= 0)
-		return 0;
+	va_start(va, fmt);
+	n = fmtvprint(f, fmt, va);
+	va_end(va);
 	return n;
 }
 

+ 1 - 8
sys/src/libc/fmt/fmtvprint.c

@@ -5,8 +5,7 @@
 
 /*
  * format a string into the output buffer
- * designed for formats which themselves call fmt,
- * but ignore any width flags
+ * designed for formats which themselves call fmt
  */
 int
 fmtvprint(Fmt *f, char *fmt, va_list args)
@@ -14,15 +13,9 @@ fmtvprint(Fmt *f, char *fmt, va_list args)
 	va_list va;
 	int n;
 
-	f->flags = 0;
-	f->width = 0;
-	f->prec = 0;
 	va = f->args;
 	f->args = args;
 	n = dofmt(f, fmt);
-	f->flags = 0;
-	f->width = 0;
-	f->prec = 0;
 	f->args = va;
 	if(n >= 0)
 		return 0;