Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1D2sTF-0001Wg-Db for qemu-devel@nongnu.org; Sun, 20 Feb 2005 09:54:05 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1D2sT6-0001SP-PU for qemu-devel@nongnu.org; Sun, 20 Feb 2005 09:53:59 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1D2sT6-0001Q3-F0 for qemu-devel@nongnu.org; Sun, 20 Feb 2005 09:53:56 -0500 Received: from [157.193.204.1] (helo=trappist.elis.UGent.be) by monty-python.gnu.org with esmtp (Exim 4.34) id 1D2s5W-00072v-Ed for qemu-devel@nongnu.org; Sun, 20 Feb 2005 09:29:34 -0500 Received: from [157.193.206.33] (bigmac.elis.UGent.be [157.193.206.33]) by trappist.elis.UGent.be (8.11.6/8.11.6) with ESMTP id j1KETX401536 for ; Sun, 20 Feb 2005 15:29:33 +0100 Mime-Version: 1.0 (Apple Message framework v619.2) In-Reply-To: <67020f2e144efbf20ea9d0eb09315239@elis.ugent.be> References: <6a3c367237141a46e9d50c2806a212c0@elis.ugent.be> <67020f2e144efbf20ea9d0eb09315239@elis.ugent.be> Content-Type: multipart/mixed; boundary=Apple-Mail-7--393931285 Message-Id: <87491237e8d0eaafae0d0da9f45799de@elis.ugent.be> From: Jonas Maebe Subject: Re: [Qemu-devel] Patch to fix Mac OS X compilation Date: Sun, 20 Feb 2005 15:29:31 +0100 Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --Apple-Mail-7--393931285 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed On 19 feb 2005, at 21:00, Jonas Maebe wrote: > And again a more improved patch (I think). This one includes a special > case/hack for Mac OS X for __op_gen_label. Now qemu doesn't crash > anymore when trying to boot freedos, but it doesn't show anything > either. I just get a black screen. The same goes for reactos, so I > guess it's some endless loop while emulating the bios or so. Here's the semi-final fix (stupid bug in my previous patch). FreeDos can now boot, so long as you do not load any drivers. The reason is that the emulation of the loope instruction goes wrong, and that instruction is used in himem.sys (but does not occur when booting without it). The problem is that this is the assembler code generated by gcc for op_loopzw: 0x74370 : mflr r0 0x74374 : stw r0,8(r1) 0x74378 : stwu r1,-64(r1) 0x7437c : lwz r0,48(r27) 0x74380 : rlwinm r0,r0,3,0,28 0x74384 : lis r2,12 0x74388 : lwz r2,-16636(r2) 0x7438c : lwzx r12,r2,r0 0x74390 : mtctr r12 0x74394 : bctrl 0x74398 : lhz r0,6(r27) 0x7439c : cmpwi cr7,r0,0 0x743a0 : beq- cr7,0x743b0 0x743a4 : andi. r0,r3,64 0x743a8 : beq- 0x743b0 0x743ac : b 0x296eb0 <__op_gen_label1> 0x743b0 : lwz r0,72(r1) 0x743b4 : addi r1,r1,64 0x743b8 : mtlr r0 At address 0x743ac, the branch to __op_gen_label1 gets patched so it points to the basic block coming after the loopzw. In that case, LR does not get restored (it was destroyed at 0x74394 by the bctrl), so the next blr which gets executed returns to 0x74398. This causes an endless loop, obviously. This does not seem to be Mac OS X-specific at all, and should also happen under Linux/ppc I think. Jonas --Apple-Mail-7--393931285 Content-Transfer-Encoding: 7bit Content-Type: application/octet-stream; x-unix-mode=0644; name="qemu-macosx4.patch" Content-Disposition: attachment; filename=qemu-macosx4.patch Index: dyngen.c =================================================================== RCS file: /cvsroot/qemu/qemu/dyngen.c,v retrieving revision 1.37 diff -u -r1.37 dyngen.c --- dyngen.c 23 Jan 2005 20:42:06 -0000 1.37 +++ dyngen.c 20 Feb 2005 14:12:01 -0000 @@ -996,11 +996,11 @@ switch(rel->r_type) { - case PPC_RELOC_LO16: fetch_next_pair_value(rel+1, &other_half); sectoffset = (sectoffset & 0xffff); + case PPC_RELOC_LO16: fetch_next_pair_value(rel+1, &other_half); sectoffset |= (other_half << 16); break; - case PPC_RELOC_HI16: fetch_next_pair_value(rel+1, &other_half); sectoffset = (other_half & 0xffff); + case PPC_RELOC_HI16: fetch_next_pair_value(rel+1, &other_half); sectoffset = (sectoffset << 16) | (uint16_t)(other_half & 0xffff); break; - case PPC_RELOC_HA16: fetch_next_pair_value(rel+1, &other_half); sectoffset = (other_half & 0xffff); + case PPC_RELOC_HA16: fetch_next_pair_value(rel+1, &other_half); sectoffset = (sectoffset << 16) + (int16_t)(other_half & 0xffff); break; case PPC_RELOC_BR24: sectoffset = ( *(uint32_t *)(text + rel->r_address) & 0x03fffffc ); @@ -1146,13 +1146,11 @@ /* Now transform the symtab, to an extended version, with the sym size, and the C name */ for(i = 0, sym = symtab, syment = symtab_std; i < nb_syms; i++, sym++, syment++) { - const char *name; struct nlist *sym_follow, *sym_next = 0; unsigned int j; - name = find_str_by_index(sym->n_un.n_strx); memset(sym, 0, sizeof(*sym)); - if ( sym->n_type & N_STAB ) /* Debug symbols are skipped */ + if ( syment->n_type & N_STAB ) /* Debug symbols are skipped */ continue; memcpy(sym, syment, sizeof(*syment)); @@ -1848,11 +1846,16 @@ sym_name); switch(type) { case PPC_RELOC_BR24: - fprintf(outfile, "{\n"); - fprintf(outfile, " uint32_t imm = *(uint32_t *)(gen_code_ptr + %d) & 0x3fffffc;\n", slide); - fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = (*(uint32_t *)(gen_code_ptr + %d) & ~0x03fffffc) | ((imm + ((long)%s - (long)gen_code_ptr) + %d) & 0x03fffffc);\n", + if (!strstart(sym_name,"__op_gen_label",&p)) { + fprintf(outfile, "{\n"); + fprintf(outfile, " uint32_t imm = *(uint32_t *)(gen_code_ptr + %d) & 0x3fffffc;\n", slide); + fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = (*(uint32_t *)(gen_code_ptr + %d) & ~0x03fffffc) | ((imm + ((long)%s - (long)gen_code_ptr) + %d) & 0x03fffffc);\n", slide, slide, name, sslide ); - fprintf(outfile, "}\n"); + fprintf(outfile, "}\n"); + } else { + fprintf(outfile, " *(uint32_t *)(gen_code_ptr + %d) = (*(uint32_t *)(gen_code_ptr + %d) & ~0x03fffffc) | (((long)%s - (long)gen_code_ptr - %d) & 0x03fffffc);\n", + slide, slide, final_sym_name, slide); + } break; case PPC_RELOC_HI16: fprintf(outfile, " *(uint16_t *)(gen_code_ptr + %d + 2) = (%s + %d) >> 16;\n", Index: osdep.c =================================================================== RCS file: /cvsroot/qemu/qemu/osdep.c,v retrieving revision 1.7 diff -u -r1.7 osdep.c --- osdep.c 10 Feb 2005 21:59:15 -0000 1.7 +++ osdep.c 20 Feb 2005 14:12:01 -0000 @@ -273,7 +273,7 @@ #else -#include +#include int qemu_write(int fd, const void *buf, size_t n) { --Apple-Mail-7--393931285--