xref: /csrg-svn/sys/hp300/DOC/HPMMU.notes (revision 63155)
153884ShiblerOverview:
253884Shibler--------
353884Shibler
453884Shibler	(Some of this is gleaned from an article in the September 1986
553884Shibler	Hewlett-Packard Journal and info in the July 1987 HP Communicator)
653884Shibler
753884Shibler	Page and segment table entries mimic the Motorola 68851 PMMU,
853884Shibler	in an effort at upward compatibility.  The HP MMU uses a two
953884Shibler	level translation scheme.  There are seperate (but equal!)
1053884Shibler	translation tables for both supervisor and user modes.  At the
1153884Shibler	lowest level are page tables.  Each page table consists of one
1253884Shibler	or more 4k pages of 1024x4 byte page table entries.  Each PTE
1353884Shibler	maps one 4k page of VA space.  At the highest level is the
1453884Shibler	segment table.  The segment table is a single 4K page of 1024x4
1553884Shibler	byte entries.  Each entry points to a 4k page of PTEs.  Hence
1653884Shibler	one STE maps 4Mb of VA space and one page of STEs is sufficient
1753884Shibler	to map the entire 4Gb address space (what a coincidence!).  The
1853884Shibler	unused valid bit in page and segment table entries must be
1953884Shibler	zero.
2053884Shibler
2153884Shibler	There are seperate translation lookaside buffers for the user
2253884Shibler	and supervisor modes, each containing 1024 entries.
2353884Shibler
2453884Shibler	To augment the 68020's instruction cache, the HP CPU has an
25*54012Shibler	external cache.  A direct-mapped, virtual cache implementation
26*54012Shibler	is used with 16 Kbytes of cache on 320 systems and 32 Kbytes on
27*54012Shibler	350 systems.  Each cache entry can contain instructions or data,
28*54012Shibler	from either user or supervisor space.  Seperate valid bits are
29*54012Shibler	kept for user and supervisor entries, allowing for descriminatory
3053884Shibler	flushing of the cache.
3153884Shibler
3253884Shibler	MMU translation and cache-miss detection are done in parallel.
3353884Shibler
3453884Shibler
3553884ShiblerSegment table entries:
3653884Shibler------- ----- -------
3753884Shibler
3853884Shibler	bits 31-12:	Physical page frame number of PT page
3953884Shibler	bits 11-4:	Reserved at zero
4053884Shibler			(can software use them?)
4153884Shibler	bit 3:		Reserved at one
4253884Shibler	bit 2:		Set to 1 if segment is read-only, ow read-write
4353884Shibler	bits 1-0:	Valid bits
4453884Shibler			(hardware uses bit 1)
4553884Shibler
4653884Shibler
4753884ShiblerPage table entries:
4853884Shibler---- ----- -------
4953884Shibler
5053884Shibler	bits 31-12:	Physical page frame number of page
5153884Shibler	bits 11-7:	Available for software use
5253884Shibler	bit 6:		If 1, inhibits caching of data in this page.
5353884Shibler			(both instruction and external cache)
5453884Shibler	bit 5:		Reserved at zero
5553884Shibler	bit 4:		Hardware modify bit
5653884Shibler	bit 3:		Hardware reference bit
5753884Shibler	bit 2:		Set to 1 if page is read-only, ow read-write
5853884Shibler	bits 1-0:	Valid bits
5953884Shibler			(hardware uses bit 0)
6053884Shibler
6153884Shibler
6253884ShiblerHardware registers:
6353884Shibler-------- ---------
6453884Shibler
6553884Shibler	The hardware has four longword registers controlling the MMU.
6653884Shibler	The registers can be accessed as shortwords also (remember to
6753884Shibler	add 2 to addresses given below).
6853884Shibler
6953884Shibler	5F4000:	Supervisor mode segment table pointer.  Loaded (as longword)
7053884Shibler		with page frame number (i.e. Physaddr >> 12) of the segment
7153884Shibler		table mapping supervisor space.
7253884Shibler	5F4004: User mode segment table pointer.  Loaded (as longword) with
7353884Shibler		page frame number of the segment table mapping user space.
7453884Shibler	5F4008: TLB control register.  Used to invalid large sections of the
7553884Shibler		TLB.  More info below.
7653884Shibler	5F400C:	MMU command/status register.  Defined as follows:
7753884Shibler
7853884Shibler		bit 15:	If 1, indicates a page table fault occured
7953884Shibler		bit 14:	If 1, indicates a page fault occured
8053884Shibler		bit 13: If 1, indicates a protection fault (write to RO page)
8153884Shibler		bit 6:	MC68881 enable.  Tied to chip enable line.
8253884Shibler			(set this bit to enable)
8353884Shibler		bit 5:	MC68020 instruction cache enable.  Tied to Insruction
8453884Shibler			cache disable line.  (set this bit to enable)
8553884Shibler		bit 3:	If 1, indicates an MMU related bus error occured.
8653884Shibler			Bits 13-15 are now valid.
8753884Shibler		bit 2:	External cache enable.  (set this bit to enable)
8853884Shibler		bit 1:	Supervisor mapping enable.  Enables translation of
8953884Shibler			supervisor space VAs.
9053884Shibler		bit 0:	User mapping enable.  Enables translation of user
9153884Shibler			space VAs.
9253884Shibler
9353884Shibler
9453884Shibler	Any bits set by the hardware are cleared only by software.
9553884Shibler	(i.e. bits 3,13,14,15)
9653884Shibler
9753884ShiblerInvalidating TLB:
9853884Shibler------------ ---
9953884Shibler
10053884Shibler	All translations:
10153884Shibler		Read the TLB control register (5F4008) as a longword.
10253884Shibler
10353884Shibler	User translations only:
10453884Shibler		Write a longword 0 to TLB register or set the user
10553884Shibler		segment table pointer.
10653884Shibler
10753884Shibler	Supervisor translations only:
10853884Shibler		Write a longword 0x8000 to TLB register or set the
10953884Shibler		supervisor segment table pointer.
11053884Shibler
11153884Shibler	A particular VA translation:
11253884Shibler		Set destination function code to 3 ("purge" space),
11353884Shibler		write a longword 0 to the VA whose translation we are to
11453884Shibler		invalidate, and restore function code.  This apparently
11553884Shibler		invalidates any translation for that VA in both the user
11653884Shibler		and supervisor LB.  Here is what I did:
11753884Shibler
11853884Shibler		#define FC_PURGE 3
11953884Shibler		#define FC_USERD 1
12053884Shibler		_TBIS:
12153884Shibler			movl	sp@(4),a0	| VA to invalidate
12253884Shibler			moveq	#FC_PURGE,d0	| change address space
12353884Shibler			movc	d0,dfc		|   for destination
12453884Shibler			moveq	#0,d0		| zero to invalidate?
12553884Shibler			movsl	d0,a0@		| hit it
12653884Shibler			moveq	#FC_USERD,d0	| back to old
12753884Shibler			movc	d0,dfc		|   address space
12853884Shibler			rts			| done
12953884Shibler
13053884Shibler
13153884ShiblerInvalidating the external cache:
13253884Shibler------------ --- -------- -----
13353884Shibler
13453884Shibler	Everything:
13553884Shibler		Toggle the cache enable bit (bit 2) in the MMU control
13653884Shibler		register (5F400C).  Can be done by ANDing and ORing the
13753884Shibler		register location.
13853884Shibler
13953884Shibler	User:
14053884Shibler		Change the user segment table pointer register (5F4004),
14153884Shibler		i.e. read the current value and write it back.
14253884Shibler
14353884Shibler	Supervisor:
14453884Shibler		Change the supervisor segment table pointer register
14553884Shibler		(5F4000), i.e. read the current value and write it back.
146