shithub: riscv

Download patch

ref: e4b5f170cffd0d5e788d9090f8f2a9802fe267e9
parent: 8a8329ad952b0fced970cc0b83e5e87d4a5ceb7a
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Jul 25 11:54:22 EDT 2021

libc: change usize to 64-bit for amd64 and arm64, make memory(2) functions use usize

--- a/amd64/include/u.h
+++ b/amd64/include/u.h
@@ -8,7 +8,7 @@
 typedef	unsigned long long uvlong;
 typedef long long	intptr;
 typedef unsigned long long uintptr;
-typedef unsigned long	usize;
+typedef unsigned long long usize;
 typedef	uint		Rune;
 typedef union FPdbleword FPdbleword;
 typedef uintptr		jmp_buf[2];
--- a/arm64/include/u.h
+++ b/arm64/include/u.h
@@ -9,7 +9,7 @@
 typedef	unsigned long long uvlong;
 typedef vlong	intptr;
 typedef uvlong	uintptr;
-typedef unsigned long	usize;
+typedef unsigned long long usize;
 typedef	uint		Rune;
 typedef union FPdbleword FPdbleword;
 typedef uintptr	jmp_buf[2];
--- a/sys/include/libc.h
+++ b/sys/include/libc.h
@@ -8,12 +8,12 @@
 /*
  * mem routines
  */
-extern	void*	memccpy(void*, void*, int, ulong);
-extern	void*	memset(void*, int, ulong);
-extern	int	memcmp(void*, void*, ulong);
-extern	void*	memcpy(void*, void*, ulong);
-extern	void*	memmove(void*, void*, ulong);
-extern	void*	memchr(void*, int, ulong);
+extern	void*	memccpy(void*, void*, int, usize);
+extern	void*	memset(void*, int, usize);
+extern	int	memcmp(void*, void*, usize);
+extern	void*	memcpy(void*, void*, usize);
+extern	void*	memmove(void*, void*, usize);
+extern	void*	memchr(void*, int, usize);
 
 /*
  * string routines
--- a/sys/man/2/memory
+++ b/sys/man/2/memory
@@ -8,22 +8,22 @@
 .PP
 .ta \w'\fLvoid* 'u
 .B
-void*	memccpy(void *s1, void *s2, int c, ulong n)
+void*	memccpy(void *s1, void *s2, int c, usize n)
 .PP
 .B
-void*	memchr(void *s, int c, ulong n)
+void*	memchr(void *s, int c, usize n)
 .PP
 .B
-int	memcmp(void *s1, void *s2, ulong n)
+int	memcmp(void *s1, void *s2, usize n)
 .PP
 .B
-void*	memcpy(void *s1, void *s2, ulong n)
+void*	memcpy(void *s1, void *s2, usize n)
 .PP
 .B
-void*	memmove(void *s1, void *s2, ulong n)
+void*	memmove(void *s1, void *s2, usize n)
 .PP
 .B
-void*	memset(void *s, int c, ulong n)
+void*	memset(void *s, int c, usize n)
 .PP
 .B #include <libsec.h>
 .PP
--- a/sys/src/9/port/lib.h
+++ b/sys/src/9/port/lib.h
@@ -8,11 +8,11 @@
 /*
  * mem routines
  */
-extern	void*	memccpy(void*, void*, int, ulong);
-extern	void*	memset(void*, int, ulong);
-extern	int	memcmp(void*, void*, ulong);
-extern	void*	memmove(void*, void*, ulong);
-extern	void*	memchr(void*, int, ulong);
+extern	void*	memccpy(void*, void*, int, usize);
+extern	void*	memset(void*, int, usize);
+extern	int	memcmp(void*, void*, usize);
+extern	void*	memmove(void*, void*, usize);
+extern	void*	memchr(void*, int, usize);
 
 /*
  * string routines
--- a/sys/src/cmd/aux/disksim.c
+++ b/sys/src/cmd/aux/disksim.c
@@ -349,13 +349,13 @@
 }
 
 void*
-evommem(void *a, void *b, ulong n)
+evommem(void *a, void *b, usize n)
 {
 	return memmove(b, a, n);
 }
 
 int
-isnonzero(void *v, ulong n)
+isnonzero(void *v, usize n)
 {
 	uchar *a, *ea;
 	
@@ -375,7 +375,7 @@
 	vlong offset;
 	long count, tot, n, o;
 	uchar *blk, *dat;
-	void *(*move)(void*, void*, ulong);
+	void *(*move)(void*, void*, usize);
 
 	q = r->fid->qid.path-Qpart;
 	if(q < 0 || q > nelem(tab) || !tab[q].inuse || tab[q].vers != r->fid->qid.vers){
--- a/sys/src/libc/amd64/memccpy.s
+++ b/sys/src/libc/amd64/memccpy.s
@@ -1,7 +1,7 @@
-	TEXT	memccpy(SB),$0
+TEXT	memccpy(SB),$0
 
-	MOVL	n+24(FP), CX
-	CMPL	CX, $0
+	MOVQ	n+24(FP), CX
+	CMPQ	CX, $0
 	JEQ	none
 	MOVQ	p2+8(FP), DI
 	MOVBLZX	c+16(FP), AX
@@ -18,7 +18,7 @@
  */
 none:
 	MOVL	$0, AX
-	MOVL	n+24(FP), BX
+	MOVQ	n+24(FP), BX
 	JMP	memcpy
 
 /*
@@ -44,7 +44,7 @@
 	ORQ	SI, DX
 	ANDL	$3, DX
 	JNE	c3
-	MOVL	BX, CX
+	MOVQ	BX, CX
 	SHRQ	$2, CX
 	REP;	MOVSL
 /*
@@ -52,7 +52,7 @@
  */
 	ANDL	$3, BX
 c3:
-	MOVL	BX, CX
+	MOVQ	BX, CX
 	REP;	MOVSB
 
 	RET
--- a/sys/src/libc/amd64/memchr.s
+++ b/sys/src/libc/amd64/memchr.s
@@ -1,7 +1,7 @@
-	TEXT	memchr(SB),$0
+TEXT	memchr(SB),$0
 
-	MOVL	n+16(FP), CX
-	CMPL	CX, $0
+	MOVQ	n+16(FP), CX
+	CMPQ	CX, $0
 	JEQ	none
 	MOVQ	RARG, DI
 	MOVBLZX	c+8(FP), AX
--- a/sys/src/libc/amd64/memcmp.s
+++ b/sys/src/libc/amd64/memcmp.s
@@ -1,7 +1,7 @@
-	TEXT	memcmp(SB),$0
+TEXT	memcmp(SB),$0
 
-	MOVL	n+16(FP), BX
-	CMPL	BX, $0
+	MOVQ	n+16(FP), BX
+	CMPQ	BX, $0
 	JEQ	none
 	MOVQ	RARG, DI
 	MOVQ	p2+8(FP), SI
@@ -14,7 +14,7 @@
  * first by longs
  */
 
-	MOVL	BX, CX
+	MOVQ	BX, CX
 	SHRQ	$2, CX
 
 	REP;	CMPSL
@@ -25,7 +25,7 @@
  */
 	ANDL	$3, BX
 c3:
-	MOVL	BX, CX
+	MOVQ	BX, CX
 	REP;	CMPSB
 	JNE	found1
 
--- a/sys/src/libc/amd64/memcpy.s
+++ b/sys/src/libc/amd64/memcpy.s
@@ -2,8 +2,8 @@
 	MOVQ	RARG, DI
 	MOVQ	DI, AX			/* return value */
 	MOVQ	p2+8(FP), SI
-	MOVL	n+16(FP), BX
-	CMPL	BX, $0
+	MOVQ	n+16(FP), BX
+	CMPQ	BX, $0
 	JGT	_ok
 	JEQ	_return			/* nothing to do if n == 0 */
 	MOVL	$0, SI			/* fault if n < 0 */
@@ -40,7 +40,7 @@
  */
 	JEQ	_return			/* flags set by above ANDL */
 c3f:
-	MOVL	BX, CX
+	MOVQ	BX, CX
 	REP;	MOVSB
 
 	RET
@@ -62,7 +62,7 @@
 	ORQ	SI, DX
 	ANDL	$3, DX
 	JNE	c3b
-	MOVL	BX, CX
+	MOVQ	BX, CX
 	SHRQ	$2, CX
 	ANDL	$3, BX
 	REP;	MOVSL
@@ -74,7 +74,7 @@
 c3b:
 	ADDQ	$3, DI
 	ADDQ	$3, SI
-	MOVL	BX, CX
+	MOVQ	BX, CX
 	REP;	MOVSB
 
 _return:
--- a/sys/src/libc/amd64/memmove.s
+++ b/sys/src/libc/amd64/memmove.s
@@ -2,8 +2,8 @@
 	MOVQ	RARG, DI
 	MOVQ	DI, AX			/* return value */
 	MOVQ	p2+8(FP), SI
-	MOVL	n+16(FP), BX
-	CMPL	BX, $0
+	MOVQ	n+16(FP), BX
+	CMPQ	BX, $0
 	JGT	_ok
 	JEQ	_return			/* nothing to do if n == 0 */
 	MOVL	$0, SI			/* fault if n < 0 */
@@ -40,7 +40,7 @@
  */
 	JEQ	_return			/* flags set by above ANDL */
 c3f:
-	MOVL	BX, CX
+	MOVQ	BX, CX
 	REP;	MOVSB
 
 	RET
@@ -62,7 +62,7 @@
 	ORQ	SI, DX
 	ANDL	$3, DX
 	JNE	c3b
-	MOVL	BX, CX
+	MOVQ	BX, CX
 	SHRQ	$2, CX
 	ANDL	$3, BX
 	REP;	MOVSL
@@ -74,7 +74,7 @@
 c3b:
 	ADDQ	$3, DI
 	ADDQ	$3, SI
-	MOVL	BX, CX
+	MOVQ	BX, CX
 	REP;	MOVSB
 
 _return:
--- a/sys/src/libc/amd64/memset.s
+++ b/sys/src/libc/amd64/memset.s
@@ -1,13 +1,13 @@
-	TEXT	memset(SB),$0
+TEXT	memset(SB),$0
 
 	CLD
 	MOVQ	RARG, DI
 	MOVBLZX	c+8(FP), AX
-	MOVL	n+16(FP), BX
+	MOVQ	n+16(FP), BX
 /*
  * if not enough bytes, just set bytes
  */
-	CMPL	BX, $9
+	CMPQ	BX, $9
 	JLS	c3
 /*
  * if not aligned, just set bytes
--- a/sys/src/libc/arm64/memmove.s
+++ b/sys/src/libc/arm64/memmove.s
@@ -1,7 +1,7 @@
 TEXT memcpy(SB), $-4
 TEXT memmove(SB), $-4
 	MOV	from+8(FP), R1
-	MOVWU	n+16(FP), R2
+	MOV	n+16(FP), R2
 
 	CMP	R0, R1
 	BEQ	_done
--- a/sys/src/libc/arm64/memset.s
+++ b/sys/src/libc/arm64/memset.s
@@ -1,6 +1,6 @@
 TEXT memset(SB), $-4
 	MOVBU	c+8(FP), R1
-	MOVWU	n+16(FP), R2
+	MOV	n+16(FP), R2
 
 	MOV	R0, R5
 	ADD	R0, R2, R3
--- a/sys/src/libc/port/memccpy.c
+++ b/sys/src/libc/port/memccpy.c
@@ -2,7 +2,7 @@
 #include	<libc.h>
 
 void*
-memccpy(void *a1, void *a2, int c, ulong n)
+memccpy(void *a1, void *a2, int c, usize n)
 {
 	uchar *s1, *s2;
 
--- a/sys/src/libc/port/memchr.c
+++ b/sys/src/libc/port/memchr.c
@@ -2,7 +2,7 @@
 #include	<libc.h>
 
 void*
-memchr(void *ap, int c, ulong n)
+memchr(void *ap, int c, usize n)
 {
 	uchar *sp;
 
--- a/sys/src/libc/port/memcmp.c
+++ b/sys/src/libc/port/memcmp.c
@@ -2,7 +2,7 @@
 #include	<libc.h>
 
 int
-memcmp(void *a1, void *a2, ulong n)
+memcmp(void *a1, void *a2, usize n)
 {
 	uchar *s1, *s2;
 	uint c1, c2;
--- a/sys/src/libc/port/memmove.c
+++ b/sys/src/libc/port/memmove.c
@@ -2,12 +2,10 @@
 #include	<libc.h>
 
 void*
-memmove(void *a1, void *a2, ulong n)
+memmove(void *a1, void *a2, usize n)
 {
 	char *s1, *s2;
 
-	if((long)n < 0)
-		abort();
 	s1 = a1;
 	s2 = a2;
 	if((s2 < s1) && (s2+n > s1))
@@ -29,7 +27,7 @@
 }
 
 void*
-memcpy(void *a1, void *a2, ulong n)
+memcpy(void *a1, void *a2, usize n)
 {
 	return memmove(a1, a2, n);
 }
--- a/sys/src/libc/port/memset.c
+++ b/sys/src/libc/port/memset.c
@@ -2,7 +2,7 @@
 #include	<libc.h>
 
 void*
-memset(void *ap, int c, ulong n)
+memset(void *ap, int c, usize n)
 {
 	char *p;