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