Skip to contentSkip to conversation

Introduce QOM CPU and use it for ARM

RFC PATCH In review Andreas Färber 4 participants 47 messages Feb 3, 2012 – Feb 17, 2012 Kbuild

lore
Share & tools
lore
#0 lore raw

v3 cover Introduce QOM CPU and use it for ARM

Hello,

Here's an improved and extended series on incrementally converting CPUState to QOM, rebased onto Anthony's qom-upstream.14 plus some master updates.

The general idea behind the series is to cease having CPU-dependent code in generic functions, in favor of storing constant data in CPU classes and letting instance methods either be dumb initializations or overwritten. After the initial introduction of the types, this series is mainly mechanical code movement. This series does NOT yet...
...model ARM CPU has-a cp15 register,
...introduce SoCs (child<CPU> plus devices),
...touch machines.

Patch 1 rearranges module init for QOM, so that objects can really be used beyond devices. Introduces a neutral type_init() macro for new types. Does not depend on 3rd QOM series and could be cherry-picked.

Patch 2 adds QOM support to the user emulators. Note that more dependencies and some stubs were now needed to successfully compile.

Patch 3 introduces the QOM CPU base class.

Patches 4-19 derive and start using a QOM CPU for ARM.
Patch 5 integrates legacy CPUARMState into QOM.
Patch 7 is a proof of concept for CPUState -> CPU lookup.
Patch 19 completes freeing cpu_reset() and cpu_arm_init() of any model logic.

Patch 20 adds a sample read-only property accessing legacy CPUState. Patch 21 is a hack to allow inspecting this using
QMP/qmp qom-list --path=/cpu --property=halted
For some reason the logic seems inverted (False for -S, True while running)...

Available at:
http://repo.or.cz/w/qemu/afaerber.git/shortlog/refs/heads/qom-cpu.v3

TODO: We might want to sort -cpu ? alphabetically; object_class_foreach() prints them in hash table order.

Agenda:
AF: Convert one other target as proof of concept.
Once Anthony's 3rd QOM series is merged, sort out and merge (what is now) 1-19.
all: Incrementally (hopefully in parallel) derive QOM CPUs for all targets. Only when all targets are converted will it be possible to move fields from CPU_COMMON into CPU, to add properties in common code, to simplify some function names and to eliminate CPUState *env in core code!

Regards,
Andreas

Cc Anthony Liguori <[email protected]>
Cc Peter Maydell <[email protected]>

v2 -> v3:
* Rebased against qom-upstream.14 branch (and that against master).

* Build common dependencies for user emulators in libuser/.
* New dependencies needed after moving properties into object.c.
* Add a qemu-user.c with stubs needed for successful linking.

* Move cpu.c from hw/ to qom/ (built only once).
* Use proper GPL headers.

* Rename target-arm/cpu-core.c to cpu.c now that we no longer need VPATH.
* Leave cpu-core.h as is to separate from legacy cpu.h.
* Fix -cpu alias "pxa270": handled in cpu_arm_init().
* Use proper GPL headers.

* Start removing CPUID uses in cpu_reset_model_id() and cpu.h.
* Fully convert cpu_reset_model_id() to ARMCPUInfo or per-model code.
* Experiment with adding properties.

v1 -> v2:

* Cherry-pick Anthony's object_class_foreach() patch.

* Don't introduce extra early_init(), just relocate former MODULE_INIT_DEVICE.
* Provide new type_init() macro to be used instead of device_init().

* Drop processor_init() and MODULE_INIT_CPU in favor of MODULE_INIT_DEVICE.
* Prepare cast macros for CPU.
* Add documentation.

* Fix ARMCPUClass type name (arm-cpu-core -> arm-cpu).
* Add documentation.
* Rename ARMCPUDef to ARMCPUInfo.
* Use a C99-style table for initializing the classes through class_data instead of individual class_init functions (suggested by Anthony).
* Prepare reset callback.

* Make ENV_GET_OBJECT() use an inline function for readability.
* Invoke the CPU's reset method from cpu_reset().

* Do feature initialization via table where sensible.
* Add feature flags to ARMCPU as well (suggested by PMM for future tweaking, also simplifies load/save a bit) and initialize them from ARMCPUClass.
* Make feature inference work for ARMCPU as well by not passing the ARMCPUClass. Use function-local macros to avoid the ugliness of deferencing the features pointer.

Andreas Färber (21):
qom: Register QOM infrastructure early
qom: Add QOM support to user emulators
qom: Introduce CPU class
target-arm: Introduce QOM CPU and use it for CPUID lookup
target-arm: Embed CPUARMState in QOM ARMCPU
target-arm: Prepare model-specific class_init function
target-arm: Overwrite reset handler for ti925t
target-arm: Move CPU feature flags out of CPUState
target-arm: No longer abort on unhandled CPUIDs on reset
target-arm: Store cp15 c0_c1 and c0_c2 in ARMCPUClass
target-arm: Store cp15 c0_cachetype register in ARMCPUClass
target-arm: Move cp15 c1_sys register to ARMCPUClass
target-arm: Store JTAG_ID in ARMCPUClass
target-arm: Move the PXA270's iwMMXt reset to pxa270_reset()
target-arm: Store VFP FPSID register in ARMCPUClass
target-arm: Store VFP MVFR0 and MVFR1 in ARMCPUClass
target-arm: Store CLIDR in ARMCPUClass
target-arm: Store CCSIDRs in ARMCPUClass
target-arm: Kill off cpu_reset_model_id()
target-arm: Prepare halted property for CPU
target-arm: Just for testing!

 Makefile.objs         |    6 +
 Makefile.target       |    1 +
 Makefile.user         |    1 +
 bsd-user/main.c       |    2 +
 configure             |    2 +
 darwin-user/main.c    |    3 +
 include/qemu/cpu.h    |   73 ++++++
 linux-user/main.c     |    2 +
 module.h              |    5 +-
 qemu-user.c           |   37 +++
 qom/Makefile          |    1 +
 qom/cpu.c             |   50 ++++
 target-arm/cpu-core.h |   93 ++++++++
 target-arm/cpu.c      |  631 +++++++++++++++++++++++++++++++++++++++++++++++++
 target-arm/cpu.h      |   27 +--
 target-arm/helper.c   |  425 +++------------------------------
 target-arm/machine.c  |    6 +-
 vl.c                  |    4 +-
 18 files changed, 944 insertions(+), 425 deletions(-)
 create mode 100644 include/qemu/cpu.h
 create mode 100644 qemu-user.c
 create mode 100644 qom/cpu.c
 create mode 100644 target-arm/cpu-core.h
 create mode 100644 target-arm/cpu.c
Signature · 1 line
1.7.7
#1 lore raw

PATCH v3 1/21 qom: Register QOM infrastructure early

QOM TYPE_INTERFACE was registered with device_init(), whose constructors are executed rather late in vl.c's main().

Rename the module init type from DEVICE to QOM and call it very early so that QOM can safely be used for machines and CPUs.

device_init() is left for legacy types. New ones should use type_init().

---
 module.h |    5 +++--
 vl.c     |    4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)
module.h +3 -2
index ef66730..56391a5 100644
@@ -21,15 +21,16 @@ static void __attribute__((constructor)) do_qemu_init_ ## function(void) {  \
 }
 
 typedef enum {
+    MODULE_INIT_QOM,
     MODULE_INIT_BLOCK,
-    MODULE_INIT_DEVICE,
     MODULE_INIT_MACHINE,
     MODULE_INIT_QAPI,
     MODULE_INIT_MAX
 } module_init_type;
 
+#define type_init(function) module_init(function, MODULE_INIT_QOM)
 #define block_init(function) module_init(function, MODULE_INIT_BLOCK)
-#define device_init(function) module_init(function, MODULE_INIT_DEVICE)
+#define device_init(function) module_init(function, MODULE_INIT_QOM)
 #define machine_init(function) module_init(function, MODULE_INIT_MACHINE)
 #define qapi_init(function) module_init(function, MODULE_INIT_QAPI)
 
vl.c +2 -2
index 2d464cf..8f2fc3c 100644
@@ -2221,6 +2221,8 @@ int main(int argc, char **argv, char **envp)
 #endif
     }
 
+    module_call_init(MODULE_INIT_QOM);
+
     runstate_init();
 
     init_clocks();
@@ -3357,8 +3359,6 @@ int main(int argc, char **argv, char **envp)
     if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
         exit(1);
 
-    module_call_init(MODULE_INIT_DEVICE);
-
     /* must be after qdev registration but before machine init */
     if (vga_model) {
         select_vgahw(vga_model);
Signature · 1 line
1.7.7
#2 lore raw

Re: [Qemu-devel] [PATCH v3 01/21] qom: Register QOM infrastructure early

Quoted 7 lines · Andreas Färber

QOM TYPE_INTERFACE was registered with device_init(), whose constructors are executed rather late in vl.c's main().

Rename the module init type from DEVICE to QOM and call it very early so that QOM can safely be used for machines and CPUs.

device_init() is left for legacy types. New ones should use type_init().

There are no legacy device_init users. Everything can (and should) be converted to type_init() and MODULE_INIT_QOM can be invoked very early.

Regards,

Anthony Liguori

#3 lore raw

RFC PATCH v3 2/21 qom: Add QOM support to user emulators

In reply to Andreas Färber

Link the Object base class and the module infrastructure for class registration. Call QOM module init.

---
 Makefile.objs      |    6 ++++++
 Makefile.user      |    1 +
 bsd-user/main.c    |    2 ++
 configure          |    2 ++
 darwin-user/main.c |    3 +++
 linux-user/main.c  |    2 ++
 qemu-user.c        |   37 +++++++++++++++++++++++++++++++++++++
 7 files changed, 53 insertions(+), 0 deletions(-)
 create mode 100644 qemu-user.c
Makefile.objs +6 -0
index ec35320..1155cc0 100644
@@ -182,7 +182,11 @@ user-obj-y =
 user-obj-y += envlist.o path.o
 user-obj-y += tcg-runtime.o host-utils.o
 user-obj-y += cutils.o cache-utils.o
+user-obj-y += module.o
+user-obj-y += qemu-user.o
 user-obj-y += $(trace-obj-y)
+user-obj-y += $(qobject-obj-y)
+user-obj-y += $(addprefix qom/, $(qom-y))
 
 ######################################################################
 # libhw
@@ -421,6 +425,8 @@ qapi-obj-y = $(addprefix qapi/, $(qapi-nested-y))
 common-obj-y += qmp-marshal.o qapi-visit.o qapi-types.o $(qapi-obj-y)
 common-obj-y += qmp.o hmp.o
 
+user-obj-y += $(qapi-obj-y)
+
 ######################################################################
 # guest agent
 
Makefile.user +1 -0
index 2b1e4d1..72d01c1 100644
@@ -9,6 +9,7 @@ include $(SRC_PATH)/rules.mak
 $(call set-vpath, $(SRC_PATH))
 
 QEMU_CFLAGS+=-I..
+QEMU_CFLAGS+=-I$(SRC_PATH)/include
 
 include $(SRC_PATH)/Makefile.objs
 
bsd-user/main.c +2 -0
index cc7d4a3..cdb0d0a 100644
@@ -748,6 +748,8 @@ int main(int argc, char **argv)
     if (argc <= 1)
         usage();
 
+    module_call_init(MODULE_INIT_QOM);
+
     if ((envlist = envlist_create()) == NULL) {
         (void) fprintf(stderr, "Unable to allocate envlist\n");
         exit(1);
configure +2 -0
index 3b0b300..ee1140e 100755
@@ -3849,6 +3849,8 @@ fi
 d=libuser
 mkdir -p $d
 mkdir -p $d/trace
+mkdir -p $d/qapi
+mkdir -p $d/qom
 symlink $source_path/Makefile.user $d/Makefile
 
 if test "$docs" = "yes" ; then
darwin-user/main.c +3 -0
index 9b57c20..e1519c7 100644
@@ -28,6 +28,7 @@
 #include <sys/mman.h>
 
 #include "qemu.h"
+#include "qemu-common.h"
 
 #define DEBUG_LOGFILE "/tmp/qemu.log"
 
@@ -749,6 +750,8 @@ int main(int argc, char **argv)
     if (argc <= 1)
         usage();
 
+    module_call_init(MODULE_INIT_QOM);
+
     optind = 1;
     for(;;) {
         if (optind >= argc)
linux-user/main.c +2 -0
index 64d2208..f55109c 100644
@@ -3278,6 +3278,8 @@ int main(int argc, char **argv, char **envp)
     int i;
     int ret;
 
+    module_call_init(MODULE_INIT_QOM);
+
     qemu_cache_utils_init(envp);
 
     if ((envlist = envlist_create()) == NULL) {
qemu-user.c new file +37 -0
new file mode 100644
index 0000000..51b2649
@@ -0,0 +1,37 @@
+/*
+ * Stubs for QEMU user emulation
+ *
+ * Copyright (c) 2012 SUSE LINUX Products GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see
+ * <http://www.gnu.org/licenses/old-licenses/gpl-2.0>
+ */
+
+#include "qemu-common.h"
+#include "monitor.h"
+
+Monitor *cur_mon;
+
+int monitor_cur_is_qmp(void)
+{
+    return 0;
+}
+
+void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
+{
+}
+
+void monitor_set_error(Monitor *mon, QError *qerror)
+{
+}
Signature · 1 line
1.7.7
#4 lore raw

Re: [Qemu-devel] [PATCH RFC v3 02/21] qom: Add QOM support to user emulators

Quoted 5 lines · Andreas Färber

Link the Object base class and the module infrastructure for class registration. Call QOM module init.

If we're going to go down this road, then I have a hard requirement. We need to build the common infrastructure only once.

Otherwise build times are going to explode and we'll end up with CONFIG_USER_ONLY #defines all over the place.

Regards,

Anthony Liguori

Quoted 151 lines
---
  Makefile.objs      |    6 ++++++
  Makefile.user      |    1 +
  bsd-user/main.c    |    2 ++
  configure          |    2 ++
  darwin-user/main.c |    3 +++
  linux-user/main.c  |    2 ++
  qemu-user.c        |   37 +++++++++++++++++++++++++++++++++++++
  7 files changed, 53 insertions(+), 0 deletions(-)

create mode 100644 qemu-user.c

Makefile.objs +6 -0
index ec35320..1155cc0 100644
@@ -182,7 +182,11 @@ user-obj-y =
  user-obj-y += envlist.o path.o
  user-obj-y += tcg-runtime.o host-utils.o
  user-obj-y += cutils.o cache-utils.o
+user-obj-y += module.o
+user-obj-y += qemu-user.o
  user-obj-y += $(trace-obj-y)
+user-obj-y += $(qobject-obj-y)
+user-obj-y += $(addprefix qom/, $(qom-y))
 
  ######################################################################
  # libhw
@@ -421,6 +425,8 @@ qapi-obj-y = $(addprefix qapi/, $(qapi-nested-y))
  common-obj-y += qmp-marshal.o qapi-visit.o qapi-types.o $(qapi-obj-y)
  common-obj-y += qmp.o hmp.o
 
+user-obj-y += $(qapi-obj-y)
+
  ######################################################################
  # guest agent
 
Makefile.user +1 -0
index 2b1e4d1..72d01c1 100644
@@ -9,6 +9,7 @@ include $(SRC_PATH)/rules.mak
  $(call set-vpath, $(SRC_PATH))
 
  QEMU_CFLAGS+=-I..
+QEMU_CFLAGS+=-I$(SRC_PATH)/include
 
  include $(SRC_PATH)/Makefile.objs
 
bsd-user/main.c +2 -0
index cc7d4a3..cdb0d0a 100644
@@ -748,6 +748,8 @@ int main(int argc, char **argv)
      if (argc<= 1)
          usage();
 
+    module_call_init(MODULE_INIT_QOM);
+
      if ((envlist = envlist_create()) == NULL) {
          (void) fprintf(stderr, "Unable to allocate envlist\n");
          exit(1);
configure +2 -0
index 3b0b300..ee1140e 100755
@@ -3849,6 +3849,8 @@ fi
  d=libuser
  mkdir -p $d
  mkdir -p $d/trace
+mkdir -p $d/qapi
+mkdir -p $d/qom
  symlink $source_path/Makefile.user $d/Makefile
 
  if test "$docs" = "yes" ; then
darwin-user/main.c +3 -0
index 9b57c20..e1519c7 100644
@@ -28,6 +28,7 @@
  #include<sys/mman.h>
 
  #include "qemu.h"
+#include "qemu-common.h"
 
  #define DEBUG_LOGFILE "/tmp/qemu.log"
 
@@ -749,6 +750,8 @@ int main(int argc, char **argv)
      if (argc<= 1)
          usage();
 
+    module_call_init(MODULE_INIT_QOM);
+
      optind = 1;
      for(;;) {
          if (optind>= argc)
linux-user/main.c +2 -0
index 64d2208..f55109c 100644
@@ -3278,6 +3278,8 @@ int main(int argc, char **argv, char **envp)
      int i;
      int ret;
 
+    module_call_init(MODULE_INIT_QOM);
+
      qemu_cache_utils_init(envp);
 
      if ((envlist = envlist_create()) == NULL) {
qemu-user.c new file +37 -0
new file mode 100644
index 0000000..51b2649
@@ -0,0 +1,37 @@
+/*
+ * Stubs for QEMU user emulation
+ *
+ * Copyright (c) 2012 SUSE LINUX Products GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see
+ *<http://www.gnu.org/licenses/old-licenses/gpl-2.0>
+ */
+
+#include "qemu-common.h"
+#include "monitor.h"
+
+Monitor *cur_mon;
+
+int monitor_cur_is_qmp(void)
+{
+    return 0;
+}
+
+void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
+{
+}
+
+void monitor_set_error(Monitor *mon, QError *qerror)
+{
+}
#5 lore raw

Re: [Qemu-devel] [PATCH RFC v3 02/21] qom: Add QOM support to user emulators

Am 06.02.2012 20:16, schrieb Anthony Liguori:

Quoted 12 lines · Andreas Färber
Quoted 5 lines

Link the Object base class and the module infrastructure for class registration. Call QOM module init.

If we're going to go down this road, then I have a hard requirement. We need to build the common infrastructure only once.

Otherwise build times are going to explode and we'll end up with CONFIG_USER_ONLY #defines all over the place.

v3 builds it once as before plus once for the user emulators. If that is really too much already, please advise where to move the objects to.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#6 lore raw

Re: [Qemu-devel] [PATCH RFC v3 02/21] qom: Add QOM support to user emulators

In reply to Anthony Liguori
Quoted 5 lines · Anthony Liguori

If we're going to go down this road, then I have a hard requirement.  We need to build the common infrastructure only once.

Otherwise build times are going to explode and we'll end up with CONFIG_USER_ONLY #defines all over the place.

You already have to build twice, because you can't say "build the user emulators with --static and the system emulators without", so one of the standard use cases requires doing two configure-and-build runs anyhow.

-- PMM

#7 lore raw

Re: [Qemu-devel] [PATCH RFC v3 02/21] qom: Add QOM support to user emulators

Quoted 11 lines · Peter Maydell
Quoted 5 lines · Anthony Liguori

If we're going to go down this road, then I have a hard requirement. We need to build the common infrastructure only once.

Otherwise build times are going to explode and we'll end up with CONFIG_USER_ONLY #defines all over the place.

You already have to build twice, because you can't say "build the user emulators with --static and the system emulators without", so one of the standard use cases requires doing two configure-and-build runs anyhow.

So does it make sense to build both user and system emulators by default?

QOM has a lot of dependencies. Rebuilding it for user means that we're goign to end up rebuilding a lot of user code which sucks.

Regards,

Anthony Liguori

Quoted 3 lines

-- PMM

#8 lore raw

RFC PATCH v3 3/21 qom: Introduce CPU class

In reply to Andreas Färber

It's abstract and derived directly from TYPE_OBJECT. Prepare a virtual reset method.

Cc Anthony Liguori <[email protected]>
Cc Peter Maydell <[email protected]>
---
 include/qemu/cpu.h |   73 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 qom/Makefile       |    1 +
 qom/cpu.c          |   50 +++++++++++++++++++++++++++++++++++
 3 files changed, 124 insertions(+), 0 deletions(-)
 create mode 100644 include/qemu/cpu.h
 create mode 100644 qom/cpu.c
include/qemu/cpu.h new file +73 -0
new file mode 100644
index 0000000..22c7404
@@ -0,0 +1,73 @@
+/*
+ * QEMU CPU model
+ *
+ * Copyright (c) 2012 SUSE LINUX Products GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see
+ * <http://www.gnu.org/licenses/old-licenses/gpl-2.0>
+ */
+#ifndef QEMU_CPU_H
+#define QEMU_CPU_H
+
+#include "qemu/object.h"
+
+#define TYPE_CPU "cpu"
+
+#define CPU(obj) OBJECT_CHECK(CPU, (obj), TYPE_CPU)
+#define CPU_CLASS(class) OBJECT_CLASS_CHECK(CPUClass, (class), TYPE_CPU)
+#define CPU_GET_CLASS(obj) OBJECT_GET_CLASS(CPUClass, (obj), TYPE_CPU)
+
+typedef struct CPU CPU;
+
+/**
+ * CPUClass:
+ * @reset: Callback to reset the #CPU to its initial state.
+ *
+ * Represents a CPU family or model.
+ */
+typedef struct CPUClass {
+    ObjectClass parent_class;
+
+    void (*reset)(CPU *cpu);
+} CPUClass;
+
+/**
+ * CPU:
+ *
+ * State of one CPU core or thread.
+ */
+struct CPU {
+    Object parent_obj;
+
+    /* TODO Move common fields from CPUState here. */
+};
+
+
+/* TODO Rename to cpu_reset once all CPUState is converted to QOM. */
+/**
+ * cpu_do_reset:
+ * @cpu: The CPU whose state is to be reset.
+ */
+void cpu_do_reset(CPU *cpu);
+
+/**
+ * cpu_common_reset:
+ * @cpu: The CPU whose common state is to be reset.
+ *
+ * To be used by derived classes.
+ */
+void cpu_common_reset(CPU *cpu);
+
+
+#endif
qom/Makefile +1 -0
index f33f0be..0a1c8e0 100644
@@ -1 +1,2 @@
 qom-y = object.o container.o
+qom-y += cpu.o
qom/cpu.c new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
1.7.7
#9 lore raw

Re: [Qemu-devel] [PATCH RFC v3 03/21] qom: Introduce CPU class

Quoted 41 lines · Andreas Färber

It's abstract and derived directly from TYPE_OBJECT. Prepare a virtual reset method.

Cc Anthony Liguori<[email protected]>
Cc Peter Maydell<[email protected]>
---
  include/qemu/cpu.h |   73 ++++++++++++++++++++++++++++++++++++++++++++++++++++
  qom/Makefile       |    1 +
  qom/cpu.c          |   50 +++++++++++++++++++++++++++++++++++
  3 files changed, 124 insertions(+), 0 deletions(-)

create mode 100644 include/qemu/cpu.h
create mode 100644 qom/cpu.c

include/qemu/cpu.h new file +21 -0
new file mode 100644
index 0000000..22c7404
@@ -0,0 +1,73 @@
+/*
+ * QEMU CPU model
+ *
+ * Copyright (c) 2012 SUSE LINUX Products GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see
+ *<http://www.gnu.org/licenses/old-licenses/gpl-2.0>
+ */
+#ifndef QEMU_CPU_H
+#define QEMU_CPU_H

include/qemu/cpu.h line 31

Quoted 10 lines
include/qemu/cpu.h new file +10 -0
+
+#include "qemu/object.h"
+
+#define TYPE_CPU "cpu"
+
+#define CPU(obj) OBJECT_CHECK(CPU, (obj), TYPE_CPU)
+#define CPU_CLASS(class) OBJECT_CLASS_CHECK(CPUClass, (class), TYPE_CPU)
+#define CPU_GET_CLASS(obj) OBJECT_GET_CLASS(CPUClass, (obj), TYPE_CPU)
+
+typedef struct CPU CPU;

If this doesn't result in a build error, then C is a worse language than I thought it was :-/

But we definitely shouldn't have a typename and macro name of the same thing and expect it to work...

Quoted 21 lines
include/qemu/cpu.h new file +21 -0
+
+/**
+ * CPUClass:
+ * @reset: Callback to reset the #CPU to its initial state.
+ *
+ * Represents a CPU family or model.
+ */
+typedef struct CPUClass {
+    ObjectClass parent_class;
+
+    void (*reset)(CPU *cpu);
+} CPUClass;
+
+/**
+ * CPU:
+ *
+ * State of one CPU core or thread.
+ */
+struct CPU {
+    Object parent_obj;
+

include/qemu/cpu.h line 62

Quoted 10 lines
include/qemu/cpu.h new file +10 -0
+    /* TODO Move common fields from CPUState here. */
+};
+
+
+/* TODO Rename to cpu_reset once all CPUState is converted to QOM. */
+/**
+ * cpu_do_reset:
+ * @cpu: The CPU whose state is to be reset.
+ */
+void cpu_do_reset(CPU *cpu);

Better to sed-away the current cpu_reset() callers to cpu_reset_legacy() and then make this cpu_reset(). Otherwise, you're introducing new code that has the wrong usage which is never a good strategy.

include/qemu/cpu.h line 70

Quoted 8 lines
include/qemu/cpu.h new file +8 -0
+
+/**
+ * cpu_common_reset:
+ * @cpu: The CPU whose common state is to be reset.
+ *
+ * To be used by derived classes.
+ */
+void cpu_common_reset(CPU *cpu);

Make this static, initialize reset = cpu_common_reset in cpu_class_initfn, then in the derived class initfn, save the pointer to the parent reset function so it can be called later.

At some point, I had an:

ObjectClass *object_get_super_class(Object *obj);

Such that you could do:

CPUClass *super = CPU_CLASS(object_get_super_class(OBJECT(s)));

super->reset(CPU(s));

But my fear was that the subtle semantic of the object representing the class of your super class (which is different than a casted form of your class) would lead to confusion.

Regards,

Anthony Liguori

Quoted 66 lines
include/qemu/cpu.h new file +3 -0
+
+
+#endif
qom/Makefile +1 -0
index f33f0be..0a1c8e0 100644
@@ -1 +1,2 @@
  qom-y = object.o container.o
+qom-y += cpu.o
qom/cpu.c new file +50 -0
new file mode 100644
index 0000000..a60823f
@@ -0,0 +1,50 @@
+/*
+ * QEMU CPU model
+ *
+ * Copyright (c) 2012 SUSE LINUX Products GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see
+ *<http://www.gnu.org/licenses/old-licenses/gpl-2.0>
+ */
+
+#include "qemu/cpu.h"
+#include "qemu-common.h"
+
+void cpu_do_reset(CPU *cpu)
+{
+    CPUClass *klass = CPU_GET_CLASS(cpu);
+
+    if (klass->reset != NULL) {
+        (*klass->reset)(cpu);
+    }
+}
+
+void cpu_common_reset(CPU *cpu)
+{
+}
+
+static TypeInfo cpu_type_info = {
+    .name = TYPE_CPU,
+    .parent = TYPE_OBJECT,
+    .instance_size = sizeof(CPU),
+    .abstract = true,
+    .class_size = sizeof(CPUClass),
+};
+
+static void cpu_register_types(void)
+{
+    type_register_static(&cpu_type_info);
+}
+
+type_init(cpu_register_types)
#10 lore raw

Re: [Qemu-devel] [PATCH RFC v3 03/21] qom: Introduce CPU class

Quoted 11 lines · Anthony Liguori

include/qemu/cpu.h line 31

Quoted 5 lines · Andreas Färber
include/qemu/cpu.h new file +5 -0
+#define CPU(obj) OBJECT_CHECK(CPU, (obj), TYPE_CPU)
+#define CPU_CLASS(class) OBJECT_CLASS_CHECK(CPUClass, (class), TYPE_CPU)
+#define CPU_GET_CLASS(obj) OBJECT_GET_CLASS(CPUClass, (obj), TYPE_CPU)
+
+typedef struct CPU CPU;

If this doesn't result in a build error, then C is a worse language than I thought it was :-/

Quoted 2 lines

But we definitely shouldn't have a typename and macro name of the same thing and expect it to work...

The C standard says that function-like macros are only applied when the function-like
macro name is followed by a '(' as the next preprocessing token, so this isn't relying on any kind of gcc-specific behaviour.

Whether we *want* to do it is largely a style issue :-)

-- PMM

#11 lore raw

Re: [Qemu-devel] [PATCH RFC v3 03/21] qom: Introduce CPU class

In reply to Anthony Liguori

Am 06.02.2012 20:24, schrieb Anthony Liguori:

Quoted 12 lines · Andreas Färber

include/qemu/cpu.h line 70

Quoted 7 lines
include/qemu/cpu.h new file +7 -0
+/**
+ * cpu_common_reset:
+ * @cpu: The CPU whose common state is to be reset.
+ *
+ * To be used by derived classes.
+ */
+void cpu_common_reset(CPU *cpu);

Make this static, initialize reset = cpu_common_reset in cpu_class_initfn, then in the derived class initfn, save the pointer to the parent reset function so it can be called later.

I don't see how that would work. To initialize, e.g., the ARMCPUClass with additional class fields I'm overriding the .class_init. So in order to let CPUClass initialize the reset callback to its static one I'd need to make CPU's class_init function non-static so that I can call that from my derived class' class_init function, no?

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#12 lore raw

Re: [Qemu-devel] [PATCH RFC v3 03/21] qom: Introduce CPU class

Quoted 14 lines · Andreas Färber

Am 06.02.2012 20:24, schrieb Anthony Liguori:

Quoted 12 lines · Andreas Färber

include/qemu/cpu.h line 70

Quoted 7 lines
include/qemu/cpu.h new file +7 -0
+/**
+ * cpu_common_reset:
+ * @cpu: The CPU whose common state is to be reset.
+ *
+ * To be used by derived classes.
+ */
+void cpu_common_reset(CPU *cpu);

Make this static, initialize reset = cpu_common_reset in cpu_class_initfn, then in the derived class initfn, save the pointer to the parent reset function so it can be called later.

Quoted 2 lines

I don't see how that would work. To initialize, e.g., the ARMCPUClass with additional class fields I'm overriding the .class_init.

You're not overriding the class_init. The class init for a type is called when that class is initialized for the first time. See the documentation in object.h.

When class_init is called, the parent class type's class_init has already been called and the default values are set. So:

static void arm_cpu_reset(CPUCommon *cpu)
{
ARMCPU *s = ARM_CPU(cpu);
ARMCPUClass *ac = ARM_CPU_GET_CLASS(s);

// do arm specific reset

// call super class reset
ac->super_reset(cpu);
}

static void arm_cpu_class_initfn(ObjectClass *klass, void *data) {
CPUCommonClass *cc = CPU_COMMON_CLASS(klass); ARMCPUClass *ac = ARM_CPU_CLASS(klass);

// cc->reset was set in CPUCommonClass's class_init ac->super_reset = cc->reset;
cc->reset = arm_cpu_reset;
}

It's admittedly a little funky but this is the common idiom in gobject. I'm not sure there's a better way.

Regards,

Anthony Liguori

So in order

Quoted 6 lines

to let CPUClass initialize the reset callback to its static one I'd need to make CPU's class_init function non-static so that I can call that from my derived class' class_init function, no?

Andreas

#13 lore raw

RFC PATCH v3 4/21 target-arm: Introduce QOM CPU and use it for CPUID lookup

In reply to Andreas Färber

Create a CPU subclass, and register classes matching all CPU models except for "pxa270", which is an alias for "pxa270-a0".

Make arm_cpu_list() enumerate CPU subclasses.

Replace cpu_arm_find_by_name()'s string -> CPUID lookup by storing the CPUID in the class.
NB: CPUIDs were first introduced by Paul Brook in r1765 (2006).

Cc Anthony Liguori <[email protected]>
Cc Paul Brook <[email protected]>
Cc Peter Maydell <[email protected]>
---
 Makefile.target       |    1 +
 target-arm/cpu-core.h |   59 +++++++++++++++
 target-arm/cpu.c      |  190 +++++++++++++++++++++++++++++++++++++++++++++++++
 target-arm/cpu.h      |    1 -
 target-arm/helper.c   |   85 +++++++---------------
 5 files changed, 277 insertions(+), 59 deletions(-)
 create mode 100644 target-arm/cpu-core.h
 create mode 100644 target-arm/cpu.c
Makefile.target +1 -0
index 68481a3..5c139be 100644
@@ -80,6 +80,7 @@ endif
 libobj-$(TARGET_SPARC64) += vis_helper.o
 libobj-$(CONFIG_NEED_MMU) += mmu.o
 libobj-$(TARGET_ARM) += neon_helper.o iwmmxt_helper.o
+libobj-$(TARGET_ARM) += cpu.o
 ifeq ($(TARGET_BASE_ARCH), sparc)
 libobj-y += fop_helper.o cc_helper.o win_helper.o mmu_helper.o ldst_helper.o
 libobj-y += cpu_init.o
target-arm/cpu-core.h new file +59 -0

59 lines not on this page · raw message

target-arm/cpu.c new file +190 -0

190 lines not on this page · raw message

target-arm/cpu.h +0 -1
index 0d9b39c..5905ef2 100644
@@ -420,7 +420,6 @@ void cpu_arm_set_cp_io(CPUARMState *env, int cpnum,
 #define ARM_CPUID_PXA260      0x69052903
 #define ARM_CPUID_PXA261      0x69052d05
 #define ARM_CPUID_PXA262      0x69052d06
-#define ARM_CPUID_PXA270      0x69054110
 #define ARM_CPUID_PXA270_A0   0x69054110
 #define ARM_CPUID_PXA270_A1   0x69054111
 #define ARM_CPUID_PXA270_B0   0x69054112
target-arm/helper.c +27 -58

127 lines not on this page · raw message

Signature · 1 line
1.7.7
#14 lore raw

RFC PATCH v3 5/21 target-arm: Embed CPUARMState in QOM ARMCPU

In reply to Andreas Färber

We g_malloc0()'ed CPUARMState ourself, and exec.c's cpu_copy() runs through cpu_init() as well, so we are at liberty to supply the CPUState any way we see fit. Having CPUARMState as field in the QOM CPU allows both to access env from an ARMCPU object and to access the QOM Object and its ObjectClass from an env pointer, in ARM code for now.

The goal is to convert all CPUs to QOM and to use CPU objects in central places, especially once we have property support for Object. This will then allow to have TCG AREG0 point to target-specific fields where small immediate offsets are desired (as pointed out by rth) while allowing for common fields at known offsets from the base class.

Having the CPUID in ARMCPUClass, we can set it from the instance_init function. Same for cpu_model_str, which is now the QOM class name.

Make cpu_reset() call cpu_do_reset() and move most of its code to arm_cpu_reset().

Cc Anthony Liguori <[email protected]>
Cc Paul Brook <[email protected]>
Cc Peter Maydell <[email protected]>
Cc Richard Henderson <[email protected]>
---
 target-arm/cpu-core.h |   11 +++++++
 target-arm/cpu.c      |   78 +++++++++++++++++++++++++++++++++++++++++++++++++
 target-arm/helper.c   |   71 ++++----------------------------------------
 3 files changed, 96 insertions(+), 64 deletions(-)
target-arm/cpu-core.h +11 -0
index 3e8f046..4ba5ee0 100644
@@ -21,6 +21,7 @@
 #define QEMU_ARM_CPU_CORE_H
 
 #include "qemu/cpu.h"
+#include "cpu.h"
 
 #define TYPE_ARM_CPU "arm-cpu"
 
@@ -53,7 +54,17 @@ typedef struct ARMCPUClass {
 typedef struct ARMCPU {
     /*< private >*/
     CPU parent_obj;
+
+    /* TODO Inline this and split off common state */
+    CPUARMState env;
 } ARMCPU;
 
+static inline Object *arm_env_get_object(CPUARMState *env)
+{
+    return OBJECT((void *)(env) - offsetof(ARMCPU, env));
+}
+
+#define ENV_GET_OBJECT(e) arm_env_get_object(e)
+
 
 #endif
target-arm/cpu.c +78 -0

100 lines not on this page · raw message

target-arm/helper.c +7 -64

117 lines not on this page · raw message

Signature · 1 line
1.7.7
#15 lore raw

Re: [Qemu-devel] [PATCH RFC v3 05/21] target-arm: Embed CPUARMState in QOM ARMCPU

Quoted 46 lines · Andreas Färber

We g_malloc0()'ed CPUARMState ourself, and exec.c's cpu_copy() runs through cpu_init() as well, so we are at liberty to supply the CPUState any way we see fit. Having CPUARMState as field in the QOM CPU allows both to access env from an ARMCPU object and to access the QOM Object and its ObjectClass from an env pointer, in ARM code for now.

The goal is to convert all CPUs to QOM and to use CPU objects in central places, especially once we have property support for Object. This will then allow to have TCG AREG0 point to target-specific fields where small immediate offsets are desired (as pointed out by rth) while allowing for common fields at known offsets from the base class.

Having the CPUID in ARMCPUClass, we can set it from the instance_init function. Same for cpu_model_str, which is now the QOM class name.

Make cpu_reset() call cpu_do_reset() and move most of its code to arm_cpu_reset().

Cc Anthony Liguori<[email protected]>
Cc Paul Brook<[email protected]>
Cc Peter Maydell<[email protected]>
Cc Richard Henderson<[email protected]>
---
  target-arm/cpu-core.h |   11 +++++++
  target-arm/cpu.c      |   78 +++++++++++++++++++++++++++++++++++++++++++++++++
  target-arm/helper.c   |   71 ++++----------------------------------------
  3 files changed, 96 insertions(+), 64 deletions(-)
target-arm/cpu-core.h +2 -0
index 3e8f046..4ba5ee0 100644
@@ -21,6 +21,7 @@
  #define QEMU_ARM_CPU_CORE_H
 
  #include "qemu/cpu.h"
+#include "cpu.h"
 
  #define TYPE_ARM_CPU "arm-cpu"
 
@@ -53,7 +54,17 @@ typedef struct ARMCPUClass {
  typedef struct ARMCPU {
      /*<  private>*/
      CPU parent_obj;
+

target-arm/cpu-core.h typedef struct ARMCPUClass { · line 67

Quoted 10 lines
target-arm/cpu-core.h +8 -0
+    /* TODO Inline this and split off common state */
+    CPUARMState env;
  } ARMCPU;
 
+static inline Object *arm_env_get_object(CPUARMState *env)
+{
+    return OBJECT((void *)(env) - offsetof(ARMCPU, env));
+}
+
+#define ENV_GET_OBJECT(e) arm_env_get_object(e)

I'd prefer:

ARMCPU *arm_cpu_from_cpu_state(CPUState *env) {
return ARM_CPU(container_of(env, ARMCPU, env));
}

Regards,

Anthony Liguori

Quoted 236 lines
target-arm/cpu-core.h +0 -0
  #endif
target-arm/cpu.c +78 -0
index 9255a19..43231c9 100644
@@ -20,10 +20,75 @@
 
  #include "cpu-core.h"
  #include "qemu-common.h"
+#if !defined(CONFIG_USER_ONLY)
+#include "hw/loader.h"
+#endif
 
  static void arm_cpu_reset(CPU *c)
  {
+    ARMCPU *cpu = ARM_CPU(c);
+    CPUARMState *env =&cpu->env;
+    uint32_t id;
+    uint32_t tmp;
+
+    if (qemu_loglevel_mask(CPU_LOG_RESET)) {
+        qemu_log("CPU Reset (CPU %d)\n", env->cpu_index);
+        log_cpu_state(env, 0);
+    }
+
      cpu_common_reset(c);
+
+    id = env->cp15.c0_cpuid;
+    tmp = env->cp15.c15_config_base_address;
+    memset(env, 0, offsetof(CPUARMState, breakpoints));
+    env->cp15.c0_cpuid = id;
+    env->cp15.c15_config_base_address = tmp;
+
+#if defined(CONFIG_USER_ONLY)
+    env->uncached_cpsr = ARM_CPU_MODE_USR;
+    /* For user mode we must enable access to coprocessors */
+    env->vfp.xregs[ARM_VFP_FPEXC] = 1<<  30;
+    if (arm_feature(env, ARM_FEATURE_IWMMXT)) {
+        env->cp15.c15_cpar = 3;
+    } else if (arm_feature(env, ARM_FEATURE_XSCALE)) {
+        env->cp15.c15_cpar = 1;
+    }
+#else
+    /* SVC mode with interrupts disabled.  */
+    env->uncached_cpsr = ARM_CPU_MODE_SVC | CPSR_A | CPSR_F | CPSR_I;
+    /* On ARMv7-M the CPSR_I is the value of the PRIMASK register, and is
+       clear at reset.  Initial SP and PC are loaded from ROM.  */
+    if (IS_M(env)) {
+        uint32_t pc;
+        uint8_t *rom;
+        env->uncached_cpsr&= ~CPSR_I;
+        rom = rom_ptr(0);
+        if (rom) {
+            /* We should really use ldl_phys here, in case the guest
+               modified flash and reset itself.  However images
+               loaded via -kernel have not been copied yet, so load the
+               values directly from there.  */
+            env->regs[13] = ldl_p(rom);
+            pc = ldl_p(rom + 4);
+            env->thumb = pc&  1;
+            env->regs[15] = pc&  ~1;
+        }
+    }
+    env->vfp.xregs[ARM_VFP_FPEXC] = 0;
+    env->cp15.c2_base_mask = 0xffffc000u;
+    /* v7 performance monitor control register: same implementor
+     * field as main ID register, and we implement no event counters.
+     */
+    env->cp15.c9_pmcr = (id&  0xff000000);
+#endif
+    set_flush_to_zero(1,&env->vfp.standard_fp_status);
+    set_flush_inputs_to_zero(1,&env->vfp.standard_fp_status);
+    set_default_nan_mode(1,&env->vfp.standard_fp_status);
+    set_float_detect_tininess(float_tininess_before_rounding,
+&env->vfp.fp_status);
+    set_float_detect_tininess(float_tininess_before_rounding,
+&env->vfp.standard_fp_status);
+    tlb_flush(env, 1);
  }
 
  /* CPU models */
@@ -144,6 +209,18 @@ static const ARMCPUInfo arm_cpus[] = {
      },
  };
 
+static void arm_cpu_initfn(Object *obj)
+{
+    ARMCPU *cpu = ARM_CPU(obj);
+    ARMCPUClass *cpu_class = ARM_CPU_GET_CLASS(obj);
+
+    memset(&cpu->env, 0, sizeof(CPUARMState));
+    cpu_exec_init(&cpu->env);
+
+    cpu->env.cpu_model_str = object_get_typename(obj);
+    cpu->env.cp15.c0_cpuid = cpu_class->cp15.c0_cpuid;
+}
+
  static void arm_cpu_class_init(ObjectClass *klass, void *data)
  {
      ARMCPUClass *k = ARM_CPU_CLASS(klass);
@@ -161,6 +238,7 @@ static void cpu_register(const ARMCPUInfo *info)
          .name = info->name,
          .parent = TYPE_ARM_CPU,
          .instance_size = sizeof(ARMCPU),
+        .instance_init = arm_cpu_initfn,
          .class_size = sizeof(ARMCPUClass),
          .class_init = arm_cpu_class_init,
          .class_data = (void *)info,
target-arm/helper.c +7 -64
index d8425db..c5ba7fd 100644
@@ -7,9 +7,6 @@
  #include "helper.h"
  #include "qemu-common.h"
  #include "host-utils.h"
-#if !defined(CONFIG_USER_ONLY)
-#include "hw/loader.h"
-#endif
  #include "sysemu.h"
  #include "cpu-core.h"
 
@@ -59,7 +56,6 @@ static inline void set_feature(CPUARMState *env, int feature)
 
  static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
  {
-    env->cp15.c0_cpuid = id;
      switch (id) {
      case ARM_CPUID_ARM926:
          set_feature(env, ARM_FEATURE_V5);
@@ -285,64 +281,12 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
  void cpu_reset(CPUARMState *env)
  {
      uint32_t id;
-    uint32_t tmp = 0;
 
-    if (qemu_loglevel_mask(CPU_LOG_RESET)) {
-        qemu_log("CPU Reset (CPU %d)\n", env->cpu_index);
-        log_cpu_state(env, 0);
-    }
+    cpu_do_reset(CPU(ENV_GET_OBJECT(env)));
 
      id = env->cp15.c0_cpuid;
-    tmp = env->cp15.c15_config_base_address;
-    memset(env, 0, offsetof(CPUARMState, breakpoints));
      if (id)
          cpu_reset_model_id(env, id);
-    env->cp15.c15_config_base_address = tmp;
-#if defined (CONFIG_USER_ONLY)
-    env->uncached_cpsr = ARM_CPU_MODE_USR;
-    /* For user mode we must enable access to coprocessors */
-    env->vfp.xregs[ARM_VFP_FPEXC] = 1<<  30;
-    if (arm_feature(env, ARM_FEATURE_IWMMXT)) {
-        env->cp15.c15_cpar = 3;
-    } else if (arm_feature(env, ARM_FEATURE_XSCALE)) {
-        env->cp15.c15_cpar = 1;
-    }
-#else
-    /* SVC mode with interrupts disabled.  */
-    env->uncached_cpsr = ARM_CPU_MODE_SVC | CPSR_A | CPSR_F | CPSR_I;
-    /* On ARMv7-M the CPSR_I is the value of the PRIMASK register, and is
-       clear at reset.  Initial SP and PC are loaded from ROM.  */
-    if (IS_M(env)) {
-        uint32_t pc;
-        uint8_t *rom;
-        env->uncached_cpsr&= ~CPSR_I;
-        rom = rom_ptr(0);
-        if (rom) {
-            /* We should really use ldl_phys here, in case the guest
-               modified flash and reset itself.  However images
-               loaded via -kernel have not been copied yet, so load the
-               values directly from there.  */
-            env->regs[13] = ldl_p(rom);
-            pc = ldl_p(rom + 4);
-            env->thumb = pc&  1;
-            env->regs[15] = pc&  ~1;
-        }
-    }
-    env->vfp.xregs[ARM_VFP_FPEXC] = 0;
-    env->cp15.c2_base_mask = 0xffffc000u;
-    /* v7 performance monitor control register: same implementor
-     * field as main ID register, and we implement no event counters.
-     */
-    env->cp15.c9_pmcr = (id&  0xff000000);
-#endif
-    set_flush_to_zero(1,&env->vfp.standard_fp_status);
-    set_flush_inputs_to_zero(1,&env->vfp.standard_fp_status);
-    set_default_nan_mode(1,&env->vfp.standard_fp_status);
-    set_float_detect_tininess(float_tininess_before_rounding,
-&env->vfp.fp_status);
-    set_float_detect_tininess(float_tininess_before_rounding,
-&env->vfp.standard_fp_status);
-    tlb_flush(env, 1);
  }
 
  static int vfp_gdb_get_reg(CPUState *env, uint8_t *buf, int reg)
@@ -400,7 +344,7 @@ static int vfp_gdb_set_reg(CPUState *env, uint8_t *buf, int reg)
  CPUARMState *cpu_arm_init(const char *cpu_model)
  {
      ObjectClass *klass;
-    ARMCPUClass *cpu_class;
+    ARMCPU *cpu;
      CPUARMState *env;
      static int inited = 0;
 
@@ -413,16 +357,14 @@ CPUARMState *cpu_arm_init(const char *cpu_model)
      if (klass == NULL) {
          return NULL;
      }
-    cpu_class = ARM_CPU_CLASS(klass);
-    env = g_malloc0(sizeof(CPUARMState));
-    cpu_exec_init(env);
+    cpu = ARM_CPU(object_new(cpu_model));
+    env =&cpu->env;
+
      if (tcg_enabled()&&  !inited) {
          inited = 1;
          arm_translate_init();
      }
 
-    env->cpu_model_str = cpu_model;
-    env->cp15.c0_cpuid = cpu_class->cp15.c0_cpuid;
      cpu_reset(env);
      if (arm_feature(env, ARM_FEATURE_NEON)) {
          gdb_register_coprocessor(env, vfp_gdb_get_reg, vfp_gdb_set_reg,
@@ -464,7 +406,8 @@ void arm_cpu_list(FILE *f, fprintf_function cpu_fprintf)
 
  void cpu_arm_close(CPUARMState *env)
  {
-    g_free(env);
+    Object *obj = ENV_GET_OBJECT(env);
+    object_delete(obj);
  }
 
  static int bad_mode_switch(CPUState *env, int mode)
#16 lore raw

Re: [Qemu-devel] [PATCH RFC v3 05/21] target-arm: Embed CPUARMState in QOM ARMCPU

Am 07.02.2012 00:00, schrieb Anthony Liguori:

Quoted 10 lines · Andreas Färber

target-arm/cpu-core.h typedef struct ARMCPUClass { · line 67

Quoted 6 lines
target-arm/cpu-core.h +6 -0
+static inline Object *arm_env_get_object(CPUARMState *env)
+{
+    return OBJECT((void *)(env) - offsetof(ARMCPU, env));
+}
+
+#define ENV_GET_OBJECT(e) arm_env_get_object(e)

I'd prefer:

Quoted 4 lines

ARMCPU *arm_cpu_from_cpu_state(CPUState *env)

{
   return ARM_CPU(container_of(env, ARMCPU, env));
}

container_of() is a nice suggestion. However I deliberately decided against ARMCPU to be able to use it from common code; CPU would work though.

e.g.
#ifdef ENV_GET_OBJECT
// new code
#else
// legacy code
#endif

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#17 lore raw

RFC PATCH v3 6/21 target-arm: Prepare model-specific class_init function

In reply to Andreas Färber

This allows to share initialization between CPU models.

---
 target-arm/cpu.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
target-arm/cpu.c +5 -0
index 43231c9..b794ec1 100644
@@ -96,6 +96,7 @@ static void arm_cpu_reset(CPU *c)
 typedef struct ARMCPUInfo {
     const char *name;
     uint32_t id;
+    void (*class_init)(ARMCPUClass *klass, const struct ARMCPUInfo *info);
 } ARMCPUInfo;
 
 static const ARMCPUInfo arm_cpus[] = {
@@ -230,6 +231,10 @@ static void arm_cpu_class_init(ObjectClass *klass, void *data)
     cpu_class->reset = arm_cpu_reset;
 
     k->cp15.c0_cpuid = info->id;
+
+    if (info->class_init != NULL) {
+        (*info->class_init)(k, info);
+    }
 }
 
 static void cpu_register(const ARMCPUInfo *info)
Signature · 1 line
1.7.7
#18 lore raw

Re: [Qemu-devel] [PATCH RFC v3 06/21] target-arm: Prepare model-specific class_init function

Quoted 12 lines · Andreas Färber

This allows to share initialization between CPU models.

---
  target-arm/cpu.c |    5 +++++
  1 files changed, 5 insertions(+), 0 deletions(-)
target-arm/cpu.c +0 -0
index 43231c9..b794ec1 100644

target-arm/cpu.c static void arm_cpu_reset(CPU *c) · line 100

Quoted 5 lines
target-arm/cpu.c +1 -0
@@ -96,6 +96,7 @@ static void arm_cpu_reset(CPU *c)
  typedef struct ARMCPUInfo {
      const char *name;
      uint32_t id;
+    void (*class_init)(ARMCPUClass *klass, const struct ARMCPUInfo *info);
  } ARMCPUInfo;

So could you do:

TypeInfo arm_cpus[] = {

   {
	.name = "arm-cpu-model",
        .parent = TYPE_ARM_CPU,
        .class_data = (void *)(intptr_t)0x2342342,
        .class_init = arm_generic_init,

}

It's roughly the same code but then there isn't redirection. You can do this in general by having something like:

.class_data = (SpecialInfo[]){ .id = 0x23423423 },

Regards,

Anthony Liguori

Quoted 13 lines
target-arm/cpu.c +4 -0
  static const ARMCPUInfo arm_cpus[] = {
@@ -230,6 +231,10 @@ static void arm_cpu_class_init(ObjectClass *klass, void *data)
      cpu_class->reset = arm_cpu_reset;
 
      k->cp15.c0_cpuid = info->id;
+
+    if (info->class_init != NULL) {
+        (*info->class_init)(k, info);
+    }
  }
 
  static void cpu_register(const ARMCPUInfo *info)
#19 lore raw

Re: [Qemu-devel] [PATCH RFC v3 06/21] target-arm: Prepare model-specific class_init function

Am 07.02.2012 00:03, schrieb Anthony Liguori:

Quoted 30 lines · Andreas Färber
Quoted 12 lines

This allows to share initialization between CPU models.

---
  target-arm/cpu.c |    5 +++++
  1 files changed, 5 insertions(+), 0 deletions(-)
target-arm/cpu.c +0 -0
index 43231c9..b794ec1 100644

target-arm/cpu.c static void arm_cpu_reset(CPU *c) · line 101

Quoted 6 lines
target-arm/cpu.c +1 -0
@@ -96,6 +96,7 @@ static void arm_cpu_reset(CPU *c)
  typedef struct ARMCPUInfo {
      const char *name;
      uint32_t id;
+    void (*class_init)(ARMCPUClass *klass, const struct ARMCPUInfo
 *info);
  } ARMCPUInfo;

So could you do:

TypeInfo arm_cpus[] = {
   {
    .name = "arm-cpu-model",
        .parent = TYPE_ARM_CPU,
        .class_data = (void *)(intptr_t)0x2342342,
        .class_init = arm_generic_init,
   }
Quoted 4 lines

It's roughly the same code but then there isn't redirection. You can do this in general by having something like:

.class_data = (SpecialInfo[]){ .id = 0x23423423 },

Have you reviewed the users of this? More fields are being added, and the specific users of this facility initialize fields not shared by many CPUs so I wanted to keep ARMCPUInfo small. The shared fields are already being initialized by arm_cpu_class_init() via .class_data.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#20 lore raw

RFC PATCH v3 7/21 target-arm: Overwrite reset handler for ti925t

In reply to Andreas Färber

The OMAPCP feature allows to switch between TI915T and TI925T via cp15 c15_ticonfig register. Move reset into ti925t-specific callback.

---
 target-arm/cpu.c    |   18 ++++++++++++++++++
 target-arm/helper.c |    1 -
 2 files changed, 18 insertions(+), 1 deletions(-)
target-arm/cpu.c +18 -0
index b794ec1..a6dbad3 100644
@@ -99,6 +99,23 @@ typedef struct ARMCPUInfo {
     void (*class_init)(ARMCPUClass *klass, const struct ARMCPUInfo *info);
 } ARMCPUInfo;
 
+static void ti925t_reset(CPU *c)
+{
+    ARMCPU *cpu = ARM_CPU(c);
+    CPUARMState *env = &cpu->env;
+
+    arm_cpu_reset(c);
+
+    env->cp15.c0_cpuid = ARM_CPUID_TI925T; /* Depends on wiring. */
+}
+
+static void ti925t_class_init(ARMCPUClass *klass, const ARMCPUInfo *info)
+{
+    CPUClass *cpu_class = CPU_CLASS(klass);
+
+    cpu_class->reset = ti925t_reset;
+}
+
 static const ARMCPUInfo arm_cpus[] = {
     {
         .name = "arm926",
@@ -151,6 +168,7 @@ static const ARMCPUInfo arm_cpus[] = {
     {
         .name = "ti925t",
         .id = 0x54029252,
+        .class_init = ti925t_class_init,
     },
     {
         .name = "sa1100",
target-arm/helper.c +0 -1
index c5ba7fd..e877c3f 100644
@@ -201,7 +201,6 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
     case ARM_CPUID_TI925T:
         set_feature(env, ARM_FEATURE_V4T);
         set_feature(env, ARM_FEATURE_OMAPCP);
-        env->cp15.c0_cpuid = ARM_CPUID_TI925T; /* Depends on wiring.  */
         env->cp15.c0_cachetype = 0x5109149;
         env->cp15.c1_sys = 0x00000070;
         env->cp15.c15_i_max = 0x000;
Signature · 1 line
1.7.7
#21 lore raw

Re: [Qemu-devel] [PATCH RFC v3 07/21] target-arm: Overwrite reset handler for ti925t

Quoted 17 lines · Andreas Färber

The OMAPCP feature allows to switch between TI915T and TI925T via cp15 c15_ticonfig register. Move reset into ti925t-specific callback.

---
 target-arm/cpu.c    |   18 ++++++++++++++++++
 target-arm/helper.c |    1 -

 2 files changed, 18 insertions(+), 1 deletions(-)
target-arm/cpu.c +0 -0
index b794ec1..a6dbad3 100644
@@ -99,6 +99,23 @@ typedef struct ARMCPUInfo {
     void (*class_init)(ARMCPUClass *klass, const struct ARMCPUInfo *info);
  } ARMCPUInfo;

target-arm/cpu.c typedef struct ARMCPUInfo { · line 110

Quoted 10 lines
target-arm/cpu.c +9 -0
 
+static void ti925t_reset(CPU *c)
+{
+    ARMCPU *cpu = ARM_CPU(c);
+    CPUARMState *env = &cpu->env;
+
+    arm_cpu_reset(c);
+
+    env->cp15.c0_cpuid = ARM_CPUID_TI925T; /* Depends on wiring. */
+}

If/when I finish my cp15 cleanup series this will become unnecessary, because c0_cpuid will just be another cp15 register among many which the CPU defines in its init function somewhere (and the cp15 register struct will include "reset value for this cp15 register" and arm_cpu_reset() will just enumerate them all and set them to their reset values).

-- PMM

#22 lore raw

RFC PATCH v3 8/21 target-arm: Move CPU feature flags out of CPUState

In reply to Andreas Färber

The internal CPU feature flags were only ever set in cpu_reset_model_id(). Therefore move their initialization into ARMCPUClass. We might want to tweak them in the future though (e.g., -cpu cortex-r4,+fpu), so keep a copy in ARMCPU. This in turn means we need to infer features for both ARMCPUClass and ARMCPU, so move feature inference to arm_infer_features() and use macros to simplify it.

Since cpu.h defines ARMCPUState, which has been incorporated into ARMCPU, and tries to use arm_feature() in cpu_get_tb_cpu_state(), move arm_feature() to cpu-core.h and add a forward declaration.

---
 target-arm/cpu-core.h |   12 ++++
 target-arm/cpu.c      |  159 +++++++++++++++++++++++++++++++++++++++++++++++++
 target-arm/cpu.h      |    9 +--
 target-arm/helper.c   |   95 -----------------------------
 target-arm/machine.c  |    6 +-
 5 files changed, 177 insertions(+), 104 deletions(-)
target-arm/cpu-core.h +12 -0
index 4ba5ee0..9f090a8 100644
@@ -44,6 +44,9 @@ typedef struct ARMCPUClass {
     struct {
         uint32_t c0_cpuid;
     } cp15;
+
+    /* Internal CPU feature flags. */
+    uint32_t features;
 } ARMCPUClass;
 
 /**
@@ -55,6 +58,9 @@ typedef struct ARMCPU {
     /*< private >*/
     CPU parent_obj;
 
+    /* Internal CPU feature flags. */
+    uint32_t features;
+
     /* TODO Inline this and split off common state */
     CPUARMState env;
 } ARMCPU;
@@ -66,5 +72,11 @@ static inline Object *arm_env_get_object(CPUARMState *env)
 
 #define ENV_GET_OBJECT(e) arm_env_get_object(e)
 
+static inline int arm_feature(CPUARMState *env, int feature)
+{
+    ARMCPU *cpu = ARM_CPU(ENV_GET_OBJECT(env));
+    return (cpu->features & (1u << feature)) != 0;
+}
+
 
 #endif
target-arm/cpu.c +159 -0

302 lines not on this page · raw message

target-arm/cpu.h +2 -7
index 5905ef2..bf8c911 100644
@@ -170,9 +170,6 @@ typedef struct CPUARMState {
     uint32_t teecr;
     uint32_t teehbr;
 
-    /* Internal CPU feature flags.  */
-    uint32_t features;
-
     /* VFP coprocessor state.  */
     struct {
         float64 regs[32];
@@ -385,10 +382,7 @@ enum arm_features {
     ARM_FEATURE_GENERIC_TIMER,
 };
 
-static inline int arm_feature(CPUARMState *env, int feature)
-{
-    return (env->features & (1u << feature)) != 0;
-}
+static inline int arm_feature(CPUARMState *env, int feature);
 
 void arm_cpu_list(FILE *f, fprintf_function cpu_fprintf);
 
@@ -475,6 +469,7 @@ static inline void cpu_clone_regs(CPUState *env, target_ulong newsp)
 #endif
 
 #include "cpu-all.h"
+#include "cpu-core.h"
 
 /* Bit usage in the TB flags field: */
 #define ARM_TBFLAG_THUMB_SHIFT      0
target-arm/helper.c +0 -95

192 lines not on this page · raw message

target-arm/machine.c +4 -2
index f66b8df..c93fded 100644
@@ -5,6 +5,7 @@ void cpu_save(QEMUFile *f, void *opaque)
 {
     int i;
     CPUARMState *env = (CPUARMState *)opaque;
+    ARMCPU *cpu = ARM_CPU(ENV_GET_OBJECT(env));
 
     for (i = 0; i < 16; i++) {
         qemu_put_be32(f, env->regs[i]);
@@ -61,7 +62,7 @@ void cpu_save(QEMUFile *f, void *opaque)
     qemu_put_be32(f, env->cp15.c15_diagnostic);
     qemu_put_be32(f, env->cp15.c15_power_diagnostic);
 
-    qemu_put_be32(f, env->features);
+    qemu_put_be32(f, cpu->features);
 
     if (arm_feature(env, ARM_FEATURE_VFP)) {
         for (i = 0;  i < 16; i++) {
@@ -115,6 +116,7 @@ void cpu_save(QEMUFile *f, void *opaque)
 int cpu_load(QEMUFile *f, void *opaque, int version_id)
 {
     CPUARMState *env = (CPUARMState *)opaque;
+    ARMCPU *cpu = ARM_CPU(ENV_GET_OBJECT(env));
     int i;
     uint32_t val;
 
@@ -179,7 +181,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)
     env->cp15.c15_diagnostic = qemu_get_be32(f);
     env->cp15.c15_power_diagnostic = qemu_get_be32(f);
 
-    env->features = qemu_get_be32(f);
+    cpu->features = qemu_get_be32(f);
 
     if (arm_feature(env, ARM_FEATURE_VFP)) {
         for (i = 0;  i < 16; i++) {
Signature · 1 line
1.7.7
#23 lore raw

Re: [Qemu-devel] [PATCH RFC v3 08/21] target-arm: Move CPU feature flags out of CPUState

Quoted 13 lines · Andreas Färber
target-arm/cpu.c +4 -0
+static void sa11xx_class_init(ARMCPUClass *k, const ARMCPUInfo *info)
+{
+    set_class_feature(k, ARM_FEATURE_STRONGARM);
+}

 static const ARMCPUInfo arm_cpus[] = {
    {
        .name = "arm926",
        .id = 0x41069265,
+        .features = ARM_FEATURE(V5) |
+                    ARM_FEATURE(VFP),
    },

Quoted 5 lines

    {
        .name = "sa1100",
        .id = 0x4401A11B,
+        .class_init = sa11xx_class_init,
    },

So why are we handling some of these feature bits by setting them in .features, and some of them via a .class_init which sets the feature bit?

-- PMM

#24 lore raw

Re: [Qemu-devel] [PATCH RFC v3 08/21] target-arm: Move CPU feature flags out of CPUState

Am 07.02.2012 18:28, schrieb Peter Maydell:

Quoted 20 lines · Andreas Färber
Quoted 8 lines
target-arm/cpu.c +4 -0
+static void sa11xx_class_init(ARMCPUClass *k, const ARMCPUInfo *info)
+{
+    set_class_feature(k, ARM_FEATURE_STRONGARM);
+}
 
 static const ARMCPUInfo arm_cpus[] = {
    {
        .name = "arm926",

target-arm/cpu.c static void ti925t_class_init(ARMCPUClass *klass, const ARMCPUInfo *info) · line 223

Quoted 10 lines
target-arm/cpu.c +3 -0
        .id = 0x41069265,
+        .features = ARM_FEATURE(V5) |
+                    ARM_FEATURE(VFP),
    },
 
    {
        .name = "sa1100",
        .id = 0x4401A11B,
+        .class_init = sa11xx_class_init,
    },
Quoted 3 lines

So why are we handling some of these feature bits by setting them in .features, and some of them via a .class_init which sets the feature bit?

To avoid duplication. This corresponds to fall-throughs in the switch.

Eventually as suggested by you we would get rid of some of these duplicate models and let the user (or an alias-like compatibility mechanism) set the desired revision numbers on one base class via QOM properties. Then those class_inits would no longer be needed.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#25 lore raw

RFC PATCH v3 9/21 target-arm: No longer abort on unhandled CPUIDs on reset

In reply to Andreas Färber

Having moved the reset code for some CPUs to class_init, we can drop some of the cases in the switch.

---
 target-arm/cpu.h    |    2 --
 target-arm/helper.c |    5 -----
 2 files changed, 0 insertions(+), 7 deletions(-)
target-arm/cpu.h +0 -2
index bf8c911..6731256 100644
@@ -427,8 +427,6 @@ void cpu_arm_set_cp_io(CPUARMState *env, int cpnum,
 #define ARM_CPUID_CORTEXA8    0x410fc080
 #define ARM_CPUID_CORTEXA9    0x410fc090
 #define ARM_CPUID_CORTEXA15   0x412fc0f1
-#define ARM_CPUID_CORTEXM3    0x410fc231
-#define ARM_CPUID_ANY         0xffffffff
 
 #if defined(CONFIG_USER_ONLY)
 #define TARGET_PAGE_BITS 12
target-arm/helper.c +0 -5
index 4fd8ba8..67e18cc 100644
@@ -141,10 +141,6 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
         env->cp15.c0_ccsid[2] = 0x711fe07a; /* 4096K L2 unified cache */
         env->cp15.c1_sys = 0x00c50078;
         break;
-    case ARM_CPUID_CORTEXM3:
-        break;
-    case ARM_CPUID_ANY: /* For userspace emulation.  */
-        break;
     case ARM_CPUID_TI915T:
     case ARM_CPUID_TI925T:
         env->cp15.c0_cachetype = 0x5109149;
@@ -177,7 +173,6 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
         env->cp15.c1_sys = 0x00000070;
         break;
     default:
-        cpu_abort(env, "Bad CPU ID: %x\n", id);
         break;
     }
 }
Signature · 1 line
1.7.7
#26 lore raw

RFC PATCH v3 10/21 target-arm: Store cp15 c0_c1 and c0_c2 in ARMCPUClass

In reply to Andreas Färber

For now set them in the reset function.

---
 target-arm/cpu-core.h |    2 +
 target-arm/cpu.c      |   64 +++++++++++++++++++++++++++++++++++++++++++++++++
 target-arm/helper.c   |   51 ---------------------------------------
 3 files changed, 66 insertions(+), 51 deletions(-)
target-arm/cpu-core.h +2 -0
index 9f090a8..bb59f8d 100644
@@ -43,6 +43,8 @@ typedef struct ARMCPUClass {
 
     struct {
         uint32_t c0_cpuid;
+        uint32_t c0_c1[8];
+        uint32_t c0_c2[8];
     } cp15;
 
     /* Internal CPU feature flags. */
target-arm/cpu.c +64 -0

130 lines not on this page · raw message

target-arm/helper.c +0 -51

93 lines not on this page · raw message

Signature · 1 line
1.7.7
#27 lore raw

RFC PATCH v3 11/21 target-arm: Store cp15 c0_cachetype register in ARMCPUClass

In reply to Andreas Färber
---
 target-arm/cpu-core.h |    1 +
 target-arm/cpu.c      |   18 ++++++++++++++++++
 target-arm/helper.c   |   12 ------------
 3 files changed, 19 insertions(+), 12 deletions(-)
target-arm/cpu-core.h +1 -0
index bb59f8d..1d5adc8 100644
@@ -43,6 +43,7 @@ typedef struct ARMCPUClass {
 
     struct {
         uint32_t c0_cpuid;
+        uint32_t c0_cachetype;
         uint32_t c0_c1[8];
         uint32_t c0_c2[8];
     } cp15;
target-arm/cpu.c +18 -0
index 909eb1a..fe34b31 100644
@@ -46,6 +46,7 @@ static void arm_cpu_reset(CPU *c)
     env->cp15.c15_config_base_address = tmp;
 
     /* TODO Move these into arm_cpu_initfn() once no longer zeroed above. */
+    env->cp15.c0_cachetype = cpu_class->cp15.c0_cachetype;
     memcpy(env->cp15.c0_c1, cpu_class->cp15.c0_c1, 8 * sizeof(uint32_t));
     memcpy(env->cp15.c0_c2, cpu_class->cp15.c0_c2, 8 * sizeof(uint32_t));
 
@@ -164,6 +165,7 @@ static inline void unset_class_feature(ARMCPUClass *klass, int feature)
 typedef struct ARMCPUInfo {
     const char *name;
     uint32_t id;
+    uint32_t cp15_c0_cachetype;
     uint32_t cp15_c0_c1[8];
     uint32_t cp15_c0_c2[8];
     uint32_t features;
@@ -183,6 +185,7 @@ static void arm1136_r0_class_init(ARMCPUClass *k, const ARMCPUInfo *info)
      * for 1136_r2 (in particular r0p2 does not actually implement most
      * of the ID registers).
      */
+    k->cp15.c0_cachetype = r1_class->cp15.c0_cachetype;
     memcpy(k->cp15.c0_c1, r1_class->cp15.c0_c1, 8 * sizeof(uint32_t));
     memcpy(k->cp15.c0_c2, r1_class->cp15.c0_c2, 8 * sizeof(uint32_t));
 }
@@ -211,12 +214,16 @@ static void sa11xx_class_init(ARMCPUClass *k, const ARMCPUInfo *info)
 
 static void pxa25x_class_init(ARMCPUClass *k, const ARMCPUInfo *info)
 {
+    k->cp15.c0_cachetype = 0xd172172;
+
     set_class_feature(k, ARM_FEATURE_V5);
     set_class_feature(k, ARM_FEATURE_XSCALE);
 }
 
 static void pxa270_class_init(ARMCPUClass *k, const ARMCPUInfo *info)
 {
+    k->cp15.c0_cachetype = 0xd172172;
+
     set_class_feature(k, ARM_FEATURE_V5);
     set_class_feature(k, ARM_FEATURE_XSCALE);
     set_class_feature(k, ARM_FEATURE_IWMMXT);
@@ -226,18 +233,21 @@ static const ARMCPUInfo arm_cpus[] = {
     {
         .name = "arm926",
         .id = 0x41069265,
+        .cp15_c0_cachetype = 0x1dd20d2,
         .features = ARM_FEATURE(V5) |
                     ARM_FEATURE(VFP),
     },
     {
         .name = "arm946",
         .id = 0x41059461,
+        .cp15_c0_cachetype = 0x0f004006,
         .features = ARM_FEATURE(V5) |
                     ARM_FEATURE(MPU),
     },
     {
         .name = "arm1026",
         .id = 0x4106a262,
+        .cp15_c0_cachetype = 0x1dd20d2,
         .features = ARM_FEATURE(V5) |
                     ARM_FEATURE(VFP) |
                     ARM_FEATURE(AUXCR),
@@ -254,6 +264,7 @@ static const ARMCPUInfo arm_cpus[] = {
     {
         .name = "arm1136",
         .id = 0x4117b363,
+        .cp15_c0_cachetype = 0x1dd20d2,
         .cp15_c0_c1 = {
             0x111, 0x1, 0x2, 0x3,
             0x01130003, 0x10030302, 0x01222110, 0
@@ -268,6 +279,7 @@ static const ARMCPUInfo arm_cpus[] = {
     {
         .name = "arm1176",
         .id = 0x410fb767,
+        .cp15_c0_cachetype = 0x1dd20d2,
         .cp15_c0_c1 = {
             0x111, 0x11, 0x33, 0,
             0x01130003, 0x10030302, 0x01222100, 0
@@ -283,6 +295,7 @@ static const ARMCPUInfo arm_cpus[] = {
     {
         .name = "arm11mpcore",
         .id = 0x410fb022,
+        .cp15_c0_cachetype = 0x1dd20d2,
         .cp15_c0_c1 = {
             0x111, 0x1, 0, 0x2,
             0x01100103, 0x10020302, 0x01222000, 0
@@ -304,6 +317,7 @@ static const ARMCPUInfo arm_cpus[] = {
     {
         .name = "cortex-a8",
         .id = 0x410fc080,
+        .cp15_c0_cachetype = 0x82048004,
         .cp15_c0_c1 = {
             0x1031, 0x11, 0x400, 0,
             0x31100003, 0x20000000, 0x01202000, 0x11
@@ -320,6 +334,7 @@ static const ARMCPUInfo arm_cpus[] = {
     {
         .name = "cortex-a9",
         .id = 0x410fc090,
+        .cp15_c0_cachetype = 0x80038003,
         .cp15_c0_c1 = {
             0x1031, 0x11, 0x000, 0,
             0x00100103, 0x20000000, 0x01230000, 0x00002111
@@ -342,6 +357,7 @@ static const ARMCPUInfo arm_cpus[] = {
     {
         .name = "cortex-a15",
         .id = 0x412fc0f1,
+        .cp15_c0_cachetype = 0x8444c004,
         .cp15_c0_c1 = {
             0x00001131, 0x00011011, 0x02010555, 0x00000000,
             0x10201105, 0x20000000, 0x01240000, 0x02102211
@@ -362,6 +378,7 @@ static const ARMCPUInfo arm_cpus[] = {
     {
         .name = "ti925t",
         .id = 0x54029252,
+        .cp15_c0_cachetype = 0x5109149,
         .features = ARM_FEATURE(V4T) |
                     ARM_FEATURE(OMAPCP),
         .class_init = ti925t_class_init,
@@ -467,6 +484,7 @@ static void arm_cpu_class_init(ObjectClass *klass, void *data)
     cpu_class->reset = arm_cpu_reset;
 
     k->cp15.c0_cpuid = info->id;
+    k->cp15.c0_cachetype = info->cp15_c0_cachetype;
     memcpy(k->cp15.c0_c1, info->cp15_c0_c1, 8 * sizeof(uint32_t));
     memcpy(k->cp15.c0_c2, info->cp15_c0_c2, 8 * sizeof(uint32_t));
     k->features = info->features;
target-arm/helper.c +0 -12
index 2af8df4..9a4afad 100644
@@ -15,16 +15,13 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
     switch (id) {
     case ARM_CPUID_ARM926:
         env->vfp.xregs[ARM_VFP_FPSID] = 0x41011090;
-        env->cp15.c0_cachetype = 0x1dd20d2;
         env->cp15.c1_sys = 0x00090078;
         break;
     case ARM_CPUID_ARM946:
-        env->cp15.c0_cachetype = 0x0f004006;
         env->cp15.c1_sys = 0x00000078;
         break;
     case ARM_CPUID_ARM1026:
         env->vfp.xregs[ARM_VFP_FPSID] = 0x410110a0;
-        env->cp15.c0_cachetype = 0x1dd20d2;
         env->cp15.c1_sys = 0x00090078;
         break;
     case ARM_CPUID_ARM1136:
@@ -42,27 +39,23 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
         env->vfp.xregs[ARM_VFP_FPSID] = 0x410120b4;
         env->vfp.xregs[ARM_VFP_MVFR0] = 0x11111111;
         env->vfp.xregs[ARM_VFP_MVFR1] = 0x00000000;
-        env->cp15.c0_cachetype = 0x1dd20d2;
         env->cp15.c1_sys = 0x00050078;
         break;
     case ARM_CPUID_ARM1176:
         env->vfp.xregs[ARM_VFP_FPSID] = 0x410120b5;
         env->vfp.xregs[ARM_VFP_MVFR0] = 0x11111111;
         env->vfp.xregs[ARM_VFP_MVFR1] = 0x00000000;
-        env->cp15.c0_cachetype = 0x1dd20d2;
         env->cp15.c1_sys = 0x00050078;
         break;
     case ARM_CPUID_ARM11MPCORE:
         env->vfp.xregs[ARM_VFP_FPSID] = 0x410120b4;
         env->vfp.xregs[ARM_VFP_MVFR0] = 0x11111111;
         env->vfp.xregs[ARM_VFP_MVFR1] = 0x00000000;
-        env->cp15.c0_cachetype = 0x1dd20d2;
         break;
     case ARM_CPUID_CORTEXA8:
         env->vfp.xregs[ARM_VFP_FPSID] = 0x410330c0;
         env->vfp.xregs[ARM_VFP_MVFR0] = 0x11110222;
         env->vfp.xregs[ARM_VFP_MVFR1] = 0x00011100;
-        env->cp15.c0_cachetype = 0x82048004;
         env->cp15.c0_clid = (1 << 27) | (2 << 24) | 3;
         env->cp15.c0_ccsid[0] = 0xe007e01a; /* 16k L1 dcache. */
         env->cp15.c0_ccsid[1] = 0x2007e01a; /* 16k L1 icache. */
@@ -73,7 +66,6 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
         env->vfp.xregs[ARM_VFP_FPSID] = 0x41034000; /* Guess */
         env->vfp.xregs[ARM_VFP_MVFR0] = 0x11110222;
         env->vfp.xregs[ARM_VFP_MVFR1] = 0x01111111;
-        env->cp15.c0_cachetype = 0x80038003;
         env->cp15.c0_clid = (1 << 27) | (1 << 24) | 3;
         env->cp15.c0_ccsid[0] = 0xe00fe015; /* 16k L1 dcache. */
         env->cp15.c0_ccsid[1] = 0x200fe015; /* 16k L1 icache. */
@@ -83,7 +75,6 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
         env->vfp.xregs[ARM_VFP_FPSID] = 0x410430f0;
         env->vfp.xregs[ARM_VFP_MVFR0] = 0x10110222;
         env->vfp.xregs[ARM_VFP_MVFR1] = 0x11111111;
-        env->cp15.c0_cachetype = 0x8444c004;
         env->cp15.c0_clid = 0x0a200023;
         env->cp15.c0_ccsid[0] = 0x701fe00a; /* 32K L1 dcache */
         env->cp15.c0_ccsid[1] = 0x201fe00a; /* 32K L1 icache */
@@ -92,7 +83,6 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
         break;
     case ARM_CPUID_TI915T:
     case ARM_CPUID_TI925T:
-        env->cp15.c0_cachetype = 0x5109149;
         env->cp15.c1_sys = 0x00000070;
         env->cp15.c15_i_max = 0x000;
         env->cp15.c15_i_min = 0xff0;
@@ -103,7 +93,6 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
     case ARM_CPUID_PXA261:
     case ARM_CPUID_PXA262:
         /* JTAG_ID is ((id << 28) | 0x09265013) */
-        env->cp15.c0_cachetype = 0xd172172;
         env->cp15.c1_sys = 0x00000078;
         break;
     case ARM_CPUID_PXA270_A0:
@@ -114,7 +103,6 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
     case ARM_CPUID_PXA270_C5:
         /* JTAG_ID is ((id << 28) | 0x09265013) */
         env->iwmmxt.cregs[ARM_IWMMXT_wCID] = 0x69051000 | 'Q';
-        env->cp15.c0_cachetype = 0xd172172;
         env->cp15.c1_sys = 0x00000078;
         break;
     case ARM_CPUID_SA1100:
Signature · 1 line
1.7.7
#28 lore raw

RFC PATCH v3 12/21 target-arm: Move cp15 c1_sys register to ARMCPUClass

In reply to Andreas Färber
---
 target-arm/cpu-core.h |    1 +
 target-arm/cpu.c      |   19 +++++++++++++++++++
 target-arm/cpu.h      |    3 ---
 target-arm/helper.c   |   17 -----------------
 4 files changed, 20 insertions(+), 20 deletions(-)
target-arm/cpu-core.h +1 -0
index 1d5adc8..3e7dfae 100644
@@ -46,6 +46,7 @@ typedef struct ARMCPUClass {
         uint32_t c0_cachetype;
         uint32_t c0_c1[8];
         uint32_t c0_c2[8];
+        uint32_t c1_sys;
     } cp15;
 
     /* Internal CPU feature flags. */
target-arm/cpu.c +19 -0
index fe34b31..2c1e1a6 100644
@@ -50,6 +50,9 @@ static void arm_cpu_reset(CPU *c)
     memcpy(env->cp15.c0_c1, cpu_class->cp15.c0_c1, 8 * sizeof(uint32_t));
     memcpy(env->cp15.c0_c2, cpu_class->cp15.c0_c2, 8 * sizeof(uint32_t));
 
+    /* Genuine reset */
+    env->cp15.c1_sys = cpu_class->cp15.c1_sys;
+
 #if defined(CONFIG_USER_ONLY)
     env->uncached_cpsr = ARM_CPU_MODE_USR;
     /* For user mode we must enable access to coprocessors */
@@ -168,6 +171,7 @@ typedef struct ARMCPUInfo {
     uint32_t cp15_c0_cachetype;
     uint32_t cp15_c0_c1[8];
     uint32_t cp15_c0_c2[8];
+    uint32_t cp15_c1_sys;
     uint32_t features;
     void (*class_init)(ARMCPUClass *klass, const struct ARMCPUInfo *info);
 } ARMCPUInfo;
@@ -188,6 +192,7 @@ static void arm1136_r0_class_init(ARMCPUClass *k, const ARMCPUInfo *info)
     k->cp15.c0_cachetype = r1_class->cp15.c0_cachetype;
     memcpy(k->cp15.c0_c1, r1_class->cp15.c0_c1, 8 * sizeof(uint32_t));
     memcpy(k->cp15.c0_c2, r1_class->cp15.c0_c2, 8 * sizeof(uint32_t));
+    k->cp15.c1_sys = r1_class->cp15.c1_sys;
 }
 
 static void ti925t_reset(CPU *c)
@@ -209,12 +214,15 @@ static void ti925t_class_init(ARMCPUClass *klass, const ARMCPUInfo *info)
 
 static void sa11xx_class_init(ARMCPUClass *k, const ARMCPUInfo *info)
 {
+    k->cp15.c1_sys = 0x00000070;
+
     set_class_feature(k, ARM_FEATURE_STRONGARM);
 }
 
 static void pxa25x_class_init(ARMCPUClass *k, const ARMCPUInfo *info)
 {
     k->cp15.c0_cachetype = 0xd172172;
+    k->cp15.c1_sys = 0x00000078;
 
     set_class_feature(k, ARM_FEATURE_V5);
     set_class_feature(k, ARM_FEATURE_XSCALE);
@@ -223,6 +231,7 @@ static void pxa25x_class_init(ARMCPUClass *k, const ARMCPUInfo *info)
 static void pxa270_class_init(ARMCPUClass *k, const ARMCPUInfo *info)
 {
     k->cp15.c0_cachetype = 0xd172172;
+    k->cp15.c1_sys = 0x00000078;
 
     set_class_feature(k, ARM_FEATURE_V5);
     set_class_feature(k, ARM_FEATURE_XSCALE);
@@ -234,6 +243,7 @@ static const ARMCPUInfo arm_cpus[] = {
         .name = "arm926",
         .id = 0x41069265,
         .cp15_c0_cachetype = 0x1dd20d2,
+        .cp15_c1_sys = 0x00090078,
         .features = ARM_FEATURE(V5) |
                     ARM_FEATURE(VFP),
     },
@@ -241,6 +251,7 @@ static const ARMCPUInfo arm_cpus[] = {
         .name = "arm946",
         .id = 0x41059461,
         .cp15_c0_cachetype = 0x0f004006,
+        .cp15_c1_sys = 0x00000078,
         .features = ARM_FEATURE(V5) |
                     ARM_FEATURE(MPU),
     },
@@ -248,6 +259,7 @@ static const ARMCPUInfo arm_cpus[] = {
         .name = "arm1026",
         .id = 0x4106a262,
         .cp15_c0_cachetype = 0x1dd20d2,
+        .cp15_c1_sys = 0x00090078,
         .features = ARM_FEATURE(V5) |
                     ARM_FEATURE(VFP) |
                     ARM_FEATURE(AUXCR),
@@ -273,6 +285,7 @@ static const ARMCPUInfo arm_cpus[] = {
             0x00140011, 0x12002111, 0x11231111, 0x01102131,
             0x141, 0, 0, 0
         },
+        .cp15_c1_sys = 0x00050078,
         .features = ARM_FEATURE(V6) |
                     ARM_FEATURE(VFP),
     },
@@ -288,6 +301,7 @@ static const ARMCPUInfo arm_cpus[] = {
             0x0140011, 0x12002111, 0x11231121, 0x01102131,
             0x01141, 0, 0, 0
         },
+        .cp15_c1_sys = 0x00050078,
         .features = ARM_FEATURE(V6K) |
                     ARM_FEATURE(VFP) |
                     ARM_FEATURE(VAPA),
@@ -326,6 +340,7 @@ static const ARMCPUInfo arm_cpus[] = {
             0x00101111, 0x12112111, 0x21232031, 0x11112131,
             0x00111142, 0, 0, 0
         },
+        .cp15_c1_sys = 0x00c50078,
         .features = ARM_FEATURE(V7) |
                     ARM_FEATURE(VFP3) |
                     ARM_FEATURE(NEON) |
@@ -343,6 +358,7 @@ static const ARMCPUInfo arm_cpus[] = {
             0x00101111, 0x13112111, 0x21232041, 0x11112131,
             0x00111142, 0, 0, 0
         },
+        .cp15_c1_sys = 0x00c50078,
         .features = ARM_FEATURE(V7) |
                     ARM_FEATURE(VFP3) |
                     ARM_FEATURE(VFP_FP16) |
@@ -366,6 +382,7 @@ static const ARMCPUInfo arm_cpus[] = {
             0x02101110, 0x13112111, 0x21232041, 0x11112131,
             0x10011142, 0, 0, 0
         },
+        .cp15_c1_sys = 0x00c50078,
         .features = ARM_FEATURE(V7) |
                     ARM_FEATURE(VFP4) |
                     ARM_FEATURE(VFP_FP16) |
@@ -379,6 +396,7 @@ static const ARMCPUInfo arm_cpus[] = {
         .name = "ti925t",
         .id = 0x54029252,
         .cp15_c0_cachetype = 0x5109149,
+        .cp15_c1_sys = 0x00000070,
         .features = ARM_FEATURE(V4T) |
                     ARM_FEATURE(OMAPCP),
         .class_init = ti925t_class_init,
@@ -487,6 +505,7 @@ static void arm_cpu_class_init(ObjectClass *klass, void *data)
     k->cp15.c0_cachetype = info->cp15_c0_cachetype;
     memcpy(k->cp15.c0_c1, info->cp15_c0_c1, 8 * sizeof(uint32_t));
     memcpy(k->cp15.c0_c2, info->cp15_c0_c2, 8 * sizeof(uint32_t));
+    k->cp15.c1_sys = info->cp15_c1_sys;
     k->features = info->features;
 
     if (info->class_init != NULL) {
target-arm/cpu.h +0 -3
index 6731256..e16befd 100644
@@ -404,11 +404,8 @@ void cpu_arm_set_cp_io(CPUARMState *env, int cpnum,
 
 #define ARM_CPUID_ARM1026     0x4106a262
 #define ARM_CPUID_ARM926      0x41069265
-#define ARM_CPUID_ARM946      0x41059461
 #define ARM_CPUID_TI915T      0x54029152
 #define ARM_CPUID_TI925T      0x54029252
-#define ARM_CPUID_SA1100      0x4401A11B
-#define ARM_CPUID_SA1110      0x6901B119
 #define ARM_CPUID_PXA250      0x69052100
 #define ARM_CPUID_PXA255      0x69052d00
 #define ARM_CPUID_PXA260      0x69052903
target-arm/helper.c +0 -17
index 9a4afad..32319e4 100644
@@ -15,14 +15,9 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
     switch (id) {
     case ARM_CPUID_ARM926:
         env->vfp.xregs[ARM_VFP_FPSID] = 0x41011090;
-        env->cp15.c1_sys = 0x00090078;
-        break;
-    case ARM_CPUID_ARM946:
-        env->cp15.c1_sys = 0x00000078;
         break;
     case ARM_CPUID_ARM1026:
         env->vfp.xregs[ARM_VFP_FPSID] = 0x410110a0;
-        env->cp15.c1_sys = 0x00090078;
         break;
     case ARM_CPUID_ARM1136:
         /* This is the 1136 r1, which is a v6K core */
@@ -39,13 +34,11 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
         env->vfp.xregs[ARM_VFP_FPSID] = 0x410120b4;
         env->vfp.xregs[ARM_VFP_MVFR0] = 0x11111111;
         env->vfp.xregs[ARM_VFP_MVFR1] = 0x00000000;
-        env->cp15.c1_sys = 0x00050078;
         break;
     case ARM_CPUID_ARM1176:
         env->vfp.xregs[ARM_VFP_FPSID] = 0x410120b5;
         env->vfp.xregs[ARM_VFP_MVFR0] = 0x11111111;
         env->vfp.xregs[ARM_VFP_MVFR1] = 0x00000000;
-        env->cp15.c1_sys = 0x00050078;
         break;
     case ARM_CPUID_ARM11MPCORE:
         env->vfp.xregs[ARM_VFP_FPSID] = 0x410120b4;
@@ -60,7 +53,6 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
         env->cp15.c0_ccsid[0] = 0xe007e01a; /* 16k L1 dcache. */
         env->cp15.c0_ccsid[1] = 0x2007e01a; /* 16k L1 icache. */
         env->cp15.c0_ccsid[2] = 0xf0000000; /* No L2 icache. */
-        env->cp15.c1_sys = 0x00c50078;
         break;
     case ARM_CPUID_CORTEXA9:
         env->vfp.xregs[ARM_VFP_FPSID] = 0x41034000; /* Guess */
@@ -69,7 +61,6 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
         env->cp15.c0_clid = (1 << 27) | (1 << 24) | 3;
         env->cp15.c0_ccsid[0] = 0xe00fe015; /* 16k L1 dcache. */
         env->cp15.c0_ccsid[1] = 0x200fe015; /* 16k L1 icache. */
-        env->cp15.c1_sys = 0x00c50078;
         break;
     case ARM_CPUID_CORTEXA15:
         env->vfp.xregs[ARM_VFP_FPSID] = 0x410430f0;
@@ -79,11 +70,9 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
         env->cp15.c0_ccsid[0] = 0x701fe00a; /* 32K L1 dcache */
         env->cp15.c0_ccsid[1] = 0x201fe00a; /* 32K L1 icache */
         env->cp15.c0_ccsid[2] = 0x711fe07a; /* 4096K L2 unified cache */
-        env->cp15.c1_sys = 0x00c50078;
         break;
     case ARM_CPUID_TI915T:
     case ARM_CPUID_TI925T:
-        env->cp15.c1_sys = 0x00000070;
         env->cp15.c15_i_max = 0x000;
         env->cp15.c15_i_min = 0xff0;
         break;
@@ -93,7 +82,6 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
     case ARM_CPUID_PXA261:
     case ARM_CPUID_PXA262:
         /* JTAG_ID is ((id << 28) | 0x09265013) */
-        env->cp15.c1_sys = 0x00000078;
         break;
     case ARM_CPUID_PXA270_A0:
     case ARM_CPUID_PXA270_A1:
@@ -103,11 +91,6 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
     case ARM_CPUID_PXA270_C5:
         /* JTAG_ID is ((id << 28) | 0x09265013) */
         env->iwmmxt.cregs[ARM_IWMMXT_wCID] = 0x69051000 | 'Q';
-        env->cp15.c1_sys = 0x00000078;
-        break;
-    case ARM_CPUID_SA1100:
-    case ARM_CPUID_SA1110:
-        env->cp15.c1_sys = 0x00000070;
         break;
     default:
         break;
Signature · 1 line
1.7.7
#29 lore raw

RFC PATCH v3 13/21 target-arm: Store JTAG_ID in ARMCPUClass

In reply to Andreas Färber

That way we can remove some more CPUID cases without losing info.

Cc Peter Maydell <[email protected]>
Cc Andrzej Zaborowski <[email protected]>
---
 target-arm/cpu-core.h |    1 +
 target-arm/cpu.c      |    2 ++
 target-arm/cpu.h      |    5 -----
 target-arm/helper.c   |    8 --------
 4 files changed, 3 insertions(+), 13 deletions(-)
target-arm/cpu-core.h +1 -0
index 3e7dfae..eac1a03 100644
@@ -48,6 +48,7 @@ typedef struct ARMCPUClass {
         uint32_t c0_c2[8];
         uint32_t c1_sys;
     } cp15;
+    uint64_t jtag_id;
 
     /* Internal CPU feature flags. */
     uint32_t features;
target-arm/cpu.c +2 -0
index 2c1e1a6..7d4f0f6 100644
@@ -223,6 +223,7 @@ static void pxa25x_class_init(ARMCPUClass *k, const ARMCPUInfo *info)
 {
     k->cp15.c0_cachetype = 0xd172172;
     k->cp15.c1_sys = 0x00000078;
+    k->jtag_id = ((uint64_t)k->cp15.c0_cpuid << 28) | 0x09265013;
 
     set_class_feature(k, ARM_FEATURE_V5);
     set_class_feature(k, ARM_FEATURE_XSCALE);
@@ -232,6 +233,7 @@ static void pxa270_class_init(ARMCPUClass *k, const ARMCPUInfo *info)
 {
     k->cp15.c0_cachetype = 0xd172172;
     k->cp15.c1_sys = 0x00000078;
+    k->jtag_id = ((uint64_t)k->cp15.c0_cpuid << 28) | 0x09265013;
 
     set_class_feature(k, ARM_FEATURE_V5);
     set_class_feature(k, ARM_FEATURE_XSCALE);
target-arm/cpu.h +0 -5
index e16befd..351b057 100644
@@ -406,11 +406,6 @@ void cpu_arm_set_cp_io(CPUARMState *env, int cpnum,
 #define ARM_CPUID_ARM926      0x41069265
 #define ARM_CPUID_TI915T      0x54029152
 #define ARM_CPUID_TI925T      0x54029252
-#define ARM_CPUID_PXA250      0x69052100
-#define ARM_CPUID_PXA255      0x69052d00
-#define ARM_CPUID_PXA260      0x69052903
-#define ARM_CPUID_PXA261      0x69052d05
-#define ARM_CPUID_PXA262      0x69052d06
 #define ARM_CPUID_PXA270_A0   0x69054110
 #define ARM_CPUID_PXA270_A1   0x69054111
 #define ARM_CPUID_PXA270_B0   0x69054112
target-arm/helper.c +0 -8
index 32319e4..bf28fea 100644
@@ -76,20 +76,12 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
         env->cp15.c15_i_max = 0x000;
         env->cp15.c15_i_min = 0xff0;
         break;
-    case ARM_CPUID_PXA250:
-    case ARM_CPUID_PXA255:
-    case ARM_CPUID_PXA260:
-    case ARM_CPUID_PXA261:
-    case ARM_CPUID_PXA262:
-        /* JTAG_ID is ((id << 28) | 0x09265013) */
-        break;
     case ARM_CPUID_PXA270_A0:
     case ARM_CPUID_PXA270_A1:
     case ARM_CPUID_PXA270_B0:
     case ARM_CPUID_PXA270_B1:
     case ARM_CPUID_PXA270_C0:
     case ARM_CPUID_PXA270_C5:
-        /* JTAG_ID is ((id << 28) | 0x09265013) */
         env->iwmmxt.cregs[ARM_IWMMXT_wCID] = 0x69051000 | 'Q';
         break;
     default:
Signature · 1 line
1.7.7
#30 lore raw

Re: [Qemu-devel] [PATCH RFC v3 13/21] target-arm: Store JTAG_ID in ARMCPUClass

Quoted 17 lines · Andreas Färber

That way we can remove some more CPUID cases without losing info.

Cc Peter Maydell <[email protected]>
Cc Andrzej Zaborowski <[email protected]>

---
 target-arm/cpu-core.h |    1 +
 target-arm/cpu.c      |    2 ++
 target-arm/cpu.h      |    5 -----
 target-arm/helper.c   |    8 --------

 4 files changed, 3 insertions(+), 13 deletions(-)
target-arm/cpu-core.h +0 -0
index 3e7dfae..eac1a03 100644

target-arm/cpu-core.h typedef struct ARMCPUClass { · line 51

Quoted 4 lines
target-arm/cpu-core.h +1 -0
@@ -48,6 +48,7 @@ typedef struct ARMCPUClass {
         uint32_t c0_c2[8];
         uint32_t c1_sys;
     } cp15;
+    uint64_t jtag_id;

If we're not using this anywhere we should just not have it.

-- PMM

#31 lore raw

Re: [Qemu-devel] [PATCH RFC v3 13/21] target-arm: Store JTAG_ID in ARMCPUClass

Am 07.02.2012 18:47, schrieb Peter Maydell:

Quoted 13 lines · Andreas Färber
Quoted 12 lines

That way we can remove some more CPUID cases without losing info.

Cc Peter Maydell <[email protected]>
Cc Andrzej Zaborowski <[email protected]>
---
 target-arm/cpu-core.h |    1 +
 target-arm/cpu.c      |    2 ++
 target-arm/cpu.h      |    5 -----
 target-arm/helper.c   |    8 --------
 4 files changed, 3 insertions(+), 13 deletions(-)
Quoted 11 lines

target-arm/cpu-core.h typedef struct ARMCPUClass { · line 51

Quoted 9 lines
target-arm/cpu-core.h +1 -0
index 3e7dfae..eac1a03 100644
@@ -48,6 +48,7 @@ typedef struct ARMCPUClass {
        uint32_t c0_c2[8];
        uint32_t c1_sys;
    } cp15;
+    uint64_t jtag_id;

If we're not using this anywhere we should just not have it.

Andrzej will have had his reasons to put it in the code. This series just moves code around so I don't want to remove it without his ack. I cc'ed him in the hopes of getting an explanation. :)

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#32 lore raw

Re: [Qemu-devel] [PATCH RFC v3 13/21] target-arm: Store JTAG_ID in ARMCPUClass

Quoted 8 lines · Andreas Färber

Am 07.02.2012 18:47, schrieb Peter Maydell:

Quoted 4 lines · Andreas Färber
Quoted 1 line

+    uint64_t jtag_id;

If we're not using this anywhere we should just not have it.

Andrzej will have had his reasons to put it in the code. This series just moves code around so I don't want to remove it without his ack.

That was my point -- as far as I can see this patch *is* adding code and a struct field that wasn't there before.

-- PMM

#33 lore raw

Re: [Qemu-devel] [PATCH RFC v3 13/21] target-arm: Store JTAG_ID in ARMCPUClass

Am 07.02.2012 20:06, schrieb Peter Maydell:

Quoted 5 lines · Andreas Färber
Quoted 4 lines

Am 07.02.2012 18:47, schrieb Peter Maydell:

Quoted 3 lines · Andreas Färber
Quoted 1 line

+ uint64_t jtag_id;

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

If we're not using this anywhere we should just not have it.

Andrzej will have had his reasons to put it in the code. This series just moves code around so I don't want to remove it without his ack.

That was my point -- as far as I can see this patch *is* adding code and a struct field that wasn't there before.

Huh? Look closely, it *was* a comment in the original code. And I don't want to *move* that comment over into my new code. Therefore I'm adding a class field where such informational data can properly be stored and inspected - per class, not per CPUState instance.

I can imagine storing much more information in a CPU class such as vendor name*, description, logo, link to docs and chip color ;) to allow for a nice lspci-like inspection.
* Yeah, in case of ARM the vendor can be inferred from CPUID so a getter would be sufficient but you get the idea.

Again, I don't specifically need a jtag_id field, but this data is definitely coming from existing code. If Andrzej doesn't respond here, feel free to send a trivial patch to remove it from there.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#34 lore raw

Re: [Qemu-devel] [PATCH RFC v3 13/21] target-arm: Store JTAG_ID in ARMCPUClass

Quoted 9 lines · Andreas Färber

Am 07.02.2012 20:06, schrieb Peter Maydell:

Quoted 6 lines · Andreas Färber
Quoted 2 lines

Andrzej will have had his reasons to put it in the code. This series just moves code around so I don't want to remove it without his ack.

That was my point -- as far as I can see this patch *is* adding code and a struct field that wasn't there before.

Huh? Look closely, it *was* a comment in the original code.

Exactly. It was a comment; now it's code. I don't think we should be adding code.

Quoted 1 line

And I don't want to *move* that comment over into my new code.

You can move the comment, or you can just drop it; I'm happy with either. I don't want new code/struct fields we don't use.

-- PMM

#35 lore raw

RFC PATCH v3 14/21 target-arm: Move the PXA270's iwMMXt reset to pxa270_reset()

In reply to Andreas Färber

No other emulated CPU uses this at this time.

Cc Peter Maydell <[email protected]>
Cc Andrzej Zaborowski <[email protected]>
---
 target-arm/cpu.c    |   14 ++++++++++++++
 target-arm/cpu.h    |    6 ------
 target-arm/helper.c |    8 --------
 3 files changed, 14 insertions(+), 14 deletions(-)
target-arm/cpu.c +14 -0
index 7d4f0f6..bf4b272 100644
@@ -229,8 +229,22 @@ static void pxa25x_class_init(ARMCPUClass *k, const ARMCPUInfo *info)
     set_class_feature(k, ARM_FEATURE_XSCALE);
 }
 
+static void pxa270_reset(CPU *c)
+{
+    ARMCPU *cpu = ARM_CPU(c);
+    CPUARMState *env = &cpu->env;
+
+    arm_cpu_reset(c);
+
+    env->iwmmxt.cregs[ARM_IWMMXT_wCID] = 0x69051000 | 'Q';
+}
+
 static void pxa270_class_init(ARMCPUClass *k, const ARMCPUInfo *info)
 {
+    CPUClass *cpu_class = CPU_CLASS(k);
+
+    cpu_class->reset = pxa270_reset;
+
     k->cp15.c0_cachetype = 0xd172172;
     k->cp15.c1_sys = 0x00000078;
     k->jtag_id = ((uint64_t)k->cp15.c0_cpuid << 28) | 0x09265013;
target-arm/cpu.h +0 -6
index 351b057..32aaa4e 100644
@@ -406,12 +406,6 @@ void cpu_arm_set_cp_io(CPUARMState *env, int cpnum,
 #define ARM_CPUID_ARM926      0x41069265
 #define ARM_CPUID_TI915T      0x54029152
 #define ARM_CPUID_TI925T      0x54029252
-#define ARM_CPUID_PXA270_A0   0x69054110
-#define ARM_CPUID_PXA270_A1   0x69054111
-#define ARM_CPUID_PXA270_B0   0x69054112
-#define ARM_CPUID_PXA270_B1   0x69054113
-#define ARM_CPUID_PXA270_C0   0x69054114
-#define ARM_CPUID_PXA270_C5   0x69054117
 #define ARM_CPUID_ARM1136     0x4117b363
 #define ARM_CPUID_ARM1136_R2  0x4107b362
 #define ARM_CPUID_ARM1176     0x410fb767
target-arm/helper.c +0 -8
index bf28fea..4a531b8 100644
@@ -76,14 +76,6 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
         env->cp15.c15_i_max = 0x000;
         env->cp15.c15_i_min = 0xff0;
         break;
-    case ARM_CPUID_PXA270_A0:
-    case ARM_CPUID_PXA270_A1:
-    case ARM_CPUID_PXA270_B0:
-    case ARM_CPUID_PXA270_B1:
-    case ARM_CPUID_PXA270_C0:
-    case ARM_CPUID_PXA270_C5:
-        env->iwmmxt.cregs[ARM_IWMMXT_wCID] = 0x69051000 | 'Q';
-        break;
     default:
         break;
     }
Signature · 1 line
1.7.7
#36 lore raw

Re: [Qemu-devel] [PATCH RFC v3 14/21] target-arm: Move the PXA270's iwMMXt reset to pxa270_reset()

Quoted 1 line · Andreas Färber

No other emulated CPU uses this at this time.

But why does this code better fit in hw/ than target-arm? The iwMMXt registers are core registers after all.

Also the defines let the board code request a cpu revision by name instead of using a magic number, so I think they're useful.

Cheers

#37 lore raw

Re: [Qemu-devel] [PATCH RFC v3 14/21] target-arm: Move the PXA270's iwMMXt reset to pxa270_reset()

Am 17.02.2012 10:59, schrieb andrzej zaborowski:

Quoted 5 lines · Andreas Färber
Quoted 1 line

No other emulated CPU uses this at this time.

But why does this code better fit in hw/ than target-arm? The iwMMXt registers are core registers after all.

It seems you've misread something here. This is all in target-arm. :)

Quoted 2 lines

Also the defines let the board code request a cpu revision by name instead of using a magic number, so I think they're useful.

No, the boards request a CPU by type name, which is not magic either.

The whole point of QOM'ification is to have the CPU provide the necessary fields and methods, not logic spread across the code in an if-this-cpu-then fashion. I plan to tackle cp15 (the last remainder of CPUID code dependencies) when I'm through with all other targets. If someone really needs the CPUID they can access it through ARMCPU (CPUARMState).

The final plan for rnpn is to have two QOM properties and to request a "pxa270" CPU, then set the revision since there are no functional dependencies on the revision at all. (cc'ing Paul)
I've actually compile-tested and grep'ed this.

Please note also the following v4 that came out of an IRC discussion:
http://repo.or.cz/w/qemu/afaerber.git/commitdiff/1262acf06308cf2bde46520d0238548cb73c79fe
If you need the JTAG_ID somewhere please let us know soon.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#38 lore raw

Re: [Qemu-devel] [PATCH RFC v3 14/21] target-arm: Move the PXA270's iwMMXt reset to pxa270_reset()

Quoted 8 lines · Andreas Färber

Am 17.02.2012 10:59, schrieb andrzej zaborowski:

Quoted 5 lines · Andreas Färber
Quoted 1 line

No other emulated CPU uses this at this time.

But why does this code better fit in hw/ than target-arm?  The iwMMXt registers are core registers after all.

It seems you've misread something here. This is all in target-arm. :)

Yes, I did, sorry. I had looked at the whole series previously, forgotten it, then looked at this patch that was still in my inbox without any of the context.

...

Quoted 5 lines

The final plan for rnpn is to have two QOM properties and to request a "pxa270" CPU, then set the revision since there are no functional dependencies on the revision at all. (cc'ing Paul)
I've actually compile-tested and grep'ed this.

Sounds reasonable.

Quoted 4 lines

Please note also the following v4 that came out of an IRC discussion:
http://repo.or.cz/w/qemu/afaerber.git/commitdiff/1262acf06308cf2bde46520d0238548cb73c79fe
If you need the JTAG_ID somewhere please let us know soon.

No, it's not used anywhere (obviously otherwise it wouldn't be a comment)

Cheers

#39 lore raw

RFC PATCH v3 15/21 target-arm: Store VFP FPSID register in ARMCPUClass

In reply to Andreas Färber
---
 target-arm/cpu-core.h |    3 +++
 target-arm/cpu.c      |   11 +++++++++++
 target-arm/cpu.h      |    1 -
 target-arm/helper.c   |   12 ------------
 4 files changed, 14 insertions(+), 13 deletions(-)
target-arm/cpu-core.h +3 -0
index eac1a03..0b2eb0a 100644
@@ -48,6 +48,9 @@ typedef struct ARMCPUClass {
         uint32_t c0_c2[8];
         uint32_t c1_sys;
     } cp15;
+    struct {
+        uint32_t fpsid;
+    } vfp;
     uint64_t jtag_id;
 
     /* Internal CPU feature flags. */
target-arm/cpu.c +11 -0
index bf4b272..7893fa8 100644
@@ -52,6 +52,7 @@ static void arm_cpu_reset(CPU *c)
 
     /* Genuine reset */
     env->cp15.c1_sys = cpu_class->cp15.c1_sys;
+    env->vfp.xregs[ARM_VFP_FPSID] = cpu_class->vfp.fpsid;
 
 #if defined(CONFIG_USER_ONLY)
     env->uncached_cpsr = ARM_CPU_MODE_USR;
@@ -172,6 +173,7 @@ typedef struct ARMCPUInfo {
     uint32_t cp15_c0_c1[8];
     uint32_t cp15_c0_c2[8];
     uint32_t cp15_c1_sys;
+    uint32_t vfp_fpsid;
     uint32_t features;
     void (*class_init)(ARMCPUClass *klass, const struct ARMCPUInfo *info);
 } ARMCPUInfo;
@@ -260,6 +262,7 @@ static const ARMCPUInfo arm_cpus[] = {
         .id = 0x41069265,
         .cp15_c0_cachetype = 0x1dd20d2,
         .cp15_c1_sys = 0x00090078,
+        .vfp_fpsid = 0x41011090,
         .features = ARM_FEATURE(V5) |
                     ARM_FEATURE(VFP),
     },
@@ -276,6 +279,7 @@ static const ARMCPUInfo arm_cpus[] = {
         .id = 0x4106a262,
         .cp15_c0_cachetype = 0x1dd20d2,
         .cp15_c1_sys = 0x00090078,
+        .vfp_fpsid = 0x410110a0,
         .features = ARM_FEATURE(V5) |
                     ARM_FEATURE(VFP) |
                     ARM_FEATURE(AUXCR),
@@ -302,6 +306,7 @@ static const ARMCPUInfo arm_cpus[] = {
             0x141, 0, 0, 0
         },
         .cp15_c1_sys = 0x00050078,
+        .vfp_fpsid = 0x410120b4,
         .features = ARM_FEATURE(V6) |
                     ARM_FEATURE(VFP),
     },
@@ -318,6 +323,7 @@ static const ARMCPUInfo arm_cpus[] = {
             0x01141, 0, 0, 0
         },
         .cp15_c1_sys = 0x00050078,
+        .vfp_fpsid = 0x410120b5,
         .features = ARM_FEATURE(V6K) |
                     ARM_FEATURE(VFP) |
                     ARM_FEATURE(VAPA),
@@ -334,6 +340,7 @@ static const ARMCPUInfo arm_cpus[] = {
             0x00100011, 0x12002111, 0x11221011, 0x01102131,
             0x141, 0, 0, 0
         },
+        .vfp_fpsid = 0x410120b4,
         .features = ARM_FEATURE(V6K) |
                     ARM_FEATURE(VFP) |
                     ARM_FEATURE(VAPA),
@@ -357,6 +364,7 @@ static const ARMCPUInfo arm_cpus[] = {
             0x00111142, 0, 0, 0
         },
         .cp15_c1_sys = 0x00c50078,
+        .vfp_fpsid = 0x410330c0,
         .features = ARM_FEATURE(V7) |
                     ARM_FEATURE(VFP3) |
                     ARM_FEATURE(NEON) |
@@ -375,6 +383,7 @@ static const ARMCPUInfo arm_cpus[] = {
             0x00111142, 0, 0, 0
         },
         .cp15_c1_sys = 0x00c50078,
+        .vfp_fpsid = 0x41034000, /* Guess */
         .features = ARM_FEATURE(V7) |
                     ARM_FEATURE(VFP3) |
                     ARM_FEATURE(VFP_FP16) |
@@ -399,6 +408,7 @@ static const ARMCPUInfo arm_cpus[] = {
             0x10011142, 0, 0, 0
         },
         .cp15_c1_sys = 0x00c50078,
+        .vfp_fpsid = 0x410430f0,
         .features = ARM_FEATURE(V7) |
                     ARM_FEATURE(VFP4) |
                     ARM_FEATURE(VFP_FP16) |
@@ -522,6 +532,7 @@ static void arm_cpu_class_init(ObjectClass *klass, void *data)
     memcpy(k->cp15.c0_c1, info->cp15_c0_c1, 8 * sizeof(uint32_t));
     memcpy(k->cp15.c0_c2, info->cp15_c0_c2, 8 * sizeof(uint32_t));
     k->cp15.c1_sys = info->cp15_c1_sys;
+    k->vfp.fpsid = info->vfp_fpsid;
     k->features = info->features;
 
     if (info->class_init != NULL) {
target-arm/cpu.h +0 -1
index 32aaa4e..a1630b0 100644
@@ -403,7 +403,6 @@ void cpu_arm_set_cp_io(CPUARMState *env, int cpnum,
 #define ARM_CPUID(env) (env->cp15.c0_cpuid)
 
 #define ARM_CPUID_ARM1026     0x4106a262
-#define ARM_CPUID_ARM926      0x41069265
 #define ARM_CPUID_TI915T      0x54029152
 #define ARM_CPUID_TI925T      0x54029252
 #define ARM_CPUID_ARM1136     0x4117b363
target-arm/helper.c +0 -12
index 4a531b8..466519a 100644
@@ -13,12 +13,6 @@
 static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
 {
     switch (id) {
-    case ARM_CPUID_ARM926:
-        env->vfp.xregs[ARM_VFP_FPSID] = 0x41011090;
-        break;
-    case ARM_CPUID_ARM1026:
-        env->vfp.xregs[ARM_VFP_FPSID] = 0x410110a0;
-        break;
     case ARM_CPUID_ARM1136:
         /* This is the 1136 r1, which is a v6K core */
         /* Fall through */
@@ -31,22 +25,18 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
          * for 1136_r2 (in particular r0p2 does not actually implement most
          * of the ID registers).
          */
-        env->vfp.xregs[ARM_VFP_FPSID] = 0x410120b4;
         env->vfp.xregs[ARM_VFP_MVFR0] = 0x11111111;
         env->vfp.xregs[ARM_VFP_MVFR1] = 0x00000000;
         break;
     case ARM_CPUID_ARM1176:
-        env->vfp.xregs[ARM_VFP_FPSID] = 0x410120b5;
         env->vfp.xregs[ARM_VFP_MVFR0] = 0x11111111;
         env->vfp.xregs[ARM_VFP_MVFR1] = 0x00000000;
         break;
     case ARM_CPUID_ARM11MPCORE:
-        env->vfp.xregs[ARM_VFP_FPSID] = 0x410120b4;
         env->vfp.xregs[ARM_VFP_MVFR0] = 0x11111111;
         env->vfp.xregs[ARM_VFP_MVFR1] = 0x00000000;
         break;
     case ARM_CPUID_CORTEXA8:
-        env->vfp.xregs[ARM_VFP_FPSID] = 0x410330c0;
         env->vfp.xregs[ARM_VFP_MVFR0] = 0x11110222;
         env->vfp.xregs[ARM_VFP_MVFR1] = 0x00011100;
         env->cp15.c0_clid = (1 << 27) | (2 << 24) | 3;
@@ -55,7 +45,6 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
         env->cp15.c0_ccsid[2] = 0xf0000000; /* No L2 icache. */
         break;
     case ARM_CPUID_CORTEXA9:
-        env->vfp.xregs[ARM_VFP_FPSID] = 0x41034000; /* Guess */
         env->vfp.xregs[ARM_VFP_MVFR0] = 0x11110222;
         env->vfp.xregs[ARM_VFP_MVFR1] = 0x01111111;
         env->cp15.c0_clid = (1 << 27) | (1 << 24) | 3;
@@ -63,7 +52,6 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
         env->cp15.c0_ccsid[1] = 0x200fe015; /* 16k L1 icache. */
         break;
     case ARM_CPUID_CORTEXA15:
-        env->vfp.xregs[ARM_VFP_FPSID] = 0x410430f0;
         env->vfp.xregs[ARM_VFP_MVFR0] = 0x10110222;
         env->vfp.xregs[ARM_VFP_MVFR1] = 0x11111111;
         env->cp15.c0_clid = 0x0a200023;
Signature · 1 line
1.7.7
#40 lore raw

Re: [Qemu-devel] [PATCH RFC v3 15/21] target-arm: Store VFP FPSID register in ARMCPUClass

Quoted 10 lines · Andreas Färber
(quoted diff) +0 -0
@@ -375,6 +383,7 @@ static const ARMCPUInfo arm_cpus[] = {

            0x00111142, 0, 0, 0
        },
        .cp15_c1_sys = 0x00c50078,
+        .vfp_fpsid = 0x41034000, /* Guess */
        .features = ARM_FEATURE(V7) |
                    ARM_FEATURE(VFP3) |
                    ARM_FEATURE(VFP_FP16) |

(quoted diff) +0 -0
@@ -55,7 +45,6 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
Quoted 7 lines

        env->cp15.c0_ccsid[2] = 0xf0000000; /* No L2 icache. */ break;
    case ARM_CPUID_CORTEXA9:
-        env->vfp.xregs[ARM_VFP_FPSID] = 0x41034000; /* Guess */ env->vfp.xregs[ARM_VFP_MVFR0] = 0x11110222; env->vfp.xregs[ARM_VFP_MVFR1] = 0x01111111; env->cp15.c0_clid = (1 << 27) | (1 << 24) | 3;

Incidentally, this guess for FPSID is wrong -- it should be 0x41033090 for the r0p0 we're claiming to model (later revs the bottom nibble is bumped). I'll send a patch...

-- PMM

#41 lore raw

RFC PATCH v3 16/21 target-arm: Store VFP MVFR0 and MVFR1 in ARMCPUClass

In reply to Andreas Färber
---
 target-arm/cpu-core.h |    1 +
 target-arm/cpu.c      |   11 +++++++++++
 target-arm/helper.c   |   29 -----------------------------
 3 files changed, 12 insertions(+), 29 deletions(-)
target-arm/cpu-core.h +1 -0
index 0b2eb0a..53fac1a 100644
@@ -50,6 +50,7 @@ typedef struct ARMCPUClass {
     } cp15;
     struct {
         uint32_t fpsid;
+        uint32_t mvfr[2];
     } vfp;
     uint64_t jtag_id;
 
target-arm/cpu.c +11 -0
index 7893fa8..d004cfd 100644
@@ -49,6 +49,8 @@ static void arm_cpu_reset(CPU *c)
     env->cp15.c0_cachetype = cpu_class->cp15.c0_cachetype;
     memcpy(env->cp15.c0_c1, cpu_class->cp15.c0_c1, 8 * sizeof(uint32_t));
     memcpy(env->cp15.c0_c2, cpu_class->cp15.c0_c2, 8 * sizeof(uint32_t));
+    env->vfp.xregs[ARM_VFP_MVFR0] = cpu_class->vfp.mvfr[0];
+    env->vfp.xregs[ARM_VFP_MVFR1] = cpu_class->vfp.mvfr[1];
 
     /* Genuine reset */
     env->cp15.c1_sys = cpu_class->cp15.c1_sys;
@@ -174,6 +176,7 @@ typedef struct ARMCPUInfo {
     uint32_t cp15_c0_c2[8];
     uint32_t cp15_c1_sys;
     uint32_t vfp_fpsid;
+    uint32_t vfp_mvfr[2];
     uint32_t features;
     void (*class_init)(ARMCPUClass *klass, const struct ARMCPUInfo *info);
 } ARMCPUInfo;
@@ -307,6 +310,7 @@ static const ARMCPUInfo arm_cpus[] = {
         },
         .cp15_c1_sys = 0x00050078,
         .vfp_fpsid = 0x410120b4,
+        .vfp_mvfr = { 0x11111111, 0x00000000 },
         .features = ARM_FEATURE(V6) |
                     ARM_FEATURE(VFP),
     },
@@ -324,6 +328,7 @@ static const ARMCPUInfo arm_cpus[] = {
         },
         .cp15_c1_sys = 0x00050078,
         .vfp_fpsid = 0x410120b5,
+        .vfp_mvfr = { 0x11111111, 0x00000000 },
         .features = ARM_FEATURE(V6K) |
                     ARM_FEATURE(VFP) |
                     ARM_FEATURE(VAPA),
@@ -341,6 +346,7 @@ static const ARMCPUInfo arm_cpus[] = {
             0x141, 0, 0, 0
         },
         .vfp_fpsid = 0x410120b4,
+        .vfp_mvfr = { 0x11111111, 0x00000000 },
         .features = ARM_FEATURE(V6K) |
                     ARM_FEATURE(VFP) |
                     ARM_FEATURE(VAPA),
@@ -365,6 +371,7 @@ static const ARMCPUInfo arm_cpus[] = {
         },
         .cp15_c1_sys = 0x00c50078,
         .vfp_fpsid = 0x410330c0,
+        .vfp_mvfr = { 0x11110222, 0x00011100 },
         .features = ARM_FEATURE(V7) |
                     ARM_FEATURE(VFP3) |
                     ARM_FEATURE(NEON) |
@@ -384,6 +391,7 @@ static const ARMCPUInfo arm_cpus[] = {
         },
         .cp15_c1_sys = 0x00c50078,
         .vfp_fpsid = 0x41034000, /* Guess */
+        .vfp_mvfr = { 0x11110222, 0x01111111 },
         .features = ARM_FEATURE(V7) |
                     ARM_FEATURE(VFP3) |
                     ARM_FEATURE(VFP_FP16) |
@@ -409,6 +417,7 @@ static const ARMCPUInfo arm_cpus[] = {
         },
         .cp15_c1_sys = 0x00c50078,
         .vfp_fpsid = 0x410430f0,
+        .vfp_mvfr = { 0x10110222, 0x11111111 },
         .features = ARM_FEATURE(V7) |
                     ARM_FEATURE(VFP4) |
                     ARM_FEATURE(VFP_FP16) |
@@ -533,6 +542,8 @@ static void arm_cpu_class_init(ObjectClass *klass, void *data)
     memcpy(k->cp15.c0_c2, info->cp15_c0_c2, 8 * sizeof(uint32_t));
     k->cp15.c1_sys = info->cp15_c1_sys;
     k->vfp.fpsid = info->vfp_fpsid;
+    k->vfp.mvfr[0] = info->vfp_mvfr[0];
+    k->vfp.mvfr[1] = info->vfp_mvfr[1];
     k->features = info->features;
 
     if (info->class_init != NULL) {
target-arm/helper.c +0 -29
index 466519a..4ec375c 100644
@@ -13,47 +13,18 @@
 static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
 {
     switch (id) {
-    case ARM_CPUID_ARM1136:
-        /* This is the 1136 r1, which is a v6K core */
-        /* Fall through */
-    case ARM_CPUID_ARM1136_R2:
-        /* What qemu calls "arm1136_r2" is actually the 1136 r0p2, ie an
-         * older core than plain "arm1136". In particular this does not
-         * have the v6K features.
-         */
-        /* These ID register values are correct for 1136 but may be wrong
-         * for 1136_r2 (in particular r0p2 does not actually implement most
-         * of the ID registers).
-         */
-        env->vfp.xregs[ARM_VFP_MVFR0] = 0x11111111;
-        env->vfp.xregs[ARM_VFP_MVFR1] = 0x00000000;
-        break;
-    case ARM_CPUID_ARM1176:
-        env->vfp.xregs[ARM_VFP_MVFR0] = 0x11111111;
-        env->vfp.xregs[ARM_VFP_MVFR1] = 0x00000000;
-        break;
-    case ARM_CPUID_ARM11MPCORE:
-        env->vfp.xregs[ARM_VFP_MVFR0] = 0x11111111;
-        env->vfp.xregs[ARM_VFP_MVFR1] = 0x00000000;
-        break;
     case ARM_CPUID_CORTEXA8:
-        env->vfp.xregs[ARM_VFP_MVFR0] = 0x11110222;
-        env->vfp.xregs[ARM_VFP_MVFR1] = 0x00011100;
         env->cp15.c0_clid = (1 << 27) | (2 << 24) | 3;
         env->cp15.c0_ccsid[0] = 0xe007e01a; /* 16k L1 dcache. */
         env->cp15.c0_ccsid[1] = 0x2007e01a; /* 16k L1 icache. */
         env->cp15.c0_ccsid[2] = 0xf0000000; /* No L2 icache. */
         break;
     case ARM_CPUID_CORTEXA9:
-        env->vfp.xregs[ARM_VFP_MVFR0] = 0x11110222;
-        env->vfp.xregs[ARM_VFP_MVFR1] = 0x01111111;
         env->cp15.c0_clid = (1 << 27) | (1 << 24) | 3;
         env->cp15.c0_ccsid[0] = 0xe00fe015; /* 16k L1 dcache. */
         env->cp15.c0_ccsid[1] = 0x200fe015; /* 16k L1 icache. */
         break;
     case ARM_CPUID_CORTEXA15:
-        env->vfp.xregs[ARM_VFP_MVFR0] = 0x10110222;
-        env->vfp.xregs[ARM_VFP_MVFR1] = 0x11111111;
         env->cp15.c0_clid = 0x0a200023;
         env->cp15.c0_ccsid[0] = 0x701fe00a; /* 32K L1 dcache */
         env->cp15.c0_ccsid[1] = 0x201fe00a; /* 32K L1 icache */
Signature · 1 line
1.7.7
#42 lore raw

RFC PATCH v3 17/21 target-arm: Store CLIDR in ARMCPUClass

In reply to Andreas Färber
---
 target-arm/cpu-core.h |    1 +
 target-arm/cpu.c      |    6 ++++++
 target-arm/helper.c   |    3 ---
 3 files changed, 7 insertions(+), 3 deletions(-)
target-arm/cpu-core.h +1 -0
index 53fac1a..0ed92ce 100644
@@ -44,6 +44,7 @@ typedef struct ARMCPUClass {
     struct {
         uint32_t c0_cpuid;
         uint32_t c0_cachetype;
+        uint32_t c0_clid;
         uint32_t c0_c1[8];
         uint32_t c0_c2[8];
         uint32_t c1_sys;
target-arm/cpu.c +6 -0
index d004cfd..8333ca4 100644
@@ -47,6 +47,7 @@ static void arm_cpu_reset(CPU *c)
 
     /* TODO Move these into arm_cpu_initfn() once no longer zeroed above. */
     env->cp15.c0_cachetype = cpu_class->cp15.c0_cachetype;
+    env->cp15.c0_clid = cpu_class->cp15.c0_clid;
     memcpy(env->cp15.c0_c1, cpu_class->cp15.c0_c1, 8 * sizeof(uint32_t));
     memcpy(env->cp15.c0_c2, cpu_class->cp15.c0_c2, 8 * sizeof(uint32_t));
     env->vfp.xregs[ARM_VFP_MVFR0] = cpu_class->vfp.mvfr[0];
@@ -172,6 +173,7 @@ typedef struct ARMCPUInfo {
     const char *name;
     uint32_t id;
     uint32_t cp15_c0_cachetype;
+    uint32_t cp15_c0_clid;
     uint32_t cp15_c0_c1[8];
     uint32_t cp15_c0_c2[8];
     uint32_t cp15_c1_sys;
@@ -361,6 +363,7 @@ static const ARMCPUInfo arm_cpus[] = {
         .name = "cortex-a8",
         .id = 0x410fc080,
         .cp15_c0_cachetype = 0x82048004,
+        .cp15_c0_clid = (1 << 27) | (2 << 24) | 3,
         .cp15_c0_c1 = {
             0x1031, 0x11, 0x400, 0,
             0x31100003, 0x20000000, 0x01202000, 0x11
@@ -381,6 +384,7 @@ static const ARMCPUInfo arm_cpus[] = {
         .name = "cortex-a9",
         .id = 0x410fc090,
         .cp15_c0_cachetype = 0x80038003,
+        .cp15_c0_clid = (1 << 27) | (1 << 24) | 3,
         .cp15_c0_c1 = {
             0x1031, 0x11, 0x000, 0,
             0x00100103, 0x20000000, 0x01230000, 0x00002111
@@ -407,6 +411,7 @@ static const ARMCPUInfo arm_cpus[] = {
         .name = "cortex-a15",
         .id = 0x412fc0f1,
         .cp15_c0_cachetype = 0x8444c004,
+        .cp15_c0_clid = 0x0a200023,
         .cp15_c0_c1 = {
             0x00001131, 0x00011011, 0x02010555, 0x00000000,
             0x10201105, 0x20000000, 0x01240000, 0x02102211
@@ -538,6 +543,7 @@ static void arm_cpu_class_init(ObjectClass *klass, void *data)
 
     k->cp15.c0_cpuid = info->id;
     k->cp15.c0_cachetype = info->cp15_c0_cachetype;
+    k->cp15.c0_clid = info->cp15_c0_clid;
     memcpy(k->cp15.c0_c1, info->cp15_c0_c1, 8 * sizeof(uint32_t));
     memcpy(k->cp15.c0_c2, info->cp15_c0_c2, 8 * sizeof(uint32_t));
     k->cp15.c1_sys = info->cp15_c1_sys;
target-arm/helper.c +0 -3
index 4ec375c..6f2c9a0 100644
@@ -14,18 +14,15 @@ static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
 {
     switch (id) {
     case ARM_CPUID_CORTEXA8:
-        env->cp15.c0_clid = (1 << 27) | (2 << 24) | 3;
         env->cp15.c0_ccsid[0] = 0xe007e01a; /* 16k L1 dcache. */
         env->cp15.c0_ccsid[1] = 0x2007e01a; /* 16k L1 icache. */
         env->cp15.c0_ccsid[2] = 0xf0000000; /* No L2 icache. */
         break;
     case ARM_CPUID_CORTEXA9:
-        env->cp15.c0_clid = (1 << 27) | (1 << 24) | 3;
         env->cp15.c0_ccsid[0] = 0xe00fe015; /* 16k L1 dcache. */
         env->cp15.c0_ccsid[1] = 0x200fe015; /* 16k L1 icache. */
         break;
     case ARM_CPUID_CORTEXA15:
-        env->cp15.c0_clid = 0x0a200023;
         env->cp15.c0_ccsid[0] = 0x701fe00a; /* 32K L1 dcache */
         env->cp15.c0_ccsid[1] = 0x201fe00a; /* 32K L1 icache */
         env->cp15.c0_ccsid[2] = 0x711fe07a; /* 4096K L2 unified cache */
Signature · 1 line
1.7.7
#43 lore raw

RFC PATCH v3 18/21 target-arm: Store CCSIDRs in ARMCPUClass

In reply to Andreas Färber
---
 target-arm/cpu-core.h |    1 +
 target-arm/cpu.c      |   18 ++++++++++++++++++
 target-arm/helper.c   |   14 --------------
 3 files changed, 19 insertions(+), 14 deletions(-)
target-arm/cpu-core.h +1 -0
index 0ed92ce..a58e62b 100644
@@ -44,6 +44,7 @@ typedef struct ARMCPUClass {
     struct {
         uint32_t c0_cpuid;
         uint32_t c0_cachetype;
+        uint32_t c0_ccsid[16];
         uint32_t c0_clid;
         uint32_t c0_c1[8];
         uint32_t c0_c2[8];
target-arm/cpu.c +18 -0
index 8333ca4..8186a96 100644
@@ -47,6 +47,8 @@ static void arm_cpu_reset(CPU *c)
 
     /* TODO Move these into arm_cpu_initfn() once no longer zeroed above. */
     env->cp15.c0_cachetype = cpu_class->cp15.c0_cachetype;
+    memcpy(env->cp15.c0_ccsid, cpu_class->cp15.c0_ccsid,
+           16 * sizeof(uint32_t));
     env->cp15.c0_clid = cpu_class->cp15.c0_clid;
     memcpy(env->cp15.c0_c1, cpu_class->cp15.c0_c1, 8 * sizeof(uint32_t));
     memcpy(env->cp15.c0_c2, cpu_class->cp15.c0_c2, 8 * sizeof(uint32_t));
@@ -173,6 +175,7 @@ typedef struct ARMCPUInfo {
     const char *name;
     uint32_t id;
     uint32_t cp15_c0_cachetype;
+    uint32_t cp15_c0_ccsid[16];
     uint32_t cp15_c0_clid;
     uint32_t cp15_c0_c1[8];
     uint32_t cp15_c0_c2[8];
@@ -363,6 +366,11 @@ static const ARMCPUInfo arm_cpus[] = {
         .name = "cortex-a8",
         .id = 0x410fc080,
         .cp15_c0_cachetype = 0x82048004,
+        .cp15_c0_ccsid = {
+            0xe007e01a, /* 16k L1 dcache. */
+            0x2007e01a, /* 16k L1 icache. */
+            0xf0000000, /* No L2 icache. */
+        },
         .cp15_c0_clid = (1 << 27) | (2 << 24) | 3,
         .cp15_c0_c1 = {
             0x1031, 0x11, 0x400, 0,
@@ -384,6 +392,10 @@ static const ARMCPUInfo arm_cpus[] = {
         .name = "cortex-a9",
         .id = 0x410fc090,
         .cp15_c0_cachetype = 0x80038003,
+        .cp15_c0_ccsid = {
+            0xe00fe015, /* 16k L1 dcache. */
+            0x200fe015, /* 16k L1 icache. */
+        },
         .cp15_c0_clid = (1 << 27) | (1 << 24) | 3,
         .cp15_c0_c1 = {
             0x1031, 0x11, 0x000, 0,
@@ -411,6 +423,11 @@ static const ARMCPUInfo arm_cpus[] = {
         .name = "cortex-a15",
         .id = 0x412fc0f1,
         .cp15_c0_cachetype = 0x8444c004,
+        .cp15_c0_ccsid = {
+            0x701fe00a, /* 32K L1 dcache */
+            0x201fe00a, /* 32K L1 icache */
+            0x711fe07a, /* 4096K L2 unified cache */
+        },
         .cp15_c0_clid = 0x0a200023,
         .cp15_c0_c1 = {
             0x00001131, 0x00011011, 0x02010555, 0x00000000,
@@ -543,6 +560,7 @@ static void arm_cpu_class_init(ObjectClass *klass, void *data)
 
     k->cp15.c0_cpuid = info->id;
     k->cp15.c0_cachetype = info->cp15_c0_cachetype;
+    memcpy(k->cp15.c0_ccsid, info->cp15_c0_ccsid, 16 * sizeof(uint32_t));
     k->cp15.c0_clid = info->cp15_c0_clid;
     memcpy(k->cp15.c0_c1, info->cp15_c0_c1, 8 * sizeof(uint32_t));
     memcpy(k->cp15.c0_c2, info->cp15_c0_c2, 8 * sizeof(uint32_t));
target-arm/helper.c +0 -14
index 6f2c9a0..6ecae15 100644
@@ -13,20 +13,6 @@
 static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
 {
     switch (id) {
-    case ARM_CPUID_CORTEXA8:
-        env->cp15.c0_ccsid[0] = 0xe007e01a; /* 16k L1 dcache. */
-        env->cp15.c0_ccsid[1] = 0x2007e01a; /* 16k L1 icache. */
-        env->cp15.c0_ccsid[2] = 0xf0000000; /* No L2 icache. */
-        break;
-    case ARM_CPUID_CORTEXA9:
-        env->cp15.c0_ccsid[0] = 0xe00fe015; /* 16k L1 dcache. */
-        env->cp15.c0_ccsid[1] = 0x200fe015; /* 16k L1 icache. */
-        break;
-    case ARM_CPUID_CORTEXA15:
-        env->cp15.c0_ccsid[0] = 0x701fe00a; /* 32K L1 dcache */
-        env->cp15.c0_ccsid[1] = 0x201fe00a; /* 32K L1 icache */
-        env->cp15.c0_ccsid[2] = 0x711fe07a; /* 4096K L2 unified cache */
-        break;
     case ARM_CPUID_TI915T:
     case ARM_CPUID_TI925T:
         env->cp15.c15_i_max = 0x000;
Signature · 1 line
1.7.7
#44 lore raw

RFC PATCH v3 19/21 target-arm: Kill off cpu_reset_model_id()

In reply to Andreas Färber

Move last remaining TI925T bits to ti925t_reset().

This reduces cpu_reset() to triviality and lets us reset the CPU directly from arm_cpu_initfn().

---
 target-arm/cpu.c    |    4 ++++
 target-arm/helper.c |   20 --------------------
 2 files changed, 4 insertions(+), 20 deletions(-)
target-arm/cpu.c +4 -0
index 8186a96..74f4e9b 100644
@@ -213,6 +213,8 @@ static void ti925t_reset(CPU *c)
     arm_cpu_reset(c);
 
     env->cp15.c0_cpuid = ARM_CPUID_TI925T; /* Depends on wiring. */
+    env->cp15.c15_i_max = 0x000;
+    env->cp15.c15_i_min = 0xff0;
 }
 
 static void ti925t_class_init(ARMCPUClass *klass, const ARMCPUInfo *info)
@@ -548,6 +550,8 @@ static void arm_cpu_initfn(Object *obj)
 
     cpu->env.cpu_model_str = object_get_typename(obj);
     cpu->env.cp15.c0_cpuid = cpu_class->cp15.c0_cpuid;
+
+    cpu_do_reset(CPU(cpu));
 }
 
 static void arm_cpu_class_init(ObjectClass *klass, void *data)
target-arm/helper.c +0 -20
index 6ecae15..cb98661 100644
@@ -10,28 +10,9 @@
 #include "sysemu.h"
 #include "cpu-core.h"
 
-static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
-{
-    switch (id) {
-    case ARM_CPUID_TI915T:
-    case ARM_CPUID_TI925T:
-        env->cp15.c15_i_max = 0x000;
-        env->cp15.c15_i_min = 0xff0;
-        break;
-    default:
-        break;
-    }
-}
-
 void cpu_reset(CPUARMState *env)
 {
-    uint32_t id;
-
     cpu_do_reset(CPU(ENV_GET_OBJECT(env)));
-
-    id = env->cp15.c0_cpuid;
-    if (id)
-        cpu_reset_model_id(env, id);
 }
 
 static int vfp_gdb_get_reg(CPUState *env, uint8_t *buf, int reg)
@@ -110,7 +91,6 @@ CPUARMState *cpu_arm_init(const char *cpu_model)
         arm_translate_init();
     }
 
-    cpu_reset(env);
     if (arm_feature(env, ARM_FEATURE_NEON)) {
         gdb_register_coprocessor(env, vfp_gdb_get_reg, vfp_gdb_set_reg,
                                  51, "arm-neon.xml", 0);
Signature · 1 line
1.7.7
#45 lore raw

RFC PATCH v3 20/21 target-arm: Prepare halted property for CPU

In reply to Andreas Färber

Read-only and ARM-specific for now.

Cc Peter Maydell <[email protected]>
Cc Anthony Liguori <[email protected]>
---
 target-arm/cpu.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
target-arm/cpu.c +12 -0
index 74f4e9b..4dfec15 100644
@@ -20,6 +20,7 @@
 
 #include "cpu-core.h"
 #include "qemu-common.h"
+#include "qapi/qapi-visit-core.h"
 #if !defined(CONFIG_USER_ONLY)
 #include "hw/loader.h"
 #endif
@@ -538,6 +539,14 @@ static const ARMCPUInfo arm_cpus[] = {
     },
 };
 
+static void arm_cpu_get_halted(Object *obj, Visitor *v, void *opaque,
+                               const char *name, Error **errp)
+{
+    ARMCPU *cpu = ARM_CPU(obj);
+    bool halted = cpu->env.halted != 0;
+    visit_type_bool(v, &halted, name, errp);
+}
+
 static void arm_cpu_initfn(Object *obj)
 {
     ARMCPU *cpu = ARM_CPU(obj);
@@ -552,6 +561,9 @@ static void arm_cpu_initfn(Object *obj)
     cpu->env.cp15.c0_cpuid = cpu_class->cp15.c0_cpuid;
 
     cpu_do_reset(CPU(cpu));
+
+    object_property_add(obj, "halted", "boolean",
+                        arm_cpu_get_halted, NULL, NULL, NULL, NULL);
 }
 
 static void arm_cpu_class_init(ObjectClass *klass, void *data)
Signature · 1 line
1.7.7
#46 lore raw

PATCH v3 21/21 target-arm: Just for testing!

In reply to Andreas Färber

Add the CPU as child<> of / so that it can be inspected with qom-get.

---
 target-arm/cpu.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
target-arm/cpu.c +2 -0
index 4dfec15..ad8e317 100644
@@ -564,6 +564,8 @@ static void arm_cpu_initfn(Object *obj)
 
     object_property_add(obj, "halted", "boolean",
                         arm_cpu_get_halted, NULL, NULL, NULL, NULL);
+
+    object_property_add_child(object_get_root(), "cpu", obj, NULL); /* XXX */
 }
 
 static void arm_cpu_class_init(ObjectClass *klass, void *data)
Signature · 1 line
1.7.7