[PATCH 2/2] hw/sparc/leon3: Have write_bootloader() take a void pointer argument

Philippe Mathieu-Daudé posted 2 patches 9 months, 2 weeks ago
Maintainers: Fabien Chouteau <chouteau@adacore.com>, Frederic Konrad <konrad.frederic@yahoo.fr>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Artyom Tarasenko <atar4qemu@gmail.com>
[PATCH 2/2] hw/sparc/leon3: Have write_bootloader() take a void pointer argument
Posted by Philippe Mathieu-Daudé 9 months, 2 weeks ago
Directly use the void pointer argument returned
by memory_region_get_ram_ptr().

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/sparc/leon3.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
index d096fb04cb..8717c72e77 100644
--- a/hw/sparc/leon3.c
+++ b/hw/sparc/leon3.c
@@ -94,9 +94,9 @@ static uint32_t *gen_store_u32(uint32_t *code, hwaddr addr, uint32_t val)
  * state (eg: initialized by the bootloader). This little code reproduces
  * this behavior.
  */
-static void write_bootloader(uint8_t *base, hwaddr kernel_addr)
+static void write_bootloader(void *ptr, hwaddr kernel_addr)
 {
-    uint32_t *p = (uint32_t *) base;
+    uint32_t *p = (uint32_t *) ptr;
 
     /* Initialize the UARTs                                        */
     /* *UART_CONTROL = UART_RECEIVE_ENABLE | UART_TRANSMIT_ENABLE; */
@@ -338,10 +338,7 @@ static void leon3_generic_hw_init(MachineState *machine)
              * the machine in an initialized state through a little
              * bootloader.
              */
-            uint8_t *bootloader_entry;
-
-            bootloader_entry = memory_region_get_ram_ptr(prom);
-            write_bootloader(bootloader_entry, entry);
+            write_bootloader(memory_region_get_ram_ptr(prom), entry);
             env->pc = LEON3_PROM_OFFSET;
             env->npc = LEON3_PROM_OFFSET + 4;
             reset_info->entry = LEON3_PROM_OFFSET;
-- 
2.41.0


Re: [PATCH 2/2] hw/sparc/leon3: Have write_bootloader() take a void pointer argument
Posted by Peter Maydell 9 months, 2 weeks ago
On Thu, 15 Feb 2024 at 13:28, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> Directly use the void pointer argument returned
> by memory_region_get_ram_ptr().
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  hw/sparc/leon3.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/hw/sparc/leon3.c b/hw/sparc/leon3.c
> index d096fb04cb..8717c72e77 100644
> --- a/hw/sparc/leon3.c
> +++ b/hw/sparc/leon3.c
> @@ -94,9 +94,9 @@ static uint32_t *gen_store_u32(uint32_t *code, hwaddr addr, uint32_t val)
>   * state (eg: initialized by the bootloader). This little code reproduces
>   * this behavior.
>   */
> -static void write_bootloader(uint8_t *base, hwaddr kernel_addr)
> +static void write_bootloader(void *ptr, hwaddr kernel_addr)
>  {
> -    uint32_t *p = (uint32_t *) base;
> +    uint32_t *p = (uint32_t *) ptr;

I don't think you need the cast any more now ptr is void*.
(If you do, then our coding style doesn't put a space after
the cast.)

>
>      /* Initialize the UARTs                                        */
>      /* *UART_CONTROL = UART_RECEIVE_ENABLE | UART_TRANSMIT_ENABLE; */
> @@ -338,10 +338,7 @@ static void leon3_generic_hw_init(MachineState *machine)
>               * the machine in an initialized state through a little
>               * bootloader.
>               */
> -            uint8_t *bootloader_entry;
> -
> -            bootloader_entry = memory_region_get_ram_ptr(prom);
> -            write_bootloader(bootloader_entry, entry);
> +            write_bootloader(memory_region_get_ram_ptr(prom), entry);
>              env->pc = LEON3_PROM_OFFSET;
>              env->npc = LEON3_PROM_OFFSET + 4;
>              reset_info->entry = LEON3_PROM_OFFSET;
> --

Either way,
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM
Re: [PATCH 2/2] hw/sparc/leon3: Have write_bootloader() take a void pointer argument
Posted by Philippe Mathieu-Daudé 9 months, 2 weeks ago
On 15/2/24 15:13, Peter Maydell wrote:
> On Thu, 15 Feb 2024 at 13:28, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>>
>> Directly use the void pointer argument returned
>> by memory_region_get_ram_ptr().
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>   hw/sparc/leon3.c | 9 +++------
>>   1 file changed, 3 insertions(+), 6 deletions(-)


>> -static void write_bootloader(uint8_t *base, hwaddr kernel_addr)
>> +static void write_bootloader(void *ptr, hwaddr kernel_addr)
>>   {
>> -    uint32_t *p = (uint32_t *) base;
>> +    uint32_t *p = (uint32_t *) ptr;
> 
> I don't think you need the cast any more now ptr is void*.
> (If you do, then our coding style doesn't put a space after
> the cast.)

Right, updated.

> Either way,
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

Thank you!