2 * bpf_jit32.h: BPF JIT compiler for PPC
4 * Copyright 2011 Matt Evans <matt@ozlabs.org>, IBM Corporation
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; version 2
19 #define BPF_PPC_STACK_R3_OFF 48
20 #define BPF_PPC_STACK_LOCALS 32
21 #define BPF_PPC_STACK_BASIC (48+64)
22 #define BPF_PPC_STACK_SAVE (18*8)
23 #define BPF_PPC_STACKFRAME (BPF_PPC_STACK_BASIC+BPF_PPC_STACK_LOCALS+ \
25 #define BPF_PPC_SLOWPATH_FRAME (48+64)
27 #define BPF_PPC_STACK_R3_OFF 24
28 #define BPF_PPC_STACK_LOCALS 16
29 #define BPF_PPC_STACK_BASIC (24+32)
30 #define BPF_PPC_STACK_SAVE (18*4)
31 #define BPF_PPC_STACKFRAME (BPF_PPC_STACK_BASIC+BPF_PPC_STACK_LOCALS+ \
33 #define BPF_PPC_SLOWPATH_FRAME (24+32)
36 #define REG_SZ (BITS_PER_LONG/8)
39 * Generated code register usage:
41 * As normal PPC C ABI (e.g. r1=sp, r2=TOC), with:
43 * skb r3 (Entry parameter)
49 * skb headlen r15 (skb->len - skb->data_len)
68 * Assembly helpers from arch/powerpc/net/bpf_jit.S:
70 #define DECLARE_LOAD_FUNC(func) \
71 extern u8 func[], func##_negative_offset[], func##_positive_offset[]
73 DECLARE_LOAD_FUNC(sk_load_word
);
74 DECLARE_LOAD_FUNC(sk_load_half
);
75 DECLARE_LOAD_FUNC(sk_load_byte
);
76 DECLARE_LOAD_FUNC(sk_load_byte_msh
);
78 #define PPC_LBZ_OFFS(r, base, i) do { if ((i) < 32768) PPC_LBZ(r, base, i); \
79 else { PPC_ADDIS(r, base, IMM_HA(i)); \
80 PPC_LBZ(r, r, IMM_L(i)); } } while(0)
82 #define PPC_LD_OFFS(r, base, i) do { if ((i) < 32768) PPC_LD(r, base, i); \
83 else { PPC_ADDIS(r, base, IMM_HA(i)); \
84 PPC_LD(r, r, IMM_L(i)); } } while(0)
86 #define PPC_LWZ_OFFS(r, base, i) do { if ((i) < 32768) PPC_LWZ(r, base, i); \
87 else { PPC_ADDIS(r, base, IMM_HA(i)); \
88 PPC_LWZ(r, r, IMM_L(i)); } } while(0)
90 #define PPC_LHZ_OFFS(r, base, i) do { if ((i) < 32768) PPC_LHZ(r, base, i); \
91 else { PPC_ADDIS(r, base, IMM_HA(i)); \
92 PPC_LHZ(r, r, IMM_L(i)); } } while(0)
95 #define PPC_LL_OFFS(r, base, i) do { PPC_LD_OFFS(r, base, i); } while(0)
97 #define PPC_LL_OFFS(r, base, i) do { PPC_LWZ_OFFS(r, base, i); } while(0)
102 #define PPC_BPF_LOAD_CPU(r) \
103 do { BUILD_BUG_ON(FIELD_SIZEOF(struct paca_struct, paca_index) != 2); \
104 PPC_LHZ_OFFS(r, 13, offsetof(struct paca_struct, paca_index)); \
107 #define PPC_BPF_LOAD_CPU(r) \
108 do { BUILD_BUG_ON(FIELD_SIZEOF(struct thread_info, cpu) != 4); \
109 PPC_LHZ_OFFS(r, (1 & ~(THREAD_SIZE - 1)), \
110 offsetof(struct thread_info, cpu)); \
114 #define PPC_BPF_LOAD_CPU(r) do { PPC_LI(r, 0); } while(0)
117 #define PPC_LHBRX_OFFS(r, base, i) \
118 do { PPC_LI32(r, i); PPC_LHBRX(r, r, base); } while(0)
119 #ifdef __LITTLE_ENDIAN__
120 #define PPC_NTOHS_OFFS(r, base, i) PPC_LHBRX_OFFS(r, base, i)
122 #define PPC_NTOHS_OFFS(r, base, i) PPC_LHZ_OFFS(r, base, i)
125 #define PPC_BPF_LL(r, base, i) do { PPC_LWZ(r, base, i); } while(0)
126 #define PPC_BPF_STL(r, base, i) do { PPC_STW(r, base, i); } while(0)
127 #define PPC_BPF_STLU(r, base, i) do { PPC_STWU(r, base, i); } while(0)
129 #define SEEN_DATAREF 0x10000 /* might call external helpers */
130 #define SEEN_XREG 0x20000 /* X reg is used */
131 #define SEEN_MEM 0x40000 /* SEEN_MEM+(1<<n) = use mem[n] for temporary
133 #define SEEN_MEM_MSK 0x0ffff
135 struct codegen_context
{
138 int pc_ret0
; /* bpf index of first RET #0 instruction (if any) */