shithub: nix

Download patch

ref: beacaa8db0edc753cf5231d2fd6532b6cc27749a
parent: b91e711e4dc2a2fef04e8212c1efe41b92691b6d
author: glenda <glenda@cirno>
date: Sun May 5 12:28:00 EDT 2024

get tcore to compile, checkpoint

--- a/sys/src/nix/pc64/nix.h
+++ b/sys/src/nix/pc64/nix.h
@@ -12,7 +12,10 @@
 struct NIX
 {
 	ICC*	icc;			/* inter-core call */
-	int	nixtype;	
+	int	nixtype;
+	int apicno; // not sure we need this? 
+	int online; // TODO: what is this really? 
+	uvlong nicc;
 };
 
 /*
--- a/sys/src/nix/pc64/nixmkfile
+++ b/sys/src/nix/pc64/nixmkfile
@@ -61,6 +61,7 @@
 	$DEVS\
 	$PORT\
 	acore.$O\
+	tcore.$O\
 	l64acidt.$O\
 	l64acsyscall.$O\
 
--- a/sys/src/nix/pc64/tcore.c
+++ b/sys/src/nix/pc64/tcore.c
@@ -1,17 +1,18 @@
-#include "u.h"
-#include "../port/lib.h"
-#include "mem.h"
-#include "dat.h"
-#include "fns.h"
+#include	"u.h"
+#include	"tos.h"
+#include	"../port/lib.h"
+#include	"mem.h"
+#include	"dat.h"
+#include	"fns.h"
+#include	"io.h"
+#include	"../port/pci.h"
+#include	"ureg.h"
+#include	"pool.h"
+#include 	"mp.h"
 
-#include <tos.h>
-#include <pool.h>
-#include "amd64.h"
-#include "ureg.h"
-#include "io.h"
-
 Lock nixaclock;	/* NIX AC lock; held while assigning procs to cores */
 
+#define DBG print
 /*
  * NIX support for the time sharing core.
  */
@@ -24,8 +25,8 @@
 {
 	int i;
 	Mach *mp;
+	extern char **rolename;
 
-	mp = nil;
 	if(core == 0)
 		panic("can't getac for a %s", rolename[NIXTC]);
 	lock(&nixaclock);
@@ -34,9 +35,9 @@
 		nexterror();
 	}
 	if(core > 0){
-		if(core >= MACHMAX)
+		if(core >= MAXMACH)
 			error("no such core");
-		mp = sys->machptr[core];
+		mp = machp[core];
 		if(mp == nil || mp->online == 0 || mp->proc != nil)
 			error("core not online or busy");
 		if(mp->nixtype != NIXAC)
@@ -44,8 +45,8 @@
 	Found:
 		mp->proc = p;
 	}else{
-		for(i = 0; i < MACHMAX; i++)
-			if((mp = sys->machptr[i]) != nil && mp->online && mp->nixtype == NIXAC)
+		for(i = 0; i < MAXMACH; i++)
+			if((mp = machp[i]) != nil && mp->online && mp->nixtype == NIXAC)
 				if(mp->proc == nil)
 					goto Found;
 		error("not enough cores");
@@ -78,7 +79,7 @@
 	 * It's ok if the AC gets idle in the mean time.
 	 */
 	DBG("intrac: ipi to cpu%d\n", ac->machno);
-	apicipi(ac->apicno);
+	panic("apicipi(ac->apicno);\n");
 }
 
 void
@@ -129,7 +130,7 @@
 int
 runac(Mach *mp, APfunc func, int flushtlb, void *a, long n)
 {
-	uchar *dpg, *spg;
+	void *dpg, *spg;
 
 	if (n > sizeof(mp->icc->data))
 		panic("runac: args too long");
@@ -141,16 +142,17 @@
 
 	memmove(mp->icc->data, a, n);
 	if(flushtlb){
-		DBG("runac flushtlb: cppml4 %#p %#p\n", mp->pml4->pa, m->pml4->pa);
-		dpg = UINT2PTR(mp->pml4->va);
-		spg = UINT2PTR(m->pml4->va);
+		DBG("runac flushtlb: cppml4 %#p %#p\n", mp->pml4, m->pml4);
+		dpg = mp->pml4;
+		spg = m->pml4;
 		/* We should copy less:
 		 *	memmove(dgp, spg, m->pml4->daddr * sizeof(PTE));
 		 */
 		memmove(dpg, spg, PTSZ);
 		if(0){
-			print("runac: upac pml4 %#p\n", up->ac->pml4->pa);
-			dumpptepg(4, up->ac->pml4->pa);
+			void dumpptepg(int lvl, uintptr pa);
+			print("runac: upac pml4 %#p\n", up->ac->pml4);
+			//dumpptepg(4, up->ac->pml4);
 		}
 	}
 	mp->icc->flushtlb = flushtlb;
@@ -163,7 +165,7 @@
 	}
 	qlock(&up->debug);
 	up->nicc++;
-	up->state = Exotic;
+	// TODO up->state = Exotic;
 	up->psstate = 0;
 	qunlock(&up->debug);
 	poperror();
@@ -171,6 +173,49 @@
 	mp->icc->fn = func;
 	sched();
 	return mp->icc->rc;
+}
+
+/* TODO: get this into port/proc.c */
+void
+uprocctl(Proc *up)
+{
+	char *state;
+	ulong s;
+
+	switch(up->procctl) {
+	case Proc_exitbig:
+		spllo();
+		pprint("Killed: Insufficient physical memory\n");
+		pexit("Killed: Insufficient physical memory", 1);
+
+	case Proc_exitme:
+		spllo();		/* pexit has locks in it */
+		pexit("Killed", 1);
+
+	case Proc_traceme:
+		if(up->nnote == 0)
+			return;
+		/* No break */
+
+	case Proc_stopme:
+		up->procctl = 0;
+		state = up->psstate;
+		up->psstate = statename[Stopped];
+		/* free a waiting debugger */
+		s = spllo();
+		qlock(&up->debug);
+		if(up->pdbg != nil) {
+			wakeup(&up->pdbg->sleep);
+			up->pdbg = nil;
+		}
+		qunlock(&up->debug);
+		splhi();
+		up->state = Stopped;
+		sched();
+		up->psstate = state;
+		splx(s);
+		return;
+	}
 }
 
 /*
--- a/sys/src/nix/port/portdat.h
+++ b/sys/src/nix/port/portdat.h
@@ -794,6 +794,7 @@
 	uvlong nactrap;
 	uvlong actime;
 	uvlong actime1;
+	Mach *ac;
 };
 
 enum