Skip to contentSkip to conversation

QOM CPUState patch queue 2015-03-10

GIT PULL Applied Andreas Färber 2 participants 8 messages Mar 10, 2015 – Mar 11, 2015

lore
Share & tools
lore
#0 lore raw

Hello Peter,

This is my QOM CPU patch queue. Please pull.

Regards,
Andreas

Cc Peter Maydell <[email protected]>
Cc Eduardo Habkost <[email protected]>

The following changes since commit 1976058109890892db8ec88bfd3273f79c459f6b:

Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (2015-03-10 14:01:22 +0000)

are available in the git repository at:

git://github.com/afaerber/qemu-cpu.git tags/qom-cpu-for-peter

for you to fetch changes up to 2994fd96d986578a342f2342501b4ad30f6d0a85:

cpu: Make cpu_init() return QOM CPUState object (2015-03-10 17:33:51 +0100)

----------------------------------------------------------------
QOM CPUState and X86CPU

* Add CPUClass documentation
* Clean up X86CPU APIC realization
* Cleanups around cpu_init()

----------------------------------------------------------------
Eduardo Habkost (4):
target-unicore32: Make uc32_cpu_init() return UniCore32CPU
m68k: Use cpu_m68k_init()
unicore32: Use uc32_cpu_init()
cpu: Make cpu_init() return QOM CPUState object

Markus Armbruster (1):
target-i386: Clean up misuse of qdev_init() in realize method

Peter Maydell (1):
cpu: Add missing documentation for some CPUClass methods

 bsd-user/main.c           |  6 +++---
 hw/m68k/dummy_m68k.c      |  6 ++++--
 hw/unicore32/puv3.c       |  6 ++++--
 include/qom/cpu.h         | 12 ++++++++++++
 linux-user/main.c         | 10 +++++-----
 target-alpha/cpu.h        |  9 +--------
 target-arm/cpu.h          |  9 +--------
 target-cris/cpu.h         |  9 +--------
 target-i386/cpu.c         |  8 ++------
 target-i386/cpu.h         |  9 +--------
 target-lm32/cpu.h         |  9 +--------
 target-m68k/cpu.h         |  9 +--------
 target-microblaze/cpu.h   |  9 +--------
 target-mips/cpu.h         |  9 +--------
 target-moxie/cpu.h        |  9 +--------
 target-openrisc/cpu.h     |  9 +--------
 target-ppc/cpu.h          |  9 +--------
 target-s390x/cpu.h        |  2 +-
 target-sh4/cpu.h          |  9 +--------
 target-sparc/cpu.h        |  9 +--------
 target-tricore/cpu.h      | 10 +---------
 target-unicore32/cpu.h    |  6 ++++--
 target-unicore32/helper.c | 10 ++--------
 target-xtensa/cpu.h       |  9 +--------
 24 files changed, 52 insertions(+), 150 deletions(-)
#1 lore raw

[Qemu-devel] [PULL 1/6] cpu: Add missing documentation for some CPUClass methods

From: Peter Maydell <[email protected]>

The CPUClass QOM methods virtio_is_big_endian, write_elf{32,64}_note and write_elf{32,64}_qemunote were added without any description being added to the doc comment. Correct this omission.

---
 include/qom/cpu.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/qom/cpu.h +12 -0
index 48fd6fb..d6279c0 100644
@@ -82,6 +82,10 @@ struct TranslationBlock;
  * @do_unassigned_access: Callback for unassigned access handling.
  * @do_unaligned_access: Callback for unaligned access handling, if
  * the target defines #ALIGNED_ONLY.
+ * @virtio_is_big_endian: Callback to return %true if a CPU which supports
+ * runtime configurable endianness is currently big-endian. Non-configurable
+ * CPUs can use the default implementation of this method. This method should
+ * not be used by any callers other than the pre-1.0 virtio devices.
  * @memory_rw_debug: Callback for GDB memory access.
  * @dump_state: Callback for dumping state.
  * @dump_statistics: Callback for dumping statistics.
@@ -96,6 +100,14 @@ struct TranslationBlock;
  * @gdb_read_register: Callback for letting GDB read a register.
  * @gdb_write_register: Callback for letting GDB write a register.
  * @debug_excp_handler: Callback for handling debug exceptions.
+ * @write_elf64_note: Callback for writing a CPU-specific ELF note to a
+ * 64-bit VM coredump.
+ * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
+ * note to a 32-bit VM coredump.
+ * @write_elf32_note: Callback for writing a CPU-specific ELF note to a
+ * 32-bit VM coredump.
+ * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF
+ * note to a 32-bit VM coredump.
  * @vmsd: State description for migration.
  * @gdb_num_core_regs: Number of core registers accessible to GDB.
  * @gdb_core_xml_file: File name for core registers GDB XML description.
Signature · 1 line
2.1.4
#2 lore raw

[Qemu-devel] [PULL 5/6] unicore32: Use uc32_cpu_init()

In reply to Andreas Färber

From: Eduardo Habkost <[email protected]>

Instead of using the legacy cpu_init() function, use uc32_cpu_init() to create a UniCore32CPU object.

---
 hw/unicore32/puv3.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/unicore32/puv3.c +4 -2
index c41499e..cc9a21a 100644
@@ -109,6 +109,7 @@ static void puv3_init(MachineState *machine)
     const char *kernel_filename = machine->kernel_filename;
     const char *initrd_filename = machine->initrd_filename;
     CPUUniCore32State *env;
+    UniCore32CPU *cpu;
 
     if (initrd_filename) {
         hw_error("Please use kernel built-in initramdisk.\n");
@@ -118,10 +119,11 @@ static void puv3_init(MachineState *machine)
         cpu_model = "UniCore-II";
     }
 
-    env = cpu_init(cpu_model);
-    if (!env) {
+    cpu = uc32_cpu_init(cpu_model);
+    if (!cpu) {
         hw_error("Unable to find CPU definition\n");
     }
+    env = &cpu->env;
 
     puv3_soc_init(env);
     puv3_board_init(env, ram_size);
Signature · 1 line
2.1.4
#3 lore raw

[Qemu-devel] [PULL 6/6] cpu: Make cpu_init() return QOM CPUState object

In reply to Andreas Färber

From: Eduardo Habkost <[email protected]>

Instead of making cpu_init() return CPUArchState, return CPUState.

Changes were made using the Coccinelle semantic patch below.

@@
typedef CPUState;
identifier e;
expression args;
type CPUArchState;
@@
- e =
+ cpu =

          cpu_init(args);
  -   if (!e) {
  +   if (!cpu) {
          ...
      }

- cpu = ENV_GET_CPU(env);
+ e = cpu->env_ptr;

@@
identifier new_env, new_cpu, env, cpu;
type CPUArchState;
expression args;
@@
-{

  -   CPUState *cpu = ENV_GET_CPU(env);
  -   CPUArchState *new_env = cpu_init(args);
  -   CPUState *new_cpu = ENV_GET_CPU(new_env);
  +{
  +   CPUState *cpu = ENV_GET_CPU(env);
  +   CPUState *new_cpu = cpu_init(args);
  +   CPUArchState *new_env = new_cpu->env_ptr;
      ...

}

@@
identifier c, cpu_init_func, cpu_model;
type StateType, CPUType;
@@
-static inline StateType* cpu_init(const char *cpu_model) -{
- CPUType *c = cpu_init_func(cpu_model);
(
- if (c == NULL) {
- return NULL;
- }
- return &c->env;
|
- if (c) {
- return &c->env;
- }
- return NULL;
)
-}
+#define cpu_init(cpu_model) CPU(cpu_init_func(cpu_model))

@@
identifier cpu_init_func;
identifier model;
@@
-#define cpu_init(model) (&cpu_init_func(model)->env) +#define cpu_init(model) CPU(cpu_init_func(model))

Cc Blue Swirl <[email protected]>
Cc Guan Xuetao <[email protected]>
Cc Riku Voipio <[email protected]>
Cc Richard Henderson <[email protected]>
Cc Peter Maydell <[email protected]>
Cc "Edgar E. Iglesias" <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Michael Walle <[email protected]>
Cc Aurelien Jarno <[email protected]>
Cc Leon Alrae <[email protected]>
Cc Anthony Green <[email protected]>
Cc Jia Liu <[email protected]>
Cc Alexander Graf <[email protected]>
Cc Bastian Koppelmann <[email protected]>
Cc Max Filippov <[email protected]>
[AF: Fixed up cpu_copy() manually]
---
 bsd-user/main.c         |  6 +++---
 linux-user/main.c       | 10 +++++-----
 target-alpha/cpu.h      |  9 +--------
 target-arm/cpu.h        |  9 +--------
 target-cris/cpu.h       |  9 +--------
 target-i386/cpu.h       |  9 +--------
 target-lm32/cpu.h       |  9 +--------
 target-m68k/cpu.h       |  9 +--------
 target-microblaze/cpu.h |  9 +--------
 target-mips/cpu.h       |  9 +--------
 target-moxie/cpu.h      |  9 +--------
 target-openrisc/cpu.h   |  9 +--------
 target-ppc/cpu.h        |  9 +--------
 target-s390x/cpu.h      |  2 +-
 target-sh4/cpu.h        |  9 +--------
 target-sparc/cpu.h      |  9 +--------
 target-tricore/cpu.h    | 10 +---------
 target-unicore32/cpu.h  | 10 +---------
 target-xtensa/cpu.h     |  9 +--------
 19 files changed, 25 insertions(+), 139 deletions(-)
bsd-user/main.c +3 -3
index 0e8c26c..1bb2754 100644
@@ -908,12 +908,12 @@ int main(int argc, char **argv)
     cpu_exec_init_all();
     /* NOTE: we need to init the CPU at this stage to get
        qemu_host_page_size */
-    env = cpu_init(cpu_model);
-    if (!env) {
+    cpu = cpu_init(cpu_model);
+    if (!cpu) {
         fprintf(stderr, "Unable to find CPU definition\n");
         exit(1);
     }
-    cpu = ENV_GET_CPU(env);
+    env = cpu->env_ptr;
 #if defined(TARGET_SPARC) || defined(TARGET_PPC)
     cpu_reset(cpu);
 #endif
linux-user/main.c +5 -5
index d92702a..6bd23af 100644
@@ -3452,8 +3452,8 @@ void init_task_state(TaskState *ts)
 CPUArchState *cpu_copy(CPUArchState *env)
 {
     CPUState *cpu = ENV_GET_CPU(env);
-    CPUArchState *new_env = cpu_init(cpu_model);
-    CPUState *new_cpu = ENV_GET_CPU(new_env);
+    CPUState *new_cpu = cpu_init(cpu_model);
+    CPUArchState *new_env = cpu->env_ptr;
     CPUBreakpoint *bp;
     CPUWatchpoint *wp;
 
@@ -3939,12 +3939,12 @@ int main(int argc, char **argv, char **envp)
     cpu_exec_init_all();
     /* NOTE: we need to init the CPU at this stage to get
        qemu_host_page_size */
-    env = cpu_init(cpu_model);
-    if (!env) {
+    cpu = cpu_init(cpu_model);
+    if (!cpu) {
         fprintf(stderr, "Unable to find CPU definition\n");
         exit(1);
     }
-    cpu = ENV_GET_CPU(env);
+    env = cpu->env_ptr;
     cpu_reset(cpu);
 
     thread_cpu = cpu;
target-alpha/cpu.h +1 -8
index e276dbf..9538f19 100644
@@ -429,14 +429,7 @@ void alpha_translate_init(void);
 
 AlphaCPU *cpu_alpha_init(const char *cpu_model);
 
-static inline CPUAlphaState *cpu_init(const char *cpu_model)
-{
-    AlphaCPU *cpu = cpu_alpha_init(cpu_model);
-    if (cpu == NULL) {
-        return NULL;
-    }
-    return &cpu->env;
-}
+#define cpu_init(cpu_model) CPU(cpu_alpha_init(cpu_model))
 
 void alpha_cpu_list(FILE *f, fprintf_function cpu_fprintf);
 int cpu_alpha_exec(CPUAlphaState *s);
target-arm/cpu.h +1 -8
index 11845a6..083211c 100644
@@ -1569,14 +1569,7 @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx)
     return unmasked || pstate_unmasked;
 }
 
-static inline CPUARMState *cpu_init(const char *cpu_model)
-{
-    ARMCPU *cpu = cpu_arm_init(cpu_model);
-    if (cpu) {
-        return &cpu->env;
-    }
-    return NULL;
-}
+#define cpu_init(cpu_model) CPU(cpu_arm_init(cpu_model))
 
 #define cpu_exec cpu_arm_exec
 #define cpu_gen_code cpu_arm_gen_code
target-cris/cpu.h +1 -8
index eea14b6..677b38c 100644
@@ -221,14 +221,7 @@ enum {
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
-static inline CPUCRISState *cpu_init(const char *cpu_model)
-{
-    CRISCPU *cpu = cpu_cris_init(cpu_model);
-    if (cpu == NULL) {
-        return NULL;
-    }
-    return &cpu->env;
-}
+#define cpu_init(cpu_model) CPU(cpu_cris_init(cpu_model))
 
 #define cpu_exec cpu_cris_exec
 #define cpu_gen_code cpu_cris_gen_code
target-i386/cpu.h +1 -8
index 478450c..4255803 100644
@@ -1171,14 +1171,7 @@ uint64_t cpu_get_tsc(CPUX86State *env);
 # define PHYS_ADDR_MASK 0xfffffffffLL
 # endif
 
-static inline CPUX86State *cpu_init(const char *cpu_model)
-{
-    X86CPU *cpu = cpu_x86_init(cpu_model);
-    if (cpu == NULL) {
-        return NULL;
-    }
-    return &cpu->env;
-}
+#define cpu_init(cpu_model) CPU(cpu_x86_init(cpu_model))
 
 #define cpu_exec cpu_x86_exec
 #define cpu_gen_code cpu_x86_gen_code
target-lm32/cpu.h +1 -8
index e558c59..11ae68d 100644
@@ -217,14 +217,7 @@ void lm32_watchpoint_insert(CPULM32State *env, int index, target_ulong address,
 void lm32_watchpoint_remove(CPULM32State *env, int index);
 bool lm32_cpu_do_semihosting(CPUState *cs);
 
-static inline CPULM32State *cpu_init(const char *cpu_model)
-{
-    LM32CPU *cpu = cpu_lm32_init(cpu_model);
-    if (cpu == NULL) {
-        return NULL;
-    }
-    return &cpu->env;
-}
+#define cpu_init(cpu_model) CPU(cpu_lm32_init(cpu_model))
 
 #define cpu_list lm32_cpu_list
 #define cpu_exec cpu_lm32_exec
target-m68k/cpu.h +1 -8
index 3a1b9ab..5f165da 100644
@@ -212,14 +212,7 @@ void register_m68k_insns (CPUM68KState *env);
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
-static inline CPUM68KState *cpu_init(const char *cpu_model)
-{
-    M68kCPU *cpu = cpu_m68k_init(cpu_model);
-    if (cpu == NULL) {
-        return NULL;
-    }
-    return &cpu->env;
-}
+#define cpu_init(cpu_model) CPU(cpu_m68k_init(cpu_model))
 
 #define cpu_exec cpu_m68k_exec
 #define cpu_gen_code cpu_m68k_gen_code
target-microblaze/cpu.h +1 -8
index 5794f89..7d06227 100644
@@ -297,14 +297,7 @@ enum {
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
-static inline CPUMBState *cpu_init(const char *cpu_model)
-{
-    MicroBlazeCPU *cpu = cpu_mb_init(cpu_model);
-    if (cpu == NULL) {
-        return NULL;
-    }
-    return &cpu->env;
-}
+#define cpu_init(cpu_model) CPU(cpu_mb_init(cpu_model))
 
 #define cpu_exec cpu_mb_exec
 #define cpu_gen_code cpu_mb_gen_code
target-mips/cpu.h +1 -8
index 5ea61bc..f44c814 100644
@@ -739,14 +739,7 @@ void mips_tcg_init(void);
 MIPSCPU *cpu_mips_init(const char *cpu_model);
 int cpu_mips_signal_handler(int host_signum, void *pinfo, void *puc);
 
-static inline CPUMIPSState *cpu_init(const char *cpu_model)
-{
-    MIPSCPU *cpu = cpu_mips_init(cpu_model);
-    if (cpu == NULL) {
-        return NULL;
-    }
-    return &cpu->env;
-}
+#define cpu_init(cpu_model) CPU(cpu_mips_init(cpu_model))
 
 /* TODO QOM'ify CPU reset and remove */
 void cpu_state_reset(CPUMIPSState *s);
target-moxie/cpu.h +1 -8
index d809393..c2733a2 100644
@@ -121,14 +121,7 @@ void moxie_translate_init(void);
 int cpu_moxie_signal_handler(int host_signum, void *pinfo,
                              void *puc);
 
-static inline CPUMoxieState *cpu_init(const char *cpu_model)
-{
-    MoxieCPU *cpu = cpu_moxie_init(cpu_model);
-    if (cpu == NULL) {
-        return NULL;
-    }
-    return &cpu->env;
-}
+#define cpu_init(cpu_model) CPU(cpu_moxie_init(cpu_model))
 
 #define cpu_exec cpu_moxie_exec
 #define cpu_gen_code cpu_moxie_gen_code
target-openrisc/cpu.h +1 -8
index 69b96c6..b25324b 100644
@@ -389,14 +389,7 @@ int cpu_openrisc_get_phys_data(OpenRISCCPU *cpu,
                                int *prot, target_ulong address, int rw);
 #endif
 
-static inline CPUOpenRISCState *cpu_init(const char *cpu_model)
-{
-    OpenRISCCPU *cpu = cpu_openrisc_init(cpu_model);
-    if (cpu) {
-        return &cpu->env;
-    }
-    return NULL;
-}
+#define cpu_init(cpu_model) CPU(cpu_openrisc_init(cpu_model))
 
 #include "exec/cpu-all.h"
 
target-ppc/cpu.h +1 -8
index abc3545..f15815f 100644
@@ -1238,14 +1238,7 @@ static inline uint64_t ppc_dump_gpr(CPUPPCState *env, int gprn)
 int ppc_dcr_read (ppc_dcr_t *dcr_env, int dcrn, uint32_t *valp);
 int ppc_dcr_write (ppc_dcr_t *dcr_env, int dcrn, uint32_t val);
 
-static inline CPUPPCState *cpu_init(const char *cpu_model)
-{
-    PowerPCCPU *cpu = cpu_ppc_init(cpu_model);
-    if (cpu == NULL) {
-        return NULL;
-    }
-    return &cpu->env;
-}
+#define cpu_init(cpu_model) CPU(cpu_ppc_init(cpu_model))
 
 #define cpu_exec cpu_ppc_exec
 #define cpu_gen_code cpu_ppc_gen_code
target-s390x/cpu.h +1 -1
index b6b4632..67fc53c 100644
@@ -466,7 +466,7 @@ int css_do_rchp(uint8_t cssid, uint8_t chpid);
 bool css_present(uint8_t cssid);
 #endif
 
-#define cpu_init(model) (&cpu_s390x_init(model)->env)
+#define cpu_init(model) CPU(cpu_s390x_init(model))
 #define cpu_exec cpu_s390x_exec
 #define cpu_gen_code cpu_s390x_gen_code
 #define cpu_signal_handler cpu_s390x_signal_handler
target-sh4/cpu.h +1 -8
index b2fb199..c8dea6c 100644
@@ -221,14 +221,7 @@ int cpu_sh4_is_cached(CPUSH4State * env, target_ulong addr);
 
 void cpu_load_tlb(CPUSH4State * env);
 
-static inline CPUSH4State *cpu_init(const char *cpu_model)
-{
-    SuperHCPU *cpu = cpu_sh4_init(cpu_model);
-    if (cpu == NULL) {
-        return NULL;
-    }
-    return &cpu->env;
-}
+#define cpu_init(cpu_model) CPU(cpu_sh4_init(cpu_model))
 
 #define cpu_exec cpu_sh4_exec
 #define cpu_gen_code cpu_sh4_gen_code
target-sparc/cpu.h +1 -8
index 0a50e5d..f5c9006 100644
@@ -594,14 +594,7 @@ hwaddr cpu_get_phys_page_nofault(CPUSPARCState *env, target_ulong addr,
 int cpu_sparc_signal_handler(int host_signum, void *pinfo, void *puc);
 
 #ifndef NO_CPU_IO_DEFS
-static inline CPUSPARCState *cpu_init(const char *cpu_model)
-{
-    SPARCCPU *cpu = cpu_sparc_init(cpu_model);
-    if (cpu == NULL) {
-        return NULL;
-    }
-    return &cpu->env;
-}
+#define cpu_init(cpu_model) CPU(cpu_sparc_init(cpu_model))
 #endif
 
 #define cpu_exec cpu_sparc_exec
target-tricore/cpu.h +1 -9
index e5409e4..b473426 100644
@@ -378,15 +378,7 @@ static inline void cpu_get_tb_cpu_state(CPUTriCoreState *env, target_ulong *pc,
 
 TriCoreCPU *cpu_tricore_init(const char *cpu_model);
 
-static inline CPUTriCoreState *cpu_init(const char *cpu_model)
-{
-    TriCoreCPU *cpu = cpu_tricore_init(cpu_model);
-    if (cpu == NULL) {
-        return NULL;
-    }
-    return &cpu->env;
-
-}
+#define cpu_init(cpu_model) CPU(cpu_tricore_init(cpu_model))
 
 
 /* helpers.c */
target-unicore32/cpu.h +1 -9
index 11d76dc..14dc862 100644
@@ -143,15 +143,7 @@ static inline int cpu_mmu_index(CPUUniCore32State *env)
 
 UniCore32CPU *uc32_cpu_init(const char *cpu_model);
 
-static inline CPUUniCore32State *cpu_init(const char *cpu_model)
-{
-    UniCore32CPU *cpu = uc32_cpu_init(cpu_model);
-    if (cpu == NULL) {
-        return NULL;
-    }
-    return &cpu->env;
-
-}
+#define cpu_init(cpu_model) CPU(uc32_cpu_init(cpu_model))
 
 static inline void cpu_get_tb_cpu_state(CPUUniCore32State *env, target_ulong *pc,
                                         target_ulong *cs_base, int *flags)
target-xtensa/cpu.h +1 -8
index 60ee563..dfd0d1c 100644
@@ -379,14 +379,7 @@ typedef struct CPUXtensaState {
 
 XtensaCPU *cpu_xtensa_init(const char *cpu_model);
 
-static inline CPUXtensaState *cpu_init(const char *cpu_model)
-{
-    XtensaCPU *cpu = cpu_xtensa_init(cpu_model);
-    if (cpu == NULL) {
-        return NULL;
-    }
-    return &cpu->env;
-}
+#define cpu_init(cpu_model) CPU(cpu_xtensa_init(cpu_model))
 
 void xtensa_translate_init(void);
 void xtensa_breakpoint_handler(CPUState *cs);
Signature · 1 line
2.1.4
#4 lore raw

[Qemu-devel] [PULL 4/6] m68k: Use cpu_m68k_init()

In reply to Andreas Färber

From: Eduardo Habkost <[email protected]>

Instead of using the legacy cpu_init() function, use cpu_m68k_init() directly to create a M68kCPU object.

---
 hw/m68k/dummy_m68k.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/m68k/dummy_m68k.c +4 -2
index facd561..278f4c0 100644
@@ -21,6 +21,7 @@ static void dummy_m68k_init(MachineState *machine)
     ram_addr_t ram_size = machine->ram_size;
     const char *cpu_model = machine->cpu_model;
     const char *kernel_filename = machine->kernel_filename;
+    M68kCPU *cpu;
     CPUM68KState *env;
     MemoryRegion *address_space_mem =  get_system_memory();
     MemoryRegion *ram = g_new(MemoryRegion, 1);
@@ -30,11 +31,12 @@ static void dummy_m68k_init(MachineState *machine)
 
     if (!cpu_model)
         cpu_model = "cfv4e";
-    env = cpu_init(cpu_model);
-    if (!env) {
+    cpu = cpu_m68k_init(cpu_model);
+    if (!cpu) {
         fprintf(stderr, "Unable to find m68k CPU definition\n");
         exit(1);
     }
+    env = &cpu->env;
 
     /* Initialize CPU registers.  */
     env->vbr = 0;
Signature · 1 line
2.1.4
#5 lore raw

[Qemu-devel] [PULL 2/6] target-i386: Clean up misuse of qdev_init() in realize method

In reply to Andreas Färber

From: Markus Armbruster <[email protected]>

x86_cpu_apic_realize() calls qdev_init() to realize the APIC. qdev_init()'s error handling has unwanted side effects: it unparents the device, and it calls qerror_report_err().

qerror_report_err() is always inappropriate in realize methods, because it doesn't return the Error object. It either reports the error to stderr or the human monitor, or it stores it in the QMP monitor, where it makes the QMP command fail even though the realize method succeeded.

Fortunately, qdev_init() can't actually fail here, because realize can't fail for any of the three possible APIC device models.

Clean up by cutting out the qdev_init() middle-man: set property "realized" directly.

---
 target-i386/cpu.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
target-i386/cpu.c +2 -6
index d543e2b..97777fb 100644
@@ -2751,12 +2751,8 @@ static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
     if (cpu->apic_state == NULL) {
         return;
     }
-
-    if (qdev_init(cpu->apic_state)) {
-        error_setg(errp, "APIC device '%s' could not be initialized",
-                   object_get_typename(OBJECT(cpu->apic_state)));
-        return;
-    }
+    object_property_set_bool(OBJECT(cpu->apic_state), true, "realized",
+                             errp);
 }
 #else
 static void x86_cpu_apic_realize(X86CPU *cpu, Error **errp)
Signature · 1 line
2.1.4
#6 lore raw

[Qemu-devel] [PULL 3/6] target-unicore32: Make uc32_cpu_init() return UniCore32CPU

In reply to Andreas Färber

From: Eduardo Habkost <[email protected]>

This way, the cpu_init() function in target-unicore32 will follow the same pattern used on all other architectures.

---
 target-unicore32/cpu.h    | 14 ++++++++++++--
 target-unicore32/helper.c | 10 ++--------
 2 files changed, 14 insertions(+), 10 deletions(-)
target-unicore32/cpu.h +12 -2
index 50972f9..11d76dc 100644
@@ -122,11 +122,9 @@ void cpu_asr_write(CPUUniCore32State *env1, target_ulong val, target_ulong mask)
 #define UC32_HWCAP_CMOV                 4 /* 1 << 2 */
 #define UC32_HWCAP_UCF64                8 /* 1 << 3 */
 
-#define cpu_init                        uc32_cpu_init
 #define cpu_exec                        uc32_cpu_exec
 #define cpu_signal_handler              uc32_cpu_signal_handler
 
-CPUUniCore32State *uc32_cpu_init(const char *cpu_model);
 int uc32_cpu_exec(CPUUniCore32State *s);
 int uc32_cpu_signal_handler(int host_signum, void *pinfo, void *puc);
 
@@ -143,6 +141,18 @@ static inline int cpu_mmu_index(CPUUniCore32State *env)
 #include "cpu-qom.h"
 #include "exec/exec-all.h"
 
+UniCore32CPU *uc32_cpu_init(const char *cpu_model);
+
+static inline CPUUniCore32State *cpu_init(const char *cpu_model)
+{
+    UniCore32CPU *cpu = uc32_cpu_init(cpu_model);
+    if (cpu == NULL) {
+        return NULL;
+    }
+    return &cpu->env;
+
+}
+
 static inline void cpu_get_tb_cpu_state(CPUUniCore32State *env, target_ulong *pc,
                                         target_ulong *cs_base, int *flags)
 {
target-unicore32/helper.c +2 -8
index b4654fa..ae63277 100644
@@ -25,15 +25,9 @@
 #define DPRINTF(fmt, ...) do {} while (0)
 #endif
 
-CPUUniCore32State *uc32_cpu_init(const char *cpu_model)
+UniCore32CPU *uc32_cpu_init(const char *cpu_model)
 {
-    UniCore32CPU *cpu;
-
-    cpu = UNICORE32_CPU(cpu_generic_init(TYPE_UNICORE32_CPU, cpu_model));
-    if (cpu == NULL) {
-        return NULL;
-    }
-    return &cpu->env;
+    return UNICORE32_CPU(cpu_generic_init(TYPE_UNICORE32_CPU, cpu_model));
 }
 
 uint32_t HELPER(clo)(uint32_t x)
Signature · 1 line
2.1.4
#7 lore raw
In reply to Andreas Färber
Quoted 21 lines · Andreas Färber

Hello Peter,

This is my QOM CPU patch queue. Please pull.

Regards,
Andreas

Cc Peter Maydell <[email protected]>
Cc Eduardo Habkost <[email protected]>

The following changes since commit 1976058109890892db8ec88bfd3273f79c459f6b:

Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (2015-03-10 14:01:22 +0000)

are available in the git repository at:

git://github.com/afaerber/qemu-cpu.git tags/qom-cpu-for-peter

for you to fetch changes up to 2994fd96d986578a342f2342501b4ad30f6d0a85:

Quoted 9 lines

cpu: Make cpu_init() return QOM CPUState object (2015-03-10 17:33:51 +0100)

----------------------------------------------------------------
QOM CPUState and X86CPU

* Add CPUClass documentation
* Clean up X86CPU APIC realization
* Cleanups around cpu_init()

Applied, thanks.

-- PMM