Message ID | 20240412073346.458116-16-richard.henderson@linaro.org |
---|---|
State | Superseded |
Headers | show |
Series | misc: Replace sprintf | expand |
On 4/12/24 00:33, Richard Henderson wrote: > Signed-off-by: Richard Henderson <richard.henderson@linaro.org> > --- > disas/microblaze.c | 263 ++++++++++++++++++++++++--------------------- > 1 file changed, 141 insertions(+), 122 deletions(-) > > diff --git a/disas/microblaze.c b/disas/microblaze.c > index 3473c94164..c729c76585 100644 > --- a/disas/microblaze.c > +++ b/disas/microblaze.c > @@ -787,134 +787,153 @@ static void print_immval_addr(struct disassemble_info *info, bool immfound, > } > > 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; > - void * stream = info->stream; > - unsigned long inst, prev_inst; > - const struct op_code_struct *op, *pop; > - int immval = 0; > - bfd_boolean immfound = FALSE; > - static bfd_vma prev_insn_addr = -1; /*init the prev insn addr */ > - static int prev_insn_vma = -1; /*init the prev insn vma */ > - int curr_insn_vma = info->buffer_vma; > + fprintf_function fprintf_func = info->fprintf_func; > + void *stream = info->stream; > + unsigned long inst, prev_inst; > + const struct op_code_struct *op, *pop; > + int immval = 0; > + bool immfound = false; > + static bfd_vma prev_insn_addr = -1; /*init the prev insn addr */ > + static int prev_insn_vma = -1; /*init the prev insn 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); > - if (inst == 0) { > - return -1; > - } > + inst = read_insn_microblaze (memaddr, info, &op); > + if (inst == 0) { > + return -1; > + } > > - if (prev_insn_vma == curr_insn_vma) { > - if (memaddr-(info->bytes_per_chunk) == prev_insn_addr) { > - prev_inst = read_insn_microblaze (prev_insn_addr, info, &pop); > - if (prev_inst == 0) > - return -1; > - if (pop->instr == imm) { > - immval = (get_int_field_imm(prev_inst) << 16) & 0xffff0000; > - immfound = TRUE; > + if (prev_insn_vma == curr_insn_vma) { > + if (memaddr - info->bytes_per_chunk == prev_insn_addr) { > + prev_inst = read_insn_microblaze (prev_insn_addr, info, &pop); > + if (prev_inst == 0) > + return -1; > + if (pop->instr == imm) { > + immval = (get_int_field_imm(prev_inst) << 16) & 0xffff0000; > + immfound = TRUE; > + } > + else { > + immval = 0; > + immfound = FALSE; > + } > + } > } > - else { > - immval = 0; > - immfound = FALSE; > - } > - } > - } > - /* make curr insn as prev insn */ > - prev_insn_addr = memaddr; > - 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) { > - fprintf_func (stream, ".short 0x%04lx", inst); > - } > - else > - { > - fprintf_func (stream, "%s", op->name); > + if (op->name == 0) { > + fprintf_func (stream, ".short 0x%04lx", inst); > + return 4; > + } > + > + fprintf_func (stream, "%s", op->name); > > - switch (op->inst_type) > - { > - case INST_TYPE_RD_R1_R2: > - fprintf_func(stream, "\t%s, %s, %s", get_field_rd(inst), get_field_r1(inst), get_field_r2(inst)); > - break; > - case INST_TYPE_RD_R1_IMM: > - fprintf_func(stream, "\t%s, %s, %s", get_field_rd(inst), get_field_r1(inst), get_field_imm(inst)); > - if (get_int_field_r1(inst) == 0) { > - print_immval_addr(info, immfound, immval, inst, 0); > - } > - break; > - case INST_TYPE_RD_R1_IMM5: > - fprintf_func(stream, "\t%s, %s, %s", get_field_rd(inst), get_field_r1(inst), get_field_imm5(inst)); > - break; > - case INST_TYPE_RD_RFSL: > - fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_rfsl(inst)); > - break; > - case INST_TYPE_R1_RFSL: > - fprintf_func(stream, "\t%s, %s", get_field_r1(inst), get_field_rfsl(inst)); > - break; > - case INST_TYPE_RD_SPECIAL: > - fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_special(inst, op)); > - break; > - case INST_TYPE_SPECIAL_R1: > - fprintf_func(stream, "\t%s, %s", get_field_special(inst, op), get_field_r1(inst)); > - break; > - case INST_TYPE_RD_R1: > - fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_r1(inst)); > - break; > - case INST_TYPE_R1_R2: > - fprintf_func(stream, "\t%s, %s", get_field_r1(inst), get_field_r2(inst)); > - break; > - case INST_TYPE_R1_IMM: > - fprintf_func(stream, "\t%s, %s", get_field_r1(inst), get_field_imm(inst)); > - /* The non-pc relative instructions are returns, which shouldn't > - have a label printed */ > - if (op->inst_offset_type == INST_PC_OFFSET) { > - print_immval_addr(info, immfound, immval, inst, memaddr); > - } > - break; > - case INST_TYPE_RD_IMM: > - fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_imm(inst)); > - print_immval_addr(info, immfound, immval, inst, > - op->inst_offset_type == INST_PC_OFFSET > - ? memaddr : 0); > - break; > - case INST_TYPE_IMM: > - fprintf_func(stream, "\t%s", get_field_imm(inst)); > - if (op->instr != imm) { > - print_immval_addr(info, immfound, immval, inst, > - op->inst_offset_type == INST_PC_OFFSET > - ? memaddr : 0); > - } > - break; > - case INST_TYPE_RD_R2: > - fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_r2(inst)); > - break; > - case INST_TYPE_R2: > - fprintf_func(stream, "\t%s", get_field_r2(inst)); > - break; > - case INST_TYPE_R1: > - fprintf_func(stream, "\t%s", 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; > - } > + switch (op->inst_type) { > + case INST_TYPE_RD_R1_R2: > + fprintf_func(stream, "\t%s, %s, %s", > + get_field_rd(inst), get_field_r1(inst), > + get_field_r2(inst)); > + break; > + case INST_TYPE_RD_R1_IMM: > + fprintf_func(stream, "\t%s, %s, %s", > + get_field_rd(inst), get_field_r1(inst), > + get_field_imm(inst)); > + if (get_int_field_r1(inst) == 0) { > + print_immval_addr(info, immfound, immval, inst, 0); > + } > + break; > + case INST_TYPE_RD_R1_IMM5: > + fprintf_func(stream, "\t%s, %s, %s", > + get_field_rd(inst), get_field_r1(inst), > + get_field_imm5(inst)); > + break; > + case INST_TYPE_RD_RFSL: > + fprintf_func(stream, "\t%s, %s", > + get_field_rd(inst), get_field_rfsl(inst)); > + break; > + case INST_TYPE_R1_RFSL: > + fprintf_func(stream, "\t%s, %s", > + get_field_r1(inst), get_field_rfsl(inst)); > + break; > + case INST_TYPE_RD_SPECIAL: > + fprintf_func(stream, "\t%s, %s", > + get_field_rd(inst), get_field_special(inst, op)); > + break; > + case INST_TYPE_SPECIAL_R1: > + fprintf_func(stream, "\t%s, %s", > + get_field_special(inst, op), get_field_r1(inst)); > + break; > + case INST_TYPE_RD_R1: > + fprintf_func(stream, "\t%s, %s", > + get_field_rd(inst), get_field_r1(inst)); > + break; > + case INST_TYPE_R1_R2: > + fprintf_func(stream, "\t%s, %s", > + get_field_r1(inst), get_field_r2(inst)); > + break; > + case INST_TYPE_R1_IMM: > + fprintf_func(stream, "\t%s, %s", > + get_field_r1(inst), get_field_imm(inst)); > + /* > + * The non-pc relative instructions are returns, > + * which shouldn't have a label printed. > + */ > + if (op->inst_offset_type == INST_PC_OFFSET) { > + print_immval_addr(info, immfound, immval, inst, memaddr); > + } > + break; > + case INST_TYPE_RD_IMM: > + fprintf_func(stream, "\t%s, %s", > + get_field_rd(inst), get_field_imm(inst)); > + print_immval_addr(info, immfound, immval, inst, > + op->inst_offset_type == INST_PC_OFFSET > + ? memaddr : 0); > + break; > + case INST_TYPE_IMM: > + fprintf_func(stream, "\t%s", get_field_imm(inst)); > + if (op->instr != imm) { > + print_immval_addr(info, immfound, immval, inst, > + op->inst_offset_type == INST_PC_OFFSET > + ? memaddr : 0); > + } > + break; > + case INST_TYPE_RD_R2: > + fprintf_func(stream, "\t%s, %s", > + get_field_rd(inst), get_field_r2(inst)); > + break; > + case INST_TYPE_R2: > + fprintf_func(stream, "\t%s", > + get_field_r2(inst)); > + break; > + case INST_TYPE_R1: > + fprintf_func(stream, "\t%s", > + 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; > } > - > - /* Say how many bytes we consumed? */ > - return 4; > + return 4; > } Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
diff --git a/disas/microblaze.c b/disas/microblaze.c index 3473c94164..c729c76585 100644 --- a/disas/microblaze.c +++ b/disas/microblaze.c @@ -787,134 +787,153 @@ static void print_immval_addr(struct disassemble_info *info, bool immfound, } 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; - void * stream = info->stream; - unsigned long inst, prev_inst; - const struct op_code_struct *op, *pop; - int immval = 0; - bfd_boolean immfound = FALSE; - static bfd_vma prev_insn_addr = -1; /*init the prev insn addr */ - static int prev_insn_vma = -1; /*init the prev insn vma */ - int curr_insn_vma = info->buffer_vma; + fprintf_function fprintf_func = info->fprintf_func; + void *stream = info->stream; + unsigned long inst, prev_inst; + const struct op_code_struct *op, *pop; + int immval = 0; + bool immfound = false; + static bfd_vma prev_insn_addr = -1; /*init the prev insn addr */ + static int prev_insn_vma = -1; /*init the prev insn 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); - if (inst == 0) { - return -1; - } + inst = read_insn_microblaze (memaddr, info, &op); + if (inst == 0) { + return -1; + } - if (prev_insn_vma == curr_insn_vma) { - if (memaddr-(info->bytes_per_chunk) == prev_insn_addr) { - prev_inst = read_insn_microblaze (prev_insn_addr, info, &pop); - if (prev_inst == 0) - return -1; - if (pop->instr == imm) { - immval = (get_int_field_imm(prev_inst) << 16) & 0xffff0000; - immfound = TRUE; + if (prev_insn_vma == curr_insn_vma) { + if (memaddr - info->bytes_per_chunk == prev_insn_addr) { + prev_inst = read_insn_microblaze (prev_insn_addr, info, &pop); + if (prev_inst == 0) + return -1; + if (pop->instr == imm) { + immval = (get_int_field_imm(prev_inst) << 16) & 0xffff0000; + immfound = TRUE; + } + else { + immval = 0; + immfound = FALSE; + } + } } - else { - immval = 0; - immfound = FALSE; - } - } - } - /* make curr insn as prev insn */ - prev_insn_addr = memaddr; - 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) { - fprintf_func (stream, ".short 0x%04lx", inst); - } - else - { - fprintf_func (stream, "%s", op->name); + if (op->name == 0) { + fprintf_func (stream, ".short 0x%04lx", inst); + return 4; + } + + fprintf_func (stream, "%s", op->name); - switch (op->inst_type) - { - case INST_TYPE_RD_R1_R2: - fprintf_func(stream, "\t%s, %s, %s", get_field_rd(inst), get_field_r1(inst), get_field_r2(inst)); - break; - case INST_TYPE_RD_R1_IMM: - fprintf_func(stream, "\t%s, %s, %s", get_field_rd(inst), get_field_r1(inst), get_field_imm(inst)); - if (get_int_field_r1(inst) == 0) { - print_immval_addr(info, immfound, immval, inst, 0); - } - break; - case INST_TYPE_RD_R1_IMM5: - fprintf_func(stream, "\t%s, %s, %s", get_field_rd(inst), get_field_r1(inst), get_field_imm5(inst)); - break; - case INST_TYPE_RD_RFSL: - fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_rfsl(inst)); - break; - case INST_TYPE_R1_RFSL: - fprintf_func(stream, "\t%s, %s", get_field_r1(inst), get_field_rfsl(inst)); - break; - case INST_TYPE_RD_SPECIAL: - fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_special(inst, op)); - break; - case INST_TYPE_SPECIAL_R1: - fprintf_func(stream, "\t%s, %s", get_field_special(inst, op), get_field_r1(inst)); - break; - case INST_TYPE_RD_R1: - fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_r1(inst)); - break; - case INST_TYPE_R1_R2: - fprintf_func(stream, "\t%s, %s", get_field_r1(inst), get_field_r2(inst)); - break; - case INST_TYPE_R1_IMM: - fprintf_func(stream, "\t%s, %s", get_field_r1(inst), get_field_imm(inst)); - /* The non-pc relative instructions are returns, which shouldn't - have a label printed */ - if (op->inst_offset_type == INST_PC_OFFSET) { - print_immval_addr(info, immfound, immval, inst, memaddr); - } - break; - case INST_TYPE_RD_IMM: - fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_imm(inst)); - print_immval_addr(info, immfound, immval, inst, - op->inst_offset_type == INST_PC_OFFSET - ? memaddr : 0); - break; - case INST_TYPE_IMM: - fprintf_func(stream, "\t%s", get_field_imm(inst)); - if (op->instr != imm) { - print_immval_addr(info, immfound, immval, inst, - op->inst_offset_type == INST_PC_OFFSET - ? memaddr : 0); - } - break; - case INST_TYPE_RD_R2: - fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_r2(inst)); - break; - case INST_TYPE_R2: - fprintf_func(stream, "\t%s", get_field_r2(inst)); - break; - case INST_TYPE_R1: - fprintf_func(stream, "\t%s", 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; - } + switch (op->inst_type) { + case INST_TYPE_RD_R1_R2: + fprintf_func(stream, "\t%s, %s, %s", + get_field_rd(inst), get_field_r1(inst), + get_field_r2(inst)); + break; + case INST_TYPE_RD_R1_IMM: + fprintf_func(stream, "\t%s, %s, %s", + get_field_rd(inst), get_field_r1(inst), + get_field_imm(inst)); + if (get_int_field_r1(inst) == 0) { + print_immval_addr(info, immfound, immval, inst, 0); + } + break; + case INST_TYPE_RD_R1_IMM5: + fprintf_func(stream, "\t%s, %s, %s", + get_field_rd(inst), get_field_r1(inst), + get_field_imm5(inst)); + break; + case INST_TYPE_RD_RFSL: + fprintf_func(stream, "\t%s, %s", + get_field_rd(inst), get_field_rfsl(inst)); + break; + case INST_TYPE_R1_RFSL: + fprintf_func(stream, "\t%s, %s", + get_field_r1(inst), get_field_rfsl(inst)); + break; + case INST_TYPE_RD_SPECIAL: + fprintf_func(stream, "\t%s, %s", + get_field_rd(inst), get_field_special(inst, op)); + break; + case INST_TYPE_SPECIAL_R1: + fprintf_func(stream, "\t%s, %s", + get_field_special(inst, op), get_field_r1(inst)); + break; + case INST_TYPE_RD_R1: + fprintf_func(stream, "\t%s, %s", + get_field_rd(inst), get_field_r1(inst)); + break; + case INST_TYPE_R1_R2: + fprintf_func(stream, "\t%s, %s", + get_field_r1(inst), get_field_r2(inst)); + break; + case INST_TYPE_R1_IMM: + fprintf_func(stream, "\t%s, %s", + get_field_r1(inst), get_field_imm(inst)); + /* + * The non-pc relative instructions are returns, + * which shouldn't have a label printed. + */ + if (op->inst_offset_type == INST_PC_OFFSET) { + print_immval_addr(info, immfound, immval, inst, memaddr); + } + break; + case INST_TYPE_RD_IMM: + fprintf_func(stream, "\t%s, %s", + get_field_rd(inst), get_field_imm(inst)); + print_immval_addr(info, immfound, immval, inst, + op->inst_offset_type == INST_PC_OFFSET + ? memaddr : 0); + break; + case INST_TYPE_IMM: + fprintf_func(stream, "\t%s", get_field_imm(inst)); + if (op->instr != imm) { + print_immval_addr(info, immfound, immval, inst, + op->inst_offset_type == INST_PC_OFFSET + ? memaddr : 0); + } + break; + case INST_TYPE_RD_R2: + fprintf_func(stream, "\t%s, %s", + get_field_rd(inst), get_field_r2(inst)); + break; + case INST_TYPE_R2: + fprintf_func(stream, "\t%s", + get_field_r2(inst)); + break; + case INST_TYPE_R1: + fprintf_func(stream, "\t%s", + 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; } - - /* Say how many bytes we consumed? */ - return 4; + return 4; }
Signed-off-by: Richard Henderson <richard.henderson@linaro.org> --- disas/microblaze.c | 263 ++++++++++++++++++++++++--------------------- 1 file changed, 141 insertions(+), 122 deletions(-)