forked from bminor/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmep-core.cpu
3082 lines (2670 loc) · 96.4 KB
/
mep-core.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
; Toshiba MeP Media Engine architecture 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.
(include "simplify.inc")
(define-pmacro isa-enum ()
(isas mep
; begin-isa-enum
ext_core1 ext_cop1_16 ext_cop1_32 ext_cop1_48 ext_cop1_64
; end-isa-enum
)
)
(define-arch
(name mep)
(comment "Toshiba MeP Media Engine")
(insn-lsb0? #f) ;; work around cgen limitation
(machs mep h1 c5)
isa-enum
)
(define-isa
(name mep)
(comment "MeP core instruction set")
(default-insn-word-bitsize 32)
(default-insn-bitsize 32)
(base-insn-bitsize 32)
)
; begin-isas
(define-isa
(name ext_core1)
(comment "MeP core extension instruction set")
(default-insn-word-bitsize 32)
(default-insn-bitsize 32)
(base-insn-bitsize 32)
)
(define-isa
(name ext_cop1_16)
(comment "MeP coprocessor instruction set")
(default-insn-word-bitsize 32)
(default-insn-bitsize 32)
(base-insn-bitsize 32)
)
(define-isa
(name ext_cop1_32)
(comment "MeP coprocessor instruction set")
(default-insn-word-bitsize 32)
(default-insn-bitsize 32)
(base-insn-bitsize 32)
)
(define-isa
(name ext_cop1_48)
(comment "MeP coprocessor instruction set")
(default-insn-word-bitsize 32)
(default-insn-bitsize 32)
(base-insn-bitsize 32)
)
(define-isa
(name ext_cop1_64)
(comment "MeP coprocessor instruction set")
(default-insn-word-bitsize 32)
(default-insn-bitsize 32)
(base-insn-bitsize 32)
)
(define-pmacro all-mep-isas () (ISA mep,ext_core1,ext_cop1_16,ext_cop1_32,ext_cop1_48,ext_cop1_64))
(define-pmacro all-mep-core-isas () (ISA mep,ext_core1,ext_cop1_32))
(define-pmacro all-core-isa-list () mep,ext_core1)
; end-isas
(define-cpu
(name mepf)
(comment "MeP family")
(endian either)
(insn-chunk-bitsize 16)
(word-bitsize 32)
)
(define-mach
(name mep)
(comment "MeP media engine")
(cpu mepf)
isa-enum
)
(define-mach
(name h1)
(comment "H1 media engine")
(cpu mepf)
isa-enum
)
(define-mach
(name c5)
(comment "C5 media engine")
(cpu mepf)
isa-enum
)
(define-model
(name mep)
(comment "MeP media engine processor")
(mach c5) ; mach gets changed by MeP-Integrator
(unit u-exec "execution unit" ()
1 1 ; issue done
() () () ())
; Branch unit
(unit u-branch "Branch Unit" ()
0 0 ; issue done
() ; state
() ; inputs
((pc)) ; outputs
() ; profile action (default)
)
; Multiply unit
(unit u-multiply "Multiply Unit" ()
0 0 ; issue done
() ; state
() ; inputs
() ; outputs
() ; profile action (default)
)
; Divide unit
(unit u-divide "Divide Unit" ()
0 0 ; issue done
() ; state
() ; inputs
() ; outputs
() ; profile action (default)
)
; Stcb unit
(unit u-stcb "stcb Unit" ()
0 0 ; issue done
() ; state
() ; inputs
() ; outputs
() ; profile action (default)
)
; Ldcb unit
(unit u-ldcb "ldcb Unit" ()
0 0 ; issue done
() ; state
() ; inputs
() ; outputs
() ; profile action (default)
)
; Load gpr unit
(unit u-load-gpr "Load into GPR Unit" ()
0 0 ; issue done
() ; state
() ; inputs
((loadreg INT -1)) ; outputs
() ; profile action (default)
)
(unit u-ldcb-gpr "Ldcb into GPR Unit" ()
0 0 ; issue done
() ; state
() ; inputs
((loadreg INT -1)) ; outputs
() ; profile action (default)
)
; Multiply into GPR unit
(unit u-mul-gpr "Multiply into GPR Unit" ()
0 0 ; issue done
() ; state
() ; inputs
((resultreg INT -1)) ; outputs
() ; profile action (default)
)
; Use gpr unit -- stalls if GPR not ready
(unit u-use-gpr "Use GPR Unit" ()
0 0 ; issue done
() ; state
((usereg INT -1)) ; inputs
() ; outputs
() ; profile action (default)
)
; Use ctrl-reg unit -- stalls if CTRL-REG not ready
(unit u-use-ctrl-reg "Use CTRL-REG Unit" ()
0 0 ; issue done
() ; state
((usereg INT -1)) ; inputs
() ; outputs
() ; profile action (default)
)
; Store ctrl-reg unit -- stalls if CTRL-REG not ready
(unit u-store-ctrl-reg "Store CTRL-REG Unit" ()
0 0 ; issue done
() ; state
() ; inputs
((storereg INT -1)) ; outputs
() ; profile action (default)
)
)
; Hardware elements.
(dnh h-pc "program counter" (PC PROFILE all-mep-isas) (pc) () () ())
(define-hardware
(name h-gpr)
(comment "General purpose registers")
(attrs all-mep-isas CACHE-ADDR PROFILE)
(type register SI (16))
(indices keyword "$"
(("0" 0) ("1" 1) ("2" 2) ("3" 3) ("4" 4) ("5" 5)
("6" 6) ("7" 7) ("8" 8) ("9" 9) ("10" 10) ("11" 11)
; "$8" is the preferred name for register 8, but "$tp", "$gp"
; and "$sp" are preferred for their respective registers.
(fp 8) (tp 13) (gp 14) (sp 15)
("12" 12) ("13" 13) ("14" 14) ("15" 15)))
)
(define-hardware
(name h-csr)
(comment "Control/special registers")
(attrs all-mep-isas PROFILE)
(type register SI (32))
(indices keyword "$"
((pc 0) (lp 1) (sar 2) (rpb 4) (rpe 5) (rpc 6)
(hi 7) (lo 8) (mb0 12) (me0 13) (mb1 14) (me1 15)
(psw 16) (id 17) (tmp 18) (epc 19) (exc 20) (cfg 21)
(npc 23) (dbg 24) (depc 25) (opt 26) (rcfg 27) (ccfg 28)
; begin-extra-csr-registers
(vid 22)
; end-extra-csr-registers
))
(get (index) (c-call SI "cgen_get_csr_value" index))
(set (index newval) (c-call VOID "cgen_set_csr_value" index newval))
)
(define-pmacro (-reg-pair n) ((.sym n) n))
(define-hardware
(name h-cr64)
(comment "64-bit coprocessor registers")
(attrs all-mep-isas)
; This assumes that the data path of the co-pro is 64 bits.
(type register DI (32))
(indices keyword "$c" (.map -reg-pair (.iota 32)))
(set (index newval) (c-call VOID "h_cr64_queue_set" index newval))
)
(define-hardware
(name h-cr64-w)
(comment "64-bit coprocessor registers, pending writes")
(attrs all-mep-isas)
; This assumes that the data path of the co-pro is 64 bits.
(type register DI (32))
)
(define-hardware
(name h-cr)
(comment "32-bit coprocessor registers")
(attrs all-mep-isas VIRTUAL)
(type register SI (32))
(indices keyword "$c" (.map -reg-pair (.iota 32)))
(set (index newval) (c-call VOID "h_cr64_set" index (ext DI newval)))
(get (index) (trunc SI (c-call DI "h_cr64_get" index)))
)
;; Given a coprocessor control register number N, expand to a
;; name/index pair: ($ccrN N)
(define-pmacro (-ccr-reg-pair n) ((.sym "$ccr" n) n))
(define-hardware
(name h-ccr)
(comment "Coprocessor control registers")
(attrs all-mep-isas)
(type register SI (64))
(indices keyword "" (.map -ccr-reg-pair (.iota 64)))
(set (index newval) (c-call VOID "h_ccr_queue_set" index newval))
)
(define-hardware
(name h-ccr-w)
(comment "Coprocessor control registers, pending writes")
(attrs all-mep-isas)
(type register SI (64))
)
; Instruction fields. Bit numbering reversed.
; Conventions:
;
; N = number of bits in value
; A = alignment (2 or 4, omit for 1)
; B = leftmost (i.e. closest to zero) bit position
;
; -- Generic Fields (f-*) --
; N number of bits in *value* (1-24)
; [us] signed vs unsigned
; B position of left-most bit (4-16)
; aA opt. alignment (2=drop 1 lsb, 4=drop 2 lsbs, etc)
; n opt. for noncontiguous fields
; f-foo-{hi,lo} msb/lsb parts of field f-foo
;
; -- Operands --
; pcrelNaA PC-relative branch target (signed)
; pcabsNaA Absolute branch target (unsigned)
;
; [us]dispNaA [un]signed displacement
; [us]immN [un]signed immediate value
; addrNaA absolute address (unsigned)
;
; Additional prefixes may be used for special cases.
(dnf f-major "major opcode" (all-mep-core-isas) 0 4)
(dnf f-rn "register n" (all-mep-core-isas) 4 4)
(dnf f-rn3 "register 0-7" (all-mep-core-isas) 5 3)
(dnf f-rm "register m" (all-mep-core-isas) 8 4)
(dnf f-rl "register l" (all-mep-core-isas) 12 4)
(dnf f-sub2 "sub opcode (2 bits)" (all-mep-core-isas) 14 2)
(dnf f-sub3 "sub opcode (3 bits)" (all-mep-core-isas) 13 3)
(dnf f-sub4 "sub opcode (4 bits)" (all-mep-core-isas) 12 4)
(dnf f-ext "extended field" (all-mep-core-isas) 16 8)
(dnf f-ext4 "extended field 16:4" (all-mep-core-isas) 16 4)
(dnf f-ext62 "extended field 20:2" (all-mep-core-isas) 20 2)
(dnf f-crn "copro register n" (all-mep-core-isas) 4 4)
(df f-csrn-hi "cr hi 1u15" (all-mep-core-isas) 15 1 UINT #f #f)
(df f-csrn-lo "cr lo 4u8" (all-mep-core-isas) 8 4 UINT #f #f)
(define-multi-ifield
(name f-csrn)
(comment "control reg")
(attrs all-mep-core-isas)
(mode UINT)
(subfields f-csrn-hi f-csrn-lo)
(insert (sequence ()
(set (ifield f-csrn-lo) (and (ifield f-csrn) #xf))
(set (ifield f-csrn-hi) (srl (ifield f-csrn) 4))))
(extract (set (ifield f-csrn)
(or (sll (ifield f-csrn-hi) 4) (ifield f-csrn-lo))))
)
(df f-crnx-hi "crx hi 1u28" (all-mep-core-isas) 28 1 UINT #f #f)
(df f-crnx-lo "crx lo 4u4" (all-mep-core-isas) 4 4 UINT #f #f)
(define-multi-ifield
(name f-crnx)
(comment "copro register n (0-31)")
(attrs all-mep-core-isas)
(mode UINT)
(subfields f-crnx-hi f-crnx-lo)
(insert (sequence ()
(set (ifield f-crnx-lo) (and (ifield f-crnx) #xf))
(set (ifield f-crnx-hi) (srl (ifield f-crnx) 4))))
(extract (set (ifield f-crnx)
(or (sll (ifield f-crnx-hi) 4) (ifield f-crnx-lo))))
)
; Miscellaneous fields.
(define-pmacro (dnfb n)
(dnf (.sym f- n) (.str "bit " n) (all-mep-isas) n 1))
; Define small fields used throughout the instruction set description.
; Each field (eg. `f-N') is at single bit field at position N.
(dnfb 0)
(dnfb 1)
(dnfb 2)
(dnfb 3)
(dnfb 4)
(dnfb 5)
(dnfb 6)
(dnfb 7)
(dnfb 8)
(dnfb 9)
(dnfb 10)
(dnfb 11)
(dnfb 12)
(dnfb 13)
(dnfb 14)
(dnfb 15)
(dnfb 16)
(dnfb 17)
(dnfb 18)
(dnfb 19)
(dnfb 20)
(dnfb 21)
(dnfb 22)
(dnfb 23)
(dnfb 24)
(dnfb 25)
(dnfb 26)
(dnfb 27)
(dnfb 28)
(dnfb 29)
(dnfb 30)
(dnfb 31)
; Branch/Jump target addresses
(df f-8s8a2 "pc-rel addr (8 bits)" (all-mep-core-isas PCREL-ADDR) 8 7 INT
((value pc) (sra SI (sub SI value pc) 1))
((value pc) (add SI (sll SI value 1) pc)))
(df f-12s4a2 "pc-rel addr (12 bits)" (all-mep-core-isas PCREL-ADDR) 4 11 INT
((value pc) (sra SI (sub SI value pc) 1))
((value pc) (add SI (sll SI value 1) pc)))
(df f-17s16a2 "pc-rel addr (17 bits)" (all-mep-core-isas PCREL-ADDR) 16 16 INT
((value pc) (sra SI (sub SI value pc) 1))
((value pc) (add SI (sll SI value 1) pc)))
(df f-24s5a2n-hi "24s5a2n hi 16s16" (all-mep-core-isas PCREL-ADDR) 16 16 INT #f #f)
(df f-24s5a2n-lo "24s5a2n lo 7s5a2" (all-mep-core-isas PCREL-ADDR) 5 7 UINT #f #f)
(define-multi-ifield
(name f-24s5a2n)
(comment "pc-rel addr (24 bits align 2)")
(attrs all-mep-core-isas PCREL-ADDR)
(mode INT)
(subfields f-24s5a2n-hi f-24s5a2n-lo)
(insert (sequence ()
(set (ifield f-24s5a2n)
(sub (ifield f-24s5a2n) pc))
(set (ifield f-24s5a2n-lo)
(srl (and (ifield f-24s5a2n) #xfe) 1))
(set (ifield f-24s5a2n-hi)
(sra INT (ifield f-24s5a2n) 8))))
(extract (set (ifield f-24s5a2n)
(add SI (or (sll (ifield f-24s5a2n-hi) 8)
(sll (ifield f-24s5a2n-lo) 1))
pc)))
)
(df f-24u5a2n-hi "24u5a2n hi 16u16" (all-mep-core-isas) 16 16 UINT #f #f)
(df f-24u5a2n-lo "24u5a2n lo 7u5a2" (all-mep-core-isas) 5 7 UINT #f #f)
(define-multi-ifield
(name f-24u5a2n)
(comment "abs jump target (24 bits, alignment 2)")
(attrs all-mep-core-isas ABS-ADDR)
(mode UINT)
(subfields f-24u5a2n-hi f-24u5a2n-lo)
(insert (sequence ()
(set (ifield f-24u5a2n-lo)
(srl (and (ifield f-24u5a2n) #xff) 1))
(set (ifield f-24u5a2n-hi)
(srl (ifield f-24u5a2n) 8))
))
(extract (set (ifield f-24u5a2n)
(or (sll (ifield f-24u5a2n-hi) 8)
(sll (ifield f-24u5a2n-lo) 1))))
)
; Displacement fields.
(df f-2u6 "SAR offset (2 bits)" (all-mep-core-isas) 6 2 UINT #f #f)
(df f-7u9 "tp-rel b (7 bits)" (all-mep-core-isas) 9 7 UINT #f #f)
(df f-7u9a2 "tp-rel h (7 bits)" (all-mep-core-isas) 9 6 UINT
((value pc) (srl SI value 1))
((value pc) (sll SI value 1)))
(df f-7u9a4 "tp/sp-rel w (7 bits)" (all-mep-core-isas) 9 5 UINT
((value pc) (srl SI value 2))
((value pc) (sll SI value 2)))
(df f-16s16 "general 16-bit s-val" (all-mep-core-isas) 16 16 INT #f #f)
; Immediate fields.
(df f-2u10 "swi level (2 bits)" (all-mep-core-isas) 10 2 UINT #f #f)
(df f-3u5 "bit offset (3 bits)" (all-mep-core-isas) 5 3 UINT #f #f)
(df f-4u8 "bCC const (4 bits)" (all-mep-core-isas) 8 4 UINT #f #f)
(df f-5u8 "slt & shifts (5 bits)" (all-mep-core-isas) 8 5 UINT #f #f)
(df f-5u24 "clip immediate (5 bits)" (all-mep-core-isas) 24 5 UINT #f #f)
(df f-6s8 "add immediate (6 bits)" (all-mep-core-isas) 8 6 INT #f #f)
(df f-8s8 "add imm (8 bits)" (all-mep-core-isas) 8 8 INT #f #f)
(df f-16u16 "general 16-bit u-val" (all-mep-core-isas) 16 16 UINT #f #f)
(df f-12u16 "cmov fixed 1" (all-mep-core-isas) 16 12 UINT #f #f)
(df f-3u29 "cmov fixed 2" (all-mep-core-isas) 29 3 UINT #f #f)
; These are all for the coprocessor opcodes
; The field is like IJKiiiiiii where I and J are toggled if K is set,
; for compatibility with older cores.
(define-pmacro (compute-cdisp10 val)
(cond SI
((and SI (cond SI ((and SI val #x80) (xor SI val #x300)) (else val)) #x200)
(sub (cond SI ((and SI val #x80) (xor SI val #x300)) (else val)) #x400))
(else
(cond SI ((and SI val #x80) (xor SI val #x300)) (else val)))
)
)
(define-pmacro (extend-cdisp10 val)
(cond SI
((and SI (compute-cdisp10 val) #x200)
(sub (and SI (compute-cdisp10 val) #x3ff) #x400))
(else
(and SI (compute-cdisp10 val) #x3ff))
)
)
(df f-cdisp10 "cop imm10" (all-mep-core-isas) 22 10 INT
((value pc) (extend-cdisp10 value))
((value pc) (extend-cdisp10 value))
)
; Non-contiguous fields.
(df f-24u8a4n-hi "24u8a4n hi 16u16" (all-mep-core-isas) 16 16 UINT #f #f)
(df f-24u8a4n-lo "24u8a4n lo 8u8a4" (all-mep-core-isas) 8 6 UINT #f #f)
(define-multi-ifield
(name f-24u8a4n)
(comment "absolute 24-bit address")
(attrs all-mep-core-isas)
(mode UINT)
(subfields f-24u8a4n-hi f-24u8a4n-lo)
(insert (sequence ()
(set (ifield f-24u8a4n-hi) (srl (ifield f-24u8a4n) 8))
(set (ifield f-24u8a4n-lo) (srl (and (ifield f-24u8a4n) #xfc) 2))))
(extract (set (ifield f-24u8a4n)
(or (sll (ifield f-24u8a4n-hi) 8)
(sll (ifield f-24u8a4n-lo) 2))))
)
(df f-24u8n-hi "24u8n hi 16u16" (all-mep-core-isas) 16 16 UINT #f #f)
(df f-24u8n-lo "24u8n lo 8u8" (all-mep-core-isas) 8 8 UINT #f #f)
(define-multi-ifield
(name f-24u8n)
(comment "24-bit constant")
(attrs all-mep-core-isas)
(mode UINT)
(subfields f-24u8n-hi f-24u8n-lo)
(insert (sequence ()
(set (ifield f-24u8n-hi) (srl (ifield f-24u8n) 8))
(set (ifield f-24u8n-lo) (and (ifield f-24u8n) #xff))))
(extract (set (ifield f-24u8n)
(or (sll (ifield f-24u8n-hi) 8)
(ifield f-24u8n-lo))))
)
(df f-24u4n-hi "24u4n hi 8u4" (all-mep-core-isas) 4 8 UINT #f #f)
(df f-24u4n-lo "24u4n lo 16u16" (all-mep-core-isas) 16 16 UINT #f #f)
(define-multi-ifield
(name f-24u4n)
(comment "coprocessor code")
(attrs all-mep-core-isas)
(mode UINT)
(subfields f-24u4n-hi f-24u4n-lo)
(insert (sequence ()
(set (ifield f-24u4n-hi) (srl (ifield f-24u4n) 16))
(set (ifield f-24u4n-lo) (and (ifield f-24u4n) #xffff))))
(extract (set (ifield f-24u4n)
(or (sll (ifield f-24u4n-hi) 16)
(ifield f-24u4n-lo))))
)
(define-multi-ifield
(name f-callnum)
(comment "system call number field")
(attrs all-mep-core-isas)
(mode UINT)
(subfields f-5 f-6 f-7 f-11)
(insert (sequence ()
(set (ifield f-5) (and (srl (ifield f-callnum) 3) 1))
(set (ifield f-6) (and (srl (ifield f-callnum) 2) 1))
(set (ifield f-7) (and (srl (ifield f-callnum) 1) 1))
(set (ifield f-11) (and (ifield f-callnum) 1))))
(extract (set (ifield f-callnum)
(or (sll (ifield f-5) 3)
(or (sll (ifield f-6) 2)
(or (sll (ifield f-7) 1)
(ifield f-11))))))
)
(df f-ccrn-hi "ccrn hi 2u28" (all-mep-core-isas) 28 2 UINT #f #f)
(df f-ccrn-lo "ccrn lo 4u4" (all-mep-core-isas) 4 4 UINT #f #f)
(define-multi-ifield
(name f-ccrn)
(comment "Coprocessor register number field")
(attrs all-mep-core-isas)
(mode UINT)
(subfields f-ccrn-hi f-ccrn-lo)
(insert (sequence ()
(set (ifield f-ccrn-hi) (and (srl (ifield f-ccrn) 4) #x3))
(set (ifield f-ccrn-lo) (and (ifield f-ccrn) #xf))))
(extract (set (ifield f-ccrn)
(or (sll (ifield f-ccrn-hi) 4)
(ifield f-ccrn-lo))))
)
; Operands.
;; Only LABEL, REGNUM, FMAX_FLOAT and FMAX_INT are now relevant for correct
;; operation. The others are mostly kept for backwards compatibility,
;; although they do affect the dummy prototypes in
;; gcc/config/mep/intrinsics.h.
(define-attr
(type enum)
(for operand)
(name CDATA)
(comment "datatype to use for C intrinsics mapping")
(values LABEL REGNUM FMAX_FLOAT FMAX_INT
POINTER LONG ULONG SHORT USHORT CHAR UCHAR CP_DATA_BUS_INT)
(default LONG))
(define-attr
(type enum)
(for insn)
(name CPTYPE)
(comment "datatype to use for coprocessor values")
(values CP_DATA_BUS_INT VECT V2SI V4HI V8QI V2USI V4UHI V8UQI)
(default CP_DATA_BUS_INT))
(define-attr
(type enum)
(for insn)
(name CRET)
;; VOID - all arguments are passed as parameters; if any are written, pointers to them are passed.
;; FIRST - the first argument is the return value.
;; FIRSTCOPY - the first argument is the return value, but a copy is also the first parameter.
(values VOID FIRST FIRSTCOPY)
(default VOID)
(comment "Insn's intrinsic returns void, or the first argument rather than (or in addition to) passing it."))
(define-attr
(type integer)
(for operand)
(name ALIGN)
(comment "alignment of immediate operands")
(default 1))
(define-attr
(for operand)
(type boolean)
(name RELOC_IMPLIES_OVERFLOW)
(comment "Operand should not be considered as a candidate for relocs"))
(define-attr
(for hardware)
(type boolean)
(name IS_FLOAT)
(comment "Register contains a floating point value"))
(define-pmacro (dpop name commment attrib hwr field func)
(define-full-operand name comment attrib
hwr DFLT field ((parse func)) () ()))
(define-pmacro (dprp name commment attrib hwr field pafunc prfunc)
(define-full-operand name comment attrib
hwr DFLT field ((parse pafunc) (print prfunc)) () ()))
(dnop r0 "register 0" (all-mep-core-isas) h-gpr 0)
(dnop rn "register Rn" (all-mep-core-isas) h-gpr f-rn)
(dnop rm "register Rm" (all-mep-core-isas) h-gpr f-rm)
(dnop rl "register Rl" (all-mep-core-isas) h-gpr f-rl)
(dnop rn3 "register 0-7" (all-mep-core-isas) h-gpr f-rn3)
;; Variants of RM/RN with different CDATA attributes. See comment above
;; CDATA for more details.
(dnop rma "register Rm holding pointer" (all-mep-core-isas (CDATA POINTER)) h-gpr f-rm)
(dnop rnc "register Rn holding char" (all-mep-core-isas (CDATA LONG)) h-gpr f-rn)
(dnop rnuc "register Rn holding unsigned char" (all-mep-core-isas (CDATA LONG)) h-gpr f-rn)
(dnop rns "register Rn holding short" (all-mep-core-isas (CDATA LONG)) h-gpr f-rn)
(dnop rnus "register Rn holding unsigned short" (all-mep-core-isas (CDATA LONG)) h-gpr f-rn)
(dnop rnl "register Rn holding long" (all-mep-core-isas (CDATA LONG)) h-gpr f-rn)
(dnop rnul "register Rn holding unsigned long" (all-mep-core-isas (CDATA ULONG)) h-gpr f-rn)
(dnop rn3c "register 0-7 holding unsigned char" (all-mep-core-isas (CDATA LONG)) h-gpr f-rn3)
(dnop rn3uc "register 0-7 holding byte" (all-mep-core-isas (CDATA LONG)) h-gpr f-rn3)
(dnop rn3s "register 0-7 holding unsigned short" (all-mep-core-isas (CDATA LONG)) h-gpr f-rn3)
(dnop rn3us "register 0-7 holding short" (all-mep-core-isas (CDATA LONG)) h-gpr f-rn3)
(dnop rn3l "register 0-7 holding unsigned long" (all-mep-core-isas (CDATA LONG)) h-gpr f-rn3)
(dnop rn3ul "register 0-7 holding long" (all-mep-core-isas (CDATA ULONG)) h-gpr f-rn3)
(dnop lp "link pointer" (all-mep-core-isas) h-csr 1)
(dnop sar "shift amount register" (all-mep-core-isas) h-csr 2)
(dnop hi "high result" (all-mep-core-isas) h-csr 7)
(dnop lo "low result" (all-mep-core-isas) h-csr 8)
(dnop mb0 "modulo begin register 0" (all-mep-core-isas) h-csr 12)
(dnop me0 "modulo end register 0" (all-mep-core-isas) h-csr 13)
(dnop mb1 "modulo begin register 1" (all-mep-core-isas) h-csr 14)
(dnop me1 "modulo end register 1" (all-mep-core-isas) h-csr 15)
(dnop psw "program status word" (all-mep-core-isas) h-csr 16)
(dnop epc "exception prog counter" (all-mep-core-isas) h-csr 19)
(dnop exc "exception cause" (all-mep-core-isas) h-csr 20)
(dnop npc "nmi program counter" (all-mep-core-isas) h-csr 23)
(dnop dbg "debug register" (all-mep-core-isas) h-csr 24)
(dnop depc "debug exception pc" (all-mep-core-isas) h-csr 25)
(dnop opt "option register" (all-mep-core-isas) h-csr 26)
(dnop r1 "register 1" (all-mep-core-isas) h-gpr 1)
(dnop tp "tiny data area pointer" (all-mep-core-isas) h-gpr 13)
(dnop sp "stack pointer" (all-mep-core-isas) h-gpr 15)
(dprp tpr "TP register" (all-mep-core-isas) h-gpr 13 "tpreg" "tpreg")
(dprp spr "SP register" (all-mep-core-isas) h-gpr 15 "spreg" "spreg")
(define-full-operand
csrn "control/special register" (all-mep-core-isas (CDATA REGNUM)) h-csr
DFLT f-csrn ((parse "csrn")) () ()
)
(dnop csrn-idx "control/special reg idx" (all-mep-core-isas) h-uint f-csrn)
(dnop crn64 "copro Rn (64-bit)" (all-mep-core-isas (CDATA CP_DATA_BUS_INT)) h-cr64 f-crn)
(dnop crn "copro Rn (32-bit)" (all-mep-core-isas (CDATA CP_DATA_BUS_INT)) h-cr f-crn)
(dnop crnx64 "copro Rn (0-31, 64-bit)" (all-mep-core-isas (CDATA CP_DATA_BUS_INT)) h-cr64 f-crnx)
(dnop crnx "copro Rn (0-31, 32-bit)" (all-mep-core-isas (CDATA CP_DATA_BUS_INT)) h-cr f-crnx)
(dnop ccrn "copro control reg CCRn" (all-mep-core-isas (CDATA REGNUM)) h-ccr f-ccrn)
(dnop cccc "copro flags" (all-mep-core-isas) h-uint f-rm)
(dprp pcrel8a2 "pc-rel addr (8 bits)" (all-mep-core-isas (CDATA LABEL) RELAX) h-sint f-8s8a2 "mep_align" "address")
(dprp pcrel12a2 "pc-rel addr (12 bits)" (all-mep-core-isas (CDATA LABEL) RELAX) h-sint f-12s4a2 "mep_align" "address")
(dprp pcrel17a2 "pc-rel addr (17 bits)" (all-mep-core-isas (CDATA LABEL) RELAX) h-sint f-17s16a2 "mep_align" "address")
(dprp pcrel24a2 "pc-rel addr (24 bits)" (all-mep-core-isas (CDATA LABEL)) h-sint f-24s5a2n "mep_align" "address")
(dprp pcabs24a2 "pc-abs addr (24 bits)" (all-mep-core-isas (CDATA LABEL)) h-uint f-24u5a2n "mep_alignu" "address")
(dpop sdisp16 "displacement (16 bits)" (all-mep-core-isas) h-sint f-16s16 "signed16")
(dpop simm16 "signed imm (16 bits)" (all-mep-core-isas) h-sint f-16s16 "signed16")
(dpop uimm16 "unsigned imm (16 bits)" (all-mep-core-isas) h-uint f-16u16 "unsigned16")
(dnop code16 "uci/dsp code (16 bits)" (all-mep-core-isas) h-uint f-16u16)
(dnop udisp2 "SSARB addend (2 bits)" (all-mep-core-isas) h-sint f-2u6)
(dnop uimm2 "interrupt (2 bits)" (all-mep-core-isas) h-uint f-2u10)
(dnop simm6 "add const (6 bits)" (all-mep-core-isas) h-sint f-6s8)
(dnop simm8 "mov const (8 bits)" (all-mep-core-isas RELOC_IMPLIES_OVERFLOW)
h-sint f-8s8)
(dpop addr24a4 "sw/lw addr (24 bits)" (all-mep-core-isas (ALIGN 4)) h-uint f-24u8a4n "mep_alignu")
(dnop code24 "coprocessor code" (all-mep-core-isas) h-uint f-24u4n)
(dnop callnum "system call number" (all-mep-core-isas) h-uint f-callnum)
(dnop uimm3 "bit immediate (3 bits)" (all-mep-core-isas) h-uint f-3u5)
(dnop uimm4 "bCC const (4 bits)" (all-mep-core-isas) h-uint f-4u8)
(dnop uimm5 "bit/shift val (5 bits)" (all-mep-core-isas) h-uint f-5u8)
(dpop udisp7 "tp-rel b (7 bits)" (all-mep-core-isas) h-uint f-7u9 "unsigned7")
(dpop udisp7a2 "tp-rel h (7 bits)" (all-mep-core-isas (ALIGN 2)) h-uint f-7u9a2 "unsigned7")
(dpop udisp7a4 "tp/sp-rel w (7 bits)" (all-mep-core-isas (ALIGN 4)) h-uint f-7u9a4 "unsigned7")
(dpop uimm7a4 "sp w-addend (7 bits)" (all-mep-core-isas (ALIGN 4)) h-uint f-7u9a4 "mep_alignu")
(dnop uimm24 "immediate (24 bits)" (all-mep-core-isas) h-uint f-24u8n)
(dnop cimm4 "cache immed'te (4 bits)" (all-mep-core-isas) h-uint f-rn)
(dnop cimm5 "clip immediate (5 bits)" (all-mep-core-isas) h-uint f-5u24)
(dpop cdisp10 "copro addend (8/10 bits)" (all-mep-core-isas) h-sint f-cdisp10 "cdisp10")
(dpop cdisp10a2 "copro addend (8/10 bits)" (all-mep-core-isas) h-sint f-cdisp10 "cdisp10")
(dpop cdisp10a4 "copro addend (8/10 bits)" (all-mep-core-isas) h-sint f-cdisp10 "cdisp10")
(dpop cdisp10a8 "copro addend (8/10 bits)" (all-mep-core-isas) h-sint f-cdisp10 "cdisp10")
; Special operand representing the various ways that the literal zero can be
; specified.
(define-full-operand
zero "Zero operand" (all-mep-core-isas) h-sint DFLT f-nil
((parse "zero")) () ()
)
; Attributes.
(define-attr
(for insn)
(type boolean)
(name OPTIONAL_BIT_INSN)
(comment "optional bit manipulation instruction"))
(define-attr
(for insn)
(type boolean)
(name OPTIONAL_MUL_INSN)
(comment "optional 32-bit multiply instruction"))
(define-attr
(for insn)
(type boolean)
(name OPTIONAL_DIV_INSN)
(comment "optional 32-bit divide instruction"))
(define-attr
(for insn)
(type boolean)
(name OPTIONAL_DEBUG_INSN)
(comment "optional debug instruction"))
(define-attr
(for insn)
(type boolean)
(name OPTIONAL_LDZ_INSN)
(comment "optional leading zeroes instruction"))
(define-attr
(for insn)
(type boolean)
(name OPTIONAL_ABS_INSN)
(comment "optional absolute difference instruction"))
(define-attr
(for insn)
(type boolean)
(name OPTIONAL_AVE_INSN)
(comment "optional average instruction"))
(define-attr
(for insn)
(type boolean)
(name OPTIONAL_MINMAX_INSN)
(comment "optional min/max instruction"))
(define-attr
(for insn)
(type boolean)
(name OPTIONAL_CLIP_INSN)
(comment "optional clipping instruction"))
(define-attr
(for insn)
(type boolean)
(name OPTIONAL_SAT_INSN)
(comment "optional saturation instruction"))
(define-attr
(for insn)
(type boolean)
(name OPTIONAL_UCI_INSN)
(comment "optional UCI instruction"))
(define-attr
(for insn)
(type boolean)
(name OPTIONAL_DSP_INSN)
(comment "optional DSP instruction"))
(define-attr
(for insn)
(type boolean)
(name OPTIONAL_CP_INSN)
(comment "optional coprocessor-related instruction"))
(define-attr
(for insn)
(type boolean)
(name OPTIONAL_CP64_INSN)
(comment "optional coprocessor-related 64 data bit instruction"))
(define-attr
(for insn)
(type boolean)
(name OPTIONAL_VLIW64)
(comment "optional vliw64 mode (vliw32 is default)"))
(define-attr
(for insn)
(type enum)
(name STALL)
(attrs META)
(values NONE SHIFTI INT2 LOAD STORE LDC STC LDCB STCB SSARB FSFT RET
ADVCK MUL MULR DIV)
(default NONE)
(comment "gcc stall attribute"))
(define-attr
(for insn)
(type string)
(name INTRINSIC)
(attrs META)
(comment "gcc intrinsic name"))
(define-attr
(for insn)
(type enum)
(name SLOT)
(attrs META)
(values NONE C3 V1 V3 P0S P0 P1)
(default NONE)
(comment "coprocessor slot type"))
(define-attr
(for insn)
(type boolean)
(name MAY_TRAP)
(comment "instruction may generate an exception"))
; Attributes for scheduling restrictions in vliw mode
(define-attr
(for insn)
(type boolean)
(name VLIW_ALONE)
(comment "instruction can be scheduled alone in vliw mode"))
(define-attr
(for insn)
(type boolean)
(name VLIW_NO_CORE_NOP)
(comment "there is no corresponding nop core instruction"))
(define-attr
(for insn)
(type boolean)
(name VLIW_NO_COP_NOP)
(comment "there is no corresponding nop coprocessor instruction"))
(define-attr
(for insn)
(type boolean)
(name VLIW64_NO_MATCHING_NOP)
(comment "there is no corresponding nop coprocessor instruction"))
(define-attr
(for insn)
(type boolean)
(name VLIW32_NO_MATCHING_NOP)
(comment "there is no corresponding nop coprocessor instruction"))
(define-attr
(for insn)
(type boolean)
(name VOLATILE)
(comment "Insn is volatile."))
(define-attr
(for insn)
(type integer)
(name LATENCY)
(comment "The latency of this insn, used for scheduling as an intrinsic in gcc")
(default 0))
; The MeP config tool will edit this.
(define-attr
(type enum)
(for insn)
(name CONFIG)
(values NONE ; config-attr-start
default
) ; config-attr-end
)
; Enumerations.
(define-normal-insn-enum major "major opcodes" (all-mep-core-isas) MAJ_
f-major
(.map .str (.iota 16))
)
(define-pmacro (dni-isa xname xcomment xattrs xsyntax xformat xsemantics xtiming isa)
(define-insn
(name xname)
(comment xcomment)
(.splice attrs (.unsplice xattrs) (ISA isa))
(syntax xsyntax)
(format xformat)
(semantics xsemantics)
(.splice timing (.unsplice xtiming))
)
)
(define-pmacro (dnmi-isa xname xcomment xattrs xsyntax xemit isa)
(dnmi xname xcomment (.splice (.unsplice xattrs) (ISA isa)) xsyntax xemit)
)
; For making profiling calls and dynamic configuration
(define-pmacro (cg-profile caller callee)
(c-call "cg_profile" caller callee)
)
; For dynamic configuration only
(define-pmacro (cg-profile-jump caller callee)
(c-call "cg_profile_jump" caller callee)
)
; For defining Core Instructions
(define-pmacro (dnci xname xcomment xattrs xsyntax xformat xsemantics xtiming)