aboutsummaryrefslogtreecommitdiff
path: root/target-m68k
diff options
context:
space:
mode:
Diffstat (limited to 'target-m68k')
-rw-r--r--target-m68k/cpu-qom.h2
-rw-r--r--target-m68k/cpu.c24
-rw-r--r--target-m68k/cpu.h15
-rw-r--r--target-m68k/helper.c27
4 files changed, 52 insertions, 16 deletions
diff --git a/target-m68k/cpu-qom.h b/target-m68k/cpu-qom.h
index 170daa7c96..20e5684552 100644
--- a/target-m68k/cpu-qom.h
+++ b/target-m68k/cpu-qom.h
@@ -33,6 +33,7 @@
/**
* M68kCPUClass:
+ * @parent_realize: The parent class' realize handler.
* @parent_reset: The parent class' reset handler.
*
* A Motorola 68k CPU model.
@@ -42,6 +43,7 @@ typedef struct M68kCPUClass {
CPUClass parent_class;
/*< public >*/
+ DeviceRealize parent_realize;
void (*parent_reset)(CPUState *cpu);
} M68kCPUClass;
diff --git a/target-m68k/cpu.c b/target-m68k/cpu.c
index c71f715174..f5a109854b 100644
--- a/target-m68k/cpu.c
+++ b/target-m68k/cpu.c
@@ -139,12 +139,33 @@ static const M68kCPUInfo m68k_cpus[] = {
{ .name = "any", .instance_init = any_cpu_initfn },
};
+static void m68k_cpu_realizefn(DeviceState *dev, Error **errp)
+{
+ M68kCPU *cpu = M68K_CPU(dev);
+ M68kCPUClass *mcc = M68K_CPU_GET_CLASS(dev);
+
+ m68k_cpu_init_gdb(cpu);
+
+ cpu_reset(CPU(cpu));
+ qemu_init_vcpu(&cpu->env);
+
+ mcc->parent_realize(dev, errp);
+}
+
static void m68k_cpu_initfn(Object *obj)
{
+ CPUState *cs = CPU(obj);
M68kCPU *cpu = M68K_CPU(obj);
CPUM68KState *env = &cpu->env;
+ static bool inited;
+ cs->env_ptr = env;
cpu_exec_init(env);
+
+ if (tcg_enabled() && !inited) {
+ inited = true;
+ m68k_tcg_init();
+ }
}
static const VMStateDescription vmstate_m68k_cpu = {
@@ -158,6 +179,9 @@ static void m68k_cpu_class_init(ObjectClass *c, void *data)
CPUClass *cc = CPU_CLASS(c);
DeviceClass *dc = DEVICE_CLASS(c);
+ mcc->parent_realize = dc->realize;
+ dc->realize = m68k_cpu_realizefn;
+
mcc->parent_reset = cc->reset;
cc->reset = m68k_cpu_reset;
diff --git a/target-m68k/cpu.h b/target-m68k/cpu.h
index adaf56c471..2672eae7c8 100644
--- a/target-m68k/cpu.h
+++ b/target-m68k/cpu.h
@@ -116,7 +116,8 @@ typedef struct CPUM68KState {
#include "cpu-qom.h"
void m68k_tcg_init(void);
-CPUM68KState *cpu_m68k_init(const char *cpu_model);
+void m68k_cpu_init_gdb(M68kCPU *cpu);
+M68kCPU *cpu_m68k_init(const char *cpu_model);
int cpu_m68k_exec(CPUM68KState *s);
void do_interrupt(CPUM68KState *env1);
void do_interrupt_m68k_hardirq(CPUM68KState *env1);
@@ -168,7 +169,7 @@ enum {
#define MACSR_V 0x002
#define MACSR_EV 0x001
-void m68k_set_irq_level(CPUM68KState *env, int level, uint8_t vector);
+void m68k_set_irq_level(M68kCPU *cpu, int level, uint8_t vector);
void m68k_set_macsr(CPUM68KState *env, uint32_t val);
void m68k_switch_sp(CPUM68KState *env);
@@ -214,7 +215,15 @@ void register_m68k_insns (CPUM68KState *env);
#define TARGET_PHYS_ADDR_SPACE_BITS 32
#define TARGET_VIRT_ADDR_SPACE_BITS 32
-#define cpu_init cpu_m68k_init
+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_exec cpu_m68k_exec
#define cpu_gen_code cpu_m68k_gen_code
#define cpu_signal_handler cpu_m68k_signal_handler
diff --git a/target-m68k/helper.c b/target-m68k/helper.c
index 5ddcd707fd..1bae3ab326 100644
--- a/target-m68k/helper.c
+++ b/target-m68k/helper.c
@@ -98,12 +98,11 @@ static int fpu_gdb_set_reg(CPUM68KState *env, uint8_t *mem_buf, int n)
return 0;
}
-CPUM68KState *cpu_m68k_init(const char *cpu_model)
+M68kCPU *cpu_m68k_init(const char *cpu_model)
{
M68kCPU *cpu;
CPUM68KState *env;
ObjectClass *oc;
- static int inited;
oc = cpu_class_by_name(TYPE_M68K_CPU, cpu_model);
if (oc == NULL) {
@@ -111,24 +110,24 @@ CPUM68KState *cpu_m68k_init(const char *cpu_model)
}
cpu = M68K_CPU(object_new(object_class_get_name(oc)));
env = &cpu->env;
-
- if (!inited) {
- inited = 1;
- m68k_tcg_init();
- }
-
env->cpu_model_str = cpu_model;
register_m68k_insns(env);
+
+ object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
+
+ return cpu;
+}
+
+void m68k_cpu_init_gdb(M68kCPU *cpu)
+{
+ CPUM68KState *env = &cpu->env;
+
if (m68k_feature(env, M68K_FEATURE_CF_FPU)) {
gdb_register_coprocessor(env, fpu_gdb_get_reg, fpu_gdb_set_reg,
11, "cf-fp.xml", 18);
}
/* TODO: Add [E]MAC registers. */
-
- cpu_reset(ENV_GET_CPU(env));
- qemu_init_vcpu(env);
- return env;
}
void cpu_m68k_flush_flags(CPUM68KState *env, int cc_op)
@@ -311,8 +310,10 @@ int cpu_m68k_handle_mmu_fault (CPUM68KState *env, target_ulong address, int rw,
be handled by the interrupt controller. Real hardware only requests
the vector when the interrupt is acknowledged by the CPU. For
simplicitly we calculate it when the interrupt is signalled. */
-void m68k_set_irq_level(CPUM68KState *env, int level, uint8_t vector)
+void m68k_set_irq_level(M68kCPU *cpu, int level, uint8_t vector)
{
+ CPUM68KState *env = &cpu->env;
+
env->pending_level = level;
env->pending_vector = vector;
if (level)