msp430-decode.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* Opcode decoder for the TI MSP430
  2. Copyright (C) 2012-2015 Free Software Foundation, Inc.
  3. Written by DJ Delorie <dj@redhat.com>
  4. This file is part of GDB, the GNU Debugger.
  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. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. typedef enum
  21. {
  22. MSO_unknown,
  23. /* Double-operand instructions - all repeat .REPEATS times. */
  24. MSO_mov, /* dest = src */
  25. MSO_add, /* dest += src */
  26. MSO_addc, /* dest += src + carry */
  27. MSO_subc, /* dest -= (src-1) + carry */
  28. MSO_sub, /* dest -= src */
  29. MSO_cmp, /* dest - src -> status */
  30. MSO_dadd, /* dest += src (as BCD) */
  31. MSO_bit, /* dest & src -> status */
  32. MSO_bic, /* dest &= ~src (bit clear) */
  33. MSO_bis, /* dest |= src (bit set, OR) */
  34. MSO_xor, /* dest ^= src */
  35. MSO_and, /* dest &= src */
  36. /* Single-operand instructions. */
  37. MSO_rrc, /* Rotate through carry, dest >>= .REPEATS. */
  38. MSO_swpb, /* Swap lower bytes of operand. */
  39. MSO_rra, /* Signed shift dest >>= .REPEATS. */
  40. MSO_sxt, /* Sign extend lower byte. */
  41. MSO_push, /* Push .REPEATS registers (or other op) starting at SRC going towards R0. */
  42. MSO_pop, /* Pop .REPEATS registers starting at DEST going towards R15. */
  43. MSO_call,
  44. MSO_reti,
  45. /* Jumps. */
  46. MSO_jmp, /* PC = SRC if .COND true. */
  47. /* Extended single-operand instructions. */
  48. MSO_rru, /* Unsigned shift right, dest >>= .REPEATS. */
  49. } MSP430_Opcode_ID;
  50. typedef enum
  51. {
  52. MSP430_Operand_None,
  53. MSP430_Operand_Immediate,
  54. MSP430_Operand_Register,
  55. MSP430_Operand_Indirect,
  56. MSP430_Operand_Indirect_Postinc
  57. } MSP430_Operand_Type;
  58. typedef enum
  59. {
  60. MSR_0 = 0,
  61. MSR_PC = 0,
  62. MSR_SP = 1,
  63. MSR_SR = 2,
  64. MSR_CG = 3,
  65. MSR_None = 16,
  66. } MSP430_Register;
  67. typedef struct
  68. {
  69. MSP430_Operand_Type type;
  70. int addend;
  71. MSP430_Register reg : 8;
  72. MSP430_Register reg2 : 8;
  73. unsigned char bit_number : 4;
  74. unsigned char condition : 3;
  75. } MSP430_Opcode_Operand;
  76. typedef enum
  77. {
  78. MSP430_Byte = 0,
  79. MSP430_Word,
  80. MSP430_Addr
  81. } MSP430_Size;
  82. /* These numerically match the bit encoding. */
  83. typedef enum
  84. {
  85. MSC_nz = 0,
  86. MSC_z,
  87. MSC_nc,
  88. MSC_c,
  89. MSC_n,
  90. MSC_ge,
  91. MSC_l,
  92. MSC_true,
  93. } MSP430_Condition;
  94. #define MSP430_FLAG_C 0x01
  95. #define MSP430_FLAG_Z 0x02
  96. #define MSP430_FLAG_N 0x04
  97. #define MSP430_FLAG_V 0x80
  98. typedef struct
  99. {
  100. int lineno;
  101. MSP430_Opcode_ID id;
  102. unsigned flags_1:8; /* These flags are set to '1' by the insn. */
  103. unsigned flags_0:8; /* These flags are set to '0' by the insn. */
  104. unsigned flags_set:8; /* These flags are set appropriately by the insn. */
  105. unsigned zc:1; /* If set, pretend the carry bit is zero. */
  106. unsigned repeat_reg:1; /* If set, count is in REG[repeats]. */
  107. unsigned ofs_430x:1; /* If set, the offset in any operand is 430x (else use 430 compatibility mode). */
  108. unsigned repeats:5; /* Contains COUNT-1, or register number. */
  109. int n_bytes; /* Opcode size in BYTES. */
  110. char * syntax;
  111. MSP430_Size size; /* Operand size in BITS. */
  112. MSP430_Condition cond;
  113. /* By convention, these are [0]destination, [1]source. */
  114. MSP430_Opcode_Operand op[2];
  115. } MSP430_Opcode_Decoded;
  116. int msp430_decode_opcode (unsigned long, MSP430_Opcode_Decoded *, int (*)(void *), void *);
  117. #ifdef __cplusplus
  118. }
  119. #endif