|
2 | 2 | * bpf_jit.h: BPF JIT compiler for PPC
|
3 | 3 | *
|
4 | 4 | * Copyright 2011 Matt Evans <[email protected]>, IBM Corporation
|
| 5 | + * 2016 Naveen N. Rao <[email protected]> |
5 | 6 | *
|
6 | 7 | * This program is free software; you can redistribute it and/or
|
7 | 8 | * modify it under the terms of the GNU General Public License
|
|
13 | 14 |
|
14 | 15 | #ifndef __ASSEMBLY__
|
15 | 16 |
|
16 |
| -#ifdef CONFIG_PPC64 |
| 17 | +#include <asm/types.h> |
| 18 | + |
| 19 | +#ifdef PPC64_ELF_ABI_v1 |
17 | 20 | #define FUNCTION_DESCR_SIZE 24
|
18 | 21 | #else
|
19 | 22 | #define FUNCTION_DESCR_SIZE 0
|
|
52 | 55 | ___PPC_RA(base) | IMM_L(i))
|
53 | 56 | #define PPC_STWU(r, base, i) EMIT(PPC_INST_STWU | ___PPC_RS(r) | \
|
54 | 57 | ___PPC_RA(base) | IMM_L(i))
|
| 58 | +#define PPC_STH(r, base, i) EMIT(PPC_INST_STH | ___PPC_RS(r) | \ |
| 59 | + ___PPC_RA(base) | IMM_L(i)) |
| 60 | +#define PPC_STB(r, base, i) EMIT(PPC_INST_STB | ___PPC_RS(r) | \ |
| 61 | + ___PPC_RA(base) | IMM_L(i)) |
55 | 62 |
|
56 | 63 | #define PPC_LBZ(r, base, i) EMIT(PPC_INST_LBZ | ___PPC_RT(r) | \
|
57 | 64 | ___PPC_RA(base) | IMM_L(i))
|
|
63 | 70 | ___PPC_RA(base) | IMM_L(i))
|
64 | 71 | #define PPC_LHBRX(r, base, b) EMIT(PPC_INST_LHBRX | ___PPC_RT(r) | \
|
65 | 72 | ___PPC_RA(base) | ___PPC_RB(b))
|
| 73 | +#define PPC_LDBRX(r, base, b) EMIT(PPC_INST_LDBRX | ___PPC_RT(r) | \ |
| 74 | + ___PPC_RA(base) | ___PPC_RB(b)) |
| 75 | + |
| 76 | +#define PPC_BPF_LDARX(t, a, b, eh) EMIT(PPC_INST_LDARX | ___PPC_RT(t) | \ |
| 77 | + ___PPC_RA(a) | ___PPC_RB(b) | \ |
| 78 | + __PPC_EH(eh)) |
| 79 | +#define PPC_BPF_LWARX(t, a, b, eh) EMIT(PPC_INST_LWARX | ___PPC_RT(t) | \ |
| 80 | + ___PPC_RA(a) | ___PPC_RB(b) | \ |
| 81 | + __PPC_EH(eh)) |
| 82 | +#define PPC_BPF_STWCX(s, a, b) EMIT(PPC_INST_STWCX | ___PPC_RS(s) | \ |
| 83 | + ___PPC_RA(a) | ___PPC_RB(b)) |
| 84 | +#define PPC_BPF_STDCX(s, a, b) EMIT(PPC_INST_STDCX | ___PPC_RS(s) | \ |
| 85 | + ___PPC_RA(a) | ___PPC_RB(b)) |
66 | 86 |
|
67 | 87 | #ifdef CONFIG_PPC64
|
68 | 88 | #define PPC_BPF_LL(r, base, i) do { PPC_LD(r, base, i); } while(0)
|
|
76 | 96 |
|
77 | 97 | #define PPC_CMPWI(a, i) EMIT(PPC_INST_CMPWI | ___PPC_RA(a) | IMM_L(i))
|
78 | 98 | #define PPC_CMPDI(a, i) EMIT(PPC_INST_CMPDI | ___PPC_RA(a) | IMM_L(i))
|
| 99 | +#define PPC_CMPW(a, b) EMIT(PPC_INST_CMPW | ___PPC_RA(a) | \ |
| 100 | + ___PPC_RB(b)) |
| 101 | +#define PPC_CMPD(a, b) EMIT(PPC_INST_CMPD | ___PPC_RA(a) | \ |
| 102 | + ___PPC_RB(b)) |
79 | 103 | #define PPC_CMPLWI(a, i) EMIT(PPC_INST_CMPLWI | ___PPC_RA(a) | IMM_L(i))
|
| 104 | +#define PPC_CMPLDI(a, i) EMIT(PPC_INST_CMPLDI | ___PPC_RA(a) | IMM_L(i)) |
80 | 105 | #define PPC_CMPLW(a, b) EMIT(PPC_INST_CMPLW | ___PPC_RA(a) | \
|
81 | 106 | ___PPC_RB(b))
|
| 107 | +#define PPC_CMPLD(a, b) EMIT(PPC_INST_CMPLD | ___PPC_RA(a) | \ |
| 108 | + ___PPC_RB(b)) |
82 | 109 |
|
83 | 110 | #define PPC_SUB(d, a, b) EMIT(PPC_INST_SUB | ___PPC_RT(d) | \
|
84 | 111 | ___PPC_RB(a) | ___PPC_RA(b))
|
85 | 112 | #define PPC_ADD(d, a, b) EMIT(PPC_INST_ADD | ___PPC_RT(d) | \
|
86 | 113 | ___PPC_RA(a) | ___PPC_RB(b))
|
| 114 | +#define PPC_MULD(d, a, b) EMIT(PPC_INST_MULLD | ___PPC_RT(d) | \ |
| 115 | + ___PPC_RA(a) | ___PPC_RB(b)) |
87 | 116 | #define PPC_MULW(d, a, b) EMIT(PPC_INST_MULLW | ___PPC_RT(d) | \
|
88 | 117 | ___PPC_RA(a) | ___PPC_RB(b))
|
89 | 118 | #define PPC_MULHWU(d, a, b) EMIT(PPC_INST_MULHWU | ___PPC_RT(d) | \
|
|
92 | 121 | ___PPC_RA(a) | IMM_L(i))
|
93 | 122 | #define PPC_DIVWU(d, a, b) EMIT(PPC_INST_DIVWU | ___PPC_RT(d) | \
|
94 | 123 | ___PPC_RA(a) | ___PPC_RB(b))
|
| 124 | +#define PPC_DIVD(d, a, b) EMIT(PPC_INST_DIVD | ___PPC_RT(d) | \ |
| 125 | + ___PPC_RA(a) | ___PPC_RB(b)) |
95 | 126 | #define PPC_AND(d, a, b) EMIT(PPC_INST_AND | ___PPC_RA(d) | \
|
96 | 127 | ___PPC_RS(a) | ___PPC_RB(b))
|
97 | 128 | #define PPC_ANDI(d, a, i) EMIT(PPC_INST_ANDI | ___PPC_RA(d) | \
|
|
100 | 131 | ___PPC_RS(a) | ___PPC_RB(b))
|
101 | 132 | #define PPC_OR(d, a, b) EMIT(PPC_INST_OR | ___PPC_RA(d) | \
|
102 | 133 | ___PPC_RS(a) | ___PPC_RB(b))
|
| 134 | +#define PPC_MR(d, a) PPC_OR(d, a, a) |
103 | 135 | #define PPC_ORI(d, a, i) EMIT(PPC_INST_ORI | ___PPC_RA(d) | \
|
104 | 136 | ___PPC_RS(a) | IMM_L(i))
|
105 | 137 | #define PPC_ORIS(d, a, i) EMIT(PPC_INST_ORIS | ___PPC_RA(d) | \
|
|
110 | 142 | ___PPC_RS(a) | IMM_L(i))
|
111 | 143 | #define PPC_XORIS(d, a, i) EMIT(PPC_INST_XORIS | ___PPC_RA(d) | \
|
112 | 144 | ___PPC_RS(a) | IMM_L(i))
|
| 145 | +#define PPC_EXTSW(d, a) EMIT(PPC_INST_EXTSW | ___PPC_RA(d) | \ |
| 146 | + ___PPC_RS(a)) |
113 | 147 | #define PPC_SLW(d, a, s) EMIT(PPC_INST_SLW | ___PPC_RA(d) | \
|
114 | 148 | ___PPC_RS(a) | ___PPC_RB(s))
|
| 149 | +#define PPC_SLD(d, a, s) EMIT(PPC_INST_SLD | ___PPC_RA(d) | \ |
| 150 | + ___PPC_RS(a) | ___PPC_RB(s)) |
115 | 151 | #define PPC_SRW(d, a, s) EMIT(PPC_INST_SRW | ___PPC_RA(d) | \
|
116 | 152 | ___PPC_RS(a) | ___PPC_RB(s))
|
| 153 | +#define PPC_SRD(d, a, s) EMIT(PPC_INST_SRD | ___PPC_RA(d) | \ |
| 154 | + ___PPC_RS(a) | ___PPC_RB(s)) |
| 155 | +#define PPC_SRAD(d, a, s) EMIT(PPC_INST_SRAD | ___PPC_RA(d) | \ |
| 156 | + ___PPC_RS(a) | ___PPC_RB(s)) |
| 157 | +#define PPC_SRADI(d, a, i) EMIT(PPC_INST_SRADI | ___PPC_RA(d) | \ |
| 158 | + ___PPC_RS(a) | __PPC_SH(i) | \ |
| 159 | + (((i) & 0x20) >> 4)) |
117 | 160 | #define PPC_RLWINM(d, a, i, mb, me) EMIT(PPC_INST_RLWINM | ___PPC_RA(d) | \
|
118 | 161 | ___PPC_RS(a) | __PPC_SH(i) | \
|
119 | 162 | __PPC_MB(mb) | __PPC_ME(me))
|
| 163 | +#define PPC_RLWIMI(d, a, i, mb, me) EMIT(PPC_INST_RLWIMI | ___PPC_RA(d) | \ |
| 164 | + ___PPC_RS(a) | __PPC_SH(i) | \ |
| 165 | + __PPC_MB(mb) | __PPC_ME(me)) |
| 166 | +#define PPC_RLDICL(d, a, i, mb) EMIT(PPC_INST_RLDICL | ___PPC_RA(d) | \ |
| 167 | + ___PPC_RS(a) | __PPC_SH(i) | \ |
| 168 | + __PPC_MB64(mb) | (((i) & 0x20) >> 4)) |
120 | 169 | #define PPC_RLDICR(d, a, i, me) EMIT(PPC_INST_RLDICR | ___PPC_RA(d) | \
|
121 | 170 | ___PPC_RS(a) | __PPC_SH(i) | \
|
122 | 171 | __PPC_ME64(me) | (((i) & 0x20) >> 4))
|
|
127 | 176 | #define PPC_SRWI(d, a, i) PPC_RLWINM(d, a, 32-(i), i, 31)
|
128 | 177 | /* sldi = rldicr Rx, Ry, n, 63-n */
|
129 | 178 | #define PPC_SLDI(d, a, i) PPC_RLDICR(d, a, i, 63-(i))
|
| 179 | +/* sldi = rldicl Rx, Ry, 64-n, n */ |
| 180 | +#define PPC_SRDI(d, a, i) PPC_RLDICL(d, a, 64-(i), i) |
130 | 181 |
|
131 | 182 | #define PPC_NEG(d, a) EMIT(PPC_INST_NEG | ___PPC_RT(d) | ___PPC_RA(a))
|
132 | 183 |
|
|
0 commit comments