]> git.proxmox.com Git - mirror_qemu.git/blame - target-mips/cpu.c
exec: move cpu_exec_init() calls to realize functions
[mirror_qemu.git] / target-mips / cpu.c
CommitLineData
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"
14c03ab9 24#include "kvm_mips.h"
0f71a709 25#include "qemu-common.h"
14c03ab9 26#include "sysemu/kvm.h"
63c91552 27#include "exec/exec-all.h"
0f71a709
AF
28
29
f45748f1
AF
30static void mips_cpu_set_pc(CPUState *cs, vaddr value)
31{
32 MIPSCPU *cpu = MIPS_CPU(cs);
33 CPUMIPSState *env = &cpu->env;
34
35 env->active_tc.PC = value & ~(target_ulong)1;
36 if (value & 1) {
37 env->hflags |= MIPS_HFLAG_M16;
38 } else {
39 env->hflags &= ~(MIPS_HFLAG_M16);
40 }
41}
42
bdf7ae5b
AF
43static void mips_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
44{
45 MIPSCPU *cpu = MIPS_CPU(cs);
46 CPUMIPSState *env = &cpu->env;
47
48 env->active_tc.PC = tb->pc;
49 env->hflags &= ~MIPS_HFLAG_BMASK;
50 env->hflags |= tb->flags & MIPS_HFLAG_BMASK;
51}
52
8c2e1b00
AF
53static bool mips_cpu_has_work(CPUState *cs)
54{
55 MIPSCPU *cpu = MIPS_CPU(cs);
56 CPUMIPSState *env = &cpu->env;
57 bool has_work = false;
58
7540a43a
LA
59 /* Prior to MIPS Release 6 it is implementation dependent if non-enabled
60 interrupts wake-up the CPU, however most of the implementations only
8c2e1b00
AF
61 check for interrupts that can be taken. */
62 if ((cs->interrupt_request & CPU_INTERRUPT_HARD) &&
63 cpu_mips_hw_interrupts_pending(env)) {
7540a43a
LA
64 if (cpu_mips_hw_interrupts_enabled(env) ||
65 (env->insn_flags & ISA_MIPS32R6)) {
71ca034a
LA
66 has_work = true;
67 }
8c2e1b00
AF
68 }
69
70 /* MIPS-MT has the ability to halt the CPU. */
71 if (env->CP0_Config3 & (1 << CP0C3_MT)) {
72 /* The QEMU model will issue an _WAKE request whenever the CPUs
73 should be woken up. */
74 if (cs->interrupt_request & CPU_INTERRUPT_WAKE) {
75 has_work = true;
76 }
77
78 if (!mips_vpe_active(env)) {
79 has_work = false;
80 }
81 }
01bc435b
YK
82 /* MIPS Release 6 has the ability to halt the CPU. */
83 if (env->CP0_Config5 & (1 << CP0C5_VP)) {
84 if (cs->interrupt_request & CPU_INTERRUPT_WAKE) {
85 has_work = true;
86 }
87 if (!mips_vp_active(env)) {
88 has_work = false;
89 }
90 }
8c2e1b00
AF
91 return has_work;
92}
93
0f71a709
AF
94/* CPUClass::reset() */
95static void mips_cpu_reset(CPUState *s)
96{
97 MIPSCPU *cpu = MIPS_CPU(s);
98 MIPSCPUClass *mcc = MIPS_CPU_GET_CLASS(cpu);
99 CPUMIPSState *env = &cpu->env;
100
101 mcc->parent_reset(s);
102
f0c3c505 103 memset(env, 0, offsetof(CPUMIPSState, mvp));
00c8cb0a 104 tlb_flush(s, 1);
55e5c285 105
0f71a709 106 cpu_state_reset(env);
14c03ab9
JH
107
108#ifndef CONFIG_USER_ONLY
109 if (kvm_enabled()) {
110 kvm_mips_reset_vcpu(cpu);
111 }
112#endif
0f71a709
AF
113}
114
63a946c7
PC
115static void mips_cpu_disas_set_info(CPUState *s, disassemble_info *info) {
116#ifdef TARGET_WORDS_BIGENDIAN
117 info->print_insn = print_insn_big_mips;
118#else
119 info->print_insn = print_insn_little_mips;
120#endif
121}
122
c1caf1d9
AF
123static void mips_cpu_realizefn(DeviceState *dev, Error **errp)
124{
14a10fc3 125 CPUState *cs = CPU(dev);
c1caf1d9 126 MIPSCPUClass *mcc = MIPS_CPU_GET_CLASS(dev);
ce5b1bbf
LV
127 Error *local_err = NULL;
128
129 cpu_exec_realizefn(cs, &local_err);
130 if (local_err != NULL) {
131 error_propagate(errp, local_err);
132 return;
133 }
c1caf1d9 134
14a10fc3
AF
135 cpu_reset(cs);
136 qemu_init_vcpu(cs);
c1caf1d9
AF
137
138 mcc->parent_realize(dev, errp);
139}
140
5b0c40f7
AF
141static void mips_cpu_initfn(Object *obj)
142{
c05efcb1 143 CPUState *cs = CPU(obj);
5b0c40f7
AF
144 MIPSCPU *cpu = MIPS_CPU(obj);
145 CPUMIPSState *env = &cpu->env;
146
c05efcb1 147 cs->env_ptr = env;
78ce64f4
AF
148
149 if (tcg_enabled()) {
150 mips_tcg_init();
151 }
5b0c40f7
AF
152}
153
0f71a709
AF
154static void mips_cpu_class_init(ObjectClass *c, void *data)
155{
156 MIPSCPUClass *mcc = MIPS_CPU_CLASS(c);
157 CPUClass *cc = CPU_CLASS(c);
c1caf1d9
AF
158 DeviceClass *dc = DEVICE_CLASS(c);
159
160 mcc->parent_realize = dc->realize;
161 dc->realize = mips_cpu_realizefn;
0f71a709
AF
162
163 mcc->parent_reset = cc->reset;
164 cc->reset = mips_cpu_reset;
97a8ea5a 165
8c2e1b00 166 cc->has_work = mips_cpu_has_work;
97a8ea5a 167 cc->do_interrupt = mips_cpu_do_interrupt;
fa4faba4 168 cc->cpu_exec_interrupt = mips_cpu_exec_interrupt;
878096ee 169 cc->dump_state = mips_cpu_dump_state;
f45748f1 170 cc->set_pc = mips_cpu_set_pc;
bdf7ae5b 171 cc->synchronize_from_tb = mips_cpu_synchronize_from_tb;
5b50e790
AF
172 cc->gdb_read_register = mips_cpu_gdb_read_register;
173 cc->gdb_write_register = mips_cpu_gdb_write_register;
7510454e
AF
174#ifdef CONFIG_USER_ONLY
175 cc->handle_mmu_fault = mips_cpu_handle_mmu_fault;
176#else
00b941e5 177 cc->do_unassigned_access = mips_cpu_unassigned_access;
93e22326 178 cc->do_unaligned_access = mips_cpu_do_unaligned_access;
00b941e5 179 cc->get_phys_page_debug = mips_cpu_get_phys_page_debug;
04cd7962 180 cc->vmsd = &vmstate_mips_cpu;
00b941e5 181#endif
63a946c7 182 cc->disas_set_info = mips_cpu_disas_set_info;
a0e372f0
AF
183
184 cc->gdb_num_core_regs = 73;
2472b6c0 185 cc->gdb_stop_before_watchpoint = true;
0f71a709
AF
186}
187
188static const TypeInfo mips_cpu_type_info = {
189 .name = TYPE_MIPS_CPU,
190 .parent = TYPE_CPU,
191 .instance_size = sizeof(MIPSCPU),
5b0c40f7 192 .instance_init = mips_cpu_initfn,
0f71a709
AF
193 .abstract = false,
194 .class_size = sizeof(MIPSCPUClass),
195 .class_init = mips_cpu_class_init,
196};
197
198static void mips_cpu_register_types(void)
199{
200 type_register_static(&mips_cpu_type_info);
201}
202
203type_init(mips_cpu_register_types)