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 :
16 * esi : offset of byte(s) to fetch in skb (can be scratched)
17 * r8 : 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 */
27 js bpf_slow_path_word_neg
29 sk_load_word_positive_offset:
30 .globl sk_load_word_positive_offset
33 sub %esi,%eax # hlen - offset
35 jle bpf_slow_path_word
36 mov (SKBDATA,%rsi),%eax
37 bswap %eax /* ntohl() */
44 js bpf_slow_path_half_neg
46 sk_load_half_positive_offset:
47 .globl sk_load_half_positive_offset
50 sub %esi,%eax # hlen - offset
52 jle bpf_slow_path_half
53 movzwl (SKBDATA,%rsi),%eax
61 js bpf_slow_path_byte_neg
63 sk_load_byte_positive_offset:
64 .globl sk_load_byte_positive_offset
66 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
67 jle bpf_slow_path_byte
68 movzbl (SKBDATA,%rsi),%eax
72 * sk_load_byte_msh - BPF_S_LDX_B_MSH helper
74 * Implements BPF_S_LDX_B_MSH : ldxb 4*([offset]&0xf)
75 * Must preserve A accumulator (%eax)
76 * Inputs : %esi is the offset value
79 .globl sk_load_byte_msh
81 js bpf_slow_path_byte_msh_neg
83 sk_load_byte_msh_positive_offset:
84 .globl sk_load_byte_msh_positive_offset
85 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte_msh */
86 jle bpf_slow_path_byte_msh
87 movzbl (SKBDATA,%rsi),%ebx
92 /* rsi contains offset and can be scratched */
93 #define bpf_slow_path_common(LEN) \
94 push %rdi; /* save skb */ \
97 /* rsi already has offset */ \
98 mov $LEN,%ecx; /* len */ \
100 call skb_copy_bits; \
108 bpf_slow_path_common(4)
115 bpf_slow_path_common(2)
123 bpf_slow_path_common(1)
125 movzbl -12(%rbp),%eax
128 bpf_slow_path_byte_msh:
129 xchg %eax,%ebx /* dont lose A , X is about to be scratched */
130 bpf_slow_path_common(1)
132 movzbl -12(%rbp),%eax
138 #define sk_negative_common(SIZE) \
139 push %rdi; /* save skb */ \
142 /* rsi already has offset */ \
143 mov $SIZE,%ecx; /* size */ \
144 call bpf_internal_load_pointer_neg_helper; \
152 bpf_slow_path_word_neg:
153 cmp SKF_MAX_NEG_OFF, %esi /* test range */
154 jl bpf_error /* offset lower -> error */
155 sk_load_word_negative_offset:
156 .globl sk_load_word_negative_offset
157 sk_negative_common(4)
162 bpf_slow_path_half_neg:
163 cmp SKF_MAX_NEG_OFF, %esi
165 sk_load_half_negative_offset:
166 .globl sk_load_half_negative_offset
167 sk_negative_common(2)
173 bpf_slow_path_byte_neg:
174 cmp SKF_MAX_NEG_OFF, %esi
176 sk_load_byte_negative_offset:
177 .globl sk_load_byte_negative_offset
178 sk_negative_common(1)
182 bpf_slow_path_byte_msh_neg:
183 cmp SKF_MAX_NEG_OFF, %esi
185 sk_load_byte_msh_negative_offset:
186 .globl sk_load_byte_msh_negative_offset
187 xchg %eax,%ebx /* dont lose A , X is about to be scratched */
188 sk_negative_common(1)
196 # force a return 0 from jit handler