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