Skip to contentSkip to conversation

lsi53c895a: fix endianness issues

PATCH Stefan Hajnoczi 2 participants 2 messages Jan 7, 2011 1 message not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 7 lines · On Fri, Jan 7, 2011 at 2:43 PM, <[email protected]> wrote:

From: Aurelien Jarno <[email protected]>

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.

Quoted 7 lines

This fixes the boot of an ARM versatile machine on MIPS and PowerPC hosts.

---
 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.

If addr is not in script_ram[], then it is converted to little-endian?
Will lsi emulation work on big-endian hosts?

Stefan

#2 lore raw
Quoted 32 lines · Stefan Hajnoczi
Quoted 7 lines · On Fri, Jan 7, 2011 at 2:43 PM, <[email protected]> wrote:

From: Aurelien Jarno <[email protected]>

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.

Quoted 7 lines

This fixes the boot of an ARM versatile machine on MIPS and PowerPC hosts.

---
 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);
}
Quoted 1 line

If addr is in script_ram[], then the return value is host byteorder.

Correct, it's what is assumed latter during the script execution.

Quoted 1 line

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.

Quoted 2 lines

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).

Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net