hw/m68k/mcf5208: add support for reset
PATCH v2 1/1 hw/m68k/mcf5208: add support for reset
Add reset support for mcf5208.
--- hw/m68k/mcf5208.c | 49 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-)
hw/m68k/mcf5208.c +46 -3
@@ -40,6 +40,8 @@#define PCSR_PRE_SHIFT 8#define PCSR_PRE_MASK 0x0f00 +#define RCR_SOFTRST 0x80 + typedef struct { MemoryRegion iomem; qemu_irq irq;
@@ -185,13 +187,54 @@ static const MemoryRegionOps m5208_sys_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static void mcf5208_sys_init (MemoryRegion *address_space,qemu_irq *pic) +static uint64_t m5208_rcm_read (void *opaque,hwaddr addr, +unsigned size) +{ +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIX "\n" , + __func__, addr); +return 0 ; +} + +static void m5208_rcm_write (void *opaque,hwaddr addr, +uint64_t value,unsigned size) +{ +M68kCPU *cpu = opaque; +CPUState *cs =CPU (cpu); +switch (addr) { +case 0x0 :/* RCR */ +if (value &RCR_SOFTRST ) { +cpu_reset (cs); + cpu->env.aregs[7 ] =ldl_phys (cs->as,0 ); + cpu->env.pc =ldl_phys (cs->as,4 ); + } +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIX "\n" , + __func__, addr); +break ; + } +} + +static const MemoryRegionOps m5208_rcm_ops = { + .read = m5208_rcm_read, + .write = m5208_rcm_write, + .endianness =DEVICE_NATIVE_ENDIAN , +}; + +static void mcf5208_sys_init (MemoryRegion *address_space,qemu_irq *pic, +M68kCPU *cpu) { -MemoryRegion *iomem =g_new (MemoryRegion,1 ); +MemoryRegion *iomem;m5208_timer_state *s;int i; +/* RCM */ + iomem =g_new (MemoryRegion,1 ); +memory_region_init_io (iomem,NULL , &m5208_rcm_ops, cpu, +"m5208-rcm" ,0x00000080 ); +memory_region_add_subregion (address_space,0xfc0a0000 , iomem);/* SDRAMC. */ + iomem =g_new (MemoryRegion,1 );memory_region_init_io (iomem,NULL , &m5208_sys_ops,NULL ,"m5208-sys" ,0x00004000 );memory_region_add_subregion (address_space,0xfc0a8000 , iomem);/* Timers. */
@@ -265,7 +308,7 @@ static void mcf5208evb_init(MachineState *machine)mcf_uart_create_mmap (0xfc064000 , pic[27 ],serial_hd (1 ));mcf_uart_create_mmap (0xfc068000 , pic[28 ],serial_hd (2 )); -mcf5208_sys_init (address_space_mem, pic); +mcf5208_sys_init (address_space_mem, pic, cpu);mcf_fec_init (address_space_mem,0xfc030000 , pic +36 );
Signature · 1 line
2.44.0
Am Fri, 8 Mar 2024 10:08:12 +0100
schrieb Angelo Dureghello <[email protected]>:
Quoted 21 lines
Add reset support for mcf5208.
Signed-off-by Angelo Dureghello <[email protected]>--- hw/m68k/mcf5208.c | 49 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-)hw/m68k/mcf5208.c +2
-0@@ -40,6 +40,8 @@#define PCSR_PRE_SHIFT 8#define PCSR_PRE_MASK 0x0f00 +#define RCR_SOFTRST 0x80 + typedef struct { MemoryRegion iomem; qemu_irq irq;
hw/m68k/mcf5208.c static const MemoryRegionOps m5208_sys_ops = { · line 194
Quoted 9 lines
hw/m68k/mcf5208.c +5
-1@@ -185,13 +187,54 @@ static const MemoryRegionOps m5208_sys_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static void mcf5208_sys_init (MemoryRegion *address_space,qemu_irq *pic) +static uint64_t m5208_rcm_read (void *opaque,hwaddr addr, +unsigned size) +{ +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIX "\n" , + __func__, addr);
I'd maybe rather not print this message if the guest tries to read from RCR or RSR - reading back a 0 should be fine here without logging a "bad offset".
Quoted 24 lines
hw/m68k/mcf5208.c +24
-0+return 0 ; +} + +static void m5208_rcm_write (void *opaque,hwaddr addr, +uint64_t value,unsigned size) +{ +M68kCPU *cpu = opaque; +CPUState *cs =CPU (cpu); +switch (addr) { +case 0x0 :/* RCR */ +if (value &RCR_SOFTRST ) { +cpu_reset (cs); + cpu->env.aregs[7 ] =ldl_phys (cs->as,0 ); + cpu->env.pc =ldl_phys (cs->as,4 ); + } +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIX "\n" , + __func__, addr); +break ; + } +} + +static const MemoryRegionOps m5208_rcm_ops = {
hw/m68k/mcf5208.c static const MemoryRegionOps m5208_sys_ops = { · line 227
Quoted 10 lines
hw/m68k/mcf5208.c +8
-1+ .read = m5208_rcm_read, + .write = m5208_rcm_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static void mcf5208_sys_init (MemoryRegion *address_space,qemu_irq *pic, +M68kCPU *cpu) { -MemoryRegion *iomem =g_new (MemoryRegion,1 ); +MemoryRegion *iomem;
I think it's more common coding style in the QEMU sources to have separate variables for separate MemoryRegions instead of re-using one variable for separate MemoryRegions like you do it below. See e.g. microchip_pfsoc_soc_realize() in hw/riscv/microchip_pfsoc.c.
Quoted 14 lines
hw/m68k/mcf5208.c +6
-0m5208_timer_state *s;int i; +/* RCM */ + iomem =g_new (MemoryRegion,1 ); +memory_region_init_io (iomem,NULL , &m5208_rcm_ops, cpu, +"m5208-rcm" ,0x00000080 ); +memory_region_add_subregion (address_space,0xfc0a0000 , iomem);/* SDRAMC. */ + iomem =g_new (MemoryRegion,1 );memory_region_init_io (iomem,NULL , &m5208_sys_ops,NULL ,"m5208-sys" ,0x00004000 );memory_region_add_subregion (address_space,0xfc0a8000 , iomem);/* Timers. */
hw/m68k/mcf5208.c static void mcf5208evb_init(MachineState *machine) · line 313
Quoted 7 lines
hw/m68k/mcf5208.c +1
-1@@ -265,7 +308,7 @@ static void mcf5208evb_init(MachineState *machine)mcf_uart_create_mmap (0xfc064000 , pic[27 ],serial_hd (1 ));mcf_uart_create_mmap (0xfc068000 , pic[28 ],serial_hd (2 )); -mcf5208_sys_init (address_space_mem, pic); +mcf5208_sys_init (address_space_mem, pic, cpu);mcf_fec_init (address_space_mem,0xfc030000 , pic +36 );
All in all, patch looks fine to me ... if you could update the above two nits by Monday, I can try to get this merged before the next soft freeze of QEMU (on Tuesday).
Thanks,
Thomas
Hi Thomas,
Quoted 95 lines · Thomas Huth
Am Fri, 8 Mar 2024 10:08:12 +0100
schrieb Angelo Dureghello <[email protected]>:Quoted 21 lines
Add reset support for mcf5208.
Signed-off-by Angelo Dureghello <[email protected]>--- hw/m68k/mcf5208.c | 49 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-)hw/m68k/mcf5208.c +2
-0@@ -40,6 +40,8 @@#define PCSR_PRE_SHIFT 8#define PCSR_PRE_MASK 0x0f00 +#define RCR_SOFTRST 0x80 + typedef struct { MemoryRegion iomem; qemu_irq irq;hw/m68k/mcf5208.c static const MemoryRegionOps m5208_sys_ops = { · line 194
Quoted 9 lines
hw/m68k/mcf5208.c +5
-1@@ -185,13 +187,54 @@ static const MemoryRegionOps m5208_sys_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static void mcf5208_sys_init (MemoryRegion *address_space,qemu_irq *pic) +static uint64_t m5208_rcm_read (void *opaque,hwaddr addr, +unsigned size) +{ +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIX "\n" , + __func__, addr);I'd maybe rather not print this message if the guest tries to read from RCR or RSR - reading back a 0 should be fine here without logging a "bad offset".
Quoted 24 lines
hw/m68k/mcf5208.c +24
-0+return 0 ; +} + +static void m5208_rcm_write (void *opaque,hwaddr addr, +uint64_t value,unsigned size) +{ +M68kCPU *cpu = opaque; +CPUState *cs =CPU (cpu); +switch (addr) { +case 0x0 :/* RCR */ +if (value &RCR_SOFTRST ) { +cpu_reset (cs); + cpu->env.aregs[7 ] =ldl_phys (cs->as,0 ); + cpu->env.pc =ldl_phys (cs->as,4 ); + } +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIX "\n" , + __func__, addr); +break ; + } +} + +static const MemoryRegionOps m5208_rcm_ops = {hw/m68k/mcf5208.c static const MemoryRegionOps m5208_sys_ops = { · line 227
Quoted 10 lines
hw/m68k/mcf5208.c +8
-1+ .read = m5208_rcm_read, + .write = m5208_rcm_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + +static void mcf5208_sys_init (MemoryRegion *address_space,qemu_irq *pic, +M68kCPU *cpu) { -MemoryRegion *iomem =g_new (MemoryRegion,1 ); +MemoryRegion *iomem;I think it's more common coding style in the QEMU sources to have separate variables for separate MemoryRegions instead of re-using one variable for separate MemoryRegions like you do it below. See e.g.
microchip_pfsoc_soc_realize()inhw/riscv/microchip_pfsoc.c.Quoted 17 lines
hw/m68k/mcf5208.c +6
-0m5208_timer_state *s;int i; +/* RCM */ + iomem =g_new (MemoryRegion,1 ); +memory_region_init_io (iomem,NULL , &m5208_rcm_ops, cpu, +"m5208-rcm" ,0x00000080 ); +memory_region_add_subregion (address_space,0xfc0a0000 , iomem);/* SDRAMC. */ + iomem =g_new (MemoryRegion,1 );memory_region_init_io (iomem,NULL , &m5208_sys_ops,NULL ,"m5208-sys" ,0x00004000 );memory_region_add_subregion (address_space,0xfc0a8000 , iomem);/* Timers. */ @@ -265,7 +308,7 @@ static void mcf5208evb_init(MachineState *machine)mcf_uart_create_mmap (0xfc064000 , pic[27 ],serial_hd (1 ));mcf_uart_create_mmap (0xfc068000 , pic[28 ],serial_hd (2 ));
Quoted 8 lines
hw/m68k/mcf5208.c static void mcf5208evb_init(MachineState *machine) · line 313
Quoted 4 lines
hw/m68k/mcf5208.c +1
-1-mcf5208_sys_init (address_space_mem, pic); +mcf5208_sys_init (address_space_mem, pic, cpu);mcf_fec_init (address_space_mem,0xfc030000 , pic +36 );All in all, patch looks fine to me ... if you could update the above two nits by Monday, I can try to get this merged before the next soft freeze of QEMU (on Tuesday).
thanks a lot, sending v3.
Quoted 3 lines
Thanks,
Thomas
Regards,
angelo