forked from bminor/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfr30.cpu
1863 lines (1692 loc) · 52.4 KB
/
fr30.cpu
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
; Fujitsu FR30 CPU description. -*- Scheme -*-
; Copyright 2011 Free Software Foundation, Inc.
;
; Contributed by Red Hat Inc;
;
; This file is part of the GNU Binutils.
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
; MA 02110-1301, USA.
(define-rtl-version 0 8)
(include "simplify.inc")
; define-arch must appear first
(define-arch
(name fr30) ; name of cpu family
(comment "Fujitsu FR30")
(default-alignment forced)
(insn-lsb0? #f)
(machs fr30)
(isas fr30)
)
(define-isa
(name fr30)
(base-insn-bitsize 16)
(decode-assist (0 1 2 3 4 5 6 7)) ; Initial bitnumbers to decode insns by.
(liw-insns 1) ; The fr30 fetches 1 insn at a time.
(parallel-insns 1) ; The fr30 executes 1 insn at a time.
)
(define-cpu
; cpu names must be distinct from the architecture name and machine names.
; The "b" suffix stands for "base" and is the convention.
; The "f" suffix stands for "family" and is the convention.
(name fr30bf)
(comment "Fujitsu FR30 base family")
(endian big)
(word-bitsize 32)
)
(define-mach
(name fr30)
(comment "Generic FR30 cpu")
(cpu fr30bf)
)
; Model descriptions.
;
(define-model
(name fr30-1) (comment "fr30-1") (attrs)
(mach fr30)
(pipeline all "" () ((fetch) (decode) (execute) (writeback)))
; `state' is a list of variables for recording model state
(state
; bit mask of h-gr registers loaded from memory by previous insn
(load-regs UINT)
; bit mask of h-gr registers loaded from memory by current insn
(load-regs-pending UINT)
)
(unit u-exec "Execution Unit" ()
1 1 ; issue done
() ; state
((Ri INT -1) (Rj INT -1)) ; inputs
((Ri INT -1)) ; outputs
() ; profile action (default)
)
(unit u-cti "Branch Unit" ()
1 1 ; issue done
() ; state
((Ri INT -1)) ; inputs
((pc)) ; outputs
() ; profile action (default)
)
(unit u-load "Memory Load Unit" ()
1 1 ; issue done
() ; state
((Rj INT -1)
;(ld-mem AI)
) ; inputs
((Ri INT -1)) ; outputs
() ; profile action (default)
)
(unit u-store "Memory Store Unit" ()
1 1 ; issue done
() ; state
((Ri INT -1) (Rj INT -1)) ; inputs
() ; ((st-mem AI)) ; outputs
() ; profile action (default)
)
(unit u-ldm "LDM Memory Load Unit" ()
1 1 ; issue done
() ; state
((reglist INT)) ; inputs
() ; outputs
() ; profile action (default)
)
(unit u-stm "STM Memory Store Unit" ()
1 1 ; issue done
() ; state
((reglist INT)) ; inputs
() ; outputs
() ; profile action (default)
)
)
; The instruction fetch/execute cycle.
;
; This is how to fetch and decode an instruction.
; Leave it out for now
; (define-extract (const SI 0))
; This is how to execute a decoded instruction.
; Leave it out for now
; (define-execute (const SI 0))
; Instruction fields.
;
; Attributes:
; PCREL-ADDR: pc relative value (for reloc and disassembly purposes)
; ABS-ADDR: absolute address (for reloc and disassembly purposes?)
; RESERVED: bits are not used to decode insn, must be all 0
(dnf f-op1 "1st 4 bits of opcode" () 0 4)
(dnf f-op2 "2nd 4 bits of opcode" () 4 4)
(dnf f-op3 "3rd 4 bits of opcode" () 8 4)
(dnf f-op4 "4th 4 bits of opcode" () 12 4)
(dnf f-op5 "5th bit of opcode" () 4 1)
(dnf f-cc "condition code" () 4 4)
(dnf f-ccc "coprocessor calc code" () 16 8)
(dnf f-Rj "register Rj" () 8 4)
(dnf f-Ri "register Ri" () 12 4)
(dnf f-Rs1 "register Rs" () 8 4)
(dnf f-Rs2 "register Rs" () 12 4)
(dnf f-Rjc "register Rj" () 24 4)
(dnf f-Ric "register Ri" () 28 4)
(dnf f-CRj "coprocessor register" () 24 4)
(dnf f-CRi "coprocessor register" () 28 4)
(dnf f-u4 "4 bit 0 extended" () 8 4)
(dnf f-u4c "4 bit 0 extended" () 12 4)
(df f-i4 "4 bit sign extended" () 8 4 INT #f #f)
(df f-m4 "4 bit minus extended" () 8 4 UINT
; ??? This field takes a value in the range [-16,-1] but there
; doesn't seem a way to tell CGEN that. Use an unsigned field and
; disable range checks on insertion by masking. Restore the sign
; on extraction. CGEN generated documentation for insns that use
; this field will be wrong.
((value pc) (and WI value (const #xf)))
((value pc) (or WI value (const -16)))
)
(dnf f-u8 "8 bit unsigned" () 8 8)
(dnf f-i8 "8 bit unsigned" () 4 8)
(dnf f-i20-4 "upper 4 bits of i20" () 8 4)
(dnf f-i20-16 "lower 16 bits of i20" () 16 16)
(dnmf f-i20 "20 bit unsigned" () UINT
(f-i20-4 f-i20-16)
(sequence () ; insert
(set (ifield f-i20-4) (srl (ifield f-i20) (const 16)))
(set (ifield f-i20-16) (and (ifield f-i20) (const #xffff)))
)
(sequence () ; extract
(set (ifield f-i20) (or (sll (ifield f-i20-4) (const 16))
(ifield f-i20-16)))
)
)
(dnf f-i32 "32 bit immediate" (SIGN-OPT) 16 32)
(df f-udisp6 "6 bit unsigned offset" () 8 4 UINT
((value pc) (srl UWI value (const 2)))
((value pc) (sll UWI value (const 2)))
)
(df f-disp8 "8 bit signed offset" () 4 8 INT #f #f)
(df f-disp9 "9 bit signed offset" () 4 8 INT
((value pc) (sra WI value (const 1)))
((value pc) (sll WI value (const 1)))
)
(df f-disp10 "10 bit signed offset" () 4 8 INT
((value pc) (sra WI value (const 2)))
((value pc) (sll WI value (const 2)))
)
(df f-s10 "10 bit signed offset" () 8 8 INT
((value pc) (sra WI value (const 2)))
((value pc) (sll WI value (const 2)))
)
(df f-u10 "10 bit unsigned offset" () 8 8 UINT
((value pc) (srl UWI value (const 2)))
((value pc) (sll UWI value (const 2)))
)
(df f-rel9 "9 pc relative signed offset" (PCREL-ADDR) 8 8 INT
((value pc) (sra WI (sub WI value (add WI pc (const 2))) (const 1)))
((value pc) (add WI (sll WI value (const 1)) (add WI pc (const 2))))
)
(dnf f-dir8 "8 bit direct address" () 8 8)
(df f-dir9 "9 bit direct address" () 8 8 UINT
((value pc) (srl UWI value (const 1)))
((value pc) (sll UWI value (const 1)))
)
(df f-dir10 "10 bit direct address" () 8 8 UINT
((value pc) (srl UWI value (const 2)))
((value pc) (sll UWI value (const 2)))
)
(df f-rel12 "12 bit pc relative signed offset" (PCREL-ADDR) 5 11 INT
((value pc) (sra WI (sub WI value (add WI pc (const 2))) (const 1)))
((value pc) (add WI (sll WI value (const 1)) (add WI pc (const 2))))
)
(dnf f-reglist_hi_st "8 bit register mask for stm" () 8 8)
(dnf f-reglist_low_st "8 bit register mask for stm" () 8 8)
(dnf f-reglist_hi_ld "8 bit register mask for ldm" () 8 8)
(dnf f-reglist_low_ld "8 bit register mask for ldm" () 8 8)
; Enums.
; insn-op1: bits 0-3
; FIXME: should use die macro or some such
(define-normal-insn-enum insn-op1 "insn op1 enums" () OP1_ f-op1
("0" "1" "2" "3" "4" "5" "6" "7"
"8" "9" "A" "B" "C" "D" "E" "F")
)
; insn-op2: bits 4-7
; FIXME: should use die macro or some such
(define-normal-insn-enum insn-op2 "insn op2 enums" () OP2_ f-op2
("0" "1" "2" "3" "4" "5" "6" "7"
"8" "9" "A" "B" "C" "D" "E" "F")
)
; insn-op3: bits 8-11
; FIXME: should use die macro or some such
(define-normal-insn-enum insn-op3 "insn op3 enums" () OP3_ f-op3
("0" "1" "2" "3" "4" "5" "6" "7"
"8" "9" "A" "B" "C" "D" "E" "F")
)
; insn-op4: bits 12-15
; FIXME: should use die macro or some such
(define-normal-insn-enum insn-op4 "insn op4 enums" () OP4_ f-op4
("0")
)
; insn-op5: bit 4 (5th bit origin 0)
; FIXME: should use die macro or some such
(define-normal-insn-enum insn-op5 "insn op5 enums" () OP5_ f-op5
("0" "1")
)
; insn-cc: condition codes
; FIXME: should use die macro or some such
(define-normal-insn-enum insn-cc "insn cc enums" () CC_ f-cc
("ra" "no" "eq" "ne" "c" "nc" "n" "p" "v" "nv" "lt" "ge" "le" "gt" "ls" "hi")
)
; Hardware pieces.
; These entries list the elements of the raw hardware.
; They're also used to provide tables and other elements of the assembly
; language.
(dnh h-pc "program counter" (PC PROFILE) (pc) () () ())
(define-keyword
(name gr-names)
(enum-prefix H-GR-)
(values (r0 0) (r1 1) (r2 2) (r3 3) (r4 4) (r5 5) (r6 6) (r7 7)
(r8 8) (r9 9) (r10 10) (r11 11) (r12 12) (r13 13) (r14 14) (r15 15)
(ac 13) (fp 14) (sp 15))
)
(define-hardware
(name h-gr)
(comment "general registers")
(attrs PROFILE CACHE-ADDR)
(type register WI (16))
(indices extern-keyword gr-names)
)
(define-keyword
(name cr-names)
(enum-prefix H-CR-)
(values (cr0 0) (cr1 1) (cr2 2) (cr3 3)
(cr4 4) (cr5 5) (cr6 6) (cr7 7)
(cr8 8) (cr9 9) (cr10 10) (cr11 11)
(cr12 12) (cr13 13) (cr14 14) (cr15 15))
)
(define-hardware
(name h-cr)
(comment "coprocessor registers")
(attrs)
(type register WI (16))
(indices extern-keyword cr-names)
)
(define-keyword
(name dr-names)
(enum-prefix H-DR-)
(values (tbr 0) (rp 1) (ssp 2) (usp 3) (mdh 4) (mdl 5))
)
(define-hardware
(name h-dr)
(comment "dedicated registers")
(type register WI (6))
(indices extern-keyword dr-names)
(get (index) (c-call WI "@cpu@_h_dr_get_handler" index))
(set (index newval) (c-call VOID "@cpu@_h_dr_set_handler" index newval))
)
(define-hardware
(name h-ps)
(comment "processor status")
(type register UWI)
(indices keyword "" ((ps 0)))
(get () (c-call UWI "@cpu@_h_ps_get_handler"))
(set (newval) (c-call VOID "@cpu@_h_ps_set_handler" newval))
)
(dnh h-r13 "General Register 13 explicitly required"
()
(register WI)
(keyword "" ((r13 0)))
() ()
)
(dnh h-r14 "General Register 14 explicitly required"
()
(register WI)
(keyword "" ((r14 0)))
() ()
)
(dnh h-r15 "General Register 15 explicitly required"
()
(register WI)
(keyword "" ((r15 0)))
() ()
)
; These bits are actually part of the PS register but are accessed more
; often than the entire register, so define them directly. We can assemble
; the PS register from its components when necessary.
(dsh h-nbit "negative bit" () (register BI))
(dsh h-zbit "zero bit" () (register BI))
(dsh h-vbit "overflow bit" () (register BI))
(dsh h-cbit "carry bit" () (register BI))
(dsh h-ibit "interrupt enable bit" () (register BI))
(define-hardware
(name h-sbit)
(comment "stack bit")
(type register BI)
(get () (c-call BI "@cpu@_h_sbit_get_handler"))
(set (newval) (c-call VOID "@cpu@_h_sbit_set_handler" newval))
)
(dsh h-tbit "trace trap bit" () (register BI))
(dsh h-d0bit "division 0 bit" () (register BI))
(dsh h-d1bit "division 1 bit" () (register BI))
; These represent sub-registers within the program status register
(define-hardware
(name h-ccr)
(comment "condition code bits")
(type register UQI)
(get () (c-call UQI "@cpu@_h_ccr_get_handler"))
(set (newval) (c-call VOID "@cpu@_h_ccr_set_handler" newval))
)
(define-hardware
(name h-scr)
(comment "system condition bits")
(type register UQI)
(get () (c-call UQI "@cpu@_h_scr_get_handler"))
(set (newval) (c-call VOID "@cpu@_h_scr_set_handler" newval))
)
(define-hardware
(name h-ilm)
(comment "interrupt level mask")
(type register UQI)
(get () (c-call UQI "@cpu@_h_ilm_get_handler"))
(set (newval) (c-call VOID "@cpu@_h_ilm_set_handler" newval))
)
; Instruction Operands.
; These entries provide a layer between the assembler and the raw hardware
; description, and are used to refer to hardware elements in the semantic
; code. Usually there's a bit of over-specification, but in more complicated
; instruction sets there isn't.
; FR30 specific operand attributes:
(define-attr
(for operand)
(type boolean)
(name HASH-PREFIX)
(comment "immediates have an optional '#' prefix")
)
; ??? Convention says this should be o-sr, but then the insn definitions
; should refer to o-sr which is clumsy. The "o-" could be implicit, but
; then it should be implicit for all the symbols here, but then there would
; be confusion between (f-)simm8 and (h-)simm8.
; So for now the rule is exactly as it appears here.
(dnop Ri "destination register" () h-gr f-Ri)
(dnop Rj "source register" () h-gr f-Rj)
(dnop Ric "target register coproc insn" () h-gr f-Ric)
(dnop Rjc "source register coproc insn" () h-gr f-Rjc)
(dnop CRi "coprocessor register" () h-cr f-CRi)
(dnop CRj "coprocessor register" () h-cr f-CRj)
(dnop Rs1 "dedicated register" () h-dr f-Rs1)
(dnop Rs2 "dedicated register" () h-dr f-Rs2)
(dnop R13 "General Register 13" () h-r13 f-nil)
(dnop R14 "General Register 14" () h-r14 f-nil)
(dnop R15 "General Register 15" () h-r15 f-nil)
(dnop ps "Program Status register" () h-ps f-nil)
(dnop u4 "4 bit unsigned immediate" (HASH-PREFIX) h-uint f-u4)
(dnop u4c "4 bit unsigned immediate" (HASH-PREFIX) h-uint f-u4c)
(dnop u8 "8 bit unsigned immediate" (HASH-PREFIX) h-uint f-u8)
(dnop i8 "8 bit unsigned immediate" (HASH-PREFIX) h-uint f-i8)
(dnop udisp6 "6 bit unsigned immediate" (HASH-PREFIX) h-uint f-udisp6)
(dnop disp8 "8 bit signed immediate" (HASH-PREFIX) h-sint f-disp8)
(dnop disp9 "9 bit signed immediate" (HASH-PREFIX) h-sint f-disp9)
(dnop disp10 "10 bit signed immediate" (HASH-PREFIX) h-sint f-disp10)
(dnop s10 "10 bit signed immediate" (HASH-PREFIX) h-sint f-s10)
(dnop u10 "10 bit unsigned immediate" (HASH-PREFIX) h-uint f-u10)
(dnop i32 "32 bit immediate" (HASH-PREFIX) h-uint f-i32)
(define-operand
(name m4)
(comment "4 bit negative immediate")
(attrs HASH-PREFIX)
(type h-sint)
(index f-m4)
(handlers (print "m4"))
)
(define-operand
(name i20)
(comment "20 bit immediate")
(attrs HASH-PREFIX)
(type h-uint)
(index f-i20)
)
(dnop dir8 "8 bit direct address" () h-uint f-dir8)
(dnop dir9 "9 bit direct address" () h-uint f-dir9)
(dnop dir10 "10 bit direct address" () h-uint f-dir10)
(dnop label9 "9 bit pc relative address" () h-iaddr f-rel9)
(dnop label12 "12 bit pc relative address" () h-iaddr f-rel12)
(define-operand
(name reglist_low_ld)
(comment "8 bit low register mask for ldm")
(attrs)
(type h-uint)
(index f-reglist_low_ld)
(handlers (parse "low_register_list_ld")
(print "low_register_list_ld"))
)
(define-operand
(name reglist_hi_ld)
(comment "8 bit high register mask for ldm")
(attrs)
(type h-uint)
(index f-reglist_hi_ld)
(handlers (parse "hi_register_list_ld")
(print "hi_register_list_ld"))
)
(define-operand
(name reglist_low_st)
(comment "8 bit low register mask for stm")
(attrs)
(type h-uint)
(index f-reglist_low_st)
(handlers (parse "low_register_list_st")
(print "low_register_list_st"))
)
(define-operand
(name reglist_hi_st)
(comment "8 bit high register mask for stm")
(attrs)
(type h-uint)
(index f-reglist_hi_st)
(handlers (parse "hi_register_list_st")
(print "hi_register_list_st"))
)
(dnop cc "condition codes" () h-uint f-cc)
(dnop ccc "coprocessor calc" (HASH-PREFIX) h-uint f-ccc)
(dnop nbit "negative bit" (SEM-ONLY) h-nbit f-nil)
(dnop vbit "overflow bit" (SEM-ONLY) h-vbit f-nil)
(dnop zbit "zero bit" (SEM-ONLY) h-zbit f-nil)
(dnop cbit "carry bit" (SEM-ONLY) h-cbit f-nil)
(dnop ibit "interrupt bit" (SEM-ONLY) h-ibit f-nil)
(dnop sbit "stack bit" (SEM-ONLY) h-sbit f-nil)
(dnop tbit "trace trap bit" (SEM-ONLY) h-tbit f-nil)
(dnop d0bit "division 0 bit" (SEM-ONLY) h-d0bit f-nil)
(dnop d1bit "division 1 bit" (SEM-ONLY) h-d1bit f-nil)
(dnop ccr "condition code bits" (SEM-ONLY) h-ccr f-nil)
(dnop scr "system condition bits" (SEM-ONLY) h-scr f-nil)
(dnop ilm "interrupt level mask" (SEM-ONLY) h-ilm f-nil)
; Instruction definitions.
;
; Notes:
; - dni is short for "define-normal-instruction"
; FR30 specific insn attributes:
(define-attr
(for insn)
(type boolean)
(name NOT-IN-DELAY-SLOT)
(comment "insn can't go in delay slot")
)
; Sets zbit and nbit based on the value of x
;
(define-pmacro (set-z-and-n x)
(sequence ()
(set zbit (eq x (const 0)))
(set nbit (lt x (const 0))))
)
; Binary integer instruction which sets status bits
;
(define-pmacro (binary-int-op name insn comment opc1 opc2 op arg1 arg2)
(dni name
(.str insn " " comment)
()
(.str insn " $" arg1 ",$" arg2)
(+ opc1 opc2 arg1 arg2)
(sequence ()
(set vbit ((.sym op -oflag) arg2 arg1 (const 0)))
(set cbit ((.sym op -cflag) arg2 arg1 (const 0)))
(set arg2 (op arg2 arg1))
(set-z-and-n arg2))
()
)
)
; Binary integer instruction which does *not* set status bits
;
(define-pmacro (binary-int-op-n name insn comment opc1 opc2 op arg1 arg2)
(dni name
(.str insn " " comment)
()
(.str insn " $" arg1 ",$" arg2)
(+ opc1 opc2 arg1 arg2)
(set arg2 (op arg2 arg1))
()
)
)
; Binary integer instruction with carry which sets status bits
;
(define-pmacro (binary-int-op-c name insn comment opc1 opc2 op arg1 arg2)
(dni name
(.str insn " " comment)
()
(.str insn " $" arg1 ",$" arg2)
(+ opc1 opc2 arg1 arg2)
(sequence ((WI tmp))
(set tmp ((.sym op c) arg2 arg1 cbit))
(set vbit ((.sym op -oflag) arg2 arg1 cbit))
(set cbit ((.sym op -cflag) arg2 arg1 cbit))
(set arg2 tmp)
(set-z-and-n arg2))
()
)
)
(binary-int-op add add "reg/reg" OP1_A OP2_6 add Rj Ri)
(binary-int-op addi add "immed/reg" OP1_A OP2_4 add u4 Ri)
(binary-int-op add2 add2 "immed/reg" OP1_A OP2_5 add m4 Ri)
(binary-int-op-c addc addc "reg/reg" OP1_A OP2_7 add Rj Ri)
(binary-int-op-n addn addn "reg/reg" OP1_A OP2_2 add Rj Ri)
(binary-int-op-n addni addn "immed/reg" OP1_A OP2_0 add u4 Ri)
(binary-int-op-n addn2 addn2 "immed/reg" OP1_A OP2_1 add m4 Ri)
(binary-int-op sub sub "reg/reg" OP1_A OP2_C sub Rj Ri)
(binary-int-op-c subc subc "reg/reg" OP1_A OP2_D sub Rj Ri)
(binary-int-op-n subn subn "reg/reg" OP1_A OP2_E sub Rj Ri)
; Integer compare instruction
;
(define-pmacro (int-cmp name insn comment opc1 opc2 arg1 arg2)
(dni name
(.str insn " " comment)
()
(.str insn " $" arg1 ",$" arg2)
(+ opc1 opc2 arg1 arg2)
(sequence ((WI tmp1))
(set vbit (sub-oflag arg2 arg1 (const 0)))
(set cbit (sub-cflag arg2 arg1 (const 0)))
(set tmp1 (sub arg2 arg1))
(set-z-and-n tmp1)
)
()
)
)
(int-cmp cmp cmp "reg/reg" OP1_A OP2_A Rj Ri)
(int-cmp cmpi cmp "immed/reg" OP1_A OP2_8 u4 Ri)
(int-cmp cmp2 cmp2 "immed/reg" OP1_A OP2_9 m4 Ri)
; Binary logical instruction
;
(define-pmacro (binary-logical-op name insn comment opc1 opc2 op arg1 arg2)
(dni name
(.str insn " " comment)
()
(.str insn " $" arg1 ",$" arg2)
(+ opc1 opc2 arg1 arg2)
(sequence ()
(set arg2 (op arg2 arg1))
(set-z-and-n arg2))
()
)
)
(binary-logical-op and and "reg/reg" OP1_8 OP2_2 and Rj Ri)
(binary-logical-op or or "reg/reg" OP1_9 OP2_2 or Rj Ri)
(binary-logical-op eor eor "reg/reg" OP1_9 OP2_A xor Rj Ri)
(define-pmacro (les-units model) ; les: load-exec-store
(model (unit u-exec) (unit u-load) (unit u-store))
)
; Binary logical instruction to memory
;
(define-pmacro (binary-logical-op-m name insn comment opc1 opc2 mode op arg1 arg2)
(dni name
(.str insn " " comment)
(NOT-IN-DELAY-SLOT)
(.str insn " $" arg1 ",@$" arg2)
(+ opc1 opc2 arg1 arg2)
(sequence ((mode tmp))
(set mode tmp (op mode (mem mode arg2) arg1))
(set-z-and-n tmp)
(set mode (mem mode arg2) tmp))
((les-units fr30-1))
)
)
(binary-logical-op-m andm and "reg/mem" OP1_8 OP2_4 WI and Rj Ri)
(binary-logical-op-m andh andh "reg/mem" OP1_8 OP2_5 HI and Rj Ri)
(binary-logical-op-m andb andb "reg/mem" OP1_8 OP2_6 QI and Rj Ri)
(binary-logical-op-m orm or "reg/mem" OP1_9 OP2_4 WI or Rj Ri)
(binary-logical-op-m orh orh "reg/mem" OP1_9 OP2_5 HI or Rj Ri)
(binary-logical-op-m orb orb "reg/mem" OP1_9 OP2_6 QI or Rj Ri)
(binary-logical-op-m eorm eor "reg/mem" OP1_9 OP2_C WI xor Rj Ri)
(binary-logical-op-m eorh eorh "reg/mem" OP1_9 OP2_D HI xor Rj Ri)
(binary-logical-op-m eorb eorb "reg/mem" OP1_9 OP2_E QI xor Rj Ri)
; Binary logical instruction to low half of byte in memory
;
(dni bandl
"bandl #u4,@Ri"
(NOT-IN-DELAY-SLOT)
"bandl $u4,@$Ri"
(+ OP1_8 OP2_0 u4 Ri)
(set QI (mem QI Ri)
(and QI
(or QI u4 (const #xf0))
(mem QI Ri)))
((les-units fr30-1))
)
(dni borl
"borl #u4,@Ri"
(NOT-IN-DELAY-SLOT)
"borl $u4,@$Ri"
(+ OP1_9 OP2_0 u4 Ri)
(set QI (mem QI Ri) (or QI u4 (mem QI Ri)))
((les-units fr30-1))
)
(dni beorl
"beorl #u4,@Ri"
(NOT-IN-DELAY-SLOT)
"beorl $u4,@$Ri"
(+ OP1_9 OP2_8 u4 Ri)
(set QI (mem QI Ri) (xor QI u4 (mem QI Ri)))
((les-units fr30-1))
)
; Binary logical instruction to high half of byte in memory
;
(dni bandh
"bandh #u4,@Ri"
(NOT-IN-DELAY-SLOT)
"bandh $u4,@$Ri"
(+ OP1_8 OP2_1 u4 Ri)
(set QI (mem QI Ri)
(and QI
(or QI (sll QI u4 (const 4)) (const #x0f))
(mem QI Ri)))
((les-units fr30-1))
)
(define-pmacro (binary-or-op-mh name insn opc1 opc2 op arg1 arg2)
(dni name
(.str name " #" arg1 ",@" args)
(NOT-IN-DELAY-SLOT)
(.str name " $" arg1 ",@$" arg2)
(+ opc1 opc2 arg1 arg2)
(set QI (mem QI arg2)
(insn QI
(sll QI arg1 (const 4))
(mem QI arg2)))
((les-units fr30-1))
)
)
(binary-or-op-mh borh or OP1_9 OP2_1 or u4 Ri)
(binary-or-op-mh beorh xor OP1_9 OP2_9 xor u4 Ri)
(dni btstl
"btstl #u4,@Ri"
(NOT-IN-DELAY-SLOT)
"btstl $u4,@$Ri"
(+ OP1_8 OP2_8 u4 Ri)
(sequence ((QI tmp))
(set tmp (and QI u4 (mem QI Ri)))
(set zbit (eq tmp (const 0)))
(set nbit (const 0)))
((fr30-1 (unit u-load) (unit u-exec (cycles 2))))
)
(dni btsth
"btsth #u4,@Ri"
(NOT-IN-DELAY-SLOT)
"btsth $u4,@$Ri"
(+ OP1_8 OP2_9 u4 Ri)
(sequence ((QI tmp))
(set tmp (and QI (sll QI u4 (const 4)) (mem QI Ri)))
(set zbit (eq tmp (const 0)))
(set nbit (lt tmp (const 0))))
((fr30-1 (unit u-load) (unit u-exec (cycles 2))))
)
(dni mul
"mul Rj,Ri"
(NOT-IN-DELAY-SLOT)
"mul $Rj,$Ri"
(+ OP1_A OP2_F Rj Ri)
(sequence ((DI tmp))
(set tmp (mul DI (ext DI Rj) (ext DI Ri)))
(set (reg h-dr 5) (trunc WI tmp))
(set (reg h-dr 4) (trunc WI (srl tmp (const 32))))
(set nbit (lt (reg h-dr 5) (const 0)))
(set zbit (eq tmp (const DI 0)))
(set vbit (orif
(gt tmp (const DI #x7fffffff))
(lt tmp (neg (const DI #x80000000))))))
((fr30-1 (unit u-exec (cycles 5))))
)
(dni mulu
"mulu Rj,Ri"
(NOT-IN-DELAY-SLOT)
"mulu $Rj,$Ri"
(+ OP1_A OP2_B Rj Ri)
(sequence ((DI tmp))
(set tmp (mul DI (zext DI Rj) (zext DI Ri)))
(set (reg h-dr 5) (trunc WI tmp))
(set (reg h-dr 4) (trunc WI (srl tmp (const 32))))
(set nbit (lt (reg h-dr 4) (const 0)))
(set zbit (eq (reg h-dr 5) (const 0)))
(set vbit (ne (reg h-dr 4) (const 0))))
((fr30-1 (unit u-exec (cycles 5))))
)
(dni mulh
"mulh Rj,Ri"
(NOT-IN-DELAY-SLOT)
"mulh $Rj,$Ri"
(+ OP1_B OP2_F Rj Ri)
(sequence ()
(set (reg h-dr 5) (mul (trunc HI Rj) (trunc HI Ri)))
(set nbit (lt (reg h-dr 5) (const 0)))
(set zbit (ge (reg h-dr 5) (const 0))))
((fr30-1 (unit u-exec (cycles 3))))
)
(dni muluh
"muluh Rj,Ri"
(NOT-IN-DELAY-SLOT)
"muluh $Rj,$Ri"
(+ OP1_B OP2_B Rj Ri)
(sequence ()
(set (reg h-dr 5) (mul (and Rj (const #xffff))
(and Ri (const #xffff))))
(set nbit (lt (reg h-dr 5) (const 0)))
(set zbit (ge (reg h-dr 5) (const 0))))
((fr30-1 (unit u-exec (cycles 3))))
)
(dni div0s
"div0s Ri"
()
"div0s $Ri"
(+ OP1_9 OP2_7 OP3_4 Ri)
(sequence ()
(set d0bit (lt (reg h-dr 5) (const 0)))
(set d1bit (xor d0bit (lt Ri (const 0))))
(if (ne d0bit (const 0))
(set (reg h-dr 4) (const #xffffffff))
(set (reg h-dr 4) (const 0))))
()
)
(dni div0u
"div0u Ri"
()
"div0u $Ri"
(+ OP1_9 OP2_7 OP3_5 Ri)
(sequence ()
(set d0bit (const 0))
(set d1bit (const 0))
(set (reg h-dr 4) (const 0)))
()
)
(dni div1
"div1 Ri"
()
"div1 $Ri"
(+ OP1_9 OP2_7 OP3_6 Ri)
(sequence ((WI tmp))
(set (reg h-dr 4) (sll (reg h-dr 4) (const 1)))
(if (lt (reg h-dr 5) (const 0))
(set (reg h-dr 4) (add (reg h-dr 4) (const 1))))
(set (reg h-dr 5) (sll (reg h-dr 5) (const 1)))
(if (eq d1bit (const 1))
(sequence ()
(set tmp (add (reg h-dr 4) Ri))
(set cbit (add-cflag (reg h-dr 4) Ri (const 0))))
(sequence ()
(set tmp (sub (reg h-dr 4) Ri))
(set cbit (sub-cflag (reg h-dr 4) Ri (const 0)))))
(if (not (xor (xor d0bit d1bit) cbit))
(sequence ()
(set (reg h-dr 4) tmp)
(set (reg h-dr 5) (or (reg h-dr 5) (const 1)))))
(set zbit (eq (reg h-dr 4) (const 0))))
()
)
(dni div2
"div2 Ri"
()
"div2 $Ri"
(+ OP1_9 OP2_7 OP3_7 Ri)
(sequence ((WI tmp))
(if (eq d1bit (const 1))
(sequence ()
(set tmp (add (reg h-dr 4) Ri))
(set cbit (add-cflag (reg h-dr 4) Ri (const 0))))
(sequence ()
(set tmp (sub (reg h-dr 4) Ri))
(set cbit (sub-cflag (reg h-dr 4) Ri (const 0)))))
(if (eq tmp (const 0))
(sequence ()
(set zbit (const 1))
(set (reg h-dr 4) (const 0)))
(set zbit (const 0))))
()
)
(dni div3
"div3"
()
"div3"
(+ OP1_9 OP2_F OP3_6 OP4_0)
(if (eq zbit (const 1))
(set (reg h-dr 5) (add (reg h-dr 5) (const 1))))
()
)
(dni div4s
"div4s"
()
"div4s"
(+ OP1_9 OP2_F OP3_7 OP4_0)
(if (eq d1bit (const 1))
(set (reg h-dr 5) (neg (reg h-dr 5))))
()
)
(define-pmacro (leftshift-op name insn opc1 opc2 arg1 arg2 shift-expr)
(dni name
(.str insn " " arg1 "," arg2)
()
(.str insn " $" arg1 ",$" arg2)
(+ opc1 opc2 arg1 arg2)
(sequence ((WI shift))
(set shift shift-expr)
(if (ne shift (const 0))
(sequence ()
(set cbit (ne (and arg2
(sll (const 1)
(sub (const 32) shift)))
(const 0)))
(set arg2 (sll arg2 shift)))
(set cbit (const 0)))
(set nbit (lt arg2 (const 0)))
(set zbit (eq arg2 (const 0))))
()
)
)
(leftshift-op lsl lsl OP1_B OP2_6 Rj Ri (and Rj (const #x1f)))
(leftshift-op lsli lsl OP1_B OP2_4 u4 Ri u4)
(leftshift-op lsl2 lsl2 OP1_B OP2_5 u4 Ri (add u4 (const #x10)))
(define-pmacro (rightshift-op name insn opc1 opc2 op arg1 arg2 shift-expr)
(dni name
(.str insn " " arg1 "," arg2)
()
(.str insn " $" arg1 ",$" arg2)
(+ opc1 opc2 arg1 arg2)
(sequence ((WI shift))
(set shift shift-expr)
(if (ne shift (const 0))
(sequence ()
(set cbit (ne (and arg2
(sll (const 1)
(sub shift (const 1))))
(const 0)))
(set arg2 (op arg2 shift)))
(set cbit (const 0)))
(set nbit (lt arg2 (const 0)))
(set zbit (eq arg2 (const 0))))
()
)
)
(rightshift-op lsr lsr OP1_B OP2_2 srl Rj Ri (and Rj (const #x1f)))
(rightshift-op lsri lsr OP1_B OP2_0 srl u4 Ri u4)
(rightshift-op lsr2 lsr2 OP1_B OP2_1 srl u4 Ri (add u4 (const #x10)))
(rightshift-op asr asr OP1_B OP2_A sra Rj Ri (and Rj (const #x1f)))
(rightshift-op asri asr OP1_B OP2_8 sra u4 Ri u4)
(rightshift-op asr2 asr2 OP1_B OP2_9 sra u4 Ri (add u4 (const #x10)))
(dni ldi8
"load 8 bit unsigned immediate"
()
"ldi:8 $i8,$Ri"
(+ OP1_C i8 Ri)
(set Ri i8)
()
)
; Typing ldi:8 in in emacs is a pain.
(dnmi ldi8m "ldi:8 without the colon"
(NO-DIS)
"ldi8 $i8,$Ri"
(emit ldi8 i8 Ri)
)
(dni ldi20
"load 20 bit unsigned immediate"
(NOT-IN-DELAY-SLOT)
"ldi:20 $i20,$Ri"
(+ OP1_9 OP2_B Ri i20)
(set Ri i20)
((fr30-1 (unit u-exec (cycles 2))))
)
; Typing ldi:20 in in emacs is a pain.
(dnmi ldi20m "ldi:20 without the colon"
(NO-DIS)
"ldi20 $i20,$Ri"