• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Opcode decoder for the Renesas RX
2    Copyright (C) 2008-2014 Free Software Foundation, Inc.
3    Written by DJ Delorie <dj@redhat.com>
4 
5    This file is part of GDB, the GNU Debugger and GAS, the GNU Assembler.
6 
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11 
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
20    02110-1301, USA.  */
21 
22 /* The RX decoder in libopcodes is used by the simulator, gdb's
23    analyzer, and the disassembler.  Given an opcode data source,
24    it decodes the next opcode into the following structures.  */
25 
26 typedef enum
27 {
28   RX_AnySize = 0,
29   RX_Byte, /* undefined extension */
30   RX_UByte,
31   RX_SByte,
32   RX_Word, /* undefined extension */
33   RX_UWord,
34   RX_SWord,
35   RX_3Byte,
36   RX_Long,
37 } RX_Size;
38 
39 typedef enum
40 {
41   RX_Operand_None,
42   RX_Operand_Immediate,	/* #addend */
43   RX_Operand_Register,	/* Rn */
44   RX_Operand_Indirect,	/* [Rn + addend] */
45   RX_Operand_Postinc,	/* [Rn+] */
46   RX_Operand_Predec,	/* [-Rn] */
47   RX_Operand_Condition,	/* eq, gtu, etc */
48   RX_Operand_Flag,	/* [UIOSZC] */
49   RX_Operand_TwoReg,	/* [Rn + scale*R2] */
50 } RX_Operand_Type;
51 
52 typedef enum
53 {
54   RXO_unknown,
55   RXO_mov,	/* d = s (signed) */
56   RXO_movbi,	/* d = [s,s2] (signed) */
57   RXO_movbir,	/* [s,s2] = d (signed) */
58   RXO_pushm,	/* s..s2 */
59   RXO_popm,	/* s..s2 */
60   RXO_xchg,	/* s <-> d */
61   RXO_stcc,	/* d = s if cond(s2) */
62   RXO_rtsd,	/* rtsd, 1=imm, 2-0 = reg if reg type */
63 
64   /* These are all either d OP= s or, if s2 is set, d = s OP s2.  Note
65      that d may be "None".  */
66   RXO_and,
67   RXO_or,
68   RXO_xor,
69   RXO_add,
70   RXO_sub,
71   RXO_mul,
72   RXO_div,
73   RXO_divu,
74   RXO_shll,
75   RXO_shar,
76   RXO_shlr,
77 
78   RXO_adc,	/* d = d + s + carry */
79   RXO_sbb,	/* d = d - s - ~carry */
80   RXO_abs,	/* d = |s| */
81   RXO_max,	/* d = max(d,s) */
82   RXO_min,	/* d = min(d,s) */
83   RXO_emul,	/* d:64 = d:32 * s */
84   RXO_emulu,	/* d:64 = d:32 * s (unsigned) */
85 
86   RXO_rolc,	/* d <<= 1 through carry */
87   RXO_rorc,	/* d >>= 1 through carry*/
88   RXO_rotl,	/* d <<= #s without carry */
89   RXO_rotr,	/* d >>= #s without carry*/
90   RXO_revw,	/* d = revw(s) */
91   RXO_revl,	/* d = revl(s) */
92   RXO_branch,	/* pc = d if cond(s) */
93   RXO_branchrel,/* pc += d if cond(s) */
94   RXO_jsr,	/* pc = d */
95   RXO_jsrrel,	/* pc += d */
96   RXO_rts,
97   RXO_nop,
98   RXO_nop2,
99   RXO_nop3,
100 
101   RXO_scmpu,
102   RXO_smovu,
103   RXO_smovb,
104   RXO_suntil,
105   RXO_swhile,
106   RXO_smovf,
107   RXO_sstr,
108 
109   RXO_rmpa,
110   RXO_mulhi,
111   RXO_mullo,
112   RXO_machi,
113   RXO_maclo,
114   RXO_mvtachi,
115   RXO_mvtaclo,
116   RXO_mvfachi,
117   RXO_mvfacmi,
118   RXO_mvfaclo,
119   RXO_racw,
120 
121   RXO_sat,	/* sat(d) */
122   RXO_satr,
123 
124   RXO_fadd,	/* d op= s */
125   RXO_fcmp,
126   RXO_fsub,
127   RXO_ftoi,
128   RXO_fmul,
129   RXO_fdiv,
130   RXO_round,
131   RXO_itof,
132 
133   RXO_bset,	/* d |= (1<<s) */
134   RXO_bclr,	/* d &= ~(1<<s) */
135   RXO_btst,	/* s & (1<<s2) */
136   RXO_bnot,	/* d ^= (1<<s) */
137   RXO_bmcc,	/* d<s> = cond(s2) */
138 
139   RXO_clrpsw,	/* flag index in d */
140   RXO_setpsw,	/* flag index in d */
141   RXO_mvtipl,	/* new IPL in s */
142 
143   RXO_rtfi,
144   RXO_rte,
145   RXO_rtd,	/* undocumented */
146   RXO_brk,
147   RXO_dbt,	/* undocumented */
148   RXO_int,	/* vector id in s */
149   RXO_stop,
150   RXO_wait,
151 
152   RXO_sccnd,	/* d = cond(s) ? 1 : 0 */
153 } RX_Opcode_ID;
154 
155 /* Condition bitpatterns, as registers.  */
156 #define RXC_eq		0
157 #define RXC_z		0
158 #define RXC_ne		1
159 #define RXC_nz		1
160 #define RXC_c		2
161 #define RXC_nc		3
162 #define RXC_gtu		4
163 #define RXC_leu		5
164 #define RXC_pz		6
165 #define RXC_n		7
166 #define RXC_ge		8
167 #define RXC_lt		9
168 #define RXC_gt		10
169 #define RXC_le		11
170 #define RXC_o		12
171 #define RXC_no		13
172 #define RXC_always	14
173 #define RXC_never	15
174 
175 typedef struct
176 {
177   RX_Operand_Type  type;
178   int              reg;
179   int              addend;
180   RX_Size          size;
181 } RX_Opcode_Operand;
182 
183 typedef struct
184 {
185   RX_Opcode_ID      id;
186   int               n_bytes;
187   int               prefix;
188   char *            syntax;
189   RX_Size           size;
190   /* By convention, these are destination, source1, source2.  */
191   RX_Opcode_Operand op[3];
192 
193   /* The logic here is:
194      newflags = (oldflags & ~(int)flags_0) | flags_1 | (op_flags & flags_s)
195      Only the O, S, Z, and C flags are affected.  */
196   char flags_0; /* This also clears out flags-to-be-set.  */
197   char flags_1;
198   char flags_s;
199 } RX_Opcode_Decoded;
200 
201 /* Within the syntax, %c-style format specifiers are as follows:
202 
203    %% = '%' character
204    %0 = operand[0] (destination)
205    %1 = operand[1] (source)
206    %2 = operand[2] (2nd source)
207    %s = operation size (b/w/l)
208    %SN = operand size [N] (N=0,1,2)
209    %aN = op[N] as an address (N=0,1,2)
210 
211    Register numbers 0..15 are general registers.  16..31 are control
212    registers.  32..47 are condition codes.  */
213 
214 int rx_decode_opcode (unsigned long, RX_Opcode_Decoded *, int (*)(void *), void *);
215