1 ; Hitachi SH architecture description. -*- Scheme -*- 2 ; 3 ; Copyright 2000, 2001, 2007, 2009 Free Software Foundation, Inc. 4 ; 5 ; Contributed by Red Hat Inc; developed under contract from Hitachi 6 ; Semiconductor (America) Inc. 7 ; 8 ; This file is part of the GNU Binutils. 9 ; 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. 14 ; 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. 19 ; 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, 23 ; MA 02110-1301, USA. 24 25 26 (include "simplify.inc") 27 28 (define-arch 29 (name sh) 30 (comment "Hitachi SuperH (SH)") 31 (insn-lsb0? #t) 32 (machs sh2 sh3 sh3e sh4 sh5) 33 (isas compact media) 34 ) 35 36 38 ; Instruction sets. 39 40 (define-isa 41 (name media) 42 (comment "SHmedia 32-bit instruction set") 43 (base-insn-bitsize 32) 44 ) 45 46 (define-isa 47 (name compact) 48 (comment "SHcompact 16-bit instruction set") 49 (base-insn-bitsize 16) 50 ) 51 52 54 ; CPU family. 55 56 (define-cpu 57 (name sh64) 58 (comment "SH 64-bit family") 59 (endian either) 60 (word-bitsize 32) 61 ) 62 64 65 (define-mach 66 (name sh2) 67 (comment "SH-2 CPU core") 68 (cpu sh64) 69 (isas compact) 70 ) 71 72 (define-mach 73 (name sh3) 74 (comment "SH-3 CPU core") 75 (cpu sh64) 76 (isas compact) 77 ) 78 79 (define-mach 80 (name sh3e) 81 (comment "SH-3e CPU core") 82 (cpu sh64) 83 (isas compact) 84 ) 85 86 (define-mach 87 (name sh4) 88 (comment "SH-4 CPU core") 89 (cpu sh64) 90 (isas compact) 91 ) 92 93 (define-mach 94 (name sh5) 95 (comment "SH-5 CPU core") 96 (cpu sh64) 97 (isas compact media) 98 ) 99 100 (define-model 101 (name sh5) 102 (comment "SH-5 reference implementation") 103 (mach sh5) 104 (unit u-exec "Execution unit" () 105 1 1 ; issue done 106 () () () ()) 107 ) 108 110 ; Hardware elements. 111 112 (define-hardware 113 (name h-pc) 114 (comment "Program counter") 115 (attrs PC (ISA compact,media)) 116 (type pc UDI) 117 (get () (raw-reg h-pc)) 118 (set (newval) (sequence () 119 (set (raw-reg h-ism) (and newval 1)) 120 (set (raw-reg h-pc) (and newval (inv UDI 1))))) 121 ) 122 123 (define-pmacro (-build-greg-name n) ((.sym r n) n)) 124 125 (define-hardware 126 (name h-gr) 127 (comment "General purpose integer registers") 128 (attrs (ISA media,compact)) 129 (type register DI (64)) 130 (indices keyword "" (.map -build-greg-name (.iota 64))) 131 (get (index) 132 (if DI (eq index 63) 133 (const 0) 134 (raw-reg h-gr index))) 135 (set (index newval) 136 (if (ne index 63) 137 (set (raw-reg h-gr index) newval) 138 (nop))) 139 ) 140 141 (define-hardware 142 (name h-grc) 143 (comment "General purpose integer registers (SHcompact view)") 144 (attrs VIRTUAL (ISA compact)) 145 (type register SI (16)) 146 (indices keyword "" (.map -build-greg-name (.iota 16))) 147 (get (index) 148 (and (raw-reg h-gr index) (zext DI #xFFFFFFFF))) 149 (set (index newval) 150 (set (raw-reg h-gr index) (ext DI newval))) 151 ) 152 153 (define-pmacro (-build-creg-name n) ((.sym cr n) n)) 154 155 (define-hardware 156 (name h-cr) 157 (comment "Control registers") 158 (attrs (ISA media)) 159 (type register DI (64)) 160 (indices keyword "" (.map -build-creg-name (.iota 64))) 161 (get (index) 162 (if DI (eq index 0) 163 (zext DI (reg h-sr)) 164 (raw-reg h-cr index))) 165 (set (index newval) 166 (if (eq index 0) 167 (set (reg h-sr) newval) 168 (set (raw-reg h-cr index) newval))) 169 ) 170 171 (define-hardware 172 (name h-sr) 173 (comment "Status register") 174 (attrs (ISA compact,media)) 175 (type register SI) 176 ) 177 178 (define-hardware 179 (name h-fpscr) 180 (comment "Floating point status and control register") 181 (attrs (ISA compact,media)) 182 (type register SI) 183 ) 184 185 (define-hardware 186 (name h-frbit) 187 (comment "Floating point register file bit") 188 (attrs (ISA media,compact) VIRTUAL) 189 (type register BI) 190 (get () (and (srl (reg h-sr) 14) 1)) 191 (set (newvalue) (set (reg h-sr) (or (and (reg h-sr) (inv (sll 1 14))) (sll SI newvalue 14)))) 192 ) 193 194 (define-hardware 195 (name h-szbit) 196 (comment "Floating point transfer size bit") 197 (attrs (ISA media,compact) VIRTUAL) 198 (type register BI) 199 (get () (and (srl (reg h-sr) 13) 1)) 200 (set (newvalue) (set (reg h-sr) (or (and (reg h-sr) (inv (sll 1 13))) (sll SI newvalue 13)))) 201 ) 202 203 (define-hardware 204 (name h-prbit) 205 (comment "Floating point precision bit") 206 (attrs (ISA media,compact) VIRTUAL) 207 (type register BI) 208 (get () (and (srl (reg h-sr) 12) 1)) 209 (set (newvalue) (set (reg h-sr) (or (and (reg h-sr) (inv (sll 1 12))) (sll SI newvalue 12)))) 210 ) 211 212 (define-hardware 213 (name h-sbit) 214 (comment "Multiply-accumulate saturation flag") 215 (attrs (ISA compact) VIRTUAL) 216 (type register BI) 217 (get () (and (srl (reg h-sr) 1) 1)) 218 (set (newvalue) (set (reg h-sr) (or (and (reg h-sr) (inv 2)) (sll SI newvalue 1)))) 219 ) 220 221 (define-hardware 222 (name h-mbit) 223 (comment "Divide-step M flag") 224 (attrs (ISA compact) VIRTUAL) 225 (type register BI) 226 (get () (and (srl (reg h-sr) 9) 1)) 227 (set (newvalue) (set (reg h-sr) (or (and (reg h-sr) (inv (sll 1 9))) (sll SI newvalue 9)))) 228 ) 229 230 (define-hardware 231 (name h-qbit) 232 (comment "Divide-step Q flag") 233 (attrs (ISA compact) VIRTUAL) 234 (type register BI) 235 (get () (and (srl (reg h-sr) 8) 1)) 236 (set (newvalue) (set (reg h-sr) (or (and (reg h-sr) (inv (sll 1 8))) (sll SI newvalue 8)))) 237 ) 238 239 (define-pmacro (-build-freg-name n) ((.sym fr n) n)) 240 241 (define-hardware 242 (name h-fr) 243 (comment "Single precision floating point registers") 244 (attrs (ISA media,compact)) 245 (type register SF (64)) 246 (indices keyword "" (.map -build-freg-name (.iota 64))) 247 ) 248 249 250 (define-pmacro (-build-fpair-name n) ((.sym fp n) n)) 251 252 (define-hardware 253 (name h-fp) 254 (comment "Single precision floating point register pairs") 255 (attrs (ISA media,compact)) 256 (type register DF (32)) 257 (indices keyword "" (.map -build-fpair-name (.iota 32))) 258 ) 259 260 (define-pmacro (-build-fvec-name n) ((.sym fv n) n)) 261 262 (define-hardware 263 (name h-fv) 264 (comment "Single precision floating point vectors") 265 (attrs VIRTUAL (ISA media,compact)) 266 (type register SF (16)) 267 (indices keyword "" (.map -build-fvec-name (.iota 16))) 268 ; Mask with $F to ensure 0 <= index < 15. 269 (get (index) (reg h-fr (mul (and UQI index 15) 4))) 270 (set (index newval) (set (reg h-fr (mul (and UQI index 15) 4)) newval)) 271 ) 272 273 (define-hardware 274 (name h-fmtx) 275 (comment "Single precision floating point matrices") 276 (attrs VIRTUAL (ISA media)) 277 (type register SF (4)) 278 (indices keyword "" ((mtrx0 0) (mtrx1 1) (mtrx2 2) (mtrx3 3))) 279 ; Mask with $3 to ensure 0 <= index < 4. 280 (get (index) (reg h-fr (mul (and UQI index 3) 16))) 281 (set (index newval) (set (reg h-fr (mul (and UQI index 3) 16)) newval)) 282 ) 283 284 (define-pmacro (-build-dreg-name n) ((.sym dr n) n)) 285 286 (define-hardware 287 (name h-dr) 288 (comment "Double precision floating point registers") 289 (attrs (ISA media,compact) VIRTUAL) 290 (type register DF (32)) 291 (indices keyword "" (.map -build-dreg-name (.iota 64))) 292 (get (index) 293 (subword DF 294 (or 295 (sll DI (zext DI (subword SI (reg h-fr index) 0)) 32) 296 (zext DI (subword SI (reg h-fr (add index 1)) 0))) 0)) 297 (set (index newval) 298 (sequence () 299 (set (reg h-fr index) 300 (subword SF (subword SI newval 0) 0)) 301 (set (reg h-fr (add index 1)) 302 (subword SF (subword SI newval 1) 0)))) 303 ) 304 305 (define-hardware 306 (name h-tr) 307 (comment "Branch target registers") 308 (attrs (ISA media)) 309 (type register DI (8)) 310 (indices keyword "" ((tr0 0) (tr1 1) (tr2 2) (tr3 3) (tr4 4) (tr5 5) (tr6 6) (tr7 7))) 311 ) 312 313 (define-hardware 314 (name h-endian) 315 (comment "Current endian mode") 316 (attrs (ISA compact,media) VIRTUAL) 317 (type register BI) 318 (get () (c-call BI "sh64_endian")) 319 (set (newval) (error "cannot alter target byte order mid-program")) 320 ) 321 322 (define-hardware 323 (name h-ism) 324 (comment "Current instruction set mode") 325 (attrs (ISA compact,media)) 326 (type register BI) 327 (get () (raw-reg h-ism)) 328 (set (newval) (error "cannot set ism directly")) 329 ) 330 331 333 ; Operands. 334 335 (dnop endian "Endian mode" ((ISA compact,media)) h-endian f-nil) 336 (dnop ism "Instruction set mode" ((ISA compact,media)) h-ism f-nil) 337 338 ; Universally useful macros. 339 340 ; A pmacro for use in semantic bodies of unimplemented insns. 341 (define-pmacro (unimp mnemonic) (nop)) 342 343 ; Join 2 ints together in natural bit order. 344 (define-pmacro (-join-si s1 s0) 345 (or (sll (zext DI s1) 32) 346 (zext DI s0))) 347 348 ; Join 4 half-ints together in natural bit order. 349 (define-pmacro (-join-hi h3 h2 h1 h0) 350 (or (sll (zext DI h3) 48) 351 (or (sll (zext DI h2) 32) 352 (or (sll (zext DI h1) 16) 353 (zext DI h0))))) 354 355 ; Join 8 quarter-ints together in natural bit order. 356 (define-pmacro (-join-qi b7 b6 b5 b4 b3 b2 b1 b0) 357 (or (sll (zext DI b7) 56) 358 (or (sll (zext DI b6) 48) 359 (or (sll (zext DI b5) 40) 360 (or (sll (zext DI b4) 32) 361 (or (sll (zext DI b3) 24) 362 (or (sll (zext DI b2) 16) 363 (or (sll (zext DI b1) 8) 364 (zext DI b0))))))))) 365 366 368 ; Include the two instruction set descriptions from their respective 369 ; source files. 370 371 (if (keep-isa? (compact)) 372 (include "sh64-compact.cpu")) 373 374 (if (keep-isa? (media)) 375 (include "sh64-media.cpu")) 376