shithub: riscv

Download patch

ref: 2c2cf405d21514116fc928df8583280f3b03b6bf
parent: 6c5e9f73197f0e6bfc59119541312a1d281133b2
author: Jacob Moody <moody@posixcafe.org>
date: Thu May 16 19:28:21 EDT 2024

ja, jl: get them compiling here

--- a/sys/include/a.out.h
+++ b/sys/include/a.out.h
@@ -28,12 +28,14 @@
 #define	L_MAGIC		_MAGIC(0, 23)		/* dec alpha (retired) */
 #define	P_MAGIC		_MAGIC(0, 24)		/* mips 3000 LE */
 #define	U_MAGIC		_MAGIC(0, 25)		/* sparc64 */
+#define	Y_MAGIC		_MAGIC(0, 29)		/* riscv */
 #define	S_MAGIC		_MAGIC(HDR_MAGIC, 26)	/* amd64 */
 #define	T_MAGIC		_MAGIC(HDR_MAGIC, 27)	/* powerpc64 */
 #define	R_MAGIC		_MAGIC(HDR_MAGIC, 28)	/* arm64 */
+#define	B_MAGIC		_MAGIC(HDR_MAGIC, 30)	/* riscv64 */
 
 #define	MIN_MAGIC	8
-#define	MAX_MAGIC	28			/* <= 90 */
+#define	MAX_MAGIC	30			/* <= 90 */
 
 #define	DYN_MAGIC	0x80000000		/* dlm */
 
--- a/sys/src/cmd/ja/a.h
+++ b/sys/src/cmd/ja/a.h
@@ -2,6 +2,7 @@
 #include <libc.h>
 #include <bio.h>
 #include "../jc/j.out.h"
+#include "../cc/compat.h"
 
 #ifndef	EXTERN
 #define	EXTERN	extern
@@ -95,7 +96,6 @@
 EXTERN	Hist*	ehist;
 EXTERN	int	newflag;
 EXTERN	Hist*	hist;
-EXTERN	char*	hunk;
 EXTERN	char*	include[NINCLUDE];
 EXTERN	Io*	iofree;
 EXTERN	Io*	ionext;
@@ -102,7 +102,6 @@
 EXTERN	Io*	iostack;
 EXTERN	long	lineno;
 EXTERN	int	nerrors;
-EXTERN	long	nhunk;
 EXTERN	int	ninclude;
 EXTERN	int	nosched;
 EXTERN	Gen	nullgen;
@@ -115,7 +114,6 @@
 EXTERN	char	symb[NSYMB];
 EXTERN	int	thechar;
 EXTERN	char*	thestring;
-EXTERN	long	thunk;
 EXTERN	Biobuf	obuf;
 
 void*	alloc(long);
@@ -144,7 +142,7 @@
 void	domacro(void);
 void	macund(void);
 void	macdef(void);
-void	macexpand(Sym*, char*);
+int	macexpand(Sym*, char*, int);
 void	macinc(void);
 void	macprag(void);
 void	maclin(void);
@@ -154,29 +152,7 @@
 void	prfile(long);
 void	outhist(void);
 void	linehist(char*, int);
-void	gethunk(void);
 void	yyerror(char*, ...);
 int	yyparse(void);
 void	setinclude(char*);
 int	assemble(char*);
-
-/*
- *	system-dependent stuff from ../cc/compat.c
- */
-
-enum				/* keep in synch with ../cc/cc.h */
-{
-	Plan9	= 1<<0,
-	Unix	= 1<<1,
-	Windows	= 1<<2
-};
-int	mywait(int*);
-int	mycreat(char*, int);
-int	systemtype(int);
-int	pathchar(void);
-char*	mygetwd(char*, int);
-int	myexec(char*, char*[]);
-int	mydup(int, int);
-int	myfork(void);
-int	mypipe(int*);
-void*	mysbrk(ulong);
--- a/sys/src/cmd/ja/lex.c
+++ b/sys/src/cmd/ja/lex.c
@@ -389,7 +389,6 @@
 	iostack = I;
 	iofree = I;
 	peekc = IGN;
-	nhunk = 0;
 	for(i=0; i<NHASH; i++)
 		hash[i] = S;
 	for(i=0; itab[i].name; i++) {
--- a/sys/src/cmd/jl/asm.c
+++ b/sys/src/cmd/jl/asm.c
@@ -135,7 +135,7 @@
 	case 1:
 		break;
 	case 2:
-		t = thechar == 'j'? (debug['X']? B_MAGIC: Y_MAGIC): Z_MAGIC;
+		t = thechar == 'j'? B_MAGIC: Y_MAGIC;
 		lput(t);
 		lput(textsize);			/* sizes */
 		lput(datsize);
@@ -147,11 +147,6 @@
 		if (t & HDR_MAGIC)
 			llput(entryvalue());	/* va of entry */
 		break;
-	case 5:
-		if(thechar == 'j')
-			elf64(243, ELFDATA2LSB, 0, nil); /* 243 is RISCV */
-		else
-			elf32(243, ELFDATA2LSB, 0, nil);
 	}
 	cflush();
 }
--- a/sys/src/cmd/jl/compat.c
+++ b/sys/src/cmd/jl/compat.c
@@ -1,67 +1,2 @@
 #include	"l.h"
-
-/*
- * fake malloc
- */
-void*
-malloc(uintptr n)
-{
-	void *p;
-
-	while(n & 7)
-		n++;
-	while(nhunk < n)
-		gethunk();
-	p = hunk;
-	nhunk -= n;
-	hunk += n;
-	return p;
-}
-
-void*
-mallocz(uintptr n, int clr)
-{
-	void *p;
-
-	while(n & 7)
-		n++;
-	while(nhunk < n)
-		gethunk();
-	p = hunk;
-	if (clr)
-		memset(p, 0, n);
-	nhunk -= n;
-	hunk += n;
-	return p;
-}
-
-void
-free(void *p)
-{
-	USED(p);
-}
-
-void*
-calloc(uintptr m, uintptr n)
-{
-	void *p;
-
-	n *= m;
-	p = malloc(n);
-	memset(p, 0, n);
-	return p;
-}
-
-void*
-realloc(void*, uintptr)
-{
-	fprint(2, "realloc called\n");
-	abort();
-	return 0;
-}
-
-void
-setmalloctag(void *v, uintptr pc)
-{
-	USED(v, pc);
-}
+#include	"../cc/compat"
--- a/sys/src/cmd/jl/l.h
+++ b/sys/src/cmd/jl/l.h
@@ -2,6 +2,7 @@
 #include	<libc.h>
 #include	<bio.h>
 #include	"../jc/j.out.h"
+#include	"../cc/compat.h"
 
 #ifndef	EXTERN
 #define	EXTERN	extern
@@ -228,7 +229,6 @@
 EXTERN	char*	libraryobj[50];
 EXTERN	int	libraryp;
 EXTERN	int	xrefresolv;
-EXTERN	char*	hunk;		/* compat.c's malloc */
 EXTERN	char	inuxi1[1];
 EXTERN	char	inuxi2[2];
 EXTERN	char	inuxi4[4];
@@ -237,7 +237,6 @@
 EXTERN	long	lcsize;
 EXTERN	char	literal[32];
 EXTERN	int	nerrors;
-EXTERN	long	nhunk;		/* compat.c's malloc */
 EXTERN	Prog	nopalign;
 EXTERN	long	instoffset;
 EXTERN	vlong	instoffx;
@@ -250,7 +249,6 @@
 EXTERN	long	symsize;
 EXTERN	Prog*	textp;
 EXTERN	long	textsize;
-EXTERN	long	thunk;		/* compat.c's malloc */
 EXTERN	int	version;
 EXTERN	char	xcmp[32][32];
 EXTERN	Prog	zprg;
@@ -310,7 +308,6 @@
 void	exchange(Prog*);
 int	find1(long, int);
 void	follow(void);
-void	gethunk(void);
 void	histtoauto(void);
 double	ieeedtod(Ieee*);
 long	ieeedtof(Ieee*);
--- a/sys/src/cmd/jl/obj.c
+++ b/sys/src/cmd/jl/obj.c
@@ -240,7 +240,6 @@
 out:
 	if(debug['v']) {
 		Bprint(&bso, "%5.2f cpu time\n", cputime());
-		Bprint(&bso, "%ld memory used\n", thunk);
 		Bprint(&bso, "%lld sizeof adr\n", (vlong)sizeof(Adr));
 		Bprint(&bso, "%lld sizeof prog\n", (vlong)sizeof(Prog));
 	}
@@ -437,26 +436,14 @@
 		break;
 
 	case D_SCONST:
-		while(nhunk < NSNAME)
-			gethunk();
-		a->sval = (char*)hunk;
-		nhunk -= NSNAME;
-		hunk += NSNAME;
-
+		a->sval = mallocz(NSNAME, 1);
 		memmove(a->sval, p+4, NSNAME);
 		c += NSNAME;
 		break;
 
 	case D_VCONST:
-		while(nhunk < 12)
-			gethunk();
-		if((uintptr)hunk & 2){
-			nhunk -= 4;
-			hunk += 4;
-		}
-		a->vval = (vlong*)hunk;
-		nhunk -= 8;
-		hunk += 8;
+		a->vval = mallocz(sizeof(vlong), 1);
+
 		*(long*)a->vval = p[4] | (p[5]<<8) |
 			(p[6]<<16) | (p[7]<<24);
 		*((long*)a->vval + 1) = p[8] | (p[9]<<8) |
@@ -465,11 +452,7 @@
 		break;
 
 	case D_FCONST:
-		while(nhunk < sizeof(Ieee))
-			gethunk();
-		a->ieee = (Ieee*)hunk;
-		nhunk -= NSNAME;
-		hunk += NSNAME;
+		a->ieee = mallocz(sizeof(Ieee), 1);
 
 		a->ieee->l = p[4] | (p[5]<<8) |
 			(p[6]<<16) | (p[7]<<24);
@@ -494,11 +477,7 @@
 			return c;
 		}
 
-	while(nhunk < sizeof(Auto))
-		gethunk();
-	u = (Auto*)hunk;
-	nhunk -= sizeof(Auto);
-	hunk += sizeof(Auto);
+	u = mallocz(sizeof(Auto), 1);
 
 	u->link = curauto;
 	curauto = u;
@@ -786,12 +765,7 @@
 		goto loop;
 	}
 
-	if(nhunk < sizeof(Prog))
-		gethunk();
-	p = (Prog*)hunk;
-	nhunk -= sizeof(Prog);
-	hunk += sizeof(Prog);
-
+	p = prg();
 	p->as = o;
 	p->reg = bloc[1];
 	p->line = bloc[2] | (bloc[3]<<8) | (bloc[4]<<16) | (bloc[5]<<24);
@@ -1168,11 +1142,7 @@
 		if(memcmp(s->name, symb, l) == 0)
 			return s;
 
-	while(nhunk < sizeof(Sym))
-		gethunk();
-	s = (Sym*)hunk;
-	nhunk -= sizeof(Sym);
-	hunk += sizeof(Sym);
+	s = mallocz(sizeof(Sym), 1);
 
 	s->name = malloc(l);
 	memmove(s->name, symb, l);
@@ -1191,36 +1161,9 @@
 {
 	Prog *p;
 
-	while(nhunk < sizeof(Prog))
-		gethunk();
-	p = (Prog*)hunk;
-	nhunk -= sizeof(Prog);
-	hunk += sizeof(Prog);
-
+	p = malloc(sizeof *p);
 	*p = zprg;
 	return p;
-}
-
-void
-gethunk(void)
-{
-	char *h;
-	long nh;
-
-	nh = NHUNK;
-	if(thunk >= 5L*NHUNK) {
-		nh = 5L*NHUNK;
-		if(thunk >= 25L*NHUNK)
-			nh = 25L*NHUNK;
-	}
-	h = mysbrk(nh);
-	if(h == (char*)-1) {
-		diag("out of memory");
-		errorexit();
-	}
-	hunk = h;
-	nhunk = nh;
-	thunk += nh;
 }
 
 void