lm32-desc.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  1. /* DO NOT EDIT! -*- buffer-read-only: t -*- vi:set ro: */
  2. /* CPU data for lm32.
  3. THIS FILE IS MACHINE GENERATED WITH CGEN.
  4. Copyright (C) 1996-2022 Free Software Foundation, Inc.
  5. This file is part of the GNU Binutils and/or GDB, the GNU debugger.
  6. This file is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3, or (at your option)
  9. any later version.
  10. It is distributed in the hope that it will be useful, but WITHOUT
  11. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  13. License for more details.
  14. You should have received a copy of the GNU General Public License along
  15. with this program; if not, write to the Free Software Foundation, Inc.,
  16. 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
  17. */
  18. #include "sysdep.h"
  19. #include <stdio.h>
  20. #include <stdarg.h>
  21. #include <stdlib.h>
  22. #include "ansidecl.h"
  23. #include "bfd.h"
  24. #include "symcat.h"
  25. #include "lm32-desc.h"
  26. #include "lm32-opc.h"
  27. #include "opintl.h"
  28. #include "libiberty.h"
  29. #include "xregex.h"
  30. /* Attributes. */
  31. static const CGEN_ATTR_ENTRY bool_attr[] =
  32. {
  33. { "#f", 0 },
  34. { "#t", 1 },
  35. { 0, 0 }
  36. };
  37. static const CGEN_ATTR_ENTRY MACH_attr[] ATTRIBUTE_UNUSED =
  38. {
  39. { "base", MACH_BASE },
  40. { "lm32", MACH_LM32 },
  41. { "max", MACH_MAX },
  42. { 0, 0 }
  43. };
  44. static const CGEN_ATTR_ENTRY ISA_attr[] ATTRIBUTE_UNUSED =
  45. {
  46. { "lm32", ISA_LM32 },
  47. { "max", ISA_MAX },
  48. { 0, 0 }
  49. };
  50. const CGEN_ATTR_TABLE lm32_cgen_ifield_attr_table[] =
  51. {
  52. { "MACH", & MACH_attr[0], & MACH_attr[0] },
  53. { "VIRTUAL", &bool_attr[0], &bool_attr[0] },
  54. { "PCREL-ADDR", &bool_attr[0], &bool_attr[0] },
  55. { "ABS-ADDR", &bool_attr[0], &bool_attr[0] },
  56. { "RESERVED", &bool_attr[0], &bool_attr[0] },
  57. { "SIGN-OPT", &bool_attr[0], &bool_attr[0] },
  58. { "SIGNED", &bool_attr[0], &bool_attr[0] },
  59. { 0, 0, 0 }
  60. };
  61. const CGEN_ATTR_TABLE lm32_cgen_hardware_attr_table[] =
  62. {
  63. { "MACH", & MACH_attr[0], & MACH_attr[0] },
  64. { "VIRTUAL", &bool_attr[0], &bool_attr[0] },
  65. { "CACHE-ADDR", &bool_attr[0], &bool_attr[0] },
  66. { "PC", &bool_attr[0], &bool_attr[0] },
  67. { "PROFILE", &bool_attr[0], &bool_attr[0] },
  68. { 0, 0, 0 }
  69. };
  70. const CGEN_ATTR_TABLE lm32_cgen_operand_attr_table[] =
  71. {
  72. { "MACH", & MACH_attr[0], & MACH_attr[0] },
  73. { "VIRTUAL", &bool_attr[0], &bool_attr[0] },
  74. { "PCREL-ADDR", &bool_attr[0], &bool_attr[0] },
  75. { "ABS-ADDR", &bool_attr[0], &bool_attr[0] },
  76. { "SIGN-OPT", &bool_attr[0], &bool_attr[0] },
  77. { "SIGNED", &bool_attr[0], &bool_attr[0] },
  78. { "NEGATIVE", &bool_attr[0], &bool_attr[0] },
  79. { "RELAX", &bool_attr[0], &bool_attr[0] },
  80. { "SEM-ONLY", &bool_attr[0], &bool_attr[0] },
  81. { 0, 0, 0 }
  82. };
  83. const CGEN_ATTR_TABLE lm32_cgen_insn_attr_table[] =
  84. {
  85. { "MACH", & MACH_attr[0], & MACH_attr[0] },
  86. { "ALIAS", &bool_attr[0], &bool_attr[0] },
  87. { "VIRTUAL", &bool_attr[0], &bool_attr[0] },
  88. { "UNCOND-CTI", &bool_attr[0], &bool_attr[0] },
  89. { "COND-CTI", &bool_attr[0], &bool_attr[0] },
  90. { "SKIP-CTI", &bool_attr[0], &bool_attr[0] },
  91. { "DELAY-SLOT", &bool_attr[0], &bool_attr[0] },
  92. { "RELAXABLE", &bool_attr[0], &bool_attr[0] },
  93. { "RELAXED", &bool_attr[0], &bool_attr[0] },
  94. { "NO-DIS", &bool_attr[0], &bool_attr[0] },
  95. { "PBB", &bool_attr[0], &bool_attr[0] },
  96. { 0, 0, 0 }
  97. };
  98. /* Instruction set variants. */
  99. static const CGEN_ISA lm32_cgen_isa_table[] = {
  100. { "lm32", 32, 32, 32, 32 },
  101. { 0, 0, 0, 0, 0 }
  102. };
  103. /* Machine variants. */
  104. static const CGEN_MACH lm32_cgen_mach_table[] = {
  105. { "lm32", "lm32", MACH_LM32, 0 },
  106. { 0, 0, 0, 0 }
  107. };
  108. static CGEN_KEYWORD_ENTRY lm32_cgen_opval_h_gr_entries[] =
  109. {
  110. { "gp", 26, {0, {{{0, 0}}}}, 0, 0 },
  111. { "fp", 27, {0, {{{0, 0}}}}, 0, 0 },
  112. { "sp", 28, {0, {{{0, 0}}}}, 0, 0 },
  113. { "ra", 29, {0, {{{0, 0}}}}, 0, 0 },
  114. { "ea", 30, {0, {{{0, 0}}}}, 0, 0 },
  115. { "ba", 31, {0, {{{0, 0}}}}, 0, 0 },
  116. { "r0", 0, {0, {{{0, 0}}}}, 0, 0 },
  117. { "r1", 1, {0, {{{0, 0}}}}, 0, 0 },
  118. { "r2", 2, {0, {{{0, 0}}}}, 0, 0 },
  119. { "r3", 3, {0, {{{0, 0}}}}, 0, 0 },
  120. { "r4", 4, {0, {{{0, 0}}}}, 0, 0 },
  121. { "r5", 5, {0, {{{0, 0}}}}, 0, 0 },
  122. { "r6", 6, {0, {{{0, 0}}}}, 0, 0 },
  123. { "r7", 7, {0, {{{0, 0}}}}, 0, 0 },
  124. { "r8", 8, {0, {{{0, 0}}}}, 0, 0 },
  125. { "r9", 9, {0, {{{0, 0}}}}, 0, 0 },
  126. { "r10", 10, {0, {{{0, 0}}}}, 0, 0 },
  127. { "r11", 11, {0, {{{0, 0}}}}, 0, 0 },
  128. { "r12", 12, {0, {{{0, 0}}}}, 0, 0 },
  129. { "r13", 13, {0, {{{0, 0}}}}, 0, 0 },
  130. { "r14", 14, {0, {{{0, 0}}}}, 0, 0 },
  131. { "r15", 15, {0, {{{0, 0}}}}, 0, 0 },
  132. { "r16", 16, {0, {{{0, 0}}}}, 0, 0 },
  133. { "r17", 17, {0, {{{0, 0}}}}, 0, 0 },
  134. { "r18", 18, {0, {{{0, 0}}}}, 0, 0 },
  135. { "r19", 19, {0, {{{0, 0}}}}, 0, 0 },
  136. { "r20", 20, {0, {{{0, 0}}}}, 0, 0 },
  137. { "r21", 21, {0, {{{0, 0}}}}, 0, 0 },
  138. { "r22", 22, {0, {{{0, 0}}}}, 0, 0 },
  139. { "r23", 23, {0, {{{0, 0}}}}, 0, 0 },
  140. { "r24", 24, {0, {{{0, 0}}}}, 0, 0 },
  141. { "r25", 25, {0, {{{0, 0}}}}, 0, 0 },
  142. { "r26", 26, {0, {{{0, 0}}}}, 0, 0 },
  143. { "r27", 27, {0, {{{0, 0}}}}, 0, 0 },
  144. { "r28", 28, {0, {{{0, 0}}}}, 0, 0 },
  145. { "r29", 29, {0, {{{0, 0}}}}, 0, 0 },
  146. { "r30", 30, {0, {{{0, 0}}}}, 0, 0 },
  147. { "r31", 31, {0, {{{0, 0}}}}, 0, 0 }
  148. };
  149. CGEN_KEYWORD lm32_cgen_opval_h_gr =
  150. {
  151. & lm32_cgen_opval_h_gr_entries[0],
  152. 38,
  153. 0, 0, 0, 0, ""
  154. };
  155. static CGEN_KEYWORD_ENTRY lm32_cgen_opval_h_csr_entries[] =
  156. {
  157. { "IE", 0, {0, {{{0, 0}}}}, 0, 0 },
  158. { "IM", 1, {0, {{{0, 0}}}}, 0, 0 },
  159. { "IP", 2, {0, {{{0, 0}}}}, 0, 0 },
  160. { "ICC", 3, {0, {{{0, 0}}}}, 0, 0 },
  161. { "DCC", 4, {0, {{{0, 0}}}}, 0, 0 },
  162. { "CC", 5, {0, {{{0, 0}}}}, 0, 0 },
  163. { "CFG", 6, {0, {{{0, 0}}}}, 0, 0 },
  164. { "EBA", 7, {0, {{{0, 0}}}}, 0, 0 },
  165. { "DC", 8, {0, {{{0, 0}}}}, 0, 0 },
  166. { "DEBA", 9, {0, {{{0, 0}}}}, 0, 0 },
  167. { "CFG2", 10, {0, {{{0, 0}}}}, 0, 0 },
  168. { "JTX", 14, {0, {{{0, 0}}}}, 0, 0 },
  169. { "JRX", 15, {0, {{{0, 0}}}}, 0, 0 },
  170. { "BP0", 16, {0, {{{0, 0}}}}, 0, 0 },
  171. { "BP1", 17, {0, {{{0, 0}}}}, 0, 0 },
  172. { "BP2", 18, {0, {{{0, 0}}}}, 0, 0 },
  173. { "BP3", 19, {0, {{{0, 0}}}}, 0, 0 },
  174. { "WP0", 24, {0, {{{0, 0}}}}, 0, 0 },
  175. { "WP1", 25, {0, {{{0, 0}}}}, 0, 0 },
  176. { "WP2", 26, {0, {{{0, 0}}}}, 0, 0 },
  177. { "WP3", 27, {0, {{{0, 0}}}}, 0, 0 },
  178. { "PSW", 29, {0, {{{0, 0}}}}, 0, 0 },
  179. { "TLBVADDR", 30, {0, {{{0, 0}}}}, 0, 0 },
  180. { "TLBPADDR", 31, {0, {{{0, 0}}}}, 0, 0 },
  181. { "TLBBADVADDR", 31, {0, {{{0, 0}}}}, 0, 0 }
  182. };
  183. CGEN_KEYWORD lm32_cgen_opval_h_csr =
  184. {
  185. & lm32_cgen_opval_h_csr_entries[0],
  186. 25,
  187. 0, 0, 0, 0, ""
  188. };
  189. /* The hardware table. */
  190. #define A(a) (1 << CGEN_HW_##a)
  191. const CGEN_HW_ENTRY lm32_cgen_hw_table[] =
  192. {
  193. { "h-memory", HW_H_MEMORY, CGEN_ASM_NONE, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } },
  194. { "h-sint", HW_H_SINT, CGEN_ASM_NONE, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } },
  195. { "h-uint", HW_H_UINT, CGEN_ASM_NONE, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } },
  196. { "h-addr", HW_H_ADDR, CGEN_ASM_NONE, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } },
  197. { "h-iaddr", HW_H_IADDR, CGEN_ASM_NONE, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } },
  198. { "h-pc", HW_H_PC, CGEN_ASM_NONE, 0, { 0|A(PC), { { { (1<<MACH_BASE), 0 } } } } },
  199. { "h-gr", HW_H_GR, CGEN_ASM_KEYWORD, (PTR) & lm32_cgen_opval_h_gr, { 0, { { { (1<<MACH_BASE), 0 } } } } },
  200. { "h-csr", HW_H_CSR, CGEN_ASM_KEYWORD, (PTR) & lm32_cgen_opval_h_csr, { 0, { { { (1<<MACH_BASE), 0 } } } } },
  201. { 0, 0, CGEN_ASM_NONE, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } }
  202. };
  203. #undef A
  204. /* The instruction field table. */
  205. #define A(a) (1 << CGEN_IFLD_##a)
  206. const CGEN_IFLD lm32_cgen_ifld_table[] =
  207. {
  208. { LM32_F_NIL, "f-nil", 0, 0, 0, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } },
  209. { LM32_F_ANYOF, "f-anyof", 0, 0, 0, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } },
  210. { LM32_F_OPCODE, "f-opcode", 0, 32, 31, 6, { 0, { { { (1<<MACH_BASE), 0 } } } } },
  211. { LM32_F_R0, "f-r0", 0, 32, 25, 5, { 0, { { { (1<<MACH_BASE), 0 } } } } },
  212. { LM32_F_R1, "f-r1", 0, 32, 20, 5, { 0, { { { (1<<MACH_BASE), 0 } } } } },
  213. { LM32_F_R2, "f-r2", 0, 32, 15, 5, { 0, { { { (1<<MACH_BASE), 0 } } } } },
  214. { LM32_F_RESV0, "f-resv0", 0, 32, 10, 11, { 0|A(RESERVED), { { { (1<<MACH_BASE), 0 } } } } },
  215. { LM32_F_SHIFT, "f-shift", 0, 32, 4, 5, { 0, { { { (1<<MACH_BASE), 0 } } } } },
  216. { LM32_F_IMM, "f-imm", 0, 32, 15, 16, { 0, { { { (1<<MACH_BASE), 0 } } } } },
  217. { LM32_F_UIMM, "f-uimm", 0, 32, 15, 16, { 0, { { { (1<<MACH_BASE), 0 } } } } },
  218. { LM32_F_CSR, "f-csr", 0, 32, 25, 5, { 0, { { { (1<<MACH_BASE), 0 } } } } },
  219. { LM32_F_USER, "f-user", 0, 32, 10, 11, { 0, { { { (1<<MACH_BASE), 0 } } } } },
  220. { LM32_F_EXCEPTION, "f-exception", 0, 32, 25, 26, { 0, { { { (1<<MACH_BASE), 0 } } } } },
  221. { LM32_F_BRANCH, "f-branch", 0, 32, 15, 16, { 0|A(PCREL_ADDR), { { { (1<<MACH_BASE), 0 } } } } },
  222. { LM32_F_CALL, "f-call", 0, 32, 25, 26, { 0|A(PCREL_ADDR), { { { (1<<MACH_BASE), 0 } } } } },
  223. { 0, 0, 0, 0, 0, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } }
  224. };
  225. #undef A
  226. /* multi ifield declarations */
  227. /* multi ifield definitions */
  228. /* The operand table. */
  229. #define A(a) (1 << CGEN_OPERAND_##a)
  230. #define OPERAND(op) LM32_OPERAND_##op
  231. const CGEN_OPERAND lm32_cgen_operand_table[] =
  232. {
  233. /* pc: program counter */
  234. { "pc", LM32_OPERAND_PC, HW_H_PC, 0, 0,
  235. { 0, { (const PTR) &lm32_cgen_ifld_table[LM32_F_NIL] } },
  236. { 0|A(SEM_ONLY), { { { (1<<MACH_BASE), 0 } } } } },
  237. /* r0: register 0 */
  238. { "r0", LM32_OPERAND_R0, HW_H_GR, 25, 5,
  239. { 0, { (const PTR) &lm32_cgen_ifld_table[LM32_F_R0] } },
  240. { 0, { { { (1<<MACH_BASE), 0 } } } } },
  241. /* r1: register 1 */
  242. { "r1", LM32_OPERAND_R1, HW_H_GR, 20, 5,
  243. { 0, { (const PTR) &lm32_cgen_ifld_table[LM32_F_R1] } },
  244. { 0, { { { (1<<MACH_BASE), 0 } } } } },
  245. /* r2: register 2 */
  246. { "r2", LM32_OPERAND_R2, HW_H_GR, 15, 5,
  247. { 0, { (const PTR) &lm32_cgen_ifld_table[LM32_F_R2] } },
  248. { 0, { { { (1<<MACH_BASE), 0 } } } } },
  249. /* shift: shift amout */
  250. { "shift", LM32_OPERAND_SHIFT, HW_H_UINT, 4, 5,
  251. { 0, { (const PTR) &lm32_cgen_ifld_table[LM32_F_SHIFT] } },
  252. { 0, { { { (1<<MACH_BASE), 0 } } } } },
  253. /* imm: signed immediate */
  254. { "imm", LM32_OPERAND_IMM, HW_H_SINT, 15, 16,
  255. { 0, { (const PTR) &lm32_cgen_ifld_table[LM32_F_IMM] } },
  256. { 0, { { { (1<<MACH_BASE), 0 } } } } },
  257. /* uimm: unsigned immediate */
  258. { "uimm", LM32_OPERAND_UIMM, HW_H_UINT, 15, 16,
  259. { 0, { (const PTR) &lm32_cgen_ifld_table[LM32_F_UIMM] } },
  260. { 0, { { { (1<<MACH_BASE), 0 } } } } },
  261. /* branch: branch offset */
  262. { "branch", LM32_OPERAND_BRANCH, HW_H_IADDR, 15, 16,
  263. { 0, { (const PTR) &lm32_cgen_ifld_table[LM32_F_BRANCH] } },
  264. { 0|A(PCREL_ADDR), { { { (1<<MACH_BASE), 0 } } } } },
  265. /* call: call offset */
  266. { "call", LM32_OPERAND_CALL, HW_H_IADDR, 25, 26,
  267. { 0, { (const PTR) &lm32_cgen_ifld_table[LM32_F_CALL] } },
  268. { 0|A(PCREL_ADDR), { { { (1<<MACH_BASE), 0 } } } } },
  269. /* csr: csr */
  270. { "csr", LM32_OPERAND_CSR, HW_H_CSR, 25, 5,
  271. { 0, { (const PTR) &lm32_cgen_ifld_table[LM32_F_CSR] } },
  272. { 0, { { { (1<<MACH_BASE), 0 } } } } },
  273. /* user: user */
  274. { "user", LM32_OPERAND_USER, HW_H_UINT, 10, 11,
  275. { 0, { (const PTR) &lm32_cgen_ifld_table[LM32_F_USER] } },
  276. { 0, { { { (1<<MACH_BASE), 0 } } } } },
  277. /* exception: exception */
  278. { "exception", LM32_OPERAND_EXCEPTION, HW_H_UINT, 25, 26,
  279. { 0, { (const PTR) &lm32_cgen_ifld_table[LM32_F_EXCEPTION] } },
  280. { 0, { { { (1<<MACH_BASE), 0 } } } } },
  281. /* hi16: high 16-bit immediate */
  282. { "hi16", LM32_OPERAND_HI16, HW_H_UINT, 15, 16,
  283. { 0, { (const PTR) &lm32_cgen_ifld_table[LM32_F_UIMM] } },
  284. { 0, { { { (1<<MACH_BASE), 0 } } } } },
  285. /* lo16: low 16-bit immediate */
  286. { "lo16", LM32_OPERAND_LO16, HW_H_UINT, 15, 16,
  287. { 0, { (const PTR) &lm32_cgen_ifld_table[LM32_F_UIMM] } },
  288. { 0, { { { (1<<MACH_BASE), 0 } } } } },
  289. /* gp16: gp relative 16-bit immediate */
  290. { "gp16", LM32_OPERAND_GP16, HW_H_SINT, 15, 16,
  291. { 0, { (const PTR) &lm32_cgen_ifld_table[LM32_F_IMM] } },
  292. { 0, { { { (1<<MACH_BASE), 0 } } } } },
  293. /* got16: got 16-bit immediate */
  294. { "got16", LM32_OPERAND_GOT16, HW_H_SINT, 15, 16,
  295. { 0, { (const PTR) &lm32_cgen_ifld_table[LM32_F_IMM] } },
  296. { 0, { { { (1<<MACH_BASE), 0 } } } } },
  297. /* gotoffhi16: got offset high 16-bit immediate */
  298. { "gotoffhi16", LM32_OPERAND_GOTOFFHI16, HW_H_SINT, 15, 16,
  299. { 0, { (const PTR) &lm32_cgen_ifld_table[LM32_F_IMM] } },
  300. { 0, { { { (1<<MACH_BASE), 0 } } } } },
  301. /* gotofflo16: got offset low 16-bit immediate */
  302. { "gotofflo16", LM32_OPERAND_GOTOFFLO16, HW_H_SINT, 15, 16,
  303. { 0, { (const PTR) &lm32_cgen_ifld_table[LM32_F_IMM] } },
  304. { 0, { { { (1<<MACH_BASE), 0 } } } } },
  305. /* sentinel */
  306. { 0, 0, 0, 0, 0,
  307. { 0, { (const PTR) 0 } },
  308. { 0, { { { (1<<MACH_BASE), 0 } } } } }
  309. };
  310. #undef A
  311. /* The instruction table. */
  312. #define OP(field) CGEN_SYNTAX_MAKE_FIELD (OPERAND (field))
  313. #define A(a) (1 << CGEN_INSN_##a)
  314. static const CGEN_IBASE lm32_cgen_insn_table[MAX_INSNS] =
  315. {
  316. /* Special null first entry.
  317. A `num' value of zero is thus invalid.
  318. Also, the special `invalid' insn resides here. */
  319. { 0, 0, 0, 0, { 0, { { { (1<<MACH_BASE), 0 } } } } },
  320. /* add $r2,$r0,$r1 */
  321. {
  322. LM32_INSN_ADD, "add", "add", 32,
  323. { 0, { { { (1<<MACH_BASE), 0 } } } }
  324. },
  325. /* addi $r1,$r0,$imm */
  326. {
  327. LM32_INSN_ADDI, "addi", "addi", 32,
  328. { 0, { { { (1<<MACH_BASE), 0 } } } }
  329. },
  330. /* and $r2,$r0,$r1 */
  331. {
  332. LM32_INSN_AND, "and", "and", 32,
  333. { 0, { { { (1<<MACH_BASE), 0 } } } }
  334. },
  335. /* andi $r1,$r0,$uimm */
  336. {
  337. LM32_INSN_ANDI, "andi", "andi", 32,
  338. { 0, { { { (1<<MACH_BASE), 0 } } } }
  339. },
  340. /* andhi $r1,$r0,$hi16 */
  341. {
  342. LM32_INSN_ANDHII, "andhii", "andhi", 32,
  343. { 0, { { { (1<<MACH_BASE), 0 } } } }
  344. },
  345. /* b $r0 */
  346. {
  347. LM32_INSN_B, "b", "b", 32,
  348. { 0|A(UNCOND_CTI), { { { (1<<MACH_BASE), 0 } } } }
  349. },
  350. /* bi $call */
  351. {
  352. LM32_INSN_BI, "bi", "bi", 32,
  353. { 0|A(UNCOND_CTI), { { { (1<<MACH_BASE), 0 } } } }
  354. },
  355. /* be $r0,$r1,$branch */
  356. {
  357. LM32_INSN_BE, "be", "be", 32,
  358. { 0|A(COND_CTI), { { { (1<<MACH_BASE), 0 } } } }
  359. },
  360. /* bg $r0,$r1,$branch */
  361. {
  362. LM32_INSN_BG, "bg", "bg", 32,
  363. { 0|A(COND_CTI), { { { (1<<MACH_BASE), 0 } } } }
  364. },
  365. /* bge $r0,$r1,$branch */
  366. {
  367. LM32_INSN_BGE, "bge", "bge", 32,
  368. { 0|A(COND_CTI), { { { (1<<MACH_BASE), 0 } } } }
  369. },
  370. /* bgeu $r0,$r1,$branch */
  371. {
  372. LM32_INSN_BGEU, "bgeu", "bgeu", 32,
  373. { 0|A(COND_CTI), { { { (1<<MACH_BASE), 0 } } } }
  374. },
  375. /* bgu $r0,$r1,$branch */
  376. {
  377. LM32_INSN_BGU, "bgu", "bgu", 32,
  378. { 0|A(COND_CTI), { { { (1<<MACH_BASE), 0 } } } }
  379. },
  380. /* bne $r0,$r1,$branch */
  381. {
  382. LM32_INSN_BNE, "bne", "bne", 32,
  383. { 0|A(COND_CTI), { { { (1<<MACH_BASE), 0 } } } }
  384. },
  385. /* call $r0 */
  386. {
  387. LM32_INSN_CALL, "call", "call", 32,
  388. { 0|A(UNCOND_CTI), { { { (1<<MACH_BASE), 0 } } } }
  389. },
  390. /* calli $call */
  391. {
  392. LM32_INSN_CALLI, "calli", "calli", 32,
  393. { 0|A(UNCOND_CTI), { { { (1<<MACH_BASE), 0 } } } }
  394. },
  395. /* cmpe $r2,$r0,$r1 */
  396. {
  397. LM32_INSN_CMPE, "cmpe", "cmpe", 32,
  398. { 0, { { { (1<<MACH_BASE), 0 } } } }
  399. },
  400. /* cmpei $r1,$r0,$imm */
  401. {
  402. LM32_INSN_CMPEI, "cmpei", "cmpei", 32,
  403. { 0, { { { (1<<MACH_BASE), 0 } } } }
  404. },
  405. /* cmpg $r2,$r0,$r1 */
  406. {
  407. LM32_INSN_CMPG, "cmpg", "cmpg", 32,
  408. { 0, { { { (1<<MACH_BASE), 0 } } } }
  409. },
  410. /* cmpgi $r1,$r0,$imm */
  411. {
  412. LM32_INSN_CMPGI, "cmpgi", "cmpgi", 32,
  413. { 0, { { { (1<<MACH_BASE), 0 } } } }
  414. },
  415. /* cmpge $r2,$r0,$r1 */
  416. {
  417. LM32_INSN_CMPGE, "cmpge", "cmpge", 32,
  418. { 0, { { { (1<<MACH_BASE), 0 } } } }
  419. },
  420. /* cmpgei $r1,$r0,$imm */
  421. {
  422. LM32_INSN_CMPGEI, "cmpgei", "cmpgei", 32,
  423. { 0, { { { (1<<MACH_BASE), 0 } } } }
  424. },
  425. /* cmpgeu $r2,$r0,$r1 */
  426. {
  427. LM32_INSN_CMPGEU, "cmpgeu", "cmpgeu", 32,
  428. { 0, { { { (1<<MACH_BASE), 0 } } } }
  429. },
  430. /* cmpgeui $r1,$r0,$uimm */
  431. {
  432. LM32_INSN_CMPGEUI, "cmpgeui", "cmpgeui", 32,
  433. { 0, { { { (1<<MACH_BASE), 0 } } } }
  434. },
  435. /* cmpgu $r2,$r0,$r1 */
  436. {
  437. LM32_INSN_CMPGU, "cmpgu", "cmpgu", 32,
  438. { 0, { { { (1<<MACH_BASE), 0 } } } }
  439. },
  440. /* cmpgui $r1,$r0,$uimm */
  441. {
  442. LM32_INSN_CMPGUI, "cmpgui", "cmpgui", 32,
  443. { 0, { { { (1<<MACH_BASE), 0 } } } }
  444. },
  445. /* cmpne $r2,$r0,$r1 */
  446. {
  447. LM32_INSN_CMPNE, "cmpne", "cmpne", 32,
  448. { 0, { { { (1<<MACH_BASE), 0 } } } }
  449. },
  450. /* cmpnei $r1,$r0,$imm */
  451. {
  452. LM32_INSN_CMPNEI, "cmpnei", "cmpnei", 32,
  453. { 0, { { { (1<<MACH_BASE), 0 } } } }
  454. },
  455. /* divu $r2,$r0,$r1 */
  456. {
  457. LM32_INSN_DIVU, "divu", "divu", 32,
  458. { 0|A(UNCOND_CTI), { { { (1<<MACH_BASE), 0 } } } }
  459. },
  460. /* lb $r1,($r0+$imm) */
  461. {
  462. LM32_INSN_LB, "lb", "lb", 32,
  463. { 0, { { { (1<<MACH_BASE), 0 } } } }
  464. },
  465. /* lbu $r1,($r0+$imm) */
  466. {
  467. LM32_INSN_LBU, "lbu", "lbu", 32,
  468. { 0, { { { (1<<MACH_BASE), 0 } } } }
  469. },
  470. /* lh $r1,($r0+$imm) */
  471. {
  472. LM32_INSN_LH, "lh", "lh", 32,
  473. { 0, { { { (1<<MACH_BASE), 0 } } } }
  474. },
  475. /* lhu $r1,($r0+$imm) */
  476. {
  477. LM32_INSN_LHU, "lhu", "lhu", 32,
  478. { 0, { { { (1<<MACH_BASE), 0 } } } }
  479. },
  480. /* lw $r1,($r0+$imm) */
  481. {
  482. LM32_INSN_LW, "lw", "lw", 32,
  483. { 0, { { { (1<<MACH_BASE), 0 } } } }
  484. },
  485. /* modu $r2,$r0,$r1 */
  486. {
  487. LM32_INSN_MODU, "modu", "modu", 32,
  488. { 0|A(UNCOND_CTI), { { { (1<<MACH_BASE), 0 } } } }
  489. },
  490. /* mul $r2,$r0,$r1 */
  491. {
  492. LM32_INSN_MUL, "mul", "mul", 32,
  493. { 0, { { { (1<<MACH_BASE), 0 } } } }
  494. },
  495. /* muli $r1,$r0,$imm */
  496. {
  497. LM32_INSN_MULI, "muli", "muli", 32,
  498. { 0, { { { (1<<MACH_BASE), 0 } } } }
  499. },
  500. /* nor $r2,$r0,$r1 */
  501. {
  502. LM32_INSN_NOR, "nor", "nor", 32,
  503. { 0, { { { (1<<MACH_BASE), 0 } } } }
  504. },
  505. /* nori $r1,$r0,$uimm */
  506. {
  507. LM32_INSN_NORI, "nori", "nori", 32,
  508. { 0, { { { (1<<MACH_BASE), 0 } } } }
  509. },
  510. /* or $r2,$r0,$r1 */
  511. {
  512. LM32_INSN_OR, "or", "or", 32,
  513. { 0, { { { (1<<MACH_BASE), 0 } } } }
  514. },
  515. /* ori $r1,$r0,$lo16 */
  516. {
  517. LM32_INSN_ORI, "ori", "ori", 32,
  518. { 0, { { { (1<<MACH_BASE), 0 } } } }
  519. },
  520. /* orhi $r1,$r0,$hi16 */
  521. {
  522. LM32_INSN_ORHII, "orhii", "orhi", 32,
  523. { 0, { { { (1<<MACH_BASE), 0 } } } }
  524. },
  525. /* rcsr $r2,$csr */
  526. {
  527. LM32_INSN_RCSR, "rcsr", "rcsr", 32,
  528. { 0, { { { (1<<MACH_BASE), 0 } } } }
  529. },
  530. /* sb ($r0+$imm),$r1 */
  531. {
  532. LM32_INSN_SB, "sb", "sb", 32,
  533. { 0, { { { (1<<MACH_BASE), 0 } } } }
  534. },
  535. /* sextb $r2,$r0 */
  536. {
  537. LM32_INSN_SEXTB, "sextb", "sextb", 32,
  538. { 0, { { { (1<<MACH_BASE), 0 } } } }
  539. },
  540. /* sexth $r2,$r0 */
  541. {
  542. LM32_INSN_SEXTH, "sexth", "sexth", 32,
  543. { 0, { { { (1<<MACH_BASE), 0 } } } }
  544. },
  545. /* sh ($r0+$imm),$r1 */
  546. {
  547. LM32_INSN_SH, "sh", "sh", 32,
  548. { 0, { { { (1<<MACH_BASE), 0 } } } }
  549. },
  550. /* sl $r2,$r0,$r1 */
  551. {
  552. LM32_INSN_SL, "sl", "sl", 32,
  553. { 0, { { { (1<<MACH_BASE), 0 } } } }
  554. },
  555. /* sli $r1,$r0,$imm */
  556. {
  557. LM32_INSN_SLI, "sli", "sli", 32,
  558. { 0, { { { (1<<MACH_BASE), 0 } } } }
  559. },
  560. /* sr $r2,$r0,$r1 */
  561. {
  562. LM32_INSN_SR, "sr", "sr", 32,
  563. { 0, { { { (1<<MACH_BASE), 0 } } } }
  564. },
  565. /* sri $r1,$r0,$imm */
  566. {
  567. LM32_INSN_SRI, "sri", "sri", 32,
  568. { 0, { { { (1<<MACH_BASE), 0 } } } }
  569. },
  570. /* sru $r2,$r0,$r1 */
  571. {
  572. LM32_INSN_SRU, "sru", "sru", 32,
  573. { 0, { { { (1<<MACH_BASE), 0 } } } }
  574. },
  575. /* srui $r1,$r0,$imm */
  576. {
  577. LM32_INSN_SRUI, "srui", "srui", 32,
  578. { 0, { { { (1<<MACH_BASE), 0 } } } }
  579. },
  580. /* sub $r2,$r0,$r1 */
  581. {
  582. LM32_INSN_SUB, "sub", "sub", 32,
  583. { 0, { { { (1<<MACH_BASE), 0 } } } }
  584. },
  585. /* sw ($r0+$imm),$r1 */
  586. {
  587. LM32_INSN_SW, "sw", "sw", 32,
  588. { 0, { { { (1<<MACH_BASE), 0 } } } }
  589. },
  590. /* user $r2,$r0,$r1,$user */
  591. {
  592. LM32_INSN_USER, "user", "user", 32,
  593. { 0, { { { (1<<MACH_BASE), 0 } } } }
  594. },
  595. /* wcsr $csr,$r1 */
  596. {
  597. LM32_INSN_WCSR, "wcsr", "wcsr", 32,
  598. { 0, { { { (1<<MACH_BASE), 0 } } } }
  599. },
  600. /* xor $r2,$r0,$r1 */
  601. {
  602. LM32_INSN_XOR, "xor", "xor", 32,
  603. { 0, { { { (1<<MACH_BASE), 0 } } } }
  604. },
  605. /* xori $r1,$r0,$uimm */
  606. {
  607. LM32_INSN_XORI, "xori", "xori", 32,
  608. { 0, { { { (1<<MACH_BASE), 0 } } } }
  609. },
  610. /* xnor $r2,$r0,$r1 */
  611. {
  612. LM32_INSN_XNOR, "xnor", "xnor", 32,
  613. { 0, { { { (1<<MACH_BASE), 0 } } } }
  614. },
  615. /* xnori $r1,$r0,$uimm */
  616. {
  617. LM32_INSN_XNORI, "xnori", "xnori", 32,
  618. { 0, { { { (1<<MACH_BASE), 0 } } } }
  619. },
  620. /* break */
  621. {
  622. LM32_INSN_BREAK, "break", "break", 32,
  623. { 0|A(UNCOND_CTI), { { { (1<<MACH_BASE), 0 } } } }
  624. },
  625. /* scall */
  626. {
  627. LM32_INSN_SCALL, "scall", "scall", 32,
  628. { 0|A(UNCOND_CTI), { { { (1<<MACH_BASE), 0 } } } }
  629. },
  630. /* bret */
  631. {
  632. -1, "bret", "bret", 32,
  633. { 0|A(ALIAS)|A(UNCOND_CTI), { { { (1<<MACH_BASE), 0 } } } }
  634. },
  635. /* eret */
  636. {
  637. -1, "eret", "eret", 32,
  638. { 0|A(ALIAS)|A(UNCOND_CTI), { { { (1<<MACH_BASE), 0 } } } }
  639. },
  640. /* ret */
  641. {
  642. -1, "ret", "ret", 32,
  643. { 0|A(ALIAS)|A(UNCOND_CTI), { { { (1<<MACH_BASE), 0 } } } }
  644. },
  645. /* mv $r2,$r0 */
  646. {
  647. -1, "mv", "mv", 32,
  648. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  649. },
  650. /* mvi $r1,$imm */
  651. {
  652. -1, "mvi", "mvi", 32,
  653. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  654. },
  655. /* mvu $r1,$lo16 */
  656. {
  657. -1, "mvui", "mvu", 32,
  658. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  659. },
  660. /* mvhi $r1,$hi16 */
  661. {
  662. -1, "mvhi", "mvhi", 32,
  663. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  664. },
  665. /* mva $r1,$gp16 */
  666. {
  667. -1, "mva", "mva", 32,
  668. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  669. },
  670. /* not $r2,$r0 */
  671. {
  672. -1, "not", "not", 32,
  673. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  674. },
  675. /* nop */
  676. {
  677. -1, "nop", "nop", 32,
  678. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  679. },
  680. /* lb $r1,$gp16 */
  681. {
  682. -1, "lbgprel", "lb", 32,
  683. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  684. },
  685. /* lbu $r1,$gp16 */
  686. {
  687. -1, "lbugprel", "lbu", 32,
  688. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  689. },
  690. /* lh $r1,$gp16 */
  691. {
  692. -1, "lhgprel", "lh", 32,
  693. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  694. },
  695. /* lhu $r1,$gp16 */
  696. {
  697. -1, "lhugprel", "lhu", 32,
  698. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  699. },
  700. /* lw $r1,$gp16 */
  701. {
  702. -1, "lwgprel", "lw", 32,
  703. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  704. },
  705. /* sb $gp16,$r1 */
  706. {
  707. -1, "sbgprel", "sb", 32,
  708. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  709. },
  710. /* sh $gp16,$r1 */
  711. {
  712. -1, "shgprel", "sh", 32,
  713. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  714. },
  715. /* sw $gp16,$r1 */
  716. {
  717. -1, "swgprel", "sw", 32,
  718. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  719. },
  720. /* lw $r1,(gp+$got16) */
  721. {
  722. -1, "lwgotrel", "lw", 32,
  723. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  724. },
  725. /* orhi $r1,$r0,$gotoffhi16 */
  726. {
  727. -1, "orhigotoffi", "orhi", 32,
  728. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  729. },
  730. /* addi $r1,$r0,$gotofflo16 */
  731. {
  732. -1, "addgotoff", "addi", 32,
  733. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  734. },
  735. /* sw ($r0+$gotofflo16),$r1 */
  736. {
  737. -1, "swgotoff", "sw", 32,
  738. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  739. },
  740. /* lw $r1,($r0+$gotofflo16) */
  741. {
  742. -1, "lwgotoff", "lw", 32,
  743. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  744. },
  745. /* sh ($r0+$gotofflo16),$r1 */
  746. {
  747. -1, "shgotoff", "sh", 32,
  748. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  749. },
  750. /* lh $r1,($r0+$gotofflo16) */
  751. {
  752. -1, "lhgotoff", "lh", 32,
  753. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  754. },
  755. /* lhu $r1,($r0+$gotofflo16) */
  756. {
  757. -1, "lhugotoff", "lhu", 32,
  758. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  759. },
  760. /* sb ($r0+$gotofflo16),$r1 */
  761. {
  762. -1, "sbgotoff", "sb", 32,
  763. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  764. },
  765. /* lb $r1,($r0+$gotofflo16) */
  766. {
  767. -1, "lbgotoff", "lb", 32,
  768. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  769. },
  770. /* lbu $r1,($r0+$gotofflo16) */
  771. {
  772. -1, "lbugotoff", "lbu", 32,
  773. { 0|A(ALIAS), { { { (1<<MACH_BASE), 0 } } } }
  774. },
  775. };
  776. #undef OP
  777. #undef A
  778. /* Initialize anything needed to be done once, before any cpu_open call. */
  779. static void
  780. init_tables (void)
  781. {
  782. }
  783. #ifndef opcodes_error_handler
  784. #define opcodes_error_handler(...) \
  785. fprintf (stderr, __VA_ARGS__); fputc ('\n', stderr)
  786. #endif
  787. static const CGEN_MACH * lookup_mach_via_bfd_name (const CGEN_MACH *, const char *);
  788. static void build_hw_table (CGEN_CPU_TABLE *);
  789. static void build_ifield_table (CGEN_CPU_TABLE *);
  790. static void build_operand_table (CGEN_CPU_TABLE *);
  791. static void build_insn_table (CGEN_CPU_TABLE *);
  792. static void lm32_cgen_rebuild_tables (CGEN_CPU_TABLE *);
  793. /* Subroutine of lm32_cgen_cpu_open to look up a mach via its bfd name. */
  794. static const CGEN_MACH *
  795. lookup_mach_via_bfd_name (const CGEN_MACH *table, const char *name)
  796. {
  797. while (table->name)
  798. {
  799. if (strcmp (name, table->bfd_name) == 0)
  800. return table;
  801. ++table;
  802. }
  803. return NULL;
  804. }
  805. /* Subroutine of lm32_cgen_cpu_open to build the hardware table. */
  806. static void
  807. build_hw_table (CGEN_CPU_TABLE *cd)
  808. {
  809. int i;
  810. int machs = cd->machs;
  811. const CGEN_HW_ENTRY *init = & lm32_cgen_hw_table[0];
  812. /* MAX_HW is only an upper bound on the number of selected entries.
  813. However each entry is indexed by it's enum so there can be holes in
  814. the table. */
  815. const CGEN_HW_ENTRY **selected =
  816. (const CGEN_HW_ENTRY **) xmalloc (MAX_HW * sizeof (CGEN_HW_ENTRY *));
  817. cd->hw_table.init_entries = init;
  818. cd->hw_table.entry_size = sizeof (CGEN_HW_ENTRY);
  819. memset (selected, 0, MAX_HW * sizeof (CGEN_HW_ENTRY *));
  820. /* ??? For now we just use machs to determine which ones we want. */
  821. for (i = 0; init[i].name != NULL; ++i)
  822. if (CGEN_HW_ATTR_VALUE (&init[i], CGEN_HW_MACH)
  823. & machs)
  824. selected[init[i].type] = &init[i];
  825. cd->hw_table.entries = selected;
  826. cd->hw_table.num_entries = MAX_HW;
  827. }
  828. /* Subroutine of lm32_cgen_cpu_open to build the hardware table. */
  829. static void
  830. build_ifield_table (CGEN_CPU_TABLE *cd)
  831. {
  832. cd->ifld_table = & lm32_cgen_ifld_table[0];
  833. }
  834. /* Subroutine of lm32_cgen_cpu_open to build the hardware table. */
  835. static void
  836. build_operand_table (CGEN_CPU_TABLE *cd)
  837. {
  838. int i;
  839. int machs = cd->machs;
  840. const CGEN_OPERAND *init = & lm32_cgen_operand_table[0];
  841. /* MAX_OPERANDS is only an upper bound on the number of selected entries.
  842. However each entry is indexed by it's enum so there can be holes in
  843. the table. */
  844. const CGEN_OPERAND **selected = xmalloc (MAX_OPERANDS * sizeof (* selected));
  845. cd->operand_table.init_entries = init;
  846. cd->operand_table.entry_size = sizeof (CGEN_OPERAND);
  847. memset (selected, 0, MAX_OPERANDS * sizeof (CGEN_OPERAND *));
  848. /* ??? For now we just use mach to determine which ones we want. */
  849. for (i = 0; init[i].name != NULL; ++i)
  850. if (CGEN_OPERAND_ATTR_VALUE (&init[i], CGEN_OPERAND_MACH)
  851. & machs)
  852. selected[init[i].type] = &init[i];
  853. cd->operand_table.entries = selected;
  854. cd->operand_table.num_entries = MAX_OPERANDS;
  855. }
  856. /* Subroutine of lm32_cgen_cpu_open to build the hardware table.
  857. ??? This could leave out insns not supported by the specified mach/isa,
  858. but that would cause errors like "foo only supported by bar" to become
  859. "unknown insn", so for now we include all insns and require the app to
  860. do the checking later.
  861. ??? On the other hand, parsing of such insns may require their hardware or
  862. operand elements to be in the table [which they mightn't be]. */
  863. static void
  864. build_insn_table (CGEN_CPU_TABLE *cd)
  865. {
  866. int i;
  867. const CGEN_IBASE *ib = & lm32_cgen_insn_table[0];
  868. CGEN_INSN *insns = xmalloc (MAX_INSNS * sizeof (CGEN_INSN));
  869. memset (insns, 0, MAX_INSNS * sizeof (CGEN_INSN));
  870. for (i = 0; i < MAX_INSNS; ++i)
  871. insns[i].base = &ib[i];
  872. cd->insn_table.init_entries = insns;
  873. cd->insn_table.entry_size = sizeof (CGEN_IBASE);
  874. cd->insn_table.num_init_entries = MAX_INSNS;
  875. }
  876. /* Subroutine of lm32_cgen_cpu_open to rebuild the tables. */
  877. static void
  878. lm32_cgen_rebuild_tables (CGEN_CPU_TABLE *cd)
  879. {
  880. int i;
  881. CGEN_BITSET *isas = cd->isas;
  882. unsigned int machs = cd->machs;
  883. cd->int_insn_p = CGEN_INT_INSN_P;
  884. /* Data derived from the isa spec. */
  885. #define UNSET (CGEN_SIZE_UNKNOWN + 1)
  886. cd->default_insn_bitsize = UNSET;
  887. cd->base_insn_bitsize = UNSET;
  888. cd->min_insn_bitsize = 65535; /* Some ridiculously big number. */
  889. cd->max_insn_bitsize = 0;
  890. for (i = 0; i < MAX_ISAS; ++i)
  891. if (cgen_bitset_contains (isas, i))
  892. {
  893. const CGEN_ISA *isa = & lm32_cgen_isa_table[i];
  894. /* Default insn sizes of all selected isas must be
  895. equal or we set the result to 0, meaning "unknown". */
  896. if (cd->default_insn_bitsize == UNSET)
  897. cd->default_insn_bitsize = isa->default_insn_bitsize;
  898. else if (isa->default_insn_bitsize == cd->default_insn_bitsize)
  899. ; /* This is ok. */
  900. else
  901. cd->default_insn_bitsize = CGEN_SIZE_UNKNOWN;
  902. /* Base insn sizes of all selected isas must be equal
  903. or we set the result to 0, meaning "unknown". */
  904. if (cd->base_insn_bitsize == UNSET)
  905. cd->base_insn_bitsize = isa->base_insn_bitsize;
  906. else if (isa->base_insn_bitsize == cd->base_insn_bitsize)
  907. ; /* This is ok. */
  908. else
  909. cd->base_insn_bitsize = CGEN_SIZE_UNKNOWN;
  910. /* Set min,max insn sizes. */
  911. if (isa->min_insn_bitsize < cd->min_insn_bitsize)
  912. cd->min_insn_bitsize = isa->min_insn_bitsize;
  913. if (isa->max_insn_bitsize > cd->max_insn_bitsize)
  914. cd->max_insn_bitsize = isa->max_insn_bitsize;
  915. }
  916. /* Data derived from the mach spec. */
  917. for (i = 0; i < MAX_MACHS; ++i)
  918. if (((1 << i) & machs) != 0)
  919. {
  920. const CGEN_MACH *mach = & lm32_cgen_mach_table[i];
  921. if (mach->insn_chunk_bitsize != 0)
  922. {
  923. if (cd->insn_chunk_bitsize != 0 && cd->insn_chunk_bitsize != mach->insn_chunk_bitsize)
  924. {
  925. opcodes_error_handler
  926. (/* xgettext:c-format */
  927. _("internal error: lm32_cgen_rebuild_tables: "
  928. "conflicting insn-chunk-bitsize values: `%d' vs. `%d'"),
  929. cd->insn_chunk_bitsize, mach->insn_chunk_bitsize);
  930. abort ();
  931. }
  932. cd->insn_chunk_bitsize = mach->insn_chunk_bitsize;
  933. }
  934. }
  935. /* Determine which hw elements are used by MACH. */
  936. build_hw_table (cd);
  937. /* Build the ifield table. */
  938. build_ifield_table (cd);
  939. /* Determine which operands are used by MACH/ISA. */
  940. build_operand_table (cd);
  941. /* Build the instruction table. */
  942. build_insn_table (cd);
  943. }
  944. /* Initialize a cpu table and return a descriptor.
  945. It's much like opening a file, and must be the first function called.
  946. The arguments are a set of (type/value) pairs, terminated with
  947. CGEN_CPU_OPEN_END.
  948. Currently supported values:
  949. CGEN_CPU_OPEN_ISAS: bitmap of values in enum isa_attr
  950. CGEN_CPU_OPEN_MACHS: bitmap of values in enum mach_attr
  951. CGEN_CPU_OPEN_BFDMACH: specify 1 mach using bfd name
  952. CGEN_CPU_OPEN_ENDIAN: specify endian choice
  953. CGEN_CPU_OPEN_INSN_ENDIAN: specify instruction endian choice
  954. CGEN_CPU_OPEN_END: terminates arguments
  955. ??? Simultaneous multiple isas might not make sense, but it's not (yet)
  956. precluded. */
  957. CGEN_CPU_DESC
  958. lm32_cgen_cpu_open (enum cgen_cpu_open_arg arg_type, ...)
  959. {
  960. CGEN_CPU_TABLE *cd = (CGEN_CPU_TABLE *) xmalloc (sizeof (CGEN_CPU_TABLE));
  961. static int init_p;
  962. CGEN_BITSET *isas = 0; /* 0 = "unspecified" */
  963. unsigned int machs = 0; /* 0 = "unspecified" */
  964. enum cgen_endian endian = CGEN_ENDIAN_UNKNOWN;
  965. enum cgen_endian insn_endian = CGEN_ENDIAN_UNKNOWN;
  966. va_list ap;
  967. if (! init_p)
  968. {
  969. init_tables ();
  970. init_p = 1;
  971. }
  972. memset (cd, 0, sizeof (*cd));
  973. va_start (ap, arg_type);
  974. while (arg_type != CGEN_CPU_OPEN_END)
  975. {
  976. switch (arg_type)
  977. {
  978. case CGEN_CPU_OPEN_ISAS :
  979. isas = va_arg (ap, CGEN_BITSET *);
  980. break;
  981. case CGEN_CPU_OPEN_MACHS :
  982. machs = va_arg (ap, unsigned int);
  983. break;
  984. case CGEN_CPU_OPEN_BFDMACH :
  985. {
  986. const char *name = va_arg (ap, const char *);
  987. const CGEN_MACH *mach =
  988. lookup_mach_via_bfd_name (lm32_cgen_mach_table, name);
  989. if (mach != NULL)
  990. machs |= 1 << mach->num;
  991. break;
  992. }
  993. case CGEN_CPU_OPEN_ENDIAN :
  994. endian = va_arg (ap, enum cgen_endian);
  995. break;
  996. case CGEN_CPU_OPEN_INSN_ENDIAN :
  997. insn_endian = va_arg (ap, enum cgen_endian);
  998. break;
  999. default :
  1000. opcodes_error_handler
  1001. (/* xgettext:c-format */
  1002. _("internal error: lm32_cgen_cpu_open: "
  1003. "unsupported argument `%d'"),
  1004. arg_type);
  1005. abort (); /* ??? return NULL? */
  1006. }
  1007. arg_type = va_arg (ap, enum cgen_cpu_open_arg);
  1008. }
  1009. va_end (ap);
  1010. /* Mach unspecified means "all". */
  1011. if (machs == 0)
  1012. machs = (1 << MAX_MACHS) - 1;
  1013. /* Base mach is always selected. */
  1014. machs |= 1;
  1015. if (endian == CGEN_ENDIAN_UNKNOWN)
  1016. {
  1017. /* ??? If target has only one, could have a default. */
  1018. opcodes_error_handler
  1019. (/* xgettext:c-format */
  1020. _("internal error: lm32_cgen_cpu_open: no endianness specified"));
  1021. abort ();
  1022. }
  1023. cd->isas = cgen_bitset_copy (isas);
  1024. cd->machs = machs;
  1025. cd->endian = endian;
  1026. cd->insn_endian
  1027. = (insn_endian == CGEN_ENDIAN_UNKNOWN ? endian : insn_endian);
  1028. /* Table (re)builder. */
  1029. cd->rebuild_tables = lm32_cgen_rebuild_tables;
  1030. lm32_cgen_rebuild_tables (cd);
  1031. /* Default to not allowing signed overflow. */
  1032. cd->signed_overflow_ok_p = 0;
  1033. return (CGEN_CPU_DESC) cd;
  1034. }
  1035. /* Cover fn to lm32_cgen_cpu_open to handle the simple case of 1 isa, 1 mach.
  1036. MACH_NAME is the bfd name of the mach. */
  1037. CGEN_CPU_DESC
  1038. lm32_cgen_cpu_open_1 (const char *mach_name, enum cgen_endian endian)
  1039. {
  1040. return lm32_cgen_cpu_open (CGEN_CPU_OPEN_BFDMACH, mach_name,
  1041. CGEN_CPU_OPEN_ENDIAN, endian,
  1042. CGEN_CPU_OPEN_END);
  1043. }
  1044. /* Close a cpu table.
  1045. ??? This can live in a machine independent file, but there's currently
  1046. no place to put this file (there's no libcgen). libopcodes is the wrong
  1047. place as some simulator ports use this but they don't use libopcodes. */
  1048. void
  1049. lm32_cgen_cpu_close (CGEN_CPU_DESC cd)
  1050. {
  1051. unsigned int i;
  1052. const CGEN_INSN *insns;
  1053. if (cd->macro_insn_table.init_entries)
  1054. {
  1055. insns = cd->macro_insn_table.init_entries;
  1056. for (i = 0; i < cd->macro_insn_table.num_init_entries; ++i, ++insns)
  1057. if (CGEN_INSN_RX ((insns)))
  1058. regfree (CGEN_INSN_RX (insns));
  1059. }
  1060. if (cd->insn_table.init_entries)
  1061. {
  1062. insns = cd->insn_table.init_entries;
  1063. for (i = 0; i < cd->insn_table.num_init_entries; ++i, ++insns)
  1064. if (CGEN_INSN_RX (insns))
  1065. regfree (CGEN_INSN_RX (insns));
  1066. }
  1067. free ((CGEN_INSN *) cd->macro_insn_table.init_entries);
  1068. free ((CGEN_INSN *) cd->insn_table.init_entries);
  1069. free ((CGEN_HW_ENTRY *) cd->hw_table.entries);
  1070. free ((CGEN_HW_ENTRY *) cd->operand_table.entries);
  1071. free (cd);
  1072. }