shithub: loong

Download patch

ref: 8287e0cd29d9afdb41efa029705644f8427cf53a
parent: 1900acf7ad612d4f40701ad9b32434579c269304
author: kws <kws@cirno>
date: Fri Dec 29 22:27:09 EST 2023

more libraries

diff: cannot open b/sys/src/libc/9syscall//null: file does not exist: 'b/sys/src/libc/9syscall//null' diff: cannot open b/sys/src/libc/loong//null: file does not exist: 'b/sys/src/libc/loong//null' diff: cannot open b/sys/src/libc//null: file does not exist: 'b/sys/src/libc//null' diff: cannot open b/sys/src/libmp/loong//null: file does not exist: 'b/sys/src/libmp/loong//null' diff: cannot open b/sys/src/libmp//null: file does not exist: 'b/sys/src/libmp//null' diff: cannot open b/sys/src/libsec/loong//null: file does not exist: 'b/sys/src/libsec/loong//null' diff: cannot open b/sys/src/libsec//null: file does not exist: 'b/sys/src/libsec//null' diff: cannot open b/sys/src/libthread//null: file does not exist: 'b/sys/src/libthread//null'
--- a/bind.rc
+++ b/bind.rc
@@ -4,6 +4,11 @@
 bind -b sys/include /sys/include
 bind -bc sys/src/libmach /sys/src/libmach
 bind -bc sys/src/boot/efi /sys/src/boot/efi
+bind -a sys/src/libc /sys/src/libc
+bind -a sys/src/libsec /sys/src/libsec
+bind -a sys/src/libmp /sys/src/libmp
+bind -ac sys/src/libthread /sys/src/libthread
+bind -bc sys/src/libc/9syscall /sys/src/libc/9syscall
 bind -ac sys/src/cmd /sys/src/cmd
 bind -c sys/src/cmd/aux/aout2efi.c /sys/src/cmd/aux/aout2efi.c
 bind -c sys/lib/rootstub /sys/lib/rootstub
--- a/sys/src/cmd/zc/list.c
+++ b/sys/src/cmd/zc/list.c
@@ -115,6 +115,12 @@
 			sprint(str, "%N(R%d)(REG)", a, a->reg);
 		break;
 
+	case D_FREG:
+		sprint(str, "F%d", a->reg);
+		if(a->name != D_NONE || a->sym != S)
+			sprint(str, "%N(R%d)(REG)", a, a->reg);
+		break;
+
 	case D_FCCREG:
 		sprint(str, "FCC%d", a->reg);
 		if(a->name != D_NONE || a->sym != S)
--- a/sys/src/cmd/zc/reg.c
+++ b/sys/src/cmd/zc/reg.c
@@ -577,7 +577,7 @@
 		v++;
 	}
 	if(s)
-		if(s->name[0] == '.')
+		if(s->name[0] == '.' && strcmp(s->name, ".ret") != 0)
 			goto none;
 	if(nvar >= NVAR) {
 		if(debug['w'] > 1 && s)
--- a/sys/src/cmd/zc/txt.c
+++ b/sys/src/cmd/zc/txt.c
@@ -559,7 +559,6 @@
 {
 	int ft, tt, a;
 	Node nod;
-	Prog *p1;
 
 	ft = f->type->etype;
 	tt = t->type->etype;
@@ -748,40 +747,12 @@
 	case TULONG:
 		switch(tt) {
 		case TDOUBLE:
-			diag(Z, "TODO long -> double");
-#ifdef TODO
-			gins(AMOVW, f, t);
-			gins(AMOVWD, t, t);
-			if(ft == TULONG || ft == TUINT) {
-				regalloc(&nod, t, Z);
-				gins(ACMPGED, t, Z);
-				p->reg = FREGZERO;
-				gins(ABFPT, Z, Z);
-				p1 = p;
-				gins(AMOVD, nodfconst(4294967296.), &nod);
-				gins(AADDD, &nod, t);
-				patch(p1, pc);
-				regfree(&nod);
-			}
-#endif
+			gins(AMOVV, f, t);
+			gins(AMOVVD, t, t);
 			return;
 		case TFLOAT:
-			diag(Z, "TODO long -> float");
-#ifdef TODO
 			gins(AMOVW, f, t);
-			gins(AMOVWF, t, t);
-			if(ft == TULONG || ft == TUINT) {
-				regalloc(&nod, t, Z);
-				gins(ACMPGEF, t, Z);
-				p->reg = FREGZERO;
-				gins(ABFPT, Z, Z);
-				p1 = p;
-				gins(AMOVF, nodfconst(4294967296.), &nod);
-				gins(AADDF, &nod, t);
-				patch(p1, pc);
-				regfree(&nod);
-			}
-#endif
+			gins(AMOVVF, t, t);
 			return;
 		case TUVLONG:
 		case TVLONG:
--- a/sys/src/cmd/zl/asm.c
+++ b/sys/src/cmd/zl/asm.c
@@ -994,18 +994,6 @@
 		o3 = OP_12IRR(opirr(p->as+ALAST), v, REGTMP, p->to.reg);
 		break;
 
-#ifdef TODO
-	case 37:	/* movw r,mr */
-		a = OP_TEN();	/* movgr2cf */
-		o1 = OP_RR(a, p->from.reg, p->to.reg);
-		break;
-
-	case 38:	/* movw mr,r */
-		a = OP_TEN();	/* movcf2gr */
-		o1 = OP_RR(a, p->to.reg, p->from.reg);
-		break;
-#endif
-
 	case 40:	/* word */
 		if(aflag)
 			return 0;
@@ -1012,29 +1000,15 @@
 		o1 = regoff(&p->to);
 		break;
 
-#ifdef TODO
-	case 41:	/* movw r,fcr */
-		a = OP_TEN(); /* movgr2fcsr */
-		o1 = OP_RR(a, p->from.reg, p->to.reg);
-		break;
-
-	case 42:	/* movw fcr,r */
-		a = OP_TEN();	/* movfcsr2gr */
-		o1 = OP_RR(a, p->to.reg, p->from.reg);
-		break;
-#endif
-
-#ifdef TODO
 	case 47:	/* movv r,fr */
-		r = SP(2,1)|(5<<21);		/* dmtc1 */
-		o1 = OP_RRR(r, p->from.reg, 0, p->to.reg);
+		r = OP_TEN(8, 1322);		/* movgr2fr.d */
+		o1 = OP_RR(r, p->from.reg, p->to.reg);
 		break;
 
 	case 48:	/* movv fr,r */
-		r = SP(2,1)|(1<<21);		/* dmfc1 */
-		o1 = OP_RRR(r, p->to.reg, 0, p->from.reg);
+		r = OP_TEN(8, 1326);		/* movfr2gr.d */
+		o1 = OP_RR(r, p->from.reg, p->to.reg);
 		break;
-#endif
 	}
 	if(aflag)
 		return o1;
--- a/sys/src/cmd/zl/obj.c
+++ b/sys/src/cmd/zl/obj.c
@@ -477,24 +477,25 @@
 void
 addlib(char *obj)
 {
-	char fn1[LIBNAMELEN], comp[LIBNAMELEN], *p, *name;
-	int i, search;
+	char name[1024], comp[256], *p;
+	int i;
 
 	if(histfrogp <= 0)
 		return;
 
-	name = fn1;
-	search = 0;
 	if(histfrog[0]->name[1] == '/') {
-		sprint(name, "");
+		name[0] = 0;
 		i = 1;
-	} else if(histfrog[0]->name[1] == '.') {
-		sprint(name, ".");
+	} else
+	if(histfrog[0]->name[1] == '.') {
+		snprint(name, sizeof name, ".");
 		i = 0;
 	} else {
-		sprint(name, "");
+		if(debug['9'])
+			snprint(name, sizeof name, "/%s/lib", thestring);
+		else
+			snprint(name, sizeof name, "/usr/%clib", thechar);
 		i = 0;
-		search = 1;
 	}
 
 	for(; i<histfrogp; i++) {
@@ -517,13 +518,12 @@
 			memmove(p+strlen(thestring), p+2, strlen(p+2)+1);
 			memmove(p, thestring, strlen(thestring));
 		}
-		if(strlen(fn1) + strlen(comp) + 3 >= sizeof(fn1)) {
+		if(strlen(name) + strlen(comp) + 3 >= sizeof(name)) {
 			diag("library component too long");
 			return;
 		}
-		if(i > 0 || !search)
-			strcat(fn1, "/");
-		strcat(fn1, comp);
+		strcat(name, "/");
+		strcat(name, comp);
 	}
 	for(i=0; i<libraryp; i++)
 		if(strcmp(name, library[i]) == 0)
--- /dev/null
+++ b/sys/src/libc/9syscall/mkfile
@@ -1,0 +1,160 @@
+NPROC=1
+</$objtype/mkfile
+
+install:V:
+	SYS=`{sed '/^#define._X[123]/d; s/#define.([A-Z0-9_]*).*/\1/' sys.h}
+	for(I in $SYS) {
+		i=`{echo $I|tr A-Z a-z}
+		n=`{sed -n '/[ 	]'$I'[ 	]/s/.*	//p' sys.h}
+		if(~ $i (exits nsec)) i=_$i
+		{switch($objtype){
+		case 68000 68020
+			echo TEXT $i'(SB)', 1, '$0'
+			echo MOVL '$'$n, R0
+			echo TRAP '$0'
+			echo RTS
+		case mips
+			echo TEXT $i'(SB)', 1, '$0'
+			echo MOVW R1, '0(FP)'
+			echo MOVW '$'$n, R1
+			echo SYSCALL
+			if(~ $i (seek _nsec)) {
+				echo 'MOVW $-1,R5
+				BNE R1,R5,4(PC)
+				MOVW a+0(FP),R5
+				MOVW R1,0(R5)
+				MOVW R1,4(R5)'
+			}
+			echo RET
+		case mips2
+			echo TEXT $i'(SB)', 1, '$0'
+			echo MOVW R1, '0(FP)'
+			echo MOVW '$'$n, R1
+			echo ADD '$4',R29
+			echo SYSCALL
+			echo ADD '$-4',R29
+			echo RET
+		case spim
+			echo TEXT $i'(SB)', 1, '$0'
+			echo MOVW R1, '0(FP)'
+			echo MOVW '$'$n, R1
+			echo ADD '$4',R29
+			echo SYSCALL
+			echo ADD '$-4',R29
+			if(~ $i (seek _nsec)) {		# untested so far - geoff
+				echo 'MOVW $-1,R5
+				BNE R1,R5,4(PC)
+				MOVW a+0(FP),R5
+				MOVW R1,0(R5)
+				MOVW R1,4(R5)'
+			}
+			echo RET
+		case 386
+			echo TEXT $i'(SB)', 1, '$0'
+			echo MOVL '$'$n, AX
+			echo INT '$'64
+			if(~ $i (seek _nsec)) {
+				echo 'CMPL AX,$-1
+				JNE 4(PC)
+				MOVL a+0(FP),CX
+				MOVL AX,0(CX)
+				MOVL AX,4(CX)'
+			}
+			echo RET
+		case amd64
+			j=$i
+			if(~ $i seek) j=_seek
+			echo TEXT $j'(SB)', 1, '$0'
+			echo MOVQ RARG, 'a0+0(FP)'
+			echo MOVQ '$'$n, RARG
+			echo SYSCALL
+			echo RET
+		case sparc sparc64
+			echo TEXT $i'(SB)', 1, '$0'
+			echo MOVW R7, '0(FP)'
+			echo MOVW '$'$n, R7
+			echo TA R0
+			if(~ $i (seek _nsec)) {
+				echo 'CMP R7,$-1
+				BNE 4(PC)
+				MOVW a+0(FP),R8
+				MOVW R7,0(R8)
+				MOVW R7,4(R8)'
+			}
+			echo RETURN
+		case 3210
+			echo TEXT $i'(SB)', 1, '$0'
+			echo MOVW R3, '0(FP)'
+			echo MOVW '$'$n, R3
+			echo WORD '$0x06000000'
+			echo RETURN
+		case 29000
+			echo TEXT $i'(SB)', 1, '$0'
+			echo MOVL R69, '0(FP)'
+			echo MOVL '$'$n, R69
+			echo EMULATE 0
+			echo RET
+		case arm
+			echo TEXT $i'(SB)', 1, '$0'
+			echo MOVW R0, '0(FP)'
+			echo MOVW '$'$n, R0
+			echo SWI 0
+			if(~ $i (seek _nsec)) {
+				echo 'CMP $-1,R0
+				BNE 4(PC)
+				MOVW a+0(FP),R1
+				MOVW R0,0(R1)
+				MOVW R0,4(R1)'
+			}
+			echo RET
+		case arm64
+			j=$i
+			if(~ $i seek) j=_seek
+			echo TEXT $j'(SB)', 1, '$0'
+			echo MOV R0, '0(FP)'
+			echo MOV '$'$n, R0
+			echo SVC
+			echo RETURN
+		case loong
+			j=$i
+			if(~ $i seek) j=_seek
+			echo TEXT $j'(SB)', 1, '$0'
+			echo MOVV R4, '0(FP)'
+			echo MOVV '$'$n, R4
+			echo SYSCALL
+			echo RET
+		case power
+			echo TEXT $i'(SB)', 1, '$0'
+			echo MOVW R3, '0(FP)'
+			echo MOVW '$'$n, R3
+			echo SYSCALL
+			if(~ $i (seek _nsec)) {
+				echo 'CMP R3,$-1
+				BNE 4(PC)
+				MOVW a+0(FP),R8
+				MOVW R3,0(R8)
+				MOVW R3,4(R8)'
+			}
+			echo RETURN
+		case alpha
+			j=$i
+			if(~ $i seek) j=_seek
+			echo TEXT $j'(SB)', 1, '$0'
+			echo MOVL R0, '0(FP)'
+			echo MOVQ '$'$n, R0
+			echo CALL_PAL '$'0x83
+			echo RET
+		}} > $i.s
+		$AS $i.s
+	}
+	ar vu /$objtype/lib/libc.a *.$O
+	rm -f *.$O *.s
+
+nuke clean:V:
+	rm -f *.[$OS]
+
+installall:V:
+	for(objtype in $CPUS) mk install
+
+update:V:
+	update $UPDATEFLAGS mkfile sys.h
--- /dev/null
+++ b/sys/src/libc/loong/_seek.c
@@ -1,0 +1,14 @@
+#include <u.h>
+#include <libc.h>
+
+extern int _seek(vlong*, int, vlong, int);
+
+vlong
+seek(int fd, vlong o, int p)
+{
+	vlong l;
+
+	if(_seek(&l, fd, o, p) < 0)
+		l = -1LL;
+	return l;
+}
--- /dev/null
+++ b/sys/src/libc/loong/argv0.s
@@ -1,0 +1,4 @@
+GLOBL	argv0(SB), $8
+GLOBL	_tos(SB), $8
+GLOBL	_privates(SB), $8
+GLOBL	_nprivates(SB), $4
--- /dev/null
+++ b/sys/src/libc/loong/getcallerpc.s
@@ -1,0 +1,3 @@
+TEXT getcallerpc(SB), $0
+	MOVV	0(SP), R4
+	RET
--- /dev/null
+++ b/sys/src/libc/loong/mkfile
@@ -1,0 +1,29 @@
+objtype=loong
+</$objtype/mkfile
+OS=z
+
+LIB=/$objtype/lib/libc.a
+SFILES=\
+	argv0.s\
+#	atom.s\
+	getcallerpc.s\
+#	getfcr.s\
+#	main9.s\
+#	main9p.s\
+#	setjmp.s\
+#	tas.s\
+
+CFILES=\
+	notejmp.c\
+	_seek.c\
+
+HFILES=/sys/include/libc.h
+
+OFILES=${CFILES:%.c=%.$O} ${SFILES:%.s=%.$O}
+
+UPDATE=mkfile\
+	$HFILES\
+	$CFILES\
+	$SFILES\
+
+</sys/src/cmd/mksyslib
--- /dev/null
+++ b/sys/src/libc/loong/notejmp.c
@@ -1,0 +1,16 @@
+#include <u.h>
+#include <libc.h>
+#include <ureg.h>
+
+void
+notejmp(void *vr, jmp_buf j, int ret)
+{
+	struct Ureg *r = vr;
+
+	r->r4 = ret;
+	if(ret == 0)
+		r->r4 = 1;
+	r->pc = j[JMPBUFPC];
+	r->sp = j[JMPBUFSP];
+	noted(NCONT);
+}
--- /dev/null
+++ b/sys/src/libmp/loong/mkfile
@@ -1,0 +1,7 @@
+objtype=loong
+</$objtype/mkfile
+
+install clean all update:V:
+	
+
+
--- /dev/null
+++ b/sys/src/libsec/loong/mkfile
@@ -1,0 +1,2 @@
+install clean all:V:
+	exit
--- /dev/null
+++ b/sys/src/libthread/loong.c
@@ -1,0 +1,28 @@
+#include <u.h>
+#include <libc.h>
+#include <thread.h>
+#include "threadimpl.h"
+
+/* first argument goes in a register; simplest just to ignore it */
+static void
+launcherloong(int, void (*f)(void *arg), void *arg)
+{
+	(*f)(arg);
+	threadexits(nil);
+}
+
+void
+_threadinitstack(Thread *t, void (*f)(void*), void *arg)
+{
+	uintptr *tos;
+
+	tos = (uintptr*)&t->stk[t->stksize&~15];
+	*--tos = (uintptr)arg;
+	*--tos = (uintptr)f;
+	*--tos = 0;	/* first arg to launcherloong */
+	*--tos = 0;	/* place to store return PC */
+
+	t->sched[JMPBUFPC] = (uintptr)launcherloong+JMPBUFDPC;
+	t->sched[JMPBUFSP] = (uintptr)tos;
+}
+