Subversion Repositories Kolibri OS

Rev

Rev 5191 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  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.  
  5.    This file is part of GDB, the GNU Debugger.
  6.  
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 3 of the License, or
  10.    (at your option) any later version.
  11.  
  12.    This program is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with this program; if not, write to the Free Software
  19.    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
  20.    02110-1301, USA.  */
  21.  
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25.  
  26. typedef enum
  27. {
  28.   MSO_unknown,
  29.   /* Double-operand instructions - all repeat .REPEATS times. */
  30.   MSO_mov,      /* dest = src */
  31.   MSO_add,      /* dest += src */
  32.   MSO_addc,     /* dest += src + carry */
  33.   MSO_subc,     /* dest -= (src-1) + carry */
  34.   MSO_sub,      /* dest -= src */
  35.   MSO_cmp,      /* dest - src -> status */
  36.   MSO_dadd,     /* dest += src (as BCD) */
  37.   MSO_bit,      /* dest & src -> status */
  38.   MSO_bic,      /* dest &= ~src (bit clear) */
  39.   MSO_bis,      /* dest |= src (bit set, OR) */
  40.   MSO_xor,      /* dest ^= src */
  41.   MSO_and,      /* dest &= src */
  42.  
  43.   /* Single-operand instructions.  */
  44.   MSO_rrc,      /* Rotate through carry, dest >>= .REPEATS.  */
  45.   MSO_swpb,     /* Swap lower bytes of operand.  */
  46.   MSO_rra,      /* Signed shift dest >>= .REPEATS.  */
  47.   MSO_sxt,      /* Sign extend lower byte.  */
  48.   MSO_push,     /* Push .REPEATS registers (or other op) starting at SRC going towards R0.  */
  49.   MSO_pop,      /* Pop .REPEATS registers starting at DEST going towards R15.  */
  50.   MSO_call,
  51.   MSO_reti,
  52.  
  53.   /* Jumps.  */
  54.   MSO_jmp,      /* PC = SRC if .COND true.  */
  55.  
  56.   /* Extended single-operand instructions.  */
  57.   MSO_rru,      /* Unsigned shift right, dest >>= .REPEATS.  */
  58.  
  59. } MSP430_Opcode_ID;
  60.  
  61. typedef enum
  62. {
  63.   MSP430_Operand_None,
  64.   MSP430_Operand_Immediate,
  65.   MSP430_Operand_Register,
  66.   MSP430_Operand_Indirect,
  67.   MSP430_Operand_Indirect_Postinc
  68. } MSP430_Operand_Type;
  69.  
  70. typedef enum
  71. {
  72.   MSR_0 = 0,
  73.   MSR_PC = 0,
  74.   MSR_SP = 1,
  75.   MSR_SR = 2,
  76.   MSR_CG = 3,
  77.   MSR_None = 16,
  78. } MSP430_Register;
  79.  
  80. typedef struct
  81. {
  82.   MSP430_Operand_Type  type;
  83.   int                  addend;
  84.   MSP430_Register      reg : 8;
  85.   MSP430_Register      reg2 : 8;
  86.   unsigned char        bit_number : 4;
  87.   unsigned char        condition : 3;
  88. } MSP430_Opcode_Operand;
  89.  
  90. typedef enum
  91. {
  92.   MSP430_Byte = 0,
  93.   MSP430_Word,
  94.   MSP430_Addr
  95. } MSP430_Size;
  96.  
  97. /* These numerically match the bit encoding.  */
  98. typedef enum
  99. {
  100.   MSC_nz = 0,
  101.   MSC_z,
  102.   MSC_nc,
  103.   MSC_c,
  104.   MSC_n,
  105.   MSC_ge,
  106.   MSC_l,
  107.   MSC_true,
  108. } MSP430_Condition;
  109.  
  110. #define MSP430_FLAG_C   0x01
  111. #define MSP430_FLAG_Z   0x02
  112. #define MSP430_FLAG_N   0x04
  113. #define MSP430_FLAG_V   0x80
  114.  
  115. typedef struct
  116. {
  117.   int lineno;
  118.   MSP430_Opcode_ID      id;
  119.   unsigned              flags_1:8;      /* These flags are set to '1' by the insn.  */
  120.   unsigned              flags_0:8;      /* These flags are set to '0' by the insn.  */
  121.   unsigned              flags_set:8;    /* These flags are set appropriately by the insn.  */
  122.   unsigned              zc:1;           /* If set, pretend the carry bit is zero.  */
  123.   unsigned              repeat_reg:1;   /* If set, count is in REG[repeats].  */
  124.   unsigned              ofs_430x:1;     /* If set, the offset in any operand is 430x (else use 430 compatibility mode).  */
  125.   unsigned              repeats:5;      /* Contains COUNT-1, or register number.  */
  126.   int                   n_bytes;        /* Opcode size in BYTES.  */
  127.   char *                syntax;
  128.   MSP430_Size           size;           /* Operand size in BITS.  */
  129.   MSP430_Condition      cond;
  130.   /* By convention, these are [0]destination, [1]source.  */
  131.   MSP430_Opcode_Operand op[2];
  132. } MSP430_Opcode_Decoded;
  133.  
  134. int msp430_decode_opcode (unsigned long, MSP430_Opcode_Decoded *, int (*)(void *), void *);
  135.  
  136. #ifdef __cplusplus
  137. }
  138. #endif
  139.