shithub: riscv

Download patch

ref: f58706f2cf09a338bd39153757d1db399ad73f9e
parent: befdd7d7559f95734976d0ae127ac234eeb5b7d3
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Jun 28 14:57:13 EDT 2017

zynq: simplify initcode stack setup (just do it in init0 when the stack is mapped)

--- a/sys/src/9/zynq/main.c
+++ b/sys/src/9/zynq/main.c
@@ -11,7 +11,6 @@
 
 Conf conf;
 int normalprint, delaylink;
-uchar *sp;
 
 enum { MAXCONF = 64 };
 
@@ -191,42 +190,10 @@
 	imagmem->maxsize = kmem - (kmem/10);
 }
 
-static uchar *
-pusharg(char *p)
-{
-	int n;
-	
-	n = strlen(p) + 1;
-	sp -= n;
-	memmove(sp, p, n);
-	return sp;
-}
-
 static void
-bootargs(void *base)
-{
-	int i, ac;
-	uchar *av[32];
-	uchar **lsp;
-	
-	sp = (uchar *) base + BY2PG - sizeof(Tos);
-	
-	ac = 0;
-	av[ac++] = pusharg("boot");
-	sp = (uchar *) ((ulong) sp & ~3);
-	sp -= (ac + 1) * sizeof(sp);
-	lsp = (uchar **) sp;
-	for(i = 0; i < ac; i++)
-		lsp[i] = av[i] + ((USTKTOP - BY2PG) - (ulong) base);
-	lsp[i] = 0;
-	sp += (USTKTOP - BY2PG) - (ulong) base;
-	sp -= BY2WD;
-}
-
-static void
 init0(void)
 {
-	char buf[ERRMAX];
+	char buf[ERRMAX], **sp;
 	int i;
 
 	up->nerrlab = 0;
@@ -257,6 +224,11 @@
 		poperror();
 	}
 	kproc("alarm", alarmkproc, 0);
+
+	sp = (char**)(USTKTOP - sizeof(Tos) - 8 - sizeof(sp[0])*4);
+	sp[3] = sp[2] = nil;
+	strcpy(sp[1] = (char*)&sp[4], "boot");
+	sp[0] = nil;
 	touser(sp);
 }
 
@@ -288,10 +260,9 @@
 	s = newseg(SG_STACK, USTKTOP - USTKSIZE, USTKSIZE / BY2PG);
 	p->seg[SSEG] = s;
 	pg = newpage(0, 0, USTKTOP - BY2PG);
+	segpage(s, pg);
 	v = tmpmap(pg->pa);
 	memset(v, 0, BY2PG);
-	segpage(s, pg);
-	bootargs(v);
 	tmpunmap(v);
 	
 	s = newseg(SG_TEXT, UTZERO, 1);