Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion asm/instruction.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,9 @@ func (ins Instruction) Format(f fmt.State, c rune) {
}

case cls.IsJump():
fmt.Fprintf(f, "%v ", op)
switch jop := op.JumpOp(); jop {
case Call:
fmt.Fprintf(f, "%v ", op)
switch ins.Src {
case PseudoCall:
// bpf-to-bpf call
Expand All @@ -411,13 +411,23 @@ func (ins Instruction) Format(f fmt.State, c rune) {
}

case Ja:
fmt.Fprintf(f, "%v ", op)
if ins.OpCode.Class() == Jump32Class {
fmt.Fprintf(f, "imm: %d", ins.Constant)
} else {
fmt.Fprintf(f, "off: %d", ins.Offset)
}

case JCOND:
switch ins.Src {
case PseudoMayGoto:
fmt.Fprintf(f, "JCond may_goto off: %d", ins.Offset)
default:
fmt.Fprintf(f, "%v", op)
}

default:
fmt.Fprintf(f, "%v ", op)
fmt.Fprintf(f, "dst: %s off: %d ", ins.Dst, ins.Offset)
if op.Source() == ImmSource {
fmt.Fprintf(f, "imm: %d", ins.Constant)
Expand Down
3 changes: 3 additions & 0 deletions asm/instruction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ func TestISAv4(t *testing.T) {
0xcb, 0x21, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, // store_release((u16 *)(r1 + 0x0), w2)
0xc3, 0x21, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, // store_release((u32 *)(r1 + 0x0), w2)
0xdb, 0x21, 0x00, 0x00, 0x10, 0x01, 0x00, 0x00, // store_release((u64 *)(r1 + 0x0), r2)

0xe5, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, // may_goto +30
}

insns, err := AppendInstructions(nil, bytes.NewReader(rawInsns), binary.LittleEndian, platform.Linux)
Expand Down Expand Up @@ -427,6 +429,7 @@ func TestISAv4(t *testing.T) {
"StXAtomicStRelH dst: r1 src: r2 off: 0",
"StXAtomicStRelW dst: r1 src: r2 off: 0",
"StXAtomicStRelDW dst: r1 src: r2 off: 0",
"JCond may_goto off: 30",
}

for i, ins := range insns {
Expand Down
2 changes: 2 additions & 0 deletions asm/jump.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const (
JSLT JumpOp = 0xc0
// JSLE jumps by offset if signed r <= signed imm
JSLE JumpOp = 0xd0
// JCOND is a conditional pseudo jump to encode the may_goto instruction
JCOND JumpOp = 0xe0
)

// Return emits an exit instruction.
Expand Down
6 changes: 4 additions & 2 deletions asm/jump_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions asm/opcode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func TestGetSetJumpOp(t *testing.T) {
JLE,
JSLT,
JSLE,
JCOND,
} {
test(Jump32Class, op, true)
test(JumpClass, op, true)
Expand Down
1 change: 1 addition & 0 deletions asm/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (
PseudoCall = R1 // BPF_PSEUDO_CALL
PseudoFunc = R4 // BPF_PSEUDO_FUNC
PseudoKfuncCall = R2 // BPF_PSEUDO_KFUNC_CALL
PseudoMayGoto = R0 // BPF_MAY_GOTO
)

func (r Register) String() string {
Expand Down
Loading