Blob Blame History Raw
--- qemu/dyngen.c.x	2005-05-16 10:30:43.000000000 +0100
+++ qemu/dyngen.c	2005-05-16 10:32:41.000000000 +0100
@@ -1996,6 +1996,9 @@ void gen_code(const char *name, host_ulo
     int retpos;
     int exit_addrs[MAX_EXITS];
 #endif
+#if defined(HOST_PPC)
+    uint8_t *blr_addr = NULL;
+#endif
 
     /* Compute exact size excluding prologue and epilogue instructions.
      * Increment start_offset to skip epilogue instructions, then compute
@@ -2018,9 +2021,23 @@ void gen_code(const char *name, host_ulo
         p = (void *)(p_end - 4);
         if (p == p_start)
             error("empty code for %s", name);
-        if (get32((uint32_t *)p) != 0x4e800020)
-            error("blr expected at the end of %s", name);
-        copy_size = p - p_start;
+        if (get32((uint32_t *)p) == 0x4e800020) {
+		copy_size = p - p_start; /* blr at end */
+	} else {
+	    /* Find the blr and note its address so that we 
+	       can emit code to rewrite it to a branch. */
+	    do {
+		p -= 4;
+
+		if (get32((uint32_t *)p) == 0x4e800020) {
+		    blr_addr = p;
+		    copy_size = p_end - p_start;
+		    break;
+		}
+	    } while (p > p_start);
+	    if (p == p_start)
+		error("blr expected in the end of %s", name);
+	}
     }
 #elif defined(HOST_S390)
     {
@@ -2633,6 +2650,9 @@ void gen_code(const char *name, host_ulo
 #else
 #error unsupport object format
 #endif
+		if (blr_addr)
+		    fprintf(outfile, "    *(uint32_t *)(gen_code_ptr + %d) = 0x48000000 | %d;\n",
+			    blr_addr - p_start, p_end - blr_addr);
             }
 #elif defined(HOST_S390)
             {