Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HOest-0000wX-9j for qemu-devel@nongnu.org; Tue, 06 Mar 2007 13:59:39 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HOess-0000w6-5i for qemu-devel@nongnu.org; Tue, 06 Mar 2007 13:59:38 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HOesr-0000w3-Vs for qemu-devel@nongnu.org; Tue, 06 Mar 2007 13:59:38 -0500 Received: from smtp4-g19.free.fr ([212.27.42.30]) by monty-python.gnu.org with esmtp (Exim 4.52) id 1HOesq-0002eQ-Ka for qemu-devel@nongnu.org; Tue, 06 Mar 2007 13:59:37 -0500 Received: from ibm (rob92-1-82-67-154-188.fbx.proxad.net [82.67.154.188]) by smtp4-g19.free.fr (Postfix) with ESMTP id 32CCF67415 for ; Tue, 6 Mar 2007 19:59:35 +0100 (CET) From: =?iso-8859-1?Q?Herv=E9_Poussineau?= Date: Tue, 6 Mar 2007 19:57:30 +0100 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0011_01C76029.AC7653F0" Message-Id: <20070306185935.32CCF67415@smtp4-g19.free.fr> Subject: [Qemu-devel] [PATCH] Choose emulated MIPS CPU at runtime #2 Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is a multi-part message in MIME format. ------=_NextPart_000_0011_01C76029.AC7653F0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, This patch uses the new "-cpu" command line option, to choose the CPU = model at runtime. It takes care of Thiemo's remarks about existing CPU models. It defaults to MIPS 4KEc in 32bits mode, and R4000 in 64bits mode. To answer Daniel's concerns, the FPU bit in the CPU structure is set = only if the chosen CPU has a FPU. This thing is only done once per CPU reset (ie most of the times, once per qemu launch), so it has no runtime cost. Herv=E9 ------=_NextPart_000_0011_01C76029.AC7653F0 Content-Type: application/octet-stream; name="mips-cpu2.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="mips-cpu2.diff" ? target-mips/translate_init.c=0A= Index: Makefile.target=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvsroot/qemu/qemu/Makefile.target,v=0A= retrieving revision 1.147=0A= diff -u -r1.147 Makefile.target=0A= --- Makefile.target 28 Feb 2007 21:36:41 -0000 1.147=0A= +++ Makefile.target 6 Mar 2007 18:17:43 -0000=0A= @@ -550,6 +550,7 @@=0A= ifeq ($(TARGET_ARCH), mips)=0A= op.o: op.c op_template.c fop_template.c op_mem.c=0A= op_helper.o: op_helper_mem.c=0A= +translate.o: translate.c translate_init.c=0A= endif=0A= =0A= loader.o: loader.c elf_ops.h=0A= Index: vl.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvsroot/qemu/qemu/vl.c,v=0A= retrieving revision 1.261=0A= diff -u -r1.261 vl.c=0A= --- vl.c 5 Mar 2007 19:44:01 -0000 1.261=0A= +++ vl.c 6 Mar 2007 18:17:46 -0000=0A= @@ -7007,6 +7007,8 @@=0A= if (optarg[0] =3D=3D '?') {=0A= #if defined(TARGET_PPC)=0A= ppc_cpu_list(stdout, &fprintf);=0A= +#elif defined(TARGET_MIPS)=0A= + mips_cpu_list(stdout, &fprintf);=0A= #endif=0A= exit(1);=0A= } else {=0A= Index: vl.h=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvsroot/qemu/qemu/vl.h,v=0A= retrieving revision 1.191=0A= diff -u -r1.191 vl.h=0A= --- vl.h 5 Mar 2007 19:44:02 -0000 1.191=0A= +++ vl.h 6 Mar 2007 18:17:47 -0000=0A= @@ -713,6 +713,10 @@=0A= void ppc_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char = *fmt, ...));=0A= #endif=0A= =0A= +#if defined(TARGET_MIPS)=0A= +void mips_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char = *fmt, ...));=0A= +#endif=0A= +=0A= /* ISA bus */=0A= =0A= extern target_phys_addr_t isa_mem_base;=0A= Index: hw/mips_malta.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvsroot/qemu/qemu/hw/mips_malta.c,v=0A= retrieving revision 1.15=0A= diff -u -r1.15 mips_malta.c=0A= --- hw/mips_malta.c 5 Mar 2007 19:44:02 -0000 1.15=0A= +++ hw/mips_malta.c 6 Mar 2007 18:17:47 -0000=0A= @@ -626,8 +626,20 @@=0A= /* fdctrl_t *floppy_controller; */=0A= MaltaFPGAState *malta_fpga;=0A= int ret;=0A= + mips_def_t *def;=0A= =0A= + /* init CPUs */=0A= + if (cpu_model =3D=3D NULL) {=0A= +#ifdef MIPS_HAS_MIPS64=0A= + cpu_model =3D "R4000";=0A= +#else=0A= + cpu_model =3D "4KEc";=0A= +#endif=0A= + }=0A= + if (mips_find_by_name(cpu_model, &def) !=3D 0)=0A= + def =3D NULL;=0A= env =3D cpu_init();=0A= + cpu_mips_register(env, def);=0A= register_savevm("cpu", 0, 3, cpu_save, cpu_load, env);=0A= qemu_register_reset(main_cpu_reset, env);=0A= =0A= Index: hw/mips_r4k.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvsroot/qemu/qemu/hw/mips_r4k.c,v=0A= retrieving revision 1.37=0A= diff -u -r1.37 mips_r4k.c=0A= --- hw/mips_r4k.c 5 Mar 2007 19:44:02 -0000 1.37=0A= +++ hw/mips_r4k.c 6 Mar 2007 18:17:47 -0000=0A= @@ -138,8 +138,20 @@=0A= CPUState *env;=0A= static RTCState *rtc_state;=0A= int i;=0A= + mips_def_t *def;=0A= =0A= + /* init CPUs */=0A= + if (cpu_model =3D=3D NULL) {=0A= +#ifdef MIPS_HAS_MIPS64=0A= + cpu_model =3D "R4000";=0A= +#else=0A= + cpu_model =3D "4KEc";=0A= +#endif=0A= + }=0A= + if (mips_find_by_name(cpu_model, &def) !=3D 0)=0A= + def =3D NULL;=0A= env =3D cpu_init();=0A= + cpu_mips_register(env, def);=0A= register_savevm("cpu", 0, 3, cpu_save, cpu_load, env);=0A= qemu_register_reset(main_cpu_reset, env);=0A= =0A= @@ -148,7 +160,7 @@=0A= =0A= if (!mips_qemu_iomemtype) {=0A= mips_qemu_iomemtype =3D cpu_register_io_memory(0, = mips_qemu_read,=0A= - mips_qemu_write, NULL);=0A= + mips_qemu_write, = NULL);=0A= }=0A= cpu_register_physical_memory(0x1fbf0000, 0x10000, = mips_qemu_iomemtype);=0A= =0A= Index: target-mips/cpu.h=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvsroot/qemu/qemu/target-mips/cpu.h,v=0A= retrieving revision 1.23=0A= diff -u -r1.23 cpu.h=0A= --- target-mips/cpu.h 2 Mar 2007 20:48:00 -0000 1.23=0A= +++ target-mips/cpu.h 6 Mar 2007 18:17:48 -0000=0A= @@ -282,6 +282,11 @@=0A= struct QEMUTimer *timer; /* Internal timer */=0A= };=0A= =0A= +typedef struct mips_def_t mips_def_t;=0A= +int mips_find_by_name (const unsigned char *name, mips_def_t **def);=0A= +void mips_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char = *fmt, ...));=0A= +int cpu_mips_register (CPUMIPSState *env, mips_def_t *def);=0A= +=0A= #include "cpu-all.h"=0A= =0A= /* Memory access type :=0A= Index: target-mips/mips-defs.h=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvsroot/qemu/qemu/target-mips/mips-defs.h,v=0A= retrieving revision 1.7=0A= diff -u -r1.7 mips-defs.h=0A= --- target-mips/mips-defs.h 28 Feb 2007 22:37:42 -0000 1.7=0A= +++ target-mips/mips-defs.h 6 Mar 2007 18:17:48 -0000=0A= @@ -6,26 +6,15 @@=0A= /* If we want to use host float regs... */=0A= //#define USE_HOST_FLOAT_REGS=0A= =0A= -#define MIPS_R4Kc 0x00018000=0A= -#define MIPS_R4Kp 0x00018300=0A= -=0A= -/* Emulate MIPS R4Kc for now */=0A= -#define MIPS_CPU MIPS_R4Kc=0A= -=0A= -#if (MIPS_CPU =3D=3D MIPS_R4Kc)=0A= /* 32 bits target */=0A= #undef MIPS_HAS_MIPS64=0A= //#define MIPS_HAS_MIPS64 1=0A= /* real pages are variable size... */=0A= #define TARGET_PAGE_BITS 12=0A= -/* Uses MIPS R4Kx enhancements to MIPS32 architecture */=0A= -#define MIPS_USES_R4K_EXT=0A= /* Uses MIPS R4Kc TLB model */=0A= #define MIPS_USES_R4K_TLB=0A= #define MIPS_TLB_NB 16=0A= #define MIPS_TLB_MAX 128=0A= -/* basic FPU register support */=0A= -#define MIPS_USES_FPU 1=0A= /* Define a implementation number of 1.=0A= * Define a major version 1, minor version 0.=0A= */=0A= @@ -63,21 +52,6 @@=0A= ((0 << CP0C3_M) | (0 << CP0C3_DSPP) | (0 << CP0C3_LPA) | \=0A= (0 << CP0C3_VEIC) | (0 << CP0C3_VInt) | (0 << CP0C3_SP) | \=0A= (0 << CP0C3_MT) | (0 << CP0C3_SM) | (0 << CP0C3_TL))=0A= -#elif (MIPS_CPU =3D=3D MIPS_R4Kp)=0A= -/* 32 bits target */=0A= -#undef MIPS_HAS_MIPS64=0A= -/* real pages are variable size... */=0A= -#define TARGET_PAGE_BITS 12=0A= -/* Uses MIPS R4Kx enhancements to MIPS32 architecture */=0A= -#define MIPS_USES_R4K_EXT=0A= -/* Uses MIPS R4Km FPM MMU model */=0A= -#define MIPS_USES_R4K_FPM=0A= -#else=0A= -#error "MIPS CPU not defined"=0A= -/* Reminder for other flags */=0A= -//#undef MIPS_HAS_MIPS64=0A= -//#define MIPS_USES_FPU=0A= -#endif=0A= =0A= #ifdef MIPS_HAS_MIPS64=0A= #define TARGET_LONG_BITS 64=0A= Index: target-mips/translate.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvsroot/qemu/qemu/target-mips/translate.c,v=0A= retrieving revision 1.36=0A= diff -u -r1.36 translate.c=0A= --- target-mips/translate.c 2 Mar 2007 20:48:00 -0000 1.36=0A= +++ target-mips/translate.c 6 Mar 2007 18:17:50 -0000=0A= @@ -5283,12 +5283,6 @@=0A= env->CP0_Wired =3D 0;=0A= /* SMP not implemented */=0A= env->CP0_EBase =3D 0x80000000;=0A= - env->CP0_Config0 =3D MIPS_CONFIG0;=0A= - env->CP0_Config1 =3D MIPS_CONFIG1;=0A= -#ifdef MIPS_USES_FPU=0A= - /* basic FPU register support */=0A= - env->CP0_Config1 |=3D (1 << CP0C1_FP);=0A= -#endif=0A= env->CP0_Config2 =3D MIPS_CONFIG2;=0A= env->CP0_Config3 =3D MIPS_CONFIG3;=0A= env->CP0_Status =3D (1 << CP0St_BEV) | (1 << CP0St_ERL);=0A= @@ -5296,7 +5290,6 @@=0A= env->hflags =3D MIPS_HFLAG_ERL;=0A= /* Count register increments in debug mode, EJTAG version 1 */=0A= env->CP0_Debug =3D (1 << CP0DB_CNT) | (0x1 << CP0DB_VER);=0A= - env->CP0_PRid =3D MIPS_CPU;=0A= #endif=0A= env->exception_index =3D EXCP_NONE;=0A= #if defined(CONFIG_USER_ONLY)=0A= @@ -5308,3 +5301,5 @@=0A= env->SYNCI_Step =3D 16;=0A= env->CCRes =3D 2;=0A= }=0A= +=0A= +#include "translate_init.c"=0A= Index: target-mips/translate_init.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= --- /dev/null ? +++ target-mips/translate_init.c Tue Mar 06 19:22:18 2007 @@ -0,0 +1,91 @@ +/* + * MIPS emulation for qemu: CPU initialisation routines. + * + * Copyright (c) 2004-2005 Jocelyn Mayer + * Copyright (c) 2007 Herve Poussineau + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 = USA + */ + +struct mips_def_t { + const unsigned char *name; + int32_t CP0_PRid; + int32_t CP0_Config0; + int32_t CP0_Config1; +}; + +/***********************************************************************= ******/ +/* MIPS CPU definitions */ +static mips_def_t mips_defs[] =3D +{ +#ifndef MIPS_HAS_MIPS64 + { + .name =3D "4KEc", + .CP0_PRid =3D 0x00018000, + .CP0_Config0 =3D MIPS_CONFIG0, + .CP0_Config1 =3D MIPS_CONFIG1, + }, + { + .name =3D "24Kf", + .CP0_PRid =3D 0x00018000, + .CP0_Config0 =3D MIPS_CONFIG0, + .CP0_Config1 =3D MIPS_CONFIG1 | (1 << CP0C1_FP), + }, +#else + { + .name =3D "R4000", + .CP0_PRid =3D 0x00018000, + .CP0_Config0 =3D MIPS_CONFIG0 | (0x2 << CP0C0_AT), + .CP0_Config1 =3D MIPS_CONFIG1 | (1 << CP0C1_FP), + }, +#endif +}; + +int mips_find_by_name (const unsigned char *name, mips_def_t **def) +{ + int i, ret; + + ret =3D -1; + *def =3D NULL; + for (i =3D 0; i < sizeof(mips_defs) / sizeof(mips_defs[0]); i++) { + if (strcasecmp(name, mips_defs[i].name) =3D=3D 0) { + *def =3D &mips_defs[i]; + ret =3D 0; + break; + } + } + + return ret; +} + +void mips_cpu_list (FILE *f, int (*cpu_fprintf)(FILE *f, const char = *fmt, ...)) +{ + int i; + + for (i =3D 0; i < sizeof(mips_defs) / sizeof(mips_defs[0]); i++) { + (*cpu_fprintf)(f, "MIPS '%s'\n", + mips_defs[i].name); + } +} + +int cpu_mips_register (CPUMIPSState *env, mips_def_t *def) +{ + if (!def) + cpu_abort(env, "Unable to find MIPS CPU definition\n"); + env->CP0_PRid =3D def->CP0_PRid; + env->CP0_Config0 =3D def->CP0_Config0; + env->CP0_Config1 =3D def->CP0_Config1; + return 0; +} ------=_NextPart_000_0011_01C76029.AC7653F0--