MAINTAINERS: Add some ARM related files to the corresponding sections
[qemu/ar7.git] / target-moxie / cpu.c
blobb0be4a7551c1ff50a70db3249384f563b3b0a732
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 "qemu/osdep.h"
21 #include "qapi/error.h"
22 #include "cpu.h"
23 #include "qemu-common.h"
24 #include "migration/vmstate.h"
25 #include "machine.h"
26 #include "exec/exec-all.h"
28 static void moxie_cpu_set_pc(CPUState *cs, vaddr value)
30 MoxieCPU *cpu = MOXIE_CPU(cs);
32 cpu->env.pc = value;
35 static bool moxie_cpu_has_work(CPUState *cs)
37 return cs->interrupt_request & CPU_INTERRUPT_HARD;
40 static void moxie_cpu_reset(CPUState *s)
42 MoxieCPU *cpu = MOXIE_CPU(s);
43 MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(cpu);
44 CPUMoxieState *env = &cpu->env;
46 mcc->parent_reset(s);
48 memset(env, 0, sizeof(CPUMoxieState));
49 env->pc = 0x1000;
51 tlb_flush(s, 1);
54 static void moxie_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)
56 info->mach = bfd_arch_moxie;
57 info->print_insn = print_insn_moxie;
60 static void moxie_cpu_realizefn(DeviceState *dev, Error **errp)
62 CPUState *cs = CPU(dev);
63 MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(dev);
64 Error *local_err = NULL;
66 cpu_exec_realizefn(cs, &local_err);
67 if (local_err != NULL) {
68 error_propagate(errp, local_err);
69 return;
72 qemu_init_vcpu(cs);
73 cpu_reset(cs);
75 mcc->parent_realize(dev, errp);
78 static void moxie_cpu_initfn(Object *obj)
80 CPUState *cs = CPU(obj);
81 MoxieCPU *cpu = MOXIE_CPU(obj);
82 static int inited;
84 cs->env_ptr = &cpu->env;
86 if (tcg_enabled() && !inited) {
87 inited = 1;
88 moxie_translate_init();
92 static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model)
94 ObjectClass *oc;
96 if (cpu_model == NULL) {
97 return NULL;
100 oc = object_class_by_name(cpu_model);
101 if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_MOXIE_CPU) ||
102 object_class_is_abstract(oc))) {
103 return NULL;
105 return oc;
108 static void moxie_cpu_class_init(ObjectClass *oc, void *data)
110 DeviceClass *dc = DEVICE_CLASS(oc);
111 CPUClass *cc = CPU_CLASS(oc);
112 MoxieCPUClass *mcc = MOXIE_CPU_CLASS(oc);
114 mcc->parent_realize = dc->realize;
115 dc->realize = moxie_cpu_realizefn;
117 mcc->parent_reset = cc->reset;
118 cc->reset = moxie_cpu_reset;
120 cc->class_by_name = moxie_cpu_class_by_name;
122 cc->has_work = moxie_cpu_has_work;
123 cc->do_interrupt = moxie_cpu_do_interrupt;
124 cc->dump_state = moxie_cpu_dump_state;
125 cc->set_pc = moxie_cpu_set_pc;
126 #ifdef CONFIG_USER_ONLY
127 cc->handle_mmu_fault = moxie_cpu_handle_mmu_fault;
128 #else
129 cc->get_phys_page_debug = moxie_cpu_get_phys_page_debug;
130 cc->vmsd = &vmstate_moxie_cpu;
131 #endif
132 cc->disas_set_info = moxie_cpu_disas_set_info;
135 static void moxielite_initfn(Object *obj)
137 /* Set cpu feature flags */
140 static void moxie_any_initfn(Object *obj)
142 /* Set cpu feature flags */
145 typedef struct MoxieCPUInfo {
146 const char *name;
147 void (*initfn)(Object *obj);
148 } MoxieCPUInfo;
150 static const MoxieCPUInfo moxie_cpus[] = {
151 { .name = "MoxieLite", .initfn = moxielite_initfn },
152 { .name = "any", .initfn = moxie_any_initfn },
155 MoxieCPU *cpu_moxie_init(const char *cpu_model)
157 return MOXIE_CPU(cpu_generic_init(TYPE_MOXIE_CPU, cpu_model));
160 static void cpu_register(const MoxieCPUInfo *info)
162 TypeInfo type_info = {
163 .parent = TYPE_MOXIE_CPU,
164 .instance_size = sizeof(MoxieCPU),
165 .instance_init = info->initfn,
166 .class_size = sizeof(MoxieCPUClass),
169 type_info.name = g_strdup_printf("%s-" TYPE_MOXIE_CPU, info->name);
170 type_register(&type_info);
171 g_free((void *)type_info.name);
174 static const TypeInfo moxie_cpu_type_info = {
175 .name = TYPE_MOXIE_CPU,
176 .parent = TYPE_CPU,
177 .instance_size = sizeof(MoxieCPU),
178 .instance_init = moxie_cpu_initfn,
179 .class_size = sizeof(MoxieCPUClass),
180 .class_init = moxie_cpu_class_init,
183 static void moxie_cpu_register_types(void)
185 int i;
186 type_register_static(&moxie_cpu_type_info);
187 for (i = 0; i < ARRAY_SIZE(moxie_cpus); i++) {
188 cpu_register(&moxie_cpus[i]);
192 type_init(moxie_cpu_register_types)