root / target-ppc / translate.c @ 477023a6
History | View | Annotate | Download (206.4 kB)
1 |
/*
|
---|---|
2 |
* PowerPC emulation for qemu: main translation routines.
|
3 |
*
|
4 |
* Copyright (c) 2003-2007 Jocelyn Mayer
|
5 |
*
|
6 |
* This library is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU Lesser General Public
|
8 |
* License as published by the Free Software Foundation; either
|
9 |
* version 2 of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This library is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
* Lesser General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU Lesser General Public
|
17 |
* License along with this library; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 |
*/
|
20 |
#include <stdarg.h> |
21 |
#include <stdlib.h> |
22 |
#include <stdio.h> |
23 |
#include <string.h> |
24 |
#include <inttypes.h> |
25 |
|
26 |
#include "cpu.h" |
27 |
#include "exec-all.h" |
28 |
#include "disas.h" |
29 |
|
30 |
/* Include definitions for instructions classes and implementations flags */
|
31 |
//#define DO_SINGLE_STEP
|
32 |
//#define PPC_DEBUG_DISAS
|
33 |
//#define DEBUG_MEMORY_ACCESSES
|
34 |
//#define DO_PPC_STATISTICS
|
35 |
|
36 |
/*****************************************************************************/
|
37 |
/* Code translation helpers */
|
38 |
#if defined(USE_DIRECT_JUMP)
|
39 |
#define TBPARAM(x)
|
40 |
#else
|
41 |
#define TBPARAM(x) (long)(x) |
42 |
#endif
|
43 |
|
44 |
enum {
|
45 |
#define DEF(s, n, copy_size) INDEX_op_ ## s, |
46 |
#include "opc.h" |
47 |
#undef DEF
|
48 |
NB_OPS, |
49 |
}; |
50 |
|
51 |
static uint16_t *gen_opc_ptr;
|
52 |
static uint32_t *gen_opparam_ptr;
|
53 |
|
54 |
#include "gen-op.h" |
55 |
|
56 |
static inline void gen_set_T0 (target_ulong val) |
57 |
{ |
58 |
#if defined(TARGET_PPC64)
|
59 |
if (val >> 32) |
60 |
gen_op_set_T0_64(val >> 32, val);
|
61 |
else
|
62 |
#endif
|
63 |
gen_op_set_T0(val); |
64 |
} |
65 |
|
66 |
static inline void gen_set_T1 (target_ulong val) |
67 |
{ |
68 |
#if defined(TARGET_PPC64)
|
69 |
if (val >> 32) |
70 |
gen_op_set_T1_64(val >> 32, val);
|
71 |
else
|
72 |
#endif
|
73 |
gen_op_set_T1(val); |
74 |
} |
75 |
|
76 |
#define GEN8(func, NAME) \
|
77 |
static GenOpFunc *NAME ## _table [8] = { \ |
78 |
NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \ |
79 |
NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \ |
80 |
}; \ |
81 |
static inline void func(int n) \ |
82 |
{ \ |
83 |
NAME ## _table[n](); \ |
84 |
} |
85 |
|
86 |
#define GEN16(func, NAME) \
|
87 |
static GenOpFunc *NAME ## _table [16] = { \ |
88 |
NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \ |
89 |
NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \ |
90 |
NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \ |
91 |
NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \ |
92 |
}; \ |
93 |
static inline void func(int n) \ |
94 |
{ \ |
95 |
NAME ## _table[n](); \ |
96 |
} |
97 |
|
98 |
#define GEN32(func, NAME) \
|
99 |
static GenOpFunc *NAME ## _table [32] = { \ |
100 |
NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \ |
101 |
NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \ |
102 |
NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \ |
103 |
NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \ |
104 |
NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \ |
105 |
NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \ |
106 |
NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \ |
107 |
NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \ |
108 |
}; \ |
109 |
static inline void func(int n) \ |
110 |
{ \ |
111 |
NAME ## _table[n](); \ |
112 |
} |
113 |
|
114 |
/* Condition register moves */
|
115 |
GEN8(gen_op_load_crf_T0, gen_op_load_crf_T0_crf); |
116 |
GEN8(gen_op_load_crf_T1, gen_op_load_crf_T1_crf); |
117 |
GEN8(gen_op_store_T0_crf, gen_op_store_T0_crf_crf); |
118 |
GEN8(gen_op_store_T1_crf, gen_op_store_T1_crf_crf); |
119 |
|
120 |
/* Floating point condition and status register moves */
|
121 |
GEN8(gen_op_load_fpscr_T0, gen_op_load_fpscr_T0_fpscr); |
122 |
GEN8(gen_op_store_T0_fpscr, gen_op_store_T0_fpscr_fpscr); |
123 |
GEN8(gen_op_clear_fpscr, gen_op_clear_fpscr_fpscr); |
124 |
static inline void gen_op_store_T0_fpscri (int n, uint8_t param) |
125 |
{ |
126 |
gen_op_set_T0(param); |
127 |
gen_op_store_T0_fpscr(n); |
128 |
} |
129 |
|
130 |
/* General purpose registers moves */
|
131 |
GEN32(gen_op_load_gpr_T0, gen_op_load_gpr_T0_gpr); |
132 |
GEN32(gen_op_load_gpr_T1, gen_op_load_gpr_T1_gpr); |
133 |
GEN32(gen_op_load_gpr_T2, gen_op_load_gpr_T2_gpr); |
134 |
|
135 |
GEN32(gen_op_store_T0_gpr, gen_op_store_T0_gpr_gpr); |
136 |
GEN32(gen_op_store_T1_gpr, gen_op_store_T1_gpr_gpr); |
137 |
#if 0 // unused
|
138 |
GEN32(gen_op_store_T2_gpr, gen_op_store_T2_gpr_gpr);
|
139 |
#endif
|
140 |
|
141 |
/* floating point registers moves */
|
142 |
GEN32(gen_op_load_fpr_FT0, gen_op_load_fpr_FT0_fpr); |
143 |
GEN32(gen_op_load_fpr_FT1, gen_op_load_fpr_FT1_fpr); |
144 |
GEN32(gen_op_load_fpr_FT2, gen_op_load_fpr_FT2_fpr); |
145 |
GEN32(gen_op_store_FT0_fpr, gen_op_store_FT0_fpr_fpr); |
146 |
GEN32(gen_op_store_FT1_fpr, gen_op_store_FT1_fpr_fpr); |
147 |
#if 0 // unused
|
148 |
GEN32(gen_op_store_FT2_fpr, gen_op_store_FT2_fpr_fpr);
|
149 |
#endif
|
150 |
|
151 |
/* internal defines */
|
152 |
typedef struct DisasContext { |
153 |
struct TranslationBlock *tb;
|
154 |
target_ulong nip; |
155 |
uint32_t opcode; |
156 |
uint32_t exception; |
157 |
/* Routine used to access memory */
|
158 |
int mem_idx;
|
159 |
/* Translation flags */
|
160 |
#if !defined(CONFIG_USER_ONLY)
|
161 |
int supervisor;
|
162 |
#endif
|
163 |
#if defined(TARGET_PPC64)
|
164 |
int sf_mode;
|
165 |
#endif
|
166 |
int fpu_enabled;
|
167 |
#if defined(TARGET_PPCEMB)
|
168 |
int spe_enabled;
|
169 |
#endif
|
170 |
ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */
|
171 |
int singlestep_enabled;
|
172 |
} DisasContext; |
173 |
|
174 |
struct opc_handler_t {
|
175 |
/* invalid bits */
|
176 |
uint32_t inval; |
177 |
/* instruction type */
|
178 |
uint64_t type; |
179 |
/* handler */
|
180 |
void (*handler)(DisasContext *ctx);
|
181 |
#if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
|
182 |
const unsigned char *oname; |
183 |
#endif
|
184 |
#if defined(DO_PPC_STATISTICS)
|
185 |
uint64_t count; |
186 |
#endif
|
187 |
}; |
188 |
|
189 |
static inline void gen_set_Rc0 (DisasContext *ctx) |
190 |
{ |
191 |
#if defined(TARGET_PPC64)
|
192 |
if (ctx->sf_mode)
|
193 |
gen_op_cmpi_64(0);
|
194 |
else
|
195 |
#endif
|
196 |
gen_op_cmpi(0);
|
197 |
gen_op_set_Rc0(); |
198 |
} |
199 |
|
200 |
static inline void gen_update_nip (DisasContext *ctx, target_ulong nip) |
201 |
{ |
202 |
#if defined(TARGET_PPC64)
|
203 |
if (ctx->sf_mode)
|
204 |
gen_op_update_nip_64(nip >> 32, nip);
|
205 |
else
|
206 |
#endif
|
207 |
gen_op_update_nip(nip); |
208 |
} |
209 |
|
210 |
#define GEN_EXCP(ctx, excp, error) \
|
211 |
do { \
|
212 |
if ((ctx)->exception == POWERPC_EXCP_NONE) { \
|
213 |
gen_update_nip(ctx, (ctx)->nip); \ |
214 |
} \ |
215 |
gen_op_raise_exception_err((excp), (error)); \ |
216 |
ctx->exception = (excp); \ |
217 |
} while (0) |
218 |
|
219 |
#define GEN_EXCP_INVAL(ctx) \
|
220 |
GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \ |
221 |
POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL) |
222 |
|
223 |
#define GEN_EXCP_PRIVOPC(ctx) \
|
224 |
GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \ |
225 |
POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_OPC) |
226 |
|
227 |
#define GEN_EXCP_PRIVREG(ctx) \
|
228 |
GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \ |
229 |
POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_REG) |
230 |
|
231 |
#define GEN_EXCP_NO_FP(ctx) \
|
232 |
GEN_EXCP(ctx, POWERPC_EXCP_FPU, 0)
|
233 |
|
234 |
#define GEN_EXCP_NO_AP(ctx) \
|
235 |
GEN_EXCP(ctx, POWERPC_EXCP_APU, 0)
|
236 |
|
237 |
/* Stop translation */
|
238 |
static inline void GEN_STOP (DisasContext *ctx) |
239 |
{ |
240 |
gen_update_nip(ctx, ctx->nip); |
241 |
ctx->exception = POWERPC_EXCP_STOP; |
242 |
} |
243 |
|
244 |
/* No need to update nip here, as execution flow will change */
|
245 |
static inline void GEN_SYNC (DisasContext *ctx) |
246 |
{ |
247 |
ctx->exception = POWERPC_EXCP_SYNC; |
248 |
} |
249 |
|
250 |
#define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
|
251 |
static void gen_##name (DisasContext *ctx); \ |
252 |
GEN_OPCODE(name, opc1, opc2, opc3, inval, type); \ |
253 |
static void gen_##name (DisasContext *ctx) |
254 |
|
255 |
typedef struct opcode_t { |
256 |
unsigned char opc1, opc2, opc3; |
257 |
#if HOST_LONG_BITS == 64 /* Explicitely align to 64 bits */ |
258 |
unsigned char pad[5]; |
259 |
#else
|
260 |
unsigned char pad[1]; |
261 |
#endif
|
262 |
opc_handler_t handler; |
263 |
const unsigned char *oname; |
264 |
} opcode_t; |
265 |
|
266 |
/*****************************************************************************/
|
267 |
/*** Instruction decoding ***/
|
268 |
#define EXTRACT_HELPER(name, shift, nb) \
|
269 |
static inline uint32_t name (uint32_t opcode) \ |
270 |
{ \ |
271 |
return (opcode >> (shift)) & ((1 << (nb)) - 1); \ |
272 |
} |
273 |
|
274 |
#define EXTRACT_SHELPER(name, shift, nb) \
|
275 |
static inline int32_t name (uint32_t opcode) \ |
276 |
{ \ |
277 |
return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \ |
278 |
} |
279 |
|
280 |
/* Opcode part 1 */
|
281 |
EXTRACT_HELPER(opc1, 26, 6); |
282 |
/* Opcode part 2 */
|
283 |
EXTRACT_HELPER(opc2, 1, 5); |
284 |
/* Opcode part 3 */
|
285 |
EXTRACT_HELPER(opc3, 6, 5); |
286 |
/* Update Cr0 flags */
|
287 |
EXTRACT_HELPER(Rc, 0, 1); |
288 |
/* Destination */
|
289 |
EXTRACT_HELPER(rD, 21, 5); |
290 |
/* Source */
|
291 |
EXTRACT_HELPER(rS, 21, 5); |
292 |
/* First operand */
|
293 |
EXTRACT_HELPER(rA, 16, 5); |
294 |
/* Second operand */
|
295 |
EXTRACT_HELPER(rB, 11, 5); |
296 |
/* Third operand */
|
297 |
EXTRACT_HELPER(rC, 6, 5); |
298 |
/*** Get CRn ***/
|
299 |
EXTRACT_HELPER(crfD, 23, 3); |
300 |
EXTRACT_HELPER(crfS, 18, 3); |
301 |
EXTRACT_HELPER(crbD, 21, 5); |
302 |
EXTRACT_HELPER(crbA, 16, 5); |
303 |
EXTRACT_HELPER(crbB, 11, 5); |
304 |
/* SPR / TBL */
|
305 |
EXTRACT_HELPER(_SPR, 11, 10); |
306 |
static inline uint32_t SPR (uint32_t opcode) |
307 |
{ |
308 |
uint32_t sprn = _SPR(opcode); |
309 |
|
310 |
return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5); |
311 |
} |
312 |
/*** Get constants ***/
|
313 |
EXTRACT_HELPER(IMM, 12, 8); |
314 |
/* 16 bits signed immediate value */
|
315 |
EXTRACT_SHELPER(SIMM, 0, 16); |
316 |
/* 16 bits unsigned immediate value */
|
317 |
EXTRACT_HELPER(UIMM, 0, 16); |
318 |
/* Bit count */
|
319 |
EXTRACT_HELPER(NB, 11, 5); |
320 |
/* Shift count */
|
321 |
EXTRACT_HELPER(SH, 11, 5); |
322 |
/* Mask start */
|
323 |
EXTRACT_HELPER(MB, 6, 5); |
324 |
/* Mask end */
|
325 |
EXTRACT_HELPER(ME, 1, 5); |
326 |
/* Trap operand */
|
327 |
EXTRACT_HELPER(TO, 21, 5); |
328 |
|
329 |
EXTRACT_HELPER(CRM, 12, 8); |
330 |
EXTRACT_HELPER(FM, 17, 8); |
331 |
EXTRACT_HELPER(SR, 16, 4); |
332 |
EXTRACT_HELPER(FPIMM, 20, 4); |
333 |
|
334 |
/*** Jump target decoding ***/
|
335 |
/* Displacement */
|
336 |
EXTRACT_SHELPER(d, 0, 16); |
337 |
/* Immediate address */
|
338 |
static inline target_ulong LI (uint32_t opcode) |
339 |
{ |
340 |
return (opcode >> 0) & 0x03FFFFFC; |
341 |
} |
342 |
|
343 |
static inline uint32_t BD (uint32_t opcode) |
344 |
{ |
345 |
return (opcode >> 0) & 0xFFFC; |
346 |
} |
347 |
|
348 |
EXTRACT_HELPER(BO, 21, 5); |
349 |
EXTRACT_HELPER(BI, 16, 5); |
350 |
/* Absolute/relative address */
|
351 |
EXTRACT_HELPER(AA, 1, 1); |
352 |
/* Link */
|
353 |
EXTRACT_HELPER(LK, 0, 1); |
354 |
|
355 |
/* Create a mask between <start> and <end> bits */
|
356 |
static inline target_ulong MASK (uint32_t start, uint32_t end) |
357 |
{ |
358 |
target_ulong ret; |
359 |
|
360 |
#if defined(TARGET_PPC64)
|
361 |
if (likely(start == 0)) { |
362 |
ret = (uint64_t)(-1ULL) << (63 - end); |
363 |
} else if (likely(end == 63)) { |
364 |
ret = (uint64_t)(-1ULL) >> start;
|
365 |
} |
366 |
#else
|
367 |
if (likely(start == 0)) { |
368 |
ret = (uint32_t)(-1ULL) << (31 - end); |
369 |
} else if (likely(end == 31)) { |
370 |
ret = (uint32_t)(-1ULL) >> start;
|
371 |
} |
372 |
#endif
|
373 |
else {
|
374 |
ret = (((target_ulong)(-1ULL)) >> (start)) ^
|
375 |
(((target_ulong)(-1ULL) >> (end)) >> 1); |
376 |
if (unlikely(start > end))
|
377 |
return ~ret;
|
378 |
} |
379 |
|
380 |
return ret;
|
381 |
} |
382 |
|
383 |
/*****************************************************************************/
|
384 |
/* PowerPC Instructions types definitions */
|
385 |
enum {
|
386 |
PPC_NONE = 0x0000000000000000ULL,
|
387 |
/* integer operations instructions */
|
388 |
/* flow control instructions */
|
389 |
/* virtual memory instructions */
|
390 |
/* ld/st with reservation instructions */
|
391 |
/* cache control instructions */
|
392 |
/* spr/msr access instructions */
|
393 |
PPC_INSNS_BASE = 0x0000000000000001ULL,
|
394 |
#define PPC_INTEGER PPC_INSNS_BASE
|
395 |
#define PPC_FLOW PPC_INSNS_BASE
|
396 |
#define PPC_MEM PPC_INSNS_BASE
|
397 |
#define PPC_RES PPC_INSNS_BASE
|
398 |
#define PPC_CACHE PPC_INSNS_BASE
|
399 |
#define PPC_MISC PPC_INSNS_BASE
|
400 |
/* Optional floating point instructions */
|
401 |
PPC_FLOAT = 0x0000000000000002ULL,
|
402 |
PPC_FLOAT_FSQRT = 0x0000000000000004ULL,
|
403 |
PPC_FLOAT_FRES = 0x0000000000000008ULL,
|
404 |
PPC_FLOAT_FRSQRTE = 0x0000000000000010ULL,
|
405 |
PPC_FLOAT_FSEL = 0x0000000000000020ULL,
|
406 |
PPC_FLOAT_STFIWX = 0x0000000000000040ULL,
|
407 |
/* external control instructions */
|
408 |
PPC_EXTERN = 0x0000000000000080ULL,
|
409 |
/* segment register access instructions */
|
410 |
PPC_SEGMENT = 0x0000000000000100ULL,
|
411 |
/* Optional cache control instruction */
|
412 |
PPC_CACHE_DCBA = 0x0000000000000200ULL,
|
413 |
/* Optional memory control instructions */
|
414 |
PPC_MEM_TLBIA = 0x0000000000000400ULL,
|
415 |
PPC_MEM_TLBIE = 0x0000000000000800ULL,
|
416 |
PPC_MEM_TLBSYNC = 0x0000000000001000ULL,
|
417 |
/* eieio & sync */
|
418 |
PPC_MEM_SYNC = 0x0000000000002000ULL,
|
419 |
/* PowerPC 6xx TLB management instructions */
|
420 |
PPC_6xx_TLB = 0x0000000000004000ULL,
|
421 |
/* Altivec support */
|
422 |
PPC_ALTIVEC = 0x0000000000008000ULL,
|
423 |
/* Time base mftb instruction */
|
424 |
PPC_MFTB = 0x0000000000010000ULL,
|
425 |
/* Embedded PowerPC dedicated instructions */
|
426 |
PPC_EMB_COMMON = 0x0000000000020000ULL,
|
427 |
/* PowerPC 40x exception model */
|
428 |
PPC_40x_EXCP = 0x0000000000040000ULL,
|
429 |
/* PowerPC 40x TLB management instructions */
|
430 |
PPC_40x_TLB = 0x0000000000080000ULL,
|
431 |
/* PowerPC 405 Mac instructions */
|
432 |
PPC_405_MAC = 0x0000000000100000ULL,
|
433 |
/* PowerPC 440 specific instructions */
|
434 |
PPC_440_SPEC = 0x0000000000200000ULL,
|
435 |
/* Power-to-PowerPC bridge (601) */
|
436 |
PPC_POWER_BR = 0x0000000000400000ULL,
|
437 |
/* PowerPC 602 specific */
|
438 |
PPC_602_SPEC = 0x0000000000800000ULL,
|
439 |
/* Deprecated instructions */
|
440 |
/* Original POWER instruction set */
|
441 |
PPC_POWER = 0x0000000001000000ULL,
|
442 |
/* POWER2 instruction set extension */
|
443 |
PPC_POWER2 = 0x0000000002000000ULL,
|
444 |
/* Power RTC support */
|
445 |
PPC_POWER_RTC = 0x0000000004000000ULL,
|
446 |
/* 64 bits PowerPC instructions */
|
447 |
/* 64 bits PowerPC instruction set */
|
448 |
PPC_64B = 0x0000000008000000ULL,
|
449 |
/* 64 bits hypervisor extensions */
|
450 |
PPC_64H = 0x0000000010000000ULL,
|
451 |
/* 64 bits PowerPC "bridge" features */
|
452 |
PPC_64_BRIDGE = 0x0000000020000000ULL,
|
453 |
/* BookE (embedded) PowerPC specification */
|
454 |
PPC_BOOKE = 0x0000000040000000ULL,
|
455 |
/* eieio */
|
456 |
PPC_MEM_EIEIO = 0x0000000080000000ULL,
|
457 |
/* e500 vector instructions */
|
458 |
PPC_E500_VECTOR = 0x0000000100000000ULL,
|
459 |
/* PowerPC 4xx dedicated instructions */
|
460 |
PPC_4xx_COMMON = 0x0000000200000000ULL,
|
461 |
/* PowerPC 2.03 specification extensions */
|
462 |
PPC_203 = 0x0000000400000000ULL,
|
463 |
/* PowerPC 2.03 SPE extension */
|
464 |
PPC_SPE = 0x0000000800000000ULL,
|
465 |
/* PowerPC 2.03 SPE floating-point extension */
|
466 |
PPC_SPEFPU = 0x0000001000000000ULL,
|
467 |
/* SLB management */
|
468 |
PPC_SLBI = 0x0000002000000000ULL,
|
469 |
/* PowerPC 40x ibct instructions */
|
470 |
PPC_40x_ICBT = 0x0000004000000000ULL,
|
471 |
/* PowerPC 74xx TLB management instructions */
|
472 |
PPC_74xx_TLB = 0x0000008000000000ULL,
|
473 |
/* More BookE (embedded) instructions... */
|
474 |
PPC_BOOKE_EXT = 0x0000010000000000ULL,
|
475 |
/* rfmci is not implemented in all BookE PowerPC */
|
476 |
PPC_RFMCI = 0x0000020000000000ULL,
|
477 |
/* user-mode DCR access, implemented in PowerPC 460 */
|
478 |
PPC_DCRUX = 0x0000040000000000ULL,
|
479 |
}; |
480 |
|
481 |
/*****************************************************************************/
|
482 |
/* PowerPC instructions table */
|
483 |
#if HOST_LONG_BITS == 64 |
484 |
#define OPC_ALIGN 8 |
485 |
#else
|
486 |
#define OPC_ALIGN 4 |
487 |
#endif
|
488 |
#if defined(__APPLE__)
|
489 |
#define OPCODES_SECTION \
|
490 |
__attribute__ ((section("__TEXT,__opcodes"), unused, aligned (OPC_ALIGN) ))
|
491 |
#else
|
492 |
#define OPCODES_SECTION \
|
493 |
__attribute__ ((section(".opcodes"), unused, aligned (OPC_ALIGN) ))
|
494 |
#endif
|
495 |
|
496 |
#if defined(DO_PPC_STATISTICS)
|
497 |
#define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
|
498 |
OPCODES_SECTION opcode_t opc_##name = { \ |
499 |
.opc1 = op1, \ |
500 |
.opc2 = op2, \ |
501 |
.opc3 = op3, \ |
502 |
.pad = { 0, }, \
|
503 |
.handler = { \ |
504 |
.inval = invl, \ |
505 |
.type = _typ, \ |
506 |
.handler = &gen_##name, \ |
507 |
.oname = stringify(name), \ |
508 |
}, \ |
509 |
.oname = stringify(name), \ |
510 |
} |
511 |
#else
|
512 |
#define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
|
513 |
OPCODES_SECTION opcode_t opc_##name = { \ |
514 |
.opc1 = op1, \ |
515 |
.opc2 = op2, \ |
516 |
.opc3 = op3, \ |
517 |
.pad = { 0, }, \
|
518 |
.handler = { \ |
519 |
.inval = invl, \ |
520 |
.type = _typ, \ |
521 |
.handler = &gen_##name, \ |
522 |
}, \ |
523 |
.oname = stringify(name), \ |
524 |
} |
525 |
#endif
|
526 |
|
527 |
#define GEN_OPCODE_MARK(name) \
|
528 |
OPCODES_SECTION opcode_t opc_##name = { \ |
529 |
.opc1 = 0xFF, \
|
530 |
.opc2 = 0xFF, \
|
531 |
.opc3 = 0xFF, \
|
532 |
.pad = { 0, }, \
|
533 |
.handler = { \ |
534 |
.inval = 0x00000000, \
|
535 |
.type = 0x00, \
|
536 |
.handler = NULL, \
|
537 |
}, \ |
538 |
.oname = stringify(name), \ |
539 |
} |
540 |
|
541 |
/* Start opcode list */
|
542 |
GEN_OPCODE_MARK(start); |
543 |
|
544 |
/* Invalid instruction */
|
545 |
GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE) |
546 |
{ |
547 |
GEN_EXCP_INVAL(ctx); |
548 |
} |
549 |
|
550 |
static opc_handler_t invalid_handler = {
|
551 |
.inval = 0xFFFFFFFF,
|
552 |
.type = PPC_NONE, |
553 |
.handler = gen_invalid, |
554 |
}; |
555 |
|
556 |
/*** Integer arithmetic ***/
|
557 |
#define __GEN_INT_ARITH2(name, opc1, opc2, opc3, inval, type) \
|
558 |
GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \ |
559 |
{ \ |
560 |
gen_op_load_gpr_T0(rA(ctx->opcode)); \ |
561 |
gen_op_load_gpr_T1(rB(ctx->opcode)); \ |
562 |
gen_op_##name(); \ |
563 |
gen_op_store_T0_gpr(rD(ctx->opcode)); \ |
564 |
if (unlikely(Rc(ctx->opcode) != 0)) \ |
565 |
gen_set_Rc0(ctx); \ |
566 |
} |
567 |
|
568 |
#define __GEN_INT_ARITH2_O(name, opc1, opc2, opc3, inval, type) \
|
569 |
GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \ |
570 |
{ \ |
571 |
gen_op_load_gpr_T0(rA(ctx->opcode)); \ |
572 |
gen_op_load_gpr_T1(rB(ctx->opcode)); \ |
573 |
gen_op_##name(); \ |
574 |
gen_op_store_T0_gpr(rD(ctx->opcode)); \ |
575 |
if (unlikely(Rc(ctx->opcode) != 0)) \ |
576 |
gen_set_Rc0(ctx); \ |
577 |
} |
578 |
|
579 |
#define __GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
|
580 |
GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
|
581 |
{ \ |
582 |
gen_op_load_gpr_T0(rA(ctx->opcode)); \ |
583 |
gen_op_##name(); \ |
584 |
gen_op_store_T0_gpr(rD(ctx->opcode)); \ |
585 |
if (unlikely(Rc(ctx->opcode) != 0)) \ |
586 |
gen_set_Rc0(ctx); \ |
587 |
} |
588 |
#define __GEN_INT_ARITH1_O(name, opc1, opc2, opc3, type) \
|
589 |
GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
|
590 |
{ \ |
591 |
gen_op_load_gpr_T0(rA(ctx->opcode)); \ |
592 |
gen_op_##name(); \ |
593 |
gen_op_store_T0_gpr(rD(ctx->opcode)); \ |
594 |
if (unlikely(Rc(ctx->opcode) != 0)) \ |
595 |
gen_set_Rc0(ctx); \ |
596 |
} |
597 |
|
598 |
/* Two operands arithmetic functions */
|
599 |
#define GEN_INT_ARITH2(name, opc1, opc2, opc3, type) \
|
600 |
__GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000000, type) \
|
601 |
__GEN_INT_ARITH2_O(name##o, opc1, opc2, opc3 | 0x10, 0x00000000, type) |
602 |
|
603 |
/* Two operands arithmetic functions with no overflow allowed */
|
604 |
#define GEN_INT_ARITHN(name, opc1, opc2, opc3, type) \
|
605 |
__GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000400, type)
|
606 |
|
607 |
/* One operand arithmetic functions */
|
608 |
#define GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
|
609 |
__GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \ |
610 |
__GEN_INT_ARITH1_O(name##o, opc1, opc2, opc3 | 0x10, type) |
611 |
|
612 |
#if defined(TARGET_PPC64)
|
613 |
#define __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, inval, type) \
|
614 |
GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \ |
615 |
{ \ |
616 |
gen_op_load_gpr_T0(rA(ctx->opcode)); \ |
617 |
gen_op_load_gpr_T1(rB(ctx->opcode)); \ |
618 |
if (ctx->sf_mode) \
|
619 |
gen_op_##name##_64(); \ |
620 |
else \
|
621 |
gen_op_##name(); \ |
622 |
gen_op_store_T0_gpr(rD(ctx->opcode)); \ |
623 |
if (unlikely(Rc(ctx->opcode) != 0)) \ |
624 |
gen_set_Rc0(ctx); \ |
625 |
} |
626 |
|
627 |
#define __GEN_INT_ARITH2_O_64(name, opc1, opc2, opc3, inval, type) \
|
628 |
GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \ |
629 |
{ \ |
630 |
gen_op_load_gpr_T0(rA(ctx->opcode)); \ |
631 |
gen_op_load_gpr_T1(rB(ctx->opcode)); \ |
632 |
if (ctx->sf_mode) \
|
633 |
gen_op_##name##_64(); \ |
634 |
else \
|
635 |
gen_op_##name(); \ |
636 |
gen_op_store_T0_gpr(rD(ctx->opcode)); \ |
637 |
if (unlikely(Rc(ctx->opcode) != 0)) \ |
638 |
gen_set_Rc0(ctx); \ |
639 |
} |
640 |
|
641 |
#define __GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
|
642 |
GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
|
643 |
{ \ |
644 |
gen_op_load_gpr_T0(rA(ctx->opcode)); \ |
645 |
if (ctx->sf_mode) \
|
646 |
gen_op_##name##_64(); \ |
647 |
else \
|
648 |
gen_op_##name(); \ |
649 |
gen_op_store_T0_gpr(rD(ctx->opcode)); \ |
650 |
if (unlikely(Rc(ctx->opcode) != 0)) \ |
651 |
gen_set_Rc0(ctx); \ |
652 |
} |
653 |
#define __GEN_INT_ARITH1_O_64(name, opc1, opc2, opc3, type) \
|
654 |
GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
|
655 |
{ \ |
656 |
gen_op_load_gpr_T0(rA(ctx->opcode)); \ |
657 |
if (ctx->sf_mode) \
|
658 |
gen_op_##name##_64(); \ |
659 |
else \
|
660 |
gen_op_##name(); \ |
661 |
gen_op_store_T0_gpr(rD(ctx->opcode)); \ |
662 |
if (unlikely(Rc(ctx->opcode) != 0)) \ |
663 |
gen_set_Rc0(ctx); \ |
664 |
} |
665 |
|
666 |
/* Two operands arithmetic functions */
|
667 |
#define GEN_INT_ARITH2_64(name, opc1, opc2, opc3, type) \
|
668 |
__GEN_INT_ARITH2_64(name, opc1, opc2, opc3, 0x00000000, type) \
|
669 |
__GEN_INT_ARITH2_O_64(name##o, opc1, opc2, opc3 | 0x10, 0x00000000, type) |
670 |
|
671 |
/* Two operands arithmetic functions with no overflow allowed */
|
672 |
#define GEN_INT_ARITHN_64(name, opc1, opc2, opc3, type) \
|
673 |
__GEN_INT_ARITH2_64(name, opc1, opc2, opc3, 0x00000400, type)
|
674 |
|
675 |
/* One operand arithmetic functions */
|
676 |
#define GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
|
677 |
__GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \ |
678 |
__GEN_INT_ARITH1_O_64(name##o, opc1, opc2, opc3 | 0x10, type) |
679 |
#else
|
680 |
#define GEN_INT_ARITH2_64 GEN_INT_ARITH2
|
681 |
#define GEN_INT_ARITHN_64 GEN_INT_ARITHN
|
682 |
#define GEN_INT_ARITH1_64 GEN_INT_ARITH1
|
683 |
#endif
|
684 |
|
685 |
/* add add. addo addo. */
|
686 |
static inline void gen_op_addo (void) |
687 |
{ |
688 |
gen_op_move_T2_T0(); |
689 |
gen_op_add(); |
690 |
gen_op_check_addo(); |
691 |
} |
692 |
#if defined(TARGET_PPC64)
|
693 |
#define gen_op_add_64 gen_op_add
|
694 |
static inline void gen_op_addo_64 (void) |
695 |
{ |
696 |
gen_op_move_T2_T0(); |
697 |
gen_op_add(); |
698 |
gen_op_check_addo_64(); |
699 |
} |
700 |
#endif
|
701 |
GEN_INT_ARITH2_64 (add, 0x1F, 0x0A, 0x08, PPC_INTEGER); |
702 |
/* addc addc. addco addco. */
|
703 |
static inline void gen_op_addc (void) |
704 |
{ |
705 |
gen_op_move_T2_T0(); |
706 |
gen_op_add(); |
707 |
gen_op_check_addc(); |
708 |
} |
709 |
static inline void gen_op_addco (void) |
710 |
{ |
711 |
gen_op_move_T2_T0(); |
712 |
gen_op_add(); |
713 |
gen_op_check_addc(); |
714 |
gen_op_check_addo(); |
715 |
} |
716 |
#if defined(TARGET_PPC64)
|
717 |
static inline void gen_op_addc_64 (void) |
718 |
{ |
719 |
gen_op_move_T2_T0(); |
720 |
gen_op_add(); |
721 |
gen_op_check_addc_64(); |
722 |
} |
723 |
static inline void gen_op_addco_64 (void) |
724 |
{ |
725 |
gen_op_move_T2_T0(); |
726 |
gen_op_add(); |
727 |
gen_op_check_addc_64(); |
728 |
gen_op_check_addo_64(); |
729 |
} |
730 |
#endif
|
731 |
GEN_INT_ARITH2_64 (addc, 0x1F, 0x0A, 0x00, PPC_INTEGER); |
732 |
/* adde adde. addeo addeo. */
|
733 |
static inline void gen_op_addeo (void) |
734 |
{ |
735 |
gen_op_move_T2_T0(); |
736 |
gen_op_adde(); |
737 |
gen_op_check_addo(); |
738 |
} |
739 |
#if defined(TARGET_PPC64)
|
740 |
static inline void gen_op_addeo_64 (void) |
741 |
{ |
742 |
gen_op_move_T2_T0(); |
743 |
gen_op_adde_64(); |
744 |
gen_op_check_addo_64(); |
745 |
} |
746 |
#endif
|
747 |
GEN_INT_ARITH2_64 (adde, 0x1F, 0x0A, 0x04, PPC_INTEGER); |
748 |
/* addme addme. addmeo addmeo. */
|
749 |
static inline void gen_op_addme (void) |
750 |
{ |
751 |
gen_op_move_T1_T0(); |
752 |
gen_op_add_me(); |
753 |
} |
754 |
#if defined(TARGET_PPC64)
|
755 |
static inline void gen_op_addme_64 (void) |
756 |
{ |
757 |
gen_op_move_T1_T0(); |
758 |
gen_op_add_me_64(); |
759 |
} |
760 |
#endif
|
761 |
GEN_INT_ARITH1_64 (addme, 0x1F, 0x0A, 0x07, PPC_INTEGER); |
762 |
/* addze addze. addzeo addzeo. */
|
763 |
static inline void gen_op_addze (void) |
764 |
{ |
765 |
gen_op_move_T2_T0(); |
766 |
gen_op_add_ze(); |
767 |
gen_op_check_addc(); |
768 |
} |
769 |
static inline void gen_op_addzeo (void) |
770 |
{ |
771 |
gen_op_move_T2_T0(); |
772 |
gen_op_add_ze(); |
773 |
gen_op_check_addc(); |
774 |
gen_op_check_addo(); |
775 |
} |
776 |
#if defined(TARGET_PPC64)
|
777 |
static inline void gen_op_addze_64 (void) |
778 |
{ |
779 |
gen_op_move_T2_T0(); |
780 |
gen_op_add_ze(); |
781 |
gen_op_check_addc_64(); |
782 |
} |
783 |
static inline void gen_op_addzeo_64 (void) |
784 |
{ |
785 |
gen_op_move_T2_T0(); |
786 |
gen_op_add_ze(); |
787 |
gen_op_check_addc_64(); |
788 |
gen_op_check_addo_64(); |
789 |
} |
790 |
#endif
|
791 |
GEN_INT_ARITH1_64 (addze, 0x1F, 0x0A, 0x06, PPC_INTEGER); |
792 |
/* divw divw. divwo divwo. */
|
793 |
GEN_INT_ARITH2 (divw, 0x1F, 0x0B, 0x0F, PPC_INTEGER); |
794 |
/* divwu divwu. divwuo divwuo. */
|
795 |
GEN_INT_ARITH2 (divwu, 0x1F, 0x0B, 0x0E, PPC_INTEGER); |
796 |
/* mulhw mulhw. */
|
797 |
GEN_INT_ARITHN (mulhw, 0x1F, 0x0B, 0x02, PPC_INTEGER); |
798 |
/* mulhwu mulhwu. */
|
799 |
GEN_INT_ARITHN (mulhwu, 0x1F, 0x0B, 0x00, PPC_INTEGER); |
800 |
/* mullw mullw. mullwo mullwo. */
|
801 |
GEN_INT_ARITH2 (mullw, 0x1F, 0x0B, 0x07, PPC_INTEGER); |
802 |
/* neg neg. nego nego. */
|
803 |
GEN_INT_ARITH1_64 (neg, 0x1F, 0x08, 0x03, PPC_INTEGER); |
804 |
/* subf subf. subfo subfo. */
|
805 |
static inline void gen_op_subfo (void) |
806 |
{ |
807 |
gen_op_move_T2_T0(); |
808 |
gen_op_subf(); |
809 |
gen_op_check_subfo(); |
810 |
} |
811 |
#if defined(TARGET_PPC64)
|
812 |
#define gen_op_subf_64 gen_op_subf
|
813 |
static inline void gen_op_subfo_64 (void) |
814 |
{ |
815 |
gen_op_move_T2_T0(); |
816 |
gen_op_subf(); |
817 |
gen_op_check_subfo_64(); |
818 |
} |
819 |
#endif
|
820 |
GEN_INT_ARITH2_64 (subf, 0x1F, 0x08, 0x01, PPC_INTEGER); |
821 |
/* subfc subfc. subfco subfco. */
|
822 |
static inline void gen_op_subfc (void) |
823 |
{ |
824 |
gen_op_subf(); |
825 |
gen_op_check_subfc(); |
826 |
} |
827 |
static inline void gen_op_subfco (void) |
828 |
{ |
829 |
gen_op_move_T2_T0(); |
830 |
gen_op_subf(); |
831 |
gen_op_check_subfc(); |
832 |
gen_op_check_subfo(); |
833 |
} |
834 |
#if defined(TARGET_PPC64)
|
835 |
static inline void gen_op_subfc_64 (void) |
836 |
{ |
837 |
gen_op_subf(); |
838 |
gen_op_check_subfc_64(); |
839 |
} |
840 |
static inline void gen_op_subfco_64 (void) |
841 |
{ |
842 |
gen_op_move_T2_T0(); |
843 |
gen_op_subf(); |
844 |
gen_op_check_subfc_64(); |
845 |
gen_op_check_subfo_64(); |
846 |
} |
847 |
#endif
|
848 |
GEN_INT_ARITH2_64 (subfc, 0x1F, 0x08, 0x00, PPC_INTEGER); |
849 |
/* subfe subfe. subfeo subfeo. */
|
850 |
static inline void gen_op_subfeo (void) |
851 |
{ |
852 |
gen_op_move_T2_T0(); |
853 |
gen_op_subfe(); |
854 |
gen_op_check_subfo(); |
855 |
} |
856 |
#if defined(TARGET_PPC64)
|
857 |
#define gen_op_subfe_64 gen_op_subfe
|
858 |
static inline void gen_op_subfeo_64 (void) |
859 |
{ |
860 |
gen_op_move_T2_T0(); |
861 |
gen_op_subfe_64(); |
862 |
gen_op_check_subfo_64(); |
863 |
} |
864 |
#endif
|
865 |
GEN_INT_ARITH2_64 (subfe, 0x1F, 0x08, 0x04, PPC_INTEGER); |
866 |
/* subfme subfme. subfmeo subfmeo. */
|
867 |
GEN_INT_ARITH1_64 (subfme, 0x1F, 0x08, 0x07, PPC_INTEGER); |
868 |
/* subfze subfze. subfzeo subfzeo. */
|
869 |
GEN_INT_ARITH1_64 (subfze, 0x1F, 0x08, 0x06, PPC_INTEGER); |
870 |
/* addi */
|
871 |
GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) |
872 |
{ |
873 |
target_long simm = SIMM(ctx->opcode); |
874 |
|
875 |
if (rA(ctx->opcode) == 0) { |
876 |
/* li case */
|
877 |
gen_set_T0(simm); |
878 |
} else {
|
879 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
880 |
if (likely(simm != 0)) |
881 |
gen_op_addi(simm); |
882 |
} |
883 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
884 |
} |
885 |
/* addic */
|
886 |
GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) |
887 |
{ |
888 |
target_long simm = SIMM(ctx->opcode); |
889 |
|
890 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
891 |
if (likely(simm != 0)) { |
892 |
gen_op_move_T2_T0(); |
893 |
gen_op_addi(simm); |
894 |
#if defined(TARGET_PPC64)
|
895 |
if (ctx->sf_mode)
|
896 |
gen_op_check_addc_64(); |
897 |
else
|
898 |
#endif
|
899 |
gen_op_check_addc(); |
900 |
} else {
|
901 |
gen_op_clear_xer_ca(); |
902 |
} |
903 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
904 |
} |
905 |
/* addic. */
|
906 |
GEN_HANDLER(addic_, 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) |
907 |
{ |
908 |
target_long simm = SIMM(ctx->opcode); |
909 |
|
910 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
911 |
if (likely(simm != 0)) { |
912 |
gen_op_move_T2_T0(); |
913 |
gen_op_addi(simm); |
914 |
#if defined(TARGET_PPC64)
|
915 |
if (ctx->sf_mode)
|
916 |
gen_op_check_addc_64(); |
917 |
else
|
918 |
#endif
|
919 |
gen_op_check_addc(); |
920 |
} else {
|
921 |
gen_op_clear_xer_ca(); |
922 |
} |
923 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
924 |
gen_set_Rc0(ctx); |
925 |
} |
926 |
/* addis */
|
927 |
GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) |
928 |
{ |
929 |
target_long simm = SIMM(ctx->opcode); |
930 |
|
931 |
if (rA(ctx->opcode) == 0) { |
932 |
/* lis case */
|
933 |
gen_set_T0(simm << 16);
|
934 |
} else {
|
935 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
936 |
if (likely(simm != 0)) |
937 |
gen_op_addi(simm << 16);
|
938 |
} |
939 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
940 |
} |
941 |
/* mulli */
|
942 |
GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) |
943 |
{ |
944 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
945 |
gen_op_mulli(SIMM(ctx->opcode)); |
946 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
947 |
} |
948 |
/* subfic */
|
949 |
GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) |
950 |
{ |
951 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
952 |
#if defined(TARGET_PPC64)
|
953 |
if (ctx->sf_mode)
|
954 |
gen_op_subfic_64(SIMM(ctx->opcode)); |
955 |
else
|
956 |
#endif
|
957 |
gen_op_subfic(SIMM(ctx->opcode)); |
958 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
959 |
} |
960 |
|
961 |
#if defined(TARGET_PPC64)
|
962 |
/* mulhd mulhd. */
|
963 |
GEN_INT_ARITHN (mulhd, 0x1F, 0x09, 0x02, PPC_64B); |
964 |
/* mulhdu mulhdu. */
|
965 |
GEN_INT_ARITHN (mulhdu, 0x1F, 0x09, 0x00, PPC_64B); |
966 |
/* mulld mulld. mulldo mulldo. */
|
967 |
GEN_INT_ARITH2 (mulld, 0x1F, 0x09, 0x07, PPC_64B); |
968 |
/* divd divd. divdo divdo. */
|
969 |
GEN_INT_ARITH2 (divd, 0x1F, 0x09, 0x0F, PPC_64B); |
970 |
/* divdu divdu. divduo divduo. */
|
971 |
GEN_INT_ARITH2 (divdu, 0x1F, 0x09, 0x0E, PPC_64B); |
972 |
#endif
|
973 |
|
974 |
/*** Integer comparison ***/
|
975 |
#if defined(TARGET_PPC64)
|
976 |
#define GEN_CMP(name, opc, type) \
|
977 |
GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, type) \ |
978 |
{ \ |
979 |
gen_op_load_gpr_T0(rA(ctx->opcode)); \ |
980 |
gen_op_load_gpr_T1(rB(ctx->opcode)); \ |
981 |
if (ctx->sf_mode && (ctx->opcode & 0x00200000)) \ |
982 |
gen_op_##name##_64(); \ |
983 |
else \
|
984 |
gen_op_##name(); \ |
985 |
gen_op_store_T0_crf(crfD(ctx->opcode)); \ |
986 |
} |
987 |
#else
|
988 |
#define GEN_CMP(name, opc, type) \
|
989 |
GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, type) \ |
990 |
{ \ |
991 |
gen_op_load_gpr_T0(rA(ctx->opcode)); \ |
992 |
gen_op_load_gpr_T1(rB(ctx->opcode)); \ |
993 |
gen_op_##name(); \ |
994 |
gen_op_store_T0_crf(crfD(ctx->opcode)); \ |
995 |
} |
996 |
#endif
|
997 |
|
998 |
/* cmp */
|
999 |
GEN_CMP(cmp, 0x00, PPC_INTEGER);
|
1000 |
/* cmpi */
|
1001 |
GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER) |
1002 |
{ |
1003 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
1004 |
#if defined(TARGET_PPC64)
|
1005 |
if (ctx->sf_mode && (ctx->opcode & 0x00200000)) |
1006 |
gen_op_cmpi_64(SIMM(ctx->opcode)); |
1007 |
else
|
1008 |
#endif
|
1009 |
gen_op_cmpi(SIMM(ctx->opcode)); |
1010 |
gen_op_store_T0_crf(crfD(ctx->opcode)); |
1011 |
} |
1012 |
/* cmpl */
|
1013 |
GEN_CMP(cmpl, 0x01, PPC_INTEGER);
|
1014 |
/* cmpli */
|
1015 |
GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER) |
1016 |
{ |
1017 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
1018 |
#if defined(TARGET_PPC64)
|
1019 |
if (ctx->sf_mode && (ctx->opcode & 0x00200000)) |
1020 |
gen_op_cmpli_64(UIMM(ctx->opcode)); |
1021 |
else
|
1022 |
#endif
|
1023 |
gen_op_cmpli(UIMM(ctx->opcode)); |
1024 |
gen_op_store_T0_crf(crfD(ctx->opcode)); |
1025 |
} |
1026 |
|
1027 |
/* isel (PowerPC 2.03 specification) */
|
1028 |
GEN_HANDLER(isel, 0x1F, 0x0F, 0x00, 0x00000001, PPC_203) |
1029 |
{ |
1030 |
uint32_t bi = rC(ctx->opcode); |
1031 |
uint32_t mask; |
1032 |
|
1033 |
if (rA(ctx->opcode) == 0) { |
1034 |
gen_set_T0(0);
|
1035 |
} else {
|
1036 |
gen_op_load_gpr_T1(rA(ctx->opcode)); |
1037 |
} |
1038 |
gen_op_load_gpr_T2(rB(ctx->opcode)); |
1039 |
mask = 1 << (3 - (bi & 0x03)); |
1040 |
gen_op_load_crf_T0(bi >> 2);
|
1041 |
gen_op_test_true(mask); |
1042 |
gen_op_isel(); |
1043 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
1044 |
} |
1045 |
|
1046 |
/*** Integer logical ***/
|
1047 |
#define __GEN_LOGICAL2(name, opc2, opc3, type) \
|
1048 |
GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000000, type) \ |
1049 |
{ \ |
1050 |
gen_op_load_gpr_T0(rS(ctx->opcode)); \ |
1051 |
gen_op_load_gpr_T1(rB(ctx->opcode)); \ |
1052 |
gen_op_##name(); \ |
1053 |
gen_op_store_T0_gpr(rA(ctx->opcode)); \ |
1054 |
if (unlikely(Rc(ctx->opcode) != 0)) \ |
1055 |
gen_set_Rc0(ctx); \ |
1056 |
} |
1057 |
#define GEN_LOGICAL2(name, opc, type) \
|
1058 |
__GEN_LOGICAL2(name, 0x1C, opc, type)
|
1059 |
|
1060 |
#define GEN_LOGICAL1(name, opc, type) \
|
1061 |
GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) \ |
1062 |
{ \ |
1063 |
gen_op_load_gpr_T0(rS(ctx->opcode)); \ |
1064 |
gen_op_##name(); \ |
1065 |
gen_op_store_T0_gpr(rA(ctx->opcode)); \ |
1066 |
if (unlikely(Rc(ctx->opcode) != 0)) \ |
1067 |
gen_set_Rc0(ctx); \ |
1068 |
} |
1069 |
|
1070 |
/* and & and. */
|
1071 |
GEN_LOGICAL2(and, 0x00, PPC_INTEGER);
|
1072 |
/* andc & andc. */
|
1073 |
GEN_LOGICAL2(andc, 0x01, PPC_INTEGER);
|
1074 |
/* andi. */
|
1075 |
GEN_HANDLER(andi_, 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) |
1076 |
{ |
1077 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
1078 |
gen_op_andi_T0(UIMM(ctx->opcode)); |
1079 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
1080 |
gen_set_Rc0(ctx); |
1081 |
} |
1082 |
/* andis. */
|
1083 |
GEN_HANDLER(andis_, 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) |
1084 |
{ |
1085 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
1086 |
gen_op_andi_T0(UIMM(ctx->opcode) << 16);
|
1087 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
1088 |
gen_set_Rc0(ctx); |
1089 |
} |
1090 |
|
1091 |
/* cntlzw */
|
1092 |
GEN_LOGICAL1(cntlzw, 0x00, PPC_INTEGER);
|
1093 |
/* eqv & eqv. */
|
1094 |
GEN_LOGICAL2(eqv, 0x08, PPC_INTEGER);
|
1095 |
/* extsb & extsb. */
|
1096 |
GEN_LOGICAL1(extsb, 0x1D, PPC_INTEGER);
|
1097 |
/* extsh & extsh. */
|
1098 |
GEN_LOGICAL1(extsh, 0x1C, PPC_INTEGER);
|
1099 |
/* nand & nand. */
|
1100 |
GEN_LOGICAL2(nand, 0x0E, PPC_INTEGER);
|
1101 |
/* nor & nor. */
|
1102 |
GEN_LOGICAL2(nor, 0x03, PPC_INTEGER);
|
1103 |
|
1104 |
/* or & or. */
|
1105 |
GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER) |
1106 |
{ |
1107 |
int rs, ra, rb;
|
1108 |
|
1109 |
rs = rS(ctx->opcode); |
1110 |
ra = rA(ctx->opcode); |
1111 |
rb = rB(ctx->opcode); |
1112 |
/* Optimisation for mr. ri case */
|
1113 |
if (rs != ra || rs != rb) {
|
1114 |
gen_op_load_gpr_T0(rs); |
1115 |
if (rs != rb) {
|
1116 |
gen_op_load_gpr_T1(rb); |
1117 |
gen_op_or(); |
1118 |
} |
1119 |
gen_op_store_T0_gpr(ra); |
1120 |
if (unlikely(Rc(ctx->opcode) != 0)) |
1121 |
gen_set_Rc0(ctx); |
1122 |
} else if (unlikely(Rc(ctx->opcode) != 0)) { |
1123 |
gen_op_load_gpr_T0(rs); |
1124 |
gen_set_Rc0(ctx); |
1125 |
} |
1126 |
} |
1127 |
|
1128 |
/* orc & orc. */
|
1129 |
GEN_LOGICAL2(orc, 0x0C, PPC_INTEGER);
|
1130 |
/* xor & xor. */
|
1131 |
GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER) |
1132 |
{ |
1133 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
1134 |
/* Optimisation for "set to zero" case */
|
1135 |
if (rS(ctx->opcode) != rB(ctx->opcode)) {
|
1136 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
1137 |
gen_op_xor(); |
1138 |
} else {
|
1139 |
gen_op_reset_T0(); |
1140 |
} |
1141 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
1142 |
if (unlikely(Rc(ctx->opcode) != 0)) |
1143 |
gen_set_Rc0(ctx); |
1144 |
} |
1145 |
/* ori */
|
1146 |
GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) |
1147 |
{ |
1148 |
target_ulong uimm = UIMM(ctx->opcode); |
1149 |
|
1150 |
if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { |
1151 |
/* NOP */
|
1152 |
/* XXX: should handle special NOPs for POWER series */
|
1153 |
return;
|
1154 |
} |
1155 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
1156 |
if (likely(uimm != 0)) |
1157 |
gen_op_ori(uimm); |
1158 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
1159 |
} |
1160 |
/* oris */
|
1161 |
GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) |
1162 |
{ |
1163 |
target_ulong uimm = UIMM(ctx->opcode); |
1164 |
|
1165 |
if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { |
1166 |
/* NOP */
|
1167 |
return;
|
1168 |
} |
1169 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
1170 |
if (likely(uimm != 0)) |
1171 |
gen_op_ori(uimm << 16);
|
1172 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
1173 |
} |
1174 |
/* xori */
|
1175 |
GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) |
1176 |
{ |
1177 |
target_ulong uimm = UIMM(ctx->opcode); |
1178 |
|
1179 |
if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { |
1180 |
/* NOP */
|
1181 |
return;
|
1182 |
} |
1183 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
1184 |
if (likely(uimm != 0)) |
1185 |
gen_op_xori(uimm); |
1186 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
1187 |
} |
1188 |
|
1189 |
/* xoris */
|
1190 |
GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) |
1191 |
{ |
1192 |
target_ulong uimm = UIMM(ctx->opcode); |
1193 |
|
1194 |
if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { |
1195 |
/* NOP */
|
1196 |
return;
|
1197 |
} |
1198 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
1199 |
if (likely(uimm != 0)) |
1200 |
gen_op_xori(uimm << 16);
|
1201 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
1202 |
} |
1203 |
|
1204 |
/* popcntb : PowerPC 2.03 specification */
|
1205 |
GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_203) |
1206 |
{ |
1207 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
1208 |
#if defined(TARGET_PPC64)
|
1209 |
if (ctx->sf_mode)
|
1210 |
gen_op_popcntb_64(); |
1211 |
else
|
1212 |
#endif
|
1213 |
gen_op_popcntb(); |
1214 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
1215 |
} |
1216 |
|
1217 |
#if defined(TARGET_PPC64)
|
1218 |
/* extsw & extsw. */
|
1219 |
GEN_LOGICAL1(extsw, 0x1E, PPC_64B);
|
1220 |
/* cntlzd */
|
1221 |
GEN_LOGICAL1(cntlzd, 0x01, PPC_64B);
|
1222 |
#endif
|
1223 |
|
1224 |
/*** Integer rotate ***/
|
1225 |
/* rlwimi & rlwimi. */
|
1226 |
GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) |
1227 |
{ |
1228 |
target_ulong mask; |
1229 |
uint32_t mb, me, sh; |
1230 |
|
1231 |
mb = MB(ctx->opcode); |
1232 |
me = ME(ctx->opcode); |
1233 |
sh = SH(ctx->opcode); |
1234 |
if (likely(sh == 0)) { |
1235 |
if (likely(mb == 0 && me == 31)) { |
1236 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
1237 |
goto do_store;
|
1238 |
} else if (likely(mb == 31 && me == 0)) { |
1239 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
1240 |
goto do_store;
|
1241 |
} |
1242 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
1243 |
gen_op_load_gpr_T1(rA(ctx->opcode)); |
1244 |
goto do_mask;
|
1245 |
} |
1246 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
1247 |
gen_op_load_gpr_T1(rA(ctx->opcode)); |
1248 |
gen_op_rotli32_T0(SH(ctx->opcode)); |
1249 |
do_mask:
|
1250 |
#if defined(TARGET_PPC64)
|
1251 |
mb += 32;
|
1252 |
me += 32;
|
1253 |
#endif
|
1254 |
mask = MASK(mb, me); |
1255 |
gen_op_andi_T0(mask); |
1256 |
gen_op_andi_T1(~mask); |
1257 |
gen_op_or(); |
1258 |
do_store:
|
1259 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
1260 |
if (unlikely(Rc(ctx->opcode) != 0)) |
1261 |
gen_set_Rc0(ctx); |
1262 |
} |
1263 |
/* rlwinm & rlwinm. */
|
1264 |
GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) |
1265 |
{ |
1266 |
uint32_t mb, me, sh; |
1267 |
|
1268 |
sh = SH(ctx->opcode); |
1269 |
mb = MB(ctx->opcode); |
1270 |
me = ME(ctx->opcode); |
1271 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
1272 |
if (likely(sh == 0)) { |
1273 |
goto do_mask;
|
1274 |
} |
1275 |
if (likely(mb == 0)) { |
1276 |
if (likely(me == 31)) { |
1277 |
gen_op_rotli32_T0(sh); |
1278 |
goto do_store;
|
1279 |
} else if (likely(me == (31 - sh))) { |
1280 |
gen_op_sli_T0(sh); |
1281 |
goto do_store;
|
1282 |
} |
1283 |
} else if (likely(me == 31)) { |
1284 |
if (likely(sh == (32 - mb))) { |
1285 |
gen_op_srli_T0(mb); |
1286 |
goto do_store;
|
1287 |
} |
1288 |
} |
1289 |
gen_op_rotli32_T0(sh); |
1290 |
do_mask:
|
1291 |
#if defined(TARGET_PPC64)
|
1292 |
mb += 32;
|
1293 |
me += 32;
|
1294 |
#endif
|
1295 |
gen_op_andi_T0(MASK(mb, me)); |
1296 |
do_store:
|
1297 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
1298 |
if (unlikely(Rc(ctx->opcode) != 0)) |
1299 |
gen_set_Rc0(ctx); |
1300 |
} |
1301 |
/* rlwnm & rlwnm. */
|
1302 |
GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) |
1303 |
{ |
1304 |
uint32_t mb, me; |
1305 |
|
1306 |
mb = MB(ctx->opcode); |
1307 |
me = ME(ctx->opcode); |
1308 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
1309 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
1310 |
gen_op_rotl32_T0_T1(); |
1311 |
if (unlikely(mb != 0 || me != 31)) { |
1312 |
#if defined(TARGET_PPC64)
|
1313 |
mb += 32;
|
1314 |
me += 32;
|
1315 |
#endif
|
1316 |
gen_op_andi_T0(MASK(mb, me)); |
1317 |
} |
1318 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
1319 |
if (unlikely(Rc(ctx->opcode) != 0)) |
1320 |
gen_set_Rc0(ctx); |
1321 |
} |
1322 |
|
1323 |
#if defined(TARGET_PPC64)
|
1324 |
#define GEN_PPC64_R2(name, opc1, opc2) \
|
1325 |
GEN_HANDLER(name##0, opc1, opc2, 0xFF, 0x00000000, PPC_64B) \ |
1326 |
{ \ |
1327 |
gen_##name(ctx, 0); \ |
1328 |
} \ |
1329 |
GEN_HANDLER(name##1, opc1, opc2 | 0x10, 0xFF, 0x00000000, PPC_64B) \ |
1330 |
{ \ |
1331 |
gen_##name(ctx, 1); \ |
1332 |
} |
1333 |
#define GEN_PPC64_R4(name, opc1, opc2) \
|
1334 |
GEN_HANDLER(name##0, opc1, opc2, 0xFF, 0x00000000, PPC_64B) \ |
1335 |
{ \ |
1336 |
gen_##name(ctx, 0, 0); \ |
1337 |
} \ |
1338 |
GEN_HANDLER(name##1, opc1, opc2 | 0x01, 0xFF, 0x00000000, PPC_64B) \ |
1339 |
{ \ |
1340 |
gen_##name(ctx, 0, 1); \ |
1341 |
} \ |
1342 |
GEN_HANDLER(name##2, opc1, opc2 | 0x10, 0xFF, 0x00000000, PPC_64B) \ |
1343 |
{ \ |
1344 |
gen_##name(ctx, 1, 0); \ |
1345 |
} \ |
1346 |
GEN_HANDLER(name##3, opc1, opc2 | 0x11, 0xFF, 0x00000000, PPC_64B) \ |
1347 |
{ \ |
1348 |
gen_##name(ctx, 1, 1); \ |
1349 |
} |
1350 |
|
1351 |
static inline void gen_andi_T0_64 (DisasContext *ctx, uint64_t mask) |
1352 |
{ |
1353 |
if (mask >> 32) |
1354 |
gen_op_andi_T0_64(mask >> 32, mask & 0xFFFFFFFF); |
1355 |
else
|
1356 |
gen_op_andi_T0(mask); |
1357 |
} |
1358 |
|
1359 |
static inline void gen_andi_T1_64 (DisasContext *ctx, uint64_t mask) |
1360 |
{ |
1361 |
if (mask >> 32) |
1362 |
gen_op_andi_T1_64(mask >> 32, mask & 0xFFFFFFFF); |
1363 |
else
|
1364 |
gen_op_andi_T1(mask); |
1365 |
} |
1366 |
|
1367 |
static inline void gen_rldinm (DisasContext *ctx, uint32_t mb, uint32_t me, |
1368 |
uint32_t sh) |
1369 |
{ |
1370 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
1371 |
if (likely(sh == 0)) { |
1372 |
goto do_mask;
|
1373 |
} |
1374 |
if (likely(mb == 0)) { |
1375 |
if (likely(me == 63)) { |
1376 |
gen_op_rotli64_T0(sh); |
1377 |
goto do_store;
|
1378 |
} else if (likely(me == (63 - sh))) { |
1379 |
gen_op_sli_T0(sh); |
1380 |
goto do_store;
|
1381 |
} |
1382 |
} else if (likely(me == 63)) { |
1383 |
if (likely(sh == (64 - mb))) { |
1384 |
gen_op_srli_T0_64(mb); |
1385 |
goto do_store;
|
1386 |
} |
1387 |
} |
1388 |
gen_op_rotli64_T0(sh); |
1389 |
do_mask:
|
1390 |
gen_andi_T0_64(ctx, MASK(mb, me)); |
1391 |
do_store:
|
1392 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
1393 |
if (unlikely(Rc(ctx->opcode) != 0)) |
1394 |
gen_set_Rc0(ctx); |
1395 |
} |
1396 |
/* rldicl - rldicl. */
|
1397 |
static inline void gen_rldicl (DisasContext *ctx, int mbn, int shn) |
1398 |
{ |
1399 |
uint32_t sh, mb; |
1400 |
|
1401 |
sh = SH(ctx->opcode) | (shn << 5);
|
1402 |
mb = MB(ctx->opcode) | (mbn << 5);
|
1403 |
gen_rldinm(ctx, mb, 63, sh);
|
1404 |
} |
1405 |
GEN_PPC64_R4(rldicl, 0x1E, 0x00); |
1406 |
/* rldicr - rldicr. */
|
1407 |
static inline void gen_rldicr (DisasContext *ctx, int men, int shn) |
1408 |
{ |
1409 |
uint32_t sh, me; |
1410 |
|
1411 |
sh = SH(ctx->opcode) | (shn << 5);
|
1412 |
me = MB(ctx->opcode) | (men << 5);
|
1413 |
gen_rldinm(ctx, 0, me, sh);
|
1414 |
} |
1415 |
GEN_PPC64_R4(rldicr, 0x1E, 0x02); |
1416 |
/* rldic - rldic. */
|
1417 |
static inline void gen_rldic (DisasContext *ctx, int mbn, int shn) |
1418 |
{ |
1419 |
uint32_t sh, mb; |
1420 |
|
1421 |
sh = SH(ctx->opcode) | (shn << 5);
|
1422 |
mb = MB(ctx->opcode) | (mbn << 5);
|
1423 |
gen_rldinm(ctx, mb, 63 - sh, sh);
|
1424 |
} |
1425 |
GEN_PPC64_R4(rldic, 0x1E, 0x04); |
1426 |
|
1427 |
static inline void gen_rldnm (DisasContext *ctx, uint32_t mb, uint32_t me) |
1428 |
{ |
1429 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
1430 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
1431 |
gen_op_rotl64_T0_T1(); |
1432 |
if (unlikely(mb != 0 || me != 63)) { |
1433 |
gen_andi_T0_64(ctx, MASK(mb, me)); |
1434 |
} |
1435 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
1436 |
if (unlikely(Rc(ctx->opcode) != 0)) |
1437 |
gen_set_Rc0(ctx); |
1438 |
} |
1439 |
|
1440 |
/* rldcl - rldcl. */
|
1441 |
static inline void gen_rldcl (DisasContext *ctx, int mbn) |
1442 |
{ |
1443 |
uint32_t mb; |
1444 |
|
1445 |
mb = MB(ctx->opcode) | (mbn << 5);
|
1446 |
gen_rldnm(ctx, mb, 63);
|
1447 |
} |
1448 |
GEN_PPC64_R2(rldcl, 0x1E, 0x08); |
1449 |
/* rldcr - rldcr. */
|
1450 |
static inline void gen_rldcr (DisasContext *ctx, int men) |
1451 |
{ |
1452 |
uint32_t me; |
1453 |
|
1454 |
me = MB(ctx->opcode) | (men << 5);
|
1455 |
gen_rldnm(ctx, 0, me);
|
1456 |
} |
1457 |
GEN_PPC64_R2(rldcr, 0x1E, 0x09); |
1458 |
/* rldimi - rldimi. */
|
1459 |
static inline void gen_rldimi (DisasContext *ctx, int mbn, int shn) |
1460 |
{ |
1461 |
uint64_t mask; |
1462 |
uint32_t sh, mb; |
1463 |
|
1464 |
sh = SH(ctx->opcode) | (shn << 5);
|
1465 |
mb = MB(ctx->opcode) | (mbn << 5);
|
1466 |
if (likely(sh == 0)) { |
1467 |
if (likely(mb == 0)) { |
1468 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
1469 |
goto do_store;
|
1470 |
} else if (likely(mb == 63)) { |
1471 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
1472 |
goto do_store;
|
1473 |
} |
1474 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
1475 |
gen_op_load_gpr_T1(rA(ctx->opcode)); |
1476 |
goto do_mask;
|
1477 |
} |
1478 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
1479 |
gen_op_load_gpr_T1(rA(ctx->opcode)); |
1480 |
gen_op_rotli64_T0(sh); |
1481 |
do_mask:
|
1482 |
mask = MASK(mb, 63 - sh);
|
1483 |
gen_andi_T0_64(ctx, mask); |
1484 |
gen_andi_T1_64(ctx, ~mask); |
1485 |
gen_op_or(); |
1486 |
do_store:
|
1487 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
1488 |
if (unlikely(Rc(ctx->opcode) != 0)) |
1489 |
gen_set_Rc0(ctx); |
1490 |
} |
1491 |
GEN_PPC64_R4(rldimi, 0x1E, 0x06); |
1492 |
#endif
|
1493 |
|
1494 |
/*** Integer shift ***/
|
1495 |
/* slw & slw. */
|
1496 |
__GEN_LOGICAL2(slw, 0x18, 0x00, PPC_INTEGER); |
1497 |
/* sraw & sraw. */
|
1498 |
__GEN_LOGICAL2(sraw, 0x18, 0x18, PPC_INTEGER); |
1499 |
/* srawi & srawi. */
|
1500 |
GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER) |
1501 |
{ |
1502 |
int mb, me;
|
1503 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
1504 |
if (SH(ctx->opcode) != 0) { |
1505 |
gen_op_move_T1_T0(); |
1506 |
mb = 32 - SH(ctx->opcode);
|
1507 |
me = 31;
|
1508 |
#if defined(TARGET_PPC64)
|
1509 |
mb += 32;
|
1510 |
me += 32;
|
1511 |
#endif
|
1512 |
gen_op_srawi(SH(ctx->opcode), MASK(mb, me)); |
1513 |
} |
1514 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
1515 |
if (unlikely(Rc(ctx->opcode) != 0)) |
1516 |
gen_set_Rc0(ctx); |
1517 |
} |
1518 |
/* srw & srw. */
|
1519 |
__GEN_LOGICAL2(srw, 0x18, 0x10, PPC_INTEGER); |
1520 |
|
1521 |
#if defined(TARGET_PPC64)
|
1522 |
/* sld & sld. */
|
1523 |
__GEN_LOGICAL2(sld, 0x1B, 0x00, PPC_64B); |
1524 |
/* srad & srad. */
|
1525 |
__GEN_LOGICAL2(srad, 0x1A, 0x18, PPC_64B); |
1526 |
/* sradi & sradi. */
|
1527 |
static inline void gen_sradi (DisasContext *ctx, int n) |
1528 |
{ |
1529 |
uint64_t mask; |
1530 |
int sh, mb, me;
|
1531 |
|
1532 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
1533 |
sh = SH(ctx->opcode) + (n << 5);
|
1534 |
if (sh != 0) { |
1535 |
gen_op_move_T1_T0(); |
1536 |
mb = 64 - SH(ctx->opcode);
|
1537 |
me = 63;
|
1538 |
mask = MASK(mb, me); |
1539 |
gen_op_sradi(sh, mask >> 32, mask);
|
1540 |
} |
1541 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
1542 |
if (unlikely(Rc(ctx->opcode) != 0)) |
1543 |
gen_set_Rc0(ctx); |
1544 |
} |
1545 |
GEN_HANDLER(sradi0, 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B) |
1546 |
{ |
1547 |
gen_sradi(ctx, 0);
|
1548 |
} |
1549 |
GEN_HANDLER(sradi1, 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B) |
1550 |
{ |
1551 |
gen_sradi(ctx, 1);
|
1552 |
} |
1553 |
/* srd & srd. */
|
1554 |
__GEN_LOGICAL2(srd, 0x1B, 0x10, PPC_64B); |
1555 |
#endif
|
1556 |
|
1557 |
/*** Floating-Point arithmetic ***/
|
1558 |
#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, type) \
|
1559 |
GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type) \ |
1560 |
{ \ |
1561 |
if (unlikely(!ctx->fpu_enabled)) { \
|
1562 |
GEN_EXCP_NO_FP(ctx); \ |
1563 |
return; \
|
1564 |
} \ |
1565 |
gen_op_reset_scrfx(); \ |
1566 |
gen_op_load_fpr_FT0(rA(ctx->opcode)); \ |
1567 |
gen_op_load_fpr_FT1(rC(ctx->opcode)); \ |
1568 |
gen_op_load_fpr_FT2(rB(ctx->opcode)); \ |
1569 |
gen_op_f##op(); \ |
1570 |
if (isfloat) { \
|
1571 |
gen_op_frsp(); \ |
1572 |
} \ |
1573 |
gen_op_store_FT0_fpr(rD(ctx->opcode)); \ |
1574 |
if (unlikely(Rc(ctx->opcode) != 0)) \ |
1575 |
gen_op_set_Rc1(); \ |
1576 |
} |
1577 |
|
1578 |
#define GEN_FLOAT_ACB(name, op2, type) \
|
1579 |
_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, type); \ |
1580 |
_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, type); |
1581 |
|
1582 |
#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat) \
|
1583 |
GEN_HANDLER(f##name, op1, op2, 0xFF, inval, PPC_FLOAT) \ |
1584 |
{ \ |
1585 |
if (unlikely(!ctx->fpu_enabled)) { \
|
1586 |
GEN_EXCP_NO_FP(ctx); \ |
1587 |
return; \
|
1588 |
} \ |
1589 |
gen_op_reset_scrfx(); \ |
1590 |
gen_op_load_fpr_FT0(rA(ctx->opcode)); \ |
1591 |
gen_op_load_fpr_FT1(rB(ctx->opcode)); \ |
1592 |
gen_op_f##op(); \ |
1593 |
if (isfloat) { \
|
1594 |
gen_op_frsp(); \ |
1595 |
} \ |
1596 |
gen_op_store_FT0_fpr(rD(ctx->opcode)); \ |
1597 |
if (unlikely(Rc(ctx->opcode) != 0)) \ |
1598 |
gen_op_set_Rc1(); \ |
1599 |
} |
1600 |
#define GEN_FLOAT_AB(name, op2, inval) \
|
1601 |
_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0); \ |
1602 |
_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1); |
1603 |
|
1604 |
#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat) \
|
1605 |
GEN_HANDLER(f##name, op1, op2, 0xFF, inval, PPC_FLOAT) \ |
1606 |
{ \ |
1607 |
if (unlikely(!ctx->fpu_enabled)) { \
|
1608 |
GEN_EXCP_NO_FP(ctx); \ |
1609 |
return; \
|
1610 |
} \ |
1611 |
gen_op_reset_scrfx(); \ |
1612 |
gen_op_load_fpr_FT0(rA(ctx->opcode)); \ |
1613 |
gen_op_load_fpr_FT1(rC(ctx->opcode)); \ |
1614 |
gen_op_f##op(); \ |
1615 |
if (isfloat) { \
|
1616 |
gen_op_frsp(); \ |
1617 |
} \ |
1618 |
gen_op_store_FT0_fpr(rD(ctx->opcode)); \ |
1619 |
if (unlikely(Rc(ctx->opcode) != 0)) \ |
1620 |
gen_op_set_Rc1(); \ |
1621 |
} |
1622 |
#define GEN_FLOAT_AC(name, op2, inval) \
|
1623 |
_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0); \ |
1624 |
_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1); |
1625 |
|
1626 |
#define GEN_FLOAT_B(name, op2, op3, type) \
|
1627 |
GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type) \ |
1628 |
{ \ |
1629 |
if (unlikely(!ctx->fpu_enabled)) { \
|
1630 |
GEN_EXCP_NO_FP(ctx); \ |
1631 |
return; \
|
1632 |
} \ |
1633 |
gen_op_reset_scrfx(); \ |
1634 |
gen_op_load_fpr_FT0(rB(ctx->opcode)); \ |
1635 |
gen_op_f##name(); \ |
1636 |
gen_op_store_FT0_fpr(rD(ctx->opcode)); \ |
1637 |
if (unlikely(Rc(ctx->opcode) != 0)) \ |
1638 |
gen_op_set_Rc1(); \ |
1639 |
} |
1640 |
|
1641 |
#define GEN_FLOAT_BS(name, op1, op2, type) \
|
1642 |
GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type) \ |
1643 |
{ \ |
1644 |
if (unlikely(!ctx->fpu_enabled)) { \
|
1645 |
GEN_EXCP_NO_FP(ctx); \ |
1646 |
return; \
|
1647 |
} \ |
1648 |
gen_op_reset_scrfx(); \ |
1649 |
gen_op_load_fpr_FT0(rB(ctx->opcode)); \ |
1650 |
gen_op_f##name(); \ |
1651 |
gen_op_store_FT0_fpr(rD(ctx->opcode)); \ |
1652 |
if (unlikely(Rc(ctx->opcode) != 0)) \ |
1653 |
gen_op_set_Rc1(); \ |
1654 |
} |
1655 |
|
1656 |
/* fadd - fadds */
|
1657 |
GEN_FLOAT_AB(add, 0x15, 0x000007C0); |
1658 |
/* fdiv - fdivs */
|
1659 |
GEN_FLOAT_AB(div, 0x12, 0x000007C0); |
1660 |
/* fmul - fmuls */
|
1661 |
GEN_FLOAT_AC(mul, 0x19, 0x0000F800); |
1662 |
|
1663 |
/* fres */
|
1664 |
GEN_FLOAT_BS(res, 0x3B, 0x18, PPC_FLOAT_FRES); |
1665 |
|
1666 |
/* frsqrte */
|
1667 |
GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, PPC_FLOAT_FRSQRTE); |
1668 |
|
1669 |
/* fsel */
|
1670 |
_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, PPC_FLOAT_FSEL); |
1671 |
/* fsub - fsubs */
|
1672 |
GEN_FLOAT_AB(sub, 0x14, 0x000007C0); |
1673 |
/* Optional: */
|
1674 |
/* fsqrt */
|
1675 |
GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT) |
1676 |
{ |
1677 |
if (unlikely(!ctx->fpu_enabled)) {
|
1678 |
GEN_EXCP_NO_FP(ctx); |
1679 |
return;
|
1680 |
} |
1681 |
gen_op_reset_scrfx(); |
1682 |
gen_op_load_fpr_FT0(rB(ctx->opcode)); |
1683 |
gen_op_fsqrt(); |
1684 |
gen_op_store_FT0_fpr(rD(ctx->opcode)); |
1685 |
if (unlikely(Rc(ctx->opcode) != 0)) |
1686 |
gen_op_set_Rc1(); |
1687 |
} |
1688 |
|
1689 |
GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT) |
1690 |
{ |
1691 |
if (unlikely(!ctx->fpu_enabled)) {
|
1692 |
GEN_EXCP_NO_FP(ctx); |
1693 |
return;
|
1694 |
} |
1695 |
gen_op_reset_scrfx(); |
1696 |
gen_op_load_fpr_FT0(rB(ctx->opcode)); |
1697 |
gen_op_fsqrt(); |
1698 |
gen_op_frsp(); |
1699 |
gen_op_store_FT0_fpr(rD(ctx->opcode)); |
1700 |
if (unlikely(Rc(ctx->opcode) != 0)) |
1701 |
gen_op_set_Rc1(); |
1702 |
} |
1703 |
|
1704 |
/*** Floating-Point multiply-and-add ***/
|
1705 |
/* fmadd - fmadds */
|
1706 |
GEN_FLOAT_ACB(madd, 0x1D, PPC_FLOAT);
|
1707 |
/* fmsub - fmsubs */
|
1708 |
GEN_FLOAT_ACB(msub, 0x1C, PPC_FLOAT);
|
1709 |
/* fnmadd - fnmadds */
|
1710 |
GEN_FLOAT_ACB(nmadd, 0x1F, PPC_FLOAT);
|
1711 |
/* fnmsub - fnmsubs */
|
1712 |
GEN_FLOAT_ACB(nmsub, 0x1E, PPC_FLOAT);
|
1713 |
|
1714 |
/*** Floating-Point round & convert ***/
|
1715 |
/* fctiw */
|
1716 |
GEN_FLOAT_B(ctiw, 0x0E, 0x00, PPC_FLOAT); |
1717 |
/* fctiwz */
|
1718 |
GEN_FLOAT_B(ctiwz, 0x0F, 0x00, PPC_FLOAT); |
1719 |
/* frsp */
|
1720 |
GEN_FLOAT_B(rsp, 0x0C, 0x00, PPC_FLOAT); |
1721 |
#if defined(TARGET_PPC64)
|
1722 |
/* fcfid */
|
1723 |
GEN_FLOAT_B(cfid, 0x0E, 0x1A, PPC_64B); |
1724 |
/* fctid */
|
1725 |
GEN_FLOAT_B(ctid, 0x0E, 0x19, PPC_64B); |
1726 |
/* fctidz */
|
1727 |
GEN_FLOAT_B(ctidz, 0x0F, 0x19, PPC_64B); |
1728 |
#endif
|
1729 |
|
1730 |
/*** Floating-Point compare ***/
|
1731 |
/* fcmpo */
|
1732 |
GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT) |
1733 |
{ |
1734 |
if (unlikely(!ctx->fpu_enabled)) {
|
1735 |
GEN_EXCP_NO_FP(ctx); |
1736 |
return;
|
1737 |
} |
1738 |
gen_op_reset_scrfx(); |
1739 |
gen_op_load_fpr_FT0(rA(ctx->opcode)); |
1740 |
gen_op_load_fpr_FT1(rB(ctx->opcode)); |
1741 |
gen_op_fcmpo(); |
1742 |
gen_op_store_T0_crf(crfD(ctx->opcode)); |
1743 |
} |
1744 |
|
1745 |
/* fcmpu */
|
1746 |
GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT) |
1747 |
{ |
1748 |
if (unlikely(!ctx->fpu_enabled)) {
|
1749 |
GEN_EXCP_NO_FP(ctx); |
1750 |
return;
|
1751 |
} |
1752 |
gen_op_reset_scrfx(); |
1753 |
gen_op_load_fpr_FT0(rA(ctx->opcode)); |
1754 |
gen_op_load_fpr_FT1(rB(ctx->opcode)); |
1755 |
gen_op_fcmpu(); |
1756 |
gen_op_store_T0_crf(crfD(ctx->opcode)); |
1757 |
} |
1758 |
|
1759 |
/*** Floating-point move ***/
|
1760 |
/* fabs */
|
1761 |
GEN_FLOAT_B(abs, 0x08, 0x08, PPC_FLOAT); |
1762 |
|
1763 |
/* fmr - fmr. */
|
1764 |
GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT) |
1765 |
{ |
1766 |
if (unlikely(!ctx->fpu_enabled)) {
|
1767 |
GEN_EXCP_NO_FP(ctx); |
1768 |
return;
|
1769 |
} |
1770 |
gen_op_reset_scrfx(); |
1771 |
gen_op_load_fpr_FT0(rB(ctx->opcode)); |
1772 |
gen_op_store_FT0_fpr(rD(ctx->opcode)); |
1773 |
if (unlikely(Rc(ctx->opcode) != 0)) |
1774 |
gen_op_set_Rc1(); |
1775 |
} |
1776 |
|
1777 |
/* fnabs */
|
1778 |
GEN_FLOAT_B(nabs, 0x08, 0x04, PPC_FLOAT); |
1779 |
/* fneg */
|
1780 |
GEN_FLOAT_B(neg, 0x08, 0x01, PPC_FLOAT); |
1781 |
|
1782 |
/*** Floating-Point status & ctrl register ***/
|
1783 |
/* mcrfs */
|
1784 |
GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT) |
1785 |
{ |
1786 |
if (unlikely(!ctx->fpu_enabled)) {
|
1787 |
GEN_EXCP_NO_FP(ctx); |
1788 |
return;
|
1789 |
} |
1790 |
gen_op_load_fpscr_T0(crfS(ctx->opcode)); |
1791 |
gen_op_store_T0_crf(crfD(ctx->opcode)); |
1792 |
gen_op_clear_fpscr(crfS(ctx->opcode)); |
1793 |
} |
1794 |
|
1795 |
/* mffs */
|
1796 |
GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT) |
1797 |
{ |
1798 |
if (unlikely(!ctx->fpu_enabled)) {
|
1799 |
GEN_EXCP_NO_FP(ctx); |
1800 |
return;
|
1801 |
} |
1802 |
gen_op_load_fpscr(); |
1803 |
gen_op_store_FT0_fpr(rD(ctx->opcode)); |
1804 |
if (unlikely(Rc(ctx->opcode) != 0)) |
1805 |
gen_op_set_Rc1(); |
1806 |
} |
1807 |
|
1808 |
/* mtfsb0 */
|
1809 |
GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT) |
1810 |
{ |
1811 |
uint8_t crb; |
1812 |
|
1813 |
if (unlikely(!ctx->fpu_enabled)) {
|
1814 |
GEN_EXCP_NO_FP(ctx); |
1815 |
return;
|
1816 |
} |
1817 |
crb = crbD(ctx->opcode) >> 2;
|
1818 |
gen_op_load_fpscr_T0(crb); |
1819 |
gen_op_andi_T0(~(1 << (crbD(ctx->opcode) & 0x03))); |
1820 |
gen_op_store_T0_fpscr(crb); |
1821 |
if (unlikely(Rc(ctx->opcode) != 0)) |
1822 |
gen_op_set_Rc1(); |
1823 |
} |
1824 |
|
1825 |
/* mtfsb1 */
|
1826 |
GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT) |
1827 |
{ |
1828 |
uint8_t crb; |
1829 |
|
1830 |
if (unlikely(!ctx->fpu_enabled)) {
|
1831 |
GEN_EXCP_NO_FP(ctx); |
1832 |
return;
|
1833 |
} |
1834 |
crb = crbD(ctx->opcode) >> 2;
|
1835 |
gen_op_load_fpscr_T0(crb); |
1836 |
gen_op_ori(1 << (crbD(ctx->opcode) & 0x03)); |
1837 |
gen_op_store_T0_fpscr(crb); |
1838 |
if (unlikely(Rc(ctx->opcode) != 0)) |
1839 |
gen_op_set_Rc1(); |
1840 |
} |
1841 |
|
1842 |
/* mtfsf */
|
1843 |
GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x02010000, PPC_FLOAT) |
1844 |
{ |
1845 |
if (unlikely(!ctx->fpu_enabled)) {
|
1846 |
GEN_EXCP_NO_FP(ctx); |
1847 |
return;
|
1848 |
} |
1849 |
gen_op_load_fpr_FT0(rB(ctx->opcode)); |
1850 |
gen_op_store_fpscr(FM(ctx->opcode)); |
1851 |
if (unlikely(Rc(ctx->opcode) != 0)) |
1852 |
gen_op_set_Rc1(); |
1853 |
} |
1854 |
|
1855 |
/* mtfsfi */
|
1856 |
GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT) |
1857 |
{ |
1858 |
if (unlikely(!ctx->fpu_enabled)) {
|
1859 |
GEN_EXCP_NO_FP(ctx); |
1860 |
return;
|
1861 |
} |
1862 |
gen_op_store_T0_fpscri(crbD(ctx->opcode) >> 2, FPIMM(ctx->opcode));
|
1863 |
if (unlikely(Rc(ctx->opcode) != 0)) |
1864 |
gen_op_set_Rc1(); |
1865 |
} |
1866 |
|
1867 |
/*** Addressing modes ***/
|
1868 |
/* Register indirect with immediate index : EA = (rA|0) + SIMM */
|
1869 |
static inline void gen_addr_imm_index (DisasContext *ctx, int maskl) |
1870 |
{ |
1871 |
target_long simm = SIMM(ctx->opcode); |
1872 |
|
1873 |
if (maskl)
|
1874 |
simm &= ~0x03;
|
1875 |
if (rA(ctx->opcode) == 0) { |
1876 |
gen_set_T0(simm); |
1877 |
} else {
|
1878 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
1879 |
if (likely(simm != 0)) |
1880 |
gen_op_addi(simm); |
1881 |
} |
1882 |
#ifdef DEBUG_MEMORY_ACCESSES
|
1883 |
gen_op_print_mem_EA(); |
1884 |
#endif
|
1885 |
} |
1886 |
|
1887 |
static inline void gen_addr_reg_index (DisasContext *ctx) |
1888 |
{ |
1889 |
if (rA(ctx->opcode) == 0) { |
1890 |
gen_op_load_gpr_T0(rB(ctx->opcode)); |
1891 |
} else {
|
1892 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
1893 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
1894 |
gen_op_add(); |
1895 |
} |
1896 |
#ifdef DEBUG_MEMORY_ACCESSES
|
1897 |
gen_op_print_mem_EA(); |
1898 |
#endif
|
1899 |
} |
1900 |
|
1901 |
static inline void gen_addr_register (DisasContext *ctx) |
1902 |
{ |
1903 |
if (rA(ctx->opcode) == 0) { |
1904 |
gen_op_reset_T0(); |
1905 |
} else {
|
1906 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
1907 |
} |
1908 |
#ifdef DEBUG_MEMORY_ACCESSES
|
1909 |
gen_op_print_mem_EA(); |
1910 |
#endif
|
1911 |
} |
1912 |
|
1913 |
/*** Integer load ***/
|
1914 |
#define op_ldst(name) (*gen_op_##name[ctx->mem_idx])() |
1915 |
#if defined(CONFIG_USER_ONLY)
|
1916 |
#if defined(TARGET_PPC64)
|
1917 |
#define OP_LD_TABLE(width) \
|
1918 |
static GenOpFunc *gen_op_l##width[] = { \ |
1919 |
&gen_op_l##width##_raw, \ |
1920 |
&gen_op_l##width##_le_raw, \ |
1921 |
&gen_op_l##width##_64_raw, \ |
1922 |
&gen_op_l##width##_le_64_raw, \ |
1923 |
}; |
1924 |
#define OP_ST_TABLE(width) \
|
1925 |
static GenOpFunc *gen_op_st##width[] = { \ |
1926 |
&gen_op_st##width##_raw, \ |
1927 |
&gen_op_st##width##_le_raw, \ |
1928 |
&gen_op_st##width##_64_raw, \ |
1929 |
&gen_op_st##width##_le_64_raw, \ |
1930 |
}; |
1931 |
/* Byte access routine are endian safe */
|
1932 |
#define gen_op_stb_le_64_raw gen_op_stb_64_raw
|
1933 |
#define gen_op_lbz_le_64_raw gen_op_lbz_64_raw
|
1934 |
#else
|
1935 |
#define OP_LD_TABLE(width) \
|
1936 |
static GenOpFunc *gen_op_l##width[] = { \ |
1937 |
&gen_op_l##width##_raw, \ |
1938 |
&gen_op_l##width##_le_raw, \ |
1939 |
}; |
1940 |
#define OP_ST_TABLE(width) \
|
1941 |
static GenOpFunc *gen_op_st##width[] = { \ |
1942 |
&gen_op_st##width##_raw, \ |
1943 |
&gen_op_st##width##_le_raw, \ |
1944 |
}; |
1945 |
#endif
|
1946 |
/* Byte access routine are endian safe */
|
1947 |
#define gen_op_stb_le_raw gen_op_stb_raw
|
1948 |
#define gen_op_lbz_le_raw gen_op_lbz_raw
|
1949 |
#else
|
1950 |
#if defined(TARGET_PPC64)
|
1951 |
#define OP_LD_TABLE(width) \
|
1952 |
static GenOpFunc *gen_op_l##width[] = { \ |
1953 |
&gen_op_l##width##_user, \ |
1954 |
&gen_op_l##width##_le_user, \ |
1955 |
&gen_op_l##width##_kernel, \ |
1956 |
&gen_op_l##width##_le_kernel, \ |
1957 |
&gen_op_l##width##_64_user, \ |
1958 |
&gen_op_l##width##_le_64_user, \ |
1959 |
&gen_op_l##width##_64_kernel, \ |
1960 |
&gen_op_l##width##_le_64_kernel, \ |
1961 |
}; |
1962 |
#define OP_ST_TABLE(width) \
|
1963 |
static GenOpFunc *gen_op_st##width[] = { \ |
1964 |
&gen_op_st##width##_user, \ |
1965 |
&gen_op_st##width##_le_user, \ |
1966 |
&gen_op_st##width##_kernel, \ |
1967 |
&gen_op_st##width##_le_kernel, \ |
1968 |
&gen_op_st##width##_64_user, \ |
1969 |
&gen_op_st##width##_le_64_user, \ |
1970 |
&gen_op_st##width##_64_kernel, \ |
1971 |
&gen_op_st##width##_le_64_kernel, \ |
1972 |
}; |
1973 |
/* Byte access routine are endian safe */
|
1974 |
#define gen_op_stb_le_64_user gen_op_stb_64_user
|
1975 |
#define gen_op_lbz_le_64_user gen_op_lbz_64_user
|
1976 |
#define gen_op_stb_le_64_kernel gen_op_stb_64_kernel
|
1977 |
#define gen_op_lbz_le_64_kernel gen_op_lbz_64_kernel
|
1978 |
#else
|
1979 |
#define OP_LD_TABLE(width) \
|
1980 |
static GenOpFunc *gen_op_l##width[] = { \ |
1981 |
&gen_op_l##width##_user, \ |
1982 |
&gen_op_l##width##_le_user, \ |
1983 |
&gen_op_l##width##_kernel, \ |
1984 |
&gen_op_l##width##_le_kernel, \ |
1985 |
}; |
1986 |
#define OP_ST_TABLE(width) \
|
1987 |
static GenOpFunc *gen_op_st##width[] = { \ |
1988 |
&gen_op_st##width##_user, \ |
1989 |
&gen_op_st##width##_le_user, \ |
1990 |
&gen_op_st##width##_kernel, \ |
1991 |
&gen_op_st##width##_le_kernel, \ |
1992 |
}; |
1993 |
#endif
|
1994 |
/* Byte access routine are endian safe */
|
1995 |
#define gen_op_stb_le_user gen_op_stb_user
|
1996 |
#define gen_op_lbz_le_user gen_op_lbz_user
|
1997 |
#define gen_op_stb_le_kernel gen_op_stb_kernel
|
1998 |
#define gen_op_lbz_le_kernel gen_op_lbz_kernel
|
1999 |
#endif
|
2000 |
|
2001 |
#define GEN_LD(width, opc, type) \
|
2002 |
GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \ |
2003 |
{ \ |
2004 |
gen_addr_imm_index(ctx, 0); \
|
2005 |
op_ldst(l##width); \ |
2006 |
gen_op_store_T1_gpr(rD(ctx->opcode)); \ |
2007 |
} |
2008 |
|
2009 |
#define GEN_LDU(width, opc, type) \
|
2010 |
GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \ |
2011 |
{ \ |
2012 |
if (unlikely(rA(ctx->opcode) == 0 || \ |
2013 |
rA(ctx->opcode) == rD(ctx->opcode))) { \ |
2014 |
GEN_EXCP_INVAL(ctx); \ |
2015 |
return; \
|
2016 |
} \ |
2017 |
if (type == PPC_64B) \
|
2018 |
gen_addr_imm_index(ctx, 1); \
|
2019 |
else \
|
2020 |
gen_addr_imm_index(ctx, 0); \
|
2021 |
op_ldst(l##width); \ |
2022 |
gen_op_store_T1_gpr(rD(ctx->opcode)); \ |
2023 |
gen_op_store_T0_gpr(rA(ctx->opcode)); \ |
2024 |
} |
2025 |
|
2026 |
#define GEN_LDUX(width, opc2, opc3, type) \
|
2027 |
GEN_HANDLER(l##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \ |
2028 |
{ \ |
2029 |
if (unlikely(rA(ctx->opcode) == 0 || \ |
2030 |
rA(ctx->opcode) == rD(ctx->opcode))) { \ |
2031 |
GEN_EXCP_INVAL(ctx); \ |
2032 |
return; \
|
2033 |
} \ |
2034 |
gen_addr_reg_index(ctx); \ |
2035 |
op_ldst(l##width); \ |
2036 |
gen_op_store_T1_gpr(rD(ctx->opcode)); \ |
2037 |
gen_op_store_T0_gpr(rA(ctx->opcode)); \ |
2038 |
} |
2039 |
|
2040 |
#define GEN_LDX(width, opc2, opc3, type) \
|
2041 |
GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \ |
2042 |
{ \ |
2043 |
gen_addr_reg_index(ctx); \ |
2044 |
op_ldst(l##width); \ |
2045 |
gen_op_store_T1_gpr(rD(ctx->opcode)); \ |
2046 |
} |
2047 |
|
2048 |
#define GEN_LDS(width, op, type) \
|
2049 |
OP_LD_TABLE(width); \ |
2050 |
GEN_LD(width, op | 0x20, type); \
|
2051 |
GEN_LDU(width, op | 0x21, type); \
|
2052 |
GEN_LDUX(width, 0x17, op | 0x01, type); \ |
2053 |
GEN_LDX(width, 0x17, op | 0x00, type) |
2054 |
|
2055 |
/* lbz lbzu lbzux lbzx */
|
2056 |
GEN_LDS(bz, 0x02, PPC_INTEGER);
|
2057 |
/* lha lhau lhaux lhax */
|
2058 |
GEN_LDS(ha, 0x0A, PPC_INTEGER);
|
2059 |
/* lhz lhzu lhzux lhzx */
|
2060 |
GEN_LDS(hz, 0x08, PPC_INTEGER);
|
2061 |
/* lwz lwzu lwzux lwzx */
|
2062 |
GEN_LDS(wz, 0x00, PPC_INTEGER);
|
2063 |
#if defined(TARGET_PPC64)
|
2064 |
OP_LD_TABLE(wa); |
2065 |
OP_LD_TABLE(d); |
2066 |
/* lwaux */
|
2067 |
GEN_LDUX(wa, 0x15, 0x0B, PPC_64B); |
2068 |
/* lwax */
|
2069 |
GEN_LDX(wa, 0x15, 0x0A, PPC_64B); |
2070 |
/* ldux */
|
2071 |
GEN_LDUX(d, 0x15, 0x01, PPC_64B); |
2072 |
/* ldx */
|
2073 |
GEN_LDX(d, 0x15, 0x00, PPC_64B); |
2074 |
GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B) |
2075 |
{ |
2076 |
if (Rc(ctx->opcode)) {
|
2077 |
if (unlikely(rA(ctx->opcode) == 0 || |
2078 |
rA(ctx->opcode) == rD(ctx->opcode))) { |
2079 |
GEN_EXCP_INVAL(ctx); |
2080 |
return;
|
2081 |
} |
2082 |
} |
2083 |
gen_addr_imm_index(ctx, 1);
|
2084 |
if (ctx->opcode & 0x02) { |
2085 |
/* lwa (lwau is undefined) */
|
2086 |
op_ldst(lwa); |
2087 |
} else {
|
2088 |
/* ld - ldu */
|
2089 |
op_ldst(ld); |
2090 |
} |
2091 |
gen_op_store_T1_gpr(rD(ctx->opcode)); |
2092 |
if (Rc(ctx->opcode))
|
2093 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
2094 |
} |
2095 |
#endif
|
2096 |
|
2097 |
/*** Integer store ***/
|
2098 |
#define GEN_ST(width, opc, type) \
|
2099 |
GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \ |
2100 |
{ \ |
2101 |
gen_addr_imm_index(ctx, 0); \
|
2102 |
gen_op_load_gpr_T1(rS(ctx->opcode)); \ |
2103 |
op_ldst(st##width); \ |
2104 |
} |
2105 |
|
2106 |
#define GEN_STU(width, opc, type) \
|
2107 |
GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \ |
2108 |
{ \ |
2109 |
if (unlikely(rA(ctx->opcode) == 0)) { \ |
2110 |
GEN_EXCP_INVAL(ctx); \ |
2111 |
return; \
|
2112 |
} \ |
2113 |
if (type == PPC_64B) \
|
2114 |
gen_addr_imm_index(ctx, 1); \
|
2115 |
else \
|
2116 |
gen_addr_imm_index(ctx, 0); \
|
2117 |
gen_op_load_gpr_T1(rS(ctx->opcode)); \ |
2118 |
op_ldst(st##width); \ |
2119 |
gen_op_store_T0_gpr(rA(ctx->opcode)); \ |
2120 |
} |
2121 |
|
2122 |
#define GEN_STUX(width, opc2, opc3, type) \
|
2123 |
GEN_HANDLER(st##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \ |
2124 |
{ \ |
2125 |
if (unlikely(rA(ctx->opcode) == 0)) { \ |
2126 |
GEN_EXCP_INVAL(ctx); \ |
2127 |
return; \
|
2128 |
} \ |
2129 |
gen_addr_reg_index(ctx); \ |
2130 |
gen_op_load_gpr_T1(rS(ctx->opcode)); \ |
2131 |
op_ldst(st##width); \ |
2132 |
gen_op_store_T0_gpr(rA(ctx->opcode)); \ |
2133 |
} |
2134 |
|
2135 |
#define GEN_STX(width, opc2, opc3, type) \
|
2136 |
GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \ |
2137 |
{ \ |
2138 |
gen_addr_reg_index(ctx); \ |
2139 |
gen_op_load_gpr_T1(rS(ctx->opcode)); \ |
2140 |
op_ldst(st##width); \ |
2141 |
} |
2142 |
|
2143 |
#define GEN_STS(width, op, type) \
|
2144 |
OP_ST_TABLE(width); \ |
2145 |
GEN_ST(width, op | 0x20, type); \
|
2146 |
GEN_STU(width, op | 0x21, type); \
|
2147 |
GEN_STUX(width, 0x17, op | 0x01, type); \ |
2148 |
GEN_STX(width, 0x17, op | 0x00, type) |
2149 |
|
2150 |
/* stb stbu stbux stbx */
|
2151 |
GEN_STS(b, 0x06, PPC_INTEGER);
|
2152 |
/* sth sthu sthux sthx */
|
2153 |
GEN_STS(h, 0x0C, PPC_INTEGER);
|
2154 |
/* stw stwu stwux stwx */
|
2155 |
GEN_STS(w, 0x04, PPC_INTEGER);
|
2156 |
#if defined(TARGET_PPC64)
|
2157 |
OP_ST_TABLE(d); |
2158 |
GEN_STUX(d, 0x15, 0x05, PPC_64B); |
2159 |
GEN_STX(d, 0x15, 0x04, PPC_64B); |
2160 |
GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000002, PPC_64B) |
2161 |
{ |
2162 |
if (Rc(ctx->opcode)) {
|
2163 |
if (unlikely(rA(ctx->opcode) == 0)) { |
2164 |
GEN_EXCP_INVAL(ctx); |
2165 |
return;
|
2166 |
} |
2167 |
} |
2168 |
gen_addr_imm_index(ctx, 1);
|
2169 |
gen_op_load_gpr_T1(rS(ctx->opcode)); |
2170 |
op_ldst(std); |
2171 |
if (Rc(ctx->opcode))
|
2172 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
2173 |
} |
2174 |
#endif
|
2175 |
/*** Integer load and store with byte reverse ***/
|
2176 |
/* lhbrx */
|
2177 |
OP_LD_TABLE(hbr); |
2178 |
GEN_LDX(hbr, 0x16, 0x18, PPC_INTEGER); |
2179 |
/* lwbrx */
|
2180 |
OP_LD_TABLE(wbr); |
2181 |
GEN_LDX(wbr, 0x16, 0x10, PPC_INTEGER); |
2182 |
/* sthbrx */
|
2183 |
OP_ST_TABLE(hbr); |
2184 |
GEN_STX(hbr, 0x16, 0x1C, PPC_INTEGER); |
2185 |
/* stwbrx */
|
2186 |
OP_ST_TABLE(wbr); |
2187 |
GEN_STX(wbr, 0x16, 0x14, PPC_INTEGER); |
2188 |
|
2189 |
/*** Integer load and store multiple ***/
|
2190 |
#define op_ldstm(name, reg) (*gen_op_##name[ctx->mem_idx])(reg) |
2191 |
#if defined(TARGET_PPC64)
|
2192 |
#if defined(CONFIG_USER_ONLY)
|
2193 |
static GenOpFunc1 *gen_op_lmw[] = {
|
2194 |
&gen_op_lmw_raw, |
2195 |
&gen_op_lmw_le_raw, |
2196 |
&gen_op_lmw_64_raw, |
2197 |
&gen_op_lmw_le_64_raw, |
2198 |
}; |
2199 |
static GenOpFunc1 *gen_op_stmw[] = {
|
2200 |
&gen_op_stmw_64_raw, |
2201 |
&gen_op_stmw_le_64_raw, |
2202 |
}; |
2203 |
#else
|
2204 |
static GenOpFunc1 *gen_op_lmw[] = {
|
2205 |
&gen_op_lmw_user, |
2206 |
&gen_op_lmw_le_user, |
2207 |
&gen_op_lmw_kernel, |
2208 |
&gen_op_lmw_le_kernel, |
2209 |
&gen_op_lmw_64_user, |
2210 |
&gen_op_lmw_le_64_user, |
2211 |
&gen_op_lmw_64_kernel, |
2212 |
&gen_op_lmw_le_64_kernel, |
2213 |
}; |
2214 |
static GenOpFunc1 *gen_op_stmw[] = {
|
2215 |
&gen_op_stmw_user, |
2216 |
&gen_op_stmw_le_user, |
2217 |
&gen_op_stmw_kernel, |
2218 |
&gen_op_stmw_le_kernel, |
2219 |
&gen_op_stmw_64_user, |
2220 |
&gen_op_stmw_le_64_user, |
2221 |
&gen_op_stmw_64_kernel, |
2222 |
&gen_op_stmw_le_64_kernel, |
2223 |
}; |
2224 |
#endif
|
2225 |
#else
|
2226 |
#if defined(CONFIG_USER_ONLY)
|
2227 |
static GenOpFunc1 *gen_op_lmw[] = {
|
2228 |
&gen_op_lmw_raw, |
2229 |
&gen_op_lmw_le_raw, |
2230 |
}; |
2231 |
static GenOpFunc1 *gen_op_stmw[] = {
|
2232 |
&gen_op_stmw_raw, |
2233 |
&gen_op_stmw_le_raw, |
2234 |
}; |
2235 |
#else
|
2236 |
static GenOpFunc1 *gen_op_lmw[] = {
|
2237 |
&gen_op_lmw_user, |
2238 |
&gen_op_lmw_le_user, |
2239 |
&gen_op_lmw_kernel, |
2240 |
&gen_op_lmw_le_kernel, |
2241 |
}; |
2242 |
static GenOpFunc1 *gen_op_stmw[] = {
|
2243 |
&gen_op_stmw_user, |
2244 |
&gen_op_stmw_le_user, |
2245 |
&gen_op_stmw_kernel, |
2246 |
&gen_op_stmw_le_kernel, |
2247 |
}; |
2248 |
#endif
|
2249 |
#endif
|
2250 |
|
2251 |
/* lmw */
|
2252 |
GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) |
2253 |
{ |
2254 |
/* NIP cannot be restored if the memory exception comes from an helper */
|
2255 |
gen_update_nip(ctx, ctx->nip - 4);
|
2256 |
gen_addr_imm_index(ctx, 0);
|
2257 |
op_ldstm(lmw, rD(ctx->opcode)); |
2258 |
} |
2259 |
|
2260 |
/* stmw */
|
2261 |
GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER) |
2262 |
{ |
2263 |
/* NIP cannot be restored if the memory exception comes from an helper */
|
2264 |
gen_update_nip(ctx, ctx->nip - 4);
|
2265 |
gen_addr_imm_index(ctx, 0);
|
2266 |
op_ldstm(stmw, rS(ctx->opcode)); |
2267 |
} |
2268 |
|
2269 |
/*** Integer load and store strings ***/
|
2270 |
#define op_ldsts(name, start) (*gen_op_##name[ctx->mem_idx])(start) |
2271 |
#define op_ldstsx(name, rd, ra, rb) (*gen_op_##name[ctx->mem_idx])(rd, ra, rb) |
2272 |
#if defined(TARGET_PPC64)
|
2273 |
#if defined(CONFIG_USER_ONLY)
|
2274 |
static GenOpFunc1 *gen_op_lswi[] = {
|
2275 |
&gen_op_lswi_raw, |
2276 |
&gen_op_lswi_le_raw, |
2277 |
&gen_op_lswi_64_raw, |
2278 |
&gen_op_lswi_le_64_raw, |
2279 |
}; |
2280 |
static GenOpFunc3 *gen_op_lswx[] = {
|
2281 |
&gen_op_lswx_raw, |
2282 |
&gen_op_lswx_le_raw, |
2283 |
&gen_op_lswx_64_raw, |
2284 |
&gen_op_lswx_le_64_raw, |
2285 |
}; |
2286 |
static GenOpFunc1 *gen_op_stsw[] = {
|
2287 |
&gen_op_stsw_raw, |
2288 |
&gen_op_stsw_le_raw, |
2289 |
&gen_op_stsw_64_raw, |
2290 |
&gen_op_stsw_le_64_raw, |
2291 |
}; |
2292 |
#else
|
2293 |
static GenOpFunc1 *gen_op_lswi[] = {
|
2294 |
&gen_op_lswi_user, |
2295 |
&gen_op_lswi_le_user, |
2296 |
&gen_op_lswi_kernel, |
2297 |
&gen_op_lswi_le_kernel, |
2298 |
&gen_op_lswi_64_user, |
2299 |
&gen_op_lswi_le_64_user, |
2300 |
&gen_op_lswi_64_kernel, |
2301 |
&gen_op_lswi_le_64_kernel, |
2302 |
}; |
2303 |
static GenOpFunc3 *gen_op_lswx[] = {
|
2304 |
&gen_op_lswx_user, |
2305 |
&gen_op_lswx_le_user, |
2306 |
&gen_op_lswx_kernel, |
2307 |
&gen_op_lswx_le_kernel, |
2308 |
&gen_op_lswx_64_user, |
2309 |
&gen_op_lswx_le_64_user, |
2310 |
&gen_op_lswx_64_kernel, |
2311 |
&gen_op_lswx_le_64_kernel, |
2312 |
}; |
2313 |
static GenOpFunc1 *gen_op_stsw[] = {
|
2314 |
&gen_op_stsw_user, |
2315 |
&gen_op_stsw_le_user, |
2316 |
&gen_op_stsw_kernel, |
2317 |
&gen_op_stsw_le_kernel, |
2318 |
&gen_op_stsw_64_user, |
2319 |
&gen_op_stsw_le_64_user, |
2320 |
&gen_op_stsw_64_kernel, |
2321 |
&gen_op_stsw_le_64_kernel, |
2322 |
}; |
2323 |
#endif
|
2324 |
#else
|
2325 |
#if defined(CONFIG_USER_ONLY)
|
2326 |
static GenOpFunc1 *gen_op_lswi[] = {
|
2327 |
&gen_op_lswi_raw, |
2328 |
&gen_op_lswi_le_raw, |
2329 |
}; |
2330 |
static GenOpFunc3 *gen_op_lswx[] = {
|
2331 |
&gen_op_lswx_raw, |
2332 |
&gen_op_lswx_le_raw, |
2333 |
}; |
2334 |
static GenOpFunc1 *gen_op_stsw[] = {
|
2335 |
&gen_op_stsw_raw, |
2336 |
&gen_op_stsw_le_raw, |
2337 |
}; |
2338 |
#else
|
2339 |
static GenOpFunc1 *gen_op_lswi[] = {
|
2340 |
&gen_op_lswi_user, |
2341 |
&gen_op_lswi_le_user, |
2342 |
&gen_op_lswi_kernel, |
2343 |
&gen_op_lswi_le_kernel, |
2344 |
}; |
2345 |
static GenOpFunc3 *gen_op_lswx[] = {
|
2346 |
&gen_op_lswx_user, |
2347 |
&gen_op_lswx_le_user, |
2348 |
&gen_op_lswx_kernel, |
2349 |
&gen_op_lswx_le_kernel, |
2350 |
}; |
2351 |
static GenOpFunc1 *gen_op_stsw[] = {
|
2352 |
&gen_op_stsw_user, |
2353 |
&gen_op_stsw_le_user, |
2354 |
&gen_op_stsw_kernel, |
2355 |
&gen_op_stsw_le_kernel, |
2356 |
}; |
2357 |
#endif
|
2358 |
#endif
|
2359 |
|
2360 |
/* lswi */
|
2361 |
/* PowerPC32 specification says we must generate an exception if
|
2362 |
* rA is in the range of registers to be loaded.
|
2363 |
* In an other hand, IBM says this is valid, but rA won't be loaded.
|
2364 |
* For now, I'll follow the spec...
|
2365 |
*/
|
2366 |
GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_INTEGER) |
2367 |
{ |
2368 |
int nb = NB(ctx->opcode);
|
2369 |
int start = rD(ctx->opcode);
|
2370 |
int ra = rA(ctx->opcode);
|
2371 |
int nr;
|
2372 |
|
2373 |
if (nb == 0) |
2374 |
nb = 32;
|
2375 |
nr = nb / 4;
|
2376 |
if (unlikely(((start + nr) > 32 && |
2377 |
start <= ra && (start + nr - 32) > ra) ||
|
2378 |
((start + nr) <= 32 && start <= ra && (start + nr) > ra))) {
|
2379 |
GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM, |
2380 |
POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_LSWX); |
2381 |
return;
|
2382 |
} |
2383 |
/* NIP cannot be restored if the memory exception comes from an helper */
|
2384 |
gen_update_nip(ctx, ctx->nip - 4);
|
2385 |
gen_addr_register(ctx); |
2386 |
gen_op_set_T1(nb); |
2387 |
op_ldsts(lswi, start); |
2388 |
} |
2389 |
|
2390 |
/* lswx */
|
2391 |
GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_INTEGER) |
2392 |
{ |
2393 |
int ra = rA(ctx->opcode);
|
2394 |
int rb = rB(ctx->opcode);
|
2395 |
|
2396 |
/* NIP cannot be restored if the memory exception comes from an helper */
|
2397 |
gen_update_nip(ctx, ctx->nip - 4);
|
2398 |
gen_addr_reg_index(ctx); |
2399 |
if (ra == 0) { |
2400 |
ra = rb; |
2401 |
} |
2402 |
gen_op_load_xer_bc(); |
2403 |
op_ldstsx(lswx, rD(ctx->opcode), ra, rb); |
2404 |
} |
2405 |
|
2406 |
/* stswi */
|
2407 |
GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_INTEGER) |
2408 |
{ |
2409 |
int nb = NB(ctx->opcode);
|
2410 |
|
2411 |
/* NIP cannot be restored if the memory exception comes from an helper */
|
2412 |
gen_update_nip(ctx, ctx->nip - 4);
|
2413 |
gen_addr_register(ctx); |
2414 |
if (nb == 0) |
2415 |
nb = 32;
|
2416 |
gen_op_set_T1(nb); |
2417 |
op_ldsts(stsw, rS(ctx->opcode)); |
2418 |
} |
2419 |
|
2420 |
/* stswx */
|
2421 |
GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_INTEGER) |
2422 |
{ |
2423 |
/* NIP cannot be restored if the memory exception comes from an helper */
|
2424 |
gen_update_nip(ctx, ctx->nip - 4);
|
2425 |
gen_addr_reg_index(ctx); |
2426 |
gen_op_load_xer_bc(); |
2427 |
op_ldsts(stsw, rS(ctx->opcode)); |
2428 |
} |
2429 |
|
2430 |
/*** Memory synchronisation ***/
|
2431 |
/* eieio */
|
2432 |
GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FF0801, PPC_MEM_EIEIO) |
2433 |
{ |
2434 |
} |
2435 |
|
2436 |
/* isync */
|
2437 |
GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FF0801, PPC_MEM) |
2438 |
{ |
2439 |
GEN_STOP(ctx); |
2440 |
} |
2441 |
|
2442 |
#define op_lwarx() (*gen_op_lwarx[ctx->mem_idx])()
|
2443 |
#define op_stwcx() (*gen_op_stwcx[ctx->mem_idx])()
|
2444 |
#if defined(TARGET_PPC64)
|
2445 |
#if defined(CONFIG_USER_ONLY)
|
2446 |
static GenOpFunc *gen_op_lwarx[] = {
|
2447 |
&gen_op_lwarx_raw, |
2448 |
&gen_op_lwarx_le_raw, |
2449 |
&gen_op_lwarx_64_raw, |
2450 |
&gen_op_lwarx_le_64_raw, |
2451 |
}; |
2452 |
static GenOpFunc *gen_op_stwcx[] = {
|
2453 |
&gen_op_stwcx_raw, |
2454 |
&gen_op_stwcx_le_raw, |
2455 |
&gen_op_stwcx_64_raw, |
2456 |
&gen_op_stwcx_le_64_raw, |
2457 |
}; |
2458 |
#else
|
2459 |
static GenOpFunc *gen_op_lwarx[] = {
|
2460 |
&gen_op_lwarx_user, |
2461 |
&gen_op_lwarx_le_user, |
2462 |
&gen_op_lwarx_kernel, |
2463 |
&gen_op_lwarx_le_kernel, |
2464 |
&gen_op_lwarx_64_user, |
2465 |
&gen_op_lwarx_le_64_user, |
2466 |
&gen_op_lwarx_64_kernel, |
2467 |
&gen_op_lwarx_le_64_kernel, |
2468 |
}; |
2469 |
static GenOpFunc *gen_op_stwcx[] = {
|
2470 |
&gen_op_stwcx_user, |
2471 |
&gen_op_stwcx_le_user, |
2472 |
&gen_op_stwcx_kernel, |
2473 |
&gen_op_stwcx_le_kernel, |
2474 |
&gen_op_stwcx_64_user, |
2475 |
&gen_op_stwcx_le_64_user, |
2476 |
&gen_op_stwcx_64_kernel, |
2477 |
&gen_op_stwcx_le_64_kernel, |
2478 |
}; |
2479 |
#endif
|
2480 |
#else
|
2481 |
#if defined(CONFIG_USER_ONLY)
|
2482 |
static GenOpFunc *gen_op_lwarx[] = {
|
2483 |
&gen_op_lwarx_raw, |
2484 |
&gen_op_lwarx_le_raw, |
2485 |
}; |
2486 |
static GenOpFunc *gen_op_stwcx[] = {
|
2487 |
&gen_op_stwcx_raw, |
2488 |
&gen_op_stwcx_le_raw, |
2489 |
}; |
2490 |
#else
|
2491 |
static GenOpFunc *gen_op_lwarx[] = {
|
2492 |
&gen_op_lwarx_user, |
2493 |
&gen_op_lwarx_le_user, |
2494 |
&gen_op_lwarx_kernel, |
2495 |
&gen_op_lwarx_le_kernel, |
2496 |
}; |
2497 |
static GenOpFunc *gen_op_stwcx[] = {
|
2498 |
&gen_op_stwcx_user, |
2499 |
&gen_op_stwcx_le_user, |
2500 |
&gen_op_stwcx_kernel, |
2501 |
&gen_op_stwcx_le_kernel, |
2502 |
}; |
2503 |
#endif
|
2504 |
#endif
|
2505 |
|
2506 |
/* lwarx */
|
2507 |
GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000001, PPC_RES) |
2508 |
{ |
2509 |
gen_addr_reg_index(ctx); |
2510 |
op_lwarx(); |
2511 |
gen_op_store_T1_gpr(rD(ctx->opcode)); |
2512 |
} |
2513 |
|
2514 |
/* stwcx. */
|
2515 |
GEN_HANDLER(stwcx_, 0x1F, 0x16, 0x04, 0x00000000, PPC_RES) |
2516 |
{ |
2517 |
gen_addr_reg_index(ctx); |
2518 |
gen_op_load_gpr_T1(rS(ctx->opcode)); |
2519 |
op_stwcx(); |
2520 |
} |
2521 |
|
2522 |
#if defined(TARGET_PPC64)
|
2523 |
#define op_ldarx() (*gen_op_ldarx[ctx->mem_idx])()
|
2524 |
#define op_stdcx() (*gen_op_stdcx[ctx->mem_idx])()
|
2525 |
#if defined(CONFIG_USER_ONLY)
|
2526 |
static GenOpFunc *gen_op_ldarx[] = {
|
2527 |
&gen_op_ldarx_raw, |
2528 |
&gen_op_ldarx_le_raw, |
2529 |
&gen_op_ldarx_64_raw, |
2530 |
&gen_op_ldarx_le_64_raw, |
2531 |
}; |
2532 |
static GenOpFunc *gen_op_stdcx[] = {
|
2533 |
&gen_op_stdcx_raw, |
2534 |
&gen_op_stdcx_le_raw, |
2535 |
&gen_op_stdcx_64_raw, |
2536 |
&gen_op_stdcx_le_64_raw, |
2537 |
}; |
2538 |
#else
|
2539 |
static GenOpFunc *gen_op_ldarx[] = {
|
2540 |
&gen_op_ldarx_user, |
2541 |
&gen_op_ldarx_le_user, |
2542 |
&gen_op_ldarx_kernel, |
2543 |
&gen_op_ldarx_le_kernel, |
2544 |
&gen_op_ldarx_64_user, |
2545 |
&gen_op_ldarx_le_64_user, |
2546 |
&gen_op_ldarx_64_kernel, |
2547 |
&gen_op_ldarx_le_64_kernel, |
2548 |
}; |
2549 |
static GenOpFunc *gen_op_stdcx[] = {
|
2550 |
&gen_op_stdcx_user, |
2551 |
&gen_op_stdcx_le_user, |
2552 |
&gen_op_stdcx_kernel, |
2553 |
&gen_op_stdcx_le_kernel, |
2554 |
&gen_op_stdcx_64_user, |
2555 |
&gen_op_stdcx_le_64_user, |
2556 |
&gen_op_stdcx_64_kernel, |
2557 |
&gen_op_stdcx_le_64_kernel, |
2558 |
}; |
2559 |
#endif
|
2560 |
|
2561 |
/* ldarx */
|
2562 |
GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000001, PPC_64B) |
2563 |
{ |
2564 |
gen_addr_reg_index(ctx); |
2565 |
op_ldarx(); |
2566 |
gen_op_store_T1_gpr(rD(ctx->opcode)); |
2567 |
} |
2568 |
|
2569 |
/* stdcx. */
|
2570 |
GEN_HANDLER(stdcx_, 0x1F, 0x16, 0x06, 0x00000000, PPC_64B) |
2571 |
{ |
2572 |
gen_addr_reg_index(ctx); |
2573 |
gen_op_load_gpr_T1(rS(ctx->opcode)); |
2574 |
op_stdcx(); |
2575 |
} |
2576 |
#endif /* defined(TARGET_PPC64) */ |
2577 |
|
2578 |
/* sync */
|
2579 |
GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x03CF0801, PPC_MEM_SYNC) |
2580 |
{ |
2581 |
} |
2582 |
|
2583 |
/*** Floating-point load ***/
|
2584 |
#define GEN_LDF(width, opc, type) \
|
2585 |
GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \ |
2586 |
{ \ |
2587 |
if (unlikely(!ctx->fpu_enabled)) { \
|
2588 |
GEN_EXCP_NO_FP(ctx); \ |
2589 |
return; \
|
2590 |
} \ |
2591 |
gen_addr_imm_index(ctx, 0); \
|
2592 |
op_ldst(l##width); \ |
2593 |
gen_op_store_FT0_fpr(rD(ctx->opcode)); \ |
2594 |
} |
2595 |
|
2596 |
#define GEN_LDUF(width, opc, type) \
|
2597 |
GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \ |
2598 |
{ \ |
2599 |
if (unlikely(!ctx->fpu_enabled)) { \
|
2600 |
GEN_EXCP_NO_FP(ctx); \ |
2601 |
return; \
|
2602 |
} \ |
2603 |
if (unlikely(rA(ctx->opcode) == 0)) { \ |
2604 |
GEN_EXCP_INVAL(ctx); \ |
2605 |
return; \
|
2606 |
} \ |
2607 |
gen_addr_imm_index(ctx, 0); \
|
2608 |
op_ldst(l##width); \ |
2609 |
gen_op_store_FT0_fpr(rD(ctx->opcode)); \ |
2610 |
gen_op_store_T0_gpr(rA(ctx->opcode)); \ |
2611 |
} |
2612 |
|
2613 |
#define GEN_LDUXF(width, opc, type) \
|
2614 |
GEN_HANDLER(l##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \ |
2615 |
{ \ |
2616 |
if (unlikely(!ctx->fpu_enabled)) { \
|
2617 |
GEN_EXCP_NO_FP(ctx); \ |
2618 |
return; \
|
2619 |
} \ |
2620 |
if (unlikely(rA(ctx->opcode) == 0)) { \ |
2621 |
GEN_EXCP_INVAL(ctx); \ |
2622 |
return; \
|
2623 |
} \ |
2624 |
gen_addr_reg_index(ctx); \ |
2625 |
op_ldst(l##width); \ |
2626 |
gen_op_store_FT0_fpr(rD(ctx->opcode)); \ |
2627 |
gen_op_store_T0_gpr(rA(ctx->opcode)); \ |
2628 |
} |
2629 |
|
2630 |
#define GEN_LDXF(width, opc2, opc3, type) \
|
2631 |
GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \ |
2632 |
{ \ |
2633 |
if (unlikely(!ctx->fpu_enabled)) { \
|
2634 |
GEN_EXCP_NO_FP(ctx); \ |
2635 |
return; \
|
2636 |
} \ |
2637 |
gen_addr_reg_index(ctx); \ |
2638 |
op_ldst(l##width); \ |
2639 |
gen_op_store_FT0_fpr(rD(ctx->opcode)); \ |
2640 |
} |
2641 |
|
2642 |
#define GEN_LDFS(width, op, type) \
|
2643 |
OP_LD_TABLE(width); \ |
2644 |
GEN_LDF(width, op | 0x20, type); \
|
2645 |
GEN_LDUF(width, op | 0x21, type); \
|
2646 |
GEN_LDUXF(width, op | 0x01, type); \
|
2647 |
GEN_LDXF(width, 0x17, op | 0x00, type) |
2648 |
|
2649 |
/* lfd lfdu lfdux lfdx */
|
2650 |
GEN_LDFS(fd, 0x12, PPC_FLOAT);
|
2651 |
/* lfs lfsu lfsux lfsx */
|
2652 |
GEN_LDFS(fs, 0x10, PPC_FLOAT);
|
2653 |
|
2654 |
/*** Floating-point store ***/
|
2655 |
#define GEN_STF(width, opc, type) \
|
2656 |
GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \ |
2657 |
{ \ |
2658 |
if (unlikely(!ctx->fpu_enabled)) { \
|
2659 |
GEN_EXCP_NO_FP(ctx); \ |
2660 |
return; \
|
2661 |
} \ |
2662 |
gen_addr_imm_index(ctx, 0); \
|
2663 |
gen_op_load_fpr_FT0(rS(ctx->opcode)); \ |
2664 |
op_ldst(st##width); \ |
2665 |
} |
2666 |
|
2667 |
#define GEN_STUF(width, opc, type) \
|
2668 |
GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \ |
2669 |
{ \ |
2670 |
if (unlikely(!ctx->fpu_enabled)) { \
|
2671 |
GEN_EXCP_NO_FP(ctx); \ |
2672 |
return; \
|
2673 |
} \ |
2674 |
if (unlikely(rA(ctx->opcode) == 0)) { \ |
2675 |
GEN_EXCP_INVAL(ctx); \ |
2676 |
return; \
|
2677 |
} \ |
2678 |
gen_addr_imm_index(ctx, 0); \
|
2679 |
gen_op_load_fpr_FT0(rS(ctx->opcode)); \ |
2680 |
op_ldst(st##width); \ |
2681 |
gen_op_store_T0_gpr(rA(ctx->opcode)); \ |
2682 |
} |
2683 |
|
2684 |
#define GEN_STUXF(width, opc, type) \
|
2685 |
GEN_HANDLER(st##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \ |
2686 |
{ \ |
2687 |
if (unlikely(!ctx->fpu_enabled)) { \
|
2688 |
GEN_EXCP_NO_FP(ctx); \ |
2689 |
return; \
|
2690 |
} \ |
2691 |
if (unlikely(rA(ctx->opcode) == 0)) { \ |
2692 |
GEN_EXCP_INVAL(ctx); \ |
2693 |
return; \
|
2694 |
} \ |
2695 |
gen_addr_reg_index(ctx); \ |
2696 |
gen_op_load_fpr_FT0(rS(ctx->opcode)); \ |
2697 |
op_ldst(st##width); \ |
2698 |
gen_op_store_T0_gpr(rA(ctx->opcode)); \ |
2699 |
} |
2700 |
|
2701 |
#define GEN_STXF(width, opc2, opc3, type) \
|
2702 |
GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \ |
2703 |
{ \ |
2704 |
if (unlikely(!ctx->fpu_enabled)) { \
|
2705 |
GEN_EXCP_NO_FP(ctx); \ |
2706 |
return; \
|
2707 |
} \ |
2708 |
gen_addr_reg_index(ctx); \ |
2709 |
gen_op_load_fpr_FT0(rS(ctx->opcode)); \ |
2710 |
op_ldst(st##width); \ |
2711 |
} |
2712 |
|
2713 |
#define GEN_STFS(width, op, type) \
|
2714 |
OP_ST_TABLE(width); \ |
2715 |
GEN_STF(width, op | 0x20, type); \
|
2716 |
GEN_STUF(width, op | 0x21, type); \
|
2717 |
GEN_STUXF(width, op | 0x01, type); \
|
2718 |
GEN_STXF(width, 0x17, op | 0x00, type) |
2719 |
|
2720 |
/* stfd stfdu stfdux stfdx */
|
2721 |
GEN_STFS(fd, 0x16, PPC_FLOAT);
|
2722 |
/* stfs stfsu stfsux stfsx */
|
2723 |
GEN_STFS(fs, 0x14, PPC_FLOAT);
|
2724 |
|
2725 |
/* Optional: */
|
2726 |
/* stfiwx */
|
2727 |
OP_ST_TABLE(fiwx); |
2728 |
GEN_STXF(fiwx, 0x17, 0x1E, PPC_FLOAT_STFIWX); |
2729 |
|
2730 |
/*** Branch ***/
|
2731 |
static inline void gen_goto_tb (DisasContext *ctx, int n, target_ulong dest) |
2732 |
{ |
2733 |
TranslationBlock *tb; |
2734 |
tb = ctx->tb; |
2735 |
if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
|
2736 |
if (n == 0) |
2737 |
gen_op_goto_tb0(TBPARAM(tb)); |
2738 |
else
|
2739 |
gen_op_goto_tb1(TBPARAM(tb)); |
2740 |
gen_set_T1(dest); |
2741 |
#if defined(TARGET_PPC64)
|
2742 |
if (ctx->sf_mode)
|
2743 |
gen_op_b_T1_64(); |
2744 |
else
|
2745 |
#endif
|
2746 |
gen_op_b_T1(); |
2747 |
gen_op_set_T0((long)tb + n);
|
2748 |
if (ctx->singlestep_enabled)
|
2749 |
gen_op_debug(); |
2750 |
gen_op_exit_tb(); |
2751 |
} else {
|
2752 |
gen_set_T1(dest); |
2753 |
#if defined(TARGET_PPC64)
|
2754 |
if (ctx->sf_mode)
|
2755 |
gen_op_b_T1_64(); |
2756 |
else
|
2757 |
#endif
|
2758 |
gen_op_b_T1(); |
2759 |
gen_op_reset_T0(); |
2760 |
if (ctx->singlestep_enabled)
|
2761 |
gen_op_debug(); |
2762 |
gen_op_exit_tb(); |
2763 |
} |
2764 |
} |
2765 |
|
2766 |
static inline void gen_setlr (DisasContext *ctx, target_ulong nip) |
2767 |
{ |
2768 |
#if defined(TARGET_PPC64)
|
2769 |
if (ctx->sf_mode != 0 && (nip >> 32)) |
2770 |
gen_op_setlr_64(ctx->nip >> 32, ctx->nip);
|
2771 |
else
|
2772 |
#endif
|
2773 |
gen_op_setlr(ctx->nip); |
2774 |
} |
2775 |
|
2776 |
/* b ba bl bla */
|
2777 |
GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW) |
2778 |
{ |
2779 |
target_ulong li, target; |
2780 |
|
2781 |
/* sign extend LI */
|
2782 |
#if defined(TARGET_PPC64)
|
2783 |
if (ctx->sf_mode)
|
2784 |
li = ((int64_t)LI(ctx->opcode) << 38) >> 38; |
2785 |
else
|
2786 |
#endif
|
2787 |
li = ((int32_t)LI(ctx->opcode) << 6) >> 6; |
2788 |
if (likely(AA(ctx->opcode) == 0)) |
2789 |
target = ctx->nip + li - 4;
|
2790 |
else
|
2791 |
target = li; |
2792 |
#if defined(TARGET_PPC64)
|
2793 |
if (!ctx->sf_mode)
|
2794 |
target = (uint32_t)target; |
2795 |
#endif
|
2796 |
if (LK(ctx->opcode))
|
2797 |
gen_setlr(ctx, ctx->nip); |
2798 |
gen_goto_tb(ctx, 0, target);
|
2799 |
ctx->exception = POWERPC_EXCP_BRANCH; |
2800 |
} |
2801 |
|
2802 |
#define BCOND_IM 0 |
2803 |
#define BCOND_LR 1 |
2804 |
#define BCOND_CTR 2 |
2805 |
|
2806 |
static inline void gen_bcond (DisasContext *ctx, int type) |
2807 |
{ |
2808 |
target_ulong target = 0;
|
2809 |
target_ulong li; |
2810 |
uint32_t bo = BO(ctx->opcode); |
2811 |
uint32_t bi = BI(ctx->opcode); |
2812 |
uint32_t mask; |
2813 |
|
2814 |
if ((bo & 0x4) == 0) |
2815 |
gen_op_dec_ctr(); |
2816 |
switch(type) {
|
2817 |
case BCOND_IM:
|
2818 |
li = (target_long)((int16_t)(BD(ctx->opcode))); |
2819 |
if (likely(AA(ctx->opcode) == 0)) { |
2820 |
target = ctx->nip + li - 4;
|
2821 |
} else {
|
2822 |
target = li; |
2823 |
} |
2824 |
#if defined(TARGET_PPC64)
|
2825 |
if (!ctx->sf_mode)
|
2826 |
target = (uint32_t)target; |
2827 |
#endif
|
2828 |
break;
|
2829 |
case BCOND_CTR:
|
2830 |
gen_op_movl_T1_ctr(); |
2831 |
break;
|
2832 |
default:
|
2833 |
case BCOND_LR:
|
2834 |
gen_op_movl_T1_lr(); |
2835 |
break;
|
2836 |
} |
2837 |
if (LK(ctx->opcode))
|
2838 |
gen_setlr(ctx, ctx->nip); |
2839 |
if (bo & 0x10) { |
2840 |
/* No CR condition */
|
2841 |
switch (bo & 0x6) { |
2842 |
case 0: |
2843 |
#if defined(TARGET_PPC64)
|
2844 |
if (ctx->sf_mode)
|
2845 |
gen_op_test_ctr_64(); |
2846 |
else
|
2847 |
#endif
|
2848 |
gen_op_test_ctr(); |
2849 |
break;
|
2850 |
case 2: |
2851 |
#if defined(TARGET_PPC64)
|
2852 |
if (ctx->sf_mode)
|
2853 |
gen_op_test_ctrz_64(); |
2854 |
else
|
2855 |
#endif
|
2856 |
gen_op_test_ctrz(); |
2857 |
break;
|
2858 |
default:
|
2859 |
case 4: |
2860 |
case 6: |
2861 |
if (type == BCOND_IM) {
|
2862 |
gen_goto_tb(ctx, 0, target);
|
2863 |
} else {
|
2864 |
#if defined(TARGET_PPC64)
|
2865 |
if (ctx->sf_mode)
|
2866 |
gen_op_b_T1_64(); |
2867 |
else
|
2868 |
#endif
|
2869 |
gen_op_b_T1(); |
2870 |
gen_op_reset_T0(); |
2871 |
} |
2872 |
goto no_test;
|
2873 |
} |
2874 |
} else {
|
2875 |
mask = 1 << (3 - (bi & 0x03)); |
2876 |
gen_op_load_crf_T0(bi >> 2);
|
2877 |
if (bo & 0x8) { |
2878 |
switch (bo & 0x6) { |
2879 |
case 0: |
2880 |
#if defined(TARGET_PPC64)
|
2881 |
if (ctx->sf_mode)
|
2882 |
gen_op_test_ctr_true_64(mask); |
2883 |
else
|
2884 |
#endif
|
2885 |
gen_op_test_ctr_true(mask); |
2886 |
break;
|
2887 |
case 2: |
2888 |
#if defined(TARGET_PPC64)
|
2889 |
if (ctx->sf_mode)
|
2890 |
gen_op_test_ctrz_true_64(mask); |
2891 |
else
|
2892 |
#endif
|
2893 |
gen_op_test_ctrz_true(mask); |
2894 |
break;
|
2895 |
default:
|
2896 |
case 4: |
2897 |
case 6: |
2898 |
gen_op_test_true(mask); |
2899 |
break;
|
2900 |
} |
2901 |
} else {
|
2902 |
switch (bo & 0x6) { |
2903 |
case 0: |
2904 |
#if defined(TARGET_PPC64)
|
2905 |
if (ctx->sf_mode)
|
2906 |
gen_op_test_ctr_false_64(mask); |
2907 |
else
|
2908 |
#endif
|
2909 |
gen_op_test_ctr_false(mask); |
2910 |
break;
|
2911 |
case 2: |
2912 |
#if defined(TARGET_PPC64)
|
2913 |
if (ctx->sf_mode)
|
2914 |
gen_op_test_ctrz_false_64(mask); |
2915 |
else
|
2916 |
#endif
|
2917 |
gen_op_test_ctrz_false(mask); |
2918 |
break;
|
2919 |
default:
|
2920 |
case 4: |
2921 |
case 6: |
2922 |
gen_op_test_false(mask); |
2923 |
break;
|
2924 |
} |
2925 |
} |
2926 |
} |
2927 |
if (type == BCOND_IM) {
|
2928 |
int l1 = gen_new_label();
|
2929 |
gen_op_jz_T0(l1); |
2930 |
gen_goto_tb(ctx, 0, target);
|
2931 |
gen_set_label(l1); |
2932 |
gen_goto_tb(ctx, 1, ctx->nip);
|
2933 |
} else {
|
2934 |
#if defined(TARGET_PPC64)
|
2935 |
if (ctx->sf_mode)
|
2936 |
gen_op_btest_T1_64(ctx->nip >> 32, ctx->nip);
|
2937 |
else
|
2938 |
#endif
|
2939 |
gen_op_btest_T1(ctx->nip); |
2940 |
gen_op_reset_T0(); |
2941 |
no_test:
|
2942 |
if (ctx->singlestep_enabled)
|
2943 |
gen_op_debug(); |
2944 |
gen_op_exit_tb(); |
2945 |
} |
2946 |
ctx->exception = POWERPC_EXCP_BRANCH; |
2947 |
} |
2948 |
|
2949 |
GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW) |
2950 |
{ |
2951 |
gen_bcond(ctx, BCOND_IM); |
2952 |
} |
2953 |
|
2954 |
GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW) |
2955 |
{ |
2956 |
gen_bcond(ctx, BCOND_CTR); |
2957 |
} |
2958 |
|
2959 |
GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW) |
2960 |
{ |
2961 |
gen_bcond(ctx, BCOND_LR); |
2962 |
} |
2963 |
|
2964 |
/*** Condition register logical ***/
|
2965 |
#define GEN_CRLOGIC(op, opc) \
|
2966 |
GEN_HANDLER(cr##op, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) \ |
2967 |
{ \ |
2968 |
gen_op_load_crf_T0(crbA(ctx->opcode) >> 2); \
|
2969 |
gen_op_getbit_T0(3 - (crbA(ctx->opcode) & 0x03)); \ |
2970 |
gen_op_load_crf_T1(crbB(ctx->opcode) >> 2); \
|
2971 |
gen_op_getbit_T1(3 - (crbB(ctx->opcode) & 0x03)); \ |
2972 |
gen_op_##op(); \ |
2973 |
gen_op_load_crf_T1(crbD(ctx->opcode) >> 2); \
|
2974 |
gen_op_setcrfbit(~(1 << (3 - (crbD(ctx->opcode) & 0x03))), \ |
2975 |
3 - (crbD(ctx->opcode) & 0x03)); \ |
2976 |
gen_op_store_T1_crf(crbD(ctx->opcode) >> 2); \
|
2977 |
} |
2978 |
|
2979 |
/* crand */
|
2980 |
GEN_CRLOGIC(and, 0x08);
|
2981 |
/* crandc */
|
2982 |
GEN_CRLOGIC(andc, 0x04);
|
2983 |
/* creqv */
|
2984 |
GEN_CRLOGIC(eqv, 0x09);
|
2985 |
/* crnand */
|
2986 |
GEN_CRLOGIC(nand, 0x07);
|
2987 |
/* crnor */
|
2988 |
GEN_CRLOGIC(nor, 0x01);
|
2989 |
/* cror */
|
2990 |
GEN_CRLOGIC(or, 0x0E);
|
2991 |
/* crorc */
|
2992 |
GEN_CRLOGIC(orc, 0x0D);
|
2993 |
/* crxor */
|
2994 |
GEN_CRLOGIC(xor, 0x06);
|
2995 |
/* mcrf */
|
2996 |
GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER) |
2997 |
{ |
2998 |
gen_op_load_crf_T0(crfS(ctx->opcode)); |
2999 |
gen_op_store_T0_crf(crfD(ctx->opcode)); |
3000 |
} |
3001 |
|
3002 |
/*** System linkage ***/
|
3003 |
/* rfi (supervisor only) */
|
3004 |
GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW) |
3005 |
{ |
3006 |
#if defined(CONFIG_USER_ONLY)
|
3007 |
GEN_EXCP_PRIVOPC(ctx); |
3008 |
#else
|
3009 |
/* Restore CPU state */
|
3010 |
if (unlikely(!ctx->supervisor)) {
|
3011 |
GEN_EXCP_PRIVOPC(ctx); |
3012 |
return;
|
3013 |
} |
3014 |
gen_op_rfi(); |
3015 |
GEN_SYNC(ctx); |
3016 |
#endif
|
3017 |
} |
3018 |
|
3019 |
#if defined(TARGET_PPC64)
|
3020 |
GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B) |
3021 |
{ |
3022 |
#if defined(CONFIG_USER_ONLY)
|
3023 |
GEN_EXCP_PRIVOPC(ctx); |
3024 |
#else
|
3025 |
/* Restore CPU state */
|
3026 |
if (unlikely(!ctx->supervisor)) {
|
3027 |
GEN_EXCP_PRIVOPC(ctx); |
3028 |
return;
|
3029 |
} |
3030 |
gen_op_rfid(); |
3031 |
GEN_SYNC(ctx); |
3032 |
#endif
|
3033 |
} |
3034 |
#endif
|
3035 |
|
3036 |
/* sc */
|
3037 |
GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW) |
3038 |
{ |
3039 |
uint32_t lev; |
3040 |
|
3041 |
lev = (ctx->opcode >> 5) & 0x7F; |
3042 |
#if defined(CONFIG_USER_ONLY)
|
3043 |
GEN_EXCP(ctx, POWERPC_EXCP_SYSCALL_USER, lev); |
3044 |
#else
|
3045 |
GEN_EXCP(ctx, POWERPC_EXCP_SYSCALL, lev); |
3046 |
#endif
|
3047 |
} |
3048 |
|
3049 |
/*** Trap ***/
|
3050 |
/* tw */
|
3051 |
GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW) |
3052 |
{ |
3053 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
3054 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
3055 |
/* Update the nip since this might generate a trap exception */
|
3056 |
gen_update_nip(ctx, ctx->nip); |
3057 |
gen_op_tw(TO(ctx->opcode)); |
3058 |
} |
3059 |
|
3060 |
/* twi */
|
3061 |
GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW) |
3062 |
{ |
3063 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
3064 |
gen_set_T1(SIMM(ctx->opcode)); |
3065 |
/* Update the nip since this might generate a trap exception */
|
3066 |
gen_update_nip(ctx, ctx->nip); |
3067 |
gen_op_tw(TO(ctx->opcode)); |
3068 |
} |
3069 |
|
3070 |
#if defined(TARGET_PPC64)
|
3071 |
/* td */
|
3072 |
GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B) |
3073 |
{ |
3074 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
3075 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
3076 |
/* Update the nip since this might generate a trap exception */
|
3077 |
gen_update_nip(ctx, ctx->nip); |
3078 |
gen_op_td(TO(ctx->opcode)); |
3079 |
} |
3080 |
|
3081 |
/* tdi */
|
3082 |
GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B) |
3083 |
{ |
3084 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
3085 |
gen_set_T1(SIMM(ctx->opcode)); |
3086 |
/* Update the nip since this might generate a trap exception */
|
3087 |
gen_update_nip(ctx, ctx->nip); |
3088 |
gen_op_td(TO(ctx->opcode)); |
3089 |
} |
3090 |
#endif
|
3091 |
|
3092 |
/*** Processor control ***/
|
3093 |
/* mcrxr */
|
3094 |
GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC) |
3095 |
{ |
3096 |
gen_op_load_xer_cr(); |
3097 |
gen_op_store_T0_crf(crfD(ctx->opcode)); |
3098 |
gen_op_clear_xer_ov(); |
3099 |
gen_op_clear_xer_ca(); |
3100 |
} |
3101 |
|
3102 |
/* mfcr */
|
3103 |
GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC) |
3104 |
{ |
3105 |
uint32_t crm, crn; |
3106 |
|
3107 |
if (likely(ctx->opcode & 0x00100000)) { |
3108 |
crm = CRM(ctx->opcode); |
3109 |
if (likely((crm ^ (crm - 1)) == 0)) { |
3110 |
crn = ffs(crm); |
3111 |
gen_op_load_cro(7 - crn);
|
3112 |
} |
3113 |
} else {
|
3114 |
gen_op_load_cr(); |
3115 |
} |
3116 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
3117 |
} |
3118 |
|
3119 |
/* mfmsr */
|
3120 |
GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC) |
3121 |
{ |
3122 |
#if defined(CONFIG_USER_ONLY)
|
3123 |
GEN_EXCP_PRIVREG(ctx); |
3124 |
#else
|
3125 |
if (unlikely(!ctx->supervisor)) {
|
3126 |
GEN_EXCP_PRIVREG(ctx); |
3127 |
return;
|
3128 |
} |
3129 |
gen_op_load_msr(); |
3130 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
3131 |
#endif
|
3132 |
} |
3133 |
|
3134 |
#if 0
|
3135 |
#define SPR_NOACCESS ((void *)(-1))
|
3136 |
#else
|
3137 |
static void spr_noaccess (void *opaque, int sprn) |
3138 |
{ |
3139 |
sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5); |
3140 |
printf("ERROR: try to access SPR %d !\n", sprn);
|
3141 |
} |
3142 |
#define SPR_NOACCESS (&spr_noaccess)
|
3143 |
#endif
|
3144 |
|
3145 |
/* mfspr */
|
3146 |
static inline void gen_op_mfspr (DisasContext *ctx) |
3147 |
{ |
3148 |
void (*read_cb)(void *opaque, int sprn); |
3149 |
uint32_t sprn = SPR(ctx->opcode); |
3150 |
|
3151 |
#if !defined(CONFIG_USER_ONLY)
|
3152 |
if (ctx->supervisor)
|
3153 |
read_cb = ctx->spr_cb[sprn].oea_read; |
3154 |
else
|
3155 |
#endif
|
3156 |
read_cb = ctx->spr_cb[sprn].uea_read; |
3157 |
if (likely(read_cb != NULL)) { |
3158 |
if (likely(read_cb != SPR_NOACCESS)) {
|
3159 |
(*read_cb)(ctx, sprn); |
3160 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
3161 |
} else {
|
3162 |
/* Privilege exception */
|
3163 |
if (loglevel != 0) { |
3164 |
fprintf(logfile, "Trying to read privileged spr %d %03x\n",
|
3165 |
sprn, sprn); |
3166 |
} |
3167 |
printf("Trying to read privileged spr %d %03x\n", sprn, sprn);
|
3168 |
GEN_EXCP_PRIVREG(ctx); |
3169 |
} |
3170 |
} else {
|
3171 |
/* Not defined */
|
3172 |
if (loglevel != 0) { |
3173 |
fprintf(logfile, "Trying to read invalid spr %d %03x\n",
|
3174 |
sprn, sprn); |
3175 |
} |
3176 |
printf("Trying to read invalid spr %d %03x\n", sprn, sprn);
|
3177 |
GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM, |
3178 |
POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_SPR); |
3179 |
} |
3180 |
} |
3181 |
|
3182 |
GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC) |
3183 |
{ |
3184 |
gen_op_mfspr(ctx); |
3185 |
} |
3186 |
|
3187 |
/* mftb */
|
3188 |
GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB) |
3189 |
{ |
3190 |
gen_op_mfspr(ctx); |
3191 |
} |
3192 |
|
3193 |
/* mtcrf */
|
3194 |
GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC) |
3195 |
{ |
3196 |
uint32_t crm, crn; |
3197 |
|
3198 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
3199 |
crm = CRM(ctx->opcode); |
3200 |
if (likely((ctx->opcode & 0x00100000) || (crm ^ (crm - 1)) == 0)) { |
3201 |
crn = ffs(crm); |
3202 |
gen_op_srli_T0(crn * 4);
|
3203 |
gen_op_andi_T0(0xF);
|
3204 |
gen_op_store_cro(7 - crn);
|
3205 |
} else {
|
3206 |
gen_op_store_cr(crm); |
3207 |
} |
3208 |
} |
3209 |
|
3210 |
/* mtmsr */
|
3211 |
#if defined(TARGET_PPC64)
|
3212 |
GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001FF801, PPC_64B) |
3213 |
{ |
3214 |
#if defined(CONFIG_USER_ONLY)
|
3215 |
GEN_EXCP_PRIVREG(ctx); |
3216 |
#else
|
3217 |
if (unlikely(!ctx->supervisor)) {
|
3218 |
GEN_EXCP_PRIVREG(ctx); |
3219 |
return;
|
3220 |
} |
3221 |
gen_update_nip(ctx, ctx->nip); |
3222 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
3223 |
gen_op_store_msr(); |
3224 |
/* Must stop the translation as machine state (may have) changed */
|
3225 |
/* Note that mtmsr is not always defined as context-synchronizing */
|
3226 |
GEN_STOP(ctx); |
3227 |
#endif
|
3228 |
} |
3229 |
#endif
|
3230 |
|
3231 |
GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC) |
3232 |
{ |
3233 |
#if defined(CONFIG_USER_ONLY)
|
3234 |
GEN_EXCP_PRIVREG(ctx); |
3235 |
#else
|
3236 |
if (unlikely(!ctx->supervisor)) {
|
3237 |
GEN_EXCP_PRIVREG(ctx); |
3238 |
return;
|
3239 |
} |
3240 |
gen_update_nip(ctx, ctx->nip); |
3241 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
3242 |
#if defined(TARGET_PPC64)
|
3243 |
if (!ctx->sf_mode)
|
3244 |
gen_op_store_msr_32(); |
3245 |
else
|
3246 |
#endif
|
3247 |
gen_op_store_msr(); |
3248 |
/* Must stop the translation as machine state (may have) changed */
|
3249 |
/* Note that mtmsrd is not always defined as context-synchronizing */
|
3250 |
GEN_STOP(ctx); |
3251 |
#endif
|
3252 |
} |
3253 |
|
3254 |
/* mtspr */
|
3255 |
GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC) |
3256 |
{ |
3257 |
void (*write_cb)(void *opaque, int sprn); |
3258 |
uint32_t sprn = SPR(ctx->opcode); |
3259 |
|
3260 |
#if !defined(CONFIG_USER_ONLY)
|
3261 |
if (ctx->supervisor)
|
3262 |
write_cb = ctx->spr_cb[sprn].oea_write; |
3263 |
else
|
3264 |
#endif
|
3265 |
write_cb = ctx->spr_cb[sprn].uea_write; |
3266 |
if (likely(write_cb != NULL)) { |
3267 |
if (likely(write_cb != SPR_NOACCESS)) {
|
3268 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
3269 |
(*write_cb)(ctx, sprn); |
3270 |
} else {
|
3271 |
/* Privilege exception */
|
3272 |
if (loglevel != 0) { |
3273 |
fprintf(logfile, "Trying to write privileged spr %d %03x\n",
|
3274 |
sprn, sprn); |
3275 |
} |
3276 |
printf("Trying to write privileged spr %d %03x\n", sprn, sprn);
|
3277 |
GEN_EXCP_PRIVREG(ctx); |
3278 |
} |
3279 |
} else {
|
3280 |
/* Not defined */
|
3281 |
if (loglevel != 0) { |
3282 |
fprintf(logfile, "Trying to write invalid spr %d %03x\n",
|
3283 |
sprn, sprn); |
3284 |
} |
3285 |
printf("Trying to write invalid spr %d %03x\n", sprn, sprn);
|
3286 |
GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM, |
3287 |
POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_SPR); |
3288 |
} |
3289 |
} |
3290 |
|
3291 |
/*** Cache management ***/
|
3292 |
/* For now, all those will be implemented as nop:
|
3293 |
* this is valid, regarding the PowerPC specs...
|
3294 |
* We just have to flush tb while invalidating instruction cache lines...
|
3295 |
*/
|
3296 |
/* dcbf */
|
3297 |
GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03E00001, PPC_CACHE) |
3298 |
{ |
3299 |
gen_addr_reg_index(ctx); |
3300 |
op_ldst(lbz); |
3301 |
} |
3302 |
|
3303 |
/* dcbi (Supervisor only) */
|
3304 |
GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE) |
3305 |
{ |
3306 |
#if defined(CONFIG_USER_ONLY)
|
3307 |
GEN_EXCP_PRIVOPC(ctx); |
3308 |
#else
|
3309 |
if (unlikely(!ctx->supervisor)) {
|
3310 |
GEN_EXCP_PRIVOPC(ctx); |
3311 |
return;
|
3312 |
} |
3313 |
gen_addr_reg_index(ctx); |
3314 |
/* XXX: specification says this should be treated as a store by the MMU */
|
3315 |
//op_ldst(lbz);
|
3316 |
op_ldst(stb); |
3317 |
#endif
|
3318 |
} |
3319 |
|
3320 |
/* dcdst */
|
3321 |
GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE) |
3322 |
{ |
3323 |
/* XXX: specification say this is treated as a load by the MMU */
|
3324 |
gen_addr_reg_index(ctx); |
3325 |
op_ldst(lbz); |
3326 |
} |
3327 |
|
3328 |
/* dcbt */
|
3329 |
GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x03E00001, PPC_CACHE) |
3330 |
{ |
3331 |
/* XXX: specification say this is treated as a load by the MMU
|
3332 |
* but does not generate any exception
|
3333 |
*/
|
3334 |
} |
3335 |
|
3336 |
/* dcbtst */
|
3337 |
GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x03E00001, PPC_CACHE) |
3338 |
{ |
3339 |
/* XXX: specification say this is treated as a load by the MMU
|
3340 |
* but does not generate any exception
|
3341 |
*/
|
3342 |
} |
3343 |
|
3344 |
/* dcbz */
|
3345 |
#define op_dcbz() (*gen_op_dcbz[ctx->mem_idx])()
|
3346 |
#if defined(TARGET_PPC64)
|
3347 |
#if defined(CONFIG_USER_ONLY)
|
3348 |
static GenOpFunc *gen_op_dcbz[] = {
|
3349 |
&gen_op_dcbz_raw, |
3350 |
&gen_op_dcbz_raw, |
3351 |
&gen_op_dcbz_64_raw, |
3352 |
&gen_op_dcbz_64_raw, |
3353 |
}; |
3354 |
#else
|
3355 |
static GenOpFunc *gen_op_dcbz[] = {
|
3356 |
&gen_op_dcbz_user, |
3357 |
&gen_op_dcbz_user, |
3358 |
&gen_op_dcbz_kernel, |
3359 |
&gen_op_dcbz_kernel, |
3360 |
&gen_op_dcbz_64_user, |
3361 |
&gen_op_dcbz_64_user, |
3362 |
&gen_op_dcbz_64_kernel, |
3363 |
&gen_op_dcbz_64_kernel, |
3364 |
}; |
3365 |
#endif
|
3366 |
#else
|
3367 |
#if defined(CONFIG_USER_ONLY)
|
3368 |
static GenOpFunc *gen_op_dcbz[] = {
|
3369 |
&gen_op_dcbz_raw, |
3370 |
&gen_op_dcbz_raw, |
3371 |
}; |
3372 |
#else
|
3373 |
static GenOpFunc *gen_op_dcbz[] = {
|
3374 |
&gen_op_dcbz_user, |
3375 |
&gen_op_dcbz_user, |
3376 |
&gen_op_dcbz_kernel, |
3377 |
&gen_op_dcbz_kernel, |
3378 |
}; |
3379 |
#endif
|
3380 |
#endif
|
3381 |
|
3382 |
GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE) |
3383 |
{ |
3384 |
gen_addr_reg_index(ctx); |
3385 |
op_dcbz(); |
3386 |
gen_op_check_reservation(); |
3387 |
} |
3388 |
|
3389 |
/* icbi */
|
3390 |
#define op_icbi() (*gen_op_icbi[ctx->mem_idx])()
|
3391 |
#if defined(TARGET_PPC64)
|
3392 |
#if defined(CONFIG_USER_ONLY)
|
3393 |
static GenOpFunc *gen_op_icbi[] = {
|
3394 |
&gen_op_icbi_raw, |
3395 |
&gen_op_icbi_raw, |
3396 |
&gen_op_icbi_64_raw, |
3397 |
&gen_op_icbi_64_raw, |
3398 |
}; |
3399 |
#else
|
3400 |
static GenOpFunc *gen_op_icbi[] = {
|
3401 |
&gen_op_icbi_user, |
3402 |
&gen_op_icbi_user, |
3403 |
&gen_op_icbi_kernel, |
3404 |
&gen_op_icbi_kernel, |
3405 |
&gen_op_icbi_64_user, |
3406 |
&gen_op_icbi_64_user, |
3407 |
&gen_op_icbi_64_kernel, |
3408 |
&gen_op_icbi_64_kernel, |
3409 |
}; |
3410 |
#endif
|
3411 |
#else
|
3412 |
#if defined(CONFIG_USER_ONLY)
|
3413 |
static GenOpFunc *gen_op_icbi[] = {
|
3414 |
&gen_op_icbi_raw, |
3415 |
&gen_op_icbi_raw, |
3416 |
}; |
3417 |
#else
|
3418 |
static GenOpFunc *gen_op_icbi[] = {
|
3419 |
&gen_op_icbi_user, |
3420 |
&gen_op_icbi_user, |
3421 |
&gen_op_icbi_kernel, |
3422 |
&gen_op_icbi_kernel, |
3423 |
}; |
3424 |
#endif
|
3425 |
#endif
|
3426 |
|
3427 |
GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE) |
3428 |
{ |
3429 |
gen_addr_reg_index(ctx); |
3430 |
op_icbi(); |
3431 |
} |
3432 |
|
3433 |
/* Optional: */
|
3434 |
/* dcba */
|
3435 |
GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA) |
3436 |
{ |
3437 |
} |
3438 |
|
3439 |
/*** Segment register manipulation ***/
|
3440 |
/* Supervisor only: */
|
3441 |
/* mfsr */
|
3442 |
GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT) |
3443 |
{ |
3444 |
#if defined(CONFIG_USER_ONLY)
|
3445 |
GEN_EXCP_PRIVREG(ctx); |
3446 |
#else
|
3447 |
if (unlikely(!ctx->supervisor)) {
|
3448 |
GEN_EXCP_PRIVREG(ctx); |
3449 |
return;
|
3450 |
} |
3451 |
gen_op_set_T1(SR(ctx->opcode)); |
3452 |
gen_op_load_sr(); |
3453 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
3454 |
#endif
|
3455 |
} |
3456 |
|
3457 |
/* mfsrin */
|
3458 |
GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT) |
3459 |
{ |
3460 |
#if defined(CONFIG_USER_ONLY)
|
3461 |
GEN_EXCP_PRIVREG(ctx); |
3462 |
#else
|
3463 |
if (unlikely(!ctx->supervisor)) {
|
3464 |
GEN_EXCP_PRIVREG(ctx); |
3465 |
return;
|
3466 |
} |
3467 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
3468 |
gen_op_srli_T1(28);
|
3469 |
gen_op_load_sr(); |
3470 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
3471 |
#endif
|
3472 |
} |
3473 |
|
3474 |
/* mtsr */
|
3475 |
GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT) |
3476 |
{ |
3477 |
#if defined(CONFIG_USER_ONLY)
|
3478 |
GEN_EXCP_PRIVREG(ctx); |
3479 |
#else
|
3480 |
if (unlikely(!ctx->supervisor)) {
|
3481 |
GEN_EXCP_PRIVREG(ctx); |
3482 |
return;
|
3483 |
} |
3484 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
3485 |
gen_op_set_T1(SR(ctx->opcode)); |
3486 |
gen_op_store_sr(); |
3487 |
#endif
|
3488 |
} |
3489 |
|
3490 |
/* mtsrin */
|
3491 |
GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT) |
3492 |
{ |
3493 |
#if defined(CONFIG_USER_ONLY)
|
3494 |
GEN_EXCP_PRIVREG(ctx); |
3495 |
#else
|
3496 |
if (unlikely(!ctx->supervisor)) {
|
3497 |
GEN_EXCP_PRIVREG(ctx); |
3498 |
return;
|
3499 |
} |
3500 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
3501 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
3502 |
gen_op_srli_T1(28);
|
3503 |
gen_op_store_sr(); |
3504 |
#endif
|
3505 |
} |
3506 |
|
3507 |
/*** Lookaside buffer management ***/
|
3508 |
/* Optional & supervisor only: */
|
3509 |
/* tlbia */
|
3510 |
GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA) |
3511 |
{ |
3512 |
#if defined(CONFIG_USER_ONLY)
|
3513 |
GEN_EXCP_PRIVOPC(ctx); |
3514 |
#else
|
3515 |
if (unlikely(!ctx->supervisor)) {
|
3516 |
if (loglevel != 0) |
3517 |
fprintf(logfile, "%s: ! supervisor\n", __func__);
|
3518 |
GEN_EXCP_PRIVOPC(ctx); |
3519 |
return;
|
3520 |
} |
3521 |
gen_op_tlbia(); |
3522 |
#endif
|
3523 |
} |
3524 |
|
3525 |
/* tlbie */
|
3526 |
GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE) |
3527 |
{ |
3528 |
#if defined(CONFIG_USER_ONLY)
|
3529 |
GEN_EXCP_PRIVOPC(ctx); |
3530 |
#else
|
3531 |
if (unlikely(!ctx->supervisor)) {
|
3532 |
GEN_EXCP_PRIVOPC(ctx); |
3533 |
return;
|
3534 |
} |
3535 |
gen_op_load_gpr_T0(rB(ctx->opcode)); |
3536 |
#if defined(TARGET_PPC64)
|
3537 |
if (ctx->sf_mode)
|
3538 |
gen_op_tlbie_64(); |
3539 |
else
|
3540 |
#endif
|
3541 |
gen_op_tlbie(); |
3542 |
#endif
|
3543 |
} |
3544 |
|
3545 |
/* tlbsync */
|
3546 |
GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC) |
3547 |
{ |
3548 |
#if defined(CONFIG_USER_ONLY)
|
3549 |
GEN_EXCP_PRIVOPC(ctx); |
3550 |
#else
|
3551 |
if (unlikely(!ctx->supervisor)) {
|
3552 |
GEN_EXCP_PRIVOPC(ctx); |
3553 |
return;
|
3554 |
} |
3555 |
/* This has no effect: it should ensure that all previous
|
3556 |
* tlbie have completed
|
3557 |
*/
|
3558 |
GEN_STOP(ctx); |
3559 |
#endif
|
3560 |
} |
3561 |
|
3562 |
#if defined(TARGET_PPC64)
|
3563 |
/* slbia */
|
3564 |
GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI) |
3565 |
{ |
3566 |
#if defined(CONFIG_USER_ONLY)
|
3567 |
GEN_EXCP_PRIVOPC(ctx); |
3568 |
#else
|
3569 |
if (unlikely(!ctx->supervisor)) {
|
3570 |
if (loglevel != 0) |
3571 |
fprintf(logfile, "%s: ! supervisor\n", __func__);
|
3572 |
GEN_EXCP_PRIVOPC(ctx); |
3573 |
return;
|
3574 |
} |
3575 |
gen_op_slbia(); |
3576 |
#endif
|
3577 |
} |
3578 |
|
3579 |
/* slbie */
|
3580 |
GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI) |
3581 |
{ |
3582 |
#if defined(CONFIG_USER_ONLY)
|
3583 |
GEN_EXCP_PRIVOPC(ctx); |
3584 |
#else
|
3585 |
if (unlikely(!ctx->supervisor)) {
|
3586 |
GEN_EXCP_PRIVOPC(ctx); |
3587 |
return;
|
3588 |
} |
3589 |
gen_op_load_gpr_T0(rB(ctx->opcode)); |
3590 |
gen_op_slbie(); |
3591 |
#endif
|
3592 |
} |
3593 |
#endif
|
3594 |
|
3595 |
/*** External control ***/
|
3596 |
/* Optional: */
|
3597 |
#define op_eciwx() (*gen_op_eciwx[ctx->mem_idx])()
|
3598 |
#define op_ecowx() (*gen_op_ecowx[ctx->mem_idx])()
|
3599 |
#if defined(TARGET_PPC64)
|
3600 |
#if defined(CONFIG_USER_ONLY)
|
3601 |
static GenOpFunc *gen_op_eciwx[] = {
|
3602 |
&gen_op_eciwx_raw, |
3603 |
&gen_op_eciwx_le_raw, |
3604 |
&gen_op_eciwx_64_raw, |
3605 |
&gen_op_eciwx_le_64_raw, |
3606 |
}; |
3607 |
static GenOpFunc *gen_op_ecowx[] = {
|
3608 |
&gen_op_ecowx_raw, |
3609 |
&gen_op_ecowx_le_raw, |
3610 |
&gen_op_ecowx_64_raw, |
3611 |
&gen_op_ecowx_le_64_raw, |
3612 |
}; |
3613 |
#else
|
3614 |
static GenOpFunc *gen_op_eciwx[] = {
|
3615 |
&gen_op_eciwx_user, |
3616 |
&gen_op_eciwx_le_user, |
3617 |
&gen_op_eciwx_kernel, |
3618 |
&gen_op_eciwx_le_kernel, |
3619 |
&gen_op_eciwx_64_user, |
3620 |
&gen_op_eciwx_le_64_user, |
3621 |
&gen_op_eciwx_64_kernel, |
3622 |
&gen_op_eciwx_le_64_kernel, |
3623 |
}; |
3624 |
static GenOpFunc *gen_op_ecowx[] = {
|
3625 |
&gen_op_ecowx_user, |
3626 |
&gen_op_ecowx_le_user, |
3627 |
&gen_op_ecowx_kernel, |
3628 |
&gen_op_ecowx_le_kernel, |
3629 |
&gen_op_ecowx_64_user, |
3630 |
&gen_op_ecowx_le_64_user, |
3631 |
&gen_op_ecowx_64_kernel, |
3632 |
&gen_op_ecowx_le_64_kernel, |
3633 |
}; |
3634 |
#endif
|
3635 |
#else
|
3636 |
#if defined(CONFIG_USER_ONLY)
|
3637 |
static GenOpFunc *gen_op_eciwx[] = {
|
3638 |
&gen_op_eciwx_raw, |
3639 |
&gen_op_eciwx_le_raw, |
3640 |
}; |
3641 |
static GenOpFunc *gen_op_ecowx[] = {
|
3642 |
&gen_op_ecowx_raw, |
3643 |
&gen_op_ecowx_le_raw, |
3644 |
}; |
3645 |
#else
|
3646 |
static GenOpFunc *gen_op_eciwx[] = {
|
3647 |
&gen_op_eciwx_user, |
3648 |
&gen_op_eciwx_le_user, |
3649 |
&gen_op_eciwx_kernel, |
3650 |
&gen_op_eciwx_le_kernel, |
3651 |
}; |
3652 |
static GenOpFunc *gen_op_ecowx[] = {
|
3653 |
&gen_op_ecowx_user, |
3654 |
&gen_op_ecowx_le_user, |
3655 |
&gen_op_ecowx_kernel, |
3656 |
&gen_op_ecowx_le_kernel, |
3657 |
}; |
3658 |
#endif
|
3659 |
#endif
|
3660 |
|
3661 |
/* eciwx */
|
3662 |
GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN) |
3663 |
{ |
3664 |
/* Should check EAR[E] & alignment ! */
|
3665 |
gen_addr_reg_index(ctx); |
3666 |
op_eciwx(); |
3667 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
3668 |
} |
3669 |
|
3670 |
/* ecowx */
|
3671 |
GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN) |
3672 |
{ |
3673 |
/* Should check EAR[E] & alignment ! */
|
3674 |
gen_addr_reg_index(ctx); |
3675 |
gen_op_load_gpr_T1(rS(ctx->opcode)); |
3676 |
op_ecowx(); |
3677 |
} |
3678 |
|
3679 |
/* PowerPC 601 specific instructions */
|
3680 |
/* abs - abs. */
|
3681 |
GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR) |
3682 |
{ |
3683 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
3684 |
gen_op_POWER_abs(); |
3685 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
3686 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3687 |
gen_set_Rc0(ctx); |
3688 |
} |
3689 |
|
3690 |
/* abso - abso. */
|
3691 |
GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR) |
3692 |
{ |
3693 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
3694 |
gen_op_POWER_abso(); |
3695 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
3696 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3697 |
gen_set_Rc0(ctx); |
3698 |
} |
3699 |
|
3700 |
/* clcs */
|
3701 |
GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR) |
3702 |
{ |
3703 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
3704 |
gen_op_POWER_clcs(); |
3705 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
3706 |
} |
3707 |
|
3708 |
/* div - div. */
|
3709 |
GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR) |
3710 |
{ |
3711 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
3712 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
3713 |
gen_op_POWER_div(); |
3714 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
3715 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3716 |
gen_set_Rc0(ctx); |
3717 |
} |
3718 |
|
3719 |
/* divo - divo. */
|
3720 |
GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR) |
3721 |
{ |
3722 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
3723 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
3724 |
gen_op_POWER_divo(); |
3725 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
3726 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3727 |
gen_set_Rc0(ctx); |
3728 |
} |
3729 |
|
3730 |
/* divs - divs. */
|
3731 |
GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR) |
3732 |
{ |
3733 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
3734 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
3735 |
gen_op_POWER_divs(); |
3736 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
3737 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3738 |
gen_set_Rc0(ctx); |
3739 |
} |
3740 |
|
3741 |
/* divso - divso. */
|
3742 |
GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR) |
3743 |
{ |
3744 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
3745 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
3746 |
gen_op_POWER_divso(); |
3747 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
3748 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3749 |
gen_set_Rc0(ctx); |
3750 |
} |
3751 |
|
3752 |
/* doz - doz. */
|
3753 |
GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR) |
3754 |
{ |
3755 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
3756 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
3757 |
gen_op_POWER_doz(); |
3758 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
3759 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3760 |
gen_set_Rc0(ctx); |
3761 |
} |
3762 |
|
3763 |
/* dozo - dozo. */
|
3764 |
GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR) |
3765 |
{ |
3766 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
3767 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
3768 |
gen_op_POWER_dozo(); |
3769 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
3770 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3771 |
gen_set_Rc0(ctx); |
3772 |
} |
3773 |
|
3774 |
/* dozi */
|
3775 |
GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR) |
3776 |
{ |
3777 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
3778 |
gen_op_set_T1(SIMM(ctx->opcode)); |
3779 |
gen_op_POWER_doz(); |
3780 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
3781 |
} |
3782 |
|
3783 |
/* As lscbx load from memory byte after byte, it's always endian safe */
|
3784 |
#define op_POWER_lscbx(start, ra, rb) \
|
3785 |
(*gen_op_POWER_lscbx[ctx->mem_idx])(start, ra, rb) |
3786 |
#if defined(CONFIG_USER_ONLY)
|
3787 |
static GenOpFunc3 *gen_op_POWER_lscbx[] = {
|
3788 |
&gen_op_POWER_lscbx_raw, |
3789 |
&gen_op_POWER_lscbx_raw, |
3790 |
}; |
3791 |
#else
|
3792 |
static GenOpFunc3 *gen_op_POWER_lscbx[] = {
|
3793 |
&gen_op_POWER_lscbx_user, |
3794 |
&gen_op_POWER_lscbx_user, |
3795 |
&gen_op_POWER_lscbx_kernel, |
3796 |
&gen_op_POWER_lscbx_kernel, |
3797 |
}; |
3798 |
#endif
|
3799 |
|
3800 |
/* lscbx - lscbx. */
|
3801 |
GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR) |
3802 |
{ |
3803 |
int ra = rA(ctx->opcode);
|
3804 |
int rb = rB(ctx->opcode);
|
3805 |
|
3806 |
gen_addr_reg_index(ctx); |
3807 |
if (ra == 0) { |
3808 |
ra = rb; |
3809 |
} |
3810 |
/* NIP cannot be restored if the memory exception comes from an helper */
|
3811 |
gen_update_nip(ctx, ctx->nip - 4);
|
3812 |
gen_op_load_xer_bc(); |
3813 |
gen_op_load_xer_cmp(); |
3814 |
op_POWER_lscbx(rD(ctx->opcode), ra, rb); |
3815 |
gen_op_store_xer_bc(); |
3816 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3817 |
gen_set_Rc0(ctx); |
3818 |
} |
3819 |
|
3820 |
/* maskg - maskg. */
|
3821 |
GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR) |
3822 |
{ |
3823 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
3824 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
3825 |
gen_op_POWER_maskg(); |
3826 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
3827 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3828 |
gen_set_Rc0(ctx); |
3829 |
} |
3830 |
|
3831 |
/* maskir - maskir. */
|
3832 |
GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR) |
3833 |
{ |
3834 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
3835 |
gen_op_load_gpr_T1(rS(ctx->opcode)); |
3836 |
gen_op_load_gpr_T2(rB(ctx->opcode)); |
3837 |
gen_op_POWER_maskir(); |
3838 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
3839 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3840 |
gen_set_Rc0(ctx); |
3841 |
} |
3842 |
|
3843 |
/* mul - mul. */
|
3844 |
GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR) |
3845 |
{ |
3846 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
3847 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
3848 |
gen_op_POWER_mul(); |
3849 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
3850 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3851 |
gen_set_Rc0(ctx); |
3852 |
} |
3853 |
|
3854 |
/* mulo - mulo. */
|
3855 |
GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR) |
3856 |
{ |
3857 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
3858 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
3859 |
gen_op_POWER_mulo(); |
3860 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
3861 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3862 |
gen_set_Rc0(ctx); |
3863 |
} |
3864 |
|
3865 |
/* nabs - nabs. */
|
3866 |
GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR) |
3867 |
{ |
3868 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
3869 |
gen_op_POWER_nabs(); |
3870 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
3871 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3872 |
gen_set_Rc0(ctx); |
3873 |
} |
3874 |
|
3875 |
/* nabso - nabso. */
|
3876 |
GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR) |
3877 |
{ |
3878 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
3879 |
gen_op_POWER_nabso(); |
3880 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
3881 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3882 |
gen_set_Rc0(ctx); |
3883 |
} |
3884 |
|
3885 |
/* rlmi - rlmi. */
|
3886 |
GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR) |
3887 |
{ |
3888 |
uint32_t mb, me; |
3889 |
|
3890 |
mb = MB(ctx->opcode); |
3891 |
me = ME(ctx->opcode); |
3892 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
3893 |
gen_op_load_gpr_T1(rA(ctx->opcode)); |
3894 |
gen_op_load_gpr_T2(rB(ctx->opcode)); |
3895 |
gen_op_POWER_rlmi(MASK(mb, me), ~MASK(mb, me)); |
3896 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
3897 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3898 |
gen_set_Rc0(ctx); |
3899 |
} |
3900 |
|
3901 |
/* rrib - rrib. */
|
3902 |
GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR) |
3903 |
{ |
3904 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
3905 |
gen_op_load_gpr_T1(rA(ctx->opcode)); |
3906 |
gen_op_load_gpr_T2(rB(ctx->opcode)); |
3907 |
gen_op_POWER_rrib(); |
3908 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
3909 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3910 |
gen_set_Rc0(ctx); |
3911 |
} |
3912 |
|
3913 |
/* sle - sle. */
|
3914 |
GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR) |
3915 |
{ |
3916 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
3917 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
3918 |
gen_op_POWER_sle(); |
3919 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
3920 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3921 |
gen_set_Rc0(ctx); |
3922 |
} |
3923 |
|
3924 |
/* sleq - sleq. */
|
3925 |
GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR) |
3926 |
{ |
3927 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
3928 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
3929 |
gen_op_POWER_sleq(); |
3930 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
3931 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3932 |
gen_set_Rc0(ctx); |
3933 |
} |
3934 |
|
3935 |
/* sliq - sliq. */
|
3936 |
GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR) |
3937 |
{ |
3938 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
3939 |
gen_op_set_T1(SH(ctx->opcode)); |
3940 |
gen_op_POWER_sle(); |
3941 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
3942 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3943 |
gen_set_Rc0(ctx); |
3944 |
} |
3945 |
|
3946 |
/* slliq - slliq. */
|
3947 |
GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR) |
3948 |
{ |
3949 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
3950 |
gen_op_set_T1(SH(ctx->opcode)); |
3951 |
gen_op_POWER_sleq(); |
3952 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
3953 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3954 |
gen_set_Rc0(ctx); |
3955 |
} |
3956 |
|
3957 |
/* sllq - sllq. */
|
3958 |
GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR) |
3959 |
{ |
3960 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
3961 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
3962 |
gen_op_POWER_sllq(); |
3963 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
3964 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3965 |
gen_set_Rc0(ctx); |
3966 |
} |
3967 |
|
3968 |
/* slq - slq. */
|
3969 |
GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR) |
3970 |
{ |
3971 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
3972 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
3973 |
gen_op_POWER_slq(); |
3974 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
3975 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3976 |
gen_set_Rc0(ctx); |
3977 |
} |
3978 |
|
3979 |
/* sraiq - sraiq. */
|
3980 |
GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR) |
3981 |
{ |
3982 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
3983 |
gen_op_set_T1(SH(ctx->opcode)); |
3984 |
gen_op_POWER_sraq(); |
3985 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
3986 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3987 |
gen_set_Rc0(ctx); |
3988 |
} |
3989 |
|
3990 |
/* sraq - sraq. */
|
3991 |
GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR) |
3992 |
{ |
3993 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
3994 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
3995 |
gen_op_POWER_sraq(); |
3996 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
3997 |
if (unlikely(Rc(ctx->opcode) != 0)) |
3998 |
gen_set_Rc0(ctx); |
3999 |
} |
4000 |
|
4001 |
/* sre - sre. */
|
4002 |
GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR) |
4003 |
{ |
4004 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
4005 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
4006 |
gen_op_POWER_sre(); |
4007 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
4008 |
if (unlikely(Rc(ctx->opcode) != 0)) |
4009 |
gen_set_Rc0(ctx); |
4010 |
} |
4011 |
|
4012 |
/* srea - srea. */
|
4013 |
GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR) |
4014 |
{ |
4015 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
4016 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
4017 |
gen_op_POWER_srea(); |
4018 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
4019 |
if (unlikely(Rc(ctx->opcode) != 0)) |
4020 |
gen_set_Rc0(ctx); |
4021 |
} |
4022 |
|
4023 |
/* sreq */
|
4024 |
GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR) |
4025 |
{ |
4026 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
4027 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
4028 |
gen_op_POWER_sreq(); |
4029 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
4030 |
if (unlikely(Rc(ctx->opcode) != 0)) |
4031 |
gen_set_Rc0(ctx); |
4032 |
} |
4033 |
|
4034 |
/* sriq */
|
4035 |
GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR) |
4036 |
{ |
4037 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
4038 |
gen_op_set_T1(SH(ctx->opcode)); |
4039 |
gen_op_POWER_srq(); |
4040 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
4041 |
if (unlikely(Rc(ctx->opcode) != 0)) |
4042 |
gen_set_Rc0(ctx); |
4043 |
} |
4044 |
|
4045 |
/* srliq */
|
4046 |
GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR) |
4047 |
{ |
4048 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
4049 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
4050 |
gen_op_set_T1(SH(ctx->opcode)); |
4051 |
gen_op_POWER_srlq(); |
4052 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
4053 |
if (unlikely(Rc(ctx->opcode) != 0)) |
4054 |
gen_set_Rc0(ctx); |
4055 |
} |
4056 |
|
4057 |
/* srlq */
|
4058 |
GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR) |
4059 |
{ |
4060 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
4061 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
4062 |
gen_op_POWER_srlq(); |
4063 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
4064 |
if (unlikely(Rc(ctx->opcode) != 0)) |
4065 |
gen_set_Rc0(ctx); |
4066 |
} |
4067 |
|
4068 |
/* srq */
|
4069 |
GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR) |
4070 |
{ |
4071 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
4072 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
4073 |
gen_op_POWER_srq(); |
4074 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
4075 |
if (unlikely(Rc(ctx->opcode) != 0)) |
4076 |
gen_set_Rc0(ctx); |
4077 |
} |
4078 |
|
4079 |
/* PowerPC 602 specific instructions */
|
4080 |
/* dsa */
|
4081 |
GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC) |
4082 |
{ |
4083 |
/* XXX: TODO */
|
4084 |
GEN_EXCP_INVAL(ctx); |
4085 |
} |
4086 |
|
4087 |
/* esa */
|
4088 |
GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC) |
4089 |
{ |
4090 |
/* XXX: TODO */
|
4091 |
GEN_EXCP_INVAL(ctx); |
4092 |
} |
4093 |
|
4094 |
/* mfrom */
|
4095 |
GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC) |
4096 |
{ |
4097 |
#if defined(CONFIG_USER_ONLY)
|
4098 |
GEN_EXCP_PRIVOPC(ctx); |
4099 |
#else
|
4100 |
if (unlikely(!ctx->supervisor)) {
|
4101 |
GEN_EXCP_PRIVOPC(ctx); |
4102 |
return;
|
4103 |
} |
4104 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
4105 |
gen_op_602_mfrom(); |
4106 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
4107 |
#endif
|
4108 |
} |
4109 |
|
4110 |
/* 602 - 603 - G2 TLB management */
|
4111 |
/* tlbld */
|
4112 |
GEN_HANDLER(tlbld, 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB) |
4113 |
{ |
4114 |
#if defined(CONFIG_USER_ONLY)
|
4115 |
GEN_EXCP_PRIVOPC(ctx); |
4116 |
#else
|
4117 |
if (unlikely(!ctx->supervisor)) {
|
4118 |
GEN_EXCP_PRIVOPC(ctx); |
4119 |
return;
|
4120 |
} |
4121 |
gen_op_load_gpr_T0(rB(ctx->opcode)); |
4122 |
gen_op_6xx_tlbld(); |
4123 |
#endif
|
4124 |
} |
4125 |
|
4126 |
/* tlbli */
|
4127 |
GEN_HANDLER(tlbli, 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB) |
4128 |
{ |
4129 |
#if defined(CONFIG_USER_ONLY)
|
4130 |
GEN_EXCP_PRIVOPC(ctx); |
4131 |
#else
|
4132 |
if (unlikely(!ctx->supervisor)) {
|
4133 |
GEN_EXCP_PRIVOPC(ctx); |
4134 |
return;
|
4135 |
} |
4136 |
gen_op_load_gpr_T0(rB(ctx->opcode)); |
4137 |
gen_op_6xx_tlbli(); |
4138 |
#endif
|
4139 |
} |
4140 |
|
4141 |
/* POWER instructions not in PowerPC 601 */
|
4142 |
/* clf */
|
4143 |
GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER) |
4144 |
{ |
4145 |
/* Cache line flush: implemented as no-op */
|
4146 |
} |
4147 |
|
4148 |
/* cli */
|
4149 |
GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER) |
4150 |
{ |
4151 |
/* Cache line invalidate: privileged and treated as no-op */
|
4152 |
#if defined(CONFIG_USER_ONLY)
|
4153 |
GEN_EXCP_PRIVOPC(ctx); |
4154 |
#else
|
4155 |
if (unlikely(!ctx->supervisor)) {
|
4156 |
GEN_EXCP_PRIVOPC(ctx); |
4157 |
return;
|
4158 |
} |
4159 |
#endif
|
4160 |
} |
4161 |
|
4162 |
/* dclst */
|
4163 |
GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER) |
4164 |
{ |
4165 |
/* Data cache line store: treated as no-op */
|
4166 |
} |
4167 |
|
4168 |
GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER) |
4169 |
{ |
4170 |
#if defined(CONFIG_USER_ONLY)
|
4171 |
GEN_EXCP_PRIVOPC(ctx); |
4172 |
#else
|
4173 |
if (unlikely(!ctx->supervisor)) {
|
4174 |
GEN_EXCP_PRIVOPC(ctx); |
4175 |
return;
|
4176 |
} |
4177 |
int ra = rA(ctx->opcode);
|
4178 |
int rd = rD(ctx->opcode);
|
4179 |
|
4180 |
gen_addr_reg_index(ctx); |
4181 |
gen_op_POWER_mfsri(); |
4182 |
gen_op_store_T0_gpr(rd); |
4183 |
if (ra != 0 && ra != rd) |
4184 |
gen_op_store_T1_gpr(ra); |
4185 |
#endif
|
4186 |
} |
4187 |
|
4188 |
GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER) |
4189 |
{ |
4190 |
#if defined(CONFIG_USER_ONLY)
|
4191 |
GEN_EXCP_PRIVOPC(ctx); |
4192 |
#else
|
4193 |
if (unlikely(!ctx->supervisor)) {
|
4194 |
GEN_EXCP_PRIVOPC(ctx); |
4195 |
return;
|
4196 |
} |
4197 |
gen_addr_reg_index(ctx); |
4198 |
gen_op_POWER_rac(); |
4199 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
4200 |
#endif
|
4201 |
} |
4202 |
|
4203 |
GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER) |
4204 |
{ |
4205 |
#if defined(CONFIG_USER_ONLY)
|
4206 |
GEN_EXCP_PRIVOPC(ctx); |
4207 |
#else
|
4208 |
if (unlikely(!ctx->supervisor)) {
|
4209 |
GEN_EXCP_PRIVOPC(ctx); |
4210 |
return;
|
4211 |
} |
4212 |
gen_op_POWER_rfsvc(); |
4213 |
GEN_SYNC(ctx); |
4214 |
#endif
|
4215 |
} |
4216 |
|
4217 |
/* svc is not implemented for now */
|
4218 |
|
4219 |
/* POWER2 specific instructions */
|
4220 |
/* Quad manipulation (load/store two floats at a time) */
|
4221 |
#define op_POWER2_lfq() (*gen_op_POWER2_lfq[ctx->mem_idx])()
|
4222 |
#define op_POWER2_stfq() (*gen_op_POWER2_stfq[ctx->mem_idx])()
|
4223 |
#if defined(CONFIG_USER_ONLY)
|
4224 |
static GenOpFunc *gen_op_POWER2_lfq[] = {
|
4225 |
&gen_op_POWER2_lfq_le_raw, |
4226 |
&gen_op_POWER2_lfq_raw, |
4227 |
}; |
4228 |
static GenOpFunc *gen_op_POWER2_stfq[] = {
|
4229 |
&gen_op_POWER2_stfq_le_raw, |
4230 |
&gen_op_POWER2_stfq_raw, |
4231 |
}; |
4232 |
#else
|
4233 |
static GenOpFunc *gen_op_POWER2_lfq[] = {
|
4234 |
&gen_op_POWER2_lfq_le_user, |
4235 |
&gen_op_POWER2_lfq_user, |
4236 |
&gen_op_POWER2_lfq_le_kernel, |
4237 |
&gen_op_POWER2_lfq_kernel, |
4238 |
}; |
4239 |
static GenOpFunc *gen_op_POWER2_stfq[] = {
|
4240 |
&gen_op_POWER2_stfq_le_user, |
4241 |
&gen_op_POWER2_stfq_user, |
4242 |
&gen_op_POWER2_stfq_le_kernel, |
4243 |
&gen_op_POWER2_stfq_kernel, |
4244 |
}; |
4245 |
#endif
|
4246 |
|
4247 |
/* lfq */
|
4248 |
GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2) |
4249 |
{ |
4250 |
/* NIP cannot be restored if the memory exception comes from an helper */
|
4251 |
gen_update_nip(ctx, ctx->nip - 4);
|
4252 |
gen_addr_imm_index(ctx, 0);
|
4253 |
op_POWER2_lfq(); |
4254 |
gen_op_store_FT0_fpr(rD(ctx->opcode)); |
4255 |
gen_op_store_FT1_fpr(rD(ctx->opcode) + 1);
|
4256 |
} |
4257 |
|
4258 |
/* lfqu */
|
4259 |
GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2) |
4260 |
{ |
4261 |
int ra = rA(ctx->opcode);
|
4262 |
|
4263 |
/* NIP cannot be restored if the memory exception comes from an helper */
|
4264 |
gen_update_nip(ctx, ctx->nip - 4);
|
4265 |
gen_addr_imm_index(ctx, 0);
|
4266 |
op_POWER2_lfq(); |
4267 |
gen_op_store_FT0_fpr(rD(ctx->opcode)); |
4268 |
gen_op_store_FT1_fpr(rD(ctx->opcode) + 1);
|
4269 |
if (ra != 0) |
4270 |
gen_op_store_T0_gpr(ra); |
4271 |
} |
4272 |
|
4273 |
/* lfqux */
|
4274 |
GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2) |
4275 |
{ |
4276 |
int ra = rA(ctx->opcode);
|
4277 |
|
4278 |
/* NIP cannot be restored if the memory exception comes from an helper */
|
4279 |
gen_update_nip(ctx, ctx->nip - 4);
|
4280 |
gen_addr_reg_index(ctx); |
4281 |
op_POWER2_lfq(); |
4282 |
gen_op_store_FT0_fpr(rD(ctx->opcode)); |
4283 |
gen_op_store_FT1_fpr(rD(ctx->opcode) + 1);
|
4284 |
if (ra != 0) |
4285 |
gen_op_store_T0_gpr(ra); |
4286 |
} |
4287 |
|
4288 |
/* lfqx */
|
4289 |
GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2) |
4290 |
{ |
4291 |
/* NIP cannot be restored if the memory exception comes from an helper */
|
4292 |
gen_update_nip(ctx, ctx->nip - 4);
|
4293 |
gen_addr_reg_index(ctx); |
4294 |
op_POWER2_lfq(); |
4295 |
gen_op_store_FT0_fpr(rD(ctx->opcode)); |
4296 |
gen_op_store_FT1_fpr(rD(ctx->opcode) + 1);
|
4297 |
} |
4298 |
|
4299 |
/* stfq */
|
4300 |
GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2) |
4301 |
{ |
4302 |
/* NIP cannot be restored if the memory exception comes from an helper */
|
4303 |
gen_update_nip(ctx, ctx->nip - 4);
|
4304 |
gen_addr_imm_index(ctx, 0);
|
4305 |
gen_op_load_fpr_FT0(rS(ctx->opcode)); |
4306 |
gen_op_load_fpr_FT1(rS(ctx->opcode) + 1);
|
4307 |
op_POWER2_stfq(); |
4308 |
} |
4309 |
|
4310 |
/* stfqu */
|
4311 |
GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2) |
4312 |
{ |
4313 |
int ra = rA(ctx->opcode);
|
4314 |
|
4315 |
/* NIP cannot be restored if the memory exception comes from an helper */
|
4316 |
gen_update_nip(ctx, ctx->nip - 4);
|
4317 |
gen_addr_imm_index(ctx, 0);
|
4318 |
gen_op_load_fpr_FT0(rS(ctx->opcode)); |
4319 |
gen_op_load_fpr_FT1(rS(ctx->opcode) + 1);
|
4320 |
op_POWER2_stfq(); |
4321 |
if (ra != 0) |
4322 |
gen_op_store_T0_gpr(ra); |
4323 |
} |
4324 |
|
4325 |
/* stfqux */
|
4326 |
GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2) |
4327 |
{ |
4328 |
int ra = rA(ctx->opcode);
|
4329 |
|
4330 |
/* NIP cannot be restored if the memory exception comes from an helper */
|
4331 |
gen_update_nip(ctx, ctx->nip - 4);
|
4332 |
gen_addr_reg_index(ctx); |
4333 |
gen_op_load_fpr_FT0(rS(ctx->opcode)); |
4334 |
gen_op_load_fpr_FT1(rS(ctx->opcode) + 1);
|
4335 |
op_POWER2_stfq(); |
4336 |
if (ra != 0) |
4337 |
gen_op_store_T0_gpr(ra); |
4338 |
} |
4339 |
|
4340 |
/* stfqx */
|
4341 |
GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2) |
4342 |
{ |
4343 |
/* NIP cannot be restored if the memory exception comes from an helper */
|
4344 |
gen_update_nip(ctx, ctx->nip - 4);
|
4345 |
gen_addr_reg_index(ctx); |
4346 |
gen_op_load_fpr_FT0(rS(ctx->opcode)); |
4347 |
gen_op_load_fpr_FT1(rS(ctx->opcode) + 1);
|
4348 |
op_POWER2_stfq(); |
4349 |
} |
4350 |
|
4351 |
/* BookE specific instructions */
|
4352 |
/* XXX: not implemented on 440 ? */
|
4353 |
GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_BOOKE_EXT) |
4354 |
{ |
4355 |
/* XXX: TODO */
|
4356 |
GEN_EXCP_INVAL(ctx); |
4357 |
} |
4358 |
|
4359 |
/* XXX: not implemented on 440 ? */
|
4360 |
GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_BOOKE_EXT) |
4361 |
{ |
4362 |
#if defined(CONFIG_USER_ONLY)
|
4363 |
GEN_EXCP_PRIVOPC(ctx); |
4364 |
#else
|
4365 |
if (unlikely(!ctx->supervisor)) {
|
4366 |
GEN_EXCP_PRIVOPC(ctx); |
4367 |
return;
|
4368 |
} |
4369 |
gen_addr_reg_index(ctx); |
4370 |
/* Use the same micro-ops as for tlbie */
|
4371 |
#if defined(TARGET_PPC64)
|
4372 |
if (ctx->sf_mode)
|
4373 |
gen_op_tlbie_64(); |
4374 |
else
|
4375 |
#endif
|
4376 |
gen_op_tlbie(); |
4377 |
#endif
|
4378 |
} |
4379 |
|
4380 |
/* All 405 MAC instructions are translated here */
|
4381 |
static inline void gen_405_mulladd_insn (DisasContext *ctx, int opc2, int opc3, |
4382 |
int ra, int rb, int rt, int Rc) |
4383 |
{ |
4384 |
gen_op_load_gpr_T0(ra); |
4385 |
gen_op_load_gpr_T1(rb); |
4386 |
switch (opc3 & 0x0D) { |
4387 |
case 0x05: |
4388 |
/* macchw - macchw. - macchwo - macchwo. */
|
4389 |
/* macchws - macchws. - macchwso - macchwso. */
|
4390 |
/* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
|
4391 |
/* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
|
4392 |
/* mulchw - mulchw. */
|
4393 |
gen_op_405_mulchw(); |
4394 |
break;
|
4395 |
case 0x04: |
4396 |
/* macchwu - macchwu. - macchwuo - macchwuo. */
|
4397 |
/* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
|
4398 |
/* mulchwu - mulchwu. */
|
4399 |
gen_op_405_mulchwu(); |
4400 |
break;
|
4401 |
case 0x01: |
4402 |
/* machhw - machhw. - machhwo - machhwo. */
|
4403 |
/* machhws - machhws. - machhwso - machhwso. */
|
4404 |
/* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
|
4405 |
/* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
|
4406 |
/* mulhhw - mulhhw. */
|
4407 |
gen_op_405_mulhhw(); |
4408 |
break;
|
4409 |
case 0x00: |
4410 |
/* machhwu - machhwu. - machhwuo - machhwuo. */
|
4411 |
/* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
|
4412 |
/* mulhhwu - mulhhwu. */
|
4413 |
gen_op_405_mulhhwu(); |
4414 |
break;
|
4415 |
case 0x0D: |
4416 |
/* maclhw - maclhw. - maclhwo - maclhwo. */
|
4417 |
/* maclhws - maclhws. - maclhwso - maclhwso. */
|
4418 |
/* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
|
4419 |
/* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
|
4420 |
/* mullhw - mullhw. */
|
4421 |
gen_op_405_mullhw(); |
4422 |
break;
|
4423 |
case 0x0C: |
4424 |
/* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
|
4425 |
/* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
|
4426 |
/* mullhwu - mullhwu. */
|
4427 |
gen_op_405_mullhwu(); |
4428 |
break;
|
4429 |
} |
4430 |
if (opc2 & 0x02) { |
4431 |
/* nmultiply-and-accumulate (0x0E) */
|
4432 |
gen_op_neg(); |
4433 |
} |
4434 |
if (opc2 & 0x04) { |
4435 |
/* (n)multiply-and-accumulate (0x0C - 0x0E) */
|
4436 |
gen_op_load_gpr_T2(rt); |
4437 |
gen_op_move_T1_T0(); |
4438 |
gen_op_405_add_T0_T2(); |
4439 |
} |
4440 |
if (opc3 & 0x10) { |
4441 |
/* Check overflow */
|
4442 |
if (opc3 & 0x01) |
4443 |
gen_op_405_check_ov(); |
4444 |
else
|
4445 |
gen_op_405_check_ovu(); |
4446 |
} |
4447 |
if (opc3 & 0x02) { |
4448 |
/* Saturate */
|
4449 |
if (opc3 & 0x01) |
4450 |
gen_op_405_check_sat(); |
4451 |
else
|
4452 |
gen_op_405_check_satu(); |
4453 |
} |
4454 |
gen_op_store_T0_gpr(rt); |
4455 |
if (unlikely(Rc) != 0) { |
4456 |
/* Update Rc0 */
|
4457 |
gen_set_Rc0(ctx); |
4458 |
} |
4459 |
} |
4460 |
|
4461 |
#define GEN_MAC_HANDLER(name, opc2, opc3) \
|
4462 |
GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) \ |
4463 |
{ \ |
4464 |
gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \ |
4465 |
rD(ctx->opcode), Rc(ctx->opcode)); \ |
4466 |
} |
4467 |
|
4468 |
/* macchw - macchw. */
|
4469 |
GEN_MAC_HANDLER(macchw, 0x0C, 0x05); |
4470 |
/* macchwo - macchwo. */
|
4471 |
GEN_MAC_HANDLER(macchwo, 0x0C, 0x15); |
4472 |
/* macchws - macchws. */
|
4473 |
GEN_MAC_HANDLER(macchws, 0x0C, 0x07); |
4474 |
/* macchwso - macchwso. */
|
4475 |
GEN_MAC_HANDLER(macchwso, 0x0C, 0x17); |
4476 |
/* macchwsu - macchwsu. */
|
4477 |
GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06); |
4478 |
/* macchwsuo - macchwsuo. */
|
4479 |
GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16); |
4480 |
/* macchwu - macchwu. */
|
4481 |
GEN_MAC_HANDLER(macchwu, 0x0C, 0x04); |
4482 |
/* macchwuo - macchwuo. */
|
4483 |
GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14); |
4484 |
/* machhw - machhw. */
|
4485 |
GEN_MAC_HANDLER(machhw, 0x0C, 0x01); |
4486 |
/* machhwo - machhwo. */
|
4487 |
GEN_MAC_HANDLER(machhwo, 0x0C, 0x11); |
4488 |
/* machhws - machhws. */
|
4489 |
GEN_MAC_HANDLER(machhws, 0x0C, 0x03); |
4490 |
/* machhwso - machhwso. */
|
4491 |
GEN_MAC_HANDLER(machhwso, 0x0C, 0x13); |
4492 |
/* machhwsu - machhwsu. */
|
4493 |
GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02); |
4494 |
/* machhwsuo - machhwsuo. */
|
4495 |
GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12); |
4496 |
/* machhwu - machhwu. */
|
4497 |
GEN_MAC_HANDLER(machhwu, 0x0C, 0x00); |
4498 |
/* machhwuo - machhwuo. */
|
4499 |
GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10); |
4500 |
/* maclhw - maclhw. */
|
4501 |
GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D); |
4502 |
/* maclhwo - maclhwo. */
|
4503 |
GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D); |
4504 |
/* maclhws - maclhws. */
|
4505 |
GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F); |
4506 |
/* maclhwso - maclhwso. */
|
4507 |
GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F); |
4508 |
/* maclhwu - maclhwu. */
|
4509 |
GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C); |
4510 |
/* maclhwuo - maclhwuo. */
|
4511 |
GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C); |
4512 |
/* maclhwsu - maclhwsu. */
|
4513 |
GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E); |
4514 |
/* maclhwsuo - maclhwsuo. */
|
4515 |
GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E); |
4516 |
/* nmacchw - nmacchw. */
|
4517 |
GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05); |
4518 |
/* nmacchwo - nmacchwo. */
|
4519 |
GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15); |
4520 |
/* nmacchws - nmacchws. */
|
4521 |
GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07); |
4522 |
/* nmacchwso - nmacchwso. */
|
4523 |
GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17); |
4524 |
/* nmachhw - nmachhw. */
|
4525 |
GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01); |
4526 |
/* nmachhwo - nmachhwo. */
|
4527 |
GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11); |
4528 |
/* nmachhws - nmachhws. */
|
4529 |
GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03); |
4530 |
/* nmachhwso - nmachhwso. */
|
4531 |
GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13); |
4532 |
/* nmaclhw - nmaclhw. */
|
4533 |
GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D); |
4534 |
/* nmaclhwo - nmaclhwo. */
|
4535 |
GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D); |
4536 |
/* nmaclhws - nmaclhws. */
|
4537 |
GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F); |
4538 |
/* nmaclhwso - nmaclhwso. */
|
4539 |
GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F); |
4540 |
|
4541 |
/* mulchw - mulchw. */
|
4542 |
GEN_MAC_HANDLER(mulchw, 0x08, 0x05); |
4543 |
/* mulchwu - mulchwu. */
|
4544 |
GEN_MAC_HANDLER(mulchwu, 0x08, 0x04); |
4545 |
/* mulhhw - mulhhw. */
|
4546 |
GEN_MAC_HANDLER(mulhhw, 0x08, 0x01); |
4547 |
/* mulhhwu - mulhhwu. */
|
4548 |
GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00); |
4549 |
/* mullhw - mullhw. */
|
4550 |
GEN_MAC_HANDLER(mullhw, 0x08, 0x0D); |
4551 |
/* mullhwu - mullhwu. */
|
4552 |
GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C); |
4553 |
|
4554 |
/* mfdcr */
|
4555 |
GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_EMB_COMMON) |
4556 |
{ |
4557 |
#if defined(CONFIG_USER_ONLY)
|
4558 |
GEN_EXCP_PRIVREG(ctx); |
4559 |
#else
|
4560 |
uint32_t dcrn = SPR(ctx->opcode); |
4561 |
|
4562 |
if (unlikely(!ctx->supervisor)) {
|
4563 |
GEN_EXCP_PRIVREG(ctx); |
4564 |
return;
|
4565 |
} |
4566 |
gen_op_set_T0(dcrn); |
4567 |
gen_op_load_dcr(); |
4568 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
4569 |
#endif
|
4570 |
} |
4571 |
|
4572 |
/* mtdcr */
|
4573 |
GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_EMB_COMMON) |
4574 |
{ |
4575 |
#if defined(CONFIG_USER_ONLY)
|
4576 |
GEN_EXCP_PRIVREG(ctx); |
4577 |
#else
|
4578 |
uint32_t dcrn = SPR(ctx->opcode); |
4579 |
|
4580 |
if (unlikely(!ctx->supervisor)) {
|
4581 |
GEN_EXCP_PRIVREG(ctx); |
4582 |
return;
|
4583 |
} |
4584 |
gen_op_set_T0(dcrn); |
4585 |
gen_op_load_gpr_T1(rS(ctx->opcode)); |
4586 |
gen_op_store_dcr(); |
4587 |
#endif
|
4588 |
} |
4589 |
|
4590 |
/* mfdcrx */
|
4591 |
/* XXX: not implemented on 440 ? */
|
4592 |
GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_BOOKE_EXT) |
4593 |
{ |
4594 |
#if defined(CONFIG_USER_ONLY)
|
4595 |
GEN_EXCP_PRIVREG(ctx); |
4596 |
#else
|
4597 |
if (unlikely(!ctx->supervisor)) {
|
4598 |
GEN_EXCP_PRIVREG(ctx); |
4599 |
return;
|
4600 |
} |
4601 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
4602 |
gen_op_load_dcr(); |
4603 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
4604 |
/* Note: Rc update flag set leads to undefined state of Rc0 */
|
4605 |
#endif
|
4606 |
} |
4607 |
|
4608 |
/* mtdcrx */
|
4609 |
/* XXX: not implemented on 440 ? */
|
4610 |
GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_BOOKE_EXT) |
4611 |
{ |
4612 |
#if defined(CONFIG_USER_ONLY)
|
4613 |
GEN_EXCP_PRIVREG(ctx); |
4614 |
#else
|
4615 |
if (unlikely(!ctx->supervisor)) {
|
4616 |
GEN_EXCP_PRIVREG(ctx); |
4617 |
return;
|
4618 |
} |
4619 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
4620 |
gen_op_load_gpr_T1(rS(ctx->opcode)); |
4621 |
gen_op_store_dcr(); |
4622 |
/* Note: Rc update flag set leads to undefined state of Rc0 */
|
4623 |
#endif
|
4624 |
} |
4625 |
|
4626 |
/* mfdcrux (PPC 460) : user-mode access to DCR */
|
4627 |
GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX) |
4628 |
{ |
4629 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
4630 |
gen_op_load_dcr(); |
4631 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
4632 |
/* Note: Rc update flag set leads to undefined state of Rc0 */
|
4633 |
} |
4634 |
|
4635 |
/* mtdcrux (PPC 460) : user-mode access to DCR */
|
4636 |
GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX) |
4637 |
{ |
4638 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
4639 |
gen_op_load_gpr_T1(rS(ctx->opcode)); |
4640 |
gen_op_store_dcr(); |
4641 |
/* Note: Rc update flag set leads to undefined state of Rc0 */
|
4642 |
} |
4643 |
|
4644 |
/* dccci */
|
4645 |
GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON) |
4646 |
{ |
4647 |
#if defined(CONFIG_USER_ONLY)
|
4648 |
GEN_EXCP_PRIVOPC(ctx); |
4649 |
#else
|
4650 |
if (unlikely(!ctx->supervisor)) {
|
4651 |
GEN_EXCP_PRIVOPC(ctx); |
4652 |
return;
|
4653 |
} |
4654 |
/* interpreted as no-op */
|
4655 |
#endif
|
4656 |
} |
4657 |
|
4658 |
/* dcread */
|
4659 |
GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON) |
4660 |
{ |
4661 |
#if defined(CONFIG_USER_ONLY)
|
4662 |
GEN_EXCP_PRIVOPC(ctx); |
4663 |
#else
|
4664 |
if (unlikely(!ctx->supervisor)) {
|
4665 |
GEN_EXCP_PRIVOPC(ctx); |
4666 |
return;
|
4667 |
} |
4668 |
gen_addr_reg_index(ctx); |
4669 |
op_ldst(lwz); |
4670 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
4671 |
#endif
|
4672 |
} |
4673 |
|
4674 |
/* icbt */
|
4675 |
GEN_HANDLER(icbt_40x, 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT) |
4676 |
{ |
4677 |
/* interpreted as no-op */
|
4678 |
/* XXX: specification say this is treated as a load by the MMU
|
4679 |
* but does not generate any exception
|
4680 |
*/
|
4681 |
} |
4682 |
|
4683 |
/* iccci */
|
4684 |
GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON) |
4685 |
{ |
4686 |
#if defined(CONFIG_USER_ONLY)
|
4687 |
GEN_EXCP_PRIVOPC(ctx); |
4688 |
#else
|
4689 |
if (unlikely(!ctx->supervisor)) {
|
4690 |
GEN_EXCP_PRIVOPC(ctx); |
4691 |
return;
|
4692 |
} |
4693 |
/* interpreted as no-op */
|
4694 |
#endif
|
4695 |
} |
4696 |
|
4697 |
/* icread */
|
4698 |
GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON) |
4699 |
{ |
4700 |
#if defined(CONFIG_USER_ONLY)
|
4701 |
GEN_EXCP_PRIVOPC(ctx); |
4702 |
#else
|
4703 |
if (unlikely(!ctx->supervisor)) {
|
4704 |
GEN_EXCP_PRIVOPC(ctx); |
4705 |
return;
|
4706 |
} |
4707 |
/* interpreted as no-op */
|
4708 |
#endif
|
4709 |
} |
4710 |
|
4711 |
/* rfci (supervisor only) */
|
4712 |
GEN_HANDLER(rfci_40x, 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP) |
4713 |
{ |
4714 |
#if defined(CONFIG_USER_ONLY)
|
4715 |
GEN_EXCP_PRIVOPC(ctx); |
4716 |
#else
|
4717 |
if (unlikely(!ctx->supervisor)) {
|
4718 |
GEN_EXCP_PRIVOPC(ctx); |
4719 |
return;
|
4720 |
} |
4721 |
/* Restore CPU state */
|
4722 |
gen_op_40x_rfci(); |
4723 |
GEN_SYNC(ctx); |
4724 |
#endif
|
4725 |
} |
4726 |
|
4727 |
GEN_HANDLER(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE) |
4728 |
{ |
4729 |
#if defined(CONFIG_USER_ONLY)
|
4730 |
GEN_EXCP_PRIVOPC(ctx); |
4731 |
#else
|
4732 |
if (unlikely(!ctx->supervisor)) {
|
4733 |
GEN_EXCP_PRIVOPC(ctx); |
4734 |
return;
|
4735 |
} |
4736 |
/* Restore CPU state */
|
4737 |
gen_op_rfci(); |
4738 |
GEN_SYNC(ctx); |
4739 |
#endif
|
4740 |
} |
4741 |
|
4742 |
/* BookE specific */
|
4743 |
/* XXX: not implemented on 440 ? */
|
4744 |
GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_BOOKE_EXT) |
4745 |
{ |
4746 |
#if defined(CONFIG_USER_ONLY)
|
4747 |
GEN_EXCP_PRIVOPC(ctx); |
4748 |
#else
|
4749 |
if (unlikely(!ctx->supervisor)) {
|
4750 |
GEN_EXCP_PRIVOPC(ctx); |
4751 |
return;
|
4752 |
} |
4753 |
/* Restore CPU state */
|
4754 |
gen_op_rfdi(); |
4755 |
GEN_SYNC(ctx); |
4756 |
#endif
|
4757 |
} |
4758 |
|
4759 |
/* XXX: not implemented on 440 ? */
|
4760 |
GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI) |
4761 |
{ |
4762 |
#if defined(CONFIG_USER_ONLY)
|
4763 |
GEN_EXCP_PRIVOPC(ctx); |
4764 |
#else
|
4765 |
if (unlikely(!ctx->supervisor)) {
|
4766 |
GEN_EXCP_PRIVOPC(ctx); |
4767 |
return;
|
4768 |
} |
4769 |
/* Restore CPU state */
|
4770 |
gen_op_rfmci(); |
4771 |
GEN_SYNC(ctx); |
4772 |
#endif
|
4773 |
} |
4774 |
|
4775 |
/* TLB management - PowerPC 405 implementation */
|
4776 |
/* tlbre */
|
4777 |
GEN_HANDLER(tlbre_40x, 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB) |
4778 |
{ |
4779 |
#if defined(CONFIG_USER_ONLY)
|
4780 |
GEN_EXCP_PRIVOPC(ctx); |
4781 |
#else
|
4782 |
if (unlikely(!ctx->supervisor)) {
|
4783 |
GEN_EXCP_PRIVOPC(ctx); |
4784 |
return;
|
4785 |
} |
4786 |
switch (rB(ctx->opcode)) {
|
4787 |
case 0: |
4788 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
4789 |
gen_op_4xx_tlbre_hi(); |
4790 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
4791 |
break;
|
4792 |
case 1: |
4793 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
4794 |
gen_op_4xx_tlbre_lo(); |
4795 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
4796 |
break;
|
4797 |
default:
|
4798 |
GEN_EXCP_INVAL(ctx); |
4799 |
break;
|
4800 |
} |
4801 |
#endif
|
4802 |
} |
4803 |
|
4804 |
/* tlbsx - tlbsx. */
|
4805 |
GEN_HANDLER(tlbsx_40x, 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB) |
4806 |
{ |
4807 |
#if defined(CONFIG_USER_ONLY)
|
4808 |
GEN_EXCP_PRIVOPC(ctx); |
4809 |
#else
|
4810 |
if (unlikely(!ctx->supervisor)) {
|
4811 |
GEN_EXCP_PRIVOPC(ctx); |
4812 |
return;
|
4813 |
} |
4814 |
gen_addr_reg_index(ctx); |
4815 |
if (Rc(ctx->opcode))
|
4816 |
gen_op_4xx_tlbsx_(); |
4817 |
else
|
4818 |
gen_op_4xx_tlbsx(); |
4819 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
4820 |
#endif
|
4821 |
} |
4822 |
|
4823 |
/* tlbwe */
|
4824 |
GEN_HANDLER(tlbwe_40x, 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB) |
4825 |
{ |
4826 |
#if defined(CONFIG_USER_ONLY)
|
4827 |
GEN_EXCP_PRIVOPC(ctx); |
4828 |
#else
|
4829 |
if (unlikely(!ctx->supervisor)) {
|
4830 |
GEN_EXCP_PRIVOPC(ctx); |
4831 |
return;
|
4832 |
} |
4833 |
switch (rB(ctx->opcode)) {
|
4834 |
case 0: |
4835 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
4836 |
gen_op_load_gpr_T1(rS(ctx->opcode)); |
4837 |
gen_op_4xx_tlbwe_hi(); |
4838 |
break;
|
4839 |
case 1: |
4840 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
4841 |
gen_op_load_gpr_T1(rS(ctx->opcode)); |
4842 |
gen_op_4xx_tlbwe_lo(); |
4843 |
break;
|
4844 |
default:
|
4845 |
GEN_EXCP_INVAL(ctx); |
4846 |
break;
|
4847 |
} |
4848 |
#endif
|
4849 |
} |
4850 |
|
4851 |
/* TLB management - PowerPC 440 implementation */
|
4852 |
/* tlbre */
|
4853 |
GEN_HANDLER(tlbre_440, 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE) |
4854 |
{ |
4855 |
#if defined(CONFIG_USER_ONLY)
|
4856 |
GEN_EXCP_PRIVOPC(ctx); |
4857 |
#else
|
4858 |
if (unlikely(!ctx->supervisor)) {
|
4859 |
GEN_EXCP_PRIVOPC(ctx); |
4860 |
return;
|
4861 |
} |
4862 |
switch (rB(ctx->opcode)) {
|
4863 |
case 0: |
4864 |
case 1: |
4865 |
case 2: |
4866 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
4867 |
gen_op_440_tlbre(rB(ctx->opcode)); |
4868 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
4869 |
break;
|
4870 |
default:
|
4871 |
GEN_EXCP_INVAL(ctx); |
4872 |
break;
|
4873 |
} |
4874 |
#endif
|
4875 |
} |
4876 |
|
4877 |
/* tlbsx - tlbsx. */
|
4878 |
GEN_HANDLER(tlbsx_440, 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE) |
4879 |
{ |
4880 |
#if defined(CONFIG_USER_ONLY)
|
4881 |
GEN_EXCP_PRIVOPC(ctx); |
4882 |
#else
|
4883 |
if (unlikely(!ctx->supervisor)) {
|
4884 |
GEN_EXCP_PRIVOPC(ctx); |
4885 |
return;
|
4886 |
} |
4887 |
gen_addr_reg_index(ctx); |
4888 |
if (Rc(ctx->opcode))
|
4889 |
gen_op_440_tlbsx_(); |
4890 |
else
|
4891 |
gen_op_440_tlbsx(); |
4892 |
gen_op_store_T0_gpr(rD(ctx->opcode)); |
4893 |
#endif
|
4894 |
} |
4895 |
|
4896 |
/* tlbwe */
|
4897 |
GEN_HANDLER(tlbwe_440, 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE) |
4898 |
{ |
4899 |
#if defined(CONFIG_USER_ONLY)
|
4900 |
GEN_EXCP_PRIVOPC(ctx); |
4901 |
#else
|
4902 |
if (unlikely(!ctx->supervisor)) {
|
4903 |
GEN_EXCP_PRIVOPC(ctx); |
4904 |
return;
|
4905 |
} |
4906 |
switch (rB(ctx->opcode)) {
|
4907 |
case 0: |
4908 |
case 1: |
4909 |
case 2: |
4910 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
4911 |
gen_op_load_gpr_T1(rS(ctx->opcode)); |
4912 |
gen_op_440_tlbwe(rB(ctx->opcode)); |
4913 |
break;
|
4914 |
default:
|
4915 |
GEN_EXCP_INVAL(ctx); |
4916 |
break;
|
4917 |
} |
4918 |
#endif
|
4919 |
} |
4920 |
|
4921 |
/* wrtee */
|
4922 |
GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_EMB_COMMON) |
4923 |
{ |
4924 |
#if defined(CONFIG_USER_ONLY)
|
4925 |
GEN_EXCP_PRIVOPC(ctx); |
4926 |
#else
|
4927 |
if (unlikely(!ctx->supervisor)) {
|
4928 |
GEN_EXCP_PRIVOPC(ctx); |
4929 |
return;
|
4930 |
} |
4931 |
gen_op_load_gpr_T0(rD(ctx->opcode)); |
4932 |
gen_op_wrte(); |
4933 |
/* Stop translation to have a chance to raise an exception
|
4934 |
* if we just set msr_ee to 1
|
4935 |
*/
|
4936 |
GEN_STOP(ctx); |
4937 |
#endif
|
4938 |
} |
4939 |
|
4940 |
/* wrteei */
|
4941 |
GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000EFC01, PPC_EMB_COMMON) |
4942 |
{ |
4943 |
#if defined(CONFIG_USER_ONLY)
|
4944 |
GEN_EXCP_PRIVOPC(ctx); |
4945 |
#else
|
4946 |
if (unlikely(!ctx->supervisor)) {
|
4947 |
GEN_EXCP_PRIVOPC(ctx); |
4948 |
return;
|
4949 |
} |
4950 |
gen_op_set_T0(ctx->opcode & 0x00010000);
|
4951 |
gen_op_wrte(); |
4952 |
/* Stop translation to have a chance to raise an exception
|
4953 |
* if we just set msr_ee to 1
|
4954 |
*/
|
4955 |
GEN_STOP(ctx); |
4956 |
#endif
|
4957 |
} |
4958 |
|
4959 |
/* PowerPC 440 specific instructions */
|
4960 |
/* dlmzb */
|
4961 |
GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC) |
4962 |
{ |
4963 |
gen_op_load_gpr_T0(rS(ctx->opcode)); |
4964 |
gen_op_load_gpr_T1(rB(ctx->opcode)); |
4965 |
gen_op_440_dlmzb(); |
4966 |
gen_op_store_T0_gpr(rA(ctx->opcode)); |
4967 |
gen_op_store_xer_bc(); |
4968 |
if (Rc(ctx->opcode)) {
|
4969 |
gen_op_440_dlmzb_update_Rc(); |
4970 |
gen_op_store_T0_crf(0);
|
4971 |
} |
4972 |
} |
4973 |
|
4974 |
/* mbar replaces eieio on 440 */
|
4975 |
GEN_HANDLER(mbar, 0x1F, 0x16, 0x13, 0x001FF801, PPC_BOOKE) |
4976 |
{ |
4977 |
/* interpreted as no-op */
|
4978 |
} |
4979 |
|
4980 |
/* msync replaces sync on 440 */
|
4981 |
GEN_HANDLER(msync, 0x1F, 0x16, 0x12, 0x03FF0801, PPC_BOOKE) |
4982 |
{ |
4983 |
/* interpreted as no-op */
|
4984 |
} |
4985 |
|
4986 |
/* icbt */
|
4987 |
GEN_HANDLER(icbt_440, 0x1F, 0x16, 0x00, 0x03E00001, PPC_BOOKE) |
4988 |
{ |
4989 |
/* interpreted as no-op */
|
4990 |
/* XXX: specification say this is treated as a load by the MMU
|
4991 |
* but does not generate any exception
|
4992 |
*/
|
4993 |
} |
4994 |
|
4995 |
#if defined(TARGET_PPCEMB)
|
4996 |
/*** SPE extension ***/
|
4997 |
|
4998 |
/* Register moves */
|
4999 |
GEN32(gen_op_load_gpr64_T0, gen_op_load_gpr64_T0_gpr); |
5000 |
GEN32(gen_op_load_gpr64_T1, gen_op_load_gpr64_T1_gpr); |
5001 |
#if 0 // unused
|
5002 |
GEN32(gen_op_load_gpr64_T2, gen_op_load_gpr64_T2_gpr);
|
5003 |
#endif
|
5004 |
|
5005 |
GEN32(gen_op_store_T0_gpr64, gen_op_store_T0_gpr64_gpr); |
5006 |
GEN32(gen_op_store_T1_gpr64, gen_op_store_T1_gpr64_gpr); |
5007 |
#if 0 // unused
|
5008 |
GEN32(gen_op_store_T2_gpr64, gen_op_store_T2_gpr64_gpr);
|
5009 |
#endif
|
5010 |
|
5011 |
#define GEN_SPE(name0, name1, opc2, opc3, inval, type) \
|
5012 |
GEN_HANDLER(name0##_##name1, 0x04, opc2, opc3, inval, type) \ |
5013 |
{ \ |
5014 |
if (Rc(ctx->opcode)) \
|
5015 |
gen_##name1(ctx); \ |
5016 |
else \
|
5017 |
gen_##name0(ctx); \ |
5018 |
} |
5019 |
|
5020 |
/* Handler for undefined SPE opcodes */
|
5021 |
static inline void gen_speundef (DisasContext *ctx) |
5022 |
{ |
5023 |
GEN_EXCP_INVAL(ctx); |
5024 |
} |
5025 |
|
5026 |
/* SPE load and stores */
|
5027 |
static inline void gen_addr_spe_imm_index (DisasContext *ctx, int sh) |
5028 |
{ |
5029 |
target_long simm = rB(ctx->opcode); |
5030 |
|
5031 |
if (rA(ctx->opcode) == 0) { |
5032 |
gen_set_T0(simm << sh); |
5033 |
} else {
|
5034 |
gen_op_load_gpr_T0(rA(ctx->opcode)); |
5035 |
if (likely(simm != 0)) |
5036 |
gen_op_addi(simm << sh); |
5037 |
} |
5038 |
} |
5039 |
|
5040 |
#define op_spe_ldst(name) (*gen_op_##name[ctx->mem_idx])() |
5041 |
#if defined(CONFIG_USER_ONLY)
|
5042 |
#if defined(TARGET_PPC64)
|
5043 |
#define OP_SPE_LD_TABLE(name) \
|
5044 |
static GenOpFunc *gen_op_spe_l##name[] = { \ |
5045 |
&gen_op_spe_l##name##_raw, \ |
5046 |
&gen_op_spe_l##name##_le_raw, \ |
5047 |
&gen_op_spe_l##name##_64_raw, \ |
5048 |
&gen_op_spe_l##name##_le_64_raw, \ |
5049 |
}; |
5050 |
#define OP_SPE_ST_TABLE(name) \
|
5051 |
static GenOpFunc *gen_op_spe_st##name[] = { \ |
5052 |
&gen_op_spe_st##name##_raw, \ |
5053 |
&gen_op_spe_st##name##_le_raw, \ |
5054 |
&gen_op_spe_st##name##_64_raw, \ |
5055 |
&gen_op_spe_st##name##_le_64_raw, \ |
5056 |
}; |
5057 |
#else /* defined(TARGET_PPC64) */ |
5058 |
#define OP_SPE_LD_TABLE(name) \
|
5059 |
static GenOpFunc *gen_op_spe_l##name[] = { \ |
5060 |
&gen_op_spe_l##name##_raw, \ |
5061 |
&gen_op_spe_l##name##_le_raw, \ |
5062 |
}; |
5063 |
#define OP_SPE_ST_TABLE(name) \
|
5064 |
static GenOpFunc *gen_op_spe_st##name[] = { \ |
5065 |
&gen_op_spe_st##name##_raw, \ |
5066 |
&gen_op_spe_st##name##_le_raw, \ |
5067 |
}; |
5068 |
#endif /* defined(TARGET_PPC64) */ |
5069 |
#else /* defined(CONFIG_USER_ONLY) */ |
5070 |
#if defined(TARGET_PPC64)
|
5071 |
#define OP_SPE_LD_TABLE(name) \
|
5072 |
static GenOpFunc *gen_op_spe_l##name[] = { \ |
5073 |
&gen_op_spe_l##name##_user, \ |
5074 |
&gen_op_spe_l##name##_le_user, \ |
5075 |
&gen_op_spe_l##name##_kernel, \ |
5076 |
&gen_op_spe_l##name##_le_kernel, \ |
5077 |
&gen_op_spe_l##name##_64_user, \ |
5078 |
&gen_op_spe_l##name##_le_64_user, \ |
5079 |
&gen_op_spe_l##name##_64_kernel, \ |
5080 |
&gen_op_spe_l##name##_le_64_kernel, \ |
5081 |
}; |
5082 |
#define OP_SPE_ST_TABLE(name) \
|
5083 |
static GenOpFunc *gen_op_spe_st##name[] = { \ |
5084 |
&gen_op_spe_st##name##_user, \ |
5085 |
&gen_op_spe_st##name##_le_user, \ |
5086 |
&gen_op_spe_st##name##_kernel, \ |
5087 |
&gen_op_spe_st##name##_le_kernel, \ |
5088 |
&gen_op_spe_st##name##_64_user, \ |
5089 |
&gen_op_spe_st##name##_le_64_user, \ |
5090 |
&gen_op_spe_st##name##_64_kernel, \ |
5091 |
&gen_op_spe_st##name##_le_64_kernel, \ |
5092 |
}; |
5093 |
#else /* defined(TARGET_PPC64) */ |
5094 |
#define OP_SPE_LD_TABLE(name) \
|
5095 |
static GenOpFunc *gen_op_spe_l##name[] = { \ |
5096 |
&gen_op_spe_l##name##_user, \ |
5097 |
&gen_op_spe_l##name##_le_user, \ |
5098 |
&gen_op_spe_l##name##_kernel, \ |
5099 |
&gen_op_spe_l##name##_le_kernel, \ |
5100 |
}; |
5101 |
#define OP_SPE_ST_TABLE(name) \
|
5102 |
static GenOpFunc *gen_op_spe_st##name[] = { \ |
5103 |
&gen_op_spe_st##name##_user, \ |
5104 |
&gen_op_spe_st##name##_le_user, \ |
5105 |
&gen_op_spe_st##name##_kernel, \ |
5106 |
&gen_op_spe_st##name##_le_kernel, \ |
5107 |
}; |
5108 |
#endif /* defined(TARGET_PPC64) */ |
5109 |
#endif /* defined(CONFIG_USER_ONLY) */ |
5110 |
|
5111 |
#define GEN_SPE_LD(name, sh) \
|
5112 |
static inline void gen_evl##name (DisasContext *ctx) \ |
5113 |
{ \ |
5114 |
if (unlikely(!ctx->spe_enabled)) { \
|
5115 |
GEN_EXCP_NO_AP(ctx); \ |
5116 |
return; \
|
5117 |
} \ |
5118 |
gen_addr_spe_imm_index(ctx, sh); \ |
5119 |
op_spe_ldst(spe_l##name); \ |
5120 |
gen_op_store_T1_gpr64(rD(ctx->opcode)); \ |
5121 |
} |
5122 |
|
5123 |
#define GEN_SPE_LDX(name) \
|
5124 |
static inline void gen_evl##name##x (DisasContext *ctx) \ |
5125 |
{ \ |
5126 |
if (unlikely(!ctx->spe_enabled)) { \
|
5127 |
GEN_EXCP_NO_AP(ctx); \ |
5128 |
return; \
|
5129 |
} \ |
5130 |
gen_addr_reg_index(ctx); \ |
5131 |
op_spe_ldst(spe_l##name); \ |
5132 |
gen_op_store_T1_gpr64(rD(ctx->opcode)); \ |
5133 |
} |
5134 |
|
5135 |
#define GEN_SPEOP_LD(name, sh) \
|
5136 |
OP_SPE_LD_TABLE(name); \ |
5137 |
GEN_SPE_LD(name, sh); \ |
5138 |
GEN_SPE_LDX(name) |
5139 |
|
5140 |
#define GEN_SPE_ST(name, sh) \
|
5141 |
static inline void gen_evst##name (DisasContext *ctx) \ |
5142 |
{ \ |
5143 |
if (unlikely(!ctx->spe_enabled)) { \
|
5144 |
GEN_EXCP_NO_AP(ctx); \ |
5145 |
return; \
|
5146 |
} \ |
5147 |
gen_addr_spe_imm_index(ctx, sh); \ |
5148 |
gen_op_load_gpr64_T1(rS(ctx->opcode)); \ |
5149 |
op_spe_ldst(spe_st##name); \ |
5150 |
} |
5151 |
|
5152 |
#define GEN_SPE_STX(name) \
|
5153 |
static inline void gen_evst##name##x (DisasContext *ctx) \ |
5154 |
{ \ |
5155 |
if (unlikely(!ctx->spe_enabled)) { \
|
5156 |
GEN_EXCP_NO_AP(ctx); \ |
5157 |
return; \
|
5158 |
} \ |
5159 |
gen_addr_reg_index(ctx); \ |
5160 |
gen_op_load_gpr64_T1(rS(ctx->opcode)); \ |
5161 |
op_spe_ldst(spe_st##name); \ |
5162 |
} |
5163 |
|
5164 |
#define GEN_SPEOP_ST(name, sh) \
|
5165 |
OP_SPE_ST_TABLE(name); \ |
5166 |
GEN_SPE_ST(name, sh); \ |
5167 |
GEN_SPE_STX(name) |
5168 |
|
5169 |
#define GEN_SPEOP_LDST(name, sh) \
|
5170 |
GEN_SPEOP_LD(name, sh); \ |
5171 |
GEN_SPEOP_ST(name, sh) |
5172 |
|
5173 |
/* SPE arithmetic and logic */
|
5174 |
#define GEN_SPEOP_ARITH2(name) \
|
5175 |
static inline void gen_##name (DisasContext *ctx) \ |
5176 |
{ \ |
5177 |
if (unlikely(!ctx->spe_enabled)) { \
|
5178 |
GEN_EXCP_NO_AP(ctx); \ |
5179 |
return; \
|
5180 |
} \ |
5181 |
gen_op_load_gpr64_T0(rA(ctx->opcode)); \ |
5182 |
gen_op_load_gpr64_T1(rB(ctx->opcode)); \ |
5183 |
gen_op_##name(); \ |
5184 |
gen_op_store_T0_gpr64(rD(ctx->opcode)); \ |
5185 |
} |
5186 |
|
5187 |
#define GEN_SPEOP_ARITH1(name) \
|
5188 |
static inline void gen_##name (DisasContext *ctx) \ |
5189 |
{ \ |
5190 |
if (unlikely(!ctx->spe_enabled)) { \
|
5191 |
GEN_EXCP_NO_AP(ctx); \ |
5192 |
return; \
|
5193 |
} \ |
5194 |
gen_op_load_gpr64_T0(rA(ctx->opcode)); \ |
5195 |
gen_op_##name(); \ |
5196 |
gen_op_store_T0_gpr64(rD(ctx->opcode)); \ |
5197 |
} |
5198 |
|
5199 |
#define GEN_SPEOP_COMP(name) \
|
5200 |
static inline void gen_##name (DisasContext *ctx) \ |
5201 |
{ \ |
5202 |
if (unlikely(!ctx->spe_enabled)) { \
|
5203 |
GEN_EXCP_NO_AP(ctx); \ |
5204 |
return; \
|
5205 |
} \ |
5206 |
gen_op_load_gpr64_T0(rA(ctx->opcode)); \ |
5207 |
gen_op_load_gpr64_T1(rB(ctx->opcode)); \ |
5208 |
gen_op_##name(); \ |
5209 |
gen_op_store_T0_crf(crfD(ctx->opcode)); \ |
5210 |
} |
5211 |
|
5212 |
/* Logical */
|
5213 |
GEN_SPEOP_ARITH2(evand); |
5214 |
GEN_SPEOP_ARITH2(evandc); |
5215 |
GEN_SPEOP_ARITH2(evxor); |
5216 |
GEN_SPEOP_ARITH2(evor); |
5217 |
GEN_SPEOP_ARITH2(evnor); |
5218 |
GEN_SPEOP_ARITH2(eveqv); |
5219 |
GEN_SPEOP_ARITH2(evorc); |
5220 |
GEN_SPEOP_ARITH2(evnand); |
5221 |
GEN_SPEOP_ARITH2(evsrwu); |
5222 |
GEN_SPEOP_ARITH2(evsrws); |
5223 |
GEN_SPEOP_ARITH2(evslw); |
5224 |
GEN_SPEOP_ARITH2(evrlw); |
5225 |
GEN_SPEOP_ARITH2(evmergehi); |
5226 |
GEN_SPEOP_ARITH2(evmergelo); |
5227 |
GEN_SPEOP_ARITH2(evmergehilo); |
5228 |
GEN_SPEOP_ARITH2(evmergelohi); |
5229 |
|
5230 |
/* Arithmetic */
|
5231 |
GEN_SPEOP_ARITH2(evaddw); |
5232 |
GEN_SPEOP_ARITH2(evsubfw); |
5233 |
GEN_SPEOP_ARITH1(evabs); |
5234 |
GEN_SPEOP_ARITH1(evneg); |
5235 |
GEN_SPEOP_ARITH1(evextsb); |
5236 |
GEN_SPEOP_ARITH1(evextsh); |
5237 |
GEN_SPEOP_ARITH1(evrndw); |
5238 |
GEN_SPEOP_ARITH1(evcntlzw); |
5239 |
GEN_SPEOP_ARITH1(evcntlsw); |
5240 |
static inline void gen_brinc (DisasContext *ctx) |
5241 |
{ |
5242 |
/* Note: brinc is usable even if SPE is disabled */
|
5243 |
gen_op_load_gpr64_T0(rA(ctx->opcode)); |
5244 |
gen_op_load_gpr64_T1(rB(ctx->opcode)); |
5245 |
gen_op_brinc(); |
5246 |
gen_op_store_T0_gpr64(rD(ctx->opcode)); |
5247 |
} |
5248 |
|
5249 |
#define GEN_SPEOP_ARITH_IMM2(name) \
|
5250 |
static inline void gen_##name##i (DisasContext *ctx) \ |
5251 |
{ \ |
5252 |
if (unlikely(!ctx->spe_enabled)) { \
|
5253 |
GEN_EXCP_NO_AP(ctx); \ |
5254 |
return; \
|
5255 |
} \ |
5256 |
gen_op_load_gpr64_T0(rB(ctx->opcode)); \ |
5257 |
gen_op_splatwi_T1_64(rA(ctx->opcode)); \ |
5258 |
gen_op_##name(); \ |
5259 |
gen_op_store_T0_gpr64(rD(ctx->opcode)); \ |
5260 |
} |
5261 |
|
5262 |
#define GEN_SPEOP_LOGIC_IMM2(name) \
|
5263 |
static inline void gen_##name##i (DisasContext *ctx) \ |
5264 |
{ \ |
5265 |
if (unlikely(!ctx->spe_enabled)) { \
|
5266 |
GEN_EXCP_NO_AP(ctx); \ |
5267 |
return; \
|
5268 |
} \ |
5269 |
gen_op_load_gpr64_T0(rA(ctx->opcode)); \ |
5270 |
gen_op_splatwi_T1_64(rB(ctx->opcode)); \ |
5271 |
gen_op_##name(); \ |
5272 |
gen_op_store_T0_gpr64(rD(ctx->opcode)); \ |
5273 |
} |
5274 |
|
5275 |
GEN_SPEOP_ARITH_IMM2(evaddw); |
5276 |
#define gen_evaddiw gen_evaddwi
|
5277 |
GEN_SPEOP_ARITH_IMM2(evsubfw); |
5278 |
#define gen_evsubifw gen_evsubfwi
|
5279 |
GEN_SPEOP_LOGIC_IMM2(evslw); |
5280 |
GEN_SPEOP_LOGIC_IMM2(evsrwu); |
5281 |
#define gen_evsrwis gen_evsrwsi
|
5282 |
GEN_SPEOP_LOGIC_IMM2(evsrws); |
5283 |
#define gen_evsrwiu gen_evsrwui
|
5284 |
GEN_SPEOP_LOGIC_IMM2(evrlw); |
5285 |
|
5286 |
static inline void gen_evsplati (DisasContext *ctx) |
5287 |
{ |
5288 |
int32_t imm = (int32_t)(rA(ctx->opcode) << 27) >> 27; |
5289 |
|
5290 |
gen_op_splatwi_T0_64(imm); |
5291 |
gen_op_store_T0_gpr64(rD(ctx->opcode)); |
5292 |
} |
5293 |
|
5294 |
static inline void gen_evsplatfi (DisasContext *ctx) |
5295 |
{ |
5296 |
uint32_t imm = rA(ctx->opcode) << 27;
|
5297 |
|
5298 |
gen_op_splatwi_T0_64(imm); |
5299 |
gen_op_store_T0_gpr64(rD(ctx->opcode)); |
5300 |
} |
5301 |
|
5302 |
/* Comparison */
|
5303 |
GEN_SPEOP_COMP(evcmpgtu); |
5304 |
GEN_SPEOP_COMP(evcmpgts); |
5305 |
GEN_SPEOP_COMP(evcmpltu); |
5306 |
GEN_SPEOP_COMP(evcmplts); |
5307 |
GEN_SPEOP_COMP(evcmpeq); |
5308 |
|
5309 |
GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, PPC_SPE); //// |
5310 |
GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, PPC_SPE); |
5311 |
GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, PPC_SPE); //// |
5312 |
GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, PPC_SPE); |
5313 |
GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, PPC_SPE); //// |
5314 |
GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, PPC_SPE); //// |
5315 |
GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, PPC_SPE); //// |
5316 |
GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x00000000, PPC_SPE); // |
5317 |
GEN_SPE(speundef, evand, 0x08, 0x08, 0x00000000, PPC_SPE); //// |
5318 |
GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, PPC_SPE); //// |
5319 |
GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, PPC_SPE); //// |
5320 |
GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, PPC_SPE); //// |
5321 |
GEN_SPE(speundef, evorc, 0x0D, 0x08, 0x00000000, PPC_SPE); //// |
5322 |
GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, PPC_SPE); //// |
5323 |
GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, PPC_SPE); //// |
5324 |
GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, PPC_SPE); |
5325 |
GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, PPC_SPE); //// |
5326 |
GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, PPC_SPE); |
5327 |
GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, PPC_SPE); // |
5328 |
GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, PPC_SPE); |
5329 |
GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, PPC_SPE); //// |
5330 |
GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, PPC_SPE); //// |
5331 |
GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, PPC_SPE); //// |
5332 |
GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, PPC_SPE); //// |
5333 |
GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, PPC_SPE); //// |
5334 |
|
5335 |
static inline void gen_evsel (DisasContext *ctx) |
5336 |
{ |
5337 |
if (unlikely(!ctx->spe_enabled)) {
|
5338 |
GEN_EXCP_NO_AP(ctx); |
5339 |
return;
|
5340 |
} |
5341 |
gen_op_load_crf_T0(ctx->opcode & 0x7);
|
5342 |
gen_op_load_gpr64_T0(rA(ctx->opcode)); |
5343 |
gen_op_load_gpr64_T1(rB(ctx->opcode)); |
5344 |
gen_op_evsel(); |
5345 |
gen_op_store_T0_gpr64(rD(ctx->opcode)); |
5346 |
} |
5347 |
|
5348 |
GEN_HANDLER(evsel0, 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE) |
5349 |
{ |
5350 |
gen_evsel(ctx); |
5351 |
} |
5352 |
GEN_HANDLER(evsel1, 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE) |
5353 |
{ |
5354 |
gen_evsel(ctx); |
5355 |
} |
5356 |
GEN_HANDLER(evsel2, 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE) |
5357 |
{ |
5358 |
gen_evsel(ctx); |
5359 |
} |
5360 |
GEN_HANDLER(evsel3, 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE) |
5361 |
{ |
5362 |
gen_evsel(ctx); |
5363 |
} |
5364 |
|
5365 |
/* Load and stores */
|
5366 |
#if defined(TARGET_PPC64)
|
5367 |
/* In that case, we already have 64 bits load & stores
|
5368 |
* so, spe_ldd is equivalent to ld and spe_std is equivalent to std
|
5369 |
*/
|
5370 |
#if defined(CONFIG_USER_ONLY)
|
5371 |
#define gen_op_spe_ldd_raw gen_op_ld_raw
|
5372 |
#define gen_op_spe_ldd_64_raw gen_op_ld_64_raw
|
5373 |
#define gen_op_spe_ldd_le_raw gen_op_ld_le_raw
|
5374 |
#define gen_op_spe_ldd_le_64_raw gen_op_ld_le_64_raw
|
5375 |
#define gen_op_spe_stdd_raw gen_op_ld_raw
|
5376 |
#define gen_op_spe_stdd_64_raw gen_op_std_64_raw
|
5377 |
#define gen_op_spe_stdd_le_raw gen_op_std_le_raw
|
5378 |
#define gen_op_spe_stdd_le_64_raw gen_op_std_le_64_raw
|
5379 |
#else /* defined(CONFIG_USER_ONLY) */ |
5380 |
#define gen_op_spe_ldd_kernel gen_op_ld_kernel
|
5381 |
#define gen_op_spe_ldd_64_kernel gen_op_ld_64_kernel
|
5382 |
#define gen_op_spe_ldd_le_kernel gen_op_ld_kernel
|
5383 |
#define gen_op_spe_ldd_le_64_kernel gen_op_ld_64_kernel
|
5384 |
#define gen_op_spe_ldd_user gen_op_ld_user
|
5385 |
#define gen_op_spe_ldd_64_user gen_op_ld_64_user
|
5386 |
#define gen_op_spe_ldd_le_user gen_op_ld_le_user
|
5387 |
#define gen_op_spe_ldd_le_64_user gen_op_ld_le_64_user
|
5388 |
#define gen_op_spe_stdd_kernel gen_op_std_kernel
|
5389 |
#define gen_op_spe_stdd_64_kernel gen_op_std_64_kernel
|
5390 |
#define gen_op_spe_stdd_le_kernel gen_op_std_kernel
|
5391 |
#define gen_op_spe_stdd_le_64_kernel gen_op_std_64_kernel
|
5392 |
#define gen_op_spe_stdd_user gen_op_std_user
|
5393 |
#define gen_op_spe_stdd_64_user gen_op_std_64_user
|
5394 |
#define gen_op_spe_stdd_le_user gen_op_std_le_user
|
5395 |
#define gen_op_spe_stdd_le_64_user gen_op_std_le_64_user
|
5396 |
#endif /* defined(CONFIG_USER_ONLY) */ |
5397 |
#endif /* defined(TARGET_PPC64) */ |
5398 |
GEN_SPEOP_LDST(dd, 3);
|
5399 |
GEN_SPEOP_LDST(dw, 3);
|
5400 |
GEN_SPEOP_LDST(dh, 3);
|
5401 |
GEN_SPEOP_LDST(whe, 2);
|
5402 |
GEN_SPEOP_LD(whou, 2);
|
5403 |
GEN_SPEOP_LD(whos, 2);
|
5404 |
GEN_SPEOP_ST(who, 2);
|
5405 |
|
5406 |
#if defined(TARGET_PPC64)
|
5407 |
/* In that case, spe_stwwo is equivalent to stw */
|
5408 |
#if defined(CONFIG_USER_ONLY)
|
5409 |
#define gen_op_spe_stwwo_raw gen_op_stw_raw
|
5410 |
#define gen_op_spe_stwwo_le_raw gen_op_stw_le_raw
|
5411 |
#define gen_op_spe_stwwo_64_raw gen_op_stw_64_raw
|
5412 |
#define gen_op_spe_stwwo_le_64_raw gen_op_stw_le_64_raw
|
5413 |
#else
|
5414 |
#define gen_op_spe_stwwo_user gen_op_stw_user
|
5415 |
#define gen_op_spe_stwwo_le_user gen_op_stw_le_user
|
5416 |
#define gen_op_spe_stwwo_64_user gen_op_stw_64_user
|
5417 |
#define gen_op_spe_stwwo_le_64_user gen_op_stw_le_64_user
|
5418 |
#define gen_op_spe_stwwo_kernel gen_op_stw_kernel
|
5419 |
#define gen_op_spe_stwwo_le_kernel gen_op_stw_le_kernel
|
5420 |
#define gen_op_spe_stwwo_64_kernel gen_op_stw_64_kernel
|
5421 |
#define gen_op_spe_stwwo_le_64_kernel gen_op_stw_le_64_kernel
|
5422 |
#endif
|
5423 |
#endif
|
5424 |
#define _GEN_OP_SPE_STWWE(suffix) \
|
5425 |
static inline void gen_op_spe_stwwe_##suffix (void) \ |
5426 |
{ \ |
5427 |
gen_op_srli32_T1_64(); \ |
5428 |
gen_op_spe_stwwo_##suffix(); \ |
5429 |
} |
5430 |
#define _GEN_OP_SPE_STWWE_LE(suffix) \
|
5431 |
static inline void gen_op_spe_stwwe_le_##suffix (void) \ |
5432 |
{ \ |
5433 |
gen_op_srli32_T1_64(); \ |
5434 |
gen_op_spe_stwwo_le_##suffix(); \ |
5435 |
} |
5436 |
#if defined(TARGET_PPC64)
|
5437 |
#define GEN_OP_SPE_STWWE(suffix) \
|
5438 |
_GEN_OP_SPE_STWWE(suffix); \ |
5439 |
_GEN_OP_SPE_STWWE_LE(suffix); \ |
5440 |
static inline void gen_op_spe_stwwe_64_##suffix (void) \ |
5441 |
{ \ |
5442 |
gen_op_srli32_T1_64(); \ |
5443 |
gen_op_spe_stwwo_64_##suffix(); \ |
5444 |
} \ |
5445 |
static inline void gen_op_spe_stwwe_le_64_##suffix (void) \ |
5446 |
{ \ |
5447 |
gen_op_srli32_T1_64(); \ |
5448 |
gen_op_spe_stwwo_le_64_##suffix(); \ |
5449 |
} |
5450 |
#else
|
5451 |
#define GEN_OP_SPE_STWWE(suffix) \
|
5452 |
_GEN_OP_SPE_STWWE(suffix); \ |
5453 |
_GEN_OP_SPE_STWWE_LE(suffix) |
5454 |
#endif
|
5455 |
#if defined(CONFIG_USER_ONLY)
|
5456 |
GEN_OP_SPE_STWWE(raw); |
5457 |
#else /* defined(CONFIG_USER_ONLY) */ |
5458 |
GEN_OP_SPE_STWWE(kernel); |
5459 |
GEN_OP_SPE_STWWE(user); |
5460 |
#endif /* defined(CONFIG_USER_ONLY) */ |
5461 |
GEN_SPEOP_ST(wwe, 2);
|
5462 |
GEN_SPEOP_ST(wwo, 2);
|
5463 |
|
5464 |
#define GEN_SPE_LDSPLAT(name, op, suffix) \
|
5465 |
static inline void gen_op_spe_l##name##_##suffix (void) \ |
5466 |
{ \ |
5467 |
gen_op_##op##_##suffix(); \ |
5468 |
gen_op_splatw_T1_64(); \ |
5469 |
} |
5470 |
|
5471 |
#define GEN_OP_SPE_LHE(suffix) \
|
5472 |
static inline void gen_op_spe_lhe_##suffix (void) \ |
5473 |
{ \ |
5474 |
gen_op_spe_lh_##suffix(); \ |
5475 |
gen_op_sli16_T1_64(); \ |
5476 |
} |
5477 |
|
5478 |
#define GEN_OP_SPE_LHX(suffix) \
|
5479 |
static inline void gen_op_spe_lhx_##suffix (void) \ |
5480 |
{ \ |
5481 |
gen_op_spe_lh_##suffix(); \ |
5482 |
gen_op_extsh_T1_64(); \ |
5483 |
} |
5484 |
|
5485 |
#if defined(CONFIG_USER_ONLY)
|
5486 |
GEN_OP_SPE_LHE(raw); |
5487 |
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, raw); |
5488 |
GEN_OP_SPE_LHE(le_raw); |
5489 |
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_raw); |
5490 |
GEN_SPE_LDSPLAT(hhousplat, spe_lh, raw); |
5491 |
GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_raw); |
5492 |
GEN_OP_SPE_LHX(raw); |
5493 |
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, raw); |
5494 |
GEN_OP_SPE_LHX(le_raw); |
5495 |
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_raw); |
5496 |
#if defined(TARGET_PPC64)
|
5497 |
GEN_OP_SPE_LHE(64_raw);
|
5498 |
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_raw);
|
5499 |
GEN_OP_SPE_LHE(le_64_raw); |
5500 |
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_raw); |
5501 |
GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_raw);
|
5502 |
GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_raw); |
5503 |
GEN_OP_SPE_LHX(64_raw);
|
5504 |
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_raw);
|
5505 |
GEN_OP_SPE_LHX(le_64_raw); |
5506 |
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_raw); |
5507 |
#endif
|
5508 |
#else
|
5509 |
GEN_OP_SPE_LHE(kernel); |
5510 |
GEN_OP_SPE_LHE(user); |
5511 |
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, kernel); |
5512 |
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, user); |
5513 |
GEN_OP_SPE_LHE(le_kernel); |
5514 |
GEN_OP_SPE_LHE(le_user); |
5515 |
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_kernel); |
5516 |
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_user); |
5517 |
GEN_SPE_LDSPLAT(hhousplat, spe_lh, kernel); |
5518 |
GEN_SPE_LDSPLAT(hhousplat, spe_lh, user); |
5519 |
GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_kernel); |
5520 |
GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_user); |
5521 |
GEN_OP_SPE_LHX(kernel); |
5522 |
GEN_OP_SPE_LHX(user); |
5523 |
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, kernel); |
5524 |
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, user); |
5525 |
GEN_OP_SPE_LHX(le_kernel); |
5526 |
GEN_OP_SPE_LHX(le_user); |
5527 |
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_kernel); |
5528 |
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_user); |
5529 |
#if defined(TARGET_PPC64)
|
5530 |
GEN_OP_SPE_LHE(64_kernel);
|
5531 |
GEN_OP_SPE_LHE(64_user);
|
5532 |
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_kernel);
|
5533 |
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_user);
|
5534 |
GEN_OP_SPE_LHE(le_64_kernel); |
5535 |
GEN_OP_SPE_LHE(le_64_user); |
5536 |
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_kernel); |
5537 |
GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_user); |
5538 |
GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_kernel);
|
5539 |
GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_user);
|
5540 |
GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_kernel); |
5541 |
GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_user); |
5542 |
GEN_OP_SPE_LHX(64_kernel);
|
5543 |
GEN_OP_SPE_LHX(64_user);
|
5544 |
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_kernel);
|
5545 |
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_user);
|
5546 |
GEN_OP_SPE_LHX(le_64_kernel); |
5547 |
GEN_OP_SPE_LHX(le_64_user); |
5548 |
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_kernel); |
5549 |
GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_user); |
5550 |
#endif
|
5551 |
#endif
|
5552 |
GEN_SPEOP_LD(hhesplat, 1);
|
5553 |
GEN_SPEOP_LD(hhousplat, 1);
|
5554 |
GEN_SPEOP_LD(hhossplat, 1);
|
5555 |
GEN_SPEOP_LD(wwsplat, 2);
|
5556 |
GEN_SPEOP_LD(whsplat, 2);
|
5557 |
|
5558 |
GEN_SPE(evlddx, evldd, 0x00, 0x0C, 0x00000000, PPC_SPE); // |
5559 |
GEN_SPE(evldwx, evldw, 0x01, 0x0C, 0x00000000, PPC_SPE); // |
5560 |
GEN_SPE(evldhx, evldh, 0x02, 0x0C, 0x00000000, PPC_SPE); // |
5561 |
GEN_SPE(evlhhesplatx, evlhhesplat, 0x04, 0x0C, 0x00000000, PPC_SPE); // |
5562 |
GEN_SPE(evlhhousplatx, evlhhousplat, 0x06, 0x0C, 0x00000000, PPC_SPE); // |
5563 |
GEN_SPE(evlhhossplatx, evlhhossplat, 0x07, 0x0C, 0x00000000, PPC_SPE); // |
5564 |
GEN_SPE(evlwhex, evlwhe, 0x08, 0x0C, 0x00000000, PPC_SPE); // |
5565 |
GEN_SPE(evlwhoux, evlwhou, 0x0A, 0x0C, 0x00000000, PPC_SPE); // |
5566 |
GEN_SPE(evlwhosx, evlwhos, 0x0B, 0x0C, 0x00000000, PPC_SPE); // |
5567 |
GEN_SPE(evlwwsplatx, evlwwsplat, 0x0C, 0x0C, 0x00000000, PPC_SPE); // |
5568 |
GEN_SPE(evlwhsplatx, evlwhsplat, 0x0E, 0x0C, 0x00000000, PPC_SPE); // |
5569 |
GEN_SPE(evstddx, evstdd, 0x10, 0x0C, 0x00000000, PPC_SPE); // |
5570 |
GEN_SPE(evstdwx, evstdw, 0x11, 0x0C, 0x00000000, PPC_SPE); // |
5571 |
GEN_SPE(evstdhx, evstdh, 0x12, 0x0C, 0x00000000, PPC_SPE); // |
5572 |
GEN_SPE(evstwhex, evstwhe, 0x18, 0x0C, 0x00000000, PPC_SPE); // |
5573 |
GEN_SPE(evstwhox, evstwho, 0x1A, 0x0C, 0x00000000, PPC_SPE); // |
5574 |
GEN_SPE(evstwwex, evstwwe, 0x1C, 0x0C, 0x00000000, PPC_SPE); // |
5575 |
GEN_SPE(evstwwox, evstwwo, 0x1E, 0x0C, 0x00000000, PPC_SPE); // |
5576 |
|
5577 |
/* Multiply and add - TODO */
|
5578 |
#if 0
|
5579 |
GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0x00000000, PPC_SPE);
|
5580 |
GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0x00000000, PPC_SPE);
|
5581 |
GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, PPC_SPE);
|
5582 |
GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0x00000000, PPC_SPE);
|
5583 |
GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, PPC_SPE);
|
5584 |
GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0x00000000, PPC_SPE);
|
5585 |
GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0x00000000, PPC_SPE);
|
5586 |
GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0x00000000, PPC_SPE);
|
5587 |
GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, PPC_SPE);
|
5588 |
GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0x00000000, PPC_SPE);
|
5589 |
GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, PPC_SPE);
|
5590 |
GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0x00000000, PPC_SPE);
|
5591 |
|
5592 |
GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0x00000000, PPC_SPE);
|
5593 |
GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, PPC_SPE);
|
5594 |
GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, PPC_SPE);
|
5595 |
GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0x00000000, PPC_SPE);
|
5596 |
GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0x00000000, PPC_SPE);
|
5597 |
GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, PPC_SPE);
|
5598 |
GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0x00000000, PPC_SPE);
|
5599 |
GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0x00000000, PPC_SPE);
|
5600 |
GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, PPC_SPE);
|
5601 |
GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, PPC_SPE);
|
5602 |
GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0x00000000, PPC_SPE);
|
5603 |
GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0x00000000, PPC_SPE);
|
5604 |
GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, PPC_SPE);
|
5605 |
GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0x00000000, PPC_SPE);
|
5606 |
|
5607 |
GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, PPC_SPE);
|
5608 |
GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, PPC_SPE);
|
5609 |
GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, PPC_SPE);
|
5610 |
GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, PPC_SPE);
|
5611 |
GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, PPC_SPE);
|
5612 |
GEN_SPE(evmra, speundef, 0x07, 0x13, 0x0000F800, PPC_SPE);
|
5613 |
|
5614 |
GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, PPC_SPE);
|
5615 |
GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0x00000000, PPC_SPE);
|
5616 |
GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, PPC_SPE);
|
5617 |
GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0x00000000, PPC_SPE);
|
5618 |
GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, PPC_SPE);
|
5619 |
GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0x00000000, PPC_SPE);
|
5620 |
GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, PPC_SPE);
|
5621 |
GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0x00000000, PPC_SPE);
|
5622 |
GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, PPC_SPE);
|
5623 |
GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0x00000000, PPC_SPE);
|
5624 |
GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, PPC_SPE);
|
5625 |
GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0x00000000, PPC_SPE);
|
5626 |
|
5627 |
GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, PPC_SPE);
|
5628 |
GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, PPC_SPE);
|
5629 |
GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0x00000000, PPC_SPE);
|
5630 |
GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, PPC_SPE);
|
5631 |
GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0x00000000, PPC_SPE);
|
5632 |
|
5633 |
GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, PPC_SPE);
|
5634 |
GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0x00000000, PPC_SPE);
|
5635 |
GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, PPC_SPE);
|
5636 |
GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0x00000000, PPC_SPE);
|
5637 |
GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, PPC_SPE);
|
5638 |
GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0x00000000, PPC_SPE);
|
5639 |
GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, PPC_SPE);
|
5640 |
GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0x00000000, PPC_SPE);
|
5641 |
GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, PPC_SPE);
|
5642 |
GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0x00000000, PPC_SPE);
|
5643 |
GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, PPC_SPE);
|
5644 |
GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0x00000000, PPC_SPE);
|
5645 |
|
5646 |
GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, PPC_SPE);
|
5647 |
GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, PPC_SPE);
|
5648 |
GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0x00000000, PPC_SPE);
|
5649 |
GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, PPC_SPE);
|
5650 |
GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0x00000000, PPC_SPE);
|
5651 |
#endif
|
5652 |
|
5653 |
/*** SPE floating-point extension ***/
|
5654 |
#define GEN_SPEFPUOP_CONV(name) \
|
5655 |
static inline void gen_##name (DisasContext *ctx) \ |
5656 |
{ \ |
5657 |
gen_op_load_gpr64_T0(rB(ctx->opcode)); \ |
5658 |
gen_op_##name(); \ |
5659 |
gen_op_store_T0_gpr64(rD(ctx->opcode)); \ |
5660 |
} |
5661 |
|
5662 |
/* Single precision floating-point vectors operations */
|
5663 |
/* Arithmetic */
|
5664 |
GEN_SPEOP_ARITH2(evfsadd); |
5665 |
GEN_SPEOP_ARITH2(evfssub); |
5666 |
GEN_SPEOP_ARITH2(evfsmul); |
5667 |
GEN_SPEOP_ARITH2(evfsdiv); |
5668 |
GEN_SPEOP_ARITH1(evfsabs); |
5669 |
GEN_SPEOP_ARITH1(evfsnabs); |
5670 |
GEN_SPEOP_ARITH1(evfsneg); |
5671 |
/* Conversion */
|
5672 |
GEN_SPEFPUOP_CONV(evfscfui); |
5673 |
GEN_SPEFPUOP_CONV(evfscfsi); |
5674 |
GEN_SPEFPUOP_CONV(evfscfuf); |
5675 |
GEN_SPEFPUOP_CONV(evfscfsf); |
5676 |
GEN_SPEFPUOP_CONV(evfsctui); |
5677 |
GEN_SPEFPUOP_CONV(evfsctsi); |
5678 |
GEN_SPEFPUOP_CONV(evfsctuf); |
5679 |
GEN_SPEFPUOP_CONV(evfsctsf); |
5680 |
GEN_SPEFPUOP_CONV(evfsctuiz); |
5681 |
GEN_SPEFPUOP_CONV(evfsctsiz); |
5682 |
/* Comparison */
|
5683 |
GEN_SPEOP_COMP(evfscmpgt); |
5684 |
GEN_SPEOP_COMP(evfscmplt); |
5685 |
GEN_SPEOP_COMP(evfscmpeq); |
5686 |
GEN_SPEOP_COMP(evfststgt); |
5687 |
GEN_SPEOP_COMP(evfststlt); |
5688 |
GEN_SPEOP_COMP(evfststeq); |
5689 |
|
5690 |
/* Opcodes definitions */
|
5691 |
GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, PPC_SPEFPU); // |
5692 |
GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, PPC_SPEFPU); // |
5693 |
GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, PPC_SPEFPU); // |
5694 |
GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, PPC_SPEFPU); // |
5695 |
GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, PPC_SPEFPU); // |
5696 |
GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, PPC_SPEFPU); // |
5697 |
GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, PPC_SPEFPU); // |
5698 |
GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, PPC_SPEFPU); // |
5699 |
GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, PPC_SPEFPU); // |
5700 |
GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, PPC_SPEFPU); // |
5701 |
GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, PPC_SPEFPU); // |
5702 |
GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, PPC_SPEFPU); // |
5703 |
GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, PPC_SPEFPU); // |
5704 |
GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, PPC_SPEFPU); // |
5705 |
|
5706 |
/* Single precision floating-point operations */
|
5707 |
/* Arithmetic */
|
5708 |
GEN_SPEOP_ARITH2(efsadd); |
5709 |
GEN_SPEOP_ARITH2(efssub); |
5710 |
GEN_SPEOP_ARITH2(efsmul); |
5711 |
GEN_SPEOP_ARITH2(efsdiv); |
5712 |
GEN_SPEOP_ARITH1(efsabs); |
5713 |
GEN_SPEOP_ARITH1(efsnabs); |
5714 |
GEN_SPEOP_ARITH1(efsneg); |
5715 |
/* Conversion */
|
5716 |
GEN_SPEFPUOP_CONV(efscfui); |
5717 |
GEN_SPEFPUOP_CONV(efscfsi); |
5718 |
GEN_SPEFPUOP_CONV(efscfuf); |
5719 |
GEN_SPEFPUOP_CONV(efscfsf); |
5720 |
GEN_SPEFPUOP_CONV(efsctui); |
5721 |
GEN_SPEFPUOP_CONV(efsctsi); |
5722 |
GEN_SPEFPUOP_CONV(efsctuf); |
5723 |
GEN_SPEFPUOP_CONV(efsctsf); |
5724 |
GEN_SPEFPUOP_CONV(efsctuiz); |
5725 |
GEN_SPEFPUOP_CONV(efsctsiz); |
5726 |
GEN_SPEFPUOP_CONV(efscfd); |
5727 |
/* Comparison */
|
5728 |
GEN_SPEOP_COMP(efscmpgt); |
5729 |
GEN_SPEOP_COMP(efscmplt); |
5730 |
GEN_SPEOP_COMP(efscmpeq); |
5731 |
GEN_SPEOP_COMP(efststgt); |
5732 |
GEN_SPEOP_COMP(efststlt); |
5733 |
GEN_SPEOP_COMP(efststeq); |
5734 |
|
5735 |
/* Opcodes definitions */
|
5736 |
GEN_SPE(efsadd, efssub, 0x00, 0x0A, 0x00000000, PPC_SPEFPU); // |
5737 |
GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, PPC_SPEFPU); // |
5738 |
GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, PPC_SPEFPU); // |
5739 |
GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, PPC_SPEFPU); // |
5740 |
GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, PPC_SPEFPU); // |
5741 |
GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, PPC_SPEFPU); // |
5742 |
GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, PPC_SPEFPU); // |
5743 |
GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, PPC_SPEFPU); // |
5744 |
GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, PPC_SPEFPU); // |
5745 |
GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, PPC_SPEFPU); // |
5746 |
GEN_SPE(efsctuiz, efsctsiz, 0x0C, 0x0B, 0x00180000, PPC_SPEFPU); // |
5747 |
GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, PPC_SPEFPU); // |
5748 |
GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, PPC_SPEFPU); // |
5749 |
|
5750 |
/* Double precision floating-point operations */
|
5751 |
/* Arithmetic */
|
5752 |
GEN_SPEOP_ARITH2(efdadd); |
5753 |
GEN_SPEOP_ARITH2(efdsub); |
5754 |
GEN_SPEOP_ARITH2(efdmul); |
5755 |
GEN_SPEOP_ARITH2(efddiv); |
5756 |
GEN_SPEOP_ARITH1(efdabs); |
5757 |
GEN_SPEOP_ARITH1(efdnabs); |
5758 |
GEN_SPEOP_ARITH1(efdneg); |
5759 |
/* Conversion */
|
5760 |
|
5761 |
GEN_SPEFPUOP_CONV(efdcfui); |
5762 |
GEN_SPEFPUOP_CONV(efdcfsi); |
5763 |
GEN_SPEFPUOP_CONV(efdcfuf); |
5764 |
GEN_SPEFPUOP_CONV(efdcfsf); |
5765 |
GEN_SPEFPUOP_CONV(efdctui); |
5766 |
GEN_SPEFPUOP_CONV(efdctsi); |
5767 |
GEN_SPEFPUOP_CONV(efdctuf); |
5768 |
GEN_SPEFPUOP_CONV(efdctsf); |
5769 |
GEN_SPEFPUOP_CONV(efdctuiz); |
5770 |
GEN_SPEFPUOP_CONV(efdctsiz); |
5771 |
GEN_SPEFPUOP_CONV(efdcfs); |
5772 |
GEN_SPEFPUOP_CONV(efdcfuid); |
5773 |
GEN_SPEFPUOP_CONV(efdcfsid); |
5774 |
GEN_SPEFPUOP_CONV(efdctuidz); |
5775 |
GEN_SPEFPUOP_CONV(efdctsidz); |
5776 |
/* Comparison */
|
5777 |
GEN_SPEOP_COMP(efdcmpgt); |
5778 |
GEN_SPEOP_COMP(efdcmplt); |
5779 |
GEN_SPEOP_COMP(efdcmpeq); |
5780 |
GEN_SPEOP_COMP(efdtstgt); |
5781 |
GEN_SPEOP_COMP(efdtstlt); |
5782 |
GEN_SPEOP_COMP(efdtsteq); |
5783 |
|
5784 |
/* Opcodes definitions */
|
5785 |
GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, PPC_SPEFPU); // |
5786 |
GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, PPC_SPEFPU); // |
5787 |
GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, PPC_SPEFPU); // |
5788 |
GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, PPC_SPEFPU); // |
5789 |
GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, PPC_SPEFPU); // |
5790 |
GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, PPC_SPEFPU); // |
5791 |
GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, PPC_SPEFPU); // |
5792 |
GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, PPC_SPEFPU); // |
5793 |
GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, PPC_SPEFPU); // |
5794 |
GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, PPC_SPEFPU); // |
5795 |
GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, PPC_SPEFPU); // |
5796 |
GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, PPC_SPEFPU); // |
5797 |
GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, PPC_SPEFPU); // |
5798 |
GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, PPC_SPEFPU); // |
5799 |
GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, PPC_SPEFPU); // |
5800 |
GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, PPC_SPEFPU); // |
5801 |
#endif
|
5802 |
|
5803 |
/* End opcode list */
|
5804 |
GEN_OPCODE_MARK(end); |
5805 |
|
5806 |
#include "translate_init.c" |
5807 |
|
5808 |
/*****************************************************************************/
|
5809 |
/* Misc PowerPC helpers */
|
5810 |
static inline uint32_t load_xer (CPUState *env) |
5811 |
{ |
5812 |
return (xer_so << XER_SO) |
|
5813 |
(xer_ov << XER_OV) | |
5814 |
(xer_ca << XER_CA) | |
5815 |
(xer_bc << XER_BC) | |
5816 |
(xer_cmp << XER_CMP); |
5817 |
} |
5818 |
|
5819 |
void cpu_dump_state (CPUState *env, FILE *f,
|
5820 |
int (*cpu_fprintf)(FILE *f, const char *fmt, ...), |
5821 |
int flags)
|
5822 |
{ |
5823 |
#if defined(TARGET_PPC64) || 1 |
5824 |
#define FILL "" |
5825 |
#define RGPL 4 |
5826 |
#define RFPL 4 |
5827 |
#else
|
5828 |
#define FILL " " |
5829 |
#define RGPL 8 |
5830 |
#define RFPL 4 |
5831 |
#endif
|
5832 |
|
5833 |
int i;
|
5834 |
|
5835 |
cpu_fprintf(f, "NIP " ADDRX " LR " ADDRX " CTR " ADDRX "\n", |
5836 |
env->nip, env->lr, env->ctr); |
5837 |
cpu_fprintf(f, "MSR " REGX FILL " XER %08x " |
5838 |
#if !defined(NO_TIMER_DUMP)
|
5839 |
"TB %08x %08x "
|
5840 |
#if !defined(CONFIG_USER_ONLY)
|
5841 |
"DECR %08x"
|
5842 |
#endif
|
5843 |
#endif
|
5844 |
"\n",
|
5845 |
do_load_msr(env), load_xer(env) |
5846 |
#if !defined(NO_TIMER_DUMP)
|
5847 |
, cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env) |
5848 |
#if !defined(CONFIG_USER_ONLY)
|
5849 |
, cpu_ppc_load_decr(env) |
5850 |
#endif
|
5851 |
#endif
|
5852 |
); |
5853 |
for (i = 0; i < 32; i++) { |
5854 |
if ((i & (RGPL - 1)) == 0) |
5855 |
cpu_fprintf(f, "GPR%02d", i);
|
5856 |
cpu_fprintf(f, " " REGX, (target_ulong)env->gpr[i]);
|
5857 |
if ((i & (RGPL - 1)) == (RGPL - 1)) |
5858 |
cpu_fprintf(f, "\n");
|
5859 |
} |
5860 |
cpu_fprintf(f, "CR ");
|
5861 |
for (i = 0; i < 8; i++) |
5862 |
cpu_fprintf(f, "%01x", env->crf[i]);
|
5863 |
cpu_fprintf(f, " [");
|
5864 |
for (i = 0; i < 8; i++) { |
5865 |
char a = '-'; |
5866 |
if (env->crf[i] & 0x08) |
5867 |
a = 'L';
|
5868 |
else if (env->crf[i] & 0x04) |
5869 |
a = 'G';
|
5870 |
else if (env->crf[i] & 0x02) |
5871 |
a = 'E';
|
5872 |
cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' '); |
5873 |
} |
5874 |
cpu_fprintf(f, " ] " FILL "RES " REGX "\n", env->reserve); |
5875 |
for (i = 0; i < 32; i++) { |
5876 |
if ((i & (RFPL - 1)) == 0) |
5877 |
cpu_fprintf(f, "FPR%02d", i);
|
5878 |
cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
|
5879 |
if ((i & (RFPL - 1)) == (RFPL - 1)) |
5880 |
cpu_fprintf(f, "\n");
|
5881 |
} |
5882 |
cpu_fprintf(f, "SRR0 " REGX " SRR1 " REGX " " FILL FILL FILL |
5883 |
"SDR1 " REGX "\n", |
5884 |
env->spr[SPR_SRR0], env->spr[SPR_SRR1], env->sdr1); |
5885 |
|
5886 |
#undef RGPL
|
5887 |
#undef RFPL
|
5888 |
#undef FILL
|
5889 |
} |
5890 |
|
5891 |
void cpu_dump_statistics (CPUState *env, FILE*f,
|
5892 |
int (*cpu_fprintf)(FILE *f, const char *fmt, ...), |
5893 |
int flags)
|
5894 |
{ |
5895 |
#if defined(DO_PPC_STATISTICS)
|
5896 |
opc_handler_t **t1, **t2, **t3, *handler; |
5897 |
int op1, op2, op3;
|
5898 |
|
5899 |
t1 = env->opcodes; |
5900 |
for (op1 = 0; op1 < 64; op1++) { |
5901 |
handler = t1[op1]; |
5902 |
if (is_indirect_opcode(handler)) {
|
5903 |
t2 = ind_table(handler); |
5904 |
for (op2 = 0; op2 < 32; op2++) { |
5905 |
handler = t2[op2]; |
5906 |
if (is_indirect_opcode(handler)) {
|
5907 |
t3 = ind_table(handler); |
5908 |
for (op3 = 0; op3 < 32; op3++) { |
5909 |
handler = t3[op3]; |
5910 |
if (handler->count == 0) |
5911 |
continue;
|
5912 |
cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
|
5913 |
"%016llx %lld\n",
|
5914 |
op1, op2, op3, op1, (op3 << 5) | op2,
|
5915 |
handler->oname, |
5916 |
handler->count, handler->count); |
5917 |
} |
5918 |
} else {
|
5919 |
if (handler->count == 0) |
5920 |
continue;
|
5921 |
cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
|
5922 |
"%016llx %lld\n",
|
5923 |
op1, op2, op1, op2, handler->oname, |
5924 |
handler->count, handler->count); |
5925 |
} |
5926 |
} |
5927 |
} else {
|
5928 |
if (handler->count == 0) |
5929 |
continue;
|
5930 |
cpu_fprintf(f, "%02x (%02x ) %16s: %016llx %lld\n",
|
5931 |
op1, op1, handler->oname, |
5932 |
handler->count, handler->count); |
5933 |
} |
5934 |
} |
5935 |
#endif
|
5936 |
} |
5937 |
|
5938 |
/*****************************************************************************/
|
5939 |
static inline int gen_intermediate_code_internal (CPUState *env, |
5940 |
TranslationBlock *tb, |
5941 |
int search_pc)
|
5942 |
{ |
5943 |
DisasContext ctx, *ctxp = &ctx; |
5944 |
opc_handler_t **table, *handler; |
5945 |
target_ulong pc_start; |
5946 |
uint16_t *gen_opc_end; |
5947 |
int j, lj = -1; |
5948 |
|
5949 |
pc_start = tb->pc; |
5950 |
gen_opc_ptr = gen_opc_buf; |
5951 |
gen_opc_end = gen_opc_buf + OPC_MAX_SIZE; |
5952 |
gen_opparam_ptr = gen_opparam_buf; |
5953 |
nb_gen_labels = 0;
|
5954 |
ctx.nip = pc_start; |
5955 |
ctx.tb = tb; |
5956 |
ctx.exception = POWERPC_EXCP_NONE; |
5957 |
ctx.spr_cb = env->spr_cb; |
5958 |
#if defined(CONFIG_USER_ONLY)
|
5959 |
ctx.mem_idx = msr_le; |
5960 |
#if defined(TARGET_PPC64)
|
5961 |
ctx.mem_idx |= msr_sf << 1;
|
5962 |
#endif
|
5963 |
#else
|
5964 |
ctx.supervisor = 1 - msr_pr;
|
5965 |
ctx.mem_idx = ((1 - msr_pr) << 1) | msr_le; |
5966 |
#if defined(TARGET_PPC64)
|
5967 |
ctx.mem_idx |= msr_sf << 2;
|
5968 |
#endif
|
5969 |
#endif
|
5970 |
#if defined(TARGET_PPC64)
|
5971 |
ctx.sf_mode = msr_sf; |
5972 |
#endif
|
5973 |
ctx.fpu_enabled = msr_fp; |
5974 |
#if defined(TARGET_PPCEMB)
|
5975 |
ctx.spe_enabled = msr_spe; |
5976 |
#endif
|
5977 |
ctx.singlestep_enabled = env->singlestep_enabled; |
5978 |
#if defined (DO_SINGLE_STEP) && 0 |
5979 |
/* Single step trace mode */
|
5980 |
msr_se = 1;
|
5981 |
#endif
|
5982 |
/* Set env in case of segfault during code fetch */
|
5983 |
while (ctx.exception == POWERPC_EXCP_NONE && gen_opc_ptr < gen_opc_end) {
|
5984 |
if (unlikely(env->nb_breakpoints > 0)) { |
5985 |
for (j = 0; j < env->nb_breakpoints; j++) { |
5986 |
if (env->breakpoints[j] == ctx.nip) {
|
5987 |
gen_update_nip(&ctx, ctx.nip); |
5988 |
gen_op_debug(); |
5989 |
break;
|
5990 |
} |
5991 |
} |
5992 |
} |
5993 |
if (unlikely(search_pc)) {
|
5994 |
j = gen_opc_ptr - gen_opc_buf; |
5995 |
if (lj < j) {
|
5996 |
lj++; |
5997 |
while (lj < j)
|
5998 |
gen_opc_instr_start[lj++] = 0;
|
5999 |
gen_opc_pc[lj] = ctx.nip; |
6000 |
gen_opc_instr_start[lj] = 1;
|
6001 |
} |
6002 |
} |
6003 |
#if defined PPC_DEBUG_DISAS
|
6004 |
if (loglevel & CPU_LOG_TB_IN_ASM) {
|
6005 |
fprintf(logfile, "----------------\n");
|
6006 |
fprintf(logfile, "nip=" ADDRX " super=%d ir=%d\n", |
6007 |
ctx.nip, 1 - msr_pr, msr_ir);
|
6008 |
} |
6009 |
#endif
|
6010 |
ctx.opcode = ldl_code(ctx.nip); |
6011 |
if (msr_le) {
|
6012 |
ctx.opcode = ((ctx.opcode & 0xFF000000) >> 24) | |
6013 |
((ctx.opcode & 0x00FF0000) >> 8) | |
6014 |
((ctx.opcode & 0x0000FF00) << 8) | |
6015 |
((ctx.opcode & 0x000000FF) << 24); |
6016 |
} |
6017 |
#if defined PPC_DEBUG_DISAS
|
6018 |
if (loglevel & CPU_LOG_TB_IN_ASM) {
|
6019 |
fprintf(logfile, "translate opcode %08x (%02x %02x %02x) (%s)\n",
|
6020 |
ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode), |
6021 |
opc3(ctx.opcode), msr_le ? "little" : "big"); |
6022 |
} |
6023 |
#endif
|
6024 |
ctx.nip += 4;
|
6025 |
table = env->opcodes; |
6026 |
handler = table[opc1(ctx.opcode)]; |
6027 |
if (is_indirect_opcode(handler)) {
|
6028 |
table = ind_table(handler); |
6029 |
handler = table[opc2(ctx.opcode)]; |
6030 |
if (is_indirect_opcode(handler)) {
|
6031 |
table = ind_table(handler); |
6032 |
handler = table[opc3(ctx.opcode)]; |
6033 |
} |
6034 |
} |
6035 |
/* Is opcode *REALLY* valid ? */
|
6036 |
if (unlikely(handler->handler == &gen_invalid)) {
|
6037 |
if (loglevel != 0) { |
6038 |
fprintf(logfile, "invalid/unsupported opcode: "
|
6039 |
"%02x - %02x - %02x (%08x) 0x" ADDRX " %d\n", |
6040 |
opc1(ctx.opcode), opc2(ctx.opcode), |
6041 |
opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, msr_ir);
|
6042 |
} else {
|
6043 |
printf("invalid/unsupported opcode: "
|
6044 |
"%02x - %02x - %02x (%08x) 0x" ADDRX " %d\n", |
6045 |
opc1(ctx.opcode), opc2(ctx.opcode), |
6046 |
opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, msr_ir);
|
6047 |
} |
6048 |
} else {
|
6049 |
if (unlikely((ctx.opcode & handler->inval) != 0)) { |
6050 |
if (loglevel != 0) { |
6051 |
fprintf(logfile, "invalid bits: %08x for opcode: "
|
6052 |
"%02x - %02x - %02x (%08x) 0x" ADDRX "\n", |
6053 |
ctx.opcode & handler->inval, opc1(ctx.opcode), |
6054 |
opc2(ctx.opcode), opc3(ctx.opcode), |
6055 |
ctx.opcode, ctx.nip - 4);
|
6056 |
} else {
|
6057 |
printf("invalid bits: %08x for opcode: "
|
6058 |
"%02x - %02x - %02x (%08x) 0x" ADDRX "\n", |
6059 |
ctx.opcode & handler->inval, opc1(ctx.opcode), |
6060 |
opc2(ctx.opcode), opc3(ctx.opcode), |
6061 |
ctx.opcode, ctx.nip - 4);
|
6062 |
} |
6063 |
GEN_EXCP_INVAL(ctxp); |
6064 |
break;
|
6065 |
} |
6066 |
} |
6067 |
(*(handler->handler))(&ctx); |
6068 |
#if defined(DO_PPC_STATISTICS)
|
6069 |
handler->count++; |
6070 |
#endif
|
6071 |
/* Check trace mode exceptions */
|
6072 |
#if 0 // XXX: buggy on embedded PowerPC
|
6073 |
if (unlikely((msr_be && ctx.exception == POWERPC_EXCP_BRANCH) ||
|
6074 |
/* Check in single step trace mode
|
6075 |
* we need to stop except if:
|
6076 |
* - rfi, trap or syscall
|
6077 |
* - first instruction of an exception handler
|
6078 |
*/
|
6079 |
(msr_se && (ctx.nip < 0x100 ||
|
6080 |
ctx.nip > 0xF00 ||
|
6081 |
(ctx.nip & 0xFC) != 0x04) &&
|
6082 |
#if defined(CONFIG_USER_ONLY)
|
6083 |
ctx.exception != POWERPC_EXCP_SYSCALL_USER &&
|
6084 |
#else
|
6085 |
ctx.exception != POWERPC_EXCP_SYSCALL && |
6086 |
#endif
|
6087 |
ctx.exception != POWERPC_EXCP_TRAP))) { |
6088 |
GEN_EXCP(ctxp, POWERPC_EXCP_TRACE, 0);
|
6089 |
} |
6090 |
#endif
|
6091 |
/* if we reach a page boundary or are single stepping, stop
|
6092 |
* generation
|
6093 |
*/
|
6094 |
if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) || |
6095 |
(env->singlestep_enabled))) { |
6096 |
break;
|
6097 |
} |
6098 |
#if defined (DO_SINGLE_STEP)
|
6099 |
break;
|
6100 |
#endif
|
6101 |
} |
6102 |
if (ctx.exception == POWERPC_EXCP_NONE) {
|
6103 |
gen_goto_tb(&ctx, 0, ctx.nip);
|
6104 |
} else if (ctx.exception != POWERPC_EXCP_BRANCH) { |
6105 |
gen_op_reset_T0(); |
6106 |
/* Generate the return instruction */
|
6107 |
gen_op_exit_tb(); |
6108 |
} |
6109 |
*gen_opc_ptr = INDEX_op_end; |
6110 |
if (unlikely(search_pc)) {
|
6111 |
j = gen_opc_ptr - gen_opc_buf; |
6112 |
lj++; |
6113 |
while (lj <= j)
|
6114 |
gen_opc_instr_start[lj++] = 0;
|
6115 |
} else {
|
6116 |
tb->size = ctx.nip - pc_start; |
6117 |
} |
6118 |
#if defined(DEBUG_DISAS)
|
6119 |
if (loglevel & CPU_LOG_TB_CPU) {
|
6120 |
fprintf(logfile, "---------------- excp: %04x\n", ctx.exception);
|
6121 |
cpu_dump_state(env, logfile, fprintf, 0);
|
6122 |
} |
6123 |
if (loglevel & CPU_LOG_TB_IN_ASM) {
|
6124 |
int flags;
|
6125 |
flags = env->bfd_mach; |
6126 |
flags |= msr_le << 16;
|
6127 |
fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
|
6128 |
target_disas(logfile, pc_start, ctx.nip - pc_start, flags); |
6129 |
fprintf(logfile, "\n");
|
6130 |
} |
6131 |
if (loglevel & CPU_LOG_TB_OP) {
|
6132 |
fprintf(logfile, "OP:\n");
|
6133 |
dump_ops(gen_opc_buf, gen_opparam_buf); |
6134 |
fprintf(logfile, "\n");
|
6135 |
} |
6136 |
#endif
|
6137 |
return 0; |
6138 |
} |
6139 |
|
6140 |
int gen_intermediate_code (CPUState *env, struct TranslationBlock *tb) |
6141 |
{ |
6142 |
return gen_intermediate_code_internal(env, tb, 0); |
6143 |
} |
6144 |
|
6145 |
int gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb) |
6146 |
{ |
6147 |
return gen_intermediate_code_internal(env, tb, 1); |
6148 |
} |