Received: from [140.186.70.92] (port=53131 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PbFOf-0006Po-2J for qemu-devel@nongnu.org; Fri, 07 Jan 2011 11:42:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PbFOb-0006wO-9P for qemu-devel@nongnu.org; Fri, 07 Jan 2011 11:42:34 -0500 Received: from hall.aurel32.net ([88.191.126.93]:60417) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PbFOa-0006wA-W6 for qemu-devel@nongnu.org; Fri, 07 Jan 2011 11:42:33 -0500 Date: Fri, 7 Jan 2011 17:42:30 +0100 From: Aurelien Jarno Subject: Re: [Qemu-devel] [PATCH] lsi53c895a: fix endianness issues Message-ID: <20110107164230.GM21099@hall.aurel32.net> References: <199928188099966684@unknownmsgid> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Sender: Aurelien Jarno List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: qemu-devel@nongnu.org On Fri, Jan 07, 2011 at 04:21:29PM +0000, Stefan Hajnoczi wrote: > On Fri, Jan 7, 2011 at 2:43 PM, wrote: > > From: Aurelien Jarno > > > > lsi_ram_read*() and lsi_ram_write*() are not consistent, one uses > > leXX_to_cpu() the other uses nothing. As the comment above the RAM > > declaration says: "Script ram is stored as 32-bit words in host > > byteorder.", remove the leXX_to_cpu() calls. > > > > This fixes the boot of an ARM versatile machine on MIPS and PowerPC > > hosts. > > > > Signed-off-by: Aurelien Jarno > > --- > >  hw/lsi53c895a.c |    4 ++-- > >  1 files changed, 2 insertions(+), 2 deletions(-) > > script_ram[] is host byteorder for sure. This patch looks correct. > > Now I'm wondering about read_dword: > > static inline uint32_t read_dword(LSIState *s, uint32_t addr) > { > uint32_t buf; > > /* Optimize reading from SCRIPTS RAM. */ > if ((addr & 0xffffe000) == s->script_ram_base) { > return s->script_ram[(addr & 0x1fff) >> 2]; > } > cpu_physical_memory_read(addr, (uint8_t *)&buf, 4); > return cpu_to_le32(buf); > } > > If addr is in script_ram[], then the return value is host byteorder. Correct, it's what is assumed latter during the script execution. > If addr is not in script_ram[], then it is converted to little-endian? It needs to be converted to host byteorder. le32_to_cpu() would probably more correct here for little endian targets (I doubt anyway that lsi53c895a works on big endian targets given other parts of the code). It should probably be only bswapped for cross-endian if we latter add support for big endian. > Will lsi emulation work on big-endian hosts? > With this patch it definitely works on big-endian hosts and little-endian guests (tested with ARM guest on MIPS and PowerPC hosts). -- Aurelien Jarno GPG: 1024D/F1BCDB73 aurelien@aurel32.net http://www.aurel32.net