sh.cpu 9.0 KB

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