blob: 927b1a1e44cc37f84a69ce6e4a8c0d16e66a1f52 [file] [log] [blame]
Anthony Green525bd322013-03-18 15:49:22 -04001/*
2 * QEMU Moxie CPU
3 *
4 * Copyright (c) 2013 Anthony Green
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
Peter Maydelld24688f2016-01-26 18:17:25 +000020#include "qemu/osdep.h"
Markus Armbrusterda34e652016-03-14 09:01:28 +010021#include "qapi/error.h"
Anthony Green525bd322013-03-18 15:49:22 -040022#include "cpu.h"
23#include "qemu-common.h"
24#include "migration/vmstate.h"
25#include "machine.h"
Paolo Bonzini63c91552016-03-15 13:18:37 +010026#include "exec/exec-all.h"
Anthony Green525bd322013-03-18 15:49:22 -040027
Andreas Färbera10b9782013-06-28 20:43:26 +020028static void moxie_cpu_set_pc(CPUState *cs, vaddr value)
29{
30 MoxieCPU *cpu = MOXIE_CPU(cs);
31
32 cpu->env.pc = value;
33}
34
Andreas Färber8c2e1b02013-08-25 18:53:55 +020035static bool moxie_cpu_has_work(CPUState *cs)
36{
37 return cs->interrupt_request & CPU_INTERRUPT_HARD;
38}
39
Anthony Green525bd322013-03-18 15:49:22 -040040static void moxie_cpu_reset(CPUState *s)
41{
42 MoxieCPU *cpu = MOXIE_CPU(s);
43 MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(cpu);
44 CPUMoxieState *env = &cpu->env;
45
Anthony Green525bd322013-03-18 15:49:22 -040046 mcc->parent_reset(s);
47
Alex Bennée1f5c00c2016-11-14 14:19:17 +000048 memset(env, 0, offsetof(CPUMoxieState, end_reset_fields));
Anthony Green525bd322013-03-18 15:49:22 -040049 env->pc = 0x1000;
Anthony Green525bd322013-03-18 15:49:22 -040050}
51
Peter Crosthwaite9f87a4c2015-07-11 18:59:59 -070052static void moxie_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)
53{
54 info->mach = bfd_arch_moxie;
55 info->print_insn = print_insn_moxie;
56}
57
Anthony Green525bd322013-03-18 15:49:22 -040058static void moxie_cpu_realizefn(DeviceState *dev, Error **errp)
59{
Andreas Färber14a10fc2013-07-27 02:53:25 +020060 CPUState *cs = CPU(dev);
Andreas Färberc643bed2013-05-27 03:23:24 +020061 MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(dev);
Laurent Vivierce5b1bb2016-10-20 13:26:03 +020062 Error *local_err = NULL;
63
64 cpu_exec_realizefn(cs, &local_err);
65 if (local_err != NULL) {
66 error_propagate(errp, local_err);
67 return;
68 }
Anthony Green525bd322013-03-18 15:49:22 -040069
Andreas Färber14a10fc2013-07-27 02:53:25 +020070 qemu_init_vcpu(cs);
71 cpu_reset(cs);
Anthony Green525bd322013-03-18 15:49:22 -040072
Andreas Färberc643bed2013-05-27 03:23:24 +020073 mcc->parent_realize(dev, errp);
Anthony Green525bd322013-03-18 15:49:22 -040074}
75
76static void moxie_cpu_initfn(Object *obj)
77{
78 CPUState *cs = CPU(obj);
79 MoxieCPU *cpu = MOXIE_CPU(obj);
80 static int inited;
81
82 cs->env_ptr = &cpu->env;
Anthony Green525bd322013-03-18 15:49:22 -040083
84 if (tcg_enabled() && !inited) {
85 inited = 1;
86 moxie_translate_init();
87 }
88}
89
90static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model)
91{
92 ObjectClass *oc;
93
94 if (cpu_model == NULL) {
95 return NULL;
96 }
97
98 oc = object_class_by_name(cpu_model);
99 if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_MOXIE_CPU) ||
100 object_class_is_abstract(oc))) {
101 return NULL;
102 }
103 return oc;
104}
105
106static void moxie_cpu_class_init(ObjectClass *oc, void *data)
107{
108 DeviceClass *dc = DEVICE_CLASS(oc);
109 CPUClass *cc = CPU_CLASS(oc);
110 MoxieCPUClass *mcc = MOXIE_CPU_CLASS(oc);
111
112 mcc->parent_realize = dc->realize;
113 dc->realize = moxie_cpu_realizefn;
114
115 mcc->parent_reset = cc->reset;
116 cc->reset = moxie_cpu_reset;
117
118 cc->class_by_name = moxie_cpu_class_by_name;
119
Andreas Färber8c2e1b02013-08-25 18:53:55 +0200120 cc->has_work = moxie_cpu_has_work;
Dunrong Huang53574062013-03-31 09:35:53 +0800121 cc->do_interrupt = moxie_cpu_do_interrupt;
Andreas Färber878096e2013-05-27 01:33:50 +0200122 cc->dump_state = moxie_cpu_dump_state;
Andreas Färbera10b9782013-06-28 20:43:26 +0200123 cc->set_pc = moxie_cpu_set_pc;
Andreas Färber75104542013-08-26 03:01:33 +0200124#ifdef CONFIG_USER_ONLY
125 cc->handle_mmu_fault = moxie_cpu_handle_mmu_fault;
126#else
Andreas Färber00b941e2013-06-29 18:55:54 +0200127 cc->get_phys_page_debug = moxie_cpu_get_phys_page_debug;
128 cc->vmsd = &vmstate_moxie_cpu;
129#endif
Peter Crosthwaite9f87a4c2015-07-11 18:59:59 -0700130 cc->disas_set_info = moxie_cpu_disas_set_info;
Anthony Green525bd322013-03-18 15:49:22 -0400131}
132
133static void moxielite_initfn(Object *obj)
134{
135 /* Set cpu feature flags */
136}
137
138static void moxie_any_initfn(Object *obj)
139{
140 /* Set cpu feature flags */
141}
142
143typedef struct MoxieCPUInfo {
144 const char *name;
145 void (*initfn)(Object *obj);
146} MoxieCPUInfo;
147
148static const MoxieCPUInfo moxie_cpus[] = {
149 { .name = "MoxieLite", .initfn = moxielite_initfn },
150 { .name = "any", .initfn = moxie_any_initfn },
151};
152
153MoxieCPU *cpu_moxie_init(const char *cpu_model)
154{
Andreas Färber92626852014-03-04 03:17:10 +0100155 return MOXIE_CPU(cpu_generic_init(TYPE_MOXIE_CPU, cpu_model));
Anthony Green525bd322013-03-18 15:49:22 -0400156}
157
158static void cpu_register(const MoxieCPUInfo *info)
159{
160 TypeInfo type_info = {
161 .parent = TYPE_MOXIE_CPU,
162 .instance_size = sizeof(MoxieCPU),
163 .instance_init = info->initfn,
164 .class_size = sizeof(MoxieCPUClass),
165 };
166
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);
170}
171
172static 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,
179};
180
181static void moxie_cpu_register_types(void)
182{
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]);
187 }
188}
189
190type_init(moxie_cpu_register_types)