Commit 56cbd82e authored by Jiong Wang's avatar Jiong Wang Committed by Alexei Starovoitov

bpf: disassembler support JMP32

This patch teaches disassembler about JMP32. There are two places to
update:

  - Class 0x6 now used by BPF_JMP32, not "unused".

  - BPF_JMP32 need to show comparison operands properly.
    The disassemble format is to add an extra "(32)" before the operands if
    it is a sub-register. A better disassemble format for both JMP32 and
    ALU32 just show the register prefix as "w" instead of "r", this is the
    format using by LLVM assembler.
Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarJiong Wang <jiong.wang@netronome.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 092ed096
...@@ -67,7 +67,7 @@ const char *const bpf_class_string[8] = { ...@@ -67,7 +67,7 @@ const char *const bpf_class_string[8] = {
[BPF_STX] = "stx", [BPF_STX] = "stx",
[BPF_ALU] = "alu", [BPF_ALU] = "alu",
[BPF_JMP] = "jmp", [BPF_JMP] = "jmp",
[BPF_RET] = "BUG", [BPF_JMP32] = "jmp32",
[BPF_ALU64] = "alu64", [BPF_ALU64] = "alu64",
}; };
...@@ -136,23 +136,22 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs, ...@@ -136,23 +136,22 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs,
else else
print_bpf_end_insn(verbose, cbs->private_data, insn); print_bpf_end_insn(verbose, cbs->private_data, insn);
} else if (BPF_OP(insn->code) == BPF_NEG) { } else if (BPF_OP(insn->code) == BPF_NEG) {
verbose(cbs->private_data, "(%02x) r%d = %s-r%d\n", verbose(cbs->private_data, "(%02x) %c%d = -%c%d\n",
insn->code, insn->dst_reg, insn->code, class == BPF_ALU ? 'w' : 'r',
class == BPF_ALU ? "(u32) " : "", insn->dst_reg, class == BPF_ALU ? 'w' : 'r',
insn->dst_reg); insn->dst_reg);
} else if (BPF_SRC(insn->code) == BPF_X) { } else if (BPF_SRC(insn->code) == BPF_X) {
verbose(cbs->private_data, "(%02x) %sr%d %s %sr%d\n", verbose(cbs->private_data, "(%02x) %c%d %s %c%d\n",
insn->code, class == BPF_ALU ? "(u32) " : "", insn->code, class == BPF_ALU ? 'w' : 'r',
insn->dst_reg, insn->dst_reg,
bpf_alu_string[BPF_OP(insn->code) >> 4], bpf_alu_string[BPF_OP(insn->code) >> 4],
class == BPF_ALU ? "(u32) " : "", class == BPF_ALU ? 'w' : 'r',
insn->src_reg); insn->src_reg);
} else { } else {
verbose(cbs->private_data, "(%02x) %sr%d %s %s%d\n", verbose(cbs->private_data, "(%02x) %c%d %s %d\n",
insn->code, class == BPF_ALU ? "(u32) " : "", insn->code, class == BPF_ALU ? 'w' : 'r',
insn->dst_reg, insn->dst_reg,
bpf_alu_string[BPF_OP(insn->code) >> 4], bpf_alu_string[BPF_OP(insn->code) >> 4],
class == BPF_ALU ? "(u32) " : "",
insn->imm); insn->imm);
} }
} else if (class == BPF_STX) { } else if (class == BPF_STX) {
...@@ -220,7 +219,7 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs, ...@@ -220,7 +219,7 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs,
verbose(cbs->private_data, "BUG_ld_%02x\n", insn->code); verbose(cbs->private_data, "BUG_ld_%02x\n", insn->code);
return; return;
} }
} else if (class == BPF_JMP) { } else if (class == BPF_JMP32 || class == BPF_JMP) {
u8 opcode = BPF_OP(insn->code); u8 opcode = BPF_OP(insn->code);
if (opcode == BPF_CALL) { if (opcode == BPF_CALL) {
...@@ -244,13 +243,18 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs, ...@@ -244,13 +243,18 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs,
} else if (insn->code == (BPF_JMP | BPF_EXIT)) { } else if (insn->code == (BPF_JMP | BPF_EXIT)) {
verbose(cbs->private_data, "(%02x) exit\n", insn->code); verbose(cbs->private_data, "(%02x) exit\n", insn->code);
} else if (BPF_SRC(insn->code) == BPF_X) { } else if (BPF_SRC(insn->code) == BPF_X) {
verbose(cbs->private_data, "(%02x) if r%d %s r%d goto pc%+d\n", verbose(cbs->private_data,
insn->code, insn->dst_reg, "(%02x) if %c%d %s %c%d goto pc%+d\n",
insn->code, class == BPF_JMP32 ? 'w' : 'r',
insn->dst_reg,
bpf_jmp_string[BPF_OP(insn->code) >> 4], bpf_jmp_string[BPF_OP(insn->code) >> 4],
class == BPF_JMP32 ? 'w' : 'r',
insn->src_reg, insn->off); insn->src_reg, insn->off);
} else { } else {
verbose(cbs->private_data, "(%02x) if r%d %s 0x%x goto pc%+d\n", verbose(cbs->private_data,
insn->code, insn->dst_reg, "(%02x) if %c%d %s 0x%x goto pc%+d\n",
insn->code, class == BPF_JMP32 ? 'w' : 'r',
insn->dst_reg,
bpf_jmp_string[BPF_OP(insn->code) >> 4], bpf_jmp_string[BPF_OP(insn->code) >> 4],
insn->imm, insn->off); insn->imm, insn->off);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment