xref: /OK3568_Linux_fs/kernel/arch/m68k/fpsp040/x_store.S (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun|
2*4882a593Smuzhiyun|	x_store.sa 3.2 1/24/91
3*4882a593Smuzhiyun|
4*4882a593Smuzhiyun|	store --- store operand to memory or register
5*4882a593Smuzhiyun|
6*4882a593Smuzhiyun|	Used by underflow and overflow handlers.
7*4882a593Smuzhiyun|
8*4882a593Smuzhiyun|	a6 = points to fp value to be stored.
9*4882a593Smuzhiyun|
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun|		Copyright (C) Motorola, Inc. 1990
12*4882a593Smuzhiyun|			All Rights Reserved
13*4882a593Smuzhiyun|
14*4882a593Smuzhiyun|       For details on the license for this file, please see the
15*4882a593Smuzhiyun|       file, README, in this same directory.
16*4882a593Smuzhiyun
17*4882a593SmuzhiyunX_STORE:	|idnt    2,1 | Motorola 040 Floating Point Software Package
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun	|section	8
20*4882a593Smuzhiyun
21*4882a593Smuzhiyunfpreg_mask:
22*4882a593Smuzhiyun	.byte	0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun#include "fpsp.h"
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun	|xref	mem_write
27*4882a593Smuzhiyun	|xref	get_fline
28*4882a593Smuzhiyun	|xref	g_opcls
29*4882a593Smuzhiyun	|xref	g_dfmtou
30*4882a593Smuzhiyun	|xref	reg_dest
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun	.global	dest_ext
33*4882a593Smuzhiyun	.global	dest_dbl
34*4882a593Smuzhiyun	.global	dest_sgl
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun	.global	store
37*4882a593Smuzhiyunstore:
38*4882a593Smuzhiyun	btstb	#E3,E_BYTE(%a6)
39*4882a593Smuzhiyun	beqs	E1_sto
40*4882a593SmuzhiyunE3_sto:
41*4882a593Smuzhiyun	movel	CMDREG3B(%a6),%d0
42*4882a593Smuzhiyun	bfextu	%d0{#6:#3},%d0		|isolate dest. reg from cmdreg3b
43*4882a593Smuzhiyunsto_fp:
44*4882a593Smuzhiyun	lea	fpreg_mask,%a1
45*4882a593Smuzhiyun	moveb	(%a1,%d0.w),%d0		|convert reg# to dynamic register mask
46*4882a593Smuzhiyun	tstb	LOCAL_SGN(%a0)
47*4882a593Smuzhiyun	beqs	is_pos
48*4882a593Smuzhiyun	bsetb	#sign_bit,LOCAL_EX(%a0)
49*4882a593Smuzhiyunis_pos:
50*4882a593Smuzhiyun	fmovemx (%a0),%d0		|move to correct register
51*4882a593Smuzhiyun|
52*4882a593Smuzhiyun|	if fp0-fp3 is being modified, we must put a copy
53*4882a593Smuzhiyun|	in the USER_FPn variable on the stack because all exception
54*4882a593Smuzhiyun|	handlers restore fp0-fp3 from there.
55*4882a593Smuzhiyun|
56*4882a593Smuzhiyun	cmpb	#0x80,%d0
57*4882a593Smuzhiyun	bnes	not_fp0
58*4882a593Smuzhiyun	fmovemx %fp0-%fp0,USER_FP0(%a6)
59*4882a593Smuzhiyun	rts
60*4882a593Smuzhiyunnot_fp0:
61*4882a593Smuzhiyun	cmpb	#0x40,%d0
62*4882a593Smuzhiyun	bnes	not_fp1
63*4882a593Smuzhiyun	fmovemx %fp1-%fp1,USER_FP1(%a6)
64*4882a593Smuzhiyun	rts
65*4882a593Smuzhiyunnot_fp1:
66*4882a593Smuzhiyun	cmpb	#0x20,%d0
67*4882a593Smuzhiyun	bnes	not_fp2
68*4882a593Smuzhiyun	fmovemx %fp2-%fp2,USER_FP2(%a6)
69*4882a593Smuzhiyun	rts
70*4882a593Smuzhiyunnot_fp2:
71*4882a593Smuzhiyun	cmpb	#0x10,%d0
72*4882a593Smuzhiyun	bnes	not_fp3
73*4882a593Smuzhiyun	fmovemx %fp3-%fp3,USER_FP3(%a6)
74*4882a593Smuzhiyun	rts
75*4882a593Smuzhiyunnot_fp3:
76*4882a593Smuzhiyun	rts
77*4882a593Smuzhiyun
78*4882a593SmuzhiyunE1_sto:
79*4882a593Smuzhiyun	bsrl	g_opcls		|returns opclass in d0
80*4882a593Smuzhiyun	cmpib	#3,%d0
81*4882a593Smuzhiyun	beq	opc011		|branch if opclass 3
82*4882a593Smuzhiyun	movel	CMDREG1B(%a6),%d0
83*4882a593Smuzhiyun	bfextu	%d0{#6:#3},%d0	|extract destination register
84*4882a593Smuzhiyun	bras	sto_fp
85*4882a593Smuzhiyun
86*4882a593Smuzhiyunopc011:
87*4882a593Smuzhiyun	bsrl	g_dfmtou	|returns dest format in d0
88*4882a593Smuzhiyun|				;ext=00, sgl=01, dbl=10
89*4882a593Smuzhiyun	movel	%a0,%a1		|save source addr in a1
90*4882a593Smuzhiyun	movel	EXC_EA(%a6),%a0	|get the address
91*4882a593Smuzhiyun	cmpil	#0,%d0		|if dest format is extended
92*4882a593Smuzhiyun	beq	dest_ext	|then branch
93*4882a593Smuzhiyun	cmpil	#1,%d0		|if dest format is single
94*4882a593Smuzhiyun	beq	dest_sgl	|then branch
95*4882a593Smuzhiyun|
96*4882a593Smuzhiyun|	fall through to dest_dbl
97*4882a593Smuzhiyun|
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun|
100*4882a593Smuzhiyun|	dest_dbl --- write double precision value to user space
101*4882a593Smuzhiyun|
102*4882a593Smuzhiyun|Input
103*4882a593Smuzhiyun|	a0 -> destination address
104*4882a593Smuzhiyun|	a1 -> source in extended precision
105*4882a593Smuzhiyun|Output
106*4882a593Smuzhiyun|	a0 -> destroyed
107*4882a593Smuzhiyun|	a1 -> destroyed
108*4882a593Smuzhiyun|	d0 -> 0
109*4882a593Smuzhiyun|
110*4882a593Smuzhiyun|Changes extended precision to double precision.
111*4882a593Smuzhiyun| Note: no attempt is made to round the extended value to double.
112*4882a593Smuzhiyun|	dbl_sign = ext_sign
113*4882a593Smuzhiyun|	dbl_exp = ext_exp - $3fff(ext bias) + $7ff(dbl bias)
114*4882a593Smuzhiyun|	get rid of ext integer bit
115*4882a593Smuzhiyun|	dbl_mant = ext_mant{62:12}
116*4882a593Smuzhiyun|
117*4882a593Smuzhiyun|		---------------   ---------------    ---------------
118*4882a593Smuzhiyun|  extended ->  |s|    exp    |   |1| ms mant   |    | ls mant     |
119*4882a593Smuzhiyun|		---------------   ---------------    ---------------
120*4882a593Smuzhiyun|		 95	    64    63 62	      32      31     11	  0
121*4882a593Smuzhiyun|				     |			     |
122*4882a593Smuzhiyun|				     |			     |
123*4882a593Smuzhiyun|				     |			     |
124*4882a593Smuzhiyun|			             v			     v
125*4882a593Smuzhiyun|			      ---------------   ---------------
126*4882a593Smuzhiyun|  double   ->		      |s|exp| mant  |   |  mant       |
127*4882a593Smuzhiyun|			      ---------------   ---------------
128*4882a593Smuzhiyun|			      63     51   32   31	       0
129*4882a593Smuzhiyun|
130*4882a593Smuzhiyundest_dbl:
131*4882a593Smuzhiyun	clrl	%d0		|clear d0
132*4882a593Smuzhiyun	movew	LOCAL_EX(%a1),%d0	|get exponent
133*4882a593Smuzhiyun	subw	#0x3fff,%d0	|subtract extended precision bias
134*4882a593Smuzhiyun	cmpw	#0x4000,%d0	|check if inf
135*4882a593Smuzhiyun	beqs	inf		|if so, special case
136*4882a593Smuzhiyun	addw	#0x3ff,%d0	|add double precision bias
137*4882a593Smuzhiyun	swap	%d0		|d0 now in upper word
138*4882a593Smuzhiyun	lsll	#4,%d0		|d0 now in proper place for dbl prec exp
139*4882a593Smuzhiyun	tstb	LOCAL_SGN(%a1)
140*4882a593Smuzhiyun	beqs	get_mant	|if positive, go process mantissa
141*4882a593Smuzhiyun	bsetl	#31,%d0		|if negative, put in sign information
142*4882a593Smuzhiyun|				; before continuing
143*4882a593Smuzhiyun	bras	get_mant	|go process mantissa
144*4882a593Smuzhiyuninf:
145*4882a593Smuzhiyun	movel	#0x7ff00000,%d0	|load dbl inf exponent
146*4882a593Smuzhiyun	clrl	LOCAL_HI(%a1)	|clear msb
147*4882a593Smuzhiyun	tstb	LOCAL_SGN(%a1)
148*4882a593Smuzhiyun	beqs	dbl_inf		|if positive, go ahead and write it
149*4882a593Smuzhiyun	bsetl	#31,%d0		|if negative put in sign information
150*4882a593Smuzhiyundbl_inf:
151*4882a593Smuzhiyun	movel	%d0,LOCAL_EX(%a1)	|put the new exp back on the stack
152*4882a593Smuzhiyun	bras	dbl_wrt
153*4882a593Smuzhiyunget_mant:
154*4882a593Smuzhiyun	movel	LOCAL_HI(%a1),%d1	|get ms mantissa
155*4882a593Smuzhiyun	bfextu	%d1{#1:#20},%d1	|get upper 20 bits of ms
156*4882a593Smuzhiyun	orl	%d1,%d0		|put these bits in ms word of double
157*4882a593Smuzhiyun	movel	%d0,LOCAL_EX(%a1)	|put the new exp back on the stack
158*4882a593Smuzhiyun	movel	LOCAL_HI(%a1),%d1	|get ms mantissa
159*4882a593Smuzhiyun	movel	#21,%d0		|load shift count
160*4882a593Smuzhiyun	lsll	%d0,%d1		|put lower 11 bits in upper bits
161*4882a593Smuzhiyun	movel	%d1,LOCAL_HI(%a1)	|build lower lword in memory
162*4882a593Smuzhiyun	movel	LOCAL_LO(%a1),%d1	|get ls mantissa
163*4882a593Smuzhiyun	bfextu	%d1{#0:#21},%d0	|get ls 21 bits of double
164*4882a593Smuzhiyun	orl	%d0,LOCAL_HI(%a1)	|put them in double result
165*4882a593Smuzhiyundbl_wrt:
166*4882a593Smuzhiyun	movel	#0x8,%d0		|byte count for double precision number
167*4882a593Smuzhiyun	exg	%a0,%a1		|a0=supervisor source, a1=user dest
168*4882a593Smuzhiyun	bsrl	mem_write	|move the number to the user's memory
169*4882a593Smuzhiyun	rts
170*4882a593Smuzhiyun|
171*4882a593Smuzhiyun|	dest_sgl --- write single precision value to user space
172*4882a593Smuzhiyun|
173*4882a593Smuzhiyun|Input
174*4882a593Smuzhiyun|	a0 -> destination address
175*4882a593Smuzhiyun|	a1 -> source in extended precision
176*4882a593Smuzhiyun|
177*4882a593Smuzhiyun|Output
178*4882a593Smuzhiyun|	a0 -> destroyed
179*4882a593Smuzhiyun|	a1 -> destroyed
180*4882a593Smuzhiyun|	d0 -> 0
181*4882a593Smuzhiyun|
182*4882a593Smuzhiyun|Changes extended precision to single precision.
183*4882a593Smuzhiyun|	sgl_sign = ext_sign
184*4882a593Smuzhiyun|	sgl_exp = ext_exp - $3fff(ext bias) + $7f(sgl bias)
185*4882a593Smuzhiyun|	get rid of ext integer bit
186*4882a593Smuzhiyun|	sgl_mant = ext_mant{62:12}
187*4882a593Smuzhiyun|
188*4882a593Smuzhiyun|		---------------   ---------------    ---------------
189*4882a593Smuzhiyun|  extended ->  |s|    exp    |   |1| ms mant   |    | ls mant     |
190*4882a593Smuzhiyun|		---------------   ---------------    ---------------
191*4882a593Smuzhiyun|		 95	    64    63 62	   40 32      31     12	  0
192*4882a593Smuzhiyun|				     |	   |
193*4882a593Smuzhiyun|				     |	   |
194*4882a593Smuzhiyun|				     |	   |
195*4882a593Smuzhiyun|			             v     v
196*4882a593Smuzhiyun|			      ---------------
197*4882a593Smuzhiyun|  single   ->		      |s|exp| mant  |
198*4882a593Smuzhiyun|			      ---------------
199*4882a593Smuzhiyun|			      31     22     0
200*4882a593Smuzhiyun|
201*4882a593Smuzhiyundest_sgl:
202*4882a593Smuzhiyun	clrl	%d0
203*4882a593Smuzhiyun	movew	LOCAL_EX(%a1),%d0	|get exponent
204*4882a593Smuzhiyun	subw	#0x3fff,%d0	|subtract extended precision bias
205*4882a593Smuzhiyun	cmpw	#0x4000,%d0	|check if inf
206*4882a593Smuzhiyun	beqs	sinf		|if so, special case
207*4882a593Smuzhiyun	addw	#0x7f,%d0		|add single precision bias
208*4882a593Smuzhiyun	swap	%d0		|put exp in upper word of d0
209*4882a593Smuzhiyun	lsll	#7,%d0		|shift it into single exp bits
210*4882a593Smuzhiyun	tstb	LOCAL_SGN(%a1)
211*4882a593Smuzhiyun	beqs	get_sman	|if positive, continue
212*4882a593Smuzhiyun	bsetl	#31,%d0		|if negative, put in sign first
213*4882a593Smuzhiyun	bras	get_sman	|get mantissa
214*4882a593Smuzhiyunsinf:
215*4882a593Smuzhiyun	movel	#0x7f800000,%d0	|load single inf exp to d0
216*4882a593Smuzhiyun	tstb	LOCAL_SGN(%a1)
217*4882a593Smuzhiyun	beqs	sgl_wrt		|if positive, continue
218*4882a593Smuzhiyun	bsetl	#31,%d0		|if negative, put in sign info
219*4882a593Smuzhiyun	bras	sgl_wrt
220*4882a593Smuzhiyun
221*4882a593Smuzhiyunget_sman:
222*4882a593Smuzhiyun	movel	LOCAL_HI(%a1),%d1	|get ms mantissa
223*4882a593Smuzhiyun	bfextu	%d1{#1:#23},%d1	|get upper 23 bits of ms
224*4882a593Smuzhiyun	orl	%d1,%d0		|put these bits in ms word of single
225*4882a593Smuzhiyun
226*4882a593Smuzhiyunsgl_wrt:
227*4882a593Smuzhiyun	movel	%d0,L_SCR1(%a6)	|put the new exp back on the stack
228*4882a593Smuzhiyun	movel	#0x4,%d0		|byte count for single precision number
229*4882a593Smuzhiyun	tstl	%a0		|users destination address
230*4882a593Smuzhiyun	beqs	sgl_Dn		|destination is a data register
231*4882a593Smuzhiyun	exg	%a0,%a1		|a0=supervisor source, a1=user dest
232*4882a593Smuzhiyun	leal	L_SCR1(%a6),%a0	|point a0 to data
233*4882a593Smuzhiyun	bsrl	mem_write	|move the number to the user's memory
234*4882a593Smuzhiyun	rts
235*4882a593Smuzhiyunsgl_Dn:
236*4882a593Smuzhiyun	bsrl	get_fline	|returns fline word in d0
237*4882a593Smuzhiyun	andw	#0x7,%d0		|isolate register number
238*4882a593Smuzhiyun	movel	%d0,%d1		|d1 has size:reg formatted for reg_dest
239*4882a593Smuzhiyun	orl	#0x10,%d1		|reg_dest wants size added to reg#
240*4882a593Smuzhiyun	bral	reg_dest	|size is X, rts in reg_dest will
241*4882a593Smuzhiyun|				;return to caller of dest_sgl
242*4882a593Smuzhiyun
243*4882a593Smuzhiyundest_ext:
244*4882a593Smuzhiyun	tstb	LOCAL_SGN(%a1)	|put back sign into exponent word
245*4882a593Smuzhiyun	beqs	dstx_cont
246*4882a593Smuzhiyun	bsetb	#sign_bit,LOCAL_EX(%a1)
247*4882a593Smuzhiyundstx_cont:
248*4882a593Smuzhiyun	clrb	LOCAL_SGN(%a1)	|clear out the sign byte
249*4882a593Smuzhiyun
250*4882a593Smuzhiyun	movel	#0x0c,%d0		|byte count for extended number
251*4882a593Smuzhiyun	exg	%a0,%a1		|a0=supervisor source, a1=user dest
252*4882a593Smuzhiyun	bsrl	mem_write	|move the number to the user's memory
253*4882a593Smuzhiyun	rts
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun	|end
256