2023-01-01 14:08:42 +08:00
|
|
|
@c Copyright (C) 2019-2023 Free Software Foundation, Inc.
|
2019-05-24 01:05:12 +08:00
|
|
|
@c This is part of the GAS manual.
|
|
|
|
@c For copying conditions, see the file as.texinfo.
|
|
|
|
|
|
|
|
@ifset GENERIC
|
|
|
|
@page
|
|
|
|
@node BPF-Dependent
|
|
|
|
@chapter BPF Dependent Features
|
|
|
|
@end ifset
|
|
|
|
|
|
|
|
@ifclear GENERIC
|
|
|
|
@node Machine Dependencies
|
|
|
|
@chapter BPF Dependent Features
|
|
|
|
@end ifclear
|
|
|
|
|
|
|
|
@cindex BPF support
|
|
|
|
@menu
|
2023-08-02 19:06:23 +08:00
|
|
|
* BPF Options:: BPF specific command-line options.
|
|
|
|
* BPF Special Characters:: Comments and statements.
|
|
|
|
* BPF Registers:: Register names.
|
|
|
|
* BPF Directives:: Machine directives.
|
|
|
|
* BPF Instructions:: Machine instructions.
|
2019-05-24 01:05:12 +08:00
|
|
|
@end menu
|
|
|
|
|
|
|
|
@node BPF Options
|
2023-08-02 19:06:23 +08:00
|
|
|
@section BPF Options
|
2019-05-24 01:05:12 +08:00
|
|
|
@cindex BPF options (none)
|
|
|
|
@cindex options for BPF (none)
|
|
|
|
|
|
|
|
@c man begin OPTIONS
|
|
|
|
@table @gcctabopt
|
|
|
|
|
|
|
|
@cindex @option{-EB} command-line option, BPF
|
|
|
|
@item -EB
|
|
|
|
This option specifies that the assembler should emit big-endian eBPF.
|
|
|
|
|
|
|
|
@cindex @option{-EL} command-line option, BPF
|
|
|
|
@item -EL
|
|
|
|
This option specifies that the assembler should emit little-endian
|
|
|
|
eBPF.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@cindex @option{-mdialect} command-line options, BPF
|
|
|
|
@item -mdialect=@var{dialect}
|
|
|
|
This option specifies the assembly language dialect to recognize while
|
|
|
|
assembling. The assembler supports @option{normal} and
|
|
|
|
@option{pseudoc}.
|
|
|
|
|
|
|
|
@cindex @option{-misa-spec} command-line options, BPF
|
|
|
|
@item -misa-spec=@var{spec}
|
|
|
|
This option specifies the version of the BPF instruction set to use
|
|
|
|
when assembling. The BPF ISA versions supported are @option{v1} @option{v2}, @option{v3} and @option{v4}.
|
|
|
|
|
|
|
|
The value @option{xbpf} can be specified to recognize extra
|
|
|
|
instructions that are used by GCC for testing purposes. But beware
|
|
|
|
this is not valid BPF.
|
|
|
|
|
|
|
|
@cindex @option{-mno-relax} command-line options, BPF
|
|
|
|
@item -mno-relax
|
|
|
|
This option tells the assembler to not relax instructions.
|
2019-05-24 01:05:12 +08:00
|
|
|
@end table
|
|
|
|
|
|
|
|
Note that if no endianness option is specified in the command line,
|
|
|
|
the host endianness is used.
|
|
|
|
@c man end
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@node BPF Special Characters
|
|
|
|
@section BPF Special Characters
|
2019-05-24 01:05:12 +08:00
|
|
|
|
|
|
|
@cindex line comment character, BPF
|
|
|
|
@cindex BPF line comment character
|
2023-08-02 19:06:23 +08:00
|
|
|
The presence of a @samp{;} or a @samp{#} on a line indicates the start
|
|
|
|
of a comment that extends to the end of the current line.
|
2019-05-24 01:05:12 +08:00
|
|
|
|
|
|
|
@cindex statement separator, BPF
|
|
|
|
Statements and assembly directives are separated by newlines.
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@node BPF Registers
|
|
|
|
@section BPF Registers
|
2019-05-24 01:05:12 +08:00
|
|
|
|
|
|
|
@cindex BPF register names
|
|
|
|
@cindex register names, BPF
|
|
|
|
The eBPF processor provides ten general-purpose 64-bit registers,
|
|
|
|
which are read-write, and a read-only frame pointer register:
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@noindent
|
|
|
|
In normal syntax:
|
|
|
|
|
2019-05-24 01:05:12 +08:00
|
|
|
@table @samp
|
|
|
|
@item %r0 .. %r9
|
|
|
|
General-purpose registers.
|
|
|
|
@item %r10
|
2023-08-02 19:06:23 +08:00
|
|
|
@itemx %fp
|
|
|
|
Read-only frame pointer register.
|
2019-05-24 01:05:12 +08:00
|
|
|
@end table
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
All BPF registers are 64-bit long. However, in the Pseudo-C syntax
|
|
|
|
registers can be referred using different names, which actually
|
|
|
|
reflect the kind of instruction they appear on:
|
|
|
|
|
|
|
|
@noindent
|
|
|
|
In pseudoc syntax:
|
2019-05-24 01:05:12 +08:00
|
|
|
|
|
|
|
@table @samp
|
2023-08-02 19:06:23 +08:00
|
|
|
@item r0..r9
|
|
|
|
General-purpose register in an instruction that operates on its value
|
|
|
|
as if it was a 64-bit value.
|
|
|
|
@item w0..w9
|
|
|
|
General-purpose register in an instruction that operates on its value
|
|
|
|
as if it was a 32-bit value.
|
|
|
|
@item r10
|
|
|
|
Read-only frame pointer register.
|
2019-05-24 01:05:12 +08:00
|
|
|
@end table
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@noindent
|
|
|
|
Note that in the Pseudo-C syntax register names are not preceded by
|
|
|
|
@code{%} characters.
|
2019-05-24 01:05:12 +08:00
|
|
|
|
2019-07-18 04:57:23 +08:00
|
|
|
@node BPF Directives
|
2023-08-02 19:06:23 +08:00
|
|
|
@section BPF Directives
|
2019-07-18 04:57:23 +08:00
|
|
|
|
|
|
|
@cindex machine directives, BPF
|
|
|
|
|
|
|
|
The BPF version of @code{@value{AS}} supports the following additional
|
|
|
|
machine directives:
|
|
|
|
|
|
|
|
@table @code
|
|
|
|
@cindex @code{half} directive, BPF
|
|
|
|
@item .word
|
|
|
|
The @code{.half} directive produces a 16 bit value.
|
|
|
|
|
|
|
|
@cindex @code{word} directive, BPF
|
|
|
|
@item .word
|
|
|
|
The @code{.word} directive produces a 32 bit value.
|
|
|
|
|
|
|
|
@cindex @code{dword} directive, BPF
|
|
|
|
@item .dword
|
|
|
|
The @code{.dword} directive produces a 64 bit value.
|
|
|
|
@end table
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@node BPF Instructions
|
|
|
|
@section BPF Instructions
|
2019-05-24 01:05:12 +08:00
|
|
|
|
|
|
|
@cindex BPF opcodes
|
|
|
|
@cindex opcodes for BPF
|
|
|
|
In the instruction descriptions below the following field descriptors
|
|
|
|
are used:
|
|
|
|
|
|
|
|
@table @code
|
2023-08-02 19:06:23 +08:00
|
|
|
@item rd
|
|
|
|
Destination general-purpose register whose role is to be the
|
|
|
|
destination of an operation.
|
|
|
|
@item rs
|
2019-05-24 01:05:12 +08:00
|
|
|
Source general-purpose register whose role is to be the source of an
|
|
|
|
operation.
|
|
|
|
@item disp16
|
|
|
|
16-bit signed PC-relative offset, measured in number of 64-bit words,
|
|
|
|
minus one.
|
|
|
|
@item disp32
|
|
|
|
32-bit signed PC-relative offset, measured in number of 64-bit words,
|
|
|
|
minus one.
|
|
|
|
@item offset16
|
2023-08-02 19:06:23 +08:00
|
|
|
Signed 16-bit immediate representing an offset in bytes.
|
|
|
|
@item disp16
|
|
|
|
Signed 16-bit immediate representing a displacement to a target,
|
|
|
|
measured in number of 64-bit words @emph{minus one}.
|
|
|
|
@item disp32
|
|
|
|
Signed 32-bit immediate representing a displacement to a target,
|
|
|
|
measured in number of 64-bit words @emph{minus one}.
|
2019-05-24 01:05:12 +08:00
|
|
|
@item imm32
|
|
|
|
Signed 32-bit immediate.
|
|
|
|
@item imm64
|
|
|
|
Signed 64-bit immediate.
|
|
|
|
@end table
|
|
|
|
|
2023-08-17 15:38:37 +08:00
|
|
|
@noindent
|
|
|
|
Note that the assembler allows to express the value for an immediate
|
|
|
|
using any numerical literal whose two's complement encoding fits in
|
|
|
|
the immediate field. For example, @code{-2}, @code{0xfffffffe} and
|
|
|
|
@code{4294967294} all denote the same encoded 32-bit immediate, whose
|
|
|
|
value may be then interpreted by different instructions as either as a
|
|
|
|
negative or a positive number.
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@subsection Arithmetic instructions
|
2019-05-24 01:05:12 +08:00
|
|
|
|
|
|
|
The destination register in these instructions act like an
|
|
|
|
accumulator.
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
Note that in pseudoc syntax these instructions should use @code{r}
|
|
|
|
registers.
|
|
|
|
|
2019-05-24 01:05:12 +08:00
|
|
|
@table @code
|
2023-08-02 19:06:23 +08:00
|
|
|
@item add rd, rs
|
|
|
|
@itemx add rd, imm32
|
|
|
|
@itemx rd += rs
|
|
|
|
@itemx rd += imm32
|
2019-05-24 01:05:12 +08:00
|
|
|
64-bit arithmetic addition.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item sub rd, rs
|
|
|
|
@itemx sub rd, rs
|
|
|
|
@itemx rd -= rs
|
|
|
|
@itemx rd -= imm32
|
2019-05-24 01:05:12 +08:00
|
|
|
64-bit arithmetic subtraction.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item mul rd, rs
|
|
|
|
@itemx mul rd, imm32
|
|
|
|
@itemx rd *= rs
|
|
|
|
@itemx rd *= imm32
|
2019-05-24 01:05:12 +08:00
|
|
|
64-bit arithmetic multiplication.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item div rd, rs
|
|
|
|
@itemx div rd, imm32
|
|
|
|
@itemx rd /= rs
|
|
|
|
@itemx rd /= imm32
|
2019-05-24 01:05:12 +08:00
|
|
|
64-bit arithmetic integer division.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item mod rd, rs
|
|
|
|
@itemx mod rd, imm32
|
|
|
|
@itemx rd %= rs
|
|
|
|
@itemx rd %= imm32
|
2019-05-24 01:05:12 +08:00
|
|
|
64-bit integer remainder.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item and rd, rs
|
|
|
|
@itemx and rd, imm32
|
|
|
|
@itemx rd &= rs
|
|
|
|
@itemx rd &= imm32
|
2019-05-24 01:05:12 +08:00
|
|
|
64-bit bit-wise ``and'' operation.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item or rd, rs
|
|
|
|
@itemx or rd, imm32
|
|
|
|
@itemx rd |= rs
|
|
|
|
@itemx rd |= imm32
|
2019-05-24 01:05:12 +08:00
|
|
|
64-bit bit-wise ``or'' operation.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item xor rd, imm32
|
|
|
|
@itemx xor rd, rs
|
|
|
|
@itemx rd ^= rs
|
|
|
|
@itemx rd ^= imm32
|
2019-05-24 01:05:12 +08:00
|
|
|
64-bit bit-wise exclusive-or operation.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item lsh rd, rs
|
|
|
|
@itemx ldh rd, imm32
|
|
|
|
@itemx rd <<= rs
|
|
|
|
@itemx rd <<= imm32
|
|
|
|
64-bit left shift, by @code{rs} or @code{imm32} bits.
|
|
|
|
|
|
|
|
@item rsh %d, %s
|
|
|
|
@itemx rsh rd, imm32
|
|
|
|
@itemx rd >>= rs
|
|
|
|
@itemx rd >>= imm32
|
|
|
|
64-bit right logical shift, by @code{rs} or @code{imm32} bits.
|
|
|
|
|
|
|
|
@item arsh rd, rs
|
|
|
|
@itemx arsh rd, imm32
|
|
|
|
@itemx rd s>>= rs
|
|
|
|
@itemx rd s>>= imm32
|
|
|
|
64-bit right arithmetic shift, by @code{rs} or @code{imm32} bits.
|
|
|
|
|
|
|
|
@item neg rd
|
|
|
|
@itemx rd = - rd
|
2019-05-24 01:05:12 +08:00
|
|
|
64-bit arithmetic negation.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item mov rd, rs
|
|
|
|
@itemx mov rd, imm32
|
|
|
|
@itemx rd = rs
|
|
|
|
@itemx rd = imm32
|
|
|
|
Move the 64-bit value of @code{rs} in @code{rd}, or load @code{imm32}
|
|
|
|
in @code{rd}.
|
|
|
|
|
|
|
|
@item movs rd, rs, 8
|
|
|
|
@itemx rd = (s8) rs
|
|
|
|
Move the sign-extended 8-bit value in @code{rs} to @code{rd}.
|
|
|
|
|
|
|
|
@item movs rd, rs, 16
|
|
|
|
@itemx rd = (s16) rs
|
|
|
|
Move the sign-extended 16-bit value in @code{rs} to @code{rd}.
|
|
|
|
|
|
|
|
@item movs rd, rs, 32
|
|
|
|
@itemx rd = (s32) rs
|
|
|
|
Move the sign-extended 32-bit value in @code{rs} to @code{rd}.
|
2019-05-24 01:05:12 +08:00
|
|
|
@end table
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@subsection 32-bit arithmetic instructions
|
2019-05-24 01:05:12 +08:00
|
|
|
|
|
|
|
The destination register in these instructions act as an accumulator.
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
Note that in pseudoc syntax these instructions should use @code{w}
|
|
|
|
registers. It is not allowed to mix @code{w} and @code{r} registers
|
|
|
|
in the same instruction.
|
|
|
|
|
2019-05-24 01:05:12 +08:00
|
|
|
@table @code
|
2023-08-02 19:06:23 +08:00
|
|
|
@item add32 rd, rs
|
|
|
|
@itemx add32 rd, imm32
|
|
|
|
@itemx rd += rs
|
|
|
|
@itemx rd += imm32
|
2019-05-24 01:05:12 +08:00
|
|
|
32-bit arithmetic addition.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item sub32 rd, rs
|
|
|
|
@itemx sub32 rd, imm32
|
|
|
|
@itemx rd -= rs
|
|
|
|
@itemx rd += imm32
|
2019-05-24 01:05:12 +08:00
|
|
|
32-bit arithmetic subtraction.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item mul32 rd, rs
|
|
|
|
@itemx mul32 rd, imm32
|
|
|
|
@itemx rd *= rs
|
|
|
|
@itemx rd *= imm32
|
2019-05-24 01:05:12 +08:00
|
|
|
32-bit arithmetic multiplication.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item div32 rd, rs
|
|
|
|
@itemx div32 rd, imm32
|
|
|
|
@itemx rd /= rs
|
|
|
|
@itemx rd /= imm32
|
2019-05-24 01:05:12 +08:00
|
|
|
32-bit arithmetic integer division.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item mod32 rd, rs
|
|
|
|
@itemx mod32 rd, imm32
|
|
|
|
@itemx rd %= rs
|
|
|
|
@itemx rd %= imm32
|
2019-05-24 01:05:12 +08:00
|
|
|
32-bit integer remainder.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item and32 rd, rs
|
|
|
|
@itemx and32 rd, imm32
|
|
|
|
@itemx rd &= rs
|
|
|
|
@itemx rd &= imm32
|
2019-05-24 01:05:12 +08:00
|
|
|
32-bit bit-wise ``and'' operation.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item or32 rd, rs
|
|
|
|
@itemx or32 rd, imm32
|
|
|
|
@itemx rd |= rs
|
|
|
|
@itemx rd |= imm32
|
2019-05-24 01:05:12 +08:00
|
|
|
32-bit bit-wise ``or'' operation.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item xor32 rd, rs
|
|
|
|
@itemx xor32 rd, imm32
|
|
|
|
@itemx rd ^= rs
|
|
|
|
@itemx rd ^= imm32
|
2019-05-24 01:05:12 +08:00
|
|
|
32-bit bit-wise exclusive-or operation.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item lsh32 rd, rs
|
|
|
|
@itemx lsh32 rd, imm32
|
|
|
|
@itemx rd <<= rs
|
|
|
|
@itemx rd <<= imm32
|
|
|
|
32-bit left shift, by @code{rs} or @code{imm32} bits.
|
|
|
|
|
|
|
|
@item rsh32 rd, rs
|
|
|
|
@itemx rsh32 rd, imm32
|
|
|
|
@itemx rd >>= rs
|
|
|
|
@itemx rd >>= imm32
|
|
|
|
32-bit right logical shift, by @code{rs} or @code{imm32} bits.
|
|
|
|
|
|
|
|
@item arsh32 rd, rs
|
|
|
|
@itemx arsh32 rd, imm32
|
|
|
|
@itemx rd s>>= rs
|
|
|
|
@itemx rd s>>= imm32
|
|
|
|
32-bit right arithmetic shift, by @code{rs} or @code{imm32} bits.
|
|
|
|
|
|
|
|
@item neg32 rd
|
|
|
|
@itemx rd = - rd
|
2019-05-24 01:05:12 +08:00
|
|
|
32-bit arithmetic negation.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item mov32 rd, rs
|
|
|
|
@itemx mov32 rd, imm32
|
|
|
|
@itemx rd = rs
|
|
|
|
@itemx rd = imm32
|
|
|
|
Move the 32-bit value of @code{rs} in @code{rd}, or load @code{imm32}
|
|
|
|
in @code{rd}.
|
|
|
|
|
|
|
|
@item mov32s rd, rs, 8
|
|
|
|
@itemx rd = (s8) rs
|
|
|
|
Move the sign-extended 8-bit value in @code{rs} to @code{rd}.
|
|
|
|
|
|
|
|
@item mov32s rd, rs, 16
|
|
|
|
@itemx rd = (s16) rs
|
|
|
|
Move the sign-extended 16-bit value in @code{rs} to @code{rd}.
|
|
|
|
|
|
|
|
@item mov32s rd, rs, 32
|
|
|
|
@itemx rd = (s32) rs
|
|
|
|
Move the sign-extended 32-bit value in @code{rs} to @code{rd}.
|
|
|
|
@end table
|
|
|
|
|
|
|
|
@subsection Endianness conversion instructions
|
|
|
|
|
|
|
|
@table @code
|
|
|
|
@item endle rd, 16
|
|
|
|
@itemx endle rd, 32
|
|
|
|
@itemx endle rd, 64
|
|
|
|
@itemx rd = le16 rd
|
|
|
|
@itemx rd = le32 rd
|
|
|
|
@itemx rd = le64 rd
|
|
|
|
Convert the 16-bit, 32-bit or 64-bit value in @code{rd} to
|
|
|
|
little-endian and store it back in @code{rd}.
|
|
|
|
@item endbe %d, 16
|
|
|
|
@itemx endbe %d, 32
|
|
|
|
@itemx endbe %d, 64
|
|
|
|
@itemx rd = be16 rd
|
|
|
|
@itemx rd = be32 rd
|
|
|
|
@itemx rd = be64 rd
|
|
|
|
Convert the 16-bit, 32-bit or 64-bit value in @code{rd} to big-endian
|
|
|
|
and store it back in @code{rd}.
|
2019-05-24 01:05:12 +08:00
|
|
|
@end table
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@subsection Byte swap instructions
|
2023-07-24 08:54:06 +08:00
|
|
|
|
|
|
|
@table @code
|
2023-08-02 19:06:23 +08:00
|
|
|
@item bswap rd, 16
|
|
|
|
@itemx rd = bswap16 rd
|
|
|
|
Swap the least-significant 16-bit word in @code{rd} with the
|
|
|
|
most-significant 16-bit word.
|
|
|
|
|
|
|
|
@item bswap rd, 32
|
|
|
|
@itemx rd = bswap32 rd
|
|
|
|
Swap the least-significant 32-bit word in @code{rd} with the
|
|
|
|
most-significant 32-bit word.
|
|
|
|
|
|
|
|
@item bswap rd, 64
|
|
|
|
@itemx rd = bswap64 rd
|
|
|
|
Swap the least-significant 64-bit word in @code{rd} with the
|
|
|
|
most-significant 64-bit word.
|
2023-07-24 08:54:06 +08:00
|
|
|
@end table
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@subsection 64-bit load and pseudo maps
|
2019-05-24 01:05:12 +08:00
|
|
|
|
|
|
|
@table @code
|
2023-08-02 19:06:23 +08:00
|
|
|
@item lddw rd, imm64
|
|
|
|
@itemx rd = imm64 ll
|
|
|
|
Load the given signed 64-bit immediate to the destination register
|
|
|
|
@code{rd}.
|
2019-05-24 01:05:12 +08:00
|
|
|
@end table
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@subsection Load instructions for socket filters
|
2019-05-24 01:05:12 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
@file{Documentation/networking/filter.txt} in the Linux kernel source
|
|
|
|
tree for more information.
|
|
|
|
|
|
|
|
Absolute loads:
|
|
|
|
|
|
|
|
@table @code
|
2019-07-15 22:00:28 +08:00
|
|
|
@item ldabsdw imm32
|
2023-08-02 19:06:23 +08:00
|
|
|
@itemx r0 = *(u64 *) skb[imm32]
|
2019-05-24 01:05:12 +08:00
|
|
|
Absolute 64-bit load.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
2019-07-15 22:00:28 +08:00
|
|
|
@item ldabsw imm32
|
2023-08-02 19:06:23 +08:00
|
|
|
@itemx r0 = *(u32 *) skb[imm32]
|
2019-05-24 01:05:12 +08:00
|
|
|
Absolute 32-bit load.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
2019-07-15 22:00:28 +08:00
|
|
|
@item ldabsh imm32
|
2023-08-02 19:06:23 +08:00
|
|
|
@itemx r0 = *(u16 *) skb[imm32]
|
2019-05-24 01:05:12 +08:00
|
|
|
Absolute 16-bit load.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
2019-07-15 22:00:28 +08:00
|
|
|
@item ldabsb imm32
|
2023-08-02 19:06:23 +08:00
|
|
|
@itemx r0 = *(u8 *) skb[imm32]
|
2019-05-24 01:05:12 +08:00
|
|
|
Absolute 8-bit load.
|
|
|
|
@end table
|
|
|
|
|
|
|
|
Indirect loads:
|
|
|
|
|
|
|
|
@table @code
|
2023-08-02 19:06:23 +08:00
|
|
|
@item ldinddw rs, imm32
|
|
|
|
@itemx r0 = *(u64 *) skb[rs + imm32]
|
2019-05-24 01:05:12 +08:00
|
|
|
Indirect 64-bit load.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item ldindw rs, imm32
|
|
|
|
@itemx r0 = *(u32 *) skb[rs + imm32]
|
2019-05-24 01:05:12 +08:00
|
|
|
Indirect 32-bit load.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item ldindh rs, imm32
|
|
|
|
@itemx r0 = *(u16 *) skb[rs + imm32]
|
2019-05-24 01:05:12 +08:00
|
|
|
Indirect 16-bit load.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
2019-07-15 22:00:28 +08:00
|
|
|
@item ldindb %s, imm32
|
2023-08-02 19:06:23 +08:00
|
|
|
@itemx r0 = *(u8 *) skb[rs + imm32]
|
2019-05-24 01:05:12 +08:00
|
|
|
Indirect 8-bit load.
|
|
|
|
@end table
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@subsection Generic load/store instructions
|
2019-05-24 01:05:12 +08:00
|
|
|
|
|
|
|
General-purpose load and store instructions are provided for several
|
|
|
|
word sizes.
|
|
|
|
|
|
|
|
Load to register instructions:
|
|
|
|
|
|
|
|
@table @code
|
2023-08-02 19:06:23 +08:00
|
|
|
@item ldxdw rd, [rs + offset16]
|
|
|
|
@itemx rd = *(u64 *) (rs + offset16)
|
2019-05-24 01:05:12 +08:00
|
|
|
Generic 64-bit load.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item ldxw rd, [rs + offset16]
|
|
|
|
@itemx rd = *(u32 *) (rs + offset16)
|
2019-05-24 01:05:12 +08:00
|
|
|
Generic 32-bit load.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item ldxh rd, [rs + offset16]
|
|
|
|
@itemx rd = *(u16 *) (rs + offset16)
|
2019-05-24 01:05:12 +08:00
|
|
|
Generic 16-bit load.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item ldxb rd, [rs + offset16]
|
|
|
|
@itemx rd = *(u8 *) (rs + offset16)
|
2019-05-24 01:05:12 +08:00
|
|
|
Generic 8-bit load.
|
|
|
|
@end table
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
Signed load to register instructions:
|
|
|
|
|
|
|
|
@table @code
|
|
|
|
@item ldxsdw rd, [rs + offset16]
|
|
|
|
@itemx rd = *(s64 *) (rs + offset16)
|
|
|
|
Generic 64-bit signed load.
|
|
|
|
|
|
|
|
@item ldxsw rd, [rs + offset16]
|
|
|
|
@itemx rd = *(s32 *) (rs + offset16)
|
|
|
|
Generic 32-bit signed load.
|
|
|
|
|
|
|
|
@item ldxsh rd, [rs + offset16]
|
|
|
|
@itemx rd = *(s16 *) (rs + offset16)
|
|
|
|
Generic 16-bit signed load.
|
|
|
|
|
|
|
|
@item ldxsb rd, [rs + offset16]
|
|
|
|
@itemx rd = *(s8 *) (rs + offset16)
|
|
|
|
Generic 8-bit signed load.
|
|
|
|
@end table
|
|
|
|
|
2019-05-24 01:05:12 +08:00
|
|
|
Store from register instructions:
|
|
|
|
|
|
|
|
@table @code
|
2023-08-02 19:06:23 +08:00
|
|
|
@item stxdw [rd + offset16], %s
|
|
|
|
@itemx *(u64 *) (rd + offset16)
|
2019-05-24 01:05:12 +08:00
|
|
|
Generic 64-bit store.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item stxw [rd + offset16], %s
|
|
|
|
@itemx *(u32 *) (rd + offset16)
|
2019-05-24 01:05:12 +08:00
|
|
|
Generic 32-bit store.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item stxh [rd + offset16], %s
|
|
|
|
@itemx *(u16 *) (rd + offset16)
|
2019-05-24 01:05:12 +08:00
|
|
|
Generic 16-bit store.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item stxb [rd + offset16], %s
|
|
|
|
@itemx *(u8 *) (rd + offset16)
|
2019-05-24 01:05:12 +08:00
|
|
|
Generic 8-bit store.
|
|
|
|
@end table
|
|
|
|
|
|
|
|
Store from immediates instructions:
|
|
|
|
|
|
|
|
@table @code
|
2023-08-02 19:06:23 +08:00
|
|
|
@item stdw [rd + offset16], imm32
|
|
|
|
@itemx *(u64 *) (rd + offset16) = imm32
|
2019-05-24 01:05:12 +08:00
|
|
|
Store immediate as 64-bit.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item stw [rd + offset16], imm32
|
|
|
|
@itemx *(u32 *) (rd + offset16) = imm32
|
2019-05-24 01:05:12 +08:00
|
|
|
Store immediate as 32-bit.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item sth [rd + offset16], imm32
|
|
|
|
@itemx *(u16 *) (rd + offset16) = imm32
|
2019-05-24 01:05:12 +08:00
|
|
|
Store immediate as 16-bit.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item stb [rd + offset16], imm32
|
|
|
|
@itemx *(u8 *) (rd + offset16) = imm32
|
2019-05-24 01:05:12 +08:00
|
|
|
Store immediate as 8-bit.
|
|
|
|
@end table
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@subsection Jump instructions
|
2019-05-24 01:05:12 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
@table @code
|
2023-08-02 19:06:23 +08:00
|
|
|
@item ja disp16
|
|
|
|
@itemx goto disp16
|
2019-05-24 01:05:12 +08:00
|
|
|
Jump-always.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item jal disp32
|
|
|
|
@itemx gotol disp32
|
|
|
|
Jump-always, long range.
|
|
|
|
|
|
|
|
@item jeq rd, rs, disp16
|
|
|
|
@itemx jeq rd, imm32, disp16
|
|
|
|
@itemx if rd == rs goto disp16
|
|
|
|
@itemx if rd == imm32 goto disp16
|
2023-04-20 22:46:08 +08:00
|
|
|
Jump if equal, unsigned.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item jgt rd, rs, disp16
|
|
|
|
@itemx jgt rd, imm32, disp16
|
|
|
|
@itemx if rd > rs goto disp16
|
|
|
|
@itemx if rd > imm32 goto disp16
|
2023-04-20 22:46:08 +08:00
|
|
|
Jump if greater, unsigned.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item jge rd, rs, disp16
|
|
|
|
@itemx jge rd, imm32, disp16
|
|
|
|
@itemx if rd >= rs goto disp16
|
|
|
|
@itemx if rd >= imm32 goto disp16
|
2019-05-24 01:05:12 +08:00
|
|
|
Jump if greater or equal.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item jlt rd, rs, disp16
|
|
|
|
@itemx jlt rd, imm32, disp16
|
|
|
|
@itemx if rd < rs goto disp16
|
|
|
|
@itemx if rd < imm32 goto disp16
|
2019-05-24 01:05:12 +08:00
|
|
|
Jump if lesser.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item jle rd , rs, disp16
|
|
|
|
@itemx jle rd, imm32, disp16
|
|
|
|
@itemx if rd <= rs goto disp16
|
|
|
|
@itemx if rd <= imm32 goto disp16
|
2019-05-24 01:05:12 +08:00
|
|
|
Jump if lesser or equal.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item jset rd, rs, disp16
|
|
|
|
@itemx jset rd, imm32, disp16
|
|
|
|
@itemx if rd & rs goto disp16
|
|
|
|
@itemx if rd & imm32 goto disp16
|
2019-05-24 01:05:12 +08:00
|
|
|
Jump if signed equal.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item jne rd, rs, disp16
|
|
|
|
@itemx jne rd, imm32, disp16
|
|
|
|
@itemx if rd != rs goto disp16
|
|
|
|
@itemx if rd != imm32 goto disp16
|
2019-05-24 01:05:12 +08:00
|
|
|
Jump if not equal.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item jsgt rd, rs, disp16
|
|
|
|
@itemx jsgt rd, imm32, disp16
|
|
|
|
@itemx if rd s> rs goto disp16
|
|
|
|
@itemx if rd s> imm32 goto disp16
|
2019-05-24 01:05:12 +08:00
|
|
|
Jump if signed greater.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item jsge rd, rs, disp16
|
|
|
|
@itemx jsge rd, imm32, disp16
|
|
|
|
@itemx if rd s>= rd goto disp16
|
|
|
|
@itemx if rd s>= imm32 goto disp16
|
2019-05-24 01:05:12 +08:00
|
|
|
Jump if signed greater or equal.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item jslt rd, rs, disp16
|
|
|
|
@itemx jslt rd, imm32, disp16
|
|
|
|
@itemx if rd s< rs goto disp16
|
|
|
|
@itemx if rd s< imm32 goto disp16
|
2019-05-24 01:05:12 +08:00
|
|
|
Jump if signed lesser.
|
2023-08-02 19:06:23 +08:00
|
|
|
|
|
|
|
@item jsle rd, rs, disp16
|
|
|
|
@itemx jsle rd, imm32, disp16
|
|
|
|
@itemx if rd s<= rs goto disp16
|
|
|
|
@itemx if rd s<= imm32 goto disp16
|
2019-05-24 01:05:12 +08:00
|
|
|
Jump if signed lesser or equal.
|
|
|
|
@end table
|
|
|
|
|
|
|
|
A call instruction is provided in order to perform calls to other eBPF
|
|
|
|
functions, or to external kernel helpers:
|
|
|
|
|
|
|
|
@table @code
|
2023-08-02 19:06:23 +08:00
|
|
|
@item call disp32
|
|
|
|
@item call imm32
|
2019-05-24 01:05:12 +08:00
|
|
|
Jump and link to the offset @emph{disp32}, or to the kernel helper
|
|
|
|
function identified by @emph{imm32}.
|
|
|
|
@end table
|
|
|
|
|
|
|
|
Finally:
|
|
|
|
|
|
|
|
@table @code
|
|
|
|
@item exit
|
|
|
|
Terminate the eBPF program.
|
|
|
|
@end table
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@subsection 32-bit jump instructions
|
|
|
|
|
|
|
|
eBPF provides the following compare-and-jump instructions, which
|
|
|
|
compare the 32-bit 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.
|
2019-05-24 01:05:12 +08:00
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
These instructions are only available in BPF v3 or later.
|
2023-04-20 22:46:08 +08:00
|
|
|
|
DesCGENization of the BPF binutils port
CGEN is cool, but the BPF architecture is simply too bizarre for it.
The weird way of BPF to handle endianness in instruction encoding, the
weird C-like alternative assembly syntax, the weird abuse of
multi-byte (or infra-byte) instruction fields as opcodes, the unusual
presence of opcodes beyond the first 32-bits of some instructions, are
all examples of what makes it a PITA to continue using CGEN for this
port. The bpf.cpu file is becoming so complex and so nested with
p-macros that it is very difficult to read, and quite challenging to
update. Also, every time we are forced to change something in CGEN to
accommodate BPF requirements (which is often) we have to do extensive
testing to make sure we do not break any other target using CGEN.
This is getting un-maintenable.
So I have decided to bite the bullet and revamp/rewrite the port so it
no longer uses CGEN. Overall, this involved:
* To remove the cpu/bpf.{cpu,opc} descriptions.
* To remove the CGEN generated files.
* To replace the CGEN generated opcodes table with a new hand-written
opcodes table for BPF.
* To replace the CGEN generated disassembler wih a new disassembler
that uses the new opcodes.
* To replace the CGEN generated assembler with a new assembler that uses the
new opcodes.
* To replace the CGEN generated simulator with a new simulator that uses the
new opcodes. [This is pushed in GDB in another patch.]
* To adapt the build systems to the new situation.
Additionally, this patch introduces some extensions and improvements:
* A new BPF relocation BPF_RELOC_BPF_DISP16 plus corresponding ELF
relocation R_BPF_GNU_64_16 are added to the BPF BFD port. These
relocations are used for section-relative 16-bit offsets used in
load/store instructions.
* The disassembler now has support for the "pseudo-c" assembly syntax of
BPF. What dialect to use when disassembling is controlled by a command
line option.
* The disassembler now has support for dumping instruction immediates in
either octal, hexadecimal or decimal. The used output base is controlled
by a new command-line option.
* The GAS BPF test suite has been re-structured and expanded in order to
test the disassembler pseudoc syntax support. Minor bugs have been also
fixed there. The assembler generic tests that were disabled for bpf-*-*
targets due to the previous implementation of pseudoc syntax are now
re-enabled. Additional tests have been added to test the new features of
the assembler. .dump files are no longer used.
* The linker BPF test suite has been adapted to the command line options
used by the new disassembler.
The result is very satisfactory. This patchs adds 3448 lines of code
and removes 10542 lines of code.
Tested in:
* Target bpf-unknown-none with 64-bit little-endian host and 32-bit
little-endian host.
* Target x86-64-linux-gnu with --enable-targets=all
Note that I have not tested in a big-endian host yet. I will do so
once this lands upstream so I can use the GCC compiler farm.
I have not included ChangeLog entries in this patch: these would be
massive and not very useful, considering this is pretty much a rewrite
of the port. I beg the indulgence of the global maintainers.
2023-07-15 06:50:14 +08:00
|
|
|
@table @code
|
2023-08-02 19:06:23 +08:00
|
|
|
@item jeq32 rd, rs, disp16
|
|
|
|
@itemx jeq32 rd, imm32, disp16
|
|
|
|
@itemx if rd == rs goto disp16
|
|
|
|
@itemx if rd == imm32 goto disp16
|
|
|
|
Jump if equal, unsigned.
|
2023-04-20 22:46:08 +08:00
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@item jgt32 rd, rs, disp16
|
|
|
|
@itemx jgt32 rd, imm32, disp16
|
|
|
|
@itemx if rd > rs goto disp16
|
|
|
|
@itemx if rd > imm32 goto disp16
|
|
|
|
Jump if greater, unsigned.
|
2023-04-20 22:46:08 +08:00
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@item jge32 rd, rs, disp16
|
|
|
|
@itemx jge32 rd, imm32, disp16
|
|
|
|
@itemx if rd >= rs goto disp16
|
|
|
|
@itemx if rd >= imm32 goto disp16
|
|
|
|
Jump if greater or equal.
|
2023-04-20 22:46:08 +08:00
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@item jlt32 rd, rs, disp16
|
|
|
|
@itemx jlt32 rd, imm32, disp16
|
|
|
|
@itemx if rd < rs goto disp16
|
|
|
|
@itemx if rd < imm32 goto disp16
|
|
|
|
Jump if lesser.
|
2023-04-20 22:46:08 +08:00
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@item jle32 rd , rs, disp16
|
|
|
|
@itemx jle32 rd, imm32, disp16
|
|
|
|
@itemx if rd <= rs goto disp16
|
|
|
|
@itemx if rd <= imm32 goto disp16
|
|
|
|
Jump if lesser or equal.
|
2023-04-20 22:46:08 +08:00
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@item jset32 rd, rs, disp16
|
|
|
|
@itemx jset32 rd, imm32, disp16
|
|
|
|
@itemx if rd & rs goto disp16
|
|
|
|
@itemx if rd & imm32 goto disp16
|
|
|
|
Jump if signed equal.
|
DesCGENization of the BPF binutils port
CGEN is cool, but the BPF architecture is simply too bizarre for it.
The weird way of BPF to handle endianness in instruction encoding, the
weird C-like alternative assembly syntax, the weird abuse of
multi-byte (or infra-byte) instruction fields as opcodes, the unusual
presence of opcodes beyond the first 32-bits of some instructions, are
all examples of what makes it a PITA to continue using CGEN for this
port. The bpf.cpu file is becoming so complex and so nested with
p-macros that it is very difficult to read, and quite challenging to
update. Also, every time we are forced to change something in CGEN to
accommodate BPF requirements (which is often) we have to do extensive
testing to make sure we do not break any other target using CGEN.
This is getting un-maintenable.
So I have decided to bite the bullet and revamp/rewrite the port so it
no longer uses CGEN. Overall, this involved:
* To remove the cpu/bpf.{cpu,opc} descriptions.
* To remove the CGEN generated files.
* To replace the CGEN generated opcodes table with a new hand-written
opcodes table for BPF.
* To replace the CGEN generated disassembler wih a new disassembler
that uses the new opcodes.
* To replace the CGEN generated assembler with a new assembler that uses the
new opcodes.
* To replace the CGEN generated simulator with a new simulator that uses the
new opcodes. [This is pushed in GDB in another patch.]
* To adapt the build systems to the new situation.
Additionally, this patch introduces some extensions and improvements:
* A new BPF relocation BPF_RELOC_BPF_DISP16 plus corresponding ELF
relocation R_BPF_GNU_64_16 are added to the BPF BFD port. These
relocations are used for section-relative 16-bit offsets used in
load/store instructions.
* The disassembler now has support for the "pseudo-c" assembly syntax of
BPF. What dialect to use when disassembling is controlled by a command
line option.
* The disassembler now has support for dumping instruction immediates in
either octal, hexadecimal or decimal. The used output base is controlled
by a new command-line option.
* The GAS BPF test suite has been re-structured and expanded in order to
test the disassembler pseudoc syntax support. Minor bugs have been also
fixed there. The assembler generic tests that were disabled for bpf-*-*
targets due to the previous implementation of pseudoc syntax are now
re-enabled. Additional tests have been added to test the new features of
the assembler. .dump files are no longer used.
* The linker BPF test suite has been adapted to the command line options
used by the new disassembler.
The result is very satisfactory. This patchs adds 3448 lines of code
and removes 10542 lines of code.
Tested in:
* Target bpf-unknown-none with 64-bit little-endian host and 32-bit
little-endian host.
* Target x86-64-linux-gnu with --enable-targets=all
Note that I have not tested in a big-endian host yet. I will do so
once this lands upstream so I can use the GCC compiler farm.
I have not included ChangeLog entries in this patch: these would be
massive and not very useful, considering this is pretty much a rewrite
of the port. I beg the indulgence of the global maintainers.
2023-07-15 06:50:14 +08:00
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@item jne32 rd, rs, disp16
|
|
|
|
@itemx jne32 rd, imm32, disp16
|
|
|
|
@itemx if rd != rs goto disp16
|
|
|
|
@itemx if rd != imm32 goto disp16
|
|
|
|
Jump if not equal.
|
2023-07-25 05:50:34 +08:00
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@item jsgt32 rd, rs, disp16
|
|
|
|
@itemx jsgt32 rd, imm32, disp16
|
|
|
|
@itemx if rd s> rs goto disp16
|
|
|
|
@itemx if rd s> imm32 goto disp16
|
|
|
|
Jump if signed greater.
|
|
|
|
|
|
|
|
@item jsge32 rd, rs, disp16
|
|
|
|
@itemx jsge32 rd, imm32, disp16
|
|
|
|
@itemx if rd s>= rd goto disp16
|
|
|
|
@itemx if rd s>= imm32 goto disp16
|
|
|
|
Jump if signed greater or equal.
|
|
|
|
|
|
|
|
@item jslt32 rd, rs, disp16
|
|
|
|
@itemx jslt32 rd, imm32, disp16
|
|
|
|
@itemx if rd s< rs goto disp16
|
|
|
|
@itemx if rd s< imm32 goto disp16
|
|
|
|
Jump if signed lesser.
|
|
|
|
|
|
|
|
@item jsle32 rd, rs, disp16
|
|
|
|
@itemx jsle32 rd, imm32, disp16
|
|
|
|
@itemx if rd s<= rs goto disp16
|
|
|
|
@itemx if rd s<= imm32 goto disp16
|
|
|
|
Jump if signed lesser or equal.
|
2023-07-25 05:50:34 +08:00
|
|
|
@end table
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@subsection Atomic instructions
|
DesCGENization of the BPF binutils port
CGEN is cool, but the BPF architecture is simply too bizarre for it.
The weird way of BPF to handle endianness in instruction encoding, the
weird C-like alternative assembly syntax, the weird abuse of
multi-byte (or infra-byte) instruction fields as opcodes, the unusual
presence of opcodes beyond the first 32-bits of some instructions, are
all examples of what makes it a PITA to continue using CGEN for this
port. The bpf.cpu file is becoming so complex and so nested with
p-macros that it is very difficult to read, and quite challenging to
update. Also, every time we are forced to change something in CGEN to
accommodate BPF requirements (which is often) we have to do extensive
testing to make sure we do not break any other target using CGEN.
This is getting un-maintenable.
So I have decided to bite the bullet and revamp/rewrite the port so it
no longer uses CGEN. Overall, this involved:
* To remove the cpu/bpf.{cpu,opc} descriptions.
* To remove the CGEN generated files.
* To replace the CGEN generated opcodes table with a new hand-written
opcodes table for BPF.
* To replace the CGEN generated disassembler wih a new disassembler
that uses the new opcodes.
* To replace the CGEN generated assembler with a new assembler that uses the
new opcodes.
* To replace the CGEN generated simulator with a new simulator that uses the
new opcodes. [This is pushed in GDB in another patch.]
* To adapt the build systems to the new situation.
Additionally, this patch introduces some extensions and improvements:
* A new BPF relocation BPF_RELOC_BPF_DISP16 plus corresponding ELF
relocation R_BPF_GNU_64_16 are added to the BPF BFD port. These
relocations are used for section-relative 16-bit offsets used in
load/store instructions.
* The disassembler now has support for the "pseudo-c" assembly syntax of
BPF. What dialect to use when disassembling is controlled by a command
line option.
* The disassembler now has support for dumping instruction immediates in
either octal, hexadecimal or decimal. The used output base is controlled
by a new command-line option.
* The GAS BPF test suite has been re-structured and expanded in order to
test the disassembler pseudoc syntax support. Minor bugs have been also
fixed there. The assembler generic tests that were disabled for bpf-*-*
targets due to the previous implementation of pseudoc syntax are now
re-enabled. Additional tests have been added to test the new features of
the assembler. .dump files are no longer used.
* The linker BPF test suite has been adapted to the command line options
used by the new disassembler.
The result is very satisfactory. This patchs adds 3448 lines of code
and removes 10542 lines of code.
Tested in:
* Target bpf-unknown-none with 64-bit little-endian host and 32-bit
little-endian host.
* Target x86-64-linux-gnu with --enable-targets=all
Note that I have not tested in a big-endian host yet. I will do so
once this lands upstream so I can use the GCC compiler farm.
I have not included ChangeLog entries in this patch: these would be
massive and not very useful, considering this is pretty much a rewrite
of the port. I beg the indulgence of the global maintainers.
2023-07-15 06:50:14 +08:00
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
Atomic exchange instructions are provided in two flavors: one for
|
|
|
|
compare-and-swap, one for unconditional exchange.
|
|
|
|
|
|
|
|
@table @code
|
|
|
|
@item acmp [rd + offset16], rs
|
|
|
|
@itemx r0 = cmpxchg_64 (rd + offset16, r0, rs)
|
|
|
|
Atomic compare-and-swap. Compares value in @code{r0} to value
|
|
|
|
addressed by @code{rd + offset16}. On match, the value addressed by
|
|
|
|
@code{rd + offset16} is replaced with the value in @code{rs}.
|
|
|
|
Regardless, the value that was at @code{rd + offset16} is
|
|
|
|
zero-extended and loaded into @code{r0}.
|
|
|
|
|
|
|
|
@item axchg [rd + offset16], rs
|
|
|
|
@itemx rs = xchg_64 (rd + offset16, rs)
|
|
|
|
Atomic exchange. Atomically exchanges the value in @code{rs} with
|
|
|
|
the value addressed by @code{rd + offset16}.
|
|
|
|
@end table
|
DesCGENization of the BPF binutils port
CGEN is cool, but the BPF architecture is simply too bizarre for it.
The weird way of BPF to handle endianness in instruction encoding, the
weird C-like alternative assembly syntax, the weird abuse of
multi-byte (or infra-byte) instruction fields as opcodes, the unusual
presence of opcodes beyond the first 32-bits of some instructions, are
all examples of what makes it a PITA to continue using CGEN for this
port. The bpf.cpu file is becoming so complex and so nested with
p-macros that it is very difficult to read, and quite challenging to
update. Also, every time we are forced to change something in CGEN to
accommodate BPF requirements (which is often) we have to do extensive
testing to make sure we do not break any other target using CGEN.
This is getting un-maintenable.
So I have decided to bite the bullet and revamp/rewrite the port so it
no longer uses CGEN. Overall, this involved:
* To remove the cpu/bpf.{cpu,opc} descriptions.
* To remove the CGEN generated files.
* To replace the CGEN generated opcodes table with a new hand-written
opcodes table for BPF.
* To replace the CGEN generated disassembler wih a new disassembler
that uses the new opcodes.
* To replace the CGEN generated assembler with a new assembler that uses the
new opcodes.
* To replace the CGEN generated simulator with a new simulator that uses the
new opcodes. [This is pushed in GDB in another patch.]
* To adapt the build systems to the new situation.
Additionally, this patch introduces some extensions and improvements:
* A new BPF relocation BPF_RELOC_BPF_DISP16 plus corresponding ELF
relocation R_BPF_GNU_64_16 are added to the BPF BFD port. These
relocations are used for section-relative 16-bit offsets used in
load/store instructions.
* The disassembler now has support for the "pseudo-c" assembly syntax of
BPF. What dialect to use when disassembling is controlled by a command
line option.
* The disassembler now has support for dumping instruction immediates in
either octal, hexadecimal or decimal. The used output base is controlled
by a new command-line option.
* The GAS BPF test suite has been re-structured and expanded in order to
test the disassembler pseudoc syntax support. Minor bugs have been also
fixed there. The assembler generic tests that were disabled for bpf-*-*
targets due to the previous implementation of pseudoc syntax are now
re-enabled. Additional tests have been added to test the new features of
the assembler. .dump files are no longer used.
* The linker BPF test suite has been adapted to the command line options
used by the new disassembler.
The result is very satisfactory. This patchs adds 3448 lines of code
and removes 10542 lines of code.
Tested in:
* Target bpf-unknown-none with 64-bit little-endian host and 32-bit
little-endian host.
* Target x86-64-linux-gnu with --enable-targets=all
Note that I have not tested in a big-endian host yet. I will do so
once this lands upstream so I can use the GCC compiler farm.
I have not included ChangeLog entries in this patch: these would be
massive and not very useful, considering this is pretty much a rewrite
of the port. I beg the indulgence of the global maintainers.
2023-07-15 06:50:14 +08:00
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@noindent
|
|
|
|
The following instructions provide atomic arithmetic operations.
|
DesCGENization of the BPF binutils port
CGEN is cool, but the BPF architecture is simply too bizarre for it.
The weird way of BPF to handle endianness in instruction encoding, the
weird C-like alternative assembly syntax, the weird abuse of
multi-byte (or infra-byte) instruction fields as opcodes, the unusual
presence of opcodes beyond the first 32-bits of some instructions, are
all examples of what makes it a PITA to continue using CGEN for this
port. The bpf.cpu file is becoming so complex and so nested with
p-macros that it is very difficult to read, and quite challenging to
update. Also, every time we are forced to change something in CGEN to
accommodate BPF requirements (which is often) we have to do extensive
testing to make sure we do not break any other target using CGEN.
This is getting un-maintenable.
So I have decided to bite the bullet and revamp/rewrite the port so it
no longer uses CGEN. Overall, this involved:
* To remove the cpu/bpf.{cpu,opc} descriptions.
* To remove the CGEN generated files.
* To replace the CGEN generated opcodes table with a new hand-written
opcodes table for BPF.
* To replace the CGEN generated disassembler wih a new disassembler
that uses the new opcodes.
* To replace the CGEN generated assembler with a new assembler that uses the
new opcodes.
* To replace the CGEN generated simulator with a new simulator that uses the
new opcodes. [This is pushed in GDB in another patch.]
* To adapt the build systems to the new situation.
Additionally, this patch introduces some extensions and improvements:
* A new BPF relocation BPF_RELOC_BPF_DISP16 plus corresponding ELF
relocation R_BPF_GNU_64_16 are added to the BPF BFD port. These
relocations are used for section-relative 16-bit offsets used in
load/store instructions.
* The disassembler now has support for the "pseudo-c" assembly syntax of
BPF. What dialect to use when disassembling is controlled by a command
line option.
* The disassembler now has support for dumping instruction immediates in
either octal, hexadecimal or decimal. The used output base is controlled
by a new command-line option.
* The GAS BPF test suite has been re-structured and expanded in order to
test the disassembler pseudoc syntax support. Minor bugs have been also
fixed there. The assembler generic tests that were disabled for bpf-*-*
targets due to the previous implementation of pseudoc syntax are now
re-enabled. Additional tests have been added to test the new features of
the assembler. .dump files are no longer used.
* The linker BPF test suite has been adapted to the command line options
used by the new disassembler.
The result is very satisfactory. This patchs adds 3448 lines of code
and removes 10542 lines of code.
Tested in:
* Target bpf-unknown-none with 64-bit little-endian host and 32-bit
little-endian host.
* Target x86-64-linux-gnu with --enable-targets=all
Note that I have not tested in a big-endian host yet. I will do so
once this lands upstream so I can use the GCC compiler farm.
I have not included ChangeLog entries in this patch: these would be
massive and not very useful, considering this is pretty much a rewrite
of the port. I beg the indulgence of the global maintainers.
2023-07-15 06:50:14 +08:00
|
|
|
|
2023-08-02 16:23:36 +08:00
|
|
|
@table @code
|
2023-08-02 19:06:23 +08:00
|
|
|
@item aadd [rd + offset16], rs
|
|
|
|
@itemx lock *(u64 *)(rd + offset16) = rs
|
|
|
|
Atomic add instruction.
|
|
|
|
|
|
|
|
@item aor [rd + offset16], rs
|
|
|
|
@itemx lock *(u64 *) (rd + offset16) |= rs
|
|
|
|
Atomic or instruction.
|
|
|
|
|
|
|
|
@item aand [rd + offset16], rs
|
|
|
|
@itemx lock *(u64 *) (rd + offset16) &= rs
|
|
|
|
Atomic and instruction.
|
|
|
|
|
|
|
|
@item axor [rd + offset16], rs
|
|
|
|
@itemx lock *(u64 *) (rd + offset16) ^= rs
|
|
|
|
Atomic xor instruction.
|
2023-04-20 22:46:08 +08:00
|
|
|
@end table
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@noindent
|
|
|
|
The following variants perform fetching before the atomic operation.
|
2023-04-20 22:46:08 +08:00
|
|
|
|
|
|
|
@table @code
|
2023-08-02 19:06:23 +08:00
|
|
|
@item afadd [rd + offset16], rs
|
|
|
|
@itemx rs = atomic_fetch_add ((u64 *)(rd + offset16), rs)
|
|
|
|
Atomic fetch-and-add instruction.
|
|
|
|
|
|
|
|
@item afor [rd + offset16], rs
|
|
|
|
@itemx rs = atomic_fetch_or ((u64 *)(rd + offset16), rs)
|
|
|
|
Atomic fetch-and-or instruction.
|
|
|
|
|
|
|
|
@item afand [rd + offset16], rs
|
|
|
|
@itemx rs = atomic_fetch_and ((u64 *)(rd + offset16), rs)
|
|
|
|
Atomic fetch-and-and instruction.
|
|
|
|
|
|
|
|
@item afxor [rd + offset16], rs
|
|
|
|
@itemx rs = atomic_fetch_xor ((u64 *)(rd + offset16), rs)
|
|
|
|
Atomic fetch-and-or instruction.
|
2023-04-20 22:46:08 +08:00
|
|
|
@end table
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
The above instructions were introduced in the V3 of the BPF
|
|
|
|
instruction set. The following instruction is supported for backwards
|
|
|
|
compatibility:
|
2023-04-20 22:46:08 +08:00
|
|
|
|
|
|
|
@table @code
|
2023-08-02 19:06:23 +08:00
|
|
|
@item xadddw [rd + offset16], rs
|
|
|
|
Alias to @code{aadd}.
|
2023-04-20 22:46:08 +08:00
|
|
|
@end table
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@subsection 32-bit atomic instructions
|
|
|
|
|
|
|
|
32-bit atomic exchange instructions are provided in two flavors: one
|
|
|
|
for compare-and-swap, one for unconditional exchange.
|
2023-07-25 05:50:34 +08:00
|
|
|
|
|
|
|
@table @code
|
2023-08-02 19:06:23 +08:00
|
|
|
@item acmp32 [rd + offset16], rs
|
|
|
|
@itemx w0 = cmpxchg32_32 (rd + offset16, w0, ws)
|
|
|
|
Atomic compare-and-swap. Compares value in @code{w0} to value
|
|
|
|
addressed by @code{rd + offset16}. On match, the value addressed by
|
|
|
|
@code{rd + offset16} is replaced with the value in @code{ws}.
|
|
|
|
Regardless, the value that was at @code{rd + offset16} is
|
|
|
|
zero-extended and loaded into @code{w0}.
|
|
|
|
|
|
|
|
@item axchg [rd + offset16], rs
|
|
|
|
@itemx ws = xchg32_32 (rd + offset16, ws)
|
|
|
|
Atomic exchange. Atomically exchanges the value in @code{ws} with
|
|
|
|
the value addressed by @code{rd + offset16}.
|
2023-07-25 05:50:34 +08:00
|
|
|
@end table
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@noindent
|
|
|
|
The following instructions provide 32-bit atomic arithmetic operations.
|
2023-04-20 22:46:08 +08:00
|
|
|
|
|
|
|
@table @code
|
2023-08-02 19:06:23 +08:00
|
|
|
@item aadd32 [rd + offset16], rs
|
|
|
|
@itemx lock *(u32 *)(rd + offset16) = rs
|
|
|
|
Atomic add instruction.
|
|
|
|
|
|
|
|
@item aor32 [rd + offset16], rs
|
|
|
|
@itemx lock *(u32 *) (rd + offset16) |= rs
|
|
|
|
Atomic or instruction.
|
|
|
|
|
|
|
|
@item aand32 [rd + offset16], rs
|
|
|
|
@itemx lock *(u32 *) (rd + offset16) &= rs
|
|
|
|
Atomic and instruction.
|
|
|
|
|
|
|
|
@item axor32 [rd + offset16], rs
|
|
|
|
@itemx lock *(u32 *) (rd + offset16) ^= rs
|
|
|
|
Atomic xor instruction
|
2023-04-20 22:46:08 +08:00
|
|
|
@end table
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
@noindent
|
|
|
|
The following variants perform fetching before the atomic operation.
|
2023-04-20 22:46:08 +08:00
|
|
|
|
|
|
|
@table @code
|
2023-08-02 19:06:23 +08:00
|
|
|
@item afadd32 [dr + offset16], rs
|
|
|
|
@itemx ws = atomic_fetch_add ((u32 *)(rd + offset16), ws)
|
|
|
|
Atomic fetch-and-add instruction.
|
|
|
|
|
|
|
|
@item afor32 [dr + offset16], rs
|
|
|
|
@itemx ws = atomic_fetch_or ((u32 *)(rd + offset16), ws)
|
|
|
|
Atomic fetch-and-or instruction.
|
|
|
|
|
|
|
|
@item afand32 [dr + offset16], rs
|
|
|
|
@itemx ws = atomic_fetch_and ((u32 *)(rd + offset16), ws)
|
|
|
|
Atomic fetch-and-and instruction.
|
|
|
|
|
|
|
|
@item afxor32 [dr + offset16], rs
|
|
|
|
@itemx ws = atomic_fetch_xor ((u32 *)(rd + offset16), ws)
|
|
|
|
Atomic fetch-and-or instruction
|
2023-04-20 22:46:08 +08:00
|
|
|
@end table
|
|
|
|
|
2023-08-02 19:06:23 +08:00
|
|
|
The above instructions were introduced in the V3 of the BPF
|
|
|
|
instruction set. The following instruction is supported for backwards
|
|
|
|
compatibility:
|
2023-04-20 22:46:08 +08:00
|
|
|
|
|
|
|
@table @code
|
2023-08-02 19:06:23 +08:00
|
|
|
@item xaddw [rd + offset16], rs
|
|
|
|
Alias to @code{aadd32}.
|
2023-04-20 22:46:08 +08:00
|
|
|
@end table
|