]>
Commit | Line | Data |
---|---|---|
0f71a709 AF |
1 | /* |
2 | * QEMU MIPS CPU | |
3 | * | |
4 | * Copyright (c) 2012 SUSE LINUX Products GmbH | |
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 Lesser General Public | |
17 | * License along with this library; if not, see | |
18 | * <http://www.gnu.org/licenses/lgpl-2.1.html> | |
19 | */ | |
20 | ||
c684822a | 21 | #include "qemu/osdep.h" |
da34e65c | 22 | #include "qapi/error.h" |
0f71a709 | 23 | #include "cpu.h" |
26aa3d9a | 24 | #include "internal.h" |
14c03ab9 | 25 | #include "kvm_mips.h" |
0b8fa32f | 26 | #include "qemu/module.h" |
14c03ab9 | 27 | #include "sysemu/kvm.h" |
63c91552 | 28 | #include "exec/exec-all.h" |
0f71a709 AF |
29 | |
30 | ||
f45748f1 AF |
31 | static void mips_cpu_set_pc(CPUState *cs, vaddr value) |
32 | { | |
33 | MIPSCPU *cpu = MIPS_CPU(cs); | |
34 | CPUMIPSState *env = &cpu->env; | |
35 | ||
36 | env->active_tc.PC = value & ~(target_ulong)1; | |
37 | if (value & 1) { | |
38 | env->hflags |= MIPS_HFLAG_M16; | |
39 | } else { | |
40 | env->hflags &= ~(MIPS_HFLAG_M16); | |
41 | } | |
42 | } | |
43 | ||
bdf7ae5b AF |
44 | static void mips_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb) |
45 | { | |
46 | MIPSCPU *cpu = MIPS_CPU(cs); | |
47 | CPUMIPSState *env = &cpu->env; | |
48 | ||
49 | env->active_tc.PC = tb->pc; | |
50 | env->hflags &= ~MIPS_HFLAG_BMASK; | |
51 | env->hflags |= tb->flags & MIPS_HFLAG_BMASK; | |
52 | } | |
53 | ||
8c2e1b00 AF |
54 | static bool mips_cpu_has_work(CPUState *cs) |
55 | { | |
56 | MIPSCPU *cpu = MIPS_CPU(cs); | |
57 | CPUMIPSState *env = &cpu->env; | |
58 | bool has_work = false; | |
59 | ||
cf02a116 AM |
60 | /* |
61 | * Prior to MIPS Release 6 it is implementation dependent if non-enabled | |
62 | * interrupts wake-up the CPU, however most of the implementations only | |
63 | * check for interrupts that can be taken. | |
64 | */ | |
8c2e1b00 AF |
65 | if ((cs->interrupt_request & CPU_INTERRUPT_HARD) && |
66 | cpu_mips_hw_interrupts_pending(env)) { | |
7540a43a LA |
67 | if (cpu_mips_hw_interrupts_enabled(env) || |
68 | (env->insn_flags & ISA_MIPS32R6)) { | |
71ca034a LA |
69 | has_work = true; |
70 | } | |
8c2e1b00 AF |
71 | } |
72 | ||
73 | /* MIPS-MT has the ability to halt the CPU. */ | |
74 | if (env->CP0_Config3 & (1 << CP0C3_MT)) { | |
cf02a116 AM |
75 | /* |
76 | * The QEMU model will issue an _WAKE request whenever the CPUs | |
77 | * should be woken up. | |
78 | */ | |
8c2e1b00 AF |
79 | if (cs->interrupt_request & CPU_INTERRUPT_WAKE) { |
80 | has_work = true; | |
81 | } | |
82 | ||
83 | if (!mips_vpe_active(env)) { | |
84 | has_work = false; | |
85 | } | |
86 | } | |
01bc435b YK |
87 | /* MIPS Release 6 has the ability to halt the CPU. */ |
88 | if (env->CP0_Config5 & (1 << CP0C5_VP)) { | |
89 | if (cs->interrupt_request & CPU_INTERRUPT_WAKE) { | |
90 | has_work = true; | |
91 | } | |
92 | if (!mips_vp_active(env)) { | |
93 | has_work = false; | |
94 | } | |
95 | } | |
8c2e1b00 AF |
96 | return has_work; |
97 | } | |
98 | ||
0f71a709 AF |
99 | /* CPUClass::reset() */ |
100 | static void mips_cpu_reset(CPUState *s) | |
101 | { | |
102 | MIPSCPU *cpu = MIPS_CPU(s); | |
103 | MIPSCPUClass *mcc = MIPS_CPU_GET_CLASS(cpu); | |
104 | CPUMIPSState *env = &cpu->env; | |
105 | ||
106 | mcc->parent_reset(s); | |
107 | ||
1f5c00cf | 108 | memset(env, 0, offsetof(CPUMIPSState, end_reset_fields)); |
55e5c285 | 109 | |
0f71a709 | 110 | cpu_state_reset(env); |
14c03ab9 JH |
111 | |
112 | #ifndef CONFIG_USER_ONLY | |
113 | if (kvm_enabled()) { | |
114 | kvm_mips_reset_vcpu(cpu); | |
115 | } | |
116 | #endif | |
0f71a709 AF |
117 | } |
118 | ||
cf02a116 AM |
119 | static void mips_cpu_disas_set_info(CPUState *s, disassemble_info *info) |
120 | { | |
89a955e8 AM |
121 | MIPSCPU *cpu = MIPS_CPU(s); |
122 | CPUMIPSState *env = &cpu->env; | |
123 | ||
124 | if (!(env->insn_flags & ISA_NANOMIPS32)) { | |
63a946c7 | 125 | #ifdef TARGET_WORDS_BIGENDIAN |
89a955e8 | 126 | info->print_insn = print_insn_big_mips; |
63a946c7 | 127 | #else |
89a955e8 | 128 | info->print_insn = print_insn_little_mips; |
63a946c7 | 129 | #endif |
89a955e8 AM |
130 | } else { |
131 | #if defined(CONFIG_NANOMIPS_DIS) | |
132 | info->print_insn = print_insn_nanomips; | |
133 | #endif | |
134 | } | |
63a946c7 PC |
135 | } |
136 | ||
c1caf1d9 AF |
137 | static void mips_cpu_realizefn(DeviceState *dev, Error **errp) |
138 | { | |
14a10fc3 | 139 | CPUState *cs = CPU(dev); |
df4dc102 | 140 | MIPSCPU *cpu = MIPS_CPU(dev); |
c1caf1d9 | 141 | MIPSCPUClass *mcc = MIPS_CPU_GET_CLASS(dev); |
ce5b1bbf LV |
142 | Error *local_err = NULL; |
143 | ||
144 | cpu_exec_realizefn(cs, &local_err); | |
145 | if (local_err != NULL) { | |
146 | error_propagate(errp, local_err); | |
147 | return; | |
148 | } | |
c1caf1d9 | 149 | |
df4dc102 PMD |
150 | cpu_mips_realize_env(&cpu->env); |
151 | ||
14a10fc3 AF |
152 | cpu_reset(cs); |
153 | qemu_init_vcpu(cs); | |
c1caf1d9 AF |
154 | |
155 | mcc->parent_realize(dev, errp); | |
156 | } | |
157 | ||
5b0c40f7 AF |
158 | static void mips_cpu_initfn(Object *obj) |
159 | { | |
160 | MIPSCPU *cpu = MIPS_CPU(obj); | |
161 | CPUMIPSState *env = &cpu->env; | |
41da212c | 162 | MIPSCPUClass *mcc = MIPS_CPU_GET_CLASS(obj); |
5b0c40f7 | 163 | |
7506ed90 | 164 | cpu_set_cpustate_pointers(cpu); |
41da212c | 165 | env->cpu_model = mcc->cpu_def; |
5b0c40f7 AF |
166 | } |
167 | ||
41da212c IM |
168 | static char *mips_cpu_type_name(const char *cpu_model) |
169 | { | |
a7519f2b | 170 | return g_strdup_printf(MIPS_CPU_TYPE_NAME("%s"), cpu_model); |
41da212c IM |
171 | } |
172 | ||
173 | static ObjectClass *mips_cpu_class_by_name(const char *cpu_model) | |
174 | { | |
175 | ObjectClass *oc; | |
176 | char *typename; | |
177 | ||
41da212c IM |
178 | typename = mips_cpu_type_name(cpu_model); |
179 | oc = object_class_by_name(typename); | |
180 | g_free(typename); | |
181 | return oc; | |
182 | } | |
183 | ||
0f71a709 AF |
184 | static void mips_cpu_class_init(ObjectClass *c, void *data) |
185 | { | |
186 | MIPSCPUClass *mcc = MIPS_CPU_CLASS(c); | |
187 | CPUClass *cc = CPU_CLASS(c); | |
c1caf1d9 AF |
188 | DeviceClass *dc = DEVICE_CLASS(c); |
189 | ||
bf853881 PMD |
190 | device_class_set_parent_realize(dc, mips_cpu_realizefn, |
191 | &mcc->parent_realize); | |
0f71a709 AF |
192 | mcc->parent_reset = cc->reset; |
193 | cc->reset = mips_cpu_reset; | |
97a8ea5a | 194 | |
41da212c | 195 | cc->class_by_name = mips_cpu_class_by_name; |
8c2e1b00 | 196 | cc->has_work = mips_cpu_has_work; |
97a8ea5a | 197 | cc->do_interrupt = mips_cpu_do_interrupt; |
fa4faba4 | 198 | cc->cpu_exec_interrupt = mips_cpu_exec_interrupt; |
878096ee | 199 | cc->dump_state = mips_cpu_dump_state; |
f45748f1 | 200 | cc->set_pc = mips_cpu_set_pc; |
bdf7ae5b | 201 | cc->synchronize_from_tb = mips_cpu_synchronize_from_tb; |
5b50e790 AF |
202 | cc->gdb_read_register = mips_cpu_gdb_read_register; |
203 | cc->gdb_write_register = mips_cpu_gdb_write_register; | |
931d019f | 204 | #ifndef CONFIG_USER_ONLY |
4f02a06d | 205 | cc->do_transaction_failed = mips_cpu_do_transaction_failed; |
93e22326 | 206 | cc->do_unaligned_access = mips_cpu_do_unaligned_access; |
00b941e5 | 207 | cc->get_phys_page_debug = mips_cpu_get_phys_page_debug; |
04cd7962 | 208 | cc->vmsd = &vmstate_mips_cpu; |
00b941e5 | 209 | #endif |
63a946c7 | 210 | cc->disas_set_info = mips_cpu_disas_set_info; |
74d7fc7f | 211 | #ifdef CONFIG_TCG |
55c3ceef | 212 | cc->tcg_initialize = mips_tcg_init; |
931d019f | 213 | cc->tlb_fill = mips_cpu_tlb_fill; |
74d7fc7f | 214 | #endif |
a0e372f0 AF |
215 | |
216 | cc->gdb_num_core_regs = 73; | |
2472b6c0 | 217 | cc->gdb_stop_before_watchpoint = true; |
0f71a709 AF |
218 | } |
219 | ||
220 | static const TypeInfo mips_cpu_type_info = { | |
221 | .name = TYPE_MIPS_CPU, | |
222 | .parent = TYPE_CPU, | |
223 | .instance_size = sizeof(MIPSCPU), | |
5b0c40f7 | 224 | .instance_init = mips_cpu_initfn, |
41da212c | 225 | .abstract = true, |
0f71a709 AF |
226 | .class_size = sizeof(MIPSCPUClass), |
227 | .class_init = mips_cpu_class_init, | |
228 | }; | |
229 | ||
41da212c IM |
230 | static void mips_cpu_cpudef_class_init(ObjectClass *oc, void *data) |
231 | { | |
232 | MIPSCPUClass *mcc = MIPS_CPU_CLASS(oc); | |
233 | mcc->cpu_def = data; | |
234 | } | |
235 | ||
236 | static void mips_register_cpudef_type(const struct mips_def_t *def) | |
237 | { | |
238 | char *typename = mips_cpu_type_name(def->name); | |
239 | TypeInfo ti = { | |
240 | .name = typename, | |
241 | .parent = TYPE_MIPS_CPU, | |
242 | .class_init = mips_cpu_cpudef_class_init, | |
243 | .class_data = (void *)def, | |
244 | }; | |
245 | ||
246 | type_register(&ti); | |
247 | g_free(typename); | |
248 | } | |
249 | ||
0f71a709 AF |
250 | static void mips_cpu_register_types(void) |
251 | { | |
41da212c IM |
252 | int i; |
253 | ||
0f71a709 | 254 | type_register_static(&mips_cpu_type_info); |
41da212c IM |
255 | for (i = 0; i < mips_defs_number; i++) { |
256 | mips_register_cpudef_type(&mips_defs[i]); | |
257 | } | |
0f71a709 AF |
258 | } |
259 | ||
260 | type_init(mips_cpu_register_types) |