qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH RFC v2 4/8] qom: Introduce CPU class


From: Andreas Färber
Subject: [Qemu-devel] [PATCH RFC v2 4/8] qom: Introduce CPU class
Date: Wed, 1 Feb 2012 13:57:21 +0100

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

Place it in hw/. Have user emulators pick it up via VPATH, building it
per target since they didn't use any qdev/QOM devices so far.

Signed-off-by: Andreas Färber <address@hidden>
Cc: Anthony Liguori <address@hidden>
---
 Makefile.objs      |    1 +
 Makefile.target    |    9 +++++--
 hw/cpu.c           |   39 ++++++++++++++++++++++++++++++++
 include/qemu/cpu.h |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 108 insertions(+), 3 deletions(-)
 create mode 100644 hw/cpu.c
 create mode 100644 include/qemu/cpu.h

diff --git a/Makefile.objs b/Makefile.objs
index b942625..a4b20fa 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -189,6 +189,7 @@ user-obj-y += $(trace-obj-y)
 
 hw-obj-y =
 hw-obj-y += vl.o loader.o
+hw-obj-y += cpu.o
 hw-obj-$(CONFIG_VIRTIO) += virtio-console.o
 hw-obj-y += usb-libhw.o
 hw-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
diff --git a/Makefile.target b/Makefile.target
index d1b7867..5d3470e 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -107,7 +107,7 @@ signal.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
 
 ifdef CONFIG_LINUX_USER
 
-$(call set-vpath, 
$(SRC_PATH)/linux-user:$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR))
+$(call set-vpath, 
$(SRC_PATH)/linux-user:$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR):$(SRC_PATH)/hw)
 
 QEMU_CFLAGS+=-I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR) 
-I$(SRC_PATH)/linux-user
 obj-y = main.o syscall.o strace.o mmap.o signal.o thunk.o \
@@ -130,6 +130,7 @@ obj-m68k-y += m68k-sim.o m68k-semi.o
 $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)
 
 obj-y += module.o
+obj-y += cpu.o
 obj-y += $(addprefix ../qom/, $(qom-y))
 obj-y += $(addprefix ../libuser/, $(user-obj-y))
 obj-y += $(addprefix ../libdis-user/, $(libdis-y))
@@ -142,7 +143,7 @@ endif #CONFIG_LINUX_USER
 
 ifdef CONFIG_DARWIN_USER
 
-$(call set-vpath, $(SRC_PATH)/darwin-user)
+$(call set-vpath, $(SRC_PATH)/darwin-user:$(SRC_PATH)/hw)
 
 QEMU_CFLAGS+=-I$(SRC_PATH)/darwin-user -I$(SRC_PATH)/darwin-user/$(TARGET_ARCH)
 
@@ -159,6 +160,7 @@ obj-i386-y += ioport-user.o
 $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)
 
 obj-y += module.o
+obj-y += cpu.o
 obj-y += $(addprefix ../qom/, $(qom-y))
 obj-y += $(addprefix ../libuser/, $(user-obj-y))
 obj-y += $(addprefix ../libdis-user/, $(libdis-y))
@@ -171,7 +173,7 @@ endif #CONFIG_DARWIN_USER
 
 ifdef CONFIG_BSD_USER
 
-$(call set-vpath, $(SRC_PATH)/bsd-user)
+$(call set-vpath, $(SRC_PATH)/bsd-user:$(SRC_PATH)/hw)
 
 QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ARCH)
 
@@ -183,6 +185,7 @@ obj-i386-y += ioport-user.o
 $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)
 
 obj-y += module.o
+obj-y += cpu.o
 obj-y += $(addprefix ../qom/, $(qom-y))
 obj-y += $(addprefix ../libuser/, $(user-obj-y))
 obj-y += $(addprefix ../libdis-user/, $(libdis-y))
diff --git a/hw/cpu.c b/hw/cpu.c
new file mode 100644
index 0000000..1502fee
--- /dev/null
+++ b/hw/cpu.c
@@ -0,0 +1,39 @@
+/*
+ * QEMU CPU model
+ *
+ * Copyright (c) 2012 SUSE LINUX Products GmbH
+ *
+ * Licensed under the terms of the GNU GPL version 2
+ * or (at your option) any later version.
+ */
+
+#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)
diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h
new file mode 100644
index 0000000..cccf4a5
--- /dev/null
+++ b/include/qemu/cpu.h
@@ -0,0 +1,62 @@
+/*
+ * QEMU CPU model
+ *
+ * Copyright (c) 2012 SUSE LINUX Products GmbH
+ *
+ * Licensed under the terms of the GNU GPL version 2
+ * or (at your option) any later version.
+ */
+#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
-- 
1.7.7




reply via email to

[Prev in Thread] Current Thread [Next in Thread]