; This file belongs to FreeMiNT.  It's not in the original MiNT 1.12
; distribution.  See the file Changes.MH for a detailed log of changes.

;
; set_mmu(crp,tc): called once, the first time a page table is built, to 
; switch away from the MMU setup that came from the ROM and into the setup 
; that we just built.  The CRP is actually on the stack, and it's 8 bytes.
; The TC is four bytes at sp@(0xc).  "Nulls" is here because we need to
; shove zeros into a few places.
;
%ifndef MMU040
	DATA
nulltc:	dc.l	0

	TEXT

	XDEF	_set_mmu

_set_mmu:
	pflusha
	pmove	(nulltc).l,tc		; turn off mmu
	dc.l	$f0390800,nulltc	; pmove nulltc,tt0
	dc.l	$f0390c00,nulltc	; pmove nulltc,tt1
	pmove	4(sp),crp		; caution: crp is 8 bytes
	pmove	$c(sp),tc
	rts

;
; save_mmu, restr_mmu: save and restore the MMU setup that came from ROM
;
	BSS
oldcrp:	ds.l	1
	ds.l	1
oldtc:	ds.l	1
oldtt0:	ds.l	1
oldtt1:	ds.l	1

	TEXT

	XDEF	_save_mmu

_save_mmu:
	pmove	tc,oldtc
	dc.l	$f0390a00,oldtt0	; pmove	tt0,oldtt0
	dc.l	$f0390e00,oldtt1	; pmove	tt1,oldtt1
	pmove	crp,oldcrp
	rts


	XDEF	_restr_mmu

_restr_mmu:
	pmove	(nulltc).l,tc
	dc.l	$f0390800,oldtt0	; pmove	oldtt0,tt0
	dc.l	$f0390c00,oldtt1	; pmove	oldtt1,tt1
	pmove	oldcrp,crp
	pmove	oldtc,tc
	rts


	XDEF	_flush_mmu

_flush_mmu:
	pflusha
	rts

%else
	; it seems GNU ld doesn't like completely empty object files
	TEXT
	XDEF	mmu030dummy

mmu030dummy:
	nop

%endif
