diff mbox series

[07/13] hw/xtensa/xtfpga: Remove TARGET_BIG_ENDIAN #ifdef'ry

Message ID 20240930073450.33195-8-philmd@linaro.org
State Superseded
Headers show
Series hw: Add ld/st_endian() APIs | expand

Commit Message

Philippe Mathieu-Daudé Sept. 30, 2024, 7:34 a.m. UTC
Move code evaluation from preprocessor to compiler so
both if() ladders are processed. Mostly style change.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/xtensa/xtfpga.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Thomas Huth Sept. 30, 2024, 2:28 p.m. UTC | #1
On 30/09/2024 09.34, Philippe Mathieu-Daudé wrote:
> Move code evaluation from preprocessor to compiler so
> both if() ladders are processed. Mostly style change.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/xtensa/xtfpga.c | 12 +++++++-----
>   1 file changed, 7 insertions(+), 5 deletions(-)

Reviewed-by: Thomas Huth <thuth@redhat.com>
Pierrick Bouvier Oct. 1, 2024, 4:51 p.m. UTC | #2
On 9/30/24 00:34, Philippe Mathieu-Daudé wrote:
> Move code evaluation from preprocessor to compiler so
> both if() ladders are processed. Mostly style change.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/xtensa/xtfpga.c | 12 +++++++-----
>   1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
> index 955e8867a3..228f00b045 100644
> --- a/hw/xtensa/xtfpga.c
> +++ b/hw/xtensa/xtfpga.c
> @@ -415,8 +415,7 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
>               }
>           }
>           if (entry_point != env->pc) {
> -            uint8_t boot[] = {
> -#if TARGET_BIG_ENDIAN
> +            uint8_t boot_be[] = {
>                   0x60, 0x00, 0x08,       /* j    1f */
>                   0x00,                   /* .literal_position */
>                   0x00, 0x00, 0x00, 0x00, /* .literal entry_pc */
> @@ -425,7 +424,8 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
>                   0x10, 0xff, 0xfe,       /* l32r a0, entry_pc */
>                   0x12, 0xff, 0xfe,       /* l32r a2, entry_a2 */
>                   0x0a, 0x00, 0x00,       /* jx   a0 */
> -#else
> +            };
> +            uint8_t boot_le[] = {
>                   0x06, 0x02, 0x00,       /* j    1f */
>                   0x00,                   /* .literal_position */
>                   0x00, 0x00, 0x00, 0x00, /* .literal entry_pc */
> @@ -434,14 +434,16 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
>                   0x01, 0xfe, 0xff,       /* l32r a0, entry_pc */
>                   0x21, 0xfe, 0xff,       /* l32r a2, entry_a2 */
>                   0xa0, 0x00, 0x00,       /* jx   a0 */
> -#endif
>               };
> +            const size_t boot_sz = TARGET_BIG_ENDIAN ? sizeof(boot_be)
> +                                                     : sizeof(boot_le);
> +            uint8_t *boot = TARGET_BIG_ENDIAN ? boot_be : boot_le;
>               uint32_t entry_pc = tswap32(entry_point);
>               uint32_t entry_a2 = tswap32(tagptr);
>   
>               memcpy(boot + 4, &entry_pc, sizeof(entry_pc));
>               memcpy(boot + 8, &entry_a2, sizeof(entry_a2));
> -            cpu_physical_memory_write(env->pc, boot, sizeof(boot));
> +            cpu_physical_memory_write(env->pc, boot, boot_sz);
>           }
>       } else {
>           if (flash) {

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Richard Henderson Oct. 3, 2024, 9:35 p.m. UTC | #3
On 9/30/24 00:34, Philippe Mathieu-Daudé wrote:
> Move code evaluation from preprocessor to compiler so
> both if() ladders are processed. Mostly style change.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/xtensa/xtfpga.c | 12 +++++++-----
>   1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
> index 955e8867a3..228f00b045 100644
> --- a/hw/xtensa/xtfpga.c
> +++ b/hw/xtensa/xtfpga.c
> @@ -415,8 +415,7 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
>               }
>           }
>           if (entry_point != env->pc) {
> -            uint8_t boot[] = {
> -#if TARGET_BIG_ENDIAN
> +            uint8_t boot_be[] = {
>                   0x60, 0x00, 0x08,       /* j    1f */
>                   0x00,                   /* .literal_position */
>                   0x00, 0x00, 0x00, 0x00, /* .literal entry_pc */
> @@ -425,7 +424,8 @@ static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
>                   0x10, 0xff, 0xfe,       /* l32r a0, entry_pc */
>                   0x12, 0xff, 0xfe,       /* l32r a2, entry_a2 */
>                   0x0a, 0x00, 0x00,       /* jx   a0 */
> -#else
> +            };
> +            uint8_t boot_le[] = {

Fix these to use static const?


r~
Philippe Mathieu-Daudé Oct. 10, 2024, 6:08 p.m. UTC | #4
On 3/10/24 18:35, Richard Henderson wrote:
> On 9/30/24 00:34, Philippe Mathieu-Daudé wrote:
>> Move code evaluation from preprocessor to compiler so
>> both if() ladders are processed. Mostly style change.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>   hw/xtensa/xtfpga.c | 12 +++++++-----
>>   1 file changed, 7 insertions(+), 5 deletions(-)
>>
>> diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
>> index 955e8867a3..228f00b045 100644
>> --- a/hw/xtensa/xtfpga.c
>> +++ b/hw/xtensa/xtfpga.c
>> @@ -415,8 +415,7 @@ static void xtfpga_init(const XtfpgaBoardDesc 
>> *board, MachineState *machine)
>>               }
>>           }
>>           if (entry_point != env->pc) {
>> -            uint8_t boot[] = {
>> -#if TARGET_BIG_ENDIAN
>> +            uint8_t boot_be[] = {
>>                   0x60, 0x00, 0x08,       /* j    1f */
>>                   0x00,                   /* .literal_position */
>>                   0x00, 0x00, 0x00, 0x00, /* .literal entry_pc */

                                              ^^^^^^^^^^^^^^^^

>> @@ -425,7 +424,8 @@ static void xtfpga_init(const XtfpgaBoardDesc 
>> *board, MachineState *machine)
>>                   0x10, 0xff, 0xfe,       /* l32r a0, entry_pc */
>>                   0x12, 0xff, 0xfe,       /* l32r a2, entry_a2 */
>>                   0x0a, 0x00, 0x00,       /* jx   a0 */
>> -#else
>> +            };
>> +            uint8_t boot_le[] = {
> 
> Fix these to use static const?

We use memcpy() to up update $pc/$a2 in place.

> 
> 
> r~
diff mbox series

Patch

diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
index 955e8867a3..228f00b045 100644
--- a/hw/xtensa/xtfpga.c
+++ b/hw/xtensa/xtfpga.c
@@ -415,8 +415,7 @@  static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
             }
         }
         if (entry_point != env->pc) {
-            uint8_t boot[] = {
-#if TARGET_BIG_ENDIAN
+            uint8_t boot_be[] = {
                 0x60, 0x00, 0x08,       /* j    1f */
                 0x00,                   /* .literal_position */
                 0x00, 0x00, 0x00, 0x00, /* .literal entry_pc */
@@ -425,7 +424,8 @@  static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
                 0x10, 0xff, 0xfe,       /* l32r a0, entry_pc */
                 0x12, 0xff, 0xfe,       /* l32r a2, entry_a2 */
                 0x0a, 0x00, 0x00,       /* jx   a0 */
-#else
+            };
+            uint8_t boot_le[] = {
                 0x06, 0x02, 0x00,       /* j    1f */
                 0x00,                   /* .literal_position */
                 0x00, 0x00, 0x00, 0x00, /* .literal entry_pc */
@@ -434,14 +434,16 @@  static void xtfpga_init(const XtfpgaBoardDesc *board, MachineState *machine)
                 0x01, 0xfe, 0xff,       /* l32r a0, entry_pc */
                 0x21, 0xfe, 0xff,       /* l32r a2, entry_a2 */
                 0xa0, 0x00, 0x00,       /* jx   a0 */
-#endif
             };
+            const size_t boot_sz = TARGET_BIG_ENDIAN ? sizeof(boot_be)
+                                                     : sizeof(boot_le);
+            uint8_t *boot = TARGET_BIG_ENDIAN ? boot_be : boot_le;
             uint32_t entry_pc = tswap32(entry_point);
             uint32_t entry_a2 = tswap32(tagptr);
 
             memcpy(boot + 4, &entry_pc, sizeof(entry_pc));
             memcpy(boot + 8, &entry_a2, sizeof(entry_a2));
-            cpu_physical_memory_write(env->pc, boot, sizeof(boot));
+            cpu_physical_memory_write(env->pc, boot, boot_sz);
         }
     } else {
         if (flash) {