s12z-opc.c revision 1.1.1.4 1 1.1 christos /* s12z-decode.c -- Freescale S12Z disassembly
2 1.1.1.4 christos Copyright (C) 2018-2025 Free Software Foundation, Inc.
3 1.1 christos
4 1.1 christos This file is part of the GNU opcodes library.
5 1.1 christos
6 1.1 christos This library is free software; you can redistribute it and/or modify
7 1.1 christos it under the terms of the GNU General Public License as published by
8 1.1 christos the Free Software Foundation; either version 3, or (at your option)
9 1.1 christos any later version.
10 1.1 christos
11 1.1 christos It is distributed in the hope that it will be useful, but WITHOUT
12 1.1 christos ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 1.1 christos or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 1.1 christos License for more details.
15 1.1 christos
16 1.1 christos You should have received a copy of the GNU General Public License
17 1.1 christos along with this program; if not, write to the Free Software
18 1.1 christos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 1.1 christos MA 02110-1301, USA. */
20 1.1 christos
21 1.1 christos #include "sysdep.h"
22 1.1 christos #include <stdio.h>
23 1.1 christos #include <stdint.h>
24 1.1 christos #include <stdbool.h>
25 1.1 christos #include <assert.h>
26 1.1 christos
27 1.1 christos #include "opcode/s12z.h"
28 1.1 christos
29 1.1 christos #include "bfd.h"
30 1.1 christos
31 1.1 christos #include "s12z-opc.h"
32 1.1 christos
33 1.1 christos
34 1.1.1.2 christos typedef int (*insn_bytes_f) (struct mem_read_abstraction_base *);
35 1.1 christos
36 1.1.1.2 christos typedef int (*operands_f) (struct mem_read_abstraction_base *,
37 1.1.1.2 christos int *n_operands, struct operand **operand);
38 1.1 christos
39 1.1 christos typedef enum optr (*discriminator_f) (struct mem_read_abstraction_base *,
40 1.1.1.2 christos enum optr hint);
41 1.1 christos
42 1.1 christos enum OPR_MODE
43 1.1 christos {
44 1.1 christos OPR_IMMe4,
45 1.1 christos OPR_REG,
46 1.1 christos OPR_OFXYS,
47 1.1 christos OPR_XY_PRE_INC,
48 1.1 christos OPR_XY_POST_INC,
49 1.1 christos OPR_XY_PRE_DEC,
50 1.1 christos OPR_XY_POST_DEC,
51 1.1 christos OPR_S_PRE_DEC,
52 1.1 christos OPR_S_POST_INC,
53 1.1 christos OPR_REG_DIRECT,
54 1.1 christos OPR_REG_INDIRECT,
55 1.1 christos OPR_IDX_DIRECT,
56 1.1 christos OPR_IDX_INDIRECT,
57 1.1 christos OPR_EXT1,
58 1.1 christos OPR_IDX2_REG,
59 1.1 christos OPR_IDX3_DIRECT,
60 1.1 christos OPR_IDX3_INDIRECT,
61 1.1 christos
62 1.1 christos OPR_EXT18,
63 1.1 christos OPR_IDX3_DIRECT_REG,
64 1.1 christos OPR_EXT3_DIRECT,
65 1.1 christos OPR_EXT3_INDIRECT
66 1.1 christos };
67 1.1 christos
68 1.1 christos struct opr_pb
69 1.1 christos {
70 1.1 christos uint8_t mask;
71 1.1 christos uint8_t value;
72 1.1 christos int n_operands;
73 1.1 christos enum OPR_MODE mode;
74 1.1 christos };
75 1.1 christos
76 1.1 christos static const struct opr_pb opr_pb[] = {
77 1.1 christos {0xF0, 0x70, 1, OPR_IMMe4},
78 1.1 christos {0xF8, 0xB8, 1, OPR_REG},
79 1.1 christos {0xC0, 0x40, 1, OPR_OFXYS},
80 1.1 christos {0xEF, 0xE3, 1, OPR_XY_PRE_INC},
81 1.1 christos {0xEF, 0xE7, 1, OPR_XY_POST_INC},
82 1.1 christos {0xEF, 0xC3, 1, OPR_XY_PRE_DEC},
83 1.1 christos {0xEF, 0xC7, 1, OPR_XY_POST_DEC},
84 1.1 christos {0xFF, 0xFB, 1, OPR_S_PRE_DEC},
85 1.1 christos {0xFF, 0xFF, 1, OPR_S_POST_INC},
86 1.1 christos {0xC8, 0x88, 1, OPR_REG_DIRECT},
87 1.1 christos {0xE8, 0xC8, 1, OPR_REG_INDIRECT},
88 1.1 christos
89 1.1 christos {0xCE, 0xC0, 2, OPR_IDX_DIRECT},
90 1.1 christos {0xCE, 0xC4, 2, OPR_IDX_INDIRECT},
91 1.1 christos {0xC0, 0x00, 2, OPR_EXT1},
92 1.1 christos
93 1.1 christos {0xC8, 0x80, 3, OPR_IDX2_REG},
94 1.1 christos {0xFA, 0xF8, 3, OPR_EXT18},
95 1.1 christos
96 1.1 christos {0xCF, 0xC2, 4, OPR_IDX3_DIRECT},
97 1.1 christos {0xCF, 0xC6, 4, OPR_IDX3_INDIRECT},
98 1.1 christos
99 1.1 christos {0xF8, 0xE8, 4, OPR_IDX3_DIRECT_REG},
100 1.1 christos {0xFF, 0xFA, 4, OPR_EXT3_DIRECT},
101 1.1 christos {0xFF, 0xFE, 4, OPR_EXT3_INDIRECT},
102 1.1 christos };
103 1.1 christos
104 1.1 christos /* Return the number of bytes in a OPR operand, including the XB postbyte.
105 1.1 christos It does not include any preceeding opcodes. */
106 1.1 christos static int
107 1.1 christos x_opr_n_bytes (struct mem_read_abstraction_base *mra, int offset)
108 1.1 christos {
109 1.1 christos bfd_byte xb;
110 1.1 christos int status = mra->read (mra, offset, 1, &xb);
111 1.1 christos if (status < 0)
112 1.1 christos return status;
113 1.1 christos
114 1.1 christos size_t i;
115 1.1 christos for (i = 0; i < sizeof (opr_pb) / sizeof (opr_pb[0]); ++i)
116 1.1 christos {
117 1.1 christos const struct opr_pb *pb = opr_pb + i;
118 1.1 christos if ((xb & pb->mask) == pb->value)
119 1.1 christos {
120 1.1 christos return pb->n_operands;
121 1.1 christos }
122 1.1 christos }
123 1.1 christos
124 1.1 christos return 1;
125 1.1 christos }
126 1.1 christos
127 1.1 christos static int
128 1.1 christos opr_n_bytes_p1 (struct mem_read_abstraction_base *mra)
129 1.1 christos {
130 1.1.1.2 christos int n = x_opr_n_bytes (mra, 0);
131 1.1.1.2 christos if (n < 0)
132 1.1.1.2 christos return n;
133 1.1.1.2 christos return 1 + n;
134 1.1 christos }
135 1.1 christos
136 1.1 christos static int
137 1.1 christos opr_n_bytes2 (struct mem_read_abstraction_base *mra)
138 1.1 christos {
139 1.1 christos int s = x_opr_n_bytes (mra, 0);
140 1.1.1.2 christos if (s < 0)
141 1.1.1.2 christos return s;
142 1.1.1.2 christos int n = x_opr_n_bytes (mra, s);
143 1.1.1.2 christos if (n < 0)
144 1.1.1.2 christos return n;
145 1.1.1.2 christos return s + n + 1;
146 1.1 christos }
147 1.1 christos
148 1.1 christos enum BB_MODE
149 1.1 christos {
150 1.1 christos BB_REG_REG_REG,
151 1.1 christos BB_REG_REG_IMM,
152 1.1 christos BB_REG_OPR_REG,
153 1.1 christos BB_OPR_REG_REG,
154 1.1 christos BB_REG_OPR_IMM,
155 1.1 christos BB_OPR_REG_IMM
156 1.1 christos };
157 1.1 christos
158 1.1 christos struct opr_bb
159 1.1 christos {
160 1.1 christos uint8_t mask;
161 1.1 christos uint8_t value;
162 1.1 christos int n_operands;
163 1.1 christos bool opr;
164 1.1 christos enum BB_MODE mode;
165 1.1 christos };
166 1.1 christos
167 1.1 christos static const struct opr_bb bb_modes[] =
168 1.1 christos {
169 1.1 christos {0x60, 0x00, 2, false, BB_REG_REG_REG},
170 1.1 christos {0x60, 0x20, 3, false, BB_REG_REG_IMM},
171 1.1 christos {0x70, 0x40, 2, true, BB_REG_OPR_REG},
172 1.1 christos {0x70, 0x50, 2, true, BB_OPR_REG_REG},
173 1.1 christos {0x70, 0x60, 3, true, BB_REG_OPR_IMM},
174 1.1 christos {0x70, 0x70, 3, true, BB_OPR_REG_IMM}
175 1.1 christos };
176 1.1 christos
177 1.1 christos static int
178 1.1 christos bfextins_n_bytes (struct mem_read_abstraction_base *mra)
179 1.1 christos {
180 1.1 christos bfd_byte bb;
181 1.1 christos int status = mra->read (mra, 0, 1, &bb);
182 1.1 christos if (status < 0)
183 1.1 christos return status;
184 1.1 christos
185 1.1 christos size_t i;
186 1.1 christos const struct opr_bb *bbs = 0;
187 1.1 christos for (i = 0; i < sizeof (bb_modes) / sizeof (bb_modes[0]); ++i)
188 1.1 christos {
189 1.1 christos bbs = bb_modes + i;
190 1.1 christos if ((bb & bbs->mask) == bbs->value)
191 1.1 christos {
192 1.1 christos break;
193 1.1 christos }
194 1.1 christos }
195 1.1 christos
196 1.1 christos int n = bbs->n_operands;
197 1.1 christos if (bbs->opr)
198 1.1.1.2 christos {
199 1.1.1.2 christos int x = x_opr_n_bytes (mra, n - 1);
200 1.1.1.2 christos if (x < 0)
201 1.1.1.2 christos return x;
202 1.1.1.2 christos n += x;
203 1.1.1.2 christos }
204 1.1 christos
205 1.1 christos return n;
206 1.1 christos }
207 1.1 christos
208 1.1 christos static int
209 1.1 christos single (struct mem_read_abstraction_base *mra ATTRIBUTE_UNUSED)
210 1.1 christos {
211 1.1 christos return 1;
212 1.1 christos }
213 1.1 christos
214 1.1 christos static int
215 1.1 christos two (struct mem_read_abstraction_base *mra ATTRIBUTE_UNUSED)
216 1.1 christos {
217 1.1 christos return 2;
218 1.1 christos }
219 1.1 christos
220 1.1 christos static int
221 1.1 christos three (struct mem_read_abstraction_base *mra ATTRIBUTE_UNUSED)
222 1.1 christos {
223 1.1 christos return 3;
224 1.1 christos }
225 1.1 christos
226 1.1 christos static int
227 1.1 christos four (struct mem_read_abstraction_base *mra ATTRIBUTE_UNUSED)
228 1.1 christos {
229 1.1 christos return 4;
230 1.1 christos }
231 1.1 christos
232 1.1 christos static int
233 1.1 christos five (struct mem_read_abstraction_base *mra ATTRIBUTE_UNUSED)
234 1.1 christos {
235 1.1 christos return 5;
236 1.1 christos }
237 1.1 christos
238 1.1 christos static int
239 1.1 christos pcrel_15bit (struct mem_read_abstraction_base *mra)
240 1.1 christos {
241 1.1 christos bfd_byte byte;
242 1.1 christos int status = mra->read (mra, 0, 1, &byte);
243 1.1 christos if (status < 0)
244 1.1 christos return status;
245 1.1 christos return (byte & 0x80) ? 3 : 2;
246 1.1 christos }
247 1.1 christos
248 1.1 christos
249 1.1 christos
250 1.1 christos static int
252 1.1 christos xysp_reg_from_postbyte (uint8_t postbyte)
253 1.1 christos {
254 1.1 christos int reg = -1;
255 1.1 christos switch ((postbyte & 0x30) >> 4)
256 1.1 christos {
257 1.1 christos case 0:
258 1.1 christos reg = REG_X;
259 1.1 christos break;
260 1.1 christos case 1:
261 1.1 christos reg = REG_Y;
262 1.1 christos break;
263 1.1 christos case 2:
264 1.1 christos reg = REG_S;
265 1.1 christos break;
266 1.1 christos default:
267 1.1 christos reg = REG_P;
268 1.1 christos }
269 1.1 christos return reg;
270 1.1 christos }
271 1.1 christos
272 1.1 christos static struct operand *
273 1.1 christos create_immediate_operand (int value)
274 1.1 christos {
275 1.1 christos struct immediate_operand *op = malloc (sizeof (*op));
276 1.1.1.2 christos
277 1.1.1.2 christos if (op != NULL)
278 1.1.1.2 christos {
279 1.1.1.2 christos op->parent.cl = OPND_CL_IMMEDIATE;
280 1.1.1.2 christos op->parent.osize = -1;
281 1.1.1.2 christos op->value = value;
282 1.1 christos }
283 1.1 christos return (struct operand *) op;
284 1.1 christos }
285 1.1 christos
286 1.1 christos static struct operand *
287 1.1 christos create_bitfield_operand (int width, int offset)
288 1.1 christos {
289 1.1 christos struct bitfield_operand *op = malloc (sizeof (*op));
290 1.1.1.2 christos
291 1.1.1.2 christos if (op != NULL)
292 1.1.1.2 christos {
293 1.1.1.2 christos op->parent.cl = OPND_CL_BIT_FIELD;
294 1.1.1.2 christos op->parent.osize = -1;
295 1.1.1.2 christos op->width = width;
296 1.1.1.2 christos op->offset = offset;
297 1.1 christos }
298 1.1 christos return (struct operand *) op;
299 1.1 christos }
300 1.1 christos
301 1.1 christos static struct operand *
302 1.1 christos create_register_operand_with_size (int reg, short osize)
303 1.1 christos {
304 1.1 christos struct register_operand *op = malloc (sizeof (*op));
305 1.1.1.2 christos
306 1.1.1.2 christos if (op != NULL)
307 1.1.1.2 christos {
308 1.1.1.2 christos op->parent.cl = OPND_CL_REGISTER;
309 1.1.1.2 christos op->parent.osize = osize;
310 1.1.1.2 christos op->reg = reg;
311 1.1 christos }
312 1.1 christos return (struct operand *) op;
313 1.1 christos }
314 1.1 christos
315 1.1 christos static struct operand *
316 1.1 christos create_register_operand (int reg)
317 1.1 christos {
318 1.1 christos return create_register_operand_with_size (reg, -1);
319 1.1 christos }
320 1.1 christos
321 1.1 christos static struct operand *
322 1.1 christos create_register_all_operand (void)
323 1.1 christos {
324 1.1 christos struct register_operand *op = malloc (sizeof (*op));
325 1.1.1.2 christos
326 1.1.1.2 christos if (op != NULL)
327 1.1.1.2 christos {
328 1.1.1.2 christos op->parent.cl = OPND_CL_REGISTER_ALL;
329 1.1.1.2 christos op->parent.osize = -1;
330 1.1 christos }
331 1.1 christos return (struct operand *) op;
332 1.1 christos }
333 1.1 christos
334 1.1 christos static struct operand *
335 1.1 christos create_register_all16_operand (void)
336 1.1 christos {
337 1.1 christos struct register_operand *op = malloc (sizeof (*op));
338 1.1.1.2 christos
339 1.1.1.2 christos if (op != NULL)
340 1.1.1.2 christos {
341 1.1.1.2 christos op->parent.cl = OPND_CL_REGISTER_ALL16;
342 1.1.1.2 christos op->parent.osize = -1;
343 1.1 christos }
344 1.1 christos return (struct operand *) op;
345 1.1 christos }
346 1.1 christos
347 1.1 christos
348 1.1 christos static struct operand *
349 1.1 christos create_simple_memory_operand (bfd_vma addr, bfd_vma base, bool relative)
350 1.1.1.2 christos {
351 1.1 christos struct simple_memory_operand *op;
352 1.1 christos
353 1.1.1.2 christos assert (relative || base == 0);
354 1.1.1.2 christos op = malloc (sizeof (*op));
355 1.1.1.2 christos if (op != NULL)
356 1.1.1.2 christos {
357 1.1.1.2 christos op->parent.cl = OPND_CL_SIMPLE_MEMORY;
358 1.1.1.2 christos op->parent.osize = -1;
359 1.1.1.2 christos op->addr = addr;
360 1.1.1.2 christos op->base = base;
361 1.1.1.2 christos op->relative = relative;
362 1.1 christos }
363 1.1 christos return (struct operand *) op;
364 1.1 christos }
365 1.1 christos
366 1.1 christos static struct operand *
367 1.1 christos create_memory_operand (bool indirect, int base, int n_regs, int reg0, int reg1)
368 1.1 christos {
369 1.1 christos struct memory_operand *op = malloc (sizeof (*op));
370 1.1.1.2 christos
371 1.1.1.2 christos if (op != NULL)
372 1.1.1.2 christos {
373 1.1.1.2 christos op->parent.cl = OPND_CL_MEMORY;
374 1.1.1.2 christos op->parent.osize = -1;
375 1.1.1.2 christos op->indirect = indirect;
376 1.1.1.2 christos op->base_offset = base;
377 1.1.1.2 christos op->mutation = OPND_RM_NONE;
378 1.1.1.2 christos op->n_regs = n_regs;
379 1.1.1.2 christos op->regs[0] = reg0;
380 1.1.1.2 christos op->regs[1] = reg1;
381 1.1 christos }
382 1.1 christos return (struct operand *) op;
383 1.1 christos }
384 1.1 christos
385 1.1 christos static struct operand *
386 1.1 christos create_memory_auto_operand (enum op_reg_mutation mutation, int reg)
387 1.1 christos {
388 1.1 christos struct memory_operand *op = malloc (sizeof (*op));
389 1.1.1.2 christos
390 1.1.1.2 christos if (op != NULL)
391 1.1.1.2 christos {
392 1.1.1.2 christos op->parent.cl = OPND_CL_MEMORY;
393 1.1.1.2 christos op->parent.osize = -1;
394 1.1.1.2 christos op->indirect = false;
395 1.1.1.2 christos op->base_offset = 0;
396 1.1.1.2 christos op->mutation = mutation;
397 1.1.1.2 christos op->n_regs = 1;
398 1.1.1.2 christos op->regs[0] = reg;
399 1.1.1.2 christos op->regs[1] = -1;
400 1.1 christos }
401 1.1 christos return (struct operand *) op;
402 1.1 christos }
403 1.1 christos
404 1.1 christos
405 1.1.1.2 christos
407 1.1 christos static int
408 1.1 christos z_ext24_decode (struct mem_read_abstraction_base *mra, int *n_operands,
409 1.1.1.2 christos struct operand **operand)
410 1.1 christos {
411 1.1 christos struct operand *op;
412 1.1 christos uint8_t buffer[3];
413 1.1.1.2 christos int status = mra->read (mra, 0, 3, buffer);
414 1.1 christos if (status < 0)
415 1.1 christos return status;
416 1.1 christos
417 1.1 christos int i;
418 1.1 christos uint32_t addr = 0;
419 1.1 christos for (i = 0; i < 3; ++i)
420 1.1 christos {
421 1.1 christos addr <<= 8;
422 1.1 christos addr |= buffer[i];
423 1.1.1.2 christos }
424 1.1.1.2 christos
425 1.1.1.2 christos op = create_simple_memory_operand (addr, 0, false);
426 1.1.1.2 christos if (op == NULL)
427 1.1.1.2 christos return -1;
428 1.1 christos operand[(*n_operands)++] = op;
429 1.1 christos return 0;
430 1.1 christos }
431 1.1.1.2 christos
432 1.1 christos
433 1.1.1.2 christos static int
434 1.1 christos z_decode_signed_value (struct mem_read_abstraction_base *mra, int offset,
435 1.1 christos short size, uint32_t *result)
436 1.1 christos {
437 1.1 christos assert (size >0);
438 1.1.1.2 christos assert (size <= 4);
439 1.1.1.2 christos bfd_byte buffer[4];
440 1.1.1.2 christos int status = mra->read (mra, offset, size, buffer);
441 1.1 christos if (status < 0)
442 1.1 christos return status;
443 1.1 christos
444 1.1 christos int i;
445 1.1 christos uint32_t value = 0;
446 1.1 christos for (i = 0; i < size; ++i)
447 1.1 christos value = (value << 8) | buffer[i];
448 1.1 christos
449 1.1 christos if (buffer[0] & 0x80)
450 1.1.1.2 christos {
451 1.1 christos /* Deal with negative values */
452 1.1.1.2 christos value -= 1u << (size * 4) << (size * 4);
453 1.1.1.2 christos }
454 1.1 christos *result = value;
455 1.1 christos return 0;
456 1.1.1.2 christos }
457 1.1.1.2 christos
458 1.1.1.2 christos static int
459 1.1 christos decode_signed_value (struct mem_read_abstraction_base *mra, short size,
460 1.1.1.2 christos uint32_t *result)
461 1.1 christos {
462 1.1 christos return z_decode_signed_value (mra, 0, size, result);
463 1.1.1.2 christos }
464 1.1 christos
465 1.1 christos static int
466 1.1 christos x_imm1 (struct mem_read_abstraction_base *mra,
467 1.1 christos int offset,
468 1.1.1.2 christos int *n_operands, struct operand **operand)
469 1.1 christos {
470 1.1 christos struct operand *op;
471 1.1 christos bfd_byte byte;
472 1.1.1.2 christos int status = mra->read (mra, offset, 1, &byte);
473 1.1 christos if (status < 0)
474 1.1.1.2 christos return status;
475 1.1.1.2 christos
476 1.1.1.2 christos op = create_immediate_operand (byte);
477 1.1.1.2 christos if (op == NULL)
478 1.1.1.2 christos return -1;
479 1.1 christos operand[(*n_operands)++] = op;
480 1.1 christos return 0;
481 1.1 christos }
482 1.1.1.2 christos
483 1.1 christos /* An eight bit immediate operand. */
484 1.1 christos static int
485 1.1 christos imm1_decode (struct mem_read_abstraction_base *mra,
486 1.1.1.2 christos int *n_operands, struct operand **operand)
487 1.1 christos {
488 1.1 christos return x_imm1 (mra, 0, n_operands, operand);
489 1.1.1.2 christos }
490 1.1 christos
491 1.1 christos static int
492 1.1 christos trap_decode (struct mem_read_abstraction_base *mra,
493 1.1.1.2 christos int *n_operands, struct operand **operand)
494 1.1 christos {
495 1.1 christos return x_imm1 (mra, -1, n_operands, operand);
496 1.1 christos }
497 1.1 christos
498 1.1 christos
499 1.1 christos static struct operand *
500 1.1 christos x_opr_decode_with_size (struct mem_read_abstraction_base *mra, int offset,
501 1.1 christos short osize)
502 1.1 christos {
503 1.1 christos bfd_byte postbyte;
504 1.1 christos int status = mra->read (mra, offset, 1, &postbyte);
505 1.1 christos if (status < 0)
506 1.1 christos return NULL;
507 1.1 christos offset++;
508 1.1 christos
509 1.1 christos enum OPR_MODE mode = -1;
510 1.1 christos size_t i;
511 1.1 christos for (i = 0; i < sizeof (opr_pb) / sizeof (opr_pb[0]); ++i)
512 1.1 christos {
513 1.1 christos const struct opr_pb *pb = opr_pb + i;
514 1.1 christos if ((postbyte & pb->mask) == pb->value)
515 1.1 christos {
516 1.1 christos mode = pb->mode;
517 1.1 christos break;
518 1.1 christos }
519 1.1 christos }
520 1.1 christos
521 1.1 christos struct operand *operand = NULL;
522 1.1 christos switch (mode)
523 1.1 christos {
524 1.1 christos case OPR_IMMe4:
525 1.1 christos {
526 1.1 christos int n;
527 1.1 christos uint8_t x = (postbyte & 0x0F);
528 1.1 christos if (x == 0)
529 1.1 christos n = -1;
530 1.1 christos else
531 1.1 christos n = x;
532 1.1 christos
533 1.1 christos operand = create_immediate_operand (n);
534 1.1 christos break;
535 1.1 christos }
536 1.1 christos case OPR_REG:
537 1.1 christos {
538 1.1 christos uint8_t x = (postbyte & 0x07);
539 1.1 christos operand = create_register_operand (x);
540 1.1 christos break;
541 1.1 christos }
542 1.1 christos case OPR_OFXYS:
543 1.1 christos {
544 1.1 christos operand = create_memory_operand (false, postbyte & 0x0F, 1,
545 1.1 christos xysp_reg_from_postbyte (postbyte), -1);
546 1.1 christos break;
547 1.1 christos }
548 1.1 christos case OPR_REG_DIRECT:
549 1.1 christos {
550 1.1 christos operand = create_memory_operand (false, 0, 2, postbyte & 0x07,
551 1.1 christos xysp_reg_from_postbyte (postbyte));
552 1.1 christos break;
553 1.1 christos }
554 1.1 christos case OPR_REG_INDIRECT:
555 1.1 christos {
556 1.1 christos operand = create_memory_operand (true, 0, 2, postbyte & 0x07,
557 1.1 christos (postbyte & 0x10) ? REG_Y : REG_X);
558 1.1 christos break;
559 1.1 christos }
560 1.1 christos
561 1.1 christos case OPR_IDX_INDIRECT:
562 1.1.1.2 christos {
563 1.1.1.2 christos uint8_t x1;
564 1.1.1.2 christos status = mra->read (mra, offset, 1, &x1);
565 1.1 christos if (status < 0)
566 1.1 christos return NULL;
567 1.1 christos int idx = x1;
568 1.1 christos
569 1.1 christos if (postbyte & 0x01)
570 1.1 christos {
571 1.1 christos /* Deal with negative values */
572 1.1 christos idx -= 0x1UL << 8;
573 1.1 christos }
574 1.1 christos
575 1.1 christos operand = create_memory_operand (true, idx, 1,
576 1.1 christos xysp_reg_from_postbyte (postbyte), -1);
577 1.1 christos break;
578 1.1 christos }
579 1.1 christos
580 1.1 christos case OPR_IDX3_DIRECT:
581 1.1.1.2 christos {
582 1.1.1.2 christos uint8_t x[3];
583 1.1.1.2 christos status = mra->read (mra, offset, 3, x);
584 1.1 christos if (status < 0)
585 1.1 christos return NULL;
586 1.1 christos int idx = x[0] << 16 | x[1] << 8 | x[2];
587 1.1 christos
588 1.1 christos if (x[0] & 0x80)
589 1.1 christos {
590 1.1 christos /* Deal with negative values */
591 1.1 christos idx -= 0x1UL << 24;
592 1.1 christos }
593 1.1 christos
594 1.1 christos operand = create_memory_operand (false, idx, 1,
595 1.1 christos xysp_reg_from_postbyte (postbyte), -1);
596 1.1 christos break;
597 1.1 christos }
598 1.1 christos
599 1.1 christos case OPR_IDX3_DIRECT_REG:
600 1.1.1.2 christos {
601 1.1.1.2 christos uint8_t x[3];
602 1.1.1.2 christos status = mra->read (mra, offset, 3, x);
603 1.1 christos if (status < 0)
604 1.1 christos return NULL;
605 1.1 christos int idx = x[0] << 16 | x[1] << 8 | x[2];
606 1.1 christos
607 1.1 christos if (x[0] & 0x80)
608 1.1 christos {
609 1.1 christos /* Deal with negative values */
610 1.1 christos idx -= 0x1UL << 24;
611 1.1 christos }
612 1.1 christos
613 1.1 christos operand = create_memory_operand (false, idx, 1, postbyte & 0x07, -1);
614 1.1 christos break;
615 1.1 christos }
616 1.1 christos
617 1.1 christos case OPR_IDX3_INDIRECT:
618 1.1.1.2 christos {
619 1.1.1.2 christos uint8_t x[3];
620 1.1.1.2 christos status = mra->read (mra, offset, 3, x);
621 1.1 christos if (status < 0)
622 1.1 christos return NULL;
623 1.1 christos int idx = x[0] << 16 | x[1] << 8 | x[2];
624 1.1 christos
625 1.1 christos if (x[0] & 0x80)
626 1.1 christos {
627 1.1 christos /* Deal with negative values */
628 1.1 christos idx -= 0x1UL << 24;
629 1.1 christos }
630 1.1 christos
631 1.1 christos operand = create_memory_operand (true, idx, 1,
632 1.1 christos xysp_reg_from_postbyte (postbyte), -1);
633 1.1 christos break;
634 1.1 christos }
635 1.1 christos
636 1.1 christos case OPR_IDX_DIRECT:
637 1.1.1.2 christos {
638 1.1.1.2 christos uint8_t x1;
639 1.1.1.2 christos status = mra->read (mra, offset, 1, &x1);
640 1.1 christos if (status < 0)
641 1.1 christos return NULL;
642 1.1 christos int idx = x1;
643 1.1 christos
644 1.1 christos if (postbyte & 0x01)
645 1.1 christos {
646 1.1 christos /* Deal with negative values */
647 1.1 christos idx -= 0x1UL << 8;
648 1.1 christos }
649 1.1 christos
650 1.1 christos operand = create_memory_operand (false, idx, 1,
651 1.1 christos xysp_reg_from_postbyte (postbyte), -1);
652 1.1 christos break;
653 1.1 christos }
654 1.1 christos
655 1.1 christos case OPR_IDX2_REG:
656 1.1.1.2 christos {
657 1.1.1.2 christos uint8_t x[2];
658 1.1.1.2 christos status = mra->read (mra, offset, 2, x);
659 1.1 christos if (status < 0)
660 1.1 christos return NULL;
661 1.1 christos uint32_t idx = x[1] | x[0] << 8 ;
662 1.1 christos idx |= (postbyte & 0x30) << 12;
663 1.1 christos
664 1.1 christos operand = create_memory_operand (false, idx, 1, postbyte & 0x07, -1);
665 1.1 christos break;
666 1.1 christos }
667 1.1 christos
668 1.1 christos case OPR_XY_PRE_INC:
669 1.1 christos {
670 1.1 christos operand = create_memory_auto_operand (OPND_RM_PRE_INC,
671 1.1 christos (postbyte & 0x10) ? REG_Y: REG_X);
672 1.1 christos break;
673 1.1 christos }
674 1.1 christos case OPR_XY_POST_INC:
675 1.1 christos {
676 1.1 christos operand = create_memory_auto_operand (OPND_RM_POST_INC,
677 1.1 christos (postbyte & 0x10) ? REG_Y: REG_X);
678 1.1 christos break;
679 1.1 christos }
680 1.1 christos case OPR_XY_PRE_DEC:
681 1.1 christos {
682 1.1 christos operand = create_memory_auto_operand (OPND_RM_PRE_DEC,
683 1.1 christos (postbyte & 0x10) ? REG_Y: REG_X);
684 1.1 christos break;
685 1.1 christos }
686 1.1 christos case OPR_XY_POST_DEC:
687 1.1 christos {
688 1.1 christos operand = create_memory_auto_operand (OPND_RM_POST_DEC,
689 1.1 christos (postbyte & 0x10) ? REG_Y: REG_X);
690 1.1 christos break;
691 1.1 christos }
692 1.1 christos case OPR_S_PRE_DEC:
693 1.1 christos {
694 1.1 christos operand = create_memory_auto_operand (OPND_RM_PRE_DEC, REG_S);
695 1.1 christos break;
696 1.1 christos }
697 1.1 christos case OPR_S_POST_INC:
698 1.1 christos {
699 1.1 christos operand = create_memory_auto_operand (OPND_RM_POST_INC, REG_S);
700 1.1 christos break;
701 1.1 christos }
702 1.1 christos
703 1.1 christos case OPR_EXT18:
704 1.1 christos {
705 1.1 christos const size_t size = 2;
706 1.1 christos bfd_byte buffer[4];
707 1.1.1.2 christos status = mra->read (mra, offset, size, buffer);
708 1.1 christos if (status < 0)
709 1.1 christos return NULL;
710 1.1 christos
711 1.1 christos uint32_t ext18 = 0;
712 1.1 christos for (i = 0; i < size; ++i)
713 1.1 christos {
714 1.1 christos ext18 <<= 8;
715 1.1 christos ext18 |= buffer[i];
716 1.1 christos }
717 1.1 christos
718 1.1 christos ext18 |= (postbyte & 0x01) << 16;
719 1.1 christos ext18 |= (postbyte & 0x04) << 15;
720 1.1 christos
721 1.1 christos operand = create_simple_memory_operand (ext18, 0, false);
722 1.1 christos break;
723 1.1 christos }
724 1.1 christos
725 1.1 christos case OPR_EXT1:
726 1.1.1.2 christos {
727 1.1.1.2 christos uint8_t x1 = 0;
728 1.1.1.2 christos status = mra->read (mra, offset, 1, &x1);
729 1.1 christos if (status < 0)
730 1.1 christos return NULL;
731 1.1 christos int16_t addr;
732 1.1 christos addr = x1;
733 1.1 christos addr |= (postbyte & 0x3f) << 8;
734 1.1 christos
735 1.1 christos operand = create_simple_memory_operand (addr, 0, false);
736 1.1 christos break;
737 1.1 christos }
738 1.1 christos
739 1.1 christos case OPR_EXT3_DIRECT:
740 1.1 christos {
741 1.1 christos const size_t size = 3;
742 1.1 christos bfd_byte buffer[4];
743 1.1.1.2 christos status = mra->read (mra, offset, size, buffer);
744 1.1 christos if (status < 0)
745 1.1 christos return NULL;
746 1.1 christos
747 1.1 christos uint32_t ext24 = 0;
748 1.1 christos for (i = 0; i < size; ++i)
749 1.1 christos {
750 1.1 christos ext24 |= buffer[i] << (8 * (size - i - 1));
751 1.1 christos }
752 1.1 christos
753 1.1 christos operand = create_simple_memory_operand (ext24, 0, false);
754 1.1 christos break;
755 1.1 christos }
756 1.1 christos
757 1.1 christos case OPR_EXT3_INDIRECT:
758 1.1 christos {
759 1.1 christos const size_t size = 3;
760 1.1 christos bfd_byte buffer[4];
761 1.1.1.2 christos status = mra->read (mra, offset, size, buffer);
762 1.1 christos if (status < 0)
763 1.1 christos return NULL;
764 1.1 christos
765 1.1 christos uint32_t ext24 = 0;
766 1.1 christos for (i = 0; i < size; ++i)
767 1.1 christos {
768 1.1 christos ext24 |= buffer[i] << (8 * (size - i - 1));
769 1.1 christos }
770 1.1 christos
771 1.1 christos operand = create_memory_operand (true, ext24, 0, -1, -1);
772 1.1 christos break;
773 1.1 christos }
774 1.1 christos
775 1.1 christos default:
776 1.1 christos printf ("Unknown OPR mode #0x%x (%d)", postbyte, mode);
777 1.1 christos abort ();
778 1.1.1.2 christos }
779 1.1.1.2 christos
780 1.1 christos if (operand != NULL)
781 1.1 christos operand->osize = osize;
782 1.1 christos
783 1.1 christos return operand;
784 1.1 christos }
785 1.1 christos
786 1.1 christos static struct operand *
787 1.1 christos x_opr_decode (struct mem_read_abstraction_base *mra, int offset)
788 1.1 christos {
789 1.1 christos return x_opr_decode_with_size (mra, offset, -1);
790 1.1.1.2 christos }
791 1.1 christos
792 1.1 christos static int
793 1.1 christos z_opr_decode (struct mem_read_abstraction_base *mra,
794 1.1.1.2 christos int *n_operands, struct operand **operand)
795 1.1.1.2 christos {
796 1.1.1.2 christos struct operand *op = x_opr_decode (mra, 0);
797 1.1.1.2 christos if (op == NULL)
798 1.1.1.2 christos return -1;
799 1.1 christos operand[(*n_operands)++] = op;
800 1.1 christos return 0;
801 1.1.1.2 christos }
802 1.1 christos
803 1.1 christos static int
804 1.1 christos z_opr_decode2 (struct mem_read_abstraction_base *mra,
805 1.1 christos int *n_operands, struct operand **operand)
806 1.1.1.2 christos {
807 1.1.1.2 christos int n = x_opr_n_bytes (mra, 0);
808 1.1.1.2 christos if (n < 0)
809 1.1.1.2 christos return n;
810 1.1.1.2 christos struct operand *op = x_opr_decode (mra, 0);
811 1.1.1.2 christos if (op == NULL)
812 1.1.1.2 christos return -1;
813 1.1.1.2 christos operand[(*n_operands)++] = op;
814 1.1.1.2 christos op = x_opr_decode (mra, n);
815 1.1.1.2 christos if (op == NULL)
816 1.1.1.2 christos return -1;
817 1.1 christos operand[(*n_operands)++] = op;
818 1.1 christos return 0;
819 1.1.1.2 christos }
820 1.1 christos
821 1.1 christos static int
822 1.1 christos imm1234 (struct mem_read_abstraction_base *mra, int base,
823 1.1.1.2 christos int *n_operands, struct operand **operand)
824 1.1 christos {
825 1.1 christos struct operand *op;
826 1.1 christos bfd_byte opcode;
827 1.1.1.2 christos int status = mra->read (mra, -1, 1, &opcode);
828 1.1 christos if (status < 0)
829 1.1 christos return status;
830 1.1 christos
831 1.1 christos opcode -= base;
832 1.1 christos
833 1.1.1.2 christos int size = registers[opcode & 0xF].bytes;
834 1.1.1.2 christos
835 1.1.1.2 christos uint32_t imm;
836 1.1.1.2 christos if (decode_signed_value (mra, size, &imm) < 0)
837 1.1.1.2 christos return -1;
838 1.1.1.2 christos
839 1.1.1.2 christos op = create_immediate_operand (imm);
840 1.1.1.2 christos if (op == NULL)
841 1.1.1.2 christos return -1;
842 1.1 christos operand[(*n_operands)++] = op;
843 1.1 christos return 0;
844 1.1 christos }
845 1.1 christos
846 1.1.1.2 christos
847 1.1 christos /* Special case of LD and CMP with register S and IMM operand */
848 1.1 christos static int
849 1.1 christos reg_s_imm (struct mem_read_abstraction_base *mra, int *n_operands,
850 1.1.1.2 christos struct operand **operand)
851 1.1 christos {
852 1.1.1.2 christos struct operand *op;
853 1.1.1.2 christos
854 1.1.1.2 christos op = create_register_operand (REG_S);
855 1.1.1.2 christos if (op == NULL)
856 1.1.1.2 christos return -1;
857 1.1.1.2 christos operand[(*n_operands)++] = op;
858 1.1.1.2 christos
859 1.1.1.2 christos uint32_t imm;
860 1.1.1.2 christos if (decode_signed_value (mra, 3, &imm) < 0)
861 1.1.1.2 christos return -1;
862 1.1.1.2 christos op = create_immediate_operand (imm);
863 1.1.1.2 christos if (op == NULL)
864 1.1.1.2 christos return -1;
865 1.1 christos operand[(*n_operands)++] = op;
866 1.1 christos return 0;
867 1.1 christos }
868 1.1.1.2 christos
869 1.1 christos /* Special case of LD, CMP and ST with register S and OPR operand */
870 1.1 christos static int
871 1.1 christos reg_s_opr (struct mem_read_abstraction_base *mra, int *n_operands,
872 1.1.1.2 christos struct operand **operand)
873 1.1.1.2 christos {
874 1.1.1.2 christos struct operand *op;
875 1.1.1.2 christos
876 1.1.1.2 christos op = create_register_operand (REG_S);
877 1.1.1.2 christos if (op == NULL)
878 1.1.1.2 christos return -1;
879 1.1.1.2 christos operand[(*n_operands)++] = op;
880 1.1.1.2 christos op = x_opr_decode (mra, 0);
881 1.1.1.2 christos if (op == NULL)
882 1.1.1.2 christos return -1;
883 1.1 christos operand[(*n_operands)++] = op;
884 1.1 christos return 0;
885 1.1.1.2 christos }
886 1.1 christos
887 1.1 christos static int
888 1.1 christos z_imm1234_8base (struct mem_read_abstraction_base *mra, int *n_operands,
889 1.1.1.2 christos struct operand **operand)
890 1.1 christos {
891 1.1 christos return imm1234 (mra, 8, n_operands, operand);
892 1.1.1.2 christos }
893 1.1 christos
894 1.1 christos static int
895 1.1 christos z_imm1234_0base (struct mem_read_abstraction_base *mra, int *n_operands,
896 1.1.1.2 christos struct operand **operand)
897 1.1 christos {
898 1.1 christos return imm1234 (mra, 0, n_operands, operand);
899 1.1 christos }
900 1.1.1.2 christos
901 1.1 christos
902 1.1 christos static int
903 1.1 christos z_tfr (struct mem_read_abstraction_base *mra, int *n_operands,
904 1.1.1.2 christos struct operand **operand)
905 1.1 christos {
906 1.1 christos struct operand *op;
907 1.1 christos bfd_byte byte;
908 1.1.1.2 christos int status = mra->read (mra, 0, 1, &byte);
909 1.1 christos if (status < 0)
910 1.1.1.2 christos return status;
911 1.1.1.2 christos
912 1.1.1.2 christos op = create_register_operand (byte >> 4);
913 1.1.1.2 christos if (op == NULL)
914 1.1.1.2 christos return -1;
915 1.1.1.2 christos operand[(*n_operands)++] = op;
916 1.1.1.2 christos op = create_register_operand (byte & 0x0F);
917 1.1.1.2 christos if (op == NULL)
918 1.1.1.2 christos return -1;
919 1.1 christos operand[(*n_operands)++] = op;
920 1.1 christos return 0;
921 1.1.1.2 christos }
922 1.1 christos
923 1.1 christos static int
924 1.1 christos z_reg (struct mem_read_abstraction_base *mra, int *n_operands,
925 1.1.1.2 christos struct operand **operand)
926 1.1 christos {
927 1.1 christos struct operand *op;
928 1.1 christos bfd_byte byte;
929 1.1.1.2 christos int status = mra->read (mra, -1, 1, &byte);
930 1.1 christos if (status < 0)
931 1.1.1.2 christos return status;
932 1.1.1.2 christos
933 1.1.1.2 christos op = create_register_operand (byte & 0x07);
934 1.1.1.2 christos if (op == NULL)
935 1.1.1.2 christos return -1;
936 1.1 christos operand[(*n_operands)++] = op;
937 1.1 christos return 0;
938 1.1 christos }
939 1.1.1.2 christos
940 1.1 christos
941 1.1 christos static int
942 1.1 christos reg_xy (struct mem_read_abstraction_base *mra,
943 1.1.1.2 christos int *n_operands, struct operand **operand)
944 1.1 christos {
945 1.1 christos struct operand *op;
946 1.1 christos bfd_byte byte;
947 1.1.1.2 christos int status = mra->read (mra, -1, 1, &byte);
948 1.1 christos if (status < 0)
949 1.1.1.2 christos return status;
950 1.1.1.2 christos
951 1.1.1.2 christos op = create_register_operand ((byte & 0x01) ? REG_Y : REG_X);
952 1.1.1.2 christos if (op == NULL)
953 1.1.1.2 christos return -1;
954 1.1 christos operand[(*n_operands)++] = op;
955 1.1 christos return 0;
956 1.1.1.2 christos }
957 1.1 christos
958 1.1 christos static int
959 1.1 christos lea_reg_xys_opr (struct mem_read_abstraction_base *mra,
960 1.1.1.2 christos int *n_operands, struct operand **operand)
961 1.1 christos {
962 1.1 christos struct operand *op;
963 1.1 christos bfd_byte byte;
964 1.1.1.2 christos int status = mra->read (mra, -1, 1, &byte);
965 1.1 christos if (status < 0)
966 1.1 christos return status;
967 1.1 christos
968 1.1 christos int reg_xys = -1;
969 1.1 christos switch (byte & 0x03)
970 1.1 christos {
971 1.1 christos case 0x00:
972 1.1 christos reg_xys = REG_X;
973 1.1 christos break;
974 1.1 christos case 0x01:
975 1.1 christos reg_xys = REG_Y;
976 1.1 christos break;
977 1.1 christos case 0x02:
978 1.1 christos reg_xys = REG_S;
979 1.1 christos break;
980 1.1.1.2 christos }
981 1.1.1.2 christos
982 1.1.1.2 christos op = create_register_operand (reg_xys);
983 1.1.1.2 christos if (op == NULL)
984 1.1.1.2 christos return -1;
985 1.1.1.2 christos operand[(*n_operands)++] = op;
986 1.1.1.2 christos op = x_opr_decode (mra, 0);
987 1.1.1.2 christos if (op == NULL)
988 1.1.1.2 christos return -1;
989 1.1 christos operand[(*n_operands)++] = op;
990 1.1 christos return 0;
991 1.1.1.2 christos }
992 1.1 christos
993 1.1 christos static int
994 1.1 christos lea_reg_xys (struct mem_read_abstraction_base *mra,
995 1.1.1.2 christos int *n_operands, struct operand **operand)
996 1.1 christos {
997 1.1 christos struct operand *op;
998 1.1 christos bfd_byte byte;
999 1.1.1.2 christos int status = mra->read (mra, -1, 1, &byte);
1000 1.1 christos if (status < 0)
1001 1.1 christos return status;
1002 1.1 christos
1003 1.1 christos int reg_n = -1;
1004 1.1 christos switch (byte & 0x03)
1005 1.1 christos {
1006 1.1 christos case 0x00:
1007 1.1 christos reg_n = REG_X;
1008 1.1 christos break;
1009 1.1 christos case 0x01:
1010 1.1 christos reg_n = REG_Y;
1011 1.1 christos break;
1012 1.1 christos case 0x02:
1013 1.1 christos reg_n = REG_S;
1014 1.1 christos break;
1015 1.1 christos }
1016 1.1 christos
1017 1.1.1.2 christos status = mra->read (mra, 0, 1, &byte);
1018 1.1 christos if (status < 0)
1019 1.1.1.2 christos return status;
1020 1.1.1.2 christos
1021 1.1.1.2 christos op = create_register_operand (reg_n);
1022 1.1.1.2 christos if (op == NULL)
1023 1.1.1.2 christos return -1;
1024 1.1.1.2 christos operand[(*n_operands)++] = op;
1025 1.1.1.2 christos op = create_memory_operand (false, (int8_t) byte, 1, reg_n, -1);
1026 1.1.1.2 christos if (op == NULL)
1027 1.1.1.2 christos return -1;
1028 1.1 christos operand[(*n_operands)++] = op;
1029 1.1 christos return 0;
1030 1.1 christos }
1031 1.1 christos
1032 1.1.1.2 christos
1033 1.1 christos /* PC Relative offsets of size 15 or 7 bits */
1034 1.1 christos static int
1035 1.1 christos rel_15_7 (struct mem_read_abstraction_base *mra, int offset,
1036 1.1.1.2 christos int *n_operands, struct operand **operands)
1037 1.1 christos {
1038 1.1 christos struct operand *op;
1039 1.1 christos bfd_byte upper;
1040 1.1.1.2 christos int status = mra->read (mra, offset - 1, 1, &upper);
1041 1.1 christos if (status < 0)
1042 1.1 christos return status;
1043 1.1 christos
1044 1.1 christos bool rel_size = (upper & 0x80);
1045 1.1 christos
1046 1.1 christos int16_t addr = upper;
1047 1.1 christos if (rel_size)
1048 1.1 christos {
1049 1.1 christos /* 15 bits. Get the next byte */
1050 1.1 christos bfd_byte lower;
1051 1.1.1.2 christos status = mra->read (mra, offset, 1, &lower);
1052 1.1 christos if (status < 0)
1053 1.1 christos return status;
1054 1.1 christos
1055 1.1 christos addr <<= 8;
1056 1.1 christos addr |= lower;
1057 1.1 christos addr &= 0x7FFF;
1058 1.1 christos
1059 1.1 christos bool negative = (addr & 0x4000);
1060 1.1 christos addr &= 0x3FFF;
1061 1.1 christos if (negative)
1062 1.1 christos addr = addr - 0x4000;
1063 1.1 christos }
1064 1.1 christos else
1065 1.1 christos {
1066 1.1 christos /* 7 bits. */
1067 1.1 christos bool negative = (addr & 0x40);
1068 1.1 christos addr &= 0x3F;
1069 1.1 christos if (negative)
1070 1.1 christos addr = addr - 0x40;
1071 1.1.1.2 christos }
1072 1.1.1.2 christos
1073 1.1.1.2 christos op = create_simple_memory_operand (addr, mra->posn (mra) - 1, true);
1074 1.1.1.2 christos if (op == NULL)
1075 1.1.1.2 christos return -1;
1076 1.1 christos operands[(*n_operands)++] = op;
1077 1.1 christos return 0;
1078 1.1 christos }
1079 1.1 christos
1080 1.1.1.2 christos
1081 1.1 christos /* PC Relative offsets of size 15 or 7 bits */
1082 1.1 christos static int
1083 1.1 christos decode_rel_15_7 (struct mem_read_abstraction_base *mra,
1084 1.1.1.2 christos int *n_operands, struct operand **operand)
1085 1.1 christos {
1086 1.1 christos return rel_15_7 (mra, 1, n_operands, operand);
1087 1.1 christos }
1088 1.1 christos
1089 1.1 christos static int shift_n_bytes (struct mem_read_abstraction_base *);
1090 1.1 christos static int mov_imm_opr_n_bytes (struct mem_read_abstraction_base *);
1091 1.1 christos static int loop_prim_n_bytes (struct mem_read_abstraction_base *);
1092 1.1 christos static int bm_rel_n_bytes (struct mem_read_abstraction_base *);
1093 1.1 christos static int mul_n_bytes (struct mem_read_abstraction_base *);
1094 1.1.1.2 christos static int bm_n_bytes (struct mem_read_abstraction_base *);
1095 1.1.1.2 christos
1096 1.1.1.2 christos static int psh_pul_decode (struct mem_read_abstraction_base *mra, int *n_operands, struct operand **operand);
1097 1.1.1.2 christos static int shift_decode (struct mem_read_abstraction_base *mra, int *n_operands, struct operand **operand);
1098 1.1.1.2 christos static int mul_decode (struct mem_read_abstraction_base *mra, int *n_operands, struct operand **operand);
1099 1.1.1.2 christos static int bm_decode (struct mem_read_abstraction_base *mra, int *n_operands, struct operand **operand);
1100 1.1.1.2 christos static int bm_rel_decode (struct mem_read_abstraction_base *mra, int *n_operands, struct operand **operand);
1101 1.1.1.2 christos static int mov_imm_opr (struct mem_read_abstraction_base *mra, int *n_operands, struct operand **operand);
1102 1.1.1.2 christos static int loop_primitive_decode (struct mem_read_abstraction_base *mra, int *n_operands, struct operand **operands);
1103 1.1 christos static int bit_field_decode (struct mem_read_abstraction_base *mra, int *n_operands, struct operand **operands);
1104 1.1 christos static int exg_sex_decode (struct mem_read_abstraction_base *mra, int *n_operands, struct operand **operands);
1105 1.1 christos
1106 1.1 christos
1107 1.1 christos static enum optr shift_discrim (struct mem_read_abstraction_base *mra, enum optr hint);
1108 1.1 christos static enum optr psh_pul_discrim (struct mem_read_abstraction_base *mra, enum optr hint);
1109 1.1 christos static enum optr mul_discrim (struct mem_read_abstraction_base *mra, enum optr hint);
1110 1.1 christos static enum optr loop_primitive_discrim (struct mem_read_abstraction_base *mra, enum optr hint);
1111 1.1 christos static enum optr bit_field_discrim (struct mem_read_abstraction_base *mra, enum optr hint);
1112 1.1 christos static enum optr exg_sex_discrim (struct mem_read_abstraction_base *mra, enum optr hint);
1113 1.1.1.2 christos
1114 1.1 christos
1115 1.1 christos static int
1116 1.1 christos cmp_xy (struct mem_read_abstraction_base *mra ATTRIBUTE_UNUSED,
1117 1.1.1.2 christos int *n_operands, struct operand **operand)
1118 1.1.1.2 christos {
1119 1.1.1.2 christos struct operand *op;
1120 1.1.1.2 christos
1121 1.1.1.2 christos op = create_register_operand (REG_X);
1122 1.1.1.2 christos if (op == NULL)
1123 1.1.1.2 christos return -1;
1124 1.1.1.2 christos operand[(*n_operands)++] = op;
1125 1.1.1.2 christos op = create_register_operand (REG_Y);
1126 1.1.1.2 christos if (op == NULL)
1127 1.1.1.2 christos return -1;
1128 1.1 christos operand[(*n_operands)++] = op;
1129 1.1 christos return 0;
1130 1.1.1.2 christos }
1131 1.1 christos
1132 1.1 christos static int
1133 1.1 christos sub_d6_x_y (struct mem_read_abstraction_base *mra ATTRIBUTE_UNUSED,
1134 1.1.1.2 christos int *n_operands, struct operand **operand)
1135 1.1.1.2 christos {
1136 1.1.1.2 christos struct operand *op;
1137 1.1.1.2 christos
1138 1.1.1.2 christos op = create_register_operand (REG_D6);
1139 1.1.1.2 christos if (op == NULL)
1140 1.1.1.2 christos return -1;
1141 1.1.1.2 christos operand[(*n_operands)++] = op;
1142 1.1.1.2 christos op = create_register_operand (REG_X);
1143 1.1.1.2 christos if (op == NULL)
1144 1.1.1.2 christos return -1;
1145 1.1.1.2 christos operand[(*n_operands)++] = op;
1146 1.1.1.2 christos op = create_register_operand (REG_Y);
1147 1.1.1.2 christos if (op == NULL)
1148 1.1.1.2 christos return -1;
1149 1.1 christos operand[(*n_operands)++] = op;
1150 1.1 christos return 0;
1151 1.1.1.2 christos }
1152 1.1 christos
1153 1.1 christos static int
1154 1.1 christos sub_d6_y_x (struct mem_read_abstraction_base *mra ATTRIBUTE_UNUSED,
1155 1.1.1.2 christos int *n_operands, struct operand **operand)
1156 1.1.1.2 christos {
1157 1.1.1.2 christos struct operand *op;
1158 1.1.1.2 christos
1159 1.1.1.2 christos op = create_register_operand (REG_D6);
1160 1.1.1.2 christos if (op == NULL)
1161 1.1.1.2 christos return -1;
1162 1.1.1.2 christos operand[(*n_operands)++] = op;
1163 1.1.1.2 christos op = create_register_operand (REG_Y);
1164 1.1.1.2 christos if (op == NULL)
1165 1.1.1.2 christos return -1;
1166 1.1.1.2 christos operand[(*n_operands)++] = op;
1167 1.1.1.2 christos op = create_register_operand (REG_X);
1168 1.1.1.2 christos if (op == NULL)
1169 1.1.1.2 christos return -1;
1170 1.1 christos operand[(*n_operands)++] = op;
1171 1.1 christos return 0;
1172 1.1.1.2 christos }
1173 1.1 christos
1174 1.1 christos static int
1175 1.1 christos ld_18bit_decode (struct mem_read_abstraction_base *mra, int *n_operands,
1176 1.1 christos struct operand **operand);
1177 1.1 christos
1178 1.1 christos static enum optr
1179 1.1 christos mul_discrim (struct mem_read_abstraction_base *mra, enum optr hint)
1180 1.1 christos {
1181 1.1 christos uint8_t mb;
1182 1.1 christos int status = mra->read (mra, 0, 1, &mb);
1183 1.1 christos if (status < 0)
1184 1.1 christos return OP_INVALID;
1185 1.1 christos
1186 1.1 christos bool signed_op = (mb & 0x80);
1187 1.1 christos
1188 1.1 christos switch (hint)
1189 1.1 christos {
1190 1.1 christos case OPBASE_mul:
1191 1.1 christos return signed_op ? OP_muls : OP_mulu;
1192 1.1 christos break;
1193 1.1 christos case OPBASE_div:
1194 1.1 christos return signed_op ? OP_divs : OP_divu;
1195 1.1 christos break;
1196 1.1 christos case OPBASE_mod:
1197 1.1 christos return signed_op ? OP_mods : OP_modu;
1198 1.1 christos break;
1199 1.1 christos case OPBASE_mac:
1200 1.1 christos return signed_op ? OP_macs : OP_macu;
1201 1.1 christos break;
1202 1.1 christos case OPBASE_qmul:
1203 1.1 christos return signed_op ? OP_qmuls : OP_qmulu;
1204 1.1 christos break;
1205 1.1 christos default:
1206 1.1 christos abort ();
1207 1.1 christos }
1208 1.1 christos
1209 1.1 christos return OP_INVALID;
1210 1.1 christos }
1211 1.1 christos
1212 1.1 christos struct opcode
1213 1.1 christos {
1214 1.1 christos /* The operation that this opcode performs. */
1215 1.1 christos enum optr operator;
1216 1.1 christos
1217 1.1 christos /* The size of this operation. May be -1 if it is implied
1218 1.1 christos in the operands or if size is not applicable. */
1219 1.1 christos short osize;
1220 1.1 christos
1221 1.1 christos /* Some operations need this function to work out which operation
1222 1.1 christos is intended. */
1223 1.1 christos discriminator_f discriminator;
1224 1.1 christos
1225 1.1 christos /* A function returning the number of bytes in this instruction. */
1226 1.1 christos insn_bytes_f insn_bytes;
1227 1.1 christos
1228 1.1 christos operands_f operands;
1229 1.1 christos operands_f operands2;
1230 1.1 christos };
1231 1.1 christos
1232 1.1 christos static const struct opcode page2[] =
1233 1.1 christos {
1234 1.1 christos [0x00] = {OP_ld, -1, 0, opr_n_bytes_p1, reg_s_opr, 0},
1235 1.1 christos [0x01] = {OP_st, -1, 0, opr_n_bytes_p1, reg_s_opr, 0},
1236 1.1 christos [0x02] = {OP_cmp, -1, 0, opr_n_bytes_p1, reg_s_opr, 0},
1237 1.1 christos [0x03] = {OP_ld, -1, 0, four, reg_s_imm, 0},
1238 1.1 christos [0x04] = {OP_cmp, -1, 0, four, reg_s_imm, 0},
1239 1.1 christos [0x05] = {OP_stop, -1, 0, single, 0, 0},
1240 1.1 christos [0x06] = {OP_wai, -1, 0, single, 0, 0},
1241 1.1 christos [0x07] = {OP_sys, -1, 0, single, 0, 0},
1242 1.1 christos [0x08] = {0xFFFF, -1, bit_field_discrim, bfextins_n_bytes, bit_field_decode, 0}, /* BFEXT / BFINS */
1243 1.1 christos [0x09] = {0xFFFF, -1, bit_field_discrim, bfextins_n_bytes, bit_field_decode, 0},
1244 1.1 christos [0x0a] = {0xFFFF, -1, bit_field_discrim, bfextins_n_bytes, bit_field_decode, 0},
1245 1.1 christos [0x0b] = {0xFFFF, -1, bit_field_discrim, bfextins_n_bytes, bit_field_decode, 0},
1246 1.1 christos [0x0c] = {0xFFFF, -1, bit_field_discrim, bfextins_n_bytes, bit_field_decode, 0},
1247 1.1 christos [0x0d] = {0xFFFF, -1, bit_field_discrim, bfextins_n_bytes, bit_field_decode, 0},
1248 1.1 christos [0x0e] = {0xFFFF, -1, bit_field_discrim, bfextins_n_bytes, bit_field_decode, 0},
1249 1.1 christos [0x0f] = {0xFFFF, -1, bit_field_discrim, bfextins_n_bytes, bit_field_decode, 0},
1250 1.1 christos [0x10] = {OP_minu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1251 1.1 christos [0x11] = {OP_minu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1252 1.1 christos [0x12] = {OP_minu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1253 1.1 christos [0x13] = {OP_minu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1254 1.1 christos [0x14] = {OP_minu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1255 1.1 christos [0x15] = {OP_minu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1256 1.1 christos [0x16] = {OP_minu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1257 1.1 christos [0x17] = {OP_minu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1258 1.1 christos [0x18] = {OP_maxu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1259 1.1 christos [0x19] = {OP_maxu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1260 1.1 christos [0x1a] = {OP_maxu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1261 1.1 christos [0x1b] = {OP_maxu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1262 1.1 christos [0x1c] = {OP_maxu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1263 1.1 christos [0x1d] = {OP_maxu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1264 1.1 christos [0x1e] = {OP_maxu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1265 1.1 christos [0x1f] = {OP_maxu, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1266 1.1 christos [0x20] = {OP_mins, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1267 1.1 christos [0x21] = {OP_mins, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1268 1.1 christos [0x22] = {OP_mins, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1269 1.1 christos [0x23] = {OP_mins, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1270 1.1 christos [0x24] = {OP_mins, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1271 1.1 christos [0x25] = {OP_mins, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1272 1.1 christos [0x26] = {OP_mins, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1273 1.1 christos [0x27] = {OP_mins, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1274 1.1 christos [0x28] = {OP_maxs, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1275 1.1 christos [0x29] = {OP_maxs, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1276 1.1 christos [0x2a] = {OP_maxs, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1277 1.1 christos [0x2b] = {OP_maxs, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1278 1.1 christos [0x2c] = {OP_maxs, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1279 1.1 christos [0x2d] = {OP_maxs, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1280 1.1 christos [0x2e] = {OP_maxs, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1281 1.1 christos [0x2f] = {OP_maxs, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1282 1.1 christos [0x30] = {OPBASE_div, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1283 1.1 christos [0x31] = {OPBASE_div, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1284 1.1 christos [0x32] = {OPBASE_div, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1285 1.1 christos [0x33] = {OPBASE_div, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1286 1.1 christos [0x34] = {OPBASE_div, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1287 1.1 christos [0x35] = {OPBASE_div, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1288 1.1 christos [0x36] = {OPBASE_div, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1289 1.1 christos [0x37] = {OPBASE_div, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1290 1.1 christos [0x38] = {OPBASE_mod, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1291 1.1 christos [0x39] = {OPBASE_mod, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1292 1.1 christos [0x3a] = {OPBASE_mod, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1293 1.1 christos [0x3b] = {OPBASE_mod, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1294 1.1 christos [0x3c] = {OPBASE_mod, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1295 1.1 christos [0x3d] = {OPBASE_mod, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1296 1.1 christos [0x3e] = {OPBASE_mod, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1297 1.1 christos [0x3f] = {OPBASE_mod, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1298 1.1 christos [0x40] = {OP_abs, -1, 0, single, z_reg, 0},
1299 1.1 christos [0x41] = {OP_abs, -1, 0, single, z_reg, 0},
1300 1.1 christos [0x42] = {OP_abs, -1, 0, single, z_reg, 0},
1301 1.1 christos [0x43] = {OP_abs, -1, 0, single, z_reg, 0},
1302 1.1 christos [0x44] = {OP_abs, -1, 0, single, z_reg, 0},
1303 1.1 christos [0x45] = {OP_abs, -1, 0, single, z_reg, 0},
1304 1.1 christos [0x46] = {OP_abs, -1, 0, single, z_reg, 0},
1305 1.1 christos [0x47] = {OP_abs, -1, 0, single, z_reg, 0},
1306 1.1 christos [0x48] = {OPBASE_mac, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1307 1.1 christos [0x49] = {OPBASE_mac, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1308 1.1 christos [0x4a] = {OPBASE_mac, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1309 1.1 christos [0x4b] = {OPBASE_mac, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1310 1.1 christos [0x4c] = {OPBASE_mac, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1311 1.1 christos [0x4d] = {OPBASE_mac, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1312 1.1 christos [0x4e] = {OPBASE_mac, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1313 1.1 christos [0x4f] = {OPBASE_mac, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1314 1.1 christos [0x50] = {OP_adc, -1, 0, three, z_reg, z_imm1234_0base},
1315 1.1 christos [0x51] = {OP_adc, -1, 0, three, z_reg, z_imm1234_0base},
1316 1.1 christos [0x52] = {OP_adc, -1, 0, three, z_reg, z_imm1234_0base},
1317 1.1 christos [0x53] = {OP_adc, -1, 0, three, z_reg, z_imm1234_0base},
1318 1.1 christos [0x54] = {OP_adc, -1, 0, two, z_reg, z_imm1234_0base},
1319 1.1 christos [0x55] = {OP_adc, -1, 0, two, z_reg, z_imm1234_0base},
1320 1.1 christos [0x56] = {OP_adc, -1, 0, five, z_reg, z_imm1234_0base},
1321 1.1 christos [0x57] = {OP_adc, -1, 0, five, z_reg, z_imm1234_0base},
1322 1.1 christos [0x58] = {OP_bit, -1, 0, three, z_reg, z_imm1234_8base},
1323 1.1 christos [0x59] = {OP_bit, -1, 0, three, z_reg, z_imm1234_8base},
1324 1.1 christos [0x5a] = {OP_bit, -1, 0, three, z_reg, z_imm1234_8base},
1325 1.1 christos [0x5b] = {OP_bit, -1, 0, three, z_reg, z_imm1234_8base},
1326 1.1 christos [0x5c] = {OP_bit, -1, 0, two, z_reg, z_imm1234_8base},
1327 1.1 christos [0x5d] = {OP_bit, -1, 0, two, z_reg, z_imm1234_8base},
1328 1.1 christos [0x5e] = {OP_bit, -1, 0, five, z_reg, z_imm1234_8base},
1329 1.1 christos [0x5f] = {OP_bit, -1, 0, five, z_reg, z_imm1234_8base},
1330 1.1 christos [0x60] = {OP_adc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1331 1.1 christos [0x61] = {OP_adc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1332 1.1 christos [0x62] = {OP_adc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1333 1.1 christos [0x63] = {OP_adc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1334 1.1 christos [0x64] = {OP_adc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1335 1.1 christos [0x65] = {OP_adc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1336 1.1 christos [0x66] = {OP_adc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1337 1.1 christos [0x67] = {OP_adc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1338 1.1 christos [0x68] = {OP_bit, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1339 1.1 christos [0x69] = {OP_bit, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1340 1.1 christos [0x6a] = {OP_bit, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1341 1.1 christos [0x6b] = {OP_bit, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1342 1.1 christos [0x6c] = {OP_bit, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1343 1.1 christos [0x6d] = {OP_bit, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1344 1.1 christos [0x6e] = {OP_bit, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1345 1.1 christos [0x6f] = {OP_bit, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1346 1.1 christos [0x70] = {OP_sbc, -1, 0, three, z_reg, z_imm1234_0base},
1347 1.1 christos [0x71] = {OP_sbc, -1, 0, three, z_reg, z_imm1234_0base},
1348 1.1 christos [0x72] = {OP_sbc, -1, 0, three, z_reg, z_imm1234_0base},
1349 1.1 christos [0x73] = {OP_sbc, -1, 0, three, z_reg, z_imm1234_0base},
1350 1.1 christos [0x74] = {OP_sbc, -1, 0, two, z_reg, z_imm1234_0base},
1351 1.1 christos [0x75] = {OP_sbc, -1, 0, two, z_reg, z_imm1234_0base},
1352 1.1 christos [0x76] = {OP_sbc, -1, 0, five, z_reg, z_imm1234_0base},
1353 1.1 christos [0x77] = {OP_sbc, -1, 0, five, z_reg, z_imm1234_0base},
1354 1.1 christos [0x78] = {OP_eor, -1, 0, three, z_reg, z_imm1234_8base},
1355 1.1 christos [0x79] = {OP_eor, -1, 0, three, z_reg, z_imm1234_8base},
1356 1.1 christos [0x7a] = {OP_eor, -1, 0, three, z_reg, z_imm1234_8base},
1357 1.1 christos [0x7b] = {OP_eor, -1, 0, three, z_reg, z_imm1234_8base},
1358 1.1 christos [0x7c] = {OP_eor, -1, 0, two, z_reg, z_imm1234_8base},
1359 1.1 christos [0x7d] = {OP_eor, -1, 0, two, z_reg, z_imm1234_8base},
1360 1.1 christos [0x7e] = {OP_eor, -1, 0, five, z_reg, z_imm1234_8base},
1361 1.1 christos [0x7f] = {OP_eor, -1, 0, five, z_reg, z_imm1234_8base},
1362 1.1 christos [0x80] = {OP_sbc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1363 1.1 christos [0x81] = {OP_sbc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1364 1.1 christos [0x82] = {OP_sbc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1365 1.1 christos [0x83] = {OP_sbc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1366 1.1 christos [0x84] = {OP_sbc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1367 1.1 christos [0x85] = {OP_sbc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1368 1.1 christos [0x86] = {OP_sbc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1369 1.1 christos [0x87] = {OP_sbc, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1370 1.1 christos [0x88] = {OP_eor, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1371 1.1 christos [0x89] = {OP_eor, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1372 1.1 christos [0x8a] = {OP_eor, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1373 1.1 christos [0x8b] = {OP_eor, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1374 1.1 christos [0x8c] = {OP_eor, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1375 1.1 christos [0x8d] = {OP_eor, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1376 1.1 christos [0x8e] = {OP_eor, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1377 1.1 christos [0x8f] = {OP_eor, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1378 1.1 christos [0x90] = {OP_rti, -1, 0, single, 0, 0},
1379 1.1 christos [0x91] = {OP_clb, -1, 0, two, z_tfr, 0},
1380 1.1 christos [0x92] = {OP_trap, -1, 0, single, trap_decode, 0},
1381 1.1 christos [0x93] = {OP_trap, -1, 0, single, trap_decode, 0},
1382 1.1 christos [0x94] = {OP_trap, -1, 0, single, trap_decode, 0},
1383 1.1 christos [0x95] = {OP_trap, -1, 0, single, trap_decode, 0},
1384 1.1 christos [0x96] = {OP_trap, -1, 0, single, trap_decode, 0},
1385 1.1 christos [0x97] = {OP_trap, -1, 0, single, trap_decode, 0},
1386 1.1 christos [0x98] = {OP_trap, -1, 0, single, trap_decode, 0},
1387 1.1 christos [0x99] = {OP_trap, -1, 0, single, trap_decode, 0},
1388 1.1 christos [0x9a] = {OP_trap, -1, 0, single, trap_decode, 0},
1389 1.1 christos [0x9b] = {OP_trap, -1, 0, single, trap_decode, 0},
1390 1.1 christos [0x9c] = {OP_trap, -1, 0, single, trap_decode, 0},
1391 1.1 christos [0x9d] = {OP_trap, -1, 0, single, trap_decode, 0},
1392 1.1 christos [0x9e] = {OP_trap, -1, 0, single, trap_decode, 0},
1393 1.1 christos [0x9f] = {OP_trap, -1, 0, single, trap_decode, 0},
1394 1.1 christos [0xa0] = {OP_sat, -1, 0, single, z_reg, 0},
1395 1.1 christos [0xa1] = {OP_sat, -1, 0, single, z_reg, 0},
1396 1.1 christos [0xa2] = {OP_sat, -1, 0, single, z_reg, 0},
1397 1.1 christos [0xa3] = {OP_sat, -1, 0, single, z_reg, 0},
1398 1.1 christos [0xa4] = {OP_sat, -1, 0, single, z_reg, 0},
1399 1.1 christos [0xa5] = {OP_sat, -1, 0, single, z_reg, 0},
1400 1.1 christos [0xa6] = {OP_sat, -1, 0, single, z_reg, 0},
1401 1.1 christos [0xa7] = {OP_sat, -1, 0, single, z_reg, 0},
1402 1.1 christos [0xa8] = {OP_trap, -1, 0, single, trap_decode, 0},
1403 1.1 christos [0xa9] = {OP_trap, -1, 0, single, trap_decode, 0},
1404 1.1 christos [0xaa] = {OP_trap, -1, 0, single, trap_decode, 0},
1405 1.1 christos [0xab] = {OP_trap, -1, 0, single, trap_decode, 0},
1406 1.1 christos [0xac] = {OP_trap, -1, 0, single, trap_decode, 0},
1407 1.1 christos [0xad] = {OP_trap, -1, 0, single, trap_decode, 0},
1408 1.1 christos [0xae] = {OP_trap, -1, 0, single, trap_decode, 0},
1409 1.1 christos [0xaf] = {OP_trap, -1, 0, single, trap_decode, 0},
1410 1.1 christos [0xb0] = {OPBASE_qmul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1411 1.1 christos [0xb1] = {OPBASE_qmul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1412 1.1 christos [0xb2] = {OPBASE_qmul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1413 1.1 christos [0xb3] = {OPBASE_qmul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1414 1.1 christos [0xb4] = {OPBASE_qmul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1415 1.1 christos [0xb5] = {OPBASE_qmul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1416 1.1 christos [0xb6] = {OPBASE_qmul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1417 1.1 christos [0xb7] = {OPBASE_qmul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1418 1.1 christos [0xb8] = {OP_trap, -1, 0, single, trap_decode, 0},
1419 1.1 christos [0xb9] = {OP_trap, -1, 0, single, trap_decode, 0},
1420 1.1 christos [0xba] = {OP_trap, -1, 0, single, trap_decode, 0},
1421 1.1 christos [0xbb] = {OP_trap, -1, 0, single, trap_decode, 0},
1422 1.1 christos [0xbc] = {OP_trap, -1, 0, single, trap_decode, 0},
1423 1.1 christos [0xbd] = {OP_trap, -1, 0, single, trap_decode, 0},
1424 1.1 christos [0xbe] = {OP_trap, -1, 0, single, trap_decode, 0},
1425 1.1 christos [0xbf] = {OP_trap, -1, 0, single, trap_decode, 0},
1426 1.1 christos [0xc0] = {OP_trap, -1, 0, single, trap_decode, 0},
1427 1.1 christos [0xc1] = {OP_trap, -1, 0, single, trap_decode, 0},
1428 1.1 christos [0xc2] = {OP_trap, -1, 0, single, trap_decode, 0},
1429 1.1 christos [0xc3] = {OP_trap, -1, 0, single, trap_decode, 0},
1430 1.1 christos [0xc4] = {OP_trap, -1, 0, single, trap_decode, 0},
1431 1.1 christos [0xc5] = {OP_trap, -1, 0, single, trap_decode, 0},
1432 1.1 christos [0xc6] = {OP_trap, -1, 0, single, trap_decode, 0},
1433 1.1 christos [0xc7] = {OP_trap, -1, 0, single, trap_decode, 0},
1434 1.1 christos [0xc8] = {OP_trap, -1, 0, single, trap_decode, 0},
1435 1.1 christos [0xc9] = {OP_trap, -1, 0, single, trap_decode, 0},
1436 1.1 christos [0xca] = {OP_trap, -1, 0, single, trap_decode, 0},
1437 1.1 christos [0xcb] = {OP_trap, -1, 0, single, trap_decode, 0},
1438 1.1 christos [0xcc] = {OP_trap, -1, 0, single, trap_decode, 0},
1439 1.1 christos [0xcd] = {OP_trap, -1, 0, single, trap_decode, 0},
1440 1.1 christos [0xce] = {OP_trap, -1, 0, single, trap_decode, 0},
1441 1.1 christos [0xcf] = {OP_trap, -1, 0, single, trap_decode, 0},
1442 1.1 christos [0xd0] = {OP_trap, -1, 0, single, trap_decode, 0},
1443 1.1 christos [0xd1] = {OP_trap, -1, 0, single, trap_decode, 0},
1444 1.1 christos [0xd2] = {OP_trap, -1, 0, single, trap_decode, 0},
1445 1.1 christos [0xd3] = {OP_trap, -1, 0, single, trap_decode, 0},
1446 1.1 christos [0xd4] = {OP_trap, -1, 0, single, trap_decode, 0},
1447 1.1 christos [0xd5] = {OP_trap, -1, 0, single, trap_decode, 0},
1448 1.1 christos [0xd6] = {OP_trap, -1, 0, single, trap_decode, 0},
1449 1.1 christos [0xd7] = {OP_trap, -1, 0, single, trap_decode, 0},
1450 1.1 christos [0xd8] = {OP_trap, -1, 0, single, trap_decode, 0},
1451 1.1 christos [0xd9] = {OP_trap, -1, 0, single, trap_decode, 0},
1452 1.1 christos [0xda] = {OP_trap, -1, 0, single, trap_decode, 0},
1453 1.1 christos [0xdb] = {OP_trap, -1, 0, single, trap_decode, 0},
1454 1.1 christos [0xdc] = {OP_trap, -1, 0, single, trap_decode, 0},
1455 1.1 christos [0xdd] = {OP_trap, -1, 0, single, trap_decode, 0},
1456 1.1 christos [0xde] = {OP_trap, -1, 0, single, trap_decode, 0},
1457 1.1 christos [0xdf] = {OP_trap, -1, 0, single, trap_decode, 0},
1458 1.1 christos [0xe0] = {OP_trap, -1, 0, single, trap_decode, 0},
1459 1.1 christos [0xe1] = {OP_trap, -1, 0, single, trap_decode, 0},
1460 1.1 christos [0xe2] = {OP_trap, -1, 0, single, trap_decode, 0},
1461 1.1 christos [0xe3] = {OP_trap, -1, 0, single, trap_decode, 0},
1462 1.1 christos [0xe4] = {OP_trap, -1, 0, single, trap_decode, 0},
1463 1.1 christos [0xe5] = {OP_trap, -1, 0, single, trap_decode, 0},
1464 1.1 christos [0xe6] = {OP_trap, -1, 0, single, trap_decode, 0},
1465 1.1 christos [0xe7] = {OP_trap, -1, 0, single, trap_decode, 0},
1466 1.1 christos [0xe8] = {OP_trap, -1, 0, single, trap_decode, 0},
1467 1.1 christos [0xe9] = {OP_trap, -1, 0, single, trap_decode, 0},
1468 1.1 christos [0xea] = {OP_trap, -1, 0, single, trap_decode, 0},
1469 1.1 christos [0xeb] = {OP_trap, -1, 0, single, trap_decode, 0},
1470 1.1 christos [0xec] = {OP_trap, -1, 0, single, trap_decode, 0},
1471 1.1 christos [0xed] = {OP_trap, -1, 0, single, trap_decode, 0},
1472 1.1 christos [0xee] = {OP_trap, -1, 0, single, trap_decode, 0},
1473 1.1 christos [0xef] = {OP_trap, -1, 0, single, trap_decode, 0},
1474 1.1 christos [0xf0] = {OP_trap, -1, 0, single, trap_decode, 0},
1475 1.1 christos [0xf1] = {OP_trap, -1, 0, single, trap_decode, 0},
1476 1.1 christos [0xf2] = {OP_trap, -1, 0, single, trap_decode, 0},
1477 1.1 christos [0xf3] = {OP_trap, -1, 0, single, trap_decode, 0},
1478 1.1 christos [0xf4] = {OP_trap, -1, 0, single, trap_decode, 0},
1479 1.1 christos [0xf5] = {OP_trap, -1, 0, single, trap_decode, 0},
1480 1.1 christos [0xf6] = {OP_trap, -1, 0, single, trap_decode, 0},
1481 1.1 christos [0xf7] = {OP_trap, -1, 0, single, trap_decode, 0},
1482 1.1 christos [0xf8] = {OP_trap, -1, 0, single, trap_decode, 0},
1483 1.1 christos [0xf9] = {OP_trap, -1, 0, single, trap_decode, 0},
1484 1.1 christos [0xfa] = {OP_trap, -1, 0, single, trap_decode, 0},
1485 1.1 christos [0xfb] = {OP_trap, -1, 0, single, trap_decode, 0},
1486 1.1 christos [0xfc] = {OP_trap, -1, 0, single, trap_decode, 0},
1487 1.1 christos [0xfd] = {OP_trap, -1, 0, single, trap_decode, 0},
1488 1.1 christos [0xfe] = {OP_trap, -1, 0, single, trap_decode, 0},
1489 1.1 christos [0xff] = {OP_trap, -1, 0, single, trap_decode, 0},
1490 1.1 christos };
1491 1.1 christos
1492 1.1 christos static const struct opcode page1[] =
1493 1.1 christos {
1494 1.1 christos [0x00] = {OP_bgnd, -1, 0, single, 0, 0},
1495 1.1 christos [0x01] = {OP_nop, -1, 0, single, 0, 0},
1496 1.1 christos [0x02] = {OP_brclr, -1, 0, bm_rel_n_bytes, bm_rel_decode, 0},
1497 1.1 christos [0x03] = {OP_brset, -1, 0, bm_rel_n_bytes, bm_rel_decode, 0},
1498 1.1 christos [0x04] = {0xFFFF, -1, psh_pul_discrim, two, psh_pul_decode, 0}, /* psh/pul */
1499 1.1 christos [0x05] = {OP_rts, -1, 0, single, 0, 0},
1500 1.1 christos [0x06] = {OP_lea, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1501 1.1 christos [0x07] = {OP_lea, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1502 1.1 christos [0x08] = {OP_lea, -1, 0, opr_n_bytes_p1, lea_reg_xys_opr, 0},
1503 1.1 christos [0x09] = {OP_lea, -1, 0, opr_n_bytes_p1, lea_reg_xys_opr, 0},
1504 1.1 christos [0x0a] = {OP_lea, -1, 0, opr_n_bytes_p1, lea_reg_xys_opr, 0},
1505 1.1 christos [0x0b] = {0xFFFF, -1, loop_primitive_discrim, loop_prim_n_bytes, loop_primitive_decode, 0}, /* Loop primitives TBcc / DBcc */
1506 1.1 christos [0x0c] = {OP_mov, 0, 0, mov_imm_opr_n_bytes, mov_imm_opr, 0},
1507 1.1 christos [0x0d] = {OP_mov, 1, 0, mov_imm_opr_n_bytes, mov_imm_opr, 0},
1508 1.1 christos [0x0e] = {OP_mov, 2, 0, mov_imm_opr_n_bytes, mov_imm_opr, 0},
1509 1.1 christos [0x0f] = {OP_mov, 3, 0, mov_imm_opr_n_bytes, mov_imm_opr, 0},
1510 1.1 christos [0x10] = {0xFFFF, -1, shift_discrim, shift_n_bytes, shift_decode, 0}, /* lsr/lsl/asl/asr/rol/ror */
1511 1.1 christos [0x11] = {0xFFFF, -1, shift_discrim, shift_n_bytes, shift_decode, 0},
1512 1.1 christos [0x12] = {0xFFFF, -1, shift_discrim, shift_n_bytes, shift_decode, 0},
1513 1.1 christos [0x13] = {0xFFFF, -1, shift_discrim, shift_n_bytes, shift_decode, 0},
1514 1.1 christos [0x14] = {0xFFFF, -1, shift_discrim, shift_n_bytes, shift_decode, 0},
1515 1.1 christos [0x15] = {0xFFFF, -1, shift_discrim, shift_n_bytes, shift_decode, 0},
1516 1.1 christos [0x16] = {0xFFFF, -1, shift_discrim, shift_n_bytes, shift_decode, 0},
1517 1.1 christos [0x17] = {0xFFFF, -1, shift_discrim, shift_n_bytes, shift_decode, 0},
1518 1.1 christos [0x18] = {OP_lea, -1, 0, two, lea_reg_xys, NULL},
1519 1.1 christos [0x19] = {OP_lea, -1, 0, two, lea_reg_xys, NULL},
1520 1.1 christos [0x1a] = {OP_lea, -1, 0, two, lea_reg_xys, NULL},
1521 1.1 christos /* 0x1b PG2 */
1522 1.1 christos [0x1c] = {OP_mov, 0, 0, opr_n_bytes2, z_opr_decode2, 0},
1523 1.1 christos [0x1d] = {OP_mov, 1, 0, opr_n_bytes2, z_opr_decode2, 0},
1524 1.1 christos [0x1e] = {OP_mov, 2, 0, opr_n_bytes2, z_opr_decode2, 0},
1525 1.1 christos [0x1f] = {OP_mov, 3, 0, opr_n_bytes2, z_opr_decode2, 0},
1526 1.1 christos [0x20] = {OP_bra, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
1527 1.1 christos [0x21] = {OP_bsr, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
1528 1.1 christos [0x22] = {OP_bhi, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
1529 1.1 christos [0x23] = {OP_bls, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
1530 1.1 christos [0x24] = {OP_bcc, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
1531 1.1 christos [0x25] = {OP_bcs, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
1532 1.1 christos [0x26] = {OP_bne, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
1533 1.1 christos [0x27] = {OP_beq, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
1534 1.1 christos [0x28] = {OP_bvc, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
1535 1.1 christos [0x29] = {OP_bvs, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
1536 1.1 christos [0x2a] = {OP_bpl, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
1537 1.1 christos [0x2b] = {OP_bmi, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
1538 1.1 christos [0x2c] = {OP_bge, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
1539 1.1 christos [0x2d] = {OP_blt, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
1540 1.1 christos [0x2e] = {OP_bgt, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
1541 1.1 christos [0x2f] = {OP_ble, -1, 0, pcrel_15bit, decode_rel_15_7, 0},
1542 1.1 christos [0x30] = {OP_inc, -1, 0, single, z_reg, 0},
1543 1.1 christos [0x31] = {OP_inc, -1, 0, single, z_reg, 0},
1544 1.1 christos [0x32] = {OP_inc, -1, 0, single, z_reg, 0},
1545 1.1 christos [0x33] = {OP_inc, -1, 0, single, z_reg, 0},
1546 1.1 christos [0x34] = {OP_inc, -1, 0, single, z_reg, 0},
1547 1.1 christos [0x35] = {OP_inc, -1, 0, single, z_reg, 0},
1548 1.1 christos [0x36] = {OP_inc, -1, 0, single, z_reg, 0},
1549 1.1 christos [0x37] = {OP_inc, -1, 0, single, z_reg, 0},
1550 1.1 christos [0x38] = {OP_clr, -1, 0, single, z_reg, 0},
1551 1.1 christos [0x39] = {OP_clr, -1, 0, single, z_reg, 0},
1552 1.1 christos [0x3a] = {OP_clr, -1, 0, single, z_reg, 0},
1553 1.1 christos [0x3b] = {OP_clr, -1, 0, single, z_reg, 0},
1554 1.1 christos [0x3c] = {OP_clr, -1, 0, single, z_reg, 0},
1555 1.1 christos [0x3d] = {OP_clr, -1, 0, single, z_reg, 0},
1556 1.1 christos [0x3e] = {OP_clr, -1, 0, single, z_reg, 0},
1557 1.1 christos [0x3f] = {OP_clr, -1, 0, single, z_reg, 0},
1558 1.1 christos [0x40] = {OP_dec, -1, 0, single, z_reg, 0},
1559 1.1 christos [0x41] = {OP_dec, -1, 0, single, z_reg, 0},
1560 1.1 christos [0x42] = {OP_dec, -1, 0, single, z_reg, 0},
1561 1.1 christos [0x43] = {OP_dec, -1, 0, single, z_reg, 0},
1562 1.1 christos [0x44] = {OP_dec, -1, 0, single, z_reg, 0},
1563 1.1 christos [0x45] = {OP_dec, -1, 0, single, z_reg, 0},
1564 1.1 christos [0x46] = {OP_dec, -1, 0, single, z_reg, 0},
1565 1.1 christos [0x47] = {OP_dec, -1, 0, single, z_reg, 0},
1566 1.1 christos [0x48] = {OPBASE_mul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1567 1.1 christos [0x49] = {OPBASE_mul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1568 1.1 christos [0x4a] = {OPBASE_mul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1569 1.1 christos [0x4b] = {OPBASE_mul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1570 1.1 christos [0x4c] = {OPBASE_mul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1571 1.1 christos [0x4d] = {OPBASE_mul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1572 1.1 christos [0x4e] = {OPBASE_mul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1573 1.1 christos [0x4f] = {OPBASE_mul, -1, mul_discrim, mul_n_bytes, mul_decode, 0},
1574 1.1 christos [0x50] = {OP_add, -1, 0, three, z_reg, z_imm1234_0base},
1575 1.1 christos [0x51] = {OP_add, -1, 0, three, z_reg, z_imm1234_0base},
1576 1.1 christos [0x52] = {OP_add, -1, 0, three, z_reg, z_imm1234_0base},
1577 1.1 christos [0x53] = {OP_add, -1, 0, three, z_reg, z_imm1234_0base},
1578 1.1 christos [0x54] = {OP_add, -1, 0, two, z_reg, z_imm1234_0base},
1579 1.1 christos [0x55] = {OP_add, -1, 0, two, z_reg, z_imm1234_0base},
1580 1.1 christos [0x56] = {OP_add, -1, 0, five, z_reg, z_imm1234_0base},
1581 1.1 christos [0x57] = {OP_add, -1, 0, five, z_reg, z_imm1234_0base},
1582 1.1 christos [0x58] = {OP_and, -1, 0, three, z_reg, z_imm1234_8base},
1583 1.1 christos [0x59] = {OP_and, -1, 0, three, z_reg, z_imm1234_8base},
1584 1.1 christos [0x5a] = {OP_and, -1, 0, three, z_reg, z_imm1234_8base},
1585 1.1 christos [0x5b] = {OP_and, -1, 0, three, z_reg, z_imm1234_8base},
1586 1.1 christos [0x5c] = {OP_and, -1, 0, two, z_reg, z_imm1234_8base},
1587 1.1 christos [0x5d] = {OP_and, -1, 0, two, z_reg, z_imm1234_8base},
1588 1.1 christos [0x5e] = {OP_and, -1, 0, five, z_reg, z_imm1234_8base},
1589 1.1 christos [0x5f] = {OP_and, -1, 0, five, z_reg, z_imm1234_8base},
1590 1.1 christos [0x60] = {OP_add, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1591 1.1 christos [0x61] = {OP_add, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1592 1.1 christos [0x62] = {OP_add, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1593 1.1 christos [0x63] = {OP_add, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1594 1.1 christos [0x64] = {OP_add, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1595 1.1 christos [0x65] = {OP_add, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1596 1.1 christos [0x66] = {OP_add, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1597 1.1 christos [0x67] = {OP_add, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1598 1.1 christos [0x68] = {OP_and, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1599 1.1 christos [0x69] = {OP_and, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1600 1.1 christos [0x6a] = {OP_and, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1601 1.1 christos [0x6b] = {OP_and, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1602 1.1 christos [0x6c] = {OP_and, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1603 1.1 christos [0x6d] = {OP_and, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1604 1.1 christos [0x6e] = {OP_and, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1605 1.1 christos [0x6f] = {OP_and, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1606 1.1 christos [0x70] = {OP_sub, -1, 0, three, z_reg, z_imm1234_0base},
1607 1.1 christos [0x71] = {OP_sub, -1, 0, three, z_reg, z_imm1234_0base},
1608 1.1 christos [0x72] = {OP_sub, -1, 0, three, z_reg, z_imm1234_0base},
1609 1.1 christos [0x73] = {OP_sub, -1, 0, three, z_reg, z_imm1234_0base},
1610 1.1 christos [0x74] = {OP_sub, -1, 0, two, z_reg, z_imm1234_0base},
1611 1.1 christos [0x75] = {OP_sub, -1, 0, two, z_reg, z_imm1234_0base},
1612 1.1 christos [0x76] = {OP_sub, -1, 0, five, z_reg, z_imm1234_0base},
1613 1.1 christos [0x77] = {OP_sub, -1, 0, five, z_reg, z_imm1234_0base},
1614 1.1 christos [0x78] = {OP_or, -1, 0, three, z_reg, z_imm1234_8base},
1615 1.1 christos [0x79] = {OP_or, -1, 0, three, z_reg, z_imm1234_8base},
1616 1.1 christos [0x7a] = {OP_or, -1, 0, three, z_reg, z_imm1234_8base},
1617 1.1 christos [0x7b] = {OP_or, -1, 0, three, z_reg, z_imm1234_8base},
1618 1.1 christos [0x7c] = {OP_or, -1, 0, two, z_reg, z_imm1234_8base},
1619 1.1 christos [0x7d] = {OP_or, -1, 0, two, z_reg, z_imm1234_8base},
1620 1.1 christos [0x7e] = {OP_or, -1, 0, five, z_reg, z_imm1234_8base},
1621 1.1 christos [0x7f] = {OP_or, -1, 0, five, z_reg, z_imm1234_8base},
1622 1.1 christos [0x80] = {OP_sub, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1623 1.1 christos [0x81] = {OP_sub, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1624 1.1 christos [0x82] = {OP_sub, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1625 1.1 christos [0x83] = {OP_sub, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1626 1.1 christos [0x84] = {OP_sub, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1627 1.1 christos [0x85] = {OP_sub, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1628 1.1 christos [0x86] = {OP_sub, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1629 1.1 christos [0x87] = {OP_sub, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1630 1.1 christos [0x88] = {OP_or, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1631 1.1 christos [0x89] = {OP_or, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1632 1.1 christos [0x8a] = {OP_or, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1633 1.1 christos [0x8b] = {OP_or, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1634 1.1 christos [0x8c] = {OP_or, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1635 1.1 christos [0x8d] = {OP_or, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1636 1.1 christos [0x8e] = {OP_or, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1637 1.1 christos [0x8f] = {OP_or, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1638 1.1 christos [0x90] = {OP_ld, -1, 0, three, z_reg, z_imm1234_0base},
1639 1.1 christos [0x91] = {OP_ld, -1, 0, three, z_reg, z_imm1234_0base},
1640 1.1 christos [0x92] = {OP_ld, -1, 0, three, z_reg, z_imm1234_0base},
1641 1.1 christos [0x93] = {OP_ld, -1, 0, three, z_reg, z_imm1234_0base},
1642 1.1 christos [0x94] = {OP_ld, -1, 0, two, z_reg, z_imm1234_0base},
1643 1.1 christos [0x95] = {OP_ld, -1, 0, two, z_reg, z_imm1234_0base},
1644 1.1 christos [0x96] = {OP_ld, -1, 0, five, z_reg, z_imm1234_0base},
1645 1.1 christos [0x97] = {OP_ld, -1, 0, five, z_reg, z_imm1234_0base},
1646 1.1 christos [0x98] = {OP_ld, -1, 0, four, reg_xy, z_imm1234_0base},
1647 1.1 christos [0x99] = {OP_ld, -1, 0, four, reg_xy, z_imm1234_0base},
1648 1.1 christos [0x9a] = {OP_clr, -1, 0, single, reg_xy, 0},
1649 1.1 christos [0x9b] = {OP_clr, -1, 0, single, reg_xy, 0},
1650 1.1 christos [0x9c] = {OP_inc, 0, 0, opr_n_bytes_p1, z_opr_decode, 0},
1651 1.1 christos [0x9d] = {OP_inc, 1, 0, opr_n_bytes_p1, z_opr_decode, 0},
1652 1.1 christos [0x9e] = {OP_tfr, -1, 0, two, z_tfr, NULL},
1653 1.1 christos [0x9f] = {OP_inc, 3, 0, opr_n_bytes_p1, z_opr_decode, 0},
1654 1.1 christos [0xa0] = {OP_ld, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1655 1.1 christos [0xa1] = {OP_ld, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1656 1.1 christos [0xa2] = {OP_ld, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1657 1.1 christos [0xa3] = {OP_ld, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1658 1.1 christos [0xa4] = {OP_ld, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1659 1.1 christos [0xa5] = {OP_ld, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1660 1.1 christos [0xa6] = {OP_ld, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1661 1.1 christos [0xa7] = {OP_ld, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1662 1.1 christos [0xa8] = {OP_ld, -1, 0, opr_n_bytes_p1, reg_xy, z_opr_decode},
1663 1.1 christos [0xa9] = {OP_ld, -1, 0, opr_n_bytes_p1, reg_xy, z_opr_decode},
1664 1.1 christos [0xaa] = {OP_jmp, -1, 0, opr_n_bytes_p1, z_opr_decode, 0},
1665 1.1 christos [0xab] = {OP_jsr, -1, 0, opr_n_bytes_p1, z_opr_decode, 0},
1666 1.1 christos [0xac] = {OP_dec, 0, 0, opr_n_bytes_p1, z_opr_decode, 0},
1667 1.1 christos [0xad] = {OP_dec, 1, 0, opr_n_bytes_p1, z_opr_decode, 0},
1668 1.1 christos [0xae] = {0xFFFF, -1, exg_sex_discrim, two, exg_sex_decode, 0}, /* EXG / SEX */
1669 1.1 christos [0xaf] = {OP_dec, 3, 0, opr_n_bytes_p1, 0, z_opr_decode},
1670 1.1 christos [0xb0] = {OP_ld, -1, 0, four, z_reg, z_ext24_decode},
1671 1.1 christos [0xb1] = {OP_ld, -1, 0, four, z_reg, z_ext24_decode},
1672 1.1 christos [0xb2] = {OP_ld, -1, 0, four, z_reg, z_ext24_decode},
1673 1.1 christos [0xb3] = {OP_ld, -1, 0, four, z_reg, z_ext24_decode},
1674 1.1 christos [0xb4] = {OP_ld, -1, 0, four, z_reg, z_ext24_decode},
1675 1.1 christos [0xb5] = {OP_ld, -1, 0, four, z_reg, z_ext24_decode},
1676 1.1 christos [0xb6] = {OP_ld, -1, 0, four, z_reg, z_ext24_decode},
1677 1.1 christos [0xb7] = {OP_ld, -1, 0, four, z_reg, z_ext24_decode},
1678 1.1 christos [0xb8] = {OP_ld, -1, 0, four, reg_xy, z_ext24_decode},
1679 1.1 christos [0xb9] = {OP_ld, -1, 0, four, reg_xy, z_ext24_decode},
1680 1.1 christos [0xba] = {OP_jmp, -1, 0, four, z_ext24_decode, 0},
1681 1.1 christos [0xbb] = {OP_jsr, -1, 0, four, z_ext24_decode, 0},
1682 1.1 christos [0xbc] = {OP_clr, 0, 0, opr_n_bytes_p1, z_opr_decode, 0},
1683 1.1 christos [0xbd] = {OP_clr, 1, 0, opr_n_bytes_p1, z_opr_decode, 0},
1684 1.1 christos [0xbe] = {OP_clr, 2, 0, opr_n_bytes_p1, z_opr_decode, 0},
1685 1.1 christos [0xbf] = {OP_clr, 3, 0, opr_n_bytes_p1, z_opr_decode, 0},
1686 1.1 christos [0xc0] = {OP_st, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1687 1.1 christos [0xc1] = {OP_st, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1688 1.1 christos [0xc2] = {OP_st, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1689 1.1 christos [0xc3] = {OP_st, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1690 1.1 christos [0xc4] = {OP_st, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1691 1.1 christos [0xc5] = {OP_st, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1692 1.1 christos [0xc6] = {OP_st, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1693 1.1 christos [0xc7] = {OP_st, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1694 1.1 christos [0xc8] = {OP_st, -1, 0, opr_n_bytes_p1, reg_xy, z_opr_decode},
1695 1.1 christos [0xc9] = {OP_st, -1, 0, opr_n_bytes_p1, reg_xy, z_opr_decode},
1696 1.1 christos [0xca] = {OP_ld, -1, 0, three, reg_xy, ld_18bit_decode},
1697 1.1 christos [0xcb] = {OP_ld, -1, 0, three, reg_xy, ld_18bit_decode},
1698 1.1 christos [0xcc] = {OP_com, 0, 0, opr_n_bytes_p1, NULL, z_opr_decode},
1699 1.1 christos [0xcd] = {OP_com, 1, 0, opr_n_bytes_p1, NULL, z_opr_decode},
1700 1.1 christos [0xce] = {OP_andcc, -1, 0, two, imm1_decode, 0},
1701 1.1 christos [0xcf] = {OP_com, 3, 0, opr_n_bytes_p1, NULL, z_opr_decode},
1702 1.1 christos [0xd0] = {OP_st, -1, 0, four, z_reg, z_ext24_decode},
1703 1.1 christos [0xd1] = {OP_st, -1, 0, four, z_reg, z_ext24_decode},
1704 1.1 christos [0xd2] = {OP_st, -1, 0, four, z_reg, z_ext24_decode},
1705 1.1 christos [0xd3] = {OP_st, -1, 0, four, z_reg, z_ext24_decode},
1706 1.1 christos [0xd4] = {OP_st, -1, 0, four, z_reg, z_ext24_decode},
1707 1.1 christos [0xd5] = {OP_st, -1, 0, four, z_reg, z_ext24_decode},
1708 1.1 christos [0xd6] = {OP_st, -1, 0, four, z_reg, z_ext24_decode},
1709 1.1 christos [0xd7] = {OP_st, -1, 0, four, z_reg, z_ext24_decode},
1710 1.1 christos [0xd8] = {OP_st, -1, 0, four, reg_xy, z_ext24_decode},
1711 1.1 christos [0xd9] = {OP_st, -1, 0, four, reg_xy, z_ext24_decode},
1712 1.1 christos [0xda] = {OP_ld, -1, 0, three, reg_xy, ld_18bit_decode},
1713 1.1 christos [0xdb] = {OP_ld, -1, 0, three, reg_xy, ld_18bit_decode},
1714 1.1 christos [0xdc] = {OP_neg, 0, 0, opr_n_bytes_p1, NULL, z_opr_decode},
1715 1.1 christos [0xdd] = {OP_neg, 1, 0, opr_n_bytes_p1, NULL, z_opr_decode},
1716 1.1 christos [0xde] = {OP_orcc, -1, 0, two, imm1_decode, 0},
1717 1.1 christos [0xdf] = {OP_neg, 3, 0, opr_n_bytes_p1, NULL, z_opr_decode},
1718 1.1 christos [0xe0] = {OP_cmp, -1, 0, three, z_reg, z_imm1234_0base},
1719 1.1 christos [0xe1] = {OP_cmp, -1, 0, three, z_reg, z_imm1234_0base},
1720 1.1 christos [0xe2] = {OP_cmp, -1, 0, three, z_reg, z_imm1234_0base},
1721 1.1 christos [0xe3] = {OP_cmp, -1, 0, three, z_reg, z_imm1234_0base},
1722 1.1 christos [0xe4] = {OP_cmp, -1, 0, two, z_reg, z_imm1234_0base},
1723 1.1 christos [0xe5] = {OP_cmp, -1, 0, two, z_reg, z_imm1234_0base},
1724 1.1 christos [0xe6] = {OP_cmp, -1, 0, five, z_reg, z_imm1234_0base},
1725 1.1 christos [0xe7] = {OP_cmp, -1, 0, five, z_reg, z_imm1234_0base},
1726 1.1 christos [0xe8] = {OP_cmp, -1, 0, four, reg_xy, z_imm1234_0base},
1727 1.1 christos [0xe9] = {OP_cmp, -1, 0, four, reg_xy, z_imm1234_0base},
1728 1.1 christos [0xea] = {OP_ld, -1, 0, three, reg_xy, ld_18bit_decode},
1729 1.1 christos [0xeb] = {OP_ld, -1, 0, three, reg_xy, ld_18bit_decode},
1730 1.1 christos [0xec] = {OP_bclr, -1, 0, bm_n_bytes, bm_decode, 0},
1731 1.1 christos [0xed] = {OP_bset, -1, 0, bm_n_bytes, bm_decode, 0},
1732 1.1 christos [0xee] = {OP_btgl, -1, 0, bm_n_bytes, bm_decode, 0},
1733 1.1 christos [0xef] = {OP_INVALID, -1, 0, NULL, NULL, NULL}, /* SPARE */
1734 1.1 christos [0xf0] = {OP_cmp, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1735 1.1 christos [0xf1] = {OP_cmp, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1736 1.1 christos [0xf2] = {OP_cmp, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1737 1.1 christos [0xf3] = {OP_cmp, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1738 1.1 christos [0xf4] = {OP_cmp, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1739 1.1 christos [0xf5] = {OP_cmp, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1740 1.1 christos [0xf6] = {OP_cmp, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1741 1.1 christos [0xf7] = {OP_cmp, -1, 0, opr_n_bytes_p1, z_reg, z_opr_decode},
1742 1.1 christos [0xf8] = {OP_cmp, -1, 0, opr_n_bytes_p1, reg_xy, z_opr_decode},
1743 1.1 christos [0xf9] = {OP_cmp, -1, 0, opr_n_bytes_p1, reg_xy, z_opr_decode},
1744 1.1 christos [0xfa] = {OP_ld, -1, 0, three, reg_xy, ld_18bit_decode},
1745 1.1 christos [0xfb] = {OP_ld, -1, 0, three, reg_xy, ld_18bit_decode},
1746 1.1 christos [0xfc] = {OP_cmp, -1, 0, single, cmp_xy, 0},
1747 1.1 christos [0xfd] = {OP_sub, -1, 0, single, sub_d6_x_y, 0},
1748 1.1 christos [0xfe] = {OP_sub, -1, 0, single, sub_d6_y_x, 0},
1749 1.1 christos [0xff] = {OP_swi, -1, 0, single, 0, 0}
1750 1.1 christos };
1751 1.1 christos
1752 1.1 christos static const int oprregs1[] =
1753 1.1 christos {
1754 1.1 christos REG_D3, REG_D2, REG_D1, REG_D0, REG_CCL, REG_CCH
1755 1.1 christos };
1756 1.1 christos
1757 1.1 christos static const int oprregs2[] =
1758 1.1 christos {
1759 1.1 christos REG_Y, REG_X, REG_D7, REG_D6, REG_D5, REG_D4
1760 1.1 christos };
1761 1.1 christos
1762 1.1 christos
1763 1.1 christos
1764 1.1 christos
1766 1.1 christos enum MUL_MODE
1767 1.1 christos {
1768 1.1 christos MUL_REG_REG,
1769 1.1 christos MUL_REG_OPR,
1770 1.1 christos MUL_REG_IMM,
1771 1.1 christos MUL_OPR_OPR
1772 1.1 christos };
1773 1.1 christos
1774 1.1 christos struct mb
1775 1.1 christos {
1776 1.1 christos uint8_t mask;
1777 1.1 christos uint8_t value;
1778 1.1 christos enum MUL_MODE mode;
1779 1.1 christos };
1780 1.1 christos
1781 1.1 christos static const struct mb mul_table[] = {
1782 1.1 christos {0x40, 0x00, MUL_REG_REG},
1783 1.1 christos
1784 1.1 christos {0x47, 0x40, MUL_REG_OPR},
1785 1.1 christos {0x47, 0x41, MUL_REG_OPR},
1786 1.1 christos {0x47, 0x43, MUL_REG_OPR},
1787 1.1 christos
1788 1.1 christos {0x47, 0x44, MUL_REG_IMM},
1789 1.1 christos {0x47, 0x45, MUL_REG_IMM},
1790 1.1 christos {0x47, 0x47, MUL_REG_IMM},
1791 1.1 christos
1792 1.1 christos {0x43, 0x42, MUL_OPR_OPR},
1793 1.1.1.2 christos };
1794 1.1 christos
1795 1.1 christos
1796 1.1 christos static int
1797 1.1 christos mul_decode (struct mem_read_abstraction_base *mra,
1798 1.1.1.2 christos int *n_operands, struct operand **operand)
1799 1.1 christos {
1800 1.1 christos uint8_t mb;
1801 1.1.1.2 christos struct operand *op;
1802 1.1 christos int status = mra->read (mra, 0, 1, &mb);
1803 1.1 christos if (status < 0)
1804 1.1 christos return status;
1805 1.1 christos
1806 1.1.1.2 christos uint8_t byte;
1807 1.1 christos status = mra->read (mra, -1, 1, &byte);
1808 1.1 christos if (status < 0)
1809 1.1 christos return status;
1810 1.1 christos
1811 1.1 christos enum MUL_MODE mode = -1;
1812 1.1 christos size_t i;
1813 1.1 christos for (i = 0; i < sizeof (mul_table) / sizeof (mul_table[0]); ++i)
1814 1.1 christos {
1815 1.1 christos const struct mb *mm = mul_table + i;
1816 1.1 christos if ((mb & mm->mask) == mm->value)
1817 1.1 christos {
1818 1.1 christos mode = mm->mode;
1819 1.1.1.2 christos break;
1820 1.1.1.2 christos }
1821 1.1.1.2 christos }
1822 1.1.1.2 christos op = create_register_operand (byte & 0x07);
1823 1.1 christos if (op == NULL)
1824 1.1 christos return -1;
1825 1.1 christos operand[(*n_operands)++] = op;
1826 1.1 christos
1827 1.1 christos switch (mode)
1828 1.1 christos {
1829 1.1.1.2 christos case MUL_REG_IMM:
1830 1.1.1.2 christos {
1831 1.1.1.2 christos int size = (mb & 0x3);
1832 1.1.1.2 christos op = create_register_operand_with_size ((mb & 0x38) >> 3, size);
1833 1.1.1.2 christos if (op == NULL)
1834 1.1.1.2 christos return -1;
1835 1.1.1.2 christos operand[(*n_operands)++] = op;
1836 1.1.1.2 christos
1837 1.1.1.2 christos uint32_t imm;
1838 1.1.1.2 christos if (z_decode_signed_value (mra, 1, size + 1, &imm) < 0)
1839 1.1.1.2 christos return -1;
1840 1.1.1.2 christos op = create_immediate_operand (imm);
1841 1.1 christos if (op == NULL)
1842 1.1 christos return -1;
1843 1.1 christos operand[(*n_operands)++] = op;
1844 1.1.1.2 christos }
1845 1.1.1.2 christos break;
1846 1.1.1.2 christos case MUL_REG_REG:
1847 1.1.1.2 christos op = create_register_operand ((mb & 0x38) >> 3);
1848 1.1.1.2 christos if (op == NULL)
1849 1.1.1.2 christos return -1;
1850 1.1.1.2 christos operand[(*n_operands)++] = op;
1851 1.1.1.2 christos op = create_register_operand (mb & 0x07);
1852 1.1 christos if (op == NULL)
1853 1.1 christos return -1;
1854 1.1.1.2 christos operand[(*n_operands)++] = op;
1855 1.1.1.2 christos break;
1856 1.1.1.2 christos case MUL_REG_OPR:
1857 1.1.1.2 christos op = create_register_operand ((mb & 0x38) >> 3);
1858 1.1.1.2 christos if (op == NULL)
1859 1.1.1.2 christos return -1;
1860 1.1.1.2 christos operand[(*n_operands)++] = op;
1861 1.1.1.2 christos op = x_opr_decode_with_size (mra, 1, mb & 0x3);
1862 1.1 christos if (op == NULL)
1863 1.1 christos return -1;
1864 1.1 christos operand[(*n_operands)++] = op;
1865 1.1 christos break;
1866 1.1.1.2 christos case MUL_OPR_OPR:
1867 1.1.1.2 christos {
1868 1.1.1.2 christos int first = x_opr_n_bytes (mra, 1);
1869 1.1.1.2 christos if (first < 0)
1870 1.1.1.2 christos return first;
1871 1.1.1.2 christos op = x_opr_decode_with_size (mra, 1, (mb & 0x30) >> 4);
1872 1.1.1.2 christos if (op == NULL)
1873 1.1.1.2 christos return -1;
1874 1.1.1.2 christos operand[(*n_operands)++] = op;
1875 1.1.1.2 christos op = x_opr_decode_with_size (mra, first + 1, (mb & 0x0c) >> 2);
1876 1.1 christos if (op == NULL)
1877 1.1 christos return -1;
1878 1.1 christos operand[(*n_operands)++] = op;
1879 1.1.1.2 christos break;
1880 1.1 christos }
1881 1.1 christos }
1882 1.1 christos return 0;
1883 1.1 christos }
1884 1.1 christos
1885 1.1 christos
1886 1.1 christos static int
1887 1.1.1.2 christos mul_n_bytes (struct mem_read_abstraction_base *mra)
1888 1.1 christos {
1889 1.1 christos int nx = 2;
1890 1.1 christos int first, second;
1891 1.1.1.2 christos uint8_t mb;
1892 1.1 christos int status = mra->read (mra, 0, 1, &mb);
1893 1.1 christos if (status < 0)
1894 1.1 christos return status;
1895 1.1 christos
1896 1.1 christos enum MUL_MODE mode = -1;
1897 1.1 christos size_t i;
1898 1.1 christos for (i = 0; i < sizeof (mul_table) / sizeof (mul_table[0]); ++i)
1899 1.1 christos {
1900 1.1 christos const struct mb *mm = mul_table + i;
1901 1.1 christos if ((mb & mm->mask) == mm->value)
1902 1.1 christos {
1903 1.1 christos mode = mm->mode;
1904 1.1 christos break;
1905 1.1 christos }
1906 1.1 christos }
1907 1.1 christos
1908 1.1 christos int size = (mb & 0x3) + 1;
1909 1.1 christos
1910 1.1 christos switch (mode)
1911 1.1 christos {
1912 1.1 christos case MUL_REG_IMM:
1913 1.1 christos nx += size;
1914 1.1 christos break;
1915 1.1.1.2 christos case MUL_REG_REG:
1916 1.1.1.2 christos break;
1917 1.1.1.2 christos case MUL_REG_OPR:
1918 1.1.1.2 christos first = x_opr_n_bytes (mra, 1);
1919 1.1 christos if (first < 0)
1920 1.1 christos return first;
1921 1.1.1.2 christos nx += first;
1922 1.1.1.2 christos break;
1923 1.1.1.2 christos case MUL_OPR_OPR:
1924 1.1.1.2 christos first = x_opr_n_bytes (mra, nx - 1);
1925 1.1.1.2 christos if (first < 0)
1926 1.1.1.2 christos return first;
1927 1.1.1.2 christos nx += first;
1928 1.1.1.2 christos second = x_opr_n_bytes (mra, nx - 1);
1929 1.1 christos if (second < 0)
1930 1.1 christos return second;
1931 1.1 christos nx += second;
1932 1.1 christos break;
1933 1.1 christos }
1934 1.1 christos
1935 1.1 christos return nx;
1936 1.1 christos }
1937 1.1 christos
1938 1.1 christos
1939 1.1 christos /* The NXP documentation is vague about BM_RESERVED0 and BM_RESERVED1,
1941 1.1 christos and contains obvious typos.
1942 1.1 christos However the Freescale tools and experiments with the chip itself
1943 1.1 christos seem to indicate that they behave like BM_REG_IMM and BM_OPR_REG
1944 1.1 christos respectively. */
1945 1.1 christos
1946 1.1 christos enum BM_MODE
1947 1.1 christos {
1948 1.1 christos BM_REG_IMM,
1949 1.1 christos BM_RESERVED0,
1950 1.1 christos BM_OPR_B,
1951 1.1 christos BM_OPR_W,
1952 1.1 christos BM_OPR_L,
1953 1.1 christos BM_OPR_REG,
1954 1.1 christos BM_RESERVED1
1955 1.1 christos };
1956 1.1 christos
1957 1.1 christos struct bm
1958 1.1 christos {
1959 1.1 christos uint8_t mask;
1960 1.1 christos uint8_t value;
1961 1.1 christos enum BM_MODE mode;
1962 1.1 christos };
1963 1.1 christos
1964 1.1 christos static const struct bm bm_table[] = {
1965 1.1.1.2 christos { 0xC6, 0x04, BM_REG_IMM},
1966 1.1 christos { 0x84, 0x00, BM_REG_IMM},
1967 1.1 christos { 0x06, 0x06, BM_REG_IMM},
1968 1.1 christos { 0xC6, 0x44, BM_RESERVED0},
1969 1.1 christos
1970 1.1 christos { 0x8F, 0x80, BM_OPR_B},
1971 1.1 christos { 0x8E, 0x82, BM_OPR_W},
1972 1.1 christos { 0x8C, 0x88, BM_OPR_L},
1973 1.1 christos
1974 1.1.1.2 christos { 0x83, 0x81, BM_OPR_REG},
1975 1.1 christos { 0x87, 0x84, BM_RESERVED1},
1976 1.1 christos };
1977 1.1 christos
1978 1.1.1.2 christos static int
1979 1.1 christos bm_decode (struct mem_read_abstraction_base *mra,
1980 1.1 christos int *n_operands, struct operand **operand)
1981 1.1 christos {
1982 1.1.1.2 christos struct operand *op;
1983 1.1 christos uint8_t bm;
1984 1.1 christos int status = mra->read (mra, 0, 1, &bm);
1985 1.1 christos if (status < 0)
1986 1.1 christos return status;
1987 1.1 christos
1988 1.1 christos size_t i;
1989 1.1 christos enum BM_MODE mode = -1;
1990 1.1 christos for (i = 0; i < sizeof (bm_table) / sizeof (bm_table[0]); ++i)
1991 1.1 christos {
1992 1.1 christos const struct bm *bme = bm_table + i;
1993 1.1 christos if ((bm & bme->mask) == bme->value)
1994 1.1 christos {
1995 1.1 christos mode = bme->mode;
1996 1.1 christos break;
1997 1.1 christos }
1998 1.1 christos }
1999 1.1 christos
2000 1.1.1.2 christos switch (mode)
2001 1.1.1.2 christos {
2002 1.1.1.2 christos case BM_REG_IMM:
2003 1.1.1.2 christos case BM_RESERVED0:
2004 1.1 christos op = create_register_operand (bm & 0x07);
2005 1.1 christos if (op == NULL)
2006 1.1.1.2 christos return -1;
2007 1.1.1.2 christos operand[(*n_operands)++] = op;
2008 1.1.1.2 christos break;
2009 1.1.1.2 christos case BM_OPR_B:
2010 1.1 christos op = x_opr_decode_with_size (mra, 1, 0);
2011 1.1 christos if (op == NULL)
2012 1.1.1.2 christos return -1;
2013 1.1.1.2 christos operand[(*n_operands)++] = op;
2014 1.1.1.2 christos break;
2015 1.1.1.2 christos case BM_OPR_W:
2016 1.1 christos op = x_opr_decode_with_size (mra, 1, 1);
2017 1.1 christos if (op == NULL)
2018 1.1.1.2 christos return -1;
2019 1.1.1.2 christos operand[(*n_operands)++] = op;
2020 1.1.1.2 christos break;
2021 1.1.1.2 christos case BM_OPR_L:
2022 1.1 christos op = x_opr_decode_with_size (mra, 1, 3);
2023 1.1 christos if (op == NULL)
2024 1.1 christos return -1;
2025 1.1 christos operand[(*n_operands)++] = op;
2026 1.1 christos break;
2027 1.1.1.2 christos case BM_OPR_REG:
2028 1.1.1.2 christos case BM_RESERVED1:
2029 1.1.1.2 christos {
2030 1.1 christos uint8_t xb;
2031 1.1 christos status = mra->read (mra, 1, 1, &xb);
2032 1.1.1.2 christos if (status < 0)
2033 1.1 christos return status;
2034 1.1.1.2 christos /* Don't emit a size suffix for register operands */
2035 1.1.1.2 christos if ((xb & 0xF8) != 0xB8)
2036 1.1.1.2 christos op = x_opr_decode_with_size (mra, 1, (bm & 0x0c) >> 2);
2037 1.1.1.2 christos else
2038 1.1 christos op = x_opr_decode (mra, 1);
2039 1.1 christos if (op == NULL)
2040 1.1 christos return -1;
2041 1.1 christos operand[(*n_operands)++] = op;
2042 1.1 christos }
2043 1.1 christos break;
2044 1.1 christos }
2045 1.1 christos
2046 1.1 christos uint8_t imm = 0;
2047 1.1 christos switch (mode)
2048 1.1.1.2 christos {
2049 1.1.1.2 christos case BM_REG_IMM:
2050 1.1.1.2 christos case BM_RESERVED0:
2051 1.1.1.2 christos imm = (bm & 0x38) >> 3;
2052 1.1 christos op = create_immediate_operand (imm);
2053 1.1 christos if (op == NULL)
2054 1.1 christos return -1;
2055 1.1 christos operand[(*n_operands)++] = op;
2056 1.1 christos break;
2057 1.1 christos case BM_OPR_L:
2058 1.1 christos imm |= (bm & 0x03) << 3;
2059 1.1 christos /* fallthrough */
2060 1.1 christos case BM_OPR_W:
2061 1.1.1.2 christos imm |= (bm & 0x01) << 3;
2062 1.1.1.2 christos /* fallthrough */
2063 1.1.1.2 christos case BM_OPR_B:
2064 1.1.1.2 christos imm |= (bm & 0x70) >> 4;
2065 1.1 christos op = create_immediate_operand (imm);
2066 1.1 christos if (op == NULL)
2067 1.1 christos return -1;
2068 1.1.1.2 christos operand[(*n_operands)++] = op;
2069 1.1.1.2 christos break;
2070 1.1.1.2 christos case BM_OPR_REG:
2071 1.1.1.2 christos case BM_RESERVED1:
2072 1.1 christos op = create_register_operand ((bm & 0x70) >> 4);
2073 1.1 christos if (op == NULL)
2074 1.1.1.2 christos return -1;
2075 1.1 christos operand[(*n_operands)++] = op;
2076 1.1 christos break;
2077 1.1 christos }
2078 1.1.1.2 christos return 0;
2079 1.1 christos }
2080 1.1 christos
2081 1.1 christos
2082 1.1.1.2 christos static int
2083 1.1 christos bm_rel_decode (struct mem_read_abstraction_base *mra,
2084 1.1 christos int *n_operands, struct operand **operand)
2085 1.1 christos {
2086 1.1.1.2 christos struct operand *op;
2087 1.1 christos uint8_t bm;
2088 1.1 christos int status = mra->read (mra, 0, 1, &bm);
2089 1.1 christos if (status < 0)
2090 1.1 christos return status;
2091 1.1 christos
2092 1.1 christos size_t i;
2093 1.1 christos enum BM_MODE mode = -1;
2094 1.1 christos for (i = 0; i < sizeof (bm_table) / sizeof (bm_table[0]); ++i)
2095 1.1 christos {
2096 1.1 christos const struct bm *bme = bm_table + i;
2097 1.1 christos if ((bm & bme->mask) == bme->value)
2098 1.1 christos {
2099 1.1 christos mode = bme->mode;
2100 1.1 christos break;
2101 1.1 christos }
2102 1.1 christos }
2103 1.1 christos
2104 1.1 christos int n = 1;
2105 1.1.1.2 christos switch (mode)
2106 1.1.1.2 christos {
2107 1.1.1.2 christos case BM_REG_IMM:
2108 1.1.1.2 christos case BM_RESERVED0:
2109 1.1 christos op = create_register_operand (bm & 0x07);
2110 1.1 christos if (op == NULL)
2111 1.1.1.2 christos return -1;
2112 1.1.1.2 christos operand[(*n_operands)++] = op;
2113 1.1.1.2 christos break;
2114 1.1.1.2 christos case BM_OPR_B:
2115 1.1.1.2 christos op = x_opr_decode_with_size (mra, 1, 0);
2116 1.1.1.2 christos if (op == NULL)
2117 1.1.1.2 christos return -1;
2118 1.1.1.2 christos operand[(*n_operands)++] = op;
2119 1.1 christos n = x_opr_n_bytes (mra, 1);
2120 1.1 christos if (n < 0)
2121 1.1.1.2 christos return n;
2122 1.1.1.2 christos n += 1;
2123 1.1.1.2 christos break;
2124 1.1.1.2 christos case BM_OPR_W:
2125 1.1.1.2 christos op = x_opr_decode_with_size (mra, 1, 1);
2126 1.1.1.2 christos if (op == NULL)
2127 1.1.1.2 christos return -1;
2128 1.1.1.2 christos operand[(*n_operands)++] = op;
2129 1.1 christos n = x_opr_n_bytes (mra, 1);
2130 1.1 christos if (n < 0)
2131 1.1.1.2 christos return n;
2132 1.1.1.2 christos n += 1;
2133 1.1.1.2 christos break;
2134 1.1.1.2 christos case BM_OPR_L:
2135 1.1.1.2 christos op = x_opr_decode_with_size (mra, 1, 3);
2136 1.1.1.2 christos if (op == NULL)
2137 1.1.1.2 christos return -1;
2138 1.1.1.2 christos operand[(*n_operands)++] = op;
2139 1.1 christos n = x_opr_n_bytes (mra, 1);
2140 1.1 christos if (n < 0)
2141 1.1 christos return n;
2142 1.1 christos n += 1;
2143 1.1 christos break;
2144 1.1.1.2 christos case BM_OPR_REG:
2145 1.1.1.2 christos case BM_RESERVED1:
2146 1.1.1.2 christos {
2147 1.1 christos uint8_t xb;
2148 1.1 christos status = mra->read (mra, +1, 1, &xb);
2149 1.1 christos if (status < 0)
2150 1.1 christos return status;
2151 1.1.1.2 christos /* Don't emit a size suffix for register operands */
2152 1.1 christos if ((xb & 0xF8) != 0xB8)
2153 1.1 christos {
2154 1.1.1.2 christos short os = (bm & 0x0c) >> 2;
2155 1.1.1.2 christos op = x_opr_decode_with_size (mra, 1, os);
2156 1.1.1.2 christos }
2157 1.1.1.2 christos else
2158 1.1 christos op = x_opr_decode (mra, 1);
2159 1.1 christos if (op == NULL)
2160 1.1 christos return -1;
2161 1.1 christos operand[(*n_operands)++] = op;
2162 1.1.1.2 christos }
2163 1.1 christos break;
2164 1.1 christos }
2165 1.1 christos
2166 1.1 christos int x, imm = 0;
2167 1.1 christos switch (mode)
2168 1.1 christos {
2169 1.1 christos case BM_OPR_L:
2170 1.1 christos imm |= (bm & 0x02) << 3;
2171 1.1 christos /* fall through */
2172 1.1 christos case BM_OPR_W:
2173 1.1.1.2 christos imm |= (bm & 0x01) << 3;
2174 1.1.1.2 christos /* fall through */
2175 1.1.1.2 christos case BM_OPR_B:
2176 1.1.1.2 christos imm |= (bm & 0x70) >> 4;
2177 1.1 christos op = create_immediate_operand (imm);
2178 1.1 christos if (op == NULL)
2179 1.1 christos return -1;
2180 1.1.1.2 christos operand[(*n_operands)++] = op;
2181 1.1.1.2 christos break;
2182 1.1.1.2 christos case BM_RESERVED0:
2183 1.1.1.2 christos imm = (bm & 0x38) >> 3;
2184 1.1 christos op = create_immediate_operand (imm);
2185 1.1 christos if (op == NULL)
2186 1.1 christos return -1;
2187 1.1.1.2 christos operand[(*n_operands)++] = op;
2188 1.1.1.2 christos break;
2189 1.1.1.2 christos case BM_REG_IMM:
2190 1.1.1.2 christos imm = (bm & 0xF8) >> 3;
2191 1.1 christos op = create_immediate_operand (imm);
2192 1.1 christos if (op == NULL)
2193 1.1 christos return -1;
2194 1.1.1.2 christos operand[(*n_operands)++] = op;
2195 1.1.1.2 christos break;
2196 1.1.1.2 christos case BM_OPR_REG:
2197 1.1.1.2 christos case BM_RESERVED1:
2198 1.1.1.2 christos op = create_register_operand ((bm & 0x70) >> 4);
2199 1.1.1.2 christos if (op == NULL)
2200 1.1.1.2 christos return -1;
2201 1.1.1.2 christos operand[(*n_operands)++] = op;
2202 1.1 christos x = x_opr_n_bytes (mra, 1);
2203 1.1 christos if (x < 0)
2204 1.1 christos return x;
2205 1.1.1.2 christos n += x;
2206 1.1 christos break;
2207 1.1 christos }
2208 1.1 christos
2209 1.1 christos return rel_15_7 (mra, n + 1, n_operands, operand);
2210 1.1 christos }
2211 1.1 christos
2212 1.1 christos static int
2213 1.1 christos bm_n_bytes (struct mem_read_abstraction_base *mra)
2214 1.1 christos {
2215 1.1 christos uint8_t bm;
2216 1.1 christos int status = mra->read (mra, 0, 1, &bm);
2217 1.1 christos if (status < 0)
2218 1.1 christos return status;
2219 1.1 christos
2220 1.1 christos size_t i;
2221 1.1 christos enum BM_MODE mode = -1;
2222 1.1 christos for (i = 0; i < sizeof (bm_table) / sizeof (bm_table[0]); ++i)
2223 1.1 christos {
2224 1.1 christos const struct bm *bme = bm_table + i;
2225 1.1 christos if ((bm & bme->mask) == bme->value)
2226 1.1 christos {
2227 1.1 christos mode = bme->mode;
2228 1.1.1.2 christos break;
2229 1.1 christos }
2230 1.1 christos }
2231 1.1 christos
2232 1.1 christos int n = 0;
2233 1.1 christos switch (mode)
2234 1.1 christos {
2235 1.1 christos case BM_REG_IMM:
2236 1.1 christos case BM_RESERVED0:
2237 1.1 christos break;
2238 1.1 christos
2239 1.1 christos case BM_OPR_B:
2240 1.1.1.2 christos case BM_OPR_W:
2241 1.1.1.2 christos case BM_OPR_L:
2242 1.1.1.2 christos case BM_OPR_REG:
2243 1.1 christos case BM_RESERVED1:
2244 1.1 christos n = x_opr_n_bytes (mra, 1);
2245 1.1 christos if (n < 0)
2246 1.1.1.2 christos return n;
2247 1.1 christos break;
2248 1.1 christos }
2249 1.1 christos
2250 1.1 christos return n + 2;
2251 1.1 christos }
2252 1.1 christos
2253 1.1 christos static int
2254 1.1 christos bm_rel_n_bytes (struct mem_read_abstraction_base *mra)
2255 1.1 christos {
2256 1.1 christos int n = 1 + bm_n_bytes (mra);
2257 1.1 christos
2258 1.1 christos bfd_byte rb;
2259 1.1 christos int status = mra->read (mra, n - 2, 1, &rb);
2260 1.1 christos if (status != 0)
2261 1.1 christos return status;
2262 1.1 christos
2263 1.1 christos if (rb & 0x80)
2264 1.1 christos n++;
2265 1.1 christos
2266 1.1 christos return n;
2267 1.1 christos }
2268 1.1 christos
2269 1.1 christos
2270 1.1 christos
2271 1.1 christos
2273 1.1 christos
2274 1.1 christos /* shift direction */
2275 1.1 christos enum SB_DIR
2276 1.1 christos {
2277 1.1 christos SB_LEFT,
2278 1.1 christos SB_RIGHT
2279 1.1 christos };
2280 1.1 christos
2281 1.1 christos enum SB_TYPE
2282 1.1 christos {
2283 1.1 christos SB_ARITHMETIC,
2284 1.1 christos SB_LOGICAL
2285 1.1 christos };
2286 1.1 christos
2287 1.1 christos
2288 1.1 christos enum SB_MODE
2289 1.1 christos {
2290 1.1 christos SB_REG_REG_N_EFF,
2291 1.1 christos SB_REG_REG_N,
2292 1.1 christos SB_REG_OPR_EFF,
2293 1.1 christos SB_ROT,
2294 1.1 christos SB_REG_OPR_OPR,
2295 1.1 christos SB_OPR_N
2296 1.1 christos };
2297 1.1 christos
2298 1.1 christos struct sb
2299 1.1 christos {
2300 1.1 christos uint8_t mask;
2301 1.1 christos uint8_t value;
2302 1.1 christos enum SB_MODE mode;
2303 1.1 christos };
2304 1.1 christos
2305 1.1 christos static const struct sb sb_table[] = {
2306 1.1 christos {0x30, 0x00, SB_REG_REG_N_EFF},
2307 1.1 christos {0x30, 0x10, SB_REG_REG_N},
2308 1.1 christos {0x34, 0x20, SB_REG_OPR_EFF},
2309 1.1 christos {0x34, 0x24, SB_ROT},
2310 1.1 christos {0x34, 0x30, SB_REG_OPR_OPR},
2311 1.1 christos {0x34, 0x34, SB_OPR_N},
2312 1.1 christos };
2313 1.1.1.2 christos
2314 1.1 christos static int
2315 1.1 christos shift_n_bytes (struct mem_read_abstraction_base *mra)
2316 1.1 christos {
2317 1.1 christos bfd_byte sb;
2318 1.1 christos int opr1, opr2;
2319 1.1 christos int status = mra->read (mra, 0, 1, &sb);
2320 1.1 christos if (status != 0)
2321 1.1 christos return status;
2322 1.1 christos
2323 1.1 christos size_t i;
2324 1.1 christos enum SB_MODE mode = -1;
2325 1.1 christos for (i = 0; i < sizeof (sb_table) / sizeof (sb_table[0]); ++i)
2326 1.1 christos {
2327 1.1 christos const struct sb *sbe = sb_table + i;
2328 1.1 christos if ((sb & sbe->mask) == sbe->value)
2329 1.1 christos mode = sbe->mode;
2330 1.1 christos }
2331 1.1 christos
2332 1.1 christos switch (mode)
2333 1.1.1.2 christos {
2334 1.1.1.2 christos case SB_REG_REG_N_EFF:
2335 1.1.1.2 christos return 2;
2336 1.1.1.2 christos case SB_REG_OPR_EFF:
2337 1.1 christos case SB_ROT:
2338 1.1.1.2 christos opr1 = x_opr_n_bytes (mra, 1);
2339 1.1.1.2 christos if (opr1 < 0)
2340 1.1.1.2 christos return opr1;
2341 1.1.1.2 christos return 2 + opr1;
2342 1.1.1.2 christos case SB_REG_OPR_OPR:
2343 1.1.1.2 christos opr1 = x_opr_n_bytes (mra, 1);
2344 1.1 christos if (opr1 < 0)
2345 1.1.1.2 christos return opr1;
2346 1.1.1.2 christos opr2 = 0;
2347 1.1.1.2 christos if ((sb & 0x30) != 0x20)
2348 1.1.1.2 christos {
2349 1.1 christos opr2 = x_opr_n_bytes (mra, opr1 + 1);
2350 1.1 christos if (opr2 < 0)
2351 1.1 christos return opr2;
2352 1.1 christos }
2353 1.1 christos return 2 + opr1 + opr2;
2354 1.1 christos default:
2355 1.1 christos return 3;
2356 1.1 christos }
2357 1.1 christos
2358 1.1 christos /* not reached */
2359 1.1 christos return -1;
2360 1.1 christos }
2361 1.1 christos
2362 1.1.1.2 christos
2364 1.1 christos static int
2365 1.1 christos mov_imm_opr_n_bytes (struct mem_read_abstraction_base *mra)
2366 1.1 christos {
2367 1.1.1.2 christos bfd_byte byte;
2368 1.1.1.2 christos int status = mra->read (mra, -1, 1, &byte);
2369 1.1.1.2 christos if (status < 0)
2370 1.1 christos return status;
2371 1.1.1.2 christos
2372 1.1 christos int size = byte - 0x0c + 1;
2373 1.1 christos int n = x_opr_n_bytes (mra, size);
2374 1.1.1.2 christos if (n < 0)
2375 1.1 christos return n;
2376 1.1 christos
2377 1.1 christos return size + n + 1;
2378 1.1.1.2 christos }
2379 1.1 christos
2380 1.1 christos static int
2381 1.1 christos mov_imm_opr (struct mem_read_abstraction_base *mra,
2382 1.1.1.2 christos int *n_operands, struct operand **operand)
2383 1.1 christos {
2384 1.1 christos struct operand *op;
2385 1.1.1.2 christos bfd_byte byte;
2386 1.1.1.2 christos int status = mra->read (mra, -1, 1, &byte);
2387 1.1.1.2 christos if (status < 0)
2388 1.1.1.2 christos return status;
2389 1.1.1.2 christos
2390 1.1.1.2 christos int size = byte - 0x0c + 1;
2391 1.1.1.2 christos uint32_t imm;
2392 1.1.1.2 christos if (decode_signed_value (mra, size, &imm))
2393 1.1.1.2 christos return -1;
2394 1.1.1.2 christos
2395 1.1.1.2 christos op = create_immediate_operand (imm);
2396 1.1.1.2 christos if (op == NULL)
2397 1.1.1.2 christos return -1;
2398 1.1 christos operand[(*n_operands)++] = op;
2399 1.1 christos op = x_opr_decode (mra, size);
2400 1.1 christos if (op == NULL)
2401 1.1 christos return -1;
2402 1.1.1.2 christos operand[(*n_operands)++] = op;
2403 1.1 christos return 0;
2404 1.1 christos }
2405 1.1 christos
2406 1.1.1.2 christos
2407 1.1 christos
2409 1.1 christos static int
2410 1.1 christos ld_18bit_decode (struct mem_read_abstraction_base *mra,
2411 1.1.1.2 christos int *n_operands, struct operand **operand)
2412 1.1 christos {
2413 1.1 christos struct operand *op;
2414 1.1 christos size_t size = 3;
2415 1.1.1.2 christos bfd_byte buffer[3];
2416 1.1 christos int status = mra->read (mra, 0, 2, buffer + 1);
2417 1.1 christos if (status < 0)
2418 1.1 christos return status;
2419 1.1 christos
2420 1.1 christos status = mra->read (mra, -1, 1, buffer);
2421 1.1 christos if (status < 0)
2422 1.1 christos return status;
2423 1.1 christos
2424 1.1 christos buffer[0] = (buffer[0] & 0x30) >> 4;
2425 1.1 christos
2426 1.1.1.2 christos size_t i;
2427 1.1.1.2 christos uint32_t imm = 0;
2428 1.1.1.2 christos for (i = 0; i < size; ++i)
2429 1.1.1.2 christos {
2430 1.1.1.2 christos imm |= buffer[i] << (8 * (size - i - 1));
2431 1.1 christos }
2432 1.1 christos
2433 1.1 christos op = create_immediate_operand (imm);
2434 1.1 christos if (op == NULL)
2435 1.1 christos return -1;
2436 1.1 christos operand[(*n_operands)++] = op;
2437 1.1 christos return 0;
2438 1.1 christos }
2439 1.1 christos
2440 1.1 christos
2441 1.1 christos
2443 1.1 christos /* Loop Primitives */
2444 1.1 christos
2445 1.1 christos enum LP_MODE {
2446 1.1 christos LP_REG,
2447 1.1 christos LP_XY,
2448 1.1 christos LP_OPR
2449 1.1 christos };
2450 1.1 christos
2451 1.1 christos struct lp
2452 1.1 christos {
2453 1.1 christos uint8_t mask;
2454 1.1 christos uint8_t value;
2455 1.1 christos enum LP_MODE mode;
2456 1.1 christos };
2457 1.1 christos
2458 1.1 christos static const struct lp lp_mode[] = {
2459 1.1 christos {0x08, 0x00, LP_REG},
2460 1.1 christos {0x0C, 0x08, LP_XY},
2461 1.1 christos {0x0C, 0x0C, LP_OPR},
2462 1.1.1.2 christos };
2463 1.1.1.2 christos
2464 1.1.1.2 christos
2465 1.1 christos static int
2466 1.1 christos loop_prim_n_bytes (struct mem_read_abstraction_base *mra)
2467 1.1 christos {
2468 1.1 christos int mx = 0;
2469 1.1 christos uint8_t lb;
2470 1.1 christos int status = mra->read (mra, mx++, 1, &lb);
2471 1.1 christos if (status < 0)
2472 1.1 christos return status;
2473 1.1 christos
2474 1.1 christos enum LP_MODE mode = -1;
2475 1.1 christos size_t i;
2476 1.1 christos for (i = 0; i < sizeof (lp_mode) / sizeof (lp_mode[0]); ++i)
2477 1.1 christos {
2478 1.1 christos const struct lp *pb = lp_mode + i;
2479 1.1 christos if ((lb & pb->mask) == pb->value)
2480 1.1.1.2 christos {
2481 1.1.1.2 christos mode = pb->mode;
2482 1.1.1.2 christos break;
2483 1.1.1.2 christos }
2484 1.1 christos }
2485 1.1 christos
2486 1.1 christos if (mode == LP_OPR)
2487 1.1.1.2 christos {
2488 1.1.1.2 christos int n = x_opr_n_bytes (mra, mx);
2489 1.1.1.2 christos if (n < 0)
2490 1.1 christos return n;
2491 1.1 christos mx += n;
2492 1.1 christos }
2493 1.1 christos
2494 1.1 christos uint8_t rb;
2495 1.1 christos status = mra->read (mra, mx++, 1, &rb);
2496 1.1 christos if (status < 0)
2497 1.1 christos return status;
2498 1.1 christos if (rb & 0x80)
2499 1.1 christos mx++;
2500 1.1 christos
2501 1.1 christos return mx + 1;
2502 1.1 christos }
2503 1.1 christos
2504 1.1 christos
2505 1.1 christos
2506 1.1 christos
2508 1.1 christos static enum optr
2509 1.1 christos exg_sex_discrim (struct mem_read_abstraction_base *mra,
2510 1.1.1.2 christos enum optr hint ATTRIBUTE_UNUSED)
2511 1.1.1.2 christos {
2512 1.1 christos uint8_t eb;
2513 1.1.1.2 christos int status = mra->read (mra, 0, 1, &eb);
2514 1.1.1.2 christos enum optr operator = OP_INVALID;
2515 1.1 christos if (status < 0)
2516 1.1 christos return operator;
2517 1.1 christos
2518 1.1 christos struct operand *op0 = create_register_operand ((eb & 0xf0) >> 4);
2519 1.1 christos if (op0 == NULL)
2520 1.1 christos return -1;
2521 1.1 christos struct operand *op1 = create_register_operand (eb & 0xf);
2522 1.1 christos if (op1 == NULL)
2523 1.1 christos return -1;
2524 1.1 christos
2525 1.1 christos int reg0 = ((struct register_operand *) op0)->reg;
2526 1.1 christos int reg1 = ((struct register_operand *) op1)->reg;
2527 1.1 christos if (reg0 >= 0 && reg0 < S12Z_N_REGISTERS
2528 1.1 christos && reg1 >= 0 && reg1 < S12Z_N_REGISTERS)
2529 1.1 christos {
2530 1.1 christos const struct reg *r0 = registers + reg0;
2531 1.1 christos const struct reg *r1 = registers + reg1;
2532 1.1 christos
2533 1.1 christos operator = r0->bytes < r1->bytes ? OP_sex : OP_exg;
2534 1.1.1.2 christos }
2535 1.1 christos
2536 1.1 christos free (op0);
2537 1.1 christos free (op1);
2538 1.1.1.2 christos
2539 1.1 christos return operator;
2540 1.1 christos }
2541 1.1 christos
2542 1.1.1.2 christos
2543 1.1 christos static int
2544 1.1 christos exg_sex_decode (struct mem_read_abstraction_base *mra,
2545 1.1.1.2 christos int *n_operands, struct operand **operands)
2546 1.1.1.2 christos {
2547 1.1.1.2 christos struct operand *op;
2548 1.1.1.2 christos uint8_t eb;
2549 1.1.1.2 christos int status = mra->read (mra, 0, 1, &eb);
2550 1.1.1.2 christos if (status < 0)
2551 1.1.1.2 christos return status;
2552 1.1.1.2 christos
2553 1.1.1.2 christos /* Ship out the operands. */
2554 1.1 christos op = create_register_operand ((eb & 0xf0) >> 4);
2555 1.1 christos if (op == NULL)
2556 1.1 christos return -1;
2557 1.1 christos operands[(*n_operands)++] = op;
2558 1.1 christos op = create_register_operand (eb & 0xf);
2559 1.1 christos if (op == NULL)
2560 1.1 christos return -1;
2561 1.1 christos operands[(*n_operands)++] = op;
2562 1.1 christos return 0;
2563 1.1 christos }
2564 1.1 christos
2565 1.1 christos static enum optr
2566 1.1 christos loop_primitive_discrim (struct mem_read_abstraction_base *mra,
2567 1.1 christos enum optr hint ATTRIBUTE_UNUSED)
2568 1.1 christos {
2569 1.1.1.2 christos uint8_t lb;
2570 1.1 christos int status = mra->read (mra, 0, 1, &lb);
2571 1.1 christos if (status < 0)
2572 1.1 christos return OP_INVALID;
2573 1.1.1.2 christos
2574 1.1.1.2 christos enum optr opbase = (lb & 0x80) ? OP_dbNE : OP_tbNE;
2575 1.1 christos return opbase + ((lb & 0x70) >> 4);
2576 1.1 christos }
2577 1.1 christos
2578 1.1.1.2 christos static int
2579 1.1 christos loop_primitive_decode (struct mem_read_abstraction_base *mra,
2580 1.1 christos int *n_operands, struct operand **operands)
2581 1.1 christos {
2582 1.1 christos struct operand *op;
2583 1.1 christos int n, offs = 1;
2584 1.1 christos uint8_t lb;
2585 1.1 christos int status = mra->read (mra, 0, 1, &lb);
2586 1.1 christos if (status < 0)
2587 1.1 christos return status;
2588 1.1 christos
2589 1.1 christos enum LP_MODE mode = -1;
2590 1.1 christos size_t i;
2591 1.1 christos for (i = 0; i < sizeof (lp_mode) / sizeof (lp_mode[0]); ++i)
2592 1.1 christos {
2593 1.1 christos const struct lp *pb = lp_mode + i;
2594 1.1 christos if ((lb & pb->mask) == pb->value)
2595 1.1.1.2 christos {
2596 1.1.1.2 christos mode = pb->mode;
2597 1.1.1.2 christos break;
2598 1.1.1.2 christos }
2599 1.1 christos }
2600 1.1 christos
2601 1.1.1.2 christos switch (mode)
2602 1.1.1.2 christos {
2603 1.1.1.2 christos case LP_REG:
2604 1.1.1.2 christos op = create_register_operand (lb & 0x07);
2605 1.1 christos if (op == NULL)
2606 1.1 christos return -1;
2607 1.1.1.2 christos operands[(*n_operands)++] = op;
2608 1.1.1.2 christos break;
2609 1.1.1.2 christos case LP_XY:
2610 1.1.1.2 christos op = create_register_operand ((lb & 0x01) + REG_X);
2611 1.1.1.2 christos if (op == NULL)
2612 1.1.1.2 christos return -1;
2613 1.1.1.2 christos operands[(*n_operands)++] = op;
2614 1.1.1.2 christos break;
2615 1.1 christos case LP_OPR:
2616 1.1 christos n = x_opr_n_bytes (mra, 1);
2617 1.1 christos if (n < 0)
2618 1.1.1.2 christos return n;
2619 1.1 christos offs += n;
2620 1.1 christos op = x_opr_decode_with_size (mra, 1, lb & 0x03);
2621 1.1 christos if (op == NULL)
2622 1.1 christos return -1;
2623 1.1 christos operands[(*n_operands)++] = op;
2624 1.1 christos break;
2625 1.1 christos }
2626 1.1 christos
2627 1.1 christos return rel_15_7 (mra, offs + 1, n_operands, operands);
2628 1.1 christos }
2629 1.1 christos
2630 1.1 christos
2631 1.1 christos static enum optr
2632 1.1 christos shift_discrim (struct mem_read_abstraction_base *mra,
2633 1.1 christos enum optr hint ATTRIBUTE_UNUSED)
2634 1.1 christos {
2635 1.1 christos size_t i;
2636 1.1 christos uint8_t sb;
2637 1.1 christos int status = mra->read (mra, 0, 1, &sb);
2638 1.1 christos if (status < 0)
2639 1.1 christos return OP_INVALID;
2640 1.1 christos
2641 1.1 christos enum SB_DIR dir = (sb & 0x40) ? SB_LEFT : SB_RIGHT;
2642 1.1 christos enum SB_TYPE type = (sb & 0x80) ? SB_ARITHMETIC : SB_LOGICAL;
2643 1.1 christos enum SB_MODE mode = -1;
2644 1.1 christos for (i = 0; i < sizeof (sb_table) / sizeof (sb_table[0]); ++i)
2645 1.1 christos {
2646 1.1 christos const struct sb *sbe = sb_table + i;
2647 1.1 christos if ((sb & sbe->mask) == sbe->value)
2648 1.1 christos mode = sbe->mode;
2649 1.1 christos }
2650 1.1 christos
2651 1.1 christos if (mode == SB_ROT)
2652 1.1.1.2 christos return (dir == SB_LEFT) ? OP_rol : OP_ror;
2653 1.1 christos
2654 1.1 christos if (type == SB_LOGICAL)
2655 1.1 christos return (dir == SB_LEFT) ? OP_lsl : OP_lsr;
2656 1.1.1.2 christos
2657 1.1 christos return (dir == SB_LEFT) ? OP_asl : OP_asr;
2658 1.1 christos }
2659 1.1 christos
2660 1.1 christos
2661 1.1.1.2 christos static int
2662 1.1 christos shift_decode (struct mem_read_abstraction_base *mra, int *n_operands,
2663 1.1 christos struct operand **operands)
2664 1.1 christos {
2665 1.1 christos struct operand *op;
2666 1.1.1.2 christos size_t i;
2667 1.1 christos uint8_t byte;
2668 1.1 christos int status = mra->read (mra, -1, 1, &byte);
2669 1.1 christos if (status < 0)
2670 1.1 christos return status;
2671 1.1 christos
2672 1.1 christos uint8_t sb;
2673 1.1 christos status = mra->read (mra, 0, 1, &sb);
2674 1.1 christos if (status < 0)
2675 1.1 christos return status;
2676 1.1 christos
2677 1.1 christos enum SB_MODE mode = -1;
2678 1.1 christos for (i = 0; i < sizeof (sb_table) / sizeof (sb_table[0]); ++i)
2679 1.1 christos {
2680 1.1 christos const struct sb *sbe = sb_table + i;
2681 1.1 christos if ((sb & sbe->mask) == sbe->value)
2682 1.1 christos mode = sbe->mode;
2683 1.1 christos }
2684 1.1 christos
2685 1.1 christos short osize = -1;
2686 1.1 christos switch (mode)
2687 1.1.1.2 christos {
2688 1.1.1.2 christos case SB_REG_OPR_EFF:
2689 1.1.1.2 christos case SB_ROT:
2690 1.1 christos case SB_REG_OPR_OPR:
2691 1.1 christos osize = sb & 0x03;
2692 1.1 christos break;
2693 1.1 christos case SB_OPR_N:
2694 1.1 christos {
2695 1.1 christos uint8_t xb;
2696 1.1 christos status = mra->read (mra, 1, 1, &xb);
2697 1.1 christos if (status < 0)
2698 1.1 christos return status;
2699 1.1 christos /* The size suffix is not printed if the OPR operand refers
2700 1.1 christos directly to a register, because the size is implied by the
2701 1.1 christos size of that register. */
2702 1.1 christos if ((xb & 0xF8) != 0xB8)
2703 1.1 christos osize = sb & 0x03;
2704 1.1 christos }
2705 1.1 christos break;
2706 1.1.1.2 christos default:
2707 1.1.1.2 christos break;
2708 1.1.1.2 christos };
2709 1.1.1.2 christos
2710 1.1 christos /* Destination register */
2711 1.1 christos switch (mode)
2712 1.1 christos {
2713 1.1.1.2 christos case SB_REG_REG_N_EFF:
2714 1.1.1.2 christos case SB_REG_REG_N:
2715 1.1.1.2 christos op = create_register_operand (byte & 0x07);
2716 1.1.1.2 christos if (op == NULL)
2717 1.1 christos return -1;
2718 1.1 christos operands[(*n_operands)++] = op;
2719 1.1 christos break;
2720 1.1.1.2 christos case SB_REG_OPR_EFF:
2721 1.1.1.2 christos case SB_REG_OPR_OPR:
2722 1.1.1.2 christos op = create_register_operand (byte & 0x07);
2723 1.1.1.2 christos if (op == NULL)
2724 1.1 christos return -1;
2725 1.1 christos operands[(*n_operands)++] = op;
2726 1.1 christos break;
2727 1.1 christos
2728 1.1 christos case SB_ROT:
2729 1.1 christos op = x_opr_decode_with_size (mra, 1, osize);
2730 1.1 christos if (op == NULL)
2731 1.1 christos return -1;
2732 1.1 christos operands[(*n_operands)++] = op;
2733 1.1 christos break;
2734 1.1 christos
2735 1.1.1.2 christos default:
2736 1.1.1.2 christos break;
2737 1.1.1.2 christos }
2738 1.1.1.2 christos
2739 1.1 christos /* Source register */
2740 1.1 christos switch (mode)
2741 1.1 christos {
2742 1.1.1.2 christos case SB_REG_REG_N_EFF:
2743 1.1.1.2 christos case SB_REG_REG_N:
2744 1.1.1.2 christos op = create_register_operand_with_size (sb & 0x07, osize);
2745 1.1.1.2 christos if (op == NULL)
2746 1.1 christos return -1;
2747 1.1 christos operands[(*n_operands)++] = op;
2748 1.1 christos break;
2749 1.1 christos
2750 1.1 christos case SB_REG_OPR_OPR:
2751 1.1 christos op = x_opr_decode_with_size (mra, 1, osize);
2752 1.1 christos if (op == NULL)
2753 1.1 christos return -1;
2754 1.1 christos operands[(*n_operands)++] = op;
2755 1.1 christos break;
2756 1.1 christos
2757 1.1.1.2 christos default:
2758 1.1.1.2 christos break;
2759 1.1.1.2 christos }
2760 1.1.1.2 christos
2761 1.1 christos /* 3rd arg */
2762 1.1 christos switch (mode)
2763 1.1 christos {
2764 1.1 christos case SB_REG_OPR_EFF:
2765 1.1 christos case SB_OPR_N:
2766 1.1.1.2 christos op = x_opr_decode_with_size (mra, 1, osize);
2767 1.1.1.2 christos if (op == NULL)
2768 1.1.1.2 christos return -1;
2769 1.1 christos operands[(*n_operands)++] = op;
2770 1.1 christos break;
2771 1.1 christos
2772 1.1 christos case SB_REG_REG_N:
2773 1.1 christos {
2774 1.1 christos uint8_t xb;
2775 1.1 christos status = mra->read (mra, 1, 1, &xb);
2776 1.1 christos if (status < 0)
2777 1.1 christos return status;
2778 1.1 christos
2779 1.1.1.2 christos /* This case is slightly unusual.
2780 1.1.1.2 christos If XB matches the binary pattern 0111XXXX, then instead of
2781 1.1.1.2 christos interpreting this as a general OPR postbyte in the IMMe4 mode,
2782 1.1.1.2 christos the XB byte is interpreted in s special way. */
2783 1.1 christos if ((xb & 0xF0) == 0x70)
2784 1.1 christos {
2785 1.1 christos if (byte & 0x10)
2786 1.1 christos {
2787 1.1 christos int shift = ((sb & 0x08) >> 3) | ((xb & 0x0f) << 1);
2788 1.1 christos op = create_immediate_operand (shift);
2789 1.1 christos if (op == NULL)
2790 1.1 christos return -1;
2791 1.1 christos operands[(*n_operands)++] = op;
2792 1.1.1.2 christos }
2793 1.1.1.2 christos else
2794 1.1.1.2 christos {
2795 1.1.1.2 christos /* This should not happen. */
2796 1.1 christos abort ();
2797 1.1 christos }
2798 1.1 christos }
2799 1.1 christos else
2800 1.1 christos {
2801 1.1 christos op = x_opr_decode (mra, 1);
2802 1.1 christos if (op == NULL)
2803 1.1.1.2 christos return -1;
2804 1.1.1.2 christos operands[(*n_operands)++] = op;
2805 1.1.1.2 christos }
2806 1.1.1.2 christos }
2807 1.1.1.2 christos break;
2808 1.1 christos case SB_REG_OPR_OPR:
2809 1.1 christos {
2810 1.1 christos uint8_t xb;
2811 1.1 christos int n = x_opr_n_bytes (mra, 1);
2812 1.1 christos if (n < 0)
2813 1.1 christos return n;
2814 1.1.1.2 christos status = mra->read (mra, 1 + n, 1, &xb);
2815 1.1.1.2 christos if (status < 0)
2816 1.1.1.2 christos return status;
2817 1.1.1.2 christos
2818 1.1 christos if ((xb & 0xF0) == 0x70)
2819 1.1 christos {
2820 1.1 christos int imm = xb & 0x0F;
2821 1.1.1.2 christos imm <<= 1;
2822 1.1.1.2 christos imm |= (sb & 0x08) >> 3;
2823 1.1.1.2 christos op = create_immediate_operand (imm);
2824 1.1.1.2 christos if (op == NULL)
2825 1.1 christos return -1;
2826 1.1 christos operands[(*n_operands)++] = op;
2827 1.1 christos }
2828 1.1 christos else
2829 1.1 christos {
2830 1.1 christos op = x_opr_decode (mra, 1 + n);
2831 1.1 christos if (op == NULL)
2832 1.1 christos return -1;
2833 1.1 christos operands[(*n_operands)++] = op;
2834 1.1 christos }
2835 1.1 christos }
2836 1.1 christos break;
2837 1.1 christos default:
2838 1.1 christos break;
2839 1.1.1.2 christos }
2840 1.1.1.2 christos
2841 1.1.1.2 christos switch (mode)
2842 1.1.1.2 christos {
2843 1.1 christos case SB_REG_REG_N_EFF:
2844 1.1 christos case SB_REG_OPR_EFF:
2845 1.1 christos case SB_OPR_N:
2846 1.1 christos {
2847 1.1 christos int imm = (sb & 0x08) ? 2 : 1;
2848 1.1 christos op = create_immediate_operand (imm);
2849 1.1.1.2 christos if (op == NULL)
2850 1.1 christos return -1;
2851 1.1 christos operands[(*n_operands)++] = op;
2852 1.1 christos }
2853 1.1 christos break;
2854 1.1 christos
2855 1.1 christos default:
2856 1.1 christos break;
2857 1.1 christos }
2858 1.1 christos return 0;
2859 1.1 christos }
2860 1.1 christos
2861 1.1 christos static enum optr
2862 1.1 christos psh_pul_discrim (struct mem_read_abstraction_base *mra,
2863 1.1 christos enum optr hint ATTRIBUTE_UNUSED)
2864 1.1 christos {
2865 1.1.1.2 christos uint8_t byte;
2866 1.1 christos int status = mra->read (mra, 0, 1, &byte);
2867 1.1 christos if (status != 0)
2868 1.1 christos return OP_INVALID;
2869 1.1.1.2 christos
2870 1.1 christos return (byte & 0x80) ? OP_pull: OP_push;
2871 1.1 christos }
2872 1.1 christos
2873 1.1.1.2 christos
2874 1.1 christos static int
2875 1.1 christos psh_pul_decode (struct mem_read_abstraction_base *mra,
2876 1.1 christos int *n_operands, struct operand **operand)
2877 1.1 christos {
2878 1.1.1.2 christos struct operand *op;
2879 1.1.1.2 christos uint8_t byte;
2880 1.1.1.2 christos int status = mra->read (mra, 0, 1, &byte);
2881 1.1.1.2 christos if (status != 0)
2882 1.1.1.2 christos return status;
2883 1.1.1.2 christos int bit;
2884 1.1 christos if (byte & 0x40)
2885 1.1 christos {
2886 1.1 christos if ((byte & 0x3F) == 0)
2887 1.1 christos {
2888 1.1 christos op = create_register_all16_operand ();
2889 1.1.1.2 christos if (op == NULL)
2890 1.1.1.2 christos return -1;
2891 1.1.1.2 christos operand[(*n_operands)++] = op;
2892 1.1.1.2 christos }
2893 1.1 christos else
2894 1.1 christos for (bit = 5; bit >= 0; --bit)
2895 1.1 christos {
2896 1.1 christos if (byte & (0x1 << bit))
2897 1.1 christos {
2898 1.1 christos op = create_register_operand (oprregs2[bit]);
2899 1.1.1.2 christos if (op == NULL)
2900 1.1.1.2 christos return -1;
2901 1.1.1.2 christos operand[(*n_operands)++] = op;
2902 1.1.1.2 christos }
2903 1.1.1.2 christos }
2904 1.1.1.2 christos }
2905 1.1 christos else
2906 1.1 christos {
2907 1.1 christos if ((byte & 0x3F) == 0)
2908 1.1 christos {
2909 1.1 christos op = create_register_all_operand ();
2910 1.1.1.2 christos if (op == NULL)
2911 1.1.1.2 christos return -1;
2912 1.1.1.2 christos operand[(*n_operands)++] = op;
2913 1.1.1.2 christos }
2914 1.1 christos else
2915 1.1 christos for (bit = 5; bit >= 0; --bit)
2916 1.1 christos {
2917 1.1.1.2 christos if (byte & (0x1 << bit))
2918 1.1 christos {
2919 1.1 christos op = create_register_operand (oprregs1[bit]);
2920 1.1 christos if (op == NULL)
2921 1.1 christos return -1;
2922 1.1 christos operand[(*n_operands)++] = op;
2923 1.1 christos }
2924 1.1 christos }
2925 1.1 christos }
2926 1.1 christos return 0;
2927 1.1 christos }
2928 1.1 christos
2929 1.1 christos static enum optr
2930 1.1.1.2 christos bit_field_discrim (struct mem_read_abstraction_base *mra,
2931 1.1 christos enum optr hint ATTRIBUTE_UNUSED)
2932 1.1 christos {
2933 1.1.1.2 christos int status;
2934 1.1 christos bfd_byte bb;
2935 1.1 christos status = mra->read (mra, 0, 1, &bb);
2936 1.1 christos if (status != 0)
2937 1.1.1.2 christos return OP_INVALID;
2938 1.1 christos
2939 1.1 christos return (bb & 0x80) ? OP_bfins : OP_bfext;
2940 1.1 christos }
2941 1.1 christos
2942 1.1 christos static int
2943 1.1.1.2 christos bit_field_decode (struct mem_read_abstraction_base *mra,
2944 1.1 christos int *n_operands, struct operand **operands)
2945 1.1 christos {
2946 1.1 christos struct operand *op;
2947 1.1 christos int status;
2948 1.1.1.2 christos
2949 1.1 christos bfd_byte byte2;
2950 1.1 christos status = mra->read (mra, -1, 1, &byte2);
2951 1.1 christos if (status != 0)
2952 1.1 christos return status;
2953 1.1 christos
2954 1.1 christos bfd_byte bb;
2955 1.1 christos status = mra->read (mra, 0, 1, &bb);
2956 1.1 christos if (status != 0)
2957 1.1 christos return status;
2958 1.1 christos
2959 1.1 christos enum BB_MODE mode = -1;
2960 1.1 christos size_t i;
2961 1.1 christos const struct opr_bb *bbs = 0;
2962 1.1 christos for (i = 0; i < sizeof (bb_modes) / sizeof (bb_modes[0]); ++i)
2963 1.1 christos {
2964 1.1 christos bbs = bb_modes + i;
2965 1.1 christos if ((bb & bbs->mask) == bbs->value)
2966 1.1 christos {
2967 1.1 christos mode = bbs->mode;
2968 1.1 christos break;
2969 1.1 christos }
2970 1.1.1.2 christos }
2971 1.1.1.2 christos int reg1 = byte2 & 0x07;
2972 1.1.1.2 christos /* First operand */
2973 1.1.1.2 christos switch (mode)
2974 1.1 christos {
2975 1.1 christos case BB_REG_REG_REG:
2976 1.1.1.2 christos case BB_REG_REG_IMM:
2977 1.1.1.2 christos case BB_REG_OPR_REG:
2978 1.1.1.2 christos case BB_REG_OPR_IMM:
2979 1.1.1.2 christos op = create_register_operand (reg1);
2980 1.1 christos if (op == NULL)
2981 1.1 christos return -1;
2982 1.1.1.2 christos operands[(*n_operands)++] = op;
2983 1.1.1.2 christos break;
2984 1.1.1.2 christos case BB_OPR_REG_REG:
2985 1.1.1.2 christos op = x_opr_decode_with_size (mra, 1, (bb >> 2) & 0x03);
2986 1.1 christos if (op == NULL)
2987 1.1 christos return -1;
2988 1.1 christos operands[(*n_operands)++] = op;
2989 1.1 christos break;
2990 1.1 christos case BB_OPR_REG_IMM:
2991 1.1 christos op = x_opr_decode_with_size (mra, 2, (bb >> 2) & 0x03);
2992 1.1 christos if (op == NULL)
2993 1.1 christos return -1;
2994 1.1 christos operands[(*n_operands)++] = op;
2995 1.1 christos break;
2996 1.1.1.2 christos }
2997 1.1.1.2 christos
2998 1.1.1.2 christos /* Second operand */
2999 1.1.1.2 christos switch (mode)
3000 1.1 christos {
3001 1.1 christos case BB_REG_REG_REG:
3002 1.1 christos case BB_REG_REG_IMM:
3003 1.1 christos {
3004 1.1 christos int reg_src = (bb >> 2) & 0x07;
3005 1.1 christos op = create_register_operand (reg_src);
3006 1.1.1.2 christos if (op == NULL)
3007 1.1.1.2 christos return -1;
3008 1.1.1.2 christos operands[(*n_operands)++] = op;
3009 1.1.1.2 christos }
3010 1.1 christos break;
3011 1.1 christos case BB_OPR_REG_REG:
3012 1.1 christos case BB_OPR_REG_IMM:
3013 1.1.1.2 christos {
3014 1.1.1.2 christos int reg_src = (byte2 & 0x07);
3015 1.1.1.2 christos op = create_register_operand (reg_src);
3016 1.1.1.2 christos if (op == NULL)
3017 1.1 christos return -1;
3018 1.1 christos operands[(*n_operands)++] = op;
3019 1.1.1.2 christos }
3020 1.1.1.2 christos break;
3021 1.1.1.2 christos case BB_REG_OPR_REG:
3022 1.1.1.2 christos op = x_opr_decode_with_size (mra, 1, (bb >> 2) & 0x03);
3023 1.1 christos if (op == NULL)
3024 1.1 christos return -1;
3025 1.1 christos operands[(*n_operands)++] = op;
3026 1.1 christos break;
3027 1.1 christos case BB_REG_OPR_IMM:
3028 1.1 christos op = x_opr_decode_with_size (mra, 2, (bb >> 2) & 0x03);
3029 1.1 christos if (op == NULL)
3030 1.1 christos return -1;
3031 1.1 christos operands[(*n_operands)++] = op;
3032 1.1 christos break;
3033 1.1 christos }
3034 1.1.1.2 christos
3035 1.1.1.2 christos /* Third operand */
3036 1.1.1.2 christos switch (mode)
3037 1.1.1.2 christos {
3038 1.1 christos case BB_REG_REG_REG:
3039 1.1 christos case BB_OPR_REG_REG:
3040 1.1 christos case BB_REG_OPR_REG:
3041 1.1 christos {
3042 1.1 christos int reg_parm = bb & 0x03;
3043 1.1 christos op = create_register_operand (reg_parm);
3044 1.1 christos if (op == NULL)
3045 1.1.1.2 christos return -1;
3046 1.1.1.2 christos operands[(*n_operands)++] = op;
3047 1.1.1.2 christos }
3048 1.1 christos break;
3049 1.1 christos case BB_REG_REG_IMM:
3050 1.1 christos case BB_OPR_REG_IMM:
3051 1.1 christos case BB_REG_OPR_IMM:
3052 1.1.1.2 christos {
3053 1.1.1.2 christos bfd_byte i1;
3054 1.1.1.2 christos status = mra->read (mra, 1, 1, &i1);
3055 1.1.1.2 christos if (status < 0)
3056 1.1 christos return status;
3057 1.1 christos int offset = i1 & 0x1f;
3058 1.1 christos int width = bb & 0x03;
3059 1.1.1.2 christos width <<= 3;
3060 1.1 christos width |= i1 >> 5;
3061 1.1 christos op = create_bitfield_operand (width, offset);
3062 1.1 christos if (op == NULL)
3063 1.1 christos return -1;
3064 1.1 christos operands[(*n_operands)++] = op;
3065 1.1 christos }
3066 1.1 christos break;
3067 1.1 christos }
3068 1.1 christos return 0;
3069 1.1 christos }
3070 1.1 christos
3071 1.1 christos
3072 1.1 christos /* Decode the next instruction at MRA, according to OPC.
3073 1.1 christos The operation to be performed is returned.
3074 1.1.1.2 christos The number of operands, will be placed in N_OPERANDS.
3075 1.1.1.2 christos The operands themselved into OPERANDS. */
3076 1.1.1.2 christos static enum optr
3077 1.1.1.2 christos decode_operation (const struct opcode *opc,
3078 1.1.1.2 christos struct mem_read_abstraction_base *mra,
3079 1.1 christos int *n_operands, struct operand **operands)
3080 1.1 christos {
3081 1.1.1.2 christos enum optr op = opc->operator;
3082 1.1.1.2 christos if (opc->discriminator)
3083 1.1 christos {
3084 1.1 christos op = opc->discriminator (mra, opc->operator);
3085 1.1.1.2 christos if (op == OP_INVALID)
3086 1.1.1.2 christos return op;
3087 1.1 christos }
3088 1.1 christos
3089 1.1 christos if (opc->operands)
3090 1.1 christos if (opc->operands (mra, n_operands, operands) < 0)
3091 1.1 christos return OP_INVALID;
3092 1.1 christos
3093 1.1 christos if (opc->operands2)
3094 1.1 christos if (opc->operands2 (mra, n_operands, operands) < 0)
3095 1.1 christos return OP_INVALID;
3096 1.1 christos
3097 1.1 christos return op;
3098 1.1 christos }
3099 1.1 christos
3100 1.1.1.2 christos int
3101 1.1 christos decode_s12z (enum optr *myoperator, short *osize,
3102 1.1 christos int *n_operands, struct operand **operands,
3103 1.1 christos struct mem_read_abstraction_base *mra)
3104 1.1 christos {
3105 1.1 christos int n_bytes = 0;
3106 1.1 christos bfd_byte byte;
3107 1.1 christos
3108 1.1 christos int status = mra->read (mra, 0, 1, &byte);
3109 1.1 christos if (status < 0)
3110 1.1 christos return status;
3111 1.1 christos
3112 1.1.1.2 christos mra->advance (mra);
3113 1.1.1.2 christos
3114 1.1.1.2 christos const struct opcode *opc = page1 + byte;
3115 1.1 christos if (byte == PAGE2_PREBYTE)
3116 1.1 christos {
3117 1.1 christos /* Opcodes in page2 have an additional byte */
3118 1.1 christos n_bytes++;
3119 1.1 christos
3120 1.1 christos bfd_byte byte2;
3121 1.1 christos status = mra->read (mra, 0, 1, &byte2);
3122 1.1.1.2 christos if (status < 0)
3123 1.1.1.2 christos return status;
3124 1.1.1.2 christos mra->advance (mra);
3125 1.1.1.2 christos opc = page2 + byte2;
3126 1.1.1.2 christos }
3127 1.1.1.2 christos *myoperator = decode_operation (opc, mra, n_operands, operands);
3128 1.1.1.2 christos *osize = opc->osize;
3129 1.1.1.2 christos
3130 1.1.1.2 christos /* Return the number of bytes in the instruction. */
3131 1.1 christos if (*myoperator != OP_INVALID && opc->insn_bytes)
3132 1.1 christos {
3133 1.1 christos int n = opc->insn_bytes (mra);
3134 1.1 christos if (n < 0)
3135 return n;
3136 n_bytes += n;
3137 }
3138 else
3139 n_bytes += 1;
3140
3141 return n_bytes;
3142 }
3143
3144