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