fr30.opc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /* FR30 opcode support. -*- C -*-
  2. Copyright 2011 Free Software Foundation, Inc.
  3. Contributed by Red Hat Inc;
  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 fr30.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. /* ??? This can be improved upon. */
  31. #undef CGEN_DIS_HASH_SIZE
  32. #define CGEN_DIS_HASH_SIZE 16
  33. #undef CGEN_DIS_HASH
  34. #define CGEN_DIS_HASH(buffer, value) (((unsigned char *) (buffer))[0] >> 4)
  35. /* -- */
  36. /* -- asm.c */
  37. /* Handle register lists for LDMx and STMx. */
  38. static int
  39. parse_register_number (const char **strp)
  40. {
  41. int regno;
  42. if (**strp < '0' || **strp > '9')
  43. return -1; /* Error. */
  44. regno = **strp - '0';
  45. ++*strp;
  46. if (**strp >= '0' && **strp <= '9')
  47. {
  48. regno = regno * 10 + (**strp - '0');
  49. ++*strp;
  50. }
  51. return regno;
  52. }
  53. static const char *
  54. parse_register_list (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  55. const char **strp,
  56. int opindex ATTRIBUTE_UNUSED,
  57. unsigned long *valuep,
  58. int high_low, /* 0 == high, 1 == low. */
  59. int load_store) /* 0 == load, 1 == store. */
  60. {
  61. *valuep = 0;
  62. while (**strp && **strp != ')')
  63. {
  64. int regno;
  65. if (**strp != 'R' && **strp != 'r')
  66. break;
  67. ++*strp;
  68. regno = parse_register_number (strp);
  69. if (regno == -1)
  70. return _("Register number is not valid");
  71. if (regno > 7 && !high_low)
  72. return _("Register must be between r0 and r7");
  73. if (regno < 8 && high_low)
  74. return _("Register must be between r8 and r15");
  75. if (high_low)
  76. regno -= 8;
  77. if (load_store) /* Mask is reversed for store. */
  78. *valuep |= 0x80 >> regno;
  79. else
  80. *valuep |= 1 << regno;
  81. if (**strp == ',')
  82. {
  83. if (*(*strp + 1) == ')')
  84. break;
  85. ++*strp;
  86. }
  87. }
  88. if (!*strp || **strp != ')')
  89. return _("Register list is not valid");
  90. return NULL;
  91. }
  92. static const char *
  93. parse_low_register_list_ld (CGEN_CPU_DESC cd,
  94. const char **strp,
  95. int opindex,
  96. unsigned long *valuep)
  97. {
  98. return parse_register_list (cd, strp, opindex, valuep,
  99. 0 /* Low. */, 0 /* Load. */);
  100. }
  101. static const char *
  102. parse_hi_register_list_ld (CGEN_CPU_DESC cd,
  103. const char **strp,
  104. int opindex,
  105. unsigned long *valuep)
  106. {
  107. return parse_register_list (cd, strp, opindex, valuep,
  108. 1 /* High. */, 0 /* Load. */);
  109. }
  110. static const char *
  111. parse_low_register_list_st (CGEN_CPU_DESC cd,
  112. const char **strp,
  113. int opindex,
  114. unsigned long *valuep)
  115. {
  116. return parse_register_list (cd, strp, opindex, valuep,
  117. 0 /* Low. */, 1 /* Store. */);
  118. }
  119. static const char *
  120. parse_hi_register_list_st (CGEN_CPU_DESC cd,
  121. const char **strp,
  122. int opindex,
  123. unsigned long *valuep)
  124. {
  125. return parse_register_list (cd, strp, opindex, valuep,
  126. 1 /* High. */, 1 /* Store. */);
  127. }
  128. /* -- */
  129. /* -- dis.c */
  130. static void
  131. print_register_list (void * dis_info,
  132. long value,
  133. long offset,
  134. int load_store) /* 0 == load, 1 == store. */
  135. {
  136. disassemble_info *info = dis_info;
  137. int mask;
  138. int reg_index = 0;
  139. char * comma = "";
  140. if (load_store)
  141. mask = 0x80;
  142. else
  143. mask = 1;
  144. if (value & mask)
  145. {
  146. (*info->fprintf_func) (info->stream, "r%li", reg_index + offset);
  147. comma = ",";
  148. }
  149. for (reg_index = 1; reg_index <= 7; ++reg_index)
  150. {
  151. if (load_store)
  152. mask >>= 1;
  153. else
  154. mask <<= 1;
  155. if (value & mask)
  156. {
  157. (*info->fprintf_func) (info->stream, "%sr%li", comma, reg_index + offset);
  158. comma = ",";
  159. }
  160. }
  161. }
  162. static void
  163. print_hi_register_list_ld (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  164. void * dis_info,
  165. long value,
  166. unsigned int attrs ATTRIBUTE_UNUSED,
  167. bfd_vma pc ATTRIBUTE_UNUSED,
  168. int length ATTRIBUTE_UNUSED)
  169. {
  170. print_register_list (dis_info, value, 8, 0 /* Load. */);
  171. }
  172. static void
  173. print_low_register_list_ld (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  174. void * dis_info,
  175. long value,
  176. unsigned int attrs ATTRIBUTE_UNUSED,
  177. bfd_vma pc ATTRIBUTE_UNUSED,
  178. int length ATTRIBUTE_UNUSED)
  179. {
  180. print_register_list (dis_info, value, 0, 0 /* Load. */);
  181. }
  182. static void
  183. print_hi_register_list_st (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  184. void * dis_info,
  185. long value,
  186. unsigned int attrs ATTRIBUTE_UNUSED,
  187. bfd_vma pc ATTRIBUTE_UNUSED,
  188. int length ATTRIBUTE_UNUSED)
  189. {
  190. print_register_list (dis_info, value, 8, 1 /* Store. */);
  191. }
  192. static void
  193. print_low_register_list_st (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  194. void * dis_info,
  195. long value,
  196. unsigned int attrs ATTRIBUTE_UNUSED,
  197. bfd_vma pc ATTRIBUTE_UNUSED,
  198. int length ATTRIBUTE_UNUSED)
  199. {
  200. print_register_list (dis_info, value, 0, 1 /* Store. */);
  201. }
  202. static void
  203. print_m4 (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
  204. void * dis_info,
  205. long value,
  206. unsigned int attrs ATTRIBUTE_UNUSED,
  207. bfd_vma pc ATTRIBUTE_UNUSED,
  208. int length ATTRIBUTE_UNUSED)
  209. {
  210. disassemble_info *info = (disassemble_info *) dis_info;
  211. (*info->fprintf_func) (info->stream, "%ld", value);
  212. }
  213. /* -- */