Browse Source

Plan 9 from Bell Labs 2006-03-12

David du Colombier 15 years ago
parent
commit
a6ff7efdf0

+ 5 - 5
dist/replica/_plan9.db

@@ -224,7 +224,7 @@
 386/bin/execnet - 775 sys sys 1138500564 178046
 386/bin/exportfs - 775 sys sys 1135570807 162237
 386/bin/ext2srv - 775 sys sys 1135570808 179710
-386/bin/faces - 775 sys sys 1139457581 194170
+386/bin/faces - 775 sys sys 1142099815 194163
 386/bin/factor - 775 sys sys 1135570809 61456
 386/bin/fcp - 775 sys sys 1136656336 82190
 386/bin/file - 775 sys sys 1138500574 120581
@@ -7994,7 +7994,7 @@ sys/src/9/pc/main.c - 664 sys sys 1131290418 15224
 sys/src/9/pc/mem.h - 664 sys sys 1137622431 5203
 sys/src/9/pc/memory.c - 664 sys sys 1131573303 18191
 sys/src/9/pc/mkfile - 664 sys sys 1137622906 3572
-sys/src/9/pc/mmu.c - 664 sys sys 1136336093 24152
+sys/src/9/pc/mmu.c - 664 sys sys 1142124315 25229
 sys/src/9/pc/mouse.c - 664 sys sys 1098479254 7057
 sys/src/9/pc/mp.c - 664 sys sys 1131538523 17317
 sys/src/9/pc/mp.h - 664 sys sys 1131538511 6652
@@ -8069,7 +8069,7 @@ sys/src/9/port/chan.c - 664 sys sys 1141940068 34831
 sys/src/9/port/cis.c - 664 sys sys 1099761153 9248
 sys/src/9/port/debugalloc.c - 664 sys sys 1014931171 10402
 sys/src/9/port/dev.c - 664 sys sys 1131289870 8219
-sys/src/9/port/devaudio.c - 664 sys sys 1067722761 21130
+sys/src/9/port/devaudio.c - 664 sys sys 1142086793 21147
 sys/src/9/port/devbridge.c - 664 sys sys 1055688301 24308
 sys/src/9/port/devcap.c - 664 sys sys 1048644215 4113
 sys/src/9/port/devcons.c - 664 sys sys 1139667186 23014
@@ -8085,7 +8085,7 @@ sys/src/9/port/devmntstats.c - 664 sys sys 1014931173 4039
 sys/src/9/port/devmouse.c - 664 sys sys 1130848303 13517
 sys/src/9/port/devpipe.c - 664 sys sys 1077055016 5825
 sys/src/9/port/devpnp.c - 664 sys sys 1088560907 13624
-sys/src/9/port/devproc.c - 664 sys sys 1138469351 28497
+sys/src/9/port/devproc.c - 664 sys sys 1142086847 28500
 sys/src/9/port/devroot.c - 664 sys sys 1067722764 4254
 sys/src/9/port/devsd.c - 664 sys sys 1138458233 30866
 sys/src/9/port/devsdp.c - 664 sys sys 1057323393 44800
@@ -10111,7 +10111,7 @@ sys/src/cmd/ext2srv/xfile.c - 664 sys sys 1055687749 2543
 sys/src/cmd/ext2srv/xfssrv.c - 664 sys sys 1055687749 1292
 sys/src/cmd/faces - 20000000775 sys sys 952888246 0
 sys/src/cmd/faces/dblook.c - 664 sys sys 944961084 359
-sys/src/cmd/faces/facedb.c - 664 sys sys 1139442044 10555
+sys/src/cmd/faces/facedb.c - 664 sys sys 1142086801 10551
 sys/src/cmd/faces/faces.h - 664 sys sys 1072972232 1115
 sys/src/cmd/faces/main.c - 664 sys sys 1106409986 13643
 sys/src/cmd/faces/mkfile - 664 sys sys 1062460262 355

+ 5 - 5
dist/replica/plan9.db

@@ -224,7 +224,7 @@
 386/bin/execnet - 775 sys sys 1138500564 178046
 386/bin/exportfs - 775 sys sys 1135570807 162237
 386/bin/ext2srv - 775 sys sys 1135570808 179710
-386/bin/faces - 775 sys sys 1139457581 194170
+386/bin/faces - 775 sys sys 1142099815 194163
 386/bin/factor - 775 sys sys 1135570809 61456
 386/bin/fcp - 775 sys sys 1136656336 82190
 386/bin/file - 775 sys sys 1138500574 120581
@@ -7994,7 +7994,7 @@ sys/src/9/pc/main.c - 664 sys sys 1131290418 15224
 sys/src/9/pc/mem.h - 664 sys sys 1137622431 5203
 sys/src/9/pc/memory.c - 664 sys sys 1131573303 18191
 sys/src/9/pc/mkfile - 664 sys sys 1137622906 3572
-sys/src/9/pc/mmu.c - 664 sys sys 1136336093 24152
+sys/src/9/pc/mmu.c - 664 sys sys 1142124315 25229
 sys/src/9/pc/mouse.c - 664 sys sys 1098479254 7057
 sys/src/9/pc/mp.c - 664 sys sys 1131538523 17317
 sys/src/9/pc/mp.h - 664 sys sys 1131538511 6652
@@ -8069,7 +8069,7 @@ sys/src/9/port/chan.c - 664 sys sys 1141940068 34831
 sys/src/9/port/cis.c - 664 sys sys 1099761153 9248
 sys/src/9/port/debugalloc.c - 664 sys sys 1014931171 10402
 sys/src/9/port/dev.c - 664 sys sys 1131289870 8219
-sys/src/9/port/devaudio.c - 664 sys sys 1067722761 21130
+sys/src/9/port/devaudio.c - 664 sys sys 1142086793 21147
 sys/src/9/port/devbridge.c - 664 sys sys 1055688301 24308
 sys/src/9/port/devcap.c - 664 sys sys 1048644215 4113
 sys/src/9/port/devcons.c - 664 sys sys 1139667186 23014
@@ -8085,7 +8085,7 @@ sys/src/9/port/devmntstats.c - 664 sys sys 1014931173 4039
 sys/src/9/port/devmouse.c - 664 sys sys 1130848303 13517
 sys/src/9/port/devpipe.c - 664 sys sys 1077055016 5825
 sys/src/9/port/devpnp.c - 664 sys sys 1088560907 13624
-sys/src/9/port/devproc.c - 664 sys sys 1138469351 28497
+sys/src/9/port/devproc.c - 664 sys sys 1142086847 28500
 sys/src/9/port/devroot.c - 664 sys sys 1067722764 4254
 sys/src/9/port/devsd.c - 664 sys sys 1138458233 30866
 sys/src/9/port/devsdp.c - 664 sys sys 1057323393 44800
@@ -10111,7 +10111,7 @@ sys/src/cmd/ext2srv/xfile.c - 664 sys sys 1055687749 2543
 sys/src/cmd/ext2srv/xfssrv.c - 664 sys sys 1055687749 1292
 sys/src/cmd/faces - 20000000775 sys sys 952888246 0
 sys/src/cmd/faces/dblook.c - 664 sys sys 944961084 359
-sys/src/cmd/faces/facedb.c - 664 sys sys 1139442044 10555
+sys/src/cmd/faces/facedb.c - 664 sys sys 1142086801 10551
 sys/src/cmd/faces/faces.h - 664 sys sys 1072972232 1115
 sys/src/cmd/faces/main.c - 664 sys sys 1106409986 13643
 sys/src/cmd/faces/mkfile - 664 sys sys 1062460262 355

+ 5 - 0
dist/replica/plan9.log

@@ -27988,3 +27988,8 @@
 1142019024 8 c sys/src/cmd/aux/vga/clgd542x.c - 664 sys sys 1142017871 7249
 1142025590 0 c 386/bin/aux/vga - 775 sys sys 1142025580 333840
 1142029825 0 c 386/bin/aux/vga - 775 sys sys 1142028350 333841
+1142087443 0 c sys/src/9/port/devaudio.c - 664 sys sys 1142086793 21147
+1142087443 1 c sys/src/9/port/devproc.c - 664 sys sys 1142086847 28500
+1142087443 2 c sys/src/cmd/faces/facedb.c - 664 sys sys 1142086801 10551
+1142100046 0 c 386/bin/faces - 775 sys sys 1142099815 194163
+1142124411 0 c sys/src/9/pc/mmu.c - 664 sys sys 1142124315 25229

+ 59 - 25
sys/src/9/pc/mmu.c

@@ -195,7 +195,7 @@ flushpg(ulong va)
 	if(X86FAMILY(m->cpuidax) >= 4)
 		invlpg(va);
 	else
-		putcr3(m->tss->cr3);
+		putcr3(getcr3());
 }
 	
 /*
@@ -287,7 +287,6 @@ taskswitch(ulong pdb, ulong stack)
 	tss->esp1 = stack;
 	tss->ss2 = KDSEL;
 	tss->esp2 = stack;
-	tss->cr3 = pdb;
 	putcr3(pdb);
 }
 
@@ -336,8 +335,8 @@ mmurelease(Proc* proc)
 			panic("mmurelease: no mmupdb");
 		if(--proc->kmaptable->ref)
 			panic("mmurelease: kmap ref %d\n", proc->kmaptable->ref);
-		if(up->nkmap)
-			panic("mmurelease: nkmap %d\n", up->nkmap);
+		if(proc->nkmap)
+			panic("mmurelease: nkmap %d\n", proc->nkmap);
 		/*
 		 * remove kmaptable from pdb before putting pdb up for reuse.
 		 */
@@ -379,29 +378,56 @@ upallocpdb(void)
 	ulong *pdb;
 	Page *page;
 	
+	if(up->mmupdb != nil)
+		return;
 	page = mmupdballoc();
 	s = splhi();
+	if(up->mmupdb != nil){
+		/*
+		 * Perhaps we got an interrupt while
+		 * mmupdballoc was sleeping and that
+		 * interrupt allocated an mmupdb?
+		 * Seems unlikely.
+		 */
+		mmupdbfree(up, page);
+		splx(s);
+		return;
+	}
 	pdb = tmpmap(page);
 	pdb[PDX(MACHADDR)] = m->pdb[PDX(MACHADDR)];
 	tmpunmap(pdb);
 	up->mmupdb = page;
-//XXX should have this	m->tss->cr3 = up->mmupdb->pa;
 	putcr3(up->mmupdb->pa);
 	splx(s);
 }
-	
+
 /*
  * Update the mmu in response to a user fault.  pa may have PTEWRITE set.
  */
 void
 putmmu(ulong va, ulong pa, Page*)
 {
-	int old;
+	int old, s;
 	Page *page;
 
 	if(up->mmupdb == nil)
 		upallocpdb();
 
+	/*
+	 * We should be able to get through this with interrupts
+	 * turned on (if we get interrupted we'll just pick up 
+	 * where we left off) but we get many faults accessing
+	 * vpt[] near the end of this function, and they always happen
+	 * after the process has been switched out and then 
+	 * switched back, usually many times in a row (perhaps
+	 * it cannot switch back successfully for some reason).
+	 * 
+	 * In any event, I'm tired of searching for this bug.  
+	 * Turn off interrupts during putmmu even though
+	 * we shouldn't need to.		- rsc
+	 */
+	
+	s = splhi();
 	if(!(vpd[PDX(va)]&PTEVALID)){
 		if(up->mmufree == 0)
 			page = newpage(0, 0, 0);
@@ -422,6 +448,7 @@ putmmu(ulong va, ulong pa, Page*)
 		flushpg(va);
 	if(getcr3() != up->mmupdb->pa)
 		print("bad cr3 %.8lux %.8lux\n", getcr3(), up->mmupdb->pa);
+	splx(s);
 }
 
 /*
@@ -652,8 +679,8 @@ int
 pdbmap(ulong *pdb, ulong pa, ulong va, int size)
 {
 	int pse;
-	ulong pae, pgsz, *pte, *table;
-	ulong flag;
+	ulong pgsz, *pte, *table;
+	ulong flag, off;
 	
 	flag = pa&0xFFF;
 	pa &= ~0xFFF;
@@ -663,30 +690,27 @@ pdbmap(ulong *pdb, ulong pa, ulong va, int size)
 	else
 		pse = 0;
 
-	pae = pa + size;
-	while(pa < pae){
-		table = &pdb[PDX(va)];
+	for(off=0; off<size; off+=pgsz){
+		table = &pdb[PDX(va+off)];
 		if((*table&PTEVALID) && (*table&PTESIZE))
 			panic("vmap: va=%#.8lux pa=%#.8lux pde=%#.8lux",
-				va, pa, *table);
+				va+off, pa+off, *table);
 
 		/*
 		 * Check if it can be mapped using a 4MB page:
 		 * va, pa aligned and size >= 4MB and processor can do it.
 		 */
-		if(pse && pa%(4*MB) == 0 && va%(4*MB) == 0 && (pae >= pa+4*MB)){
-			*table = pa|PTESIZE|flag|PTEVALID;
+		if(pse && (pa+off)%(4*MB) == 0 && (va+off)%(4*MB) == 0 && (size-off) >= 4*MB){
+			*table = (pa+off)|flag|PTESIZE|PTEVALID;
 			pgsz = 4*MB;
 		}else{
-			pte = mmuwalk(pdb, va, 2, 1);
+			pte = mmuwalk(pdb, va+off, 2, 1);
 			if(*pte&PTEVALID)
 				panic("vmap: va=%#.8lux pa=%#.8lux pte=%#.8lux",
-					va, pa, *pte);
-			*pte = pa|flag|PTEVALID;
+					va+off, pa+off, *pte);
+			*pte = (pa+off)|flag|PTEVALID;
 			pgsz = BY2PG;
 		}
-		pa += pgsz;
-		va += pgsz;
 	}
 	return 0;
 }
@@ -774,6 +798,14 @@ kmap(Page *page)
 		panic("kmap: up=0 pc=%#.8lux", getcallerpc(&page));
 	if(up->mmupdb == nil)
 		upallocpdb();
+	if(up->nkmap < 0)
+		panic("kmap %lud %s: nkmap=%d", up->pid, up->text, up->nkmap);
+	
+	/*
+	 * Splhi shouldn't be necessary here, but paranoia reigns.
+	 * See comment in putmmu above.
+	 */
+	s = splhi();
 	up->nkmap++;
 	if(!(vpd[PDX(KMAP)]&PTEVALID)){
 		/* allocate page directory */
@@ -781,15 +813,15 @@ kmap(Page *page)
 			panic("bad kmapsize");
 		if(up->kmaptable != nil)
 			panic("kmaptable");
-		s = spllo();
+		spllo();
 		up->kmaptable = newpage(0, 0, 0);
-		splx(s);
+		splhi();
 		vpd[PDX(KMAP)] = up->kmaptable->pa|PTEWRITE|PTEVALID;
+		flushpg((ulong)kpt);
 		memset(kpt, 0, BY2PG);
-
-		/* might as well finish the job */
 		kpt[0] = page->pa|PTEWRITE|PTEVALID;
 		up->lastkmap = 0;
+		splx(s);
 		return (KMap*)KMAP;
 	}
 	if(up->kmaptable == nil)
@@ -800,6 +832,7 @@ kmap(Page *page)
 			o = (i+o)%NKPT;
 			kpt[o] = page->pa|PTEWRITE|PTEVALID;
 			up->lastkmap = o;
+			splx(s);
 			return (KMap*)(KMAP+o*BY2PG);
 		}
 	}
@@ -820,11 +853,12 @@ kunmap(KMap *k)
 	if(!(vpt[VPTX(va)]&PTEVALID))
 		panic("kunmap: not mapped %#.8lux pc=%#.8lux", va, getcallerpc(&k));
 	up->nkmap--;
+	if(up->nkmap < 0)
+		panic("kunmap %lud %s: nkmap=%d", up->pid, up->text, up->nkmap);
 	vpt[VPTX(va)] = 0;
 	flushpg(va);
 }
 
-
 /*
  * Temporary one-page mapping used to edit page directories.
  *

+ 1 - 0
sys/src/9/port/devaudio.c

@@ -1206,6 +1206,7 @@ audiowrite(Chan *c, void *vp, long n, vlong)
 				audio.filling = 0;
 				swab(b->virt);
 				putbuf(&audio.full, b);
+				pokeaudio();
 			}
 		}
 		poperror();

+ 1 - 1
sys/src/9/port/devproc.c

@@ -1395,7 +1395,7 @@ procctlreq(Proc *p, char *va, int n)
 			p->trace ^= 1;
 			break;
 		case 2:
-			p->trace = atoi(cb->f[1])?1:0;
+			p->trace = (atoi(cb->f[1]) != 0);
 			break;
 		default:
 			error("args");

+ 1 - 1
sys/src/cmd/faces/facedb.c

@@ -275,7 +275,7 @@ tryfindfiledir(char *dom, char *user, char *dir)
 	while((n = dirread(fd, &d)) > 0){
 		for(i=0; i<n; i++){
 			if((d[i].mode&DMDIR)
-			&& strncmp(d[i].name, "512x512x", 8) != 0
+			&& strncmp(d[i].name, "512x", 4) != 0
 			&& strncmp(d[i].name, "48x48x", 6) != 0){
 				ndir = emalloc(strlen(dir)+1+strlen(d[i].name)+1);
 				strcpy(ndir, dir);