1 ; OpenRISC family. -*- Scheme -*-
2 ; Copyright 2000, 2001, 2011 Free Software Foundation, Inc.
3 ; Contributed by Johan Rydberg, jrydberg@opencores.org
5 ; This program is free software; you can redistribute it and/or modify
6 ; it under the terms of the GNU General Public License as published by
7 ; the Free Software Foundation; either version 2 of the License, or
8 ; (at your option) any later version.
10 ; This program is distributed in the hope that it will be useful,
11 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ; GNU General Public License for more details.
15 ; You should have received a copy of the GNU General Public License
16 ; along with this program; if not, write to the Free Software
17 ; Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
19 (include "simplify.inc")
21 ; OpenRISC 1000 is an architecture of a family of open source,
22 ; synthesizeable RISC microprocessor cores. It is a 32-bit load
23 ; and store RISC architecture designed with emphasis on speed,
24 ; compact instruction set and scalability. OpenRISC 1000 targets
25 ; wide range of embedded environments.
29 (comment "OpenRISC 1000")
31 (machs openrisc or1300)
38 ; An attribute to describe if a model has insn and/or data caches.
43 (comment "if this model has caches")
44 (values DATA-CACHE INSN-CACHE)
47 ; An attribute to describe if an insn can be in the delay slot or not.
51 (name NOT-IN-DELAY-SLOT)
52 (comment "insn can't go in delay slot")
55 ; IDOC attribute for instruction documentation.
61 (comment "insn kind for documentation")
68 (PRIV - () "Priviledged")
69 (MISC - () "Miscellaneous")
73 ; Enum for exception vectors.
76 (comment "exception vectors")
79 (values (("RESET") ("BUSERR" -) ("DPF" -) ("IPF" -) ("EXTINT" -) ("ALIGN" -)
80 ("ILLEGAL" -) ("PEINT" -) ("DTLBMISS" -) ("ITLBMISS" -) ("RRANGE" -)
81 ("SYSCALL" -) ("BREAK" -) ("RESERVED" -)))
85 ; Instruction set parameters.
91 ; Base insturction length. The insns is always 32 bits wide.
92 (base-insn-bitsize 32)
94 ; Address of insn in delay slot
95 (setup-semantics (set-quiet (reg h-delay-insn) (add pc 4)))
99 ; CPU family definitions.
102 ; CPU names must be distinct from the architecture name and machine names.
103 ; The "b" suffix stands for "base" and is the convention.
104 ; The "f" suffix stands for "family" and is the convention.
106 (comment "OpenRISC base family")
114 (comment "Generic OpenRISC cpu")
116 (bfd-name "openrisc")
119 ; OpenRISC 1300 machine
122 (comment "OpenRISC 1300")
124 (bfd-name "openrisc:1300")
130 ; Generic OpenRISC model
132 (name openrisc-1) (comment "OpenRISC generic model") (attrs)
135 ; Nothing special about this.
136 (unit u-exec "Execution Unit" () 1 1 () () () ())
141 (name or1320-1) (comment "OpenRISC 1320 model")
143 ; This model has both instruction and data cache
144 (attrs (HAS-CACHE INSN-CACHE,DATA-CACHE))
147 ; Nothing special about this.
148 (unit u-exec "Execution Unit" () 1 1 () () () ())
152 ; Instruction fields.
155 ; . PCREL-ADDR pc relative value (for reloc and disassembly purposes)
156 ; . ABS-ADDR absolute address (for reloc and disassembly purposes?)
157 ; . RESERVED bits are not used to decode insn, must be all 0
159 ; Instruction classes.
160 (dnf f-class "insn class" () 31 2)
161 (dnf f-sub "sub class" () 29 4)
164 (dnf f-r1 "r1" () 25 5)
165 (dnf f-r2 "r2" () 20 5)
166 (dnf f-r3 "r3" () 15 5)
169 (df f-simm16 "signed imm (16)" () 15 16 INT #f #f)
170 (dnf f-uimm16 "unsigned imm (16)" () 15 16)
171 (dnf f-uimm5 "unsigned imm (5)" () 4 5)
172 (df f-hi16 "high 16" () 15 16 INT #f #f)
173 (df f-lo16 "low 16" () 15 16 INT #f #f)
176 (dnf f-op1 "op1" () 31 2)
177 (dnf f-op2 "op2" () 29 4)
178 (dnf f-op3 "op3" () 25 2)
179 (dnf f-op4 "op4" () 23 3)
180 (dnf f-op5 "op3" () 25 5)
181 (dnf f-op6 "op4" () 7 3)
182 (dnf f-op7 "op5" () 3 4)
184 (dnf f-i16-1 "uimm16-1" () 10 11)
185 (dnf f-i16-2 "uimm16-2" () 25 5)
187 ; PC relative, 26-bit (2 shifted to right)
188 (df f-disp26 "disp26" (PCREL-ADDR) 25 26 INT
189 ((value pc) (sra WI (sub WI value pc) (const 2)))
190 ((value pc) (add WI (sll WI value (const 2)) pc)))
192 ; absolute, 26-bit (2 shifted to right)
193 (df f-abs26 "abs26" (ABS-ADDR) 25 26 INT
194 ((value pc) (sra WI pc (const 2)))
195 ((value pc) (sll WI value (const 2))))
199 (comment "16 bit signed")
202 (subfields f-i16-1 f-i16-2)
204 (set (ifield f-i16-2) (and (sra (ifield f-i16nc)
207 (set (ifield f-i16-1) (and (ifield f-i16nc)
209 (extract (sequence ()
210 (set (ifield f-i16nc) (c-raw-call SI "@arch@_sign_extend_16bit"
211 (or (sll (ifield f-i16-2)
213 (ifield f-i16-1))))))
219 ; insn-class: bits 31-30
220 (define-normal-insn-enum insn-class "FIXME" () OP1_ f-class
221 (.map .str (.iota 4))
224 (define-normal-insn-enum insn-sub "FIXME" () OP2_ f-sub
225 (.map .str (.iota 16))
228 (define-normal-insn-enum insn-op3 "FIXME" () OP3_ f-op3
229 (.map .str (.iota 4))
232 (define-normal-insn-enum insn-op4 "FIXME" () OP4_ f-op4
233 (.map .str (.iota 8))
236 (define-normal-insn-enum insn-op5 "FIXME" () OP5_ f-op5
237 (.map .str (.iota 32))
240 (define-normal-insn-enum insn-op6 "FIXME" () OP6_ f-op6
241 (.map .str (.iota 8))
244 (define-normal-insn-enum insn-op7 "FIXME" () OP7_ f-op7
245 (.map .str (.iota 16))
251 ; These entries list the elements of the raw hardware.
252 ; They're also used to provide tables and other elements of the assembly
255 (dnh h-pc "program counter" (PC PROFILE) (pc) () () ())
258 (name h-gr) (comment "general registers") (attrs PROFILE)
259 (type register WI (32))
261 ((r0 0) (r1 1) (r2 2) (r3 3) (r4 4) (r5 5) (r6 6) (r7 7)
262 (r8 8) (r9 9) (r10 10) (r11 11) (r12 12) (r13 13) (r14 14)
263 (r15 15) (r16 16) (r17 17) (r18 18) (r19 19) (r20 20)
264 (r21 21) (r22 22) (r23 23) (r24 24) (r25 25) (r26 26)
265 (r27 27) (r28 28) (r29 29) (r30 30) (r31 31) (lr 11)
270 (name h-sr) (comment "special registers")
271 (type register WI (#x20000))
272 (get (index) (c-call SI "@arch@_h_sr_get_handler" index))
273 (set (index newval) (c-call VOID "@arch@_h_sr_set_handler" index newval))
276 (dnh h-hi16 "high 16 bits" () (immediate (INT 16)) () () ())
277 (dnh h-lo16 "low 16 bits" () (immediate (INT 16)) () () ())
279 (dsh h-cbit "condition bit" () (register BI))
280 (dsh h-delay-insn "delay insn addr" () (register SI))
283 ; Instruction operands.
285 (dnop sr "special register" (SEM-ONLY) h-sr f-nil)
286 (dnop cbit "condition bit" (SEM-ONLY) h-cbit f-nil)
287 (dnop simm-16 "16 bit signed immediate" () h-sint f-simm16)
288 (dnop uimm-16 "16 bit unsigned immediate" () h-uint f-uimm16)
289 (dnop disp-26 "pc-rel 26 bit" () h-iaddr f-disp26)
290 (dnop abs-26 "abs 26 bit" () h-iaddr f-abs26)
291 (dnop uimm-5 "imm5" () h-uint f-uimm5)
293 (dnop rD "destination register" () h-gr f-r1)
294 (dnop rA "source register A" () h-gr f-r2)
295 (dnop rB "source register B" () h-gr f-r3)
297 (dnop op-f-23 "f-op23" () h-uint f-op4)
298 (dnop op-f-3 "f-op3" () h-uint f-op5)
302 (name hi16) (comment "high 16 bit immediate, sign optional")
306 (handlers (parse "hi16"))
311 (name lo16) (comment "low 16 bit immediate, sign optional")
315 (handlers (parse "lo16"))
320 (comment "16 bit immediate, sign optional")
324 (handlers (parse "lo16"))
330 ; Branch releated instructions
332 (dni l-j "jump (absolute iaddr)"
333 ; This function may not be in delay slot
337 (+ OP1_0 OP2_0 abs-26)
339 ; We execute the delay slot before doin' the real branch
340 (delay 1 (set pc abs-26))
344 (dni l-jal "jump and link (absolute iaddr)"
345 ; This function may not be in delay slot
349 (+ OP1_0 OP2_1 abs-26)
351 ; We execute the delay slot before doin' the real branch
352 ; Set LR to (delay insn addr + 4)
354 (set (reg h-gr 11) (add (reg h-delay-insn) 4))
355 (delay 1 (set pc abs-26)))
359 (dni l-jr "jump register (absolute iaddr)"
360 ; This function may not be in delay slot
364 (+ OP1_0 OP2_5 OP3_0 OP4_0 rA uimm-16)
366 ; We execute the delay slot before doin' the real branch
367 (delay 1 (set pc rA))
371 (dni l-jalr "jump register and link (absolute iaddr)"
372 ; This function may not be in delay slot
376 (+ OP1_0 OP2_5 OP3_0 OP4_1 rA uimm-16)
378 ; We save the value of rA in a temporary slot before setting
379 ; the link register. This because "l.jalr r11" would cause
380 ; a forever-and-ever loop otherwise.
382 ; We execute the delay slot before doin' the real branch
383 (sequence ((WI tmp-slot))
385 (set (reg h-gr 11) (add (reg h-delay-insn) 4))
386 (delay 1 (set pc tmp-slot)))
390 (dni l-bal "branch and link (pc relative iaddr)"
391 ; This function may not be in delay slot
395 (+ OP1_0 OP2_2 disp-26)
397 ; We execute the delay slot before doin' the real branch
398 ; Set LR to (delay insn addr + 4)
400 (set (reg h-gr 11) (add (reg h-delay-insn) 4))
401 (delay 1 (set pc disp-26)))
405 (dni l-bnf "branch if condition bit not set (pc relative iaddr)"
406 ; This function may not be in delay slot
410 (+ OP1_0 OP2_3 disp-26)
412 ; We execute the delay slot before doin' the real branch
415 (delay 1 (set pc disp-26))))
419 (dni l-bf "branch if condition bit is set (pc relative iaddr)"
420 ; This function may not be in delay slot
424 (+ OP1_0 OP2_4 disp-26)
426 ; We execute the delay slot before doin' the real branch
429 (delay 1 (set pc disp-26))))
433 (dni l-brk "break (exception)"
434 ; This function may not be in delay slot
438 (+ OP1_0 OP2_5 OP3_3 OP4_0 rA uimm-16)
440 ; FIXME should we do it like this ??
441 (c-call VOID "@cpu@_cpu_brk" uimm-16)
445 (dni l-rfe "return from exception"
446 ; This function may not be in delay slot
450 (+ OP1_0 OP2_5 OP3_0 OP4_2 rA uimm-16)
452 (delay 1 (set pc (c-call SI "@cpu@_cpu_rfe" rA))))
456 (dni l-sys "syscall (exception)"
457 ; This function may not be in delay slot
461 (+ OP1_0 OP2_5 OP3_2 OP4_0 rA uimm-16)
463 (delay 1 (set pc (c-call SI "@cpu@_except" pc
474 (+ OP1_0 OP2_5 OP3_1 OP4_0 rA uimm-16)
481 (emit l-jr (rA 11) (uimm-16 0))
487 (+ OP1_0 OP2_6 hi16 rD rA)
488 (set rD (sll WI hi16 (const 16)))
493 ; System releated instructions
498 (+ OP1_0 OP2_7 rD rA uimm-16)
499 (set rD (c-call SI "@cpu@_cpu_mfsr" rA))
506 (+ OP1_1 OP2_0 rA rB rD (f-i16-1 0))
507 (c-call VOID "@cpu@_cpu_mtsr" rA rB)
515 (dni l-lw "load word"
517 "l.lw $rD,${simm-16}($rA)"
518 (+ OP1_2 OP2_0 rD rA simm-16)
519 (set rD (mem SI (add rA simm-16)))
523 (dni l-lbz "load byte (zero extend)"
525 "l.lbz $rD,${simm-16}($rA)"
526 (+ OP1_2 OP2_1 rD rA simm-16)
527 (set rD (zext SI (mem QI (add rA simm-16))))
531 (dni l-lbs "load byte (sign extend)"
533 "l.lbs $rD,${simm-16}($rA)"
534 (+ OP1_2 OP2_2 rD rA simm-16)
535 (set rD (ext SI (mem QI (add rA simm-16))))
539 (dni l-lhz "load halfword (zero extend)"
541 "l.lhz $rD,${simm-16}($rA)"
542 (+ OP1_2 OP2_3 rD simm-16 rA)
543 (set rD (zext SI (mem HI (add rA simm-16))))
547 (dni l-lhs "load halfword (sign extend)"
549 "l.lhs $rD,${simm-16}($rA)"
550 (+ OP1_2 OP2_4 rD rA simm-16)
551 (set rD (ext SI (mem HI (add rA simm-16))))
558 ; We have to use a multi field since the integer is splited over 2 fields
560 (define-pmacro (store-insn mnemonic op2-op mode-op)
562 (dni (.sym l- mnemonic)
563 (.str "l." mnemonic " imm(reg)/reg")
565 (.str "l." mnemonic " ${ui16nc}($rA),$rB")
566 (+ OP1_3 op2-op rB rD ui16nc)
567 (set (mem mode-op (add rA ui16nc)) rB)
573 (store-insn sw OP2_5 SI)
574 (store-insn sb OP2_6 QI)
575 (store-insn sh OP2_7 HI)
579 ; Shift and rotate instructions
582 (dnf f-f-15-8 "nop" (RESERVED) 15 8)
583 (dnf f-f-10-3 "nop" (RESERVED) 10 3)
584 (dnf f-f-4-1 "nop" (RESERVED) 4 1)
585 (dnf f-f-7-3 "nop" (RESERVED) 7 3)
587 (define-pmacro (shift-insn mnemonic op4-op)
589 (dni (.sym l- mnemonic)
590 (.str "l." mnemonic " reg/reg/reg")
592 (.str "l." mnemonic " $rD,$rA,$rB")
593 (+ OP1_3 OP2_8 rD rA rB (f-f-10-3 0) op4-op (f-f-4-1 0) OP7_8)
594 (set rD (mnemonic rA rB))
597 (dni (.sym l- mnemonic "i")
598 (.str "l." mnemonic " reg/reg/imm")
600 (.str "l." mnemonic "i $rD,$rA,${uimm-5}")
601 (+ OP1_2 OP2_13 rD rA (f-f-15-8 0) op4-op uimm-5)
602 (set rD (mnemonic rA uimm-5))
608 (shift-insn sll OP6_0)
609 (shift-insn srl OP6_1)
610 (shift-insn sra OP6_2)
611 (shift-insn ror OP6_4)
617 (dnf f-f-10-7 "nop" (RESERVED) 10 7)
619 (define-pmacro (ar-insn-u mnemonic op2-op op5-op)
621 (dni (.sym l- mnemonic)
622 (.str "l." mnemonic " reg/reg/reg")
624 (.str "l." mnemonic " $rD,$rA,$rB")
625 (+ OP1_3 OP2_8 rD rA rB (f-f-10-7 0) op5-op)
626 (set rD (mnemonic rA rB))
629 (dni (.sym l- mnemonic "i")
630 (.str "l." mnemonic " reg/reg/lo16")
632 (.str "l." mnemonic "i $rD,$rA,$lo16")
633 (+ OP1_2 op2-op rD rA lo16)
634 (set rD (mnemonic rA (and lo16 #xffff)))
640 (define-pmacro (ar-insn-s mnemonic op2-op op5-op)
642 (dni (.sym l- mnemonic)
643 (.str "l." mnemonic " reg/reg/reg")
645 (.str "l." mnemonic " $rD,$rA,$rB")
646 (+ OP1_3 OP2_8 rD rA rB (f-f-10-7 0) op5-op)
647 (set rD (mnemonic rA rB))
650 (dni (.sym l- mnemonic "i")
651 (.str "l." mnemonic " reg/reg/lo16")
653 (.str "l." mnemonic "i $rD,$rA,$lo16")
654 (+ OP1_2 op2-op rD rA lo16)
655 (set rD (mnemonic rA lo16))
661 (ar-insn-s add OP2_5 OP7_0)
662 ;;(ar-op-s addc OP2_5 OP7_0)
663 (ar-insn-s sub OP2_7 OP7_2)
664 (ar-insn-u and OP2_8 OP7_3)
665 (ar-insn-u or OP2_9 OP7_4)
666 (ar-insn-u xor OP2_10 OP7_5)
667 (ar-insn-u mul OP2_11 OP7_6)
668 ;;(ar-op-u mac OP2_12 OP7_7)
671 (dni l-div "divide (signed)"
674 (+ OP1_3 OP2_8 rD rA rB (f-f-10-7 0) OP7_9)
675 (if VOID (eq rB (const 0))
676 (c-call VOID "@arch@_cpu_trap" pc (enum SI E_ILLEGAL))
677 (set rD (div rA rB)))
681 (dni l-divu "divide (unsigned)"
684 (+ OP1_3 OP2_8 rD rA rB (f-f-10-7 0) OP7_10)
685 (if VOID (eq rB (const 0))
686 (c-call VOID "@arch@_cpu_trap" pc (enum SI E_ILLEGAL))
687 (set rD (udiv rA rB)))
692 ; Compare instructions
695 (dnf f-f-10-11 "nop" (RESERVED) 10 11)
697 ; Register compare (both signed and unsigned)
698 (define-pmacro (sf-insn-r op1-op op2-op op3-op op3-op-2 sem-op)
700 (dni (.sym l- "sf" (.sym sem-op "s"))
701 (.str "l." mnemonic " reg/reg")
703 (.str "l.sf" (.str sem-op) "s $rA,$rB")
704 (+ op1-op op2-op op3-op-2 rA rB (f-f-10-11 0))
705 (set cbit (sem-op rA rB))
708 (dni (.sym l- "sf" (.sym sem-op "u"))
709 (.str "l." mnemonic " reg/reg")
711 (.str "l.sf" (.str sem-op) "u $rA,$rB")
712 (+ op1-op op2-op op3-op rA rB (f-f-10-11 0))
713 (set cbit (sem-op rA rB))
719 ; Immediate compare (both signed and unsigned)
720 (define-pmacro (sf-insn-i op1-op op2-op op3-op op3-op-2 sem-op)
722 (dni (.sym l- "sf" (.sym sem-op "si"))
723 (.str "l." mnemonic "si reg/imm")
725 (.str "l.sf" (.str sem-op) "si $rA,${simm-16}")
726 (+ op1-op op2-op op3-op-2 rA simm-16)
727 (set cbit (sem-op rA simm-16))
730 (dni (.sym l- "sf" (.sym sem-op "ui"))
731 (.str "l." mnemonic "ui reg/imm")
733 (.str "l.sf" (.str sem-op) "ui $rA,${uimm-16}")
734 (+ op1-op op2-op op3-op rA uimm-16)
735 (set cbit (sem-op rA uimm-16))
741 (define-pmacro (sf-insn op5-op sem-op)
743 (dni (.sym l- "sf" sem-op)
744 (.str "l." mnemonic " reg/reg")
746 (.str "l.sf" (.str sem-op) " $rA,$rB")
747 (+ OP1_3 OP2_9 op5-op rA rB (f-f-10-11 0))
748 (set cbit (sem-op rA rB))
751 (dni (.sym l- "sf" (.sym sem-op "i"))
752 (.str "l." mnemonic "i reg/imm")
754 (.str "l.sf" (.str sem-op) "i $rA,${simm-16}")
755 (+ OP1_2 OP2_14 op5-op rA simm-16)
756 (set cbit (sem-op rA simm-16))
763 (sf-insn-r OP1_3 OP2_9 OP5_2 OP5_6 gt)
764 (sf-insn-r OP1_3 OP2_9 OP5_3 OP5_7 ge)
765 (sf-insn-r OP1_3 OP2_9 OP5_4 OP5_8 lt)
766 (sf-insn-r OP1_3 OP2_9 OP5_5 OP5_9 le)
768 (sf-insn-i OP1_2 OP2_14 OP5_2 OP5_6 gt)
769 (sf-insn-i OP1_2 OP2_14 OP5_3 OP5_7 ge)
770 (sf-insn-i OP1_2 OP2_14 OP5_4 OP5_8 lt)
771 (sf-insn-i OP1_2 OP2_14 OP5_5 OP5_9 le)