#include "targetsys.h"
.file "asmcode68.s"
.text
.global asmput8,asmput16,asmput32,asmget8,asmget16,asmget32
.global putmpu,regdata,asmaddr,asmdata

.equ		RPC,		0
.equ		RSR,		4
.equ		RUSP,		8
.equ		RMSP,		12
.equ		RISP,		16
.equ		RVBR,		20
.equ		RCACR,		24
.equ		RCAAR,		28
.equ		RSFC,		32
.equ		RDFC,		36
.equ		RD0,		40
#if(DEVICE==68030)
.equ		SCRP,		104
.equ		SSRP,		112
.equ		STC,		120
.equ		STT0,		124
.equ		STT1,		128
.equ		SMMUSR,		134
#endif
#if(DEVICE==68040)
.equ		SURP,		104
.equ		SSRP,		112
.equ		STC,		120
.equ		SDTT0,		124
.equ		SDTT1,		128
.equ		SITT0,		132
.equ		SITT1,		136
.equ		SMMUSR,		142
#endif
#if(DEVICE==68040 || COPROCESSOR==TRUE)
.equ		FPCR,		144
.equ		FPSR,		148
.equ		FPIAR,		152
.equ		FP0,		156
#endif

#if(DEVICE>68010)
asmput8: 	mov.b	asmdata+3,([asmaddr])
			rts

asmput16: 	mov.w	asmdata+2,([asmaddr])
		rts

asmput32: 	mov.l	asmdata,([asmaddr])
		rts

asmget8: 	clr.l	asmdata
		mov.b	([asmaddr]),asmdata+3
		bpl.b 	nosi8
		or.l   	&0xffffff00,asmdata
nosi8:		rts

asmget16: 	clr.l	asmdata
		mov.w	([asmaddr]),asmdata+2
		bpl.b 	nosi16
		or.l   	&0xffff0000,asmdata
nosi16:		rts

asmget32: 	mov.l	([asmaddr]),asmdata
		rts
#else

asmput8: 	mov.l	%a0,-(%sp)
		mov.l	asmaddr,%a0
		mov.b	asmdata+3,(%a0)
		mov.l	(%sp)+,%a0
		rts

asmput16: 	mov.l	%a0,-(%sp)
		mov.l	asmaddr,%a0
		mov.w	asmdata+2,(%a0)
		mov.l	(%sp)+,%a0
		rts

asmput32: 	mov.l	%a0,-(%sp)
		mov.l	asmaddr,%a0
		mov.l	asmdata,(%a0)
		mov.l	(%sp)+,%a0
		rts

asmget8: 	clr.l	asmdata
		mov.l	%a0,-(%sp)
		mov.l	asmaddr,%a0
		mov.b	(%a0),asmdata+3
		bpl.b 	nosi8
		or.l   	&0xffffff00,asmdata
nosi8:		mov.l	(%sp)+,%a0
		rts

asmget16: 	clr.l	asmdata
		mov.l	%a0,-(%sp)
		mov.l	asmaddr,%a0
		mov.w	(%a0),asmdata+2
		bpl.b 	nosi16
		or.l   	&0xffff0000,asmdata
nosi16:		mov.l	(%sp)+,%a0
		rts

asmget32: 	mov.l	%a0,-(%sp)
		mov.l	asmaddr,%a0
		mov.l	(%a0),asmdata
		mov.l	(%sp)+,%a0
		rts

#endif


putmpu:		
		mov.l	(regdata+RUSP),%d0
#if(DEVICE>=68010)
		mov.l	(regdata+RVBR),%d1
#endif
#if(DEVICE==68010)
		mov.l	(regdata+RISP),%a7
#endif
#if(DEVICE>=68020)
		mov.l	(regdata+RISP),%d2
		mov.l	(regdata+RMSP),%d3
		mov.l	(regdata+RCAAR),%d4
		mov.l	(regdata+RCACR),%d5
		mov.l	(regdata+RSFC),%d6
		mov.l	(regdata+RDFC),%d7
#endif
		movec.l	%d0,%usp
#if(DEVICE>=68010)
		movec.l	%d1,%vbr
#endif
#if(DEVICE>=68020)
		movec.l	%d2,%isp
		movec.l	%d3,%msp
		movec.l	%d4,%caar
		movec.l	%d5,%cacr
		movec.l	%d6,%sfc
		movec.l	%d7,%dfc
#endif
#if(DEVICE==68030)
		lea.l 	(regdata+SCRP),%a0
		short	0xf010
		short	0x4c00		#pmove (a0),crp
		lea.l 	(regdata+SSRP),%a0
		short	0xf010
		short	0x4800		#pmove (a0),srp
		lea.l 	(regdata+STC),%a0
		short	0xf010
		short	0x4000		#pmove (a0),tc
		lea.l 	(regdata+STT0),%a0
		short	0xf010
		short	0x0800		#pmove (a0),tt0
		lea.l 	(regdata+STT1),%a0
		short	0xf010
		short	0x0c00		#pmove (a0),tt1
		lea.l 	(regdata+SMMUSR),%a0
		short	0xf010
		short	0x6000		#pmove (a0),psr
#endif
#if(DEVICE==68040)
					#68040 instructions to effect supervisor
					#programer model support should be
					#inserted here and below !
#endif
#if(DEVICE==68040 || COPROCESSOR==TRUE)
		lea.l 	(regdata+FPCR),%a0
		short	0xf210
		short	0x9000 		#fmove.x (a0),fpcr
		lea.l 	(regdata+FPSR),%a0
		short	0xf210
		short	0x8800 		#fmove.x (a0),fpsr
		lea.l 	(regdata+FPIAR),%a0
		short	0xf210
		short	0x8400 		#fmove.x (a0),fpiar
		lea.l 	(regdata+FP0),%a0
		short	0xf210
		short	0xd0ff 		#fmovem.x (a0),fp0-fp7
#endif
		mov.w	&0x0024,-(%a7)
		mov.l	(regdata+RPC),-(%a7)
		mov.l	(regdata+RSR),%d0
		mov.w	%d0,-(%a7)
		movm.l	(regdata+RD0),&0x7fff
		rte

