Received: from eggs.gnu.org ([2001:4830:134:3::10]:48999) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W3qSV-0004oU-KL for qemu-devel@nongnu.org; Thu, 16 Jan 2014 12:10:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W3qSP-0006Uz-K8 for qemu-devel@nongnu.org; Thu, 16 Jan 2014 12:10:23 -0500 Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Mac OS X Mail 7.1 \(1827\)) From: Alexander Graf In-Reply-To: <52D80FFF.8070407@linux.vnet.ibm.com> Date: Thu, 16 Jan 2014 18:10:11 +0100 Content-Transfer-Encoding: quoted-printable Message-Id: <42F7ABDB-967C-42C3-A9DA-7BA2884260CD@suse.de> References: <52D80FFF.8070407@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [PATCH v2] target-ppc: gdbstub allow byte swapping for reading/writing registers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Thomas Falcon Cc: qemu-ppc , QEMU Developers On 16.01.2014, at 17:59, Thomas Falcon = wrote: > This patch allows registers to be properly read from and written to > when using the gdbstub to debug a ppc guest running in little > endian mode. It accomplishes this goal by byte swapping the values of > any registers if the MSR:LE value is set. >=20 > Signed-off-by: Thomas Falcon > --- > Have created wrapper functions that swap mem_buf in-place. > mem_buf is swapped regardless of the the host's endianness if msr_le = is true. > --- > target-ppc/cpu-qom.h | 2 ++ > target-ppc/gdbstub.c | 48 = +++++++++++++++++++++++++++++++++++++++++++++ > target-ppc/translate_init.c | 4 ++-- > 3 files changed, 52 insertions(+), 2 deletions(-) >=20 > diff --git a/target-ppc/cpu-qom.h b/target-ppc/cpu-qom.h > index 72b2232..992963f 100644 > --- a/target-ppc/cpu-qom.h > +++ b/target-ppc/cpu-qom.h > @@ -109,7 +109,9 @@ void ppc_cpu_dump_statistics(CPUState *cpu, FILE = *f, > fprintf_function cpu_fprintf, int flags); > hwaddr ppc_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); > int ppc_cpu_gdb_read_register(CPUState *cpu, uint8_t *buf, int reg); > +int ppc_cpu_gdb_read_register_wrap(CPUState *cpu, uint8_t *buf, int = reg); > int ppc_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); > +int ppc_cpu_gdb_write_register_wrap(CPUState *cpu, uint8_t *buf, int = reg); > int ppc64_cpu_write_elf64_qemunote(WriteCoreDumpFunction f, > CPUState *cpu, void *opaque); > int ppc64_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, > diff --git a/target-ppc/gdbstub.c b/target-ppc/gdbstub.c > index 1c91090..964fd85 100644 > --- a/target-ppc/gdbstub.c > +++ b/target-ppc/gdbstub.c > @@ -21,6 +21,54 @@ > #include "qemu-common.h" > #include "exec/gdbstub.h" >=20 > +/* The following functions are used to ensure the correct > + * transfer of registers between a little endian ppc target > + * and a big endian host by checking the LE bit in the Machine State = Register > + */ > + > +int ppc_cpu_gdb_read_register_wrap(CPUState *cs, uint8_t *mem_buf, = int n) > +{ > + PowerPCCPU *cpu =3D POWERPC_CPU(cs); > + CPUPPCState *env =3D &cpu->env; > + > + int len =3D ppc_cpu_gdb_read_register(cs, mem_buf, n),i; > + if(msr_le) > + { > + uint8_t tmp; > + for(i=3D0;i + { > + tmp=3D*(mem_buf+i); > + *(mem_buf+i)=3D*(mem_buf+len-1-i); > + *(mem_buf+len-1-i)=3Dtmp; > + } > + } > + return len; > +} > + > +int ppc_cpu_gdb_write_register_wrap(CPUState *cs, uint8_t *mem_buf, = int n) > +{ > + PowerPCCPU *cpu =3D POWERPC_CPU(cs); > + CPUPPCState *env =3D &cpu->env; > + if(msr_le) > + { > + int len=3D0,i=3D0; > + if(n < 64) > + len=3D8; > + else if(n =3D=3D 66) > + len=3D4; > + else > + len =3D sizeof(target_ulong); > + uint8_t tmp; > + for(i=3D0;i + { > + tmp=3D*(mem_buf+i); > + *(mem_buf+i)=3D*(mem_buf+len-1-i); > + *(mem_buf+len-1-i)=3Dtmp; > + } > + } > + return ppc_cpu_gdb_write_register(cs, mem_buf, n); Please run checkpatch.pl :). Also the return value is already then length. No need to duplicate that = logic. Alex