wire / wire-format / ebpf-instruction

eBPF instruction (8 bytes)

An eBPF program is a sequence of 8-byte instructions. Each instruction: 1-byte opcode (class + op), 1-byte dst/src registers (4 bits each), 2-byte offset (signed), 4-byte immediate. Classes: 0 LD, 1 LDX, 2 ST, 3 STX, 4 ALU, 5 JMP, 6 JMP32, 7 ALU64.

wire-format kind wire-format status standard verification verified tier B wire-format@1

aka: eBPF instruction (8 bytes)

wire format

spec: Linux kernel (eBPF)

An eBPF program is a sequence of 8-byte instructions. Each instruction: 1-byte opcode (class + op), 1-byte dst/src registers (4 bits each), 2-byte offset (signed), 4-byte immediate. Classes: 0 LD, 1 LDX, 2 ST, 3 STX, 4 ALU, 5 JMP, 6 JMP32, 7 ALU64.

fieldsizemeaning
opcode1 byteInstruction class (low 3 bits) + operation. LD/LDX/ST/STX/ALU/JMP/JMP32/ALU64.
dst_reg4 bits (high nibble of byte 1)Destination register (r0-r10; r10 is read-only frame pointer).
src_reg4 bits (low nibble of byte 1)Source register.
off2 bytes (signed)Offset for loads/stores/jumps.
imm4 bytes (signed)Immediate value; for 64-bit loads, a second instruction carries the high 32 bits.

example:

07 01 00 00 2a 00 00 00

r1 += 42 (ALU64 ADD immediate): opcode 0x07, dst r1, src 0, off 0, imm 42


provenance

agent: curl -H 'accept: application/json' wire.phall.io/wire-format/ebpf-instruction or /wire-format/ebpf-instruction.json