From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrmeU-0006Z8-UC for qemu-devel@nongnu.org; Tue, 03 Jun 2014 07:13:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WrmeN-0005u0-EL for qemu-devel@nongnu.org; Tue, 03 Jun 2014 07:13:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:21542) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrmeN-0005tg-4X for qemu-devel@nongnu.org; Tue, 03 Jun 2014 07:13:03 -0400 Message-ID: <538DADBA.4020309@redhat.com> Date: Tue, 03 Jun 2014 13:12:58 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1401392813-29645-1-git-send-email-pbonzini@redhat.com> <1401392813-29645-5-git-send-email-pbonzini@redhat.com> <53882A9D.7010501@redhat.com> <538D9410.7060300@redhat.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 4/8] linux-user: arm: handle CPSR.E correctly in strex emulation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: QEMU Developers Il 03/06/2014 11:54, Peter Maydell ha scritto: > In user emulation, things are more complicated for BE32, > because we're sort of emulating the word-invariant > bigendian using byte-invariant big-endian (this is > safe because there's no way for a userspace program > to get at anything that would let it tell the > difference). So we can't just say "set SCTLR.B > and handle as if SCTLR.B is set in the way system > emulation would", because the behaviour has to > be different. > > So in summary I'm not sure of the right approach > any more... I think overall sctlr_b makes for more accurate and overall clearer code. Here are the functions I'm using to map between the various properties: +static inline bool bswap_code(bool sctlr_b) +{ +#ifdef CONFIG_USER_ONLY + /* Mixed-endian modes are BE8 (SCTLR.B = 0, TARGET_WORDS_BIGENDIAN = 1) + * and LE8 (SCTLR.B = 1, TARGET_WORDS_BIGENDIAN = 0). + */ + return +#ifdef TARGET_WORDS_BIGENDIAN + 1 ^ +#endif + sctlr_b; +#else + /* We do not implement BE32 mode for system-mode emulation, but + * anyway it would always do little-endian accesses with + * TARGET_WORDS_BIGENDIAN = 0. + */ + return 0; +#endif +} + +#ifdef CONFIG_USER_ONLY +static inline bool arm_cpu_bswap_data(CPUARMState *env) +{ + return +#ifdef TARGET_WORDS_BIGENDIAN + 1 ^ +#endif + !!(env->cp15.c1_sys & SCTLR_B) ^ + !!(env->uncached_cpsr & CPSR_E); +} +#endif + +static inline bool arm_tbflag_is_data_be(unsigned tbflags) +{ + return +#ifdef CONFIG_USER_ONLY + ARM_TBFLAG_SCTLR_B(tbflags) ^ +#endif + ARM_TBFLAG_CPSR_E(tbflags); +} + I think this is reasonably close to what you would have for SCTLR.B emulation, only the XORing of addresses is missing. bswap_code is used in much fewer places than the current env->bswap_code, basically only in the definitions of arm_ld*_code and get_user_code_*. Everywhere else the code is accessing SCTLR.B, which is "real" architectural state. The confusing manner of handling it in user-mode emulation is wrapped by the above three inline functions. Paolo