qapi-schema: dump-guest-memory: Improve text
[qemu/ar7.git] / target-moxie / cpu.c
blob0c60c65d317924a2a05859145b796c99108f4013
1 /*
2 * QEMU Moxie CPU
4 * Copyright (c) 2013 Anthony Green
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "cpu.h"
21 #include "qemu-common.h"
22 #include "migration/vmstate.h"
23 #include "machine.h"
25 static void moxie_cpu_set_pc(CPUState *cs, vaddr value)
27 MoxieCPU *cpu = MOXIE_CPU(cs);
29 cpu->env.pc = value;
32 static bool moxie_cpu_has_work(CPUState *cs)
34 return cs->interrupt_request & CPU_INTERRUPT_HARD;
37 static void moxie_cpu_reset(CPUState *s)
39 MoxieCPU *cpu = MOXIE_CPU(s);
40 MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(cpu);
41 CPUMoxieState *env = &cpu->env;
43 mcc->parent_reset(s);
45 memset(env, 0, sizeof(CPUMoxieState));
46 env->pc = 0x1000;
48 tlb_flush(s, 1);
51 static void moxie_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)
53 info->mach = bfd_arch_moxie;
54 info->print_insn = print_insn_moxie;
57 static void moxie_cpu_realizefn(DeviceState *dev, Error **errp)
59 CPUState *cs = CPU(dev);
60 MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(dev);
62 qemu_init_vcpu(cs);
63 cpu_reset(cs);
65 mcc->parent_realize(dev, errp);
68 static void moxie_cpu_initfn(Object *obj)
70 CPUState *cs = CPU(obj);
71 MoxieCPU *cpu = MOXIE_CPU(obj);
72 static int inited;
74 cs->env_ptr = &cpu->env;
75 cpu_exec_init(cs, &error_abort);
77 if (tcg_enabled() && !inited) {
78 inited = 1;
79 moxie_translate_init();
83 static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model)
85 ObjectClass *oc;
87 if (cpu_model == NULL) {
88 return NULL;
91 oc = object_class_by_name(cpu_model);
92 if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_MOXIE_CPU) ||
93 object_class_is_abstract(oc))) {
94 return NULL;
96 return oc;
99 static void moxie_cpu_class_init(ObjectClass *oc, void *data)
101 DeviceClass *dc = DEVICE_CLASS(oc);
102 CPUClass *cc = CPU_CLASS(oc);
103 MoxieCPUClass *mcc = MOXIE_CPU_CLASS(oc);
105 mcc->parent_realize = dc->realize;
106 dc->realize = moxie_cpu_realizefn;
108 mcc->parent_reset = cc->reset;
109 cc->reset = moxie_cpu_reset;
111 cc->class_by_name = moxie_cpu_class_by_name;
113 cc->has_work = moxie_cpu_has_work;
114 cc->do_interrupt = moxie_cpu_do_interrupt;
115 cc->dump_state = moxie_cpu_dump_state;
116 cc->set_pc = moxie_cpu_set_pc;
117 #ifdef CONFIG_USER_ONLY
118 cc->handle_mmu_fault = moxie_cpu_handle_mmu_fault;
119 #else
120 cc->get_phys_page_debug = moxie_cpu_get_phys_page_debug;
121 cc->vmsd = &vmstate_moxie_cpu;
122 #endif
123 cc->disas_set_info = moxie_cpu_disas_set_info;
126 * Reason: moxie_cpu_initfn() calls cpu_exec_init(), which saves
127 * the object in cpus -> dangling pointer after final
128 * object_unref().
130 dc->cannot_destroy_with_object_finalize_yet = true;
133 static void moxielite_initfn(Object *obj)
135 /* Set cpu feature flags */
138 static void moxie_any_initfn(Object *obj)
140 /* Set cpu feature flags */
143 typedef struct MoxieCPUInfo {
144 const char *name;
145 void (*initfn)(Object *obj);
146 } MoxieCPUInfo;
148 static const MoxieCPUInfo moxie_cpus[] = {
149 { .name = "MoxieLite", .initfn = moxielite_initfn },
150 { .name = "any", .initfn = moxie_any_initfn },
153 MoxieCPU *cpu_moxie_init(const char *cpu_model)
155 return MOXIE_CPU(cpu_generic_init(TYPE_MOXIE_CPU, cpu_model));
158 static void cpu_register(const MoxieCPUInfo *info)
160 TypeInfo type_info = {
161 .parent = TYPE_MOXIE_CPU,
162 .instance_size = sizeof(MoxieCPU),
163 .instance_init = info->initfn,
164 .class_size = sizeof(MoxieCPUClass),
167 type_info.name = g_strdup_printf("%s-" TYPE_MOXIE_CPU, info->name);
168 type_register(&type_info);
169 g_free((void *)type_info.name);
172 static const TypeInfo moxie_cpu_type_info = {
173 .name = TYPE_MOXIE_CPU,
174 .parent = TYPE_CPU,
175 .instance_size = sizeof(MoxieCPU),
176 .instance_init = moxie_cpu_initfn,
177 .class_size = sizeof(MoxieCPUClass),
178 .class_init = moxie_cpu_class_init,
181 static void moxie_cpu_register_types(void)
183 int i;
184 type_register_static(&moxie_cpu_type_info);
185 for (i = 0; i < ARRAY_SIZE(moxie_cpus); i++) {
186 cpu_register(&moxie_cpus[i]);
190 type_init(moxie_cpu_register_types)