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
|
/* Print i860 instructions for GDB, the GNU debugger.
Copyright status of this module is unclear!!!
Copyright (C) 1992 Free Software Foundation, Inc.
SVR4 changes Contributed by Peggy Fieland (pfieland@stratus.com)
GDB is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY. No author or distributor accepts responsibility to anyone
for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing.
Refer to the GDB General Public License for full details.
Everyone is granted permission to copy, modify and redistribute GDB,
but only under the conditions described in the GDB General Public
License. A copy of this license is supposed to have been given to you
along with GDB so you can know your rights and responsibilities. It
should be in a file named COPYING. Among other things, the copyright
notice and this notice must be preserved on all copies.
In other words, go ahead and share GDB, but don't try to stop
anyone else from sharing it farther. Help stamp out software hoarding!
*/
#include "defs.h"
#include "tm-i860.h"
#include "i860-opcode.h"
/* i860 instructions are never longer than this many bytes. */
#define MAXLEN 4
static int fp_instr();
static void fld_offset();
static void gen_rrr();
static void gen_irr();
static void ctrl_a();
/*
* integer registers names
*/
static char *ireg[32] =
{
"r0", "r1", "sp", "fp", "r4", "r5", "r6", "r7",
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
"r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
"r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
};
/*
* Control registers of the ld.c and st.c instructions
*/
static char *ctlreg[32] =
{
"fir", "psr", "dirbase", "db", "fsr", "?", "?", "?",
"?", "?", "?", "?", "?", "?", "?", "?",
"?", "?", "?", "?", "?", "?", "?", "?",
"?", "?", "?", "?", "?", "?", "?", "?"
};
/***********************************************************************
* Print the i860 instruction at address MEMADDR in debugged memory,
* on STREAM. Returns length of the instruction, in bytes, which
* is always 4.
*/
int
print_insn (memaddr, stream)
CORE_ADDR memaddr; /* address of the instruction */
FILE *stream; /* stream on which to write result */
{
union insn_fmt insn; /* the instruction we're decoding */
long offset; /* the (decoded) offset from the instruction */
long split_offset; /* the value of a ld/st-style split offset */
int ai; /* autoincrement flag */
char suffix; /* length suffix */
adj_read_memory (memaddr, &insn, MAXLEN);
/* These offsets used in ld, st, bte, etc. instructions and are formed by
* combining 2 separate fields within the instruction and sign-extending
* the result
*/
split_offset = (insn.gen.dest << 11) | insn.gen.offset;
split_offset = SIGN_EXT(16, split_offset);
switch (insn.gen.op1)
{
case 000:
fprintf (stream, "ld.b %s(%s),%s", ireg[insn.gen.src1],
ireg[insn.gen.src2], ireg[insn.gen.dest]);
break;
case 001:
offset = SIGN_EXT(16, insn.geni.offset);
fprintf (stream, "ld.b 0x%x(%s),%s", offset,
ireg[insn.geni.src2], ireg[insn.geni.dest]);
break;
case 002:
fprintf (stream, "ixfr %s,f%d", ireg[insn.gen.src1], insn.gen.dest);
break;
case 003:
fprintf (stream, "st.b %s,0x%x(%s)", ireg[insn.gen.src1], split_offset,
ireg[insn.geni.src2]);
break;
case 004:
fprintf (stream, "ld.%c %s(%s),%s", (insn.gen.offset & 1) ? 'l' : 's',
ireg[insn.gen.src1], ireg[insn.gen.src2], ireg[insn.gen.dest]);
break;
case 005:
offset = SIGN_EXT(16, insn.geni.offset);
fprintf (stream, "ld.%c 0x%x(%s),%s", (insn.geni.offset & 1) ? 'l' : 's',
(offset & ~1), ireg[insn.geni.src2], ireg[insn.geni.dest]);
break;
case 007:
fprintf (stream, "st.%c %s,0x%x(%s)", (insn.geni.offset & 1) ? 'l' : 's',
ireg[insn.gen.src1], (split_offset & ~1), ireg[insn.geni.src2]);
break;
case 010:
offset = insn.gen.offset;
fld_offset(&offset, &suffix, &ai);
fprintf (stream, "fld.%c %s(%s)%s,f%d", suffix,
ireg[insn.gen.src1], ireg[insn.gen.src2], ai ? "++" : "",
insn.gen.dest);
break;
case 011:
offset = SIGN_EXT(16, insn.geni.offset);
fld_offset(&offset, &suffix, &ai);
fprintf (stream, "fld.%c 0x%x(%s)%s,f%d", suffix,
offset, ireg[insn.gen.src2], ai ? "++" : "", insn.gen.dest);
break;
case 012:
offset = insn.gen.offset;
fld_offset(&offset, &suffix, &ai);
fprintf (stream, "fst.%c f%d,%s(%s)%s", suffix,
insn.gen.dest, ireg[insn.gen.src1], ireg[insn.gen.src2],
ai ? "++" : "");
break;
case 013:
offset = SIGN_EXT(16, insn.geni.offset);
fld_offset(&offset, &suffix, &ai);
fprintf (stream, "fst.%c f%d,0x%x(%s)%s", suffix,
insn.gen.dest, offset, ireg[insn.gen.src2], ai ? "++" : "");
break;
case 014:
fprintf (stream, "ld.c %s,%s", ctlreg[insn.gen.src2],
ireg[insn.gen.dest]);
break;
case 015:
offset = SIGN_EXT(16, insn.geni.offset);
fld_offset(&offset, &suffix, &ai);
fprintf (stream, "flush 0x%x(%s)%s", offset, ireg[insn.gen.src2],
ai ? "++" : "");
break;
case 016:
fprintf (stream, "st.c %s,%s", ireg[insn.gen.src1],
ctlreg[insn.gen.src2]);
break;
case 017:
offset = SIGN_EXT(16, insn.geni.offset);
fld_offset(&offset, &suffix, &ai);
fprintf (stream, "pst.d f%d,0x%x(%s)%s", insn.gen.dest,
offset, ireg[insn.gen.src2], ai ? "++" : "");
break;
case 020:
fprintf (stream, "bri %s", ireg[insn.gen.src1]);
break;
case 021:
gen_rrr("trap", insn, stream);
break;
case 022:
/*
* Floating-point Opcodes
*/
if (!fp_instr(insn.fp, stream))
fprintf (stream, "0x%08x (invalid instruction)", insn.int_val);
break;
case 023:
/*
* Core Escape Opcodes
*/
switch (insn.esc.op2)
{
case 1:
fprintf (stream, "lock");
break;
case 2:
fprintf (stream, "calli %s", ireg[insn.esc.src1]);
break;
case 4:
fprintf (stream, "intovr");
break;
case 7:
fprintf (stream, "unlock");
break;
default:
fprintf (stream, "0x%08x (invalid instruction)", insn.int_val);
break;
}
break;
case 024:
fprintf (stream, "btne %s,%s,", ireg[insn.gen.src1],
ireg[insn.gen.src2]);
offset = split_offset << 2;
print_address ((CORE_ADDR) (memaddr + 4 + offset), stream);
break;
case 025:
fprintf (stream, "btne 0x%x,%s,", insn.gen.src1, ireg[insn.gen.src2]);
offset = split_offset << 2;
print_address ((CORE_ADDR) (memaddr + 4 + offset), stream);
break;
case 026:
fprintf (stream, "bte %s,%s,", ireg[insn.gen.src1],
ireg[insn.gen.src2]);
offset = split_offset << 2;
print_address ((CORE_ADDR) (memaddr + 4 + offset), stream);
break;
case 027:
fprintf (stream, "bte 0x%x,%s,", insn.gen.src1, ireg[insn.gen.src2]);
offset = split_offset << 2;
print_address ((CORE_ADDR) (memaddr + 4 + offset), stream);
break;
case 030:
offset = insn.gen.offset;
fld_offset(&offset, &suffix, &ai);
fprintf (stream, "pfld.%c %s(%s)%s,f%d", suffix,
ireg[insn.gen.src1], ireg[insn.gen.src2], ai ? "++" : "",
insn.gen.dest);
break;
case 031:
offset = SIGN_EXT(16, insn.geni.offset);
fld_offset(&offset, &suffix, &ai);
fprintf (stream, "pfld.%c 0x%x(%s)%s,f%d", suffix,
offset, ireg[insn.gen.src2], ai ? "++" : "", insn.gen.dest);
break;
case 032:
ctrl_a("br", insn, memaddr, stream);
break;
case 033:
ctrl_a("call", insn, memaddr, stream);
break;
case 034:
ctrl_a("bc", insn, memaddr, stream);
break;
case 035:
ctrl_a("bc.t", insn, memaddr, stream);
break;
case 036:
ctrl_a("bnc", insn, memaddr, stream);
break;
case 037:
ctrl_a("bnc.t", insn, memaddr, stream);
break;
case 040:
gen_rrr("addu", insn, stream);
break;
case 041:
gen_irr("addu", insn, SIGN_EXT(16, insn.geni.offset), stream);
break;
case 042:
gen_rrr("subu", insn, stream);
break;
case 043:
gen_irr("subu", insn, SIGN_EXT(16, insn.geni.offset), stream);
break;
case 044:
gen_rrr("adds", insn, stream);
break;
case 045:
gen_irr("adds", insn, SIGN_EXT(16, insn.geni.offset), stream);
break;
case 046:
gen_rrr("subs", insn, stream);
break;
case 047:
gen_irr("subs", insn, SIGN_EXT(16, insn.geni.offset), stream);
break;
case 050:
if (insn.gen.src1 == 0)
{
if (insn.gen.src2 == 0 && insn.gen.dest == 0)
fprintf (stream, "nop");
else
fprintf (stream, "mov %s,%s", ireg[insn.gen.src2],
ireg[insn.gen.dest]);
}
else
gen_rrr("shl", insn, stream);
break;
case 051:
gen_irr("shl", insn, insn.geni.offset, stream);
break;
case 052:
gen_rrr("shr", insn, stream);
break;
case 053:
gen_irr("shr", insn, insn.geni.offset, stream);
break;
case 054:
if (insn.gen.src1 == 0 && insn.gen.src2 == 0 && insn.gen.dest == 0)
{
if ((insn.int_val & (1 << 9)) != 0)
fprintf (stream, "d.");
fprintf (stream, "fnop");
}
else
gen_rrr("shrd", insn, stream);
break;
case 055:
fprintf (stream, "bla %s,%s,", ireg[insn.gen.src1],
ireg[insn.gen.src2]);
offset = split_offset << 2;
print_address ((CORE_ADDR) (memaddr + 4 + offset), stream);
break;
case 056:
gen_rrr("shra", insn, stream);
break;
case 057:
gen_irr("shra", insn, insn.geni.offset, stream);
break;
case 060:
gen_rrr("and", insn, stream);
break;
case 061:
gen_irr("and", insn, insn.geni.offset, stream);
break;
case 063:
gen_irr("andh", insn, insn.geni.offset, stream);
break;
case 064:
gen_rrr("andnot", insn, stream);
break;
case 065:
gen_irr("andnot", insn, insn.geni.offset, stream);
break;
case 067:
gen_irr("andnoth", insn, insn.geni.offset, stream);
break;
case 070:
gen_rrr("or", insn, stream);
break;
case 071:
gen_irr("or", insn, insn.geni.offset, stream);
break;
case 073:
gen_irr("orh", insn, insn.geni.offset, stream);
break;
case 074:
gen_rrr("xor", insn, stream);
break;
case 075:
gen_irr("xor", insn, insn.geni.offset, stream);
break;
case 077:
gen_irr("xorh", insn, insn.geni.offset, stream);
break;
default:
fprintf (stream, "0x%08x (invalid instruction)", insn.int_val);
break;
}
return(4);
}
/* A full list of floating point opcodes - if the entry is NULL, there is
* no corresponding instruction
*/
static char *fp_ops[] =
{
"r2p1", "r2pt", "r2ap1", "r2apt",
"i2p1", "i2pt", "i2ap1", "i2apt",
"rat1p2", "m12apm", "ra1p2", "m12ttpa",
"iat1p2", "m12tpm", "ia1p2", "m12tpa",
"r2s1", "r2st", "r2as1", "r2ast",
"i2s1", "i2st", "i2as1", "i2ast",
"rat1s2", "m12asm", "ra1s2", "m12ttsa",
"iat1s2", "m12tsm", "ia1s2", "m12tsa",
"fmul", "fmlow", "frcp", "frsqr",
"fmul3", NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
"fadd", "fsub", "fix", "famov",
"fgt", "feq", NULL, NULL,
NULL, NULL, "ftrunc", NULL,
NULL, NULL, NULL, NULL,
"fxfr", NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
NULL, "fiadd", NULL, NULL,
NULL, "fisub", NULL, NULL,
"faddp", "faddz", NULL, NULL,
NULL, NULL, NULL, "fzchkl",
NULL, NULL, "form", NULL,
NULL, NULL, NULL, "fzchks",
};
/* Alternate list of floating point opcodes for PFMAM/PFMSM instructions
*/
static char *alt_fp_ops[] =
{
"mr2p1", "mr2pt", "mr2mp1", "mr2mpt",
"mi2p1", "mi2pt", "mi2mp1", "mi2mpt",
"mrmt1p2", "mm12mpm", "mrm1p2", "mm12ttpm",
"mimt1p2", "mm12tpm", "mim1p2", "mm12tpm",
"mr2s1", "mr2st", "mr2ms1", "mr2mst",
"mi2s1", "mi2st", "mi2ms1", "mi2mst",
"mrmt1s2", "mm12msm", "mrm1s2", "mm12ttsm",
"mimt1s2", "mm12tsm", "mim1s2", "mm12tsm",
};
/* Floating point precision suffix values - indexed by s and r bits of
* instructions.
*/
static char precision[2] =
{
's', 'd',
};
/***********************************************************************
* Print floating-point instruction 'insn' on the indicated stream
* Returns 1 if successful, 0 on failure (invalid instruction)
*/
static int
fp_instr(insn, stream)
struct fp_fmt insn; /* instruction to decode */
FILE *stream; /* stream to print on */
{
char *name; /* the opcode name */
name = fp_ops[insn.op2];
if (name && insn.d)
fprintf(stream, "d.");
if (insn.op2 < 0x20)
{
/*
* DPC Ops
*/
if (insn.p == 0) /* use PFMAM/PFMSM ops if p=0 */
name = alt_fp_ops[insn.op2];
fprintf (stream, "%s.%c%c f%d,f%d,f%d", name,
precision[insn.s], precision[insn.r],
insn.src1, insn.src2, insn.dest);
}
else
{
switch (insn.op2)
{
case 0x21: /* fmlow (no pipeline allowed) */
fprintf (stream, "%s.%c%c f%d,f%d,f%d", name,
precision[insn.s], precision[insn.r],
insn.src1, insn.src2, insn.dest);
break;
case 0x22: /* frcp */
case 0x23: /* fsqrt */
fprintf (stream, "%s.%c%c f%d,f%d", name,
precision[insn.s], precision[insn.r],
insn.src2, insn.dest);
break;
case 0x24: /* pfmul3 */
fprintf (stream, "pfmul3.dd f%d,f%d,f%d",
insn.src1, insn.src2, insn.dest);
break;
case 0x30: /* fadd */
case 0x49: /* fiadd */
if (insn.src2 == 0)
{
/*
* Really fmov
*/
fprintf (stream, "%sfmov.%c%c f%d,f%d", insn.p ? "p" : "",
precision[insn.s], precision[insn.r],
insn.src1, insn.dest);
}
else
{
fprintf (stream, "%s%s.%c%c f%d,f%d,f%d", insn.p ? "p" : "", name,
precision[insn.s], precision[insn.r],
insn.src1, insn.src2, insn.dest);
}
break;
case 0x32: /* fix */
case 0x3A: /* ftrunc */
fprintf (stream, "%s%s.%c%c f%d,f%d", insn.p ? "p" : "", name,
precision[insn.s], precision[insn.r],
insn.src1, insn.dest);
break;
case 0x34: /* pfgt/pfle */
if (insn.r)
name = "fle";
fprintf (stream, "p%s.%c%c f%d,f%d,f%d", name,
precision[insn.s], precision[insn.s],
insn.src1, insn.src2, insn.dest);
break;
case 0x35: /* pfeq */
fprintf (stream, "pfeq.%c%c f%d,f%d,f%d",
precision[insn.s], precision[insn.r],
insn.src1, insn.src2, insn.dest);
break;
case 0x40: /* fxfr */
fprintf (stream, "fxfr f%d,%s", insn.src1, ireg[insn.dest]);
break;
case 0x50: /* faddp */
case 0x51: /* faddz */
case 0x57: /* fzchkl */
case 0x5F: /* fzchks */
/*
* Graphics ops with no precision
*/
fprintf (stream, "%s%s f%d,f%d,f%d", insn.p ? "p" : "", name,
insn.src1, insn.src2, insn.dest);
break;
case 0x5A: /* form */
fprintf (stream, "%sform f%d,f%d", insn.p ? "p" : "",
insn.src1, insn.dest);
break;
default:
/*
* All the rest are uniform 3-address, optionally pipelined, etc
*/
if (name)
fprintf (stream, "%s%s.%c%c f%d,f%d,f%d", insn.p ? "p" : "", name,
precision[insn.s], precision[insn.r],
insn.src1, insn.src2, insn.dest);
else
return (0);
break;
}
}
return (1);
}
/***********************************************************************
* Decode fld/fst-style offset encodings into actual offset, precision suffix,
* and autoincrement flag
*/
static void
fld_offset(offset, suffix, autoincrement)
long *offset; /* original and returned offset */
char *suffix; /* returned suffix character */
int *autoincrement; /* autoincrement flag (1 if ai) */
{
long off = *offset; /* working copy of *offset */
*autoincrement = ((off & 1) != 0);
if (off & 2)
{
*suffix = 'l';
*offset = (off & ~3);
}
else if (off & 4)
{
*suffix = 'q';
*offset = (off & ~7);
}
else
{
*suffix = 'd';
*offset = (off & ~7);
}
}
/***********************************************************************
* Print a general format instruction of the three register form:
* op rx,ry,rz
*/
static void
gen_rrr(name, insn, stream)
char *name;
union insn_fmt insn;
FILE *stream;
{
fprintf (stream, "%s %s,%s,%s", name, ireg[insn.gen.src1],
ireg[insn.gen.src2], ireg[insn.gen.dest]);
}
/***********************************************************************
* Print a general format instruction of the immed + two register form:
* op i,ry,rz
*/
static void
gen_irr(name, insn, immed, stream)
char *name;
union insn_fmt insn;
long immed;
FILE *stream;
{
fprintf (stream, "%s 0x%x,%s,%s", name, immed,
ireg[insn.gen.src2], ireg[insn.gen.dest]);
}
/***********************************************************************
* Print a ctrl format instruction with a 26-bit displacement:
* op addr
*/
static void
ctrl_a(name, insn, memaddr, stream)
char *name;
union insn_fmt insn;
CORE_ADDR memaddr;
FILE *stream;
{
long offset;
fprintf (stream, "%s ", name);
offset = SIGN_EXT(28, insn.ctrl.offset << 2);
print_address ((CORE_ADDR) (memaddr + 4 + offset), stream);
}
|