Commit bd107c5602 for qemu.org

commit bd107c56027e297358af8a12bf1709472f5a77a4
Author: Kirill A. Korinsky <kirill@korins.ky>
Date:   Tue Dec 1 22:36:04 2026 +0100

    target/hppa: Fix tcg_gen_goto_tb assertion

    On hppa a branch may generate three exits from one block, but qemu has
    only two slots; the third exit reused slot 0 and badaboom happened.
    Try to assign a unique slot to avoid the problem.

    Signed-off-by: Kirill A. Korinsky <kirill@korins.ky>
    Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4835
    Signed-off-by: Helge Deller <deller@gmx.de>

diff --git a/target/hppa/translate.c b/target/hppa/translate.c
index c8e2b13c8c..70bc7deabd 100644
--- a/target/hppa/translate.c
+++ b/target/hppa/translate.c
@@ -85,6 +85,7 @@ typedef struct DisasContext {
     uint32_t tb_flags;
     int mmu_idx;
     int privilege;
+    unsigned goto_tb_idx;
     uint32_t psw_xb;
     bool psw_n_nonzero;
     bool psw_b_next;
@@ -791,7 +792,8 @@ static bool gen_illegal(DisasContext *ctx)
 static bool use_goto_tb(DisasContext *ctx, const DisasIAQE *f,
                         const DisasIAQE *b)
 {
-    return (!iaqe_variable(f) &&
+    return (ctx->goto_tb_idx <= TB_EXIT_IDXMAX &&
+            !iaqe_variable(f) &&
             (b == NULL || !iaqe_variable(b)) &&
             translator_use_goto_tb(&ctx->base, ctx->iaoq_first + f->disp));
 }
@@ -808,11 +810,13 @@ static bool use_nullify_skip(DisasContext *ctx)
                 & TARGET_PAGE_MASK) == 0);
 }

-static void gen_goto_tb(DisasContext *ctx, int which,
+static void gen_goto_tb(DisasContext *ctx,
                         const DisasIAQE *f, const DisasIAQE *b)
 {
     install_iaq_entries(ctx, f, b);
     if (use_goto_tb(ctx, f, b)) {
+        unsigned which = ctx->goto_tb_idx++;
+
         tcg_gen_goto_tb(which);
         tcg_gen_exit_tb(ctx->base.tb, which);
     } else {
@@ -1960,7 +1964,7 @@ static bool do_dbranch(DisasContext *ctx, int64_t disp,
             if (use_nullify_skip(ctx)) {
                 nullify_set(ctx, 0);
                 store_psw_xb(ctx, 0);
-                gen_goto_tb(ctx, 0, &ctx->iaq_j, NULL);
+                gen_goto_tb(ctx, &ctx->iaq_j, NULL);
                 ctx->base.is_jmp = DISAS_NORETURN;
                 return true;
             }
@@ -1975,17 +1979,17 @@ static bool do_dbranch(DisasContext *ctx, int64_t disp,
         if (is_n && use_nullify_skip(ctx)) {
             nullify_set(ctx, 0);
             store_psw_xb(ctx, 0);
-            gen_goto_tb(ctx, 0, &ctx->iaq_j, NULL);
+            gen_goto_tb(ctx, &ctx->iaq_j, NULL);
         } else {
             nullify_set(ctx, is_n);
             store_psw_xb(ctx, PSW_B);
-            gen_goto_tb(ctx, 0, &ctx->iaq_b, &ctx->iaq_j);
+            gen_goto_tb(ctx, &ctx->iaq_b, &ctx->iaq_j);
         }
         nullify_end(ctx);

         nullify_set(ctx, 0);
         store_psw_xb(ctx, 0);
-        gen_goto_tb(ctx, 1, &ctx->iaq_b, NULL);
+        gen_goto_tb(ctx, &ctx->iaq_b, NULL);
         ctx->base.is_jmp = DISAS_NORETURN;
     }
     return true;
@@ -2017,7 +2021,7 @@ static bool do_cbranch(DisasContext *ctx, int64_t disp, bool is_n,
         nullify_set(ctx, 0);
         store_psw_xb(ctx, 0);
         next = iaqe_incr(&ctx->iaq_b, 4);
-        gen_goto_tb(ctx, 0, &next, NULL);
+        gen_goto_tb(ctx, &next, NULL);
     } else {
         if (!n && ctx->null_lab) {
             gen_set_label(ctx->null_lab);
@@ -2025,7 +2029,7 @@ static bool do_cbranch(DisasContext *ctx, int64_t disp, bool is_n,
         }
         nullify_set(ctx, n);
         store_psw_xb(ctx, 0);
-        gen_goto_tb(ctx, 0, &ctx->iaq_b, NULL);
+        gen_goto_tb(ctx, &ctx->iaq_b, NULL);
     }

     gen_set_label(taken);
@@ -2037,11 +2041,11 @@ static bool do_cbranch(DisasContext *ctx, int64_t disp, bool is_n,
     if (n && use_nullify_skip(ctx)) {
         nullify_set(ctx, 0);
         store_psw_xb(ctx, 0);
-        gen_goto_tb(ctx, 1, &next, NULL);
+        gen_goto_tb(ctx, &next, NULL);
     } else {
         nullify_set(ctx, n);
         store_psw_xb(ctx, PSW_B);
-        gen_goto_tb(ctx, 1, &ctx->iaq_b, &next);
+        gen_goto_tb(ctx, &ctx->iaq_b, &next);
     }

     /* Not taken: the branch itself was nullified.  */
@@ -4970,7 +4974,7 @@ static void hppa_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
             && (ctx->null_cond.c == TCG_COND_NEVER
                 || ctx->null_cond.c == TCG_COND_ALWAYS)) {
             nullify_set(ctx, ctx->null_cond.c == TCG_COND_ALWAYS);
-            gen_goto_tb(ctx, 0, f, b);
+            gen_goto_tb(ctx, f, b);
             break;
         }
         /* FALLTHRU */