In the instruction descriptions below the following field descriptors are used:
%d
%s
disp16
disp32
offset16
imm32
imm64
The destination register in these instructions act like an accumulator.
add %d, (%s|imm32)
sub %d, (%s|imm32)
mul %d, (%s|imm32)
div %d, (%s|imm32)
mod %d, (%s|imm32)
and %d, (%s|imm32)
or %d, (%s|imm32)
xor %d, (%s|imm32)
lsh %d, (%s|imm32)
%s
or imm32
bits.
rsh %d, (%s|imm32)
%s
or imm32
bits.
arsh %d, (%s|imm32)
%s
or imm32
bits.
neg %d
mov %d, (%s|imm32)
%s
in %d
, or load imm32
in %d
.
The destination register in these instructions act as an accumulator.
add32 %d, (%s|imm32)
sub32 %d, (%s|imm32)
mul32 %d, (%s|imm32)
div32 %d, (%s|imm32)
mod32 %d, (%s|imm32)
and32 %d, (%s|imm32)
or32 %d, (%s|imm32)
xor32 %d, (%s|imm32)
lsh32 %d, (%s|imm32)
%s
or imm32
bits.
rsh32 %d, (%s|imm32)
%s
or imm32
bits.
arsh32 %d, (%s|imm32)
%s
or imm32
bits.
neg32 %d
mov32 %d, (%s|imm32)
%s
in %d
, or load imm32
in %d
.
endle %d, (8|16|32)
%d
to
little-endian.
endbe %d, (8|16|32)
%d
to big-endian.
lddw %d, imm64
%d
.
lddw %d, %map_fd(N)
%d
.
The following instructions are intended to be used in socket filters, and are therefore not general-purpose: they make assumptions on the contents of several registers. See the file Documentation/networking/filter.txt in the Linux kernel source tree for more information.
Absolute loads:
ldabsdw imm32
ldabsw imm32
ldabsh imm32
ldabsb imm32
Indirect loads:
ldinddw %s, imm32
ldindw %s, imm32
ldindh %s, imm32
ldindb %s, imm32
General-purpose load and store instructions are provided for several word sizes.
Load to register instructions:
ldxdw %d, [%s+offset16]
ldxw %d, [%s+offset16]
ldxh %d, [%s+offset16]
ldxb %d, [%s+offset16]
Store from register instructions:
stxdw [%d+offset16], %s
stxw [%d+offset16], %s
stxh [%d+offset16], %s
stxb [%d+offset16], %s
Store from immediates instructions:
stddw [%d+offset16], imm32
stdw [%d+offset16], imm32
stdh [%d+offset16], imm32
stdb [%d+offset16], imm32
eBPF provides the following compare-and-jump instructions, which compare the values of the two given registers, or the values of a register and an immediate, and perform a branch in case the comparison holds true.
ja %d,(%s|imm32),disp16
jeq %d,(%s|imm32),disp16
jgt %d,(%s|imm32),disp16
jge %d,(%s|imm32),disp16
jlt %d,(%s|imm32),disp16
jle %d,(%s|imm32),disp16
jset %d,(%s|imm32),disp16
jne %d,(%s|imm32),disp16
jsgt %d,(%s|imm32),disp16
jsge %d,(%s|imm32),disp16
jslt %d,(%s|imm32),disp16
jsle %d,(%s|imm32),disp16
A call instruction is provided in order to perform calls to other eBPF functions, or to external kernel helpers:
call (disp32|imm32)
Finally:
exit
Atomic exchange-and-add instructions are provided in two flavors: one for swapping 64-bit quantities and another for 32-bit quantities.
xadddw [%d+offset16],%s
xaddw [%d+offset16],%s