rl78.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* Opcode decoder for the Renesas RL78
  2. Copyright (C) 2011-2015 Free Software Foundation, Inc.
  3. Written by DJ Delorie <dj@redhat.com>
  4. This file is part of GDB, the GNU Debugger and GAS, the GNU Assembler.
  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, MA
  16. 02110-1301, USA. */
  17. /* The RL78 decoder in libopcodes is used by the simulator, gdb's
  18. analyzer, and the disassembler. Given an opcode data source, it
  19. decodes the next opcode into the following structures. */
  20. #ifndef RL78_OPCODES_H_INCLUDED
  21. #define RL78_OPCODES_H_INCLUDED
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. typedef enum {
  26. RL78_ISA_DEFAULT,
  27. RL78_ISA_G10,
  28. RL78_ISA_G13,
  29. RL78_ISA_G14,
  30. } RL78_Dis_Isa;
  31. /* For the purposes of these structures, the RL78 registers are as
  32. follows, despite most of these being memory-mapped and
  33. bank-switched: */
  34. typedef enum {
  35. RL78_Reg_None,
  36. /* The order of these matches the encodings. */
  37. RL78_Reg_X,
  38. RL78_Reg_A,
  39. RL78_Reg_C,
  40. RL78_Reg_B,
  41. RL78_Reg_E,
  42. RL78_Reg_D,
  43. RL78_Reg_L,
  44. RL78_Reg_H,
  45. /* The order of these matches the encodings. */
  46. RL78_Reg_AX,
  47. RL78_Reg_BC,
  48. RL78_Reg_DE,
  49. RL78_Reg_HL,
  50. /* Unordered. */
  51. RL78_Reg_SP,
  52. RL78_Reg_PSW,
  53. RL78_Reg_CS,
  54. RL78_Reg_ES,
  55. RL78_Reg_PMC,
  56. RL78_Reg_MEM
  57. } RL78_Register;
  58. typedef enum
  59. {
  60. RL78_Byte = 0,
  61. RL78_Word
  62. } RL78_Size;
  63. typedef enum {
  64. RL78_Condition_T,
  65. RL78_Condition_F,
  66. RL78_Condition_C,
  67. RL78_Condition_NC,
  68. RL78_Condition_H,
  69. RL78_Condition_NH,
  70. RL78_Condition_Z,
  71. RL78_Condition_NZ
  72. } RL78_Condition;
  73. typedef enum {
  74. RL78_Operand_None = 0,
  75. RL78_Operand_Immediate, /* #addend */
  76. RL78_Operand_Register, /* reg */
  77. RL78_Operand_Indirect, /* [reg + reg2 + addend] */
  78. RL78_Operand_Bit, /* reg.bit */
  79. RL78_Operand_BitIndirect, /* [reg+reg2+addend].bit */
  80. RL78_Operand_PreDec, /* [--reg] = push */
  81. RL78_Operand_PostInc /* [reg++] = pop */
  82. } RL78_Operand_Type;
  83. typedef enum
  84. {
  85. RLO_unknown,
  86. RLO_add, /* d += s */
  87. RLO_addc, /* d += s + CY */
  88. RLO_and, /* d &= s (byte, word, bit) */
  89. RLO_branch, /* pc = d */
  90. RLO_branch_cond, /* pc = d if cond(src) */
  91. RLO_branch_cond_clear, /* pc = d if cond(src), and clear(src) */
  92. RLO_break, /* BRK */
  93. RLO_call, /* call */
  94. RLO_cmp, /* cmp d, s */
  95. RLO_divhu, /* DIVHU */
  96. RLO_divwu, /* DIVWU */
  97. RLO_halt, /* HALT */
  98. RLO_mov, /* d = s */
  99. RLO_mach, /* MACH */
  100. RLO_machu, /* MACHU */
  101. RLO_mulu, /* MULU */
  102. RLO_mulh, /* MULH */
  103. RLO_mulhu, /* MULHU */
  104. RLO_nop, /* NOP */
  105. RLO_or, /* d |= s */
  106. RLO_ret, /* RET */
  107. RLO_reti, /* RETI */
  108. RLO_rol, /* d <<= s, MSB to LSB and CY */
  109. RLO_rolc, /* d <<= s, MSB to CY, CY, to LSB */
  110. RLO_ror, /* d >>= s, LSB to MSB and CY */
  111. RLO_rorc, /* d >>= s, LSB to CY, CY, to MSB */
  112. RLO_sar, /* d >>= s, signed */
  113. RLO_sel, /* rb = s */
  114. RLO_shr, /* d >>= s, unsigned */
  115. RLO_shl, /* d <<= s */
  116. RLO_skip, /* skip next insn is cond(s) */
  117. RLO_stop, /* STOP */
  118. RLO_sub, /* d -= s */
  119. RLO_subc, /* d -= s - CY */
  120. RLO_xch, /* swap d, s */
  121. RLO_xor, /* d ^= s */
  122. } RL78_Opcode_ID;
  123. typedef struct {
  124. RL78_Operand_Type type;
  125. int addend;
  126. RL78_Register reg : 8;
  127. RL78_Register reg2 : 8;
  128. unsigned char bit_number : 4;
  129. unsigned char condition : 3;
  130. unsigned char use_es : 1;
  131. } RL78_Opcode_Operand;
  132. /* PSW flag bits */
  133. #define RL78_PSW_IE 0x80
  134. #define RL78_PSW_Z 0x40
  135. #define RL78_PSW_RBS1 0x20
  136. #define RL78_PSW_AC 0x10
  137. #define RL78_PSW_RBS0 0x08
  138. #define RL78_PSW_ISP1 0x04
  139. #define RL78_PSW_ISP0 0x02
  140. #define RL78_PSW_CY 0x01
  141. #define RL78_SFR_SP 0xffff8
  142. #define RL78_SFR_PSW 0xffffa
  143. #define RL78_SFR_CS 0xffffc
  144. #define RL78_SFR_ES 0xffffd
  145. #define RL78_SFR_PMC 0xffffe
  146. #define RL78_SFR_MEM 0xfffff
  147. typedef struct
  148. {
  149. int lineno;
  150. RL78_Opcode_ID id:24;
  151. unsigned flags:8; /* PSW mask, for side effects only */
  152. int n_bytes;
  153. char * syntax;
  154. RL78_Size size;
  155. /* By convention, these are destination, source. */
  156. RL78_Opcode_Operand op[2];
  157. } RL78_Opcode_Decoded;
  158. int rl78_decode_opcode (unsigned long, RL78_Opcode_Decoded *, int (*)(void *), void *, RL78_Dis_Isa);
  159. #ifdef __cplusplus
  160. }
  161. #endif
  162. #endif