diff options
author | Blue Swirl <blauwirbel@gmail.com> | 2012-05-01 09:27:53 +0000 |
---|---|---|
committer | Blue Swirl <blauwirbel@gmail.com> | 2012-05-01 09:27:53 +0000 |
commit | 61d25e1548b5e5ec8b670e72e82a2a7b909f9d52 (patch) | |
tree | 6cfa2f23703fe891504e71ac4349de227e7ff746 /target-m68k/helper.c | |
parent | 42fe1c245f0239ebcdc084740a1777ac3699d071 (diff) | |
parent | 894a84e632e4e71eaa3588d7ca9854bf4d9027ea (diff) |
Merge branch 'qom-cpu-rest.v1' of git://github.com/afaerber/qemu-cpu
* 'qom-cpu-rest.v1' of git://github.com/afaerber/qemu-cpu:
Makefile: Simplify compilation of target-*/cpu.c
target-mips: Start QOM'ifying CPU init
target-mips: QOM'ify CPU
target-m68k: Add QOM CPU subclasses
target-m68k: Start QOM'ifying CPU init
target-m68k: QOM'ify CPU reset
target-m68k: QOM'ify CPU
target-sh4: Start QOM'ifying CPU init
target-sh4: QOM'ify CPU reset
target-sh4: QOM'ify CPU
MAINTAINERS: Downgrade target-mips and target-sh4 to Odd Fixes
MAINTAINERS: Downgrade target-m68k to Odd Fixes
Diffstat (limited to 'target-m68k/helper.c')
-rw-r--r-- | target-m68k/helper.c | 165 |
1 files changed, 54 insertions, 111 deletions
diff --git a/target-m68k/helper.c b/target-m68k/helper.c index 1feed9be67..f428375d7d 100644 --- a/target-m68k/helper.c +++ b/target-m68k/helper.c @@ -25,35 +25,50 @@ #define SIGNBIT (1u << 31) -enum m68k_cpuid { - M68K_CPUID_M5206, - M68K_CPUID_M5208, - M68K_CPUID_CFV4E, - M68K_CPUID_ANY, -}; - -typedef struct m68k_def_t m68k_def_t; - -struct m68k_def_t { - const char * name; - enum m68k_cpuid id; -}; - -static m68k_def_t m68k_cpu_defs[] = { - {"m5206", M68K_CPUID_M5206}, - {"m5208", M68K_CPUID_M5208}, - {"cfv4e", M68K_CPUID_CFV4E}, - {"any", M68K_CPUID_ANY}, - {NULL, 0}, -}; +typedef struct M68kCPUListState { + fprintf_function cpu_fprintf; + FILE *file; +} M68kCPUListState; + +/* Sort alphabetically, except for "any". */ +static gint m68k_cpu_list_compare(gconstpointer a, gconstpointer b) +{ + ObjectClass *class_a = (ObjectClass *)a; + ObjectClass *class_b = (ObjectClass *)b; + const char *name_a, *name_b; + + name_a = object_class_get_name(class_a); + name_b = object_class_get_name(class_b); + if (strcmp(name_a, "any") == 0) { + return 1; + } else if (strcmp(name_b, "any") == 0) { + return -1; + } else { + return strcasecmp(name_a, name_b); + } +} + +static void m68k_cpu_list_entry(gpointer data, gpointer user_data) +{ + ObjectClass *c = data; + M68kCPUListState *s = user_data; + + (*s->cpu_fprintf)(s->file, "%s\n", + object_class_get_name(c)); +} void m68k_cpu_list(FILE *f, fprintf_function cpu_fprintf) { - unsigned int i; + M68kCPUListState s = { + .file = f, + .cpu_fprintf = cpu_fprintf, + }; + GSList *list; - for (i = 0; m68k_cpu_defs[i].name; i++) { - (*cpu_fprintf)(f, "%s\n", m68k_cpu_defs[i].name); - } + list = object_class_get_list(TYPE_M68K_CPU, false); + list = g_slist_sort(list, m68k_cpu_list_compare); + g_slist_foreach(list, m68k_cpu_list_entry, &s); + g_slist_free(list); } static int fpu_gdb_get_reg(CPUM68KState *env, uint8_t *mem_buf, int n) @@ -83,92 +98,23 @@ static int fpu_gdb_set_reg(CPUM68KState *env, uint8_t *mem_buf, int n) return 0; } -static void m68k_set_feature(CPUM68KState *env, int feature) -{ - env->features |= (1u << feature); -} - -static int cpu_m68k_set_model(CPUM68KState *env, const char *name) -{ - m68k_def_t *def; - - for (def = m68k_cpu_defs; def->name; def++) { - if (strcmp(def->name, name) == 0) - break; - } - if (!def->name) - return -1; - - switch (def->id) { - case M68K_CPUID_M5206: - m68k_set_feature(env, M68K_FEATURE_CF_ISA_A); - break; - case M68K_CPUID_M5208: - m68k_set_feature(env, M68K_FEATURE_CF_ISA_A); - m68k_set_feature(env, M68K_FEATURE_CF_ISA_APLUSC); - m68k_set_feature(env, M68K_FEATURE_BRAL); - m68k_set_feature(env, M68K_FEATURE_CF_EMAC); - m68k_set_feature(env, M68K_FEATURE_USP); - break; - case M68K_CPUID_CFV4E: - m68k_set_feature(env, M68K_FEATURE_CF_ISA_A); - m68k_set_feature(env, M68K_FEATURE_CF_ISA_B); - m68k_set_feature(env, M68K_FEATURE_BRAL); - m68k_set_feature(env, M68K_FEATURE_CF_FPU); - m68k_set_feature(env, M68K_FEATURE_CF_EMAC); - m68k_set_feature(env, M68K_FEATURE_USP); - break; - case M68K_CPUID_ANY: - m68k_set_feature(env, M68K_FEATURE_CF_ISA_A); - m68k_set_feature(env, M68K_FEATURE_CF_ISA_B); - m68k_set_feature(env, M68K_FEATURE_CF_ISA_APLUSC); - m68k_set_feature(env, M68K_FEATURE_BRAL); - m68k_set_feature(env, M68K_FEATURE_CF_FPU); - /* MAC and EMAC are mututally exclusive, so pick EMAC. - It's mostly backwards compatible. */ - m68k_set_feature(env, M68K_FEATURE_CF_EMAC); - m68k_set_feature(env, M68K_FEATURE_CF_EMAC_B); - m68k_set_feature(env, M68K_FEATURE_USP); - m68k_set_feature(env, M68K_FEATURE_EXT_FULL); - m68k_set_feature(env, M68K_FEATURE_WORD_INDEX); - break; - } - - register_m68k_insns(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. */ - return 0; -} - void cpu_state_reset(CPUM68KState *env) { - if (qemu_loglevel_mask(CPU_LOG_RESET)) { - qemu_log("CPU Reset (CPU %d)\n", env->cpu_index); - log_cpu_state(env, 0); - } - - memset(env, 0, offsetof(CPUM68KState, breakpoints)); -#if !defined (CONFIG_USER_ONLY) - env->sr = 0x2700; -#endif - m68k_switch_sp(env); - /* ??? FP regs should be initialized to NaN. */ - env->cc_op = CC_OP_FLAGS; - /* TODO: We should set PC from the interrupt vector. */ - env->pc = 0; - tlb_flush(env, 1); + cpu_reset(ENV_GET_CPU(env)); } CPUM68KState *cpu_m68k_init(const char *cpu_model) { + M68kCPU *cpu; CPUM68KState *env; static int inited; - env = g_malloc0(sizeof(CPUM68KState)); - cpu_exec_init(env); + if (object_class_by_name(cpu_model) == NULL) { + return NULL; + } + cpu = M68K_CPU(object_new(cpu_model)); + env = &cpu->env; + if (!inited) { inited = 1; m68k_tcg_init(); @@ -176,21 +122,18 @@ CPUM68KState *cpu_m68k_init(const char *cpu_model) env->cpu_model_str = cpu_model; - if (cpu_m68k_set_model(env, cpu_model) < 0) { - cpu_m68k_close(env); - return NULL; + register_m68k_insns(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_state_reset(env); + cpu_reset(ENV_GET_CPU(env)); qemu_init_vcpu(env); return env; } -void cpu_m68k_close(CPUM68KState *env) -{ - g_free(env); -} - void cpu_m68k_flush_flags(CPUM68KState *env, int cc_op) { int flags; |