forked from bminor/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcris-dis.c
1688 lines (1414 loc) · 44.1 KB
/
cris-dis.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Disassembler code for CRIS.
Copyright (C) 2000-2016 Free Software Foundation, Inc.
Contributed by Axis Communications AB, Lund, Sweden.
Written by Hans-Peter Nilsson.
This file is part of the GNU opcodes library.
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
It is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#include "sysdep.h"
#include "dis-asm.h"
#include "opcode/cris.h"
#include "libiberty.h"
/* No instruction will be disassembled longer than this. In theory, and
in silicon, address prefixes can be cascaded. In practice, cascading
is not used by GCC, and not supported by the assembler. */
#ifndef MAX_BYTES_PER_CRIS_INSN
#define MAX_BYTES_PER_CRIS_INSN 8
#endif
/* Whether or not to decode prefixes, folding it into the following
instruction. FIXME: Make this optional later. */
#ifndef PARSE_PREFIX
#define PARSE_PREFIX 1
#endif
/* Sometimes we prefix all registers with this character. */
#define REGISTER_PREFIX_CHAR '$'
/* Whether or not to trace the following sequence:
sub* X,r%d
bound* Y,r%d
adds.w [pc+r%d.w],pc
This is the assembly form of a switch-statement in C.
The "sub is optional. If there is none, then X will be zero.
X is the value of the first case,
Y is the number of cases (including default).
This results in case offsets printed on the form:
case N: -> case_address
where N is an estimation on the corresponding 'case' operand in C,
and case_address is where execution of that case continues after the
sequence presented above.
The old style of output was to print the offsets as instructions,
which made it hard to follow "case"-constructs in the disassembly,
and caused a lot of annoying warnings about undefined instructions.
FIXME: Make this optional later. */
#ifndef TRACE_CASE
#define TRACE_CASE (disdata->trace_case)
#endif
enum cris_disass_family
{ cris_dis_v0_v10, cris_dis_common_v10_v32, cris_dis_v32 };
/* Stored in the disasm_info->private_data member. */
struct cris_disasm_data
{
/* Whether to print something less confusing if we find something
matching a switch-construct. */
bfd_boolean trace_case;
/* Whether this code is flagged as crisv32. FIXME: Should be an enum
that includes "compatible". */
enum cris_disass_family distype;
};
/* Value of first element in switch. */
static long case_offset = 0;
/* How many more case-offsets to print. */
static long case_offset_counter = 0;
/* Number of case offsets. */
static long no_of_case_offsets = 0;
/* Candidate for next case_offset. */
static long last_immediate = 0;
static int cris_constraint
(const char *, unsigned, unsigned, struct cris_disasm_data *);
/* Parse disassembler options and store state in info. FIXME: For the
time being, we abuse static variables. */
static bfd_boolean
cris_parse_disassembler_options (disassemble_info *info,
enum cris_disass_family distype)
{
struct cris_disasm_data *disdata;
info->private_data = calloc (1, sizeof (struct cris_disasm_data));
disdata = (struct cris_disasm_data *) info->private_data;
if (disdata == NULL)
return FALSE;
/* Default true. */
disdata->trace_case
= (info->disassembler_options == NULL
|| (strcmp (info->disassembler_options, "nocase") != 0));
disdata->distype = distype;
return TRUE;
}
static const struct cris_spec_reg *
spec_reg_info (unsigned int sreg, enum cris_disass_family distype)
{
int i;
for (i = 0; cris_spec_regs[i].name != NULL; i++)
{
if (cris_spec_regs[i].number == sreg)
{
if (distype == cris_dis_v32)
switch (cris_spec_regs[i].applicable_version)
{
case cris_ver_warning:
case cris_ver_version_all:
case cris_ver_v3p:
case cris_ver_v8p:
case cris_ver_v10p:
case cris_ver_v32p:
/* No ambiguous sizes or register names with CRISv32. */
if (cris_spec_regs[i].warning == NULL)
return &cris_spec_regs[i];
default:
;
}
else if (cris_spec_regs[i].applicable_version != cris_ver_v32p)
return &cris_spec_regs[i];
}
}
return NULL;
}
/* Return the number of bits in the argument. */
static int
number_of_bits (unsigned int val)
{
int bits;
for (bits = 0; val != 0; val &= val - 1)
bits++;
return bits;
}
/* Get an entry in the opcode-table. */
static const struct cris_opcode *
get_opcode_entry (unsigned int insn,
unsigned int prefix_insn,
struct cris_disasm_data *disdata)
{
/* For non-prefixed insns, we keep a table of pointers, indexed by the
insn code. Each entry is initialized when found to be NULL. */
static const struct cris_opcode **opc_table = NULL;
const struct cris_opcode *max_matchedp = NULL;
const struct cris_opcode **prefix_opc_table = NULL;
/* We hold a table for each prefix that need to be handled differently. */
static const struct cris_opcode **dip_prefixes = NULL;
static const struct cris_opcode **bdapq_m1_prefixes = NULL;
static const struct cris_opcode **bdapq_m2_prefixes = NULL;
static const struct cris_opcode **bdapq_m4_prefixes = NULL;
static const struct cris_opcode **rest_prefixes = NULL;
/* Allocate and clear the opcode-table. */
if (opc_table == NULL)
{
opc_table = malloc (65536 * sizeof (opc_table[0]));
if (opc_table == NULL)
return NULL;
memset (opc_table, 0, 65536 * sizeof (const struct cris_opcode *));
dip_prefixes
= malloc (65536 * sizeof (const struct cris_opcode **));
if (dip_prefixes == NULL)
return NULL;
memset (dip_prefixes, 0, 65536 * sizeof (dip_prefixes[0]));
bdapq_m1_prefixes
= malloc (65536 * sizeof (const struct cris_opcode **));
if (bdapq_m1_prefixes == NULL)
return NULL;
memset (bdapq_m1_prefixes, 0, 65536 * sizeof (bdapq_m1_prefixes[0]));
bdapq_m2_prefixes
= malloc (65536 * sizeof (const struct cris_opcode **));
if (bdapq_m2_prefixes == NULL)
return NULL;
memset (bdapq_m2_prefixes, 0, 65536 * sizeof (bdapq_m2_prefixes[0]));
bdapq_m4_prefixes
= malloc (65536 * sizeof (const struct cris_opcode **));
if (bdapq_m4_prefixes == NULL)
return NULL;
memset (bdapq_m4_prefixes, 0, 65536 * sizeof (bdapq_m4_prefixes[0]));
rest_prefixes
= malloc (65536 * sizeof (const struct cris_opcode **));
if (rest_prefixes == NULL)
return NULL;
memset (rest_prefixes, 0, 65536 * sizeof (rest_prefixes[0]));
}
/* Get the right table if this is a prefix.
This code is connected to cris_constraints in that it knows what
prefixes play a role in recognition of patterns; the necessary
state is reflected by which table is used. If constraints
involving match or non-match of prefix insns are changed, then this
probably needs changing too. */
if (prefix_insn != NO_CRIS_PREFIX)
{
const struct cris_opcode *popcodep
= (opc_table[prefix_insn] != NULL
? opc_table[prefix_insn]
: get_opcode_entry (prefix_insn, NO_CRIS_PREFIX, disdata));
if (popcodep == NULL)
return NULL;
if (popcodep->match == BDAP_QUICK_OPCODE)
{
/* Since some offsets are recognized with "push" macros, we
have to have different tables for them. */
int offset = (prefix_insn & 255);
if (offset > 127)
offset -= 256;
switch (offset)
{
case -4:
prefix_opc_table = bdapq_m4_prefixes;
break;
case -2:
prefix_opc_table = bdapq_m2_prefixes;
break;
case -1:
prefix_opc_table = bdapq_m1_prefixes;
break;
default:
prefix_opc_table = rest_prefixes;
break;
}
}
else if (popcodep->match == DIP_OPCODE)
/* We don't allow postincrement when the prefix is DIP, so use a
different table for DIP. */
prefix_opc_table = dip_prefixes;
else
prefix_opc_table = rest_prefixes;
}
if (prefix_insn != NO_CRIS_PREFIX
&& prefix_opc_table[insn] != NULL)
max_matchedp = prefix_opc_table[insn];
else if (prefix_insn == NO_CRIS_PREFIX && opc_table[insn] != NULL)
max_matchedp = opc_table[insn];
else
{
const struct cris_opcode *opcodep;
int max_level_of_match = -1;
for (opcodep = cris_opcodes;
opcodep->name != NULL;
opcodep++)
{
int level_of_match;
if (disdata->distype == cris_dis_v32)
{
switch (opcodep->applicable_version)
{
case cris_ver_version_all:
break;
case cris_ver_v0_3:
case cris_ver_v0_10:
case cris_ver_v3_10:
case cris_ver_sim_v0_10:
case cris_ver_v8_10:
case cris_ver_v10:
case cris_ver_warning:
continue;
case cris_ver_v3p:
case cris_ver_v8p:
case cris_ver_v10p:
case cris_ver_v32p:
break;
case cris_ver_v8:
abort ();
default:
abort ();
}
}
else
{
switch (opcodep->applicable_version)
{
case cris_ver_version_all:
case cris_ver_v0_3:
case cris_ver_v3p:
case cris_ver_v0_10:
case cris_ver_v8p:
case cris_ver_v8_10:
case cris_ver_v10:
case cris_ver_sim_v0_10:
case cris_ver_v10p:
case cris_ver_warning:
break;
case cris_ver_v32p:
continue;
case cris_ver_v8:
abort ();
default:
abort ();
}
}
/* We give a double lead for bits matching the template in
cris_opcodes. Not even, because then "move p8,r10" would
be given 2 bits lead over "clear.d r10". When there's a
tie, the first entry in the table wins. This is
deliberate, to avoid a more complicated recognition
formula. */
if ((opcodep->match & insn) == opcodep->match
&& (opcodep->lose & insn) == 0
&& ((level_of_match
= cris_constraint (opcodep->args,
insn,
prefix_insn,
disdata))
>= 0)
&& ((level_of_match
+= 2 * number_of_bits (opcodep->match
| opcodep->lose))
> max_level_of_match))
{
max_matchedp = opcodep;
max_level_of_match = level_of_match;
/* If there was a full match, never mind looking
further. */
if (level_of_match >= 2 * 16)
break;
}
}
/* Fill in the new entry.
If there are changes to the opcode-table involving prefixes, and
disassembly then does not work correctly, try removing the
else-clause below that fills in the prefix-table. If that
helps, you need to change the prefix_opc_table setting above, or
something related. */
if (prefix_insn == NO_CRIS_PREFIX)
opc_table[insn] = max_matchedp;
else
prefix_opc_table[insn] = max_matchedp;
}
return max_matchedp;
}
/* Return -1 if the constraints of a bitwise-matched instruction say
that there is no match. Otherwise return a nonnegative number
indicating the confidence in the match (higher is better). */
static int
cris_constraint (const char *cs,
unsigned int insn,
unsigned int prefix_insn,
struct cris_disasm_data *disdata)
{
int retval = 0;
int tmp;
int prefix_ok = 0;
const char *s;
for (s = cs; *s; s++)
switch (*s)
{
case '!':
/* Do not recognize "pop" if there's a prefix and then only for
v0..v10. */
if (prefix_insn != NO_CRIS_PREFIX
|| disdata->distype != cris_dis_v0_v10)
return -1;
break;
case 'U':
/* Not recognized at disassembly. */
return -1;
case 'M':
/* Size modifier for "clear", i.e. special register 0, 4 or 8.
Check that it is one of them. Only special register 12 could
be mismatched, but checking for matches is more logical than
checking for mismatches when there are only a few cases. */
tmp = ((insn >> 12) & 0xf);
if (tmp != 0 && tmp != 4 && tmp != 8)
return -1;
break;
case 'm':
if ((insn & 0x30) == 0x30)
return -1;
break;
case 'S':
/* A prefix operand without side-effect. */
if (prefix_insn != NO_CRIS_PREFIX && (insn & 0x400) == 0)
{
prefix_ok = 1;
break;
}
else
return -1;
case 's':
case 'y':
case 'Y':
/* If this is a prefixed insn with postincrement (side-effect),
the prefix must not be DIP. */
if (prefix_insn != NO_CRIS_PREFIX)
{
if (insn & 0x400)
{
const struct cris_opcode *prefix_opcodep
= get_opcode_entry (prefix_insn, NO_CRIS_PREFIX, disdata);
if (prefix_opcodep->match == DIP_OPCODE)
return -1;
}
prefix_ok = 1;
}
break;
case 'B':
/* If we don't fall through, then the prefix is ok. */
prefix_ok = 1;
/* A "push" prefix. Check for valid "push" size.
In case of special register, it may be != 4. */
if (prefix_insn != NO_CRIS_PREFIX)
{
/* Match the prefix insn to BDAPQ. */
const struct cris_opcode *prefix_opcodep
= get_opcode_entry (prefix_insn, NO_CRIS_PREFIX, disdata);
if (prefix_opcodep->match == BDAP_QUICK_OPCODE)
{
int pushsize = (prefix_insn & 255);
if (pushsize > 127)
pushsize -= 256;
if (s[1] == 'P')
{
unsigned int spec_reg = (insn >> 12) & 15;
const struct cris_spec_reg *sregp
= spec_reg_info (spec_reg, disdata->distype);
/* For a special-register, the "prefix size" must
match the size of the register. */
if (sregp && sregp->reg_size == (unsigned int) -pushsize)
break;
}
else if (s[1] == 'R')
{
if ((insn & 0x30) == 0x20 && pushsize == -4)
break;
}
/* FIXME: Should abort here; next constraint letter
*must* be 'P' or 'R'. */
}
}
return -1;
case 'D':
retval = (((insn >> 12) & 15) == (insn & 15));
if (!retval)
return -1;
else
retval += 4;
break;
case 'P':
{
const struct cris_spec_reg *sregp
= spec_reg_info ((insn >> 12) & 15, disdata->distype);
/* Since we match four bits, we will give a value of 4-1 = 3
in a match. If there is a corresponding exact match of a
special register in another pattern, it will get a value of
4, which will be higher. This should be correct in that an
exact pattern would match better than a general pattern.
Note that there is a reason for not returning zero; the
pattern for "clear" is partly matched in the bit-pattern
(the two lower bits must be zero), while the bit-pattern
for a move from a special register is matched in the
register constraint. */
if (sregp != NULL)
{
retval += 3;
break;
}
else
return -1;
}
}
if (prefix_insn != NO_CRIS_PREFIX && ! prefix_ok)
return -1;
return retval;
}
/* Format number as hex with a leading "0x" into outbuffer. */
static char *
format_hex (unsigned long number,
char *outbuffer,
struct cris_disasm_data *disdata)
{
/* Truncate negative numbers on >32-bit hosts. */
number &= 0xffffffff;
sprintf (outbuffer, "0x%lx", number);
/* Save this value for the "case" support. */
if (TRACE_CASE)
last_immediate = number;
return outbuffer + strlen (outbuffer);
}
/* Format number as decimal into outbuffer. Parameter signedp says
whether the number should be formatted as signed (!= 0) or
unsigned (== 0). */
static char *
format_dec (long number, char *outbuffer, int signedp)
{
last_immediate = number;
if (signedp)
sprintf (outbuffer, "%ld", number);
else
sprintf (outbuffer, "%lu", (unsigned long) number);
return outbuffer + strlen (outbuffer);
}
/* Format the name of the general register regno into outbuffer. */
static char *
format_reg (struct cris_disasm_data *disdata,
int regno,
char *outbuffer_start,
bfd_boolean with_reg_prefix)
{
char *outbuffer = outbuffer_start;
if (with_reg_prefix)
*outbuffer++ = REGISTER_PREFIX_CHAR;
switch (regno)
{
case 15:
/* For v32, there is no context in which we output PC. */
if (disdata->distype == cris_dis_v32)
strcpy (outbuffer, "acr");
else
strcpy (outbuffer, "pc");
break;
case 14:
strcpy (outbuffer, "sp");
break;
default:
sprintf (outbuffer, "r%d", regno);
break;
}
return outbuffer_start + strlen (outbuffer_start);
}
/* Format the name of a support register into outbuffer. */
static char *
format_sup_reg (unsigned int regno,
char *outbuffer_start,
bfd_boolean with_reg_prefix)
{
char *outbuffer = outbuffer_start;
int i;
if (with_reg_prefix)
*outbuffer++ = REGISTER_PREFIX_CHAR;
for (i = 0; cris_support_regs[i].name != NULL; i++)
if (cris_support_regs[i].number == regno)
{
sprintf (outbuffer, "%s", cris_support_regs[i].name);
return outbuffer_start + strlen (outbuffer_start);
}
/* There's supposed to be register names covering all numbers, though
some may be generic names. */
sprintf (outbuffer, "format_sup_reg-BUG");
return outbuffer_start + strlen (outbuffer_start);
}
/* Return the length of an instruction. */
static unsigned
bytes_to_skip (unsigned int insn,
const struct cris_opcode *matchedp,
enum cris_disass_family distype,
const struct cris_opcode *prefix_matchedp)
{
/* Each insn is a word plus "immediate" operands. */
unsigned to_skip = 2;
const char *template_name = (const char *) matchedp->args;
const char *s;
for (s = template_name; *s; s++)
if ((*s == 's' || *s == 'N' || *s == 'Y')
&& (insn & 0x400) && (insn & 15) == 15
&& prefix_matchedp == NULL)
{
/* Immediate via [pc+], so we have to check the size of the
operand. */
int mode_size = 1 << ((insn >> 4) & (*template_name == 'z' ? 1 : 3));
if (matchedp->imm_oprnd_size == SIZE_FIX_32)
to_skip += 4;
else if (matchedp->imm_oprnd_size == SIZE_SPEC_REG)
{
const struct cris_spec_reg *sregp
= spec_reg_info ((insn >> 12) & 15, distype);
/* FIXME: Improve error handling; should have been caught
earlier. */
if (sregp == NULL)
return 2;
/* PC is incremented by two, not one, for a byte. Except on
CRISv32, where constants are always DWORD-size for
special registers. */
to_skip +=
distype == cris_dis_v32 ? 4 : (sregp->reg_size + 1) & ~1;
}
else
to_skip += (mode_size + 1) & ~1;
}
else if (*s == 'n')
to_skip += 4;
else if (*s == 'b')
to_skip += 2;
return to_skip;
}
/* Print condition code flags. */
static char *
print_flags (struct cris_disasm_data *disdata, unsigned int insn, char *cp)
{
/* Use the v8 (Etrax 100) flag definitions for disassembly.
The differences with v0 (Etrax 1..4) vs. Svinto are:
v0 'd' <=> v8 'm'
v0 'e' <=> v8 'b'.
FIXME: Emit v0..v3 flag names somehow. */
static const char v8_fnames[] = "cvznxibm";
static const char v32_fnames[] = "cvznxiup";
const char *fnames
= disdata->distype == cris_dis_v32 ? v32_fnames : v8_fnames;
unsigned char flagbits = (((insn >> 8) & 0xf0) | (insn & 15));
int i;
for (i = 0; i < 8; i++)
if (flagbits & (1 << i))
*cp++ = fnames[i];
return cp;
}
/* Print out an insn with its operands, and update the info->insn_type
fields. The prefix_opcodep and the rest hold a prefix insn that is
supposed to be output as an address mode. */
static void
print_with_operands (const struct cris_opcode *opcodep,
unsigned int insn,
unsigned char *buffer,
bfd_vma addr,
disassemble_info *info,
/* If a prefix insn was before this insn (and is supposed
to be output as an address), here is a description of
it. */
const struct cris_opcode *prefix_opcodep,
unsigned int prefix_insn,
unsigned char *prefix_buffer,
bfd_boolean with_reg_prefix)
{
/* Get a buffer of somewhat reasonable size where we store
intermediate parts of the insn. */
char temp[sizeof (".d [$r13=$r12-2147483648],$r10") * 2];
char *tp = temp;
static const char mode_char[] = "bwd?";
const char *s;
const char *cs;
struct cris_disasm_data *disdata
= (struct cris_disasm_data *) info->private_data;
/* Print out the name first thing we do. */
(*info->fprintf_func) (info->stream, "%s", opcodep->name);
cs = opcodep->args;
s = cs;
/* Ignore any prefix indicator. */
if (*s == 'p')
s++;
if (*s == 'm' || *s == 'M' || *s == 'z')
{
*tp++ = '.';
/* Get the size-letter. */
*tp++ = *s == 'M'
? (insn & 0x8000 ? 'd'
: insn & 0x4000 ? 'w' : 'b')
: mode_char[(insn >> 4) & (*s == 'z' ? 1 : 3)];
/* Ignore the size and the space character that follows. */
s += 2;
}
/* Add a space if this isn't a long-branch, because for those will add
the condition part of the name later. */
if (opcodep->match != (BRANCH_PC_LOW + BRANCH_INCR_HIGH * 256))
*tp++ = ' ';
/* Fill in the insn-type if deducible from the name (and there's no
better way). */
if (opcodep->name[0] == 'j')
{
if (CONST_STRNEQ (opcodep->name, "jsr"))
/* It's "jsr" or "jsrc". */
info->insn_type = dis_jsr;
else
/* Any other jump-type insn is considered a branch. */
info->insn_type = dis_branch;
}
/* We might know some more fields right now. */
info->branch_delay_insns = opcodep->delayed;
/* Handle operands. */
for (; *s; s++)
{
switch (*s)
{
case 'T':
tp = format_sup_reg ((insn >> 12) & 15, tp, with_reg_prefix);
break;
case 'A':
if (with_reg_prefix)
*tp++ = REGISTER_PREFIX_CHAR;
*tp++ = 'a';
*tp++ = 'c';
*tp++ = 'r';
break;
case '[':
case ']':
case ',':
*tp++ = *s;
break;
case '!':
/* Ignore at this point; used at earlier stages to avoid
recognition if there's a prefix at something that in other
ways looks like a "pop". */
break;
case 'd':
/* Ignore. This is an optional ".d " on the large one of
relaxable insns. */
break;
case 'B':
/* This was the prefix that made this a "push". We've already
handled it by recognizing it, so signal that the prefix is
handled by setting it to NULL. */
prefix_opcodep = NULL;
break;
case 'D':
case 'r':
tp = format_reg (disdata, insn & 15, tp, with_reg_prefix);
break;
case 'R':
tp = format_reg (disdata, (insn >> 12) & 15, tp, with_reg_prefix);
break;
case 'n':
{
/* Like N but pc-relative to the start of the insn. */
unsigned long number
= (buffer[2] + buffer[3] * 256 + buffer[4] * 65536
+ buffer[5] * 0x1000000 + addr);
/* Finish off and output previous formatted bytes. */
*tp = 0;
if (temp[0])
(*info->fprintf_func) (info->stream, "%s", temp);
tp = temp;
(*info->print_address_func) ((bfd_vma) number, info);
}
break;
case 'u':
{
/* Like n but the offset is bits <3:0> in the instruction. */
unsigned long number = (buffer[0] & 0xf) * 2 + addr;
/* Finish off and output previous formatted bytes. */
*tp = 0;
if (temp[0])
(*info->fprintf_func) (info->stream, "%s", temp);
tp = temp;
(*info->print_address_func) ((bfd_vma) number, info);
}
break;
case 'N':
case 'y':
case 'Y':
case 'S':
case 's':
/* Any "normal" memory operand. */
if ((insn & 0x400) && (insn & 15) == 15 && prefix_opcodep == NULL)
{
/* We're looking at [pc+], i.e. we need to output an immediate
number, where the size can depend on different things. */
long number;
int signedp
= ((*cs == 'z' && (insn & 0x20))
|| opcodep->match == BDAP_QUICK_OPCODE);
int nbytes;
if (opcodep->imm_oprnd_size == SIZE_FIX_32)
nbytes = 4;
else if (opcodep->imm_oprnd_size == SIZE_SPEC_REG)
{
const struct cris_spec_reg *sregp
= spec_reg_info ((insn >> 12) & 15, disdata->distype);
/* A NULL return should have been as a non-match earlier,
so catch it as an internal error in the error-case
below. */
if (sregp == NULL)
/* Whatever non-valid size. */
nbytes = 42;
else
/* PC is always incremented by a multiple of two.
For CRISv32, immediates are always 4 bytes for
special registers. */
nbytes = disdata->distype == cris_dis_v32
? 4 : (sregp->reg_size + 1) & ~1;
}
else
{
int mode_size = 1 << ((insn >> 4) & (*cs == 'z' ? 1 : 3));
if (mode_size == 1)
nbytes = 2;
else
nbytes = mode_size;
}
switch (nbytes)
{
case 1:
number = buffer[2];
if (signedp && number > 127)
number -= 256;
break;
case 2:
number = buffer[2] + buffer[3] * 256;
if (signedp && number > 32767)
number -= 65536;
break;
case 4:
number
= buffer[2] + buffer[3] * 256 + buffer[4] * 65536
+ buffer[5] * 0x1000000;
break;
default:
strcpy (tp, "bug");
tp += 3;
number = 42;
}
if ((*cs == 'z' && (insn & 0x20))
|| (opcodep->match == BDAP_QUICK_OPCODE
&& (nbytes <= 2 || buffer[1 + nbytes] == 0)))
tp = format_dec (number, tp, signedp);
else
{
unsigned int highbyte = (number >> 24) & 0xff;
/* Either output this as an address or as a number. If it's
a dword with the same high-byte as the address of the
insn, assume it's an address, and also if it's a non-zero
non-0xff high-byte. If this is a jsr or a jump, then
it's definitely an address. */
if (nbytes == 4
&& (highbyte == ((addr >> 24) & 0xff)
|| (highbyte != 0 && highbyte != 0xff)
|| info->insn_type == dis_branch
|| info->insn_type == dis_jsr))
{
/* Finish off and output previous formatted bytes. */
*tp = 0;
tp = temp;
if (temp[0])
(*info->fprintf_func) (info->stream, "%s", temp);
(*info->print_address_func) ((bfd_vma) number, info);
info->target = number;
}
else
tp = format_hex (number, tp, disdata);
}
}
else
{
/* Not an immediate number. Then this is a (possibly
prefixed) memory operand. */
if (info->insn_type != dis_nonbranch)
{
int mode_size
= 1 << ((insn >> 4)
& (opcodep->args[0] == 'z' ? 1 : 3));
int size;
info->insn_type = dis_dref;
info->flags |= CRIS_DIS_FLAG_MEMREF;
if (opcodep->imm_oprnd_size == SIZE_FIX_32)