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/dwarf2.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 */)
30 js bpf_slow_path_word_neg
32 sk_load_word_positive_offset:
33 .globl sk_load_word_positive_offset
36 sub %esi,%eax # hlen - offset
38 jle bpf_slow_path_word
39 mov (SKBDATA,%rsi),%eax
40 bswap %eax /* ntohl() */
47 js bpf_slow_path_half_neg
49 sk_load_half_positive_offset:
50 .globl sk_load_half_positive_offset
53 sub %esi,%eax # hlen - offset
55 jle bpf_slow_path_half
56 movzwl (SKBDATA,%rsi),%eax
64 js bpf_slow_path_byte_neg
66 sk_load_byte_positive_offset:
67 .globl sk_load_byte_positive_offset
69 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
70 jle bpf_slow_path_byte
71 movzbl (SKBDATA,%rsi),%eax
74 /* rsi contains offset and can be scratched */
75 #define bpf_slow_path_common(LEN) \
76 mov %rbx, %rdi; /* arg1 == skb */ \
79 /* rsi already has offset */ \
80 mov $LEN,%ecx; /* len */ \
81 lea - MAX_BPF_STACK + 32(%rbp),%rdx; \
89 bpf_slow_path_common(4)
91 mov - MAX_BPF_STACK + 32(%rbp),%eax
96 bpf_slow_path_common(2)
98 mov - MAX_BPF_STACK + 32(%rbp),%ax
104 bpf_slow_path_common(1)
106 movzbl - MAX_BPF_STACK + 32(%rbp),%eax
109 #define sk_negative_common(SIZE) \
110 mov %rbx, %rdi; /* arg1 == skb */ \
113 /* rsi already has offset */ \
114 mov $SIZE,%edx; /* size */ \
115 call bpf_internal_load_pointer_neg_helper; \
121 bpf_slow_path_word_neg:
122 cmp SKF_MAX_NEG_OFF, %esi /* test range */
123 jl bpf_error /* offset lower -> error */
124 sk_load_word_negative_offset:
125 .globl sk_load_word_negative_offset
126 sk_negative_common(4)
131 bpf_slow_path_half_neg:
132 cmp SKF_MAX_NEG_OFF, %esi
134 sk_load_half_negative_offset:
135 .globl sk_load_half_negative_offset
136 sk_negative_common(2)
142 bpf_slow_path_byte_neg:
143 cmp SKF_MAX_NEG_OFF, %esi
145 sk_load_byte_negative_offset:
146 .globl sk_load_byte_negative_offset
147 sk_negative_common(1)
152 # force a return 0 from jit handler
154 mov - MAX_BPF_STACK(%rbp),%rbx
155 mov - MAX_BPF_STACK + 8(%rbp),%r13
156 mov - MAX_BPF_STACK + 16(%rbp),%r14
157 mov - MAX_BPF_STACK + 24(%rbp),%r15