shithub: nix

Download patch

ref: 9df57796ae86da20d019b8184eca852d7e31a306
parent: 5bb60a06b61388bbd2e29a20b2a363346f9c9dbc
author: glenda <glenda@cirno>
date: Tue May 7 18:12:36 EDT 2024

Initial nix scaffolding. Now to add acshed etc.

--- a/sys/src/nix/pc64/devnix.c
+++ b/sys/src/nix/pc64/devnix.c
@@ -25,7 +25,6 @@
 	Qdir,
 	Qctl,
 	Qstat,
-	Q1,
 };
 
 static Dirtab nixdir[] = {
@@ -32,25 +31,21 @@
 	".",		{Qdir, 0, QTDIR},	0,	0555,
 	"nixctl",	{Qctl},		0,	0666,
 	"nixstat",  {Qstat},	0,	0444,
-	"nix1",		{Q1},		0,	0444,
 };
 
 typedef struct DEVNIX DEVNIX;
 
 struct DEVNIX {
-	int online;
 	int nixed;
 } nixes[MAXMACH];
 
-int nnix = 1; // fix later
+int nnix = 0;
 
-
 static void
 nixreset(void)
 {
 	DEVNIX *nix;
 
-	if (0)
 	for(nnix = 0; nnix < MAXMACH; nnix++){
 		nix = &nixes[nnix];
 		print("nix %p\n", nix);
@@ -73,7 +68,7 @@
 {
 	if(debug&DBGFS)
 		print("nixwalk\n");
-	return devwalk(c, nc, name, nname, nixdir, 3*nnix+1, devgen);
+	return devwalk(c, nc, name, nname, nixdir, nelem(nixdir), devgen);
 }
 
 static int
@@ -81,38 +76,31 @@
 {
 	if(debug&DBGFS)
 		print("nixstat\n");
-	return devstat(c, db, n, nixdir, 3*nnix+1, devgen);
+	return devstat(c, db, n, nixdir, nelem(nixdir), devgen);
 }
 
 static Chan*
 nixopen(Chan *c, int omode)
 {
-	int i;
-	DEVNIX *nix;
-
 	if(debug&DBGFS)
 		print("nixopen\n");
-	if(omode != OREAD)
-		error(Eperm);
 	c->aux = 0;
-	i = 0;
 	switch((ulong)c->qid.path){
 	case Qctl:
-		error(Eperm);
 		break;
 	case Qstat:
-		error(Eperm);
+		if (omode != OREAD)
+			error(Eperm);
 		break;
-	case Q1:
-		print("we really oughtta nix\n");
-		error(Eperm);
-		break;
+	default:
+		if (omode != OREAD)
+			error(Eperm);
 	}
-	return devopen(c, omode, nixdir, 3*nnix+1, devgen);
+	return devopen(c, omode, nixdir, nelem(nixdir), devgen);
 }
 
 static void
-nixclose(Chan *c)
+nixclose(Chan *)
 {
 	if(debug&DBGFS)
 		print("nixclose\n");
@@ -124,7 +112,6 @@
 	int i, len;
 	long off = voff;
 	uchar *buf = va;
-	DEVNIX *nix;
 	static char nixinfo[1024];
 
 	i = 0;
@@ -133,7 +120,7 @@
 		if(debug&(DBGFS|DBGREAD))
 			print("nixread %p %d %d\n", va, n, voff);
 
-		n = devdirread(c, (char *)buf, n, nixdir, 3*nnix+1, devgen);
+		n = devdirread(c, (char *)buf, n, nixdir, nelem(nixdir), devgen);
 		if(debug&(DBGFS|DBGREAD))
 			print("nixread %ld\n", n);
 		return n;
@@ -141,9 +128,6 @@
 		error(Eperm);
 		break;
 	case Qstat:
-		if(i >= nnix)
-			error(Eio);
-		nix = nixes+i;
 		len = snprint(nixinfo, sizeof nixinfo, "sizzle me a sizzler");
 		if(voff > len)
 			return 0;
@@ -151,18 +135,59 @@
 			n = len - voff;
 		memmove(va, nixinfo+voff, n);
 		return n;
-	case Q1:
-		error(Eperm);
-		break;
+	default:
+		panic("nixread: %d\n", c->qid.path);
 	}
 	return -1;
 }
 
+/* can only write to Qctl */
 static long
-nixwrite(Chan *, void *, long, vlong)
+nixwrite(Chan *, void *p, long n, vlong)
 {
-	error(Eperm);
-	return 0;
+	int nf;
+	char *f[2];
+
+	nf = tokenize(p, f, nelem(f));	
+
+
+	if (strcmp(f[0], "a") == 0) {
+		if (nf != 1)
+			error("a 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;
+		print("NIX ME %d\n", m->machno);
+		/* acsched here */
+		/* 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)
+			error("usage: nix <core#>");
+		core = strtoull(f[1], 0, 0);
+		if (core > MAXMACH)
+			error("Core is > MAXMACH");
+		if (nixes[core].nixed == 0)
+			error("Core is not nixed");
+		print("I guess we run on it\n");
+		print("I guess we're back\n");
+	}
+
+	error("no such operation\n");
 }
 
 Dev nixdevtab = {