Statistics
| Branch: | Revision:

root / target-ppc / translate.c @ eaabeef2

History | View | Annotate | Download (340.6 kB)

1 79aceca5 bellard
/*
2 3fc6c082 bellard
 *  PowerPC emulation for qemu: main translation routines.
3 5fafdf24 ths
 *
4 76a66253 j_mayer
 *  Copyright (c) 2003-2007 Jocelyn Mayer
5 79aceca5 bellard
 *
6 79aceca5 bellard
 * This library is free software; you can redistribute it and/or
7 79aceca5 bellard
 * modify it under the terms of the GNU Lesser General Public
8 79aceca5 bellard
 * License as published by the Free Software Foundation; either
9 79aceca5 bellard
 * version 2 of the License, or (at your option) any later version.
10 79aceca5 bellard
 *
11 79aceca5 bellard
 * This library is distributed in the hope that it will be useful,
12 79aceca5 bellard
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 79aceca5 bellard
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 79aceca5 bellard
 * Lesser General Public License for more details.
15 79aceca5 bellard
 *
16 79aceca5 bellard
 * You should have received a copy of the GNU Lesser General Public
17 8167ee88 Blue Swirl
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 79aceca5 bellard
 */
19 c6a1c22b bellard
#include <stdarg.h>
20 c6a1c22b bellard
#include <stdlib.h>
21 c6a1c22b bellard
#include <stdio.h>
22 c6a1c22b bellard
#include <string.h>
23 c6a1c22b bellard
#include <inttypes.h>
24 c6a1c22b bellard
25 79aceca5 bellard
#include "cpu.h"
26 c6a1c22b bellard
#include "exec-all.h"
27 79aceca5 bellard
#include "disas.h"
28 57fec1fe bellard
#include "tcg-op.h"
29 ca10f867 aurel32
#include "qemu-common.h"
30 0cfe11ea aurel32
#include "host-utils.h"
31 79aceca5 bellard
32 a7812ae4 pbrook
#include "helper.h"
33 a7812ae4 pbrook
#define GEN_HELPER 1
34 a7812ae4 pbrook
#include "helper.h"
35 a7812ae4 pbrook
36 8cbcb4fa aurel32
#define CPU_SINGLE_STEP 0x1
37 8cbcb4fa aurel32
#define CPU_BRANCH_STEP 0x2
38 8cbcb4fa aurel32
#define GDBSTUB_SINGLE_STEP 0x4
39 8cbcb4fa aurel32
40 a750fc0b j_mayer
/* Include definitions for instructions classes and implementations flags */
41 9fddaa0c bellard
//#define PPC_DEBUG_DISAS
42 76a66253 j_mayer
//#define DO_PPC_STATISTICS
43 79aceca5 bellard
44 d12d51d5 aliguori
#ifdef PPC_DEBUG_DISAS
45 93fcfe39 aliguori
#  define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
46 d12d51d5 aliguori
#else
47 d12d51d5 aliguori
#  define LOG_DISAS(...) do { } while (0)
48 d12d51d5 aliguori
#endif
49 a750fc0b j_mayer
/*****************************************************************************/
50 a750fc0b j_mayer
/* Code translation helpers                                                  */
51 c53be334 bellard
52 f78fb44e aurel32
/* global register indexes */
53 a7812ae4 pbrook
static TCGv_ptr cpu_env;
54 1d542695 aurel32
static char cpu_reg_names[10*3 + 22*4 /* GPR */
55 f78fb44e aurel32
#if !defined(TARGET_PPC64)
56 1d542695 aurel32
    + 10*4 + 22*5 /* SPE GPRh */
57 f78fb44e aurel32
#endif
58 a5e26afa aurel32
    + 10*4 + 22*5 /* FPR */
59 47e4661c aurel32
    + 2*(10*6 + 22*7) /* AVRh, AVRl */
60 47e4661c aurel32
    + 8*5 /* CRF */];
61 f78fb44e aurel32
static TCGv cpu_gpr[32];
62 f78fb44e aurel32
#if !defined(TARGET_PPC64)
63 f78fb44e aurel32
static TCGv cpu_gprh[32];
64 f78fb44e aurel32
#endif
65 a7812ae4 pbrook
static TCGv_i64 cpu_fpr[32];
66 a7812ae4 pbrook
static TCGv_i64 cpu_avrh[32], cpu_avrl[32];
67 a7812ae4 pbrook
static TCGv_i32 cpu_crf[8];
68 bd568f18 aurel32
static TCGv cpu_nip;
69 6527f6ea aurel32
static TCGv cpu_msr;
70 cfdcd37a aurel32
static TCGv cpu_ctr;
71 cfdcd37a aurel32
static TCGv cpu_lr;
72 3d7b417e aurel32
static TCGv cpu_xer;
73 cf360a32 aurel32
static TCGv cpu_reserve;
74 a7812ae4 pbrook
static TCGv_i32 cpu_fpscr;
75 a7859e89 aurel32
static TCGv_i32 cpu_access_type;
76 f78fb44e aurel32
77 2e70f6ef pbrook
#include "gen-icount.h"
78 2e70f6ef pbrook
79 2e70f6ef pbrook
void ppc_translate_init(void)
80 2e70f6ef pbrook
{
81 f78fb44e aurel32
    int i;
82 f78fb44e aurel32
    char* p;
83 2dc766da blueswir1
    size_t cpu_reg_names_size;
84 b2437bf2 pbrook
    static int done_init = 0;
85 f78fb44e aurel32
86 2e70f6ef pbrook
    if (done_init)
87 2e70f6ef pbrook
        return;
88 f78fb44e aurel32
89 a7812ae4 pbrook
    cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
90 a7812ae4 pbrook
91 f78fb44e aurel32
    p = cpu_reg_names;
92 2dc766da blueswir1
    cpu_reg_names_size = sizeof(cpu_reg_names);
93 47e4661c aurel32
94 47e4661c aurel32
    for (i = 0; i < 8; i++) {
95 2dc766da blueswir1
        snprintf(p, cpu_reg_names_size, "crf%d", i);
96 a7812ae4 pbrook
        cpu_crf[i] = tcg_global_mem_new_i32(TCG_AREG0,
97 a7812ae4 pbrook
                                            offsetof(CPUState, crf[i]), p);
98 47e4661c aurel32
        p += 5;
99 2dc766da blueswir1
        cpu_reg_names_size -= 5;
100 47e4661c aurel32
    }
101 47e4661c aurel32
102 f78fb44e aurel32
    for (i = 0; i < 32; i++) {
103 2dc766da blueswir1
        snprintf(p, cpu_reg_names_size, "r%d", i);
104 a7812ae4 pbrook
        cpu_gpr[i] = tcg_global_mem_new(TCG_AREG0,
105 f78fb44e aurel32
                                        offsetof(CPUState, gpr[i]), p);
106 f78fb44e aurel32
        p += (i < 10) ? 3 : 4;
107 2dc766da blueswir1
        cpu_reg_names_size -= (i < 10) ? 3 : 4;
108 f78fb44e aurel32
#if !defined(TARGET_PPC64)
109 2dc766da blueswir1
        snprintf(p, cpu_reg_names_size, "r%dH", i);
110 a7812ae4 pbrook
        cpu_gprh[i] = tcg_global_mem_new_i32(TCG_AREG0,
111 a7812ae4 pbrook
                                             offsetof(CPUState, gprh[i]), p);
112 f78fb44e aurel32
        p += (i < 10) ? 4 : 5;
113 2dc766da blueswir1
        cpu_reg_names_size -= (i < 10) ? 4 : 5;
114 f78fb44e aurel32
#endif
115 1d542695 aurel32
116 2dc766da blueswir1
        snprintf(p, cpu_reg_names_size, "fp%d", i);
117 a7812ae4 pbrook
        cpu_fpr[i] = tcg_global_mem_new_i64(TCG_AREG0,
118 a7812ae4 pbrook
                                            offsetof(CPUState, fpr[i]), p);
119 ec1ac72d aurel32
        p += (i < 10) ? 4 : 5;
120 2dc766da blueswir1
        cpu_reg_names_size -= (i < 10) ? 4 : 5;
121 a5e26afa aurel32
122 2dc766da blueswir1
        snprintf(p, cpu_reg_names_size, "avr%dH", i);
123 e2542fe2 Juan Quintela
#ifdef HOST_WORDS_BIGENDIAN
124 fe1e5c53 aurel32
        cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,
125 fe1e5c53 aurel32
                                             offsetof(CPUState, avr[i].u64[0]), p);
126 fe1e5c53 aurel32
#else
127 a7812ae4 pbrook
        cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0,
128 fe1e5c53 aurel32
                                             offsetof(CPUState, avr[i].u64[1]), p);
129 fe1e5c53 aurel32
#endif
130 1d542695 aurel32
        p += (i < 10) ? 6 : 7;
131 2dc766da blueswir1
        cpu_reg_names_size -= (i < 10) ? 6 : 7;
132 ec1ac72d aurel32
133 2dc766da blueswir1
        snprintf(p, cpu_reg_names_size, "avr%dL", i);
134 e2542fe2 Juan Quintela
#ifdef HOST_WORDS_BIGENDIAN
135 fe1e5c53 aurel32
        cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,
136 fe1e5c53 aurel32
                                             offsetof(CPUState, avr[i].u64[1]), p);
137 fe1e5c53 aurel32
#else
138 a7812ae4 pbrook
        cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0,
139 fe1e5c53 aurel32
                                             offsetof(CPUState, avr[i].u64[0]), p);
140 fe1e5c53 aurel32
#endif
141 1d542695 aurel32
        p += (i < 10) ? 6 : 7;
142 2dc766da blueswir1
        cpu_reg_names_size -= (i < 10) ? 6 : 7;
143 f78fb44e aurel32
    }
144 f10dc08e aurel32
145 a7812ae4 pbrook
    cpu_nip = tcg_global_mem_new(TCG_AREG0,
146 bd568f18 aurel32
                                 offsetof(CPUState, nip), "nip");
147 bd568f18 aurel32
148 6527f6ea aurel32
    cpu_msr = tcg_global_mem_new(TCG_AREG0,
149 6527f6ea aurel32
                                 offsetof(CPUState, msr), "msr");
150 6527f6ea aurel32
151 a7812ae4 pbrook
    cpu_ctr = tcg_global_mem_new(TCG_AREG0,
152 cfdcd37a aurel32
                                 offsetof(CPUState, ctr), "ctr");
153 cfdcd37a aurel32
154 a7812ae4 pbrook
    cpu_lr = tcg_global_mem_new(TCG_AREG0,
155 cfdcd37a aurel32
                                offsetof(CPUState, lr), "lr");
156 cfdcd37a aurel32
157 a7812ae4 pbrook
    cpu_xer = tcg_global_mem_new(TCG_AREG0,
158 3d7b417e aurel32
                                 offsetof(CPUState, xer), "xer");
159 3d7b417e aurel32
160 cf360a32 aurel32
    cpu_reserve = tcg_global_mem_new(TCG_AREG0,
161 18b21a2f Nathan Froyd
                                     offsetof(CPUState, reserve_addr),
162 18b21a2f Nathan Froyd
                                     "reserve_addr");
163 cf360a32 aurel32
164 a7812ae4 pbrook
    cpu_fpscr = tcg_global_mem_new_i32(TCG_AREG0,
165 a7812ae4 pbrook
                                       offsetof(CPUState, fpscr), "fpscr");
166 e1571908 aurel32
167 a7859e89 aurel32
    cpu_access_type = tcg_global_mem_new_i32(TCG_AREG0,
168 a7859e89 aurel32
                                             offsetof(CPUState, access_type), "access_type");
169 a7859e89 aurel32
170 f10dc08e aurel32
    /* register helpers */
171 a7812ae4 pbrook
#define GEN_HELPER 2
172 f10dc08e aurel32
#include "helper.h"
173 f10dc08e aurel32
174 2e70f6ef pbrook
    done_init = 1;
175 2e70f6ef pbrook
}
176 2e70f6ef pbrook
177 79aceca5 bellard
/* internal defines */
178 79aceca5 bellard
typedef struct DisasContext {
179 79aceca5 bellard
    struct TranslationBlock *tb;
180 0fa85d43 bellard
    target_ulong nip;
181 79aceca5 bellard
    uint32_t opcode;
182 9a64fbe4 bellard
    uint32_t exception;
183 3cc62370 bellard
    /* Routine used to access memory */
184 3cc62370 bellard
    int mem_idx;
185 76db3ba4 aurel32
    int access_type;
186 3cc62370 bellard
    /* Translation flags */
187 76db3ba4 aurel32
    int le_mode;
188 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
189 d9bce9d9 j_mayer
    int sf_mode;
190 d9bce9d9 j_mayer
#endif
191 3cc62370 bellard
    int fpu_enabled;
192 a9d9eb8f j_mayer
    int altivec_enabled;
193 0487d6a8 j_mayer
    int spe_enabled;
194 c227f099 Anthony Liguori
    ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */
195 ea4e754f bellard
    int singlestep_enabled;
196 79aceca5 bellard
} DisasContext;
197 79aceca5 bellard
198 c227f099 Anthony Liguori
struct opc_handler_t {
199 79aceca5 bellard
    /* invalid bits */
200 79aceca5 bellard
    uint32_t inval;
201 9a64fbe4 bellard
    /* instruction type */
202 0487d6a8 j_mayer
    uint64_t type;
203 79aceca5 bellard
    /* handler */
204 79aceca5 bellard
    void (*handler)(DisasContext *ctx);
205 a750fc0b j_mayer
#if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
206 b55266b5 blueswir1
    const char *oname;
207 a750fc0b j_mayer
#endif
208 a750fc0b j_mayer
#if defined(DO_PPC_STATISTICS)
209 76a66253 j_mayer
    uint64_t count;
210 76a66253 j_mayer
#endif
211 3fc6c082 bellard
};
212 79aceca5 bellard
213 636aa200 Blue Swirl
static inline void gen_reset_fpstatus(void)
214 7c58044c j_mayer
{
215 7c58044c j_mayer
#ifdef CONFIG_SOFTFLOAT
216 a44d2ce1 aurel32
    gen_helper_reset_fpstatus();
217 7c58044c j_mayer
#endif
218 7c58044c j_mayer
}
219 7c58044c j_mayer
220 636aa200 Blue Swirl
static inline void gen_compute_fprf(TCGv_i64 arg, int set_fprf, int set_rc)
221 7c58044c j_mayer
{
222 0f2f39c2 aurel32
    TCGv_i32 t0 = tcg_temp_new_i32();
223 af12906f aurel32
224 7c58044c j_mayer
    if (set_fprf != 0) {
225 7c58044c j_mayer
        /* This case might be optimized later */
226 0f2f39c2 aurel32
        tcg_gen_movi_i32(t0, 1);
227 af12906f aurel32
        gen_helper_compute_fprf(t0, arg, t0);
228 a7812ae4 pbrook
        if (unlikely(set_rc)) {
229 0f2f39c2 aurel32
            tcg_gen_mov_i32(cpu_crf[1], t0);
230 a7812ae4 pbrook
        }
231 af12906f aurel32
        gen_helper_float_check_status();
232 7c58044c j_mayer
    } else if (unlikely(set_rc)) {
233 7c58044c j_mayer
        /* We always need to compute fpcc */
234 0f2f39c2 aurel32
        tcg_gen_movi_i32(t0, 0);
235 af12906f aurel32
        gen_helper_compute_fprf(t0, arg, t0);
236 0f2f39c2 aurel32
        tcg_gen_mov_i32(cpu_crf[1], t0);
237 7c58044c j_mayer
    }
238 af12906f aurel32
239 0f2f39c2 aurel32
    tcg_temp_free_i32(t0);
240 7c58044c j_mayer
}
241 7c58044c j_mayer
242 636aa200 Blue Swirl
static inline void gen_set_access_type(DisasContext *ctx, int access_type)
243 a7859e89 aurel32
{
244 76db3ba4 aurel32
    if (ctx->access_type != access_type) {
245 76db3ba4 aurel32
        tcg_gen_movi_i32(cpu_access_type, access_type);
246 76db3ba4 aurel32
        ctx->access_type = access_type;
247 76db3ba4 aurel32
    }
248 a7859e89 aurel32
}
249 a7859e89 aurel32
250 636aa200 Blue Swirl
static inline void gen_update_nip(DisasContext *ctx, target_ulong nip)
251 d9bce9d9 j_mayer
{
252 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
253 d9bce9d9 j_mayer
    if (ctx->sf_mode)
254 bd568f18 aurel32
        tcg_gen_movi_tl(cpu_nip, nip);
255 d9bce9d9 j_mayer
    else
256 d9bce9d9 j_mayer
#endif
257 bd568f18 aurel32
        tcg_gen_movi_tl(cpu_nip, (uint32_t)nip);
258 d9bce9d9 j_mayer
}
259 d9bce9d9 j_mayer
260 636aa200 Blue Swirl
static inline void gen_exception_err(DisasContext *ctx, uint32_t excp, uint32_t error)
261 e06fcd75 aurel32
{
262 e06fcd75 aurel32
    TCGv_i32 t0, t1;
263 e06fcd75 aurel32
    if (ctx->exception == POWERPC_EXCP_NONE) {
264 e06fcd75 aurel32
        gen_update_nip(ctx, ctx->nip);
265 e06fcd75 aurel32
    }
266 e06fcd75 aurel32
    t0 = tcg_const_i32(excp);
267 e06fcd75 aurel32
    t1 = tcg_const_i32(error);
268 e06fcd75 aurel32
    gen_helper_raise_exception_err(t0, t1);
269 e06fcd75 aurel32
    tcg_temp_free_i32(t0);
270 e06fcd75 aurel32
    tcg_temp_free_i32(t1);
271 e06fcd75 aurel32
    ctx->exception = (excp);
272 e06fcd75 aurel32
}
273 e1833e1f j_mayer
274 636aa200 Blue Swirl
static inline void gen_exception(DisasContext *ctx, uint32_t excp)
275 e06fcd75 aurel32
{
276 e06fcd75 aurel32
    TCGv_i32 t0;
277 e06fcd75 aurel32
    if (ctx->exception == POWERPC_EXCP_NONE) {
278 e06fcd75 aurel32
        gen_update_nip(ctx, ctx->nip);
279 e06fcd75 aurel32
    }
280 e06fcd75 aurel32
    t0 = tcg_const_i32(excp);
281 e06fcd75 aurel32
    gen_helper_raise_exception(t0);
282 e06fcd75 aurel32
    tcg_temp_free_i32(t0);
283 e06fcd75 aurel32
    ctx->exception = (excp);
284 e06fcd75 aurel32
}
285 e1833e1f j_mayer
286 636aa200 Blue Swirl
static inline void gen_debug_exception(DisasContext *ctx)
287 e06fcd75 aurel32
{
288 e06fcd75 aurel32
    TCGv_i32 t0;
289 5518f3a6 blueswir1
290 5518f3a6 blueswir1
    if (ctx->exception != POWERPC_EXCP_BRANCH)
291 5518f3a6 blueswir1
        gen_update_nip(ctx, ctx->nip);
292 e06fcd75 aurel32
    t0 = tcg_const_i32(EXCP_DEBUG);
293 e06fcd75 aurel32
    gen_helper_raise_exception(t0);
294 e06fcd75 aurel32
    tcg_temp_free_i32(t0);
295 e06fcd75 aurel32
}
296 9a64fbe4 bellard
297 636aa200 Blue Swirl
static inline void gen_inval_exception(DisasContext *ctx, uint32_t error)
298 e06fcd75 aurel32
{
299 e06fcd75 aurel32
    gen_exception_err(ctx, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | error);
300 e06fcd75 aurel32
}
301 a9d9eb8f j_mayer
302 f24e5695 bellard
/* Stop translation */
303 636aa200 Blue Swirl
static inline void gen_stop_exception(DisasContext *ctx)
304 3fc6c082 bellard
{
305 d9bce9d9 j_mayer
    gen_update_nip(ctx, ctx->nip);
306 e1833e1f j_mayer
    ctx->exception = POWERPC_EXCP_STOP;
307 3fc6c082 bellard
}
308 3fc6c082 bellard
309 f24e5695 bellard
/* No need to update nip here, as execution flow will change */
310 636aa200 Blue Swirl
static inline void gen_sync_exception(DisasContext *ctx)
311 2be0071f bellard
{
312 e1833e1f j_mayer
    ctx->exception = POWERPC_EXCP_SYNC;
313 2be0071f bellard
}
314 2be0071f bellard
315 79aceca5 bellard
#define GEN_HANDLER(name, opc1, opc2, opc3, inval, type)                      \
316 5c55ff99 Blue Swirl
GEN_OPCODE(name, opc1, opc2, opc3, inval, type)
317 79aceca5 bellard
318 c7697e1f j_mayer
#define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type)               \
319 5c55ff99 Blue Swirl
GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type)
320 c7697e1f j_mayer
321 c227f099 Anthony Liguori
typedef struct opcode_t {
322 79aceca5 bellard
    unsigned char opc1, opc2, opc3;
323 1235fc06 ths
#if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
324 18fba28c bellard
    unsigned char pad[5];
325 18fba28c bellard
#else
326 18fba28c bellard
    unsigned char pad[1];
327 18fba28c bellard
#endif
328 c227f099 Anthony Liguori
    opc_handler_t handler;
329 b55266b5 blueswir1
    const char *oname;
330 c227f099 Anthony Liguori
} opcode_t;
331 79aceca5 bellard
332 a750fc0b j_mayer
/*****************************************************************************/
333 79aceca5 bellard
/***                           Instruction decoding                        ***/
334 79aceca5 bellard
#define EXTRACT_HELPER(name, shift, nb)                                       \
335 636aa200 Blue Swirl
static inline uint32_t name(uint32_t opcode)                                  \
336 79aceca5 bellard
{                                                                             \
337 79aceca5 bellard
    return (opcode >> (shift)) & ((1 << (nb)) - 1);                           \
338 79aceca5 bellard
}
339 79aceca5 bellard
340 79aceca5 bellard
#define EXTRACT_SHELPER(name, shift, nb)                                      \
341 636aa200 Blue Swirl
static inline int32_t name(uint32_t opcode)                                   \
342 79aceca5 bellard
{                                                                             \
343 18fba28c bellard
    return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1));                \
344 79aceca5 bellard
}
345 79aceca5 bellard
346 79aceca5 bellard
/* Opcode part 1 */
347 79aceca5 bellard
EXTRACT_HELPER(opc1, 26, 6);
348 79aceca5 bellard
/* Opcode part 2 */
349 79aceca5 bellard
EXTRACT_HELPER(opc2, 1, 5);
350 79aceca5 bellard
/* Opcode part 3 */
351 79aceca5 bellard
EXTRACT_HELPER(opc3, 6, 5);
352 79aceca5 bellard
/* Update Cr0 flags */
353 79aceca5 bellard
EXTRACT_HELPER(Rc, 0, 1);
354 79aceca5 bellard
/* Destination */
355 79aceca5 bellard
EXTRACT_HELPER(rD, 21, 5);
356 79aceca5 bellard
/* Source */
357 79aceca5 bellard
EXTRACT_HELPER(rS, 21, 5);
358 79aceca5 bellard
/* First operand */
359 79aceca5 bellard
EXTRACT_HELPER(rA, 16, 5);
360 79aceca5 bellard
/* Second operand */
361 79aceca5 bellard
EXTRACT_HELPER(rB, 11, 5);
362 79aceca5 bellard
/* Third operand */
363 79aceca5 bellard
EXTRACT_HELPER(rC, 6, 5);
364 79aceca5 bellard
/***                               Get CRn                                 ***/
365 79aceca5 bellard
EXTRACT_HELPER(crfD, 23, 3);
366 79aceca5 bellard
EXTRACT_HELPER(crfS, 18, 3);
367 79aceca5 bellard
EXTRACT_HELPER(crbD, 21, 5);
368 79aceca5 bellard
EXTRACT_HELPER(crbA, 16, 5);
369 79aceca5 bellard
EXTRACT_HELPER(crbB, 11, 5);
370 79aceca5 bellard
/* SPR / TBL */
371 3fc6c082 bellard
EXTRACT_HELPER(_SPR, 11, 10);
372 636aa200 Blue Swirl
static inline uint32_t SPR(uint32_t opcode)
373 3fc6c082 bellard
{
374 3fc6c082 bellard
    uint32_t sprn = _SPR(opcode);
375 3fc6c082 bellard
376 3fc6c082 bellard
    return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
377 3fc6c082 bellard
}
378 79aceca5 bellard
/***                              Get constants                            ***/
379 79aceca5 bellard
EXTRACT_HELPER(IMM, 12, 8);
380 79aceca5 bellard
/* 16 bits signed immediate value */
381 79aceca5 bellard
EXTRACT_SHELPER(SIMM, 0, 16);
382 79aceca5 bellard
/* 16 bits unsigned immediate value */
383 79aceca5 bellard
EXTRACT_HELPER(UIMM, 0, 16);
384 21d21583 aurel32
/* 5 bits signed immediate value */
385 21d21583 aurel32
EXTRACT_HELPER(SIMM5, 16, 5);
386 27a4edb3 aurel32
/* 5 bits signed immediate value */
387 27a4edb3 aurel32
EXTRACT_HELPER(UIMM5, 16, 5);
388 79aceca5 bellard
/* Bit count */
389 79aceca5 bellard
EXTRACT_HELPER(NB, 11, 5);
390 79aceca5 bellard
/* Shift count */
391 79aceca5 bellard
EXTRACT_HELPER(SH, 11, 5);
392 cd633b10 aurel32
/* Vector shift count */
393 cd633b10 aurel32
EXTRACT_HELPER(VSH, 6, 4);
394 79aceca5 bellard
/* Mask start */
395 79aceca5 bellard
EXTRACT_HELPER(MB, 6, 5);
396 79aceca5 bellard
/* Mask end */
397 79aceca5 bellard
EXTRACT_HELPER(ME, 1, 5);
398 fb0eaffc bellard
/* Trap operand */
399 fb0eaffc bellard
EXTRACT_HELPER(TO, 21, 5);
400 79aceca5 bellard
401 79aceca5 bellard
EXTRACT_HELPER(CRM, 12, 8);
402 79aceca5 bellard
EXTRACT_HELPER(FM, 17, 8);
403 79aceca5 bellard
EXTRACT_HELPER(SR, 16, 4);
404 e4bb997e aurel32
EXTRACT_HELPER(FPIMM, 12, 4);
405 fb0eaffc bellard
406 79aceca5 bellard
/***                            Jump target decoding                       ***/
407 79aceca5 bellard
/* Displacement */
408 79aceca5 bellard
EXTRACT_SHELPER(d, 0, 16);
409 79aceca5 bellard
/* Immediate address */
410 636aa200 Blue Swirl
static inline target_ulong LI(uint32_t opcode)
411 79aceca5 bellard
{
412 79aceca5 bellard
    return (opcode >> 0) & 0x03FFFFFC;
413 79aceca5 bellard
}
414 79aceca5 bellard
415 636aa200 Blue Swirl
static inline uint32_t BD(uint32_t opcode)
416 79aceca5 bellard
{
417 79aceca5 bellard
    return (opcode >> 0) & 0xFFFC;
418 79aceca5 bellard
}
419 79aceca5 bellard
420 79aceca5 bellard
EXTRACT_HELPER(BO, 21, 5);
421 79aceca5 bellard
EXTRACT_HELPER(BI, 16, 5);
422 79aceca5 bellard
/* Absolute/relative address */
423 79aceca5 bellard
EXTRACT_HELPER(AA, 1, 1);
424 79aceca5 bellard
/* Link */
425 79aceca5 bellard
EXTRACT_HELPER(LK, 0, 1);
426 79aceca5 bellard
427 79aceca5 bellard
/* Create a mask between <start> and <end> bits */
428 636aa200 Blue Swirl
static inline target_ulong MASK(uint32_t start, uint32_t end)
429 79aceca5 bellard
{
430 76a66253 j_mayer
    target_ulong ret;
431 79aceca5 bellard
432 76a66253 j_mayer
#if defined(TARGET_PPC64)
433 76a66253 j_mayer
    if (likely(start == 0)) {
434 6f2d8978 j_mayer
        ret = UINT64_MAX << (63 - end);
435 76a66253 j_mayer
    } else if (likely(end == 63)) {
436 6f2d8978 j_mayer
        ret = UINT64_MAX >> start;
437 76a66253 j_mayer
    }
438 76a66253 j_mayer
#else
439 76a66253 j_mayer
    if (likely(start == 0)) {
440 6f2d8978 j_mayer
        ret = UINT32_MAX << (31  - end);
441 76a66253 j_mayer
    } else if (likely(end == 31)) {
442 6f2d8978 j_mayer
        ret = UINT32_MAX >> start;
443 76a66253 j_mayer
    }
444 76a66253 j_mayer
#endif
445 76a66253 j_mayer
    else {
446 76a66253 j_mayer
        ret = (((target_ulong)(-1ULL)) >> (start)) ^
447 76a66253 j_mayer
            (((target_ulong)(-1ULL) >> (end)) >> 1);
448 76a66253 j_mayer
        if (unlikely(start > end))
449 76a66253 j_mayer
            return ~ret;
450 76a66253 j_mayer
    }
451 79aceca5 bellard
452 79aceca5 bellard
    return ret;
453 79aceca5 bellard
}
454 79aceca5 bellard
455 a750fc0b j_mayer
/*****************************************************************************/
456 a750fc0b j_mayer
/* PowerPC instructions table                                                */
457 933dc6eb bellard
458 76a66253 j_mayer
#if defined(DO_PPC_STATISTICS)
459 79aceca5 bellard
#define GEN_OPCODE(name, op1, op2, op3, invl, _typ)                           \
460 5c55ff99 Blue Swirl
{                                                                             \
461 79aceca5 bellard
    .opc1 = op1,                                                              \
462 79aceca5 bellard
    .opc2 = op2,                                                              \
463 79aceca5 bellard
    .opc3 = op3,                                                              \
464 18fba28c bellard
    .pad  = { 0, },                                                           \
465 79aceca5 bellard
    .handler = {                                                              \
466 79aceca5 bellard
        .inval   = invl,                                                      \
467 9a64fbe4 bellard
        .type = _typ,                                                         \
468 79aceca5 bellard
        .handler = &gen_##name,                                               \
469 76a66253 j_mayer
        .oname = stringify(name),                                             \
470 79aceca5 bellard
    },                                                                        \
471 3fc6c082 bellard
    .oname = stringify(name),                                                 \
472 79aceca5 bellard
}
473 c7697e1f j_mayer
#define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ)                    \
474 5c55ff99 Blue Swirl
{                                                                             \
475 c7697e1f j_mayer
    .opc1 = op1,                                                              \
476 c7697e1f j_mayer
    .opc2 = op2,                                                              \
477 c7697e1f j_mayer
    .opc3 = op3,                                                              \
478 c7697e1f j_mayer
    .pad  = { 0, },                                                           \
479 c7697e1f j_mayer
    .handler = {                                                              \
480 c7697e1f j_mayer
        .inval   = invl,                                                      \
481 c7697e1f j_mayer
        .type = _typ,                                                         \
482 c7697e1f j_mayer
        .handler = &gen_##name,                                               \
483 c7697e1f j_mayer
        .oname = onam,                                                        \
484 c7697e1f j_mayer
    },                                                                        \
485 c7697e1f j_mayer
    .oname = onam,                                                            \
486 c7697e1f j_mayer
}
487 76a66253 j_mayer
#else
488 76a66253 j_mayer
#define GEN_OPCODE(name, op1, op2, op3, invl, _typ)                           \
489 5c55ff99 Blue Swirl
{                                                                             \
490 c7697e1f j_mayer
    .opc1 = op1,                                                              \
491 c7697e1f j_mayer
    .opc2 = op2,                                                              \
492 c7697e1f j_mayer
    .opc3 = op3,                                                              \
493 c7697e1f j_mayer
    .pad  = { 0, },                                                           \
494 c7697e1f j_mayer
    .handler = {                                                              \
495 c7697e1f j_mayer
        .inval   = invl,                                                      \
496 c7697e1f j_mayer
        .type = _typ,                                                         \
497 c7697e1f j_mayer
        .handler = &gen_##name,                                               \
498 5c55ff99 Blue Swirl
    },                                                                        \
499 5c55ff99 Blue Swirl
    .oname = stringify(name),                                                 \
500 5c55ff99 Blue Swirl
}
501 5c55ff99 Blue Swirl
#define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ)                    \
502 5c55ff99 Blue Swirl
{                                                                             \
503 5c55ff99 Blue Swirl
    .opc1 = op1,                                                              \
504 5c55ff99 Blue Swirl
    .opc2 = op2,                                                              \
505 5c55ff99 Blue Swirl
    .opc3 = op3,                                                              \
506 5c55ff99 Blue Swirl
    .pad  = { 0, },                                                           \
507 5c55ff99 Blue Swirl
    .handler = {                                                              \
508 5c55ff99 Blue Swirl
        .inval   = invl,                                                      \
509 5c55ff99 Blue Swirl
        .type = _typ,                                                         \
510 5c55ff99 Blue Swirl
        .handler = &gen_##name,                                               \
511 5c55ff99 Blue Swirl
    },                                                                        \
512 5c55ff99 Blue Swirl
    .oname = onam,                                                            \
513 5c55ff99 Blue Swirl
}
514 5c55ff99 Blue Swirl
#endif
515 2e610050 Blue Swirl
516 5c55ff99 Blue Swirl
/* SPR load/store helpers */
517 636aa200 Blue Swirl
static inline void gen_load_spr(TCGv t, int reg)
518 5c55ff99 Blue Swirl
{
519 5c55ff99 Blue Swirl
    tcg_gen_ld_tl(t, cpu_env, offsetof(CPUState, spr[reg]));
520 5c55ff99 Blue Swirl
}
521 2e610050 Blue Swirl
522 636aa200 Blue Swirl
static inline void gen_store_spr(int reg, TCGv t)
523 5c55ff99 Blue Swirl
{
524 5c55ff99 Blue Swirl
    tcg_gen_st_tl(t, cpu_env, offsetof(CPUState, spr[reg]));
525 5c55ff99 Blue Swirl
}
526 2e610050 Blue Swirl
527 54623277 Blue Swirl
/* Invalid instruction */
528 99e300ef Blue Swirl
static void gen_invalid(DisasContext *ctx)
529 9a64fbe4 bellard
{
530 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
531 9a64fbe4 bellard
}
532 9a64fbe4 bellard
533 c227f099 Anthony Liguori
static opc_handler_t invalid_handler = {
534 79aceca5 bellard
    .inval   = 0xFFFFFFFF,
535 9a64fbe4 bellard
    .type    = PPC_NONE,
536 79aceca5 bellard
    .handler = gen_invalid,
537 79aceca5 bellard
};
538 79aceca5 bellard
539 e1571908 aurel32
/***                           Integer comparison                          ***/
540 e1571908 aurel32
541 636aa200 Blue Swirl
static inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf)
542 e1571908 aurel32
{
543 e1571908 aurel32
    int l1, l2, l3;
544 e1571908 aurel32
545 269f3e95 aurel32
    tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_xer);
546 269f3e95 aurel32
    tcg_gen_shri_i32(cpu_crf[crf], cpu_crf[crf], XER_SO);
547 e1571908 aurel32
    tcg_gen_andi_i32(cpu_crf[crf], cpu_crf[crf], 1);
548 e1571908 aurel32
549 e1571908 aurel32
    l1 = gen_new_label();
550 e1571908 aurel32
    l2 = gen_new_label();
551 e1571908 aurel32
    l3 = gen_new_label();
552 e1571908 aurel32
    if (s) {
553 ea363694 aurel32
        tcg_gen_brcond_tl(TCG_COND_LT, arg0, arg1, l1);
554 ea363694 aurel32
        tcg_gen_brcond_tl(TCG_COND_GT, arg0, arg1, l2);
555 e1571908 aurel32
    } else {
556 ea363694 aurel32
        tcg_gen_brcond_tl(TCG_COND_LTU, arg0, arg1, l1);
557 ea363694 aurel32
        tcg_gen_brcond_tl(TCG_COND_GTU, arg0, arg1, l2);
558 e1571908 aurel32
    }
559 e1571908 aurel32
    tcg_gen_ori_i32(cpu_crf[crf], cpu_crf[crf], 1 << CRF_EQ);
560 e1571908 aurel32
    tcg_gen_br(l3);
561 e1571908 aurel32
    gen_set_label(l1);
562 e1571908 aurel32
    tcg_gen_ori_i32(cpu_crf[crf], cpu_crf[crf], 1 << CRF_LT);
563 e1571908 aurel32
    tcg_gen_br(l3);
564 e1571908 aurel32
    gen_set_label(l2);
565 e1571908 aurel32
    tcg_gen_ori_i32(cpu_crf[crf], cpu_crf[crf], 1 << CRF_GT);
566 e1571908 aurel32
    gen_set_label(l3);
567 e1571908 aurel32
}
568 e1571908 aurel32
569 636aa200 Blue Swirl
static inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf)
570 e1571908 aurel32
{
571 ea363694 aurel32
    TCGv t0 = tcg_const_local_tl(arg1);
572 ea363694 aurel32
    gen_op_cmp(arg0, t0, s, crf);
573 ea363694 aurel32
    tcg_temp_free(t0);
574 e1571908 aurel32
}
575 e1571908 aurel32
576 e1571908 aurel32
#if defined(TARGET_PPC64)
577 636aa200 Blue Swirl
static inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf)
578 e1571908 aurel32
{
579 ea363694 aurel32
    TCGv t0, t1;
580 a7812ae4 pbrook
    t0 = tcg_temp_local_new();
581 a7812ae4 pbrook
    t1 = tcg_temp_local_new();
582 e1571908 aurel32
    if (s) {
583 ea363694 aurel32
        tcg_gen_ext32s_tl(t0, arg0);
584 ea363694 aurel32
        tcg_gen_ext32s_tl(t1, arg1);
585 e1571908 aurel32
    } else {
586 ea363694 aurel32
        tcg_gen_ext32u_tl(t0, arg0);
587 ea363694 aurel32
        tcg_gen_ext32u_tl(t1, arg1);
588 e1571908 aurel32
    }
589 ea363694 aurel32
    gen_op_cmp(t0, t1, s, crf);
590 ea363694 aurel32
    tcg_temp_free(t1);
591 ea363694 aurel32
    tcg_temp_free(t0);
592 e1571908 aurel32
}
593 e1571908 aurel32
594 636aa200 Blue Swirl
static inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf)
595 e1571908 aurel32
{
596 ea363694 aurel32
    TCGv t0 = tcg_const_local_tl(arg1);
597 ea363694 aurel32
    gen_op_cmp32(arg0, t0, s, crf);
598 ea363694 aurel32
    tcg_temp_free(t0);
599 e1571908 aurel32
}
600 e1571908 aurel32
#endif
601 e1571908 aurel32
602 636aa200 Blue Swirl
static inline void gen_set_Rc0(DisasContext *ctx, TCGv reg)
603 e1571908 aurel32
{
604 e1571908 aurel32
#if defined(TARGET_PPC64)
605 e1571908 aurel32
    if (!(ctx->sf_mode))
606 e1571908 aurel32
        gen_op_cmpi32(reg, 0, 1, 0);
607 e1571908 aurel32
    else
608 e1571908 aurel32
#endif
609 e1571908 aurel32
        gen_op_cmpi(reg, 0, 1, 0);
610 e1571908 aurel32
}
611 e1571908 aurel32
612 e1571908 aurel32
/* cmp */
613 99e300ef Blue Swirl
static void gen_cmp(DisasContext *ctx)
614 e1571908 aurel32
{
615 e1571908 aurel32
#if defined(TARGET_PPC64)
616 e1571908 aurel32
    if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
617 e1571908 aurel32
        gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
618 e1571908 aurel32
                     1, crfD(ctx->opcode));
619 e1571908 aurel32
    else
620 e1571908 aurel32
#endif
621 e1571908 aurel32
        gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
622 e1571908 aurel32
                   1, crfD(ctx->opcode));
623 e1571908 aurel32
}
624 e1571908 aurel32
625 e1571908 aurel32
/* cmpi */
626 99e300ef Blue Swirl
static void gen_cmpi(DisasContext *ctx)
627 e1571908 aurel32
{
628 e1571908 aurel32
#if defined(TARGET_PPC64)
629 e1571908 aurel32
    if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
630 e1571908 aurel32
        gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
631 e1571908 aurel32
                      1, crfD(ctx->opcode));
632 e1571908 aurel32
    else
633 e1571908 aurel32
#endif
634 e1571908 aurel32
        gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
635 e1571908 aurel32
                    1, crfD(ctx->opcode));
636 e1571908 aurel32
}
637 e1571908 aurel32
638 e1571908 aurel32
/* cmpl */
639 99e300ef Blue Swirl
static void gen_cmpl(DisasContext *ctx)
640 e1571908 aurel32
{
641 e1571908 aurel32
#if defined(TARGET_PPC64)
642 e1571908 aurel32
    if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
643 e1571908 aurel32
        gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
644 e1571908 aurel32
                     0, crfD(ctx->opcode));
645 e1571908 aurel32
    else
646 e1571908 aurel32
#endif
647 e1571908 aurel32
        gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
648 e1571908 aurel32
                   0, crfD(ctx->opcode));
649 e1571908 aurel32
}
650 e1571908 aurel32
651 e1571908 aurel32
/* cmpli */
652 99e300ef Blue Swirl
static void gen_cmpli(DisasContext *ctx)
653 e1571908 aurel32
{
654 e1571908 aurel32
#if defined(TARGET_PPC64)
655 e1571908 aurel32
    if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
656 e1571908 aurel32
        gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
657 e1571908 aurel32
                      0, crfD(ctx->opcode));
658 e1571908 aurel32
    else
659 e1571908 aurel32
#endif
660 e1571908 aurel32
        gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
661 e1571908 aurel32
                    0, crfD(ctx->opcode));
662 e1571908 aurel32
}
663 e1571908 aurel32
664 e1571908 aurel32
/* isel (PowerPC 2.03 specification) */
665 99e300ef Blue Swirl
static void gen_isel(DisasContext *ctx)
666 e1571908 aurel32
{
667 e1571908 aurel32
    int l1, l2;
668 e1571908 aurel32
    uint32_t bi = rC(ctx->opcode);
669 e1571908 aurel32
    uint32_t mask;
670 a7812ae4 pbrook
    TCGv_i32 t0;
671 e1571908 aurel32
672 e1571908 aurel32
    l1 = gen_new_label();
673 e1571908 aurel32
    l2 = gen_new_label();
674 e1571908 aurel32
675 e1571908 aurel32
    mask = 1 << (3 - (bi & 0x03));
676 a7812ae4 pbrook
    t0 = tcg_temp_new_i32();
677 fea0c503 aurel32
    tcg_gen_andi_i32(t0, cpu_crf[bi >> 2], mask);
678 fea0c503 aurel32
    tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
679 e1571908 aurel32
    if (rA(ctx->opcode) == 0)
680 e1571908 aurel32
        tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
681 e1571908 aurel32
    else
682 e1571908 aurel32
        tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
683 e1571908 aurel32
    tcg_gen_br(l2);
684 e1571908 aurel32
    gen_set_label(l1);
685 e1571908 aurel32
    tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
686 e1571908 aurel32
    gen_set_label(l2);
687 a7812ae4 pbrook
    tcg_temp_free_i32(t0);
688 e1571908 aurel32
}
689 e1571908 aurel32
690 79aceca5 bellard
/***                           Integer arithmetic                          ***/
691 79aceca5 bellard
692 636aa200 Blue Swirl
static inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0,
693 636aa200 Blue Swirl
                                           TCGv arg1, TCGv arg2, int sub)
694 74637406 aurel32
{
695 74637406 aurel32
    int l1;
696 74637406 aurel32
    TCGv t0;
697 79aceca5 bellard
698 74637406 aurel32
    l1 = gen_new_label();
699 74637406 aurel32
    /* Start with XER OV disabled, the most likely case */
700 74637406 aurel32
    tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
701 a7812ae4 pbrook
    t0 = tcg_temp_local_new();
702 74637406 aurel32
    tcg_gen_xor_tl(t0, arg0, arg1);
703 74637406 aurel32
#if defined(TARGET_PPC64)
704 74637406 aurel32
    if (!ctx->sf_mode)
705 74637406 aurel32
        tcg_gen_ext32s_tl(t0, t0);
706 74637406 aurel32
#endif
707 74637406 aurel32
    if (sub)
708 74637406 aurel32
        tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0, l1);
709 74637406 aurel32
    else
710 74637406 aurel32
        tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1);
711 74637406 aurel32
    tcg_gen_xor_tl(t0, arg1, arg2);
712 74637406 aurel32
#if defined(TARGET_PPC64)
713 74637406 aurel32
    if (!ctx->sf_mode)
714 74637406 aurel32
        tcg_gen_ext32s_tl(t0, t0);
715 74637406 aurel32
#endif
716 74637406 aurel32
    if (sub)
717 74637406 aurel32
        tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1);
718 74637406 aurel32
    else
719 74637406 aurel32
        tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0, l1);
720 74637406 aurel32
    tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
721 74637406 aurel32
    gen_set_label(l1);
722 74637406 aurel32
    tcg_temp_free(t0);
723 79aceca5 bellard
}
724 79aceca5 bellard
725 636aa200 Blue Swirl
static inline void gen_op_arith_compute_ca(DisasContext *ctx, TCGv arg1,
726 636aa200 Blue Swirl
                                           TCGv arg2, int sub)
727 74637406 aurel32
{
728 74637406 aurel32
    int l1 = gen_new_label();
729 d9bce9d9 j_mayer
730 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
731 74637406 aurel32
    if (!(ctx->sf_mode)) {
732 74637406 aurel32
        TCGv t0, t1;
733 a7812ae4 pbrook
        t0 = tcg_temp_new();
734 a7812ae4 pbrook
        t1 = tcg_temp_new();
735 d9bce9d9 j_mayer
736 74637406 aurel32
        tcg_gen_ext32u_tl(t0, arg1);
737 74637406 aurel32
        tcg_gen_ext32u_tl(t1, arg2);
738 74637406 aurel32
        if (sub) {
739 74637406 aurel32
            tcg_gen_brcond_tl(TCG_COND_GTU, t0, t1, l1);
740 bdc4e053 aurel32
        } else {
741 74637406 aurel32
            tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
742 74637406 aurel32
        }
743 a9730017 aurel32
        tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA);
744 a9730017 aurel32
        gen_set_label(l1);
745 a9730017 aurel32
        tcg_temp_free(t0);
746 a9730017 aurel32
        tcg_temp_free(t1);
747 74637406 aurel32
    } else
748 74637406 aurel32
#endif
749 a9730017 aurel32
    {
750 a9730017 aurel32
        if (sub) {
751 a9730017 aurel32
            tcg_gen_brcond_tl(TCG_COND_GTU, arg1, arg2, l1);
752 a9730017 aurel32
        } else {
753 a9730017 aurel32
            tcg_gen_brcond_tl(TCG_COND_GEU, arg1, arg2, l1);
754 a9730017 aurel32
        }
755 a9730017 aurel32
        tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA);
756 a9730017 aurel32
        gen_set_label(l1);
757 74637406 aurel32
    }
758 d9bce9d9 j_mayer
}
759 d9bce9d9 j_mayer
760 74637406 aurel32
/* Common add function */
761 636aa200 Blue Swirl
static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1,
762 636aa200 Blue Swirl
                                    TCGv arg2, int add_ca, int compute_ca,
763 636aa200 Blue Swirl
                                    int compute_ov)
764 74637406 aurel32
{
765 74637406 aurel32
    TCGv t0, t1;
766 d9bce9d9 j_mayer
767 74637406 aurel32
    if ((!compute_ca && !compute_ov) ||
768 a7812ae4 pbrook
        (!TCGV_EQUAL(ret,arg1) && !TCGV_EQUAL(ret, arg2)))  {
769 74637406 aurel32
        t0 = ret;
770 74637406 aurel32
    } else {
771 a7812ae4 pbrook
        t0 = tcg_temp_local_new();
772 74637406 aurel32
    }
773 79aceca5 bellard
774 74637406 aurel32
    if (add_ca) {
775 a7812ae4 pbrook
        t1 = tcg_temp_local_new();
776 74637406 aurel32
        tcg_gen_andi_tl(t1, cpu_xer, (1 << XER_CA));
777 74637406 aurel32
        tcg_gen_shri_tl(t1, t1, XER_CA);
778 d2e9fd8f malc
    } else {
779 d2e9fd8f malc
        TCGV_UNUSED(t1);
780 74637406 aurel32
    }
781 79aceca5 bellard
782 74637406 aurel32
    if (compute_ca && compute_ov) {
783 74637406 aurel32
        /* Start with XER CA and OV disabled, the most likely case */
784 74637406 aurel32
        tcg_gen_andi_tl(cpu_xer, cpu_xer, ~((1 << XER_CA) | (1 << XER_OV)));
785 74637406 aurel32
    } else if (compute_ca) {
786 74637406 aurel32
        /* Start with XER CA disabled, the most likely case */
787 74637406 aurel32
        tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
788 74637406 aurel32
    } else if (compute_ov) {
789 74637406 aurel32
        /* Start with XER OV disabled, the most likely case */
790 74637406 aurel32
        tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
791 74637406 aurel32
    }
792 79aceca5 bellard
793 74637406 aurel32
    tcg_gen_add_tl(t0, arg1, arg2);
794 74637406 aurel32
795 74637406 aurel32
    if (compute_ca) {
796 74637406 aurel32
        gen_op_arith_compute_ca(ctx, t0, arg1, 0);
797 74637406 aurel32
    }
798 74637406 aurel32
    if (add_ca) {
799 74637406 aurel32
        tcg_gen_add_tl(t0, t0, t1);
800 74637406 aurel32
        gen_op_arith_compute_ca(ctx, t0, t1, 0);
801 74637406 aurel32
        tcg_temp_free(t1);
802 74637406 aurel32
    }
803 74637406 aurel32
    if (compute_ov) {
804 74637406 aurel32
        gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0);
805 74637406 aurel32
    }
806 74637406 aurel32
807 74637406 aurel32
    if (unlikely(Rc(ctx->opcode) != 0))
808 74637406 aurel32
        gen_set_Rc0(ctx, t0);
809 74637406 aurel32
810 a7812ae4 pbrook
    if (!TCGV_EQUAL(t0, ret)) {
811 74637406 aurel32
        tcg_gen_mov_tl(ret, t0);
812 74637406 aurel32
        tcg_temp_free(t0);
813 74637406 aurel32
    }
814 39dd32ee aurel32
}
815 74637406 aurel32
/* Add functions with two operands */
816 74637406 aurel32
#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov)         \
817 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                                       \
818 74637406 aurel32
{                                                                             \
819 74637406 aurel32
    gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)],                           \
820 74637406 aurel32
                     cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],      \
821 74637406 aurel32
                     add_ca, compute_ca, compute_ov);                         \
822 74637406 aurel32
}
823 74637406 aurel32
/* Add functions with one operand and one immediate */
824 74637406 aurel32
#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val,                        \
825 74637406 aurel32
                                add_ca, compute_ca, compute_ov)               \
826 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                                       \
827 74637406 aurel32
{                                                                             \
828 74637406 aurel32
    TCGv t0 = tcg_const_local_tl(const_val);                                  \
829 74637406 aurel32
    gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)],                           \
830 74637406 aurel32
                     cpu_gpr[rA(ctx->opcode)], t0,                            \
831 74637406 aurel32
                     add_ca, compute_ca, compute_ov);                         \
832 74637406 aurel32
    tcg_temp_free(t0);                                                        \
833 74637406 aurel32
}
834 74637406 aurel32
835 74637406 aurel32
/* add  add.  addo  addo. */
836 74637406 aurel32
GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
837 74637406 aurel32
GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
838 74637406 aurel32
/* addc  addc.  addco  addco. */
839 74637406 aurel32
GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
840 74637406 aurel32
GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
841 74637406 aurel32
/* adde  adde.  addeo  addeo. */
842 74637406 aurel32
GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
843 74637406 aurel32
GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
844 74637406 aurel32
/* addme  addme.  addmeo  addmeo.  */
845 74637406 aurel32
GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
846 74637406 aurel32
GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
847 74637406 aurel32
/* addze  addze.  addzeo  addzeo.*/
848 74637406 aurel32
GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
849 74637406 aurel32
GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
850 74637406 aurel32
/* addi */
851 99e300ef Blue Swirl
static void gen_addi(DisasContext *ctx)
852 d9bce9d9 j_mayer
{
853 74637406 aurel32
    target_long simm = SIMM(ctx->opcode);
854 74637406 aurel32
855 74637406 aurel32
    if (rA(ctx->opcode) == 0) {
856 74637406 aurel32
        /* li case */
857 74637406 aurel32
        tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm);
858 74637406 aurel32
    } else {
859 74637406 aurel32
        tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], simm);
860 74637406 aurel32
    }
861 d9bce9d9 j_mayer
}
862 74637406 aurel32
/* addic  addic.*/
863 636aa200 Blue Swirl
static inline void gen_op_addic(DisasContext *ctx, TCGv ret, TCGv arg1,
864 636aa200 Blue Swirl
                                int compute_Rc0)
865 d9bce9d9 j_mayer
{
866 74637406 aurel32
    target_long simm = SIMM(ctx->opcode);
867 74637406 aurel32
868 74637406 aurel32
    /* Start with XER CA and OV disabled, the most likely case */
869 74637406 aurel32
    tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
870 74637406 aurel32
871 74637406 aurel32
    if (likely(simm != 0)) {
872 a7812ae4 pbrook
        TCGv t0 = tcg_temp_local_new();
873 74637406 aurel32
        tcg_gen_addi_tl(t0, arg1, simm);
874 74637406 aurel32
        gen_op_arith_compute_ca(ctx, t0, arg1, 0);
875 74637406 aurel32
        tcg_gen_mov_tl(ret, t0);
876 74637406 aurel32
        tcg_temp_free(t0);
877 74637406 aurel32
    } else {
878 74637406 aurel32
        tcg_gen_mov_tl(ret, arg1);
879 74637406 aurel32
    }
880 74637406 aurel32
    if (compute_Rc0) {
881 74637406 aurel32
        gen_set_Rc0(ctx, ret);
882 74637406 aurel32
    }
883 d9bce9d9 j_mayer
}
884 99e300ef Blue Swirl
885 99e300ef Blue Swirl
static void gen_addic(DisasContext *ctx)
886 d9bce9d9 j_mayer
{
887 74637406 aurel32
    gen_op_addic(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0);
888 d9bce9d9 j_mayer
}
889 e8eaa2c0 Blue Swirl
890 e8eaa2c0 Blue Swirl
static void gen_addic_(DisasContext *ctx)
891 d9bce9d9 j_mayer
{
892 74637406 aurel32
    gen_op_addic(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 1);
893 d9bce9d9 j_mayer
}
894 99e300ef Blue Swirl
895 54623277 Blue Swirl
/* addis */
896 99e300ef Blue Swirl
static void gen_addis(DisasContext *ctx)
897 d9bce9d9 j_mayer
{
898 74637406 aurel32
    target_long simm = SIMM(ctx->opcode);
899 74637406 aurel32
900 74637406 aurel32
    if (rA(ctx->opcode) == 0) {
901 74637406 aurel32
        /* lis case */
902 74637406 aurel32
        tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16);
903 74637406 aurel32
    } else {
904 74637406 aurel32
        tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], simm << 16);
905 74637406 aurel32
    }
906 d9bce9d9 j_mayer
}
907 74637406 aurel32
908 636aa200 Blue Swirl
static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1,
909 636aa200 Blue Swirl
                                     TCGv arg2, int sign, int compute_ov)
910 d9bce9d9 j_mayer
{
911 2ef1b120 aurel32
    int l1 = gen_new_label();
912 2ef1b120 aurel32
    int l2 = gen_new_label();
913 a7812ae4 pbrook
    TCGv_i32 t0 = tcg_temp_local_new_i32();
914 a7812ae4 pbrook
    TCGv_i32 t1 = tcg_temp_local_new_i32();
915 74637406 aurel32
916 2ef1b120 aurel32
    tcg_gen_trunc_tl_i32(t0, arg1);
917 2ef1b120 aurel32
    tcg_gen_trunc_tl_i32(t1, arg2);
918 2ef1b120 aurel32
    tcg_gen_brcondi_i32(TCG_COND_EQ, t1, 0, l1);
919 74637406 aurel32
    if (sign) {
920 2ef1b120 aurel32
        int l3 = gen_new_label();
921 2ef1b120 aurel32
        tcg_gen_brcondi_i32(TCG_COND_NE, t1, -1, l3);
922 2ef1b120 aurel32
        tcg_gen_brcondi_i32(TCG_COND_EQ, t0, INT32_MIN, l1);
923 74637406 aurel32
        gen_set_label(l3);
924 2ef1b120 aurel32
        tcg_gen_div_i32(t0, t0, t1);
925 74637406 aurel32
    } else {
926 2ef1b120 aurel32
        tcg_gen_divu_i32(t0, t0, t1);
927 74637406 aurel32
    }
928 74637406 aurel32
    if (compute_ov) {
929 74637406 aurel32
        tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
930 74637406 aurel32
    }
931 74637406 aurel32
    tcg_gen_br(l2);
932 74637406 aurel32
    gen_set_label(l1);
933 74637406 aurel32
    if (sign) {
934 2ef1b120 aurel32
        tcg_gen_sari_i32(t0, t0, 31);
935 74637406 aurel32
    } else {
936 74637406 aurel32
        tcg_gen_movi_i32(t0, 0);
937 74637406 aurel32
    }
938 74637406 aurel32
    if (compute_ov) {
939 74637406 aurel32
        tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
940 74637406 aurel32
    }
941 74637406 aurel32
    gen_set_label(l2);
942 2ef1b120 aurel32
    tcg_gen_extu_i32_tl(ret, t0);
943 a7812ae4 pbrook
    tcg_temp_free_i32(t0);
944 a7812ae4 pbrook
    tcg_temp_free_i32(t1);
945 74637406 aurel32
    if (unlikely(Rc(ctx->opcode) != 0))
946 74637406 aurel32
        gen_set_Rc0(ctx, ret);
947 d9bce9d9 j_mayer
}
948 74637406 aurel32
/* Div functions */
949 74637406 aurel32
#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov)                      \
950 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                                       \
951 74637406 aurel32
{                                                                             \
952 74637406 aurel32
    gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)],                          \
953 74637406 aurel32
                     cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],      \
954 74637406 aurel32
                     sign, compute_ov);                                       \
955 74637406 aurel32
}
956 74637406 aurel32
/* divwu  divwu.  divwuo  divwuo.   */
957 74637406 aurel32
GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0);
958 74637406 aurel32
GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1);
959 74637406 aurel32
/* divw  divw.  divwo  divwo.   */
960 74637406 aurel32
GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0);
961 74637406 aurel32
GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1);
962 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
963 636aa200 Blue Swirl
static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, TCGv arg1,
964 636aa200 Blue Swirl
                                     TCGv arg2, int sign, int compute_ov)
965 d9bce9d9 j_mayer
{
966 2ef1b120 aurel32
    int l1 = gen_new_label();
967 2ef1b120 aurel32
    int l2 = gen_new_label();
968 74637406 aurel32
969 74637406 aurel32
    tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1);
970 74637406 aurel32
    if (sign) {
971 2ef1b120 aurel32
        int l3 = gen_new_label();
972 74637406 aurel32
        tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3);
973 74637406 aurel32
        tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1);
974 74637406 aurel32
        gen_set_label(l3);
975 74637406 aurel32
        tcg_gen_div_i64(ret, arg1, arg2);
976 74637406 aurel32
    } else {
977 74637406 aurel32
        tcg_gen_divu_i64(ret, arg1, arg2);
978 74637406 aurel32
    }
979 74637406 aurel32
    if (compute_ov) {
980 74637406 aurel32
        tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
981 74637406 aurel32
    }
982 74637406 aurel32
    tcg_gen_br(l2);
983 74637406 aurel32
    gen_set_label(l1);
984 74637406 aurel32
    if (sign) {
985 74637406 aurel32
        tcg_gen_sari_i64(ret, arg1, 63);
986 74637406 aurel32
    } else {
987 74637406 aurel32
        tcg_gen_movi_i64(ret, 0);
988 74637406 aurel32
    }
989 74637406 aurel32
    if (compute_ov) {
990 74637406 aurel32
        tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
991 74637406 aurel32
    }
992 74637406 aurel32
    gen_set_label(l2);
993 74637406 aurel32
    if (unlikely(Rc(ctx->opcode) != 0))
994 74637406 aurel32
        gen_set_Rc0(ctx, ret);
995 d9bce9d9 j_mayer
}
996 74637406 aurel32
#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov)                      \
997 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                                       \
998 74637406 aurel32
{                                                                             \
999 2ef1b120 aurel32
    gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)],                          \
1000 2ef1b120 aurel32
                      cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],     \
1001 2ef1b120 aurel32
                      sign, compute_ov);                                      \
1002 74637406 aurel32
}
1003 74637406 aurel32
/* divwu  divwu.  divwuo  divwuo.   */
1004 74637406 aurel32
GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0);
1005 74637406 aurel32
GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1);
1006 74637406 aurel32
/* divw  divw.  divwo  divwo.   */
1007 74637406 aurel32
GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0);
1008 74637406 aurel32
GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1);
1009 d9bce9d9 j_mayer
#endif
1010 74637406 aurel32
1011 74637406 aurel32
/* mulhw  mulhw. */
1012 99e300ef Blue Swirl
static void gen_mulhw(DisasContext *ctx)
1013 d9bce9d9 j_mayer
{
1014 a7812ae4 pbrook
    TCGv_i64 t0, t1;
1015 74637406 aurel32
1016 a7812ae4 pbrook
    t0 = tcg_temp_new_i64();
1017 a7812ae4 pbrook
    t1 = tcg_temp_new_i64();
1018 74637406 aurel32
#if defined(TARGET_PPC64)
1019 74637406 aurel32
    tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]);
1020 74637406 aurel32
    tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]);
1021 74637406 aurel32
    tcg_gen_mul_i64(t0, t0, t1);
1022 74637406 aurel32
    tcg_gen_shri_i64(cpu_gpr[rD(ctx->opcode)], t0, 32);
1023 74637406 aurel32
#else
1024 74637406 aurel32
    tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1025 74637406 aurel32
    tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1026 74637406 aurel32
    tcg_gen_mul_i64(t0, t0, t1);
1027 74637406 aurel32
    tcg_gen_shri_i64(t0, t0, 32);
1028 74637406 aurel32
    tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0);
1029 74637406 aurel32
#endif
1030 a7812ae4 pbrook
    tcg_temp_free_i64(t0);
1031 a7812ae4 pbrook
    tcg_temp_free_i64(t1);
1032 74637406 aurel32
    if (unlikely(Rc(ctx->opcode) != 0))
1033 74637406 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1034 d9bce9d9 j_mayer
}
1035 99e300ef Blue Swirl
1036 54623277 Blue Swirl
/* mulhwu  mulhwu.  */
1037 99e300ef Blue Swirl
static void gen_mulhwu(DisasContext *ctx)
1038 d9bce9d9 j_mayer
{
1039 a7812ae4 pbrook
    TCGv_i64 t0, t1;
1040 74637406 aurel32
1041 a7812ae4 pbrook
    t0 = tcg_temp_new_i64();
1042 a7812ae4 pbrook
    t1 = tcg_temp_new_i64();
1043 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
1044 74637406 aurel32
    tcg_gen_ext32u_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1045 74637406 aurel32
    tcg_gen_ext32u_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1046 74637406 aurel32
    tcg_gen_mul_i64(t0, t0, t1);
1047 74637406 aurel32
    tcg_gen_shri_i64(cpu_gpr[rD(ctx->opcode)], t0, 32);
1048 74637406 aurel32
#else
1049 74637406 aurel32
    tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1050 74637406 aurel32
    tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1051 74637406 aurel32
    tcg_gen_mul_i64(t0, t0, t1);
1052 74637406 aurel32
    tcg_gen_shri_i64(t0, t0, 32);
1053 74637406 aurel32
    tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0);
1054 74637406 aurel32
#endif
1055 a7812ae4 pbrook
    tcg_temp_free_i64(t0);
1056 a7812ae4 pbrook
    tcg_temp_free_i64(t1);
1057 74637406 aurel32
    if (unlikely(Rc(ctx->opcode) != 0))
1058 74637406 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1059 d9bce9d9 j_mayer
}
1060 99e300ef Blue Swirl
1061 54623277 Blue Swirl
/* mullw  mullw. */
1062 99e300ef Blue Swirl
static void gen_mullw(DisasContext *ctx)
1063 d9bce9d9 j_mayer
{
1064 74637406 aurel32
    tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1065 74637406 aurel32
                   cpu_gpr[rB(ctx->opcode)]);
1066 1e4c090f aurel32
    tcg_gen_ext32s_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)]);
1067 74637406 aurel32
    if (unlikely(Rc(ctx->opcode) != 0))
1068 74637406 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1069 d9bce9d9 j_mayer
}
1070 99e300ef Blue Swirl
1071 54623277 Blue Swirl
/* mullwo  mullwo. */
1072 99e300ef Blue Swirl
static void gen_mullwo(DisasContext *ctx)
1073 d9bce9d9 j_mayer
{
1074 74637406 aurel32
    int l1;
1075 a7812ae4 pbrook
    TCGv_i64 t0, t1;
1076 74637406 aurel32
1077 a7812ae4 pbrook
    t0 = tcg_temp_new_i64();
1078 a7812ae4 pbrook
    t1 = tcg_temp_new_i64();
1079 74637406 aurel32
    l1 = gen_new_label();
1080 74637406 aurel32
    /* Start with XER OV disabled, the most likely case */
1081 74637406 aurel32
    tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
1082 74637406 aurel32
#if defined(TARGET_PPC64)
1083 74637406 aurel32
    tcg_gen_ext32s_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1084 74637406 aurel32
    tcg_gen_ext32s_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1085 74637406 aurel32
#else
1086 74637406 aurel32
    tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1087 74637406 aurel32
    tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1088 d9bce9d9 j_mayer
#endif
1089 74637406 aurel32
    tcg_gen_mul_i64(t0, t0, t1);
1090 74637406 aurel32
#if defined(TARGET_PPC64)
1091 74637406 aurel32
    tcg_gen_ext32s_i64(cpu_gpr[rD(ctx->opcode)], t0);
1092 74637406 aurel32
    tcg_gen_brcond_i64(TCG_COND_EQ, t0, cpu_gpr[rD(ctx->opcode)], l1);
1093 74637406 aurel32
#else
1094 74637406 aurel32
    tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0);
1095 74637406 aurel32
    tcg_gen_ext32s_i64(t1, t0);
1096 74637406 aurel32
    tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1);
1097 74637406 aurel32
#endif
1098 74637406 aurel32
    tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
1099 74637406 aurel32
    gen_set_label(l1);
1100 a7812ae4 pbrook
    tcg_temp_free_i64(t0);
1101 a7812ae4 pbrook
    tcg_temp_free_i64(t1);
1102 74637406 aurel32
    if (unlikely(Rc(ctx->opcode) != 0))
1103 74637406 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1104 d9bce9d9 j_mayer
}
1105 99e300ef Blue Swirl
1106 54623277 Blue Swirl
/* mulli */
1107 99e300ef Blue Swirl
static void gen_mulli(DisasContext *ctx)
1108 d9bce9d9 j_mayer
{
1109 74637406 aurel32
    tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1110 74637406 aurel32
                    SIMM(ctx->opcode));
1111 d9bce9d9 j_mayer
}
1112 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
1113 74637406 aurel32
#define GEN_INT_ARITH_MUL_HELPER(name, opc3)                                  \
1114 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                                       \
1115 74637406 aurel32
{                                                                             \
1116 a7812ae4 pbrook
    gen_helper_##name (cpu_gpr[rD(ctx->opcode)],                              \
1117 74637406 aurel32
                       cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);   \
1118 74637406 aurel32
    if (unlikely(Rc(ctx->opcode) != 0))                                       \
1119 74637406 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);                           \
1120 d9bce9d9 j_mayer
}
1121 74637406 aurel32
/* mulhd  mulhd. */
1122 74637406 aurel32
GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00);
1123 74637406 aurel32
/* mulhdu  mulhdu. */
1124 74637406 aurel32
GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02);
1125 99e300ef Blue Swirl
1126 54623277 Blue Swirl
/* mulld  mulld. */
1127 99e300ef Blue Swirl
static void gen_mulld(DisasContext *ctx)
1128 d9bce9d9 j_mayer
{
1129 74637406 aurel32
    tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1130 74637406 aurel32
                   cpu_gpr[rB(ctx->opcode)]);
1131 74637406 aurel32
    if (unlikely(Rc(ctx->opcode) != 0))
1132 74637406 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1133 d9bce9d9 j_mayer
}
1134 74637406 aurel32
/* mulldo  mulldo. */
1135 74637406 aurel32
GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17);
1136 d9bce9d9 j_mayer
#endif
1137 74637406 aurel32
1138 74637406 aurel32
/* neg neg. nego nego. */
1139 636aa200 Blue Swirl
static inline void gen_op_arith_neg(DisasContext *ctx, TCGv ret, TCGv arg1,
1140 636aa200 Blue Swirl
                                    int ov_check)
1141 d9bce9d9 j_mayer
{
1142 ec6469a3 aurel32
    int l1 = gen_new_label();
1143 ec6469a3 aurel32
    int l2 = gen_new_label();
1144 a7812ae4 pbrook
    TCGv t0 = tcg_temp_local_new();
1145 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
1146 74637406 aurel32
    if (ctx->sf_mode) {
1147 741a7444 aurel32
        tcg_gen_mov_tl(t0, arg1);
1148 ec6469a3 aurel32
        tcg_gen_brcondi_tl(TCG_COND_EQ, t0, INT64_MIN, l1);
1149 ec6469a3 aurel32
    } else
1150 ec6469a3 aurel32
#endif
1151 ec6469a3 aurel32
    {
1152 ec6469a3 aurel32
        tcg_gen_ext32s_tl(t0, arg1);
1153 74637406 aurel32
        tcg_gen_brcondi_tl(TCG_COND_EQ, t0, INT32_MIN, l1);
1154 74637406 aurel32
    }
1155 74637406 aurel32
    tcg_gen_neg_tl(ret, arg1);
1156 74637406 aurel32
    if (ov_check) {
1157 74637406 aurel32
        tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
1158 74637406 aurel32
    }
1159 74637406 aurel32
    tcg_gen_br(l2);
1160 74637406 aurel32
    gen_set_label(l1);
1161 ec6469a3 aurel32
    tcg_gen_mov_tl(ret, t0);
1162 74637406 aurel32
    if (ov_check) {
1163 74637406 aurel32
        tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
1164 74637406 aurel32
    }
1165 74637406 aurel32
    gen_set_label(l2);
1166 ec6469a3 aurel32
    tcg_temp_free(t0);
1167 74637406 aurel32
    if (unlikely(Rc(ctx->opcode) != 0))
1168 74637406 aurel32
        gen_set_Rc0(ctx, ret);
1169 74637406 aurel32
}
1170 99e300ef Blue Swirl
1171 99e300ef Blue Swirl
static void gen_neg(DisasContext *ctx)
1172 d9bce9d9 j_mayer
{
1173 ec6469a3 aurel32
    gen_op_arith_neg(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0);
1174 d9bce9d9 j_mayer
}
1175 99e300ef Blue Swirl
1176 99e300ef Blue Swirl
static void gen_nego(DisasContext *ctx)
1177 79aceca5 bellard
{
1178 ec6469a3 aurel32
    gen_op_arith_neg(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 1);
1179 79aceca5 bellard
}
1180 74637406 aurel32
1181 74637406 aurel32
/* Common subf function */
1182 636aa200 Blue Swirl
static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1,
1183 636aa200 Blue Swirl
                                     TCGv arg2, int add_ca, int compute_ca,
1184 636aa200 Blue Swirl
                                     int compute_ov)
1185 79aceca5 bellard
{
1186 74637406 aurel32
    TCGv t0, t1;
1187 76a66253 j_mayer
1188 74637406 aurel32
    if ((!compute_ca && !compute_ov) ||
1189 a7812ae4 pbrook
        (!TCGV_EQUAL(ret, arg1) && !TCGV_EQUAL(ret, arg2)))  {
1190 74637406 aurel32
        t0 = ret;
1191 e864cabd j_mayer
    } else {
1192 a7812ae4 pbrook
        t0 = tcg_temp_local_new();
1193 d9bce9d9 j_mayer
    }
1194 76a66253 j_mayer
1195 74637406 aurel32
    if (add_ca) {
1196 a7812ae4 pbrook
        t1 = tcg_temp_local_new();
1197 74637406 aurel32
        tcg_gen_andi_tl(t1, cpu_xer, (1 << XER_CA));
1198 74637406 aurel32
        tcg_gen_shri_tl(t1, t1, XER_CA);
1199 d2e9fd8f malc
    } else {
1200 d2e9fd8f malc
        TCGV_UNUSED(t1);
1201 d9bce9d9 j_mayer
    }
1202 79aceca5 bellard
1203 74637406 aurel32
    if (compute_ca && compute_ov) {
1204 74637406 aurel32
        /* Start with XER CA and OV disabled, the most likely case */
1205 74637406 aurel32
        tcg_gen_andi_tl(cpu_xer, cpu_xer, ~((1 << XER_CA) | (1 << XER_OV)));
1206 74637406 aurel32
    } else if (compute_ca) {
1207 74637406 aurel32
        /* Start with XER CA disabled, the most likely case */
1208 74637406 aurel32
        tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
1209 74637406 aurel32
    } else if (compute_ov) {
1210 74637406 aurel32
        /* Start with XER OV disabled, the most likely case */
1211 74637406 aurel32
        tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
1212 74637406 aurel32
    }
1213 74637406 aurel32
1214 74637406 aurel32
    if (add_ca) {
1215 74637406 aurel32
        tcg_gen_not_tl(t0, arg1);
1216 74637406 aurel32
        tcg_gen_add_tl(t0, t0, arg2);
1217 74637406 aurel32
        gen_op_arith_compute_ca(ctx, t0, arg2, 0);
1218 74637406 aurel32
        tcg_gen_add_tl(t0, t0, t1);
1219 74637406 aurel32
        gen_op_arith_compute_ca(ctx, t0, t1, 0);
1220 74637406 aurel32
        tcg_temp_free(t1);
1221 79aceca5 bellard
    } else {
1222 74637406 aurel32
        tcg_gen_sub_tl(t0, arg2, arg1);
1223 74637406 aurel32
        if (compute_ca) {
1224 74637406 aurel32
            gen_op_arith_compute_ca(ctx, t0, arg2, 1);
1225 74637406 aurel32
        }
1226 74637406 aurel32
    }
1227 74637406 aurel32
    if (compute_ov) {
1228 74637406 aurel32
        gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1);
1229 74637406 aurel32
    }
1230 74637406 aurel32
1231 74637406 aurel32
    if (unlikely(Rc(ctx->opcode) != 0))
1232 74637406 aurel32
        gen_set_Rc0(ctx, t0);
1233 74637406 aurel32
1234 a7812ae4 pbrook
    if (!TCGV_EQUAL(t0, ret)) {
1235 74637406 aurel32
        tcg_gen_mov_tl(ret, t0);
1236 74637406 aurel32
        tcg_temp_free(t0);
1237 79aceca5 bellard
    }
1238 79aceca5 bellard
}
1239 74637406 aurel32
/* Sub functions with Two operands functions */
1240 74637406 aurel32
#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov)        \
1241 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                                       \
1242 74637406 aurel32
{                                                                             \
1243 74637406 aurel32
    gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)],                          \
1244 74637406 aurel32
                      cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],     \
1245 74637406 aurel32
                      add_ca, compute_ca, compute_ov);                        \
1246 74637406 aurel32
}
1247 74637406 aurel32
/* Sub functions with one operand and one immediate */
1248 74637406 aurel32
#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val,                       \
1249 74637406 aurel32
                                add_ca, compute_ca, compute_ov)               \
1250 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                                       \
1251 74637406 aurel32
{                                                                             \
1252 74637406 aurel32
    TCGv t0 = tcg_const_local_tl(const_val);                                  \
1253 74637406 aurel32
    gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)],                          \
1254 74637406 aurel32
                      cpu_gpr[rA(ctx->opcode)], t0,                           \
1255 74637406 aurel32
                      add_ca, compute_ca, compute_ov);                        \
1256 74637406 aurel32
    tcg_temp_free(t0);                                                        \
1257 74637406 aurel32
}
1258 74637406 aurel32
/* subf  subf.  subfo  subfo. */
1259 74637406 aurel32
GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
1260 74637406 aurel32
GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
1261 74637406 aurel32
/* subfc  subfc.  subfco  subfco. */
1262 74637406 aurel32
GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
1263 74637406 aurel32
GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
1264 74637406 aurel32
/* subfe  subfe.  subfeo  subfo. */
1265 74637406 aurel32
GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
1266 74637406 aurel32
GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
1267 74637406 aurel32
/* subfme  subfme.  subfmeo  subfmeo.  */
1268 74637406 aurel32
GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
1269 74637406 aurel32
GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
1270 74637406 aurel32
/* subfze  subfze.  subfzeo  subfzeo.*/
1271 74637406 aurel32
GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
1272 74637406 aurel32
GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
1273 99e300ef Blue Swirl
1274 54623277 Blue Swirl
/* subfic */
1275 99e300ef Blue Swirl
static void gen_subfic(DisasContext *ctx)
1276 79aceca5 bellard
{
1277 74637406 aurel32
    /* Start with XER CA and OV disabled, the most likely case */
1278 74637406 aurel32
    tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
1279 a7812ae4 pbrook
    TCGv t0 = tcg_temp_local_new();
1280 74637406 aurel32
    TCGv t1 = tcg_const_local_tl(SIMM(ctx->opcode));
1281 74637406 aurel32
    tcg_gen_sub_tl(t0, t1, cpu_gpr[rA(ctx->opcode)]);
1282 74637406 aurel32
    gen_op_arith_compute_ca(ctx, t0, t1, 1);
1283 74637406 aurel32
    tcg_temp_free(t1);
1284 74637406 aurel32
    tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
1285 74637406 aurel32
    tcg_temp_free(t0);
1286 79aceca5 bellard
}
1287 79aceca5 bellard
1288 79aceca5 bellard
/***                            Integer logical                            ***/
1289 26d67362 aurel32
#define GEN_LOGICAL2(name, tcg_op, opc, type)                                 \
1290 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                                       \
1291 79aceca5 bellard
{                                                                             \
1292 26d67362 aurel32
    tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)],                \
1293 26d67362 aurel32
       cpu_gpr[rB(ctx->opcode)]);                                             \
1294 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))                                       \
1295 26d67362 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);                           \
1296 79aceca5 bellard
}
1297 79aceca5 bellard
1298 26d67362 aurel32
#define GEN_LOGICAL1(name, tcg_op, opc, type)                                 \
1299 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                                       \
1300 79aceca5 bellard
{                                                                             \
1301 26d67362 aurel32
    tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);               \
1302 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))                                       \
1303 26d67362 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);                           \
1304 79aceca5 bellard
}
1305 79aceca5 bellard
1306 79aceca5 bellard
/* and & and. */
1307 26d67362 aurel32
GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER);
1308 79aceca5 bellard
/* andc & andc. */
1309 26d67362 aurel32
GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER);
1310 e8eaa2c0 Blue Swirl
1311 54623277 Blue Swirl
/* andi. */
1312 e8eaa2c0 Blue Swirl
static void gen_andi_(DisasContext *ctx)
1313 79aceca5 bellard
{
1314 26d67362 aurel32
    tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode));
1315 26d67362 aurel32
    gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1316 79aceca5 bellard
}
1317 e8eaa2c0 Blue Swirl
1318 54623277 Blue Swirl
/* andis. */
1319 e8eaa2c0 Blue Swirl
static void gen_andis_(DisasContext *ctx)
1320 79aceca5 bellard
{
1321 26d67362 aurel32
    tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16);
1322 26d67362 aurel32
    gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1323 79aceca5 bellard
}
1324 99e300ef Blue Swirl
1325 54623277 Blue Swirl
/* cntlzw */
1326 99e300ef Blue Swirl
static void gen_cntlzw(DisasContext *ctx)
1327 26d67362 aurel32
{
1328 a7812ae4 pbrook
    gen_helper_cntlzw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1329 26d67362 aurel32
    if (unlikely(Rc(ctx->opcode) != 0))
1330 2e31f5d3 pbrook
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1331 26d67362 aurel32
}
1332 79aceca5 bellard
/* eqv & eqv. */
1333 26d67362 aurel32
GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER);
1334 79aceca5 bellard
/* extsb & extsb. */
1335 26d67362 aurel32
GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER);
1336 79aceca5 bellard
/* extsh & extsh. */
1337 26d67362 aurel32
GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER);
1338 79aceca5 bellard
/* nand & nand. */
1339 26d67362 aurel32
GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER);
1340 79aceca5 bellard
/* nor & nor. */
1341 26d67362 aurel32
GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER);
1342 99e300ef Blue Swirl
1343 54623277 Blue Swirl
/* or & or. */
1344 99e300ef Blue Swirl
static void gen_or(DisasContext *ctx)
1345 9a64fbe4 bellard
{
1346 76a66253 j_mayer
    int rs, ra, rb;
1347 76a66253 j_mayer
1348 76a66253 j_mayer
    rs = rS(ctx->opcode);
1349 76a66253 j_mayer
    ra = rA(ctx->opcode);
1350 76a66253 j_mayer
    rb = rB(ctx->opcode);
1351 76a66253 j_mayer
    /* Optimisation for mr. ri case */
1352 76a66253 j_mayer
    if (rs != ra || rs != rb) {
1353 26d67362 aurel32
        if (rs != rb)
1354 26d67362 aurel32
            tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]);
1355 26d67362 aurel32
        else
1356 26d67362 aurel32
            tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]);
1357 76a66253 j_mayer
        if (unlikely(Rc(ctx->opcode) != 0))
1358 26d67362 aurel32
            gen_set_Rc0(ctx, cpu_gpr[ra]);
1359 76a66253 j_mayer
    } else if (unlikely(Rc(ctx->opcode) != 0)) {
1360 26d67362 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rs]);
1361 c80f84e3 j_mayer
#if defined(TARGET_PPC64)
1362 c80f84e3 j_mayer
    } else {
1363 26d67362 aurel32
        int prio = 0;
1364 26d67362 aurel32
1365 c80f84e3 j_mayer
        switch (rs) {
1366 c80f84e3 j_mayer
        case 1:
1367 c80f84e3 j_mayer
            /* Set process priority to low */
1368 26d67362 aurel32
            prio = 2;
1369 c80f84e3 j_mayer
            break;
1370 c80f84e3 j_mayer
        case 6:
1371 c80f84e3 j_mayer
            /* Set process priority to medium-low */
1372 26d67362 aurel32
            prio = 3;
1373 c80f84e3 j_mayer
            break;
1374 c80f84e3 j_mayer
        case 2:
1375 c80f84e3 j_mayer
            /* Set process priority to normal */
1376 26d67362 aurel32
            prio = 4;
1377 c80f84e3 j_mayer
            break;
1378 be147d08 j_mayer
#if !defined(CONFIG_USER_ONLY)
1379 be147d08 j_mayer
        case 31:
1380 76db3ba4 aurel32
            if (ctx->mem_idx > 0) {
1381 be147d08 j_mayer
                /* Set process priority to very low */
1382 26d67362 aurel32
                prio = 1;
1383 be147d08 j_mayer
            }
1384 be147d08 j_mayer
            break;
1385 be147d08 j_mayer
        case 5:
1386 76db3ba4 aurel32
            if (ctx->mem_idx > 0) {
1387 be147d08 j_mayer
                /* Set process priority to medium-hight */
1388 26d67362 aurel32
                prio = 5;
1389 be147d08 j_mayer
            }
1390 be147d08 j_mayer
            break;
1391 be147d08 j_mayer
        case 3:
1392 76db3ba4 aurel32
            if (ctx->mem_idx > 0) {
1393 be147d08 j_mayer
                /* Set process priority to high */
1394 26d67362 aurel32
                prio = 6;
1395 be147d08 j_mayer
            }
1396 be147d08 j_mayer
            break;
1397 be147d08 j_mayer
        case 7:
1398 76db3ba4 aurel32
            if (ctx->mem_idx > 1) {
1399 be147d08 j_mayer
                /* Set process priority to very high */
1400 26d67362 aurel32
                prio = 7;
1401 be147d08 j_mayer
            }
1402 be147d08 j_mayer
            break;
1403 be147d08 j_mayer
#endif
1404 c80f84e3 j_mayer
        default:
1405 c80f84e3 j_mayer
            /* nop */
1406 c80f84e3 j_mayer
            break;
1407 c80f84e3 j_mayer
        }
1408 26d67362 aurel32
        if (prio) {
1409 a7812ae4 pbrook
            TCGv t0 = tcg_temp_new();
1410 54cdcae6 aurel32
            gen_load_spr(t0, SPR_PPR);
1411 ea363694 aurel32
            tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL);
1412 ea363694 aurel32
            tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50);
1413 54cdcae6 aurel32
            gen_store_spr(SPR_PPR, t0);
1414 ea363694 aurel32
            tcg_temp_free(t0);
1415 26d67362 aurel32
        }
1416 c80f84e3 j_mayer
#endif
1417 9a64fbe4 bellard
    }
1418 9a64fbe4 bellard
}
1419 79aceca5 bellard
/* orc & orc. */
1420 26d67362 aurel32
GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER);
1421 99e300ef Blue Swirl
1422 54623277 Blue Swirl
/* xor & xor. */
1423 99e300ef Blue Swirl
static void gen_xor(DisasContext *ctx)
1424 9a64fbe4 bellard
{
1425 9a64fbe4 bellard
    /* Optimisation for "set to zero" case */
1426 26d67362 aurel32
    if (rS(ctx->opcode) != rB(ctx->opcode))
1427 312179c4 aurel32
        tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1428 26d67362 aurel32
    else
1429 26d67362 aurel32
        tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
1430 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
1431 26d67362 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1432 9a64fbe4 bellard
}
1433 99e300ef Blue Swirl
1434 54623277 Blue Swirl
/* ori */
1435 99e300ef Blue Swirl
static void gen_ori(DisasContext *ctx)
1436 79aceca5 bellard
{
1437 76a66253 j_mayer
    target_ulong uimm = UIMM(ctx->opcode);
1438 79aceca5 bellard
1439 9a64fbe4 bellard
    if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1440 9a64fbe4 bellard
        /* NOP */
1441 76a66253 j_mayer
        /* XXX: should handle special NOPs for POWER series */
1442 9a64fbe4 bellard
        return;
1443 76a66253 j_mayer
    }
1444 26d67362 aurel32
    tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
1445 79aceca5 bellard
}
1446 99e300ef Blue Swirl
1447 54623277 Blue Swirl
/* oris */
1448 99e300ef Blue Swirl
static void gen_oris(DisasContext *ctx)
1449 79aceca5 bellard
{
1450 76a66253 j_mayer
    target_ulong uimm = UIMM(ctx->opcode);
1451 79aceca5 bellard
1452 9a64fbe4 bellard
    if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1453 9a64fbe4 bellard
        /* NOP */
1454 9a64fbe4 bellard
        return;
1455 76a66253 j_mayer
    }
1456 26d67362 aurel32
    tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
1457 79aceca5 bellard
}
1458 99e300ef Blue Swirl
1459 54623277 Blue Swirl
/* xori */
1460 99e300ef Blue Swirl
static void gen_xori(DisasContext *ctx)
1461 79aceca5 bellard
{
1462 76a66253 j_mayer
    target_ulong uimm = UIMM(ctx->opcode);
1463 9a64fbe4 bellard
1464 9a64fbe4 bellard
    if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1465 9a64fbe4 bellard
        /* NOP */
1466 9a64fbe4 bellard
        return;
1467 9a64fbe4 bellard
    }
1468 26d67362 aurel32
    tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
1469 79aceca5 bellard
}
1470 99e300ef Blue Swirl
1471 54623277 Blue Swirl
/* xoris */
1472 99e300ef Blue Swirl
static void gen_xoris(DisasContext *ctx)
1473 79aceca5 bellard
{
1474 76a66253 j_mayer
    target_ulong uimm = UIMM(ctx->opcode);
1475 9a64fbe4 bellard
1476 9a64fbe4 bellard
    if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1477 9a64fbe4 bellard
        /* NOP */
1478 9a64fbe4 bellard
        return;
1479 9a64fbe4 bellard
    }
1480 26d67362 aurel32
    tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
1481 79aceca5 bellard
}
1482 99e300ef Blue Swirl
1483 54623277 Blue Swirl
/* popcntb : PowerPC 2.03 specification */
1484 99e300ef Blue Swirl
static void gen_popcntb(DisasContext *ctx)
1485 d9bce9d9 j_mayer
{
1486 eaabeef2 David Gibson
    gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1487 eaabeef2 David Gibson
}
1488 eaabeef2 David Gibson
1489 eaabeef2 David Gibson
static void gen_popcntw(DisasContext *ctx)
1490 eaabeef2 David Gibson
{
1491 eaabeef2 David Gibson
    gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1492 eaabeef2 David Gibson
}
1493 eaabeef2 David Gibson
1494 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
1495 eaabeef2 David Gibson
/* popcntd: PowerPC 2.06 specification */
1496 eaabeef2 David Gibson
static void gen_popcntd(DisasContext *ctx)
1497 eaabeef2 David Gibson
{
1498 eaabeef2 David Gibson
    gen_helper_popcntd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1499 d9bce9d9 j_mayer
}
1500 eaabeef2 David Gibson
#endif
1501 d9bce9d9 j_mayer
1502 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
1503 d9bce9d9 j_mayer
/* extsw & extsw. */
1504 26d67362 aurel32
GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B);
1505 99e300ef Blue Swirl
1506 54623277 Blue Swirl
/* cntlzd */
1507 99e300ef Blue Swirl
static void gen_cntlzd(DisasContext *ctx)
1508 26d67362 aurel32
{
1509 a7812ae4 pbrook
    gen_helper_cntlzd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1510 26d67362 aurel32
    if (unlikely(Rc(ctx->opcode) != 0))
1511 26d67362 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1512 26d67362 aurel32
}
1513 d9bce9d9 j_mayer
#endif
1514 d9bce9d9 j_mayer
1515 79aceca5 bellard
/***                             Integer rotate                            ***/
1516 99e300ef Blue Swirl
1517 54623277 Blue Swirl
/* rlwimi & rlwimi. */
1518 99e300ef Blue Swirl
static void gen_rlwimi(DisasContext *ctx)
1519 79aceca5 bellard
{
1520 76a66253 j_mayer
    uint32_t mb, me, sh;
1521 79aceca5 bellard
1522 79aceca5 bellard
    mb = MB(ctx->opcode);
1523 79aceca5 bellard
    me = ME(ctx->opcode);
1524 76a66253 j_mayer
    sh = SH(ctx->opcode);
1525 d03ef511 aurel32
    if (likely(sh == 0 && mb == 0 && me == 31)) {
1526 d03ef511 aurel32
        tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1527 d03ef511 aurel32
    } else {
1528 d03ef511 aurel32
        target_ulong mask;
1529 a7812ae4 pbrook
        TCGv t1;
1530 a7812ae4 pbrook
        TCGv t0 = tcg_temp_new();
1531 54843a58 aurel32
#if defined(TARGET_PPC64)
1532 a7812ae4 pbrook
        TCGv_i32 t2 = tcg_temp_new_i32();
1533 a7812ae4 pbrook
        tcg_gen_trunc_i64_i32(t2, cpu_gpr[rS(ctx->opcode)]);
1534 a7812ae4 pbrook
        tcg_gen_rotli_i32(t2, t2, sh);
1535 a7812ae4 pbrook
        tcg_gen_extu_i32_i64(t0, t2);
1536 a7812ae4 pbrook
        tcg_temp_free_i32(t2);
1537 54843a58 aurel32
#else
1538 54843a58 aurel32
        tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1539 54843a58 aurel32
#endif
1540 76a66253 j_mayer
#if defined(TARGET_PPC64)
1541 d03ef511 aurel32
        mb += 32;
1542 d03ef511 aurel32
        me += 32;
1543 76a66253 j_mayer
#endif
1544 d03ef511 aurel32
        mask = MASK(mb, me);
1545 a7812ae4 pbrook
        t1 = tcg_temp_new();
1546 d03ef511 aurel32
        tcg_gen_andi_tl(t0, t0, mask);
1547 d03ef511 aurel32
        tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1548 d03ef511 aurel32
        tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1549 d03ef511 aurel32
        tcg_temp_free(t0);
1550 d03ef511 aurel32
        tcg_temp_free(t1);
1551 d03ef511 aurel32
    }
1552 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
1553 d03ef511 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1554 79aceca5 bellard
}
1555 99e300ef Blue Swirl
1556 54623277 Blue Swirl
/* rlwinm & rlwinm. */
1557 99e300ef Blue Swirl
static void gen_rlwinm(DisasContext *ctx)
1558 79aceca5 bellard
{
1559 79aceca5 bellard
    uint32_t mb, me, sh;
1560 3b46e624 ths
1561 79aceca5 bellard
    sh = SH(ctx->opcode);
1562 79aceca5 bellard
    mb = MB(ctx->opcode);
1563 79aceca5 bellard
    me = ME(ctx->opcode);
1564 d03ef511 aurel32
1565 d03ef511 aurel32
    if (likely(mb == 0 && me == (31 - sh))) {
1566 d03ef511 aurel32
        if (likely(sh == 0)) {
1567 d03ef511 aurel32
            tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1568 d03ef511 aurel32
        } else {
1569 a7812ae4 pbrook
            TCGv t0 = tcg_temp_new();
1570 d03ef511 aurel32
            tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1571 d03ef511 aurel32
            tcg_gen_shli_tl(t0, t0, sh);
1572 d03ef511 aurel32
            tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1573 d03ef511 aurel32
            tcg_temp_free(t0);
1574 79aceca5 bellard
        }
1575 d03ef511 aurel32
    } else if (likely(sh != 0 && me == 31 && sh == (32 - mb))) {
1576 a7812ae4 pbrook
        TCGv t0 = tcg_temp_new();
1577 d03ef511 aurel32
        tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1578 d03ef511 aurel32
        tcg_gen_shri_tl(t0, t0, mb);
1579 d03ef511 aurel32
        tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1580 d03ef511 aurel32
        tcg_temp_free(t0);
1581 d03ef511 aurel32
    } else {
1582 a7812ae4 pbrook
        TCGv t0 = tcg_temp_new();
1583 54843a58 aurel32
#if defined(TARGET_PPC64)
1584 a7812ae4 pbrook
        TCGv_i32 t1 = tcg_temp_new_i32();
1585 54843a58 aurel32
        tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1586 54843a58 aurel32
        tcg_gen_rotli_i32(t1, t1, sh);
1587 54843a58 aurel32
        tcg_gen_extu_i32_i64(t0, t1);
1588 a7812ae4 pbrook
        tcg_temp_free_i32(t1);
1589 54843a58 aurel32
#else
1590 54843a58 aurel32
        tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1591 54843a58 aurel32
#endif
1592 76a66253 j_mayer
#if defined(TARGET_PPC64)
1593 d03ef511 aurel32
        mb += 32;
1594 d03ef511 aurel32
        me += 32;
1595 76a66253 j_mayer
#endif
1596 d03ef511 aurel32
        tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1597 d03ef511 aurel32
        tcg_temp_free(t0);
1598 d03ef511 aurel32
    }
1599 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
1600 d03ef511 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1601 79aceca5 bellard
}
1602 99e300ef Blue Swirl
1603 54623277 Blue Swirl
/* rlwnm & rlwnm. */
1604 99e300ef Blue Swirl
static void gen_rlwnm(DisasContext *ctx)
1605 79aceca5 bellard
{
1606 79aceca5 bellard
    uint32_t mb, me;
1607 54843a58 aurel32
    TCGv t0;
1608 54843a58 aurel32
#if defined(TARGET_PPC64)
1609 a7812ae4 pbrook
    TCGv_i32 t1, t2;
1610 54843a58 aurel32
#endif
1611 79aceca5 bellard
1612 79aceca5 bellard
    mb = MB(ctx->opcode);
1613 79aceca5 bellard
    me = ME(ctx->opcode);
1614 a7812ae4 pbrook
    t0 = tcg_temp_new();
1615 d03ef511 aurel32
    tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1f);
1616 54843a58 aurel32
#if defined(TARGET_PPC64)
1617 a7812ae4 pbrook
    t1 = tcg_temp_new_i32();
1618 a7812ae4 pbrook
    t2 = tcg_temp_new_i32();
1619 54843a58 aurel32
    tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1620 54843a58 aurel32
    tcg_gen_trunc_i64_i32(t2, t0);
1621 54843a58 aurel32
    tcg_gen_rotl_i32(t1, t1, t2);
1622 54843a58 aurel32
    tcg_gen_extu_i32_i64(t0, t1);
1623 a7812ae4 pbrook
    tcg_temp_free_i32(t1);
1624 a7812ae4 pbrook
    tcg_temp_free_i32(t2);
1625 54843a58 aurel32
#else
1626 54843a58 aurel32
    tcg_gen_rotl_i32(t0, cpu_gpr[rS(ctx->opcode)], t0);
1627 54843a58 aurel32
#endif
1628 76a66253 j_mayer
    if (unlikely(mb != 0 || me != 31)) {
1629 76a66253 j_mayer
#if defined(TARGET_PPC64)
1630 76a66253 j_mayer
        mb += 32;
1631 76a66253 j_mayer
        me += 32;
1632 76a66253 j_mayer
#endif
1633 54843a58 aurel32
        tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1634 d03ef511 aurel32
    } else {
1635 54843a58 aurel32
        tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1636 79aceca5 bellard
    }
1637 54843a58 aurel32
    tcg_temp_free(t0);
1638 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
1639 d03ef511 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1640 79aceca5 bellard
}
1641 79aceca5 bellard
1642 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
1643 d9bce9d9 j_mayer
#define GEN_PPC64_R2(name, opc1, opc2)                                        \
1644 e8eaa2c0 Blue Swirl
static void glue(gen_, name##0)(DisasContext *ctx)                            \
1645 d9bce9d9 j_mayer
{                                                                             \
1646 d9bce9d9 j_mayer
    gen_##name(ctx, 0);                                                       \
1647 d9bce9d9 j_mayer
}                                                                             \
1648 e8eaa2c0 Blue Swirl
                                                                              \
1649 e8eaa2c0 Blue Swirl
static void glue(gen_, name##1)(DisasContext *ctx)                            \
1650 d9bce9d9 j_mayer
{                                                                             \
1651 d9bce9d9 j_mayer
    gen_##name(ctx, 1);                                                       \
1652 d9bce9d9 j_mayer
}
1653 d9bce9d9 j_mayer
#define GEN_PPC64_R4(name, opc1, opc2)                                        \
1654 e8eaa2c0 Blue Swirl
static void glue(gen_, name##0)(DisasContext *ctx)                            \
1655 d9bce9d9 j_mayer
{                                                                             \
1656 d9bce9d9 j_mayer
    gen_##name(ctx, 0, 0);                                                    \
1657 d9bce9d9 j_mayer
}                                                                             \
1658 e8eaa2c0 Blue Swirl
                                                                              \
1659 e8eaa2c0 Blue Swirl
static void glue(gen_, name##1)(DisasContext *ctx)                            \
1660 d9bce9d9 j_mayer
{                                                                             \
1661 d9bce9d9 j_mayer
    gen_##name(ctx, 0, 1);                                                    \
1662 d9bce9d9 j_mayer
}                                                                             \
1663 e8eaa2c0 Blue Swirl
                                                                              \
1664 e8eaa2c0 Blue Swirl
static void glue(gen_, name##2)(DisasContext *ctx)                            \
1665 d9bce9d9 j_mayer
{                                                                             \
1666 d9bce9d9 j_mayer
    gen_##name(ctx, 1, 0);                                                    \
1667 d9bce9d9 j_mayer
}                                                                             \
1668 e8eaa2c0 Blue Swirl
                                                                              \
1669 e8eaa2c0 Blue Swirl
static void glue(gen_, name##3)(DisasContext *ctx)                            \
1670 d9bce9d9 j_mayer
{                                                                             \
1671 d9bce9d9 j_mayer
    gen_##name(ctx, 1, 1);                                                    \
1672 d9bce9d9 j_mayer
}
1673 51789c41 j_mayer
1674 636aa200 Blue Swirl
static inline void gen_rldinm(DisasContext *ctx, uint32_t mb, uint32_t me,
1675 636aa200 Blue Swirl
                              uint32_t sh)
1676 51789c41 j_mayer
{
1677 d03ef511 aurel32
    if (likely(sh != 0 && mb == 0 && me == (63 - sh))) {
1678 d03ef511 aurel32
        tcg_gen_shli_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
1679 d03ef511 aurel32
    } else if (likely(sh != 0 && me == 63 && sh == (64 - mb))) {
1680 d03ef511 aurel32
        tcg_gen_shri_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], mb);
1681 d03ef511 aurel32
    } else {
1682 a7812ae4 pbrook
        TCGv t0 = tcg_temp_new();
1683 54843a58 aurel32
        tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
1684 d03ef511 aurel32
        if (likely(mb == 0 && me == 63)) {
1685 54843a58 aurel32
            tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1686 d03ef511 aurel32
        } else {
1687 d03ef511 aurel32
            tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1688 51789c41 j_mayer
        }
1689 d03ef511 aurel32
        tcg_temp_free(t0);
1690 51789c41 j_mayer
    }
1691 51789c41 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
1692 d03ef511 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1693 51789c41 j_mayer
}
1694 d9bce9d9 j_mayer
/* rldicl - rldicl. */
1695 636aa200 Blue Swirl
static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn)
1696 d9bce9d9 j_mayer
{
1697 51789c41 j_mayer
    uint32_t sh, mb;
1698 d9bce9d9 j_mayer
1699 9d53c753 j_mayer
    sh = SH(ctx->opcode) | (shn << 5);
1700 9d53c753 j_mayer
    mb = MB(ctx->opcode) | (mbn << 5);
1701 51789c41 j_mayer
    gen_rldinm(ctx, mb, 63, sh);
1702 d9bce9d9 j_mayer
}
1703 51789c41 j_mayer
GEN_PPC64_R4(rldicl, 0x1E, 0x00);
1704 d9bce9d9 j_mayer
/* rldicr - rldicr. */
1705 636aa200 Blue Swirl
static inline void gen_rldicr(DisasContext *ctx, int men, int shn)
1706 d9bce9d9 j_mayer
{
1707 51789c41 j_mayer
    uint32_t sh, me;
1708 d9bce9d9 j_mayer
1709 9d53c753 j_mayer
    sh = SH(ctx->opcode) | (shn << 5);
1710 9d53c753 j_mayer
    me = MB(ctx->opcode) | (men << 5);
1711 51789c41 j_mayer
    gen_rldinm(ctx, 0, me, sh);
1712 d9bce9d9 j_mayer
}
1713 51789c41 j_mayer
GEN_PPC64_R4(rldicr, 0x1E, 0x02);
1714 d9bce9d9 j_mayer
/* rldic - rldic. */
1715 636aa200 Blue Swirl
static inline void gen_rldic(DisasContext *ctx, int mbn, int shn)
1716 d9bce9d9 j_mayer
{
1717 51789c41 j_mayer
    uint32_t sh, mb;
1718 d9bce9d9 j_mayer
1719 9d53c753 j_mayer
    sh = SH(ctx->opcode) | (shn << 5);
1720 9d53c753 j_mayer
    mb = MB(ctx->opcode) | (mbn << 5);
1721 51789c41 j_mayer
    gen_rldinm(ctx, mb, 63 - sh, sh);
1722 51789c41 j_mayer
}
1723 51789c41 j_mayer
GEN_PPC64_R4(rldic, 0x1E, 0x04);
1724 51789c41 j_mayer
1725 636aa200 Blue Swirl
static inline void gen_rldnm(DisasContext *ctx, uint32_t mb, uint32_t me)
1726 51789c41 j_mayer
{
1727 54843a58 aurel32
    TCGv t0;
1728 d03ef511 aurel32
1729 d03ef511 aurel32
    mb = MB(ctx->opcode);
1730 d03ef511 aurel32
    me = ME(ctx->opcode);
1731 a7812ae4 pbrook
    t0 = tcg_temp_new();
1732 d03ef511 aurel32
    tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f);
1733 54843a58 aurel32
    tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1734 51789c41 j_mayer
    if (unlikely(mb != 0 || me != 63)) {
1735 54843a58 aurel32
        tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1736 54843a58 aurel32
    } else {
1737 54843a58 aurel32
        tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1738 54843a58 aurel32
    }
1739 54843a58 aurel32
    tcg_temp_free(t0);
1740 51789c41 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
1741 d03ef511 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1742 d9bce9d9 j_mayer
}
1743 51789c41 j_mayer
1744 d9bce9d9 j_mayer
/* rldcl - rldcl. */
1745 636aa200 Blue Swirl
static inline void gen_rldcl(DisasContext *ctx, int mbn)
1746 d9bce9d9 j_mayer
{
1747 51789c41 j_mayer
    uint32_t mb;
1748 d9bce9d9 j_mayer
1749 9d53c753 j_mayer
    mb = MB(ctx->opcode) | (mbn << 5);
1750 51789c41 j_mayer
    gen_rldnm(ctx, mb, 63);
1751 d9bce9d9 j_mayer
}
1752 36081602 j_mayer
GEN_PPC64_R2(rldcl, 0x1E, 0x08);
1753 d9bce9d9 j_mayer
/* rldcr - rldcr. */
1754 636aa200 Blue Swirl
static inline void gen_rldcr(DisasContext *ctx, int men)
1755 d9bce9d9 j_mayer
{
1756 51789c41 j_mayer
    uint32_t me;
1757 d9bce9d9 j_mayer
1758 9d53c753 j_mayer
    me = MB(ctx->opcode) | (men << 5);
1759 51789c41 j_mayer
    gen_rldnm(ctx, 0, me);
1760 d9bce9d9 j_mayer
}
1761 36081602 j_mayer
GEN_PPC64_R2(rldcr, 0x1E, 0x09);
1762 d9bce9d9 j_mayer
/* rldimi - rldimi. */
1763 636aa200 Blue Swirl
static inline void gen_rldimi(DisasContext *ctx, int mbn, int shn)
1764 d9bce9d9 j_mayer
{
1765 271a916e j_mayer
    uint32_t sh, mb, me;
1766 d9bce9d9 j_mayer
1767 9d53c753 j_mayer
    sh = SH(ctx->opcode) | (shn << 5);
1768 9d53c753 j_mayer
    mb = MB(ctx->opcode) | (mbn << 5);
1769 271a916e j_mayer
    me = 63 - sh;
1770 d03ef511 aurel32
    if (unlikely(sh == 0 && mb == 0)) {
1771 d03ef511 aurel32
        tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1772 d03ef511 aurel32
    } else {
1773 d03ef511 aurel32
        TCGv t0, t1;
1774 d03ef511 aurel32
        target_ulong mask;
1775 d03ef511 aurel32
1776 a7812ae4 pbrook
        t0 = tcg_temp_new();
1777 54843a58 aurel32
        tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
1778 a7812ae4 pbrook
        t1 = tcg_temp_new();
1779 d03ef511 aurel32
        mask = MASK(mb, me);
1780 d03ef511 aurel32
        tcg_gen_andi_tl(t0, t0, mask);
1781 d03ef511 aurel32
        tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1782 d03ef511 aurel32
        tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1783 d03ef511 aurel32
        tcg_temp_free(t0);
1784 d03ef511 aurel32
        tcg_temp_free(t1);
1785 51789c41 j_mayer
    }
1786 51789c41 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
1787 d03ef511 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1788 d9bce9d9 j_mayer
}
1789 36081602 j_mayer
GEN_PPC64_R4(rldimi, 0x1E, 0x06);
1790 d9bce9d9 j_mayer
#endif
1791 d9bce9d9 j_mayer
1792 79aceca5 bellard
/***                             Integer shift                             ***/
1793 99e300ef Blue Swirl
1794 54623277 Blue Swirl
/* slw & slw. */
1795 99e300ef Blue Swirl
static void gen_slw(DisasContext *ctx)
1796 26d67362 aurel32
{
1797 7fd6bf7d Aurelien Jarno
    TCGv t0, t1;
1798 26d67362 aurel32
1799 7fd6bf7d Aurelien Jarno
    t0 = tcg_temp_new();
1800 7fd6bf7d Aurelien Jarno
    /* AND rS with a mask that is 0 when rB >= 0x20 */
1801 7fd6bf7d Aurelien Jarno
#if defined(TARGET_PPC64)
1802 7fd6bf7d Aurelien Jarno
    tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1803 7fd6bf7d Aurelien Jarno
    tcg_gen_sari_tl(t0, t0, 0x3f);
1804 7fd6bf7d Aurelien Jarno
#else
1805 7fd6bf7d Aurelien Jarno
    tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1806 7fd6bf7d Aurelien Jarno
    tcg_gen_sari_tl(t0, t0, 0x1f);
1807 7fd6bf7d Aurelien Jarno
#endif
1808 7fd6bf7d Aurelien Jarno
    tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1809 7fd6bf7d Aurelien Jarno
    t1 = tcg_temp_new();
1810 7fd6bf7d Aurelien Jarno
    tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1811 7fd6bf7d Aurelien Jarno
    tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1812 7fd6bf7d Aurelien Jarno
    tcg_temp_free(t1);
1813 fea0c503 aurel32
    tcg_temp_free(t0);
1814 7fd6bf7d Aurelien Jarno
    tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
1815 26d67362 aurel32
    if (unlikely(Rc(ctx->opcode) != 0))
1816 26d67362 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1817 26d67362 aurel32
}
1818 99e300ef Blue Swirl
1819 54623277 Blue Swirl
/* sraw & sraw. */
1820 99e300ef Blue Swirl
static void gen_sraw(DisasContext *ctx)
1821 26d67362 aurel32
{
1822 a7812ae4 pbrook
    gen_helper_sraw(cpu_gpr[rA(ctx->opcode)],
1823 a7812ae4 pbrook
                    cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1824 26d67362 aurel32
    if (unlikely(Rc(ctx->opcode) != 0))
1825 26d67362 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1826 26d67362 aurel32
}
1827 99e300ef Blue Swirl
1828 54623277 Blue Swirl
/* srawi & srawi. */
1829 99e300ef Blue Swirl
static void gen_srawi(DisasContext *ctx)
1830 79aceca5 bellard
{
1831 26d67362 aurel32
    int sh = SH(ctx->opcode);
1832 26d67362 aurel32
    if (sh != 0) {
1833 26d67362 aurel32
        int l1, l2;
1834 fea0c503 aurel32
        TCGv t0;
1835 26d67362 aurel32
        l1 = gen_new_label();
1836 26d67362 aurel32
        l2 = gen_new_label();
1837 a7812ae4 pbrook
        t0 = tcg_temp_local_new();
1838 fea0c503 aurel32
        tcg_gen_ext32s_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1839 fea0c503 aurel32
        tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1);
1840 fea0c503 aurel32
        tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1ULL << sh) - 1);
1841 fea0c503 aurel32
        tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1842 269f3e95 aurel32
        tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA);
1843 26d67362 aurel32
        tcg_gen_br(l2);
1844 26d67362 aurel32
        gen_set_label(l1);
1845 269f3e95 aurel32
        tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
1846 26d67362 aurel32
        gen_set_label(l2);
1847 fea0c503 aurel32
        tcg_gen_ext32s_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1848 fea0c503 aurel32
        tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], t0, sh);
1849 fea0c503 aurel32
        tcg_temp_free(t0);
1850 26d67362 aurel32
    } else {
1851 26d67362 aurel32
        tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1852 269f3e95 aurel32
        tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
1853 d9bce9d9 j_mayer
    }
1854 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
1855 26d67362 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1856 79aceca5 bellard
}
1857 99e300ef Blue Swirl
1858 54623277 Blue Swirl
/* srw & srw. */
1859 99e300ef Blue Swirl
static void gen_srw(DisasContext *ctx)
1860 26d67362 aurel32
{
1861 fea0c503 aurel32
    TCGv t0, t1;
1862 d9bce9d9 j_mayer
1863 7fd6bf7d Aurelien Jarno
    t0 = tcg_temp_new();
1864 7fd6bf7d Aurelien Jarno
    /* AND rS with a mask that is 0 when rB >= 0x20 */
1865 7fd6bf7d Aurelien Jarno
#if defined(TARGET_PPC64)
1866 7fd6bf7d Aurelien Jarno
    tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a);
1867 7fd6bf7d Aurelien Jarno
    tcg_gen_sari_tl(t0, t0, 0x3f);
1868 7fd6bf7d Aurelien Jarno
#else
1869 7fd6bf7d Aurelien Jarno
    tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a);
1870 7fd6bf7d Aurelien Jarno
    tcg_gen_sari_tl(t0, t0, 0x1f);
1871 7fd6bf7d Aurelien Jarno
#endif
1872 7fd6bf7d Aurelien Jarno
    tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1873 7fd6bf7d Aurelien Jarno
    tcg_gen_ext32u_tl(t0, t0);
1874 a7812ae4 pbrook
    t1 = tcg_temp_new();
1875 7fd6bf7d Aurelien Jarno
    tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f);
1876 7fd6bf7d Aurelien Jarno
    tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1877 fea0c503 aurel32
    tcg_temp_free(t1);
1878 fea0c503 aurel32
    tcg_temp_free(t0);
1879 26d67362 aurel32
    if (unlikely(Rc(ctx->opcode) != 0))
1880 26d67362 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1881 26d67362 aurel32
}
1882 54623277 Blue Swirl
1883 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
1884 d9bce9d9 j_mayer
/* sld & sld. */
1885 99e300ef Blue Swirl
static void gen_sld(DisasContext *ctx)
1886 26d67362 aurel32
{
1887 7fd6bf7d Aurelien Jarno
    TCGv t0, t1;
1888 26d67362 aurel32
1889 7fd6bf7d Aurelien Jarno
    t0 = tcg_temp_new();
1890 7fd6bf7d Aurelien Jarno
    /* AND rS with a mask that is 0 when rB >= 0x40 */
1891 7fd6bf7d Aurelien Jarno
    tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
1892 7fd6bf7d Aurelien Jarno
    tcg_gen_sari_tl(t0, t0, 0x3f);
1893 7fd6bf7d Aurelien Jarno
    tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1894 7fd6bf7d Aurelien Jarno
    t1 = tcg_temp_new();
1895 7fd6bf7d Aurelien Jarno
    tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
1896 7fd6bf7d Aurelien Jarno
    tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1897 7fd6bf7d Aurelien Jarno
    tcg_temp_free(t1);
1898 fea0c503 aurel32
    tcg_temp_free(t0);
1899 26d67362 aurel32
    if (unlikely(Rc(ctx->opcode) != 0))
1900 26d67362 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1901 26d67362 aurel32
}
1902 99e300ef Blue Swirl
1903 54623277 Blue Swirl
/* srad & srad. */
1904 99e300ef Blue Swirl
static void gen_srad(DisasContext *ctx)
1905 26d67362 aurel32
{
1906 a7812ae4 pbrook
    gen_helper_srad(cpu_gpr[rA(ctx->opcode)],
1907 a7812ae4 pbrook
                    cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1908 26d67362 aurel32
    if (unlikely(Rc(ctx->opcode) != 0))
1909 26d67362 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1910 26d67362 aurel32
}
1911 d9bce9d9 j_mayer
/* sradi & sradi. */
1912 636aa200 Blue Swirl
static inline void gen_sradi(DisasContext *ctx, int n)
1913 d9bce9d9 j_mayer
{
1914 26d67362 aurel32
    int sh = SH(ctx->opcode) + (n << 5);
1915 d9bce9d9 j_mayer
    if (sh != 0) {
1916 26d67362 aurel32
        int l1, l2;
1917 fea0c503 aurel32
        TCGv t0;
1918 26d67362 aurel32
        l1 = gen_new_label();
1919 26d67362 aurel32
        l2 = gen_new_label();
1920 a7812ae4 pbrook
        t0 = tcg_temp_local_new();
1921 26d67362 aurel32
        tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
1922 fea0c503 aurel32
        tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1ULL << sh) - 1);
1923 fea0c503 aurel32
        tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1924 269f3e95 aurel32
        tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA);
1925 26d67362 aurel32
        tcg_gen_br(l2);
1926 26d67362 aurel32
        gen_set_label(l1);
1927 269f3e95 aurel32
        tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
1928 26d67362 aurel32
        gen_set_label(l2);
1929 a9730017 aurel32
        tcg_temp_free(t0);
1930 26d67362 aurel32
        tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
1931 26d67362 aurel32
    } else {
1932 26d67362 aurel32
        tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1933 269f3e95 aurel32
        tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
1934 d9bce9d9 j_mayer
    }
1935 d9bce9d9 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
1936 26d67362 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1937 d9bce9d9 j_mayer
}
1938 e8eaa2c0 Blue Swirl
1939 e8eaa2c0 Blue Swirl
static void gen_sradi0(DisasContext *ctx)
1940 d9bce9d9 j_mayer
{
1941 d9bce9d9 j_mayer
    gen_sradi(ctx, 0);
1942 d9bce9d9 j_mayer
}
1943 e8eaa2c0 Blue Swirl
1944 e8eaa2c0 Blue Swirl
static void gen_sradi1(DisasContext *ctx)
1945 d9bce9d9 j_mayer
{
1946 d9bce9d9 j_mayer
    gen_sradi(ctx, 1);
1947 d9bce9d9 j_mayer
}
1948 99e300ef Blue Swirl
1949 54623277 Blue Swirl
/* srd & srd. */
1950 99e300ef Blue Swirl
static void gen_srd(DisasContext *ctx)
1951 26d67362 aurel32
{
1952 7fd6bf7d Aurelien Jarno
    TCGv t0, t1;
1953 26d67362 aurel32
1954 7fd6bf7d Aurelien Jarno
    t0 = tcg_temp_new();
1955 7fd6bf7d Aurelien Jarno
    /* AND rS with a mask that is 0 when rB >= 0x40 */
1956 7fd6bf7d Aurelien Jarno
    tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39);
1957 7fd6bf7d Aurelien Jarno
    tcg_gen_sari_tl(t0, t0, 0x3f);
1958 7fd6bf7d Aurelien Jarno
    tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1959 7fd6bf7d Aurelien Jarno
    t1 = tcg_temp_new();
1960 7fd6bf7d Aurelien Jarno
    tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f);
1961 7fd6bf7d Aurelien Jarno
    tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1962 7fd6bf7d Aurelien Jarno
    tcg_temp_free(t1);
1963 fea0c503 aurel32
    tcg_temp_free(t0);
1964 26d67362 aurel32
    if (unlikely(Rc(ctx->opcode) != 0))
1965 26d67362 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1966 26d67362 aurel32
}
1967 d9bce9d9 j_mayer
#endif
1968 79aceca5 bellard
1969 79aceca5 bellard
/***                       Floating-Point arithmetic                       ***/
1970 7c58044c j_mayer
#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type)           \
1971 99e300ef Blue Swirl
static void gen_f##name(DisasContext *ctx)                                    \
1972 9a64fbe4 bellard
{                                                                             \
1973 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {                                        \
1974 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
1975 3cc62370 bellard
        return;                                                               \
1976 3cc62370 bellard
    }                                                                         \
1977 eb44b959 aurel32
    /* NIP cannot be restored if the memory exception comes from an helper */ \
1978 eb44b959 aurel32
    gen_update_nip(ctx, ctx->nip - 4);                                        \
1979 7c58044c j_mayer
    gen_reset_fpstatus();                                                     \
1980 af12906f aurel32
    gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],      \
1981 af12906f aurel32
                     cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);     \
1982 4ecc3190 bellard
    if (isfloat) {                                                            \
1983 af12906f aurel32
        gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]);  \
1984 4ecc3190 bellard
    }                                                                         \
1985 af12906f aurel32
    gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf,                      \
1986 af12906f aurel32
                     Rc(ctx->opcode) != 0);                                   \
1987 9a64fbe4 bellard
}
1988 9a64fbe4 bellard
1989 7c58044c j_mayer
#define GEN_FLOAT_ACB(name, op2, set_fprf, type)                              \
1990 7c58044c j_mayer
_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type);                     \
1991 7c58044c j_mayer
_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
1992 9a64fbe4 bellard
1993 7c58044c j_mayer
#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type)     \
1994 99e300ef Blue Swirl
static void gen_f##name(DisasContext *ctx)                                    \
1995 9a64fbe4 bellard
{                                                                             \
1996 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {                                        \
1997 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
1998 3cc62370 bellard
        return;                                                               \
1999 3cc62370 bellard
    }                                                                         \
2000 eb44b959 aurel32
    /* NIP cannot be restored if the memory exception comes from an helper */ \
2001 eb44b959 aurel32
    gen_update_nip(ctx, ctx->nip - 4);                                        \
2002 7c58044c j_mayer
    gen_reset_fpstatus();                                                     \
2003 af12906f aurel32
    gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],      \
2004 af12906f aurel32
                     cpu_fpr[rB(ctx->opcode)]);                               \
2005 4ecc3190 bellard
    if (isfloat) {                                                            \
2006 af12906f aurel32
        gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]);  \
2007 4ecc3190 bellard
    }                                                                         \
2008 af12906f aurel32
    gen_compute_fprf(cpu_fpr[rD(ctx->opcode)],                                \
2009 af12906f aurel32
                     set_fprf, Rc(ctx->opcode) != 0);                         \
2010 9a64fbe4 bellard
}
2011 7c58044c j_mayer
#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type)                        \
2012 7c58044c j_mayer
_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type);               \
2013 7c58044c j_mayer
_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2014 9a64fbe4 bellard
2015 7c58044c j_mayer
#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type)     \
2016 99e300ef Blue Swirl
static void gen_f##name(DisasContext *ctx)                                    \
2017 9a64fbe4 bellard
{                                                                             \
2018 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {                                        \
2019 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
2020 3cc62370 bellard
        return;                                                               \
2021 3cc62370 bellard
    }                                                                         \
2022 eb44b959 aurel32
    /* NIP cannot be restored if the memory exception comes from an helper */ \
2023 eb44b959 aurel32
    gen_update_nip(ctx, ctx->nip - 4);                                        \
2024 7c58044c j_mayer
    gen_reset_fpstatus();                                                     \
2025 af12906f aurel32
    gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)],      \
2026 af12906f aurel32
                       cpu_fpr[rC(ctx->opcode)]);                             \
2027 4ecc3190 bellard
    if (isfloat) {                                                            \
2028 af12906f aurel32
        gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]);  \
2029 4ecc3190 bellard
    }                                                                         \
2030 af12906f aurel32
    gen_compute_fprf(cpu_fpr[rD(ctx->opcode)],                                \
2031 af12906f aurel32
                     set_fprf, Rc(ctx->opcode) != 0);                         \
2032 9a64fbe4 bellard
}
2033 7c58044c j_mayer
#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type)                        \
2034 7c58044c j_mayer
_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type);               \
2035 7c58044c j_mayer
_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2036 9a64fbe4 bellard
2037 7c58044c j_mayer
#define GEN_FLOAT_B(name, op2, op3, set_fprf, type)                           \
2038 99e300ef Blue Swirl
static void gen_f##name(DisasContext *ctx)                                    \
2039 9a64fbe4 bellard
{                                                                             \
2040 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {                                        \
2041 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
2042 3cc62370 bellard
        return;                                                               \
2043 3cc62370 bellard
    }                                                                         \
2044 eb44b959 aurel32
    /* NIP cannot be restored if the memory exception comes from an helper */ \
2045 eb44b959 aurel32
    gen_update_nip(ctx, ctx->nip - 4);                                        \
2046 7c58044c j_mayer
    gen_reset_fpstatus();                                                     \
2047 af12906f aurel32
    gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);   \
2048 af12906f aurel32
    gen_compute_fprf(cpu_fpr[rD(ctx->opcode)],                                \
2049 af12906f aurel32
                     set_fprf, Rc(ctx->opcode) != 0);                         \
2050 79aceca5 bellard
}
2051 79aceca5 bellard
2052 7c58044c j_mayer
#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type)                          \
2053 99e300ef Blue Swirl
static void gen_f##name(DisasContext *ctx)                                    \
2054 9a64fbe4 bellard
{                                                                             \
2055 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {                                        \
2056 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
2057 3cc62370 bellard
        return;                                                               \
2058 3cc62370 bellard
    }                                                                         \
2059 eb44b959 aurel32
    /* NIP cannot be restored if the memory exception comes from an helper */ \
2060 eb44b959 aurel32
    gen_update_nip(ctx, ctx->nip - 4);                                        \
2061 7c58044c j_mayer
    gen_reset_fpstatus();                                                     \
2062 af12906f aurel32
    gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);   \
2063 af12906f aurel32
    gen_compute_fprf(cpu_fpr[rD(ctx->opcode)],                                \
2064 af12906f aurel32
                     set_fprf, Rc(ctx->opcode) != 0);                         \
2065 79aceca5 bellard
}
2066 79aceca5 bellard
2067 9a64fbe4 bellard
/* fadd - fadds */
2068 7c58044c j_mayer
GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT);
2069 4ecc3190 bellard
/* fdiv - fdivs */
2070 7c58044c j_mayer
GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT);
2071 4ecc3190 bellard
/* fmul - fmuls */
2072 7c58044c j_mayer
GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT);
2073 79aceca5 bellard
2074 d7e4b87e j_mayer
/* fre */
2075 7c58044c j_mayer
GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT);
2076 d7e4b87e j_mayer
2077 a750fc0b j_mayer
/* fres */
2078 7c58044c j_mayer
GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES);
2079 79aceca5 bellard
2080 a750fc0b j_mayer
/* frsqrte */
2081 7c58044c j_mayer
GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
2082 7c58044c j_mayer
2083 7c58044c j_mayer
/* frsqrtes */
2084 99e300ef Blue Swirl
static void gen_frsqrtes(DisasContext *ctx)
2085 7c58044c j_mayer
{
2086 af12906f aurel32
    if (unlikely(!ctx->fpu_enabled)) {
2087 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);
2088 af12906f aurel32
        return;
2089 af12906f aurel32
    }
2090 eb44b959 aurel32
    /* NIP cannot be restored if the memory exception comes from an helper */
2091 eb44b959 aurel32
    gen_update_nip(ctx, ctx->nip - 4);
2092 af12906f aurel32
    gen_reset_fpstatus();
2093 af12906f aurel32
    gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2094 af12906f aurel32
    gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]);
2095 af12906f aurel32
    gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
2096 7c58044c j_mayer
}
2097 79aceca5 bellard
2098 a750fc0b j_mayer
/* fsel */
2099 7c58044c j_mayer
_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL);
2100 4ecc3190 bellard
/* fsub - fsubs */
2101 7c58044c j_mayer
GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
2102 79aceca5 bellard
/* Optional: */
2103 99e300ef Blue Swirl
2104 54623277 Blue Swirl
/* fsqrt */
2105 99e300ef Blue Swirl
static void gen_fsqrt(DisasContext *ctx)
2106 c7d344af bellard
{
2107 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {
2108 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);
2109 c7d344af bellard
        return;
2110 c7d344af bellard
    }
2111 eb44b959 aurel32
    /* NIP cannot be restored if the memory exception comes from an helper */
2112 eb44b959 aurel32
    gen_update_nip(ctx, ctx->nip - 4);
2113 7c58044c j_mayer
    gen_reset_fpstatus();
2114 af12906f aurel32
    gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2115 af12906f aurel32
    gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
2116 c7d344af bellard
}
2117 79aceca5 bellard
2118 99e300ef Blue Swirl
static void gen_fsqrts(DisasContext *ctx)
2119 79aceca5 bellard
{
2120 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {
2121 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);
2122 3cc62370 bellard
        return;
2123 3cc62370 bellard
    }
2124 eb44b959 aurel32
    /* NIP cannot be restored if the memory exception comes from an helper */
2125 eb44b959 aurel32
    gen_update_nip(ctx, ctx->nip - 4);
2126 7c58044c j_mayer
    gen_reset_fpstatus();
2127 af12906f aurel32
    gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2128 af12906f aurel32
    gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]);
2129 af12906f aurel32
    gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0);
2130 79aceca5 bellard
}
2131 79aceca5 bellard
2132 79aceca5 bellard
/***                     Floating-Point multiply-and-add                   ***/
2133 4ecc3190 bellard
/* fmadd - fmadds */
2134 7c58044c j_mayer
GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT);
2135 4ecc3190 bellard
/* fmsub - fmsubs */
2136 7c58044c j_mayer
GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT);
2137 4ecc3190 bellard
/* fnmadd - fnmadds */
2138 7c58044c j_mayer
GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT);
2139 4ecc3190 bellard
/* fnmsub - fnmsubs */
2140 7c58044c j_mayer
GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT);
2141 79aceca5 bellard
2142 79aceca5 bellard
/***                     Floating-Point round & convert                    ***/
2143 79aceca5 bellard
/* fctiw */
2144 7c58044c j_mayer
GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT);
2145 79aceca5 bellard
/* fctiwz */
2146 7c58044c j_mayer
GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT);
2147 79aceca5 bellard
/* frsp */
2148 7c58044c j_mayer
GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT);
2149 426613db j_mayer
#if defined(TARGET_PPC64)
2150 426613db j_mayer
/* fcfid */
2151 7c58044c j_mayer
GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B);
2152 426613db j_mayer
/* fctid */
2153 7c58044c j_mayer
GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B);
2154 426613db j_mayer
/* fctidz */
2155 7c58044c j_mayer
GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B);
2156 426613db j_mayer
#endif
2157 79aceca5 bellard
2158 d7e4b87e j_mayer
/* frin */
2159 7c58044c j_mayer
GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT);
2160 d7e4b87e j_mayer
/* friz */
2161 7c58044c j_mayer
GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT);
2162 d7e4b87e j_mayer
/* frip */
2163 7c58044c j_mayer
GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT);
2164 d7e4b87e j_mayer
/* frim */
2165 7c58044c j_mayer
GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT);
2166 d7e4b87e j_mayer
2167 79aceca5 bellard
/***                         Floating-Point compare                        ***/
2168 99e300ef Blue Swirl
2169 54623277 Blue Swirl
/* fcmpo */
2170 99e300ef Blue Swirl
static void gen_fcmpo(DisasContext *ctx)
2171 79aceca5 bellard
{
2172 330c483b aurel32
    TCGv_i32 crf;
2173 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {
2174 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);
2175 3cc62370 bellard
        return;
2176 3cc62370 bellard
    }
2177 eb44b959 aurel32
    /* NIP cannot be restored if the memory exception comes from an helper */
2178 eb44b959 aurel32
    gen_update_nip(ctx, ctx->nip - 4);
2179 7c58044c j_mayer
    gen_reset_fpstatus();
2180 9a819377 aurel32
    crf = tcg_const_i32(crfD(ctx->opcode));
2181 9a819377 aurel32
    gen_helper_fcmpo(cpu_fpr[rA(ctx->opcode)], cpu_fpr[rB(ctx->opcode)], crf);
2182 330c483b aurel32
    tcg_temp_free_i32(crf);
2183 af12906f aurel32
    gen_helper_float_check_status();
2184 79aceca5 bellard
}
2185 79aceca5 bellard
2186 79aceca5 bellard
/* fcmpu */
2187 99e300ef Blue Swirl
static void gen_fcmpu(DisasContext *ctx)
2188 79aceca5 bellard
{
2189 330c483b aurel32
    TCGv_i32 crf;
2190 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {
2191 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);
2192 3cc62370 bellard
        return;
2193 3cc62370 bellard
    }
2194 eb44b959 aurel32
    /* NIP cannot be restored if the memory exception comes from an helper */
2195 eb44b959 aurel32
    gen_update_nip(ctx, ctx->nip - 4);
2196 7c58044c j_mayer
    gen_reset_fpstatus();
2197 9a819377 aurel32
    crf = tcg_const_i32(crfD(ctx->opcode));
2198 9a819377 aurel32
    gen_helper_fcmpu(cpu_fpr[rA(ctx->opcode)], cpu_fpr[rB(ctx->opcode)], crf);
2199 330c483b aurel32
    tcg_temp_free_i32(crf);
2200 af12906f aurel32
    gen_helper_float_check_status();
2201 79aceca5 bellard
}
2202 79aceca5 bellard
2203 9a64fbe4 bellard
/***                         Floating-point move                           ***/
2204 9a64fbe4 bellard
/* fabs */
2205 7c58044c j_mayer
/* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2206 7c58044c j_mayer
GEN_FLOAT_B(abs, 0x08, 0x08, 0, PPC_FLOAT);
2207 9a64fbe4 bellard
2208 9a64fbe4 bellard
/* fmr  - fmr. */
2209 7c58044c j_mayer
/* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2210 99e300ef Blue Swirl
static void gen_fmr(DisasContext *ctx)
2211 9a64fbe4 bellard
{
2212 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {
2213 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);
2214 3cc62370 bellard
        return;
2215 3cc62370 bellard
    }
2216 af12906f aurel32
    tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]);
2217 af12906f aurel32
    gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2218 9a64fbe4 bellard
}
2219 9a64fbe4 bellard
2220 9a64fbe4 bellard
/* fnabs */
2221 7c58044c j_mayer
/* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2222 7c58044c j_mayer
GEN_FLOAT_B(nabs, 0x08, 0x04, 0, PPC_FLOAT);
2223 9a64fbe4 bellard
/* fneg */
2224 7c58044c j_mayer
/* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2225 7c58044c j_mayer
GEN_FLOAT_B(neg, 0x08, 0x01, 0, PPC_FLOAT);
2226 9a64fbe4 bellard
2227 79aceca5 bellard
/***                  Floating-Point status & ctrl register                ***/
2228 99e300ef Blue Swirl
2229 54623277 Blue Swirl
/* mcrfs */
2230 99e300ef Blue Swirl
static void gen_mcrfs(DisasContext *ctx)
2231 79aceca5 bellard
{
2232 7c58044c j_mayer
    int bfa;
2233 7c58044c j_mayer
2234 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {
2235 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);
2236 3cc62370 bellard
        return;
2237 3cc62370 bellard
    }
2238 7c58044c j_mayer
    bfa = 4 * (7 - crfS(ctx->opcode));
2239 e1571908 aurel32
    tcg_gen_shri_i32(cpu_crf[crfD(ctx->opcode)], cpu_fpscr, bfa);
2240 e1571908 aurel32
    tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf);
2241 af12906f aurel32
    tcg_gen_andi_i32(cpu_fpscr, cpu_fpscr, ~(0xF << bfa));
2242 79aceca5 bellard
}
2243 79aceca5 bellard
2244 79aceca5 bellard
/* mffs */
2245 99e300ef Blue Swirl
static void gen_mffs(DisasContext *ctx)
2246 79aceca5 bellard
{
2247 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {
2248 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);
2249 3cc62370 bellard
        return;
2250 3cc62370 bellard
    }
2251 7c58044c j_mayer
    gen_reset_fpstatus();
2252 af12906f aurel32
    tcg_gen_extu_i32_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr);
2253 af12906f aurel32
    gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0);
2254 79aceca5 bellard
}
2255 79aceca5 bellard
2256 79aceca5 bellard
/* mtfsb0 */
2257 99e300ef Blue Swirl
static void gen_mtfsb0(DisasContext *ctx)
2258 79aceca5 bellard
{
2259 fb0eaffc bellard
    uint8_t crb;
2260 3b46e624 ths
2261 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {
2262 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);
2263 3cc62370 bellard
        return;
2264 3cc62370 bellard
    }
2265 6e35d524 aurel32
    crb = 31 - crbD(ctx->opcode);
2266 7c58044c j_mayer
    gen_reset_fpstatus();
2267 6e35d524 aurel32
    if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) {
2268 eb44b959 aurel32
        TCGv_i32 t0;
2269 eb44b959 aurel32
        /* NIP cannot be restored if the memory exception comes from an helper */
2270 eb44b959 aurel32
        gen_update_nip(ctx, ctx->nip - 4);
2271 eb44b959 aurel32
        t0 = tcg_const_i32(crb);
2272 6e35d524 aurel32
        gen_helper_fpscr_clrbit(t0);
2273 6e35d524 aurel32
        tcg_temp_free_i32(t0);
2274 6e35d524 aurel32
    }
2275 7c58044c j_mayer
    if (unlikely(Rc(ctx->opcode) != 0)) {
2276 e1571908 aurel32
        tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
2277 7c58044c j_mayer
    }
2278 79aceca5 bellard
}
2279 79aceca5 bellard
2280 79aceca5 bellard
/* mtfsb1 */
2281 99e300ef Blue Swirl
static void gen_mtfsb1(DisasContext *ctx)
2282 79aceca5 bellard
{
2283 fb0eaffc bellard
    uint8_t crb;
2284 3b46e624 ths
2285 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {
2286 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);
2287 3cc62370 bellard
        return;
2288 3cc62370 bellard
    }
2289 6e35d524 aurel32
    crb = 31 - crbD(ctx->opcode);
2290 7c58044c j_mayer
    gen_reset_fpstatus();
2291 7c58044c j_mayer
    /* XXX: we pretend we can only do IEEE floating-point computations */
2292 af12906f aurel32
    if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) {
2293 eb44b959 aurel32
        TCGv_i32 t0;
2294 eb44b959 aurel32
        /* NIP cannot be restored if the memory exception comes from an helper */
2295 eb44b959 aurel32
        gen_update_nip(ctx, ctx->nip - 4);
2296 eb44b959 aurel32
        t0 = tcg_const_i32(crb);
2297 af12906f aurel32
        gen_helper_fpscr_setbit(t0);
2298 0f2f39c2 aurel32
        tcg_temp_free_i32(t0);
2299 af12906f aurel32
    }
2300 7c58044c j_mayer
    if (unlikely(Rc(ctx->opcode) != 0)) {
2301 e1571908 aurel32
        tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
2302 7c58044c j_mayer
    }
2303 7c58044c j_mayer
    /* We can raise a differed exception */
2304 af12906f aurel32
    gen_helper_float_check_status();
2305 79aceca5 bellard
}
2306 79aceca5 bellard
2307 79aceca5 bellard
/* mtfsf */
2308 99e300ef Blue Swirl
static void gen_mtfsf(DisasContext *ctx)
2309 79aceca5 bellard
{
2310 0f2f39c2 aurel32
    TCGv_i32 t0;
2311 4911012d blueswir1
    int L = ctx->opcode & 0x02000000;
2312 af12906f aurel32
2313 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {
2314 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);
2315 3cc62370 bellard
        return;
2316 3cc62370 bellard
    }
2317 eb44b959 aurel32
    /* NIP cannot be restored if the memory exception comes from an helper */
2318 eb44b959 aurel32
    gen_update_nip(ctx, ctx->nip - 4);
2319 7c58044c j_mayer
    gen_reset_fpstatus();
2320 4911012d blueswir1
    if (L)
2321 4911012d blueswir1
        t0 = tcg_const_i32(0xff);
2322 4911012d blueswir1
    else
2323 4911012d blueswir1
        t0 = tcg_const_i32(FM(ctx->opcode));
2324 af12906f aurel32
    gen_helper_store_fpscr(cpu_fpr[rB(ctx->opcode)], t0);
2325 0f2f39c2 aurel32
    tcg_temp_free_i32(t0);
2326 7c58044c j_mayer
    if (unlikely(Rc(ctx->opcode) != 0)) {
2327 e1571908 aurel32
        tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
2328 7c58044c j_mayer
    }
2329 7c58044c j_mayer
    /* We can raise a differed exception */
2330 af12906f aurel32
    gen_helper_float_check_status();
2331 79aceca5 bellard
}
2332 79aceca5 bellard
2333 79aceca5 bellard
/* mtfsfi */
2334 99e300ef Blue Swirl
static void gen_mtfsfi(DisasContext *ctx)
2335 79aceca5 bellard
{
2336 7c58044c j_mayer
    int bf, sh;
2337 0f2f39c2 aurel32
    TCGv_i64 t0;
2338 0f2f39c2 aurel32
    TCGv_i32 t1;
2339 7c58044c j_mayer
2340 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {
2341 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);
2342 3cc62370 bellard
        return;
2343 3cc62370 bellard
    }
2344 7c58044c j_mayer
    bf = crbD(ctx->opcode) >> 2;
2345 7c58044c j_mayer
    sh = 7 - bf;
2346 eb44b959 aurel32
    /* NIP cannot be restored if the memory exception comes from an helper */
2347 eb44b959 aurel32
    gen_update_nip(ctx, ctx->nip - 4);
2348 7c58044c j_mayer
    gen_reset_fpstatus();
2349 0f2f39c2 aurel32
    t0 = tcg_const_i64(FPIMM(ctx->opcode) << (4 * sh));
2350 af12906f aurel32
    t1 = tcg_const_i32(1 << sh);
2351 af12906f aurel32
    gen_helper_store_fpscr(t0, t1);
2352 0f2f39c2 aurel32
    tcg_temp_free_i64(t0);
2353 0f2f39c2 aurel32
    tcg_temp_free_i32(t1);
2354 7c58044c j_mayer
    if (unlikely(Rc(ctx->opcode) != 0)) {
2355 e1571908 aurel32
        tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
2356 7c58044c j_mayer
    }
2357 7c58044c j_mayer
    /* We can raise a differed exception */
2358 af12906f aurel32
    gen_helper_float_check_status();
2359 79aceca5 bellard
}
2360 79aceca5 bellard
2361 76a66253 j_mayer
/***                           Addressing modes                            ***/
2362 76a66253 j_mayer
/* Register indirect with immediate index : EA = (rA|0) + SIMM */
2363 636aa200 Blue Swirl
static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA,
2364 636aa200 Blue Swirl
                                      target_long maskl)
2365 76a66253 j_mayer
{
2366 76a66253 j_mayer
    target_long simm = SIMM(ctx->opcode);
2367 76a66253 j_mayer
2368 be147d08 j_mayer
    simm &= ~maskl;
2369 76db3ba4 aurel32
    if (rA(ctx->opcode) == 0) {
2370 76db3ba4 aurel32
#if defined(TARGET_PPC64)
2371 76db3ba4 aurel32
        if (!ctx->sf_mode) {
2372 76db3ba4 aurel32
            tcg_gen_movi_tl(EA, (uint32_t)simm);
2373 76db3ba4 aurel32
        } else
2374 76db3ba4 aurel32
#endif
2375 e2be8d8d aurel32
        tcg_gen_movi_tl(EA, simm);
2376 76db3ba4 aurel32
    } else if (likely(simm != 0)) {
2377 e2be8d8d aurel32
        tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm);
2378 76db3ba4 aurel32
#if defined(TARGET_PPC64)
2379 76db3ba4 aurel32
        if (!ctx->sf_mode) {
2380 76db3ba4 aurel32
            tcg_gen_ext32u_tl(EA, EA);
2381 76db3ba4 aurel32
        }
2382 76db3ba4 aurel32
#endif
2383 76db3ba4 aurel32
    } else {
2384 76db3ba4 aurel32
#if defined(TARGET_PPC64)
2385 76db3ba4 aurel32
        if (!ctx->sf_mode) {
2386 76db3ba4 aurel32
            tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2387 76db3ba4 aurel32
        } else
2388 76db3ba4 aurel32
#endif
2389 e2be8d8d aurel32
        tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2390 76db3ba4 aurel32
    }
2391 76a66253 j_mayer
}
2392 76a66253 j_mayer
2393 636aa200 Blue Swirl
static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA)
2394 76a66253 j_mayer
{
2395 76db3ba4 aurel32
    if (rA(ctx->opcode) == 0) {
2396 76db3ba4 aurel32
#if defined(TARGET_PPC64)
2397 76db3ba4 aurel32
        if (!ctx->sf_mode) {
2398 76db3ba4 aurel32
            tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2399 76db3ba4 aurel32
        } else
2400 76db3ba4 aurel32
#endif
2401 e2be8d8d aurel32
        tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2402 76db3ba4 aurel32
    } else {
2403 e2be8d8d aurel32
        tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
2404 76db3ba4 aurel32
#if defined(TARGET_PPC64)
2405 76db3ba4 aurel32
        if (!ctx->sf_mode) {
2406 76db3ba4 aurel32
            tcg_gen_ext32u_tl(EA, EA);
2407 76db3ba4 aurel32
        }
2408 76db3ba4 aurel32
#endif
2409 76db3ba4 aurel32
    }
2410 76a66253 j_mayer
}
2411 76a66253 j_mayer
2412 636aa200 Blue Swirl
static inline void gen_addr_register(DisasContext *ctx, TCGv EA)
2413 76a66253 j_mayer
{
2414 76db3ba4 aurel32
    if (rA(ctx->opcode) == 0) {
2415 e2be8d8d aurel32
        tcg_gen_movi_tl(EA, 0);
2416 76db3ba4 aurel32
    } else {
2417 76db3ba4 aurel32
#if defined(TARGET_PPC64)
2418 76db3ba4 aurel32
        if (!ctx->sf_mode) {
2419 76db3ba4 aurel32
            tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2420 76db3ba4 aurel32
        } else
2421 76db3ba4 aurel32
#endif
2422 76db3ba4 aurel32
            tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2423 76db3ba4 aurel32
    }
2424 76db3ba4 aurel32
}
2425 76db3ba4 aurel32
2426 636aa200 Blue Swirl
static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1,
2427 636aa200 Blue Swirl
                                target_long val)
2428 76db3ba4 aurel32
{
2429 76db3ba4 aurel32
    tcg_gen_addi_tl(ret, arg1, val);
2430 76db3ba4 aurel32
#if defined(TARGET_PPC64)
2431 76db3ba4 aurel32
    if (!ctx->sf_mode) {
2432 76db3ba4 aurel32
        tcg_gen_ext32u_tl(ret, ret);
2433 76db3ba4 aurel32
    }
2434 76db3ba4 aurel32
#endif
2435 76a66253 j_mayer
}
2436 76a66253 j_mayer
2437 636aa200 Blue Swirl
static inline void gen_check_align(DisasContext *ctx, TCGv EA, int mask)
2438 cf360a32 aurel32
{
2439 cf360a32 aurel32
    int l1 = gen_new_label();
2440 cf360a32 aurel32
    TCGv t0 = tcg_temp_new();
2441 cf360a32 aurel32
    TCGv_i32 t1, t2;
2442 cf360a32 aurel32
    /* NIP cannot be restored if the memory exception comes from an helper */
2443 cf360a32 aurel32
    gen_update_nip(ctx, ctx->nip - 4);
2444 cf360a32 aurel32
    tcg_gen_andi_tl(t0, EA, mask);
2445 cf360a32 aurel32
    tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2446 cf360a32 aurel32
    t1 = tcg_const_i32(POWERPC_EXCP_ALIGN);
2447 cf360a32 aurel32
    t2 = tcg_const_i32(0);
2448 cf360a32 aurel32
    gen_helper_raise_exception_err(t1, t2);
2449 cf360a32 aurel32
    tcg_temp_free_i32(t1);
2450 cf360a32 aurel32
    tcg_temp_free_i32(t2);
2451 cf360a32 aurel32
    gen_set_label(l1);
2452 cf360a32 aurel32
    tcg_temp_free(t0);
2453 cf360a32 aurel32
}
2454 cf360a32 aurel32
2455 7863667f j_mayer
/***                             Integer load                              ***/
2456 636aa200 Blue Swirl
static inline void gen_qemu_ld8u(DisasContext *ctx, TCGv arg1, TCGv arg2)
2457 76db3ba4 aurel32
{
2458 76db3ba4 aurel32
    tcg_gen_qemu_ld8u(arg1, arg2, ctx->mem_idx);
2459 76db3ba4 aurel32
}
2460 76db3ba4 aurel32
2461 636aa200 Blue Swirl
static inline void gen_qemu_ld8s(DisasContext *ctx, TCGv arg1, TCGv arg2)
2462 76db3ba4 aurel32
{
2463 76db3ba4 aurel32
    tcg_gen_qemu_ld8s(arg1, arg2, ctx->mem_idx);
2464 76db3ba4 aurel32
}
2465 76db3ba4 aurel32
2466 636aa200 Blue Swirl
static inline void gen_qemu_ld16u(DisasContext *ctx, TCGv arg1, TCGv arg2)
2467 76db3ba4 aurel32
{
2468 76db3ba4 aurel32
    tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
2469 76db3ba4 aurel32
    if (unlikely(ctx->le_mode)) {
2470 fa3966a3 aurel32
        tcg_gen_bswap16_tl(arg1, arg1);
2471 76db3ba4 aurel32
    }
2472 b61f2753 aurel32
}
2473 b61f2753 aurel32
2474 636aa200 Blue Swirl
static inline void gen_qemu_ld16s(DisasContext *ctx, TCGv arg1, TCGv arg2)
2475 b61f2753 aurel32
{
2476 76db3ba4 aurel32
    if (unlikely(ctx->le_mode)) {
2477 76db3ba4 aurel32
        tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
2478 fa3966a3 aurel32
        tcg_gen_bswap16_tl(arg1, arg1);
2479 76db3ba4 aurel32
        tcg_gen_ext16s_tl(arg1, arg1);
2480 76db3ba4 aurel32
    } else {
2481 76db3ba4 aurel32
        tcg_gen_qemu_ld16s(arg1, arg2, ctx->mem_idx);
2482 76db3ba4 aurel32
    }
2483 b61f2753 aurel32
}
2484 b61f2753 aurel32
2485 636aa200 Blue Swirl
static inline void gen_qemu_ld32u(DisasContext *ctx, TCGv arg1, TCGv arg2)
2486 b61f2753 aurel32
{
2487 76db3ba4 aurel32
    tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
2488 76db3ba4 aurel32
    if (unlikely(ctx->le_mode)) {
2489 fa3966a3 aurel32
        tcg_gen_bswap32_tl(arg1, arg1);
2490 76db3ba4 aurel32
    }
2491 b61f2753 aurel32
}
2492 b61f2753 aurel32
2493 76db3ba4 aurel32
#if defined(TARGET_PPC64)
2494 636aa200 Blue Swirl
static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2)
2495 b61f2753 aurel32
{
2496 a457e7ee blueswir1
    if (unlikely(ctx->le_mode)) {
2497 76db3ba4 aurel32
        tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
2498 fa3966a3 aurel32
        tcg_gen_bswap32_tl(arg1, arg1);
2499 fa3966a3 aurel32
        tcg_gen_ext32s_tl(arg1, arg1);
2500 b61f2753 aurel32
    } else
2501 76db3ba4 aurel32
        tcg_gen_qemu_ld32s(arg1, arg2, ctx->mem_idx);
2502 b61f2753 aurel32
}
2503 76db3ba4 aurel32
#endif
2504 b61f2753 aurel32
2505 636aa200 Blue Swirl
static inline void gen_qemu_ld64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
2506 b61f2753 aurel32
{
2507 76db3ba4 aurel32
    tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx);
2508 76db3ba4 aurel32
    if (unlikely(ctx->le_mode)) {
2509 66896cb8 aurel32
        tcg_gen_bswap64_i64(arg1, arg1);
2510 76db3ba4 aurel32
    }
2511 b61f2753 aurel32
}
2512 b61f2753 aurel32
2513 636aa200 Blue Swirl
static inline void gen_qemu_st8(DisasContext *ctx, TCGv arg1, TCGv arg2)
2514 b61f2753 aurel32
{
2515 76db3ba4 aurel32
    tcg_gen_qemu_st8(arg1, arg2, ctx->mem_idx);
2516 b61f2753 aurel32
}
2517 b61f2753 aurel32
2518 636aa200 Blue Swirl
static inline void gen_qemu_st16(DisasContext *ctx, TCGv arg1, TCGv arg2)
2519 b61f2753 aurel32
{
2520 76db3ba4 aurel32
    if (unlikely(ctx->le_mode)) {
2521 76db3ba4 aurel32
        TCGv t0 = tcg_temp_new();
2522 76db3ba4 aurel32
        tcg_gen_ext16u_tl(t0, arg1);
2523 fa3966a3 aurel32
        tcg_gen_bswap16_tl(t0, t0);
2524 76db3ba4 aurel32
        tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
2525 76db3ba4 aurel32
        tcg_temp_free(t0);
2526 76db3ba4 aurel32
    } else {
2527 76db3ba4 aurel32
        tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
2528 76db3ba4 aurel32
    }
2529 b61f2753 aurel32
}
2530 b61f2753 aurel32
2531 636aa200 Blue Swirl
static inline void gen_qemu_st32(DisasContext *ctx, TCGv arg1, TCGv arg2)
2532 b61f2753 aurel32
{
2533 76db3ba4 aurel32
    if (unlikely(ctx->le_mode)) {
2534 fa3966a3 aurel32
        TCGv t0 = tcg_temp_new();
2535 fa3966a3 aurel32
        tcg_gen_ext32u_tl(t0, arg1);
2536 fa3966a3 aurel32
        tcg_gen_bswap32_tl(t0, t0);
2537 76db3ba4 aurel32
        tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
2538 76db3ba4 aurel32
        tcg_temp_free(t0);
2539 76db3ba4 aurel32
    } else {
2540 76db3ba4 aurel32
        tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
2541 76db3ba4 aurel32
    }
2542 b61f2753 aurel32
}
2543 b61f2753 aurel32
2544 636aa200 Blue Swirl
static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
2545 b61f2753 aurel32
{
2546 76db3ba4 aurel32
    if (unlikely(ctx->le_mode)) {
2547 a7812ae4 pbrook
        TCGv_i64 t0 = tcg_temp_new_i64();
2548 66896cb8 aurel32
        tcg_gen_bswap64_i64(t0, arg1);
2549 76db3ba4 aurel32
        tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx);
2550 a7812ae4 pbrook
        tcg_temp_free_i64(t0);
2551 b61f2753 aurel32
    } else
2552 76db3ba4 aurel32
        tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx);
2553 b61f2753 aurel32
}
2554 b61f2753 aurel32
2555 0c8aacd4 aurel32
#define GEN_LD(name, ldop, opc, type)                                         \
2556 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                                       \
2557 79aceca5 bellard
{                                                                             \
2558 76db3ba4 aurel32
    TCGv EA;                                                                  \
2559 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_INT);                                     \
2560 76db3ba4 aurel32
    EA = tcg_temp_new();                                                      \
2561 76db3ba4 aurel32
    gen_addr_imm_index(ctx, EA, 0);                                           \
2562 76db3ba4 aurel32
    gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA);                       \
2563 b61f2753 aurel32
    tcg_temp_free(EA);                                                        \
2564 79aceca5 bellard
}
2565 79aceca5 bellard
2566 0c8aacd4 aurel32
#define GEN_LDU(name, ldop, opc, type)                                        \
2567 99e300ef Blue Swirl
static void glue(gen_, name##u)(DisasContext *ctx)                                    \
2568 79aceca5 bellard
{                                                                             \
2569 b61f2753 aurel32
    TCGv EA;                                                                  \
2570 76a66253 j_mayer
    if (unlikely(rA(ctx->opcode) == 0 ||                                      \
2571 76a66253 j_mayer
                 rA(ctx->opcode) == rD(ctx->opcode))) {                       \
2572 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);                   \
2573 9fddaa0c bellard
        return;                                                               \
2574 9a64fbe4 bellard
    }                                                                         \
2575 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_INT);                                     \
2576 0c8aacd4 aurel32
    EA = tcg_temp_new();                                                      \
2577 9d53c753 j_mayer
    if (type == PPC_64B)                                                      \
2578 76db3ba4 aurel32
        gen_addr_imm_index(ctx, EA, 0x03);                                    \
2579 9d53c753 j_mayer
    else                                                                      \
2580 76db3ba4 aurel32
        gen_addr_imm_index(ctx, EA, 0);                                       \
2581 76db3ba4 aurel32
    gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA);                       \
2582 b61f2753 aurel32
    tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);                             \
2583 b61f2753 aurel32
    tcg_temp_free(EA);                                                        \
2584 79aceca5 bellard
}
2585 79aceca5 bellard
2586 0c8aacd4 aurel32
#define GEN_LDUX(name, ldop, opc2, opc3, type)                                \
2587 99e300ef Blue Swirl
static void glue(gen_, name##ux)(DisasContext *ctx)                                   \
2588 79aceca5 bellard
{                                                                             \
2589 b61f2753 aurel32
    TCGv EA;                                                                  \
2590 76a66253 j_mayer
    if (unlikely(rA(ctx->opcode) == 0 ||                                      \
2591 76a66253 j_mayer
                 rA(ctx->opcode) == rD(ctx->opcode))) {                       \
2592 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);                   \
2593 9fddaa0c bellard
        return;                                                               \
2594 9a64fbe4 bellard
    }                                                                         \
2595 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_INT);                                     \
2596 0c8aacd4 aurel32
    EA = tcg_temp_new();                                                      \
2597 76db3ba4 aurel32
    gen_addr_reg_index(ctx, EA);                                              \
2598 76db3ba4 aurel32
    gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA);                       \
2599 b61f2753 aurel32
    tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);                             \
2600 b61f2753 aurel32
    tcg_temp_free(EA);                                                        \
2601 79aceca5 bellard
}
2602 79aceca5 bellard
2603 0c8aacd4 aurel32
#define GEN_LDX(name, ldop, opc2, opc3, type)                                 \
2604 99e300ef Blue Swirl
static void glue(gen_, name##x)(DisasContext *ctx)                            \
2605 79aceca5 bellard
{                                                                             \
2606 76db3ba4 aurel32
    TCGv EA;                                                                  \
2607 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_INT);                                     \
2608 76db3ba4 aurel32
    EA = tcg_temp_new();                                                      \
2609 76db3ba4 aurel32
    gen_addr_reg_index(ctx, EA);                                              \
2610 76db3ba4 aurel32
    gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA);                       \
2611 b61f2753 aurel32
    tcg_temp_free(EA);                                                        \
2612 79aceca5 bellard
}
2613 79aceca5 bellard
2614 0c8aacd4 aurel32
#define GEN_LDS(name, ldop, op, type)                                         \
2615 0c8aacd4 aurel32
GEN_LD(name, ldop, op | 0x20, type);                                          \
2616 0c8aacd4 aurel32
GEN_LDU(name, ldop, op | 0x21, type);                                         \
2617 0c8aacd4 aurel32
GEN_LDUX(name, ldop, 0x17, op | 0x01, type);                                  \
2618 0c8aacd4 aurel32
GEN_LDX(name, ldop, 0x17, op | 0x00, type)
2619 79aceca5 bellard
2620 79aceca5 bellard
/* lbz lbzu lbzux lbzx */
2621 0c8aacd4 aurel32
GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER);
2622 79aceca5 bellard
/* lha lhau lhaux lhax */
2623 0c8aacd4 aurel32
GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER);
2624 79aceca5 bellard
/* lhz lhzu lhzux lhzx */
2625 0c8aacd4 aurel32
GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER);
2626 79aceca5 bellard
/* lwz lwzu lwzux lwzx */
2627 0c8aacd4 aurel32
GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER);
2628 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
2629 d9bce9d9 j_mayer
/* lwaux */
2630 0c8aacd4 aurel32
GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B);
2631 d9bce9d9 j_mayer
/* lwax */
2632 0c8aacd4 aurel32
GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B);
2633 d9bce9d9 j_mayer
/* ldux */
2634 0c8aacd4 aurel32
GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B);
2635 d9bce9d9 j_mayer
/* ldx */
2636 0c8aacd4 aurel32
GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B);
2637 99e300ef Blue Swirl
2638 99e300ef Blue Swirl
static void gen_ld(DisasContext *ctx)
2639 d9bce9d9 j_mayer
{
2640 b61f2753 aurel32
    TCGv EA;
2641 d9bce9d9 j_mayer
    if (Rc(ctx->opcode)) {
2642 d9bce9d9 j_mayer
        if (unlikely(rA(ctx->opcode) == 0 ||
2643 d9bce9d9 j_mayer
                     rA(ctx->opcode) == rD(ctx->opcode))) {
2644 e06fcd75 aurel32
            gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2645 d9bce9d9 j_mayer
            return;
2646 d9bce9d9 j_mayer
        }
2647 d9bce9d9 j_mayer
    }
2648 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_INT);
2649 a7812ae4 pbrook
    EA = tcg_temp_new();
2650 76db3ba4 aurel32
    gen_addr_imm_index(ctx, EA, 0x03);
2651 d9bce9d9 j_mayer
    if (ctx->opcode & 0x02) {
2652 d9bce9d9 j_mayer
        /* lwa (lwau is undefined) */
2653 76db3ba4 aurel32
        gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA);
2654 d9bce9d9 j_mayer
    } else {
2655 d9bce9d9 j_mayer
        /* ld - ldu */
2656 76db3ba4 aurel32
        gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], EA);
2657 d9bce9d9 j_mayer
    }
2658 d9bce9d9 j_mayer
    if (Rc(ctx->opcode))
2659 b61f2753 aurel32
        tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2660 b61f2753 aurel32
    tcg_temp_free(EA);
2661 d9bce9d9 j_mayer
}
2662 99e300ef Blue Swirl
2663 54623277 Blue Swirl
/* lq */
2664 99e300ef Blue Swirl
static void gen_lq(DisasContext *ctx)
2665 be147d08 j_mayer
{
2666 be147d08 j_mayer
#if defined(CONFIG_USER_ONLY)
2667 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
2668 be147d08 j_mayer
#else
2669 be147d08 j_mayer
    int ra, rd;
2670 b61f2753 aurel32
    TCGv EA;
2671 be147d08 j_mayer
2672 be147d08 j_mayer
    /* Restore CPU state */
2673 76db3ba4 aurel32
    if (unlikely(ctx->mem_idx == 0)) {
2674 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
2675 be147d08 j_mayer
        return;
2676 be147d08 j_mayer
    }
2677 be147d08 j_mayer
    ra = rA(ctx->opcode);
2678 be147d08 j_mayer
    rd = rD(ctx->opcode);
2679 be147d08 j_mayer
    if (unlikely((rd & 1) || rd == ra)) {
2680 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2681 be147d08 j_mayer
        return;
2682 be147d08 j_mayer
    }
2683 76db3ba4 aurel32
    if (unlikely(ctx->le_mode)) {
2684 be147d08 j_mayer
        /* Little-endian mode is not handled */
2685 e06fcd75 aurel32
        gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
2686 be147d08 j_mayer
        return;
2687 be147d08 j_mayer
    }
2688 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_INT);
2689 a7812ae4 pbrook
    EA = tcg_temp_new();
2690 76db3ba4 aurel32
    gen_addr_imm_index(ctx, EA, 0x0F);
2691 76db3ba4 aurel32
    gen_qemu_ld64(ctx, cpu_gpr[rd], EA);
2692 76db3ba4 aurel32
    gen_addr_add(ctx, EA, EA, 8);
2693 76db3ba4 aurel32
    gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA);
2694 b61f2753 aurel32
    tcg_temp_free(EA);
2695 be147d08 j_mayer
#endif
2696 be147d08 j_mayer
}
2697 d9bce9d9 j_mayer
#endif
2698 79aceca5 bellard
2699 79aceca5 bellard
/***                              Integer store                            ***/
2700 0c8aacd4 aurel32
#define GEN_ST(name, stop, opc, type)                                         \
2701 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                                       \
2702 79aceca5 bellard
{                                                                             \
2703 76db3ba4 aurel32
    TCGv EA;                                                                  \
2704 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_INT);                                     \
2705 76db3ba4 aurel32
    EA = tcg_temp_new();                                                      \
2706 76db3ba4 aurel32
    gen_addr_imm_index(ctx, EA, 0);                                           \
2707 76db3ba4 aurel32
    gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA);                       \
2708 b61f2753 aurel32
    tcg_temp_free(EA);                                                        \
2709 79aceca5 bellard
}
2710 79aceca5 bellard
2711 0c8aacd4 aurel32
#define GEN_STU(name, stop, opc, type)                                        \
2712 99e300ef Blue Swirl
static void glue(gen_, stop##u)(DisasContext *ctx)                                    \
2713 79aceca5 bellard
{                                                                             \
2714 b61f2753 aurel32
    TCGv EA;                                                                  \
2715 76a66253 j_mayer
    if (unlikely(rA(ctx->opcode) == 0)) {                                     \
2716 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);                   \
2717 9fddaa0c bellard
        return;                                                               \
2718 9a64fbe4 bellard
    }                                                                         \
2719 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_INT);                                     \
2720 0c8aacd4 aurel32
    EA = tcg_temp_new();                                                      \
2721 9d53c753 j_mayer
    if (type == PPC_64B)                                                      \
2722 76db3ba4 aurel32
        gen_addr_imm_index(ctx, EA, 0x03);                                    \
2723 9d53c753 j_mayer
    else                                                                      \
2724 76db3ba4 aurel32
        gen_addr_imm_index(ctx, EA, 0);                                       \
2725 76db3ba4 aurel32
    gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA);                       \
2726 b61f2753 aurel32
    tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);                             \
2727 b61f2753 aurel32
    tcg_temp_free(EA);                                                        \
2728 79aceca5 bellard
}
2729 79aceca5 bellard
2730 0c8aacd4 aurel32
#define GEN_STUX(name, stop, opc2, opc3, type)                                \
2731 99e300ef Blue Swirl
static void glue(gen_, name##ux)(DisasContext *ctx)                                   \
2732 79aceca5 bellard
{                                                                             \
2733 b61f2753 aurel32
    TCGv EA;                                                                  \
2734 76a66253 j_mayer
    if (unlikely(rA(ctx->opcode) == 0)) {                                     \
2735 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);                   \
2736 9fddaa0c bellard
        return;                                                               \
2737 9a64fbe4 bellard
    }                                                                         \
2738 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_INT);                                     \
2739 0c8aacd4 aurel32
    EA = tcg_temp_new();                                                      \
2740 76db3ba4 aurel32
    gen_addr_reg_index(ctx, EA);                                              \
2741 76db3ba4 aurel32
    gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA);                       \
2742 b61f2753 aurel32
    tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);                             \
2743 b61f2753 aurel32
    tcg_temp_free(EA);                                                        \
2744 79aceca5 bellard
}
2745 79aceca5 bellard
2746 0c8aacd4 aurel32
#define GEN_STX(name, stop, opc2, opc3, type)                                 \
2747 99e300ef Blue Swirl
static void glue(gen_, name##x)(DisasContext *ctx)                                    \
2748 79aceca5 bellard
{                                                                             \
2749 76db3ba4 aurel32
    TCGv EA;                                                                  \
2750 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_INT);                                     \
2751 76db3ba4 aurel32
    EA = tcg_temp_new();                                                      \
2752 76db3ba4 aurel32
    gen_addr_reg_index(ctx, EA);                                              \
2753 76db3ba4 aurel32
    gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA);                       \
2754 b61f2753 aurel32
    tcg_temp_free(EA);                                                        \
2755 79aceca5 bellard
}
2756 79aceca5 bellard
2757 0c8aacd4 aurel32
#define GEN_STS(name, stop, op, type)                                         \
2758 0c8aacd4 aurel32
GEN_ST(name, stop, op | 0x20, type);                                          \
2759 0c8aacd4 aurel32
GEN_STU(name, stop, op | 0x21, type);                                         \
2760 0c8aacd4 aurel32
GEN_STUX(name, stop, 0x17, op | 0x01, type);                                  \
2761 0c8aacd4 aurel32
GEN_STX(name, stop, 0x17, op | 0x00, type)
2762 79aceca5 bellard
2763 79aceca5 bellard
/* stb stbu stbux stbx */
2764 0c8aacd4 aurel32
GEN_STS(stb, st8, 0x06, PPC_INTEGER);
2765 79aceca5 bellard
/* sth sthu sthux sthx */
2766 0c8aacd4 aurel32
GEN_STS(sth, st16, 0x0C, PPC_INTEGER);
2767 79aceca5 bellard
/* stw stwu stwux stwx */
2768 0c8aacd4 aurel32
GEN_STS(stw, st32, 0x04, PPC_INTEGER);
2769 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
2770 0c8aacd4 aurel32
GEN_STUX(std, st64, 0x15, 0x05, PPC_64B);
2771 0c8aacd4 aurel32
GEN_STX(std, st64, 0x15, 0x04, PPC_64B);
2772 99e300ef Blue Swirl
2773 99e300ef Blue Swirl
static void gen_std(DisasContext *ctx)
2774 d9bce9d9 j_mayer
{
2775 be147d08 j_mayer
    int rs;
2776 b61f2753 aurel32
    TCGv EA;
2777 be147d08 j_mayer
2778 be147d08 j_mayer
    rs = rS(ctx->opcode);
2779 be147d08 j_mayer
    if ((ctx->opcode & 0x3) == 0x2) {
2780 be147d08 j_mayer
#if defined(CONFIG_USER_ONLY)
2781 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
2782 be147d08 j_mayer
#else
2783 be147d08 j_mayer
        /* stq */
2784 76db3ba4 aurel32
        if (unlikely(ctx->mem_idx == 0)) {
2785 e06fcd75 aurel32
            gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
2786 be147d08 j_mayer
            return;
2787 be147d08 j_mayer
        }
2788 be147d08 j_mayer
        if (unlikely(rs & 1)) {
2789 e06fcd75 aurel32
            gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2790 d9bce9d9 j_mayer
            return;
2791 d9bce9d9 j_mayer
        }
2792 76db3ba4 aurel32
        if (unlikely(ctx->le_mode)) {
2793 be147d08 j_mayer
            /* Little-endian mode is not handled */
2794 e06fcd75 aurel32
            gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
2795 be147d08 j_mayer
            return;
2796 be147d08 j_mayer
        }
2797 76db3ba4 aurel32
        gen_set_access_type(ctx, ACCESS_INT);
2798 a7812ae4 pbrook
        EA = tcg_temp_new();
2799 76db3ba4 aurel32
        gen_addr_imm_index(ctx, EA, 0x03);
2800 76db3ba4 aurel32
        gen_qemu_st64(ctx, cpu_gpr[rs], EA);
2801 76db3ba4 aurel32
        gen_addr_add(ctx, EA, EA, 8);
2802 76db3ba4 aurel32
        gen_qemu_st64(ctx, cpu_gpr[rs+1], EA);
2803 b61f2753 aurel32
        tcg_temp_free(EA);
2804 be147d08 j_mayer
#endif
2805 be147d08 j_mayer
    } else {
2806 be147d08 j_mayer
        /* std / stdu */
2807 be147d08 j_mayer
        if (Rc(ctx->opcode)) {
2808 be147d08 j_mayer
            if (unlikely(rA(ctx->opcode) == 0)) {
2809 e06fcd75 aurel32
                gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
2810 be147d08 j_mayer
                return;
2811 be147d08 j_mayer
            }
2812 be147d08 j_mayer
        }
2813 76db3ba4 aurel32
        gen_set_access_type(ctx, ACCESS_INT);
2814 a7812ae4 pbrook
        EA = tcg_temp_new();
2815 76db3ba4 aurel32
        gen_addr_imm_index(ctx, EA, 0x03);
2816 76db3ba4 aurel32
        gen_qemu_st64(ctx, cpu_gpr[rs], EA);
2817 be147d08 j_mayer
        if (Rc(ctx->opcode))
2818 b61f2753 aurel32
            tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2819 b61f2753 aurel32
        tcg_temp_free(EA);
2820 d9bce9d9 j_mayer
    }
2821 d9bce9d9 j_mayer
}
2822 d9bce9d9 j_mayer
#endif
2823 79aceca5 bellard
/***                Integer load and store with byte reverse               ***/
2824 79aceca5 bellard
/* lhbrx */
2825 86178a57 Juan Quintela
static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
2826 b61f2753 aurel32
{
2827 76db3ba4 aurel32
    tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx);
2828 76db3ba4 aurel32
    if (likely(!ctx->le_mode)) {
2829 fa3966a3 aurel32
        tcg_gen_bswap16_tl(arg1, arg1);
2830 76db3ba4 aurel32
    }
2831 b61f2753 aurel32
}
2832 0c8aacd4 aurel32
GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER);
2833 b61f2753 aurel32
2834 79aceca5 bellard
/* lwbrx */
2835 86178a57 Juan Quintela
static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2)
2836 b61f2753 aurel32
{
2837 76db3ba4 aurel32
    tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx);
2838 76db3ba4 aurel32
    if (likely(!ctx->le_mode)) {
2839 fa3966a3 aurel32
        tcg_gen_bswap32_tl(arg1, arg1);
2840 76db3ba4 aurel32
    }
2841 b61f2753 aurel32
}
2842 0c8aacd4 aurel32
GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER);
2843 b61f2753 aurel32
2844 79aceca5 bellard
/* sthbrx */
2845 86178a57 Juan Quintela
static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2)
2846 b61f2753 aurel32
{
2847 76db3ba4 aurel32
    if (likely(!ctx->le_mode)) {
2848 76db3ba4 aurel32
        TCGv t0 = tcg_temp_new();
2849 76db3ba4 aurel32
        tcg_gen_ext16u_tl(t0, arg1);
2850 fa3966a3 aurel32
        tcg_gen_bswap16_tl(t0, t0);
2851 76db3ba4 aurel32
        tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx);
2852 76db3ba4 aurel32
        tcg_temp_free(t0);
2853 76db3ba4 aurel32
    } else {
2854 76db3ba4 aurel32
        tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx);
2855 76db3ba4 aurel32
    }
2856 b61f2753 aurel32
}
2857 0c8aacd4 aurel32
GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER);
2858 b61f2753 aurel32
2859 79aceca5 bellard
/* stwbrx */
2860 86178a57 Juan Quintela
static inline void gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2)
2861 b61f2753 aurel32
{
2862 76db3ba4 aurel32
    if (likely(!ctx->le_mode)) {
2863 fa3966a3 aurel32
        TCGv t0 = tcg_temp_new();
2864 fa3966a3 aurel32
        tcg_gen_ext32u_tl(t0, arg1);
2865 fa3966a3 aurel32
        tcg_gen_bswap32_tl(t0, t0);
2866 76db3ba4 aurel32
        tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx);
2867 76db3ba4 aurel32
        tcg_temp_free(t0);
2868 76db3ba4 aurel32
    } else {
2869 76db3ba4 aurel32
        tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx);
2870 76db3ba4 aurel32
    }
2871 b61f2753 aurel32
}
2872 0c8aacd4 aurel32
GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER);
2873 79aceca5 bellard
2874 79aceca5 bellard
/***                    Integer load and store multiple                    ***/
2875 99e300ef Blue Swirl
2876 54623277 Blue Swirl
/* lmw */
2877 99e300ef Blue Swirl
static void gen_lmw(DisasContext *ctx)
2878 79aceca5 bellard
{
2879 76db3ba4 aurel32
    TCGv t0;
2880 76db3ba4 aurel32
    TCGv_i32 t1;
2881 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_INT);
2882 76a66253 j_mayer
    /* NIP cannot be restored if the memory exception comes from an helper */
2883 d9bce9d9 j_mayer
    gen_update_nip(ctx, ctx->nip - 4);
2884 76db3ba4 aurel32
    t0 = tcg_temp_new();
2885 76db3ba4 aurel32
    t1 = tcg_const_i32(rD(ctx->opcode));
2886 76db3ba4 aurel32
    gen_addr_imm_index(ctx, t0, 0);
2887 ff4a62cd aurel32
    gen_helper_lmw(t0, t1);
2888 ff4a62cd aurel32
    tcg_temp_free(t0);
2889 ff4a62cd aurel32
    tcg_temp_free_i32(t1);
2890 79aceca5 bellard
}
2891 79aceca5 bellard
2892 79aceca5 bellard
/* stmw */
2893 99e300ef Blue Swirl
static void gen_stmw(DisasContext *ctx)
2894 79aceca5 bellard
{
2895 76db3ba4 aurel32
    TCGv t0;
2896 76db3ba4 aurel32
    TCGv_i32 t1;
2897 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_INT);
2898 76a66253 j_mayer
    /* NIP cannot be restored if the memory exception comes from an helper */
2899 d9bce9d9 j_mayer
    gen_update_nip(ctx, ctx->nip - 4);
2900 76db3ba4 aurel32
    t0 = tcg_temp_new();
2901 76db3ba4 aurel32
    t1 = tcg_const_i32(rS(ctx->opcode));
2902 76db3ba4 aurel32
    gen_addr_imm_index(ctx, t0, 0);
2903 ff4a62cd aurel32
    gen_helper_stmw(t0, t1);
2904 ff4a62cd aurel32
    tcg_temp_free(t0);
2905 ff4a62cd aurel32
    tcg_temp_free_i32(t1);
2906 79aceca5 bellard
}
2907 79aceca5 bellard
2908 79aceca5 bellard
/***                    Integer load and store strings                     ***/
2909 54623277 Blue Swirl
2910 79aceca5 bellard
/* lswi */
2911 3fc6c082 bellard
/* PowerPC32 specification says we must generate an exception if
2912 9a64fbe4 bellard
 * rA is in the range of registers to be loaded.
2913 9a64fbe4 bellard
 * In an other hand, IBM says this is valid, but rA won't be loaded.
2914 9a64fbe4 bellard
 * For now, I'll follow the spec...
2915 9a64fbe4 bellard
 */
2916 99e300ef Blue Swirl
static void gen_lswi(DisasContext *ctx)
2917 79aceca5 bellard
{
2918 dfbc799d aurel32
    TCGv t0;
2919 dfbc799d aurel32
    TCGv_i32 t1, t2;
2920 79aceca5 bellard
    int nb = NB(ctx->opcode);
2921 79aceca5 bellard
    int start = rD(ctx->opcode);
2922 9a64fbe4 bellard
    int ra = rA(ctx->opcode);
2923 79aceca5 bellard
    int nr;
2924 79aceca5 bellard
2925 79aceca5 bellard
    if (nb == 0)
2926 79aceca5 bellard
        nb = 32;
2927 79aceca5 bellard
    nr = nb / 4;
2928 76a66253 j_mayer
    if (unlikely(((start + nr) > 32  &&
2929 76a66253 j_mayer
                  start <= ra && (start + nr - 32) > ra) ||
2930 76a66253 j_mayer
                 ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) {
2931 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
2932 9fddaa0c bellard
        return;
2933 297d8e62 bellard
    }
2934 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_INT);
2935 8dd4983c bellard
    /* NIP cannot be restored if the memory exception comes from an helper */
2936 d9bce9d9 j_mayer
    gen_update_nip(ctx, ctx->nip - 4);
2937 dfbc799d aurel32
    t0 = tcg_temp_new();
2938 76db3ba4 aurel32
    gen_addr_register(ctx, t0);
2939 dfbc799d aurel32
    t1 = tcg_const_i32(nb);
2940 dfbc799d aurel32
    t2 = tcg_const_i32(start);
2941 dfbc799d aurel32
    gen_helper_lsw(t0, t1, t2);
2942 dfbc799d aurel32
    tcg_temp_free(t0);
2943 dfbc799d aurel32
    tcg_temp_free_i32(t1);
2944 dfbc799d aurel32
    tcg_temp_free_i32(t2);
2945 79aceca5 bellard
}
2946 79aceca5 bellard
2947 79aceca5 bellard
/* lswx */
2948 99e300ef Blue Swirl
static void gen_lswx(DisasContext *ctx)
2949 79aceca5 bellard
{
2950 76db3ba4 aurel32
    TCGv t0;
2951 76db3ba4 aurel32
    TCGv_i32 t1, t2, t3;
2952 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_INT);
2953 76a66253 j_mayer
    /* NIP cannot be restored if the memory exception comes from an helper */
2954 d9bce9d9 j_mayer
    gen_update_nip(ctx, ctx->nip - 4);
2955 76db3ba4 aurel32
    t0 = tcg_temp_new();
2956 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
2957 76db3ba4 aurel32
    t1 = tcg_const_i32(rD(ctx->opcode));
2958 76db3ba4 aurel32
    t2 = tcg_const_i32(rA(ctx->opcode));
2959 76db3ba4 aurel32
    t3 = tcg_const_i32(rB(ctx->opcode));
2960 dfbc799d aurel32
    gen_helper_lswx(t0, t1, t2, t3);
2961 dfbc799d aurel32
    tcg_temp_free(t0);
2962 dfbc799d aurel32
    tcg_temp_free_i32(t1);
2963 dfbc799d aurel32
    tcg_temp_free_i32(t2);
2964 dfbc799d aurel32
    tcg_temp_free_i32(t3);
2965 79aceca5 bellard
}
2966 79aceca5 bellard
2967 79aceca5 bellard
/* stswi */
2968 99e300ef Blue Swirl
static void gen_stswi(DisasContext *ctx)
2969 79aceca5 bellard
{
2970 76db3ba4 aurel32
    TCGv t0;
2971 76db3ba4 aurel32
    TCGv_i32 t1, t2;
2972 4b3686fa bellard
    int nb = NB(ctx->opcode);
2973 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_INT);
2974 76a66253 j_mayer
    /* NIP cannot be restored if the memory exception comes from an helper */
2975 d9bce9d9 j_mayer
    gen_update_nip(ctx, ctx->nip - 4);
2976 76db3ba4 aurel32
    t0 = tcg_temp_new();
2977 76db3ba4 aurel32
    gen_addr_register(ctx, t0);
2978 4b3686fa bellard
    if (nb == 0)
2979 4b3686fa bellard
        nb = 32;
2980 dfbc799d aurel32
    t1 = tcg_const_i32(nb);
2981 76db3ba4 aurel32
    t2 = tcg_const_i32(rS(ctx->opcode));
2982 dfbc799d aurel32
    gen_helper_stsw(t0, t1, t2);
2983 dfbc799d aurel32
    tcg_temp_free(t0);
2984 dfbc799d aurel32
    tcg_temp_free_i32(t1);
2985 dfbc799d aurel32
    tcg_temp_free_i32(t2);
2986 79aceca5 bellard
}
2987 79aceca5 bellard
2988 79aceca5 bellard
/* stswx */
2989 99e300ef Blue Swirl
static void gen_stswx(DisasContext *ctx)
2990 79aceca5 bellard
{
2991 76db3ba4 aurel32
    TCGv t0;
2992 76db3ba4 aurel32
    TCGv_i32 t1, t2;
2993 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_INT);
2994 8dd4983c bellard
    /* NIP cannot be restored if the memory exception comes from an helper */
2995 5fafdf24 ths
    gen_update_nip(ctx, ctx->nip - 4);
2996 76db3ba4 aurel32
    t0 = tcg_temp_new();
2997 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
2998 76db3ba4 aurel32
    t1 = tcg_temp_new_i32();
2999 dfbc799d aurel32
    tcg_gen_trunc_tl_i32(t1, cpu_xer);
3000 dfbc799d aurel32
    tcg_gen_andi_i32(t1, t1, 0x7F);
3001 76db3ba4 aurel32
    t2 = tcg_const_i32(rS(ctx->opcode));
3002 dfbc799d aurel32
    gen_helper_stsw(t0, t1, t2);
3003 dfbc799d aurel32
    tcg_temp_free(t0);
3004 dfbc799d aurel32
    tcg_temp_free_i32(t1);
3005 dfbc799d aurel32
    tcg_temp_free_i32(t2);
3006 79aceca5 bellard
}
3007 79aceca5 bellard
3008 79aceca5 bellard
/***                        Memory synchronisation                         ***/
3009 79aceca5 bellard
/* eieio */
3010 99e300ef Blue Swirl
static void gen_eieio(DisasContext *ctx)
3011 79aceca5 bellard
{
3012 79aceca5 bellard
}
3013 79aceca5 bellard
3014 79aceca5 bellard
/* isync */
3015 99e300ef Blue Swirl
static void gen_isync(DisasContext *ctx)
3016 79aceca5 bellard
{
3017 e06fcd75 aurel32
    gen_stop_exception(ctx);
3018 79aceca5 bellard
}
3019 79aceca5 bellard
3020 111bfab3 bellard
/* lwarx */
3021 99e300ef Blue Swirl
static void gen_lwarx(DisasContext *ctx)
3022 79aceca5 bellard
{
3023 76db3ba4 aurel32
    TCGv t0;
3024 18b21a2f Nathan Froyd
    TCGv gpr = cpu_gpr[rD(ctx->opcode)];
3025 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_RES);
3026 76db3ba4 aurel32
    t0 = tcg_temp_local_new();
3027 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
3028 cf360a32 aurel32
    gen_check_align(ctx, t0, 0x03);
3029 18b21a2f Nathan Froyd
    gen_qemu_ld32u(ctx, gpr, t0);
3030 cf360a32 aurel32
    tcg_gen_mov_tl(cpu_reserve, t0);
3031 18b21a2f Nathan Froyd
    tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUState, reserve_val));
3032 cf360a32 aurel32
    tcg_temp_free(t0);
3033 79aceca5 bellard
}
3034 79aceca5 bellard
3035 4425265b Nathan Froyd
#if defined(CONFIG_USER_ONLY)
3036 4425265b Nathan Froyd
static void gen_conditional_store (DisasContext *ctx, TCGv EA,
3037 4425265b Nathan Froyd
                                   int reg, int size)
3038 4425265b Nathan Froyd
{
3039 4425265b Nathan Froyd
    TCGv t0 = tcg_temp_new();
3040 4425265b Nathan Froyd
    uint32_t save_exception = ctx->exception;
3041 4425265b Nathan Froyd
3042 4425265b Nathan Froyd
    tcg_gen_st_tl(EA, cpu_env, offsetof(CPUState, reserve_ea));
3043 4425265b Nathan Froyd
    tcg_gen_movi_tl(t0, (size << 5) | reg);
3044 4425265b Nathan Froyd
    tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, reserve_info));
3045 4425265b Nathan Froyd
    tcg_temp_free(t0);
3046 4425265b Nathan Froyd
    gen_update_nip(ctx, ctx->nip-4);
3047 4425265b Nathan Froyd
    ctx->exception = POWERPC_EXCP_BRANCH;
3048 4425265b Nathan Froyd
    gen_exception(ctx, POWERPC_EXCP_STCX);
3049 4425265b Nathan Froyd
    ctx->exception = save_exception;
3050 4425265b Nathan Froyd
}
3051 4425265b Nathan Froyd
#endif
3052 4425265b Nathan Froyd
3053 79aceca5 bellard
/* stwcx. */
3054 e8eaa2c0 Blue Swirl
static void gen_stwcx_(DisasContext *ctx)
3055 79aceca5 bellard
{
3056 76db3ba4 aurel32
    TCGv t0;
3057 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_RES);
3058 76db3ba4 aurel32
    t0 = tcg_temp_local_new();
3059 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
3060 cf360a32 aurel32
    gen_check_align(ctx, t0, 0x03);
3061 4425265b Nathan Froyd
#if defined(CONFIG_USER_ONLY)
3062 4425265b Nathan Froyd
    gen_conditional_store(ctx, t0, rS(ctx->opcode), 4);
3063 4425265b Nathan Froyd
#else
3064 4425265b Nathan Froyd
    {
3065 4425265b Nathan Froyd
        int l1;
3066 4425265b Nathan Froyd
3067 4425265b Nathan Froyd
        tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_xer);
3068 4425265b Nathan Froyd
        tcg_gen_shri_i32(cpu_crf[0], cpu_crf[0], XER_SO);
3069 4425265b Nathan Froyd
        tcg_gen_andi_i32(cpu_crf[0], cpu_crf[0], 1);
3070 4425265b Nathan Froyd
        l1 = gen_new_label();
3071 4425265b Nathan Froyd
        tcg_gen_brcond_tl(TCG_COND_NE, t0, cpu_reserve, l1);
3072 4425265b Nathan Froyd
        tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
3073 4425265b Nathan Froyd
        gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], t0);
3074 4425265b Nathan Froyd
        gen_set_label(l1);
3075 4425265b Nathan Froyd
        tcg_gen_movi_tl(cpu_reserve, -1);
3076 4425265b Nathan Froyd
    }
3077 4425265b Nathan Froyd
#endif
3078 cf360a32 aurel32
    tcg_temp_free(t0);
3079 79aceca5 bellard
}
3080 79aceca5 bellard
3081 426613db j_mayer
#if defined(TARGET_PPC64)
3082 426613db j_mayer
/* ldarx */
3083 99e300ef Blue Swirl
static void gen_ldarx(DisasContext *ctx)
3084 426613db j_mayer
{
3085 76db3ba4 aurel32
    TCGv t0;
3086 18b21a2f Nathan Froyd
    TCGv gpr = cpu_gpr[rD(ctx->opcode)];
3087 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_RES);
3088 76db3ba4 aurel32
    t0 = tcg_temp_local_new();
3089 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
3090 cf360a32 aurel32
    gen_check_align(ctx, t0, 0x07);
3091 18b21a2f Nathan Froyd
    gen_qemu_ld64(ctx, gpr, t0);
3092 cf360a32 aurel32
    tcg_gen_mov_tl(cpu_reserve, t0);
3093 18b21a2f Nathan Froyd
    tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUState, reserve_val));
3094 cf360a32 aurel32
    tcg_temp_free(t0);
3095 426613db j_mayer
}
3096 426613db j_mayer
3097 426613db j_mayer
/* stdcx. */
3098 e8eaa2c0 Blue Swirl
static void gen_stdcx_(DisasContext *ctx)
3099 426613db j_mayer
{
3100 76db3ba4 aurel32
    TCGv t0;
3101 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_RES);
3102 76db3ba4 aurel32
    t0 = tcg_temp_local_new();
3103 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
3104 cf360a32 aurel32
    gen_check_align(ctx, t0, 0x07);
3105 4425265b Nathan Froyd
#if defined(CONFIG_USER_ONLY)
3106 4425265b Nathan Froyd
    gen_conditional_store(ctx, t0, rS(ctx->opcode), 8);
3107 4425265b Nathan Froyd
#else
3108 4425265b Nathan Froyd
    {
3109 4425265b Nathan Froyd
        int l1;
3110 4425265b Nathan Froyd
        tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_xer);
3111 4425265b Nathan Froyd
        tcg_gen_shri_i32(cpu_crf[0], cpu_crf[0], XER_SO);
3112 4425265b Nathan Froyd
        tcg_gen_andi_i32(cpu_crf[0], cpu_crf[0], 1);
3113 4425265b Nathan Froyd
        l1 = gen_new_label();
3114 4425265b Nathan Froyd
        tcg_gen_brcond_tl(TCG_COND_NE, t0, cpu_reserve, l1);
3115 4425265b Nathan Froyd
        tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ);
3116 4425265b Nathan Froyd
        gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], t0);
3117 4425265b Nathan Froyd
        gen_set_label(l1);
3118 4425265b Nathan Froyd
        tcg_gen_movi_tl(cpu_reserve, -1);
3119 4425265b Nathan Froyd
    }
3120 4425265b Nathan Froyd
#endif
3121 cf360a32 aurel32
    tcg_temp_free(t0);
3122 426613db j_mayer
}
3123 426613db j_mayer
#endif /* defined(TARGET_PPC64) */
3124 426613db j_mayer
3125 79aceca5 bellard
/* sync */
3126 99e300ef Blue Swirl
static void gen_sync(DisasContext *ctx)
3127 79aceca5 bellard
{
3128 79aceca5 bellard
}
3129 79aceca5 bellard
3130 0db1b20e j_mayer
/* wait */
3131 99e300ef Blue Swirl
static void gen_wait(DisasContext *ctx)
3132 0db1b20e j_mayer
{
3133 931ff272 aurel32
    TCGv_i32 t0 = tcg_temp_new_i32();
3134 931ff272 aurel32
    tcg_gen_st_i32(t0, cpu_env, offsetof(CPUState, halted));
3135 931ff272 aurel32
    tcg_temp_free_i32(t0);
3136 0db1b20e j_mayer
    /* Stop translation, as the CPU is supposed to sleep from now */
3137 e06fcd75 aurel32
    gen_exception_err(ctx, EXCP_HLT, 1);
3138 0db1b20e j_mayer
}
3139 0db1b20e j_mayer
3140 79aceca5 bellard
/***                         Floating-point load                           ***/
3141 a0d7d5a7 aurel32
#define GEN_LDF(name, ldop, opc, type)                                        \
3142 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                                       \
3143 79aceca5 bellard
{                                                                             \
3144 a0d7d5a7 aurel32
    TCGv EA;                                                                  \
3145 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {                                        \
3146 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
3147 4ecc3190 bellard
        return;                                                               \
3148 4ecc3190 bellard
    }                                                                         \
3149 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_FLOAT);                                   \
3150 a0d7d5a7 aurel32
    EA = tcg_temp_new();                                                      \
3151 76db3ba4 aurel32
    gen_addr_imm_index(ctx, EA, 0);                                           \
3152 76db3ba4 aurel32
    gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA);                       \
3153 a0d7d5a7 aurel32
    tcg_temp_free(EA);                                                        \
3154 79aceca5 bellard
}
3155 79aceca5 bellard
3156 a0d7d5a7 aurel32
#define GEN_LDUF(name, ldop, opc, type)                                       \
3157 99e300ef Blue Swirl
static void glue(gen_, name##u)(DisasContext *ctx)                                    \
3158 79aceca5 bellard
{                                                                             \
3159 a0d7d5a7 aurel32
    TCGv EA;                                                                  \
3160 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {                                        \
3161 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
3162 4ecc3190 bellard
        return;                                                               \
3163 4ecc3190 bellard
    }                                                                         \
3164 76a66253 j_mayer
    if (unlikely(rA(ctx->opcode) == 0)) {                                     \
3165 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);                   \
3166 9fddaa0c bellard
        return;                                                               \
3167 9a64fbe4 bellard
    }                                                                         \
3168 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_FLOAT);                                   \
3169 a0d7d5a7 aurel32
    EA = tcg_temp_new();                                                      \
3170 76db3ba4 aurel32
    gen_addr_imm_index(ctx, EA, 0);                                           \
3171 76db3ba4 aurel32
    gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA);                       \
3172 a0d7d5a7 aurel32
    tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);                             \
3173 a0d7d5a7 aurel32
    tcg_temp_free(EA);                                                        \
3174 79aceca5 bellard
}
3175 79aceca5 bellard
3176 a0d7d5a7 aurel32
#define GEN_LDUXF(name, ldop, opc, type)                                      \
3177 99e300ef Blue Swirl
static void glue(gen_, name##ux)(DisasContext *ctx)                                   \
3178 79aceca5 bellard
{                                                                             \
3179 a0d7d5a7 aurel32
    TCGv EA;                                                                  \
3180 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {                                        \
3181 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
3182 4ecc3190 bellard
        return;                                                               \
3183 4ecc3190 bellard
    }                                                                         \
3184 76a66253 j_mayer
    if (unlikely(rA(ctx->opcode) == 0)) {                                     \
3185 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);                   \
3186 9fddaa0c bellard
        return;                                                               \
3187 9a64fbe4 bellard
    }                                                                         \
3188 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_FLOAT);                                   \
3189 a0d7d5a7 aurel32
    EA = tcg_temp_new();                                                      \
3190 76db3ba4 aurel32
    gen_addr_reg_index(ctx, EA);                                              \
3191 76db3ba4 aurel32
    gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA);                       \
3192 a0d7d5a7 aurel32
    tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);                             \
3193 a0d7d5a7 aurel32
    tcg_temp_free(EA);                                                        \
3194 79aceca5 bellard
}
3195 79aceca5 bellard
3196 a0d7d5a7 aurel32
#define GEN_LDXF(name, ldop, opc2, opc3, type)                                \
3197 99e300ef Blue Swirl
static void glue(gen_, name##x)(DisasContext *ctx)                                    \
3198 79aceca5 bellard
{                                                                             \
3199 a0d7d5a7 aurel32
    TCGv EA;                                                                  \
3200 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {                                        \
3201 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
3202 4ecc3190 bellard
        return;                                                               \
3203 4ecc3190 bellard
    }                                                                         \
3204 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_FLOAT);                                   \
3205 a0d7d5a7 aurel32
    EA = tcg_temp_new();                                                      \
3206 76db3ba4 aurel32
    gen_addr_reg_index(ctx, EA);                                              \
3207 76db3ba4 aurel32
    gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA);                       \
3208 a0d7d5a7 aurel32
    tcg_temp_free(EA);                                                        \
3209 79aceca5 bellard
}
3210 79aceca5 bellard
3211 a0d7d5a7 aurel32
#define GEN_LDFS(name, ldop, op, type)                                        \
3212 a0d7d5a7 aurel32
GEN_LDF(name, ldop, op | 0x20, type);                                         \
3213 a0d7d5a7 aurel32
GEN_LDUF(name, ldop, op | 0x21, type);                                        \
3214 a0d7d5a7 aurel32
GEN_LDUXF(name, ldop, op | 0x01, type);                                       \
3215 a0d7d5a7 aurel32
GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3216 a0d7d5a7 aurel32
3217 636aa200 Blue Swirl
static inline void gen_qemu_ld32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
3218 a0d7d5a7 aurel32
{
3219 a0d7d5a7 aurel32
    TCGv t0 = tcg_temp_new();
3220 a0d7d5a7 aurel32
    TCGv_i32 t1 = tcg_temp_new_i32();
3221 76db3ba4 aurel32
    gen_qemu_ld32u(ctx, t0, arg2);
3222 a0d7d5a7 aurel32
    tcg_gen_trunc_tl_i32(t1, t0);
3223 a0d7d5a7 aurel32
    tcg_temp_free(t0);
3224 a0d7d5a7 aurel32
    gen_helper_float32_to_float64(arg1, t1);
3225 a0d7d5a7 aurel32
    tcg_temp_free_i32(t1);
3226 a0d7d5a7 aurel32
}
3227 79aceca5 bellard
3228 a0d7d5a7 aurel32
 /* lfd lfdu lfdux lfdx */
3229 a0d7d5a7 aurel32
GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT);
3230 a0d7d5a7 aurel32
 /* lfs lfsu lfsux lfsx */
3231 a0d7d5a7 aurel32
GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT);
3232 79aceca5 bellard
3233 79aceca5 bellard
/***                         Floating-point store                          ***/
3234 a0d7d5a7 aurel32
#define GEN_STF(name, stop, opc, type)                                        \
3235 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                                       \
3236 79aceca5 bellard
{                                                                             \
3237 a0d7d5a7 aurel32
    TCGv EA;                                                                  \
3238 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {                                        \
3239 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
3240 4ecc3190 bellard
        return;                                                               \
3241 4ecc3190 bellard
    }                                                                         \
3242 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_FLOAT);                                   \
3243 a0d7d5a7 aurel32
    EA = tcg_temp_new();                                                      \
3244 76db3ba4 aurel32
    gen_addr_imm_index(ctx, EA, 0);                                           \
3245 76db3ba4 aurel32
    gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA);                       \
3246 a0d7d5a7 aurel32
    tcg_temp_free(EA);                                                        \
3247 79aceca5 bellard
}
3248 79aceca5 bellard
3249 a0d7d5a7 aurel32
#define GEN_STUF(name, stop, opc, type)                                       \
3250 99e300ef Blue Swirl
static void glue(gen_, name##u)(DisasContext *ctx)                                    \
3251 79aceca5 bellard
{                                                                             \
3252 a0d7d5a7 aurel32
    TCGv EA;                                                                  \
3253 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {                                        \
3254 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
3255 4ecc3190 bellard
        return;                                                               \
3256 4ecc3190 bellard
    }                                                                         \
3257 76a66253 j_mayer
    if (unlikely(rA(ctx->opcode) == 0)) {                                     \
3258 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);                   \
3259 9fddaa0c bellard
        return;                                                               \
3260 9a64fbe4 bellard
    }                                                                         \
3261 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_FLOAT);                                   \
3262 a0d7d5a7 aurel32
    EA = tcg_temp_new();                                                      \
3263 76db3ba4 aurel32
    gen_addr_imm_index(ctx, EA, 0);                                           \
3264 76db3ba4 aurel32
    gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA);                       \
3265 a0d7d5a7 aurel32
    tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);                             \
3266 a0d7d5a7 aurel32
    tcg_temp_free(EA);                                                        \
3267 79aceca5 bellard
}
3268 79aceca5 bellard
3269 a0d7d5a7 aurel32
#define GEN_STUXF(name, stop, opc, type)                                      \
3270 99e300ef Blue Swirl
static void glue(gen_, name##ux)(DisasContext *ctx)                                   \
3271 79aceca5 bellard
{                                                                             \
3272 a0d7d5a7 aurel32
    TCGv EA;                                                                  \
3273 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {                                        \
3274 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
3275 4ecc3190 bellard
        return;                                                               \
3276 4ecc3190 bellard
    }                                                                         \
3277 76a66253 j_mayer
    if (unlikely(rA(ctx->opcode) == 0)) {                                     \
3278 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);                   \
3279 9fddaa0c bellard
        return;                                                               \
3280 9a64fbe4 bellard
    }                                                                         \
3281 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_FLOAT);                                   \
3282 a0d7d5a7 aurel32
    EA = tcg_temp_new();                                                      \
3283 76db3ba4 aurel32
    gen_addr_reg_index(ctx, EA);                                              \
3284 76db3ba4 aurel32
    gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA);                       \
3285 a0d7d5a7 aurel32
    tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);                             \
3286 a0d7d5a7 aurel32
    tcg_temp_free(EA);                                                        \
3287 79aceca5 bellard
}
3288 79aceca5 bellard
3289 a0d7d5a7 aurel32
#define GEN_STXF(name, stop, opc2, opc3, type)                                \
3290 99e300ef Blue Swirl
static void glue(gen_, name##x)(DisasContext *ctx)                                    \
3291 79aceca5 bellard
{                                                                             \
3292 a0d7d5a7 aurel32
    TCGv EA;                                                                  \
3293 76a66253 j_mayer
    if (unlikely(!ctx->fpu_enabled)) {                                        \
3294 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_FPU);                                 \
3295 4ecc3190 bellard
        return;                                                               \
3296 4ecc3190 bellard
    }                                                                         \
3297 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_FLOAT);                                   \
3298 a0d7d5a7 aurel32
    EA = tcg_temp_new();                                                      \
3299 76db3ba4 aurel32
    gen_addr_reg_index(ctx, EA);                                              \
3300 76db3ba4 aurel32
    gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA);                       \
3301 a0d7d5a7 aurel32
    tcg_temp_free(EA);                                                        \
3302 79aceca5 bellard
}
3303 79aceca5 bellard
3304 a0d7d5a7 aurel32
#define GEN_STFS(name, stop, op, type)                                        \
3305 a0d7d5a7 aurel32
GEN_STF(name, stop, op | 0x20, type);                                         \
3306 a0d7d5a7 aurel32
GEN_STUF(name, stop, op | 0x21, type);                                        \
3307 a0d7d5a7 aurel32
GEN_STUXF(name, stop, op | 0x01, type);                                       \
3308 a0d7d5a7 aurel32
GEN_STXF(name, stop, 0x17, op | 0x00, type)
3309 a0d7d5a7 aurel32
3310 636aa200 Blue Swirl
static inline void gen_qemu_st32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
3311 a0d7d5a7 aurel32
{
3312 a0d7d5a7 aurel32
    TCGv_i32 t0 = tcg_temp_new_i32();
3313 a0d7d5a7 aurel32
    TCGv t1 = tcg_temp_new();
3314 a0d7d5a7 aurel32
    gen_helper_float64_to_float32(t0, arg1);
3315 a0d7d5a7 aurel32
    tcg_gen_extu_i32_tl(t1, t0);
3316 a0d7d5a7 aurel32
    tcg_temp_free_i32(t0);
3317 76db3ba4 aurel32
    gen_qemu_st32(ctx, t1, arg2);
3318 a0d7d5a7 aurel32
    tcg_temp_free(t1);
3319 a0d7d5a7 aurel32
}
3320 79aceca5 bellard
3321 79aceca5 bellard
/* stfd stfdu stfdux stfdx */
3322 a0d7d5a7 aurel32
GEN_STFS(stfd, st64, 0x16, PPC_FLOAT);
3323 79aceca5 bellard
/* stfs stfsu stfsux stfsx */
3324 a0d7d5a7 aurel32
GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT);
3325 79aceca5 bellard
3326 79aceca5 bellard
/* Optional: */
3327 636aa200 Blue Swirl
static inline void gen_qemu_st32fiw(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
3328 a0d7d5a7 aurel32
{
3329 a0d7d5a7 aurel32
    TCGv t0 = tcg_temp_new();
3330 a0d7d5a7 aurel32
    tcg_gen_trunc_i64_tl(t0, arg1),
3331 76db3ba4 aurel32
    gen_qemu_st32(ctx, t0, arg2);
3332 a0d7d5a7 aurel32
    tcg_temp_free(t0);
3333 a0d7d5a7 aurel32
}
3334 79aceca5 bellard
/* stfiwx */
3335 a0d7d5a7 aurel32
GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX);
3336 79aceca5 bellard
3337 79aceca5 bellard
/***                                Branch                                 ***/
3338 636aa200 Blue Swirl
static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
3339 c1942362 bellard
{
3340 c1942362 bellard
    TranslationBlock *tb;
3341 c1942362 bellard
    tb = ctx->tb;
3342 a2ffb812 aurel32
#if defined(TARGET_PPC64)
3343 a2ffb812 aurel32
    if (!ctx->sf_mode)
3344 a2ffb812 aurel32
        dest = (uint32_t) dest;
3345 a2ffb812 aurel32
#endif
3346 57fec1fe bellard
    if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) &&
3347 8cbcb4fa aurel32
        likely(!ctx->singlestep_enabled)) {
3348 57fec1fe bellard
        tcg_gen_goto_tb(n);
3349 a2ffb812 aurel32
        tcg_gen_movi_tl(cpu_nip, dest & ~3);
3350 57fec1fe bellard
        tcg_gen_exit_tb((long)tb + n);
3351 c1942362 bellard
    } else {
3352 a2ffb812 aurel32
        tcg_gen_movi_tl(cpu_nip, dest & ~3);
3353 8cbcb4fa aurel32
        if (unlikely(ctx->singlestep_enabled)) {
3354 8cbcb4fa aurel32
            if ((ctx->singlestep_enabled &
3355 bdc4e053 aurel32
                (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) &&
3356 8cbcb4fa aurel32
                ctx->exception == POWERPC_EXCP_BRANCH) {
3357 8cbcb4fa aurel32
                target_ulong tmp = ctx->nip;
3358 8cbcb4fa aurel32
                ctx->nip = dest;
3359 e06fcd75 aurel32
                gen_exception(ctx, POWERPC_EXCP_TRACE);
3360 8cbcb4fa aurel32
                ctx->nip = tmp;
3361 8cbcb4fa aurel32
            }
3362 8cbcb4fa aurel32
            if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) {
3363 e06fcd75 aurel32
                gen_debug_exception(ctx);
3364 8cbcb4fa aurel32
            }
3365 8cbcb4fa aurel32
        }
3366 57fec1fe bellard
        tcg_gen_exit_tb(0);
3367 c1942362 bellard
    }
3368 c53be334 bellard
}
3369 c53be334 bellard
3370 636aa200 Blue Swirl
static inline void gen_setlr(DisasContext *ctx, target_ulong nip)
3371 e1833e1f j_mayer
{
3372 e1833e1f j_mayer
#if defined(TARGET_PPC64)
3373 a2ffb812 aurel32
    if (ctx->sf_mode == 0)
3374 a2ffb812 aurel32
        tcg_gen_movi_tl(cpu_lr, (uint32_t)nip);
3375 e1833e1f j_mayer
    else
3376 e1833e1f j_mayer
#endif
3377 a2ffb812 aurel32
        tcg_gen_movi_tl(cpu_lr, nip);
3378 e1833e1f j_mayer
}
3379 e1833e1f j_mayer
3380 79aceca5 bellard
/* b ba bl bla */
3381 99e300ef Blue Swirl
static void gen_b(DisasContext *ctx)
3382 79aceca5 bellard
{
3383 76a66253 j_mayer
    target_ulong li, target;
3384 38a64f9d bellard
3385 8cbcb4fa aurel32
    ctx->exception = POWERPC_EXCP_BRANCH;
3386 38a64f9d bellard
    /* sign extend LI */
3387 76a66253 j_mayer
#if defined(TARGET_PPC64)
3388 d9bce9d9 j_mayer
    if (ctx->sf_mode)
3389 d9bce9d9 j_mayer
        li = ((int64_t)LI(ctx->opcode) << 38) >> 38;
3390 d9bce9d9 j_mayer
    else
3391 76a66253 j_mayer
#endif
3392 d9bce9d9 j_mayer
        li = ((int32_t)LI(ctx->opcode) << 6) >> 6;
3393 76a66253 j_mayer
    if (likely(AA(ctx->opcode) == 0))
3394 046d6672 bellard
        target = ctx->nip + li - 4;
3395 79aceca5 bellard
    else
3396 9a64fbe4 bellard
        target = li;
3397 e1833e1f j_mayer
    if (LK(ctx->opcode))
3398 e1833e1f j_mayer
        gen_setlr(ctx, ctx->nip);
3399 c1942362 bellard
    gen_goto_tb(ctx, 0, target);
3400 79aceca5 bellard
}
3401 79aceca5 bellard
3402 e98a6e40 bellard
#define BCOND_IM  0
3403 e98a6e40 bellard
#define BCOND_LR  1
3404 e98a6e40 bellard
#define BCOND_CTR 2
3405 e98a6e40 bellard
3406 636aa200 Blue Swirl
static inline void gen_bcond(DisasContext *ctx, int type)
3407 d9bce9d9 j_mayer
{
3408 d9bce9d9 j_mayer
    uint32_t bo = BO(ctx->opcode);
3409 05f92404 Blue Swirl
    int l1;
3410 a2ffb812 aurel32
    TCGv target;
3411 e98a6e40 bellard
3412 8cbcb4fa aurel32
    ctx->exception = POWERPC_EXCP_BRANCH;
3413 a2ffb812 aurel32
    if (type == BCOND_LR || type == BCOND_CTR) {
3414 a7812ae4 pbrook
        target = tcg_temp_local_new();
3415 a2ffb812 aurel32
        if (type == BCOND_CTR)
3416 a2ffb812 aurel32
            tcg_gen_mov_tl(target, cpu_ctr);
3417 a2ffb812 aurel32
        else
3418 a2ffb812 aurel32
            tcg_gen_mov_tl(target, cpu_lr);
3419 d2e9fd8f malc
    } else {
3420 d2e9fd8f malc
        TCGV_UNUSED(target);
3421 e98a6e40 bellard
    }
3422 e1833e1f j_mayer
    if (LK(ctx->opcode))
3423 e1833e1f j_mayer
        gen_setlr(ctx, ctx->nip);
3424 a2ffb812 aurel32
    l1 = gen_new_label();
3425 a2ffb812 aurel32
    if ((bo & 0x4) == 0) {
3426 a2ffb812 aurel32
        /* Decrement and test CTR */
3427 a7812ae4 pbrook
        TCGv temp = tcg_temp_new();
3428 a2ffb812 aurel32
        if (unlikely(type == BCOND_CTR)) {
3429 e06fcd75 aurel32
            gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3430 a2ffb812 aurel32
            return;
3431 a2ffb812 aurel32
        }
3432 a2ffb812 aurel32
        tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
3433 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
3434 a2ffb812 aurel32
        if (!ctx->sf_mode)
3435 a2ffb812 aurel32
            tcg_gen_ext32u_tl(temp, cpu_ctr);
3436 a2ffb812 aurel32
        else
3437 d9bce9d9 j_mayer
#endif
3438 a2ffb812 aurel32
            tcg_gen_mov_tl(temp, cpu_ctr);
3439 a2ffb812 aurel32
        if (bo & 0x2) {
3440 a2ffb812 aurel32
            tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
3441 a2ffb812 aurel32
        } else {
3442 a2ffb812 aurel32
            tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
3443 e98a6e40 bellard
        }
3444 a7812ae4 pbrook
        tcg_temp_free(temp);
3445 a2ffb812 aurel32
    }
3446 a2ffb812 aurel32
    if ((bo & 0x10) == 0) {
3447 a2ffb812 aurel32
        /* Test CR */
3448 a2ffb812 aurel32
        uint32_t bi = BI(ctx->opcode);
3449 a2ffb812 aurel32
        uint32_t mask = 1 << (3 - (bi & 0x03));
3450 a7812ae4 pbrook
        TCGv_i32 temp = tcg_temp_new_i32();
3451 a2ffb812 aurel32
3452 d9bce9d9 j_mayer
        if (bo & 0x8) {
3453 a2ffb812 aurel32
            tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3454 a2ffb812 aurel32
            tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1);
3455 d9bce9d9 j_mayer
        } else {
3456 a2ffb812 aurel32
            tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3457 a2ffb812 aurel32
            tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1);
3458 d9bce9d9 j_mayer
        }
3459 a7812ae4 pbrook
        tcg_temp_free_i32(temp);
3460 d9bce9d9 j_mayer
    }
3461 e98a6e40 bellard
    if (type == BCOND_IM) {
3462 a2ffb812 aurel32
        target_ulong li = (target_long)((int16_t)(BD(ctx->opcode)));
3463 a2ffb812 aurel32
        if (likely(AA(ctx->opcode) == 0)) {
3464 a2ffb812 aurel32
            gen_goto_tb(ctx, 0, ctx->nip + li - 4);
3465 a2ffb812 aurel32
        } else {
3466 a2ffb812 aurel32
            gen_goto_tb(ctx, 0, li);
3467 a2ffb812 aurel32
        }
3468 c53be334 bellard
        gen_set_label(l1);
3469 c1942362 bellard
        gen_goto_tb(ctx, 1, ctx->nip);
3470 e98a6e40 bellard
    } else {
3471 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
3472 a2ffb812 aurel32
        if (!(ctx->sf_mode))
3473 a2ffb812 aurel32
            tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3);
3474 a2ffb812 aurel32
        else
3475 a2ffb812 aurel32
#endif
3476 a2ffb812 aurel32
            tcg_gen_andi_tl(cpu_nip, target, ~3);
3477 a2ffb812 aurel32
        tcg_gen_exit_tb(0);
3478 a2ffb812 aurel32
        gen_set_label(l1);
3479 a2ffb812 aurel32
#if defined(TARGET_PPC64)
3480 a2ffb812 aurel32
        if (!(ctx->sf_mode))
3481 a2ffb812 aurel32
            tcg_gen_movi_tl(cpu_nip, (uint32_t)ctx->nip);
3482 d9bce9d9 j_mayer
        else
3483 d9bce9d9 j_mayer
#endif
3484 a2ffb812 aurel32
            tcg_gen_movi_tl(cpu_nip, ctx->nip);
3485 57fec1fe bellard
        tcg_gen_exit_tb(0);
3486 08e46e54 j_mayer
    }
3487 e98a6e40 bellard
}
3488 e98a6e40 bellard
3489 99e300ef Blue Swirl
static void gen_bc(DisasContext *ctx)
3490 3b46e624 ths
{
3491 e98a6e40 bellard
    gen_bcond(ctx, BCOND_IM);
3492 e98a6e40 bellard
}
3493 e98a6e40 bellard
3494 99e300ef Blue Swirl
static void gen_bcctr(DisasContext *ctx)
3495 3b46e624 ths
{
3496 e98a6e40 bellard
    gen_bcond(ctx, BCOND_CTR);
3497 e98a6e40 bellard
}
3498 e98a6e40 bellard
3499 99e300ef Blue Swirl
static void gen_bclr(DisasContext *ctx)
3500 3b46e624 ths
{
3501 e98a6e40 bellard
    gen_bcond(ctx, BCOND_LR);
3502 e98a6e40 bellard
}
3503 79aceca5 bellard
3504 79aceca5 bellard
/***                      Condition register logical                       ***/
3505 e1571908 aurel32
#define GEN_CRLOGIC(name, tcg_op, opc)                                        \
3506 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                                       \
3507 79aceca5 bellard
{                                                                             \
3508 fc0d441e j_mayer
    uint8_t bitmask;                                                          \
3509 fc0d441e j_mayer
    int sh;                                                                   \
3510 a7812ae4 pbrook
    TCGv_i32 t0, t1;                                                          \
3511 fc0d441e j_mayer
    sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03);             \
3512 a7812ae4 pbrook
    t0 = tcg_temp_new_i32();                                                  \
3513 fc0d441e j_mayer
    if (sh > 0)                                                               \
3514 fea0c503 aurel32
        tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh);            \
3515 fc0d441e j_mayer
    else if (sh < 0)                                                          \
3516 fea0c503 aurel32
        tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh);           \
3517 e1571908 aurel32
    else                                                                      \
3518 fea0c503 aurel32
        tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]);                 \
3519 a7812ae4 pbrook
    t1 = tcg_temp_new_i32();                                                  \
3520 fc0d441e j_mayer
    sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03);             \
3521 fc0d441e j_mayer
    if (sh > 0)                                                               \
3522 fea0c503 aurel32
        tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh);            \
3523 fc0d441e j_mayer
    else if (sh < 0)                                                          \
3524 fea0c503 aurel32
        tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh);           \
3525 e1571908 aurel32
    else                                                                      \
3526 fea0c503 aurel32
        tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]);                 \
3527 fea0c503 aurel32
    tcg_op(t0, t0, t1);                                                       \
3528 fc0d441e j_mayer
    bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03));                          \
3529 fea0c503 aurel32
    tcg_gen_andi_i32(t0, t0, bitmask);                                        \
3530 fea0c503 aurel32
    tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask);          \
3531 fea0c503 aurel32
    tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1);                  \
3532 a7812ae4 pbrook
    tcg_temp_free_i32(t0);                                                    \
3533 a7812ae4 pbrook
    tcg_temp_free_i32(t1);                                                    \
3534 79aceca5 bellard
}
3535 79aceca5 bellard
3536 79aceca5 bellard
/* crand */
3537 e1571908 aurel32
GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08);
3538 79aceca5 bellard
/* crandc */
3539 e1571908 aurel32
GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04);
3540 79aceca5 bellard
/* creqv */
3541 e1571908 aurel32
GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09);
3542 79aceca5 bellard
/* crnand */
3543 e1571908 aurel32
GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07);
3544 79aceca5 bellard
/* crnor */
3545 e1571908 aurel32
GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01);
3546 79aceca5 bellard
/* cror */
3547 e1571908 aurel32
GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E);
3548 79aceca5 bellard
/* crorc */
3549 e1571908 aurel32
GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D);
3550 79aceca5 bellard
/* crxor */
3551 e1571908 aurel32
GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06);
3552 99e300ef Blue Swirl
3553 54623277 Blue Swirl
/* mcrf */
3554 99e300ef Blue Swirl
static void gen_mcrf(DisasContext *ctx)
3555 79aceca5 bellard
{
3556 47e4661c aurel32
    tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]);
3557 79aceca5 bellard
}
3558 79aceca5 bellard
3559 79aceca5 bellard
/***                           System linkage                              ***/
3560 99e300ef Blue Swirl
3561 54623277 Blue Swirl
/* rfi (mem_idx only) */
3562 99e300ef Blue Swirl
static void gen_rfi(DisasContext *ctx)
3563 79aceca5 bellard
{
3564 9a64fbe4 bellard
#if defined(CONFIG_USER_ONLY)
3565 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
3566 9a64fbe4 bellard
#else
3567 9a64fbe4 bellard
    /* Restore CPU state */
3568 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
3569 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
3570 9fddaa0c bellard
        return;
3571 9a64fbe4 bellard
    }
3572 d72a19f7 aurel32
    gen_helper_rfi();
3573 e06fcd75 aurel32
    gen_sync_exception(ctx);
3574 9a64fbe4 bellard
#endif
3575 79aceca5 bellard
}
3576 79aceca5 bellard
3577 426613db j_mayer
#if defined(TARGET_PPC64)
3578 99e300ef Blue Swirl
static void gen_rfid(DisasContext *ctx)
3579 426613db j_mayer
{
3580 426613db j_mayer
#if defined(CONFIG_USER_ONLY)
3581 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
3582 426613db j_mayer
#else
3583 426613db j_mayer
    /* Restore CPU state */
3584 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
3585 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
3586 426613db j_mayer
        return;
3587 426613db j_mayer
    }
3588 d72a19f7 aurel32
    gen_helper_rfid();
3589 e06fcd75 aurel32
    gen_sync_exception(ctx);
3590 426613db j_mayer
#endif
3591 426613db j_mayer
}
3592 426613db j_mayer
3593 99e300ef Blue Swirl
static void gen_hrfid(DisasContext *ctx)
3594 be147d08 j_mayer
{
3595 be147d08 j_mayer
#if defined(CONFIG_USER_ONLY)
3596 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
3597 be147d08 j_mayer
#else
3598 be147d08 j_mayer
    /* Restore CPU state */
3599 76db3ba4 aurel32
    if (unlikely(ctx->mem_idx <= 1)) {
3600 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
3601 be147d08 j_mayer
        return;
3602 be147d08 j_mayer
    }
3603 d72a19f7 aurel32
    gen_helper_hrfid();
3604 e06fcd75 aurel32
    gen_sync_exception(ctx);
3605 be147d08 j_mayer
#endif
3606 be147d08 j_mayer
}
3607 be147d08 j_mayer
#endif
3608 be147d08 j_mayer
3609 79aceca5 bellard
/* sc */
3610 417bf010 j_mayer
#if defined(CONFIG_USER_ONLY)
3611 417bf010 j_mayer
#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3612 417bf010 j_mayer
#else
3613 417bf010 j_mayer
#define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3614 417bf010 j_mayer
#endif
3615 99e300ef Blue Swirl
static void gen_sc(DisasContext *ctx)
3616 79aceca5 bellard
{
3617 e1833e1f j_mayer
    uint32_t lev;
3618 e1833e1f j_mayer
3619 e1833e1f j_mayer
    lev = (ctx->opcode >> 5) & 0x7F;
3620 e06fcd75 aurel32
    gen_exception_err(ctx, POWERPC_SYSCALL, lev);
3621 79aceca5 bellard
}
3622 79aceca5 bellard
3623 79aceca5 bellard
/***                                Trap                                   ***/
3624 99e300ef Blue Swirl
3625 54623277 Blue Swirl
/* tw */
3626 99e300ef Blue Swirl
static void gen_tw(DisasContext *ctx)
3627 79aceca5 bellard
{
3628 cab3bee2 aurel32
    TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
3629 db9a231d Aurelien Jarno
    /* Update the nip since this might generate a trap exception */
3630 db9a231d Aurelien Jarno
    gen_update_nip(ctx, ctx->nip);
3631 cab3bee2 aurel32
    gen_helper_tw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0);
3632 cab3bee2 aurel32
    tcg_temp_free_i32(t0);
3633 79aceca5 bellard
}
3634 79aceca5 bellard
3635 79aceca5 bellard
/* twi */
3636 99e300ef Blue Swirl
static void gen_twi(DisasContext *ctx)
3637 79aceca5 bellard
{
3638 cab3bee2 aurel32
    TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
3639 cab3bee2 aurel32
    TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
3640 db9a231d Aurelien Jarno
    /* Update the nip since this might generate a trap exception */
3641 db9a231d Aurelien Jarno
    gen_update_nip(ctx, ctx->nip);
3642 cab3bee2 aurel32
    gen_helper_tw(cpu_gpr[rA(ctx->opcode)], t0, t1);
3643 cab3bee2 aurel32
    tcg_temp_free(t0);
3644 cab3bee2 aurel32
    tcg_temp_free_i32(t1);
3645 79aceca5 bellard
}
3646 79aceca5 bellard
3647 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
3648 d9bce9d9 j_mayer
/* td */
3649 99e300ef Blue Swirl
static void gen_td(DisasContext *ctx)
3650 d9bce9d9 j_mayer
{
3651 cab3bee2 aurel32
    TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode));
3652 db9a231d Aurelien Jarno
    /* Update the nip since this might generate a trap exception */
3653 db9a231d Aurelien Jarno
    gen_update_nip(ctx, ctx->nip);
3654 cab3bee2 aurel32
    gen_helper_td(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0);
3655 cab3bee2 aurel32
    tcg_temp_free_i32(t0);
3656 d9bce9d9 j_mayer
}
3657 d9bce9d9 j_mayer
3658 d9bce9d9 j_mayer
/* tdi */
3659 99e300ef Blue Swirl
static void gen_tdi(DisasContext *ctx)
3660 d9bce9d9 j_mayer
{
3661 cab3bee2 aurel32
    TCGv t0 = tcg_const_tl(SIMM(ctx->opcode));
3662 cab3bee2 aurel32
    TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode));
3663 db9a231d Aurelien Jarno
    /* Update the nip since this might generate a trap exception */
3664 db9a231d Aurelien Jarno
    gen_update_nip(ctx, ctx->nip);
3665 cab3bee2 aurel32
    gen_helper_td(cpu_gpr[rA(ctx->opcode)], t0, t1);
3666 cab3bee2 aurel32
    tcg_temp_free(t0);
3667 cab3bee2 aurel32
    tcg_temp_free_i32(t1);
3668 d9bce9d9 j_mayer
}
3669 d9bce9d9 j_mayer
#endif
3670 d9bce9d9 j_mayer
3671 79aceca5 bellard
/***                          Processor control                            ***/
3672 99e300ef Blue Swirl
3673 54623277 Blue Swirl
/* mcrxr */
3674 99e300ef Blue Swirl
static void gen_mcrxr(DisasContext *ctx)
3675 79aceca5 bellard
{
3676 3d7b417e aurel32
    tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], cpu_xer);
3677 3d7b417e aurel32
    tcg_gen_shri_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], XER_CA);
3678 269f3e95 aurel32
    tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_SO | 1 << XER_OV | 1 << XER_CA));
3679 79aceca5 bellard
}
3680 79aceca5 bellard
3681 0cfe11ea aurel32
/* mfcr mfocrf */
3682 99e300ef Blue Swirl
static void gen_mfcr(DisasContext *ctx)
3683 79aceca5 bellard
{
3684 76a66253 j_mayer
    uint32_t crm, crn;
3685 3b46e624 ths
3686 76a66253 j_mayer
    if (likely(ctx->opcode & 0x00100000)) {
3687 76a66253 j_mayer
        crm = CRM(ctx->opcode);
3688 8dd640e4 malc
        if (likely(crm && ((crm & (crm - 1)) == 0))) {
3689 0cfe11ea aurel32
            crn = ctz32 (crm);
3690 e1571908 aurel32
            tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]);
3691 0497d2f4 aurel32
            tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)],
3692 0497d2f4 aurel32
                            cpu_gpr[rD(ctx->opcode)], crn * 4);
3693 76a66253 j_mayer
        }
3694 d9bce9d9 j_mayer
    } else {
3695 651721b2 aurel32
        TCGv_i32 t0 = tcg_temp_new_i32();
3696 651721b2 aurel32
        tcg_gen_mov_i32(t0, cpu_crf[0]);
3697 651721b2 aurel32
        tcg_gen_shli_i32(t0, t0, 4);
3698 651721b2 aurel32
        tcg_gen_or_i32(t0, t0, cpu_crf[1]);
3699 651721b2 aurel32
        tcg_gen_shli_i32(t0, t0, 4);
3700 651721b2 aurel32
        tcg_gen_or_i32(t0, t0, cpu_crf[2]);
3701 651721b2 aurel32
        tcg_gen_shli_i32(t0, t0, 4);
3702 651721b2 aurel32
        tcg_gen_or_i32(t0, t0, cpu_crf[3]);
3703 651721b2 aurel32
        tcg_gen_shli_i32(t0, t0, 4);
3704 651721b2 aurel32
        tcg_gen_or_i32(t0, t0, cpu_crf[4]);
3705 651721b2 aurel32
        tcg_gen_shli_i32(t0, t0, 4);
3706 651721b2 aurel32
        tcg_gen_or_i32(t0, t0, cpu_crf[5]);
3707 651721b2 aurel32
        tcg_gen_shli_i32(t0, t0, 4);
3708 651721b2 aurel32
        tcg_gen_or_i32(t0, t0, cpu_crf[6]);
3709 651721b2 aurel32
        tcg_gen_shli_i32(t0, t0, 4);
3710 651721b2 aurel32
        tcg_gen_or_i32(t0, t0, cpu_crf[7]);
3711 651721b2 aurel32
        tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0);
3712 651721b2 aurel32
        tcg_temp_free_i32(t0);
3713 d9bce9d9 j_mayer
    }
3714 79aceca5 bellard
}
3715 79aceca5 bellard
3716 79aceca5 bellard
/* mfmsr */
3717 99e300ef Blue Swirl
static void gen_mfmsr(DisasContext *ctx)
3718 79aceca5 bellard
{
3719 9a64fbe4 bellard
#if defined(CONFIG_USER_ONLY)
3720 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
3721 9a64fbe4 bellard
#else
3722 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
3723 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
3724 9fddaa0c bellard
        return;
3725 9a64fbe4 bellard
    }
3726 6527f6ea aurel32
    tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr);
3727 9a64fbe4 bellard
#endif
3728 79aceca5 bellard
}
3729 79aceca5 bellard
3730 7b13448f Blue Swirl
static void spr_noaccess(void *opaque, int gprn, int sprn)
3731 3fc6c082 bellard
{
3732 7b13448f Blue Swirl
#if 0
3733 3fc6c082 bellard
    sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
3734 3fc6c082 bellard
    printf("ERROR: try to access SPR %d !\n", sprn);
3735 7b13448f Blue Swirl
#endif
3736 3fc6c082 bellard
}
3737 3fc6c082 bellard
#define SPR_NOACCESS (&spr_noaccess)
3738 3fc6c082 bellard
3739 79aceca5 bellard
/* mfspr */
3740 636aa200 Blue Swirl
static inline void gen_op_mfspr(DisasContext *ctx)
3741 79aceca5 bellard
{
3742 45d827d2 aurel32
    void (*read_cb)(void *opaque, int gprn, int sprn);
3743 79aceca5 bellard
    uint32_t sprn = SPR(ctx->opcode);
3744 79aceca5 bellard
3745 3fc6c082 bellard
#if !defined(CONFIG_USER_ONLY)
3746 76db3ba4 aurel32
    if (ctx->mem_idx == 2)
3747 be147d08 j_mayer
        read_cb = ctx->spr_cb[sprn].hea_read;
3748 76db3ba4 aurel32
    else if (ctx->mem_idx)
3749 3fc6c082 bellard
        read_cb = ctx->spr_cb[sprn].oea_read;
3750 3fc6c082 bellard
    else
3751 9a64fbe4 bellard
#endif
3752 3fc6c082 bellard
        read_cb = ctx->spr_cb[sprn].uea_read;
3753 76a66253 j_mayer
    if (likely(read_cb != NULL)) {
3754 76a66253 j_mayer
        if (likely(read_cb != SPR_NOACCESS)) {
3755 45d827d2 aurel32
            (*read_cb)(ctx, rD(ctx->opcode), sprn);
3756 3fc6c082 bellard
        } else {
3757 3fc6c082 bellard
            /* Privilege exception */
3758 9fceefa7 j_mayer
            /* This is a hack to avoid warnings when running Linux:
3759 9fceefa7 j_mayer
             * this OS breaks the PowerPC virtualisation model,
3760 9fceefa7 j_mayer
             * allowing userland application to read the PVR
3761 9fceefa7 j_mayer
             */
3762 9fceefa7 j_mayer
            if (sprn != SPR_PVR) {
3763 93fcfe39 aliguori
                qemu_log("Trying to read privileged spr %d %03x at "
3764 90e189ec Blue Swirl
                         TARGET_FMT_lx "\n", sprn, sprn, ctx->nip);
3765 90e189ec Blue Swirl
                printf("Trying to read privileged spr %d %03x at "
3766 90e189ec Blue Swirl
                       TARGET_FMT_lx "\n", sprn, sprn, ctx->nip);
3767 f24e5695 bellard
            }
3768 e06fcd75 aurel32
            gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
3769 79aceca5 bellard
        }
3770 3fc6c082 bellard
    } else {
3771 3fc6c082 bellard
        /* Not defined */
3772 93fcfe39 aliguori
        qemu_log("Trying to read invalid spr %d %03x at "
3773 90e189ec Blue Swirl
                    TARGET_FMT_lx "\n", sprn, sprn, ctx->nip);
3774 90e189ec Blue Swirl
        printf("Trying to read invalid spr %d %03x at " TARGET_FMT_lx "\n",
3775 077fc206 j_mayer
               sprn, sprn, ctx->nip);
3776 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
3777 79aceca5 bellard
    }
3778 79aceca5 bellard
}
3779 79aceca5 bellard
3780 99e300ef Blue Swirl
static void gen_mfspr(DisasContext *ctx)
3781 79aceca5 bellard
{
3782 3fc6c082 bellard
    gen_op_mfspr(ctx);
3783 76a66253 j_mayer
}
3784 3fc6c082 bellard
3785 3fc6c082 bellard
/* mftb */
3786 99e300ef Blue Swirl
static void gen_mftb(DisasContext *ctx)
3787 3fc6c082 bellard
{
3788 3fc6c082 bellard
    gen_op_mfspr(ctx);
3789 79aceca5 bellard
}
3790 79aceca5 bellard
3791 0cfe11ea aurel32
/* mtcrf mtocrf*/
3792 99e300ef Blue Swirl
static void gen_mtcrf(DisasContext *ctx)
3793 79aceca5 bellard
{
3794 76a66253 j_mayer
    uint32_t crm, crn;
3795 3b46e624 ths
3796 76a66253 j_mayer
    crm = CRM(ctx->opcode);
3797 8dd640e4 malc
    if (likely((ctx->opcode & 0x00100000))) {
3798 8dd640e4 malc
        if (crm && ((crm & (crm - 1)) == 0)) {
3799 8dd640e4 malc
            TCGv_i32 temp = tcg_temp_new_i32();
3800 0cfe11ea aurel32
            crn = ctz32 (crm);
3801 8dd640e4 malc
            tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
3802 0cfe11ea aurel32
            tcg_gen_shri_i32(temp, temp, crn * 4);
3803 0cfe11ea aurel32
            tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf);
3804 8dd640e4 malc
            tcg_temp_free_i32(temp);
3805 8dd640e4 malc
        }
3806 76a66253 j_mayer
    } else {
3807 651721b2 aurel32
        TCGv_i32 temp = tcg_temp_new_i32();
3808 651721b2 aurel32
        tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]);
3809 651721b2 aurel32
        for (crn = 0 ; crn < 8 ; crn++) {
3810 651721b2 aurel32
            if (crm & (1 << crn)) {
3811 651721b2 aurel32
                    tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4);
3812 651721b2 aurel32
                    tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf);
3813 651721b2 aurel32
            }
3814 651721b2 aurel32
        }
3815 a7812ae4 pbrook
        tcg_temp_free_i32(temp);
3816 76a66253 j_mayer
    }
3817 79aceca5 bellard
}
3818 79aceca5 bellard
3819 79aceca5 bellard
/* mtmsr */
3820 426613db j_mayer
#if defined(TARGET_PPC64)
3821 99e300ef Blue Swirl
static void gen_mtmsrd(DisasContext *ctx)
3822 426613db j_mayer
{
3823 426613db j_mayer
#if defined(CONFIG_USER_ONLY)
3824 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
3825 426613db j_mayer
#else
3826 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
3827 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
3828 426613db j_mayer
        return;
3829 426613db j_mayer
    }
3830 be147d08 j_mayer
    if (ctx->opcode & 0x00010000) {
3831 be147d08 j_mayer
        /* Special form that does not need any synchronisation */
3832 6527f6ea aurel32
        TCGv t0 = tcg_temp_new();
3833 6527f6ea aurel32
        tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
3834 6527f6ea aurel32
        tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
3835 6527f6ea aurel32
        tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
3836 6527f6ea aurel32
        tcg_temp_free(t0);
3837 be147d08 j_mayer
    } else {
3838 056b05f8 j_mayer
        /* XXX: we need to update nip before the store
3839 056b05f8 j_mayer
         *      if we enter power saving mode, we will exit the loop
3840 056b05f8 j_mayer
         *      directly from ppc_store_msr
3841 056b05f8 j_mayer
         */
3842 be147d08 j_mayer
        gen_update_nip(ctx, ctx->nip);
3843 6527f6ea aurel32
        gen_helper_store_msr(cpu_gpr[rS(ctx->opcode)]);
3844 be147d08 j_mayer
        /* Must stop the translation as machine state (may have) changed */
3845 be147d08 j_mayer
        /* Note that mtmsr is not always defined as context-synchronizing */
3846 e06fcd75 aurel32
        gen_stop_exception(ctx);
3847 be147d08 j_mayer
    }
3848 426613db j_mayer
#endif
3849 426613db j_mayer
}
3850 426613db j_mayer
#endif
3851 426613db j_mayer
3852 99e300ef Blue Swirl
static void gen_mtmsr(DisasContext *ctx)
3853 79aceca5 bellard
{
3854 9a64fbe4 bellard
#if defined(CONFIG_USER_ONLY)
3855 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
3856 9a64fbe4 bellard
#else
3857 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
3858 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
3859 9fddaa0c bellard
        return;
3860 9a64fbe4 bellard
    }
3861 be147d08 j_mayer
    if (ctx->opcode & 0x00010000) {
3862 be147d08 j_mayer
        /* Special form that does not need any synchronisation */
3863 6527f6ea aurel32
        TCGv t0 = tcg_temp_new();
3864 6527f6ea aurel32
        tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE));
3865 6527f6ea aurel32
        tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE)));
3866 6527f6ea aurel32
        tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
3867 6527f6ea aurel32
        tcg_temp_free(t0);
3868 be147d08 j_mayer
    } else {
3869 056b05f8 j_mayer
        /* XXX: we need to update nip before the store
3870 056b05f8 j_mayer
         *      if we enter power saving mode, we will exit the loop
3871 056b05f8 j_mayer
         *      directly from ppc_store_msr
3872 056b05f8 j_mayer
         */
3873 be147d08 j_mayer
        gen_update_nip(ctx, ctx->nip);
3874 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
3875 6527f6ea aurel32
        if (!ctx->sf_mode) {
3876 6527f6ea aurel32
            TCGv t0 = tcg_temp_new();
3877 6527f6ea aurel32
            TCGv t1 = tcg_temp_new();
3878 6527f6ea aurel32
            tcg_gen_andi_tl(t0, cpu_msr, 0xFFFFFFFF00000000ULL);
3879 6527f6ea aurel32
            tcg_gen_ext32u_tl(t1, cpu_gpr[rS(ctx->opcode)]);
3880 6527f6ea aurel32
            tcg_gen_or_tl(t0, t0, t1);
3881 6527f6ea aurel32
            tcg_temp_free(t1);
3882 6527f6ea aurel32
            gen_helper_store_msr(t0);
3883 6527f6ea aurel32
            tcg_temp_free(t0);
3884 6527f6ea aurel32
        } else
3885 d9bce9d9 j_mayer
#endif
3886 6527f6ea aurel32
            gen_helper_store_msr(cpu_gpr[rS(ctx->opcode)]);
3887 be147d08 j_mayer
        /* Must stop the translation as machine state (may have) changed */
3888 6527f6ea aurel32
        /* Note that mtmsr is not always defined as context-synchronizing */
3889 e06fcd75 aurel32
        gen_stop_exception(ctx);
3890 be147d08 j_mayer
    }
3891 9a64fbe4 bellard
#endif
3892 79aceca5 bellard
}
3893 79aceca5 bellard
3894 79aceca5 bellard
/* mtspr */
3895 99e300ef Blue Swirl
static void gen_mtspr(DisasContext *ctx)
3896 79aceca5 bellard
{
3897 45d827d2 aurel32
    void (*write_cb)(void *opaque, int sprn, int gprn);
3898 79aceca5 bellard
    uint32_t sprn = SPR(ctx->opcode);
3899 79aceca5 bellard
3900 3fc6c082 bellard
#if !defined(CONFIG_USER_ONLY)
3901 76db3ba4 aurel32
    if (ctx->mem_idx == 2)
3902 be147d08 j_mayer
        write_cb = ctx->spr_cb[sprn].hea_write;
3903 76db3ba4 aurel32
    else if (ctx->mem_idx)
3904 3fc6c082 bellard
        write_cb = ctx->spr_cb[sprn].oea_write;
3905 3fc6c082 bellard
    else
3906 9a64fbe4 bellard
#endif
3907 3fc6c082 bellard
        write_cb = ctx->spr_cb[sprn].uea_write;
3908 76a66253 j_mayer
    if (likely(write_cb != NULL)) {
3909 76a66253 j_mayer
        if (likely(write_cb != SPR_NOACCESS)) {
3910 45d827d2 aurel32
            (*write_cb)(ctx, sprn, rS(ctx->opcode));
3911 3fc6c082 bellard
        } else {
3912 3fc6c082 bellard
            /* Privilege exception */
3913 93fcfe39 aliguori
            qemu_log("Trying to write privileged spr %d %03x at "
3914 90e189ec Blue Swirl
                     TARGET_FMT_lx "\n", sprn, sprn, ctx->nip);
3915 90e189ec Blue Swirl
            printf("Trying to write privileged spr %d %03x at " TARGET_FMT_lx
3916 90e189ec Blue Swirl
                   "\n", sprn, sprn, ctx->nip);
3917 e06fcd75 aurel32
            gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
3918 76a66253 j_mayer
        }
3919 3fc6c082 bellard
    } else {
3920 3fc6c082 bellard
        /* Not defined */
3921 93fcfe39 aliguori
        qemu_log("Trying to write invalid spr %d %03x at "
3922 90e189ec Blue Swirl
                 TARGET_FMT_lx "\n", sprn, sprn, ctx->nip);
3923 90e189ec Blue Swirl
        printf("Trying to write invalid spr %d %03x at " TARGET_FMT_lx "\n",
3924 077fc206 j_mayer
               sprn, sprn, ctx->nip);
3925 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR);
3926 79aceca5 bellard
    }
3927 79aceca5 bellard
}
3928 79aceca5 bellard
3929 79aceca5 bellard
/***                         Cache management                              ***/
3930 99e300ef Blue Swirl
3931 54623277 Blue Swirl
/* dcbf */
3932 99e300ef Blue Swirl
static void gen_dcbf(DisasContext *ctx)
3933 79aceca5 bellard
{
3934 dac454af j_mayer
    /* XXX: specification says this is treated as a load by the MMU */
3935 76db3ba4 aurel32
    TCGv t0;
3936 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_CACHE);
3937 76db3ba4 aurel32
    t0 = tcg_temp_new();
3938 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
3939 76db3ba4 aurel32
    gen_qemu_ld8u(ctx, t0, t0);
3940 fea0c503 aurel32
    tcg_temp_free(t0);
3941 79aceca5 bellard
}
3942 79aceca5 bellard
3943 79aceca5 bellard
/* dcbi (Supervisor only) */
3944 99e300ef Blue Swirl
static void gen_dcbi(DisasContext *ctx)
3945 79aceca5 bellard
{
3946 a541f297 bellard
#if defined(CONFIG_USER_ONLY)
3947 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
3948 a541f297 bellard
#else
3949 b61f2753 aurel32
    TCGv EA, val;
3950 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
3951 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
3952 9fddaa0c bellard
        return;
3953 9a64fbe4 bellard
    }
3954 a7812ae4 pbrook
    EA = tcg_temp_new();
3955 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_CACHE);
3956 76db3ba4 aurel32
    gen_addr_reg_index(ctx, EA);
3957 a7812ae4 pbrook
    val = tcg_temp_new();
3958 76a66253 j_mayer
    /* XXX: specification says this should be treated as a store by the MMU */
3959 76db3ba4 aurel32
    gen_qemu_ld8u(ctx, val, EA);
3960 76db3ba4 aurel32
    gen_qemu_st8(ctx, val, EA);
3961 b61f2753 aurel32
    tcg_temp_free(val);
3962 b61f2753 aurel32
    tcg_temp_free(EA);
3963 a541f297 bellard
#endif
3964 79aceca5 bellard
}
3965 79aceca5 bellard
3966 79aceca5 bellard
/* dcdst */
3967 99e300ef Blue Swirl
static void gen_dcbst(DisasContext *ctx)
3968 79aceca5 bellard
{
3969 76a66253 j_mayer
    /* XXX: specification say this is treated as a load by the MMU */
3970 76db3ba4 aurel32
    TCGv t0;
3971 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_CACHE);
3972 76db3ba4 aurel32
    t0 = tcg_temp_new();
3973 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
3974 76db3ba4 aurel32
    gen_qemu_ld8u(ctx, t0, t0);
3975 fea0c503 aurel32
    tcg_temp_free(t0);
3976 79aceca5 bellard
}
3977 79aceca5 bellard
3978 79aceca5 bellard
/* dcbt */
3979 99e300ef Blue Swirl
static void gen_dcbt(DisasContext *ctx)
3980 79aceca5 bellard
{
3981 0db1b20e j_mayer
    /* interpreted as no-op */
3982 76a66253 j_mayer
    /* XXX: specification say this is treated as a load by the MMU
3983 76a66253 j_mayer
     *      but does not generate any exception
3984 76a66253 j_mayer
     */
3985 79aceca5 bellard
}
3986 79aceca5 bellard
3987 79aceca5 bellard
/* dcbtst */
3988 99e300ef Blue Swirl
static void gen_dcbtst(DisasContext *ctx)
3989 79aceca5 bellard
{
3990 0db1b20e j_mayer
    /* interpreted as no-op */
3991 76a66253 j_mayer
    /* XXX: specification say this is treated as a load by the MMU
3992 76a66253 j_mayer
     *      but does not generate any exception
3993 76a66253 j_mayer
     */
3994 79aceca5 bellard
}
3995 79aceca5 bellard
3996 79aceca5 bellard
/* dcbz */
3997 99e300ef Blue Swirl
static void gen_dcbz(DisasContext *ctx)
3998 79aceca5 bellard
{
3999 76db3ba4 aurel32
    TCGv t0;
4000 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_CACHE);
4001 799a8c8d aurel32
    /* NIP cannot be restored if the memory exception comes from an helper */
4002 799a8c8d aurel32
    gen_update_nip(ctx, ctx->nip - 4);
4003 76db3ba4 aurel32
    t0 = tcg_temp_new();
4004 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
4005 799a8c8d aurel32
    gen_helper_dcbz(t0);
4006 799a8c8d aurel32
    tcg_temp_free(t0);
4007 d63001d1 j_mayer
}
4008 d63001d1 j_mayer
4009 e8eaa2c0 Blue Swirl
static void gen_dcbz_970(DisasContext *ctx)
4010 d63001d1 j_mayer
{
4011 76db3ba4 aurel32
    TCGv t0;
4012 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_CACHE);
4013 799a8c8d aurel32
    /* NIP cannot be restored if the memory exception comes from an helper */
4014 799a8c8d aurel32
    gen_update_nip(ctx, ctx->nip - 4);
4015 76db3ba4 aurel32
    t0 = tcg_temp_new();
4016 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
4017 d63001d1 j_mayer
    if (ctx->opcode & 0x00200000)
4018 799a8c8d aurel32
        gen_helper_dcbz(t0);
4019 d63001d1 j_mayer
    else
4020 799a8c8d aurel32
        gen_helper_dcbz_970(t0);
4021 799a8c8d aurel32
    tcg_temp_free(t0);
4022 79aceca5 bellard
}
4023 79aceca5 bellard
4024 ae1c1a3d aurel32
/* dst / dstt */
4025 99e300ef Blue Swirl
static void gen_dst(DisasContext *ctx)
4026 ae1c1a3d aurel32
{
4027 ae1c1a3d aurel32
    if (rA(ctx->opcode) == 0) {
4028 ae1c1a3d aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4029 ae1c1a3d aurel32
    } else {
4030 ae1c1a3d aurel32
        /* interpreted as no-op */
4031 ae1c1a3d aurel32
    }
4032 ae1c1a3d aurel32
}
4033 ae1c1a3d aurel32
4034 ae1c1a3d aurel32
/* dstst /dststt */
4035 99e300ef Blue Swirl
static void gen_dstst(DisasContext *ctx)
4036 ae1c1a3d aurel32
{
4037 ae1c1a3d aurel32
    if (rA(ctx->opcode) == 0) {
4038 ae1c1a3d aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX);
4039 ae1c1a3d aurel32
    } else {
4040 ae1c1a3d aurel32
        /* interpreted as no-op */
4041 ae1c1a3d aurel32
    }
4042 ae1c1a3d aurel32
4043 ae1c1a3d aurel32
}
4044 ae1c1a3d aurel32
4045 ae1c1a3d aurel32
/* dss / dssall */
4046 99e300ef Blue Swirl
static void gen_dss(DisasContext *ctx)
4047 ae1c1a3d aurel32
{
4048 ae1c1a3d aurel32
    /* interpreted as no-op */
4049 ae1c1a3d aurel32
}
4050 ae1c1a3d aurel32
4051 79aceca5 bellard
/* icbi */
4052 99e300ef Blue Swirl
static void gen_icbi(DisasContext *ctx)
4053 79aceca5 bellard
{
4054 76db3ba4 aurel32
    TCGv t0;
4055 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_CACHE);
4056 30032c94 j_mayer
    /* NIP cannot be restored if the memory exception comes from an helper */
4057 30032c94 j_mayer
    gen_update_nip(ctx, ctx->nip - 4);
4058 76db3ba4 aurel32
    t0 = tcg_temp_new();
4059 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
4060 37d269df aurel32
    gen_helper_icbi(t0);
4061 37d269df aurel32
    tcg_temp_free(t0);
4062 79aceca5 bellard
}
4063 79aceca5 bellard
4064 79aceca5 bellard
/* Optional: */
4065 79aceca5 bellard
/* dcba */
4066 99e300ef Blue Swirl
static void gen_dcba(DisasContext *ctx)
4067 79aceca5 bellard
{
4068 0db1b20e j_mayer
    /* interpreted as no-op */
4069 0db1b20e j_mayer
    /* XXX: specification say this is treated as a store by the MMU
4070 0db1b20e j_mayer
     *      but does not generate any exception
4071 0db1b20e j_mayer
     */
4072 79aceca5 bellard
}
4073 79aceca5 bellard
4074 79aceca5 bellard
/***                    Segment register manipulation                      ***/
4075 79aceca5 bellard
/* Supervisor only: */
4076 99e300ef Blue Swirl
4077 54623277 Blue Swirl
/* mfsr */
4078 99e300ef Blue Swirl
static void gen_mfsr(DisasContext *ctx)
4079 79aceca5 bellard
{
4080 9a64fbe4 bellard
#if defined(CONFIG_USER_ONLY)
4081 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4082 9a64fbe4 bellard
#else
4083 74d37793 aurel32
    TCGv t0;
4084 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
4085 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4086 9fddaa0c bellard
        return;
4087 9a64fbe4 bellard
    }
4088 74d37793 aurel32
    t0 = tcg_const_tl(SR(ctx->opcode));
4089 74d37793 aurel32
    gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], t0);
4090 74d37793 aurel32
    tcg_temp_free(t0);
4091 9a64fbe4 bellard
#endif
4092 79aceca5 bellard
}
4093 79aceca5 bellard
4094 79aceca5 bellard
/* mfsrin */
4095 99e300ef Blue Swirl
static void gen_mfsrin(DisasContext *ctx)
4096 79aceca5 bellard
{
4097 9a64fbe4 bellard
#if defined(CONFIG_USER_ONLY)
4098 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4099 9a64fbe4 bellard
#else
4100 74d37793 aurel32
    TCGv t0;
4101 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
4102 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4103 9fddaa0c bellard
        return;
4104 9a64fbe4 bellard
    }
4105 74d37793 aurel32
    t0 = tcg_temp_new();
4106 74d37793 aurel32
    tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4107 74d37793 aurel32
    tcg_gen_andi_tl(t0, t0, 0xF);
4108 74d37793 aurel32
    gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], t0);
4109 74d37793 aurel32
    tcg_temp_free(t0);
4110 9a64fbe4 bellard
#endif
4111 79aceca5 bellard
}
4112 79aceca5 bellard
4113 79aceca5 bellard
/* mtsr */
4114 99e300ef Blue Swirl
static void gen_mtsr(DisasContext *ctx)
4115 79aceca5 bellard
{
4116 9a64fbe4 bellard
#if defined(CONFIG_USER_ONLY)
4117 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4118 9a64fbe4 bellard
#else
4119 74d37793 aurel32
    TCGv t0;
4120 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
4121 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4122 9fddaa0c bellard
        return;
4123 9a64fbe4 bellard
    }
4124 74d37793 aurel32
    t0 = tcg_const_tl(SR(ctx->opcode));
4125 74d37793 aurel32
    gen_helper_store_sr(t0, cpu_gpr[rS(ctx->opcode)]);
4126 74d37793 aurel32
    tcg_temp_free(t0);
4127 9a64fbe4 bellard
#endif
4128 79aceca5 bellard
}
4129 79aceca5 bellard
4130 79aceca5 bellard
/* mtsrin */
4131 99e300ef Blue Swirl
static void gen_mtsrin(DisasContext *ctx)
4132 79aceca5 bellard
{
4133 9a64fbe4 bellard
#if defined(CONFIG_USER_ONLY)
4134 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4135 9a64fbe4 bellard
#else
4136 74d37793 aurel32
    TCGv t0;
4137 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
4138 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4139 9fddaa0c bellard
        return;
4140 9a64fbe4 bellard
    }
4141 74d37793 aurel32
    t0 = tcg_temp_new();
4142 74d37793 aurel32
    tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4143 74d37793 aurel32
    tcg_gen_andi_tl(t0, t0, 0xF);
4144 74d37793 aurel32
    gen_helper_store_sr(t0, cpu_gpr[rD(ctx->opcode)]);
4145 74d37793 aurel32
    tcg_temp_free(t0);
4146 9a64fbe4 bellard
#endif
4147 79aceca5 bellard
}
4148 79aceca5 bellard
4149 12de9a39 j_mayer
#if defined(TARGET_PPC64)
4150 12de9a39 j_mayer
/* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4151 e8eaa2c0 Blue Swirl
4152 54623277 Blue Swirl
/* mfsr */
4153 e8eaa2c0 Blue Swirl
static void gen_mfsr_64b(DisasContext *ctx)
4154 12de9a39 j_mayer
{
4155 12de9a39 j_mayer
#if defined(CONFIG_USER_ONLY)
4156 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4157 12de9a39 j_mayer
#else
4158 74d37793 aurel32
    TCGv t0;
4159 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
4160 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4161 12de9a39 j_mayer
        return;
4162 12de9a39 j_mayer
    }
4163 74d37793 aurel32
    t0 = tcg_const_tl(SR(ctx->opcode));
4164 f6b868fc blueswir1
    gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], t0);
4165 74d37793 aurel32
    tcg_temp_free(t0);
4166 12de9a39 j_mayer
#endif
4167 12de9a39 j_mayer
}
4168 12de9a39 j_mayer
4169 12de9a39 j_mayer
/* mfsrin */
4170 e8eaa2c0 Blue Swirl
static void gen_mfsrin_64b(DisasContext *ctx)
4171 12de9a39 j_mayer
{
4172 12de9a39 j_mayer
#if defined(CONFIG_USER_ONLY)
4173 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4174 12de9a39 j_mayer
#else
4175 74d37793 aurel32
    TCGv t0;
4176 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
4177 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4178 12de9a39 j_mayer
        return;
4179 12de9a39 j_mayer
    }
4180 74d37793 aurel32
    t0 = tcg_temp_new();
4181 74d37793 aurel32
    tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4182 74d37793 aurel32
    tcg_gen_andi_tl(t0, t0, 0xF);
4183 f6b868fc blueswir1
    gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], t0);
4184 74d37793 aurel32
    tcg_temp_free(t0);
4185 12de9a39 j_mayer
#endif
4186 12de9a39 j_mayer
}
4187 12de9a39 j_mayer
4188 12de9a39 j_mayer
/* mtsr */
4189 e8eaa2c0 Blue Swirl
static void gen_mtsr_64b(DisasContext *ctx)
4190 12de9a39 j_mayer
{
4191 12de9a39 j_mayer
#if defined(CONFIG_USER_ONLY)
4192 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4193 12de9a39 j_mayer
#else
4194 74d37793 aurel32
    TCGv t0;
4195 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
4196 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4197 12de9a39 j_mayer
        return;
4198 12de9a39 j_mayer
    }
4199 74d37793 aurel32
    t0 = tcg_const_tl(SR(ctx->opcode));
4200 f6b868fc blueswir1
    gen_helper_store_sr(t0, cpu_gpr[rS(ctx->opcode)]);
4201 74d37793 aurel32
    tcg_temp_free(t0);
4202 12de9a39 j_mayer
#endif
4203 12de9a39 j_mayer
}
4204 12de9a39 j_mayer
4205 12de9a39 j_mayer
/* mtsrin */
4206 e8eaa2c0 Blue Swirl
static void gen_mtsrin_64b(DisasContext *ctx)
4207 12de9a39 j_mayer
{
4208 12de9a39 j_mayer
#if defined(CONFIG_USER_ONLY)
4209 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4210 12de9a39 j_mayer
#else
4211 74d37793 aurel32
    TCGv t0;
4212 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
4213 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4214 12de9a39 j_mayer
        return;
4215 12de9a39 j_mayer
    }
4216 74d37793 aurel32
    t0 = tcg_temp_new();
4217 74d37793 aurel32
    tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28);
4218 74d37793 aurel32
    tcg_gen_andi_tl(t0, t0, 0xF);
4219 f6b868fc blueswir1
    gen_helper_store_sr(t0, cpu_gpr[rS(ctx->opcode)]);
4220 74d37793 aurel32
    tcg_temp_free(t0);
4221 12de9a39 j_mayer
#endif
4222 12de9a39 j_mayer
}
4223 f6b868fc blueswir1
4224 f6b868fc blueswir1
/* slbmte */
4225 e8eaa2c0 Blue Swirl
static void gen_slbmte(DisasContext *ctx)
4226 f6b868fc blueswir1
{
4227 f6b868fc blueswir1
#if defined(CONFIG_USER_ONLY)
4228 f6b868fc blueswir1
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4229 f6b868fc blueswir1
#else
4230 f6b868fc blueswir1
    if (unlikely(!ctx->mem_idx)) {
4231 f6b868fc blueswir1
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4232 f6b868fc blueswir1
        return;
4233 f6b868fc blueswir1
    }
4234 f6b868fc blueswir1
    gen_helper_store_slb(cpu_gpr[rB(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
4235 f6b868fc blueswir1
#endif
4236 f6b868fc blueswir1
}
4237 f6b868fc blueswir1
4238 efdef95f David Gibson
static void gen_slbmfee(DisasContext *ctx)
4239 efdef95f David Gibson
{
4240 efdef95f David Gibson
#if defined(CONFIG_USER_ONLY)
4241 efdef95f David Gibson
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4242 efdef95f David Gibson
#else
4243 efdef95f David Gibson
    if (unlikely(!ctx->mem_idx)) {
4244 efdef95f David Gibson
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4245 efdef95f David Gibson
        return;
4246 efdef95f David Gibson
    }
4247 efdef95f David Gibson
    gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)],
4248 efdef95f David Gibson
                             cpu_gpr[rB(ctx->opcode)]);
4249 efdef95f David Gibson
#endif
4250 efdef95f David Gibson
}
4251 efdef95f David Gibson
4252 efdef95f David Gibson
static void gen_slbmfev(DisasContext *ctx)
4253 efdef95f David Gibson
{
4254 efdef95f David Gibson
#if defined(CONFIG_USER_ONLY)
4255 efdef95f David Gibson
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4256 efdef95f David Gibson
#else
4257 efdef95f David Gibson
    if (unlikely(!ctx->mem_idx)) {
4258 efdef95f David Gibson
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
4259 efdef95f David Gibson
        return;
4260 efdef95f David Gibson
    }
4261 efdef95f David Gibson
    gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)],
4262 efdef95f David Gibson
                             cpu_gpr[rB(ctx->opcode)]);
4263 efdef95f David Gibson
#endif
4264 efdef95f David Gibson
}
4265 12de9a39 j_mayer
#endif /* defined(TARGET_PPC64) */
4266 12de9a39 j_mayer
4267 79aceca5 bellard
/***                      Lookaside buffer management                      ***/
4268 76db3ba4 aurel32
/* Optional & mem_idx only: */
4269 99e300ef Blue Swirl
4270 54623277 Blue Swirl
/* tlbia */
4271 99e300ef Blue Swirl
static void gen_tlbia(DisasContext *ctx)
4272 79aceca5 bellard
{
4273 9a64fbe4 bellard
#if defined(CONFIG_USER_ONLY)
4274 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4275 9a64fbe4 bellard
#else
4276 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
4277 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4278 9fddaa0c bellard
        return;
4279 9a64fbe4 bellard
    }
4280 74d37793 aurel32
    gen_helper_tlbia();
4281 9a64fbe4 bellard
#endif
4282 79aceca5 bellard
}
4283 79aceca5 bellard
4284 bf14b1ce blueswir1
/* tlbiel */
4285 99e300ef Blue Swirl
static void gen_tlbiel(DisasContext *ctx)
4286 bf14b1ce blueswir1
{
4287 bf14b1ce blueswir1
#if defined(CONFIG_USER_ONLY)
4288 bf14b1ce blueswir1
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4289 bf14b1ce blueswir1
#else
4290 bf14b1ce blueswir1
    if (unlikely(!ctx->mem_idx)) {
4291 bf14b1ce blueswir1
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4292 bf14b1ce blueswir1
        return;
4293 bf14b1ce blueswir1
    }
4294 bf14b1ce blueswir1
    gen_helper_tlbie(cpu_gpr[rB(ctx->opcode)]);
4295 bf14b1ce blueswir1
#endif
4296 bf14b1ce blueswir1
}
4297 bf14b1ce blueswir1
4298 79aceca5 bellard
/* tlbie */
4299 99e300ef Blue Swirl
static void gen_tlbie(DisasContext *ctx)
4300 79aceca5 bellard
{
4301 9a64fbe4 bellard
#if defined(CONFIG_USER_ONLY)
4302 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4303 9a64fbe4 bellard
#else
4304 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
4305 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4306 9fddaa0c bellard
        return;
4307 9a64fbe4 bellard
    }
4308 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
4309 74d37793 aurel32
    if (!ctx->sf_mode) {
4310 74d37793 aurel32
        TCGv t0 = tcg_temp_new();
4311 74d37793 aurel32
        tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
4312 74d37793 aurel32
        gen_helper_tlbie(t0);
4313 74d37793 aurel32
        tcg_temp_free(t0);
4314 74d37793 aurel32
    } else
4315 d9bce9d9 j_mayer
#endif
4316 74d37793 aurel32
        gen_helper_tlbie(cpu_gpr[rB(ctx->opcode)]);
4317 9a64fbe4 bellard
#endif
4318 79aceca5 bellard
}
4319 79aceca5 bellard
4320 79aceca5 bellard
/* tlbsync */
4321 99e300ef Blue Swirl
static void gen_tlbsync(DisasContext *ctx)
4322 79aceca5 bellard
{
4323 9a64fbe4 bellard
#if defined(CONFIG_USER_ONLY)
4324 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4325 9a64fbe4 bellard
#else
4326 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
4327 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4328 9fddaa0c bellard
        return;
4329 9a64fbe4 bellard
    }
4330 9a64fbe4 bellard
    /* This has no effect: it should ensure that all previous
4331 9a64fbe4 bellard
     * tlbie have completed
4332 9a64fbe4 bellard
     */
4333 e06fcd75 aurel32
    gen_stop_exception(ctx);
4334 9a64fbe4 bellard
#endif
4335 79aceca5 bellard
}
4336 79aceca5 bellard
4337 426613db j_mayer
#if defined(TARGET_PPC64)
4338 426613db j_mayer
/* slbia */
4339 99e300ef Blue Swirl
static void gen_slbia(DisasContext *ctx)
4340 426613db j_mayer
{
4341 426613db j_mayer
#if defined(CONFIG_USER_ONLY)
4342 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4343 426613db j_mayer
#else
4344 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
4345 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4346 426613db j_mayer
        return;
4347 426613db j_mayer
    }
4348 74d37793 aurel32
    gen_helper_slbia();
4349 426613db j_mayer
#endif
4350 426613db j_mayer
}
4351 426613db j_mayer
4352 426613db j_mayer
/* slbie */
4353 99e300ef Blue Swirl
static void gen_slbie(DisasContext *ctx)
4354 426613db j_mayer
{
4355 426613db j_mayer
#if defined(CONFIG_USER_ONLY)
4356 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4357 426613db j_mayer
#else
4358 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
4359 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
4360 426613db j_mayer
        return;
4361 426613db j_mayer
    }
4362 74d37793 aurel32
    gen_helper_slbie(cpu_gpr[rB(ctx->opcode)]);
4363 426613db j_mayer
#endif
4364 426613db j_mayer
}
4365 426613db j_mayer
#endif
4366 426613db j_mayer
4367 79aceca5 bellard
/***                              External control                         ***/
4368 79aceca5 bellard
/* Optional: */
4369 99e300ef Blue Swirl
4370 54623277 Blue Swirl
/* eciwx */
4371 99e300ef Blue Swirl
static void gen_eciwx(DisasContext *ctx)
4372 79aceca5 bellard
{
4373 76db3ba4 aurel32
    TCGv t0;
4374 fa407c03 aurel32
    /* Should check EAR[E] ! */
4375 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_EXT);
4376 76db3ba4 aurel32
    t0 = tcg_temp_new();
4377 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
4378 fa407c03 aurel32
    gen_check_align(ctx, t0, 0x03);
4379 76db3ba4 aurel32
    gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], t0);
4380 fa407c03 aurel32
    tcg_temp_free(t0);
4381 76a66253 j_mayer
}
4382 76a66253 j_mayer
4383 76a66253 j_mayer
/* ecowx */
4384 99e300ef Blue Swirl
static void gen_ecowx(DisasContext *ctx)
4385 76a66253 j_mayer
{
4386 76db3ba4 aurel32
    TCGv t0;
4387 fa407c03 aurel32
    /* Should check EAR[E] ! */
4388 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_EXT);
4389 76db3ba4 aurel32
    t0 = tcg_temp_new();
4390 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
4391 fa407c03 aurel32
    gen_check_align(ctx, t0, 0x03);
4392 76db3ba4 aurel32
    gen_qemu_st32(ctx, cpu_gpr[rD(ctx->opcode)], t0);
4393 fa407c03 aurel32
    tcg_temp_free(t0);
4394 76a66253 j_mayer
}
4395 76a66253 j_mayer
4396 76a66253 j_mayer
/* PowerPC 601 specific instructions */
4397 99e300ef Blue Swirl
4398 54623277 Blue Swirl
/* abs - abs. */
4399 99e300ef Blue Swirl
static void gen_abs(DisasContext *ctx)
4400 76a66253 j_mayer
{
4401 22e0e173 aurel32
    int l1 = gen_new_label();
4402 22e0e173 aurel32
    int l2 = gen_new_label();
4403 22e0e173 aurel32
    tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1);
4404 22e0e173 aurel32
    tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4405 22e0e173 aurel32
    tcg_gen_br(l2);
4406 22e0e173 aurel32
    gen_set_label(l1);
4407 22e0e173 aurel32
    tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4408 22e0e173 aurel32
    gen_set_label(l2);
4409 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4410 22e0e173 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4411 76a66253 j_mayer
}
4412 76a66253 j_mayer
4413 76a66253 j_mayer
/* abso - abso. */
4414 99e300ef Blue Swirl
static void gen_abso(DisasContext *ctx)
4415 76a66253 j_mayer
{
4416 22e0e173 aurel32
    int l1 = gen_new_label();
4417 22e0e173 aurel32
    int l2 = gen_new_label();
4418 22e0e173 aurel32
    int l3 = gen_new_label();
4419 22e0e173 aurel32
    /* Start with XER OV disabled, the most likely case */
4420 22e0e173 aurel32
    tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
4421 22e0e173 aurel32
    tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2);
4422 22e0e173 aurel32
    tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1);
4423 22e0e173 aurel32
    tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
4424 22e0e173 aurel32
    tcg_gen_br(l2);
4425 22e0e173 aurel32
    gen_set_label(l1);
4426 22e0e173 aurel32
    tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4427 22e0e173 aurel32
    tcg_gen_br(l3);
4428 22e0e173 aurel32
    gen_set_label(l2);
4429 22e0e173 aurel32
    tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4430 22e0e173 aurel32
    gen_set_label(l3);
4431 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4432 22e0e173 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4433 76a66253 j_mayer
}
4434 76a66253 j_mayer
4435 76a66253 j_mayer
/* clcs */
4436 99e300ef Blue Swirl
static void gen_clcs(DisasContext *ctx)
4437 76a66253 j_mayer
{
4438 22e0e173 aurel32
    TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode));
4439 22e0e173 aurel32
    gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], t0);
4440 22e0e173 aurel32
    tcg_temp_free_i32(t0);
4441 c7697e1f j_mayer
    /* Rc=1 sets CR0 to an undefined state */
4442 76a66253 j_mayer
}
4443 76a66253 j_mayer
4444 76a66253 j_mayer
/* div - div. */
4445 99e300ef Blue Swirl
static void gen_div(DisasContext *ctx)
4446 76a66253 j_mayer
{
4447 22e0e173 aurel32
    gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
4448 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4449 22e0e173 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4450 76a66253 j_mayer
}
4451 76a66253 j_mayer
4452 76a66253 j_mayer
/* divo - divo. */
4453 99e300ef Blue Swirl
static void gen_divo(DisasContext *ctx)
4454 76a66253 j_mayer
{
4455 22e0e173 aurel32
    gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
4456 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4457 22e0e173 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4458 76a66253 j_mayer
}
4459 76a66253 j_mayer
4460 76a66253 j_mayer
/* divs - divs. */
4461 99e300ef Blue Swirl
static void gen_divs(DisasContext *ctx)
4462 76a66253 j_mayer
{
4463 22e0e173 aurel32
    gen_helper_divs(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
4464 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4465 22e0e173 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4466 76a66253 j_mayer
}
4467 76a66253 j_mayer
4468 76a66253 j_mayer
/* divso - divso. */
4469 99e300ef Blue Swirl
static void gen_divso(DisasContext *ctx)
4470 76a66253 j_mayer
{
4471 22e0e173 aurel32
    gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
4472 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4473 22e0e173 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4474 76a66253 j_mayer
}
4475 76a66253 j_mayer
4476 76a66253 j_mayer
/* doz - doz. */
4477 99e300ef Blue Swirl
static void gen_doz(DisasContext *ctx)
4478 76a66253 j_mayer
{
4479 22e0e173 aurel32
    int l1 = gen_new_label();
4480 22e0e173 aurel32
    int l2 = gen_new_label();
4481 22e0e173 aurel32
    tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4482 22e0e173 aurel32
    tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4483 22e0e173 aurel32
    tcg_gen_br(l2);
4484 22e0e173 aurel32
    gen_set_label(l1);
4485 22e0e173 aurel32
    tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4486 22e0e173 aurel32
    gen_set_label(l2);
4487 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4488 22e0e173 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4489 76a66253 j_mayer
}
4490 76a66253 j_mayer
4491 76a66253 j_mayer
/* dozo - dozo. */
4492 99e300ef Blue Swirl
static void gen_dozo(DisasContext *ctx)
4493 76a66253 j_mayer
{
4494 22e0e173 aurel32
    int l1 = gen_new_label();
4495 22e0e173 aurel32
    int l2 = gen_new_label();
4496 22e0e173 aurel32
    TCGv t0 = tcg_temp_new();
4497 22e0e173 aurel32
    TCGv t1 = tcg_temp_new();
4498 22e0e173 aurel32
    TCGv t2 = tcg_temp_new();
4499 22e0e173 aurel32
    /* Start with XER OV disabled, the most likely case */
4500 22e0e173 aurel32
    tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
4501 22e0e173 aurel32
    tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1);
4502 22e0e173 aurel32
    tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4503 22e0e173 aurel32
    tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4504 22e0e173 aurel32
    tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0);
4505 22e0e173 aurel32
    tcg_gen_andc_tl(t1, t1, t2);
4506 22e0e173 aurel32
    tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
4507 22e0e173 aurel32
    tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
4508 22e0e173 aurel32
    tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
4509 22e0e173 aurel32
    tcg_gen_br(l2);
4510 22e0e173 aurel32
    gen_set_label(l1);
4511 22e0e173 aurel32
    tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4512 22e0e173 aurel32
    gen_set_label(l2);
4513 22e0e173 aurel32
    tcg_temp_free(t0);
4514 22e0e173 aurel32
    tcg_temp_free(t1);
4515 22e0e173 aurel32
    tcg_temp_free(t2);
4516 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4517 22e0e173 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4518 76a66253 j_mayer
}
4519 76a66253 j_mayer
4520 76a66253 j_mayer
/* dozi */
4521 99e300ef Blue Swirl
static void gen_dozi(DisasContext *ctx)
4522 76a66253 j_mayer
{
4523 22e0e173 aurel32
    target_long simm = SIMM(ctx->opcode);
4524 22e0e173 aurel32
    int l1 = gen_new_label();
4525 22e0e173 aurel32
    int l2 = gen_new_label();
4526 22e0e173 aurel32
    tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1);
4527 22e0e173 aurel32
    tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]);
4528 22e0e173 aurel32
    tcg_gen_br(l2);
4529 22e0e173 aurel32
    gen_set_label(l1);
4530 22e0e173 aurel32
    tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
4531 22e0e173 aurel32
    gen_set_label(l2);
4532 22e0e173 aurel32
    if (unlikely(Rc(ctx->opcode) != 0))
4533 22e0e173 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4534 76a66253 j_mayer
}
4535 76a66253 j_mayer
4536 76a66253 j_mayer
/* lscbx - lscbx. */
4537 99e300ef Blue Swirl
static void gen_lscbx(DisasContext *ctx)
4538 76a66253 j_mayer
{
4539 bdb4b689 aurel32
    TCGv t0 = tcg_temp_new();
4540 bdb4b689 aurel32
    TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode));
4541 bdb4b689 aurel32
    TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode));
4542 bdb4b689 aurel32
    TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode));
4543 76a66253 j_mayer
4544 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
4545 76a66253 j_mayer
    /* NIP cannot be restored if the memory exception comes from an helper */
4546 d9bce9d9 j_mayer
    gen_update_nip(ctx, ctx->nip - 4);
4547 bdb4b689 aurel32
    gen_helper_lscbx(t0, t0, t1, t2, t3);
4548 bdb4b689 aurel32
    tcg_temp_free_i32(t1);
4549 bdb4b689 aurel32
    tcg_temp_free_i32(t2);
4550 bdb4b689 aurel32
    tcg_temp_free_i32(t3);
4551 3d7b417e aurel32
    tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
4552 bdb4b689 aurel32
    tcg_gen_or_tl(cpu_xer, cpu_xer, t0);
4553 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4554 bdb4b689 aurel32
        gen_set_Rc0(ctx, t0);
4555 bdb4b689 aurel32
    tcg_temp_free(t0);
4556 76a66253 j_mayer
}
4557 76a66253 j_mayer
4558 76a66253 j_mayer
/* maskg - maskg. */
4559 99e300ef Blue Swirl
static void gen_maskg(DisasContext *ctx)
4560 76a66253 j_mayer
{
4561 22e0e173 aurel32
    int l1 = gen_new_label();
4562 22e0e173 aurel32
    TCGv t0 = tcg_temp_new();
4563 22e0e173 aurel32
    TCGv t1 = tcg_temp_new();
4564 22e0e173 aurel32
    TCGv t2 = tcg_temp_new();
4565 22e0e173 aurel32
    TCGv t3 = tcg_temp_new();
4566 22e0e173 aurel32
    tcg_gen_movi_tl(t3, 0xFFFFFFFF);
4567 22e0e173 aurel32
    tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4568 22e0e173 aurel32
    tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F);
4569 22e0e173 aurel32
    tcg_gen_addi_tl(t2, t0, 1);
4570 22e0e173 aurel32
    tcg_gen_shr_tl(t2, t3, t2);
4571 22e0e173 aurel32
    tcg_gen_shr_tl(t3, t3, t1);
4572 22e0e173 aurel32
    tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3);
4573 22e0e173 aurel32
    tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1);
4574 22e0e173 aurel32
    tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4575 22e0e173 aurel32
    gen_set_label(l1);
4576 22e0e173 aurel32
    tcg_temp_free(t0);
4577 22e0e173 aurel32
    tcg_temp_free(t1);
4578 22e0e173 aurel32
    tcg_temp_free(t2);
4579 22e0e173 aurel32
    tcg_temp_free(t3);
4580 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4581 22e0e173 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4582 76a66253 j_mayer
}
4583 76a66253 j_mayer
4584 76a66253 j_mayer
/* maskir - maskir. */
4585 99e300ef Blue Swirl
static void gen_maskir(DisasContext *ctx)
4586 76a66253 j_mayer
{
4587 22e0e173 aurel32
    TCGv t0 = tcg_temp_new();
4588 22e0e173 aurel32
    TCGv t1 = tcg_temp_new();
4589 22e0e173 aurel32
    tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
4590 22e0e173 aurel32
    tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
4591 22e0e173 aurel32
    tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4592 22e0e173 aurel32
    tcg_temp_free(t0);
4593 22e0e173 aurel32
    tcg_temp_free(t1);
4594 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4595 22e0e173 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4596 76a66253 j_mayer
}
4597 76a66253 j_mayer
4598 76a66253 j_mayer
/* mul - mul. */
4599 99e300ef Blue Swirl
static void gen_mul(DisasContext *ctx)
4600 76a66253 j_mayer
{
4601 22e0e173 aurel32
    TCGv_i64 t0 = tcg_temp_new_i64();
4602 22e0e173 aurel32
    TCGv_i64 t1 = tcg_temp_new_i64();
4603 22e0e173 aurel32
    TCGv t2 = tcg_temp_new();
4604 22e0e173 aurel32
    tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
4605 22e0e173 aurel32
    tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
4606 22e0e173 aurel32
    tcg_gen_mul_i64(t0, t0, t1);
4607 22e0e173 aurel32
    tcg_gen_trunc_i64_tl(t2, t0);
4608 22e0e173 aurel32
    gen_store_spr(SPR_MQ, t2);
4609 22e0e173 aurel32
    tcg_gen_shri_i64(t1, t0, 32);
4610 22e0e173 aurel32
    tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
4611 22e0e173 aurel32
    tcg_temp_free_i64(t0);
4612 22e0e173 aurel32
    tcg_temp_free_i64(t1);
4613 22e0e173 aurel32
    tcg_temp_free(t2);
4614 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4615 22e0e173 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4616 76a66253 j_mayer
}
4617 76a66253 j_mayer
4618 76a66253 j_mayer
/* mulo - mulo. */
4619 99e300ef Blue Swirl
static void gen_mulo(DisasContext *ctx)
4620 76a66253 j_mayer
{
4621 22e0e173 aurel32
    int l1 = gen_new_label();
4622 22e0e173 aurel32
    TCGv_i64 t0 = tcg_temp_new_i64();
4623 22e0e173 aurel32
    TCGv_i64 t1 = tcg_temp_new_i64();
4624 22e0e173 aurel32
    TCGv t2 = tcg_temp_new();
4625 22e0e173 aurel32
    /* Start with XER OV disabled, the most likely case */
4626 22e0e173 aurel32
    tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
4627 22e0e173 aurel32
    tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
4628 22e0e173 aurel32
    tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
4629 22e0e173 aurel32
    tcg_gen_mul_i64(t0, t0, t1);
4630 22e0e173 aurel32
    tcg_gen_trunc_i64_tl(t2, t0);
4631 22e0e173 aurel32
    gen_store_spr(SPR_MQ, t2);
4632 22e0e173 aurel32
    tcg_gen_shri_i64(t1, t0, 32);
4633 22e0e173 aurel32
    tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1);
4634 22e0e173 aurel32
    tcg_gen_ext32s_i64(t1, t0);
4635 22e0e173 aurel32
    tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1);
4636 22e0e173 aurel32
    tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
4637 22e0e173 aurel32
    gen_set_label(l1);
4638 22e0e173 aurel32
    tcg_temp_free_i64(t0);
4639 22e0e173 aurel32
    tcg_temp_free_i64(t1);
4640 22e0e173 aurel32
    tcg_temp_free(t2);
4641 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4642 22e0e173 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4643 76a66253 j_mayer
}
4644 76a66253 j_mayer
4645 76a66253 j_mayer
/* nabs - nabs. */
4646 99e300ef Blue Swirl
static void gen_nabs(DisasContext *ctx)
4647 76a66253 j_mayer
{
4648 22e0e173 aurel32
    int l1 = gen_new_label();
4649 22e0e173 aurel32
    int l2 = gen_new_label();
4650 22e0e173 aurel32
    tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
4651 22e0e173 aurel32
    tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4652 22e0e173 aurel32
    tcg_gen_br(l2);
4653 22e0e173 aurel32
    gen_set_label(l1);
4654 22e0e173 aurel32
    tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4655 22e0e173 aurel32
    gen_set_label(l2);
4656 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4657 22e0e173 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4658 76a66253 j_mayer
}
4659 76a66253 j_mayer
4660 76a66253 j_mayer
/* nabso - nabso. */
4661 99e300ef Blue Swirl
static void gen_nabso(DisasContext *ctx)
4662 76a66253 j_mayer
{
4663 22e0e173 aurel32
    int l1 = gen_new_label();
4664 22e0e173 aurel32
    int l2 = gen_new_label();
4665 22e0e173 aurel32
    tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1);
4666 22e0e173 aurel32
    tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4667 22e0e173 aurel32
    tcg_gen_br(l2);
4668 22e0e173 aurel32
    gen_set_label(l1);
4669 22e0e173 aurel32
    tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
4670 22e0e173 aurel32
    gen_set_label(l2);
4671 22e0e173 aurel32
    /* nabs never overflows */
4672 22e0e173 aurel32
    tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
4673 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4674 22e0e173 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
4675 76a66253 j_mayer
}
4676 76a66253 j_mayer
4677 76a66253 j_mayer
/* rlmi - rlmi. */
4678 99e300ef Blue Swirl
static void gen_rlmi(DisasContext *ctx)
4679 76a66253 j_mayer
{
4680 7487953d aurel32
    uint32_t mb = MB(ctx->opcode);
4681 7487953d aurel32
    uint32_t me = ME(ctx->opcode);
4682 7487953d aurel32
    TCGv t0 = tcg_temp_new();
4683 7487953d aurel32
    tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4684 7487953d aurel32
    tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
4685 7487953d aurel32
    tcg_gen_andi_tl(t0, t0, MASK(mb, me));
4686 7487953d aurel32
    tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me));
4687 7487953d aurel32
    tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0);
4688 7487953d aurel32
    tcg_temp_free(t0);
4689 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4690 7487953d aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4691 76a66253 j_mayer
}
4692 76a66253 j_mayer
4693 76a66253 j_mayer
/* rrib - rrib. */
4694 99e300ef Blue Swirl
static void gen_rrib(DisasContext *ctx)
4695 76a66253 j_mayer
{
4696 7487953d aurel32
    TCGv t0 = tcg_temp_new();
4697 7487953d aurel32
    TCGv t1 = tcg_temp_new();
4698 7487953d aurel32
    tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4699 7487953d aurel32
    tcg_gen_movi_tl(t1, 0x80000000);
4700 7487953d aurel32
    tcg_gen_shr_tl(t1, t1, t0);
4701 7487953d aurel32
    tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
4702 7487953d aurel32
    tcg_gen_and_tl(t0, t0, t1);
4703 7487953d aurel32
    tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1);
4704 7487953d aurel32
    tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4705 7487953d aurel32
    tcg_temp_free(t0);
4706 7487953d aurel32
    tcg_temp_free(t1);
4707 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4708 7487953d aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4709 76a66253 j_mayer
}
4710 76a66253 j_mayer
4711 76a66253 j_mayer
/* sle - sle. */
4712 99e300ef Blue Swirl
static void gen_sle(DisasContext *ctx)
4713 76a66253 j_mayer
{
4714 7487953d aurel32
    TCGv t0 = tcg_temp_new();
4715 7487953d aurel32
    TCGv t1 = tcg_temp_new();
4716 7487953d aurel32
    tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
4717 7487953d aurel32
    tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
4718 7487953d aurel32
    tcg_gen_subfi_tl(t1, 32, t1);
4719 7487953d aurel32
    tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
4720 7487953d aurel32
    tcg_gen_or_tl(t1, t0, t1);
4721 7487953d aurel32
    tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
4722 7487953d aurel32
    gen_store_spr(SPR_MQ, t1);
4723 7487953d aurel32
    tcg_temp_free(t0);
4724 7487953d aurel32
    tcg_temp_free(t1);
4725 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4726 7487953d aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4727 76a66253 j_mayer
}
4728 76a66253 j_mayer
4729 76a66253 j_mayer
/* sleq - sleq. */
4730 99e300ef Blue Swirl
static void gen_sleq(DisasContext *ctx)
4731 76a66253 j_mayer
{
4732 7487953d aurel32
    TCGv t0 = tcg_temp_new();
4733 7487953d aurel32
    TCGv t1 = tcg_temp_new();
4734 7487953d aurel32
    TCGv t2 = tcg_temp_new();
4735 7487953d aurel32
    tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4736 7487953d aurel32
    tcg_gen_movi_tl(t2, 0xFFFFFFFF);
4737 7487953d aurel32
    tcg_gen_shl_tl(t2, t2, t0);
4738 7487953d aurel32
    tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
4739 7487953d aurel32
    gen_load_spr(t1, SPR_MQ);
4740 7487953d aurel32
    gen_store_spr(SPR_MQ, t0);
4741 7487953d aurel32
    tcg_gen_and_tl(t0, t0, t2);
4742 7487953d aurel32
    tcg_gen_andc_tl(t1, t1, t2);
4743 7487953d aurel32
    tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4744 7487953d aurel32
    tcg_temp_free(t0);
4745 7487953d aurel32
    tcg_temp_free(t1);
4746 7487953d aurel32
    tcg_temp_free(t2);
4747 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4748 7487953d aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4749 76a66253 j_mayer
}
4750 76a66253 j_mayer
4751 76a66253 j_mayer
/* sliq - sliq. */
4752 99e300ef Blue Swirl
static void gen_sliq(DisasContext *ctx)
4753 76a66253 j_mayer
{
4754 7487953d aurel32
    int sh = SH(ctx->opcode);
4755 7487953d aurel32
    TCGv t0 = tcg_temp_new();
4756 7487953d aurel32
    TCGv t1 = tcg_temp_new();
4757 7487953d aurel32
    tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
4758 7487953d aurel32
    tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
4759 7487953d aurel32
    tcg_gen_or_tl(t1, t0, t1);
4760 7487953d aurel32
    tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
4761 7487953d aurel32
    gen_store_spr(SPR_MQ, t1);
4762 7487953d aurel32
    tcg_temp_free(t0);
4763 7487953d aurel32
    tcg_temp_free(t1);
4764 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4765 7487953d aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4766 76a66253 j_mayer
}
4767 76a66253 j_mayer
4768 76a66253 j_mayer
/* slliq - slliq. */
4769 99e300ef Blue Swirl
static void gen_slliq(DisasContext *ctx)
4770 76a66253 j_mayer
{
4771 7487953d aurel32
    int sh = SH(ctx->opcode);
4772 7487953d aurel32
    TCGv t0 = tcg_temp_new();
4773 7487953d aurel32
    TCGv t1 = tcg_temp_new();
4774 7487953d aurel32
    tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
4775 7487953d aurel32
    gen_load_spr(t1, SPR_MQ);
4776 7487953d aurel32
    gen_store_spr(SPR_MQ, t0);
4777 7487953d aurel32
    tcg_gen_andi_tl(t0, t0,  (0xFFFFFFFFU << sh));
4778 7487953d aurel32
    tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh));
4779 7487953d aurel32
    tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4780 7487953d aurel32
    tcg_temp_free(t0);
4781 7487953d aurel32
    tcg_temp_free(t1);
4782 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4783 7487953d aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4784 76a66253 j_mayer
}
4785 76a66253 j_mayer
4786 76a66253 j_mayer
/* sllq - sllq. */
4787 99e300ef Blue Swirl
static void gen_sllq(DisasContext *ctx)
4788 76a66253 j_mayer
{
4789 7487953d aurel32
    int l1 = gen_new_label();
4790 7487953d aurel32
    int l2 = gen_new_label();
4791 7487953d aurel32
    TCGv t0 = tcg_temp_local_new();
4792 7487953d aurel32
    TCGv t1 = tcg_temp_local_new();
4793 7487953d aurel32
    TCGv t2 = tcg_temp_local_new();
4794 7487953d aurel32
    tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
4795 7487953d aurel32
    tcg_gen_movi_tl(t1, 0xFFFFFFFF);
4796 7487953d aurel32
    tcg_gen_shl_tl(t1, t1, t2);
4797 7487953d aurel32
    tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
4798 7487953d aurel32
    tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
4799 7487953d aurel32
    gen_load_spr(t0, SPR_MQ);
4800 7487953d aurel32
    tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4801 7487953d aurel32
    tcg_gen_br(l2);
4802 7487953d aurel32
    gen_set_label(l1);
4803 7487953d aurel32
    tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
4804 7487953d aurel32
    gen_load_spr(t2, SPR_MQ);
4805 7487953d aurel32
    tcg_gen_andc_tl(t1, t2, t1);
4806 7487953d aurel32
    tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4807 7487953d aurel32
    gen_set_label(l2);
4808 7487953d aurel32
    tcg_temp_free(t0);
4809 7487953d aurel32
    tcg_temp_free(t1);
4810 7487953d aurel32
    tcg_temp_free(t2);
4811 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4812 7487953d aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4813 76a66253 j_mayer
}
4814 76a66253 j_mayer
4815 76a66253 j_mayer
/* slq - slq. */
4816 99e300ef Blue Swirl
static void gen_slq(DisasContext *ctx)
4817 76a66253 j_mayer
{
4818 7487953d aurel32
    int l1 = gen_new_label();
4819 7487953d aurel32
    TCGv t0 = tcg_temp_new();
4820 7487953d aurel32
    TCGv t1 = tcg_temp_new();
4821 7487953d aurel32
    tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
4822 7487953d aurel32
    tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
4823 7487953d aurel32
    tcg_gen_subfi_tl(t1, 32, t1);
4824 7487953d aurel32
    tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
4825 7487953d aurel32
    tcg_gen_or_tl(t1, t0, t1);
4826 7487953d aurel32
    gen_store_spr(SPR_MQ, t1);
4827 7487953d aurel32
    tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
4828 7487953d aurel32
    tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
4829 7487953d aurel32
    tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
4830 7487953d aurel32
    tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
4831 7487953d aurel32
    gen_set_label(l1);
4832 7487953d aurel32
    tcg_temp_free(t0);
4833 7487953d aurel32
    tcg_temp_free(t1);
4834 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4835 7487953d aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4836 76a66253 j_mayer
}
4837 76a66253 j_mayer
4838 d9bce9d9 j_mayer
/* sraiq - sraiq. */
4839 99e300ef Blue Swirl
static void gen_sraiq(DisasContext *ctx)
4840 76a66253 j_mayer
{
4841 7487953d aurel32
    int sh = SH(ctx->opcode);
4842 7487953d aurel32
    int l1 = gen_new_label();
4843 7487953d aurel32
    TCGv t0 = tcg_temp_new();
4844 7487953d aurel32
    TCGv t1 = tcg_temp_new();
4845 7487953d aurel32
    tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
4846 7487953d aurel32
    tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
4847 7487953d aurel32
    tcg_gen_or_tl(t0, t0, t1);
4848 7487953d aurel32
    gen_store_spr(SPR_MQ, t0);
4849 7487953d aurel32
    tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
4850 7487953d aurel32
    tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1);
4851 7487953d aurel32
    tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
4852 7487953d aurel32
    tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_CA));
4853 7487953d aurel32
    gen_set_label(l1);
4854 7487953d aurel32
    tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
4855 7487953d aurel32
    tcg_temp_free(t0);
4856 7487953d aurel32
    tcg_temp_free(t1);
4857 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4858 7487953d aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4859 76a66253 j_mayer
}
4860 76a66253 j_mayer
4861 76a66253 j_mayer
/* sraq - sraq. */
4862 99e300ef Blue Swirl
static void gen_sraq(DisasContext *ctx)
4863 76a66253 j_mayer
{
4864 7487953d aurel32
    int l1 = gen_new_label();
4865 7487953d aurel32
    int l2 = gen_new_label();
4866 7487953d aurel32
    TCGv t0 = tcg_temp_new();
4867 7487953d aurel32
    TCGv t1 = tcg_temp_local_new();
4868 7487953d aurel32
    TCGv t2 = tcg_temp_local_new();
4869 7487953d aurel32
    tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
4870 7487953d aurel32
    tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
4871 7487953d aurel32
    tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2);
4872 7487953d aurel32
    tcg_gen_subfi_tl(t2, 32, t2);
4873 7487953d aurel32
    tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2);
4874 7487953d aurel32
    tcg_gen_or_tl(t0, t0, t2);
4875 7487953d aurel32
    gen_store_spr(SPR_MQ, t0);
4876 7487953d aurel32
    tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
4877 7487953d aurel32
    tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1);
4878 7487953d aurel32
    tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]);
4879 7487953d aurel32
    tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31);
4880 7487953d aurel32
    gen_set_label(l1);
4881 7487953d aurel32
    tcg_temp_free(t0);
4882 7487953d aurel32
    tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1);
4883 7487953d aurel32
    tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
4884 7487953d aurel32
    tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2);
4885 7487953d aurel32
    tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2);
4886 7487953d aurel32
    tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_CA));
4887 7487953d aurel32
    gen_set_label(l2);
4888 7487953d aurel32
    tcg_temp_free(t1);
4889 7487953d aurel32
    tcg_temp_free(t2);
4890 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4891 7487953d aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4892 76a66253 j_mayer
}
4893 76a66253 j_mayer
4894 76a66253 j_mayer
/* sre - sre. */
4895 99e300ef Blue Swirl
static void gen_sre(DisasContext *ctx)
4896 76a66253 j_mayer
{
4897 7487953d aurel32
    TCGv t0 = tcg_temp_new();
4898 7487953d aurel32
    TCGv t1 = tcg_temp_new();
4899 7487953d aurel32
    tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
4900 7487953d aurel32
    tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
4901 7487953d aurel32
    tcg_gen_subfi_tl(t1, 32, t1);
4902 7487953d aurel32
    tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
4903 7487953d aurel32
    tcg_gen_or_tl(t1, t0, t1);
4904 7487953d aurel32
    tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
4905 7487953d aurel32
    gen_store_spr(SPR_MQ, t1);
4906 7487953d aurel32
    tcg_temp_free(t0);
4907 7487953d aurel32
    tcg_temp_free(t1);
4908 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4909 7487953d aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4910 76a66253 j_mayer
}
4911 76a66253 j_mayer
4912 76a66253 j_mayer
/* srea - srea. */
4913 99e300ef Blue Swirl
static void gen_srea(DisasContext *ctx)
4914 76a66253 j_mayer
{
4915 7487953d aurel32
    TCGv t0 = tcg_temp_new();
4916 7487953d aurel32
    TCGv t1 = tcg_temp_new();
4917 7487953d aurel32
    tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
4918 7487953d aurel32
    tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
4919 7487953d aurel32
    gen_store_spr(SPR_MQ, t0);
4920 7487953d aurel32
    tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1);
4921 7487953d aurel32
    tcg_temp_free(t0);
4922 7487953d aurel32
    tcg_temp_free(t1);
4923 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4924 7487953d aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4925 76a66253 j_mayer
}
4926 76a66253 j_mayer
4927 76a66253 j_mayer
/* sreq */
4928 99e300ef Blue Swirl
static void gen_sreq(DisasContext *ctx)
4929 76a66253 j_mayer
{
4930 7487953d aurel32
    TCGv t0 = tcg_temp_new();
4931 7487953d aurel32
    TCGv t1 = tcg_temp_new();
4932 7487953d aurel32
    TCGv t2 = tcg_temp_new();
4933 7487953d aurel32
    tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F);
4934 7487953d aurel32
    tcg_gen_movi_tl(t1, 0xFFFFFFFF);
4935 7487953d aurel32
    tcg_gen_shr_tl(t1, t1, t0);
4936 7487953d aurel32
    tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
4937 7487953d aurel32
    gen_load_spr(t2, SPR_MQ);
4938 7487953d aurel32
    gen_store_spr(SPR_MQ, t0);
4939 7487953d aurel32
    tcg_gen_and_tl(t0, t0, t1);
4940 7487953d aurel32
    tcg_gen_andc_tl(t2, t2, t1);
4941 7487953d aurel32
    tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
4942 7487953d aurel32
    tcg_temp_free(t0);
4943 7487953d aurel32
    tcg_temp_free(t1);
4944 7487953d aurel32
    tcg_temp_free(t2);
4945 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4946 7487953d aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4947 76a66253 j_mayer
}
4948 76a66253 j_mayer
4949 76a66253 j_mayer
/* sriq */
4950 99e300ef Blue Swirl
static void gen_sriq(DisasContext *ctx)
4951 76a66253 j_mayer
{
4952 7487953d aurel32
    int sh = SH(ctx->opcode);
4953 7487953d aurel32
    TCGv t0 = tcg_temp_new();
4954 7487953d aurel32
    TCGv t1 = tcg_temp_new();
4955 7487953d aurel32
    tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
4956 7487953d aurel32
    tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh);
4957 7487953d aurel32
    tcg_gen_or_tl(t1, t0, t1);
4958 7487953d aurel32
    tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
4959 7487953d aurel32
    gen_store_spr(SPR_MQ, t1);
4960 7487953d aurel32
    tcg_temp_free(t0);
4961 7487953d aurel32
    tcg_temp_free(t1);
4962 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4963 7487953d aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4964 76a66253 j_mayer
}
4965 76a66253 j_mayer
4966 76a66253 j_mayer
/* srliq */
4967 99e300ef Blue Swirl
static void gen_srliq(DisasContext *ctx)
4968 76a66253 j_mayer
{
4969 7487953d aurel32
    int sh = SH(ctx->opcode);
4970 7487953d aurel32
    TCGv t0 = tcg_temp_new();
4971 7487953d aurel32
    TCGv t1 = tcg_temp_new();
4972 7487953d aurel32
    tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
4973 7487953d aurel32
    gen_load_spr(t1, SPR_MQ);
4974 7487953d aurel32
    gen_store_spr(SPR_MQ, t0);
4975 7487953d aurel32
    tcg_gen_andi_tl(t0, t0,  (0xFFFFFFFFU >> sh));
4976 7487953d aurel32
    tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh));
4977 7487953d aurel32
    tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
4978 7487953d aurel32
    tcg_temp_free(t0);
4979 7487953d aurel32
    tcg_temp_free(t1);
4980 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
4981 7487953d aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
4982 76a66253 j_mayer
}
4983 76a66253 j_mayer
4984 76a66253 j_mayer
/* srlq */
4985 99e300ef Blue Swirl
static void gen_srlq(DisasContext *ctx)
4986 76a66253 j_mayer
{
4987 7487953d aurel32
    int l1 = gen_new_label();
4988 7487953d aurel32
    int l2 = gen_new_label();
4989 7487953d aurel32
    TCGv t0 = tcg_temp_local_new();
4990 7487953d aurel32
    TCGv t1 = tcg_temp_local_new();
4991 7487953d aurel32
    TCGv t2 = tcg_temp_local_new();
4992 7487953d aurel32
    tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F);
4993 7487953d aurel32
    tcg_gen_movi_tl(t1, 0xFFFFFFFF);
4994 7487953d aurel32
    tcg_gen_shr_tl(t2, t1, t2);
4995 7487953d aurel32
    tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20);
4996 7487953d aurel32
    tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
4997 7487953d aurel32
    gen_load_spr(t0, SPR_MQ);
4998 7487953d aurel32
    tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2);
4999 7487953d aurel32
    tcg_gen_br(l2);
5000 7487953d aurel32
    gen_set_label(l1);
5001 7487953d aurel32
    tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2);
5002 7487953d aurel32
    tcg_gen_and_tl(t0, t0, t2);
5003 7487953d aurel32
    gen_load_spr(t1, SPR_MQ);
5004 7487953d aurel32
    tcg_gen_andc_tl(t1, t1, t2);
5005 7487953d aurel32
    tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
5006 7487953d aurel32
    gen_set_label(l2);
5007 7487953d aurel32
    tcg_temp_free(t0);
5008 7487953d aurel32
    tcg_temp_free(t1);
5009 7487953d aurel32
    tcg_temp_free(t2);
5010 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
5011 7487953d aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5012 76a66253 j_mayer
}
5013 76a66253 j_mayer
5014 76a66253 j_mayer
/* srq */
5015 99e300ef Blue Swirl
static void gen_srq(DisasContext *ctx)
5016 76a66253 j_mayer
{
5017 7487953d aurel32
    int l1 = gen_new_label();
5018 7487953d aurel32
    TCGv t0 = tcg_temp_new();
5019 7487953d aurel32
    TCGv t1 = tcg_temp_new();
5020 7487953d aurel32
    tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F);
5021 7487953d aurel32
    tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1);
5022 7487953d aurel32
    tcg_gen_subfi_tl(t1, 32, t1);
5023 7487953d aurel32
    tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1);
5024 7487953d aurel32
    tcg_gen_or_tl(t1, t0, t1);
5025 7487953d aurel32
    gen_store_spr(SPR_MQ, t1);
5026 7487953d aurel32
    tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20);
5027 7487953d aurel32
    tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
5028 7487953d aurel32
    tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
5029 7487953d aurel32
    tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
5030 7487953d aurel32
    gen_set_label(l1);
5031 7487953d aurel32
    tcg_temp_free(t0);
5032 7487953d aurel32
    tcg_temp_free(t1);
5033 76a66253 j_mayer
    if (unlikely(Rc(ctx->opcode) != 0))
5034 7487953d aurel32
        gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
5035 76a66253 j_mayer
}
5036 76a66253 j_mayer
5037 76a66253 j_mayer
/* PowerPC 602 specific instructions */
5038 99e300ef Blue Swirl
5039 54623277 Blue Swirl
/* dsa  */
5040 99e300ef Blue Swirl
static void gen_dsa(DisasContext *ctx)
5041 76a66253 j_mayer
{
5042 76a66253 j_mayer
    /* XXX: TODO */
5043 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5044 76a66253 j_mayer
}
5045 76a66253 j_mayer
5046 76a66253 j_mayer
/* esa */
5047 99e300ef Blue Swirl
static void gen_esa(DisasContext *ctx)
5048 76a66253 j_mayer
{
5049 76a66253 j_mayer
    /* XXX: TODO */
5050 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5051 76a66253 j_mayer
}
5052 76a66253 j_mayer
5053 76a66253 j_mayer
/* mfrom */
5054 99e300ef Blue Swirl
static void gen_mfrom(DisasContext *ctx)
5055 76a66253 j_mayer
{
5056 76a66253 j_mayer
#if defined(CONFIG_USER_ONLY)
5057 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5058 76a66253 j_mayer
#else
5059 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5060 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5061 76a66253 j_mayer
        return;
5062 76a66253 j_mayer
    }
5063 cf02a65c aurel32
    gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5064 76a66253 j_mayer
#endif
5065 76a66253 j_mayer
}
5066 76a66253 j_mayer
5067 76a66253 j_mayer
/* 602 - 603 - G2 TLB management */
5068 e8eaa2c0 Blue Swirl
5069 54623277 Blue Swirl
/* tlbld */
5070 e8eaa2c0 Blue Swirl
static void gen_tlbld_6xx(DisasContext *ctx)
5071 76a66253 j_mayer
{
5072 76a66253 j_mayer
#if defined(CONFIG_USER_ONLY)
5073 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5074 76a66253 j_mayer
#else
5075 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5076 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5077 76a66253 j_mayer
        return;
5078 76a66253 j_mayer
    }
5079 74d37793 aurel32
    gen_helper_6xx_tlbd(cpu_gpr[rB(ctx->opcode)]);
5080 76a66253 j_mayer
#endif
5081 76a66253 j_mayer
}
5082 76a66253 j_mayer
5083 76a66253 j_mayer
/* tlbli */
5084 e8eaa2c0 Blue Swirl
static void gen_tlbli_6xx(DisasContext *ctx)
5085 76a66253 j_mayer
{
5086 76a66253 j_mayer
#if defined(CONFIG_USER_ONLY)
5087 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5088 76a66253 j_mayer
#else
5089 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5090 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5091 76a66253 j_mayer
        return;
5092 76a66253 j_mayer
    }
5093 74d37793 aurel32
    gen_helper_6xx_tlbi(cpu_gpr[rB(ctx->opcode)]);
5094 76a66253 j_mayer
#endif
5095 76a66253 j_mayer
}
5096 76a66253 j_mayer
5097 7dbe11ac j_mayer
/* 74xx TLB management */
5098 e8eaa2c0 Blue Swirl
5099 54623277 Blue Swirl
/* tlbld */
5100 e8eaa2c0 Blue Swirl
static void gen_tlbld_74xx(DisasContext *ctx)
5101 7dbe11ac j_mayer
{
5102 7dbe11ac j_mayer
#if defined(CONFIG_USER_ONLY)
5103 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5104 7dbe11ac j_mayer
#else
5105 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5106 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5107 7dbe11ac j_mayer
        return;
5108 7dbe11ac j_mayer
    }
5109 74d37793 aurel32
    gen_helper_74xx_tlbd(cpu_gpr[rB(ctx->opcode)]);
5110 7dbe11ac j_mayer
#endif
5111 7dbe11ac j_mayer
}
5112 7dbe11ac j_mayer
5113 7dbe11ac j_mayer
/* tlbli */
5114 e8eaa2c0 Blue Swirl
static void gen_tlbli_74xx(DisasContext *ctx)
5115 7dbe11ac j_mayer
{
5116 7dbe11ac j_mayer
#if defined(CONFIG_USER_ONLY)
5117 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5118 7dbe11ac j_mayer
#else
5119 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5120 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5121 7dbe11ac j_mayer
        return;
5122 7dbe11ac j_mayer
    }
5123 74d37793 aurel32
    gen_helper_74xx_tlbi(cpu_gpr[rB(ctx->opcode)]);
5124 7dbe11ac j_mayer
#endif
5125 7dbe11ac j_mayer
}
5126 7dbe11ac j_mayer
5127 76a66253 j_mayer
/* POWER instructions not in PowerPC 601 */
5128 99e300ef Blue Swirl
5129 54623277 Blue Swirl
/* clf */
5130 99e300ef Blue Swirl
static void gen_clf(DisasContext *ctx)
5131 76a66253 j_mayer
{
5132 76a66253 j_mayer
    /* Cache line flush: implemented as no-op */
5133 76a66253 j_mayer
}
5134 76a66253 j_mayer
5135 76a66253 j_mayer
/* cli */
5136 99e300ef Blue Swirl
static void gen_cli(DisasContext *ctx)
5137 76a66253 j_mayer
{
5138 7f75ffd3 blueswir1
    /* Cache line invalidate: privileged and treated as no-op */
5139 76a66253 j_mayer
#if defined(CONFIG_USER_ONLY)
5140 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5141 76a66253 j_mayer
#else
5142 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5143 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5144 76a66253 j_mayer
        return;
5145 76a66253 j_mayer
    }
5146 76a66253 j_mayer
#endif
5147 76a66253 j_mayer
}
5148 76a66253 j_mayer
5149 76a66253 j_mayer
/* dclst */
5150 99e300ef Blue Swirl
static void gen_dclst(DisasContext *ctx)
5151 76a66253 j_mayer
{
5152 76a66253 j_mayer
    /* Data cache line store: treated as no-op */
5153 76a66253 j_mayer
}
5154 76a66253 j_mayer
5155 99e300ef Blue Swirl
static void gen_mfsri(DisasContext *ctx)
5156 76a66253 j_mayer
{
5157 76a66253 j_mayer
#if defined(CONFIG_USER_ONLY)
5158 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5159 76a66253 j_mayer
#else
5160 74d37793 aurel32
    int ra = rA(ctx->opcode);
5161 74d37793 aurel32
    int rd = rD(ctx->opcode);
5162 74d37793 aurel32
    TCGv t0;
5163 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5164 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5165 76a66253 j_mayer
        return;
5166 76a66253 j_mayer
    }
5167 74d37793 aurel32
    t0 = tcg_temp_new();
5168 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
5169 74d37793 aurel32
    tcg_gen_shri_tl(t0, t0, 28);
5170 74d37793 aurel32
    tcg_gen_andi_tl(t0, t0, 0xF);
5171 74d37793 aurel32
    gen_helper_load_sr(cpu_gpr[rd], t0);
5172 74d37793 aurel32
    tcg_temp_free(t0);
5173 76a66253 j_mayer
    if (ra != 0 && ra != rd)
5174 74d37793 aurel32
        tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]);
5175 76a66253 j_mayer
#endif
5176 76a66253 j_mayer
}
5177 76a66253 j_mayer
5178 99e300ef Blue Swirl
static void gen_rac(DisasContext *ctx)
5179 76a66253 j_mayer
{
5180 76a66253 j_mayer
#if defined(CONFIG_USER_ONLY)
5181 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5182 76a66253 j_mayer
#else
5183 22e0e173 aurel32
    TCGv t0;
5184 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5185 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5186 76a66253 j_mayer
        return;
5187 76a66253 j_mayer
    }
5188 22e0e173 aurel32
    t0 = tcg_temp_new();
5189 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
5190 22e0e173 aurel32
    gen_helper_rac(cpu_gpr[rD(ctx->opcode)], t0);
5191 22e0e173 aurel32
    tcg_temp_free(t0);
5192 76a66253 j_mayer
#endif
5193 76a66253 j_mayer
}
5194 76a66253 j_mayer
5195 99e300ef Blue Swirl
static void gen_rfsvc(DisasContext *ctx)
5196 76a66253 j_mayer
{
5197 76a66253 j_mayer
#if defined(CONFIG_USER_ONLY)
5198 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5199 76a66253 j_mayer
#else
5200 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5201 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5202 76a66253 j_mayer
        return;
5203 76a66253 j_mayer
    }
5204 d72a19f7 aurel32
    gen_helper_rfsvc();
5205 e06fcd75 aurel32
    gen_sync_exception(ctx);
5206 76a66253 j_mayer
#endif
5207 76a66253 j_mayer
}
5208 76a66253 j_mayer
5209 76a66253 j_mayer
/* svc is not implemented for now */
5210 76a66253 j_mayer
5211 76a66253 j_mayer
/* POWER2 specific instructions */
5212 76a66253 j_mayer
/* Quad manipulation (load/store two floats at a time) */
5213 76a66253 j_mayer
5214 76a66253 j_mayer
/* lfq */
5215 99e300ef Blue Swirl
static void gen_lfq(DisasContext *ctx)
5216 76a66253 j_mayer
{
5217 01a4afeb aurel32
    int rd = rD(ctx->opcode);
5218 76db3ba4 aurel32
    TCGv t0;
5219 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_FLOAT);
5220 76db3ba4 aurel32
    t0 = tcg_temp_new();
5221 76db3ba4 aurel32
    gen_addr_imm_index(ctx, t0, 0);
5222 76db3ba4 aurel32
    gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5223 76db3ba4 aurel32
    gen_addr_add(ctx, t0, t0, 8);
5224 76db3ba4 aurel32
    gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
5225 01a4afeb aurel32
    tcg_temp_free(t0);
5226 76a66253 j_mayer
}
5227 76a66253 j_mayer
5228 76a66253 j_mayer
/* lfqu */
5229 99e300ef Blue Swirl
static void gen_lfqu(DisasContext *ctx)
5230 76a66253 j_mayer
{
5231 76a66253 j_mayer
    int ra = rA(ctx->opcode);
5232 01a4afeb aurel32
    int rd = rD(ctx->opcode);
5233 76db3ba4 aurel32
    TCGv t0, t1;
5234 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_FLOAT);
5235 76db3ba4 aurel32
    t0 = tcg_temp_new();
5236 76db3ba4 aurel32
    t1 = tcg_temp_new();
5237 76db3ba4 aurel32
    gen_addr_imm_index(ctx, t0, 0);
5238 76db3ba4 aurel32
    gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5239 76db3ba4 aurel32
    gen_addr_add(ctx, t1, t0, 8);
5240 76db3ba4 aurel32
    gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5241 76a66253 j_mayer
    if (ra != 0)
5242 01a4afeb aurel32
        tcg_gen_mov_tl(cpu_gpr[ra], t0);
5243 01a4afeb aurel32
    tcg_temp_free(t0);
5244 01a4afeb aurel32
    tcg_temp_free(t1);
5245 76a66253 j_mayer
}
5246 76a66253 j_mayer
5247 76a66253 j_mayer
/* lfqux */
5248 99e300ef Blue Swirl
static void gen_lfqux(DisasContext *ctx)
5249 76a66253 j_mayer
{
5250 76a66253 j_mayer
    int ra = rA(ctx->opcode);
5251 01a4afeb aurel32
    int rd = rD(ctx->opcode);
5252 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_FLOAT);
5253 76db3ba4 aurel32
    TCGv t0, t1;
5254 76db3ba4 aurel32
    t0 = tcg_temp_new();
5255 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
5256 76db3ba4 aurel32
    gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5257 76db3ba4 aurel32
    t1 = tcg_temp_new();
5258 76db3ba4 aurel32
    gen_addr_add(ctx, t1, t0, 8);
5259 76db3ba4 aurel32
    gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5260 76db3ba4 aurel32
    tcg_temp_free(t1);
5261 76a66253 j_mayer
    if (ra != 0)
5262 01a4afeb aurel32
        tcg_gen_mov_tl(cpu_gpr[ra], t0);
5263 01a4afeb aurel32
    tcg_temp_free(t0);
5264 76a66253 j_mayer
}
5265 76a66253 j_mayer
5266 76a66253 j_mayer
/* lfqx */
5267 99e300ef Blue Swirl
static void gen_lfqx(DisasContext *ctx)
5268 76a66253 j_mayer
{
5269 01a4afeb aurel32
    int rd = rD(ctx->opcode);
5270 76db3ba4 aurel32
    TCGv t0;
5271 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_FLOAT);
5272 76db3ba4 aurel32
    t0 = tcg_temp_new();
5273 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
5274 76db3ba4 aurel32
    gen_qemu_ld64(ctx, cpu_fpr[rd], t0);
5275 76db3ba4 aurel32
    gen_addr_add(ctx, t0, t0, 8);
5276 76db3ba4 aurel32
    gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0);
5277 01a4afeb aurel32
    tcg_temp_free(t0);
5278 76a66253 j_mayer
}
5279 76a66253 j_mayer
5280 76a66253 j_mayer
/* stfq */
5281 99e300ef Blue Swirl
static void gen_stfq(DisasContext *ctx)
5282 76a66253 j_mayer
{
5283 01a4afeb aurel32
    int rd = rD(ctx->opcode);
5284 76db3ba4 aurel32
    TCGv t0;
5285 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_FLOAT);
5286 76db3ba4 aurel32
    t0 = tcg_temp_new();
5287 76db3ba4 aurel32
    gen_addr_imm_index(ctx, t0, 0);
5288 76db3ba4 aurel32
    gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5289 76db3ba4 aurel32
    gen_addr_add(ctx, t0, t0, 8);
5290 76db3ba4 aurel32
    gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
5291 01a4afeb aurel32
    tcg_temp_free(t0);
5292 76a66253 j_mayer
}
5293 76a66253 j_mayer
5294 76a66253 j_mayer
/* stfqu */
5295 99e300ef Blue Swirl
static void gen_stfqu(DisasContext *ctx)
5296 76a66253 j_mayer
{
5297 76a66253 j_mayer
    int ra = rA(ctx->opcode);
5298 01a4afeb aurel32
    int rd = rD(ctx->opcode);
5299 76db3ba4 aurel32
    TCGv t0, t1;
5300 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_FLOAT);
5301 76db3ba4 aurel32
    t0 = tcg_temp_new();
5302 76db3ba4 aurel32
    gen_addr_imm_index(ctx, t0, 0);
5303 76db3ba4 aurel32
    gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5304 76db3ba4 aurel32
    t1 = tcg_temp_new();
5305 76db3ba4 aurel32
    gen_addr_add(ctx, t1, t0, 8);
5306 76db3ba4 aurel32
    gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5307 76db3ba4 aurel32
    tcg_temp_free(t1);
5308 76a66253 j_mayer
    if (ra != 0)
5309 01a4afeb aurel32
        tcg_gen_mov_tl(cpu_gpr[ra], t0);
5310 01a4afeb aurel32
    tcg_temp_free(t0);
5311 76a66253 j_mayer
}
5312 76a66253 j_mayer
5313 76a66253 j_mayer
/* stfqux */
5314 99e300ef Blue Swirl
static void gen_stfqux(DisasContext *ctx)
5315 76a66253 j_mayer
{
5316 76a66253 j_mayer
    int ra = rA(ctx->opcode);
5317 01a4afeb aurel32
    int rd = rD(ctx->opcode);
5318 76db3ba4 aurel32
    TCGv t0, t1;
5319 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_FLOAT);
5320 76db3ba4 aurel32
    t0 = tcg_temp_new();
5321 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
5322 76db3ba4 aurel32
    gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5323 76db3ba4 aurel32
    t1 = tcg_temp_new();
5324 76db3ba4 aurel32
    gen_addr_add(ctx, t1, t0, 8);
5325 76db3ba4 aurel32
    gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1);
5326 76db3ba4 aurel32
    tcg_temp_free(t1);
5327 76a66253 j_mayer
    if (ra != 0)
5328 01a4afeb aurel32
        tcg_gen_mov_tl(cpu_gpr[ra], t0);
5329 01a4afeb aurel32
    tcg_temp_free(t0);
5330 76a66253 j_mayer
}
5331 76a66253 j_mayer
5332 76a66253 j_mayer
/* stfqx */
5333 99e300ef Blue Swirl
static void gen_stfqx(DisasContext *ctx)
5334 76a66253 j_mayer
{
5335 01a4afeb aurel32
    int rd = rD(ctx->opcode);
5336 76db3ba4 aurel32
    TCGv t0;
5337 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_FLOAT);
5338 76db3ba4 aurel32
    t0 = tcg_temp_new();
5339 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
5340 76db3ba4 aurel32
    gen_qemu_st64(ctx, cpu_fpr[rd], t0);
5341 76db3ba4 aurel32
    gen_addr_add(ctx, t0, t0, 8);
5342 76db3ba4 aurel32
    gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0);
5343 01a4afeb aurel32
    tcg_temp_free(t0);
5344 76a66253 j_mayer
}
5345 76a66253 j_mayer
5346 76a66253 j_mayer
/* BookE specific instructions */
5347 99e300ef Blue Swirl
5348 54623277 Blue Swirl
/* XXX: not implemented on 440 ? */
5349 99e300ef Blue Swirl
static void gen_mfapidi(DisasContext *ctx)
5350 76a66253 j_mayer
{
5351 76a66253 j_mayer
    /* XXX: TODO */
5352 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5353 76a66253 j_mayer
}
5354 76a66253 j_mayer
5355 2662a059 j_mayer
/* XXX: not implemented on 440 ? */
5356 99e300ef Blue Swirl
static void gen_tlbiva(DisasContext *ctx)
5357 76a66253 j_mayer
{
5358 76a66253 j_mayer
#if defined(CONFIG_USER_ONLY)
5359 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5360 76a66253 j_mayer
#else
5361 74d37793 aurel32
    TCGv t0;
5362 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5363 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5364 76a66253 j_mayer
        return;
5365 76a66253 j_mayer
    }
5366 ec72e276 aurel32
    t0 = tcg_temp_new();
5367 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
5368 74d37793 aurel32
    gen_helper_tlbie(cpu_gpr[rB(ctx->opcode)]);
5369 74d37793 aurel32
    tcg_temp_free(t0);
5370 76a66253 j_mayer
#endif
5371 76a66253 j_mayer
}
5372 76a66253 j_mayer
5373 76a66253 j_mayer
/* All 405 MAC instructions are translated here */
5374 636aa200 Blue Swirl
static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3,
5375 636aa200 Blue Swirl
                                        int ra, int rb, int rt, int Rc)
5376 76a66253 j_mayer
{
5377 182608d4 aurel32
    TCGv t0, t1;
5378 182608d4 aurel32
5379 a7812ae4 pbrook
    t0 = tcg_temp_local_new();
5380 a7812ae4 pbrook
    t1 = tcg_temp_local_new();
5381 182608d4 aurel32
5382 76a66253 j_mayer
    switch (opc3 & 0x0D) {
5383 76a66253 j_mayer
    case 0x05:
5384 76a66253 j_mayer
        /* macchw    - macchw.    - macchwo   - macchwo.   */
5385 76a66253 j_mayer
        /* macchws   - macchws.   - macchwso  - macchwso.  */
5386 76a66253 j_mayer
        /* nmacchw   - nmacchw.   - nmacchwo  - nmacchwo.  */
5387 76a66253 j_mayer
        /* nmacchws  - nmacchws.  - nmacchwso - nmacchwso. */
5388 76a66253 j_mayer
        /* mulchw - mulchw. */
5389 182608d4 aurel32
        tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5390 182608d4 aurel32
        tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5391 182608d4 aurel32
        tcg_gen_ext16s_tl(t1, t1);
5392 76a66253 j_mayer
        break;
5393 76a66253 j_mayer
    case 0x04:
5394 76a66253 j_mayer
        /* macchwu   - macchwu.   - macchwuo  - macchwuo.  */
5395 76a66253 j_mayer
        /* macchwsu  - macchwsu.  - macchwsuo - macchwsuo. */
5396 76a66253 j_mayer
        /* mulchwu - mulchwu. */
5397 182608d4 aurel32
        tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5398 182608d4 aurel32
        tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5399 182608d4 aurel32
        tcg_gen_ext16u_tl(t1, t1);
5400 76a66253 j_mayer
        break;
5401 76a66253 j_mayer
    case 0x01:
5402 76a66253 j_mayer
        /* machhw    - machhw.    - machhwo   - machhwo.   */
5403 76a66253 j_mayer
        /* machhws   - machhws.   - machhwso  - machhwso.  */
5404 76a66253 j_mayer
        /* nmachhw   - nmachhw.   - nmachhwo  - nmachhwo.  */
5405 76a66253 j_mayer
        /* nmachhws  - nmachhws.  - nmachhwso - nmachhwso. */
5406 76a66253 j_mayer
        /* mulhhw - mulhhw. */
5407 182608d4 aurel32
        tcg_gen_sari_tl(t0, cpu_gpr[ra], 16);
5408 182608d4 aurel32
        tcg_gen_ext16s_tl(t0, t0);
5409 182608d4 aurel32
        tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5410 182608d4 aurel32
        tcg_gen_ext16s_tl(t1, t1);
5411 76a66253 j_mayer
        break;
5412 76a66253 j_mayer
    case 0x00:
5413 76a66253 j_mayer
        /* machhwu   - machhwu.   - machhwuo  - machhwuo.  */
5414 76a66253 j_mayer
        /* machhwsu  - machhwsu.  - machhwsuo - machhwsuo. */
5415 76a66253 j_mayer
        /* mulhhwu - mulhhwu. */
5416 182608d4 aurel32
        tcg_gen_shri_tl(t0, cpu_gpr[ra], 16);
5417 182608d4 aurel32
        tcg_gen_ext16u_tl(t0, t0);
5418 182608d4 aurel32
        tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5419 182608d4 aurel32
        tcg_gen_ext16u_tl(t1, t1);
5420 76a66253 j_mayer
        break;
5421 76a66253 j_mayer
    case 0x0D:
5422 76a66253 j_mayer
        /* maclhw    - maclhw.    - maclhwo   - maclhwo.   */
5423 76a66253 j_mayer
        /* maclhws   - maclhws.   - maclhwso  - maclhwso.  */
5424 76a66253 j_mayer
        /* nmaclhw   - nmaclhw.   - nmaclhwo  - nmaclhwo.  */
5425 76a66253 j_mayer
        /* nmaclhws  - nmaclhws.  - nmaclhwso - nmaclhwso. */
5426 76a66253 j_mayer
        /* mullhw - mullhw. */
5427 182608d4 aurel32
        tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5428 182608d4 aurel32
        tcg_gen_ext16s_tl(t1, cpu_gpr[rb]);
5429 76a66253 j_mayer
        break;
5430 76a66253 j_mayer
    case 0x0C:
5431 76a66253 j_mayer
        /* maclhwu   - maclhwu.   - maclhwuo  - maclhwuo.  */
5432 76a66253 j_mayer
        /* maclhwsu  - maclhwsu.  - maclhwsuo - maclhwsuo. */
5433 76a66253 j_mayer
        /* mullhwu - mullhwu. */
5434 182608d4 aurel32
        tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5435 182608d4 aurel32
        tcg_gen_ext16u_tl(t1, cpu_gpr[rb]);
5436 76a66253 j_mayer
        break;
5437 76a66253 j_mayer
    }
5438 76a66253 j_mayer
    if (opc2 & 0x04) {
5439 182608d4 aurel32
        /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5440 182608d4 aurel32
        tcg_gen_mul_tl(t1, t0, t1);
5441 182608d4 aurel32
        if (opc2 & 0x02) {
5442 182608d4 aurel32
            /* nmultiply-and-accumulate (0x0E) */
5443 182608d4 aurel32
            tcg_gen_sub_tl(t0, cpu_gpr[rt], t1);
5444 182608d4 aurel32
        } else {
5445 182608d4 aurel32
            /* multiply-and-accumulate (0x0C) */
5446 182608d4 aurel32
            tcg_gen_add_tl(t0, cpu_gpr[rt], t1);
5447 182608d4 aurel32
        }
5448 182608d4 aurel32
5449 182608d4 aurel32
        if (opc3 & 0x12) {
5450 182608d4 aurel32
            /* Check overflow and/or saturate */
5451 182608d4 aurel32
            int l1 = gen_new_label();
5452 182608d4 aurel32
5453 182608d4 aurel32
            if (opc3 & 0x10) {
5454 182608d4 aurel32
                /* Start with XER OV disabled, the most likely case */
5455 182608d4 aurel32
                tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
5456 182608d4 aurel32
            }
5457 182608d4 aurel32
            if (opc3 & 0x01) {
5458 182608d4 aurel32
                /* Signed */
5459 182608d4 aurel32
                tcg_gen_xor_tl(t1, cpu_gpr[rt], t1);
5460 182608d4 aurel32
                tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1);
5461 182608d4 aurel32
                tcg_gen_xor_tl(t1, cpu_gpr[rt], t0);
5462 182608d4 aurel32
                tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1);
5463 bdc4e053 aurel32
                if (opc3 & 0x02) {
5464 182608d4 aurel32
                    /* Saturate */
5465 182608d4 aurel32
                    tcg_gen_sari_tl(t0, cpu_gpr[rt], 31);
5466 182608d4 aurel32
                    tcg_gen_xori_tl(t0, t0, 0x7fffffff);
5467 182608d4 aurel32
                }
5468 182608d4 aurel32
            } else {
5469 182608d4 aurel32
                /* Unsigned */
5470 182608d4 aurel32
                tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
5471 bdc4e053 aurel32
                if (opc3 & 0x02) {
5472 182608d4 aurel32
                    /* Saturate */
5473 182608d4 aurel32
                    tcg_gen_movi_tl(t0, UINT32_MAX);
5474 182608d4 aurel32
                }
5475 182608d4 aurel32
            }
5476 182608d4 aurel32
            if (opc3 & 0x10) {
5477 182608d4 aurel32
                /* Check overflow */
5478 182608d4 aurel32
                tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
5479 182608d4 aurel32
            }
5480 182608d4 aurel32
            gen_set_label(l1);
5481 182608d4 aurel32
            tcg_gen_mov_tl(cpu_gpr[rt], t0);
5482 182608d4 aurel32
        }
5483 182608d4 aurel32
    } else {
5484 182608d4 aurel32
        tcg_gen_mul_tl(cpu_gpr[rt], t0, t1);
5485 76a66253 j_mayer
    }
5486 182608d4 aurel32
    tcg_temp_free(t0);
5487 182608d4 aurel32
    tcg_temp_free(t1);
5488 76a66253 j_mayer
    if (unlikely(Rc) != 0) {
5489 76a66253 j_mayer
        /* Update Rc0 */
5490 182608d4 aurel32
        gen_set_Rc0(ctx, cpu_gpr[rt]);
5491 76a66253 j_mayer
    }
5492 76a66253 j_mayer
}
5493 76a66253 j_mayer
5494 a750fc0b j_mayer
#define GEN_MAC_HANDLER(name, opc2, opc3)                                     \
5495 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                               \
5496 76a66253 j_mayer
{                                                                             \
5497 76a66253 j_mayer
    gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode),   \
5498 76a66253 j_mayer
                         rD(ctx->opcode), Rc(ctx->opcode));                   \
5499 76a66253 j_mayer
}
5500 76a66253 j_mayer
5501 76a66253 j_mayer
/* macchw    - macchw.    */
5502 a750fc0b j_mayer
GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
5503 76a66253 j_mayer
/* macchwo   - macchwo.   */
5504 a750fc0b j_mayer
GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
5505 76a66253 j_mayer
/* macchws   - macchws.   */
5506 a750fc0b j_mayer
GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
5507 76a66253 j_mayer
/* macchwso  - macchwso.  */
5508 a750fc0b j_mayer
GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
5509 76a66253 j_mayer
/* macchwsu  - macchwsu.  */
5510 a750fc0b j_mayer
GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
5511 76a66253 j_mayer
/* macchwsuo - macchwsuo. */
5512 a750fc0b j_mayer
GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
5513 76a66253 j_mayer
/* macchwu   - macchwu.   */
5514 a750fc0b j_mayer
GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
5515 76a66253 j_mayer
/* macchwuo  - macchwuo.  */
5516 a750fc0b j_mayer
GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
5517 76a66253 j_mayer
/* machhw    - machhw.    */
5518 a750fc0b j_mayer
GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
5519 76a66253 j_mayer
/* machhwo   - machhwo.   */
5520 a750fc0b j_mayer
GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
5521 76a66253 j_mayer
/* machhws   - machhws.   */
5522 a750fc0b j_mayer
GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
5523 76a66253 j_mayer
/* machhwso  - machhwso.  */
5524 a750fc0b j_mayer
GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
5525 76a66253 j_mayer
/* machhwsu  - machhwsu.  */
5526 a750fc0b j_mayer
GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
5527 76a66253 j_mayer
/* machhwsuo - machhwsuo. */
5528 a750fc0b j_mayer
GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
5529 76a66253 j_mayer
/* machhwu   - machhwu.   */
5530 a750fc0b j_mayer
GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
5531 76a66253 j_mayer
/* machhwuo  - machhwuo.  */
5532 a750fc0b j_mayer
GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
5533 76a66253 j_mayer
/* maclhw    - maclhw.    */
5534 a750fc0b j_mayer
GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
5535 76a66253 j_mayer
/* maclhwo   - maclhwo.   */
5536 a750fc0b j_mayer
GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
5537 76a66253 j_mayer
/* maclhws   - maclhws.   */
5538 a750fc0b j_mayer
GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
5539 76a66253 j_mayer
/* maclhwso  - maclhwso.  */
5540 a750fc0b j_mayer
GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
5541 76a66253 j_mayer
/* maclhwu   - maclhwu.   */
5542 a750fc0b j_mayer
GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
5543 76a66253 j_mayer
/* maclhwuo  - maclhwuo.  */
5544 a750fc0b j_mayer
GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
5545 76a66253 j_mayer
/* maclhwsu  - maclhwsu.  */
5546 a750fc0b j_mayer
GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
5547 76a66253 j_mayer
/* maclhwsuo - maclhwsuo. */
5548 a750fc0b j_mayer
GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
5549 76a66253 j_mayer
/* nmacchw   - nmacchw.   */
5550 a750fc0b j_mayer
GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
5551 76a66253 j_mayer
/* nmacchwo  - nmacchwo.  */
5552 a750fc0b j_mayer
GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
5553 76a66253 j_mayer
/* nmacchws  - nmacchws.  */
5554 a750fc0b j_mayer
GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
5555 76a66253 j_mayer
/* nmacchwso - nmacchwso. */
5556 a750fc0b j_mayer
GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
5557 76a66253 j_mayer
/* nmachhw   - nmachhw.   */
5558 a750fc0b j_mayer
GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
5559 76a66253 j_mayer
/* nmachhwo  - nmachhwo.  */
5560 a750fc0b j_mayer
GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
5561 76a66253 j_mayer
/* nmachhws  - nmachhws.  */
5562 a750fc0b j_mayer
GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
5563 76a66253 j_mayer
/* nmachhwso - nmachhwso. */
5564 a750fc0b j_mayer
GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
5565 76a66253 j_mayer
/* nmaclhw   - nmaclhw.   */
5566 a750fc0b j_mayer
GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
5567 76a66253 j_mayer
/* nmaclhwo  - nmaclhwo.  */
5568 a750fc0b j_mayer
GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
5569 76a66253 j_mayer
/* nmaclhws  - nmaclhws.  */
5570 a750fc0b j_mayer
GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
5571 76a66253 j_mayer
/* nmaclhwso - nmaclhwso. */
5572 a750fc0b j_mayer
GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
5573 76a66253 j_mayer
5574 76a66253 j_mayer
/* mulchw  - mulchw.  */
5575 a750fc0b j_mayer
GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
5576 76a66253 j_mayer
/* mulchwu - mulchwu. */
5577 a750fc0b j_mayer
GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
5578 76a66253 j_mayer
/* mulhhw  - mulhhw.  */
5579 a750fc0b j_mayer
GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
5580 76a66253 j_mayer
/* mulhhwu - mulhhwu. */
5581 a750fc0b j_mayer
GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
5582 76a66253 j_mayer
/* mullhw  - mullhw.  */
5583 a750fc0b j_mayer
GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
5584 76a66253 j_mayer
/* mullhwu - mullhwu. */
5585 a750fc0b j_mayer
GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
5586 76a66253 j_mayer
5587 76a66253 j_mayer
/* mfdcr */
5588 99e300ef Blue Swirl
static void gen_mfdcr(DisasContext *ctx)
5589 76a66253 j_mayer
{
5590 76a66253 j_mayer
#if defined(CONFIG_USER_ONLY)
5591 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
5592 76a66253 j_mayer
#else
5593 06dca6a7 aurel32
    TCGv dcrn;
5594 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5595 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
5596 76a66253 j_mayer
        return;
5597 76a66253 j_mayer
    }
5598 06dca6a7 aurel32
    /* NIP cannot be restored if the memory exception comes from an helper */
5599 06dca6a7 aurel32
    gen_update_nip(ctx, ctx->nip - 4);
5600 06dca6a7 aurel32
    dcrn = tcg_const_tl(SPR(ctx->opcode));
5601 06dca6a7 aurel32
    gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], dcrn);
5602 06dca6a7 aurel32
    tcg_temp_free(dcrn);
5603 76a66253 j_mayer
#endif
5604 76a66253 j_mayer
}
5605 76a66253 j_mayer
5606 76a66253 j_mayer
/* mtdcr */
5607 99e300ef Blue Swirl
static void gen_mtdcr(DisasContext *ctx)
5608 76a66253 j_mayer
{
5609 76a66253 j_mayer
#if defined(CONFIG_USER_ONLY)
5610 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
5611 76a66253 j_mayer
#else
5612 06dca6a7 aurel32
    TCGv dcrn;
5613 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5614 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
5615 76a66253 j_mayer
        return;
5616 76a66253 j_mayer
    }
5617 06dca6a7 aurel32
    /* NIP cannot be restored if the memory exception comes from an helper */
5618 06dca6a7 aurel32
    gen_update_nip(ctx, ctx->nip - 4);
5619 06dca6a7 aurel32
    dcrn = tcg_const_tl(SPR(ctx->opcode));
5620 06dca6a7 aurel32
    gen_helper_store_dcr(dcrn, cpu_gpr[rS(ctx->opcode)]);
5621 06dca6a7 aurel32
    tcg_temp_free(dcrn);
5622 a42bd6cc j_mayer
#endif
5623 a42bd6cc j_mayer
}
5624 a42bd6cc j_mayer
5625 a42bd6cc j_mayer
/* mfdcrx */
5626 2662a059 j_mayer
/* XXX: not implemented on 440 ? */
5627 99e300ef Blue Swirl
static void gen_mfdcrx(DisasContext *ctx)
5628 a42bd6cc j_mayer
{
5629 a42bd6cc j_mayer
#if defined(CONFIG_USER_ONLY)
5630 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
5631 a42bd6cc j_mayer
#else
5632 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5633 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
5634 a42bd6cc j_mayer
        return;
5635 a42bd6cc j_mayer
    }
5636 06dca6a7 aurel32
    /* NIP cannot be restored if the memory exception comes from an helper */
5637 06dca6a7 aurel32
    gen_update_nip(ctx, ctx->nip - 4);
5638 06dca6a7 aurel32
    gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5639 a750fc0b j_mayer
    /* Note: Rc update flag set leads to undefined state of Rc0 */
5640 a42bd6cc j_mayer
#endif
5641 a42bd6cc j_mayer
}
5642 a42bd6cc j_mayer
5643 a42bd6cc j_mayer
/* mtdcrx */
5644 2662a059 j_mayer
/* XXX: not implemented on 440 ? */
5645 99e300ef Blue Swirl
static void gen_mtdcrx(DisasContext *ctx)
5646 a42bd6cc j_mayer
{
5647 a42bd6cc j_mayer
#if defined(CONFIG_USER_ONLY)
5648 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
5649 a42bd6cc j_mayer
#else
5650 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5651 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG);
5652 a42bd6cc j_mayer
        return;
5653 a42bd6cc j_mayer
    }
5654 06dca6a7 aurel32
    /* NIP cannot be restored if the memory exception comes from an helper */
5655 06dca6a7 aurel32
    gen_update_nip(ctx, ctx->nip - 4);
5656 06dca6a7 aurel32
    gen_helper_store_dcr(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
5657 a750fc0b j_mayer
    /* Note: Rc update flag set leads to undefined state of Rc0 */
5658 76a66253 j_mayer
#endif
5659 76a66253 j_mayer
}
5660 76a66253 j_mayer
5661 a750fc0b j_mayer
/* mfdcrux (PPC 460) : user-mode access to DCR */
5662 99e300ef Blue Swirl
static void gen_mfdcrux(DisasContext *ctx)
5663 a750fc0b j_mayer
{
5664 06dca6a7 aurel32
    /* NIP cannot be restored if the memory exception comes from an helper */
5665 06dca6a7 aurel32
    gen_update_nip(ctx, ctx->nip - 4);
5666 06dca6a7 aurel32
    gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5667 a750fc0b j_mayer
    /* Note: Rc update flag set leads to undefined state of Rc0 */
5668 a750fc0b j_mayer
}
5669 a750fc0b j_mayer
5670 a750fc0b j_mayer
/* mtdcrux (PPC 460) : user-mode access to DCR */
5671 99e300ef Blue Swirl
static void gen_mtdcrux(DisasContext *ctx)
5672 a750fc0b j_mayer
{
5673 06dca6a7 aurel32
    /* NIP cannot be restored if the memory exception comes from an helper */
5674 06dca6a7 aurel32
    gen_update_nip(ctx, ctx->nip - 4);
5675 06dca6a7 aurel32
    gen_helper_store_dcr(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
5676 a750fc0b j_mayer
    /* Note: Rc update flag set leads to undefined state of Rc0 */
5677 a750fc0b j_mayer
}
5678 a750fc0b j_mayer
5679 76a66253 j_mayer
/* dccci */
5680 99e300ef Blue Swirl
static void gen_dccci(DisasContext *ctx)
5681 76a66253 j_mayer
{
5682 76a66253 j_mayer
#if defined(CONFIG_USER_ONLY)
5683 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5684 76a66253 j_mayer
#else
5685 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5686 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5687 76a66253 j_mayer
        return;
5688 76a66253 j_mayer
    }
5689 76a66253 j_mayer
    /* interpreted as no-op */
5690 76a66253 j_mayer
#endif
5691 76a66253 j_mayer
}
5692 76a66253 j_mayer
5693 76a66253 j_mayer
/* dcread */
5694 99e300ef Blue Swirl
static void gen_dcread(DisasContext *ctx)
5695 76a66253 j_mayer
{
5696 76a66253 j_mayer
#if defined(CONFIG_USER_ONLY)
5697 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5698 76a66253 j_mayer
#else
5699 b61f2753 aurel32
    TCGv EA, val;
5700 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5701 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5702 76a66253 j_mayer
        return;
5703 76a66253 j_mayer
    }
5704 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_CACHE);
5705 a7812ae4 pbrook
    EA = tcg_temp_new();
5706 76db3ba4 aurel32
    gen_addr_reg_index(ctx, EA);
5707 a7812ae4 pbrook
    val = tcg_temp_new();
5708 76db3ba4 aurel32
    gen_qemu_ld32u(ctx, val, EA);
5709 b61f2753 aurel32
    tcg_temp_free(val);
5710 b61f2753 aurel32
    tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA);
5711 b61f2753 aurel32
    tcg_temp_free(EA);
5712 76a66253 j_mayer
#endif
5713 76a66253 j_mayer
}
5714 76a66253 j_mayer
5715 76a66253 j_mayer
/* icbt */
5716 e8eaa2c0 Blue Swirl
static void gen_icbt_40x(DisasContext *ctx)
5717 76a66253 j_mayer
{
5718 76a66253 j_mayer
    /* interpreted as no-op */
5719 76a66253 j_mayer
    /* XXX: specification say this is treated as a load by the MMU
5720 76a66253 j_mayer
     *      but does not generate any exception
5721 76a66253 j_mayer
     */
5722 76a66253 j_mayer
}
5723 76a66253 j_mayer
5724 76a66253 j_mayer
/* iccci */
5725 99e300ef Blue Swirl
static void gen_iccci(DisasContext *ctx)
5726 76a66253 j_mayer
{
5727 76a66253 j_mayer
#if defined(CONFIG_USER_ONLY)
5728 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5729 76a66253 j_mayer
#else
5730 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5731 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5732 76a66253 j_mayer
        return;
5733 76a66253 j_mayer
    }
5734 76a66253 j_mayer
    /* interpreted as no-op */
5735 76a66253 j_mayer
#endif
5736 76a66253 j_mayer
}
5737 76a66253 j_mayer
5738 76a66253 j_mayer
/* icread */
5739 99e300ef Blue Swirl
static void gen_icread(DisasContext *ctx)
5740 76a66253 j_mayer
{
5741 76a66253 j_mayer
#if defined(CONFIG_USER_ONLY)
5742 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5743 76a66253 j_mayer
#else
5744 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5745 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5746 76a66253 j_mayer
        return;
5747 76a66253 j_mayer
    }
5748 76a66253 j_mayer
    /* interpreted as no-op */
5749 76a66253 j_mayer
#endif
5750 76a66253 j_mayer
}
5751 76a66253 j_mayer
5752 76db3ba4 aurel32
/* rfci (mem_idx only) */
5753 e8eaa2c0 Blue Swirl
static void gen_rfci_40x(DisasContext *ctx)
5754 a42bd6cc j_mayer
{
5755 a42bd6cc j_mayer
#if defined(CONFIG_USER_ONLY)
5756 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5757 a42bd6cc j_mayer
#else
5758 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5759 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5760 a42bd6cc j_mayer
        return;
5761 a42bd6cc j_mayer
    }
5762 a42bd6cc j_mayer
    /* Restore CPU state */
5763 d72a19f7 aurel32
    gen_helper_40x_rfci();
5764 e06fcd75 aurel32
    gen_sync_exception(ctx);
5765 a42bd6cc j_mayer
#endif
5766 a42bd6cc j_mayer
}
5767 a42bd6cc j_mayer
5768 99e300ef Blue Swirl
static void gen_rfci(DisasContext *ctx)
5769 a42bd6cc j_mayer
{
5770 a42bd6cc j_mayer
#if defined(CONFIG_USER_ONLY)
5771 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5772 a42bd6cc j_mayer
#else
5773 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5774 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5775 a42bd6cc j_mayer
        return;
5776 a42bd6cc j_mayer
    }
5777 a42bd6cc j_mayer
    /* Restore CPU state */
5778 d72a19f7 aurel32
    gen_helper_rfci();
5779 e06fcd75 aurel32
    gen_sync_exception(ctx);
5780 a42bd6cc j_mayer
#endif
5781 a42bd6cc j_mayer
}
5782 a42bd6cc j_mayer
5783 a42bd6cc j_mayer
/* BookE specific */
5784 99e300ef Blue Swirl
5785 54623277 Blue Swirl
/* XXX: not implemented on 440 ? */
5786 99e300ef Blue Swirl
static void gen_rfdi(DisasContext *ctx)
5787 76a66253 j_mayer
{
5788 76a66253 j_mayer
#if defined(CONFIG_USER_ONLY)
5789 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5790 76a66253 j_mayer
#else
5791 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5792 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5793 76a66253 j_mayer
        return;
5794 76a66253 j_mayer
    }
5795 76a66253 j_mayer
    /* Restore CPU state */
5796 d72a19f7 aurel32
    gen_helper_rfdi();
5797 e06fcd75 aurel32
    gen_sync_exception(ctx);
5798 76a66253 j_mayer
#endif
5799 76a66253 j_mayer
}
5800 76a66253 j_mayer
5801 2662a059 j_mayer
/* XXX: not implemented on 440 ? */
5802 99e300ef Blue Swirl
static void gen_rfmci(DisasContext *ctx)
5803 a42bd6cc j_mayer
{
5804 a42bd6cc j_mayer
#if defined(CONFIG_USER_ONLY)
5805 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5806 a42bd6cc j_mayer
#else
5807 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5808 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5809 a42bd6cc j_mayer
        return;
5810 a42bd6cc j_mayer
    }
5811 a42bd6cc j_mayer
    /* Restore CPU state */
5812 d72a19f7 aurel32
    gen_helper_rfmci();
5813 e06fcd75 aurel32
    gen_sync_exception(ctx);
5814 a42bd6cc j_mayer
#endif
5815 a42bd6cc j_mayer
}
5816 5eb7995e j_mayer
5817 d9bce9d9 j_mayer
/* TLB management - PowerPC 405 implementation */
5818 e8eaa2c0 Blue Swirl
5819 54623277 Blue Swirl
/* tlbre */
5820 e8eaa2c0 Blue Swirl
static void gen_tlbre_40x(DisasContext *ctx)
5821 76a66253 j_mayer
{
5822 76a66253 j_mayer
#if defined(CONFIG_USER_ONLY)
5823 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5824 76a66253 j_mayer
#else
5825 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5826 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5827 76a66253 j_mayer
        return;
5828 76a66253 j_mayer
    }
5829 76a66253 j_mayer
    switch (rB(ctx->opcode)) {
5830 76a66253 j_mayer
    case 0:
5831 74d37793 aurel32
        gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5832 76a66253 j_mayer
        break;
5833 76a66253 j_mayer
    case 1:
5834 74d37793 aurel32
        gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
5835 76a66253 j_mayer
        break;
5836 76a66253 j_mayer
    default:
5837 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5838 76a66253 j_mayer
        break;
5839 9a64fbe4 bellard
    }
5840 76a66253 j_mayer
#endif
5841 76a66253 j_mayer
}
5842 76a66253 j_mayer
5843 d9bce9d9 j_mayer
/* tlbsx - tlbsx. */
5844 e8eaa2c0 Blue Swirl
static void gen_tlbsx_40x(DisasContext *ctx)
5845 76a66253 j_mayer
{
5846 76a66253 j_mayer
#if defined(CONFIG_USER_ONLY)
5847 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5848 76a66253 j_mayer
#else
5849 74d37793 aurel32
    TCGv t0;
5850 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5851 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5852 76a66253 j_mayer
        return;
5853 76a66253 j_mayer
    }
5854 74d37793 aurel32
    t0 = tcg_temp_new();
5855 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
5856 74d37793 aurel32
    gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], t0);
5857 74d37793 aurel32
    tcg_temp_free(t0);
5858 74d37793 aurel32
    if (Rc(ctx->opcode)) {
5859 74d37793 aurel32
        int l1 = gen_new_label();
5860 74d37793 aurel32
        tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_xer);
5861 74d37793 aurel32
        tcg_gen_shri_i32(cpu_crf[0], cpu_crf[0], XER_SO);
5862 74d37793 aurel32
        tcg_gen_andi_i32(cpu_crf[0], cpu_crf[0], 1);
5863 74d37793 aurel32
        tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
5864 74d37793 aurel32
        tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
5865 74d37793 aurel32
        gen_set_label(l1);
5866 74d37793 aurel32
    }
5867 76a66253 j_mayer
#endif
5868 79aceca5 bellard
}
5869 79aceca5 bellard
5870 76a66253 j_mayer
/* tlbwe */
5871 e8eaa2c0 Blue Swirl
static void gen_tlbwe_40x(DisasContext *ctx)
5872 79aceca5 bellard
{
5873 76a66253 j_mayer
#if defined(CONFIG_USER_ONLY)
5874 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5875 76a66253 j_mayer
#else
5876 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5877 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5878 76a66253 j_mayer
        return;
5879 76a66253 j_mayer
    }
5880 76a66253 j_mayer
    switch (rB(ctx->opcode)) {
5881 76a66253 j_mayer
    case 0:
5882 74d37793 aurel32
        gen_helper_4xx_tlbwe_hi(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
5883 76a66253 j_mayer
        break;
5884 76a66253 j_mayer
    case 1:
5885 74d37793 aurel32
        gen_helper_4xx_tlbwe_lo(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
5886 76a66253 j_mayer
        break;
5887 76a66253 j_mayer
    default:
5888 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5889 76a66253 j_mayer
        break;
5890 9a64fbe4 bellard
    }
5891 76a66253 j_mayer
#endif
5892 76a66253 j_mayer
}
5893 76a66253 j_mayer
5894 a4bb6c3e j_mayer
/* TLB management - PowerPC 440 implementation */
5895 e8eaa2c0 Blue Swirl
5896 54623277 Blue Swirl
/* tlbre */
5897 e8eaa2c0 Blue Swirl
static void gen_tlbre_440(DisasContext *ctx)
5898 5eb7995e j_mayer
{
5899 5eb7995e j_mayer
#if defined(CONFIG_USER_ONLY)
5900 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5901 5eb7995e j_mayer
#else
5902 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5903 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5904 5eb7995e j_mayer
        return;
5905 5eb7995e j_mayer
    }
5906 5eb7995e j_mayer
    switch (rB(ctx->opcode)) {
5907 5eb7995e j_mayer
    case 0:
5908 5eb7995e j_mayer
    case 1:
5909 5eb7995e j_mayer
    case 2:
5910 74d37793 aurel32
        {
5911 74d37793 aurel32
            TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
5912 5823947f Edgar E. Iglesias
            gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], t0, cpu_gpr[rA(ctx->opcode)]);
5913 74d37793 aurel32
            tcg_temp_free_i32(t0);
5914 74d37793 aurel32
        }
5915 5eb7995e j_mayer
        break;
5916 5eb7995e j_mayer
    default:
5917 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5918 5eb7995e j_mayer
        break;
5919 5eb7995e j_mayer
    }
5920 5eb7995e j_mayer
#endif
5921 5eb7995e j_mayer
}
5922 5eb7995e j_mayer
5923 5eb7995e j_mayer
/* tlbsx - tlbsx. */
5924 e8eaa2c0 Blue Swirl
static void gen_tlbsx_440(DisasContext *ctx)
5925 5eb7995e j_mayer
{
5926 5eb7995e j_mayer
#if defined(CONFIG_USER_ONLY)
5927 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5928 5eb7995e j_mayer
#else
5929 74d37793 aurel32
    TCGv t0;
5930 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5931 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5932 5eb7995e j_mayer
        return;
5933 5eb7995e j_mayer
    }
5934 74d37793 aurel32
    t0 = tcg_temp_new();
5935 76db3ba4 aurel32
    gen_addr_reg_index(ctx, t0);
5936 74d37793 aurel32
    gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], t0);
5937 74d37793 aurel32
    tcg_temp_free(t0);
5938 74d37793 aurel32
    if (Rc(ctx->opcode)) {
5939 74d37793 aurel32
        int l1 = gen_new_label();
5940 74d37793 aurel32
        tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_xer);
5941 74d37793 aurel32
        tcg_gen_shri_i32(cpu_crf[0], cpu_crf[0], XER_SO);
5942 74d37793 aurel32
        tcg_gen_andi_i32(cpu_crf[0], cpu_crf[0], 1);
5943 74d37793 aurel32
        tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1);
5944 74d37793 aurel32
        tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02);
5945 74d37793 aurel32
        gen_set_label(l1);
5946 74d37793 aurel32
    }
5947 5eb7995e j_mayer
#endif
5948 5eb7995e j_mayer
}
5949 5eb7995e j_mayer
5950 5eb7995e j_mayer
/* tlbwe */
5951 e8eaa2c0 Blue Swirl
static void gen_tlbwe_440(DisasContext *ctx)
5952 5eb7995e j_mayer
{
5953 5eb7995e j_mayer
#if defined(CONFIG_USER_ONLY)
5954 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5955 5eb7995e j_mayer
#else
5956 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5957 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5958 5eb7995e j_mayer
        return;
5959 5eb7995e j_mayer
    }
5960 5eb7995e j_mayer
    switch (rB(ctx->opcode)) {
5961 5eb7995e j_mayer
    case 0:
5962 5eb7995e j_mayer
    case 1:
5963 5eb7995e j_mayer
    case 2:
5964 74d37793 aurel32
        {
5965 74d37793 aurel32
            TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode));
5966 74d37793 aurel32
            gen_helper_440_tlbwe(t0, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
5967 74d37793 aurel32
            tcg_temp_free_i32(t0);
5968 74d37793 aurel32
        }
5969 5eb7995e j_mayer
        break;
5970 5eb7995e j_mayer
    default:
5971 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
5972 5eb7995e j_mayer
        break;
5973 5eb7995e j_mayer
    }
5974 5eb7995e j_mayer
#endif
5975 5eb7995e j_mayer
}
5976 5eb7995e j_mayer
5977 76a66253 j_mayer
/* wrtee */
5978 99e300ef Blue Swirl
static void gen_wrtee(DisasContext *ctx)
5979 76a66253 j_mayer
{
5980 76a66253 j_mayer
#if defined(CONFIG_USER_ONLY)
5981 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5982 76a66253 j_mayer
#else
5983 6527f6ea aurel32
    TCGv t0;
5984 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
5985 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
5986 76a66253 j_mayer
        return;
5987 76a66253 j_mayer
    }
5988 6527f6ea aurel32
    t0 = tcg_temp_new();
5989 6527f6ea aurel32
    tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE));
5990 6527f6ea aurel32
    tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
5991 6527f6ea aurel32
    tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
5992 6527f6ea aurel32
    tcg_temp_free(t0);
5993 dee96f6c j_mayer
    /* Stop translation to have a chance to raise an exception
5994 dee96f6c j_mayer
     * if we just set msr_ee to 1
5995 dee96f6c j_mayer
     */
5996 e06fcd75 aurel32
    gen_stop_exception(ctx);
5997 76a66253 j_mayer
#endif
5998 76a66253 j_mayer
}
5999 76a66253 j_mayer
6000 76a66253 j_mayer
/* wrteei */
6001 99e300ef Blue Swirl
static void gen_wrteei(DisasContext *ctx)
6002 76a66253 j_mayer
{
6003 76a66253 j_mayer
#if defined(CONFIG_USER_ONLY)
6004 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6005 76a66253 j_mayer
#else
6006 76db3ba4 aurel32
    if (unlikely(!ctx->mem_idx)) {
6007 e06fcd75 aurel32
        gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
6008 76a66253 j_mayer
        return;
6009 76a66253 j_mayer
    }
6010 fbe73008 Baojun Wang
    if (ctx->opcode & 0x00008000) {
6011 6527f6ea aurel32
        tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE));
6012 6527f6ea aurel32
        /* Stop translation to have a chance to raise an exception */
6013 e06fcd75 aurel32
        gen_stop_exception(ctx);
6014 6527f6ea aurel32
    } else {
6015 1b6e5f99 aurel32
        tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE));
6016 6527f6ea aurel32
    }
6017 76a66253 j_mayer
#endif
6018 76a66253 j_mayer
}
6019 76a66253 j_mayer
6020 08e46e54 j_mayer
/* PowerPC 440 specific instructions */
6021 99e300ef Blue Swirl
6022 54623277 Blue Swirl
/* dlmzb */
6023 99e300ef Blue Swirl
static void gen_dlmzb(DisasContext *ctx)
6024 76a66253 j_mayer
{
6025 ef0d51af aurel32
    TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode));
6026 ef0d51af aurel32
    gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)],
6027 ef0d51af aurel32
                     cpu_gpr[rB(ctx->opcode)], t0);
6028 ef0d51af aurel32
    tcg_temp_free_i32(t0);
6029 76a66253 j_mayer
}
6030 76a66253 j_mayer
6031 76a66253 j_mayer
/* mbar replaces eieio on 440 */
6032 99e300ef Blue Swirl
static void gen_mbar(DisasContext *ctx)
6033 76a66253 j_mayer
{
6034 76a66253 j_mayer
    /* interpreted as no-op */
6035 76a66253 j_mayer
}
6036 76a66253 j_mayer
6037 76a66253 j_mayer
/* msync replaces sync on 440 */
6038 99e300ef Blue Swirl
static void gen_msync(DisasContext *ctx)
6039 76a66253 j_mayer
{
6040 76a66253 j_mayer
    /* interpreted as no-op */
6041 76a66253 j_mayer
}
6042 76a66253 j_mayer
6043 76a66253 j_mayer
/* icbt */
6044 e8eaa2c0 Blue Swirl
static void gen_icbt_440(DisasContext *ctx)
6045 76a66253 j_mayer
{
6046 76a66253 j_mayer
    /* interpreted as no-op */
6047 76a66253 j_mayer
    /* XXX: specification say this is treated as a load by the MMU
6048 76a66253 j_mayer
     *      but does not generate any exception
6049 76a66253 j_mayer
     */
6050 79aceca5 bellard
}
6051 79aceca5 bellard
6052 a9d9eb8f j_mayer
/***                      Altivec vector extension                         ***/
6053 a9d9eb8f j_mayer
/* Altivec registers moves */
6054 a9d9eb8f j_mayer
6055 636aa200 Blue Swirl
static inline TCGv_ptr gen_avr_ptr(int reg)
6056 564e571a aurel32
{
6057 e4704b3b aurel32
    TCGv_ptr r = tcg_temp_new_ptr();
6058 564e571a aurel32
    tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg]));
6059 564e571a aurel32
    return r;
6060 564e571a aurel32
}
6061 564e571a aurel32
6062 a9d9eb8f j_mayer
#define GEN_VR_LDX(name, opc2, opc3)                                          \
6063 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                                       \
6064 a9d9eb8f j_mayer
{                                                                             \
6065 fe1e5c53 aurel32
    TCGv EA;                                                                  \
6066 a9d9eb8f j_mayer
    if (unlikely(!ctx->altivec_enabled)) {                                    \
6067 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_VPU);                                 \
6068 a9d9eb8f j_mayer
        return;                                                               \
6069 a9d9eb8f j_mayer
    }                                                                         \
6070 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_INT);                                     \
6071 fe1e5c53 aurel32
    EA = tcg_temp_new();                                                      \
6072 76db3ba4 aurel32
    gen_addr_reg_index(ctx, EA);                                              \
6073 fe1e5c53 aurel32
    tcg_gen_andi_tl(EA, EA, ~0xf);                                            \
6074 76db3ba4 aurel32
    if (ctx->le_mode) {                                                       \
6075 76db3ba4 aurel32
        gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA);                    \
6076 fe1e5c53 aurel32
        tcg_gen_addi_tl(EA, EA, 8);                                           \
6077 76db3ba4 aurel32
        gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA);                    \
6078 fe1e5c53 aurel32
    } else {                                                                  \
6079 76db3ba4 aurel32
        gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA);                    \
6080 fe1e5c53 aurel32
        tcg_gen_addi_tl(EA, EA, 8);                                           \
6081 76db3ba4 aurel32
        gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA);                    \
6082 fe1e5c53 aurel32
    }                                                                         \
6083 fe1e5c53 aurel32
    tcg_temp_free(EA);                                                        \
6084 a9d9eb8f j_mayer
}
6085 a9d9eb8f j_mayer
6086 a9d9eb8f j_mayer
#define GEN_VR_STX(name, opc2, opc3)                                          \
6087 99e300ef Blue Swirl
static void gen_st##name(DisasContext *ctx)                                   \
6088 a9d9eb8f j_mayer
{                                                                             \
6089 fe1e5c53 aurel32
    TCGv EA;                                                                  \
6090 a9d9eb8f j_mayer
    if (unlikely(!ctx->altivec_enabled)) {                                    \
6091 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_VPU);                                 \
6092 a9d9eb8f j_mayer
        return;                                                               \
6093 a9d9eb8f j_mayer
    }                                                                         \
6094 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_INT);                                     \
6095 fe1e5c53 aurel32
    EA = tcg_temp_new();                                                      \
6096 76db3ba4 aurel32
    gen_addr_reg_index(ctx, EA);                                              \
6097 fe1e5c53 aurel32
    tcg_gen_andi_tl(EA, EA, ~0xf);                                            \
6098 76db3ba4 aurel32
    if (ctx->le_mode) {                                                       \
6099 76db3ba4 aurel32
        gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA);                    \
6100 fe1e5c53 aurel32
        tcg_gen_addi_tl(EA, EA, 8);                                           \
6101 76db3ba4 aurel32
        gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA);                    \
6102 fe1e5c53 aurel32
    } else {                                                                  \
6103 76db3ba4 aurel32
        gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA);                    \
6104 fe1e5c53 aurel32
        tcg_gen_addi_tl(EA, EA, 8);                                           \
6105 76db3ba4 aurel32
        gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA);                    \
6106 fe1e5c53 aurel32
    }                                                                         \
6107 fe1e5c53 aurel32
    tcg_temp_free(EA);                                                        \
6108 a9d9eb8f j_mayer
}
6109 a9d9eb8f j_mayer
6110 cbfb6ae9 aurel32
#define GEN_VR_LVE(name, opc2, opc3)                                    \
6111 99e300ef Blue Swirl
static void gen_lve##name(DisasContext *ctx)                            \
6112 cbfb6ae9 aurel32
    {                                                                   \
6113 cbfb6ae9 aurel32
        TCGv EA;                                                        \
6114 cbfb6ae9 aurel32
        TCGv_ptr rs;                                                    \
6115 cbfb6ae9 aurel32
        if (unlikely(!ctx->altivec_enabled)) {                          \
6116 cbfb6ae9 aurel32
            gen_exception(ctx, POWERPC_EXCP_VPU);                       \
6117 cbfb6ae9 aurel32
            return;                                                     \
6118 cbfb6ae9 aurel32
        }                                                               \
6119 cbfb6ae9 aurel32
        gen_set_access_type(ctx, ACCESS_INT);                           \
6120 cbfb6ae9 aurel32
        EA = tcg_temp_new();                                            \
6121 cbfb6ae9 aurel32
        gen_addr_reg_index(ctx, EA);                                    \
6122 cbfb6ae9 aurel32
        rs = gen_avr_ptr(rS(ctx->opcode));                              \
6123 cbfb6ae9 aurel32
        gen_helper_lve##name (rs, EA);                                  \
6124 cbfb6ae9 aurel32
        tcg_temp_free(EA);                                              \
6125 cbfb6ae9 aurel32
        tcg_temp_free_ptr(rs);                                          \
6126 cbfb6ae9 aurel32
    }
6127 cbfb6ae9 aurel32
6128 cbfb6ae9 aurel32
#define GEN_VR_STVE(name, opc2, opc3)                                   \
6129 99e300ef Blue Swirl
static void gen_stve##name(DisasContext *ctx)                           \
6130 cbfb6ae9 aurel32
    {                                                                   \
6131 cbfb6ae9 aurel32
        TCGv EA;                                                        \
6132 cbfb6ae9 aurel32
        TCGv_ptr rs;                                                    \
6133 cbfb6ae9 aurel32
        if (unlikely(!ctx->altivec_enabled)) {                          \
6134 cbfb6ae9 aurel32
            gen_exception(ctx, POWERPC_EXCP_VPU);                       \
6135 cbfb6ae9 aurel32
            return;                                                     \
6136 cbfb6ae9 aurel32
        }                                                               \
6137 cbfb6ae9 aurel32
        gen_set_access_type(ctx, ACCESS_INT);                           \
6138 cbfb6ae9 aurel32
        EA = tcg_temp_new();                                            \
6139 cbfb6ae9 aurel32
        gen_addr_reg_index(ctx, EA);                                    \
6140 cbfb6ae9 aurel32
        rs = gen_avr_ptr(rS(ctx->opcode));                              \
6141 cbfb6ae9 aurel32
        gen_helper_stve##name (rs, EA);                                 \
6142 cbfb6ae9 aurel32
        tcg_temp_free(EA);                                              \
6143 cbfb6ae9 aurel32
        tcg_temp_free_ptr(rs);                                          \
6144 cbfb6ae9 aurel32
    }
6145 cbfb6ae9 aurel32
6146 fe1e5c53 aurel32
GEN_VR_LDX(lvx, 0x07, 0x03);
6147 a9d9eb8f j_mayer
/* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
6148 fe1e5c53 aurel32
GEN_VR_LDX(lvxl, 0x07, 0x0B);
6149 a9d9eb8f j_mayer
6150 cbfb6ae9 aurel32
GEN_VR_LVE(bx, 0x07, 0x00);
6151 cbfb6ae9 aurel32
GEN_VR_LVE(hx, 0x07, 0x01);
6152 cbfb6ae9 aurel32
GEN_VR_LVE(wx, 0x07, 0x02);
6153 cbfb6ae9 aurel32
6154 fe1e5c53 aurel32
GEN_VR_STX(svx, 0x07, 0x07);
6155 a9d9eb8f j_mayer
/* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
6156 fe1e5c53 aurel32
GEN_VR_STX(svxl, 0x07, 0x0F);
6157 a9d9eb8f j_mayer
6158 cbfb6ae9 aurel32
GEN_VR_STVE(bx, 0x07, 0x04);
6159 cbfb6ae9 aurel32
GEN_VR_STVE(hx, 0x07, 0x05);
6160 cbfb6ae9 aurel32
GEN_VR_STVE(wx, 0x07, 0x06);
6161 cbfb6ae9 aurel32
6162 99e300ef Blue Swirl
static void gen_lvsl(DisasContext *ctx)
6163 bf8d8ded aurel32
{
6164 bf8d8ded aurel32
    TCGv_ptr rd;
6165 bf8d8ded aurel32
    TCGv EA;
6166 bf8d8ded aurel32
    if (unlikely(!ctx->altivec_enabled)) {
6167 bf8d8ded aurel32
        gen_exception(ctx, POWERPC_EXCP_VPU);
6168 bf8d8ded aurel32
        return;
6169 bf8d8ded aurel32
    }
6170 bf8d8ded aurel32
    EA = tcg_temp_new();
6171 bf8d8ded aurel32
    gen_addr_reg_index(ctx, EA);
6172 bf8d8ded aurel32
    rd = gen_avr_ptr(rD(ctx->opcode));
6173 bf8d8ded aurel32
    gen_helper_lvsl(rd, EA);
6174 bf8d8ded aurel32
    tcg_temp_free(EA);
6175 bf8d8ded aurel32
    tcg_temp_free_ptr(rd);
6176 bf8d8ded aurel32
}
6177 bf8d8ded aurel32
6178 99e300ef Blue Swirl
static void gen_lvsr(DisasContext *ctx)
6179 bf8d8ded aurel32
{
6180 bf8d8ded aurel32
    TCGv_ptr rd;
6181 bf8d8ded aurel32
    TCGv EA;
6182 bf8d8ded aurel32
    if (unlikely(!ctx->altivec_enabled)) {
6183 bf8d8ded aurel32
        gen_exception(ctx, POWERPC_EXCP_VPU);
6184 bf8d8ded aurel32
        return;
6185 bf8d8ded aurel32
    }
6186 bf8d8ded aurel32
    EA = tcg_temp_new();
6187 bf8d8ded aurel32
    gen_addr_reg_index(ctx, EA);
6188 bf8d8ded aurel32
    rd = gen_avr_ptr(rD(ctx->opcode));
6189 bf8d8ded aurel32
    gen_helper_lvsr(rd, EA);
6190 bf8d8ded aurel32
    tcg_temp_free(EA);
6191 bf8d8ded aurel32
    tcg_temp_free_ptr(rd);
6192 bf8d8ded aurel32
}
6193 bf8d8ded aurel32
6194 99e300ef Blue Swirl
static void gen_mfvscr(DisasContext *ctx)
6195 785f451b aurel32
{
6196 785f451b aurel32
    TCGv_i32 t;
6197 785f451b aurel32
    if (unlikely(!ctx->altivec_enabled)) {
6198 785f451b aurel32
        gen_exception(ctx, POWERPC_EXCP_VPU);
6199 785f451b aurel32
        return;
6200 785f451b aurel32
    }
6201 785f451b aurel32
    tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0);
6202 785f451b aurel32
    t = tcg_temp_new_i32();
6203 785f451b aurel32
    tcg_gen_ld_i32(t, cpu_env, offsetof(CPUState, vscr));
6204 785f451b aurel32
    tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t);
6205 fce5ecb7 aurel32
    tcg_temp_free_i32(t);
6206 785f451b aurel32
}
6207 785f451b aurel32
6208 99e300ef Blue Swirl
static void gen_mtvscr(DisasContext *ctx)
6209 785f451b aurel32
{
6210 6e87b7c7 aurel32
    TCGv_ptr p;
6211 785f451b aurel32
    if (unlikely(!ctx->altivec_enabled)) {
6212 785f451b aurel32
        gen_exception(ctx, POWERPC_EXCP_VPU);
6213 785f451b aurel32
        return;
6214 785f451b aurel32
    }
6215 6e87b7c7 aurel32
    p = gen_avr_ptr(rD(ctx->opcode));
6216 6e87b7c7 aurel32
    gen_helper_mtvscr(p);
6217 6e87b7c7 aurel32
    tcg_temp_free_ptr(p);
6218 785f451b aurel32
}
6219 785f451b aurel32
6220 7a9b96cf aurel32
/* Logical operations */
6221 7a9b96cf aurel32
#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3)                        \
6222 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                                 \
6223 7a9b96cf aurel32
{                                                                       \
6224 7a9b96cf aurel32
    if (unlikely(!ctx->altivec_enabled)) {                              \
6225 7a9b96cf aurel32
        gen_exception(ctx, POWERPC_EXCP_VPU);                           \
6226 7a9b96cf aurel32
        return;                                                         \
6227 7a9b96cf aurel32
    }                                                                   \
6228 7a9b96cf aurel32
    tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6229 7a9b96cf aurel32
    tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6230 7a9b96cf aurel32
}
6231 7a9b96cf aurel32
6232 7a9b96cf aurel32
GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16);
6233 7a9b96cf aurel32
GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17);
6234 7a9b96cf aurel32
GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18);
6235 7a9b96cf aurel32
GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19);
6236 7a9b96cf aurel32
GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20);
6237 7a9b96cf aurel32
6238 8e27dd6f aurel32
#define GEN_VXFORM(name, opc2, opc3)                                    \
6239 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                                 \
6240 8e27dd6f aurel32
{                                                                       \
6241 8e27dd6f aurel32
    TCGv_ptr ra, rb, rd;                                                \
6242 8e27dd6f aurel32
    if (unlikely(!ctx->altivec_enabled)) {                              \
6243 8e27dd6f aurel32
        gen_exception(ctx, POWERPC_EXCP_VPU);                           \
6244 8e27dd6f aurel32
        return;                                                         \
6245 8e27dd6f aurel32
    }                                                                   \
6246 8e27dd6f aurel32
    ra = gen_avr_ptr(rA(ctx->opcode));                                  \
6247 8e27dd6f aurel32
    rb = gen_avr_ptr(rB(ctx->opcode));                                  \
6248 8e27dd6f aurel32
    rd = gen_avr_ptr(rD(ctx->opcode));                                  \
6249 8e27dd6f aurel32
    gen_helper_##name (rd, ra, rb);                                     \
6250 8e27dd6f aurel32
    tcg_temp_free_ptr(ra);                                              \
6251 8e27dd6f aurel32
    tcg_temp_free_ptr(rb);                                              \
6252 8e27dd6f aurel32
    tcg_temp_free_ptr(rd);                                              \
6253 8e27dd6f aurel32
}
6254 8e27dd6f aurel32
6255 7872c51c aurel32
GEN_VXFORM(vaddubm, 0, 0);
6256 7872c51c aurel32
GEN_VXFORM(vadduhm, 0, 1);
6257 7872c51c aurel32
GEN_VXFORM(vadduwm, 0, 2);
6258 7872c51c aurel32
GEN_VXFORM(vsububm, 0, 16);
6259 7872c51c aurel32
GEN_VXFORM(vsubuhm, 0, 17);
6260 7872c51c aurel32
GEN_VXFORM(vsubuwm, 0, 18);
6261 e4039339 aurel32
GEN_VXFORM(vmaxub, 1, 0);
6262 e4039339 aurel32
GEN_VXFORM(vmaxuh, 1, 1);
6263 e4039339 aurel32
GEN_VXFORM(vmaxuw, 1, 2);
6264 e4039339 aurel32
GEN_VXFORM(vmaxsb, 1, 4);
6265 e4039339 aurel32
GEN_VXFORM(vmaxsh, 1, 5);
6266 e4039339 aurel32
GEN_VXFORM(vmaxsw, 1, 6);
6267 e4039339 aurel32
GEN_VXFORM(vminub, 1, 8);
6268 e4039339 aurel32
GEN_VXFORM(vminuh, 1, 9);
6269 e4039339 aurel32
GEN_VXFORM(vminuw, 1, 10);
6270 e4039339 aurel32
GEN_VXFORM(vminsb, 1, 12);
6271 e4039339 aurel32
GEN_VXFORM(vminsh, 1, 13);
6272 e4039339 aurel32
GEN_VXFORM(vminsw, 1, 14);
6273 fab3cbe9 aurel32
GEN_VXFORM(vavgub, 1, 16);
6274 fab3cbe9 aurel32
GEN_VXFORM(vavguh, 1, 17);
6275 fab3cbe9 aurel32
GEN_VXFORM(vavguw, 1, 18);
6276 fab3cbe9 aurel32
GEN_VXFORM(vavgsb, 1, 20);
6277 fab3cbe9 aurel32
GEN_VXFORM(vavgsh, 1, 21);
6278 fab3cbe9 aurel32
GEN_VXFORM(vavgsw, 1, 22);
6279 3b430048 aurel32
GEN_VXFORM(vmrghb, 6, 0);
6280 3b430048 aurel32
GEN_VXFORM(vmrghh, 6, 1);
6281 3b430048 aurel32
GEN_VXFORM(vmrghw, 6, 2);
6282 3b430048 aurel32
GEN_VXFORM(vmrglb, 6, 4);
6283 3b430048 aurel32
GEN_VXFORM(vmrglh, 6, 5);
6284 3b430048 aurel32
GEN_VXFORM(vmrglw, 6, 6);
6285 2c277908 aurel32
GEN_VXFORM(vmuloub, 4, 0);
6286 2c277908 aurel32
GEN_VXFORM(vmulouh, 4, 1);
6287 2c277908 aurel32
GEN_VXFORM(vmulosb, 4, 4);
6288 2c277908 aurel32
GEN_VXFORM(vmulosh, 4, 5);
6289 2c277908 aurel32
GEN_VXFORM(vmuleub, 4, 8);
6290 2c277908 aurel32
GEN_VXFORM(vmuleuh, 4, 9);
6291 2c277908 aurel32
GEN_VXFORM(vmulesb, 4, 12);
6292 2c277908 aurel32
GEN_VXFORM(vmulesh, 4, 13);
6293 d79f0809 aurel32
GEN_VXFORM(vslb, 2, 4);
6294 d79f0809 aurel32
GEN_VXFORM(vslh, 2, 5);
6295 d79f0809 aurel32
GEN_VXFORM(vslw, 2, 6);
6296 07ef34c3 aurel32
GEN_VXFORM(vsrb, 2, 8);
6297 07ef34c3 aurel32
GEN_VXFORM(vsrh, 2, 9);
6298 07ef34c3 aurel32
GEN_VXFORM(vsrw, 2, 10);
6299 07ef34c3 aurel32
GEN_VXFORM(vsrab, 2, 12);
6300 07ef34c3 aurel32
GEN_VXFORM(vsrah, 2, 13);
6301 07ef34c3 aurel32
GEN_VXFORM(vsraw, 2, 14);
6302 7b239bec aurel32
GEN_VXFORM(vslo, 6, 16);
6303 7b239bec aurel32
GEN_VXFORM(vsro, 6, 17);
6304 e343da72 aurel32
GEN_VXFORM(vaddcuw, 0, 6);
6305 e343da72 aurel32
GEN_VXFORM(vsubcuw, 0, 22);
6306 5ab09f33 aurel32
GEN_VXFORM(vaddubs, 0, 8);
6307 5ab09f33 aurel32
GEN_VXFORM(vadduhs, 0, 9);
6308 5ab09f33 aurel32
GEN_VXFORM(vadduws, 0, 10);
6309 5ab09f33 aurel32
GEN_VXFORM(vaddsbs, 0, 12);
6310 5ab09f33 aurel32
GEN_VXFORM(vaddshs, 0, 13);
6311 5ab09f33 aurel32
GEN_VXFORM(vaddsws, 0, 14);
6312 5ab09f33 aurel32
GEN_VXFORM(vsububs, 0, 24);
6313 5ab09f33 aurel32
GEN_VXFORM(vsubuhs, 0, 25);
6314 5ab09f33 aurel32
GEN_VXFORM(vsubuws, 0, 26);
6315 5ab09f33 aurel32
GEN_VXFORM(vsubsbs, 0, 28);
6316 5ab09f33 aurel32
GEN_VXFORM(vsubshs, 0, 29);
6317 5ab09f33 aurel32
GEN_VXFORM(vsubsws, 0, 30);
6318 5e1d0985 aurel32
GEN_VXFORM(vrlb, 2, 0);
6319 5e1d0985 aurel32
GEN_VXFORM(vrlh, 2, 1);
6320 5e1d0985 aurel32
GEN_VXFORM(vrlw, 2, 2);
6321 d9430add aurel32
GEN_VXFORM(vsl, 2, 7);
6322 d9430add aurel32
GEN_VXFORM(vsr, 2, 11);
6323 5335a145 aurel32
GEN_VXFORM(vpkuhum, 7, 0);
6324 5335a145 aurel32
GEN_VXFORM(vpkuwum, 7, 1);
6325 5335a145 aurel32
GEN_VXFORM(vpkuhus, 7, 2);
6326 5335a145 aurel32
GEN_VXFORM(vpkuwus, 7, 3);
6327 5335a145 aurel32
GEN_VXFORM(vpkshus, 7, 4);
6328 5335a145 aurel32
GEN_VXFORM(vpkswus, 7, 5);
6329 5335a145 aurel32
GEN_VXFORM(vpkshss, 7, 6);
6330 5335a145 aurel32
GEN_VXFORM(vpkswss, 7, 7);
6331 1dd9ffb9 aurel32
GEN_VXFORM(vpkpx, 7, 12);
6332 8142cddd aurel32
GEN_VXFORM(vsum4ubs, 4, 24);
6333 8142cddd aurel32
GEN_VXFORM(vsum4sbs, 4, 28);
6334 8142cddd aurel32
GEN_VXFORM(vsum4shs, 4, 25);
6335 8142cddd aurel32
GEN_VXFORM(vsum2sws, 4, 26);
6336 8142cddd aurel32
GEN_VXFORM(vsumsws, 4, 30);
6337 56fdd213 aurel32
GEN_VXFORM(vaddfp, 5, 0);
6338 56fdd213 aurel32
GEN_VXFORM(vsubfp, 5, 1);
6339 1536ff64 aurel32
GEN_VXFORM(vmaxfp, 5, 16);
6340 1536ff64 aurel32
GEN_VXFORM(vminfp, 5, 17);
6341 fab3cbe9 aurel32
6342 0cbcd906 aurel32
#define GEN_VXRFORM1(opname, name, str, opc2, opc3)                     \
6343 e8eaa2c0 Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                         \
6344 0cbcd906 aurel32
    {                                                                   \
6345 0cbcd906 aurel32
        TCGv_ptr ra, rb, rd;                                            \
6346 0cbcd906 aurel32
        if (unlikely(!ctx->altivec_enabled)) {                          \
6347 0cbcd906 aurel32
            gen_exception(ctx, POWERPC_EXCP_VPU);                       \
6348 0cbcd906 aurel32
            return;                                                     \
6349 0cbcd906 aurel32
        }                                                               \
6350 0cbcd906 aurel32
        ra = gen_avr_ptr(rA(ctx->opcode));                              \
6351 0cbcd906 aurel32
        rb = gen_avr_ptr(rB(ctx->opcode));                              \
6352 0cbcd906 aurel32
        rd = gen_avr_ptr(rD(ctx->opcode));                              \
6353 0cbcd906 aurel32
        gen_helper_##opname (rd, ra, rb);                               \
6354 0cbcd906 aurel32
        tcg_temp_free_ptr(ra);                                          \
6355 0cbcd906 aurel32
        tcg_temp_free_ptr(rb);                                          \
6356 0cbcd906 aurel32
        tcg_temp_free_ptr(rd);                                          \
6357 0cbcd906 aurel32
    }
6358 0cbcd906 aurel32
6359 0cbcd906 aurel32
#define GEN_VXRFORM(name, opc2, opc3)                                \
6360 0cbcd906 aurel32
    GEN_VXRFORM1(name, name, #name, opc2, opc3)                      \
6361 0cbcd906 aurel32
    GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
6362 0cbcd906 aurel32
6363 1add6e23 aurel32
GEN_VXRFORM(vcmpequb, 3, 0)
6364 1add6e23 aurel32
GEN_VXRFORM(vcmpequh, 3, 1)
6365 1add6e23 aurel32
GEN_VXRFORM(vcmpequw, 3, 2)
6366 1add6e23 aurel32
GEN_VXRFORM(vcmpgtsb, 3, 12)
6367 1add6e23 aurel32
GEN_VXRFORM(vcmpgtsh, 3, 13)
6368 1add6e23 aurel32
GEN_VXRFORM(vcmpgtsw, 3, 14)
6369 1add6e23 aurel32
GEN_VXRFORM(vcmpgtub, 3, 8)
6370 1add6e23 aurel32
GEN_VXRFORM(vcmpgtuh, 3, 9)
6371 1add6e23 aurel32
GEN_VXRFORM(vcmpgtuw, 3, 10)
6372 819ca121 aurel32
GEN_VXRFORM(vcmpeqfp, 3, 3)
6373 819ca121 aurel32
GEN_VXRFORM(vcmpgefp, 3, 7)
6374 819ca121 aurel32
GEN_VXRFORM(vcmpgtfp, 3, 11)
6375 819ca121 aurel32
GEN_VXRFORM(vcmpbfp, 3, 15)
6376 1add6e23 aurel32
6377 c026766b aurel32
#define GEN_VXFORM_SIMM(name, opc2, opc3)                               \
6378 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                         \
6379 c026766b aurel32
    {                                                                   \
6380 c026766b aurel32
        TCGv_ptr rd;                                                    \
6381 c026766b aurel32
        TCGv_i32 simm;                                                  \
6382 c026766b aurel32
        if (unlikely(!ctx->altivec_enabled)) {                          \
6383 c026766b aurel32
            gen_exception(ctx, POWERPC_EXCP_VPU);                       \
6384 c026766b aurel32
            return;                                                     \
6385 c026766b aurel32
        }                                                               \
6386 c026766b aurel32
        simm = tcg_const_i32(SIMM5(ctx->opcode));                       \
6387 c026766b aurel32
        rd = gen_avr_ptr(rD(ctx->opcode));                              \
6388 c026766b aurel32
        gen_helper_##name (rd, simm);                                   \
6389 c026766b aurel32
        tcg_temp_free_i32(simm);                                        \
6390 c026766b aurel32
        tcg_temp_free_ptr(rd);                                          \
6391 c026766b aurel32
    }
6392 c026766b aurel32
6393 c026766b aurel32
GEN_VXFORM_SIMM(vspltisb, 6, 12);
6394 c026766b aurel32
GEN_VXFORM_SIMM(vspltish, 6, 13);
6395 c026766b aurel32
GEN_VXFORM_SIMM(vspltisw, 6, 14);
6396 c026766b aurel32
6397 de5f2484 aurel32
#define GEN_VXFORM_NOA(name, opc2, opc3)                                \
6398 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                                 \
6399 de5f2484 aurel32
    {                                                                   \
6400 de5f2484 aurel32
        TCGv_ptr rb, rd;                                                \
6401 de5f2484 aurel32
        if (unlikely(!ctx->altivec_enabled)) {                          \
6402 de5f2484 aurel32
            gen_exception(ctx, POWERPC_EXCP_VPU);                       \
6403 de5f2484 aurel32
            return;                                                     \
6404 de5f2484 aurel32
        }                                                               \
6405 de5f2484 aurel32
        rb = gen_avr_ptr(rB(ctx->opcode));                              \
6406 de5f2484 aurel32
        rd = gen_avr_ptr(rD(ctx->opcode));                              \
6407 de5f2484 aurel32
        gen_helper_##name (rd, rb);                                     \
6408 de5f2484 aurel32
        tcg_temp_free_ptr(rb);                                          \
6409 de5f2484 aurel32
        tcg_temp_free_ptr(rd);                                         \
6410 de5f2484 aurel32
    }
6411 de5f2484 aurel32
6412 6cf1c6e5 aurel32
GEN_VXFORM_NOA(vupkhsb, 7, 8);
6413 6cf1c6e5 aurel32
GEN_VXFORM_NOA(vupkhsh, 7, 9);
6414 6cf1c6e5 aurel32
GEN_VXFORM_NOA(vupklsb, 7, 10);
6415 6cf1c6e5 aurel32
GEN_VXFORM_NOA(vupklsh, 7, 11);
6416 79f85c3a aurel32
GEN_VXFORM_NOA(vupkhpx, 7, 13);
6417 79f85c3a aurel32
GEN_VXFORM_NOA(vupklpx, 7, 15);
6418 bdfbac35 aurel32
GEN_VXFORM_NOA(vrefp, 5, 4);
6419 071fc3b1 aurel32
GEN_VXFORM_NOA(vrsqrtefp, 5, 5);
6420 0bffbc6c Aurelien Jarno
GEN_VXFORM_NOA(vexptefp, 5, 6);
6421 b580763f aurel32
GEN_VXFORM_NOA(vlogefp, 5, 7);
6422 f6b19645 aurel32
GEN_VXFORM_NOA(vrfim, 5, 8);
6423 f6b19645 aurel32
GEN_VXFORM_NOA(vrfin, 5, 9);
6424 f6b19645 aurel32
GEN_VXFORM_NOA(vrfip, 5, 10);
6425 f6b19645 aurel32
GEN_VXFORM_NOA(vrfiz, 5, 11);
6426 79f85c3a aurel32
6427 21d21583 aurel32
#define GEN_VXFORM_SIMM(name, opc2, opc3)                               \
6428 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                                 \
6429 21d21583 aurel32
    {                                                                   \
6430 21d21583 aurel32
        TCGv_ptr rd;                                                    \
6431 21d21583 aurel32
        TCGv_i32 simm;                                                  \
6432 21d21583 aurel32
        if (unlikely(!ctx->altivec_enabled)) {                          \
6433 21d21583 aurel32
            gen_exception(ctx, POWERPC_EXCP_VPU);                       \
6434 21d21583 aurel32
            return;                                                     \
6435 21d21583 aurel32
        }                                                               \
6436 21d21583 aurel32
        simm = tcg_const_i32(SIMM5(ctx->opcode));                       \
6437 21d21583 aurel32
        rd = gen_avr_ptr(rD(ctx->opcode));                              \
6438 21d21583 aurel32
        gen_helper_##name (rd, simm);                                   \
6439 21d21583 aurel32
        tcg_temp_free_i32(simm);                                        \
6440 21d21583 aurel32
        tcg_temp_free_ptr(rd);                                          \
6441 21d21583 aurel32
    }
6442 21d21583 aurel32
6443 27a4edb3 aurel32
#define GEN_VXFORM_UIMM(name, opc2, opc3)                               \
6444 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                                 \
6445 27a4edb3 aurel32
    {                                                                   \
6446 27a4edb3 aurel32
        TCGv_ptr rb, rd;                                                \
6447 27a4edb3 aurel32
        TCGv_i32 uimm;                                                  \
6448 27a4edb3 aurel32
        if (unlikely(!ctx->altivec_enabled)) {                          \
6449 27a4edb3 aurel32
            gen_exception(ctx, POWERPC_EXCP_VPU);                       \
6450 27a4edb3 aurel32
            return;                                                     \
6451 27a4edb3 aurel32
        }                                                               \
6452 27a4edb3 aurel32
        uimm = tcg_const_i32(UIMM5(ctx->opcode));                       \
6453 27a4edb3 aurel32
        rb = gen_avr_ptr(rB(ctx->opcode));                              \
6454 27a4edb3 aurel32
        rd = gen_avr_ptr(rD(ctx->opcode));                              \
6455 27a4edb3 aurel32
        gen_helper_##name (rd, rb, uimm);                               \
6456 27a4edb3 aurel32
        tcg_temp_free_i32(uimm);                                        \
6457 27a4edb3 aurel32
        tcg_temp_free_ptr(rb);                                          \
6458 27a4edb3 aurel32
        tcg_temp_free_ptr(rd);                                          \
6459 27a4edb3 aurel32
    }
6460 27a4edb3 aurel32
6461 e4e6bee7 aurel32
GEN_VXFORM_UIMM(vspltb, 6, 8);
6462 e4e6bee7 aurel32
GEN_VXFORM_UIMM(vsplth, 6, 9);
6463 e4e6bee7 aurel32
GEN_VXFORM_UIMM(vspltw, 6, 10);
6464 e140632e aurel32
GEN_VXFORM_UIMM(vcfux, 5, 12);
6465 e140632e aurel32
GEN_VXFORM_UIMM(vcfsx, 5, 13);
6466 875b31db aurel32
GEN_VXFORM_UIMM(vctuxs, 5, 14);
6467 875b31db aurel32
GEN_VXFORM_UIMM(vctsxs, 5, 15);
6468 e4e6bee7 aurel32
6469 99e300ef Blue Swirl
static void gen_vsldoi(DisasContext *ctx)
6470 cd633b10 aurel32
{
6471 cd633b10 aurel32
    TCGv_ptr ra, rb, rd;
6472 fce5ecb7 aurel32
    TCGv_i32 sh;
6473 cd633b10 aurel32
    if (unlikely(!ctx->altivec_enabled)) {
6474 cd633b10 aurel32
        gen_exception(ctx, POWERPC_EXCP_VPU);
6475 cd633b10 aurel32
        return;
6476 cd633b10 aurel32
    }
6477 cd633b10 aurel32
    ra = gen_avr_ptr(rA(ctx->opcode));
6478 cd633b10 aurel32
    rb = gen_avr_ptr(rB(ctx->opcode));
6479 cd633b10 aurel32
    rd = gen_avr_ptr(rD(ctx->opcode));
6480 cd633b10 aurel32
    sh = tcg_const_i32(VSH(ctx->opcode));
6481 cd633b10 aurel32
    gen_helper_vsldoi (rd, ra, rb, sh);
6482 cd633b10 aurel32
    tcg_temp_free_ptr(ra);
6483 cd633b10 aurel32
    tcg_temp_free_ptr(rb);
6484 cd633b10 aurel32
    tcg_temp_free_ptr(rd);
6485 fce5ecb7 aurel32
    tcg_temp_free_i32(sh);
6486 cd633b10 aurel32
}
6487 cd633b10 aurel32
6488 707cec33 aurel32
#define GEN_VAFORM_PAIRED(name0, name1, opc2)                           \
6489 99e300ef Blue Swirl
static void glue(gen_, name0##_##name1)(DisasContext *ctx)                      \
6490 707cec33 aurel32
    {                                                                   \
6491 707cec33 aurel32
        TCGv_ptr ra, rb, rc, rd;                                        \
6492 707cec33 aurel32
        if (unlikely(!ctx->altivec_enabled)) {                          \
6493 707cec33 aurel32
            gen_exception(ctx, POWERPC_EXCP_VPU);                       \
6494 707cec33 aurel32
            return;                                                     \
6495 707cec33 aurel32
        }                                                               \
6496 707cec33 aurel32
        ra = gen_avr_ptr(rA(ctx->opcode));                              \
6497 707cec33 aurel32
        rb = gen_avr_ptr(rB(ctx->opcode));                              \
6498 707cec33 aurel32
        rc = gen_avr_ptr(rC(ctx->opcode));                              \
6499 707cec33 aurel32
        rd = gen_avr_ptr(rD(ctx->opcode));                              \
6500 707cec33 aurel32
        if (Rc(ctx->opcode)) {                                          \
6501 707cec33 aurel32
            gen_helper_##name1 (rd, ra, rb, rc);                        \
6502 707cec33 aurel32
        } else {                                                        \
6503 707cec33 aurel32
            gen_helper_##name0 (rd, ra, rb, rc);                        \
6504 707cec33 aurel32
        }                                                               \
6505 707cec33 aurel32
        tcg_temp_free_ptr(ra);                                          \
6506 707cec33 aurel32
        tcg_temp_free_ptr(rb);                                          \
6507 707cec33 aurel32
        tcg_temp_free_ptr(rc);                                          \
6508 707cec33 aurel32
        tcg_temp_free_ptr(rd);                                          \
6509 707cec33 aurel32
    }
6510 707cec33 aurel32
6511 b161ae27 aurel32
GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16)
6512 b161ae27 aurel32
6513 99e300ef Blue Swirl
static void gen_vmladduhm(DisasContext *ctx)
6514 bcd2ee23 aurel32
{
6515 bcd2ee23 aurel32
    TCGv_ptr ra, rb, rc, rd;
6516 bcd2ee23 aurel32
    if (unlikely(!ctx->altivec_enabled)) {
6517 bcd2ee23 aurel32
        gen_exception(ctx, POWERPC_EXCP_VPU);
6518 bcd2ee23 aurel32
        return;
6519 bcd2ee23 aurel32
    }
6520 bcd2ee23 aurel32
    ra = gen_avr_ptr(rA(ctx->opcode));
6521 bcd2ee23 aurel32
    rb = gen_avr_ptr(rB(ctx->opcode));
6522 bcd2ee23 aurel32
    rc = gen_avr_ptr(rC(ctx->opcode));
6523 bcd2ee23 aurel32
    rd = gen_avr_ptr(rD(ctx->opcode));
6524 bcd2ee23 aurel32
    gen_helper_vmladduhm(rd, ra, rb, rc);
6525 bcd2ee23 aurel32
    tcg_temp_free_ptr(ra);
6526 bcd2ee23 aurel32
    tcg_temp_free_ptr(rb);
6527 bcd2ee23 aurel32
    tcg_temp_free_ptr(rc);
6528 bcd2ee23 aurel32
    tcg_temp_free_ptr(rd);
6529 bcd2ee23 aurel32
}
6530 bcd2ee23 aurel32
6531 b04ae981 aurel32
GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18)
6532 4d9903b6 aurel32
GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19)
6533 eae07261 aurel32
GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20)
6534 d1258698 aurel32
GEN_VAFORM_PAIRED(vsel, vperm, 21)
6535 35cf7c7e aurel32
GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23)
6536 b04ae981 aurel32
6537 0487d6a8 j_mayer
/***                           SPE extension                               ***/
6538 0487d6a8 j_mayer
/* Register moves */
6539 3cd7d1dd j_mayer
6540 a0e13900 Fabien Chouteau
6541 a0e13900 Fabien Chouteau
static inline void gen_evmra(DisasContext *ctx)
6542 a0e13900 Fabien Chouteau
{
6543 a0e13900 Fabien Chouteau
6544 a0e13900 Fabien Chouteau
    if (unlikely(!ctx->spe_enabled)) {
6545 a0e13900 Fabien Chouteau
        gen_exception(ctx, POWERPC_EXCP_APU);
6546 a0e13900 Fabien Chouteau
        return;
6547 a0e13900 Fabien Chouteau
    }
6548 a0e13900 Fabien Chouteau
6549 a0e13900 Fabien Chouteau
#if defined(TARGET_PPC64)
6550 a0e13900 Fabien Chouteau
    /* rD := rA */
6551 a0e13900 Fabien Chouteau
    tcg_gen_mov_i64(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
6552 a0e13900 Fabien Chouteau
6553 a0e13900 Fabien Chouteau
    /* spe_acc := rA */
6554 a0e13900 Fabien Chouteau
    tcg_gen_st_i64(cpu_gpr[rA(ctx->opcode)],
6555 a0e13900 Fabien Chouteau
                   cpu_env,
6556 a0e13900 Fabien Chouteau
                   offsetof(CPUState, spe_acc));
6557 a0e13900 Fabien Chouteau
#else
6558 a0e13900 Fabien Chouteau
    TCGv_i64 tmp = tcg_temp_new_i64();
6559 a0e13900 Fabien Chouteau
6560 a0e13900 Fabien Chouteau
    /* tmp := rA_lo + rA_hi << 32 */
6561 a0e13900 Fabien Chouteau
    tcg_gen_concat_i32_i64(tmp, cpu_gpr[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
6562 a0e13900 Fabien Chouteau
6563 a0e13900 Fabien Chouteau
    /* spe_acc := tmp */
6564 a0e13900 Fabien Chouteau
    tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUState, spe_acc));
6565 a0e13900 Fabien Chouteau
    tcg_temp_free_i64(tmp);
6566 a0e13900 Fabien Chouteau
6567 a0e13900 Fabien Chouteau
    /* rD := rA */
6568 a0e13900 Fabien Chouteau
    tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
6569 a0e13900 Fabien Chouteau
    tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
6570 a0e13900 Fabien Chouteau
#endif
6571 a0e13900 Fabien Chouteau
}
6572 a0e13900 Fabien Chouteau
6573 636aa200 Blue Swirl
static inline void gen_load_gpr64(TCGv_i64 t, int reg)
6574 636aa200 Blue Swirl
{
6575 f78fb44e aurel32
#if defined(TARGET_PPC64)
6576 f78fb44e aurel32
    tcg_gen_mov_i64(t, cpu_gpr[reg]);
6577 f78fb44e aurel32
#else
6578 36aa55dc pbrook
    tcg_gen_concat_i32_i64(t, cpu_gpr[reg], cpu_gprh[reg]);
6579 3cd7d1dd j_mayer
#endif
6580 f78fb44e aurel32
}
6581 3cd7d1dd j_mayer
6582 636aa200 Blue Swirl
static inline void gen_store_gpr64(int reg, TCGv_i64 t)
6583 636aa200 Blue Swirl
{
6584 f78fb44e aurel32
#if defined(TARGET_PPC64)
6585 f78fb44e aurel32
    tcg_gen_mov_i64(cpu_gpr[reg], t);
6586 f78fb44e aurel32
#else
6587 a7812ae4 pbrook
    TCGv_i64 tmp = tcg_temp_new_i64();
6588 f78fb44e aurel32
    tcg_gen_trunc_i64_i32(cpu_gpr[reg], t);
6589 f78fb44e aurel32
    tcg_gen_shri_i64(tmp, t, 32);
6590 f78fb44e aurel32
    tcg_gen_trunc_i64_i32(cpu_gprh[reg], tmp);
6591 a7812ae4 pbrook
    tcg_temp_free_i64(tmp);
6592 3cd7d1dd j_mayer
#endif
6593 f78fb44e aurel32
}
6594 3cd7d1dd j_mayer
6595 0487d6a8 j_mayer
#define GEN_SPE(name0, name1, opc2, opc3, inval, type)                        \
6596 99e300ef Blue Swirl
static void glue(gen_, name0##_##name1)(DisasContext *ctx)                    \
6597 0487d6a8 j_mayer
{                                                                             \
6598 0487d6a8 j_mayer
    if (Rc(ctx->opcode))                                                      \
6599 0487d6a8 j_mayer
        gen_##name1(ctx);                                                     \
6600 0487d6a8 j_mayer
    else                                                                      \
6601 0487d6a8 j_mayer
        gen_##name0(ctx);                                                     \
6602 0487d6a8 j_mayer
}
6603 0487d6a8 j_mayer
6604 0487d6a8 j_mayer
/* Handler for undefined SPE opcodes */
6605 636aa200 Blue Swirl
static inline void gen_speundef(DisasContext *ctx)
6606 0487d6a8 j_mayer
{
6607 e06fcd75 aurel32
    gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
6608 0487d6a8 j_mayer
}
6609 0487d6a8 j_mayer
6610 57951c27 aurel32
/* SPE logic */
6611 57951c27 aurel32
#if defined(TARGET_PPC64)
6612 57951c27 aurel32
#define GEN_SPEOP_LOGIC2(name, tcg_op)                                        \
6613 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
6614 0487d6a8 j_mayer
{                                                                             \
6615 0487d6a8 j_mayer
    if (unlikely(!ctx->spe_enabled)) {                                        \
6616 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
6617 0487d6a8 j_mayer
        return;                                                               \
6618 0487d6a8 j_mayer
    }                                                                         \
6619 57951c27 aurel32
    tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],                \
6620 57951c27 aurel32
           cpu_gpr[rB(ctx->opcode)]);                                         \
6621 57951c27 aurel32
}
6622 57951c27 aurel32
#else
6623 57951c27 aurel32
#define GEN_SPEOP_LOGIC2(name, tcg_op)                                        \
6624 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
6625 57951c27 aurel32
{                                                                             \
6626 57951c27 aurel32
    if (unlikely(!ctx->spe_enabled)) {                                        \
6627 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
6628 57951c27 aurel32
        return;                                                               \
6629 57951c27 aurel32
    }                                                                         \
6630 57951c27 aurel32
    tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],                \
6631 57951c27 aurel32
           cpu_gpr[rB(ctx->opcode)]);                                         \
6632 57951c27 aurel32
    tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],              \
6633 57951c27 aurel32
           cpu_gprh[rB(ctx->opcode)]);                                        \
6634 0487d6a8 j_mayer
}
6635 57951c27 aurel32
#endif
6636 57951c27 aurel32
6637 57951c27 aurel32
GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl);
6638 57951c27 aurel32
GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl);
6639 57951c27 aurel32
GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl);
6640 57951c27 aurel32
GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl);
6641 57951c27 aurel32
GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl);
6642 57951c27 aurel32
GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl);
6643 57951c27 aurel32
GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl);
6644 57951c27 aurel32
GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl);
6645 0487d6a8 j_mayer
6646 57951c27 aurel32
/* SPE logic immediate */
6647 57951c27 aurel32
#if defined(TARGET_PPC64)
6648 57951c27 aurel32
#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi)                               \
6649 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
6650 3d3a6a0a aurel32
{                                                                             \
6651 3d3a6a0a aurel32
    if (unlikely(!ctx->spe_enabled)) {                                        \
6652 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
6653 3d3a6a0a aurel32
        return;                                                               \
6654 3d3a6a0a aurel32
    }                                                                         \
6655 a7812ae4 pbrook
    TCGv_i32 t0 = tcg_temp_local_new_i32();                                   \
6656 a7812ae4 pbrook
    TCGv_i32 t1 = tcg_temp_local_new_i32();                                   \
6657 a7812ae4 pbrook
    TCGv_i64 t2 = tcg_temp_local_new_i64();                                   \
6658 57951c27 aurel32
    tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]);                      \
6659 57951c27 aurel32
    tcg_opi(t0, t0, rB(ctx->opcode));                                         \
6660 57951c27 aurel32
    tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32);                       \
6661 57951c27 aurel32
    tcg_gen_trunc_i64_i32(t1, t2);                                            \
6662 a7812ae4 pbrook
    tcg_temp_free_i64(t2);                                                    \
6663 57951c27 aurel32
    tcg_opi(t1, t1, rB(ctx->opcode));                                         \
6664 57951c27 aurel32
    tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1);                 \
6665 a7812ae4 pbrook
    tcg_temp_free_i32(t0);                                                    \
6666 a7812ae4 pbrook
    tcg_temp_free_i32(t1);                                                    \
6667 3d3a6a0a aurel32
}
6668 57951c27 aurel32
#else
6669 57951c27 aurel32
#define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi)                               \
6670 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
6671 0487d6a8 j_mayer
{                                                                             \
6672 0487d6a8 j_mayer
    if (unlikely(!ctx->spe_enabled)) {                                        \
6673 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
6674 0487d6a8 j_mayer
        return;                                                               \
6675 0487d6a8 j_mayer
    }                                                                         \
6676 57951c27 aurel32
    tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],               \
6677 57951c27 aurel32
            rB(ctx->opcode));                                                 \
6678 57951c27 aurel32
    tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],             \
6679 57951c27 aurel32
            rB(ctx->opcode));                                                 \
6680 0487d6a8 j_mayer
}
6681 57951c27 aurel32
#endif
6682 57951c27 aurel32
GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32);
6683 57951c27 aurel32
GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32);
6684 57951c27 aurel32
GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32);
6685 57951c27 aurel32
GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32);
6686 0487d6a8 j_mayer
6687 57951c27 aurel32
/* SPE arithmetic */
6688 57951c27 aurel32
#if defined(TARGET_PPC64)
6689 57951c27 aurel32
#define GEN_SPEOP_ARITH1(name, tcg_op)                                        \
6690 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
6691 0487d6a8 j_mayer
{                                                                             \
6692 0487d6a8 j_mayer
    if (unlikely(!ctx->spe_enabled)) {                                        \
6693 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
6694 0487d6a8 j_mayer
        return;                                                               \
6695 0487d6a8 j_mayer
    }                                                                         \
6696 a7812ae4 pbrook
    TCGv_i32 t0 = tcg_temp_local_new_i32();                                   \
6697 a7812ae4 pbrook
    TCGv_i32 t1 = tcg_temp_local_new_i32();                                   \
6698 a7812ae4 pbrook
    TCGv_i64 t2 = tcg_temp_local_new_i64();                                   \
6699 57951c27 aurel32
    tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]);                      \
6700 57951c27 aurel32
    tcg_op(t0, t0);                                                           \
6701 57951c27 aurel32
    tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32);                       \
6702 57951c27 aurel32
    tcg_gen_trunc_i64_i32(t1, t2);                                            \
6703 a7812ae4 pbrook
    tcg_temp_free_i64(t2);                                                    \
6704 57951c27 aurel32
    tcg_op(t1, t1);                                                           \
6705 57951c27 aurel32
    tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1);                 \
6706 a7812ae4 pbrook
    tcg_temp_free_i32(t0);                                                    \
6707 a7812ae4 pbrook
    tcg_temp_free_i32(t1);                                                    \
6708 0487d6a8 j_mayer
}
6709 57951c27 aurel32
#else
6710 a7812ae4 pbrook
#define GEN_SPEOP_ARITH1(name, tcg_op)                                        \
6711 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
6712 57951c27 aurel32
{                                                                             \
6713 57951c27 aurel32
    if (unlikely(!ctx->spe_enabled)) {                                        \
6714 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
6715 57951c27 aurel32
        return;                                                               \
6716 57951c27 aurel32
    }                                                                         \
6717 57951c27 aurel32
    tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);               \
6718 57951c27 aurel32
    tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);             \
6719 57951c27 aurel32
}
6720 57951c27 aurel32
#endif
6721 0487d6a8 j_mayer
6722 636aa200 Blue Swirl
static inline void gen_op_evabs(TCGv_i32 ret, TCGv_i32 arg1)
6723 57951c27 aurel32
{
6724 57951c27 aurel32
    int l1 = gen_new_label();
6725 57951c27 aurel32
    int l2 = gen_new_label();
6726 0487d6a8 j_mayer
6727 57951c27 aurel32
    tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1);
6728 57951c27 aurel32
    tcg_gen_neg_i32(ret, arg1);
6729 57951c27 aurel32
    tcg_gen_br(l2);
6730 57951c27 aurel32
    gen_set_label(l1);
6731 a7812ae4 pbrook
    tcg_gen_mov_i32(ret, arg1);
6732 57951c27 aurel32
    gen_set_label(l2);
6733 57951c27 aurel32
}
6734 57951c27 aurel32
GEN_SPEOP_ARITH1(evabs, gen_op_evabs);
6735 57951c27 aurel32
GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32);
6736 57951c27 aurel32
GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32);
6737 57951c27 aurel32
GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32);
6738 636aa200 Blue Swirl
static inline void gen_op_evrndw(TCGv_i32 ret, TCGv_i32 arg1)
6739 0487d6a8 j_mayer
{
6740 57951c27 aurel32
    tcg_gen_addi_i32(ret, arg1, 0x8000);
6741 57951c27 aurel32
    tcg_gen_ext16u_i32(ret, ret);
6742 57951c27 aurel32
}
6743 57951c27 aurel32
GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw);
6744 a7812ae4 pbrook
GEN_SPEOP_ARITH1(evcntlsw, gen_helper_cntlsw32);
6745 a7812ae4 pbrook
GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32);
6746 0487d6a8 j_mayer
6747 57951c27 aurel32
#if defined(TARGET_PPC64)
6748 57951c27 aurel32
#define GEN_SPEOP_ARITH2(name, tcg_op)                                        \
6749 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
6750 0487d6a8 j_mayer
{                                                                             \
6751 0487d6a8 j_mayer
    if (unlikely(!ctx->spe_enabled)) {                                        \
6752 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
6753 0487d6a8 j_mayer
        return;                                                               \
6754 0487d6a8 j_mayer
    }                                                                         \
6755 a7812ae4 pbrook
    TCGv_i32 t0 = tcg_temp_local_new_i32();                                   \
6756 a7812ae4 pbrook
    TCGv_i32 t1 = tcg_temp_local_new_i32();                                   \
6757 a7812ae4 pbrook
    TCGv_i32 t2 = tcg_temp_local_new_i32();                                   \
6758 501e23c4 aurel32
    TCGv_i64 t3 = tcg_temp_local_new_i64();                                   \
6759 57951c27 aurel32
    tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]);                      \
6760 57951c27 aurel32
    tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]);                      \
6761 57951c27 aurel32
    tcg_op(t0, t0, t2);                                                       \
6762 57951c27 aurel32
    tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32);                       \
6763 57951c27 aurel32
    tcg_gen_trunc_i64_i32(t1, t3);                                            \
6764 57951c27 aurel32
    tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32);                       \
6765 57951c27 aurel32
    tcg_gen_trunc_i64_i32(t2, t3);                                            \
6766 a7812ae4 pbrook
    tcg_temp_free_i64(t3);                                                    \
6767 57951c27 aurel32
    tcg_op(t1, t1, t2);                                                       \
6768 a7812ae4 pbrook
    tcg_temp_free_i32(t2);                                                    \
6769 57951c27 aurel32
    tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1);                 \
6770 a7812ae4 pbrook
    tcg_temp_free_i32(t0);                                                    \
6771 a7812ae4 pbrook
    tcg_temp_free_i32(t1);                                                    \
6772 0487d6a8 j_mayer
}
6773 57951c27 aurel32
#else
6774 57951c27 aurel32
#define GEN_SPEOP_ARITH2(name, tcg_op)                                        \
6775 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
6776 0487d6a8 j_mayer
{                                                                             \
6777 0487d6a8 j_mayer
    if (unlikely(!ctx->spe_enabled)) {                                        \
6778 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
6779 0487d6a8 j_mayer
        return;                                                               \
6780 0487d6a8 j_mayer
    }                                                                         \
6781 57951c27 aurel32
    tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],                \
6782 57951c27 aurel32
           cpu_gpr[rB(ctx->opcode)]);                                         \
6783 57951c27 aurel32
    tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)],              \
6784 57951c27 aurel32
           cpu_gprh[rB(ctx->opcode)]);                                        \
6785 0487d6a8 j_mayer
}
6786 57951c27 aurel32
#endif
6787 0487d6a8 j_mayer
6788 636aa200 Blue Swirl
static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
6789 57951c27 aurel32
{
6790 a7812ae4 pbrook
    TCGv_i32 t0;
6791 57951c27 aurel32
    int l1, l2;
6792 0487d6a8 j_mayer
6793 57951c27 aurel32
    l1 = gen_new_label();
6794 57951c27 aurel32
    l2 = gen_new_label();
6795 a7812ae4 pbrook
    t0 = tcg_temp_local_new_i32();
6796 57951c27 aurel32
    /* No error here: 6 bits are used */
6797 57951c27 aurel32
    tcg_gen_andi_i32(t0, arg2, 0x3F);
6798 57951c27 aurel32
    tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
6799 57951c27 aurel32
    tcg_gen_shr_i32(ret, arg1, t0);
6800 57951c27 aurel32
    tcg_gen_br(l2);
6801 57951c27 aurel32
    gen_set_label(l1);
6802 57951c27 aurel32
    tcg_gen_movi_i32(ret, 0);
6803 0aef4261 Aurelien Jarno
    gen_set_label(l2);
6804 a7812ae4 pbrook
    tcg_temp_free_i32(t0);
6805 57951c27 aurel32
}
6806 57951c27 aurel32
GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu);
6807 636aa200 Blue Swirl
static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
6808 57951c27 aurel32
{
6809 a7812ae4 pbrook
    TCGv_i32 t0;
6810 57951c27 aurel32
    int l1, l2;
6811 57951c27 aurel32
6812 57951c27 aurel32
    l1 = gen_new_label();
6813 57951c27 aurel32
    l2 = gen_new_label();
6814 a7812ae4 pbrook
    t0 = tcg_temp_local_new_i32();
6815 57951c27 aurel32
    /* No error here: 6 bits are used */
6816 57951c27 aurel32
    tcg_gen_andi_i32(t0, arg2, 0x3F);
6817 57951c27 aurel32
    tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
6818 57951c27 aurel32
    tcg_gen_sar_i32(ret, arg1, t0);
6819 57951c27 aurel32
    tcg_gen_br(l2);
6820 57951c27 aurel32
    gen_set_label(l1);
6821 57951c27 aurel32
    tcg_gen_movi_i32(ret, 0);
6822 0aef4261 Aurelien Jarno
    gen_set_label(l2);
6823 a7812ae4 pbrook
    tcg_temp_free_i32(t0);
6824 57951c27 aurel32
}
6825 57951c27 aurel32
GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws);
6826 636aa200 Blue Swirl
static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
6827 57951c27 aurel32
{
6828 a7812ae4 pbrook
    TCGv_i32 t0;
6829 57951c27 aurel32
    int l1, l2;
6830 57951c27 aurel32
6831 57951c27 aurel32
    l1 = gen_new_label();
6832 57951c27 aurel32
    l2 = gen_new_label();
6833 a7812ae4 pbrook
    t0 = tcg_temp_local_new_i32();
6834 57951c27 aurel32
    /* No error here: 6 bits are used */
6835 57951c27 aurel32
    tcg_gen_andi_i32(t0, arg2, 0x3F);
6836 57951c27 aurel32
    tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1);
6837 57951c27 aurel32
    tcg_gen_shl_i32(ret, arg1, t0);
6838 57951c27 aurel32
    tcg_gen_br(l2);
6839 57951c27 aurel32
    gen_set_label(l1);
6840 57951c27 aurel32
    tcg_gen_movi_i32(ret, 0);
6841 e29ef9fa Aurelien Jarno
    gen_set_label(l2);
6842 a7812ae4 pbrook
    tcg_temp_free_i32(t0);
6843 57951c27 aurel32
}
6844 57951c27 aurel32
GEN_SPEOP_ARITH2(evslw, gen_op_evslw);
6845 636aa200 Blue Swirl
static inline void gen_op_evrlw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
6846 57951c27 aurel32
{
6847 a7812ae4 pbrook
    TCGv_i32 t0 = tcg_temp_new_i32();
6848 57951c27 aurel32
    tcg_gen_andi_i32(t0, arg2, 0x1F);
6849 57951c27 aurel32
    tcg_gen_rotl_i32(ret, arg1, t0);
6850 a7812ae4 pbrook
    tcg_temp_free_i32(t0);
6851 57951c27 aurel32
}
6852 57951c27 aurel32
GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw);
6853 636aa200 Blue Swirl
static inline void gen_evmergehi(DisasContext *ctx)
6854 57951c27 aurel32
{
6855 57951c27 aurel32
    if (unlikely(!ctx->spe_enabled)) {
6856 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);
6857 57951c27 aurel32
        return;
6858 57951c27 aurel32
    }
6859 57951c27 aurel32
#if defined(TARGET_PPC64)
6860 a7812ae4 pbrook
    TCGv t0 = tcg_temp_new();
6861 a7812ae4 pbrook
    TCGv t1 = tcg_temp_new();
6862 57951c27 aurel32
    tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
6863 57951c27 aurel32
    tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
6864 57951c27 aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
6865 57951c27 aurel32
    tcg_temp_free(t0);
6866 57951c27 aurel32
    tcg_temp_free(t1);
6867 57951c27 aurel32
#else
6868 57951c27 aurel32
    tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
6869 57951c27 aurel32
    tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
6870 57951c27 aurel32
#endif
6871 57951c27 aurel32
}
6872 57951c27 aurel32
GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32);
6873 636aa200 Blue Swirl
static inline void gen_op_evsubf(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
6874 0487d6a8 j_mayer
{
6875 57951c27 aurel32
    tcg_gen_sub_i32(ret, arg2, arg1);
6876 57951c27 aurel32
}
6877 57951c27 aurel32
GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf);
6878 0487d6a8 j_mayer
6879 57951c27 aurel32
/* SPE arithmetic immediate */
6880 57951c27 aurel32
#if defined(TARGET_PPC64)
6881 57951c27 aurel32
#define GEN_SPEOP_ARITH_IMM2(name, tcg_op)                                    \
6882 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
6883 57951c27 aurel32
{                                                                             \
6884 57951c27 aurel32
    if (unlikely(!ctx->spe_enabled)) {                                        \
6885 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
6886 57951c27 aurel32
        return;                                                               \
6887 57951c27 aurel32
    }                                                                         \
6888 a7812ae4 pbrook
    TCGv_i32 t0 = tcg_temp_local_new_i32();                                   \
6889 a7812ae4 pbrook
    TCGv_i32 t1 = tcg_temp_local_new_i32();                                   \
6890 a7812ae4 pbrook
    TCGv_i64 t2 = tcg_temp_local_new_i64();                                   \
6891 57951c27 aurel32
    tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]);                      \
6892 57951c27 aurel32
    tcg_op(t0, t0, rA(ctx->opcode));                                          \
6893 57951c27 aurel32
    tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32);                       \
6894 57951c27 aurel32
    tcg_gen_trunc_i64_i32(t1, t2);                                            \
6895 e06fcd75 aurel32
    tcg_temp_free_i64(t2);                                                    \
6896 57951c27 aurel32
    tcg_op(t1, t1, rA(ctx->opcode));                                          \
6897 57951c27 aurel32
    tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1);                 \
6898 a7812ae4 pbrook
    tcg_temp_free_i32(t0);                                                    \
6899 a7812ae4 pbrook
    tcg_temp_free_i32(t1);                                                    \
6900 57951c27 aurel32
}
6901 57951c27 aurel32
#else
6902 57951c27 aurel32
#define GEN_SPEOP_ARITH_IMM2(name, tcg_op)                                    \
6903 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
6904 57951c27 aurel32
{                                                                             \
6905 57951c27 aurel32
    if (unlikely(!ctx->spe_enabled)) {                                        \
6906 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
6907 57951c27 aurel32
        return;                                                               \
6908 57951c27 aurel32
    }                                                                         \
6909 57951c27 aurel32
    tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],                \
6910 57951c27 aurel32
           rA(ctx->opcode));                                                  \
6911 57951c27 aurel32
    tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)],              \
6912 57951c27 aurel32
           rA(ctx->opcode));                                                  \
6913 57951c27 aurel32
}
6914 57951c27 aurel32
#endif
6915 57951c27 aurel32
GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32);
6916 57951c27 aurel32
GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32);
6917 57951c27 aurel32
6918 57951c27 aurel32
/* SPE comparison */
6919 57951c27 aurel32
#if defined(TARGET_PPC64)
6920 57951c27 aurel32
#define GEN_SPEOP_COMP(name, tcg_cond)                                        \
6921 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
6922 57951c27 aurel32
{                                                                             \
6923 57951c27 aurel32
    if (unlikely(!ctx->spe_enabled)) {                                        \
6924 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
6925 57951c27 aurel32
        return;                                                               \
6926 57951c27 aurel32
    }                                                                         \
6927 57951c27 aurel32
    int l1 = gen_new_label();                                                 \
6928 57951c27 aurel32
    int l2 = gen_new_label();                                                 \
6929 57951c27 aurel32
    int l3 = gen_new_label();                                                 \
6930 57951c27 aurel32
    int l4 = gen_new_label();                                                 \
6931 a7812ae4 pbrook
    TCGv_i32 t0 = tcg_temp_local_new_i32();                                   \
6932 a7812ae4 pbrook
    TCGv_i32 t1 = tcg_temp_local_new_i32();                                   \
6933 a7812ae4 pbrook
    TCGv_i64 t2 = tcg_temp_local_new_i64();                                   \
6934 57951c27 aurel32
    tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]);                      \
6935 57951c27 aurel32
    tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]);                      \
6936 57951c27 aurel32
    tcg_gen_brcond_i32(tcg_cond, t0, t1, l1);                                 \
6937 a7812ae4 pbrook
    tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0);                          \
6938 57951c27 aurel32
    tcg_gen_br(l2);                                                           \
6939 57951c27 aurel32
    gen_set_label(l1);                                                        \
6940 57951c27 aurel32
    tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)],                              \
6941 57951c27 aurel32
                     CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL);                  \
6942 57951c27 aurel32
    gen_set_label(l2);                                                        \
6943 57951c27 aurel32
    tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32);                       \
6944 57951c27 aurel32
    tcg_gen_trunc_i64_i32(t0, t2);                                            \
6945 57951c27 aurel32
    tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32);                       \
6946 57951c27 aurel32
    tcg_gen_trunc_i64_i32(t1, t2);                                            \
6947 a7812ae4 pbrook
    tcg_temp_free_i64(t2);                                                    \
6948 57951c27 aurel32
    tcg_gen_brcond_i32(tcg_cond, t0, t1, l3);                                 \
6949 57951c27 aurel32
    tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)],  \
6950 57951c27 aurel32
                     ~(CRF_CH | CRF_CH_AND_CL));                              \
6951 57951c27 aurel32
    tcg_gen_br(l4);                                                           \
6952 57951c27 aurel32
    gen_set_label(l3);                                                        \
6953 57951c27 aurel32
    tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)],   \
6954 57951c27 aurel32
                    CRF_CH | CRF_CH_OR_CL);                                   \
6955 57951c27 aurel32
    gen_set_label(l4);                                                        \
6956 a7812ae4 pbrook
    tcg_temp_free_i32(t0);                                                    \
6957 a7812ae4 pbrook
    tcg_temp_free_i32(t1);                                                    \
6958 57951c27 aurel32
}
6959 57951c27 aurel32
#else
6960 57951c27 aurel32
#define GEN_SPEOP_COMP(name, tcg_cond)                                        \
6961 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
6962 57951c27 aurel32
{                                                                             \
6963 57951c27 aurel32
    if (unlikely(!ctx->spe_enabled)) {                                        \
6964 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
6965 57951c27 aurel32
        return;                                                               \
6966 57951c27 aurel32
    }                                                                         \
6967 57951c27 aurel32
    int l1 = gen_new_label();                                                 \
6968 57951c27 aurel32
    int l2 = gen_new_label();                                                 \
6969 57951c27 aurel32
    int l3 = gen_new_label();                                                 \
6970 57951c27 aurel32
    int l4 = gen_new_label();                                                 \
6971 57951c27 aurel32
                                                                              \
6972 57951c27 aurel32
    tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)],                    \
6973 57951c27 aurel32
                       cpu_gpr[rB(ctx->opcode)], l1);                         \
6974 57951c27 aurel32
    tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0);                           \
6975 57951c27 aurel32
    tcg_gen_br(l2);                                                           \
6976 57951c27 aurel32
    gen_set_label(l1);                                                        \
6977 57951c27 aurel32
    tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)],                              \
6978 57951c27 aurel32
                     CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL);                  \
6979 57951c27 aurel32
    gen_set_label(l2);                                                        \
6980 57951c27 aurel32
    tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)],                   \
6981 57951c27 aurel32
                       cpu_gprh[rB(ctx->opcode)], l3);                        \
6982 57951c27 aurel32
    tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)],  \
6983 57951c27 aurel32
                     ~(CRF_CH | CRF_CH_AND_CL));                              \
6984 57951c27 aurel32
    tcg_gen_br(l4);                                                           \
6985 57951c27 aurel32
    gen_set_label(l3);                                                        \
6986 57951c27 aurel32
    tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)],   \
6987 57951c27 aurel32
                    CRF_CH | CRF_CH_OR_CL);                                   \
6988 57951c27 aurel32
    gen_set_label(l4);                                                        \
6989 57951c27 aurel32
}
6990 57951c27 aurel32
#endif
6991 57951c27 aurel32
GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU);
6992 57951c27 aurel32
GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT);
6993 57951c27 aurel32
GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU);
6994 57951c27 aurel32
GEN_SPEOP_COMP(evcmplts, TCG_COND_LT);
6995 57951c27 aurel32
GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ);
6996 57951c27 aurel32
6997 57951c27 aurel32
/* SPE misc */
6998 636aa200 Blue Swirl
static inline void gen_brinc(DisasContext *ctx)
6999 57951c27 aurel32
{
7000 57951c27 aurel32
    /* Note: brinc is usable even if SPE is disabled */
7001 a7812ae4 pbrook
    gen_helper_brinc(cpu_gpr[rD(ctx->opcode)],
7002 a7812ae4 pbrook
                     cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
7003 0487d6a8 j_mayer
}
7004 636aa200 Blue Swirl
static inline void gen_evmergelo(DisasContext *ctx)
7005 57951c27 aurel32
{
7006 57951c27 aurel32
    if (unlikely(!ctx->spe_enabled)) {
7007 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);
7008 57951c27 aurel32
        return;
7009 57951c27 aurel32
    }
7010 57951c27 aurel32
#if defined(TARGET_PPC64)
7011 a7812ae4 pbrook
    TCGv t0 = tcg_temp_new();
7012 a7812ae4 pbrook
    TCGv t1 = tcg_temp_new();
7013 17d9b3af Aurelien Jarno
    tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
7014 57951c27 aurel32
    tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
7015 57951c27 aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
7016 57951c27 aurel32
    tcg_temp_free(t0);
7017 57951c27 aurel32
    tcg_temp_free(t1);
7018 57951c27 aurel32
#else
7019 57951c27 aurel32
    tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
7020 33890b3e Nathan Froyd
    tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
7021 57951c27 aurel32
#endif
7022 57951c27 aurel32
}
7023 636aa200 Blue Swirl
static inline void gen_evmergehilo(DisasContext *ctx)
7024 57951c27 aurel32
{
7025 57951c27 aurel32
    if (unlikely(!ctx->spe_enabled)) {
7026 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);
7027 57951c27 aurel32
        return;
7028 57951c27 aurel32
    }
7029 57951c27 aurel32
#if defined(TARGET_PPC64)
7030 a7812ae4 pbrook
    TCGv t0 = tcg_temp_new();
7031 a7812ae4 pbrook
    TCGv t1 = tcg_temp_new();
7032 17d9b3af Aurelien Jarno
    tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]);
7033 57951c27 aurel32
    tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL);
7034 57951c27 aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
7035 57951c27 aurel32
    tcg_temp_free(t0);
7036 57951c27 aurel32
    tcg_temp_free(t1);
7037 57951c27 aurel32
#else
7038 57951c27 aurel32
    tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
7039 57951c27 aurel32
    tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
7040 57951c27 aurel32
#endif
7041 57951c27 aurel32
}
7042 636aa200 Blue Swirl
static inline void gen_evmergelohi(DisasContext *ctx)
7043 57951c27 aurel32
{
7044 57951c27 aurel32
    if (unlikely(!ctx->spe_enabled)) {
7045 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);
7046 57951c27 aurel32
        return;
7047 57951c27 aurel32
    }
7048 57951c27 aurel32
#if defined(TARGET_PPC64)
7049 a7812ae4 pbrook
    TCGv t0 = tcg_temp_new();
7050 a7812ae4 pbrook
    TCGv t1 = tcg_temp_new();
7051 57951c27 aurel32
    tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32);
7052 57951c27 aurel32
    tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32);
7053 57951c27 aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1);
7054 57951c27 aurel32
    tcg_temp_free(t0);
7055 57951c27 aurel32
    tcg_temp_free(t1);
7056 57951c27 aurel32
#else
7057 33890b3e Nathan Froyd
    if (rD(ctx->opcode) == rA(ctx->opcode)) {
7058 33890b3e Nathan Froyd
        TCGv_i32 tmp = tcg_temp_new_i32();
7059 33890b3e Nathan Froyd
        tcg_gen_mov_i32(tmp, cpu_gpr[rA(ctx->opcode)]);
7060 33890b3e Nathan Froyd
        tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
7061 33890b3e Nathan Froyd
        tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], tmp);
7062 33890b3e Nathan Froyd
        tcg_temp_free_i32(tmp);
7063 33890b3e Nathan Froyd
    } else {
7064 33890b3e Nathan Froyd
        tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
7065 33890b3e Nathan Froyd
        tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
7066 33890b3e Nathan Froyd
    }
7067 57951c27 aurel32
#endif
7068 57951c27 aurel32
}
7069 636aa200 Blue Swirl
static inline void gen_evsplati(DisasContext *ctx)
7070 57951c27 aurel32
{
7071 ae01847f Nathan Froyd
    uint64_t imm = ((int32_t)(rA(ctx->opcode) << 27)) >> 27;
7072 0487d6a8 j_mayer
7073 57951c27 aurel32
#if defined(TARGET_PPC64)
7074 38d14952 aurel32
    tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
7075 57951c27 aurel32
#else
7076 57951c27 aurel32
    tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
7077 57951c27 aurel32
    tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
7078 57951c27 aurel32
#endif
7079 57951c27 aurel32
}
7080 636aa200 Blue Swirl
static inline void gen_evsplatfi(DisasContext *ctx)
7081 0487d6a8 j_mayer
{
7082 ae01847f Nathan Froyd
    uint64_t imm = rA(ctx->opcode) << 27;
7083 0487d6a8 j_mayer
7084 57951c27 aurel32
#if defined(TARGET_PPC64)
7085 38d14952 aurel32
    tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm);
7086 57951c27 aurel32
#else
7087 57951c27 aurel32
    tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm);
7088 57951c27 aurel32
    tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm);
7089 57951c27 aurel32
#endif
7090 0487d6a8 j_mayer
}
7091 0487d6a8 j_mayer
7092 636aa200 Blue Swirl
static inline void gen_evsel(DisasContext *ctx)
7093 57951c27 aurel32
{
7094 57951c27 aurel32
    int l1 = gen_new_label();
7095 57951c27 aurel32
    int l2 = gen_new_label();
7096 57951c27 aurel32
    int l3 = gen_new_label();
7097 57951c27 aurel32
    int l4 = gen_new_label();
7098 a7812ae4 pbrook
    TCGv_i32 t0 = tcg_temp_local_new_i32();
7099 57951c27 aurel32
#if defined(TARGET_PPC64)
7100 a7812ae4 pbrook
    TCGv t1 = tcg_temp_local_new();
7101 a7812ae4 pbrook
    TCGv t2 = tcg_temp_local_new();
7102 57951c27 aurel32
#endif
7103 57951c27 aurel32
    tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3);
7104 57951c27 aurel32
    tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
7105 57951c27 aurel32
#if defined(TARGET_PPC64)
7106 57951c27 aurel32
    tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF00000000ULL);
7107 57951c27 aurel32
#else
7108 57951c27 aurel32
    tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]);
7109 57951c27 aurel32
#endif
7110 57951c27 aurel32
    tcg_gen_br(l2);
7111 57951c27 aurel32
    gen_set_label(l1);
7112 57951c27 aurel32
#if defined(TARGET_PPC64)
7113 57951c27 aurel32
    tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0xFFFFFFFF00000000ULL);
7114 57951c27 aurel32
#else
7115 57951c27 aurel32
    tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]);
7116 57951c27 aurel32
#endif
7117 57951c27 aurel32
    gen_set_label(l2);
7118 57951c27 aurel32
    tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2);
7119 57951c27 aurel32
    tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3);
7120 57951c27 aurel32
#if defined(TARGET_PPC64)
7121 17d9b3af Aurelien Jarno
    tcg_gen_ext32u_tl(t2, cpu_gpr[rA(ctx->opcode)]);
7122 57951c27 aurel32
#else
7123 57951c27 aurel32
    tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
7124 57951c27 aurel32
#endif
7125 57951c27 aurel32
    tcg_gen_br(l4);
7126 57951c27 aurel32
    gen_set_label(l3);
7127 57951c27 aurel32
#if defined(TARGET_PPC64)
7128 17d9b3af Aurelien Jarno
    tcg_gen_ext32u_tl(t2, cpu_gpr[rB(ctx->opcode)]);
7129 57951c27 aurel32
#else
7130 57951c27 aurel32
    tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
7131 57951c27 aurel32
#endif
7132 57951c27 aurel32
    gen_set_label(l4);
7133 a7812ae4 pbrook
    tcg_temp_free_i32(t0);
7134 57951c27 aurel32
#if defined(TARGET_PPC64)
7135 57951c27 aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t1, t2);
7136 57951c27 aurel32
    tcg_temp_free(t1);
7137 57951c27 aurel32
    tcg_temp_free(t2);
7138 57951c27 aurel32
#endif
7139 57951c27 aurel32
}
7140 e8eaa2c0 Blue Swirl
7141 e8eaa2c0 Blue Swirl
static void gen_evsel0(DisasContext *ctx)
7142 57951c27 aurel32
{
7143 57951c27 aurel32
    gen_evsel(ctx);
7144 57951c27 aurel32
}
7145 e8eaa2c0 Blue Swirl
7146 e8eaa2c0 Blue Swirl
static void gen_evsel1(DisasContext *ctx)
7147 57951c27 aurel32
{
7148 57951c27 aurel32
    gen_evsel(ctx);
7149 57951c27 aurel32
}
7150 e8eaa2c0 Blue Swirl
7151 e8eaa2c0 Blue Swirl
static void gen_evsel2(DisasContext *ctx)
7152 57951c27 aurel32
{
7153 57951c27 aurel32
    gen_evsel(ctx);
7154 57951c27 aurel32
}
7155 e8eaa2c0 Blue Swirl
7156 e8eaa2c0 Blue Swirl
static void gen_evsel3(DisasContext *ctx)
7157 57951c27 aurel32
{
7158 57951c27 aurel32
    gen_evsel(ctx);
7159 57951c27 aurel32
}
7160 0487d6a8 j_mayer
7161 a0e13900 Fabien Chouteau
/* Multiply */
7162 a0e13900 Fabien Chouteau
7163 a0e13900 Fabien Chouteau
static inline void gen_evmwumi(DisasContext *ctx)
7164 a0e13900 Fabien Chouteau
{
7165 a0e13900 Fabien Chouteau
    TCGv_i64 t0, t1;
7166 a0e13900 Fabien Chouteau
7167 a0e13900 Fabien Chouteau
    if (unlikely(!ctx->spe_enabled)) {
7168 a0e13900 Fabien Chouteau
        gen_exception(ctx, POWERPC_EXCP_APU);
7169 a0e13900 Fabien Chouteau
        return;
7170 a0e13900 Fabien Chouteau
    }
7171 a0e13900 Fabien Chouteau
7172 a0e13900 Fabien Chouteau
    t0 = tcg_temp_new_i64();
7173 a0e13900 Fabien Chouteau
    t1 = tcg_temp_new_i64();
7174 a0e13900 Fabien Chouteau
7175 a0e13900 Fabien Chouteau
    /* t0 := rA; t1 := rB */
7176 a0e13900 Fabien Chouteau
#if defined(TARGET_PPC64)
7177 a0e13900 Fabien Chouteau
    tcg_gen_ext32u_tl(t0, cpu_gpr[rA(ctx->opcode)]);
7178 a0e13900 Fabien Chouteau
    tcg_gen_ext32u_tl(t1, cpu_gpr[rB(ctx->opcode)]);
7179 a0e13900 Fabien Chouteau
#else
7180 a0e13900 Fabien Chouteau
    tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
7181 a0e13900 Fabien Chouteau
    tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
7182 a0e13900 Fabien Chouteau
#endif
7183 a0e13900 Fabien Chouteau
7184 a0e13900 Fabien Chouteau
    tcg_gen_mul_i64(t0, t0, t1);  /* t0 := rA * rB */
7185 a0e13900 Fabien Chouteau
7186 a0e13900 Fabien Chouteau
    gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
7187 a0e13900 Fabien Chouteau
7188 a0e13900 Fabien Chouteau
    tcg_temp_free_i64(t0);
7189 a0e13900 Fabien Chouteau
    tcg_temp_free_i64(t1);
7190 a0e13900 Fabien Chouteau
}
7191 a0e13900 Fabien Chouteau
7192 a0e13900 Fabien Chouteau
static inline void gen_evmwumia(DisasContext *ctx)
7193 a0e13900 Fabien Chouteau
{
7194 a0e13900 Fabien Chouteau
    TCGv_i64 tmp;
7195 a0e13900 Fabien Chouteau
7196 a0e13900 Fabien Chouteau
    if (unlikely(!ctx->spe_enabled)) {
7197 a0e13900 Fabien Chouteau
        gen_exception(ctx, POWERPC_EXCP_APU);
7198 a0e13900 Fabien Chouteau
        return;
7199 a0e13900 Fabien Chouteau
    }
7200 a0e13900 Fabien Chouteau
7201 a0e13900 Fabien Chouteau
    gen_evmwumi(ctx);            /* rD := rA * rB */
7202 a0e13900 Fabien Chouteau
7203 a0e13900 Fabien Chouteau
    tmp = tcg_temp_new_i64();
7204 a0e13900 Fabien Chouteau
7205 a0e13900 Fabien Chouteau
    /* acc := rD */
7206 a0e13900 Fabien Chouteau
    gen_load_gpr64(tmp, rD(ctx->opcode));
7207 a0e13900 Fabien Chouteau
    tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUState, spe_acc));
7208 a0e13900 Fabien Chouteau
    tcg_temp_free_i64(tmp);
7209 a0e13900 Fabien Chouteau
}
7210 a0e13900 Fabien Chouteau
7211 a0e13900 Fabien Chouteau
static inline void gen_evmwumiaa(DisasContext *ctx)
7212 a0e13900 Fabien Chouteau
{
7213 a0e13900 Fabien Chouteau
    TCGv_i64 acc;
7214 a0e13900 Fabien Chouteau
    TCGv_i64 tmp;
7215 a0e13900 Fabien Chouteau
7216 a0e13900 Fabien Chouteau
    if (unlikely(!ctx->spe_enabled)) {
7217 a0e13900 Fabien Chouteau
        gen_exception(ctx, POWERPC_EXCP_APU);
7218 a0e13900 Fabien Chouteau
        return;
7219 a0e13900 Fabien Chouteau
    }
7220 a0e13900 Fabien Chouteau
7221 a0e13900 Fabien Chouteau
    gen_evmwumi(ctx);           /* rD := rA * rB */
7222 a0e13900 Fabien Chouteau
7223 a0e13900 Fabien Chouteau
    acc = tcg_temp_new_i64();
7224 a0e13900 Fabien Chouteau
    tmp = tcg_temp_new_i64();
7225 a0e13900 Fabien Chouteau
7226 a0e13900 Fabien Chouteau
    /* tmp := rD */
7227 a0e13900 Fabien Chouteau
    gen_load_gpr64(tmp, rD(ctx->opcode));
7228 a0e13900 Fabien Chouteau
7229 a0e13900 Fabien Chouteau
    /* Load acc */
7230 a0e13900 Fabien Chouteau
    tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUState, spe_acc));
7231 a0e13900 Fabien Chouteau
7232 a0e13900 Fabien Chouteau
    /* acc := tmp + acc */
7233 a0e13900 Fabien Chouteau
    tcg_gen_add_i64(acc, acc, tmp);
7234 a0e13900 Fabien Chouteau
7235 a0e13900 Fabien Chouteau
    /* Store acc */
7236 a0e13900 Fabien Chouteau
    tcg_gen_st_i64(acc, cpu_env, offsetof(CPUState, spe_acc));
7237 a0e13900 Fabien Chouteau
7238 a0e13900 Fabien Chouteau
    /* rD := acc */
7239 a0e13900 Fabien Chouteau
    gen_store_gpr64(rD(ctx->opcode), acc);
7240 a0e13900 Fabien Chouteau
7241 a0e13900 Fabien Chouteau
    tcg_temp_free_i64(acc);
7242 a0e13900 Fabien Chouteau
    tcg_temp_free_i64(tmp);
7243 a0e13900 Fabien Chouteau
}
7244 a0e13900 Fabien Chouteau
7245 a0e13900 Fabien Chouteau
static inline void gen_evmwsmi(DisasContext *ctx)
7246 a0e13900 Fabien Chouteau
{
7247 a0e13900 Fabien Chouteau
    TCGv_i64 t0, t1;
7248 a0e13900 Fabien Chouteau
7249 a0e13900 Fabien Chouteau
    if (unlikely(!ctx->spe_enabled)) {
7250 a0e13900 Fabien Chouteau
        gen_exception(ctx, POWERPC_EXCP_APU);
7251 a0e13900 Fabien Chouteau
        return;
7252 a0e13900 Fabien Chouteau
    }
7253 a0e13900 Fabien Chouteau
7254 a0e13900 Fabien Chouteau
    t0 = tcg_temp_new_i64();
7255 a0e13900 Fabien Chouteau
    t1 = tcg_temp_new_i64();
7256 a0e13900 Fabien Chouteau
7257 a0e13900 Fabien Chouteau
    /* t0 := rA; t1 := rB */
7258 a0e13900 Fabien Chouteau
#if defined(TARGET_PPC64)
7259 a0e13900 Fabien Chouteau
    tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]);
7260 a0e13900 Fabien Chouteau
    tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]);
7261 a0e13900 Fabien Chouteau
#else
7262 a0e13900 Fabien Chouteau
    tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
7263 a0e13900 Fabien Chouteau
    tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
7264 a0e13900 Fabien Chouteau
#endif
7265 a0e13900 Fabien Chouteau
7266 a0e13900 Fabien Chouteau
    tcg_gen_mul_i64(t0, t0, t1);  /* t0 := rA * rB */
7267 a0e13900 Fabien Chouteau
7268 a0e13900 Fabien Chouteau
    gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */
7269 a0e13900 Fabien Chouteau
7270 a0e13900 Fabien Chouteau
    tcg_temp_free_i64(t0);
7271 a0e13900 Fabien Chouteau
    tcg_temp_free_i64(t1);
7272 a0e13900 Fabien Chouteau
}
7273 a0e13900 Fabien Chouteau
7274 a0e13900 Fabien Chouteau
static inline void gen_evmwsmia(DisasContext *ctx)
7275 a0e13900 Fabien Chouteau
{
7276 a0e13900 Fabien Chouteau
    TCGv_i64 tmp;
7277 a0e13900 Fabien Chouteau
7278 a0e13900 Fabien Chouteau
    gen_evmwsmi(ctx);            /* rD := rA * rB */
7279 a0e13900 Fabien Chouteau
7280 a0e13900 Fabien Chouteau
    tmp = tcg_temp_new_i64();
7281 a0e13900 Fabien Chouteau
7282 a0e13900 Fabien Chouteau
    /* acc := rD */
7283 a0e13900 Fabien Chouteau
    gen_load_gpr64(tmp, rD(ctx->opcode));
7284 a0e13900 Fabien Chouteau
    tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUState, spe_acc));
7285 a0e13900 Fabien Chouteau
7286 a0e13900 Fabien Chouteau
    tcg_temp_free_i64(tmp);
7287 a0e13900 Fabien Chouteau
}
7288 a0e13900 Fabien Chouteau
7289 a0e13900 Fabien Chouteau
static inline void gen_evmwsmiaa(DisasContext *ctx)
7290 a0e13900 Fabien Chouteau
{
7291 a0e13900 Fabien Chouteau
    TCGv_i64 acc = tcg_temp_new_i64();
7292 a0e13900 Fabien Chouteau
    TCGv_i64 tmp = tcg_temp_new_i64();
7293 a0e13900 Fabien Chouteau
7294 a0e13900 Fabien Chouteau
    gen_evmwsmi(ctx);           /* rD := rA * rB */
7295 a0e13900 Fabien Chouteau
7296 a0e13900 Fabien Chouteau
    acc = tcg_temp_new_i64();
7297 a0e13900 Fabien Chouteau
    tmp = tcg_temp_new_i64();
7298 a0e13900 Fabien Chouteau
7299 a0e13900 Fabien Chouteau
    /* tmp := rD */
7300 a0e13900 Fabien Chouteau
    gen_load_gpr64(tmp, rD(ctx->opcode));
7301 a0e13900 Fabien Chouteau
7302 a0e13900 Fabien Chouteau
    /* Load acc */
7303 a0e13900 Fabien Chouteau
    tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUState, spe_acc));
7304 a0e13900 Fabien Chouteau
7305 a0e13900 Fabien Chouteau
    /* acc := tmp + acc */
7306 a0e13900 Fabien Chouteau
    tcg_gen_add_i64(acc, acc, tmp);
7307 a0e13900 Fabien Chouteau
7308 a0e13900 Fabien Chouteau
    /* Store acc */
7309 a0e13900 Fabien Chouteau
    tcg_gen_st_i64(acc, cpu_env, offsetof(CPUState, spe_acc));
7310 a0e13900 Fabien Chouteau
7311 a0e13900 Fabien Chouteau
    /* rD := acc */
7312 a0e13900 Fabien Chouteau
    gen_store_gpr64(rD(ctx->opcode), acc);
7313 a0e13900 Fabien Chouteau
7314 a0e13900 Fabien Chouteau
    tcg_temp_free_i64(acc);
7315 a0e13900 Fabien Chouteau
    tcg_temp_free_i64(tmp);
7316 a0e13900 Fabien Chouteau
}
7317 a0e13900 Fabien Chouteau
7318 0487d6a8 j_mayer
GEN_SPE(evaddw,         speundef,      0x00, 0x08, 0x00000000, PPC_SPE); ////
7319 0487d6a8 j_mayer
GEN_SPE(evaddiw,        speundef,      0x01, 0x08, 0x00000000, PPC_SPE);
7320 0487d6a8 j_mayer
GEN_SPE(evsubfw,        speundef,      0x02, 0x08, 0x00000000, PPC_SPE); ////
7321 0487d6a8 j_mayer
GEN_SPE(evsubifw,       speundef,      0x03, 0x08, 0x00000000, PPC_SPE);
7322 0487d6a8 j_mayer
GEN_SPE(evabs,          evneg,         0x04, 0x08, 0x0000F800, PPC_SPE); ////
7323 0487d6a8 j_mayer
GEN_SPE(evextsb,        evextsh,       0x05, 0x08, 0x0000F800, PPC_SPE); ////
7324 0487d6a8 j_mayer
GEN_SPE(evrndw,         evcntlzw,      0x06, 0x08, 0x0000F800, PPC_SPE); ////
7325 0487d6a8 j_mayer
GEN_SPE(evcntlsw,       brinc,         0x07, 0x08, 0x00000000, PPC_SPE); //
7326 a0e13900 Fabien Chouteau
GEN_SPE(evmra,          speundef,      0x02, 0x13, 0x0000F800, PPC_SPE);
7327 0487d6a8 j_mayer
GEN_SPE(speundef,       evand,         0x08, 0x08, 0x00000000, PPC_SPE); ////
7328 0487d6a8 j_mayer
GEN_SPE(evandc,         speundef,      0x09, 0x08, 0x00000000, PPC_SPE); ////
7329 0487d6a8 j_mayer
GEN_SPE(evxor,          evor,          0x0B, 0x08, 0x00000000, PPC_SPE); ////
7330 0487d6a8 j_mayer
GEN_SPE(evnor,          eveqv,         0x0C, 0x08, 0x00000000, PPC_SPE); ////
7331 a0e13900 Fabien Chouteau
GEN_SPE(evmwumi,        evmwsmi,       0x0C, 0x11, 0x00000000, PPC_SPE);
7332 a0e13900 Fabien Chouteau
GEN_SPE(evmwumia,       evmwsmia,      0x1C, 0x11, 0x00000000, PPC_SPE);
7333 a0e13900 Fabien Chouteau
GEN_SPE(evmwumiaa,      evmwsmiaa,     0x0C, 0x15, 0x00000000, PPC_SPE);
7334 0487d6a8 j_mayer
GEN_SPE(speundef,       evorc,         0x0D, 0x08, 0x00000000, PPC_SPE); ////
7335 0487d6a8 j_mayer
GEN_SPE(evnand,         speundef,      0x0F, 0x08, 0x00000000, PPC_SPE); ////
7336 0487d6a8 j_mayer
GEN_SPE(evsrwu,         evsrws,        0x10, 0x08, 0x00000000, PPC_SPE); ////
7337 0487d6a8 j_mayer
GEN_SPE(evsrwiu,        evsrwis,       0x11, 0x08, 0x00000000, PPC_SPE);
7338 0487d6a8 j_mayer
GEN_SPE(evslw,          speundef,      0x12, 0x08, 0x00000000, PPC_SPE); ////
7339 0487d6a8 j_mayer
GEN_SPE(evslwi,         speundef,      0x13, 0x08, 0x00000000, PPC_SPE);
7340 0487d6a8 j_mayer
GEN_SPE(evrlw,          evsplati,      0x14, 0x08, 0x00000000, PPC_SPE); //
7341 0487d6a8 j_mayer
GEN_SPE(evrlwi,         evsplatfi,     0x15, 0x08, 0x00000000, PPC_SPE);
7342 0487d6a8 j_mayer
GEN_SPE(evmergehi,      evmergelo,     0x16, 0x08, 0x00000000, PPC_SPE); ////
7343 0487d6a8 j_mayer
GEN_SPE(evmergehilo,    evmergelohi,   0x17, 0x08, 0x00000000, PPC_SPE); ////
7344 0487d6a8 j_mayer
GEN_SPE(evcmpgtu,       evcmpgts,      0x18, 0x08, 0x00600000, PPC_SPE); ////
7345 0487d6a8 j_mayer
GEN_SPE(evcmpltu,       evcmplts,      0x19, 0x08, 0x00600000, PPC_SPE); ////
7346 0487d6a8 j_mayer
GEN_SPE(evcmpeq,        speundef,      0x1A, 0x08, 0x00600000, PPC_SPE); ////
7347 0487d6a8 j_mayer
7348 6a6ae23f aurel32
/* SPE load and stores */
7349 636aa200 Blue Swirl
static inline void gen_addr_spe_imm_index(DisasContext *ctx, TCGv EA, int sh)
7350 6a6ae23f aurel32
{
7351 6a6ae23f aurel32
    target_ulong uimm = rB(ctx->opcode);
7352 6a6ae23f aurel32
7353 76db3ba4 aurel32
    if (rA(ctx->opcode) == 0) {
7354 6a6ae23f aurel32
        tcg_gen_movi_tl(EA, uimm << sh);
7355 76db3ba4 aurel32
    } else {
7356 6a6ae23f aurel32
        tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], uimm << sh);
7357 76db3ba4 aurel32
#if defined(TARGET_PPC64)
7358 76db3ba4 aurel32
        if (!ctx->sf_mode) {
7359 76db3ba4 aurel32
            tcg_gen_ext32u_tl(EA, EA);
7360 76db3ba4 aurel32
        }
7361 76db3ba4 aurel32
#endif
7362 76db3ba4 aurel32
    }
7363 0487d6a8 j_mayer
}
7364 6a6ae23f aurel32
7365 636aa200 Blue Swirl
static inline void gen_op_evldd(DisasContext *ctx, TCGv addr)
7366 6a6ae23f aurel32
{
7367 6a6ae23f aurel32
#if defined(TARGET_PPC64)
7368 76db3ba4 aurel32
    gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], addr);
7369 6a6ae23f aurel32
#else
7370 6a6ae23f aurel32
    TCGv_i64 t0 = tcg_temp_new_i64();
7371 76db3ba4 aurel32
    gen_qemu_ld64(ctx, t0, addr);
7372 6a6ae23f aurel32
    tcg_gen_trunc_i64_i32(cpu_gpr[rD(ctx->opcode)], t0);
7373 6a6ae23f aurel32
    tcg_gen_shri_i64(t0, t0, 32);
7374 6a6ae23f aurel32
    tcg_gen_trunc_i64_i32(cpu_gprh[rD(ctx->opcode)], t0);
7375 6a6ae23f aurel32
    tcg_temp_free_i64(t0);
7376 6a6ae23f aurel32
#endif
7377 0487d6a8 j_mayer
}
7378 6a6ae23f aurel32
7379 636aa200 Blue Swirl
static inline void gen_op_evldw(DisasContext *ctx, TCGv addr)
7380 6a6ae23f aurel32
{
7381 0487d6a8 j_mayer
#if defined(TARGET_PPC64)
7382 6a6ae23f aurel32
    TCGv t0 = tcg_temp_new();
7383 76db3ba4 aurel32
    gen_qemu_ld32u(ctx, t0, addr);
7384 6a6ae23f aurel32
    tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
7385 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 4);
7386 76db3ba4 aurel32
    gen_qemu_ld32u(ctx, t0, addr);
7387 6a6ae23f aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7388 6a6ae23f aurel32
    tcg_temp_free(t0);
7389 6a6ae23f aurel32
#else
7390 76db3ba4 aurel32
    gen_qemu_ld32u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
7391 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 4);
7392 76db3ba4 aurel32
    gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
7393 6a6ae23f aurel32
#endif
7394 0487d6a8 j_mayer
}
7395 6a6ae23f aurel32
7396 636aa200 Blue Swirl
static inline void gen_op_evldh(DisasContext *ctx, TCGv addr)
7397 6a6ae23f aurel32
{
7398 6a6ae23f aurel32
    TCGv t0 = tcg_temp_new();
7399 6a6ae23f aurel32
#if defined(TARGET_PPC64)
7400 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, t0, addr);
7401 6a6ae23f aurel32
    tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
7402 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 2);
7403 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, t0, addr);
7404 6a6ae23f aurel32
    tcg_gen_shli_tl(t0, t0, 32);
7405 6a6ae23f aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7406 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 2);
7407 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, t0, addr);
7408 6a6ae23f aurel32
    tcg_gen_shli_tl(t0, t0, 16);
7409 6a6ae23f aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7410 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 2);
7411 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, t0, addr);
7412 6a6ae23f aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7413 0487d6a8 j_mayer
#else
7414 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, t0, addr);
7415 6a6ae23f aurel32
    tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
7416 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 2);
7417 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, t0, addr);
7418 6a6ae23f aurel32
    tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
7419 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 2);
7420 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, t0, addr);
7421 6a6ae23f aurel32
    tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
7422 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 2);
7423 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, t0, addr);
7424 6a6ae23f aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7425 0487d6a8 j_mayer
#endif
7426 6a6ae23f aurel32
    tcg_temp_free(t0);
7427 0487d6a8 j_mayer
}
7428 0487d6a8 j_mayer
7429 636aa200 Blue Swirl
static inline void gen_op_evlhhesplat(DisasContext *ctx, TCGv addr)
7430 6a6ae23f aurel32
{
7431 6a6ae23f aurel32
    TCGv t0 = tcg_temp_new();
7432 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, t0, addr);
7433 6a6ae23f aurel32
#if defined(TARGET_PPC64)
7434 6a6ae23f aurel32
    tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
7435 6a6ae23f aurel32
    tcg_gen_shli_tl(t0, t0, 16);
7436 6a6ae23f aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7437 6a6ae23f aurel32
#else
7438 6a6ae23f aurel32
    tcg_gen_shli_tl(t0, t0, 16);
7439 6a6ae23f aurel32
    tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
7440 6a6ae23f aurel32
    tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
7441 6a6ae23f aurel32
#endif
7442 6a6ae23f aurel32
    tcg_temp_free(t0);
7443 0487d6a8 j_mayer
}
7444 0487d6a8 j_mayer
7445 636aa200 Blue Swirl
static inline void gen_op_evlhhousplat(DisasContext *ctx, TCGv addr)
7446 6a6ae23f aurel32
{
7447 6a6ae23f aurel32
    TCGv t0 = tcg_temp_new();
7448 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, t0, addr);
7449 6a6ae23f aurel32
#if defined(TARGET_PPC64)
7450 6a6ae23f aurel32
    tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
7451 6a6ae23f aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7452 6a6ae23f aurel32
#else
7453 6a6ae23f aurel32
    tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
7454 6a6ae23f aurel32
    tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
7455 6a6ae23f aurel32
#endif
7456 6a6ae23f aurel32
    tcg_temp_free(t0);
7457 0487d6a8 j_mayer
}
7458 0487d6a8 j_mayer
7459 636aa200 Blue Swirl
static inline void gen_op_evlhhossplat(DisasContext *ctx, TCGv addr)
7460 6a6ae23f aurel32
{
7461 6a6ae23f aurel32
    TCGv t0 = tcg_temp_new();
7462 76db3ba4 aurel32
    gen_qemu_ld16s(ctx, t0, addr);
7463 6a6ae23f aurel32
#if defined(TARGET_PPC64)
7464 6a6ae23f aurel32
    tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
7465 6a6ae23f aurel32
    tcg_gen_ext32u_tl(t0, t0);
7466 6a6ae23f aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7467 6a6ae23f aurel32
#else
7468 6a6ae23f aurel32
    tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
7469 6a6ae23f aurel32
    tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
7470 6a6ae23f aurel32
#endif
7471 6a6ae23f aurel32
    tcg_temp_free(t0);
7472 6a6ae23f aurel32
}
7473 6a6ae23f aurel32
7474 636aa200 Blue Swirl
static inline void gen_op_evlwhe(DisasContext *ctx, TCGv addr)
7475 6a6ae23f aurel32
{
7476 6a6ae23f aurel32
    TCGv t0 = tcg_temp_new();
7477 6a6ae23f aurel32
#if defined(TARGET_PPC64)
7478 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, t0, addr);
7479 6a6ae23f aurel32
    tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
7480 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 2);
7481 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, t0, addr);
7482 6a6ae23f aurel32
    tcg_gen_shli_tl(t0, t0, 16);
7483 6a6ae23f aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7484 6a6ae23f aurel32
#else
7485 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, t0, addr);
7486 6a6ae23f aurel32
    tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
7487 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 2);
7488 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, t0, addr);
7489 6a6ae23f aurel32
    tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
7490 6a6ae23f aurel32
#endif
7491 6a6ae23f aurel32
    tcg_temp_free(t0);
7492 6a6ae23f aurel32
}
7493 6a6ae23f aurel32
7494 636aa200 Blue Swirl
static inline void gen_op_evlwhou(DisasContext *ctx, TCGv addr)
7495 6a6ae23f aurel32
{
7496 6a6ae23f aurel32
#if defined(TARGET_PPC64)
7497 6a6ae23f aurel32
    TCGv t0 = tcg_temp_new();
7498 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
7499 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 2);
7500 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, t0, addr);
7501 6a6ae23f aurel32
    tcg_gen_shli_tl(t0, t0, 32);
7502 6a6ae23f aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7503 6a6ae23f aurel32
    tcg_temp_free(t0);
7504 6a6ae23f aurel32
#else
7505 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, cpu_gprh[rD(ctx->opcode)], addr);
7506 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 2);
7507 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr);
7508 6a6ae23f aurel32
#endif
7509 6a6ae23f aurel32
}
7510 6a6ae23f aurel32
7511 636aa200 Blue Swirl
static inline void gen_op_evlwhos(DisasContext *ctx, TCGv addr)
7512 6a6ae23f aurel32
{
7513 6a6ae23f aurel32
#if defined(TARGET_PPC64)
7514 6a6ae23f aurel32
    TCGv t0 = tcg_temp_new();
7515 76db3ba4 aurel32
    gen_qemu_ld16s(ctx, t0, addr);
7516 6a6ae23f aurel32
    tcg_gen_ext32u_tl(cpu_gpr[rD(ctx->opcode)], t0);
7517 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 2);
7518 76db3ba4 aurel32
    gen_qemu_ld16s(ctx, t0, addr);
7519 6a6ae23f aurel32
    tcg_gen_shli_tl(t0, t0, 32);
7520 6a6ae23f aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7521 6a6ae23f aurel32
    tcg_temp_free(t0);
7522 6a6ae23f aurel32
#else
7523 76db3ba4 aurel32
    gen_qemu_ld16s(ctx, cpu_gprh[rD(ctx->opcode)], addr);
7524 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 2);
7525 76db3ba4 aurel32
    gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], addr);
7526 6a6ae23f aurel32
#endif
7527 6a6ae23f aurel32
}
7528 6a6ae23f aurel32
7529 636aa200 Blue Swirl
static inline void gen_op_evlwwsplat(DisasContext *ctx, TCGv addr)
7530 6a6ae23f aurel32
{
7531 6a6ae23f aurel32
    TCGv t0 = tcg_temp_new();
7532 76db3ba4 aurel32
    gen_qemu_ld32u(ctx, t0, addr);
7533 0487d6a8 j_mayer
#if defined(TARGET_PPC64)
7534 6a6ae23f aurel32
    tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32);
7535 6a6ae23f aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7536 6a6ae23f aurel32
#else
7537 6a6ae23f aurel32
    tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0);
7538 6a6ae23f aurel32
    tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
7539 6a6ae23f aurel32
#endif
7540 6a6ae23f aurel32
    tcg_temp_free(t0);
7541 6a6ae23f aurel32
}
7542 6a6ae23f aurel32
7543 636aa200 Blue Swirl
static inline void gen_op_evlwhsplat(DisasContext *ctx, TCGv addr)
7544 6a6ae23f aurel32
{
7545 6a6ae23f aurel32
    TCGv t0 = tcg_temp_new();
7546 6a6ae23f aurel32
#if defined(TARGET_PPC64)
7547 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, t0, addr);
7548 6a6ae23f aurel32
    tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48);
7549 6a6ae23f aurel32
    tcg_gen_shli_tl(t0, t0, 32);
7550 6a6ae23f aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7551 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 2);
7552 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, t0, addr);
7553 6a6ae23f aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7554 6a6ae23f aurel32
    tcg_gen_shli_tl(t0, t0, 16);
7555 6a6ae23f aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0);
7556 6a6ae23f aurel32
#else
7557 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, t0, addr);
7558 6a6ae23f aurel32
    tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16);
7559 6a6ae23f aurel32
    tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
7560 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 2);
7561 76db3ba4 aurel32
    gen_qemu_ld16u(ctx, t0, addr);
7562 6a6ae23f aurel32
    tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16);
7563 6a6ae23f aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0);
7564 0487d6a8 j_mayer
#endif
7565 6a6ae23f aurel32
    tcg_temp_free(t0);
7566 6a6ae23f aurel32
}
7567 6a6ae23f aurel32
7568 636aa200 Blue Swirl
static inline void gen_op_evstdd(DisasContext *ctx, TCGv addr)
7569 6a6ae23f aurel32
{
7570 6a6ae23f aurel32
#if defined(TARGET_PPC64)
7571 76db3ba4 aurel32
    gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], addr);
7572 0487d6a8 j_mayer
#else
7573 6a6ae23f aurel32
    TCGv_i64 t0 = tcg_temp_new_i64();
7574 6a6ae23f aurel32
    tcg_gen_concat_i32_i64(t0, cpu_gpr[rS(ctx->opcode)], cpu_gprh[rS(ctx->opcode)]);
7575 76db3ba4 aurel32
    gen_qemu_st64(ctx, t0, addr);
7576 6a6ae23f aurel32
    tcg_temp_free_i64(t0);
7577 6a6ae23f aurel32
#endif
7578 6a6ae23f aurel32
}
7579 6a6ae23f aurel32
7580 636aa200 Blue Swirl
static inline void gen_op_evstdw(DisasContext *ctx, TCGv addr)
7581 6a6ae23f aurel32
{
7582 0487d6a8 j_mayer
#if defined(TARGET_PPC64)
7583 6a6ae23f aurel32
    TCGv t0 = tcg_temp_new();
7584 6a6ae23f aurel32
    tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
7585 76db3ba4 aurel32
    gen_qemu_st32(ctx, t0, addr);
7586 6a6ae23f aurel32
    tcg_temp_free(t0);
7587 6a6ae23f aurel32
#else
7588 76db3ba4 aurel32
    gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
7589 6a6ae23f aurel32
#endif
7590 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 4);
7591 76db3ba4 aurel32
    gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
7592 6a6ae23f aurel32
}
7593 6a6ae23f aurel32
7594 636aa200 Blue Swirl
static inline void gen_op_evstdh(DisasContext *ctx, TCGv addr)
7595 6a6ae23f aurel32
{
7596 6a6ae23f aurel32
    TCGv t0 = tcg_temp_new();
7597 6a6ae23f aurel32
#if defined(TARGET_PPC64)
7598 6a6ae23f aurel32
    tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
7599 6a6ae23f aurel32
#else
7600 6a6ae23f aurel32
    tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
7601 6a6ae23f aurel32
#endif
7602 76db3ba4 aurel32
    gen_qemu_st16(ctx, t0, addr);
7603 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 2);
7604 6a6ae23f aurel32
#if defined(TARGET_PPC64)
7605 6a6ae23f aurel32
    tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
7606 76db3ba4 aurel32
    gen_qemu_st16(ctx, t0, addr);
7607 6a6ae23f aurel32
#else
7608 76db3ba4 aurel32
    gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
7609 6a6ae23f aurel32
#endif
7610 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 2);
7611 6a6ae23f aurel32
    tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
7612 76db3ba4 aurel32
    gen_qemu_st16(ctx, t0, addr);
7613 6a6ae23f aurel32
    tcg_temp_free(t0);
7614 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 2);
7615 76db3ba4 aurel32
    gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
7616 6a6ae23f aurel32
}
7617 6a6ae23f aurel32
7618 636aa200 Blue Swirl
static inline void gen_op_evstwhe(DisasContext *ctx, TCGv addr)
7619 6a6ae23f aurel32
{
7620 6a6ae23f aurel32
    TCGv t0 = tcg_temp_new();
7621 6a6ae23f aurel32
#if defined(TARGET_PPC64)
7622 6a6ae23f aurel32
    tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48);
7623 6a6ae23f aurel32
#else
7624 6a6ae23f aurel32
    tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16);
7625 6a6ae23f aurel32
#endif
7626 76db3ba4 aurel32
    gen_qemu_st16(ctx, t0, addr);
7627 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 2);
7628 6a6ae23f aurel32
    tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16);
7629 76db3ba4 aurel32
    gen_qemu_st16(ctx, t0, addr);
7630 6a6ae23f aurel32
    tcg_temp_free(t0);
7631 6a6ae23f aurel32
}
7632 6a6ae23f aurel32
7633 636aa200 Blue Swirl
static inline void gen_op_evstwho(DisasContext *ctx, TCGv addr)
7634 6a6ae23f aurel32
{
7635 6a6ae23f aurel32
#if defined(TARGET_PPC64)
7636 6a6ae23f aurel32
    TCGv t0 = tcg_temp_new();
7637 6a6ae23f aurel32
    tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
7638 76db3ba4 aurel32
    gen_qemu_st16(ctx, t0, addr);
7639 6a6ae23f aurel32
    tcg_temp_free(t0);
7640 6a6ae23f aurel32
#else
7641 76db3ba4 aurel32
    gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr);
7642 6a6ae23f aurel32
#endif
7643 76db3ba4 aurel32
    gen_addr_add(ctx, addr, addr, 2);
7644 76db3ba4 aurel32
    gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr);
7645 6a6ae23f aurel32
}
7646 6a6ae23f aurel32
7647 636aa200 Blue Swirl
static inline void gen_op_evstwwe(DisasContext *ctx, TCGv addr)
7648 6a6ae23f aurel32
{
7649 6a6ae23f aurel32
#if defined(TARGET_PPC64)
7650 6a6ae23f aurel32
    TCGv t0 = tcg_temp_new();
7651 6a6ae23f aurel32
    tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32);
7652 76db3ba4 aurel32
    gen_qemu_st32(ctx, t0, addr);
7653 6a6ae23f aurel32
    tcg_temp_free(t0);
7654 6a6ae23f aurel32
#else
7655 76db3ba4 aurel32
    gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr);
7656 6a6ae23f aurel32
#endif
7657 6a6ae23f aurel32
}
7658 6a6ae23f aurel32
7659 636aa200 Blue Swirl
static inline void gen_op_evstwwo(DisasContext *ctx, TCGv addr)
7660 6a6ae23f aurel32
{
7661 76db3ba4 aurel32
    gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr);
7662 6a6ae23f aurel32
}
7663 6a6ae23f aurel32
7664 6a6ae23f aurel32
#define GEN_SPEOP_LDST(name, opc2, sh)                                        \
7665 99e300ef Blue Swirl
static void glue(gen_, name)(DisasContext *ctx)                                       \
7666 6a6ae23f aurel32
{                                                                             \
7667 6a6ae23f aurel32
    TCGv t0;                                                                  \
7668 6a6ae23f aurel32
    if (unlikely(!ctx->spe_enabled)) {                                        \
7669 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
7670 6a6ae23f aurel32
        return;                                                               \
7671 6a6ae23f aurel32
    }                                                                         \
7672 76db3ba4 aurel32
    gen_set_access_type(ctx, ACCESS_INT);                                     \
7673 6a6ae23f aurel32
    t0 = tcg_temp_new();                                                      \
7674 6a6ae23f aurel32
    if (Rc(ctx->opcode)) {                                                    \
7675 76db3ba4 aurel32
        gen_addr_spe_imm_index(ctx, t0, sh);                                  \
7676 6a6ae23f aurel32
    } else {                                                                  \
7677 76db3ba4 aurel32
        gen_addr_reg_index(ctx, t0);                                          \
7678 6a6ae23f aurel32
    }                                                                         \
7679 6a6ae23f aurel32
    gen_op_##name(ctx, t0);                                                   \
7680 6a6ae23f aurel32
    tcg_temp_free(t0);                                                        \
7681 6a6ae23f aurel32
}
7682 6a6ae23f aurel32
7683 6a6ae23f aurel32
GEN_SPEOP_LDST(evldd, 0x00, 3);
7684 6a6ae23f aurel32
GEN_SPEOP_LDST(evldw, 0x01, 3);
7685 6a6ae23f aurel32
GEN_SPEOP_LDST(evldh, 0x02, 3);
7686 6a6ae23f aurel32
GEN_SPEOP_LDST(evlhhesplat, 0x04, 1);
7687 6a6ae23f aurel32
GEN_SPEOP_LDST(evlhhousplat, 0x06, 1);
7688 6a6ae23f aurel32
GEN_SPEOP_LDST(evlhhossplat, 0x07, 1);
7689 6a6ae23f aurel32
GEN_SPEOP_LDST(evlwhe, 0x08, 2);
7690 6a6ae23f aurel32
GEN_SPEOP_LDST(evlwhou, 0x0A, 2);
7691 6a6ae23f aurel32
GEN_SPEOP_LDST(evlwhos, 0x0B, 2);
7692 6a6ae23f aurel32
GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2);
7693 6a6ae23f aurel32
GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2);
7694 6a6ae23f aurel32
7695 6a6ae23f aurel32
GEN_SPEOP_LDST(evstdd, 0x10, 3);
7696 6a6ae23f aurel32
GEN_SPEOP_LDST(evstdw, 0x11, 3);
7697 6a6ae23f aurel32
GEN_SPEOP_LDST(evstdh, 0x12, 3);
7698 6a6ae23f aurel32
GEN_SPEOP_LDST(evstwhe, 0x18, 2);
7699 6a6ae23f aurel32
GEN_SPEOP_LDST(evstwho, 0x1A, 2);
7700 6a6ae23f aurel32
GEN_SPEOP_LDST(evstwwe, 0x1C, 2);
7701 6a6ae23f aurel32
GEN_SPEOP_LDST(evstwwo, 0x1E, 2);
7702 0487d6a8 j_mayer
7703 0487d6a8 j_mayer
/* Multiply and add - TODO */
7704 0487d6a8 j_mayer
#if 0
7705 0487d6a8 j_mayer
GEN_SPE(speundef,       evmhessf,      0x01, 0x10, 0x00000000, PPC_SPE);
7706 0487d6a8 j_mayer
GEN_SPE(speundef,       evmhossf,      0x03, 0x10, 0x00000000, PPC_SPE);
7707 0487d6a8 j_mayer
GEN_SPE(evmheumi,       evmhesmi,      0x04, 0x10, 0x00000000, PPC_SPE);
7708 0487d6a8 j_mayer
GEN_SPE(speundef,       evmhesmf,      0x05, 0x10, 0x00000000, PPC_SPE);
7709 0487d6a8 j_mayer
GEN_SPE(evmhoumi,       evmhosmi,      0x06, 0x10, 0x00000000, PPC_SPE);
7710 0487d6a8 j_mayer
GEN_SPE(speundef,       evmhosmf,      0x07, 0x10, 0x00000000, PPC_SPE);
7711 0487d6a8 j_mayer
GEN_SPE(speundef,       evmhessfa,     0x11, 0x10, 0x00000000, PPC_SPE);
7712 0487d6a8 j_mayer
GEN_SPE(speundef,       evmhossfa,     0x13, 0x10, 0x00000000, PPC_SPE);
7713 0487d6a8 j_mayer
GEN_SPE(evmheumia,      evmhesmia,     0x14, 0x10, 0x00000000, PPC_SPE);
7714 0487d6a8 j_mayer
GEN_SPE(speundef,       evmhesmfa,     0x15, 0x10, 0x00000000, PPC_SPE);
7715 0487d6a8 j_mayer
GEN_SPE(evmhoumia,      evmhosmia,     0x16, 0x10, 0x00000000, PPC_SPE);
7716 0487d6a8 j_mayer
GEN_SPE(speundef,       evmhosmfa,     0x17, 0x10, 0x00000000, PPC_SPE);
7717 0487d6a8 j_mayer

7718 0487d6a8 j_mayer
GEN_SPE(speundef,       evmwhssf,      0x03, 0x11, 0x00000000, PPC_SPE);
7719 0487d6a8 j_mayer
GEN_SPE(evmwlumi,       speundef,      0x04, 0x11, 0x00000000, PPC_SPE);
7720 0487d6a8 j_mayer
GEN_SPE(evmwhumi,       evmwhsmi,      0x06, 0x11, 0x00000000, PPC_SPE);
7721 0487d6a8 j_mayer
GEN_SPE(speundef,       evmwhsmf,      0x07, 0x11, 0x00000000, PPC_SPE);
7722 0487d6a8 j_mayer
GEN_SPE(speundef,       evmwssf,       0x09, 0x11, 0x00000000, PPC_SPE);
7723 0487d6a8 j_mayer
GEN_SPE(speundef,       evmwsmf,       0x0D, 0x11, 0x00000000, PPC_SPE);
7724 0487d6a8 j_mayer
GEN_SPE(speundef,       evmwhssfa,     0x13, 0x11, 0x00000000, PPC_SPE);
7725 0487d6a8 j_mayer
GEN_SPE(evmwlumia,      speundef,      0x14, 0x11, 0x00000000, PPC_SPE);
7726 0487d6a8 j_mayer
GEN_SPE(evmwhumia,      evmwhsmia,     0x16, 0x11, 0x00000000, PPC_SPE);
7727 0487d6a8 j_mayer
GEN_SPE(speundef,       evmwhsmfa,     0x17, 0x11, 0x00000000, PPC_SPE);
7728 0487d6a8 j_mayer
GEN_SPE(speundef,       evmwssfa,      0x19, 0x11, 0x00000000, PPC_SPE);
7729 0487d6a8 j_mayer
GEN_SPE(speundef,       evmwsmfa,      0x1D, 0x11, 0x00000000, PPC_SPE);
7730 0487d6a8 j_mayer

7731 0487d6a8 j_mayer
GEN_SPE(evadduiaaw,     evaddsiaaw,    0x00, 0x13, 0x0000F800, PPC_SPE);
7732 0487d6a8 j_mayer
GEN_SPE(evsubfusiaaw,   evsubfssiaaw,  0x01, 0x13, 0x0000F800, PPC_SPE);
7733 0487d6a8 j_mayer
GEN_SPE(evaddumiaaw,    evaddsmiaaw,   0x04, 0x13, 0x0000F800, PPC_SPE);
7734 0487d6a8 j_mayer
GEN_SPE(evsubfumiaaw,   evsubfsmiaaw,  0x05, 0x13, 0x0000F800, PPC_SPE);
7735 0487d6a8 j_mayer
GEN_SPE(evdivws,        evdivwu,       0x06, 0x13, 0x00000000, PPC_SPE);
7736 0487d6a8 j_mayer

7737 0487d6a8 j_mayer
GEN_SPE(evmheusiaaw,    evmhessiaaw,   0x00, 0x14, 0x00000000, PPC_SPE);
7738 0487d6a8 j_mayer
GEN_SPE(speundef,       evmhessfaaw,   0x01, 0x14, 0x00000000, PPC_SPE);
7739 0487d6a8 j_mayer
GEN_SPE(evmhousiaaw,    evmhossiaaw,   0x02, 0x14, 0x00000000, PPC_SPE);
7740 0487d6a8 j_mayer
GEN_SPE(speundef,       evmhossfaaw,   0x03, 0x14, 0x00000000, PPC_SPE);
7741 0487d6a8 j_mayer
GEN_SPE(evmheumiaaw,    evmhesmiaaw,   0x04, 0x14, 0x00000000, PPC_SPE);
7742 0487d6a8 j_mayer
GEN_SPE(speundef,       evmhesmfaaw,   0x05, 0x14, 0x00000000, PPC_SPE);
7743 0487d6a8 j_mayer
GEN_SPE(evmhoumiaaw,    evmhosmiaaw,   0x06, 0x14, 0x00000000, PPC_SPE);
7744 0487d6a8 j_mayer
GEN_SPE(speundef,       evmhosmfaaw,   0x07, 0x14, 0x00000000, PPC_SPE);
7745 0487d6a8 j_mayer
GEN_SPE(evmhegumiaa,    evmhegsmiaa,   0x14, 0x14, 0x00000000, PPC_SPE);
7746 0487d6a8 j_mayer
GEN_SPE(speundef,       evmhegsmfaa,   0x15, 0x14, 0x00000000, PPC_SPE);
7747 0487d6a8 j_mayer
GEN_SPE(evmhogumiaa,    evmhogsmiaa,   0x16, 0x14, 0x00000000, PPC_SPE);
7748 0487d6a8 j_mayer
GEN_SPE(speundef,       evmhogsmfaa,   0x17, 0x14, 0x00000000, PPC_SPE);
7749 0487d6a8 j_mayer

7750 0487d6a8 j_mayer
GEN_SPE(evmwlusiaaw,    evmwlssiaaw,   0x00, 0x15, 0x00000000, PPC_SPE);
7751 0487d6a8 j_mayer
GEN_SPE(evmwlumiaaw,    evmwlsmiaaw,   0x04, 0x15, 0x00000000, PPC_SPE);
7752 0487d6a8 j_mayer
GEN_SPE(speundef,       evmwssfaa,     0x09, 0x15, 0x00000000, PPC_SPE);
7753 0487d6a8 j_mayer
GEN_SPE(speundef,       evmwsmfaa,     0x0D, 0x15, 0x00000000, PPC_SPE);
7754 0487d6a8 j_mayer

7755 0487d6a8 j_mayer
GEN_SPE(evmheusianw,    evmhessianw,   0x00, 0x16, 0x00000000, PPC_SPE);
7756 0487d6a8 j_mayer
GEN_SPE(speundef,       evmhessfanw,   0x01, 0x16, 0x00000000, PPC_SPE);
7757 0487d6a8 j_mayer
GEN_SPE(evmhousianw,    evmhossianw,   0x02, 0x16, 0x00000000, PPC_SPE);
7758 0487d6a8 j_mayer
GEN_SPE(speundef,       evmhossfanw,   0x03, 0x16, 0x00000000, PPC_SPE);
7759 0487d6a8 j_mayer
GEN_SPE(evmheumianw,    evmhesmianw,   0x04, 0x16, 0x00000000, PPC_SPE);
7760 0487d6a8 j_mayer
GEN_SPE(speundef,       evmhesmfanw,   0x05, 0x16, 0x00000000, PPC_SPE);
7761 0487d6a8 j_mayer
GEN_SPE(evmhoumianw,    evmhosmianw,   0x06, 0x16, 0x00000000, PPC_SPE);
7762 0487d6a8 j_mayer
GEN_SPE(speundef,       evmhosmfanw,   0x07, 0x16, 0x00000000, PPC_SPE);
7763 0487d6a8 j_mayer
GEN_SPE(evmhegumian,    evmhegsmian,   0x14, 0x16, 0x00000000, PPC_SPE);
7764 0487d6a8 j_mayer
GEN_SPE(speundef,       evmhegsmfan,   0x15, 0x16, 0x00000000, PPC_SPE);
7765 0487d6a8 j_mayer
GEN_SPE(evmhigumian,    evmhigsmian,   0x16, 0x16, 0x00000000, PPC_SPE);
7766 0487d6a8 j_mayer
GEN_SPE(speundef,       evmhogsmfan,   0x17, 0x16, 0x00000000, PPC_SPE);
7767 0487d6a8 j_mayer

7768 0487d6a8 j_mayer
GEN_SPE(evmwlusianw,    evmwlssianw,   0x00, 0x17, 0x00000000, PPC_SPE);
7769 0487d6a8 j_mayer
GEN_SPE(evmwlumianw,    evmwlsmianw,   0x04, 0x17, 0x00000000, PPC_SPE);
7770 0487d6a8 j_mayer
GEN_SPE(speundef,       evmwssfan,     0x09, 0x17, 0x00000000, PPC_SPE);
7771 0487d6a8 j_mayer
GEN_SPE(evmwumian,      evmwsmian,     0x0C, 0x17, 0x00000000, PPC_SPE);
7772 0487d6a8 j_mayer
GEN_SPE(speundef,       evmwsmfan,     0x0D, 0x17, 0x00000000, PPC_SPE);
7773 0487d6a8 j_mayer
#endif
7774 0487d6a8 j_mayer
7775 0487d6a8 j_mayer
/***                      SPE floating-point extension                     ***/
7776 1c97856d aurel32
#if defined(TARGET_PPC64)
7777 1c97856d aurel32
#define GEN_SPEFPUOP_CONV_32_32(name)                                         \
7778 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
7779 0487d6a8 j_mayer
{                                                                             \
7780 1c97856d aurel32
    TCGv_i32 t0;                                                              \
7781 1c97856d aurel32
    TCGv t1;                                                                  \
7782 1c97856d aurel32
    t0 = tcg_temp_new_i32();                                                  \
7783 1c97856d aurel32
    tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]);                       \
7784 1c97856d aurel32
    gen_helper_##name(t0, t0);                                                \
7785 1c97856d aurel32
    t1 = tcg_temp_new();                                                      \
7786 1c97856d aurel32
    tcg_gen_extu_i32_tl(t1, t0);                                              \
7787 1c97856d aurel32
    tcg_temp_free_i32(t0);                                                    \
7788 1c97856d aurel32
    tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)],       \
7789 1c97856d aurel32
                    0xFFFFFFFF00000000ULL);                                   \
7790 1c97856d aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1);    \
7791 1c97856d aurel32
    tcg_temp_free(t1);                                                        \
7792 0487d6a8 j_mayer
}
7793 1c97856d aurel32
#define GEN_SPEFPUOP_CONV_32_64(name)                                         \
7794 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
7795 1c97856d aurel32
{                                                                             \
7796 1c97856d aurel32
    TCGv_i32 t0;                                                              \
7797 1c97856d aurel32
    TCGv t1;                                                                  \
7798 1c97856d aurel32
    t0 = tcg_temp_new_i32();                                                  \
7799 1c97856d aurel32
    gen_helper_##name(t0, cpu_gpr[rB(ctx->opcode)]);                          \
7800 1c97856d aurel32
    t1 = tcg_temp_new();                                                      \
7801 1c97856d aurel32
    tcg_gen_extu_i32_tl(t1, t0);                                              \
7802 1c97856d aurel32
    tcg_temp_free_i32(t0);                                                    \
7803 1c97856d aurel32
    tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)],       \
7804 1c97856d aurel32
                    0xFFFFFFFF00000000ULL);                                   \
7805 1c97856d aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1);    \
7806 1c97856d aurel32
    tcg_temp_free(t1);                                                        \
7807 1c97856d aurel32
}
7808 1c97856d aurel32
#define GEN_SPEFPUOP_CONV_64_32(name)                                         \
7809 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
7810 1c97856d aurel32
{                                                                             \
7811 1c97856d aurel32
    TCGv_i32 t0 = tcg_temp_new_i32();                                         \
7812 1c97856d aurel32
    tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]);                       \
7813 1c97856d aurel32
    gen_helper_##name(cpu_gpr[rD(ctx->opcode)], t0);                          \
7814 1c97856d aurel32
    tcg_temp_free_i32(t0);                                                    \
7815 1c97856d aurel32
}
7816 1c97856d aurel32
#define GEN_SPEFPUOP_CONV_64_64(name)                                         \
7817 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
7818 1c97856d aurel32
{                                                                             \
7819 1c97856d aurel32
    gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);    \
7820 1c97856d aurel32
}
7821 1c97856d aurel32
#define GEN_SPEFPUOP_ARITH2_32_32(name)                                       \
7822 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
7823 57951c27 aurel32
{                                                                             \
7824 1c97856d aurel32
    TCGv_i32 t0, t1;                                                          \
7825 1c97856d aurel32
    TCGv_i64 t2;                                                              \
7826 57951c27 aurel32
    if (unlikely(!ctx->spe_enabled)) {                                        \
7827 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
7828 57951c27 aurel32
        return;                                                               \
7829 57951c27 aurel32
    }                                                                         \
7830 1c97856d aurel32
    t0 = tcg_temp_new_i32();                                                  \
7831 1c97856d aurel32
    t1 = tcg_temp_new_i32();                                                  \
7832 1c97856d aurel32
    tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);                       \
7833 1c97856d aurel32
    tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);                       \
7834 1c97856d aurel32
    gen_helper_##name(t0, t0, t1);                                            \
7835 1c97856d aurel32
    tcg_temp_free_i32(t1);                                                    \
7836 1c97856d aurel32
    t2 = tcg_temp_new();                                                      \
7837 1c97856d aurel32
    tcg_gen_extu_i32_tl(t2, t0);                                              \
7838 1c97856d aurel32
    tcg_temp_free_i32(t0);                                                    \
7839 1c97856d aurel32
    tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)],       \
7840 1c97856d aurel32
                    0xFFFFFFFF00000000ULL);                                   \
7841 1c97856d aurel32
    tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2);    \
7842 1c97856d aurel32
    tcg_temp_free(t2);                                                        \
7843 57951c27 aurel32
}
7844 1c97856d aurel32
#define GEN_SPEFPUOP_ARITH2_64_64(name)                                       \
7845 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
7846 57951c27 aurel32
{                                                                             \
7847 57951c27 aurel32
    if (unlikely(!ctx->spe_enabled)) {                                        \
7848 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
7849 57951c27 aurel32
        return;                                                               \
7850 57951c27 aurel32
    }                                                                         \
7851 1c97856d aurel32
    gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],     \
7852 1c97856d aurel32
                      cpu_gpr[rB(ctx->opcode)]);                              \
7853 57951c27 aurel32
}
7854 1c97856d aurel32
#define GEN_SPEFPUOP_COMP_32(name)                                            \
7855 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
7856 57951c27 aurel32
{                                                                             \
7857 1c97856d aurel32
    TCGv_i32 t0, t1;                                                          \
7858 57951c27 aurel32
    if (unlikely(!ctx->spe_enabled)) {                                        \
7859 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
7860 57951c27 aurel32
        return;                                                               \
7861 57951c27 aurel32
    }                                                                         \
7862 1c97856d aurel32
    t0 = tcg_temp_new_i32();                                                  \
7863 1c97856d aurel32
    t1 = tcg_temp_new_i32();                                                  \
7864 1c97856d aurel32
    tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]);                       \
7865 1c97856d aurel32
    tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]);                       \
7866 1c97856d aurel32
    gen_helper_##name(cpu_crf[crfD(ctx->opcode)], t0, t1);                    \
7867 1c97856d aurel32
    tcg_temp_free_i32(t0);                                                    \
7868 1c97856d aurel32
    tcg_temp_free_i32(t1);                                                    \
7869 1c97856d aurel32
}
7870 1c97856d aurel32
#define GEN_SPEFPUOP_COMP_64(name)                                            \
7871 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
7872 1c97856d aurel32
{                                                                             \
7873 1c97856d aurel32
    if (unlikely(!ctx->spe_enabled)) {                                        \
7874 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
7875 1c97856d aurel32
        return;                                                               \
7876 1c97856d aurel32
    }                                                                         \
7877 1c97856d aurel32
    gen_helper_##name(cpu_crf[crfD(ctx->opcode)],                             \
7878 1c97856d aurel32
                      cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);    \
7879 1c97856d aurel32
}
7880 1c97856d aurel32
#else
7881 1c97856d aurel32
#define GEN_SPEFPUOP_CONV_32_32(name)                                         \
7882 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
7883 1c97856d aurel32
{                                                                             \
7884 1c97856d aurel32
    gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);    \
7885 57951c27 aurel32
}
7886 1c97856d aurel32
#define GEN_SPEFPUOP_CONV_32_64(name)                                         \
7887 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
7888 1c97856d aurel32
{                                                                             \
7889 1c97856d aurel32
    TCGv_i64 t0 = tcg_temp_new_i64();                                         \
7890 1c97856d aurel32
    gen_load_gpr64(t0, rB(ctx->opcode));                                      \
7891 1c97856d aurel32
    gen_helper_##name(cpu_gpr[rD(ctx->opcode)], t0);                          \
7892 1c97856d aurel32
    tcg_temp_free_i64(t0);                                                    \
7893 1c97856d aurel32
}
7894 1c97856d aurel32
#define GEN_SPEFPUOP_CONV_64_32(name)                                         \
7895 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
7896 1c97856d aurel32
{                                                                             \
7897 1c97856d aurel32
    TCGv_i64 t0 = tcg_temp_new_i64();                                         \
7898 1c97856d aurel32
    gen_helper_##name(t0, cpu_gpr[rB(ctx->opcode)]);                          \
7899 1c97856d aurel32
    gen_store_gpr64(rD(ctx->opcode), t0);                                     \
7900 1c97856d aurel32
    tcg_temp_free_i64(t0);                                                    \
7901 1c97856d aurel32
}
7902 1c97856d aurel32
#define GEN_SPEFPUOP_CONV_64_64(name)                                         \
7903 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
7904 1c97856d aurel32
{                                                                             \
7905 1c97856d aurel32
    TCGv_i64 t0 = tcg_temp_new_i64();                                         \
7906 1c97856d aurel32
    gen_load_gpr64(t0, rB(ctx->opcode));                                      \
7907 1c97856d aurel32
    gen_helper_##name(t0, t0);                                                \
7908 1c97856d aurel32
    gen_store_gpr64(rD(ctx->opcode), t0);                                     \
7909 1c97856d aurel32
    tcg_temp_free_i64(t0);                                                    \
7910 1c97856d aurel32
}
7911 1c97856d aurel32
#define GEN_SPEFPUOP_ARITH2_32_32(name)                                       \
7912 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
7913 1c97856d aurel32
{                                                                             \
7914 1c97856d aurel32
    if (unlikely(!ctx->spe_enabled)) {                                        \
7915 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
7916 1c97856d aurel32
        return;                                                               \
7917 1c97856d aurel32
    }                                                                         \
7918 1c97856d aurel32
    gen_helper_##name(cpu_gpr[rD(ctx->opcode)],                               \
7919 1c97856d aurel32
                      cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);    \
7920 1c97856d aurel32
}
7921 1c97856d aurel32
#define GEN_SPEFPUOP_ARITH2_64_64(name)                                       \
7922 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
7923 1c97856d aurel32
{                                                                             \
7924 1c97856d aurel32
    TCGv_i64 t0, t1;                                                          \
7925 1c97856d aurel32
    if (unlikely(!ctx->spe_enabled)) {                                        \
7926 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
7927 1c97856d aurel32
        return;                                                               \
7928 1c97856d aurel32
    }                                                                         \
7929 1c97856d aurel32
    t0 = tcg_temp_new_i64();                                                  \
7930 1c97856d aurel32
    t1 = tcg_temp_new_i64();                                                  \
7931 1c97856d aurel32
    gen_load_gpr64(t0, rA(ctx->opcode));                                      \
7932 1c97856d aurel32
    gen_load_gpr64(t1, rB(ctx->opcode));                                      \
7933 1c97856d aurel32
    gen_helper_##name(t0, t0, t1);                                            \
7934 1c97856d aurel32
    gen_store_gpr64(rD(ctx->opcode), t0);                                     \
7935 1c97856d aurel32
    tcg_temp_free_i64(t0);                                                    \
7936 1c97856d aurel32
    tcg_temp_free_i64(t1);                                                    \
7937 1c97856d aurel32
}
7938 1c97856d aurel32
#define GEN_SPEFPUOP_COMP_32(name)                                            \
7939 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
7940 1c97856d aurel32
{                                                                             \
7941 1c97856d aurel32
    if (unlikely(!ctx->spe_enabled)) {                                        \
7942 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
7943 1c97856d aurel32
        return;                                                               \
7944 1c97856d aurel32
    }                                                                         \
7945 1c97856d aurel32
    gen_helper_##name(cpu_crf[crfD(ctx->opcode)],                             \
7946 1c97856d aurel32
                      cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);    \
7947 1c97856d aurel32
}
7948 1c97856d aurel32
#define GEN_SPEFPUOP_COMP_64(name)                                            \
7949 636aa200 Blue Swirl
static inline void gen_##name(DisasContext *ctx)                              \
7950 1c97856d aurel32
{                                                                             \
7951 1c97856d aurel32
    TCGv_i64 t0, t1;                                                          \
7952 1c97856d aurel32
    if (unlikely(!ctx->spe_enabled)) {                                        \
7953 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);                                 \
7954 1c97856d aurel32
        return;                                                               \
7955 1c97856d aurel32
    }                                                                         \
7956 1c97856d aurel32
    t0 = tcg_temp_new_i64();                                                  \
7957 1c97856d aurel32
    t1 = tcg_temp_new_i64();                                                  \
7958 1c97856d aurel32
    gen_load_gpr64(t0, rA(ctx->opcode));                                      \
7959 1c97856d aurel32
    gen_load_gpr64(t1, rB(ctx->opcode));                                      \
7960 1c97856d aurel32
    gen_helper_##name(cpu_crf[crfD(ctx->opcode)], t0, t1);                    \
7961 1c97856d aurel32
    tcg_temp_free_i64(t0);                                                    \
7962 1c97856d aurel32
    tcg_temp_free_i64(t1);                                                    \
7963 1c97856d aurel32
}
7964 1c97856d aurel32
#endif
7965 57951c27 aurel32
7966 0487d6a8 j_mayer
/* Single precision floating-point vectors operations */
7967 0487d6a8 j_mayer
/* Arithmetic */
7968 1c97856d aurel32
GEN_SPEFPUOP_ARITH2_64_64(evfsadd);
7969 1c97856d aurel32
GEN_SPEFPUOP_ARITH2_64_64(evfssub);
7970 1c97856d aurel32
GEN_SPEFPUOP_ARITH2_64_64(evfsmul);
7971 1c97856d aurel32
GEN_SPEFPUOP_ARITH2_64_64(evfsdiv);
7972 636aa200 Blue Swirl
static inline void gen_evfsabs(DisasContext *ctx)
7973 1c97856d aurel32
{
7974 1c97856d aurel32
    if (unlikely(!ctx->spe_enabled)) {
7975 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);
7976 1c97856d aurel32
        return;
7977 1c97856d aurel32
    }
7978 1c97856d aurel32
#if defined(TARGET_PPC64)
7979 6d5c34fa Mike Pall
    tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000080000000LL);
7980 1c97856d aurel32
#else
7981 6d5c34fa Mike Pall
    tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x80000000);
7982 6d5c34fa Mike Pall
    tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
7983 1c97856d aurel32
#endif
7984 1c97856d aurel32
}
7985 636aa200 Blue Swirl
static inline void gen_evfsnabs(DisasContext *ctx)
7986 1c97856d aurel32
{
7987 1c97856d aurel32
    if (unlikely(!ctx->spe_enabled)) {
7988 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);
7989 1c97856d aurel32
        return;
7990 1c97856d aurel32
    }
7991 1c97856d aurel32
#if defined(TARGET_PPC64)
7992 6d5c34fa Mike Pall
    tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
7993 1c97856d aurel32
#else
7994 6d5c34fa Mike Pall
    tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
7995 6d5c34fa Mike Pall
    tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
7996 1c97856d aurel32
#endif
7997 1c97856d aurel32
}
7998 636aa200 Blue Swirl
static inline void gen_evfsneg(DisasContext *ctx)
7999 1c97856d aurel32
{
8000 1c97856d aurel32
    if (unlikely(!ctx->spe_enabled)) {
8001 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);
8002 1c97856d aurel32
        return;
8003 1c97856d aurel32
    }
8004 1c97856d aurel32
#if defined(TARGET_PPC64)
8005 6d5c34fa Mike Pall
    tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL);
8006 1c97856d aurel32
#else
8007 6d5c34fa Mike Pall
    tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
8008 6d5c34fa Mike Pall
    tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
8009 1c97856d aurel32
#endif
8010 1c97856d aurel32
}
8011 1c97856d aurel32
8012 0487d6a8 j_mayer
/* Conversion */
8013 1c97856d aurel32
GEN_SPEFPUOP_CONV_64_64(evfscfui);
8014 1c97856d aurel32
GEN_SPEFPUOP_CONV_64_64(evfscfsi);
8015 1c97856d aurel32
GEN_SPEFPUOP_CONV_64_64(evfscfuf);
8016 1c97856d aurel32
GEN_SPEFPUOP_CONV_64_64(evfscfsf);
8017 1c97856d aurel32
GEN_SPEFPUOP_CONV_64_64(evfsctui);
8018 1c97856d aurel32
GEN_SPEFPUOP_CONV_64_64(evfsctsi);
8019 1c97856d aurel32
GEN_SPEFPUOP_CONV_64_64(evfsctuf);
8020 1c97856d aurel32
GEN_SPEFPUOP_CONV_64_64(evfsctsf);
8021 1c97856d aurel32
GEN_SPEFPUOP_CONV_64_64(evfsctuiz);
8022 1c97856d aurel32
GEN_SPEFPUOP_CONV_64_64(evfsctsiz);
8023 1c97856d aurel32
8024 0487d6a8 j_mayer
/* Comparison */
8025 1c97856d aurel32
GEN_SPEFPUOP_COMP_64(evfscmpgt);
8026 1c97856d aurel32
GEN_SPEFPUOP_COMP_64(evfscmplt);
8027 1c97856d aurel32
GEN_SPEFPUOP_COMP_64(evfscmpeq);
8028 1c97856d aurel32
GEN_SPEFPUOP_COMP_64(evfststgt);
8029 1c97856d aurel32
GEN_SPEFPUOP_COMP_64(evfststlt);
8030 1c97856d aurel32
GEN_SPEFPUOP_COMP_64(evfststeq);
8031 0487d6a8 j_mayer
8032 0487d6a8 j_mayer
/* Opcodes definitions */
8033 40569b7e aurel32
GEN_SPE(evfsadd,        evfssub,       0x00, 0x0A, 0x00000000, PPC_SPE_SINGLE); //
8034 40569b7e aurel32
GEN_SPE(evfsabs,        evfsnabs,      0x02, 0x0A, 0x0000F800, PPC_SPE_SINGLE); //
8035 40569b7e aurel32
GEN_SPE(evfsneg,        speundef,      0x03, 0x0A, 0x0000F800, PPC_SPE_SINGLE); //
8036 40569b7e aurel32
GEN_SPE(evfsmul,        evfsdiv,       0x04, 0x0A, 0x00000000, PPC_SPE_SINGLE); //
8037 40569b7e aurel32
GEN_SPE(evfscmpgt,      evfscmplt,     0x06, 0x0A, 0x00600000, PPC_SPE_SINGLE); //
8038 40569b7e aurel32
GEN_SPE(evfscmpeq,      speundef,      0x07, 0x0A, 0x00600000, PPC_SPE_SINGLE); //
8039 40569b7e aurel32
GEN_SPE(evfscfui,       evfscfsi,      0x08, 0x0A, 0x00180000, PPC_SPE_SINGLE); //
8040 40569b7e aurel32
GEN_SPE(evfscfuf,       evfscfsf,      0x09, 0x0A, 0x00180000, PPC_SPE_SINGLE); //
8041 40569b7e aurel32
GEN_SPE(evfsctui,       evfsctsi,      0x0A, 0x0A, 0x00180000, PPC_SPE_SINGLE); //
8042 40569b7e aurel32
GEN_SPE(evfsctuf,       evfsctsf,      0x0B, 0x0A, 0x00180000, PPC_SPE_SINGLE); //
8043 40569b7e aurel32
GEN_SPE(evfsctuiz,      speundef,      0x0C, 0x0A, 0x00180000, PPC_SPE_SINGLE); //
8044 40569b7e aurel32
GEN_SPE(evfsctsiz,      speundef,      0x0D, 0x0A, 0x00180000, PPC_SPE_SINGLE); //
8045 40569b7e aurel32
GEN_SPE(evfststgt,      evfststlt,     0x0E, 0x0A, 0x00600000, PPC_SPE_SINGLE); //
8046 40569b7e aurel32
GEN_SPE(evfststeq,      speundef,      0x0F, 0x0A, 0x00600000, PPC_SPE_SINGLE); //
8047 0487d6a8 j_mayer
8048 0487d6a8 j_mayer
/* Single precision floating-point operations */
8049 0487d6a8 j_mayer
/* Arithmetic */
8050 1c97856d aurel32
GEN_SPEFPUOP_ARITH2_32_32(efsadd);
8051 1c97856d aurel32
GEN_SPEFPUOP_ARITH2_32_32(efssub);
8052 1c97856d aurel32
GEN_SPEFPUOP_ARITH2_32_32(efsmul);
8053 1c97856d aurel32
GEN_SPEFPUOP_ARITH2_32_32(efsdiv);
8054 636aa200 Blue Swirl
static inline void gen_efsabs(DisasContext *ctx)
8055 1c97856d aurel32
{
8056 1c97856d aurel32
    if (unlikely(!ctx->spe_enabled)) {
8057 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);
8058 1c97856d aurel32
        return;
8059 1c97856d aurel32
    }
8060 6d5c34fa Mike Pall
    tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL);
8061 1c97856d aurel32
}
8062 636aa200 Blue Swirl
static inline void gen_efsnabs(DisasContext *ctx)
8063 1c97856d aurel32
{
8064 1c97856d aurel32
    if (unlikely(!ctx->spe_enabled)) {
8065 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);
8066 1c97856d aurel32
        return;
8067 1c97856d aurel32
    }
8068 6d5c34fa Mike Pall
    tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
8069 1c97856d aurel32
}
8070 636aa200 Blue Swirl
static inline void gen_efsneg(DisasContext *ctx)
8071 1c97856d aurel32
{
8072 1c97856d aurel32
    if (unlikely(!ctx->spe_enabled)) {
8073 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);
8074 1c97856d aurel32
        return;
8075 1c97856d aurel32
    }
8076 6d5c34fa Mike Pall
    tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000);
8077 1c97856d aurel32
}
8078 1c97856d aurel32
8079 0487d6a8 j_mayer
/* Conversion */
8080 1c97856d aurel32
GEN_SPEFPUOP_CONV_32_32(efscfui);
8081 1c97856d aurel32
GEN_SPEFPUOP_CONV_32_32(efscfsi);
8082 1c97856d aurel32
GEN_SPEFPUOP_CONV_32_32(efscfuf);
8083 1c97856d aurel32
GEN_SPEFPUOP_CONV_32_32(efscfsf);
8084 1c97856d aurel32
GEN_SPEFPUOP_CONV_32_32(efsctui);
8085 1c97856d aurel32
GEN_SPEFPUOP_CONV_32_32(efsctsi);
8086 1c97856d aurel32
GEN_SPEFPUOP_CONV_32_32(efsctuf);
8087 1c97856d aurel32
GEN_SPEFPUOP_CONV_32_32(efsctsf);
8088 1c97856d aurel32
GEN_SPEFPUOP_CONV_32_32(efsctuiz);
8089 1c97856d aurel32
GEN_SPEFPUOP_CONV_32_32(efsctsiz);
8090 1c97856d aurel32
GEN_SPEFPUOP_CONV_32_64(efscfd);
8091 1c97856d aurel32
8092 0487d6a8 j_mayer
/* Comparison */
8093 1c97856d aurel32
GEN_SPEFPUOP_COMP_32(efscmpgt);
8094 1c97856d aurel32
GEN_SPEFPUOP_COMP_32(efscmplt);
8095 1c97856d aurel32
GEN_SPEFPUOP_COMP_32(efscmpeq);
8096 1c97856d aurel32
GEN_SPEFPUOP_COMP_32(efststgt);
8097 1c97856d aurel32
GEN_SPEFPUOP_COMP_32(efststlt);
8098 1c97856d aurel32
GEN_SPEFPUOP_COMP_32(efststeq);
8099 0487d6a8 j_mayer
8100 0487d6a8 j_mayer
/* Opcodes definitions */
8101 40569b7e aurel32
GEN_SPE(efsadd,         efssub,        0x00, 0x0B, 0x00000000, PPC_SPE_SINGLE); //
8102 40569b7e aurel32
GEN_SPE(efsabs,         efsnabs,       0x02, 0x0B, 0x0000F800, PPC_SPE_SINGLE); //
8103 40569b7e aurel32
GEN_SPE(efsneg,         speundef,      0x03, 0x0B, 0x0000F800, PPC_SPE_SINGLE); //
8104 40569b7e aurel32
GEN_SPE(efsmul,         efsdiv,        0x04, 0x0B, 0x00000000, PPC_SPE_SINGLE); //
8105 40569b7e aurel32
GEN_SPE(efscmpgt,       efscmplt,      0x06, 0x0B, 0x00600000, PPC_SPE_SINGLE); //
8106 40569b7e aurel32
GEN_SPE(efscmpeq,       efscfd,        0x07, 0x0B, 0x00600000, PPC_SPE_SINGLE); //
8107 40569b7e aurel32
GEN_SPE(efscfui,        efscfsi,       0x08, 0x0B, 0x00180000, PPC_SPE_SINGLE); //
8108 40569b7e aurel32
GEN_SPE(efscfuf,        efscfsf,       0x09, 0x0B, 0x00180000, PPC_SPE_SINGLE); //
8109 40569b7e aurel32
GEN_SPE(efsctui,        efsctsi,       0x0A, 0x0B, 0x00180000, PPC_SPE_SINGLE); //
8110 40569b7e aurel32
GEN_SPE(efsctuf,        efsctsf,       0x0B, 0x0B, 0x00180000, PPC_SPE_SINGLE); //
8111 40569b7e aurel32
GEN_SPE(efsctuiz,       speundef,      0x0C, 0x0B, 0x00180000, PPC_SPE_SINGLE); //
8112 40569b7e aurel32
GEN_SPE(efsctsiz,       speundef,      0x0D, 0x0B, 0x00180000, PPC_SPE_SINGLE); //
8113 40569b7e aurel32
GEN_SPE(efststgt,       efststlt,      0x0E, 0x0B, 0x00600000, PPC_SPE_SINGLE); //
8114 40569b7e aurel32
GEN_SPE(efststeq,       speundef,      0x0F, 0x0B, 0x00600000, PPC_SPE_SINGLE); //
8115 0487d6a8 j_mayer
8116 0487d6a8 j_mayer
/* Double precision floating-point operations */
8117 0487d6a8 j_mayer
/* Arithmetic */
8118 1c97856d aurel32
GEN_SPEFPUOP_ARITH2_64_64(efdadd);
8119 1c97856d aurel32
GEN_SPEFPUOP_ARITH2_64_64(efdsub);
8120 1c97856d aurel32
GEN_SPEFPUOP_ARITH2_64_64(efdmul);
8121 1c97856d aurel32
GEN_SPEFPUOP_ARITH2_64_64(efddiv);
8122 636aa200 Blue Swirl
static inline void gen_efdabs(DisasContext *ctx)
8123 1c97856d aurel32
{
8124 1c97856d aurel32
    if (unlikely(!ctx->spe_enabled)) {
8125 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);
8126 1c97856d aurel32
        return;
8127 1c97856d aurel32
    }
8128 1c97856d aurel32
#if defined(TARGET_PPC64)
8129 6d5c34fa Mike Pall
    tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000000000000LL);
8130 1c97856d aurel32
#else
8131 6d5c34fa Mike Pall
    tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8132 6d5c34fa Mike Pall
    tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000);
8133 1c97856d aurel32
#endif
8134 1c97856d aurel32
}
8135 636aa200 Blue Swirl
static inline void gen_efdnabs(DisasContext *ctx)
8136 1c97856d aurel32
{
8137 1c97856d aurel32
    if (unlikely(!ctx->spe_enabled)) {
8138 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);
8139 1c97856d aurel32
        return;
8140 1c97856d aurel32
    }
8141 1c97856d aurel32
#if defined(TARGET_PPC64)
8142 6d5c34fa Mike Pall
    tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
8143 1c97856d aurel32
#else
8144 6d5c34fa Mike Pall
    tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8145 6d5c34fa Mike Pall
    tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
8146 1c97856d aurel32
#endif
8147 1c97856d aurel32
}
8148 636aa200 Blue Swirl
static inline void gen_efdneg(DisasContext *ctx)
8149 1c97856d aurel32
{
8150 1c97856d aurel32
    if (unlikely(!ctx->spe_enabled)) {
8151 e06fcd75 aurel32
        gen_exception(ctx, POWERPC_EXCP_APU);
8152 1c97856d aurel32
        return;
8153 1c97856d aurel32
    }
8154 1c97856d aurel32
#if defined(TARGET_PPC64)
8155 6d5c34fa Mike Pall
    tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL);
8156 1c97856d aurel32
#else
8157 6d5c34fa Mike Pall
    tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
8158 6d5c34fa Mike Pall
    tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000);
8159 1c97856d aurel32
#endif
8160 1c97856d aurel32
}
8161 1c97856d aurel32
8162 0487d6a8 j_mayer
/* Conversion */
8163 1c97856d aurel32
GEN_SPEFPUOP_CONV_64_32(efdcfui);
8164 1c97856d aurel32
GEN_SPEFPUOP_CONV_64_32(efdcfsi);
8165 1c97856d aurel32
GEN_SPEFPUOP_CONV_64_32(efdcfuf);
8166 1c97856d aurel32
GEN_SPEFPUOP_CONV_64_32(efdcfsf);
8167 1c97856d aurel32
GEN_SPEFPUOP_CONV_32_64(efdctui);
8168 1c97856d aurel32
GEN_SPEFPUOP_CONV_32_64(efdctsi);
8169 1c97856d aurel32
GEN_SPEFPUOP_CONV_32_64(efdctuf);
8170 1c97856d aurel32
GEN_SPEFPUOP_CONV_32_64(efdctsf);
8171 1c97856d aurel32
GEN_SPEFPUOP_CONV_32_64(efdctuiz);
8172 1c97856d aurel32
GEN_SPEFPUOP_CONV_32_64(efdctsiz);
8173 1c97856d aurel32
GEN_SPEFPUOP_CONV_64_32(efdcfs);
8174 1c97856d aurel32
GEN_SPEFPUOP_CONV_64_64(efdcfuid);
8175 1c97856d aurel32
GEN_SPEFPUOP_CONV_64_64(efdcfsid);
8176 1c97856d aurel32
GEN_SPEFPUOP_CONV_64_64(efdctuidz);
8177 1c97856d aurel32
GEN_SPEFPUOP_CONV_64_64(efdctsidz);
8178 0487d6a8 j_mayer
8179 0487d6a8 j_mayer
/* Comparison */
8180 1c97856d aurel32
GEN_SPEFPUOP_COMP_64(efdcmpgt);
8181 1c97856d aurel32
GEN_SPEFPUOP_COMP_64(efdcmplt);
8182 1c97856d aurel32
GEN_SPEFPUOP_COMP_64(efdcmpeq);
8183 1c97856d aurel32
GEN_SPEFPUOP_COMP_64(efdtstgt);
8184 1c97856d aurel32
GEN_SPEFPUOP_COMP_64(efdtstlt);
8185 1c97856d aurel32
GEN_SPEFPUOP_COMP_64(efdtsteq);
8186 0487d6a8 j_mayer
8187 0487d6a8 j_mayer
/* Opcodes definitions */
8188 40569b7e aurel32
GEN_SPE(efdadd,         efdsub,        0x10, 0x0B, 0x00000000, PPC_SPE_DOUBLE); //
8189 40569b7e aurel32
GEN_SPE(efdcfuid,       efdcfsid,      0x11, 0x0B, 0x00180000, PPC_SPE_DOUBLE); //
8190 40569b7e aurel32
GEN_SPE(efdabs,         efdnabs,       0x12, 0x0B, 0x0000F800, PPC_SPE_DOUBLE); //
8191 40569b7e aurel32
GEN_SPE(efdneg,         speundef,      0x13, 0x0B, 0x0000F800, PPC_SPE_DOUBLE); //
8192 40569b7e aurel32
GEN_SPE(efdmul,         efddiv,        0x14, 0x0B, 0x00000000, PPC_SPE_DOUBLE); //
8193 40569b7e aurel32
GEN_SPE(efdctuidz,      efdctsidz,     0x15, 0x0B, 0x00180000, PPC_SPE_DOUBLE); //
8194 40569b7e aurel32
GEN_SPE(efdcmpgt,       efdcmplt,      0x16, 0x0B, 0x00600000, PPC_SPE_DOUBLE); //
8195 40569b7e aurel32
GEN_SPE(efdcmpeq,       efdcfs,        0x17, 0x0B, 0x00600000, PPC_SPE_DOUBLE); //
8196 40569b7e aurel32
GEN_SPE(efdcfui,        efdcfsi,       0x18, 0x0B, 0x00180000, PPC_SPE_DOUBLE); //
8197 40569b7e aurel32
GEN_SPE(efdcfuf,        efdcfsf,       0x19, 0x0B, 0x00180000, PPC_SPE_DOUBLE); //
8198 40569b7e aurel32
GEN_SPE(efdctui,        efdctsi,       0x1A, 0x0B, 0x00180000, PPC_SPE_DOUBLE); //
8199 40569b7e aurel32
GEN_SPE(efdctuf,        efdctsf,       0x1B, 0x0B, 0x00180000, PPC_SPE_DOUBLE); //
8200 40569b7e aurel32
GEN_SPE(efdctuiz,       speundef,      0x1C, 0x0B, 0x00180000, PPC_SPE_DOUBLE); //
8201 40569b7e aurel32
GEN_SPE(efdctsiz,       speundef,      0x1D, 0x0B, 0x00180000, PPC_SPE_DOUBLE); //
8202 40569b7e aurel32
GEN_SPE(efdtstgt,       efdtstlt,      0x1E, 0x0B, 0x00600000, PPC_SPE_DOUBLE); //
8203 40569b7e aurel32
GEN_SPE(efdtsteq,       speundef,      0x1F, 0x0B, 0x00600000, PPC_SPE_DOUBLE); //
8204 0487d6a8 j_mayer
8205 c227f099 Anthony Liguori
static opcode_t opcodes[] = {
8206 5c55ff99 Blue Swirl
GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE),
8207 5c55ff99 Blue Swirl
GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER),
8208 5c55ff99 Blue Swirl
GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
8209 5c55ff99 Blue Swirl
GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER),
8210 5c55ff99 Blue Swirl
GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER),
8211 5c55ff99 Blue Swirl
GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL),
8212 5c55ff99 Blue Swirl
GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8213 5c55ff99 Blue Swirl
GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8214 5c55ff99 Blue Swirl
GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8215 5c55ff99 Blue Swirl
GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8216 5c55ff99 Blue Swirl
GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER),
8217 5c55ff99 Blue Swirl
GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER),
8218 5c55ff99 Blue Swirl
GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER),
8219 5c55ff99 Blue Swirl
GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER),
8220 5c55ff99 Blue Swirl
GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8221 5c55ff99 Blue Swirl
#if defined(TARGET_PPC64)
8222 5c55ff99 Blue Swirl
GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B),
8223 5c55ff99 Blue Swirl
#endif
8224 5c55ff99 Blue Swirl
GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER),
8225 5c55ff99 Blue Swirl
GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER),
8226 5c55ff99 Blue Swirl
GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8227 5c55ff99 Blue Swirl
GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8228 5c55ff99 Blue Swirl
GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8229 5c55ff99 Blue Swirl
GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER),
8230 5c55ff99 Blue Swirl
GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER),
8231 5c55ff99 Blue Swirl
GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER),
8232 5c55ff99 Blue Swirl
GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8233 5c55ff99 Blue Swirl
GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8234 5c55ff99 Blue Swirl
GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8235 5c55ff99 Blue Swirl
GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8236 5c55ff99 Blue Swirl
GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB),
8237 eaabeef2 David Gibson
GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD),
8238 5c55ff99 Blue Swirl
#if defined(TARGET_PPC64)
8239 eaabeef2 David Gibson
GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD),
8240 5c55ff99 Blue Swirl
GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B),
8241 5c55ff99 Blue Swirl
#endif
8242 5c55ff99 Blue Swirl
GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8243 5c55ff99 Blue Swirl
GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8244 5c55ff99 Blue Swirl
GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8245 5c55ff99 Blue Swirl
GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER),
8246 5c55ff99 Blue Swirl
GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER),
8247 5c55ff99 Blue Swirl
GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER),
8248 5c55ff99 Blue Swirl
GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER),
8249 5c55ff99 Blue Swirl
#if defined(TARGET_PPC64)
8250 5c55ff99 Blue Swirl
GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B),
8251 5c55ff99 Blue Swirl
GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B),
8252 5c55ff99 Blue Swirl
GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B),
8253 5c55ff99 Blue Swirl
GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B),
8254 5c55ff99 Blue Swirl
GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B),
8255 5c55ff99 Blue Swirl
#endif
8256 5c55ff99 Blue Swirl
GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES),
8257 5c55ff99 Blue Swirl
GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
8258 5c55ff99 Blue Swirl
GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT),
8259 5c55ff99 Blue Swirl
GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT),
8260 5c55ff99 Blue Swirl
GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT),
8261 5c55ff99 Blue Swirl
GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT),
8262 5c55ff99 Blue Swirl
GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT),
8263 5c55ff99 Blue Swirl
GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT),
8264 5c55ff99 Blue Swirl
GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT),
8265 5c55ff99 Blue Swirl
GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT),
8266 5c55ff99 Blue Swirl
GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00010000, PPC_FLOAT),
8267 5c55ff99 Blue Swirl
GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT),
8268 5c55ff99 Blue Swirl
#if defined(TARGET_PPC64)
8269 5c55ff99 Blue Swirl
GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B),
8270 5c55ff99 Blue Swirl
GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX),
8271 5c55ff99 Blue Swirl
GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B),
8272 5c55ff99 Blue Swirl
#endif
8273 5c55ff99 Blue Swirl
GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8274 5c55ff99 Blue Swirl
GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER),
8275 5c55ff99 Blue Swirl
GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING),
8276 5c55ff99 Blue Swirl
GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING),
8277 5c55ff99 Blue Swirl
GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING),
8278 5c55ff99 Blue Swirl
GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING),
8279 5c55ff99 Blue Swirl
GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO),
8280 5c55ff99 Blue Swirl
GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM),
8281 f844c817 Alexander Graf
GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES),
8282 5c55ff99 Blue Swirl
GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES),
8283 5c55ff99 Blue Swirl
#if defined(TARGET_PPC64)
8284 f844c817 Alexander Graf
GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B),
8285 5c55ff99 Blue Swirl
GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B),
8286 5c55ff99 Blue Swirl
#endif
8287 5c55ff99 Blue Swirl
GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC),
8288 5c55ff99 Blue Swirl
GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT),
8289 5c55ff99 Blue Swirl
GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
8290 5c55ff99 Blue Swirl
GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
8291 5c55ff99 Blue Swirl
GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW),
8292 5c55ff99 Blue Swirl
GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW),
8293 5c55ff99 Blue Swirl
GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER),
8294 5c55ff99 Blue Swirl
GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW),
8295 5c55ff99 Blue Swirl
#if defined(TARGET_PPC64)
8296 5c55ff99 Blue Swirl
GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B),
8297 5c55ff99 Blue Swirl
GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H),
8298 5c55ff99 Blue Swirl
#endif
8299 5c55ff99 Blue Swirl
GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW),
8300 5c55ff99 Blue Swirl
GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW),
8301 5c55ff99 Blue Swirl
GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
8302 5c55ff99 Blue Swirl
#if defined(TARGET_PPC64)
8303 5c55ff99 Blue Swirl
GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B),
8304 5c55ff99 Blue Swirl
GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B),
8305 5c55ff99 Blue Swirl
#endif
8306 5c55ff99 Blue Swirl
GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC),
8307 5c55ff99 Blue Swirl
GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC),
8308 5c55ff99 Blue Swirl
GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC),
8309 5c55ff99 Blue Swirl
GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC),
8310 5c55ff99 Blue Swirl
GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB),
8311 5c55ff99 Blue Swirl
GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC),
8312 5c55ff99 Blue Swirl
#if defined(TARGET_PPC64)
8313 5c55ff99 Blue Swirl
GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B),
8314 5c55ff99 Blue Swirl
#endif
8315 5c55ff99 Blue Swirl
GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC),
8316 5c55ff99 Blue Swirl
GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC),
8317 5c55ff99 Blue Swirl
GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE),
8318 5c55ff99 Blue Swirl
GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE),
8319 5c55ff99 Blue Swirl
GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE),
8320 5c55ff99 Blue Swirl
GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE),
8321 5c55ff99 Blue Swirl
GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE),
8322 5c55ff99 Blue Swirl
GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE_DCBZ),
8323 5c55ff99 Blue Swirl
GEN_HANDLER2(dcbz_970, "dcbz", 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZT),
8324 5c55ff99 Blue Swirl
GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC),
8325 5c55ff99 Blue Swirl
GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC),
8326 5c55ff99 Blue Swirl
GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC),
8327 5c55ff99 Blue Swirl
GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI),
8328 5c55ff99 Blue Swirl
GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA),
8329 5c55ff99 Blue Swirl
GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT),
8330 5c55ff99 Blue Swirl
GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT),
8331 5c55ff99 Blue Swirl
GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT),
8332 5c55ff99 Blue Swirl
GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT),
8333 5c55ff99 Blue Swirl
#if defined(TARGET_PPC64)
8334 5c55ff99 Blue Swirl
GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B),
8335 5c55ff99 Blue Swirl
GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
8336 5c55ff99 Blue Swirl
             PPC_SEGMENT_64B),
8337 5c55ff99 Blue Swirl
GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B),
8338 5c55ff99 Blue Swirl
GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
8339 5c55ff99 Blue Swirl
             PPC_SEGMENT_64B),
8340 efdef95f David Gibson
GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B),
8341 efdef95f David Gibson
GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B),
8342 efdef95f David Gibson
GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B),
8343 5c55ff99 Blue Swirl
#endif
8344 5c55ff99 Blue Swirl
GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA),
8345 5c55ff99 Blue Swirl
GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE),
8346 5c55ff99 Blue Swirl
GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE),
8347 5c55ff99 Blue Swirl
GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC),
8348 5c55ff99 Blue Swirl
#if defined(TARGET_PPC64)
8349 5c55ff99 Blue Swirl
GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI),
8350 5c55ff99 Blue Swirl
GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI),
8351 5c55ff99 Blue Swirl
#endif
8352 5c55ff99 Blue Swirl
GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN),
8353 5c55ff99 Blue Swirl
GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN),
8354 5c55ff99 Blue Swirl
GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR),
8355 5c55ff99 Blue Swirl
GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR),
8356 5c55ff99 Blue Swirl
GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR),
8357 5c55ff99 Blue Swirl
GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR),
8358 5c55ff99 Blue Swirl
GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR),
8359 5c55ff99 Blue Swirl
GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR),
8360 5c55ff99 Blue Swirl
GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR),
8361 5c55ff99 Blue Swirl
GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR),
8362 5c55ff99 Blue Swirl
GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR),
8363 5c55ff99 Blue Swirl
GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
8364 5c55ff99 Blue Swirl
GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR),
8365 5c55ff99 Blue Swirl
GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR),
8366 5c55ff99 Blue Swirl
GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR),
8367 5c55ff99 Blue Swirl
GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR),
8368 5c55ff99 Blue Swirl
GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR),
8369 5c55ff99 Blue Swirl
GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR),
8370 5c55ff99 Blue Swirl
GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR),
8371 5c55ff99 Blue Swirl
GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR),
8372 5c55ff99 Blue Swirl
GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR),
8373 5c55ff99 Blue Swirl
GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR),
8374 5c55ff99 Blue Swirl
GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR),
8375 5c55ff99 Blue Swirl
GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR),
8376 5c55ff99 Blue Swirl
GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR),
8377 5c55ff99 Blue Swirl
GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR),
8378 5c55ff99 Blue Swirl
GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR),
8379 5c55ff99 Blue Swirl
GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR),
8380 5c55ff99 Blue Swirl
GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR),
8381 5c55ff99 Blue Swirl
GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR),
8382 5c55ff99 Blue Swirl
GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR),
8383 5c55ff99 Blue Swirl
GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR),
8384 5c55ff99 Blue Swirl
GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR),
8385 5c55ff99 Blue Swirl
GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR),
8386 5c55ff99 Blue Swirl
GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR),
8387 5c55ff99 Blue Swirl
GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR),
8388 5c55ff99 Blue Swirl
GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC),
8389 5c55ff99 Blue Swirl
GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC),
8390 5c55ff99 Blue Swirl
GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC),
8391 5c55ff99 Blue Swirl
GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB),
8392 5c55ff99 Blue Swirl
GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB),
8393 5c55ff99 Blue Swirl
GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB),
8394 5c55ff99 Blue Swirl
GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB),
8395 5c55ff99 Blue Swirl
GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER),
8396 5c55ff99 Blue Swirl
GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER),
8397 5c55ff99 Blue Swirl
GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER),
8398 5c55ff99 Blue Swirl
GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER),
8399 5c55ff99 Blue Swirl
GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER),
8400 5c55ff99 Blue Swirl
GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER),
8401 5c55ff99 Blue Swirl
GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
8402 5c55ff99 Blue Swirl
GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
8403 5c55ff99 Blue Swirl
GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2),
8404 5c55ff99 Blue Swirl
GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2),
8405 5c55ff99 Blue Swirl
GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
8406 5c55ff99 Blue Swirl
GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2),
8407 5c55ff99 Blue Swirl
GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2),
8408 5c55ff99 Blue Swirl
GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2),
8409 5c55ff99 Blue Swirl
GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI),
8410 5c55ff99 Blue Swirl
GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA),
8411 5c55ff99 Blue Swirl
GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR),
8412 5c55ff99 Blue Swirl
GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR),
8413 5c55ff99 Blue Swirl
GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX),
8414 5c55ff99 Blue Swirl
GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX),
8415 5c55ff99 Blue Swirl
GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX),
8416 5c55ff99 Blue Swirl
GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX),
8417 5c55ff99 Blue Swirl
GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON),
8418 5c55ff99 Blue Swirl
GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON),
8419 5c55ff99 Blue Swirl
GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT),
8420 5c55ff99 Blue Swirl
GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON),
8421 5c55ff99 Blue Swirl
GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON),
8422 5c55ff99 Blue Swirl
GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP),
8423 5c55ff99 Blue Swirl
GEN_HANDLER(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE),
8424 5c55ff99 Blue Swirl
GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI),
8425 5c55ff99 Blue Swirl
GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI),
8426 5c55ff99 Blue Swirl
GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB),
8427 5c55ff99 Blue Swirl
GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB),
8428 5c55ff99 Blue Swirl
GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB),
8429 5c55ff99 Blue Swirl
GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE),
8430 5c55ff99 Blue Swirl
GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE),
8431 5c55ff99 Blue Swirl
GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE),
8432 5c55ff99 Blue Swirl
GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE),
8433 fbe73008 Baojun Wang
GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE),
8434 5c55ff99 Blue Swirl
GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC),
8435 5c55ff99 Blue Swirl
GEN_HANDLER(mbar, 0x1F, 0x16, 0x1a, 0x001FF801, PPC_BOOKE),
8436 5c55ff99 Blue Swirl
GEN_HANDLER(msync, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE),
8437 5c55ff99 Blue Swirl
GEN_HANDLER2(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001, PPC_BOOKE),
8438 5c55ff99 Blue Swirl
GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC),
8439 5c55ff99 Blue Swirl
GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC),
8440 5c55ff99 Blue Swirl
GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC),
8441 5c55ff99 Blue Swirl
GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC),
8442 5c55ff99 Blue Swirl
GEN_HANDLER(vsldoi, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC),
8443 5c55ff99 Blue Swirl
GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC),
8444 5c55ff99 Blue Swirl
GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE),
8445 5c55ff99 Blue Swirl
GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE),
8446 5c55ff99 Blue Swirl
GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE),
8447 5c55ff99 Blue Swirl
GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE),
8448 5c55ff99 Blue Swirl
8449 5c55ff99 Blue Swirl
#undef GEN_INT_ARITH_ADD
8450 5c55ff99 Blue Swirl
#undef GEN_INT_ARITH_ADD_CONST
8451 5c55ff99 Blue Swirl
#define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov)         \
8452 5c55ff99 Blue Swirl
GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
8453 5c55ff99 Blue Swirl
#define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val,                        \
8454 5c55ff99 Blue Swirl
                                add_ca, compute_ca, compute_ov)               \
8455 5c55ff99 Blue Swirl
GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
8456 5c55ff99 Blue Swirl
GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
8457 5c55ff99 Blue Swirl
GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
8458 5c55ff99 Blue Swirl
GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
8459 5c55ff99 Blue Swirl
GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
8460 5c55ff99 Blue Swirl
GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
8461 5c55ff99 Blue Swirl
GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
8462 5c55ff99 Blue Swirl
GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
8463 5c55ff99 Blue Swirl
GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
8464 5c55ff99 Blue Swirl
GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
8465 5c55ff99 Blue Swirl
GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
8466 5c55ff99 Blue Swirl
8467 5c55ff99 Blue Swirl
#undef GEN_INT_ARITH_DIVW
8468 5c55ff99 Blue Swirl
#define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov)                      \
8469 5c55ff99 Blue Swirl
GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
8470 5c55ff99 Blue Swirl
GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0),
8471 5c55ff99 Blue Swirl
GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1),
8472 5c55ff99 Blue Swirl
GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0),
8473 5c55ff99 Blue Swirl
GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1),
8474 5c55ff99 Blue Swirl
8475 5c55ff99 Blue Swirl
#if defined(TARGET_PPC64)
8476 5c55ff99 Blue Swirl
#undef GEN_INT_ARITH_DIVD
8477 5c55ff99 Blue Swirl
#define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov)                      \
8478 5c55ff99 Blue Swirl
GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8479 5c55ff99 Blue Swirl
GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0),
8480 5c55ff99 Blue Swirl
GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1),
8481 5c55ff99 Blue Swirl
GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0),
8482 5c55ff99 Blue Swirl
GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1),
8483 5c55ff99 Blue Swirl
8484 5c55ff99 Blue Swirl
#undef GEN_INT_ARITH_MUL_HELPER
8485 5c55ff99 Blue Swirl
#define GEN_INT_ARITH_MUL_HELPER(name, opc3)                                  \
8486 5c55ff99 Blue Swirl
GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8487 5c55ff99 Blue Swirl
GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00),
8488 5c55ff99 Blue Swirl
GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02),
8489 5c55ff99 Blue Swirl
GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17),
8490 5c55ff99 Blue Swirl
#endif
8491 5c55ff99 Blue Swirl
8492 5c55ff99 Blue Swirl
#undef GEN_INT_ARITH_SUBF
8493 5c55ff99 Blue Swirl
#undef GEN_INT_ARITH_SUBF_CONST
8494 5c55ff99 Blue Swirl
#define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov)        \
8495 5c55ff99 Blue Swirl
GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
8496 5c55ff99 Blue Swirl
#define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val,                       \
8497 5c55ff99 Blue Swirl
                                add_ca, compute_ca, compute_ov)               \
8498 5c55ff99 Blue Swirl
GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
8499 5c55ff99 Blue Swirl
GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
8500 5c55ff99 Blue Swirl
GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
8501 5c55ff99 Blue Swirl
GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
8502 5c55ff99 Blue Swirl
GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
8503 5c55ff99 Blue Swirl
GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
8504 5c55ff99 Blue Swirl
GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
8505 5c55ff99 Blue Swirl
GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
8506 5c55ff99 Blue Swirl
GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
8507 5c55ff99 Blue Swirl
GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
8508 5c55ff99 Blue Swirl
GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
8509 5c55ff99 Blue Swirl
8510 5c55ff99 Blue Swirl
#undef GEN_LOGICAL1
8511 5c55ff99 Blue Swirl
#undef GEN_LOGICAL2
8512 5c55ff99 Blue Swirl
#define GEN_LOGICAL2(name, tcg_op, opc, type)                                 \
8513 5c55ff99 Blue Swirl
GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
8514 5c55ff99 Blue Swirl
#define GEN_LOGICAL1(name, tcg_op, opc, type)                                 \
8515 5c55ff99 Blue Swirl
GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
8516 5c55ff99 Blue Swirl
GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER),
8517 5c55ff99 Blue Swirl
GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER),
8518 5c55ff99 Blue Swirl
GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER),
8519 5c55ff99 Blue Swirl
GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER),
8520 5c55ff99 Blue Swirl
GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER),
8521 5c55ff99 Blue Swirl
GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER),
8522 5c55ff99 Blue Swirl
GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER),
8523 5c55ff99 Blue Swirl
GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER),
8524 5c55ff99 Blue Swirl
#if defined(TARGET_PPC64)
8525 5c55ff99 Blue Swirl
GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B),
8526 5c55ff99 Blue Swirl
#endif
8527 5c55ff99 Blue Swirl
8528 5c55ff99 Blue Swirl
#if defined(TARGET_PPC64)
8529 5c55ff99 Blue Swirl
#undef GEN_PPC64_R2
8530 5c55ff99 Blue Swirl
#undef GEN_PPC64_R4
8531 5c55ff99 Blue Swirl
#define GEN_PPC64_R2(name, opc1, opc2)                                        \
8532 5c55ff99 Blue Swirl
GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8533 5c55ff99 Blue Swirl
GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000,   \
8534 5c55ff99 Blue Swirl
             PPC_64B)
8535 5c55ff99 Blue Swirl
#define GEN_PPC64_R4(name, opc1, opc2)                                        \
8536 5c55ff99 Blue Swirl
GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8537 5c55ff99 Blue Swirl
GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000,   \
8538 5c55ff99 Blue Swirl
             PPC_64B),                                                        \
8539 5c55ff99 Blue Swirl
GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000,   \
8540 5c55ff99 Blue Swirl
             PPC_64B),                                                        \
8541 5c55ff99 Blue Swirl
GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000,   \
8542 5c55ff99 Blue Swirl
             PPC_64B)
8543 5c55ff99 Blue Swirl
GEN_PPC64_R4(rldicl, 0x1E, 0x00),
8544 5c55ff99 Blue Swirl
GEN_PPC64_R4(rldicr, 0x1E, 0x02),
8545 5c55ff99 Blue Swirl
GEN_PPC64_R4(rldic, 0x1E, 0x04),
8546 5c55ff99 Blue Swirl
GEN_PPC64_R2(rldcl, 0x1E, 0x08),
8547 5c55ff99 Blue Swirl
GEN_PPC64_R2(rldcr, 0x1E, 0x09),
8548 5c55ff99 Blue Swirl
GEN_PPC64_R4(rldimi, 0x1E, 0x06),
8549 5c55ff99 Blue Swirl
#endif
8550 5c55ff99 Blue Swirl
8551 5c55ff99 Blue Swirl
#undef _GEN_FLOAT_ACB
8552 5c55ff99 Blue Swirl
#undef GEN_FLOAT_ACB
8553 5c55ff99 Blue Swirl
#undef _GEN_FLOAT_AB
8554 5c55ff99 Blue Swirl
#undef GEN_FLOAT_AB
8555 5c55ff99 Blue Swirl
#undef _GEN_FLOAT_AC
8556 5c55ff99 Blue Swirl
#undef GEN_FLOAT_AC
8557 5c55ff99 Blue Swirl
#undef GEN_FLOAT_B
8558 5c55ff99 Blue Swirl
#undef GEN_FLOAT_BS
8559 5c55ff99 Blue Swirl
#define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type)           \
8560 5c55ff99 Blue Swirl
GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
8561 5c55ff99 Blue Swirl
#define GEN_FLOAT_ACB(name, op2, set_fprf, type)                              \
8562 5c55ff99 Blue Swirl
_GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type),                     \
8563 5c55ff99 Blue Swirl
_GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
8564 5c55ff99 Blue Swirl
#define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type)     \
8565 5c55ff99 Blue Swirl
GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
8566 5c55ff99 Blue Swirl
#define GEN_FLOAT_AB(name, op2, inval, set_fprf, type)                        \
8567 5c55ff99 Blue Swirl
_GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type),               \
8568 5c55ff99 Blue Swirl
_GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
8569 5c55ff99 Blue Swirl
#define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type)     \
8570 5c55ff99 Blue Swirl
GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
8571 5c55ff99 Blue Swirl
#define GEN_FLOAT_AC(name, op2, inval, set_fprf, type)                        \
8572 5c55ff99 Blue Swirl
_GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type),               \
8573 5c55ff99 Blue Swirl
_GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
8574 5c55ff99 Blue Swirl
#define GEN_FLOAT_B(name, op2, op3, set_fprf, type)                           \
8575 5c55ff99 Blue Swirl
GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
8576 5c55ff99 Blue Swirl
#define GEN_FLOAT_BS(name, op1, op2, set_fprf, type)                          \
8577 5c55ff99 Blue Swirl
GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
8578 5c55ff99 Blue Swirl
8579 5c55ff99 Blue Swirl
GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT),
8580 5c55ff99 Blue Swirl
GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT),
8581 5c55ff99 Blue Swirl
GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT),
8582 5c55ff99 Blue Swirl
GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT),
8583 5c55ff99 Blue Swirl
GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES),
8584 5c55ff99 Blue Swirl
GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE),
8585 5c55ff99 Blue Swirl
_GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL),
8586 5c55ff99 Blue Swirl
GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT),
8587 5c55ff99 Blue Swirl
GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT),
8588 5c55ff99 Blue Swirl
GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT),
8589 5c55ff99 Blue Swirl
GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT),
8590 5c55ff99 Blue Swirl
GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT),
8591 5c55ff99 Blue Swirl
GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT),
8592 5c55ff99 Blue Swirl
GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT),
8593 5c55ff99 Blue Swirl
GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT),
8594 5c55ff99 Blue Swirl
#if defined(TARGET_PPC64)
8595 5c55ff99 Blue Swirl
GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B),
8596 5c55ff99 Blue Swirl
GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B),
8597 5c55ff99 Blue Swirl
GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B),
8598 5c55ff99 Blue Swirl
#endif
8599 5c55ff99 Blue Swirl
GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT),
8600 5c55ff99 Blue Swirl
GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT),
8601 5c55ff99 Blue Swirl
GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT),
8602 5c55ff99 Blue Swirl
GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT),
8603 5c55ff99 Blue Swirl
GEN_FLOAT_B(abs, 0x08, 0x08, 0, PPC_FLOAT),
8604 5c55ff99 Blue Swirl
GEN_FLOAT_B(nabs, 0x08, 0x04, 0, PPC_FLOAT),
8605 5c55ff99 Blue Swirl
GEN_FLOAT_B(neg, 0x08, 0x01, 0, PPC_FLOAT),
8606 5c55ff99 Blue Swirl
8607 5c55ff99 Blue Swirl
#undef GEN_LD
8608 5c55ff99 Blue Swirl
#undef GEN_LDU
8609 5c55ff99 Blue Swirl
#undef GEN_LDUX
8610 5c55ff99 Blue Swirl
#undef GEN_LDX
8611 5c55ff99 Blue Swirl
#undef GEN_LDS
8612 5c55ff99 Blue Swirl
#define GEN_LD(name, ldop, opc, type)                                         \
8613 5c55ff99 Blue Swirl
GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8614 5c55ff99 Blue Swirl
#define GEN_LDU(name, ldop, opc, type)                                        \
8615 5c55ff99 Blue Swirl
GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8616 5c55ff99 Blue Swirl
#define GEN_LDUX(name, ldop, opc2, opc3, type)                                \
8617 5c55ff99 Blue Swirl
GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
8618 5c55ff99 Blue Swirl
#define GEN_LDX(name, ldop, opc2, opc3, type)                                 \
8619 5c55ff99 Blue Swirl
GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
8620 5c55ff99 Blue Swirl
#define GEN_LDS(name, ldop, op, type)                                         \
8621 5c55ff99 Blue Swirl
GEN_LD(name, ldop, op | 0x20, type)                                           \
8622 5c55ff99 Blue Swirl
GEN_LDU(name, ldop, op | 0x21, type)                                          \
8623 5c55ff99 Blue Swirl
GEN_LDUX(name, ldop, 0x17, op | 0x01, type)                                   \
8624 5c55ff99 Blue Swirl
GEN_LDX(name, ldop, 0x17, op | 0x00, type)
8625 5c55ff99 Blue Swirl
8626 5c55ff99 Blue Swirl
GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER)
8627 5c55ff99 Blue Swirl
GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER)
8628 5c55ff99 Blue Swirl
GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER)
8629 5c55ff99 Blue Swirl
GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER)
8630 5c55ff99 Blue Swirl
#if defined(TARGET_PPC64)
8631 5c55ff99 Blue Swirl
GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B)
8632 5c55ff99 Blue Swirl
GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B)
8633 5c55ff99 Blue Swirl
GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B)
8634 5c55ff99 Blue Swirl
GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B)
8635 5c55ff99 Blue Swirl
#endif
8636 5c55ff99 Blue Swirl
GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER)
8637 5c55ff99 Blue Swirl
GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER)
8638 5c55ff99 Blue Swirl
8639 5c55ff99 Blue Swirl
#undef GEN_ST
8640 5c55ff99 Blue Swirl
#undef GEN_STU
8641 5c55ff99 Blue Swirl
#undef GEN_STUX
8642 5c55ff99 Blue Swirl
#undef GEN_STX
8643 5c55ff99 Blue Swirl
#undef GEN_STS
8644 5c55ff99 Blue Swirl
#define GEN_ST(name, stop, opc, type)                                         \
8645 5c55ff99 Blue Swirl
GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8646 5c55ff99 Blue Swirl
#define GEN_STU(name, stop, opc, type)                                        \
8647 5c55ff99 Blue Swirl
GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
8648 5c55ff99 Blue Swirl
#define GEN_STUX(name, stop, opc2, opc3, type)                                \
8649 5c55ff99 Blue Swirl
GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
8650 5c55ff99 Blue Swirl
#define GEN_STX(name, stop, opc2, opc3, type)                                 \
8651 5c55ff99 Blue Swirl
GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
8652 5c55ff99 Blue Swirl
#define GEN_STS(name, stop, op, type)                                         \
8653 5c55ff99 Blue Swirl
GEN_ST(name, stop, op | 0x20, type)                                           \
8654 5c55ff99 Blue Swirl
GEN_STU(name, stop, op | 0x21, type)                                          \
8655 5c55ff99 Blue Swirl
GEN_STUX(name, stop, 0x17, op | 0x01, type)                                   \
8656 5c55ff99 Blue Swirl
GEN_STX(name, stop, 0x17, op | 0x00, type)
8657 5c55ff99 Blue Swirl
8658 5c55ff99 Blue Swirl
GEN_STS(stb, st8, 0x06, PPC_INTEGER)
8659 5c55ff99 Blue Swirl
GEN_STS(sth, st16, 0x0C, PPC_INTEGER)
8660 5c55ff99 Blue Swirl
GEN_STS(stw, st32, 0x04, PPC_INTEGER)
8661 5c55ff99 Blue Swirl
#if defined(TARGET_PPC64)
8662 5c55ff99 Blue Swirl
GEN_STUX(std, st64, 0x15, 0x05, PPC_64B)
8663 5c55ff99 Blue Swirl
GEN_STX(std, st64, 0x15, 0x04, PPC_64B)
8664 5c55ff99 Blue Swirl
#endif
8665 5c55ff99 Blue Swirl
GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER)
8666 5c55ff99 Blue Swirl
GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER)
8667 5c55ff99 Blue Swirl
8668 5c55ff99 Blue Swirl
#undef GEN_LDF
8669 5c55ff99 Blue Swirl
#undef GEN_LDUF
8670 5c55ff99 Blue Swirl
#undef GEN_LDUXF
8671 5c55ff99 Blue Swirl
#undef GEN_LDXF
8672 5c55ff99 Blue Swirl
#undef GEN_LDFS
8673 5c55ff99 Blue Swirl
#define GEN_LDF(name, ldop, opc, type)                                        \
8674 5c55ff99 Blue Swirl
GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8675 5c55ff99 Blue Swirl
#define GEN_LDUF(name, ldop, opc, type)                                       \
8676 5c55ff99 Blue Swirl
GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8677 5c55ff99 Blue Swirl
#define GEN_LDUXF(name, ldop, opc, type)                                      \
8678 5c55ff99 Blue Swirl
GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
8679 5c55ff99 Blue Swirl
#define GEN_LDXF(name, ldop, opc2, opc3, type)                                \
8680 5c55ff99 Blue Swirl
GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
8681 5c55ff99 Blue Swirl
#define GEN_LDFS(name, ldop, op, type)                                        \
8682 5c55ff99 Blue Swirl
GEN_LDF(name, ldop, op | 0x20, type)                                          \
8683 5c55ff99 Blue Swirl
GEN_LDUF(name, ldop, op | 0x21, type)                                         \
8684 5c55ff99 Blue Swirl
GEN_LDUXF(name, ldop, op | 0x01, type)                                        \
8685 5c55ff99 Blue Swirl
GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
8686 5c55ff99 Blue Swirl
8687 5c55ff99 Blue Swirl
GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT)
8688 5c55ff99 Blue Swirl
GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT)
8689 5c55ff99 Blue Swirl
8690 5c55ff99 Blue Swirl
#undef GEN_STF
8691 5c55ff99 Blue Swirl
#undef GEN_STUF
8692 5c55ff99 Blue Swirl
#undef GEN_STUXF
8693 5c55ff99 Blue Swirl
#undef GEN_STXF
8694 5c55ff99 Blue Swirl
#undef GEN_STFS
8695 5c55ff99 Blue Swirl
#define GEN_STF(name, stop, opc, type)                                        \
8696 5c55ff99 Blue Swirl
GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8697 5c55ff99 Blue Swirl
#define GEN_STUF(name, stop, opc, type)                                       \
8698 5c55ff99 Blue Swirl
GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8699 5c55ff99 Blue Swirl
#define GEN_STUXF(name, stop, opc, type)                                      \
8700 5c55ff99 Blue Swirl
GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
8701 5c55ff99 Blue Swirl
#define GEN_STXF(name, stop, opc2, opc3, type)                                \
8702 5c55ff99 Blue Swirl
GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
8703 5c55ff99 Blue Swirl
#define GEN_STFS(name, stop, op, type)                                        \
8704 5c55ff99 Blue Swirl
GEN_STF(name, stop, op | 0x20, type)                                          \
8705 5c55ff99 Blue Swirl
GEN_STUF(name, stop, op | 0x21, type)                                         \
8706 5c55ff99 Blue Swirl
GEN_STUXF(name, stop, op | 0x01, type)                                        \
8707 5c55ff99 Blue Swirl
GEN_STXF(name, stop, 0x17, op | 0x00, type)
8708 5c55ff99 Blue Swirl
8709 5c55ff99 Blue Swirl
GEN_STFS(stfd, st64, 0x16, PPC_FLOAT)
8710 5c55ff99 Blue Swirl
GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT)
8711 5c55ff99 Blue Swirl
GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX)
8712 5c55ff99 Blue Swirl
8713 5c55ff99 Blue Swirl
#undef GEN_CRLOGIC
8714 5c55ff99 Blue Swirl
#define GEN_CRLOGIC(name, tcg_op, opc)                                        \
8715 5c55ff99 Blue Swirl
GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
8716 5c55ff99 Blue Swirl
GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08),
8717 5c55ff99 Blue Swirl
GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04),
8718 5c55ff99 Blue Swirl
GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09),
8719 5c55ff99 Blue Swirl
GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07),
8720 5c55ff99 Blue Swirl
GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01),
8721 5c55ff99 Blue Swirl
GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E),
8722 5c55ff99 Blue Swirl
GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D),
8723 5c55ff99 Blue Swirl
GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06),
8724 5c55ff99 Blue Swirl
8725 5c55ff99 Blue Swirl
#undef GEN_MAC_HANDLER
8726 5c55ff99 Blue Swirl
#define GEN_MAC_HANDLER(name, opc2, opc3)                                     \
8727 5c55ff99 Blue Swirl
GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
8728 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(macchw, 0x0C, 0x05),
8729 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(macchwo, 0x0C, 0x15),
8730 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(macchws, 0x0C, 0x07),
8731 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(macchwso, 0x0C, 0x17),
8732 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06),
8733 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16),
8734 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(macchwu, 0x0C, 0x04),
8735 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14),
8736 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(machhw, 0x0C, 0x01),
8737 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(machhwo, 0x0C, 0x11),
8738 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(machhws, 0x0C, 0x03),
8739 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(machhwso, 0x0C, 0x13),
8740 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02),
8741 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12),
8742 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(machhwu, 0x0C, 0x00),
8743 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10),
8744 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D),
8745 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D),
8746 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F),
8747 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F),
8748 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C),
8749 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C),
8750 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E),
8751 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E),
8752 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05),
8753 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15),
8754 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07),
8755 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17),
8756 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01),
8757 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11),
8758 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03),
8759 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13),
8760 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D),
8761 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D),
8762 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F),
8763 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F),
8764 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(mulchw, 0x08, 0x05),
8765 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(mulchwu, 0x08, 0x04),
8766 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(mulhhw, 0x08, 0x01),
8767 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00),
8768 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(mullhw, 0x08, 0x0D),
8769 5c55ff99 Blue Swirl
GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C),
8770 5c55ff99 Blue Swirl
8771 5c55ff99 Blue Swirl
#undef GEN_VR_LDX
8772 5c55ff99 Blue Swirl
#undef GEN_VR_STX
8773 5c55ff99 Blue Swirl
#undef GEN_VR_LVE
8774 5c55ff99 Blue Swirl
#undef GEN_VR_STVE
8775 5c55ff99 Blue Swirl
#define GEN_VR_LDX(name, opc2, opc3)                                          \
8776 5c55ff99 Blue Swirl
GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
8777 5c55ff99 Blue Swirl
#define GEN_VR_STX(name, opc2, opc3)                                          \
8778 5c55ff99 Blue Swirl
GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
8779 5c55ff99 Blue Swirl
#define GEN_VR_LVE(name, opc2, opc3)                                    \
8780 5c55ff99 Blue Swirl
    GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
8781 5c55ff99 Blue Swirl
#define GEN_VR_STVE(name, opc2, opc3)                                   \
8782 5c55ff99 Blue Swirl
    GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
8783 5c55ff99 Blue Swirl
GEN_VR_LDX(lvx, 0x07, 0x03),
8784 5c55ff99 Blue Swirl
GEN_VR_LDX(lvxl, 0x07, 0x0B),
8785 5c55ff99 Blue Swirl
GEN_VR_LVE(bx, 0x07, 0x00),
8786 5c55ff99 Blue Swirl
GEN_VR_LVE(hx, 0x07, 0x01),
8787 5c55ff99 Blue Swirl
GEN_VR_LVE(wx, 0x07, 0x02),
8788 5c55ff99 Blue Swirl
GEN_VR_STX(svx, 0x07, 0x07),
8789 5c55ff99 Blue Swirl
GEN_VR_STX(svxl, 0x07, 0x0F),
8790 5c55ff99 Blue Swirl
GEN_VR_STVE(bx, 0x07, 0x04),
8791 5c55ff99 Blue Swirl
GEN_VR_STVE(hx, 0x07, 0x05),
8792 5c55ff99 Blue Swirl
GEN_VR_STVE(wx, 0x07, 0x06),
8793 5c55ff99 Blue Swirl
8794 5c55ff99 Blue Swirl
#undef GEN_VX_LOGICAL
8795 5c55ff99 Blue Swirl
#define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3)                        \
8796 5c55ff99 Blue Swirl
GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
8797 5c55ff99 Blue Swirl
GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16),
8798 5c55ff99 Blue Swirl
GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17),
8799 5c55ff99 Blue Swirl
GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18),
8800 5c55ff99 Blue Swirl
GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19),
8801 5c55ff99 Blue Swirl
GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20),
8802 5c55ff99 Blue Swirl
8803 5c55ff99 Blue Swirl
#undef GEN_VXFORM
8804 5c55ff99 Blue Swirl
#define GEN_VXFORM(name, opc2, opc3)                                    \
8805 5c55ff99 Blue Swirl
GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
8806 5c55ff99 Blue Swirl
GEN_VXFORM(vaddubm, 0, 0),
8807 5c55ff99 Blue Swirl
GEN_VXFORM(vadduhm, 0, 1),
8808 5c55ff99 Blue Swirl
GEN_VXFORM(vadduwm, 0, 2),
8809 5c55ff99 Blue Swirl
GEN_VXFORM(vsububm, 0, 16),
8810 5c55ff99 Blue Swirl
GEN_VXFORM(vsubuhm, 0, 17),
8811 5c55ff99 Blue Swirl
GEN_VXFORM(vsubuwm, 0, 18),
8812 5c55ff99 Blue Swirl
GEN_VXFORM(vmaxub, 1, 0),
8813 5c55ff99 Blue Swirl
GEN_VXFORM(vmaxuh, 1, 1),
8814 5c55ff99 Blue Swirl
GEN_VXFORM(vmaxuw, 1, 2),
8815 5c55ff99 Blue Swirl
GEN_VXFORM(vmaxsb, 1, 4),
8816 5c55ff99 Blue Swirl
GEN_VXFORM(vmaxsh, 1, 5),
8817 5c55ff99 Blue Swirl
GEN_VXFORM(vmaxsw, 1, 6),
8818 5c55ff99 Blue Swirl
GEN_VXFORM(vminub, 1, 8),
8819 5c55ff99 Blue Swirl
GEN_VXFORM(vminuh, 1, 9),
8820 5c55ff99 Blue Swirl
GEN_VXFORM(vminuw, 1, 10),
8821 5c55ff99 Blue Swirl
GEN_VXFORM(vminsb, 1, 12),
8822 5c55ff99 Blue Swirl
GEN_VXFORM(vminsh, 1, 13),
8823 5c55ff99 Blue Swirl
GEN_VXFORM(vminsw, 1, 14),
8824 5c55ff99 Blue Swirl
GEN_VXFORM(vavgub, 1, 16),
8825 5c55ff99 Blue Swirl
GEN_VXFORM(vavguh, 1, 17),
8826 5c55ff99 Blue Swirl
GEN_VXFORM(vavguw, 1, 18),
8827 5c55ff99 Blue Swirl
GEN_VXFORM(vavgsb, 1, 20),
8828 5c55ff99 Blue Swirl
GEN_VXFORM(vavgsh, 1, 21),
8829 5c55ff99 Blue Swirl
GEN_VXFORM(vavgsw, 1, 22),
8830 5c55ff99 Blue Swirl
GEN_VXFORM(vmrghb, 6, 0),
8831 5c55ff99 Blue Swirl
GEN_VXFORM(vmrghh, 6, 1),
8832 5c55ff99 Blue Swirl
GEN_VXFORM(vmrghw, 6, 2),
8833 5c55ff99 Blue Swirl
GEN_VXFORM(vmrglb, 6, 4),
8834 5c55ff99 Blue Swirl
GEN_VXFORM(vmrglh, 6, 5),
8835 5c55ff99 Blue Swirl
GEN_VXFORM(vmrglw, 6, 6),
8836 5c55ff99 Blue Swirl
GEN_VXFORM(vmuloub, 4, 0),
8837 5c55ff99 Blue Swirl
GEN_VXFORM(vmulouh, 4, 1),
8838 5c55ff99 Blue Swirl
GEN_VXFORM(vmulosb, 4, 4),
8839 5c55ff99 Blue Swirl
GEN_VXFORM(vmulosh, 4, 5),
8840 5c55ff99 Blue Swirl
GEN_VXFORM(vmuleub, 4, 8),
8841 5c55ff99 Blue Swirl
GEN_VXFORM(vmuleuh, 4, 9),
8842 5c55ff99 Blue Swirl
GEN_VXFORM(vmulesb, 4, 12),
8843 5c55ff99 Blue Swirl
GEN_VXFORM(vmulesh, 4, 13),
8844 5c55ff99 Blue Swirl
GEN_VXFORM(vslb, 2, 4),
8845 5c55ff99 Blue Swirl
GEN_VXFORM(vslh, 2, 5),
8846 5c55ff99 Blue Swirl
GEN_VXFORM(vslw, 2, 6),
8847 5c55ff99 Blue Swirl
GEN_VXFORM(vsrb, 2, 8),
8848 5c55ff99 Blue Swirl
GEN_VXFORM(vsrh, 2, 9),
8849 5c55ff99 Blue Swirl
GEN_VXFORM(vsrw, 2, 10),
8850 5c55ff99 Blue Swirl
GEN_VXFORM(vsrab, 2, 12),
8851 5c55ff99 Blue Swirl
GEN_VXFORM(vsrah, 2, 13),
8852 5c55ff99 Blue Swirl
GEN_VXFORM(vsraw, 2, 14),
8853 5c55ff99 Blue Swirl
GEN_VXFORM(vslo, 6, 16),
8854 5c55ff99 Blue Swirl
GEN_VXFORM(vsro, 6, 17),
8855 5c55ff99 Blue Swirl
GEN_VXFORM(vaddcuw, 0, 6),
8856 5c55ff99 Blue Swirl
GEN_VXFORM(vsubcuw, 0, 22),
8857 5c55ff99 Blue Swirl
GEN_VXFORM(vaddubs, 0, 8),
8858 5c55ff99 Blue Swirl
GEN_VXFORM(vadduhs, 0, 9),
8859 5c55ff99 Blue Swirl
GEN_VXFORM(vadduws, 0, 10),
8860 5c55ff99 Blue Swirl
GEN_VXFORM(vaddsbs, 0, 12),
8861 5c55ff99 Blue Swirl
GEN_VXFORM(vaddshs, 0, 13),
8862 5c55ff99 Blue Swirl
GEN_VXFORM(vaddsws, 0, 14),
8863 5c55ff99 Blue Swirl
GEN_VXFORM(vsububs, 0, 24),
8864 5c55ff99 Blue Swirl
GEN_VXFORM(vsubuhs, 0, 25),
8865 5c55ff99 Blue Swirl
GEN_VXFORM(vsubuws, 0, 26),
8866 5c55ff99 Blue Swirl
GEN_VXFORM(vsubsbs, 0, 28),
8867 5c55ff99 Blue Swirl
GEN_VXFORM(vsubshs, 0, 29),
8868 5c55ff99 Blue Swirl
GEN_VXFORM(vsubsws, 0, 30),
8869 5c55ff99 Blue Swirl
GEN_VXFORM(vrlb, 2, 0),
8870 5c55ff99 Blue Swirl
GEN_VXFORM(vrlh, 2, 1),
8871 5c55ff99 Blue Swirl
GEN_VXFORM(vrlw, 2, 2),
8872 5c55ff99 Blue Swirl
GEN_VXFORM(vsl, 2, 7),
8873 5c55ff99 Blue Swirl
GEN_VXFORM(vsr, 2, 11),
8874 5c55ff99 Blue Swirl
GEN_VXFORM(vpkuhum, 7, 0),
8875 5c55ff99 Blue Swirl
GEN_VXFORM(vpkuwum, 7, 1),
8876 5c55ff99 Blue Swirl
GEN_VXFORM(vpkuhus, 7, 2),
8877 5c55ff99 Blue Swirl
GEN_VXFORM(vpkuwus, 7, 3),
8878 5c55ff99 Blue Swirl
GEN_VXFORM(vpkshus, 7, 4),
8879 5c55ff99 Blue Swirl
GEN_VXFORM(vpkswus, 7, 5),
8880 5c55ff99 Blue Swirl
GEN_VXFORM(vpkshss, 7, 6),
8881 5c55ff99 Blue Swirl
GEN_VXFORM(vpkswss, 7, 7),
8882 5c55ff99 Blue Swirl
GEN_VXFORM(vpkpx, 7, 12),
8883 5c55ff99 Blue Swirl
GEN_VXFORM(vsum4ubs, 4, 24),
8884 5c55ff99 Blue Swirl
GEN_VXFORM(vsum4sbs, 4, 28),
8885 5c55ff99 Blue Swirl
GEN_VXFORM(vsum4shs, 4, 25),
8886 5c55ff99 Blue Swirl
GEN_VXFORM(vsum2sws, 4, 26),
8887 5c55ff99 Blue Swirl
GEN_VXFORM(vsumsws, 4, 30),
8888 5c55ff99 Blue Swirl
GEN_VXFORM(vaddfp, 5, 0),
8889 5c55ff99 Blue Swirl
GEN_VXFORM(vsubfp, 5, 1),
8890 5c55ff99 Blue Swirl
GEN_VXFORM(vmaxfp, 5, 16),
8891 5c55ff99 Blue Swirl
GEN_VXFORM(vminfp, 5, 17),
8892 5c55ff99 Blue Swirl
8893 5c55ff99 Blue Swirl
#undef GEN_VXRFORM1
8894 5c55ff99 Blue Swirl
#undef GEN_VXRFORM
8895 5c55ff99 Blue Swirl
#define GEN_VXRFORM1(opname, name, str, opc2, opc3)                     \
8896 5c55ff99 Blue Swirl
    GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
8897 5c55ff99 Blue Swirl
#define GEN_VXRFORM(name, opc2, opc3)                                \
8898 5c55ff99 Blue Swirl
    GEN_VXRFORM1(name, name, #name, opc2, opc3)                      \
8899 5c55ff99 Blue Swirl
    GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
8900 5c55ff99 Blue Swirl
GEN_VXRFORM(vcmpequb, 3, 0)
8901 5c55ff99 Blue Swirl
GEN_VXRFORM(vcmpequh, 3, 1)
8902 5c55ff99 Blue Swirl
GEN_VXRFORM(vcmpequw, 3, 2)
8903 5c55ff99 Blue Swirl
GEN_VXRFORM(vcmpgtsb, 3, 12)
8904 5c55ff99 Blue Swirl
GEN_VXRFORM(vcmpgtsh, 3, 13)
8905 5c55ff99 Blue Swirl
GEN_VXRFORM(vcmpgtsw, 3, 14)
8906 5c55ff99 Blue Swirl
GEN_VXRFORM(vcmpgtub, 3, 8)
8907 5c55ff99 Blue Swirl
GEN_VXRFORM(vcmpgtuh, 3, 9)
8908 5c55ff99 Blue Swirl
GEN_VXRFORM(vcmpgtuw, 3, 10)
8909 5c55ff99 Blue Swirl
GEN_VXRFORM(vcmpeqfp, 3, 3)
8910 5c55ff99 Blue Swirl
GEN_VXRFORM(vcmpgefp, 3, 7)
8911 5c55ff99 Blue Swirl
GEN_VXRFORM(vcmpgtfp, 3, 11)
8912 5c55ff99 Blue Swirl
GEN_VXRFORM(vcmpbfp, 3, 15)
8913 5c55ff99 Blue Swirl
8914 5c55ff99 Blue Swirl
#undef GEN_VXFORM_SIMM
8915 5c55ff99 Blue Swirl
#define GEN_VXFORM_SIMM(name, opc2, opc3)                               \
8916 5c55ff99 Blue Swirl
    GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
8917 5c55ff99 Blue Swirl
GEN_VXFORM_SIMM(vspltisb, 6, 12),
8918 5c55ff99 Blue Swirl
GEN_VXFORM_SIMM(vspltish, 6, 13),
8919 5c55ff99 Blue Swirl
GEN_VXFORM_SIMM(vspltisw, 6, 14),
8920 5c55ff99 Blue Swirl
8921 5c55ff99 Blue Swirl
#undef GEN_VXFORM_NOA
8922 5c55ff99 Blue Swirl
#define GEN_VXFORM_NOA(name, opc2, opc3)                                \
8923 5c55ff99 Blue Swirl
    GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
8924 5c55ff99 Blue Swirl
GEN_VXFORM_NOA(vupkhsb, 7, 8),
8925 5c55ff99 Blue Swirl
GEN_VXFORM_NOA(vupkhsh, 7, 9),
8926 5c55ff99 Blue Swirl
GEN_VXFORM_NOA(vupklsb, 7, 10),
8927 5c55ff99 Blue Swirl
GEN_VXFORM_NOA(vupklsh, 7, 11),
8928 5c55ff99 Blue Swirl
GEN_VXFORM_NOA(vupkhpx, 7, 13),
8929 5c55ff99 Blue Swirl
GEN_VXFORM_NOA(vupklpx, 7, 15),
8930 5c55ff99 Blue Swirl
GEN_VXFORM_NOA(vrefp, 5, 4),
8931 5c55ff99 Blue Swirl
GEN_VXFORM_NOA(vrsqrtefp, 5, 5),
8932 0bffbc6c Aurelien Jarno
GEN_VXFORM_NOA(vexptefp, 5, 6),
8933 5c55ff99 Blue Swirl
GEN_VXFORM_NOA(vlogefp, 5, 7),
8934 5c55ff99 Blue Swirl
GEN_VXFORM_NOA(vrfim, 5, 8),
8935 5c55ff99 Blue Swirl
GEN_VXFORM_NOA(vrfin, 5, 9),
8936 5c55ff99 Blue Swirl
GEN_VXFORM_NOA(vrfip, 5, 10),
8937 5c55ff99 Blue Swirl
GEN_VXFORM_NOA(vrfiz, 5, 11),
8938 5c55ff99 Blue Swirl
8939 5c55ff99 Blue Swirl
#undef GEN_VXFORM_UIMM
8940 5c55ff99 Blue Swirl
#define GEN_VXFORM_UIMM(name, opc2, opc3)                               \
8941 5c55ff99 Blue Swirl
    GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
8942 5c55ff99 Blue Swirl
GEN_VXFORM_UIMM(vspltb, 6, 8),
8943 5c55ff99 Blue Swirl
GEN_VXFORM_UIMM(vsplth, 6, 9),
8944 5c55ff99 Blue Swirl
GEN_VXFORM_UIMM(vspltw, 6, 10),
8945 5c55ff99 Blue Swirl
GEN_VXFORM_UIMM(vcfux, 5, 12),
8946 5c55ff99 Blue Swirl
GEN_VXFORM_UIMM(vcfsx, 5, 13),
8947 5c55ff99 Blue Swirl
GEN_VXFORM_UIMM(vctuxs, 5, 14),
8948 5c55ff99 Blue Swirl
GEN_VXFORM_UIMM(vctsxs, 5, 15),
8949 5c55ff99 Blue Swirl
8950 5c55ff99 Blue Swirl
#undef GEN_VAFORM_PAIRED
8951 5c55ff99 Blue Swirl
#define GEN_VAFORM_PAIRED(name0, name1, opc2)                           \
8952 5c55ff99 Blue Swirl
    GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
8953 5c55ff99 Blue Swirl
GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16),
8954 5c55ff99 Blue Swirl
GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18),
8955 5c55ff99 Blue Swirl
GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19),
8956 5c55ff99 Blue Swirl
GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20),
8957 5c55ff99 Blue Swirl
GEN_VAFORM_PAIRED(vsel, vperm, 21),
8958 5c55ff99 Blue Swirl
GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23),
8959 5c55ff99 Blue Swirl
8960 5c55ff99 Blue Swirl
#undef GEN_SPE
8961 5c55ff99 Blue Swirl
#define GEN_SPE(name0, name1, opc2, opc3, inval, type)                        \
8962 5c55ff99 Blue Swirl
GEN_HANDLER(name0##_##name1, 0x04, opc2, opc3, inval, type)
8963 5c55ff99 Blue Swirl
GEN_SPE(evaddw,         speundef,      0x00, 0x08, 0x00000000, PPC_SPE),
8964 5c55ff99 Blue Swirl
GEN_SPE(evaddiw,        speundef,      0x01, 0x08, 0x00000000, PPC_SPE),
8965 5c55ff99 Blue Swirl
GEN_SPE(evsubfw,        speundef,      0x02, 0x08, 0x00000000, PPC_SPE),
8966 5c55ff99 Blue Swirl
GEN_SPE(evsubifw,       speundef,      0x03, 0x08, 0x00000000, PPC_SPE),
8967 5c55ff99 Blue Swirl
GEN_SPE(evabs,          evneg,         0x04, 0x08, 0x0000F800, PPC_SPE),
8968 5c55ff99 Blue Swirl
GEN_SPE(evextsb,        evextsh,       0x05, 0x08, 0x0000F800, PPC_SPE),
8969 5c55ff99 Blue Swirl
GEN_SPE(evrndw,         evcntlzw,      0x06, 0x08, 0x0000F800, PPC_SPE),
8970 5c55ff99 Blue Swirl
GEN_SPE(evcntlsw,       brinc,         0x07, 0x08, 0x00000000, PPC_SPE),
8971 a0e13900 Fabien Chouteau
GEN_SPE(evmra,          speundef,      0x02, 0x13, 0x0000F800, PPC_SPE),
8972 5c55ff99 Blue Swirl
GEN_SPE(speundef,       evand,         0x08, 0x08, 0x00000000, PPC_SPE),
8973 5c55ff99 Blue Swirl
GEN_SPE(evandc,         speundef,      0x09, 0x08, 0x00000000, PPC_SPE),
8974 5c55ff99 Blue Swirl
GEN_SPE(evxor,          evor,          0x0B, 0x08, 0x00000000, PPC_SPE),
8975 5c55ff99 Blue Swirl
GEN_SPE(evnor,          eveqv,         0x0C, 0x08, 0x00000000, PPC_SPE),
8976 a0e13900 Fabien Chouteau
GEN_SPE(evmwumi,        evmwsmi,       0x0C, 0x11, 0x00000000, PPC_SPE),
8977 a0e13900 Fabien Chouteau
GEN_SPE(evmwumia,       evmwsmia,      0x1C, 0x11, 0x00000000, PPC_SPE),
8978 a0e13900 Fabien Chouteau
GEN_SPE(evmwumiaa,      evmwsmiaa,     0x0C, 0x15, 0x00000000, PPC_SPE),
8979 5c55ff99 Blue Swirl
GEN_SPE(speundef,       evorc,         0x0D, 0x08, 0x00000000, PPC_SPE),
8980 5c55ff99 Blue Swirl
GEN_SPE(evnand,         speundef,      0x0F, 0x08, 0x00000000, PPC_SPE),
8981 5c55ff99 Blue Swirl
GEN_SPE(evsrwu,         evsrws,        0x10, 0x08, 0x00000000, PPC_SPE),
8982 5c55ff99 Blue Swirl
GEN_SPE(evsrwiu,        evsrwis,       0x11, 0x08, 0x00000000, PPC_SPE),
8983 5c55ff99 Blue Swirl
GEN_SPE(evslw,          speundef,      0x12, 0x08, 0x00000000, PPC_SPE),
8984 5c55ff99 Blue Swirl
GEN_SPE(evslwi,         speundef,      0x13, 0x08, 0x00000000, PPC_SPE),
8985 5c55ff99 Blue Swirl
GEN_SPE(evrlw,          evsplati,      0x14, 0x08, 0x00000000, PPC_SPE),
8986 5c55ff99 Blue Swirl
GEN_SPE(evrlwi,         evsplatfi,     0x15, 0x08, 0x00000000, PPC_SPE),
8987 5c55ff99 Blue Swirl
GEN_SPE(evmergehi,      evmergelo,     0x16, 0x08, 0x00000000, PPC_SPE),
8988 5c55ff99 Blue Swirl
GEN_SPE(evmergehilo,    evmergelohi,   0x17, 0x08, 0x00000000, PPC_SPE),
8989 5c55ff99 Blue Swirl
GEN_SPE(evcmpgtu,       evcmpgts,      0x18, 0x08, 0x00600000, PPC_SPE),
8990 5c55ff99 Blue Swirl
GEN_SPE(evcmpltu,       evcmplts,      0x19, 0x08, 0x00600000, PPC_SPE),
8991 5c55ff99 Blue Swirl
GEN_SPE(evcmpeq,        speundef,      0x1A, 0x08, 0x00600000, PPC_SPE),
8992 5c55ff99 Blue Swirl
8993 5c55ff99 Blue Swirl
GEN_SPE(evfsadd,        evfssub,       0x00, 0x0A, 0x00000000, PPC_SPE_SINGLE),
8994 5c55ff99 Blue Swirl
GEN_SPE(evfsabs,        evfsnabs,      0x02, 0x0A, 0x0000F800, PPC_SPE_SINGLE),
8995 5c55ff99 Blue Swirl
GEN_SPE(evfsneg,        speundef,      0x03, 0x0A, 0x0000F800, PPC_SPE_SINGLE),
8996 5c55ff99 Blue Swirl
GEN_SPE(evfsmul,        evfsdiv,       0x04, 0x0A, 0x00000000, PPC_SPE_SINGLE),
8997 5c55ff99 Blue Swirl
GEN_SPE(evfscmpgt,      evfscmplt,     0x06, 0x0A, 0x00600000, PPC_SPE_SINGLE),
8998 5c55ff99 Blue Swirl
GEN_SPE(evfscmpeq,      speundef,      0x07, 0x0A, 0x00600000, PPC_SPE_SINGLE),
8999 5c55ff99 Blue Swirl
GEN_SPE(evfscfui,       evfscfsi,      0x08, 0x0A, 0x00180000, PPC_SPE_SINGLE),
9000 5c55ff99 Blue Swirl
GEN_SPE(evfscfuf,       evfscfsf,      0x09, 0x0A, 0x00180000, PPC_SPE_SINGLE),
9001 5c55ff99 Blue Swirl
GEN_SPE(evfsctui,       evfsctsi,      0x0A, 0x0A, 0x00180000, PPC_SPE_SINGLE),
9002 5c55ff99 Blue Swirl
GEN_SPE(evfsctuf,       evfsctsf,      0x0B, 0x0A, 0x00180000, PPC_SPE_SINGLE),
9003 5c55ff99 Blue Swirl
GEN_SPE(evfsctuiz,      speundef,      0x0C, 0x0A, 0x00180000, PPC_SPE_SINGLE),
9004 5c55ff99 Blue Swirl
GEN_SPE(evfsctsiz,      speundef,      0x0D, 0x0A, 0x00180000, PPC_SPE_SINGLE),
9005 5c55ff99 Blue Swirl
GEN_SPE(evfststgt,      evfststlt,     0x0E, 0x0A, 0x00600000, PPC_SPE_SINGLE),
9006 5c55ff99 Blue Swirl
GEN_SPE(evfststeq,      speundef,      0x0F, 0x0A, 0x00600000, PPC_SPE_SINGLE),
9007 5c55ff99 Blue Swirl
9008 5c55ff99 Blue Swirl
GEN_SPE(efsadd,         efssub,        0x00, 0x0B, 0x00000000, PPC_SPE_SINGLE),
9009 5c55ff99 Blue Swirl
GEN_SPE(efsabs,         efsnabs,       0x02, 0x0B, 0x0000F800, PPC_SPE_SINGLE),
9010 5c55ff99 Blue Swirl
GEN_SPE(efsneg,         speundef,      0x03, 0x0B, 0x0000F800, PPC_SPE_SINGLE),
9011 5c55ff99 Blue Swirl
GEN_SPE(efsmul,         efsdiv,        0x04, 0x0B, 0x00000000, PPC_SPE_SINGLE),
9012 5c55ff99 Blue Swirl
GEN_SPE(efscmpgt,       efscmplt,      0x06, 0x0B, 0x00600000, PPC_SPE_SINGLE),
9013 5c55ff99 Blue Swirl
GEN_SPE(efscmpeq,       efscfd,        0x07, 0x0B, 0x00600000, PPC_SPE_SINGLE),
9014 5c55ff99 Blue Swirl
GEN_SPE(efscfui,        efscfsi,       0x08, 0x0B, 0x00180000, PPC_SPE_SINGLE),
9015 5c55ff99 Blue Swirl
GEN_SPE(efscfuf,        efscfsf,       0x09, 0x0B, 0x00180000, PPC_SPE_SINGLE),
9016 5c55ff99 Blue Swirl
GEN_SPE(efsctui,        efsctsi,       0x0A, 0x0B, 0x00180000, PPC_SPE_SINGLE),
9017 5c55ff99 Blue Swirl
GEN_SPE(efsctuf,        efsctsf,       0x0B, 0x0B, 0x00180000, PPC_SPE_SINGLE),
9018 5c55ff99 Blue Swirl
GEN_SPE(efsctuiz,       speundef,      0x0C, 0x0B, 0x00180000, PPC_SPE_SINGLE),
9019 5c55ff99 Blue Swirl
GEN_SPE(efsctsiz,       speundef,      0x0D, 0x0B, 0x00180000, PPC_SPE_SINGLE),
9020 5c55ff99 Blue Swirl
GEN_SPE(efststgt,       efststlt,      0x0E, 0x0B, 0x00600000, PPC_SPE_SINGLE),
9021 5c55ff99 Blue Swirl
GEN_SPE(efststeq,       speundef,      0x0F, 0x0B, 0x00600000, PPC_SPE_SINGLE),
9022 5c55ff99 Blue Swirl
9023 5c55ff99 Blue Swirl
GEN_SPE(efdadd,         efdsub,        0x10, 0x0B, 0x00000000, PPC_SPE_DOUBLE),
9024 5c55ff99 Blue Swirl
GEN_SPE(efdcfuid,       efdcfsid,      0x11, 0x0B, 0x00180000, PPC_SPE_DOUBLE),
9025 5c55ff99 Blue Swirl
GEN_SPE(efdabs,         efdnabs,       0x12, 0x0B, 0x0000F800, PPC_SPE_DOUBLE),
9026 5c55ff99 Blue Swirl
GEN_SPE(efdneg,         speundef,      0x13, 0x0B, 0x0000F800, PPC_SPE_DOUBLE),
9027 5c55ff99 Blue Swirl
GEN_SPE(efdmul,         efddiv,        0x14, 0x0B, 0x00000000, PPC_SPE_DOUBLE),
9028 5c55ff99 Blue Swirl
GEN_SPE(efdctuidz,      efdctsidz,     0x15, 0x0B, 0x00180000, PPC_SPE_DOUBLE),
9029 5c55ff99 Blue Swirl
GEN_SPE(efdcmpgt,       efdcmplt,      0x16, 0x0B, 0x00600000, PPC_SPE_DOUBLE),
9030 5c55ff99 Blue Swirl
GEN_SPE(efdcmpeq,       efdcfs,        0x17, 0x0B, 0x00600000, PPC_SPE_DOUBLE),
9031 5c55ff99 Blue Swirl
GEN_SPE(efdcfui,        efdcfsi,       0x18, 0x0B, 0x00180000, PPC_SPE_DOUBLE),
9032 5c55ff99 Blue Swirl
GEN_SPE(efdcfuf,        efdcfsf,       0x19, 0x0B, 0x00180000, PPC_SPE_DOUBLE),
9033 5c55ff99 Blue Swirl
GEN_SPE(efdctui,        efdctsi,       0x1A, 0x0B, 0x00180000, PPC_SPE_DOUBLE),
9034 5c55ff99 Blue Swirl
GEN_SPE(efdctuf,        efdctsf,       0x1B, 0x0B, 0x00180000, PPC_SPE_DOUBLE),
9035 5c55ff99 Blue Swirl
GEN_SPE(efdctuiz,       speundef,      0x1C, 0x0B, 0x00180000, PPC_SPE_DOUBLE),
9036 5c55ff99 Blue Swirl
GEN_SPE(efdctsiz,       speundef,      0x1D, 0x0B, 0x00180000, PPC_SPE_DOUBLE),
9037 5c55ff99 Blue Swirl
GEN_SPE(efdtstgt,       efdtstlt,      0x1E, 0x0B, 0x00600000, PPC_SPE_DOUBLE),
9038 5c55ff99 Blue Swirl
GEN_SPE(efdtsteq,       speundef,      0x1F, 0x0B, 0x00600000, PPC_SPE_DOUBLE),
9039 5c55ff99 Blue Swirl
9040 5c55ff99 Blue Swirl
#undef GEN_SPEOP_LDST
9041 5c55ff99 Blue Swirl
#define GEN_SPEOP_LDST(name, opc2, sh)                                        \
9042 5c55ff99 Blue Swirl
GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
9043 5c55ff99 Blue Swirl
GEN_SPEOP_LDST(evldd, 0x00, 3),
9044 5c55ff99 Blue Swirl
GEN_SPEOP_LDST(evldw, 0x01, 3),
9045 5c55ff99 Blue Swirl
GEN_SPEOP_LDST(evldh, 0x02, 3),
9046 5c55ff99 Blue Swirl
GEN_SPEOP_LDST(evlhhesplat, 0x04, 1),
9047 5c55ff99 Blue Swirl
GEN_SPEOP_LDST(evlhhousplat, 0x06, 1),
9048 5c55ff99 Blue Swirl
GEN_SPEOP_LDST(evlhhossplat, 0x07, 1),
9049 5c55ff99 Blue Swirl
GEN_SPEOP_LDST(evlwhe, 0x08, 2),
9050 5c55ff99 Blue Swirl
GEN_SPEOP_LDST(evlwhou, 0x0A, 2),
9051 5c55ff99 Blue Swirl
GEN_SPEOP_LDST(evlwhos, 0x0B, 2),
9052 5c55ff99 Blue Swirl
GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2),
9053 5c55ff99 Blue Swirl
GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2),
9054 5c55ff99 Blue Swirl
9055 5c55ff99 Blue Swirl
GEN_SPEOP_LDST(evstdd, 0x10, 3),
9056 5c55ff99 Blue Swirl
GEN_SPEOP_LDST(evstdw, 0x11, 3),
9057 5c55ff99 Blue Swirl
GEN_SPEOP_LDST(evstdh, 0x12, 3),
9058 5c55ff99 Blue Swirl
GEN_SPEOP_LDST(evstwhe, 0x18, 2),
9059 5c55ff99 Blue Swirl
GEN_SPEOP_LDST(evstwho, 0x1A, 2),
9060 5c55ff99 Blue Swirl
GEN_SPEOP_LDST(evstwwe, 0x1C, 2),
9061 5c55ff99 Blue Swirl
GEN_SPEOP_LDST(evstwwo, 0x1E, 2),
9062 5c55ff99 Blue Swirl
};
9063 5c55ff99 Blue Swirl
9064 3fc6c082 bellard
#include "translate_init.c"
9065 0411a972 j_mayer
#include "helper_regs.h"
9066 79aceca5 bellard
9067 9a64fbe4 bellard
/*****************************************************************************/
9068 3fc6c082 bellard
/* Misc PowerPC helpers */
9069 9a78eead Stefan Weil
void cpu_dump_state (CPUState *env, FILE *f, fprintf_function cpu_fprintf,
9070 36081602 j_mayer
                     int flags)
9071 79aceca5 bellard
{
9072 3fc6c082 bellard
#define RGPL  4
9073 3fc6c082 bellard
#define RFPL  4
9074 3fc6c082 bellard
9075 79aceca5 bellard
    int i;
9076 79aceca5 bellard
9077 90e189ec Blue Swirl
    cpu_fprintf(f, "NIP " TARGET_FMT_lx "   LR " TARGET_FMT_lx " CTR "
9078 9a78eead Stefan Weil
                TARGET_FMT_lx " XER " TARGET_FMT_lx "\n",
9079 9a78eead Stefan Weil
                env->nip, env->lr, env->ctr, env->xer);
9080 90e189ec Blue Swirl
    cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx "  HF "
9081 90e189ec Blue Swirl
                TARGET_FMT_lx " idx %d\n", env->msr, env->spr[SPR_HID0],
9082 90e189ec Blue Swirl
                env->hflags, env->mmu_idx);
9083 d9bce9d9 j_mayer
#if !defined(NO_TIMER_DUMP)
9084 9a78eead Stefan Weil
    cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64
9085 76a66253 j_mayer
#if !defined(CONFIG_USER_ONLY)
9086 9a78eead Stefan Weil
                " DECR %08" PRIu32
9087 76a66253 j_mayer
#endif
9088 76a66253 j_mayer
                "\n",
9089 077fc206 j_mayer
                cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
9090 76a66253 j_mayer
#if !defined(CONFIG_USER_ONLY)
9091 76a66253 j_mayer
                , cpu_ppc_load_decr(env)
9092 76a66253 j_mayer
#endif
9093 76a66253 j_mayer
                );
9094 077fc206 j_mayer
#endif
9095 76a66253 j_mayer
    for (i = 0; i < 32; i++) {
9096 3fc6c082 bellard
        if ((i & (RGPL - 1)) == 0)
9097 3fc6c082 bellard
            cpu_fprintf(f, "GPR%02d", i);
9098 b11ebf64 Blue Swirl
        cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i));
9099 3fc6c082 bellard
        if ((i & (RGPL - 1)) == (RGPL - 1))
9100 7fe48483 bellard
            cpu_fprintf(f, "\n");
9101 76a66253 j_mayer
    }
9102 3fc6c082 bellard
    cpu_fprintf(f, "CR ");
9103 76a66253 j_mayer
    for (i = 0; i < 8; i++)
9104 7fe48483 bellard
        cpu_fprintf(f, "%01x", env->crf[i]);
9105 7fe48483 bellard
    cpu_fprintf(f, "  [");
9106 76a66253 j_mayer
    for (i = 0; i < 8; i++) {
9107 76a66253 j_mayer
        char a = '-';
9108 76a66253 j_mayer
        if (env->crf[i] & 0x08)
9109 76a66253 j_mayer
            a = 'L';
9110 76a66253 j_mayer
        else if (env->crf[i] & 0x04)
9111 76a66253 j_mayer
            a = 'G';
9112 76a66253 j_mayer
        else if (env->crf[i] & 0x02)
9113 76a66253 j_mayer
            a = 'E';
9114 7fe48483 bellard
        cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
9115 76a66253 j_mayer
    }
9116 90e189ec Blue Swirl
    cpu_fprintf(f, " ]             RES " TARGET_FMT_lx "\n",
9117 90e189ec Blue Swirl
                env->reserve_addr);
9118 3fc6c082 bellard
    for (i = 0; i < 32; i++) {
9119 3fc6c082 bellard
        if ((i & (RFPL - 1)) == 0)
9120 3fc6c082 bellard
            cpu_fprintf(f, "FPR%02d", i);
9121 26a76461 bellard
        cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
9122 3fc6c082 bellard
        if ((i & (RFPL - 1)) == (RFPL - 1))
9123 7fe48483 bellard
            cpu_fprintf(f, "\n");
9124 79aceca5 bellard
    }
9125 7889270a aurel32
    cpu_fprintf(f, "FPSCR %08x\n", env->fpscr);
9126 f2e63a42 j_mayer
#if !defined(CONFIG_USER_ONLY)
9127 90e189ec Blue Swirl
    cpu_fprintf(f, "SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx " SDR1 "
9128 90e189ec Blue Swirl
                TARGET_FMT_lx "\n", env->spr[SPR_SRR0], env->spr[SPR_SRR1],
9129 90e189ec Blue Swirl
                env->sdr1);
9130 f2e63a42 j_mayer
#endif
9131 79aceca5 bellard
9132 3fc6c082 bellard
#undef RGPL
9133 3fc6c082 bellard
#undef RFPL
9134 79aceca5 bellard
}
9135 79aceca5 bellard
9136 9a78eead Stefan Weil
void cpu_dump_statistics (CPUState *env, FILE*f, fprintf_function cpu_fprintf,
9137 76a66253 j_mayer
                          int flags)
9138 76a66253 j_mayer
{
9139 76a66253 j_mayer
#if defined(DO_PPC_STATISTICS)
9140 c227f099 Anthony Liguori
    opc_handler_t **t1, **t2, **t3, *handler;
9141 76a66253 j_mayer
    int op1, op2, op3;
9142 76a66253 j_mayer
9143 76a66253 j_mayer
    t1 = env->opcodes;
9144 76a66253 j_mayer
    for (op1 = 0; op1 < 64; op1++) {
9145 76a66253 j_mayer
        handler = t1[op1];
9146 76a66253 j_mayer
        if (is_indirect_opcode(handler)) {
9147 76a66253 j_mayer
            t2 = ind_table(handler);
9148 76a66253 j_mayer
            for (op2 = 0; op2 < 32; op2++) {
9149 76a66253 j_mayer
                handler = t2[op2];
9150 76a66253 j_mayer
                if (is_indirect_opcode(handler)) {
9151 76a66253 j_mayer
                    t3 = ind_table(handler);
9152 76a66253 j_mayer
                    for (op3 = 0; op3 < 32; op3++) {
9153 76a66253 j_mayer
                        handler = t3[op3];
9154 76a66253 j_mayer
                        if (handler->count == 0)
9155 76a66253 j_mayer
                            continue;
9156 76a66253 j_mayer
                        cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
9157 0bfcd599 Blue Swirl
                                    "%016" PRIx64 " %" PRId64 "\n",
9158 76a66253 j_mayer
                                    op1, op2, op3, op1, (op3 << 5) | op2,
9159 76a66253 j_mayer
                                    handler->oname,
9160 76a66253 j_mayer
                                    handler->count, handler->count);
9161 76a66253 j_mayer
                    }
9162 76a66253 j_mayer
                } else {
9163 76a66253 j_mayer
                    if (handler->count == 0)
9164 76a66253 j_mayer
                        continue;
9165 76a66253 j_mayer
                    cpu_fprintf(f, "%02x %02x    (%02x %04d) %16s: "
9166 0bfcd599 Blue Swirl
                                "%016" PRIx64 " %" PRId64 "\n",
9167 76a66253 j_mayer
                                op1, op2, op1, op2, handler->oname,
9168 76a66253 j_mayer
                                handler->count, handler->count);
9169 76a66253 j_mayer
                }
9170 76a66253 j_mayer
            }
9171 76a66253 j_mayer
        } else {
9172 76a66253 j_mayer
            if (handler->count == 0)
9173 76a66253 j_mayer
                continue;
9174 0bfcd599 Blue Swirl
            cpu_fprintf(f, "%02x       (%02x     ) %16s: %016" PRIx64
9175 0bfcd599 Blue Swirl
                        " %" PRId64 "\n",
9176 76a66253 j_mayer
                        op1, op1, handler->oname,
9177 76a66253 j_mayer
                        handler->count, handler->count);
9178 76a66253 j_mayer
        }
9179 76a66253 j_mayer
    }
9180 76a66253 j_mayer
#endif
9181 76a66253 j_mayer
}
9182 76a66253 j_mayer
9183 9a64fbe4 bellard
/*****************************************************************************/
9184 636aa200 Blue Swirl
static inline void gen_intermediate_code_internal(CPUState *env,
9185 636aa200 Blue Swirl
                                                  TranslationBlock *tb,
9186 636aa200 Blue Swirl
                                                  int search_pc)
9187 79aceca5 bellard
{
9188 9fddaa0c bellard
    DisasContext ctx, *ctxp = &ctx;
9189 c227f099 Anthony Liguori
    opc_handler_t **table, *handler;
9190 0fa85d43 bellard
    target_ulong pc_start;
9191 79aceca5 bellard
    uint16_t *gen_opc_end;
9192 a1d1bb31 aliguori
    CPUBreakpoint *bp;
9193 79aceca5 bellard
    int j, lj = -1;
9194 2e70f6ef pbrook
    int num_insns;
9195 2e70f6ef pbrook
    int max_insns;
9196 79aceca5 bellard
9197 79aceca5 bellard
    pc_start = tb->pc;
9198 79aceca5 bellard
    gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
9199 046d6672 bellard
    ctx.nip = pc_start;
9200 79aceca5 bellard
    ctx.tb = tb;
9201 e1833e1f j_mayer
    ctx.exception = POWERPC_EXCP_NONE;
9202 3fc6c082 bellard
    ctx.spr_cb = env->spr_cb;
9203 76db3ba4 aurel32
    ctx.mem_idx = env->mmu_idx;
9204 76db3ba4 aurel32
    ctx.access_type = -1;
9205 76db3ba4 aurel32
    ctx.le_mode = env->hflags & (1 << MSR_LE) ? 1 : 0;
9206 d9bce9d9 j_mayer
#if defined(TARGET_PPC64)
9207 d9bce9d9 j_mayer
    ctx.sf_mode = msr_sf;
9208 9a64fbe4 bellard
#endif
9209 3cc62370 bellard
    ctx.fpu_enabled = msr_fp;
9210 a9d9eb8f j_mayer
    if ((env->flags & POWERPC_FLAG_SPE) && msr_spe)
9211 d26bfc9a j_mayer
        ctx.spe_enabled = msr_spe;
9212 d26bfc9a j_mayer
    else
9213 d26bfc9a j_mayer
        ctx.spe_enabled = 0;
9214 a9d9eb8f j_mayer
    if ((env->flags & POWERPC_FLAG_VRE) && msr_vr)
9215 a9d9eb8f j_mayer
        ctx.altivec_enabled = msr_vr;
9216 a9d9eb8f j_mayer
    else
9217 a9d9eb8f j_mayer
        ctx.altivec_enabled = 0;
9218 d26bfc9a j_mayer
    if ((env->flags & POWERPC_FLAG_SE) && msr_se)
9219 8cbcb4fa aurel32
        ctx.singlestep_enabled = CPU_SINGLE_STEP;
9220 d26bfc9a j_mayer
    else
9221 8cbcb4fa aurel32
        ctx.singlestep_enabled = 0;
9222 d26bfc9a j_mayer
    if ((env->flags & POWERPC_FLAG_BE) && msr_be)
9223 8cbcb4fa aurel32
        ctx.singlestep_enabled |= CPU_BRANCH_STEP;
9224 8cbcb4fa aurel32
    if (unlikely(env->singlestep_enabled))
9225 8cbcb4fa aurel32
        ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP;
9226 3fc6c082 bellard
#if defined (DO_SINGLE_STEP) && 0
9227 9a64fbe4 bellard
    /* Single step trace mode */
9228 9a64fbe4 bellard
    msr_se = 1;
9229 9a64fbe4 bellard
#endif
9230 2e70f6ef pbrook
    num_insns = 0;
9231 2e70f6ef pbrook
    max_insns = tb->cflags & CF_COUNT_MASK;
9232 2e70f6ef pbrook
    if (max_insns == 0)
9233 2e70f6ef pbrook
        max_insns = CF_COUNT_MASK;
9234 2e70f6ef pbrook
9235 2e70f6ef pbrook
    gen_icount_start();
9236 9a64fbe4 bellard
    /* Set env in case of segfault during code fetch */
9237 e1833e1f j_mayer
    while (ctx.exception == POWERPC_EXCP_NONE && gen_opc_ptr < gen_opc_end) {
9238 72cf2d4f Blue Swirl
        if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) {
9239 72cf2d4f Blue Swirl
            QTAILQ_FOREACH(bp, &env->breakpoints, entry) {
9240 a1d1bb31 aliguori
                if (bp->pc == ctx.nip) {
9241 e06fcd75 aurel32
                    gen_debug_exception(ctxp);
9242 ea4e754f bellard
                    break;
9243 ea4e754f bellard
                }
9244 ea4e754f bellard
            }
9245 ea4e754f bellard
        }
9246 76a66253 j_mayer
        if (unlikely(search_pc)) {
9247 79aceca5 bellard
            j = gen_opc_ptr - gen_opc_buf;
9248 79aceca5 bellard
            if (lj < j) {
9249 79aceca5 bellard
                lj++;
9250 79aceca5 bellard
                while (lj < j)
9251 79aceca5 bellard
                    gen_opc_instr_start[lj++] = 0;
9252 79aceca5 bellard
            }
9253 af4b6c54 aurel32
            gen_opc_pc[lj] = ctx.nip;
9254 af4b6c54 aurel32
            gen_opc_instr_start[lj] = 1;
9255 af4b6c54 aurel32
            gen_opc_icount[lj] = num_insns;
9256 79aceca5 bellard
        }
9257 d12d51d5 aliguori
        LOG_DISAS("----------------\n");
9258 90e189ec Blue Swirl
        LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n",
9259 d12d51d5 aliguori
                  ctx.nip, ctx.mem_idx, (int)msr_ir);
9260 2e70f6ef pbrook
        if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
9261 2e70f6ef pbrook
            gen_io_start();
9262 76db3ba4 aurel32
        if (unlikely(ctx.le_mode)) {
9263 056401ea j_mayer
            ctx.opcode = bswap32(ldl_code(ctx.nip));
9264 056401ea j_mayer
        } else {
9265 056401ea j_mayer
            ctx.opcode = ldl_code(ctx.nip);
9266 111bfab3 bellard
        }
9267 d12d51d5 aliguori
        LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
9268 9a64fbe4 bellard
                    ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
9269 056401ea j_mayer
                    opc3(ctx.opcode), little_endian ? "little" : "big");
9270 731c54f8 Aurelien Jarno
        if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP)))
9271 731c54f8 Aurelien Jarno
            tcg_gen_debug_insn_start(ctx.nip);
9272 046d6672 bellard
        ctx.nip += 4;
9273 3fc6c082 bellard
        table = env->opcodes;
9274 2e70f6ef pbrook
        num_insns++;
9275 79aceca5 bellard
        handler = table[opc1(ctx.opcode)];
9276 79aceca5 bellard
        if (is_indirect_opcode(handler)) {
9277 79aceca5 bellard
            table = ind_table(handler);
9278 79aceca5 bellard
            handler = table[opc2(ctx.opcode)];
9279 79aceca5 bellard
            if (is_indirect_opcode(handler)) {
9280 79aceca5 bellard
                table = ind_table(handler);
9281 79aceca5 bellard
                handler = table[opc3(ctx.opcode)];
9282 79aceca5 bellard
            }
9283 79aceca5 bellard
        }
9284 79aceca5 bellard
        /* Is opcode *REALLY* valid ? */
9285 76a66253 j_mayer
        if (unlikely(handler->handler == &gen_invalid)) {
9286 93fcfe39 aliguori
            if (qemu_log_enabled()) {
9287 93fcfe39 aliguori
                qemu_log("invalid/unsupported opcode: "
9288 90e189ec Blue Swirl
                         "%02x - %02x - %02x (%08x) " TARGET_FMT_lx " %d\n",
9289 90e189ec Blue Swirl
                         opc1(ctx.opcode), opc2(ctx.opcode),
9290 90e189ec Blue Swirl
                         opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
9291 4b3686fa bellard
            }
9292 76a66253 j_mayer
        } else {
9293 76a66253 j_mayer
            if (unlikely((ctx.opcode & handler->inval) != 0)) {
9294 93fcfe39 aliguori
                if (qemu_log_enabled()) {
9295 93fcfe39 aliguori
                    qemu_log("invalid bits: %08x for opcode: "
9296 90e189ec Blue Swirl
                             "%02x - %02x - %02x (%08x) " TARGET_FMT_lx "\n",
9297 90e189ec Blue Swirl
                             ctx.opcode & handler->inval, opc1(ctx.opcode),
9298 90e189ec Blue Swirl
                             opc2(ctx.opcode), opc3(ctx.opcode),
9299 90e189ec Blue Swirl
                             ctx.opcode, ctx.nip - 4);
9300 76a66253 j_mayer
                }
9301 e06fcd75 aurel32
                gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL);
9302 4b3686fa bellard
                break;
9303 79aceca5 bellard
            }
9304 79aceca5 bellard
        }
9305 4b3686fa bellard
        (*(handler->handler))(&ctx);
9306 76a66253 j_mayer
#if defined(DO_PPC_STATISTICS)
9307 76a66253 j_mayer
        handler->count++;
9308 76a66253 j_mayer
#endif
9309 9a64fbe4 bellard
        /* Check trace mode exceptions */
9310 8cbcb4fa aurel32
        if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP &&
9311 8cbcb4fa aurel32
                     (ctx.nip <= 0x100 || ctx.nip > 0xF00) &&
9312 8cbcb4fa aurel32
                     ctx.exception != POWERPC_SYSCALL &&
9313 8cbcb4fa aurel32
                     ctx.exception != POWERPC_EXCP_TRAP &&
9314 8cbcb4fa aurel32
                     ctx.exception != POWERPC_EXCP_BRANCH)) {
9315 e06fcd75 aurel32
            gen_exception(ctxp, POWERPC_EXCP_TRACE);
9316 d26bfc9a j_mayer
        } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
9317 2e70f6ef pbrook
                            (env->singlestep_enabled) ||
9318 1b530a6d aurel32
                            singlestep ||
9319 2e70f6ef pbrook
                            num_insns >= max_insns)) {
9320 d26bfc9a j_mayer
            /* if we reach a page boundary or are single stepping, stop
9321 d26bfc9a j_mayer
             * generation
9322 d26bfc9a j_mayer
             */
9323 8dd4983c bellard
            break;
9324 76a66253 j_mayer
        }
9325 3fc6c082 bellard
    }
9326 2e70f6ef pbrook
    if (tb->cflags & CF_LAST_IO)
9327 2e70f6ef pbrook
        gen_io_end();
9328 e1833e1f j_mayer
    if (ctx.exception == POWERPC_EXCP_NONE) {
9329 c1942362 bellard
        gen_goto_tb(&ctx, 0, ctx.nip);
9330 e1833e1f j_mayer
    } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
9331 8cbcb4fa aurel32
        if (unlikely(env->singlestep_enabled)) {
9332 e06fcd75 aurel32
            gen_debug_exception(ctxp);
9333 8cbcb4fa aurel32
        }
9334 76a66253 j_mayer
        /* Generate the return instruction */
9335 57fec1fe bellard
        tcg_gen_exit_tb(0);
9336 9a64fbe4 bellard
    }
9337 2e70f6ef pbrook
    gen_icount_end(tb, num_insns);
9338 79aceca5 bellard
    *gen_opc_ptr = INDEX_op_end;
9339 76a66253 j_mayer
    if (unlikely(search_pc)) {
9340 9a64fbe4 bellard
        j = gen_opc_ptr - gen_opc_buf;
9341 9a64fbe4 bellard
        lj++;
9342 9a64fbe4 bellard
        while (lj <= j)
9343 9a64fbe4 bellard
            gen_opc_instr_start[lj++] = 0;
9344 9a64fbe4 bellard
    } else {
9345 046d6672 bellard
        tb->size = ctx.nip - pc_start;
9346 2e70f6ef pbrook
        tb->icount = num_insns;
9347 9a64fbe4 bellard
    }
9348 d9bce9d9 j_mayer
#if defined(DEBUG_DISAS)
9349 8fec2b8c aliguori
    if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
9350 76a66253 j_mayer
        int flags;
9351 237c0af0 j_mayer
        flags = env->bfd_mach;
9352 76db3ba4 aurel32
        flags |= ctx.le_mode << 16;
9353 93fcfe39 aliguori
        qemu_log("IN: %s\n", lookup_symbol(pc_start));
9354 93fcfe39 aliguori
        log_target_disas(pc_start, ctx.nip - pc_start, flags);
9355 93fcfe39 aliguori
        qemu_log("\n");
9356 9fddaa0c bellard
    }
9357 79aceca5 bellard
#endif
9358 79aceca5 bellard
}
9359 79aceca5 bellard
9360 2cfc5f17 ths
void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
9361 79aceca5 bellard
{
9362 2cfc5f17 ths
    gen_intermediate_code_internal(env, tb, 0);
9363 79aceca5 bellard
}
9364 79aceca5 bellard
9365 2cfc5f17 ths
void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
9366 79aceca5 bellard
{
9367 2cfc5f17 ths
    gen_intermediate_code_internal(env, tb, 1);
9368 79aceca5 bellard
}
9369 d2856f1a aurel32
9370 d2856f1a aurel32
void gen_pc_load(CPUState *env, TranslationBlock *tb,
9371 d2856f1a aurel32
                unsigned long searched_pc, int pc_pos, void *puc)
9372 d2856f1a aurel32
{
9373 d2856f1a aurel32
    env->nip = gen_opc_pc[pc_pos];
9374 d2856f1a aurel32
}