-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathepiphany.cpu
2937 lines (2407 loc) · 79 KB
/
epiphany.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
; Adapteva EPIPHANY CPU description. -*- Scheme -*-
; Copyright 1998, 1999, 2000, 2001, 2003, 2006, 2007, 2008, 2009, 2010, 2011
; Free Software Foundation, Inc.
;
; Contributed by Embecosm on behalf of Adapteva, Inc.
; This file is part of the GNU Binutils and of GDB.
;
; 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-arch must appear first
(define-arch
(name epiphany) ; name of cpu family
(comment "Adapteva, Inc. EPIPHANY family")
(default-alignment aligned)
(insn-lsb0? #t)
; - a 16/32 bit instruction machine (the default)
(machs epiphany32)
(isas epiphany)
)
; Attributes.
(define-attr
(for insn)
(type boolean)
(name SHORT-INSN)
(comment "instruction is a 16 bit form")
)
;; 3 bit add/sub immediate forms - useful for relaxing into 11 bit form
(define-attr
(for insn)
(type boolean)
(name IMM3)
(comment "instruction has a 3 bit immediate form")
)
;; 8 bit mov immediate forms - useful for relaxing into 16 bit form
(define-attr
(for insn)
(type boolean)
(name IMM8)
(comment "instruction has a 8 bit immediate form")
)
; Instruction set parameters.
(define-isa
(name epiphany)
(comment "Adapteva, Inc. EPIPHANY32 ISA")
(default-insn-word-bitsize 32)
(default-insn-bitsize 32)
(base-insn-bitsize 32)
(decode-assist (3 2 1 0)) ; CGEN can figure this out
(liw-insns 1) ; # instructions fetched at once
)
; Cpu family definitions.
(define-cpu
; cpu names must be distinct from the architecture name and machine names.
(name epiphanybf)
(comment "Adapteva, Inc. EPIPHANY Family")
(endian little)
(word-bitsize 32)
)
(define-cpu
(name epiphanymf)
(comment "Adapteva, Inc. EPIPHANY Family")
(endian little)
(word-bitsize 32)
)
(define-mach
(name epiphany32)
(comment "Adapteva EPIPHANY")
(cpu epiphanybf)
)
; Model descriptions.
(define-model
(name epiphany32) (comment "Adapteva EPIPHANY 32/16") (attrs)
(mach epiphany32)
(unit u-exec "Execution Unit" ()
1 1 ; issue done
() ; state
() ; inputs
() ; outputs
() ; profile action (default)
)
)
; Instruction fields.
;
; Attributes:
; XXX: what EPIPHANY attrs
; 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
; RELOC: there is a relocation associated with this field
(define-attr
(for ifield operand)
(type boolean)
(name RELOC)
(comment "there is a reloc associated with this field (experiment)")
)
;; define the fields of the instruction.
;; name description ATTR MSB LEN
(dnf f-opc "primary opcode" () 3 4)
(dnf f-opc-4-1 "secondary opcode" () 4 1)
(dnf f-opc-6-3 "secondary opcode" () 6 3) ;;
(dnf f-opc-8-5 "tertiary opcode" () 8 5) ;;
(dnf f-opc-19-4 "additional opcode bits" () 19 4)
(dnf f-condcode "condition codes" () 7 4)
(dnf f-secondary-ccs "flag for secondary ccs" () 7 1)
(dnf f-shift "shift amount" () 9 5)
(dnf f-wordsize "load/store size" () 6 2)
(dnf f-store "load/store flag" () 4 1) ;; 0==load,1==store
(dnf f-opc-8-1 "opcode bits" () 8 1)
(dnf f-opc-31-32 "all opcode set" () 31 32)
(df f-simm8 "branch displacement" (PCREL-ADDR RELOC) 15 8 INT
((value pc) (sra SI (sub SI value pc) 1))
((value pc) (add SI (mul SI value 2) pc)))
(df f-simm24 "branch displacement" (PCREL-ADDR RELOC) 31 24 INT
((value pc) (sra SI (sub SI value pc) 1))
((value pc) (add SI (mul SI value 2) pc)))
(df f-sdisp3 "signed immediate 3 bit" () 9 3 INT #f #f)
(dnf f-disp3 "address offset" () 9 3)
(dnf f-disp8 "address offset" () 23 8)
(dnf f-imm8 "move/add/sub imm8" () 12 8)
(dnf f-imm-27-8 "move/add/sub imm16" () 27 8)
(dnf f-addsubx "+/- index address" () 20 1)
(dnf f-subd "+/- displ address" () 24 1)
(dnf f-pm "post-modify immediate" () 25 1)
(dnf f-rm "short rm" () 9 3) ;; RM
(dnf f-rn "short rn" () 12 3) ;; RN
(dnf f-rd "short rd" () 15 3) ;; RD
(dnf f-rm-x "extension rm" () 25 3) ;; RM
(dnf f-rn-x "extension rn" () 28 3) ;; RN
(dnf f-rd-x "extension rd" () 31 3) ;; RD
(dnf f-dc-9-1 "DC" (RESERVED) 9 1)
(dnf f-sn "short sn" () 12 3) ;; SN
(dnf f-sd "short sd" () 15 3) ;; SD
(dnf f-sn-x "extension sn" () 28 3) ;; SN
(dnf f-sd-x "extension sd" () 31 3) ;; SD
(dnf f-dc-7-4 "movts zeros" () 7 4)
(dnf f-trap-swi-9-1 "trap or swi" () 9 1)
(dnf f-gien-gidis-9-1 "gien or gidis" () 9 1)
(dnf f-dc-15-3 "DC" (RESERVED) 15 3)
(dnf f-dc-15-7 "DC" (RESERVED) 15 7)
(dnf f-dc-15-6 "DC" () 15 6)
(dnf f-trap-num "trap number" () 15 6)
(dnf f-dc-20-1 "DC" (RESERVED) 20 1)
(dnf f-dc-21-1 "DC" (RESERVED) 21 1)
(dnf f-dc-21-2 "DC" (RESERVED) 21 2)
(dnf f-dc-22-3 "DC" (RESERVED) 22 3)
(dnf f-dc-22-2 "DC" (RESERVED) 22 2)
(dnf f-dc-22-1 "DC" (RESERVED) 22 1)
(dnf f-dc-25-6 "DC" (RESERVED) 25 6)
(dnf f-dc-25-4 "DC" (RESERVED) 25 4)
(dnf f-dc-25-2 "DC" (RESERVED) 25 2)
(dnf f-dc-25-1 "DC" (RESERVED) 25 1)
(dnf f-dc-28-1 "DC" (RESERVED) 28 1)
(dnf f-dc-31-3 "DC" (RESERVED) 31 3)
(dnmf f-disp11 "Unsigned offset for load/store" () UINT (f-disp3 f-disp8)
(sequence ()
(set (ifield f-disp8) (and (srl (ifield f-disp11) 3) (const 255)))
(set (ifield f-disp3) (and (ifield f-disp11) 7)))
(sequence ()
(set (ifield f-disp11) (or (sll (ifield f-disp8) 3)
(ifield f-disp3)))
)
)
(dnmf f-sdisp11 "Signed offset for load/store" () INT (f-disp3 f-disp8)
(sequence () ;encode
(set (ifield f-disp8) (and #xff (srl SI (ifield f-sdisp11) 3)))
(set (ifield f-disp3) (and SI (ifield f-sdisp11) 7)))
(sequence () ;decode
(set (ifield f-sdisp11)
(sub SI (xor (and (or (sll (ifield f-disp8) 3)
(ifield f-disp3))
#x7ff)
#x400)
#x400)))
)
(dnmf f-imm16 "Short immediate for move/add/sub" () UINT (f-imm8 f-imm-27-8)
(sequence ()
(set (ifield f-imm8) (and (ifield f-imm16) #xff))
(set (ifield f-imm-27-8) (srl (ifield f-imm16) 8)))
(sequence ()
(set (ifield f-imm16) (or (sll (ifield f-imm-27-8) 8)
(ifield f-imm8))))
)
;; 32 bit instructions have the register number broken into two non-contiguous fields
(define-pmacro (x-reg-field reg)
(define-multi-ifield
(name (.sym "f-" reg "6"))
(mode UINT)
(subfields (.sym "f-" reg "-x") (.sym "f-" reg))
(insert (sequence ()
(set (ifield (.sym "f-" reg)) (and (ifield (.sym "f-" reg "6"))
(const 7)))
(set (ifield (.sym "f-" reg "-x")) (srl (ifield (.sym "f-" reg "6"))
(const 3)))
))
(extract (sequence ()
(set (ifield (.sym "f-" reg "6")) (or (sll (ifield (.sym "f-" reg "-x"))
(const 3))
(ifield (.sym "f-" reg))))
))
)
)
(x-reg-field rd) ; f-rd6
(x-reg-field rn) ; f-rn6
(x-reg-field rm) ; f-rm6
(x-reg-field sd) ; f-sd6
(x-reg-field sn) ; f-sn6
;;;;;;;;;;
; Enums. ;
;;;;;;;;;;
; insn-opc: bits 3..0 - major family selector
(define-normal-insn-enum insn-opc "opc enums" () OP4_ f-opc
(
BRANCH16 ;; 0000
LDSTR16X ;; 0001
FLOW16 ;; 0010
IMM16 ;; 0011
LDSTR16D ;; 0100
LDSTR16P ;; 0101
LSHIFT16 ;; 0110 - logical shift
DSP16 ;; 0111 - 3 reg DSP 16 bit insns
BRANCH ;; 1000
LDSTRX ;; 1001
ALU16 ;; 1010 - 3 reg 16 bit
IMM32 ;; 1011
LDSTRD ;; 1100
LDSTRP ;; 1101
ASHIFT16 ;; 1110 ASR, BITR
MISC ;; 1111 - 32 bit shifts, 3 reg ALU, 3 reg DSP, FLOW, BITR
)
)
(define-normal-insn-enum insn-wordsize "memory access width" () OPW_ f-wordsize
; specifies the size of a memory load/store operation
(BYTE SHORT WORD DOUBLE)
)
(define-normal-insn-enum insn-memory-access "memory access direction" () OP_ f-store
; load=0, store=1
(LOAD STORE)
)
; enum for trap codes used by simulator
(define-normal-insn-enum trap-codes "trap instruction dispatch code" () TRAP_ f-trap-num
(write read open exit pass fail close other)
)
; cond branch: bits 7..4
;
(define-normal-insn-enum insn-cond "branch conditions" () OPC_ f-condcode
(EQ NE GTU GTEU LTEU LTU GT GTE LT LTE BEQ BNE BLT BLTE B BL))
; dsp 3 operand opcodes
(define-normal-insn-enum insn-bop "binary operator subcodes" () OPB_ f-opc-6-3
(EOR ADD LSL SUB LSR AND ASR ORR))
; dsp 3 operand opcodes
(define-normal-insn-enum insn-bopext "binary operator subcodes" () OPBE_ f-opc-6-3
(FEXT FDEP LFSR - - - - -))
(define-normal-insn-enum insn-fop "floating operators" () OPF_ f-opc-6-3
(ADD SUB MUL MADD MSUB FLOAT FIX FABS))
(define-normal-insn-enum insn-fopexn "extended floating operators" () OPF_ f-opc-6-3
(FRECIP FSQRT - - - - - -))
; Immediate operation secondary opcodes
(define-normal-insn-enum insn-immop "immediate operators" () OPI_ f-opc-6-3
(- ADD - SUB - - - TRAP) ; TRAP is special extension for simulator
)
; don't care fields
(define-normal-insn-enum insn-dc-25-2 "don't cares" () OPI_25_2_ f-dc-25-2
(MBZ))
; General Register keyword names.
(define-keyword
(name gr-names)
(print-name h-registers)
(prefix "")
(values
; some preferred aliases
(fp 11) (sp 13) (lr 14)
; the default register names
(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)
(r16 16) (r17 17) (r18 18) (r19 19) (r20 20) (r21 21) (r22 22) (r23 23)
(r24 24) (r25 25) (r26 26) (r27 27) (r28 28) (r29 29) (r30 30) (r31 31)
(r32 32) (r33 33) (r34 34) (r35 35) (r36 36) (r37 37) (r38 38) (r39 39)
(r40 40) (r41 41) (r42 42) (r43 43) (r44 44) (r45 45) (r46 46) (r47 47)
(r48 48) (r49 49) (r50 50) (r51 51) (r52 52) (r53 53) (r54 54) (r55 55)
(r56 56) (r57 57) (r58 58) (r59 59) (r60 60) (r61 61) (r62 62) (r63 63)
; some less popular aliases
(a1 0) (a2 1) (a3 2) (a4 3) (v1 4) (v2 5) (v3 6) (v4 7)
(v5 8) (v6 9) (v7 10) (v8 11)
(sb 9) (sl 10) (ip 12)
)
)
(define-normal-insn-enum post-index "+/- index register" () DIR_ f-addsubx (POSTINC POSTDEC))
(define-normal-insn-enum disp-post-modify "postmodify displacement" () PMOD_ f-pm (DISP POST))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Hardware pieces.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 64 general-purpose registers
(define-hardware
(name h-registers)
(comment "all addressable registers")
(type register SI (64))
(attrs PROFILE CACHE-ADDR)
(indices extern-keyword gr-names)
)
;; Same 64 registers as floating point registers
(define-hardware
(name h-fpregisters)
(comment "all GPRs as float values")
(type register SF (64))
(attrs PROFILE VIRTUAL)
(indices extern-keyword gr-names)
(get (index) (subword SF (reg h-registers index) 0))
(set (index newval) (set (reg h-registers index) (subword SI newval 0)))
)
;; define processor status bits as physical hardware
(define-pmacro (psw-h-bit name cmt)
(dsh name cmt () (register BI)))
(psw-h-bit h-zbit "integer zero bit")
(psw-h-bit h-nbit "integer neg bit")
(psw-h-bit h-cbit "integer carry bit")
(psw-h-bit h-vbit "integer overflow bit")
(psw-h-bit h-vsbit "integer overflow sticky")
(psw-h-bit h-bzbit "floating point zero bit")
(psw-h-bit h-bnbit "floating point neg bit")
(psw-h-bit h-bvbit "floating point ovfl bit")
(psw-h-bit h-bubit "floating point underfl bit")
(psw-h-bit h-bibit "floating point invalid bit")
(psw-h-bit h-bcbit "floating point carry bit")
(psw-h-bit h-bvsbit "floating point overflow sticky")
(psw-h-bit h-bisbit "floating point invalid sticky")
(psw-h-bit h-busbit "floating point underflow sticky")
(psw-h-bit h-expcause0bit "exceprion cause bit0")
(psw-h-bit h-expcause1bit "exceprion cause bit1")
(psw-h-bit h-expcause2bit "external load stalled bit")
(psw-h-bit h-extFstallbit "external fetch stalled bit")
(psw-h-bit h-trmbit "0=round to nearest, 1=trunacte select bit")
(psw-h-bit h-invExcEnbit "invalid exception enable bit")
(psw-h-bit h-ovfExcEnbit "overflow exception enable bit")
(psw-h-bit h-unExcEnbit "underflow exception enablebit ")
(psw-h-bit h-timer0bit0 "timer 0 mode selection 0")
(psw-h-bit h-timer0bit1 "timer 0 mode selection 1")
(psw-h-bit h-timer0bit2 "timer 0 mode selection 2")
(psw-h-bit h-timer0bit3 "timer 0 mode selection 3")
(psw-h-bit h-timer1bit0 "timer 1 mode selection 0")
(psw-h-bit h-timer1bit1 "timer 1 mode selection 1")
(psw-h-bit h-timer1bit2 "timer 1 mode selection 2")
(psw-h-bit h-timer1bit3 "timer 1 mode selection 3")
(psw-h-bit h-mbkptEnbit "multicore bkpt enable")
(psw-h-bit h-clockGateEnbit "clock gating enable bkpt enable")
(psw-h-bit h-coreCfgResBit12 "core config bit 12")
(psw-h-bit h-coreCfgResBit13 "core config bit 13")
(psw-h-bit h-coreCfgResBit14 "core config bit 14")
(psw-h-bit h-coreCfgResBit15 "core config bit 15")
(psw-h-bit h-coreCfgResBit16 "core config bit 16")
(psw-h-bit h-coreCfgResBit20 "core config bit 20")
(psw-h-bit h-coreCfgResBit21 "core config bit 21")
(psw-h-bit h-coreCfgResBit24 "core config bit 24")
(psw-h-bit h-coreCfgResBit25 "core config bit 25")
(psw-h-bit h-coreCfgResBit26 "core config bit 26")
(psw-h-bit h-coreCfgResBit27 "core config bit 27")
(psw-h-bit h-coreCfgResBit28 "core config bit 28")
(psw-h-bit h-coreCfgResBit29 "core config bit 29")
(psw-h-bit h-coreCfgResBit30 "core config bit 30")
(psw-h-bit h-coreCfgResBit31 "core config bit 31")
(psw-h-bit h-arithmetic-modebit0 "arithmetic mode bit0")
(psw-h-bit h-arithmetic-modebit1 "arithmetic mode bit1")
(psw-h-bit h-arithmetic-modebit2 "arithmetic mode bit2")
(psw-h-bit h-gidisablebit "global interrupt disable bit")
(psw-h-bit h-kmbit "kernel mode bit")
(psw-h-bit h-caibit "core active indicator mode bit")
(psw-h-bit h-sflagbit "sflag bit")
; Define operands for each of the physical bits
(define-pmacro (psw-bit name hname cmt)
(dnop name cmt (SEM-ONLY) hname f-nil)
)
(psw-bit zbit h-zbit "integer zero bit")
(psw-bit nbit h-nbit "integer neg bit")
(psw-bit cbit h-cbit "integer carry bit")
(psw-bit vbit h-vbit "integer overflow bit")
(psw-bit bzbit h-bzbit "floating point zero bit")
(psw-bit bnbit h-bnbit "floating point neg bit")
(psw-bit bvbit h-bvbit "floating point ovfl bit")
(psw-bit bcbit h-bcbit "floating point carry bit")
(psw-bit bubit h-bubit "floating point underfl bit")
(psw-bit bibit h-bibit "floating point invalid bit")
(psw-bit vsbit h-vsbit "integer overflow sticky")
(psw-bit bvsbit h-bvsbit "floating point overflow sticky")
(psw-bit bisbit h-bisbit "floating point invalid sticky")
(psw-bit busbit h-busbit "floating point underflow sticky")
(psw-bit expcause0bit h-expcause0bit "exceprion cause bit0")
(psw-bit expcause1bit h-expcause1bit "exceprion cause bit1")
(psw-bit expcause2bit h-expcause2bit "external load stalled bit")
(psw-bit extFstallbit h-extFstallbit "external fetch stalled bit")
(psw-bit trmbit h-trmbit "0=round to nearest, 1=trunacte selct bit")
(psw-bit invExcEnbit h-invExcEnbit "invalid exception enable bit")
(psw-bit ovfExcEnbit h-ovfExcEnbit "overflow exception enable bit")
(psw-bit unExcEnbit h-unExcEnbit "underflow exception enable bit")
(psw-bit timer0bit0 h-timer0bit0 "timer 0 mode selection 0")
(psw-bit timer0bit1 h-timer0bit1 "timer 0 mode selection 1")
(psw-bit timer0bit2 h-timer0bit2 "timer 0 mode selection 2")
(psw-bit timer0bit3 h-timer0bit3 "timer 0 mode selection 3")
(psw-bit timer1bit0 h-timer1bit0 "timer 1 mode selection 0")
(psw-bit timer1bit1 h-timer1bit1 "timer 1 mode selection 1")
(psw-bit timer1bit2 h-timer1bit2 "timer 1 mode selection 2")
(psw-bit timer1bit3 h-timer1bit3 "timer 1 mode selection 3")
(psw-bit mbkptEnbit h-mbkptEnbit "multicore bkpt enable")
(psw-bit clockGateEnbit h-clockGateEnbit "clock gate enable enable")
(psw-bit arithmetic-modebit0 h-arithmetic-modebit0 "arithmetic mode bit0")
(psw-bit arithmetic-modebit1 h-arithmetic-modebit1 "arithmetic mode bit1")
(psw-bit arithmetic-modebit2 h-arithmetic-modebit2 "arithmetic mode bit2")
(psw-bit coreCfgResBit12 h-coreCfgResBit12 "core config bit 12")
(psw-bit coreCfgResBit13 h-coreCfgResBit13 "core config bit 13")
(psw-bit coreCfgResBit14 h-coreCfgResBit14 "core config bit 14")
(psw-bit coreCfgResBit15 h-coreCfgResBit15 "core config bit 15")
(psw-bit coreCfgResBit16 h-coreCfgResBit16 "core config bit 16")
(psw-bit coreCfgResBit20 h-coreCfgResBit20 "core config bit 20")
(psw-bit coreCfgResBit21 h-coreCfgResBit21 "core config bit 21")
(psw-bit coreCfgResBit24 h-coreCfgResBit24 "core config bit 24")
(psw-bit coreCfgResBit25 h-coreCfgResBit25 "core config bit 25")
(psw-bit coreCfgResBit26 h-coreCfgResBit26 "core config bit 26")
(psw-bit coreCfgResBit27 h-coreCfgResBit27 "core config bit 27")
(psw-bit coreCfgResBit28 h-coreCfgResBit28 "core config bit 28")
(psw-bit coreCfgResBit29 h-coreCfgResBit29 "core config bit 29")
(psw-bit coreCfgResBit30 h-coreCfgResBit30 "core config bit 30")
(psw-bit coreCfgResBit31 h-coreCfgResBit31 "core config bit 31")
(psw-bit gidisablebit h-gidisablebit "global interrupt disable bit")
(psw-bit kmbit h-kmbit "kernel mode bit")
(psw-bit caibit h-caibit "core actibe indicator bit")
(psw-bit sflagbit h-sflagbit "sflag bit")
;; Special registers - accessed via MOVTS and MOVFS.
;;
;; "Core control and status" in group MR0=0, MR1=0
(define-keyword
(name cr-names)
(print-name h-core-registers)
(prefix "")
(values (config 0)
(status 1) ; unified condition codes
(pc 2) ; virtualized PC
(debug 3);
(iab 4)
(lc 5);loop counter Not impemented
(ls 6);loop start address Not impemented
(le 7);loop end address Not impemented
(iret 8)
(imask 9)
(ilat 10)
(ilatst 11)
(ilatcl 12)
(ipend 13)
(ctimer0 14)
(ctimer1 15)
(hstatus 16)
)
)
;; DMA registers in group MR0=1, MR1=0
(define-keyword
(name crdma-names)
(print-name h-coredma-registers)
(prefix "")
(values
(dma0config 0)
(dma0stride 1)
(dma0count 2)
(dma0srcaddr 3)
(dma0dstaddr 4)
(dma0auto0 5)
(dma0auto1 6)
(dma0status 7)
(dma1config 8)
(dma1stride 9)
(dma1count 10)
(dma1srcaddr 11)
(dma1dstaddr 12)
(dma1auto0 13)
(dma1auto1 14)
(dma1status 15)
)
)
;; mem configuration registers in group MR0=0, MR1=1
(define-keyword
(name crmem-names)
(print-name h-coremem-registers)
(prefix "")
(values
(memconfig 0)
(memstatus 1)
(memprotect 2)
(memreserve 3)
)
)
;; mesh configuration registers in group MR0=1, MR1=1
(define-keyword
(name crmesh-names)
(print-name h-coremesh-registers)
(prefix "")
(values
(meshconfig 0)
(coreid 1)
(meshmulticast 2)
(swreset 3)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; PC is a byte-addressed register
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(dnh h-pc "program counter" (PC PROFILE) (pc) () () ())
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Memory Effective Address wants to be visible
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(dnh h-memaddr "memory effective address" (PROFILE) (register SI) () () ())
(dnop memaddr "memory effective address" (SEM-ONLY) h-memaddr f-nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Special Core Registers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; STATUS
;; [0]=core active indicator
;; [1]=global interrupt disable
;; [2]=processor mode(1=user mode, 0=kernel mode)
;; [3]=wired AND global flag
;; [4]=integer zero zbit
;; [5]=integer negative nbit
;; [6]=integer carry cbit
;; [7]=integer overflow vbit
;; [8]=fpu zero flag bzbit
;; [9]=fpu negative flag bnbit
;; [10]=fpu overflow flag bvbit
;; [11]=fpu carry flag(not used) bcbit
;; [12]=ialu overflow flag(sticky) vsbit
;; [13]=fpu invalid flag(sticky) bisbit
;; [14]=fpu overflow flag(sticky) bvsbit
;; [15]=fpu underflow flag(sticky) busbit
;; [17:16]=exception cause 00=no exception 01=load-store exception 10=fpu exception 11=unimplemented instruction
;; expcause1bit
;; expcause0bit
;; [18]=external load stalled expcause2bit
;; [19]=external fetch stalled extFstallbit
;; [31:20]=RESERVED
(define-hardware
(name h-core-registers)
(comment "Special Core Registers")
(type register USI (17))
(attrs)
(indices extern-keyword cr-names)
(get (index)
(cond USI
((eq index (const 1)) ; STATUS reg ?
(or (or (or (or (sll USI kmbit (const 2))
(sll USI gidisablebit (const 1)))
(or (or (sll USI expcause1bit (const 17))
(sll USI expcause0bit (const 16)))
(or (sll USI expcause2bit (const 18))
(sll USI extFstallbit (const 19)))))
(or (or (or (sll USI busbit (const 15))
(sll USI bisbit (const 13)))
(or (sll USI bvsbit (const 14))
(sll USI vsbit (const 12))))
(or (or (sll USI bvbit (const 10))
(sll USI bcbit (const 11)))
(or (sll USI bnbit (const 9))
(sll USI bzbit (const 8))))))
(or (or (or (sll USI vbit (const 7))
(sll USI cbit (const 6)))
(or (sll USI nbit (const 5))
(sll USI zbit (const 4))))
(or (sll USI sflagbit (const 3))
(sll USI (const 1) (const 0)))))) ;caibit
((eq index (const 0)) ; Config reg ?
(or (or (or (or (or (or (sll USI timer0bit2 (const 6))
(sll USI timer0bit3 (const 7)))
(or (or (sll USI coreCfgResBit28 (const 28))
(sll USI coreCfgResBit29 (const 29)))
(or (sll USI coreCfgResBit30 (const 30))
(sll USI coreCfgResBit31 (const 31)))))
(or (or (sll USI coreCfgResBit24 (const 24))
(sll USI coreCfgResBit25 (const 25)))
(or (sll USI coreCfgResBit26 (const 26))
(sll USI coreCfgResBit27 (const 27)))))
(or (or (sll USI timer0bit0 (const 4))
(sll USI timer0bit1 (const 5)))
(or (sll USI coreCfgResBit14 (const 14))
(sll USI coreCfgResBit15 (const 15)))))
(or (or (or (or (sll USI timer1bit2 (const 10))
(sll USI timer1bit3 (const 11)))
(or (sll USI coreCfgResBit12 (const 12))
(sll USI coreCfgResBit13 (const 13))))
(or (sll USI clockGateEnbit (const 22))
(sll USI mbkptEnbit (const 23))))
(or (or (sll USI timer1bit0 (const 8))
(sll USI timer1bit1 (const 9)))
(or (sll USI coreCfgResBit20 (const 20))
(sll USI coreCfgResBit21 (const 21))))))
(or (or (sll USI invExcEnbit (const 1))
(sll USI ovfExcEnbit (const 2)))
(or (or (sll USI trmbit (const 0))
(sll USI unExcEnbit (const 3)))
(or (or (sll USI arithmetic-modebit0 (const 17))
(sll USI arithmetic-modebit1 (const 18)))
(or (sll USI arithmetic-modebit2 (const 19))
(sll USI coreCfgResBit16 (const 16)))))))) ;config reg
((eq index (const 2)) (raw-reg USI h-pc)) ;PC reg
(else (raw-reg USI h-core-registers index))))
(set (index val)
(cond VOID
((eq index (const 0)) ; CONFIG reg
(sequence ()
(set trmbit (and (const 1) (srl val (const 0))))
(set invExcEnbit (and (const 1) (srl val (const 1))))
(set ovfExcEnbit (and (const 1) (srl val (const 2))))
(set unExcEnbit (and (const 1) (srl val (const 3))))
(set timer0bit0 (and (const 1) (srl val (const 4))))
(set timer0bit1 (and (const 1) (srl val (const 5))))
(set timer0bit2 (and (const 1) (srl val (const 6))))
(set timer0bit3 (and (const 1) (srl val (const 7))))
(set timer1bit0 (and (const 1) (srl val (const 8))))
(set timer1bit1 (and (const 1) (srl val (const 9))))
(set timer1bit2 (and (const 1) (srl val (const 10))))
(set timer1bit3 (and (const 1) (srl val (const 11))))
(set coreCfgResBit12 (and (const 1) (srl val (const 12))))
(set coreCfgResBit13 (and (const 1) (srl val (const 13))))
(set coreCfgResBit14 (and (const 1) (srl val (const 14))))
(set coreCfgResBit15 (and (const 1) (srl val (const 15))))
(set coreCfgResBit16 (and (const 1) (srl val (const 16))))
(set arithmetic-modebit0 (and (const 1) (srl val (const 17))))
(set arithmetic-modebit1 (and (const 1) (srl val (const 18))))
(set arithmetic-modebit2 (and (const 1) (srl val (const 19))))
(set coreCfgResBit20 (and (const 1) (srl val (const 20))))
(set coreCfgResBit21 (and (const 1) (srl val (const 21))))
(set clockGateEnbit (and (const 1) (srl val (const 22))))
(set mbkptEnbit (and (const 1) (srl val (const 23))))
(set coreCfgResBit24 (and (const 1) (srl val (const 24))))
(set coreCfgResBit25 (and (const 1) (srl val (const 25))))
(set coreCfgResBit26 (and (const 1) (srl val (const 26))))
(set coreCfgResBit27 (and (const 1) (srl val (const 27))))
(set coreCfgResBit28 (and (const 1) (srl val (const 28))))
(set coreCfgResBit29 (and (const 1) (srl val (const 29))))
(set coreCfgResBit30 (and (const 1) (srl val (const 30))))
(set coreCfgResBit31 (and (const 1) (srl val (const 31))))
(set (raw-reg USI h-core-registers index) val)
;; check LSB of CONFIG for rounding mode
(c-call "epiphany_set_rounding_mode" val)
)
)
((eq index (const 1)) ;STATUS reg ; TODO check which bits can be set or clear
(sequence ((USI newval))
(set newval (and val (const #xfff2)))
(set extFstallbit (and (const 1) (srl newval (const 19))))
(set expcause2bit (and (const 1) (srl newval (const 18))))
(set expcause1bit (and (const 1) (srl newval (const 17))))
(set expcause0bit (and (const 1) (srl newval (const 16))))
(set busbit (and (const 1) (srl newval (const 15))))
(set bisbit (and (const 1) (srl newval (const 13))))
(set bvsbit (and (const 1) (srl newval (const 14))))
(set vsbit (and (const 1) (srl newval (const 12))))
(set bvbit (and (const 1) (srl newval (const 10))))
(set bcbit (and (const 1) (srl newval (const 11))))
(set bnbit (and (const 1) (srl newval (const 9))))
(set bzbit (and (const 1) (srl newval (const 8))))
(set vbit (and (const 1) (srl newval (const 7))))
(set cbit (and (const 1) (srl newval (const 6))))
(set nbit (and (const 1) (srl newval (const 5))))
(set zbit (and (const 1) (srl newval (const 4))))
(set sflagbit (and (const 1) (srl newval (const 3))))
(set kmbit (and (const 1) (srl newval (const 2))))
;;(set gie (and (const 1) (srl newval (const 1))))
(set (raw-reg SI h-core-registers (const 1)) newval)
))
;; causes simulator errors
;; ((eq index (const 2)) ;PC reg
;; (set pc val))
(else (set (raw-reg USI h-core-registers index) val))
))
)
; (define-pmacro (hcr-config) (reg h-core-registers 0)) etc.
(.splice begin (.unsplice (.map
(.pmacro (xname xnum)
(define-pmacro ((.sym hcr- xname)) (reg h-core-registers xnum)))
(
config
status
pc
debug
iab
lc
ls
le
iret
imask
ilat
ilatst
ilatcl
ipend
ctimer0
ctimer1
hstatus
)
(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
)
)))
;; DMA registers in MMR space
(define-hardware
(name h-coredma-registers)
(comment "DMA registers in MMR space")
(type register USI (16))
(attrs)
(indices extern-keyword crdma-names)
)
;; MEM registers in MMR space
(define-hardware
(name h-coremem-registers)
(comment "MEM registers in MMR space")
(type register USI (4))
(attrs)
(indices extern-keyword crmem-names)
)
;; MEM registers in MMR space
(define-hardware
(name h-coremesh-registers)
(comment "MESH registers in MMR space")
(type register USI (4))
(attrs)
(indices extern-keyword crmesh-names)
)
; Operands
; Branch displacements
(define-operand
(name simm24)
(comment "branch address pc-relative")
(attrs RELAX)
(type h-iaddr)
(index f-simm24)
(handlers (parse "branch_addr")))
(define-operand
(name simm8)
(comment "branch address pc-relative")
(attrs RELAX)
(type h-iaddr)
(index f-simm8)
(handlers (parse "branch_addr")))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Register operands
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-pmacro (short-regs nm group hw cmt)
(define-operand
(name nm)
(comment cmt)
(attrs)
(type hw)
(index (.sym "f-r" group))
(handlers (parse "shortregs") (print "keyword"))
)
)
(define-pmacro (short-regs-core nm group hw cmt)
(define-operand
(name nm)
(comment cmt)
(attrs)
(type hw)
(index (.sym "f-s" group))
(handlers (parse "shortregs") (print "keyword"))
)
)
; short regs (0-7)
(short-regs rd d h-registers "destination register")
(short-regs rn n h-registers "source register")
(short-regs rm m h-registers "source register")
(short-regs frd d h-fpregisters "fp destination register")
(short-regs frn n h-fpregisters "fp source register")
(short-regs frm m h-fpregisters "fp source register")
; long regs (0-63)
(dnop rd6 "destination register" () h-registers f-rd6)
(dnop rn6 "source register" () h-registers f-rn6)
(dnop rm6 "source register" () h-registers f-rm6)
(dnop frd6 "fp destination register" () h-fpregisters f-rd6)
(dnop frn6 "fp source register" () h-fpregisters f-rn6)
(dnop frm6 "fp source register" () h-fpregisters f-rm6)
; special regs (0-7)
(short-regs-core sd d h-core-registers "special destination")
(short-regs-core sn n h-core-registers "special source")
; special regs (long form)
(dnop sd6 "special destination register" () h-core-registers f-sd6)
(dnop sn6 "special source register" () h-core-registers f-sn6)
(dnop sddma "dma register" () h-coredma-registers f-sd6)
(dnop sndma "dma register" () h-coredma-registers f-sn6)
(dnop sdmem "mem register" () h-coremem-registers f-sd6)
(dnop snmem "mem register" () h-coremem-registers f-sn6)
(dnop sdmesh "mesh register" () h-coremesh-registers f-sd6)
(dnop snmesh "mesh register" () h-coremesh-registers f-sn6)
; Immediate literals - but don't allow register names!
(define-pmacro (dimmop nm cmt hwtype idx)
(define-operand (name nm) (comment cmt) (type hwtype) (index idx)
(attrs RELAX)
(handlers (parse "simm_not_reg")
(print "simm_not_reg")))
)