5113f6f70
김현기
kernel add
|
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
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MOTOROLA MICROPROCESSOR & MEMORY TECHNOLOGY GROUP
M68000 Hi-Performance Microprocessor Division
M68060 Software Package
Production Release P1.00 -- October 10, 1994
M68060 Software Package Copyright © 1993, 1994 Motorola Inc. All rights reserved.
THE SOFTWARE is provided on an "AS IS" basis and without warranty.
To the maximum extent permitted by applicable law,
MOTOROLA DISCLAIMS ALL WARRANTIES WHETHER EXPRESS OR IMPLIED,
INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
and any warranty against infringement with regard to the SOFTWARE
(INCLUDING ANY MODIFIED VERSIONS THEREOF) and any accompanying written materials.
To the maximum extent permitted by applicable law,
IN NO EVENT SHALL MOTOROLA BE LIABLE FOR ANY DAMAGES WHATSOEVER
(INCLUDING WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS)
ARISING OF THE USE OR INABILITY TO USE THE SOFTWARE.
Motorola assumes no responsibility for the maintenance and support of the SOFTWARE.
You are hereby granted a copyright license to use, modify, and distribute the SOFTWARE
so long as this entire notice is retained without alteration in any modified and/or
redistributed versions, and that such modified versions are clearly identified as such.
No licenses are granted by implication, estoppel or otherwise under any patents
or trademarks of Motorola, Inc.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bra.l _060LSP__idivs64_
short 0x0000
bra.l _060LSP__idivu64_
short 0x0000
bra.l _060LSP__imuls64_
short 0x0000
bra.l _060LSP__imulu64_
short 0x0000
bra.l _060LSP__cmp2_Ab_
short 0x0000
bra.l _060LSP__cmp2_Aw_
short 0x0000
bra.l _060LSP__cmp2_Al_
short 0x0000
bra.l _060LSP__cmp2_Db_
short 0x0000
bra.l _060LSP__cmp2_Dw_
short 0x0000
bra.l _060LSP__cmp2_Dl_
short 0x0000
align 0x200
set POSNEG, -1
set NDIVISOR, -2
set NDIVIDEND, -3
set DDSECOND, -4
set DDNORMAL, -8
set DDQUOTIENT, -12
set DIV64_CC, -16
global _060LSP__idivs64_
_060LSP__idivs64_:
link.w %a6,&-16
movm.l &0x3f00,-(%sp)
mov.w %cc,DIV64_CC(%a6)
st POSNEG(%a6)
bra.b ldiv64_cont
global _060LSP__idivu64_
_060LSP__idivu64_:
link.w %a6,&-16
movm.l &0x3f00,-(%sp)
mov.w %cc,DIV64_CC(%a6)
sf POSNEG(%a6)
ldiv64_cont:
mov.l 0x8(%a6),%d7
beq.w ldiv64eq0
mov.l 0xc(%a6), %d5
mov.l 0x10(%a6), %d6
tst.b POSNEG(%a6)
beq.b ldspecialcases
tst.l %d7
slt NDIVISOR(%a6)
bpl.b ldsgndividend
neg.l %d7
ldsgndividend:
tst.l %d5
slt NDIVIDEND(%a6)
bpl.b ldspecialcases
mov.w &0x0, %cc
negx.l %d6
negx.l %d5
ldspecialcases:
tst.l %d5
bne.b ldnormaldivide
tst.l %d6
beq.w lddone
cmp.l %d7,%d6
bls.b ld32bitdivide
exg %d5,%d6
bra.w ldivfinish
ld32bitdivide:
tdivu.l %d7, %d5:%d6
bra.b ldivfinish
ldnormaldivide:
cmp.l %d7,%d5
bls.b lddovf
bsr.l ldclassical
ldivfinish:
tst.b POSNEG(%a6)
beq.b lddone
tst.b NDIVIDEND(%a6)
beq.b ldcc
neg.l %d5
ldcc:
mov.b NDIVISOR(%a6), %d0
eor.b %d0, NDIVIDEND(%a6)
beq.b ldqpos
cmpi.l %d6, &0x80000000
bhi.b lddovf
neg.l %d6
bra.b lddone
ldqpos:
btst &0x1f, %d6
bne.b lddovf
lddone:
andi.w &0x10,DIV64_CC(%a6)
mov.w DIV64_CC(%a6),%cc
tst.l %d6
ldexit:
movm.l &0x0060,([0x14,%a6])
movm.l (%sp)+,&0x00fc
unlk %a6
rts
lddovf:
mov.l 0xc(%a6), %d5
mov.l 0x10(%a6), %d6
andi.w &0x1c,DIV64_CC(%a6)
ori.w &0x02,DIV64_CC(%a6)
mov.w DIV64_CC(%a6),%cc
bra.b ldexit
ldiv64eq0:
mov.l 0xc(%a6),([0x14,%a6])
mov.l 0x10(%a6),([0x14,%a6],0x4)
mov.w DIV64_CC(%a6),%cc
movm.l (%sp)+,&0x00fc
unlk %a6
divu.w &0x0,%d0
rts
ldclassical:
cmpi.l %d7, &0xffff
bhi.b lddknuth
clr.l %d1
swap %d5
swap %d6
mov.w %d6, %d5
divu.w %d7, %d5
mov.w %d5, %d1
swap %d6
mov.w %d6, %d5
divu.w %d7, %d5
swap %d1
mov.w %d5, %d1
clr.w %d5
swap %d5
mov.l %d1, %d6
rts
lddknuth:
clr.l DDNORMAL(%a6)
clr.b DDSECOND(%a6)
clr.l %d1
lddnchk:
btst &31, %d7
bne.b lddnormalized
addq.l &0x1, DDNORMAL(%a6)
lsl.l &0x1, %d7
lsl.l &0x1, %d6
roxl.l &0x1, %d5
bra.w lddnchk
lddnormalized:
mov.l %d7, %d3
mov.l %d5, %d2
swap %d2
swap %d3
cmp.w %d2, %d3
bne.b lddqcalc1
mov.w &0xffff, %d1
bra.b lddadj0
lddqcalc1:
mov.l %d5, %d1
divu.w %d3, %d1
andi.l &0x0000ffff, %d1
lddadj0:
mov.l %d6, -(%sp)
clr.w %d6
swap %d6
lddadj1: mov.l %d7, %d3
mov.l %d1, %d2
mulu.w %d7, %d2
swap %d3
mulu.w %d1, %d3
mov.l %d5, %d4
sub.l %d3, %d4 # U1U2 - V1q
swap %d4
mov.w %d4,%d0
mov.w %d6,%d4 # insert lower word (U3)
tst.w %d0 # is upper word set?
bne.w lddadjd1
# add.l %d6, %d4 # (U1U2 - V1q) + U3
cmp.l %d2, %d4
bls.b lddadjd1 # is V2q > (U1U2-V1q) + U3 ?
subq.l &0x1, %d1 # yes, decrement and recheck
bra.b lddadj1
lddadjd1:
# now test the word by multiplying it by the divisor (V1V2) and comparing
# the 3 digit (word) result with the current dividend words
mov.l %d5, -(%sp) # save %d5 (%d6 already saved)
mov.l %d1, %d6
swap %d6 # shift answer to ms 3 words
mov.l %d7, %d5
bsr.l ldmm2
mov.l %d5, %d2 # now %d2,%d3 are trial*divisor
mov.l %d6, %d3
mov.l (%sp)+, %d5 # restore dividend
mov.l (%sp)+, %d6
sub.l %d3, %d6
subx.l %d2, %d5 # subtract double precision
bcc ldd2nd # no carry, do next quotient digit
subq.l &0x1, %d1 # q is one too large
# need to add back divisor longword to current ms 3 digits of dividend
# - according to Knuth, this is done only 2 out of 65536 times for random
# divisor, dividend selection.
clr.l %d2
mov.l %d7, %d3
swap %d3
clr.w %d3 # %d3 now ls word of divisor
add.l %d3, %d6 # aligned with 3rd word of dividend
addx.l %d2, %d5
mov.l %d7, %d3
clr.w %d3 # %d3 now ms word of divisor
swap %d3 # aligned with 2nd word of dividend
add.l %d3, %d5
ldd2nd:
tst.b DDSECOND(%a6) # both q words done?
bne.b lddremain
# first quotient digit now correct. store digit and shift the
# (subtracted) dividend
mov.w %d1, DDQUOTIENT(%a6)
clr.l %d1
swap %d5
swap %d6
mov.w %d6, %d5
clr.w %d6
st DDSECOND(%a6) # second digit
bra.w lddnormalized
lddremain:
# add 2nd word to quotient, get the remainder.
mov.w %d1, DDQUOTIENT+2(%a6)
# shift down one word/digit to renormalize remainder.
mov.w %d5, %d6
swap %d6
swap %d5
mov.l DDNORMAL(%a6), %d7 # get norm shift count
beq.b lddrn
subq.l &0x1, %d7 # set for loop count
lddnlp:
lsr.l &0x1, %d5 # shift into %d6
roxr.l &0x1, %d6
dbf %d7, lddnlp
lddrn:
mov.l %d6, %d5 # remainder
mov.l DDQUOTIENT(%a6), %d6 # quotient
rts
ldmm2:
# factors for the 32X32->64 multiplication are in %d5 and %d6.
# returns 64 bit result in %d5 (hi) %d6(lo).
# destroys %d2,%d3,%d4.
# multiply hi,lo words of each factor to get 4 intermediate products
mov.l %d6, %d2
mov.l %d6, %d3
mov.l %d5, %d4
swap %d3
swap %d4
mulu.w %d5, %d6 # %d6 <- lsw*lsw
mulu.w %d3, %d5 # %d5 <- msw-dest*lsw-source
mulu.w %d4, %d2 # %d2 <- msw-source*lsw-dest
mulu.w %d4, %d3 # %d3 <- msw*msw
# now use swap and addx to consolidate to two longwords
clr.l %d4
swap %d6
add.w %d5, %d6 # add msw of l*l to lsw of m*l product
addx.w %d4, %d3 # add any carry to m*m product
add.w %d2, %d6 # add in lsw of other m*l product
addx.w %d4, %d3 # add any carry to m*m product
swap %d6 # %d6 is low 32 bits of final product
clr.w %d5
clr.w %d2 # lsw of two mixed products used,
swap %d5 # now use msws of longwords
swap %d2
add.l %d2, %d5
add.l %d3, %d5 # %d5 now ms 32 bits of final product
rts
#########################################################################
# XDEF **************************************************************** #
# _060LSP__imulu64_(): Emulate 64-bit unsigned mul instruction #
# _060LSP__imuls64_(): Emulate 64-bit signed mul instruction. #
# #
# This is the library version which is accessed as a subroutine #
# and therefore does not work exactly like the 680X0 mul{s,u}.l
set MUL64_CC, -4
global _060LSP__imulu64_
_060LSP__imulu64_:
link.w %a6,&-4
movm.l &0x3800,-(%sp)
mov.w %cc,MUL64_CC(%a6)
mov.l 0x8(%a6),%d0
beq.w mulu64_zero
mov.l 0xc(%a6),%d1
beq.w mulu64_zero
mulu64_alg:
mov.l %d0,%d2
mov.l %d0,%d3
mov.l %d1,%d4
swap %d3
swap %d4
mulu.w %d1,%d0
mulu.w %d3,%d1
mulu.w %d4,%d2
mulu.w %d4,%d3
clr.l %d4
swap %d0
add.w %d1,%d0
addx.l %d4,%d3
add.w %d2,%d0
addx.l %d4,%d3
swap %d0
clr.w %d1
clr.w %d2
swap %d1
swap %d2
add.l %d2,%d1
add.l %d3,%d1
mov.w MUL64_CC(%a6),%d4
andi.b &0x10,%d4
tst.l %d1
bpl.b mulu64_ddone
ori.b &0x8,%d4
mulu64_ddone:
mov.w %d4,%cc
mulu64_end:
exg %d1,%d0
movm.l &0x0003,([0x10,%a6])
movm.l (%sp)+,&0x001c
unlk %a6
rts
mulu64_zero:
clr.l %d0
clr.l %d1
mov.w MUL64_CC(%a6),%d4
andi.b &0x10,%d4
ori.b &0x4,%d4
mov.w %d4,%cc
bra.b mulu64_end
global _060LSP__imuls64_
_060LSP__imuls64_:
link.w %a6,&-4
movm.l &0x3c00,-(%sp)
mov.w %cc,MUL64_CC(%a6)
mov.l 0x8(%a6),%d0
beq.b mulu64_zero
mov.l 0xc(%a6),%d1
beq.b mulu64_zero
clr.b %d5
tst.l %d0
bge.b muls64_chk_md_sgn
neg.l %d0
ori.b &0x1,%d5
muls64_chk_md_sgn:
tst.l %d1
bge.b muls64_alg
neg.l %d1
eori.b &0x1,%d5
muls64_alg:
mov.l %d0,%d2
mov.l %d0,%d3
mov.l %d1,%d4
swap %d3
swap %d4
mulu.w %d1,%d0
mulu.w %d3,%d1
mulu.w %d4,%d2
mulu.w %d4,%d3
clr.l %d4
swap %d0
add.w %d1,%d0
addx.l %d4,%d3
add.w %d2,%d0
addx.l %d4,%d3
swap %d0
clr.w %d1
clr.w %d2
swap %d1
swap %d2
add.l %d2,%d1
add.l %d3,%d1
tst.b %d5
beq.b muls64_done
muls64_neg:
not.l %d0
not.l %d1
addq.l &1,%d0
addx.l %d4,%d1
muls64_done:
mov.w MUL64_CC(%a6),%d4
andi.b &0x10,%d4
tst.l %d1
bpl.b muls64_ddone
ori.b &0x8,%d4
muls64_ddone:
mov.w %d4,%cc
muls64_end:
exg %d1,%d0
movm.l &0x0003,([0x10,%a6])
movm.l (%sp)+,&0x003c
unlk %a6
rts
muls64_zero:
clr.l %d0
clr.l %d1
mov.w MUL64_CC(%a6),%d4
andi.b &0x10,%d4
ori.b &0x4,%d4
mov.w %d4,%cc
bra.b muls64_end
set CMP2_CC, -4
global _060LSP__cmp2_Ab_
_060LSP__cmp2_Ab_:
link.w %a6,&-4
movm.l &0x3800,-(%sp)
mov.w %cc,CMP2_CC(%a6)
mov.l 0x8(%a6), %d2
mov.b ([0xc,%a6],0x0),%d0
mov.b ([0xc,%a6],0x1),%d1
extb.l %d0
extb.l %d1
bra.w l_cmp2_cmp
global _060LSP__cmp2_Aw_
_060LSP__cmp2_Aw_:
link.w %a6,&-4
movm.l &0x3800,-(%sp)
mov.w %cc,CMP2_CC(%a6)
mov.l 0x8(%a6), %d2
mov.w ([0xc,%a6],0x0),%d0
mov.w ([0xc,%a6],0x2),%d1
ext.l %d0
ext.l %d1
bra.w l_cmp2_cmp
global _060LSP__cmp2_Al_
_060LSP__cmp2_Al_:
link.w %a6,&-4
movm.l &0x3800,-(%sp)
mov.w %cc,CMP2_CC(%a6)
mov.l 0x8(%a6), %d2
mov.l ([0xc,%a6],0x0),%d0
mov.l ([0xc,%a6],0x4),%d1
bra.w l_cmp2_cmp
global _060LSP__cmp2_Db_
_060LSP__cmp2_Db_:
link.w %a6,&-4
movm.l &0x3800,-(%sp)
mov.w %cc,CMP2_CC(%a6)
mov.l 0x8(%a6), %d2
mov.b ([0xc,%a6],0x0),%d0
mov.b ([0xc,%a6],0x1),%d1
extb.l %d0
extb.l %d1
extb.l %d2
bra.w l_cmp2_cmp
global _060LSP__cmp2_Dw_
_060LSP__cmp2_Dw_:
link.w %a6,&-4
movm.l &0x3800,-(%sp)
mov.w %cc,CMP2_CC(%a6)
mov.l 0x8(%a6), %d2
mov.w ([0xc,%a6],0x0),%d0
mov.w ([0xc,%a6],0x2),%d1
ext.l %d0
ext.l %d1
ext.l %d2
bra.w l_cmp2_cmp
global _060LSP__cmp2_Dl_
_060LSP__cmp2_Dl_:
link.w %a6,&-4
movm.l &0x3800,-(%sp)
mov.w %cc,CMP2_CC(%a6)
mov.l 0x8(%a6), %d2
mov.l ([0xc,%a6],0x0),%d0
mov.l ([0xc,%a6],0x4),%d1
l_cmp2_cmp:
sub.l %d0, %d2 # (Rn - lo)
mov.w %cc, %d3 # fetch resulting ccodes
andi.b &0x4, %d3 # keep 'Z' bit
sub.l %d0, %d1 # (hi - lo)
cmp.l %d1,%d2 # ((hi - lo) - (Rn - hi))
mov.w %cc, %d4 # fetch resulting ccodes
or.b %d4, %d3 # combine w/ earlier ccodes
andi.b &0x5, %d3 # keep 'Z' and 'N'
mov.w CMP2_CC(%a6), %d4 # fetch old ccodes
andi.b &0x1a, %d4 # keep 'X','N','V' bits
or.b %d3, %d4 # insert new ccodes
mov.w %d4,%cc # save new ccodes
# EPILOGUE BEGIN ########################################################
# fmovm.l (%sp)+,&0x0 # restore no fpregs
movm.l (%sp)+,&0x001c # restore d2-d4
unlk %a6
# EPILOGUE END ##########################################################
rts
|