s12z-opc.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /* s12z-dis.h -- Header file for s12z-dis.c and s12z-decode.c
  2. Copyright (C) 2019-2022 Free Software Foundation, Inc.
  3. This file is part of the GNU opcodes library.
  4. This library is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. It is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  11. License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; see the file COPYING3. If not,
  14. see <http://www.gnu.org/licenses/>. */
  15. #ifndef S12Z_OPC_H
  16. #define S12Z_OPC_H
  17. #include <stdbool.h>
  18. #ifdef __cplusplus
  19. extern "C"
  20. {
  21. #endif
  22. /* An abstraction used to read machine code from a source. */
  23. struct mem_read_abstraction_base
  24. {
  25. int (*read) (struct mem_read_abstraction_base *, int, size_t, bfd_byte *);
  26. void (*advance) (struct mem_read_abstraction_base *);
  27. bfd_vma (*posn) (struct mem_read_abstraction_base *);
  28. };
  29. /* Machine code operators.
  30. These *roughly* correspond to opcodes.
  31. But describe their purpose rather than their form. */
  32. enum optr
  33. {
  34. OP_INVALID = 0,
  35. OP_push,
  36. OP_pull,
  37. /* Test and branch. */
  38. OP_tbNE, OP_tbEQ, OP_tbPL, OP_tbMI, OP_tbGT, OP_tbLE,
  39. /* Decrement and branch. */
  40. OP_dbNE, OP_dbEQ, OP_dbPL, OP_dbMI, OP_dbGT, OP_dbLE,
  41. /* Note: sex and exg are the same opcode.
  42. They are mnemonic changes according to the operands. */
  43. OP_sex,
  44. OP_exg,
  45. /* Shifters. */
  46. OP_lsl, OP_lsr,
  47. OP_asl, OP_asr,
  48. OP_rol, OP_ror,
  49. /* Bit field operations. */
  50. OP_bfins, OP_bfext,
  51. OP_trap,
  52. OP_ld,
  53. OP_st,
  54. OP_cmp,
  55. OP_stop,
  56. OP_wai,
  57. OP_sys,
  58. OP_minu,
  59. OP_mins,
  60. OP_maxu,
  61. OP_maxs,
  62. OP_abs,
  63. OP_adc,
  64. OP_bit,
  65. OP_sbc,
  66. OP_rti,
  67. OP_clb,
  68. OP_eor,
  69. OP_sat,
  70. OP_nop,
  71. OP_bgnd,
  72. OP_brclr,
  73. OP_brset,
  74. OP_rts,
  75. OP_lea,
  76. OP_mov,
  77. OP_bra,
  78. OP_bsr,
  79. OP_bhi,
  80. OP_bls,
  81. OP_bcc,
  82. OP_bcs,
  83. OP_bne,
  84. OP_beq,
  85. OP_bvc,
  86. OP_bvs,
  87. OP_bpl,
  88. OP_bmi,
  89. OP_bge,
  90. OP_blt,
  91. OP_bgt,
  92. OP_ble,
  93. OP_inc,
  94. OP_clr,
  95. OP_dec,
  96. OP_add,
  97. OP_sub,
  98. OP_and,
  99. OP_or,
  100. OP_tfr,
  101. OP_jmp,
  102. OP_jsr,
  103. OP_com,
  104. OP_andcc,
  105. OP_neg,
  106. OP_orcc,
  107. OP_bclr,
  108. OP_bset,
  109. OP_btgl,
  110. OP_swi,
  111. OP_mulu,
  112. OP_divu,
  113. OP_modu,
  114. OP_macu,
  115. OP_qmulu,
  116. OP_muls,
  117. OP_divs,
  118. OP_mods,
  119. OP_macs,
  120. OP_qmuls,
  121. OPBASE_mul = 0x4000,
  122. OPBASE_div,
  123. OPBASE_mod,
  124. OPBASE_mac,
  125. OPBASE_qmul,
  126. n_OPS
  127. };
  128. /* Used for operands which mutate their index/base registers.
  129. Eg ld d0, (s+). */
  130. enum op_reg_mutation
  131. {
  132. OPND_RM_NONE,
  133. OPND_RM_PRE_DEC,
  134. OPND_RM_PRE_INC,
  135. OPND_RM_POST_DEC,
  136. OPND_RM_POST_INC
  137. };
  138. /* The class of an operand. */
  139. enum opnd_class
  140. {
  141. OPND_CL_IMMEDIATE,
  142. OPND_CL_MEMORY,
  143. OPND_CL_REGISTER,
  144. OPND_CL_REGISTER_ALL, /* Used only for psh/pul. */
  145. OPND_CL_REGISTER_ALL16, /* Used only for psh/pul. */
  146. OPND_CL_SIMPLE_MEMORY,
  147. OPND_CL_BIT_FIELD
  148. };
  149. /* Base structure of all operands. */
  150. struct operand
  151. {
  152. enum opnd_class cl;
  153. /* OSIZE determines the size of memory access for
  154. the operation in which the operand participates.
  155. It may be -1 which indicates either unknown
  156. (must be determined by other operands) or if
  157. it is not applicable for this operation. */
  158. int osize;
  159. };
  160. /* Immediate operands. Eg: #23 */
  161. struct immediate_operand
  162. {
  163. struct operand parent;
  164. int value;
  165. };
  166. /* Bitfield operands. Used only in bfext and bfins
  167. instructions. */
  168. struct bitfield_operand
  169. {
  170. struct operand parent;
  171. int width;
  172. int offset;
  173. };
  174. /* Register operands. */
  175. struct register_operand
  176. {
  177. struct operand parent;
  178. int reg;
  179. };
  180. /* Simple memory operands. ie, direct memory,
  181. no index, no pre/post inc/dec. May be either relative or absolute.
  182. Eg st d0, 0x123456 */
  183. struct simple_memory_operand
  184. {
  185. struct operand parent;
  186. bfd_vma addr;
  187. bfd_vma base;
  188. bool relative;
  189. };
  190. /* Memory operands. Should be able to represent all memory
  191. operands in the S12Z instruction set which are not simple
  192. memory operands. */
  193. struct memory_operand
  194. {
  195. struct operand parent;
  196. /* True for indirect operands: eg [0x123456] */
  197. bool indirect;
  198. /* The value of any offset. eg 45 in (45,d7) */
  199. int base_offset;
  200. /* Does this operand increment or decrement
  201. its participating registers. Eg (-s) */
  202. enum op_reg_mutation mutation;
  203. /* The number of registers participating in this operand.
  204. For S12Z this is always in the range [0, 6] (but for most
  205. instructions it's <= 2). */
  206. int n_regs;
  207. /* The participating registers. */
  208. int regs[6];
  209. };
  210. /* Decode a single instruction.
  211. OPERATOR, OSIZE, N_OPERANDS and OPERANDS are pointers to
  212. variables which must be provided by the caller.
  213. N_OPERANDS will be incremented by the number of operands read, so
  214. you should assign it to something before calling this function.
  215. OPERANDS must be large enough to contain all operands read
  216. (which may be up to 6).
  217. It is the responsibility of the caller to free all operands
  218. when they are no longer needed.
  219. Returns the number of bytes read. */
  220. int decode_s12z (enum optr *myoperator, short *osize,
  221. int *n_operands, struct operand **operands,
  222. struct mem_read_abstraction_base *);
  223. #ifdef __cplusplus
  224. }
  225. #endif
  226. #endif /* S12Z_OPC_H */