disas/microblaze: Re-indent print_insn_microblaze

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Message-Id: <20240412073346.458116-16-richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson 2024-04-12 00:33:34 -07:00
parent 58e5632c70
commit c3c6fed646
1 changed files with 141 additions and 122 deletions

View File

@ -787,134 +787,153 @@ static void print_immval_addr(struct disassemble_info *info, bool immfound,
} }
int int
print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info) print_insn_microblaze(bfd_vma memaddr, struct disassemble_info *info)
{ {
fprintf_function fprintf_func = info->fprintf_func; fprintf_function fprintf_func = info->fprintf_func;
void * stream = info->stream; void *stream = info->stream;
unsigned long inst, prev_inst; unsigned long inst, prev_inst;
const struct op_code_struct *op, *pop; const struct op_code_struct *op, *pop;
int immval = 0; int immval = 0;
bfd_boolean immfound = FALSE; bool immfound = false;
static bfd_vma prev_insn_addr = -1; /*init the prev insn addr */ static bfd_vma prev_insn_addr = -1; /*init the prev insn addr */
static int prev_insn_vma = -1; /*init the prev insn vma */ static int prev_insn_vma = -1; /*init the prev insn vma */
int curr_insn_vma = info->buffer_vma; int curr_insn_vma = info->buffer_vma;
info->bytes_per_chunk = 4; info->bytes_per_chunk = 4;
inst = read_insn_microblaze (memaddr, info, &op); inst = read_insn_microblaze (memaddr, info, &op);
if (inst == 0) { if (inst == 0) {
return -1; return -1;
} }
if (prev_insn_vma == curr_insn_vma) { if (prev_insn_vma == curr_insn_vma) {
if (memaddr-(info->bytes_per_chunk) == prev_insn_addr) { if (memaddr - info->bytes_per_chunk == prev_insn_addr) {
prev_inst = read_insn_microblaze (prev_insn_addr, info, &pop); prev_inst = read_insn_microblaze (prev_insn_addr, info, &pop);
if (prev_inst == 0) if (prev_inst == 0)
return -1; return -1;
if (pop->instr == imm) { if (pop->instr == imm) {
immval = (get_int_field_imm(prev_inst) << 16) & 0xffff0000; immval = (get_int_field_imm(prev_inst) << 16) & 0xffff0000;
immfound = TRUE; immfound = TRUE;
}
else {
immval = 0;
immfound = FALSE;
}
}
} }
else { /* make curr insn as prev insn */
immval = 0; prev_insn_addr = memaddr;
immfound = FALSE; prev_insn_vma = curr_insn_vma;
}
}
}
/* make curr insn as prev insn */
prev_insn_addr = memaddr;
prev_insn_vma = curr_insn_vma;
if (op->name == 0) { if (op->name == 0) {
fprintf_func (stream, ".short 0x%04lx", inst); fprintf_func (stream, ".short 0x%04lx", inst);
} return 4;
else }
{
fprintf_func (stream, "%s", op->name); fprintf_func (stream, "%s", op->name);
switch (op->inst_type) switch (op->inst_type) {
{ case INST_TYPE_RD_R1_R2:
case INST_TYPE_RD_R1_R2: fprintf_func(stream, "\t%s, %s, %s",
fprintf_func(stream, "\t%s, %s, %s", get_field_rd(inst), get_field_r1(inst), get_field_r2(inst)); get_field_rd(inst), get_field_r1(inst),
break; get_field_r2(inst));
case INST_TYPE_RD_R1_IMM: break;
fprintf_func(stream, "\t%s, %s, %s", get_field_rd(inst), get_field_r1(inst), get_field_imm(inst)); case INST_TYPE_RD_R1_IMM:
if (get_int_field_r1(inst) == 0) { fprintf_func(stream, "\t%s, %s, %s",
print_immval_addr(info, immfound, immval, inst, 0); get_field_rd(inst), get_field_r1(inst),
} get_field_imm(inst));
break; if (get_int_field_r1(inst) == 0) {
case INST_TYPE_RD_R1_IMM5: print_immval_addr(info, immfound, immval, inst, 0);
fprintf_func(stream, "\t%s, %s, %s", get_field_rd(inst), get_field_r1(inst), get_field_imm5(inst)); }
break; break;
case INST_TYPE_RD_RFSL: case INST_TYPE_RD_R1_IMM5:
fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_rfsl(inst)); fprintf_func(stream, "\t%s, %s, %s",
break; get_field_rd(inst), get_field_r1(inst),
case INST_TYPE_R1_RFSL: get_field_imm5(inst));
fprintf_func(stream, "\t%s, %s", get_field_r1(inst), get_field_rfsl(inst)); break;
break; case INST_TYPE_RD_RFSL:
case INST_TYPE_RD_SPECIAL: fprintf_func(stream, "\t%s, %s",
fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_special(inst, op)); get_field_rd(inst), get_field_rfsl(inst));
break; break;
case INST_TYPE_SPECIAL_R1: case INST_TYPE_R1_RFSL:
fprintf_func(stream, "\t%s, %s", get_field_special(inst, op), get_field_r1(inst)); fprintf_func(stream, "\t%s, %s",
break; get_field_r1(inst), get_field_rfsl(inst));
case INST_TYPE_RD_R1: break;
fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_r1(inst)); case INST_TYPE_RD_SPECIAL:
break; fprintf_func(stream, "\t%s, %s",
case INST_TYPE_R1_R2: get_field_rd(inst), get_field_special(inst, op));
fprintf_func(stream, "\t%s, %s", get_field_r1(inst), get_field_r2(inst)); break;
break; case INST_TYPE_SPECIAL_R1:
case INST_TYPE_R1_IMM: fprintf_func(stream, "\t%s, %s",
fprintf_func(stream, "\t%s, %s", get_field_r1(inst), get_field_imm(inst)); get_field_special(inst, op), get_field_r1(inst));
/* The non-pc relative instructions are returns, which shouldn't break;
have a label printed */ case INST_TYPE_RD_R1:
if (op->inst_offset_type == INST_PC_OFFSET) { fprintf_func(stream, "\t%s, %s",
print_immval_addr(info, immfound, immval, inst, memaddr); get_field_rd(inst), get_field_r1(inst));
} break;
break; case INST_TYPE_R1_R2:
case INST_TYPE_RD_IMM: fprintf_func(stream, "\t%s, %s",
fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_imm(inst)); get_field_r1(inst), get_field_r2(inst));
print_immval_addr(info, immfound, immval, inst, break;
op->inst_offset_type == INST_PC_OFFSET case INST_TYPE_R1_IMM:
? memaddr : 0); fprintf_func(stream, "\t%s, %s",
break; get_field_r1(inst), get_field_imm(inst));
case INST_TYPE_IMM: /*
fprintf_func(stream, "\t%s", get_field_imm(inst)); * The non-pc relative instructions are returns,
if (op->instr != imm) { * which shouldn't have a label printed.
print_immval_addr(info, immfound, immval, inst, */
op->inst_offset_type == INST_PC_OFFSET if (op->inst_offset_type == INST_PC_OFFSET) {
? memaddr : 0); print_immval_addr(info, immfound, immval, inst, memaddr);
} }
break; break;
case INST_TYPE_RD_R2: case INST_TYPE_RD_IMM:
fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_r2(inst)); fprintf_func(stream, "\t%s, %s",
break; get_field_rd(inst), get_field_imm(inst));
case INST_TYPE_R2: print_immval_addr(info, immfound, immval, inst,
fprintf_func(stream, "\t%s", get_field_r2(inst)); op->inst_offset_type == INST_PC_OFFSET
break; ? memaddr : 0);
case INST_TYPE_R1: break;
fprintf_func(stream, "\t%s", get_field_r1(inst)); case INST_TYPE_IMM:
break; fprintf_func(stream, "\t%s", get_field_imm(inst));
case INST_TYPE_RD_R1_SPECIAL: if (op->instr != imm) {
fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_r2(inst)); print_immval_addr(info, immfound, immval, inst,
break; op->inst_offset_type == INST_PC_OFFSET
case INST_TYPE_RD_IMM15: ? memaddr : 0);
fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_imm15(inst)); }
break; break;
/* For tuqula instruction */ case INST_TYPE_RD_R2:
case INST_TYPE_RD: fprintf_func(stream, "\t%s, %s",
fprintf_func(stream, "\t%s", get_field_rd(inst)); get_field_rd(inst), get_field_r2(inst));
break; break;
case INST_TYPE_RFSL: case INST_TYPE_R2:
fprintf_func(stream, "\t%s", get_field_rfsl(inst)); fprintf_func(stream, "\t%s",
break; get_field_r2(inst));
default: break;
/* if the disassembler lags the instruction set */ case INST_TYPE_R1:
fprintf_func (stream, "\tundecoded operands, inst is 0x%04lx", inst); fprintf_func(stream, "\t%s",
break; get_field_r1(inst));
} break;
case INST_TYPE_RD_R1_SPECIAL:
fprintf_func(stream, "\t%s, %s",
get_field_rd(inst), get_field_r2(inst));
break;
case INST_TYPE_RD_IMM15:
fprintf_func(stream, "\t%s, %s",
get_field_rd(inst), get_field_imm15(inst));
break;
/* For tuqula instruction */
case INST_TYPE_RD:
fprintf_func(stream, "\t%s",
get_field_rd(inst));
break;
case INST_TYPE_RFSL:
fprintf_func(stream, "\t%s",
get_field_rfsl(inst));
break;
default:
/* if the disassembler lags the instruction set */
fprintf_func(stream, "\tundecoded operands, inst is 0x%04lx", inst);
break;
} }
return 4;
/* Say how many bytes we consumed? */
return 4;
} }