iq2000.opc 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /* IQ2000 opcode support. -*- C -*-
  2. Copyright 2000, 2001, 2002, 2005, 2007, 2009 Free Software Foundation, Inc.
  3. Contributed by Red Hat Inc; developed under contract from Fujitsu.
  4. This file is part of the GNU Binutils.
  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 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. MA 02110-1301, USA. */
  17. /* This file is an addendum to iq2000.cpu. Heavy use of C code isn't
  18. appropriate in .cpu files, so it resides here. This especially applies
  19. to assembly/disassembly where parsing/printing can be quite involved.
  20. Such things aren't really part of the specification of the cpu, per se,
  21. so .cpu files provide the general framework and .opc files handle the
  22. nitty-gritty details as necessary.
  23. Each section is delimited with start and end markers.
  24. <arch>-opc.h additions use: "-- opc.h"
  25. <arch>-opc.c additions use: "-- opc.c"
  26. <arch>-asm.c additions use: "-- asm.c"
  27. <arch>-dis.c additions use: "-- dis.c"
  28. <arch>-ibd.h additions use: "-- ibd.h". */
  29. /* -- opc.h */
  30. /* Allows reason codes to be output when assembler errors occur. */
  31. #define CGEN_VERBOSE_ASSEMBLER_ERRORS
  32. /* Override disassembly hashing - there are variable bits in the top
  33. byte of these instructions. */
  34. #define CGEN_DIS_HASH_SIZE 8
  35. #define CGEN_DIS_HASH(buf,value) (((* (unsigned char*) (buf)) >> 6) % CGEN_DIS_HASH_SIZE)
  36. /* following activates check beyond hashing since some iq2000 and iq10
  37. instructions have same mnemonics but different functionality. */
  38. #define CGEN_VALIDATE_INSN_SUPPORTED
  39. extern int iq2000_cgen_insn_supported (CGEN_CPU_DESC, const CGEN_INSN *);
  40. /* -- asm.c */
  41. #include "safe-ctype.h"
  42. static const char * MISSING_CLOSING_PARENTHESIS = N_("missing `)'");
  43. /* Special check to ensure that instruction exists for given machine. */
  44. int
  45. iq2000_cgen_insn_supported (CGEN_CPU_DESC cd, const CGEN_INSN *insn)
  46. {
  47. int machs = cd->machs;
  48. return (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_MACH) & machs) != 0;
  49. }
  50. static int
  51. iq2000_cgen_isa_register (const char **strp)
  52. {
  53. int len;
  54. int ch1, ch2;
  55. if (**strp == 'r' || **strp == 'R')
  56. {
  57. len = strlen (*strp);
  58. if (len == 2)
  59. {
  60. ch1 = (*strp)[1];
  61. if ('0' <= ch1 && ch1 <= '9')
  62. return 1;
  63. }
  64. else if (len == 3)
  65. {
  66. ch1 = (*strp)[1];
  67. ch2 = (*strp)[2];
  68. if (('1' <= ch1 && ch1 <= '2') && ('0' <= ch2 && ch2 <= '9'))
  69. return 1;
  70. if ('3' == ch1 && (ch2 == '0' || ch2 == '1'))
  71. return 1;
  72. }
  73. }
  74. if (**strp == '%'
  75. && TOLOWER ((*strp)[1]) != 'l'
  76. && TOLOWER ((*strp)[1]) != 'h')
  77. return 1;
  78. return 0;
  79. }
  80. /* Handle negated literal. */
  81. static const char *
  82. parse_mimm (CGEN_CPU_DESC cd,
  83. const char **strp,
  84. int opindex,
  85. unsigned long *valuep)
  86. {
  87. const char *errmsg;
  88. /* Verify this isn't a register. */
  89. if (iq2000_cgen_isa_register (strp))
  90. errmsg = _("immediate value cannot be register");
  91. else
  92. {
  93. long value;
  94. errmsg = cgen_parse_signed_integer (cd, strp, opindex, & value);
  95. if (errmsg == NULL)
  96. {
  97. long x = (-value) & 0xFFFF0000;
  98. if (x != 0 && x != (long) 0xFFFF0000)
  99. errmsg = _("immediate value out of range");
  100. else
  101. *valuep = (-value & 0xFFFF);
  102. }
  103. }
  104. return errmsg;
  105. }
  106. /* Handle signed/unsigned literal. */
  107. static const char *
  108. parse_imm (CGEN_CPU_DESC cd,
  109. const char **strp,
  110. int opindex,
  111. unsigned long *valuep)
  112. {
  113. const char *errmsg;
  114. if (iq2000_cgen_isa_register (strp))
  115. errmsg = _("immediate value cannot be register");
  116. else
  117. {
  118. long value;
  119. errmsg = cgen_parse_signed_integer (cd, strp, opindex, & value);
  120. if (errmsg == NULL)
  121. {
  122. long x = value & 0xFFFF0000;
  123. if (x != 0 && x != (long) 0xFFFF0000)
  124. errmsg = _("immediate value out of range");
  125. else
  126. *valuep = (value & 0xFFFF);
  127. }
  128. }
  129. return errmsg;
  130. }
  131. /* Handle iq10 21-bit jmp offset. */
  132. static const char *
  133. parse_jtargq10 (CGEN_CPU_DESC cd,
  134. const char **strp,
  135. int opindex,
  136. int reloc ATTRIBUTE_UNUSED,
  137. enum cgen_parse_operand_result *type_addr ATTRIBUTE_UNUSED,
  138. bfd_vma *valuep)
  139. {
  140. const char *errmsg;
  141. bfd_vma value;
  142. enum cgen_parse_operand_result result_type = CGEN_PARSE_OPERAND_RESULT_NUMBER;
  143. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_IQ2000_OFFSET_21,
  144. & result_type, & value);
  145. if (errmsg == NULL && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
  146. {
  147. /* Check value is within 23-bits
  148. (remembering that 2-bit shift right will occur). */
  149. if (value > 0x7fffff)
  150. return _("21-bit offset out of range");
  151. }
  152. *valuep = (value & 0x7FFFFF);
  153. return errmsg;
  154. }
  155. /* Handle high(). */
  156. static const char *
  157. parse_hi16 (CGEN_CPU_DESC cd,
  158. const char **strp,
  159. int opindex,
  160. unsigned long *valuep)
  161. {
  162. if (strncasecmp (*strp, "%hi(", 4) == 0)
  163. {
  164. enum cgen_parse_operand_result result_type;
  165. bfd_vma value;
  166. const char *errmsg;
  167. *strp += 4;
  168. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_HI16,
  169. & result_type, & value);
  170. if (**strp != ')')
  171. return MISSING_CLOSING_PARENTHESIS;
  172. ++*strp;
  173. if (errmsg == NULL
  174. && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
  175. {
  176. /* If value has top-bit of %lo on, then it will
  177. sign-propagate and so we compensate by adding
  178. 1 to the resultant %hi value. */
  179. if (value & 0x8000)
  180. value += 0x10000;
  181. value >>= 16;
  182. value &= 0xffff;
  183. }
  184. *valuep = value;
  185. return errmsg;
  186. }
  187. /* We add %uhi in case a user just wants the high 16-bits or is using
  188. an insn like ori for %lo which does not sign-propagate. */
  189. if (strncasecmp (*strp, "%uhi(", 5) == 0)
  190. {
  191. enum cgen_parse_operand_result result_type;
  192. bfd_vma value;
  193. const char *errmsg;
  194. *strp += 5;
  195. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_IQ2000_UHI16,
  196. & result_type, & value);
  197. if (**strp != ')')
  198. return MISSING_CLOSING_PARENTHESIS;
  199. ++*strp;
  200. if (errmsg == NULL
  201. && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
  202. value >>= 16;
  203. value &= 0xffff;
  204. *valuep = value;
  205. return errmsg;
  206. }
  207. return parse_imm (cd, strp, opindex, valuep);
  208. }
  209. /* Handle %lo in a signed context.
  210. The signedness of the value doesn't matter to %lo(), but this also
  211. handles the case where %lo() isn't present. */
  212. static const char *
  213. parse_lo16 (CGEN_CPU_DESC cd,
  214. const char **strp,
  215. int opindex,
  216. unsigned long *valuep)
  217. {
  218. if (strncasecmp (*strp, "%lo(", 4) == 0)
  219. {
  220. const char *errmsg;
  221. enum cgen_parse_operand_result result_type;
  222. bfd_vma value;
  223. *strp += 4;
  224. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_LO16,
  225. & result_type, & value);
  226. if (**strp != ')')
  227. return MISSING_CLOSING_PARENTHESIS;
  228. ++*strp;
  229. if (errmsg == NULL
  230. && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
  231. value &= 0xffff;
  232. *valuep = value;
  233. return errmsg;
  234. }
  235. return parse_imm (cd, strp, opindex, valuep);
  236. }
  237. /* Handle %lo in a negated signed context.
  238. The signedness of the value doesn't matter to %lo(), but this also
  239. handles the case where %lo() isn't present. */
  240. static const char *
  241. parse_mlo16 (CGEN_CPU_DESC cd,
  242. const char **strp,
  243. int opindex,
  244. unsigned long *valuep)
  245. {
  246. if (strncasecmp (*strp, "%lo(", 4) == 0)
  247. {
  248. const char *errmsg;
  249. enum cgen_parse_operand_result result_type;
  250. bfd_vma value;
  251. *strp += 4;
  252. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_LO16,
  253. & result_type, & value);
  254. if (**strp != ')')
  255. return MISSING_CLOSING_PARENTHESIS;
  256. ++*strp;
  257. if (errmsg == NULL
  258. && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
  259. value = (-value) & 0xffff;
  260. *valuep = value;
  261. return errmsg;
  262. }
  263. return parse_mimm (cd, strp, opindex, valuep);
  264. }
  265. /* -- */