ubsan: xgate: left shift of negative value
[deliverable/binutils-gdb.git] / opcodes / s12z-opc.h
CommitLineData
ef1ad42b 1/* s12z-dis.h -- Header file for s12z-dis.c and s12z-decode.c
b3adc24a 2 Copyright (C) 2019-2020 Free Software Foundation, Inc.
ef1ad42b
JD
3
4 This file is part of the GNU opcodes library.
5
6 This library is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
11 It is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; see the file COPYING3. If not,
18 see <http://www.gnu.org/licenses/>. */
19
20#ifndef S12Z_OPC_H
21#define S12Z_OPC_H
22
23#include <stdbool.h>
24
d10be0cb
JD
25#ifdef __cplusplus
26extern "C"
27{
28#endif
29
ef1ad42b
JD
30/* An abstraction used to read machine code from a source. */
31struct mem_read_abstraction_base
32{
33 int (*read) (struct mem_read_abstraction_base *, int, size_t, bfd_byte *);
34 void (*advance) (struct mem_read_abstraction_base *);
35 bfd_vma (*posn) (struct mem_read_abstraction_base *);
36};
37
38
39/* Machine code operators.
40 These *roughly* correspond to opcodes.
41 But describe their purpose rather than their form. */
e5a557ac 42enum optr
ef1ad42b
JD
43 {
44 OP_INVALID = 0,
45
46 OP_push,
47 OP_pull,
48 /* Test and branch. */
49 OP_tbNE, OP_tbEQ, OP_tbPL, OP_tbMI, OP_tbGT, OP_tbLE,
50 /* Decrement and branch. */
51 OP_dbNE, OP_dbEQ, OP_dbPL, OP_dbMI, OP_dbGT, OP_dbLE,
52
53 /* Note: sex and exg are the same opcode.
54 They are mnemonic changes according to the operands. */
55 OP_sex,
56 OP_exg,
57
58 /* Shifters. */
59 OP_lsl, OP_lsr,
60 OP_asl, OP_asr,
61 OP_rol, OP_ror,
62 /* Bit field operations. */
63 OP_bfins, OP_bfext,
64 OP_trap,
65
66 OP_ld,
67 OP_st,
68 OP_cmp,
69
70 OP_stop,
71 OP_wai,
72 OP_sys,
73
74 OP_minu,
75 OP_mins,
76 OP_maxu,
77 OP_maxs,
78
79 OP_abs,
80 OP_adc,
81 OP_bit,
82 OP_sbc,
83 OP_rti,
84 OP_clb,
85 OP_eor,
86
87 OP_sat,
88
89 OP_nop,
90 OP_bgnd,
91 OP_brclr,
92 OP_brset,
93 OP_rts,
94 OP_lea,
95 OP_mov,
96
97 OP_bra,
98 OP_bsr,
99 OP_bhi,
100 OP_bls,
101 OP_bcc,
102 OP_bcs,
103 OP_bne,
104 OP_beq,
105 OP_bvc,
106 OP_bvs,
107 OP_bpl,
108 OP_bmi,
109 OP_bge,
110 OP_blt,
111 OP_bgt,
112 OP_ble,
113 OP_inc,
114 OP_clr,
115 OP_dec,
116
117 OP_add,
118 OP_sub,
119 OP_and,
120 OP_or,
121
122 OP_tfr,
123 OP_jmp,
124 OP_jsr,
125 OP_com,
126 OP_andcc,
127 OP_neg,
128 OP_orcc,
129 OP_bclr,
130 OP_bset,
131 OP_btgl,
132 OP_swi,
133
134 OP_mulu,
135 OP_divu,
136 OP_modu,
137 OP_macu,
138 OP_qmulu,
139
140 OP_muls,
141 OP_divs,
142 OP_mods,
143 OP_macs,
144 OP_qmuls,
145
146 OPBASE_mul = 0x4000,
147 OPBASE_div,
148 OPBASE_mod,
149 OPBASE_mac,
150 OPBASE_qmul,
151
152 n_OPS
153 };
154
155
156/* Used for operands which mutate their index/base registers.
157 Eg ld d0, (s+). */
158enum op_reg_mutation
159 {
160 OPND_RM_NONE,
161 OPND_RM_PRE_DEC,
162 OPND_RM_PRE_INC,
163 OPND_RM_POST_DEC,
164 OPND_RM_POST_INC
165 };
166
167/* The class of an operand. */
168enum opnd_class
169 {
170 OPND_CL_IMMEDIATE,
171 OPND_CL_MEMORY,
172 OPND_CL_REGISTER,
173 OPND_CL_REGISTER_ALL, /* Used only for psh/pul. */
174 OPND_CL_REGISTER_ALL16, /* Used only for psh/pul. */
175 OPND_CL_SIMPLE_MEMORY,
176 OPND_CL_BIT_FIELD
177 };
178
179
180/* Base structure of all operands. */
181struct operand
182{
183 enum opnd_class cl;
184
185 /* OSIZE determines the size of memory access for
186 the operation in which the operand participates.
187 It may be -1 which indicates either unknown
188 (must be determined by other operands) or if
189 it is not applicable for this operation. */
190 int osize;
191};
192
193/* Immediate operands. Eg: #23 */
194struct immediate_operand
195{
196 struct operand parent;
197 int value;
198};
199
200/* Bitfield operands. Used only in bfext and bfins
201 instructions. */
202struct bitfield_operand
203{
204 struct operand parent;
205 int width;
206 int offset;
207};
208
209/* Register operands. */
210struct register_operand
211{
212 struct operand parent;
213 int reg;
214};
215
216
217/* Simple memory operands. ie, direct memory,
218 no index, no pre/post inc/dec. May be either relative or absolute.
219 Eg st d0, 0x123456 */
220struct simple_memory_operand
221{
222 struct operand parent;
223
224 bfd_vma addr;
225 bfd_vma base;
226 bool relative;
227};
228
229
230/* Memory operands. Should be able to represent all memory
231 operands in the S12Z instruction set which are not simple
232 memory operands. */
233struct memory_operand
234{
235 struct operand parent;
236
237 /* True for indirect operands: eg [0x123456] */
238 bool indirect;
239
240 /* The value of any offset. eg 45 in (45,d7) */
241 int base_offset;
242
243 /* Does this operand increment or decrement
244 its participating registers. Eg (-s) */
245 enum op_reg_mutation mutation;
246
247 /* The number of registers participating in this operand.
248 For S12Z this is always in the range [0, 6] (but for most
249 instructions it's <= 2). */
250 int n_regs;
251
252 /* The participating registers. */
253 int regs[6];
254};
255
256
257/* Decode a single instruction.
258 OPERATOR, OSIZE, N_OPERANDS and OPERANDS are pointers to
259 variables which must be provided by the caller.
260 N_OPERANDS will be incremented by the number of operands read, so
261 you should assign it to something before calling this function.
262 OPERANDS must be large enough to contain all operands read
263 (which may be up to 6).
264 It is the responsibility of the caller to free all operands
265 when they are no longer needed.
266 Returns the number of bytes read. */
e5a557ac 267int decode_s12z (enum optr *myoperator, short *osize,
ef1ad42b
JD
268 int *n_operands, struct operand **operands,
269 struct mem_read_abstraction_base *);
d10be0cb
JD
270#ifdef __cplusplus
271}
272#endif
ef1ad42b
JD
273
274#endif /* S12Z_OPC_H */
This page took 0.080806 seconds and 4 git commands to generate.