lm32.opc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /* Lattice Mico32 opcode support. -*- C -*-
  2. Copyright 2008, 2009 Free Software Foundation, Inc.
  3. Contributed by Jon Beniston <jon@beniston.com>
  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. /* -- opc.h */
  18. /* Allows reason codes to be output when assembler errors occur. */
  19. #define CGEN_VERBOSE_ASSEMBLER_ERRORS
  20. #define CGEN_DIS_HASH_SIZE 64
  21. #define CGEN_DIS_HASH(buf,value) ((value >> 26) & 0x3f)
  22. /* -- asm.c */
  23. /* Handle signed/unsigned literal. */
  24. static const char *
  25. parse_imm (CGEN_CPU_DESC cd,
  26. const char **strp,
  27. int opindex,
  28. unsigned long *valuep)
  29. {
  30. const char *errmsg;
  31. signed long value;
  32. errmsg = cgen_parse_signed_integer (cd, strp, opindex, & value);
  33. if (errmsg == NULL)
  34. {
  35. unsigned long x = value & 0xFFFF0000;
  36. if (x != 0 && x != 0xFFFF0000)
  37. errmsg = _("immediate value out of range");
  38. else
  39. *valuep = (value & 0xFFFF);
  40. }
  41. return errmsg;
  42. }
  43. /* Handle hi() */
  44. static const char *
  45. parse_hi16 (CGEN_CPU_DESC cd,
  46. const char **strp,
  47. int opindex,
  48. unsigned long *valuep)
  49. {
  50. if (strncasecmp (*strp, "hi(", 3) == 0)
  51. {
  52. enum cgen_parse_operand_result result_type;
  53. bfd_vma value;
  54. const char *errmsg;
  55. *strp += 3;
  56. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_HI16,
  57. &result_type, &value);
  58. if (**strp != ')')
  59. return _("missing `)'");
  60. ++*strp;
  61. if (errmsg == NULL
  62. && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
  63. value = (value >> 16) & 0xffff;
  64. *valuep = value;
  65. return errmsg;
  66. }
  67. return parse_imm (cd, strp, opindex, valuep);
  68. }
  69. /* Handle lo() */
  70. static const char *
  71. parse_lo16 (CGEN_CPU_DESC cd,
  72. const char **strp,
  73. int opindex,
  74. unsigned long *valuep)
  75. {
  76. if (strncasecmp (*strp, "lo(", 3) == 0)
  77. {
  78. const char *errmsg;
  79. enum cgen_parse_operand_result result_type;
  80. bfd_vma value;
  81. *strp += 3;
  82. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_LO16,
  83. &result_type, &value);
  84. if (**strp != ')')
  85. return _("missing `)'");
  86. ++*strp;
  87. if (errmsg == NULL
  88. && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
  89. value &= 0xffff;
  90. *valuep = value;
  91. return errmsg;
  92. }
  93. return parse_imm (cd, strp, opindex, valuep);
  94. }
  95. /* Handle gp() */
  96. static const char *
  97. parse_gp16 (CGEN_CPU_DESC cd,
  98. const char **strp,
  99. int opindex,
  100. long *valuep)
  101. {
  102. if (strncasecmp (*strp, "gp(", 3) == 0)
  103. {
  104. const char *errmsg;
  105. enum cgen_parse_operand_result result_type;
  106. bfd_vma value;
  107. *strp += 3;
  108. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_GPREL16,
  109. & result_type, & value);
  110. if (**strp != ')')
  111. return _("missing `)'");
  112. ++*strp;
  113. if (errmsg == NULL
  114. && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
  115. value &= 0xffff;
  116. *valuep = value;
  117. return errmsg;
  118. }
  119. return _("expecting gp relative address: gp(symbol)");
  120. }
  121. /* Handle got() */
  122. static const char *
  123. parse_got16 (CGEN_CPU_DESC cd,
  124. const char **strp,
  125. int opindex,
  126. long *valuep)
  127. {
  128. if (strncasecmp (*strp, "got(", 4) == 0)
  129. {
  130. const char *errmsg;
  131. enum cgen_parse_operand_result result_type;
  132. bfd_vma value;
  133. *strp += 4;
  134. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_LM32_16_GOT,
  135. & result_type, & value);
  136. if (**strp != ')')
  137. return _("missing `)'");
  138. ++*strp;
  139. if (errmsg == NULL
  140. && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
  141. value &= 0xffff;
  142. *valuep = value;
  143. return errmsg;
  144. }
  145. return _("expecting got relative address: got(symbol)");
  146. }
  147. /* Handle gotoffhi16() */
  148. static const char *
  149. parse_gotoff_hi16 (CGEN_CPU_DESC cd,
  150. const char **strp,
  151. int opindex,
  152. long *valuep)
  153. {
  154. if (strncasecmp (*strp, "gotoffhi16(", 11) == 0)
  155. {
  156. const char *errmsg;
  157. enum cgen_parse_operand_result result_type;
  158. bfd_vma value;
  159. *strp += 11;
  160. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_LM32_GOTOFF_HI16,
  161. & result_type, & value);
  162. if (**strp != ')')
  163. return _("missing `)'");
  164. ++*strp;
  165. if (errmsg == NULL
  166. && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
  167. value &= 0xffff;
  168. *valuep = value;
  169. return errmsg;
  170. }
  171. return _("expecting got relative address: gotoffhi16(symbol)");
  172. }
  173. /* Handle gotofflo16() */
  174. static const char *
  175. parse_gotoff_lo16 (CGEN_CPU_DESC cd,
  176. const char **strp,
  177. int opindex,
  178. long *valuep)
  179. {
  180. if (strncasecmp (*strp, "gotofflo16(", 11) == 0)
  181. {
  182. const char *errmsg;
  183. enum cgen_parse_operand_result result_type;
  184. bfd_vma value;
  185. *strp += 11;
  186. errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_LM32_GOTOFF_LO16,
  187. &result_type, &value);
  188. if (**strp != ')')
  189. return _("missing `)'");
  190. ++*strp;
  191. if (errmsg == NULL
  192. && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
  193. value &= 0xffff;
  194. *valuep = value;
  195. return errmsg;
  196. }
  197. return _("expecting got relative address: gotofflo16(symbol)");
  198. }