2 * BPF Jit compiler for s390, help functions.
4 * Copyright IBM Corp. 2012
6 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
8 #include <linux/linkage.h>
12 * registers %r2, %r6-%r8, %r10-%r11, %r13, %r15 are call saved
14 * %r3: offset parameter
15 * %r5: BPF A accumulator
17 * %r9: save register for skb pointer
19 * %r11: skb->len - skb->data_len (headlen)
20 * %r12: BPF X accumulator
22 * skb_copy_bits takes 4 parameters:
24 * %r3 = offset into skb data
25 * %r4 = length to copy
26 * %r5 = pointer to temp buffer
30 /* A = *(u32 *) (skb->data+K+X) */
31 ENTRY(sk_load_word_ind)
32 ar %r3,%r12 # offset += X
33 bmr %r8 # < 0 -> return with cc
35 /* A = *(u32 *) (skb->data+K) */
37 llgfr %r1,%r3 # extend offset
38 ahi %r3,4 # offset + 4
39 clr %r11,%r3 # hlen <= offset + 4 ?
41 l %r5,0(%r1,%r10) # get word from skb
42 xr %r1,%r1 # set cc to zero
46 lgr %r9,%r2 # save %r2
48 la %r5,160(%r15) # pointer to temp buffer
49 brasl %r14,skb_copy_bits # get data from skb
50 l %r5,160(%r15) # load result from temp buffer
51 ltgr %r2,%r2 # set cc to (%r2 != 0)
52 lgr %r2,%r9 # restore %r2
55 /* A = *(u16 *) (skb->data+K+X) */
56 ENTRY(sk_load_half_ind)
57 ar %r3,%r12 # offset += X
58 bmr %r8 # < 0 -> return with cc
60 /* A = *(u16 *) (skb->data+K) */
62 llgfr %r1,%r3 # extend offset
63 ahi %r3,2 # offset + 2
64 clr %r11,%r3 # hlen <= offset + 2 ?
66 llgh %r5,0(%r1,%r10) # get half from skb
67 xr %r1,%r1 # set cc to zero
71 lgr %r9,%r2 # save %r2
73 la %r5,162(%r15) # pointer to temp buffer
74 brasl %r14,skb_copy_bits # get data from skb
75 xc 160(2,%r15),160(%r15)
76 l %r5,160(%r15) # load result from temp buffer
77 ltgr %r2,%r2 # set cc to (%r2 != 0)
78 lgr %r2,%r9 # restore %r2
81 /* A = *(u8 *) (skb->data+K+X) */
82 ENTRY(sk_load_byte_ind)
83 ar %r3,%r12 # offset += X
84 bmr %r8 # < 0 -> return with cc
86 /* A = *(u8 *) (skb->data+K) */
88 llgfr %r1,%r3 # extend offset
89 clr %r11,%r3 # hlen < offset ?
92 ic %r5,0(%r1,%r10) # get byte from skb
93 xr %r1,%r1 # set cc to zero
97 lgr %r9,%r2 # save %r2
99 la %r5,163(%r15) # pointer to temp buffer
100 brasl %r14,skb_copy_bits # get data from skb
101 xc 160(3,%r15),160(%r15)
102 l %r5,160(%r15) # load result from temp buffer
103 ltgr %r2,%r2 # set cc to (%r2 != 0)
104 lgr %r2,%r9 # restore %r2
107 /* A = (*(u8 *)(skb->data+K) & 0xf) << 2 */
108 ENTRY(sk_load_byte_msh)
109 llgfr %r1,%r3 # extend offset
110 clr %r11,%r3 # hlen < offset ?
111 jle sk_load_byte_slow
113 ic %r12,0(%r1,%r10) # get byte from skb
116 xr %r1,%r1 # set cc to zero
119 sk_load_byte_msh_slow:
120 lgr %r9,%r2 # save %r2
122 la %r5,162(%r15) # pointer to temp buffer
123 brasl %r14,skb_copy_bits # get data from skb
124 xc 160(3,%r15),160(%r15)
125 l %r12,160(%r15) # load result from temp buffer
128 ltgr %r2,%r2 # set cc to (%r2 != 0)
129 lgr %r2,%r9 # restore %r2