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