1 ; Lattice Mico32 CPU description. -*- Scheme -*-
2 ; Copyright 2008, 2009 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"
105 (BP0 16) (BP1 17) (BP2 18) (BP3 19)
106 (WP0 24) (WP1 25) (WP2 26) (WP3 27)
113 ; Instruction fields.
115 (dnf f-opcode "opcode field" () 31 6)
116 (dnf f-r0 "register index 0 field" () 25 5)
117 (dnf f-r1 "register index 1 field" () 20 5)
118 (dnf f-r2 "register index 2 field" () 15 5)
119 (dnf f-resv0 "reserved" (RESERVED) 10 11)
120 (dnf f-shift "shift amount field" () 4 5)
121 (df f-imm "signed immediate field" () 15 16 INT #f #f)
122 (dnf f-uimm "unsigned immediate field" () 15 16)
123 (dnf f-csr "csr field" () 25 5)
124 (dnf f-user "user defined field" () 10 11)
125 (dnf f-exception "exception field" () 25 26)
127 (df f-branch "branch offset field" (PCREL-ADDR) 15 16 INT
128 ((value pc) (sra SI (sub SI value pc) 2))
129 ((value pc) (add SI pc (sra SI (sll SI value 16) 14)))
131 (df f-call "call offset field" (PCREL-ADDR) 25 26 INT
132 ((value pc) (sra SI (sub SI value pc) 2))
133 ((value pc) (add SI pc (sra SI (sll SI value 6) 4)))
139 (dnop r0 "register 0" () h-gr f-r0)
140 (dnop r1 "register 1" () h-gr f-r1)
141 (dnop r2 "register 2" () h-gr f-r2)
142 (dnop shift "shift amout" () h-uint f-shift)
143 (dnop imm "signed immediate" () h-sint f-imm)
144 (dnop uimm "unsigned immediate" () h-uint f-uimm)
145 (dnop branch "branch offset" () h-iaddr f-branch)
146 (dnop call "call offset" () h-iaddr f-call)
147 (dnop csr "csr" () h-csr f-csr)
148 (dnop user "user" () h-uint f-user)
149 (dnop exception "exception" () h-uint f-exception)
153 (comment "high 16-bit immediate")
157 (handlers (parse "hi16"))
162 (comment "low 16-bit immediate")
166 (handlers (parse "lo16"))
171 (comment "gp relative 16-bit immediate")
175 (handlers (parse "gp16"))
180 (comment "got 16-bit immediate")
184 (handlers (parse "got16"))
189 (comment "got offset high 16-bit immediate")
193 (handlers (parse "gotoff_hi16"))
198 (comment "got offset low 16-bit immediate")
202 (handlers (parse "gotoff_lo16"))
208 (define-normal-insn-enum
209 opcodes "opcodes" () OP_ f-opcode
275 ; Instructions. Note: Reg-reg must come before reg-imm.
279 (+ OP_ADD r0 r1 r2 (f-resv0 0))
284 (dni addi "add immediate" ()
286 (+ OP_ADDI r0 r1 imm)
287 (set r1 (add r0 (ext SI (trunc HI imm))))
293 (+ OP_AND r0 r1 r2 (f-resv0 0))
298 (dni andi "and immediate" ()
300 (+ OP_ANDI r0 r1 uimm)
301 (set r1 (and r0 (zext SI uimm)))
305 (dni andhii "and high immediate" ()
306 "andhi $r1,$r0,$hi16"
307 (+ OP_ANDHI r0 r1 hi16)
308 (set r1 (and r0 (sll SI hi16 16)))
314 (+ OP_B r0 (f-r1 0) (f-r2 0) (f-resv0 0))
315 (set pc (c-call USI "@cpu@_b_insn" r0 f-r0))
319 (dni bi "branch immediate" ()
322 (set pc (ext SI call))
326 (dni be "branch equal" ()
328 (+ OP_BE r0 r1 branch)
335 (dni bg "branch greater" ()
337 (+ OP_BG r0 r1 branch)
344 (dni bge "branch greater or equal" ()
345 "bge $r0,$r1,$branch"
346 (+ OP_BGE r0 r1 branch)
353 (dni bgeu "branch greater or equal unsigned" ()
354 "bgeu $r0,$r1,$branch"
355 (+ OP_BGEU r0 r1 branch)
362 (dni bgu "branch greater unsigned" ()
363 "bgu $r0,$r1,$branch"
364 (+ OP_BGU r0 r1 branch)
371 (dni bne "branch not equal" ()
372 "bne $r0,$r1,$branch"
373 (+ OP_BNE r0 r1 branch)
382 (+ OP_CALL r0 (f-r1 0) (f-r2 0) (f-resv0 0))
384 (set (reg h-gr 29) (add pc 4))
390 (dni calli "call immediate" ()
394 (set (reg h-gr 29) (add pc 4))
395 (set pc (ext SI call))
400 (dni cmpe "compare equal" ()
402 (+ OP_CMPE r0 r1 r2 (f-resv0 0))
403 (set r2 (eq SI r0 r1))
407 (dni cmpei "compare equal immediate" ()
409 (+ OP_CMPEI r0 r1 imm)
410 (set r1 (eq SI r0 (ext SI (trunc HI imm))))
414 (dni cmpg "compare greater than" ()
416 (+ OP_CMPG r0 r1 r2 (f-resv0 0))
417 (set r2 (gt SI r0 r1))
421 (dni cmpgi "compare greater than immediate" ()
423 (+ OP_CMPGI r0 r1 imm)
424 (set r1 (gt SI r0 (ext SI (trunc HI imm))))
428 (dni cmpge "compare greater or equal" ()
430 (+ OP_CMPGE r0 r1 r2 (f-resv0 0))
431 (set r2 (ge SI r0 r1))
435 (dni cmpgei "compare greater or equal immediate" ()
436 "cmpgei $r1,$r0,$imm"
437 (+ OP_CMPGEI r0 r1 imm)
438 (set r1 (ge SI r0 (ext SI (trunc HI imm))))
442 (dni cmpgeu "compare greater or equal unsigned" ()
444 (+ OP_CMPGEU r0 r1 r2 (f-resv0 0))
445 (set r2 (geu SI r0 r1))
449 (dni cmpgeui "compare greater or equal unsigned immediate" ()
450 "cmpgeui $r1,$r0,$uimm"
451 (+ OP_CMPGEUI r0 r1 uimm)
452 (set r1 (geu SI r0 (zext SI uimm)))
456 (dni cmpgu "compare greater than unsigned" ()
458 (+ OP_CMPGU r0 r1 r2 (f-resv0 0))
459 (set r2 (gtu SI r0 r1))
463 (dni cmpgui "compare greater than unsigned immediate" ()
464 "cmpgui $r1,$r0,$uimm"
465 (+ OP_CMPGUI r0 r1 uimm)
466 (set r1 (gtu SI r0 (zext SI uimm)))
470 (dni cmpne "compare not equal" ()
472 (+ OP_CMPNE r0 r1 r2 (f-resv0 0))
473 (set r2 (ne SI r0 r1))
477 (dni cmpnei "compare not equal immediate" ()
478 "cmpnei $r1,$r0,$imm"
479 (+ OP_CMPNEI r0 r1 imm)
480 (set r1 (ne SI r0 (ext SI (trunc HI imm))))
484 (dni divu "unsigned divide" ()
486 (+ OP_DIVU r0 r1 r2 (f-resv0 0))
487 (set pc (c-call USI "@cpu@_divu_insn" pc f-r0 f-r1 f-r2))
491 (dni lb "load byte" ()
494 (set r1 (ext SI (mem QI (add r0 (ext SI (trunc HI imm))))))
498 (dni lbu "load byte unsigned" ()
501 (set r1 (zext SI (mem QI (add r0 (ext SI (trunc HI imm))))))
505 (dni lh "load halfword" ()
508 (set r1 (ext SI (mem HI (add r0 (ext SI (trunc HI imm))))))
512 (dni lhu "load halfword unsigned" ()
515 (set r1 (zext SI (mem HI (add r0 (ext SI (trunc HI imm))))))
519 (dni lw "load word" ()
522 (set r1 (mem SI (add r0 (ext SI (trunc HI imm)))))
526 (dni modu "unsigned modulus" ()
528 (+ OP_MODU r0 r1 r2 (f-resv0 0))
529 (set pc (c-call USI "@cpu@_modu_insn" pc f-r0 f-r1 f-r2))
533 (dni mul "mulitply" ()
535 (+ OP_MUL r0 r1 r2 (f-resv0 0))
540 (dni muli "multiply immediate" ()
542 (+ OP_MULI r0 r1 imm)
543 (set r1 (mul r0 (ext SI (trunc HI imm))))
549 (+ OP_NOR r0 r1 r2 (f-resv0 0))
550 (set r2 (inv (or r0 r1)))
554 (dni nori "nor immediate" ()
556 (+ OP_NORI r0 r1 uimm)
557 (set r1 (inv (or r0 (zext SI uimm))))
563 (+ OP_OR r0 r1 r2 (f-resv0 0))
568 (dni ori "or immediate" ()
570 (+ OP_ORI r0 r1 lo16)
571 (set r1 (or r0 (zext SI lo16)))
575 (dni orhii "or high immediate" ()
577 (+ OP_ORHI r0 r1 hi16)
578 (set r1 (or r0 (sll SI hi16 16)))
582 (dni rcsr "read control or status register" ()
584 (+ OP_RCSR csr (f-r1 0) r2 (f-resv0 0))
589 (dni sb "store byte" ()
592 (set (mem QI (add r0 (ext SI (trunc HI imm)))) r1)
596 (dni sextb "sign extend byte" ()
598 (+ OP_SEXTB r0 (f-r1 0) r2 (f-resv0 0))
599 (set r2 (ext SI (trunc QI r0)))
603 (dni sexth "sign extend half-word" ()
605 (+ OP_SEXTH r0 (f-r1 0) r2 (f-resv0 0))
606 (set r2 (ext SI (trunc HI r0)))
610 (dni sh "store halfword" ()
613 (set (mem HI (add r0 (ext SI (trunc HI imm)))) r1)
617 (dni sl "shift left" ()
619 (+ OP_SL r0 r1 r2 (f-resv0 0))
620 (set r2 (sll SI r0 r1))
624 (dni sli "shift left immediate" ()
627 (set r1 (sll SI r0 imm))
631 (dni sr "shift right" ()
633 (+ OP_SR r0 r1 r2 (f-resv0 0))
634 (set r2 (sra SI r0 r1))
638 (dni sri "shift right immediate" ()
641 (set r1 (sra SI r0 imm))
645 (dni sru "shift right unsigned" ()
647 (+ OP_SRU r0 r1 r2 (f-resv0 0))
648 (set r2 (srl SI r0 r1))
652 (dni srui "shift right unsigned immediate" ()
654 (+ OP_SRUI r0 r1 imm)
655 (set r1 (srl SI r0 imm))
659 (dni sub "subtract" ()
661 (+ OP_SUB r0 r1 r2 (f-resv0 0))
666 (dni sw "store word" ()
669 (set (mem SI (add r0 (ext SI (trunc HI imm)))) r1)
673 (dni user "user defined instruction" ()
674 "user $r2,$r0,$r1,$user"
675 (+ OP_USER r0 r1 r2 user)
676 (set r2 (c-call SI "@cpu@_user_insn" r0 r1 user))
680 (dni wcsr "write control or status register" ()
682 (+ OP_WCSR csr r1 (f-r2 0) (f-resv0 0))
683 (c-call VOID "@cpu@_wcsr_insn" f-csr r1)
689 (+ OP_XOR r0 r1 r2 (f-resv0 0))
694 (dni xori "xor immediate" ()
696 (+ OP_XORI r0 r1 uimm)
697 (set r1 (xor r0 (zext SI uimm)))
703 (+ OP_XNOR r0 r1 r2 (f-resv0 0))
704 (set r2 (inv (xor r0 r1)))
708 (dni xnori "xnor immediate" ()
709 "xnori $r1,$r0,$uimm"
710 (+ OP_XNORI r0 r1 uimm)
711 (set r1 (inv (xor r0 (zext SI uimm))))
715 ; Pseudo instructions
717 (dni break "breakpoint" ()
719 (+ OP_RAISE (f-exception 2))
720 (set pc (c-call USI "@cpu@_break_insn" pc))
724 (dni scall "system call" ()
726 (+ OP_RAISE (f-exception 7))
727 (set pc (c-call USI "@cpu@_scall_insn" pc))
731 (dni bret "return from breakpoint" (ALIAS)
733 (+ OP_B (f-r0 31) (f-r1 0) (f-r2 0) (f-resv0 0))
734 (set pc (c-call USI "@cpu@_bret_insn" r0))
738 (dni eret "return from exception" (ALIAS)
740 (+ OP_B (f-r0 30) (f-r1 0) (f-r2 0) (f-resv0 0))
741 (set pc (c-call USI "@cpu@_eret_insn" r0))
745 (dni ret "return" (ALIAS)
747 (+ OP_B (f-r0 29) (f-r1 0) (f-r2 0) (f-resv0 0))
752 (dni mv "move" (ALIAS)
754 (+ OP_OR r0 (f-r1 0) r2 (f-resv0 0))
759 (dni mvi "move immediate" (ALIAS)
761 (+ OP_ADDI (f-r0 0) r1 imm)
762 (set r1 (add r0 (ext SI (trunc HI imm))))
766 (dni mvui "move unsigned immediate" (ALIAS)
768 (+ OP_ORI (f-r0 0) r1 lo16)
769 (set r1 (zext SI lo16))
773 (dni mvhi "move high immediate" (ALIAS)
775 (+ OP_ORHI (f-r0 0) r1 hi16)
776 (set r1 (or r0 (sll SI hi16 16)))
780 (dni mva "move address" (ALIAS)
782 (+ OP_ADDI (f-r0 26) r1 gp16)
783 (set r1 (add r0 (ext SI (trunc HI gp16))))
787 (dni not "not" (ALIAS)
789 (+ OP_XNOR r0 (f-r1 0) r2 (f-resv0 0))
794 (dni nop "nop" (ALIAS)
796 (+ OP_ADDI (f-r0 0) (f-r1 0) (f-imm 0))
801 (dni lbgprel "load byte gp relative" (ALIAS)
803 (+ OP_LB (f-r0 26) r1 gp16)
804 (set r1 (ext SI (mem QI (add r0 (ext SI (trunc HI gp16))))))
808 (dni lbugprel "load byte unsigned gp relative" (ALIAS)
810 (+ OP_LBU (f-r0 26) r1 gp16)
811 (set r1 (zext SI (mem QI (add r0 (ext SI (trunc HI gp16))))))
815 (dni lhgprel "load halfword gp relative" (ALIAS)
817 (+ OP_LH (f-r0 26) r1 gp16)
818 (set r1 (ext SI (mem HI (add r0 (ext SI (trunc HI gp16))))))
822 (dni lhugprel "load halfword unsigned gp relative" (ALIAS)
824 (+ OP_LHU (f-r0 26) r1 gp16)
825 (set r1 (zext SI (mem HI (add r0 (ext SI (trunc HI gp16))))))
829 (dni lwgprel "load word gp relative" (ALIAS)
831 (+ OP_LW (f-r0 26) r1 gp16)
832 (set r1 (mem SI (add r0 (ext SI (trunc HI gp16)))))
836 (dni sbgprel "store byte gp relative" (ALIAS)
838 (+ OP_SB (f-r0 26) r1 gp16)
839 (set (mem QI (add r0 (ext SI (trunc HI gp16)))) r1)
843 (dni shgprel "store halfword gp relative" (ALIAS)
845 (+ OP_SH (f-r0 26) r1 gp16)
846 (set (mem HI (add r0 (ext SI (trunc HI gp16)))) r1)
850 (dni swgprel "store word gp relative" (ALIAS)
852 (+ OP_SW (f-r0 26) r1 gp16)
853 (set (mem SI (add r0 (ext SI (trunc HI gp16)))) r1)
857 (dni lwgotrel "load word got relative" (ALIAS)
859 (+ OP_LW (f-r0 26) r1 got16)
860 (set r1 (mem SI (add r0 (ext SI (trunc HI got16)))))
864 (dni orhigotoffi "or high got offset immediate" (ALIAS)
865 "orhi $r1,$r0,$gotoffhi16"
866 (+ OP_ORHI r0 r1 gotoffhi16)
867 (set r1 (or r0 (sll SI gotoffhi16 16)))
871 (dni addgotoff "add got offset" (ALIAS)
872 "addi $r1,$r0,$gotofflo16"
873 (+ OP_ADDI r0 r1 gotofflo16)
874 (set r1 (add r0 (ext SI (trunc HI gotofflo16))))
878 (dni swgotoff "store word got offset" (ALIAS)
879 "sw ($r0+$gotofflo16),$r1"
880 (+ OP_SW r0 r1 gotofflo16)
881 (set (mem SI (add r0 (ext SI (trunc HI gotofflo16)))) r1)
885 (dni lwgotoff "load word got offset" (ALIAS)
886 "lw $r1,($r0+$gotofflo16)"
887 (+ OP_LW r0 r1 gotofflo16)
888 (set r1 (mem SI (add r0 (ext SI (trunc HI gotofflo16)))))
892 (dni shgotoff "store half word got offset" (ALIAS)
893 "sh ($r0+$gotofflo16),$r1"
894 (+ OP_SH r0 r1 gotofflo16)
895 (set (mem HI (add r0 (ext SI (trunc HI gotofflo16)))) r1)
899 (dni lhgotoff "load half word got offset" (ALIAS)
900 "lh $r1,($r0+$gotofflo16)"
901 (+ OP_LH r0 r1 gotofflo16)
902 (set r1 (ext SI (mem HI (add r0 (ext SI (trunc HI gotofflo16))))))
906 (dni lhugotoff "load half word got offset unsigned" (ALIAS)
907 "lhu $r1,($r0+$gotofflo16)"
908 (+ OP_LHU r0 r1 gotofflo16)
909 (set r1 (zext SI (mem HI (add r0 (ext SI (trunc HI gotofflo16))))))
913 (dni sbgotoff "store byte got offset" (ALIAS)
914 "sb ($r0+$gotofflo16),$r1"
915 (+ OP_SB r0 r1 gotofflo16)
916 (set (mem QI (add r0 (ext SI (trunc HI gotofflo16)))) r1)
920 (dni lbgotoff "load byte got offset" (ALIAS)
921 "lb $r1,($r0+$gotofflo16)"
922 (+ OP_LB r0 r1 gotofflo16)
923 (set r1 (ext SI (mem QI (add r0 (ext SI (trunc HI gotofflo16))))))
927 (dni lbugotoff "load byte got offset unsigned" (ALIAS)
928 "lbu $r1,($r0+$gotofflo16)"
929 (+ OP_LBU r0 r1 gotofflo16)
930 (set r1 (zext SI (mem QI (add r0 (ext SI (trunc HI gotofflo16))))))