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 */
25 .type name, @function; \
30 js bpf_slow_path_word_neg
32 FUNC(sk_load_word_positive_offset)
34 sub %esi,%eax # hlen - offset
36 jle bpf_slow_path_word
37 mov (SKBDATA,%rsi),%eax
38 bswap %eax /* ntohl() */
43 js bpf_slow_path_half_neg
45 FUNC(sk_load_half_positive_offset)
47 sub %esi,%eax # hlen - offset
49 jle bpf_slow_path_half
50 movzwl (SKBDATA,%rsi),%eax
56 js bpf_slow_path_byte_neg
58 FUNC(sk_load_byte_positive_offset)
59 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
60 jle bpf_slow_path_byte
61 movzbl (SKBDATA,%rsi),%eax
64 /* rsi contains offset and can be scratched */
65 #define bpf_slow_path_common(LEN) \
68 mov %rbx, %rdi; /* arg1 == skb */ \
71 /* rsi already has offset */ \
72 mov $LEN,%ecx; /* len */ \
81 bpf_slow_path_common(4)
88 bpf_slow_path_common(2)
96 bpf_slow_path_common(1)
101 #define sk_negative_common(SIZE) \
103 mov %rbx, %rdi; /* arg1 == skb */ \
106 /* rsi already has offset */ \
107 mov $SIZE,%edx; /* size */ \
108 call bpf_internal_load_pointer_neg_helper; \
115 bpf_slow_path_word_neg:
116 cmp SKF_MAX_NEG_OFF, %esi /* test range */
117 jl bpf_error /* offset lower -> error */
119 FUNC(sk_load_word_negative_offset)
120 sk_negative_common(4)
125 bpf_slow_path_half_neg:
126 cmp SKF_MAX_NEG_OFF, %esi
129 FUNC(sk_load_half_negative_offset)
130 sk_negative_common(2)
136 bpf_slow_path_byte_neg:
137 cmp SKF_MAX_NEG_OFF, %esi
140 FUNC(sk_load_byte_negative_offset)
141 sk_negative_common(1)
146 # force a return 0 from jit handler