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