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>
13 * Calling convention :
14 * rbx : skb pointer (callee saved)
15 * esi : offset of byte(s) to fetch in skb (can be scratched)
16 * r10 : copy of skb->data
17 * r9d : hlen = skb->len - skb->data_len
20 #define SKF_MAX_NEG_OFF $(-0x200000) /* SKF_LL_OFF from filter.h */
21 #define MAX_BPF_STACK (512 /* from filter.h */ + \
22 32 /* space for rbx,r13,r14,r15 */ + \
23 8 /* space for skb_copy_bits */)
29 js bpf_slow_path_word_neg
31 sk_load_word_positive_offset:
32 .globl sk_load_word_positive_offset
35 sub %esi,%eax # hlen - offset
37 jle bpf_slow_path_word
38 mov (SKBDATA,%rsi),%eax
39 bswap %eax /* ntohl() */
46 js bpf_slow_path_half_neg
48 sk_load_half_positive_offset:
49 .globl sk_load_half_positive_offset
52 sub %esi,%eax # hlen - offset
54 jle bpf_slow_path_half
55 movzwl (SKBDATA,%rsi),%eax
63 js bpf_slow_path_byte_neg
65 sk_load_byte_positive_offset:
66 .globl sk_load_byte_positive_offset
68 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
69 jle bpf_slow_path_byte
70 movzbl (SKBDATA,%rsi),%eax
73 /* rsi contains offset and can be scratched */
74 #define bpf_slow_path_common(LEN) \
75 mov %rbx, %rdi; /* arg1 == skb */ \
78 /* rsi already has offset */ \
79 mov $LEN,%ecx; /* len */ \
80 lea - MAX_BPF_STACK + 32(%rbp),%rdx; \
88 bpf_slow_path_common(4)
90 mov - MAX_BPF_STACK + 32(%rbp),%eax
95 bpf_slow_path_common(2)
97 mov - MAX_BPF_STACK + 32(%rbp),%ax
103 bpf_slow_path_common(1)
105 movzbl - MAX_BPF_STACK + 32(%rbp),%eax
108 #define sk_negative_common(SIZE) \
109 mov %rbx, %rdi; /* arg1 == skb */ \
112 /* rsi already has offset */ \
113 mov $SIZE,%edx; /* size */ \
114 call bpf_internal_load_pointer_neg_helper; \
120 bpf_slow_path_word_neg:
121 cmp SKF_MAX_NEG_OFF, %esi /* test range */
122 jl bpf_error /* offset lower -> error */
123 sk_load_word_negative_offset:
124 .globl sk_load_word_negative_offset
125 sk_negative_common(4)
130 bpf_slow_path_half_neg:
131 cmp SKF_MAX_NEG_OFF, %esi
133 sk_load_half_negative_offset:
134 .globl sk_load_half_negative_offset
135 sk_negative_common(2)
141 bpf_slow_path_byte_neg:
142 cmp SKF_MAX_NEG_OFF, %esi
144 sk_load_byte_negative_offset:
145 .globl sk_load_byte_negative_offset
146 sk_negative_common(1)
151 # force a return 0 from jit handler
153 mov - MAX_BPF_STACK(%rbp),%rbx
154 mov - MAX_BPF_STACK + 8(%rbp),%r13
155 mov - MAX_BPF_STACK + 16(%rbp),%r14
156 mov - MAX_BPF_STACK + 24(%rbp),%r15