| 1 |
/* |
| 2 |
The following codes come from ppc-codegen.h: |
| 3 |
|
| 4 |
Copyright (C) 2001 Radek Doulik |
| 5 |
|
| 6 |
for testing do the following: ./test | as -o test.o |
| 7 |
*/ |
| 8 |
|
| 9 |
#ifndef __MONO_PPC_CODEGEN_H__ |
| 10 |
#define __MONO_PPC_CODEGEN_H__ |
| 11 |
#include <assert.h> |
| 12 |
|
| 13 |
typedef enum { |
| 14 |
ppc_r0 = 0, |
| 15 |
ppc_r1, |
| 16 |
ppc_sp = ppc_r1, |
| 17 |
ppc_r2, |
| 18 |
ppc_r3, |
| 19 |
ppc_r4, |
| 20 |
ppc_r5, |
| 21 |
ppc_r6, |
| 22 |
ppc_r7, |
| 23 |
ppc_r8, |
| 24 |
ppc_r9, |
| 25 |
ppc_r10, |
| 26 |
ppc_r11, |
| 27 |
ppc_r12, |
| 28 |
ppc_r13, |
| 29 |
ppc_r14, |
| 30 |
ppc_r15, |
| 31 |
ppc_r16, |
| 32 |
ppc_r17, |
| 33 |
ppc_r18, |
| 34 |
ppc_r19, |
| 35 |
ppc_r20, |
| 36 |
ppc_r21, |
| 37 |
ppc_r22, |
| 38 |
ppc_r23, |
| 39 |
ppc_r24, |
| 40 |
ppc_r25, |
| 41 |
ppc_r26, |
| 42 |
ppc_r27, |
| 43 |
ppc_r28, |
| 44 |
ppc_r29, |
| 45 |
ppc_r30, |
| 46 |
ppc_r31 |
| 47 |
} PPCIntRegister; |
| 48 |
|
| 49 |
typedef enum { |
| 50 |
ppc_f0 = 0, |
| 51 |
ppc_f1, |
| 52 |
ppc_f2, |
| 53 |
ppc_f3, |
| 54 |
ppc_f4, |
| 55 |
ppc_f5, |
| 56 |
ppc_f6, |
| 57 |
ppc_f7, |
| 58 |
ppc_f8, |
| 59 |
ppc_f9, |
| 60 |
ppc_f10, |
| 61 |
ppc_f11, |
| 62 |
ppc_f12, |
| 63 |
ppc_f13, |
| 64 |
ppc_f14, |
| 65 |
ppc_f15, |
| 66 |
ppc_f16, |
| 67 |
ppc_f17, |
| 68 |
ppc_f18, |
| 69 |
ppc_f19, |
| 70 |
ppc_f20, |
| 71 |
ppc_f21, |
| 72 |
ppc_f22, |
| 73 |
ppc_f23, |
| 74 |
ppc_f24, |
| 75 |
ppc_f25, |
| 76 |
ppc_f26, |
| 77 |
ppc_f27, |
| 78 |
ppc_f28, |
| 79 |
ppc_f29, |
| 80 |
ppc_f30, |
| 81 |
ppc_f31 |
| 82 |
} PPCFloatRegister; |
| 83 |
|
| 84 |
typedef enum { |
| 85 |
ppc_lr = 256, |
| 86 |
ppc_ctr = 256 + 32, |
| 87 |
ppc_xer = 32 |
| 88 |
} PPCSpecialRegister; |
| 89 |
|
| 90 |
enum { |
| 91 |
/* B0 operand for branches */ |
| 92 |
PPC_BR_DEC_CTR_NONZERO_FALSE = 0, |
| 93 |
PPC_BR_LIKELY = 1, /* can be or'ed with the conditional variants */ |
| 94 |
PPC_BR_DEC_CTR_ZERO_FALSE = 2, |
| 95 |
PPC_BR_FALSE = 4, |
| 96 |
PPC_BR_DEC_CTR_NONZERO_TRUE = 8, |
| 97 |
PPC_BR_DEC_CTR_ZERO_TRUE = 10, |
| 98 |
PPC_BR_TRUE = 12, |
| 99 |
PPC_BR_DEC_CTR_NONZERO = 16, |
| 100 |
PPC_BR_DEC_CTR_ZERO = 18, |
| 101 |
PPC_BR_ALWAYS = 20, |
| 102 |
/* B1 operand for branches */ |
| 103 |
PPC_BR_LT = 0, |
| 104 |
PPC_BR_GT = 1, |
| 105 |
PPC_BR_EQ = 2, |
| 106 |
PPC_BR_SO = 3, |
| 107 |
}; |
| 108 |
|
| 109 |
enum { |
| 110 |
PPC_TRAP_LT = 1, |
| 111 |
PPC_TRAP_GT = 2, |
| 112 |
PPC_TRAP_EQ = 4, |
| 113 |
PPC_TRAP_LT_UN = 8, |
| 114 |
PPC_TRAP_GT_UN = 16, |
| 115 |
PPC_TRAP_LE = 1 + PPC_TRAP_EQ, |
| 116 |
PPC_TRAP_GE = 2 + PPC_TRAP_EQ, |
| 117 |
PPC_TRAP_LE_UN = 8 + PPC_TRAP_EQ, |
| 118 |
PPC_TRAP_GE_UN = 16 + PPC_TRAP_EQ |
| 119 |
}; |
| 120 |
|
| 121 |
#define ppc_emit32(c,x) do { *((unsigned int *) (c)) = x; (c) = (unsigned char *)(c) + sizeof (unsigned int);} while (0) |
| 122 |
|
| 123 |
#define ppc_is_imm16(val) ((int)(val) >= (int)-(1<<15) && (int)(val) <= (int)((1<<15)-1)) |
| 124 |
#define ppc_is_uimm16(val) ((int)(val) >= 0 && (int)(val) <= 65535) |
| 125 |
|
| 126 |
#define ppc_load(c,D,v) do { \ |
| 127 |
if (ppc_is_imm16 ((v))) { \ |
| 128 |
ppc_li ((c), (D), (unsigned short)(v)); \ |
| 129 |
} else { \ |
| 130 |
ppc_lis ((c), (D), (unsigned int)(v) >> 16); \ |
| 131 |
ppc_ori ((c), (D), (D), (unsigned int)(v) & 0xffff); \ |
| 132 |
} \ |
| 133 |
} while (0) |
| 134 |
|
| 135 |
#define ppc_break(c) ppc_tw((c),31,0,0) |
| 136 |
#define ppc_addi(c,D,A,d) ppc_emit32 (c, (14 << 26) | ((D) << 21) | ((A) << 16) | (unsigned short)(d)) |
| 137 |
#define ppc_addis(c,D,A,d) ppc_emit32 (c, (15 << 26) | ((D) << 21) | ((A) << 16) | (unsigned short)(d)) |
| 138 |
#define ppc_li(c,D,v) ppc_addi (c, D, 0, (unsigned short)(v)); |
| 139 |
#define ppc_lis(c,D,v) ppc_addis (c, D, 0, (unsigned short)(v)); |
| 140 |
#define ppc_lwz(c,D,d,a) ppc_emit32 (c, (32 << 26) | ((D) << 21) | ((a) << 16) | (unsigned short)(d)) |
| 141 |
#define ppc_lhz(c,D,d,a) ppc_emit32 (c, (40 << 26) | ((D) << 21) | ((a) << 16) | (unsigned short)(d)) |
| 142 |
#define ppc_lbz(c,D,d,a) ppc_emit32 (c, (34 << 26) | ((D) << 21) | ((a) << 16) | (unsigned short)(d)) |
| 143 |
#define ppc_stw(c,S,d,a) ppc_emit32 (c, (36 << 26) | ((S) << 21) | ((a) << 16) | (unsigned short)(d)) |
| 144 |
#define ppc_sth(c,S,d,a) ppc_emit32 (c, (44 << 26) | ((S) << 21) | ((a) << 16) | (unsigned short)(d)) |
| 145 |
#define ppc_stb(c,S,d,a) ppc_emit32 (c, (38 << 26) | ((S) << 21) | ((a) << 16) | (unsigned short)(d)) |
| 146 |
#define ppc_stwu(c,s,d,a) ppc_emit32 (c, (37 << 26) | ((s) << 21) | ((a) << 16) | (unsigned short)(d)) |
| 147 |
#define ppc_or(c,a,s,b) ppc_emit32 (c, (31 << 26) | ((s) << 21) | ((a) << 16) | ((b) << 11) | 888) |
| 148 |
/* ori updated as pem.fm & MPCFPE32B - Zhe */ |
| 149 |
#define ppc_ori(c,A,S,UIMM) ppc_emit32 (c, (24 << 26) | ((S) << 21) | ((A) << 16) | (unsigned short)(UIMM)) |
| 150 |
#define ppc_mr(c,a,s) ppc_or (c, a, s, s) |
| 151 |
#define ppc_mfspr(c,D,spr) ppc_emit32 (c, (31 << 26) | ((D) << 21) | ((spr) << 11) | (339 << 1)) |
| 152 |
#define ppc_mflr(c,D) ppc_mfspr (c, D, ppc_lr) |
| 153 |
#define ppc_mtspr(c,spr,S) ppc_emit32 (c, (31 << 26) | ((S) << 21) | ((spr) << 11) | (467 << 1)) |
| 154 |
#define ppc_mtlr(c,S) ppc_mtspr (c, ppc_lr, S) |
| 155 |
#define ppc_mtctr(c,S) ppc_mtspr (c, ppc_ctr, S) |
| 156 |
#define ppc_mtxer(c,S) ppc_mtspr (c, ppc_xer, S) |
| 157 |
|
| 158 |
#define ppc_b(c,li) ppc_emit32 (c, (18 << 26) | ((li) << 2)) |
| 159 |
#define ppc_bl(c,li) ppc_emit32 (c, (18 << 26) | ((li) << 2) | 1) |
| 160 |
#define ppc_ba(c,li) ppc_emit32 (c, (18 << 26) | ((li) << 2) | 2) |
| 161 |
#define ppc_bla(c,li) ppc_emit32 (c, (18 << 26) | ((li) << 2) | 3) |
| 162 |
#define ppc_blrl(c) ppc_emit32 (c, 0x4e800021) |
| 163 |
#define ppc_blr(c) ppc_emit32 (c, 0x4e800020) |
| 164 |
|
| 165 |
#define ppc_lfs(c,D,d,A) ppc_emit32 (c, (48 << 26) | ((D) << 21) | ((A) << 16) | (unsigned short)(d)) |
| 166 |
#define ppc_lfd(c,D,d,A) ppc_emit32 (c, (50 << 26) | ((D) << 21) | ((A) << 16) | (unsigned short)(d)) |
| 167 |
#define ppc_stfs(c,S,d,a) ppc_emit32 (c, (52 << 26) | ((S) << 21) | ((a) << 16) | (unsigned short)(d)) |
| 168 |
#define ppc_stfd(c,S,d,a) ppc_emit32 (c, (54 << 26) | ((S) << 21) | ((a) << 16) | (unsigned short)(d)) |
| 169 |
|
| 170 |
/*********************************************************************** |
| 171 |
The macros below were tapped out by Christopher Taylor <ct_AT_clemson_DOT_edu> |
| 172 |
from 18 November 2002 to 19 December 2002. |
| 173 |
|
| 174 |
Special thanks to rodo, lupus, dietmar, miguel, and duncan for patience, |
| 175 |
and motivation. |
| 176 |
|
| 177 |
The macros found in this file are based on the assembler instructions found |
| 178 |
in Motorola and Digital DNA's: |
| 179 |
|
| 180 |
"Programming Enviornments Manual For 32-bit Implementations of the PowerPC Architecture" |
| 181 |
|
| 182 |
MPCFPE32B/AD |
| 183 |
12/2001 |
| 184 |
REV2 |
| 185 |
|
| 186 |
see pages 326 - 524 for detailed information regarding each instruction |
| 187 |
|
| 188 |
Also see the "Ximian Copyright Agreement, 2002" for more information regarding |
| 189 |
my and Ximian's copyright to this code. ;) |
| 190 |
*************************************************************************/ |
| 191 |
|
| 192 |
#define ppc_addx(c,D,A,B,OE,Rc) ppc_emit32(c, (31 << 26) | ((D) << 21) | ((A) << 16) | ((B) << 11) | (OE << 10) | (266 << 1) | Rc) |
| 193 |
#define ppc_add(c,D,A,B) ppc_addx(c,D,A,B,0,0) |
| 194 |
#define ppc_addd(c,D,A,B) ppc_addx(c,D,A,B,0,1) |
| 195 |
#define ppc_addo(c,D,A,B) ppc_addx(c,D,A,B,1,0) |
| 196 |
#define ppc_addod(c,D,A,B) ppc_addx(c,D,A,B,1,1) |
| 197 |
|
| 198 |
#define ppc_addcx(c,D,A,B,OE,Rc) ppc_emit32(c, (31 << 26) | ((D) << 21) | ((A) << 16) | ((B) << 11) | (OE << 10) | (10 << 1) | Rc) |
| 199 |
#define ppc_addc(c,D,A,B) ppc_addcx(c,D,A,B,0,0) |
| 200 |
#define ppc_addcd(c,D,A,B) ppc_addcx(c,D,A,B,0,1) |
| 201 |
#define ppc_addco(c,D,A,B) ppc_addcx(c,D,A,B,1,0) |
| 202 |
#define ppc_addcod(c,D,A,B) ppc_addcx(c,D,A,B,1,1) |
| 203 |
|
| 204 |
#define ppc_addex(c,D,A,B,OE,Rc) ppc_emit32(c, (31 << 26) | ((D) << 21) | ((A) << 16) | ((B) << 11) | (OE << 10) | (138 << 1) | Rc) |
| 205 |
#define ppc_adde(c,D,A,B) ppc_addex(c,D,A,B,0,0) |
| 206 |
#define ppc_added(c,D,A,B) ppc_addex(c,D,A,B,0,1) |
| 207 |
#define ppc_addeo(c,D,A,B) ppc_addex(c,D,A,B,1,0) |
| 208 |
#define ppc_addeod(c,D,A,B) ppc_addex(c,D,A,B,1,1) |
| 209 |
|
| 210 |
#define ppc_addic(c,D,A,d) ppc_emit32(c, (12 << 26) | ((D) << 21) | ((A) << 16) | (unsigned short)(d)) |
| 211 |
#define ppc_addicd(c,D,A,d) ppc_emit32(c, (13 << 26) | ((D) << 21) | ((A) << 16) | (unsigned short)(d)) |
| 212 |
|
| 213 |
#define ppc_addmex(c,D,A,OE,RC) ppc_emit32(c, (31 << 26) | ((D) << 21 ) | ((A) << 16) | (0 << 11) | ((OE) << 10) | (234 << 1) | RC) |
| 214 |
#define ppc_addme(c,D,A) ppc_addmex(c,D,A,0,0) |
| 215 |
#define ppc_addmed(c,D,A) ppc_addmex(c,D,A,0,1) |
| 216 |
#define ppc_addmeo(c,D,A) ppc_addmex(c,D,A,1,0) |
| 217 |
#define ppc_addmeod(c,D,A) ppc_addmex(c,D,A,1,1) |
| 218 |
|
| 219 |
#define ppc_addzex(c,D,A,OE,RC) ppc_emit32(c, (31 << 26) | ((D) << 21 ) | ((A) << 16) | (0 << 11) | ((OE) << 10) | (202 << 1) | RC) |
| 220 |
#define ppc_addze(c,D,A) ppc_addzex(c,D,A,0,0) |
| 221 |
#define ppc_addzed(c,D,A) ppc_addzex(c,D,A,0,1) |
| 222 |
#define ppc_addzeo(c,D,A) ppc_addzex(c,D,A,1,0) |
| 223 |
#define ppc_addzeod(c,D,A) ppc_addzex(c,D,A,1,1) |
| 224 |
|
| 225 |
/* and* updated as pem.fm & MPCFPE32B - Zhe */ |
| 226 |
#define ppc_andx(c,A,S,B,RC) ppc_emit32(c, (31 << 26) | ((S) << 21 ) | ((A) << 16) | ((B) << 11) | (28 << 1) | RC) |
| 227 |
#define ppc_and(c,A,S,B) ppc_andx(c,A,S,B,0) |
| 228 |
#define ppc_andd(c,A,S,B) ppc_andx(c,A,S,B,1) |
| 229 |
|
| 230 |
#define ppc_andcx(c,A,S,B,RC) ppc_emit32(c, (31 << 26) | ((S) << 21 ) | ((A) << 16) | ((B) << 11) | (60 << 1) | RC) |
| 231 |
#define ppc_andc(c,A,S,B) ppc_andcx(c,A,S,B,0) |
| 232 |
#define ppc_andcd(c,A,S,B) ppc_andcx(c,A,S,B,1) |
| 233 |
|
| 234 |
#define ppc_andid(c,A,S,d) ppc_emit32(c, (28 << 26) | ((S) << 21 ) | ((A) << 16) | ((unsigned short)(d))) |
| 235 |
#define ppc_andisd(c,A,S,d) ppc_emit32(c, (29 << 26) | ((S) << 21 ) | ((A) << 16) | ((unsigned short)(d))) |
| 236 |
|
| 237 |
#define ppc_bcx(c,BO,BI,BD,AA,LK) ppc_emit32(c, (16 << 26) | (BO << 21 )| (BI << 16) | ((BD) << 2) | ((AA) << 1) | LK) |
| 238 |
#define ppc_bc(c,BO,BI,BD) ppc_bcx(c,BO,BI,BD,0,0) |
| 239 |
#define ppc_bca(c,BO,BI,BD) ppc_bcx(c,BO,BI,BD,1,0) |
| 240 |
#define ppc_bcl(c,BO,BI,BD) ppc_bcx(c,BO,BI,BD,0,1) |
| 241 |
#define ppc_bcla(c,BO,BI,BD) ppc_bcx(c,BO,BI,BD,1,1) |
| 242 |
|
| 243 |
#define ppc_bcctrx(c,BO,BI,LK) ppc_emit32(c, (19 << 26) | (BO << 21 )| (BI << 16) | (0 << 11) | (528 << 1) | LK) |
| 244 |
#define ppc_bcctr(c,BO,BI) ppc_bcctrx(c,BO,BI,0) |
| 245 |
#define ppc_bcctrl(c,BO,BI) ppc_bcctrx(c,BO,BI,1) |
| 246 |
|
| 247 |
#define ppc_bnectrp(c,BO,BI) ppc_bcctr(c,BO,BI) |
| 248 |
#define ppc_bnectrlp(c,BO,BI) ppc_bcctr(c,BO,BI) |
| 249 |
|
| 250 |
#define ppc_bclrx(c,BO,BI,LK) ppc_emit32(c, (19 << 26) | (BO << 21 )| (BI << 16) | (0 << 11) | (16 << 1) | LK) |
| 251 |
#define ppc_bclr(c,BO,BI) ppc_bclrx(c,BO,BI,0) |
| 252 |
#define ppc_bclrl(c,BO,BI) ppc_bclrx(c,BO,BI,1) |
| 253 |
|
| 254 |
#define ppc_bnelrp(c,BO,BI) ppc_bclr(c,BO,BI) |
| 255 |
#define ppc_bnelrlp(c,BO,BI) ppc_bclr(c,BO,BI) |
| 256 |
|
| 257 |
#define ppc_cmp(c,cfrD,L,A,B) ppc_emit32(c, (31 << 26) | (cfrD << 23) | (0 << 22) | (L << 21) | (A << 16) | (B << 11) | (0x00000 << 1) | 0 ) |
| 258 |
#define ppc_cmpi(c,cfrD,L,A,B) ppc_emit32(c, (11 << 26) | (cfrD << 23) | (0 << 22) | (L << 21) | (A << 16) | (unsigned short)(B)) |
| 259 |
#define ppc_cmpl(c,cfrD,L,A,B) ppc_emit32(c, (31 << 26) | (cfrD << 23) | (0 << 22) | (L << 21) | (A << 16) | (B << 11) | (32 << 1) | 0 ) |
| 260 |
#define ppc_cmpli(c,cfrD,L,A,B) ppc_emit32(c, (10 << 26) | (cfrD << 23) | (0 << 22) | (L << 21) | (A << 16) | (unsigned short)(B)) |
| 261 |
|
| 262 |
/* cntlzw* updated as pem.fm & MPCFPE32B - Zhe */ |
| 263 |
#define ppc_cntlzwx(c,A,S,Rc) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (0 << 11) | (26 << 1) | Rc) |
| 264 |
#define ppc_cntlzw(c,A,S) ppc_cntlzwx(c,A,S,0) |
| 265 |
#define ppc_cntlzwd(c,A,S) ppc_cntlzwx(c,A,S,1) |
| 266 |
|
| 267 |
#define ppc_crand(c,D,A,B) ppc_emit32(c, (19 << 26) | (D << 21) | (A << 16) | (B << 11) | (257 << 1) | 0) |
| 268 |
#define ppc_crandc(c,D,A,B) ppc_emit32(c, (19 << 26) | (D << 21) | (A << 16) | (B << 11) | (129 << 1) | 0) |
| 269 |
#define ppc_creqv(c,D,A,B) ppc_emit32(c, (19 << 26) | (D << 21) | (A << 16) | (B << 11) | (289 << 1) | 0) |
| 270 |
#define ppc_crnand(c,D,A,B) ppc_emit32(c, (19 << 26) | (D << 21) | (A << 16) | (B << 11) | (225 << 1) | 0) |
| 271 |
#define ppc_crnor(c,D,A,B) ppc_emit32(c, (19 << 26) | (D << 21) | (A << 16) | (B << 11) | (33 << 1) | 0) |
| 272 |
#define ppc_cror(c,D,A,B) ppc_emit32(c, (19 << 26) | (D << 21) | (A << 16) | (B << 11) | (449 << 1) | 0) |
| 273 |
#define ppc_crorc(c,D,A,B) ppc_emit32(c, (19 << 26) | (D << 21) | (A << 16) | (B << 11) | (417 << 1) | 0) |
| 274 |
#define ppc_crxor(c,D,A,B) ppc_emit32(c, (19 << 26) | (D << 21) | (A << 16) | (B << 11) | (193 << 1) | 0) |
| 275 |
|
| 276 |
#define ppc_dcba(c,A,B) ppc_emit32(c, (31 << 26) | (0 << 21) | (A << 16) | (B << 11) | (758 << 1) | 0) |
| 277 |
#define ppc_dcbf(c,A,B) ppc_emit32(c, (31 << 26) | (0 << 21) | (A << 16) | (B << 11) | (86 << 1) | 0) |
| 278 |
#define ppc_dcbi(c,A,B) ppc_emit32(c, (31 << 26) | (0 << 21) | (A << 16) | (B << 11) | (470 << 1) | 0) |
| 279 |
#define ppc_dcbst(c,A,B) ppc_emit32(c, (31 << 26) | (0 << 21) | (A << 16) | (B << 11) | (54 << 1) | 0) |
| 280 |
/* dcbt updated as pem.fm.2.3 - Zhe */ |
| 281 |
#define ppc_dcbt(c,A,B,TH) ppc_emit32(c, (31 << 26) | (TH << 21) | (A << 16) | (B << 11) | (278 << 1) | 0) |
| 282 |
#define ppc_dcbtst(c,A,B) ppc_emit32(c, (31 << 26) | (0 << 21) | (A << 16) | (B << 11) | (246 << 1) | 0) |
| 283 |
#define ppc_dcbz(c,A,B) ppc_emit32(c, (31 << 26) | (0 << 21) | (A << 16) | (B << 11) | (1014 << 1) | 0) |
| 284 |
|
| 285 |
#define ppc_divwx(c,D,A,B,OE,Rc) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (OE << 10) | (491 << 1) | Rc) |
| 286 |
#define ppc_divw(c,D,A,B) ppc_divwx(c,D,A,B,0,0) |
| 287 |
#define ppc_divwd(c,D,A,B) ppc_divwx(c,D,A,B,0,1) |
| 288 |
#define ppc_divwo(c,D,A,B) ppc_divwx(c,D,A,B,1,0) |
| 289 |
#define ppc_divwod(c,D,A,B) ppc_divwx(c,D,A,B,1,1) |
| 290 |
|
| 291 |
#define ppc_divwux(c,D,A,B,OE,Rc) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (OE << 10) | (459 << 1) | Rc) |
| 292 |
#define ppc_divwu(c,D,A,B) ppc_divwux(c,D,A,B,0,0) |
| 293 |
#define ppc_divwud(c,D,A,B) ppc_divwux(c,D,A,B,0,1) |
| 294 |
#define ppc_divwuo(c,D,A,B) ppc_divwux(c,D,A,B,1,0) |
| 295 |
#define ppc_divwuod(c,D,A,B) ppc_divwux(c,D,A,B,1,1) |
| 296 |
|
| 297 |
#define ppc_eciwx(c,D,A,B) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (310 << 1) | 0) |
| 298 |
#define ppc_ecowx(c,S,A,B) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (438 << 1) | 0) |
| 299 |
#define ppc_eieio(c) ppc_emit32(c, (31 << 26) | (0 << 21) | (0 << 16) | (0 << 11) | (854 << 1) | 0) |
| 300 |
|
| 301 |
#define ppc_eqvx(c,A,S,B,Rc) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (284 << 1) | Rc) |
| 302 |
#define ppc_eqv(c,A,S,B) ppc_eqvx(c,A,S,B,0) |
| 303 |
#define ppc_eqvd(c,A,S,B) ppc_eqvx(c,A,S,B,1) |
| 304 |
|
| 305 |
#define ppc_extsbx(c,A,S,Rc) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (0 << 11) | (954 << 1) | Rc) |
| 306 |
#define ppc_extsb(c,A,S) ppc_extsbx(c,A,S,0) |
| 307 |
#define ppc_extsbd(c,A,S) ppc_extsbx(c,A,S,1) |
| 308 |
|
| 309 |
#define ppc_extshx(c,A,S,Rc) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (0 << 11) | (922 << 1) | Rc) |
| 310 |
#define ppc_extsh(c,A,S) ppc_extshx(c,A,S,0) |
| 311 |
#define ppc_extshd(c,A,S) ppc_extshx(c,A,S,1) |
| 312 |
|
| 313 |
#define ppc_fabsx(c,D,B,Rc) ppc_emit32(c, (63 << 26) | (D << 21) | (0 << 16) | (B << 11) | (264 << 1) | Rc) |
| 314 |
#define ppc_fabs(c,D,B) ppc_fabsx(c,D,B,0) |
| 315 |
#define ppc_fabsd(c,D,B) ppc_fabsx(c,D,B,1) |
| 316 |
|
| 317 |
#define ppc_faddx(c,D,A,B,Rc) ppc_emit32(c, (63 << 26) | (D << 21) | (A << 16) | (B << 11) | (0 << 6) | (21 << 1) | Rc) |
| 318 |
#define ppc_fadd(c,D,A,B) ppc_faddx(c,D,A,B,0) |
| 319 |
#define ppc_faddd(c,D,A,B) ppc_faddx(c,D,A,B,1) |
| 320 |
|
| 321 |
#define ppc_faddsx(c,D,A,B,Rc) ppc_emit32(c, (59 << 26) | (D << 21) | (A << 16) | (B << 11) | (0 << 6) | (21 << 1) | Rc) |
| 322 |
#define ppc_fadds(c,D,A,B) ppc_faddsx(c,D,A,B,0) |
| 323 |
#define ppc_faddsd(c,D,A,B) ppc_faddsx(c,D,A,B,1) |
| 324 |
|
| 325 |
#define ppc_fcmpo(c,crfD,A,B) ppc_emit32(c, (63 << 26) | (crfD << 23) | (0 << 21) | (A << 16) | (B << 11) | (32 << 1) | 0) |
| 326 |
#define ppc_fcmpu(c,crfD,A,B) ppc_emit32(c, (63 << 26) | (crfD << 23) | (0 << 21) | (A << 16) | (B << 11) | (0 << 1) | 0) |
| 327 |
|
| 328 |
#define ppc_fctiwx(c,D,B,Rc) ppc_emit32(c, (63 << 26) | (D << 21) | (0 << 16) | (B << 11) | (14 << 1) | Rc) |
| 329 |
#define ppc_fctiw(c,D,B) ppc_fctiwx(c,D,B,0) |
| 330 |
#define ppc_fctiwd(c,D,B) ppc_fctiwx(c,D,B,1) |
| 331 |
|
| 332 |
#define ppc_fctiwzx(c,D,B,Rc) ppc_emit32(c, (63 << 26) | (D << 21) | (0 << 16) | (B << 11) | (15 << 1) | Rc) |
| 333 |
#define ppc_fctiwz(c,D,B) ppc_fctiwzx(c,D,B,0) |
| 334 |
#define ppc_fctiwzd(c,D,B) ppc_fctiwzx(c,D,B,1) |
| 335 |
|
| 336 |
#define ppc_fdivx(c,D,A,B,Rc) ppc_emit32(c, (63 << 26) | (D << 21) | (A << 16) | (B << 11) | (0 << 6) | (18 << 1) | Rc) |
| 337 |
#define ppc_fdiv(c,D,A,B) ppc_fdivx(c,D,A,B,0) |
| 338 |
#define ppc_fdivd(c,D,A,B) ppc_fdivx(c,D,A,B,1) |
| 339 |
|
| 340 |
#define ppc_fdivsx(c,D,A,B,Rc) ppc_emit32(c, (59 << 26) | (D << 21) | (A << 16) | (B << 11) | (0 << 6) | (18 << 1) | Rc) |
| 341 |
#define ppc_fdivs(c,D,A,B) ppc_fdivsx(c,D,A,B,0) |
| 342 |
#define ppc_fdivsd(c,D,A,B) ppc_fdivsx(c,D,A,B,1) |
| 343 |
|
| 344 |
#define ppc_fmaddx(c,D,A,B,C,Rc) ppc_emit32(c, (63 << 26) | (D << 21) | (A << 16) | (B << 11) | (C << 6) | (29 << 1) | Rc) |
| 345 |
#define ppc_fmadd(c,D,A,B,C) ppc_fmaddx(c,D,A,B,C,0) |
| 346 |
#define ppc_fmaddd(c,D,A,B,C) ppc_fmaddx(c,D,A,B,C,1) |
| 347 |
|
| 348 |
#define ppc_fmaddsx(c,D,A,B,C,Rc) ppc_emit32(c, (59 << 26) | (D << 21) | (A << 16) | (B << 11) | (C << 6) | (29 << 1) | Rc) |
| 349 |
#define ppc_fmadds(c,D,A,B,C) ppc_fmaddsx(c,D,A,B,C,0) |
| 350 |
#define ppc_fmaddsd(c,D,A,B,C) ppc_fmaddsx(c,D,A,B,C,1) |
| 351 |
|
| 352 |
#define ppc_fmrx(c,D,B,Rc) ppc_emit32(c, (63 << 26) | (D << 21) | (0 << 16) | (B << 11) | (72 << 1) | Rc) |
| 353 |
#define ppc_fmr(c,D,B) ppc_fmrx(c,D,B,0) |
| 354 |
#define ppc_fmrd(c,D,B) ppc_fmrx(c,D,B,1) |
| 355 |
|
| 356 |
#define ppc_fmsubx(c,D,A,C,B,Rc) ppc_emit32(c, (63 << 26) | (D << 21) | (A << 16) | (B << 11) | (C << 6) | (28 << 1) | Rc) |
| 357 |
#define ppc_fmsub(c,D,A,C,B) ppc_fmsubx(c,D,A,C,B,0) |
| 358 |
#define ppc_fmsubd(c,D,A,C,B) ppc_fmsubx(c,D,A,C,B,1) |
| 359 |
|
| 360 |
#define ppc_fmsubsx(c,D,A,C,B,Rc) ppc_emit32(c, (59 << 26) | (D << 21) | (A << 16) | (B << 11) | (C << 6) | (28 << 1) | Rc) |
| 361 |
#define ppc_fmsubs(c,D,A,C,B) ppc_fmsubsx(c,D,A,C,B,0) |
| 362 |
#define ppc_fmsubsd(c,D,A,C,B) ppc_fmsubsx(c,D,A,C,B,1) |
| 363 |
|
| 364 |
#define ppc_fmulx(c,D,A,C,Rc) ppc_emit32(c, (63 << 26) | (D << 21) | (A << 16) | (0 << 11) | (C << 6) | (25 << 1) | Rc) |
| 365 |
#define ppc_fmul(c,D,A,C) ppc_fmulx(c,D,A,C,0) |
| 366 |
#define ppc_fmuld(c,D,A,C) ppc_fmulx(c,D,A,C,1) |
| 367 |
|
| 368 |
#define ppc_fmulsx(c,D,A,C,Rc) ppc_emit32(c, (59 << 26) | (D << 21) | (A << 16) | (0 << 11) | (C << 6) | (25 << 1) | Rc) |
| 369 |
#define ppc_fmuls(c,D,A,C) ppc_fmulsx(c,D,A,C,0) |
| 370 |
#define ppc_fmulsd(c,D,A,C) ppc_fmulsx(c,D,A,C,1) |
| 371 |
|
| 372 |
#define ppc_fnabsx(c,D,B,Rc) ppc_emit32(c, (63 << 26) | (D << 21) | (0 << 16) | (B << 11) | (136 << 1) | Rc) |
| 373 |
#define ppc_fnabs(c,D,B) ppc_fnabsx(c,D,B,0) |
| 374 |
#define ppc_fnabsd(c,D,B) ppc_fnabsx(c,D,B,1) |
| 375 |
|
| 376 |
#define ppc_fnegx(c,D,B,Rc) ppc_emit32(c, (63 << 26) | (D << 21) | (0 << 16) | (B << 11) | (40 << 1) | Rc) |
| 377 |
#define ppc_fneg(c,D,B) ppc_fnegx(c,D,B,0) |
| 378 |
#define ppc_fnegd(c,D,B) ppc_fnegx(c,D,B,1) |
| 379 |
|
| 380 |
#define ppc_fnmaddx(c,D,A,C,B,Rc) ppc_emit32(c, (63 << 26) | (D << 21) | (A << 16) | (B << 11) | (C << 6) | (31 << 1) | Rc) |
| 381 |
#define ppc_fnmadd(c,D,A,C,B) ppc_fnmaddx(c,D,A,C,B,0) |
| 382 |
#define ppc_fnmaddd(c,D,A,C,B) ppc_fnmaddx(c,D,A,C,B,1) |
| 383 |
|
| 384 |
#define ppc_fnmaddsx(c,D,A,C,B,Rc) ppc_emit32(c, (59 << 26) | (D << 21) | (A << 16) | (B << 11) | (C << 6) | (31 << 1) | Rc) |
| 385 |
#define ppc_fnmadds(c,D,A,C,B) ppc_fnmaddsx(c,D,A,C,B,0) |
| 386 |
#define ppc_fnmaddsd(c,D,A,C,B) ppc_fnmaddsx(c,D,A,C,B,1) |
| 387 |
|
| 388 |
#define ppc_fnmsubx(c,D,A,C,B,Rc) ppc_emit32(c, (63 << 26) | (D << 21) | (A << 16) | (B << 11) | (C << 6) | (30 << 1) | Rc) |
| 389 |
#define ppc_fnmsub(c,D,A,C,B) ppc_fnmsubx(c,D,A,C,B,0) |
| 390 |
#define ppc_fnmsubd(c,D,A,C,B) ppc_fnmsubx(c,D,A,C,B,1) |
| 391 |
|
| 392 |
#define ppc_fnmsubsx(c,D,A,C,B,Rc) ppc_emit32(c, (59 << 26) | (D << 21) | (A << 16) | (B << 11) | (C << 6) | (30 << 1) | Rc) |
| 393 |
#define ppc_fnmsubs(c,D,A,C,B) ppc_fnmsubsx(c,D,A,C,B,0) |
| 394 |
#define ppc_fnmsubsd(c,D,A,C,B) ppc_fnmsubsx(c,D,A,C,B,1) |
| 395 |
|
| 396 |
#define ppc_fresx(c,D,B,Rc) ppc_emit32(c, (59 << 26) | (D << 21) | (0 << 16) | (B << 11) | (0 << 6) | (24 << 1) | Rc) |
| 397 |
#define ppc_fres(c,D,B) ppc_fresx(c,D,B,0) |
| 398 |
#define ppc_fresd(c,D,B) ppc_fresx(c,D,B,1) |
| 399 |
|
| 400 |
#define ppc_frspx(c,D,B,Rc) ppc_emit32(c, (63 << 26) | (D << 21) | (0 << 16) | (B << 11) | (12 << 1) | Rc) |
| 401 |
#define ppc_frsp(c,D,B) ppc_frspx(c,D,B,0) |
| 402 |
#define ppc_frspd(c,D,B) ppc_frspx(c,D,B,1) |
| 403 |
|
| 404 |
#define ppc_frsqrtex(c,D,B,Rc) ppc_emit32(c, (63 << 26) | (D << 21) | (0 << 16) | (B << 11) | (0 << 6) | (26 << 1) | Rc) |
| 405 |
#define ppc_frsqrte(c,D,B) ppc_frsqrtex(c,D,B,0) |
| 406 |
#define ppc_frsqrted(c,D,B) ppc_frsqrtex(c,D,B,1) |
| 407 |
|
| 408 |
#define ppc_fselx(c,D,A,C,B,Rc) ppc_emit32(c, (63 << 26) | (D << 21) | (A << 16) | (B << 11) | (C << 6) | (23 << 1) | Rc) |
| 409 |
#define ppc_fsel(c,D,A,C,B) ppc_fselx(c,D,A,C,B,0) |
| 410 |
#define ppc_fseld(c,D,A,C,B) ppc_fselx(c,D,A,C,B,1) |
| 411 |
|
| 412 |
#define ppc_fsqrtx(c,D,B,Rc) ppc_emit32(c, (63 << 26) | (D << 21) | (0 << 16) | (B << 11) | (0 << 6) | (22 << 1) | Rc) |
| 413 |
#define ppc_fsqrt(c,D,B) ppc_fsqrtx(c,D,B,0) |
| 414 |
#define ppc_fsqrtd(c,D,B) ppc_fsqrtx(c,D,B,1) |
| 415 |
|
| 416 |
#define ppc_fsqrtsx(c,D,B,Rc) ppc_emit32(c, (59 << 26) | (D << 21) | (0 << 16) | (B << 11) | (0 << 6) | (22 << 1) | Rc) |
| 417 |
#define ppc_fsqrts(c,D,B) ppc_fsqrtsx(c,D,B,0) |
| 418 |
#define ppc_fsqrtsd(c,D,B) ppc_fsqrtsx(c,D,B,1) |
| 419 |
|
| 420 |
#define ppc_fsubx(c,D,A,B,Rc) ppc_emit32(c, (63 << 26) | (D << 21) | (A << 16) | (B << 11) | (0 << 6) | (20 << 1) | Rc) |
| 421 |
#define ppc_fsub(c,D,A,B) ppc_fsubx(c,D,A,B,0) |
| 422 |
#define ppc_fsubd(c,D,A,B) ppc_fsubx(c,D,A,B,1) |
| 423 |
|
| 424 |
#define ppc_fsubsx(c,D,A,B,Rc) ppc_emit32(c, (59 << 26) | (D << 21) | (A << 16) | (B << 11) | (0 << 6) | (20 << 1) | Rc) |
| 425 |
#define ppc_fsubs(c,D,A,B) ppc_fsubsx(c,D,A,B,0) |
| 426 |
#define ppc_fsubsd(c,D,A,B) ppc_fsubsx(c,D,A,B,1) |
| 427 |
|
| 428 |
#define ppc_icbi(c,A,B) ppc_emit32(c, (31 << 26) | (0 << 21) | (A << 16) | (B << 11) | (982 << 1) | 0) |
| 429 |
|
| 430 |
#define ppc_isync(c) ppc_emit32(c, (19 << 26) | (0 << 11) | (150 << 1) | 0) |
| 431 |
|
| 432 |
/* lbzu updated as pem.fm & MPCFPE32B - Zhe */ |
| 433 |
#define ppc_lbzu(c,D,d,A) ppc_emit32(c, (35 << 26) | (D << 21) | (A << 16) | (unsigned short)d) |
| 434 |
#define ppc_lbzux(c,D,A,B) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (119 << 1) | 0) |
| 435 |
#define ppc_lbzx(c,D,A,B) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (87 << 1) | 0) |
| 436 |
|
| 437 |
/* lfdu updated as pem.fm & MPCFPE32B - Zhe */ |
| 438 |
#define ppc_lfdu(c,D,d,A) ppc_emit32(c, (51 << 26) | (D << 21) | (A << 16) | (unsigned short)d) |
| 439 |
#define ppc_lfdux(c,D,A,B) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (631 << 1) | 0) |
| 440 |
#define ppc_lfdx(c,D,A,B) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (599 << 1) | 0) |
| 441 |
|
| 442 |
/* lfs* updated as pem.fm & MPCFPE32B - Zhe */ |
| 443 |
#define ppc_lfsu(c,D,d,A) ppc_emit32(c, (49 << 26) | (D << 21) | (A << 16) | (unsigned short)d) |
| 444 |
#define ppc_lfsux(c,D,A,B) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (567 << 1) | 0) |
| 445 |
#define ppc_lfsx(c,D,A,B) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (535 << 1) | 0) |
| 446 |
|
| 447 |
/* lha, lhau, lhzu updated as pem.fm & MPCFPE32B - Zhe */ |
| 448 |
#define ppc_lha(c,D,d,A) ppc_emit32(c, (42 << 26) | (D << 21) | (A << 16) | (unsigned short)d) |
| 449 |
#define ppc_lhau(c,D,d,A) ppc_emit32(c, (43 << 26) | (D << 21) | (A << 16) | (unsigned short)d) |
| 450 |
#define ppc_lhaux(c,D,A,B) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (375 << 1) | 0) |
| 451 |
#define ppc_lhax(c,D,A,B) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (343 << 1) | 0) |
| 452 |
#define ppc_lhbrx(c,D,A,B) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (790 << 1) | 0) |
| 453 |
#define ppc_lhzu(c,D,d,A) ppc_emit32(c, (41 << 26) | (D << 21) | (A << 16) | (unsigned short)d) |
| 454 |
|
| 455 |
#define ppc_lhzux(c,D,A,B) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (311 << 1) | 0) |
| 456 |
#define ppc_lhzx(c,D,A,B) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (279 << 1) | 0) |
| 457 |
|
| 458 |
/* lmw updated as pem.fm & MPCFPE32B - Zhe */ |
| 459 |
#define ppc_lmw(c,D,d,A) ppc_emit32(c, (46 << 26) | (D << 21) | (A << 16) | (unsigned short)d) |
| 460 |
|
| 461 |
#define ppc_lswi(c,D,A,NB) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (NB << 11) | (597 << 1) | 0) |
| 462 |
#define ppc_lswx(c,D,A,B) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (533 << 1) | 0) |
| 463 |
#define ppc_lwarx(c,D,A,B) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (20 << 1) | 0) |
| 464 |
#define ppc_lwbrx(c,D,A,B) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (534 << 1) | 0) |
| 465 |
|
| 466 |
/* lwzu updated as pem.fm & MPCFPE32B - Zhe */ |
| 467 |
#define ppc_lwzu(c,D,d,A) ppc_emit32(c, (33 << 26) | (D << 21) | (A << 16) | (unsigned short)d) |
| 468 |
#define ppc_lwzux(c,D,A,B) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (55 << 1) | 0) |
| 469 |
#define ppc_lwzx(c,D,A,B) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (23 << 1) | 0) |
| 470 |
|
| 471 |
#define ppc_mcrf(c,crfD,crfS) ppc_emit32(c, (19 << 26) | (crfD << 23) | (0 << 21) | (crfS << 18) | 0) |
| 472 |
#define ppc_mcrfs(c,crfD,crfS) ppc_emit32(c, (63 << 26) | (crfD << 23) | (0 << 21) | (crfS << 18) | (0 << 16) | (64 << 1) | 0) |
| 473 |
#define ppc_mcrxr(c,crfD) ppc_emit32(c, (31 << 26) | (crfD << 23) | (0 << 16) | (512 << 1) | 0) |
| 474 |
|
| 475 |
#define ppc_mfcr(c,D) ppc_emit32(c, (31 << 26) | (D << 21) | (0 << 16) | (19 << 1) | 0) |
| 476 |
#define ppc_mffsx(c,D,Rc) ppc_emit32(c, (63 << 26) | (D << 21) | (0 << 16) | (583 << 1) | Rc) |
| 477 |
#define ppc_mffs(c,D) ppc_mffsx(c,D,0) |
| 478 |
#define ppc_mffsd(c,D) ppc_mffsx(c,D,1) |
| 479 |
#define ppc_mfmsr(c,D) ppc_emit32(c, (31 << 26) | (D << 21) | (0 << 16) | (83 << 1) | 0) |
| 480 |
#define ppc_mfsr(c,D,SR) ppc_emit32(c, (31 << 26) | (D << 21) | (0 << 20) | (SR << 16) | (0 << 11) | (595 << 1) | 0) |
| 481 |
#define ppc_mfsrin(c,D,B) ppc_emit32(c, (31 << 26) | (D << 21) | (0 << 16) | (B << 11) | (659 << 1) | 0) |
| 482 |
#define ppc_mftb(c,D,TBR) ppc_emit32(c, (31 << 26) | (D << 21) | (TBR << 11) | (371 << 1) | 0) |
| 483 |
|
| 484 |
#define ppc_mtcrf(c,CRM,S) ppc_emit32(c, (31 << 26) | (S << 21) | (0 << 20) | (CRM << 12) | (0 << 11) | (144 << 1) | 0) |
| 485 |
|
| 486 |
#define ppc_mtfsb0x(c,CRB,Rc) ppc_emit32(c, (63 << 26) | (CRB << 21) | (0 << 11) | (70 << 1) | Rc) |
| 487 |
#define ppc_mtfsb0(c,CRB) ppc_mtfsb0x(c,CRB,0) |
| 488 |
#define ppc_mtfsb0d(c,CRB) ppc_mtfsb0x(c,CRB,1) |
| 489 |
|
| 490 |
#define ppc_mtfsb1x(c,CRB,Rc) ppc_emit32(c, (63 << 26) | (CRB << 21) | (0 << 11) | (38 << 1) | Rc) |
| 491 |
#define ppc_mtfsb1(c,CRB) ppc_mtfsb1x(c,CRB,0) |
| 492 |
#define ppc_mtfsb1d(c,CRB) ppc_mtfsb1x(c,CRB,1) |
| 493 |
|
| 494 |
#define ppc_mtfsfx(c,FM,B,Rc) ppc_emit32(c, (63 << 26) | (0 << 25) | (FM << 22) | (0 << 21) | (B << 11) | (711 << 1) | Rc) |
| 495 |
#define ppc_mtfsf(c,FM,B) ppc_mtfsfx(c,FM,B,0) |
| 496 |
#define ppc_mtfsfd(c,FM,B) ppc_mtfsfx(c,FM,B,1) |
| 497 |
|
| 498 |
#define ppc_mtfsfix(c,crfD,IMM,Rc) ppc_emit32(c, (63 << 26) | (crfD << 23) | (0 << 16) | (IMM << 12) | (0 << 11) | (134 << 1) | Rc) |
| 499 |
#define ppc_mtfsfi(c,crfD,IMM) ppc_mtfsfix(c,crfD,IMM,0) |
| 500 |
#define ppc_mtfsfid(c,crfD,IMM) ppc_mtfsfix(c,crfD,IMM,1) |
| 501 |
|
| 502 |
#define ppc_mtmsr(c, S) ppc_emit32(c, (31 << 26) | (S << 21) | (0 << 11) | (146 << 1) | 0) |
| 503 |
|
| 504 |
#define ppc_mtsr(c,SR,S) ppc_emit32(c, (31 << 26) | (S << 21) | (0 << 20) | (SR << 16) | (0 << 11) | (210 << 1) | 0) |
| 505 |
#define ppc_mtsrin(c,S,B) ppc_emit32(c, (31 << 26) | (S << 21) | (0 << 16) | (B << 11) | (242 << 1) | 0) |
| 506 |
|
| 507 |
#define ppc_mulhwx(c,D,A,B,Rc) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (0 << 10) | (75 << 1) | Rc) |
| 508 |
#define ppc_mulhw(c,D,A,B) ppc_mulhwx(c,D,A,B,0) |
| 509 |
#define ppc_mulhwd(c,D,A,B) ppc_mulhwx(c,D,A,B,1) |
| 510 |
|
| 511 |
#define ppc_mulhwux(c,D,A,B,Rc) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (0 << 10) | (11 << 1) | Rc) |
| 512 |
#define ppc_mulhwu(c,D,A,B) ppc_mulhwux(c,D,A,B,0) |
| 513 |
#define ppc_mulhwud(c,D,A,B) ppc_mulhwux(c,D,A,B,1) |
| 514 |
|
| 515 |
#define ppc_mulli(c,D,A,SIMM) ppc_emit32(c, ((07) << 26) | (D << 21) | (A << 16) | (unsigned short)(SIMM)) |
| 516 |
|
| 517 |
#define ppc_mullwx(c,D,A,B,OE,Rc) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (OE << 10) | (235 << 1) | Rc) |
| 518 |
#define ppc_mullw(c,D,A,B) ppc_mullwx(c,D,A,B,0,0) |
| 519 |
#define ppc_mullwd(c,D,A,B) ppc_mullwx(c,D,A,B,0,1) |
| 520 |
#define ppc_mullwo(c,D,A,B) ppc_mullwx(c,D,A,B,1,0) |
| 521 |
#define ppc_mullwod(c,D,A,B) ppc_mullwx(c,D,A,B,1,1) |
| 522 |
|
| 523 |
#define ppc_nandx(c,A,S,B,Rc) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (476 << 1) | Rc) |
| 524 |
#define ppc_nand(c,A,S,B) ppc_nandx(c,A,S,B,0) |
| 525 |
#define ppc_nandd(c,A,S,B) ppc_nandx(c,A,S,B,1) |
| 526 |
|
| 527 |
#define ppc_negx(c,D,A,OE,Rc) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (0 << 11) | (OE << 10) | (104 << 1) | Rc) |
| 528 |
#define ppc_neg(c,D,A) ppc_negx(c,D,A,0,0) |
| 529 |
#define ppc_negd(c,D,A) ppc_negx(c,D,A,0,1) |
| 530 |
#define ppc_nego(c,D,A) ppc_negx(c,D,A,1,0) |
| 531 |
#define ppc_negod(c,D,A) ppc_negx(c,D,A,1,1) |
| 532 |
|
| 533 |
#define ppc_norx(c,A,S,B,Rc) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (124 << 1) | Rc) |
| 534 |
#define ppc_nor(c,A,S,B) ppc_norx(c,A,S,B,0) |
| 535 |
#define ppc_nord(c,A,S,B) ppc_norx(c,A,S,B,1) |
| 536 |
|
| 537 |
#define ppc_not(c,A,S) ppc_norx(c,A,S,S,0) |
| 538 |
|
| 539 |
#define ppc_orx(c,A,S,B,Rc) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (444 << 1) | Rc) |
| 540 |
#define ppc_ord(c,A,S,B) ppc_orx(c,A,S,B,1) |
| 541 |
|
| 542 |
#define ppc_orcx(c,A,S,B,Rc) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (412 << 1) | Rc) |
| 543 |
#define ppc_orc(c,A,S,B) ppc_orcx(c,A,S,B,0) |
| 544 |
#define ppc_orcd(c,A,S,B) ppc_orcx(c,A,S,B,1) |
| 545 |
|
| 546 |
#define ppc_oris(c,A,S,UIMM) ppc_emit32(c, (25 << 26) | (S << 21) | (A << 16) | (unsigned short)(UIMM)) |
| 547 |
|
| 548 |
#define ppc_rfi(c) ppc_emit32(c, (19 << 26) | (0 << 11) | (50 << 1) | 0) |
| 549 |
|
| 550 |
/* rlw* updated to avoid gcc warnings - Zhe */ |
| 551 |
#define ppc_rlwimix(c,A,S,SH,MB,ME,Rc) ppc_emit32(c, (20 << 26) | (S << 21) | (A << 16) | ((SH) << 11) | ((MB) << 6) | ((ME) << 1) | Rc) |
| 552 |
#define ppc_rlwimi(c,A,S,SH,MB,ME) ppc_rlwimix(c,A,S,SH,MB,ME,0) |
| 553 |
#define ppc_rlwimid(c,A,S,SH,MB,ME) ppc_rlwimix(c,A,S,SH,MB,ME,1) |
| 554 |
|
| 555 |
#define ppc_rlwinmx(c,A,S,SH,MB,ME,Rc) ppc_emit32(c, (21 << 26) | (S << 21) | (A << 16) | ((SH) << 11) | ((MB) << 6) | ((ME) << 1) | Rc) |
| 556 |
#define ppc_rlwinm(c,A,S,SH,MB,ME) ppc_rlwinmx(c,A,S,SH,MB,ME,0) |
| 557 |
#define ppc_rlwinmd(c,A,S,SH,MB,ME) ppc_rlwinmx(c,A,S,SH,MB,ME,1) |
| 558 |
|
| 559 |
#define ppc_rlwnmx(c,A,S,SH,MB,ME,Rc) ppc_emit32(c, (23 << 26) | (S << 21) | (A << 16) | ((SH) << 11) | ((MB) << 6) | ((ME) << 1) | Rc) |
| 560 |
#define ppc_rlwnm(c,A,S,SH,MB,ME) ppc_rlwnmx(c,A,S,SH,MB,ME,0) |
| 561 |
#define ppc_rlwnmd(c,A,S,SH,MB,ME) ppc_rlwnmx(c,A,S,SH,MB,ME,1) |
| 562 |
|
| 563 |
#define ppc_sc(c) ppc_emit32(c, (17 << 26) | (0 << 2) | (1 << 1) | 0) |
| 564 |
|
| 565 |
/* slw* updated as pem.fm & MPCFPE32B - Zhe */ |
| 566 |
#define ppc_slwx(c,A,S,B,Rc) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (24 << 1) | Rc) |
| 567 |
#define ppc_slw(c,A,S,B) ppc_slwx(c,A,S,B,0) |
| 568 |
#define ppc_slwd(c,A,S,B) ppc_slwx(c,A,S,B,1) |
| 569 |
|
| 570 |
#define ppc_srawx(c,A,S,B,Rc) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (792 << 1) | Rc) |
| 571 |
#define ppc_sraw(c,A,S,B) ppc_srawx(c,A,S,B,0) |
| 572 |
#define ppc_srawd(c,A,S,B) ppc_srawx(c,A,S,B,1) |
| 573 |
|
| 574 |
#define ppc_srawix(c,A,S,SH,Rc) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (SH << 11) | (824 << 1) | Rc) |
| 575 |
#define ppc_srawi(c,A,S,B) ppc_srawix(c,A,S,B,0) |
| 576 |
#define ppc_srawid(c,A,S,B) ppc_srawix(c,A,S,B,1) |
| 577 |
|
| 578 |
#define ppc_srwx(c,A,S,SH,Rc) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (SH << 11) | (536 << 1) | Rc) |
| 579 |
#define ppc_srw(c,A,S,B) ppc_srwx(c,A,S,B,0) |
| 580 |
#define ppc_srwd(c,A,S,B) ppc_srwx(c,A,S,B,1) |
| 581 |
|
| 582 |
/* stbu updated as pem.fm & MPCFPE32B - Zhe */ |
| 583 |
#define ppc_stbu(c,S,d,A) ppc_emit32(c, (39 << 26) | (S << 21) | (A << 16) | (unsigned short)(d)) |
| 584 |
|
| 585 |
#define ppc_stbux(c,S,A,B) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (247 << 1) | 0) |
| 586 |
#define ppc_stbx(c,S,A,B) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (215 << 1) | 0) |
| 587 |
|
| 588 |
/* stfdu updated as pem.fm & MPCFPE32B - Zhe */ |
| 589 |
#define ppc_stfdu(c,S,d,A) ppc_emit32(c, (55 << 26) | (S << 21) | (A << 16) | (unsigned short)(d)) |
| 590 |
|
| 591 |
#define ppc_stfdx(c,S,A,B) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (727 << 1) | 0) |
| 592 |
#define ppc_stfiwx(c,S,A,B) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (983 << 1) | 0) |
| 593 |
|
| 594 |
/* stfsu, sthu, stmw updated as pem.fm & MPCFPE32B - Zhe */ |
| 595 |
#define ppc_stfsu(c,S,d,A) ppc_emit32(c, (53 << 26) | (S << 21) | (A << 16) | (unsigned short)(d)) |
| 596 |
#define ppc_stfsux(c,S,A,B) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (695 << 1) | 0) |
| 597 |
#define ppc_stfsx(c,S,A,B) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (663 << 1) | 0) |
| 598 |
#define ppc_sthbrx(c,S,A,B) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (918 << 1) | 0) |
| 599 |
#define ppc_sthu(c,S,d,A) ppc_emit32(c, (45 << 26) | (S << 21) | (A << 16) | (unsigned short)(d)) |
| 600 |
#define ppc_sthux(c,S,A,B) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (439 << 1) | 0) |
| 601 |
#define ppc_sthx(c,S,A,B) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (407 << 1) | 0) |
| 602 |
#define ppc_stmw(c,S,d,A) ppc_emit32(c, (47 << 26) | (S << 21) | (A << 16) | (unsigned short)(d)) |
| 603 |
#define ppc_stswi(c,S,A,NB) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (NB << 11) | (725 << 1) | 0) |
| 604 |
#define ppc_stswx(c,S,A,NB) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (NB << 11) | (661 << 1) | 0) |
| 605 |
#define ppc_stwbrx(c,S,A,B) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (662 << 1) | 0) |
| 606 |
#define ppc_stwcxd(c,S,A,B) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (150 << 1) | 1) |
| 607 |
#define ppc_stwux(c,S,A,B) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (183 << 1) | 0) |
| 608 |
#define ppc_stwx(c,S,A,B) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (151 << 1) | 0) |
| 609 |
|
| 610 |
#define ppc_subfx(c,D,A,B,OE,Rc) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (OE << 10) | (40 << 1) | Rc) |
| 611 |
#define ppc_subf(c,D,A,B) ppc_subfx(c,D,A,B,0,0) |
| 612 |
#define ppc_subfd(c,D,A,B) ppc_subfx(c,D,A,B,0,1) |
| 613 |
#define ppc_subfo(c,D,A,B) ppc_subfx(c,D,A,B,1,0) |
| 614 |
#define ppc_subfod(c,D,A,B) ppc_subfx(c,D,A,B,1,1) |
| 615 |
|
| 616 |
#define ppc_sub(c,D,A,B) ppc_subf(c,D,B,A) |
| 617 |
|
| 618 |
#define ppc_subfcx(c,D,A,B,OE,Rc) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (OE << 10) | (8 << 1) | Rc) |
| 619 |
#define ppc_subfc(c,D,A,B) ppc_subfcx(c,D,A,B,0,0) |
| 620 |
#define ppc_subfcd(c,D,A,B) ppc_subfcx(c,D,A,B,0,1) |
| 621 |
#define ppc_subfco(c,D,A,B) ppc_subfcx(c,D,A,B,1,0) |
| 622 |
#define ppc_subfcod(c,D,A,B) ppc_subfcx(c,D,A,B,1,1) |
| 623 |
|
| 624 |
#define ppc_subfex(c,D,A,B,OE,Rc) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (B << 11) | (OE << 10) | (136 << 1) | Rc) |
| 625 |
#define ppc_subfe(c,D,A,B) ppc_subfex(c,D,A,B,0,0) |
| 626 |
#define ppc_subfed(c,D,A,B) ppc_subfex(c,D,A,B,0,1) |
| 627 |
#define ppc_subfeo(c,D,A,B) ppc_subfex(c,D,A,B,1,0) |
| 628 |
#define ppc_subfeod(c,D,A,B) ppc_subfex(c,D,A,B,1,1) |
| 629 |
|
| 630 |
#define ppc_subfic(c,D,A,SIMM) ppc_emit32(c, (8 << 26) | (D << 21) | (A << 16) | (unsigned short)(SIMM)) |
| 631 |
|
| 632 |
#define ppc_subfmex(c,D,A,OE,Rc) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (0 << 11) | (OE << 10) | (232 << 1) | Rc) |
| 633 |
#define ppc_subfme(c,D,A) ppc_subfmex(c,D,A,0,0) |
| 634 |
#define ppc_subfmed(c,D,A) ppc_subfmex(c,D,A,0,1) |
| 635 |
#define ppc_subfmeo(c,D,A) ppc_subfmex(c,D,A,1,0) |
| 636 |
#define ppc_subfmeod(c,D,A) ppc_subfmex(c,D,A,1,1) |
| 637 |
|
| 638 |
#define ppc_subfzex(c,D,A,OE,Rc) ppc_emit32(c, (31 << 26) | (D << 21) | (A << 16) | (0 << 11) | (OE << 10) | (200 << 1) | Rc) |
| 639 |
#define ppc_subfze(c,D,A) ppc_subfzex(c,D,A,0,0) |
| 640 |
#define ppc_subfzed(c,D,A) ppc_subfzex(c,D,A,0,1) |
| 641 |
#define ppc_subfzeo(c,D,A) ppc_subfzex(c,D,A,1,0) |
| 642 |
#define ppc_subfzeod(c,D,A) ppc_subfzex(c,D,A,1,1) |
| 643 |
|
| 644 |
#define ppc_sync(c) ppc_emit32(c, (31 << 26) | (0 << 11) | (598 << 1) | 0) |
| 645 |
#define ppc_tlbia(c) ppc_emit32(c, (31 << 26) | (0 << 11) | (370 << 1) | 0) |
| 646 |
#define ppc_tlbie(c,B) ppc_emit32(c, (31 << 26) | (0 << 16) | (B << 11) | (306 << 1) | 0) |
| 647 |
#define ppc_tlbsync(c) ppc_emit32(c, (31 << 26) | (0 << 11) | (566 << 1) | 0) |
| 648 |
|
| 649 |
#define ppc_tw(c,TO,A,B) ppc_emit32(c, (31 << 26) | (TO << 21) | (A << 16) | (B << 11) | (4 << 1) | 0) |
| 650 |
#define ppc_twi(c,TO,A,SIMM) ppc_emit32(c, (3 << 26) | (TO << 21) | (A << 16) | (unsigned short)(SIMM)) |
| 651 |
|
| 652 |
#define ppc_xorx(c,A,S,B,RC) ppc_emit32(c, (31 << 26) | (S << 21) | (A << 16) | (B << 11) | (316 << 1) | RC) |
| 653 |
#define ppc_xor(c,A,S,B) ppc_xorx(c,A,S,B,0) |
| 654 |
#define ppc_xord(c,A,S,B) ppc_xorx(c,A,S,B,1) |
| 655 |
|
| 656 |
/* xori* updated as pem.fm & MPCFPE32B - Zhe */ |
| 657 |
#define ppc_xori(c,A,S,UIMM) ppc_emit32(c, (26 << 26) | (S << 21) | (A << 16) | (unsigned short)(UIMM)) |
| 658 |
#define ppc_xoris(c,A,S,UIMM) ppc_emit32(c, (27 << 26) | (S << 21) | (A << 16) | (unsigned short)(UIMM)) |
| 659 |
|
| 660 |
/* this marks the end of my work, ct */ |
| 661 |
|
| 662 |
/* |
| 663 |
* The following codes come from mini-ppc.c: |
| 664 |
* PowerPC backend for the Mono code generator |
| 665 |
* |
| 666 |
* Authors: |
| 667 |
* Paolo Molaro ([email protected]) |
| 668 |
* Dietmar Maurer ([email protected]) |
| 669 |
* |
| 670 |
* (C) 2003 Ximian, Inc. |
| 671 |
*/ |
| 672 |
|
| 673 |
/* deal with some of the ABI differences here */ |
| 674 |
#ifdef __APPLE__ |
| 675 |
#define PPC_RET_ADDR_OFFSET 8 |
| 676 |
#define PPC_STACK_ALIGNMENT 16 |
| 677 |
#define PPC_STACK_PARAM_OFFSET 24 |
| 678 |
#define PPC_MINIMAL_STACK_SIZE 24 |
| 679 |
#define PPC_FIRST_ARG_REG ppc_r3 |
| 680 |
#define PPC_LAST_ARG_REG ppc_r10 |
| 681 |
#define PPC_FIRST_FPARG_REG ppc_f1 |
| 682 |
#define PPC_LAST_FPARG_REG ppc_f13 |
| 683 |
#define PPC_PASS_STRUCTS_BY_VALUE 1 |
| 684 |
#else |
| 685 |
/* SVR4 - Linux, NetBSD, etc. */ |
| 686 |
#define PPC_RET_ADDR_OFFSET 4 |
| 687 |
#define PPC_STACK_ALIGNMENT 16 |
| 688 |
#define PPC_STACK_PARAM_OFFSET 8 |
| 689 |
#define PPC_MINIMAL_STACK_SIZE 8 |
| 690 |
#define PPC_FIRST_ARG_REG ppc_r3 |
| 691 |
#define PPC_LAST_ARG_REG ppc_r10 |
| 692 |
#define PPC_FIRST_FPARG_REG ppc_f1 |
| 693 |
#define PPC_LAST_FPARG_REG ppc_f8 |
| 694 |
/* set the next to 0 once inssel-ppc.brg is updated */ |
| 695 |
#define PPC_PASS_STRUCTS_BY_VALUE 1 |
| 696 |
#define PPC_SMALL_RET_STRUCT_IN_REG 1 |
| 697 |
|
| 698 |
#endif |
| 699 |
|
| 700 |
// code from ppc/tramp.c, try to keep in sync |
| 701 |
#define MIN_CACHE_LINE 8 |
| 702 |
|
| 703 |
static inline void mono_ppc_flush_icache (unsigned char *code, int size) |
| 704 |
{ |
| 705 |
unsigned int i; |
| 706 |
unsigned char *p; |
| 707 |
|
| 708 |
p = code; |
| 709 |
/* use dcbf for smp support, later optimize for UP, see pem._64bit.d20030611.pdf page 211 */ |
| 710 |
if (1) { |
| 711 |
for (i = 0; i < size; i += MIN_CACHE_LINE, p += MIN_CACHE_LINE) { |
| 712 |
asm ("dcbf 0,%0;" : : "r"(p) : "memory"); |
| 713 |
} |
| 714 |
} else { |
| 715 |
for (i = 0; i < size; i += MIN_CACHE_LINE, p += MIN_CACHE_LINE) { |
| 716 |
asm ("dcbst 0,%0;" : : "r"(p) : "memory"); |
| 717 |
} |
| 718 |
} |
| 719 |
asm ("sync"); |
| 720 |
p = code; |
| 721 |
for (i = 0; i < size; i += MIN_CACHE_LINE, p += MIN_CACHE_LINE) { |
| 722 |
asm ("icbi 0,%0; sync;" : : "r"(p) : "memory"); |
| 723 |
} |
| 724 |
asm ("sync"); |
| 725 |
asm ("isync"); |
| 726 |
} |
| 727 |
|
| 728 |
static inline void ppc_patch (unsigned char *code, unsigned char *target) |
| 729 |
{ |
| 730 |
unsigned int ins = *(unsigned int*)code; |
| 731 |
unsigned int prim = ins >> 26; |
| 732 |
unsigned int ovf; |
| 733 |
|
| 734 |
//g_print ("patching 0x%08x (0x%08x) to point to 0x%08x\n", code, ins, target); |
| 735 |
if (prim == 18) { |
| 736 |
// prefer relative branches, they are more position independent (e.g. for AOT compilation). |
| 737 |
int diff = target - code; |
| 738 |
if (diff >= 0){ |
| 739 |
if (diff <= 33554431){ |
| 740 |
ins = (18 << 26) | (diff) | (ins & 1); |
| 741 |
*(unsigned int*)code = ins; |
| 742 |
return; |
| 743 |
} |
| 744 |
} else { |
| 745 |
/* diff between 0 and -33554432 */ |
| 746 |
if (diff >= -33554432){ |
| 747 |
ins = (18 << 26) | (diff & ~0xfc000000) | (ins & 1); |
| 748 |
*(unsigned int*)code = ins; |
| 749 |
return; |
| 750 |
} |
| 751 |
} |
| 752 |
|
| 753 |
if ((long)target >= 0){ |
| 754 |
if ((long)target <= 33554431){ |
| 755 |
ins = (18 << 26) | ((unsigned int) target) | (ins & 1) | 2; |
| 756 |
*(unsigned int*)code = ins; |
| 757 |
return; |
| 758 |
} |
| 759 |
} else { |
| 760 |
if ((long)target >= -33554432){ |
| 761 |
ins = (18 << 26) | (((unsigned int)target) & ~0xfc000000) | (ins & 1) | 2; |
| 762 |
*(unsigned int*)code = ins; |
| 763 |
return; |
| 764 |
} |
| 765 |
} |
| 766 |
|
| 767 |
// handle_thunk (TRUE, code, target); |
| 768 |
return; |
| 769 |
|
| 770 |
assert (0); |
| 771 |
} |
| 772 |
|
| 773 |
|
| 774 |
if (prim == 16) { |
| 775 |
// absolute address |
| 776 |
if (ins & 2) { |
| 777 |
unsigned int li = (unsigned int)target; |
| 778 |
ins = (ins & 0xffff0000) | (ins & 3); |
| 779 |
ovf = li & 0xffff0000; |
| 780 |
if (ovf != 0 && ovf != 0xffff0000) |
| 781 |
assert (0); |
| 782 |
li &= 0xffff; |
| 783 |
ins |= li; |
| 784 |
// FIXME: assert the top bits of li are 0 |
| 785 |
} else { |
| 786 |
int diff = target - code; |
| 787 |
ins = (ins & 0xffff0000) | (ins & 3); |
| 788 |
ovf = diff & 0xffff0000; |
| 789 |
if (ovf != 0 && ovf != 0xffff0000) |
| 790 |
assert (0); |
| 791 |
diff &= 0xffff; |
| 792 |
ins |= diff; |
| 793 |
} |
| 794 |
*(unsigned int*)code = ins; |
| 795 |
return; |
| 796 |
} |
| 797 |
|
| 798 |
if (prim == 15 || ins == 0x4e800021) { |
| 799 |
unsigned int *seq; |
| 800 |
/* the trampoline code will try to patch the blrl */ |
| 801 |
if (ins == 0x4e800021) { |
| 802 |
code -= 12; |
| 803 |
} |
| 804 |
/* this is the lis/ori/mtlr/blrl sequence */ |
| 805 |
seq = (unsigned int*)code; |
| 806 |
assert ((seq [0] >> 26) == 15); |
| 807 |
assert ((seq [1] >> 26) == 24); |
| 808 |
assert ((seq [2] >> 26) == 31); |
| 809 |
assert (seq [3] == 0x4e800021); |
| 810 |
/* FIXME: make this thread safe */ |
| 811 |
ppc_lis (code, ppc_r0, (unsigned int)(target) >> 16); |
| 812 |
ppc_ori (code, ppc_r0, ppc_r0, (unsigned int)(target) & 0xffff); |
| 813 |
mono_ppc_flush_icache (code - 8, 8); |
| 814 |
} else { |
| 815 |
assert (0); |
| 816 |
} |
| 817 |
// g_print ("patched with 0x%08x\n", ins); |
| 818 |
} |
| 819 |
|
| 820 |
/* Works done by Zhe Fang ([email protected]) |
| 821 |
Most macros here are based on the assembler instructions can |
| 822 |
be founded in |
| 823 |
|
| 824 |
"Appendix F. Simplified Mnemonics" of IBM's |
| 825 |
|
| 826 |
"PowerPC Microprocessor Family: |
| 827 |
The Programming Enviornments for 32-Bit Microprocessors" |
| 828 |
|
| 829 |
G522-0290-01 |
| 830 |
02/21/2000 |
| 831 |
|
| 832 |
also referenced in |
| 833 |
|
| 834 |
"Appendix E. Simplified Mnemonics" of IBM's |
| 835 |
|
| 836 |
"PowerPC Microprocessor Family: |
| 837 |
The Programming Enviornments for 32 and 64-Bit Microprocessors" |
| 838 |
|
| 839 |
pem.fm.2.3 |
| 840 |
March 31, 2005 |
| 841 |
|
| 842 |
and |
| 843 |
|
| 844 |
"Appendix E. Simplified Mnemonics for PowerPC Instructions" |
| 845 |
of Freescale Semiconductor's |
| 846 |
|
| 847 |
"Programming Enviornments Manual for 32-Bit Implementations |
| 848 |
of the PowerPC Architecture" |
| 849 |
|
| 850 |
MPCFPE32B |
| 851 |
Rev. 3, 9/2005 |
| 852 |
|
| 853 |
The Branch-Conditional-Prediction relative codes are followed |
| 854 |
the descriptions in |
| 855 |
|
| 856 |
"4.2.4.2 Conditional Branch Control" of IBM's |
| 857 |
|
| 858 |
"PowerPC Microprocessor Family: |
| 859 |
The Programming Enviornments Manual for 32 and 64-bit Microprocessors" |
| 860 |
|
| 861 |
pem.fm.2.3 |
| 862 |
March 31, 2005 |
| 863 |
|
| 864 |
and also compatiable with other manuals above |
| 865 |
*/ |
| 866 |
|
| 867 |
typedef enum { |
| 868 |
ppc_cr0 = 0, |
| 869 |
ppc_cr1, |
| 870 |
ppc_cr2, |
| 871 |
ppc_cr3, |
| 872 |
ppc_cr4, |
| 873 |
ppc_cr5, |
| 874 |
ppc_cr6, |
| 875 |
ppc_cr7 |
| 876 |
} PPCCRField; |
| 877 |
|
| 878 |
#define ppc_crbf(f,b) (4*f+b) |
| 879 |
|
| 880 |
enum { |
| 881 |
/* for BO */ |
| 882 |
PPC_BR_FALSE_UNLIKELY = 6, |
| 883 |
PPC_BR_FALSE_LIKELY = 7, |
| 884 |
PPC_BR_TRUE_UNLIKELY = 14, |
| 885 |
PPC_BR_TRUE_LIKELY = 15, |
| 886 |
PPC_BR_DEC_CTR_NONZERO_UNLIKELY = 24, |
| 887 |
PPC_BR_DEC_CTR_NONZERO_LIKELY = 25, |
| 888 |
PPC_BR_DEC_CTR_ZERO_UNLIKELY = 26, |
| 889 |
PPC_BR_DEC_CTR_ZERO_LIKELY = 27, |
| 890 |
/* for BH */ |
| 891 |
PPC_BR_BCLR_SUB_RETURN = 0, |
| 892 |
PPC_BR_BCCTR_NOT_SUB_RETURN = 0, |
| 893 |
PPC_BR_BCLR_NOT_SUB_RETURN = 1, |
| 894 |
PPC_BR_BCLR_NOT_PREDICTABLE = 3, |
| 895 |
PPC_BR_BCCTR_NOT_PREDICTABLE = 3 |
| 896 |
}; |
| 897 |
|
| 898 |
/*#define ppc_bcctrx(c,BO,BI,BH,LK) ppc_emit32(c, (19 << 26) | (BO << 21 )| (BI << 16) | (BH << 11) | (528 << 1) | LK) |
| 899 |
#define ppc_bcctr(c,BO,BI,BH) ppc_bcctrx(c,BO,BI,BH,0) |
| 900 |
#define ppc_bcctrl(c,BO,BI,BH) ppc_bcctrx(c,BO,BI,BH,1) |
| 901 |
|
| 902 |
#define ppc_bclrx(c,BO,BI,BH,LK) ppc_emit32(c, (19 << 26) | (BO << 21 )| (BI << 16) | (BH << 11) | (16 << 1) | LK) |
| 903 |
#define ppc_bclr(c,BO,BI,BH) ppc_bclrx(c,BO,BI,BH,0) |
| 904 |
#define ppc_bclrl(c,BO,BI,BH) ppc_bclrx(c,BO,BI,BH,1)*/ |
| 905 |
|
| 906 |
#define ppc_subi(c,D,A,d) ppc_addi(c,D,A,-(d)) |
| 907 |
#define ppc_subis(c,D,A,d) ppc_addis(c,D,A,-(d)) |
| 908 |
#define ppc_subic(c,D,A,d) ppc_addic(c,D,A,-(d)) |
| 909 |
#define ppc_subicd(c,D,A,d) ppc_addicd(c,D,A,-(d)) |
| 910 |
|
| 911 |
#define ppc_sub(c,D,A,B) ppc_subf(c,D,B,A) |
| 912 |
#define ppc_subc(c,D,A,B) ppc_subfc(c,D,B,A) |
| 913 |
|
| 914 |
#define ppc_cmpwi(c,cfrD,A,B) ppc_cmpi(c,cfrD,0,A,B) |
| 915 |
#define ppc_cmpw(c,cfrD,A,B) ppc_cmp(c,cfrD,0,A,B) |
| 916 |
#define ppc_cmplwi(c,cfrD,A,B) ppc_cmpli(c,cfrD,0,A,B) |
| 917 |
#define ppc_cmplw(c,cfrD,A,B) ppc_cmpl(c,cfrD,0,A,B) |
| 918 |
|
| 919 |
#define ppc_extlwi(c,A,S,n,b) ppc_rlwinm(c,A,S,b,0,((n-1) & 0x1f)) |
| 920 |
#define ppc_extrwi(c,A,S,n,b) ppc_rlwinm(c,A,S,((b+n) & 0x1f),((32-(n)) & 0x1f),31) |
| 921 |
#define ppc_inslwi(c,A,S,n,b) ppc_rlwimi(c,A,S,(32-(b) & 0x1f),b,((b+n-1) & 0x1f)) |
| 922 |
#define ppc_insrwi(c,A,S,n,b) ppc_rlwimi(c,A,S,((32-(b)-(n)) & 0x1f),b,((b+n-1) & 0x1f)) |
| 923 |
#define ppc_rotlwi(c,A,S,n) ppc_rlwinm(c,A,S,n,0,31) |
| 924 |
#define ppc_rotrwi(c,A,S,n) ppc_rlwinm(c,A,S,((32-(n)) & 0x1f),0,31) |
| 925 |
#define ppc_rotlw(c,A,S,B) ppc_rlwinm(c,A,S,B,0,31) |
| 926 |
#define ppc_slwi(c,A,S,n) ppc_rlwinm(c,A,S,n,0,31-(n)) |
| 927 |
#define ppc_srwi(c,A,S,n) ppc_rlwinm(c,A,S,((32-(n)) & 0x1f),n,31) |
| 928 |
#define ppc_clrlwi(c,A,S,n) ppc_rlwinm(c,A,S,0,n,31) |
| 929 |
#define ppc_clrrwi(c,A,S,n) ppc_rlwinm(c,A,S,0,0,31-(n)) |
| 930 |
#define ppc_clrlslwi(c,A,S,b,n) ppc_rlwinm(c,A,S,n,((b-(n)) & 0x1f),31-(n)) |
| 931 |
|
| 932 |
#define ppc_bctr(c) ppc_emit32(c,0x4e800420) |
| 933 |
#define ppc_bctrl(c) ppc_emit32(c,0x4e800421) |
| 934 |
|
| 935 |
|
| 936 |
#define ppc_crset(c,bx) ppc_creqv(c,bx,bx,bx) |
| 937 |
#define ppc_crclr(c,bx) ppc_crxor(c,bx,bx,bx) |
| 938 |
#define ppc_crmove(c,bx,by) ppc_cror(c,bx,by,by) |
| 939 |
#define ppc_crnot(c,bx,by) ppc_crnor(c,bx,by,by) |
| 940 |
|
| 941 |
|
| 942 |
#define ppc_nop(c) ppc_ori(c,0,0,0) |
| 943 |
|
| 944 |
//#define ppc_la(c,D,d,A) ppc_addi(c,D,A,d) |
| 945 |
#define ppc_la(c,D,v) ppc_addi(c,D,v,v) |
| 946 |
|
| 947 |
#define ppc_mtcr(c,S) ppc_mtcrf(c,0xff,S) |
| 948 |
|
| 949 |
/* Helper macros for assembler */ |
| 950 |
#define ppc_hi16(v) ((unsigned int)(v) >> 16) |
| 951 |
#define ppc_ha16(v) (ppc_hi16(v) + ((v & 0x8000) >> 15)) |
| 952 |
#define ppc_lo16(v) ((unsigned int)(v) & 0xffff) |
| 953 |
|
| 954 |
#endif |