]>
Commit | Line | Data |
---|---|---|
525bd324 AG |
1 | /* |
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 | ||
20 | #include "cpu.h" | |
21 | #include "qemu-common.h" | |
22 | #include "migration/vmstate.h" | |
23 | #include "machine.h" | |
24 | ||
a10b978c AF |
25 | static void moxie_cpu_set_pc(CPUState *cs, vaddr value) |
26 | { | |
27 | MoxieCPU *cpu = MOXIE_CPU(cs); | |
28 | ||
29 | cpu->env.pc = value; | |
30 | } | |
31 | ||
8c2e1b00 AF |
32 | static bool moxie_cpu_has_work(CPUState *cs) |
33 | { | |
34 | return cs->interrupt_request & CPU_INTERRUPT_HARD; | |
35 | } | |
36 | ||
525bd324 AG |
37 | static void moxie_cpu_reset(CPUState *s) |
38 | { | |
39 | MoxieCPU *cpu = MOXIE_CPU(s); | |
40 | MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(cpu); | |
41 | CPUMoxieState *env = &cpu->env; | |
42 | ||
525bd324 AG |
43 | mcc->parent_reset(s); |
44 | ||
f0c3c505 | 45 | memset(env, 0, sizeof(CPUMoxieState)); |
525bd324 AG |
46 | env->pc = 0x1000; |
47 | ||
00c8cb0a | 48 | tlb_flush(s, 1); |
525bd324 AG |
49 | } |
50 | ||
51 | static void moxie_cpu_realizefn(DeviceState *dev, Error **errp) | |
52 | { | |
14a10fc3 | 53 | CPUState *cs = CPU(dev); |
c643bed9 | 54 | MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(dev); |
525bd324 | 55 | |
14a10fc3 AF |
56 | qemu_init_vcpu(cs); |
57 | cpu_reset(cs); | |
525bd324 | 58 | |
c643bed9 | 59 | mcc->parent_realize(dev, errp); |
525bd324 AG |
60 | } |
61 | ||
62 | static void moxie_cpu_initfn(Object *obj) | |
63 | { | |
64 | CPUState *cs = CPU(obj); | |
65 | MoxieCPU *cpu = MOXIE_CPU(obj); | |
66 | static int inited; | |
67 | ||
68 | cs->env_ptr = &cpu->env; | |
4bad9e39 | 69 | cpu_exec_init(cs, &error_abort); |
525bd324 AG |
70 | |
71 | if (tcg_enabled() && !inited) { | |
72 | inited = 1; | |
73 | moxie_translate_init(); | |
74 | } | |
75 | } | |
76 | ||
77 | static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model) | |
78 | { | |
79 | ObjectClass *oc; | |
80 | ||
81 | if (cpu_model == NULL) { | |
82 | return NULL; | |
83 | } | |
84 | ||
85 | oc = object_class_by_name(cpu_model); | |
86 | if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_MOXIE_CPU) || | |
87 | object_class_is_abstract(oc))) { | |
88 | return NULL; | |
89 | } | |
90 | return oc; | |
91 | } | |
92 | ||
93 | static void moxie_cpu_class_init(ObjectClass *oc, void *data) | |
94 | { | |
95 | DeviceClass *dc = DEVICE_CLASS(oc); | |
96 | CPUClass *cc = CPU_CLASS(oc); | |
97 | MoxieCPUClass *mcc = MOXIE_CPU_CLASS(oc); | |
98 | ||
99 | mcc->parent_realize = dc->realize; | |
100 | dc->realize = moxie_cpu_realizefn; | |
101 | ||
102 | mcc->parent_reset = cc->reset; | |
103 | cc->reset = moxie_cpu_reset; | |
104 | ||
105 | cc->class_by_name = moxie_cpu_class_by_name; | |
106 | ||
8c2e1b00 | 107 | cc->has_work = moxie_cpu_has_work; |
53574064 | 108 | cc->do_interrupt = moxie_cpu_do_interrupt; |
878096ee | 109 | cc->dump_state = moxie_cpu_dump_state; |
a10b978c | 110 | cc->set_pc = moxie_cpu_set_pc; |
7510454e AF |
111 | #ifdef CONFIG_USER_ONLY |
112 | cc->handle_mmu_fault = moxie_cpu_handle_mmu_fault; | |
113 | #else | |
00b941e5 AF |
114 | cc->get_phys_page_debug = moxie_cpu_get_phys_page_debug; |
115 | cc->vmsd = &vmstate_moxie_cpu; | |
116 | #endif | |
525bd324 AG |
117 | } |
118 | ||
119 | static void moxielite_initfn(Object *obj) | |
120 | { | |
121 | /* Set cpu feature flags */ | |
122 | } | |
123 | ||
124 | static void moxie_any_initfn(Object *obj) | |
125 | { | |
126 | /* Set cpu feature flags */ | |
127 | } | |
128 | ||
129 | typedef struct MoxieCPUInfo { | |
130 | const char *name; | |
131 | void (*initfn)(Object *obj); | |
132 | } MoxieCPUInfo; | |
133 | ||
134 | static const MoxieCPUInfo moxie_cpus[] = { | |
135 | { .name = "MoxieLite", .initfn = moxielite_initfn }, | |
136 | { .name = "any", .initfn = moxie_any_initfn }, | |
137 | }; | |
138 | ||
139 | MoxieCPU *cpu_moxie_init(const char *cpu_model) | |
140 | { | |
9262685b | 141 | return MOXIE_CPU(cpu_generic_init(TYPE_MOXIE_CPU, cpu_model)); |
525bd324 AG |
142 | } |
143 | ||
144 | static void cpu_register(const MoxieCPUInfo *info) | |
145 | { | |
146 | TypeInfo type_info = { | |
147 | .parent = TYPE_MOXIE_CPU, | |
148 | .instance_size = sizeof(MoxieCPU), | |
149 | .instance_init = info->initfn, | |
150 | .class_size = sizeof(MoxieCPUClass), | |
151 | }; | |
152 | ||
153 | type_info.name = g_strdup_printf("%s-" TYPE_MOXIE_CPU, info->name); | |
154 | type_register(&type_info); | |
155 | g_free((void *)type_info.name); | |
156 | } | |
157 | ||
158 | static const TypeInfo moxie_cpu_type_info = { | |
159 | .name = TYPE_MOXIE_CPU, | |
160 | .parent = TYPE_CPU, | |
161 | .instance_size = sizeof(MoxieCPU), | |
162 | .instance_init = moxie_cpu_initfn, | |
163 | .class_size = sizeof(MoxieCPUClass), | |
164 | .class_init = moxie_cpu_class_init, | |
165 | }; | |
166 | ||
167 | static void moxie_cpu_register_types(void) | |
168 | { | |
169 | int i; | |
170 | type_register_static(&moxie_cpu_type_info); | |
171 | for (i = 0; i < ARRAY_SIZE(moxie_cpus); i++) { | |
172 | cpu_register(&moxie_cpus[i]); | |
173 | } | |
174 | } | |
175 | ||
176 | type_init(moxie_cpu_register_types) |