xref: /openbmc/linux/arch/arm/net/bpf_jit_32.h (revision ddecdfcea0ae891f782ae853771c867ab51024c2)
1*ddecdfceSMircea Gherzan /*
2*ddecdfceSMircea Gherzan  * Just-In-Time compiler for BPF filters on 32bit ARM
3*ddecdfceSMircea Gherzan  *
4*ddecdfceSMircea Gherzan  * Copyright (c) 2011 Mircea Gherzan <mgherzan@gmail.com>
5*ddecdfceSMircea Gherzan  *
6*ddecdfceSMircea Gherzan  * This program is free software; you can redistribute it and/or modify it
7*ddecdfceSMircea Gherzan  * under the terms of the GNU General Public License as published by the
8*ddecdfceSMircea Gherzan  * Free Software Foundation; version 2 of the License.
9*ddecdfceSMircea Gherzan  */
10*ddecdfceSMircea Gherzan 
11*ddecdfceSMircea Gherzan #ifndef PFILTER_OPCODES_ARM_H
12*ddecdfceSMircea Gherzan #define PFILTER_OPCODES_ARM_H
13*ddecdfceSMircea Gherzan 
14*ddecdfceSMircea Gherzan #define ARM_R0	0
15*ddecdfceSMircea Gherzan #define ARM_R1	1
16*ddecdfceSMircea Gherzan #define ARM_R2	2
17*ddecdfceSMircea Gherzan #define ARM_R3	3
18*ddecdfceSMircea Gherzan #define ARM_R4	4
19*ddecdfceSMircea Gherzan #define ARM_R5	5
20*ddecdfceSMircea Gherzan #define ARM_R6	6
21*ddecdfceSMircea Gherzan #define ARM_R7	7
22*ddecdfceSMircea Gherzan #define ARM_R8	8
23*ddecdfceSMircea Gherzan #define ARM_R9	9
24*ddecdfceSMircea Gherzan #define ARM_R10	10
25*ddecdfceSMircea Gherzan #define ARM_FP	11
26*ddecdfceSMircea Gherzan #define ARM_IP	12
27*ddecdfceSMircea Gherzan #define ARM_SP	13
28*ddecdfceSMircea Gherzan #define ARM_LR	14
29*ddecdfceSMircea Gherzan #define ARM_PC	15
30*ddecdfceSMircea Gherzan 
31*ddecdfceSMircea Gherzan #define ARM_COND_EQ		0x0
32*ddecdfceSMircea Gherzan #define ARM_COND_NE		0x1
33*ddecdfceSMircea Gherzan #define ARM_COND_CS		0x2
34*ddecdfceSMircea Gherzan #define ARM_COND_HS		ARM_COND_CS
35*ddecdfceSMircea Gherzan #define ARM_COND_CC		0x3
36*ddecdfceSMircea Gherzan #define ARM_COND_LO		ARM_COND_CC
37*ddecdfceSMircea Gherzan #define ARM_COND_MI		0x4
38*ddecdfceSMircea Gherzan #define ARM_COND_PL		0x5
39*ddecdfceSMircea Gherzan #define ARM_COND_VS		0x6
40*ddecdfceSMircea Gherzan #define ARM_COND_VC		0x7
41*ddecdfceSMircea Gherzan #define ARM_COND_HI		0x8
42*ddecdfceSMircea Gherzan #define ARM_COND_LS		0x9
43*ddecdfceSMircea Gherzan #define ARM_COND_GE		0xa
44*ddecdfceSMircea Gherzan #define ARM_COND_LT		0xb
45*ddecdfceSMircea Gherzan #define ARM_COND_GT		0xc
46*ddecdfceSMircea Gherzan #define ARM_COND_LE		0xd
47*ddecdfceSMircea Gherzan #define ARM_COND_AL		0xe
48*ddecdfceSMircea Gherzan 
49*ddecdfceSMircea Gherzan /* register shift types */
50*ddecdfceSMircea Gherzan #define SRTYPE_LSL		0
51*ddecdfceSMircea Gherzan #define SRTYPE_LSR		1
52*ddecdfceSMircea Gherzan #define SRTYPE_ASR		2
53*ddecdfceSMircea Gherzan #define SRTYPE_ROR		3
54*ddecdfceSMircea Gherzan 
55*ddecdfceSMircea Gherzan #define ARM_INST_ADD_R		0x00800000
56*ddecdfceSMircea Gherzan #define ARM_INST_ADD_I		0x02800000
57*ddecdfceSMircea Gherzan 
58*ddecdfceSMircea Gherzan #define ARM_INST_AND_R		0x00000000
59*ddecdfceSMircea Gherzan #define ARM_INST_AND_I		0x02000000
60*ddecdfceSMircea Gherzan 
61*ddecdfceSMircea Gherzan #define ARM_INST_BIC_R		0x01c00000
62*ddecdfceSMircea Gherzan #define ARM_INST_BIC_I		0x03c00000
63*ddecdfceSMircea Gherzan 
64*ddecdfceSMircea Gherzan #define ARM_INST_B		0x0a000000
65*ddecdfceSMircea Gherzan #define ARM_INST_BX		0x012FFF10
66*ddecdfceSMircea Gherzan #define ARM_INST_BLX_R		0x012fff30
67*ddecdfceSMircea Gherzan 
68*ddecdfceSMircea Gherzan #define ARM_INST_CMP_R		0x01500000
69*ddecdfceSMircea Gherzan #define ARM_INST_CMP_I		0x03500000
70*ddecdfceSMircea Gherzan 
71*ddecdfceSMircea Gherzan #define ARM_INST_LDRB_I		0x05d00000
72*ddecdfceSMircea Gherzan #define ARM_INST_LDRB_R		0x07d00000
73*ddecdfceSMircea Gherzan #define ARM_INST_LDRH_I		0x01d000b0
74*ddecdfceSMircea Gherzan #define ARM_INST_LDR_I		0x05900000
75*ddecdfceSMircea Gherzan 
76*ddecdfceSMircea Gherzan #define ARM_INST_LDM		0x08900000
77*ddecdfceSMircea Gherzan 
78*ddecdfceSMircea Gherzan #define ARM_INST_LSL_I		0x01a00000
79*ddecdfceSMircea Gherzan #define ARM_INST_LSL_R		0x01a00010
80*ddecdfceSMircea Gherzan 
81*ddecdfceSMircea Gherzan #define ARM_INST_LSR_I		0x01a00020
82*ddecdfceSMircea Gherzan #define ARM_INST_LSR_R		0x01a00030
83*ddecdfceSMircea Gherzan 
84*ddecdfceSMircea Gherzan #define ARM_INST_MOV_R		0x01a00000
85*ddecdfceSMircea Gherzan #define ARM_INST_MOV_I		0x03a00000
86*ddecdfceSMircea Gherzan #define ARM_INST_MOVW		0x03000000
87*ddecdfceSMircea Gherzan #define ARM_INST_MOVT		0x03400000
88*ddecdfceSMircea Gherzan 
89*ddecdfceSMircea Gherzan #define ARM_INST_MUL		0x00000090
90*ddecdfceSMircea Gherzan 
91*ddecdfceSMircea Gherzan #define ARM_INST_POP		0x08bd0000
92*ddecdfceSMircea Gherzan #define ARM_INST_PUSH		0x092d0000
93*ddecdfceSMircea Gherzan 
94*ddecdfceSMircea Gherzan #define ARM_INST_ORR_R		0x01800000
95*ddecdfceSMircea Gherzan #define ARM_INST_ORR_I		0x03800000
96*ddecdfceSMircea Gherzan 
97*ddecdfceSMircea Gherzan #define ARM_INST_REV		0x06bf0f30
98*ddecdfceSMircea Gherzan #define ARM_INST_REV16		0x06bf0fb0
99*ddecdfceSMircea Gherzan 
100*ddecdfceSMircea Gherzan #define ARM_INST_RSB_I		0x02600000
101*ddecdfceSMircea Gherzan 
102*ddecdfceSMircea Gherzan #define ARM_INST_SUB_R		0x00400000
103*ddecdfceSMircea Gherzan #define ARM_INST_SUB_I		0x02400000
104*ddecdfceSMircea Gherzan 
105*ddecdfceSMircea Gherzan #define ARM_INST_STR_I		0x05800000
106*ddecdfceSMircea Gherzan 
107*ddecdfceSMircea Gherzan #define ARM_INST_TST_R		0x01100000
108*ddecdfceSMircea Gherzan #define ARM_INST_TST_I		0x03100000
109*ddecdfceSMircea Gherzan 
110*ddecdfceSMircea Gherzan #define ARM_INST_UDIV		0x0730f010
111*ddecdfceSMircea Gherzan 
112*ddecdfceSMircea Gherzan #define ARM_INST_UMULL		0x00800090
113*ddecdfceSMircea Gherzan 
114*ddecdfceSMircea Gherzan /* register */
115*ddecdfceSMircea Gherzan #define _AL3_R(op, rd, rn, rm)	((op ## _R) | (rd) << 12 | (rn) << 16 | (rm))
116*ddecdfceSMircea Gherzan /* immediate */
117*ddecdfceSMircea Gherzan #define _AL3_I(op, rd, rn, imm)	((op ## _I) | (rd) << 12 | (rn) << 16 | (imm))
118*ddecdfceSMircea Gherzan 
119*ddecdfceSMircea Gherzan #define ARM_ADD_R(rd, rn, rm)	_AL3_R(ARM_INST_ADD, rd, rn, rm)
120*ddecdfceSMircea Gherzan #define ARM_ADD_I(rd, rn, imm)	_AL3_I(ARM_INST_ADD, rd, rn, imm)
121*ddecdfceSMircea Gherzan 
122*ddecdfceSMircea Gherzan #define ARM_AND_R(rd, rn, rm)	_AL3_R(ARM_INST_AND, rd, rn, rm)
123*ddecdfceSMircea Gherzan #define ARM_AND_I(rd, rn, imm)	_AL3_I(ARM_INST_AND, rd, rn, imm)
124*ddecdfceSMircea Gherzan 
125*ddecdfceSMircea Gherzan #define ARM_BIC_R(rd, rn, rm)	_AL3_R(ARM_INST_BIC, rd, rn, rm)
126*ddecdfceSMircea Gherzan #define ARM_BIC_I(rd, rn, imm)	_AL3_I(ARM_INST_BIC, rd, rn, imm)
127*ddecdfceSMircea Gherzan 
128*ddecdfceSMircea Gherzan #define ARM_B(imm24)		(ARM_INST_B | ((imm24) & 0xffffff))
129*ddecdfceSMircea Gherzan #define ARM_BX(rm)		(ARM_INST_BX | (rm))
130*ddecdfceSMircea Gherzan #define ARM_BLX_R(rm)		(ARM_INST_BLX_R | (rm))
131*ddecdfceSMircea Gherzan 
132*ddecdfceSMircea Gherzan #define ARM_CMP_R(rn, rm)	_AL3_R(ARM_INST_CMP, 0, rn, rm)
133*ddecdfceSMircea Gherzan #define ARM_CMP_I(rn, imm)	_AL3_I(ARM_INST_CMP, 0, rn, imm)
134*ddecdfceSMircea Gherzan 
135*ddecdfceSMircea Gherzan #define ARM_LDR_I(rt, rn, off)	(ARM_INST_LDR_I | (rt) << 12 | (rn) << 16 \
136*ddecdfceSMircea Gherzan 				 | (off))
137*ddecdfceSMircea Gherzan #define ARM_LDRB_I(rt, rn, off)	(ARM_INST_LDRB_I | (rt) << 12 | (rn) << 16 \
138*ddecdfceSMircea Gherzan 				 | (off))
139*ddecdfceSMircea Gherzan #define ARM_LDRB_R(rt, rn, rm)	(ARM_INST_LDRB_R | (rt) << 12 | (rn) << 16 \
140*ddecdfceSMircea Gherzan 				 | (rm))
141*ddecdfceSMircea Gherzan #define ARM_LDRH_I(rt, rn, off)	(ARM_INST_LDRH_I | (rt) << 12 | (rn) << 16 \
142*ddecdfceSMircea Gherzan 				 | (((off) & 0xf0) << 4) | ((off) & 0xf))
143*ddecdfceSMircea Gherzan 
144*ddecdfceSMircea Gherzan #define ARM_LDM(rn, regs)	(ARM_INST_LDM | (rn) << 16 | (regs))
145*ddecdfceSMircea Gherzan 
146*ddecdfceSMircea Gherzan #define ARM_LSL_R(rd, rn, rm)	(_AL3_R(ARM_INST_LSL, rd, 0, rn) | (rm) << 8)
147*ddecdfceSMircea Gherzan #define ARM_LSL_I(rd, rn, imm)	(_AL3_I(ARM_INST_LSL, rd, 0, rn) | (imm) << 7)
148*ddecdfceSMircea Gherzan 
149*ddecdfceSMircea Gherzan #define ARM_LSR_R(rd, rn, rm)	(_AL3_R(ARM_INST_LSR, rd, 0, rn) | (rm) << 8)
150*ddecdfceSMircea Gherzan #define ARM_LSR_I(rd, rn, imm)	(_AL3_I(ARM_INST_LSR, rd, 0, rn) | (imm) << 7)
151*ddecdfceSMircea Gherzan 
152*ddecdfceSMircea Gherzan #define ARM_MOV_R(rd, rm)	_AL3_R(ARM_INST_MOV, rd, 0, rm)
153*ddecdfceSMircea Gherzan #define ARM_MOV_I(rd, imm)	_AL3_I(ARM_INST_MOV, rd, 0, imm)
154*ddecdfceSMircea Gherzan 
155*ddecdfceSMircea Gherzan #define ARM_MOVW(rd, imm)	\
156*ddecdfceSMircea Gherzan 	(ARM_INST_MOVW | ((imm) >> 12) << 16 | (rd) << 12 | ((imm) & 0x0fff))
157*ddecdfceSMircea Gherzan 
158*ddecdfceSMircea Gherzan #define ARM_MOVT(rd, imm)	\
159*ddecdfceSMircea Gherzan 	(ARM_INST_MOVT | ((imm) >> 12) << 16 | (rd) << 12 | ((imm) & 0x0fff))
160*ddecdfceSMircea Gherzan 
161*ddecdfceSMircea Gherzan #define ARM_MUL(rd, rm, rn)	(ARM_INST_MUL | (rd) << 16 | (rm) << 8 | (rn))
162*ddecdfceSMircea Gherzan 
163*ddecdfceSMircea Gherzan #define ARM_POP(regs)		(ARM_INST_POP | (regs))
164*ddecdfceSMircea Gherzan #define ARM_PUSH(regs)		(ARM_INST_PUSH | (regs))
165*ddecdfceSMircea Gherzan 
166*ddecdfceSMircea Gherzan #define ARM_ORR_R(rd, rn, rm)	_AL3_R(ARM_INST_ORR, rd, rn, rm)
167*ddecdfceSMircea Gherzan #define ARM_ORR_I(rd, rn, imm)	_AL3_I(ARM_INST_ORR, rd, rn, imm)
168*ddecdfceSMircea Gherzan #define ARM_ORR_S(rd, rn, rm, type, rs)	\
169*ddecdfceSMircea Gherzan 	(ARM_ORR_R(rd, rn, rm) | (type) << 5 | (rs) << 7)
170*ddecdfceSMircea Gherzan 
171*ddecdfceSMircea Gherzan #define ARM_REV(rd, rm)		(ARM_INST_REV | (rd) << 12 | (rm))
172*ddecdfceSMircea Gherzan #define ARM_REV16(rd, rm)	(ARM_INST_REV16 | (rd) << 12 | (rm))
173*ddecdfceSMircea Gherzan 
174*ddecdfceSMircea Gherzan #define ARM_RSB_I(rd, rn, imm)	_AL3_I(ARM_INST_RSB, rd, rn, imm)
175*ddecdfceSMircea Gherzan 
176*ddecdfceSMircea Gherzan #define ARM_SUB_R(rd, rn, rm)	_AL3_R(ARM_INST_SUB, rd, rn, rm)
177*ddecdfceSMircea Gherzan #define ARM_SUB_I(rd, rn, imm)	_AL3_I(ARM_INST_SUB, rd, rn, imm)
178*ddecdfceSMircea Gherzan 
179*ddecdfceSMircea Gherzan #define ARM_STR_I(rt, rn, off)	(ARM_INST_STR_I | (rt) << 12 | (rn) << 16 \
180*ddecdfceSMircea Gherzan 				 | (off))
181*ddecdfceSMircea Gherzan 
182*ddecdfceSMircea Gherzan #define ARM_TST_R(rn, rm)	_AL3_R(ARM_INST_TST, 0, rn, rm)
183*ddecdfceSMircea Gherzan #define ARM_TST_I(rn, imm)	_AL3_I(ARM_INST_TST, 0, rn, imm)
184*ddecdfceSMircea Gherzan 
185*ddecdfceSMircea Gherzan #define ARM_UDIV(rd, rn, rm)	(ARM_INST_UDIV | (rd) << 16 | (rn) | (rm) << 8)
186*ddecdfceSMircea Gherzan 
187*ddecdfceSMircea Gherzan #define ARM_UMULL(rd_lo, rd_hi, rn, rm)	(ARM_INST_UMULL | (rd_hi) << 16 \
188*ddecdfceSMircea Gherzan 					 | (rd_lo) << 12 | (rm) << 8 | rn)
189*ddecdfceSMircea Gherzan 
190*ddecdfceSMircea Gherzan #endif /* PFILTER_OPCODES_ARM_H */
191