From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GXGew-0004Jw-0t for qemu-devel@nongnu.org; Tue, 10 Oct 2006 08:24:34 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GXGeu-0004JO-Q3 for qemu-devel@nongnu.org; Tue, 10 Oct 2006 08:24:33 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GXGeu-0004JL-K7 for qemu-devel@nongnu.org; Tue, 10 Oct 2006 08:24:32 -0400 Received: from [195.141.71.141] (helo=mail.esmertec.com) by monty-python.gnu.org with esmtp (Exim 4.52) id 1GXGmg-0007Th-GJ for qemu-devel@nongnu.org; Tue, 10 Oct 2006 08:32:34 -0400 Received: from ddenholm by dalmore.esmertec.com with local (Exim 4.50) id 1GXGeK-0001zR-7v for qemu-devel@nongnu.org; Tue, 10 Oct 2006 13:23:56 +0100 From: Dave Denholm Date: Tue, 10 Oct 2006 13:23:56 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: [Qemu-devel] qemu-mips on x86: stat() broken in 0.8.2 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 Hi, I think emulation of stat() on qemu-mips (big-endian) hosted on x86 is broken. Or more generally, probably either-endian mips on the opposite-endian host. In linux-user/syscall.c around line 2892 in the 0.8.2 release, it uses tswapl() for ppc, and tswap16() for all other targets. But target_stat.t_mode is 32-bit on both mips and ppc, and so I think mips also needs a 32-bit swap.My local fix is just to change #if defined(TARGET_PPC) to #if defined(TARGET_PPC) || defined(TARGET_MIPS) and that seems to fix the problem I was seeing. A slightly more general test might be if (sizeof(target_st->st_mode) == 4) { ... tswapl(); } else { ... tswap16(); } but I'll leave that up to you. I was confused about why the busybox executable in the prebuilt tests seemed to work, and worked the same with both the original executable and my modified version, but it uses fstat64() rather than stat(), and that of course is a different code path. (fstat64() uses the put_user macro which automatically senses the width of the target. Any particular reason for the difference ?) Another small change I have locally is to suppress warnings about unimplemented mips system call 4147 (cache flush). Since qemu handles self-modifying code transparently (in effect, a coherent cache, or no cache at all), the flush can be implemented as a no-op. In fact, it might be mildly interesting if the detection of self-modifying code was turned off for non-x86 targets, and cache-flush calls were required to discarded generated code, since that would make it possible to detect missed calls to cache-flush on programs with self-modifying code. But perhaps I have a different agenda from other users in this area ;-) diff below dd -- Dave Denholm http://www.esmertec.com $ diff --unified syscall.c.~1~ syscall.c --- syscall.c.~1~ 2006-07-22 18:23:34.000000000 +0100 +++ syscall.c 2006-10-10 13:00:56.695069058 +0100 @@ -2889,7 +2889,7 @@ lock_user_struct(target_st, arg2, 0); target_st->st_dev = tswap16(st.st_dev); target_st->st_ino = tswapl(st.st_ino); -#if defined(TARGET_PPC) +#if defined(TARGET_PPC) || defined(TARGET_MIPS) target_st->st_mode = tswapl(st.st_mode); /* XXX: check this */ target_st->st_uid = tswap32(st.st_uid); target_st->st_gid = tswap32(st.st_gid); @@ -3785,6 +3785,12 @@ break; } #endif +#ifdef TARGET_NR_cacheflush + case TARGET_NR_cacheflush: + /* self-modifying code is handled automatically, so nothing needed */ + ret = 0; + break; +#endif #ifdef TARGET_NR_security case TARGET_NR_security: goto unimplemented;