1 /* SPDX-License-Identifier: GPL-2.0 */
2 #include <asm/ptrace.h>
4 #include "bpf_jit_64.h"
7 #define SCRATCH_OFF STACK_BIAS + 128
8 #define BE_PTR(label) be,pn %xcc, label
9 #define SIGN_EXTEND(reg) sra reg, 0, reg
11 #define SKF_MAX_NEG_OFF (-0x200000) /* SKF_LL_OFF from filter.h */
14 .globl bpf_jit_load_word
17 bl bpf_slow_path_word_neg
19 .globl bpf_jit_load_word_positive_offset
20 bpf_jit_load_word_positive_offset:
21 sub r_HEADLEN, r_OFF, r_TMP
23 ble bpf_slow_path_word
24 add r_SKB_DATA, r_OFF, r_TMP
26 bne load_word_unaligned
31 ldub [r_TMP + 0x0], r_OFF
32 ldub [r_TMP + 0x1], r_TMP2
34 or r_OFF, r_TMP2, r_OFF
35 ldub [r_TMP + 0x2], r_TMP2
37 or r_OFF, r_TMP2, r_OFF
38 ldub [r_TMP + 0x3], r_TMP2
41 or r_OFF, r_TMP2, r_RESULT
43 .globl bpf_jit_load_half
46 bl bpf_slow_path_half_neg
48 .globl bpf_jit_load_half_positive_offset
49 bpf_jit_load_half_positive_offset:
50 sub r_HEADLEN, r_OFF, r_TMP
52 ble bpf_slow_path_half
53 add r_SKB_DATA, r_OFF, r_TMP
55 bne load_half_unaligned
58 lduh [r_TMP], r_RESULT
60 ldub [r_TMP + 0x0], r_OFF
61 ldub [r_TMP + 0x1], r_TMP2
64 or r_OFF, r_TMP2, r_RESULT
66 .globl bpf_jit_load_byte
69 bl bpf_slow_path_byte_neg
71 .globl bpf_jit_load_byte_positive_offset
72 bpf_jit_load_byte_positive_offset:
74 bge bpf_slow_path_byte
77 ldub [r_SKB_DATA + r_OFF], r_RESULT
79 #define bpf_slow_path_common(LEN) \
80 save %sp, -SAVE_SZ, %sp; \
83 add %fp, SCRATCH_OFF, %o2; \
90 bpf_slow_path_common(4)
92 ld [%sp + SCRATCH_OFF], r_RESULT
96 bpf_slow_path_common(2)
98 lduh [%sp + SCRATCH_OFF], r_RESULT
102 bpf_slow_path_common(1)
104 ldub [%sp + SCRATCH_OFF], r_RESULT
108 #define bpf_negative_common(LEN) \
109 save %sp, -SAVE_SZ, %sp; \
113 call bpf_internal_load_pointer_neg_helper; \
120 bpf_slow_path_word_neg:
121 sethi %hi(SKF_MAX_NEG_OFF), r_TMP
125 .globl bpf_jit_load_word_negative_offset
126 bpf_jit_load_word_negative_offset:
127 bpf_negative_common(4)
129 bne load_word_unaligned
134 bpf_slow_path_half_neg:
135 sethi %hi(SKF_MAX_NEG_OFF), r_TMP
139 .globl bpf_jit_load_half_negative_offset
140 bpf_jit_load_half_negative_offset:
141 bpf_negative_common(2)
143 bne load_half_unaligned
146 lduh [r_TMP], r_RESULT
148 bpf_slow_path_byte_neg:
149 sethi %hi(SKF_MAX_NEG_OFF), r_TMP
153 .globl bpf_jit_load_byte_negative_offset
154 bpf_jit_load_byte_negative_offset:
155 bpf_negative_common(1)
157 ldub [r_TMP], r_RESULT
160 /* Make the JIT program itself return zero. */
162 restore %g0, %g0, %o0