Pass the correct number of parameters to `symbol_file_add'.
[deliverable/binutils-gdb.git] / gdb / arm-pinsn.c
1 /* Print Acorn Risc Machine instructions for GDB, the GNU debugger.
2 Copyright 1986, 1989, 1991 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program 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 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #include "defs.h"
21 #include <ctype.h>
22 #include <assert.h>
23
24 #include "symtab.h"
25 #include "opcode/arm.h"
26
27 extern char *reg_names[];
28
29 static char *shift_names[] = {
30 "lsl", "lsr", "asr", "ror",
31 };
32
33 static char *cond_names[] = {
34 "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
35 "hi", "ls", "ge", "lt", "gt", "le", "", "nv"
36 };
37
38 static char float_precision[] = "sdep";
39 static char float_rounding[] = " pmz";
40 static float float_immed[] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 0.5, 10.0 };
41
42 static void print_ldr_str_offset();
43 static void print_ldc_stc_offset();
44 static long immediate_value();
45 \f
46 /* Print the ARM instruction at address MEMADDR in debugged memory,
47 on STREAM. Returns length of the instruction, in bytes. */
48
49 int
50 print_insn (memaddr, stream)
51 CORE_ADDR memaddr;
52 FILE *stream;
53 {
54 unsigned long ins;
55 register struct opcode *op;
56 register char *p;
57 register int i, c;
58 int s, e, val;
59
60 ins = read_memory_integer(memaddr, 4);
61 for (i = 0, op = opcodes; i < N_OPCODES; i++, op++)
62 if ((ins & op->mask) == op->value) break;
63 assert(i != N_OPCODES);
64
65 for (p = op->assembler; *p;) {
66 c = *p++;
67 if (c == '%') {
68 s = e = 0;
69 while (isdigit(*p))
70 s = s*10 + (*p++ - '0');
71 if (*p == '-') {
72 p++;
73 while (isdigit(*p))
74 e = e*10 + (*p++ - '0');
75 } else
76 e = s;
77 assert(s >= 0 && s <= 31 && e >= 0 && e <= 31);
78 val = (ins >> s) & ((1 << (e + 1 - s)) - 1);
79 switch (*p++) {
80 case '%' :
81 putc('%', stream);
82 break;
83 case 'd' :
84 fprintf(stream, "%d", val);
85 break;
86 case 'x' :
87 fprintf(stream, "%x", val);
88 break;
89 case 'r' :
90 assert(val >= 0 && val <= 15);
91 fprintf(stream, "%s", reg_names[val]);
92 break;
93 case 'c' :
94 fprintf(stream, "%s", cond_names[ins >> 28]);
95 break;
96 case '\'' :
97 assert(*p);
98 c = *p++;
99 if (val)
100 putc(c, stream);
101 break;
102 case '`' :
103 assert(*p);
104 c = *p++;
105 if (!val)
106 putc(c, stream);
107 break;
108 case '?' :
109 assert(*p);
110 c = *p++;
111 assert(*p);
112 if (val)
113 p++;
114 else
115 c = *p++;
116 putc(c, stream);
117 break;
118 case 'p' :
119 if (((ins >> 12) & 0xf) == 0xf)
120 putc('p', stream);
121 break;
122 case 'o' :
123 if (ins & (1<<25)) {
124 int immed = immediate_value(ins & 0xfff);
125 fprintf (stream, "#%d (0x%x)", immed, immed);
126 } else {
127 int operand2 = ins & 0xfff;
128 /* in operand2 :
129 bits 0-3 are the base register
130 bits 5-6 are the shift (0=lsl, 1=lsr, 2=asr, 3=ror)
131 if bit 4 is zero then bits 7-11 are an immediate shift count
132 else bit 7 must be zero and bits 8-11 are the register
133 to be used as a shift count.
134 Note: no shift at all is encoded as "reg lsl #0" */
135 fprintf (stream, "%s", reg_names[operand2 & 0xf]);
136 if (operand2 & 0xff0) {
137 /* ror #0 is really rrx (rotate right extend) */
138 if ((operand2 & 0xff0) == 0x060)
139 fprintf (stream, ", rrx");
140 else {
141 fprintf (stream, ", %s ",
142 shift_names[(operand2 >> 5) & 3]);
143 if (operand2 & (1<<4)) /* register shift */
144 fprintf (stream, "%s",
145 reg_names[operand2 >> 8]);
146 else /* immediate shift */
147 fprintf (stream, "#%d",
148 operand2 >> 7);
149 }
150 }
151 }
152 break;
153 case 'a' :
154 fprintf (stream, "[%s", reg_names[(ins >> 16) & 0xf]);
155 if (ins & (1<<24)) {
156 fprintf (stream, ", ");
157 print_ldr_str_offset (ins, stream);
158 putc (']', stream);
159 if (ins & (1<<21)) putc('!', stream);
160 /* If it is a pc relative load, then it is probably
161 a constant so print it */
162 if (((ins >> 16) & 0xf) == 15 &&
163 (ins & (1<<25)) == 0 &&
164 (ins & (1<<20))) {
165 int addr = memaddr + 8 +
166 (ins & 0xfff) * ((ins & (1<<23)) ? 1 : -1);
167 fprintf (stream, " (contents=");
168 print_address (read_memory_integer(addr, 4), stream);
169 fprintf (stream, ")");
170 }
171 } else {
172 fprintf (stream, "]," );
173 print_ldr_str_offset (ins, stream);
174 }
175 break;
176 case 'b' :
177 print_address (memaddr + 8 + (((int)ins << 8) >> 6), stream);
178 break;
179 case 'A' :
180 fprintf (stream, "[%s", reg_names[(ins >> 16) & 0xf]);
181 if (ins & (1<<24)) {
182 fprintf (stream, ", ");
183 print_ldc_stc_offset (ins, stream);
184 putc(']', stream);
185 if (ins & (1<<21))
186 putc('!', stream);
187 } else {
188 fprintf (stream, "], ");
189 print_ldc_stc_offset (ins, stream);
190 }
191 break;
192 case 'm' :
193 {
194 int regnum, first = 1;
195 putc('{', stream);
196 for (regnum = 0; regnum < 16; regnum++)
197 if (ins & (1<<regnum)) {
198 if (!first)
199 putc (',', stream);
200 first = 0;
201 fprintf (stream, "%s", reg_names[regnum]);
202 }
203 putc('}', stream);
204 }
205 break;
206 case 'P' :
207 val = ((ins >> 18) & 2) | ((ins >> 7) & 1);
208 putc(float_precision[val], stream);
209 break;
210 case 'Q' :
211 val = ((ins >> 21) & 2) | ((ins >> 15) & 1);
212 putc(float_precision[val], stream);
213 break;
214 case 'R' :
215 val = ((ins >> 5) & 3);
216 if (val) putc(float_rounding[val], stream);
217 break;
218 case 'f' :
219 assert(val >= 0 && val <= 15);
220 if (val > 7)
221 fprintf (stream, "#%3.1f", float_immed[val - 8]);
222 else
223 fprintf (stream, "f%d", val);
224 break;
225 default:
226 abort();
227 }
228 } else
229 putc(c, stream);
230 }
231 return 4;
232 }
233
234 static long
235 immediate_value(operand)
236 int operand;
237 {
238 int val = operand & 0xff;
239 int shift = 2*(operand >> 8);
240 /* immediate value is (val ror shift) */
241 return (val >> shift) | (val << (32 - shift));
242 }
243
244 static void
245 print_ldr_str_offset(ins, stream)
246 unsigned long ins;
247 FILE *stream;
248 {
249 if ((ins & (1<<25)) == 0)
250 fprintf (stream, "#%d",
251 (ins & 0xfff) * ((ins & (1<<23)) ? 1 : -1));
252 else {
253 fprintf (stream, "%s%s", reg_names[ins & 0xf],
254 (ins & (1<<23)) ? "" : "-");
255 if (ins & 0xff0)
256 fprintf (stream, ", %s #%d",
257 shift_names[(ins >> 5) & 3],
258 (ins >> 7) & 0x1f);
259 }
260 }
261
262 static void
263 print_ldc_stc_offset(ins, stream)
264 unsigned long ins;
265 FILE *stream;
266 {
267 fprintf (stream, "#%d",
268 4 * (ins & 0xff) * ((ins & (1<<23)) ? 1 : -1));
269 }
This page took 0.034545 seconds and 4 git commands to generate.