175fd0b74Schristos /* Opcode decoder for the TI MSP430 2*e992f068Schristos Copyright (C) 2012-2022 Free Software Foundation, Inc. 375fd0b74Schristos Written by DJ Delorie <dj@redhat.com> 475fd0b74Schristos 575fd0b74Schristos This file is part of GDB, the GNU Debugger. 675fd0b74Schristos 775fd0b74Schristos This program is free software; you can redistribute it and/or modify 875fd0b74Schristos it under the terms of the GNU General Public License as published by 975fd0b74Schristos the Free Software Foundation; either version 3 of the License, or 1075fd0b74Schristos (at your option) any later version. 1175fd0b74Schristos 1275fd0b74Schristos This program is distributed in the hope that it will be useful, 1375fd0b74Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 1475fd0b74Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1575fd0b74Schristos GNU General Public License for more details. 1675fd0b74Schristos 1775fd0b74Schristos You should have received a copy of the GNU General Public License 1875fd0b74Schristos along with this program; if not, write to the Free Software 1975fd0b74Schristos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 2075fd0b74Schristos 02110-1301, USA. */ 2175fd0b74Schristos 2275fd0b74Schristos #ifdef __cplusplus 2375fd0b74Schristos extern "C" { 2475fd0b74Schristos #endif 2575fd0b74Schristos 2675fd0b74Schristos typedef enum 2775fd0b74Schristos { 2875fd0b74Schristos MSO_unknown, 2975fd0b74Schristos /* Double-operand instructions - all repeat .REPEATS times. */ 3075fd0b74Schristos MSO_mov, /* dest = src */ 3175fd0b74Schristos MSO_add, /* dest += src */ 3275fd0b74Schristos MSO_addc, /* dest += src + carry */ 3375fd0b74Schristos MSO_subc, /* dest -= (src-1) + carry */ 3475fd0b74Schristos MSO_sub, /* dest -= src */ 3575fd0b74Schristos MSO_cmp, /* dest - src -> status */ 3675fd0b74Schristos MSO_dadd, /* dest += src (as BCD) */ 3775fd0b74Schristos MSO_bit, /* dest & src -> status */ 3875fd0b74Schristos MSO_bic, /* dest &= ~src (bit clear) */ 3975fd0b74Schristos MSO_bis, /* dest |= src (bit set, OR) */ 4075fd0b74Schristos MSO_xor, /* dest ^= src */ 4175fd0b74Schristos MSO_and, /* dest &= src */ 4275fd0b74Schristos 4375fd0b74Schristos /* Single-operand instructions. */ 4475fd0b74Schristos MSO_rrc, /* Rotate through carry, dest >>= .REPEATS. */ 4575fd0b74Schristos MSO_swpb, /* Swap lower bytes of operand. */ 4675fd0b74Schristos MSO_rra, /* Signed shift dest >>= .REPEATS. */ 4775fd0b74Schristos MSO_sxt, /* Sign extend lower byte. */ 4875fd0b74Schristos MSO_push, /* Push .REPEATS registers (or other op) starting at SRC going towards R0. */ 4975fd0b74Schristos MSO_pop, /* Pop .REPEATS registers starting at DEST going towards R15. */ 5075fd0b74Schristos MSO_call, 5175fd0b74Schristos MSO_reti, 5275fd0b74Schristos 5375fd0b74Schristos /* Jumps. */ 5475fd0b74Schristos MSO_jmp, /* PC = SRC if .COND true. */ 5575fd0b74Schristos 5675fd0b74Schristos /* Extended single-operand instructions. */ 5775fd0b74Schristos MSO_rru, /* Unsigned shift right, dest >>= .REPEATS. */ 5875fd0b74Schristos 5975fd0b74Schristos } MSP430_Opcode_ID; 6075fd0b74Schristos 6175fd0b74Schristos typedef enum 6275fd0b74Schristos { 6375fd0b74Schristos MSP430_Operand_None, 6475fd0b74Schristos MSP430_Operand_Immediate, 6575fd0b74Schristos MSP430_Operand_Register, 6675fd0b74Schristos MSP430_Operand_Indirect, 6775fd0b74Schristos MSP430_Operand_Indirect_Postinc 6875fd0b74Schristos } MSP430_Operand_Type; 6975fd0b74Schristos 7075fd0b74Schristos typedef enum 7175fd0b74Schristos { 7275fd0b74Schristos MSR_0 = 0, 7375fd0b74Schristos MSR_PC = 0, 7475fd0b74Schristos MSR_SP = 1, 7575fd0b74Schristos MSR_SR = 2, 7675fd0b74Schristos MSR_CG = 3, 7775fd0b74Schristos MSR_None = 16, 7875fd0b74Schristos } MSP430_Register; 7975fd0b74Schristos 8075fd0b74Schristos typedef struct 8175fd0b74Schristos { 8275fd0b74Schristos MSP430_Operand_Type type; 8375fd0b74Schristos int addend; 8475fd0b74Schristos MSP430_Register reg : 8; 8575fd0b74Schristos MSP430_Register reg2 : 8; 8675fd0b74Schristos unsigned char bit_number : 4; 8775fd0b74Schristos unsigned char condition : 3; 8875fd0b74Schristos } MSP430_Opcode_Operand; 8975fd0b74Schristos 9075fd0b74Schristos /* These numerically match the bit encoding. */ 9175fd0b74Schristos typedef enum 9275fd0b74Schristos { 9375fd0b74Schristos MSC_nz = 0, 9475fd0b74Schristos MSC_z, 9575fd0b74Schristos MSC_nc, 9675fd0b74Schristos MSC_c, 9775fd0b74Schristos MSC_n, 9875fd0b74Schristos MSC_ge, 9975fd0b74Schristos MSC_l, 10075fd0b74Schristos MSC_true, 10175fd0b74Schristos } MSP430_Condition; 10275fd0b74Schristos 10375fd0b74Schristos #define MSP430_FLAG_C 0x01 10475fd0b74Schristos #define MSP430_FLAG_Z 0x02 10575fd0b74Schristos #define MSP430_FLAG_N 0x04 10675fd0b74Schristos #define MSP430_FLAG_V 0x80 10775fd0b74Schristos 10875fd0b74Schristos typedef struct 10975fd0b74Schristos { 11075fd0b74Schristos int lineno; 11175fd0b74Schristos MSP430_Opcode_ID id; 11275fd0b74Schristos unsigned flags_1:8; /* These flags are set to '1' by the insn. */ 11375fd0b74Schristos unsigned flags_0:8; /* These flags are set to '0' by the insn. */ 11475fd0b74Schristos unsigned flags_set:8; /* These flags are set appropriately by the insn. */ 11575fd0b74Schristos unsigned zc:1; /* If set, pretend the carry bit is zero. */ 11675fd0b74Schristos unsigned repeat_reg:1; /* If set, count is in REG[repeats]. */ 11775fd0b74Schristos unsigned ofs_430x:1; /* If set, the offset in any operand is 430x (else use 430 compatibility mode). */ 11875fd0b74Schristos unsigned repeats:5; /* Contains COUNT-1, or register number. */ 11975fd0b74Schristos int n_bytes; /* Opcode size in BYTES. */ 12075fd0b74Schristos char * syntax; 12175fd0b74Schristos int size; /* Operand size in BITS. */ 12275fd0b74Schristos MSP430_Condition cond; 12375fd0b74Schristos /* By convention, these are [0]destination, [1]source. */ 12475fd0b74Schristos MSP430_Opcode_Operand op[2]; 12575fd0b74Schristos } MSP430_Opcode_Decoded; 12675fd0b74Schristos 12775fd0b74Schristos int msp430_decode_opcode (unsigned long, MSP430_Opcode_Decoded *, int (*)(void *), void *); 12875fd0b74Schristos 12975fd0b74Schristos #ifdef __cplusplus 13075fd0b74Schristos } 13175fd0b74Schristos #endif 132