All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH-for-6.2 0/2] disas/nios2: Simplify endianess conversion
@ 2021-08-07 11:09 Philippe Mathieu-Daudé
  2021-08-07 11:09 ` [PATCH-for-6.2 1/2] disas/nios2: Fix style in print_insn_nios2() Philippe Mathieu-Daudé
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-08-07 11:09 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marek Vasut, Thomas Huth, Chris Wulff, Richard Henderson,
	Philippe Mathieu-Daudé,
	Alex Bennée

After chatting with Richard Henderson and Paolo Bonzini, we
concluded the load/store API is mature enough to have target
code endianess-agnostic.
Thus we could remove the TARGET_WORDS_BIGENDIAN definition from
target-specific code (restricting it to the binary format loaders).

While experimenting, I noticed the Nios2 disassembler is an easy
win. MIPS will follow shortly.

Philippe Mathieu-Daudé (2):
  disas/nios2: Fix style in print_insn_nios2()
  disas/nios2: Simplify endianess conversion

 include/disas/dis-asm.h |  3 +-
 disas/nios2.c           | 71 ++++++++++++++++-------------------------
 target/nios2/cpu.c      |  6 +---
 3 files changed, 29 insertions(+), 51 deletions(-)

-- 
2.31.1



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH-for-6.2 1/2] disas/nios2: Fix style in print_insn_nios2()
  2021-08-07 11:09 [PATCH-for-6.2 0/2] disas/nios2: Simplify endianess conversion Philippe Mathieu-Daudé
@ 2021-08-07 11:09 ` Philippe Mathieu-Daudé
  2021-08-09  6:08   ` Thomas Huth
  2021-09-29 15:28   ` Laurent Vivier
  2021-08-07 11:09 ` [PATCH-for-6.2 2/2] disas/nios2: Simplify endianess conversion Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-08-07 11:09 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marek Vasut, Thomas Huth, Chris Wulff, Richard Henderson,
	Philippe Mathieu-Daudé,
	Alex Bennée

We are going to modify this function, fix its style first.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 disas/nios2.c | 53 +++++++++++++++++++++++++--------------------------
 1 file changed, 26 insertions(+), 27 deletions(-)

diff --git a/disas/nios2.c b/disas/nios2.c
index c3e82140c79..d124902ae3e 100644
--- a/disas/nios2.c
+++ b/disas/nios2.c
@@ -3482,38 +3482,37 @@ static int
 print_insn_nios2 (bfd_vma address, disassemble_info *info,
 		  enum bfd_endian endianness)
 {
-  bfd_byte buffer[INSNLEN];
-  int status;
+    bfd_byte buffer[INSNLEN];
+    int status;
 
-  status = (*info->read_memory_func) (address, buffer, INSNLEN, info);
-  if (status == 0)
-    {
-      unsigned long insn;
-      if (endianness == BFD_ENDIAN_BIG)
-	insn = (unsigned long) bfd_getb32 (buffer);
-      else
-	insn = (unsigned long) bfd_getl32 (buffer);
-      return nios2_disassemble (address, insn, info);
+    status = (*info->read_memory_func)(address, buffer, INSNLEN, info);
+    if (status == 0) {
+        unsigned long insn;
+        if (endianness == BFD_ENDIAN_BIG) {
+            insn = (unsigned long) bfd_getb32(buffer);
+        } else {
+            insn = (unsigned long) bfd_getl32(buffer);
+        }
+        return nios2_disassemble(address, insn, info);
     }
 
-  /* We might have a 16-bit R2 instruction at the end of memory.  Try that.  */
-  if (info->mach == bfd_mach_nios2r2)
-    {
-      status = (*info->read_memory_func) (address, buffer, 2, info);
-      if (status == 0)
-	{
-	  unsigned long insn;
-	  if (endianness == BFD_ENDIAN_BIG)
-	    insn = (unsigned long) bfd_getb16 (buffer);
-	  else
-	    insn = (unsigned long) bfd_getl16 (buffer);
-	  return nios2_disassemble (address, insn, info);
-	}
+    /* We might have a 16-bit R2 instruction at the end of memory. Try that. */
+    if (info->mach == bfd_mach_nios2r2) {
+        status = (*info->read_memory_func)(address, buffer, 2, info);
+        if (status == 0) {
+            unsigned long insn;
+            if (endianness == BFD_ENDIAN_BIG) {
+                insn = (unsigned long) bfd_getb16(buffer);
+            } else {
+                insn = (unsigned long) bfd_getl16(buffer);
+            }
+            return nios2_disassemble(address, insn, info);
+        }
     }
 
-  /* If we got here, we couldn't read anything.  */
-  (*info->memory_error_func) (status, address, info);
-  return -1;
+    /* If we got here, we couldn't read anything.  */
+    (*info->memory_error_func)(status, address, info);
+    return -1;
 }
 
 /* These two functions are the main entry points, accessed from
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH-for-6.2 2/2] disas/nios2: Simplify endianess conversion
  2021-08-07 11:09 [PATCH-for-6.2 0/2] disas/nios2: Simplify endianess conversion Philippe Mathieu-Daudé
  2021-08-07 11:09 ` [PATCH-for-6.2 1/2] disas/nios2: Fix style in print_insn_nios2() Philippe Mathieu-Daudé
@ 2021-08-07 11:09 ` Philippe Mathieu-Daudé
  2021-08-09  6:12   ` Thomas Huth
  2021-09-29 15:28   ` Laurent Vivier
  2021-09-18  9:19 ` [PATCH-for-6.2 0/2] " Philippe Mathieu-Daudé
  2021-10-19  7:43 ` Laurent Vivier
  3 siblings, 2 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-08-07 11:09 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marek Vasut, Thomas Huth, Chris Wulff, Richard Henderson,
	Philippe Mathieu-Daudé,
	Alex Bennée

Since commit 12b6e9b27d4 ("disas: Clean up CPUDebug initialization")
the disassemble_info->bfd_endian enum is set for all targets in
target_disas(). We can directly call print_insn_nios2() and simplify.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 include/disas/dis-asm.h |  3 +--
 disas/nios2.c           | 22 +++-------------------
 target/nios2/cpu.c      |  6 +-----
 3 files changed, 5 insertions(+), 26 deletions(-)

diff --git a/include/disas/dis-asm.h b/include/disas/dis-asm.h
index 524f29196d9..08e1beec854 100644
--- a/include/disas/dis-asm.h
+++ b/include/disas/dis-asm.h
@@ -455,8 +455,7 @@ int print_insn_crisv32          (bfd_vma, disassemble_info*);
 int print_insn_crisv10          (bfd_vma, disassemble_info*);
 int print_insn_microblaze       (bfd_vma, disassemble_info*);
 int print_insn_ia64             (bfd_vma, disassemble_info*);
-int print_insn_big_nios2        (bfd_vma, disassemble_info*);
-int print_insn_little_nios2     (bfd_vma, disassemble_info*);
+int print_insn_nios2(bfd_vma, disassemble_info*);
 int print_insn_xtensa           (bfd_vma, disassemble_info*);
 int print_insn_riscv32          (bfd_vma, disassemble_info*);
 int print_insn_riscv64          (bfd_vma, disassemble_info*);
diff --git a/disas/nios2.c b/disas/nios2.c
index d124902ae3e..98ac07d72e9 100644
--- a/disas/nios2.c
+++ b/disas/nios2.c
@@ -3478,9 +3478,7 @@ nios2_disassemble (bfd_vma address, unsigned long opcode,
    instruction word at the address given, and prints the disassembled
    instruction on the stream info->stream using info->fprintf_func. */
 
-static int
-print_insn_nios2 (bfd_vma address, disassemble_info *info,
-		  enum bfd_endian endianness)
+int print_insn_nios2(bfd_vma address, disassemble_info *info)
 {
     bfd_byte buffer[INSNLEN];
     int status;
@@ -3488,7 +3486,7 @@ print_insn_nios2 (bfd_vma address, disassemble_info *info,
     status = (*info->read_memory_func)(address, buffer, INSNLEN, info);
     if (status == 0) {
         unsigned long insn;
-        if (endianness == BFD_ENDIAN_BIG) {
+        if (info->endian == BFD_ENDIAN_BIG) {
             insn = (unsigned long) bfd_getb32(buffer);
         } else {
             insn = (unsigned long) bfd_getl32(buffer);
@@ -3501,7 +3499,7 @@ print_insn_nios2 (bfd_vma address, disassemble_info *info,
         status = (*info->read_memory_func)(address, buffer, 2, info);
         if (status == 0) {
             unsigned long insn;
-            if (endianness == BFD_ENDIAN_BIG) {
+            if (info->endian == BFD_ENDIAN_BIG) {
                 insn = (unsigned long) bfd_getb16(buffer);
             } else {
                 insn = (unsigned long) bfd_getl16(buffer);
@@ -3514,17 +3512,3 @@ print_insn_nios2 (bfd_vma address, disassemble_info *info,
     (*info->memory_error_func)(status, address, info);
     return -1;
 }
-
-/* These two functions are the main entry points, accessed from
-   disassemble.c.  */
-int
-print_insn_big_nios2 (bfd_vma address, disassemble_info *info)
-{
-  return print_insn_nios2 (address, info, BFD_ENDIAN_BIG);
-}
-
-int
-print_insn_little_nios2 (bfd_vma address, disassemble_info *info)
-{
-  return print_insn_nios2 (address, info, BFD_ENDIAN_LITTLE);
-}
diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c
index 5e37defef80..5b503b5bb99 100644
--- a/target/nios2/cpu.c
+++ b/target/nios2/cpu.c
@@ -146,11 +146,7 @@ static void nios2_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)
 {
     /* NOTE: NiosII R2 is not supported yet. */
     info->mach = bfd_arch_nios2;
-#ifdef TARGET_WORDS_BIGENDIAN
-    info->print_insn = print_insn_big_nios2;
-#else
-    info->print_insn = print_insn_little_nios2;
-#endif
+    info->print_insn = print_insn_nios2;
 }
 
 static int nios2_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH-for-6.2 1/2] disas/nios2: Fix style in print_insn_nios2()
  2021-08-07 11:09 ` [PATCH-for-6.2 1/2] disas/nios2: Fix style in print_insn_nios2() Philippe Mathieu-Daudé
@ 2021-08-09  6:08   ` Thomas Huth
  2021-08-09  7:14     ` Philippe Mathieu-Daudé
  2021-09-29 15:28   ` Laurent Vivier
  1 sibling, 1 reply; 13+ messages in thread
From: Thomas Huth @ 2021-08-09  6:08 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Marek Vasut, Richard Henderson, Chris Wulff, Alex Bennée

On 07/08/2021 13.09, Philippe Mathieu-Daudé wrote:
> We are going to modify this function, fix its style first.
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>   disas/nios2.c | 53 +++++++++++++++++++++++++--------------------------
>   1 file changed, 26 insertions(+), 27 deletions(-)

I guess it'd make sense to either re-indent the whole file or to bite the 
bullet and life with the checkpatch warnings here ... otherwise you now have 
one function that matches the QEMU coding style while the rest of the file 
looks completely different.

OTOH, we still can clean that up later, so in case you want to keep this patch:

Reviewed-by: Thomas Huth <thuth@redhat.com>



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH-for-6.2 2/2] disas/nios2: Simplify endianess conversion
  2021-08-07 11:09 ` [PATCH-for-6.2 2/2] disas/nios2: Simplify endianess conversion Philippe Mathieu-Daudé
@ 2021-08-09  6:12   ` Thomas Huth
  2021-08-09  9:48     ` Philippe Mathieu-Daudé
  2021-09-29 15:28   ` Laurent Vivier
  1 sibling, 1 reply; 13+ messages in thread
From: Thomas Huth @ 2021-08-09  6:12 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Marek Vasut, Richard Henderson, Chris Wulff, Alex Bennée

On 07/08/2021 13.09, Philippe Mathieu-Daudé wrote:
> Since commit 12b6e9b27d4 ("disas: Clean up CPUDebug initialization")
> the disassemble_info->bfd_endian enum is set for all targets in
> target_disas(). We can directly call print_insn_nios2() and simplify.
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>   include/disas/dis-asm.h |  3 +--
>   disas/nios2.c           | 22 +++-------------------
>   target/nios2/cpu.c      |  6 +-----
>   3 files changed, 5 insertions(+), 26 deletions(-)
[...]
> diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c
> index 5e37defef80..5b503b5bb99 100644
> --- a/target/nios2/cpu.c
> +++ b/target/nios2/cpu.c
> @@ -146,11 +146,7 @@ static void nios2_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)
>   {
>       /* NOTE: NiosII R2 is not supported yet. */
>       info->mach = bfd_arch_nios2;
> -#ifdef TARGET_WORDS_BIGENDIAN
> -    info->print_insn = print_insn_big_nios2;
> -#else
> -    info->print_insn = print_insn_little_nios2;
> -#endif
> +    info->print_insn = print_insn_nios2;
>   }

Oh, wow, I didn't even know that nios2 could be compiled with different 
endianness? I mean, we only have a "nios2-softmmu" target, not something 
like "nios2be-softmmu" and "nios2le-softmmu" ?

Anyway, your patch makes a lot of sense to clean this up.

Reviewed-by: Thomas Huth <thuth@redhat.com>



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH-for-6.2 1/2] disas/nios2: Fix style in print_insn_nios2()
  2021-08-09  6:08   ` Thomas Huth
@ 2021-08-09  7:14     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-08-09  7:14 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel, Peter Maydell, Richard Henderson
  Cc: Marek Vasut, Chris Wulff, Alex Bennée

+Peter for overall style recommendation.

On 8/9/21 8:08 AM, Thomas Huth wrote:
> On 07/08/2021 13.09, Philippe Mathieu-Daudé wrote:
>> We are going to modify this function, fix its style first.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>> ---
>>   disas/nios2.c | 53 +++++++++++++++++++++++++--------------------------
>>   1 file changed, 26 insertions(+), 27 deletions(-)
> 
> I guess it'd make sense to either re-indent the whole file or to bite
> the bullet and life with the checkpatch warnings here ... otherwise you
> now have one function that matches the QEMU coding style while the rest
> of the file looks completely different.

Yeah I didn't know what to do here, I remember a discussion
(3 years ago?) "disas/..." is old import from binutils libopcode,
so better not diverge the style. But the capstone updates shuffled
things a bit. And nobody is tracking the parent project.
I'm tempted to keep the style and ignore the warnings.

> OTOH, we still can clean that up later, so in case you want to keep this
> patch:
> 
> Reviewed-by: Thomas Huth <thuth@redhat.com>

Thanks.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH-for-6.2 2/2] disas/nios2: Simplify endianess conversion
  2021-08-09  6:12   ` Thomas Huth
@ 2021-08-09  9:48     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-08-09  9:48 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel, Marek Vasut
  Cc: Alex Bennée, Chris Wulff, Richard Henderson, Alexander Graf

On 8/9/21 8:12 AM, Thomas Huth wrote:
> On 07/08/2021 13.09, Philippe Mathieu-Daudé wrote:
>> Since commit 12b6e9b27d4 ("disas: Clean up CPUDebug initialization")
>> the disassemble_info->bfd_endian enum is set for all targets in
>> target_disas(). We can directly call print_insn_nios2() and simplify.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>> ---
>>   include/disas/dis-asm.h |  3 +--
>>   disas/nios2.c           | 22 +++-------------------
>>   target/nios2/cpu.c      |  6 +-----
>>   3 files changed, 5 insertions(+), 26 deletions(-)
> [...]
>> diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c
>> index 5e37defef80..5b503b5bb99 100644
>> --- a/target/nios2/cpu.c
>> +++ b/target/nios2/cpu.c
>> @@ -146,11 +146,7 @@ static void nios2_cpu_disas_set_info(CPUState
>> *cpu, disassemble_info *info)
>>   {
>>       /* NOTE: NiosII R2 is not supported yet. */
>>       info->mach = bfd_arch_nios2;
>> -#ifdef TARGET_WORDS_BIGENDIAN
>> -    info->print_insn = print_insn_big_nios2;
>> -#else
>> -    info->print_insn = print_insn_little_nios2;
>> -#endif
>> +    info->print_insn = print_insn_nios2;
>>   }
> 
> Oh, wow, I didn't even know that nios2 could be compiled with different
> endianness? I mean, we only have a "nios2-softmmu" target, not something
> like "nios2be-softmmu" and "nios2le-softmmu" ?

$ git grep ENDIAN configs/targets/nios2-*
$

We only build little-endian targets, but looking at commit
b7862564880 ("nios2: Add Altera 10M50 GHRD emulation")
hw/nios2/boot.c is ready to load big-endian ELF if we were
building the big-endian targets.

> Anyway, your patch makes a lot of sense to clean this up.
> 
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> 
> 


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH-for-6.2 0/2] disas/nios2: Simplify endianess conversion
  2021-08-07 11:09 [PATCH-for-6.2 0/2] disas/nios2: Simplify endianess conversion Philippe Mathieu-Daudé
  2021-08-07 11:09 ` [PATCH-for-6.2 1/2] disas/nios2: Fix style in print_insn_nios2() Philippe Mathieu-Daudé
  2021-08-07 11:09 ` [PATCH-for-6.2 2/2] disas/nios2: Simplify endianess conversion Philippe Mathieu-Daudé
@ 2021-09-18  9:19 ` Philippe Mathieu-Daudé
  2021-09-23 15:14   ` Laurent Vivier
  2021-10-19  7:43 ` Laurent Vivier
  3 siblings, 1 reply; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-18  9:19 UTC (permalink / raw)
  To: qemu-devel, QEMU Trivial
  Cc: Marek Vasut, Alex Bennée, Thomas Huth, Chris Wulff,
	Richard Henderson

Cc'ing qemu-trivial@ (series fully reviewed).

On 8/7/21 13:09, Philippe Mathieu-Daudé wrote:
> After chatting with Richard Henderson and Paolo Bonzini, we
> concluded the load/store API is mature enough to have target
> code endianess-agnostic.
> Thus we could remove the TARGET_WORDS_BIGENDIAN definition from
> target-specific code (restricting it to the binary format loaders).
> 
> While experimenting, I noticed the Nios2 disassembler is an easy
> win. MIPS will follow shortly.
> 
> Philippe Mathieu-Daudé (2):
>   disas/nios2: Fix style in print_insn_nios2()
>   disas/nios2: Simplify endianess conversion
> 
>  include/disas/dis-asm.h |  3 +-
>  disas/nios2.c           | 71 ++++++++++++++++-------------------------
>  target/nios2/cpu.c      |  6 +---
>  3 files changed, 29 insertions(+), 51 deletions(-)
> 


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH-for-6.2 0/2] disas/nios2: Simplify endianess conversion
  2021-09-18  9:19 ` [PATCH-for-6.2 0/2] " Philippe Mathieu-Daudé
@ 2021-09-23 15:14   ` Laurent Vivier
  2021-09-24  9:40     ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 13+ messages in thread
From: Laurent Vivier @ 2021-09-23 15:14 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, Chris Wulff, Marek Vasut
  Cc: QEMU Trivial, Richard Henderson, Thomas Huth, Alex Bennée,
	qemu-devel

Le 18/09/2021 à 11:19, Philippe Mathieu-Daudé a écrit :
> Cc'ing qemu-trivial@ (series fully reviewed).
>

An Acked-by from one of NiosII maintainers would be welcome.

Thanks,
Laurent

> On 8/7/21 13:09, Philippe Mathieu-Daudé wrote:
>> After chatting with Richard Henderson and Paolo Bonzini, we
>> concluded the load/store API is mature enough to have target
>> code endianess-agnostic.
>> Thus we could remove the TARGET_WORDS_BIGENDIAN definition from
>> target-specific code (restricting it to the binary format loaders).
>>
>> While experimenting, I noticed the Nios2 disassembler is an easy
>> win. MIPS will follow shortly.
>>
>> Philippe Mathieu-Daudé (2):
>>   disas/nios2: Fix style in print_insn_nios2()
>>   disas/nios2: Simplify endianess conversion
>>
>>  include/disas/dis-asm.h |  3 +-
>>  disas/nios2.c           | 71 ++++++++++++++++-------------------------
>>  target/nios2/cpu.c      |  6 +---
>>  3 files changed, 29 insertions(+), 51 deletions(-)
>>
> 



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH-for-6.2 0/2] disas/nios2: Simplify endianess conversion
  2021-09-23 15:14   ` Laurent Vivier
@ 2021-09-24  9:40     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 13+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-24  9:40 UTC (permalink / raw)
  To: Laurent Vivier, Chris Wulff, Marek Vasut
  Cc: QEMU Trivial, Alex Bennée, Thomas Huth, Richard Henderson,
	qemu-devel

Hi Cris and Marek, could you help me get this series merged?

On 9/23/21 17:14, Laurent Vivier wrote:
> Le 18/09/2021 à 11:19, Philippe Mathieu-Daudé a écrit :
>> Cc'ing qemu-trivial@ (series fully reviewed).
>>
> 
> An Acked-by from one of NiosII maintainers would be welcome.
> 
> Thanks,
> Laurent
> 
>> On 8/7/21 13:09, Philippe Mathieu-Daudé wrote:
>>> After chatting with Richard Henderson and Paolo Bonzini, we
>>> concluded the load/store API is mature enough to have target
>>> code endianess-agnostic.
>>> Thus we could remove the TARGET_WORDS_BIGENDIAN definition from
>>> target-specific code (restricting it to the binary format loaders).
>>>
>>> While experimenting, I noticed the Nios2 disassembler is an easy
>>> win. MIPS will follow shortly.
>>>
>>> Philippe Mathieu-Daudé (2):
>>>    disas/nios2: Fix style in print_insn_nios2()
>>>    disas/nios2: Simplify endianess conversion
>>>
>>>   include/disas/dis-asm.h |  3 +-
>>>   disas/nios2.c           | 71 ++++++++++++++++-------------------------
>>>   target/nios2/cpu.c      |  6 +---
>>>   3 files changed, 29 insertions(+), 51 deletions(-)
>>>
>>
> 
> 


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH-for-6.2 1/2] disas/nios2: Fix style in print_insn_nios2()
  2021-08-07 11:09 ` [PATCH-for-6.2 1/2] disas/nios2: Fix style in print_insn_nios2() Philippe Mathieu-Daudé
  2021-08-09  6:08   ` Thomas Huth
@ 2021-09-29 15:28   ` Laurent Vivier
  1 sibling, 0 replies; 13+ messages in thread
From: Laurent Vivier @ 2021-09-29 15:28 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Marek Vasut, Alex Bennée, Thomas Huth, Chris Wulff,
	Richard Henderson

Le 07/08/2021 à 13:09, Philippe Mathieu-Daudé a écrit :
> We are going to modify this function, fix its style first.
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  disas/nios2.c | 53 +++++++++++++++++++++++++--------------------------
>  1 file changed, 26 insertions(+), 27 deletions(-)
> 
> diff --git a/disas/nios2.c b/disas/nios2.c
> index c3e82140c79..d124902ae3e 100644
> --- a/disas/nios2.c
> +++ b/disas/nios2.c
> @@ -3482,38 +3482,37 @@ static int
>  print_insn_nios2 (bfd_vma address, disassemble_info *info,
>  		  enum bfd_endian endianness)
>  {
> -  bfd_byte buffer[INSNLEN];
> -  int status;
> +    bfd_byte buffer[INSNLEN];
> +    int status;
>  
> -  status = (*info->read_memory_func) (address, buffer, INSNLEN, info);
> -  if (status == 0)
> -    {
> -      unsigned long insn;
> -      if (endianness == BFD_ENDIAN_BIG)
> -	insn = (unsigned long) bfd_getb32 (buffer);
> -      else
> -	insn = (unsigned long) bfd_getl32 (buffer);
> -      return nios2_disassemble (address, insn, info);
> +    status = (*info->read_memory_func)(address, buffer, INSNLEN, info);
> +    if (status == 0) {
> +        unsigned long insn;
> +        if (endianness == BFD_ENDIAN_BIG) {
> +            insn = (unsigned long) bfd_getb32(buffer);
> +        } else {
> +            insn = (unsigned long) bfd_getl32(buffer);
> +        }
> +        return nios2_disassemble(address, insn, info);
>      }
>  
> -  /* We might have a 16-bit R2 instruction at the end of memory.  Try that.  */
> -  if (info->mach == bfd_mach_nios2r2)
> -    {
> -      status = (*info->read_memory_func) (address, buffer, 2, info);
> -      if (status == 0)
> -	{
> -	  unsigned long insn;
> -	  if (endianness == BFD_ENDIAN_BIG)
> -	    insn = (unsigned long) bfd_getb16 (buffer);
> -	  else
> -	    insn = (unsigned long) bfd_getl16 (buffer);
> -	  return nios2_disassemble (address, insn, info);
> -	}
> +    /* We might have a 16-bit R2 instruction at the end of memory. Try that. */
> +    if (info->mach == bfd_mach_nios2r2) {
> +        status = (*info->read_memory_func)(address, buffer, 2, info);
> +        if (status == 0) {
> +            unsigned long insn;
> +            if (endianness == BFD_ENDIAN_BIG) {
> +                insn = (unsigned long) bfd_getb16(buffer);
> +            } else {
> +                insn = (unsigned long) bfd_getl16(buffer);
> +            }
> +            return nios2_disassemble(address, insn, info);
> +        }
>      }
>  
> -  /* If we got here, we couldn't read anything.  */
> -  (*info->memory_error_func) (status, address, info);
> -  return -1;
> +    /* If we got here, we couldn't read anything.  */
> +    (*info->memory_error_func)(status, address, info);
> +    return -1;
>  }
>  
>  /* These two functions are the main entry points, accessed from
> 

Reviewed-by: Laurent Vivier <laurent@vivier.eu>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH-for-6.2 2/2] disas/nios2: Simplify endianess conversion
  2021-08-07 11:09 ` [PATCH-for-6.2 2/2] disas/nios2: Simplify endianess conversion Philippe Mathieu-Daudé
  2021-08-09  6:12   ` Thomas Huth
@ 2021-09-29 15:28   ` Laurent Vivier
  1 sibling, 0 replies; 13+ messages in thread
From: Laurent Vivier @ 2021-09-29 15:28 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Marek Vasut, Alex Bennée, Thomas Huth, Chris Wulff,
	Richard Henderson

Le 07/08/2021 à 13:09, Philippe Mathieu-Daudé a écrit :
> Since commit 12b6e9b27d4 ("disas: Clean up CPUDebug initialization")
> the disassemble_info->bfd_endian enum is set for all targets in
> target_disas(). We can directly call print_insn_nios2() and simplify.
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  include/disas/dis-asm.h |  3 +--
>  disas/nios2.c           | 22 +++-------------------
>  target/nios2/cpu.c      |  6 +-----
>  3 files changed, 5 insertions(+), 26 deletions(-)
> 
> diff --git a/include/disas/dis-asm.h b/include/disas/dis-asm.h
> index 524f29196d9..08e1beec854 100644
> --- a/include/disas/dis-asm.h
> +++ b/include/disas/dis-asm.h
> @@ -455,8 +455,7 @@ int print_insn_crisv32          (bfd_vma, disassemble_info*);
>  int print_insn_crisv10          (bfd_vma, disassemble_info*);
>  int print_insn_microblaze       (bfd_vma, disassemble_info*);
>  int print_insn_ia64             (bfd_vma, disassemble_info*);
> -int print_insn_big_nios2        (bfd_vma, disassemble_info*);
> -int print_insn_little_nios2     (bfd_vma, disassemble_info*);
> +int print_insn_nios2(bfd_vma, disassemble_info*);
>  int print_insn_xtensa           (bfd_vma, disassemble_info*);
>  int print_insn_riscv32          (bfd_vma, disassemble_info*);
>  int print_insn_riscv64          (bfd_vma, disassemble_info*);
> diff --git a/disas/nios2.c b/disas/nios2.c
> index d124902ae3e..98ac07d72e9 100644
> --- a/disas/nios2.c
> +++ b/disas/nios2.c
> @@ -3478,9 +3478,7 @@ nios2_disassemble (bfd_vma address, unsigned long opcode,
>     instruction word at the address given, and prints the disassembled
>     instruction on the stream info->stream using info->fprintf_func. */
>  
> -static int
> -print_insn_nios2 (bfd_vma address, disassemble_info *info,
> -		  enum bfd_endian endianness)
> +int print_insn_nios2(bfd_vma address, disassemble_info *info)
>  {
>      bfd_byte buffer[INSNLEN];
>      int status;
> @@ -3488,7 +3486,7 @@ print_insn_nios2 (bfd_vma address, disassemble_info *info,
>      status = (*info->read_memory_func)(address, buffer, INSNLEN, info);
>      if (status == 0) {
>          unsigned long insn;
> -        if (endianness == BFD_ENDIAN_BIG) {
> +        if (info->endian == BFD_ENDIAN_BIG) {
>              insn = (unsigned long) bfd_getb32(buffer);
>          } else {
>              insn = (unsigned long) bfd_getl32(buffer);
> @@ -3501,7 +3499,7 @@ print_insn_nios2 (bfd_vma address, disassemble_info *info,
>          status = (*info->read_memory_func)(address, buffer, 2, info);
>          if (status == 0) {
>              unsigned long insn;
> -            if (endianness == BFD_ENDIAN_BIG) {
> +            if (info->endian == BFD_ENDIAN_BIG) {
>                  insn = (unsigned long) bfd_getb16(buffer);
>              } else {
>                  insn = (unsigned long) bfd_getl16(buffer);
> @@ -3514,17 +3512,3 @@ print_insn_nios2 (bfd_vma address, disassemble_info *info,
>      (*info->memory_error_func)(status, address, info);
>      return -1;
>  }
> -
> -/* These two functions are the main entry points, accessed from
> -   disassemble.c.  */
> -int
> -print_insn_big_nios2 (bfd_vma address, disassemble_info *info)
> -{
> -  return print_insn_nios2 (address, info, BFD_ENDIAN_BIG);
> -}
> -
> -int
> -print_insn_little_nios2 (bfd_vma address, disassemble_info *info)
> -{
> -  return print_insn_nios2 (address, info, BFD_ENDIAN_LITTLE);
> -}
> diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c
> index 5e37defef80..5b503b5bb99 100644
> --- a/target/nios2/cpu.c
> +++ b/target/nios2/cpu.c
> @@ -146,11 +146,7 @@ static void nios2_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)
>  {
>      /* NOTE: NiosII R2 is not supported yet. */
>      info->mach = bfd_arch_nios2;
> -#ifdef TARGET_WORDS_BIGENDIAN
> -    info->print_insn = print_insn_big_nios2;
> -#else
> -    info->print_insn = print_insn_little_nios2;
> -#endif
> +    info->print_insn = print_insn_nios2;
>  }
>  
>  static int nios2_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
> 

Reviewed-by: Laurent Vivier <laurent@vivier.eu>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH-for-6.2 0/2] disas/nios2: Simplify endianess conversion
  2021-08-07 11:09 [PATCH-for-6.2 0/2] disas/nios2: Simplify endianess conversion Philippe Mathieu-Daudé
                   ` (2 preceding siblings ...)
  2021-09-18  9:19 ` [PATCH-for-6.2 0/2] " Philippe Mathieu-Daudé
@ 2021-10-19  7:43 ` Laurent Vivier
  3 siblings, 0 replies; 13+ messages in thread
From: Laurent Vivier @ 2021-10-19  7:43 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Marek Vasut, Thomas Huth, qemu-trivial, Chris Wulff,
	Richard Henderson, Alex Bennée

Le 07/08/2021 à 13:09, Philippe Mathieu-Daudé a écrit :
> After chatting with Richard Henderson and Paolo Bonzini, we
> concluded the load/store API is mature enough to have target
> code endianess-agnostic.
> Thus we could remove the TARGET_WORDS_BIGENDIAN definition from
> target-specific code (restricting it to the binary format loaders).
> 
> While experimenting, I noticed the Nios2 disassembler is an easy
> win. MIPS will follow shortly.
> 
> Philippe Mathieu-Daudé (2):
>   disas/nios2: Fix style in print_insn_nios2()
>   disas/nios2: Simplify endianess conversion
> 
>  include/disas/dis-asm.h |  3 +-
>  disas/nios2.c           | 71 ++++++++++++++++-------------------------
>  target/nios2/cpu.c      |  6 +---
>  3 files changed, 29 insertions(+), 51 deletions(-)
> 

Applied to my trivial-patches branch.

Thanks,
Laurent


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-10-19  8:03 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-07 11:09 [PATCH-for-6.2 0/2] disas/nios2: Simplify endianess conversion Philippe Mathieu-Daudé
2021-08-07 11:09 ` [PATCH-for-6.2 1/2] disas/nios2: Fix style in print_insn_nios2() Philippe Mathieu-Daudé
2021-08-09  6:08   ` Thomas Huth
2021-08-09  7:14     ` Philippe Mathieu-Daudé
2021-09-29 15:28   ` Laurent Vivier
2021-08-07 11:09 ` [PATCH-for-6.2 2/2] disas/nios2: Simplify endianess conversion Philippe Mathieu-Daudé
2021-08-09  6:12   ` Thomas Huth
2021-08-09  9:48     ` Philippe Mathieu-Daudé
2021-09-29 15:28   ` Laurent Vivier
2021-09-18  9:19 ` [PATCH-for-6.2 0/2] " Philippe Mathieu-Daudé
2021-09-23 15:14   ` Laurent Vivier
2021-09-24  9:40     ` Philippe Mathieu-Daudé
2021-10-19  7:43 ` Laurent Vivier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.