Statistics
| Branch: | Revision:

root / target-alpha / translate.c @ 1d6198c3

History | View | Annotate | Download (74.8 kB)

1 4c9649a9 j_mayer
/*
2 4c9649a9 j_mayer
 *  Alpha emulation cpu translation for qemu.
3 5fafdf24 ths
 *
4 4c9649a9 j_mayer
 *  Copyright (c) 2007 Jocelyn Mayer
5 4c9649a9 j_mayer
 *
6 4c9649a9 j_mayer
 * This library is free software; you can redistribute it and/or
7 4c9649a9 j_mayer
 * modify it under the terms of the GNU Lesser General Public
8 4c9649a9 j_mayer
 * License as published by the Free Software Foundation; either
9 4c9649a9 j_mayer
 * version 2 of the License, or (at your option) any later version.
10 4c9649a9 j_mayer
 *
11 4c9649a9 j_mayer
 * This library is distributed in the hope that it will be useful,
12 4c9649a9 j_mayer
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 4c9649a9 j_mayer
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 4c9649a9 j_mayer
 * Lesser General Public License for more details.
15 4c9649a9 j_mayer
 *
16 4c9649a9 j_mayer
 * You should have received a copy of the GNU Lesser General Public
17 4c9649a9 j_mayer
 * License along with this library; if not, write to the Free Software
18 4c9649a9 j_mayer
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 4c9649a9 j_mayer
 */
20 4c9649a9 j_mayer
21 4c9649a9 j_mayer
#include <stdint.h>
22 4c9649a9 j_mayer
#include <stdlib.h>
23 4c9649a9 j_mayer
#include <stdio.h>
24 4c9649a9 j_mayer
25 4c9649a9 j_mayer
#include "cpu.h"
26 4c9649a9 j_mayer
#include "exec-all.h"
27 4c9649a9 j_mayer
#include "disas.h"
28 ae8ecd42 aurel32
#include "host-utils.h"
29 57fec1fe bellard
#include "tcg-op.h"
30 ca10f867 aurel32
#include "qemu-common.h"
31 4c9649a9 j_mayer
32 a7812ae4 pbrook
#include "helper.h"
33 a7812ae4 pbrook
#define GEN_HELPER 1
34 a7812ae4 pbrook
#include "helper.h"
35 a7812ae4 pbrook
36 55489a17 aurel32
/* #define DO_SINGLE_STEP */
37 4c9649a9 j_mayer
#define ALPHA_DEBUG_DISAS
38 55489a17 aurel32
/* #define DO_TB_FLUSH */
39 4c9649a9 j_mayer
40 4c9649a9 j_mayer
typedef struct DisasContext DisasContext;
41 4c9649a9 j_mayer
struct DisasContext {
42 4c9649a9 j_mayer
    uint64_t pc;
43 4c9649a9 j_mayer
    int mem_idx;
44 4c9649a9 j_mayer
#if !defined (CONFIG_USER_ONLY)
45 4c9649a9 j_mayer
    int pal_mode;
46 4c9649a9 j_mayer
#endif
47 4c9649a9 j_mayer
    uint32_t amask;
48 4c9649a9 j_mayer
};
49 4c9649a9 j_mayer
50 3761035f aurel32
/* global register indexes */
51 a7812ae4 pbrook
static TCGv_ptr cpu_env;
52 496cb5b9 aurel32
static TCGv cpu_ir[31];
53 f18cd223 aurel32
static TCGv cpu_fir[31];
54 496cb5b9 aurel32
static TCGv cpu_pc;
55 f4ed8679 aurel32
static TCGv cpu_lock;
56 496cb5b9 aurel32
57 3761035f aurel32
/* register names */
58 f18cd223 aurel32
static char cpu_reg_names[10*4+21*5 + 10*5+21*6];
59 2e70f6ef pbrook
60 2e70f6ef pbrook
#include "gen-icount.h"
61 2e70f6ef pbrook
62 a5f1b965 blueswir1
static void alpha_translate_init(void)
63 2e70f6ef pbrook
{
64 496cb5b9 aurel32
    int i;
65 496cb5b9 aurel32
    char *p;
66 2e70f6ef pbrook
    static int done_init = 0;
67 496cb5b9 aurel32
68 2e70f6ef pbrook
    if (done_init)
69 2e70f6ef pbrook
        return;
70 496cb5b9 aurel32
71 a7812ae4 pbrook
    cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
72 496cb5b9 aurel32
73 496cb5b9 aurel32
    p = cpu_reg_names;
74 496cb5b9 aurel32
    for (i = 0; i < 31; i++) {
75 496cb5b9 aurel32
        sprintf(p, "ir%d", i);
76 a7812ae4 pbrook
        cpu_ir[i] = tcg_global_mem_new_i64(TCG_AREG0,
77 a7812ae4 pbrook
                                           offsetof(CPUState, ir[i]), p);
78 6ba8dcd7 aurel32
        p += (i < 10) ? 4 : 5;
79 f18cd223 aurel32
80 f18cd223 aurel32
        sprintf(p, "fir%d", i);
81 a7812ae4 pbrook
        cpu_fir[i] = tcg_global_mem_new_i64(TCG_AREG0,
82 a7812ae4 pbrook
                                            offsetof(CPUState, fir[i]), p);
83 f18cd223 aurel32
        p += (i < 10) ? 5 : 6;
84 496cb5b9 aurel32
    }
85 496cb5b9 aurel32
86 a7812ae4 pbrook
    cpu_pc = tcg_global_mem_new_i64(TCG_AREG0,
87 a7812ae4 pbrook
                                    offsetof(CPUState, pc), "pc");
88 496cb5b9 aurel32
89 a7812ae4 pbrook
    cpu_lock = tcg_global_mem_new_i64(TCG_AREG0,
90 a7812ae4 pbrook
                                      offsetof(CPUState, lock), "lock");
91 f4ed8679 aurel32
92 496cb5b9 aurel32
    /* register helpers */
93 a7812ae4 pbrook
#define GEN_HELPER 2
94 496cb5b9 aurel32
#include "helper.h"
95 496cb5b9 aurel32
96 2e70f6ef pbrook
    done_init = 1;
97 2e70f6ef pbrook
}
98 2e70f6ef pbrook
99 f071b4d3 j_mayer
static always_inline void gen_excp (DisasContext *ctx,
100 f071b4d3 j_mayer
                                    int exception, int error_code)
101 4c9649a9 j_mayer
{
102 a7812ae4 pbrook
    TCGv_i32 tmp1, tmp2;
103 6ad02592 aurel32
104 496cb5b9 aurel32
    tcg_gen_movi_i64(cpu_pc, ctx->pc);
105 6ad02592 aurel32
    tmp1 = tcg_const_i32(exception);
106 6ad02592 aurel32
    tmp2 = tcg_const_i32(error_code);
107 a7812ae4 pbrook
    gen_helper_excp(tmp1, tmp2);
108 a7812ae4 pbrook
    tcg_temp_free_i32(tmp2);
109 a7812ae4 pbrook
    tcg_temp_free_i32(tmp1);
110 4c9649a9 j_mayer
}
111 4c9649a9 j_mayer
112 f071b4d3 j_mayer
static always_inline void gen_invalid (DisasContext *ctx)
113 4c9649a9 j_mayer
{
114 4c9649a9 j_mayer
    gen_excp(ctx, EXCP_OPCDEC, 0);
115 4c9649a9 j_mayer
}
116 4c9649a9 j_mayer
117 f18cd223 aurel32
static always_inline void gen_qemu_ldf (TCGv t0, TCGv t1, int flags)
118 f18cd223 aurel32
{
119 a7812ae4 pbrook
    TCGv tmp = tcg_temp_new();
120 a7812ae4 pbrook
    TCGv_i32 tmp32 = tcg_temp_new_i32();
121 f18cd223 aurel32
    tcg_gen_qemu_ld32u(tmp, t1, flags);
122 a7812ae4 pbrook
    tcg_gen_trunc_i64_i32(tmp32, tmp);
123 a7812ae4 pbrook
    gen_helper_memory_to_f(t0, tmp32);
124 a7812ae4 pbrook
    tcg_temp_free_i32(tmp32);
125 f18cd223 aurel32
    tcg_temp_free(tmp);
126 f18cd223 aurel32
}
127 f18cd223 aurel32
128 f18cd223 aurel32
static always_inline void gen_qemu_ldg (TCGv t0, TCGv t1, int flags)
129 f18cd223 aurel32
{
130 a7812ae4 pbrook
    TCGv tmp = tcg_temp_new();
131 f18cd223 aurel32
    tcg_gen_qemu_ld64(tmp, t1, flags);
132 a7812ae4 pbrook
    gen_helper_memory_to_g(t0, tmp);
133 f18cd223 aurel32
    tcg_temp_free(tmp);
134 f18cd223 aurel32
}
135 f18cd223 aurel32
136 f18cd223 aurel32
static always_inline void gen_qemu_lds (TCGv t0, TCGv t1, int flags)
137 f18cd223 aurel32
{
138 a7812ae4 pbrook
    TCGv tmp = tcg_temp_new();
139 a7812ae4 pbrook
    TCGv_i32 tmp32 = tcg_temp_new_i32();
140 f18cd223 aurel32
    tcg_gen_qemu_ld32u(tmp, t1, flags);
141 a7812ae4 pbrook
    tcg_gen_trunc_i64_i32(tmp32, tmp);
142 a7812ae4 pbrook
    gen_helper_memory_to_s(t0, tmp32);
143 a7812ae4 pbrook
    tcg_temp_free_i32(tmp32);
144 f18cd223 aurel32
    tcg_temp_free(tmp);
145 f18cd223 aurel32
}
146 f18cd223 aurel32
147 f4ed8679 aurel32
static always_inline void gen_qemu_ldl_l (TCGv t0, TCGv t1, int flags)
148 f4ed8679 aurel32
{
149 f4ed8679 aurel32
    tcg_gen_mov_i64(cpu_lock, t1);
150 f4ed8679 aurel32
    tcg_gen_qemu_ld32s(t0, t1, flags);
151 f4ed8679 aurel32
}
152 f4ed8679 aurel32
153 f4ed8679 aurel32
static always_inline void gen_qemu_ldq_l (TCGv t0, TCGv t1, int flags)
154 f4ed8679 aurel32
{
155 f4ed8679 aurel32
    tcg_gen_mov_i64(cpu_lock, t1);
156 f4ed8679 aurel32
    tcg_gen_qemu_ld64(t0, t1, flags);
157 f4ed8679 aurel32
}
158 f4ed8679 aurel32
159 023d8ca2 aurel32
static always_inline void gen_load_mem (DisasContext *ctx,
160 023d8ca2 aurel32
                                        void (*tcg_gen_qemu_load)(TCGv t0, TCGv t1, int flags),
161 023d8ca2 aurel32
                                        int ra, int rb, int32_t disp16,
162 f18cd223 aurel32
                                        int fp, int clear)
163 023d8ca2 aurel32
{
164 023d8ca2 aurel32
    TCGv addr;
165 023d8ca2 aurel32
166 023d8ca2 aurel32
    if (unlikely(ra == 31))
167 023d8ca2 aurel32
        return;
168 023d8ca2 aurel32
169 a7812ae4 pbrook
    addr = tcg_temp_new();
170 023d8ca2 aurel32
    if (rb != 31) {
171 023d8ca2 aurel32
        tcg_gen_addi_i64(addr, cpu_ir[rb], disp16);
172 023d8ca2 aurel32
        if (clear)
173 023d8ca2 aurel32
            tcg_gen_andi_i64(addr, addr, ~0x7);
174 023d8ca2 aurel32
    } else {
175 023d8ca2 aurel32
        if (clear)
176 023d8ca2 aurel32
            disp16 &= ~0x7;
177 023d8ca2 aurel32
        tcg_gen_movi_i64(addr, disp16);
178 023d8ca2 aurel32
    }
179 f18cd223 aurel32
    if (fp)
180 f18cd223 aurel32
        tcg_gen_qemu_load(cpu_fir[ra], addr, ctx->mem_idx);
181 f18cd223 aurel32
    else
182 f18cd223 aurel32
        tcg_gen_qemu_load(cpu_ir[ra], addr, ctx->mem_idx);
183 023d8ca2 aurel32
    tcg_temp_free(addr);
184 023d8ca2 aurel32
}
185 023d8ca2 aurel32
186 f18cd223 aurel32
static always_inline void gen_qemu_stf (TCGv t0, TCGv t1, int flags)
187 f18cd223 aurel32
{
188 a7812ae4 pbrook
    TCGv_i32 tmp32 = tcg_temp_new_i32();
189 a7812ae4 pbrook
    TCGv tmp = tcg_temp_new();
190 a7812ae4 pbrook
    gen_helper_f_to_memory(tmp32, t0);
191 a7812ae4 pbrook
    tcg_gen_extu_i32_i64(tmp, tmp32);
192 f18cd223 aurel32
    tcg_gen_qemu_st32(tmp, t1, flags);
193 f18cd223 aurel32
    tcg_temp_free(tmp);
194 a7812ae4 pbrook
    tcg_temp_free_i32(tmp32);
195 f18cd223 aurel32
}
196 f18cd223 aurel32
197 f18cd223 aurel32
static always_inline void gen_qemu_stg (TCGv t0, TCGv t1, int flags)
198 f18cd223 aurel32
{
199 a7812ae4 pbrook
    TCGv tmp = tcg_temp_new();
200 a7812ae4 pbrook
    gen_helper_g_to_memory(tmp, t0);
201 f18cd223 aurel32
    tcg_gen_qemu_st64(tmp, t1, flags);
202 f18cd223 aurel32
    tcg_temp_free(tmp);
203 f18cd223 aurel32
}
204 f18cd223 aurel32
205 f18cd223 aurel32
static always_inline void gen_qemu_sts (TCGv t0, TCGv t1, int flags)
206 f18cd223 aurel32
{
207 a7812ae4 pbrook
    TCGv_i32 tmp32 = tcg_temp_new_i32();
208 a7812ae4 pbrook
    TCGv tmp = tcg_temp_new();
209 a7812ae4 pbrook
    gen_helper_s_to_memory(tmp32, t0);
210 a7812ae4 pbrook
    tcg_gen_extu_i32_i64(tmp, tmp32);
211 f18cd223 aurel32
    tcg_gen_qemu_st32(tmp, t1, flags);
212 f18cd223 aurel32
    tcg_temp_free(tmp);
213 a7812ae4 pbrook
    tcg_temp_free_i32(tmp32);
214 f18cd223 aurel32
}
215 f18cd223 aurel32
216 f4ed8679 aurel32
static always_inline void gen_qemu_stl_c (TCGv t0, TCGv t1, int flags)
217 f4ed8679 aurel32
{
218 f4ed8679 aurel32
    int l1, l2;
219 f4ed8679 aurel32
220 f4ed8679 aurel32
    l1 = gen_new_label();
221 f4ed8679 aurel32
    l2 = gen_new_label();
222 f4ed8679 aurel32
    tcg_gen_brcond_i64(TCG_COND_NE, cpu_lock, t1, l1);
223 f4ed8679 aurel32
    tcg_gen_qemu_st32(t0, t1, flags);
224 6223246a aurel32
    tcg_gen_movi_i64(t0, 1);
225 f4ed8679 aurel32
    tcg_gen_br(l2);
226 f4ed8679 aurel32
    gen_set_label(l1);
227 6223246a aurel32
    tcg_gen_movi_i64(t0, 0);
228 f4ed8679 aurel32
    gen_set_label(l2);
229 f4ed8679 aurel32
    tcg_gen_movi_i64(cpu_lock, -1);
230 f4ed8679 aurel32
}
231 f4ed8679 aurel32
232 f4ed8679 aurel32
static always_inline void gen_qemu_stq_c (TCGv t0, TCGv t1, int flags)
233 f4ed8679 aurel32
{
234 f4ed8679 aurel32
    int l1, l2;
235 f4ed8679 aurel32
236 f4ed8679 aurel32
    l1 = gen_new_label();
237 f4ed8679 aurel32
    l2 = gen_new_label();
238 f4ed8679 aurel32
    tcg_gen_brcond_i64(TCG_COND_NE, cpu_lock, t1, l1);
239 f4ed8679 aurel32
    tcg_gen_qemu_st64(t0, t1, flags);
240 6223246a aurel32
    tcg_gen_movi_i64(t0, 1);
241 f4ed8679 aurel32
    tcg_gen_br(l2);
242 f4ed8679 aurel32
    gen_set_label(l1);
243 6223246a aurel32
    tcg_gen_movi_i64(t0, 0);
244 f4ed8679 aurel32
    gen_set_label(l2);
245 f4ed8679 aurel32
    tcg_gen_movi_i64(cpu_lock, -1);
246 f4ed8679 aurel32
}
247 f4ed8679 aurel32
248 023d8ca2 aurel32
static always_inline void gen_store_mem (DisasContext *ctx,
249 023d8ca2 aurel32
                                         void (*tcg_gen_qemu_store)(TCGv t0, TCGv t1, int flags),
250 023d8ca2 aurel32
                                         int ra, int rb, int32_t disp16,
251 57a92c8e aurel32
                                         int fp, int clear, int local)
252 023d8ca2 aurel32
{
253 9cd38c23 aurel32
    TCGv addr;
254 57a92c8e aurel32
    if (local)
255 a7812ae4 pbrook
        addr = tcg_temp_local_new();
256 57a92c8e aurel32
    else
257 a7812ae4 pbrook
        addr = tcg_temp_new();
258 023d8ca2 aurel32
    if (rb != 31) {
259 023d8ca2 aurel32
        tcg_gen_addi_i64(addr, cpu_ir[rb], disp16);
260 023d8ca2 aurel32
        if (clear)
261 023d8ca2 aurel32
            tcg_gen_andi_i64(addr, addr, ~0x7);
262 023d8ca2 aurel32
    } else {
263 023d8ca2 aurel32
        if (clear)
264 023d8ca2 aurel32
            disp16 &= ~0x7;
265 023d8ca2 aurel32
        tcg_gen_movi_i64(addr, disp16);
266 023d8ca2 aurel32
    }
267 f18cd223 aurel32
    if (ra != 31) {
268 f18cd223 aurel32
        if (fp)
269 f18cd223 aurel32
            tcg_gen_qemu_store(cpu_fir[ra], addr, ctx->mem_idx);
270 f18cd223 aurel32
        else
271 f18cd223 aurel32
            tcg_gen_qemu_store(cpu_ir[ra], addr, ctx->mem_idx);
272 f18cd223 aurel32
    } else {
273 57a92c8e aurel32
        TCGv zero;
274 57a92c8e aurel32
        if (local)
275 57a92c8e aurel32
            zero = tcg_const_local_i64(0);
276 57a92c8e aurel32
        else
277 57a92c8e aurel32
            zero = tcg_const_i64(0);
278 023d8ca2 aurel32
        tcg_gen_qemu_store(zero, addr, ctx->mem_idx);
279 023d8ca2 aurel32
        tcg_temp_free(zero);
280 023d8ca2 aurel32
    }
281 023d8ca2 aurel32
    tcg_temp_free(addr);
282 023d8ca2 aurel32
}
283 023d8ca2 aurel32
284 f071b4d3 j_mayer
static always_inline void gen_bcond (DisasContext *ctx,
285 9c29504e aurel32
                                     TCGCond cond,
286 9c29504e aurel32
                                     int ra, int32_t disp16, int mask)
287 4c9649a9 j_mayer
{
288 9c29504e aurel32
    int l1, l2;
289 9c29504e aurel32
290 9c29504e aurel32
    l1 = gen_new_label();
291 9c29504e aurel32
    l2 = gen_new_label();
292 9c29504e aurel32
    if (likely(ra != 31)) {
293 9c29504e aurel32
        if (mask) {
294 a7812ae4 pbrook
            TCGv tmp = tcg_temp_new();
295 9c29504e aurel32
            tcg_gen_andi_i64(tmp, cpu_ir[ra], 1);
296 9c29504e aurel32
            tcg_gen_brcondi_i64(cond, tmp, 0, l1);
297 9c29504e aurel32
            tcg_temp_free(tmp);
298 9c29504e aurel32
        } else
299 9c29504e aurel32
            tcg_gen_brcondi_i64(cond, cpu_ir[ra], 0, l1);
300 9c29504e aurel32
    } else {
301 9c29504e aurel32
        /* Very uncommon case - Do not bother to optimize.  */
302 9c29504e aurel32
        TCGv tmp = tcg_const_i64(0);
303 9c29504e aurel32
        tcg_gen_brcondi_i64(cond, tmp, 0, l1);
304 9c29504e aurel32
        tcg_temp_free(tmp);
305 9c29504e aurel32
    }
306 9c29504e aurel32
    tcg_gen_movi_i64(cpu_pc, ctx->pc);
307 9c29504e aurel32
    tcg_gen_br(l2);
308 9c29504e aurel32
    gen_set_label(l1);
309 9c29504e aurel32
    tcg_gen_movi_i64(cpu_pc, ctx->pc + (int64_t)(disp16 << 2));
310 9c29504e aurel32
    gen_set_label(l2);
311 4c9649a9 j_mayer
}
312 4c9649a9 j_mayer
313 a7812ae4 pbrook
static always_inline void gen_fbcond (DisasContext *ctx, int opc,
314 f071b4d3 j_mayer
                                      int ra, int32_t disp16)
315 4c9649a9 j_mayer
{
316 f18cd223 aurel32
    int l1, l2;
317 f18cd223 aurel32
    TCGv tmp;
318 a7812ae4 pbrook
    TCGv src;
319 f18cd223 aurel32
320 f18cd223 aurel32
    l1 = gen_new_label();
321 f18cd223 aurel32
    l2 = gen_new_label();
322 f18cd223 aurel32
    if (ra != 31) {
323 a7812ae4 pbrook
        tmp = tcg_temp_new();
324 a7812ae4 pbrook
        src = cpu_fir[ra];
325 f18cd223 aurel32
    } else  {
326 f18cd223 aurel32
        tmp = tcg_const_i64(0);
327 a7812ae4 pbrook
        src = tmp;
328 a7812ae4 pbrook
    }
329 a7812ae4 pbrook
    switch (opc) {
330 a7812ae4 pbrook
    case 0x31: /* FBEQ */
331 a7812ae4 pbrook
        gen_helper_cmpfeq(tmp, src);
332 a7812ae4 pbrook
        break;
333 a7812ae4 pbrook
    case 0x32: /* FBLT */
334 a7812ae4 pbrook
        gen_helper_cmpflt(tmp, src);
335 a7812ae4 pbrook
        break;
336 a7812ae4 pbrook
    case 0x33: /* FBLE */
337 a7812ae4 pbrook
        gen_helper_cmpfle(tmp, src);
338 a7812ae4 pbrook
        break;
339 a7812ae4 pbrook
    case 0x35: /* FBNE */
340 a7812ae4 pbrook
        gen_helper_cmpfne(tmp, src);
341 a7812ae4 pbrook
        break;
342 a7812ae4 pbrook
    case 0x36: /* FBGE */
343 a7812ae4 pbrook
        gen_helper_cmpfge(tmp, src);
344 a7812ae4 pbrook
        break;
345 a7812ae4 pbrook
    case 0x37: /* FBGT */
346 a7812ae4 pbrook
        gen_helper_cmpfgt(tmp, src);
347 a7812ae4 pbrook
        break;
348 a7812ae4 pbrook
    default:
349 a7812ae4 pbrook
        abort();
350 f18cd223 aurel32
    }
351 f18cd223 aurel32
    tcg_gen_brcondi_i64(TCG_COND_NE, tmp, 0, l1);
352 f18cd223 aurel32
    tcg_gen_movi_i64(cpu_pc, ctx->pc);
353 f18cd223 aurel32
    tcg_gen_br(l2);
354 f18cd223 aurel32
    gen_set_label(l1);
355 f18cd223 aurel32
    tcg_gen_movi_i64(cpu_pc, ctx->pc + (int64_t)(disp16 << 2));
356 f18cd223 aurel32
    gen_set_label(l2);
357 4c9649a9 j_mayer
}
358 4c9649a9 j_mayer
359 fe2b269a aurel32
static always_inline void gen_cmov (TCGCond inv_cond,
360 f071b4d3 j_mayer
                                    int ra, int rb, int rc,
361 adf3c8b6 aurel32
                                    int islit, uint8_t lit, int mask)
362 4c9649a9 j_mayer
{
363 9c29504e aurel32
    int l1;
364 9c29504e aurel32
365 9c29504e aurel32
    if (unlikely(rc == 31))
366 9c29504e aurel32
        return;
367 9c29504e aurel32
368 9c29504e aurel32
    l1 = gen_new_label();
369 9c29504e aurel32
370 9c29504e aurel32
    if (ra != 31) {
371 9c29504e aurel32
        if (mask) {
372 a7812ae4 pbrook
            TCGv tmp = tcg_temp_new();
373 9c29504e aurel32
            tcg_gen_andi_i64(tmp, cpu_ir[ra], 1);
374 9c29504e aurel32
            tcg_gen_brcondi_i64(inv_cond, tmp, 0, l1);
375 9c29504e aurel32
            tcg_temp_free(tmp);
376 9c29504e aurel32
        } else
377 9c29504e aurel32
            tcg_gen_brcondi_i64(inv_cond, cpu_ir[ra], 0, l1);
378 9c29504e aurel32
    } else {
379 9c29504e aurel32
        /* Very uncommon case - Do not bother to optimize.  */
380 9c29504e aurel32
        TCGv tmp = tcg_const_i64(0);
381 9c29504e aurel32
        tcg_gen_brcondi_i64(inv_cond, tmp, 0, l1);
382 9c29504e aurel32
        tcg_temp_free(tmp);
383 9c29504e aurel32
    }
384 9c29504e aurel32
385 4c9649a9 j_mayer
    if (islit)
386 9c29504e aurel32
        tcg_gen_movi_i64(cpu_ir[rc], lit);
387 4c9649a9 j_mayer
    else
388 dfaa8583 aurel32
        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
389 9c29504e aurel32
    gen_set_label(l1);
390 4c9649a9 j_mayer
}
391 4c9649a9 j_mayer
392 a7812ae4 pbrook
#define FARITH2(name)                                       \
393 a7812ae4 pbrook
static always_inline void glue(gen_f, name)(int rb, int rc) \
394 a7812ae4 pbrook
{                                                           \
395 a7812ae4 pbrook
    if (unlikely(rc == 31))                                 \
396 a7812ae4 pbrook
      return;                                               \
397 a7812ae4 pbrook
                                                            \
398 a7812ae4 pbrook
    if (rb != 31)                                           \
399 a7812ae4 pbrook
        gen_helper_ ## name (cpu_fir[rc], cpu_fir[rb]);    \
400 a7812ae4 pbrook
    else {                                                  \
401 a7812ae4 pbrook
        TCGv tmp = tcg_const_i64(0);                        \
402 a7812ae4 pbrook
        gen_helper_ ## name (cpu_fir[rc], tmp);            \
403 a7812ae4 pbrook
        tcg_temp_free(tmp);                                 \
404 a7812ae4 pbrook
    }                                                       \
405 4c9649a9 j_mayer
}
406 a7812ae4 pbrook
FARITH2(sqrts)
407 a7812ae4 pbrook
FARITH2(sqrtf)
408 a7812ae4 pbrook
FARITH2(sqrtg)
409 a7812ae4 pbrook
FARITH2(sqrtt)
410 a7812ae4 pbrook
FARITH2(cvtgf)
411 a7812ae4 pbrook
FARITH2(cvtgq)
412 a7812ae4 pbrook
FARITH2(cvtqf)
413 a7812ae4 pbrook
FARITH2(cvtqg)
414 a7812ae4 pbrook
FARITH2(cvtst)
415 a7812ae4 pbrook
FARITH2(cvtts)
416 a7812ae4 pbrook
FARITH2(cvttq)
417 a7812ae4 pbrook
FARITH2(cvtqs)
418 a7812ae4 pbrook
FARITH2(cvtqt)
419 a7812ae4 pbrook
FARITH2(cvtlq)
420 a7812ae4 pbrook
FARITH2(cvtql)
421 a7812ae4 pbrook
FARITH2(cvtqlv)
422 a7812ae4 pbrook
FARITH2(cvtqlsv)
423 a7812ae4 pbrook
424 a7812ae4 pbrook
#define FARITH3(name)                                                     \
425 a7812ae4 pbrook
static always_inline void glue(gen_f, name) (int ra, int rb, int rc)      \
426 a7812ae4 pbrook
{                                                                         \
427 a7812ae4 pbrook
    if (unlikely(rc == 31))                                               \
428 a7812ae4 pbrook
        return;                                                           \
429 a7812ae4 pbrook
                                                                          \
430 a7812ae4 pbrook
    if (ra != 31) {                                                       \
431 a7812ae4 pbrook
        if (rb != 31)                                                     \
432 a7812ae4 pbrook
            gen_helper_ ## name (cpu_fir[rc], cpu_fir[ra], cpu_fir[rb]);  \
433 a7812ae4 pbrook
        else {                                                            \
434 a7812ae4 pbrook
            TCGv tmp = tcg_const_i64(0);                                  \
435 a7812ae4 pbrook
            gen_helper_ ## name (cpu_fir[rc], cpu_fir[ra], tmp);          \
436 a7812ae4 pbrook
            tcg_temp_free(tmp);                                           \
437 a7812ae4 pbrook
        }                                                                 \
438 a7812ae4 pbrook
    } else {                                                              \
439 a7812ae4 pbrook
        TCGv tmp = tcg_const_i64(0);                                      \
440 a7812ae4 pbrook
        if (rb != 31)                                                     \
441 a7812ae4 pbrook
            gen_helper_ ## name (cpu_fir[rc], tmp, cpu_fir[rb]);          \
442 a7812ae4 pbrook
        else                                                              \
443 a7812ae4 pbrook
            gen_helper_ ## name (cpu_fir[rc], tmp, tmp);                   \
444 a7812ae4 pbrook
        tcg_temp_free(tmp);                                               \
445 a7812ae4 pbrook
    }                                                                     \
446 4c9649a9 j_mayer
}
447 4c9649a9 j_mayer
448 a7812ae4 pbrook
FARITH3(addf)
449 a7812ae4 pbrook
FARITH3(subf)
450 a7812ae4 pbrook
FARITH3(mulf)
451 a7812ae4 pbrook
FARITH3(divf)
452 a7812ae4 pbrook
FARITH3(addg)
453 a7812ae4 pbrook
FARITH3(subg)
454 a7812ae4 pbrook
FARITH3(mulg)
455 a7812ae4 pbrook
FARITH3(divg)
456 a7812ae4 pbrook
FARITH3(cmpgeq)
457 a7812ae4 pbrook
FARITH3(cmpglt)
458 a7812ae4 pbrook
FARITH3(cmpgle)
459 a7812ae4 pbrook
FARITH3(adds)
460 a7812ae4 pbrook
FARITH3(subs)
461 a7812ae4 pbrook
FARITH3(muls)
462 a7812ae4 pbrook
FARITH3(divs)
463 a7812ae4 pbrook
FARITH3(addt)
464 a7812ae4 pbrook
FARITH3(subt)
465 a7812ae4 pbrook
FARITH3(mult)
466 a7812ae4 pbrook
FARITH3(divt)
467 a7812ae4 pbrook
FARITH3(cmptun)
468 a7812ae4 pbrook
FARITH3(cmpteq)
469 a7812ae4 pbrook
FARITH3(cmptlt)
470 a7812ae4 pbrook
FARITH3(cmptle)
471 a7812ae4 pbrook
FARITH3(cpys)
472 a7812ae4 pbrook
FARITH3(cpysn)
473 a7812ae4 pbrook
FARITH3(cpyse)
474 a7812ae4 pbrook
475 a7812ae4 pbrook
#define FCMOV(name)                                                   \
476 a7812ae4 pbrook
static always_inline void glue(gen_f, name) (int ra, int rb, int rc)  \
477 a7812ae4 pbrook
{                                                                     \
478 a7812ae4 pbrook
    int l1;                                                           \
479 a7812ae4 pbrook
    TCGv tmp;                                                         \
480 a7812ae4 pbrook
                                                                      \
481 a7812ae4 pbrook
    if (unlikely(rc == 31))                                           \
482 a7812ae4 pbrook
        return;                                                       \
483 a7812ae4 pbrook
                                                                      \
484 a7812ae4 pbrook
    l1 = gen_new_label();                                             \
485 a7812ae4 pbrook
    tmp = tcg_temp_new();                                 \
486 a7812ae4 pbrook
    if (ra != 31) {                                                   \
487 a7812ae4 pbrook
        tmp = tcg_temp_new();                             \
488 a7812ae4 pbrook
        gen_helper_ ## name (tmp, cpu_fir[ra]);                       \
489 a7812ae4 pbrook
    } else  {                                                         \
490 a7812ae4 pbrook
        tmp = tcg_const_i64(0);                                       \
491 a7812ae4 pbrook
        gen_helper_ ## name (tmp, tmp);                               \
492 a7812ae4 pbrook
    }                                                                 \
493 a7812ae4 pbrook
    tcg_gen_brcondi_i64(TCG_COND_EQ, tmp, 0, l1);                     \
494 a7812ae4 pbrook
    if (rb != 31)                                                     \
495 a7812ae4 pbrook
        tcg_gen_mov_i64(cpu_fir[rc], cpu_fir[ra]);                    \
496 a7812ae4 pbrook
    else                                                              \
497 a7812ae4 pbrook
        tcg_gen_movi_i64(cpu_fir[rc], 0);                             \
498 a7812ae4 pbrook
    gen_set_label(l1);                                                \
499 4c9649a9 j_mayer
}
500 a7812ae4 pbrook
FCMOV(cmpfeq)
501 a7812ae4 pbrook
FCMOV(cmpfne)
502 a7812ae4 pbrook
FCMOV(cmpflt)
503 a7812ae4 pbrook
FCMOV(cmpfge)
504 a7812ae4 pbrook
FCMOV(cmpfle)
505 a7812ae4 pbrook
FCMOV(cmpfgt)
506 4c9649a9 j_mayer
507 b3249f63 aurel32
/* EXTWH, EXTWH, EXTLH, EXTQH */
508 b3249f63 aurel32
static always_inline void gen_ext_h(void (*tcg_gen_ext_i64)(TCGv t0, TCGv t1),
509 b3249f63 aurel32
                                    int ra, int rb, int rc,
510 adf3c8b6 aurel32
                                    int islit, uint8_t lit)
511 b3249f63 aurel32
{
512 b3249f63 aurel32
    if (unlikely(rc == 31))
513 b3249f63 aurel32
        return;
514 b3249f63 aurel32
515 b3249f63 aurel32
    if (ra != 31) {
516 dfaa8583 aurel32
        if (islit) {
517 dfaa8583 aurel32
            if (lit != 0)
518 dfaa8583 aurel32
                tcg_gen_shli_i64(cpu_ir[rc], cpu_ir[ra], 64 - ((lit & 7) * 8));
519 dfaa8583 aurel32
            else
520 dfaa8583 aurel32
                tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[ra]);
521 fe2b269a aurel32
        } else {
522 b3249f63 aurel32
            TCGv tmp1, tmp2;
523 a7812ae4 pbrook
            tmp1 = tcg_temp_new();
524 b3249f63 aurel32
            tcg_gen_andi_i64(tmp1, cpu_ir[rb], 7);
525 b3249f63 aurel32
            tcg_gen_shli_i64(tmp1, tmp1, 3);
526 b3249f63 aurel32
            tmp2 = tcg_const_i64(64);
527 b3249f63 aurel32
            tcg_gen_sub_i64(tmp1, tmp2, tmp1);
528 b3249f63 aurel32
            tcg_temp_free(tmp2);
529 dfaa8583 aurel32
            tcg_gen_shl_i64(cpu_ir[rc], cpu_ir[ra], tmp1);
530 b3249f63 aurel32
            tcg_temp_free(tmp1);
531 dfaa8583 aurel32
        }
532 dfaa8583 aurel32
        if (tcg_gen_ext_i64)
533 dfaa8583 aurel32
            tcg_gen_ext_i64(cpu_ir[rc], cpu_ir[rc]);
534 b3249f63 aurel32
    } else
535 b3249f63 aurel32
        tcg_gen_movi_i64(cpu_ir[rc], 0);
536 b3249f63 aurel32
}
537 b3249f63 aurel32
538 b3249f63 aurel32
/* EXTBL, EXTWL, EXTWL, EXTLL, EXTQL */
539 b3249f63 aurel32
static always_inline void gen_ext_l(void (*tcg_gen_ext_i64)(TCGv t0, TCGv t1),
540 b3249f63 aurel32
                                    int ra, int rb, int rc,
541 adf3c8b6 aurel32
                                    int islit, uint8_t lit)
542 b3249f63 aurel32
{
543 b3249f63 aurel32
    if (unlikely(rc == 31))
544 b3249f63 aurel32
        return;
545 b3249f63 aurel32
546 b3249f63 aurel32
    if (ra != 31) {
547 dfaa8583 aurel32
        if (islit) {
548 dfaa8583 aurel32
                tcg_gen_shri_i64(cpu_ir[rc], cpu_ir[ra], (lit & 7) * 8);
549 dfaa8583 aurel32
        } else {
550 a7812ae4 pbrook
            TCGv tmp = tcg_temp_new();
551 b3249f63 aurel32
            tcg_gen_andi_i64(tmp, cpu_ir[rb], 7);
552 b3249f63 aurel32
            tcg_gen_shli_i64(tmp, tmp, 3);
553 dfaa8583 aurel32
            tcg_gen_shr_i64(cpu_ir[rc], cpu_ir[ra], tmp);
554 b3249f63 aurel32
            tcg_temp_free(tmp);
555 fe2b269a aurel32
        }
556 dfaa8583 aurel32
        if (tcg_gen_ext_i64)
557 dfaa8583 aurel32
            tcg_gen_ext_i64(cpu_ir[rc], cpu_ir[rc]);
558 b3249f63 aurel32
    } else
559 b3249f63 aurel32
        tcg_gen_movi_i64(cpu_ir[rc], 0);
560 b3249f63 aurel32
}
561 b3249f63 aurel32
562 04acd307 aurel32
/* Code to call arith3 helpers */
563 a7812ae4 pbrook
#define ARITH3(name)                                                  \
564 a7812ae4 pbrook
static always_inline void glue(gen_, name) (int ra, int rb, int rc,   \
565 a7812ae4 pbrook
                                            int islit, uint8_t lit)   \
566 a7812ae4 pbrook
{                                                                     \
567 a7812ae4 pbrook
    if (unlikely(rc == 31))                                           \
568 a7812ae4 pbrook
        return;                                                       \
569 a7812ae4 pbrook
                                                                      \
570 a7812ae4 pbrook
    if (ra != 31) {                                                   \
571 a7812ae4 pbrook
        if (islit) {                                                  \
572 a7812ae4 pbrook
            TCGv tmp = tcg_const_i64(lit);                            \
573 a7812ae4 pbrook
            gen_helper_ ## name(cpu_ir[rc], cpu_ir[ra], tmp);         \
574 a7812ae4 pbrook
            tcg_temp_free(tmp);                                       \
575 a7812ae4 pbrook
        } else                                                        \
576 a7812ae4 pbrook
            gen_helper_ ## name (cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]); \
577 a7812ae4 pbrook
    } else {                                                          \
578 a7812ae4 pbrook
        TCGv tmp1 = tcg_const_i64(0);                                 \
579 a7812ae4 pbrook
        if (islit) {                                                  \
580 a7812ae4 pbrook
            TCGv tmp2 = tcg_const_i64(lit);                           \
581 a7812ae4 pbrook
            gen_helper_ ## name (cpu_ir[rc], tmp1, tmp2);             \
582 a7812ae4 pbrook
            tcg_temp_free(tmp2);                                      \
583 a7812ae4 pbrook
        } else                                                        \
584 a7812ae4 pbrook
            gen_helper_ ## name (cpu_ir[rc], tmp1, cpu_ir[rb]);       \
585 a7812ae4 pbrook
        tcg_temp_free(tmp1);                                          \
586 a7812ae4 pbrook
    }                                                                 \
587 b3249f63 aurel32
}
588 a7812ae4 pbrook
ARITH3(cmpbge)
589 a7812ae4 pbrook
ARITH3(addlv)
590 a7812ae4 pbrook
ARITH3(sublv)
591 a7812ae4 pbrook
ARITH3(addqv)
592 a7812ae4 pbrook
ARITH3(subqv)
593 a7812ae4 pbrook
ARITH3(mskbl)
594 a7812ae4 pbrook
ARITH3(insbl)
595 a7812ae4 pbrook
ARITH3(mskwl)
596 a7812ae4 pbrook
ARITH3(inswl)
597 a7812ae4 pbrook
ARITH3(mskll)
598 a7812ae4 pbrook
ARITH3(insll)
599 a7812ae4 pbrook
ARITH3(zap)
600 a7812ae4 pbrook
ARITH3(zapnot)
601 a7812ae4 pbrook
ARITH3(mskql)
602 a7812ae4 pbrook
ARITH3(insql)
603 a7812ae4 pbrook
ARITH3(mskwh)
604 a7812ae4 pbrook
ARITH3(inswh)
605 a7812ae4 pbrook
ARITH3(msklh)
606 a7812ae4 pbrook
ARITH3(inslh)
607 a7812ae4 pbrook
ARITH3(mskqh)
608 a7812ae4 pbrook
ARITH3(insqh)
609 a7812ae4 pbrook
ARITH3(umulh)
610 a7812ae4 pbrook
ARITH3(mullv)
611 a7812ae4 pbrook
ARITH3(mulqv)
612 b3249f63 aurel32
613 01ff9cc8 aurel32
static always_inline void gen_cmp(TCGCond cond,
614 01ff9cc8 aurel32
                                  int ra, int rb, int rc,
615 a1cf28f4 aurel32
                                  int islit, uint8_t lit)
616 01ff9cc8 aurel32
{
617 01ff9cc8 aurel32
    int l1, l2;
618 01ff9cc8 aurel32
    TCGv tmp;
619 01ff9cc8 aurel32
620 01ff9cc8 aurel32
    if (unlikely(rc == 31))
621 01ff9cc8 aurel32
    return;
622 01ff9cc8 aurel32
623 01ff9cc8 aurel32
    l1 = gen_new_label();
624 01ff9cc8 aurel32
    l2 = gen_new_label();
625 01ff9cc8 aurel32
626 01ff9cc8 aurel32
    if (ra != 31) {
627 a7812ae4 pbrook
        tmp = tcg_temp_new();
628 01ff9cc8 aurel32
        tcg_gen_mov_i64(tmp, cpu_ir[ra]);
629 01ff9cc8 aurel32
    } else
630 01ff9cc8 aurel32
        tmp = tcg_const_i64(0);
631 01ff9cc8 aurel32
    if (islit)
632 01ff9cc8 aurel32
        tcg_gen_brcondi_i64(cond, tmp, lit, l1);
633 01ff9cc8 aurel32
    else
634 dfaa8583 aurel32
        tcg_gen_brcond_i64(cond, tmp, cpu_ir[rb], l1);
635 01ff9cc8 aurel32
636 01ff9cc8 aurel32
    tcg_gen_movi_i64(cpu_ir[rc], 0);
637 01ff9cc8 aurel32
    tcg_gen_br(l2);
638 01ff9cc8 aurel32
    gen_set_label(l1);
639 01ff9cc8 aurel32
    tcg_gen_movi_i64(cpu_ir[rc], 1);
640 01ff9cc8 aurel32
    gen_set_label(l2);
641 01ff9cc8 aurel32
}
642 01ff9cc8 aurel32
643 f071b4d3 j_mayer
static always_inline int translate_one (DisasContext *ctx, uint32_t insn)
644 4c9649a9 j_mayer
{
645 4c9649a9 j_mayer
    uint32_t palcode;
646 4c9649a9 j_mayer
    int32_t disp21, disp16, disp12;
647 4c9649a9 j_mayer
    uint16_t fn11, fn16;
648 4c9649a9 j_mayer
    uint8_t opc, ra, rb, rc, sbz, fpfn, fn7, fn2, islit;
649 adf3c8b6 aurel32
    uint8_t lit;
650 4c9649a9 j_mayer
    int ret;
651 4c9649a9 j_mayer
652 4c9649a9 j_mayer
    /* Decode all instruction fields */
653 4c9649a9 j_mayer
    opc = insn >> 26;
654 4c9649a9 j_mayer
    ra = (insn >> 21) & 0x1F;
655 4c9649a9 j_mayer
    rb = (insn >> 16) & 0x1F;
656 4c9649a9 j_mayer
    rc = insn & 0x1F;
657 4c9649a9 j_mayer
    sbz = (insn >> 13) & 0x07;
658 4c9649a9 j_mayer
    islit = (insn >> 12) & 1;
659 dfaa8583 aurel32
    if (rb == 31 && !islit) {
660 dfaa8583 aurel32
        islit = 1;
661 dfaa8583 aurel32
        lit = 0;
662 dfaa8583 aurel32
    } else
663 dfaa8583 aurel32
        lit = (insn >> 13) & 0xFF;
664 4c9649a9 j_mayer
    palcode = insn & 0x03FFFFFF;
665 4c9649a9 j_mayer
    disp21 = ((int32_t)((insn & 0x001FFFFF) << 11)) >> 11;
666 4c9649a9 j_mayer
    disp16 = (int16_t)(insn & 0x0000FFFF);
667 4c9649a9 j_mayer
    disp12 = (int32_t)((insn & 0x00000FFF) << 20) >> 20;
668 4c9649a9 j_mayer
    fn16 = insn & 0x0000FFFF;
669 4c9649a9 j_mayer
    fn11 = (insn >> 5) & 0x000007FF;
670 4c9649a9 j_mayer
    fpfn = fn11 & 0x3F;
671 4c9649a9 j_mayer
    fn7 = (insn >> 5) & 0x0000007F;
672 4c9649a9 j_mayer
    fn2 = (insn >> 5) & 0x00000003;
673 4c9649a9 j_mayer
    ret = 0;
674 4c9649a9 j_mayer
#if defined ALPHA_DEBUG_DISAS
675 4c9649a9 j_mayer
    if (logfile != NULL) {
676 4c9649a9 j_mayer
        fprintf(logfile, "opc %02x ra %d rb %d rc %d disp16 %04x\n",
677 4c9649a9 j_mayer
                opc, ra, rb, rc, disp16);
678 4c9649a9 j_mayer
    }
679 4c9649a9 j_mayer
#endif
680 4c9649a9 j_mayer
    switch (opc) {
681 4c9649a9 j_mayer
    case 0x00:
682 4c9649a9 j_mayer
        /* CALL_PAL */
683 4c9649a9 j_mayer
        if (palcode >= 0x80 && palcode < 0xC0) {
684 4c9649a9 j_mayer
            /* Unprivileged PAL call */
685 4c9649a9 j_mayer
            gen_excp(ctx, EXCP_CALL_PAL + ((palcode & 0x1F) << 6), 0);
686 4c9649a9 j_mayer
#if !defined (CONFIG_USER_ONLY)
687 4c9649a9 j_mayer
        } else if (palcode < 0x40) {
688 4c9649a9 j_mayer
            /* Privileged PAL code */
689 4c9649a9 j_mayer
            if (ctx->mem_idx & 1)
690 4c9649a9 j_mayer
                goto invalid_opc;
691 4c9649a9 j_mayer
            else
692 4c9649a9 j_mayer
                gen_excp(ctx, EXCP_CALL_PALP + ((palcode & 0x1F) << 6), 0);
693 4c9649a9 j_mayer
#endif
694 4c9649a9 j_mayer
        } else {
695 4c9649a9 j_mayer
            /* Invalid PAL call */
696 4c9649a9 j_mayer
            goto invalid_opc;
697 4c9649a9 j_mayer
        }
698 4c9649a9 j_mayer
        ret = 3;
699 4c9649a9 j_mayer
        break;
700 4c9649a9 j_mayer
    case 0x01:
701 4c9649a9 j_mayer
        /* OPC01 */
702 4c9649a9 j_mayer
        goto invalid_opc;
703 4c9649a9 j_mayer
    case 0x02:
704 4c9649a9 j_mayer
        /* OPC02 */
705 4c9649a9 j_mayer
        goto invalid_opc;
706 4c9649a9 j_mayer
    case 0x03:
707 4c9649a9 j_mayer
        /* OPC03 */
708 4c9649a9 j_mayer
        goto invalid_opc;
709 4c9649a9 j_mayer
    case 0x04:
710 4c9649a9 j_mayer
        /* OPC04 */
711 4c9649a9 j_mayer
        goto invalid_opc;
712 4c9649a9 j_mayer
    case 0x05:
713 4c9649a9 j_mayer
        /* OPC05 */
714 4c9649a9 j_mayer
        goto invalid_opc;
715 4c9649a9 j_mayer
    case 0x06:
716 4c9649a9 j_mayer
        /* OPC06 */
717 4c9649a9 j_mayer
        goto invalid_opc;
718 4c9649a9 j_mayer
    case 0x07:
719 4c9649a9 j_mayer
        /* OPC07 */
720 4c9649a9 j_mayer
        goto invalid_opc;
721 4c9649a9 j_mayer
    case 0x08:
722 4c9649a9 j_mayer
        /* LDA */
723 1ef4ef4e aurel32
        if (likely(ra != 31)) {
724 496cb5b9 aurel32
            if (rb != 31)
725 3761035f aurel32
                tcg_gen_addi_i64(cpu_ir[ra], cpu_ir[rb], disp16);
726 3761035f aurel32
            else
727 3761035f aurel32
                tcg_gen_movi_i64(cpu_ir[ra], disp16);
728 496cb5b9 aurel32
        }
729 4c9649a9 j_mayer
        break;
730 4c9649a9 j_mayer
    case 0x09:
731 4c9649a9 j_mayer
        /* LDAH */
732 1ef4ef4e aurel32
        if (likely(ra != 31)) {
733 496cb5b9 aurel32
            if (rb != 31)
734 3761035f aurel32
                tcg_gen_addi_i64(cpu_ir[ra], cpu_ir[rb], disp16 << 16);
735 3761035f aurel32
            else
736 3761035f aurel32
                tcg_gen_movi_i64(cpu_ir[ra], disp16 << 16);
737 496cb5b9 aurel32
        }
738 4c9649a9 j_mayer
        break;
739 4c9649a9 j_mayer
    case 0x0A:
740 4c9649a9 j_mayer
        /* LDBU */
741 4c9649a9 j_mayer
        if (!(ctx->amask & AMASK_BWX))
742 4c9649a9 j_mayer
            goto invalid_opc;
743 f18cd223 aurel32
        gen_load_mem(ctx, &tcg_gen_qemu_ld8u, ra, rb, disp16, 0, 0);
744 4c9649a9 j_mayer
        break;
745 4c9649a9 j_mayer
    case 0x0B:
746 4c9649a9 j_mayer
        /* LDQ_U */
747 f18cd223 aurel32
        gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 0, 1);
748 4c9649a9 j_mayer
        break;
749 4c9649a9 j_mayer
    case 0x0C:
750 4c9649a9 j_mayer
        /* LDWU */
751 4c9649a9 j_mayer
        if (!(ctx->amask & AMASK_BWX))
752 4c9649a9 j_mayer
            goto invalid_opc;
753 f18cd223 aurel32
        gen_load_mem(ctx, &tcg_gen_qemu_ld16u, ra, rb, disp16, 0, 1);
754 4c9649a9 j_mayer
        break;
755 4c9649a9 j_mayer
    case 0x0D:
756 4c9649a9 j_mayer
        /* STW */
757 57a92c8e aurel32
        gen_store_mem(ctx, &tcg_gen_qemu_st16, ra, rb, disp16, 0, 0, 0);
758 4c9649a9 j_mayer
        break;
759 4c9649a9 j_mayer
    case 0x0E:
760 4c9649a9 j_mayer
        /* STB */
761 57a92c8e aurel32
        gen_store_mem(ctx, &tcg_gen_qemu_st8, ra, rb, disp16, 0, 0, 0);
762 4c9649a9 j_mayer
        break;
763 4c9649a9 j_mayer
    case 0x0F:
764 4c9649a9 j_mayer
        /* STQ_U */
765 57a92c8e aurel32
        gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 0, 1, 0);
766 4c9649a9 j_mayer
        break;
767 4c9649a9 j_mayer
    case 0x10:
768 4c9649a9 j_mayer
        switch (fn7) {
769 4c9649a9 j_mayer
        case 0x00:
770 4c9649a9 j_mayer
            /* ADDL */
771 30c7183b aurel32
            if (likely(rc != 31)) {
772 30c7183b aurel32
                if (ra != 31) {
773 30c7183b aurel32
                    if (islit) {
774 30c7183b aurel32
                        tcg_gen_addi_i64(cpu_ir[rc], cpu_ir[ra], lit);
775 30c7183b aurel32
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
776 dfaa8583 aurel32
                    } else {
777 30c7183b aurel32
                        tcg_gen_add_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
778 30c7183b aurel32
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
779 dfaa8583 aurel32
                    }
780 30c7183b aurel32
                } else {
781 30c7183b aurel32
                    if (islit)
782 dfaa8583 aurel32
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
783 30c7183b aurel32
                    else
784 dfaa8583 aurel32
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rb]);
785 30c7183b aurel32
                }
786 30c7183b aurel32
            }
787 4c9649a9 j_mayer
            break;
788 4c9649a9 j_mayer
        case 0x02:
789 4c9649a9 j_mayer
            /* S4ADDL */
790 30c7183b aurel32
            if (likely(rc != 31)) {
791 30c7183b aurel32
                if (ra != 31) {
792 a7812ae4 pbrook
                    TCGv tmp = tcg_temp_new();
793 dfaa8583 aurel32
                    tcg_gen_shli_i64(tmp, cpu_ir[ra], 2);
794 dfaa8583 aurel32
                    if (islit)
795 dfaa8583 aurel32
                        tcg_gen_addi_i64(tmp, tmp, lit);
796 dfaa8583 aurel32
                    else
797 dfaa8583 aurel32
                        tcg_gen_add_i64(tmp, tmp, cpu_ir[rb]);
798 dfaa8583 aurel32
                    tcg_gen_ext32s_i64(cpu_ir[rc], tmp);
799 dfaa8583 aurel32
                    tcg_temp_free(tmp);
800 30c7183b aurel32
                } else {
801 30c7183b aurel32
                    if (islit)
802 30c7183b aurel32
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
803 30c7183b aurel32
                    else
804 dfaa8583 aurel32
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rb]);
805 30c7183b aurel32
                }
806 30c7183b aurel32
            }
807 4c9649a9 j_mayer
            break;
808 4c9649a9 j_mayer
        case 0x09:
809 4c9649a9 j_mayer
            /* SUBL */
810 30c7183b aurel32
            if (likely(rc != 31)) {
811 30c7183b aurel32
                if (ra != 31) {
812 dfaa8583 aurel32
                    if (islit)
813 30c7183b aurel32
                        tcg_gen_subi_i64(cpu_ir[rc], cpu_ir[ra], lit);
814 dfaa8583 aurel32
                    else
815 30c7183b aurel32
                        tcg_gen_sub_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
816 dfaa8583 aurel32
                    tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
817 30c7183b aurel32
                } else {
818 30c7183b aurel32
                    if (islit)
819 30c7183b aurel32
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
820 dfaa8583 aurel32
                    else {
821 30c7183b aurel32
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
822 30c7183b aurel32
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
823 30c7183b aurel32
                }
824 30c7183b aurel32
            }
825 4c9649a9 j_mayer
            break;
826 4c9649a9 j_mayer
        case 0x0B:
827 4c9649a9 j_mayer
            /* S4SUBL */
828 30c7183b aurel32
            if (likely(rc != 31)) {
829 30c7183b aurel32
                if (ra != 31) {
830 a7812ae4 pbrook
                    TCGv tmp = tcg_temp_new();
831 dfaa8583 aurel32
                    tcg_gen_shli_i64(tmp, cpu_ir[ra], 2);
832 dfaa8583 aurel32
                    if (islit)
833 dfaa8583 aurel32
                        tcg_gen_subi_i64(tmp, tmp, lit);
834 dfaa8583 aurel32
                    else
835 dfaa8583 aurel32
                        tcg_gen_sub_i64(tmp, tmp, cpu_ir[rb]);
836 dfaa8583 aurel32
                    tcg_gen_ext32s_i64(cpu_ir[rc], tmp);
837 dfaa8583 aurel32
                    tcg_temp_free(tmp);
838 30c7183b aurel32
                } else {
839 30c7183b aurel32
                    if (islit)
840 30c7183b aurel32
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
841 dfaa8583 aurel32
                    else {
842 30c7183b aurel32
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
843 30c7183b aurel32
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
844 dfaa8583 aurel32
                    }
845 30c7183b aurel32
                }
846 30c7183b aurel32
            }
847 4c9649a9 j_mayer
            break;
848 4c9649a9 j_mayer
        case 0x0F:
849 4c9649a9 j_mayer
            /* CMPBGE */
850 a7812ae4 pbrook
            gen_cmpbge(ra, rb, rc, islit, lit);
851 4c9649a9 j_mayer
            break;
852 4c9649a9 j_mayer
        case 0x12:
853 4c9649a9 j_mayer
            /* S8ADDL */
854 30c7183b aurel32
            if (likely(rc != 31)) {
855 30c7183b aurel32
                if (ra != 31) {
856 a7812ae4 pbrook
                    TCGv tmp = tcg_temp_new();
857 dfaa8583 aurel32
                    tcg_gen_shli_i64(tmp, cpu_ir[ra], 3);
858 dfaa8583 aurel32
                    if (islit)
859 dfaa8583 aurel32
                        tcg_gen_addi_i64(tmp, tmp, lit);
860 dfaa8583 aurel32
                    else
861 dfaa8583 aurel32
                        tcg_gen_add_i64(tmp, tmp, cpu_ir[rb]);
862 dfaa8583 aurel32
                    tcg_gen_ext32s_i64(cpu_ir[rc], tmp);
863 dfaa8583 aurel32
                    tcg_temp_free(tmp);
864 30c7183b aurel32
                } else {
865 30c7183b aurel32
                    if (islit)
866 30c7183b aurel32
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
867 30c7183b aurel32
                    else
868 dfaa8583 aurel32
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rb]);
869 30c7183b aurel32
                }
870 30c7183b aurel32
            }
871 4c9649a9 j_mayer
            break;
872 4c9649a9 j_mayer
        case 0x1B:
873 4c9649a9 j_mayer
            /* S8SUBL */
874 30c7183b aurel32
            if (likely(rc != 31)) {
875 30c7183b aurel32
                if (ra != 31) {
876 a7812ae4 pbrook
                    TCGv tmp = tcg_temp_new();
877 dfaa8583 aurel32
                    tcg_gen_shli_i64(tmp, cpu_ir[ra], 3);
878 dfaa8583 aurel32
                    if (islit)
879 dfaa8583 aurel32
                        tcg_gen_subi_i64(tmp, tmp, lit);
880 dfaa8583 aurel32
                    else
881 dfaa8583 aurel32
                       tcg_gen_sub_i64(tmp, tmp, cpu_ir[rb]);
882 dfaa8583 aurel32
                    tcg_gen_ext32s_i64(cpu_ir[rc], tmp);
883 dfaa8583 aurel32
                    tcg_temp_free(tmp);
884 30c7183b aurel32
                } else {
885 30c7183b aurel32
                    if (islit)
886 30c7183b aurel32
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
887 dfaa8583 aurel32
                    else
888 30c7183b aurel32
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
889 30c7183b aurel32
                        tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
890 dfaa8583 aurel32
                    }
891 30c7183b aurel32
                }
892 30c7183b aurel32
            }
893 4c9649a9 j_mayer
            break;
894 4c9649a9 j_mayer
        case 0x1D:
895 4c9649a9 j_mayer
            /* CMPULT */
896 01ff9cc8 aurel32
            gen_cmp(TCG_COND_LTU, ra, rb, rc, islit, lit);
897 4c9649a9 j_mayer
            break;
898 4c9649a9 j_mayer
        case 0x20:
899 4c9649a9 j_mayer
            /* ADDQ */
900 30c7183b aurel32
            if (likely(rc != 31)) {
901 30c7183b aurel32
                if (ra != 31) {
902 30c7183b aurel32
                    if (islit)
903 30c7183b aurel32
                        tcg_gen_addi_i64(cpu_ir[rc], cpu_ir[ra], lit);
904 30c7183b aurel32
                    else
905 dfaa8583 aurel32
                        tcg_gen_add_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
906 30c7183b aurel32
                } else {
907 30c7183b aurel32
                    if (islit)
908 30c7183b aurel32
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
909 30c7183b aurel32
                    else
910 dfaa8583 aurel32
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
911 30c7183b aurel32
                }
912 30c7183b aurel32
            }
913 4c9649a9 j_mayer
            break;
914 4c9649a9 j_mayer
        case 0x22:
915 4c9649a9 j_mayer
            /* S4ADDQ */
916 30c7183b aurel32
            if (likely(rc != 31)) {
917 30c7183b aurel32
                if (ra != 31) {
918 a7812ae4 pbrook
                    TCGv tmp = tcg_temp_new();
919 dfaa8583 aurel32
                    tcg_gen_shli_i64(tmp, cpu_ir[ra], 2);
920 dfaa8583 aurel32
                    if (islit)
921 dfaa8583 aurel32
                        tcg_gen_addi_i64(cpu_ir[rc], tmp, lit);
922 dfaa8583 aurel32
                    else
923 dfaa8583 aurel32
                        tcg_gen_add_i64(cpu_ir[rc], tmp, cpu_ir[rb]);
924 dfaa8583 aurel32
                    tcg_temp_free(tmp);
925 30c7183b aurel32
                } else {
926 30c7183b aurel32
                    if (islit)
927 30c7183b aurel32
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
928 30c7183b aurel32
                    else
929 dfaa8583 aurel32
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
930 30c7183b aurel32
                }
931 30c7183b aurel32
            }
932 4c9649a9 j_mayer
            break;
933 4c9649a9 j_mayer
        case 0x29:
934 4c9649a9 j_mayer
            /* SUBQ */
935 30c7183b aurel32
            if (likely(rc != 31)) {
936 30c7183b aurel32
                if (ra != 31) {
937 30c7183b aurel32
                    if (islit)
938 30c7183b aurel32
                        tcg_gen_subi_i64(cpu_ir[rc], cpu_ir[ra], lit);
939 30c7183b aurel32
                    else
940 dfaa8583 aurel32
                        tcg_gen_sub_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
941 30c7183b aurel32
                } else {
942 30c7183b aurel32
                    if (islit)
943 30c7183b aurel32
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
944 30c7183b aurel32
                    else
945 dfaa8583 aurel32
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
946 30c7183b aurel32
                }
947 30c7183b aurel32
            }
948 4c9649a9 j_mayer
            break;
949 4c9649a9 j_mayer
        case 0x2B:
950 4c9649a9 j_mayer
            /* S4SUBQ */
951 30c7183b aurel32
            if (likely(rc != 31)) {
952 30c7183b aurel32
                if (ra != 31) {
953 a7812ae4 pbrook
                    TCGv tmp = tcg_temp_new();
954 dfaa8583 aurel32
                    tcg_gen_shli_i64(tmp, cpu_ir[ra], 2);
955 dfaa8583 aurel32
                    if (islit)
956 dfaa8583 aurel32
                        tcg_gen_subi_i64(cpu_ir[rc], tmp, lit);
957 dfaa8583 aurel32
                    else
958 dfaa8583 aurel32
                        tcg_gen_sub_i64(cpu_ir[rc], tmp, cpu_ir[rb]);
959 dfaa8583 aurel32
                    tcg_temp_free(tmp);
960 30c7183b aurel32
                } else {
961 30c7183b aurel32
                    if (islit)
962 30c7183b aurel32
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
963 30c7183b aurel32
                    else
964 dfaa8583 aurel32
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
965 30c7183b aurel32
                }
966 30c7183b aurel32
            }
967 4c9649a9 j_mayer
            break;
968 4c9649a9 j_mayer
        case 0x2D:
969 4c9649a9 j_mayer
            /* CMPEQ */
970 01ff9cc8 aurel32
            gen_cmp(TCG_COND_EQ, ra, rb, rc, islit, lit);
971 4c9649a9 j_mayer
            break;
972 4c9649a9 j_mayer
        case 0x32:
973 4c9649a9 j_mayer
            /* S8ADDQ */
974 30c7183b aurel32
            if (likely(rc != 31)) {
975 30c7183b aurel32
                if (ra != 31) {
976 a7812ae4 pbrook
                    TCGv tmp = tcg_temp_new();
977 dfaa8583 aurel32
                    tcg_gen_shli_i64(tmp, cpu_ir[ra], 3);
978 dfaa8583 aurel32
                    if (islit)
979 dfaa8583 aurel32
                        tcg_gen_addi_i64(cpu_ir[rc], tmp, lit);
980 dfaa8583 aurel32
                    else
981 dfaa8583 aurel32
                        tcg_gen_add_i64(cpu_ir[rc], tmp, cpu_ir[rb]);
982 dfaa8583 aurel32
                    tcg_temp_free(tmp);
983 30c7183b aurel32
                } else {
984 30c7183b aurel32
                    if (islit)
985 30c7183b aurel32
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
986 30c7183b aurel32
                    else
987 dfaa8583 aurel32
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
988 30c7183b aurel32
                }
989 30c7183b aurel32
            }
990 4c9649a9 j_mayer
            break;
991 4c9649a9 j_mayer
        case 0x3B:
992 4c9649a9 j_mayer
            /* S8SUBQ */
993 30c7183b aurel32
            if (likely(rc != 31)) {
994 30c7183b aurel32
                if (ra != 31) {
995 a7812ae4 pbrook
                    TCGv tmp = tcg_temp_new();
996 dfaa8583 aurel32
                    tcg_gen_shli_i64(tmp, cpu_ir[ra], 3);
997 dfaa8583 aurel32
                    if (islit)
998 dfaa8583 aurel32
                        tcg_gen_subi_i64(cpu_ir[rc], tmp, lit);
999 dfaa8583 aurel32
                    else
1000 dfaa8583 aurel32
                        tcg_gen_sub_i64(cpu_ir[rc], tmp, cpu_ir[rb]);
1001 dfaa8583 aurel32
                    tcg_temp_free(tmp);
1002 30c7183b aurel32
                } else {
1003 30c7183b aurel32
                    if (islit)
1004 30c7183b aurel32
                        tcg_gen_movi_i64(cpu_ir[rc], -lit);
1005 30c7183b aurel32
                    else
1006 dfaa8583 aurel32
                        tcg_gen_neg_i64(cpu_ir[rc], cpu_ir[rb]);
1007 30c7183b aurel32
                }
1008 30c7183b aurel32
            }
1009 4c9649a9 j_mayer
            break;
1010 4c9649a9 j_mayer
        case 0x3D:
1011 4c9649a9 j_mayer
            /* CMPULE */
1012 01ff9cc8 aurel32
            gen_cmp(TCG_COND_LEU, ra, rb, rc, islit, lit);
1013 4c9649a9 j_mayer
            break;
1014 4c9649a9 j_mayer
        case 0x40:
1015 4c9649a9 j_mayer
            /* ADDL/V */
1016 a7812ae4 pbrook
            gen_addlv(ra, rb, rc, islit, lit);
1017 4c9649a9 j_mayer
            break;
1018 4c9649a9 j_mayer
        case 0x49:
1019 4c9649a9 j_mayer
            /* SUBL/V */
1020 a7812ae4 pbrook
            gen_sublv(ra, rb, rc, islit, lit);
1021 4c9649a9 j_mayer
            break;
1022 4c9649a9 j_mayer
        case 0x4D:
1023 4c9649a9 j_mayer
            /* CMPLT */
1024 01ff9cc8 aurel32
            gen_cmp(TCG_COND_LT, ra, rb, rc, islit, lit);
1025 4c9649a9 j_mayer
            break;
1026 4c9649a9 j_mayer
        case 0x60:
1027 4c9649a9 j_mayer
            /* ADDQ/V */
1028 a7812ae4 pbrook
            gen_addqv(ra, rb, rc, islit, lit);
1029 4c9649a9 j_mayer
            break;
1030 4c9649a9 j_mayer
        case 0x69:
1031 4c9649a9 j_mayer
            /* SUBQ/V */
1032 a7812ae4 pbrook
            gen_subqv(ra, rb, rc, islit, lit);
1033 4c9649a9 j_mayer
            break;
1034 4c9649a9 j_mayer
        case 0x6D:
1035 4c9649a9 j_mayer
            /* CMPLE */
1036 01ff9cc8 aurel32
            gen_cmp(TCG_COND_LE, ra, rb, rc, islit, lit);
1037 4c9649a9 j_mayer
            break;
1038 4c9649a9 j_mayer
        default:
1039 4c9649a9 j_mayer
            goto invalid_opc;
1040 4c9649a9 j_mayer
        }
1041 4c9649a9 j_mayer
        break;
1042 4c9649a9 j_mayer
    case 0x11:
1043 4c9649a9 j_mayer
        switch (fn7) {
1044 4c9649a9 j_mayer
        case 0x00:
1045 4c9649a9 j_mayer
            /* AND */
1046 30c7183b aurel32
            if (likely(rc != 31)) {
1047 dfaa8583 aurel32
                if (ra == 31)
1048 30c7183b aurel32
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
1049 30c7183b aurel32
                else if (islit)
1050 30c7183b aurel32
                    tcg_gen_andi_i64(cpu_ir[rc], cpu_ir[ra], lit);
1051 30c7183b aurel32
                else
1052 30c7183b aurel32
                    tcg_gen_and_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1053 30c7183b aurel32
            }
1054 4c9649a9 j_mayer
            break;
1055 4c9649a9 j_mayer
        case 0x08:
1056 4c9649a9 j_mayer
            /* BIC */
1057 30c7183b aurel32
            if (likely(rc != 31)) {
1058 30c7183b aurel32
                if (ra != 31) {
1059 30c7183b aurel32
                    if (islit)
1060 30c7183b aurel32
                        tcg_gen_andi_i64(cpu_ir[rc], cpu_ir[ra], ~lit);
1061 1b581c44 aurel32
                    else
1062 1b581c44 aurel32
                        tcg_gen_andc_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1063 30c7183b aurel32
                } else
1064 30c7183b aurel32
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
1065 30c7183b aurel32
            }
1066 4c9649a9 j_mayer
            break;
1067 4c9649a9 j_mayer
        case 0x14:
1068 4c9649a9 j_mayer
            /* CMOVLBS */
1069 fe2b269a aurel32
            gen_cmov(TCG_COND_EQ, ra, rb, rc, islit, lit, 1);
1070 4c9649a9 j_mayer
            break;
1071 4c9649a9 j_mayer
        case 0x16:
1072 4c9649a9 j_mayer
            /* CMOVLBC */
1073 fe2b269a aurel32
            gen_cmov(TCG_COND_NE, ra, rb, rc, islit, lit, 1);
1074 4c9649a9 j_mayer
            break;
1075 4c9649a9 j_mayer
        case 0x20:
1076 4c9649a9 j_mayer
            /* BIS */
1077 30c7183b aurel32
            if (likely(rc != 31)) {
1078 30c7183b aurel32
                if (ra != 31) {
1079 30c7183b aurel32
                    if (islit)
1080 30c7183b aurel32
                        tcg_gen_ori_i64(cpu_ir[rc], cpu_ir[ra], lit);
1081 8bb6e981 aurel32
                    else
1082 30c7183b aurel32
                        tcg_gen_or_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1083 4c9649a9 j_mayer
                } else {
1084 30c7183b aurel32
                    if (islit)
1085 30c7183b aurel32
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
1086 30c7183b aurel32
                    else
1087 dfaa8583 aurel32
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
1088 4c9649a9 j_mayer
                }
1089 4c9649a9 j_mayer
            }
1090 4c9649a9 j_mayer
            break;
1091 4c9649a9 j_mayer
        case 0x24:
1092 4c9649a9 j_mayer
            /* CMOVEQ */
1093 fe2b269a aurel32
            gen_cmov(TCG_COND_NE, ra, rb, rc, islit, lit, 0);
1094 4c9649a9 j_mayer
            break;
1095 4c9649a9 j_mayer
        case 0x26:
1096 4c9649a9 j_mayer
            /* CMOVNE */
1097 fe2b269a aurel32
            gen_cmov(TCG_COND_EQ, ra, rb, rc, islit, lit, 0);
1098 4c9649a9 j_mayer
            break;
1099 4c9649a9 j_mayer
        case 0x28:
1100 4c9649a9 j_mayer
            /* ORNOT */
1101 30c7183b aurel32
            if (likely(rc != 31)) {
1102 dfaa8583 aurel32
                if (ra != 31) {
1103 30c7183b aurel32
                    if (islit)
1104 30c7183b aurel32
                        tcg_gen_ori_i64(cpu_ir[rc], cpu_ir[ra], ~lit);
1105 1b581c44 aurel32
                    else
1106 1b581c44 aurel32
                        tcg_gen_orc_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1107 30c7183b aurel32
                } else {
1108 30c7183b aurel32
                    if (islit)
1109 30c7183b aurel32
                        tcg_gen_movi_i64(cpu_ir[rc], ~lit);
1110 30c7183b aurel32
                    else
1111 30c7183b aurel32
                        tcg_gen_not_i64(cpu_ir[rc], cpu_ir[rb]);
1112 30c7183b aurel32
                }
1113 30c7183b aurel32
            }
1114 4c9649a9 j_mayer
            break;
1115 4c9649a9 j_mayer
        case 0x40:
1116 4c9649a9 j_mayer
            /* XOR */
1117 30c7183b aurel32
            if (likely(rc != 31)) {
1118 30c7183b aurel32
                if (ra != 31) {
1119 30c7183b aurel32
                    if (islit)
1120 30c7183b aurel32
                        tcg_gen_xori_i64(cpu_ir[rc], cpu_ir[ra], lit);
1121 30c7183b aurel32
                    else
1122 dfaa8583 aurel32
                        tcg_gen_xor_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1123 30c7183b aurel32
                } else {
1124 30c7183b aurel32
                    if (islit)
1125 30c7183b aurel32
                        tcg_gen_movi_i64(cpu_ir[rc], lit);
1126 30c7183b aurel32
                    else
1127 dfaa8583 aurel32
                        tcg_gen_mov_i64(cpu_ir[rc], cpu_ir[rb]);
1128 30c7183b aurel32
                }
1129 30c7183b aurel32
            }
1130 4c9649a9 j_mayer
            break;
1131 4c9649a9 j_mayer
        case 0x44:
1132 4c9649a9 j_mayer
            /* CMOVLT */
1133 fe2b269a aurel32
            gen_cmov(TCG_COND_GE, ra, rb, rc, islit, lit, 0);
1134 4c9649a9 j_mayer
            break;
1135 4c9649a9 j_mayer
        case 0x46:
1136 4c9649a9 j_mayer
            /* CMOVGE */
1137 fe2b269a aurel32
            gen_cmov(TCG_COND_LT, ra, rb, rc, islit, lit, 0);
1138 4c9649a9 j_mayer
            break;
1139 4c9649a9 j_mayer
        case 0x48:
1140 4c9649a9 j_mayer
            /* EQV */
1141 30c7183b aurel32
            if (likely(rc != 31)) {
1142 30c7183b aurel32
                if (ra != 31) {
1143 30c7183b aurel32
                    if (islit)
1144 30c7183b aurel32
                        tcg_gen_xori_i64(cpu_ir[rc], cpu_ir[ra], ~lit);
1145 1b581c44 aurel32
                    else
1146 1b581c44 aurel32
                        tcg_gen_eqv_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1147 30c7183b aurel32
                } else {
1148 30c7183b aurel32
                    if (islit)
1149 30c7183b aurel32
                        tcg_gen_movi_i64(cpu_ir[rc], ~lit);
1150 30c7183b aurel32
                    else
1151 dfaa8583 aurel32
                        tcg_gen_not_i64(cpu_ir[rc], cpu_ir[rb]);
1152 30c7183b aurel32
                }
1153 30c7183b aurel32
            }
1154 4c9649a9 j_mayer
            break;
1155 4c9649a9 j_mayer
        case 0x61:
1156 4c9649a9 j_mayer
            /* AMASK */
1157 ae8ecd42 aurel32
            if (likely(rc != 31)) {
1158 ae8ecd42 aurel32
                if (islit)
1159 ae8ecd42 aurel32
                    tcg_gen_movi_i64(cpu_ir[rc], helper_amask(lit));
1160 ae8ecd42 aurel32
                else
1161 a7812ae4 pbrook
                    gen_helper_amask(cpu_ir[rc], cpu_ir[rb]);
1162 ae8ecd42 aurel32
            }
1163 4c9649a9 j_mayer
            break;
1164 4c9649a9 j_mayer
        case 0x64:
1165 4c9649a9 j_mayer
            /* CMOVLE */
1166 fe2b269a aurel32
            gen_cmov(TCG_COND_GT, ra, rb, rc, islit, lit, 0);
1167 4c9649a9 j_mayer
            break;
1168 4c9649a9 j_mayer
        case 0x66:
1169 4c9649a9 j_mayer
            /* CMOVGT */
1170 fe2b269a aurel32
            gen_cmov(TCG_COND_LE, ra, rb, rc, islit, lit, 0);
1171 4c9649a9 j_mayer
            break;
1172 4c9649a9 j_mayer
        case 0x6C:
1173 4c9649a9 j_mayer
            /* IMPLVER */
1174 3761035f aurel32
            if (rc != 31)
1175 a7812ae4 pbrook
                gen_helper_load_implver(cpu_ir[rc]);
1176 4c9649a9 j_mayer
            break;
1177 4c9649a9 j_mayer
        default:
1178 4c9649a9 j_mayer
            goto invalid_opc;
1179 4c9649a9 j_mayer
        }
1180 4c9649a9 j_mayer
        break;
1181 4c9649a9 j_mayer
    case 0x12:
1182 4c9649a9 j_mayer
        switch (fn7) {
1183 4c9649a9 j_mayer
        case 0x02:
1184 4c9649a9 j_mayer
            /* MSKBL */
1185 a7812ae4 pbrook
            gen_mskbl(ra, rb, rc, islit, lit);
1186 4c9649a9 j_mayer
            break;
1187 4c9649a9 j_mayer
        case 0x06:
1188 4c9649a9 j_mayer
            /* EXTBL */
1189 b3249f63 aurel32
            gen_ext_l(&tcg_gen_ext8u_i64, ra, rb, rc, islit, lit);
1190 4c9649a9 j_mayer
            break;
1191 4c9649a9 j_mayer
        case 0x0B:
1192 4c9649a9 j_mayer
            /* INSBL */
1193 a7812ae4 pbrook
            gen_insbl(ra, rb, rc, islit, lit);
1194 4c9649a9 j_mayer
            break;
1195 4c9649a9 j_mayer
        case 0x12:
1196 4c9649a9 j_mayer
            /* MSKWL */
1197 a7812ae4 pbrook
            gen_mskwl(ra, rb, rc, islit, lit);
1198 4c9649a9 j_mayer
            break;
1199 4c9649a9 j_mayer
        case 0x16:
1200 4c9649a9 j_mayer
            /* EXTWL */
1201 b3249f63 aurel32
            gen_ext_l(&tcg_gen_ext16u_i64, ra, rb, rc, islit, lit);
1202 4c9649a9 j_mayer
            break;
1203 4c9649a9 j_mayer
        case 0x1B:
1204 4c9649a9 j_mayer
            /* INSWL */
1205 a7812ae4 pbrook
            gen_inswl(ra, rb, rc, islit, lit);
1206 4c9649a9 j_mayer
            break;
1207 4c9649a9 j_mayer
        case 0x22:
1208 4c9649a9 j_mayer
            /* MSKLL */
1209 a7812ae4 pbrook
            gen_mskll(ra, rb, rc, islit, lit);
1210 4c9649a9 j_mayer
            break;
1211 4c9649a9 j_mayer
        case 0x26:
1212 4c9649a9 j_mayer
            /* EXTLL */
1213 b3249f63 aurel32
            gen_ext_l(&tcg_gen_ext32u_i64, ra, rb, rc, islit, lit);
1214 4c9649a9 j_mayer
            break;
1215 4c9649a9 j_mayer
        case 0x2B:
1216 4c9649a9 j_mayer
            /* INSLL */
1217 a7812ae4 pbrook
            gen_insll(ra, rb, rc, islit, lit);
1218 4c9649a9 j_mayer
            break;
1219 4c9649a9 j_mayer
        case 0x30:
1220 4c9649a9 j_mayer
            /* ZAP */
1221 a7812ae4 pbrook
            gen_zap(ra, rb, rc, islit, lit);
1222 4c9649a9 j_mayer
            break;
1223 4c9649a9 j_mayer
        case 0x31:
1224 4c9649a9 j_mayer
            /* ZAPNOT */
1225 a7812ae4 pbrook
            gen_zapnot(ra, rb, rc, islit, lit);
1226 4c9649a9 j_mayer
            break;
1227 4c9649a9 j_mayer
        case 0x32:
1228 4c9649a9 j_mayer
            /* MSKQL */
1229 a7812ae4 pbrook
            gen_mskql(ra, rb, rc, islit, lit);
1230 4c9649a9 j_mayer
            break;
1231 4c9649a9 j_mayer
        case 0x34:
1232 4c9649a9 j_mayer
            /* SRL */
1233 30c7183b aurel32
            if (likely(rc != 31)) {
1234 30c7183b aurel32
                if (ra != 31) {
1235 30c7183b aurel32
                    if (islit)
1236 30c7183b aurel32
                        tcg_gen_shri_i64(cpu_ir[rc], cpu_ir[ra], lit & 0x3f);
1237 dfaa8583 aurel32
                    else {
1238 a7812ae4 pbrook
                        TCGv shift = tcg_temp_new();
1239 30c7183b aurel32
                        tcg_gen_andi_i64(shift, cpu_ir[rb], 0x3f);
1240 30c7183b aurel32
                        tcg_gen_shr_i64(cpu_ir[rc], cpu_ir[ra], shift);
1241 30c7183b aurel32
                        tcg_temp_free(shift);
1242 dfaa8583 aurel32
                    }
1243 30c7183b aurel32
                } else
1244 30c7183b aurel32
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
1245 30c7183b aurel32
            }
1246 4c9649a9 j_mayer
            break;
1247 4c9649a9 j_mayer
        case 0x36:
1248 4c9649a9 j_mayer
            /* EXTQL */
1249 b3249f63 aurel32
            gen_ext_l(NULL, ra, rb, rc, islit, lit);
1250 4c9649a9 j_mayer
            break;
1251 4c9649a9 j_mayer
        case 0x39:
1252 4c9649a9 j_mayer
            /* SLL */
1253 30c7183b aurel32
            if (likely(rc != 31)) {
1254 30c7183b aurel32
                if (ra != 31) {
1255 30c7183b aurel32
                    if (islit)
1256 30c7183b aurel32
                        tcg_gen_shli_i64(cpu_ir[rc], cpu_ir[ra], lit & 0x3f);
1257 dfaa8583 aurel32
                    else {
1258 a7812ae4 pbrook
                        TCGv shift = tcg_temp_new();
1259 30c7183b aurel32
                        tcg_gen_andi_i64(shift, cpu_ir[rb], 0x3f);
1260 30c7183b aurel32
                        tcg_gen_shl_i64(cpu_ir[rc], cpu_ir[ra], shift);
1261 30c7183b aurel32
                        tcg_temp_free(shift);
1262 dfaa8583 aurel32
                    }
1263 30c7183b aurel32
                } else
1264 30c7183b aurel32
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
1265 30c7183b aurel32
            }
1266 4c9649a9 j_mayer
            break;
1267 4c9649a9 j_mayer
        case 0x3B:
1268 4c9649a9 j_mayer
            /* INSQL */
1269 a7812ae4 pbrook
            gen_insql(ra, rb, rc, islit, lit);
1270 4c9649a9 j_mayer
            break;
1271 4c9649a9 j_mayer
        case 0x3C:
1272 4c9649a9 j_mayer
            /* SRA */
1273 30c7183b aurel32
            if (likely(rc != 31)) {
1274 30c7183b aurel32
                if (ra != 31) {
1275 30c7183b aurel32
                    if (islit)
1276 30c7183b aurel32
                        tcg_gen_sari_i64(cpu_ir[rc], cpu_ir[ra], lit & 0x3f);
1277 dfaa8583 aurel32
                    else {
1278 a7812ae4 pbrook
                        TCGv shift = tcg_temp_new();
1279 30c7183b aurel32
                        tcg_gen_andi_i64(shift, cpu_ir[rb], 0x3f);
1280 30c7183b aurel32
                        tcg_gen_sar_i64(cpu_ir[rc], cpu_ir[ra], shift);
1281 30c7183b aurel32
                        tcg_temp_free(shift);
1282 dfaa8583 aurel32
                    }
1283 30c7183b aurel32
                } else
1284 30c7183b aurel32
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
1285 30c7183b aurel32
            }
1286 4c9649a9 j_mayer
            break;
1287 4c9649a9 j_mayer
        case 0x52:
1288 4c9649a9 j_mayer
            /* MSKWH */
1289 a7812ae4 pbrook
            gen_mskwh(ra, rb, rc, islit, lit);
1290 4c9649a9 j_mayer
            break;
1291 4c9649a9 j_mayer
        case 0x57:
1292 4c9649a9 j_mayer
            /* INSWH */
1293 a7812ae4 pbrook
            gen_inswh(ra, rb, rc, islit, lit);
1294 4c9649a9 j_mayer
            break;
1295 4c9649a9 j_mayer
        case 0x5A:
1296 4c9649a9 j_mayer
            /* EXTWH */
1297 b3249f63 aurel32
            gen_ext_h(&tcg_gen_ext16u_i64, ra, rb, rc, islit, lit);
1298 4c9649a9 j_mayer
            break;
1299 4c9649a9 j_mayer
        case 0x62:
1300 4c9649a9 j_mayer
            /* MSKLH */
1301 a7812ae4 pbrook
            gen_msklh(ra, rb, rc, islit, lit);
1302 4c9649a9 j_mayer
            break;
1303 4c9649a9 j_mayer
        case 0x67:
1304 4c9649a9 j_mayer
            /* INSLH */
1305 a7812ae4 pbrook
            gen_inslh(ra, rb, rc, islit, lit);
1306 4c9649a9 j_mayer
            break;
1307 4c9649a9 j_mayer
        case 0x6A:
1308 4c9649a9 j_mayer
            /* EXTLH */
1309 b3249f63 aurel32
            gen_ext_h(&tcg_gen_ext16u_i64, ra, rb, rc, islit, lit);
1310 4c9649a9 j_mayer
            break;
1311 4c9649a9 j_mayer
        case 0x72:
1312 4c9649a9 j_mayer
            /* MSKQH */
1313 a7812ae4 pbrook
            gen_mskqh(ra, rb, rc, islit, lit);
1314 4c9649a9 j_mayer
            break;
1315 4c9649a9 j_mayer
        case 0x77:
1316 4c9649a9 j_mayer
            /* INSQH */
1317 a7812ae4 pbrook
            gen_insqh(ra, rb, rc, islit, lit);
1318 4c9649a9 j_mayer
            break;
1319 4c9649a9 j_mayer
        case 0x7A:
1320 4c9649a9 j_mayer
            /* EXTQH */
1321 b3249f63 aurel32
            gen_ext_h(NULL, ra, rb, rc, islit, lit);
1322 4c9649a9 j_mayer
            break;
1323 4c9649a9 j_mayer
        default:
1324 4c9649a9 j_mayer
            goto invalid_opc;
1325 4c9649a9 j_mayer
        }
1326 4c9649a9 j_mayer
        break;
1327 4c9649a9 j_mayer
    case 0x13:
1328 4c9649a9 j_mayer
        switch (fn7) {
1329 4c9649a9 j_mayer
        case 0x00:
1330 4c9649a9 j_mayer
            /* MULL */
1331 30c7183b aurel32
            if (likely(rc != 31)) {
1332 dfaa8583 aurel32
                if (ra == 31)
1333 30c7183b aurel32
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
1334 30c7183b aurel32
                else {
1335 30c7183b aurel32
                    if (islit)
1336 30c7183b aurel32
                        tcg_gen_muli_i64(cpu_ir[rc], cpu_ir[ra], lit);
1337 30c7183b aurel32
                    else
1338 30c7183b aurel32
                        tcg_gen_mul_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1339 30c7183b aurel32
                    tcg_gen_ext32s_i64(cpu_ir[rc], cpu_ir[rc]);
1340 30c7183b aurel32
                }
1341 30c7183b aurel32
            }
1342 4c9649a9 j_mayer
            break;
1343 4c9649a9 j_mayer
        case 0x20:
1344 4c9649a9 j_mayer
            /* MULQ */
1345 30c7183b aurel32
            if (likely(rc != 31)) {
1346 dfaa8583 aurel32
                if (ra == 31)
1347 30c7183b aurel32
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
1348 30c7183b aurel32
                else if (islit)
1349 30c7183b aurel32
                    tcg_gen_muli_i64(cpu_ir[rc], cpu_ir[ra], lit);
1350 30c7183b aurel32
                else
1351 30c7183b aurel32
                    tcg_gen_mul_i64(cpu_ir[rc], cpu_ir[ra], cpu_ir[rb]);
1352 30c7183b aurel32
            }
1353 4c9649a9 j_mayer
            break;
1354 4c9649a9 j_mayer
        case 0x30:
1355 4c9649a9 j_mayer
            /* UMULH */
1356 a7812ae4 pbrook
            gen_umulh(ra, rb, rc, islit, lit);
1357 4c9649a9 j_mayer
            break;
1358 4c9649a9 j_mayer
        case 0x40:
1359 4c9649a9 j_mayer
            /* MULL/V */
1360 a7812ae4 pbrook
            gen_mullv(ra, rb, rc, islit, lit);
1361 4c9649a9 j_mayer
            break;
1362 4c9649a9 j_mayer
        case 0x60:
1363 4c9649a9 j_mayer
            /* MULQ/V */
1364 a7812ae4 pbrook
            gen_mulqv(ra, rb, rc, islit, lit);
1365 4c9649a9 j_mayer
            break;
1366 4c9649a9 j_mayer
        default:
1367 4c9649a9 j_mayer
            goto invalid_opc;
1368 4c9649a9 j_mayer
        }
1369 4c9649a9 j_mayer
        break;
1370 4c9649a9 j_mayer
    case 0x14:
1371 4c9649a9 j_mayer
        switch (fpfn) { /* f11 & 0x3F */
1372 4c9649a9 j_mayer
        case 0x04:
1373 4c9649a9 j_mayer
            /* ITOFS */
1374 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_FIX))
1375 4c9649a9 j_mayer
                goto invalid_opc;
1376 f18cd223 aurel32
            if (likely(rc != 31)) {
1377 f18cd223 aurel32
                if (ra != 31) {
1378 a7812ae4 pbrook
                    TCGv_i32 tmp = tcg_temp_new_i32();
1379 f18cd223 aurel32
                    tcg_gen_trunc_i64_i32(tmp, cpu_ir[ra]);
1380 a7812ae4 pbrook
                    gen_helper_memory_to_s(cpu_fir[rc], tmp);
1381 a7812ae4 pbrook
                    tcg_temp_free_i32(tmp);
1382 f18cd223 aurel32
                } else
1383 f18cd223 aurel32
                    tcg_gen_movi_i64(cpu_fir[rc], 0);
1384 f18cd223 aurel32
            }
1385 4c9649a9 j_mayer
            break;
1386 4c9649a9 j_mayer
        case 0x0A:
1387 4c9649a9 j_mayer
            /* SQRTF */
1388 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_FIX))
1389 4c9649a9 j_mayer
                goto invalid_opc;
1390 a7812ae4 pbrook
            gen_fsqrtf(rb, rc);
1391 4c9649a9 j_mayer
            break;
1392 4c9649a9 j_mayer
        case 0x0B:
1393 4c9649a9 j_mayer
            /* SQRTS */
1394 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_FIX))
1395 4c9649a9 j_mayer
                goto invalid_opc;
1396 a7812ae4 pbrook
            gen_fsqrts(rb, rc);
1397 4c9649a9 j_mayer
            break;
1398 4c9649a9 j_mayer
        case 0x14:
1399 4c9649a9 j_mayer
            /* ITOFF */
1400 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_FIX))
1401 4c9649a9 j_mayer
                goto invalid_opc;
1402 f18cd223 aurel32
            if (likely(rc != 31)) {
1403 f18cd223 aurel32
                if (ra != 31) {
1404 a7812ae4 pbrook
                    TCGv_i32 tmp = tcg_temp_new_i32();
1405 f18cd223 aurel32
                    tcg_gen_trunc_i64_i32(tmp, cpu_ir[ra]);
1406 a7812ae4 pbrook
                    gen_helper_memory_to_f(cpu_fir[rc], tmp);
1407 a7812ae4 pbrook
                    tcg_temp_free_i32(tmp);
1408 f18cd223 aurel32
                } else
1409 f18cd223 aurel32
                    tcg_gen_movi_i64(cpu_fir[rc], 0);
1410 f18cd223 aurel32
            }
1411 4c9649a9 j_mayer
            break;
1412 4c9649a9 j_mayer
        case 0x24:
1413 4c9649a9 j_mayer
            /* ITOFT */
1414 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_FIX))
1415 4c9649a9 j_mayer
                goto invalid_opc;
1416 f18cd223 aurel32
            if (likely(rc != 31)) {
1417 f18cd223 aurel32
                if (ra != 31)
1418 f18cd223 aurel32
                    tcg_gen_mov_i64(cpu_fir[rc], cpu_ir[ra]);
1419 f18cd223 aurel32
                else
1420 f18cd223 aurel32
                    tcg_gen_movi_i64(cpu_fir[rc], 0);
1421 f18cd223 aurel32
            }
1422 4c9649a9 j_mayer
            break;
1423 4c9649a9 j_mayer
        case 0x2A:
1424 4c9649a9 j_mayer
            /* SQRTG */
1425 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_FIX))
1426 4c9649a9 j_mayer
                goto invalid_opc;
1427 a7812ae4 pbrook
            gen_fsqrtg(rb, rc);
1428 4c9649a9 j_mayer
            break;
1429 4c9649a9 j_mayer
        case 0x02B:
1430 4c9649a9 j_mayer
            /* SQRTT */
1431 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_FIX))
1432 4c9649a9 j_mayer
                goto invalid_opc;
1433 a7812ae4 pbrook
            gen_fsqrtt(rb, rc);
1434 4c9649a9 j_mayer
            break;
1435 4c9649a9 j_mayer
        default:
1436 4c9649a9 j_mayer
            goto invalid_opc;
1437 4c9649a9 j_mayer
        }
1438 4c9649a9 j_mayer
        break;
1439 4c9649a9 j_mayer
    case 0x15:
1440 4c9649a9 j_mayer
        /* VAX floating point */
1441 4c9649a9 j_mayer
        /* XXX: rounding mode and trap are ignored (!) */
1442 4c9649a9 j_mayer
        switch (fpfn) { /* f11 & 0x3F */
1443 4c9649a9 j_mayer
        case 0x00:
1444 4c9649a9 j_mayer
            /* ADDF */
1445 a7812ae4 pbrook
            gen_faddf(ra, rb, rc);
1446 4c9649a9 j_mayer
            break;
1447 4c9649a9 j_mayer
        case 0x01:
1448 4c9649a9 j_mayer
            /* SUBF */
1449 a7812ae4 pbrook
            gen_fsubf(ra, rb, rc);
1450 4c9649a9 j_mayer
            break;
1451 4c9649a9 j_mayer
        case 0x02:
1452 4c9649a9 j_mayer
            /* MULF */
1453 a7812ae4 pbrook
            gen_fmulf(ra, rb, rc);
1454 4c9649a9 j_mayer
            break;
1455 4c9649a9 j_mayer
        case 0x03:
1456 4c9649a9 j_mayer
            /* DIVF */
1457 a7812ae4 pbrook
            gen_fdivf(ra, rb, rc);
1458 4c9649a9 j_mayer
            break;
1459 4c9649a9 j_mayer
        case 0x1E:
1460 4c9649a9 j_mayer
            /* CVTDG */
1461 4c9649a9 j_mayer
#if 0 // TODO
1462 a7812ae4 pbrook
            gen_fcvtdg(rb, rc);
1463 4c9649a9 j_mayer
#else
1464 4c9649a9 j_mayer
            goto invalid_opc;
1465 4c9649a9 j_mayer
#endif
1466 4c9649a9 j_mayer
            break;
1467 4c9649a9 j_mayer
        case 0x20:
1468 4c9649a9 j_mayer
            /* ADDG */
1469 a7812ae4 pbrook
            gen_faddg(ra, rb, rc);
1470 4c9649a9 j_mayer
            break;
1471 4c9649a9 j_mayer
        case 0x21:
1472 4c9649a9 j_mayer
            /* SUBG */
1473 a7812ae4 pbrook
            gen_fsubg(ra, rb, rc);
1474 4c9649a9 j_mayer
            break;
1475 4c9649a9 j_mayer
        case 0x22:
1476 4c9649a9 j_mayer
            /* MULG */
1477 a7812ae4 pbrook
            gen_fmulg(ra, rb, rc);
1478 4c9649a9 j_mayer
            break;
1479 4c9649a9 j_mayer
        case 0x23:
1480 4c9649a9 j_mayer
            /* DIVG */
1481 a7812ae4 pbrook
            gen_fdivg(ra, rb, rc);
1482 4c9649a9 j_mayer
            break;
1483 4c9649a9 j_mayer
        case 0x25:
1484 4c9649a9 j_mayer
            /* CMPGEQ */
1485 a7812ae4 pbrook
            gen_fcmpgeq(ra, rb, rc);
1486 4c9649a9 j_mayer
            break;
1487 4c9649a9 j_mayer
        case 0x26:
1488 4c9649a9 j_mayer
            /* CMPGLT */
1489 a7812ae4 pbrook
            gen_fcmpglt(ra, rb, rc);
1490 4c9649a9 j_mayer
            break;
1491 4c9649a9 j_mayer
        case 0x27:
1492 4c9649a9 j_mayer
            /* CMPGLE */
1493 a7812ae4 pbrook
            gen_fcmpgle(ra, rb, rc);
1494 4c9649a9 j_mayer
            break;
1495 4c9649a9 j_mayer
        case 0x2C:
1496 4c9649a9 j_mayer
            /* CVTGF */
1497 a7812ae4 pbrook
            gen_fcvtgf(rb, rc);
1498 4c9649a9 j_mayer
            break;
1499 4c9649a9 j_mayer
        case 0x2D:
1500 4c9649a9 j_mayer
            /* CVTGD */
1501 4c9649a9 j_mayer
#if 0 // TODO
1502 a7812ae4 pbrook
            gen_fcvtgd(rb, rc);
1503 4c9649a9 j_mayer
#else
1504 4c9649a9 j_mayer
            goto invalid_opc;
1505 4c9649a9 j_mayer
#endif
1506 4c9649a9 j_mayer
            break;
1507 4c9649a9 j_mayer
        case 0x2F:
1508 4c9649a9 j_mayer
            /* CVTGQ */
1509 a7812ae4 pbrook
            gen_fcvtgq(rb, rc);
1510 4c9649a9 j_mayer
            break;
1511 4c9649a9 j_mayer
        case 0x3C:
1512 4c9649a9 j_mayer
            /* CVTQF */
1513 a7812ae4 pbrook
            gen_fcvtqf(rb, rc);
1514 4c9649a9 j_mayer
            break;
1515 4c9649a9 j_mayer
        case 0x3E:
1516 4c9649a9 j_mayer
            /* CVTQG */
1517 a7812ae4 pbrook
            gen_fcvtqg(rb, rc);
1518 4c9649a9 j_mayer
            break;
1519 4c9649a9 j_mayer
        default:
1520 4c9649a9 j_mayer
            goto invalid_opc;
1521 4c9649a9 j_mayer
        }
1522 4c9649a9 j_mayer
        break;
1523 4c9649a9 j_mayer
    case 0x16:
1524 4c9649a9 j_mayer
        /* IEEE floating-point */
1525 4c9649a9 j_mayer
        /* XXX: rounding mode and traps are ignored (!) */
1526 4c9649a9 j_mayer
        switch (fpfn) { /* f11 & 0x3F */
1527 4c9649a9 j_mayer
        case 0x00:
1528 4c9649a9 j_mayer
            /* ADDS */
1529 a7812ae4 pbrook
            gen_fadds(ra, rb, rc);
1530 4c9649a9 j_mayer
            break;
1531 4c9649a9 j_mayer
        case 0x01:
1532 4c9649a9 j_mayer
            /* SUBS */
1533 a7812ae4 pbrook
            gen_fsubs(ra, rb, rc);
1534 4c9649a9 j_mayer
            break;
1535 4c9649a9 j_mayer
        case 0x02:
1536 4c9649a9 j_mayer
            /* MULS */
1537 a7812ae4 pbrook
            gen_fmuls(ra, rb, rc);
1538 4c9649a9 j_mayer
            break;
1539 4c9649a9 j_mayer
        case 0x03:
1540 4c9649a9 j_mayer
            /* DIVS */
1541 a7812ae4 pbrook
            gen_fdivs(ra, rb, rc);
1542 4c9649a9 j_mayer
            break;
1543 4c9649a9 j_mayer
        case 0x20:
1544 4c9649a9 j_mayer
            /* ADDT */
1545 a7812ae4 pbrook
            gen_faddt(ra, rb, rc);
1546 4c9649a9 j_mayer
            break;
1547 4c9649a9 j_mayer
        case 0x21:
1548 4c9649a9 j_mayer
            /* SUBT */
1549 a7812ae4 pbrook
            gen_fsubt(ra, rb, rc);
1550 4c9649a9 j_mayer
            break;
1551 4c9649a9 j_mayer
        case 0x22:
1552 4c9649a9 j_mayer
            /* MULT */
1553 a7812ae4 pbrook
            gen_fmult(ra, rb, rc);
1554 4c9649a9 j_mayer
            break;
1555 4c9649a9 j_mayer
        case 0x23:
1556 4c9649a9 j_mayer
            /* DIVT */
1557 a7812ae4 pbrook
            gen_fdivt(ra, rb, rc);
1558 4c9649a9 j_mayer
            break;
1559 4c9649a9 j_mayer
        case 0x24:
1560 4c9649a9 j_mayer
            /* CMPTUN */
1561 a7812ae4 pbrook
            gen_fcmptun(ra, rb, rc);
1562 4c9649a9 j_mayer
            break;
1563 4c9649a9 j_mayer
        case 0x25:
1564 4c9649a9 j_mayer
            /* CMPTEQ */
1565 a7812ae4 pbrook
            gen_fcmpteq(ra, rb, rc);
1566 4c9649a9 j_mayer
            break;
1567 4c9649a9 j_mayer
        case 0x26:
1568 4c9649a9 j_mayer
            /* CMPTLT */
1569 a7812ae4 pbrook
            gen_fcmptlt(ra, rb, rc);
1570 4c9649a9 j_mayer
            break;
1571 4c9649a9 j_mayer
        case 0x27:
1572 4c9649a9 j_mayer
            /* CMPTLE */
1573 a7812ae4 pbrook
            gen_fcmptle(ra, rb, rc);
1574 4c9649a9 j_mayer
            break;
1575 4c9649a9 j_mayer
        case 0x2C:
1576 4c9649a9 j_mayer
            /* XXX: incorrect */
1577 a74b4d2c aurel32
            if (fn11 == 0x2AC || fn11 == 0x6AC) {
1578 4c9649a9 j_mayer
                /* CVTST */
1579 a7812ae4 pbrook
                gen_fcvtst(rb, rc);
1580 4c9649a9 j_mayer
            } else {
1581 4c9649a9 j_mayer
                /* CVTTS */
1582 a7812ae4 pbrook
                gen_fcvtts(rb, rc);
1583 4c9649a9 j_mayer
            }
1584 4c9649a9 j_mayer
            break;
1585 4c9649a9 j_mayer
        case 0x2F:
1586 4c9649a9 j_mayer
            /* CVTTQ */
1587 a7812ae4 pbrook
            gen_fcvttq(rb, rc);
1588 4c9649a9 j_mayer
            break;
1589 4c9649a9 j_mayer
        case 0x3C:
1590 4c9649a9 j_mayer
            /* CVTQS */
1591 a7812ae4 pbrook
            gen_fcvtqs(rb, rc);
1592 4c9649a9 j_mayer
            break;
1593 4c9649a9 j_mayer
        case 0x3E:
1594 4c9649a9 j_mayer
            /* CVTQT */
1595 a7812ae4 pbrook
            gen_fcvtqt(rb, rc);
1596 4c9649a9 j_mayer
            break;
1597 4c9649a9 j_mayer
        default:
1598 4c9649a9 j_mayer
            goto invalid_opc;
1599 4c9649a9 j_mayer
        }
1600 4c9649a9 j_mayer
        break;
1601 4c9649a9 j_mayer
    case 0x17:
1602 4c9649a9 j_mayer
        switch (fn11) {
1603 4c9649a9 j_mayer
        case 0x010:
1604 4c9649a9 j_mayer
            /* CVTLQ */
1605 a7812ae4 pbrook
            gen_fcvtlq(rb, rc);
1606 4c9649a9 j_mayer
            break;
1607 4c9649a9 j_mayer
        case 0x020:
1608 f18cd223 aurel32
            if (likely(rc != 31)) {
1609 f18cd223 aurel32
                if (ra == rb)
1610 4c9649a9 j_mayer
                    /* FMOV */
1611 f18cd223 aurel32
                    tcg_gen_mov_i64(cpu_fir[rc], cpu_fir[ra]);
1612 f18cd223 aurel32
                else
1613 f18cd223 aurel32
                    /* CPYS */
1614 a7812ae4 pbrook
                    gen_fcpys(ra, rb, rc);
1615 4c9649a9 j_mayer
            }
1616 4c9649a9 j_mayer
            break;
1617 4c9649a9 j_mayer
        case 0x021:
1618 4c9649a9 j_mayer
            /* CPYSN */
1619 a7812ae4 pbrook
            gen_fcpysn(ra, rb, rc);
1620 4c9649a9 j_mayer
            break;
1621 4c9649a9 j_mayer
        case 0x022:
1622 4c9649a9 j_mayer
            /* CPYSE */
1623 a7812ae4 pbrook
            gen_fcpyse(ra, rb, rc);
1624 4c9649a9 j_mayer
            break;
1625 4c9649a9 j_mayer
        case 0x024:
1626 4c9649a9 j_mayer
            /* MT_FPCR */
1627 f18cd223 aurel32
            if (likely(ra != 31))
1628 a7812ae4 pbrook
                gen_helper_store_fpcr(cpu_fir[ra]);
1629 f18cd223 aurel32
            else {
1630 f18cd223 aurel32
                TCGv tmp = tcg_const_i64(0);
1631 a7812ae4 pbrook
                gen_helper_store_fpcr(tmp);
1632 f18cd223 aurel32
                tcg_temp_free(tmp);
1633 f18cd223 aurel32
            }
1634 4c9649a9 j_mayer
            break;
1635 4c9649a9 j_mayer
        case 0x025:
1636 4c9649a9 j_mayer
            /* MF_FPCR */
1637 f18cd223 aurel32
            if (likely(ra != 31))
1638 a7812ae4 pbrook
                gen_helper_load_fpcr(cpu_fir[ra]);
1639 4c9649a9 j_mayer
            break;
1640 4c9649a9 j_mayer
        case 0x02A:
1641 4c9649a9 j_mayer
            /* FCMOVEQ */
1642 a7812ae4 pbrook
            gen_fcmpfeq(ra, rb, rc);
1643 4c9649a9 j_mayer
            break;
1644 4c9649a9 j_mayer
        case 0x02B:
1645 4c9649a9 j_mayer
            /* FCMOVNE */
1646 a7812ae4 pbrook
            gen_fcmpfne(ra, rb, rc);
1647 4c9649a9 j_mayer
            break;
1648 4c9649a9 j_mayer
        case 0x02C:
1649 4c9649a9 j_mayer
            /* FCMOVLT */
1650 a7812ae4 pbrook
            gen_fcmpflt(ra, rb, rc);
1651 4c9649a9 j_mayer
            break;
1652 4c9649a9 j_mayer
        case 0x02D:
1653 4c9649a9 j_mayer
            /* FCMOVGE */
1654 a7812ae4 pbrook
            gen_fcmpfge(ra, rb, rc);
1655 4c9649a9 j_mayer
            break;
1656 4c9649a9 j_mayer
        case 0x02E:
1657 4c9649a9 j_mayer
            /* FCMOVLE */
1658 a7812ae4 pbrook
            gen_fcmpfle(ra, rb, rc);
1659 4c9649a9 j_mayer
            break;
1660 4c9649a9 j_mayer
        case 0x02F:
1661 4c9649a9 j_mayer
            /* FCMOVGT */
1662 a7812ae4 pbrook
            gen_fcmpfgt(ra, rb, rc);
1663 4c9649a9 j_mayer
            break;
1664 4c9649a9 j_mayer
        case 0x030:
1665 4c9649a9 j_mayer
            /* CVTQL */
1666 a7812ae4 pbrook
            gen_fcvtql(rb, rc);
1667 4c9649a9 j_mayer
            break;
1668 4c9649a9 j_mayer
        case 0x130:
1669 4c9649a9 j_mayer
            /* CVTQL/V */
1670 a7812ae4 pbrook
            gen_fcvtqlv(rb, rc);
1671 4c9649a9 j_mayer
            break;
1672 4c9649a9 j_mayer
        case 0x530:
1673 4c9649a9 j_mayer
            /* CVTQL/SV */
1674 a7812ae4 pbrook
            gen_fcvtqlsv(rb, rc);
1675 4c9649a9 j_mayer
            break;
1676 4c9649a9 j_mayer
        default:
1677 4c9649a9 j_mayer
            goto invalid_opc;
1678 4c9649a9 j_mayer
        }
1679 4c9649a9 j_mayer
        break;
1680 4c9649a9 j_mayer
    case 0x18:
1681 4c9649a9 j_mayer
        switch ((uint16_t)disp16) {
1682 4c9649a9 j_mayer
        case 0x0000:
1683 4c9649a9 j_mayer
            /* TRAPB */
1684 4c9649a9 j_mayer
            /* No-op. Just exit from the current tb */
1685 4c9649a9 j_mayer
            ret = 2;
1686 4c9649a9 j_mayer
            break;
1687 4c9649a9 j_mayer
        case 0x0400:
1688 4c9649a9 j_mayer
            /* EXCB */
1689 4c9649a9 j_mayer
            /* No-op. Just exit from the current tb */
1690 4c9649a9 j_mayer
            ret = 2;
1691 4c9649a9 j_mayer
            break;
1692 4c9649a9 j_mayer
        case 0x4000:
1693 4c9649a9 j_mayer
            /* MB */
1694 4c9649a9 j_mayer
            /* No-op */
1695 4c9649a9 j_mayer
            break;
1696 4c9649a9 j_mayer
        case 0x4400:
1697 4c9649a9 j_mayer
            /* WMB */
1698 4c9649a9 j_mayer
            /* No-op */
1699 4c9649a9 j_mayer
            break;
1700 4c9649a9 j_mayer
        case 0x8000:
1701 4c9649a9 j_mayer
            /* FETCH */
1702 4c9649a9 j_mayer
            /* No-op */
1703 4c9649a9 j_mayer
            break;
1704 4c9649a9 j_mayer
        case 0xA000:
1705 4c9649a9 j_mayer
            /* FETCH_M */
1706 4c9649a9 j_mayer
            /* No-op */
1707 4c9649a9 j_mayer
            break;
1708 4c9649a9 j_mayer
        case 0xC000:
1709 4c9649a9 j_mayer
            /* RPCC */
1710 3761035f aurel32
            if (ra != 31)
1711 a7812ae4 pbrook
                gen_helper_load_pcc(cpu_ir[ra]);
1712 4c9649a9 j_mayer
            break;
1713 4c9649a9 j_mayer
        case 0xE000:
1714 4c9649a9 j_mayer
            /* RC */
1715 3761035f aurel32
            if (ra != 31)
1716 a7812ae4 pbrook
                gen_helper_rc(cpu_ir[ra]);
1717 4c9649a9 j_mayer
            break;
1718 4c9649a9 j_mayer
        case 0xE800:
1719 4c9649a9 j_mayer
            /* ECB */
1720 4c9649a9 j_mayer
            /* XXX: TODO: evict tb cache at address rb */
1721 4c9649a9 j_mayer
#if 0
1722 4c9649a9 j_mayer
            ret = 2;
1723 4c9649a9 j_mayer
#else
1724 4c9649a9 j_mayer
            goto invalid_opc;
1725 4c9649a9 j_mayer
#endif
1726 4c9649a9 j_mayer
            break;
1727 4c9649a9 j_mayer
        case 0xF000:
1728 4c9649a9 j_mayer
            /* RS */
1729 3761035f aurel32
            if (ra != 31)
1730 a7812ae4 pbrook
                gen_helper_rs(cpu_ir[ra]);
1731 4c9649a9 j_mayer
            break;
1732 4c9649a9 j_mayer
        case 0xF800:
1733 4c9649a9 j_mayer
            /* WH64 */
1734 4c9649a9 j_mayer
            /* No-op */
1735 4c9649a9 j_mayer
            break;
1736 4c9649a9 j_mayer
        default:
1737 4c9649a9 j_mayer
            goto invalid_opc;
1738 4c9649a9 j_mayer
        }
1739 4c9649a9 j_mayer
        break;
1740 4c9649a9 j_mayer
    case 0x19:
1741 4c9649a9 j_mayer
        /* HW_MFPR (PALcode) */
1742 4c9649a9 j_mayer
#if defined (CONFIG_USER_ONLY)
1743 4c9649a9 j_mayer
        goto invalid_opc;
1744 4c9649a9 j_mayer
#else
1745 4c9649a9 j_mayer
        if (!ctx->pal_mode)
1746 4c9649a9 j_mayer
            goto invalid_opc;
1747 8bb6e981 aurel32
        if (ra != 31) {
1748 8bb6e981 aurel32
            TCGv tmp = tcg_const_i32(insn & 0xFF);
1749 a7812ae4 pbrook
            gen_helper_mfpr(cpu_ir[ra], tmp, cpu_ir[ra]);
1750 8bb6e981 aurel32
            tcg_temp_free(tmp);
1751 8bb6e981 aurel32
        }
1752 4c9649a9 j_mayer
        break;
1753 4c9649a9 j_mayer
#endif
1754 4c9649a9 j_mayer
    case 0x1A:
1755 3761035f aurel32
        if (rb != 31)
1756 3761035f aurel32
            tcg_gen_andi_i64(cpu_pc, cpu_ir[rb], ~3);
1757 3761035f aurel32
        else
1758 3761035f aurel32
            tcg_gen_movi_i64(cpu_pc, 0);
1759 1304ca87 aurel32
        if (ra != 31)
1760 1304ca87 aurel32
            tcg_gen_movi_i64(cpu_ir[ra], ctx->pc);
1761 4c9649a9 j_mayer
        /* Those four jumps only differ by the branch prediction hint */
1762 4c9649a9 j_mayer
        switch (fn2) {
1763 4c9649a9 j_mayer
        case 0x0:
1764 4c9649a9 j_mayer
            /* JMP */
1765 4c9649a9 j_mayer
            break;
1766 4c9649a9 j_mayer
        case 0x1:
1767 4c9649a9 j_mayer
            /* JSR */
1768 4c9649a9 j_mayer
            break;
1769 4c9649a9 j_mayer
        case 0x2:
1770 4c9649a9 j_mayer
            /* RET */
1771 4c9649a9 j_mayer
            break;
1772 4c9649a9 j_mayer
        case 0x3:
1773 4c9649a9 j_mayer
            /* JSR_COROUTINE */
1774 4c9649a9 j_mayer
            break;
1775 4c9649a9 j_mayer
        }
1776 4c9649a9 j_mayer
        ret = 1;
1777 4c9649a9 j_mayer
        break;
1778 4c9649a9 j_mayer
    case 0x1B:
1779 4c9649a9 j_mayer
        /* HW_LD (PALcode) */
1780 4c9649a9 j_mayer
#if defined (CONFIG_USER_ONLY)
1781 4c9649a9 j_mayer
        goto invalid_opc;
1782 4c9649a9 j_mayer
#else
1783 4c9649a9 j_mayer
        if (!ctx->pal_mode)
1784 4c9649a9 j_mayer
            goto invalid_opc;
1785 8bb6e981 aurel32
        if (ra != 31) {
1786 a7812ae4 pbrook
            TCGv addr = tcg_temp_new();
1787 8bb6e981 aurel32
            if (rb != 31)
1788 8bb6e981 aurel32
                tcg_gen_addi_i64(addr, cpu_ir[rb], disp12);
1789 8bb6e981 aurel32
            else
1790 8bb6e981 aurel32
                tcg_gen_movi_i64(addr, disp12);
1791 8bb6e981 aurel32
            switch ((insn >> 12) & 0xF) {
1792 8bb6e981 aurel32
            case 0x0:
1793 8bb6e981 aurel32
                /* Longword physical access */
1794 a7812ae4 pbrook
                gen_helper_ldl_raw(cpu_ir[ra], addr);
1795 8bb6e981 aurel32
                break;
1796 8bb6e981 aurel32
            case 0x1:
1797 8bb6e981 aurel32
                /* Quadword physical access */
1798 a7812ae4 pbrook
                gen_helper_ldq_raw(cpu_ir[ra], addr);
1799 8bb6e981 aurel32
                break;
1800 8bb6e981 aurel32
            case 0x2:
1801 8bb6e981 aurel32
                /* Longword physical access with lock */
1802 a7812ae4 pbrook
                gen_helper_ldl_l_raw(cpu_ir[ra], addr);
1803 8bb6e981 aurel32
                break;
1804 8bb6e981 aurel32
            case 0x3:
1805 8bb6e981 aurel32
                /* Quadword physical access with lock */
1806 a7812ae4 pbrook
                gen_helper_ldq_l_raw(cpu_ir[ra], addr);
1807 8bb6e981 aurel32
                break;
1808 8bb6e981 aurel32
            case 0x4:
1809 8bb6e981 aurel32
                /* Longword virtual PTE fetch */
1810 a7812ae4 pbrook
                gen_helper_ldl_kernel(cpu_ir[ra], addr);
1811 8bb6e981 aurel32
                break;
1812 8bb6e981 aurel32
            case 0x5:
1813 8bb6e981 aurel32
                /* Quadword virtual PTE fetch */
1814 a7812ae4 pbrook
                gen_helper_ldq_kernel(cpu_ir[ra], addr);
1815 8bb6e981 aurel32
                break;
1816 8bb6e981 aurel32
            case 0x6:
1817 8bb6e981 aurel32
                /* Incpu_ir[ra]id */
1818 8bb6e981 aurel32
                goto incpu_ir[ra]id_opc;
1819 8bb6e981 aurel32
            case 0x7:
1820 8bb6e981 aurel32
                /* Incpu_ir[ra]id */
1821 8bb6e981 aurel32
                goto incpu_ir[ra]id_opc;
1822 8bb6e981 aurel32
            case 0x8:
1823 8bb6e981 aurel32
                /* Longword virtual access */
1824 a7812ae4 pbrook
                gen_helper_st_virt_to_phys(addr, addr);
1825 a7812ae4 pbrook
                gen_helper_ldl_raw(cpu_ir[ra], addr);
1826 8bb6e981 aurel32
                break;
1827 8bb6e981 aurel32
            case 0x9:
1828 8bb6e981 aurel32
                /* Quadword virtual access */
1829 a7812ae4 pbrook
                gen_helper_st_virt_to_phys(addr, addr);
1830 a7812ae4 pbrook
                gen_helper_ldq_raw(cpu_ir[ra], addr);
1831 8bb6e981 aurel32
                break;
1832 8bb6e981 aurel32
            case 0xA:
1833 8bb6e981 aurel32
                /* Longword virtual access with protection check */
1834 8bb6e981 aurel32
                tcg_gen_qemu_ld32s(cpu_ir[ra], addr, ctx->flags);
1835 8bb6e981 aurel32
                break;
1836 8bb6e981 aurel32
            case 0xB:
1837 8bb6e981 aurel32
                /* Quadword virtual access with protection check */
1838 8bb6e981 aurel32
                tcg_gen_qemu_ld64(cpu_ir[ra], addr, ctx->flags);
1839 8bb6e981 aurel32
                break;
1840 8bb6e981 aurel32
            case 0xC:
1841 8bb6e981 aurel32
                /* Longword virtual access with altenate access mode */
1842 a7812ae4 pbrook
                gen_helper_set_alt_mode();
1843 a7812ae4 pbrook
                gen_helper_st_virt_to_phys(addr, addr);
1844 a7812ae4 pbrook
                gen_helper_ldl_raw(cpu_ir[ra], addr);
1845 a7812ae4 pbrook
                gen_helper_restore_mode();
1846 8bb6e981 aurel32
                break;
1847 8bb6e981 aurel32
            case 0xD:
1848 8bb6e981 aurel32
                /* Quadword virtual access with altenate access mode */
1849 a7812ae4 pbrook
                gen_helper_set_alt_mode();
1850 a7812ae4 pbrook
                gen_helper_st_virt_to_phys(addr, addr);
1851 a7812ae4 pbrook
                gen_helper_ldq_raw(cpu_ir[ra], addr);
1852 a7812ae4 pbrook
                gen_helper_restore_mode();
1853 8bb6e981 aurel32
                break;
1854 8bb6e981 aurel32
            case 0xE:
1855 8bb6e981 aurel32
                /* Longword virtual access with alternate access mode and
1856 8bb6e981 aurel32
                 * protection checks
1857 8bb6e981 aurel32
                 */
1858 a7812ae4 pbrook
                gen_helper_set_alt_mode();
1859 a7812ae4 pbrook
                gen_helper_ldl_data(cpu_ir[ra], addr);
1860 a7812ae4 pbrook
                gen_helper_restore_mode();
1861 8bb6e981 aurel32
                break;
1862 8bb6e981 aurel32
            case 0xF:
1863 8bb6e981 aurel32
                /* Quadword virtual access with alternate access mode and
1864 8bb6e981 aurel32
                 * protection checks
1865 8bb6e981 aurel32
                 */
1866 a7812ae4 pbrook
                gen_helper_set_alt_mode();
1867 a7812ae4 pbrook
                gen_helper_ldq_data(cpu_ir[ra], addr);
1868 a7812ae4 pbrook
                gen_helper_restore_mode();
1869 8bb6e981 aurel32
                break;
1870 8bb6e981 aurel32
            }
1871 8bb6e981 aurel32
            tcg_temp_free(addr);
1872 4c9649a9 j_mayer
        }
1873 4c9649a9 j_mayer
        break;
1874 4c9649a9 j_mayer
#endif
1875 4c9649a9 j_mayer
    case 0x1C:
1876 4c9649a9 j_mayer
        switch (fn7) {
1877 4c9649a9 j_mayer
        case 0x00:
1878 4c9649a9 j_mayer
            /* SEXTB */
1879 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_BWX))
1880 4c9649a9 j_mayer
                goto invalid_opc;
1881 ae8ecd42 aurel32
            if (likely(rc != 31)) {
1882 ae8ecd42 aurel32
                if (islit)
1883 ae8ecd42 aurel32
                    tcg_gen_movi_i64(cpu_ir[rc], (int64_t)((int8_t)lit));
1884 ae8ecd42 aurel32
                else
1885 dfaa8583 aurel32
                    tcg_gen_ext8s_i64(cpu_ir[rc], cpu_ir[rb]);
1886 ae8ecd42 aurel32
            }
1887 4c9649a9 j_mayer
            break;
1888 4c9649a9 j_mayer
        case 0x01:
1889 4c9649a9 j_mayer
            /* SEXTW */
1890 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_BWX))
1891 4c9649a9 j_mayer
                goto invalid_opc;
1892 ae8ecd42 aurel32
            if (likely(rc != 31)) {
1893 ae8ecd42 aurel32
                if (islit)
1894 ae8ecd42 aurel32
                    tcg_gen_movi_i64(cpu_ir[rc], (int64_t)((int16_t)lit));
1895 ae8ecd42 aurel32
                else
1896 dfaa8583 aurel32
                    tcg_gen_ext16s_i64(cpu_ir[rc], cpu_ir[rb]);
1897 ae8ecd42 aurel32
            }
1898 4c9649a9 j_mayer
            break;
1899 4c9649a9 j_mayer
        case 0x30:
1900 4c9649a9 j_mayer
            /* CTPOP */
1901 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_CIX))
1902 4c9649a9 j_mayer
                goto invalid_opc;
1903 ae8ecd42 aurel32
            if (likely(rc != 31)) {
1904 ae8ecd42 aurel32
                if (islit)
1905 ae8ecd42 aurel32
                    tcg_gen_movi_i64(cpu_ir[rc], ctpop64(lit));
1906 ae8ecd42 aurel32
                else
1907 a7812ae4 pbrook
                    gen_helper_ctpop(cpu_ir[rc], cpu_ir[rb]);
1908 ae8ecd42 aurel32
            }
1909 4c9649a9 j_mayer
            break;
1910 4c9649a9 j_mayer
        case 0x31:
1911 4c9649a9 j_mayer
            /* PERR */
1912 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_MVI))
1913 4c9649a9 j_mayer
                goto invalid_opc;
1914 4c9649a9 j_mayer
            /* XXX: TODO */
1915 4c9649a9 j_mayer
            goto invalid_opc;
1916 4c9649a9 j_mayer
            break;
1917 4c9649a9 j_mayer
        case 0x32:
1918 4c9649a9 j_mayer
            /* CTLZ */
1919 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_CIX))
1920 4c9649a9 j_mayer
                goto invalid_opc;
1921 ae8ecd42 aurel32
            if (likely(rc != 31)) {
1922 ae8ecd42 aurel32
                if (islit)
1923 ae8ecd42 aurel32
                    tcg_gen_movi_i64(cpu_ir[rc], clz64(lit));
1924 ae8ecd42 aurel32
                else
1925 a7812ae4 pbrook
                    gen_helper_ctlz(cpu_ir[rc], cpu_ir[rb]);
1926 ae8ecd42 aurel32
            }
1927 4c9649a9 j_mayer
            break;
1928 4c9649a9 j_mayer
        case 0x33:
1929 4c9649a9 j_mayer
            /* CTTZ */
1930 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_CIX))
1931 4c9649a9 j_mayer
                goto invalid_opc;
1932 ae8ecd42 aurel32
            if (likely(rc != 31)) {
1933 ae8ecd42 aurel32
                if (islit)
1934 ae8ecd42 aurel32
                    tcg_gen_movi_i64(cpu_ir[rc], ctz64(lit));
1935 ae8ecd42 aurel32
                else
1936 a7812ae4 pbrook
                    gen_helper_cttz(cpu_ir[rc], cpu_ir[rb]);
1937 ae8ecd42 aurel32
            }
1938 4c9649a9 j_mayer
            break;
1939 4c9649a9 j_mayer
        case 0x34:
1940 4c9649a9 j_mayer
            /* UNPKBW */
1941 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_MVI))
1942 4c9649a9 j_mayer
                goto invalid_opc;
1943 4c9649a9 j_mayer
            /* XXX: TODO */
1944 4c9649a9 j_mayer
            goto invalid_opc;
1945 4c9649a9 j_mayer
            break;
1946 4c9649a9 j_mayer
        case 0x35:
1947 4c9649a9 j_mayer
            /* UNPKWL */
1948 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_MVI))
1949 4c9649a9 j_mayer
                goto invalid_opc;
1950 4c9649a9 j_mayer
            /* XXX: TODO */
1951 4c9649a9 j_mayer
            goto invalid_opc;
1952 4c9649a9 j_mayer
            break;
1953 4c9649a9 j_mayer
        case 0x36:
1954 4c9649a9 j_mayer
            /* PKWB */
1955 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_MVI))
1956 4c9649a9 j_mayer
                goto invalid_opc;
1957 4c9649a9 j_mayer
            /* XXX: TODO */
1958 4c9649a9 j_mayer
            goto invalid_opc;
1959 4c9649a9 j_mayer
            break;
1960 4c9649a9 j_mayer
        case 0x37:
1961 4c9649a9 j_mayer
            /* PKLB */
1962 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_MVI))
1963 4c9649a9 j_mayer
                goto invalid_opc;
1964 4c9649a9 j_mayer
            /* XXX: TODO */
1965 4c9649a9 j_mayer
            goto invalid_opc;
1966 4c9649a9 j_mayer
            break;
1967 4c9649a9 j_mayer
        case 0x38:
1968 4c9649a9 j_mayer
            /* MINSB8 */
1969 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_MVI))
1970 4c9649a9 j_mayer
                goto invalid_opc;
1971 4c9649a9 j_mayer
            /* XXX: TODO */
1972 4c9649a9 j_mayer
            goto invalid_opc;
1973 4c9649a9 j_mayer
            break;
1974 4c9649a9 j_mayer
        case 0x39:
1975 4c9649a9 j_mayer
            /* MINSW4 */
1976 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_MVI))
1977 4c9649a9 j_mayer
                goto invalid_opc;
1978 4c9649a9 j_mayer
            /* XXX: TODO */
1979 4c9649a9 j_mayer
            goto invalid_opc;
1980 4c9649a9 j_mayer
            break;
1981 4c9649a9 j_mayer
        case 0x3A:
1982 4c9649a9 j_mayer
            /* MINUB8 */
1983 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_MVI))
1984 4c9649a9 j_mayer
                goto invalid_opc;
1985 4c9649a9 j_mayer
            /* XXX: TODO */
1986 4c9649a9 j_mayer
            goto invalid_opc;
1987 4c9649a9 j_mayer
            break;
1988 4c9649a9 j_mayer
        case 0x3B:
1989 4c9649a9 j_mayer
            /* MINUW4 */
1990 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_MVI))
1991 4c9649a9 j_mayer
                goto invalid_opc;
1992 4c9649a9 j_mayer
            /* XXX: TODO */
1993 4c9649a9 j_mayer
            goto invalid_opc;
1994 4c9649a9 j_mayer
            break;
1995 4c9649a9 j_mayer
        case 0x3C:
1996 4c9649a9 j_mayer
            /* MAXUB8 */
1997 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_MVI))
1998 4c9649a9 j_mayer
                goto invalid_opc;
1999 4c9649a9 j_mayer
            /* XXX: TODO */
2000 4c9649a9 j_mayer
            goto invalid_opc;
2001 4c9649a9 j_mayer
            break;
2002 4c9649a9 j_mayer
        case 0x3D:
2003 4c9649a9 j_mayer
            /* MAXUW4 */
2004 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_MVI))
2005 4c9649a9 j_mayer
                goto invalid_opc;
2006 4c9649a9 j_mayer
            /* XXX: TODO */
2007 4c9649a9 j_mayer
            goto invalid_opc;
2008 4c9649a9 j_mayer
            break;
2009 4c9649a9 j_mayer
        case 0x3E:
2010 4c9649a9 j_mayer
            /* MAXSB8 */
2011 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_MVI))
2012 4c9649a9 j_mayer
                goto invalid_opc;
2013 4c9649a9 j_mayer
            /* XXX: TODO */
2014 4c9649a9 j_mayer
            goto invalid_opc;
2015 4c9649a9 j_mayer
            break;
2016 4c9649a9 j_mayer
        case 0x3F:
2017 4c9649a9 j_mayer
            /* MAXSW4 */
2018 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_MVI))
2019 4c9649a9 j_mayer
                goto invalid_opc;
2020 4c9649a9 j_mayer
            /* XXX: TODO */
2021 4c9649a9 j_mayer
            goto invalid_opc;
2022 4c9649a9 j_mayer
            break;
2023 4c9649a9 j_mayer
        case 0x70:
2024 4c9649a9 j_mayer
            /* FTOIT */
2025 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_FIX))
2026 4c9649a9 j_mayer
                goto invalid_opc;
2027 f18cd223 aurel32
            if (likely(rc != 31)) {
2028 f18cd223 aurel32
                if (ra != 31)
2029 f18cd223 aurel32
                    tcg_gen_mov_i64(cpu_ir[rc], cpu_fir[ra]);
2030 f18cd223 aurel32
                else
2031 f18cd223 aurel32
                    tcg_gen_movi_i64(cpu_ir[rc], 0);
2032 f18cd223 aurel32
            }
2033 4c9649a9 j_mayer
            break;
2034 4c9649a9 j_mayer
        case 0x78:
2035 4c9649a9 j_mayer
            /* FTOIS */
2036 4c9649a9 j_mayer
            if (!(ctx->amask & AMASK_FIX))
2037 4c9649a9 j_mayer
                goto invalid_opc;
2038 f18cd223 aurel32
            if (rc != 31) {
2039 a7812ae4 pbrook
                TCGv_i32 tmp1 = tcg_temp_new_i32();
2040 f18cd223 aurel32
                if (ra != 31)
2041 a7812ae4 pbrook
                    gen_helper_s_to_memory(tmp1, cpu_fir[ra]);
2042 f18cd223 aurel32
                else {
2043 f18cd223 aurel32
                    TCGv tmp2 = tcg_const_i64(0);
2044 a7812ae4 pbrook
                    gen_helper_s_to_memory(tmp1, tmp2);
2045 f18cd223 aurel32
                    tcg_temp_free(tmp2);
2046 f18cd223 aurel32
                }
2047 f18cd223 aurel32
                tcg_gen_ext_i32_i64(cpu_ir[rc], tmp1);
2048 a7812ae4 pbrook
                tcg_temp_free_i32(tmp1);
2049 f18cd223 aurel32
            }
2050 4c9649a9 j_mayer
            break;
2051 4c9649a9 j_mayer
        default:
2052 4c9649a9 j_mayer
            goto invalid_opc;
2053 4c9649a9 j_mayer
        }
2054 4c9649a9 j_mayer
        break;
2055 4c9649a9 j_mayer
    case 0x1D:
2056 4c9649a9 j_mayer
        /* HW_MTPR (PALcode) */
2057 4c9649a9 j_mayer
#if defined (CONFIG_USER_ONLY)
2058 4c9649a9 j_mayer
        goto invalid_opc;
2059 4c9649a9 j_mayer
#else
2060 4c9649a9 j_mayer
        if (!ctx->pal_mode)
2061 4c9649a9 j_mayer
            goto invalid_opc;
2062 8bb6e981 aurel32
        else {
2063 8bb6e981 aurel32
            TCGv tmp1 = tcg_const_i32(insn & 0xFF);
2064 8bb6e981 aurel32
            if (ra != 31)
2065 a7812ae4 pbrook
                gen_helper_mtpr(tmp1, cpu_ir[ra]);
2066 8bb6e981 aurel32
            else {
2067 8bb6e981 aurel32
                TCGv tmp2 = tcg_const_i64(0);
2068 a7812ae4 pbrook
                gen_helper_mtpr(tmp1, tmp2);
2069 8bb6e981 aurel32
                tcg_temp_free(tmp2);
2070 8bb6e981 aurel32
            }
2071 8bb6e981 aurel32
            tcg_temp_free(tmp1);
2072 8bb6e981 aurel32
            ret = 2;
2073 8bb6e981 aurel32
        }
2074 4c9649a9 j_mayer
        break;
2075 4c9649a9 j_mayer
#endif
2076 4c9649a9 j_mayer
    case 0x1E:
2077 4c9649a9 j_mayer
        /* HW_REI (PALcode) */
2078 4c9649a9 j_mayer
#if defined (CONFIG_USER_ONLY)
2079 4c9649a9 j_mayer
        goto invalid_opc;
2080 4c9649a9 j_mayer
#else
2081 4c9649a9 j_mayer
        if (!ctx->pal_mode)
2082 4c9649a9 j_mayer
            goto invalid_opc;
2083 4c9649a9 j_mayer
        if (rb == 31) {
2084 4c9649a9 j_mayer
            /* "Old" alpha */
2085 a7812ae4 pbrook
            gen_helper_hw_rei();
2086 4c9649a9 j_mayer
        } else {
2087 8bb6e981 aurel32
            TCGv tmp;
2088 8bb6e981 aurel32
2089 8bb6e981 aurel32
            if (ra != 31) {
2090 a7812ae4 pbrook
                tmp = tcg_temp_new();
2091 8bb6e981 aurel32
                tcg_gen_addi_i64(tmp, cpu_ir[rb], (((int64_t)insn << 51) >> 51));
2092 8bb6e981 aurel32
            } else
2093 8bb6e981 aurel32
                tmp = tcg_const_i64(((int64_t)insn << 51) >> 51);
2094 a7812ae4 pbrook
            gen_helper_hw_ret(tmp);
2095 8bb6e981 aurel32
            tcg_temp_free(tmp);
2096 4c9649a9 j_mayer
        }
2097 4c9649a9 j_mayer
        ret = 2;
2098 4c9649a9 j_mayer
        break;
2099 4c9649a9 j_mayer
#endif
2100 4c9649a9 j_mayer
    case 0x1F:
2101 4c9649a9 j_mayer
        /* HW_ST (PALcode) */
2102 4c9649a9 j_mayer
#if defined (CONFIG_USER_ONLY)
2103 4c9649a9 j_mayer
        goto invalid_opc;
2104 4c9649a9 j_mayer
#else
2105 4c9649a9 j_mayer
        if (!ctx->pal_mode)
2106 4c9649a9 j_mayer
            goto invalid_opc;
2107 8bb6e981 aurel32
        else {
2108 8bb6e981 aurel32
            TCGv addr, val;
2109 a7812ae4 pbrook
            addr = tcg_temp_new();
2110 8bb6e981 aurel32
            if (rb != 31)
2111 8bb6e981 aurel32
                tcg_gen_addi_i64(addr, cpu_ir[rb], disp12);
2112 8bb6e981 aurel32
            else
2113 8bb6e981 aurel32
                tcg_gen_movi_i64(addr, disp12);
2114 8bb6e981 aurel32
            if (ra != 31)
2115 8bb6e981 aurel32
                val = cpu_ir[ra];
2116 8bb6e981 aurel32
            else {
2117 a7812ae4 pbrook
                val = tcg_temp_new();
2118 8bb6e981 aurel32
                tcg_gen_movi_i64(val, 0);
2119 8bb6e981 aurel32
            }
2120 8bb6e981 aurel32
            switch ((insn >> 12) & 0xF) {
2121 8bb6e981 aurel32
            case 0x0:
2122 8bb6e981 aurel32
                /* Longword physical access */
2123 a7812ae4 pbrook
                gen_helper_stl_raw(val, addr);
2124 8bb6e981 aurel32
                break;
2125 8bb6e981 aurel32
            case 0x1:
2126 8bb6e981 aurel32
                /* Quadword physical access */
2127 a7812ae4 pbrook
                gen_helper_stq_raw(val, addr);
2128 8bb6e981 aurel32
                break;
2129 8bb6e981 aurel32
            case 0x2:
2130 8bb6e981 aurel32
                /* Longword physical access with lock */
2131 a7812ae4 pbrook
                gen_helper_stl_c_raw(val, val, addr);
2132 8bb6e981 aurel32
                break;
2133 8bb6e981 aurel32
            case 0x3:
2134 8bb6e981 aurel32
                /* Quadword physical access with lock */
2135 a7812ae4 pbrook
                gen_helper_stq_c_raw(val, val, addr);
2136 8bb6e981 aurel32
                break;
2137 8bb6e981 aurel32
            case 0x4:
2138 8bb6e981 aurel32
                /* Longword virtual access */
2139 a7812ae4 pbrook
                gen_helper_st_virt_to_phys(addr, addr);
2140 a7812ae4 pbrook
                gen_helper_stl_raw(val, addr);
2141 8bb6e981 aurel32
                break;
2142 8bb6e981 aurel32
            case 0x5:
2143 8bb6e981 aurel32
                /* Quadword virtual access */
2144 a7812ae4 pbrook
                gen_helper_st_virt_to_phys(addr, addr);
2145 a7812ae4 pbrook
                gen_helper_stq_raw(val, addr);
2146 8bb6e981 aurel32
                break;
2147 8bb6e981 aurel32
            case 0x6:
2148 8bb6e981 aurel32
                /* Invalid */
2149 8bb6e981 aurel32
                goto invalid_opc;
2150 8bb6e981 aurel32
            case 0x7:
2151 8bb6e981 aurel32
                /* Invalid */
2152 8bb6e981 aurel32
                goto invalid_opc;
2153 8bb6e981 aurel32
            case 0x8:
2154 8bb6e981 aurel32
                /* Invalid */
2155 8bb6e981 aurel32
                goto invalid_opc;
2156 8bb6e981 aurel32
            case 0x9:
2157 8bb6e981 aurel32
                /* Invalid */
2158 8bb6e981 aurel32
                goto invalid_opc;
2159 8bb6e981 aurel32
            case 0xA:
2160 8bb6e981 aurel32
                /* Invalid */
2161 8bb6e981 aurel32
                goto invalid_opc;
2162 8bb6e981 aurel32
            case 0xB:
2163 8bb6e981 aurel32
                /* Invalid */
2164 8bb6e981 aurel32
                goto invalid_opc;
2165 8bb6e981 aurel32
            case 0xC:
2166 8bb6e981 aurel32
                /* Longword virtual access with alternate access mode */
2167 a7812ae4 pbrook
                gen_helper_set_alt_mode();
2168 a7812ae4 pbrook
                gen_helper_st_virt_to_phys(addr, addr);
2169 a7812ae4 pbrook
                gen_helper_stl_raw(val, addr);
2170 a7812ae4 pbrook
                gen_helper_restore_mode();
2171 8bb6e981 aurel32
                break;
2172 8bb6e981 aurel32
            case 0xD:
2173 8bb6e981 aurel32
                /* Quadword virtual access with alternate access mode */
2174 a7812ae4 pbrook
                gen_helper_set_alt_mode();
2175 a7812ae4 pbrook
                gen_helper_st_virt_to_phys(addr, addr);
2176 a7812ae4 pbrook
                gen_helper_stl_raw(val, addr);
2177 a7812ae4 pbrook
                gen_helper_restore_mode();
2178 8bb6e981 aurel32
                break;
2179 8bb6e981 aurel32
            case 0xE:
2180 8bb6e981 aurel32
                /* Invalid */
2181 8bb6e981 aurel32
                goto invalid_opc;
2182 8bb6e981 aurel32
            case 0xF:
2183 8bb6e981 aurel32
                /* Invalid */
2184 8bb6e981 aurel32
                goto invalid_opc;
2185 8bb6e981 aurel32
            }
2186 8bb6e981 aurel32
            if (ra != 31)
2187 8bb6e981 aurel32
                tcg_temp_free(val);
2188 8bb6e981 aurel32
            tcg_temp_free(addr);
2189 4c9649a9 j_mayer
        }
2190 4c9649a9 j_mayer
        ret = 2;
2191 4c9649a9 j_mayer
        break;
2192 4c9649a9 j_mayer
#endif
2193 4c9649a9 j_mayer
    case 0x20:
2194 4c9649a9 j_mayer
        /* LDF */
2195 f18cd223 aurel32
        gen_load_mem(ctx, &gen_qemu_ldf, ra, rb, disp16, 1, 0);
2196 4c9649a9 j_mayer
        break;
2197 4c9649a9 j_mayer
    case 0x21:
2198 4c9649a9 j_mayer
        /* LDG */
2199 f18cd223 aurel32
        gen_load_mem(ctx, &gen_qemu_ldg, ra, rb, disp16, 1, 0);
2200 4c9649a9 j_mayer
        break;
2201 4c9649a9 j_mayer
    case 0x22:
2202 4c9649a9 j_mayer
        /* LDS */
2203 f18cd223 aurel32
        gen_load_mem(ctx, &gen_qemu_lds, ra, rb, disp16, 1, 0);
2204 4c9649a9 j_mayer
        break;
2205 4c9649a9 j_mayer
    case 0x23:
2206 4c9649a9 j_mayer
        /* LDT */
2207 f18cd223 aurel32
        gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 1, 0);
2208 4c9649a9 j_mayer
        break;
2209 4c9649a9 j_mayer
    case 0x24:
2210 4c9649a9 j_mayer
        /* STF */
2211 57a92c8e aurel32
        gen_store_mem(ctx, &gen_qemu_stf, ra, rb, disp16, 1, 0, 0);
2212 4c9649a9 j_mayer
        break;
2213 4c9649a9 j_mayer
    case 0x25:
2214 4c9649a9 j_mayer
        /* STG */
2215 57a92c8e aurel32
        gen_store_mem(ctx, &gen_qemu_stg, ra, rb, disp16, 1, 0, 0);
2216 4c9649a9 j_mayer
        break;
2217 4c9649a9 j_mayer
    case 0x26:
2218 4c9649a9 j_mayer
        /* STS */
2219 57a92c8e aurel32
        gen_store_mem(ctx, &gen_qemu_sts, ra, rb, disp16, 1, 0, 0);
2220 4c9649a9 j_mayer
        break;
2221 4c9649a9 j_mayer
    case 0x27:
2222 4c9649a9 j_mayer
        /* STT */
2223 57a92c8e aurel32
        gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 1, 0, 0);
2224 4c9649a9 j_mayer
        break;
2225 4c9649a9 j_mayer
    case 0x28:
2226 4c9649a9 j_mayer
        /* LDL */
2227 f18cd223 aurel32
        gen_load_mem(ctx, &tcg_gen_qemu_ld32s, ra, rb, disp16, 0, 0);
2228 4c9649a9 j_mayer
        break;
2229 4c9649a9 j_mayer
    case 0x29:
2230 4c9649a9 j_mayer
        /* LDQ */
2231 f18cd223 aurel32
        gen_load_mem(ctx, &tcg_gen_qemu_ld64, ra, rb, disp16, 0, 0);
2232 4c9649a9 j_mayer
        break;
2233 4c9649a9 j_mayer
    case 0x2A:
2234 4c9649a9 j_mayer
        /* LDL_L */
2235 f4ed8679 aurel32
        gen_load_mem(ctx, &gen_qemu_ldl_l, ra, rb, disp16, 0, 0);
2236 4c9649a9 j_mayer
        break;
2237 4c9649a9 j_mayer
    case 0x2B:
2238 4c9649a9 j_mayer
        /* LDQ_L */
2239 f4ed8679 aurel32
        gen_load_mem(ctx, &gen_qemu_ldq_l, ra, rb, disp16, 0, 0);
2240 4c9649a9 j_mayer
        break;
2241 4c9649a9 j_mayer
    case 0x2C:
2242 4c9649a9 j_mayer
        /* STL */
2243 57a92c8e aurel32
        gen_store_mem(ctx, &tcg_gen_qemu_st32, ra, rb, disp16, 0, 0, 0);
2244 4c9649a9 j_mayer
        break;
2245 4c9649a9 j_mayer
    case 0x2D:
2246 4c9649a9 j_mayer
        /* STQ */
2247 57a92c8e aurel32
        gen_store_mem(ctx, &tcg_gen_qemu_st64, ra, rb, disp16, 0, 0, 0);
2248 4c9649a9 j_mayer
        break;
2249 4c9649a9 j_mayer
    case 0x2E:
2250 4c9649a9 j_mayer
        /* STL_C */
2251 57a92c8e aurel32
        gen_store_mem(ctx, &gen_qemu_stl_c, ra, rb, disp16, 0, 0, 1);
2252 4c9649a9 j_mayer
        break;
2253 4c9649a9 j_mayer
    case 0x2F:
2254 4c9649a9 j_mayer
        /* STQ_C */
2255 57a92c8e aurel32
        gen_store_mem(ctx, &gen_qemu_stq_c, ra, rb, disp16, 0, 0, 1);
2256 4c9649a9 j_mayer
        break;
2257 4c9649a9 j_mayer
    case 0x30:
2258 4c9649a9 j_mayer
        /* BR */
2259 3761035f aurel32
        if (ra != 31)
2260 3761035f aurel32
            tcg_gen_movi_i64(cpu_ir[ra], ctx->pc);
2261 3761035f aurel32
        tcg_gen_movi_i64(cpu_pc, ctx->pc + (int64_t)(disp21 << 2));
2262 4c9649a9 j_mayer
        ret = 1;
2263 4c9649a9 j_mayer
        break;
2264 a7812ae4 pbrook
    case 0x31: /* FBEQ */
2265 a7812ae4 pbrook
    case 0x32: /* FBLT */
2266 a7812ae4 pbrook
    case 0x33: /* FBLE */
2267 a7812ae4 pbrook
        gen_fbcond(ctx, opc, ra, disp16);
2268 4c9649a9 j_mayer
        ret = 1;
2269 4c9649a9 j_mayer
        break;
2270 4c9649a9 j_mayer
    case 0x34:
2271 4c9649a9 j_mayer
        /* BSR */
2272 3761035f aurel32
        if (ra != 31)
2273 3761035f aurel32
            tcg_gen_movi_i64(cpu_ir[ra], ctx->pc);
2274 3761035f aurel32
        tcg_gen_movi_i64(cpu_pc, ctx->pc + (int64_t)(disp21 << 2));
2275 4c9649a9 j_mayer
        ret = 1;
2276 4c9649a9 j_mayer
        break;
2277 a7812ae4 pbrook
    case 0x35: /* FBNE */
2278 a7812ae4 pbrook
    case 0x36: /* FBGE */
2279 a7812ae4 pbrook
    case 0x37: /* FBGT */
2280 a7812ae4 pbrook
        gen_fbcond(ctx, opc, ra, disp16);
2281 4c9649a9 j_mayer
        ret = 1;
2282 4c9649a9 j_mayer
        break;
2283 4c9649a9 j_mayer
    case 0x38:
2284 4c9649a9 j_mayer
        /* BLBC */
2285 9c29504e aurel32
        gen_bcond(ctx, TCG_COND_EQ, ra, disp16, 1);
2286 4c9649a9 j_mayer
        ret = 1;
2287 4c9649a9 j_mayer
        break;
2288 4c9649a9 j_mayer
    case 0x39:
2289 4c9649a9 j_mayer
        /* BEQ */
2290 9c29504e aurel32
        gen_bcond(ctx, TCG_COND_EQ, ra, disp16, 0);
2291 4c9649a9 j_mayer
        ret = 1;
2292 4c9649a9 j_mayer
        break;
2293 4c9649a9 j_mayer
    case 0x3A:
2294 4c9649a9 j_mayer
        /* BLT */
2295 9c29504e aurel32
        gen_bcond(ctx, TCG_COND_LT, ra, disp16, 0);
2296 4c9649a9 j_mayer
        ret = 1;
2297 4c9649a9 j_mayer
        break;
2298 4c9649a9 j_mayer
    case 0x3B:
2299 4c9649a9 j_mayer
        /* BLE */
2300 9c29504e aurel32
        gen_bcond(ctx, TCG_COND_LE, ra, disp16, 0);
2301 4c9649a9 j_mayer
        ret = 1;
2302 4c9649a9 j_mayer
        break;
2303 4c9649a9 j_mayer
    case 0x3C:
2304 4c9649a9 j_mayer
        /* BLBS */
2305 9c29504e aurel32
        gen_bcond(ctx, TCG_COND_NE, ra, disp16, 1);
2306 4c9649a9 j_mayer
        ret = 1;
2307 4c9649a9 j_mayer
        break;
2308 4c9649a9 j_mayer
    case 0x3D:
2309 4c9649a9 j_mayer
        /* BNE */
2310 9c29504e aurel32
        gen_bcond(ctx, TCG_COND_NE, ra, disp16, 0);
2311 4c9649a9 j_mayer
        ret = 1;
2312 4c9649a9 j_mayer
        break;
2313 4c9649a9 j_mayer
    case 0x3E:
2314 4c9649a9 j_mayer
        /* BGE */
2315 9c29504e aurel32
        gen_bcond(ctx, TCG_COND_GE, ra, disp16, 0);
2316 4c9649a9 j_mayer
        ret = 1;
2317 4c9649a9 j_mayer
        break;
2318 4c9649a9 j_mayer
    case 0x3F:
2319 4c9649a9 j_mayer
        /* BGT */
2320 9c29504e aurel32
        gen_bcond(ctx, TCG_COND_GT, ra, disp16, 0);
2321 4c9649a9 j_mayer
        ret = 1;
2322 4c9649a9 j_mayer
        break;
2323 4c9649a9 j_mayer
    invalid_opc:
2324 4c9649a9 j_mayer
        gen_invalid(ctx);
2325 4c9649a9 j_mayer
        ret = 3;
2326 4c9649a9 j_mayer
        break;
2327 4c9649a9 j_mayer
    }
2328 4c9649a9 j_mayer
2329 4c9649a9 j_mayer
    return ret;
2330 4c9649a9 j_mayer
}
2331 4c9649a9 j_mayer
2332 2cfc5f17 ths
static always_inline void gen_intermediate_code_internal (CPUState *env,
2333 2cfc5f17 ths
                                                          TranslationBlock *tb,
2334 2cfc5f17 ths
                                                          int search_pc)
2335 4c9649a9 j_mayer
{
2336 4c9649a9 j_mayer
#if defined ALPHA_DEBUG_DISAS
2337 4c9649a9 j_mayer
    static int insn_count;
2338 4c9649a9 j_mayer
#endif
2339 4c9649a9 j_mayer
    DisasContext ctx, *ctxp = &ctx;
2340 4c9649a9 j_mayer
    target_ulong pc_start;
2341 4c9649a9 j_mayer
    uint32_t insn;
2342 4c9649a9 j_mayer
    uint16_t *gen_opc_end;
2343 a1d1bb31 aliguori
    CPUBreakpoint *bp;
2344 4c9649a9 j_mayer
    int j, lj = -1;
2345 4c9649a9 j_mayer
    int ret;
2346 2e70f6ef pbrook
    int num_insns;
2347 2e70f6ef pbrook
    int max_insns;
2348 4c9649a9 j_mayer
2349 4c9649a9 j_mayer
    pc_start = tb->pc;
2350 4c9649a9 j_mayer
    gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
2351 4c9649a9 j_mayer
    ctx.pc = pc_start;
2352 4c9649a9 j_mayer
    ctx.amask = env->amask;
2353 4c9649a9 j_mayer
#if defined (CONFIG_USER_ONLY)
2354 4c9649a9 j_mayer
    ctx.mem_idx = 0;
2355 4c9649a9 j_mayer
#else
2356 4c9649a9 j_mayer
    ctx.mem_idx = ((env->ps >> 3) & 3);
2357 4c9649a9 j_mayer
    ctx.pal_mode = env->ipr[IPR_EXC_ADDR] & 1;
2358 4c9649a9 j_mayer
#endif
2359 2e70f6ef pbrook
    num_insns = 0;
2360 2e70f6ef pbrook
    max_insns = tb->cflags & CF_COUNT_MASK;
2361 2e70f6ef pbrook
    if (max_insns == 0)
2362 2e70f6ef pbrook
        max_insns = CF_COUNT_MASK;
2363 2e70f6ef pbrook
2364 2e70f6ef pbrook
    gen_icount_start();
2365 4c9649a9 j_mayer
    for (ret = 0; ret == 0;) {
2366 c0ce998e aliguori
        if (unlikely(!TAILQ_EMPTY(&env->breakpoints))) {
2367 c0ce998e aliguori
            TAILQ_FOREACH(bp, &env->breakpoints, entry) {
2368 a1d1bb31 aliguori
                if (bp->pc == ctx.pc) {
2369 4c9649a9 j_mayer
                    gen_excp(&ctx, EXCP_DEBUG, 0);
2370 4c9649a9 j_mayer
                    break;
2371 4c9649a9 j_mayer
                }
2372 4c9649a9 j_mayer
            }
2373 4c9649a9 j_mayer
        }
2374 4c9649a9 j_mayer
        if (search_pc) {
2375 4c9649a9 j_mayer
            j = gen_opc_ptr - gen_opc_buf;
2376 4c9649a9 j_mayer
            if (lj < j) {
2377 4c9649a9 j_mayer
                lj++;
2378 4c9649a9 j_mayer
                while (lj < j)
2379 4c9649a9 j_mayer
                    gen_opc_instr_start[lj++] = 0;
2380 4c9649a9 j_mayer
                gen_opc_pc[lj] = ctx.pc;
2381 4c9649a9 j_mayer
                gen_opc_instr_start[lj] = 1;
2382 2e70f6ef pbrook
                gen_opc_icount[lj] = num_insns;
2383 4c9649a9 j_mayer
            }
2384 4c9649a9 j_mayer
        }
2385 2e70f6ef pbrook
        if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
2386 2e70f6ef pbrook
            gen_io_start();
2387 4c9649a9 j_mayer
#if defined ALPHA_DEBUG_DISAS
2388 4c9649a9 j_mayer
        insn_count++;
2389 4c9649a9 j_mayer
        if (logfile != NULL) {
2390 e96efcfc j_mayer
            fprintf(logfile, "pc " TARGET_FMT_lx " mem_idx %d\n",
2391 e96efcfc j_mayer
                    ctx.pc, ctx.mem_idx);
2392 4c9649a9 j_mayer
        }
2393 4c9649a9 j_mayer
#endif
2394 4c9649a9 j_mayer
        insn = ldl_code(ctx.pc);
2395 4c9649a9 j_mayer
#if defined ALPHA_DEBUG_DISAS
2396 4c9649a9 j_mayer
        insn_count++;
2397 4c9649a9 j_mayer
        if (logfile != NULL) {
2398 4c9649a9 j_mayer
            fprintf(logfile, "opcode %08x %d\n", insn, insn_count);
2399 4c9649a9 j_mayer
        }
2400 4c9649a9 j_mayer
#endif
2401 2e70f6ef pbrook
        num_insns++;
2402 4c9649a9 j_mayer
        ctx.pc += 4;
2403 4c9649a9 j_mayer
        ret = translate_one(ctxp, insn);
2404 4c9649a9 j_mayer
        if (ret != 0)
2405 4c9649a9 j_mayer
            break;
2406 4c9649a9 j_mayer
        /* if we reach a page boundary or are single stepping, stop
2407 4c9649a9 j_mayer
         * generation
2408 4c9649a9 j_mayer
         */
2409 4c9649a9 j_mayer
        if (((ctx.pc & (TARGET_PAGE_SIZE - 1)) == 0) ||
2410 2e70f6ef pbrook
            num_insns >= max_insns) {
2411 4c9649a9 j_mayer
            break;
2412 4c9649a9 j_mayer
        }
2413 19bf517b aurel32
2414 19bf517b aurel32
        if (env->singlestep_enabled) {
2415 19bf517b aurel32
            gen_excp(&ctx, EXCP_DEBUG, 0);
2416 19bf517b aurel32
            break;
2417 19bf517b aurel32
        }
2418 19bf517b aurel32
2419 4c9649a9 j_mayer
#if defined (DO_SINGLE_STEP)
2420 4c9649a9 j_mayer
        break;
2421 4c9649a9 j_mayer
#endif
2422 4c9649a9 j_mayer
    }
2423 4c9649a9 j_mayer
    if (ret != 1 && ret != 3) {
2424 496cb5b9 aurel32
        tcg_gen_movi_i64(cpu_pc, ctx.pc);
2425 4c9649a9 j_mayer
    }
2426 4c9649a9 j_mayer
#if defined (DO_TB_FLUSH)
2427 a7812ae4 pbrook
    gen_helper_tb_flush();
2428 4c9649a9 j_mayer
#endif
2429 2e70f6ef pbrook
    if (tb->cflags & CF_LAST_IO)
2430 2e70f6ef pbrook
        gen_io_end();
2431 4c9649a9 j_mayer
    /* Generate the return instruction */
2432 57fec1fe bellard
    tcg_gen_exit_tb(0);
2433 2e70f6ef pbrook
    gen_icount_end(tb, num_insns);
2434 4c9649a9 j_mayer
    *gen_opc_ptr = INDEX_op_end;
2435 4c9649a9 j_mayer
    if (search_pc) {
2436 4c9649a9 j_mayer
        j = gen_opc_ptr - gen_opc_buf;
2437 4c9649a9 j_mayer
        lj++;
2438 4c9649a9 j_mayer
        while (lj <= j)
2439 4c9649a9 j_mayer
            gen_opc_instr_start[lj++] = 0;
2440 4c9649a9 j_mayer
    } else {
2441 4c9649a9 j_mayer
        tb->size = ctx.pc - pc_start;
2442 2e70f6ef pbrook
        tb->icount = num_insns;
2443 4c9649a9 j_mayer
    }
2444 4c9649a9 j_mayer
#if defined ALPHA_DEBUG_DISAS
2445 4c9649a9 j_mayer
    if (loglevel & CPU_LOG_TB_CPU) {
2446 4c9649a9 j_mayer
        cpu_dump_state(env, logfile, fprintf, 0);
2447 4c9649a9 j_mayer
    }
2448 4c9649a9 j_mayer
    if (loglevel & CPU_LOG_TB_IN_ASM) {
2449 4c9649a9 j_mayer
        fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
2450 fe2b269a aurel32
        target_disas(logfile, pc_start, ctx.pc - pc_start, 1);
2451 4c9649a9 j_mayer
        fprintf(logfile, "\n");
2452 4c9649a9 j_mayer
    }
2453 4c9649a9 j_mayer
#endif
2454 4c9649a9 j_mayer
}
2455 4c9649a9 j_mayer
2456 2cfc5f17 ths
void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
2457 4c9649a9 j_mayer
{
2458 2cfc5f17 ths
    gen_intermediate_code_internal(env, tb, 0);
2459 4c9649a9 j_mayer
}
2460 4c9649a9 j_mayer
2461 2cfc5f17 ths
void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
2462 4c9649a9 j_mayer
{
2463 2cfc5f17 ths
    gen_intermediate_code_internal(env, tb, 1);
2464 4c9649a9 j_mayer
}
2465 4c9649a9 j_mayer
2466 aaed909a bellard
CPUAlphaState * cpu_alpha_init (const char *cpu_model)
2467 4c9649a9 j_mayer
{
2468 4c9649a9 j_mayer
    CPUAlphaState *env;
2469 4c9649a9 j_mayer
    uint64_t hwpcb;
2470 4c9649a9 j_mayer
2471 4c9649a9 j_mayer
    env = qemu_mallocz(sizeof(CPUAlphaState));
2472 4c9649a9 j_mayer
    if (!env)
2473 4c9649a9 j_mayer
        return NULL;
2474 4c9649a9 j_mayer
    cpu_exec_init(env);
2475 2e70f6ef pbrook
    alpha_translate_init();
2476 4c9649a9 j_mayer
    tlb_flush(env, 1);
2477 4c9649a9 j_mayer
    /* XXX: should not be hardcoded */
2478 4c9649a9 j_mayer
    env->implver = IMPLVER_2106x;
2479 4c9649a9 j_mayer
    env->ps = 0x1F00;
2480 4c9649a9 j_mayer
#if defined (CONFIG_USER_ONLY)
2481 4c9649a9 j_mayer
    env->ps |= 1 << 3;
2482 4c9649a9 j_mayer
#endif
2483 4c9649a9 j_mayer
    pal_init(env);
2484 4c9649a9 j_mayer
    /* Initialize IPR */
2485 4c9649a9 j_mayer
    hwpcb = env->ipr[IPR_PCBB];
2486 4c9649a9 j_mayer
    env->ipr[IPR_ASN] = 0;
2487 4c9649a9 j_mayer
    env->ipr[IPR_ASTEN] = 0;
2488 4c9649a9 j_mayer
    env->ipr[IPR_ASTSR] = 0;
2489 4c9649a9 j_mayer
    env->ipr[IPR_DATFX] = 0;
2490 4c9649a9 j_mayer
    /* XXX: fix this */
2491 4c9649a9 j_mayer
    //    env->ipr[IPR_ESP] = ldq_raw(hwpcb + 8);
2492 4c9649a9 j_mayer
    //    env->ipr[IPR_KSP] = ldq_raw(hwpcb + 0);
2493 4c9649a9 j_mayer
    //    env->ipr[IPR_SSP] = ldq_raw(hwpcb + 16);
2494 4c9649a9 j_mayer
    //    env->ipr[IPR_USP] = ldq_raw(hwpcb + 24);
2495 4c9649a9 j_mayer
    env->ipr[IPR_FEN] = 0;
2496 4c9649a9 j_mayer
    env->ipr[IPR_IPL] = 31;
2497 4c9649a9 j_mayer
    env->ipr[IPR_MCES] = 0;
2498 4c9649a9 j_mayer
    env->ipr[IPR_PERFMON] = 0; /* Implementation specific */
2499 4c9649a9 j_mayer
    //    env->ipr[IPR_PTBR] = ldq_raw(hwpcb + 32);
2500 4c9649a9 j_mayer
    env->ipr[IPR_SISR] = 0;
2501 4c9649a9 j_mayer
    env->ipr[IPR_VIRBND] = -1ULL;
2502 4c9649a9 j_mayer
2503 4c9649a9 j_mayer
    return env;
2504 4c9649a9 j_mayer
}
2505 aaed909a bellard
2506 d2856f1a aurel32
void gen_pc_load(CPUState *env, TranslationBlock *tb,
2507 d2856f1a aurel32
                unsigned long searched_pc, int pc_pos, void *puc)
2508 d2856f1a aurel32
{
2509 d2856f1a aurel32
    env->pc = gen_opc_pc[pc_pos];
2510 d2856f1a aurel32
}