Proposal: option for CPU selection
Here's a patch that allow the user to specify a specific CPU model/variant on the command line.
This makes different CPU tests less painfull, as the current code need a recompilation for this.
This patch only has an actual effect when using the PowerPC target, as I don't want to break other targets, but would be imho easy to implement for all targets.
It just adds a -C <cpu_model> facultative option to the command line and a new parameter to the machine->init callback. A machine can then ignore this parameter or tune the emulated CPU based on the given CPU model.
Any comments will be welcome but I'd like to insist that such an option would really be useful, at least for testing purposes.
Signature · 2 lines
J. Mayer <[email protected]> Never organized
Index: vl.c
===================================================================
RCS file: /sources/qemu/qemu/vl.c,v
retrieving revision 1.259
vl.c +17 -1
@@ -6339,6 +6339,7 @@ void help(void)"\n" "Standard options:\n" "-M machine select emulated machine (-M ? for list)\n" +"-C cpu select CPU (-C ? for list)\n" "-fda/-fdb file use 'file' as floppy disk 0/1 image\n" "-hda/-hdb file use 'file' as IDE hard disk 0/1 image\n" "-hdc/-hdd file use 'file' as IDE hard disk 2/3 image\n"
@@ -6471,6 +6472,7 @@ enum { QEMU_OPTION_h,QEMU_OPTION_M , +QEMU_OPTION_C , QEMU_OPTION_fda, QEMU_OPTION_fdb, QEMU_OPTION_hda,
@@ -6546,6 +6548,7 @@ const QEMUOption qemu_options[] = { { "help", 0, QEMU_OPTION_h }, { "M", HAS_ARG, QEMU_OPTION_M }, + { "C", HAS_ARG, QEMU_OPTION_C }, { "fda", HAS_ARG, QEMU_OPTION_fda }, { "fdb", HAS_ARG, QEMU_OPTION_fdb }, { "hda", HAS_ARG, QEMU_OPTION_hda },
@@ -6851,6 +6854,7 @@ int main(int argc, char **argv)int parallel_device_index;const char *loadvm =NULL ;QEMUMachine *machine; +const char *cpu_model;char usb_devices[MAX_USB_CMDLINE ][128 ];int usb_devices_index;int fds[2 ];
@@ -6888,6 +6892,7 @@ int main(int argc, char **argv)register_machines (); machine = first_machine; + cpu_model =NULL ; initrd_filename =NULL ;for (i =0 ; i <MAX_FD ; i++) fd_filename[i] =NULL ;
@@ -6979,6 +6984,17 @@ int main(int argc, char **argv)exit (1 ); }break ; +case QEMU_OPTION_C : +/* hw initialization will check this */ +if (optarg[0 ] =='?' ) { +#if defined(TARGET_PPC ) || defined(TARGET_PPC64 ) +ppc_cpu_list (stdout, &fprintf); +#endif +exit (1 ); + }else { + cpu_model = optarg; + } +break ;case QEMU_OPTION_initrd: initrd_filename = optarg;break ;
@@ -7553,7 +7569,7 @@ int main(int argc, char **argv) machine->init (ram_size, vga_ram_size, boot_device, ds, fd_filename, snapshot, - kernel_filename, kernel_cmdline, initrd_filename); + kernel_filename, kernel_cmdline, initrd_filename, cpu_model);/* init USB devices */ if (usb_enabled) {
Index: vl.h
===================================================================
RCS file: /sources/qemu/qemu/vl.h,v
retrieving revision 1.189
vl.h +5 -1
@@ -695,7 +695,7 @@ typedef void QEMUMachineInitFunc(int ramint boot_device, DisplayState *ds, const char **fd_filename, int snapshot, const char *kernel_filename, const char *kernel_cmdline, - const char *initrd_filename); + const char *initrd_filename, const char *cpu_model); typedef struct QEMUMachine { const char *name;
@@ -709,6 +709,10 @@ int qemu_register_machine(QEMUMachine *mtypedef void SetIRQFunc (void *opaque,int irq_num,int level);typedef void IRQRequestFunc (void *opaque,int level); +#if defined(TARGET_PPC ) || defined(TARGET_PPC64 ) +void ppc_cpu_list (FILE *f,int (*cpu_fprintf)(FILE *f,const char *fmt, ...)); +#endif +/* ISA bus */ extern target_phys_addr_t isa_mem_base;
Index: hw/integratorcp.c
===================================================================
RCS file: /sources/qemu/qemu/hw/integratorcp.c,v
retrieving revision 1.11
integratorcp.c +2 -2
@@ -516,7 +516,7 @@ static void integratorcp_init(int ram_sistatic void integratorcp926_init (int ram_size,int vga_ram_size,int boot_device,DisplayState *ds,const char **fd_filename,int snapshot,const char *kernel_filename,const char *kernel_cmdline, -const char *initrd_filename) +const char *initrd_filename,const char *cpu_model) { integratorcp_init(ram_size, vga_ram_size, boot_device, ds, fd_filename, snapshot, kernel_filename, kernel_cmdline,
@@ -526,7 +526,7 @@ static void integratorcp926_init(int ramstatic void integratorcp1026_init (int ram_size,int vga_ram_size,int boot_device,DisplayState *ds,const char **fd_filename,int snapshot,const char *kernel_filename,const char *kernel_cmdline, -const char *initrd_filename) +const char *initrd_filename,const char *cpu_model) { integratorcp_init(ram_size, vga_ram_size, boot_device, ds, fd_filename, snapshot, kernel_filename, kernel_cmdline,
Index: hw/mips_malta.c
===================================================================
RCS file: /sources/qemu/qemu/hw/mips_malta.c,v
retrieving revision 1.12
mips_malta.c +1 -1
@@ -494,7 +494,7 @@ staticvoid mips_malta_init (int ram_size,int vga_ram_size,int boot_device,DisplayState *ds,const char **fd_filename,int snapshot,const char *kernel_filename,const char *kernel_cmdline, -const char *initrd_filename) +const char *initrd_filename,const char *cpu_model) {char buf[1024 ];unsigned long bios_offset;
Index: hw/mips_r4k.c
===================================================================
RCS file: /sources/qemu/qemu/hw/mips_r4k.c,v
retrieving revision 1.35
mips_r4k.c +1 -1
@@ -130,7 +130,7 @@ staticvoid mips_r4k_init (int ram_size,int vga_ram_size,int boot_device,DisplayState *ds,const char **fd_filename,int snapshot,const char *kernel_filename,const char *kernel_cmdline, -const char *initrd_filename) +const char *initrd_filename,const char *cpu_model) {char buf[1024 ];unsigned long bios_offset;
Index: hw/pc.c
===================================================================
RCS file: /sources/qemu/qemu/hw/pc.c,v
retrieving revision 1.70
pc.c +4 -2
@@ -758,7 +758,8 @@ static void pc_init_pci(int ram_size, in int snapshot, const char *kernel_filename, const char *kernel_cmdline, - const char *initrd_filename) + const char *initrd_filename, + const char *cpu_model) { pc_init1(ram_size, vga_ram_size, boot_device, ds, fd_filename, snapshot,
@@ -771,7 +772,8 @@ static void pc_init_isa(int ram_size, in int snapshot, const char *kernel_filename, const char *kernel_cmdline, - const char *initrd_filename) + const char *initrd_filename, + const char *cpu_model) { pc_init1(ram_size, vga_ram_size, boot_device, ds, fd_filename, snapshot,
Index: hw/realview.c
===================================================================
RCS file: /sources/qemu/qemu/hw/realview.c,v
retrieving revision 1.3
realview.c +1 -1
@@ -15,7 +15,7 @@static void realview_init (int ram_size,int vga_ram_size,int boot_device,DisplayState *ds,const char **fd_filename,int snapshot,const char *kernel_filename,const char *kernel_cmdline, -const char *initrd_filename) +const char *initrd_filename,const char *cpu_model) {CPUState *env;void *pic;
Index: hw/shix.c
===================================================================
RCS file: /sources/qemu/qemu/hw/shix.c,v
retrieving revision 1.1
shix.c +1 -1
@@ -70,7 +70,7 @@ void vga_screen_dump(const char *filenamvoid shix_init (int ram_size,int vga_ram_size,int boot_device,DisplayState * ds,const char **fd_filename,int snapshot,const char *kernel_filename,const char *kernel_cmdline, -const char *initrd_filename) +const char *initrd_filename,const char *cpu_model) {int ret;CPUState *env;
Index: hw/sun4m.c
===================================================================
RCS file: /sources/qemu/qemu/hw/sun4m.c,v
retrieving revision 1.24
sun4m.c +1 -1
@@ -211,7 +211,7 @@ static void main_cpu_reset(void *opaque)static void sun4m_init (int ram_size,int vga_ram_size,int boot_device,DisplayState *ds,const char **fd_filename,int snapshot,const char *kernel_filename,const char *kernel_cmdline, -const char *initrd_filename) +const char *initrd_filename,const char *cpu_model) {CPUState *env, *envs[MAX_CPUS ];char buf[1024 ];
Index: hw/sun4u.c
===================================================================
RCS file: /sources/qemu/qemu/hw/sun4u.c,v
retrieving revision 1.12
sun4u.c +1 -1
@@ -257,7 +257,7 @@ static fdctrl_t *floppy_controller;static void sun4u_init (int ram_size,int vga_ram_size,int boot_device,DisplayState *ds,const char **fd_filename,int snapshot,const char *kernel_filename,const char *kernel_cmdline, -const char *initrd_filename) +const char *initrd_filename,const char *cpu_model) {CPUState *env;char buf[1024 ];
Index: hw/versatilepb.c
===================================================================
RCS file: /sources/qemu/qemu/hw/versatilepb.c,v
retrieving revision 1.8
versatilepb.c +2 -2
@@ -257,7 +257,7 @@ static void versatile_init(int ram_size,static void vpb_init (int ram_size,int vga_ram_size,int boot_device,DisplayState *ds,const char **fd_filename,int snapshot,const char *kernel_filename,const char *kernel_cmdline, -const char *initrd_filename) +const char *initrd_filename,const char *cpu_model) { versatile_init(ram_size, vga_ram_size, boot_device, ds, fd_filename, snapshot,
@@ -268,7 +268,7 @@ static void vpb_init(int ram_size, int vstatic void vab_init (int ram_size,int vga_ram_size,int boot_device,DisplayState *ds,const char **fd_filename,int snapshot,const char *kernel_filename,const char *kernel_cmdline, -const char *initrd_filename) +const char *initrd_filename,const char *cpu_model) { versatile_init(ram_size, vga_ram_size, boot_device, ds, fd_filename, snapshot,
Index: hw/ppc_chrp.c
===================================================================
RCS file: /sources/qemu/qemu/hw/ppc_chrp.c,v
retrieving revision 1.26
ppc_chrp.c +28 -31
93 lines not on this page · raw message
Index: hw/ppc_prep.c
===================================================================
RCS file: /sources/qemu/qemu/hw/ppc_prep.c,v
retrieving revision 1.29
ppc_prep.c +11 -10
@@ -518,10 +522,12 @@ CPUReadMemoryFunc *PPC_prep_io_read[] =#define NVRAM_SIZE 0x2000/* PowerPC PREP hardware initialisation */ -static void ppc_prep_init (int ram_size,int vga_ram_size,int boot_device, -DisplayState *ds,const char **fd_filename,int snapshot, -const char *kernel_filename,const char *kernel_cmdline, -const char *initrd_filename) +static void ppc_prep_init (int ram_size,int vga_ram_size,int boot_device, +DisplayState *ds,const char **fd_filename, +int snapshot,const char *kernel_filename, +const char *kernel_cmdline, +const char *initrd_filename, +const char *cpu_model) {CPUState *env;char buf[1024 ];
@@ -535,12 +541,11 @@ static void ppc_prep_init(int ram_size, env =cpu_init ();register_savevm ("cpu" ,0 ,3 , cpu_save, cpu_load, env); - -/* Register CPU as a 604 */ -/* XXX: CPU model (or PVR) should be provided on command line */ -// ppc_find_by_name("604r", &def); -// ppc_find_by_name("604e", &def); -ppc_find_by_name ("604" , &def); + +/* Default CPU is a 604 */ +if (cpu_model ==NULL ) + cpu_model ="604" ; +ppc_find_by_name (cpu_model, &def);if (def ==NULL ) {cpu_abort (env,"Unable to find PowerPC CPU definition\n" ); }
OK. Except that I would prefer "-cpu" instead of "-C".
Regards,
Fabrice.
Quoted 13 lines · J. Mayer
Here's a patch that allow the user to specify a specific CPU model/variant on the command line.
This makes different CPU tests less painfull, as the current code need a recompilation for this.
This patch only has an actual effect when using the PowerPC target, as I don't want to break other targets, but would be imho easy to implement for all targets.
It just adds a -C <cpu_model> facultative option to the command line and a new parameter to themachine->initcallback. A machine can then ignore this parameter or tune the emulated CPU based on the given CPU model.Any comments will be welcome but I'd like to insist that such an option would really be useful, at least for testing purposes.
Quoted 1 line · Fabrice Bellard
OK. Except that I would prefer "-cpu" instead of "-C".
OK; I choosed -C for "symetry" with the machine selection option (-M) but -cpu is OK for me...
Quoted 14 lines
Quoted 13 lines · J. Mayer
Here's a patch that allow the user to specify a specific CPU model/variant on the command line.
This makes different CPU tests less painfull, as the current code need a recompilation for this.
This patch only has an actual effect when using the PowerPC target, as I don't want to break other targets, but would be imho easy to implement for all targets.
It just adds a -C <cpu_model> facultative option to the command line and a new parameter to themachine->initcallback. A machine can then ignore this parameter or tune the emulated CPU based on the given CPU model.Any comments will be welcome but I'd like to insist that such an option would really be useful, at least for testing purposes.
Signature · 2 lines
J. Mayer <[email protected]> Never organized
If you ever called qemu with "-cpu ?" and wonder why you get no answer:
here is a small patch which changes this behaviour for all targets without CPU selection.
Regards
Stefan
vl.c +2 -0
@@ -7040,6 +7040,8 @@mips_cpu_list (stdout, &fprintf);#elif defined(TARGET_SPARC )sparc_cpu_list (stdout, &fprintf); +#else +printf ("Target ignores cpu selection\n" );#endif exit (1 ); }else {
main.c +2 -0
@@ -1747,6 +1747,8 @@mips_cpu_list (stdout, &fprintf);#elif defined(TARGET_SPARC )sparc_cpu_list (stdout, &fprintf); +#else +printf ("Target ignores cpu selection\n" );#endif _exit (1 ); }