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