3089
tcg_gen_movi_tl(cpu_lr, nip);
3090
}
3091
3092
-#define BCOND_IM 0
3093
-#define BCOND_LR 1
3094
-#define BCOND_CTR 2
3095
-#define BCOND_TAR 3
3096
-
3097
-static void gen_bcond(DisasContext *ctx, int type)
3098
-{
3099
- uint32_t bo = BO(ctx->opcode);
3100
- TCGLabel *l1;
3101
- TCGv target;
3102
- target_long bhrb_type = BHRB_TYPE_OTHER;
3103
-
3104
- if (type == BCOND_LR || type == BCOND_CTR || type == BCOND_TAR) {
3105
- target = tcg_temp_new();
3106
- if (type == BCOND_CTR) {
3107
- tcg_gen_mov_tl(target, cpu_ctr);
3108
- } else if (type == BCOND_TAR) {
3109
- gen_load_spr(target, SPR_TAR);
3110
- } else {
3111
- tcg_gen_mov_tl(target, cpu_lr);
3112
- }
3113
- if (!LK(ctx->opcode)) {
3114
- bhrb_type |= BHRB_TYPE_INDIRECT;
3115
- }
3116
- bhrb_type |= BHRB_TYPE_XL_FORM;
3117
- } else {
3118
- target = NULL;
3119
- }
3120
- if (LK(ctx->opcode)) {
3121
- gen_setlr(ctx, ctx->base.pc_next);
3122
- bhrb_type |= BHRB_TYPE_CALL;
3123
- }
3124
- l1 = gen_new_label();
3125
- if ((bo & 0x4) == 0) {
3126
- /* Decrement and test CTR */
3127
- TCGv temp = tcg_temp_new();
3128
-
3129
- if (type == BCOND_CTR) {
3130
- /*
3131
- * All ISAs up to v3 describe this form of bcctr as invalid but
3132
- * some processors, ie. 64-bit server processors compliant with
3133
- * arch 2.x, do implement a "test and decrement" logic instead,
3134
- * as described in their respective UMs. This logic involves CTR
3135
- * to act as both the branch target and a counter, which makes
3136
- * it basically useless and thus never used in real code.
3137
- *
3138
- * This form was hence chosen to trigger extra micro-architectural
3139
- * side-effect on real HW needed for the Spectre v2 workaround.
3140
- * It is up to guests that implement such workaround, ie. linux, to
3141
- * use this form in a way it just triggers the side-effect without
3142
- * doing anything else harmful.
3143
- */
3144
- if (unlikely(!is_book3s_arch2x(ctx))) {
3145
- gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL);
3146
- return;
3147
- }
3148
-
3149
- if (NARROW_MODE(ctx)) {
3150
- tcg_gen_ext32u_tl(temp, cpu_ctr);
3151
- } else {
3152
- tcg_gen_mov_tl(temp, cpu_ctr);
3153
- }
3154
- if (bo & 0x2) {
3155
- tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
3156
- } else {
3157
- tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
3158
- }
3159
- tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
3160
- } else {
3161
- tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
3162
- if (NARROW_MODE(ctx)) {
3163
- tcg_gen_ext32u_tl(temp, cpu_ctr);
3164
- } else {
3165
- tcg_gen_mov_tl(temp, cpu_ctr);
3166
- }
3167
- if (bo & 0x2) {
3168
- tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
3169
- } else {
3170
- tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
3171
- }
3172
- }
3173
- bhrb_type |= BHRB_TYPE_COND;
3174
- }
3175
- if ((bo & 0x10) == 0) {
3176
- /* Test CR */
3177
- uint32_t bi = BI(ctx->opcode);
3178
- uint32_t mask = 0x08 >> (bi & 0x03);
3179
- TCGv_i32 temp = tcg_temp_new_i32();
3180
-
3181
- if (bo & 0x8) {
3182
- tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3183
- tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1);
3184
- } else {
3185
- tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3186
- tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1);
3187
- }
3188
- bhrb_type |= BHRB_TYPE_COND;
3189
- }
3190
-
3191
- gen_update_branch_history(ctx, ctx->cia, target, bhrb_type);
3192
-
3193
- if (type == BCOND_IM) {
3194
- target_ulong li = (target_long)((int16_t)(BD(ctx->opcode)));
3195
- if (likely(AA(ctx->opcode) == 0)) {
3196
- gen_goto_tb(ctx, 0, ctx->cia + li);
3197
- } else {
3198
- gen_goto_tb(ctx, 0, li);
3199
- }
3200
- } else {
3201
- if (NARROW_MODE(ctx)) {
3202
- tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3);
3203
- } else {
3204
- tcg_gen_andi_tl(cpu_nip, target, ~3);
3205
- }
3206
- gen_lookup_and_goto_ptr(ctx);
3207
- }
3208
- if ((bo & 0x14) != 0x14) {
3209
- /* fallthrough case */
3210
- gen_set_label(l1);
3211
- gen_goto_tb(ctx, 1, ctx->base.pc_next);
3212
- }
3213
- ctx->base.is_jmp = DISAS_NORETURN;
3214
-}
3215
-
3216
-static void gen_bc(DisasContext *ctx)
3217
-{
3218
- gen_bcond(ctx, BCOND_IM);
3219
-}
3220
-
3221
-static void gen_bcctr(DisasContext *ctx)
3222
-{
3223
- gen_bcond(ctx, BCOND_CTR);
3224
-}
3225
-
3226
-static void gen_bclr(DisasContext *ctx)
3227
-{
3228
- gen_bcond(ctx, BCOND_LR);
3229
-}
3230
-
3231
-static void gen_bctar(DisasContext *ctx)
3232
-{
3233
- gen_bcond(ctx, BCOND_TAR);
3234
-}
3235
-
3092
/*** Condition register logical ***/
3093
#define GEN_CRLOGIC(name, tcg_op, opc) \
3094
static void glue(gen_, name)(DisasContext *ctx) \
5186
/* ISA v3.0 changed the extended opcode from 62 to 30 */
5187
GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x039FF801, PPC_WAIT),
5188
GEN_HANDLER_E(wait, 0x1F, 0x1E, 0x00, 0x039CF801, PPC_NONE, PPC2_ISA300),
5333
-GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW),
5334
-GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW),
5335
-GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW),
5336
-GEN_HANDLER_E(bctar, 0x13, 0x10, 0x11, 0x0000E000, PPC_NONE, PPC2_BCTAR_ISA207),
5189
GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW),
5190
#if defined(TARGET_PPC64)
5191
GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B),