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