/src/binutils-gdb/opcodes/microblaze-dis.c
Line | Count | Source |
1 | | /* Disassemble Xilinx microblaze instructions. |
2 | | |
3 | | Copyright (C) 2009-2026 Free Software Foundation, Inc. |
4 | | |
5 | | This file is part of the GNU opcodes library. |
6 | | |
7 | | This library is free software; you can redistribute it and/or modify |
8 | | it under the terms of the GNU General Public License as published by |
9 | | the Free Software Foundation; either version 3, or (at your option) |
10 | | any later version. |
11 | | |
12 | | It is distributed in the hope that it will be useful, but WITHOUT |
13 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
14 | | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
15 | | License for more details. |
16 | | |
17 | | You should have received a copy of the GNU General Public License |
18 | | along with this file; see the file COPYING. If not, write to the |
19 | | Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, |
20 | | MA 02110-1301, USA. */ |
21 | | |
22 | | |
23 | | #include "sysdep.h" |
24 | | #define STATIC_TABLE |
25 | | #define DEFINE_TABLE |
26 | | |
27 | | #include "disassemble.h" |
28 | | #include <strings.h> |
29 | | #include "microblaze-opc.h" |
30 | | #include "microblaze-dis.h" |
31 | | |
32 | 41.1k | #define get_field_rd(buf, instr) get_field (buf, instr, RD_MASK, RD_LOW) |
33 | 36.5k | #define get_field_r1(buf, instr) get_field (buf, instr, RA_MASK, RA_LOW) |
34 | 6.82k | #define get_field_r2(buf, instr) get_field (buf, instr, RB_MASK, RB_LOW) |
35 | 6.25k | #define get_int_field_imm(instr) ((instr & IMM_MASK) >> IMM_LOW) |
36 | 26.4k | #define get_int_field_r1(instr) ((instr & RA_MASK) >> RA_LOW) |
37 | | |
38 | 124k | #define NUM_STRBUFS 4 |
39 | | #define STRBUF_SIZE 25 |
40 | | |
41 | | struct string_buf |
42 | | { |
43 | | unsigned int which; |
44 | | char str[NUM_STRBUFS][STRBUF_SIZE]; |
45 | | }; |
46 | | |
47 | | static inline char * |
48 | | strbuf (struct string_buf *buf) |
49 | 124k | { |
50 | 124k | #ifdef ENABLE_CHECKING |
51 | 124k | if (buf->which >= NUM_STRBUFS) |
52 | 0 | abort (); |
53 | 124k | #endif |
54 | 124k | return buf->str[buf->which++]; |
55 | 124k | } |
56 | | |
57 | | static char * |
58 | | get_field (struct string_buf *buf, long instr, long mask, unsigned short low) |
59 | 84.5k | { |
60 | 84.5k | char *p = strbuf (buf); |
61 | | |
62 | 84.5k | sprintf (p, "%s%d", register_prefix, (int)((instr & mask) >> low)); |
63 | 84.5k | return p; |
64 | 84.5k | } |
65 | | |
66 | | static char * |
67 | | get_field_imm (struct string_buf *buf, long instr) |
68 | 29.1k | { |
69 | 29.1k | char *p = strbuf (buf); |
70 | | |
71 | 29.1k | sprintf (p, "%d", (short)((instr & IMM_MASK) >> IMM_LOW)); |
72 | 29.1k | return p; |
73 | 29.1k | } |
74 | | |
75 | | static char * |
76 | | get_field_imm5 (struct string_buf *buf, long instr) |
77 | 361 | { |
78 | 361 | char *p = strbuf (buf); |
79 | | |
80 | 361 | sprintf (p, "%d", (short)((instr & IMM5_MASK) >> IMM_LOW)); |
81 | 361 | return p; |
82 | 361 | } |
83 | | |
84 | | static char * |
85 | | get_field_imm5_mbar (struct string_buf *buf, long instr) |
86 | 208 | { |
87 | 208 | char *p = strbuf (buf); |
88 | | |
89 | 208 | sprintf (p, "%d", (short)((instr & IMM5_MBAR_MASK) >> IMM_MBAR)); |
90 | 208 | return p; |
91 | 208 | } |
92 | | |
93 | | static char * |
94 | | get_field_immw (struct string_buf *buf, long instr) |
95 | 267 | { |
96 | 267 | char *p = strbuf (buf); |
97 | | |
98 | 267 | if (instr & 0x00004000) |
99 | 71 | sprintf (p, "%d", (short)(((instr & IMM5_WIDTH_MASK) |
100 | 71 | >> IMM_WIDTH_LOW))); /* bsefi */ |
101 | 196 | else |
102 | 196 | sprintf (p, "%d", (short)(((instr & IMM5_WIDTH_MASK) >> |
103 | 196 | IMM_WIDTH_LOW) - ((instr & IMM5_MASK) >> |
104 | 196 | IMM_LOW) + 1)); /* bsifi */ |
105 | 267 | return p; |
106 | 267 | } |
107 | | |
108 | | static char * |
109 | | get_field_rfsl (struct string_buf *buf, long instr) |
110 | 7.65k | { |
111 | 7.65k | char *p = strbuf (buf); |
112 | | |
113 | 7.65k | sprintf (p, "%s%d", fsl_register_prefix, |
114 | 7.65k | (short)((instr & RFSL_MASK) >> IMM_LOW)); |
115 | 7.65k | return p; |
116 | 7.65k | } |
117 | | |
118 | | static char * |
119 | | get_field_imm15 (struct string_buf *buf, long instr) |
120 | 37 | { |
121 | 37 | char *p = strbuf (buf); |
122 | | |
123 | 37 | sprintf (p, "%d", (short)((instr & IMM15_MASK) >> IMM_LOW)); |
124 | 37 | return p; |
125 | 37 | } |
126 | | |
127 | | static char * |
128 | | get_field_special (struct string_buf *buf, long instr, |
129 | | const struct op_code_struct *op) |
130 | 1.80k | { |
131 | 1.80k | char *p = strbuf (buf); |
132 | 1.80k | char *spr; |
133 | | |
134 | 1.80k | switch ((((instr & IMM_MASK) >> IMM_LOW) ^ op->immval_mask)) |
135 | 1.80k | { |
136 | 15 | case MICROBLAZE_REG_MSR_MASK: |
137 | 15 | spr = "msr"; |
138 | 15 | break; |
139 | 155 | case MICROBLAZE_REG_PC_MASK: |
140 | 155 | spr = "pc"; |
141 | 155 | break; |
142 | 41 | case MICROBLAZE_REG_EAR_MASK: |
143 | 41 | spr = "ear"; |
144 | 41 | break; |
145 | 198 | case MICROBLAZE_REG_ESR_MASK: |
146 | 198 | spr = "esr"; |
147 | 198 | break; |
148 | 13 | case MICROBLAZE_REG_FSR_MASK: |
149 | 13 | spr = "fsr"; |
150 | 13 | break; |
151 | 141 | case MICROBLAZE_REG_BTR_MASK: |
152 | 141 | spr = "btr"; |
153 | 141 | break; |
154 | 94 | case MICROBLAZE_REG_EDR_MASK: |
155 | 94 | spr = "edr"; |
156 | 94 | break; |
157 | 22 | case MICROBLAZE_REG_PID_MASK: |
158 | 22 | spr = "pid"; |
159 | 22 | break; |
160 | 47 | case MICROBLAZE_REG_ZPR_MASK: |
161 | 47 | spr = "zpr"; |
162 | 47 | break; |
163 | 84 | case MICROBLAZE_REG_TLBX_MASK: |
164 | 84 | spr = "tlbx"; |
165 | 84 | break; |
166 | 164 | case MICROBLAZE_REG_TLBLO_MASK: |
167 | 164 | spr = "tlblo"; |
168 | 164 | break; |
169 | 83 | case MICROBLAZE_REG_TLBHI_MASK: |
170 | 83 | spr = "tlbhi"; |
171 | 83 | break; |
172 | 14 | case MICROBLAZE_REG_TLBSX_MASK: |
173 | 14 | spr = "tlbsx"; |
174 | 14 | break; |
175 | 21 | case MICROBLAZE_REG_SHR_MASK: |
176 | 21 | spr = "shr"; |
177 | 21 | break; |
178 | 201 | case MICROBLAZE_REG_SLR_MASK: |
179 | 201 | spr = "slr"; |
180 | 201 | break; |
181 | 509 | default: |
182 | 509 | if (((((instr & IMM_MASK) >> IMM_LOW) ^ op->immval_mask) & 0xE000) |
183 | 509 | == MICROBLAZE_REG_PVR_MASK) |
184 | 321 | { |
185 | 321 | sprintf (p, "%spvr%d", register_prefix, |
186 | 321 | ((unsigned short)(((instr & IMM_MASK) >> IMM_LOW) |
187 | 321 | ^ op->immval_mask) |
188 | 321 | ^ MICROBLAZE_REG_PVR_MASK)); |
189 | 321 | return p; |
190 | 321 | } |
191 | 188 | else |
192 | 188 | spr = "pc"; |
193 | 188 | break; |
194 | 1.80k | } |
195 | | |
196 | 1.48k | sprintf (p, "%s%s", register_prefix, spr); |
197 | 1.48k | return p; |
198 | 1.80k | } |
199 | | |
200 | | static unsigned long |
201 | | read_insn_microblaze (bfd_vma memaddr, |
202 | | struct disassemble_info *info, |
203 | | const struct op_code_struct **opr) |
204 | 110k | { |
205 | 110k | unsigned char ibytes[4]; |
206 | 110k | int status; |
207 | 110k | const struct op_code_struct *op; |
208 | 110k | unsigned long inst; |
209 | | |
210 | 110k | status = info->read_memory_func (memaddr, ibytes, 4, info); |
211 | | |
212 | 110k | if (status != 0) |
213 | 93 | { |
214 | 93 | info->memory_error_func (status, memaddr, info); |
215 | 93 | return 0; |
216 | 93 | } |
217 | | |
218 | 110k | if (info->endian == BFD_ENDIAN_BIG) |
219 | 14.1k | inst = (((unsigned) ibytes[0] << 24) | (ibytes[1] << 16) |
220 | 14.1k | | (ibytes[2] << 8) | ibytes[3]); |
221 | 96.0k | else if (info->endian == BFD_ENDIAN_LITTLE) |
222 | 96.0k | inst = (((unsigned) ibytes[3] << 24) | (ibytes[2] << 16) |
223 | 96.0k | | (ibytes[1] << 8) | ibytes[0]); |
224 | 0 | else |
225 | 0 | abort (); |
226 | | |
227 | | /* Just a linear search of the table. */ |
228 | 22.4M | for (op = microblaze_opcodes; op->name != 0; op ++) |
229 | 22.3M | if (op->bit_sequence == (inst & op->opcode_mask)) |
230 | 50.6k | break; |
231 | | |
232 | 110k | *opr = op; |
233 | 110k | return inst; |
234 | 110k | } |
235 | | |
236 | | |
237 | | int |
238 | | print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info) |
239 | 103k | { |
240 | 103k | fprintf_ftype print_func = info->fprintf_func; |
241 | 103k | void *stream = info->stream; |
242 | 103k | unsigned long inst, prev_inst; |
243 | 103k | const struct op_code_struct *op, *pop; |
244 | 103k | int immval = 0; |
245 | 103k | bool immfound = false; |
246 | 103k | static bfd_vma prev_insn_addr = -1; /* Init the prev insn addr. */ |
247 | 103k | static int prev_insn_vma = -1; /* Init the prev insn vma. */ |
248 | 103k | int curr_insn_vma = info->buffer_vma; |
249 | 103k | struct string_buf buf; |
250 | | |
251 | 103k | buf.which = 0; |
252 | 103k | info->bytes_per_chunk = 4; |
253 | | |
254 | 103k | inst = read_insn_microblaze (memaddr, info, &op); |
255 | 103k | if (inst == 0) |
256 | 276 | return -1; |
257 | | |
258 | 103k | if (prev_insn_vma == curr_insn_vma) |
259 | 7.18k | { |
260 | 7.18k | if (memaddr-(info->bytes_per_chunk) == prev_insn_addr) |
261 | 6.85k | { |
262 | 6.85k | prev_inst = read_insn_microblaze (prev_insn_addr, info, &pop); |
263 | 6.85k | if (prev_inst == 0) |
264 | 0 | return -1; |
265 | 6.85k | if (pop->instr == imm) |
266 | 2 | { |
267 | 2 | immval = (get_int_field_imm (prev_inst) << 16) & 0xffff0000; |
268 | 2 | immfound = true; |
269 | 2 | } |
270 | 6.85k | else |
271 | 6.85k | { |
272 | 6.85k | immval = 0; |
273 | 6.85k | immfound = false; |
274 | 6.85k | } |
275 | 6.85k | } |
276 | 7.18k | } |
277 | | |
278 | | /* Make curr insn as prev insn. */ |
279 | 103k | prev_insn_addr = memaddr; |
280 | 103k | prev_insn_vma = curr_insn_vma; |
281 | | |
282 | 103k | if (op->name == NULL) |
283 | 55.4k | print_func (stream, ".long 0x%04x", (unsigned int) inst); |
284 | 47.8k | else |
285 | 47.8k | { |
286 | 47.8k | print_func (stream, "%s", op->name); |
287 | | |
288 | 47.8k | switch (op->inst_type) |
289 | 47.8k | { |
290 | 3.85k | case INST_TYPE_RD_R1_R2: |
291 | 3.85k | print_func (stream, "\t%s, %s, %s", get_field_rd (&buf, inst), |
292 | 3.85k | get_field_r1 (&buf, inst), get_field_r2 (&buf, inst)); |
293 | 3.85k | break; |
294 | 26.4k | case INST_TYPE_RD_R1_IMM: |
295 | 26.4k | print_func (stream, "\t%s, %s, %s", get_field_rd (&buf, inst), |
296 | 26.4k | get_field_r1 (&buf, inst), get_field_imm (&buf, inst)); |
297 | 26.4k | if (info->print_address_func && get_int_field_r1 (inst) == 0 |
298 | 4.07k | && info->symbol_at_address_func) |
299 | 4.07k | { |
300 | 4.07k | if (immfound) |
301 | 2 | immval |= (get_int_field_imm (inst) & 0x0000ffff); |
302 | 4.07k | else |
303 | 4.07k | { |
304 | 4.07k | immval = get_int_field_imm (inst); |
305 | 4.07k | if (immval & 0x8000) |
306 | 1.96k | immval |= (~0xFFFF); |
307 | 4.07k | } |
308 | 4.07k | if (immval > 0 && info->symbol_at_address_func (immval, info)) |
309 | 0 | { |
310 | 0 | print_func (stream, "\t// "); |
311 | 0 | info->print_address_func (immval, info); |
312 | 0 | } |
313 | 4.07k | } |
314 | 26.4k | break; |
315 | 94 | case INST_TYPE_RD_R1_IMM5: |
316 | 94 | print_func (stream, "\t%s, %s, %s", get_field_rd (&buf, inst), |
317 | 94 | get_field_r1 (&buf, inst), get_field_imm5 (&buf, inst)); |
318 | 94 | break; |
319 | 6.25k | case INST_TYPE_RD_RFSL: |
320 | 6.25k | print_func (stream, "\t%s, %s", get_field_rd (&buf, inst), |
321 | 6.25k | get_field_rfsl (&buf, inst)); |
322 | 6.25k | break; |
323 | 711 | case INST_TYPE_R1_RFSL: |
324 | 711 | print_func (stream, "\t%s, %s", get_field_r1 (&buf, inst), |
325 | 711 | get_field_rfsl (&buf, inst)); |
326 | 711 | break; |
327 | 1.80k | case INST_TYPE_RD_SPECIAL: |
328 | 1.80k | print_func (stream, "\t%s, %s", get_field_rd (&buf, inst), |
329 | 1.80k | get_field_special (&buf, inst, op)); |
330 | 1.80k | break; |
331 | 0 | case INST_TYPE_SPECIAL_R1: |
332 | 0 | print_func (stream, "\t%s, %s", get_field_special (&buf, inst, op), |
333 | 0 | get_field_r1 (&buf, inst)); |
334 | 0 | break; |
335 | 1.49k | case INST_TYPE_RD_R1: |
336 | 1.49k | print_func (stream, "\t%s, %s", get_field_rd (&buf, inst), |
337 | 1.49k | get_field_r1 (&buf, inst)); |
338 | 1.49k | break; |
339 | 1.64k | case INST_TYPE_R1_R2: |
340 | 1.64k | print_func (stream, "\t%s, %s", get_field_r1 (&buf, inst), |
341 | 1.64k | get_field_r2 (&buf, inst)); |
342 | 1.64k | break; |
343 | 1.72k | case INST_TYPE_R1_IMM: |
344 | 1.72k | print_func (stream, "\t%s, %s", get_field_r1 (&buf, inst), |
345 | 1.72k | get_field_imm (&buf, inst)); |
346 | | /* The non-pc relative instructions are returns, which shouldn't |
347 | | have a label printed. */ |
348 | 1.72k | if (info->print_address_func && op->inst_offset_type == INST_PC_OFFSET |
349 | 1.44k | && info->symbol_at_address_func) |
350 | 1.44k | { |
351 | 1.44k | if (immfound) |
352 | 0 | immval |= (get_int_field_imm (inst) & 0x0000ffff); |
353 | 1.44k | else |
354 | 1.44k | { |
355 | 1.44k | immval = get_int_field_imm (inst); |
356 | 1.44k | if (immval & 0x8000) |
357 | 1.11k | immval |= (~0xFFFF); |
358 | 1.44k | } |
359 | 1.44k | immval += memaddr; |
360 | 1.44k | if (immval > 0 && info->symbol_at_address_func (immval, info)) |
361 | 0 | { |
362 | 0 | print_func (stream, "\t// "); |
363 | 0 | info->print_address_func (immval, info); |
364 | 0 | } |
365 | 1.44k | else |
366 | 1.44k | { |
367 | 1.44k | print_func (stream, "\t\t// "); |
368 | 1.44k | print_func (stream, "%x", immval); |
369 | 1.44k | } |
370 | 1.44k | } |
371 | 1.72k | break; |
372 | 229 | case INST_TYPE_RD_IMM: |
373 | 229 | print_func (stream, "\t%s, %s", get_field_rd (&buf, inst), |
374 | 229 | get_field_imm (&buf, inst)); |
375 | 229 | if (info->print_address_func && info->symbol_at_address_func) |
376 | 229 | { |
377 | 229 | if (immfound) |
378 | 0 | immval |= (get_int_field_imm (inst) & 0x0000ffff); |
379 | 229 | else |
380 | 229 | { |
381 | 229 | immval = get_int_field_imm (inst); |
382 | 229 | if (immval & 0x8000) |
383 | 139 | immval |= (~0xFFFF); |
384 | 229 | } |
385 | 229 | if (op->inst_offset_type == INST_PC_OFFSET) |
386 | 149 | immval += (int) memaddr; |
387 | 229 | if (info->symbol_at_address_func (immval, info)) |
388 | 0 | { |
389 | 0 | print_func (stream, "\t// "); |
390 | 0 | info->print_address_func (immval, info); |
391 | 0 | } |
392 | 229 | } |
393 | 229 | break; |
394 | 671 | case INST_TYPE_IMM: |
395 | 671 | print_func (stream, "\t%s", get_field_imm (&buf, inst)); |
396 | 671 | if (info->print_address_func && info->symbol_at_address_func |
397 | 671 | && op->instr != imm) |
398 | 502 | { |
399 | 502 | if (immfound) |
400 | 0 | immval |= (get_int_field_imm (inst) & 0x0000ffff); |
401 | 502 | else |
402 | 502 | { |
403 | 502 | immval = get_int_field_imm (inst); |
404 | 502 | if (immval & 0x8000) |
405 | 120 | immval |= (~0xFFFF); |
406 | 502 | } |
407 | 502 | if (op->inst_offset_type == INST_PC_OFFSET) |
408 | 270 | immval += (int) memaddr; |
409 | 502 | if (immval > 0 && info->symbol_at_address_func (immval, info)) |
410 | 0 | { |
411 | 0 | print_func (stream, "\t// "); |
412 | 0 | info->print_address_func (immval, info); |
413 | 0 | } |
414 | 502 | else if (op->inst_offset_type == INST_PC_OFFSET) |
415 | 270 | { |
416 | 270 | print_func (stream, "\t\t// "); |
417 | 270 | print_func (stream, "%x", immval); |
418 | 270 | } |
419 | 502 | } |
420 | 671 | break; |
421 | 642 | case INST_TYPE_RD_R2: |
422 | 642 | print_func (stream, "\t%s, %s", get_field_rd (&buf, inst), |
423 | 642 | get_field_r2 (&buf, inst)); |
424 | 642 | break; |
425 | 366 | case INST_TYPE_R2: |
426 | 366 | print_func (stream, "\t%s", get_field_r2 (&buf, inst)); |
427 | 366 | break; |
428 | 0 | case INST_TYPE_R1: |
429 | 0 | print_func (stream, "\t%s", get_field_r1 (&buf, inst)); |
430 | 0 | break; |
431 | 322 | case INST_TYPE_R1_R2_SPECIAL: |
432 | 322 | print_func (stream, "\t%s, %s", get_field_r1 (&buf, inst), |
433 | 322 | get_field_r2 (&buf, inst)); |
434 | 322 | break; |
435 | 37 | case INST_TYPE_RD_IMM15: |
436 | 37 | print_func (stream, "\t%s, %s", get_field_rd (&buf, inst), |
437 | 37 | get_field_imm15 (&buf, inst)); |
438 | 37 | break; |
439 | | /* For mbar insn. */ |
440 | 208 | case INST_TYPE_IMM5: |
441 | 208 | print_func (stream, "\t%s", get_field_imm5_mbar (&buf, inst)); |
442 | 208 | break; |
443 | | /* For mbar 16 or sleep insn. */ |
444 | 322 | case INST_TYPE_NONE: |
445 | 322 | break; |
446 | | /* For bit field insns. */ |
447 | 267 | case INST_TYPE_RD_R1_IMMW_IMMS: |
448 | 267 | print_func (stream, "\t%s, %s, %s, %s", |
449 | 267 | get_field_rd (&buf, inst), |
450 | 267 | get_field_r1 (&buf, inst), |
451 | 267 | get_field_immw (&buf, inst), |
452 | 267 | get_field_imm5 (&buf, inst)); |
453 | 267 | break; |
454 | | /* For tuqula instruction */ |
455 | 0 | case INST_TYPE_RD: |
456 | 0 | print_func (stream, "\t%s", get_field_rd (&buf, inst)); |
457 | 0 | break; |
458 | 691 | case INST_TYPE_RFSL: |
459 | 691 | print_func (stream, "\t%s", get_field_rfsl (&buf, inst)); |
460 | 691 | break; |
461 | 0 | default: |
462 | | /* If the disassembler lags the instruction set. */ |
463 | 0 | print_func (stream, "\tundecoded operands, inst is 0x%04x", |
464 | 0 | (unsigned int) inst); |
465 | 0 | break; |
466 | 47.8k | } |
467 | 47.8k | } |
468 | | |
469 | | /* Say how many bytes we consumed. */ |
470 | 103k | return 4; |
471 | 103k | } |
472 | | |
473 | | enum microblaze_instr |
474 | | get_insn_microblaze (long inst, |
475 | | bool *isunsignedimm, |
476 | | enum microblaze_instr_type *insn_type, |
477 | | short *delay_slots) |
478 | 0 | { |
479 | 0 | const struct op_code_struct *op; |
480 | 0 | *isunsignedimm = false; |
481 | | |
482 | | /* Just a linear search of the table. */ |
483 | 0 | for (op = microblaze_opcodes; op->name != 0; op ++) |
484 | 0 | if (op->bit_sequence == (inst & op->opcode_mask)) |
485 | 0 | break; |
486 | |
|
487 | 0 | if (op->name == 0) |
488 | 0 | return invalid_inst; |
489 | 0 | else |
490 | 0 | { |
491 | 0 | *isunsignedimm = (op->inst_type == INST_TYPE_RD_R1_UNSIGNED_IMM); |
492 | 0 | *insn_type = op->instr_type; |
493 | 0 | *delay_slots = op->delay_slots; |
494 | 0 | return op->instr; |
495 | 0 | } |
496 | 0 | } |
497 | | |
498 | | enum microblaze_instr |
499 | | microblaze_decode_insn (long insn, int *rd, int *ra, int *rb, int *immed) |
500 | 0 | { |
501 | 0 | enum microblaze_instr op; |
502 | 0 | bool t1; |
503 | 0 | enum microblaze_instr_type t2; |
504 | 0 | short t3; |
505 | |
|
506 | 0 | op = get_insn_microblaze (insn, &t1, &t2, &t3); |
507 | 0 | *rd = (insn & RD_MASK) >> RD_LOW; |
508 | 0 | *ra = (insn & RA_MASK) >> RA_LOW; |
509 | 0 | *rb = (insn & RB_MASK) >> RB_LOW; |
510 | 0 | t3 = (insn & IMM_MASK) >> IMM_LOW; |
511 | 0 | *immed = (int) t3; |
512 | 0 | return (op); |
513 | 0 | } |
514 | | |
515 | | unsigned long |
516 | | microblaze_get_target_address (long inst, bool immfound, int immval, |
517 | | long pcval, long r1val, long r2val, |
518 | | bool *targetvalid, |
519 | | bool *unconditionalbranch) |
520 | 0 | { |
521 | 0 | const struct op_code_struct *op; |
522 | 0 | long targetaddr = 0; |
523 | |
|
524 | 0 | *unconditionalbranch = false; |
525 | | /* Just a linear search of the table. */ |
526 | 0 | for (op = microblaze_opcodes; op->name != 0; op ++) |
527 | 0 | if (op->bit_sequence == (inst & op->opcode_mask)) |
528 | 0 | break; |
529 | |
|
530 | 0 | if (op->name == 0) |
531 | 0 | { |
532 | 0 | *targetvalid = false; |
533 | 0 | } |
534 | 0 | else if (op->instr_type == branch_inst) |
535 | 0 | { |
536 | 0 | switch (op->inst_type) |
537 | 0 | { |
538 | 0 | case INST_TYPE_R2: |
539 | 0 | *unconditionalbranch = true; |
540 | | /* Fall through. */ |
541 | 0 | case INST_TYPE_RD_R2: |
542 | 0 | case INST_TYPE_R1_R2: |
543 | 0 | targetaddr = r2val; |
544 | 0 | *targetvalid = true; |
545 | 0 | if (op->inst_offset_type == INST_PC_OFFSET) |
546 | 0 | targetaddr += pcval; |
547 | 0 | break; |
548 | 0 | case INST_TYPE_IMM: |
549 | 0 | *unconditionalbranch = true; |
550 | | /* Fall through. */ |
551 | 0 | case INST_TYPE_RD_IMM: |
552 | 0 | case INST_TYPE_R1_IMM: |
553 | 0 | if (immfound) |
554 | 0 | { |
555 | 0 | targetaddr = (immval << 16) & (~0xffff); |
556 | 0 | targetaddr |= (get_int_field_imm (inst) & 0x0000ffff); |
557 | 0 | } |
558 | 0 | else |
559 | 0 | { |
560 | 0 | targetaddr = get_int_field_imm (inst); |
561 | 0 | if (targetaddr & 0x8000) |
562 | 0 | targetaddr |= (~0xFFFF); |
563 | 0 | } |
564 | 0 | if (op->inst_offset_type == INST_PC_OFFSET) |
565 | 0 | targetaddr += pcval; |
566 | 0 | *targetvalid = true; |
567 | 0 | break; |
568 | 0 | default: |
569 | 0 | *targetvalid = false; |
570 | 0 | break; |
571 | 0 | } |
572 | 0 | } |
573 | 0 | else if (op->instr_type == return_inst) |
574 | 0 | { |
575 | 0 | if (immfound) |
576 | 0 | { |
577 | 0 | targetaddr = (immval << 16) & (~0xffff); |
578 | 0 | targetaddr |= (get_int_field_imm (inst) & 0x0000ffff); |
579 | 0 | } |
580 | 0 | else |
581 | 0 | { |
582 | 0 | targetaddr = get_int_field_imm (inst); |
583 | 0 | if (targetaddr & 0x8000) |
584 | 0 | targetaddr |= (~0xFFFF); |
585 | 0 | } |
586 | 0 | targetaddr += r1val; |
587 | 0 | *targetvalid = true; |
588 | 0 | } |
589 | 0 | else |
590 | 0 | *targetvalid = false; |
591 | 0 | return targetaddr; |
592 | 0 | } |