diff mbox series

[11/16] hw/sparc: Use explicit big-endian LD/ST API

Message ID 20241003234211.53644-12-philmd@linaro.org (mailing list archive)
State New, archived
Headers show
Series misc: Use explicit endian LD/ST API | expand

Commit Message

Philippe Mathieu-Daudé Oct. 3, 2024, 11:42 p.m. UTC
The SPARC architecture uses big endianness. Directly use
the big-endian LD/ST API.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/sparc/leon3.c   | 42 +++++++++++++++++++++---------------------
 hw/sparc/sun4m.c   |  6 +++---
 hw/sparc64/sun4u.c |  6 +++---
 3 files changed, 27 insertions(+), 27 deletions(-)

Comments

Mark Cave-Ayland Oct. 4, 2024, 5:31 p.m. UTC | #1
On 04/10/2024 00:42, Philippe Mathieu-Daudé wrote:

> The SPARC architecture uses big endianness. Directly use
> the big-endian LD/ST API.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/sparc/leon3.c   | 42 +++++++++++++++++++++---------------------
>   hw/sparc/sun4m.c   |  6 +++---
>   hw/sparc64/sun4u.c |  6 +++---
>   3 files changed, 27 insertions(+), 27 deletions(-)
> 
> diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
> index 6aaa04cb191..021b5070128 100644
> --- a/hw/sparc/leon3.c
> +++ b/hw/sparc/leon3.c
> @@ -78,21 +78,21 @@ typedef struct ResetData {
>   
>   static uint32_t *gen_store_u32(uint32_t *code, hwaddr addr, uint32_t val)
>   {
> -    stl_p(code++, 0x82100000); /* mov %g0, %g1                */
> -    stl_p(code++, 0x84100000); /* mov %g0, %g2                */
> -    stl_p(code++, 0x03000000 +
> +    stl_be_p(code++, 0x82100000); /* mov %g0, %g1                */
> +    stl_be_p(code++, 0x84100000); /* mov %g0, %g2                */
> +    stl_be_p(code++, 0x03000000 +
>         extract32(addr, 10, 22));
>                                  /* sethi %hi(addr), %g1        */
> -    stl_p(code++, 0x82106000 +
> +    stl_be_p(code++, 0x82106000 +
>         extract32(addr, 0, 10));
>                                  /* or %g1, addr, %g1           */
> -    stl_p(code++, 0x05000000 +
> +    stl_be_p(code++, 0x05000000 +
>         extract32(val, 10, 22));
>                                  /* sethi %hi(val), %g2         */
> -    stl_p(code++, 0x8410a000 +
> +    stl_be_p(code++, 0x8410a000 +
>         extract32(val, 0, 10));
>                                  /* or %g2, val, %g2            */
> -    stl_p(code++, 0xc4204000); /* st %g2, [ %g1 ]             */
> +    stl_be_p(code++, 0xc4204000); /* st %g2, [ %g1 ]             */
>   
>       return code;
>   }
> @@ -112,13 +112,13 @@ static void write_bootloader(void *ptr, hwaddr kernel_addr)
>   
>       /* If we are running on a secondary CPU, jump directly to the kernel.  */
>   
> -    stl_p(p++, 0x85444000); /* rd %asr17, %g2      */
> -    stl_p(p++, 0x8530a01c); /* srl  %g2, 0x1c, %g2 */
> -    stl_p(p++, 0x80908000); /* tst  %g2            */
> +    stl_be_p(p++, 0x85444000); /* rd %asr17, %g2      */
> +    stl_be_p(p++, 0x8530a01c); /* srl  %g2, 0x1c, %g2 */
> +    stl_be_p(p++, 0x80908000); /* tst  %g2            */
>       /* Filled below.  */
>       sec_cpu_branch_p = p;
> -    stl_p(p++, 0x0BADC0DE); /* bne xxx             */
> -    stl_p(p++, 0x01000000); /* nop */
> +    stl_be_p(p++, 0x0BADC0DE); /* bne xxx             */
> +    stl_be_p(p++, 0x01000000); /* nop */
>   
>       /* Initialize the UARTs                                        */
>       /* *UART_CONTROL = UART_RECEIVE_ENABLE | UART_TRANSMIT_ENABLE; */
> @@ -133,17 +133,17 @@ static void write_bootloader(void *ptr, hwaddr kernel_addr)
>       p = gen_store_u32(p, 0x80000318, 3);
>   
>       /* Now, the relative branch above can be computed.  */
> -    stl_p(sec_cpu_branch_p, 0x12800000
> -          + (p - sec_cpu_branch_p));
> +    stl_be_p(sec_cpu_branch_p, 0x12800000
> +             + (p - sec_cpu_branch_p));
>   
>       /* JUMP to the entry point                                     */
> -    stl_p(p++, 0x82100000); /* mov %g0, %g1 */
> -    stl_p(p++, 0x03000000 + extract32(kernel_addr, 10, 22));
> -                            /* sethi %hi(kernel_addr), %g1 */
> -    stl_p(p++, 0x82106000 + extract32(kernel_addr, 0, 10));
> -                            /* or kernel_addr, %g1 */
> -    stl_p(p++, 0x81c04000); /* jmp  %g1 */
> -    stl_p(p++, 0x01000000); /* nop */
> +    stl_be_p(p++, 0x82100000); /* mov %g0, %g1 */
> +    stl_be_p(p++, 0x03000000 + extract32(kernel_addr, 10, 22));
> +                               /* sethi %hi(kernel_addr), %g1 */
> +    stl_be_p(p++, 0x82106000 + extract32(kernel_addr, 0, 10));
> +                               /* or kernel_addr, %g1 */
> +    stl_be_p(p++, 0x81c04000); /* jmp  %g1 */
> +    stl_be_p(p++, 0x01000000); /* nop */
>   }
>   
>   static void leon3_cpu_reset(void *opaque)
> diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
> index d52e6a7213f..f375f0d389b 100644
> --- a/hw/sparc/sun4m.c
> +++ b/hw/sparc/sun4m.c
> @@ -271,9 +271,9 @@ static unsigned long sun4m_load_kernel(const char *kernel_filename,
>           if (*initrd_size > 0) {
>               for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
>                   ptr = rom_ptr(KERNEL_LOAD_ADDR + i, 24);
> -                if (ptr && ldl_p(ptr) == 0x48647253) { /* HdrS */
> -                    stl_p(ptr + 16, INITRD_LOAD_ADDR);
> -                    stl_p(ptr + 20, *initrd_size);
> +                if (ptr && ldl_be_p(ptr) == 0x48647253) { /* HdrS */
> +                    stl_be_p(ptr + 16, INITRD_LOAD_ADDR);
> +                    stl_be_p(ptr + 20, *initrd_size);
>                       break;
>                   }
>               }
> diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c
> index 4ece1ac1ffc..e591e5a741a 100644
> --- a/hw/sparc64/sun4u.c
> +++ b/hw/sparc64/sun4u.c
> @@ -210,9 +210,9 @@ static uint64_t sun4u_load_kernel(const char *kernel_filename,
>           if (*initrd_size > 0) {
>               for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
>                   ptr = rom_ptr(*kernel_addr + i, 32);
> -                if (ptr && ldl_p(ptr + 8) == 0x48647253) { /* HdrS */
> -                    stl_p(ptr + 24, *initrd_addr + *kernel_addr);
> -                    stl_p(ptr + 28, *initrd_size);
> +                if (ptr && ldl_be_p(ptr + 8) == 0x48647253) { /* HdrS */
> +                    stl_be_p(ptr + 24, *initrd_addr + *kernel_addr);
> +                    stl_be_p(ptr + 28, *initrd_size);
>                       break;
>                   }
>               }

For sun4m and sun4u:

Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>


ATB,

Mark.
Clément Chigot Oct. 7, 2024, 7:03 a.m. UTC | #2
On Fri, Oct 4, 2024 at 1:43 AM Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> The SPARC architecture uses big endianness. Directly use
> the big-endian LD/ST API.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  hw/sparc/leon3.c   | 42 +++++++++++++++++++++---------------------
>  hw/sparc/sun4m.c   |  6 +++---
>  hw/sparc64/sun4u.c |  6 +++---
>  3 files changed, 27 insertions(+), 27 deletions(-)
>
> diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
> index 6aaa04cb191..021b5070128 100644
> --- a/hw/sparc/leon3.c
> +++ b/hw/sparc/leon3.c
> @@ -78,21 +78,21 @@ typedef struct ResetData {
>
>  static uint32_t *gen_store_u32(uint32_t *code, hwaddr addr, uint32_t val)
>  {
> -    stl_p(code++, 0x82100000); /* mov %g0, %g1                */
> -    stl_p(code++, 0x84100000); /* mov %g0, %g2                */
> -    stl_p(code++, 0x03000000 +
> +    stl_be_p(code++, 0x82100000); /* mov %g0, %g1                */
> +    stl_be_p(code++, 0x84100000); /* mov %g0, %g2                */
> +    stl_be_p(code++, 0x03000000 +
>        extract32(addr, 10, 22));
>                                 /* sethi %hi(addr), %g1        */
> -    stl_p(code++, 0x82106000 +
> +    stl_be_p(code++, 0x82106000 +
>        extract32(addr, 0, 10));
>                                 /* or %g1, addr, %g1           */
> -    stl_p(code++, 0x05000000 +
> +    stl_be_p(code++, 0x05000000 +
>        extract32(val, 10, 22));
>                                 /* sethi %hi(val), %g2         */
> -    stl_p(code++, 0x8410a000 +
> +    stl_be_p(code++, 0x8410a000 +
>        extract32(val, 0, 10));
>                                 /* or %g2, val, %g2            */
> -    stl_p(code++, 0xc4204000); /* st %g2, [ %g1 ]             */
> +    stl_be_p(code++, 0xc4204000); /* st %g2, [ %g1 ]             */
>
>      return code;
>  }
> @@ -112,13 +112,13 @@ static void write_bootloader(void *ptr, hwaddr kernel_addr)
>
>      /* If we are running on a secondary CPU, jump directly to the kernel.  */
>
> -    stl_p(p++, 0x85444000); /* rd %asr17, %g2      */
> -    stl_p(p++, 0x8530a01c); /* srl  %g2, 0x1c, %g2 */
> -    stl_p(p++, 0x80908000); /* tst  %g2            */
> +    stl_be_p(p++, 0x85444000); /* rd %asr17, %g2      */
> +    stl_be_p(p++, 0x8530a01c); /* srl  %g2, 0x1c, %g2 */
> +    stl_be_p(p++, 0x80908000); /* tst  %g2            */
>      /* Filled below.  */
>      sec_cpu_branch_p = p;
> -    stl_p(p++, 0x0BADC0DE); /* bne xxx             */
> -    stl_p(p++, 0x01000000); /* nop */
> +    stl_be_p(p++, 0x0BADC0DE); /* bne xxx             */
> +    stl_be_p(p++, 0x01000000); /* nop */
>
>      /* Initialize the UARTs                                        */
>      /* *UART_CONTROL = UART_RECEIVE_ENABLE | UART_TRANSMIT_ENABLE; */
> @@ -133,17 +133,17 @@ static void write_bootloader(void *ptr, hwaddr kernel_addr)
>      p = gen_store_u32(p, 0x80000318, 3);
>
>      /* Now, the relative branch above can be computed.  */
> -    stl_p(sec_cpu_branch_p, 0x12800000
> -          + (p - sec_cpu_branch_p));
> +    stl_be_p(sec_cpu_branch_p, 0x12800000
> +             + (p - sec_cpu_branch_p));
>
>      /* JUMP to the entry point                                     */
> -    stl_p(p++, 0x82100000); /* mov %g0, %g1 */
> -    stl_p(p++, 0x03000000 + extract32(kernel_addr, 10, 22));
> -                            /* sethi %hi(kernel_addr), %g1 */
> -    stl_p(p++, 0x82106000 + extract32(kernel_addr, 0, 10));
> -                            /* or kernel_addr, %g1 */
> -    stl_p(p++, 0x81c04000); /* jmp  %g1 */
> -    stl_p(p++, 0x01000000); /* nop */
> +    stl_be_p(p++, 0x82100000); /* mov %g0, %g1 */
> +    stl_be_p(p++, 0x03000000 + extract32(kernel_addr, 10, 22));
> +                               /* sethi %hi(kernel_addr), %g1 */
> +    stl_be_p(p++, 0x82106000 + extract32(kernel_addr, 0, 10));
> +                               /* or kernel_addr, %g1 */
> +    stl_be_p(p++, 0x81c04000); /* jmp  %g1 */
> +    stl_be_p(p++, 0x01000000); /* nop */
>  }
>
>  static void leon3_cpu_reset(void *opaque)
> diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
> index d52e6a7213f..f375f0d389b 100644
> --- a/hw/sparc/sun4m.c
> +++ b/hw/sparc/sun4m.c
> @@ -271,9 +271,9 @@ static unsigned long sun4m_load_kernel(const char *kernel_filename,
>          if (*initrd_size > 0) {
>              for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
>                  ptr = rom_ptr(KERNEL_LOAD_ADDR + i, 24);
> -                if (ptr && ldl_p(ptr) == 0x48647253) { /* HdrS */
> -                    stl_p(ptr + 16, INITRD_LOAD_ADDR);
> -                    stl_p(ptr + 20, *initrd_size);
> +                if (ptr && ldl_be_p(ptr) == 0x48647253) { /* HdrS */
> +                    stl_be_p(ptr + 16, INITRD_LOAD_ADDR);
> +                    stl_be_p(ptr + 20, *initrd_size);
>                      break;
>                  }
>              }
> diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c
> index 4ece1ac1ffc..e591e5a741a 100644
> --- a/hw/sparc64/sun4u.c
> +++ b/hw/sparc64/sun4u.c
> @@ -210,9 +210,9 @@ static uint64_t sun4u_load_kernel(const char *kernel_filename,
>          if (*initrd_size > 0) {
>              for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
>                  ptr = rom_ptr(*kernel_addr + i, 32);
> -                if (ptr && ldl_p(ptr + 8) == 0x48647253) { /* HdrS */
> -                    stl_p(ptr + 24, *initrd_addr + *kernel_addr);
> -                    stl_p(ptr + 28, *initrd_size);
> +                if (ptr && ldl_be_p(ptr + 8) == 0x48647253) { /* HdrS */
> +                    stl_be_p(ptr + 24, *initrd_addr + *kernel_addr);
> +                    stl_be_p(ptr + 28, *initrd_size);
>                      break;
>                  }
>              }
> --
> 2.45.2

For leon3:

Reviewed-by: Chigot Clément <chigot@adacore.com>
diff mbox series

Patch

diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
index 6aaa04cb191..021b5070128 100644
--- a/hw/sparc/leon3.c
+++ b/hw/sparc/leon3.c
@@ -78,21 +78,21 @@  typedef struct ResetData {
 
 static uint32_t *gen_store_u32(uint32_t *code, hwaddr addr, uint32_t val)
 {
-    stl_p(code++, 0x82100000); /* mov %g0, %g1                */
-    stl_p(code++, 0x84100000); /* mov %g0, %g2                */
-    stl_p(code++, 0x03000000 +
+    stl_be_p(code++, 0x82100000); /* mov %g0, %g1                */
+    stl_be_p(code++, 0x84100000); /* mov %g0, %g2                */
+    stl_be_p(code++, 0x03000000 +
       extract32(addr, 10, 22));
                                /* sethi %hi(addr), %g1        */
-    stl_p(code++, 0x82106000 +
+    stl_be_p(code++, 0x82106000 +
       extract32(addr, 0, 10));
                                /* or %g1, addr, %g1           */
-    stl_p(code++, 0x05000000 +
+    stl_be_p(code++, 0x05000000 +
       extract32(val, 10, 22));
                                /* sethi %hi(val), %g2         */
-    stl_p(code++, 0x8410a000 +
+    stl_be_p(code++, 0x8410a000 +
       extract32(val, 0, 10));
                                /* or %g2, val, %g2            */
-    stl_p(code++, 0xc4204000); /* st %g2, [ %g1 ]             */
+    stl_be_p(code++, 0xc4204000); /* st %g2, [ %g1 ]             */
 
     return code;
 }
@@ -112,13 +112,13 @@  static void write_bootloader(void *ptr, hwaddr kernel_addr)
 
     /* If we are running on a secondary CPU, jump directly to the kernel.  */
 
-    stl_p(p++, 0x85444000); /* rd %asr17, %g2      */
-    stl_p(p++, 0x8530a01c); /* srl  %g2, 0x1c, %g2 */
-    stl_p(p++, 0x80908000); /* tst  %g2            */
+    stl_be_p(p++, 0x85444000); /* rd %asr17, %g2      */
+    stl_be_p(p++, 0x8530a01c); /* srl  %g2, 0x1c, %g2 */
+    stl_be_p(p++, 0x80908000); /* tst  %g2            */
     /* Filled below.  */
     sec_cpu_branch_p = p;
-    stl_p(p++, 0x0BADC0DE); /* bne xxx             */
-    stl_p(p++, 0x01000000); /* nop */
+    stl_be_p(p++, 0x0BADC0DE); /* bne xxx             */
+    stl_be_p(p++, 0x01000000); /* nop */
 
     /* Initialize the UARTs                                        */
     /* *UART_CONTROL = UART_RECEIVE_ENABLE | UART_TRANSMIT_ENABLE; */
@@ -133,17 +133,17 @@  static void write_bootloader(void *ptr, hwaddr kernel_addr)
     p = gen_store_u32(p, 0x80000318, 3);
 
     /* Now, the relative branch above can be computed.  */
-    stl_p(sec_cpu_branch_p, 0x12800000
-          + (p - sec_cpu_branch_p));
+    stl_be_p(sec_cpu_branch_p, 0x12800000
+             + (p - sec_cpu_branch_p));
 
     /* JUMP to the entry point                                     */
-    stl_p(p++, 0x82100000); /* mov %g0, %g1 */
-    stl_p(p++, 0x03000000 + extract32(kernel_addr, 10, 22));
-                            /* sethi %hi(kernel_addr), %g1 */
-    stl_p(p++, 0x82106000 + extract32(kernel_addr, 0, 10));
-                            /* or kernel_addr, %g1 */
-    stl_p(p++, 0x81c04000); /* jmp  %g1 */
-    stl_p(p++, 0x01000000); /* nop */
+    stl_be_p(p++, 0x82100000); /* mov %g0, %g1 */
+    stl_be_p(p++, 0x03000000 + extract32(kernel_addr, 10, 22));
+                               /* sethi %hi(kernel_addr), %g1 */
+    stl_be_p(p++, 0x82106000 + extract32(kernel_addr, 0, 10));
+                               /* or kernel_addr, %g1 */
+    stl_be_p(p++, 0x81c04000); /* jmp  %g1 */
+    stl_be_p(p++, 0x01000000); /* nop */
 }
 
 static void leon3_cpu_reset(void *opaque)
diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index d52e6a7213f..f375f0d389b 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -271,9 +271,9 @@  static unsigned long sun4m_load_kernel(const char *kernel_filename,
         if (*initrd_size > 0) {
             for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
                 ptr = rom_ptr(KERNEL_LOAD_ADDR + i, 24);
-                if (ptr && ldl_p(ptr) == 0x48647253) { /* HdrS */
-                    stl_p(ptr + 16, INITRD_LOAD_ADDR);
-                    stl_p(ptr + 20, *initrd_size);
+                if (ptr && ldl_be_p(ptr) == 0x48647253) { /* HdrS */
+                    stl_be_p(ptr + 16, INITRD_LOAD_ADDR);
+                    stl_be_p(ptr + 20, *initrd_size);
                     break;
                 }
             }
diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c
index 4ece1ac1ffc..e591e5a741a 100644
--- a/hw/sparc64/sun4u.c
+++ b/hw/sparc64/sun4u.c
@@ -210,9 +210,9 @@  static uint64_t sun4u_load_kernel(const char *kernel_filename,
         if (*initrd_size > 0) {
             for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
                 ptr = rom_ptr(*kernel_addr + i, 32);
-                if (ptr && ldl_p(ptr + 8) == 0x48647253) { /* HdrS */
-                    stl_p(ptr + 24, *initrd_addr + *kernel_addr);
-                    stl_p(ptr + 28, *initrd_size);
+                if (ptr && ldl_be_p(ptr + 8) == 0x48647253) { /* HdrS */
+                    stl_be_p(ptr + 24, *initrd_addr + *kernel_addr);
+                    stl_be_p(ptr + 28, *initrd_size);
                     break;
                 }
             }