hw/hppa: Clarify machine variables and move them out of CPUArchState
cover hw/hppa: Clarify machine variables and move them out of CPUArchState
The HPPA machines uses a pair of variables for distinct meanings, depending on kernel or firmware mode used. Replace by variables per mode, allowing to use the proper type. This helps reviewing the code. This cleanup allows removing unjustified target_ulong uses.
Philippe Mathieu-Daudé (6):
hw/hppa: Use the machine default boot order at reset hw/hppa: Convert type_init() -> DEFINE_TYPES()
hw/hppa: Factor QOM HPPA_COMMON_MACHINE out
hw/hppa: Introduce HppaMachineState::boot_info::firmware structure hw/hppa: Introduce HppaMachineState::boot_info::kernel structure hw/hppa: Move kernel addresses to HppaMachineState::boot_info
structure
target/hppa/cpu.h | 4 -- hw/hppa/machine.c | 162 +++++++++++++++++++++++++++------------------- 2 files changed, 94 insertions(+), 72 deletions(-)
Signature · 1 line
2.51.0
PATCH 1/6 hw/hppa: Use the machine default boot order at reset
Since new machines might be added with different boot order than 'c', take the machine default one at reset.
--- hw/hppa/machine.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/hppa/machine.c +2 -1
@@ -640,6 +640,7 @@ static void machine_HP_C3700_init(MachineState *machine)static void hppa_machine_reset (MachineState *ms,ResetType type) { +MachineClass *mc =MACHINE_GET_CLASS (ms);unsigned int smp_cpus = ms->smp.cpus;int i;
@@ -671,7 +672,7 @@ static void hppa_machine_reset(MachineState *ms, ResetType type) cpu[0 ]->env.kernel_entry =0 ; cpu[0 ]->env.initrd_base =0 ; cpu[0 ]->env.initrd_end =0 ; - cpu[0 ]->env.cmdline_or_bootorder ='c' ; + cpu[0 ]->env.cmdline_or_bootorder = mc->default_boot_order[0 ]; }static void hppa_nmi (NMIState *n,int cpu_index,Error **errp)
Signature · 1 line
2.51.0
Re: [PATCH 1/6] hw/hppa: Use the machine default boot order at reset
Quoted 21 lines · Philippe Mathieu-Daudé
Since new machines might be added with different boot order than 'c', take the machine default one at reset.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/hppa/machine.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/hppa/machine.c +1
-0@@ -640,6 +640,7 @@ static void machine_HP_C3700_init(MachineState *machine)static void hppa_machine_reset (MachineState *ms,ResetType type) { +MachineClass *mc =MACHINE_GET_CLASS (ms);unsigned int smp_cpus = ms->smp.cpus;int i;
hw/hppa/machine.c static void hppa_machine_reset(MachineState *ms, ResetType type) · line 678
Quoted 8 lines
hw/hppa/machine.c +1
-1@@ -671,7 +672,7 @@ static void hppa_machine_reset(MachineState *ms, ResetType type) cpu[0 ]->env.kernel_entry =0 ; cpu[0 ]->env.initrd_base =0 ; cpu[0 ]->env.initrd_end =0 ; - cpu[0 ]->env.cmdline_or_bootorder ='c' ; + cpu[0 ]->env.cmdline_or_bootorder = mc->default_boot_order[0 ]; }static void hppa_nmi (NMIState *n,int cpu_index,Error **errp)
Is this perhaps trying to reset boot order to 'c' for reboot?
r~
PATCH 2/6 hw/hppa: Convert type_init() -> DEFINE_TYPES()
In reply to Philippe Mathieu-DaudéPrefer DEFINE_TYPES() macro over type_init() to register multiple QOM types.
--- hw/hppa/machine.c | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-)
hw/hppa/machine.c +18 -24
@@ -710,16 +710,6 @@ static void HP_B160L_machine_init_class_init(ObjectClass *oc, const void *data) nc->nmi_monitor_handler = hppa_nmi; } -static const TypeInfo HP_B160L_machine_init_typeinfo = { - .name =MACHINE_TYPE_NAME ("B160L" ), - .parent =TYPE_MACHINE , - .class_init = HP_B160L_machine_init_class_init, - .interfaces = (const InterfaceInfo []) { - {TYPE_NMI }, - { } - }, -}; -static void HP_C3700_machine_init_class_init (ObjectClass *oc,const void *data) {static const char *const valid_cpu_types[] = {
@@ -746,20 +736,24 @@ static void HP_C3700_machine_init_class_init(ObjectClass *oc, const void *data) nc->nmi_monitor_handler = hppa_nmi; } -static const TypeInfo HP_C3700_machine_init_typeinfo = { - .name =MACHINE_TYPE_NAME ("C3700" ), - .parent =TYPE_MACHINE , - .class_init = HP_C3700_machine_init_class_init, - .interfaces = (const InterfaceInfo []) { - {TYPE_NMI }, - { } +static const TypeInfo hppa_machine_types[] = { + { + .name =MACHINE_TYPE_NAME ("B160L" ), + .parent =TYPE_MACHINE , + .class_init = HP_B160L_machine_init_class_init, + .interfaces = (const InterfaceInfo []) { + {TYPE_NMI }, + { } + }, + }, { + .name =MACHINE_TYPE_NAME ("C3700" ), + .parent =TYPE_MACHINE , + .class_init = HP_C3700_machine_init_class_init, + .interfaces = (const InterfaceInfo []) { + {TYPE_NMI }, + { } + }, }, }; -static void hppa_machine_init_register_types (void ) -{ -type_register_static (&HP_B160L_machine_init_typeinfo); -type_register_static (&HP_C3700_machine_init_typeinfo); -} - -type_init (hppa_machine_init_register_types) +DEFINE_TYPES (hppa_machine_types)
Signature · 1 line
2.51.0
Re: [PATCH 2/6] hw/hppa: Convert type_init() -> DEFINE_TYPES()
Quoted 7 lines · Philippe Mathieu-Daudé
Prefer
DEFINE_TYPES()macro overtype_init()to register multiple QOM types.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/hppa/machine.c | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-)
r~
PATCH 3/6 hw/hppa: Factor QOM HPPA_COMMON_MACHINE out
In reply to Philippe Mathieu-DaudéB160L and C3700 share a lot of common code. Factor it out as an abstract HPPA_COMMON_MACHINE QOM parent.
--- hw/hppa/machine.c | 61 +++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 28 deletions(-)
hw/hppa/machine.c +33 -28
@@ -36,6 +36,13 @@#include "net/net.h" #include "qemu/log.h" +#define TYPE_HPPA_COMMON_MACHINE MACHINE_TYPE_NAME("hppa-common") +OBJECT_DECLARE_SIMPLE_TYPE(HppaMachineState, HPPA_COMMON_MACHINE) + +struct HppaMachineState { +MachineState parent_obj; +}; +#define MIN_SEABIOS_HPPA_VERSION 12/* require at least this fw version */ #define HPA_POWER_BUTTON (FIRMWARE_END - 0x10)
@@ -684,6 +691,22 @@ static void hppa_nmi(NMIState *n, int cpu_index, Error **errp) } } +static void hppa_machine_common_class_init (ObjectClass *oc,const void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +NMIClass *nc =NMI_CLASS (oc); + + mc->reset = hppa_machine_reset; + mc->block_default_type =IF_SCSI ; + mc->default_cpus =1 ; + mc->max_cpus =HPPA_MAX_CPUS ; + mc->default_boot_order ="cd" ; + mc->default_ram_id ="ram" ; + mc->default_nic ="tulip" ; + + nc->nmi_monitor_handler = hppa_nmi; +} +static void HP_B160L_machine_init_class_init (ObjectClass *oc,const void *data) {static const char *const valid_cpu_types[] = {
@@ -691,23 +714,13 @@ static void HP_B160L_machine_init_class_init(ObjectClass *oc, const void *data) NULL };MachineClass *mc =MACHINE_CLASS (oc); -NMIClass *nc =NMI_CLASS (oc); mc->desc ="HP B160L workstation" ; mc->default_cpu_type =TYPE_HPPA_CPU ; mc->valid_cpu_types = valid_cpu_types; mc->init = machine_HP_B160L_init; - mc->reset = hppa_machine_reset; - mc->block_default_type =IF_SCSI ; - mc->max_cpus =HPPA_MAX_CPUS ; - mc->default_cpus =1 ; mc->is_default = true; mc->default_ram_size =512 * MiB; - mc->default_boot_order ="cd" ; - mc->default_ram_id ="ram" ; - mc->default_nic ="tulip" ; - - nc->nmi_monitor_handler = hppa_nmi; }static void HP_C3700_machine_init_class_init (ObjectClass *oc,const void *data)
@@ -717,42 +730,34 @@ static void HP_C3700_machine_init_class_init(ObjectClass *oc, const void *data) NULL };MachineClass *mc =MACHINE_CLASS (oc); -NMIClass *nc =NMI_CLASS (oc); mc->desc ="HP C3700 workstation" ; mc->default_cpu_type =TYPE_HPPA64_CPU ; mc->valid_cpu_types = valid_cpu_types; mc->init = machine_HP_C3700_init; - mc->reset = hppa_machine_reset; - mc->block_default_type =IF_SCSI ; mc->max_cpus =HPPA_MAX_CPUS ; - mc->default_cpus =1 ; - mc->is_default = false; mc->default_ram_size =1024 * MiB; - mc->default_boot_order ="cd" ; - mc->default_ram_id ="ram" ; - mc->default_nic ="tulip" ; - - nc->nmi_monitor_handler = hppa_nmi; }static const TypeInfo hppa_machine_types[] = { { - .name =MACHINE_TYPE_NAME ("B160L" ), - .parent =TYPE_MACHINE , - .class_init = HP_B160L_machine_init_class_init, + .name =TYPE_HPPA_COMMON_MACHINE , + .parent =TYPE_MACHINE , + .instance_size =sizeof (HppaMachineState), + .class_init = hppa_machine_common_class_init, + .abstract = true, .interfaces = (const InterfaceInfo []) { {TYPE_NMI }, { } }, + }, { + .name =MACHINE_TYPE_NAME ("B160L" ), + .parent =TYPE_HPPA_COMMON_MACHINE , + .class_init = HP_B160L_machine_init_class_init, }, { .name =MACHINE_TYPE_NAME ("C3700" ), - .parent =TYPE_MACHINE , + .parent =TYPE_HPPA_COMMON_MACHINE , .class_init = HP_C3700_machine_init_class_init, - .interfaces = (const InterfaceInfo []) { - {TYPE_NMI }, - { } - }, }, };
Signature · 1 line
2.51.0
Re: [PATCH 3/6] hw/hppa: Factor QOM HPPA_COMMON_MACHINE out
Quoted 7 lines · Philippe Mathieu-Daudé
B160L and C3700 share a lot of common code. Factor it out as an abstract
HPPA_COMMON_MACHINEQOM parent.Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/hppa/machine.c | 61 +++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 28 deletions(-)
r~
PATCH 4/6 hw/hppa: Introduce HppaMachineState::boot_info::firmware structure
In reply to Philippe Mathieu-DaudéCurrent code uses CPUHPPAState::@kernel_entry to hold either:
- kernel entry virtual address
- firmware interactive mode
and CPUHPPAState::@cmdline_or_bootorder to hold either:
- kernel &cmdline physical address
- firmware boot order
Besides, these variables don't belong to CPUHPPAState, they depend on how the machine is started, and only apply to the first CPU.
Introduce firmware specific fields in HppaMachineState, using their correct type. Introduce the @is_kernel field, to allow distinguishing between firmware or kernel mode.
--- hw/hppa/machine.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-)
hw/hppa/machine.c +28 -8
@@ -41,6 +41,16 @@ OBJECT_DECLARE_SIMPLE_TYPE(HppaMachineState, HPPA_COMMON_MACHINE)struct HppaMachineState {MachineState parent_obj; + +struct { +bool is_kernel;/* kernel:1 firmware:0 */ +union { +struct { +char bootorder; +bool interactive_mode; + } firmware; + }; + } boot_info; };#define MIN_SEABIOS_HPPA_VERSION 12/* require at least this fw version */
@@ -356,6 +366,7 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,const char *initrd_filename = machine->initrd_filename;const char *firmware = machine->firmware;MachineClass *mc =MACHINE_GET_CLASS (machine); +HppaMachineState *hms =HPPA_COMMON_MACHINE (machine);DeviceState *dev;PCIDevice *pci_dev;char *firmware_filename;
@@ -481,6 +492,7 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,"-0x%08" PRIx64", entry at 0x%08" PRIx64", size %" PRIu64" kB\n" , kernel_low, kernel_high, kernel_entry, size / KiB); + hms->boot_info.is_kernel = true;if (kernel_cmdline) { cpu[0 ]->env.cmdline_or_bootorder =0x4000 ;
@@ -519,13 +531,15 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus, } } -if (!kernel_entry) { +if (!hms->boot_info.is_kernel) {/* When booting via firmware, tell firmware if we want interactive -* mode (kernel_entry=1), and to boot from CD (cmdline_or_bootorder='d') -* or hard disc (cmdline_or_bootorder='c'). +* mode (interactive_mode=1), and to boot from CD (bootorder='d') +* or hard disc (bootorder='c'). */ - kernel_entry = machine->boot_config.has_menu ? machine->boot_config.menu :0 ; - cpu[0 ]->env.cmdline_or_bootorder = machine->boot_config.order[0 ]; + hms->boot_info.firmware.interactive_mode = machine->boot_config.has_menu + ? machine->boot_config.menu + :0 ; + hms->boot_info.firmware.bootorder = machine->boot_config.order[0 ]; }/* Keep initial kernel_entry for first boot */
@@ -648,6 +662,7 @@ static void machine_HP_C3700_init(MachineState *machine)static void hppa_machine_reset (MachineState *ms,ResetType type) {MachineClass *mc =MACHINE_GET_CLASS (ms); +HppaMachineState *hms =HPPA_COMMON_MACHINE (ms);unsigned int smp_cpus = ms->smp.cpus;int i;
@@ -668,8 +683,12 @@ static void hppa_machine_reset(MachineState *ms, ResetType type) } cpu[0 ]->env.gr[26 ] = ms->ram_size; - cpu[0 ]->env.gr[25 ] = cpu[0 ]->env.kernel_entry; - cpu[0 ]->env.gr[24 ] = cpu[0 ]->env.cmdline_or_bootorder; + cpu[0 ]->env.gr[25 ] = hms->boot_info.is_kernel + ? cpu[0 ]->env.kernel_entry + : hms->boot_info.firmware.interactive_mode; + cpu[0 ]->env.gr[24 ] = hms->boot_info.is_kernel + ? cpu[0 ]->env.cmdline_or_bootorder + : hms->boot_info.firmware.bootorder; cpu[0 ]->env.gr[23 ] = cpu[0 ]->env.initrd_base; cpu[0 ]->env.gr[22 ] = cpu[0 ]->env.initrd_end; cpu[0 ]->env.gr[21 ] = smp_cpus;
@@ -679,7 +698,8 @@ static void hppa_machine_reset(MachineState *ms, ResetType type) cpu[0 ]->env.kernel_entry =0 ; cpu[0 ]->env.initrd_base =0 ; cpu[0 ]->env.initrd_end =0 ; - cpu[0 ]->env.cmdline_or_bootorder = mc->default_boot_order[0 ]; + cpu[0 ]->env.cmdline_or_bootorder =0 ; + hms->boot_info.firmware.bootorder = mc->default_boot_order[0 ]; }static void hppa_nmi (NMIState *n,int cpu_index,Error **errp)
Signature · 1 line
2.51.0
Re: [PATCH 4/6] hw/hppa: Introduce HppaMachineState::boot_info::firmware structure
Quoted 28 lines · Philippe Mathieu-Daudé
Current code uses CPUHPPAState::@kernel_entry to hold either:
- kernel entry virtual address
- firmware interactive mode
and CPUHPPAState::@cmdline_or_bootorder to hold either:
- kernel &cmdline physical address
- firmware boot orderBesides, these variables don't belong to CPUHPPAState, they depend on how the machine is started, and only apply to the first CPU.
Introduce firmware specific fields in HppaMachineState, using their correct type. Introduce the @is_kernel field, to allow distinguishing between firmware or kernel mode.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/hppa/machine.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-)hw/hppa/machine.c +0
-0@@ -41,6 +41,16 @@ OBJECT_DECLARE_SIMPLE_TYPE(HppaMachineState, HPPA_COMMON_MACHINE)struct HppaMachineState {MachineState parent_obj;
hw/hppa/machine.c OBJECT_DECLARE_SIMPLE_TYPE(HppaMachineState, HPPA_COMMON_MACHINE) · line 53
Quoted 10 lines
hw/hppa/machine.c +10
-0+ +struct { +bool is_kernel;/* kernel:1 firmware:0 */ +union { +struct { +char bootorder; +bool interactive_mode; + } firmware; + }; + } boot_info;
I think this is more complicated than necessary.
Quoted 26 lines
hw/hppa/machine.c +8
-5@@ -481,6 +492,7 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,"-0x%08" PRIx64", entry at 0x%08" PRIx64", size %" PRIu64" kB\n" , kernel_low, kernel_high, kernel_entry, size / KiB); + hms->boot_info.is_kernel = true;if (kernel_cmdline) { cpu[0 ]->env.cmdline_or_bootorder =0x4000 ;@@ -519,13 +531,15 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus, } } -if (!kernel_entry) { +if (!hms->boot_info.is_kernel) {/* When booting via firmware, tell firmware if we want interactive -* mode (kernel_entry=1), and to boot from CD (cmdline_or_bootorder='d') -* or hard disc (cmdline_or_bootorder='c'). +* mode (interactive_mode=1), and to boot from CD (bootorder='d') +* or hard disc (bootorder='c'). */ - kernel_entry = machine->boot_config.has_menu ? machine->boot_config.menu :0 ; - cpu[0 ]->env.cmdline_or_bootorder = machine->boot_config.order[0 ]; + hms->boot_info.firmware.interactive_mode = machine->boot_config.has_menu + ? machine->boot_config.menu + :0 ; + hms->boot_info.firmware.bootorder = machine->boot_config.order[0 ];
...
hw/hppa/machine.c static void hppa_machine_reset(MachineState *ms, ResetType type) · line 691
Quoted 12 lines
hw/hppa/machine.c +6
-2@@ -668,8 +683,12 @@ static void hppa_machine_reset(MachineState *ms, ResetType type) } cpu[0 ]->env.gr[26 ] = ms->ram_size; - cpu[0 ]->env.gr[25 ] = cpu[0 ]->env.kernel_entry; - cpu[0 ]->env.gr[24 ] = cpu[0 ]->env.cmdline_or_bootorder; + cpu[0 ]->env.gr[25 ] = hms->boot_info.is_kernel + ? cpu[0 ]->env.kernel_entry + : hms->boot_info.firmware.interactive_mode; + cpu[0 ]->env.gr[24 ] = hms->boot_info.is_kernel + ? cpu[0 ]->env.cmdline_or_bootorder + : hms->boot_info.firmware.bootorder;
I think you'd be better served by placing
uint64_t boot_gr24;
uint64_t boot_gr25;in HppaMachineState and set them in machine_HP_common_init_tail.
hw/hppa/machine.c static void hppa_machine_reset(MachineState *ms, ResetType type) · line 702
Quoted 7 lines
hw/hppa/machine.c +2
-1@@ -679,7 +698,8 @@ static void hppa_machine_reset(MachineState *ms, ResetType type) cpu[0 ]->env.kernel_entry =0 ; cpu[0 ]->env.initrd_base =0 ; cpu[0 ]->env.initrd_end =0 ; - cpu[0 ]->env.cmdline_or_bootorder = mc->default_boot_order[0 ]; + cpu[0 ]->env.cmdline_or_bootorder =0 ; + hms->boot_info.firmware.bootorder = mc->default_boot_order[0 ];
Setting hms in reset seems wrong.
r~
Re: [PATCH 4/6] hw/hppa: Introduce HppaMachineState::boot_info::firmware structure
Quoted 33 lines · Richard Henderson
Quoted 32 lines · Philippe Mathieu-Daudé
Current code uses CPUHPPAState::@kernel_entry to hold either:
- kernel entry virtual address
- firmware interactive mode
and CPUHPPAState::@cmdline_or_bootorder to hold either:
- kernel &cmdline physical address
- firmware boot orderBesides, these variables don't belong to CPUHPPAState, they depend on how the machine is started, and only apply to the first CPU.
Introduce firmware specific fields in HppaMachineState, using their correct type. Introduce the @is_kernel field, to allow distinguishing between firmware or kernel mode.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/hppa/machine.c| 36 ++++++++++++++++++++++++++++--------1 file changed, 28 insertions(+), 8 deletions(-)hw/hppa/machine.c +4
-0@@ -41,6 +41,16 @@ OBJECT_DECLARE_SIMPLE_TYPE(HppaMachineState, HPPA_COMMON_MACHINE) struct HppaMachineState { MachineState parent_obj; + + struct { + bool is_kernel; /* kernel:1 firmware:0 */ + union {
Quoted 8 lines
hw/hppa/machine.c OBJECT_DECLARE_SIMPLE_TYPE(HppaMachineState, HPPA_COMMON_MACHINE) · line 53
Quoted 6 lines
hw/hppa/machine.c +6
-0+ struct { + char bootorder; + bool interactive_mode; + } firmware; + }; + } boot_info;I think this is more complicated than necessary.
Certainly...
Quoted 50 lines
Quoted 33 lines
hw/hppa/machine.c +0
-0@@ -481,6 +492,7 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,"-0x%08" PRIx64 ", entry at 0x%08" PRIx64 ", size %" PRIu64 " kB\n",
kernel_low,kernel_high,kernel_entry, size / KiB); +hms->boot_info.is_kernel= true;
if (kernel_cmdline) { cpu[0]->env.cmdline_or_bootorder =0x4000;hw/hppa/machine.c +3
-5@@ -519,13 +531,15 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus, } } - if (!kernel_entry) { + if (!hms->boot_info.is_kernel) { /* When booting via firmware, tell firmware if we want interactive - * mode (kernel_entry=1), and to boot from CD (cmdline_or_bootorder='d') - * or hard disc (cmdline_or_bootorder='c'). + * mode (interactive_mode=1), and to boot from CD (bootorder='d') + * or hard disc (bootorder='c'). */ - kernel_entry = machine->boot_config.has_menu ? machine- >boot_config.menu : 0; - cpu[0]->env.cmdline_or_bootorder = machine-Quoted 1 line
boot_config.order[0];
+
hms->boot_info.firmware.interactive_mode= machine-Quoted 1 line
boot_config.has_menu
+ ? machine-
Quoted 1 line
boot_config.menu
+ : 0; +
hms->boot_info.firmware.bootorder= machine-Quoted 1 line
boot_config.order[0];
...
hw/hppa/machine.c static void hppa_machine_reset(MachineState *ms, · line 691
Quoted 12 lines
hw/hppa/machine.c +6
-2@@ -668,8 +683,12 @@ static void hppa_machine_reset(MachineState *ms, ResetType type) } cpu[0]->env.gr[26] = ms->ram_size; - cpu[0]->env.gr[25] = cpu[0]->env.kernel_entry; - cpu[0]->env.gr[24] = cpu[0]->env.cmdline_or_bootorder; + cpu[0]->env.gr[25] = hms->boot_info.is_kernel + ? cpu[0]->env.kernel_entry + : hms->boot_info.firmware.interactive_mode; + cpu[0]->env.gr[24] = hms->boot_info.is_kernel + ? cpu[0]->env.cmdline_or_bootorder + : hms->boot_info.firmware.bootorder;I think you'd be better served by placing
Quoted 2 lines
uint64_tboot_gr24;
uint64_tboot_gr25;
Clever :)
Quoted 12 lines
in HppaMachineState and set them in
machine_HP_common_init_tail.hw/hppa/machine.c static void hppa_machine_reset(MachineState *ms, · line 703
Quoted 8 lines
hw/hppa/machine.c +2
-1@@ -679,7 +698,8 @@ static void hppa_machine_reset(MachineState *ms, ResetType type) cpu[0]->env.kernel_entry = 0; cpu[0]->env.initrd_base = 0; cpu[0]->env.initrd_end = 0; - cpu[0]->env.cmdline_or_bootorder = mc->default_boot_order[0]; + cpu[0]->env.cmdline_or_bootorder = 0; + hms->boot_info.firmware.bootorder = mc->default_boot_order[0];Setting hms in reset seems wrong.
Yes, a pre-existing issue. I couldn't figure that piece of code (and comment) myself.
PATCH 5/6 hw/hppa: Introduce HppaMachineState::boot_info::kernel structure
In reply to Philippe Mathieu-DaudéCPUHPPAState::@cmdline_or_bootorder is now only used in kernel mode. Move it to HppaMachineState::kernel, and use the 'hwaddr' type.
--- target/hppa/cpu.h | 1 - hw/hppa/machine.c | 11 +++++++---- 2 files changed, 7 insertions(+), 5 deletions(-)
target/hppa/cpu.h +0 -1
@@ -273,7 +273,6 @@ typedef struct CPUArchState {bool is_pa20;target_ulong kernel_entry;/* Linux kernel was loaded here */ -target_ulong cmdline_or_bootorder;target_ulong initrd_base, initrd_end; } CPUHPPAState;
hw/hppa/machine.c +7 -4
@@ -49,6 +49,9 @@ struct HppaMachineState {char bootorder;bool interactive_mode; } firmware; +struct { +hwaddr cmdline_paddr; + } kernel; }; } boot_info; };
@@ -495,8 +498,8 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus, hms->boot_info.is_kernel = true;if (kernel_cmdline) { - cpu[0 ]->env.cmdline_or_bootorder =0x4000 ; -pstrcpy_targphys ("cmdline" , cpu[0 ]->env.cmdline_or_bootorder, + hms->boot_info.kernel.cmdline_paddr =0x4000 ; +pstrcpy_targphys ("cmdline" , hms->boot_info.kernel.cmdline_paddr,TARGET_PAGE_SIZE , kernel_cmdline); }
@@ -687,7 +690,7 @@ static void hppa_machine_reset(MachineState *ms, ResetType type) ? cpu[0 ]->env.kernel_entry : hms->boot_info.firmware.interactive_mode; cpu[0 ]->env.gr[24 ] = hms->boot_info.is_kernel - ? cpu[0 ]->env.cmdline_or_bootorder + ? hms->boot_info.kernel.cmdline_paddr : hms->boot_info.firmware.bootorder; cpu[0 ]->env.gr[23 ] = cpu[0 ]->env.initrd_base; cpu[0 ]->env.gr[22 ] = cpu[0 ]->env.initrd_end;
@@ -698,7 +701,7 @@ static void hppa_machine_reset(MachineState *ms, ResetType type) cpu[0 ]->env.kernel_entry =0 ; cpu[0 ]->env.initrd_base =0 ; cpu[0 ]->env.initrd_end =0 ; - cpu[0 ]->env.cmdline_or_bootorder =0 ; + hms->boot_info.kernel.cmdline_paddr =0 ; hms->boot_info.firmware.bootorder = mc->default_boot_order[0 ]; }
Signature · 1 line
2.51.0
PATCH 6/6 hw/hppa: Move kernel addresses to HppaMachineState::boot_info structure
In reply to Philippe Mathieu-DaudéRestrict kernel* related variables scope, move fields that don't belong to CPUHPPAState to HppaMachineState::boot_info::kernel. Replace target_ulong -> vaddr type for virtual addresses.
--- target/hppa/cpu.h | 3 --- hw/hppa/machine.c | 31 +++++++++++++++++-------------- 2 files changed, 17 insertions(+), 17 deletions(-)
target/hppa/cpu.h +0 -3
@@ -271,9 +271,6 @@ typedef struct CPUArchState {struct {} end_reset_fields;bool is_pa20; - -target_ulong kernel_entry;/* Linux kernel was loaded here */ -target_ulong initrd_base, initrd_end; } CPUHPPAState;/**
hw/hppa/machine.c +17 -14
@@ -50,6 +50,8 @@ struct HppaMachineState {bool interactive_mode; } firmware;struct { +vaddr entry;/* Linux kernel was loaded here */ +vaddr initrd_base, initrd_end;hwaddr cmdline_paddr; } kernel; };
@@ -365,8 +367,6 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus, TranslateFn *translate) {const char *kernel_filename = machine->kernel_filename; -const char *kernel_cmdline = machine->kernel_cmdline; -const char *initrd_filename = machine->initrd_filename;const char *firmware = machine->firmware;MachineClass *mc =MACHINE_GET_CLASS (machine);HppaMachineState *hms =HPPA_COMMON_MACHINE (machine);
@@ -375,7 +375,6 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,char *firmware_filename;uint64_t firmware_low, firmware_high;long size; -uint64_t kernel_entry =0 , kernel_low, kernel_high;MemoryRegion *addr_space =get_system_memory ();MemoryRegion *rom_region;SysBusDevice *s;
@@ -481,6 +480,11 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,/* Load kernel */ if (kernel_filename) { +uint64_t kernel_entry; +uint64_t kernel_low, kernel_high; +const char *kernel_cmdline = machine->kernel_cmdline; +const char *initrd_filename = machine->initrd_filename; + size =load_elf (kernel_filename,NULL , linux_kernel_virt_to_phys,NULL , &kernel_entry, &kernel_low, &kernel_high,NULL ,ELFDATA2MSB ,EM_PARISC ,0 ,0 );
@@ -496,6 +500,8 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,", size %" PRIu64" kB\n" , kernel_low, kernel_high, kernel_entry, size / KiB); hms->boot_info.is_kernel = true; +/* Keep initial kernel_entry for first boot */ + hms->boot_info.kernel.entry = kernel_entry;if (kernel_cmdline) { hms->boot_info.kernel.cmdline_paddr =0x4000 ;
@@ -529,8 +535,8 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus, }load_image_targphys (initrd_filename, initrd_base, initrd_size); - cpu[0 ]->env.initrd_base = initrd_base; - cpu[0 ]->env.initrd_end = initrd_base + initrd_size; + hms->boot_info.kernel.initrd_base = initrd_base; + hms->boot_info.kernel.initrd_end = initrd_base + initrd_size; } }
@@ -544,9 +550,6 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus, : 0; hms->boot_info.firmware.bootorder = machine->boot_config.order[0 ]; } - -/* Keep initial kernel_entry for first boot */ - cpu[0 ]->env.kernel_entry = kernel_entry; }/*
@@ -687,20 +690,20 @@ static void hppa_machine_reset(MachineState *ms, ResetType type) cpu[0 ]->env.gr[26 ] = ms->ram_size; cpu[0 ]->env.gr[25 ] = hms->boot_info.is_kernel - ? cpu[0 ]->env.kernel_entry + ? hms->boot_info.kernel.entry : hms->boot_info.firmware.interactive_mode; cpu[0 ]->env.gr[24 ] = hms->boot_info.is_kernel ? hms->boot_info.kernel.cmdline_paddr : hms->boot_info.firmware.bootorder; - cpu[0 ]->env.gr[23 ] = cpu[0 ]->env.initrd_base; - cpu[0 ]->env.gr[22 ] = cpu[0 ]->env.initrd_end; + cpu[0 ]->env.gr[23 ] = hms->boot_info.kernel.initrd_base; + cpu[0 ]->env.gr[22 ] = hms->boot_info.kernel.initrd_end; cpu[0 ]->env.gr[21 ] = smp_cpus; cpu[0 ]->env.gr[19 ] =FW_CFG_IO_BASE ;/* reset static fields to avoid starting Linux kernel & initrd on reboot */ - cpu[0 ]->env.kernel_entry =0 ; - cpu[0 ]->env.initrd_base =0 ; - cpu[0 ]->env.initrd_end =0 ; + hms->boot_info.kernel.entry =0 ; + hms->boot_info.kernel.initrd_base =0 ; + hms->boot_info.kernel.initrd_end =0 ; hms->boot_info.kernel.cmdline_paddr =0 ; hms->boot_info.firmware.bootorder = mc->default_boot_order[0 ]; }
Signature · 1 line
2.51.0