1 ; Lattice Mico32 CPU description. -*- Scheme -*-
2 ; Copyright 2008-2013 Free Software Foundation, Inc.
3 ; Contributed by Jon Beniston <jon@beniston.com>
5 ; This file is part of the GNU Binutils.
7 ; This program is free software; you can redistribute it and/or modify
8 ; it under the terms of the GNU General Public License as published by
9 ; the Free Software Foundation; either version 3 of the License, or
10 ; (at your option) any later version.
12 ; This program is distributed in the hope that it will be useful,
13 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ; GNU General Public License for more details.
17 ; You should have received a copy of the GNU General Public License
18 ; along with this program; if not, write to the Free Software
19 ; Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 (include "simplify.inc")
25 (name lm32) ; name of cpu family
26 (comment "Lattice Mico32")
27 (default-alignment aligned)
38 (comment "Lattice Mico32 ISA")
39 (default-insn-word-bitsize 32)
40 (default-insn-bitsize 32)
41 (base-insn-bitsize 32)
42 (decode-assist (31 30 29 28 27 26))
46 ; Cpu family definitions.
49 ; cpu names must be distinct from the architecture name and machine name
51 (comment "Lattice Mico32 CPU")
58 (comment "Lattice Mico32 MACH")
64 (comment "Lattice Mico32 reference implementation")
66 (unit u-exec "Execution unit" ()
73 (dnh h-pc "Program counter" (PC) (pc) () () ())
75 (dnh h-gr "General purpose registers"
79 (gp 26) (fp 27) (sp 28) (ra 29) (ea 30) (ba 31)
80 (r0 0) (r1 1) (r2 2) (r3 3)
81 (r4 4) (r5 5) (r6 6) (r7 7)
82 (r8 8) (r9 9) (r10 10) (r11 11)
83 (r12 12) (r13 13) (r14 14) (r15 15)
84 (r16 16) (r17 17) (r18 18) (r19 19)
85 (r20 20) (r21 21) (r22 22) (r23 23)
86 (r24 24) (r25 25) (r26 26) (r27 27)
87 (r28 28) (r29 29) (r30 30) (r31 31)
93 (dnh h-csr "Control and status registers"
106 (BP0 16) (BP1 17) (BP2 18) (BP3 19)
107 (WP0 24) (WP1 25) (WP2 26) (WP3 27)
108 (PSW 29) (TLBVADDR 30) (TLBPADDR 31) (TLBBADVADDR 31)
115 ; Instruction fields.
117 (dnf f-opcode "opcode field" () 31 6)
118 (dnf f-r0 "register index 0 field" () 25 5)
119 (dnf f-r1 "register index 1 field" () 20 5)
120 (dnf f-r2 "register index 2 field" () 15 5)
121 (dnf f-resv0 "reserved" (RESERVED) 10 11)
122 (dnf f-shift "shift amount field" () 4 5)
123 (df f-imm "signed immediate field" () 15 16 INT #f #f)
124 (dnf f-uimm "unsigned immediate field" () 15 16)
125 (dnf f-csr "csr field" () 25 5)
126 (dnf f-user "user defined field" () 10 11)
127 (dnf f-exception "exception field" () 25 26)
129 (df f-branch "branch offset field" (PCREL-ADDR) 15 16 INT
130 ((value pc) (sra SI (sub SI value pc) 2))
131 ((value pc) (add SI pc (sub (xor (sll (and value #xffff) 2)
135 (df f-call "call offset field" (PCREL-ADDR) 25 26 INT
136 ((value pc) (sra SI (sub SI value pc) 2))
137 ((value pc) (add SI pc (sub (xor (sll (and value #x3ffffff) 2)
145 (dnop r0 "register 0" () h-gr f-r0)
146 (dnop r1 "register 1" () h-gr f-r1)
147 (dnop r2 "register 2" () h-gr f-r2)
148 (dnop shift "shift amout" () h-uint f-shift)
149 (dnop imm "signed immediate" () h-sint f-imm)
150 (dnop uimm "unsigned immediate" () h-uint f-uimm)
151 (dnop branch "branch offset" () h-iaddr f-branch)
152 (dnop call "call offset" () h-iaddr f-call)
153 (dnop csr "csr" () h-csr f-csr)
154 (dnop user "user" () h-uint f-user)
155 (dnop exception "exception" () h-uint f-exception)
159 (comment "high 16-bit immediate")
163 (handlers (parse "hi16"))
168 (comment "low 16-bit immediate")
172 (handlers (parse "lo16"))
177 (comment "gp relative 16-bit immediate")
181 (handlers (parse "gp16"))
186 (comment "got 16-bit immediate")
190 (handlers (parse "got16"))
195 (comment "got offset high 16-bit immediate")
199 (handlers (parse "gotoff_hi16"))
204 (comment "got offset low 16-bit immediate")
208 (handlers (parse "gotoff_lo16"))
214 (define-normal-insn-enum
215 opcodes "opcodes" () OP_ f-opcode
281 ; Instructions. Note: Reg-reg must come before reg-imm.
285 (+ OP_ADD r0 r1 r2 (f-resv0 0))
290 (dni addi "add immediate" ()
292 (+ OP_ADDI r0 r1 imm)
293 (set r1 (add r0 (ext SI (trunc HI imm))))
299 (+ OP_AND r0 r1 r2 (f-resv0 0))
304 (dni andi "and immediate" ()
306 (+ OP_ANDI r0 r1 uimm)
307 (set r1 (and r0 (zext SI uimm)))
311 (dni andhii "and high immediate" ()
312 "andhi $r1,$r0,$hi16"
313 (+ OP_ANDHI r0 r1 hi16)
314 (set r1 (and r0 (sll SI hi16 16)))
320 (+ OP_B r0 (f-r1 0) (f-r2 0) (f-resv0 0))
321 (set pc (c-call USI "@cpu@_b_insn" r0 f-r0))
325 (dni bi "branch immediate" ()
328 (set pc (ext SI call))
332 (dni be "branch equal" ()
334 (+ OP_BE r0 r1 branch)
341 (dni bg "branch greater" ()
343 (+ OP_BG r0 r1 branch)
350 (dni bge "branch greater or equal" ()
351 "bge $r0,$r1,$branch"
352 (+ OP_BGE r0 r1 branch)
359 (dni bgeu "branch greater or equal unsigned" ()
360 "bgeu $r0,$r1,$branch"
361 (+ OP_BGEU r0 r1 branch)
368 (dni bgu "branch greater unsigned" ()
369 "bgu $r0,$r1,$branch"
370 (+ OP_BGU r0 r1 branch)
377 (dni bne "branch not equal" ()
378 "bne $r0,$r1,$branch"
379 (+ OP_BNE r0 r1 branch)
388 (+ OP_CALL r0 (f-r1 0) (f-r2 0) (f-resv0 0))
390 (set (reg h-gr 29) (add pc 4))
396 (dni calli "call immediate" ()
400 (set (reg h-gr 29) (add pc 4))
401 (set pc (ext SI call))
406 (dni cmpe "compare equal" ()
408 (+ OP_CMPE r0 r1 r2 (f-resv0 0))
409 (set r2 (eq SI r0 r1))
413 (dni cmpei "compare equal immediate" ()
415 (+ OP_CMPEI r0 r1 imm)
416 (set r1 (eq SI r0 (ext SI (trunc HI imm))))
420 (dni cmpg "compare greater than" ()
422 (+ OP_CMPG r0 r1 r2 (f-resv0 0))
423 (set r2 (gt SI r0 r1))
427 (dni cmpgi "compare greater than immediate" ()
429 (+ OP_CMPGI r0 r1 imm)
430 (set r1 (gt SI r0 (ext SI (trunc HI imm))))
434 (dni cmpge "compare greater or equal" ()
436 (+ OP_CMPGE r0 r1 r2 (f-resv0 0))
437 (set r2 (ge SI r0 r1))
441 (dni cmpgei "compare greater or equal immediate" ()
442 "cmpgei $r1,$r0,$imm"
443 (+ OP_CMPGEI r0 r1 imm)
444 (set r1 (ge SI r0 (ext SI (trunc HI imm))))
448 (dni cmpgeu "compare greater or equal unsigned" ()
450 (+ OP_CMPGEU r0 r1 r2 (f-resv0 0))
451 (set r2 (geu SI r0 r1))
455 (dni cmpgeui "compare greater or equal unsigned immediate" ()
456 "cmpgeui $r1,$r0,$uimm"
457 (+ OP_CMPGEUI r0 r1 uimm)
458 (set r1 (geu SI r0 (zext SI uimm)))
462 (dni cmpgu "compare greater than unsigned" ()
464 (+ OP_CMPGU r0 r1 r2 (f-resv0 0))
465 (set r2 (gtu SI r0 r1))
469 (dni cmpgui "compare greater than unsigned immediate" ()
470 "cmpgui $r1,$r0,$uimm"
471 (+ OP_CMPGUI r0 r1 uimm)
472 (set r1 (gtu SI r0 (zext SI uimm)))
476 (dni cmpne "compare not equal" ()
478 (+ OP_CMPNE r0 r1 r2 (f-resv0 0))
479 (set r2 (ne SI r0 r1))
483 (dni cmpnei "compare not equal immediate" ()
484 "cmpnei $r1,$r0,$imm"
485 (+ OP_CMPNEI r0 r1 imm)
486 (set r1 (ne SI r0 (ext SI (trunc HI imm))))
490 (dni divu "unsigned divide" ()
492 (+ OP_DIVU r0 r1 r2 (f-resv0 0))
493 (set pc (c-call USI "@cpu@_divu_insn" pc f-r0 f-r1 f-r2))
497 (dni lb "load byte" ()
500 (set r1 (ext SI (mem QI (add r0 (ext SI (trunc HI imm))))))
504 (dni lbu "load byte unsigned" ()
507 (set r1 (zext SI (mem QI (add r0 (ext SI (trunc HI imm))))))
511 (dni lh "load halfword" ()
514 (set r1 (ext SI (mem HI (add r0 (ext SI (trunc HI imm))))))
518 (dni lhu "load halfword unsigned" ()
521 (set r1 (zext SI (mem HI (add r0 (ext SI (trunc HI imm))))))
525 (dni lw "load word" ()
528 (set r1 (mem SI (add r0 (ext SI (trunc HI imm)))))
532 (dni modu "unsigned modulus" ()
534 (+ OP_MODU r0 r1 r2 (f-resv0 0))
535 (set pc (c-call USI "@cpu@_modu_insn" pc f-r0 f-r1 f-r2))
539 (dni mul "mulitply" ()
541 (+ OP_MUL r0 r1 r2 (f-resv0 0))
546 (dni muli "multiply immediate" ()
548 (+ OP_MULI r0 r1 imm)
549 (set r1 (mul r0 (ext SI (trunc HI imm))))
555 (+ OP_NOR r0 r1 r2 (f-resv0 0))
556 (set r2 (inv (or r0 r1)))
560 (dni nori "nor immediate" ()
562 (+ OP_NORI r0 r1 uimm)
563 (set r1 (inv (or r0 (zext SI uimm))))
569 (+ OP_OR r0 r1 r2 (f-resv0 0))
574 (dni ori "or immediate" ()
576 (+ OP_ORI r0 r1 lo16)
577 (set r1 (or r0 (zext SI lo16)))
581 (dni orhii "or high immediate" ()
583 (+ OP_ORHI r0 r1 hi16)
584 (set r1 (or r0 (sll SI hi16 16)))
588 (dni rcsr "read control or status register" ()
590 (+ OP_RCSR csr (f-r1 0) r2 (f-resv0 0))
595 (dni sb "store byte" ()
598 (set (mem QI (add r0 (ext SI (trunc HI imm)))) r1)
602 (dni sextb "sign extend byte" ()
604 (+ OP_SEXTB r0 (f-r1 0) r2 (f-resv0 0))
605 (set r2 (ext SI (trunc QI r0)))
609 (dni sexth "sign extend half-word" ()
611 (+ OP_SEXTH r0 (f-r1 0) r2 (f-resv0 0))
612 (set r2 (ext SI (trunc HI r0)))
616 (dni sh "store halfword" ()
619 (set (mem HI (add r0 (ext SI (trunc HI imm)))) r1)
623 (dni sl "shift left" ()
625 (+ OP_SL r0 r1 r2 (f-resv0 0))
626 (set r2 (sll SI r0 r1))
630 (dni sli "shift left immediate" ()
633 (set r1 (sll SI r0 imm))
637 (dni sr "shift right" ()
639 (+ OP_SR r0 r1 r2 (f-resv0 0))
640 (set r2 (sra SI r0 r1))
644 (dni sri "shift right immediate" ()
647 (set r1 (sra SI r0 imm))
651 (dni sru "shift right unsigned" ()
653 (+ OP_SRU r0 r1 r2 (f-resv0 0))
654 (set r2 (srl SI r0 r1))
658 (dni srui "shift right unsigned immediate" ()
660 (+ OP_SRUI r0 r1 imm)
661 (set r1 (srl SI r0 imm))
665 (dni sub "subtract" ()
667 (+ OP_SUB r0 r1 r2 (f-resv0 0))
672 (dni sw "store word" ()
675 (set (mem SI (add r0 (ext SI (trunc HI imm)))) r1)
679 (dni user "user defined instruction" ()
680 "user $r2,$r0,$r1,$user"
681 (+ OP_USER r0 r1 r2 user)
682 (set r2 (c-call SI "@cpu@_user_insn" r0 r1 user))
686 (dni wcsr "write control or status register" ()
688 (+ OP_WCSR csr r1 (f-r2 0) (f-resv0 0))
689 (c-call VOID "@cpu@_wcsr_insn" f-csr r1)
695 (+ OP_XOR r0 r1 r2 (f-resv0 0))
700 (dni xori "xor immediate" ()
702 (+ OP_XORI r0 r1 uimm)
703 (set r1 (xor r0 (zext SI uimm)))
709 (+ OP_XNOR r0 r1 r2 (f-resv0 0))
710 (set r2 (inv (xor r0 r1)))
714 (dni xnori "xnor immediate" ()
715 "xnori $r1,$r0,$uimm"
716 (+ OP_XNORI r0 r1 uimm)
717 (set r1 (inv (xor r0 (zext SI uimm))))
721 ; Pseudo instructions
723 (dni break "breakpoint" ()
725 (+ OP_RAISE (f-exception 2))
726 (set pc (c-call USI "@cpu@_break_insn" pc))
730 (dni scall "system call" ()
732 (+ OP_RAISE (f-exception 7))
733 (set pc (c-call USI "@cpu@_scall_insn" pc))
737 (dni bret "return from breakpoint" (ALIAS)
739 (+ OP_B (f-r0 31) (f-r1 0) (f-r2 0) (f-resv0 0))
740 (set pc (c-call USI "@cpu@_bret_insn" r0))
744 (dni eret "return from exception" (ALIAS)
746 (+ OP_B (f-r0 30) (f-r1 0) (f-r2 0) (f-resv0 0))
747 (set pc (c-call USI "@cpu@_eret_insn" r0))
751 (dni ret "return" (ALIAS)
753 (+ OP_B (f-r0 29) (f-r1 0) (f-r2 0) (f-resv0 0))
758 (dni mv "move" (ALIAS)
760 (+ OP_OR r0 (f-r1 0) r2 (f-resv0 0))
765 (dni mvi "move immediate" (ALIAS)
767 (+ OP_ADDI (f-r0 0) r1 imm)
768 (set r1 (add r0 (ext SI (trunc HI imm))))
772 (dni mvui "move unsigned immediate" (ALIAS)
774 (+ OP_ORI (f-r0 0) r1 lo16)
775 (set r1 (zext SI lo16))
779 (dni mvhi "move high immediate" (ALIAS)
781 (+ OP_ORHI (f-r0 0) r1 hi16)
782 (set r1 (or r0 (sll SI hi16 16)))
786 (dni mva "move address" (ALIAS)
788 (+ OP_ADDI (f-r0 26) r1 gp16)
789 (set r1 (add r0 (ext SI (trunc HI gp16))))
793 (dni not "not" (ALIAS)
795 (+ OP_XNOR r0 (f-r1 0) r2 (f-resv0 0))
800 (dni nop "nop" (ALIAS)
802 (+ OP_ADDI (f-r0 0) (f-r1 0) (f-imm 0))
807 (dni lbgprel "load byte gp relative" (ALIAS)
809 (+ OP_LB (f-r0 26) r1 gp16)
810 (set r1 (ext SI (mem QI (add r0 (ext SI (trunc HI gp16))))))
814 (dni lbugprel "load byte unsigned gp relative" (ALIAS)
816 (+ OP_LBU (f-r0 26) r1 gp16)
817 (set r1 (zext SI (mem QI (add r0 (ext SI (trunc HI gp16))))))
821 (dni lhgprel "load halfword gp relative" (ALIAS)
823 (+ OP_LH (f-r0 26) r1 gp16)
824 (set r1 (ext SI (mem HI (add r0 (ext SI (trunc HI gp16))))))
828 (dni lhugprel "load halfword unsigned gp relative" (ALIAS)
830 (+ OP_LHU (f-r0 26) r1 gp16)
831 (set r1 (zext SI (mem HI (add r0 (ext SI (trunc HI gp16))))))
835 (dni lwgprel "load word gp relative" (ALIAS)
837 (+ OP_LW (f-r0 26) r1 gp16)
838 (set r1 (mem SI (add r0 (ext SI (trunc HI gp16)))))
842 (dni sbgprel "store byte gp relative" (ALIAS)
844 (+ OP_SB (f-r0 26) r1 gp16)
845 (set (mem QI (add r0 (ext SI (trunc HI gp16)))) r1)
849 (dni shgprel "store halfword gp relative" (ALIAS)
851 (+ OP_SH (f-r0 26) r1 gp16)
852 (set (mem HI (add r0 (ext SI (trunc HI gp16)))) r1)
856 (dni swgprel "store word gp relative" (ALIAS)
858 (+ OP_SW (f-r0 26) r1 gp16)
859 (set (mem SI (add r0 (ext SI (trunc HI gp16)))) r1)
863 (dni lwgotrel "load word got relative" (ALIAS)
865 (+ OP_LW (f-r0 26) r1 got16)
866 (set r1 (mem SI (add r0 (ext SI (trunc HI got16)))))
870 (dni orhigotoffi "or high got offset immediate" (ALIAS)
871 "orhi $r1,$r0,$gotoffhi16"
872 (+ OP_ORHI r0 r1 gotoffhi16)
873 (set r1 (or r0 (sll SI gotoffhi16 16)))
877 (dni addgotoff "add got offset" (ALIAS)
878 "addi $r1,$r0,$gotofflo16"
879 (+ OP_ADDI r0 r1 gotofflo16)
880 (set r1 (add r0 (ext SI (trunc HI gotofflo16))))
884 (dni swgotoff "store word got offset" (ALIAS)
885 "sw ($r0+$gotofflo16),$r1"
886 (+ OP_SW r0 r1 gotofflo16)
887 (set (mem SI (add r0 (ext SI (trunc HI gotofflo16)))) r1)
891 (dni lwgotoff "load word got offset" (ALIAS)
892 "lw $r1,($r0+$gotofflo16)"
893 (+ OP_LW r0 r1 gotofflo16)
894 (set r1 (mem SI (add r0 (ext SI (trunc HI gotofflo16)))))
898 (dni shgotoff "store half word got offset" (ALIAS)
899 "sh ($r0+$gotofflo16),$r1"
900 (+ OP_SH r0 r1 gotofflo16)
901 (set (mem HI (add r0 (ext SI (trunc HI gotofflo16)))) r1)
905 (dni lhgotoff "load half word got offset" (ALIAS)
906 "lh $r1,($r0+$gotofflo16)"
907 (+ OP_LH r0 r1 gotofflo16)
908 (set r1 (ext SI (mem HI (add r0 (ext SI (trunc HI gotofflo16))))))
912 (dni lhugotoff "load half word got offset unsigned" (ALIAS)
913 "lhu $r1,($r0+$gotofflo16)"
914 (+ OP_LHU r0 r1 gotofflo16)
915 (set r1 (zext SI (mem HI (add r0 (ext SI (trunc HI gotofflo16))))))
919 (dni sbgotoff "store byte got offset" (ALIAS)
920 "sb ($r0+$gotofflo16),$r1"
921 (+ OP_SB r0 r1 gotofflo16)
922 (set (mem QI (add r0 (ext SI (trunc HI gotofflo16)))) r1)
926 (dni lbgotoff "load byte got offset" (ALIAS)
927 "lb $r1,($r0+$gotofflo16)"
928 (+ OP_LB r0 r1 gotofflo16)
929 (set r1 (ext SI (mem QI (add r0 (ext SI (trunc HI gotofflo16))))))
933 (dni lbugotoff "load byte got offset unsigned" (ALIAS)
934 "lbu $r1,($r0+$gotofflo16)"
935 (+ OP_LBU r0 r1 gotofflo16)
936 (set r1 (zext SI (mem QI (add r0 (ext SI (trunc HI gotofflo16))))))