Browse Source

Plan 9 from Bell Labs 2011-06-30

David du Colombier 12 years ago
parent
commit
9ea1c90a60
4 changed files with 61 additions and 13 deletions
  1. 10 1
      sys/src/cmd/5i/5i.c
  2. 14 3
      sys/src/cmd/ki/ki.c
  3. 23 6
      sys/src/cmd/qi/qi.c
  4. 14 3
      sys/src/cmd/vi/vi.c

+ 10 - 1
sys/src/cmd/5i/5i.c

@@ -147,6 +147,15 @@ initstk(int argc, char *argv[])
 	initmap();
 	tos = STACKTOP - sizeof(Tos)*2;	/* we'll assume twice the host's is big enough */
 	sp = tos;
+	for (i = 0; i < sizeof(Tos)*2; i++)
+		putmem_b(tos + i, 0);
+
+	/*
+	 * pid is second word from end of tos and needs to be set for nsec().
+	 * we know arm is a 32-bit cpu, so we'll assume knowledge of the Tos
+	 * struct for now, and use our pid.
+	 */
+	putmem_w(tos + 4*4 + 2*sizeof(ulong) + 3*sizeof(uvlong), getpid());
 
 	/* Build exec stack */
 	size = strlen(file)+1+BY2WD+BY2WD+BY2WD;	
@@ -157,7 +166,7 @@ initstk(int argc, char *argv[])
 	sp &= ~7;
 	reg.r[0] = tos;
 	reg.r[13] = sp;
-	reg.r[1] = STACKTOP-4;	/* Plan 9 profiling clock */
+	reg.r[1] = STACKTOP-4;	/* Plan 9 profiling clock (why & why in R1?) */
 
 	/* Push argc */
 	putmem_w(sp, argc+1);

+ 14 - 3
sys/src/cmd/ki/ki.c

@@ -2,6 +2,7 @@
 #include <libc.h>
 #include <bio.h>
 #include <mach.h>
+#include <tos.h>
 #define Extern
 #include "sparc.h"
 
@@ -277,12 +278,22 @@ reset(void)
 void
 initstk(int argc, char *argv[])
 {
-	ulong size, sp, ap;
+	ulong size, sp, ap, tos;
 	int i;
 	char *p;
 
 	initmap();
-	sp = STACKTOP - 4;
+	tos = STACKTOP - sizeof(Tos)*2;	/* we'll assume twice the host's is big enough */
+	sp = tos;
+	for (i = 0; i < sizeof(Tos)*2; i++)
+		putmem_b(tos + i, 0);
+
+	/*
+	 * pid is second word from end of tos and needs to be set for nsec().
+	 * we know sparc is a 32-bit cpu, so we'll assume knowledge of the Tos
+	 * struct for now, and use our pid.
+	 */
+	putmem_w(tos + 4*4 + 2*sizeof(ulong) + 3*sizeof(uvlong), getpid());
 
 	/* Build exec stack */
 	size = strlen(file)+1+BY2WD+BY2WD+(BY2WD*2);	
@@ -292,7 +303,7 @@ initstk(int argc, char *argv[])
 	sp -= size;
 	sp &= ~7;
 	reg.r[1] = sp;
-	reg.r[7] = STACKTOP-4;	/* Plan 9 profiling clock */
+	reg.r[7] = tos;		/* Plan 9 profiling clock, etc. */
 
 	/* Push argc */
 	putmem_w(sp, argc+1);

+ 23 - 6
sys/src/cmd/qi/qi.c

@@ -2,6 +2,7 @@
 #include <libc.h>
 #include <bio.h>
 #include <mach.h>
+#include <tos.h>
 #define Extern
 #include "power.h"
 
@@ -51,6 +52,12 @@ main(int argc, char **argv)
 	cmd();
 }
 
+/*
+ * we're rounding segment boundaries to the nearest 1MB on power now,
+ * and mach->pgsize is actually what to round segment boundaries up to.
+ */
+#define SEGROUND mach->pgsize
+
 void
 initmap(void)
 {
@@ -58,10 +65,10 @@ initmap(void)
 	ulong t, d, b, bssend;
 	Segment *s;
 
-	t = (fhdr.txtaddr+fhdr.txtsz+(BY2PG-1)) & ~(BY2PG-1);
-	d = (t + fhdr.datsz + (BY2PG-1)) & ~(BY2PG-1);
+	t = (fhdr.txtaddr+fhdr.txtsz+(SEGROUND-1)) & ~(SEGROUND-1);
+	d = (t + fhdr.datsz + (SEGROUND-1)) & ~(SEGROUND-1);
 	bssend = t + fhdr.datsz + fhdr.bsssz;
-	b = (bssend + (BY2PG-1)) & ~(BY2PG-1);
+	b = (bssend + (SEGROUND-1)) & ~(SEGROUND-1);
 
 	s = &memory.seg[Text];
 	s->type = Text;
@@ -278,12 +285,22 @@ reset(void)
 void
 initstk(int argc, char *argv[])
 {
-	ulong size, sp, ap;
+	ulong size, sp, ap, tos;
 	int i;
 	char *p;
 
 	initmap();
-	sp = STACKTOP - 4;
+	tos = STACKTOP - sizeof(Tos)*2;	/* we'll assume twice the host's is big enough */
+	sp = tos;
+	for (i = 0; i < sizeof(Tos)*2; i++)
+		putmem_b(tos + i, 0);
+
+	/*
+	 * pid is second word from end of tos and needs to be set for nsec().
+	 * we know power is a 32-bit cpu, so we'll assume knowledge of the Tos
+	 * struct for now, and use our pid.
+	 */
+	putmem_w(tos + 4*4 + 2*sizeof(ulong) + 3*sizeof(uvlong), getpid());
 
 	/* Build exec stack */
 	size = strlen(file)+1+BY2WD+BY2WD+(BY2WD*2);	
@@ -293,7 +310,7 @@ initstk(int argc, char *argv[])
 	sp -= size;
 	sp &= ~7;
 	reg.r[1] = sp;
-	reg.r[3] = STACKTOP-4;	/* Plan 9 profiling clock */
+	reg.r[3] = tos;		/* Plan 9 profiling clock, etc. */
 
 	/* Push argc */
 	putmem_w(sp, argc+1);

+ 14 - 3
sys/src/cmd/vi/vi.c

@@ -2,6 +2,7 @@
 #include <libc.h>
 #include <bio.h>
 #include <mach.h>
+#include <tos.h>
 #define Extern
 #include "mips.h"
 
@@ -291,12 +292,22 @@ void
 initstk(int argc, char *argv[])
 {
 	ulong size;
-	ulong sp, ap;
+	ulong sp, ap, tos;
 	int i;
 	char *p;
 
 	initmap();
-	sp = STACKTOP - 4;
+	tos = STACKTOP - sizeof(Tos)*2;	/* we'll assume twice the host's is big enough */
+	sp = tos;
+	for (i = 0; i < sizeof(Tos)*2; i++)
+		putmem_b(tos + i, 0);
+
+	/*
+	 * pid is second word from end of tos and needs to be set for nsec().
+	 * we know mips is a 32-bit cpu, so we'll assume knowledge of the Tos
+	 * struct for now, and use our pid.
+	 */
+	putmem_w(tos + 4*4 + 2*sizeof(ulong) + 3*sizeof(uvlong), getpid());
 
 	/* Build exec stack */
 	size = strlen(file)+1+BY2WD+BY2WD+BY2WD;	
@@ -306,7 +317,7 @@ initstk(int argc, char *argv[])
 	sp -= size;
 	sp &= ~3;
 	reg.r[29] = sp;
-	reg.r[1] = STACKTOP-4;	/* Plan 9 profiling clock */
+	reg.r[1] = tos;			/* Plan 9 profiling clock, etc. */
 
 	/* Push argc */
 	putmem_w(sp, argc+1);