summaryrefslogtreecommitdiffstats
path: root/arch/m68k/fpsp040/gen_except.S
blob: 3642cb7e3641748743a799d164dd941be57aff3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
|
|	gen_except.sa 3.7 1/16/92
|
|	gen_except --- FPSP routine to detect reportable exceptions
|
|	This routine compares the exception enable byte of the
|	user_fpcr on the stack with the exception status byte
|	of the user_fpsr.
|
|	Any routine which may report an exceptions must load
|	the stack frame in memory with the exceptional operand(s).
|
|	Priority for exceptions is:
|
|	Highest:	bsun
|			snan
|			operr
|			ovfl
|			unfl
|			dz
|			inex2
|	Lowest:		inex1
|
|	Note: The IEEE standard specifies that inex2 is to be
|	reported if ovfl occurs and the ovfl enable bit is not
|	set but the inex2 enable bit is.
|
|
|		Copyright (C) Motorola, Inc. 1990
|			All Rights Reserved
|
|       For details on the license for this file, please see the
|       file, README, in this same directory.

GEN_EXCEPT:    |idnt    2,1 | Motorola 040 Floating Point Software Package

	|section 8

#include "fpsp.h"

	|xref	real_trace
	|xref	fpsp_done
	|xref	fpsp_fmt_error

exc_tbl:
	.long	bsun_exc
	.long	commonE1
	.long	commonE1
	.long	ovfl_unfl
	.long	ovfl_unfl
	.long	commonE1
	.long	commonE3
	.long	commonE3
	.long	no_match

	.global	gen_except
gen_except:
	cmpib	#IDLE_SIZE-4,1(%a7)	|test for idle frame
	beq	do_check		|go handle idle frame
	cmpib	#UNIMP_40_SIZE-4,1(%a7)	|test for orig unimp frame
	beqs	unimp_x			|go handle unimp frame
	cmpib	#UNIMP_41_SIZE-4,1(%a7)	|test for rev unimp frame
	beqs	unimp_x			|go handle unimp frame
	cmpib	#BUSY_SIZE-4,1(%a7)	|if size <> $60, fmt error
	bnel	fpsp_fmt_error
	leal	BUSY_SIZE+LOCAL_SIZE(%a7),%a1 |init a1 so fpsp.h
|					;equates will work
| Fix up the new busy frame with entries from the unimp frame
|
	movel	ETEMP_EX(%a6),ETEMP_EX(%a1) |copy etemp from unimp
	movel	ETEMP_HI(%a6),ETEMP_HI(%a1) |frame to busy frame
	movel	ETEMP_LO(%a6),ETEMP_LO(%a1)
	movel	CMDREG1B(%a6),CMDREG1B(%a1) |set inst in frame to unimp
	movel	CMDREG1B(%a6),%d0		|fix cmd1b to make it
	andl	#0x03c30000,%d0		|work for cmd3b
	bfextu	CMDREG1B(%a6){#13:#1},%d1	|extract bit 2
	lsll	#5,%d1
	swap	%d1
	orl	%d1,%d0			|put it in the right place
	bfextu	CMDREG1B(%a6){#10:#3},%d1	|extract bit 3,4,5
	lsll	#2,%d1
	swap	%d1
	orl	%d1,%d0			|put them in the right place
	movel	%d0,CMDREG3B(%a1)		|in the busy frame
|
| Or in the FPSR from the emulation with the USER_FPSR on the stack.
|
	fmovel	%FPSR,%d0
	orl	%d0,USER_FPSR(%a6)
	movel	USER_FPSR(%a6),FPSR_SHADOW(%a1) |set exc bits
	orl	#sx_mask,E_BYTE(%a1)
	bra	do_clean

|
| Frame is an unimp frame possible resulting from an fmove <ea>,fp0
| that caused an exception
|
| a1 is modified to point into the new frame allowing fpsp equates
| to be valid.
|
unimp_x:
	cmpib	#UNIMP_40_SIZE-4,1(%a7)	|test for orig unimp frame
	bnes	test_rev
	leal	UNIMP_40_SIZE+LOCAL_SIZE(%a7),%a1
	bras	unimp_con
test_rev:
	cmpib	#UNIMP_41_SIZE-4,1(%a7)	|test for rev unimp frame
	bnel	fpsp_fmt_error		|if not $28 or $30
	leal	UNIMP_41_SIZE+LOCAL_SIZE(%a7),%a1

unimp_con:
|
| Fix up the new unimp frame with entries from the old unimp frame
|
	movel	CMDREG1B(%a6),CMDREG1B(%a1) |set inst in frame to unimp
|
| Or in the FPSR from the emulation with the USER_FPSR on the stack.
|
	fmovel	%FPSR,%d0
	orl	%d0,USER_FPSR(%a6)
	bra	do_clean

|
| Frame is idle, so check for exceptions reported through
| USER_FPSR and set the unimp frame accordingly.
| A7 must be incremented to the point before the
| idle fsave vector to the unimp vector.
|

do_check:
	addl	#4,%a7			|point A7 back to unimp frame
|
| Or in the FPSR from the emulation with the USER_FPSR on the stack.
|
	fmovel	%FPSR,%d0
	orl	%d0,USER_FPSR(%a6)
|
| On a busy frame, we must clear the nmnexc bits.
|
	cmpib	#BUSY_SIZE-4,1(%a7)	|check frame type
	bnes	check_fr		|if busy, clr nmnexc
	clrw	NMNEXC(%a6)		|clr nmnexc & nmcexc
	btstb	#5,CMDREG1B(%a6)		|test for fmove out
	bnes	frame_com
	movel	USER_FPSR(%a6),FPSR_SHADOW(%a6) |set exc bits
	orl	#sx_mask,E_BYTE(%a6)
	bras	frame_com
check_fr:
	cmpb	#UNIMP_40_SIZE-4,1(%a7)
	beqs	frame_com
	clrw	NMNEXC(%a6)
frame_com:
	moveb	FPCR_ENABLE(%a6),%d0	|get fpcr enable byte
	andb	FPSR_EXCEPT(%a6),%d0	|and in the fpsr exc byte
	bfffo	%d0{#24:#8},%d1		|test for first set bit
	leal	exc_tbl,%a0		|load jmp table address
	subib	#24,%d1			|normalize bit offset to 0-8
	movel	(%a0,%d1.w*4),%a0		|load routine address based
|					;based on first enabled exc
	jmp	(%a0)			|jump to routine
|
| Bsun is not possible in unimp or unsupp
|
bsun_exc:
	bra	do_clean
|
| The typical work to be done to the unimp frame to report an
| exception is to set the E1/E3 byte and clr the U flag.
| commonE1 does this for E1 exceptions, which are snan,
| operr, and dz.  commonE3 does this for E3 exceptions, which
| are inex2 and inex1, and also clears the E1 exception bit
| left over from the unimp exception.
|
commonE1:
	bsetb	#E1,E_BYTE(%a6)		|set E1 flag
	bra	commonE			|go clean and exit

commonE3:
	tstb	UFLG_TMP(%a6)		|test flag for unsup/unimp state
	bnes	unsE3
uniE3:
	bsetb	#E3,E_BYTE(%a6)		|set E3 flag
	bclrb	#E1,E_BYTE(%a6)		|clr E1 from unimp
	bra	commonE

unsE3:
	tstb	RES_FLG(%a6)
	bnes	unsE3_0
unsE3_1:
	bsetb	#E3,E_BYTE(%a6)		|set E3 flag
unsE3_0:
	bclrb	#E1,E_BYTE(%a6)		|clr E1 flag
	movel	CMDREG1B(%a6),%d0
	andl	#0x03c30000,%d0		|work for cmd3b
	bfextu	CMDREG1B(%a6){#13:#1},%d1	|extract bit 2
	lsll	#5,%d1
	swap	%d1
	orl	%d1,%d0			|put it in the right place
	bfextu	CMDREG1B(%a6){#10:#3},%d1	|extract bit 3,4,5
	lsll	#2,%d1
	swap	%d1
	orl	%d1,%d0			|put them in the right place
	movel	%d0,CMDREG3B(%a6)		|in the busy frame

commonE:
	bclrb	#UFLAG,T_BYTE(%a6)	|clr U flag from unimp
	bra	do_clean		|go clean and exit
|
| No bits in the enable byte match existing exceptions.  Check for
| the case of the ovfl exc without the ovfl enabled, but with
| inex2 enabled.
|
no_match:
	btstb	#inex2_bit,FPCR_ENABLE(%a6) |check for ovfl/inex2 case
	beqs	no_exc			|if