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
23 .globl sk_load_word_ind
25 add %ebx,%esi /* offset += X */
26 # test %esi,%esi /* if (offset < 0) goto bpf_error; */
33 sub %esi,%eax # hlen - offset
35 jle bpf_slow_path_word
36 mov (SKBDATA,%rsi),%eax
37 bswap %eax /* ntohl() */
42 .globl sk_load_half_ind
44 add %ebx,%esi /* offset += X */
51 sub %esi,%eax # hlen - offset
53 jle bpf_slow_path_half
54 movzwl (SKBDATA,%rsi),%eax
59 .globl sk_load_byte_ind
60 add %ebx,%esi /* offset += X */
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, already known positive
78 ENTRY(sk_load_byte_msh)
80 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte_msh */
81 jle bpf_slow_path_byte_msh
82 movzbl (SKBDATA,%rsi),%ebx
87 ENDPROC(sk_load_byte_msh)
90 # force a return 0 from jit handler
96 /* rsi contains offset and can be scratched */
97 #define bpf_slow_path_common(LEN) \
98 push %rdi; /* save skb */ \
101 /* rsi already has offset */ \
102 mov $LEN,%ecx; /* len */ \
103 lea -12(%rbp),%rdx; \
104 call skb_copy_bits; \
112 bpf_slow_path_common(4)
119 bpf_slow_path_common(2)
127 bpf_slow_path_common(1)
129 movzbl -12(%rbp),%eax
132 bpf_slow_path_byte_msh:
133 xchg %eax,%ebx /* dont lose A , X is about to be scratched */
134 bpf_slow_path_common(1)
136 movzbl -12(%rbp),%eax