Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/gnot/mmu.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname gnot/mmu.c 1990/03091
## diff -e /dev/null /n/bootesdump/1990/03091/sys/src/9/68020/mmu.c
0a
#include	"u.h"
#include	"lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"

/*
 * Called splhi, not in Running state
 */
void
mapstack(Proc *p)
{
	ulong tlbvirt, tlbphys;

	if(p->upage->va != (USERADDR|(p->pid&0xFFFF)))
		panic("mapstack %d 0x%lux 0x%lux", p->pid, p->upage->pa, p->upage->va);
	tlbvirt = USERADDR;
	tlbphys = PPN(p->upage->pa) | PTEVALID | PTEKERNEL;
	putkmmu(tlbvirt, tlbphys);
	flushmmu();
	u = (User*)USERADDR;
}

void
putkmmu(ulong tlbvirt, ulong tlbphys)
{
	if(!(tlbvirt&KZERO))
		panic("putkmmu");
	tlbvirt &= ~KZERO;
	KMAP[(tlbvirt&0x003FE000L)>>2] = tlbphys;
}

void
putmmu(ulong tlbvirt, ulong tlbphys)
{
	if(tlbvirt&KZERO)
		panic("putmmu");
	tlbphys |= VTAG(tlbvirt)<<24;
	UMAP[(tlbvirt&0x003FE000L)>>2] = tlbphys;
}

void
flushmmu(void)
{
	flushcpucache();
	*PARAM &= ~TLBFLUSH_;
	*PARAM |= TLBFLUSH_;
}
.
## diffname gnot/mmu.c 1990/06021
## diff -e /n/bootesdump/1990/03091/sys/src/9/68020/mmu.c /n/bootesdump/1990/06021/sys/src/9/68020/mmu.c
47a
}

void
kmapinit(void)
{
	KMap *k;
	int i, e;

	if(kmapalloc.init == 0){
		k = &kmapalloc.arena[0];
		k->va = KZERO|(3*1024*1024);
		k->next = 0;
		kmapalloc.free = k;
		kmapalloc.init = 1;
		return;
	}
	e = (4*1024*1024 - 256*1024)/BY2PG;	/* screen lives at top 256K */
	i = (((ulong)ialloc(0, 0))&~KZERO)/BY2PG;
print("kmapinit %d", i);
	kmapalloc.free = 0;
	for(k=&kmapalloc.arena[i]; i<e; i++,k++){
		k->va = i*BY2PG|KZERO;
		kunmap(k);
	}
}

KMap*
kmap(Page *pg)
{
	KMap *k;

	lock(&kmapalloc);
	k = kmapalloc.free;
	if(k == 0)
		panic("kmap");
	kmapalloc.free = k->next;
	unlock(&kmapalloc);
	k->pa = pg->pa;
	putkmmu(k->va, PPN(k->pa) | PTEVALID | PTEKERNEL);
	return k;
}

void
kunmap(KMap *k)
{
	k->pa = 0;
	lock(&kmapalloc);
	k->next = kmapalloc.free;
	kmapalloc.free = k;
	putkmmu(k->va, INVALIDPTE);
	unlock(&kmapalloc);
.
6a
struct
{
	Lock;
	int	init;
	KMap	*free;
	KMap	arena[4*1024*1024/BY2PG];	/* kernel mmu maps up to 4MB */
}kmapalloc;

.
## diffname gnot/mmu.c 1990/0603
## diff -e /n/bootesdump/1990/06021/sys/src/9/68020/mmu.c /n/bootesdump/1990/0603/sys/src/9/68020/mmu.c
74d
## diffname gnot/mmu.c 1990/0709
## diff -e /n/bootesdump/1990/0603/sys/src/9/68020/mmu.c /n/bootesdump/1990/0709/sys/src/9/68020/mmu.c
89a
	}
.
88c
	if(k == 0){
		dumpstack();
.
73a
	print("%lud free map registers\n", e-i);
.
66c
		k->va = KZERO|(4*1024*1024-256*1024-BY2PG);
.
## diffname gnot/mmu.c 1990/0921
## diff -e /n/bootesdump/1990/0709/sys/src/9/68020/mmu.c /n/bootesdump/1990/0921/sys/src/9/68020/mmu.c
55a
}

void
flushmmucache(void)
{
	if(u == 0)
		panic("flushmmucache");
	u->mc.next = 0;
}

void
clearmmucache(void)
{
	if(u == 0)
		panic("clearmmucache");
	memset(&u->mc, 0, sizeof u->mc);
.
45a
	if(u){
		MMU *mp;
		mp = &(u->mc.mmu[u->mc.next&(NMMU-1)]);
		mp->pa = tlbphys;
		mp->va = tlbvirt;
		mp->pid = u->p->pid;
		u->mc.next++;
	}/**/
.
29a

	if(u->mc.next >= NMMU){
		u->mc.next &= NMMU - 1;
		for(i = u->mc.next; i < NMMU; i++)
			putxmmu(u->mc.mmu[i].va, u->mc.mmu[i].pa, u->mc.mmu[i].pid);
	}
	for(i = 0; i < u->mc.next; i++)
		putxmmu(u->mc.mmu[i].va, u->mc.mmu[i].pa, u->mc.mmu[i].pid);/**/
.
21a
	ulong i;
.
14a
void
putxmmu(ulong tlbvirt, ulong tlbphys, int pid)
{
	if(pid != u->p->pid)
		panic("putxmmu %ld %ld\n", pid, u->p->pid);
	if(tlbvirt&KZERO)
		panic("putmmu");
	tlbphys |= VTAG(tlbvirt)<<24;
	UMAP[(tlbvirt&0x003FE000L)>>2] = tlbphys;
}

.
## diffname gnot/mmu.c 1990/0925
## diff -e /n/bootesdump/1990/0921/sys/src/9/68020/mmu.c /n/bootesdump/1990/0925/sys/src/9/68020/mmu.c
92,99d
87c
clearmmucache(void)
.
73c
	}
.
49c
		putxmmu(u->mc.mmu[i].va, u->mc.mmu[i].pa, u->mc.mmu[i].pid);
.
42a
	/*
 	 *  preload the MMU with the last (up to) NMMU user entries
	 *  previously faulted into it for this process.
	 */
.
## diffname gnot/mmu.c 1990/0928
## diff -e /n/bootesdump/1990/0925/sys/src/9/68020/mmu.c /n/bootesdump/1990/0928/sys/src/9/68020/mmu.c
88,95d
70,77d
42,53d
15,25d
## diffname gnot/mmu.c 1990/1004
## diff -e /n/bootesdump/1990/0928/sys/src/9/68020/mmu.c /n/bootesdump/1990/1004/sys/src/9/68020/mmu.c
56a
}

void
clearmmucache(void)
{
	if(u == 0)
		panic("flushmmucache");
	u->mc.next = 0;
.
48c
	tlbvirt = (tlbvirt&0x003FE000L)>>2;
	if(u){
		MMU *mp;
		int s;

		s = splhi();
		mp = &(u->mc.mmu[u->mc.next&(NMMU-1)]);
		mp->pa = tlbphys;
		mp->va = tlbvirt;
		u->mc.next++;
		splx(s);
	}
	UMAP[tlbvirt] = tlbphys;
.
29,30c

	/*
	 *  if not a kernel process and this process was not the 
	 *  last process on this machine, flush & preload mmu
	 */
	if(!p->kp && p!=m->lproc){
		flushmmu();

		/*
		 *  preload the MMU with the last (up to) NMMU user entries
		 *  previously faulted into it for this process.
		 */
		mn = &u->mc.mmu[u->mc.next&(NMMU-1)];
		me = &u->mc.mmu[NMMU];
		if(u->mc.next >= NMMU){
			for(mm = mn; mm < me; mm++)
				UMAP[mm->va] = mm->pa;
		}
		for(mm = u->mc.mmu; mm < mn; mm++)
			UMAP[mm->va] = mm->pa;

		m->lproc = p;
	}
.
22c
	ulong next;
	MMU *mm, *mn, *me;
.
## diffname gnot/mmu.c 1990/1211
## diff -e /n/bootesdump/1990/1004/sys/src/9/68020/mmu.c /n/bootesdump/1990/1211/sys/src/9/68020/mmu.c
151a
}

void
invalidateu(void)
{
	putkmmu(USERADDR, INVALIDPTE);
.
29a
	u = (User*)USERADDR;
.
## diffname gnot/mmu.c 1991/0507
## diff -e /n/bootesdump/1991/0201/sys/src/9/68020/mmu.c /n/bootesdump/1991/0507/sys/src/9/gnot/mmu.c
56a
mmurelease(Proc *p)
{
	USED(p);
}

void
.
## diffname gnot/mmu.c 1991/0705
## diff -e /n/bootesdump/1991/0507/sys/src/9/gnot/mmu.c /n/bootesdump/1991/0705/sys/src/9/gnot/mmu.c
104c
		panic("clearmmucache");
.
72c
putmmu(ulong tlbvirt, ulong tlbphys, Page *p)
.
31a
	if(p->newtlb) {
		flushmmu();
		clearmmucache();
		p->newtlb = 0;
	}

.
24a

.
## diffname gnot/mmu.c 1991/0802
## diff -e /n/bootesdump/1991/0705/sys/src/9/gnot/mmu.c /n/bootesdump/1991/0802/sys/src/9/gnot/mmu.c
130c
	i = PGROUND(((ulong)ialloc(0, 0))&~KZERO)/BY2PG;
.
## diffname gnot/mmu.c 1991/0817
## diff -e /n/bootesdump/1991/0802/sys/src/9/gnot/mmu.c /n/bootesdump/1991/0817/sys/src/9/gnot/mmu.c
153a
	if(u && u->p)
		u->p->state = s;
.
143a
	if(u && u->p){
		s = u->p->state;
		u->p->state = MMUing;
	}
.
142a
	int s;
.
## diffname gnot/mmu.c 1991/0821
## diff -e /n/bootesdump/1991/0817/sys/src/9/gnot/mmu.c /n/bootesdump/1991/0821/sys/src/9/gnot/mmu.c
171d
167a
	putkmmu(k->va, INVALIDPTE);

.
159,160d
156a

.
145,148d
143d
131a

.
130a

.
129c

	e = (MB4 - 256*1024)/BY2PG;	/* screen lives at top 256K */
.
123c
		k->va = KZERO|(MB4-256*1024-BY2PG);
.
12c
	KMap	arena[MB4/BY2PG];	/* kernel mmu maps up to 4MB */
.
## diffname gnot/mmu.c 1991/0827
## diff -e /n/bootesdump/1991/0821/sys/src/9/gnot/mmu.c /n/bootesdump/1991/0827/sys/src/9/gnot/mmu.c
170a
	splx(s);
.
166a
	s = splhi();
.
163a
	int s;

.
154a
	splx(s);
.
146a
	s = splhi();
.
145a
	int s;
.
## diffname gnot/mmu.c 1991/0828
## diff -e /n/bootesdump/1991/0827/sys/src/9/gnot/mmu.c /n/bootesdump/1991/0828/sys/src/9/gnot/mmu.c
160a
	if(s)
		u->p->state = s;

.
157d
148c
	if(u) {
		s = u->p->state;
		u->p->state = MMUing;
	}
	
.
146c
	int s = 0;
.
## diffname gnot/mmu.c 1991/0926
## diff -e /n/bootesdump/1991/0828/sys/src/9/gnot/mmu.c /n/bootesdump/1991/0926/sys/src/9/gnot/mmu.c
164,165d
146,151d
## diffname gnot/mmu.c 1991/0928
## diff -e /n/bootesdump/1991/0926/sys/src/9/gnot/mmu.c /n/bootesdump/1991/0928/sys/src/9/gnot/mmu.c
26c
	if(p->upage->va != (USERADDR|(p->pid&0xFFFF)) && p->pid != 0)
.
## diffname gnot/mmu.c 1991/1004
## diff -e /n/bootesdump/1991/0928/sys/src/9/gnot/mmu.c /n/bootesdump/1991/1004/sys/src/9/gnot/mmu.c
154a
	splx(s);
.
146c
	int s;

	s = splhi();
.
## diffname gnot/mmu.c 1992/0103
## diff -e /n/bootesdump/1991/1004/sys/src/9/gnot/mmu.c /n/bootesdump/1992/0103/sys/src/9/gnot/mmu.c
105,112d
85,95d
45,58d
35d
## diffname gnot/mmu.c 1992/0315
## diff -e /n/bootesdump/1992/0103/sys/src/9/gnot/mmu.c /n/bootesdump/1992/0315/sys/src/9/gnot/mmu.c
97c
	i = PGROUND(palloc.addr0)/BY2PG;
.
## diffname gnot/mmu.c 1992/0321
## diff -e /n/bootesdump/1992/0315/sys/src/9/gnot/mmu.c /n/bootesdump/1992/0321/sys/src/9/gnot/mmu.c
2c
#include	"../port/lib.h"
.
## diffname gnot/mmu.c 1992/0622
## diff -e /n/bootesdump/1992/0321/sys/src/9/gnot/mmu.c /n/bootesdump/1992/0622/sys/src/9/gnot/mmu.c
104c
		kunmap(k++);
.
102c
	for(k=&kmapalloc.arena[i]; i < e; i++){
.
## diffname gnot/mmu.c 1992/0625
## diff -e /n/bootesdump/1992/0622/sys/src/9/gnot/mmu.c /n/bootesdump/1992/0625/sys/src/9/gnot/mmu.c
105a
	print("%lud free map registers\n", i);
.
96,104c
	i = 0;
	/* Reclaim map register for pages in bank0 */
	for(p = palloc.head; p; p = p->next) {
		if(p->pa < MB4) {
			k = &kmapalloc.arena[p->pa/BY2PG];
			k->va = p->pa|KZERO;
			kunmap(k);
			i++;
		}
.
85d
83a
	int i;
	Page *p;
.
## diffname gnot/mmu.c 1992/0630
## diff -e /n/bootesdump/1992/0625/sys/src/9/gnot/mmu.c /n/bootesdump/1992/0630/sys/src/9/gnot/mmu.c
100c
		if(p->pa >= endscreen && p->pa < MB4) {
.
98c
	/*
	 * Reclaim map register for pages in bank0;
	 * screen is in virtual space overlaying physical pages; be careful
	 */
	endscreen = (PGROUND((ulong)end)&~KZERO) + 256*1024;
.
90c
		k->va = KZERO|(MB4-BY2PG);
.
84a
	ulong endscreen;
.
## diffname gnot/mmu.c 1992/0711
## diff -e /n/bootesdump/1992/0630/sys/src/9/gnot/mmu.c /n/bootesdump/1992/0711/sys/src/9/gnot/mmu.c
65a
	USED(pg);
.
64c
putmmu(ulong tlbvirt, ulong tlbphys, Page *pg)
.
22,23d
## diffname gnot/mmu.c 1993/0501 # deleted
## diff -e /n/bootesdump/1992/0711/sys/src/9/gnot/mmu.c /n/fornaxdump/1993/0501/sys/src/brazil/gnot/mmu.c
1,157d

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.