1 /* bpf_jit.S : BPF JIT helper functions
3 * Copyright (C) 2011 Eric Dumazet (eric.dumazet@gmail.com)
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; version 2
10 #include <linux/linkage.h>
11 #include <asm/frame.h>
14 * Calling convention :
15 * rbx : skb pointer (callee saved)
16 * esi : offset of byte(s) to fetch in skb (can be scratched)
17 * r10 : copy of skb->data
18 * r9d : hlen = skb->len - skb->data_len
21 #define SKF_MAX_NEG_OFF $(-0x200000) /* SKF_LL_OFF from filter.h */
22 #define MAX_BPF_STACK (512 /* from filter.h */ + \
23 32 /* space for rbx,r13,r14,r15 */ + \
24 8 /* space for skb_copy_bits */)
28 .type name, @function; \
33 js bpf_slow_path_word_neg
35 FUNC(sk_load_word_positive_offset)
37 sub %esi,%eax # hlen - offset
39 jle bpf_slow_path_word
40 mov (SKBDATA,%rsi),%eax
41 bswap %eax /* ntohl() */
46 js bpf_slow_path_half_neg
48 FUNC(sk_load_half_positive_offset)
50 sub %esi,%eax # hlen - offset
52 jle bpf_slow_path_half
53 movzwl (SKBDATA,%rsi),%eax
59 js bpf_slow_path_byte_neg
61 FUNC(sk_load_byte_positive_offset)
62 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
63 jle bpf_slow_path_byte
64 movzbl (SKBDATA,%rsi),%eax
67 /* rsi contains offset and can be scratched */
68 #define bpf_slow_path_common(LEN) \
69 lea -MAX_BPF_STACK + 32(%rbp), %rdx;\
71 mov %rbx, %rdi; /* arg1 == skb */ \
74 /* rsi already has offset */ \
75 mov $LEN,%ecx; /* len */ \
84 bpf_slow_path_common(4)
86 mov - MAX_BPF_STACK + 32(%rbp),%eax
91 bpf_slow_path_common(2)
93 mov - MAX_BPF_STACK + 32(%rbp),%ax
99 bpf_slow_path_common(1)
101 movzbl - MAX_BPF_STACK + 32(%rbp),%eax
104 #define sk_negative_common(SIZE) \
106 mov %rbx, %rdi; /* arg1 == skb */ \
109 /* rsi already has offset */ \
110 mov $SIZE,%edx; /* size */ \
111 call bpf_internal_load_pointer_neg_helper; \
118 bpf_slow_path_word_neg:
119 cmp SKF_MAX_NEG_OFF, %esi /* test range */
120 jl bpf_error /* offset lower -> error */
122 FUNC(sk_load_word_negative_offset)
123 sk_negative_common(4)
128 bpf_slow_path_half_neg:
129 cmp SKF_MAX_NEG_OFF, %esi
132 FUNC(sk_load_half_negative_offset)
133 sk_negative_common(2)
139 bpf_slow_path_byte_neg:
140 cmp SKF_MAX_NEG_OFF, %esi
143 FUNC(sk_load_byte_negative_offset)
144 sk_negative_common(1)
149 # force a return 0 from jit handler
151 mov - MAX_BPF_STACK(%rbp),%rbx
152 mov - MAX_BPF_STACK + 8(%rbp),%r13
153 mov - MAX_BPF_STACK + 16(%rbp),%r14
154 mov - MAX_BPF_STACK + 24(%rbp),%r15