xref: /netbsd-src/external/gpl3/gdb/dist/include/opcode/msp430-decode.h (revision aab831cebf6361fb2b518a47c70732e608d9abd2)
103467a24Schristos /* Opcode decoder for the TI MSP430
2*aab831ceSchristos    Copyright (C) 2012-2024 Free Software Foundation, Inc.
303467a24Schristos    Written by DJ Delorie <dj@redhat.com>
403467a24Schristos 
503467a24Schristos    This file is part of GDB, the GNU Debugger.
603467a24Schristos 
703467a24Schristos    This program is free software; you can redistribute it and/or modify
803467a24Schristos    it under the terms of the GNU General Public License as published by
903467a24Schristos    the Free Software Foundation; either version 3 of the License, or
1003467a24Schristos    (at your option) any later version.
1103467a24Schristos 
1203467a24Schristos    This program is distributed in the hope that it will be useful,
1303467a24Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
1403467a24Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1503467a24Schristos    GNU General Public License for more details.
1603467a24Schristos 
1703467a24Schristos    You should have received a copy of the GNU General Public License
1803467a24Schristos    along with this program; if not, write to the Free Software
1903467a24Schristos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
2003467a24Schristos    02110-1301, USA.  */
2103467a24Schristos 
22212397c6Schristos #ifdef __cplusplus
23212397c6Schristos extern "C" {
24212397c6Schristos #endif
25212397c6Schristos 
2603467a24Schristos typedef enum
2703467a24Schristos {
2803467a24Schristos   MSO_unknown,
2903467a24Schristos   /* Double-operand instructions - all repeat .REPEATS times. */
3003467a24Schristos   MSO_mov,	/* dest = src */
3103467a24Schristos   MSO_add,	/* dest += src */
3203467a24Schristos   MSO_addc,	/* dest += src + carry */
3303467a24Schristos   MSO_subc,	/* dest -= (src-1) + carry */
3403467a24Schristos   MSO_sub,	/* dest -= src */
3503467a24Schristos   MSO_cmp,	/* dest - src -> status */
3603467a24Schristos   MSO_dadd,	/* dest += src (as BCD) */
3703467a24Schristos   MSO_bit,	/* dest & src -> status */
3803467a24Schristos   MSO_bic,	/* dest &= ~src (bit clear) */
3903467a24Schristos   MSO_bis,	/* dest |= src (bit set, OR) */
4003467a24Schristos   MSO_xor,	/* dest ^= src */
4103467a24Schristos   MSO_and,	/* dest &= src */
4203467a24Schristos 
4303467a24Schristos   /* Single-operand instructions.  */
4403467a24Schristos   MSO_rrc,	/* Rotate through carry, dest >>= .REPEATS.  */
4503467a24Schristos   MSO_swpb,	/* Swap lower bytes of operand.  */
4603467a24Schristos   MSO_rra,	/* Signed shift dest >>= .REPEATS.  */
4703467a24Schristos   MSO_sxt,	/* Sign extend lower byte.  */
4803467a24Schristos   MSO_push,	/* Push .REPEATS registers (or other op) starting at SRC going towards R0.  */
4903467a24Schristos   MSO_pop,	/* Pop .REPEATS registers starting at DEST going towards R15.  */
5003467a24Schristos   MSO_call,
5103467a24Schristos   MSO_reti,
5203467a24Schristos 
5303467a24Schristos   /* Jumps.  */
5403467a24Schristos   MSO_jmp,	/* PC = SRC if .COND true.  */
5503467a24Schristos 
5603467a24Schristos   /* Extended single-operand instructions.  */
5703467a24Schristos   MSO_rru,	/* Unsigned shift right, dest >>= .REPEATS.  */
5803467a24Schristos 
5903467a24Schristos } MSP430_Opcode_ID;
6003467a24Schristos 
6103467a24Schristos typedef enum
6203467a24Schristos {
6303467a24Schristos   MSP430_Operand_None,
6403467a24Schristos   MSP430_Operand_Immediate,
6503467a24Schristos   MSP430_Operand_Register,
6603467a24Schristos   MSP430_Operand_Indirect,
6703467a24Schristos   MSP430_Operand_Indirect_Postinc
6803467a24Schristos } MSP430_Operand_Type;
6903467a24Schristos 
7003467a24Schristos typedef enum
7103467a24Schristos {
7203467a24Schristos   MSR_0 = 0,
7303467a24Schristos   MSR_PC = 0,
7403467a24Schristos   MSR_SP = 1,
7503467a24Schristos   MSR_SR = 2,
7603467a24Schristos   MSR_CG = 3,
7703467a24Schristos   MSR_None = 16,
7803467a24Schristos } MSP430_Register;
7903467a24Schristos 
8003467a24Schristos typedef struct
8103467a24Schristos {
8203467a24Schristos   MSP430_Operand_Type  type;
8303467a24Schristos   int                  addend;
8403467a24Schristos   MSP430_Register      reg : 8;
8503467a24Schristos   MSP430_Register      reg2 : 8;
8603467a24Schristos   unsigned char	       bit_number : 4;
8703467a24Schristos   unsigned char	       condition : 3;
8803467a24Schristos } MSP430_Opcode_Operand;
8903467a24Schristos 
9003467a24Schristos /* These numerically match the bit encoding.  */
9103467a24Schristos typedef enum
9203467a24Schristos {
9303467a24Schristos   MSC_nz = 0,
9403467a24Schristos   MSC_z,
9503467a24Schristos   MSC_nc,
9603467a24Schristos   MSC_c,
9703467a24Schristos   MSC_n,
9803467a24Schristos   MSC_ge,
9903467a24Schristos   MSC_l,
10003467a24Schristos   MSC_true,
10103467a24Schristos } MSP430_Condition;
10203467a24Schristos 
10303467a24Schristos #define MSP430_FLAG_C	0x01
10403467a24Schristos #define MSP430_FLAG_Z	0x02
10503467a24Schristos #define MSP430_FLAG_N	0x04
10603467a24Schristos #define MSP430_FLAG_V	0x80
10703467a24Schristos 
10803467a24Schristos typedef struct
10903467a24Schristos {
11003467a24Schristos   int lineno;
11103467a24Schristos   MSP430_Opcode_ID	id;
11203467a24Schristos   unsigned		flags_1:8;	/* These flags are set to '1' by the insn.  */
11303467a24Schristos   unsigned		flags_0:8;	/* These flags are set to '0' by the insn.  */
11403467a24Schristos   unsigned		flags_set:8;	/* These flags are set appropriately by the insn.  */
11503467a24Schristos   unsigned		zc:1;		/* If set, pretend the carry bit is zero.  */
11603467a24Schristos   unsigned		repeat_reg:1;	/* If set, count is in REG[repeats].  */
11703467a24Schristos   unsigned		ofs_430x:1;	/* If set, the offset in any operand is 430x (else use 430 compatibility mode).  */
11803467a24Schristos   unsigned		repeats:5;	/* Contains COUNT-1, or register number.  */
11903467a24Schristos   int			n_bytes;	/* Opcode size in BYTES.  */
12003467a24Schristos   char *		syntax;
121ba340e45Schristos   int			size;		/* Operand size in BITS.  */
12203467a24Schristos   MSP430_Condition	cond;
12303467a24Schristos   /* By convention, these are [0]destination, [1]source.  */
12403467a24Schristos   MSP430_Opcode_Operand	op[2];
12503467a24Schristos } MSP430_Opcode_Decoded;
12603467a24Schristos 
12703467a24Schristos int msp430_decode_opcode (unsigned long, MSP430_Opcode_Decoded *, int (*)(void *), void *);
128212397c6Schristos 
129212397c6Schristos #ifdef __cplusplus
130212397c6Schristos }
131212397c6Schristos #endif
132