blob: fd7c2087d7903e6de6c33e39ce02a3f72682e36a [file] [log] [blame]
bellard79aceca2003-11-23 14:55:54 +00001/*
bellard3fc6c082005-07-02 20:59:34 +00002 * PowerPC emulation for qemu: main translation routines.
ths5fafdf22007-09-16 21:08:06 +00003 *
j_mayer76a66252007-03-07 08:32:30 +00004 * Copyright (c) 2003-2007 Jocelyn Mayer
Scott Wood90dc8812011-04-29 17:10:23 -05005 * Copyright (C) 2011 Freescale Semiconductor, Inc.
bellard79aceca2003-11-23 14:55:54 +00006 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
Blue Swirl8167ee82009-07-16 20:47:01 +000018 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
bellard79aceca2003-11-23 14:55:54 +000019 */
bellardc6a1c222004-05-20 13:10:49 +000020#include <stdarg.h>
21#include <stdlib.h>
22#include <stdio.h>
23#include <string.h>
24#include <inttypes.h>
25
bellard79aceca2003-11-23 14:55:54 +000026#include "cpu.h"
bellard79aceca2003-11-23 14:55:54 +000027#include "disas.h"
bellard57fec1f2008-02-01 10:50:11 +000028#include "tcg-op.h"
aurel32ca10f862008-04-11 21:35:42 +000029#include "qemu-common.h"
aurel320cfe11e2009-03-03 06:12:14 +000030#include "host-utils.h"
bellard79aceca2003-11-23 14:55:54 +000031
pbrooka7812ae2008-11-17 14:43:54 +000032#include "helper.h"
33#define GEN_HELPER 1
34#include "helper.h"
35
aurel328cbcb4f2008-05-10 23:28:14 +000036#define CPU_SINGLE_STEP 0x1
37#define CPU_BRANCH_STEP 0x2
38#define GDBSTUB_SINGLE_STEP 0x4
39
j_mayera750fc02007-09-26 23:54:22 +000040/* Include definitions for instructions classes and implementations flags */
bellard9fddaa02004-05-21 12:59:32 +000041//#define PPC_DEBUG_DISAS
j_mayer76a66252007-03-07 08:32:30 +000042//#define DO_PPC_STATISTICS
bellard79aceca2003-11-23 14:55:54 +000043
aliguorid12d51d2009-01-15 21:48:06 +000044#ifdef PPC_DEBUG_DISAS
aliguori93fcfe32009-01-15 22:34:14 +000045# define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
aliguorid12d51d2009-01-15 21:48:06 +000046#else
47# define LOG_DISAS(...) do { } while (0)
48#endif
j_mayera750fc02007-09-26 23:54:22 +000049/*****************************************************************************/
50/* Code translation helpers */
bellardc53be332005-10-30 21:39:19 +000051
aurel32f78fb442008-09-04 05:25:47 +000052/* global register indexes */
pbrooka7812ae2008-11-17 14:43:54 +000053static TCGv_ptr cpu_env;
aurel321d542692008-09-04 14:43:45 +000054static char cpu_reg_names[10*3 + 22*4 /* GPR */
aurel32f78fb442008-09-04 05:25:47 +000055#if !defined(TARGET_PPC64)
aurel321d542692008-09-04 14:43:45 +000056 + 10*4 + 22*5 /* SPE GPRh */
aurel32f78fb442008-09-04 05:25:47 +000057#endif
aurel32a5e26af2008-09-04 14:43:54 +000058 + 10*4 + 22*5 /* FPR */
aurel3247e46612008-09-04 17:06:47 +000059 + 2*(10*6 + 22*7) /* AVRh, AVRl */
60 + 8*5 /* CRF */];
aurel32f78fb442008-09-04 05:25:47 +000061static TCGv cpu_gpr[32];
62#if !defined(TARGET_PPC64)
63static TCGv cpu_gprh[32];
64#endif
pbrooka7812ae2008-11-17 14:43:54 +000065static TCGv_i64 cpu_fpr[32];
66static TCGv_i64 cpu_avrh[32], cpu_avrl[32];
67static TCGv_i32 cpu_crf[8];
aurel32bd568f12008-09-04 18:06:03 +000068static TCGv cpu_nip;
aurel326527f6e2008-12-06 13:03:35 +000069static TCGv cpu_msr;
aurel32cfdcd372008-09-14 18:30:23 +000070static TCGv cpu_ctr;
71static TCGv cpu_lr;
aurel323d7b4172008-10-21 11:28:46 +000072static TCGv cpu_xer;
aurel32cf360a32008-11-30 16:24:39 +000073static TCGv cpu_reserve;
pbrooka7812ae2008-11-17 14:43:54 +000074static TCGv_i32 cpu_fpscr;
aurel32a7859e82008-11-23 16:30:40 +000075static TCGv_i32 cpu_access_type;
aurel32f78fb442008-09-04 05:25:47 +000076
pbrook2e70f6e2008-06-29 01:03:05 +000077#include "gen-icount.h"
78
79void ppc_translate_init(void)
80{
aurel32f78fb442008-09-04 05:25:47 +000081 int i;
82 char* p;
blueswir12dc766d2009-04-13 16:06:19 +000083 size_t cpu_reg_names_size;
pbrookb2437bf2008-06-29 12:29:56 +000084 static int done_init = 0;
aurel32f78fb442008-09-04 05:25:47 +000085
pbrook2e70f6e2008-06-29 01:03:05 +000086 if (done_init)
87 return;
aurel32f78fb442008-09-04 05:25:47 +000088
pbrooka7812ae2008-11-17 14:43:54 +000089 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
aurel32a5e26af2008-09-04 14:43:54 +000090
aurel32f78fb442008-09-04 05:25:47 +000091 p = cpu_reg_names;
blueswir12dc766d2009-04-13 16:06:19 +000092 cpu_reg_names_size = sizeof(cpu_reg_names);
aurel3247e46612008-09-04 17:06:47 +000093
94 for (i = 0; i < 8; i++) {
blueswir12dc766d2009-04-13 16:06:19 +000095 snprintf(p, cpu_reg_names_size, "crf%d", i);
pbrooka7812ae2008-11-17 14:43:54 +000096 cpu_crf[i] = tcg_global_mem_new_i32(TCG_AREG0,
97 offsetof(CPUState, crf[i]), p);
aurel3247e46612008-09-04 17:06:47 +000098 p += 5;
blueswir12dc766d2009-04-13 16:06:19 +000099 cpu_reg_names_size -= 5;
aurel3247e46612008-09-04 17:06:47 +0000100 }
101
aurel32f78fb442008-09-04 05:25:47 +0000102 for (i = 0; i < 32; i++) {
blueswir12dc766d2009-04-13 16:06:19 +0000103 snprintf(p, cpu_reg_names_size, "r%d", i);
pbrooka7812ae2008-11-17 14:43:54 +0000104 cpu_gpr[i] = tcg_global_mem_new(TCG_AREG0,
aurel32f78fb442008-09-04 05:25:47 +0000105 offsetof(CPUState, gpr[i]), p);
106 p += (i < 10) ? 3 : 4;
blueswir12dc766d2009-04-13 16:06:19 +0000107 cpu_reg_names_size -= (i < 10) ? 3 : 4;
aurel32f78fb442008-09-04 05:25:47 +0000108#if !defined(TARGET_PPC64)
blueswir12dc766d2009-04-13 16:06:19 +0000109 snprintf(p, cpu_reg_names_size, "r%dH", i);
pbrooka7812ae2008-11-17 14:43:54 +0000110 cpu_gprh[i] = tcg_global_mem_new_i32(TCG_AREG0,
111 offsetof(CPUState, gprh[i]), p);
aurel32f78fb442008-09-04 05:25:47 +0000112 p += (i < 10) ? 4 : 5;
blueswir12dc766d2009-04-13 16:06:19 +0000113 cpu_reg_names_size -= (i < 10) ? 4 : 5;
aurel32f78fb442008-09-04 05:25:47 +0000114#endif
aurel321d542692008-09-04 14:43:45 +0000115
blueswir12dc766d2009-04-13 16:06:19 +0000116 snprintf(p, cpu_reg_names_size, "fp%d", i);
pbrooka7812ae2008-11-17 14:43:54 +0000117 cpu_fpr[i] = tcg_global_mem_new_i64(TCG_AREG0,
118 offsetof(CPUState, fpr[i]), p);
aurel32ec1ac722008-09-04 15:49:12 +0000119 p += (i < 10) ? 4 : 5;
blueswir12dc766d2009-04-13 16:06:19 +0000120 cpu_reg_names_size -= (i < 10) ? 4 : 5;
aurel32a5e26af2008-09-04 14:43:54 +0000121
blueswir12dc766d2009-04-13 16:06:19 +0000122 snprintf(p, cpu_reg_names_size, "avr%dH", i);
Juan Quintelae2542fe2009-07-27 16:13:06 +0200123#ifdef HOST_WORDS_BIGENDIAN
pbrooka7812ae2008-11-17 14:43:54 +0000124 cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,
aurel32fe1e5c52008-11-24 08:47:21 +0000125 offsetof(CPUState, avr[i].u64[0]), p);
126#else
127 cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,
128 offsetof(CPUState, avr[i].u64[1]), p);
129#endif
aurel321d542692008-09-04 14:43:45 +0000130 p += (i < 10) ? 6 : 7;
blueswir12dc766d2009-04-13 16:06:19 +0000131 cpu_reg_names_size -= (i < 10) ? 6 : 7;
aurel32ec1ac722008-09-04 15:49:12 +0000132
blueswir12dc766d2009-04-13 16:06:19 +0000133 snprintf(p, cpu_reg_names_size, "avr%dL", i);
Juan Quintelae2542fe2009-07-27 16:13:06 +0200134#ifdef HOST_WORDS_BIGENDIAN
pbrooka7812ae2008-11-17 14:43:54 +0000135 cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,
aurel32fe1e5c52008-11-24 08:47:21 +0000136 offsetof(CPUState, avr[i].u64[1]), p);
137#else
138 cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,
139 offsetof(CPUState, avr[i].u64[0]), p);
140#endif
aurel321d542692008-09-04 14:43:45 +0000141 p += (i < 10) ? 6 : 7;
blueswir12dc766d2009-04-13 16:06:19 +0000142 cpu_reg_names_size -= (i < 10) ? 6 : 7;
aurel32f78fb442008-09-04 05:25:47 +0000143 }
aurel32f10dc082008-08-28 21:01:45 +0000144
pbrooka7812ae2008-11-17 14:43:54 +0000145 cpu_nip = tcg_global_mem_new(TCG_AREG0,
aurel32bd568f12008-09-04 18:06:03 +0000146 offsetof(CPUState, nip), "nip");
147
aurel326527f6e2008-12-06 13:03:35 +0000148 cpu_msr = tcg_global_mem_new(TCG_AREG0,
149 offsetof(CPUState, msr), "msr");
150
pbrooka7812ae2008-11-17 14:43:54 +0000151 cpu_ctr = tcg_global_mem_new(TCG_AREG0,
aurel32cfdcd372008-09-14 18:30:23 +0000152 offsetof(CPUState, ctr), "ctr");
153
pbrooka7812ae2008-11-17 14:43:54 +0000154 cpu_lr = tcg_global_mem_new(TCG_AREG0,
aurel32cfdcd372008-09-14 18:30:23 +0000155 offsetof(CPUState, lr), "lr");
156
pbrooka7812ae2008-11-17 14:43:54 +0000157 cpu_xer = tcg_global_mem_new(TCG_AREG0,
aurel323d7b4172008-10-21 11:28:46 +0000158 offsetof(CPUState, xer), "xer");
159
aurel32cf360a32008-11-30 16:24:39 +0000160 cpu_reserve = tcg_global_mem_new(TCG_AREG0,
Nathan Froyd18b21a22009-08-03 08:43:25 -0700161 offsetof(CPUState, reserve_addr),
162 "reserve_addr");
aurel32cf360a32008-11-30 16:24:39 +0000163
pbrooka7812ae2008-11-17 14:43:54 +0000164 cpu_fpscr = tcg_global_mem_new_i32(TCG_AREG0,
165 offsetof(CPUState, fpscr), "fpscr");
aurel32e1571902008-10-21 11:31:14 +0000166
aurel32a7859e82008-11-23 16:30:40 +0000167 cpu_access_type = tcg_global_mem_new_i32(TCG_AREG0,
168 offsetof(CPUState, access_type), "access_type");
169
aurel32f10dc082008-08-28 21:01:45 +0000170 /* register helpers */
pbrooka7812ae2008-11-17 14:43:54 +0000171#define GEN_HELPER 2
aurel32f10dc082008-08-28 21:01:45 +0000172#include "helper.h"
173
pbrook2e70f6e2008-06-29 01:03:05 +0000174 done_init = 1;
175}
176
bellard79aceca2003-11-23 14:55:54 +0000177/* internal defines */
178typedef struct DisasContext {
179 struct TranslationBlock *tb;
bellard0fa85d42005-01-03 23:43:32 +0000180 target_ulong nip;
bellard79aceca2003-11-23 14:55:54 +0000181 uint32_t opcode;
bellard9a64fbe2004-01-04 22:58:38 +0000182 uint32_t exception;
bellard3cc62372005-02-15 23:06:19 +0000183 /* Routine used to access memory */
184 int mem_idx;
aurel3276db3ba2008-12-08 18:11:21 +0000185 int access_type;
bellard3cc62372005-02-15 23:06:19 +0000186 /* Translation flags */
aurel3276db3ba2008-12-08 18:11:21 +0000187 int le_mode;
j_mayerd9bce9d2007-03-17 14:02:15 +0000188#if defined(TARGET_PPC64)
189 int sf_mode;
190#endif
bellard3cc62372005-02-15 23:06:19 +0000191 int fpu_enabled;
j_mayera9d9eb82007-10-07 18:19:26 +0000192 int altivec_enabled;
j_mayer0487d6a2007-03-20 22:11:31 +0000193 int spe_enabled;
Anthony Liguoric227f092009-10-01 16:12:16 -0500194 ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */
bellardea4e7542006-05-22 21:50:20 +0000195 int singlestep_enabled;
bellard79aceca2003-11-23 14:55:54 +0000196} DisasContext;
197
Anthony Liguoric227f092009-10-01 16:12:16 -0500198struct opc_handler_t {
bellard79aceca2003-11-23 14:55:54 +0000199 /* invalid bits */
200 uint32_t inval;
bellard9a64fbe2004-01-04 22:58:38 +0000201 /* instruction type */
j_mayer0487d6a2007-03-20 22:11:31 +0000202 uint64_t type;
Alexander Grafa5858d72011-05-01 00:00:58 +0200203 /* extended instruction type */
204 uint64_t type2;
bellard79aceca2003-11-23 14:55:54 +0000205 /* handler */
206 void (*handler)(DisasContext *ctx);
j_mayera750fc02007-09-26 23:54:22 +0000207#if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
blueswir1b55266b2008-09-20 08:07:15 +0000208 const char *oname;
j_mayera750fc02007-09-26 23:54:22 +0000209#endif
210#if defined(DO_PPC_STATISTICS)
j_mayer76a66252007-03-07 08:32:30 +0000211 uint64_t count;
212#endif
bellard3fc6c082005-07-02 20:59:34 +0000213};
bellard79aceca2003-11-23 14:55:54 +0000214
Blue Swirl636aa202009-08-16 09:06:54 +0000215static inline void gen_reset_fpstatus(void)
j_mayer7c580442007-10-27 17:54:30 +0000216{
aurel32a44d2ce2008-12-13 11:46:27 +0000217 gen_helper_reset_fpstatus();
j_mayer7c580442007-10-27 17:54:30 +0000218}
219
Blue Swirl636aa202009-08-16 09:06:54 +0000220static inline void gen_compute_fprf(TCGv_i64 arg, int set_fprf, int set_rc)
j_mayer7c580442007-10-27 17:54:30 +0000221{
aurel320f2f39c2008-11-19 17:54:49 +0000222 TCGv_i32 t0 = tcg_temp_new_i32();
aurel32af129062008-11-19 16:10:23 +0000223
j_mayer7c580442007-10-27 17:54:30 +0000224 if (set_fprf != 0) {
225 /* This case might be optimized later */
aurel320f2f39c2008-11-19 17:54:49 +0000226 tcg_gen_movi_i32(t0, 1);
aurel32af129062008-11-19 16:10:23 +0000227 gen_helper_compute_fprf(t0, arg, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000228 if (unlikely(set_rc)) {
aurel320f2f39c2008-11-19 17:54:49 +0000229 tcg_gen_mov_i32(cpu_crf[1], t0);
pbrooka7812ae2008-11-17 14:43:54 +0000230 }
aurel32af129062008-11-19 16:10:23 +0000231 gen_helper_float_check_status();
j_mayer7c580442007-10-27 17:54:30 +0000232 } else if (unlikely(set_rc)) {
233 /* We always need to compute fpcc */
aurel320f2f39c2008-11-19 17:54:49 +0000234 tcg_gen_movi_i32(t0, 0);
aurel32af129062008-11-19 16:10:23 +0000235 gen_helper_compute_fprf(t0, arg, t0);
aurel320f2f39c2008-11-19 17:54:49 +0000236 tcg_gen_mov_i32(cpu_crf[1], t0);
j_mayer7c580442007-10-27 17:54:30 +0000237 }
aurel32af129062008-11-19 16:10:23 +0000238
aurel320f2f39c2008-11-19 17:54:49 +0000239 tcg_temp_free_i32(t0);
j_mayer7c580442007-10-27 17:54:30 +0000240}
241
Blue Swirl636aa202009-08-16 09:06:54 +0000242static inline void gen_set_access_type(DisasContext *ctx, int access_type)
aurel32a7859e82008-11-23 16:30:40 +0000243{
aurel3276db3ba2008-12-08 18:11:21 +0000244 if (ctx->access_type != access_type) {
245 tcg_gen_movi_i32(cpu_access_type, access_type);
246 ctx->access_type = access_type;
247 }
aurel32a7859e82008-11-23 16:30:40 +0000248}
249
Blue Swirl636aa202009-08-16 09:06:54 +0000250static inline void gen_update_nip(DisasContext *ctx, target_ulong nip)
j_mayerd9bce9d2007-03-17 14:02:15 +0000251{
252#if defined(TARGET_PPC64)
253 if (ctx->sf_mode)
aurel32bd568f12008-09-04 18:06:03 +0000254 tcg_gen_movi_tl(cpu_nip, nip);
j_mayerd9bce9d2007-03-17 14:02:15 +0000255 else
256#endif
aurel32bd568f12008-09-04 18:06:03 +0000257 tcg_gen_movi_tl(cpu_nip, (uint32_t)nip);
j_mayerd9bce9d2007-03-17 14:02:15 +0000258}
259
Blue Swirl636aa202009-08-16 09:06:54 +0000260static inline void gen_exception_err(DisasContext *ctx, uint32_t excp, uint32_t error)
aurel32e06fcd72008-12-11 22:42:14 +0000261{
262 TCGv_i32 t0, t1;
263 if (ctx->exception == POWERPC_EXCP_NONE) {
264 gen_update_nip(ctx, ctx->nip);
265 }
266 t0 = tcg_const_i32(excp);
267 t1 = tcg_const_i32(error);
268 gen_helper_raise_exception_err(t0, t1);
269 tcg_temp_free_i32(t0);
270 tcg_temp_free_i32(t1);
271 ctx->exception = (excp);
272}
bellard79aceca2003-11-23 14:55:54 +0000273
Blue Swirl636aa202009-08-16 09:06:54 +0000274static inline void gen_exception(DisasContext *ctx, uint32_t excp)
aurel32e06fcd72008-12-11 22:42:14 +0000275{
276 TCGv_i32 t0;
277 if (ctx->exception == POWERPC_EXCP_NONE) {
278 gen_update_nip(ctx, ctx->nip);
279 }
280 t0 = tcg_const_i32(excp);
281 gen_helper_raise_exception(t0);
282 tcg_temp_free_i32(t0);
283 ctx->exception = (excp);
284}
bellard9a64fbe2004-01-04 22:58:38 +0000285
Blue Swirl636aa202009-08-16 09:06:54 +0000286static inline void gen_debug_exception(DisasContext *ctx)
aurel32e06fcd72008-12-11 22:42:14 +0000287{
288 TCGv_i32 t0;
blueswir15518f3a2009-02-19 20:17:09 +0000289
290 if (ctx->exception != POWERPC_EXCP_BRANCH)
291 gen_update_nip(ctx, ctx->nip);
aurel32e06fcd72008-12-11 22:42:14 +0000292 t0 = tcg_const_i32(EXCP_DEBUG);
293 gen_helper_raise_exception(t0);
294 tcg_temp_free_i32(t0);
295}
bellard9a64fbe2004-01-04 22:58:38 +0000296
Blue Swirl636aa202009-08-16 09:06:54 +0000297static inline void gen_inval_exception(DisasContext *ctx, uint32_t error)
aurel32e06fcd72008-12-11 22:42:14 +0000298{
299 gen_exception_err(ctx, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | error);
300}
j_mayera9d9eb82007-10-07 18:19:26 +0000301
bellardf24e5692005-11-23 21:36:30 +0000302/* Stop translation */
Blue Swirl636aa202009-08-16 09:06:54 +0000303static inline void gen_stop_exception(DisasContext *ctx)
bellard3fc6c082005-07-02 20:59:34 +0000304{
j_mayerd9bce9d2007-03-17 14:02:15 +0000305 gen_update_nip(ctx, ctx->nip);
j_mayere1833e12007-09-29 13:06:16 +0000306 ctx->exception = POWERPC_EXCP_STOP;
bellard3fc6c082005-07-02 20:59:34 +0000307}
308
bellardf24e5692005-11-23 21:36:30 +0000309/* No need to update nip here, as execution flow will change */
Blue Swirl636aa202009-08-16 09:06:54 +0000310static inline void gen_sync_exception(DisasContext *ctx)
bellard2be00712005-07-02 22:09:27 +0000311{
j_mayere1833e12007-09-29 13:06:16 +0000312 ctx->exception = POWERPC_EXCP_SYNC;
bellard2be00712005-07-02 22:09:27 +0000313}
314
bellard79aceca2003-11-23 14:55:54 +0000315#define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
Alexander Grafa5858d72011-05-01 00:00:58 +0200316GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
317
318#define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
319GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
bellard79aceca2003-11-23 14:55:54 +0000320
j_mayerc7697e12007-10-26 00:46:07 +0000321#define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
Alexander Grafa5858d72011-05-01 00:00:58 +0200322GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
323
324#define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
325GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
j_mayerc7697e12007-10-26 00:46:07 +0000326
Anthony Liguoric227f092009-10-01 16:12:16 -0500327typedef struct opcode_t {
bellard79aceca2003-11-23 14:55:54 +0000328 unsigned char opc1, opc2, opc3;
ths1235fc02008-06-03 19:51:57 +0000329#if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
bellard18fba282005-02-08 21:24:36 +0000330 unsigned char pad[5];
331#else
332 unsigned char pad[1];
333#endif
Anthony Liguoric227f092009-10-01 16:12:16 -0500334 opc_handler_t handler;
blueswir1b55266b2008-09-20 08:07:15 +0000335 const char *oname;
Anthony Liguoric227f092009-10-01 16:12:16 -0500336} opcode_t;
bellard79aceca2003-11-23 14:55:54 +0000337
j_mayera750fc02007-09-26 23:54:22 +0000338/*****************************************************************************/
bellard79aceca2003-11-23 14:55:54 +0000339/*** Instruction decoding ***/
340#define EXTRACT_HELPER(name, shift, nb) \
Blue Swirl636aa202009-08-16 09:06:54 +0000341static inline uint32_t name(uint32_t opcode) \
bellard79aceca2003-11-23 14:55:54 +0000342{ \
343 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
344}
345
346#define EXTRACT_SHELPER(name, shift, nb) \
Blue Swirl636aa202009-08-16 09:06:54 +0000347static inline int32_t name(uint32_t opcode) \
bellard79aceca2003-11-23 14:55:54 +0000348{ \
bellard18fba282005-02-08 21:24:36 +0000349 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
bellard79aceca2003-11-23 14:55:54 +0000350}
351
352/* Opcode part 1 */
353EXTRACT_HELPER(opc1, 26, 6);
354/* Opcode part 2 */
355EXTRACT_HELPER(opc2, 1, 5);
356/* Opcode part 3 */
357EXTRACT_HELPER(opc3, 6, 5);
358/* Update Cr0 flags */
359EXTRACT_HELPER(Rc, 0, 1);
360/* Destination */
361EXTRACT_HELPER(rD, 21, 5);
362/* Source */
363EXTRACT_HELPER(rS, 21, 5);
364/* First operand */
365EXTRACT_HELPER(rA, 16, 5);
366/* Second operand */
367EXTRACT_HELPER(rB, 11, 5);
368/* Third operand */
369EXTRACT_HELPER(rC, 6, 5);
370/*** Get CRn ***/
371EXTRACT_HELPER(crfD, 23, 3);
372EXTRACT_HELPER(crfS, 18, 3);
373EXTRACT_HELPER(crbD, 21, 5);
374EXTRACT_HELPER(crbA, 16, 5);
375EXTRACT_HELPER(crbB, 11, 5);
376/* SPR / TBL */
bellard3fc6c082005-07-02 20:59:34 +0000377EXTRACT_HELPER(_SPR, 11, 10);
Blue Swirl636aa202009-08-16 09:06:54 +0000378static inline uint32_t SPR(uint32_t opcode)
bellard3fc6c082005-07-02 20:59:34 +0000379{
380 uint32_t sprn = _SPR(opcode);
381
382 return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
383}
bellard79aceca2003-11-23 14:55:54 +0000384/*** Get constants ***/
385EXTRACT_HELPER(IMM, 12, 8);
386/* 16 bits signed immediate value */
387EXTRACT_SHELPER(SIMM, 0, 16);
388/* 16 bits unsigned immediate value */
389EXTRACT_HELPER(UIMM, 0, 16);
aurel3221d21582009-01-04 22:10:28 +0000390/* 5 bits signed immediate value */
391EXTRACT_HELPER(SIMM5, 16, 5);
aurel3227a4edb2009-01-04 22:10:40 +0000392/* 5 bits signed immediate value */
393EXTRACT_HELPER(UIMM5, 16, 5);
bellard79aceca2003-11-23 14:55:54 +0000394/* Bit count */
395EXTRACT_HELPER(NB, 11, 5);
396/* Shift count */
397EXTRACT_HELPER(SH, 11, 5);
aurel32cd633b12009-01-04 22:10:09 +0000398/* Vector shift count */
399EXTRACT_HELPER(VSH, 6, 4);
bellard79aceca2003-11-23 14:55:54 +0000400/* Mask start */
401EXTRACT_HELPER(MB, 6, 5);
402/* Mask end */
403EXTRACT_HELPER(ME, 1, 5);
bellardfb0eaff2004-01-04 14:57:11 +0000404/* Trap operand */
405EXTRACT_HELPER(TO, 21, 5);
bellard79aceca2003-11-23 14:55:54 +0000406
407EXTRACT_HELPER(CRM, 12, 8);
408EXTRACT_HELPER(FM, 17, 8);
409EXTRACT_HELPER(SR, 16, 4);
aurel32e4bb9972008-06-18 22:10:12 +0000410EXTRACT_HELPER(FPIMM, 12, 4);
bellardfb0eaff2004-01-04 14:57:11 +0000411
bellard79aceca2003-11-23 14:55:54 +0000412/*** Jump target decoding ***/
413/* Displacement */
414EXTRACT_SHELPER(d, 0, 16);
415/* Immediate address */
Blue Swirl636aa202009-08-16 09:06:54 +0000416static inline target_ulong LI(uint32_t opcode)
bellard79aceca2003-11-23 14:55:54 +0000417{
418 return (opcode >> 0) & 0x03FFFFFC;
419}
420
Blue Swirl636aa202009-08-16 09:06:54 +0000421static inline uint32_t BD(uint32_t opcode)
bellard79aceca2003-11-23 14:55:54 +0000422{
423 return (opcode >> 0) & 0xFFFC;
424}
425
426EXTRACT_HELPER(BO, 21, 5);
427EXTRACT_HELPER(BI, 16, 5);
428/* Absolute/relative address */
429EXTRACT_HELPER(AA, 1, 1);
430/* Link */
431EXTRACT_HELPER(LK, 0, 1);
432
433/* Create a mask between <start> and <end> bits */
Blue Swirl636aa202009-08-16 09:06:54 +0000434static inline target_ulong MASK(uint32_t start, uint32_t end)
bellard79aceca2003-11-23 14:55:54 +0000435{
j_mayer76a66252007-03-07 08:32:30 +0000436 target_ulong ret;
bellard79aceca2003-11-23 14:55:54 +0000437
j_mayer76a66252007-03-07 08:32:30 +0000438#if defined(TARGET_PPC64)
439 if (likely(start == 0)) {
j_mayer6f2d8972007-11-12 00:04:48 +0000440 ret = UINT64_MAX << (63 - end);
j_mayer76a66252007-03-07 08:32:30 +0000441 } else if (likely(end == 63)) {
j_mayer6f2d8972007-11-12 00:04:48 +0000442 ret = UINT64_MAX >> start;
j_mayer76a66252007-03-07 08:32:30 +0000443 }
444#else
445 if (likely(start == 0)) {
j_mayer6f2d8972007-11-12 00:04:48 +0000446 ret = UINT32_MAX << (31 - end);
j_mayer76a66252007-03-07 08:32:30 +0000447 } else if (likely(end == 31)) {
j_mayer6f2d8972007-11-12 00:04:48 +0000448 ret = UINT32_MAX >> start;
j_mayer76a66252007-03-07 08:32:30 +0000449 }
450#endif
451 else {
452 ret = (((target_ulong)(-1ULL)) >> (start)) ^
453 (((target_ulong)(-1ULL) >> (end)) >> 1);
454 if (unlikely(start > end))
455 return ~ret;
456 }
bellard79aceca2003-11-23 14:55:54 +0000457
458 return ret;
459}
460
j_mayera750fc02007-09-26 23:54:22 +0000461/*****************************************************************************/
j_mayera750fc02007-09-26 23:54:22 +0000462/* PowerPC instructions table */
bellard933dc6e2004-07-10 15:33:29 +0000463
j_mayer76a66252007-03-07 08:32:30 +0000464#if defined(DO_PPC_STATISTICS)
Alexander Grafa5858d72011-05-01 00:00:58 +0200465#define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
Blue Swirl5c55ff92009-06-17 15:22:31 +0000466{ \
j_mayer76a66252007-03-07 08:32:30 +0000467 .opc1 = op1, \
468 .opc2 = op2, \
469 .opc3 = op3, \
470 .pad = { 0, }, \
471 .handler = { \
472 .inval = invl, \
473 .type = _typ, \
Alexander Grafa5858d72011-05-01 00:00:58 +0200474 .type2 = _typ2, \
j_mayer76a66252007-03-07 08:32:30 +0000475 .handler = &gen_##name, \
476 .oname = stringify(name), \
477 }, \
478 .oname = stringify(name), \
479}
Alexander Grafa5858d72011-05-01 00:00:58 +0200480#define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
Blue Swirl5c55ff92009-06-17 15:22:31 +0000481{ \
j_mayerc7697e12007-10-26 00:46:07 +0000482 .opc1 = op1, \
483 .opc2 = op2, \
484 .opc3 = op3, \
485 .pad = { 0, }, \
486 .handler = { \
487 .inval = invl, \
488 .type = _typ, \
Alexander Grafa5858d72011-05-01 00:00:58 +0200489 .type2 = _typ2, \
j_mayerc7697e12007-10-26 00:46:07 +0000490 .handler = &gen_##name, \
491 .oname = onam, \
492 }, \
493 .oname = onam, \
494}
j_mayer76a66252007-03-07 08:32:30 +0000495#else
Alexander Grafa5858d72011-05-01 00:00:58 +0200496#define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
Blue Swirl5c55ff92009-06-17 15:22:31 +0000497{ \
bellard79aceca2003-11-23 14:55:54 +0000498 .opc1 = op1, \
499 .opc2 = op2, \
500 .opc3 = op3, \
bellard18fba282005-02-08 21:24:36 +0000501 .pad = { 0, }, \
bellard79aceca2003-11-23 14:55:54 +0000502 .handler = { \
503 .inval = invl, \
bellard9a64fbe2004-01-04 22:58:38 +0000504 .type = _typ, \
Alexander Grafa5858d72011-05-01 00:00:58 +0200505 .type2 = _typ2, \
bellard79aceca2003-11-23 14:55:54 +0000506 .handler = &gen_##name, \
507 }, \
bellard3fc6c082005-07-02 20:59:34 +0000508 .oname = stringify(name), \
bellard79aceca2003-11-23 14:55:54 +0000509}
Alexander Grafa5858d72011-05-01 00:00:58 +0200510#define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
Blue Swirl5c55ff92009-06-17 15:22:31 +0000511{ \
j_mayerc7697e12007-10-26 00:46:07 +0000512 .opc1 = op1, \
513 .opc2 = op2, \
514 .opc3 = op3, \
515 .pad = { 0, }, \
516 .handler = { \
517 .inval = invl, \
518 .type = _typ, \
Alexander Grafa5858d72011-05-01 00:00:58 +0200519 .type2 = _typ2, \
j_mayerc7697e12007-10-26 00:46:07 +0000520 .handler = &gen_##name, \
521 }, \
522 .oname = onam, \
523}
j_mayer76a66252007-03-07 08:32:30 +0000524#endif
bellard79aceca2003-11-23 14:55:54 +0000525
aurel3254cdcae2008-12-05 07:21:31 +0000526/* SPR load/store helpers */
Blue Swirl636aa202009-08-16 09:06:54 +0000527static inline void gen_load_spr(TCGv t, int reg)
aurel3254cdcae2008-12-05 07:21:31 +0000528{
529 tcg_gen_ld_tl(t, cpu_env, offsetof(CPUState, spr[reg]));
530}
531
Blue Swirl636aa202009-08-16 09:06:54 +0000532static inline void gen_store_spr(int reg, TCGv t)
aurel3254cdcae2008-12-05 07:21:31 +0000533{
534 tcg_gen_st_tl(t, cpu_env, offsetof(CPUState, spr[reg]));
535}
536
bellard79aceca2003-11-23 14:55:54 +0000537/* Invalid instruction */
Blue Swirl99e300e2009-06-17 15:22:09 +0000538static void gen_invalid(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +0000539{
aurel32e06fcd72008-12-11 22:42:14 +0000540 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
bellard9a64fbe2004-01-04 22:58:38 +0000541}
542
Anthony Liguoric227f092009-10-01 16:12:16 -0500543static opc_handler_t invalid_handler = {
bellard79aceca2003-11-23 14:55:54 +0000544 .inval = 0xFFFFFFFF,
bellard9a64fbe2004-01-04 22:58:38 +0000545 .type = PPC_NONE,
Alexander Grafa5858d72011-05-01 00:00:58 +0200546 .type2 = PPC_NONE,
bellard79aceca2003-11-23 14:55:54 +0000547 .handler = gen_invalid,
548};
549
aurel32e1571902008-10-21 11:31:14 +0000550/*** Integer comparison ***/
551
Blue Swirl636aa202009-08-16 09:06:54 +0000552static inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf)
aurel32e1571902008-10-21 11:31:14 +0000553{
554 int l1, l2, l3;
555
aurel32269f3e92008-11-01 00:53:48 +0000556 tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_xer);
557 tcg_gen_shri_i32(cpu_crf[crf], cpu_crf[crf], XER_SO);
aurel32e1571902008-10-21 11:31:14 +0000558 tcg_gen_andi_i32(cpu_crf[crf], cpu_crf[crf], 1);
559
560 l1 = gen_new_label();
561 l2 = gen_new_label();
562 l3 = gen_new_label();
563 if (s) {
aurel32ea363692008-10-27 22:50:39 +0000564 tcg_gen_brcond_tl(TCG_COND_LT, arg0, arg1, l1);
565 tcg_gen_brcond_tl(TCG_COND_GT, arg0, arg1, l2);
aurel32e1571902008-10-21 11:31:14 +0000566 } else {
aurel32ea363692008-10-27 22:50:39 +0000567 tcg_gen_brcond_tl(TCG_COND_LTU, arg0, arg1, l1);
568 tcg_gen_brcond_tl(TCG_COND_GTU, arg0, arg1, l2);
aurel32e1571902008-10-21 11:31:14 +0000569 }
570 tcg_gen_ori_i32(cpu_crf[crf], cpu_crf[crf], 1 << CRF_EQ);
571 tcg_gen_br(l3);
572 gen_set_label(l1);
573 tcg_gen_ori_i32(cpu_crf[crf], cpu_crf[crf], 1 << CRF_LT);
574 tcg_gen_br(l3);
575 gen_set_label(l2);
576 tcg_gen_ori_i32(cpu_crf[crf], cpu_crf[crf], 1 << CRF_GT);
577 gen_set_label(l3);
578}
579
Blue Swirl636aa202009-08-16 09:06:54 +0000580static inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf)
aurel32e1571902008-10-21 11:31:14 +0000581{
aurel32ea363692008-10-27 22:50:39 +0000582 TCGv t0 = tcg_const_local_tl(arg1);
583 gen_op_cmp(arg0, t0, s, crf);
584 tcg_temp_free(t0);
aurel32e1571902008-10-21 11:31:14 +0000585}
586
587#if defined(TARGET_PPC64)
Blue Swirl636aa202009-08-16 09:06:54 +0000588static inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf)
aurel32e1571902008-10-21 11:31:14 +0000589{
aurel32ea363692008-10-27 22:50:39 +0000590 TCGv t0, t1;
pbrooka7812ae2008-11-17 14:43:54 +0000591 t0 = tcg_temp_local_new();
592 t1 = tcg_temp_local_new();
aurel32e1571902008-10-21 11:31:14 +0000593 if (s) {
aurel32ea363692008-10-27 22:50:39 +0000594 tcg_gen_ext32s_tl(t0, arg0);
595 tcg_gen_ext32s_tl(t1, arg1);
aurel32e1571902008-10-21 11:31:14 +0000596 } else {
aurel32ea363692008-10-27 22:50:39 +0000597 tcg_gen_ext32u_tl(t0, arg0);
598 tcg_gen_ext32u_tl(t1, arg1);
aurel32e1571902008-10-21 11:31:14 +0000599 }
aurel32ea363692008-10-27 22:50:39 +0000600 gen_op_cmp(t0, t1, s, crf);
601 tcg_temp_free(t1);
602 tcg_temp_free(t0);
aurel32e1571902008-10-21 11:31:14 +0000603}
604
Blue Swirl636aa202009-08-16 09:06:54 +0000605static inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf)
aurel32e1571902008-10-21 11:31:14 +0000606{
aurel32ea363692008-10-27 22:50:39 +0000607 TCGv t0 = tcg_const_local_tl(arg1);
608 gen_op_cmp32(arg0, t0, s, crf);
609 tcg_temp_free(t0);
aurel32e1571902008-10-21 11:31:14 +0000610}
611#endif
612
Blue Swirl636aa202009-08-16 09:06:54 +0000613static inline void gen_set_Rc0(DisasContext *ctx, TCGv reg)
aurel32e1571902008-10-21 11:31:14 +0000614{
615#if defined(TARGET_PPC64)
616 if (!(ctx->sf_mode))
617 gen_op_cmpi32(reg, 0, 1, 0);
618 else
619#endif
620 gen_op_cmpi(reg, 0, 1, 0);
621}
622
623/* cmp */
Blue Swirl99e300e2009-06-17 15:22:09 +0000624static void gen_cmp(DisasContext *ctx)
aurel32e1571902008-10-21 11:31:14 +0000625{
626#if defined(TARGET_PPC64)
627 if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
628 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
629 1, crfD(ctx->opcode));
630 else
631#endif
632 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
633 1, crfD(ctx->opcode));
634}
635
636/* cmpi */
Blue Swirl99e300e2009-06-17 15:22:09 +0000637static void gen_cmpi(DisasContext *ctx)
aurel32e1571902008-10-21 11:31:14 +0000638{
639#if defined(TARGET_PPC64)
640 if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
641 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
642 1, crfD(ctx->opcode));
643 else
644#endif
645 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
646 1, crfD(ctx->opcode));
647}
648
649/* cmpl */
Blue Swirl99e300e2009-06-17 15:22:09 +0000650static void gen_cmpl(DisasContext *ctx)
aurel32e1571902008-10-21 11:31:14 +0000651{
652#if defined(TARGET_PPC64)
653 if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
654 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
655 0, crfD(ctx->opcode));
656 else
657#endif
658 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
659 0, crfD(ctx->opcode));
660}
661
662/* cmpli */
Blue Swirl99e300e2009-06-17 15:22:09 +0000663static void gen_cmpli(DisasContext *ctx)
aurel32e1571902008-10-21 11:31:14 +0000664{
665#if defined(TARGET_PPC64)
666 if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
667 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
668 0, crfD(ctx->opcode));
669 else
670#endif
671 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
672 0, crfD(ctx->opcode));
673}
674
675/* isel (PowerPC 2.03 specification) */
Blue Swirl99e300e2009-06-17 15:22:09 +0000676static void gen_isel(DisasContext *ctx)
aurel32e1571902008-10-21 11:31:14 +0000677{
678 int l1, l2;
679 uint32_t bi = rC(ctx->opcode);
680 uint32_t mask;
pbrooka7812ae2008-11-17 14:43:54 +0000681 TCGv_i32 t0;
aurel32e1571902008-10-21 11:31:14 +0000682
683 l1 = gen_new_label();
684 l2 = gen_new_label();
685
686 mask = 1 << (3 - (bi & 0x03));
pbrooka7812ae2008-11-17 14:43:54 +0000687 t0 = tcg_temp_new_i32();
aurel32fea0c502008-11-02 08:22:34 +0000688 tcg_gen_andi_i32(t0, cpu_crf[bi >> 2], mask);
689 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
aurel32e1571902008-10-21 11:31:14 +0000690 if (rA(ctx->opcode) == 0)
691 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
692 else
693 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
694 tcg_gen_br(l2);
695 gen_set_label(l1);
696 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
697 gen_set_label(l2);
pbrooka7812ae2008-11-17 14:43:54 +0000698 tcg_temp_free_i32(t0);
aurel32e1571902008-10-21 11:31:14 +0000699}
700
bellard79aceca2003-11-23 14:55:54 +0000701/*** Integer arithmetic ***/
aurel3274637402008-11-01 00:54:12 +0000702
Blue Swirl636aa202009-08-16 09:06:54 +0000703static inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0,
704 TCGv arg1, TCGv arg2, int sub)
aurel3274637402008-11-01 00:54:12 +0000705{
706 int l1;
707 TCGv t0;
708
709 l1 = gen_new_label();
710 /* Start with XER OV disabled, the most likely case */
711 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
pbrooka7812ae2008-11-17 14:43:54 +0000712 t0 = tcg_temp_local_new();
aurel3274637402008-11-01 00:54:12 +0000713 tcg_gen_xor_tl(t0, arg0, arg1);
714#if defined(TARGET_PPC64)
715 if (!ctx->sf_mode)
716 tcg_gen_ext32s_tl(t0, t0);
717#endif
718 if (sub)
719 tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0, l1);
720 else
721 tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1);
722 tcg_gen_xor_tl(t0, arg1, arg2);
723#if defined(TARGET_PPC64)
724 if (!ctx->sf_mode)
725 tcg_gen_ext32s_tl(t0, t0);
726#endif
727 if (sub)
728 tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1);
729 else
730 tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0, l1);
731 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
732 gen_set_label(l1);
733 tcg_temp_free(t0);
bellard79aceca2003-11-23 14:55:54 +0000734}
735
Blue Swirl636aa202009-08-16 09:06:54 +0000736static inline void gen_op_arith_compute_ca(DisasContext *ctx, TCGv arg1,
737 TCGv arg2, int sub)
aurel3274637402008-11-01 00:54:12 +0000738{
739 int l1 = gen_new_label();
j_mayerd9bce9d2007-03-17 14:02:15 +0000740
741#if defined(TARGET_PPC64)
aurel3274637402008-11-01 00:54:12 +0000742 if (!(ctx->sf_mode)) {
743 TCGv t0, t1;
pbrooka7812ae2008-11-17 14:43:54 +0000744 t0 = tcg_temp_new();
745 t1 = tcg_temp_new();
j_mayerd9bce9d2007-03-17 14:02:15 +0000746
aurel3274637402008-11-01 00:54:12 +0000747 tcg_gen_ext32u_tl(t0, arg1);
748 tcg_gen_ext32u_tl(t1, arg2);
749 if (sub) {
750 tcg_gen_brcond_tl(TCG_COND_GTU, t0, t1, l1);
aurel32bdc4e052008-11-09 17:27:03 +0000751 } else {
aurel3274637402008-11-01 00:54:12 +0000752 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
753 }
aurel32a9730012008-11-09 17:27:36 +0000754 tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA);
755 gen_set_label(l1);
756 tcg_temp_free(t0);
757 tcg_temp_free(t1);
aurel3274637402008-11-01 00:54:12 +0000758 } else
j_mayerd9bce9d2007-03-17 14:02:15 +0000759#endif
aurel32a9730012008-11-09 17:27:36 +0000760 {
761 if (sub) {
762 tcg_gen_brcond_tl(TCG_COND_GTU, arg1, arg2, l1);
763 } else {
764 tcg_gen_brcond_tl(TCG_COND_GEU, arg1, arg2, l1);
765 }
766 tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA);
767 gen_set_label(l1);
aurel3274637402008-11-01 00:54:12 +0000768 }
aurel3274637402008-11-01 00:54:12 +0000769}
bellard79aceca2003-11-23 14:55:54 +0000770
aurel3274637402008-11-01 00:54:12 +0000771/* Common add function */
Blue Swirl636aa202009-08-16 09:06:54 +0000772static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1,
773 TCGv arg2, int add_ca, int compute_ca,
774 int compute_ov)
aurel3239dd32e2008-09-05 14:19:43 +0000775{
aurel3274637402008-11-01 00:54:12 +0000776 TCGv t0, t1;
777
778 if ((!compute_ca && !compute_ov) ||
pbrooka7812ae2008-11-17 14:43:54 +0000779 (!TCGV_EQUAL(ret,arg1) && !TCGV_EQUAL(ret, arg2))) {
aurel3274637402008-11-01 00:54:12 +0000780 t0 = ret;
781 } else {
pbrooka7812ae2008-11-17 14:43:54 +0000782 t0 = tcg_temp_local_new();
aurel3274637402008-11-01 00:54:12 +0000783 }
784
785 if (add_ca) {
pbrooka7812ae2008-11-17 14:43:54 +0000786 t1 = tcg_temp_local_new();
aurel3274637402008-11-01 00:54:12 +0000787 tcg_gen_andi_tl(t1, cpu_xer, (1 << XER_CA));
788 tcg_gen_shri_tl(t1, t1, XER_CA);
malcd2e9fd82009-06-20 05:51:47 +0400789 } else {
790 TCGV_UNUSED(t1);
aurel3274637402008-11-01 00:54:12 +0000791 }
792
793 if (compute_ca && compute_ov) {
794 /* Start with XER CA and OV disabled, the most likely case */
795 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~((1 << XER_CA) | (1 << XER_OV)));
796 } else if (compute_ca) {
797 /* Start with XER CA disabled, the most likely case */
798 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
799 } else if (compute_ov) {
800 /* Start with XER OV disabled, the most likely case */
801 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
802 }
803
804 tcg_gen_add_tl(t0, arg1, arg2);
805
806 if (compute_ca) {
807 gen_op_arith_compute_ca(ctx, t0, arg1, 0);
808 }
809 if (add_ca) {
810 tcg_gen_add_tl(t0, t0, t1);
811 gen_op_arith_compute_ca(ctx, t0, t1, 0);
812 tcg_temp_free(t1);
813 }
814 if (compute_ov) {
815 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0);
816 }
817
818 if (unlikely(Rc(ctx->opcode) != 0))
819 gen_set_Rc0(ctx, t0);
820
pbrooka7812ae2008-11-17 14:43:54 +0000821 if (!TCGV_EQUAL(t0, ret)) {
aurel3274637402008-11-01 00:54:12 +0000822 tcg_gen_mov_tl(ret, t0);
823 tcg_temp_free(t0);
824 }
aurel3239dd32e2008-09-05 14:19:43 +0000825}
aurel3274637402008-11-01 00:54:12 +0000826/* Add functions with two operands */
827#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
Blue Swirl99e300e2009-06-17 15:22:09 +0000828static void glue(gen_, name)(DisasContext *ctx) \
aurel3274637402008-11-01 00:54:12 +0000829{ \
830 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
831 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
832 add_ca, compute_ca, compute_ov); \
j_mayerd9bce9d2007-03-17 14:02:15 +0000833}
aurel3274637402008-11-01 00:54:12 +0000834/* Add functions with one operand and one immediate */
835#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
836 add_ca, compute_ca, compute_ov) \
Blue Swirl99e300e2009-06-17 15:22:09 +0000837static void glue(gen_, name)(DisasContext *ctx) \
aurel3274637402008-11-01 00:54:12 +0000838{ \
839 TCGv t0 = tcg_const_local_tl(const_val); \
840 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
841 cpu_gpr[rA(ctx->opcode)], t0, \
842 add_ca, compute_ca, compute_ov); \
843 tcg_temp_free(t0); \
j_mayerd9bce9d2007-03-17 14:02:15 +0000844}
aurel3274637402008-11-01 00:54:12 +0000845
846/* add add. addo addo. */
847GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
848GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
849/* addc addc. addco addco. */
850GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
851GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
852/* adde adde. addeo addeo. */
853GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
854GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
bellard79aceca2003-11-23 14:55:54 +0000855/* addme addme. addmeo addmeo. */
aurel3274637402008-11-01 00:54:12 +0000856GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
857GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
858/* addze addze. addzeo addzeo.*/
859GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
860GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
bellard79aceca2003-11-23 14:55:54 +0000861/* addi */
Blue Swirl99e300e2009-06-17 15:22:09 +0000862static void gen_addi(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +0000863{
j_mayer76a66252007-03-07 08:32:30 +0000864 target_long simm = SIMM(ctx->opcode);
bellard79aceca2003-11-23 14:55:54 +0000865
866 if (rA(ctx->opcode) == 0) {
j_mayer76a66252007-03-07 08:32:30 +0000867 /* li case */
aurel3274637402008-11-01 00:54:12 +0000868 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm);
bellard79aceca2003-11-23 14:55:54 +0000869 } else {
aurel3274637402008-11-01 00:54:12 +0000870 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], simm);
bellard79aceca2003-11-23 14:55:54 +0000871 }
bellard79aceca2003-11-23 14:55:54 +0000872}
aurel3274637402008-11-01 00:54:12 +0000873/* addic addic.*/
Blue Swirl636aa202009-08-16 09:06:54 +0000874static inline void gen_op_addic(DisasContext *ctx, TCGv ret, TCGv arg1,
875 int compute_Rc0)
aurel3274637402008-11-01 00:54:12 +0000876{
877 target_long simm = SIMM(ctx->opcode);
878
879 /* Start with XER CA and OV disabled, the most likely case */
880 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
881
882 if (likely(simm != 0)) {
pbrooka7812ae2008-11-17 14:43:54 +0000883 TCGv t0 = tcg_temp_local_new();
aurel3274637402008-11-01 00:54:12 +0000884 tcg_gen_addi_tl(t0, arg1, simm);
885 gen_op_arith_compute_ca(ctx, t0, arg1, 0);
886 tcg_gen_mov_tl(ret, t0);
887 tcg_temp_free(t0);
888 } else {
889 tcg_gen_mov_tl(ret, arg1);
890 }
891 if (compute_Rc0) {
892 gen_set_Rc0(ctx, ret);
893 }
894}
Blue Swirl99e300e2009-06-17 15:22:09 +0000895
896static void gen_addic(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +0000897{
aurel3274637402008-11-01 00:54:12 +0000898 gen_op_addic(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0);
bellard79aceca2003-11-23 14:55:54 +0000899}
Blue Swirle8eaa2c2009-06-17 15:22:14 +0000900
901static void gen_addic_(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +0000902{
aurel3274637402008-11-01 00:54:12 +0000903 gen_op_addic(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 1);
bellard79aceca2003-11-23 14:55:54 +0000904}
Blue Swirl99e300e2009-06-17 15:22:09 +0000905
Blue Swirl54623272009-06-17 15:22:19 +0000906/* addis */
Blue Swirl99e300e2009-06-17 15:22:09 +0000907static void gen_addis(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +0000908{
j_mayer76a66252007-03-07 08:32:30 +0000909 target_long simm = SIMM(ctx->opcode);
bellard79aceca2003-11-23 14:55:54 +0000910
911 if (rA(ctx->opcode) == 0) {
j_mayer76a66252007-03-07 08:32:30 +0000912 /* lis case */
aurel3274637402008-11-01 00:54:12 +0000913 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16);
bellard79aceca2003-11-23 14:55:54 +0000914 } else {
aurel3274637402008-11-01 00:54:12 +0000915 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], simm << 16);
bellard79aceca2003-11-23 14:55:54 +0000916 }
aurel3274637402008-11-01 00:54:12 +0000917}
918
Blue Swirl636aa202009-08-16 09:06:54 +0000919static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1,
920 TCGv arg2, int sign, int compute_ov)
aurel3274637402008-11-01 00:54:12 +0000921{
aurel322ef1b122008-11-09 17:27:19 +0000922 int l1 = gen_new_label();
923 int l2 = gen_new_label();
pbrooka7812ae2008-11-17 14:43:54 +0000924 TCGv_i32 t0 = tcg_temp_local_new_i32();
925 TCGv_i32 t1 = tcg_temp_local_new_i32();
aurel3274637402008-11-01 00:54:12 +0000926
aurel322ef1b122008-11-09 17:27:19 +0000927 tcg_gen_trunc_tl_i32(t0, arg1);
928 tcg_gen_trunc_tl_i32(t1, arg2);
929 tcg_gen_brcondi_i32(TCG_COND_EQ, t1, 0, l1);
aurel3274637402008-11-01 00:54:12 +0000930 if (sign) {
aurel322ef1b122008-11-09 17:27:19 +0000931 int l3 = gen_new_label();
932 tcg_gen_brcondi_i32(TCG_COND_NE, t1, -1, l3);
933 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, INT32_MIN, l1);
aurel3274637402008-11-01 00:54:12 +0000934 gen_set_label(l3);
aurel322ef1b122008-11-09 17:27:19 +0000935 tcg_gen_div_i32(t0, t0, t1);
aurel3274637402008-11-01 00:54:12 +0000936 } else {
aurel322ef1b122008-11-09 17:27:19 +0000937 tcg_gen_divu_i32(t0, t0, t1);
aurel3274637402008-11-01 00:54:12 +0000938 }
939 if (compute_ov) {
940 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
941 }
942 tcg_gen_br(l2);
943 gen_set_label(l1);
944 if (sign) {
aurel322ef1b122008-11-09 17:27:19 +0000945 tcg_gen_sari_i32(t0, t0, 31);
aurel3274637402008-11-01 00:54:12 +0000946 } else {
947 tcg_gen_movi_i32(t0, 0);
948 }
949 if (compute_ov) {
950 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
951 }
952 gen_set_label(l2);
aurel322ef1b122008-11-09 17:27:19 +0000953 tcg_gen_extu_i32_tl(ret, t0);
pbrooka7812ae2008-11-17 14:43:54 +0000954 tcg_temp_free_i32(t0);
955 tcg_temp_free_i32(t1);
aurel3274637402008-11-01 00:54:12 +0000956 if (unlikely(Rc(ctx->opcode) != 0))
957 gen_set_Rc0(ctx, ret);
958}
959/* Div functions */
960#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
Blue Swirl99e300e2009-06-17 15:22:09 +0000961static void glue(gen_, name)(DisasContext *ctx) \
aurel3274637402008-11-01 00:54:12 +0000962{ \
963 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
964 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
965 sign, compute_ov); \
966}
967/* divwu divwu. divwuo divwuo. */
968GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0);
969GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1);
970/* divw divw. divwo divwo. */
971GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0);
972GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1);
973#if defined(TARGET_PPC64)
Blue Swirl636aa202009-08-16 09:06:54 +0000974static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, TCGv arg1,
975 TCGv arg2, int sign, int compute_ov)
aurel3274637402008-11-01 00:54:12 +0000976{
aurel322ef1b122008-11-09 17:27:19 +0000977 int l1 = gen_new_label();
978 int l2 = gen_new_label();
aurel3274637402008-11-01 00:54:12 +0000979
980 tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1);
981 if (sign) {
aurel322ef1b122008-11-09 17:27:19 +0000982 int l3 = gen_new_label();
aurel3274637402008-11-01 00:54:12 +0000983 tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3);
984 tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1);
985 gen_set_label(l3);
aurel3274637402008-11-01 00:54:12 +0000986 tcg_gen_div_i64(ret, arg1, arg2);
987 } else {
988 tcg_gen_divu_i64(ret, arg1, arg2);
989 }
990 if (compute_ov) {
991 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
992 }
993 tcg_gen_br(l2);
994 gen_set_label(l1);
995 if (sign) {
996 tcg_gen_sari_i64(ret, arg1, 63);
997 } else {
998 tcg_gen_movi_i64(ret, 0);
999 }
1000 if (compute_ov) {
1001 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
1002 }
1003 gen_set_label(l2);
1004 if (unlikely(Rc(ctx->opcode) != 0))
1005 gen_set_Rc0(ctx, ret);
1006}
1007#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
Blue Swirl99e300e2009-06-17 15:22:09 +00001008static void glue(gen_, name)(DisasContext *ctx) \
aurel3274637402008-11-01 00:54:12 +00001009{ \
aurel322ef1b122008-11-09 17:27:19 +00001010 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1011 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1012 sign, compute_ov); \
aurel3274637402008-11-01 00:54:12 +00001013}
1014/* divwu divwu. divwuo divwuo. */
1015GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0);
1016GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1);
1017/* divw divw. divwo divwo. */
1018GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0);
1019GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1);
1020#endif
1021
1022/* mulhw mulhw. */
Blue Swirl99e300e2009-06-17 15:22:09 +00001023static void gen_mulhw(DisasContext *ctx)
aurel3274637402008-11-01 00:54:12 +00001024{
pbrooka7812ae2008-11-17 14:43:54 +00001025 TCGv_i64 t0, t1;
aurel3274637402008-11-01 00:54:12 +00001026
pbrooka7812ae2008-11-17 14:43:54 +00001027 t0 = tcg_temp_new_i64();
1028 t1 = tcg_temp_new_i64();
aurel3274637402008-11-01 00:54:12 +00001029#if defined(TARGET_PPC64)
1030 tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]);
1031 tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]);
1032 tcg_gen_mul_i64(t0, t0, t1);
1033 tcg_gen_shri_i64(cpu_gpr[rD(ctx->opcode)], t0, 32);
1034#else
1035 tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1036 tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1037 tcg_gen_mul_i64(t0, t0, t1);
1038 tcg_gen_shri_i64(t0, t0, 32);
1039 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0);
1040#endif
pbrooka7812ae2008-11-17 14:43:54 +00001041 tcg_temp_free_i64(t0);
1042 tcg_temp_free_i64(t1);
aurel3274637402008-11-01 00:54:12 +00001043 if (unlikely(Rc(ctx->opcode) != 0))
1044 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1045}
Blue Swirl99e300e2009-06-17 15:22:09 +00001046
Blue Swirl54623272009-06-17 15:22:19 +00001047/* mulhwu mulhwu. */
Blue Swirl99e300e2009-06-17 15:22:09 +00001048static void gen_mulhwu(DisasContext *ctx)
aurel3274637402008-11-01 00:54:12 +00001049{
pbrooka7812ae2008-11-17 14:43:54 +00001050 TCGv_i64 t0, t1;
aurel3274637402008-11-01 00:54:12 +00001051
pbrooka7812ae2008-11-17 14:43:54 +00001052 t0 = tcg_temp_new_i64();
1053 t1 = tcg_temp_new_i64();
aurel3274637402008-11-01 00:54:12 +00001054#if defined(TARGET_PPC64)
1055 tcg_gen_ext32u_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1056 tcg_gen_ext32u_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1057 tcg_gen_mul_i64(t0, t0, t1);
1058 tcg_gen_shri_i64(cpu_gpr[rD(ctx->opcode)], t0, 32);
1059#else
1060 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1061 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1062 tcg_gen_mul_i64(t0, t0, t1);
1063 tcg_gen_shri_i64(t0, t0, 32);
1064 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0);
1065#endif
pbrooka7812ae2008-11-17 14:43:54 +00001066 tcg_temp_free_i64(t0);
1067 tcg_temp_free_i64(t1);
aurel3274637402008-11-01 00:54:12 +00001068 if (unlikely(Rc(ctx->opcode) != 0))
1069 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1070}
Blue Swirl99e300e2009-06-17 15:22:09 +00001071
Blue Swirl54623272009-06-17 15:22:19 +00001072/* mullw mullw. */
Blue Swirl99e300e2009-06-17 15:22:09 +00001073static void gen_mullw(DisasContext *ctx)
aurel3274637402008-11-01 00:54:12 +00001074{
aurel3274637402008-11-01 00:54:12 +00001075 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1076 cpu_gpr[rB(ctx->opcode)]);
aurel321e4c0902008-11-09 17:27:11 +00001077 tcg_gen_ext32s_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)]);
aurel3274637402008-11-01 00:54:12 +00001078 if (unlikely(Rc(ctx->opcode) != 0))
1079 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1080}
Blue Swirl99e300e2009-06-17 15:22:09 +00001081
Blue Swirl54623272009-06-17 15:22:19 +00001082/* mullwo mullwo. */
Blue Swirl99e300e2009-06-17 15:22:09 +00001083static void gen_mullwo(DisasContext *ctx)
aurel3274637402008-11-01 00:54:12 +00001084{
1085 int l1;
pbrooka7812ae2008-11-17 14:43:54 +00001086 TCGv_i64 t0, t1;
aurel3274637402008-11-01 00:54:12 +00001087
pbrooka7812ae2008-11-17 14:43:54 +00001088 t0 = tcg_temp_new_i64();
1089 t1 = tcg_temp_new_i64();
aurel3274637402008-11-01 00:54:12 +00001090 l1 = gen_new_label();
1091 /* Start with XER OV disabled, the most likely case */
1092 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
1093#if defined(TARGET_PPC64)
1094 tcg_gen_ext32s_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1095 tcg_gen_ext32s_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1096#else
1097 tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1098 tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1099#endif
1100 tcg_gen_mul_i64(t0, t0, t1);
1101#if defined(TARGET_PPC64)
1102 tcg_gen_ext32s_i64(cpu_gpr[rD(ctx->opcode)], t0);
1103 tcg_gen_brcond_i64(TCG_COND_EQ, t0, cpu_gpr[rD(ctx->opcode)], l1);
1104#else
1105 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0);
1106 tcg_gen_ext32s_i64(t1, t0);
1107 tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1);
1108#endif
1109 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
1110 gen_set_label(l1);
pbrooka7812ae2008-11-17 14:43:54 +00001111 tcg_temp_free_i64(t0);
1112 tcg_temp_free_i64(t1);
aurel3274637402008-11-01 00:54:12 +00001113 if (unlikely(Rc(ctx->opcode) != 0))
1114 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
bellard79aceca2003-11-23 14:55:54 +00001115}
Blue Swirl99e300e2009-06-17 15:22:09 +00001116
Blue Swirl54623272009-06-17 15:22:19 +00001117/* mulli */
Blue Swirl99e300e2009-06-17 15:22:09 +00001118static void gen_mulli(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00001119{
aurel3274637402008-11-01 00:54:12 +00001120 tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1121 SIMM(ctx->opcode));
bellard79aceca2003-11-23 14:55:54 +00001122}
aurel3274637402008-11-01 00:54:12 +00001123#if defined(TARGET_PPC64)
1124#define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
Blue Swirl99e300e2009-06-17 15:22:09 +00001125static void glue(gen_, name)(DisasContext *ctx) \
aurel3274637402008-11-01 00:54:12 +00001126{ \
pbrooka7812ae2008-11-17 14:43:54 +00001127 gen_helper_##name (cpu_gpr[rD(ctx->opcode)], \
aurel3274637402008-11-01 00:54:12 +00001128 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
1129 if (unlikely(Rc(ctx->opcode) != 0)) \
1130 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1131}
1132/* mulhd mulhd. */
1133GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00);
1134/* mulhdu mulhdu. */
1135GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02);
Blue Swirl99e300e2009-06-17 15:22:09 +00001136
Blue Swirl54623272009-06-17 15:22:19 +00001137/* mulld mulld. */
Blue Swirl99e300e2009-06-17 15:22:09 +00001138static void gen_mulld(DisasContext *ctx)
aurel3274637402008-11-01 00:54:12 +00001139{
1140 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1141 cpu_gpr[rB(ctx->opcode)]);
1142 if (unlikely(Rc(ctx->opcode) != 0))
1143 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1144}
1145/* mulldo mulldo. */
1146GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17);
1147#endif
1148
1149/* neg neg. nego nego. */
Blue Swirl636aa202009-08-16 09:06:54 +00001150static inline void gen_op_arith_neg(DisasContext *ctx, TCGv ret, TCGv arg1,
1151 int ov_check)
aurel3274637402008-11-01 00:54:12 +00001152{
aurel32ec6469a2008-11-09 17:27:27 +00001153 int l1 = gen_new_label();
1154 int l2 = gen_new_label();
pbrooka7812ae2008-11-17 14:43:54 +00001155 TCGv t0 = tcg_temp_local_new();
aurel3274637402008-11-01 00:54:12 +00001156#if defined(TARGET_PPC64)
1157 if (ctx->sf_mode) {
aurel32741a7442008-11-09 18:27:28 +00001158 tcg_gen_mov_tl(t0, arg1);
aurel32ec6469a2008-11-09 17:27:27 +00001159 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, INT64_MIN, l1);
1160 } else
1161#endif
1162 {
1163 tcg_gen_ext32s_tl(t0, arg1);
aurel3274637402008-11-01 00:54:12 +00001164 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, INT32_MIN, l1);
1165 }
aurel3274637402008-11-01 00:54:12 +00001166 tcg_gen_neg_tl(ret, arg1);
1167 if (ov_check) {
1168 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
1169 }
1170 tcg_gen_br(l2);
1171 gen_set_label(l1);
aurel32ec6469a2008-11-09 17:27:27 +00001172 tcg_gen_mov_tl(ret, t0);
aurel3274637402008-11-01 00:54:12 +00001173 if (ov_check) {
1174 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
1175 }
1176 gen_set_label(l2);
aurel32ec6469a2008-11-09 17:27:27 +00001177 tcg_temp_free(t0);
aurel3274637402008-11-01 00:54:12 +00001178 if (unlikely(Rc(ctx->opcode) != 0))
1179 gen_set_Rc0(ctx, ret);
1180}
Blue Swirl99e300e2009-06-17 15:22:09 +00001181
1182static void gen_neg(DisasContext *ctx)
aurel3274637402008-11-01 00:54:12 +00001183{
aurel32ec6469a2008-11-09 17:27:27 +00001184 gen_op_arith_neg(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0);
aurel3274637402008-11-01 00:54:12 +00001185}
Blue Swirl99e300e2009-06-17 15:22:09 +00001186
1187static void gen_nego(DisasContext *ctx)
aurel3274637402008-11-01 00:54:12 +00001188{
aurel32ec6469a2008-11-09 17:27:27 +00001189 gen_op_arith_neg(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 1);
aurel3274637402008-11-01 00:54:12 +00001190}
1191
1192/* Common subf function */
Blue Swirl636aa202009-08-16 09:06:54 +00001193static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1,
1194 TCGv arg2, int add_ca, int compute_ca,
1195 int compute_ov)
aurel3274637402008-11-01 00:54:12 +00001196{
1197 TCGv t0, t1;
1198
1199 if ((!compute_ca && !compute_ov) ||
pbrooka7812ae2008-11-17 14:43:54 +00001200 (!TCGV_EQUAL(ret, arg1) && !TCGV_EQUAL(ret, arg2))) {
aurel3274637402008-11-01 00:54:12 +00001201 t0 = ret;
1202 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001203 t0 = tcg_temp_local_new();
aurel3274637402008-11-01 00:54:12 +00001204 }
1205
1206 if (add_ca) {
pbrooka7812ae2008-11-17 14:43:54 +00001207 t1 = tcg_temp_local_new();
aurel3274637402008-11-01 00:54:12 +00001208 tcg_gen_andi_tl(t1, cpu_xer, (1 << XER_CA));
1209 tcg_gen_shri_tl(t1, t1, XER_CA);
malcd2e9fd82009-06-20 05:51:47 +04001210 } else {
1211 TCGV_UNUSED(t1);
aurel3274637402008-11-01 00:54:12 +00001212 }
1213
1214 if (compute_ca && compute_ov) {
1215 /* Start with XER CA and OV disabled, the most likely case */
1216 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~((1 << XER_CA) | (1 << XER_OV)));
1217 } else if (compute_ca) {
1218 /* Start with XER CA disabled, the most likely case */
1219 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
1220 } else if (compute_ov) {
1221 /* Start with XER OV disabled, the most likely case */
1222 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
1223 }
1224
1225 if (add_ca) {
1226 tcg_gen_not_tl(t0, arg1);
1227 tcg_gen_add_tl(t0, t0, arg2);
1228 gen_op_arith_compute_ca(ctx, t0, arg2, 0);
1229 tcg_gen_add_tl(t0, t0, t1);
1230 gen_op_arith_compute_ca(ctx, t0, t1, 0);
1231 tcg_temp_free(t1);
1232 } else {
1233 tcg_gen_sub_tl(t0, arg2, arg1);
1234 if (compute_ca) {
1235 gen_op_arith_compute_ca(ctx, t0, arg2, 1);
1236 }
1237 }
1238 if (compute_ov) {
1239 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1);
1240 }
1241
1242 if (unlikely(Rc(ctx->opcode) != 0))
1243 gen_set_Rc0(ctx, t0);
1244
pbrooka7812ae2008-11-17 14:43:54 +00001245 if (!TCGV_EQUAL(t0, ret)) {
aurel3274637402008-11-01 00:54:12 +00001246 tcg_gen_mov_tl(ret, t0);
1247 tcg_temp_free(t0);
1248 }
1249}
1250/* Sub functions with Two operands functions */
1251#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
Blue Swirl99e300e2009-06-17 15:22:09 +00001252static void glue(gen_, name)(DisasContext *ctx) \
aurel3274637402008-11-01 00:54:12 +00001253{ \
1254 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1255 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1256 add_ca, compute_ca, compute_ov); \
1257}
1258/* Sub functions with one operand and one immediate */
1259#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1260 add_ca, compute_ca, compute_ov) \
Blue Swirl99e300e2009-06-17 15:22:09 +00001261static void glue(gen_, name)(DisasContext *ctx) \
aurel3274637402008-11-01 00:54:12 +00001262{ \
1263 TCGv t0 = tcg_const_local_tl(const_val); \
1264 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1265 cpu_gpr[rA(ctx->opcode)], t0, \
1266 add_ca, compute_ca, compute_ov); \
1267 tcg_temp_free(t0); \
1268}
1269/* subf subf. subfo subfo. */
1270GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
1271GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
1272/* subfc subfc. subfco subfco. */
1273GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
1274GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
1275/* subfe subfe. subfeo subfo. */
1276GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
1277GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
1278/* subfme subfme. subfmeo subfmeo. */
1279GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
1280GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
1281/* subfze subfze. subfzeo subfzeo.*/
1282GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
1283GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
Blue Swirl99e300e2009-06-17 15:22:09 +00001284
Blue Swirl54623272009-06-17 15:22:19 +00001285/* subfic */
Blue Swirl99e300e2009-06-17 15:22:09 +00001286static void gen_subfic(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00001287{
aurel3274637402008-11-01 00:54:12 +00001288 /* Start with XER CA and OV disabled, the most likely case */
1289 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
pbrooka7812ae2008-11-17 14:43:54 +00001290 TCGv t0 = tcg_temp_local_new();
aurel3274637402008-11-01 00:54:12 +00001291 TCGv t1 = tcg_const_local_tl(SIMM(ctx->opcode));
1292 tcg_gen_sub_tl(t0, t1, cpu_gpr[rA(ctx->opcode)]);
1293 gen_op_arith_compute_ca(ctx, t0, t1, 1);
1294 tcg_temp_free(t1);
1295 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
1296 tcg_temp_free(t0);
bellard79aceca2003-11-23 14:55:54 +00001297}
1298
bellard79aceca2003-11-23 14:55:54 +00001299/*** Integer logical ***/
aurel3226d67362008-10-21 11:31:27 +00001300#define GEN_LOGICAL2(name, tcg_op, opc, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00001301static void glue(gen_, name)(DisasContext *ctx) \
bellard79aceca2003-11-23 14:55:54 +00001302{ \
aurel3226d67362008-10-21 11:31:27 +00001303 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1304 cpu_gpr[rB(ctx->opcode)]); \
j_mayer76a66252007-03-07 08:32:30 +00001305 if (unlikely(Rc(ctx->opcode) != 0)) \
aurel3226d67362008-10-21 11:31:27 +00001306 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
bellard79aceca2003-11-23 14:55:54 +00001307}
bellard79aceca2003-11-23 14:55:54 +00001308
aurel3226d67362008-10-21 11:31:27 +00001309#define GEN_LOGICAL1(name, tcg_op, opc, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00001310static void glue(gen_, name)(DisasContext *ctx) \
bellard79aceca2003-11-23 14:55:54 +00001311{ \
aurel3226d67362008-10-21 11:31:27 +00001312 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
j_mayer76a66252007-03-07 08:32:30 +00001313 if (unlikely(Rc(ctx->opcode) != 0)) \
aurel3226d67362008-10-21 11:31:27 +00001314 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
bellard79aceca2003-11-23 14:55:54 +00001315}
1316
1317/* and & and. */
aurel3226d67362008-10-21 11:31:27 +00001318GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER);
bellard79aceca2003-11-23 14:55:54 +00001319/* andc & andc. */
aurel3226d67362008-10-21 11:31:27 +00001320GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER);
Blue Swirle8eaa2c2009-06-17 15:22:14 +00001321
Blue Swirl54623272009-06-17 15:22:19 +00001322/* andi. */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00001323static void gen_andi_(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00001324{
aurel3226d67362008-10-21 11:31:27 +00001325 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode));
1326 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
bellard79aceca2003-11-23 14:55:54 +00001327}
Blue Swirle8eaa2c2009-06-17 15:22:14 +00001328
Blue Swirl54623272009-06-17 15:22:19 +00001329/* andis. */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00001330static void gen_andis_(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00001331{
aurel3226d67362008-10-21 11:31:27 +00001332 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16);
1333 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
bellard79aceca2003-11-23 14:55:54 +00001334}
Blue Swirl99e300e2009-06-17 15:22:09 +00001335
Blue Swirl54623272009-06-17 15:22:19 +00001336/* cntlzw */
Blue Swirl99e300e2009-06-17 15:22:09 +00001337static void gen_cntlzw(DisasContext *ctx)
aurel3226d67362008-10-21 11:31:27 +00001338{
pbrooka7812ae2008-11-17 14:43:54 +00001339 gen_helper_cntlzw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
aurel3226d67362008-10-21 11:31:27 +00001340 if (unlikely(Rc(ctx->opcode) != 0))
pbrook2e31f5d2008-10-24 12:03:16 +00001341 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
aurel3226d67362008-10-21 11:31:27 +00001342}
bellard79aceca2003-11-23 14:55:54 +00001343/* eqv & eqv. */
aurel3226d67362008-10-21 11:31:27 +00001344GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER);
bellard79aceca2003-11-23 14:55:54 +00001345/* extsb & extsb. */
aurel3226d67362008-10-21 11:31:27 +00001346GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER);
bellard79aceca2003-11-23 14:55:54 +00001347/* extsh & extsh. */
aurel3226d67362008-10-21 11:31:27 +00001348GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER);
bellard79aceca2003-11-23 14:55:54 +00001349/* nand & nand. */
aurel3226d67362008-10-21 11:31:27 +00001350GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER);
bellard79aceca2003-11-23 14:55:54 +00001351/* nor & nor. */
aurel3226d67362008-10-21 11:31:27 +00001352GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER);
Blue Swirl99e300e2009-06-17 15:22:09 +00001353
Blue Swirl54623272009-06-17 15:22:19 +00001354/* or & or. */
Blue Swirl99e300e2009-06-17 15:22:09 +00001355static void gen_or(DisasContext *ctx)
bellard9a64fbe2004-01-04 22:58:38 +00001356{
j_mayer76a66252007-03-07 08:32:30 +00001357 int rs, ra, rb;
1358
1359 rs = rS(ctx->opcode);
1360 ra = rA(ctx->opcode);
1361 rb = rB(ctx->opcode);
1362 /* Optimisation for mr. ri case */
1363 if (rs != ra || rs != rb) {
aurel3226d67362008-10-21 11:31:27 +00001364 if (rs != rb)
1365 tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]);
1366 else
1367 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]);
j_mayer76a66252007-03-07 08:32:30 +00001368 if (unlikely(Rc(ctx->opcode) != 0))
aurel3226d67362008-10-21 11:31:27 +00001369 gen_set_Rc0(ctx, cpu_gpr[ra]);
j_mayer76a66252007-03-07 08:32:30 +00001370 } else if (unlikely(Rc(ctx->opcode) != 0)) {
aurel3226d67362008-10-21 11:31:27 +00001371 gen_set_Rc0(ctx, cpu_gpr[rs]);
j_mayerc80f84e2007-09-30 01:18:26 +00001372#if defined(TARGET_PPC64)
1373 } else {
aurel3226d67362008-10-21 11:31:27 +00001374 int prio = 0;
1375
j_mayerc80f84e2007-09-30 01:18:26 +00001376 switch (rs) {
1377 case 1:
1378 /* Set process priority to low */
aurel3226d67362008-10-21 11:31:27 +00001379 prio = 2;
j_mayerc80f84e2007-09-30 01:18:26 +00001380 break;
1381 case 6:
1382 /* Set process priority to medium-low */
aurel3226d67362008-10-21 11:31:27 +00001383 prio = 3;
j_mayerc80f84e2007-09-30 01:18:26 +00001384 break;
1385 case 2:
1386 /* Set process priority to normal */
aurel3226d67362008-10-21 11:31:27 +00001387 prio = 4;
j_mayerc80f84e2007-09-30 01:18:26 +00001388 break;
j_mayerbe147d02007-09-30 13:03:23 +00001389#if !defined(CONFIG_USER_ONLY)
1390 case 31:
aurel3276db3ba2008-12-08 18:11:21 +00001391 if (ctx->mem_idx > 0) {
j_mayerbe147d02007-09-30 13:03:23 +00001392 /* Set process priority to very low */
aurel3226d67362008-10-21 11:31:27 +00001393 prio = 1;
j_mayerbe147d02007-09-30 13:03:23 +00001394 }
1395 break;
1396 case 5:
aurel3276db3ba2008-12-08 18:11:21 +00001397 if (ctx->mem_idx > 0) {
j_mayerbe147d02007-09-30 13:03:23 +00001398 /* Set process priority to medium-hight */
aurel3226d67362008-10-21 11:31:27 +00001399 prio = 5;
j_mayerbe147d02007-09-30 13:03:23 +00001400 }
1401 break;
1402 case 3:
aurel3276db3ba2008-12-08 18:11:21 +00001403 if (ctx->mem_idx > 0) {
j_mayerbe147d02007-09-30 13:03:23 +00001404 /* Set process priority to high */
aurel3226d67362008-10-21 11:31:27 +00001405 prio = 6;
j_mayerbe147d02007-09-30 13:03:23 +00001406 }
1407 break;
j_mayerbe147d02007-09-30 13:03:23 +00001408 case 7:
aurel3276db3ba2008-12-08 18:11:21 +00001409 if (ctx->mem_idx > 1) {
j_mayerbe147d02007-09-30 13:03:23 +00001410 /* Set process priority to very high */
aurel3226d67362008-10-21 11:31:27 +00001411 prio = 7;
j_mayerbe147d02007-09-30 13:03:23 +00001412 }
1413 break;
1414#endif
j_mayerc80f84e2007-09-30 01:18:26 +00001415 default:
1416 /* nop */
1417 break;
1418 }
aurel3226d67362008-10-21 11:31:27 +00001419 if (prio) {
pbrooka7812ae2008-11-17 14:43:54 +00001420 TCGv t0 = tcg_temp_new();
aurel3254cdcae2008-12-05 07:21:31 +00001421 gen_load_spr(t0, SPR_PPR);
aurel32ea363692008-10-27 22:50:39 +00001422 tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL);
1423 tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50);
aurel3254cdcae2008-12-05 07:21:31 +00001424 gen_store_spr(SPR_PPR, t0);
aurel32ea363692008-10-27 22:50:39 +00001425 tcg_temp_free(t0);
aurel3226d67362008-10-21 11:31:27 +00001426 }
j_mayerc80f84e2007-09-30 01:18:26 +00001427#endif
bellard9a64fbe2004-01-04 22:58:38 +00001428 }
bellard9a64fbe2004-01-04 22:58:38 +00001429}
bellard79aceca2003-11-23 14:55:54 +00001430/* orc & orc. */
aurel3226d67362008-10-21 11:31:27 +00001431GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER);
Blue Swirl99e300e2009-06-17 15:22:09 +00001432
Blue Swirl54623272009-06-17 15:22:19 +00001433/* xor & xor. */
Blue Swirl99e300e2009-06-17 15:22:09 +00001434static void gen_xor(DisasContext *ctx)
bellard9a64fbe2004-01-04 22:58:38 +00001435{
bellard9a64fbe2004-01-04 22:58:38 +00001436 /* Optimisation for "set to zero" case */
aurel3226d67362008-10-21 11:31:27 +00001437 if (rS(ctx->opcode) != rB(ctx->opcode))
aurel32312179c2008-10-27 22:50:31 +00001438 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
aurel3226d67362008-10-21 11:31:27 +00001439 else
1440 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
j_mayer76a66252007-03-07 08:32:30 +00001441 if (unlikely(Rc(ctx->opcode) != 0))
aurel3226d67362008-10-21 11:31:27 +00001442 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
bellard9a64fbe2004-01-04 22:58:38 +00001443}
Blue Swirl99e300e2009-06-17 15:22:09 +00001444
Blue Swirl54623272009-06-17 15:22:19 +00001445/* ori */
Blue Swirl99e300e2009-06-17 15:22:09 +00001446static void gen_ori(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00001447{
j_mayer76a66252007-03-07 08:32:30 +00001448 target_ulong uimm = UIMM(ctx->opcode);
bellard79aceca2003-11-23 14:55:54 +00001449
bellard9a64fbe2004-01-04 22:58:38 +00001450 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1451 /* NOP */
j_mayer76a66252007-03-07 08:32:30 +00001452 /* XXX: should handle special NOPs for POWER series */
bellard9a64fbe2004-01-04 22:58:38 +00001453 return;
j_mayer76a66252007-03-07 08:32:30 +00001454 }
aurel3226d67362008-10-21 11:31:27 +00001455 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
bellard79aceca2003-11-23 14:55:54 +00001456}
Blue Swirl99e300e2009-06-17 15:22:09 +00001457
Blue Swirl54623272009-06-17 15:22:19 +00001458/* oris */
Blue Swirl99e300e2009-06-17 15:22:09 +00001459static void gen_oris(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00001460{
j_mayer76a66252007-03-07 08:32:30 +00001461 target_ulong uimm = UIMM(ctx->opcode);
bellard9a64fbe2004-01-04 22:58:38 +00001462
1463 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1464 /* NOP */
1465 return;
1466 }
aurel3226d67362008-10-21 11:31:27 +00001467 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
j_mayer76a66252007-03-07 08:32:30 +00001468}
Blue Swirl99e300e2009-06-17 15:22:09 +00001469
Blue Swirl54623272009-06-17 15:22:19 +00001470/* xori */
Blue Swirl99e300e2009-06-17 15:22:09 +00001471static void gen_xori(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00001472{
1473 target_ulong uimm = UIMM(ctx->opcode);
1474
1475 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1476 /* NOP */
1477 return;
1478 }
aurel3226d67362008-10-21 11:31:27 +00001479 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
bellard79aceca2003-11-23 14:55:54 +00001480}
Blue Swirl99e300e2009-06-17 15:22:09 +00001481
Blue Swirl54623272009-06-17 15:22:19 +00001482/* xoris */
Blue Swirl99e300e2009-06-17 15:22:09 +00001483static void gen_xoris(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00001484{
j_mayer76a66252007-03-07 08:32:30 +00001485 target_ulong uimm = UIMM(ctx->opcode);
bellard9a64fbe2004-01-04 22:58:38 +00001486
1487 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1488 /* NOP */
1489 return;
1490 }
aurel3226d67362008-10-21 11:31:27 +00001491 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
bellard79aceca2003-11-23 14:55:54 +00001492}
Blue Swirl99e300e2009-06-17 15:22:09 +00001493
Blue Swirl54623272009-06-17 15:22:19 +00001494/* popcntb : PowerPC 2.03 specification */
Blue Swirl99e300e2009-06-17 15:22:09 +00001495static void gen_popcntb(DisasContext *ctx)
j_mayerd9bce9d2007-03-17 14:02:15 +00001496{
David Gibsoneaabeef2011-04-01 15:15:13 +11001497 gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
j_mayerd9bce9d2007-03-17 14:02:15 +00001498}
1499
David Gibsoneaabeef2011-04-01 15:15:13 +11001500static void gen_popcntw(DisasContext *ctx)
1501{
1502 gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1503}
1504
1505#if defined(TARGET_PPC64)
1506/* popcntd: PowerPC 2.06 specification */
1507static void gen_popcntd(DisasContext *ctx)
1508{
1509 gen_helper_popcntd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1510}
1511#endif
1512
j_mayerd9bce9d2007-03-17 14:02:15 +00001513#if defined(TARGET_PPC64)
1514/* extsw & extsw. */
aurel3226d67362008-10-21 11:31:27 +00001515GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B);
Blue Swirl99e300e2009-06-17 15:22:09 +00001516
Blue Swirl54623272009-06-17 15:22:19 +00001517/* cntlzd */
Blue Swirl99e300e2009-06-17 15:22:09 +00001518static void gen_cntlzd(DisasContext *ctx)
aurel3226d67362008-10-21 11:31:27 +00001519{
pbrooka7812ae2008-11-17 14:43:54 +00001520 gen_helper_cntlzd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
aurel3226d67362008-10-21 11:31:27 +00001521 if (unlikely(Rc(ctx->opcode) != 0))
1522 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1523}
j_mayerd9bce9d2007-03-17 14:02:15 +00001524#endif
1525
bellard79aceca2003-11-23 14:55:54 +00001526/*** Integer rotate ***/
Blue Swirl99e300e2009-06-17 15:22:09 +00001527
Blue Swirl54623272009-06-17 15:22:19 +00001528/* rlwimi & rlwimi. */
Blue Swirl99e300e2009-06-17 15:22:09 +00001529static void gen_rlwimi(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00001530{
j_mayer76a66252007-03-07 08:32:30 +00001531 uint32_t mb, me, sh;
bellard79aceca2003-11-23 14:55:54 +00001532
1533 mb = MB(ctx->opcode);
1534 me = ME(ctx->opcode);
j_mayer76a66252007-03-07 08:32:30 +00001535 sh = SH(ctx->opcode);
aurel32d03ef512008-10-27 22:50:22 +00001536 if (likely(sh == 0 && mb == 0 && me == 31)) {
1537 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1538 } else {
aurel32d03ef512008-10-27 22:50:22 +00001539 target_ulong mask;
pbrooka7812ae2008-11-17 14:43:54 +00001540 TCGv t1;
1541 TCGv t0 = tcg_temp_new();
aurel3254843a52008-11-03 07:08:44 +00001542#if defined(TARGET_PPC64)
pbrooka7812ae2008-11-17 14:43:54 +00001543 TCGv_i32 t2 = tcg_temp_new_i32();
1544 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rS(ctx->opcode)]);
1545 tcg_gen_rotli_i32(t2, t2, sh);
1546 tcg_gen_extu_i32_i64(t0, t2);
1547 tcg_temp_free_i32(t2);
aurel3254843a52008-11-03 07:08:44 +00001548#else
1549 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1550#endif
j_mayer76a66252007-03-07 08:32:30 +00001551#if defined(TARGET_PPC64)
aurel32d03ef512008-10-27 22:50:22 +00001552 mb += 32;
1553 me += 32;
j_mayer76a66252007-03-07 08:32:30 +00001554#endif
aurel32d03ef512008-10-27 22:50:22 +00001555 mask = MASK(mb, me);
pbrooka7812ae2008-11-17 14:43:54 +00001556 t1 = tcg_temp_new();
aurel32d03ef512008-10-27 22:50:22 +00001557 tcg_gen_andi_tl(t0, t0, mask);
1558 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1559 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1560 tcg_temp_free(t0);
1561 tcg_temp_free(t1);
1562 }
j_mayer76a66252007-03-07 08:32:30 +00001563 if (unlikely(Rc(ctx->opcode) != 0))
aurel32d03ef512008-10-27 22:50:22 +00001564 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
bellard79aceca2003-11-23 14:55:54 +00001565}
Blue Swirl99e300e2009-06-17 15:22:09 +00001566
Blue Swirl54623272009-06-17 15:22:19 +00001567/* rlwinm & rlwinm. */
Blue Swirl99e300e2009-06-17 15:22:09 +00001568static void gen_rlwinm(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00001569{
1570 uint32_t mb, me, sh;
ths3b46e622007-09-17 08:09:54 +00001571
bellard79aceca2003-11-23 14:55:54 +00001572 sh = SH(ctx->opcode);
1573 mb = MB(ctx->opcode);
1574 me = ME(ctx->opcode);
aurel32d03ef512008-10-27 22:50:22 +00001575
1576 if (likely(mb == 0 && me == (31 - sh))) {
1577 if (likely(sh == 0)) {
1578 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1579 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001580 TCGv t0 = tcg_temp_new();
aurel32d03ef512008-10-27 22:50:22 +00001581 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1582 tcg_gen_shli_tl(t0, t0, sh);
1583 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1584 tcg_temp_free(t0);
bellard79aceca2003-11-23 14:55:54 +00001585 }
aurel32d03ef512008-10-27 22:50:22 +00001586 } else if (likely(sh != 0 && me == 31 && sh == (32 - mb))) {
pbrooka7812ae2008-11-17 14:43:54 +00001587 TCGv t0 = tcg_temp_new();
aurel32d03ef512008-10-27 22:50:22 +00001588 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1589 tcg_gen_shri_tl(t0, t0, mb);
1590 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1591 tcg_temp_free(t0);
1592 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001593 TCGv t0 = tcg_temp_new();
aurel3254843a52008-11-03 07:08:44 +00001594#if defined(TARGET_PPC64)
pbrooka7812ae2008-11-17 14:43:54 +00001595 TCGv_i32 t1 = tcg_temp_new_i32();
aurel3254843a52008-11-03 07:08:44 +00001596 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1597 tcg_gen_rotli_i32(t1, t1, sh);
1598 tcg_gen_extu_i32_i64(t0, t1);
pbrooka7812ae2008-11-17 14:43:54 +00001599 tcg_temp_free_i32(t1);
aurel3254843a52008-11-03 07:08:44 +00001600#else
1601 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1602#endif
j_mayer76a66252007-03-07 08:32:30 +00001603#if defined(TARGET_PPC64)
aurel32d03ef512008-10-27 22:50:22 +00001604 mb += 32;
1605 me += 32;
j_mayer76a66252007-03-07 08:32:30 +00001606#endif
aurel32d03ef512008-10-27 22:50:22 +00001607 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1608 tcg_temp_free(t0);
1609 }
j_mayer76a66252007-03-07 08:32:30 +00001610 if (unlikely(Rc(ctx->opcode) != 0))
aurel32d03ef512008-10-27 22:50:22 +00001611 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
bellard79aceca2003-11-23 14:55:54 +00001612}
Blue Swirl99e300e2009-06-17 15:22:09 +00001613
Blue Swirl54623272009-06-17 15:22:19 +00001614/* rlwnm & rlwnm. */
Blue Swirl99e300e2009-06-17 15:22:09 +00001615static void gen_rlwnm(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00001616{
1617 uint32_t mb, me;
aurel3254843a52008-11-03 07:08:44 +00001618 TCGv t0;
1619#if defined(TARGET_PPC64)
pbrooka7812ae2008-11-17 14:43:54 +00001620 TCGv_i32 t1, t2;
aurel3254843a52008-11-03 07:08:44 +00001621#endif
bellard79aceca2003-11-23 14:55:54 +00001622
1623 mb = MB(ctx->opcode);
1624 me = ME(ctx->opcode);
pbrooka7812ae2008-11-17 14:43:54 +00001625 t0 = tcg_temp_new();
aurel32d03ef512008-10-27 22:50:22 +00001626 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1f);
aurel3254843a52008-11-03 07:08:44 +00001627#if defined(TARGET_PPC64)
pbrooka7812ae2008-11-17 14:43:54 +00001628 t1 = tcg_temp_new_i32();
1629 t2 = tcg_temp_new_i32();
aurel3254843a52008-11-03 07:08:44 +00001630 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1631 tcg_gen_trunc_i64_i32(t2, t0);
1632 tcg_gen_rotl_i32(t1, t1, t2);
1633 tcg_gen_extu_i32_i64(t0, t1);
pbrooka7812ae2008-11-17 14:43:54 +00001634 tcg_temp_free_i32(t1);
1635 tcg_temp_free_i32(t2);
aurel3254843a52008-11-03 07:08:44 +00001636#else
1637 tcg_gen_rotl_i32(t0, cpu_gpr[rS(ctx->opcode)], t0);
1638#endif
j_mayer76a66252007-03-07 08:32:30 +00001639 if (unlikely(mb != 0 || me != 31)) {
1640#if defined(TARGET_PPC64)
1641 mb += 32;
1642 me += 32;
1643#endif
aurel3254843a52008-11-03 07:08:44 +00001644 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
aurel32d03ef512008-10-27 22:50:22 +00001645 } else {
aurel3254843a52008-11-03 07:08:44 +00001646 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
bellard79aceca2003-11-23 14:55:54 +00001647 }
aurel3254843a52008-11-03 07:08:44 +00001648 tcg_temp_free(t0);
j_mayer76a66252007-03-07 08:32:30 +00001649 if (unlikely(Rc(ctx->opcode) != 0))
aurel32d03ef512008-10-27 22:50:22 +00001650 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
bellard79aceca2003-11-23 14:55:54 +00001651}
1652
j_mayerd9bce9d2007-03-17 14:02:15 +00001653#if defined(TARGET_PPC64)
1654#define GEN_PPC64_R2(name, opc1, opc2) \
Blue Swirle8eaa2c2009-06-17 15:22:14 +00001655static void glue(gen_, name##0)(DisasContext *ctx) \
j_mayerd9bce9d2007-03-17 14:02:15 +00001656{ \
1657 gen_##name(ctx, 0); \
1658} \
Blue Swirle8eaa2c2009-06-17 15:22:14 +00001659 \
1660static void glue(gen_, name##1)(DisasContext *ctx) \
j_mayerd9bce9d2007-03-17 14:02:15 +00001661{ \
1662 gen_##name(ctx, 1); \
1663}
1664#define GEN_PPC64_R4(name, opc1, opc2) \
Blue Swirle8eaa2c2009-06-17 15:22:14 +00001665static void glue(gen_, name##0)(DisasContext *ctx) \
j_mayerd9bce9d2007-03-17 14:02:15 +00001666{ \
1667 gen_##name(ctx, 0, 0); \
1668} \
Blue Swirle8eaa2c2009-06-17 15:22:14 +00001669 \
1670static void glue(gen_, name##1)(DisasContext *ctx) \
j_mayerd9bce9d2007-03-17 14:02:15 +00001671{ \
1672 gen_##name(ctx, 0, 1); \
1673} \
Blue Swirle8eaa2c2009-06-17 15:22:14 +00001674 \
1675static void glue(gen_, name##2)(DisasContext *ctx) \
j_mayerd9bce9d2007-03-17 14:02:15 +00001676{ \
1677 gen_##name(ctx, 1, 0); \
1678} \
Blue Swirle8eaa2c2009-06-17 15:22:14 +00001679 \
1680static void glue(gen_, name##3)(DisasContext *ctx) \
j_mayerd9bce9d2007-03-17 14:02:15 +00001681{ \
1682 gen_##name(ctx, 1, 1); \
1683}
j_mayer51789c42007-03-22 22:41:50 +00001684
Blue Swirl636aa202009-08-16 09:06:54 +00001685static inline void gen_rldinm(DisasContext *ctx, uint32_t mb, uint32_t me,
1686 uint32_t sh)
j_mayer51789c42007-03-22 22:41:50 +00001687{
aurel32d03ef512008-10-27 22:50:22 +00001688 if (likely(sh != 0 && mb == 0 && me == (63 - sh))) {
1689 tcg_gen_shli_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
1690 } else if (likely(sh != 0 && me == 63 && sh == (64 - mb))) {
1691 tcg_gen_shri_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], mb);
1692 } else {
pbrooka7812ae2008-11-17 14:43:54 +00001693 TCGv t0 = tcg_temp_new();
aurel3254843a52008-11-03 07:08:44 +00001694 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
aurel32d03ef512008-10-27 22:50:22 +00001695 if (likely(mb == 0 && me == 63)) {
aurel3254843a52008-11-03 07:08:44 +00001696 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
aurel32d03ef512008-10-27 22:50:22 +00001697 } else {
1698 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
j_mayer51789c42007-03-22 22:41:50 +00001699 }
aurel32d03ef512008-10-27 22:50:22 +00001700 tcg_temp_free(t0);
j_mayer51789c42007-03-22 22:41:50 +00001701 }
j_mayer51789c42007-03-22 22:41:50 +00001702 if (unlikely(Rc(ctx->opcode) != 0))
aurel32d03ef512008-10-27 22:50:22 +00001703 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayer51789c42007-03-22 22:41:50 +00001704}
j_mayerd9bce9d2007-03-17 14:02:15 +00001705/* rldicl - rldicl. */
Blue Swirl636aa202009-08-16 09:06:54 +00001706static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn)
j_mayerd9bce9d2007-03-17 14:02:15 +00001707{
j_mayer51789c42007-03-22 22:41:50 +00001708 uint32_t sh, mb;
j_mayerd9bce9d2007-03-17 14:02:15 +00001709
j_mayer9d53c752007-04-06 07:59:47 +00001710 sh = SH(ctx->opcode) | (shn << 5);
1711 mb = MB(ctx->opcode) | (mbn << 5);
j_mayer51789c42007-03-22 22:41:50 +00001712 gen_rldinm(ctx, mb, 63, sh);
j_mayerd9bce9d2007-03-17 14:02:15 +00001713}
j_mayer51789c42007-03-22 22:41:50 +00001714GEN_PPC64_R4(rldicl, 0x1E, 0x00);
j_mayerd9bce9d2007-03-17 14:02:15 +00001715/* rldicr - rldicr. */
Blue Swirl636aa202009-08-16 09:06:54 +00001716static inline void gen_rldicr(DisasContext *ctx, int men, int shn)
j_mayerd9bce9d2007-03-17 14:02:15 +00001717{
j_mayer51789c42007-03-22 22:41:50 +00001718 uint32_t sh, me;
j_mayerd9bce9d2007-03-17 14:02:15 +00001719
j_mayer9d53c752007-04-06 07:59:47 +00001720 sh = SH(ctx->opcode) | (shn << 5);
1721 me = MB(ctx->opcode) | (men << 5);
j_mayer51789c42007-03-22 22:41:50 +00001722 gen_rldinm(ctx, 0, me, sh);
j_mayerd9bce9d2007-03-17 14:02:15 +00001723}
j_mayer51789c42007-03-22 22:41:50 +00001724GEN_PPC64_R4(rldicr, 0x1E, 0x02);
j_mayerd9bce9d2007-03-17 14:02:15 +00001725/* rldic - rldic. */
Blue Swirl636aa202009-08-16 09:06:54 +00001726static inline void gen_rldic(DisasContext *ctx, int mbn, int shn)
j_mayerd9bce9d2007-03-17 14:02:15 +00001727{
j_mayer51789c42007-03-22 22:41:50 +00001728 uint32_t sh, mb;
j_mayerd9bce9d2007-03-17 14:02:15 +00001729
j_mayer9d53c752007-04-06 07:59:47 +00001730 sh = SH(ctx->opcode) | (shn << 5);
1731 mb = MB(ctx->opcode) | (mbn << 5);
j_mayer51789c42007-03-22 22:41:50 +00001732 gen_rldinm(ctx, mb, 63 - sh, sh);
j_mayerd9bce9d2007-03-17 14:02:15 +00001733}
j_mayer51789c42007-03-22 22:41:50 +00001734GEN_PPC64_R4(rldic, 0x1E, 0x04);
1735
Blue Swirl636aa202009-08-16 09:06:54 +00001736static inline void gen_rldnm(DisasContext *ctx, uint32_t mb, uint32_t me)
j_mayer51789c42007-03-22 22:41:50 +00001737{
aurel3254843a52008-11-03 07:08:44 +00001738 TCGv t0;
aurel32d03ef512008-10-27 22:50:22 +00001739
1740 mb = MB(ctx->opcode);
1741 me = ME(ctx->opcode);
pbrooka7812ae2008-11-17 14:43:54 +00001742 t0 = tcg_temp_new();
aurel32d03ef512008-10-27 22:50:22 +00001743 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f);
aurel3254843a52008-11-03 07:08:44 +00001744 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
j_mayer51789c42007-03-22 22:41:50 +00001745 if (unlikely(mb != 0 || me != 63)) {
aurel3254843a52008-11-03 07:08:44 +00001746 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1747 } else {
1748 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1749 }
1750 tcg_temp_free(t0);
j_mayer51789c42007-03-22 22:41:50 +00001751 if (unlikely(Rc(ctx->opcode) != 0))
aurel32d03ef512008-10-27 22:50:22 +00001752 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayer51789c42007-03-22 22:41:50 +00001753}
1754
j_mayerd9bce9d2007-03-17 14:02:15 +00001755/* rldcl - rldcl. */
Blue Swirl636aa202009-08-16 09:06:54 +00001756static inline void gen_rldcl(DisasContext *ctx, int mbn)
j_mayerd9bce9d2007-03-17 14:02:15 +00001757{
j_mayer51789c42007-03-22 22:41:50 +00001758 uint32_t mb;
j_mayerd9bce9d2007-03-17 14:02:15 +00001759
j_mayer9d53c752007-04-06 07:59:47 +00001760 mb = MB(ctx->opcode) | (mbn << 5);
j_mayer51789c42007-03-22 22:41:50 +00001761 gen_rldnm(ctx, mb, 63);
j_mayerd9bce9d2007-03-17 14:02:15 +00001762}
j_mayer36081602007-09-17 08:21:54 +00001763GEN_PPC64_R2(rldcl, 0x1E, 0x08);
j_mayerd9bce9d2007-03-17 14:02:15 +00001764/* rldcr - rldcr. */
Blue Swirl636aa202009-08-16 09:06:54 +00001765static inline void gen_rldcr(DisasContext *ctx, int men)
j_mayerd9bce9d2007-03-17 14:02:15 +00001766{
j_mayer51789c42007-03-22 22:41:50 +00001767 uint32_t me;
j_mayerd9bce9d2007-03-17 14:02:15 +00001768
j_mayer9d53c752007-04-06 07:59:47 +00001769 me = MB(ctx->opcode) | (men << 5);
j_mayer51789c42007-03-22 22:41:50 +00001770 gen_rldnm(ctx, 0, me);
j_mayerd9bce9d2007-03-17 14:02:15 +00001771}
j_mayer36081602007-09-17 08:21:54 +00001772GEN_PPC64_R2(rldcr, 0x1E, 0x09);
j_mayerd9bce9d2007-03-17 14:02:15 +00001773/* rldimi - rldimi. */
Blue Swirl636aa202009-08-16 09:06:54 +00001774static inline void gen_rldimi(DisasContext *ctx, int mbn, int shn)
j_mayerd9bce9d2007-03-17 14:02:15 +00001775{
j_mayer271a9162007-11-14 05:26:46 +00001776 uint32_t sh, mb, me;
j_mayerd9bce9d2007-03-17 14:02:15 +00001777
j_mayer9d53c752007-04-06 07:59:47 +00001778 sh = SH(ctx->opcode) | (shn << 5);
1779 mb = MB(ctx->opcode) | (mbn << 5);
j_mayer271a9162007-11-14 05:26:46 +00001780 me = 63 - sh;
aurel32d03ef512008-10-27 22:50:22 +00001781 if (unlikely(sh == 0 && mb == 0)) {
1782 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1783 } else {
1784 TCGv t0, t1;
1785 target_ulong mask;
1786
pbrooka7812ae2008-11-17 14:43:54 +00001787 t0 = tcg_temp_new();
aurel3254843a52008-11-03 07:08:44 +00001788 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
pbrooka7812ae2008-11-17 14:43:54 +00001789 t1 = tcg_temp_new();
aurel32d03ef512008-10-27 22:50:22 +00001790 mask = MASK(mb, me);
1791 tcg_gen_andi_tl(t0, t0, mask);
1792 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1793 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1794 tcg_temp_free(t0);
1795 tcg_temp_free(t1);
j_mayer51789c42007-03-22 22:41:50 +00001796 }
j_mayer51789c42007-03-22 22:41:50 +00001797 if (unlikely(Rc(ctx->opcode) != 0))
aurel32d03ef512008-10-27 22:50:22 +00001798 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayerd9bce9d2007-03-17 14:02:15 +00001799}
j_mayer36081602007-09-17 08:21:54 +00001800GEN_PPC64_R4(rldimi, 0x1E, 0x06);
j_mayerd9bce9d2007-03-17 14:02:15 +00001801#endif
1802
bellard79aceca2003-11-23 14:55:54 +00001803/*** Integer shift ***/
Blue Swirl99e300e2009-06-17 15:22:09 +00001804
Blue Swirl54623272009-06-17 15:22:19 +00001805/* slw & slw. */
Blue Swirl99e300e2009-06-17 15:22:09 +00001806static void gen_slw(DisasContext *ctx)
aurel3226d67362008-10-21 11:31:27 +00001807{
Aurelien Jarno7fd6bf72009-09-18 16:56:30 +02001808 TCGv t0, t1;
aurel3226d67362008-10-21 11:31:27 +00001809
Aurelien Jarno7fd6bf72009-09-18 16:56:30 +02001810 t0 = tcg_temp_new();
1811 /* AND rS with a mask that is 0 when rB >= 0x20 */
1812#if defined(TARGET_PPC64)
1813 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1814 tcg_gen_sari_tl(t0, t0, 0x3f);
1815#else
1816 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1817 tcg_gen_sari_tl(t0, t0, 0x1f);
1818#endif
1819 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1820 t1 = tcg_temp_new();
1821 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1822 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1823 tcg_temp_free(t1);
aurel32fea0c502008-11-02 08:22:34 +00001824 tcg_temp_free(t0);
Aurelien Jarno7fd6bf72009-09-18 16:56:30 +02001825 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
aurel3226d67362008-10-21 11:31:27 +00001826 if (unlikely(Rc(ctx->opcode) != 0))
1827 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1828}
Blue Swirl99e300e2009-06-17 15:22:09 +00001829
Blue Swirl54623272009-06-17 15:22:19 +00001830/* sraw & sraw. */
Blue Swirl99e300e2009-06-17 15:22:09 +00001831static void gen_sraw(DisasContext *ctx)
aurel3226d67362008-10-21 11:31:27 +00001832{
pbrooka7812ae2008-11-17 14:43:54 +00001833 gen_helper_sraw(cpu_gpr[rA(ctx->opcode)],
1834 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
aurel3226d67362008-10-21 11:31:27 +00001835 if (unlikely(Rc(ctx->opcode) != 0))
1836 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1837}
Blue Swirl99e300e2009-06-17 15:22:09 +00001838
Blue Swirl54623272009-06-17 15:22:19 +00001839/* srawi & srawi. */
Blue Swirl99e300e2009-06-17 15:22:09 +00001840static void gen_srawi(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00001841{
aurel3226d67362008-10-21 11:31:27 +00001842 int sh = SH(ctx->opcode);
1843 if (sh != 0) {
1844 int l1, l2;
aurel32fea0c502008-11-02 08:22:34 +00001845 TCGv t0;
aurel3226d67362008-10-21 11:31:27 +00001846 l1 = gen_new_label();
1847 l2 = gen_new_label();
pbrooka7812ae2008-11-17 14:43:54 +00001848 t0 = tcg_temp_local_new();
aurel32fea0c502008-11-02 08:22:34 +00001849 tcg_gen_ext32s_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1850 tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1);
1851 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1ULL << sh) - 1);
1852 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
aurel32269f3e92008-11-01 00:53:48 +00001853 tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA);
aurel3226d67362008-10-21 11:31:27 +00001854 tcg_gen_br(l2);
1855 gen_set_label(l1);
aurel32269f3e92008-11-01 00:53:48 +00001856 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
aurel3226d67362008-10-21 11:31:27 +00001857 gen_set_label(l2);
aurel32fea0c502008-11-02 08:22:34 +00001858 tcg_gen_ext32s_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1859 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], t0, sh);
1860 tcg_temp_free(t0);
aurel3226d67362008-10-21 11:31:27 +00001861 } else {
1862 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
aurel32269f3e92008-11-01 00:53:48 +00001863 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
j_mayerd9bce9d2007-03-17 14:02:15 +00001864 }
j_mayer76a66252007-03-07 08:32:30 +00001865 if (unlikely(Rc(ctx->opcode) != 0))
aurel3226d67362008-10-21 11:31:27 +00001866 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
bellard79aceca2003-11-23 14:55:54 +00001867}
Blue Swirl99e300e2009-06-17 15:22:09 +00001868
Blue Swirl54623272009-06-17 15:22:19 +00001869/* srw & srw. */
Blue Swirl99e300e2009-06-17 15:22:09 +00001870static void gen_srw(DisasContext *ctx)
aurel3226d67362008-10-21 11:31:27 +00001871{
aurel32fea0c502008-11-02 08:22:34 +00001872 TCGv t0, t1;
j_mayerd9bce9d2007-03-17 14:02:15 +00001873
Aurelien Jarno7fd6bf72009-09-18 16:56:30 +02001874 t0 = tcg_temp_new();
1875 /* AND rS with a mask that is 0 when rB >= 0x20 */
1876#if defined(TARGET_PPC64)
1877 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1878 tcg_gen_sari_tl(t0, t0, 0x3f);
1879#else
1880 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1881 tcg_gen_sari_tl(t0, t0, 0x1f);
1882#endif
1883 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1884 tcg_gen_ext32u_tl(t0, t0);
pbrooka7812ae2008-11-17 14:43:54 +00001885 t1 = tcg_temp_new();
Aurelien Jarno7fd6bf72009-09-18 16:56:30 +02001886 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1887 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
aurel32fea0c502008-11-02 08:22:34 +00001888 tcg_temp_free(t1);
aurel32fea0c502008-11-02 08:22:34 +00001889 tcg_temp_free(t0);
aurel3226d67362008-10-21 11:31:27 +00001890 if (unlikely(Rc(ctx->opcode) != 0))
1891 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1892}
Blue Swirl54623272009-06-17 15:22:19 +00001893
j_mayerd9bce9d2007-03-17 14:02:15 +00001894#if defined(TARGET_PPC64)
1895/* sld & sld. */
Blue Swirl99e300e2009-06-17 15:22:09 +00001896static void gen_sld(DisasContext *ctx)
aurel3226d67362008-10-21 11:31:27 +00001897{
Aurelien Jarno7fd6bf72009-09-18 16:56:30 +02001898 TCGv t0, t1;
aurel3226d67362008-10-21 11:31:27 +00001899
Aurelien Jarno7fd6bf72009-09-18 16:56:30 +02001900 t0 = tcg_temp_new();
1901 /* AND rS with a mask that is 0 when rB >= 0x40 */
1902 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
1903 tcg_gen_sari_tl(t0, t0, 0x3f);
1904 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1905 t1 = tcg_temp_new();
1906 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
1907 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1908 tcg_temp_free(t1);
aurel32fea0c502008-11-02 08:22:34 +00001909 tcg_temp_free(t0);
aurel3226d67362008-10-21 11:31:27 +00001910 if (unlikely(Rc(ctx->opcode) != 0))
1911 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1912}
Blue Swirl99e300e2009-06-17 15:22:09 +00001913
Blue Swirl54623272009-06-17 15:22:19 +00001914/* srad & srad. */
Blue Swirl99e300e2009-06-17 15:22:09 +00001915static void gen_srad(DisasContext *ctx)
aurel3226d67362008-10-21 11:31:27 +00001916{
pbrooka7812ae2008-11-17 14:43:54 +00001917 gen_helper_srad(cpu_gpr[rA(ctx->opcode)],
1918 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
aurel3226d67362008-10-21 11:31:27 +00001919 if (unlikely(Rc(ctx->opcode) != 0))
1920 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1921}
j_mayerd9bce9d2007-03-17 14:02:15 +00001922/* sradi & sradi. */
Blue Swirl636aa202009-08-16 09:06:54 +00001923static inline void gen_sradi(DisasContext *ctx, int n)
j_mayerd9bce9d2007-03-17 14:02:15 +00001924{
aurel3226d67362008-10-21 11:31:27 +00001925 int sh = SH(ctx->opcode) + (n << 5);
j_mayerd9bce9d2007-03-17 14:02:15 +00001926 if (sh != 0) {
aurel3226d67362008-10-21 11:31:27 +00001927 int l1, l2;
aurel32fea0c502008-11-02 08:22:34 +00001928 TCGv t0;
aurel3226d67362008-10-21 11:31:27 +00001929 l1 = gen_new_label();
1930 l2 = gen_new_label();
pbrooka7812ae2008-11-17 14:43:54 +00001931 t0 = tcg_temp_local_new();
aurel3226d67362008-10-21 11:31:27 +00001932 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
aurel32fea0c502008-11-02 08:22:34 +00001933 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1ULL << sh) - 1);
1934 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
aurel32269f3e92008-11-01 00:53:48 +00001935 tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA);
aurel3226d67362008-10-21 11:31:27 +00001936 tcg_gen_br(l2);
1937 gen_set_label(l1);
aurel32269f3e92008-11-01 00:53:48 +00001938 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
aurel3226d67362008-10-21 11:31:27 +00001939 gen_set_label(l2);
aurel32a9730012008-11-09 17:27:36 +00001940 tcg_temp_free(t0);
aurel3226d67362008-10-21 11:31:27 +00001941 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
1942 } else {
1943 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
aurel32269f3e92008-11-01 00:53:48 +00001944 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
j_mayerd9bce9d2007-03-17 14:02:15 +00001945 }
j_mayerd9bce9d2007-03-17 14:02:15 +00001946 if (unlikely(Rc(ctx->opcode) != 0))
aurel3226d67362008-10-21 11:31:27 +00001947 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayerd9bce9d2007-03-17 14:02:15 +00001948}
Blue Swirle8eaa2c2009-06-17 15:22:14 +00001949
1950static void gen_sradi0(DisasContext *ctx)
j_mayerd9bce9d2007-03-17 14:02:15 +00001951{
1952 gen_sradi(ctx, 0);
1953}
Blue Swirle8eaa2c2009-06-17 15:22:14 +00001954
1955static void gen_sradi1(DisasContext *ctx)
j_mayerd9bce9d2007-03-17 14:02:15 +00001956{
1957 gen_sradi(ctx, 1);
1958}
Blue Swirl99e300e2009-06-17 15:22:09 +00001959
Blue Swirl54623272009-06-17 15:22:19 +00001960/* srd & srd. */
Blue Swirl99e300e2009-06-17 15:22:09 +00001961static void gen_srd(DisasContext *ctx)
aurel3226d67362008-10-21 11:31:27 +00001962{
Aurelien Jarno7fd6bf72009-09-18 16:56:30 +02001963 TCGv t0, t1;
aurel3226d67362008-10-21 11:31:27 +00001964
Aurelien Jarno7fd6bf72009-09-18 16:56:30 +02001965 t0 = tcg_temp_new();
1966 /* AND rS with a mask that is 0 when rB >= 0x40 */
1967 tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
1968 tcg_gen_sari_tl(t0, t0, 0x3f);
1969 tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1970 t1 = tcg_temp_new();
1971 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
1972 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1973 tcg_temp_free(t1);
aurel32fea0c502008-11-02 08:22:34 +00001974 tcg_temp_free(t0);
aurel3226d67362008-10-21 11:31:27 +00001975 if (unlikely(Rc(ctx->opcode) != 0))
1976 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1977}
j_mayerd9bce9d2007-03-17 14:02:15 +00001978#endif
bellard79aceca2003-11-23 14:55:54 +00001979
1980/*** Floating-Point arithmetic ***/
j_mayer7c580442007-10-27 17:54:30 +00001981#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00001982static void gen_f##name(DisasContext *ctx) \
bellard9a64fbe2004-01-04 22:58:38 +00001983{ \
j_mayer76a66252007-03-07 08:32:30 +00001984 if (unlikely(!ctx->fpu_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00001985 gen_exception(ctx, POWERPC_EXCP_FPU); \
bellard3cc62372005-02-15 23:06:19 +00001986 return; \
1987 } \
aurel32eb44b952008-12-15 17:13:39 +00001988 /* NIP cannot be restored if the memory exception comes from an helper */ \
1989 gen_update_nip(ctx, ctx->nip - 4); \
j_mayer7c580442007-10-27 17:54:30 +00001990 gen_reset_fpstatus(); \
aurel32af129062008-11-19 16:10:23 +00001991 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], \
1992 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
bellard4ecc3192005-03-13 17:01:22 +00001993 if (isfloat) { \
aurel32af129062008-11-19 16:10:23 +00001994 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); \
bellard4ecc3192005-03-13 17:01:22 +00001995 } \
aurel32af129062008-11-19 16:10:23 +00001996 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
1997 Rc(ctx->opcode) != 0); \
bellard79aceca2003-11-23 14:55:54 +00001998}
1999
j_mayer7c580442007-10-27 17:54:30 +00002000#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2001_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2002_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
bellard9a64fbe2004-01-04 22:58:38 +00002003
j_mayer7c580442007-10-27 17:54:30 +00002004#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00002005static void gen_f##name(DisasContext *ctx) \
bellard9a64fbe2004-01-04 22:58:38 +00002006{ \
j_mayer76a66252007-03-07 08:32:30 +00002007 if (unlikely(!ctx->fpu_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00002008 gen_exception(ctx, POWERPC_EXCP_FPU); \
bellard3cc62372005-02-15 23:06:19 +00002009 return; \
2010 } \
aurel32eb44b952008-12-15 17:13:39 +00002011 /* NIP cannot be restored if the memory exception comes from an helper */ \
2012 gen_update_nip(ctx, ctx->nip - 4); \
j_mayer7c580442007-10-27 17:54:30 +00002013 gen_reset_fpstatus(); \
aurel32af129062008-11-19 16:10:23 +00002014 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], \
2015 cpu_fpr[rB(ctx->opcode)]); \
bellard4ecc3192005-03-13 17:01:22 +00002016 if (isfloat) { \
aurel32af129062008-11-19 16:10:23 +00002017 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); \
bellard4ecc3192005-03-13 17:01:22 +00002018 } \
aurel32af129062008-11-19 16:10:23 +00002019 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2020 set_fprf, Rc(ctx->opcode) != 0); \
bellard9a64fbe2004-01-04 22:58:38 +00002021}
j_mayer7c580442007-10-27 17:54:30 +00002022#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2023_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2024_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
bellard9a64fbe2004-01-04 22:58:38 +00002025
j_mayer7c580442007-10-27 17:54:30 +00002026#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00002027static void gen_f##name(DisasContext *ctx) \
bellard9a64fbe2004-01-04 22:58:38 +00002028{ \
j_mayer76a66252007-03-07 08:32:30 +00002029 if (unlikely(!ctx->fpu_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00002030 gen_exception(ctx, POWERPC_EXCP_FPU); \
bellard3cc62372005-02-15 23:06:19 +00002031 return; \
2032 } \
aurel32eb44b952008-12-15 17:13:39 +00002033 /* NIP cannot be restored if the memory exception comes from an helper */ \
2034 gen_update_nip(ctx, ctx->nip - 4); \
j_mayer7c580442007-10-27 17:54:30 +00002035 gen_reset_fpstatus(); \
aurel32af129062008-11-19 16:10:23 +00002036 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], \
2037 cpu_fpr[rC(ctx->opcode)]); \
bellard4ecc3192005-03-13 17:01:22 +00002038 if (isfloat) { \
aurel32af129062008-11-19 16:10:23 +00002039 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); \
bellard4ecc3192005-03-13 17:01:22 +00002040 } \
aurel32af129062008-11-19 16:10:23 +00002041 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2042 set_fprf, Rc(ctx->opcode) != 0); \
bellard9a64fbe2004-01-04 22:58:38 +00002043}
j_mayer7c580442007-10-27 17:54:30 +00002044#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2045_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2046_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
bellard9a64fbe2004-01-04 22:58:38 +00002047
j_mayer7c580442007-10-27 17:54:30 +00002048#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00002049static void gen_f##name(DisasContext *ctx) \
bellard9a64fbe2004-01-04 22:58:38 +00002050{ \
j_mayer76a66252007-03-07 08:32:30 +00002051 if (unlikely(!ctx->fpu_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00002052 gen_exception(ctx, POWERPC_EXCP_FPU); \
bellard3cc62372005-02-15 23:06:19 +00002053 return; \
2054 } \
aurel32eb44b952008-12-15 17:13:39 +00002055 /* NIP cannot be restored if the memory exception comes from an helper */ \
2056 gen_update_nip(ctx, ctx->nip - 4); \
j_mayer7c580442007-10-27 17:54:30 +00002057 gen_reset_fpstatus(); \
aurel32af129062008-11-19 16:10:23 +00002058 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2059 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2060 set_fprf, Rc(ctx->opcode) != 0); \
bellard79aceca2003-11-23 14:55:54 +00002061}
2062
j_mayer7c580442007-10-27 17:54:30 +00002063#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00002064static void gen_f##name(DisasContext *ctx) \
bellard9a64fbe2004-01-04 22:58:38 +00002065{ \
j_mayer76a66252007-03-07 08:32:30 +00002066 if (unlikely(!ctx->fpu_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00002067 gen_exception(ctx, POWERPC_EXCP_FPU); \
bellard3cc62372005-02-15 23:06:19 +00002068 return; \
2069 } \
aurel32eb44b952008-12-15 17:13:39 +00002070 /* NIP cannot be restored if the memory exception comes from an helper */ \
2071 gen_update_nip(ctx, ctx->nip - 4); \
j_mayer7c580442007-10-27 17:54:30 +00002072 gen_reset_fpstatus(); \
aurel32af129062008-11-19 16:10:23 +00002073 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2074 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2075 set_fprf, Rc(ctx->opcode) != 0); \
bellard9a64fbe2004-01-04 22:58:38 +00002076}
2077
2078/* fadd - fadds */
j_mayer7c580442007-10-27 17:54:30 +00002079GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT);
bellard4ecc3192005-03-13 17:01:22 +00002080/* fdiv - fdivs */
j_mayer7c580442007-10-27 17:54:30 +00002081GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT);
bellard4ecc3192005-03-13 17:01:22 +00002082/* fmul - fmuls */
j_mayer7c580442007-10-27 17:54:30 +00002083GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT);
bellard79aceca2003-11-23 14:55:54 +00002084
j_mayerd7e4b872007-09-30 01:11:48 +00002085/* fre */
j_mayer7c580442007-10-27 17:54:30 +00002086GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT);
j_mayerd7e4b872007-09-30 01:11:48 +00002087
j_mayera750fc02007-09-26 23:54:22 +00002088/* fres */
j_mayer7c580442007-10-27 17:54:30 +00002089GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES);
bellard79aceca2003-11-23 14:55:54 +00002090
j_mayera750fc02007-09-26 23:54:22 +00002091/* frsqrte */
j_mayer7c580442007-10-27 17:54:30 +00002092GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
2093
2094/* frsqrtes */
Blue Swirl99e300e2009-06-17 15:22:09 +00002095static void gen_frsqrtes(DisasContext *ctx)
j_mayer7c580442007-10-27 17:54:30 +00002096{
aurel32af129062008-11-19 16:10:23 +00002097 if (unlikely(!ctx->fpu_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00002098 gen_exception(ctx, POWERPC_EXCP_FPU);
aurel32af129062008-11-19 16:10:23 +00002099 return;
2100 }
aurel32eb44b952008-12-15 17:13:39 +00002101 /* NIP cannot be restored if the memory exception comes from an helper */
2102 gen_update_nip(ctx, ctx->nip - 4);
aurel32af129062008-11-19 16:10:23 +00002103 gen_reset_fpstatus();
2104 gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2105 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]);
2106 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
j_mayer7c580442007-10-27 17:54:30 +00002107}
bellard79aceca2003-11-23 14:55:54 +00002108
j_mayera750fc02007-09-26 23:54:22 +00002109/* fsel */
j_mayer7c580442007-10-27 17:54:30 +00002110_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL);
bellard4ecc3192005-03-13 17:01:22 +00002111/* fsub - fsubs */
j_mayer7c580442007-10-27 17:54:30 +00002112GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
bellard79aceca2003-11-23 14:55:54 +00002113/* Optional: */
Blue Swirl99e300e2009-06-17 15:22:09 +00002114
Blue Swirl54623272009-06-17 15:22:19 +00002115/* fsqrt */
Blue Swirl99e300e2009-06-17 15:22:09 +00002116static void gen_fsqrt(DisasContext *ctx)
bellardc7d344a2005-04-23 18:05:46 +00002117{
j_mayer76a66252007-03-07 08:32:30 +00002118 if (unlikely(!ctx->fpu_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00002119 gen_exception(ctx, POWERPC_EXCP_FPU);
bellardc7d344a2005-04-23 18:05:46 +00002120 return;
2121 }
aurel32eb44b952008-12-15 17:13:39 +00002122 /* NIP cannot be restored if the memory exception comes from an helper */
2123 gen_update_nip(ctx, ctx->nip - 4);
j_mayer7c580442007-10-27 17:54:30 +00002124 gen_reset_fpstatus();
aurel32af129062008-11-19 16:10:23 +00002125 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2126 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
bellardc7d344a2005-04-23 18:05:46 +00002127}
bellard79aceca2003-11-23 14:55:54 +00002128
Blue Swirl99e300e2009-06-17 15:22:09 +00002129static void gen_fsqrts(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00002130{
j_mayer76a66252007-03-07 08:32:30 +00002131 if (unlikely(!ctx->fpu_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00002132 gen_exception(ctx, POWERPC_EXCP_FPU);
bellard3cc62372005-02-15 23:06:19 +00002133 return;
2134 }
aurel32eb44b952008-12-15 17:13:39 +00002135 /* NIP cannot be restored if the memory exception comes from an helper */
2136 gen_update_nip(ctx, ctx->nip - 4);
j_mayer7c580442007-10-27 17:54:30 +00002137 gen_reset_fpstatus();
aurel32af129062008-11-19 16:10:23 +00002138 gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2139 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]);
2140 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
bellard79aceca2003-11-23 14:55:54 +00002141}
2142
2143/*** Floating-Point multiply-and-add ***/
bellard4ecc3192005-03-13 17:01:22 +00002144/* fmadd - fmadds */
j_mayer7c580442007-10-27 17:54:30 +00002145GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT);
bellard4ecc3192005-03-13 17:01:22 +00002146/* fmsub - fmsubs */
j_mayer7c580442007-10-27 17:54:30 +00002147GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT);
bellard4ecc3192005-03-13 17:01:22 +00002148/* fnmadd - fnmadds */
j_mayer7c580442007-10-27 17:54:30 +00002149GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT);
bellard4ecc3192005-03-13 17:01:22 +00002150/* fnmsub - fnmsubs */
j_mayer7c580442007-10-27 17:54:30 +00002151GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT);
bellard79aceca2003-11-23 14:55:54 +00002152
2153/*** Floating-Point round & convert ***/
2154/* fctiw */
j_mayer7c580442007-10-27 17:54:30 +00002155GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT);
bellard79aceca2003-11-23 14:55:54 +00002156/* fctiwz */
j_mayer7c580442007-10-27 17:54:30 +00002157GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT);
bellard79aceca2003-11-23 14:55:54 +00002158/* frsp */
j_mayer7c580442007-10-27 17:54:30 +00002159GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT);
j_mayer426613d2007-03-23 09:45:27 +00002160#if defined(TARGET_PPC64)
2161/* fcfid */
j_mayer7c580442007-10-27 17:54:30 +00002162GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B);
j_mayer426613d2007-03-23 09:45:27 +00002163/* fctid */
j_mayer7c580442007-10-27 17:54:30 +00002164GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B);
j_mayer426613d2007-03-23 09:45:27 +00002165/* fctidz */
j_mayer7c580442007-10-27 17:54:30 +00002166GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B);
j_mayer426613d2007-03-23 09:45:27 +00002167#endif
bellard79aceca2003-11-23 14:55:54 +00002168
j_mayerd7e4b872007-09-30 01:11:48 +00002169/* frin */
j_mayer7c580442007-10-27 17:54:30 +00002170GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT);
j_mayerd7e4b872007-09-30 01:11:48 +00002171/* friz */
j_mayer7c580442007-10-27 17:54:30 +00002172GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT);
j_mayerd7e4b872007-09-30 01:11:48 +00002173/* frip */
j_mayer7c580442007-10-27 17:54:30 +00002174GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT);
j_mayerd7e4b872007-09-30 01:11:48 +00002175/* frim */
j_mayer7c580442007-10-27 17:54:30 +00002176GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT);
j_mayerd7e4b872007-09-30 01:11:48 +00002177
bellard79aceca2003-11-23 14:55:54 +00002178/*** Floating-Point compare ***/
Blue Swirl99e300e2009-06-17 15:22:09 +00002179
Blue Swirl54623272009-06-17 15:22:19 +00002180/* fcmpo */
Blue Swirl99e300e2009-06-17 15:22:09 +00002181static void gen_fcmpo(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00002182{
aurel32330c4832008-12-15 17:13:31 +00002183 TCGv_i32 crf;
j_mayer76a66252007-03-07 08:32:30 +00002184 if (unlikely(!ctx->fpu_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00002185 gen_exception(ctx, POWERPC_EXCP_FPU);
bellard3cc62372005-02-15 23:06:19 +00002186 return;
2187 }
aurel32eb44b952008-12-15 17:13:39 +00002188 /* NIP cannot be restored if the memory exception comes from an helper */
2189 gen_update_nip(ctx, ctx->nip - 4);
j_mayer7c580442007-10-27 17:54:30 +00002190 gen_reset_fpstatus();
aurel329a819372008-12-14 19:34:09 +00002191 crf = tcg_const_i32(crfD(ctx->opcode));
2192 gen_helper_fcmpo(cpu_fpr[rA(ctx->opcode)], cpu_fpr[rB(ctx->opcode)], crf);
aurel32330c4832008-12-15 17:13:31 +00002193 tcg_temp_free_i32(crf);
aurel32af129062008-11-19 16:10:23 +00002194 gen_helper_float_check_status();
bellard79aceca2003-11-23 14:55:54 +00002195}
2196
2197/* fcmpu */
Blue Swirl99e300e2009-06-17 15:22:09 +00002198static void gen_fcmpu(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00002199{
aurel32330c4832008-12-15 17:13:31 +00002200 TCGv_i32 crf;
j_mayer76a66252007-03-07 08:32:30 +00002201 if (unlikely(!ctx->fpu_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00002202 gen_exception(ctx, POWERPC_EXCP_FPU);
bellard3cc62372005-02-15 23:06:19 +00002203 return;
2204 }
aurel32eb44b952008-12-15 17:13:39 +00002205 /* NIP cannot be restored if the memory exception comes from an helper */
2206 gen_update_nip(ctx, ctx->nip - 4);
j_mayer7c580442007-10-27 17:54:30 +00002207 gen_reset_fpstatus();
aurel329a819372008-12-14 19:34:09 +00002208 crf = tcg_const_i32(crfD(ctx->opcode));
2209 gen_helper_fcmpu(cpu_fpr[rA(ctx->opcode)], cpu_fpr[rB(ctx->opcode)], crf);
aurel32330c4832008-12-15 17:13:31 +00002210 tcg_temp_free_i32(crf);
aurel32af129062008-11-19 16:10:23 +00002211 gen_helper_float_check_status();
bellard79aceca2003-11-23 14:55:54 +00002212}
2213
bellard9a64fbe2004-01-04 22:58:38 +00002214/*** Floating-point move ***/
2215/* fabs */
j_mayer7c580442007-10-27 17:54:30 +00002216/* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2217GEN_FLOAT_B(abs, 0x08, 0x08, 0, PPC_FLOAT);
bellard9a64fbe2004-01-04 22:58:38 +00002218
2219/* fmr - fmr. */
j_mayer7c580442007-10-27 17:54:30 +00002220/* XXX: beware that fmr never checks for NaNs nor update FPSCR */
Blue Swirl99e300e2009-06-17 15:22:09 +00002221static void gen_fmr(DisasContext *ctx)
bellard9a64fbe2004-01-04 22:58:38 +00002222{
j_mayer76a66252007-03-07 08:32:30 +00002223 if (unlikely(!ctx->fpu_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00002224 gen_exception(ctx, POWERPC_EXCP_FPU);
bellard3cc62372005-02-15 23:06:19 +00002225 return;
2226 }
aurel32af129062008-11-19 16:10:23 +00002227 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2228 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
bellard9a64fbe2004-01-04 22:58:38 +00002229}
2230
2231/* fnabs */
j_mayer7c580442007-10-27 17:54:30 +00002232/* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2233GEN_FLOAT_B(nabs, 0x08, 0x04, 0, PPC_FLOAT);
bellard9a64fbe2004-01-04 22:58:38 +00002234/* fneg */
j_mayer7c580442007-10-27 17:54:30 +00002235/* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2236GEN_FLOAT_B(neg, 0x08, 0x01, 0, PPC_FLOAT);
bellard9a64fbe2004-01-04 22:58:38 +00002237
bellard79aceca2003-11-23 14:55:54 +00002238/*** Floating-Point status & ctrl register ***/
Blue Swirl99e300e2009-06-17 15:22:09 +00002239
Blue Swirl54623272009-06-17 15:22:19 +00002240/* mcrfs */
Blue Swirl99e300e2009-06-17 15:22:09 +00002241static void gen_mcrfs(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00002242{
j_mayer7c580442007-10-27 17:54:30 +00002243 int bfa;
2244
j_mayer76a66252007-03-07 08:32:30 +00002245 if (unlikely(!ctx->fpu_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00002246 gen_exception(ctx, POWERPC_EXCP_FPU);
bellard3cc62372005-02-15 23:06:19 +00002247 return;
2248 }
j_mayer7c580442007-10-27 17:54:30 +00002249 bfa = 4 * (7 - crfS(ctx->opcode));
aurel32e1571902008-10-21 11:31:14 +00002250 tcg_gen_shri_i32(cpu_crf[crfD(ctx->opcode)], cpu_fpscr, bfa);
2251 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf);
aurel32af129062008-11-19 16:10:23 +00002252 tcg_gen_andi_i32(cpu_fpscr, cpu_fpscr, ~(0xF << bfa));
bellard79aceca2003-11-23 14:55:54 +00002253}
2254
2255/* mffs */
Blue Swirl99e300e2009-06-17 15:22:09 +00002256static void gen_mffs(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00002257{
j_mayer76a66252007-03-07 08:32:30 +00002258 if (unlikely(!ctx->fpu_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00002259 gen_exception(ctx, POWERPC_EXCP_FPU);
bellard3cc62372005-02-15 23:06:19 +00002260 return;
2261 }
j_mayer7c580442007-10-27 17:54:30 +00002262 gen_reset_fpstatus();
aurel32af129062008-11-19 16:10:23 +00002263 tcg_gen_extu_i32_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr);
2264 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
bellard79aceca2003-11-23 14:55:54 +00002265}
2266
2267/* mtfsb0 */
Blue Swirl99e300e2009-06-17 15:22:09 +00002268static void gen_mtfsb0(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00002269{
bellardfb0eaff2004-01-04 14:57:11 +00002270 uint8_t crb;
ths3b46e622007-09-17 08:09:54 +00002271
j_mayer76a66252007-03-07 08:32:30 +00002272 if (unlikely(!ctx->fpu_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00002273 gen_exception(ctx, POWERPC_EXCP_FPU);
bellard3cc62372005-02-15 23:06:19 +00002274 return;
2275 }
aurel326e35d522008-12-14 18:40:58 +00002276 crb = 31 - crbD(ctx->opcode);
j_mayer7c580442007-10-27 17:54:30 +00002277 gen_reset_fpstatus();
aurel326e35d522008-12-14 18:40:58 +00002278 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) {
aurel32eb44b952008-12-15 17:13:39 +00002279 TCGv_i32 t0;
2280 /* NIP cannot be restored if the memory exception comes from an helper */
2281 gen_update_nip(ctx, ctx->nip - 4);
2282 t0 = tcg_const_i32(crb);
aurel326e35d522008-12-14 18:40:58 +00002283 gen_helper_fpscr_clrbit(t0);
2284 tcg_temp_free_i32(t0);
2285 }
j_mayer7c580442007-10-27 17:54:30 +00002286 if (unlikely(Rc(ctx->opcode) != 0)) {
aurel32e1571902008-10-21 11:31:14 +00002287 tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
j_mayer7c580442007-10-27 17:54:30 +00002288 }
bellard79aceca2003-11-23 14:55:54 +00002289}
2290
2291/* mtfsb1 */
Blue Swirl99e300e2009-06-17 15:22:09 +00002292static void gen_mtfsb1(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00002293{
bellardfb0eaff2004-01-04 14:57:11 +00002294 uint8_t crb;
ths3b46e622007-09-17 08:09:54 +00002295
j_mayer76a66252007-03-07 08:32:30 +00002296 if (unlikely(!ctx->fpu_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00002297 gen_exception(ctx, POWERPC_EXCP_FPU);
bellard3cc62372005-02-15 23:06:19 +00002298 return;
2299 }
aurel326e35d522008-12-14 18:40:58 +00002300 crb = 31 - crbD(ctx->opcode);
j_mayer7c580442007-10-27 17:54:30 +00002301 gen_reset_fpstatus();
2302 /* XXX: we pretend we can only do IEEE floating-point computations */
aurel32af129062008-11-19 16:10:23 +00002303 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) {
aurel32eb44b952008-12-15 17:13:39 +00002304 TCGv_i32 t0;
2305 /* NIP cannot be restored if the memory exception comes from an helper */
2306 gen_update_nip(ctx, ctx->nip - 4);
2307 t0 = tcg_const_i32(crb);
aurel32af129062008-11-19 16:10:23 +00002308 gen_helper_fpscr_setbit(t0);
aurel320f2f39c2008-11-19 17:54:49 +00002309 tcg_temp_free_i32(t0);
aurel32af129062008-11-19 16:10:23 +00002310 }
j_mayer7c580442007-10-27 17:54:30 +00002311 if (unlikely(Rc(ctx->opcode) != 0)) {
aurel32e1571902008-10-21 11:31:14 +00002312 tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
j_mayer7c580442007-10-27 17:54:30 +00002313 }
2314 /* We can raise a differed exception */
aurel32af129062008-11-19 16:10:23 +00002315 gen_helper_float_check_status();
bellard79aceca2003-11-23 14:55:54 +00002316}
2317
2318/* mtfsf */
Blue Swirl99e300e2009-06-17 15:22:09 +00002319static void gen_mtfsf(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00002320{
aurel320f2f39c2008-11-19 17:54:49 +00002321 TCGv_i32 t0;
blueswir149110122009-03-07 20:55:31 +00002322 int L = ctx->opcode & 0x02000000;
aurel32af129062008-11-19 16:10:23 +00002323
j_mayer76a66252007-03-07 08:32:30 +00002324 if (unlikely(!ctx->fpu_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00002325 gen_exception(ctx, POWERPC_EXCP_FPU);
bellard3cc62372005-02-15 23:06:19 +00002326 return;
2327 }
aurel32eb44b952008-12-15 17:13:39 +00002328 /* NIP cannot be restored if the memory exception comes from an helper */
2329 gen_update_nip(ctx, ctx->nip - 4);
j_mayer7c580442007-10-27 17:54:30 +00002330 gen_reset_fpstatus();
blueswir149110122009-03-07 20:55:31 +00002331 if (L)
2332 t0 = tcg_const_i32(0xff);
2333 else
2334 t0 = tcg_const_i32(FM(ctx->opcode));
aurel32af129062008-11-19 16:10:23 +00002335 gen_helper_store_fpscr(cpu_fpr[rB(ctx->opcode)], t0);
aurel320f2f39c2008-11-19 17:54:49 +00002336 tcg_temp_free_i32(t0);
j_mayer7c580442007-10-27 17:54:30 +00002337 if (unlikely(Rc(ctx->opcode) != 0)) {
aurel32e1571902008-10-21 11:31:14 +00002338 tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
j_mayer7c580442007-10-27 17:54:30 +00002339 }
2340 /* We can raise a differed exception */
aurel32af129062008-11-19 16:10:23 +00002341 gen_helper_float_check_status();
bellard79aceca2003-11-23 14:55:54 +00002342}
2343
2344/* mtfsfi */
Blue Swirl99e300e2009-06-17 15:22:09 +00002345static void gen_mtfsfi(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00002346{
j_mayer7c580442007-10-27 17:54:30 +00002347 int bf, sh;
aurel320f2f39c2008-11-19 17:54:49 +00002348 TCGv_i64 t0;
2349 TCGv_i32 t1;
j_mayer7c580442007-10-27 17:54:30 +00002350
j_mayer76a66252007-03-07 08:32:30 +00002351 if (unlikely(!ctx->fpu_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00002352 gen_exception(ctx, POWERPC_EXCP_FPU);
bellard3cc62372005-02-15 23:06:19 +00002353 return;
2354 }
j_mayer7c580442007-10-27 17:54:30 +00002355 bf = crbD(ctx->opcode) >> 2;
2356 sh = 7 - bf;
aurel32eb44b952008-12-15 17:13:39 +00002357 /* NIP cannot be restored if the memory exception comes from an helper */
2358 gen_update_nip(ctx, ctx->nip - 4);
j_mayer7c580442007-10-27 17:54:30 +00002359 gen_reset_fpstatus();
aurel320f2f39c2008-11-19 17:54:49 +00002360 t0 = tcg_const_i64(FPIMM(ctx->opcode) << (4 * sh));
aurel32af129062008-11-19 16:10:23 +00002361 t1 = tcg_const_i32(1 << sh);
2362 gen_helper_store_fpscr(t0, t1);
aurel320f2f39c2008-11-19 17:54:49 +00002363 tcg_temp_free_i64(t0);
2364 tcg_temp_free_i32(t1);
j_mayer7c580442007-10-27 17:54:30 +00002365 if (unlikely(Rc(ctx->opcode) != 0)) {
aurel32e1571902008-10-21 11:31:14 +00002366 tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
j_mayer7c580442007-10-27 17:54:30 +00002367 }
2368 /* We can raise a differed exception */
aurel32af129062008-11-19 16:10:23 +00002369 gen_helper_float_check_status();
bellard79aceca2003-11-23 14:55:54 +00002370}
2371
j_mayer76a66252007-03-07 08:32:30 +00002372/*** Addressing modes ***/
2373/* Register indirect with immediate index : EA = (rA|0) + SIMM */
Blue Swirl636aa202009-08-16 09:06:54 +00002374static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA,
2375 target_long maskl)
j_mayer76a66252007-03-07 08:32:30 +00002376{
2377 target_long simm = SIMM(ctx->opcode);
2378
j_mayerbe147d02007-09-30 13:03:23 +00002379 simm &= ~maskl;
aurel3276db3ba2008-12-08 18:11:21 +00002380 if (rA(ctx->opcode) == 0) {
2381#if defined(TARGET_PPC64)
2382 if (!ctx->sf_mode) {
2383 tcg_gen_movi_tl(EA, (uint32_t)simm);
2384 } else
2385#endif
aurel32e2be8d82008-10-14 19:55:54 +00002386 tcg_gen_movi_tl(EA, simm);
aurel3276db3ba2008-12-08 18:11:21 +00002387 } else if (likely(simm != 0)) {
aurel32e2be8d82008-10-14 19:55:54 +00002388 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm);
aurel3276db3ba2008-12-08 18:11:21 +00002389#if defined(TARGET_PPC64)
2390 if (!ctx->sf_mode) {
2391 tcg_gen_ext32u_tl(EA, EA);
2392 }
2393#endif
2394 } else {
2395#if defined(TARGET_PPC64)
2396 if (!ctx->sf_mode) {
2397 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2398 } else
2399#endif
aurel32e2be8d82008-10-14 19:55:54 +00002400 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
aurel3276db3ba2008-12-08 18:11:21 +00002401 }
j_mayer76a66252007-03-07 08:32:30 +00002402}
2403
Blue Swirl636aa202009-08-16 09:06:54 +00002404static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA)
j_mayer76a66252007-03-07 08:32:30 +00002405{
aurel3276db3ba2008-12-08 18:11:21 +00002406 if (rA(ctx->opcode) == 0) {
2407#if defined(TARGET_PPC64)
2408 if (!ctx->sf_mode) {
2409 tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2410 } else
2411#endif
aurel32e2be8d82008-10-14 19:55:54 +00002412 tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]);
aurel3276db3ba2008-12-08 18:11:21 +00002413 } else {
aurel32e2be8d82008-10-14 19:55:54 +00002414 tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
aurel3276db3ba2008-12-08 18:11:21 +00002415#if defined(TARGET_PPC64)
2416 if (!ctx->sf_mode) {
2417 tcg_gen_ext32u_tl(EA, EA);
2418 }
2419#endif
2420 }
j_mayer76a66252007-03-07 08:32:30 +00002421}
2422
Blue Swirl636aa202009-08-16 09:06:54 +00002423static inline void gen_addr_register(DisasContext *ctx, TCGv EA)
j_mayer76a66252007-03-07 08:32:30 +00002424{
aurel3276db3ba2008-12-08 18:11:21 +00002425 if (rA(ctx->opcode) == 0) {
aurel32e2be8d82008-10-14 19:55:54 +00002426 tcg_gen_movi_tl(EA, 0);
aurel3276db3ba2008-12-08 18:11:21 +00002427 } else {
2428#if defined(TARGET_PPC64)
2429 if (!ctx->sf_mode) {
2430 tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2431 } else
2432#endif
2433 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2434 }
2435}
2436
Blue Swirl636aa202009-08-16 09:06:54 +00002437static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1,
2438 target_long val)
aurel3276db3ba2008-12-08 18:11:21 +00002439{
2440 tcg_gen_addi_tl(ret, arg1, val);
2441#if defined(TARGET_PPC64)
2442 if (!ctx->sf_mode) {
2443 tcg_gen_ext32u_tl(ret, ret);
2444 }
2445#endif
j_mayer76a66252007-03-07 08:32:30 +00002446}
2447
Blue Swirl636aa202009-08-16 09:06:54 +00002448static inline void gen_check_align(DisasContext *ctx, TCGv EA, int mask)
aurel32cf360a32008-11-30 16:24:39 +00002449{
2450 int l1 = gen_new_label();
2451 TCGv t0 = tcg_temp_new();
2452 TCGv_i32 t1, t2;
2453 /* NIP cannot be restored if the memory exception comes from an helper */
2454 gen_update_nip(ctx, ctx->nip - 4);
2455 tcg_gen_andi_tl(t0, EA, mask);
2456 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2457 t1 = tcg_const_i32(POWERPC_EXCP_ALIGN);
2458 t2 = tcg_const_i32(0);
2459 gen_helper_raise_exception_err(t1, t2);
2460 tcg_temp_free_i32(t1);
2461 tcg_temp_free_i32(t2);
2462 gen_set_label(l1);
2463 tcg_temp_free(t0);
2464}
2465
j_mayer78636672007-11-16 14:11:28 +00002466/*** Integer load ***/
Blue Swirl636aa202009-08-16 09:06:54 +00002467static inline void gen_qemu_ld8u(DisasContext *ctx, TCGv arg1, TCGv arg2)
aurel3276db3ba2008-12-08 18:11:21 +00002468{
2469 tcg_gen_qemu_ld8u(arg1, arg2, ctx->mem_idx);
2470}
2471
Blue Swirl636aa202009-08-16 09:06:54 +00002472static inline void gen_qemu_ld8s(DisasContext *ctx, TCGv arg1, TCGv arg2)
aurel3276db3ba2008-12-08 18:11:21 +00002473{
2474 tcg_gen_qemu_ld8s(arg1, arg2, ctx->mem_idx);
2475}
2476
Blue Swirl636aa202009-08-16 09:06:54 +00002477static inline void gen_qemu_ld16u(DisasContext *ctx, TCGv arg1, TCGv arg2)
aurel3276db3ba2008-12-08 18:11:21 +00002478{
2479 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
2480 if (unlikely(ctx->le_mode)) {
aurel32fa3966a2009-03-13 09:35:34 +00002481 tcg_gen_bswap16_tl(arg1, arg1);
aurel3276db3ba2008-12-08 18:11:21 +00002482 }
aurel32b61f2752008-10-15 17:00:37 +00002483}
2484
Blue Swirl636aa202009-08-16 09:06:54 +00002485static inline void gen_qemu_ld16s(DisasContext *ctx, TCGv arg1, TCGv arg2)
aurel32b61f2752008-10-15 17:00:37 +00002486{
aurel3276db3ba2008-12-08 18:11:21 +00002487 if (unlikely(ctx->le_mode)) {
aurel3276db3ba2008-12-08 18:11:21 +00002488 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
aurel32fa3966a2009-03-13 09:35:34 +00002489 tcg_gen_bswap16_tl(arg1, arg1);
aurel3276db3ba2008-12-08 18:11:21 +00002490 tcg_gen_ext16s_tl(arg1, arg1);
aurel3276db3ba2008-12-08 18:11:21 +00002491 } else {
2492 tcg_gen_qemu_ld16s(arg1, arg2, ctx->mem_idx);
2493 }
aurel32b61f2752008-10-15 17:00:37 +00002494}
2495
Blue Swirl636aa202009-08-16 09:06:54 +00002496static inline void gen_qemu_ld32u(DisasContext *ctx, TCGv arg1, TCGv arg2)
aurel32b61f2752008-10-15 17:00:37 +00002497{
aurel3276db3ba2008-12-08 18:11:21 +00002498 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
2499 if (unlikely(ctx->le_mode)) {
aurel32fa3966a2009-03-13 09:35:34 +00002500 tcg_gen_bswap32_tl(arg1, arg1);
aurel3276db3ba2008-12-08 18:11:21 +00002501 }
aurel32b61f2752008-10-15 17:00:37 +00002502}
2503
aurel3276db3ba2008-12-08 18:11:21 +00002504#if defined(TARGET_PPC64)
Blue Swirl636aa202009-08-16 09:06:54 +00002505static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2)
aurel32b61f2752008-10-15 17:00:37 +00002506{
blueswir1a457e7e2009-02-28 08:25:29 +00002507 if (unlikely(ctx->le_mode)) {
aurel3276db3ba2008-12-08 18:11:21 +00002508 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
aurel32fa3966a2009-03-13 09:35:34 +00002509 tcg_gen_bswap32_tl(arg1, arg1);
2510 tcg_gen_ext32s_tl(arg1, arg1);
aurel32b61f2752008-10-15 17:00:37 +00002511 } else
aurel3276db3ba2008-12-08 18:11:21 +00002512 tcg_gen_qemu_ld32s(arg1, arg2, ctx->mem_idx);
aurel32a0d7d5a2008-11-23 16:30:50 +00002513}
aurel32b61f2752008-10-15 17:00:37 +00002514#endif
2515
Blue Swirl636aa202009-08-16 09:06:54 +00002516static inline void gen_qemu_ld64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
aurel3276db3ba2008-12-08 18:11:21 +00002517{
2518 tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx);
2519 if (unlikely(ctx->le_mode)) {
aurel3266896cb2009-03-13 09:34:48 +00002520 tcg_gen_bswap64_i64(arg1, arg1);
aurel3276db3ba2008-12-08 18:11:21 +00002521 }
2522}
2523
Blue Swirl636aa202009-08-16 09:06:54 +00002524static inline void gen_qemu_st8(DisasContext *ctx, TCGv arg1, TCGv arg2)
aurel3276db3ba2008-12-08 18:11:21 +00002525{
2526 tcg_gen_qemu_st8(arg1, arg2, ctx->mem_idx);
2527}
2528
Blue Swirl636aa202009-08-16 09:06:54 +00002529static inline void gen_qemu_st16(DisasContext *ctx, TCGv arg1, TCGv arg2)
aurel3276db3ba2008-12-08 18:11:21 +00002530{
2531 if (unlikely(ctx->le_mode)) {
aurel3276db3ba2008-12-08 18:11:21 +00002532 TCGv t0 = tcg_temp_new();
2533 tcg_gen_ext16u_tl(t0, arg1);
aurel32fa3966a2009-03-13 09:35:34 +00002534 tcg_gen_bswap16_tl(t0, t0);
aurel3276db3ba2008-12-08 18:11:21 +00002535 tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
2536 tcg_temp_free(t0);
aurel3276db3ba2008-12-08 18:11:21 +00002537 } else {
2538 tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
2539 }
2540}
2541
Blue Swirl636aa202009-08-16 09:06:54 +00002542static inline void gen_qemu_st32(DisasContext *ctx, TCGv arg1, TCGv arg2)
aurel3276db3ba2008-12-08 18:11:21 +00002543{
2544 if (unlikely(ctx->le_mode)) {
aurel32fa3966a2009-03-13 09:35:34 +00002545 TCGv t0 = tcg_temp_new();
2546 tcg_gen_ext32u_tl(t0, arg1);
2547 tcg_gen_bswap32_tl(t0, t0);
aurel3276db3ba2008-12-08 18:11:21 +00002548 tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
2549 tcg_temp_free(t0);
aurel3276db3ba2008-12-08 18:11:21 +00002550 } else {
2551 tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
2552 }
2553}
2554
Blue Swirl636aa202009-08-16 09:06:54 +00002555static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
aurel3276db3ba2008-12-08 18:11:21 +00002556{
2557 if (unlikely(ctx->le_mode)) {
2558 TCGv_i64 t0 = tcg_temp_new_i64();
aurel3266896cb2009-03-13 09:34:48 +00002559 tcg_gen_bswap64_i64(t0, arg1);
aurel3276db3ba2008-12-08 18:11:21 +00002560 tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx);
2561 tcg_temp_free_i64(t0);
2562 } else
2563 tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx);
2564}
2565
aurel320c8aacd2008-11-23 16:30:28 +00002566#define GEN_LD(name, ldop, opc, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00002567static void glue(gen_, name)(DisasContext *ctx) \
bellard79aceca2003-11-23 14:55:54 +00002568{ \
aurel3276db3ba2008-12-08 18:11:21 +00002569 TCGv EA; \
2570 gen_set_access_type(ctx, ACCESS_INT); \
2571 EA = tcg_temp_new(); \
2572 gen_addr_imm_index(ctx, EA, 0); \
2573 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
aurel32b61f2752008-10-15 17:00:37 +00002574 tcg_temp_free(EA); \
bellard79aceca2003-11-23 14:55:54 +00002575}
2576
aurel320c8aacd2008-11-23 16:30:28 +00002577#define GEN_LDU(name, ldop, opc, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00002578static void glue(gen_, name##u)(DisasContext *ctx) \
bellard79aceca2003-11-23 14:55:54 +00002579{ \
aurel32b61f2752008-10-15 17:00:37 +00002580 TCGv EA; \
j_mayer76a66252007-03-07 08:32:30 +00002581 if (unlikely(rA(ctx->opcode) == 0 || \
2582 rA(ctx->opcode) == rD(ctx->opcode))) { \
aurel32e06fcd72008-12-11 22:42:14 +00002583 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
bellard9fddaa02004-05-21 12:59:32 +00002584 return; \
bellard9a64fbe2004-01-04 22:58:38 +00002585 } \
aurel3276db3ba2008-12-08 18:11:21 +00002586 gen_set_access_type(ctx, ACCESS_INT); \
aurel320c8aacd2008-11-23 16:30:28 +00002587 EA = tcg_temp_new(); \
j_mayer9d53c752007-04-06 07:59:47 +00002588 if (type == PPC_64B) \
aurel3276db3ba2008-12-08 18:11:21 +00002589 gen_addr_imm_index(ctx, EA, 0x03); \
j_mayer9d53c752007-04-06 07:59:47 +00002590 else \
aurel3276db3ba2008-12-08 18:11:21 +00002591 gen_addr_imm_index(ctx, EA, 0); \
2592 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
aurel32b61f2752008-10-15 17:00:37 +00002593 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2594 tcg_temp_free(EA); \
bellard79aceca2003-11-23 14:55:54 +00002595}
2596
aurel320c8aacd2008-11-23 16:30:28 +00002597#define GEN_LDUX(name, ldop, opc2, opc3, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00002598static void glue(gen_, name##ux)(DisasContext *ctx) \
bellard79aceca2003-11-23 14:55:54 +00002599{ \
aurel32b61f2752008-10-15 17:00:37 +00002600 TCGv EA; \
j_mayer76a66252007-03-07 08:32:30 +00002601 if (unlikely(rA(ctx->opcode) == 0 || \
2602 rA(ctx->opcode) == rD(ctx->opcode))) { \
aurel32e06fcd72008-12-11 22:42:14 +00002603 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
bellard9fddaa02004-05-21 12:59:32 +00002604 return; \
bellard9a64fbe2004-01-04 22:58:38 +00002605 } \
aurel3276db3ba2008-12-08 18:11:21 +00002606 gen_set_access_type(ctx, ACCESS_INT); \
aurel320c8aacd2008-11-23 16:30:28 +00002607 EA = tcg_temp_new(); \
aurel3276db3ba2008-12-08 18:11:21 +00002608 gen_addr_reg_index(ctx, EA); \
2609 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
aurel32b61f2752008-10-15 17:00:37 +00002610 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2611 tcg_temp_free(EA); \
bellard79aceca2003-11-23 14:55:54 +00002612}
2613
aurel320c8aacd2008-11-23 16:30:28 +00002614#define GEN_LDX(name, ldop, opc2, opc3, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00002615static void glue(gen_, name##x)(DisasContext *ctx) \
bellard79aceca2003-11-23 14:55:54 +00002616{ \
aurel3276db3ba2008-12-08 18:11:21 +00002617 TCGv EA; \
2618 gen_set_access_type(ctx, ACCESS_INT); \
2619 EA = tcg_temp_new(); \
2620 gen_addr_reg_index(ctx, EA); \
2621 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
aurel32b61f2752008-10-15 17:00:37 +00002622 tcg_temp_free(EA); \
bellard79aceca2003-11-23 14:55:54 +00002623}
2624
aurel320c8aacd2008-11-23 16:30:28 +00002625#define GEN_LDS(name, ldop, op, type) \
2626GEN_LD(name, ldop, op | 0x20, type); \
2627GEN_LDU(name, ldop, op | 0x21, type); \
2628GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2629GEN_LDX(name, ldop, 0x17, op | 0x00, type)
bellard79aceca2003-11-23 14:55:54 +00002630
2631/* lbz lbzu lbzux lbzx */
aurel320c8aacd2008-11-23 16:30:28 +00002632GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER);
bellard79aceca2003-11-23 14:55:54 +00002633/* lha lhau lhaux lhax */
aurel320c8aacd2008-11-23 16:30:28 +00002634GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER);
bellard79aceca2003-11-23 14:55:54 +00002635/* lhz lhzu lhzux lhzx */
aurel320c8aacd2008-11-23 16:30:28 +00002636GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER);
bellard79aceca2003-11-23 14:55:54 +00002637/* lwz lwzu lwzux lwzx */
aurel320c8aacd2008-11-23 16:30:28 +00002638GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER);
j_mayerd9bce9d2007-03-17 14:02:15 +00002639#if defined(TARGET_PPC64)
j_mayerd9bce9d2007-03-17 14:02:15 +00002640/* lwaux */
aurel320c8aacd2008-11-23 16:30:28 +00002641GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B);
j_mayerd9bce9d2007-03-17 14:02:15 +00002642/* lwax */
aurel320c8aacd2008-11-23 16:30:28 +00002643GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B);
j_mayerd9bce9d2007-03-17 14:02:15 +00002644/* ldux */
aurel320c8aacd2008-11-23 16:30:28 +00002645GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B);
j_mayerd9bce9d2007-03-17 14:02:15 +00002646/* ldx */
aurel320c8aacd2008-11-23 16:30:28 +00002647GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B);
Blue Swirl99e300e2009-06-17 15:22:09 +00002648
2649static void gen_ld(DisasContext *ctx)
j_mayerd9bce9d2007-03-17 14:02:15 +00002650{
aurel32b61f2752008-10-15 17:00:37 +00002651 TCGv EA;
j_mayerd9bce9d2007-03-17 14:02:15 +00002652 if (Rc(ctx->opcode)) {
2653 if (unlikely(rA(ctx->opcode) == 0 ||
2654 rA(ctx->opcode) == rD(ctx->opcode))) {
aurel32e06fcd72008-12-11 22:42:14 +00002655 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
j_mayerd9bce9d2007-03-17 14:02:15 +00002656 return;
2657 }
2658 }
aurel3276db3ba2008-12-08 18:11:21 +00002659 gen_set_access_type(ctx, ACCESS_INT);
pbrooka7812ae2008-11-17 14:43:54 +00002660 EA = tcg_temp_new();
aurel3276db3ba2008-12-08 18:11:21 +00002661 gen_addr_imm_index(ctx, EA, 0x03);
j_mayerd9bce9d2007-03-17 14:02:15 +00002662 if (ctx->opcode & 0x02) {
2663 /* lwa (lwau is undefined) */
aurel3276db3ba2008-12-08 18:11:21 +00002664 gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA);
j_mayerd9bce9d2007-03-17 14:02:15 +00002665 } else {
2666 /* ld - ldu */
aurel3276db3ba2008-12-08 18:11:21 +00002667 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], EA);
j_mayerd9bce9d2007-03-17 14:02:15 +00002668 }
j_mayerd9bce9d2007-03-17 14:02:15 +00002669 if (Rc(ctx->opcode))
aurel32b61f2752008-10-15 17:00:37 +00002670 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2671 tcg_temp_free(EA);
j_mayerd9bce9d2007-03-17 14:02:15 +00002672}
Blue Swirl99e300e2009-06-17 15:22:09 +00002673
Blue Swirl54623272009-06-17 15:22:19 +00002674/* lq */
Blue Swirl99e300e2009-06-17 15:22:09 +00002675static void gen_lq(DisasContext *ctx)
j_mayerbe147d02007-09-30 13:03:23 +00002676{
2677#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00002678 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayerbe147d02007-09-30 13:03:23 +00002679#else
2680 int ra, rd;
aurel32b61f2752008-10-15 17:00:37 +00002681 TCGv EA;
j_mayerbe147d02007-09-30 13:03:23 +00002682
2683 /* Restore CPU state */
aurel3276db3ba2008-12-08 18:11:21 +00002684 if (unlikely(ctx->mem_idx == 0)) {
aurel32e06fcd72008-12-11 22:42:14 +00002685 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayerbe147d02007-09-30 13:03:23 +00002686 return;
2687 }
2688 ra = rA(ctx->opcode);
2689 rd = rD(ctx->opcode);
2690 if (unlikely((rd & 1) || rd == ra)) {
aurel32e06fcd72008-12-11 22:42:14 +00002691 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
j_mayerbe147d02007-09-30 13:03:23 +00002692 return;
2693 }
aurel3276db3ba2008-12-08 18:11:21 +00002694 if (unlikely(ctx->le_mode)) {
j_mayerbe147d02007-09-30 13:03:23 +00002695 /* Little-endian mode is not handled */
aurel32e06fcd72008-12-11 22:42:14 +00002696 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
j_mayerbe147d02007-09-30 13:03:23 +00002697 return;
2698 }
aurel3276db3ba2008-12-08 18:11:21 +00002699 gen_set_access_type(ctx, ACCESS_INT);
pbrooka7812ae2008-11-17 14:43:54 +00002700 EA = tcg_temp_new();
aurel3276db3ba2008-12-08 18:11:21 +00002701 gen_addr_imm_index(ctx, EA, 0x0F);
2702 gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2703 gen_addr_add(ctx, EA, EA, 8);
2704 gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
aurel32b61f2752008-10-15 17:00:37 +00002705 tcg_temp_free(EA);
j_mayerbe147d02007-09-30 13:03:23 +00002706#endif
2707}
j_mayerd9bce9d2007-03-17 14:02:15 +00002708#endif
bellard79aceca2003-11-23 14:55:54 +00002709
2710/*** Integer store ***/
aurel320c8aacd2008-11-23 16:30:28 +00002711#define GEN_ST(name, stop, opc, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00002712static void glue(gen_, name)(DisasContext *ctx) \
bellard79aceca2003-11-23 14:55:54 +00002713{ \
aurel3276db3ba2008-12-08 18:11:21 +00002714 TCGv EA; \
2715 gen_set_access_type(ctx, ACCESS_INT); \
2716 EA = tcg_temp_new(); \
2717 gen_addr_imm_index(ctx, EA, 0); \
2718 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
aurel32b61f2752008-10-15 17:00:37 +00002719 tcg_temp_free(EA); \
bellard79aceca2003-11-23 14:55:54 +00002720}
2721
aurel320c8aacd2008-11-23 16:30:28 +00002722#define GEN_STU(name, stop, opc, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00002723static void glue(gen_, stop##u)(DisasContext *ctx) \
bellard79aceca2003-11-23 14:55:54 +00002724{ \
aurel32b61f2752008-10-15 17:00:37 +00002725 TCGv EA; \
j_mayer76a66252007-03-07 08:32:30 +00002726 if (unlikely(rA(ctx->opcode) == 0)) { \
aurel32e06fcd72008-12-11 22:42:14 +00002727 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
bellard9fddaa02004-05-21 12:59:32 +00002728 return; \
bellard9a64fbe2004-01-04 22:58:38 +00002729 } \
aurel3276db3ba2008-12-08 18:11:21 +00002730 gen_set_access_type(ctx, ACCESS_INT); \
aurel320c8aacd2008-11-23 16:30:28 +00002731 EA = tcg_temp_new(); \
j_mayer9d53c752007-04-06 07:59:47 +00002732 if (type == PPC_64B) \
aurel3276db3ba2008-12-08 18:11:21 +00002733 gen_addr_imm_index(ctx, EA, 0x03); \
j_mayer9d53c752007-04-06 07:59:47 +00002734 else \
aurel3276db3ba2008-12-08 18:11:21 +00002735 gen_addr_imm_index(ctx, EA, 0); \
2736 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
aurel32b61f2752008-10-15 17:00:37 +00002737 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2738 tcg_temp_free(EA); \
bellard79aceca2003-11-23 14:55:54 +00002739}
2740
aurel320c8aacd2008-11-23 16:30:28 +00002741#define GEN_STUX(name, stop, opc2, opc3, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00002742static void glue(gen_, name##ux)(DisasContext *ctx) \
bellard79aceca2003-11-23 14:55:54 +00002743{ \
aurel32b61f2752008-10-15 17:00:37 +00002744 TCGv EA; \
j_mayer76a66252007-03-07 08:32:30 +00002745 if (unlikely(rA(ctx->opcode) == 0)) { \
aurel32e06fcd72008-12-11 22:42:14 +00002746 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
bellard9fddaa02004-05-21 12:59:32 +00002747 return; \
bellard9a64fbe2004-01-04 22:58:38 +00002748 } \
aurel3276db3ba2008-12-08 18:11:21 +00002749 gen_set_access_type(ctx, ACCESS_INT); \
aurel320c8aacd2008-11-23 16:30:28 +00002750 EA = tcg_temp_new(); \
aurel3276db3ba2008-12-08 18:11:21 +00002751 gen_addr_reg_index(ctx, EA); \
2752 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
aurel32b61f2752008-10-15 17:00:37 +00002753 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2754 tcg_temp_free(EA); \
bellard79aceca2003-11-23 14:55:54 +00002755}
2756
aurel320c8aacd2008-11-23 16:30:28 +00002757#define GEN_STX(name, stop, opc2, opc3, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00002758static void glue(gen_, name##x)(DisasContext *ctx) \
bellard79aceca2003-11-23 14:55:54 +00002759{ \
aurel3276db3ba2008-12-08 18:11:21 +00002760 TCGv EA; \
2761 gen_set_access_type(ctx, ACCESS_INT); \
2762 EA = tcg_temp_new(); \
2763 gen_addr_reg_index(ctx, EA); \
2764 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
aurel32b61f2752008-10-15 17:00:37 +00002765 tcg_temp_free(EA); \
bellard79aceca2003-11-23 14:55:54 +00002766}
2767
aurel320c8aacd2008-11-23 16:30:28 +00002768#define GEN_STS(name, stop, op, type) \
2769GEN_ST(name, stop, op | 0x20, type); \
2770GEN_STU(name, stop, op | 0x21, type); \
2771GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2772GEN_STX(name, stop, 0x17, op | 0x00, type)
bellard79aceca2003-11-23 14:55:54 +00002773
2774/* stb stbu stbux stbx */
aurel320c8aacd2008-11-23 16:30:28 +00002775GEN_STS(stb, st8, 0x06, PPC_INTEGER);
bellard79aceca2003-11-23 14:55:54 +00002776/* sth sthu sthux sthx */
aurel320c8aacd2008-11-23 16:30:28 +00002777GEN_STS(sth, st16, 0x0C, PPC_INTEGER);
bellard79aceca2003-11-23 14:55:54 +00002778/* stw stwu stwux stwx */
aurel320c8aacd2008-11-23 16:30:28 +00002779GEN_STS(stw, st32, 0x04, PPC_INTEGER);
j_mayerd9bce9d2007-03-17 14:02:15 +00002780#if defined(TARGET_PPC64)
aurel320c8aacd2008-11-23 16:30:28 +00002781GEN_STUX(std, st64, 0x15, 0x05, PPC_64B);
2782GEN_STX(std, st64, 0x15, 0x04, PPC_64B);
Blue Swirl99e300e2009-06-17 15:22:09 +00002783
2784static void gen_std(DisasContext *ctx)
j_mayerd9bce9d2007-03-17 14:02:15 +00002785{
j_mayerbe147d02007-09-30 13:03:23 +00002786 int rs;
aurel32b61f2752008-10-15 17:00:37 +00002787 TCGv EA;
j_mayerbe147d02007-09-30 13:03:23 +00002788
2789 rs = rS(ctx->opcode);
2790 if ((ctx->opcode & 0x3) == 0x2) {
2791#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00002792 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayerbe147d02007-09-30 13:03:23 +00002793#else
2794 /* stq */
aurel3276db3ba2008-12-08 18:11:21 +00002795 if (unlikely(ctx->mem_idx == 0)) {
aurel32e06fcd72008-12-11 22:42:14 +00002796 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayerbe147d02007-09-30 13:03:23 +00002797 return;
2798 }
2799 if (unlikely(rs & 1)) {
aurel32e06fcd72008-12-11 22:42:14 +00002800 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
j_mayerd9bce9d2007-03-17 14:02:15 +00002801 return;
2802 }
aurel3276db3ba2008-12-08 18:11:21 +00002803 if (unlikely(ctx->le_mode)) {
j_mayerbe147d02007-09-30 13:03:23 +00002804 /* Little-endian mode is not handled */
aurel32e06fcd72008-12-11 22:42:14 +00002805 gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
j_mayerbe147d02007-09-30 13:03:23 +00002806 return;
2807 }
aurel3276db3ba2008-12-08 18:11:21 +00002808 gen_set_access_type(ctx, ACCESS_INT);
pbrooka7812ae2008-11-17 14:43:54 +00002809 EA = tcg_temp_new();
aurel3276db3ba2008-12-08 18:11:21 +00002810 gen_addr_imm_index(ctx, EA, 0x03);
2811 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
2812 gen_addr_add(ctx, EA, EA, 8);
2813 gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
aurel32b61f2752008-10-15 17:00:37 +00002814 tcg_temp_free(EA);
j_mayerbe147d02007-09-30 13:03:23 +00002815#endif
2816 } else {
2817 /* std / stdu */
2818 if (Rc(ctx->opcode)) {
2819 if (unlikely(rA(ctx->opcode) == 0)) {
aurel32e06fcd72008-12-11 22:42:14 +00002820 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
j_mayerbe147d02007-09-30 13:03:23 +00002821 return;
2822 }
2823 }
aurel3276db3ba2008-12-08 18:11:21 +00002824 gen_set_access_type(ctx, ACCESS_INT);
pbrooka7812ae2008-11-17 14:43:54 +00002825 EA = tcg_temp_new();
aurel3276db3ba2008-12-08 18:11:21 +00002826 gen_addr_imm_index(ctx, EA, 0x03);
2827 gen_qemu_st64(ctx, cpu_gpr[rs], EA);
j_mayerbe147d02007-09-30 13:03:23 +00002828 if (Rc(ctx->opcode))
aurel32b61f2752008-10-15 17:00:37 +00002829 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2830 tcg_temp_free(EA);
j_mayerd9bce9d2007-03-17 14:02:15 +00002831 }
j_mayerd9bce9d2007-03-17 14:02:15 +00002832}
2833#endif
bellard79aceca2003-11-23 14:55:54 +00002834/*** Integer load and store with byte reverse ***/
2835/* lhbrx */
Juan Quintela86178a52009-09-23 01:19:00 +02002836static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
aurel32b61f2752008-10-15 17:00:37 +00002837{
aurel3276db3ba2008-12-08 18:11:21 +00002838 tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
2839 if (likely(!ctx->le_mode)) {
aurel32fa3966a2009-03-13 09:35:34 +00002840 tcg_gen_bswap16_tl(arg1, arg1);
aurel3276db3ba2008-12-08 18:11:21 +00002841 }
aurel32b61f2752008-10-15 17:00:37 +00002842}
aurel320c8aacd2008-11-23 16:30:28 +00002843GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER);
aurel32b61f2752008-10-15 17:00:37 +00002844
bellard79aceca2003-11-23 14:55:54 +00002845/* lwbrx */
Juan Quintela86178a52009-09-23 01:19:00 +02002846static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
aurel32b61f2752008-10-15 17:00:37 +00002847{
aurel3276db3ba2008-12-08 18:11:21 +00002848 tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
2849 if (likely(!ctx->le_mode)) {
aurel32fa3966a2009-03-13 09:35:34 +00002850 tcg_gen_bswap32_tl(arg1, arg1);
aurel3276db3ba2008-12-08 18:11:21 +00002851 }
aurel32b61f2752008-10-15 17:00:37 +00002852}
aurel320c8aacd2008-11-23 16:30:28 +00002853GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER);
aurel32b61f2752008-10-15 17:00:37 +00002854
bellard79aceca2003-11-23 14:55:54 +00002855/* sthbrx */
Juan Quintela86178a52009-09-23 01:19:00 +02002856static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2)
aurel32b61f2752008-10-15 17:00:37 +00002857{
aurel3276db3ba2008-12-08 18:11:21 +00002858 if (likely(!ctx->le_mode)) {
aurel3276db3ba2008-12-08 18:11:21 +00002859 TCGv t0 = tcg_temp_new();
2860 tcg_gen_ext16u_tl(t0, arg1);
aurel32fa3966a2009-03-13 09:35:34 +00002861 tcg_gen_bswap16_tl(t0, t0);
aurel3276db3ba2008-12-08 18:11:21 +00002862 tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
2863 tcg_temp_free(t0);
aurel3276db3ba2008-12-08 18:11:21 +00002864 } else {
2865 tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
2866 }
aurel32b61f2752008-10-15 17:00:37 +00002867}
aurel320c8aacd2008-11-23 16:30:28 +00002868GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER);
aurel32b61f2752008-10-15 17:00:37 +00002869
bellard79aceca2003-11-23 14:55:54 +00002870/* stwbrx */
Juan Quintela86178a52009-09-23 01:19:00 +02002871static inline void gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2)
aurel32b61f2752008-10-15 17:00:37 +00002872{
aurel3276db3ba2008-12-08 18:11:21 +00002873 if (likely(!ctx->le_mode)) {
aurel32fa3966a2009-03-13 09:35:34 +00002874 TCGv t0 = tcg_temp_new();
2875 tcg_gen_ext32u_tl(t0, arg1);
2876 tcg_gen_bswap32_tl(t0, t0);
aurel3276db3ba2008-12-08 18:11:21 +00002877 tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
2878 tcg_temp_free(t0);
aurel3276db3ba2008-12-08 18:11:21 +00002879 } else {
2880 tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
2881 }
aurel32b61f2752008-10-15 17:00:37 +00002882}
aurel320c8aacd2008-11-23 16:30:28 +00002883GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER);
bellard79aceca2003-11-23 14:55:54 +00002884
2885/*** Integer load and store multiple ***/
Blue Swirl99e300e2009-06-17 15:22:09 +00002886
Blue Swirl54623272009-06-17 15:22:19 +00002887/* lmw */
Blue Swirl99e300e2009-06-17 15:22:09 +00002888static void gen_lmw(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00002889{
aurel3276db3ba2008-12-08 18:11:21 +00002890 TCGv t0;
2891 TCGv_i32 t1;
2892 gen_set_access_type(ctx, ACCESS_INT);
j_mayer76a66252007-03-07 08:32:30 +00002893 /* NIP cannot be restored if the memory exception comes from an helper */
j_mayerd9bce9d2007-03-17 14:02:15 +00002894 gen_update_nip(ctx, ctx->nip - 4);
aurel3276db3ba2008-12-08 18:11:21 +00002895 t0 = tcg_temp_new();
2896 t1 = tcg_const_i32(rD(ctx->opcode));
2897 gen_addr_imm_index(ctx, t0, 0);
aurel32ff4a62c2008-11-30 16:23:56 +00002898 gen_helper_lmw(t0, t1);
2899 tcg_temp_free(t0);
2900 tcg_temp_free_i32(t1);
bellard79aceca2003-11-23 14:55:54 +00002901}
2902
2903/* stmw */
Blue Swirl99e300e2009-06-17 15:22:09 +00002904static void gen_stmw(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00002905{
aurel3276db3ba2008-12-08 18:11:21 +00002906 TCGv t0;
2907 TCGv_i32 t1;
2908 gen_set_access_type(ctx, ACCESS_INT);
j_mayer76a66252007-03-07 08:32:30 +00002909 /* NIP cannot be restored if the memory exception comes from an helper */
j_mayerd9bce9d2007-03-17 14:02:15 +00002910 gen_update_nip(ctx, ctx->nip - 4);
aurel3276db3ba2008-12-08 18:11:21 +00002911 t0 = tcg_temp_new();
2912 t1 = tcg_const_i32(rS(ctx->opcode));
2913 gen_addr_imm_index(ctx, t0, 0);
aurel32ff4a62c2008-11-30 16:23:56 +00002914 gen_helper_stmw(t0, t1);
2915 tcg_temp_free(t0);
2916 tcg_temp_free_i32(t1);
bellard79aceca2003-11-23 14:55:54 +00002917}
2918
2919/*** Integer load and store strings ***/
Blue Swirl54623272009-06-17 15:22:19 +00002920
bellard79aceca2003-11-23 14:55:54 +00002921/* lswi */
bellard3fc6c082005-07-02 20:59:34 +00002922/* PowerPC32 specification says we must generate an exception if
bellard9a64fbe2004-01-04 22:58:38 +00002923 * rA is in the range of registers to be loaded.
2924 * In an other hand, IBM says this is valid, but rA won't be loaded.
2925 * For now, I'll follow the spec...
2926 */
Blue Swirl99e300e2009-06-17 15:22:09 +00002927static void gen_lswi(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00002928{
aurel32dfbc7992008-11-30 16:24:21 +00002929 TCGv t0;
2930 TCGv_i32 t1, t2;
bellard79aceca2003-11-23 14:55:54 +00002931 int nb = NB(ctx->opcode);
2932 int start = rD(ctx->opcode);
bellard9a64fbe2004-01-04 22:58:38 +00002933 int ra = rA(ctx->opcode);
bellard79aceca2003-11-23 14:55:54 +00002934 int nr;
2935
2936 if (nb == 0)
2937 nb = 32;
2938 nr = nb / 4;
j_mayer76a66252007-03-07 08:32:30 +00002939 if (unlikely(((start + nr) > 32 &&
2940 start <= ra && (start + nr - 32) > ra) ||
2941 ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) {
aurel32e06fcd72008-12-11 22:42:14 +00002942 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
bellard9fddaa02004-05-21 12:59:32 +00002943 return;
bellard297d8e62004-02-21 14:11:27 +00002944 }
aurel3276db3ba2008-12-08 18:11:21 +00002945 gen_set_access_type(ctx, ACCESS_INT);
bellard8dd49832005-06-04 22:22:27 +00002946 /* NIP cannot be restored if the memory exception comes from an helper */
j_mayerd9bce9d2007-03-17 14:02:15 +00002947 gen_update_nip(ctx, ctx->nip - 4);
aurel32dfbc7992008-11-30 16:24:21 +00002948 t0 = tcg_temp_new();
aurel3276db3ba2008-12-08 18:11:21 +00002949 gen_addr_register(ctx, t0);
aurel32dfbc7992008-11-30 16:24:21 +00002950 t1 = tcg_const_i32(nb);
2951 t2 = tcg_const_i32(start);
2952 gen_helper_lsw(t0, t1, t2);
2953 tcg_temp_free(t0);
2954 tcg_temp_free_i32(t1);
2955 tcg_temp_free_i32(t2);
bellard79aceca2003-11-23 14:55:54 +00002956}
2957
2958/* lswx */
Blue Swirl99e300e2009-06-17 15:22:09 +00002959static void gen_lswx(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00002960{
aurel3276db3ba2008-12-08 18:11:21 +00002961 TCGv t0;
2962 TCGv_i32 t1, t2, t3;
2963 gen_set_access_type(ctx, ACCESS_INT);
j_mayer76a66252007-03-07 08:32:30 +00002964 /* NIP cannot be restored if the memory exception comes from an helper */
j_mayerd9bce9d2007-03-17 14:02:15 +00002965 gen_update_nip(ctx, ctx->nip - 4);
aurel3276db3ba2008-12-08 18:11:21 +00002966 t0 = tcg_temp_new();
2967 gen_addr_reg_index(ctx, t0);
2968 t1 = tcg_const_i32(rD(ctx->opcode));
2969 t2 = tcg_const_i32(rA(ctx->opcode));
2970 t3 = tcg_const_i32(rB(ctx->opcode));
aurel32dfbc7992008-11-30 16:24:21 +00002971 gen_helper_lswx(t0, t1, t2, t3);
2972 tcg_temp_free(t0);
2973 tcg_temp_free_i32(t1);
2974 tcg_temp_free_i32(t2);
2975 tcg_temp_free_i32(t3);
bellard79aceca2003-11-23 14:55:54 +00002976}
2977
2978/* stswi */
Blue Swirl99e300e2009-06-17 15:22:09 +00002979static void gen_stswi(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00002980{
aurel3276db3ba2008-12-08 18:11:21 +00002981 TCGv t0;
2982 TCGv_i32 t1, t2;
bellard4b3686f2004-05-23 22:18:12 +00002983 int nb = NB(ctx->opcode);
aurel3276db3ba2008-12-08 18:11:21 +00002984 gen_set_access_type(ctx, ACCESS_INT);
j_mayer76a66252007-03-07 08:32:30 +00002985 /* NIP cannot be restored if the memory exception comes from an helper */
j_mayerd9bce9d2007-03-17 14:02:15 +00002986 gen_update_nip(ctx, ctx->nip - 4);
aurel3276db3ba2008-12-08 18:11:21 +00002987 t0 = tcg_temp_new();
2988 gen_addr_register(ctx, t0);
bellard4b3686f2004-05-23 22:18:12 +00002989 if (nb == 0)
2990 nb = 32;
aurel32dfbc7992008-11-30 16:24:21 +00002991 t1 = tcg_const_i32(nb);
aurel3276db3ba2008-12-08 18:11:21 +00002992 t2 = tcg_const_i32(rS(ctx->opcode));
aurel32dfbc7992008-11-30 16:24:21 +00002993 gen_helper_stsw(t0, t1, t2);
2994 tcg_temp_free(t0);
2995 tcg_temp_free_i32(t1);
2996 tcg_temp_free_i32(t2);
bellard79aceca2003-11-23 14:55:54 +00002997}
2998
2999/* stswx */
Blue Swirl99e300e2009-06-17 15:22:09 +00003000static void gen_stswx(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003001{
aurel3276db3ba2008-12-08 18:11:21 +00003002 TCGv t0;
3003 TCGv_i32 t1, t2;
3004 gen_set_access_type(ctx, ACCESS_INT);
bellard8dd49832005-06-04 22:22:27 +00003005 /* NIP cannot be restored if the memory exception comes from an helper */
ths5fafdf22007-09-16 21:08:06 +00003006 gen_update_nip(ctx, ctx->nip - 4);
aurel3276db3ba2008-12-08 18:11:21 +00003007 t0 = tcg_temp_new();
3008 gen_addr_reg_index(ctx, t0);
3009 t1 = tcg_temp_new_i32();
aurel32dfbc7992008-11-30 16:24:21 +00003010 tcg_gen_trunc_tl_i32(t1, cpu_xer);
3011 tcg_gen_andi_i32(t1, t1, 0x7F);
aurel3276db3ba2008-12-08 18:11:21 +00003012 t2 = tcg_const_i32(rS(ctx->opcode));
aurel32dfbc7992008-11-30 16:24:21 +00003013 gen_helper_stsw(t0, t1, t2);
3014 tcg_temp_free(t0);
3015 tcg_temp_free_i32(t1);
3016 tcg_temp_free_i32(t2);
bellard79aceca2003-11-23 14:55:54 +00003017}
3018
3019/*** Memory synchronisation ***/
3020/* eieio */
Blue Swirl99e300e2009-06-17 15:22:09 +00003021static void gen_eieio(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003022{
bellard79aceca2003-11-23 14:55:54 +00003023}
3024
3025/* isync */
Blue Swirl99e300e2009-06-17 15:22:09 +00003026static void gen_isync(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003027{
aurel32e06fcd72008-12-11 22:42:14 +00003028 gen_stop_exception(ctx);
bellard79aceca2003-11-23 14:55:54 +00003029}
3030
bellard111bfab2005-04-23 18:16:07 +00003031/* lwarx */
Blue Swirl99e300e2009-06-17 15:22:09 +00003032static void gen_lwarx(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003033{
aurel3276db3ba2008-12-08 18:11:21 +00003034 TCGv t0;
Nathan Froyd18b21a22009-08-03 08:43:25 -07003035 TCGv gpr = cpu_gpr[rD(ctx->opcode)];
aurel3276db3ba2008-12-08 18:11:21 +00003036 gen_set_access_type(ctx, ACCESS_RES);
3037 t0 = tcg_temp_local_new();
3038 gen_addr_reg_index(ctx, t0);
aurel32cf360a32008-11-30 16:24:39 +00003039 gen_check_align(ctx, t0, 0x03);
Nathan Froyd18b21a22009-08-03 08:43:25 -07003040 gen_qemu_ld32u(ctx, gpr, t0);
aurel32cf360a32008-11-30 16:24:39 +00003041 tcg_gen_mov_tl(cpu_reserve, t0);
Nathan Froyd18b21a22009-08-03 08:43:25 -07003042 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUState, reserve_val));
aurel32cf360a32008-11-30 16:24:39 +00003043 tcg_temp_free(t0);
bellard79aceca2003-11-23 14:55:54 +00003044}
3045
Nathan Froyd44252652009-08-03 08:43:26 -07003046#if defined(CONFIG_USER_ONLY)
3047static void gen_conditional_store (DisasContext *ctx, TCGv EA,
3048 int reg, int size)
3049{
3050 TCGv t0 = tcg_temp_new();
3051 uint32_t save_exception = ctx->exception;
3052
3053 tcg_gen_st_tl(EA, cpu_env, offsetof(CPUState, reserve_ea));
3054 tcg_gen_movi_tl(t0, (size << 5) | reg);
3055 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, reserve_info));
3056 tcg_temp_free(t0);
3057 gen_update_nip(ctx, ctx->nip-4);
3058 ctx->exception = POWERPC_EXCP_BRANCH;
3059 gen_exception(ctx, POWERPC_EXCP_STCX);
3060 ctx->exception = save_exception;
3061}
3062#endif
3063
bellard79aceca2003-11-23 14:55:54 +00003064/* stwcx. */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00003065static void gen_stwcx_(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003066{
aurel3276db3ba2008-12-08 18:11:21 +00003067 TCGv t0;
3068 gen_set_access_type(ctx, ACCESS_RES);
3069 t0 = tcg_temp_local_new();
3070 gen_addr_reg_index(ctx, t0);
aurel32cf360a32008-11-30 16:24:39 +00003071 gen_check_align(ctx, t0, 0x03);
Nathan Froyd44252652009-08-03 08:43:26 -07003072#if defined(CONFIG_USER_ONLY)
3073 gen_conditional_store(ctx, t0, rS(ctx->opcode), 4);
3074#else
3075 {
3076 int l1;
3077
3078 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_xer);
3079 tcg_gen_shri_i32(cpu_crf[0], cpu_crf[0], XER_SO);
3080 tcg_gen_andi_i32(cpu_crf[0], cpu_crf[0], 1);
3081 l1 = gen_new_label();
3082 tcg_gen_brcond_tl(TCG_COND_NE, t0, cpu_reserve, l1);
3083 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
3084 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], t0);
3085 gen_set_label(l1);
3086 tcg_gen_movi_tl(cpu_reserve, -1);
3087 }
3088#endif
aurel32cf360a32008-11-30 16:24:39 +00003089 tcg_temp_free(t0);
bellard79aceca2003-11-23 14:55:54 +00003090}
3091
j_mayer426613d2007-03-23 09:45:27 +00003092#if defined(TARGET_PPC64)
j_mayer426613d2007-03-23 09:45:27 +00003093/* ldarx */
Blue Swirl99e300e2009-06-17 15:22:09 +00003094static void gen_ldarx(DisasContext *ctx)
j_mayer426613d2007-03-23 09:45:27 +00003095{
aurel3276db3ba2008-12-08 18:11:21 +00003096 TCGv t0;
Nathan Froyd18b21a22009-08-03 08:43:25 -07003097 TCGv gpr = cpu_gpr[rD(ctx->opcode)];
aurel3276db3ba2008-12-08 18:11:21 +00003098 gen_set_access_type(ctx, ACCESS_RES);
3099 t0 = tcg_temp_local_new();
3100 gen_addr_reg_index(ctx, t0);
aurel32cf360a32008-11-30 16:24:39 +00003101 gen_check_align(ctx, t0, 0x07);
Nathan Froyd18b21a22009-08-03 08:43:25 -07003102 gen_qemu_ld64(ctx, gpr, t0);
aurel32cf360a32008-11-30 16:24:39 +00003103 tcg_gen_mov_tl(cpu_reserve, t0);
Nathan Froyd18b21a22009-08-03 08:43:25 -07003104 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUState, reserve_val));
aurel32cf360a32008-11-30 16:24:39 +00003105 tcg_temp_free(t0);
j_mayer426613d2007-03-23 09:45:27 +00003106}
3107
3108/* stdcx. */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00003109static void gen_stdcx_(DisasContext *ctx)
j_mayer426613d2007-03-23 09:45:27 +00003110{
aurel3276db3ba2008-12-08 18:11:21 +00003111 TCGv t0;
3112 gen_set_access_type(ctx, ACCESS_RES);
3113 t0 = tcg_temp_local_new();
3114 gen_addr_reg_index(ctx, t0);
aurel32cf360a32008-11-30 16:24:39 +00003115 gen_check_align(ctx, t0, 0x07);
Nathan Froyd44252652009-08-03 08:43:26 -07003116#if defined(CONFIG_USER_ONLY)
3117 gen_conditional_store(ctx, t0, rS(ctx->opcode), 8);
3118#else
3119 {
3120 int l1;
3121 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_xer);
3122 tcg_gen_shri_i32(cpu_crf[0], cpu_crf[0], XER_SO);
3123 tcg_gen_andi_i32(cpu_crf[0], cpu_crf[0], 1);
3124 l1 = gen_new_label();
3125 tcg_gen_brcond_tl(TCG_COND_NE, t0, cpu_reserve, l1);
3126 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
3127 gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], t0);
3128 gen_set_label(l1);
3129 tcg_gen_movi_tl(cpu_reserve, -1);
3130 }
3131#endif
aurel32cf360a32008-11-30 16:24:39 +00003132 tcg_temp_free(t0);
j_mayer426613d2007-03-23 09:45:27 +00003133}
3134#endif /* defined(TARGET_PPC64) */
3135
bellard79aceca2003-11-23 14:55:54 +00003136/* sync */
Blue Swirl99e300e2009-06-17 15:22:09 +00003137static void gen_sync(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003138{
bellard79aceca2003-11-23 14:55:54 +00003139}
3140
j_mayer0db1b202007-09-30 03:46:38 +00003141/* wait */
Blue Swirl99e300e2009-06-17 15:22:09 +00003142static void gen_wait(DisasContext *ctx)
j_mayer0db1b202007-09-30 03:46:38 +00003143{
aurel32931ff272008-11-30 16:23:46 +00003144 TCGv_i32 t0 = tcg_temp_new_i32();
3145 tcg_gen_st_i32(t0, cpu_env, offsetof(CPUState, halted));
3146 tcg_temp_free_i32(t0);
j_mayer0db1b202007-09-30 03:46:38 +00003147 /* Stop translation, as the CPU is supposed to sleep from now */
aurel32e06fcd72008-12-11 22:42:14 +00003148 gen_exception_err(ctx, EXCP_HLT, 1);
j_mayer0db1b202007-09-30 03:46:38 +00003149}
3150
bellard79aceca2003-11-23 14:55:54 +00003151/*** Floating-point load ***/
aurel32a0d7d5a2008-11-23 16:30:50 +00003152#define GEN_LDF(name, ldop, opc, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00003153static void glue(gen_, name)(DisasContext *ctx) \
bellard79aceca2003-11-23 14:55:54 +00003154{ \
aurel32a0d7d5a2008-11-23 16:30:50 +00003155 TCGv EA; \
j_mayer76a66252007-03-07 08:32:30 +00003156 if (unlikely(!ctx->fpu_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00003157 gen_exception(ctx, POWERPC_EXCP_FPU); \
bellard4ecc3192005-03-13 17:01:22 +00003158 return; \
3159 } \
aurel3276db3ba2008-12-08 18:11:21 +00003160 gen_set_access_type(ctx, ACCESS_FLOAT); \
aurel32a0d7d5a2008-11-23 16:30:50 +00003161 EA = tcg_temp_new(); \
aurel3276db3ba2008-12-08 18:11:21 +00003162 gen_addr_imm_index(ctx, EA, 0); \
3163 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
aurel32a0d7d5a2008-11-23 16:30:50 +00003164 tcg_temp_free(EA); \
bellard79aceca2003-11-23 14:55:54 +00003165}
3166
aurel32a0d7d5a2008-11-23 16:30:50 +00003167#define GEN_LDUF(name, ldop, opc, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00003168static void glue(gen_, name##u)(DisasContext *ctx) \
bellard79aceca2003-11-23 14:55:54 +00003169{ \
aurel32a0d7d5a2008-11-23 16:30:50 +00003170 TCGv EA; \
j_mayer76a66252007-03-07 08:32:30 +00003171 if (unlikely(!ctx->fpu_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00003172 gen_exception(ctx, POWERPC_EXCP_FPU); \
bellard4ecc3192005-03-13 17:01:22 +00003173 return; \
3174 } \
j_mayer76a66252007-03-07 08:32:30 +00003175 if (unlikely(rA(ctx->opcode) == 0)) { \
aurel32e06fcd72008-12-11 22:42:14 +00003176 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
bellard9fddaa02004-05-21 12:59:32 +00003177 return; \
bellard9a64fbe2004-01-04 22:58:38 +00003178 } \
aurel3276db3ba2008-12-08 18:11:21 +00003179 gen_set_access_type(ctx, ACCESS_FLOAT); \
aurel32a0d7d5a2008-11-23 16:30:50 +00003180 EA = tcg_temp_new(); \
aurel3276db3ba2008-12-08 18:11:21 +00003181 gen_addr_imm_index(ctx, EA, 0); \
3182 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
aurel32a0d7d5a2008-11-23 16:30:50 +00003183 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3184 tcg_temp_free(EA); \
bellard79aceca2003-11-23 14:55:54 +00003185}
3186
aurel32a0d7d5a2008-11-23 16:30:50 +00003187#define GEN_LDUXF(name, ldop, opc, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00003188static void glue(gen_, name##ux)(DisasContext *ctx) \
bellard79aceca2003-11-23 14:55:54 +00003189{ \
aurel32a0d7d5a2008-11-23 16:30:50 +00003190 TCGv EA; \
j_mayer76a66252007-03-07 08:32:30 +00003191 if (unlikely(!ctx->fpu_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00003192 gen_exception(ctx, POWERPC_EXCP_FPU); \
bellard4ecc3192005-03-13 17:01:22 +00003193 return; \
3194 } \
j_mayer76a66252007-03-07 08:32:30 +00003195 if (unlikely(rA(ctx->opcode) == 0)) { \
aurel32e06fcd72008-12-11 22:42:14 +00003196 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
bellard9fddaa02004-05-21 12:59:32 +00003197 return; \
bellard9a64fbe2004-01-04 22:58:38 +00003198 } \
aurel3276db3ba2008-12-08 18:11:21 +00003199 gen_set_access_type(ctx, ACCESS_FLOAT); \
aurel32a0d7d5a2008-11-23 16:30:50 +00003200 EA = tcg_temp_new(); \
aurel3276db3ba2008-12-08 18:11:21 +00003201 gen_addr_reg_index(ctx, EA); \
3202 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
aurel32a0d7d5a2008-11-23 16:30:50 +00003203 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3204 tcg_temp_free(EA); \
bellard79aceca2003-11-23 14:55:54 +00003205}
3206
aurel32a0d7d5a2008-11-23 16:30:50 +00003207#define GEN_LDXF(name, ldop, opc2, opc3, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00003208static void glue(gen_, name##x)(DisasContext *ctx) \
bellard79aceca2003-11-23 14:55:54 +00003209{ \
aurel32a0d7d5a2008-11-23 16:30:50 +00003210 TCGv EA; \
j_mayer76a66252007-03-07 08:32:30 +00003211 if (unlikely(!ctx->fpu_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00003212 gen_exception(ctx, POWERPC_EXCP_FPU); \
bellard4ecc3192005-03-13 17:01:22 +00003213 return; \
3214 } \
aurel3276db3ba2008-12-08 18:11:21 +00003215 gen_set_access_type(ctx, ACCESS_FLOAT); \
aurel32a0d7d5a2008-11-23 16:30:50 +00003216 EA = tcg_temp_new(); \
aurel3276db3ba2008-12-08 18:11:21 +00003217 gen_addr_reg_index(ctx, EA); \
3218 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
aurel32a0d7d5a2008-11-23 16:30:50 +00003219 tcg_temp_free(EA); \
bellard79aceca2003-11-23 14:55:54 +00003220}
3221
aurel32a0d7d5a2008-11-23 16:30:50 +00003222#define GEN_LDFS(name, ldop, op, type) \
3223GEN_LDF(name, ldop, op | 0x20, type); \
3224GEN_LDUF(name, ldop, op | 0x21, type); \
3225GEN_LDUXF(name, ldop, op | 0x01, type); \
3226GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
bellard79aceca2003-11-23 14:55:54 +00003227
Blue Swirl636aa202009-08-16 09:06:54 +00003228static inline void gen_qemu_ld32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
aurel32a0d7d5a2008-11-23 16:30:50 +00003229{
3230 TCGv t0 = tcg_temp_new();
3231 TCGv_i32 t1 = tcg_temp_new_i32();
aurel3276db3ba2008-12-08 18:11:21 +00003232 gen_qemu_ld32u(ctx, t0, arg2);
aurel32a0d7d5a2008-11-23 16:30:50 +00003233 tcg_gen_trunc_tl_i32(t1, t0);
3234 tcg_temp_free(t0);
3235 gen_helper_float32_to_float64(arg1, t1);
3236 tcg_temp_free_i32(t1);
3237}
3238
3239 /* lfd lfdu lfdux lfdx */
3240GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT);
3241 /* lfs lfsu lfsux lfsx */
3242GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT);
bellard79aceca2003-11-23 14:55:54 +00003243
3244/*** Floating-point store ***/
aurel32a0d7d5a2008-11-23 16:30:50 +00003245#define GEN_STF(name, stop, opc, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00003246static void glue(gen_, name)(DisasContext *ctx) \
bellard79aceca2003-11-23 14:55:54 +00003247{ \
aurel32a0d7d5a2008-11-23 16:30:50 +00003248 TCGv EA; \
j_mayer76a66252007-03-07 08:32:30 +00003249 if (unlikely(!ctx->fpu_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00003250 gen_exception(ctx, POWERPC_EXCP_FPU); \
bellard4ecc3192005-03-13 17:01:22 +00003251 return; \
3252 } \
aurel3276db3ba2008-12-08 18:11:21 +00003253 gen_set_access_type(ctx, ACCESS_FLOAT); \
aurel32a0d7d5a2008-11-23 16:30:50 +00003254 EA = tcg_temp_new(); \
aurel3276db3ba2008-12-08 18:11:21 +00003255 gen_addr_imm_index(ctx, EA, 0); \
3256 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
aurel32a0d7d5a2008-11-23 16:30:50 +00003257 tcg_temp_free(EA); \
bellard79aceca2003-11-23 14:55:54 +00003258}
3259
aurel32a0d7d5a2008-11-23 16:30:50 +00003260#define GEN_STUF(name, stop, opc, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00003261static void glue(gen_, name##u)(DisasContext *ctx) \
bellard79aceca2003-11-23 14:55:54 +00003262{ \
aurel32a0d7d5a2008-11-23 16:30:50 +00003263 TCGv EA; \
j_mayer76a66252007-03-07 08:32:30 +00003264 if (unlikely(!ctx->fpu_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00003265 gen_exception(ctx, POWERPC_EXCP_FPU); \
bellard4ecc3192005-03-13 17:01:22 +00003266 return; \
3267 } \
j_mayer76a66252007-03-07 08:32:30 +00003268 if (unlikely(rA(ctx->opcode) == 0)) { \
aurel32e06fcd72008-12-11 22:42:14 +00003269 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
bellard9fddaa02004-05-21 12:59:32 +00003270 return; \
bellard9a64fbe2004-01-04 22:58:38 +00003271 } \
aurel3276db3ba2008-12-08 18:11:21 +00003272 gen_set_access_type(ctx, ACCESS_FLOAT); \
aurel32a0d7d5a2008-11-23 16:30:50 +00003273 EA = tcg_temp_new(); \
aurel3276db3ba2008-12-08 18:11:21 +00003274 gen_addr_imm_index(ctx, EA, 0); \
3275 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
aurel32a0d7d5a2008-11-23 16:30:50 +00003276 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3277 tcg_temp_free(EA); \
bellard79aceca2003-11-23 14:55:54 +00003278}
3279
aurel32a0d7d5a2008-11-23 16:30:50 +00003280#define GEN_STUXF(name, stop, opc, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00003281static void glue(gen_, name##ux)(DisasContext *ctx) \
bellard79aceca2003-11-23 14:55:54 +00003282{ \
aurel32a0d7d5a2008-11-23 16:30:50 +00003283 TCGv EA; \
j_mayer76a66252007-03-07 08:32:30 +00003284 if (unlikely(!ctx->fpu_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00003285 gen_exception(ctx, POWERPC_EXCP_FPU); \
bellard4ecc3192005-03-13 17:01:22 +00003286 return; \
3287 } \
j_mayer76a66252007-03-07 08:32:30 +00003288 if (unlikely(rA(ctx->opcode) == 0)) { \
aurel32e06fcd72008-12-11 22:42:14 +00003289 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
bellard9fddaa02004-05-21 12:59:32 +00003290 return; \
bellard9a64fbe2004-01-04 22:58:38 +00003291 } \
aurel3276db3ba2008-12-08 18:11:21 +00003292 gen_set_access_type(ctx, ACCESS_FLOAT); \
aurel32a0d7d5a2008-11-23 16:30:50 +00003293 EA = tcg_temp_new(); \
aurel3276db3ba2008-12-08 18:11:21 +00003294 gen_addr_reg_index(ctx, EA); \
3295 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
aurel32a0d7d5a2008-11-23 16:30:50 +00003296 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3297 tcg_temp_free(EA); \
bellard79aceca2003-11-23 14:55:54 +00003298}
3299
aurel32a0d7d5a2008-11-23 16:30:50 +00003300#define GEN_STXF(name, stop, opc2, opc3, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00003301static void glue(gen_, name##x)(DisasContext *ctx) \
bellard79aceca2003-11-23 14:55:54 +00003302{ \
aurel32a0d7d5a2008-11-23 16:30:50 +00003303 TCGv EA; \
j_mayer76a66252007-03-07 08:32:30 +00003304 if (unlikely(!ctx->fpu_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00003305 gen_exception(ctx, POWERPC_EXCP_FPU); \
bellard4ecc3192005-03-13 17:01:22 +00003306 return; \
3307 } \
aurel3276db3ba2008-12-08 18:11:21 +00003308 gen_set_access_type(ctx, ACCESS_FLOAT); \
aurel32a0d7d5a2008-11-23 16:30:50 +00003309 EA = tcg_temp_new(); \
aurel3276db3ba2008-12-08 18:11:21 +00003310 gen_addr_reg_index(ctx, EA); \
3311 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
aurel32a0d7d5a2008-11-23 16:30:50 +00003312 tcg_temp_free(EA); \
bellard79aceca2003-11-23 14:55:54 +00003313}
3314
aurel32a0d7d5a2008-11-23 16:30:50 +00003315#define GEN_STFS(name, stop, op, type) \
3316GEN_STF(name, stop, op | 0x20, type); \
3317GEN_STUF(name, stop, op | 0x21, type); \
3318GEN_STUXF(name, stop, op | 0x01, type); \
3319GEN_STXF(name, stop, 0x17, op | 0x00, type)
3320
Blue Swirl636aa202009-08-16 09:06:54 +00003321static inline void gen_qemu_st32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
aurel32a0d7d5a2008-11-23 16:30:50 +00003322{
3323 TCGv_i32 t0 = tcg_temp_new_i32();
3324 TCGv t1 = tcg_temp_new();
3325 gen_helper_float64_to_float32(t0, arg1);
3326 tcg_gen_extu_i32_tl(t1, t0);
3327 tcg_temp_free_i32(t0);
aurel3276db3ba2008-12-08 18:11:21 +00003328 gen_qemu_st32(ctx, t1, arg2);
aurel32a0d7d5a2008-11-23 16:30:50 +00003329 tcg_temp_free(t1);
3330}
bellard79aceca2003-11-23 14:55:54 +00003331
3332/* stfd stfdu stfdux stfdx */
aurel32a0d7d5a2008-11-23 16:30:50 +00003333GEN_STFS(stfd, st64, 0x16, PPC_FLOAT);
bellard79aceca2003-11-23 14:55:54 +00003334/* stfs stfsu stfsux stfsx */
aurel32a0d7d5a2008-11-23 16:30:50 +00003335GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT);
bellard79aceca2003-11-23 14:55:54 +00003336
3337/* Optional: */
Blue Swirl636aa202009-08-16 09:06:54 +00003338static inline void gen_qemu_st32fiw(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
aurel32a0d7d5a2008-11-23 16:30:50 +00003339{
3340 TCGv t0 = tcg_temp_new();
3341 tcg_gen_trunc_i64_tl(t0, arg1),
aurel3276db3ba2008-12-08 18:11:21 +00003342 gen_qemu_st32(ctx, t0, arg2);
aurel32a0d7d5a2008-11-23 16:30:50 +00003343 tcg_temp_free(t0);
3344}
bellard79aceca2003-11-23 14:55:54 +00003345/* stfiwx */
aurel32a0d7d5a2008-11-23 16:30:50 +00003346GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX);
bellard79aceca2003-11-23 14:55:54 +00003347
3348/*** Branch ***/
Blue Swirl636aa202009-08-16 09:06:54 +00003349static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
bellardc53be332005-10-30 21:39:19 +00003350{
bellardc1942362005-11-20 10:31:08 +00003351 TranslationBlock *tb;
3352 tb = ctx->tb;
aurel32a2ffb812008-10-21 16:31:31 +00003353#if defined(TARGET_PPC64)
3354 if (!ctx->sf_mode)
3355 dest = (uint32_t) dest;
3356#endif
bellard57fec1f2008-02-01 10:50:11 +00003357 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) &&
aurel328cbcb4f2008-05-10 23:28:14 +00003358 likely(!ctx->singlestep_enabled)) {
bellard57fec1f2008-02-01 10:50:11 +00003359 tcg_gen_goto_tb(n);
aurel32a2ffb812008-10-21 16:31:31 +00003360 tcg_gen_movi_tl(cpu_nip, dest & ~3);
Stefan Weil4b4a72e2011-04-02 13:36:31 +02003361 tcg_gen_exit_tb((tcg_target_long)tb + n);
bellardc1942362005-11-20 10:31:08 +00003362 } else {
aurel32a2ffb812008-10-21 16:31:31 +00003363 tcg_gen_movi_tl(cpu_nip, dest & ~3);
aurel328cbcb4f2008-05-10 23:28:14 +00003364 if (unlikely(ctx->singlestep_enabled)) {
3365 if ((ctx->singlestep_enabled &
aurel32bdc4e052008-11-09 17:27:03 +00003366 (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) &&
aurel328cbcb4f2008-05-10 23:28:14 +00003367 ctx->exception == POWERPC_EXCP_BRANCH) {
3368 target_ulong tmp = ctx->nip;
3369 ctx->nip = dest;
aurel32e06fcd72008-12-11 22:42:14 +00003370 gen_exception(ctx, POWERPC_EXCP_TRACE);
aurel328cbcb4f2008-05-10 23:28:14 +00003371 ctx->nip = tmp;
3372 }
3373 if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) {
aurel32e06fcd72008-12-11 22:42:14 +00003374 gen_debug_exception(ctx);
aurel328cbcb4f2008-05-10 23:28:14 +00003375 }
3376 }
bellard57fec1f2008-02-01 10:50:11 +00003377 tcg_gen_exit_tb(0);
bellardc1942362005-11-20 10:31:08 +00003378 }
bellardc53be332005-10-30 21:39:19 +00003379}
3380
Blue Swirl636aa202009-08-16 09:06:54 +00003381static inline void gen_setlr(DisasContext *ctx, target_ulong nip)
j_mayere1833e12007-09-29 13:06:16 +00003382{
3383#if defined(TARGET_PPC64)
aurel32a2ffb812008-10-21 16:31:31 +00003384 if (ctx->sf_mode == 0)
3385 tcg_gen_movi_tl(cpu_lr, (uint32_t)nip);
j_mayere1833e12007-09-29 13:06:16 +00003386 else
3387#endif
aurel32a2ffb812008-10-21 16:31:31 +00003388 tcg_gen_movi_tl(cpu_lr, nip);
j_mayere1833e12007-09-29 13:06:16 +00003389}
3390
bellard79aceca2003-11-23 14:55:54 +00003391/* b ba bl bla */
Blue Swirl99e300e2009-06-17 15:22:09 +00003392static void gen_b(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003393{
j_mayer76a66252007-03-07 08:32:30 +00003394 target_ulong li, target;
bellard38a64f92004-07-07 22:06:01 +00003395
aurel328cbcb4f2008-05-10 23:28:14 +00003396 ctx->exception = POWERPC_EXCP_BRANCH;
bellard38a64f92004-07-07 22:06:01 +00003397 /* sign extend LI */
j_mayer76a66252007-03-07 08:32:30 +00003398#if defined(TARGET_PPC64)
j_mayerd9bce9d2007-03-17 14:02:15 +00003399 if (ctx->sf_mode)
3400 li = ((int64_t)LI(ctx->opcode) << 38) >> 38;
3401 else
j_mayer76a66252007-03-07 08:32:30 +00003402#endif
j_mayerd9bce9d2007-03-17 14:02:15 +00003403 li = ((int32_t)LI(ctx->opcode) << 6) >> 6;
j_mayer76a66252007-03-07 08:32:30 +00003404 if (likely(AA(ctx->opcode) == 0))
bellard046d6672004-04-25 21:15:35 +00003405 target = ctx->nip + li - 4;
bellard79aceca2003-11-23 14:55:54 +00003406 else
bellard9a64fbe2004-01-04 22:58:38 +00003407 target = li;
j_mayere1833e12007-09-29 13:06:16 +00003408 if (LK(ctx->opcode))
3409 gen_setlr(ctx, ctx->nip);
bellardc1942362005-11-20 10:31:08 +00003410 gen_goto_tb(ctx, 0, target);
bellard79aceca2003-11-23 14:55:54 +00003411}
3412
bellarde98a6e42004-02-21 15:35:00 +00003413#define BCOND_IM 0
3414#define BCOND_LR 1
3415#define BCOND_CTR 2
bellard79aceca2003-11-23 14:55:54 +00003416
Blue Swirl636aa202009-08-16 09:06:54 +00003417static inline void gen_bcond(DisasContext *ctx, int type)
j_mayerd9bce9d2007-03-17 14:02:15 +00003418{
j_mayerd9bce9d2007-03-17 14:02:15 +00003419 uint32_t bo = BO(ctx->opcode);
Blue Swirl05f92402010-04-25 20:32:49 +00003420 int l1;
aurel32a2ffb812008-10-21 16:31:31 +00003421 TCGv target;
bellard79aceca2003-11-23 14:55:54 +00003422
aurel328cbcb4f2008-05-10 23:28:14 +00003423 ctx->exception = POWERPC_EXCP_BRANCH;
aurel32a2ffb812008-10-21 16:31:31 +00003424 if (type == BCOND_LR || type == BCOND_CTR) {
pbrooka7812ae2008-11-17 14:43:54 +00003425 target = tcg_temp_local_new();
aurel32a2ffb812008-10-21 16:31:31 +00003426 if (type == BCOND_CTR)
3427 tcg_gen_mov_tl(target, cpu_ctr);
3428 else
3429 tcg_gen_mov_tl(target, cpu_lr);
malcd2e9fd82009-06-20 05:51:47 +04003430 } else {
3431 TCGV_UNUSED(target);
bellarde98a6e42004-02-21 15:35:00 +00003432 }
j_mayere1833e12007-09-29 13:06:16 +00003433 if (LK(ctx->opcode))
3434 gen_setlr(ctx, ctx->nip);
aurel32a2ffb812008-10-21 16:31:31 +00003435 l1 = gen_new_label();
3436 if ((bo & 0x4) == 0) {
3437 /* Decrement and test CTR */
pbrooka7812ae2008-11-17 14:43:54 +00003438 TCGv temp = tcg_temp_new();
aurel32a2ffb812008-10-21 16:31:31 +00003439 if (unlikely(type == BCOND_CTR)) {
aurel32e06fcd72008-12-11 22:42:14 +00003440 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
aurel32a2ffb812008-10-21 16:31:31 +00003441 return;
bellarde98a6e42004-02-21 15:35:00 +00003442 }
aurel32a2ffb812008-10-21 16:31:31 +00003443 tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
j_mayerd9bce9d2007-03-17 14:02:15 +00003444#if defined(TARGET_PPC64)
aurel32a2ffb812008-10-21 16:31:31 +00003445 if (!ctx->sf_mode)
3446 tcg_gen_ext32u_tl(temp, cpu_ctr);
3447 else
j_mayerd9bce9d2007-03-17 14:02:15 +00003448#endif
aurel32a2ffb812008-10-21 16:31:31 +00003449 tcg_gen_mov_tl(temp, cpu_ctr);
3450 if (bo & 0x2) {
3451 tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
j_mayerd9bce9d2007-03-17 14:02:15 +00003452 } else {
aurel32a2ffb812008-10-21 16:31:31 +00003453 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
3454 }
pbrooka7812ae2008-11-17 14:43:54 +00003455 tcg_temp_free(temp);
aurel32a2ffb812008-10-21 16:31:31 +00003456 }
3457 if ((bo & 0x10) == 0) {
3458 /* Test CR */
3459 uint32_t bi = BI(ctx->opcode);
3460 uint32_t mask = 1 << (3 - (bi & 0x03));
pbrooka7812ae2008-11-17 14:43:54 +00003461 TCGv_i32 temp = tcg_temp_new_i32();
aurel32a2ffb812008-10-21 16:31:31 +00003462
3463 if (bo & 0x8) {
3464 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3465 tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1);
3466 } else {
3467 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3468 tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1);
j_mayerd9bce9d2007-03-17 14:02:15 +00003469 }
pbrooka7812ae2008-11-17 14:43:54 +00003470 tcg_temp_free_i32(temp);
j_mayerd9bce9d2007-03-17 14:02:15 +00003471 }
bellarde98a6e42004-02-21 15:35:00 +00003472 if (type == BCOND_IM) {
aurel32a2ffb812008-10-21 16:31:31 +00003473 target_ulong li = (target_long)((int16_t)(BD(ctx->opcode)));
3474 if (likely(AA(ctx->opcode) == 0)) {
3475 gen_goto_tb(ctx, 0, ctx->nip + li - 4);
3476 } else {
3477 gen_goto_tb(ctx, 0, li);
3478 }
bellardc53be332005-10-30 21:39:19 +00003479 gen_set_label(l1);
bellardc1942362005-11-20 10:31:08 +00003480 gen_goto_tb(ctx, 1, ctx->nip);
bellarde98a6e42004-02-21 15:35:00 +00003481 } else {
j_mayerd9bce9d2007-03-17 14:02:15 +00003482#if defined(TARGET_PPC64)
aurel32a2ffb812008-10-21 16:31:31 +00003483 if (!(ctx->sf_mode))
3484 tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3);
j_mayerd9bce9d2007-03-17 14:02:15 +00003485 else
3486#endif
aurel32a2ffb812008-10-21 16:31:31 +00003487 tcg_gen_andi_tl(cpu_nip, target, ~3);
3488 tcg_gen_exit_tb(0);
3489 gen_set_label(l1);
3490#if defined(TARGET_PPC64)
3491 if (!(ctx->sf_mode))
3492 tcg_gen_movi_tl(cpu_nip, (uint32_t)ctx->nip);
3493 else
3494#endif
3495 tcg_gen_movi_tl(cpu_nip, ctx->nip);
bellard57fec1f2008-02-01 10:50:11 +00003496 tcg_gen_exit_tb(0);
j_mayer08e46e52007-04-16 07:18:42 +00003497 }
bellarde98a6e42004-02-21 15:35:00 +00003498}
3499
Blue Swirl99e300e2009-06-17 15:22:09 +00003500static void gen_bc(DisasContext *ctx)
ths3b46e622007-09-17 08:09:54 +00003501{
bellarde98a6e42004-02-21 15:35:00 +00003502 gen_bcond(ctx, BCOND_IM);
3503}
3504
Blue Swirl99e300e2009-06-17 15:22:09 +00003505static void gen_bcctr(DisasContext *ctx)
ths3b46e622007-09-17 08:09:54 +00003506{
bellarde98a6e42004-02-21 15:35:00 +00003507 gen_bcond(ctx, BCOND_CTR);
3508}
3509
Blue Swirl99e300e2009-06-17 15:22:09 +00003510static void gen_bclr(DisasContext *ctx)
ths3b46e622007-09-17 08:09:54 +00003511{
bellarde98a6e42004-02-21 15:35:00 +00003512 gen_bcond(ctx, BCOND_LR);
3513}
bellard79aceca2003-11-23 14:55:54 +00003514
3515/*** Condition register logical ***/
aurel32e1571902008-10-21 11:31:14 +00003516#define GEN_CRLOGIC(name, tcg_op, opc) \
Blue Swirl99e300e2009-06-17 15:22:09 +00003517static void glue(gen_, name)(DisasContext *ctx) \
bellard79aceca2003-11-23 14:55:54 +00003518{ \
j_mayerfc0d4412007-10-31 22:02:17 +00003519 uint8_t bitmask; \
3520 int sh; \
pbrooka7812ae2008-11-17 14:43:54 +00003521 TCGv_i32 t0, t1; \
j_mayerfc0d4412007-10-31 22:02:17 +00003522 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
pbrooka7812ae2008-11-17 14:43:54 +00003523 t0 = tcg_temp_new_i32(); \
j_mayerfc0d4412007-10-31 22:02:17 +00003524 if (sh > 0) \
aurel32fea0c502008-11-02 08:22:34 +00003525 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
j_mayerfc0d4412007-10-31 22:02:17 +00003526 else if (sh < 0) \
aurel32fea0c502008-11-02 08:22:34 +00003527 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
aurel32e1571902008-10-21 11:31:14 +00003528 else \
aurel32fea0c502008-11-02 08:22:34 +00003529 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
pbrooka7812ae2008-11-17 14:43:54 +00003530 t1 = tcg_temp_new_i32(); \
j_mayerfc0d4412007-10-31 22:02:17 +00003531 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3532 if (sh > 0) \
aurel32fea0c502008-11-02 08:22:34 +00003533 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
j_mayerfc0d4412007-10-31 22:02:17 +00003534 else if (sh < 0) \
aurel32fea0c502008-11-02 08:22:34 +00003535 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
aurel32e1571902008-10-21 11:31:14 +00003536 else \
aurel32fea0c502008-11-02 08:22:34 +00003537 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3538 tcg_op(t0, t0, t1); \
j_mayerfc0d4412007-10-31 22:02:17 +00003539 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
aurel32fea0c502008-11-02 08:22:34 +00003540 tcg_gen_andi_i32(t0, t0, bitmask); \
3541 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3542 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
pbrooka7812ae2008-11-17 14:43:54 +00003543 tcg_temp_free_i32(t0); \
3544 tcg_temp_free_i32(t1); \
bellard79aceca2003-11-23 14:55:54 +00003545}
3546
3547/* crand */
aurel32e1571902008-10-21 11:31:14 +00003548GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08);
bellard79aceca2003-11-23 14:55:54 +00003549/* crandc */
aurel32e1571902008-10-21 11:31:14 +00003550GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04);
bellard79aceca2003-11-23 14:55:54 +00003551/* creqv */
aurel32e1571902008-10-21 11:31:14 +00003552GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09);
bellard79aceca2003-11-23 14:55:54 +00003553/* crnand */
aurel32e1571902008-10-21 11:31:14 +00003554GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07);
bellard79aceca2003-11-23 14:55:54 +00003555/* crnor */
aurel32e1571902008-10-21 11:31:14 +00003556GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01);
bellard79aceca2003-11-23 14:55:54 +00003557/* cror */
aurel32e1571902008-10-21 11:31:14 +00003558GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E);
bellard79aceca2003-11-23 14:55:54 +00003559/* crorc */
aurel32e1571902008-10-21 11:31:14 +00003560GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D);
bellard79aceca2003-11-23 14:55:54 +00003561/* crxor */
aurel32e1571902008-10-21 11:31:14 +00003562GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06);
Blue Swirl99e300e2009-06-17 15:22:09 +00003563
Blue Swirl54623272009-06-17 15:22:19 +00003564/* mcrf */
Blue Swirl99e300e2009-06-17 15:22:09 +00003565static void gen_mcrf(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003566{
aurel3247e46612008-09-04 17:06:47 +00003567 tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]);
bellard79aceca2003-11-23 14:55:54 +00003568}
3569
3570/*** System linkage ***/
Blue Swirl99e300e2009-06-17 15:22:09 +00003571
Blue Swirl54623272009-06-17 15:22:19 +00003572/* rfi (mem_idx only) */
Blue Swirl99e300e2009-06-17 15:22:09 +00003573static void gen_rfi(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003574{
bellard9a64fbe2004-01-04 22:58:38 +00003575#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00003576 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
bellard9a64fbe2004-01-04 22:58:38 +00003577#else
3578 /* Restore CPU state */
aurel3276db3ba2008-12-08 18:11:21 +00003579 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00003580 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
bellard9fddaa02004-05-21 12:59:32 +00003581 return;
bellard9a64fbe2004-01-04 22:58:38 +00003582 }
aurel32d72a19f2008-11-30 16:24:55 +00003583 gen_helper_rfi();
aurel32e06fcd72008-12-11 22:42:14 +00003584 gen_sync_exception(ctx);
bellard9a64fbe2004-01-04 22:58:38 +00003585#endif
bellard79aceca2003-11-23 14:55:54 +00003586}
3587
j_mayer426613d2007-03-23 09:45:27 +00003588#if defined(TARGET_PPC64)
Blue Swirl99e300e2009-06-17 15:22:09 +00003589static void gen_rfid(DisasContext *ctx)
j_mayer426613d2007-03-23 09:45:27 +00003590{
3591#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00003592 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer426613d2007-03-23 09:45:27 +00003593#else
3594 /* Restore CPU state */
aurel3276db3ba2008-12-08 18:11:21 +00003595 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00003596 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer426613d2007-03-23 09:45:27 +00003597 return;
3598 }
aurel32d72a19f2008-11-30 16:24:55 +00003599 gen_helper_rfid();
aurel32e06fcd72008-12-11 22:42:14 +00003600 gen_sync_exception(ctx);
j_mayer426613d2007-03-23 09:45:27 +00003601#endif
3602}
j_mayer426613d2007-03-23 09:45:27 +00003603
Blue Swirl99e300e2009-06-17 15:22:09 +00003604static void gen_hrfid(DisasContext *ctx)
j_mayerbe147d02007-09-30 13:03:23 +00003605{
3606#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00003607 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayerbe147d02007-09-30 13:03:23 +00003608#else
3609 /* Restore CPU state */
aurel3276db3ba2008-12-08 18:11:21 +00003610 if (unlikely(ctx->mem_idx <= 1)) {
aurel32e06fcd72008-12-11 22:42:14 +00003611 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayerbe147d02007-09-30 13:03:23 +00003612 return;
3613 }
aurel32d72a19f2008-11-30 16:24:55 +00003614 gen_helper_hrfid();
aurel32e06fcd72008-12-11 22:42:14 +00003615 gen_sync_exception(ctx);
j_mayerbe147d02007-09-30 13:03:23 +00003616#endif
3617}
3618#endif
3619
bellard79aceca2003-11-23 14:55:54 +00003620/* sc */
j_mayer417bf012007-10-07 23:10:08 +00003621#if defined(CONFIG_USER_ONLY)
3622#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3623#else
3624#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3625#endif
Blue Swirl99e300e2009-06-17 15:22:09 +00003626static void gen_sc(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003627{
j_mayere1833e12007-09-29 13:06:16 +00003628 uint32_t lev;
3629
3630 lev = (ctx->opcode >> 5) & 0x7F;
aurel32e06fcd72008-12-11 22:42:14 +00003631 gen_exception_err(ctx, POWERPC_SYSCALL, lev);
bellard79aceca2003-11-23 14:55:54 +00003632}
3633
3634/*** Trap ***/
Blue Swirl99e300e2009-06-17 15:22:09 +00003635
Blue Swirl54623272009-06-17 15:22:19 +00003636/* tw */
Blue Swirl99e300e2009-06-17 15:22:09 +00003637static void gen_tw(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003638{
aurel32cab3bee2008-11-24 11:28:19 +00003639 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
Aurelien Jarnodb9a2312010-02-28 16:02:28 +01003640 /* Update the nip since this might generate a trap exception */
3641 gen_update_nip(ctx, ctx->nip);
aurel32cab3bee2008-11-24 11:28:19 +00003642 gen_helper_tw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0);
3643 tcg_temp_free_i32(t0);
bellard79aceca2003-11-23 14:55:54 +00003644}
3645
3646/* twi */
Blue Swirl99e300e2009-06-17 15:22:09 +00003647static void gen_twi(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003648{
aurel32cab3bee2008-11-24 11:28:19 +00003649 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
3650 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
Aurelien Jarnodb9a2312010-02-28 16:02:28 +01003651 /* Update the nip since this might generate a trap exception */
3652 gen_update_nip(ctx, ctx->nip);
aurel32cab3bee2008-11-24 11:28:19 +00003653 gen_helper_tw(cpu_gpr[rA(ctx->opcode)], t0, t1);
3654 tcg_temp_free(t0);
3655 tcg_temp_free_i32(t1);
bellard79aceca2003-11-23 14:55:54 +00003656}
3657
j_mayerd9bce9d2007-03-17 14:02:15 +00003658#if defined(TARGET_PPC64)
3659/* td */
Blue Swirl99e300e2009-06-17 15:22:09 +00003660static void gen_td(DisasContext *ctx)
j_mayerd9bce9d2007-03-17 14:02:15 +00003661{
aurel32cab3bee2008-11-24 11:28:19 +00003662 TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
Aurelien Jarnodb9a2312010-02-28 16:02:28 +01003663 /* Update the nip since this might generate a trap exception */
3664 gen_update_nip(ctx, ctx->nip);
aurel32cab3bee2008-11-24 11:28:19 +00003665 gen_helper_td(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0);
3666 tcg_temp_free_i32(t0);
j_mayerd9bce9d2007-03-17 14:02:15 +00003667}
3668
3669/* tdi */
Blue Swirl99e300e2009-06-17 15:22:09 +00003670static void gen_tdi(DisasContext *ctx)
j_mayerd9bce9d2007-03-17 14:02:15 +00003671{
aurel32cab3bee2008-11-24 11:28:19 +00003672 TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
3673 TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
Aurelien Jarnodb9a2312010-02-28 16:02:28 +01003674 /* Update the nip since this might generate a trap exception */
3675 gen_update_nip(ctx, ctx->nip);
aurel32cab3bee2008-11-24 11:28:19 +00003676 gen_helper_td(cpu_gpr[rA(ctx->opcode)], t0, t1);
3677 tcg_temp_free(t0);
3678 tcg_temp_free_i32(t1);
j_mayerd9bce9d2007-03-17 14:02:15 +00003679}
3680#endif
3681
bellard79aceca2003-11-23 14:55:54 +00003682/*** Processor control ***/
Blue Swirl99e300e2009-06-17 15:22:09 +00003683
Blue Swirl54623272009-06-17 15:22:19 +00003684/* mcrxr */
Blue Swirl99e300e2009-06-17 15:22:09 +00003685static void gen_mcrxr(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003686{
aurel323d7b4172008-10-21 11:28:46 +00003687 tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], cpu_xer);
3688 tcg_gen_shri_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], XER_CA);
aurel32269f3e92008-11-01 00:53:48 +00003689 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_SO | 1 << XER_OV | 1 << XER_CA));
bellard79aceca2003-11-23 14:55:54 +00003690}
3691
aurel320cfe11e2009-03-03 06:12:14 +00003692/* mfcr mfocrf */
Blue Swirl99e300e2009-06-17 15:22:09 +00003693static void gen_mfcr(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003694{
j_mayer76a66252007-03-07 08:32:30 +00003695 uint32_t crm, crn;
ths3b46e622007-09-17 08:09:54 +00003696
j_mayer76a66252007-03-07 08:32:30 +00003697 if (likely(ctx->opcode & 0x00100000)) {
3698 crm = CRM(ctx->opcode);
malc8dd640e2009-03-02 22:39:39 +00003699 if (likely(crm && ((crm & (crm - 1)) == 0))) {
aurel320cfe11e2009-03-03 06:12:14 +00003700 crn = ctz32 (crm);
aurel32e1571902008-10-21 11:31:14 +00003701 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]);
aurel320497d2f2009-03-07 20:57:47 +00003702 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)],
3703 cpu_gpr[rD(ctx->opcode)], crn * 4);
j_mayer76a66252007-03-07 08:32:30 +00003704 }
j_mayerd9bce9d2007-03-17 14:02:15 +00003705 } else {
aurel32651721b2009-03-09 18:50:24 +00003706 TCGv_i32 t0 = tcg_temp_new_i32();
3707 tcg_gen_mov_i32(t0, cpu_crf[0]);
3708 tcg_gen_shli_i32(t0, t0, 4);
3709 tcg_gen_or_i32(t0, t0, cpu_crf[1]);
3710 tcg_gen_shli_i32(t0, t0, 4);
3711 tcg_gen_or_i32(t0, t0, cpu_crf[2]);
3712 tcg_gen_shli_i32(t0, t0, 4);
3713 tcg_gen_or_i32(t0, t0, cpu_crf[3]);
3714 tcg_gen_shli_i32(t0, t0, 4);
3715 tcg_gen_or_i32(t0, t0, cpu_crf[4]);
3716 tcg_gen_shli_i32(t0, t0, 4);
3717 tcg_gen_or_i32(t0, t0, cpu_crf[5]);
3718 tcg_gen_shli_i32(t0, t0, 4);
3719 tcg_gen_or_i32(t0, t0, cpu_crf[6]);
3720 tcg_gen_shli_i32(t0, t0, 4);
3721 tcg_gen_or_i32(t0, t0, cpu_crf[7]);
3722 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
3723 tcg_temp_free_i32(t0);
j_mayerd9bce9d2007-03-17 14:02:15 +00003724 }
bellard79aceca2003-11-23 14:55:54 +00003725}
3726
3727/* mfmsr */
Blue Swirl99e300e2009-06-17 15:22:09 +00003728static void gen_mfmsr(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003729{
bellard9a64fbe2004-01-04 22:58:38 +00003730#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00003731 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
bellard9a64fbe2004-01-04 22:58:38 +00003732#else
aurel3276db3ba2008-12-08 18:11:21 +00003733 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00003734 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
bellard9fddaa02004-05-21 12:59:32 +00003735 return;
bellard9a64fbe2004-01-04 22:58:38 +00003736 }
aurel326527f6e2008-12-06 13:03:35 +00003737 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr);
bellard9a64fbe2004-01-04 22:58:38 +00003738#endif
bellard79aceca2003-11-23 14:55:54 +00003739}
3740
Blue Swirl7b134482010-04-18 14:26:51 +00003741static void spr_noaccess(void *opaque, int gprn, int sprn)
bellard79aceca2003-11-23 14:55:54 +00003742{
Blue Swirl7b134482010-04-18 14:26:51 +00003743#if 0
bellard3fc6c082005-07-02 20:59:34 +00003744 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
3745 printf("ERROR: try to access SPR %d !\n", sprn);
Blue Swirl7b134482010-04-18 14:26:51 +00003746#endif
bellard3fc6c082005-07-02 20:59:34 +00003747}
3748#define SPR_NOACCESS (&spr_noaccess)
bellard3fc6c082005-07-02 20:59:34 +00003749
3750/* mfspr */
Blue Swirl636aa202009-08-16 09:06:54 +00003751static inline void gen_op_mfspr(DisasContext *ctx)
bellard3fc6c082005-07-02 20:59:34 +00003752{
aurel3245d827d2008-12-07 13:40:29 +00003753 void (*read_cb)(void *opaque, int gprn, int sprn);
bellard79aceca2003-11-23 14:55:54 +00003754 uint32_t sprn = SPR(ctx->opcode);
3755
bellard3fc6c082005-07-02 20:59:34 +00003756#if !defined(CONFIG_USER_ONLY)
aurel3276db3ba2008-12-08 18:11:21 +00003757 if (ctx->mem_idx == 2)
j_mayerbe147d02007-09-30 13:03:23 +00003758 read_cb = ctx->spr_cb[sprn].hea_read;
aurel3276db3ba2008-12-08 18:11:21 +00003759 else if (ctx->mem_idx)
bellard3fc6c082005-07-02 20:59:34 +00003760 read_cb = ctx->spr_cb[sprn].oea_read;
3761 else
bellard9a64fbe2004-01-04 22:58:38 +00003762#endif
bellard3fc6c082005-07-02 20:59:34 +00003763 read_cb = ctx->spr_cb[sprn].uea_read;
j_mayer76a66252007-03-07 08:32:30 +00003764 if (likely(read_cb != NULL)) {
3765 if (likely(read_cb != SPR_NOACCESS)) {
aurel3245d827d2008-12-07 13:40:29 +00003766 (*read_cb)(ctx, rD(ctx->opcode), sprn);
bellard3fc6c082005-07-02 20:59:34 +00003767 } else {
3768 /* Privilege exception */
j_mayer9fceefa2007-11-02 22:47:50 +00003769 /* This is a hack to avoid warnings when running Linux:
3770 * this OS breaks the PowerPC virtualisation model,
3771 * allowing userland application to read the PVR
3772 */
3773 if (sprn != SPR_PVR) {
aliguori93fcfe32009-01-15 22:34:14 +00003774 qemu_log("Trying to read privileged spr %d %03x at "
Blue Swirl90e189e2009-08-16 11:13:18 +00003775 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip);
3776 printf("Trying to read privileged spr %d %03x at "
3777 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip);
bellardf24e5692005-11-23 21:36:30 +00003778 }
aurel32e06fcd72008-12-11 22:42:14 +00003779 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
bellard79aceca2003-11-23 14:55:54 +00003780 }
bellard3fc6c082005-07-02 20:59:34 +00003781 } else {
3782 /* Not defined */
aliguori93fcfe32009-01-15 22:34:14 +00003783 qemu_log("Trying to read invalid spr %d %03x at "
Blue Swirl90e189e2009-08-16 11:13:18 +00003784 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip);
3785 printf("Trying to read invalid spr %d %03x at " TARGET_FMT_lx "\n",
j_mayer077fc202007-11-04 01:57:29 +00003786 sprn, sprn, ctx->nip);
aurel32e06fcd72008-12-11 22:42:14 +00003787 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
bellard79aceca2003-11-23 14:55:54 +00003788 }
bellard79aceca2003-11-23 14:55:54 +00003789}
3790
Blue Swirl99e300e2009-06-17 15:22:09 +00003791static void gen_mfspr(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003792{
bellard3fc6c082005-07-02 20:59:34 +00003793 gen_op_mfspr(ctx);
j_mayer76a66252007-03-07 08:32:30 +00003794}
bellard3fc6c082005-07-02 20:59:34 +00003795
3796/* mftb */
Blue Swirl99e300e2009-06-17 15:22:09 +00003797static void gen_mftb(DisasContext *ctx)
bellard3fc6c082005-07-02 20:59:34 +00003798{
3799 gen_op_mfspr(ctx);
bellard79aceca2003-11-23 14:55:54 +00003800}
3801
aurel320cfe11e2009-03-03 06:12:14 +00003802/* mtcrf mtocrf*/
Blue Swirl99e300e2009-06-17 15:22:09 +00003803static void gen_mtcrf(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003804{
j_mayer76a66252007-03-07 08:32:30 +00003805 uint32_t crm, crn;
ths3b46e622007-09-17 08:09:54 +00003806
j_mayer76a66252007-03-07 08:32:30 +00003807 crm = CRM(ctx->opcode);
malc8dd640e2009-03-02 22:39:39 +00003808 if (likely((ctx->opcode & 0x00100000))) {
3809 if (crm && ((crm & (crm - 1)) == 0)) {
3810 TCGv_i32 temp = tcg_temp_new_i32();
aurel320cfe11e2009-03-03 06:12:14 +00003811 crn = ctz32 (crm);
malc8dd640e2009-03-02 22:39:39 +00003812 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
aurel320cfe11e2009-03-03 06:12:14 +00003813 tcg_gen_shri_i32(temp, temp, crn * 4);
3814 tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf);
malc8dd640e2009-03-02 22:39:39 +00003815 tcg_temp_free_i32(temp);
3816 }
j_mayer76a66252007-03-07 08:32:30 +00003817 } else {
aurel32651721b2009-03-09 18:50:24 +00003818 TCGv_i32 temp = tcg_temp_new_i32();
3819 tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
3820 for (crn = 0 ; crn < 8 ; crn++) {
3821 if (crm & (1 << crn)) {
3822 tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4);
3823 tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf);
3824 }
3825 }
pbrooka7812ae2008-11-17 14:43:54 +00003826 tcg_temp_free_i32(temp);
j_mayer76a66252007-03-07 08:32:30 +00003827 }
bellard79aceca2003-11-23 14:55:54 +00003828}
3829
3830/* mtmsr */
j_mayer426613d2007-03-23 09:45:27 +00003831#if defined(TARGET_PPC64)
Blue Swirl99e300e2009-06-17 15:22:09 +00003832static void gen_mtmsrd(DisasContext *ctx)
j_mayer426613d2007-03-23 09:45:27 +00003833{
3834#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00003835 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
j_mayer426613d2007-03-23 09:45:27 +00003836#else
aurel3276db3ba2008-12-08 18:11:21 +00003837 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00003838 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
j_mayer426613d2007-03-23 09:45:27 +00003839 return;
3840 }
j_mayerbe147d02007-09-30 13:03:23 +00003841 if (ctx->opcode & 0x00010000) {
3842 /* Special form that does not need any synchronisation */
aurel326527f6e2008-12-06 13:03:35 +00003843 TCGv t0 = tcg_temp_new();
3844 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
3845 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
3846 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
3847 tcg_temp_free(t0);
j_mayerbe147d02007-09-30 13:03:23 +00003848 } else {
j_mayer056b05f2007-10-01 03:03:51 +00003849 /* XXX: we need to update nip before the store
3850 * if we enter power saving mode, we will exit the loop
3851 * directly from ppc_store_msr
3852 */
j_mayerbe147d02007-09-30 13:03:23 +00003853 gen_update_nip(ctx, ctx->nip);
aurel326527f6e2008-12-06 13:03:35 +00003854 gen_helper_store_msr(cpu_gpr[rS(ctx->opcode)]);
j_mayerbe147d02007-09-30 13:03:23 +00003855 /* Must stop the translation as machine state (may have) changed */
3856 /* Note that mtmsr is not always defined as context-synchronizing */
aurel32e06fcd72008-12-11 22:42:14 +00003857 gen_stop_exception(ctx);
j_mayerbe147d02007-09-30 13:03:23 +00003858 }
j_mayer426613d2007-03-23 09:45:27 +00003859#endif
3860}
3861#endif
3862
Blue Swirl99e300e2009-06-17 15:22:09 +00003863static void gen_mtmsr(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003864{
bellard9a64fbe2004-01-04 22:58:38 +00003865#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00003866 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
bellard9a64fbe2004-01-04 22:58:38 +00003867#else
aurel3276db3ba2008-12-08 18:11:21 +00003868 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00003869 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
bellard9fddaa02004-05-21 12:59:32 +00003870 return;
bellard9a64fbe2004-01-04 22:58:38 +00003871 }
j_mayerbe147d02007-09-30 13:03:23 +00003872 if (ctx->opcode & 0x00010000) {
3873 /* Special form that does not need any synchronisation */
aurel326527f6e2008-12-06 13:03:35 +00003874 TCGv t0 = tcg_temp_new();
3875 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
3876 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
3877 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
3878 tcg_temp_free(t0);
j_mayerbe147d02007-09-30 13:03:23 +00003879 } else {
Alexander Graf8018dc62011-06-16 10:44:23 +02003880 TCGv msr = tcg_temp_new();
3881
j_mayer056b05f2007-10-01 03:03:51 +00003882 /* XXX: we need to update nip before the store
3883 * if we enter power saving mode, we will exit the loop
3884 * directly from ppc_store_msr
3885 */
j_mayerbe147d02007-09-30 13:03:23 +00003886 gen_update_nip(ctx, ctx->nip);
j_mayerd9bce9d2007-03-17 14:02:15 +00003887#if defined(TARGET_PPC64)
Alexander Graf8018dc62011-06-16 10:44:23 +02003888 tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32);
3889#else
3890 tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]);
j_mayerd9bce9d2007-03-17 14:02:15 +00003891#endif
Alexander Graf8018dc62011-06-16 10:44:23 +02003892 gen_helper_store_msr(msr);
j_mayerbe147d02007-09-30 13:03:23 +00003893 /* Must stop the translation as machine state (may have) changed */
aurel326527f6e2008-12-06 13:03:35 +00003894 /* Note that mtmsr is not always defined as context-synchronizing */
aurel32e06fcd72008-12-11 22:42:14 +00003895 gen_stop_exception(ctx);
j_mayerbe147d02007-09-30 13:03:23 +00003896 }
bellard9a64fbe2004-01-04 22:58:38 +00003897#endif
bellard79aceca2003-11-23 14:55:54 +00003898}
3899
3900/* mtspr */
Blue Swirl99e300e2009-06-17 15:22:09 +00003901static void gen_mtspr(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003902{
aurel3245d827d2008-12-07 13:40:29 +00003903 void (*write_cb)(void *opaque, int sprn, int gprn);
bellard79aceca2003-11-23 14:55:54 +00003904 uint32_t sprn = SPR(ctx->opcode);
3905
bellard3fc6c082005-07-02 20:59:34 +00003906#if !defined(CONFIG_USER_ONLY)
aurel3276db3ba2008-12-08 18:11:21 +00003907 if (ctx->mem_idx == 2)
j_mayerbe147d02007-09-30 13:03:23 +00003908 write_cb = ctx->spr_cb[sprn].hea_write;
aurel3276db3ba2008-12-08 18:11:21 +00003909 else if (ctx->mem_idx)
bellard3fc6c082005-07-02 20:59:34 +00003910 write_cb = ctx->spr_cb[sprn].oea_write;
3911 else
bellard9a64fbe2004-01-04 22:58:38 +00003912#endif
bellard3fc6c082005-07-02 20:59:34 +00003913 write_cb = ctx->spr_cb[sprn].uea_write;
j_mayer76a66252007-03-07 08:32:30 +00003914 if (likely(write_cb != NULL)) {
3915 if (likely(write_cb != SPR_NOACCESS)) {
aurel3245d827d2008-12-07 13:40:29 +00003916 (*write_cb)(ctx, sprn, rS(ctx->opcode));
bellard3fc6c082005-07-02 20:59:34 +00003917 } else {
3918 /* Privilege exception */
aliguori93fcfe32009-01-15 22:34:14 +00003919 qemu_log("Trying to write privileged spr %d %03x at "
Blue Swirl90e189e2009-08-16 11:13:18 +00003920 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip);
3921 printf("Trying to write privileged spr %d %03x at " TARGET_FMT_lx
3922 "\n", sprn, sprn, ctx->nip);
aurel32e06fcd72008-12-11 22:42:14 +00003923 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
j_mayer76a66252007-03-07 08:32:30 +00003924 }
bellard3fc6c082005-07-02 20:59:34 +00003925 } else {
3926 /* Not defined */
aliguori93fcfe32009-01-15 22:34:14 +00003927 qemu_log("Trying to write invalid spr %d %03x at "
Blue Swirl90e189e2009-08-16 11:13:18 +00003928 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip);
3929 printf("Trying to write invalid spr %d %03x at " TARGET_FMT_lx "\n",
j_mayer077fc202007-11-04 01:57:29 +00003930 sprn, sprn, ctx->nip);
aurel32e06fcd72008-12-11 22:42:14 +00003931 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
bellard9a64fbe2004-01-04 22:58:38 +00003932 }
bellard79aceca2003-11-23 14:55:54 +00003933}
3934
3935/*** Cache management ***/
Blue Swirl99e300e2009-06-17 15:22:09 +00003936
Blue Swirl54623272009-06-17 15:22:19 +00003937/* dcbf */
Blue Swirl99e300e2009-06-17 15:22:09 +00003938static void gen_dcbf(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003939{
j_mayerdac454a2007-10-26 00:48:00 +00003940 /* XXX: specification says this is treated as a load by the MMU */
aurel3276db3ba2008-12-08 18:11:21 +00003941 TCGv t0;
3942 gen_set_access_type(ctx, ACCESS_CACHE);
3943 t0 = tcg_temp_new();
3944 gen_addr_reg_index(ctx, t0);
3945 gen_qemu_ld8u(ctx, t0, t0);
aurel32fea0c502008-11-02 08:22:34 +00003946 tcg_temp_free(t0);
bellard79aceca2003-11-23 14:55:54 +00003947}
3948
3949/* dcbi (Supervisor only) */
Blue Swirl99e300e2009-06-17 15:22:09 +00003950static void gen_dcbi(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003951{
bellarda541f292004-04-12 20:39:29 +00003952#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00003953 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
bellarda541f292004-04-12 20:39:29 +00003954#else
aurel32b61f2752008-10-15 17:00:37 +00003955 TCGv EA, val;
aurel3276db3ba2008-12-08 18:11:21 +00003956 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00003957 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
bellard9fddaa02004-05-21 12:59:32 +00003958 return;
bellard9a64fbe2004-01-04 22:58:38 +00003959 }
pbrooka7812ae2008-11-17 14:43:54 +00003960 EA = tcg_temp_new();
aurel3276db3ba2008-12-08 18:11:21 +00003961 gen_set_access_type(ctx, ACCESS_CACHE);
3962 gen_addr_reg_index(ctx, EA);
pbrooka7812ae2008-11-17 14:43:54 +00003963 val = tcg_temp_new();
j_mayer76a66252007-03-07 08:32:30 +00003964 /* XXX: specification says this should be treated as a store by the MMU */
aurel3276db3ba2008-12-08 18:11:21 +00003965 gen_qemu_ld8u(ctx, val, EA);
3966 gen_qemu_st8(ctx, val, EA);
aurel32b61f2752008-10-15 17:00:37 +00003967 tcg_temp_free(val);
3968 tcg_temp_free(EA);
bellarda541f292004-04-12 20:39:29 +00003969#endif
bellard79aceca2003-11-23 14:55:54 +00003970}
3971
3972/* dcdst */
Blue Swirl99e300e2009-06-17 15:22:09 +00003973static void gen_dcbst(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003974{
j_mayer76a66252007-03-07 08:32:30 +00003975 /* XXX: specification say this is treated as a load by the MMU */
aurel3276db3ba2008-12-08 18:11:21 +00003976 TCGv t0;
3977 gen_set_access_type(ctx, ACCESS_CACHE);
3978 t0 = tcg_temp_new();
3979 gen_addr_reg_index(ctx, t0);
3980 gen_qemu_ld8u(ctx, t0, t0);
aurel32fea0c502008-11-02 08:22:34 +00003981 tcg_temp_free(t0);
bellard79aceca2003-11-23 14:55:54 +00003982}
3983
3984/* dcbt */
Blue Swirl99e300e2009-06-17 15:22:09 +00003985static void gen_dcbt(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003986{
j_mayer0db1b202007-09-30 03:46:38 +00003987 /* interpreted as no-op */
j_mayer76a66252007-03-07 08:32:30 +00003988 /* XXX: specification say this is treated as a load by the MMU
3989 * but does not generate any exception
3990 */
bellard79aceca2003-11-23 14:55:54 +00003991}
3992
3993/* dcbtst */
Blue Swirl99e300e2009-06-17 15:22:09 +00003994static void gen_dcbtst(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00003995{
j_mayer0db1b202007-09-30 03:46:38 +00003996 /* interpreted as no-op */
j_mayer76a66252007-03-07 08:32:30 +00003997 /* XXX: specification say this is treated as a load by the MMU
3998 * but does not generate any exception
3999 */
bellard79aceca2003-11-23 14:55:54 +00004000}
4001
4002/* dcbz */
Blue Swirl99e300e2009-06-17 15:22:09 +00004003static void gen_dcbz(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00004004{
aurel3276db3ba2008-12-08 18:11:21 +00004005 TCGv t0;
4006 gen_set_access_type(ctx, ACCESS_CACHE);
aurel32799a8c82008-11-30 16:24:05 +00004007 /* NIP cannot be restored if the memory exception comes from an helper */
4008 gen_update_nip(ctx, ctx->nip - 4);
aurel3276db3ba2008-12-08 18:11:21 +00004009 t0 = tcg_temp_new();
4010 gen_addr_reg_index(ctx, t0);
aurel32799a8c82008-11-30 16:24:05 +00004011 gen_helper_dcbz(t0);
4012 tcg_temp_free(t0);
j_mayerd63001d2007-10-04 00:51:58 +00004013}
4014
Blue Swirle8eaa2c2009-06-17 15:22:14 +00004015static void gen_dcbz_970(DisasContext *ctx)
j_mayerd63001d2007-10-04 00:51:58 +00004016{
aurel3276db3ba2008-12-08 18:11:21 +00004017 TCGv t0;
4018 gen_set_access_type(ctx, ACCESS_CACHE);
aurel32799a8c82008-11-30 16:24:05 +00004019 /* NIP cannot be restored if the memory exception comes from an helper */
4020 gen_update_nip(ctx, ctx->nip - 4);
aurel3276db3ba2008-12-08 18:11:21 +00004021 t0 = tcg_temp_new();
4022 gen_addr_reg_index(ctx, t0);
j_mayerd63001d2007-10-04 00:51:58 +00004023 if (ctx->opcode & 0x00200000)
aurel32799a8c82008-11-30 16:24:05 +00004024 gen_helper_dcbz(t0);
j_mayerd63001d2007-10-04 00:51:58 +00004025 else
aurel32799a8c82008-11-30 16:24:05 +00004026 gen_helper_dcbz_970(t0);
4027 tcg_temp_free(t0);
bellard79aceca2003-11-23 14:55:54 +00004028}
4029
aurel32ae1c1a32009-01-12 21:33:02 +00004030/* dst / dstt */
Blue Swirl99e300e2009-06-17 15:22:09 +00004031static void gen_dst(DisasContext *ctx)
aurel32ae1c1a32009-01-12 21:33:02 +00004032{
4033 if (rA(ctx->opcode) == 0) {
4034 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4035 } else {
4036 /* interpreted as no-op */
4037 }
4038}
4039
4040/* dstst /dststt */
Blue Swirl99e300e2009-06-17 15:22:09 +00004041static void gen_dstst(DisasContext *ctx)
aurel32ae1c1a32009-01-12 21:33:02 +00004042{
4043 if (rA(ctx->opcode) == 0) {
4044 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4045 } else {
4046 /* interpreted as no-op */
4047 }
4048
4049}
4050
4051/* dss / dssall */
Blue Swirl99e300e2009-06-17 15:22:09 +00004052static void gen_dss(DisasContext *ctx)
aurel32ae1c1a32009-01-12 21:33:02 +00004053{
4054 /* interpreted as no-op */
4055}
4056
bellard79aceca2003-11-23 14:55:54 +00004057/* icbi */
Blue Swirl99e300e2009-06-17 15:22:09 +00004058static void gen_icbi(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00004059{
aurel3276db3ba2008-12-08 18:11:21 +00004060 TCGv t0;
4061 gen_set_access_type(ctx, ACCESS_CACHE);
j_mayer30032c92007-10-01 05:22:17 +00004062 /* NIP cannot be restored if the memory exception comes from an helper */
4063 gen_update_nip(ctx, ctx->nip - 4);
aurel3276db3ba2008-12-08 18:11:21 +00004064 t0 = tcg_temp_new();
4065 gen_addr_reg_index(ctx, t0);
aurel3237d269d2008-11-30 16:24:13 +00004066 gen_helper_icbi(t0);
4067 tcg_temp_free(t0);
bellard79aceca2003-11-23 14:55:54 +00004068}
4069
4070/* Optional: */
4071/* dcba */
Blue Swirl99e300e2009-06-17 15:22:09 +00004072static void gen_dcba(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00004073{
j_mayer0db1b202007-09-30 03:46:38 +00004074 /* interpreted as no-op */
4075 /* XXX: specification say this is treated as a store by the MMU
4076 * but does not generate any exception
4077 */
bellard79aceca2003-11-23 14:55:54 +00004078}
4079
4080/*** Segment register manipulation ***/
4081/* Supervisor only: */
Blue Swirl99e300e2009-06-17 15:22:09 +00004082
Blue Swirl54623272009-06-17 15:22:19 +00004083/* mfsr */
Blue Swirl99e300e2009-06-17 15:22:09 +00004084static void gen_mfsr(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00004085{
bellard9a64fbe2004-01-04 22:58:38 +00004086#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00004087 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
bellard9a64fbe2004-01-04 22:58:38 +00004088#else
aurel3274d37792008-12-06 21:46:17 +00004089 TCGv t0;
aurel3276db3ba2008-12-08 18:11:21 +00004090 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00004091 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
bellard9fddaa02004-05-21 12:59:32 +00004092 return;
bellard9a64fbe2004-01-04 22:58:38 +00004093 }
aurel3274d37792008-12-06 21:46:17 +00004094 t0 = tcg_const_tl(SR(ctx->opcode));
4095 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], t0);
4096 tcg_temp_free(t0);
bellard9a64fbe2004-01-04 22:58:38 +00004097#endif
bellard79aceca2003-11-23 14:55:54 +00004098}
4099
4100/* mfsrin */
Blue Swirl99e300e2009-06-17 15:22:09 +00004101static void gen_mfsrin(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00004102{
bellard9a64fbe2004-01-04 22:58:38 +00004103#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00004104 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
bellard9a64fbe2004-01-04 22:58:38 +00004105#else
aurel3274d37792008-12-06 21:46:17 +00004106 TCGv t0;
aurel3276db3ba2008-12-08 18:11:21 +00004107 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00004108 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
bellard9fddaa02004-05-21 12:59:32 +00004109 return;
bellard9a64fbe2004-01-04 22:58:38 +00004110 }
aurel3274d37792008-12-06 21:46:17 +00004111 t0 = tcg_temp_new();
4112 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4113 tcg_gen_andi_tl(t0, t0, 0xF);
4114 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], t0);
4115 tcg_temp_free(t0);
bellard9a64fbe2004-01-04 22:58:38 +00004116#endif
bellard79aceca2003-11-23 14:55:54 +00004117}
4118
4119/* mtsr */
Blue Swirl99e300e2009-06-17 15:22:09 +00004120static void gen_mtsr(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00004121{
bellard9a64fbe2004-01-04 22:58:38 +00004122#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00004123 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
bellard9a64fbe2004-01-04 22:58:38 +00004124#else
aurel3274d37792008-12-06 21:46:17 +00004125 TCGv t0;
aurel3276db3ba2008-12-08 18:11:21 +00004126 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00004127 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
bellard9fddaa02004-05-21 12:59:32 +00004128 return;
bellard9a64fbe2004-01-04 22:58:38 +00004129 }
aurel3274d37792008-12-06 21:46:17 +00004130 t0 = tcg_const_tl(SR(ctx->opcode));
4131 gen_helper_store_sr(t0, cpu_gpr[rS(ctx->opcode)]);
4132 tcg_temp_free(t0);
bellard9a64fbe2004-01-04 22:58:38 +00004133#endif
bellard79aceca2003-11-23 14:55:54 +00004134}
4135
4136/* mtsrin */
Blue Swirl99e300e2009-06-17 15:22:09 +00004137static void gen_mtsrin(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00004138{
bellard9a64fbe2004-01-04 22:58:38 +00004139#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00004140 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
bellard9a64fbe2004-01-04 22:58:38 +00004141#else
aurel3274d37792008-12-06 21:46:17 +00004142 TCGv t0;
aurel3276db3ba2008-12-08 18:11:21 +00004143 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00004144 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
bellard9fddaa02004-05-21 12:59:32 +00004145 return;
bellard9a64fbe2004-01-04 22:58:38 +00004146 }
aurel3274d37792008-12-06 21:46:17 +00004147 t0 = tcg_temp_new();
4148 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4149 tcg_gen_andi_tl(t0, t0, 0xF);
4150 gen_helper_store_sr(t0, cpu_gpr[rD(ctx->opcode)]);
4151 tcg_temp_free(t0);
bellard9a64fbe2004-01-04 22:58:38 +00004152#endif
bellard79aceca2003-11-23 14:55:54 +00004153}
4154
j_mayer12de9a32007-10-05 22:06:02 +00004155#if defined(TARGET_PPC64)
4156/* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00004157
Blue Swirl54623272009-06-17 15:22:19 +00004158/* mfsr */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00004159static void gen_mfsr_64b(DisasContext *ctx)
j_mayer12de9a32007-10-05 22:06:02 +00004160{
4161#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00004162 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
j_mayer12de9a32007-10-05 22:06:02 +00004163#else
aurel3274d37792008-12-06 21:46:17 +00004164 TCGv t0;
aurel3276db3ba2008-12-08 18:11:21 +00004165 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00004166 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
j_mayer12de9a32007-10-05 22:06:02 +00004167 return;
4168 }
aurel3274d37792008-12-06 21:46:17 +00004169 t0 = tcg_const_tl(SR(ctx->opcode));
blueswir1f6b868fc2009-03-07 20:50:01 +00004170 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], t0);
aurel3274d37792008-12-06 21:46:17 +00004171 tcg_temp_free(t0);
j_mayer12de9a32007-10-05 22:06:02 +00004172#endif
4173}
4174
4175/* mfsrin */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00004176static void gen_mfsrin_64b(DisasContext *ctx)
j_mayer12de9a32007-10-05 22:06:02 +00004177{
4178#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00004179 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
j_mayer12de9a32007-10-05 22:06:02 +00004180#else
aurel3274d37792008-12-06 21:46:17 +00004181 TCGv t0;
aurel3276db3ba2008-12-08 18:11:21 +00004182 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00004183 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
j_mayer12de9a32007-10-05 22:06:02 +00004184 return;
4185 }
aurel3274d37792008-12-06 21:46:17 +00004186 t0 = tcg_temp_new();
4187 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4188 tcg_gen_andi_tl(t0, t0, 0xF);
blueswir1f6b868fc2009-03-07 20:50:01 +00004189 gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], t0);
aurel3274d37792008-12-06 21:46:17 +00004190 tcg_temp_free(t0);
j_mayer12de9a32007-10-05 22:06:02 +00004191#endif
4192}
4193
4194/* mtsr */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00004195static void gen_mtsr_64b(DisasContext *ctx)
j_mayer12de9a32007-10-05 22:06:02 +00004196{
4197#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00004198 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
j_mayer12de9a32007-10-05 22:06:02 +00004199#else
aurel3274d37792008-12-06 21:46:17 +00004200 TCGv t0;
aurel3276db3ba2008-12-08 18:11:21 +00004201 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00004202 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
j_mayer12de9a32007-10-05 22:06:02 +00004203 return;
4204 }
aurel3274d37792008-12-06 21:46:17 +00004205 t0 = tcg_const_tl(SR(ctx->opcode));
blueswir1f6b868fc2009-03-07 20:50:01 +00004206 gen_helper_store_sr(t0, cpu_gpr[rS(ctx->opcode)]);
aurel3274d37792008-12-06 21:46:17 +00004207 tcg_temp_free(t0);
j_mayer12de9a32007-10-05 22:06:02 +00004208#endif
4209}
4210
4211/* mtsrin */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00004212static void gen_mtsrin_64b(DisasContext *ctx)
j_mayer12de9a32007-10-05 22:06:02 +00004213{
4214#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00004215 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
j_mayer12de9a32007-10-05 22:06:02 +00004216#else
aurel3274d37792008-12-06 21:46:17 +00004217 TCGv t0;
aurel3276db3ba2008-12-08 18:11:21 +00004218 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00004219 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
j_mayer12de9a32007-10-05 22:06:02 +00004220 return;
4221 }
aurel3274d37792008-12-06 21:46:17 +00004222 t0 = tcg_temp_new();
4223 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4224 tcg_gen_andi_tl(t0, t0, 0xF);
blueswir1f6b868fc2009-03-07 20:50:01 +00004225 gen_helper_store_sr(t0, cpu_gpr[rS(ctx->opcode)]);
aurel3274d37792008-12-06 21:46:17 +00004226 tcg_temp_free(t0);
j_mayer12de9a32007-10-05 22:06:02 +00004227#endif
4228}
blueswir1f6b868fc2009-03-07 20:50:01 +00004229
4230/* slbmte */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00004231static void gen_slbmte(DisasContext *ctx)
blueswir1f6b868fc2009-03-07 20:50:01 +00004232{
4233#if defined(CONFIG_USER_ONLY)
4234 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4235#else
4236 if (unlikely(!ctx->mem_idx)) {
4237 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4238 return;
4239 }
4240 gen_helper_store_slb(cpu_gpr[rB(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
4241#endif
4242}
4243
David Gibsonefdef952011-04-01 15:15:11 +11004244static void gen_slbmfee(DisasContext *ctx)
4245{
4246#if defined(CONFIG_USER_ONLY)
4247 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4248#else
4249 if (unlikely(!ctx->mem_idx)) {
4250 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4251 return;
4252 }
4253 gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)],
4254 cpu_gpr[rB(ctx->opcode)]);
4255#endif
4256}
4257
4258static void gen_slbmfev(DisasContext *ctx)
4259{
4260#if defined(CONFIG_USER_ONLY)
4261 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4262#else
4263 if (unlikely(!ctx->mem_idx)) {
4264 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4265 return;
4266 }
4267 gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)],
4268 cpu_gpr[rB(ctx->opcode)]);
4269#endif
4270}
j_mayer12de9a32007-10-05 22:06:02 +00004271#endif /* defined(TARGET_PPC64) */
4272
bellard79aceca2003-11-23 14:55:54 +00004273/*** Lookaside buffer management ***/
aurel3276db3ba2008-12-08 18:11:21 +00004274/* Optional & mem_idx only: */
Blue Swirl99e300e2009-06-17 15:22:09 +00004275
Blue Swirl54623272009-06-17 15:22:19 +00004276/* tlbia */
Blue Swirl99e300e2009-06-17 15:22:09 +00004277static void gen_tlbia(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00004278{
bellard9a64fbe2004-01-04 22:58:38 +00004279#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00004280 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
bellard9a64fbe2004-01-04 22:58:38 +00004281#else
aurel3276db3ba2008-12-08 18:11:21 +00004282 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00004283 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
bellard9fddaa02004-05-21 12:59:32 +00004284 return;
bellard9a64fbe2004-01-04 22:58:38 +00004285 }
aurel3274d37792008-12-06 21:46:17 +00004286 gen_helper_tlbia();
bellard9a64fbe2004-01-04 22:58:38 +00004287#endif
bellard79aceca2003-11-23 14:55:54 +00004288}
4289
blueswir1bf14b1c2009-03-07 20:52:22 +00004290/* tlbiel */
Blue Swirl99e300e2009-06-17 15:22:09 +00004291static void gen_tlbiel(DisasContext *ctx)
blueswir1bf14b1c2009-03-07 20:52:22 +00004292{
4293#if defined(CONFIG_USER_ONLY)
4294 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4295#else
4296 if (unlikely(!ctx->mem_idx)) {
4297 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4298 return;
4299 }
4300 gen_helper_tlbie(cpu_gpr[rB(ctx->opcode)]);
4301#endif
4302}
4303
bellard79aceca2003-11-23 14:55:54 +00004304/* tlbie */
Blue Swirl99e300e2009-06-17 15:22:09 +00004305static void gen_tlbie(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00004306{
bellard9a64fbe2004-01-04 22:58:38 +00004307#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00004308 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
bellard9a64fbe2004-01-04 22:58:38 +00004309#else
aurel3276db3ba2008-12-08 18:11:21 +00004310 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00004311 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
bellard9fddaa02004-05-21 12:59:32 +00004312 return;
bellard9a64fbe2004-01-04 22:58:38 +00004313 }
j_mayerd9bce9d2007-03-17 14:02:15 +00004314#if defined(TARGET_PPC64)
aurel3274d37792008-12-06 21:46:17 +00004315 if (!ctx->sf_mode) {
4316 TCGv t0 = tcg_temp_new();
4317 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
4318 gen_helper_tlbie(t0);
4319 tcg_temp_free(t0);
4320 } else
j_mayerd9bce9d2007-03-17 14:02:15 +00004321#endif
aurel3274d37792008-12-06 21:46:17 +00004322 gen_helper_tlbie(cpu_gpr[rB(ctx->opcode)]);
bellard9a64fbe2004-01-04 22:58:38 +00004323#endif
bellard79aceca2003-11-23 14:55:54 +00004324}
4325
4326/* tlbsync */
Blue Swirl99e300e2009-06-17 15:22:09 +00004327static void gen_tlbsync(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00004328{
bellard9a64fbe2004-01-04 22:58:38 +00004329#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00004330 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
bellard9a64fbe2004-01-04 22:58:38 +00004331#else
aurel3276db3ba2008-12-08 18:11:21 +00004332 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00004333 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
bellard9fddaa02004-05-21 12:59:32 +00004334 return;
bellard9a64fbe2004-01-04 22:58:38 +00004335 }
4336 /* This has no effect: it should ensure that all previous
4337 * tlbie have completed
4338 */
aurel32e06fcd72008-12-11 22:42:14 +00004339 gen_stop_exception(ctx);
bellard9a64fbe2004-01-04 22:58:38 +00004340#endif
bellard79aceca2003-11-23 14:55:54 +00004341}
4342
j_mayer426613d2007-03-23 09:45:27 +00004343#if defined(TARGET_PPC64)
4344/* slbia */
Blue Swirl99e300e2009-06-17 15:22:09 +00004345static void gen_slbia(DisasContext *ctx)
j_mayer426613d2007-03-23 09:45:27 +00004346{
4347#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00004348 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer426613d2007-03-23 09:45:27 +00004349#else
aurel3276db3ba2008-12-08 18:11:21 +00004350 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00004351 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer426613d2007-03-23 09:45:27 +00004352 return;
4353 }
aurel3274d37792008-12-06 21:46:17 +00004354 gen_helper_slbia();
j_mayer426613d2007-03-23 09:45:27 +00004355#endif
4356}
4357
4358/* slbie */
Blue Swirl99e300e2009-06-17 15:22:09 +00004359static void gen_slbie(DisasContext *ctx)
j_mayer426613d2007-03-23 09:45:27 +00004360{
4361#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00004362 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer426613d2007-03-23 09:45:27 +00004363#else
aurel3276db3ba2008-12-08 18:11:21 +00004364 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00004365 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer426613d2007-03-23 09:45:27 +00004366 return;
4367 }
aurel3274d37792008-12-06 21:46:17 +00004368 gen_helper_slbie(cpu_gpr[rB(ctx->opcode)]);
j_mayer426613d2007-03-23 09:45:27 +00004369#endif
4370}
4371#endif
4372
bellard79aceca2003-11-23 14:55:54 +00004373/*** External control ***/
4374/* Optional: */
Blue Swirl99e300e2009-06-17 15:22:09 +00004375
Blue Swirl54623272009-06-17 15:22:19 +00004376/* eciwx */
Blue Swirl99e300e2009-06-17 15:22:09 +00004377static void gen_eciwx(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00004378{
aurel3276db3ba2008-12-08 18:11:21 +00004379 TCGv t0;
aurel32fa407c02008-11-30 16:24:47 +00004380 /* Should check EAR[E] ! */
aurel3276db3ba2008-12-08 18:11:21 +00004381 gen_set_access_type(ctx, ACCESS_EXT);
4382 t0 = tcg_temp_new();
4383 gen_addr_reg_index(ctx, t0);
aurel32fa407c02008-11-30 16:24:47 +00004384 gen_check_align(ctx, t0, 0x03);
aurel3276db3ba2008-12-08 18:11:21 +00004385 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], t0);
aurel32fa407c02008-11-30 16:24:47 +00004386 tcg_temp_free(t0);
bellard79aceca2003-11-23 14:55:54 +00004387}
4388
4389/* ecowx */
Blue Swirl99e300e2009-06-17 15:22:09 +00004390static void gen_ecowx(DisasContext *ctx)
bellard79aceca2003-11-23 14:55:54 +00004391{
aurel3276db3ba2008-12-08 18:11:21 +00004392 TCGv t0;
aurel32fa407c02008-11-30 16:24:47 +00004393 /* Should check EAR[E] ! */
aurel3276db3ba2008-12-08 18:11:21 +00004394 gen_set_access_type(ctx, ACCESS_EXT);
4395 t0 = tcg_temp_new();
4396 gen_addr_reg_index(ctx, t0);
aurel32fa407c02008-11-30 16:24:47 +00004397 gen_check_align(ctx, t0, 0x03);
aurel3276db3ba2008-12-08 18:11:21 +00004398 gen_qemu_st32(ctx, cpu_gpr[rD(ctx->opcode)], t0);
aurel32fa407c02008-11-30 16:24:47 +00004399 tcg_temp_free(t0);
bellard79aceca2003-11-23 14:55:54 +00004400}
4401
j_mayer76a66252007-03-07 08:32:30 +00004402/* PowerPC 601 specific instructions */
Blue Swirl99e300e2009-06-17 15:22:09 +00004403
Blue Swirl54623272009-06-17 15:22:19 +00004404/* abs - abs. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004405static void gen_abs(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004406{
aurel3222e0e172008-12-06 12:19:14 +00004407 int l1 = gen_new_label();
4408 int l2 = gen_new_label();
4409 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1);
4410 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4411 tcg_gen_br(l2);
4412 gen_set_label(l1);
4413 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4414 gen_set_label(l2);
j_mayer76a66252007-03-07 08:32:30 +00004415 if (unlikely(Rc(ctx->opcode) != 0))
aurel3222e0e172008-12-06 12:19:14 +00004416 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004417}
4418
4419/* abso - abso. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004420static void gen_abso(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004421{
aurel3222e0e172008-12-06 12:19:14 +00004422 int l1 = gen_new_label();
4423 int l2 = gen_new_label();
4424 int l3 = gen_new_label();
4425 /* Start with XER OV disabled, the most likely case */
4426 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
4427 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2);
4428 tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1);
4429 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
4430 tcg_gen_br(l2);
4431 gen_set_label(l1);
4432 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4433 tcg_gen_br(l3);
4434 gen_set_label(l2);
4435 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4436 gen_set_label(l3);
j_mayer76a66252007-03-07 08:32:30 +00004437 if (unlikely(Rc(ctx->opcode) != 0))
aurel3222e0e172008-12-06 12:19:14 +00004438 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004439}
4440
4441/* clcs */
Blue Swirl99e300e2009-06-17 15:22:09 +00004442static void gen_clcs(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004443{
aurel3222e0e172008-12-06 12:19:14 +00004444 TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode));
4445 gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], t0);
4446 tcg_temp_free_i32(t0);
j_mayerc7697e12007-10-26 00:46:07 +00004447 /* Rc=1 sets CR0 to an undefined state */
j_mayer76a66252007-03-07 08:32:30 +00004448}
4449
4450/* div - div. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004451static void gen_div(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004452{
aurel3222e0e172008-12-06 12:19:14 +00004453 gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004454 if (unlikely(Rc(ctx->opcode) != 0))
aurel3222e0e172008-12-06 12:19:14 +00004455 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004456}
4457
4458/* divo - divo. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004459static void gen_divo(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004460{
aurel3222e0e172008-12-06 12:19:14 +00004461 gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004462 if (unlikely(Rc(ctx->opcode) != 0))
aurel3222e0e172008-12-06 12:19:14 +00004463 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004464}
4465
4466/* divs - divs. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004467static void gen_divs(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004468{
aurel3222e0e172008-12-06 12:19:14 +00004469 gen_helper_divs(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004470 if (unlikely(Rc(ctx->opcode) != 0))
aurel3222e0e172008-12-06 12:19:14 +00004471 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004472}
4473
4474/* divso - divso. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004475static void gen_divso(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004476{
aurel3222e0e172008-12-06 12:19:14 +00004477 gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004478 if (unlikely(Rc(ctx->opcode) != 0))
aurel3222e0e172008-12-06 12:19:14 +00004479 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004480}
4481
4482/* doz - doz. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004483static void gen_doz(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004484{
aurel3222e0e172008-12-06 12:19:14 +00004485 int l1 = gen_new_label();
4486 int l2 = gen_new_label();
4487 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4488 tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4489 tcg_gen_br(l2);
4490 gen_set_label(l1);
4491 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4492 gen_set_label(l2);
j_mayer76a66252007-03-07 08:32:30 +00004493 if (unlikely(Rc(ctx->opcode) != 0))
aurel3222e0e172008-12-06 12:19:14 +00004494 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004495}
4496
4497/* dozo - dozo. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004498static void gen_dozo(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004499{
aurel3222e0e172008-12-06 12:19:14 +00004500 int l1 = gen_new_label();
4501 int l2 = gen_new_label();
4502 TCGv t0 = tcg_temp_new();
4503 TCGv t1 = tcg_temp_new();
4504 TCGv t2 = tcg_temp_new();
4505 /* Start with XER OV disabled, the most likely case */
4506 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
4507 tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4508 tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4509 tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4510 tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0);
4511 tcg_gen_andc_tl(t1, t1, t2);
4512 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
4513 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
4514 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
4515 tcg_gen_br(l2);
4516 gen_set_label(l1);
4517 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4518 gen_set_label(l2);
4519 tcg_temp_free(t0);
4520 tcg_temp_free(t1);
4521 tcg_temp_free(t2);
j_mayer76a66252007-03-07 08:32:30 +00004522 if (unlikely(Rc(ctx->opcode) != 0))
aurel3222e0e172008-12-06 12:19:14 +00004523 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004524}
4525
4526/* dozi */
Blue Swirl99e300e2009-06-17 15:22:09 +00004527static void gen_dozi(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004528{
aurel3222e0e172008-12-06 12:19:14 +00004529 target_long simm = SIMM(ctx->opcode);
4530 int l1 = gen_new_label();
4531 int l2 = gen_new_label();
4532 tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1);
4533 tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]);
4534 tcg_gen_br(l2);
4535 gen_set_label(l1);
4536 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4537 gen_set_label(l2);
4538 if (unlikely(Rc(ctx->opcode) != 0))
4539 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004540}
4541
j_mayer76a66252007-03-07 08:32:30 +00004542/* lscbx - lscbx. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004543static void gen_lscbx(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004544{
aurel32bdb4b682008-11-30 16:24:30 +00004545 TCGv t0 = tcg_temp_new();
4546 TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode));
4547 TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode));
4548 TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode));
j_mayer76a66252007-03-07 08:32:30 +00004549
aurel3276db3ba2008-12-08 18:11:21 +00004550 gen_addr_reg_index(ctx, t0);
j_mayer76a66252007-03-07 08:32:30 +00004551 /* NIP cannot be restored if the memory exception comes from an helper */
j_mayerd9bce9d2007-03-17 14:02:15 +00004552 gen_update_nip(ctx, ctx->nip - 4);
aurel32bdb4b682008-11-30 16:24:30 +00004553 gen_helper_lscbx(t0, t0, t1, t2, t3);
4554 tcg_temp_free_i32(t1);
4555 tcg_temp_free_i32(t2);
4556 tcg_temp_free_i32(t3);
aurel323d7b4172008-10-21 11:28:46 +00004557 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
aurel32bdb4b682008-11-30 16:24:30 +00004558 tcg_gen_or_tl(cpu_xer, cpu_xer, t0);
j_mayer76a66252007-03-07 08:32:30 +00004559 if (unlikely(Rc(ctx->opcode) != 0))
aurel32bdb4b682008-11-30 16:24:30 +00004560 gen_set_Rc0(ctx, t0);
4561 tcg_temp_free(t0);
j_mayer76a66252007-03-07 08:32:30 +00004562}
4563
4564/* maskg - maskg. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004565static void gen_maskg(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004566{
aurel3222e0e172008-12-06 12:19:14 +00004567 int l1 = gen_new_label();
4568 TCGv t0 = tcg_temp_new();
4569 TCGv t1 = tcg_temp_new();
4570 TCGv t2 = tcg_temp_new();
4571 TCGv t3 = tcg_temp_new();
4572 tcg_gen_movi_tl(t3, 0xFFFFFFFF);
4573 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4574 tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F);
4575 tcg_gen_addi_tl(t2, t0, 1);
4576 tcg_gen_shr_tl(t2, t3, t2);
4577 tcg_gen_shr_tl(t3, t3, t1);
4578 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3);
4579 tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1);
4580 tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4581 gen_set_label(l1);
4582 tcg_temp_free(t0);
4583 tcg_temp_free(t1);
4584 tcg_temp_free(t2);
4585 tcg_temp_free(t3);
j_mayer76a66252007-03-07 08:32:30 +00004586 if (unlikely(Rc(ctx->opcode) != 0))
aurel3222e0e172008-12-06 12:19:14 +00004587 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004588}
4589
4590/* maskir - maskir. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004591static void gen_maskir(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004592{
aurel3222e0e172008-12-06 12:19:14 +00004593 TCGv t0 = tcg_temp_new();
4594 TCGv t1 = tcg_temp_new();
4595 tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
4596 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
4597 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4598 tcg_temp_free(t0);
4599 tcg_temp_free(t1);
j_mayer76a66252007-03-07 08:32:30 +00004600 if (unlikely(Rc(ctx->opcode) != 0))
aurel3222e0e172008-12-06 12:19:14 +00004601 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004602}
4603
4604/* mul - mul. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004605static void gen_mul(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004606{
aurel3222e0e172008-12-06 12:19:14 +00004607 TCGv_i64 t0 = tcg_temp_new_i64();
4608 TCGv_i64 t1 = tcg_temp_new_i64();
4609 TCGv t2 = tcg_temp_new();
4610 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
4611 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
4612 tcg_gen_mul_i64(t0, t0, t1);
4613 tcg_gen_trunc_i64_tl(t2, t0);
4614 gen_store_spr(SPR_MQ, t2);
4615 tcg_gen_shri_i64(t1, t0, 32);
4616 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
4617 tcg_temp_free_i64(t0);
4618 tcg_temp_free_i64(t1);
4619 tcg_temp_free(t2);
j_mayer76a66252007-03-07 08:32:30 +00004620 if (unlikely(Rc(ctx->opcode) != 0))
aurel3222e0e172008-12-06 12:19:14 +00004621 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004622}
4623
4624/* mulo - mulo. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004625static void gen_mulo(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004626{
aurel3222e0e172008-12-06 12:19:14 +00004627 int l1 = gen_new_label();
4628 TCGv_i64 t0 = tcg_temp_new_i64();
4629 TCGv_i64 t1 = tcg_temp_new_i64();
4630 TCGv t2 = tcg_temp_new();
4631 /* Start with XER OV disabled, the most likely case */
4632 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
4633 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
4634 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
4635 tcg_gen_mul_i64(t0, t0, t1);
4636 tcg_gen_trunc_i64_tl(t2, t0);
4637 gen_store_spr(SPR_MQ, t2);
4638 tcg_gen_shri_i64(t1, t0, 32);
4639 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
4640 tcg_gen_ext32s_i64(t1, t0);
4641 tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1);
4642 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
4643 gen_set_label(l1);
4644 tcg_temp_free_i64(t0);
4645 tcg_temp_free_i64(t1);
4646 tcg_temp_free(t2);
j_mayer76a66252007-03-07 08:32:30 +00004647 if (unlikely(Rc(ctx->opcode) != 0))
aurel3222e0e172008-12-06 12:19:14 +00004648 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004649}
4650
4651/* nabs - nabs. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004652static void gen_nabs(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004653{
aurel3222e0e172008-12-06 12:19:14 +00004654 int l1 = gen_new_label();
4655 int l2 = gen_new_label();
4656 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
4657 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4658 tcg_gen_br(l2);
4659 gen_set_label(l1);
4660 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4661 gen_set_label(l2);
j_mayer76a66252007-03-07 08:32:30 +00004662 if (unlikely(Rc(ctx->opcode) != 0))
aurel3222e0e172008-12-06 12:19:14 +00004663 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004664}
4665
4666/* nabso - nabso. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004667static void gen_nabso(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004668{
aurel3222e0e172008-12-06 12:19:14 +00004669 int l1 = gen_new_label();
4670 int l2 = gen_new_label();
4671 tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
4672 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4673 tcg_gen_br(l2);
4674 gen_set_label(l1);
4675 tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4676 gen_set_label(l2);
4677 /* nabs never overflows */
4678 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
j_mayer76a66252007-03-07 08:32:30 +00004679 if (unlikely(Rc(ctx->opcode) != 0))
aurel3222e0e172008-12-06 12:19:14 +00004680 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004681}
4682
4683/* rlmi - rlmi. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004684static void gen_rlmi(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004685{
aurel3274879532008-12-05 07:21:44 +00004686 uint32_t mb = MB(ctx->opcode);
4687 uint32_t me = ME(ctx->opcode);
4688 TCGv t0 = tcg_temp_new();
4689 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4690 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
4691 tcg_gen_andi_tl(t0, t0, MASK(mb, me));
4692 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me));
4693 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0);
4694 tcg_temp_free(t0);
j_mayer76a66252007-03-07 08:32:30 +00004695 if (unlikely(Rc(ctx->opcode) != 0))
aurel3274879532008-12-05 07:21:44 +00004696 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004697}
4698
4699/* rrib - rrib. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004700static void gen_rrib(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004701{
aurel3274879532008-12-05 07:21:44 +00004702 TCGv t0 = tcg_temp_new();
4703 TCGv t1 = tcg_temp_new();
4704 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4705 tcg_gen_movi_tl(t1, 0x80000000);
4706 tcg_gen_shr_tl(t1, t1, t0);
4707 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
4708 tcg_gen_and_tl(t0, t0, t1);
4709 tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1);
4710 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4711 tcg_temp_free(t0);
4712 tcg_temp_free(t1);
j_mayer76a66252007-03-07 08:32:30 +00004713 if (unlikely(Rc(ctx->opcode) != 0))
aurel3274879532008-12-05 07:21:44 +00004714 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004715}
4716
4717/* sle - sle. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004718static void gen_sle(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004719{
aurel3274879532008-12-05 07:21:44 +00004720 TCGv t0 = tcg_temp_new();
4721 TCGv t1 = tcg_temp_new();
4722 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
4723 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
4724 tcg_gen_subfi_tl(t1, 32, t1);
4725 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
4726 tcg_gen_or_tl(t1, t0, t1);
4727 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
4728 gen_store_spr(SPR_MQ, t1);
4729 tcg_temp_free(t0);
4730 tcg_temp_free(t1);
j_mayer76a66252007-03-07 08:32:30 +00004731 if (unlikely(Rc(ctx->opcode) != 0))
aurel3274879532008-12-05 07:21:44 +00004732 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004733}
4734
4735/* sleq - sleq. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004736static void gen_sleq(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004737{
aurel3274879532008-12-05 07:21:44 +00004738 TCGv t0 = tcg_temp_new();
4739 TCGv t1 = tcg_temp_new();
4740 TCGv t2 = tcg_temp_new();
4741 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4742 tcg_gen_movi_tl(t2, 0xFFFFFFFF);
4743 tcg_gen_shl_tl(t2, t2, t0);
4744 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
4745 gen_load_spr(t1, SPR_MQ);
4746 gen_store_spr(SPR_MQ, t0);
4747 tcg_gen_and_tl(t0, t0, t2);
4748 tcg_gen_andc_tl(t1, t1, t2);
4749 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4750 tcg_temp_free(t0);
4751 tcg_temp_free(t1);
4752 tcg_temp_free(t2);
j_mayer76a66252007-03-07 08:32:30 +00004753 if (unlikely(Rc(ctx->opcode) != 0))
aurel3274879532008-12-05 07:21:44 +00004754 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004755}
4756
4757/* sliq - sliq. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004758static void gen_sliq(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004759{
aurel3274879532008-12-05 07:21:44 +00004760 int sh = SH(ctx->opcode);
4761 TCGv t0 = tcg_temp_new();
4762 TCGv t1 = tcg_temp_new();
4763 tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
4764 tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
4765 tcg_gen_or_tl(t1, t0, t1);
4766 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
4767 gen_store_spr(SPR_MQ, t1);
4768 tcg_temp_free(t0);
4769 tcg_temp_free(t1);
j_mayer76a66252007-03-07 08:32:30 +00004770 if (unlikely(Rc(ctx->opcode) != 0))
aurel3274879532008-12-05 07:21:44 +00004771 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004772}
4773
4774/* slliq - slliq. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004775static void gen_slliq(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004776{
aurel3274879532008-12-05 07:21:44 +00004777 int sh = SH(ctx->opcode);
4778 TCGv t0 = tcg_temp_new();
4779 TCGv t1 = tcg_temp_new();
4780 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
4781 gen_load_spr(t1, SPR_MQ);
4782 gen_store_spr(SPR_MQ, t0);
4783 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU << sh));
4784 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh));
4785 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4786 tcg_temp_free(t0);
4787 tcg_temp_free(t1);
j_mayer76a66252007-03-07 08:32:30 +00004788 if (unlikely(Rc(ctx->opcode) != 0))
aurel3274879532008-12-05 07:21:44 +00004789 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004790}
4791
4792/* sllq - sllq. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004793static void gen_sllq(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004794{
aurel3274879532008-12-05 07:21:44 +00004795 int l1 = gen_new_label();
4796 int l2 = gen_new_label();
4797 TCGv t0 = tcg_temp_local_new();
4798 TCGv t1 = tcg_temp_local_new();
4799 TCGv t2 = tcg_temp_local_new();
4800 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
4801 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
4802 tcg_gen_shl_tl(t1, t1, t2);
4803 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
4804 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
4805 gen_load_spr(t0, SPR_MQ);
4806 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4807 tcg_gen_br(l2);
4808 gen_set_label(l1);
4809 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
4810 gen_load_spr(t2, SPR_MQ);
4811 tcg_gen_andc_tl(t1, t2, t1);
4812 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4813 gen_set_label(l2);
4814 tcg_temp_free(t0);
4815 tcg_temp_free(t1);
4816 tcg_temp_free(t2);
j_mayer76a66252007-03-07 08:32:30 +00004817 if (unlikely(Rc(ctx->opcode) != 0))
aurel3274879532008-12-05 07:21:44 +00004818 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004819}
4820
4821/* slq - slq. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004822static void gen_slq(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004823{
aurel3274879532008-12-05 07:21:44 +00004824 int l1 = gen_new_label();
4825 TCGv t0 = tcg_temp_new();
4826 TCGv t1 = tcg_temp_new();
4827 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
4828 tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
4829 tcg_gen_subfi_tl(t1, 32, t1);
4830 tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
4831 tcg_gen_or_tl(t1, t0, t1);
4832 gen_store_spr(SPR_MQ, t1);
4833 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
4834 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
4835 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
4836 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
4837 gen_set_label(l1);
4838 tcg_temp_free(t0);
4839 tcg_temp_free(t1);
j_mayer76a66252007-03-07 08:32:30 +00004840 if (unlikely(Rc(ctx->opcode) != 0))
aurel3274879532008-12-05 07:21:44 +00004841 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004842}
4843
j_mayerd9bce9d2007-03-17 14:02:15 +00004844/* sraiq - sraiq. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004845static void gen_sraiq(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004846{
aurel3274879532008-12-05 07:21:44 +00004847 int sh = SH(ctx->opcode);
4848 int l1 = gen_new_label();
4849 TCGv t0 = tcg_temp_new();
4850 TCGv t1 = tcg_temp_new();
4851 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
4852 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
4853 tcg_gen_or_tl(t0, t0, t1);
4854 gen_store_spr(SPR_MQ, t0);
4855 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
4856 tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
4857 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
4858 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_CA));
4859 gen_set_label(l1);
4860 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
4861 tcg_temp_free(t0);
4862 tcg_temp_free(t1);
j_mayer76a66252007-03-07 08:32:30 +00004863 if (unlikely(Rc(ctx->opcode) != 0))
aurel3274879532008-12-05 07:21:44 +00004864 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004865}
4866
4867/* sraq - sraq. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004868static void gen_sraq(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004869{
aurel3274879532008-12-05 07:21:44 +00004870 int l1 = gen_new_label();
4871 int l2 = gen_new_label();
4872 TCGv t0 = tcg_temp_new();
4873 TCGv t1 = tcg_temp_local_new();
4874 TCGv t2 = tcg_temp_local_new();
4875 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
4876 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
4877 tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2);
4878 tcg_gen_subfi_tl(t2, 32, t2);
4879 tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2);
4880 tcg_gen_or_tl(t0, t0, t2);
4881 gen_store_spr(SPR_MQ, t0);
4882 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
4883 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1);
4884 tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]);
4885 tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31);
4886 gen_set_label(l1);
4887 tcg_temp_free(t0);
4888 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1);
4889 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
4890 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
4891 tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2);
4892 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_CA));
4893 gen_set_label(l2);
4894 tcg_temp_free(t1);
4895 tcg_temp_free(t2);
j_mayer76a66252007-03-07 08:32:30 +00004896 if (unlikely(Rc(ctx->opcode) != 0))
aurel3274879532008-12-05 07:21:44 +00004897 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004898}
4899
4900/* sre - sre. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004901static void gen_sre(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004902{
aurel3274879532008-12-05 07:21:44 +00004903 TCGv t0 = tcg_temp_new();
4904 TCGv t1 = tcg_temp_new();
4905 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
4906 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
4907 tcg_gen_subfi_tl(t1, 32, t1);
4908 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
4909 tcg_gen_or_tl(t1, t0, t1);
4910 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
4911 gen_store_spr(SPR_MQ, t1);
4912 tcg_temp_free(t0);
4913 tcg_temp_free(t1);
j_mayer76a66252007-03-07 08:32:30 +00004914 if (unlikely(Rc(ctx->opcode) != 0))
aurel3274879532008-12-05 07:21:44 +00004915 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004916}
4917
4918/* srea - srea. */
Blue Swirl99e300e2009-06-17 15:22:09 +00004919static void gen_srea(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004920{
aurel3274879532008-12-05 07:21:44 +00004921 TCGv t0 = tcg_temp_new();
4922 TCGv t1 = tcg_temp_new();
4923 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
4924 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
4925 gen_store_spr(SPR_MQ, t0);
4926 tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1);
4927 tcg_temp_free(t0);
4928 tcg_temp_free(t1);
j_mayer76a66252007-03-07 08:32:30 +00004929 if (unlikely(Rc(ctx->opcode) != 0))
aurel3274879532008-12-05 07:21:44 +00004930 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004931}
4932
4933/* sreq */
Blue Swirl99e300e2009-06-17 15:22:09 +00004934static void gen_sreq(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004935{
aurel3274879532008-12-05 07:21:44 +00004936 TCGv t0 = tcg_temp_new();
4937 TCGv t1 = tcg_temp_new();
4938 TCGv t2 = tcg_temp_new();
4939 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4940 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
4941 tcg_gen_shr_tl(t1, t1, t0);
4942 tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
4943 gen_load_spr(t2, SPR_MQ);
4944 gen_store_spr(SPR_MQ, t0);
4945 tcg_gen_and_tl(t0, t0, t1);
4946 tcg_gen_andc_tl(t2, t2, t1);
4947 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
4948 tcg_temp_free(t0);
4949 tcg_temp_free(t1);
4950 tcg_temp_free(t2);
j_mayer76a66252007-03-07 08:32:30 +00004951 if (unlikely(Rc(ctx->opcode) != 0))
aurel3274879532008-12-05 07:21:44 +00004952 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004953}
4954
4955/* sriq */
Blue Swirl99e300e2009-06-17 15:22:09 +00004956static void gen_sriq(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004957{
aurel3274879532008-12-05 07:21:44 +00004958 int sh = SH(ctx->opcode);
4959 TCGv t0 = tcg_temp_new();
4960 TCGv t1 = tcg_temp_new();
4961 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
4962 tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
4963 tcg_gen_or_tl(t1, t0, t1);
4964 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
4965 gen_store_spr(SPR_MQ, t1);
4966 tcg_temp_free(t0);
4967 tcg_temp_free(t1);
j_mayer76a66252007-03-07 08:32:30 +00004968 if (unlikely(Rc(ctx->opcode) != 0))
aurel3274879532008-12-05 07:21:44 +00004969 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004970}
4971
4972/* srliq */
Blue Swirl99e300e2009-06-17 15:22:09 +00004973static void gen_srliq(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004974{
aurel3274879532008-12-05 07:21:44 +00004975 int sh = SH(ctx->opcode);
4976 TCGv t0 = tcg_temp_new();
4977 TCGv t1 = tcg_temp_new();
4978 tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
4979 gen_load_spr(t1, SPR_MQ);
4980 gen_store_spr(SPR_MQ, t0);
4981 tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU >> sh));
4982 tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh));
4983 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4984 tcg_temp_free(t0);
4985 tcg_temp_free(t1);
j_mayer76a66252007-03-07 08:32:30 +00004986 if (unlikely(Rc(ctx->opcode) != 0))
aurel3274879532008-12-05 07:21:44 +00004987 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00004988}
4989
4990/* srlq */
Blue Swirl99e300e2009-06-17 15:22:09 +00004991static void gen_srlq(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00004992{
aurel3274879532008-12-05 07:21:44 +00004993 int l1 = gen_new_label();
4994 int l2 = gen_new_label();
4995 TCGv t0 = tcg_temp_local_new();
4996 TCGv t1 = tcg_temp_local_new();
4997 TCGv t2 = tcg_temp_local_new();
4998 tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
4999 tcg_gen_movi_tl(t1, 0xFFFFFFFF);
5000 tcg_gen_shr_tl(t2, t1, t2);
5001 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
5002 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5003 gen_load_spr(t0, SPR_MQ);
5004 tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
5005 tcg_gen_br(l2);
5006 gen_set_label(l1);
5007 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5008 tcg_gen_and_tl(t0, t0, t2);
5009 gen_load_spr(t1, SPR_MQ);
5010 tcg_gen_andc_tl(t1, t1, t2);
5011 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5012 gen_set_label(l2);
5013 tcg_temp_free(t0);
5014 tcg_temp_free(t1);
5015 tcg_temp_free(t2);
j_mayer76a66252007-03-07 08:32:30 +00005016 if (unlikely(Rc(ctx->opcode) != 0))
aurel3274879532008-12-05 07:21:44 +00005017 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00005018}
5019
5020/* srq */
Blue Swirl99e300e2009-06-17 15:22:09 +00005021static void gen_srq(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005022{
aurel3274879532008-12-05 07:21:44 +00005023 int l1 = gen_new_label();
5024 TCGv t0 = tcg_temp_new();
5025 TCGv t1 = tcg_temp_new();
5026 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5027 tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5028 tcg_gen_subfi_tl(t1, 32, t1);
5029 tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5030 tcg_gen_or_tl(t1, t0, t1);
5031 gen_store_spr(SPR_MQ, t1);
5032 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5033 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5034 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5035 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5036 gen_set_label(l1);
5037 tcg_temp_free(t0);
5038 tcg_temp_free(t1);
j_mayer76a66252007-03-07 08:32:30 +00005039 if (unlikely(Rc(ctx->opcode) != 0))
aurel3274879532008-12-05 07:21:44 +00005040 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00005041}
5042
5043/* PowerPC 602 specific instructions */
Blue Swirl99e300e2009-06-17 15:22:09 +00005044
Blue Swirl54623272009-06-17 15:22:19 +00005045/* dsa */
Blue Swirl99e300e2009-06-17 15:22:09 +00005046static void gen_dsa(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005047{
5048 /* XXX: TODO */
aurel32e06fcd72008-12-11 22:42:14 +00005049 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
j_mayer76a66252007-03-07 08:32:30 +00005050}
5051
5052/* esa */
Blue Swirl99e300e2009-06-17 15:22:09 +00005053static void gen_esa(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005054{
5055 /* XXX: TODO */
aurel32e06fcd72008-12-11 22:42:14 +00005056 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
j_mayer76a66252007-03-07 08:32:30 +00005057}
5058
5059/* mfrom */
Blue Swirl99e300e2009-06-17 15:22:09 +00005060static void gen_mfrom(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005061{
5062#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005063 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005064#else
aurel3276db3ba2008-12-08 18:11:21 +00005065 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005066 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005067 return;
5068 }
aurel32cf02a652008-11-30 16:23:35 +00005069 gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00005070#endif
5071}
5072
5073/* 602 - 603 - G2 TLB management */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00005074
Blue Swirl54623272009-06-17 15:22:19 +00005075/* tlbld */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00005076static void gen_tlbld_6xx(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005077{
5078#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005079 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005080#else
aurel3276db3ba2008-12-08 18:11:21 +00005081 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005082 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005083 return;
5084 }
aurel3274d37792008-12-06 21:46:17 +00005085 gen_helper_6xx_tlbd(cpu_gpr[rB(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00005086#endif
5087}
5088
5089/* tlbli */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00005090static void gen_tlbli_6xx(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005091{
5092#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005093 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005094#else
aurel3276db3ba2008-12-08 18:11:21 +00005095 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005096 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005097 return;
5098 }
aurel3274d37792008-12-06 21:46:17 +00005099 gen_helper_6xx_tlbi(cpu_gpr[rB(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00005100#endif
5101}
5102
j_mayer7dbe11a2007-10-01 05:16:57 +00005103/* 74xx TLB management */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00005104
Blue Swirl54623272009-06-17 15:22:19 +00005105/* tlbld */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00005106static void gen_tlbld_74xx(DisasContext *ctx)
j_mayer7dbe11a2007-10-01 05:16:57 +00005107{
5108#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005109 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer7dbe11a2007-10-01 05:16:57 +00005110#else
aurel3276db3ba2008-12-08 18:11:21 +00005111 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005112 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer7dbe11a2007-10-01 05:16:57 +00005113 return;
5114 }
aurel3274d37792008-12-06 21:46:17 +00005115 gen_helper_74xx_tlbd(cpu_gpr[rB(ctx->opcode)]);
j_mayer7dbe11a2007-10-01 05:16:57 +00005116#endif
5117}
5118
5119/* tlbli */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00005120static void gen_tlbli_74xx(DisasContext *ctx)
j_mayer7dbe11a2007-10-01 05:16:57 +00005121{
5122#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005123 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer7dbe11a2007-10-01 05:16:57 +00005124#else
aurel3276db3ba2008-12-08 18:11:21 +00005125 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005126 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer7dbe11a2007-10-01 05:16:57 +00005127 return;
5128 }
aurel3274d37792008-12-06 21:46:17 +00005129 gen_helper_74xx_tlbi(cpu_gpr[rB(ctx->opcode)]);
j_mayer7dbe11a2007-10-01 05:16:57 +00005130#endif
5131}
5132
j_mayer76a66252007-03-07 08:32:30 +00005133/* POWER instructions not in PowerPC 601 */
Blue Swirl99e300e2009-06-17 15:22:09 +00005134
Blue Swirl54623272009-06-17 15:22:19 +00005135/* clf */
Blue Swirl99e300e2009-06-17 15:22:09 +00005136static void gen_clf(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005137{
5138 /* Cache line flush: implemented as no-op */
5139}
5140
5141/* cli */
Blue Swirl99e300e2009-06-17 15:22:09 +00005142static void gen_cli(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005143{
blueswir17f75ffd2007-05-27 19:39:27 +00005144 /* Cache line invalidate: privileged and treated as no-op */
j_mayer76a66252007-03-07 08:32:30 +00005145#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005146 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005147#else
aurel3276db3ba2008-12-08 18:11:21 +00005148 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005149 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005150 return;
5151 }
5152#endif
5153}
5154
5155/* dclst */
Blue Swirl99e300e2009-06-17 15:22:09 +00005156static void gen_dclst(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005157{
5158 /* Data cache line store: treated as no-op */
5159}
5160
Blue Swirl99e300e2009-06-17 15:22:09 +00005161static void gen_mfsri(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005162{
5163#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005164 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005165#else
aurel3274d37792008-12-06 21:46:17 +00005166 int ra = rA(ctx->opcode);
5167 int rd = rD(ctx->opcode);
5168 TCGv t0;
aurel3276db3ba2008-12-08 18:11:21 +00005169 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005170 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005171 return;
5172 }
aurel3274d37792008-12-06 21:46:17 +00005173 t0 = tcg_temp_new();
aurel3276db3ba2008-12-08 18:11:21 +00005174 gen_addr_reg_index(ctx, t0);
aurel3274d37792008-12-06 21:46:17 +00005175 tcg_gen_shri_tl(t0, t0, 28);
5176 tcg_gen_andi_tl(t0, t0, 0xF);
5177 gen_helper_load_sr(cpu_gpr[rd], t0);
5178 tcg_temp_free(t0);
j_mayer76a66252007-03-07 08:32:30 +00005179 if (ra != 0 && ra != rd)
aurel3274d37792008-12-06 21:46:17 +00005180 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]);
j_mayer76a66252007-03-07 08:32:30 +00005181#endif
5182}
5183
Blue Swirl99e300e2009-06-17 15:22:09 +00005184static void gen_rac(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005185{
5186#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005187 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005188#else
aurel3222e0e172008-12-06 12:19:14 +00005189 TCGv t0;
aurel3276db3ba2008-12-08 18:11:21 +00005190 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005191 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005192 return;
5193 }
aurel3222e0e172008-12-06 12:19:14 +00005194 t0 = tcg_temp_new();
aurel3276db3ba2008-12-08 18:11:21 +00005195 gen_addr_reg_index(ctx, t0);
aurel3222e0e172008-12-06 12:19:14 +00005196 gen_helper_rac(cpu_gpr[rD(ctx->opcode)], t0);
5197 tcg_temp_free(t0);
j_mayer76a66252007-03-07 08:32:30 +00005198#endif
5199}
5200
Blue Swirl99e300e2009-06-17 15:22:09 +00005201static void gen_rfsvc(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005202{
5203#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005204 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005205#else
aurel3276db3ba2008-12-08 18:11:21 +00005206 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005207 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005208 return;
5209 }
aurel32d72a19f2008-11-30 16:24:55 +00005210 gen_helper_rfsvc();
aurel32e06fcd72008-12-11 22:42:14 +00005211 gen_sync_exception(ctx);
j_mayer76a66252007-03-07 08:32:30 +00005212#endif
5213}
5214
5215/* svc is not implemented for now */
5216
5217/* POWER2 specific instructions */
5218/* Quad manipulation (load/store two floats at a time) */
j_mayer76a66252007-03-07 08:32:30 +00005219
5220/* lfq */
Blue Swirl99e300e2009-06-17 15:22:09 +00005221static void gen_lfq(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005222{
aurel3201a4afe2008-11-27 19:30:56 +00005223 int rd = rD(ctx->opcode);
aurel3276db3ba2008-12-08 18:11:21 +00005224 TCGv t0;
5225 gen_set_access_type(ctx, ACCESS_FLOAT);
5226 t0 = tcg_temp_new();
5227 gen_addr_imm_index(ctx, t0, 0);
5228 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5229 gen_addr_add(ctx, t0, t0, 8);
5230 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
aurel3201a4afe2008-11-27 19:30:56 +00005231 tcg_temp_free(t0);
j_mayer76a66252007-03-07 08:32:30 +00005232}
5233
5234/* lfqu */
Blue Swirl99e300e2009-06-17 15:22:09 +00005235static void gen_lfqu(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005236{
5237 int ra = rA(ctx->opcode);
aurel3201a4afe2008-11-27 19:30:56 +00005238 int rd = rD(ctx->opcode);
aurel3276db3ba2008-12-08 18:11:21 +00005239 TCGv t0, t1;
5240 gen_set_access_type(ctx, ACCESS_FLOAT);
5241 t0 = tcg_temp_new();
5242 t1 = tcg_temp_new();
5243 gen_addr_imm_index(ctx, t0, 0);
5244 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5245 gen_addr_add(ctx, t1, t0, 8);
5246 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
j_mayer76a66252007-03-07 08:32:30 +00005247 if (ra != 0)
aurel3201a4afe2008-11-27 19:30:56 +00005248 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5249 tcg_temp_free(t0);
5250 tcg_temp_free(t1);
j_mayer76a66252007-03-07 08:32:30 +00005251}
5252
5253/* lfqux */
Blue Swirl99e300e2009-06-17 15:22:09 +00005254static void gen_lfqux(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005255{
5256 int ra = rA(ctx->opcode);
aurel3201a4afe2008-11-27 19:30:56 +00005257 int rd = rD(ctx->opcode);
aurel3276db3ba2008-12-08 18:11:21 +00005258 gen_set_access_type(ctx, ACCESS_FLOAT);
5259 TCGv t0, t1;
5260 t0 = tcg_temp_new();
5261 gen_addr_reg_index(ctx, t0);
5262 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5263 t1 = tcg_temp_new();
5264 gen_addr_add(ctx, t1, t0, 8);
5265 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5266 tcg_temp_free(t1);
j_mayer76a66252007-03-07 08:32:30 +00005267 if (ra != 0)
aurel3201a4afe2008-11-27 19:30:56 +00005268 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5269 tcg_temp_free(t0);
j_mayer76a66252007-03-07 08:32:30 +00005270}
5271
5272/* lfqx */
Blue Swirl99e300e2009-06-17 15:22:09 +00005273static void gen_lfqx(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005274{
aurel3201a4afe2008-11-27 19:30:56 +00005275 int rd = rD(ctx->opcode);
aurel3276db3ba2008-12-08 18:11:21 +00005276 TCGv t0;
5277 gen_set_access_type(ctx, ACCESS_FLOAT);
5278 t0 = tcg_temp_new();
5279 gen_addr_reg_index(ctx, t0);
5280 gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5281 gen_addr_add(ctx, t0, t0, 8);
5282 gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
aurel3201a4afe2008-11-27 19:30:56 +00005283 tcg_temp_free(t0);
j_mayer76a66252007-03-07 08:32:30 +00005284}
5285
5286/* stfq */
Blue Swirl99e300e2009-06-17 15:22:09 +00005287static void gen_stfq(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005288{
aurel3201a4afe2008-11-27 19:30:56 +00005289 int rd = rD(ctx->opcode);
aurel3276db3ba2008-12-08 18:11:21 +00005290 TCGv t0;
5291 gen_set_access_type(ctx, ACCESS_FLOAT);
5292 t0 = tcg_temp_new();
5293 gen_addr_imm_index(ctx, t0, 0);
5294 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5295 gen_addr_add(ctx, t0, t0, 8);
5296 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
aurel3201a4afe2008-11-27 19:30:56 +00005297 tcg_temp_free(t0);
j_mayer76a66252007-03-07 08:32:30 +00005298}
5299
5300/* stfqu */
Blue Swirl99e300e2009-06-17 15:22:09 +00005301static void gen_stfqu(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005302{
5303 int ra = rA(ctx->opcode);
aurel3201a4afe2008-11-27 19:30:56 +00005304 int rd = rD(ctx->opcode);
aurel3276db3ba2008-12-08 18:11:21 +00005305 TCGv t0, t1;
5306 gen_set_access_type(ctx, ACCESS_FLOAT);
5307 t0 = tcg_temp_new();
5308 gen_addr_imm_index(ctx, t0, 0);
5309 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5310 t1 = tcg_temp_new();
5311 gen_addr_add(ctx, t1, t0, 8);
5312 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5313 tcg_temp_free(t1);
j_mayer76a66252007-03-07 08:32:30 +00005314 if (ra != 0)
aurel3201a4afe2008-11-27 19:30:56 +00005315 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5316 tcg_temp_free(t0);
j_mayer76a66252007-03-07 08:32:30 +00005317}
5318
5319/* stfqux */
Blue Swirl99e300e2009-06-17 15:22:09 +00005320static void gen_stfqux(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005321{
5322 int ra = rA(ctx->opcode);
aurel3201a4afe2008-11-27 19:30:56 +00005323 int rd = rD(ctx->opcode);
aurel3276db3ba2008-12-08 18:11:21 +00005324 TCGv t0, t1;
5325 gen_set_access_type(ctx, ACCESS_FLOAT);
5326 t0 = tcg_temp_new();
5327 gen_addr_reg_index(ctx, t0);
5328 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5329 t1 = tcg_temp_new();
5330 gen_addr_add(ctx, t1, t0, 8);
5331 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5332 tcg_temp_free(t1);
j_mayer76a66252007-03-07 08:32:30 +00005333 if (ra != 0)
aurel3201a4afe2008-11-27 19:30:56 +00005334 tcg_gen_mov_tl(cpu_gpr[ra], t0);
5335 tcg_temp_free(t0);
j_mayer76a66252007-03-07 08:32:30 +00005336}
5337
5338/* stfqx */
Blue Swirl99e300e2009-06-17 15:22:09 +00005339static void gen_stfqx(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005340{
aurel3201a4afe2008-11-27 19:30:56 +00005341 int rd = rD(ctx->opcode);
aurel3276db3ba2008-12-08 18:11:21 +00005342 TCGv t0;
5343 gen_set_access_type(ctx, ACCESS_FLOAT);
5344 t0 = tcg_temp_new();
5345 gen_addr_reg_index(ctx, t0);
5346 gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5347 gen_addr_add(ctx, t0, t0, 8);
5348 gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
aurel3201a4afe2008-11-27 19:30:56 +00005349 tcg_temp_free(t0);
j_mayer76a66252007-03-07 08:32:30 +00005350}
5351
5352/* BookE specific instructions */
Blue Swirl99e300e2009-06-17 15:22:09 +00005353
Blue Swirl54623272009-06-17 15:22:19 +00005354/* XXX: not implemented on 440 ? */
Blue Swirl99e300e2009-06-17 15:22:09 +00005355static void gen_mfapidi(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005356{
5357 /* XXX: TODO */
aurel32e06fcd72008-12-11 22:42:14 +00005358 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
j_mayer76a66252007-03-07 08:32:30 +00005359}
5360
j_mayer2662a052007-09-21 05:50:37 +00005361/* XXX: not implemented on 440 ? */
Blue Swirl99e300e2009-06-17 15:22:09 +00005362static void gen_tlbiva(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005363{
5364#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005365 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005366#else
aurel3274d37792008-12-06 21:46:17 +00005367 TCGv t0;
aurel3276db3ba2008-12-08 18:11:21 +00005368 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005369 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005370 return;
5371 }
aurel32ec72e272008-12-07 15:45:15 +00005372 t0 = tcg_temp_new();
aurel3276db3ba2008-12-08 18:11:21 +00005373 gen_addr_reg_index(ctx, t0);
aurel3274d37792008-12-06 21:46:17 +00005374 gen_helper_tlbie(cpu_gpr[rB(ctx->opcode)]);
5375 tcg_temp_free(t0);
j_mayer76a66252007-03-07 08:32:30 +00005376#endif
5377}
5378
5379/* All 405 MAC instructions are translated here */
Blue Swirl636aa202009-08-16 09:06:54 +00005380static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3,
5381 int ra, int rb, int rt, int Rc)
j_mayer76a66252007-03-07 08:32:30 +00005382{
aurel32182608d2008-11-01 00:54:23 +00005383 TCGv t0, t1;
5384
pbrooka7812ae2008-11-17 14:43:54 +00005385 t0 = tcg_temp_local_new();
5386 t1 = tcg_temp_local_new();
aurel32182608d2008-11-01 00:54:23 +00005387
j_mayer76a66252007-03-07 08:32:30 +00005388 switch (opc3 & 0x0D) {
5389 case 0x05:
5390 /* macchw - macchw. - macchwo - macchwo. */
5391 /* macchws - macchws. - macchwso - macchwso. */
5392 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5393 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5394 /* mulchw - mulchw. */
aurel32182608d2008-11-01 00:54:23 +00005395 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5396 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5397 tcg_gen_ext16s_tl(t1, t1);
j_mayer76a66252007-03-07 08:32:30 +00005398 break;
5399 case 0x04:
5400 /* macchwu - macchwu. - macchwuo - macchwuo. */
5401 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5402 /* mulchwu - mulchwu. */
aurel32182608d2008-11-01 00:54:23 +00005403 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5404 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5405 tcg_gen_ext16u_tl(t1, t1);
j_mayer76a66252007-03-07 08:32:30 +00005406 break;
5407 case 0x01:
5408 /* machhw - machhw. - machhwo - machhwo. */
5409 /* machhws - machhws. - machhwso - machhwso. */
5410 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5411 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5412 /* mulhhw - mulhhw. */
aurel32182608d2008-11-01 00:54:23 +00005413 tcg_gen_sari_tl(t0, cpu_gpr[ra], 16);
5414 tcg_gen_ext16s_tl(t0, t0);
5415 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5416 tcg_gen_ext16s_tl(t1, t1);
j_mayer76a66252007-03-07 08:32:30 +00005417 break;
5418 case 0x00:
5419 /* machhwu - machhwu. - machhwuo - machhwuo. */
5420 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5421 /* mulhhwu - mulhhwu. */
aurel32182608d2008-11-01 00:54:23 +00005422 tcg_gen_shri_tl(t0, cpu_gpr[ra], 16);
5423 tcg_gen_ext16u_tl(t0, t0);
5424 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5425 tcg_gen_ext16u_tl(t1, t1);
j_mayer76a66252007-03-07 08:32:30 +00005426 break;
5427 case 0x0D:
5428 /* maclhw - maclhw. - maclhwo - maclhwo. */
5429 /* maclhws - maclhws. - maclhwso - maclhwso. */
5430 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5431 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5432 /* mullhw - mullhw. */
aurel32182608d2008-11-01 00:54:23 +00005433 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5434 tcg_gen_ext16s_tl(t1, cpu_gpr[rb]);
j_mayer76a66252007-03-07 08:32:30 +00005435 break;
5436 case 0x0C:
5437 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5438 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5439 /* mullhwu - mullhwu. */
aurel32182608d2008-11-01 00:54:23 +00005440 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5441 tcg_gen_ext16u_tl(t1, cpu_gpr[rb]);
j_mayer76a66252007-03-07 08:32:30 +00005442 break;
5443 }
j_mayer76a66252007-03-07 08:32:30 +00005444 if (opc2 & 0x04) {
aurel32182608d2008-11-01 00:54:23 +00005445 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5446 tcg_gen_mul_tl(t1, t0, t1);
5447 if (opc2 & 0x02) {
5448 /* nmultiply-and-accumulate (0x0E) */
5449 tcg_gen_sub_tl(t0, cpu_gpr[rt], t1);
5450 } else {
5451 /* multiply-and-accumulate (0x0C) */
5452 tcg_gen_add_tl(t0, cpu_gpr[rt], t1);
5453 }
5454
5455 if (opc3 & 0x12) {
5456 /* Check overflow and/or saturate */
5457 int l1 = gen_new_label();
5458
5459 if (opc3 & 0x10) {
5460 /* Start with XER OV disabled, the most likely case */
5461 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
5462 }
5463 if (opc3 & 0x01) {
5464 /* Signed */
5465 tcg_gen_xor_tl(t1, cpu_gpr[rt], t1);
5466 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1);
5467 tcg_gen_xor_tl(t1, cpu_gpr[rt], t0);
5468 tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1);
aurel32bdc4e052008-11-09 17:27:03 +00005469 if (opc3 & 0x02) {
aurel32182608d2008-11-01 00:54:23 +00005470 /* Saturate */
5471 tcg_gen_sari_tl(t0, cpu_gpr[rt], 31);
5472 tcg_gen_xori_tl(t0, t0, 0x7fffffff);
5473 }
5474 } else {
5475 /* Unsigned */
5476 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
aurel32bdc4e052008-11-09 17:27:03 +00005477 if (opc3 & 0x02) {
aurel32182608d2008-11-01 00:54:23 +00005478 /* Saturate */
5479 tcg_gen_movi_tl(t0, UINT32_MAX);
5480 }
5481 }
5482 if (opc3 & 0x10) {
5483 /* Check overflow */
5484 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
5485 }
5486 gen_set_label(l1);
5487 tcg_gen_mov_tl(cpu_gpr[rt], t0);
5488 }
5489 } else {
5490 tcg_gen_mul_tl(cpu_gpr[rt], t0, t1);
j_mayer76a66252007-03-07 08:32:30 +00005491 }
aurel32182608d2008-11-01 00:54:23 +00005492 tcg_temp_free(t0);
5493 tcg_temp_free(t1);
j_mayer76a66252007-03-07 08:32:30 +00005494 if (unlikely(Rc) != 0) {
5495 /* Update Rc0 */
aurel32182608d2008-11-01 00:54:23 +00005496 gen_set_Rc0(ctx, cpu_gpr[rt]);
j_mayer76a66252007-03-07 08:32:30 +00005497 }
5498}
5499
j_mayera750fc02007-09-26 23:54:22 +00005500#define GEN_MAC_HANDLER(name, opc2, opc3) \
Blue Swirl99e300e2009-06-17 15:22:09 +00005501static void glue(gen_, name)(DisasContext *ctx) \
j_mayer76a66252007-03-07 08:32:30 +00005502{ \
5503 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5504 rD(ctx->opcode), Rc(ctx->opcode)); \
5505}
5506
5507/* macchw - macchw. */
j_mayera750fc02007-09-26 23:54:22 +00005508GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
j_mayer76a66252007-03-07 08:32:30 +00005509/* macchwo - macchwo. */
j_mayera750fc02007-09-26 23:54:22 +00005510GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
j_mayer76a66252007-03-07 08:32:30 +00005511/* macchws - macchws. */
j_mayera750fc02007-09-26 23:54:22 +00005512GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
j_mayer76a66252007-03-07 08:32:30 +00005513/* macchwso - macchwso. */
j_mayera750fc02007-09-26 23:54:22 +00005514GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
j_mayer76a66252007-03-07 08:32:30 +00005515/* macchwsu - macchwsu. */
j_mayera750fc02007-09-26 23:54:22 +00005516GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
j_mayer76a66252007-03-07 08:32:30 +00005517/* macchwsuo - macchwsuo. */
j_mayera750fc02007-09-26 23:54:22 +00005518GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
j_mayer76a66252007-03-07 08:32:30 +00005519/* macchwu - macchwu. */
j_mayera750fc02007-09-26 23:54:22 +00005520GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
j_mayer76a66252007-03-07 08:32:30 +00005521/* macchwuo - macchwuo. */
j_mayera750fc02007-09-26 23:54:22 +00005522GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
j_mayer76a66252007-03-07 08:32:30 +00005523/* machhw - machhw. */
j_mayera750fc02007-09-26 23:54:22 +00005524GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
j_mayer76a66252007-03-07 08:32:30 +00005525/* machhwo - machhwo. */
j_mayera750fc02007-09-26 23:54:22 +00005526GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
j_mayer76a66252007-03-07 08:32:30 +00005527/* machhws - machhws. */
j_mayera750fc02007-09-26 23:54:22 +00005528GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
j_mayer76a66252007-03-07 08:32:30 +00005529/* machhwso - machhwso. */
j_mayera750fc02007-09-26 23:54:22 +00005530GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
j_mayer76a66252007-03-07 08:32:30 +00005531/* machhwsu - machhwsu. */
j_mayera750fc02007-09-26 23:54:22 +00005532GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
j_mayer76a66252007-03-07 08:32:30 +00005533/* machhwsuo - machhwsuo. */
j_mayera750fc02007-09-26 23:54:22 +00005534GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
j_mayer76a66252007-03-07 08:32:30 +00005535/* machhwu - machhwu. */
j_mayera750fc02007-09-26 23:54:22 +00005536GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
j_mayer76a66252007-03-07 08:32:30 +00005537/* machhwuo - machhwuo. */
j_mayera750fc02007-09-26 23:54:22 +00005538GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
j_mayer76a66252007-03-07 08:32:30 +00005539/* maclhw - maclhw. */
j_mayera750fc02007-09-26 23:54:22 +00005540GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
j_mayer76a66252007-03-07 08:32:30 +00005541/* maclhwo - maclhwo. */
j_mayera750fc02007-09-26 23:54:22 +00005542GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
j_mayer76a66252007-03-07 08:32:30 +00005543/* maclhws - maclhws. */
j_mayera750fc02007-09-26 23:54:22 +00005544GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
j_mayer76a66252007-03-07 08:32:30 +00005545/* maclhwso - maclhwso. */
j_mayera750fc02007-09-26 23:54:22 +00005546GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
j_mayer76a66252007-03-07 08:32:30 +00005547/* maclhwu - maclhwu. */
j_mayera750fc02007-09-26 23:54:22 +00005548GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
j_mayer76a66252007-03-07 08:32:30 +00005549/* maclhwuo - maclhwuo. */
j_mayera750fc02007-09-26 23:54:22 +00005550GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
j_mayer76a66252007-03-07 08:32:30 +00005551/* maclhwsu - maclhwsu. */
j_mayera750fc02007-09-26 23:54:22 +00005552GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
j_mayer76a66252007-03-07 08:32:30 +00005553/* maclhwsuo - maclhwsuo. */
j_mayera750fc02007-09-26 23:54:22 +00005554GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
j_mayer76a66252007-03-07 08:32:30 +00005555/* nmacchw - nmacchw. */
j_mayera750fc02007-09-26 23:54:22 +00005556GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
j_mayer76a66252007-03-07 08:32:30 +00005557/* nmacchwo - nmacchwo. */
j_mayera750fc02007-09-26 23:54:22 +00005558GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
j_mayer76a66252007-03-07 08:32:30 +00005559/* nmacchws - nmacchws. */
j_mayera750fc02007-09-26 23:54:22 +00005560GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
j_mayer76a66252007-03-07 08:32:30 +00005561/* nmacchwso - nmacchwso. */
j_mayera750fc02007-09-26 23:54:22 +00005562GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
j_mayer76a66252007-03-07 08:32:30 +00005563/* nmachhw - nmachhw. */
j_mayera750fc02007-09-26 23:54:22 +00005564GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
j_mayer76a66252007-03-07 08:32:30 +00005565/* nmachhwo - nmachhwo. */
j_mayera750fc02007-09-26 23:54:22 +00005566GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
j_mayer76a66252007-03-07 08:32:30 +00005567/* nmachhws - nmachhws. */
j_mayera750fc02007-09-26 23:54:22 +00005568GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
j_mayer76a66252007-03-07 08:32:30 +00005569/* nmachhwso - nmachhwso. */
j_mayera750fc02007-09-26 23:54:22 +00005570GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
j_mayer76a66252007-03-07 08:32:30 +00005571/* nmaclhw - nmaclhw. */
j_mayera750fc02007-09-26 23:54:22 +00005572GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
j_mayer76a66252007-03-07 08:32:30 +00005573/* nmaclhwo - nmaclhwo. */
j_mayera750fc02007-09-26 23:54:22 +00005574GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
j_mayer76a66252007-03-07 08:32:30 +00005575/* nmaclhws - nmaclhws. */
j_mayera750fc02007-09-26 23:54:22 +00005576GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
j_mayer76a66252007-03-07 08:32:30 +00005577/* nmaclhwso - nmaclhwso. */
j_mayera750fc02007-09-26 23:54:22 +00005578GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
j_mayer76a66252007-03-07 08:32:30 +00005579
5580/* mulchw - mulchw. */
j_mayera750fc02007-09-26 23:54:22 +00005581GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
j_mayer76a66252007-03-07 08:32:30 +00005582/* mulchwu - mulchwu. */
j_mayera750fc02007-09-26 23:54:22 +00005583GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
j_mayer76a66252007-03-07 08:32:30 +00005584/* mulhhw - mulhhw. */
j_mayera750fc02007-09-26 23:54:22 +00005585GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
j_mayer76a66252007-03-07 08:32:30 +00005586/* mulhhwu - mulhhwu. */
j_mayera750fc02007-09-26 23:54:22 +00005587GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
j_mayer76a66252007-03-07 08:32:30 +00005588/* mullhw - mullhw. */
j_mayera750fc02007-09-26 23:54:22 +00005589GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
j_mayer76a66252007-03-07 08:32:30 +00005590/* mullhwu - mullhwu. */
j_mayera750fc02007-09-26 23:54:22 +00005591GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
j_mayer76a66252007-03-07 08:32:30 +00005592
5593/* mfdcr */
Blue Swirl99e300e2009-06-17 15:22:09 +00005594static void gen_mfdcr(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005595{
5596#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005597 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
j_mayer76a66252007-03-07 08:32:30 +00005598#else
aurel3206dca6a2008-12-06 16:37:18 +00005599 TCGv dcrn;
aurel3276db3ba2008-12-08 18:11:21 +00005600 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005601 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
j_mayer76a66252007-03-07 08:32:30 +00005602 return;
5603 }
aurel3206dca6a2008-12-06 16:37:18 +00005604 /* NIP cannot be restored if the memory exception comes from an helper */
5605 gen_update_nip(ctx, ctx->nip - 4);
5606 dcrn = tcg_const_tl(SPR(ctx->opcode));
5607 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], dcrn);
5608 tcg_temp_free(dcrn);
j_mayer76a66252007-03-07 08:32:30 +00005609#endif
5610}
5611
5612/* mtdcr */
Blue Swirl99e300e2009-06-17 15:22:09 +00005613static void gen_mtdcr(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005614{
5615#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005616 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
j_mayer76a66252007-03-07 08:32:30 +00005617#else
aurel3206dca6a2008-12-06 16:37:18 +00005618 TCGv dcrn;
aurel3276db3ba2008-12-08 18:11:21 +00005619 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005620 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
j_mayer76a66252007-03-07 08:32:30 +00005621 return;
5622 }
aurel3206dca6a2008-12-06 16:37:18 +00005623 /* NIP cannot be restored if the memory exception comes from an helper */
5624 gen_update_nip(ctx, ctx->nip - 4);
5625 dcrn = tcg_const_tl(SPR(ctx->opcode));
5626 gen_helper_store_dcr(dcrn, cpu_gpr[rS(ctx->opcode)]);
5627 tcg_temp_free(dcrn);
j_mayera42bd6c2007-03-30 10:22:46 +00005628#endif
5629}
5630
5631/* mfdcrx */
j_mayer2662a052007-09-21 05:50:37 +00005632/* XXX: not implemented on 440 ? */
Blue Swirl99e300e2009-06-17 15:22:09 +00005633static void gen_mfdcrx(DisasContext *ctx)
j_mayera42bd6c2007-03-30 10:22:46 +00005634{
5635#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005636 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
j_mayera42bd6c2007-03-30 10:22:46 +00005637#else
aurel3276db3ba2008-12-08 18:11:21 +00005638 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005639 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
j_mayera42bd6c2007-03-30 10:22:46 +00005640 return;
5641 }
aurel3206dca6a2008-12-06 16:37:18 +00005642 /* NIP cannot be restored if the memory exception comes from an helper */
5643 gen_update_nip(ctx, ctx->nip - 4);
5644 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
j_mayera750fc02007-09-26 23:54:22 +00005645 /* Note: Rc update flag set leads to undefined state of Rc0 */
j_mayera42bd6c2007-03-30 10:22:46 +00005646#endif
5647}
5648
5649/* mtdcrx */
j_mayer2662a052007-09-21 05:50:37 +00005650/* XXX: not implemented on 440 ? */
Blue Swirl99e300e2009-06-17 15:22:09 +00005651static void gen_mtdcrx(DisasContext *ctx)
j_mayera42bd6c2007-03-30 10:22:46 +00005652{
5653#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005654 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
j_mayera42bd6c2007-03-30 10:22:46 +00005655#else
aurel3276db3ba2008-12-08 18:11:21 +00005656 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005657 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
j_mayera42bd6c2007-03-30 10:22:46 +00005658 return;
5659 }
aurel3206dca6a2008-12-06 16:37:18 +00005660 /* NIP cannot be restored if the memory exception comes from an helper */
5661 gen_update_nip(ctx, ctx->nip - 4);
5662 gen_helper_store_dcr(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
j_mayera750fc02007-09-26 23:54:22 +00005663 /* Note: Rc update flag set leads to undefined state of Rc0 */
j_mayer76a66252007-03-07 08:32:30 +00005664#endif
5665}
5666
j_mayera750fc02007-09-26 23:54:22 +00005667/* mfdcrux (PPC 460) : user-mode access to DCR */
Blue Swirl99e300e2009-06-17 15:22:09 +00005668static void gen_mfdcrux(DisasContext *ctx)
j_mayera750fc02007-09-26 23:54:22 +00005669{
aurel3206dca6a2008-12-06 16:37:18 +00005670 /* NIP cannot be restored if the memory exception comes from an helper */
5671 gen_update_nip(ctx, ctx->nip - 4);
5672 gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
j_mayera750fc02007-09-26 23:54:22 +00005673 /* Note: Rc update flag set leads to undefined state of Rc0 */
5674}
5675
5676/* mtdcrux (PPC 460) : user-mode access to DCR */
Blue Swirl99e300e2009-06-17 15:22:09 +00005677static void gen_mtdcrux(DisasContext *ctx)
j_mayera750fc02007-09-26 23:54:22 +00005678{
aurel3206dca6a2008-12-06 16:37:18 +00005679 /* NIP cannot be restored if the memory exception comes from an helper */
5680 gen_update_nip(ctx, ctx->nip - 4);
5681 gen_helper_store_dcr(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
j_mayera750fc02007-09-26 23:54:22 +00005682 /* Note: Rc update flag set leads to undefined state of Rc0 */
5683}
5684
j_mayer76a66252007-03-07 08:32:30 +00005685/* dccci */
Blue Swirl99e300e2009-06-17 15:22:09 +00005686static void gen_dccci(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005687{
5688#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005689 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005690#else
aurel3276db3ba2008-12-08 18:11:21 +00005691 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005692 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005693 return;
5694 }
5695 /* interpreted as no-op */
5696#endif
5697}
5698
5699/* dcread */
Blue Swirl99e300e2009-06-17 15:22:09 +00005700static void gen_dcread(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005701{
5702#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005703 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005704#else
aurel32b61f2752008-10-15 17:00:37 +00005705 TCGv EA, val;
aurel3276db3ba2008-12-08 18:11:21 +00005706 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005707 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005708 return;
5709 }
aurel3276db3ba2008-12-08 18:11:21 +00005710 gen_set_access_type(ctx, ACCESS_CACHE);
pbrooka7812ae2008-11-17 14:43:54 +00005711 EA = tcg_temp_new();
aurel3276db3ba2008-12-08 18:11:21 +00005712 gen_addr_reg_index(ctx, EA);
pbrooka7812ae2008-11-17 14:43:54 +00005713 val = tcg_temp_new();
aurel3276db3ba2008-12-08 18:11:21 +00005714 gen_qemu_ld32u(ctx, val, EA);
aurel32b61f2752008-10-15 17:00:37 +00005715 tcg_temp_free(val);
5716 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA);
5717 tcg_temp_free(EA);
j_mayer76a66252007-03-07 08:32:30 +00005718#endif
5719}
5720
5721/* icbt */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00005722static void gen_icbt_40x(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005723{
5724 /* interpreted as no-op */
5725 /* XXX: specification say this is treated as a load by the MMU
5726 * but does not generate any exception
5727 */
5728}
5729
5730/* iccci */
Blue Swirl99e300e2009-06-17 15:22:09 +00005731static void gen_iccci(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005732{
5733#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005734 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005735#else
aurel3276db3ba2008-12-08 18:11:21 +00005736 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005737 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005738 return;
5739 }
5740 /* interpreted as no-op */
5741#endif
5742}
5743
5744/* icread */
Blue Swirl99e300e2009-06-17 15:22:09 +00005745static void gen_icread(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005746{
5747#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005748 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005749#else
aurel3276db3ba2008-12-08 18:11:21 +00005750 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005751 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005752 return;
5753 }
5754 /* interpreted as no-op */
5755#endif
5756}
5757
aurel3276db3ba2008-12-08 18:11:21 +00005758/* rfci (mem_idx only) */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00005759static void gen_rfci_40x(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005760{
5761#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005762 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005763#else
aurel3276db3ba2008-12-08 18:11:21 +00005764 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005765 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005766 return;
5767 }
5768 /* Restore CPU state */
aurel32d72a19f2008-11-30 16:24:55 +00005769 gen_helper_40x_rfci();
aurel32e06fcd72008-12-11 22:42:14 +00005770 gen_sync_exception(ctx);
j_mayer76a66252007-03-07 08:32:30 +00005771#endif
5772}
5773
Blue Swirl99e300e2009-06-17 15:22:09 +00005774static void gen_rfci(DisasContext *ctx)
j_mayera42bd6c2007-03-30 10:22:46 +00005775{
5776#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005777 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayera42bd6c2007-03-30 10:22:46 +00005778#else
aurel3276db3ba2008-12-08 18:11:21 +00005779 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005780 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayera42bd6c2007-03-30 10:22:46 +00005781 return;
5782 }
5783 /* Restore CPU state */
aurel32d72a19f2008-11-30 16:24:55 +00005784 gen_helper_rfci();
aurel32e06fcd72008-12-11 22:42:14 +00005785 gen_sync_exception(ctx);
j_mayera42bd6c2007-03-30 10:22:46 +00005786#endif
5787}
5788
5789/* BookE specific */
Blue Swirl99e300e2009-06-17 15:22:09 +00005790
Blue Swirl54623272009-06-17 15:22:19 +00005791/* XXX: not implemented on 440 ? */
Blue Swirl99e300e2009-06-17 15:22:09 +00005792static void gen_rfdi(DisasContext *ctx)
j_mayera42bd6c2007-03-30 10:22:46 +00005793{
5794#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005795 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayera42bd6c2007-03-30 10:22:46 +00005796#else
aurel3276db3ba2008-12-08 18:11:21 +00005797 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005798 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayera42bd6c2007-03-30 10:22:46 +00005799 return;
5800 }
5801 /* Restore CPU state */
aurel32d72a19f2008-11-30 16:24:55 +00005802 gen_helper_rfdi();
aurel32e06fcd72008-12-11 22:42:14 +00005803 gen_sync_exception(ctx);
j_mayera42bd6c2007-03-30 10:22:46 +00005804#endif
5805}
5806
j_mayer2662a052007-09-21 05:50:37 +00005807/* XXX: not implemented on 440 ? */
Blue Swirl99e300e2009-06-17 15:22:09 +00005808static void gen_rfmci(DisasContext *ctx)
j_mayera42bd6c2007-03-30 10:22:46 +00005809{
5810#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005811 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayera42bd6c2007-03-30 10:22:46 +00005812#else
aurel3276db3ba2008-12-08 18:11:21 +00005813 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005814 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayera42bd6c2007-03-30 10:22:46 +00005815 return;
5816 }
5817 /* Restore CPU state */
aurel32d72a19f2008-11-30 16:24:55 +00005818 gen_helper_rfmci();
aurel32e06fcd72008-12-11 22:42:14 +00005819 gen_sync_exception(ctx);
j_mayera42bd6c2007-03-30 10:22:46 +00005820#endif
5821}
j_mayer5eb79952007-09-19 05:44:04 +00005822
j_mayerd9bce9d2007-03-17 14:02:15 +00005823/* TLB management - PowerPC 405 implementation */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00005824
Blue Swirl54623272009-06-17 15:22:19 +00005825/* tlbre */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00005826static void gen_tlbre_40x(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005827{
5828#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005829 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005830#else
aurel3276db3ba2008-12-08 18:11:21 +00005831 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005832 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005833 return;
5834 }
5835 switch (rB(ctx->opcode)) {
5836 case 0:
aurel3274d37792008-12-06 21:46:17 +00005837 gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00005838 break;
5839 case 1:
aurel3274d37792008-12-06 21:46:17 +00005840 gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00005841 break;
5842 default:
aurel32e06fcd72008-12-11 22:42:14 +00005843 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
j_mayer76a66252007-03-07 08:32:30 +00005844 break;
5845 }
5846#endif
5847}
5848
j_mayerd9bce9d2007-03-17 14:02:15 +00005849/* tlbsx - tlbsx. */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00005850static void gen_tlbsx_40x(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005851{
5852#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005853 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005854#else
aurel3274d37792008-12-06 21:46:17 +00005855 TCGv t0;
aurel3276db3ba2008-12-08 18:11:21 +00005856 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005857 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005858 return;
5859 }
aurel3274d37792008-12-06 21:46:17 +00005860 t0 = tcg_temp_new();
aurel3276db3ba2008-12-08 18:11:21 +00005861 gen_addr_reg_index(ctx, t0);
aurel3274d37792008-12-06 21:46:17 +00005862 gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], t0);
5863 tcg_temp_free(t0);
5864 if (Rc(ctx->opcode)) {
5865 int l1 = gen_new_label();
5866 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_xer);
5867 tcg_gen_shri_i32(cpu_crf[0], cpu_crf[0], XER_SO);
5868 tcg_gen_andi_i32(cpu_crf[0], cpu_crf[0], 1);
5869 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
5870 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
5871 gen_set_label(l1);
5872 }
j_mayer76a66252007-03-07 08:32:30 +00005873#endif
5874}
5875
5876/* tlbwe */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00005877static void gen_tlbwe_40x(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00005878{
5879#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005880 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005881#else
aurel3276db3ba2008-12-08 18:11:21 +00005882 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005883 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00005884 return;
5885 }
5886 switch (rB(ctx->opcode)) {
5887 case 0:
aurel3274d37792008-12-06 21:46:17 +00005888 gen_helper_4xx_tlbwe_hi(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00005889 break;
5890 case 1:
aurel3274d37792008-12-06 21:46:17 +00005891 gen_helper_4xx_tlbwe_lo(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
j_mayer76a66252007-03-07 08:32:30 +00005892 break;
5893 default:
aurel32e06fcd72008-12-11 22:42:14 +00005894 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
j_mayer76a66252007-03-07 08:32:30 +00005895 break;
5896 }
5897#endif
5898}
5899
j_mayera4bb6c32007-09-21 05:28:33 +00005900/* TLB management - PowerPC 440 implementation */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00005901
Blue Swirl54623272009-06-17 15:22:19 +00005902/* tlbre */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00005903static void gen_tlbre_440(DisasContext *ctx)
j_mayer5eb79952007-09-19 05:44:04 +00005904{
5905#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005906 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer5eb79952007-09-19 05:44:04 +00005907#else
aurel3276db3ba2008-12-08 18:11:21 +00005908 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005909 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer5eb79952007-09-19 05:44:04 +00005910 return;
5911 }
5912 switch (rB(ctx->opcode)) {
5913 case 0:
j_mayer5eb79952007-09-19 05:44:04 +00005914 case 1:
j_mayer5eb79952007-09-19 05:44:04 +00005915 case 2:
aurel3274d37792008-12-06 21:46:17 +00005916 {
5917 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
Edgar E. Iglesias58239472011-01-21 23:12:42 +01005918 gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], t0, cpu_gpr[rA(ctx->opcode)]);
aurel3274d37792008-12-06 21:46:17 +00005919 tcg_temp_free_i32(t0);
5920 }
j_mayer5eb79952007-09-19 05:44:04 +00005921 break;
5922 default:
aurel32e06fcd72008-12-11 22:42:14 +00005923 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
j_mayer5eb79952007-09-19 05:44:04 +00005924 break;
5925 }
5926#endif
5927}
5928
5929/* tlbsx - tlbsx. */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00005930static void gen_tlbsx_440(DisasContext *ctx)
j_mayer5eb79952007-09-19 05:44:04 +00005931{
5932#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005933 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer5eb79952007-09-19 05:44:04 +00005934#else
aurel3274d37792008-12-06 21:46:17 +00005935 TCGv t0;
aurel3276db3ba2008-12-08 18:11:21 +00005936 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005937 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer5eb79952007-09-19 05:44:04 +00005938 return;
5939 }
aurel3274d37792008-12-06 21:46:17 +00005940 t0 = tcg_temp_new();
aurel3276db3ba2008-12-08 18:11:21 +00005941 gen_addr_reg_index(ctx, t0);
aurel3274d37792008-12-06 21:46:17 +00005942 gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], t0);
5943 tcg_temp_free(t0);
5944 if (Rc(ctx->opcode)) {
5945 int l1 = gen_new_label();
5946 tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_xer);
5947 tcg_gen_shri_i32(cpu_crf[0], cpu_crf[0], XER_SO);
5948 tcg_gen_andi_i32(cpu_crf[0], cpu_crf[0], 1);
5949 tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
5950 tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
5951 gen_set_label(l1);
5952 }
j_mayer5eb79952007-09-19 05:44:04 +00005953#endif
5954}
5955
5956/* tlbwe */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00005957static void gen_tlbwe_440(DisasContext *ctx)
j_mayer5eb79952007-09-19 05:44:04 +00005958{
5959#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00005960 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer5eb79952007-09-19 05:44:04 +00005961#else
aurel3276db3ba2008-12-08 18:11:21 +00005962 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00005963 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer5eb79952007-09-19 05:44:04 +00005964 return;
5965 }
5966 switch (rB(ctx->opcode)) {
5967 case 0:
j_mayer5eb79952007-09-19 05:44:04 +00005968 case 1:
j_mayer5eb79952007-09-19 05:44:04 +00005969 case 2:
aurel3274d37792008-12-06 21:46:17 +00005970 {
5971 TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
5972 gen_helper_440_tlbwe(t0, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
5973 tcg_temp_free_i32(t0);
5974 }
j_mayer5eb79952007-09-19 05:44:04 +00005975 break;
5976 default:
aurel32e06fcd72008-12-11 22:42:14 +00005977 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
j_mayer5eb79952007-09-19 05:44:04 +00005978 break;
5979 }
5980#endif
5981}
5982
Alexander Graf01662f32011-04-30 23:34:58 +02005983/* TLB management - PowerPC BookE 2.06 implementation */
5984
5985/* tlbre */
5986static void gen_tlbre_booke206(DisasContext *ctx)
5987{
5988#if defined(CONFIG_USER_ONLY)
5989 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5990#else
5991 if (unlikely(!ctx->mem_idx)) {
5992 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5993 return;
5994 }
5995
5996 gen_helper_booke206_tlbre();
5997#endif
5998}
5999
6000/* tlbsx - tlbsx. */
6001static void gen_tlbsx_booke206(DisasContext *ctx)
6002{
6003#if defined(CONFIG_USER_ONLY)
6004 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6005#else
6006 TCGv t0;
6007 if (unlikely(!ctx->mem_idx)) {
6008 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6009 return;
6010 }
6011
6012 if (rA(ctx->opcode)) {
6013 t0 = tcg_temp_new();
6014 tcg_gen_mov_tl(t0, cpu_gpr[rD(ctx->opcode)]);
6015 } else {
6016 t0 = tcg_const_tl(0);
6017 }
6018
6019 tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]);
6020 gen_helper_booke206_tlbsx(t0);
6021#endif
6022}
6023
6024/* tlbwe */
6025static void gen_tlbwe_booke206(DisasContext *ctx)
6026{
6027#if defined(CONFIG_USER_ONLY)
6028 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6029#else
6030 if (unlikely(!ctx->mem_idx)) {
6031 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6032 return;
6033 }
6034 gen_helper_booke206_tlbwe();
6035#endif
6036}
6037
6038static void gen_tlbivax_booke206(DisasContext *ctx)
6039{
6040#if defined(CONFIG_USER_ONLY)
6041 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6042#else
6043 TCGv t0;
6044 if (unlikely(!ctx->mem_idx)) {
6045 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6046 return;
6047 }
6048
6049 t0 = tcg_temp_new();
6050 gen_addr_reg_index(ctx, t0);
6051
6052 gen_helper_booke206_tlbivax(t0);
6053#endif
6054}
6055
6056
j_mayer76a66252007-03-07 08:32:30 +00006057/* wrtee */
Blue Swirl99e300e2009-06-17 15:22:09 +00006058static void gen_wrtee(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00006059{
6060#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00006061 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00006062#else
aurel326527f6e2008-12-06 13:03:35 +00006063 TCGv t0;
aurel3276db3ba2008-12-08 18:11:21 +00006064 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00006065 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00006066 return;
6067 }
aurel326527f6e2008-12-06 13:03:35 +00006068 t0 = tcg_temp_new();
6069 tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE));
6070 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6071 tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
6072 tcg_temp_free(t0);
j_mayerdee96f62007-09-29 15:02:38 +00006073 /* Stop translation to have a chance to raise an exception
6074 * if we just set msr_ee to 1
6075 */
aurel32e06fcd72008-12-11 22:42:14 +00006076 gen_stop_exception(ctx);
j_mayer76a66252007-03-07 08:32:30 +00006077#endif
6078}
6079
6080/* wrteei */
Blue Swirl99e300e2009-06-17 15:22:09 +00006081static void gen_wrteei(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00006082{
6083#if defined(CONFIG_USER_ONLY)
aurel32e06fcd72008-12-11 22:42:14 +00006084 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00006085#else
aurel3276db3ba2008-12-08 18:11:21 +00006086 if (unlikely(!ctx->mem_idx)) {
aurel32e06fcd72008-12-11 22:42:14 +00006087 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
j_mayer76a66252007-03-07 08:32:30 +00006088 return;
6089 }
Baojun Wangfbe73002009-07-03 18:56:57 +08006090 if (ctx->opcode & 0x00008000) {
aurel326527f6e2008-12-06 13:03:35 +00006091 tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE));
6092 /* Stop translation to have a chance to raise an exception */
aurel32e06fcd72008-12-11 22:42:14 +00006093 gen_stop_exception(ctx);
aurel326527f6e2008-12-06 13:03:35 +00006094 } else {
aurel321b6e5f92009-01-14 19:40:54 +00006095 tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
aurel326527f6e2008-12-06 13:03:35 +00006096 }
j_mayer76a66252007-03-07 08:32:30 +00006097#endif
6098}
6099
j_mayer08e46e52007-04-16 07:18:42 +00006100/* PowerPC 440 specific instructions */
Blue Swirl99e300e2009-06-17 15:22:09 +00006101
Blue Swirl54623272009-06-17 15:22:19 +00006102/* dlmzb */
Blue Swirl99e300e2009-06-17 15:22:09 +00006103static void gen_dlmzb(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00006104{
aurel32ef0d51a2008-11-30 17:26:29 +00006105 TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode));
6106 gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)],
6107 cpu_gpr[rB(ctx->opcode)], t0);
6108 tcg_temp_free_i32(t0);
j_mayer76a66252007-03-07 08:32:30 +00006109}
6110
6111/* mbar replaces eieio on 440 */
Blue Swirl99e300e2009-06-17 15:22:09 +00006112static void gen_mbar(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00006113{
6114 /* interpreted as no-op */
6115}
6116
6117/* msync replaces sync on 440 */
Blue Swirl99e300e2009-06-17 15:22:09 +00006118static void gen_msync(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00006119{
6120 /* interpreted as no-op */
6121}
6122
6123/* icbt */
Blue Swirle8eaa2c2009-06-17 15:22:14 +00006124static void gen_icbt_440(DisasContext *ctx)
j_mayer76a66252007-03-07 08:32:30 +00006125{
6126 /* interpreted as no-op */
6127 /* XXX: specification say this is treated as a load by the MMU
6128 * but does not generate any exception
6129 */
6130}
6131
j_mayera9d9eb82007-10-07 18:19:26 +00006132/*** Altivec vector extension ***/
6133/* Altivec registers moves */
j_mayera9d9eb82007-10-07 18:19:26 +00006134
Blue Swirl636aa202009-08-16 09:06:54 +00006135static inline TCGv_ptr gen_avr_ptr(int reg)
aurel32564e5712008-12-18 22:51:31 +00006136{
aurel32e4704b32009-01-03 13:31:10 +00006137 TCGv_ptr r = tcg_temp_new_ptr();
aurel32564e5712008-12-18 22:51:31 +00006138 tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg]));
6139 return r;
6140}
6141
j_mayera9d9eb82007-10-07 18:19:26 +00006142#define GEN_VR_LDX(name, opc2, opc3) \
Blue Swirl99e300e2009-06-17 15:22:09 +00006143static void glue(gen_, name)(DisasContext *ctx) \
j_mayera9d9eb82007-10-07 18:19:26 +00006144{ \
aurel32fe1e5c52008-11-24 08:47:21 +00006145 TCGv EA; \
j_mayera9d9eb82007-10-07 18:19:26 +00006146 if (unlikely(!ctx->altivec_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00006147 gen_exception(ctx, POWERPC_EXCP_VPU); \
j_mayera9d9eb82007-10-07 18:19:26 +00006148 return; \
6149 } \
aurel3276db3ba2008-12-08 18:11:21 +00006150 gen_set_access_type(ctx, ACCESS_INT); \
aurel32fe1e5c52008-11-24 08:47:21 +00006151 EA = tcg_temp_new(); \
aurel3276db3ba2008-12-08 18:11:21 +00006152 gen_addr_reg_index(ctx, EA); \
aurel32fe1e5c52008-11-24 08:47:21 +00006153 tcg_gen_andi_tl(EA, EA, ~0xf); \
aurel3276db3ba2008-12-08 18:11:21 +00006154 if (ctx->le_mode) { \
6155 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
aurel32fe1e5c52008-11-24 08:47:21 +00006156 tcg_gen_addi_tl(EA, EA, 8); \
aurel3276db3ba2008-12-08 18:11:21 +00006157 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
aurel32fe1e5c52008-11-24 08:47:21 +00006158 } else { \
aurel3276db3ba2008-12-08 18:11:21 +00006159 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
aurel32fe1e5c52008-11-24 08:47:21 +00006160 tcg_gen_addi_tl(EA, EA, 8); \
aurel3276db3ba2008-12-08 18:11:21 +00006161 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
aurel32fe1e5c52008-11-24 08:47:21 +00006162 } \
6163 tcg_temp_free(EA); \
j_mayera9d9eb82007-10-07 18:19:26 +00006164}
6165
6166#define GEN_VR_STX(name, opc2, opc3) \
Blue Swirl99e300e2009-06-17 15:22:09 +00006167static void gen_st##name(DisasContext *ctx) \
j_mayera9d9eb82007-10-07 18:19:26 +00006168{ \
aurel32fe1e5c52008-11-24 08:47:21 +00006169 TCGv EA; \
j_mayera9d9eb82007-10-07 18:19:26 +00006170 if (unlikely(!ctx->altivec_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00006171 gen_exception(ctx, POWERPC_EXCP_VPU); \
j_mayera9d9eb82007-10-07 18:19:26 +00006172 return; \
6173 } \
aurel3276db3ba2008-12-08 18:11:21 +00006174 gen_set_access_type(ctx, ACCESS_INT); \
aurel32fe1e5c52008-11-24 08:47:21 +00006175 EA = tcg_temp_new(); \
aurel3276db3ba2008-12-08 18:11:21 +00006176 gen_addr_reg_index(ctx, EA); \
aurel32fe1e5c52008-11-24 08:47:21 +00006177 tcg_gen_andi_tl(EA, EA, ~0xf); \
aurel3276db3ba2008-12-08 18:11:21 +00006178 if (ctx->le_mode) { \
6179 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
aurel32fe1e5c52008-11-24 08:47:21 +00006180 tcg_gen_addi_tl(EA, EA, 8); \
aurel3276db3ba2008-12-08 18:11:21 +00006181 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
aurel32fe1e5c52008-11-24 08:47:21 +00006182 } else { \
aurel3276db3ba2008-12-08 18:11:21 +00006183 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
aurel32fe1e5c52008-11-24 08:47:21 +00006184 tcg_gen_addi_tl(EA, EA, 8); \
aurel3276db3ba2008-12-08 18:11:21 +00006185 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
aurel32fe1e5c52008-11-24 08:47:21 +00006186 } \
6187 tcg_temp_free(EA); \
j_mayera9d9eb82007-10-07 18:19:26 +00006188}
6189
aurel32cbfb6ae2009-01-04 22:13:10 +00006190#define GEN_VR_LVE(name, opc2, opc3) \
Blue Swirl99e300e2009-06-17 15:22:09 +00006191static void gen_lve##name(DisasContext *ctx) \
aurel32cbfb6ae2009-01-04 22:13:10 +00006192 { \
6193 TCGv EA; \
6194 TCGv_ptr rs; \
6195 if (unlikely(!ctx->altivec_enabled)) { \
6196 gen_exception(ctx, POWERPC_EXCP_VPU); \
6197 return; \
6198 } \
6199 gen_set_access_type(ctx, ACCESS_INT); \
6200 EA = tcg_temp_new(); \
6201 gen_addr_reg_index(ctx, EA); \
6202 rs = gen_avr_ptr(rS(ctx->opcode)); \
6203 gen_helper_lve##name (rs, EA); \
6204 tcg_temp_free(EA); \
6205 tcg_temp_free_ptr(rs); \
6206 }
6207
6208#define GEN_VR_STVE(name, opc2, opc3) \
Blue Swirl99e300e2009-06-17 15:22:09 +00006209static void gen_stve##name(DisasContext *ctx) \
aurel32cbfb6ae2009-01-04 22:13:10 +00006210 { \
6211 TCGv EA; \
6212 TCGv_ptr rs; \
6213 if (unlikely(!ctx->altivec_enabled)) { \
6214 gen_exception(ctx, POWERPC_EXCP_VPU); \
6215 return; \
6216 } \
6217 gen_set_access_type(ctx, ACCESS_INT); \
6218 EA = tcg_temp_new(); \
6219 gen_addr_reg_index(ctx, EA); \
6220 rs = gen_avr_ptr(rS(ctx->opcode)); \
6221 gen_helper_stve##name (rs, EA); \
6222 tcg_temp_free(EA); \
6223 tcg_temp_free_ptr(rs); \
6224 }
6225
aurel32fe1e5c52008-11-24 08:47:21 +00006226GEN_VR_LDX(lvx, 0x07, 0x03);
j_mayera9d9eb82007-10-07 18:19:26 +00006227/* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
aurel32fe1e5c52008-11-24 08:47:21 +00006228GEN_VR_LDX(lvxl, 0x07, 0x0B);
j_mayera9d9eb82007-10-07 18:19:26 +00006229
aurel32cbfb6ae2009-01-04 22:13:10 +00006230GEN_VR_LVE(bx, 0x07, 0x00);
6231GEN_VR_LVE(hx, 0x07, 0x01);
6232GEN_VR_LVE(wx, 0x07, 0x02);
6233
aurel32fe1e5c52008-11-24 08:47:21 +00006234GEN_VR_STX(svx, 0x07, 0x07);
j_mayera9d9eb82007-10-07 18:19:26 +00006235/* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
aurel32fe1e5c52008-11-24 08:47:21 +00006236GEN_VR_STX(svxl, 0x07, 0x0F);
j_mayera9d9eb82007-10-07 18:19:26 +00006237
aurel32cbfb6ae2009-01-04 22:13:10 +00006238GEN_VR_STVE(bx, 0x07, 0x04);
6239GEN_VR_STVE(hx, 0x07, 0x05);
6240GEN_VR_STVE(wx, 0x07, 0x06);
6241
Blue Swirl99e300e2009-06-17 15:22:09 +00006242static void gen_lvsl(DisasContext *ctx)
aurel32bf8d8de2009-01-04 22:09:42 +00006243{
6244 TCGv_ptr rd;
6245 TCGv EA;
6246 if (unlikely(!ctx->altivec_enabled)) {
6247 gen_exception(ctx, POWERPC_EXCP_VPU);
6248 return;
6249 }
6250 EA = tcg_temp_new();
6251 gen_addr_reg_index(ctx, EA);
6252 rd = gen_avr_ptr(rD(ctx->opcode));
6253 gen_helper_lvsl(rd, EA);
6254 tcg_temp_free(EA);
6255 tcg_temp_free_ptr(rd);
6256}
6257
Blue Swirl99e300e2009-06-17 15:22:09 +00006258static void gen_lvsr(DisasContext *ctx)
aurel32bf8d8de2009-01-04 22:09:42 +00006259{
6260 TCGv_ptr rd;
6261 TCGv EA;
6262 if (unlikely(!ctx->altivec_enabled)) {
6263 gen_exception(ctx, POWERPC_EXCP_VPU);
6264 return;
6265 }
6266 EA = tcg_temp_new();
6267 gen_addr_reg_index(ctx, EA);
6268 rd = gen_avr_ptr(rD(ctx->opcode));
6269 gen_helper_lvsr(rd, EA);
6270 tcg_temp_free(EA);
6271 tcg_temp_free_ptr(rd);
6272}
6273
Blue Swirl99e300e2009-06-17 15:22:09 +00006274static void gen_mfvscr(DisasContext *ctx)
aurel32785f4512009-01-04 22:51:59 +00006275{
6276 TCGv_i32 t;
6277 if (unlikely(!ctx->altivec_enabled)) {
6278 gen_exception(ctx, POWERPC_EXCP_VPU);
6279 return;
6280 }
6281 tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0);
6282 t = tcg_temp_new_i32();
6283 tcg_gen_ld_i32(t, cpu_env, offsetof(CPUState, vscr));
6284 tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t);
aurel32fce5ecb2009-02-03 19:55:13 +00006285 tcg_temp_free_i32(t);
aurel32785f4512009-01-04 22:51:59 +00006286}
6287
Blue Swirl99e300e2009-06-17 15:22:09 +00006288static void gen_mtvscr(DisasContext *ctx)
aurel32785f4512009-01-04 22:51:59 +00006289{
aurel326e87b7c2009-02-03 19:56:09 +00006290 TCGv_ptr p;
aurel32785f4512009-01-04 22:51:59 +00006291 if (unlikely(!ctx->altivec_enabled)) {
6292 gen_exception(ctx, POWERPC_EXCP_VPU);
6293 return;
6294 }
aurel326e87b7c2009-02-03 19:56:09 +00006295 p = gen_avr_ptr(rD(ctx->opcode));
6296 gen_helper_mtvscr(p);
6297 tcg_temp_free_ptr(p);
aurel32785f4512009-01-04 22:51:59 +00006298}
6299
aurel327a9b96c2008-12-18 22:42:58 +00006300/* Logical operations */
6301#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
Blue Swirl99e300e2009-06-17 15:22:09 +00006302static void glue(gen_, name)(DisasContext *ctx) \
aurel327a9b96c2008-12-18 22:42:58 +00006303{ \
6304 if (unlikely(!ctx->altivec_enabled)) { \
6305 gen_exception(ctx, POWERPC_EXCP_VPU); \
6306 return; \
6307 } \
6308 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6309 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6310}
6311
6312GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16);
6313GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17);
6314GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18);
6315GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19);
6316GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20);
6317
aurel328e27dd62009-01-03 13:31:30 +00006318#define GEN_VXFORM(name, opc2, opc3) \
Blue Swirl99e300e2009-06-17 15:22:09 +00006319static void glue(gen_, name)(DisasContext *ctx) \
aurel328e27dd62009-01-03 13:31:30 +00006320{ \
6321 TCGv_ptr ra, rb, rd; \
6322 if (unlikely(!ctx->altivec_enabled)) { \
6323 gen_exception(ctx, POWERPC_EXCP_VPU); \
6324 return; \
6325 } \
6326 ra = gen_avr_ptr(rA(ctx->opcode)); \
6327 rb = gen_avr_ptr(rB(ctx->opcode)); \
6328 rd = gen_avr_ptr(rD(ctx->opcode)); \
6329 gen_helper_##name (rd, ra, rb); \
6330 tcg_temp_free_ptr(ra); \
6331 tcg_temp_free_ptr(rb); \
6332 tcg_temp_free_ptr(rd); \
6333}
6334
aurel327872c512009-01-03 13:31:40 +00006335GEN_VXFORM(vaddubm, 0, 0);
6336GEN_VXFORM(vadduhm, 0, 1);
6337GEN_VXFORM(vadduwm, 0, 2);
6338GEN_VXFORM(vsububm, 0, 16);
6339GEN_VXFORM(vsubuhm, 0, 17);
6340GEN_VXFORM(vsubuwm, 0, 18);
aurel32e4039332009-01-03 13:31:58 +00006341GEN_VXFORM(vmaxub, 1, 0);
6342GEN_VXFORM(vmaxuh, 1, 1);
6343GEN_VXFORM(vmaxuw, 1, 2);
6344GEN_VXFORM(vmaxsb, 1, 4);
6345GEN_VXFORM(vmaxsh, 1, 5);
6346GEN_VXFORM(vmaxsw, 1, 6);
6347GEN_VXFORM(vminub, 1, 8);
6348GEN_VXFORM(vminuh, 1, 9);
6349GEN_VXFORM(vminuw, 1, 10);
6350GEN_VXFORM(vminsb, 1, 12);
6351GEN_VXFORM(vminsh, 1, 13);
6352GEN_VXFORM(vminsw, 1, 14);
aurel32fab3cbe2009-01-03 13:31:49 +00006353GEN_VXFORM(vavgub, 1, 16);
6354GEN_VXFORM(vavguh, 1, 17);
6355GEN_VXFORM(vavguw, 1, 18);
6356GEN_VXFORM(vavgsb, 1, 20);
6357GEN_VXFORM(vavgsh, 1, 21);
6358GEN_VXFORM(vavgsw, 1, 22);
aurel323b430042009-01-04 22:08:38 +00006359GEN_VXFORM(vmrghb, 6, 0);
6360GEN_VXFORM(vmrghh, 6, 1);
6361GEN_VXFORM(vmrghw, 6, 2);
6362GEN_VXFORM(vmrglb, 6, 4);
6363GEN_VXFORM(vmrglh, 6, 5);
6364GEN_VXFORM(vmrglw, 6, 6);
aurel322c277902009-01-04 22:08:48 +00006365GEN_VXFORM(vmuloub, 4, 0);
6366GEN_VXFORM(vmulouh, 4, 1);
6367GEN_VXFORM(vmulosb, 4, 4);
6368GEN_VXFORM(vmulosh, 4, 5);
6369GEN_VXFORM(vmuleub, 4, 8);
6370GEN_VXFORM(vmuleuh, 4, 9);
6371GEN_VXFORM(vmulesb, 4, 12);
6372GEN_VXFORM(vmulesh, 4, 13);
aurel32d79f0802009-01-04 22:09:08 +00006373GEN_VXFORM(vslb, 2, 4);
6374GEN_VXFORM(vslh, 2, 5);
6375GEN_VXFORM(vslw, 2, 6);
aurel3207ef34c2009-01-04 22:08:58 +00006376GEN_VXFORM(vsrb, 2, 8);
6377GEN_VXFORM(vsrh, 2, 9);
6378GEN_VXFORM(vsrw, 2, 10);
6379GEN_VXFORM(vsrab, 2, 12);
6380GEN_VXFORM(vsrah, 2, 13);
6381GEN_VXFORM(vsraw, 2, 14);
aurel327b239be2009-01-04 22:09:19 +00006382GEN_VXFORM(vslo, 6, 16);
6383GEN_VXFORM(vsro, 6, 17);
aurel32e343da72009-01-04 22:09:31 +00006384GEN_VXFORM(vaddcuw, 0, 6);
6385GEN_VXFORM(vsubcuw, 0, 22);
aurel325ab09f32009-01-08 23:19:50 +00006386GEN_VXFORM(vaddubs, 0, 8);
6387GEN_VXFORM(vadduhs, 0, 9);
6388GEN_VXFORM(vadduws, 0, 10);
6389GEN_VXFORM(vaddsbs, 0, 12);
6390GEN_VXFORM(vaddshs, 0, 13);
6391GEN_VXFORM(vaddsws, 0, 14);
6392GEN_VXFORM(vsububs, 0, 24);
6393GEN_VXFORM(vsubuhs, 0, 25);
6394GEN_VXFORM(vsubuws, 0, 26);
6395GEN_VXFORM(vsubsbs, 0, 28);
6396GEN_VXFORM(vsubshs, 0, 29);
6397GEN_VXFORM(vsubsws, 0, 30);
aurel325e1d0982009-01-04 22:09:52 +00006398GEN_VXFORM(vrlb, 2, 0);
6399GEN_VXFORM(vrlh, 2, 1);
6400GEN_VXFORM(vrlw, 2, 2);
aurel32d9430ad2009-01-08 18:54:48 +00006401GEN_VXFORM(vsl, 2, 7);
6402GEN_VXFORM(vsr, 2, 11);
aurel325335a142009-01-04 22:12:09 +00006403GEN_VXFORM(vpkuhum, 7, 0);
6404GEN_VXFORM(vpkuwum, 7, 1);
6405GEN_VXFORM(vpkuhus, 7, 2);
6406GEN_VXFORM(vpkuwus, 7, 3);
6407GEN_VXFORM(vpkshus, 7, 4);
6408GEN_VXFORM(vpkswus, 7, 5);
6409GEN_VXFORM(vpkshss, 7, 6);
6410GEN_VXFORM(vpkswss, 7, 7);
aurel321dd9ffb2009-01-04 22:12:19 +00006411GEN_VXFORM(vpkpx, 7, 12);
aurel328142cdd2009-01-04 22:13:21 +00006412GEN_VXFORM(vsum4ubs, 4, 24);
6413GEN_VXFORM(vsum4sbs, 4, 28);
6414GEN_VXFORM(vsum4shs, 4, 25);
6415GEN_VXFORM(vsum2sws, 4, 26);
6416GEN_VXFORM(vsumsws, 4, 30);
aurel3256fdd212009-02-09 16:48:51 +00006417GEN_VXFORM(vaddfp, 5, 0);
6418GEN_VXFORM(vsubfp, 5, 1);
aurel321536ff62009-02-09 16:48:39 +00006419GEN_VXFORM(vmaxfp, 5, 16);
6420GEN_VXFORM(vminfp, 5, 17);
aurel32fab3cbe2009-01-03 13:31:49 +00006421
aurel320cbcd902009-01-08 18:54:26 +00006422#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
Blue Swirle8eaa2c2009-06-17 15:22:14 +00006423static void glue(gen_, name)(DisasContext *ctx) \
aurel320cbcd902009-01-08 18:54:26 +00006424 { \
6425 TCGv_ptr ra, rb, rd; \
6426 if (unlikely(!ctx->altivec_enabled)) { \
6427 gen_exception(ctx, POWERPC_EXCP_VPU); \
6428 return; \
6429 } \
6430 ra = gen_avr_ptr(rA(ctx->opcode)); \
6431 rb = gen_avr_ptr(rB(ctx->opcode)); \
6432 rd = gen_avr_ptr(rD(ctx->opcode)); \
6433 gen_helper_##opname (rd, ra, rb); \
6434 tcg_temp_free_ptr(ra); \
6435 tcg_temp_free_ptr(rb); \
6436 tcg_temp_free_ptr(rd); \
6437 }
6438
6439#define GEN_VXRFORM(name, opc2, opc3) \
6440 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
6441 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
6442
aurel321add6e22009-01-08 18:54:38 +00006443GEN_VXRFORM(vcmpequb, 3, 0)
6444GEN_VXRFORM(vcmpequh, 3, 1)
6445GEN_VXRFORM(vcmpequw, 3, 2)
6446GEN_VXRFORM(vcmpgtsb, 3, 12)
6447GEN_VXRFORM(vcmpgtsh, 3, 13)
6448GEN_VXRFORM(vcmpgtsw, 3, 14)
6449GEN_VXRFORM(vcmpgtub, 3, 8)
6450GEN_VXRFORM(vcmpgtuh, 3, 9)
6451GEN_VXRFORM(vcmpgtuw, 3, 10)
aurel32819ca122009-02-09 16:49:10 +00006452GEN_VXRFORM(vcmpeqfp, 3, 3)
6453GEN_VXRFORM(vcmpgefp, 3, 7)
6454GEN_VXRFORM(vcmpgtfp, 3, 11)
6455GEN_VXRFORM(vcmpbfp, 3, 15)
aurel321add6e22009-01-08 18:54:38 +00006456
aurel32c0267662009-01-08 18:54:57 +00006457#define GEN_VXFORM_SIMM(name, opc2, opc3) \
Blue Swirl99e300e2009-06-17 15:22:09 +00006458static void glue(gen_, name)(DisasContext *ctx) \
aurel32c0267662009-01-08 18:54:57 +00006459 { \
6460 TCGv_ptr rd; \
6461 TCGv_i32 simm; \
6462 if (unlikely(!ctx->altivec_enabled)) { \
6463 gen_exception(ctx, POWERPC_EXCP_VPU); \
6464 return; \
6465 } \
6466 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6467 rd = gen_avr_ptr(rD(ctx->opcode)); \
6468 gen_helper_##name (rd, simm); \
6469 tcg_temp_free_i32(simm); \
6470 tcg_temp_free_ptr(rd); \
6471 }
6472
6473GEN_VXFORM_SIMM(vspltisb, 6, 12);
6474GEN_VXFORM_SIMM(vspltish, 6, 13);
6475GEN_VXFORM_SIMM(vspltisw, 6, 14);
6476
aurel32de5f2482009-01-04 22:10:59 +00006477#define GEN_VXFORM_NOA(name, opc2, opc3) \
Blue Swirl99e300e2009-06-17 15:22:09 +00006478static void glue(gen_, name)(DisasContext *ctx) \
aurel32de5f2482009-01-04 22:10:59 +00006479 { \
6480 TCGv_ptr rb, rd; \
6481 if (unlikely(!ctx->altivec_enabled)) { \
6482 gen_exception(ctx, POWERPC_EXCP_VPU); \
6483 return; \
6484 } \
6485 rb = gen_avr_ptr(rB(ctx->opcode)); \
6486 rd = gen_avr_ptr(rD(ctx->opcode)); \
6487 gen_helper_##name (rd, rb); \
6488 tcg_temp_free_ptr(rb); \
6489 tcg_temp_free_ptr(rd); \
6490 }
6491
aurel326cf1c6e2009-01-04 22:11:20 +00006492GEN_VXFORM_NOA(vupkhsb, 7, 8);
6493GEN_VXFORM_NOA(vupkhsh, 7, 9);
6494GEN_VXFORM_NOA(vupklsb, 7, 10);
6495GEN_VXFORM_NOA(vupklsh, 7, 11);
aurel3279f85c32009-01-04 22:11:10 +00006496GEN_VXFORM_NOA(vupkhpx, 7, 13);
6497GEN_VXFORM_NOA(vupklpx, 7, 15);
aurel32bdfbac32009-02-09 16:49:29 +00006498GEN_VXFORM_NOA(vrefp, 5, 4);
aurel32071fc3b2009-02-09 16:49:40 +00006499GEN_VXFORM_NOA(vrsqrtefp, 5, 5);
Aurelien Jarno0bffbc62009-02-09 12:20:50 +01006500GEN_VXFORM_NOA(vexptefp, 5, 6);
aurel32b5807632009-02-05 22:33:36 +00006501GEN_VXFORM_NOA(vlogefp, 5, 7);
aurel32f6b19642009-02-04 13:52:03 +00006502GEN_VXFORM_NOA(vrfim, 5, 8);
6503GEN_VXFORM_NOA(vrfin, 5, 9);
6504GEN_VXFORM_NOA(vrfip, 5, 10);
6505GEN_VXFORM_NOA(vrfiz, 5, 11);
aurel3279f85c32009-01-04 22:11:10 +00006506
aurel3221d21582009-01-04 22:10:28 +00006507#define GEN_VXFORM_SIMM(name, opc2, opc3) \
Blue Swirl99e300e2009-06-17 15:22:09 +00006508static void glue(gen_, name)(DisasContext *ctx) \
aurel3221d21582009-01-04 22:10:28 +00006509 { \
6510 TCGv_ptr rd; \
6511 TCGv_i32 simm; \
6512 if (unlikely(!ctx->altivec_enabled)) { \
6513 gen_exception(ctx, POWERPC_EXCP_VPU); \
6514 return; \
6515 } \
6516 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6517 rd = gen_avr_ptr(rD(ctx->opcode)); \
6518 gen_helper_##name (rd, simm); \
6519 tcg_temp_free_i32(simm); \
6520 tcg_temp_free_ptr(rd); \
6521 }
6522
aurel3227a4edb2009-01-04 22:10:40 +00006523#define GEN_VXFORM_UIMM(name, opc2, opc3) \
Blue Swirl99e300e2009-06-17 15:22:09 +00006524static void glue(gen_, name)(DisasContext *ctx) \
aurel3227a4edb2009-01-04 22:10:40 +00006525 { \
6526 TCGv_ptr rb, rd; \
6527 TCGv_i32 uimm; \
6528 if (unlikely(!ctx->altivec_enabled)) { \
6529 gen_exception(ctx, POWERPC_EXCP_VPU); \
6530 return; \
6531 } \
6532 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6533 rb = gen_avr_ptr(rB(ctx->opcode)); \
6534 rd = gen_avr_ptr(rD(ctx->opcode)); \
6535 gen_helper_##name (rd, rb, uimm); \
6536 tcg_temp_free_i32(uimm); \
6537 tcg_temp_free_ptr(rb); \
6538 tcg_temp_free_ptr(rd); \
6539 }
6540
aurel32e4e6bee2009-01-04 22:10:49 +00006541GEN_VXFORM_UIMM(vspltb, 6, 8);
6542GEN_VXFORM_UIMM(vsplth, 6, 9);
6543GEN_VXFORM_UIMM(vspltw, 6, 10);
aurel32e1406322009-02-04 13:52:17 +00006544GEN_VXFORM_UIMM(vcfux, 5, 12);
6545GEN_VXFORM_UIMM(vcfsx, 5, 13);
aurel32875b31d2009-02-09 16:49:20 +00006546GEN_VXFORM_UIMM(vctuxs, 5, 14);
6547GEN_VXFORM_UIMM(vctsxs, 5, 15);
aurel32e4e6bee2009-01-04 22:10:49 +00006548
Blue Swirl99e300e2009-06-17 15:22:09 +00006549static void gen_vsldoi(DisasContext *ctx)
aurel32cd633b12009-01-04 22:10:09 +00006550{
6551 TCGv_ptr ra, rb, rd;
aurel32fce5ecb2009-02-03 19:55:13 +00006552 TCGv_i32 sh;
aurel32cd633b12009-01-04 22:10:09 +00006553 if (unlikely(!ctx->altivec_enabled)) {
6554 gen_exception(ctx, POWERPC_EXCP_VPU);
6555 return;
6556 }
6557 ra = gen_avr_ptr(rA(ctx->opcode));
6558 rb = gen_avr_ptr(rB(ctx->opcode));
6559 rd = gen_avr_ptr(rD(ctx->opcode));
6560 sh = tcg_const_i32(VSH(ctx->opcode));
6561 gen_helper_vsldoi (rd, ra, rb, sh);
6562 tcg_temp_free_ptr(ra);
6563 tcg_temp_free_ptr(rb);
6564 tcg_temp_free_ptr(rd);
aurel32fce5ecb2009-02-03 19:55:13 +00006565 tcg_temp_free_i32(sh);
aurel32cd633b12009-01-04 22:10:09 +00006566}
6567
aurel32707cec32009-01-04 22:11:29 +00006568#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
Blue Swirl99e300e2009-06-17 15:22:09 +00006569static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
aurel32707cec32009-01-04 22:11:29 +00006570 { \
6571 TCGv_ptr ra, rb, rc, rd; \
6572 if (unlikely(!ctx->altivec_enabled)) { \
6573 gen_exception(ctx, POWERPC_EXCP_VPU); \
6574 return; \
6575 } \
6576 ra = gen_avr_ptr(rA(ctx->opcode)); \
6577 rb = gen_avr_ptr(rB(ctx->opcode)); \
6578 rc = gen_avr_ptr(rC(ctx->opcode)); \
6579 rd = gen_avr_ptr(rD(ctx->opcode)); \
6580 if (Rc(ctx->opcode)) { \
6581 gen_helper_##name1 (rd, ra, rb, rc); \
6582 } else { \
6583 gen_helper_##name0 (rd, ra, rb, rc); \
6584 } \
6585 tcg_temp_free_ptr(ra); \
6586 tcg_temp_free_ptr(rb); \
6587 tcg_temp_free_ptr(rc); \
6588 tcg_temp_free_ptr(rd); \
6589 }
6590
aurel32b161ae22009-01-04 22:12:29 +00006591GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16)
6592
Blue Swirl99e300e2009-06-17 15:22:09 +00006593static void gen_vmladduhm(DisasContext *ctx)
aurel32bcd2ee22009-01-04 22:13:00 +00006594{
6595 TCGv_ptr ra, rb, rc, rd;
6596 if (unlikely(!ctx->altivec_enabled)) {
6597 gen_exception(ctx, POWERPC_EXCP_VPU);
6598 return;
6599 }
6600 ra = gen_avr_ptr(rA(ctx->opcode));
6601 rb = gen_avr_ptr(rB(ctx->opcode));
6602 rc = gen_avr_ptr(rC(ctx->opcode));
6603 rd = gen_avr_ptr(rD(ctx->opcode));
6604 gen_helper_vmladduhm(rd, ra, rb, rc);
6605 tcg_temp_free_ptr(ra);
6606 tcg_temp_free_ptr(rb);
6607 tcg_temp_free_ptr(rc);
6608 tcg_temp_free_ptr(rd);
6609}
6610
aurel32b04ae982009-01-04 22:11:39 +00006611GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18)
aurel324d9903b2009-01-04 22:12:39 +00006612GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19)
aurel32eae07262009-01-04 22:12:49 +00006613GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20)
aurel32d1258692009-01-04 22:11:49 +00006614GEN_VAFORM_PAIRED(vsel, vperm, 21)
aurel3235cf7c72009-02-09 16:48:59 +00006615GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23)
aurel32b04ae982009-01-04 22:11:39 +00006616
j_mayer0487d6a2007-03-20 22:11:31 +00006617/*** SPE extension ***/
j_mayer0487d6a2007-03-20 22:11:31 +00006618/* Register moves */
j_mayer3cd7d1d2007-11-12 01:56:18 +00006619
Fabien Chouteaua0e13902011-03-16 11:21:22 +01006620
6621static inline void gen_evmra(DisasContext *ctx)
6622{
6623
6624 if (unlikely(!ctx->spe_enabled)) {
6625 gen_exception(ctx, POWERPC_EXCP_APU);
6626 return;
6627 }
6628
6629#if defined(TARGET_PPC64)
6630 /* rD := rA */
6631 tcg_gen_mov_i64(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
6632
6633 /* spe_acc := rA */
6634 tcg_gen_st_i64(cpu_gpr[rA(ctx->opcode)],
6635 cpu_env,
6636 offsetof(CPUState, spe_acc));
6637#else
6638 TCGv_i64 tmp = tcg_temp_new_i64();
6639
6640 /* tmp := rA_lo + rA_hi << 32 */
6641 tcg_gen_concat_i32_i64(tmp, cpu_gpr[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
6642
6643 /* spe_acc := tmp */
6644 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUState, spe_acc));
6645 tcg_temp_free_i64(tmp);
6646
6647 /* rD := rA */
6648 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
6649 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
6650#endif
6651}
6652
Blue Swirl636aa202009-08-16 09:06:54 +00006653static inline void gen_load_gpr64(TCGv_i64 t, int reg)
6654{
aurel32f78fb442008-09-04 05:25:47 +00006655#if defined(TARGET_PPC64)
6656 tcg_gen_mov_i64(t, cpu_gpr[reg]);
6657#else
pbrook36aa55d2008-09-21 13:48:32 +00006658 tcg_gen_concat_i32_i64(t, cpu_gpr[reg], cpu_gprh[reg]);
j_mayer0487d6a2007-03-20 22:11:31 +00006659#endif
aurel32f78fb442008-09-04 05:25:47 +00006660}
j_mayer0487d6a2007-03-20 22:11:31 +00006661
Blue Swirl636aa202009-08-16 09:06:54 +00006662static inline void gen_store_gpr64(int reg, TCGv_i64 t)
6663{
aurel32f78fb442008-09-04 05:25:47 +00006664#if defined(TARGET_PPC64)
6665 tcg_gen_mov_i64(cpu_gpr[reg], t);
6666#else
pbrooka7812ae2008-11-17 14:43:54 +00006667 TCGv_i64 tmp = tcg_temp_new_i64();
aurel32f78fb442008-09-04 05:25:47 +00006668 tcg_gen_trunc_i64_i32(cpu_gpr[reg], t);
aurel32f78fb442008-09-04 05:25:47 +00006669 tcg_gen_shri_i64(tmp, t, 32);
6670 tcg_gen_trunc_i64_i32(cpu_gprh[reg], tmp);
pbrooka7812ae2008-11-17 14:43:54 +00006671 tcg_temp_free_i64(tmp);
j_mayer0487d6a2007-03-20 22:11:31 +00006672#endif
aurel32f78fb442008-09-04 05:25:47 +00006673}
j_mayer3cd7d1d2007-11-12 01:56:18 +00006674
j_mayer0487d6a2007-03-20 22:11:31 +00006675#define GEN_SPE(name0, name1, opc2, opc3, inval, type) \
Blue Swirl99e300e2009-06-17 15:22:09 +00006676static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
j_mayer0487d6a2007-03-20 22:11:31 +00006677{ \
6678 if (Rc(ctx->opcode)) \
6679 gen_##name1(ctx); \
6680 else \
6681 gen_##name0(ctx); \
6682}
6683
6684/* Handler for undefined SPE opcodes */
Blue Swirl636aa202009-08-16 09:06:54 +00006685static inline void gen_speundef(DisasContext *ctx)
j_mayer0487d6a2007-03-20 22:11:31 +00006686{
aurel32e06fcd72008-12-11 22:42:14 +00006687 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
j_mayer0487d6a2007-03-20 22:11:31 +00006688}
6689
aurel3257951c22008-11-10 11:10:23 +00006690/* SPE logic */
6691#if defined(TARGET_PPC64)
6692#define GEN_SPEOP_LOGIC2(name, tcg_op) \
Blue Swirl636aa202009-08-16 09:06:54 +00006693static inline void gen_##name(DisasContext *ctx) \
j_mayer0487d6a2007-03-20 22:11:31 +00006694{ \
6695 if (unlikely(!ctx->spe_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00006696 gen_exception(ctx, POWERPC_EXCP_APU); \
j_mayer0487d6a2007-03-20 22:11:31 +00006697 return; \
6698 } \
aurel3257951c22008-11-10 11:10:23 +00006699 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6700 cpu_gpr[rB(ctx->opcode)]); \
j_mayer0487d6a2007-03-20 22:11:31 +00006701}
aurel3257951c22008-11-10 11:10:23 +00006702#else
6703#define GEN_SPEOP_LOGIC2(name, tcg_op) \
Blue Swirl636aa202009-08-16 09:06:54 +00006704static inline void gen_##name(DisasContext *ctx) \
aurel323d3a6a02008-10-15 17:00:45 +00006705{ \
6706 if (unlikely(!ctx->spe_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00006707 gen_exception(ctx, POWERPC_EXCP_APU); \
aurel323d3a6a02008-10-15 17:00:45 +00006708 return; \
6709 } \
aurel3257951c22008-11-10 11:10:23 +00006710 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6711 cpu_gpr[rB(ctx->opcode)]); \
6712 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6713 cpu_gprh[rB(ctx->opcode)]); \
6714}
6715#endif
6716
6717GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl);
6718GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl);
6719GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl);
6720GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl);
6721GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl);
6722GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl);
6723GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl);
6724GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl);
6725
6726/* SPE logic immediate */
6727#if defined(TARGET_PPC64)
6728#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
Blue Swirl636aa202009-08-16 09:06:54 +00006729static inline void gen_##name(DisasContext *ctx) \
aurel3257951c22008-11-10 11:10:23 +00006730{ \
6731 if (unlikely(!ctx->spe_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00006732 gen_exception(ctx, POWERPC_EXCP_APU); \
aurel3257951c22008-11-10 11:10:23 +00006733 return; \
6734 } \
pbrooka7812ae2008-11-17 14:43:54 +00006735 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6736 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6737 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
aurel3257951c22008-11-10 11:10:23 +00006738 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6739 tcg_opi(t0, t0, rB(ctx->opcode)); \
6740 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6741 tcg_gen_trunc_i64_i32(t1, t2); \
pbrooka7812ae2008-11-17 14:43:54 +00006742 tcg_temp_free_i64(t2); \
aurel3257951c22008-11-10 11:10:23 +00006743 tcg_opi(t1, t1, rB(ctx->opcode)); \
6744 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
pbrooka7812ae2008-11-17 14:43:54 +00006745 tcg_temp_free_i32(t0); \
6746 tcg_temp_free_i32(t1); \
aurel323d3a6a02008-10-15 17:00:45 +00006747}
aurel3257951c22008-11-10 11:10:23 +00006748#else
6749#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
Blue Swirl636aa202009-08-16 09:06:54 +00006750static inline void gen_##name(DisasContext *ctx) \
j_mayer0487d6a2007-03-20 22:11:31 +00006751{ \
6752 if (unlikely(!ctx->spe_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00006753 gen_exception(ctx, POWERPC_EXCP_APU); \
j_mayer0487d6a2007-03-20 22:11:31 +00006754 return; \
6755 } \
aurel3257951c22008-11-10 11:10:23 +00006756 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6757 rB(ctx->opcode)); \
6758 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6759 rB(ctx->opcode)); \
j_mayer0487d6a2007-03-20 22:11:31 +00006760}
aurel3257951c22008-11-10 11:10:23 +00006761#endif
6762GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32);
6763GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32);
6764GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32);
6765GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32);
j_mayer0487d6a2007-03-20 22:11:31 +00006766
aurel3257951c22008-11-10 11:10:23 +00006767/* SPE arithmetic */
6768#if defined(TARGET_PPC64)
6769#define GEN_SPEOP_ARITH1(name, tcg_op) \
Blue Swirl636aa202009-08-16 09:06:54 +00006770static inline void gen_##name(DisasContext *ctx) \
j_mayer0487d6a2007-03-20 22:11:31 +00006771{ \
6772 if (unlikely(!ctx->spe_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00006773 gen_exception(ctx, POWERPC_EXCP_APU); \
j_mayer0487d6a2007-03-20 22:11:31 +00006774 return; \
6775 } \
pbrooka7812ae2008-11-17 14:43:54 +00006776 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6777 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6778 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
aurel3257951c22008-11-10 11:10:23 +00006779 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6780 tcg_op(t0, t0); \
6781 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6782 tcg_gen_trunc_i64_i32(t1, t2); \
pbrooka7812ae2008-11-17 14:43:54 +00006783 tcg_temp_free_i64(t2); \
aurel3257951c22008-11-10 11:10:23 +00006784 tcg_op(t1, t1); \
6785 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
pbrooka7812ae2008-11-17 14:43:54 +00006786 tcg_temp_free_i32(t0); \
6787 tcg_temp_free_i32(t1); \
j_mayer0487d6a2007-03-20 22:11:31 +00006788}
aurel3257951c22008-11-10 11:10:23 +00006789#else
pbrooka7812ae2008-11-17 14:43:54 +00006790#define GEN_SPEOP_ARITH1(name, tcg_op) \
Blue Swirl636aa202009-08-16 09:06:54 +00006791static inline void gen_##name(DisasContext *ctx) \
aurel3257951c22008-11-10 11:10:23 +00006792{ \
6793 if (unlikely(!ctx->spe_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00006794 gen_exception(ctx, POWERPC_EXCP_APU); \
aurel3257951c22008-11-10 11:10:23 +00006795 return; \
6796 } \
6797 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
6798 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
6799}
6800#endif
j_mayer0487d6a2007-03-20 22:11:31 +00006801
Blue Swirl636aa202009-08-16 09:06:54 +00006802static inline void gen_op_evabs(TCGv_i32 ret, TCGv_i32 arg1)
aurel3257951c22008-11-10 11:10:23 +00006803{
6804 int l1 = gen_new_label();
6805 int l2 = gen_new_label();
j_mayer0487d6a2007-03-20 22:11:31 +00006806
aurel3257951c22008-11-10 11:10:23 +00006807 tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1);
6808 tcg_gen_neg_i32(ret, arg1);
6809 tcg_gen_br(l2);
6810 gen_set_label(l1);
pbrooka7812ae2008-11-17 14:43:54 +00006811 tcg_gen_mov_i32(ret, arg1);
aurel3257951c22008-11-10 11:10:23 +00006812 gen_set_label(l2);
6813}
6814GEN_SPEOP_ARITH1(evabs, gen_op_evabs);
6815GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32);
6816GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32);
6817GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32);
Blue Swirl636aa202009-08-16 09:06:54 +00006818static inline void gen_op_evrndw(TCGv_i32 ret, TCGv_i32 arg1)
aurel3257951c22008-11-10 11:10:23 +00006819{
6820 tcg_gen_addi_i32(ret, arg1, 0x8000);
6821 tcg_gen_ext16u_i32(ret, ret);
6822}
6823GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw);
pbrooka7812ae2008-11-17 14:43:54 +00006824GEN_SPEOP_ARITH1(evcntlsw, gen_helper_cntlsw32);
6825GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32);
aurel3257951c22008-11-10 11:10:23 +00006826
6827#if defined(TARGET_PPC64)
6828#define GEN_SPEOP_ARITH2(name, tcg_op) \
Blue Swirl636aa202009-08-16 09:06:54 +00006829static inline void gen_##name(DisasContext *ctx) \
aurel3257951c22008-11-10 11:10:23 +00006830{ \
6831 if (unlikely(!ctx->spe_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00006832 gen_exception(ctx, POWERPC_EXCP_APU); \
aurel3257951c22008-11-10 11:10:23 +00006833 return; \
6834 } \
pbrooka7812ae2008-11-17 14:43:54 +00006835 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6836 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6837 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
aurel32501e23c2009-01-03 12:35:38 +00006838 TCGv_i64 t3 = tcg_temp_local_new_i64(); \
aurel3257951c22008-11-10 11:10:23 +00006839 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6840 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
6841 tcg_op(t0, t0, t2); \
6842 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
6843 tcg_gen_trunc_i64_i32(t1, t3); \
6844 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
6845 tcg_gen_trunc_i64_i32(t2, t3); \
pbrooka7812ae2008-11-17 14:43:54 +00006846 tcg_temp_free_i64(t3); \
aurel3257951c22008-11-10 11:10:23 +00006847 tcg_op(t1, t1, t2); \
pbrooka7812ae2008-11-17 14:43:54 +00006848 tcg_temp_free_i32(t2); \
aurel3257951c22008-11-10 11:10:23 +00006849 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
pbrooka7812ae2008-11-17 14:43:54 +00006850 tcg_temp_free_i32(t0); \
6851 tcg_temp_free_i32(t1); \
aurel3257951c22008-11-10 11:10:23 +00006852}
6853#else
6854#define GEN_SPEOP_ARITH2(name, tcg_op) \
Blue Swirl636aa202009-08-16 09:06:54 +00006855static inline void gen_##name(DisasContext *ctx) \
aurel3257951c22008-11-10 11:10:23 +00006856{ \
6857 if (unlikely(!ctx->spe_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00006858 gen_exception(ctx, POWERPC_EXCP_APU); \
aurel3257951c22008-11-10 11:10:23 +00006859 return; \
6860 } \
6861 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6862 cpu_gpr[rB(ctx->opcode)]); \
6863 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6864 cpu_gprh[rB(ctx->opcode)]); \
6865}
6866#endif
6867
Blue Swirl636aa202009-08-16 09:06:54 +00006868static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel3257951c22008-11-10 11:10:23 +00006869{
pbrooka7812ae2008-11-17 14:43:54 +00006870 TCGv_i32 t0;
aurel3257951c22008-11-10 11:10:23 +00006871 int l1, l2;
6872
6873 l1 = gen_new_label();
6874 l2 = gen_new_label();
pbrooka7812ae2008-11-17 14:43:54 +00006875 t0 = tcg_temp_local_new_i32();
aurel3257951c22008-11-10 11:10:23 +00006876 /* No error here: 6 bits are used */
6877 tcg_gen_andi_i32(t0, arg2, 0x3F);
6878 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
6879 tcg_gen_shr_i32(ret, arg1, t0);
6880 tcg_gen_br(l2);
6881 gen_set_label(l1);
6882 tcg_gen_movi_i32(ret, 0);
Aurelien Jarno0aef4262010-03-11 21:29:42 +01006883 gen_set_label(l2);
pbrooka7812ae2008-11-17 14:43:54 +00006884 tcg_temp_free_i32(t0);
aurel3257951c22008-11-10 11:10:23 +00006885}
6886GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu);
Blue Swirl636aa202009-08-16 09:06:54 +00006887static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel3257951c22008-11-10 11:10:23 +00006888{
pbrooka7812ae2008-11-17 14:43:54 +00006889 TCGv_i32 t0;
aurel3257951c22008-11-10 11:10:23 +00006890 int l1, l2;
6891
6892 l1 = gen_new_label();
6893 l2 = gen_new_label();
pbrooka7812ae2008-11-17 14:43:54 +00006894 t0 = tcg_temp_local_new_i32();
aurel3257951c22008-11-10 11:10:23 +00006895 /* No error here: 6 bits are used */
6896 tcg_gen_andi_i32(t0, arg2, 0x3F);
6897 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
6898 tcg_gen_sar_i32(ret, arg1, t0);
6899 tcg_gen_br(l2);
6900 gen_set_label(l1);
6901 tcg_gen_movi_i32(ret, 0);
Aurelien Jarno0aef4262010-03-11 21:29:42 +01006902 gen_set_label(l2);
pbrooka7812ae2008-11-17 14:43:54 +00006903 tcg_temp_free_i32(t0);
aurel3257951c22008-11-10 11:10:23 +00006904}
6905GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws);
Blue Swirl636aa202009-08-16 09:06:54 +00006906static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel3257951c22008-11-10 11:10:23 +00006907{
pbrooka7812ae2008-11-17 14:43:54 +00006908 TCGv_i32 t0;
aurel3257951c22008-11-10 11:10:23 +00006909 int l1, l2;
6910
6911 l1 = gen_new_label();
6912 l2 = gen_new_label();
pbrooka7812ae2008-11-17 14:43:54 +00006913 t0 = tcg_temp_local_new_i32();
aurel3257951c22008-11-10 11:10:23 +00006914 /* No error here: 6 bits are used */
6915 tcg_gen_andi_i32(t0, arg2, 0x3F);
6916 tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
6917 tcg_gen_shl_i32(ret, arg1, t0);
6918 tcg_gen_br(l2);
6919 gen_set_label(l1);
6920 tcg_gen_movi_i32(ret, 0);
Aurelien Jarnoe29ef9f2010-03-11 21:14:47 +01006921 gen_set_label(l2);
pbrooka7812ae2008-11-17 14:43:54 +00006922 tcg_temp_free_i32(t0);
aurel3257951c22008-11-10 11:10:23 +00006923}
6924GEN_SPEOP_ARITH2(evslw, gen_op_evslw);
Blue Swirl636aa202009-08-16 09:06:54 +00006925static inline void gen_op_evrlw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel3257951c22008-11-10 11:10:23 +00006926{
pbrooka7812ae2008-11-17 14:43:54 +00006927 TCGv_i32 t0 = tcg_temp_new_i32();
aurel3257951c22008-11-10 11:10:23 +00006928 tcg_gen_andi_i32(t0, arg2, 0x1F);
6929 tcg_gen_rotl_i32(ret, arg1, t0);
pbrooka7812ae2008-11-17 14:43:54 +00006930 tcg_temp_free_i32(t0);
aurel3257951c22008-11-10 11:10:23 +00006931}
6932GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw);
Blue Swirl636aa202009-08-16 09:06:54 +00006933static inline void gen_evmergehi(DisasContext *ctx)
aurel3257951c22008-11-10 11:10:23 +00006934{
6935 if (unlikely(!ctx->spe_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00006936 gen_exception(ctx, POWERPC_EXCP_APU);
aurel3257951c22008-11-10 11:10:23 +00006937 return;
6938 }
6939#if defined(TARGET_PPC64)
pbrooka7812ae2008-11-17 14:43:54 +00006940 TCGv t0 = tcg_temp_new();
6941 TCGv t1 = tcg_temp_new();
aurel3257951c22008-11-10 11:10:23 +00006942 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
6943 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
6944 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
6945 tcg_temp_free(t0);
6946 tcg_temp_free(t1);
6947#else
6948 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
6949 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
6950#endif
6951}
6952GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32);
Blue Swirl636aa202009-08-16 09:06:54 +00006953static inline void gen_op_evsubf(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
aurel3257951c22008-11-10 11:10:23 +00006954{
6955 tcg_gen_sub_i32(ret, arg2, arg1);
6956}
6957GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf);
6958
6959/* SPE arithmetic immediate */
6960#if defined(TARGET_PPC64)
6961#define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
Blue Swirl636aa202009-08-16 09:06:54 +00006962static inline void gen_##name(DisasContext *ctx) \
aurel3257951c22008-11-10 11:10:23 +00006963{ \
6964 if (unlikely(!ctx->spe_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00006965 gen_exception(ctx, POWERPC_EXCP_APU); \
aurel3257951c22008-11-10 11:10:23 +00006966 return; \
6967 } \
pbrooka7812ae2008-11-17 14:43:54 +00006968 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6969 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6970 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
aurel3257951c22008-11-10 11:10:23 +00006971 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
6972 tcg_op(t0, t0, rA(ctx->opcode)); \
6973 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
6974 tcg_gen_trunc_i64_i32(t1, t2); \
aurel32e06fcd72008-12-11 22:42:14 +00006975 tcg_temp_free_i64(t2); \
aurel3257951c22008-11-10 11:10:23 +00006976 tcg_op(t1, t1, rA(ctx->opcode)); \
6977 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
pbrooka7812ae2008-11-17 14:43:54 +00006978 tcg_temp_free_i32(t0); \
6979 tcg_temp_free_i32(t1); \
aurel3257951c22008-11-10 11:10:23 +00006980}
6981#else
6982#define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
Blue Swirl636aa202009-08-16 09:06:54 +00006983static inline void gen_##name(DisasContext *ctx) \
aurel3257951c22008-11-10 11:10:23 +00006984{ \
6985 if (unlikely(!ctx->spe_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00006986 gen_exception(ctx, POWERPC_EXCP_APU); \
aurel3257951c22008-11-10 11:10:23 +00006987 return; \
6988 } \
6989 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
6990 rA(ctx->opcode)); \
6991 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
6992 rA(ctx->opcode)); \
6993}
6994#endif
6995GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32);
6996GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32);
6997
6998/* SPE comparison */
6999#if defined(TARGET_PPC64)
7000#define GEN_SPEOP_COMP(name, tcg_cond) \
Blue Swirl636aa202009-08-16 09:06:54 +00007001static inline void gen_##name(DisasContext *ctx) \
aurel3257951c22008-11-10 11:10:23 +00007002{ \
7003 if (unlikely(!ctx->spe_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00007004 gen_exception(ctx, POWERPC_EXCP_APU); \
aurel3257951c22008-11-10 11:10:23 +00007005 return; \
7006 } \
7007 int l1 = gen_new_label(); \
7008 int l2 = gen_new_label(); \
7009 int l3 = gen_new_label(); \
7010 int l4 = gen_new_label(); \
pbrooka7812ae2008-11-17 14:43:54 +00007011 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7012 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7013 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
aurel3257951c22008-11-10 11:10:23 +00007014 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7015 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
7016 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
pbrooka7812ae2008-11-17 14:43:54 +00007017 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
aurel3257951c22008-11-10 11:10:23 +00007018 tcg_gen_br(l2); \
7019 gen_set_label(l1); \
7020 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
7021 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
7022 gen_set_label(l2); \
7023 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7024 tcg_gen_trunc_i64_i32(t0, t2); \
7025 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
7026 tcg_gen_trunc_i64_i32(t1, t2); \
pbrooka7812ae2008-11-17 14:43:54 +00007027 tcg_temp_free_i64(t2); \
aurel3257951c22008-11-10 11:10:23 +00007028 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
7029 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7030 ~(CRF_CH | CRF_CH_AND_CL)); \
7031 tcg_gen_br(l4); \
7032 gen_set_label(l3); \
7033 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7034 CRF_CH | CRF_CH_OR_CL); \
7035 gen_set_label(l4); \
pbrooka7812ae2008-11-17 14:43:54 +00007036 tcg_temp_free_i32(t0); \
7037 tcg_temp_free_i32(t1); \
aurel3257951c22008-11-10 11:10:23 +00007038}
7039#else
7040#define GEN_SPEOP_COMP(name, tcg_cond) \
Blue Swirl636aa202009-08-16 09:06:54 +00007041static inline void gen_##name(DisasContext *ctx) \
aurel3257951c22008-11-10 11:10:23 +00007042{ \
7043 if (unlikely(!ctx->spe_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00007044 gen_exception(ctx, POWERPC_EXCP_APU); \
aurel3257951c22008-11-10 11:10:23 +00007045 return; \
7046 } \
7047 int l1 = gen_new_label(); \
7048 int l2 = gen_new_label(); \
7049 int l3 = gen_new_label(); \
7050 int l4 = gen_new_label(); \
7051 \
7052 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
7053 cpu_gpr[rB(ctx->opcode)], l1); \
7054 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
7055 tcg_gen_br(l2); \
7056 gen_set_label(l1); \
7057 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
7058 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
7059 gen_set_label(l2); \
7060 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
7061 cpu_gprh[rB(ctx->opcode)], l3); \
7062 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7063 ~(CRF_CH | CRF_CH_AND_CL)); \
7064 tcg_gen_br(l4); \
7065 gen_set_label(l3); \
7066 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7067 CRF_CH | CRF_CH_OR_CL); \
7068 gen_set_label(l4); \
7069}
7070#endif
7071GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU);
7072GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT);
7073GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU);
7074GEN_SPEOP_COMP(evcmplts, TCG_COND_LT);
7075GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ);
7076
7077/* SPE misc */
Blue Swirl636aa202009-08-16 09:06:54 +00007078static inline void gen_brinc(DisasContext *ctx)
j_mayer0487d6a2007-03-20 22:11:31 +00007079{
7080 /* Note: brinc is usable even if SPE is disabled */
pbrooka7812ae2008-11-17 14:43:54 +00007081 gen_helper_brinc(cpu_gpr[rD(ctx->opcode)],
7082 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
j_mayer0487d6a2007-03-20 22:11:31 +00007083}
Blue Swirl636aa202009-08-16 09:06:54 +00007084static inline void gen_evmergelo(DisasContext *ctx)
aurel3257951c22008-11-10 11:10:23 +00007085{
7086 if (unlikely(!ctx->spe_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00007087 gen_exception(ctx, POWERPC_EXCP_APU);
aurel3257951c22008-11-10 11:10:23 +00007088 return;
7089 }
7090#if defined(TARGET_PPC64)
pbrooka7812ae2008-11-17 14:43:54 +00007091 TCGv t0 = tcg_temp_new();
7092 TCGv t1 = tcg_temp_new();
Aurelien Jarno17d9b3a2011-03-22 07:41:29 +01007093 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
aurel3257951c22008-11-10 11:10:23 +00007094 tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
7095 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
7096 tcg_temp_free(t0);
7097 tcg_temp_free(t1);
7098#else
aurel3257951c22008-11-10 11:10:23 +00007099 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
Nathan Froyd33890b32009-06-04 13:46:41 -07007100 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
aurel3257951c22008-11-10 11:10:23 +00007101#endif
j_mayer0487d6a2007-03-20 22:11:31 +00007102}
Blue Swirl636aa202009-08-16 09:06:54 +00007103static inline void gen_evmergehilo(DisasContext *ctx)
aurel3257951c22008-11-10 11:10:23 +00007104{
7105 if (unlikely(!ctx->spe_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00007106 gen_exception(ctx, POWERPC_EXCP_APU);
aurel3257951c22008-11-10 11:10:23 +00007107 return;
7108 }
7109#if defined(TARGET_PPC64)
pbrooka7812ae2008-11-17 14:43:54 +00007110 TCGv t0 = tcg_temp_new();
7111 TCGv t1 = tcg_temp_new();
Aurelien Jarno17d9b3a2011-03-22 07:41:29 +01007112 tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
aurel3257951c22008-11-10 11:10:23 +00007113 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
7114 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
7115 tcg_temp_free(t0);
7116 tcg_temp_free(t1);
7117#else
7118 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
7119 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
7120#endif
j_mayer0487d6a2007-03-20 22:11:31 +00007121}
Blue Swirl636aa202009-08-16 09:06:54 +00007122static inline void gen_evmergelohi(DisasContext *ctx)
aurel3257951c22008-11-10 11:10:23 +00007123{
7124 if (unlikely(!ctx->spe_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00007125 gen_exception(ctx, POWERPC_EXCP_APU);
aurel3257951c22008-11-10 11:10:23 +00007126 return;
7127 }
7128#if defined(TARGET_PPC64)
pbrooka7812ae2008-11-17 14:43:54 +00007129 TCGv t0 = tcg_temp_new();
7130 TCGv t1 = tcg_temp_new();
aurel3257951c22008-11-10 11:10:23 +00007131 tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
7132 tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
7133 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
7134 tcg_temp_free(t0);
7135 tcg_temp_free(t1);
7136#else
Nathan Froyd33890b32009-06-04 13:46:41 -07007137 if (rD(ctx->opcode) == rA(ctx->opcode)) {
7138 TCGv_i32 tmp = tcg_temp_new_i32();
7139 tcg_gen_mov_i32(tmp, cpu_gpr[rA(ctx->opcode)]);
7140 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
7141 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], tmp);
7142 tcg_temp_free_i32(tmp);
7143 } else {
7144 tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
7145 tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
7146 }
aurel3257951c22008-11-10 11:10:23 +00007147#endif
7148}
Blue Swirl636aa202009-08-16 09:06:54 +00007149static inline void gen_evsplati(DisasContext *ctx)
j_mayer0487d6a2007-03-20 22:11:31 +00007150{
Nathan Froydae018472010-02-23 12:21:31 -08007151 uint64_t imm = ((int32_t)(rA(ctx->opcode) << 27)) >> 27;
j_mayer0487d6a2007-03-20 22:11:31 +00007152
aurel3257951c22008-11-10 11:10:23 +00007153#if defined(TARGET_PPC64)
aurel3238d14952008-11-27 19:30:38 +00007154 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
aurel3257951c22008-11-10 11:10:23 +00007155#else
7156 tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
7157 tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
7158#endif
j_mayer0487d6a2007-03-20 22:11:31 +00007159}
Blue Swirl636aa202009-08-16 09:06:54 +00007160static inline void gen_evsplatfi(DisasContext *ctx)
j_mayer0487d6a2007-03-20 22:11:31 +00007161{
Nathan Froydae018472010-02-23 12:21:31 -08007162 uint64_t imm = rA(ctx->opcode) << 27;
j_mayer0487d6a2007-03-20 22:11:31 +00007163
aurel3257951c22008-11-10 11:10:23 +00007164#if defined(TARGET_PPC64)
aurel3238d14952008-11-27 19:30:38 +00007165 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
aurel3257951c22008-11-10 11:10:23 +00007166#else
7167 tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
7168 tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
7169#endif
j_mayer0487d6a2007-03-20 22:11:31 +00007170}
7171
Blue Swirl636aa202009-08-16 09:06:54 +00007172static inline void gen_evsel(DisasContext *ctx)
aurel3257951c22008-11-10 11:10:23 +00007173{
7174 int l1 = gen_new_label();
7175 int l2 = gen_new_label();
7176 int l3 = gen_new_label();
7177 int l4 = gen_new_label();
pbrooka7812ae2008-11-17 14:43:54 +00007178 TCGv_i32 t0 = tcg_temp_local_new_i32();
aurel3257951c22008-11-10 11:10:23 +00007179#if defined(TARGET_PPC64)
pbrooka7812ae2008-11-17 14:43:54 +00007180 TCGv t1 = tcg_temp_local_new();
7181 TCGv t2 = tcg_temp_local_new();
aurel3257951c22008-11-10 11:10:23 +00007182#endif
7183 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3);
7184 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
7185#if defined(TARGET_PPC64)
7186 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF00000000ULL);
7187#else
7188 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
7189#endif
7190 tcg_gen_br(l2);
7191 gen_set_label(l1);
7192#if defined(TARGET_PPC64)
7193 tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0xFFFFFFFF00000000ULL);
7194#else
7195 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
7196#endif
7197 gen_set_label(l2);
7198 tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2);
7199 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3);
7200#if defined(TARGET_PPC64)
Aurelien Jarno17d9b3a2011-03-22 07:41:29 +01007201 tcg_gen_ext32u_tl(t2, cpu_gpr[rA(ctx->opcode)]);
aurel3257951c22008-11-10 11:10:23 +00007202#else
7203 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
7204#endif
7205 tcg_gen_br(l4);
7206 gen_set_label(l3);
7207#if defined(TARGET_PPC64)
Aurelien Jarno17d9b3a2011-03-22 07:41:29 +01007208 tcg_gen_ext32u_tl(t2, cpu_gpr[rB(ctx->opcode)]);
aurel3257951c22008-11-10 11:10:23 +00007209#else
7210 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
7211#endif
7212 gen_set_label(l4);
pbrooka7812ae2008-11-17 14:43:54 +00007213 tcg_temp_free_i32(t0);
aurel3257951c22008-11-10 11:10:23 +00007214#if defined(TARGET_PPC64)
7215 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t1, t2);
7216 tcg_temp_free(t1);
7217 tcg_temp_free(t2);
7218#endif
7219}
Blue Swirle8eaa2c2009-06-17 15:22:14 +00007220
7221static void gen_evsel0(DisasContext *ctx)
aurel3257951c22008-11-10 11:10:23 +00007222{
7223 gen_evsel(ctx);
7224}
Blue Swirle8eaa2c2009-06-17 15:22:14 +00007225
7226static void gen_evsel1(DisasContext *ctx)
aurel3257951c22008-11-10 11:10:23 +00007227{
7228 gen_evsel(ctx);
7229}
Blue Swirle8eaa2c2009-06-17 15:22:14 +00007230
7231static void gen_evsel2(DisasContext *ctx)
aurel3257951c22008-11-10 11:10:23 +00007232{
7233 gen_evsel(ctx);
7234}
Blue Swirle8eaa2c2009-06-17 15:22:14 +00007235
7236static void gen_evsel3(DisasContext *ctx)
aurel3257951c22008-11-10 11:10:23 +00007237{
7238 gen_evsel(ctx);
7239}
j_mayer0487d6a2007-03-20 22:11:31 +00007240
Fabien Chouteaua0e13902011-03-16 11:21:22 +01007241/* Multiply */
7242
7243static inline void gen_evmwumi(DisasContext *ctx)
7244{
7245 TCGv_i64 t0, t1;
7246
7247 if (unlikely(!ctx->spe_enabled)) {
7248 gen_exception(ctx, POWERPC_EXCP_APU);
7249 return;
7250 }
7251
7252 t0 = tcg_temp_new_i64();
7253 t1 = tcg_temp_new_i64();
7254
7255 /* t0 := rA; t1 := rB */
7256#if defined(TARGET_PPC64)
7257 tcg_gen_ext32u_tl(t0, cpu_gpr[rA(ctx->opcode)]);
7258 tcg_gen_ext32u_tl(t1, cpu_gpr[rB(ctx->opcode)]);
7259#else
7260 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
7261 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
7262#endif
7263
7264 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
7265
7266 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
7267
7268 tcg_temp_free_i64(t0);
7269 tcg_temp_free_i64(t1);
7270}
7271
7272static inline void gen_evmwumia(DisasContext *ctx)
7273{
7274 TCGv_i64 tmp;
7275
7276 if (unlikely(!ctx->spe_enabled)) {
7277 gen_exception(ctx, POWERPC_EXCP_APU);
7278 return;
7279 }
7280
7281 gen_evmwumi(ctx); /* rD := rA * rB */
7282
7283 tmp = tcg_temp_new_i64();
7284
7285 /* acc := rD */
7286 gen_load_gpr64(tmp, rD(ctx->opcode));
7287 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUState, spe_acc));
7288 tcg_temp_free_i64(tmp);
7289}
7290
7291static inline void gen_evmwumiaa(DisasContext *ctx)
7292{
7293 TCGv_i64 acc;
7294 TCGv_i64 tmp;
7295
7296 if (unlikely(!ctx->spe_enabled)) {
7297 gen_exception(ctx, POWERPC_EXCP_APU);
7298 return;
7299 }
7300
7301 gen_evmwumi(ctx); /* rD := rA * rB */
7302
7303 acc = tcg_temp_new_i64();
7304 tmp = tcg_temp_new_i64();
7305
7306 /* tmp := rD */
7307 gen_load_gpr64(tmp, rD(ctx->opcode));
7308
7309 /* Load acc */
7310 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUState, spe_acc));
7311
7312 /* acc := tmp + acc */
7313 tcg_gen_add_i64(acc, acc, tmp);
7314
7315 /* Store acc */
7316 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUState, spe_acc));
7317
7318 /* rD := acc */
7319 gen_store_gpr64(rD(ctx->opcode), acc);
7320
7321 tcg_temp_free_i64(acc);
7322 tcg_temp_free_i64(tmp);
7323}
7324
7325static inline void gen_evmwsmi(DisasContext *ctx)
7326{
7327 TCGv_i64 t0, t1;
7328
7329 if (unlikely(!ctx->spe_enabled)) {
7330 gen_exception(ctx, POWERPC_EXCP_APU);
7331 return;
7332 }
7333
7334 t0 = tcg_temp_new_i64();
7335 t1 = tcg_temp_new_i64();
7336
7337 /* t0 := rA; t1 := rB */
7338#if defined(TARGET_PPC64)
7339 tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]);
7340 tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]);
7341#else
7342 tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
7343 tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
7344#endif
7345
7346 tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */
7347
7348 gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
7349
7350 tcg_temp_free_i64(t0);
7351 tcg_temp_free_i64(t1);
7352}
7353
7354static inline void gen_evmwsmia(DisasContext *ctx)
7355{
7356 TCGv_i64 tmp;
7357
7358 gen_evmwsmi(ctx); /* rD := rA * rB */
7359
7360 tmp = tcg_temp_new_i64();
7361
7362 /* acc := rD */
7363 gen_load_gpr64(tmp, rD(ctx->opcode));
7364 tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUState, spe_acc));
7365
7366 tcg_temp_free_i64(tmp);
7367}
7368
7369static inline void gen_evmwsmiaa(DisasContext *ctx)
7370{
7371 TCGv_i64 acc = tcg_temp_new_i64();
7372 TCGv_i64 tmp = tcg_temp_new_i64();
7373
7374 gen_evmwsmi(ctx); /* rD := rA * rB */
7375
7376 acc = tcg_temp_new_i64();
7377 tmp = tcg_temp_new_i64();
7378
7379 /* tmp := rD */
7380 gen_load_gpr64(tmp, rD(ctx->opcode));
7381
7382 /* Load acc */
7383 tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUState, spe_acc));
7384
7385 /* acc := tmp + acc */
7386 tcg_gen_add_i64(acc, acc, tmp);
7387
7388 /* Store acc */
7389 tcg_gen_st_i64(acc, cpu_env, offsetof(CPUState, spe_acc));
7390
7391 /* rD := acc */
7392 gen_store_gpr64(rD(ctx->opcode), acc);
7393
7394 tcg_temp_free_i64(acc);
7395 tcg_temp_free_i64(tmp);
7396}
7397
j_mayer0487d6a2007-03-20 22:11:31 +00007398GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, PPC_SPE); ////
7399GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, PPC_SPE);
7400GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, PPC_SPE); ////
7401GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, PPC_SPE);
7402GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, PPC_SPE); ////
7403GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, PPC_SPE); ////
7404GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, PPC_SPE); ////
7405GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x00000000, PPC_SPE); //
Fabien Chouteaua0e13902011-03-16 11:21:22 +01007406GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, PPC_SPE);
j_mayer0487d6a2007-03-20 22:11:31 +00007407GEN_SPE(speundef, evand, 0x08, 0x08, 0x00000000, PPC_SPE); ////
7408GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, PPC_SPE); ////
7409GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, PPC_SPE); ////
7410GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, PPC_SPE); ////
Fabien Chouteaua0e13902011-03-16 11:21:22 +01007411GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, PPC_SPE);
7412GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, PPC_SPE);
7413GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, PPC_SPE);
j_mayer0487d6a2007-03-20 22:11:31 +00007414GEN_SPE(speundef, evorc, 0x0D, 0x08, 0x00000000, PPC_SPE); ////
7415GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, PPC_SPE); ////
7416GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, PPC_SPE); ////
7417GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, PPC_SPE);
7418GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, PPC_SPE); ////
7419GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, PPC_SPE);
7420GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, PPC_SPE); //
7421GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, PPC_SPE);
7422GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, PPC_SPE); ////
7423GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, PPC_SPE); ////
7424GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, PPC_SPE); ////
7425GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, PPC_SPE); ////
7426GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, PPC_SPE); ////
7427
aurel326a6ae232008-11-27 19:30:47 +00007428/* SPE load and stores */
Blue Swirl636aa202009-08-16 09:06:54 +00007429static inline void gen_addr_spe_imm_index(DisasContext *ctx, TCGv EA, int sh)
aurel326a6ae232008-11-27 19:30:47 +00007430{
7431 target_ulong uimm = rB(ctx->opcode);
j_mayer0487d6a2007-03-20 22:11:31 +00007432
aurel3276db3ba2008-12-08 18:11:21 +00007433 if (rA(ctx->opcode) == 0) {
aurel326a6ae232008-11-27 19:30:47 +00007434 tcg_gen_movi_tl(EA, uimm << sh);
aurel3276db3ba2008-12-08 18:11:21 +00007435 } else {
aurel326a6ae232008-11-27 19:30:47 +00007436 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], uimm << sh);
aurel3276db3ba2008-12-08 18:11:21 +00007437#if defined(TARGET_PPC64)
7438 if (!ctx->sf_mode) {
7439 tcg_gen_ext32u_tl(EA, EA);
7440 }
7441#endif
7442 }
j_mayer0487d6a2007-03-20 22:11:31 +00007443}
aurel326a6ae232008-11-27 19:30:47 +00007444
Blue Swirl636aa202009-08-16 09:06:54 +00007445static inline void gen_op_evldd(DisasContext *ctx, TCGv addr)
aurel326a6ae232008-11-27 19:30:47 +00007446{
j_mayer0487d6a2007-03-20 22:11:31 +00007447#if defined(TARGET_PPC64)
aurel3276db3ba2008-12-08 18:11:21 +00007448 gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], addr);
j_mayer0487d6a2007-03-20 22:11:31 +00007449#else
aurel326a6ae232008-11-27 19:30:47 +00007450 TCGv_i64 t0 = tcg_temp_new_i64();
aurel3276db3ba2008-12-08 18:11:21 +00007451 gen_qemu_ld64(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007452 tcg_gen_trunc_i64_i32(cpu_gpr[rD(ctx->opcode)], t0);
7453 tcg_gen_shri_i64(t0, t0, 32);
7454 tcg_gen_trunc_i64_i32(cpu_gprh[rD(ctx->opcode)], t0);
7455 tcg_temp_free_i64(t0);
j_mayer0487d6a2007-03-20 22:11:31 +00007456#endif
j_mayer0487d6a2007-03-20 22:11:31 +00007457}
7458
Blue Swirl636aa202009-08-16 09:06:54 +00007459static inline void gen_op_evldw(DisasContext *ctx, TCGv addr)
aurel326a6ae232008-11-27 19:30:47 +00007460{
j_mayer0487d6a2007-03-20 22:11:31 +00007461#if defined(TARGET_PPC64)
aurel326a6ae232008-11-27 19:30:47 +00007462 TCGv t0 = tcg_temp_new();
aurel3276db3ba2008-12-08 18:11:21 +00007463 gen_qemu_ld32u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007464 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
aurel3276db3ba2008-12-08 18:11:21 +00007465 gen_addr_add(ctx, addr, addr, 4);
7466 gen_qemu_ld32u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007467 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7468 tcg_temp_free(t0);
j_mayer0487d6a2007-03-20 22:11:31 +00007469#else
aurel3276db3ba2008-12-08 18:11:21 +00007470 gen_qemu_ld32u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
7471 gen_addr_add(ctx, addr, addr, 4);
7472 gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
j_mayer0487d6a2007-03-20 22:11:31 +00007473#endif
aurel326a6ae232008-11-27 19:30:47 +00007474}
j_mayer0487d6a2007-03-20 22:11:31 +00007475
Blue Swirl636aa202009-08-16 09:06:54 +00007476static inline void gen_op_evldh(DisasContext *ctx, TCGv addr)
aurel326a6ae232008-11-27 19:30:47 +00007477{
7478 TCGv t0 = tcg_temp_new();
7479#if defined(TARGET_PPC64)
aurel3276db3ba2008-12-08 18:11:21 +00007480 gen_qemu_ld16u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007481 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
aurel3276db3ba2008-12-08 18:11:21 +00007482 gen_addr_add(ctx, addr, addr, 2);
7483 gen_qemu_ld16u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007484 tcg_gen_shli_tl(t0, t0, 32);
7485 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
aurel3276db3ba2008-12-08 18:11:21 +00007486 gen_addr_add(ctx, addr, addr, 2);
7487 gen_qemu_ld16u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007488 tcg_gen_shli_tl(t0, t0, 16);
7489 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
aurel3276db3ba2008-12-08 18:11:21 +00007490 gen_addr_add(ctx, addr, addr, 2);
7491 gen_qemu_ld16u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007492 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7493#else
aurel3276db3ba2008-12-08 18:11:21 +00007494 gen_qemu_ld16u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007495 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
aurel3276db3ba2008-12-08 18:11:21 +00007496 gen_addr_add(ctx, addr, addr, 2);
7497 gen_qemu_ld16u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007498 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
aurel3276db3ba2008-12-08 18:11:21 +00007499 gen_addr_add(ctx, addr, addr, 2);
7500 gen_qemu_ld16u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007501 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
aurel3276db3ba2008-12-08 18:11:21 +00007502 gen_addr_add(ctx, addr, addr, 2);
7503 gen_qemu_ld16u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007504 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7505#endif
7506 tcg_temp_free(t0);
7507}
7508
Blue Swirl636aa202009-08-16 09:06:54 +00007509static inline void gen_op_evlhhesplat(DisasContext *ctx, TCGv addr)
aurel326a6ae232008-11-27 19:30:47 +00007510{
7511 TCGv t0 = tcg_temp_new();
aurel3276db3ba2008-12-08 18:11:21 +00007512 gen_qemu_ld16u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007513#if defined(TARGET_PPC64)
7514 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
7515 tcg_gen_shli_tl(t0, t0, 16);
7516 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7517#else
7518 tcg_gen_shli_tl(t0, t0, 16);
7519 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
7520 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
7521#endif
7522 tcg_temp_free(t0);
7523}
7524
Blue Swirl636aa202009-08-16 09:06:54 +00007525static inline void gen_op_evlhhousplat(DisasContext *ctx, TCGv addr)
aurel326a6ae232008-11-27 19:30:47 +00007526{
7527 TCGv t0 = tcg_temp_new();
aurel3276db3ba2008-12-08 18:11:21 +00007528 gen_qemu_ld16u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007529#if defined(TARGET_PPC64)
7530 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
7531 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7532#else
7533 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
7534 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
7535#endif
7536 tcg_temp_free(t0);
7537}
7538
Blue Swirl636aa202009-08-16 09:06:54 +00007539static inline void gen_op_evlhhossplat(DisasContext *ctx, TCGv addr)
aurel326a6ae232008-11-27 19:30:47 +00007540{
7541 TCGv t0 = tcg_temp_new();
aurel3276db3ba2008-12-08 18:11:21 +00007542 gen_qemu_ld16s(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007543#if defined(TARGET_PPC64)
7544 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
7545 tcg_gen_ext32u_tl(t0, t0);
7546 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7547#else
7548 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
7549 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
7550#endif
7551 tcg_temp_free(t0);
7552}
7553
Blue Swirl636aa202009-08-16 09:06:54 +00007554static inline void gen_op_evlwhe(DisasContext *ctx, TCGv addr)
aurel326a6ae232008-11-27 19:30:47 +00007555{
7556 TCGv t0 = tcg_temp_new();
7557#if defined(TARGET_PPC64)
aurel3276db3ba2008-12-08 18:11:21 +00007558 gen_qemu_ld16u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007559 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
aurel3276db3ba2008-12-08 18:11:21 +00007560 gen_addr_add(ctx, addr, addr, 2);
7561 gen_qemu_ld16u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007562 tcg_gen_shli_tl(t0, t0, 16);
7563 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7564#else
aurel3276db3ba2008-12-08 18:11:21 +00007565 gen_qemu_ld16u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007566 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
aurel3276db3ba2008-12-08 18:11:21 +00007567 gen_addr_add(ctx, addr, addr, 2);
7568 gen_qemu_ld16u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007569 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
7570#endif
7571 tcg_temp_free(t0);
7572}
7573
Blue Swirl636aa202009-08-16 09:06:54 +00007574static inline void gen_op_evlwhou(DisasContext *ctx, TCGv addr)
aurel326a6ae232008-11-27 19:30:47 +00007575{
7576#if defined(TARGET_PPC64)
7577 TCGv t0 = tcg_temp_new();
aurel3276db3ba2008-12-08 18:11:21 +00007578 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
7579 gen_addr_add(ctx, addr, addr, 2);
7580 gen_qemu_ld16u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007581 tcg_gen_shli_tl(t0, t0, 32);
7582 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7583 tcg_temp_free(t0);
7584#else
aurel3276db3ba2008-12-08 18:11:21 +00007585 gen_qemu_ld16u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
7586 gen_addr_add(ctx, addr, addr, 2);
7587 gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
aurel326a6ae232008-11-27 19:30:47 +00007588#endif
7589}
7590
Blue Swirl636aa202009-08-16 09:06:54 +00007591static inline void gen_op_evlwhos(DisasContext *ctx, TCGv addr)
aurel326a6ae232008-11-27 19:30:47 +00007592{
7593#if defined(TARGET_PPC64)
7594 TCGv t0 = tcg_temp_new();
aurel3276db3ba2008-12-08 18:11:21 +00007595 gen_qemu_ld16s(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007596 tcg_gen_ext32u_tl(cpu_gpr[rD(ctx->opcode)], t0);
aurel3276db3ba2008-12-08 18:11:21 +00007597 gen_addr_add(ctx, addr, addr, 2);
7598 gen_qemu_ld16s(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007599 tcg_gen_shli_tl(t0, t0, 32);
7600 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7601 tcg_temp_free(t0);
7602#else
aurel3276db3ba2008-12-08 18:11:21 +00007603 gen_qemu_ld16s(ctx, cpu_gprh[rD(ctx->opcode)], addr);
7604 gen_addr_add(ctx, addr, addr, 2);
7605 gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], addr);
aurel326a6ae232008-11-27 19:30:47 +00007606#endif
7607}
7608
Blue Swirl636aa202009-08-16 09:06:54 +00007609static inline void gen_op_evlwwsplat(DisasContext *ctx, TCGv addr)
aurel326a6ae232008-11-27 19:30:47 +00007610{
7611 TCGv t0 = tcg_temp_new();
aurel3276db3ba2008-12-08 18:11:21 +00007612 gen_qemu_ld32u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007613#if defined(TARGET_PPC64)
7614 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
7615 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7616#else
7617 tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
7618 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
7619#endif
7620 tcg_temp_free(t0);
7621}
7622
Blue Swirl636aa202009-08-16 09:06:54 +00007623static inline void gen_op_evlwhsplat(DisasContext *ctx, TCGv addr)
aurel326a6ae232008-11-27 19:30:47 +00007624{
7625 TCGv t0 = tcg_temp_new();
7626#if defined(TARGET_PPC64)
aurel3276db3ba2008-12-08 18:11:21 +00007627 gen_qemu_ld16u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007628 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
7629 tcg_gen_shli_tl(t0, t0, 32);
7630 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
aurel3276db3ba2008-12-08 18:11:21 +00007631 gen_addr_add(ctx, addr, addr, 2);
7632 gen_qemu_ld16u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007633 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7634 tcg_gen_shli_tl(t0, t0, 16);
7635 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7636#else
aurel3276db3ba2008-12-08 18:11:21 +00007637 gen_qemu_ld16u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007638 tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
7639 tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
aurel3276db3ba2008-12-08 18:11:21 +00007640 gen_addr_add(ctx, addr, addr, 2);
7641 gen_qemu_ld16u(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007642 tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
7643 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
7644#endif
7645 tcg_temp_free(t0);
7646}
7647
Blue Swirl636aa202009-08-16 09:06:54 +00007648static inline void gen_op_evstdd(DisasContext *ctx, TCGv addr)
aurel326a6ae232008-11-27 19:30:47 +00007649{
7650#if defined(TARGET_PPC64)
aurel3276db3ba2008-12-08 18:11:21 +00007651 gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], addr);
aurel326a6ae232008-11-27 19:30:47 +00007652#else
7653 TCGv_i64 t0 = tcg_temp_new_i64();
7654 tcg_gen_concat_i32_i64(t0, cpu_gpr[rS(ctx->opcode)], cpu_gprh[rS(ctx->opcode)]);
aurel3276db3ba2008-12-08 18:11:21 +00007655 gen_qemu_st64(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007656 tcg_temp_free_i64(t0);
7657#endif
7658}
7659
Blue Swirl636aa202009-08-16 09:06:54 +00007660static inline void gen_op_evstdw(DisasContext *ctx, TCGv addr)
aurel326a6ae232008-11-27 19:30:47 +00007661{
7662#if defined(TARGET_PPC64)
7663 TCGv t0 = tcg_temp_new();
7664 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
aurel3276db3ba2008-12-08 18:11:21 +00007665 gen_qemu_st32(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007666 tcg_temp_free(t0);
7667#else
aurel3276db3ba2008-12-08 18:11:21 +00007668 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
aurel326a6ae232008-11-27 19:30:47 +00007669#endif
aurel3276db3ba2008-12-08 18:11:21 +00007670 gen_addr_add(ctx, addr, addr, 4);
7671 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
aurel326a6ae232008-11-27 19:30:47 +00007672}
7673
Blue Swirl636aa202009-08-16 09:06:54 +00007674static inline void gen_op_evstdh(DisasContext *ctx, TCGv addr)
aurel326a6ae232008-11-27 19:30:47 +00007675{
7676 TCGv t0 = tcg_temp_new();
7677#if defined(TARGET_PPC64)
7678 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
7679#else
7680 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
7681#endif
aurel3276db3ba2008-12-08 18:11:21 +00007682 gen_qemu_st16(ctx, t0, addr);
7683 gen_addr_add(ctx, addr, addr, 2);
aurel326a6ae232008-11-27 19:30:47 +00007684#if defined(TARGET_PPC64)
7685 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
aurel3276db3ba2008-12-08 18:11:21 +00007686 gen_qemu_st16(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007687#else
aurel3276db3ba2008-12-08 18:11:21 +00007688 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
aurel326a6ae232008-11-27 19:30:47 +00007689#endif
aurel3276db3ba2008-12-08 18:11:21 +00007690 gen_addr_add(ctx, addr, addr, 2);
aurel326a6ae232008-11-27 19:30:47 +00007691 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
aurel3276db3ba2008-12-08 18:11:21 +00007692 gen_qemu_st16(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007693 tcg_temp_free(t0);
aurel3276db3ba2008-12-08 18:11:21 +00007694 gen_addr_add(ctx, addr, addr, 2);
7695 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
aurel326a6ae232008-11-27 19:30:47 +00007696}
7697
Blue Swirl636aa202009-08-16 09:06:54 +00007698static inline void gen_op_evstwhe(DisasContext *ctx, TCGv addr)
aurel326a6ae232008-11-27 19:30:47 +00007699{
7700 TCGv t0 = tcg_temp_new();
7701#if defined(TARGET_PPC64)
7702 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
7703#else
7704 tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
7705#endif
aurel3276db3ba2008-12-08 18:11:21 +00007706 gen_qemu_st16(ctx, t0, addr);
7707 gen_addr_add(ctx, addr, addr, 2);
aurel326a6ae232008-11-27 19:30:47 +00007708 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
aurel3276db3ba2008-12-08 18:11:21 +00007709 gen_qemu_st16(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007710 tcg_temp_free(t0);
7711}
7712
Blue Swirl636aa202009-08-16 09:06:54 +00007713static inline void gen_op_evstwho(DisasContext *ctx, TCGv addr)
aurel326a6ae232008-11-27 19:30:47 +00007714{
7715#if defined(TARGET_PPC64)
7716 TCGv t0 = tcg_temp_new();
7717 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
aurel3276db3ba2008-12-08 18:11:21 +00007718 gen_qemu_st16(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007719 tcg_temp_free(t0);
7720#else
aurel3276db3ba2008-12-08 18:11:21 +00007721 gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
aurel326a6ae232008-11-27 19:30:47 +00007722#endif
aurel3276db3ba2008-12-08 18:11:21 +00007723 gen_addr_add(ctx, addr, addr, 2);
7724 gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
aurel326a6ae232008-11-27 19:30:47 +00007725}
7726
Blue Swirl636aa202009-08-16 09:06:54 +00007727static inline void gen_op_evstwwe(DisasContext *ctx, TCGv addr)
aurel326a6ae232008-11-27 19:30:47 +00007728{
7729#if defined(TARGET_PPC64)
7730 TCGv t0 = tcg_temp_new();
7731 tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
aurel3276db3ba2008-12-08 18:11:21 +00007732 gen_qemu_st32(ctx, t0, addr);
aurel326a6ae232008-11-27 19:30:47 +00007733 tcg_temp_free(t0);
7734#else
aurel3276db3ba2008-12-08 18:11:21 +00007735 gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
aurel326a6ae232008-11-27 19:30:47 +00007736#endif
7737}
7738
Blue Swirl636aa202009-08-16 09:06:54 +00007739static inline void gen_op_evstwwo(DisasContext *ctx, TCGv addr)
aurel326a6ae232008-11-27 19:30:47 +00007740{
aurel3276db3ba2008-12-08 18:11:21 +00007741 gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
aurel326a6ae232008-11-27 19:30:47 +00007742}
7743
7744#define GEN_SPEOP_LDST(name, opc2, sh) \
Blue Swirl99e300e2009-06-17 15:22:09 +00007745static void glue(gen_, name)(DisasContext *ctx) \
aurel326a6ae232008-11-27 19:30:47 +00007746{ \
7747 TCGv t0; \
7748 if (unlikely(!ctx->spe_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00007749 gen_exception(ctx, POWERPC_EXCP_APU); \
aurel326a6ae232008-11-27 19:30:47 +00007750 return; \
7751 } \
aurel3276db3ba2008-12-08 18:11:21 +00007752 gen_set_access_type(ctx, ACCESS_INT); \
aurel326a6ae232008-11-27 19:30:47 +00007753 t0 = tcg_temp_new(); \
7754 if (Rc(ctx->opcode)) { \
aurel3276db3ba2008-12-08 18:11:21 +00007755 gen_addr_spe_imm_index(ctx, t0, sh); \
aurel326a6ae232008-11-27 19:30:47 +00007756 } else { \
aurel3276db3ba2008-12-08 18:11:21 +00007757 gen_addr_reg_index(ctx, t0); \
aurel326a6ae232008-11-27 19:30:47 +00007758 } \
7759 gen_op_##name(ctx, t0); \
7760 tcg_temp_free(t0); \
7761}
7762
7763GEN_SPEOP_LDST(evldd, 0x00, 3);
7764GEN_SPEOP_LDST(evldw, 0x01, 3);
7765GEN_SPEOP_LDST(evldh, 0x02, 3);
7766GEN_SPEOP_LDST(evlhhesplat, 0x04, 1);
7767GEN_SPEOP_LDST(evlhhousplat, 0x06, 1);
7768GEN_SPEOP_LDST(evlhhossplat, 0x07, 1);
7769GEN_SPEOP_LDST(evlwhe, 0x08, 2);
7770GEN_SPEOP_LDST(evlwhou, 0x0A, 2);
7771GEN_SPEOP_LDST(evlwhos, 0x0B, 2);
7772GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2);
7773GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2);
7774
7775GEN_SPEOP_LDST(evstdd, 0x10, 3);
7776GEN_SPEOP_LDST(evstdw, 0x11, 3);
7777GEN_SPEOP_LDST(evstdh, 0x12, 3);
7778GEN_SPEOP_LDST(evstwhe, 0x18, 2);
7779GEN_SPEOP_LDST(evstwho, 0x1A, 2);
7780GEN_SPEOP_LDST(evstwwe, 0x1C, 2);
7781GEN_SPEOP_LDST(evstwwo, 0x1E, 2);
j_mayer0487d6a2007-03-20 22:11:31 +00007782
7783/* Multiply and add - TODO */
7784#if 0
7785GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0x00000000, PPC_SPE);
7786GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0x00000000, PPC_SPE);
7787GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, PPC_SPE);
7788GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0x00000000, PPC_SPE);
7789GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, PPC_SPE);
7790GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0x00000000, PPC_SPE);
7791GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0x00000000, PPC_SPE);
7792GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0x00000000, PPC_SPE);
7793GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, PPC_SPE);
7794GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0x00000000, PPC_SPE);
7795GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, PPC_SPE);
7796GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0x00000000, PPC_SPE);
7797
7798GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0x00000000, PPC_SPE);
7799GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, PPC_SPE);
7800GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, PPC_SPE);
7801GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0x00000000, PPC_SPE);
7802GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0x00000000, PPC_SPE);
j_mayer0487d6a2007-03-20 22:11:31 +00007803GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0x00000000, PPC_SPE);
7804GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0x00000000, PPC_SPE);
7805GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, PPC_SPE);
7806GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, PPC_SPE);
7807GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0x00000000, PPC_SPE);
7808GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0x00000000, PPC_SPE);
j_mayer0487d6a2007-03-20 22:11:31 +00007809GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0x00000000, PPC_SPE);
7810
7811GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, PPC_SPE);
7812GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, PPC_SPE);
7813GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, PPC_SPE);
7814GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, PPC_SPE);
7815GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, PPC_SPE);
j_mayer0487d6a2007-03-20 22:11:31 +00007816
7817GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, PPC_SPE);
7818GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0x00000000, PPC_SPE);
7819GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, PPC_SPE);
7820GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0x00000000, PPC_SPE);
7821GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, PPC_SPE);
7822GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0x00000000, PPC_SPE);
7823GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, PPC_SPE);
7824GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0x00000000, PPC_SPE);
7825GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, PPC_SPE);
7826GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0x00000000, PPC_SPE);
7827GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, PPC_SPE);
7828GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0x00000000, PPC_SPE);
7829
7830GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, PPC_SPE);
7831GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, PPC_SPE);
7832GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0x00000000, PPC_SPE);
j_mayer0487d6a2007-03-20 22:11:31 +00007833GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0x00000000, PPC_SPE);
7834
7835GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, PPC_SPE);
7836GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0x00000000, PPC_SPE);
7837GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, PPC_SPE);
7838GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0x00000000, PPC_SPE);
7839GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, PPC_SPE);
7840GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0x00000000, PPC_SPE);
7841GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, PPC_SPE);
7842GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0x00000000, PPC_SPE);
7843GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, PPC_SPE);
7844GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0x00000000, PPC_SPE);
7845GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, PPC_SPE);
7846GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0x00000000, PPC_SPE);
7847
7848GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, PPC_SPE);
7849GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, PPC_SPE);
7850GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0x00000000, PPC_SPE);
7851GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, PPC_SPE);
7852GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0x00000000, PPC_SPE);
7853#endif
7854
7855/*** SPE floating-point extension ***/
aurel321c978562008-11-23 10:54:04 +00007856#if defined(TARGET_PPC64)
7857#define GEN_SPEFPUOP_CONV_32_32(name) \
Blue Swirl636aa202009-08-16 09:06:54 +00007858static inline void gen_##name(DisasContext *ctx) \
j_mayer0487d6a2007-03-20 22:11:31 +00007859{ \
aurel321c978562008-11-23 10:54:04 +00007860 TCGv_i32 t0; \
7861 TCGv t1; \
7862 t0 = tcg_temp_new_i32(); \
7863 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
7864 gen_helper_##name(t0, t0); \
7865 t1 = tcg_temp_new(); \
7866 tcg_gen_extu_i32_tl(t1, t0); \
7867 tcg_temp_free_i32(t0); \
7868 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
7869 0xFFFFFFFF00000000ULL); \
7870 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
7871 tcg_temp_free(t1); \
j_mayer0487d6a2007-03-20 22:11:31 +00007872}
aurel321c978562008-11-23 10:54:04 +00007873#define GEN_SPEFPUOP_CONV_32_64(name) \
Blue Swirl636aa202009-08-16 09:06:54 +00007874static inline void gen_##name(DisasContext *ctx) \
aurel321c978562008-11-23 10:54:04 +00007875{ \
7876 TCGv_i32 t0; \
7877 TCGv t1; \
7878 t0 = tcg_temp_new_i32(); \
7879 gen_helper_##name(t0, cpu_gpr[rB(ctx->opcode)]); \
7880 t1 = tcg_temp_new(); \
7881 tcg_gen_extu_i32_tl(t1, t0); \
7882 tcg_temp_free_i32(t0); \
7883 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
7884 0xFFFFFFFF00000000ULL); \
7885 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
7886 tcg_temp_free(t1); \
7887}
7888#define GEN_SPEFPUOP_CONV_64_32(name) \
Blue Swirl636aa202009-08-16 09:06:54 +00007889static inline void gen_##name(DisasContext *ctx) \
aurel321c978562008-11-23 10:54:04 +00007890{ \
7891 TCGv_i32 t0 = tcg_temp_new_i32(); \
7892 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
7893 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], t0); \
7894 tcg_temp_free_i32(t0); \
7895}
7896#define GEN_SPEFPUOP_CONV_64_64(name) \
Blue Swirl636aa202009-08-16 09:06:54 +00007897static inline void gen_##name(DisasContext *ctx) \
aurel321c978562008-11-23 10:54:04 +00007898{ \
7899 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
7900}
7901#define GEN_SPEFPUOP_ARITH2_32_32(name) \
Blue Swirl636aa202009-08-16 09:06:54 +00007902static inline void gen_##name(DisasContext *ctx) \
aurel321c978562008-11-23 10:54:04 +00007903{ \
7904 TCGv_i32 t0, t1; \
7905 TCGv_i64 t2; \
7906 if (unlikely(!ctx->spe_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00007907 gen_exception(ctx, POWERPC_EXCP_APU); \
aurel321c978562008-11-23 10:54:04 +00007908 return; \
7909 } \
7910 t0 = tcg_temp_new_i32(); \
7911 t1 = tcg_temp_new_i32(); \
7912 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7913 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
7914 gen_helper_##name(t0, t0, t1); \
7915 tcg_temp_free_i32(t1); \
7916 t2 = tcg_temp_new(); \
7917 tcg_gen_extu_i32_tl(t2, t0); \
7918 tcg_temp_free_i32(t0); \
7919 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
7920 0xFFFFFFFF00000000ULL); \
7921 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
7922 tcg_temp_free(t2); \
7923}
7924#define GEN_SPEFPUOP_ARITH2_64_64(name) \
Blue Swirl636aa202009-08-16 09:06:54 +00007925static inline void gen_##name(DisasContext *ctx) \
aurel3257951c22008-11-10 11:10:23 +00007926{ \
7927 if (unlikely(!ctx->spe_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00007928 gen_exception(ctx, POWERPC_EXCP_APU); \
aurel3257951c22008-11-10 11:10:23 +00007929 return; \
7930 } \
aurel321c978562008-11-23 10:54:04 +00007931 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7932 cpu_gpr[rB(ctx->opcode)]); \
aurel3257951c22008-11-10 11:10:23 +00007933}
aurel321c978562008-11-23 10:54:04 +00007934#define GEN_SPEFPUOP_COMP_32(name) \
Blue Swirl636aa202009-08-16 09:06:54 +00007935static inline void gen_##name(DisasContext *ctx) \
aurel321c978562008-11-23 10:54:04 +00007936{ \
7937 TCGv_i32 t0, t1; \
7938 if (unlikely(!ctx->spe_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00007939 gen_exception(ctx, POWERPC_EXCP_APU); \
aurel321c978562008-11-23 10:54:04 +00007940 return; \
7941 } \
7942 t0 = tcg_temp_new_i32(); \
7943 t1 = tcg_temp_new_i32(); \
7944 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7945 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
7946 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], t0, t1); \
7947 tcg_temp_free_i32(t0); \
7948 tcg_temp_free_i32(t1); \
7949}
7950#define GEN_SPEFPUOP_COMP_64(name) \
Blue Swirl636aa202009-08-16 09:06:54 +00007951static inline void gen_##name(DisasContext *ctx) \
aurel3257951c22008-11-10 11:10:23 +00007952{ \
7953 if (unlikely(!ctx->spe_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00007954 gen_exception(ctx, POWERPC_EXCP_APU); \
aurel3257951c22008-11-10 11:10:23 +00007955 return; \
7956 } \
aurel321c978562008-11-23 10:54:04 +00007957 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
7958 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
aurel3257951c22008-11-10 11:10:23 +00007959}
aurel321c978562008-11-23 10:54:04 +00007960#else
7961#define GEN_SPEFPUOP_CONV_32_32(name) \
Blue Swirl636aa202009-08-16 09:06:54 +00007962static inline void gen_##name(DisasContext *ctx) \
aurel3257951c22008-11-10 11:10:23 +00007963{ \
aurel321c978562008-11-23 10:54:04 +00007964 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
7965}
7966#define GEN_SPEFPUOP_CONV_32_64(name) \
Blue Swirl636aa202009-08-16 09:06:54 +00007967static inline void gen_##name(DisasContext *ctx) \
aurel321c978562008-11-23 10:54:04 +00007968{ \
7969 TCGv_i64 t0 = tcg_temp_new_i64(); \
7970 gen_load_gpr64(t0, rB(ctx->opcode)); \
7971 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], t0); \
7972 tcg_temp_free_i64(t0); \
7973}
7974#define GEN_SPEFPUOP_CONV_64_32(name) \
Blue Swirl636aa202009-08-16 09:06:54 +00007975static inline void gen_##name(DisasContext *ctx) \
aurel321c978562008-11-23 10:54:04 +00007976{ \
7977 TCGv_i64 t0 = tcg_temp_new_i64(); \
7978 gen_helper_##name(t0, cpu_gpr[rB(ctx->opcode)]); \
7979 gen_store_gpr64(rD(ctx->opcode), t0); \
7980 tcg_temp_free_i64(t0); \
7981}
7982#define GEN_SPEFPUOP_CONV_64_64(name) \
Blue Swirl636aa202009-08-16 09:06:54 +00007983static inline void gen_##name(DisasContext *ctx) \
aurel321c978562008-11-23 10:54:04 +00007984{ \
7985 TCGv_i64 t0 = tcg_temp_new_i64(); \
7986 gen_load_gpr64(t0, rB(ctx->opcode)); \
7987 gen_helper_##name(t0, t0); \
7988 gen_store_gpr64(rD(ctx->opcode), t0); \
7989 tcg_temp_free_i64(t0); \
7990}
7991#define GEN_SPEFPUOP_ARITH2_32_32(name) \
Blue Swirl636aa202009-08-16 09:06:54 +00007992static inline void gen_##name(DisasContext *ctx) \
aurel321c978562008-11-23 10:54:04 +00007993{ \
aurel3257951c22008-11-10 11:10:23 +00007994 if (unlikely(!ctx->spe_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00007995 gen_exception(ctx, POWERPC_EXCP_APU); \
aurel3257951c22008-11-10 11:10:23 +00007996 return; \
7997 } \
aurel321c978562008-11-23 10:54:04 +00007998 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], \
7999 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
aurel3257951c22008-11-10 11:10:23 +00008000}
aurel321c978562008-11-23 10:54:04 +00008001#define GEN_SPEFPUOP_ARITH2_64_64(name) \
Blue Swirl636aa202009-08-16 09:06:54 +00008002static inline void gen_##name(DisasContext *ctx) \
aurel321c978562008-11-23 10:54:04 +00008003{ \
8004 TCGv_i64 t0, t1; \
8005 if (unlikely(!ctx->spe_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00008006 gen_exception(ctx, POWERPC_EXCP_APU); \
aurel321c978562008-11-23 10:54:04 +00008007 return; \
8008 } \
8009 t0 = tcg_temp_new_i64(); \
8010 t1 = tcg_temp_new_i64(); \
8011 gen_load_gpr64(t0, rA(ctx->opcode)); \
8012 gen_load_gpr64(t1, rB(ctx->opcode)); \
8013 gen_helper_##name(t0, t0, t1); \
8014 gen_store_gpr64(rD(ctx->opcode), t0); \
8015 tcg_temp_free_i64(t0); \
8016 tcg_temp_free_i64(t1); \
8017}
8018#define GEN_SPEFPUOP_COMP_32(name) \
Blue Swirl636aa202009-08-16 09:06:54 +00008019static inline void gen_##name(DisasContext *ctx) \
aurel321c978562008-11-23 10:54:04 +00008020{ \
8021 if (unlikely(!ctx->spe_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00008022 gen_exception(ctx, POWERPC_EXCP_APU); \
aurel321c978562008-11-23 10:54:04 +00008023 return; \
8024 } \
8025 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8026 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8027}
8028#define GEN_SPEFPUOP_COMP_64(name) \
Blue Swirl636aa202009-08-16 09:06:54 +00008029static inline void gen_##name(DisasContext *ctx) \
aurel321c978562008-11-23 10:54:04 +00008030{ \
8031 TCGv_i64 t0, t1; \
8032 if (unlikely(!ctx->spe_enabled)) { \
aurel32e06fcd72008-12-11 22:42:14 +00008033 gen_exception(ctx, POWERPC_EXCP_APU); \
aurel321c978562008-11-23 10:54:04 +00008034 return; \
8035 } \
8036 t0 = tcg_temp_new_i64(); \
8037 t1 = tcg_temp_new_i64(); \
8038 gen_load_gpr64(t0, rA(ctx->opcode)); \
8039 gen_load_gpr64(t1, rB(ctx->opcode)); \
8040 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], t0, t1); \
8041 tcg_temp_free_i64(t0); \
8042 tcg_temp_free_i64(t1); \
8043}
8044#endif
aurel3257951c22008-11-10 11:10:23 +00008045
j_mayer0487d6a2007-03-20 22:11:31 +00008046/* Single precision floating-point vectors operations */
8047/* Arithmetic */
aurel321c978562008-11-23 10:54:04 +00008048GEN_SPEFPUOP_ARITH2_64_64(evfsadd);
8049GEN_SPEFPUOP_ARITH2_64_64(evfssub);
8050GEN_SPEFPUOP_ARITH2_64_64(evfsmul);
8051GEN_SPEFPUOP_ARITH2_64_64(evfsdiv);
Blue Swirl636aa202009-08-16 09:06:54 +00008052static inline void gen_evfsabs(DisasContext *ctx)
aurel321c978562008-11-23 10:54:04 +00008053{
8054 if (unlikely(!ctx->spe_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00008055 gen_exception(ctx, POWERPC_EXCP_APU);
aurel321c978562008-11-23 10:54:04 +00008056 return;
8057 }
8058#if defined(TARGET_PPC64)
Mike Pall6d5c34f2010-12-31 21:17:53 +01008059 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000080000000LL);
aurel321c978562008-11-23 10:54:04 +00008060#else
Mike Pall6d5c34f2010-12-31 21:17:53 +01008061 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x80000000);
8062 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
aurel321c978562008-11-23 10:54:04 +00008063#endif
8064}
Blue Swirl636aa202009-08-16 09:06:54 +00008065static inline void gen_evfsnabs(DisasContext *ctx)
aurel321c978562008-11-23 10:54:04 +00008066{
8067 if (unlikely(!ctx->spe_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00008068 gen_exception(ctx, POWERPC_EXCP_APU);
aurel321c978562008-11-23 10:54:04 +00008069 return;
8070 }
8071#if defined(TARGET_PPC64)
Mike Pall6d5c34f2010-12-31 21:17:53 +01008072 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
aurel321c978562008-11-23 10:54:04 +00008073#else
Mike Pall6d5c34f2010-12-31 21:17:53 +01008074 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
8075 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
aurel321c978562008-11-23 10:54:04 +00008076#endif
8077}
Blue Swirl636aa202009-08-16 09:06:54 +00008078static inline void gen_evfsneg(DisasContext *ctx)
aurel321c978562008-11-23 10:54:04 +00008079{
8080 if (unlikely(!ctx->spe_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00008081 gen_exception(ctx, POWERPC_EXCP_APU);
aurel321c978562008-11-23 10:54:04 +00008082 return;
8083 }
8084#if defined(TARGET_PPC64)
Mike Pall6d5c34f2010-12-31 21:17:53 +01008085 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
aurel321c978562008-11-23 10:54:04 +00008086#else
Mike Pall6d5c34f2010-12-31 21:17:53 +01008087 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
8088 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
aurel321c978562008-11-23 10:54:04 +00008089#endif
8090}
8091
j_mayer0487d6a2007-03-20 22:11:31 +00008092/* Conversion */
aurel321c978562008-11-23 10:54:04 +00008093GEN_SPEFPUOP_CONV_64_64(evfscfui);
8094GEN_SPEFPUOP_CONV_64_64(evfscfsi);
8095GEN_SPEFPUOP_CONV_64_64(evfscfuf);
8096GEN_SPEFPUOP_CONV_64_64(evfscfsf);
8097GEN_SPEFPUOP_CONV_64_64(evfsctui);
8098GEN_SPEFPUOP_CONV_64_64(evfsctsi);
8099GEN_SPEFPUOP_CONV_64_64(evfsctuf);
8100GEN_SPEFPUOP_CONV_64_64(evfsctsf);
8101GEN_SPEFPUOP_CONV_64_64(evfsctuiz);
8102GEN_SPEFPUOP_CONV_64_64(evfsctsiz);
8103
j_mayer0487d6a2007-03-20 22:11:31 +00008104/* Comparison */
aurel321c978562008-11-23 10:54:04 +00008105GEN_SPEFPUOP_COMP_64(evfscmpgt);
8106GEN_SPEFPUOP_COMP_64(evfscmplt);
8107GEN_SPEFPUOP_COMP_64(evfscmpeq);
8108GEN_SPEFPUOP_COMP_64(evfststgt);
8109GEN_SPEFPUOP_COMP_64(evfststlt);
8110GEN_SPEFPUOP_COMP_64(evfststeq);
j_mayer0487d6a2007-03-20 22:11:31 +00008111
8112/* Opcodes definitions */
aurel3240569b72009-02-09 16:49:50 +00008113GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, PPC_SPE_SINGLE); //
8114GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, PPC_SPE_SINGLE); //
8115GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, PPC_SPE_SINGLE); //
8116GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, PPC_SPE_SINGLE); //
8117GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, PPC_SPE_SINGLE); //
8118GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, PPC_SPE_SINGLE); //
8119GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, PPC_SPE_SINGLE); //
8120GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, PPC_SPE_SINGLE); //
8121GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, PPC_SPE_SINGLE); //
8122GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, PPC_SPE_SINGLE); //
8123GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, PPC_SPE_SINGLE); //
8124GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, PPC_SPE_SINGLE); //
8125GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, PPC_SPE_SINGLE); //
8126GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, PPC_SPE_SINGLE); //
j_mayer0487d6a2007-03-20 22:11:31 +00008127
8128/* Single precision floating-point operations */
8129/* Arithmetic */
aurel321c978562008-11-23 10:54:04 +00008130GEN_SPEFPUOP_ARITH2_32_32(efsadd);
8131GEN_SPEFPUOP_ARITH2_32_32(efssub);
8132GEN_SPEFPUOP_ARITH2_32_32(efsmul);
8133GEN_SPEFPUOP_ARITH2_32_32(efsdiv);
Blue Swirl636aa202009-08-16 09:06:54 +00008134static inline void gen_efsabs(DisasContext *ctx)
aurel321c978562008-11-23 10:54:04 +00008135{
8136 if (unlikely(!ctx->spe_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00008137 gen_exception(ctx, POWERPC_EXCP_APU);
aurel321c978562008-11-23 10:54:04 +00008138 return;
8139 }
Mike Pall6d5c34f2010-12-31 21:17:53 +01008140 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL);
aurel321c978562008-11-23 10:54:04 +00008141}
Blue Swirl636aa202009-08-16 09:06:54 +00008142static inline void gen_efsnabs(DisasContext *ctx)
aurel321c978562008-11-23 10:54:04 +00008143{
8144 if (unlikely(!ctx->spe_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00008145 gen_exception(ctx, POWERPC_EXCP_APU);
aurel321c978562008-11-23 10:54:04 +00008146 return;
8147 }
Mike Pall6d5c34f2010-12-31 21:17:53 +01008148 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
aurel321c978562008-11-23 10:54:04 +00008149}
Blue Swirl636aa202009-08-16 09:06:54 +00008150static inline void gen_efsneg(DisasContext *ctx)
aurel321c978562008-11-23 10:54:04 +00008151{
8152 if (unlikely(!ctx->spe_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00008153 gen_exception(ctx, POWERPC_EXCP_APU);
aurel321c978562008-11-23 10:54:04 +00008154 return;
8155 }
Mike Pall6d5c34f2010-12-31 21:17:53 +01008156 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
aurel321c978562008-11-23 10:54:04 +00008157}
8158
j_mayer0487d6a2007-03-20 22:11:31 +00008159/* Conversion */
aurel321c978562008-11-23 10:54:04 +00008160GEN_SPEFPUOP_CONV_32_32(efscfui);
8161GEN_SPEFPUOP_CONV_32_32(efscfsi);
8162GEN_SPEFPUOP_CONV_32_32(efscfuf);
8163GEN_SPEFPUOP_CONV_32_32(efscfsf);
8164GEN_SPEFPUOP_CONV_32_32(efsctui);
8165GEN_SPEFPUOP_CONV_32_32(efsctsi);
8166GEN_SPEFPUOP_CONV_32_32(efsctuf);
8167GEN_SPEFPUOP_CONV_32_32(efsctsf);
8168GEN_SPEFPUOP_CONV_32_32(efsctuiz);
8169GEN_SPEFPUOP_CONV_32_32(efsctsiz);
8170GEN_SPEFPUOP_CONV_32_64(efscfd);
8171
j_mayer0487d6a2007-03-20 22:11:31 +00008172/* Comparison */
aurel321c978562008-11-23 10:54:04 +00008173GEN_SPEFPUOP_COMP_32(efscmpgt);
8174GEN_SPEFPUOP_COMP_32(efscmplt);
8175GEN_SPEFPUOP_COMP_32(efscmpeq);
8176GEN_SPEFPUOP_COMP_32(efststgt);
8177GEN_SPEFPUOP_COMP_32(efststlt);
8178GEN_SPEFPUOP_COMP_32(efststeq);
j_mayer0487d6a2007-03-20 22:11:31 +00008179
8180/* Opcodes definitions */
aurel3240569b72009-02-09 16:49:50 +00008181GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, PPC_SPE_SINGLE); //
8182GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, PPC_SPE_SINGLE); //
8183GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, PPC_SPE_SINGLE); //
8184GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, PPC_SPE_SINGLE); //
8185GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, PPC_SPE_SINGLE); //
8186GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, PPC_SPE_SINGLE); //
8187GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, PPC_SPE_SINGLE); //
8188GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, PPC_SPE_SINGLE); //
8189GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, PPC_SPE_SINGLE); //
8190GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, PPC_SPE_SINGLE); //
8191GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, PPC_SPE_SINGLE); //
8192GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, PPC_SPE_SINGLE); //
8193GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, PPC_SPE_SINGLE); //
8194GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, PPC_SPE_SINGLE); //
j_mayer0487d6a2007-03-20 22:11:31 +00008195
8196/* Double precision floating-point operations */
8197/* Arithmetic */
aurel321c978562008-11-23 10:54:04 +00008198GEN_SPEFPUOP_ARITH2_64_64(efdadd);
8199GEN_SPEFPUOP_ARITH2_64_64(efdsub);
8200GEN_SPEFPUOP_ARITH2_64_64(efdmul);
8201GEN_SPEFPUOP_ARITH2_64_64(efddiv);
Blue Swirl636aa202009-08-16 09:06:54 +00008202static inline void gen_efdabs(DisasContext *ctx)
aurel321c978562008-11-23 10:54:04 +00008203{
8204 if (unlikely(!ctx->spe_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00008205 gen_exception(ctx, POWERPC_EXCP_APU);
aurel321c978562008-11-23 10:54:04 +00008206 return;
8207 }
8208#if defined(TARGET_PPC64)
Mike Pall6d5c34f2010-12-31 21:17:53 +01008209 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000000000000LL);
aurel321c978562008-11-23 10:54:04 +00008210#else
Mike Pall6d5c34f2010-12-31 21:17:53 +01008211 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8212 tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
aurel321c978562008-11-23 10:54:04 +00008213#endif
8214}
Blue Swirl636aa202009-08-16 09:06:54 +00008215static inline void gen_efdnabs(DisasContext *ctx)
aurel321c978562008-11-23 10:54:04 +00008216{
8217 if (unlikely(!ctx->spe_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00008218 gen_exception(ctx, POWERPC_EXCP_APU);
aurel321c978562008-11-23 10:54:04 +00008219 return;
8220 }
8221#if defined(TARGET_PPC64)
Mike Pall6d5c34f2010-12-31 21:17:53 +01008222 tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
aurel321c978562008-11-23 10:54:04 +00008223#else
Mike Pall6d5c34f2010-12-31 21:17:53 +01008224 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8225 tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
aurel321c978562008-11-23 10:54:04 +00008226#endif
8227}
Blue Swirl636aa202009-08-16 09:06:54 +00008228static inline void gen_efdneg(DisasContext *ctx)
aurel321c978562008-11-23 10:54:04 +00008229{
8230 if (unlikely(!ctx->spe_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00008231 gen_exception(ctx, POWERPC_EXCP_APU);
aurel321c978562008-11-23 10:54:04 +00008232 return;
8233 }
8234#if defined(TARGET_PPC64)
Mike Pall6d5c34f2010-12-31 21:17:53 +01008235 tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
aurel321c978562008-11-23 10:54:04 +00008236#else
Mike Pall6d5c34f2010-12-31 21:17:53 +01008237 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8238 tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
aurel321c978562008-11-23 10:54:04 +00008239#endif
8240}
j_mayer0487d6a2007-03-20 22:11:31 +00008241
aurel321c978562008-11-23 10:54:04 +00008242/* Conversion */
8243GEN_SPEFPUOP_CONV_64_32(efdcfui);
8244GEN_SPEFPUOP_CONV_64_32(efdcfsi);
8245GEN_SPEFPUOP_CONV_64_32(efdcfuf);
8246GEN_SPEFPUOP_CONV_64_32(efdcfsf);
8247GEN_SPEFPUOP_CONV_32_64(efdctui);
8248GEN_SPEFPUOP_CONV_32_64(efdctsi);
8249GEN_SPEFPUOP_CONV_32_64(efdctuf);
8250GEN_SPEFPUOP_CONV_32_64(efdctsf);
8251GEN_SPEFPUOP_CONV_32_64(efdctuiz);
8252GEN_SPEFPUOP_CONV_32_64(efdctsiz);
8253GEN_SPEFPUOP_CONV_64_32(efdcfs);
8254GEN_SPEFPUOP_CONV_64_64(efdcfuid);
8255GEN_SPEFPUOP_CONV_64_64(efdcfsid);
8256GEN_SPEFPUOP_CONV_64_64(efdctuidz);
8257GEN_SPEFPUOP_CONV_64_64(efdctsidz);
8258
j_mayer0487d6a2007-03-20 22:11:31 +00008259/* Comparison */
aurel321c978562008-11-23 10:54:04 +00008260GEN_SPEFPUOP_COMP_64(efdcmpgt);
8261GEN_SPEFPUOP_COMP_64(efdcmplt);
8262GEN_SPEFPUOP_COMP_64(efdcmpeq);
8263GEN_SPEFPUOP_COMP_64(efdtstgt);
8264GEN_SPEFPUOP_COMP_64(efdtstlt);
8265GEN_SPEFPUOP_COMP_64(efdtsteq);
j_mayer0487d6a2007-03-20 22:11:31 +00008266
8267/* Opcodes definitions */
aurel3240569b72009-02-09 16:49:50 +00008268GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, PPC_SPE_DOUBLE); //
8269GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, PPC_SPE_DOUBLE); //
8270GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, PPC_SPE_DOUBLE); //
8271GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, PPC_SPE_DOUBLE); //
8272GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, PPC_SPE_DOUBLE); //
8273GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, PPC_SPE_DOUBLE); //
8274GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, PPC_SPE_DOUBLE); //
8275GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, PPC_SPE_DOUBLE); //
8276GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, PPC_SPE_DOUBLE); //
8277GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, PPC_SPE_DOUBLE); //
8278GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, PPC_SPE_DOUBLE); //
8279GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, PPC_SPE_DOUBLE); //
8280GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, PPC_SPE_DOUBLE); //
8281GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, PPC_SPE_DOUBLE); //
8282GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, PPC_SPE_DOUBLE); //
8283GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, PPC_SPE_DOUBLE); //
j_mayer0487d6a2007-03-20 22:11:31 +00008284
Anthony Liguoric227f092009-10-01 16:12:16 -05008285static opcode_t opcodes[] = {
Blue Swirl5c55ff92009-06-17 15:22:31 +00008286GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE),
8287GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER),
8288GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
8289GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER),
8290GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
8291GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL),
8292GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8293GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8294GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8295GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8296GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER),
8297GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER),
8298GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER),
8299GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER),
8300GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8301#if defined(TARGET_PPC64)
8302GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B),
8303#endif
8304GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER),
8305GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER),
8306GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8307GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8308GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8309GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER),
8310GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER),
8311GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER),
8312GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8313GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8314GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8315GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8316GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB),
David Gibsoneaabeef2011-04-01 15:15:13 +11008317GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD),
Blue Swirl5c55ff92009-06-17 15:22:31 +00008318#if defined(TARGET_PPC64)
David Gibsoneaabeef2011-04-01 15:15:13 +11008319GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD),
Blue Swirl5c55ff92009-06-17 15:22:31 +00008320GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B),
8321#endif
8322GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8323GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8324GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8325GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER),
8326GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER),
8327GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER),
8328GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER),
8329#if defined(TARGET_PPC64)
8330GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B),
8331GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B),
8332GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B),
8333GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B),
8334GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B),
8335#endif
8336GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES),
8337GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
8338GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
8339GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT),
8340GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT),
8341GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT),
8342GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT),
8343GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT),
8344GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT),
8345GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT),
8346GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00010000, PPC_FLOAT),
8347GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT),
8348#if defined(TARGET_PPC64)
8349GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B),
8350GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX),
8351GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B),
8352#endif
8353GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8354GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8355GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING),
8356GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING),
8357GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING),
8358GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING),
8359GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO),
8360GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM),
Alexander Graff844c812010-09-10 15:08:33 +00008361GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES),
Blue Swirl5c55ff92009-06-17 15:22:31 +00008362GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES),
8363#if defined(TARGET_PPC64)
Alexander Graff844c812010-09-10 15:08:33 +00008364GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B),
Blue Swirl5c55ff92009-06-17 15:22:31 +00008365GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B),
8366#endif
8367GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC),
8368GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT),
8369GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
8370GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
8371GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW),
8372GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW),
8373GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER),
8374GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW),
8375#if defined(TARGET_PPC64)
8376GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B),
8377GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H),
8378#endif
8379GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW),
8380GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW),
8381GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
8382#if defined(TARGET_PPC64)
8383GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B),
8384GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B),
8385#endif
8386GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC),
8387GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC),
8388GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC),
8389GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC),
8390GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB),
8391GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC),
8392#if defined(TARGET_PPC64)
8393GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B),
8394#endif
8395GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC),
8396GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC),
8397GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE),
8398GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE),
8399GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE),
8400GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE),
8401GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE),
8402GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE_DCBZ),
8403GEN_HANDLER2(dcbz_970, "dcbz", 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZT),
8404GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC),
8405GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC),
8406GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC),
8407GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI),
8408GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA),
8409GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT),
8410GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT),
8411GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT),
8412GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT),
8413#if defined(TARGET_PPC64)
8414GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B),
8415GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
8416 PPC_SEGMENT_64B),
8417GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B),
8418GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
8419 PPC_SEGMENT_64B),
David Gibsonefdef952011-04-01 15:15:11 +11008420GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B),
8421GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B),
8422GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B),
Blue Swirl5c55ff92009-06-17 15:22:31 +00008423#endif
8424GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA),
8425GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE),
8426GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE),
8427GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC),
8428#if defined(TARGET_PPC64)
8429GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI),
8430GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI),
8431#endif
8432GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN),
8433GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN),
8434GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR),
8435GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR),
8436GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR),
8437GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR),
8438GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR),
8439GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR),
8440GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR),
8441GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR),
8442GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR),
8443GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
8444GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR),
8445GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR),
8446GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR),
8447GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR),
8448GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR),
8449GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR),
8450GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR),
8451GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
8452GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR),
8453GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR),
8454GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR),
8455GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR),
8456GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR),
8457GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR),
8458GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR),
8459GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR),
8460GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR),
8461GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR),
8462GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR),
8463GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR),
8464GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR),
8465GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR),
8466GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR),
8467GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR),
8468GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC),
8469GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC),
8470GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC),
8471GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB),
8472GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB),
8473GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB),
8474GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB),
8475GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER),
8476GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER),
8477GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER),
8478GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER),
8479GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER),
8480GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER),
8481GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
8482GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
8483GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2),
8484GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2),
8485GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
8486GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
8487GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2),
8488GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2),
8489GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI),
8490GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA),
8491GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR),
8492GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR),
8493GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX),
8494GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX),
8495GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX),
8496GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX),
8497GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON),
8498GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON),
8499GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT),
8500GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON),
8501GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON),
8502GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP),
Alexander Graf01662f32011-04-30 23:34:58 +02008503GEN_HANDLER_E(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE, PPC2_BOOKE206),
Blue Swirl5c55ff92009-06-17 15:22:31 +00008504GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI),
8505GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI),
8506GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB),
8507GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB),
8508GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB),
8509GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE),
8510GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE),
8511GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE),
Alexander Graf01662f32011-04-30 23:34:58 +02008512GEN_HANDLER2_E(tlbre_booke206, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
8513 PPC_NONE, PPC2_BOOKE206),
8514GEN_HANDLER2_E(tlbsx_booke206, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
8515 PPC_NONE, PPC2_BOOKE206),
8516GEN_HANDLER2_E(tlbwe_booke206, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
8517 PPC_NONE, PPC2_BOOKE206),
8518GEN_HANDLER2_E(tlbivax_booke206, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
8519 PPC_NONE, PPC2_BOOKE206),
Blue Swirl5c55ff92009-06-17 15:22:31 +00008520GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE),
Baojun Wangfbe73002009-07-03 18:56:57 +08008521GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE),
Blue Swirl5c55ff92009-06-17 15:22:31 +00008522GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC),
Alexander Graf01662f32011-04-30 23:34:58 +02008523GEN_HANDLER_E(mbar, 0x1F, 0x16, 0x1a, 0x001FF801,
8524 PPC_BOOKE, PPC2_BOOKE206),
8525GEN_HANDLER_E(msync, 0x1F, 0x16, 0x12, 0x03FFF801,
8526 PPC_BOOKE, PPC2_BOOKE206),
8527GEN_HANDLER2_E(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
8528 PPC_BOOKE, PPC2_BOOKE206),
Blue Swirl5c55ff92009-06-17 15:22:31 +00008529GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC),
8530GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC),
8531GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC),
8532GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC),
8533GEN_HANDLER(vsldoi, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC),
8534GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC),
8535GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE),
8536GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE),
8537GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE),
8538GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE),
8539
8540#undef GEN_INT_ARITH_ADD
8541#undef GEN_INT_ARITH_ADD_CONST
8542#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
8543GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
8544#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
8545 add_ca, compute_ca, compute_ov) \
8546GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
8547GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
8548GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
8549GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
8550GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
8551GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
8552GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
8553GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
8554GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
8555GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
8556GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
8557
8558#undef GEN_INT_ARITH_DIVW
8559#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
8560GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
8561GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0),
8562GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1),
8563GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0),
8564GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1),
8565
8566#if defined(TARGET_PPC64)
8567#undef GEN_INT_ARITH_DIVD
8568#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
8569GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8570GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0),
8571GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1),
8572GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0),
8573GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1),
8574
8575#undef GEN_INT_ARITH_MUL_HELPER
8576#define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
8577GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8578GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00),
8579GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02),
8580GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17),
8581#endif
8582
8583#undef GEN_INT_ARITH_SUBF
8584#undef GEN_INT_ARITH_SUBF_CONST
8585#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
8586GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
8587#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
8588 add_ca, compute_ca, compute_ov) \
8589GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
8590GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
8591GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
8592GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
8593GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
8594GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
8595GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
8596GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
8597GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
8598GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
8599GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
8600
8601#undef GEN_LOGICAL1
8602#undef GEN_LOGICAL2
8603#define GEN_LOGICAL2(name, tcg_op, opc, type) \
8604GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
8605#define GEN_LOGICAL1(name, tcg_op, opc, type) \
8606GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
8607GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER),
8608GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER),
8609GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER),
8610GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER),
8611GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER),
8612GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER),
8613GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER),
8614GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER),
8615#if defined(TARGET_PPC64)
8616GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B),
8617#endif
8618
8619#if defined(TARGET_PPC64)
8620#undef GEN_PPC64_R2
8621#undef GEN_PPC64_R4
8622#define GEN_PPC64_R2(name, opc1, opc2) \
8623GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8624GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8625 PPC_64B)
8626#define GEN_PPC64_R4(name, opc1, opc2) \
8627GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8628GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
8629 PPC_64B), \
8630GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8631 PPC_64B), \
8632GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
8633 PPC_64B)
8634GEN_PPC64_R4(rldicl, 0x1E, 0x00),
8635GEN_PPC64_R4(rldicr, 0x1E, 0x02),
8636GEN_PPC64_R4(rldic, 0x1E, 0x04),
8637GEN_PPC64_R2(rldcl, 0x1E, 0x08),
8638GEN_PPC64_R2(rldcr, 0x1E, 0x09),
8639GEN_PPC64_R4(rldimi, 0x1E, 0x06),
8640#endif
8641
8642#undef _GEN_FLOAT_ACB
8643#undef GEN_FLOAT_ACB
8644#undef _GEN_FLOAT_AB
8645#undef GEN_FLOAT_AB
8646#undef _GEN_FLOAT_AC
8647#undef GEN_FLOAT_AC
8648#undef GEN_FLOAT_B
8649#undef GEN_FLOAT_BS
8650#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
8651GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
8652#define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
8653_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
8654_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
8655#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
8656GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
8657#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
8658_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
8659_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
8660#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
8661GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
8662#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
8663_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
8664_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
8665#define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
8666GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
8667#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
8668GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
8669
8670GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT),
8671GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT),
8672GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT),
8673GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT),
8674GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES),
8675GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE),
8676_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL),
8677GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT),
8678GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT),
8679GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT),
8680GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT),
8681GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT),
8682GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT),
8683GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT),
8684GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT),
8685#if defined(TARGET_PPC64)
8686GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B),
8687GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B),
8688GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B),
8689#endif
8690GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT),
8691GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT),
8692GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT),
8693GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT),
8694GEN_FLOAT_B(abs, 0x08, 0x08, 0, PPC_FLOAT),
8695GEN_FLOAT_B(nabs, 0x08, 0x04, 0, PPC_FLOAT),
8696GEN_FLOAT_B(neg, 0x08, 0x01, 0, PPC_FLOAT),
8697
8698#undef GEN_LD
8699#undef GEN_LDU
8700#undef GEN_LDUX
8701#undef GEN_LDX
8702#undef GEN_LDS
8703#define GEN_LD(name, ldop, opc, type) \
8704GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8705#define GEN_LDU(name, ldop, opc, type) \
8706GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8707#define GEN_LDUX(name, ldop, opc2, opc3, type) \
8708GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
8709#define GEN_LDX(name, ldop, opc2, opc3, type) \
8710GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
8711#define GEN_LDS(name, ldop, op, type) \
8712GEN_LD(name, ldop, op | 0x20, type) \
8713GEN_LDU(name, ldop, op | 0x21, type) \
8714GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
8715GEN_LDX(name, ldop, 0x17, op | 0x00, type)
8716
8717GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER)
8718GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER)
8719GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER)
8720GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER)
8721#if defined(TARGET_PPC64)
8722GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B)
8723GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B)
8724GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B)
8725GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B)
8726#endif
8727GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER)
8728GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER)
8729
8730#undef GEN_ST
8731#undef GEN_STU
8732#undef GEN_STUX
8733#undef GEN_STX
8734#undef GEN_STS
8735#define GEN_ST(name, stop, opc, type) \
8736GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8737#define GEN_STU(name, stop, opc, type) \
8738GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
8739#define GEN_STUX(name, stop, opc2, opc3, type) \
8740GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
8741#define GEN_STX(name, stop, opc2, opc3, type) \
8742GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
8743#define GEN_STS(name, stop, op, type) \
8744GEN_ST(name, stop, op | 0x20, type) \
8745GEN_STU(name, stop, op | 0x21, type) \
8746GEN_STUX(name, stop, 0x17, op | 0x01, type) \
8747GEN_STX(name, stop, 0x17, op | 0x00, type)
8748
8749GEN_STS(stb, st8, 0x06, PPC_INTEGER)
8750GEN_STS(sth, st16, 0x0C, PPC_INTEGER)
8751GEN_STS(stw, st32, 0x04, PPC_INTEGER)
8752#if defined(TARGET_PPC64)
8753GEN_STUX(std, st64, 0x15, 0x05, PPC_64B)
8754GEN_STX(std, st64, 0x15, 0x04, PPC_64B)
8755#endif
8756GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER)
8757GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER)
8758
8759#undef GEN_LDF
8760#undef GEN_LDUF
8761#undef GEN_LDUXF
8762#undef GEN_LDXF
8763#undef GEN_LDFS
8764#define GEN_LDF(name, ldop, opc, type) \
8765GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8766#define GEN_LDUF(name, ldop, opc, type) \
8767GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8768#define GEN_LDUXF(name, ldop, opc, type) \
8769GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
8770#define GEN_LDXF(name, ldop, opc2, opc3, type) \
8771GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
8772#define GEN_LDFS(name, ldop, op, type) \
8773GEN_LDF(name, ldop, op | 0x20, type) \
8774GEN_LDUF(name, ldop, op | 0x21, type) \
8775GEN_LDUXF(name, ldop, op | 0x01, type) \
8776GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
8777
8778GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT)
8779GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT)
8780
8781#undef GEN_STF
8782#undef GEN_STUF
8783#undef GEN_STUXF
8784#undef GEN_STXF
8785#undef GEN_STFS
8786#define GEN_STF(name, stop, opc, type) \
8787GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8788#define GEN_STUF(name, stop, opc, type) \
8789GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8790#define GEN_STUXF(name, stop, opc, type) \
8791GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
8792#define GEN_STXF(name, stop, opc2, opc3, type) \
8793GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
8794#define GEN_STFS(name, stop, op, type) \
8795GEN_STF(name, stop, op | 0x20, type) \
8796GEN_STUF(name, stop, op | 0x21, type) \
8797GEN_STUXF(name, stop, op | 0x01, type) \
8798GEN_STXF(name, stop, 0x17, op | 0x00, type)
8799
8800GEN_STFS(stfd, st64, 0x16, PPC_FLOAT)
8801GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT)
8802GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX)
8803
8804#undef GEN_CRLOGIC
8805#define GEN_CRLOGIC(name, tcg_op, opc) \
8806GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
8807GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08),
8808GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04),
8809GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09),
8810GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07),
8811GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01),
8812GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E),
8813GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D),
8814GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06),
8815
8816#undef GEN_MAC_HANDLER
8817#define GEN_MAC_HANDLER(name, opc2, opc3) \
8818GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
8819GEN_MAC_HANDLER(macchw, 0x0C, 0x05),
8820GEN_MAC_HANDLER(macchwo, 0x0C, 0x15),
8821GEN_MAC_HANDLER(macchws, 0x0C, 0x07),
8822GEN_MAC_HANDLER(macchwso, 0x0C, 0x17),
8823GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06),
8824GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16),
8825GEN_MAC_HANDLER(macchwu, 0x0C, 0x04),
8826GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14),
8827GEN_MAC_HANDLER(machhw, 0x0C, 0x01),
8828GEN_MAC_HANDLER(machhwo, 0x0C, 0x11),
8829GEN_MAC_HANDLER(machhws, 0x0C, 0x03),
8830GEN_MAC_HANDLER(machhwso, 0x0C, 0x13),
8831GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02),
8832GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12),
8833GEN_MAC_HANDLER(machhwu, 0x0C, 0x00),
8834GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10),
8835GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D),
8836GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D),
8837GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F),
8838GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F),
8839GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C),
8840GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C),
8841GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E),
8842GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E),
8843GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05),
8844GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15),
8845GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07),
8846GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17),
8847GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01),
8848GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11),
8849GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03),
8850GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13),
8851GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D),
8852GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D),
8853GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F),
8854GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F),
8855GEN_MAC_HANDLER(mulchw, 0x08, 0x05),
8856GEN_MAC_HANDLER(mulchwu, 0x08, 0x04),
8857GEN_MAC_HANDLER(mulhhw, 0x08, 0x01),
8858GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00),
8859GEN_MAC_HANDLER(mullhw, 0x08, 0x0D),
8860GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C),
8861
8862#undef GEN_VR_LDX
8863#undef GEN_VR_STX
8864#undef GEN_VR_LVE
8865#undef GEN_VR_STVE
8866#define GEN_VR_LDX(name, opc2, opc3) \
8867GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
8868#define GEN_VR_STX(name, opc2, opc3) \
8869GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
8870#define GEN_VR_LVE(name, opc2, opc3) \
8871 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
8872#define GEN_VR_STVE(name, opc2, opc3) \
8873 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
8874GEN_VR_LDX(lvx, 0x07, 0x03),
8875GEN_VR_LDX(lvxl, 0x07, 0x0B),
8876GEN_VR_LVE(bx, 0x07, 0x00),
8877GEN_VR_LVE(hx, 0x07, 0x01),
8878GEN_VR_LVE(wx, 0x07, 0x02),
8879GEN_VR_STX(svx, 0x07, 0x07),
8880GEN_VR_STX(svxl, 0x07, 0x0F),
8881GEN_VR_STVE(bx, 0x07, 0x04),
8882GEN_VR_STVE(hx, 0x07, 0x05),
8883GEN_VR_STVE(wx, 0x07, 0x06),
8884
8885#undef GEN_VX_LOGICAL
8886#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
8887GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
8888GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16),
8889GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17),
8890GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18),
8891GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19),
8892GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20),
8893
8894#undef GEN_VXFORM
8895#define GEN_VXFORM(name, opc2, opc3) \
8896GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
8897GEN_VXFORM(vaddubm, 0, 0),
8898GEN_VXFORM(vadduhm, 0, 1),
8899GEN_VXFORM(vadduwm, 0, 2),
8900GEN_VXFORM(vsububm, 0, 16),
8901GEN_VXFORM(vsubuhm, 0, 17),
8902GEN_VXFORM(vsubuwm, 0, 18),
8903GEN_VXFORM(vmaxub, 1, 0),
8904GEN_VXFORM(vmaxuh, 1, 1),
8905GEN_VXFORM(vmaxuw, 1, 2),
8906GEN_VXFORM(vmaxsb, 1, 4),
8907GEN_VXFORM(vmaxsh, 1, 5),
8908GEN_VXFORM(vmaxsw, 1, 6),
8909GEN_VXFORM(vminub, 1, 8),
8910GEN_VXFORM(vminuh, 1, 9),
8911GEN_VXFORM(vminuw, 1, 10),
8912GEN_VXFORM(vminsb, 1, 12),
8913GEN_VXFORM(vminsh, 1, 13),
8914GEN_VXFORM(vminsw, 1, 14),
8915GEN_VXFORM(vavgub, 1, 16),
8916GEN_VXFORM(vavguh, 1, 17),
8917GEN_VXFORM(vavguw, 1, 18),
8918GEN_VXFORM(vavgsb, 1, 20),
8919GEN_VXFORM(vavgsh, 1, 21),
8920GEN_VXFORM(vavgsw, 1, 22),
8921GEN_VXFORM(vmrghb, 6, 0),
8922GEN_VXFORM(vmrghh, 6, 1),
8923GEN_VXFORM(vmrghw, 6, 2),
8924GEN_VXFORM(vmrglb, 6, 4),
8925GEN_VXFORM(vmrglh, 6, 5),
8926GEN_VXFORM(vmrglw, 6, 6),
8927GEN_VXFORM(vmuloub, 4, 0),
8928GEN_VXFORM(vmulouh, 4, 1),
8929GEN_VXFORM(vmulosb, 4, 4),
8930GEN_VXFORM(vmulosh, 4, 5),
8931GEN_VXFORM(vmuleub, 4, 8),
8932GEN_VXFORM(vmuleuh, 4, 9),
8933GEN_VXFORM(vmulesb, 4, 12),
8934GEN_VXFORM(vmulesh, 4, 13),
8935GEN_VXFORM(vslb, 2, 4),
8936GEN_VXFORM(vslh, 2, 5),
8937GEN_VXFORM(vslw, 2, 6),
8938GEN_VXFORM(vsrb, 2, 8),
8939GEN_VXFORM(vsrh, 2, 9),
8940GEN_VXFORM(vsrw, 2, 10),
8941GEN_VXFORM(vsrab, 2, 12),
8942GEN_VXFORM(vsrah, 2, 13),
8943GEN_VXFORM(vsraw, 2, 14),
8944GEN_VXFORM(vslo, 6, 16),
8945GEN_VXFORM(vsro, 6, 17),
8946GEN_VXFORM(vaddcuw, 0, 6),
8947GEN_VXFORM(vsubcuw, 0, 22),
8948GEN_VXFORM(vaddubs, 0, 8),
8949GEN_VXFORM(vadduhs, 0, 9),
8950GEN_VXFORM(vadduws, 0, 10),
8951GEN_VXFORM(vaddsbs, 0, 12),
8952GEN_VXFORM(vaddshs, 0, 13),
8953GEN_VXFORM(vaddsws, 0, 14),
8954GEN_VXFORM(vsububs, 0, 24),
8955GEN_VXFORM(vsubuhs, 0, 25),
8956GEN_VXFORM(vsubuws, 0, 26),
8957GEN_VXFORM(vsubsbs, 0, 28),
8958GEN_VXFORM(vsubshs, 0, 29),
8959GEN_VXFORM(vsubsws, 0, 30),
8960GEN_VXFORM(vrlb, 2, 0),
8961GEN_VXFORM(vrlh, 2, 1),
8962GEN_VXFORM(vrlw, 2, 2),
8963GEN_VXFORM(vsl, 2, 7),
8964GEN_VXFORM(vsr, 2, 11),
8965GEN_VXFORM(vpkuhum, 7, 0),
8966GEN_VXFORM(vpkuwum, 7, 1),
8967GEN_VXFORM(vpkuhus, 7, 2),
8968GEN_VXFORM(vpkuwus, 7, 3),
8969GEN_VXFORM(vpkshus, 7, 4),
8970GEN_VXFORM(vpkswus, 7, 5),
8971GEN_VXFORM(vpkshss, 7, 6),
8972GEN_VXFORM(vpkswss, 7, 7),
8973GEN_VXFORM(vpkpx, 7, 12),
8974GEN_VXFORM(vsum4ubs, 4, 24),
8975GEN_VXFORM(vsum4sbs, 4, 28),
8976GEN_VXFORM(vsum4shs, 4, 25),
8977GEN_VXFORM(vsum2sws, 4, 26),
8978GEN_VXFORM(vsumsws, 4, 30),
8979GEN_VXFORM(vaddfp, 5, 0),
8980GEN_VXFORM(vsubfp, 5, 1),
8981GEN_VXFORM(vmaxfp, 5, 16),
8982GEN_VXFORM(vminfp, 5, 17),
8983
8984#undef GEN_VXRFORM1
8985#undef GEN_VXRFORM
8986#define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
8987 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
8988#define GEN_VXRFORM(name, opc2, opc3) \
8989 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
8990 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
8991GEN_VXRFORM(vcmpequb, 3, 0)
8992GEN_VXRFORM(vcmpequh, 3, 1)
8993GEN_VXRFORM(vcmpequw, 3, 2)
8994GEN_VXRFORM(vcmpgtsb, 3, 12)
8995GEN_VXRFORM(vcmpgtsh, 3, 13)
8996GEN_VXRFORM(vcmpgtsw, 3, 14)
8997GEN_VXRFORM(vcmpgtub, 3, 8)
8998GEN_VXRFORM(vcmpgtuh, 3, 9)
8999GEN_VXRFORM(vcmpgtuw, 3, 10)
9000GEN_VXRFORM(vcmpeqfp, 3, 3)
9001GEN_VXRFORM(vcmpgefp, 3, 7)
9002GEN_VXRFORM(vcmpgtfp, 3, 11)
9003GEN_VXRFORM(vcmpbfp, 3, 15)
9004
9005#undef GEN_VXFORM_SIMM
9006#define GEN_VXFORM_SIMM(name, opc2, opc3) \
9007 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9008GEN_VXFORM_SIMM(vspltisb, 6, 12),
9009GEN_VXFORM_SIMM(vspltish, 6, 13),
9010GEN_VXFORM_SIMM(vspltisw, 6, 14),
9011
9012#undef GEN_VXFORM_NOA
9013#define GEN_VXFORM_NOA(name, opc2, opc3) \
9014 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
9015GEN_VXFORM_NOA(vupkhsb, 7, 8),
9016GEN_VXFORM_NOA(vupkhsh, 7, 9),
9017GEN_VXFORM_NOA(vupklsb, 7, 10),
9018GEN_VXFORM_NOA(vupklsh, 7, 11),
9019GEN_VXFORM_NOA(vupkhpx, 7, 13),
9020GEN_VXFORM_NOA(vupklpx, 7, 15),
9021GEN_VXFORM_NOA(vrefp, 5, 4),
9022GEN_VXFORM_NOA(vrsqrtefp, 5, 5),
Aurelien Jarno0bffbc62009-02-09 12:20:50 +01009023GEN_VXFORM_NOA(vexptefp, 5, 6),
Blue Swirl5c55ff92009-06-17 15:22:31 +00009024GEN_VXFORM_NOA(vlogefp, 5, 7),
9025GEN_VXFORM_NOA(vrfim, 5, 8),
9026GEN_VXFORM_NOA(vrfin, 5, 9),
9027GEN_VXFORM_NOA(vrfip, 5, 10),
9028GEN_VXFORM_NOA(vrfiz, 5, 11),
9029
9030#undef GEN_VXFORM_UIMM
9031#define GEN_VXFORM_UIMM(name, opc2, opc3) \
9032 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9033GEN_VXFORM_UIMM(vspltb, 6, 8),
9034GEN_VXFORM_UIMM(vsplth, 6, 9),
9035GEN_VXFORM_UIMM(vspltw, 6, 10),
9036GEN_VXFORM_UIMM(vcfux, 5, 12),
9037GEN_VXFORM_UIMM(vcfsx, 5, 13),
9038GEN_VXFORM_UIMM(vctuxs, 5, 14),
9039GEN_VXFORM_UIMM(vctsxs, 5, 15),
9040
9041#undef GEN_VAFORM_PAIRED
9042#define GEN_VAFORM_PAIRED(name0, name1, opc2) \
9043 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
9044GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16),
9045GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18),
9046GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19),
9047GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20),
9048GEN_VAFORM_PAIRED(vsel, vperm, 21),
9049GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23),
9050
9051#undef GEN_SPE
9052#define GEN_SPE(name0, name1, opc2, opc3, inval, type) \
9053GEN_HANDLER(name0##_##name1, 0x04, opc2, opc3, inval, type)
9054GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, PPC_SPE),
9055GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, PPC_SPE),
9056GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, PPC_SPE),
9057GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, PPC_SPE),
9058GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, PPC_SPE),
9059GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, PPC_SPE),
9060GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, PPC_SPE),
9061GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x00000000, PPC_SPE),
Fabien Chouteaua0e13902011-03-16 11:21:22 +01009062GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, PPC_SPE),
Blue Swirl5c55ff92009-06-17 15:22:31 +00009063GEN_SPE(speundef, evand, 0x08, 0x08, 0x00000000, PPC_SPE),
9064GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, PPC_SPE),
9065GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, PPC_SPE),
9066GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, PPC_SPE),
Fabien Chouteaua0e13902011-03-16 11:21:22 +01009067GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, PPC_SPE),
9068GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, PPC_SPE),
9069GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, PPC_SPE),
Blue Swirl5c55ff92009-06-17 15:22:31 +00009070GEN_SPE(speundef, evorc, 0x0D, 0x08, 0x00000000, PPC_SPE),
9071GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, PPC_SPE),
9072GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, PPC_SPE),
9073GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, PPC_SPE),
9074GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, PPC_SPE),
9075GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, PPC_SPE),
9076GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, PPC_SPE),
9077GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, PPC_SPE),
9078GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, PPC_SPE),
9079GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, PPC_SPE),
9080GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, PPC_SPE),
9081GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, PPC_SPE),
9082GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, PPC_SPE),
9083
9084GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, PPC_SPE_SINGLE),
9085GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, PPC_SPE_SINGLE),
9086GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, PPC_SPE_SINGLE),
9087GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, PPC_SPE_SINGLE),
9088GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, PPC_SPE_SINGLE),
9089GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, PPC_SPE_SINGLE),
9090GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, PPC_SPE_SINGLE),
9091GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, PPC_SPE_SINGLE),
9092GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, PPC_SPE_SINGLE),
9093GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, PPC_SPE_SINGLE),
9094GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, PPC_SPE_SINGLE),
9095GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, PPC_SPE_SINGLE),
9096GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, PPC_SPE_SINGLE),
9097GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, PPC_SPE_SINGLE),
9098
9099GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, PPC_SPE_SINGLE),
9100GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, PPC_SPE_SINGLE),
9101GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, PPC_SPE_SINGLE),
9102GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, PPC_SPE_SINGLE),
9103GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, PPC_SPE_SINGLE),
9104GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, PPC_SPE_SINGLE),
9105GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, PPC_SPE_SINGLE),
9106GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, PPC_SPE_SINGLE),
9107GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, PPC_SPE_SINGLE),
9108GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, PPC_SPE_SINGLE),
9109GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, PPC_SPE_SINGLE),
9110GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, PPC_SPE_SINGLE),
9111GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, PPC_SPE_SINGLE),
9112GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, PPC_SPE_SINGLE),
9113
9114GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, PPC_SPE_DOUBLE),
9115GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, PPC_SPE_DOUBLE),
9116GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, PPC_SPE_DOUBLE),
9117GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, PPC_SPE_DOUBLE),
9118GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, PPC_SPE_DOUBLE),
9119GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, PPC_SPE_DOUBLE),
9120GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, PPC_SPE_DOUBLE),
9121GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, PPC_SPE_DOUBLE),
9122GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, PPC_SPE_DOUBLE),
9123GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, PPC_SPE_DOUBLE),
9124GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, PPC_SPE_DOUBLE),
9125GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, PPC_SPE_DOUBLE),
9126GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, PPC_SPE_DOUBLE),
9127GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, PPC_SPE_DOUBLE),
9128GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, PPC_SPE_DOUBLE),
9129GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, PPC_SPE_DOUBLE),
9130
9131#undef GEN_SPEOP_LDST
9132#define GEN_SPEOP_LDST(name, opc2, sh) \
9133GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
9134GEN_SPEOP_LDST(evldd, 0x00, 3),
9135GEN_SPEOP_LDST(evldw, 0x01, 3),
9136GEN_SPEOP_LDST(evldh, 0x02, 3),
9137GEN_SPEOP_LDST(evlhhesplat, 0x04, 1),
9138GEN_SPEOP_LDST(evlhhousplat, 0x06, 1),
9139GEN_SPEOP_LDST(evlhhossplat, 0x07, 1),
9140GEN_SPEOP_LDST(evlwhe, 0x08, 2),
9141GEN_SPEOP_LDST(evlwhou, 0x0A, 2),
9142GEN_SPEOP_LDST(evlwhos, 0x0B, 2),
9143GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2),
9144GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2),
9145
9146GEN_SPEOP_LDST(evstdd, 0x10, 3),
9147GEN_SPEOP_LDST(evstdw, 0x11, 3),
9148GEN_SPEOP_LDST(evstdh, 0x12, 3),
9149GEN_SPEOP_LDST(evstwhe, 0x18, 2),
9150GEN_SPEOP_LDST(evstwho, 0x1A, 2),
9151GEN_SPEOP_LDST(evstwwe, 0x1C, 2),
9152GEN_SPEOP_LDST(evstwwo, 0x1E, 2),
9153};
9154
bellard3fc6c082005-07-02 20:59:34 +00009155#include "translate_init.c"
j_mayer0411a972007-10-25 21:35:50 +00009156#include "helper_regs.h"
bellard79aceca2003-11-23 14:55:54 +00009157
bellard9a64fbe2004-01-04 22:58:38 +00009158/*****************************************************************************/
bellard3fc6c082005-07-02 20:59:34 +00009159/* Misc PowerPC helpers */
Stefan Weil9a78eea2010-10-22 23:03:33 +02009160void cpu_dump_state (CPUState *env, FILE *f, fprintf_function cpu_fprintf,
j_mayer36081602007-09-17 08:21:54 +00009161 int flags)
bellard79aceca2003-11-23 14:55:54 +00009162{
bellard3fc6c082005-07-02 20:59:34 +00009163#define RGPL 4
9164#define RFPL 4
bellard3fc6c082005-07-02 20:59:34 +00009165
bellard79aceca2003-11-23 14:55:54 +00009166 int i;
9167
Blue Swirl90e189e2009-08-16 11:13:18 +00009168 cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR "
Stefan Weil9a78eea2010-10-22 23:03:33 +02009169 TARGET_FMT_lx " XER " TARGET_FMT_lx "\n",
9170 env->nip, env->lr, env->ctr, env->xer);
Blue Swirl90e189e2009-08-16 11:13:18 +00009171 cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF "
9172 TARGET_FMT_lx " idx %d\n", env->msr, env->spr[SPR_HID0],
9173 env->hflags, env->mmu_idx);
j_mayerd9bce9d2007-03-17 14:02:15 +00009174#if !defined(NO_TIMER_DUMP)
Stefan Weil9a78eea2010-10-22 23:03:33 +02009175 cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64
j_mayer76a66252007-03-07 08:32:30 +00009176#if !defined(CONFIG_USER_ONLY)
Stefan Weil9a78eea2010-10-22 23:03:33 +02009177 " DECR %08" PRIu32
j_mayer76a66252007-03-07 08:32:30 +00009178#endif
9179 "\n",
j_mayer077fc202007-11-04 01:57:29 +00009180 cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
j_mayer76a66252007-03-07 08:32:30 +00009181#if !defined(CONFIG_USER_ONLY)
9182 , cpu_ppc_load_decr(env)
9183#endif
9184 );
j_mayer077fc202007-11-04 01:57:29 +00009185#endif
j_mayer76a66252007-03-07 08:32:30 +00009186 for (i = 0; i < 32; i++) {
bellard3fc6c082005-07-02 20:59:34 +00009187 if ((i & (RGPL - 1)) == 0)
9188 cpu_fprintf(f, "GPR%02d", i);
Blue Swirlb11ebf62009-08-16 11:54:37 +00009189 cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i));
bellard3fc6c082005-07-02 20:59:34 +00009190 if ((i & (RGPL - 1)) == (RGPL - 1))
bellard7fe48482004-10-09 18:08:01 +00009191 cpu_fprintf(f, "\n");
j_mayer76a66252007-03-07 08:32:30 +00009192 }
bellard3fc6c082005-07-02 20:59:34 +00009193 cpu_fprintf(f, "CR ");
j_mayer76a66252007-03-07 08:32:30 +00009194 for (i = 0; i < 8; i++)
bellard7fe48482004-10-09 18:08:01 +00009195 cpu_fprintf(f, "%01x", env->crf[i]);
9196 cpu_fprintf(f, " [");
j_mayer76a66252007-03-07 08:32:30 +00009197 for (i = 0; i < 8; i++) {
9198 char a = '-';
9199 if (env->crf[i] & 0x08)
9200 a = 'L';
9201 else if (env->crf[i] & 0x04)
9202 a = 'G';
9203 else if (env->crf[i] & 0x02)
9204 a = 'E';
bellard7fe48482004-10-09 18:08:01 +00009205 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
j_mayer76a66252007-03-07 08:32:30 +00009206 }
Blue Swirl90e189e2009-08-16 11:13:18 +00009207 cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n",
9208 env->reserve_addr);
bellard3fc6c082005-07-02 20:59:34 +00009209 for (i = 0; i < 32; i++) {
9210 if ((i & (RFPL - 1)) == 0)
9211 cpu_fprintf(f, "FPR%02d", i);
bellard26a76462006-06-25 18:15:32 +00009212 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
bellard3fc6c082005-07-02 20:59:34 +00009213 if ((i & (RFPL - 1)) == (RFPL - 1))
bellard7fe48482004-10-09 18:08:01 +00009214 cpu_fprintf(f, "\n");
bellard79aceca2003-11-23 14:55:54 +00009215 }
aurel3278892702008-12-14 18:40:49 +00009216 cpu_fprintf(f, "FPSCR %08x\n", env->fpscr);
j_mayerf2e63a42007-10-07 15:43:50 +00009217#if !defined(CONFIG_USER_ONLY)
Scott Wood90dc8812011-04-29 17:10:23 -05009218 cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx
9219 " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n",
9220 env->spr[SPR_SRR0], env->spr[SPR_SRR1],
9221 env->spr[SPR_PVR], env->spr[SPR_VRSAVE]);
9222
9223 cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx
9224 " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n",
9225 env->spr[SPR_SPRG0], env->spr[SPR_SPRG1],
9226 env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]);
9227
9228 cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx
9229 " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n",
9230 env->spr[SPR_SPRG4], env->spr[SPR_SPRG5],
9231 env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]);
9232
9233 if (env->excp_model == POWERPC_EXCP_BOOKE) {
9234 cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx
9235 " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n",
9236 env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1],
9237 env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]);
9238
9239 cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx
9240 " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n",
9241 env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR],
9242 env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]);
9243
9244 cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx
9245 " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n",
9246 env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR],
9247 env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]);
9248
9249 cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx
9250 " EPR " TARGET_FMT_lx "\n",
9251 env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8],
9252 env->spr[SPR_BOOKE_EPR]);
9253
9254 /* FSL-specific */
9255 cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx
9256 " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n",
9257 env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1],
9258 env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]);
9259
9260 /*
9261 * IVORs are left out as they are large and do not change often --
9262 * they can be read with "p $ivor0", "p $ivor1", etc.
9263 */
9264 }
9265
9266 switch (env->mmu_model) {
9267 case POWERPC_MMU_32B:
9268 case POWERPC_MMU_601:
9269 case POWERPC_MMU_SOFT_6xx:
9270 case POWERPC_MMU_SOFT_74xx:
9271#if defined(TARGET_PPC64)
9272 case POWERPC_MMU_620:
9273 case POWERPC_MMU_64B:
9274#endif
9275 cpu_fprintf(f, " SDR1 " TARGET_FMT_lx "\n", env->spr[SPR_SDR1]);
9276 break;
Alexander Graf01662f32011-04-30 23:34:58 +02009277 case POWERPC_MMU_BOOKE206:
Scott Wood90dc8812011-04-29 17:10:23 -05009278 cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx
9279 " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n",
9280 env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1],
9281 env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]);
9282
9283 cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx
9284 " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n",
9285 env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6],
9286 env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]);
9287
9288 cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx
9289 " TLB1CFG " TARGET_FMT_lx "\n",
9290 env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG],
9291 env->spr[SPR_BOOKE_TLB1CFG]);
9292 break;
9293 default:
9294 break;
9295 }
j_mayerf2e63a42007-10-07 15:43:50 +00009296#endif
bellard79aceca2003-11-23 14:55:54 +00009297
bellard3fc6c082005-07-02 20:59:34 +00009298#undef RGPL
9299#undef RFPL
bellard79aceca2003-11-23 14:55:54 +00009300}
9301
Stefan Weil9a78eea2010-10-22 23:03:33 +02009302void cpu_dump_statistics (CPUState *env, FILE*f, fprintf_function cpu_fprintf,
j_mayer76a66252007-03-07 08:32:30 +00009303 int flags)
9304{
9305#if defined(DO_PPC_STATISTICS)
Anthony Liguoric227f092009-10-01 16:12:16 -05009306 opc_handler_t **t1, **t2, **t3, *handler;
j_mayer76a66252007-03-07 08:32:30 +00009307 int op1, op2, op3;
9308
9309 t1 = env->opcodes;
9310 for (op1 = 0; op1 < 64; op1++) {
9311 handler = t1[op1];
9312 if (is_indirect_opcode(handler)) {
9313 t2 = ind_table(handler);
9314 for (op2 = 0; op2 < 32; op2++) {
9315 handler = t2[op2];
9316 if (is_indirect_opcode(handler)) {
9317 t3 = ind_table(handler);
9318 for (op3 = 0; op3 < 32; op3++) {
9319 handler = t3[op3];
9320 if (handler->count == 0)
9321 continue;
9322 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
Blue Swirl0bfcd592010-05-22 08:02:12 +00009323 "%016" PRIx64 " %" PRId64 "\n",
j_mayer76a66252007-03-07 08:32:30 +00009324 op1, op2, op3, op1, (op3 << 5) | op2,
9325 handler->oname,
9326 handler->count, handler->count);
9327 }
9328 } else {
9329 if (handler->count == 0)
9330 continue;
9331 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
Blue Swirl0bfcd592010-05-22 08:02:12 +00009332 "%016" PRIx64 " %" PRId64 "\n",
j_mayer76a66252007-03-07 08:32:30 +00009333 op1, op2, op1, op2, handler->oname,
9334 handler->count, handler->count);
9335 }
9336 }
9337 } else {
9338 if (handler->count == 0)
9339 continue;
Blue Swirl0bfcd592010-05-22 08:02:12 +00009340 cpu_fprintf(f, "%02x (%02x ) %16s: %016" PRIx64
9341 " %" PRId64 "\n",
j_mayer76a66252007-03-07 08:32:30 +00009342 op1, op1, handler->oname,
9343 handler->count, handler->count);
9344 }
9345 }
9346#endif
9347}
9348
bellard9a64fbe2004-01-04 22:58:38 +00009349/*****************************************************************************/
Blue Swirl636aa202009-08-16 09:06:54 +00009350static inline void gen_intermediate_code_internal(CPUState *env,
9351 TranslationBlock *tb,
9352 int search_pc)
bellard79aceca2003-11-23 14:55:54 +00009353{
bellard9fddaa02004-05-21 12:59:32 +00009354 DisasContext ctx, *ctxp = &ctx;
Anthony Liguoric227f092009-10-01 16:12:16 -05009355 opc_handler_t **table, *handler;
bellard0fa85d42005-01-03 23:43:32 +00009356 target_ulong pc_start;
bellard79aceca2003-11-23 14:55:54 +00009357 uint16_t *gen_opc_end;
aliguoria1d1bb32008-11-18 20:07:32 +00009358 CPUBreakpoint *bp;
bellard79aceca2003-11-23 14:55:54 +00009359 int j, lj = -1;
pbrook2e70f6e2008-06-29 01:03:05 +00009360 int num_insns;
9361 int max_insns;
bellard79aceca2003-11-23 14:55:54 +00009362
9363 pc_start = tb->pc;
bellard79aceca2003-11-23 14:55:54 +00009364 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
bellard046d6672004-04-25 21:15:35 +00009365 ctx.nip = pc_start;
bellard79aceca2003-11-23 14:55:54 +00009366 ctx.tb = tb;
j_mayere1833e12007-09-29 13:06:16 +00009367 ctx.exception = POWERPC_EXCP_NONE;
bellard3fc6c082005-07-02 20:59:34 +00009368 ctx.spr_cb = env->spr_cb;
aurel3276db3ba2008-12-08 18:11:21 +00009369 ctx.mem_idx = env->mmu_idx;
9370 ctx.access_type = -1;
9371 ctx.le_mode = env->hflags & (1 << MSR_LE) ? 1 : 0;
j_mayerd9bce9d2007-03-17 14:02:15 +00009372#if defined(TARGET_PPC64)
9373 ctx.sf_mode = msr_sf;
bellard9a64fbe2004-01-04 22:58:38 +00009374#endif
bellard3cc62372005-02-15 23:06:19 +00009375 ctx.fpu_enabled = msr_fp;
j_mayera9d9eb82007-10-07 18:19:26 +00009376 if ((env->flags & POWERPC_FLAG_SPE) && msr_spe)
j_mayerd26bfc92007-10-07 14:41:00 +00009377 ctx.spe_enabled = msr_spe;
9378 else
9379 ctx.spe_enabled = 0;
j_mayera9d9eb82007-10-07 18:19:26 +00009380 if ((env->flags & POWERPC_FLAG_VRE) && msr_vr)
9381 ctx.altivec_enabled = msr_vr;
9382 else
9383 ctx.altivec_enabled = 0;
j_mayerd26bfc92007-10-07 14:41:00 +00009384 if ((env->flags & POWERPC_FLAG_SE) && msr_se)
aurel328cbcb4f2008-05-10 23:28:14 +00009385 ctx.singlestep_enabled = CPU_SINGLE_STEP;
j_mayerd26bfc92007-10-07 14:41:00 +00009386 else
aurel328cbcb4f2008-05-10 23:28:14 +00009387 ctx.singlestep_enabled = 0;
j_mayerd26bfc92007-10-07 14:41:00 +00009388 if ((env->flags & POWERPC_FLAG_BE) && msr_be)
aurel328cbcb4f2008-05-10 23:28:14 +00009389 ctx.singlestep_enabled |= CPU_BRANCH_STEP;
9390 if (unlikely(env->singlestep_enabled))
9391 ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP;
bellard3fc6c082005-07-02 20:59:34 +00009392#if defined (DO_SINGLE_STEP) && 0
bellard9a64fbe2004-01-04 22:58:38 +00009393 /* Single step trace mode */
9394 msr_se = 1;
9395#endif
pbrook2e70f6e2008-06-29 01:03:05 +00009396 num_insns = 0;
9397 max_insns = tb->cflags & CF_COUNT_MASK;
9398 if (max_insns == 0)
9399 max_insns = CF_COUNT_MASK;
9400
9401 gen_icount_start();
bellard9a64fbe2004-01-04 22:58:38 +00009402 /* Set env in case of segfault during code fetch */
j_mayere1833e12007-09-29 13:06:16 +00009403 while (ctx.exception == POWERPC_EXCP_NONE && gen_opc_ptr < gen_opc_end) {
Blue Swirl72cf2d42009-09-12 07:36:22 +00009404 if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) {
9405 QTAILQ_FOREACH(bp, &env->breakpoints, entry) {
aliguoria1d1bb32008-11-18 20:07:32 +00009406 if (bp->pc == ctx.nip) {
aurel32e06fcd72008-12-11 22:42:14 +00009407 gen_debug_exception(ctxp);
bellardea4e7542006-05-22 21:50:20 +00009408 break;
9409 }
9410 }
9411 }
j_mayer76a66252007-03-07 08:32:30 +00009412 if (unlikely(search_pc)) {
bellard79aceca2003-11-23 14:55:54 +00009413 j = gen_opc_ptr - gen_opc_buf;
9414 if (lj < j) {
9415 lj++;
9416 while (lj < j)
9417 gen_opc_instr_start[lj++] = 0;
bellard79aceca2003-11-23 14:55:54 +00009418 }
aurel32af4b6c52009-03-29 01:18:03 +00009419 gen_opc_pc[lj] = ctx.nip;
9420 gen_opc_instr_start[lj] = 1;
9421 gen_opc_icount[lj] = num_insns;
bellard79aceca2003-11-23 14:55:54 +00009422 }
aliguorid12d51d2009-01-15 21:48:06 +00009423 LOG_DISAS("----------------\n");
Blue Swirl90e189e2009-08-16 11:13:18 +00009424 LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n",
aliguorid12d51d2009-01-15 21:48:06 +00009425 ctx.nip, ctx.mem_idx, (int)msr_ir);
pbrook2e70f6e2008-06-29 01:03:05 +00009426 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
9427 gen_io_start();
aurel3276db3ba2008-12-08 18:11:21 +00009428 if (unlikely(ctx.le_mode)) {
j_mayer056401e2007-11-04 02:55:33 +00009429 ctx.opcode = bswap32(ldl_code(ctx.nip));
9430 } else {
9431 ctx.opcode = ldl_code(ctx.nip);
bellard111bfab2005-04-23 18:16:07 +00009432 }
aliguorid12d51d2009-01-15 21:48:06 +00009433 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
bellard9a64fbe2004-01-04 22:58:38 +00009434 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
j_mayer056401e2007-11-04 02:55:33 +00009435 opc3(ctx.opcode), little_endian ? "little" : "big");
Aurelien Jarno731c54f2009-09-28 13:39:08 +02009436 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP)))
9437 tcg_gen_debug_insn_start(ctx.nip);
bellard046d6672004-04-25 21:15:35 +00009438 ctx.nip += 4;
bellard3fc6c082005-07-02 20:59:34 +00009439 table = env->opcodes;
pbrook2e70f6e2008-06-29 01:03:05 +00009440 num_insns++;
bellard79aceca2003-11-23 14:55:54 +00009441 handler = table[opc1(ctx.opcode)];
9442 if (is_indirect_opcode(handler)) {
9443 table = ind_table(handler);
9444 handler = table[opc2(ctx.opcode)];
9445 if (is_indirect_opcode(handler)) {
9446 table = ind_table(handler);
9447 handler = table[opc3(ctx.opcode)];
9448 }
9449 }
9450 /* Is opcode *REALLY* valid ? */
j_mayer76a66252007-03-07 08:32:30 +00009451 if (unlikely(handler->handler == &gen_invalid)) {
aliguori93fcfe32009-01-15 22:34:14 +00009452 if (qemu_log_enabled()) {
9453 qemu_log("invalid/unsupported opcode: "
Blue Swirl90e189e2009-08-16 11:13:18 +00009454 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx " %d\n",
9455 opc1(ctx.opcode), opc2(ctx.opcode),
9456 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
bellard4b3686f2004-05-23 22:18:12 +00009457 }
j_mayer76a66252007-03-07 08:32:30 +00009458 } else {
9459 if (unlikely((ctx.opcode & handler->inval) != 0)) {
aliguori93fcfe32009-01-15 22:34:14 +00009460 if (qemu_log_enabled()) {
9461 qemu_log("invalid bits: %08x for opcode: "
Blue Swirl90e189e2009-08-16 11:13:18 +00009462 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx "\n",
9463 ctx.opcode & handler->inval, opc1(ctx.opcode),
9464 opc2(ctx.opcode), opc3(ctx.opcode),
9465 ctx.opcode, ctx.nip - 4);
j_mayer76a66252007-03-07 08:32:30 +00009466 }
aurel32e06fcd72008-12-11 22:42:14 +00009467 gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL);
bellard4b3686f2004-05-23 22:18:12 +00009468 break;
bellard9a64fbe2004-01-04 22:58:38 +00009469 }
bellard79aceca2003-11-23 14:55:54 +00009470 }
bellard4b3686f2004-05-23 22:18:12 +00009471 (*(handler->handler))(&ctx);
j_mayer76a66252007-03-07 08:32:30 +00009472#if defined(DO_PPC_STATISTICS)
9473 handler->count++;
9474#endif
bellard9a64fbe2004-01-04 22:58:38 +00009475 /* Check trace mode exceptions */
aurel328cbcb4f2008-05-10 23:28:14 +00009476 if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP &&
9477 (ctx.nip <= 0x100 || ctx.nip > 0xF00) &&
9478 ctx.exception != POWERPC_SYSCALL &&
9479 ctx.exception != POWERPC_EXCP_TRAP &&
9480 ctx.exception != POWERPC_EXCP_BRANCH)) {
aurel32e06fcd72008-12-11 22:42:14 +00009481 gen_exception(ctxp, POWERPC_EXCP_TRACE);
j_mayerd26bfc92007-10-07 14:41:00 +00009482 } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
pbrook2e70f6e2008-06-29 01:03:05 +00009483 (env->singlestep_enabled) ||
aurel321b530a62009-04-05 20:08:59 +00009484 singlestep ||
pbrook2e70f6e2008-06-29 01:03:05 +00009485 num_insns >= max_insns)) {
j_mayerd26bfc92007-10-07 14:41:00 +00009486 /* if we reach a page boundary or are single stepping, stop
9487 * generation
9488 */
bellard8dd49832005-06-04 22:22:27 +00009489 break;
j_mayer76a66252007-03-07 08:32:30 +00009490 }
bellard3fc6c082005-07-02 20:59:34 +00009491 }
pbrook2e70f6e2008-06-29 01:03:05 +00009492 if (tb->cflags & CF_LAST_IO)
9493 gen_io_end();
j_mayere1833e12007-09-29 13:06:16 +00009494 if (ctx.exception == POWERPC_EXCP_NONE) {
bellardc1942362005-11-20 10:31:08 +00009495 gen_goto_tb(&ctx, 0, ctx.nip);
j_mayere1833e12007-09-29 13:06:16 +00009496 } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
aurel328cbcb4f2008-05-10 23:28:14 +00009497 if (unlikely(env->singlestep_enabled)) {
aurel32e06fcd72008-12-11 22:42:14 +00009498 gen_debug_exception(ctxp);
aurel328cbcb4f2008-05-10 23:28:14 +00009499 }
j_mayer76a66252007-03-07 08:32:30 +00009500 /* Generate the return instruction */
bellard57fec1f2008-02-01 10:50:11 +00009501 tcg_gen_exit_tb(0);
bellard9a64fbe2004-01-04 22:58:38 +00009502 }
pbrook2e70f6e2008-06-29 01:03:05 +00009503 gen_icount_end(tb, num_insns);
bellard79aceca2003-11-23 14:55:54 +00009504 *gen_opc_ptr = INDEX_op_end;
j_mayer76a66252007-03-07 08:32:30 +00009505 if (unlikely(search_pc)) {
bellard9a64fbe2004-01-04 22:58:38 +00009506 j = gen_opc_ptr - gen_opc_buf;
9507 lj++;
9508 while (lj <= j)
9509 gen_opc_instr_start[lj++] = 0;
bellard9a64fbe2004-01-04 22:58:38 +00009510 } else {
bellard046d6672004-04-25 21:15:35 +00009511 tb->size = ctx.nip - pc_start;
pbrook2e70f6e2008-06-29 01:03:05 +00009512 tb->icount = num_insns;
bellard9a64fbe2004-01-04 22:58:38 +00009513 }
j_mayerd9bce9d2007-03-17 14:02:15 +00009514#if defined(DEBUG_DISAS)
aliguori8fec2b82009-01-15 22:36:53 +00009515 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
j_mayer76a66252007-03-07 08:32:30 +00009516 int flags;
j_mayer237c0af2007-09-29 12:01:46 +00009517 flags = env->bfd_mach;
aurel3276db3ba2008-12-08 18:11:21 +00009518 flags |= ctx.le_mode << 16;
aliguori93fcfe32009-01-15 22:34:14 +00009519 qemu_log("IN: %s\n", lookup_symbol(pc_start));
9520 log_target_disas(pc_start, ctx.nip - pc_start, flags);
9521 qemu_log("\n");
bellard9fddaa02004-05-21 12:59:32 +00009522 }
bellard79aceca2003-11-23 14:55:54 +00009523#endif
bellard79aceca2003-11-23 14:55:54 +00009524}
9525
ths2cfc5f12008-07-18 18:01:29 +00009526void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
bellard79aceca2003-11-23 14:55:54 +00009527{
ths2cfc5f12008-07-18 18:01:29 +00009528 gen_intermediate_code_internal(env, tb, 0);
bellard79aceca2003-11-23 14:55:54 +00009529}
9530
ths2cfc5f12008-07-18 18:01:29 +00009531void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
bellard79aceca2003-11-23 14:55:54 +00009532{
ths2cfc5f12008-07-18 18:01:29 +00009533 gen_intermediate_code_internal(env, tb, 1);
bellard79aceca2003-11-23 14:55:54 +00009534}
aurel32d2856f12008-04-28 00:32:32 +00009535
Stefan Weile87b7cb2011-04-18 06:39:52 +00009536void restore_state_to_opc(CPUState *env, TranslationBlock *tb, int pc_pos)
aurel32d2856f12008-04-28 00:32:32 +00009537{
aurel32d2856f12008-04-28 00:32:32 +00009538 env->nip = gen_opc_pc[pc_pos];
aurel32d2856f12008-04-28 00:32:32 +00009539}