1*fae6e9adSlinfeng // SPDX-License-Identifier: (Apache-2.0 OR MIT)
2*fae6e9adSlinfeng
3*fae6e9adSlinfeng #![allow(clippy::unreadable_literal)]
4*fae6e9adSlinfeng #![cfg(feature = "cranelift")]
5*fae6e9adSlinfeng
6*fae6e9adSlinfeng extern crate rbpf;
7*fae6e9adSlinfeng mod common;
8*fae6e9adSlinfeng
9*fae6e9adSlinfeng use rbpf::{assembler::assemble, helpers};
10*fae6e9adSlinfeng
11*fae6e9adSlinfeng use crate::common::{TCP_SACK_ASM, TCP_SACK_MATCH, TCP_SACK_NOMATCH};
12*fae6e9adSlinfeng
13*fae6e9adSlinfeng macro_rules! test_cranelift {
14*fae6e9adSlinfeng ($name:ident, $prog:expr, $expected:expr) => {
15*fae6e9adSlinfeng #[test]
16*fae6e9adSlinfeng fn $name() {
17*fae6e9adSlinfeng let prog = assemble($prog).unwrap();
18*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmNoData::new(Some(&prog)).unwrap();
19*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
20*fae6e9adSlinfeng assert_eq!(vm.execute_program_cranelift().unwrap(), $expected);
21*fae6e9adSlinfeng }
22*fae6e9adSlinfeng };
23*fae6e9adSlinfeng ($name:ident, $prog:expr, $mem:expr, $expected:expr) => {
24*fae6e9adSlinfeng #[test]
25*fae6e9adSlinfeng fn $name() {
26*fae6e9adSlinfeng let prog = assemble($prog).unwrap();
27*fae6e9adSlinfeng let mem = &mut $mem;
28*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmRaw::new(Some(&prog)).unwrap();
29*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
30*fae6e9adSlinfeng assert_eq!(vm.execute_program_cranelift(mem).unwrap(), $expected);
31*fae6e9adSlinfeng }
32*fae6e9adSlinfeng };
33*fae6e9adSlinfeng }
34*fae6e9adSlinfeng
35*fae6e9adSlinfeng test_cranelift!(
36*fae6e9adSlinfeng test_cranelift_add,
37*fae6e9adSlinfeng "
38*fae6e9adSlinfeng mov32 r0, 0
39*fae6e9adSlinfeng mov32 r1, 2
40*fae6e9adSlinfeng add32 r0, 1
41*fae6e9adSlinfeng add32 r0, r1
42*fae6e9adSlinfeng exit
43*fae6e9adSlinfeng ",
44*fae6e9adSlinfeng 0x3
45*fae6e9adSlinfeng );
46*fae6e9adSlinfeng
47*fae6e9adSlinfeng test_cranelift!(
48*fae6e9adSlinfeng test_cranelift_alu64_arith,
49*fae6e9adSlinfeng "
50*fae6e9adSlinfeng mov r0, 0
51*fae6e9adSlinfeng mov r1, 1
52*fae6e9adSlinfeng mov r2, 2
53*fae6e9adSlinfeng mov r3, 3
54*fae6e9adSlinfeng mov r4, 4
55*fae6e9adSlinfeng mov r5, 5
56*fae6e9adSlinfeng mov r6, 6
57*fae6e9adSlinfeng mov r7, 7
58*fae6e9adSlinfeng mov r8, 8
59*fae6e9adSlinfeng mov r9, 9
60*fae6e9adSlinfeng add r0, 23
61*fae6e9adSlinfeng add r0, r7
62*fae6e9adSlinfeng sub r0, 13
63*fae6e9adSlinfeng sub r0, r1
64*fae6e9adSlinfeng mul r0, 7
65*fae6e9adSlinfeng mul r0, r3
66*fae6e9adSlinfeng div r0, 2
67*fae6e9adSlinfeng div r0, r4
68*fae6e9adSlinfeng exit
69*fae6e9adSlinfeng ",
70*fae6e9adSlinfeng 0x2a
71*fae6e9adSlinfeng );
72*fae6e9adSlinfeng
73*fae6e9adSlinfeng test_cranelift!(
74*fae6e9adSlinfeng test_cranelift_alu64_bit,
75*fae6e9adSlinfeng "
76*fae6e9adSlinfeng mov r0, 0
77*fae6e9adSlinfeng mov r1, 1
78*fae6e9adSlinfeng mov r2, 2
79*fae6e9adSlinfeng mov r3, 3
80*fae6e9adSlinfeng mov r4, 4
81*fae6e9adSlinfeng mov r5, 5
82*fae6e9adSlinfeng mov r6, 6
83*fae6e9adSlinfeng mov r7, 7
84*fae6e9adSlinfeng mov r8, 8
85*fae6e9adSlinfeng or r0, r5
86*fae6e9adSlinfeng or r0, 0xa0
87*fae6e9adSlinfeng and r0, 0xa3
88*fae6e9adSlinfeng mov r9, 0x91
89*fae6e9adSlinfeng and r0, r9
90*fae6e9adSlinfeng lsh r0, 32
91*fae6e9adSlinfeng lsh r0, 22
92*fae6e9adSlinfeng lsh r0, r8
93*fae6e9adSlinfeng rsh r0, 32
94*fae6e9adSlinfeng rsh r0, 19
95*fae6e9adSlinfeng rsh r0, r7
96*fae6e9adSlinfeng xor r0, 0x03
97*fae6e9adSlinfeng xor r0, r2
98*fae6e9adSlinfeng exit
99*fae6e9adSlinfeng ",
100*fae6e9adSlinfeng 0x11
101*fae6e9adSlinfeng );
102*fae6e9adSlinfeng
103*fae6e9adSlinfeng test_cranelift!(
104*fae6e9adSlinfeng test_cranelift_alu_arith,
105*fae6e9adSlinfeng "
106*fae6e9adSlinfeng mov32 r0, 0
107*fae6e9adSlinfeng mov32 r1, 1
108*fae6e9adSlinfeng mov32 r2, 2
109*fae6e9adSlinfeng mov32 r3, 3
110*fae6e9adSlinfeng mov32 r4, 4
111*fae6e9adSlinfeng mov32 r5, 5
112*fae6e9adSlinfeng mov32 r6, 6
113*fae6e9adSlinfeng mov32 r7, 7
114*fae6e9adSlinfeng mov32 r8, 8
115*fae6e9adSlinfeng mov32 r9, 9
116*fae6e9adSlinfeng add32 r0, 23
117*fae6e9adSlinfeng add32 r0, r7
118*fae6e9adSlinfeng sub32 r0, 13
119*fae6e9adSlinfeng sub32 r0, r1
120*fae6e9adSlinfeng mul32 r0, 7
121*fae6e9adSlinfeng mul32 r0, r3
122*fae6e9adSlinfeng div32 r0, 2
123*fae6e9adSlinfeng div32 r0, r4
124*fae6e9adSlinfeng exit
125*fae6e9adSlinfeng ",
126*fae6e9adSlinfeng 0x2a
127*fae6e9adSlinfeng );
128*fae6e9adSlinfeng
129*fae6e9adSlinfeng test_cranelift!(
130*fae6e9adSlinfeng test_cranelift_alu_bit,
131*fae6e9adSlinfeng "
132*fae6e9adSlinfeng mov32 r0, 0
133*fae6e9adSlinfeng mov32 r1, 1
134*fae6e9adSlinfeng mov32 r2, 2
135*fae6e9adSlinfeng mov32 r3, 3
136*fae6e9adSlinfeng mov32 r4, 4
137*fae6e9adSlinfeng mov32 r5, 5
138*fae6e9adSlinfeng mov32 r6, 6
139*fae6e9adSlinfeng mov32 r7, 7
140*fae6e9adSlinfeng mov32 r8, 8
141*fae6e9adSlinfeng or32 r0, r5
142*fae6e9adSlinfeng or32 r0, 0xa0
143*fae6e9adSlinfeng and32 r0, 0xa3
144*fae6e9adSlinfeng mov32 r9, 0x91
145*fae6e9adSlinfeng and32 r0, r9
146*fae6e9adSlinfeng lsh32 r0, 22
147*fae6e9adSlinfeng lsh32 r0, r8
148*fae6e9adSlinfeng rsh32 r0, 19
149*fae6e9adSlinfeng rsh32 r0, r7
150*fae6e9adSlinfeng xor32 r0, 0x03
151*fae6e9adSlinfeng xor32 r0, r2
152*fae6e9adSlinfeng exit
153*fae6e9adSlinfeng ",
154*fae6e9adSlinfeng 0x11
155*fae6e9adSlinfeng );
156*fae6e9adSlinfeng
157*fae6e9adSlinfeng test_cranelift!(
158*fae6e9adSlinfeng test_cranelift_arsh32_high_shift,
159*fae6e9adSlinfeng "
160*fae6e9adSlinfeng mov r0, 8
161*fae6e9adSlinfeng lddw r1, 0x100000001
162*fae6e9adSlinfeng arsh32 r0, r1
163*fae6e9adSlinfeng exit
164*fae6e9adSlinfeng ",
165*fae6e9adSlinfeng 0x4
166*fae6e9adSlinfeng );
167*fae6e9adSlinfeng
168*fae6e9adSlinfeng test_cranelift!(
169*fae6e9adSlinfeng test_cranelift_arsh,
170*fae6e9adSlinfeng "
171*fae6e9adSlinfeng mov32 r0, 0xf8
172*fae6e9adSlinfeng lsh32 r0, 28
173*fae6e9adSlinfeng arsh32 r0, 16
174*fae6e9adSlinfeng exit
175*fae6e9adSlinfeng ",
176*fae6e9adSlinfeng 0xffff8000
177*fae6e9adSlinfeng );
178*fae6e9adSlinfeng
179*fae6e9adSlinfeng test_cranelift!(
180*fae6e9adSlinfeng test_cranelift_arsh64,
181*fae6e9adSlinfeng "
182*fae6e9adSlinfeng mov32 r0, 1
183*fae6e9adSlinfeng lsh r0, 63
184*fae6e9adSlinfeng arsh r0, 55
185*fae6e9adSlinfeng mov32 r1, 5
186*fae6e9adSlinfeng arsh r0, r1
187*fae6e9adSlinfeng exit
188*fae6e9adSlinfeng ",
189*fae6e9adSlinfeng 0xfffffffffffffff8
190*fae6e9adSlinfeng );
191*fae6e9adSlinfeng
192*fae6e9adSlinfeng test_cranelift!(
193*fae6e9adSlinfeng test_cranelift_arsh_reg,
194*fae6e9adSlinfeng "
195*fae6e9adSlinfeng mov32 r0, 0xf8
196*fae6e9adSlinfeng mov32 r1, 16
197*fae6e9adSlinfeng lsh32 r0, 28
198*fae6e9adSlinfeng arsh32 r0, r1
199*fae6e9adSlinfeng exit
200*fae6e9adSlinfeng ",
201*fae6e9adSlinfeng 0xffff8000
202*fae6e9adSlinfeng );
203*fae6e9adSlinfeng
204*fae6e9adSlinfeng test_cranelift!(
205*fae6e9adSlinfeng test_cranelift_be16,
206*fae6e9adSlinfeng "
207*fae6e9adSlinfeng ldxh r0, [r1]
208*fae6e9adSlinfeng be16 r0
209*fae6e9adSlinfeng exit
210*fae6e9adSlinfeng ",
211*fae6e9adSlinfeng [0x11, 0x22],
212*fae6e9adSlinfeng 0x1122
213*fae6e9adSlinfeng );
214*fae6e9adSlinfeng
215*fae6e9adSlinfeng test_cranelift!(
216*fae6e9adSlinfeng test_cranelift_be16_high,
217*fae6e9adSlinfeng "
218*fae6e9adSlinfeng ldxdw r0, [r1]
219*fae6e9adSlinfeng be16 r0
220*fae6e9adSlinfeng exit
221*fae6e9adSlinfeng ",
222*fae6e9adSlinfeng [0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88],
223*fae6e9adSlinfeng 0x1122
224*fae6e9adSlinfeng );
225*fae6e9adSlinfeng
226*fae6e9adSlinfeng test_cranelift!(
227*fae6e9adSlinfeng test_cranelift_be32,
228*fae6e9adSlinfeng "
229*fae6e9adSlinfeng ldxw r0, [r1]
230*fae6e9adSlinfeng be32 r0
231*fae6e9adSlinfeng exit
232*fae6e9adSlinfeng ",
233*fae6e9adSlinfeng [0x11, 0x22, 0x33, 0x44],
234*fae6e9adSlinfeng 0x11223344
235*fae6e9adSlinfeng );
236*fae6e9adSlinfeng
237*fae6e9adSlinfeng test_cranelift!(
238*fae6e9adSlinfeng test_cranelift_be32_high,
239*fae6e9adSlinfeng "
240*fae6e9adSlinfeng ldxdw r0, [r1]
241*fae6e9adSlinfeng be32 r0
242*fae6e9adSlinfeng exit
243*fae6e9adSlinfeng ",
244*fae6e9adSlinfeng [0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88],
245*fae6e9adSlinfeng 0x11223344
246*fae6e9adSlinfeng );
247*fae6e9adSlinfeng
248*fae6e9adSlinfeng test_cranelift!(
249*fae6e9adSlinfeng test_cranelift_be64,
250*fae6e9adSlinfeng "
251*fae6e9adSlinfeng ldxdw r0, [r1]
252*fae6e9adSlinfeng be64 r0
253*fae6e9adSlinfeng exit
254*fae6e9adSlinfeng ",
255*fae6e9adSlinfeng [0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88],
256*fae6e9adSlinfeng 0x1122334455667788
257*fae6e9adSlinfeng );
258*fae6e9adSlinfeng
259*fae6e9adSlinfeng #[test]
test_cranelift_call()260*fae6e9adSlinfeng fn test_cranelift_call() {
261*fae6e9adSlinfeng let prog = assemble(
262*fae6e9adSlinfeng "
263*fae6e9adSlinfeng mov r1, 1
264*fae6e9adSlinfeng mov r2, 2
265*fae6e9adSlinfeng mov r3, 3
266*fae6e9adSlinfeng mov r4, 4
267*fae6e9adSlinfeng mov r5, 5
268*fae6e9adSlinfeng call 0
269*fae6e9adSlinfeng exit",
270*fae6e9adSlinfeng )
271*fae6e9adSlinfeng .unwrap();
272*fae6e9adSlinfeng
273*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmNoData::new(Some(&prog)).unwrap();
274*fae6e9adSlinfeng vm.register_helper(0, helpers::gather_bytes).unwrap();
275*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
276*fae6e9adSlinfeng assert_eq!(vm.execute_program_cranelift().unwrap(), 0x0102030405);
277*fae6e9adSlinfeng }
278*fae6e9adSlinfeng
279*fae6e9adSlinfeng #[test]
280*fae6e9adSlinfeng #[should_panic(expected = "[CRANELIFT] Error: unknown helper function (id: 0x3f)")]
test_cranelift_err_call_unreg()281*fae6e9adSlinfeng fn test_cranelift_err_call_unreg() {
282*fae6e9adSlinfeng let prog = assemble(
283*fae6e9adSlinfeng "
284*fae6e9adSlinfeng mov r1, 1
285*fae6e9adSlinfeng mov r2, 2
286*fae6e9adSlinfeng mov r3, 3
287*fae6e9adSlinfeng mov r4, 4
288*fae6e9adSlinfeng mov r5, 5
289*fae6e9adSlinfeng call 63
290*fae6e9adSlinfeng exit
291*fae6e9adSlinfeng ",
292*fae6e9adSlinfeng )
293*fae6e9adSlinfeng .unwrap();
294*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmNoData::new(Some(&prog)).unwrap();
295*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
296*fae6e9adSlinfeng }
297*fae6e9adSlinfeng
298*fae6e9adSlinfeng #[test]
test_cranelift_call_memfrob()299*fae6e9adSlinfeng fn test_cranelift_call_memfrob() {
300*fae6e9adSlinfeng let prog = assemble(
301*fae6e9adSlinfeng "
302*fae6e9adSlinfeng mov r6, r1
303*fae6e9adSlinfeng add r1, 2
304*fae6e9adSlinfeng mov r2, 4
305*fae6e9adSlinfeng call 1
306*fae6e9adSlinfeng ldxdw r0, [r6]
307*fae6e9adSlinfeng be64 r0
308*fae6e9adSlinfeng exit",
309*fae6e9adSlinfeng )
310*fae6e9adSlinfeng .unwrap();
311*fae6e9adSlinfeng
312*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmRaw::new(Some(&prog)).unwrap();
313*fae6e9adSlinfeng vm.register_helper(1, helpers::memfrob).unwrap();
314*fae6e9adSlinfeng let mem = &mut [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08];
315*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
316*fae6e9adSlinfeng assert_eq!(
317*fae6e9adSlinfeng vm.execute_program_cranelift(mem).unwrap(),
318*fae6e9adSlinfeng 0x102292e2f2c0708
319*fae6e9adSlinfeng );
320*fae6e9adSlinfeng }
321*fae6e9adSlinfeng
322*fae6e9adSlinfeng test_cranelift!(
323*fae6e9adSlinfeng test_cranelift_div32_high_divisor,
324*fae6e9adSlinfeng "
325*fae6e9adSlinfeng mov r0, 12
326*fae6e9adSlinfeng lddw r1, 0x100000004
327*fae6e9adSlinfeng div32 r0, r1
328*fae6e9adSlinfeng exit
329*fae6e9adSlinfeng ",
330*fae6e9adSlinfeng 0x3
331*fae6e9adSlinfeng );
332*fae6e9adSlinfeng
333*fae6e9adSlinfeng test_cranelift!(
334*fae6e9adSlinfeng test_cranelift_div32_imm,
335*fae6e9adSlinfeng "
336*fae6e9adSlinfeng lddw r0, 0x10000000c
337*fae6e9adSlinfeng div32 r0, 4
338*fae6e9adSlinfeng exit
339*fae6e9adSlinfeng ",
340*fae6e9adSlinfeng 0x3
341*fae6e9adSlinfeng );
342*fae6e9adSlinfeng
343*fae6e9adSlinfeng test_cranelift!(
344*fae6e9adSlinfeng test_cranelift_div32_reg,
345*fae6e9adSlinfeng "
346*fae6e9adSlinfeng lddw r0, 0x10000000c
347*fae6e9adSlinfeng mov r1, 4
348*fae6e9adSlinfeng div32 r0, r1
349*fae6e9adSlinfeng exit
350*fae6e9adSlinfeng ",
351*fae6e9adSlinfeng 0x3
352*fae6e9adSlinfeng );
353*fae6e9adSlinfeng
354*fae6e9adSlinfeng test_cranelift!(
355*fae6e9adSlinfeng test_cranelift_div64_imm,
356*fae6e9adSlinfeng "
357*fae6e9adSlinfeng mov r0, 0xc
358*fae6e9adSlinfeng lsh r0, 32
359*fae6e9adSlinfeng div r0, 4
360*fae6e9adSlinfeng exit
361*fae6e9adSlinfeng ",
362*fae6e9adSlinfeng 0x300000000
363*fae6e9adSlinfeng );
364*fae6e9adSlinfeng
365*fae6e9adSlinfeng test_cranelift!(
366*fae6e9adSlinfeng test_cranelift_div64_reg,
367*fae6e9adSlinfeng "
368*fae6e9adSlinfeng mov r0, 0xc
369*fae6e9adSlinfeng lsh r0, 32
370*fae6e9adSlinfeng mov r1, 4
371*fae6e9adSlinfeng div r0, r1
372*fae6e9adSlinfeng exit
373*fae6e9adSlinfeng ",
374*fae6e9adSlinfeng 0x300000000
375*fae6e9adSlinfeng );
376*fae6e9adSlinfeng
377*fae6e9adSlinfeng test_cranelift!(
378*fae6e9adSlinfeng test_cranelift_early_exit,
379*fae6e9adSlinfeng "
380*fae6e9adSlinfeng mov r0, 3
381*fae6e9adSlinfeng exit
382*fae6e9adSlinfeng mov r0, 4
383*fae6e9adSlinfeng exit
384*fae6e9adSlinfeng ",
385*fae6e9adSlinfeng 0x3
386*fae6e9adSlinfeng );
387*fae6e9adSlinfeng
388*fae6e9adSlinfeng test_cranelift!(
389*fae6e9adSlinfeng test_cranelift_div64_by_zero_imm,
390*fae6e9adSlinfeng "
391*fae6e9adSlinfeng mov32 r0, 1
392*fae6e9adSlinfeng div r0, 0
393*fae6e9adSlinfeng exit
394*fae6e9adSlinfeng ",
395*fae6e9adSlinfeng 0x0
396*fae6e9adSlinfeng );
397*fae6e9adSlinfeng
398*fae6e9adSlinfeng test_cranelift!(
399*fae6e9adSlinfeng test_cranelift_div_by_zero_imm,
400*fae6e9adSlinfeng "
401*fae6e9adSlinfeng mov32 r0, 1
402*fae6e9adSlinfeng div32 r0, 0
403*fae6e9adSlinfeng exit
404*fae6e9adSlinfeng ",
405*fae6e9adSlinfeng 0x0
406*fae6e9adSlinfeng );
407*fae6e9adSlinfeng
408*fae6e9adSlinfeng test_cranelift!(
409*fae6e9adSlinfeng test_cranelift_mod64_by_zero_imm,
410*fae6e9adSlinfeng "
411*fae6e9adSlinfeng mov32 r0, 1
412*fae6e9adSlinfeng mod r0, 0
413*fae6e9adSlinfeng exit
414*fae6e9adSlinfeng ",
415*fae6e9adSlinfeng 0x1
416*fae6e9adSlinfeng );
417*fae6e9adSlinfeng
418*fae6e9adSlinfeng test_cranelift!(
419*fae6e9adSlinfeng test_cranelift_mod_by_zero_imm,
420*fae6e9adSlinfeng "
421*fae6e9adSlinfeng mov32 r0, 1
422*fae6e9adSlinfeng mod32 r0, 0
423*fae6e9adSlinfeng exit
424*fae6e9adSlinfeng ",
425*fae6e9adSlinfeng 0x1
426*fae6e9adSlinfeng );
427*fae6e9adSlinfeng
428*fae6e9adSlinfeng test_cranelift!(
429*fae6e9adSlinfeng test_cranelift_div64_by_zero_reg,
430*fae6e9adSlinfeng "
431*fae6e9adSlinfeng mov32 r0, 1
432*fae6e9adSlinfeng mov32 r1, 0
433*fae6e9adSlinfeng div r0, r1
434*fae6e9adSlinfeng exit
435*fae6e9adSlinfeng ",
436*fae6e9adSlinfeng 0x0
437*fae6e9adSlinfeng );
438*fae6e9adSlinfeng
439*fae6e9adSlinfeng test_cranelift!(
440*fae6e9adSlinfeng test_cranelift_div_by_zero_reg,
441*fae6e9adSlinfeng "
442*fae6e9adSlinfeng mov32 r0, 1
443*fae6e9adSlinfeng mov32 r1, 0
444*fae6e9adSlinfeng div32 r0, r1
445*fae6e9adSlinfeng exit
446*fae6e9adSlinfeng ",
447*fae6e9adSlinfeng 0x0
448*fae6e9adSlinfeng );
449*fae6e9adSlinfeng
450*fae6e9adSlinfeng test_cranelift!(
451*fae6e9adSlinfeng test_cranelift_mod64_by_zero_reg,
452*fae6e9adSlinfeng "
453*fae6e9adSlinfeng mov32 r0, 1
454*fae6e9adSlinfeng mov32 r1, 0
455*fae6e9adSlinfeng mod r0, r1
456*fae6e9adSlinfeng exit
457*fae6e9adSlinfeng ",
458*fae6e9adSlinfeng 0x1
459*fae6e9adSlinfeng );
460*fae6e9adSlinfeng
461*fae6e9adSlinfeng test_cranelift!(
462*fae6e9adSlinfeng test_cranelift_mod_by_zero_reg,
463*fae6e9adSlinfeng "
464*fae6e9adSlinfeng mov32 r0, 1
465*fae6e9adSlinfeng mov32 r1, 0
466*fae6e9adSlinfeng mod32 r0, r1
467*fae6e9adSlinfeng exit
468*fae6e9adSlinfeng ",
469*fae6e9adSlinfeng 0x1
470*fae6e9adSlinfeng );
471*fae6e9adSlinfeng
472*fae6e9adSlinfeng #[test]
473*fae6e9adSlinfeng // #[should_panic(expected = "Error: out of bounds memory store (insn #1)")]
474*fae6e9adSlinfeng #[ignore = "We have stack OOB checks, but we don't yet catch the trap code and convert it into a panic"]
test_cranelift_err_stack_out_of_bound()475*fae6e9adSlinfeng fn test_cranelift_err_stack_out_of_bound() {
476*fae6e9adSlinfeng let prog = [
477*fae6e9adSlinfeng 0x72, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
478*fae6e9adSlinfeng 0x00,
479*fae6e9adSlinfeng ];
480*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmNoData::new(Some(&prog)).unwrap();
481*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
482*fae6e9adSlinfeng vm.execute_program_cranelift().unwrap();
483*fae6e9adSlinfeng }
484*fae6e9adSlinfeng
485*fae6e9adSlinfeng test_cranelift!(
486*fae6e9adSlinfeng test_cranelift_exit,
487*fae6e9adSlinfeng "
488*fae6e9adSlinfeng mov r0, 0
489*fae6e9adSlinfeng exit
490*fae6e9adSlinfeng ",
491*fae6e9adSlinfeng 0x0
492*fae6e9adSlinfeng );
493*fae6e9adSlinfeng
494*fae6e9adSlinfeng test_cranelift!(
495*fae6e9adSlinfeng test_cranelift_ja,
496*fae6e9adSlinfeng "
497*fae6e9adSlinfeng mov r0, 1
498*fae6e9adSlinfeng ja +1
499*fae6e9adSlinfeng mov r0, 2
500*fae6e9adSlinfeng exit
501*fae6e9adSlinfeng ",
502*fae6e9adSlinfeng 0x1
503*fae6e9adSlinfeng );
504*fae6e9adSlinfeng
505*fae6e9adSlinfeng test_cranelift!(
506*fae6e9adSlinfeng test_cranelift_jeq_imm,
507*fae6e9adSlinfeng "
508*fae6e9adSlinfeng mov32 r0, 0
509*fae6e9adSlinfeng mov32 r1, 0xa
510*fae6e9adSlinfeng jeq r1, 0xb, +4
511*fae6e9adSlinfeng mov32 r0, 1
512*fae6e9adSlinfeng mov32 r1, 0xb
513*fae6e9adSlinfeng jeq r1, 0xb, +1
514*fae6e9adSlinfeng mov32 r0, 2
515*fae6e9adSlinfeng exit
516*fae6e9adSlinfeng ",
517*fae6e9adSlinfeng 0x1
518*fae6e9adSlinfeng );
519*fae6e9adSlinfeng
520*fae6e9adSlinfeng test_cranelift!(
521*fae6e9adSlinfeng test_cranelift_jeq_reg,
522*fae6e9adSlinfeng "
523*fae6e9adSlinfeng mov32 r0, 0
524*fae6e9adSlinfeng mov32 r1, 0xa
525*fae6e9adSlinfeng mov32 r2, 0xb
526*fae6e9adSlinfeng jeq r1, r2, +4
527*fae6e9adSlinfeng mov32 r0, 1
528*fae6e9adSlinfeng mov32 r1, 0xb
529*fae6e9adSlinfeng jeq r1, r2, +1
530*fae6e9adSlinfeng mov32 r0, 2
531*fae6e9adSlinfeng exit
532*fae6e9adSlinfeng ",
533*fae6e9adSlinfeng 0x1
534*fae6e9adSlinfeng );
535*fae6e9adSlinfeng
536*fae6e9adSlinfeng test_cranelift!(
537*fae6e9adSlinfeng test_cranelift_jge_imm,
538*fae6e9adSlinfeng "
539*fae6e9adSlinfeng mov32 r0, 0
540*fae6e9adSlinfeng mov32 r1, 0xa
541*fae6e9adSlinfeng jge r1, 0xb, +4
542*fae6e9adSlinfeng mov32 r0, 1
543*fae6e9adSlinfeng mov32 r1, 0xc
544*fae6e9adSlinfeng jge r1, 0xb, +1
545*fae6e9adSlinfeng mov32 r0, 2
546*fae6e9adSlinfeng exit
547*fae6e9adSlinfeng ",
548*fae6e9adSlinfeng 0x1
549*fae6e9adSlinfeng );
550*fae6e9adSlinfeng
551*fae6e9adSlinfeng test_cranelift!(
552*fae6e9adSlinfeng test_cranelift_jle_imm,
553*fae6e9adSlinfeng "
554*fae6e9adSlinfeng mov32 r0, 0
555*fae6e9adSlinfeng mov32 r1, 5
556*fae6e9adSlinfeng jle r1, 4, +1
557*fae6e9adSlinfeng jle r1, 6, +1
558*fae6e9adSlinfeng exit
559*fae6e9adSlinfeng jle r1, 5, +1
560*fae6e9adSlinfeng exit
561*fae6e9adSlinfeng mov32 r0, 1
562*fae6e9adSlinfeng exit
563*fae6e9adSlinfeng ",
564*fae6e9adSlinfeng 0x1
565*fae6e9adSlinfeng );
566*fae6e9adSlinfeng
567*fae6e9adSlinfeng test_cranelift!(
568*fae6e9adSlinfeng test_cranelift_jle_reg,
569*fae6e9adSlinfeng "
570*fae6e9adSlinfeng mov r0, 0
571*fae6e9adSlinfeng mov r1, 5
572*fae6e9adSlinfeng mov r2, 4
573*fae6e9adSlinfeng mov r3, 6
574*fae6e9adSlinfeng jle r1, r2, +2
575*fae6e9adSlinfeng jle r1, r1, +1
576*fae6e9adSlinfeng exit
577*fae6e9adSlinfeng jle r1, r3, +1
578*fae6e9adSlinfeng exit
579*fae6e9adSlinfeng mov r0, 1
580*fae6e9adSlinfeng exit
581*fae6e9adSlinfeng ",
582*fae6e9adSlinfeng 0x1
583*fae6e9adSlinfeng );
584*fae6e9adSlinfeng
585*fae6e9adSlinfeng test_cranelift!(
586*fae6e9adSlinfeng test_cranelift_jgt_imm,
587*fae6e9adSlinfeng "
588*fae6e9adSlinfeng mov32 r0, 0
589*fae6e9adSlinfeng mov32 r1, 5
590*fae6e9adSlinfeng jgt r1, 6, +2
591*fae6e9adSlinfeng jgt r1, 5, +1
592*fae6e9adSlinfeng jgt r1, 4, +1
593*fae6e9adSlinfeng exit
594*fae6e9adSlinfeng mov32 r0, 1
595*fae6e9adSlinfeng exit
596*fae6e9adSlinfeng ",
597*fae6e9adSlinfeng 0x1
598*fae6e9adSlinfeng );
599*fae6e9adSlinfeng
600*fae6e9adSlinfeng test_cranelift!(
601*fae6e9adSlinfeng test_cranelift_jgt_reg,
602*fae6e9adSlinfeng "
603*fae6e9adSlinfeng mov r0, 0
604*fae6e9adSlinfeng mov r1, 5
605*fae6e9adSlinfeng mov r2, 6
606*fae6e9adSlinfeng mov r3, 4
607*fae6e9adSlinfeng jgt r1, r2, +2
608*fae6e9adSlinfeng jgt r1, r1, +1
609*fae6e9adSlinfeng jgt r1, r3, +1
610*fae6e9adSlinfeng exit
611*fae6e9adSlinfeng mov r0, 1
612*fae6e9adSlinfeng exit
613*fae6e9adSlinfeng ",
614*fae6e9adSlinfeng 0x1
615*fae6e9adSlinfeng );
616*fae6e9adSlinfeng
617*fae6e9adSlinfeng test_cranelift!(
618*fae6e9adSlinfeng test_cranelift_jlt_imm,
619*fae6e9adSlinfeng "
620*fae6e9adSlinfeng mov32 r0, 0
621*fae6e9adSlinfeng mov32 r1, 5
622*fae6e9adSlinfeng jlt r1, 4, +2
623*fae6e9adSlinfeng jlt r1, 5, +1
624*fae6e9adSlinfeng jlt r1, 6, +1
625*fae6e9adSlinfeng exit
626*fae6e9adSlinfeng mov32 r0, 1
627*fae6e9adSlinfeng exit
628*fae6e9adSlinfeng ",
629*fae6e9adSlinfeng 0x1
630*fae6e9adSlinfeng );
631*fae6e9adSlinfeng
632*fae6e9adSlinfeng test_cranelift!(
633*fae6e9adSlinfeng test_cranelift_jlt_reg,
634*fae6e9adSlinfeng "
635*fae6e9adSlinfeng mov r0, 0
636*fae6e9adSlinfeng mov r1, 5
637*fae6e9adSlinfeng mov r2, 4
638*fae6e9adSlinfeng mov r3, 6
639*fae6e9adSlinfeng jlt r1, r2, +2
640*fae6e9adSlinfeng jlt r1, r1, +1
641*fae6e9adSlinfeng jlt r1, r3, +1
642*fae6e9adSlinfeng exit
643*fae6e9adSlinfeng mov r0, 1
644*fae6e9adSlinfeng exit
645*fae6e9adSlinfeng ",
646*fae6e9adSlinfeng 0x1
647*fae6e9adSlinfeng );
648*fae6e9adSlinfeng
649*fae6e9adSlinfeng test_cranelift!(
650*fae6e9adSlinfeng test_cranelift_jit_bounce,
651*fae6e9adSlinfeng "
652*fae6e9adSlinfeng mov r0, 1
653*fae6e9adSlinfeng mov r6, r0
654*fae6e9adSlinfeng mov r7, r6
655*fae6e9adSlinfeng mov r8, r7
656*fae6e9adSlinfeng mov r9, r8
657*fae6e9adSlinfeng mov r0, r9
658*fae6e9adSlinfeng exit
659*fae6e9adSlinfeng ",
660*fae6e9adSlinfeng 0x1
661*fae6e9adSlinfeng );
662*fae6e9adSlinfeng
663*fae6e9adSlinfeng test_cranelift!(
664*fae6e9adSlinfeng test_cranelift_jne_reg,
665*fae6e9adSlinfeng "
666*fae6e9adSlinfeng mov32 r0, 0
667*fae6e9adSlinfeng mov32 r1, 0xb
668*fae6e9adSlinfeng mov32 r2, 0xb
669*fae6e9adSlinfeng jne r1, r2, +4
670*fae6e9adSlinfeng mov32 r0, 1
671*fae6e9adSlinfeng mov32 r1, 0xa
672*fae6e9adSlinfeng jne r1, r2, +1
673*fae6e9adSlinfeng mov32 r0, 2
674*fae6e9adSlinfeng exit
675*fae6e9adSlinfeng ",
676*fae6e9adSlinfeng 0x1
677*fae6e9adSlinfeng );
678*fae6e9adSlinfeng
679*fae6e9adSlinfeng test_cranelift!(
680*fae6e9adSlinfeng test_cranelift_jset_imm,
681*fae6e9adSlinfeng "
682*fae6e9adSlinfeng mov32 r0, 0
683*fae6e9adSlinfeng mov32 r1, 0x7
684*fae6e9adSlinfeng jset r1, 0x8, +4
685*fae6e9adSlinfeng mov32 r0, 1
686*fae6e9adSlinfeng mov32 r1, 0x9
687*fae6e9adSlinfeng jset r1, 0x8, +1
688*fae6e9adSlinfeng mov32 r0, 2
689*fae6e9adSlinfeng exit
690*fae6e9adSlinfeng ",
691*fae6e9adSlinfeng 0x1
692*fae6e9adSlinfeng );
693*fae6e9adSlinfeng
694*fae6e9adSlinfeng test_cranelift!(
695*fae6e9adSlinfeng test_cranelift_jset_reg,
696*fae6e9adSlinfeng "
697*fae6e9adSlinfeng mov32 r0, 0
698*fae6e9adSlinfeng mov32 r1, 0x7
699*fae6e9adSlinfeng mov32 r2, 0x8
700*fae6e9adSlinfeng jset r1, r2, +4
701*fae6e9adSlinfeng mov32 r0, 1
702*fae6e9adSlinfeng mov32 r1, 0x9
703*fae6e9adSlinfeng jset r1, r2, +1
704*fae6e9adSlinfeng mov32 r0, 2
705*fae6e9adSlinfeng exit
706*fae6e9adSlinfeng ",
707*fae6e9adSlinfeng 0x1
708*fae6e9adSlinfeng );
709*fae6e9adSlinfeng
710*fae6e9adSlinfeng test_cranelift!(
711*fae6e9adSlinfeng test_cranelift_jsge_imm,
712*fae6e9adSlinfeng "
713*fae6e9adSlinfeng mov32 r0, 0
714*fae6e9adSlinfeng mov r1, -2
715*fae6e9adSlinfeng jsge r1, -1, +5
716*fae6e9adSlinfeng jsge r1, 0, +4
717*fae6e9adSlinfeng mov32 r0, 1
718*fae6e9adSlinfeng mov r1, -1
719*fae6e9adSlinfeng jsge r1, -1, +1
720*fae6e9adSlinfeng mov32 r0, 2
721*fae6e9adSlinfeng exit
722*fae6e9adSlinfeng ",
723*fae6e9adSlinfeng 0x1
724*fae6e9adSlinfeng );
725*fae6e9adSlinfeng
726*fae6e9adSlinfeng test_cranelift!(
727*fae6e9adSlinfeng test_cranelift_jsge_reg,
728*fae6e9adSlinfeng "
729*fae6e9adSlinfeng mov32 r0, 0
730*fae6e9adSlinfeng mov r1, -2
731*fae6e9adSlinfeng mov r2, -1
732*fae6e9adSlinfeng mov32 r3, 0
733*fae6e9adSlinfeng jsge r1, r2, +5
734*fae6e9adSlinfeng jsge r1, r3, +4
735*fae6e9adSlinfeng mov32 r0, 1
736*fae6e9adSlinfeng mov r1, r2
737*fae6e9adSlinfeng jsge r1, r2, +1
738*fae6e9adSlinfeng mov32 r0, 2
739*fae6e9adSlinfeng exit
740*fae6e9adSlinfeng ",
741*fae6e9adSlinfeng 0x1
742*fae6e9adSlinfeng );
743*fae6e9adSlinfeng
744*fae6e9adSlinfeng test_cranelift!(
745*fae6e9adSlinfeng test_cranelift_jsle_imm,
746*fae6e9adSlinfeng "
747*fae6e9adSlinfeng mov32 r0, 0
748*fae6e9adSlinfeng mov r1, -2
749*fae6e9adSlinfeng jsle r1, -3, +1
750*fae6e9adSlinfeng jsle r1, -1, +1
751*fae6e9adSlinfeng exit
752*fae6e9adSlinfeng mov32 r0, 1
753*fae6e9adSlinfeng jsle r1, -2, +1
754*fae6e9adSlinfeng mov32 r0, 2
755*fae6e9adSlinfeng exit
756*fae6e9adSlinfeng ",
757*fae6e9adSlinfeng 0x1
758*fae6e9adSlinfeng );
759*fae6e9adSlinfeng
760*fae6e9adSlinfeng test_cranelift!(
761*fae6e9adSlinfeng test_cranelift_jsle_reg,
762*fae6e9adSlinfeng "
763*fae6e9adSlinfeng mov32 r0, 0
764*fae6e9adSlinfeng mov r1, -1
765*fae6e9adSlinfeng mov r2, -2
766*fae6e9adSlinfeng mov32 r3, 0
767*fae6e9adSlinfeng jsle r1, r2, +1
768*fae6e9adSlinfeng jsle r1, r3, +1
769*fae6e9adSlinfeng exit
770*fae6e9adSlinfeng mov32 r0, 1
771*fae6e9adSlinfeng mov r1, r2
772*fae6e9adSlinfeng jsle r1, r2, +1
773*fae6e9adSlinfeng mov32 r0, 2
774*fae6e9adSlinfeng exit
775*fae6e9adSlinfeng ",
776*fae6e9adSlinfeng 0x1
777*fae6e9adSlinfeng );
778*fae6e9adSlinfeng
779*fae6e9adSlinfeng test_cranelift!(
780*fae6e9adSlinfeng test_cranelift_jsgt_imm,
781*fae6e9adSlinfeng "
782*fae6e9adSlinfeng mov32 r0, 0
783*fae6e9adSlinfeng mov r1, -2
784*fae6e9adSlinfeng jsgt r1, -1, +4
785*fae6e9adSlinfeng mov32 r0, 1
786*fae6e9adSlinfeng mov32 r1, 0
787*fae6e9adSlinfeng jsgt r1, -1, +1
788*fae6e9adSlinfeng mov32 r0, 2
789*fae6e9adSlinfeng exit
790*fae6e9adSlinfeng ",
791*fae6e9adSlinfeng 0x1
792*fae6e9adSlinfeng );
793*fae6e9adSlinfeng
794*fae6e9adSlinfeng test_cranelift!(
795*fae6e9adSlinfeng test_cranelift_jsgt_reg,
796*fae6e9adSlinfeng "
797*fae6e9adSlinfeng mov32 r0, 0
798*fae6e9adSlinfeng mov r1, -2
799*fae6e9adSlinfeng mov r2, -1
800*fae6e9adSlinfeng jsgt r1, r2, +4
801*fae6e9adSlinfeng mov32 r0, 1
802*fae6e9adSlinfeng mov32 r1, 0
803*fae6e9adSlinfeng jsgt r1, r2, +1
804*fae6e9adSlinfeng mov32 r0, 2
805*fae6e9adSlinfeng exit
806*fae6e9adSlinfeng ",
807*fae6e9adSlinfeng 0x1
808*fae6e9adSlinfeng );
809*fae6e9adSlinfeng
810*fae6e9adSlinfeng test_cranelift!(
811*fae6e9adSlinfeng test_cranelift_jslt_imm,
812*fae6e9adSlinfeng "
813*fae6e9adSlinfeng mov32 r0, 0
814*fae6e9adSlinfeng mov r1, -2
815*fae6e9adSlinfeng jslt r1, -3, +2
816*fae6e9adSlinfeng jslt r1, -2, +1
817*fae6e9adSlinfeng jslt r1, -1, +1
818*fae6e9adSlinfeng exit
819*fae6e9adSlinfeng mov32 r0, 1
820*fae6e9adSlinfeng exit
821*fae6e9adSlinfeng ",
822*fae6e9adSlinfeng 0x1
823*fae6e9adSlinfeng );
824*fae6e9adSlinfeng
825*fae6e9adSlinfeng test_cranelift!(
826*fae6e9adSlinfeng test_cranelift_jslt_reg,
827*fae6e9adSlinfeng "
828*fae6e9adSlinfeng mov32 r0, 0
829*fae6e9adSlinfeng mov r1, -2
830*fae6e9adSlinfeng mov r2, -3
831*fae6e9adSlinfeng mov r3, -1
832*fae6e9adSlinfeng jslt r1, r1, +2
833*fae6e9adSlinfeng jslt r1, r2, +1
834*fae6e9adSlinfeng jslt r1, r3, +1
835*fae6e9adSlinfeng exit
836*fae6e9adSlinfeng mov32 r0, 1
837*fae6e9adSlinfeng exit
838*fae6e9adSlinfeng ",
839*fae6e9adSlinfeng 0x1
840*fae6e9adSlinfeng );
841*fae6e9adSlinfeng
842*fae6e9adSlinfeng test_cranelift!(
843*fae6e9adSlinfeng test_cranelift_jeq32_imm,
844*fae6e9adSlinfeng "
845*fae6e9adSlinfeng mov r9, 1
846*fae6e9adSlinfeng lsh r9, 32
847*fae6e9adSlinfeng mov32 r0, 0x0
848*fae6e9adSlinfeng mov32 r1, 0xa
849*fae6e9adSlinfeng jeq32 r1, 0xb, +5
850*fae6e9adSlinfeng mov32 r0, 1
851*fae6e9adSlinfeng mov r1, 0xb
852*fae6e9adSlinfeng or r1, r9
853*fae6e9adSlinfeng jeq32 r1, 0xb, +1
854*fae6e9adSlinfeng mov32 r0, 2
855*fae6e9adSlinfeng exit
856*fae6e9adSlinfeng ",
857*fae6e9adSlinfeng 0x1
858*fae6e9adSlinfeng );
859*fae6e9adSlinfeng
860*fae6e9adSlinfeng test_cranelift!(
861*fae6e9adSlinfeng test_cranelift_jeq32_reg,
862*fae6e9adSlinfeng "
863*fae6e9adSlinfeng mov r9, 1
864*fae6e9adSlinfeng lsh r9, 32
865*fae6e9adSlinfeng mov32 r0, 0
866*fae6e9adSlinfeng mov32 r1, 0xa
867*fae6e9adSlinfeng mov32 r2, 0xb
868*fae6e9adSlinfeng jeq32 r1, r2, +5
869*fae6e9adSlinfeng mov32 r0, 1
870*fae6e9adSlinfeng mov32 r1, 0xb
871*fae6e9adSlinfeng or r1, r9
872*fae6e9adSlinfeng jeq32 r1, r2, +1
873*fae6e9adSlinfeng mov32 r0, 2
874*fae6e9adSlinfeng exit
875*fae6e9adSlinfeng ",
876*fae6e9adSlinfeng 0x1
877*fae6e9adSlinfeng );
878*fae6e9adSlinfeng
879*fae6e9adSlinfeng test_cranelift!(
880*fae6e9adSlinfeng test_cranelift_jge32_imm,
881*fae6e9adSlinfeng "
882*fae6e9adSlinfeng mov r9, 1
883*fae6e9adSlinfeng lsh r9, 32
884*fae6e9adSlinfeng mov32 r0, 0
885*fae6e9adSlinfeng mov32 r1, 0xa
886*fae6e9adSlinfeng jge32 r1, 0xb, +5
887*fae6e9adSlinfeng mov32 r0, 1
888*fae6e9adSlinfeng or r1, r9
889*fae6e9adSlinfeng mov32 r1, 0xc
890*fae6e9adSlinfeng jge32 r1, 0xb, +1
891*fae6e9adSlinfeng mov32 r0, 2
892*fae6e9adSlinfeng exit
893*fae6e9adSlinfeng ",
894*fae6e9adSlinfeng 0x1
895*fae6e9adSlinfeng );
896*fae6e9adSlinfeng
897*fae6e9adSlinfeng test_cranelift!(
898*fae6e9adSlinfeng test_cranelift_jge32_reg,
899*fae6e9adSlinfeng "
900*fae6e9adSlinfeng mov r9, 1
901*fae6e9adSlinfeng lsh r9, 32
902*fae6e9adSlinfeng mov32 r0, 0
903*fae6e9adSlinfeng mov32 r1, 0xa
904*fae6e9adSlinfeng mov32 r2, 0xb
905*fae6e9adSlinfeng jge32 r1, r2, +5
906*fae6e9adSlinfeng mov32 r0, 1
907*fae6e9adSlinfeng or r1, r9
908*fae6e9adSlinfeng mov32 r1, 0xc
909*fae6e9adSlinfeng jge32 r1, r2, +1
910*fae6e9adSlinfeng mov32 r0, 2
911*fae6e9adSlinfeng exit
912*fae6e9adSlinfeng ",
913*fae6e9adSlinfeng 0x1
914*fae6e9adSlinfeng );
915*fae6e9adSlinfeng
916*fae6e9adSlinfeng test_cranelift!(
917*fae6e9adSlinfeng test_cranelift_jgt32_imm,
918*fae6e9adSlinfeng "
919*fae6e9adSlinfeng mov r9, 1
920*fae6e9adSlinfeng lsh r9, 32
921*fae6e9adSlinfeng mov32 r0, 0
922*fae6e9adSlinfeng mov32 r1, 5
923*fae6e9adSlinfeng or r1, r9
924*fae6e9adSlinfeng jgt32 r1, 6, +4
925*fae6e9adSlinfeng jgt32 r1, 5, +3
926*fae6e9adSlinfeng jgt32 r1, 4, +1
927*fae6e9adSlinfeng exit
928*fae6e9adSlinfeng mov32 r0, 1
929*fae6e9adSlinfeng exit
930*fae6e9adSlinfeng ",
931*fae6e9adSlinfeng 0x1
932*fae6e9adSlinfeng );
933*fae6e9adSlinfeng
934*fae6e9adSlinfeng test_cranelift!(
935*fae6e9adSlinfeng test_cranelift_jgt32_reg,
936*fae6e9adSlinfeng "
937*fae6e9adSlinfeng mov r9, 1
938*fae6e9adSlinfeng lsh r9, 32
939*fae6e9adSlinfeng mov r0, 0
940*fae6e9adSlinfeng mov r1, 5
941*fae6e9adSlinfeng mov32 r1, 5
942*fae6e9adSlinfeng or r1, r9
943*fae6e9adSlinfeng mov r2, 6
944*fae6e9adSlinfeng mov r3, 4
945*fae6e9adSlinfeng jgt32 r1, r2, +4
946*fae6e9adSlinfeng jgt32 r1, r1, +3
947*fae6e9adSlinfeng jgt32 r1, r3, +1
948*fae6e9adSlinfeng exit
949*fae6e9adSlinfeng mov r0, 1
950*fae6e9adSlinfeng exit
951*fae6e9adSlinfeng ",
952*fae6e9adSlinfeng 0x1
953*fae6e9adSlinfeng );
954*fae6e9adSlinfeng
955*fae6e9adSlinfeng test_cranelift!(
956*fae6e9adSlinfeng test_cranelift_jle32_imm,
957*fae6e9adSlinfeng "
958*fae6e9adSlinfeng mov r9, 1
959*fae6e9adSlinfeng lsh r9, 32
960*fae6e9adSlinfeng mov32 r0, 0
961*fae6e9adSlinfeng mov32 r1, 5
962*fae6e9adSlinfeng or r1, r9
963*fae6e9adSlinfeng jle32 r1, 4, +5
964*fae6e9adSlinfeng jle32 r1, 6, +1
965*fae6e9adSlinfeng exit
966*fae6e9adSlinfeng jle32 r1, 5, +1
967*fae6e9adSlinfeng exit
968*fae6e9adSlinfeng mov32 r0, 1
969*fae6e9adSlinfeng exit
970*fae6e9adSlinfeng ",
971*fae6e9adSlinfeng 0x1
972*fae6e9adSlinfeng );
973*fae6e9adSlinfeng
974*fae6e9adSlinfeng test_cranelift!(
975*fae6e9adSlinfeng test_cranelift_jle32_reg,
976*fae6e9adSlinfeng "
977*fae6e9adSlinfeng mov r9, 1
978*fae6e9adSlinfeng lsh r9, 32
979*fae6e9adSlinfeng mov r0, 0
980*fae6e9adSlinfeng mov r1, 5
981*fae6e9adSlinfeng mov r2, 4
982*fae6e9adSlinfeng mov r3, 6
983*fae6e9adSlinfeng or r1, r9
984*fae6e9adSlinfeng jle32 r1, r2, +5
985*fae6e9adSlinfeng jle32 r1, r1, +1
986*fae6e9adSlinfeng exit
987*fae6e9adSlinfeng jle32 r1, r3, +1
988*fae6e9adSlinfeng exit
989*fae6e9adSlinfeng mov r0, 1
990*fae6e9adSlinfeng exit
991*fae6e9adSlinfeng ",
992*fae6e9adSlinfeng 0x1
993*fae6e9adSlinfeng );
994*fae6e9adSlinfeng
995*fae6e9adSlinfeng test_cranelift!(
996*fae6e9adSlinfeng test_cranelift_jlt32_imm,
997*fae6e9adSlinfeng "
998*fae6e9adSlinfeng mov r9, 1
999*fae6e9adSlinfeng lsh r9, 32
1000*fae6e9adSlinfeng mov32 r0, 0
1001*fae6e9adSlinfeng mov32 r1, 5
1002*fae6e9adSlinfeng or r1, r9
1003*fae6e9adSlinfeng jlt32 r1, 4, +4
1004*fae6e9adSlinfeng jlt32 r1, 5, +3
1005*fae6e9adSlinfeng jlt32 r1, 6, +1
1006*fae6e9adSlinfeng exit
1007*fae6e9adSlinfeng mov32 r0, 1
1008*fae6e9adSlinfeng exit
1009*fae6e9adSlinfeng ",
1010*fae6e9adSlinfeng 0x1
1011*fae6e9adSlinfeng );
1012*fae6e9adSlinfeng
1013*fae6e9adSlinfeng test_cranelift!(
1014*fae6e9adSlinfeng test_cranelift_jlt32_reg,
1015*fae6e9adSlinfeng "
1016*fae6e9adSlinfeng mov r9, 1
1017*fae6e9adSlinfeng lsh r9, 32
1018*fae6e9adSlinfeng mov r0, 0
1019*fae6e9adSlinfeng mov r1, 5
1020*fae6e9adSlinfeng mov r2, 4
1021*fae6e9adSlinfeng mov r3, 6
1022*fae6e9adSlinfeng or r1, r9
1023*fae6e9adSlinfeng jlt32 r1, r2, +4
1024*fae6e9adSlinfeng jlt32 r1, r1, +3
1025*fae6e9adSlinfeng jlt32 r1, r3, +1
1026*fae6e9adSlinfeng exit
1027*fae6e9adSlinfeng mov r0, 1
1028*fae6e9adSlinfeng exit
1029*fae6e9adSlinfeng ",
1030*fae6e9adSlinfeng 0x1
1031*fae6e9adSlinfeng );
1032*fae6e9adSlinfeng
1033*fae6e9adSlinfeng test_cranelift!(
1034*fae6e9adSlinfeng test_cranelift_jne32_imm,
1035*fae6e9adSlinfeng "
1036*fae6e9adSlinfeng mov r9, 1
1037*fae6e9adSlinfeng lsh r9, 32
1038*fae6e9adSlinfeng mov32 r0, 0
1039*fae6e9adSlinfeng mov32 r1, 0xb
1040*fae6e9adSlinfeng or r1, r9
1041*fae6e9adSlinfeng jne32 r1, 0xb, +4
1042*fae6e9adSlinfeng mov32 r0, 1
1043*fae6e9adSlinfeng mov32 r1, 0xa
1044*fae6e9adSlinfeng or r1, r9
1045*fae6e9adSlinfeng jne32 r1, 0xb, +1
1046*fae6e9adSlinfeng mov32 r0, 2
1047*fae6e9adSlinfeng exit
1048*fae6e9adSlinfeng ",
1049*fae6e9adSlinfeng 0x1
1050*fae6e9adSlinfeng );
1051*fae6e9adSlinfeng
1052*fae6e9adSlinfeng test_cranelift!(
1053*fae6e9adSlinfeng test_cranelift_jne32_reg,
1054*fae6e9adSlinfeng "
1055*fae6e9adSlinfeng mov r9, 1
1056*fae6e9adSlinfeng lsh r9, 32
1057*fae6e9adSlinfeng mov32 r0, 0
1058*fae6e9adSlinfeng mov32 r1, 0xb
1059*fae6e9adSlinfeng or r1, r9
1060*fae6e9adSlinfeng mov32 r2, 0xb
1061*fae6e9adSlinfeng jne32 r1, r2, +4
1062*fae6e9adSlinfeng mov32 r0, 1
1063*fae6e9adSlinfeng mov32 r1, 0xa
1064*fae6e9adSlinfeng or r1, r9
1065*fae6e9adSlinfeng jne32 r1, r2, +1
1066*fae6e9adSlinfeng mov32 r0, 2
1067*fae6e9adSlinfeng exit
1068*fae6e9adSlinfeng ",
1069*fae6e9adSlinfeng 0x1
1070*fae6e9adSlinfeng );
1071*fae6e9adSlinfeng
1072*fae6e9adSlinfeng test_cranelift!(
1073*fae6e9adSlinfeng test_cranelift_jset32_imm,
1074*fae6e9adSlinfeng "
1075*fae6e9adSlinfeng mov r9, 1
1076*fae6e9adSlinfeng lsh r9, 32
1077*fae6e9adSlinfeng mov32 r0, 0
1078*fae6e9adSlinfeng mov32 r1, 0x7
1079*fae6e9adSlinfeng or r1, r9
1080*fae6e9adSlinfeng jset32 r1, 0x8, +4
1081*fae6e9adSlinfeng mov32 r0, 1
1082*fae6e9adSlinfeng mov32 r1, 0x9
1083*fae6e9adSlinfeng jset32 r1, 0x8, +1
1084*fae6e9adSlinfeng mov32 r0, 2
1085*fae6e9adSlinfeng exit
1086*fae6e9adSlinfeng ",
1087*fae6e9adSlinfeng 0x1
1088*fae6e9adSlinfeng );
1089*fae6e9adSlinfeng
1090*fae6e9adSlinfeng test_cranelift!(
1091*fae6e9adSlinfeng test_cranelift_jset32_reg,
1092*fae6e9adSlinfeng "
1093*fae6e9adSlinfeng mov r9, 1
1094*fae6e9adSlinfeng lsh r9, 32
1095*fae6e9adSlinfeng mov32 r0, 0
1096*fae6e9adSlinfeng mov32 r1, 0x7
1097*fae6e9adSlinfeng or r1, r9
1098*fae6e9adSlinfeng mov32 r2, 0x8
1099*fae6e9adSlinfeng jset32 r1, r2, +4
1100*fae6e9adSlinfeng mov32 r0, 1
1101*fae6e9adSlinfeng mov32 r1, 0x9
1102*fae6e9adSlinfeng jset32 r1, r2, +1
1103*fae6e9adSlinfeng mov32 r0, 2
1104*fae6e9adSlinfeng exit
1105*fae6e9adSlinfeng ",
1106*fae6e9adSlinfeng 0x1
1107*fae6e9adSlinfeng );
1108*fae6e9adSlinfeng
1109*fae6e9adSlinfeng test_cranelift!(
1110*fae6e9adSlinfeng test_cranelift_jsge32_imm,
1111*fae6e9adSlinfeng "
1112*fae6e9adSlinfeng mov r9, 1
1113*fae6e9adSlinfeng lsh r9, 32
1114*fae6e9adSlinfeng mov32 r0, 0
1115*fae6e9adSlinfeng mov32 r1, -2
1116*fae6e9adSlinfeng or r1, r9
1117*fae6e9adSlinfeng jsge32 r1, -1, +5
1118*fae6e9adSlinfeng jsge32 r1, 0, +4
1119*fae6e9adSlinfeng mov32 r0, 1
1120*fae6e9adSlinfeng mov r1, -1
1121*fae6e9adSlinfeng jsge32 r1, -1, +1
1122*fae6e9adSlinfeng mov32 r0, 2
1123*fae6e9adSlinfeng exit
1124*fae6e9adSlinfeng ",
1125*fae6e9adSlinfeng 0x1
1126*fae6e9adSlinfeng );
1127*fae6e9adSlinfeng
1128*fae6e9adSlinfeng test_cranelift!(
1129*fae6e9adSlinfeng test_cranelift_jsge32_reg,
1130*fae6e9adSlinfeng "
1131*fae6e9adSlinfeng mov r9, 1
1132*fae6e9adSlinfeng lsh r9, 32
1133*fae6e9adSlinfeng mov32 r0, 0
1134*fae6e9adSlinfeng mov32 r1, -2
1135*fae6e9adSlinfeng or r1, r9
1136*fae6e9adSlinfeng mov r2, -1
1137*fae6e9adSlinfeng mov32 r3, 0
1138*fae6e9adSlinfeng jsge32 r1, r2, +5
1139*fae6e9adSlinfeng jsge32 r1, r3, +4
1140*fae6e9adSlinfeng mov32 r0, 1
1141*fae6e9adSlinfeng mov r1, r2
1142*fae6e9adSlinfeng jsge32 r1, r2, +1
1143*fae6e9adSlinfeng mov32 r0, 2
1144*fae6e9adSlinfeng exit
1145*fae6e9adSlinfeng ",
1146*fae6e9adSlinfeng 0x1
1147*fae6e9adSlinfeng );
1148*fae6e9adSlinfeng
1149*fae6e9adSlinfeng test_cranelift!(
1150*fae6e9adSlinfeng test_cranelift_jsgt32_imm,
1151*fae6e9adSlinfeng "
1152*fae6e9adSlinfeng mov r9, 1
1153*fae6e9adSlinfeng lsh r9, 32
1154*fae6e9adSlinfeng mov32 r0, 0
1155*fae6e9adSlinfeng mov32 r1, -2
1156*fae6e9adSlinfeng or r1, r9
1157*fae6e9adSlinfeng jsgt32 r1, -1, +4
1158*fae6e9adSlinfeng mov32 r0, 1
1159*fae6e9adSlinfeng mov32 r1, 0
1160*fae6e9adSlinfeng jsgt32 r1, -1, +1
1161*fae6e9adSlinfeng mov32 r0, 2
1162*fae6e9adSlinfeng exit
1163*fae6e9adSlinfeng ",
1164*fae6e9adSlinfeng 0x1
1165*fae6e9adSlinfeng );
1166*fae6e9adSlinfeng
1167*fae6e9adSlinfeng test_cranelift!(
1168*fae6e9adSlinfeng test_cranelift_jsgt32_reg,
1169*fae6e9adSlinfeng "
1170*fae6e9adSlinfeng mov r9, 1
1171*fae6e9adSlinfeng lsh r9, 32
1172*fae6e9adSlinfeng mov32 r0, 0
1173*fae6e9adSlinfeng mov32 r1, -2
1174*fae6e9adSlinfeng or r1, r9
1175*fae6e9adSlinfeng mov r2, -1
1176*fae6e9adSlinfeng jsgt32 r1, r2, +4
1177*fae6e9adSlinfeng mov32 r0, 1
1178*fae6e9adSlinfeng mov32 r1, 0
1179*fae6e9adSlinfeng jsgt32 r1, r2, +1
1180*fae6e9adSlinfeng mov32 r0, 2
1181*fae6e9adSlinfeng exit
1182*fae6e9adSlinfeng ",
1183*fae6e9adSlinfeng 0x1
1184*fae6e9adSlinfeng );
1185*fae6e9adSlinfeng
1186*fae6e9adSlinfeng test_cranelift!(
1187*fae6e9adSlinfeng test_cranelift_jsle32_imm,
1188*fae6e9adSlinfeng "
1189*fae6e9adSlinfeng mov r9, 1
1190*fae6e9adSlinfeng lsh r9, 32
1191*fae6e9adSlinfeng mov32 r0, 0
1192*fae6e9adSlinfeng mov32 r1, -2
1193*fae6e9adSlinfeng or r1, r9
1194*fae6e9adSlinfeng jsle32 r1, -3, +5
1195*fae6e9adSlinfeng jsle32 r1, -1, +1
1196*fae6e9adSlinfeng exit
1197*fae6e9adSlinfeng mov32 r0, 1
1198*fae6e9adSlinfeng jsle32 r1, -2, +1
1199*fae6e9adSlinfeng mov32 r0, 2
1200*fae6e9adSlinfeng exit
1201*fae6e9adSlinfeng ",
1202*fae6e9adSlinfeng 0x1
1203*fae6e9adSlinfeng );
1204*fae6e9adSlinfeng
1205*fae6e9adSlinfeng test_cranelift!(
1206*fae6e9adSlinfeng test_cranelift_jsle32_reg,
1207*fae6e9adSlinfeng "
1208*fae6e9adSlinfeng mov r9, 1
1209*fae6e9adSlinfeng lsh r9, 32
1210*fae6e9adSlinfeng mov32 r0, 0
1211*fae6e9adSlinfeng mov32 r1, -2
1212*fae6e9adSlinfeng or r1, r9
1213*fae6e9adSlinfeng mov r2, -3
1214*fae6e9adSlinfeng mov32 r3, 0
1215*fae6e9adSlinfeng jsle32 r1, r2, +6
1216*fae6e9adSlinfeng jsle32 r1, r3, +1
1217*fae6e9adSlinfeng exit
1218*fae6e9adSlinfeng mov32 r0, 1
1219*fae6e9adSlinfeng mov r1, r2
1220*fae6e9adSlinfeng jsle32 r1, r2, +1
1221*fae6e9adSlinfeng mov32 r0, 2
1222*fae6e9adSlinfeng exit
1223*fae6e9adSlinfeng ",
1224*fae6e9adSlinfeng 0x1
1225*fae6e9adSlinfeng );
1226*fae6e9adSlinfeng
1227*fae6e9adSlinfeng test_cranelift!(
1228*fae6e9adSlinfeng test_cranelift_jslt32_imm,
1229*fae6e9adSlinfeng "
1230*fae6e9adSlinfeng mov r9, 1
1231*fae6e9adSlinfeng lsh r9, 32
1232*fae6e9adSlinfeng mov32 r0, 0
1233*fae6e9adSlinfeng mov32 r1, -2
1234*fae6e9adSlinfeng or r1, r9
1235*fae6e9adSlinfeng jslt32 r1, -3, +4
1236*fae6e9adSlinfeng jslt32 r1, -2, +3
1237*fae6e9adSlinfeng jslt32 r1, -1, +1
1238*fae6e9adSlinfeng exit
1239*fae6e9adSlinfeng mov32 r0, 1
1240*fae6e9adSlinfeng exit
1241*fae6e9adSlinfeng ",
1242*fae6e9adSlinfeng 0x1
1243*fae6e9adSlinfeng );
1244*fae6e9adSlinfeng
1245*fae6e9adSlinfeng test_cranelift!(
1246*fae6e9adSlinfeng test_cranelift_jslt32_reg,
1247*fae6e9adSlinfeng "
1248*fae6e9adSlinfeng mov r9, 1
1249*fae6e9adSlinfeng lsh r9, 32
1250*fae6e9adSlinfeng mov32 r0, 0
1251*fae6e9adSlinfeng mov32 r1, -2
1252*fae6e9adSlinfeng or r1, r9
1253*fae6e9adSlinfeng mov r2, -3
1254*fae6e9adSlinfeng mov r3, -1
1255*fae6e9adSlinfeng jslt32 r1, r1, +4
1256*fae6e9adSlinfeng jslt32 r1, r2, +3
1257*fae6e9adSlinfeng jslt32 r1, r3, +1
1258*fae6e9adSlinfeng exit
1259*fae6e9adSlinfeng mov32 r0, 1
1260*fae6e9adSlinfeng exit
1261*fae6e9adSlinfeng ",
1262*fae6e9adSlinfeng 0x1
1263*fae6e9adSlinfeng );
1264*fae6e9adSlinfeng
1265*fae6e9adSlinfeng test_cranelift!(
1266*fae6e9adSlinfeng test_cranelift_lddw,
1267*fae6e9adSlinfeng "
1268*fae6e9adSlinfeng lddw r0, 0x1122334455667788
1269*fae6e9adSlinfeng exit
1270*fae6e9adSlinfeng ",
1271*fae6e9adSlinfeng 0x1122334455667788
1272*fae6e9adSlinfeng );
1273*fae6e9adSlinfeng
1274*fae6e9adSlinfeng test_cranelift!(
1275*fae6e9adSlinfeng test_cranelift_lddw2,
1276*fae6e9adSlinfeng "
1277*fae6e9adSlinfeng lddw r0, 0x0000000080000000
1278*fae6e9adSlinfeng exit
1279*fae6e9adSlinfeng ",
1280*fae6e9adSlinfeng 0x80000000
1281*fae6e9adSlinfeng );
1282*fae6e9adSlinfeng
1283*fae6e9adSlinfeng test_cranelift!(
1284*fae6e9adSlinfeng test_cranelift_ldxb_all,
1285*fae6e9adSlinfeng "
1286*fae6e9adSlinfeng mov r0, r1
1287*fae6e9adSlinfeng ldxb r9, [r0+0]
1288*fae6e9adSlinfeng lsh r9, 0
1289*fae6e9adSlinfeng ldxb r8, [r0+1]
1290*fae6e9adSlinfeng lsh r8, 4
1291*fae6e9adSlinfeng ldxb r7, [r0+2]
1292*fae6e9adSlinfeng lsh r7, 8
1293*fae6e9adSlinfeng ldxb r6, [r0+3]
1294*fae6e9adSlinfeng lsh r6, 12
1295*fae6e9adSlinfeng ldxb r5, [r0+4]
1296*fae6e9adSlinfeng lsh r5, 16
1297*fae6e9adSlinfeng ldxb r4, [r0+5]
1298*fae6e9adSlinfeng lsh r4, 20
1299*fae6e9adSlinfeng ldxb r3, [r0+6]
1300*fae6e9adSlinfeng lsh r3, 24
1301*fae6e9adSlinfeng ldxb r2, [r0+7]
1302*fae6e9adSlinfeng lsh r2, 28
1303*fae6e9adSlinfeng ldxb r1, [r0+8]
1304*fae6e9adSlinfeng lsh r1, 32
1305*fae6e9adSlinfeng ldxb r0, [r0+9]
1306*fae6e9adSlinfeng lsh r0, 36
1307*fae6e9adSlinfeng or r0, r1
1308*fae6e9adSlinfeng or r0, r2
1309*fae6e9adSlinfeng or r0, r3
1310*fae6e9adSlinfeng or r0, r4
1311*fae6e9adSlinfeng or r0, r5
1312*fae6e9adSlinfeng or r0, r6
1313*fae6e9adSlinfeng or r0, r7
1314*fae6e9adSlinfeng or r0, r8
1315*fae6e9adSlinfeng or r0, r9
1316*fae6e9adSlinfeng exit
1317*fae6e9adSlinfeng ",
1318*fae6e9adSlinfeng [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09],
1319*fae6e9adSlinfeng 0x9876543210
1320*fae6e9adSlinfeng );
1321*fae6e9adSlinfeng
1322*fae6e9adSlinfeng test_cranelift!(
1323*fae6e9adSlinfeng test_cranelift_ldxb,
1324*fae6e9adSlinfeng "
1325*fae6e9adSlinfeng ldxb r0, [r1+2]
1326*fae6e9adSlinfeng exit
1327*fae6e9adSlinfeng ",
1328*fae6e9adSlinfeng [0xaa, 0xbb, 0x11, 0xcc, 0xdd],
1329*fae6e9adSlinfeng 0x11
1330*fae6e9adSlinfeng );
1331*fae6e9adSlinfeng
1332*fae6e9adSlinfeng test_cranelift!(
1333*fae6e9adSlinfeng test_cranelift_ldxdw,
1334*fae6e9adSlinfeng "
1335*fae6e9adSlinfeng ldxdw r0, [r1+2]
1336*fae6e9adSlinfeng exit
1337*fae6e9adSlinfeng ",
1338*fae6e9adSlinfeng [0xaa, 0xbb, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0xcc, 0xdd],
1339*fae6e9adSlinfeng 0x8877665544332211
1340*fae6e9adSlinfeng );
1341*fae6e9adSlinfeng
1342*fae6e9adSlinfeng test_cranelift!(
1343*fae6e9adSlinfeng test_cranelift_ldxh_all,
1344*fae6e9adSlinfeng "
1345*fae6e9adSlinfeng mov r0, r1
1346*fae6e9adSlinfeng ldxh r9, [r0+0]
1347*fae6e9adSlinfeng be16 r9
1348*fae6e9adSlinfeng lsh r9, 0
1349*fae6e9adSlinfeng ldxh r8, [r0+2]
1350*fae6e9adSlinfeng be16 r8
1351*fae6e9adSlinfeng lsh r8, 4
1352*fae6e9adSlinfeng ldxh r7, [r0+4]
1353*fae6e9adSlinfeng be16 r7
1354*fae6e9adSlinfeng lsh r7, 8
1355*fae6e9adSlinfeng ldxh r6, [r0+6]
1356*fae6e9adSlinfeng be16 r6
1357*fae6e9adSlinfeng lsh r6, 12
1358*fae6e9adSlinfeng ldxh r5, [r0+8]
1359*fae6e9adSlinfeng be16 r5
1360*fae6e9adSlinfeng lsh r5, 16
1361*fae6e9adSlinfeng ldxh r4, [r0+10]
1362*fae6e9adSlinfeng be16 r4
1363*fae6e9adSlinfeng lsh r4, 20
1364*fae6e9adSlinfeng ldxh r3, [r0+12]
1365*fae6e9adSlinfeng be16 r3
1366*fae6e9adSlinfeng lsh r3, 24
1367*fae6e9adSlinfeng ldxh r2, [r0+14]
1368*fae6e9adSlinfeng be16 r2
1369*fae6e9adSlinfeng lsh r2, 28
1370*fae6e9adSlinfeng ldxh r1, [r0+16]
1371*fae6e9adSlinfeng be16 r1
1372*fae6e9adSlinfeng lsh r1, 32
1373*fae6e9adSlinfeng ldxh r0, [r0+18]
1374*fae6e9adSlinfeng be16 r0
1375*fae6e9adSlinfeng lsh r0, 36
1376*fae6e9adSlinfeng or r0, r1
1377*fae6e9adSlinfeng or r0, r2
1378*fae6e9adSlinfeng or r0, r3
1379*fae6e9adSlinfeng or r0, r4
1380*fae6e9adSlinfeng or r0, r5
1381*fae6e9adSlinfeng or r0, r6
1382*fae6e9adSlinfeng or r0, r7
1383*fae6e9adSlinfeng or r0, r8
1384*fae6e9adSlinfeng or r0, r9
1385*fae6e9adSlinfeng exit
1386*fae6e9adSlinfeng ",
1387*fae6e9adSlinfeng [
1388*fae6e9adSlinfeng 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00,
1389*fae6e9adSlinfeng 0x07, 0x00, 0x08, 0x00, 0x09
1390*fae6e9adSlinfeng ],
1391*fae6e9adSlinfeng 0x9876543210
1392*fae6e9adSlinfeng );
1393*fae6e9adSlinfeng
1394*fae6e9adSlinfeng test_cranelift!(
1395*fae6e9adSlinfeng test_cranelift_ldxh_all2,
1396*fae6e9adSlinfeng "
1397*fae6e9adSlinfeng mov r0, r1
1398*fae6e9adSlinfeng ldxh r9, [r0+0]
1399*fae6e9adSlinfeng be16 r9
1400*fae6e9adSlinfeng ldxh r8, [r0+2]
1401*fae6e9adSlinfeng be16 r8
1402*fae6e9adSlinfeng ldxh r7, [r0+4]
1403*fae6e9adSlinfeng be16 r7
1404*fae6e9adSlinfeng ldxh r6, [r0+6]
1405*fae6e9adSlinfeng be16 r6
1406*fae6e9adSlinfeng ldxh r5, [r0+8]
1407*fae6e9adSlinfeng be16 r5
1408*fae6e9adSlinfeng ldxh r4, [r0+10]
1409*fae6e9adSlinfeng be16 r4
1410*fae6e9adSlinfeng ldxh r3, [r0+12]
1411*fae6e9adSlinfeng be16 r3
1412*fae6e9adSlinfeng ldxh r2, [r0+14]
1413*fae6e9adSlinfeng be16 r2
1414*fae6e9adSlinfeng ldxh r1, [r0+16]
1415*fae6e9adSlinfeng be16 r1
1416*fae6e9adSlinfeng ldxh r0, [r0+18]
1417*fae6e9adSlinfeng be16 r0
1418*fae6e9adSlinfeng or r0, r1
1419*fae6e9adSlinfeng or r0, r2
1420*fae6e9adSlinfeng or r0, r3
1421*fae6e9adSlinfeng or r0, r4
1422*fae6e9adSlinfeng or r0, r5
1423*fae6e9adSlinfeng or r0, r6
1424*fae6e9adSlinfeng or r0, r7
1425*fae6e9adSlinfeng or r0, r8
1426*fae6e9adSlinfeng or r0, r9
1427*fae6e9adSlinfeng exit
1428*fae6e9adSlinfeng ",
1429*fae6e9adSlinfeng [
1430*fae6e9adSlinfeng 0x00, 0x01, 0x00, 0x02, 0x00, 0x04, 0x00, 0x08, 0x00, 0x10, 0x00, 0x20, 0x00, 0x40, 0x00,
1431*fae6e9adSlinfeng 0x80, 0x01, 0x00, 0x02, 0x00
1432*fae6e9adSlinfeng ],
1433*fae6e9adSlinfeng 0x3ff
1434*fae6e9adSlinfeng );
1435*fae6e9adSlinfeng
1436*fae6e9adSlinfeng test_cranelift!(
1437*fae6e9adSlinfeng test_cranelift_ldxh,
1438*fae6e9adSlinfeng "
1439*fae6e9adSlinfeng ldxh r0, [r1+2]
1440*fae6e9adSlinfeng exit
1441*fae6e9adSlinfeng ",
1442*fae6e9adSlinfeng [0xaa, 0xbb, 0x11, 0x22, 0xcc, 0xdd],
1443*fae6e9adSlinfeng 0x2211
1444*fae6e9adSlinfeng );
1445*fae6e9adSlinfeng
1446*fae6e9adSlinfeng test_cranelift!(
1447*fae6e9adSlinfeng test_cranelift_ldxh_same_reg,
1448*fae6e9adSlinfeng "
1449*fae6e9adSlinfeng mov r0, r1
1450*fae6e9adSlinfeng sth [r0], 0x1234
1451*fae6e9adSlinfeng ldxh r0, [r0]
1452*fae6e9adSlinfeng exit
1453*fae6e9adSlinfeng ",
1454*fae6e9adSlinfeng [0xff, 0xff],
1455*fae6e9adSlinfeng 0x1234
1456*fae6e9adSlinfeng );
1457*fae6e9adSlinfeng
1458*fae6e9adSlinfeng test_cranelift!(
1459*fae6e9adSlinfeng test_cranelift_ldxw_all,
1460*fae6e9adSlinfeng "
1461*fae6e9adSlinfeng mov r0, r1
1462*fae6e9adSlinfeng ldxw r9, [r0+0]
1463*fae6e9adSlinfeng be32 r9
1464*fae6e9adSlinfeng ldxw r8, [r0+4]
1465*fae6e9adSlinfeng be32 r8
1466*fae6e9adSlinfeng ldxw r7, [r0+8]
1467*fae6e9adSlinfeng be32 r7
1468*fae6e9adSlinfeng ldxw r6, [r0+12]
1469*fae6e9adSlinfeng be32 r6
1470*fae6e9adSlinfeng ldxw r5, [r0+16]
1471*fae6e9adSlinfeng be32 r5
1472*fae6e9adSlinfeng ldxw r4, [r0+20]
1473*fae6e9adSlinfeng be32 r4
1474*fae6e9adSlinfeng ldxw r3, [r0+24]
1475*fae6e9adSlinfeng be32 r3
1476*fae6e9adSlinfeng ldxw r2, [r0+28]
1477*fae6e9adSlinfeng be32 r2
1478*fae6e9adSlinfeng ldxw r1, [r0+32]
1479*fae6e9adSlinfeng be32 r1
1480*fae6e9adSlinfeng ldxw r0, [r0+36]
1481*fae6e9adSlinfeng be32 r0
1482*fae6e9adSlinfeng or r0, r1
1483*fae6e9adSlinfeng or r0, r2
1484*fae6e9adSlinfeng or r0, r3
1485*fae6e9adSlinfeng or r0, r4
1486*fae6e9adSlinfeng or r0, r5
1487*fae6e9adSlinfeng or r0, r6
1488*fae6e9adSlinfeng or r0, r7
1489*fae6e9adSlinfeng or r0, r8
1490*fae6e9adSlinfeng or r0, r9
1491*fae6e9adSlinfeng exit
1492*fae6e9adSlinfeng ",
1493*fae6e9adSlinfeng [
1494*fae6e9adSlinfeng 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
1495*fae6e9adSlinfeng 0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
1496*fae6e9adSlinfeng 0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00
1497*fae6e9adSlinfeng ],
1498*fae6e9adSlinfeng 0x030f0f
1499*fae6e9adSlinfeng );
1500*fae6e9adSlinfeng
1501*fae6e9adSlinfeng test_cranelift!(
1502*fae6e9adSlinfeng test_cranelift_ldxw,
1503*fae6e9adSlinfeng "
1504*fae6e9adSlinfeng ldxw r0, [r1+2]
1505*fae6e9adSlinfeng exit
1506*fae6e9adSlinfeng ",
1507*fae6e9adSlinfeng [0xaa, 0xbb, 0x11, 0x22, 0x33, 0x44, 0xcc, 0xdd],
1508*fae6e9adSlinfeng 0x44332211
1509*fae6e9adSlinfeng );
1510*fae6e9adSlinfeng
1511*fae6e9adSlinfeng test_cranelift!(
1512*fae6e9adSlinfeng test_cranelift_le16,
1513*fae6e9adSlinfeng "
1514*fae6e9adSlinfeng ldxh r0, [r1]
1515*fae6e9adSlinfeng le16 r0
1516*fae6e9adSlinfeng exit
1517*fae6e9adSlinfeng ",
1518*fae6e9adSlinfeng [0x22, 0x11],
1519*fae6e9adSlinfeng 0x1122
1520*fae6e9adSlinfeng );
1521*fae6e9adSlinfeng
1522*fae6e9adSlinfeng test_cranelift!(
1523*fae6e9adSlinfeng test_cranelift_le32,
1524*fae6e9adSlinfeng "
1525*fae6e9adSlinfeng ldxw r0, [r1]
1526*fae6e9adSlinfeng le32 r0
1527*fae6e9adSlinfeng exit
1528*fae6e9adSlinfeng ",
1529*fae6e9adSlinfeng [0x44, 0x33, 0x22, 0x11],
1530*fae6e9adSlinfeng 0x11223344
1531*fae6e9adSlinfeng );
1532*fae6e9adSlinfeng
1533*fae6e9adSlinfeng test_cranelift!(
1534*fae6e9adSlinfeng test_cranelift_le64,
1535*fae6e9adSlinfeng "
1536*fae6e9adSlinfeng ldxdw r0, [r1]
1537*fae6e9adSlinfeng le64 r0
1538*fae6e9adSlinfeng exit
1539*fae6e9adSlinfeng ",
1540*fae6e9adSlinfeng [0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11],
1541*fae6e9adSlinfeng 0x1122334455667788
1542*fae6e9adSlinfeng );
1543*fae6e9adSlinfeng
1544*fae6e9adSlinfeng test_cranelift!(
1545*fae6e9adSlinfeng test_cranelift_lsh_reg,
1546*fae6e9adSlinfeng "
1547*fae6e9adSlinfeng mov r0, 0x1
1548*fae6e9adSlinfeng mov r7, 4
1549*fae6e9adSlinfeng lsh r0, r7
1550*fae6e9adSlinfeng exit
1551*fae6e9adSlinfeng ",
1552*fae6e9adSlinfeng 0x10
1553*fae6e9adSlinfeng );
1554*fae6e9adSlinfeng
1555*fae6e9adSlinfeng test_cranelift!(
1556*fae6e9adSlinfeng test_cranelift_mod,
1557*fae6e9adSlinfeng "
1558*fae6e9adSlinfeng mov32 r0, 5748
1559*fae6e9adSlinfeng mod32 r0, 92
1560*fae6e9adSlinfeng mov32 r1, 13
1561*fae6e9adSlinfeng mod32 r0, r1
1562*fae6e9adSlinfeng exit
1563*fae6e9adSlinfeng ",
1564*fae6e9adSlinfeng 0x5
1565*fae6e9adSlinfeng );
1566*fae6e9adSlinfeng
1567*fae6e9adSlinfeng test_cranelift!(
1568*fae6e9adSlinfeng test_cranelift_mod32,
1569*fae6e9adSlinfeng "
1570*fae6e9adSlinfeng lddw r0, 0x100000003
1571*fae6e9adSlinfeng mod32 r0, 3
1572*fae6e9adSlinfeng exit
1573*fae6e9adSlinfeng ",
1574*fae6e9adSlinfeng 0x0
1575*fae6e9adSlinfeng );
1576*fae6e9adSlinfeng
1577*fae6e9adSlinfeng test_cranelift!(
1578*fae6e9adSlinfeng test_cranelift_mod64,
1579*fae6e9adSlinfeng "
1580*fae6e9adSlinfeng mov32 r0, -1316649930
1581*fae6e9adSlinfeng lsh r0, 32
1582*fae6e9adSlinfeng or r0, 0x100dc5c8
1583*fae6e9adSlinfeng mov32 r1, 0xdde263e
1584*fae6e9adSlinfeng lsh r1, 32
1585*fae6e9adSlinfeng or r1, 0x3cbef7f3
1586*fae6e9adSlinfeng mod r0, r1
1587*fae6e9adSlinfeng mod r0, 0x658f1778
1588*fae6e9adSlinfeng exit
1589*fae6e9adSlinfeng ",
1590*fae6e9adSlinfeng 0x30ba5a04
1591*fae6e9adSlinfeng );
1592*fae6e9adSlinfeng
1593*fae6e9adSlinfeng test_cranelift!(
1594*fae6e9adSlinfeng test_cranelift_mov,
1595*fae6e9adSlinfeng "
1596*fae6e9adSlinfeng mov32 r1, 1
1597*fae6e9adSlinfeng mov32 r0, r1
1598*fae6e9adSlinfeng exit
1599*fae6e9adSlinfeng ",
1600*fae6e9adSlinfeng 0x1
1601*fae6e9adSlinfeng );
1602*fae6e9adSlinfeng
1603*fae6e9adSlinfeng test_cranelift!(
1604*fae6e9adSlinfeng test_cranelift_mul32_imm,
1605*fae6e9adSlinfeng "
1606*fae6e9adSlinfeng mov r0, 3
1607*fae6e9adSlinfeng mul32 r0, 4
1608*fae6e9adSlinfeng exit
1609*fae6e9adSlinfeng ",
1610*fae6e9adSlinfeng 0xc
1611*fae6e9adSlinfeng );
1612*fae6e9adSlinfeng
1613*fae6e9adSlinfeng test_cranelift!(
1614*fae6e9adSlinfeng test_cranelift_mul32_reg,
1615*fae6e9adSlinfeng "
1616*fae6e9adSlinfeng mov r0, 3
1617*fae6e9adSlinfeng mov r1, 4
1618*fae6e9adSlinfeng mul32 r0, r1
1619*fae6e9adSlinfeng exit
1620*fae6e9adSlinfeng ",
1621*fae6e9adSlinfeng 0xc
1622*fae6e9adSlinfeng );
1623*fae6e9adSlinfeng
1624*fae6e9adSlinfeng test_cranelift!(
1625*fae6e9adSlinfeng test_cranelift_mul32_reg_overflow,
1626*fae6e9adSlinfeng "
1627*fae6e9adSlinfeng mov r0, 0x40000001
1628*fae6e9adSlinfeng mov r1, 4
1629*fae6e9adSlinfeng mul32 r0, r1
1630*fae6e9adSlinfeng exit
1631*fae6e9adSlinfeng ",
1632*fae6e9adSlinfeng 0x4
1633*fae6e9adSlinfeng );
1634*fae6e9adSlinfeng
1635*fae6e9adSlinfeng test_cranelift!(
1636*fae6e9adSlinfeng test_cranelift_mul64_imm,
1637*fae6e9adSlinfeng "
1638*fae6e9adSlinfeng mov r0, 0x40000001
1639*fae6e9adSlinfeng mul r0, 4
1640*fae6e9adSlinfeng exit
1641*fae6e9adSlinfeng ",
1642*fae6e9adSlinfeng 0x100000004
1643*fae6e9adSlinfeng );
1644*fae6e9adSlinfeng
1645*fae6e9adSlinfeng test_cranelift!(
1646*fae6e9adSlinfeng test_cranelift_mul64_reg,
1647*fae6e9adSlinfeng "
1648*fae6e9adSlinfeng mov r0, 0x40000001
1649*fae6e9adSlinfeng mov r1, 4
1650*fae6e9adSlinfeng mul r0, r1
1651*fae6e9adSlinfeng exit
1652*fae6e9adSlinfeng ",
1653*fae6e9adSlinfeng 0x100000004
1654*fae6e9adSlinfeng );
1655*fae6e9adSlinfeng
1656*fae6e9adSlinfeng test_cranelift!(
1657*fae6e9adSlinfeng test_cranelift_mul_loop,
1658*fae6e9adSlinfeng "
1659*fae6e9adSlinfeng mov r0, 0x7
1660*fae6e9adSlinfeng add r1, 0xa
1661*fae6e9adSlinfeng lsh r1, 0x20
1662*fae6e9adSlinfeng rsh r1, 0x20
1663*fae6e9adSlinfeng jeq r1, 0x0, +4
1664*fae6e9adSlinfeng mov r0, 0x7
1665*fae6e9adSlinfeng mul r0, 0x7
1666*fae6e9adSlinfeng add r1, -1
1667*fae6e9adSlinfeng jne r1, 0x0, -3
1668*fae6e9adSlinfeng exit
1669*fae6e9adSlinfeng ",
1670*fae6e9adSlinfeng 0x75db9c97
1671*fae6e9adSlinfeng );
1672*fae6e9adSlinfeng
1673*fae6e9adSlinfeng test_cranelift!(
1674*fae6e9adSlinfeng test_cranelift_neg64,
1675*fae6e9adSlinfeng "
1676*fae6e9adSlinfeng mov32 r0, 2
1677*fae6e9adSlinfeng neg r0
1678*fae6e9adSlinfeng exit
1679*fae6e9adSlinfeng ",
1680*fae6e9adSlinfeng 0xfffffffffffffffe
1681*fae6e9adSlinfeng );
1682*fae6e9adSlinfeng
1683*fae6e9adSlinfeng test_cranelift!(
1684*fae6e9adSlinfeng test_cranelift_neg,
1685*fae6e9adSlinfeng "
1686*fae6e9adSlinfeng mov32 r0, 2
1687*fae6e9adSlinfeng neg32 r0
1688*fae6e9adSlinfeng exit
1689*fae6e9adSlinfeng ",
1690*fae6e9adSlinfeng 0xfffffffe
1691*fae6e9adSlinfeng );
1692*fae6e9adSlinfeng
1693*fae6e9adSlinfeng test_cranelift!(
1694*fae6e9adSlinfeng test_cranelift_prime,
1695*fae6e9adSlinfeng "
1696*fae6e9adSlinfeng mov r1, 67
1697*fae6e9adSlinfeng mov r0, 0x1
1698*fae6e9adSlinfeng mov r2, 0x2
1699*fae6e9adSlinfeng jgt r1, 0x2, +4
1700*fae6e9adSlinfeng ja +10
1701*fae6e9adSlinfeng add r2, 0x1
1702*fae6e9adSlinfeng mov r0, 0x1
1703*fae6e9adSlinfeng jge r2, r1, +7
1704*fae6e9adSlinfeng mov r3, r1
1705*fae6e9adSlinfeng div r3, r2
1706*fae6e9adSlinfeng mul r3, r2
1707*fae6e9adSlinfeng mov r4, r1
1708*fae6e9adSlinfeng sub r4, r3
1709*fae6e9adSlinfeng mov r0, 0x0
1710*fae6e9adSlinfeng jne r4, 0x0, -10
1711*fae6e9adSlinfeng exit
1712*fae6e9adSlinfeng ",
1713*fae6e9adSlinfeng 1
1714*fae6e9adSlinfeng );
1715*fae6e9adSlinfeng
1716*fae6e9adSlinfeng test_cranelift!(
1717*fae6e9adSlinfeng test_cranelift_rhs32,
1718*fae6e9adSlinfeng "
1719*fae6e9adSlinfeng xor r0, r0
1720*fae6e9adSlinfeng sub r0, 1
1721*fae6e9adSlinfeng rsh32 r0, 8
1722*fae6e9adSlinfeng exit
1723*fae6e9adSlinfeng ",
1724*fae6e9adSlinfeng 0x00ffffff
1725*fae6e9adSlinfeng );
1726*fae6e9adSlinfeng
1727*fae6e9adSlinfeng test_cranelift!(
1728*fae6e9adSlinfeng test_cranelift_rsh_reg,
1729*fae6e9adSlinfeng "
1730*fae6e9adSlinfeng mov r0, 0x10
1731*fae6e9adSlinfeng mov r7, 4
1732*fae6e9adSlinfeng rsh r0, r7
1733*fae6e9adSlinfeng exit
1734*fae6e9adSlinfeng ",
1735*fae6e9adSlinfeng 0x1
1736*fae6e9adSlinfeng );
1737*fae6e9adSlinfeng
1738*fae6e9adSlinfeng test_cranelift!(
1739*fae6e9adSlinfeng test_cranelift_stack,
1740*fae6e9adSlinfeng "
1741*fae6e9adSlinfeng mov r1, 51
1742*fae6e9adSlinfeng stdw [r10-16], 0xab
1743*fae6e9adSlinfeng stdw [r10-8], 0xcd
1744*fae6e9adSlinfeng and r1, 1
1745*fae6e9adSlinfeng lsh r1, 3
1746*fae6e9adSlinfeng mov r2, r10
1747*fae6e9adSlinfeng add r2, r1
1748*fae6e9adSlinfeng ldxdw r0, [r2-16]
1749*fae6e9adSlinfeng exit
1750*fae6e9adSlinfeng ",
1751*fae6e9adSlinfeng 0xcd
1752*fae6e9adSlinfeng );
1753*fae6e9adSlinfeng
1754*fae6e9adSlinfeng #[test]
test_cranelift_stack2()1755*fae6e9adSlinfeng fn test_cranelift_stack2() {
1756*fae6e9adSlinfeng let prog = assemble(
1757*fae6e9adSlinfeng "
1758*fae6e9adSlinfeng stb [r10-4], 0x01
1759*fae6e9adSlinfeng stb [r10-3], 0x02
1760*fae6e9adSlinfeng stb [r10-2], 0x03
1761*fae6e9adSlinfeng stb [r10-1], 0x04
1762*fae6e9adSlinfeng mov r1, r10
1763*fae6e9adSlinfeng mov r2, 0x4
1764*fae6e9adSlinfeng sub r1, r2
1765*fae6e9adSlinfeng call 1
1766*fae6e9adSlinfeng mov r1, 0
1767*fae6e9adSlinfeng ldxb r2, [r10-4]
1768*fae6e9adSlinfeng ldxb r3, [r10-3]
1769*fae6e9adSlinfeng ldxb r4, [r10-2]
1770*fae6e9adSlinfeng ldxb r5, [r10-1]
1771*fae6e9adSlinfeng call 0
1772*fae6e9adSlinfeng xor r0, 0x2a2a2a2a
1773*fae6e9adSlinfeng exit",
1774*fae6e9adSlinfeng )
1775*fae6e9adSlinfeng .unwrap();
1776*fae6e9adSlinfeng
1777*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmNoData::new(Some(&prog)).unwrap();
1778*fae6e9adSlinfeng vm.register_helper(0, helpers::gather_bytes).unwrap();
1779*fae6e9adSlinfeng vm.register_helper(1, helpers::memfrob).unwrap();
1780*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
1781*fae6e9adSlinfeng assert_eq!(vm.execute_program_cranelift().unwrap(), 0x01020304);
1782*fae6e9adSlinfeng }
1783*fae6e9adSlinfeng
1784*fae6e9adSlinfeng test_cranelift!(
1785*fae6e9adSlinfeng test_cranelift_stb,
1786*fae6e9adSlinfeng "
1787*fae6e9adSlinfeng stb [r1+2], 0x11
1788*fae6e9adSlinfeng ldxb r0, [r1+2]
1789*fae6e9adSlinfeng exit
1790*fae6e9adSlinfeng ",
1791*fae6e9adSlinfeng [0xaa, 0xbb, 0xff, 0xcc, 0xdd],
1792*fae6e9adSlinfeng 0x11
1793*fae6e9adSlinfeng );
1794*fae6e9adSlinfeng
1795*fae6e9adSlinfeng test_cranelift!(
1796*fae6e9adSlinfeng test_cranelift_stdw,
1797*fae6e9adSlinfeng "
1798*fae6e9adSlinfeng stdw [r1+2], 0x44332211
1799*fae6e9adSlinfeng ldxdw r0, [r1+2]
1800*fae6e9adSlinfeng exit
1801*fae6e9adSlinfeng ",
1802*fae6e9adSlinfeng [0xaa, 0xbb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xdd],
1803*fae6e9adSlinfeng 0x44332211
1804*fae6e9adSlinfeng );
1805*fae6e9adSlinfeng
1806*fae6e9adSlinfeng test_cranelift!(
1807*fae6e9adSlinfeng test_cranelift_sth,
1808*fae6e9adSlinfeng "
1809*fae6e9adSlinfeng sth [r1+2], 0x2211
1810*fae6e9adSlinfeng ldxh r0, [r1+2]
1811*fae6e9adSlinfeng exit
1812*fae6e9adSlinfeng ",
1813*fae6e9adSlinfeng [0xaa, 0xbb, 0xff, 0xff, 0xcc, 0xdd],
1814*fae6e9adSlinfeng 0x2211
1815*fae6e9adSlinfeng );
1816*fae6e9adSlinfeng
1817*fae6e9adSlinfeng #[test]
1818*fae6e9adSlinfeng #[ignore]
test_cranelift_string_stack()1819*fae6e9adSlinfeng fn test_cranelift_string_stack() {
1820*fae6e9adSlinfeng let prog = assemble(
1821*fae6e9adSlinfeng "
1822*fae6e9adSlinfeng mov r1, 0x78636261
1823*fae6e9adSlinfeng stxw [r10-8], r1
1824*fae6e9adSlinfeng mov r6, 0x0
1825*fae6e9adSlinfeng stxb [r10-4], r6
1826*fae6e9adSlinfeng stxb [r10-12], r6
1827*fae6e9adSlinfeng mov r1, 0x79636261
1828*fae6e9adSlinfeng stxw [r10-16], r1
1829*fae6e9adSlinfeng mov r1, r10
1830*fae6e9adSlinfeng add r1, -8
1831*fae6e9adSlinfeng mov r2, r1
1832*fae6e9adSlinfeng call 0x4
1833*fae6e9adSlinfeng mov r1, r0
1834*fae6e9adSlinfeng mov r0, 0x1
1835*fae6e9adSlinfeng lsh r1, 0x20
1836*fae6e9adSlinfeng rsh r1, 0x20
1837*fae6e9adSlinfeng jne r1, 0x0, +11
1838*fae6e9adSlinfeng mov r1, r10
1839*fae6e9adSlinfeng add r1, -8
1840*fae6e9adSlinfeng mov r2, r10
1841*fae6e9adSlinfeng add r2, -16
1842*fae6e9adSlinfeng call 0x4
1843*fae6e9adSlinfeng mov r1, r0
1844*fae6e9adSlinfeng lsh r1, 0x20
1845*fae6e9adSlinfeng rsh r1, 0x20
1846*fae6e9adSlinfeng mov r0, 0x1
1847*fae6e9adSlinfeng jeq r1, r6, +1
1848*fae6e9adSlinfeng mov r0, 0x0
1849*fae6e9adSlinfeng exit",
1850*fae6e9adSlinfeng )
1851*fae6e9adSlinfeng .unwrap();
1852*fae6e9adSlinfeng
1853*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmNoData::new(Some(&prog)).unwrap();
1854*fae6e9adSlinfeng vm.register_helper(4, helpers::strcmp).unwrap();
1855*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
1856*fae6e9adSlinfeng assert_eq!(vm.execute_program_cranelift().unwrap(), 0x0);
1857*fae6e9adSlinfeng }
1858*fae6e9adSlinfeng
1859*fae6e9adSlinfeng test_cranelift!(
1860*fae6e9adSlinfeng test_cranelift_stw,
1861*fae6e9adSlinfeng "
1862*fae6e9adSlinfeng stw [r1+2], 0x44332211
1863*fae6e9adSlinfeng ldxw r0, [r1+2]
1864*fae6e9adSlinfeng exit
1865*fae6e9adSlinfeng ",
1866*fae6e9adSlinfeng [0xaa, 0xbb, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xdd],
1867*fae6e9adSlinfeng 0x44332211
1868*fae6e9adSlinfeng );
1869*fae6e9adSlinfeng
1870*fae6e9adSlinfeng test_cranelift!(
1871*fae6e9adSlinfeng test_cranelift_stxb,
1872*fae6e9adSlinfeng "
1873*fae6e9adSlinfeng mov32 r2, 0x11
1874*fae6e9adSlinfeng stxb [r1+2], r2
1875*fae6e9adSlinfeng ldxb r0, [r1+2]
1876*fae6e9adSlinfeng exit
1877*fae6e9adSlinfeng ",
1878*fae6e9adSlinfeng [0xaa, 0xbb, 0xff, 0xcc, 0xdd],
1879*fae6e9adSlinfeng 0x11
1880*fae6e9adSlinfeng );
1881*fae6e9adSlinfeng
1882*fae6e9adSlinfeng test_cranelift!(
1883*fae6e9adSlinfeng test_cranelift_stxb_all,
1884*fae6e9adSlinfeng "
1885*fae6e9adSlinfeng mov r0, 0xf0
1886*fae6e9adSlinfeng mov r2, 0xf2
1887*fae6e9adSlinfeng mov r3, 0xf3
1888*fae6e9adSlinfeng mov r4, 0xf4
1889*fae6e9adSlinfeng mov r5, 0xf5
1890*fae6e9adSlinfeng mov r6, 0xf6
1891*fae6e9adSlinfeng mov r7, 0xf7
1892*fae6e9adSlinfeng mov r8, 0xf8
1893*fae6e9adSlinfeng stxb [r1], r0
1894*fae6e9adSlinfeng stxb [r1+1], r2
1895*fae6e9adSlinfeng stxb [r1+2], r3
1896*fae6e9adSlinfeng stxb [r1+3], r4
1897*fae6e9adSlinfeng stxb [r1+4], r5
1898*fae6e9adSlinfeng stxb [r1+5], r6
1899*fae6e9adSlinfeng stxb [r1+6], r7
1900*fae6e9adSlinfeng stxb [r1+7], r8
1901*fae6e9adSlinfeng ldxdw r0, [r1]
1902*fae6e9adSlinfeng be64 r0
1903*fae6e9adSlinfeng exit
1904*fae6e9adSlinfeng ",
1905*fae6e9adSlinfeng [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
1906*fae6e9adSlinfeng 0xf0f2f3f4f5f6f7f8
1907*fae6e9adSlinfeng );
1908*fae6e9adSlinfeng
1909*fae6e9adSlinfeng test_cranelift!(
1910*fae6e9adSlinfeng test_cranelift_stxb_all2,
1911*fae6e9adSlinfeng "
1912*fae6e9adSlinfeng mov r0, r1
1913*fae6e9adSlinfeng mov r1, 0xf1
1914*fae6e9adSlinfeng mov r9, 0xf9
1915*fae6e9adSlinfeng stxb [r0], r1
1916*fae6e9adSlinfeng stxb [r0+1], r9
1917*fae6e9adSlinfeng ldxh r0, [r0]
1918*fae6e9adSlinfeng be16 r0
1919*fae6e9adSlinfeng exit
1920*fae6e9adSlinfeng ",
1921*fae6e9adSlinfeng [0xff, 0xff],
1922*fae6e9adSlinfeng 0xf1f9
1923*fae6e9adSlinfeng );
1924*fae6e9adSlinfeng
1925*fae6e9adSlinfeng test_cranelift!(
1926*fae6e9adSlinfeng test_cranelift_stxb_chain,
1927*fae6e9adSlinfeng "
1928*fae6e9adSlinfeng mov r0, r1
1929*fae6e9adSlinfeng ldxb r9, [r0+0]
1930*fae6e9adSlinfeng stxb [r0+1], r9
1931*fae6e9adSlinfeng ldxb r8, [r0+1]
1932*fae6e9adSlinfeng stxb [r0+2], r8
1933*fae6e9adSlinfeng ldxb r7, [r0+2]
1934*fae6e9adSlinfeng stxb [r0+3], r7
1935*fae6e9adSlinfeng ldxb r6, [r0+3]
1936*fae6e9adSlinfeng stxb [r0+4], r6
1937*fae6e9adSlinfeng ldxb r5, [r0+4]
1938*fae6e9adSlinfeng stxb [r0+5], r5
1939*fae6e9adSlinfeng ldxb r4, [r0+5]
1940*fae6e9adSlinfeng stxb [r0+6], r4
1941*fae6e9adSlinfeng ldxb r3, [r0+6]
1942*fae6e9adSlinfeng stxb [r0+7], r3
1943*fae6e9adSlinfeng ldxb r2, [r0+7]
1944*fae6e9adSlinfeng stxb [r0+8], r2
1945*fae6e9adSlinfeng ldxb r1, [r0+8]
1946*fae6e9adSlinfeng stxb [r0+9], r1
1947*fae6e9adSlinfeng ldxb r0, [r0+9]
1948*fae6e9adSlinfeng exit
1949*fae6e9adSlinfeng ",
1950*fae6e9adSlinfeng [0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
1951*fae6e9adSlinfeng 0x2a
1952*fae6e9adSlinfeng );
1953*fae6e9adSlinfeng
1954*fae6e9adSlinfeng test_cranelift!(
1955*fae6e9adSlinfeng test_cranelift_stxdw,
1956*fae6e9adSlinfeng "
1957*fae6e9adSlinfeng mov r2, -2005440939
1958*fae6e9adSlinfeng lsh r2, 32
1959*fae6e9adSlinfeng or r2, 0x44332211
1960*fae6e9adSlinfeng stxdw [r1+2], r2
1961*fae6e9adSlinfeng ldxdw r0, [r1+2]
1962*fae6e9adSlinfeng exit
1963*fae6e9adSlinfeng ",
1964*fae6e9adSlinfeng [0xaa, 0xbb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xdd],
1965*fae6e9adSlinfeng 0x8877665544332211
1966*fae6e9adSlinfeng );
1967*fae6e9adSlinfeng
1968*fae6e9adSlinfeng test_cranelift!(
1969*fae6e9adSlinfeng test_cranelift_stxh,
1970*fae6e9adSlinfeng "
1971*fae6e9adSlinfeng mov32 r2, 0x2211
1972*fae6e9adSlinfeng stxh [r1+2], r2
1973*fae6e9adSlinfeng ldxh r0, [r1+2]
1974*fae6e9adSlinfeng exit
1975*fae6e9adSlinfeng ",
1976*fae6e9adSlinfeng [0xaa, 0xbb, 0xff, 0xff, 0xcc, 0xdd],
1977*fae6e9adSlinfeng 0x2211
1978*fae6e9adSlinfeng );
1979*fae6e9adSlinfeng
1980*fae6e9adSlinfeng test_cranelift!(
1981*fae6e9adSlinfeng test_cranelift_stxw,
1982*fae6e9adSlinfeng "
1983*fae6e9adSlinfeng mov32 r2, 0x44332211
1984*fae6e9adSlinfeng stxw [r1+2], r2
1985*fae6e9adSlinfeng ldxw r0, [r1+2]
1986*fae6e9adSlinfeng exit
1987*fae6e9adSlinfeng ",
1988*fae6e9adSlinfeng [0xaa, 0xbb, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xdd],
1989*fae6e9adSlinfeng 0x44332211
1990*fae6e9adSlinfeng );
1991*fae6e9adSlinfeng
1992*fae6e9adSlinfeng test_cranelift!(
1993*fae6e9adSlinfeng test_cranelift_subnet,
1994*fae6e9adSlinfeng "
1995*fae6e9adSlinfeng mov r2, 0xe
1996*fae6e9adSlinfeng ldxh r3, [r1+12]
1997*fae6e9adSlinfeng jne r3, 0x81, +2
1998*fae6e9adSlinfeng mov r2, 0x12
1999*fae6e9adSlinfeng ldxh r3, [r1+16]
2000*fae6e9adSlinfeng and r3, 0xffff
2001*fae6e9adSlinfeng jne r3, 0x8, +5
2002*fae6e9adSlinfeng add r1, r2
2003*fae6e9adSlinfeng mov r0, 0x1
2004*fae6e9adSlinfeng ldxw r1, [r1+16]
2005*fae6e9adSlinfeng and r1, 0xffffff
2006*fae6e9adSlinfeng jeq r1, 0x1a8c0, +1
2007*fae6e9adSlinfeng mov r0, 0x0
2008*fae6e9adSlinfeng exit
2009*fae6e9adSlinfeng ",
2010*fae6e9adSlinfeng [
2011*fae6e9adSlinfeng 0x00, 0x00, 0xc0, 0x9f, 0xa0, 0x97, 0x00, 0xa0, 0xcc, 0x3b, 0xbf, 0xfa, 0x08, 0x00, 0x45,
2012*fae6e9adSlinfeng 0x10, 0x00, 0x3c, 0x46, 0x3c, 0x40, 0x00, 0x40, 0x06, 0x73, 0x1c, 0xc0, 0xa8, 0x01, 0x02,
2013*fae6e9adSlinfeng 0xc0, 0xa8, 0x01, 0x01, 0x06, 0x0e, 0x00, 0x17, 0x99, 0xc5, 0xa0, 0xec, 0x00, 0x00, 0x00,
2014*fae6e9adSlinfeng 0x00, 0xa0, 0x02, 0x7d, 0x78, 0xe0, 0xa3, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4, 0x04, 0x02,
2015*fae6e9adSlinfeng 0x08, 0x0a, 0x00, 0x9c, 0x27, 0x24, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x00,
2016*fae6e9adSlinfeng ],
2017*fae6e9adSlinfeng 0x1
2018*fae6e9adSlinfeng );
2019*fae6e9adSlinfeng
2020*fae6e9adSlinfeng const PROG_TCP_PORT_80: [u8; 152] = [
2021*fae6e9adSlinfeng 0x71, 0x12, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x71, 0x13, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
2022*fae6e9adSlinfeng 0x67, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x4f, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2023*fae6e9adSlinfeng 0xb7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x03, 0x0c, 0x00, 0x08, 0x00, 0x00, 0x00,
2024*fae6e9adSlinfeng 0x71, 0x12, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x02, 0x0a, 0x00, 0x06, 0x00, 0x00, 0x00,
2025*fae6e9adSlinfeng 0x71, 0x12, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x01, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00,
2026*fae6e9adSlinfeng 0x57, 0x02, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x67, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
2027*fae6e9adSlinfeng 0x0f, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69, 0x12, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
2028*fae6e9adSlinfeng 0x15, 0x02, 0x02, 0x00, 0x00, 0x50, 0x00, 0x00, 0x69, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2029*fae6e9adSlinfeng 0x55, 0x01, 0x01, 0x00, 0x00, 0x50, 0x00, 0x00, 0xb7, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
2030*fae6e9adSlinfeng 0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2031*fae6e9adSlinfeng ];
2032*fae6e9adSlinfeng
2033*fae6e9adSlinfeng #[test]
test_cranelift_tcp_port80_match()2034*fae6e9adSlinfeng fn test_cranelift_tcp_port80_match() {
2035*fae6e9adSlinfeng let mem = &mut [
2036*fae6e9adSlinfeng 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x00, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x08, 0x00, 0x45,
2037*fae6e9adSlinfeng 0x00, 0x00, 0x56, 0x00, 0x01, 0x00, 0x00, 0x40, 0x06, 0xf9, 0x4d, 0xc0, 0xa8, 0x00, 0x01,
2038*fae6e9adSlinfeng 0xc0, 0xa8, 0x00, 0x02, 0x27, 0x10, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2039*fae6e9adSlinfeng 0x00, 0x50, 0x02, 0x20, 0x00, 0xc5, 0x18, 0x00, 0x00, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
2040*fae6e9adSlinfeng 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
2041*fae6e9adSlinfeng 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
2042*fae6e9adSlinfeng 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
2043*fae6e9adSlinfeng ];
2044*fae6e9adSlinfeng let prog = &PROG_TCP_PORT_80;
2045*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmRaw::new(Some(prog)).unwrap();
2046*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
2047*fae6e9adSlinfeng assert_eq!(vm.execute_program_cranelift(mem).unwrap(), 0x1);
2048*fae6e9adSlinfeng }
2049*fae6e9adSlinfeng
2050*fae6e9adSlinfeng #[test]
test_cranelift_tcp_port80_nomatch()2051*fae6e9adSlinfeng fn test_cranelift_tcp_port80_nomatch() {
2052*fae6e9adSlinfeng let mem = &mut [
2053*fae6e9adSlinfeng 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x00, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x08, 0x00, 0x45,
2054*fae6e9adSlinfeng 0x00, 0x00, 0x56, 0x00, 0x01, 0x00, 0x00, 0x40, 0x06, 0xf9, 0x4d, 0xc0, 0xa8, 0x00, 0x01,
2055*fae6e9adSlinfeng 0xc0, 0xa8, 0x00, 0x02, 0x00, 0x16, 0x27, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2056*fae6e9adSlinfeng 0x00, 0x51, 0x02, 0x20, 0x00, 0xc5, 0x18, 0x00, 0x00, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
2057*fae6e9adSlinfeng 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
2058*fae6e9adSlinfeng 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
2059*fae6e9adSlinfeng 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
2060*fae6e9adSlinfeng ];
2061*fae6e9adSlinfeng let prog = &PROG_TCP_PORT_80;
2062*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmRaw::new(Some(prog)).unwrap();
2063*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
2064*fae6e9adSlinfeng assert_eq!(vm.execute_program_cranelift(mem).unwrap(), 0x0);
2065*fae6e9adSlinfeng }
2066*fae6e9adSlinfeng
2067*fae6e9adSlinfeng #[test]
test_cranelift_tcp_port80_nomatch_ethertype()2068*fae6e9adSlinfeng fn test_cranelift_tcp_port80_nomatch_ethertype() {
2069*fae6e9adSlinfeng let mem = &mut [
2070*fae6e9adSlinfeng 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x00, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x08, 0x01, 0x45,
2071*fae6e9adSlinfeng 0x00, 0x00, 0x56, 0x00, 0x01, 0x00, 0x00, 0x40, 0x06, 0xf9, 0x4d, 0xc0, 0xa8, 0x00, 0x01,
2072*fae6e9adSlinfeng 0xc0, 0xa8, 0x00, 0x02, 0x27, 0x10, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2073*fae6e9adSlinfeng 0x00, 0x50, 0x02, 0x20, 0x00, 0xc5, 0x18, 0x00, 0x00, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
2074*fae6e9adSlinfeng 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
2075*fae6e9adSlinfeng 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
2076*fae6e9adSlinfeng 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
2077*fae6e9adSlinfeng ];
2078*fae6e9adSlinfeng let prog = &PROG_TCP_PORT_80;
2079*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmRaw::new(Some(prog)).unwrap();
2080*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
2081*fae6e9adSlinfeng assert_eq!(vm.execute_program_cranelift(mem).unwrap(), 0x0);
2082*fae6e9adSlinfeng }
2083*fae6e9adSlinfeng
2084*fae6e9adSlinfeng #[test]
test_cranelift_tcp_port80_nomatch_proto()2085*fae6e9adSlinfeng fn test_cranelift_tcp_port80_nomatch_proto() {
2086*fae6e9adSlinfeng let mem = &mut [
2087*fae6e9adSlinfeng 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x00, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x08, 0x00, 0x45,
2088*fae6e9adSlinfeng 0x00, 0x00, 0x56, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11, 0xf9, 0x4d, 0xc0, 0xa8, 0x00, 0x01,
2089*fae6e9adSlinfeng 0xc0, 0xa8, 0x00, 0x02, 0x27, 0x10, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2090*fae6e9adSlinfeng 0x00, 0x50, 0x02, 0x20, 0x00, 0xc5, 0x18, 0x00, 0x00, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
2091*fae6e9adSlinfeng 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
2092*fae6e9adSlinfeng 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
2093*fae6e9adSlinfeng 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
2094*fae6e9adSlinfeng ];
2095*fae6e9adSlinfeng let prog = &PROG_TCP_PORT_80;
2096*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmRaw::new(Some(prog)).unwrap();
2097*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
2098*fae6e9adSlinfeng assert_eq!(vm.execute_program_cranelift(mem).unwrap(), 0x0);
2099*fae6e9adSlinfeng }
2100*fae6e9adSlinfeng
2101*fae6e9adSlinfeng #[test]
test_cranelift_tcp_sack_match()2102*fae6e9adSlinfeng fn test_cranelift_tcp_sack_match() {
2103*fae6e9adSlinfeng let mut mem = TCP_SACK_MATCH.to_vec();
2104*fae6e9adSlinfeng let prog = assemble(TCP_SACK_ASM).unwrap();
2105*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmRaw::new(Some(&prog)).unwrap();
2106*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
2107*fae6e9adSlinfeng assert_eq!(
2108*fae6e9adSlinfeng vm.execute_program_cranelift(mem.as_mut_slice()).unwrap(),
2109*fae6e9adSlinfeng 0x1
2110*fae6e9adSlinfeng );
2111*fae6e9adSlinfeng }
2112*fae6e9adSlinfeng
2113*fae6e9adSlinfeng #[test]
test_cranelift_tcp_sack_nomatch()2114*fae6e9adSlinfeng fn test_cranelift_tcp_sack_nomatch() {
2115*fae6e9adSlinfeng let mut mem = TCP_SACK_NOMATCH.to_vec();
2116*fae6e9adSlinfeng let prog = assemble(TCP_SACK_ASM).unwrap();
2117*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmRaw::new(Some(&prog)).unwrap();
2118*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
2119*fae6e9adSlinfeng assert_eq!(
2120*fae6e9adSlinfeng vm.execute_program_cranelift(mem.as_mut_slice()).unwrap(),
2121*fae6e9adSlinfeng 0x0
2122*fae6e9adSlinfeng );
2123*fae6e9adSlinfeng }
2124*fae6e9adSlinfeng
2125*fae6e9adSlinfeng #[test]
test_cranelift_ldabsb()2126*fae6e9adSlinfeng fn test_cranelift_ldabsb() {
2127*fae6e9adSlinfeng let prog = &[
2128*fae6e9adSlinfeng 0x30, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2129*fae6e9adSlinfeng 0x00,
2130*fae6e9adSlinfeng ];
2131*fae6e9adSlinfeng let mem = &mut [
2132*fae6e9adSlinfeng 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee,
2133*fae6e9adSlinfeng 0xff,
2134*fae6e9adSlinfeng ];
2135*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmFixedMbuff::new(Some(prog), 0x00, 0x08).unwrap();
2136*fae6e9adSlinfeng
2137*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
2138*fae6e9adSlinfeng assert_eq!(vm.execute_program_cranelift(mem).unwrap(), 0x33);
2139*fae6e9adSlinfeng }
2140*fae6e9adSlinfeng
2141*fae6e9adSlinfeng #[test]
test_cranelift_ldabsh()2142*fae6e9adSlinfeng fn test_cranelift_ldabsh() {
2143*fae6e9adSlinfeng let prog = &[
2144*fae6e9adSlinfeng 0x28, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2145*fae6e9adSlinfeng 0x00,
2146*fae6e9adSlinfeng ];
2147*fae6e9adSlinfeng let mem = &mut [
2148*fae6e9adSlinfeng 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee,
2149*fae6e9adSlinfeng 0xff,
2150*fae6e9adSlinfeng ];
2151*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmFixedMbuff::new(Some(prog), 0x00, 0x08).unwrap();
2152*fae6e9adSlinfeng
2153*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
2154*fae6e9adSlinfeng assert_eq!(vm.execute_program_cranelift(mem).unwrap(), 0x4433);
2155*fae6e9adSlinfeng }
2156*fae6e9adSlinfeng
2157*fae6e9adSlinfeng #[test]
test_cranelift_ldabsw()2158*fae6e9adSlinfeng fn test_cranelift_ldabsw() {
2159*fae6e9adSlinfeng let prog = &[
2160*fae6e9adSlinfeng 0x20, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2161*fae6e9adSlinfeng 0x00,
2162*fae6e9adSlinfeng ];
2163*fae6e9adSlinfeng let mem = &mut [
2164*fae6e9adSlinfeng 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee,
2165*fae6e9adSlinfeng 0xff,
2166*fae6e9adSlinfeng ];
2167*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmFixedMbuff::new(Some(prog), 0x00, 0x08).unwrap();
2168*fae6e9adSlinfeng
2169*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
2170*fae6e9adSlinfeng assert_eq!(vm.execute_program_cranelift(mem).unwrap(), 0x66554433);
2171*fae6e9adSlinfeng }
2172*fae6e9adSlinfeng
2173*fae6e9adSlinfeng #[test]
test_cranelift_ldabsdw()2174*fae6e9adSlinfeng fn test_cranelift_ldabsdw() {
2175*fae6e9adSlinfeng let prog = &[
2176*fae6e9adSlinfeng 0x38, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2177*fae6e9adSlinfeng 0x00,
2178*fae6e9adSlinfeng ];
2179*fae6e9adSlinfeng let mem = &mut [
2180*fae6e9adSlinfeng 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee,
2181*fae6e9adSlinfeng 0xff,
2182*fae6e9adSlinfeng ];
2183*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmFixedMbuff::new(Some(prog), 0x00, 0x08).unwrap();
2184*fae6e9adSlinfeng
2185*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
2186*fae6e9adSlinfeng assert_eq!(
2187*fae6e9adSlinfeng vm.execute_program_cranelift(mem).unwrap(),
2188*fae6e9adSlinfeng 0xaa99887766554433
2189*fae6e9adSlinfeng );
2190*fae6e9adSlinfeng }
2191*fae6e9adSlinfeng
2192*fae6e9adSlinfeng #[test]
test_cranelift_ldindb()2193*fae6e9adSlinfeng fn test_cranelift_ldindb() {
2194*fae6e9adSlinfeng let prog = &[
2195*fae6e9adSlinfeng 0xb7, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x50, 0x10, 0x00, 0x00, 0x03, 0x00, 0x00,
2196*fae6e9adSlinfeng 0x00, 0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2197*fae6e9adSlinfeng ];
2198*fae6e9adSlinfeng let mem = &mut [
2199*fae6e9adSlinfeng 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee,
2200*fae6e9adSlinfeng 0xff,
2201*fae6e9adSlinfeng ];
2202*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmFixedMbuff::new(Some(prog), 0x00, 0x08).unwrap();
2203*fae6e9adSlinfeng
2204*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
2205*fae6e9adSlinfeng assert_eq!(vm.execute_program_cranelift(mem).unwrap(), 0x88);
2206*fae6e9adSlinfeng }
2207*fae6e9adSlinfeng
2208*fae6e9adSlinfeng #[test]
test_cranelift_ldindh()2209*fae6e9adSlinfeng fn test_cranelift_ldindh() {
2210*fae6e9adSlinfeng let prog = &[
2211*fae6e9adSlinfeng 0xb7, 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x48, 0x10, 0x00, 0x00, 0x03, 0x00, 0x00,
2212*fae6e9adSlinfeng 0x00, 0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2213*fae6e9adSlinfeng ];
2214*fae6e9adSlinfeng let mem = &mut [
2215*fae6e9adSlinfeng 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee,
2216*fae6e9adSlinfeng 0xff,
2217*fae6e9adSlinfeng ];
2218*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmFixedMbuff::new(Some(prog), 0x00, 0x08).unwrap();
2219*fae6e9adSlinfeng
2220*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
2221*fae6e9adSlinfeng assert_eq!(vm.execute_program_cranelift(mem).unwrap(), 0x9988);
2222*fae6e9adSlinfeng }
2223*fae6e9adSlinfeng
2224*fae6e9adSlinfeng #[test]
test_cranelift_ldindw()2225*fae6e9adSlinfeng fn test_cranelift_ldindw() {
2226*fae6e9adSlinfeng let prog = &[
2227*fae6e9adSlinfeng 0xb7, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x40, 0x10, 0x00, 0x00, 0x01, 0x00, 0x00,
2228*fae6e9adSlinfeng 0x00, 0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2229*fae6e9adSlinfeng ];
2230*fae6e9adSlinfeng let mem = &mut [
2231*fae6e9adSlinfeng 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee,
2232*fae6e9adSlinfeng 0xff,
2233*fae6e9adSlinfeng ];
2234*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmFixedMbuff::new(Some(prog), 0x00, 0x08).unwrap();
2235*fae6e9adSlinfeng
2236*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
2237*fae6e9adSlinfeng assert_eq!(vm.execute_program_cranelift(mem).unwrap(), 0x88776655);
2238*fae6e9adSlinfeng }
2239*fae6e9adSlinfeng
2240*fae6e9adSlinfeng #[test]
test_cranelift_ldinddw()2241*fae6e9adSlinfeng fn test_cranelift_ldinddw() {
2242*fae6e9adSlinfeng let prog = &[
2243*fae6e9adSlinfeng 0xb7, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x58, 0x10, 0x00, 0x00, 0x03, 0x00, 0x00,
2244*fae6e9adSlinfeng 0x00, 0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2245*fae6e9adSlinfeng ];
2246*fae6e9adSlinfeng let mem = &mut [
2247*fae6e9adSlinfeng 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee,
2248*fae6e9adSlinfeng 0xff,
2249*fae6e9adSlinfeng ];
2250*fae6e9adSlinfeng let mut vm = rbpf::EbpfVmFixedMbuff::new(Some(prog), 0x00, 0x08).unwrap();
2251*fae6e9adSlinfeng
2252*fae6e9adSlinfeng vm.cranelift_compile().unwrap();
2253*fae6e9adSlinfeng assert_eq!(
2254*fae6e9adSlinfeng vm.execute_program_cranelift(mem).unwrap(),
2255*fae6e9adSlinfeng 0xccbbaa9988776655
2256*fae6e9adSlinfeng );
2257*fae6e9adSlinfeng }
2258