2 * HPPA emulation cpu translation for qemu.
4 * Copyright (c) 2016 Richard Henderson <rth@twiddle.net>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
22 #include "disas/disas.h"
23 #include "qemu/host-utils.h"
24 #include "exec/exec-all.h"
25 #include "tcg/tcg-op.h"
26 #include "exec/cpu_ldst.h"
27 #include "exec/helper-proto.h"
28 #include "exec/helper-gen.h"
29 #include "exec/translator.h"
32 /* Since we have a distinction between register size and address size,
33 we need to redefine all of these. */
37 #undef tcg_global_reg_new
38 #undef tcg_global_mem_new
39 #undef tcg_temp_local_new
42 #if TARGET_LONG_BITS == 64
43 #define TCGv_tl TCGv_i64
44 #define tcg_temp_new_tl tcg_temp_new_i64
45 #define tcg_temp_free_tl tcg_temp_free_i64
46 #if TARGET_REGISTER_BITS == 64
47 #define tcg_gen_extu_reg_tl tcg_gen_mov_i64
49 #define tcg_gen_extu_reg_tl tcg_gen_extu_i32_i64
52 #define TCGv_tl TCGv_i32
53 #define tcg_temp_new_tl tcg_temp_new_i32
54 #define tcg_temp_free_tl tcg_temp_free_i32
55 #define tcg_gen_extu_reg_tl tcg_gen_mov_i32
58 #if TARGET_REGISTER_BITS == 64
59 #define TCGv_reg TCGv_i64
61 #define tcg_temp_new tcg_temp_new_i64
62 #define tcg_global_reg_new tcg_global_reg_new_i64
63 #define tcg_global_mem_new tcg_global_mem_new_i64
64 #define tcg_temp_local_new tcg_temp_local_new_i64
65 #define tcg_temp_free tcg_temp_free_i64
67 #define tcg_gen_movi_reg tcg_gen_movi_i64
68 #define tcg_gen_mov_reg tcg_gen_mov_i64
69 #define tcg_gen_ld8u_reg tcg_gen_ld8u_i64
70 #define tcg_gen_ld8s_reg tcg_gen_ld8s_i64
71 #define tcg_gen_ld16u_reg tcg_gen_ld16u_i64
72 #define tcg_gen_ld16s_reg tcg_gen_ld16s_i64
73 #define tcg_gen_ld32u_reg tcg_gen_ld32u_i64
74 #define tcg_gen_ld32s_reg tcg_gen_ld32s_i64
75 #define tcg_gen_ld_reg tcg_gen_ld_i64
76 #define tcg_gen_st8_reg tcg_gen_st8_i64
77 #define tcg_gen_st16_reg tcg_gen_st16_i64
78 #define tcg_gen_st32_reg tcg_gen_st32_i64
79 #define tcg_gen_st_reg tcg_gen_st_i64
80 #define tcg_gen_add_reg tcg_gen_add_i64
81 #define tcg_gen_addi_reg tcg_gen_addi_i64
82 #define tcg_gen_sub_reg tcg_gen_sub_i64
83 #define tcg_gen_neg_reg tcg_gen_neg_i64
84 #define tcg_gen_subfi_reg tcg_gen_subfi_i64
85 #define tcg_gen_subi_reg tcg_gen_subi_i64
86 #define tcg_gen_and_reg tcg_gen_and_i64
87 #define tcg_gen_andi_reg tcg_gen_andi_i64
88 #define tcg_gen_or_reg tcg_gen_or_i64
89 #define tcg_gen_ori_reg tcg_gen_ori_i64
90 #define tcg_gen_xor_reg tcg_gen_xor_i64
91 #define tcg_gen_xori_reg tcg_gen_xori_i64
92 #define tcg_gen_not_reg tcg_gen_not_i64
93 #define tcg_gen_shl_reg tcg_gen_shl_i64
94 #define tcg_gen_shli_reg tcg_gen_shli_i64
95 #define tcg_gen_shr_reg tcg_gen_shr_i64
96 #define tcg_gen_shri_reg tcg_gen_shri_i64
97 #define tcg_gen_sar_reg tcg_gen_sar_i64
98 #define tcg_gen_sari_reg tcg_gen_sari_i64
99 #define tcg_gen_brcond_reg tcg_gen_brcond_i64
100 #define tcg_gen_brcondi_reg tcg_gen_brcondi_i64
101 #define tcg_gen_setcond_reg tcg_gen_setcond_i64
102 #define tcg_gen_setcondi_reg tcg_gen_setcondi_i64
103 #define tcg_gen_mul_reg tcg_gen_mul_i64
104 #define tcg_gen_muli_reg tcg_gen_muli_i64
105 #define tcg_gen_div_reg tcg_gen_div_i64
106 #define tcg_gen_rem_reg tcg_gen_rem_i64
107 #define tcg_gen_divu_reg tcg_gen_divu_i64
108 #define tcg_gen_remu_reg tcg_gen_remu_i64
109 #define tcg_gen_discard_reg tcg_gen_discard_i64
110 #define tcg_gen_trunc_reg_i32 tcg_gen_extrl_i64_i32
111 #define tcg_gen_trunc_i64_reg tcg_gen_mov_i64
112 #define tcg_gen_extu_i32_reg tcg_gen_extu_i32_i64
113 #define tcg_gen_ext_i32_reg tcg_gen_ext_i32_i64
114 #define tcg_gen_extu_reg_i64 tcg_gen_mov_i64
115 #define tcg_gen_ext_reg_i64 tcg_gen_mov_i64
116 #define tcg_gen_ext8u_reg tcg_gen_ext8u_i64
117 #define tcg_gen_ext8s_reg tcg_gen_ext8s_i64
118 #define tcg_gen_ext16u_reg tcg_gen_ext16u_i64
119 #define tcg_gen_ext16s_reg tcg_gen_ext16s_i64
120 #define tcg_gen_ext32u_reg tcg_gen_ext32u_i64
121 #define tcg_gen_ext32s_reg tcg_gen_ext32s_i64
122 #define tcg_gen_bswap16_reg tcg_gen_bswap16_i64
123 #define tcg_gen_bswap32_reg tcg_gen_bswap32_i64
124 #define tcg_gen_bswap64_reg tcg_gen_bswap64_i64
125 #define tcg_gen_concat_reg_i64 tcg_gen_concat32_i64
126 #define tcg_gen_andc_reg tcg_gen_andc_i64
127 #define tcg_gen_eqv_reg tcg_gen_eqv_i64
128 #define tcg_gen_nand_reg tcg_gen_nand_i64
129 #define tcg_gen_nor_reg tcg_gen_nor_i64
130 #define tcg_gen_orc_reg tcg_gen_orc_i64
131 #define tcg_gen_clz_reg tcg_gen_clz_i64
132 #define tcg_gen_ctz_reg tcg_gen_ctz_i64
133 #define tcg_gen_clzi_reg tcg_gen_clzi_i64
134 #define tcg_gen_ctzi_reg tcg_gen_ctzi_i64
135 #define tcg_gen_clrsb_reg tcg_gen_clrsb_i64
136 #define tcg_gen_ctpop_reg tcg_gen_ctpop_i64
137 #define tcg_gen_rotl_reg tcg_gen_rotl_i64
138 #define tcg_gen_rotli_reg tcg_gen_rotli_i64
139 #define tcg_gen_rotr_reg tcg_gen_rotr_i64
140 #define tcg_gen_rotri_reg tcg_gen_rotri_i64
141 #define tcg_gen_deposit_reg tcg_gen_deposit_i64
142 #define tcg_gen_deposit_z_reg tcg_gen_deposit_z_i64
143 #define tcg_gen_extract_reg tcg_gen_extract_i64
144 #define tcg_gen_sextract_reg tcg_gen_sextract_i64
145 #define tcg_const_reg tcg_const_i64
146 #define tcg_const_local_reg tcg_const_local_i64
147 #define tcg_constant_reg tcg_constant_i64
148 #define tcg_gen_movcond_reg tcg_gen_movcond_i64
149 #define tcg_gen_add2_reg tcg_gen_add2_i64
150 #define tcg_gen_sub2_reg tcg_gen_sub2_i64
151 #define tcg_gen_qemu_ld_reg tcg_gen_qemu_ld_i64
152 #define tcg_gen_qemu_st_reg tcg_gen_qemu_st_i64
153 #define tcg_gen_atomic_xchg_reg tcg_gen_atomic_xchg_i64
154 #define tcg_gen_trunc_reg_ptr tcg_gen_trunc_i64_ptr
156 #define TCGv_reg TCGv_i32
157 #define tcg_temp_new tcg_temp_new_i32
158 #define tcg_global_reg_new tcg_global_reg_new_i32
159 #define tcg_global_mem_new tcg_global_mem_new_i32
160 #define tcg_temp_local_new tcg_temp_local_new_i32
161 #define tcg_temp_free tcg_temp_free_i32
163 #define tcg_gen_movi_reg tcg_gen_movi_i32
164 #define tcg_gen_mov_reg tcg_gen_mov_i32
165 #define tcg_gen_ld8u_reg tcg_gen_ld8u_i32
166 #define tcg_gen_ld8s_reg tcg_gen_ld8s_i32
167 #define tcg_gen_ld16u_reg tcg_gen_ld16u_i32
168 #define tcg_gen_ld16s_reg tcg_gen_ld16s_i32
169 #define tcg_gen_ld32u_reg tcg_gen_ld_i32
170 #define tcg_gen_ld32s_reg tcg_gen_ld_i32
171 #define tcg_gen_ld_reg tcg_gen_ld_i32
172 #define tcg_gen_st8_reg tcg_gen_st8_i32
173 #define tcg_gen_st16_reg tcg_gen_st16_i32
174 #define tcg_gen_st32_reg tcg_gen_st32_i32
175 #define tcg_gen_st_reg tcg_gen_st_i32
176 #define tcg_gen_add_reg tcg_gen_add_i32
177 #define tcg_gen_addi_reg tcg_gen_addi_i32
178 #define tcg_gen_sub_reg tcg_gen_sub_i32
179 #define tcg_gen_neg_reg tcg_gen_neg_i32
180 #define tcg_gen_subfi_reg tcg_gen_subfi_i32
181 #define tcg_gen_subi_reg tcg_gen_subi_i32
182 #define tcg_gen_and_reg tcg_gen_and_i32
183 #define tcg_gen_andi_reg tcg_gen_andi_i32
184 #define tcg_gen_or_reg tcg_gen_or_i32
185 #define tcg_gen_ori_reg tcg_gen_ori_i32
186 #define tcg_gen_xor_reg tcg_gen_xor_i32
187 #define tcg_gen_xori_reg tcg_gen_xori_i32
188 #define tcg_gen_not_reg tcg_gen_not_i32
189 #define tcg_gen_shl_reg tcg_gen_shl_i32
190 #define tcg_gen_shli_reg tcg_gen_shli_i32
191 #define tcg_gen_shr_reg tcg_gen_shr_i32
192 #define tcg_gen_shri_reg tcg_gen_shri_i32
193 #define tcg_gen_sar_reg tcg_gen_sar_i32
194 #define tcg_gen_sari_reg tcg_gen_sari_i32
195 #define tcg_gen_brcond_reg tcg_gen_brcond_i32
196 #define tcg_gen_brcondi_reg tcg_gen_brcondi_i32
197 #define tcg_gen_setcond_reg tcg_gen_setcond_i32
198 #define tcg_gen_setcondi_reg tcg_gen_setcondi_i32
199 #define tcg_gen_mul_reg tcg_gen_mul_i32
200 #define tcg_gen_muli_reg tcg_gen_muli_i32
201 #define tcg_gen_div_reg tcg_gen_div_i32
202 #define tcg_gen_rem_reg tcg_gen_rem_i32
203 #define tcg_gen_divu_reg tcg_gen_divu_i32
204 #define tcg_gen_remu_reg tcg_gen_remu_i32
205 #define tcg_gen_discard_reg tcg_gen_discard_i32
206 #define tcg_gen_trunc_reg_i32 tcg_gen_mov_i32
207 #define tcg_gen_trunc_i64_reg tcg_gen_extrl_i64_i32
208 #define tcg_gen_extu_i32_reg tcg_gen_mov_i32
209 #define tcg_gen_ext_i32_reg tcg_gen_mov_i32
210 #define tcg_gen_extu_reg_i64 tcg_gen_extu_i32_i64
211 #define tcg_gen_ext_reg_i64 tcg_gen_ext_i32_i64
212 #define tcg_gen_ext8u_reg tcg_gen_ext8u_i32
213 #define tcg_gen_ext8s_reg tcg_gen_ext8s_i32
214 #define tcg_gen_ext16u_reg tcg_gen_ext16u_i32
215 #define tcg_gen_ext16s_reg tcg_gen_ext16s_i32
216 #define tcg_gen_ext32u_reg tcg_gen_mov_i32
217 #define tcg_gen_ext32s_reg tcg_gen_mov_i32
218 #define tcg_gen_bswap16_reg tcg_gen_bswap16_i32
219 #define tcg_gen_bswap32_reg tcg_gen_bswap32_i32
220 #define tcg_gen_concat_reg_i64 tcg_gen_concat_i32_i64
221 #define tcg_gen_andc_reg tcg_gen_andc_i32
222 #define tcg_gen_eqv_reg tcg_gen_eqv_i32
223 #define tcg_gen_nand_reg tcg_gen_nand_i32
224 #define tcg_gen_nor_reg tcg_gen_nor_i32
225 #define tcg_gen_orc_reg tcg_gen_orc_i32
226 #define tcg_gen_clz_reg tcg_gen_clz_i32
227 #define tcg_gen_ctz_reg tcg_gen_ctz_i32
228 #define tcg_gen_clzi_reg tcg_gen_clzi_i32
229 #define tcg_gen_ctzi_reg tcg_gen_ctzi_i32
230 #define tcg_gen_clrsb_reg tcg_gen_clrsb_i32
231 #define tcg_gen_ctpop_reg tcg_gen_ctpop_i32
232 #define tcg_gen_rotl_reg tcg_gen_rotl_i32
233 #define tcg_gen_rotli_reg tcg_gen_rotli_i32
234 #define tcg_gen_rotr_reg tcg_gen_rotr_i32
235 #define tcg_gen_rotri_reg tcg_gen_rotri_i32
236 #define tcg_gen_deposit_reg tcg_gen_deposit_i32
237 #define tcg_gen_deposit_z_reg tcg_gen_deposit_z_i32
238 #define tcg_gen_extract_reg tcg_gen_extract_i32
239 #define tcg_gen_sextract_reg tcg_gen_sextract_i32
240 #define tcg_const_reg tcg_const_i32
241 #define tcg_const_local_reg tcg_const_local_i32
242 #define tcg_constant_reg tcg_constant_i32
243 #define tcg_gen_movcond_reg tcg_gen_movcond_i32
244 #define tcg_gen_add2_reg tcg_gen_add2_i32
245 #define tcg_gen_sub2_reg tcg_gen_sub2_i32
246 #define tcg_gen_qemu_ld_reg tcg_gen_qemu_ld_i32
247 #define tcg_gen_qemu_st_reg tcg_gen_qemu_st_i32
248 #define tcg_gen_atomic_xchg_reg tcg_gen_atomic_xchg_i32
249 #define tcg_gen_trunc_reg_ptr tcg_gen_ext_i32_ptr
250 #endif /* TARGET_REGISTER_BITS */
252 typedef struct DisasCond
{
257 typedef struct DisasContext
{
258 DisasContextBase base
;
280 /* Note that ssm/rsm instructions number PSW_W and PSW_E differently. */
281 static int expand_sm_imm(DisasContext
*ctx
, int val
)
283 if (val
& PSW_SM_E
) {
284 val
= (val
& ~PSW_SM_E
) | PSW_E
;
286 if (val
& PSW_SM_W
) {
287 val
= (val
& ~PSW_SM_W
) | PSW_W
;
292 /* Inverted space register indicates 0 means sr0 not inferred from base. */
293 static int expand_sr3x(DisasContext
*ctx
, int val
)
298 /* Convert the M:A bits within a memory insn to the tri-state value
299 we use for the final M. */
300 static int ma_to_m(DisasContext
*ctx
, int val
)
302 return val
& 2 ? (val
& 1 ? -1 : 1) : 0;
305 /* Convert the sign of the displacement to a pre or post-modify. */
306 static int pos_to_m(DisasContext
*ctx
, int val
)
311 static int neg_to_m(DisasContext
*ctx
, int val
)
316 /* Used for branch targets and fp memory ops. */
317 static int expand_shl2(DisasContext
*ctx
, int val
)
322 /* Used for fp memory ops. */
323 static int expand_shl3(DisasContext
*ctx
, int val
)
328 /* Used for assemble_21. */
329 static int expand_shl11(DisasContext
*ctx
, int val
)
335 /* Include the auto-generated decoder. */
336 #include "decode-insns.c.inc"
338 /* We are not using a goto_tb (for whatever reason), but have updated
339 the iaq (for whatever reason), so don't do it again on exit. */
340 #define DISAS_IAQ_N_UPDATED DISAS_TARGET_0
342 /* We are exiting the TB, but have neither emitted a goto_tb, nor
343 updated the iaq for the next instruction to be executed. */
344 #define DISAS_IAQ_N_STALE DISAS_TARGET_1
346 /* Similarly, but we want to return to the main loop immediately
347 to recognize unmasked interrupts. */
348 #define DISAS_IAQ_N_STALE_EXIT DISAS_TARGET_2
349 #define DISAS_EXIT DISAS_TARGET_3
351 /* global register indexes */
352 static TCGv_reg cpu_gr
[32];
353 static TCGv_i64 cpu_sr
[4];
354 static TCGv_i64 cpu_srH
;
355 static TCGv_reg cpu_iaoq_f
;
356 static TCGv_reg cpu_iaoq_b
;
357 static TCGv_i64 cpu_iasq_f
;
358 static TCGv_i64 cpu_iasq_b
;
359 static TCGv_reg cpu_sar
;
360 static TCGv_reg cpu_psw_n
;
361 static TCGv_reg cpu_psw_v
;
362 static TCGv_reg cpu_psw_cb
;
363 static TCGv_reg cpu_psw_cb_msb
;
365 #include "exec/gen-icount.h"
367 void hppa_translate_init(void)
369 #define DEF_VAR(V) { &cpu_##V, #V, offsetof(CPUHPPAState, V) }
371 typedef struct { TCGv_reg
*var
; const char *name
; int ofs
; } GlobalVar
;
372 static const GlobalVar vars
[] = {
373 { &cpu_sar
, "sar", offsetof(CPUHPPAState
, cr
[CR_SAR
]) },
384 /* Use the symbolic register names that match the disassembler. */
385 static const char gr_names
[32][4] = {
386 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
387 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
388 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
389 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
391 /* SR[4-7] are not global registers so that we can index them. */
392 static const char sr_names
[5][4] = {
393 "sr0", "sr1", "sr2", "sr3", "srH"
399 for (i
= 1; i
< 32; i
++) {
400 cpu_gr
[i
] = tcg_global_mem_new(cpu_env
,
401 offsetof(CPUHPPAState
, gr
[i
]),
404 for (i
= 0; i
< 4; i
++) {
405 cpu_sr
[i
] = tcg_global_mem_new_i64(cpu_env
,
406 offsetof(CPUHPPAState
, sr
[i
]),
409 cpu_srH
= tcg_global_mem_new_i64(cpu_env
,
410 offsetof(CPUHPPAState
, sr
[4]),
413 for (i
= 0; i
< ARRAY_SIZE(vars
); ++i
) {
414 const GlobalVar
*v
= &vars
[i
];
415 *v
->var
= tcg_global_mem_new(cpu_env
, v
->ofs
, v
->name
);
418 cpu_iasq_f
= tcg_global_mem_new_i64(cpu_env
,
419 offsetof(CPUHPPAState
, iasq_f
),
421 cpu_iasq_b
= tcg_global_mem_new_i64(cpu_env
,
422 offsetof(CPUHPPAState
, iasq_b
),
426 static DisasCond
cond_make_f(void)
435 static DisasCond
cond_make_t(void)
438 .c
= TCG_COND_ALWAYS
,
444 static DisasCond
cond_make_n(void)
449 .a1
= tcg_constant_reg(0)
453 static DisasCond
cond_make_0_tmp(TCGCond c
, TCGv_reg a0
)
455 assert (c
!= TCG_COND_NEVER
&& c
!= TCG_COND_ALWAYS
);
457 .c
= c
, .a0
= a0
, .a1
= tcg_constant_reg(0)
461 static DisasCond
cond_make_0(TCGCond c
, TCGv_reg a0
)
463 TCGv_reg tmp
= tcg_temp_new();
464 tcg_gen_mov_reg(tmp
, a0
);
465 return cond_make_0_tmp(c
, tmp
);
468 static DisasCond
cond_make(TCGCond c
, TCGv_reg a0
, TCGv_reg a1
)
470 DisasCond r
= { .c
= c
};
472 assert (c
!= TCG_COND_NEVER
&& c
!= TCG_COND_ALWAYS
);
473 r
.a0
= tcg_temp_new();
474 tcg_gen_mov_reg(r
.a0
, a0
);
475 r
.a1
= tcg_temp_new();
476 tcg_gen_mov_reg(r
.a1
, a1
);
481 static void cond_free(DisasCond
*cond
)
485 if (cond
->a0
!= cpu_psw_n
) {
486 tcg_temp_free(cond
->a0
);
488 tcg_temp_free(cond
->a1
);
492 case TCG_COND_ALWAYS
:
493 cond
->c
= TCG_COND_NEVER
;
500 static TCGv_reg
get_temp(DisasContext
*ctx
)
502 unsigned i
= ctx
->ntempr
++;
503 g_assert(i
< ARRAY_SIZE(ctx
->tempr
));
504 return ctx
->tempr
[i
] = tcg_temp_new();
507 #ifndef CONFIG_USER_ONLY
508 static TCGv_tl
get_temp_tl(DisasContext
*ctx
)
510 unsigned i
= ctx
->ntempl
++;
511 g_assert(i
< ARRAY_SIZE(ctx
->templ
));
512 return ctx
->templ
[i
] = tcg_temp_new_tl();
516 static TCGv_reg
load_const(DisasContext
*ctx
, target_sreg v
)
518 TCGv_reg t
= get_temp(ctx
);
519 tcg_gen_movi_reg(t
, v
);
523 static TCGv_reg
load_gpr(DisasContext
*ctx
, unsigned reg
)
526 TCGv_reg t
= get_temp(ctx
);
527 tcg_gen_movi_reg(t
, 0);
534 static TCGv_reg
dest_gpr(DisasContext
*ctx
, unsigned reg
)
536 if (reg
== 0 || ctx
->null_cond
.c
!= TCG_COND_NEVER
) {
537 return get_temp(ctx
);
543 static void save_or_nullify(DisasContext
*ctx
, TCGv_reg dest
, TCGv_reg t
)
545 if (ctx
->null_cond
.c
!= TCG_COND_NEVER
) {
546 tcg_gen_movcond_reg(ctx
->null_cond
.c
, dest
, ctx
->null_cond
.a0
,
547 ctx
->null_cond
.a1
, dest
, t
);
549 tcg_gen_mov_reg(dest
, t
);
553 static void save_gpr(DisasContext
*ctx
, unsigned reg
, TCGv_reg t
)
556 save_or_nullify(ctx
, cpu_gr
[reg
], t
);
560 #ifdef HOST_WORDS_BIGENDIAN
568 static TCGv_i32
load_frw_i32(unsigned rt
)
570 TCGv_i32 ret
= tcg_temp_new_i32();
571 tcg_gen_ld_i32(ret
, cpu_env
,
572 offsetof(CPUHPPAState
, fr
[rt
& 31])
573 + (rt
& 32 ? LO_OFS
: HI_OFS
));
577 static TCGv_i32
load_frw0_i32(unsigned rt
)
580 return tcg_const_i32(0);
582 return load_frw_i32(rt
);
586 static TCGv_i64
load_frw0_i64(unsigned rt
)
589 return tcg_const_i64(0);
591 TCGv_i64 ret
= tcg_temp_new_i64();
592 tcg_gen_ld32u_i64(ret
, cpu_env
,
593 offsetof(CPUHPPAState
, fr
[rt
& 31])
594 + (rt
& 32 ? LO_OFS
: HI_OFS
));
599 static void save_frw_i32(unsigned rt
, TCGv_i32 val
)
601 tcg_gen_st_i32(val
, cpu_env
,
602 offsetof(CPUHPPAState
, fr
[rt
& 31])
603 + (rt
& 32 ? LO_OFS
: HI_OFS
));
609 static TCGv_i64
load_frd(unsigned rt
)
611 TCGv_i64 ret
= tcg_temp_new_i64();
612 tcg_gen_ld_i64(ret
, cpu_env
, offsetof(CPUHPPAState
, fr
[rt
]));
616 static TCGv_i64
load_frd0(unsigned rt
)
619 return tcg_const_i64(0);
625 static void save_frd(unsigned rt
, TCGv_i64 val
)
627 tcg_gen_st_i64(val
, cpu_env
, offsetof(CPUHPPAState
, fr
[rt
]));
630 static void load_spr(DisasContext
*ctx
, TCGv_i64 dest
, unsigned reg
)
632 #ifdef CONFIG_USER_ONLY
633 tcg_gen_movi_i64(dest
, 0);
636 tcg_gen_mov_i64(dest
, cpu_sr
[reg
]);
637 } else if (ctx
->tb_flags
& TB_FLAG_SR_SAME
) {
638 tcg_gen_mov_i64(dest
, cpu_srH
);
640 tcg_gen_ld_i64(dest
, cpu_env
, offsetof(CPUHPPAState
, sr
[reg
]));
645 /* Skip over the implementation of an insn that has been nullified.
646 Use this when the insn is too complex for a conditional move. */
647 static void nullify_over(DisasContext
*ctx
)
649 if (ctx
->null_cond
.c
!= TCG_COND_NEVER
) {
650 /* The always condition should have been handled in the main loop. */
651 assert(ctx
->null_cond
.c
!= TCG_COND_ALWAYS
);
653 ctx
->null_lab
= gen_new_label();
655 /* If we're using PSW[N], copy it to a temp because... */
656 if (ctx
->null_cond
.a0
== cpu_psw_n
) {
657 ctx
->null_cond
.a0
= tcg_temp_new();
658 tcg_gen_mov_reg(ctx
->null_cond
.a0
, cpu_psw_n
);
660 /* ... we clear it before branching over the implementation,
661 so that (1) it's clear after nullifying this insn and
662 (2) if this insn nullifies the next, PSW[N] is valid. */
663 if (ctx
->psw_n_nonzero
) {
664 ctx
->psw_n_nonzero
= false;
665 tcg_gen_movi_reg(cpu_psw_n
, 0);
668 tcg_gen_brcond_reg(ctx
->null_cond
.c
, ctx
->null_cond
.a0
,
669 ctx
->null_cond
.a1
, ctx
->null_lab
);
670 cond_free(&ctx
->null_cond
);
674 /* Save the current nullification state to PSW[N]. */
675 static void nullify_save(DisasContext
*ctx
)
677 if (ctx
->null_cond
.c
== TCG_COND_NEVER
) {
678 if (ctx
->psw_n_nonzero
) {
679 tcg_gen_movi_reg(cpu_psw_n
, 0);
683 if (ctx
->null_cond
.a0
!= cpu_psw_n
) {
684 tcg_gen_setcond_reg(ctx
->null_cond
.c
, cpu_psw_n
,
685 ctx
->null_cond
.a0
, ctx
->null_cond
.a1
);
686 ctx
->psw_n_nonzero
= true;
688 cond_free(&ctx
->null_cond
);
691 /* Set a PSW[N] to X. The intention is that this is used immediately
692 before a goto_tb/exit_tb, so that there is no fallthru path to other
693 code within the TB. Therefore we do not update psw_n_nonzero. */
694 static void nullify_set(DisasContext
*ctx
, bool x
)
696 if (ctx
->psw_n_nonzero
|| x
) {
697 tcg_gen_movi_reg(cpu_psw_n
, x
);
701 /* Mark the end of an instruction that may have been nullified.
702 This is the pair to nullify_over. Always returns true so that
703 it may be tail-called from a translate function. */
704 static bool nullify_end(DisasContext
*ctx
)
706 TCGLabel
*null_lab
= ctx
->null_lab
;
707 DisasJumpType status
= ctx
->base
.is_jmp
;
709 /* For NEXT, NORETURN, STALE, we can easily continue (or exit).
710 For UPDATED, we cannot update on the nullified path. */
711 assert(status
!= DISAS_IAQ_N_UPDATED
);
713 if (likely(null_lab
== NULL
)) {
714 /* The current insn wasn't conditional or handled the condition
715 applied to it without a branch, so the (new) setting of
716 NULL_COND can be applied directly to the next insn. */
719 ctx
->null_lab
= NULL
;
721 if (likely(ctx
->null_cond
.c
== TCG_COND_NEVER
)) {
722 /* The next instruction will be unconditional,
723 and NULL_COND already reflects that. */
724 gen_set_label(null_lab
);
726 /* The insn that we just executed is itself nullifying the next
727 instruction. Store the condition in the PSW[N] global.
728 We asserted PSW[N] = 0 in nullify_over, so that after the
729 label we have the proper value in place. */
731 gen_set_label(null_lab
);
732 ctx
->null_cond
= cond_make_n();
734 if (status
== DISAS_NORETURN
) {
735 ctx
->base
.is_jmp
= DISAS_NEXT
;
740 static void copy_iaoq_entry(TCGv_reg dest
, target_ureg ival
, TCGv_reg vval
)
742 if (unlikely(ival
== -1)) {
743 tcg_gen_mov_reg(dest
, vval
);
745 tcg_gen_movi_reg(dest
, ival
);
749 static inline target_ureg
iaoq_dest(DisasContext
*ctx
, target_sreg disp
)
751 return ctx
->iaoq_f
+ disp
+ 8;
754 static void gen_excp_1(int exception
)
756 gen_helper_excp(cpu_env
, tcg_constant_i32(exception
));
759 static void gen_excp(DisasContext
*ctx
, int exception
)
761 copy_iaoq_entry(cpu_iaoq_f
, ctx
->iaoq_f
, cpu_iaoq_f
);
762 copy_iaoq_entry(cpu_iaoq_b
, ctx
->iaoq_b
, cpu_iaoq_b
);
764 gen_excp_1(exception
);
765 ctx
->base
.is_jmp
= DISAS_NORETURN
;
768 static bool gen_excp_iir(DisasContext
*ctx
, int exc
)
771 tcg_gen_st_reg(tcg_constant_reg(ctx
->insn
),
772 cpu_env
, offsetof(CPUHPPAState
, cr
[CR_IIR
]));
774 return nullify_end(ctx
);
777 static bool gen_illegal(DisasContext
*ctx
)
779 return gen_excp_iir(ctx
, EXCP_ILL
);
782 #ifdef CONFIG_USER_ONLY
783 #define CHECK_MOST_PRIVILEGED(EXCP) \
784 return gen_excp_iir(ctx, EXCP)
786 #define CHECK_MOST_PRIVILEGED(EXCP) \
788 if (ctx->privilege != 0) { \
789 return gen_excp_iir(ctx, EXCP); \
794 static bool use_goto_tb(DisasContext
*ctx
, target_ureg dest
)
796 return translator_use_goto_tb(&ctx
->base
, dest
);
799 /* If the next insn is to be nullified, and it's on the same page,
800 and we're not attempting to set a breakpoint on it, then we can
801 totally skip the nullified insn. This avoids creating and
802 executing a TB that merely branches to the next TB. */
803 static bool use_nullify_skip(DisasContext
*ctx
)
805 return (((ctx
->iaoq_b
^ ctx
->iaoq_f
) & TARGET_PAGE_MASK
) == 0
806 && !cpu_breakpoint_test(ctx
->cs
, ctx
->iaoq_b
, BP_ANY
));
809 static void gen_goto_tb(DisasContext
*ctx
, int which
,
810 target_ureg f
, target_ureg b
)
812 if (f
!= -1 && b
!= -1 && use_goto_tb(ctx
, f
)) {
813 tcg_gen_goto_tb(which
);
814 tcg_gen_movi_reg(cpu_iaoq_f
, f
);
815 tcg_gen_movi_reg(cpu_iaoq_b
, b
);
816 tcg_gen_exit_tb(ctx
->base
.tb
, which
);
818 copy_iaoq_entry(cpu_iaoq_f
, f
, cpu_iaoq_b
);
819 copy_iaoq_entry(cpu_iaoq_b
, b
, ctx
->iaoq_n_var
);
820 if (ctx
->base
.singlestep_enabled
) {
821 gen_excp_1(EXCP_DEBUG
);
823 tcg_gen_lookup_and_goto_ptr();
828 static bool cond_need_sv(int c
)
830 return c
== 2 || c
== 3 || c
== 6;
833 static bool cond_need_cb(int c
)
835 return c
== 4 || c
== 5;
839 * Compute conditional for arithmetic. See Page 5-3, Table 5-1, of
840 * the Parisc 1.1 Architecture Reference Manual for details.
843 static DisasCond
do_cond(unsigned cf
, TCGv_reg res
,
844 TCGv_reg cb_msb
, TCGv_reg sv
)
850 case 0: /* Never / TR (0 / 1) */
851 cond
= cond_make_f();
853 case 1: /* = / <> (Z / !Z) */
854 cond
= cond_make_0(TCG_COND_EQ
, res
);
856 case 2: /* < / >= (N ^ V / !(N ^ V) */
857 tmp
= tcg_temp_new();
858 tcg_gen_xor_reg(tmp
, res
, sv
);
859 cond
= cond_make_0_tmp(TCG_COND_LT
, tmp
);
861 case 3: /* <= / > (N ^ V) | Z / !((N ^ V) | Z) */
865 * ((res < 0) ^ (sv < 0)) | !res
866 * ((res ^ sv) < 0) | !res
867 * (~(res ^ sv) >= 0) | !res
868 * !(~(res ^ sv) >> 31) | !res
869 * !(~(res ^ sv) >> 31 & res)
871 tmp
= tcg_temp_new();
872 tcg_gen_eqv_reg(tmp
, res
, sv
);
873 tcg_gen_sari_reg(tmp
, tmp
, TARGET_REGISTER_BITS
- 1);
874 tcg_gen_and_reg(tmp
, tmp
, res
);
875 cond
= cond_make_0_tmp(TCG_COND_EQ
, tmp
);
877 case 4: /* NUV / UV (!C / C) */
878 cond
= cond_make_0(TCG_COND_EQ
, cb_msb
);
880 case 5: /* ZNV / VNZ (!C | Z / C & !Z) */
881 tmp
= tcg_temp_new();
882 tcg_gen_neg_reg(tmp
, cb_msb
);
883 tcg_gen_and_reg(tmp
, tmp
, res
);
884 cond
= cond_make_0_tmp(TCG_COND_EQ
, tmp
);
886 case 6: /* SV / NSV (V / !V) */
887 cond
= cond_make_0(TCG_COND_LT
, sv
);
889 case 7: /* OD / EV */
890 tmp
= tcg_temp_new();
891 tcg_gen_andi_reg(tmp
, res
, 1);
892 cond
= cond_make_0_tmp(TCG_COND_NE
, tmp
);
895 g_assert_not_reached();
898 cond
.c
= tcg_invert_cond(cond
.c
);
904 /* Similar, but for the special case of subtraction without borrow, we
905 can use the inputs directly. This can allow other computation to be
906 deleted as unused. */
908 static DisasCond
do_sub_cond(unsigned cf
, TCGv_reg res
,
909 TCGv_reg in1
, TCGv_reg in2
, TCGv_reg sv
)
915 cond
= cond_make(TCG_COND_EQ
, in1
, in2
);
918 cond
= cond_make(TCG_COND_LT
, in1
, in2
);
921 cond
= cond_make(TCG_COND_LE
, in1
, in2
);
923 case 4: /* << / >>= */
924 cond
= cond_make(TCG_COND_LTU
, in1
, in2
);
926 case 5: /* <<= / >> */
927 cond
= cond_make(TCG_COND_LEU
, in1
, in2
);
930 return do_cond(cf
, res
, NULL
, sv
);
933 cond
.c
= tcg_invert_cond(cond
.c
);
940 * Similar, but for logicals, where the carry and overflow bits are not
941 * computed, and use of them is undefined.
943 * Undefined or not, hardware does not trap. It seems reasonable to
944 * assume hardware treats cases c={4,5,6} as if C=0 & V=0, since that's
945 * how cases c={2,3} are treated.
948 static DisasCond
do_log_cond(unsigned cf
, TCGv_reg res
)
952 case 9: /* undef, C */
953 case 11: /* undef, C & !Z */
954 case 12: /* undef, V */
955 return cond_make_f();
958 case 8: /* undef, !C */
959 case 10: /* undef, !C | Z */
960 case 13: /* undef, !V */
961 return cond_make_t();
964 return cond_make_0(TCG_COND_EQ
, res
);
966 return cond_make_0(TCG_COND_NE
, res
);
968 return cond_make_0(TCG_COND_LT
, res
);
970 return cond_make_0(TCG_COND_GE
, res
);
972 return cond_make_0(TCG_COND_LE
, res
);
974 return cond_make_0(TCG_COND_GT
, res
);
978 return do_cond(cf
, res
, NULL
, NULL
);
981 g_assert_not_reached();
985 /* Similar, but for shift/extract/deposit conditions. */
987 static DisasCond
do_sed_cond(unsigned orig
, TCGv_reg res
)
991 /* Convert the compressed condition codes to standard.
992 0-2 are the same as logicals (nv,<,<=), while 3 is OD.
993 4-7 are the reverse of 0-3. */
1000 return do_log_cond(c
* 2 + f
, res
);
1003 /* Similar, but for unit conditions. */
1005 static DisasCond
do_unit_cond(unsigned cf
, TCGv_reg res
,
1006 TCGv_reg in1
, TCGv_reg in2
)
1009 TCGv_reg tmp
, cb
= NULL
;
1012 /* Since we want to test lots of carry-out bits all at once, do not
1013 * do our normal thing and compute carry-in of bit B+1 since that
1014 * leaves us with carry bits spread across two words.
1016 cb
= tcg_temp_new();
1017 tmp
= tcg_temp_new();
1018 tcg_gen_or_reg(cb
, in1
, in2
);
1019 tcg_gen_and_reg(tmp
, in1
, in2
);
1020 tcg_gen_andc_reg(cb
, cb
, res
);
1021 tcg_gen_or_reg(cb
, cb
, tmp
);
1026 case 0: /* never / TR */
1027 case 1: /* undefined */
1028 case 5: /* undefined */
1029 cond
= cond_make_f();
1032 case 2: /* SBZ / NBZ */
1033 /* See hasless(v,1) from
1034 * https://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord
1036 tmp
= tcg_temp_new();
1037 tcg_gen_subi_reg(tmp
, res
, 0x01010101u
);
1038 tcg_gen_andc_reg(tmp
, tmp
, res
);
1039 tcg_gen_andi_reg(tmp
, tmp
, 0x80808080u
);
1040 cond
= cond_make_0(TCG_COND_NE
, tmp
);
1044 case 3: /* SHZ / NHZ */
1045 tmp
= tcg_temp_new();
1046 tcg_gen_subi_reg(tmp
, res
, 0x00010001u
);
1047 tcg_gen_andc_reg(tmp
, tmp
, res
);
1048 tcg_gen_andi_reg(tmp
, tmp
, 0x80008000u
);
1049 cond
= cond_make_0(TCG_COND_NE
, tmp
);
1053 case 4: /* SDC / NDC */
1054 tcg_gen_andi_reg(cb
, cb
, 0x88888888u
);
1055 cond
= cond_make_0(TCG_COND_NE
, cb
);
1058 case 6: /* SBC / NBC */
1059 tcg_gen_andi_reg(cb
, cb
, 0x80808080u
);
1060 cond
= cond_make_0(TCG_COND_NE
, cb
);
1063 case 7: /* SHC / NHC */
1064 tcg_gen_andi_reg(cb
, cb
, 0x80008000u
);
1065 cond
= cond_make_0(TCG_COND_NE
, cb
);
1069 g_assert_not_reached();
1075 cond
.c
= tcg_invert_cond(cond
.c
);
1081 /* Compute signed overflow for addition. */
1082 static TCGv_reg
do_add_sv(DisasContext
*ctx
, TCGv_reg res
,
1083 TCGv_reg in1
, TCGv_reg in2
)
1085 TCGv_reg sv
= get_temp(ctx
);
1086 TCGv_reg tmp
= tcg_temp_new();
1088 tcg_gen_xor_reg(sv
, res
, in1
);
1089 tcg_gen_xor_reg(tmp
, in1
, in2
);
1090 tcg_gen_andc_reg(sv
, sv
, tmp
);
1096 /* Compute signed overflow for subtraction. */
1097 static TCGv_reg
do_sub_sv(DisasContext
*ctx
, TCGv_reg res
,
1098 TCGv_reg in1
, TCGv_reg in2
)
1100 TCGv_reg sv
= get_temp(ctx
);
1101 TCGv_reg tmp
= tcg_temp_new();
1103 tcg_gen_xor_reg(sv
, res
, in1
);
1104 tcg_gen_xor_reg(tmp
, in1
, in2
);
1105 tcg_gen_and_reg(sv
, sv
, tmp
);
1111 static void do_add(DisasContext
*ctx
, unsigned rt
, TCGv_reg in1
,
1112 TCGv_reg in2
, unsigned shift
, bool is_l
,
1113 bool is_tsv
, bool is_tc
, bool is_c
, unsigned cf
)
1115 TCGv_reg dest
, cb
, cb_msb
, sv
, tmp
;
1116 unsigned c
= cf
>> 1;
1119 dest
= tcg_temp_new();
1124 tmp
= get_temp(ctx
);
1125 tcg_gen_shli_reg(tmp
, in1
, shift
);
1129 if (!is_l
|| cond_need_cb(c
)) {
1130 TCGv_reg zero
= tcg_constant_reg(0);
1131 cb_msb
= get_temp(ctx
);
1132 tcg_gen_add2_reg(dest
, cb_msb
, in1
, zero
, in2
, zero
);
1134 tcg_gen_add2_reg(dest
, cb_msb
, dest
, cb_msb
, cpu_psw_cb_msb
, zero
);
1138 tcg_gen_xor_reg(cb
, in1
, in2
);
1139 tcg_gen_xor_reg(cb
, cb
, dest
);
1142 tcg_gen_add_reg(dest
, in1
, in2
);
1144 tcg_gen_add_reg(dest
, dest
, cpu_psw_cb_msb
);
1148 /* Compute signed overflow if required. */
1150 if (is_tsv
|| cond_need_sv(c
)) {
1151 sv
= do_add_sv(ctx
, dest
, in1
, in2
);
1153 /* ??? Need to include overflow from shift. */
1154 gen_helper_tsv(cpu_env
, sv
);
1158 /* Emit any conditional trap before any writeback. */
1159 cond
= do_cond(cf
, dest
, cb_msb
, sv
);
1161 tmp
= tcg_temp_new();
1162 tcg_gen_setcond_reg(cond
.c
, tmp
, cond
.a0
, cond
.a1
);
1163 gen_helper_tcond(cpu_env
, tmp
);
1167 /* Write back the result. */
1169 save_or_nullify(ctx
, cpu_psw_cb
, cb
);
1170 save_or_nullify(ctx
, cpu_psw_cb_msb
, cb_msb
);
1172 save_gpr(ctx
, rt
, dest
);
1173 tcg_temp_free(dest
);
1175 /* Install the new nullification. */
1176 cond_free(&ctx
->null_cond
);
1177 ctx
->null_cond
= cond
;
1180 static bool do_add_reg(DisasContext
*ctx
, arg_rrr_cf_sh
*a
,
1181 bool is_l
, bool is_tsv
, bool is_tc
, bool is_c
)
1183 TCGv_reg tcg_r1
, tcg_r2
;
1188 tcg_r1
= load_gpr(ctx
, a
->r1
);
1189 tcg_r2
= load_gpr(ctx
, a
->r2
);
1190 do_add(ctx
, a
->t
, tcg_r1
, tcg_r2
, a
->sh
, is_l
, is_tsv
, is_tc
, is_c
, a
->cf
);
1191 return nullify_end(ctx
);
1194 static bool do_add_imm(DisasContext
*ctx
, arg_rri_cf
*a
,
1195 bool is_tsv
, bool is_tc
)
1197 TCGv_reg tcg_im
, tcg_r2
;
1202 tcg_im
= load_const(ctx
, a
->i
);
1203 tcg_r2
= load_gpr(ctx
, a
->r
);
1204 do_add(ctx
, a
->t
, tcg_im
, tcg_r2
, 0, 0, is_tsv
, is_tc
, 0, a
->cf
);
1205 return nullify_end(ctx
);
1208 static void do_sub(DisasContext
*ctx
, unsigned rt
, TCGv_reg in1
,
1209 TCGv_reg in2
, bool is_tsv
, bool is_b
,
1210 bool is_tc
, unsigned cf
)
1212 TCGv_reg dest
, sv
, cb
, cb_msb
, zero
, tmp
;
1213 unsigned c
= cf
>> 1;
1216 dest
= tcg_temp_new();
1217 cb
= tcg_temp_new();
1218 cb_msb
= tcg_temp_new();
1220 zero
= tcg_constant_reg(0);
1222 /* DEST,C = IN1 + ~IN2 + C. */
1223 tcg_gen_not_reg(cb
, in2
);
1224 tcg_gen_add2_reg(dest
, cb_msb
, in1
, zero
, cpu_psw_cb_msb
, zero
);
1225 tcg_gen_add2_reg(dest
, cb_msb
, dest
, cb_msb
, cb
, zero
);
1226 tcg_gen_xor_reg(cb
, cb
, in1
);
1227 tcg_gen_xor_reg(cb
, cb
, dest
);
1229 /* DEST,C = IN1 + ~IN2 + 1. We can produce the same result in fewer
1230 operations by seeding the high word with 1 and subtracting. */
1231 tcg_gen_movi_reg(cb_msb
, 1);
1232 tcg_gen_sub2_reg(dest
, cb_msb
, in1
, cb_msb
, in2
, zero
);
1233 tcg_gen_eqv_reg(cb
, in1
, in2
);
1234 tcg_gen_xor_reg(cb
, cb
, dest
);
1237 /* Compute signed overflow if required. */
1239 if (is_tsv
|| cond_need_sv(c
)) {
1240 sv
= do_sub_sv(ctx
, dest
, in1
, in2
);
1242 gen_helper_tsv(cpu_env
, sv
);
1246 /* Compute the condition. We cannot use the special case for borrow. */
1248 cond
= do_sub_cond(cf
, dest
, in1
, in2
, sv
);
1250 cond
= do_cond(cf
, dest
, cb_msb
, sv
);
1253 /* Emit any conditional trap before any writeback. */
1255 tmp
= tcg_temp_new();
1256 tcg_gen_setcond_reg(cond
.c
, tmp
, cond
.a0
, cond
.a1
);
1257 gen_helper_tcond(cpu_env
, tmp
);
1261 /* Write back the result. */
1262 save_or_nullify(ctx
, cpu_psw_cb
, cb
);
1263 save_or_nullify(ctx
, cpu_psw_cb_msb
, cb_msb
);
1264 save_gpr(ctx
, rt
, dest
);
1265 tcg_temp_free(dest
);
1267 tcg_temp_free(cb_msb
);
1269 /* Install the new nullification. */
1270 cond_free(&ctx
->null_cond
);
1271 ctx
->null_cond
= cond
;
1274 static bool do_sub_reg(DisasContext
*ctx
, arg_rrr_cf
*a
,
1275 bool is_tsv
, bool is_b
, bool is_tc
)
1277 TCGv_reg tcg_r1
, tcg_r2
;
1282 tcg_r1
= load_gpr(ctx
, a
->r1
);
1283 tcg_r2
= load_gpr(ctx
, a
->r2
);
1284 do_sub(ctx
, a
->t
, tcg_r1
, tcg_r2
, is_tsv
, is_b
, is_tc
, a
->cf
);
1285 return nullify_end(ctx
);
1288 static bool do_sub_imm(DisasContext
*ctx
, arg_rri_cf
*a
, bool is_tsv
)
1290 TCGv_reg tcg_im
, tcg_r2
;
1295 tcg_im
= load_const(ctx
, a
->i
);
1296 tcg_r2
= load_gpr(ctx
, a
->r
);
1297 do_sub(ctx
, a
->t
, tcg_im
, tcg_r2
, is_tsv
, 0, 0, a
->cf
);
1298 return nullify_end(ctx
);
1301 static void do_cmpclr(DisasContext
*ctx
, unsigned rt
, TCGv_reg in1
,
1302 TCGv_reg in2
, unsigned cf
)
1307 dest
= tcg_temp_new();
1308 tcg_gen_sub_reg(dest
, in1
, in2
);
1310 /* Compute signed overflow if required. */
1312 if (cond_need_sv(cf
>> 1)) {
1313 sv
= do_sub_sv(ctx
, dest
, in1
, in2
);
1316 /* Form the condition for the compare. */
1317 cond
= do_sub_cond(cf
, dest
, in1
, in2
, sv
);
1320 tcg_gen_movi_reg(dest
, 0);
1321 save_gpr(ctx
, rt
, dest
);
1322 tcg_temp_free(dest
);
1324 /* Install the new nullification. */
1325 cond_free(&ctx
->null_cond
);
1326 ctx
->null_cond
= cond
;
1329 static void do_log(DisasContext
*ctx
, unsigned rt
, TCGv_reg in1
,
1330 TCGv_reg in2
, unsigned cf
,
1331 void (*fn
)(TCGv_reg
, TCGv_reg
, TCGv_reg
))
1333 TCGv_reg dest
= dest_gpr(ctx
, rt
);
1335 /* Perform the operation, and writeback. */
1337 save_gpr(ctx
, rt
, dest
);
1339 /* Install the new nullification. */
1340 cond_free(&ctx
->null_cond
);
1342 ctx
->null_cond
= do_log_cond(cf
, dest
);
1346 static bool do_log_reg(DisasContext
*ctx
, arg_rrr_cf
*a
,
1347 void (*fn
)(TCGv_reg
, TCGv_reg
, TCGv_reg
))
1349 TCGv_reg tcg_r1
, tcg_r2
;
1354 tcg_r1
= load_gpr(ctx
, a
->r1
);
1355 tcg_r2
= load_gpr(ctx
, a
->r2
);
1356 do_log(ctx
, a
->t
, tcg_r1
, tcg_r2
, a
->cf
, fn
);
1357 return nullify_end(ctx
);
1360 static void do_unit(DisasContext
*ctx
, unsigned rt
, TCGv_reg in1
,
1361 TCGv_reg in2
, unsigned cf
, bool is_tc
,
1362 void (*fn
)(TCGv_reg
, TCGv_reg
, TCGv_reg
))
1368 dest
= dest_gpr(ctx
, rt
);
1370 save_gpr(ctx
, rt
, dest
);
1371 cond_free(&ctx
->null_cond
);
1373 dest
= tcg_temp_new();
1376 cond
= do_unit_cond(cf
, dest
, in1
, in2
);
1379 TCGv_reg tmp
= tcg_temp_new();
1380 tcg_gen_setcond_reg(cond
.c
, tmp
, cond
.a0
, cond
.a1
);
1381 gen_helper_tcond(cpu_env
, tmp
);
1384 save_gpr(ctx
, rt
, dest
);
1386 cond_free(&ctx
->null_cond
);
1387 ctx
->null_cond
= cond
;
1391 #ifndef CONFIG_USER_ONLY
1392 /* The "normal" usage is SP >= 0, wherein SP == 0 selects the space
1393 from the top 2 bits of the base register. There are a few system
1394 instructions that have a 3-bit space specifier, for which SR0 is
1395 not special. To handle this, pass ~SP. */
1396 static TCGv_i64
space_select(DisasContext
*ctx
, int sp
, TCGv_reg base
)
1406 spc
= get_temp_tl(ctx
);
1407 load_spr(ctx
, spc
, sp
);
1410 if (ctx
->tb_flags
& TB_FLAG_SR_SAME
) {
1414 ptr
= tcg_temp_new_ptr();
1415 tmp
= tcg_temp_new();
1416 spc
= get_temp_tl(ctx
);
1418 tcg_gen_shri_reg(tmp
, base
, TARGET_REGISTER_BITS
- 5);
1419 tcg_gen_andi_reg(tmp
, tmp
, 030);
1420 tcg_gen_trunc_reg_ptr(ptr
, tmp
);
1423 tcg_gen_add_ptr(ptr
, ptr
, cpu_env
);
1424 tcg_gen_ld_i64(spc
, ptr
, offsetof(CPUHPPAState
, sr
[4]));
1425 tcg_temp_free_ptr(ptr
);
1431 static void form_gva(DisasContext
*ctx
, TCGv_tl
*pgva
, TCGv_reg
*pofs
,
1432 unsigned rb
, unsigned rx
, int scale
, target_sreg disp
,
1433 unsigned sp
, int modify
, bool is_phys
)
1435 TCGv_reg base
= load_gpr(ctx
, rb
);
1438 /* Note that RX is mutually exclusive with DISP. */
1440 ofs
= get_temp(ctx
);
1441 tcg_gen_shli_reg(ofs
, cpu_gr
[rx
], scale
);
1442 tcg_gen_add_reg(ofs
, ofs
, base
);
1443 } else if (disp
|| modify
) {
1444 ofs
= get_temp(ctx
);
1445 tcg_gen_addi_reg(ofs
, base
, disp
);
1451 #ifdef CONFIG_USER_ONLY
1452 *pgva
= (modify
<= 0 ? ofs
: base
);
1454 TCGv_tl addr
= get_temp_tl(ctx
);
1455 tcg_gen_extu_reg_tl(addr
, modify
<= 0 ? ofs
: base
);
1456 if (ctx
->tb_flags
& PSW_W
) {
1457 tcg_gen_andi_tl(addr
, addr
, 0x3fffffffffffffffull
);
1460 tcg_gen_or_tl(addr
, addr
, space_select(ctx
, sp
, base
));
1466 /* Emit a memory load. The modify parameter should be
1467 * < 0 for pre-modify,
1468 * > 0 for post-modify,
1469 * = 0 for no base register update.
1471 static void do_load_32(DisasContext
*ctx
, TCGv_i32 dest
, unsigned rb
,
1472 unsigned rx
, int scale
, target_sreg disp
,
1473 unsigned sp
, int modify
, MemOp mop
)
1478 /* Caller uses nullify_over/nullify_end. */
1479 assert(ctx
->null_cond
.c
== TCG_COND_NEVER
);
1481 form_gva(ctx
, &addr
, &ofs
, rb
, rx
, scale
, disp
, sp
, modify
,
1482 ctx
->mmu_idx
== MMU_PHYS_IDX
);
1483 tcg_gen_qemu_ld_reg(dest
, addr
, ctx
->mmu_idx
, mop
);
1485 save_gpr(ctx
, rb
, ofs
);
1489 static void do_load_64(DisasContext
*ctx
, TCGv_i64 dest
, unsigned rb
,
1490 unsigned rx
, int scale
, target_sreg disp
,
1491 unsigned sp
, int modify
, MemOp mop
)
1496 /* Caller uses nullify_over/nullify_end. */
1497 assert(ctx
->null_cond
.c
== TCG_COND_NEVER
);
1499 form_gva(ctx
, &addr
, &ofs
, rb
, rx
, scale
, disp
, sp
, modify
,
1500 ctx
->mmu_idx
== MMU_PHYS_IDX
);
1501 tcg_gen_qemu_ld_i64(dest
, addr
, ctx
->mmu_idx
, mop
);
1503 save_gpr(ctx
, rb
, ofs
);
1507 static void do_store_32(DisasContext
*ctx
, TCGv_i32 src
, unsigned rb
,
1508 unsigned rx
, int scale
, target_sreg disp
,
1509 unsigned sp
, int modify
, MemOp mop
)
1514 /* Caller uses nullify_over/nullify_end. */
1515 assert(ctx
->null_cond
.c
== TCG_COND_NEVER
);
1517 form_gva(ctx
, &addr
, &ofs
, rb
, rx
, scale
, disp
, sp
, modify
,
1518 ctx
->mmu_idx
== MMU_PHYS_IDX
);
1519 tcg_gen_qemu_st_i32(src
, addr
, ctx
->mmu_idx
, mop
);
1521 save_gpr(ctx
, rb
, ofs
);
1525 static void do_store_64(DisasContext
*ctx
, TCGv_i64 src
, unsigned rb
,
1526 unsigned rx
, int scale
, target_sreg disp
,
1527 unsigned sp
, int modify
, MemOp mop
)
1532 /* Caller uses nullify_over/nullify_end. */
1533 assert(ctx
->null_cond
.c
== TCG_COND_NEVER
);
1535 form_gva(ctx
, &addr
, &ofs
, rb
, rx
, scale
, disp
, sp
, modify
,
1536 ctx
->mmu_idx
== MMU_PHYS_IDX
);
1537 tcg_gen_qemu_st_i64(src
, addr
, ctx
->mmu_idx
, mop
);
1539 save_gpr(ctx
, rb
, ofs
);
1543 #if TARGET_REGISTER_BITS == 64
1544 #define do_load_reg do_load_64
1545 #define do_store_reg do_store_64
1547 #define do_load_reg do_load_32
1548 #define do_store_reg do_store_32
1551 static bool do_load(DisasContext
*ctx
, unsigned rt
, unsigned rb
,
1552 unsigned rx
, int scale
, target_sreg disp
,
1553 unsigned sp
, int modify
, MemOp mop
)
1560 /* No base register update. */
1561 dest
= dest_gpr(ctx
, rt
);
1563 /* Make sure if RT == RB, we see the result of the load. */
1564 dest
= get_temp(ctx
);
1566 do_load_reg(ctx
, dest
, rb
, rx
, scale
, disp
, sp
, modify
, mop
);
1567 save_gpr(ctx
, rt
, dest
);
1569 return nullify_end(ctx
);
1572 static bool do_floadw(DisasContext
*ctx
, unsigned rt
, unsigned rb
,
1573 unsigned rx
, int scale
, target_sreg disp
,
1574 unsigned sp
, int modify
)
1580 tmp
= tcg_temp_new_i32();
1581 do_load_32(ctx
, tmp
, rb
, rx
, scale
, disp
, sp
, modify
, MO_TEUL
);
1582 save_frw_i32(rt
, tmp
);
1583 tcg_temp_free_i32(tmp
);
1586 gen_helper_loaded_fr0(cpu_env
);
1589 return nullify_end(ctx
);
1592 static bool trans_fldw(DisasContext
*ctx
, arg_ldst
*a
)
1594 return do_floadw(ctx
, a
->t
, a
->b
, a
->x
, a
->scale
? 2 : 0,
1595 a
->disp
, a
->sp
, a
->m
);
1598 static bool do_floadd(DisasContext
*ctx
, unsigned rt
, unsigned rb
,
1599 unsigned rx
, int scale
, target_sreg disp
,
1600 unsigned sp
, int modify
)
1606 tmp
= tcg_temp_new_i64();
1607 do_load_64(ctx
, tmp
, rb
, rx
, scale
, disp
, sp
, modify
, MO_TEQ
);
1609 tcg_temp_free_i64(tmp
);
1612 gen_helper_loaded_fr0(cpu_env
);
1615 return nullify_end(ctx
);
1618 static bool trans_fldd(DisasContext
*ctx
, arg_ldst
*a
)
1620 return do_floadd(ctx
, a
->t
, a
->b
, a
->x
, a
->scale
? 3 : 0,
1621 a
->disp
, a
->sp
, a
->m
);
1624 static bool do_store(DisasContext
*ctx
, unsigned rt
, unsigned rb
,
1625 target_sreg disp
, unsigned sp
,
1626 int modify
, MemOp mop
)
1629 do_store_reg(ctx
, load_gpr(ctx
, rt
), rb
, 0, 0, disp
, sp
, modify
, mop
);
1630 return nullify_end(ctx
);
1633 static bool do_fstorew(DisasContext
*ctx
, unsigned rt
, unsigned rb
,
1634 unsigned rx
, int scale
, target_sreg disp
,
1635 unsigned sp
, int modify
)
1641 tmp
= load_frw_i32(rt
);
1642 do_store_32(ctx
, tmp
, rb
, rx
, scale
, disp
, sp
, modify
, MO_TEUL
);
1643 tcg_temp_free_i32(tmp
);
1645 return nullify_end(ctx
);
1648 static bool trans_fstw(DisasContext
*ctx
, arg_ldst
*a
)
1650 return do_fstorew(ctx
, a
->t
, a
->b
, a
->x
, a
->scale
? 2 : 0,
1651 a
->disp
, a
->sp
, a
->m
);
1654 static bool do_fstored(DisasContext
*ctx
, unsigned rt
, unsigned rb
,
1655 unsigned rx
, int scale
, target_sreg disp
,
1656 unsigned sp
, int modify
)
1663 do_store_64(ctx
, tmp
, rb
, rx
, scale
, disp
, sp
, modify
, MO_TEQ
);
1664 tcg_temp_free_i64(tmp
);
1666 return nullify_end(ctx
);
1669 static bool trans_fstd(DisasContext
*ctx
, arg_ldst
*a
)
1671 return do_fstored(ctx
, a
->t
, a
->b
, a
->x
, a
->scale
? 3 : 0,
1672 a
->disp
, a
->sp
, a
->m
);
1675 static bool do_fop_wew(DisasContext
*ctx
, unsigned rt
, unsigned ra
,
1676 void (*func
)(TCGv_i32
, TCGv_env
, TCGv_i32
))
1681 tmp
= load_frw0_i32(ra
);
1683 func(tmp
, cpu_env
, tmp
);
1685 save_frw_i32(rt
, tmp
);
1686 tcg_temp_free_i32(tmp
);
1687 return nullify_end(ctx
);
1690 static bool do_fop_wed(DisasContext
*ctx
, unsigned rt
, unsigned ra
,
1691 void (*func
)(TCGv_i32
, TCGv_env
, TCGv_i64
))
1698 dst
= tcg_temp_new_i32();
1700 func(dst
, cpu_env
, src
);
1702 tcg_temp_free_i64(src
);
1703 save_frw_i32(rt
, dst
);
1704 tcg_temp_free_i32(dst
);
1705 return nullify_end(ctx
);
1708 static bool do_fop_ded(DisasContext
*ctx
, unsigned rt
, unsigned ra
,
1709 void (*func
)(TCGv_i64
, TCGv_env
, TCGv_i64
))
1714 tmp
= load_frd0(ra
);
1716 func(tmp
, cpu_env
, tmp
);
1719 tcg_temp_free_i64(tmp
);
1720 return nullify_end(ctx
);
1723 static bool do_fop_dew(DisasContext
*ctx
, unsigned rt
, unsigned ra
,
1724 void (*func
)(TCGv_i64
, TCGv_env
, TCGv_i32
))
1730 src
= load_frw0_i32(ra
);
1731 dst
= tcg_temp_new_i64();
1733 func(dst
, cpu_env
, src
);
1735 tcg_temp_free_i32(src
);
1737 tcg_temp_free_i64(dst
);
1738 return nullify_end(ctx
);
1741 static bool do_fop_weww(DisasContext
*ctx
, unsigned rt
,
1742 unsigned ra
, unsigned rb
,
1743 void (*func
)(TCGv_i32
, TCGv_env
, TCGv_i32
, TCGv_i32
))
1748 a
= load_frw0_i32(ra
);
1749 b
= load_frw0_i32(rb
);
1751 func(a
, cpu_env
, a
, b
);
1753 tcg_temp_free_i32(b
);
1754 save_frw_i32(rt
, a
);
1755 tcg_temp_free_i32(a
);
1756 return nullify_end(ctx
);
1759 static bool do_fop_dedd(DisasContext
*ctx
, unsigned rt
,
1760 unsigned ra
, unsigned rb
,
1761 void (*func
)(TCGv_i64
, TCGv_env
, TCGv_i64
, TCGv_i64
))
1769 func(a
, cpu_env
, a
, b
);
1771 tcg_temp_free_i64(b
);
1773 tcg_temp_free_i64(a
);
1774 return nullify_end(ctx
);
1777 /* Emit an unconditional branch to a direct target, which may or may not
1778 have already had nullification handled. */
1779 static bool do_dbranch(DisasContext
*ctx
, target_ureg dest
,
1780 unsigned link
, bool is_n
)
1782 if (ctx
->null_cond
.c
== TCG_COND_NEVER
&& ctx
->null_lab
== NULL
) {
1784 copy_iaoq_entry(cpu_gr
[link
], ctx
->iaoq_n
, ctx
->iaoq_n_var
);
1788 ctx
->null_cond
.c
= TCG_COND_ALWAYS
;
1794 copy_iaoq_entry(cpu_gr
[link
], ctx
->iaoq_n
, ctx
->iaoq_n_var
);
1797 if (is_n
&& use_nullify_skip(ctx
)) {
1798 nullify_set(ctx
, 0);
1799 gen_goto_tb(ctx
, 0, dest
, dest
+ 4);
1801 nullify_set(ctx
, is_n
);
1802 gen_goto_tb(ctx
, 0, ctx
->iaoq_b
, dest
);
1807 nullify_set(ctx
, 0);
1808 gen_goto_tb(ctx
, 1, ctx
->iaoq_b
, ctx
->iaoq_n
);
1809 ctx
->base
.is_jmp
= DISAS_NORETURN
;
1814 /* Emit a conditional branch to a direct target. If the branch itself
1815 is nullified, we should have already used nullify_over. */
1816 static bool do_cbranch(DisasContext
*ctx
, target_sreg disp
, bool is_n
,
1819 target_ureg dest
= iaoq_dest(ctx
, disp
);
1820 TCGLabel
*taken
= NULL
;
1821 TCGCond c
= cond
->c
;
1824 assert(ctx
->null_cond
.c
== TCG_COND_NEVER
);
1826 /* Handle TRUE and NEVER as direct branches. */
1827 if (c
== TCG_COND_ALWAYS
) {
1828 return do_dbranch(ctx
, dest
, 0, is_n
&& disp
>= 0);
1830 if (c
== TCG_COND_NEVER
) {
1831 return do_dbranch(ctx
, ctx
->iaoq_n
, 0, is_n
&& disp
< 0);
1834 taken
= gen_new_label();
1835 tcg_gen_brcond_reg(c
, cond
->a0
, cond
->a1
, taken
);
1838 /* Not taken: Condition not satisfied; nullify on backward branches. */
1839 n
= is_n
&& disp
< 0;
1840 if (n
&& use_nullify_skip(ctx
)) {
1841 nullify_set(ctx
, 0);
1842 gen_goto_tb(ctx
, 0, ctx
->iaoq_n
, ctx
->iaoq_n
+ 4);
1844 if (!n
&& ctx
->null_lab
) {
1845 gen_set_label(ctx
->null_lab
);
1846 ctx
->null_lab
= NULL
;
1848 nullify_set(ctx
, n
);
1849 if (ctx
->iaoq_n
== -1) {
1850 /* The temporary iaoq_n_var died at the branch above.
1851 Regenerate it here instead of saving it. */
1852 tcg_gen_addi_reg(ctx
->iaoq_n_var
, cpu_iaoq_b
, 4);
1854 gen_goto_tb(ctx
, 0, ctx
->iaoq_b
, ctx
->iaoq_n
);
1857 gen_set_label(taken
);
1859 /* Taken: Condition satisfied; nullify on forward branches. */
1860 n
= is_n
&& disp
>= 0;
1861 if (n
&& use_nullify_skip(ctx
)) {
1862 nullify_set(ctx
, 0);
1863 gen_goto_tb(ctx
, 1, dest
, dest
+ 4);
1865 nullify_set(ctx
, n
);
1866 gen_goto_tb(ctx
, 1, ctx
->iaoq_b
, dest
);
1869 /* Not taken: the branch itself was nullified. */
1870 if (ctx
->null_lab
) {
1871 gen_set_label(ctx
->null_lab
);
1872 ctx
->null_lab
= NULL
;
1873 ctx
->base
.is_jmp
= DISAS_IAQ_N_STALE
;
1875 ctx
->base
.is_jmp
= DISAS_NORETURN
;
1880 /* Emit an unconditional branch to an indirect target. This handles
1881 nullification of the branch itself. */
1882 static bool do_ibranch(DisasContext
*ctx
, TCGv_reg dest
,
1883 unsigned link
, bool is_n
)
1885 TCGv_reg a0
, a1
, next
, tmp
;
1888 assert(ctx
->null_lab
== NULL
);
1890 if (ctx
->null_cond
.c
== TCG_COND_NEVER
) {
1892 copy_iaoq_entry(cpu_gr
[link
], ctx
->iaoq_n
, ctx
->iaoq_n_var
);
1894 next
= get_temp(ctx
);
1895 tcg_gen_mov_reg(next
, dest
);
1897 if (use_nullify_skip(ctx
)) {
1898 tcg_gen_mov_reg(cpu_iaoq_f
, next
);
1899 tcg_gen_addi_reg(cpu_iaoq_b
, next
, 4);
1900 nullify_set(ctx
, 0);
1901 ctx
->base
.is_jmp
= DISAS_IAQ_N_UPDATED
;
1904 ctx
->null_cond
.c
= TCG_COND_ALWAYS
;
1907 ctx
->iaoq_n_var
= next
;
1908 } else if (is_n
&& use_nullify_skip(ctx
)) {
1909 /* The (conditional) branch, B, nullifies the next insn, N,
1910 and we're allowed to skip execution N (no single-step or
1911 tracepoint in effect). Since the goto_ptr that we must use
1912 for the indirect branch consumes no special resources, we
1913 can (conditionally) skip B and continue execution. */
1914 /* The use_nullify_skip test implies we have a known control path. */
1915 tcg_debug_assert(ctx
->iaoq_b
!= -1);
1916 tcg_debug_assert(ctx
->iaoq_n
!= -1);
1918 /* We do have to handle the non-local temporary, DEST, before
1919 branching. Since IOAQ_F is not really live at this point, we
1920 can simply store DEST optimistically. Similarly with IAOQ_B. */
1921 tcg_gen_mov_reg(cpu_iaoq_f
, dest
);
1922 tcg_gen_addi_reg(cpu_iaoq_b
, dest
, 4);
1926 tcg_gen_movi_reg(cpu_gr
[link
], ctx
->iaoq_n
);
1928 tcg_gen_lookup_and_goto_ptr();
1929 return nullify_end(ctx
);
1931 c
= ctx
->null_cond
.c
;
1932 a0
= ctx
->null_cond
.a0
;
1933 a1
= ctx
->null_cond
.a1
;
1935 tmp
= tcg_temp_new();
1936 next
= get_temp(ctx
);
1938 copy_iaoq_entry(tmp
, ctx
->iaoq_n
, ctx
->iaoq_n_var
);
1939 tcg_gen_movcond_reg(c
, next
, a0
, a1
, tmp
, dest
);
1941 ctx
->iaoq_n_var
= next
;
1944 tcg_gen_movcond_reg(c
, cpu_gr
[link
], a0
, a1
, cpu_gr
[link
], tmp
);
1948 /* The branch nullifies the next insn, which means the state of N
1949 after the branch is the inverse of the state of N that applied
1951 tcg_gen_setcond_reg(tcg_invert_cond(c
), cpu_psw_n
, a0
, a1
);
1952 cond_free(&ctx
->null_cond
);
1953 ctx
->null_cond
= cond_make_n();
1954 ctx
->psw_n_nonzero
= true;
1956 cond_free(&ctx
->null_cond
);
1963 * if (IAOQ_Front{30..31} < GR[b]{30..31})
1964 * IAOQ_Next{30..31} ← GR[b]{30..31};
1966 * IAOQ_Next{30..31} ← IAOQ_Front{30..31};
1967 * which keeps the privilege level from being increased.
1969 static TCGv_reg
do_ibranch_priv(DisasContext
*ctx
, TCGv_reg offset
)
1972 switch (ctx
->privilege
) {
1974 /* Privilege 0 is maximum and is allowed to decrease. */
1977 /* Privilege 3 is minimum and is never allowed to increase. */
1978 dest
= get_temp(ctx
);
1979 tcg_gen_ori_reg(dest
, offset
, 3);
1982 dest
= get_temp(ctx
);
1983 tcg_gen_andi_reg(dest
, offset
, -4);
1984 tcg_gen_ori_reg(dest
, dest
, ctx
->privilege
);
1985 tcg_gen_movcond_reg(TCG_COND_GTU
, dest
, dest
, offset
, dest
, offset
);
1991 #ifdef CONFIG_USER_ONLY
1992 /* On Linux, page zero is normally marked execute only + gateway.
1993 Therefore normal read or write is supposed to fail, but specific
1994 offsets have kernel code mapped to raise permissions to implement
1995 system calls. Handling this via an explicit check here, rather
1996 in than the "be disp(sr2,r0)" instruction that probably sent us
1997 here, is the easiest way to handle the branch delay slot on the
1998 aforementioned BE. */
1999 static void do_page_zero(DisasContext
*ctx
)
2001 /* If by some means we get here with PSW[N]=1, that implies that
2002 the B,GATE instruction would be skipped, and we'd fault on the
2003 next insn within the privilaged page. */
2004 switch (ctx
->null_cond
.c
) {
2005 case TCG_COND_NEVER
:
2007 case TCG_COND_ALWAYS
:
2008 tcg_gen_movi_reg(cpu_psw_n
, 0);
2011 /* Since this is always the first (and only) insn within the
2012 TB, we should know the state of PSW[N] from TB->FLAGS. */
2013 g_assert_not_reached();
2016 /* Check that we didn't arrive here via some means that allowed
2017 non-sequential instruction execution. Normally the PSW[B] bit
2018 detects this by disallowing the B,GATE instruction to execute
2019 under such conditions. */
2020 if (ctx
->iaoq_b
!= ctx
->iaoq_f
+ 4) {
2024 switch (ctx
->iaoq_f
& -4) {
2025 case 0x00: /* Null pointer call */
2026 gen_excp_1(EXCP_IMP
);
2027 ctx
->base
.is_jmp
= DISAS_NORETURN
;
2030 case 0xb0: /* LWS */
2031 gen_excp_1(EXCP_SYSCALL_LWS
);
2032 ctx
->base
.is_jmp
= DISAS_NORETURN
;
2035 case 0xe0: /* SET_THREAD_POINTER */
2036 tcg_gen_st_reg(cpu_gr
[26], cpu_env
, offsetof(CPUHPPAState
, cr
[27]));
2037 tcg_gen_ori_reg(cpu_iaoq_f
, cpu_gr
[31], 3);
2038 tcg_gen_addi_reg(cpu_iaoq_b
, cpu_iaoq_f
, 4);
2039 ctx
->base
.is_jmp
= DISAS_IAQ_N_UPDATED
;
2042 case 0x100: /* SYSCALL */
2043 gen_excp_1(EXCP_SYSCALL
);
2044 ctx
->base
.is_jmp
= DISAS_NORETURN
;
2049 gen_excp_1(EXCP_ILL
);
2050 ctx
->base
.is_jmp
= DISAS_NORETURN
;
2056 static bool trans_nop(DisasContext
*ctx
, arg_nop
*a
)
2058 cond_free(&ctx
->null_cond
);
2062 static bool trans_break(DisasContext
*ctx
, arg_break
*a
)
2064 return gen_excp_iir(ctx
, EXCP_BREAK
);
2067 static bool trans_sync(DisasContext
*ctx
, arg_sync
*a
)
2069 /* No point in nullifying the memory barrier. */
2070 tcg_gen_mb(TCG_BAR_SC
| TCG_MO_ALL
);
2072 cond_free(&ctx
->null_cond
);
2076 static bool trans_mfia(DisasContext
*ctx
, arg_mfia
*a
)
2079 TCGv_reg tmp
= dest_gpr(ctx
, rt
);
2080 tcg_gen_movi_reg(tmp
, ctx
->iaoq_f
);
2081 save_gpr(ctx
, rt
, tmp
);
2083 cond_free(&ctx
->null_cond
);
2087 static bool trans_mfsp(DisasContext
*ctx
, arg_mfsp
*a
)
2090 unsigned rs
= a
->sp
;
2091 TCGv_i64 t0
= tcg_temp_new_i64();
2092 TCGv_reg t1
= tcg_temp_new();
2094 load_spr(ctx
, t0
, rs
);
2095 tcg_gen_shri_i64(t0
, t0
, 32);
2096 tcg_gen_trunc_i64_reg(t1
, t0
);
2098 save_gpr(ctx
, rt
, t1
);
2100 tcg_temp_free_i64(t0
);
2102 cond_free(&ctx
->null_cond
);
2106 static bool trans_mfctl(DisasContext
*ctx
, arg_mfctl
*a
)
2109 unsigned ctl
= a
->r
;
2114 #ifdef TARGET_HPPA64
2116 /* MFSAR without ,W masks low 5 bits. */
2117 tmp
= dest_gpr(ctx
, rt
);
2118 tcg_gen_andi_reg(tmp
, cpu_sar
, 31);
2119 save_gpr(ctx
, rt
, tmp
);
2123 save_gpr(ctx
, rt
, cpu_sar
);
2125 case CR_IT
: /* Interval Timer */
2126 /* FIXME: Respect PSW_S bit. */
2128 tmp
= dest_gpr(ctx
, rt
);
2129 if (tb_cflags(ctx
->base
.tb
) & CF_USE_ICOUNT
) {
2131 gen_helper_read_interval_timer(tmp
);
2132 ctx
->base
.is_jmp
= DISAS_IAQ_N_STALE
;
2134 gen_helper_read_interval_timer(tmp
);
2136 save_gpr(ctx
, rt
, tmp
);
2137 return nullify_end(ctx
);
2142 /* All other control registers are privileged. */
2143 CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG
);
2147 tmp
= get_temp(ctx
);
2148 tcg_gen_ld_reg(tmp
, cpu_env
, offsetof(CPUHPPAState
, cr
[ctl
]));
2149 save_gpr(ctx
, rt
, tmp
);
2152 cond_free(&ctx
->null_cond
);
2156 static bool trans_mtsp(DisasContext
*ctx
, arg_mtsp
*a
)
2159 unsigned rs
= a
->sp
;
2163 CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG
);
2167 t64
= tcg_temp_new_i64();
2168 tcg_gen_extu_reg_i64(t64
, load_gpr(ctx
, rr
));
2169 tcg_gen_shli_i64(t64
, t64
, 32);
2172 tcg_gen_st_i64(t64
, cpu_env
, offsetof(CPUHPPAState
, sr
[rs
]));
2173 ctx
->tb_flags
&= ~TB_FLAG_SR_SAME
;
2175 tcg_gen_mov_i64(cpu_sr
[rs
], t64
);
2177 tcg_temp_free_i64(t64
);
2179 return nullify_end(ctx
);
2182 static bool trans_mtctl(DisasContext
*ctx
, arg_mtctl
*a
)
2184 unsigned ctl
= a
->t
;
2188 if (ctl
== CR_SAR
) {
2189 reg
= load_gpr(ctx
, a
->r
);
2190 tmp
= tcg_temp_new();
2191 tcg_gen_andi_reg(tmp
, reg
, TARGET_REGISTER_BITS
- 1);
2192 save_or_nullify(ctx
, cpu_sar
, tmp
);
2195 cond_free(&ctx
->null_cond
);
2199 /* All other control registers are privileged or read-only. */
2200 CHECK_MOST_PRIVILEGED(EXCP_PRIV_REG
);
2202 #ifndef CONFIG_USER_ONLY
2204 reg
= load_gpr(ctx
, a
->r
);
2208 gen_helper_write_interval_timer(cpu_env
, reg
);
2211 gen_helper_write_eirr(cpu_env
, reg
);
2214 gen_helper_write_eiem(cpu_env
, reg
);
2215 ctx
->base
.is_jmp
= DISAS_IAQ_N_STALE_EXIT
;
2220 /* FIXME: Respect PSW_Q bit */
2221 /* The write advances the queue and stores to the back element. */
2222 tmp
= get_temp(ctx
);
2223 tcg_gen_ld_reg(tmp
, cpu_env
,
2224 offsetof(CPUHPPAState
, cr_back
[ctl
- CR_IIASQ
]));
2225 tcg_gen_st_reg(tmp
, cpu_env
, offsetof(CPUHPPAState
, cr
[ctl
]));
2226 tcg_gen_st_reg(reg
, cpu_env
,
2227 offsetof(CPUHPPAState
, cr_back
[ctl
- CR_IIASQ
]));
2234 tcg_gen_st_reg(reg
, cpu_env
, offsetof(CPUHPPAState
, cr
[ctl
]));
2235 #ifndef CONFIG_USER_ONLY
2236 gen_helper_change_prot_id(cpu_env
);
2241 tcg_gen_st_reg(reg
, cpu_env
, offsetof(CPUHPPAState
, cr
[ctl
]));
2244 return nullify_end(ctx
);
2248 static bool trans_mtsarcm(DisasContext
*ctx
, arg_mtsarcm
*a
)
2250 TCGv_reg tmp
= tcg_temp_new();
2252 tcg_gen_not_reg(tmp
, load_gpr(ctx
, a
->r
));
2253 tcg_gen_andi_reg(tmp
, tmp
, TARGET_REGISTER_BITS
- 1);
2254 save_or_nullify(ctx
, cpu_sar
, tmp
);
2257 cond_free(&ctx
->null_cond
);
2261 static bool trans_ldsid(DisasContext
*ctx
, arg_ldsid
*a
)
2263 TCGv_reg dest
= dest_gpr(ctx
, a
->t
);
2265 #ifdef CONFIG_USER_ONLY
2266 /* We don't implement space registers in user mode. */
2267 tcg_gen_movi_reg(dest
, 0);
2269 TCGv_i64 t0
= tcg_temp_new_i64();
2271 tcg_gen_mov_i64(t0
, space_select(ctx
, a
->sp
, load_gpr(ctx
, a
->b
)));
2272 tcg_gen_shri_i64(t0
, t0
, 32);
2273 tcg_gen_trunc_i64_reg(dest
, t0
);
2275 tcg_temp_free_i64(t0
);
2277 save_gpr(ctx
, a
->t
, dest
);
2279 cond_free(&ctx
->null_cond
);
2283 static bool trans_rsm(DisasContext
*ctx
, arg_rsm
*a
)
2285 CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR
);
2286 #ifndef CONFIG_USER_ONLY
2291 tmp
= get_temp(ctx
);
2292 tcg_gen_ld_reg(tmp
, cpu_env
, offsetof(CPUHPPAState
, psw
));
2293 tcg_gen_andi_reg(tmp
, tmp
, ~a
->i
);
2294 gen_helper_swap_system_mask(tmp
, cpu_env
, tmp
);
2295 save_gpr(ctx
, a
->t
, tmp
);
2297 /* Exit the TB to recognize new interrupts, e.g. PSW_M. */
2298 ctx
->base
.is_jmp
= DISAS_IAQ_N_STALE_EXIT
;
2299 return nullify_end(ctx
);
2303 static bool trans_ssm(DisasContext
*ctx
, arg_ssm
*a
)
2305 CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR
);
2306 #ifndef CONFIG_USER_ONLY
2311 tmp
= get_temp(ctx
);
2312 tcg_gen_ld_reg(tmp
, cpu_env
, offsetof(CPUHPPAState
, psw
));
2313 tcg_gen_ori_reg(tmp
, tmp
, a
->i
);
2314 gen_helper_swap_system_mask(tmp
, cpu_env
, tmp
);
2315 save_gpr(ctx
, a
->t
, tmp
);
2317 /* Exit the TB to recognize new interrupts, e.g. PSW_I. */
2318 ctx
->base
.is_jmp
= DISAS_IAQ_N_STALE_EXIT
;
2319 return nullify_end(ctx
);
2323 static bool trans_mtsm(DisasContext
*ctx
, arg_mtsm
*a
)
2325 CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR
);
2326 #ifndef CONFIG_USER_ONLY
2330 reg
= load_gpr(ctx
, a
->r
);
2331 tmp
= get_temp(ctx
);
2332 gen_helper_swap_system_mask(tmp
, cpu_env
, reg
);
2334 /* Exit the TB to recognize new interrupts. */
2335 ctx
->base
.is_jmp
= DISAS_IAQ_N_STALE_EXIT
;
2336 return nullify_end(ctx
);
2340 static bool do_rfi(DisasContext
*ctx
, bool rfi_r
)
2342 CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR
);
2343 #ifndef CONFIG_USER_ONLY
2347 gen_helper_rfi_r(cpu_env
);
2349 gen_helper_rfi(cpu_env
);
2351 /* Exit the TB to recognize new interrupts. */
2352 if (ctx
->base
.singlestep_enabled
) {
2353 gen_excp_1(EXCP_DEBUG
);
2355 tcg_gen_exit_tb(NULL
, 0);
2357 ctx
->base
.is_jmp
= DISAS_NORETURN
;
2359 return nullify_end(ctx
);
2363 static bool trans_rfi(DisasContext
*ctx
, arg_rfi
*a
)
2365 return do_rfi(ctx
, false);
2368 static bool trans_rfi_r(DisasContext
*ctx
, arg_rfi_r
*a
)
2370 return do_rfi(ctx
, true);
2373 static bool trans_halt(DisasContext
*ctx
, arg_halt
*a
)
2375 CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR
);
2376 #ifndef CONFIG_USER_ONLY
2378 gen_helper_halt(cpu_env
);
2379 ctx
->base
.is_jmp
= DISAS_NORETURN
;
2380 return nullify_end(ctx
);
2384 static bool trans_reset(DisasContext
*ctx
, arg_reset
*a
)
2386 CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR
);
2387 #ifndef CONFIG_USER_ONLY
2389 gen_helper_reset(cpu_env
);
2390 ctx
->base
.is_jmp
= DISAS_NORETURN
;
2391 return nullify_end(ctx
);
2395 static bool trans_nop_addrx(DisasContext
*ctx
, arg_ldst
*a
)
2398 TCGv_reg dest
= dest_gpr(ctx
, a
->b
);
2399 TCGv_reg src1
= load_gpr(ctx
, a
->b
);
2400 TCGv_reg src2
= load_gpr(ctx
, a
->x
);
2402 /* The only thing we need to do is the base register modification. */
2403 tcg_gen_add_reg(dest
, src1
, src2
);
2404 save_gpr(ctx
, a
->b
, dest
);
2406 cond_free(&ctx
->null_cond
);
2410 static bool trans_probe(DisasContext
*ctx
, arg_probe
*a
)
2413 TCGv_i32 level
, want
;
2418 dest
= dest_gpr(ctx
, a
->t
);
2419 form_gva(ctx
, &addr
, &ofs
, a
->b
, 0, 0, 0, a
->sp
, 0, false);
2422 level
= tcg_constant_i32(a
->ri
);
2424 level
= tcg_temp_new_i32();
2425 tcg_gen_trunc_reg_i32(level
, load_gpr(ctx
, a
->ri
));
2426 tcg_gen_andi_i32(level
, level
, 3);
2428 want
= tcg_constant_i32(a
->write
? PAGE_WRITE
: PAGE_READ
);
2430 gen_helper_probe(dest
, cpu_env
, addr
, level
, want
);
2432 tcg_temp_free_i32(level
);
2434 save_gpr(ctx
, a
->t
, dest
);
2435 return nullify_end(ctx
);
2438 static bool trans_ixtlbx(DisasContext
*ctx
, arg_ixtlbx
*a
)
2440 CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR
);
2441 #ifndef CONFIG_USER_ONLY
2447 form_gva(ctx
, &addr
, &ofs
, a
->b
, 0, 0, 0, a
->sp
, 0, false);
2448 reg
= load_gpr(ctx
, a
->r
);
2450 gen_helper_itlba(cpu_env
, addr
, reg
);
2452 gen_helper_itlbp(cpu_env
, addr
, reg
);
2455 /* Exit TB for TLB change if mmu is enabled. */
2456 if (ctx
->tb_flags
& PSW_C
) {
2457 ctx
->base
.is_jmp
= DISAS_IAQ_N_STALE
;
2459 return nullify_end(ctx
);
2463 static bool trans_pxtlbx(DisasContext
*ctx
, arg_pxtlbx
*a
)
2465 CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR
);
2466 #ifndef CONFIG_USER_ONLY
2472 form_gva(ctx
, &addr
, &ofs
, a
->b
, a
->x
, 0, 0, a
->sp
, a
->m
, false);
2474 save_gpr(ctx
, a
->b
, ofs
);
2477 gen_helper_ptlbe(cpu_env
);
2479 gen_helper_ptlb(cpu_env
, addr
);
2482 /* Exit TB for TLB change if mmu is enabled. */
2483 if (ctx
->tb_flags
& PSW_C
) {
2484 ctx
->base
.is_jmp
= DISAS_IAQ_N_STALE
;
2486 return nullify_end(ctx
);
2491 * Implement the pcxl and pcxl2 Fast TLB Insert instructions.
2493 * https://parisc.wiki.kernel.org/images-parisc/a/a9/Pcxl2_ers.pdf
2494 * page 13-9 (195/206)
2496 static bool trans_ixtlbxf(DisasContext
*ctx
, arg_ixtlbxf
*a
)
2498 CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR
);
2499 #ifndef CONFIG_USER_ONLY
2500 TCGv_tl addr
, atl
, stl
;
2507 * if (not (pcxl or pcxl2))
2508 * return gen_illegal(ctx);
2510 * Note for future: these are 32-bit systems; no hppa64.
2513 atl
= tcg_temp_new_tl();
2514 stl
= tcg_temp_new_tl();
2515 addr
= tcg_temp_new_tl();
2517 tcg_gen_ld32u_i64(stl
, cpu_env
,
2518 a
->data
? offsetof(CPUHPPAState
, cr
[CR_ISR
])
2519 : offsetof(CPUHPPAState
, cr
[CR_IIASQ
]));
2520 tcg_gen_ld32u_i64(atl
, cpu_env
,
2521 a
->data
? offsetof(CPUHPPAState
, cr
[CR_IOR
])
2522 : offsetof(CPUHPPAState
, cr
[CR_IIAOQ
]));
2523 tcg_gen_shli_i64(stl
, stl
, 32);
2524 tcg_gen_or_tl(addr
, atl
, stl
);
2525 tcg_temp_free_tl(atl
);
2526 tcg_temp_free_tl(stl
);
2528 reg
= load_gpr(ctx
, a
->r
);
2530 gen_helper_itlba(cpu_env
, addr
, reg
);
2532 gen_helper_itlbp(cpu_env
, addr
, reg
);
2534 tcg_temp_free_tl(addr
);
2536 /* Exit TB for TLB change if mmu is enabled. */
2537 if (ctx
->tb_flags
& PSW_C
) {
2538 ctx
->base
.is_jmp
= DISAS_IAQ_N_STALE
;
2540 return nullify_end(ctx
);
2544 static bool trans_lpa(DisasContext
*ctx
, arg_ldst
*a
)
2546 CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR
);
2547 #ifndef CONFIG_USER_ONLY
2549 TCGv_reg ofs
, paddr
;
2553 form_gva(ctx
, &vaddr
, &ofs
, a
->b
, a
->x
, 0, 0, a
->sp
, a
->m
, false);
2555 paddr
= tcg_temp_new();
2556 gen_helper_lpa(paddr
, cpu_env
, vaddr
);
2558 /* Note that physical address result overrides base modification. */
2560 save_gpr(ctx
, a
->b
, ofs
);
2562 save_gpr(ctx
, a
->t
, paddr
);
2563 tcg_temp_free(paddr
);
2565 return nullify_end(ctx
);
2569 static bool trans_lci(DisasContext
*ctx
, arg_lci
*a
)
2571 CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR
);
2573 /* The Coherence Index is an implementation-defined function of the
2574 physical address. Two addresses with the same CI have a coherent
2575 view of the cache. Our implementation is to return 0 for all,
2576 since the entire address space is coherent. */
2577 save_gpr(ctx
, a
->t
, tcg_constant_reg(0));
2579 cond_free(&ctx
->null_cond
);
2583 static bool trans_add(DisasContext
*ctx
, arg_rrr_cf_sh
*a
)
2585 return do_add_reg(ctx
, a
, false, false, false, false);
2588 static bool trans_add_l(DisasContext
*ctx
, arg_rrr_cf_sh
*a
)
2590 return do_add_reg(ctx
, a
, true, false, false, false);
2593 static bool trans_add_tsv(DisasContext
*ctx
, arg_rrr_cf_sh
*a
)
2595 return do_add_reg(ctx
, a
, false, true, false, false);
2598 static bool trans_add_c(DisasContext
*ctx
, arg_rrr_cf_sh
*a
)
2600 return do_add_reg(ctx
, a
, false, false, false, true);
2603 static bool trans_add_c_tsv(DisasContext
*ctx
, arg_rrr_cf_sh
*a
)
2605 return do_add_reg(ctx
, a
, false, true, false, true);
2608 static bool trans_sub(DisasContext
*ctx
, arg_rrr_cf
*a
)
2610 return do_sub_reg(ctx
, a
, false, false, false);
2613 static bool trans_sub_tsv(DisasContext
*ctx
, arg_rrr_cf
*a
)
2615 return do_sub_reg(ctx
, a
, true, false, false);
2618 static bool trans_sub_tc(DisasContext
*ctx
, arg_rrr_cf
*a
)
2620 return do_sub_reg(ctx
, a
, false, false, true);
2623 static bool trans_sub_tsv_tc(DisasContext
*ctx
, arg_rrr_cf
*a
)
2625 return do_sub_reg(ctx
, a
, true, false, true);
2628 static bool trans_sub_b(DisasContext
*ctx
, arg_rrr_cf
*a
)
2630 return do_sub_reg(ctx
, a
, false, true, false);
2633 static bool trans_sub_b_tsv(DisasContext
*ctx
, arg_rrr_cf
*a
)
2635 return do_sub_reg(ctx
, a
, true, true, false);
2638 static bool trans_andcm(DisasContext
*ctx
, arg_rrr_cf
*a
)
2640 return do_log_reg(ctx
, a
, tcg_gen_andc_reg
);
2643 static bool trans_and(DisasContext
*ctx
, arg_rrr_cf
*a
)
2645 return do_log_reg(ctx
, a
, tcg_gen_and_reg
);
2648 static bool trans_or(DisasContext
*ctx
, arg_rrr_cf
*a
)
2651 unsigned r2
= a
->r2
;
2652 unsigned r1
= a
->r1
;
2655 if (rt
== 0) { /* NOP */
2656 cond_free(&ctx
->null_cond
);
2659 if (r2
== 0) { /* COPY */
2661 TCGv_reg dest
= dest_gpr(ctx
, rt
);
2662 tcg_gen_movi_reg(dest
, 0);
2663 save_gpr(ctx
, rt
, dest
);
2665 save_gpr(ctx
, rt
, cpu_gr
[r1
]);
2667 cond_free(&ctx
->null_cond
);
2670 #ifndef CONFIG_USER_ONLY
2671 /* These are QEMU extensions and are nops in the real architecture:
2673 * or %r10,%r10,%r10 -- idle loop; wait for interrupt
2674 * or %r31,%r31,%r31 -- death loop; offline cpu
2675 * currently implemented as idle.
2677 if ((rt
== 10 || rt
== 31) && r1
== rt
&& r2
== rt
) { /* PAUSE */
2678 /* No need to check for supervisor, as userland can only pause
2679 until the next timer interrupt. */
2682 /* Advance the instruction queue. */
2683 copy_iaoq_entry(cpu_iaoq_f
, ctx
->iaoq_b
, cpu_iaoq_b
);
2684 copy_iaoq_entry(cpu_iaoq_b
, ctx
->iaoq_n
, ctx
->iaoq_n_var
);
2685 nullify_set(ctx
, 0);
2687 /* Tell the qemu main loop to halt until this cpu has work. */
2688 tcg_gen_st_i32(tcg_constant_i32(1), cpu_env
,
2689 offsetof(CPUState
, halted
) - offsetof(HPPACPU
, env
));
2690 gen_excp_1(EXCP_HALTED
);
2691 ctx
->base
.is_jmp
= DISAS_NORETURN
;
2693 return nullify_end(ctx
);
2697 return do_log_reg(ctx
, a
, tcg_gen_or_reg
);
2700 static bool trans_xor(DisasContext
*ctx
, arg_rrr_cf
*a
)
2702 return do_log_reg(ctx
, a
, tcg_gen_xor_reg
);
2705 static bool trans_cmpclr(DisasContext
*ctx
, arg_rrr_cf
*a
)
2707 TCGv_reg tcg_r1
, tcg_r2
;
2712 tcg_r1
= load_gpr(ctx
, a
->r1
);
2713 tcg_r2
= load_gpr(ctx
, a
->r2
);
2714 do_cmpclr(ctx
, a
->t
, tcg_r1
, tcg_r2
, a
->cf
);
2715 return nullify_end(ctx
);
2718 static bool trans_uxor(DisasContext
*ctx
, arg_rrr_cf
*a
)
2720 TCGv_reg tcg_r1
, tcg_r2
;
2725 tcg_r1
= load_gpr(ctx
, a
->r1
);
2726 tcg_r2
= load_gpr(ctx
, a
->r2
);
2727 do_unit(ctx
, a
->t
, tcg_r1
, tcg_r2
, a
->cf
, false, tcg_gen_xor_reg
);
2728 return nullify_end(ctx
);
2731 static bool do_uaddcm(DisasContext
*ctx
, arg_rrr_cf
*a
, bool is_tc
)
2733 TCGv_reg tcg_r1
, tcg_r2
, tmp
;
2738 tcg_r1
= load_gpr(ctx
, a
->r1
);
2739 tcg_r2
= load_gpr(ctx
, a
->r2
);
2740 tmp
= get_temp(ctx
);
2741 tcg_gen_not_reg(tmp
, tcg_r2
);
2742 do_unit(ctx
, a
->t
, tcg_r1
, tmp
, a
->cf
, is_tc
, tcg_gen_add_reg
);
2743 return nullify_end(ctx
);
2746 static bool trans_uaddcm(DisasContext
*ctx
, arg_rrr_cf
*a
)
2748 return do_uaddcm(ctx
, a
, false);
2751 static bool trans_uaddcm_tc(DisasContext
*ctx
, arg_rrr_cf
*a
)
2753 return do_uaddcm(ctx
, a
, true);
2756 static bool do_dcor(DisasContext
*ctx
, arg_rr_cf
*a
, bool is_i
)
2762 tmp
= get_temp(ctx
);
2763 tcg_gen_shri_reg(tmp
, cpu_psw_cb
, 3);
2765 tcg_gen_not_reg(tmp
, tmp
);
2767 tcg_gen_andi_reg(tmp
, tmp
, 0x11111111);
2768 tcg_gen_muli_reg(tmp
, tmp
, 6);
2769 do_unit(ctx
, a
->t
, load_gpr(ctx
, a
->r
), tmp
, a
->cf
, false,
2770 is_i
? tcg_gen_add_reg
: tcg_gen_sub_reg
);
2771 return nullify_end(ctx
);
2774 static bool trans_dcor(DisasContext
*ctx
, arg_rr_cf
*a
)
2776 return do_dcor(ctx
, a
, false);
2779 static bool trans_dcor_i(DisasContext
*ctx
, arg_rr_cf
*a
)
2781 return do_dcor(ctx
, a
, true);
2784 static bool trans_ds(DisasContext
*ctx
, arg_rrr_cf
*a
)
2786 TCGv_reg dest
, add1
, add2
, addc
, zero
, in1
, in2
;
2790 in1
= load_gpr(ctx
, a
->r1
);
2791 in2
= load_gpr(ctx
, a
->r2
);
2793 add1
= tcg_temp_new();
2794 add2
= tcg_temp_new();
2795 addc
= tcg_temp_new();
2796 dest
= tcg_temp_new();
2797 zero
= tcg_constant_reg(0);
2799 /* Form R1 << 1 | PSW[CB]{8}. */
2800 tcg_gen_add_reg(add1
, in1
, in1
);
2801 tcg_gen_add_reg(add1
, add1
, cpu_psw_cb_msb
);
2803 /* Add or subtract R2, depending on PSW[V]. Proper computation of
2804 carry{8} requires that we subtract via + ~R2 + 1, as described in
2805 the manual. By extracting and masking V, we can produce the
2806 proper inputs to the addition without movcond. */
2807 tcg_gen_sari_reg(addc
, cpu_psw_v
, TARGET_REGISTER_BITS
- 1);
2808 tcg_gen_xor_reg(add2
, in2
, addc
);
2809 tcg_gen_andi_reg(addc
, addc
, 1);
2810 /* ??? This is only correct for 32-bit. */
2811 tcg_gen_add2_i32(dest
, cpu_psw_cb_msb
, add1
, zero
, add2
, zero
);
2812 tcg_gen_add2_i32(dest
, cpu_psw_cb_msb
, dest
, cpu_psw_cb_msb
, addc
, zero
);
2814 tcg_temp_free(addc
);
2816 /* Write back the result register. */
2817 save_gpr(ctx
, a
->t
, dest
);
2819 /* Write back PSW[CB]. */
2820 tcg_gen_xor_reg(cpu_psw_cb
, add1
, add2
);
2821 tcg_gen_xor_reg(cpu_psw_cb
, cpu_psw_cb
, dest
);
2823 /* Write back PSW[V] for the division step. */
2824 tcg_gen_neg_reg(cpu_psw_v
, cpu_psw_cb_msb
);
2825 tcg_gen_xor_reg(cpu_psw_v
, cpu_psw_v
, in2
);
2827 /* Install the new nullification. */
2830 if (cond_need_sv(a
->cf
>> 1)) {
2831 /* ??? The lshift is supposed to contribute to overflow. */
2832 sv
= do_add_sv(ctx
, dest
, add1
, add2
);
2834 ctx
->null_cond
= do_cond(a
->cf
, dest
, cpu_psw_cb_msb
, sv
);
2837 tcg_temp_free(add1
);
2838 tcg_temp_free(add2
);
2839 tcg_temp_free(dest
);
2841 return nullify_end(ctx
);
2844 static bool trans_addi(DisasContext
*ctx
, arg_rri_cf
*a
)
2846 return do_add_imm(ctx
, a
, false, false);
2849 static bool trans_addi_tsv(DisasContext
*ctx
, arg_rri_cf
*a
)
2851 return do_add_imm(ctx
, a
, true, false);
2854 static bool trans_addi_tc(DisasContext
*ctx
, arg_rri_cf
*a
)
2856 return do_add_imm(ctx
, a
, false, true);
2859 static bool trans_addi_tc_tsv(DisasContext
*ctx
, arg_rri_cf
*a
)
2861 return do_add_imm(ctx
, a
, true, true);
2864 static bool trans_subi(DisasContext
*ctx
, arg_rri_cf
*a
)
2866 return do_sub_imm(ctx
, a
, false);
2869 static bool trans_subi_tsv(DisasContext
*ctx
, arg_rri_cf
*a
)
2871 return do_sub_imm(ctx
, a
, true);
2874 static bool trans_cmpiclr(DisasContext
*ctx
, arg_rri_cf
*a
)
2876 TCGv_reg tcg_im
, tcg_r2
;
2882 tcg_im
= load_const(ctx
, a
->i
);
2883 tcg_r2
= load_gpr(ctx
, a
->r
);
2884 do_cmpclr(ctx
, a
->t
, tcg_im
, tcg_r2
, a
->cf
);
2886 return nullify_end(ctx
);
2889 static bool trans_ld(DisasContext
*ctx
, arg_ldst
*a
)
2891 return do_load(ctx
, a
->t
, a
->b
, a
->x
, a
->scale
? a
->size
: 0,
2892 a
->disp
, a
->sp
, a
->m
, a
->size
| MO_TE
);
2895 static bool trans_st(DisasContext
*ctx
, arg_ldst
*a
)
2897 assert(a
->x
== 0 && a
->scale
== 0);
2898 return do_store(ctx
, a
->t
, a
->b
, a
->disp
, a
->sp
, a
->m
, a
->size
| MO_TE
);
2901 static bool trans_ldc(DisasContext
*ctx
, arg_ldst
*a
)
2903 MemOp mop
= MO_TE
| MO_ALIGN
| a
->size
;
2904 TCGv_reg zero
, dest
, ofs
;
2910 /* Base register modification. Make sure if RT == RB,
2911 we see the result of the load. */
2912 dest
= get_temp(ctx
);
2914 dest
= dest_gpr(ctx
, a
->t
);
2917 form_gva(ctx
, &addr
, &ofs
, a
->b
, a
->x
, a
->scale
? a
->size
: 0,
2918 a
->disp
, a
->sp
, a
->m
, ctx
->mmu_idx
== MMU_PHYS_IDX
);
2921 * For hppa1.1, LDCW is undefined unless aligned mod 16.
2922 * However actual hardware succeeds with aligned mod 4.
2923 * Detect this case and log a GUEST_ERROR.
2925 * TODO: HPPA64 relaxes the over-alignment requirement
2926 * with the ,co completer.
2928 gen_helper_ldc_check(addr
);
2930 zero
= tcg_constant_reg(0);
2931 tcg_gen_atomic_xchg_reg(dest
, addr
, zero
, ctx
->mmu_idx
, mop
);
2934 save_gpr(ctx
, a
->b
, ofs
);
2936 save_gpr(ctx
, a
->t
, dest
);
2938 return nullify_end(ctx
);
2941 static bool trans_stby(DisasContext
*ctx
, arg_stby
*a
)
2948 form_gva(ctx
, &addr
, &ofs
, a
->b
, 0, 0, a
->disp
, a
->sp
, a
->m
,
2949 ctx
->mmu_idx
== MMU_PHYS_IDX
);
2950 val
= load_gpr(ctx
, a
->r
);
2952 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
2953 gen_helper_stby_e_parallel(cpu_env
, addr
, val
);
2955 gen_helper_stby_e(cpu_env
, addr
, val
);
2958 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
2959 gen_helper_stby_b_parallel(cpu_env
, addr
, val
);
2961 gen_helper_stby_b(cpu_env
, addr
, val
);
2965 tcg_gen_andi_reg(ofs
, ofs
, ~3);
2966 save_gpr(ctx
, a
->b
, ofs
);
2969 return nullify_end(ctx
);
2972 static bool trans_lda(DisasContext
*ctx
, arg_ldst
*a
)
2974 int hold_mmu_idx
= ctx
->mmu_idx
;
2976 CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR
);
2977 ctx
->mmu_idx
= MMU_PHYS_IDX
;
2979 ctx
->mmu_idx
= hold_mmu_idx
;
2983 static bool trans_sta(DisasContext
*ctx
, arg_ldst
*a
)
2985 int hold_mmu_idx
= ctx
->mmu_idx
;
2987 CHECK_MOST_PRIVILEGED(EXCP_PRIV_OPR
);
2988 ctx
->mmu_idx
= MMU_PHYS_IDX
;
2990 ctx
->mmu_idx
= hold_mmu_idx
;
2994 static bool trans_ldil(DisasContext
*ctx
, arg_ldil
*a
)
2996 TCGv_reg tcg_rt
= dest_gpr(ctx
, a
->t
);
2998 tcg_gen_movi_reg(tcg_rt
, a
->i
);
2999 save_gpr(ctx
, a
->t
, tcg_rt
);
3000 cond_free(&ctx
->null_cond
);
3004 static bool trans_addil(DisasContext
*ctx
, arg_addil
*a
)
3006 TCGv_reg tcg_rt
= load_gpr(ctx
, a
->r
);
3007 TCGv_reg tcg_r1
= dest_gpr(ctx
, 1);
3009 tcg_gen_addi_reg(tcg_r1
, tcg_rt
, a
->i
);
3010 save_gpr(ctx
, 1, tcg_r1
);
3011 cond_free(&ctx
->null_cond
);
3015 static bool trans_ldo(DisasContext
*ctx
, arg_ldo
*a
)
3017 TCGv_reg tcg_rt
= dest_gpr(ctx
, a
->t
);
3019 /* Special case rb == 0, for the LDI pseudo-op.
3020 The COPY pseudo-op is handled for free within tcg_gen_addi_tl. */
3022 tcg_gen_movi_reg(tcg_rt
, a
->i
);
3024 tcg_gen_addi_reg(tcg_rt
, cpu_gr
[a
->b
], a
->i
);
3026 save_gpr(ctx
, a
->t
, tcg_rt
);
3027 cond_free(&ctx
->null_cond
);
3031 static bool do_cmpb(DisasContext
*ctx
, unsigned r
, TCGv_reg in1
,
3032 unsigned c
, unsigned f
, unsigned n
, int disp
)
3034 TCGv_reg dest
, in2
, sv
;
3037 in2
= load_gpr(ctx
, r
);
3038 dest
= get_temp(ctx
);
3040 tcg_gen_sub_reg(dest
, in1
, in2
);
3043 if (cond_need_sv(c
)) {
3044 sv
= do_sub_sv(ctx
, dest
, in1
, in2
);
3047 cond
= do_sub_cond(c
* 2 + f
, dest
, in1
, in2
, sv
);
3048 return do_cbranch(ctx
, disp
, n
, &cond
);
3051 static bool trans_cmpb(DisasContext
*ctx
, arg_cmpb
*a
)
3054 return do_cmpb(ctx
, a
->r2
, load_gpr(ctx
, a
->r1
), a
->c
, a
->f
, a
->n
, a
->disp
);
3057 static bool trans_cmpbi(DisasContext
*ctx
, arg_cmpbi
*a
)
3060 return do_cmpb(ctx
, a
->r
, load_const(ctx
, a
->i
), a
->c
, a
->f
, a
->n
, a
->disp
);
3063 static bool do_addb(DisasContext
*ctx
, unsigned r
, TCGv_reg in1
,
3064 unsigned c
, unsigned f
, unsigned n
, int disp
)
3066 TCGv_reg dest
, in2
, sv
, cb_msb
;
3069 in2
= load_gpr(ctx
, r
);
3070 dest
= tcg_temp_new();
3074 if (cond_need_cb(c
)) {
3075 cb_msb
= get_temp(ctx
);
3076 tcg_gen_movi_reg(cb_msb
, 0);
3077 tcg_gen_add2_reg(dest
, cb_msb
, in1
, cb_msb
, in2
, cb_msb
);
3079 tcg_gen_add_reg(dest
, in1
, in2
);
3081 if (cond_need_sv(c
)) {
3082 sv
= do_add_sv(ctx
, dest
, in1
, in2
);
3085 cond
= do_cond(c
* 2 + f
, dest
, cb_msb
, sv
);
3086 save_gpr(ctx
, r
, dest
);
3087 tcg_temp_free(dest
);
3088 return do_cbranch(ctx
, disp
, n
, &cond
);
3091 static bool trans_addb(DisasContext
*ctx
, arg_addb
*a
)
3094 return do_addb(ctx
, a
->r2
, load_gpr(ctx
, a
->r1
), a
->c
, a
->f
, a
->n
, a
->disp
);
3097 static bool trans_addbi(DisasContext
*ctx
, arg_addbi
*a
)
3100 return do_addb(ctx
, a
->r
, load_const(ctx
, a
->i
), a
->c
, a
->f
, a
->n
, a
->disp
);
3103 static bool trans_bb_sar(DisasContext
*ctx
, arg_bb_sar
*a
)
3105 TCGv_reg tmp
, tcg_r
;
3110 tmp
= tcg_temp_new();
3111 tcg_r
= load_gpr(ctx
, a
->r
);
3112 tcg_gen_shl_reg(tmp
, tcg_r
, cpu_sar
);
3114 cond
= cond_make_0(a
->c
? TCG_COND_GE
: TCG_COND_LT
, tmp
);
3116 return do_cbranch(ctx
, a
->disp
, a
->n
, &cond
);
3119 static bool trans_bb_imm(DisasContext
*ctx
, arg_bb_imm
*a
)
3121 TCGv_reg tmp
, tcg_r
;
3126 tmp
= tcg_temp_new();
3127 tcg_r
= load_gpr(ctx
, a
->r
);
3128 tcg_gen_shli_reg(tmp
, tcg_r
, a
->p
);
3130 cond
= cond_make_0(a
->c
? TCG_COND_GE
: TCG_COND_LT
, tmp
);
3132 return do_cbranch(ctx
, a
->disp
, a
->n
, &cond
);
3135 static bool trans_movb(DisasContext
*ctx
, arg_movb
*a
)
3142 dest
= dest_gpr(ctx
, a
->r2
);
3144 tcg_gen_movi_reg(dest
, 0);
3146 tcg_gen_mov_reg(dest
, cpu_gr
[a
->r1
]);
3149 cond
= do_sed_cond(a
->c
, dest
);
3150 return do_cbranch(ctx
, a
->disp
, a
->n
, &cond
);
3153 static bool trans_movbi(DisasContext
*ctx
, arg_movbi
*a
)
3160 dest
= dest_gpr(ctx
, a
->r
);
3161 tcg_gen_movi_reg(dest
, a
->i
);
3163 cond
= do_sed_cond(a
->c
, dest
);
3164 return do_cbranch(ctx
, a
->disp
, a
->n
, &cond
);
3167 static bool trans_shrpw_sar(DisasContext
*ctx
, arg_shrpw_sar
*a
)
3175 dest
= dest_gpr(ctx
, a
->t
);
3177 tcg_gen_ext32u_reg(dest
, load_gpr(ctx
, a
->r2
));
3178 tcg_gen_shr_reg(dest
, dest
, cpu_sar
);
3179 } else if (a
->r1
== a
->r2
) {
3180 TCGv_i32 t32
= tcg_temp_new_i32();
3181 tcg_gen_trunc_reg_i32(t32
, load_gpr(ctx
, a
->r2
));
3182 tcg_gen_rotr_i32(t32
, t32
, cpu_sar
);
3183 tcg_gen_extu_i32_reg(dest
, t32
);
3184 tcg_temp_free_i32(t32
);
3186 TCGv_i64 t
= tcg_temp_new_i64();
3187 TCGv_i64 s
= tcg_temp_new_i64();
3189 tcg_gen_concat_reg_i64(t
, load_gpr(ctx
, a
->r2
), load_gpr(ctx
, a
->r1
));
3190 tcg_gen_extu_reg_i64(s
, cpu_sar
);
3191 tcg_gen_shr_i64(t
, t
, s
);
3192 tcg_gen_trunc_i64_reg(dest
, t
);
3194 tcg_temp_free_i64(t
);
3195 tcg_temp_free_i64(s
);
3197 save_gpr(ctx
, a
->t
, dest
);
3199 /* Install the new nullification. */
3200 cond_free(&ctx
->null_cond
);
3202 ctx
->null_cond
= do_sed_cond(a
->c
, dest
);
3204 return nullify_end(ctx
);
3207 static bool trans_shrpw_imm(DisasContext
*ctx
, arg_shrpw_imm
*a
)
3209 unsigned sa
= 31 - a
->cpos
;
3216 dest
= dest_gpr(ctx
, a
->t
);
3217 t2
= load_gpr(ctx
, a
->r2
);
3218 if (a
->r1
== a
->r2
) {
3219 TCGv_i32 t32
= tcg_temp_new_i32();
3220 tcg_gen_trunc_reg_i32(t32
, t2
);
3221 tcg_gen_rotri_i32(t32
, t32
, sa
);
3222 tcg_gen_extu_i32_reg(dest
, t32
);
3223 tcg_temp_free_i32(t32
);
3224 } else if (a
->r1
== 0) {
3225 tcg_gen_extract_reg(dest
, t2
, sa
, 32 - sa
);
3227 TCGv_reg t0
= tcg_temp_new();
3228 tcg_gen_extract_reg(t0
, t2
, sa
, 32 - sa
);
3229 tcg_gen_deposit_reg(dest
, t0
, cpu_gr
[a
->r1
], 32 - sa
, sa
);
3232 save_gpr(ctx
, a
->t
, dest
);
3234 /* Install the new nullification. */
3235 cond_free(&ctx
->null_cond
);
3237 ctx
->null_cond
= do_sed_cond(a
->c
, dest
);
3239 return nullify_end(ctx
);
3242 static bool trans_extrw_sar(DisasContext
*ctx
, arg_extrw_sar
*a
)
3244 unsigned len
= 32 - a
->clen
;
3245 TCGv_reg dest
, src
, tmp
;
3251 dest
= dest_gpr(ctx
, a
->t
);
3252 src
= load_gpr(ctx
, a
->r
);
3253 tmp
= tcg_temp_new();
3255 /* Recall that SAR is using big-endian bit numbering. */
3256 tcg_gen_xori_reg(tmp
, cpu_sar
, TARGET_REGISTER_BITS
- 1);
3258 tcg_gen_sar_reg(dest
, src
, tmp
);
3259 tcg_gen_sextract_reg(dest
, dest
, 0, len
);
3261 tcg_gen_shr_reg(dest
, src
, tmp
);
3262 tcg_gen_extract_reg(dest
, dest
, 0, len
);
3265 save_gpr(ctx
, a
->t
, dest
);
3267 /* Install the new nullification. */
3268 cond_free(&ctx
->null_cond
);
3270 ctx
->null_cond
= do_sed_cond(a
->c
, dest
);
3272 return nullify_end(ctx
);
3275 static bool trans_extrw_imm(DisasContext
*ctx
, arg_extrw_imm
*a
)
3277 unsigned len
= 32 - a
->clen
;
3278 unsigned cpos
= 31 - a
->pos
;
3285 dest
= dest_gpr(ctx
, a
->t
);
3286 src
= load_gpr(ctx
, a
->r
);
3288 tcg_gen_sextract_reg(dest
, src
, cpos
, len
);
3290 tcg_gen_extract_reg(dest
, src
, cpos
, len
);
3292 save_gpr(ctx
, a
->t
, dest
);
3294 /* Install the new nullification. */
3295 cond_free(&ctx
->null_cond
);
3297 ctx
->null_cond
= do_sed_cond(a
->c
, dest
);
3299 return nullify_end(ctx
);
3302 static bool trans_depwi_imm(DisasContext
*ctx
, arg_depwi_imm
*a
)
3304 unsigned len
= 32 - a
->clen
;
3305 target_sreg mask0
, mask1
;
3311 if (a
->cpos
+ len
> 32) {
3315 dest
= dest_gpr(ctx
, a
->t
);
3316 mask0
= deposit64(0, a
->cpos
, len
, a
->i
);
3317 mask1
= deposit64(-1, a
->cpos
, len
, a
->i
);
3320 TCGv_reg src
= load_gpr(ctx
, a
->t
);
3322 tcg_gen_andi_reg(dest
, src
, mask1
);
3325 tcg_gen_ori_reg(dest
, src
, mask0
);
3327 tcg_gen_movi_reg(dest
, mask0
);
3329 save_gpr(ctx
, a
->t
, dest
);
3331 /* Install the new nullification. */
3332 cond_free(&ctx
->null_cond
);
3334 ctx
->null_cond
= do_sed_cond(a
->c
, dest
);
3336 return nullify_end(ctx
);
3339 static bool trans_depw_imm(DisasContext
*ctx
, arg_depw_imm
*a
)
3341 unsigned rs
= a
->nz
? a
->t
: 0;
3342 unsigned len
= 32 - a
->clen
;
3348 if (a
->cpos
+ len
> 32) {
3352 dest
= dest_gpr(ctx
, a
->t
);
3353 val
= load_gpr(ctx
, a
->r
);
3355 tcg_gen_deposit_z_reg(dest
, val
, a
->cpos
, len
);
3357 tcg_gen_deposit_reg(dest
, cpu_gr
[rs
], val
, a
->cpos
, len
);
3359 save_gpr(ctx
, a
->t
, dest
);
3361 /* Install the new nullification. */
3362 cond_free(&ctx
->null_cond
);
3364 ctx
->null_cond
= do_sed_cond(a
->c
, dest
);
3366 return nullify_end(ctx
);
3369 static bool do_depw_sar(DisasContext
*ctx
, unsigned rt
, unsigned c
,
3370 unsigned nz
, unsigned clen
, TCGv_reg val
)
3372 unsigned rs
= nz
? rt
: 0;
3373 unsigned len
= 32 - clen
;
3374 TCGv_reg mask
, tmp
, shift
, dest
;
3375 unsigned msb
= 1U << (len
- 1);
3377 dest
= dest_gpr(ctx
, rt
);
3378 shift
= tcg_temp_new();
3379 tmp
= tcg_temp_new();
3381 /* Convert big-endian bit numbering in SAR to left-shift. */
3382 tcg_gen_xori_reg(shift
, cpu_sar
, TARGET_REGISTER_BITS
- 1);
3384 mask
= tcg_const_reg(msb
+ (msb
- 1));
3385 tcg_gen_and_reg(tmp
, val
, mask
);
3387 tcg_gen_shl_reg(mask
, mask
, shift
);
3388 tcg_gen_shl_reg(tmp
, tmp
, shift
);
3389 tcg_gen_andc_reg(dest
, cpu_gr
[rs
], mask
);
3390 tcg_gen_or_reg(dest
, dest
, tmp
);
3392 tcg_gen_shl_reg(dest
, tmp
, shift
);
3394 tcg_temp_free(shift
);
3395 tcg_temp_free(mask
);
3397 save_gpr(ctx
, rt
, dest
);
3399 /* Install the new nullification. */
3400 cond_free(&ctx
->null_cond
);
3402 ctx
->null_cond
= do_sed_cond(c
, dest
);
3404 return nullify_end(ctx
);
3407 static bool trans_depw_sar(DisasContext
*ctx
, arg_depw_sar
*a
)
3412 return do_depw_sar(ctx
, a
->t
, a
->c
, a
->nz
, a
->clen
, load_gpr(ctx
, a
->r
));
3415 static bool trans_depwi_sar(DisasContext
*ctx
, arg_depwi_sar
*a
)
3420 return do_depw_sar(ctx
, a
->t
, a
->c
, a
->nz
, a
->clen
, load_const(ctx
, a
->i
));
3423 static bool trans_be(DisasContext
*ctx
, arg_be
*a
)
3427 #ifdef CONFIG_USER_ONLY
3428 /* ??? It seems like there should be a good way of using
3429 "be disp(sr2, r0)", the canonical gateway entry mechanism
3430 to our advantage. But that appears to be inconvenient to
3431 manage along side branch delay slots. Therefore we handle
3432 entry into the gateway page via absolute address. */
3433 /* Since we don't implement spaces, just branch. Do notice the special
3434 case of "be disp(*,r0)" using a direct branch to disp, so that we can
3435 goto_tb to the TB containing the syscall. */
3437 return do_dbranch(ctx
, a
->disp
, a
->l
, a
->n
);
3443 tmp
= get_temp(ctx
);
3444 tcg_gen_addi_reg(tmp
, load_gpr(ctx
, a
->b
), a
->disp
);
3445 tmp
= do_ibranch_priv(ctx
, tmp
);
3447 #ifdef CONFIG_USER_ONLY
3448 return do_ibranch(ctx
, tmp
, a
->l
, a
->n
);
3450 TCGv_i64 new_spc
= tcg_temp_new_i64();
3452 load_spr(ctx
, new_spc
, a
->sp
);
3454 copy_iaoq_entry(cpu_gr
[31], ctx
->iaoq_n
, ctx
->iaoq_n_var
);
3455 tcg_gen_mov_i64(cpu_sr
[0], cpu_iasq_f
);
3457 if (a
->n
&& use_nullify_skip(ctx
)) {
3458 tcg_gen_mov_reg(cpu_iaoq_f
, tmp
);
3459 tcg_gen_addi_reg(cpu_iaoq_b
, cpu_iaoq_f
, 4);
3460 tcg_gen_mov_i64(cpu_iasq_f
, new_spc
);
3461 tcg_gen_mov_i64(cpu_iasq_b
, cpu_iasq_f
);
3463 copy_iaoq_entry(cpu_iaoq_f
, ctx
->iaoq_b
, cpu_iaoq_b
);
3464 if (ctx
->iaoq_b
== -1) {
3465 tcg_gen_mov_i64(cpu_iasq_f
, cpu_iasq_b
);
3467 tcg_gen_mov_reg(cpu_iaoq_b
, tmp
);
3468 tcg_gen_mov_i64(cpu_iasq_b
, new_spc
);
3469 nullify_set(ctx
, a
->n
);
3471 tcg_temp_free_i64(new_spc
);
3472 tcg_gen_lookup_and_goto_ptr();
3473 ctx
->base
.is_jmp
= DISAS_NORETURN
;
3474 return nullify_end(ctx
);
3478 static bool trans_bl(DisasContext
*ctx
, arg_bl
*a
)
3480 return do_dbranch(ctx
, iaoq_dest(ctx
, a
->disp
), a
->l
, a
->n
);
3483 static bool trans_b_gate(DisasContext
*ctx
, arg_b_gate
*a
)
3485 target_ureg dest
= iaoq_dest(ctx
, a
->disp
);
3489 /* Make sure the caller hasn't done something weird with the queue.
3490 * ??? This is not quite the same as the PSW[B] bit, which would be
3491 * expensive to track. Real hardware will trap for
3493 * b gateway+4 (in delay slot of first branch)
3494 * However, checking for a non-sequential instruction queue *will*
3495 * diagnose the security hole
3498 * in which instructions at evil would run with increased privs.
3500 if (ctx
->iaoq_b
== -1 || ctx
->iaoq_b
!= ctx
->iaoq_f
+ 4) {
3501 return gen_illegal(ctx
);
3504 #ifndef CONFIG_USER_ONLY
3505 if (ctx
->tb_flags
& PSW_C
) {
3506 CPUHPPAState
*env
= ctx
->cs
->env_ptr
;
3507 int type
= hppa_artype_for_page(env
, ctx
->base
.pc_next
);
3508 /* If we could not find a TLB entry, then we need to generate an
3509 ITLB miss exception so the kernel will provide it.
3510 The resulting TLB fill operation will invalidate this TB and
3511 we will re-translate, at which point we *will* be able to find
3512 the TLB entry and determine if this is in fact a gateway page. */
3514 gen_excp(ctx
, EXCP_ITLB_MISS
);
3517 /* No change for non-gateway pages or for priv decrease. */
3518 if (type
>= 4 && type
- 4 < ctx
->privilege
) {
3519 dest
= deposit32(dest
, 0, 2, type
- 4);
3522 dest
&= -4; /* priv = 0 */
3527 TCGv_reg tmp
= dest_gpr(ctx
, a
->l
);
3528 if (ctx
->privilege
< 3) {
3529 tcg_gen_andi_reg(tmp
, tmp
, -4);
3531 tcg_gen_ori_reg(tmp
, tmp
, ctx
->privilege
);
3532 save_gpr(ctx
, a
->l
, tmp
);
3535 return do_dbranch(ctx
, dest
, 0, a
->n
);
3538 static bool trans_blr(DisasContext
*ctx
, arg_blr
*a
)
3541 TCGv_reg tmp
= get_temp(ctx
);
3542 tcg_gen_shli_reg(tmp
, load_gpr(ctx
, a
->x
), 3);
3543 tcg_gen_addi_reg(tmp
, tmp
, ctx
->iaoq_f
+ 8);
3544 /* The computation here never changes privilege level. */
3545 return do_ibranch(ctx
, tmp
, a
->l
, a
->n
);
3547 /* BLR R0,RX is a good way to load PC+8 into RX. */
3548 return do_dbranch(ctx
, ctx
->iaoq_f
+ 8, a
->l
, a
->n
);
3552 static bool trans_bv(DisasContext
*ctx
, arg_bv
*a
)
3557 dest
= load_gpr(ctx
, a
->b
);
3559 dest
= get_temp(ctx
);
3560 tcg_gen_shli_reg(dest
, load_gpr(ctx
, a
->x
), 3);
3561 tcg_gen_add_reg(dest
, dest
, load_gpr(ctx
, a
->b
));
3563 dest
= do_ibranch_priv(ctx
, dest
);
3564 return do_ibranch(ctx
, dest
, 0, a
->n
);
3567 static bool trans_bve(DisasContext
*ctx
, arg_bve
*a
)
3571 #ifdef CONFIG_USER_ONLY
3572 dest
= do_ibranch_priv(ctx
, load_gpr(ctx
, a
->b
));
3573 return do_ibranch(ctx
, dest
, a
->l
, a
->n
);
3576 dest
= do_ibranch_priv(ctx
, load_gpr(ctx
, a
->b
));
3578 copy_iaoq_entry(cpu_iaoq_f
, ctx
->iaoq_b
, cpu_iaoq_b
);
3579 if (ctx
->iaoq_b
== -1) {
3580 tcg_gen_mov_i64(cpu_iasq_f
, cpu_iasq_b
);
3582 copy_iaoq_entry(cpu_iaoq_b
, -1, dest
);
3583 tcg_gen_mov_i64(cpu_iasq_b
, space_select(ctx
, 0, dest
));
3585 copy_iaoq_entry(cpu_gr
[a
->l
], ctx
->iaoq_n
, ctx
->iaoq_n_var
);
3587 nullify_set(ctx
, a
->n
);
3588 tcg_gen_lookup_and_goto_ptr();
3589 ctx
->base
.is_jmp
= DISAS_NORETURN
;
3590 return nullify_end(ctx
);
3598 static void gen_fcpy_f(TCGv_i32 dst
, TCGv_env unused
, TCGv_i32 src
)
3600 tcg_gen_mov_i32(dst
, src
);
3603 static bool trans_fcpy_f(DisasContext
*ctx
, arg_fclass01
*a
)
3605 return do_fop_wew(ctx
, a
->t
, a
->r
, gen_fcpy_f
);
3608 static void gen_fcpy_d(TCGv_i64 dst
, TCGv_env unused
, TCGv_i64 src
)
3610 tcg_gen_mov_i64(dst
, src
);
3613 static bool trans_fcpy_d(DisasContext
*ctx
, arg_fclass01
*a
)
3615 return do_fop_ded(ctx
, a
->t
, a
->r
, gen_fcpy_d
);
3618 static void gen_fabs_f(TCGv_i32 dst
, TCGv_env unused
, TCGv_i32 src
)
3620 tcg_gen_andi_i32(dst
, src
, INT32_MAX
);
3623 static bool trans_fabs_f(DisasContext
*ctx
, arg_fclass01
*a
)
3625 return do_fop_wew(ctx
, a
->t
, a
->r
, gen_fabs_f
);
3628 static void gen_fabs_d(TCGv_i64 dst
, TCGv_env unused
, TCGv_i64 src
)
3630 tcg_gen_andi_i64(dst
, src
, INT64_MAX
);
3633 static bool trans_fabs_d(DisasContext
*ctx
, arg_fclass01
*a
)
3635 return do_fop_ded(ctx
, a
->t
, a
->r
, gen_fabs_d
);
3638 static bool trans_fsqrt_f(DisasContext
*ctx
, arg_fclass01
*a
)
3640 return do_fop_wew(ctx
, a
->t
, a
->r
, gen_helper_fsqrt_s
);
3643 static bool trans_fsqrt_d(DisasContext
*ctx
, arg_fclass01
*a
)
3645 return do_fop_ded(ctx
, a
->t
, a
->r
, gen_helper_fsqrt_d
);
3648 static bool trans_frnd_f(DisasContext
*ctx
, arg_fclass01
*a
)
3650 return do_fop_wew(ctx
, a
->t
, a
->r
, gen_helper_frnd_s
);
3653 static bool trans_frnd_d(DisasContext
*ctx
, arg_fclass01
*a
)
3655 return do_fop_ded(ctx
, a
->t
, a
->r
, gen_helper_frnd_d
);
3658 static void gen_fneg_f(TCGv_i32 dst
, TCGv_env unused
, TCGv_i32 src
)
3660 tcg_gen_xori_i32(dst
, src
, INT32_MIN
);
3663 static bool trans_fneg_f(DisasContext
*ctx
, arg_fclass01
*a
)
3665 return do_fop_wew(ctx
, a
->t
, a
->r
, gen_fneg_f
);
3668 static void gen_fneg_d(TCGv_i64 dst
, TCGv_env unused
, TCGv_i64 src
)
3670 tcg_gen_xori_i64(dst
, src
, INT64_MIN
);
3673 static bool trans_fneg_d(DisasContext
*ctx
, arg_fclass01
*a
)
3675 return do_fop_ded(ctx
, a
->t
, a
->r
, gen_fneg_d
);
3678 static void gen_fnegabs_f(TCGv_i32 dst
, TCGv_env unused
, TCGv_i32 src
)
3680 tcg_gen_ori_i32(dst
, src
, INT32_MIN
);
3683 static bool trans_fnegabs_f(DisasContext
*ctx
, arg_fclass01
*a
)
3685 return do_fop_wew(ctx
, a
->t
, a
->r
, gen_fnegabs_f
);
3688 static void gen_fnegabs_d(TCGv_i64 dst
, TCGv_env unused
, TCGv_i64 src
)
3690 tcg_gen_ori_i64(dst
, src
, INT64_MIN
);
3693 static bool trans_fnegabs_d(DisasContext
*ctx
, arg_fclass01
*a
)
3695 return do_fop_ded(ctx
, a
->t
, a
->r
, gen_fnegabs_d
);
3702 static bool trans_fcnv_d_f(DisasContext
*ctx
, arg_fclass01
*a
)
3704 return do_fop_wed(ctx
, a
->t
, a
->r
, gen_helper_fcnv_d_s
);
3707 static bool trans_fcnv_f_d(DisasContext
*ctx
, arg_fclass01
*a
)
3709 return do_fop_dew(ctx
, a
->t
, a
->r
, gen_helper_fcnv_s_d
);
3712 static bool trans_fcnv_w_f(DisasContext
*ctx
, arg_fclass01
*a
)
3714 return do_fop_wew(ctx
, a
->t
, a
->r
, gen_helper_fcnv_w_s
);
3717 static bool trans_fcnv_q_f(DisasContext
*ctx
, arg_fclass01
*a
)
3719 return do_fop_wed(ctx
, a
->t
, a
->r
, gen_helper_fcnv_dw_s
);
3722 static bool trans_fcnv_w_d(DisasContext
*ctx
, arg_fclass01
*a
)
3724 return do_fop_dew(ctx
, a
->t
, a
->r
, gen_helper_fcnv_w_d
);
3727 static bool trans_fcnv_q_d(DisasContext
*ctx
, arg_fclass01
*a
)
3729 return do_fop_ded(ctx
, a
->t
, a
->r
, gen_helper_fcnv_dw_d
);
3732 static bool trans_fcnv_f_w(DisasContext
*ctx
, arg_fclass01
*a
)
3734 return do_fop_wew(ctx
, a
->t
, a
->r
, gen_helper_fcnv_s_w
);
3737 static bool trans_fcnv_d_w(DisasContext
*ctx
, arg_fclass01
*a
)
3739 return do_fop_wed(ctx
, a
->t
, a
->r
, gen_helper_fcnv_d_w
);
3742 static bool trans_fcnv_f_q(DisasContext
*ctx
, arg_fclass01
*a
)
3744 return do_fop_dew(ctx
, a
->t
, a
->r
, gen_helper_fcnv_s_dw
);
3747 static bool trans_fcnv_d_q(DisasContext
*ctx
, arg_fclass01
*a
)
3749 return do_fop_ded(ctx
, a
->t
, a
->r
, gen_helper_fcnv_d_dw
);
3752 static bool trans_fcnv_t_f_w(DisasContext
*ctx
, arg_fclass01
*a
)
3754 return do_fop_wew(ctx
, a
->t
, a
->r
, gen_helper_fcnv_t_s_w
);
3757 static bool trans_fcnv_t_d_w(DisasContext
*ctx
, arg_fclass01
*a
)
3759 return do_fop_wed(ctx
, a
->t
, a
->r
, gen_helper_fcnv_t_d_w
);
3762 static bool trans_fcnv_t_f_q(DisasContext
*ctx
, arg_fclass01
*a
)
3764 return do_fop_dew(ctx
, a
->t
, a
->r
, gen_helper_fcnv_t_s_dw
);
3767 static bool trans_fcnv_t_d_q(DisasContext
*ctx
, arg_fclass01
*a
)
3769 return do_fop_ded(ctx
, a
->t
, a
->r
, gen_helper_fcnv_t_d_dw
);
3772 static bool trans_fcnv_uw_f(DisasContext
*ctx
, arg_fclass01
*a
)
3774 return do_fop_wew(ctx
, a
->t
, a
->r
, gen_helper_fcnv_uw_s
);
3777 static bool trans_fcnv_uq_f(DisasContext
*ctx
, arg_fclass01
*a
)
3779 return do_fop_wed(ctx
, a
->t
, a
->r
, gen_helper_fcnv_udw_s
);
3782 static bool trans_fcnv_uw_d(DisasContext
*ctx
, arg_fclass01
*a
)
3784 return do_fop_dew(ctx
, a
->t
, a
->r
, gen_helper_fcnv_uw_d
);
3787 static bool trans_fcnv_uq_d(DisasContext
*ctx
, arg_fclass01
*a
)
3789 return do_fop_ded(ctx
, a
->t
, a
->r
, gen_helper_fcnv_udw_d
);
3792 static bool trans_fcnv_f_uw(DisasContext
*ctx
, arg_fclass01
*a
)
3794 return do_fop_wew(ctx
, a
->t
, a
->r
, gen_helper_fcnv_s_uw
);
3797 static bool trans_fcnv_d_uw(DisasContext
*ctx
, arg_fclass01
*a
)
3799 return do_fop_wed(ctx
, a
->t
, a
->r
, gen_helper_fcnv_d_uw
);
3802 static bool trans_fcnv_f_uq(DisasContext
*ctx
, arg_fclass01
*a
)
3804 return do_fop_dew(ctx
, a
->t
, a
->r
, gen_helper_fcnv_s_udw
);
3807 static bool trans_fcnv_d_uq(DisasContext
*ctx
, arg_fclass01
*a
)
3809 return do_fop_ded(ctx
, a
->t
, a
->r
, gen_helper_fcnv_d_udw
);
3812 static bool trans_fcnv_t_f_uw(DisasContext
*ctx
, arg_fclass01
*a
)
3814 return do_fop_wew(ctx
, a
->t
, a
->r
, gen_helper_fcnv_t_s_uw
);
3817 static bool trans_fcnv_t_d_uw(DisasContext
*ctx
, arg_fclass01
*a
)
3819 return do_fop_wed(ctx
, a
->t
, a
->r
, gen_helper_fcnv_t_d_uw
);
3822 static bool trans_fcnv_t_f_uq(DisasContext
*ctx
, arg_fclass01
*a
)
3824 return do_fop_dew(ctx
, a
->t
, a
->r
, gen_helper_fcnv_t_s_udw
);
3827 static bool trans_fcnv_t_d_uq(DisasContext
*ctx
, arg_fclass01
*a
)
3829 return do_fop_ded(ctx
, a
->t
, a
->r
, gen_helper_fcnv_t_d_udw
);
3836 static bool trans_fcmp_f(DisasContext
*ctx
, arg_fclass2
*a
)
3838 TCGv_i32 ta
, tb
, tc
, ty
;
3842 ta
= load_frw0_i32(a
->r1
);
3843 tb
= load_frw0_i32(a
->r2
);
3844 ty
= tcg_constant_i32(a
->y
);
3845 tc
= tcg_constant_i32(a
->c
);
3847 gen_helper_fcmp_s(cpu_env
, ta
, tb
, ty
, tc
);
3849 tcg_temp_free_i32(ta
);
3850 tcg_temp_free_i32(tb
);
3852 return nullify_end(ctx
);
3855 static bool trans_fcmp_d(DisasContext
*ctx
, arg_fclass2
*a
)
3862 ta
= load_frd0(a
->r1
);
3863 tb
= load_frd0(a
->r2
);
3864 ty
= tcg_constant_i32(a
->y
);
3865 tc
= tcg_constant_i32(a
->c
);
3867 gen_helper_fcmp_d(cpu_env
, ta
, tb
, ty
, tc
);
3869 tcg_temp_free_i64(ta
);
3870 tcg_temp_free_i64(tb
);
3872 return nullify_end(ctx
);
3875 static bool trans_ftest(DisasContext
*ctx
, arg_ftest
*a
)
3882 tcg_gen_ld32u_reg(t
, cpu_env
, offsetof(CPUHPPAState
, fr0_shadow
));
3889 case 0: /* simple */
3890 tcg_gen_andi_reg(t
, t
, 0x4000000);
3891 ctx
->null_cond
= cond_make_0(TCG_COND_NE
, t
);
3919 TCGv_reg c
= load_const(ctx
, mask
);
3920 tcg_gen_or_reg(t
, t
, c
);
3921 ctx
->null_cond
= cond_make(TCG_COND_EQ
, t
, c
);
3923 tcg_gen_andi_reg(t
, t
, mask
);
3924 ctx
->null_cond
= cond_make_0(TCG_COND_EQ
, t
);
3927 unsigned cbit
= (a
->y
^ 1) - 1;
3929 tcg_gen_extract_reg(t
, t
, 21 - cbit
, 1);
3930 ctx
->null_cond
= cond_make_0(TCG_COND_NE
, t
);
3935 return nullify_end(ctx
);
3942 static bool trans_fadd_f(DisasContext
*ctx
, arg_fclass3
*a
)
3944 return do_fop_weww(ctx
, a
->t
, a
->r1
, a
->r2
, gen_helper_fadd_s
);
3947 static bool trans_fadd_d(DisasContext
*ctx
, arg_fclass3
*a
)
3949 return do_fop_dedd(ctx
, a
->t
, a
->r1
, a
->r2
, gen_helper_fadd_d
);
3952 static bool trans_fsub_f(DisasContext
*ctx
, arg_fclass3
*a
)
3954 return do_fop_weww(ctx
, a
->t
, a
->r1
, a
->r2
, gen_helper_fsub_s
);
3957 static bool trans_fsub_d(DisasContext
*ctx
, arg_fclass3
*a
)
3959 return do_fop_dedd(ctx
, a
->t
, a
->r1
, a
->r2
, gen_helper_fsub_d
);
3962 static bool trans_fmpy_f(DisasContext
*ctx
, arg_fclass3
*a
)
3964 return do_fop_weww(ctx
, a
->t
, a
->r1
, a
->r2
, gen_helper_fmpy_s
);
3967 static bool trans_fmpy_d(DisasContext
*ctx
, arg_fclass3
*a
)
3969 return do_fop_dedd(ctx
, a
->t
, a
->r1
, a
->r2
, gen_helper_fmpy_d
);
3972 static bool trans_fdiv_f(DisasContext
*ctx
, arg_fclass3
*a
)
3974 return do_fop_weww(ctx
, a
->t
, a
->r1
, a
->r2
, gen_helper_fdiv_s
);
3977 static bool trans_fdiv_d(DisasContext
*ctx
, arg_fclass3
*a
)
3979 return do_fop_dedd(ctx
, a
->t
, a
->r1
, a
->r2
, gen_helper_fdiv_d
);
3982 static bool trans_xmpyu(DisasContext
*ctx
, arg_xmpyu
*a
)
3988 x
= load_frw0_i64(a
->r1
);
3989 y
= load_frw0_i64(a
->r2
);
3990 tcg_gen_mul_i64(x
, x
, y
);
3992 tcg_temp_free_i64(x
);
3993 tcg_temp_free_i64(y
);
3995 return nullify_end(ctx
);
3998 /* Convert the fmpyadd single-precision register encodings to standard. */
3999 static inline int fmpyadd_s_reg(unsigned r
)
4001 return (r
& 16) * 2 + 16 + (r
& 15);
4004 static bool do_fmpyadd_s(DisasContext
*ctx
, arg_mpyadd
*a
, bool is_sub
)
4006 int tm
= fmpyadd_s_reg(a
->tm
);
4007 int ra
= fmpyadd_s_reg(a
->ra
);
4008 int ta
= fmpyadd_s_reg(a
->ta
);
4009 int rm2
= fmpyadd_s_reg(a
->rm2
);
4010 int rm1
= fmpyadd_s_reg(a
->rm1
);
4014 do_fop_weww(ctx
, tm
, rm1
, rm2
, gen_helper_fmpy_s
);
4015 do_fop_weww(ctx
, ta
, ta
, ra
,
4016 is_sub
? gen_helper_fsub_s
: gen_helper_fadd_s
);
4018 return nullify_end(ctx
);
4021 static bool trans_fmpyadd_f(DisasContext
*ctx
, arg_mpyadd
*a
)
4023 return do_fmpyadd_s(ctx
, a
, false);
4026 static bool trans_fmpysub_f(DisasContext
*ctx
, arg_mpyadd
*a
)
4028 return do_fmpyadd_s(ctx
, a
, true);
4031 static bool do_fmpyadd_d(DisasContext
*ctx
, arg_mpyadd
*a
, bool is_sub
)
4035 do_fop_dedd(ctx
, a
->tm
, a
->rm1
, a
->rm2
, gen_helper_fmpy_d
);
4036 do_fop_dedd(ctx
, a
->ta
, a
->ta
, a
->ra
,
4037 is_sub
? gen_helper_fsub_d
: gen_helper_fadd_d
);
4039 return nullify_end(ctx
);
4042 static bool trans_fmpyadd_d(DisasContext
*ctx
, arg_mpyadd
*a
)
4044 return do_fmpyadd_d(ctx
, a
, false);
4047 static bool trans_fmpysub_d(DisasContext
*ctx
, arg_mpyadd
*a
)
4049 return do_fmpyadd_d(ctx
, a
, true);
4052 static bool trans_fmpyfadd_f(DisasContext
*ctx
, arg_fmpyfadd_f
*a
)
4057 x
= load_frw0_i32(a
->rm1
);
4058 y
= load_frw0_i32(a
->rm2
);
4059 z
= load_frw0_i32(a
->ra3
);
4062 gen_helper_fmpynfadd_s(x
, cpu_env
, x
, y
, z
);
4064 gen_helper_fmpyfadd_s(x
, cpu_env
, x
, y
, z
);
4067 tcg_temp_free_i32(y
);
4068 tcg_temp_free_i32(z
);
4069 save_frw_i32(a
->t
, x
);
4070 tcg_temp_free_i32(x
);
4071 return nullify_end(ctx
);
4074 static bool trans_fmpyfadd_d(DisasContext
*ctx
, arg_fmpyfadd_d
*a
)
4079 x
= load_frd0(a
->rm1
);
4080 y
= load_frd0(a
->rm2
);
4081 z
= load_frd0(a
->ra3
);
4084 gen_helper_fmpynfadd_d(x
, cpu_env
, x
, y
, z
);
4086 gen_helper_fmpyfadd_d(x
, cpu_env
, x
, y
, z
);
4089 tcg_temp_free_i64(y
);
4090 tcg_temp_free_i64(z
);
4092 tcg_temp_free_i64(x
);
4093 return nullify_end(ctx
);
4096 static bool trans_diag(DisasContext
*ctx
, arg_diag
*a
)
4098 qemu_log_mask(LOG_UNIMP
, "DIAG opcode ignored\n");
4099 cond_free(&ctx
->null_cond
);
4103 static void hppa_tr_init_disas_context(DisasContextBase
*dcbase
, CPUState
*cs
)
4105 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
4109 ctx
->tb_flags
= ctx
->base
.tb
->flags
;
4111 #ifdef CONFIG_USER_ONLY
4112 ctx
->privilege
= MMU_USER_IDX
;
4113 ctx
->mmu_idx
= MMU_USER_IDX
;
4114 ctx
->iaoq_f
= ctx
->base
.pc_first
| MMU_USER_IDX
;
4115 ctx
->iaoq_b
= ctx
->base
.tb
->cs_base
| MMU_USER_IDX
;
4117 ctx
->privilege
= (ctx
->tb_flags
>> TB_FLAG_PRIV_SHIFT
) & 3;
4118 ctx
->mmu_idx
= (ctx
->tb_flags
& PSW_D
? ctx
->privilege
: MMU_PHYS_IDX
);
4120 /* Recover the IAOQ values from the GVA + PRIV. */
4121 uint64_t cs_base
= ctx
->base
.tb
->cs_base
;
4122 uint64_t iasq_f
= cs_base
& ~0xffffffffull
;
4123 int32_t diff
= cs_base
;
4125 ctx
->iaoq_f
= (ctx
->base
.pc_first
& ~iasq_f
) + ctx
->privilege
;
4126 ctx
->iaoq_b
= (diff
? ctx
->iaoq_f
+ diff
: -1);
4129 ctx
->iaoq_n_var
= NULL
;
4131 /* Bound the number of instructions by those left on the page. */
4132 bound
= -(ctx
->base
.pc_first
| TARGET_PAGE_MASK
) / 4;
4133 ctx
->base
.max_insns
= MIN(ctx
->base
.max_insns
, bound
);
4137 memset(ctx
->tempr
, 0, sizeof(ctx
->tempr
));
4138 memset(ctx
->templ
, 0, sizeof(ctx
->templ
));
4141 static void hppa_tr_tb_start(DisasContextBase
*dcbase
, CPUState
*cs
)
4143 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
4145 /* Seed the nullification status from PSW[N], as saved in TB->FLAGS. */
4146 ctx
->null_cond
= cond_make_f();
4147 ctx
->psw_n_nonzero
= false;
4148 if (ctx
->tb_flags
& PSW_N
) {
4149 ctx
->null_cond
.c
= TCG_COND_ALWAYS
;
4150 ctx
->psw_n_nonzero
= true;
4152 ctx
->null_lab
= NULL
;
4155 static void hppa_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cs
)
4157 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
4159 tcg_gen_insn_start(ctx
->iaoq_f
, ctx
->iaoq_b
);
4162 static void hppa_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cs
)
4164 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
4165 CPUHPPAState
*env
= cs
->env_ptr
;
4169 /* Execute one insn. */
4170 #ifdef CONFIG_USER_ONLY
4171 if (ctx
->base
.pc_next
< TARGET_PAGE_SIZE
) {
4173 ret
= ctx
->base
.is_jmp
;
4174 assert(ret
!= DISAS_NEXT
);
4178 /* Always fetch the insn, even if nullified, so that we check
4179 the page permissions for execute. */
4180 uint32_t insn
= translator_ldl(env
, ctx
->base
.pc_next
);
4182 /* Set up the IA queue for the next insn.
4183 This will be overwritten by a branch. */
4184 if (ctx
->iaoq_b
== -1) {
4186 ctx
->iaoq_n_var
= get_temp(ctx
);
4187 tcg_gen_addi_reg(ctx
->iaoq_n_var
, cpu_iaoq_b
, 4);
4189 ctx
->iaoq_n
= ctx
->iaoq_b
+ 4;
4190 ctx
->iaoq_n_var
= NULL
;
4193 if (unlikely(ctx
->null_cond
.c
== TCG_COND_ALWAYS
)) {
4194 ctx
->null_cond
.c
= TCG_COND_NEVER
;
4198 if (!decode(ctx
, insn
)) {
4201 ret
= ctx
->base
.is_jmp
;
4202 assert(ctx
->null_lab
== NULL
);
4206 /* Free any temporaries allocated. */
4207 for (i
= 0, n
= ctx
->ntempr
; i
< n
; ++i
) {
4208 tcg_temp_free(ctx
->tempr
[i
]);
4209 ctx
->tempr
[i
] = NULL
;
4211 for (i
= 0, n
= ctx
->ntempl
; i
< n
; ++i
) {
4212 tcg_temp_free_tl(ctx
->templ
[i
]);
4213 ctx
->templ
[i
] = NULL
;
4218 /* Advance the insn queue. Note that this check also detects
4219 a priority change within the instruction queue. */
4220 if (ret
== DISAS_NEXT
&& ctx
->iaoq_b
!= ctx
->iaoq_f
+ 4) {
4221 if (ctx
->iaoq_b
!= -1 && ctx
->iaoq_n
!= -1
4222 && use_goto_tb(ctx
, ctx
->iaoq_b
)
4223 && (ctx
->null_cond
.c
== TCG_COND_NEVER
4224 || ctx
->null_cond
.c
== TCG_COND_ALWAYS
)) {
4225 nullify_set(ctx
, ctx
->null_cond
.c
== TCG_COND_ALWAYS
);
4226 gen_goto_tb(ctx
, 0, ctx
->iaoq_b
, ctx
->iaoq_n
);
4227 ctx
->base
.is_jmp
= ret
= DISAS_NORETURN
;
4229 ctx
->base
.is_jmp
= ret
= DISAS_IAQ_N_STALE
;
4232 ctx
->iaoq_f
= ctx
->iaoq_b
;
4233 ctx
->iaoq_b
= ctx
->iaoq_n
;
4234 ctx
->base
.pc_next
+= 4;
4237 case DISAS_NORETURN
:
4238 case DISAS_IAQ_N_UPDATED
:
4242 case DISAS_IAQ_N_STALE
:
4243 case DISAS_IAQ_N_STALE_EXIT
:
4244 if (ctx
->iaoq_f
== -1) {
4245 tcg_gen_mov_reg(cpu_iaoq_f
, cpu_iaoq_b
);
4246 copy_iaoq_entry(cpu_iaoq_b
, ctx
->iaoq_n
, ctx
->iaoq_n_var
);
4247 #ifndef CONFIG_USER_ONLY
4248 tcg_gen_mov_i64(cpu_iasq_f
, cpu_iasq_b
);
4251 ctx
->base
.is_jmp
= (ret
== DISAS_IAQ_N_STALE_EXIT
4253 : DISAS_IAQ_N_UPDATED
);
4254 } else if (ctx
->iaoq_b
== -1) {
4255 tcg_gen_mov_reg(cpu_iaoq_b
, ctx
->iaoq_n_var
);
4260 g_assert_not_reached();
4264 static void hppa_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cs
)
4266 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
4267 DisasJumpType is_jmp
= ctx
->base
.is_jmp
;
4270 case DISAS_NORETURN
:
4272 case DISAS_TOO_MANY
:
4273 case DISAS_IAQ_N_STALE
:
4274 case DISAS_IAQ_N_STALE_EXIT
:
4275 copy_iaoq_entry(cpu_iaoq_f
, ctx
->iaoq_f
, cpu_iaoq_f
);
4276 copy_iaoq_entry(cpu_iaoq_b
, ctx
->iaoq_b
, cpu_iaoq_b
);
4279 case DISAS_IAQ_N_UPDATED
:
4280 if (ctx
->base
.singlestep_enabled
) {
4281 gen_excp_1(EXCP_DEBUG
);
4282 } else if (is_jmp
!= DISAS_IAQ_N_STALE_EXIT
) {
4283 tcg_gen_lookup_and_goto_ptr();
4287 tcg_gen_exit_tb(NULL
, 0);
4290 g_assert_not_reached();
4294 static void hppa_tr_disas_log(const DisasContextBase
*dcbase
, CPUState
*cs
)
4296 target_ulong pc
= dcbase
->pc_first
;
4298 #ifdef CONFIG_USER_ONLY
4301 qemu_log("IN:\n0x00000000: (null)\n");
4304 qemu_log("IN:\n0x000000b0: light-weight-syscall\n");
4307 qemu_log("IN:\n0x000000e0: set-thread-pointer-syscall\n");
4310 qemu_log("IN:\n0x00000100: syscall\n");
4315 qemu_log("IN: %s\n", lookup_symbol(pc
));
4316 log_target_disas(cs
, pc
, dcbase
->tb
->size
);
4319 static const TranslatorOps hppa_tr_ops
= {
4320 .init_disas_context
= hppa_tr_init_disas_context
,
4321 .tb_start
= hppa_tr_tb_start
,
4322 .insn_start
= hppa_tr_insn_start
,
4323 .translate_insn
= hppa_tr_translate_insn
,
4324 .tb_stop
= hppa_tr_tb_stop
,
4325 .disas_log
= hppa_tr_disas_log
,
4328 void gen_intermediate_code(CPUState
*cs
, TranslationBlock
*tb
, int max_insns
)
4331 translator_loop(&hppa_tr_ops
, &ctx
.base
, cs
, tb
, max_insns
);
4334 void restore_state_to_opc(CPUHPPAState
*env
, TranslationBlock
*tb
,
4337 env
->iaoq_f
= data
[0];
4338 if (data
[1] != (target_ureg
)-1) {
4339 env
->iaoq_b
= data
[1];
4341 /* Since we were executing the instruction at IAOQ_F, and took some
4342 sort of action that provoked the cpu_restore_state, we can infer
4343 that the instruction was not nullified. */