1 ; Hitachi SH architecture description. -*- Scheme -*-
3 ; Copyright 2000, 2001, 2007, 2009 Free Software Foundation, Inc.
5 ; Contributed by Red Hat Inc; developed under contract from Hitachi
6 ; Semiconductor (America) Inc.
8 ; This file is part of the GNU Binutils.
10 ; This program is free software; you can redistribute it and/or modify
11 ; it under the terms of the GNU General Public License as published by
12 ; the Free Software Foundation; either version 3 of the License, or
13 ; (at your option) any later version.
15 ; This program is distributed in the hope that it will be useful,
16 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ; GNU General Public License for more details.
20 ; You should have received a copy of the GNU General Public License
21 ; along with this program; if not, write to the Free Software
22 ; Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
26 (include "simplify.inc")
30 (comment "Hitachi SuperH (SH)")
32 (machs sh2 sh3 sh3e sh4 sh5)
41 (comment "SHmedia 32-bit instruction set")
42 (base-insn-bitsize 32)
47 (comment "SHcompact 16-bit instruction set")
48 (base-insn-bitsize 16)
56 (comment "SH 64-bit family")
64 (comment "SH-2 CPU core")
71 (comment "SH-3 CPU core")
78 (comment "SH-3e CPU core")
85 (comment "SH-4 CPU core")
92 (comment "SH-5 CPU core")
99 (comment "SH-5 reference implementation")
101 (unit u-exec "Execution unit" ()
110 (comment "Program counter")
111 (attrs PC (ISA compact,media))
113 (get () (raw-reg h-pc))
114 (set (newval) (sequence ()
115 (set (raw-reg h-ism) (and newval 1))
116 (set (raw-reg h-pc) (and newval (inv UDI 1)))))
119 (define-pmacro (-build-greg-name n) ((.sym r n) n))
123 (comment "General purpose integer registers")
124 (attrs (ISA media,compact))
125 (type register DI (64))
126 (indices keyword "" (.map -build-greg-name (.iota 64)))
130 (raw-reg h-gr index)))
133 (set (raw-reg h-gr index) newval)
139 (comment "General purpose integer registers (SHcompact view)")
140 (attrs VIRTUAL (ISA compact))
141 (type register SI (16))
142 (indices keyword "" (.map -build-greg-name (.iota 16)))
144 (and (raw-reg h-gr index) (zext DI #xFFFFFFFF)))
146 (set (raw-reg h-gr index) (ext DI newval)))
149 (define-pmacro (-build-creg-name n) ((.sym cr n) n))
153 (comment "Control registers")
155 (type register DI (64))
156 (indices keyword "" (.map -build-creg-name (.iota 64)))
160 (raw-reg h-cr index)))
163 (set (reg h-sr) newval)
164 (set (raw-reg h-cr index) newval)))
169 (comment "Status register")
170 (attrs (ISA compact,media))
176 (comment "Floating point status and control register")
177 (attrs (ISA compact,media))
183 (comment "Floating point register file bit")
184 (attrs (ISA media,compact) VIRTUAL)
186 (get () (and (srl (reg h-sr) 14) 1))
187 (set (newvalue) (set (reg h-sr) (or (and (reg h-sr) (inv (sll 1 14))) (sll SI newvalue 14))))
192 (comment "Floating point transfer size bit")
193 (attrs (ISA media,compact) VIRTUAL)
195 (get () (and (srl (reg h-sr) 13) 1))
196 (set (newvalue) (set (reg h-sr) (or (and (reg h-sr) (inv (sll 1 13))) (sll SI newvalue 13))))
201 (comment "Floating point precision bit")
202 (attrs (ISA media,compact) VIRTUAL)
204 (get () (and (srl (reg h-sr) 12) 1))
205 (set (newvalue) (set (reg h-sr) (or (and (reg h-sr) (inv (sll 1 12))) (sll SI newvalue 12))))
210 (comment "Multiply-accumulate saturation flag")
211 (attrs (ISA compact) VIRTUAL)
213 (get () (and (srl (reg h-sr) 1) 1))
214 (set (newvalue) (set (reg h-sr) (or (and (reg h-sr) (inv 2)) (sll SI newvalue 1))))
219 (comment "Divide-step M flag")
220 (attrs (ISA compact) VIRTUAL)
222 (get () (and (srl (reg h-sr) 9) 1))
223 (set (newvalue) (set (reg h-sr) (or (and (reg h-sr) (inv (sll 1 9))) (sll SI newvalue 9))))
228 (comment "Divide-step Q flag")
229 (attrs (ISA compact) VIRTUAL)
231 (get () (and (srl (reg h-sr) 8) 1))
232 (set (newvalue) (set (reg h-sr) (or (and (reg h-sr) (inv (sll 1 8))) (sll SI newvalue 8))))
235 (define-pmacro (-build-freg-name n) ((.sym fr n) n))
239 (comment "Single precision floating point registers")
240 (attrs (ISA media,compact))
241 (type register SF (64))
242 (indices keyword "" (.map -build-freg-name (.iota 64)))
246 (define-pmacro (-build-fpair-name n) ((.sym fp n) n))
250 (comment "Single precision floating point register pairs")
251 (attrs (ISA media,compact))
252 (type register DF (32))
253 (indices keyword "" (.map -build-fpair-name (.iota 32)))
256 (define-pmacro (-build-fvec-name n) ((.sym fv n) n))
260 (comment "Single precision floating point vectors")
261 (attrs VIRTUAL (ISA media,compact))
262 (type register SF (16))
263 (indices keyword "" (.map -build-fvec-name (.iota 16)))
264 ; Mask with $F to ensure 0 <= index < 15.
265 (get (index) (reg h-fr (mul (and UQI index 15) 4)))
266 (set (index newval) (set (reg h-fr (mul (and UQI index 15) 4)) newval))
271 (comment "Single precision floating point matrices")
272 (attrs VIRTUAL (ISA media))
273 (type register SF (4))
274 (indices keyword "" ((mtrx0 0) (mtrx1 1) (mtrx2 2) (mtrx3 3)))
275 ; Mask with $3 to ensure 0 <= index < 4.
276 (get (index) (reg h-fr (mul (and UQI index 3) 16)))
277 (set (index newval) (set (reg h-fr (mul (and UQI index 3) 16)) newval))
280 (define-pmacro (-build-dreg-name n) ((.sym dr n) n))
284 (comment "Double precision floating point registers")
285 (attrs (ISA media,compact) VIRTUAL)
286 (type register DF (32))
287 (indices keyword "" (.map -build-dreg-name (.iota 64)))
291 (sll DI (zext DI (subword SI (reg h-fr index) 0)) 32)
292 (zext DI (subword SI (reg h-fr (add index 1)) 0))) 0))
295 (set (reg h-fr index)
296 (subword SF (subword SI newval 0) 0))
297 (set (reg h-fr (add index 1))
298 (subword SF (subword SI newval 1) 0))))
303 (comment "Branch target registers")
305 (type register DI (8))
306 (indices keyword "" ((tr0 0) (tr1 1) (tr2 2) (tr3 3) (tr4 4) (tr5 5) (tr6 6) (tr7 7)))
311 (comment "Current endian mode")
312 (attrs (ISA compact,media) VIRTUAL)
314 (get () (c-call BI "sh64_endian"))
315 (set (newval) (error "cannot alter target byte order mid-program"))
320 (comment "Current instruction set mode")
321 (attrs (ISA compact,media))
323 (get () (raw-reg h-ism))
324 (set (newval) (error "cannot set ism directly"))
330 (dnop endian "Endian mode" ((ISA compact,media)) h-endian f-nil)
331 (dnop ism "Instruction set mode" ((ISA compact,media)) h-ism f-nil)
333 ; Universally useful macros.
335 ; A pmacro for use in semantic bodies of unimplemented insns.
336 (define-pmacro (unimp mnemonic) (nop))
338 ; Join 2 ints together in natural bit order.
339 (define-pmacro (-join-si s1 s0)
340 (or (sll (zext DI s1) 32)
343 ; Join 4 half-ints together in natural bit order.
344 (define-pmacro (-join-hi h3 h2 h1 h0)
345 (or (sll (zext DI h3) 48)
346 (or (sll (zext DI h2) 32)
347 (or (sll (zext DI h1) 16)
350 ; Join 8 quarter-ints together in natural bit order.
351 (define-pmacro (-join-qi b7 b6 b5 b4 b3 b2 b1 b0)
352 (or (sll (zext DI b7) 56)
353 (or (sll (zext DI b6) 48)
354 (or (sll (zext DI b5) 40)
355 (or (sll (zext DI b4) 32)
356 (or (sll (zext DI b3) 24)
357 (or (sll (zext DI b2) 16)
358 (or (sll (zext DI b1) 8)
362 ; Include the two instruction set descriptions from their respective
365 (if (keep-isa? (compact))
366 (include "sh64-compact.cpu"))
368 (if (keep-isa? (media))
369 (include "sh64-media.cpu"))