xref: /csrg-svn/sys/hp300/DOC/HPMMU.notes (revision 53884)
1*53884ShiblerOverview:
2*53884Shibler--------
3*53884Shibler
4*53884Shibler	(Some of this is gleaned from an article in the September 1986
5*53884Shibler	Hewlett-Packard Journal and info in the July 1987 HP Communicator)
6*53884Shibler
7*53884Shibler	Page and segment table entries mimic the Motorola 68851 PMMU,
8*53884Shibler	in an effort at upward compatibility.  The HP MMU uses a two
9*53884Shibler	level translation scheme.  There are seperate (but equal!)
10*53884Shibler	translation tables for both supervisor and user modes.  At the
11*53884Shibler	lowest level are page tables.  Each page table consists of one
12*53884Shibler	or more 4k pages of 1024x4 byte page table entries.  Each PTE
13*53884Shibler	maps one 4k page of VA space.  At the highest level is the
14*53884Shibler	segment table.  The segment table is a single 4K page of 1024x4
15*53884Shibler	byte entries.  Each entry points to a 4k page of PTEs.  Hence
16*53884Shibler	one STE maps 4Mb of VA space and one page of STEs is sufficient
17*53884Shibler	to map the entire 4Gb address space (what a coincidence!).  The
18*53884Shibler	unused valid bit in page and segment table entries must be
19*53884Shibler	zero.
20*53884Shibler
21*53884Shibler	There are seperate translation lookaside buffers for the user
22*53884Shibler	and supervisor modes, each containing 1024 entries.
23*53884Shibler
24*53884Shibler	To augment the 68020's instruction cache, the HP CPU has an
25*53884Shibler	external cache.  A logical cache implementation is used with 16
26*53884Shibler	Kbytes of cache on 320 systems and 32 Kbytes on 350 systems.
27*53884Shibler	Each cache entry can contain instructions or data, from either
28*53884Shibler	user or supervisor space.  Seperate valid bits are kept for
29*53884Shibler	user and supervisor entries, allowing for descriminatory
30*53884Shibler	flushing of the cache.
31*53884Shibler
32*53884Shibler	MMU translation and cache-miss detection are done in parallel.
33*53884Shibler
34*53884Shibler
35*53884ShiblerSegment table entries:
36*53884Shibler------- ----- -------
37*53884Shibler
38*53884Shibler	bits 31-12:	Physical page frame number of PT page
39*53884Shibler	bits 11-4:	Reserved at zero
40*53884Shibler			(can software use them?)
41*53884Shibler	bit 3:		Reserved at one
42*53884Shibler	bit 2:		Set to 1 if segment is read-only, ow read-write
43*53884Shibler	bits 1-0:	Valid bits
44*53884Shibler			(hardware uses bit 1)
45*53884Shibler
46*53884Shibler
47*53884ShiblerPage table entries:
48*53884Shibler---- ----- -------
49*53884Shibler
50*53884Shibler	bits 31-12:	Physical page frame number of page
51*53884Shibler	bits 11-7:	Available for software use
52*53884Shibler	bit 6:		If 1, inhibits caching of data in this page.
53*53884Shibler			(both instruction and external cache)
54*53884Shibler	bit 5:		Reserved at zero
55*53884Shibler	bit 4:		Hardware modify bit
56*53884Shibler	bit 3:		Hardware reference bit
57*53884Shibler	bit 2:		Set to 1 if page is read-only, ow read-write
58*53884Shibler	bits 1-0:	Valid bits
59*53884Shibler			(hardware uses bit 0)
60*53884Shibler
61*53884Shibler
62*53884ShiblerHardware registers:
63*53884Shibler-------- ---------
64*53884Shibler
65*53884Shibler	The hardware has four longword registers controlling the MMU.
66*53884Shibler	The registers can be accessed as shortwords also (remember to
67*53884Shibler	add 2 to addresses given below).
68*53884Shibler
69*53884Shibler	5F4000:	Supervisor mode segment table pointer.  Loaded (as longword)
70*53884Shibler		with page frame number (i.e. Physaddr >> 12) of the segment
71*53884Shibler		table mapping supervisor space.
72*53884Shibler	5F4004: User mode segment table pointer.  Loaded (as longword) with
73*53884Shibler		page frame number of the segment table mapping user space.
74*53884Shibler	5F4008: TLB control register.  Used to invalid large sections of the
75*53884Shibler		TLB.  More info below.
76*53884Shibler	5F400C:	MMU command/status register.  Defined as follows:
77*53884Shibler
78*53884Shibler		bit 15:	If 1, indicates a page table fault occured
79*53884Shibler		bit 14:	If 1, indicates a page fault occured
80*53884Shibler		bit 13: If 1, indicates a protection fault (write to RO page)
81*53884Shibler		bit 6:	MC68881 enable.  Tied to chip enable line.
82*53884Shibler			(set this bit to enable)
83*53884Shibler		bit 5:	MC68020 instruction cache enable.  Tied to Insruction
84*53884Shibler			cache disable line.  (set this bit to enable)
85*53884Shibler		bit 3:	If 1, indicates an MMU related bus error occured.
86*53884Shibler			Bits 13-15 are now valid.
87*53884Shibler		bit 2:	External cache enable.  (set this bit to enable)
88*53884Shibler		bit 1:	Supervisor mapping enable.  Enables translation of
89*53884Shibler			supervisor space VAs.
90*53884Shibler		bit 0:	User mapping enable.  Enables translation of user
91*53884Shibler			space VAs.
92*53884Shibler
93*53884Shibler
94*53884Shibler	Any bits set by the hardware are cleared only by software.
95*53884Shibler	(i.e. bits 3,13,14,15)
96*53884Shibler
97*53884ShiblerInvalidating TLB:
98*53884Shibler------------ ---
99*53884Shibler
100*53884Shibler	All translations:
101*53884Shibler		Read the TLB control register (5F4008) as a longword.
102*53884Shibler
103*53884Shibler	User translations only:
104*53884Shibler		Write a longword 0 to TLB register or set the user
105*53884Shibler		segment table pointer.
106*53884Shibler
107*53884Shibler	Supervisor translations only:
108*53884Shibler		Write a longword 0x8000 to TLB register or set the
109*53884Shibler		supervisor segment table pointer.
110*53884Shibler
111*53884Shibler	A particular VA translation:
112*53884Shibler		Set destination function code to 3 ("purge" space),
113*53884Shibler		write a longword 0 to the VA whose translation we are to
114*53884Shibler		invalidate, and restore function code.  This apparently
115*53884Shibler		invalidates any translation for that VA in both the user
116*53884Shibler		and supervisor LB.  Here is what I did:
117*53884Shibler
118*53884Shibler		#define FC_PURGE 3
119*53884Shibler		#define FC_USERD 1
120*53884Shibler		_TBIS:
121*53884Shibler			movl	sp@(4),a0	| VA to invalidate
122*53884Shibler			moveq	#FC_PURGE,d0	| change address space
123*53884Shibler			movc	d0,dfc		|   for destination
124*53884Shibler			moveq	#0,d0		| zero to invalidate?
125*53884Shibler			movsl	d0,a0@		| hit it
126*53884Shibler			moveq	#FC_USERD,d0	| back to old
127*53884Shibler			movc	d0,dfc		|   address space
128*53884Shibler			rts			| done
129*53884Shibler
130*53884Shibler
131*53884ShiblerInvalidating the external cache:
132*53884Shibler------------ --- -------- -----
133*53884Shibler
134*53884Shibler	Everything:
135*53884Shibler		Toggle the cache enable bit (bit 2) in the MMU control
136*53884Shibler		register (5F400C).  Can be done by ANDing and ORing the
137*53884Shibler		register location.
138*53884Shibler
139*53884Shibler	User:
140*53884Shibler		Change the user segment table pointer register (5F4004),
141*53884Shibler		i.e. read the current value and write it back.
142*53884Shibler
143*53884Shibler	Supervisor:
144*53884Shibler		Change the supervisor segment table pointer register
145*53884Shibler		(5F4000), i.e. read the current value and write it back.
146