Browse Source

The global m pointer is almost gone.

one or two tweaks left

Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Ronald G. Minnich 9 years ago
parent
commit
d263b2eb5c

+ 5 - 0
sys/src/9/k10/acore.c

@@ -57,6 +57,7 @@ ACVctl *acvctl[256];
 static void
 testiccfn(void)
 {
+	Mach *m = machp();
 	print("called: %s\n", ( char *)m->icc->data);
 }
 
@@ -86,6 +87,7 @@ testicc(int i)
 static void
 acstackok(void)
 {
+	Mach *m = machp();
 	char dummy;
 	char *sstart;
 
@@ -107,6 +109,7 @@ acstackok(void)
 void
 acsched(void)
 {
+	Mach *m = machp();
 	acmmuswitch();
 	for(;;){
 		acstackok();
@@ -124,6 +127,7 @@ acsched(void)
 void
 acmmuswitch(void)
 {
+	Mach *m = machp();
 	extern Page mach0pml4;
 
 	DBG("acmmuswitch mpl4 %#p mach0pml4 %#p m0pml4 %#p\n", m->pml4->pa, mach0pml4.pa, sys->machptr[0]->pml4->pa);
@@ -306,6 +310,7 @@ char *rolename[] =
 void
 acmodeset(int mode)
 {
+	Mach *m = machp();
 	switch(mode){
 	case NIXAC:
 	case NIXKC:

+ 3 - 0
sys/src/9/k10/apic.c

@@ -118,6 +118,7 @@ apicisr(int vecno)
 void
 apicinit(int apicno, uintmem pa, int isbp)
 {
+	Mach *m = machp();
 	Apic *apic;
 
 	/*
@@ -197,6 +198,7 @@ apictimer(Ureg* ureg, void* v)
 int
 apiconline(void)
 {
+	Mach *m = machp();
 	Apic *apic;
 	uint64_t tsc;
 	uint32_t dfr, ver;
@@ -350,6 +352,7 @@ apictimerenab(void)
 void
 apictimerset(uint64_t next)
 {
+	Mach *m = machp();
 	Mpl pl;
 	Apic *apic;
 	int64_t period;

+ 3 - 1
sys/src/9/k10/arch.c

@@ -27,7 +27,7 @@
 // program. In the case of Plan 9, m was r15, and up was r14. Very slick, and if there is a way to do
 // this in gcc or clang I don't know it. This also nicely handled per cpu info; R15/14 were always right for 
 // your core and context.
-Mach *m = (void *)0;
+//Mach *m = (void *)0;
 
 int
 incref(Ref *r)
@@ -87,6 +87,7 @@ procsave(Proc *p)
 static void
 linkproc(void)
 {
+	Mach *m = machp();
 	spllo();
 	m->externup->kpfun(m->externup->kparg);
 	pexit("kproc dying", 0);
@@ -118,6 +119,7 @@ kprocchild(Proc* p, void (*func)(void*), void* arg)
 void
 idlehands(void)
 {
+Mach *m = machp();
 if(0)
 	if(m->machno != 0)
 		halt();

+ 7 - 0
sys/src/9/k10/archk10.c

@@ -16,6 +16,7 @@
 static int
 cpuidinit(void)
 {
+	Mach *m = machp();
 	uint32_t eax, info[4];
 
 	/*
@@ -49,6 +50,7 @@ cpuidinit(void)
 static int
 cpuidinfo(uint32_t eax, uint32_t ecx, uint32_t info[4])
 {
+	Mach *m = machp();
 	if(m->ncpuinfos == 0 && cpuidinit() == 0)
 		return 0;
 
@@ -197,6 +199,7 @@ cpuidhz(uint32_t *info0, uint32_t *info1)
 void
 cpuiddump(void)
 {
+	Mach *m = machp();
 	int i;
 	uint32_t info[4];
 
@@ -221,6 +224,7 @@ cpuiddump(void)
 int64_t
 archhz(void)
 {
+	Mach *m = machp();
 	int64_t hz;
 	uint32_t info0[4], info1[4];
 
@@ -237,6 +241,7 @@ archhz(void)
 int
 archmmu(void)
 {
+	Mach *m = machp();
 	uint32_t info[4];
 
 	/*
@@ -361,6 +366,7 @@ archidle(void)
 void
 microdelay(int microsecs)
 {
+	Mach *m = machp();
 	uint64_t r, t;
 
 	r = rdtsc();
@@ -371,6 +377,7 @@ microdelay(int microsecs)
 void
 millidelay(int millisecs)
 {
+	Mach *m = machp();
 	uint64_t r, t;
 
 	r = rdtsc();

+ 1 - 0
sys/src/9/k10/asm.c

@@ -317,6 +317,7 @@ asmwalkalloc(usize size)
 void
 asmmeminit(void)
 {
+	Mach *m = machp();
 	int i, l;
 	Asm* assem;
 	PTE *pte, *pml4;

+ 1 - 1
sys/src/9/k10/devacpi.c

@@ -846,8 +846,8 @@ acpimblocksize(uintmem addr, int *dom)
 int
 corecolor(int core)
 {
+	Mach *m = machp();
 	Srat *sl;
-	Mach *m;
 	static int colors[32];
 
 	if(core < 0 || core >= MACHMAX)

+ 3 - 0
sys/src/9/k10/devarch.c

@@ -525,6 +525,7 @@ void (*coherence)(void) = mfence;
 static int32_t
 cputyperead(Chan* c, void *a, int32_t n, int64_t off)
 {
+	Mach *m = machp();
 	char buf[512], *s, *e;
 	int i, k;
 
@@ -575,6 +576,7 @@ archreset(void)
 uint64_t
 fastticks(uint64_t* hz)
 {
+	Mach *m = machp();
 	if(hz != nil)
 		*hz = m->cpuhz;
 	return rdtsc();
@@ -606,6 +608,7 @@ cycles(uint64_t* t)
 void
 delay(int millisecs)
 {
+	Mach *m = machp();
 	uint64_t r, t;
 
 	if(millisecs <= 0)

+ 12 - 0
sys/src/9/k10/fpu.c

@@ -120,6 +120,7 @@ fpudevprocio(Proc* proc, void* a, int32_t n, uintptr_t offset, int write)
 void
 fpunotify(Ureg* u)
 {
+	Mach *m = machp();
 	/*
 	 * Called when a note is about to be delivered to a
 	 * user process, usually at the end of a system call.
@@ -138,6 +139,7 @@ fpunotify(Ureg* u)
 void
 fpunoted(void)
 {
+	Mach *m = machp();
 	/*
 	 * Called from sysnoted() via the machine-dependent
 	 * noted() routine.
@@ -149,6 +151,7 @@ fpunoted(void)
 void
 fpusysrfork(Ureg* u)
 {
+	Mach *m = machp();
 	/*
 	 * Called early in the non-interruptible path of
 	 * sysrfork() via the machine-dependent syscall() routine.
@@ -166,6 +169,7 @@ fpusysrfork(Ureg* u)
 void
 fpusysrforkchild(Proc* child, Proc* parent)
 {
+	Mach *m = machp();
 	/*
 	 * Called later in sysrfork() via the machine-dependent
 	 * sysrforkchild() routine.
@@ -262,6 +266,7 @@ acfpusysprocsetup(Proc *p)
 static char*
 fpunote(void)
 {
+	Mach *m = machp();
 	uint16_t fsw;
 	Fxsave *fpusave;
 	char *cm;
@@ -305,6 +310,7 @@ fpunote(void)
 char*
 xfpuxf(Ureg* ureg, void* v)
 {
+	Mach *m = machp();
 	uint32_t mxcsr;
 	Fxsave *fpusave;
 	char *cm;
@@ -354,6 +360,7 @@ xfpuxf(Ureg* ureg, void* v)
 void
 fpuxf(Ureg *ureg, void *p)
 {
+	Mach *m = machp();
 	char *n;
 
 	n = xfpuxf(ureg, p);
@@ -370,6 +377,7 @@ acfpuxf(Ureg *ureg, void *p)
 static char*
 xfpumf(Ureg* ureg, void* v)
 {
+	Mach *m = machp();
 	Fxsave *fpusave;
 
 	/*
@@ -406,6 +414,7 @@ xfpumf(Ureg* ureg, void* v)
 void
 fpumf(Ureg *ureg, void *p)
 {
+	Mach *m = machp();
 	char *n;
 
 	n = xfpumf(ureg, p);
@@ -422,6 +431,7 @@ acfpumf(Ureg *ureg, void *p)
 static char*
 xfpunm(Ureg* ureg, void* v)
 {
+	Mach *m = machp();
 	Fxsave *fpusave;
 
 	/*
@@ -488,6 +498,7 @@ xfpunm(Ureg* ureg, void* v)
 void
 fpunm(Ureg *ureg, void *p)
 {
+	Mach *m = machp();
 	char *n;
 
 	n = xfpunm(ureg, p);
@@ -504,6 +515,7 @@ acfpunm(Ureg *ureg, void *p)
 void
 fpuinit(void)
 {
+	Mach *m = machp();
 	uint64_t r;
 	Fxsave *fxsave;
 	uint8_t buf[sizeof(Fxsave)+15];

+ 1 - 0
sys/src/9/k10/main.c

@@ -32,6 +32,7 @@ uintptr_t kseg0 = KZERO;
 Sys* sys = nil;
 usize sizeofSys = sizeof(Sys);
 
+Mach *m;
 /*
  * Option arguments from the command line.
  * oargv[0] is the boot file.

+ 14 - 0
sys/src/9/k10/mmu.c

@@ -31,6 +31,7 @@
 void
 mmuflushtlb(uint64_t u)
 {
+	Mach *m = machp();
 
 	m->tlbpurge++;
 	if(m->pml4->daddr){
@@ -43,6 +44,7 @@ mmuflushtlb(uint64_t u)
 void
 mmuflush(void)
 {
+	Mach *m = machp();
 	Mpl pl;
 
 	pl = splhi();
@@ -54,6 +56,7 @@ mmuflush(void)
 static void
 mmuptpfree(Proc* proc, int clear)
 {
+	Mach *m = machp();
 	int l;
 	PTE *pte;
 	Page **last, *page;
@@ -114,6 +117,7 @@ dumpptepg(int lvl, uintptr_t pa)
 void
 dumpmmu(Proc *p)
 {
+	Mach *m = machp();
 	int i;
 	Page *pg;
 
@@ -132,6 +136,7 @@ dumpmmu(Proc *p)
 void
 dumpmmuwalk(uint64_t addr)
 {
+	Mach *m = machp();
 	int l;
 	PTE *pte, *pml4;
 
@@ -201,6 +206,7 @@ mmuptpalloc(void)
 void
 mmuswitch(Proc* proc)
 {
+	Mach *m = machp();
 	PTE *pte;
 	Page *page;
 	Mpl pl;
@@ -237,6 +243,7 @@ mmuswitch(Proc* proc)
 void
 mmurelease(Proc* proc)
 {
+	Mach *m = machp();
 	Page *page, *next;
 
 	mmuptpfree(proc, 0);
@@ -263,6 +270,7 @@ mmurelease(Proc* proc)
 static void
 checkpte(uintmem ppn, void *a)
 {
+	Mach *m = machp();
 	int l;
 	PTE *pte, *pml4;
 	uint64_t addr;
@@ -307,6 +315,7 @@ Panic:
 static void
 mmuptpcheck(Proc *proc)
 {
+	Mach *m = machp();
 	int lvl, npgs, i;
 	Page *lp, *p, *pgs[16], *fp;
 	uint idx[16];
@@ -380,6 +389,7 @@ pteflags(uint attr)
 void
 mmuput(uintptr_t va, Page *pg, uint attr)
 {
+	Mach *m = machp();
 	int lvl, user, x, pgsz;
 	PTE *pte;
 	Page *page, *prev;
@@ -639,6 +649,7 @@ vmapalloc(usize size)
 void*
 vmap(uintptr_t pa, usize size)
 {
+	Mach *m = machp();
 	uintptr_t va;
 	usize o, sz;
 
@@ -691,6 +702,7 @@ vmap(uintptr_t pa, usize size)
 void
 vunmap(void* v, usize size)
 {
+	Mach *m = machp();
 	uintptr_t va;
 
 	DBG("vunmap(%#p, %lud)\n", v, size);
@@ -752,6 +764,7 @@ mmuwalk(PTE* pml4, uintptr_t va, int level, PTE** ret,
 uintmem
 mmuphysaddr(uintptr_t va)
 {
+	Mach *m = machp();
 	int l;
 	PTE *pte;
 	uintmem mask, pa;
@@ -780,6 +793,7 @@ Page mach0pml4;
 void
 mmuinit(void)
 {
+	Mach *m = machp();
 	uint8_t *p;
 	Page *page;
 	uint64_t o, pa, r, sz;

+ 5 - 0
sys/src/9/k10/pmcio.c

@@ -281,6 +281,7 @@ pmcwclose(PmcWait *w)
 static void
 waitnotstale(Mach *mp, PmcCtr *p)
 {
+	Mach *m = machp();
 	PmcWait *w;
 
 	p->stale = 1;
@@ -328,6 +329,7 @@ shouldipi(Mach *mp)
 uint64_t
 pmcgetctr(uint32_t coreno, uint32_t regno)
 {
+	Mach *m = machp();
 	PmcCtr *p;
 	Mach *mp;
 	uint64_t v;
@@ -359,6 +361,7 @@ pmcgetctr(uint32_t coreno, uint32_t regno)
 int
 pmcsetctr(uint32_t coreno, uint64_t v, uint32_t regno)
 {
+	Mach *m = machp();
 	PmcCtr *p;
 	Mach *mp;
 
@@ -402,6 +405,7 @@ ctl2ctl(PmcCtl *dctl, PmcCtl *sctl)
 int
 pmcsetctl(uint32_t coreno, PmcCtl *pctl, uint32_t regno)
 {
+	Mach *m = machp();
 	PmcCtr *p;
 	Mach *mp;
 
@@ -423,6 +427,7 @@ pmcsetctl(uint32_t coreno, PmcCtl *pctl, uint32_t regno)
 int
 pmcgetctl(uint32_t coreno, PmcCtl *pctl, uint32_t regno)
 {
+	Mach *m = machp();
 	PmcCtr *p;
 	Mach *mp;
 

+ 1 - 0
sys/src/9/k10/qmalloc.c

@@ -549,6 +549,7 @@ mallocalign(uint32_t nbytes, uint32_t align, int32_t offset, uint32_t span)
 void*
 smalloc(uint32_t size)
 {
+	Mach *m = machp();
 	void *v;
 
 	while((v = malloc(size)) == nil)

+ 1 - 0
sys/src/9/k10/sipi.c

@@ -21,6 +21,7 @@
 void
 sipi(void)
 {
+	Mach *m = machp();
 	Apic *apic;
 	Mach *mach;
 	int apicno, i;

+ 5 - 0
sys/src/9/k10/syscall.c

@@ -37,6 +37,7 @@ typedef struct {
 void
 noted(Ureg* cur, uintptr_t arg0)
 {
+	Mach *m = machp();
 	NFrame *nf;
 	Note note;
 	Ureg *nur;
@@ -126,6 +127,7 @@ noted(Ureg* cur, uintptr_t arg0)
 int
 notify(Ureg* ureg)
 {
+	Mach *m = machp();
 	int l;
 	Mpl pl;
 	Note note;
@@ -211,6 +213,7 @@ notify(Ureg* ureg)
 void
 noerrorsleft(void)
 {
+	Mach *m = machp();
 	int i;
 
 	if(m->externup->nerrlab){
@@ -231,6 +234,7 @@ void
 syscall(int badscallnr, uintptr_t a0, uintptr_t a1, uintptr_t a2, uintptr_t a3, 
 	uintptr_t a4, uintptr_t a5, Ureg *ureg)
 {
+	Mach *m = machp();
 	unsigned int scallnr = (unsigned int) badscallnr;
 	char *e;
 	uintptr_t	sp;
@@ -390,6 +394,7 @@ sysexecstack(uintptr_t stack, int argc)
 void*
 sysexecregs(uintptr_t entry, uint32_t ssize, uint32_t nargs)
 {
+	Mach *m = machp();
 	uintptr_t *sp;
 	Ureg *ureg;
 

+ 10 - 0
sys/src/9/k10/trap.c

@@ -259,6 +259,7 @@ static char* excname[32] = {
 void
 intrtime(int vno)
 {
+	Mach *m = machp();
 	uint32_t diff, x;		/* should be uint64_t */
 
 	x = perfticks();
@@ -284,6 +285,7 @@ void (*_pmcupdate)(Mach *m) = pmcnop;
 void
 kexit(Ureg* u)
 {
+ 	Mach *m = machp();
  	uint64_t t;
 	Tos *tos;
 	Mach *mp;
@@ -314,6 +316,7 @@ kexit(Ureg* u)
 void
 _trap(Ureg *ureg)
 {
+	Mach *m = machp();
 	/*
 	 * If it's a real trap in this core, then we want to
 	 * use the hardware cr2 register.
@@ -337,6 +340,7 @@ _trap(Ureg *ureg)
 void
 trap(Ureg* ureg)
 {
+	Mach *m = machp();
 	int clockintr, vno, user;
 	char buf[ERRMAX];
 	Vctl *ctl, *v;
@@ -455,6 +459,7 @@ trap(Ureg* ureg)
 static void
 dumpgpr(Ureg* ureg)
 {
+	Mach *m = machp();
 	if(m->externup != nil)
 		iprint("cpu%d: registers for %s %d\n",
 			m->machno, m->externup->text, m->externup->pid);
@@ -493,6 +498,7 @@ dumpgpr(Ureg* ureg)
 void
 dumpregs(Ureg* ureg)
 {
+	Mach *m = machp();
 
 	dumpgpr(ureg);
 
@@ -526,6 +532,7 @@ callwithureg(void (*fn)(Ureg*))
 static void
 dumpstackwithureg(Ureg* ureg)
 {
+	Mach *m = machp();
 	char *s;
 	uintptr_t l, v, i, estack;
 //	extern char etext;
@@ -580,6 +587,7 @@ dumpstack(void)
 static void
 debugbpt(Ureg* ureg, void* v)
 {
+	Mach *m = machp();
 	char buf[ERRMAX];
 
 	if(m->externup == 0)
@@ -610,6 +618,7 @@ expected(Ureg* ureg, void* v)
 static void
 faultamd64(Ureg* ureg, void* v)
 {
+	Mach *m = machp();
 	uint64_t addr;
 	int read, user, insyscall;
 	char buf[ERRMAX];
@@ -662,6 +671,7 @@ faultamd64(Ureg* ureg, void* v)
 uintptr_t
 userpc(Ureg* ureg)
 {
+	Mach *m = machp();
 	if(ureg == nil)
 		ureg = m->externup->dbgreg;
 	return ureg->ip;

+ 1 - 1
sys/src/9/k10/vsvm.c

@@ -162,9 +162,9 @@ void acsyscallentry(void)
 void
 vsvminit(int size, int nixtype)
 {
+	Mach *m = machp();
 	Sd *sd;
 	uint64_t r;
-	Mach *m = machp();
 	if(m->machno == 0){
 		idtinit(idt64, PTR2UINT(idthandlers));
 		//idtinit(acidt64, PTR2UINT(acidthandlers));