xstormy16.opc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* XSTORMY16 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 xstormy16.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. /* We can't use the default hash size because many bits are used by
  33. operands. */
  34. #define CGEN_DIS_HASH_SIZE 1
  35. #define CGEN_DIS_HASH(buf, value) 0
  36. /* -- */
  37. /* -- asm.c */
  38. /* The machine-independent code doesn't know how to disambiguate
  39. mov (foo),r3
  40. and
  41. mov (r2),r3
  42. where 'foo' is a label. This helps it out. */
  43. static const char *
  44. parse_mem8 (CGEN_CPU_DESC cd,
  45. const char **strp,
  46. int opindex,
  47. unsigned long *valuep)
  48. {
  49. if (**strp == '(')
  50. {
  51. const char *s = *strp;
  52. if (s[1] == '-' && s[2] == '-')
  53. return _("Bad register in preincrement");
  54. while (ISALNUM (*++s))
  55. ;
  56. if (s[0] == '+' && s[1] == '+' && (s[2] == ')' || s[2] == ','))
  57. return _("Bad register in postincrement");
  58. if (s[0] == ',' || s[0] == ')')
  59. return _("Bad register name");
  60. }
  61. else if (cgen_parse_keyword (cd, strp, & xstormy16_cgen_opval_gr_names,
  62. (long *) valuep) == NULL)
  63. return _("Label conflicts with register name");
  64. else if (strncasecmp (*strp, "rx,", 3) == 0
  65. || strncasecmp (*strp, "rxl,", 3) == 0
  66. || strncasecmp (*strp, "rxh,", 3) == 0)
  67. return _("Label conflicts with `Rx'");
  68. else if (**strp == '#')
  69. return _("Bad immediate expression");
  70. return cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
  71. }
  72. /* For the add and subtract instructions, there are two immediate forms,
  73. one for small operands and one for large ones. We want to use
  74. the small one when possible, but we do not want to generate relocs
  75. of the small size. This is somewhat tricky. */
  76. static const char *
  77. parse_small_immediate (CGEN_CPU_DESC cd,
  78. const char **strp,
  79. int opindex,
  80. unsigned long *valuep)
  81. {
  82. bfd_vma value;
  83. enum cgen_parse_operand_result result;
  84. const char *errmsg;
  85. if (**strp == '@')
  86. return _("No relocation for small immediate");
  87. errmsg = (* cd->parse_operand_fn)
  88. (cd, CGEN_PARSE_OPERAND_INTEGER, strp, opindex, BFD_RELOC_NONE,
  89. & result, & value);
  90. if (errmsg)
  91. return errmsg;
  92. if (result != CGEN_PARSE_OPERAND_RESULT_NUMBER)
  93. return _("Small operand was not an immediate number");
  94. *valuep = value;
  95. return NULL;
  96. }
  97. /* Literal scan be either a normal literal, a @hi() or @lo relocation. */
  98. static const char *
  99. parse_immediate16 (CGEN_CPU_DESC cd,
  100. const char **strp,
  101. int opindex,
  102. unsigned long *valuep)
  103. {
  104. const char *errmsg;
  105. enum cgen_parse_operand_result result;
  106. bfd_reloc_code_real_type code = BFD_RELOC_NONE;
  107. bfd_vma value;
  108. if (strncmp (*strp, "@hi(", 4) == 0)
  109. {
  110. *strp += 4;
  111. code = BFD_RELOC_HI16;
  112. }
  113. else
  114. if (strncmp (*strp, "@lo(", 4) == 0)
  115. {
  116. *strp += 4;
  117. code = BFD_RELOC_LO16;
  118. }
  119. if (code == BFD_RELOC_NONE)
  120. errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
  121. else
  122. {
  123. errmsg = cgen_parse_address (cd, strp, opindex, code, &result, &value);
  124. if ((errmsg == NULL) &&
  125. (result != CGEN_PARSE_OPERAND_RESULT_QUEUED))
  126. errmsg = _("Operand is not a symbol");
  127. *valuep = value;
  128. if ((code == BFD_RELOC_HI16 || code == BFD_RELOC_LO16)
  129. && **strp == ')')
  130. *strp += 1;
  131. else
  132. {
  133. errmsg = _("Syntax error: No trailing ')'");
  134. return errmsg;
  135. }
  136. }
  137. return errmsg;
  138. }
  139. /* -- */