1a2e2270fSchristos /* Opcode decoder for the Renesas RL78 2*02f41505Schristos Copyright (C) 2011-2024 Free Software Foundation, Inc. 3a2e2270fSchristos Written by DJ Delorie <dj@redhat.com> 4a2e2270fSchristos 5a2e2270fSchristos This file is part of GDB, the GNU Debugger and GAS, the GNU Assembler. 6a2e2270fSchristos 7a2e2270fSchristos This program is free software; you can redistribute it and/or modify 8a2e2270fSchristos it under the terms of the GNU General Public License as published by 9a2e2270fSchristos the Free Software Foundation; either version 3 of the License, or 10a2e2270fSchristos (at your option) any later version. 11a2e2270fSchristos 12a2e2270fSchristos This program is distributed in the hope that it will be useful, 13a2e2270fSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of 14a2e2270fSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15a2e2270fSchristos GNU General Public License for more details. 16a2e2270fSchristos 17a2e2270fSchristos You should have received a copy of the GNU General Public License 18a2e2270fSchristos along with this program; if not, write to the Free Software 19a2e2270fSchristos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 20a2e2270fSchristos 02110-1301, USA. */ 21a2e2270fSchristos 22a2e2270fSchristos /* The RL78 decoder in libopcodes is used by the simulator, gdb's 23a2e2270fSchristos analyzer, and the disassembler. Given an opcode data source, it 24a2e2270fSchristos decodes the next opcode into the following structures. */ 25a2e2270fSchristos 26a2e2270fSchristos #ifndef RL78_OPCODES_H_INCLUDED 27a2e2270fSchristos #define RL78_OPCODES_H_INCLUDED 28a2e2270fSchristos 29212397c6Schristos #ifdef __cplusplus 30212397c6Schristos extern "C" { 31212397c6Schristos #endif 32212397c6Schristos 33212397c6Schristos typedef enum { 34212397c6Schristos RL78_ISA_DEFAULT, 35212397c6Schristos RL78_ISA_G10, 36212397c6Schristos RL78_ISA_G13, 37212397c6Schristos RL78_ISA_G14, 38212397c6Schristos } RL78_Dis_Isa; 39212397c6Schristos 40a2e2270fSchristos /* For the purposes of these structures, the RL78 registers are as 41a2e2270fSchristos follows, despite most of these being memory-mapped and 42a2e2270fSchristos bank-switched: */ 43a2e2270fSchristos typedef enum { 44a2e2270fSchristos RL78_Reg_None, 45a2e2270fSchristos /* The order of these matches the encodings. */ 46a2e2270fSchristos RL78_Reg_X, 47a2e2270fSchristos RL78_Reg_A, 48a2e2270fSchristos RL78_Reg_C, 49a2e2270fSchristos RL78_Reg_B, 50a2e2270fSchristos RL78_Reg_E, 51a2e2270fSchristos RL78_Reg_D, 52a2e2270fSchristos RL78_Reg_L, 53a2e2270fSchristos RL78_Reg_H, 54a2e2270fSchristos /* The order of these matches the encodings. */ 55a2e2270fSchristos RL78_Reg_AX, 56a2e2270fSchristos RL78_Reg_BC, 57a2e2270fSchristos RL78_Reg_DE, 58a2e2270fSchristos RL78_Reg_HL, 59a2e2270fSchristos /* Unordered. */ 60a2e2270fSchristos RL78_Reg_SP, 61a2e2270fSchristos RL78_Reg_PSW, 62a2e2270fSchristos RL78_Reg_CS, 63a2e2270fSchristos RL78_Reg_ES, 64a2e2270fSchristos RL78_Reg_PMC, 65a2e2270fSchristos RL78_Reg_MEM 66a2e2270fSchristos } RL78_Register; 67a2e2270fSchristos 68a2e2270fSchristos typedef enum 69a2e2270fSchristos { 70a2e2270fSchristos RL78_Byte = 0, 71a2e2270fSchristos RL78_Word 72a2e2270fSchristos } RL78_Size; 73a2e2270fSchristos 74a2e2270fSchristos typedef enum { 75a2e2270fSchristos RL78_Condition_T, 76a2e2270fSchristos RL78_Condition_F, 77a2e2270fSchristos RL78_Condition_C, 78a2e2270fSchristos RL78_Condition_NC, 79a2e2270fSchristos RL78_Condition_H, 80a2e2270fSchristos RL78_Condition_NH, 81a2e2270fSchristos RL78_Condition_Z, 82a2e2270fSchristos RL78_Condition_NZ 83a2e2270fSchristos } RL78_Condition; 84a2e2270fSchristos 85a2e2270fSchristos typedef enum { 86a2e2270fSchristos RL78_Operand_None = 0, 87a2e2270fSchristos RL78_Operand_Immediate, /* #addend */ 88a2e2270fSchristos RL78_Operand_Register, /* reg */ 89a2e2270fSchristos RL78_Operand_Indirect, /* [reg + reg2 + addend] */ 90a2e2270fSchristos RL78_Operand_Bit, /* reg.bit */ 91a2e2270fSchristos RL78_Operand_BitIndirect, /* [reg+reg2+addend].bit */ 92a2e2270fSchristos RL78_Operand_PreDec, /* [--reg] = push */ 93a2e2270fSchristos RL78_Operand_PostInc /* [reg++] = pop */ 94a2e2270fSchristos } RL78_Operand_Type; 95a2e2270fSchristos 96a2e2270fSchristos typedef enum 97a2e2270fSchristos { 98a2e2270fSchristos RLO_unknown, 99a2e2270fSchristos RLO_add, /* d += s */ 100a2e2270fSchristos RLO_addc, /* d += s + CY */ 101a2e2270fSchristos RLO_and, /* d &= s (byte, word, bit) */ 102a2e2270fSchristos RLO_branch, /* pc = d */ 103a2e2270fSchristos RLO_branch_cond, /* pc = d if cond(src) */ 104a2e2270fSchristos RLO_branch_cond_clear, /* pc = d if cond(src), and clear(src) */ 105a2e2270fSchristos RLO_break, /* BRK */ 106a2e2270fSchristos RLO_call, /* call */ 107a2e2270fSchristos RLO_cmp, /* cmp d, s */ 108a2e2270fSchristos RLO_divhu, /* DIVHU */ 109a2e2270fSchristos RLO_divwu, /* DIVWU */ 110a2e2270fSchristos RLO_halt, /* HALT */ 111a2e2270fSchristos RLO_mov, /* d = s */ 112a2e2270fSchristos RLO_mach, /* MACH */ 113a2e2270fSchristos RLO_machu, /* MACHU */ 114a2e2270fSchristos RLO_mulu, /* MULU */ 115a2e2270fSchristos RLO_mulh, /* MULH */ 116a2e2270fSchristos RLO_mulhu, /* MULHU */ 117a2e2270fSchristos RLO_nop, /* NOP */ 118a2e2270fSchristos RLO_or, /* d |= s */ 119a2e2270fSchristos RLO_ret, /* RET */ 120a2e2270fSchristos RLO_reti, /* RETI */ 121a2e2270fSchristos RLO_rol, /* d <<= s, MSB to LSB and CY */ 122a2e2270fSchristos RLO_rolc, /* d <<= s, MSB to CY, CY, to LSB */ 123a2e2270fSchristos RLO_ror, /* d >>= s, LSB to MSB and CY */ 124a2e2270fSchristos RLO_rorc, /* d >>= s, LSB to CY, CY, to MSB */ 125a2e2270fSchristos RLO_sar, /* d >>= s, signed */ 126a2e2270fSchristos RLO_sel, /* rb = s */ 127a2e2270fSchristos RLO_shr, /* d >>= s, unsigned */ 128a2e2270fSchristos RLO_shl, /* d <<= s */ 129a2e2270fSchristos RLO_skip, /* skip next insn is cond(s) */ 130a2e2270fSchristos RLO_stop, /* STOP */ 131a2e2270fSchristos RLO_sub, /* d -= s */ 132a2e2270fSchristos RLO_subc, /* d -= s - CY */ 133a2e2270fSchristos RLO_xch, /* swap d, s */ 134a2e2270fSchristos RLO_xor, /* d ^= s */ 135a2e2270fSchristos } RL78_Opcode_ID; 136a2e2270fSchristos 137a2e2270fSchristos typedef struct { 138a2e2270fSchristos RL78_Operand_Type type; 139a2e2270fSchristos int addend; 140a2e2270fSchristos RL78_Register reg : 8; 141a2e2270fSchristos RL78_Register reg2 : 8; 142a2e2270fSchristos unsigned char bit_number : 4; 143a2e2270fSchristos unsigned char condition : 3; 144a2e2270fSchristos unsigned char use_es : 1; 145a2e2270fSchristos } RL78_Opcode_Operand; 146a2e2270fSchristos 147a2e2270fSchristos /* PSW flag bits */ 148a2e2270fSchristos #define RL78_PSW_IE 0x80 149a2e2270fSchristos #define RL78_PSW_Z 0x40 150a2e2270fSchristos #define RL78_PSW_RBS1 0x20 151a2e2270fSchristos #define RL78_PSW_AC 0x10 152a2e2270fSchristos #define RL78_PSW_RBS0 0x08 153a2e2270fSchristos #define RL78_PSW_ISP1 0x04 154a2e2270fSchristos #define RL78_PSW_ISP0 0x02 155a2e2270fSchristos #define RL78_PSW_CY 0x01 156a2e2270fSchristos 157a2e2270fSchristos #define RL78_SFR_SP 0xffff8 158a2e2270fSchristos #define RL78_SFR_PSW 0xffffa 159a2e2270fSchristos #define RL78_SFR_CS 0xffffc 160a2e2270fSchristos #define RL78_SFR_ES 0xffffd 161a2e2270fSchristos #define RL78_SFR_PMC 0xffffe 162a2e2270fSchristos #define RL78_SFR_MEM 0xfffff 163a2e2270fSchristos 164a2e2270fSchristos typedef struct 165a2e2270fSchristos { 166a2e2270fSchristos int lineno; 167a2e2270fSchristos RL78_Opcode_ID id:24; 168a2e2270fSchristos unsigned flags:8; /* PSW mask, for side effects only */ 169a2e2270fSchristos int n_bytes; 170a2e2270fSchristos char * syntax; 171a2e2270fSchristos RL78_Size size; 172a2e2270fSchristos /* By convention, these are destination, source. */ 173a2e2270fSchristos RL78_Opcode_Operand op[2]; 174a2e2270fSchristos } RL78_Opcode_Decoded; 175a2e2270fSchristos 176212397c6Schristos int rl78_decode_opcode (unsigned long, RL78_Opcode_Decoded *, int (*)(void *), void *, RL78_Dis_Isa); 177212397c6Schristos 178212397c6Schristos #ifdef __cplusplus 179212397c6Schristos } 180212397c6Schristos #endif 181a2e2270fSchristos 182a2e2270fSchristos #endif 183