1 # RUN: llvm-mc -triple bpfel -filetype=obj -o %t %s
2 # RUN: llvm-objdump -d -r %t | FileCheck --check-prefixes CHECK,CHECK-64 %s
3 # RUN: llvm-objdump -mattr=+alu32 -d -r %t | FileCheck --check-prefixes CHECK,CHECK-32 %s
5 // ======== BPF_LD Class
========
6 // Some extra whitespaces are deliberately added to test the parser.
8 r0 = * (u8
*)skb
[0] // BPF_LD | BPF_ABS | BPF_B
9 r0 = *(u16
*)skb
[2] // BPF_LD | BPF_ABS | BPF_H
10 r0 = * (u32
*)skb
[4] // BPF_LD | BPF_ABS | BPF_W
11 // CHECK
: 30 00 00 00 00 00 00 00 r0 = *(u8
*)skb
[0]
12 // CHECK
: 28 00 00 00 02 00 00 00 r0 = *(u16
*)skb
[2]
13 // CHECK
: 20 00 00 00 04 00 00 00 r0 = *(u32
*)skb
[4]
15 r0 = * (u8
*)skb
[r0] // BPF_LD | BPF_IND | BPF_B
16 r0 = * (u16
*)skb
[r1] // BPF_LD | BPF_IND | BPF_H
17 r0 = *(u32
*)skb
[r2] // BPF_LD | BPF_IND | BPF_W
18 // CHECK
: 50 00 00 00 00 00 00 00 r0 = *(u8
*)skb
[r0]
19 // CHECK
: 48 10 00 00 00 00 00 00 r0 = *(u16
*)skb
[r1]
20 // CHECK
: 40 20 00 00 00 00 00 00 r0 = *(u32
*)skb
[r2]
22 r9 = 0xffffffff ll
// BPF_LD | BPF_DW | BPF_IMM
23 r9 = 8589934591 ll
// BPF_LD | BPF_DW | BPF_IMM
24 r9 = 0x1ffffffff ll
// BPF_LD | BPF_DW | BPF_IMM
25 r9 = dummy_map ll
// BPF_LD | BPF_DW | BPF_IMM
26 // CHECK
: 18 09 00 00 ff ff ff ff
00 00 00 00 00 00 00 00 r9 = 4294967295 ll
27 // CHECK
: 18 09 00 00 ff ff ff ff
00 00 00 00 01 00 00 00 r9 = 8589934591 ll
28 // CHECK
: 18 09 00 00 ff ff ff ff
00 00 00 00 01 00 00 00 r9 = 8589934591 ll
29 // CHECK
: 18 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r9 = 0 ll
30 // CHECK
: 0000000000000060: R_BPF_64_64 dummy_map
32 // ======== BPF_LDX Class
========
33 r5 = *(u8
*)(r0 + 0) // BPF_LDX | BPF_B
34 r6 = *(u16
*)(r1 + 8) // BPF_LDX | BPF_H
35 r7 = *(u32
*)(r2 + 16) // BPF_LDX | BPF_W
36 r8 = *(u64
*)(r3 - 30) // BPF_LDX | BPF_DW
37 // CHECK-
64: 71 05 00 00 00 00 00 00 r5 = *(u8
*)(r0 + 0)
38 // CHECK-
64: 69 16 08 00 00 00 00 00 r6 = *(u16
*)(r1 + 8)
39 // CHECK-
64: 61 27 10 00 00 00 00 00 r7 = *(u32
*)(r2 + 16)
40 // CHECK-
32: 71 05 00 00 00 00 00 00 w5
= *(u8
*)(r0 + 0)
41 // CHECK-
32: 69 16 08 00 00 00 00 00 w6
= *(u16
*)(r1 + 8)
42 // CHECK-
32: 61 27 10 00 00 00 00 00 w7
= *(u32
*)(r2 + 16)
43 // CHECK
: 79 38 e2 ff
00 00 00 00 r8 = *(u64
*)(r3 - 30)
45 // ======== BPF_STX Class
========
46 *(u8
*)(r0 + 0) = r7 // BPF_STX | BPF_B
47 *(u16
*)(r1 + 8) = r8 // BPF_STX | BPF_H
48 *(u32
*)(r2 + 16) = r9 // BPF_STX | BPF_W
49 *(u64
*)(r3 - 30) = r10 // BPF_STX | BPF_DW
50 // CHECK-
64: 73 70 00 00 00 00 00 00 *(u8
*)(r0 + 0) = r7
51 // CHECK-
64: 6b 81 08 00 00 00 00 00 *(u16
*)(r1 + 8) = r8
52 // CHECK-
64: 63 92 10 00 00 00 00 00 *(u32
*)(r2 + 16) = r9
53 // CHECK-
32: 73 70 00 00 00 00 00 00 *(u8
*)(r0 + 0) = w7
54 // CHECK-
32: 6b 81 08 00 00 00 00 00 *(u16
*)(r1 + 8) = w8
55 // CHECK-
32: 63 92 10 00 00 00 00 00 *(u32
*)(r2 + 16) = w9
56 // CHECK
: 7b a3 e2 ff
00 00 00 00 *(u64
*)(r3 - 30) = r10
58 lock
*(u32
*)(r2 + 16) += r9 // BPF_STX | BPF_W | BPF_XADD
59 lock
*(u64
*)(r3 - 30) += r10 // BPF_STX | BPF_DW | BPF_XADD
60 // CHECK-
64: c3
92 10 00 00 00 00 00 lock
*(u32
*)(r2 + 16) += r9
61 // CHECK-
32: c3
92 10 00 00 00 00 00 lock
*(u32
*)(r2 + 16) += w9
62 // CHECK
: db a3 e2 ff
00 00 00 00 lock
*(u64
*)(r3 - 30) += r10
64 // ======== BPF_JMP Class
========
65 goto Llabel0
// BPF_JA
68 // CHECK
: 05 00 1a 00 00 00 00 00 goto
+26
69 // CHECK
: 85 00 00 00 01 00 00 00 call
1
70 // CHECK
: 95 00 00 00 00 00 00 00 exit
72 if
r0 == r1 goto Llabel0
// BPF_JEQ | BPF_X
73 if
r3 != r4 goto Llabel0
// BPF_JNE | BPF_X
74 // CHECK
: 1d
10 17 00 00 00 00 00 if
r0 == r1 goto
+23
75 // CHECK
: 5d
43 16 00 00 00 00 00 if
r3 != r4 goto
+22
77 if
r1 > r2 goto Llabel0
// BPF_JGT | BPF_X
78 if
r2 >= r3 goto Llabel0
// BPF_JGE | BPF_X
79 if
r4 s
> r5 goto Llabel0
// BPF_JSGT | BPF_X
80 if
r5 s
>= r6 goto Llabel0
// BPF_JSGE | BPF_X
81 // CHECK
: 2d
21 15 00 00 00 00 00 if
r1 > r2 goto
+21
82 // CHECK
: 3d
32 14 00 00 00 00 00 if
r2 >= r3 goto
+20
83 // CHECK
: 6d
54 13 00 00 00 00 00 if
r4 s
> r5 goto
+19
84 // CHECK
: 7d
65 12 00 00 00 00 00 if
r5 s
>= r6 goto
+18
86 if
r6 < r7 goto Llabel0
// BPF_JLT | BPF_X
87 if
r7 <= r8 goto Llabel0
// BPF_JLE | BPF_X
88 if
r8 s
< r9 goto Llabel0
// BPF_JSLT | BPF_X
89 if
r9 s
<= r10 goto Llabel0
// BPF_JSLE | BPF_X
90 // CHECK
: ad
76 11 00 00 00 00 00 if
r6 < r7 goto
+17
91 // CHECK
: bd
87 10 00 00 00 00 00 if
r7 <= r8 goto
+16
92 // CHECK
: cd
98 0f
00 00 00 00 00 if
r8 s
< r9 goto
+15
93 // CHECK
: dd a9
0e
00 00 00 00 00 if
r9 s
<= r10 goto
+14
95 if
r0 == 0 goto Llabel0
// BPF_JEQ | BPF_K
96 if
r3 != -1 goto Llabel0
// BPF_JNE | BPF_K
97 // CHECK
: 15 00 0d
00 00 00 00 00 if
r0 == 0 goto
+13
98 // CHECK
: 55 03 0c
00 ff ff ff ff if
r3 != -1 goto
+12
100 if
r1 > 64 goto Llabel0
// BPF_JGT | BPF_K
101 if
r2 >= 0xffffffff goto Llabel0
// BPF_JGE | BPF_K
102 if
r4 s
> 0xffffffff goto Llabel0
// BPF_JSGT | BPF_K
103 if
r5 s
>= 0x7fffffff goto Llabel0
// BPF_JSGE | BPF_K
104 // CHECK
: 25 01 0b 00 40 00 00 00 if
r1 > 64 goto
+11
105 // CHECK
: 35 02 0a 00 ff ff ff ff if
r2 >= -1 goto
+10
106 // CHECK
: 65 04 09 00 ff ff ff ff if
r4 s
> -1 goto
+9
107 // CHECK
: 75 05 08 00 ff ff ff
7f if
r5 s
>= 2147483647 goto
+8
109 if
r6 < 0xff goto Llabel0
// BPF_JLT | BPF_K
110 if
r7 <= 0xffff goto Llabel0
// BPF_JLE | BPF_K
111 if
r8 s
< 0 goto Llabel0
// BPF_JSLT | BPF_K
112 if
r9 s
<= -1 goto Llabel0
// BPF_JSLE | BPF_K
113 // CHECK
: a5
06 07 00 ff
00 00 00 if
r6 < 255 goto
+7
114 // CHECK
: b5
07 06 00 ff ff
00 00 if
r7 <= 65535 goto
+6
115 // CHECK
: c5
08 05 00 00 00 00 00 if
r8 s
< 0 goto
+5
116 // CHECK
: d5
09 04 00 ff ff ff ff if
r9 s
<= -1 goto
+4
118 // ======== BPF_ALU64 Class
========
119 r0 += r1 // BPF_ADD | BPF_X
120 r1 -= r2 // BPF_SUB | BPF_X
121 r2 *= r3 // BPF_MUL | BPF_X
122 r3 /= r4 // BPF_DIV | BPF_X
123 // CHECK
: 0f
10 00 00 00 00 00 00 r0 += r1
124 // CHECK
: 1f
21 00 00 00 00 00 00 r1 -= r2
125 // CHECK
: 2f
32 00 00 00 00 00 00 r2 *= r3
126 // CHECK
: 3f
43 00 00 00 00 00 00 r3 /= r4
130 r4 |
= r5 // BPF_OR | BPF_X
131 r5 &= r6 // BPF_AND | BPF_X
132 r6 <<= r7 // BPF_LSH | BPF_X
133 r7 >>= r8 // BPF_RSH | BPF_X
134 r8 ^
= r9 // BPF_XOR | BPF_X
135 r9 = r10 // BPF_MOV | BPF_X
136 r10 s
>>= r0 // BPF_ARSH | BPF_X
138 // CHECK
: 87 02 00 00 00 00 00 00 r2 = -r2
139 // CHECK
: 4f
54 00 00 00 00 00 00 r4 |
= r5
140 // CHECK
: 5f
65 00 00 00 00 00 00 r5 &= r6
141 // CHECK
: 6f
76 00 00 00 00 00 00 r6 <<= r7
142 // CHECK
: 7f
87 00 00 00 00 00 00 r7 >>= r8
143 // CHECK
: af
98 00 00 00 00 00 00 r8 ^
= r9
144 // CHECK
: bf a9
00 00 00 00 00 00 r9 = r10
145 // CHECK
: cf
0a 00 00 00 00 00 00 r10 s
>>= r0
147 r1 = be16
r1 // BPF_END | BPF_TO_BE
148 r2 = be32
r2 // BPF_END | BPF_TO_BE
149 r3 = be64
r3 // BPF_END | BPF_TO_BE
150 // CHECK
: dc
01 00 00 10 00 00 00 r1 = be16
r1
151 // CHECK
: dc
02 00 00 20 00 00 00 r2 = be32
r2
152 // CHECK
: dc
03 00 00 40 00 00 00 r3 = be64
r3
154 r0 += 1 // BPF_ADD | BPF_K
155 r1 -= 0x1 // BPF_SUB | BPF_K
156 r2 *= -4 // BPF_MUL | BPF_K
157 r3 /= 5 // BPF_DIV | BPF_K
158 // CHECK
: 07 00 00 00 01 00 00 00 r0 += 1
159 // CHECK
: 17 01 00 00 01 00 00 00 r1 -= 1
160 // CHECK
: 27 02 00 00 fc ff ff ff
r2 *= -4
161 // CHECK
: 37 03 00 00 05 00 00 00 r3 /= 5
163 r4 |
= 0xff // BPF_OR | BPF_K
164 r5 &= 0xFF // BPF_AND | BPF_K
165 r6 <<= 63 // BPF_LSH | BPF_K
166 r7 >>= 32 // BPF_RSH | BPF_K
167 r8 ^
= 0 // BPF_XOR | BPF_K
168 r9 = 1 // BPF_MOV | BPF_K
169 r9 = 0xffffffff // BPF_MOV | BPF_K
170 r10 s
>>= 64 // BPF_ARSH | BPF_K
171 // CHECK
: 47 04 00 00 ff
00 00 00 r4 |
= 255
172 // CHECK
: 57 05 00 00 ff
00 00 00 r5 &= 255
173 // CHECK
: 67 06 00 00 3f
00 00 00 r6 <<= 63
174 // CHECK
: 77 07 00 00 20 00 00 00 r7 >>= 32
175 // CHECK
: a7
08 00 00 00 00 00 00 r8 ^
= 0
176 // CHECK
: b7
09 00 00 01 00 00 00 r9 = 1
177 // CHECK
: b7
09 00 00 ff ff ff ff
r9 = -1
178 // CHECK
: c7
0a 00 00 40 00 00 00 r10 s
>>= 64