-
Notifications
You must be signed in to change notification settings - Fork 5
/
crt0.s
1374 lines (1184 loc) · 47.2 KB
/
crt0.s
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
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!-----------------------------------------------------------------------
! SEGA 32X support code for SH2
! by Chilly Willy
! Rom header and SH2 init/exception code - must be first in object list
!-----------------------------------------------------------------------
.text
! 68000 exception vector table at 0x000
!-----------------------------------------------------------------------
! Initial exception vectors - when the console is first turned on, it is
! in MegaDrive mode. All vectors just point to the code to start up the
! Mars adapter. After the adapter is enabled, none of these vectors will
! appear as the adapter uses its own vector table to route exceptions to
! the jump table at 0x200.
!-----------------------------------------------------------------------
.long 0x01000000,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0
.long 0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0
.long 0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0
.long 0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0
.long 0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0
.long 0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0
.long 0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0
.long 0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0,0x000003F0
! Standard MegaDrive ROM header at 0x100
.ascii "SEGA 32X "
.ascii " "
.ascii "DOOM 32X Resurre"
.ascii "ction "
.ascii " "
.ascii "DOOM 32X Resurre"
.ascii "ction "
.ascii " "
.ascii "GM 20210824-00"
.word 0x0000
.ascii "J6 "
.long 0x00000000,0x003FFFFF /* ROM start, end */
.long 0x00FF0000,0x00FFFFFF /* RAM start, end */
! 2KB of save ram on odd byte lane
.ascii "RA" /* External RAM */
.byte 0xF8 /* don't clear + odd bytes */
.byte 0x20 /* SRAM */
.long 0x00200001,0x00200FFF /* SRAM start, end */
! .ascii " " /* no SRAM */
.ascii " "
.ascii " "
.ascii " "
.ascii " "
.ascii "F " /* enable any hardware configuration */
! Mars 68000 exception jump table at 0x200
.macro jump address
.word 0x4EF9,\address>>16,\address&0xFFFF
.endm
.macro call address
.word 0x4EB9,\address>>16,\address&0xFFFF
.endm
jump 0x880800 /* reset = hot start */
call 0x880840 /* EX_BusError */
call 0x880840 /* EX_AddrError */
call 0x880840 /* EX_IllInstr */
call 0x880840 /* EX_DivByZero */
call 0x880840 /* EX_CHK */
call 0x880840 /* EX_TrapV */
call 0x880840 /* EX_Priviledge */
call 0x880840 /* EX_Trace */
call 0x880840 /* EX_LineA */
call 0x880840 /* EX_LineF */
.space 72 /* reserved */
call 0x880840 /* EX_Spurious */
call 0x880840 /* EX_Level1 */
call 0x880840 /* EX_Level2 */
call 0x880840 /* EX_Level3 */
jump 0x880880 /* EX_Level4 HBlank */
call 0x880840 /* EX_Level5 */
jump 0x8808C0 /* EX_Level6 VBlank */
call 0x880840 /* EX_Level7 */
call 0x880840 /* EX_Trap0 */
call 0x880840 /* EX_Trap1 */
call 0x880840 /* EX_Trap2 */
call 0x880840 /* EX_Trap3 */
call 0x880840 /* EX_Trap4 */
call 0x880840 /* EX_Trap5 */
call 0x880840 /* EX_Trap6 */
call 0x880840 /* EX_Trap7 */
call 0x880840 /* EX_Trap8 */
call 0x880840 /* EX_Trap9 */
call 0x880840 /* EX_TrapA */
call 0x880840 /* EX_TrapB */
call 0x880840 /* EX_TrapC */
call 0x880840 /* EX_TrapD */
call 0x880840 /* EX_TrapE */
call 0x880840 /* EX_TrapF */
.space 166 /* reserved */
! Standard Mars Header at 0x3C0
.ascii "DOOM 32XR " /* module name */
.long 0x00000000 /* version */
.long __text_end-0x02000000 /* Source (in ROM) */
.long 0x00000000 /* Destination (in SDRAM) */
.long __data_size /* Size */
.long pri_start /* Primary SH2 Jump */
.long sec_start /* Secondary SH2 Jump */
.long pri_vbr /* Primary SH2 VBR */
.long sec_vbr /* Secondary SH2 VBR */
! Standard 32X startup code for MD side at 0x3F0
.word 0x287C,0xFFFF,0xFFC0,0x23FC,0x0000,0x0000,0x00A1,0x5128
.word 0x46FC,0x2700,0x4BF9,0x00A1,0x0000,0x7001,0x0CAD,0x4D41
.word 0x5253,0x30EC,0x6600,0x03E6,0x082D,0x0007,0x5101,0x67F8
.word 0x4AAD,0x0008,0x6710,0x4A6D,0x000C,0x670A,0x082D,0x0000
.word 0x5101,0x6600,0x03B8,0x102D,0x0001,0x0200,0x000F,0x6706
.word 0x2B78,0x055A,0x4000,0x7200,0x2C41,0x4E66,0x41F9,0x0000
.word 0x04D4,0x6100,0x0152,0x6100,0x0176,0x47F9,0x0000,0x04E8
.word 0x43F9,0x00A0,0x0000,0x45F9,0x00C0,0x0011,0x3E3C,0x0100
.word 0x7000,0x3B47,0x1100,0x3B47,0x1200,0x012D,0x1100,0x66FA
.word 0x7425,0x12DB,0x51CA,0xFFFC,0x3B40,0x1200,0x3B40,0x1100
.word 0x3B47,0x1200,0x149B,0x149B,0x149B,0x149B,0x41F9,0x0000
.word 0x04C0,0x43F9,0x00FF,0x0000,0x22D8,0x22D8,0x22D8,0x22D8
.word 0x22D8,0x22D8,0x22D8,0x22D8,0x41F9,0x00FF,0x0000,0x4ED0
.word 0x1B7C,0x0001,0x5101,0x41F9,0x0000,0x06BC,0xD1FC,0x0088
.word 0x0000,0x4ED0,0x0404,0x303C,0x076C,0x0000,0x0000,0xFF00
.word 0x8137,0x0002,0x0100,0x0000,0xAF01,0xD91F,0x1127,0x0021
.word 0x2600,0xF977,0xEDB0,0xDDE1,0xFDE1,0xED47,0xED4F,0xD1E1
.word 0xF108,0xD9C1,0xD1E1,0xF1F9,0xF3ED,0x5636,0xE9E9,0x9FBF
.word 0xDFFF,0x4D41,0x5253,0x2049,0x6E69,0x7469,0x616C,0x2026
.word 0x2053,0x6563,0x7572,0x6974,0x7920,0x5072,0x6F67,0x7261
.word 0x6D20,0x2020,0x2020,0x2020,0x2020,0x2043,0x6172,0x7472
.word 0x6964,0x6765,0x2056,0x6572,0x7369,0x6F6E,0x2020,0x2020
.word 0x436F,0x7079,0x7269,0x6768,0x7420,0x5345,0x4741,0x2045
.word 0x4E54,0x4552,0x5052,0x4953,0x4553,0x2C4C,0x5444,0x2E20
.word 0x3139,0x3934,0x2020,0x2020,0x2020,0x2020,0x2020,0x2020
.word 0x2020,0x2020,0x2020,0x2020,0x2020,0x2020,0x2020,0x2020
.word 0x2020,0x2020,0x2020,0x524F,0x4D20,0x5665,0x7273,0x696F
.word 0x6E20,0x312E,0x3000,0x48E7,0xC040,0x43F9,0x00C0,0x0004
.word 0x3011,0x303C,0x8000,0x323C,0x0100,0x3E3C,0x0012,0x1018
.word 0x3280,0xD041,0x51CF,0xFFF8,0x4CDF,0x0203,0x4E75,0x48E7
.word 0x81C0,0x41F9,0x0000,0x063E,0x43F9,0x00C0,0x0004,0x3298
.word 0x3298,0x3298,0x3298,0x3298,0x3298,0x3298,0x2298,0x3341
.word 0xFFFC,0x3011,0x0800,0x0001,0x66F8,0x3298,0x3298,0x7000
.word 0x22BC,0xC000,0x0000,0x7E0F,0x3340,0xFFFC,0x3340,0xFFFC
.word 0x3340,0xFFFC,0x3340,0xFFFC,0x51CF,0xFFEE,0x22BC,0x4000
.word 0x0010,0x7E09,0x3340,0xFFFC,0x3340,0xFFFC,0x3340,0xFFFC
.word 0x3340,0xFFFC,0x51CF,0xFFEE,0x4CDF,0x0381,0x4E75,0x8114
.word 0x8F01,0x93FF,0x94FF,0x9500,0x9600,0x9780,0x4000,0x0080
.word 0x8104,0x8F02,0x48E7,0xC140,0x43F9,0x00A1,0x5180,0x08A9
.word 0x0007,0xFF80,0x66F8,0x3E3C,0x00FF,0x7000,0x7200,0x337C
.word 0x00FF,0x0004,0x3341,0x0006,0x3340,0x0008,0x4E71,0x0829
.word 0x0001,0x000B,0x66F8,0x0641,0x0100,0x51CF,0xFFE8,0x4CDF
.word 0x0283,0x4E75,0x48E7,0x8180,0x41F9,0x00A1,0x5200,0x08A8
.word 0x0007,0xFF00,0x66F8,0x3E3C,0x001F,0x20C0,0x20C0,0x20C0
.word 0x20C0,0x51CF,0xFFF6,0x4CDF,0x0181,0x4E75,0x41F9,0x00FF
.word 0x0000,0x3E3C,0x07FF,0x7000,0x20C0,0x20C0,0x20C0,0x20C0
.word 0x20C0,0x20C0,0x20C0,0x20C0,0x51CF,0xFFEE,0x3B7C,0x0000
.word 0x1200,0x7E0A,0x51CF,0xFFFE,0x43F9,0x00A1,0x5100,0x7000
.word 0x2340,0x0020,0x2340,0x0024,0x1B7C,0x0003,0x5101,0x2E79
.word 0x0088,0x0000,0x0891,0x0007,0x66FA,0x7000,0x3340,0x0002
.word 0x3340,0x0004,0x3340,0x0006,0x2340,0x0008,0x2340,0x000C
.word 0x3340,0x0010,0x3340,0x0030,0x3340,0x0032,0x3340,0x0038
.word 0x3340,0x0080,0x3340,0x0082,0x08A9,0x0000,0x008B,0x66F8
.word 0x6100,0xFF12,0x08E9,0x0000,0x008B,0x67F8,0x6100,0xFF06
.word 0x08A9,0x0000,0x008B,0x6100,0xFF3C,0x303C,0x0040,0x2229
.word 0x0020,0x0C81,0x5351,0x4552,0x6700,0x0092,0x303C,0x0080
.word 0x2229,0x0020,0x0C81,0x5344,0x4552,0x6700,0x0080,0x21FC
.word 0x0088,0x02A2,0x0070,0x303C,0x0002,0x7200,0x122D,0x0001
.word 0x1429,0x0080,0xE14A,0x8242,0x0801,0x000F,0x660A,0x0801
.word 0x0006,0x6700,0x0058,0x6008,0x0801,0x0006,0x6600,0x004E
.word 0x7020,0x41F9,0x0088,0x0000,0x3C28,0x018E,0x4A46,0x6700
.word 0x0010,0x3429,0x0028,0x0C42,0x0000,0x67F6,0xB446,0x662C
.word 0x7000,0x2340,0x0028,0x2340,0x002C,0x3E14,0x2C7C,0xFFFF
.word 0xFFC0,0x4CD6,0x7FF9,0x44FC,0x0000,0x6014,0x43F9,0x00A1
.word 0x5100,0x3340,0x0006,0x303C,0x8000,0x6004,0x44FC,0x0001
!-----------------------------------------------------------------------
! At this point (0x800), the Work RAM is clear, the VDP initialized, the
! VRAM/VSRAM/CRAM cleared, the Z80 initialized, the 32X initialized,
! both 32X framebuffers cleared, the 32X palette cleared, the SH2s
! checked for a startup error, the adapter TV mode matches the MD TV
! mode, and the ROM checksum checked. If any error is detected, the
! carry is set, otherwise it is cleared. The 68000 main code is now
! entered.
!-----------------------------------------------------------------------
.incbin "src-md/m68k.bin" /* all 68000 code & data, compiled to 0x880800/0xFF0000 */
.data
!-----------------------------------------------------------------------
! Primary Vector Base Table
!-----------------------------------------------------------------------
.equ pri_stack, 0x0603FC00
.equ sec_stack, 0x06040000
.align 4
pri_vbr:
.long pri_start /* Cold Start PC */
.long pri_stack /* Cold Start SP */
.long pri_start /* Manual Reset PC */
.long pri_stack /* Manual Reset SP */
.long pri_err /* Illegal instruction */
.long 0x00000000 /* reserved */
.long pri_err /* Invalid slot instruction */
.long 0x00000000 /* reserved */
.long 0x00000000 /* reserved */
.long pri_err /* CPU address error */
.long pri_err /* DMA address error */
.long pri_err /* NMI vector */
.long pri_err /* User break vector */
.space 76 /* reserved */
.long pri_err /* TRAPA #32 */
.long pri_err /* TRAPA #33 */
.long pri_err /* TRAPA #34 */
.long pri_err /* TRAPA #35 */
.long pri_err /* TRAPA #36 */
.long pri_err /* TRAPA #37 */
.long pri_err /* TRAPA #38 */
.long pri_err /* TRAPA #39 */
.long pri_err /* TRAPA #40 */
.long pri_err /* TRAPA #41 */
.long pri_err /* TRAPA #42 */
.long pri_err /* TRAPA #43 */
.long pri_err /* TRAPA #44 */
.long pri_err /* TRAPA #45 */
.long pri_err /* TRAPA #46 */
.long pri_err /* TRAPA #47 */
.long pri_err /* TRAPA #48 */
.long pri_err /* TRAPA #49 */
.long pri_err /* TRAPA #50 */
.long pri_err /* TRAPA #51 */
.long pri_err /* TRAPA #52 */
.long pri_err /* TRAPA #53 */
.long pri_err /* TRAPA #54 */
.long pri_err /* TRAPA #55 */
.long pri_err /* TRAPA #56 */
.long pri_err /* TRAPA #57 */
.long pri_err /* TRAPA #58 */
.long pri_err /* TRAPA #59 */
.long pri_err /* TRAPA #60 */
.long pri_err /* TRAPA #61 */
.long pri_err /* TRAPA #62 */
.long pri_err /* TRAPA #63 */
.long pri_irq /* FRT interrupt (Level 1) */
.long pri_irq /* WDT interrupt (Level 2 & 3) */
.long pri_irq /* DMA interrupt (Level 4 & 5) */
.long pri_irq /* PWM interupt (Level 6 & 7) */
.long pri_irq /* Command interupt (Level 8 & 9) */
.long pri_irq /* H Blank interupt (Level 10 & 11) */
.long pri_irq /* V Blank interupt (Level 12 & 13) */
.long pri_irq /* Reset Button (Level 14 & 15) */
!-----------------------------------------------------------------------
! Secondary Vector Base Table
!-----------------------------------------------------------------------
sec_vbr:
.long sec_start /* Cold Start PC */
.long sec_stack /* Cold Start SP */
.long sec_start /* Manual Reset PC */
.long sec_stack /* Manual Reset SP */
.long sec_err /* Illegal instruction */
.long 0x00000000 /* reserved */
.long sec_err /* Invalid slot instruction */
.long 0x00000000 /* reserved */
.long 0x00000000 /* reserved */
.long sec_err /* CPU address error */
.long sec_err /* DMA address error */
.long sec_err /* NMI vector */
.long sec_err /* User break vector */
.space 76 /* reserved */
.long sec_err /* TRAPA #32 */
.long sec_err /* TRAPA #33 */
.long sec_err /* TRAPA #34 */
.long sec_err /* TRAPA #35 */
.long sec_err /* TRAPA #36 */
.long sec_err /* TRAPA #37 */
.long sec_err /* TRAPA #38 */
.long sec_err /* TRAPA #39 */
.long sec_err /* TRAPA #40 */
.long sec_err /* TRAPA #41 */
.long sec_err /* TRAPA #42 */
.long sec_err /* TRAPA #43 */
.long sec_err /* TRAPA #44 */
.long sec_err /* TRAPA #45 */
.long sec_err /* TRAPA #46 */
.long sec_err /* TRAPA #47 */
.long sec_err /* TRAPA #48 */
.long sec_err /* TRAPA #49 */
.long sec_err /* TRAPA #50 */
.long sec_err /* TRAPA #51 */
.long sec_err /* TRAPA #52 */
.long sec_err /* TRAPA #53 */
.long sec_err /* TRAPA #54 */
.long sec_err /* TRAPA #55 */
.long sec_err /* TRAPA #56 */
.long sec_err /* TRAPA #57 */
.long sec_err /* TRAPA #58 */
.long sec_err /* TRAPA #59 */
.long sec_err /* TRAPA #60 */
.long sec_err /* TRAPA #61 */
.long sec_err /* TRAPA #62 */
.long sec_err /* TRAPA #63 */
.long sec_irq /* FRT interrupt (Level 1) */
.long sec_irq /* WDT interrupt (Level 2 & 3) */
.long sec_irq /* DMA interrupt (Level 4 & 5) */
.long sec_irq /* PWM interupt (Level 6 & 7) */
.long sec_irq /* Command interupt (Level 8 & 9) */
.long sec_irq /* H Blank interupt (Level 10 & 11 */
.long sec_irq /* V Blank interupt (Level 12 & 13) */
.long sec_irq /* Reset Button (Level 14 & 15) */
!-----------------------------------------------------------------------
! The Primary SH2 starts here
!-----------------------------------------------------------------------
pri_start:
! clear interrupt flags
mov.l _pri_int_clr,r1
mov.w r0,@-r1 /* PWM INT clear */
mov.w r0,@r1
mov.w r0,@-r1 /* CMD INT clear */
mov.w r0,@r1
mov.w r0,@-r1 /* H INT clear */
mov.w r0,@r1
mov.w r0,@-r1 /* V INT clear */
mov.w r0,@r1
mov.w r0,@-r1 /* VRES INT clear */
mov.w r0,@r1
mov.l _pri_sh2_frtctl,r1 /* Set Free Run Timer */
mov #0x00,r0
mov.b r0,@(0x00,r1) /* TIER = ints disabled */
mov #0xE2,r0
mov.b r0,@(0x07,r1) /* TOCR = select OCRA, output 1 on compare match */
mov #0x00,r0
mov.b r0,@(0x04,r1) /* OCR_H */
mov #0x01,r0
mov.b r0,@(0x05,r1) /* OCR_L => OCRA = 0x0001 */
mov #0,r0
mov.b r0,@(0x06,r1) /* TCR = input captured on falling edge, CKS = Fs/8 */
mov #1,r0
mov.b r0,@(0x01,r1) /* TCSR = clear FRC on match OCRA */
mov #0x00,r0
mov.b r0,@(0x03,r1) /* FRC_L */
mov.b r0,@(0x02,r1) /* FRC_H => clear FRC */
mov.l _pri_stk,r15
! purge cache and turn it off
mov.l _pri_cctl,r0
mov #0x10,r1 /* CP = cache purge, /CE = cache disabled */
mov.b r1,@r0
! clear bss
mov #0,r0
mov.l _bss_dst,r1
mov.l _bss_end,r2
0:
mov.b r0,@r1
add #1,r1
cmp/eq r1,r2
bf 0b
! wait for 68000 to finish init
mov.l _pri_sts,r0
mov.l _pri_ok,r1
1:
mov.l @r0,r2
nop
nop
cmp/eq r1,r2
bt 1b
! let Secondary SH2 run
mov #0,r1
mov.l r1,@(4,r0) /* clear secondary status */
mov #0x80,r0
mov.l _pri_adapter,r1
mov.b r0,@r1 /* set FM */
mov #0x08,r0 /* vbi enabled */
mov.b r0,@(1,r1) /* set int enables */
mov #0x10,r0
ldc r0,sr /* allow ints */
! purge cache, turn it on, and run main()
mov.l _pri_cctl,r0
mov #0x11,r1 /* CP = cache purge, CE = cache enabled */
mov.b r1,@r0
mov.l _pri_go,r0
jmp @r0
nop
.align 2
_pri_int_clr:
.long 0x2000401E /* one word passed last int clr reg */
_pri_stk:
.long pri_stack /* Cold Start SP */
_pri_sts:
.long 0x20004020
_pri_sh2_frtctl:
.long 0xfffffe10
_pri_ok:
.ascii "M_OK"
_pri_adapter:
.long 0x20004000
_pri_cctl:
.long 0xFFFFFE92
_pri_go:
.long _main
_bss_dst:
.long __bss_start
_bss_end:
.long __bss_end
!-----------------------------------------------------------------------
! Primary exception handler
!-----------------------------------------------------------------------
pri_err:
rte
nop
!-----------------------------------------------------------------------
! Primary IRQ handler
!-----------------------------------------------------------------------
pri_irq:
mov.l r0,@-r15
mov.l r1,@-r15
mov.l r2,@-r15
stc sr,r1 /* SR holds IRQ level in I3-I0 */
mov.w p_int_off,r2
ldc r2,sr /* disallow ints */
mov.l p_sys_frt_tocr,r2
mov #0xE0,r0 /* TOCR = select OCRA, output 0 on compare match */
mov.b r0,@r2
mov.b @r2,r0
sts.l pr,@-r15
mov r1,r0
shlr2 r0
and #0x3C,r0 /* int level to table offset */
mov.l p_int_jtable,r1
mov.l @(r0,r1),r0
jsr @r0
nop
lds.l @r15+,pr
mov.l @r15+,r2
mov.l @r15+,r1
mov.l @r15+,r0
rte
nop
.align 2
p_sys_frt_tocr:
.long 0xFFFFFE17
p_int_jtable:
.long _p_int_jtable
p_int_off:
.word 0x00F0
.align 4
_p_int_jtable:
.long pri_no_irq /* level 0 (ILL) */
.long pri_no_irq /* level 1 (FRT) */
.long pri_wdt_irq /* level 2 (WDT) */
.long pri_wdt_irq /* level 3 (WDT) */
.long pri_dma_irq /* level 4 (DMA) */
.long pri_dma_irq /* level 5 (DMA) */
.long pri_pwm_irq /* level 6 (PWM) */
.long pri_pwm_irq /* level 7 (PWM) */
.long pri_cmd_irq /* level 8 (CMD) */
.long pri_cmd_irq /* level 9 (CMD) */
.long pri_h_irq /* level 10 (HBI) */
.long pri_h_irq /* level 11 (HBI) */
.long pri_v_irq /* level 12 (VBI) */
.long pri_v_irq /* level 13 (VBI) */
.long pri_vres_irq /* level 14 (VRES) */
.long pri_vres_irq /* level 15 (VRES) */
!-----------------------------------------------------------------------
! Primary No IRQ handler
!-----------------------------------------------------------------------
pri_no_irq:
rts
nop
!-----------------------------------------------------------------------
! Primary V Blank IRQ handler
!-----------------------------------------------------------------------
pri_v_irq:
! bump ints if necessary
mov.l pvi_sh2_frtctl,r1
mov #0xE2,r0 /* TOCR = select OCRA, output 1 on compare match */
mov.b r0,@(0x07,r1) /* write TOCR */
mov.b @(0x07,r1),r0 /* read TOCR */
mov.l pvi_mars_adapter,r1
mov.w r0,@(0x16,r1) /* clear V IRQ */
! handle V IRQ - save registers
sts.l pr,@-r15
mov.l r3,@-r15
mov.l r4,@-r15
mov.l r5,@-r15
mov.l r6,@-r15
mov.l r7,@-r15
sts.l mach,@-r15
sts.l macl,@-r15
mov.l pvbi_handler_ptr,r0
jsr @r0
nop
! restore registers
lds.l @r15+,macl
lds.l @r15+,mach
mov.l @r15+,r7
mov.l @r15+,r6
mov.l @r15+,r5
mov.l @r15+,r4
mov.l @r15+,r3
lds.l @r15+,pr
rts
nop
.align 2
pvi_mars_adapter:
.long 0x20004000
pvbi_handler_ptr:
.long _pri_vbi_handler
pvi_sh2_frtctl:
.long 0xfffffe10
!-----------------------------------------------------------------------
! Primary H Blank IRQ handler
!-----------------------------------------------------------------------
pri_h_irq:
! bump ints if necessary
mov.l phi_sh2_frtctl,r1
mov #0xE2,r0 /* TOCR = select OCRA, output 1 on compare match */
mov.b r0,@(0x07,r1) /* write TOCR */
mov.b @(0x07,r1),r0 /* read TOCR */
mov.l phi_mars_adapter,r1
mov.w r0,@(0x18,r1) /* clear H IRQ */
nop
nop
nop
nop
! handle H IRQ (remove nops if more than 8 cycles)
rts
nop
.align 2
phi_mars_adapter:
.long 0x20004000
phi_sh2_frtctl:
.long 0xfffffe10
!-----------------------------------------------------------------------
! Primary Command IRQ handler
!-----------------------------------------------------------------------
pri_cmd_irq:
! bump ints if necessary
mov.l pci_sh2_frtctl,r1
mov #0xE2,r0 /* TOCR = select OCRA, output 1 on compare match */
mov.b r0,@(0x07,r1) /* write TOCR */
mov.b @(0x07,r1),r0 /* read TOCR */
mov.l pci_mars_adapter,r1
mov.w r0,@(0x1A,r1) /* clear CMD IRQ */
nop
nop
nop
nop
! handle CMD IRQ (remove nops if more than 8 cycles)
rts
nop
.align 2
pci_mars_adapter:
.long 0x20004000
pci_sh2_frtctl:
.long 0xfffffe10
!-----------------------------------------------------------------------
! Primary PWM IRQ handler
!-----------------------------------------------------------------------
pri_pwm_irq:
! bump ints if necessary
mov.l ppi_sh2_frtctl,r1
mov #0xE2,r0 /* TOCR = select OCRA, output 1 on compare match */
mov.b r0,@(0x07,r1) /* write TOCR */
mov.b @(0x07,r1),r0 /* read TOCR */
mov.l ppi_mars_adapter,r1
mov.w r0,@(0x1C,r1) /* clear PWM IRQ */
nop
nop
nop
nop
! handle PWM IRQ (remove nops if more than 8 cycles)
rts
nop
.align 2
ppi_mars_adapter:
.long 0x20004000
ppi_sh2_frtctl:
.long 0xfffffe10
!-----------------------------------------------------------------------
! Primary DMA IRQ handler
!-----------------------------------------------------------------------
pri_dma_irq:
! bump ints if necessary
mov.l pdi_sh2_frtctl,r1
mov #0xE2,r0 /* TOCR = select OCRA, output 1 on compare match */
mov.b r0,@(0x07,r1) /* write TOCR */
mov.b @(0x07,r1),r0 /* read TOCR */
! handle DMA IRQ
rts
nop
.align 2
pdi_sh2_frtctl:
.long 0xfffffe10
!-----------------------------------------------------------------------
! Primary WDT IRQ handler
!-----------------------------------------------------------------------
pri_wdt_irq:
! bump ints if necessary
mov.l pwi_sh2_frtctl,r1
mov #0xE2,r0 /* TOCR = select OCRA, output 1 on compare match */
mov.b r0,@(0x07,r1) /* write TOCR */
mov.b @(0x07,r1),r0 /* read TOCR */
mov.l pwi_sh2_wdtctl,r1
mov.b @r1,r0 /* read WTCSR */
tst #0x80,r0 /* check OVF */
bt 1f /* no overflow */
mov.w pwi_clr_ovf,r0
mov.w r0,@r1 /* clear OVF */
! handle WDT overflow
mov.l pwi_ovf_count,r1
mov.l @r1,r0
add #1,r0
mov.l r0,@r1
1:
rts
nop
.align 2
pwi_sh2_frtctl:
.long 0xfffffe10
pwi_sh2_wdtctl:
.long 0xfffffe80
pwi_ovf_count:
.long _mars_pwdt_ovf_count
pwi_clr_ovf:
.word 0xa53e /* A5 = sel WTCSR, 3E = clr OVF, IT mode, timer enabled, clksel = Fs/4096 */
!-----------------------------------------------------------------------
! Primary RESET IRQ handler
!-----------------------------------------------------------------------
pri_vres_irq:
mov.l pvri_mars_adapter,r1
mov.w r0,@(0x14,r1) /* clear VRES IRQ */
mov #0x0F,r0
shll2 r0
shll2 r0
ldc r0,sr /* disallow ints */
mov.l pvri_pri_stk,r15
mov.l pvri_pri_vres,r0
jmp @r0
nop
.align 2
pvri_mars_adapter:
.long 0x20004000
pvri_pri_stk:
.long pri_stack /* Cold Start SP */
pvri_pri_vres:
.long pri_reset
!-----------------------------------------------------------------------
! The Secondary SH2 starts here
!-----------------------------------------------------------------------
sec_start:
! clear interrupt flags
mov.l _sec_int_clr,r1
mov.w r0,@-r1 /* PWM INT clear */
mov.w r0,@r1
mov.w r0,@-r1 /* CMD INT clear */
mov.w r0,@r1
mov.w r0,@-r1 /* H INT clear */
mov.w r0,@r1
mov.w r0,@-r1 /* V INT clear */
mov.w r0,@r1
mov.w r0,@-r1 /* VRES INT clear */
mov.w r0,@r1
mov.l _sec_sh2_frtctl,r1 /* Set Free Run Timer */
mov #0x00,r0
mov.b r0,@(0x00,r1) /* TIER = ints disabled */
mov #0xE2,r0
mov.b r0,@(0x07,r1) /* TOCR = select OCRA, output 1 on compare match */
mov #0x00,r0
mov.b r0,@(0x04,r1) /* OCR_H */
mov #0x01,r0
mov.b r0,@(0x05,r1) /* OCR_L => OCRA = 0x0001 */
mov #0,r0
mov.b r0,@(0x06,r1) /* TCR = input captured on falling edge, CKS = Fs/8 */
mov #1,r0
mov.b r0,@(0x01,r1) /* TCSR = clear FRC on match OCRA */
mov #0x00,r0
mov.b r0,@(0x03,r1) /* FRC_L */
mov.b r0,@(0x02,r1) /* FRC_H => clear FRC */
mov.l _sec_stk,r15
! wait for Primary SH2 and 68000 to finish init
mov.l _sec_sts,r0
mov.l _sec_ok,r1
1:
mov.l @r0,r2
nop
nop
cmp/eq r1,r2
bt 1b
mov.l _sec_adapter,r1
mov #0x00,r0
mov.b r0,@(1,r1) /* set int enables (different from primary despite same address!) */
mov #0x0F,r0
shll2 r0
shll2 r0
ldc r0,sr /* disallow ints */
! purge cache, turn it on, and run secondary()
mov.l _sec_cctl,r0
mov #0x11,r1 /* CP = cache purge, CE = cache enabled */
mov.b r1,@r0
mov.l _sec_go,r0
jmp @r0
nop
.align 2
_sec_int_clr:
.long 0x2000401E /* one word passed last int clr reg */
_sec_stk:
.long sec_stack /* Cold Start SP */
_sec_sts:
.long 0x20004024
_sec_sh2_frtctl:
.long 0xfffffe10
_sec_ok:
.ascii "S_OK"
_sec_adapter:
.long 0x20004000
_sec_cctl:
.long 0xFFFFFE92
_sec_go:
.long _secondary
!-----------------------------------------------------------------------
! Secondary exception handler
!-----------------------------------------------------------------------
sec_err:
rte
nop
!-----------------------------------------------------------------------
! Secondary IRQ handler
!-----------------------------------------------------------------------
sec_irq:
mov.l r0,@-r15
mov.l r1,@-r15
mov.l r2,@-r15
stc sr,r1 /* SR holds IRQ level in I3-I0 */
mov.w s_int_off,r2
ldc r2,sr /* disallow ints */
mov.l s_sys_frt_tocr,r2
mov #0xE0,r0 /* TOCR = select OCRA, output 0 on compare match */
mov.b r0,@r2
mov.b @r2,r0
sts.l pr,@-r15
mov r1,r0
shlr2 r0
and #0x3C,r0 /* int level to table offset */
mov.l s_int_jtable,r1
mov.l @(r0,r1),r0
jsr @r0
nop
lds.l @r15+,pr
mov.l @r15+,r2
mov.l @r15+,r1
mov.l @r15+,r0
rte
nop
.align 2
s_sys_frt_tocr:
.long 0xFFFFFE17
s_int_jtable:
.long _s_int_jtable
s_int_off:
.word 0x00F0
.align 4
_s_int_jtable:
.long sec_no_irq /* level 0 (ILL) */
.long sec_no_irq /* level 1 (FRT) */
.long sec_wdt_irq /* level 2 (WDT) */
.long sec_wdt_irq /* level 3 (WDT) */
.long sec_dma_irq /* level 4 (DMA) */
.long sec_dma_irq /* level 5 (DMA) */
.long sec_pwm_irq /* level 6 (PWM) */
.long sec_pwm_irq /* level 7 (PWM) */
.long sec_cmd_irq /* level 8 (CMD) */
.long sec_cmd_irq /* level 9 (CMD) */
.long sec_h_irq /* level 10 (HBI) */
.long sec_h_irq /* level 11 (HBI) */
.long sec_v_irq /* level 12 (VBI) */
.long sec_v_irq /* level 13 (VBI) */
.long sec_vres_irq /* level 14 (VRES) */
.long sec_vres_irq /* level 15 (VRES) */
!-----------------------------------------------------------------------
! Secondary No IRQ handler
!-----------------------------------------------------------------------
sec_no_irq:
rts
nop
!-----------------------------------------------------------------------
! Secondary V Blank IRQ handler
!-----------------------------------------------------------------------
sec_v_irq:
! bump ints if necessary
mov.l svi_sh2_frtctl,r1
mov #0xE2,r0 /* TOCR = select OCRA, output 1 on compare match */
mov.b r0,@(0x07,r1) /* write TOCR */
mov.b @(0x07,r1),r0 /* read TOCR */
mov.l svi_mars_adapter,r1
mov.w r0,@(0x16,r1) /* clear V IRQ */
nop
nop
nop
nop
! handle V IRQ (remove nops if more than 8 cycles)
rts
nop
.align 2
svi_mars_adapter:
.long 0x20004000
svi_sh2_frtctl:
.long 0xfffffe10
!-----------------------------------------------------------------------
! Secondary H Blank IRQ handler
!-----------------------------------------------------------------------
sec_h_irq:
! bump ints if necessary
mov.l shi_sh2_frtctl,r1
mov #0xE2,r0 /* TOCR = select OCRA, output 1 on compare match */
mov.b r0,@(0x07,r1) /* write TOCR */
mov.b @(0x07,r1),r0 /* read TOCR */
mov.l shi_mars_adapter,r1
mov.w r0,@(0x18,r1) /* clear H IRQ */
nop
nop
nop
nop
! handle H IRQ (remove nops if more than 8 cycles)
rts
nop
.align 2
shi_mars_adapter:
.long 0x20004000
shi_sh2_frtctl:
.long 0xfffffe10
!-----------------------------------------------------------------------
! Secondary Command IRQ handler
!-----------------------------------------------------------------------
sec_cmd_irq:
! bump ints if necessary
mov.l sci_sh2_frtctl,r1
mov #0xE2,r0 /* TOCR = select OCRA, output 1 on compare match */
mov.b r0,@(0x07,r1) /* write TOCR */
mov.b @(0x07,r1),r0 /* read TOCR */
mov.l sci_mars_adapter,r1
mov.w r0,@(0x1A,r1) /* clear CMD IRQ */
nop
nop
nop
nop
! handle CMD IRQ (remove nops if more than 8 cycles)
rts
nop
.align 2
sci_mars_adapter:
.long 0x20004000
sci_sh2_frtctl:
.long 0xfffffe10
!-----------------------------------------------------------------------
! Secondary PWM IRQ handler
!-----------------------------------------------------------------------
sec_pwm_irq:
! bump ints if necessary
mov.l spi_sh2_frtctl,r1
mov #0xE2,r0 /* TOCR = select OCRA, output 1 on compare match */
mov.b r0,@(0x07,r1) /* write TOCR */
mov.b @(0x07,r1),r0 /* read TOCR */
mov.l spi_mars_adapter,r1
mov.w r0,@(0x1C,r1) /* clear PWM IRQ */
nop
nop
nop
nop
! handle PWM IRQ (remove nops if more than 8 cycles)
rts
nop
.align 2
spi_mars_adapter:
.long 0x20004000
spi_sh2_frtctl:
.long 0xfffffe10
!-----------------------------------------------------------------------