wire / wire-format / ebpf-instruction
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.
aka: eBPF instruction (8 bytes)
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.
| field | size | meaning |
|---|---|---|
| opcode | 1 byte | Instruction class (low 3 bits) + operation. LD/LDX/ST/STX/ALU/JMP/JMP32/ALU64. |
| dst_reg | 4 bits (high nibble of byte 1) | Destination register (r0-r10; r10 is read-only frame pointer). |
| src_reg | 4 bits (low nibble of byte 1) | Source register. |
| off | 2 bytes (signed) | Offset for loads/stores/jumps. |
| imm | 4 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
agent: curl -H 'accept: application/json' wire.phall.io/wire-format/ebpf-instruction
or /wire-format/ebpf-instruction.json