shithub: nix

Download patch

ref: 2499506dfedee7c2b68aa431306349e9037ba80e
parent: b136801101b8197b90071dd70b050911f6a7ac10
author: glenda <glenda@cirno>
date: Wed May 8 19:39:06 EDT 2024

run command is now like the original nix model.
if, while running, open nixctl and write run to it,
you become a nix process. Only problem: gets a page fault.
can't win them all.

--- a/sys/src/nix/pc64/acore.c
+++ b/sys/src/nix/pc64/acore.c
@@ -121,7 +121,6 @@
 
 	int core = m->machno;
 	acmmuswitch();
-	nix->icc->fn = nil;
 
 	print("acsched %d times on core %d\n", i, core);
 	for(;i;i--){
@@ -143,16 +142,11 @@
 }
 
 void
-actrap(Ureg *)
-{
-	print("actrap");
-}
-void
 acsyscall(void)
 {
 	print("acsyscall");
 }
-#ifdef _NOTNOW__
+
 /*
  * Beware: up is not set when this function is called.
  */
@@ -167,7 +161,6 @@
 	u = m->proc->dbgreg;
 	DBG("cpu%d: touser usp = %#p entry %#p\n", m->machno, u->sp, u->pc);
 	xactouser(u->sp);
-	panic("actouser");
 }
 
 void
@@ -197,14 +190,19 @@
 {
 	char *n;
 	ACVctl *v;
+	NIX *devnix(void);
+	NIX *nix = devnix();
 
 	n = nil;
 
+#ifdef ZERO
 	_pmcupdate(m);
 	if(m->proc != nil){
 		m->proc->nactrap++;
 		m->proc->actime1 = fastticks(nil);
 	}
+#endif
+
 	if(u->type < nelem(acvctl)){
 		v = acvctl[u->type];
 		if(v != nil){
@@ -238,27 +236,33 @@
 		print("actrap: cpu%d: %ulld\n", m->machno, u->type);
 	}
 Post:
-	m->icc->rc = ICCTRAP;
-	m->cr2 = getcr2();
+	nix->icc->rc = ICCTRAP;
+	//m->cr2 = getcr2();
 	memmove(m->proc->dbgreg, u, sizeof *u);
-	m->icc->note = n;
+	nix->icc->note = n;
+#ifdef ZERO
 	fpuprocsave(m->proc);
 	_pmcupdate(m);
+#endif
 	mfence();
-	m->icc->fn = nil;
+	nix->icc->fn = nil;
 	ready(m->proc);
 
-	mwait(&m->icc->fn);
+	//mwait(&m->icc->fn);
+	while(! nix->icc->fn)
+		;
 
-	if(m->icc->flushtlb)
+	if(nix->icc->flushtlb)
 		acmmuswitch();
-	if(m->icc->fn != actrapret)
-		acsched(-1, nil);
+	if(nix->icc->fn != actrapret)
+		acsched(-1, nix);
 	DBG("actrap: ret\n");
 	memmove(u, m->proc->dbgreg, sizeof *u);
 	if(m->proc)
 		m->proc->actime += fastticks2us(fastticks(nil) - m->proc->actime1);
 }
+
+#ifdef NOTNOW
 
 void
 acsyscall(void)
--- a/sys/src/nix/pc64/devnix.c
+++ b/sys/src/nix/pc64/devnix.c
@@ -39,12 +39,15 @@
 struct DEVNIX {
 	int nixed;
 	NIX nix;
-	ICC icc;
 } nixes[MAXMACH];
 
 int nnix = 0;
 static Segdesc *acidt;
 
+NIX *devnix() {
+	return &nixes[m->machno].nix;
+}
+
 void nixidt(uintptr *p)
 {
 	uintptr ptr[2];
@@ -208,10 +211,13 @@
 {
 	int nf;
 	char *f[2];
+	void actouser(void);
 
 	nf = tokenize(p, f, nelem(f));	
 
-
+	/* A just attaches the AC but runs nothing on it.
+	 * It is useful for tests.
+	 */
 	if (strcmp(f[0], "a") == 0) {
 			void acsched(int i, NIX *);
 		if (nf != 1)
@@ -228,6 +234,7 @@
 		 * machno. So we can just take it.
 		 */
 		nixes[m->machno].nixed = 1;
+		nixes[m->machno].nix.icc->fn = nil;
 		print("NIX ME %d\n", m->machno);
 		/* acsched here */
 		acsched(1024, &nixes[m->machno].nix);
@@ -237,6 +244,32 @@
 		return n;
 	}
 
+	if (strcmp(f[0], "run") == 0) {
+			void acsched(int i, NIX *);
+		if (nf != 1)
+			error("run takes no arguments");
+
+		/* so here's the good part. We have to be wired
+		 * to this core. So by definition ... we're on
+		 * the right core.
+		 */
+		if (m->machno == 0)
+			error("have a heart, leave core 0 alone");
+
+		/* the next good part. We're by definition on
+		 * machno. So we can just take it.
+		 */
+		nixes[m->machno].nixed = 1;
+		nixes[m->machno].nix.icc->fn = actouser;
+		print("NIX ME %d\n", m->machno);
+		/* acsched here */
+		acsched(1024, &nixes[m->machno].nix);
+		/* acsched returns and we're back. */
+		print("UN NIX ME %d\n", m->machno);
+		nixes[m->machno].nixed = 0;
+		return n;
+	
+	}
 	if (strcmp(f[0], "nix") == 0) {
 		int core;
 		if (nf != 2)