-/* bc bca bcl bcla */
-GEN_BCOND(bc, 0x10, 0xFF, 0xFF,
- do {
- uint32_t li = s_ext16(BD(ctx->opcode));
- if (AA(ctx->opcode) == 0) {
- target = (uint32_t)ctx->nip + li - 4;
- } else {
- target = li;
- }
- } while (0),
- gen_op_bl_ctr((uint32_t)ctx->nip, target),
- gen_op_b_ctr((uint32_t)ctx->nip, target),
- gen_op_bl_ctrz((uint32_t)ctx->nip, target),
- gen_op_b_ctrz((uint32_t)ctx->nip, target),
- gen_op_b(target),
- gen_op_bl(target, (uint32_t)ctx->nip),
- gen_op_bl_ctr_true((uint32_t)ctx->nip, target, mask),
- gen_op_b_ctr_true((uint32_t)ctx->nip, target, mask),
- gen_op_bl_ctrz_true((uint32_t)ctx->nip, target, mask),
- gen_op_b_ctrz_true((uint32_t)ctx->nip, target, mask),
- gen_op_bl_true((uint32_t)ctx->nip, target, mask),
- gen_op_b_true((uint32_t)ctx->nip, target, mask),
- gen_op_bl_ctr_false((uint32_t)ctx->nip, target, mask),
- gen_op_b_ctr_false((uint32_t)ctx->nip, target, mask),
- gen_op_bl_ctrz_false((uint32_t)ctx->nip, target, mask),
- gen_op_b_ctrz_false((uint32_t)ctx->nip, target, mask),
- gen_op_bl_false((uint32_t)ctx->nip, target, mask),
- gen_op_b_false((uint32_t)ctx->nip, target, mask));
-
-/* bcctr bcctrl */
-GEN_BCOND(bcctr, 0x13, 0x10, 0x10, do { } while (0),
- gen_op_bctrl_ctr((uint32_t)ctx->nip),
- gen_op_bctr_ctr((uint32_t)ctx->nip),
- gen_op_bctrl_ctrz((uint32_t)ctx->nip),
- gen_op_bctr_ctrz((uint32_t)ctx->nip),
- gen_op_bctr(),
- gen_op_bctrl((uint32_t)ctx->nip),
- gen_op_bctrl_ctr_true((uint32_t)ctx->nip, mask),
- gen_op_bctr_ctr_true((uint32_t)ctx->nip, mask),
- gen_op_bctrl_ctrz_true((uint32_t)ctx->nip, mask),
- gen_op_bctr_ctrz_true((uint32_t)ctx->nip, mask),
- gen_op_bctrl_true((uint32_t)ctx->nip, mask),
- gen_op_bctr_true((uint32_t)ctx->nip, mask),
- gen_op_bctrl_ctr_false((uint32_t)ctx->nip, mask),
- gen_op_bctr_ctr_false((uint32_t)ctx->nip, mask),
- gen_op_bctrl_ctrz_false((uint32_t)ctx->nip, mask),
- gen_op_bctr_ctrz_false((uint32_t)ctx->nip, mask),
- gen_op_bctrl_false((uint32_t)ctx->nip, mask),
- gen_op_bctr_false((uint32_t)ctx->nip, mask))
-
-/* bclr bclrl */
-GEN_BCOND(bclr, 0x13, 0x10, 0x00, do { } while (0),
- gen_op_blrl_ctr((uint32_t)ctx->nip),
- gen_op_blr_ctr((uint32_t)ctx->nip),
- gen_op_blrl_ctrz((uint32_t)ctx->nip),
- gen_op_blr_ctrz((uint32_t)ctx->nip),
- gen_op_blr(),
- gen_op_blrl((uint32_t)ctx->nip),
- gen_op_blrl_ctr_true((uint32_t)ctx->nip, mask),
- gen_op_blr_ctr_true((uint32_t)ctx->nip, mask),
- gen_op_blrl_ctrz_true((uint32_t)ctx->nip, mask),
- gen_op_blr_ctrz_true((uint32_t)ctx->nip, mask),
- gen_op_blrl_true((uint32_t)ctx->nip, mask),
- gen_op_blr_true((uint32_t)ctx->nip, mask),
- gen_op_blrl_ctr_false((uint32_t)ctx->nip, mask),
- gen_op_blr_ctr_false((uint32_t)ctx->nip, mask),
- gen_op_blrl_ctrz_false((uint32_t)ctx->nip, mask),
- gen_op_blr_ctrz_false((uint32_t)ctx->nip, mask),
- gen_op_blrl_false((uint32_t)ctx->nip, mask),
- gen_op_blr_false((uint32_t)ctx->nip, mask))
+#define BCOND_IM 0
+#define BCOND_LR 1
+#define BCOND_CTR 2
+
+static inline void gen_bcond(DisasContext *ctx, int type)
+{
+ uint32_t target = 0;
+ uint32_t bo = BO(ctx->opcode);
+ uint32_t bi = BI(ctx->opcode);
+ uint32_t mask;
+ uint32_t li;
+
+ if ((bo & 0x4) == 0)
+ gen_op_dec_ctr();
+ switch(type) {
+ case BCOND_IM:
+ li = s_ext16(BD(ctx->opcode));
+ if (AA(ctx->opcode) == 0) {
+ target = ctx->nip + li - 4;
+ } else {
+ target = li;
+ }
+ break;
+ case BCOND_CTR:
+ gen_op_movl_T1_ctr();
+ break;
+ default:
+ case BCOND_LR:
+ gen_op_movl_T1_lr();
+ break;
+ }
+ if (LK(ctx->opcode)) {
+ gen_op_setlr(ctx->nip);
+ }
+ if (bo & 0x10) {
+ /* No CR condition */
+ switch (bo & 0x6) {
+ case 0:
+ gen_op_test_ctr();
+ break;
+ case 2:
+ gen_op_test_ctrz();
+ break;
+ default:
+ case 4:
+ case 6:
+ if (type == BCOND_IM) {
+ gen_op_b((long)ctx->tb, target);
+ } else {
+ gen_op_b_T1();
+ }
+ goto no_test;
+ }
+ } else {
+ mask = 1 << (3 - (bi & 0x03));
+ gen_op_load_crf_T0(bi >> 2);
+ if (bo & 0x8) {
+ switch (bo & 0x6) {
+ case 0:
+ gen_op_test_ctr_true(mask);
+ break;
+ case 2:
+ gen_op_test_ctrz_true(mask);
+ break;
+ default:
+ case 4:
+ case 6:
+ gen_op_test_true(mask);
+ break;
+ }
+ } else {
+ switch (bo & 0x6) {
+ case 0:
+ gen_op_test_ctr_false(mask);
+ break;
+ case 2:
+ gen_op_test_ctrz_false(mask);
+ break;
+ default:
+ case 4:
+ case 6:
+ gen_op_test_false(mask);
+ break;
+ }
+ }
+ }
+ if (type == BCOND_IM) {
+ gen_op_btest((long)ctx->tb, target, ctx->nip);
+ } else {
+ gen_op_btest_T1(ctx->nip);
+ }
+ no_test:
+ ctx->exception = EXCP_BRANCH;
+}
+
+GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
+{
+ gen_bcond(ctx, BCOND_IM);
+}
+
+GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW)
+{
+ gen_bcond(ctx, BCOND_CTR);
+}
+
+GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW)
+{
+ gen_bcond(ctx, BCOND_LR);
+}