meson: fix module config
[qemu/ar7.git] / target / sh4 / cpu.c
blob3c68021c5650eb0bc36c135bc7d40866d1cf3cc5
1 /*
2 * QEMU SuperH CPU
4 * Copyright (c) 2005 Samuel Tardieu
5 * Copyright (c) 2012 SUSE LINUX Products GmbH
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see
19 * <http://www.gnu.org/licenses/lgpl-2.1.html>
22 #include "qemu/osdep.h"
23 #include "qapi/error.h"
24 #include "qemu/qemu-print.h"
25 #include "cpu.h"
26 #include "migration/vmstate.h"
27 #include "exec/exec-all.h"
28 #include "fpu/softfloat-helpers.h"
30 static void superh_cpu_set_pc(CPUState *cs, vaddr value)
32 SuperHCPU *cpu = SUPERH_CPU(cs);
34 cpu->env.pc = value;
37 static void superh_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
39 SuperHCPU *cpu = SUPERH_CPU(cs);
41 cpu->env.pc = tb->pc;
42 cpu->env.flags = tb->flags & TB_FLAG_ENVFLAGS_MASK;
45 static bool superh_cpu_has_work(CPUState *cs)
47 return cs->interrupt_request & CPU_INTERRUPT_HARD;
50 static void superh_cpu_reset(DeviceState *dev)
52 CPUState *s = CPU(dev);
53 SuperHCPU *cpu = SUPERH_CPU(s);
54 SuperHCPUClass *scc = SUPERH_CPU_GET_CLASS(cpu);
55 CPUSH4State *env = &cpu->env;
57 scc->parent_reset(dev);
59 memset(env, 0, offsetof(CPUSH4State, end_reset_fields));
61 env->pc = 0xA0000000;
62 #if defined(CONFIG_USER_ONLY)
63 env->fpscr = FPSCR_PR; /* value for userspace according to the kernel */
64 set_float_rounding_mode(float_round_nearest_even, &env->fp_status); /* ?! */
65 #else
66 env->sr = (1u << SR_MD) | (1u << SR_RB) | (1u << SR_BL) |
67 (1u << SR_I3) | (1u << SR_I2) | (1u << SR_I1) | (1u << SR_I0);
68 env->fpscr = FPSCR_DN | FPSCR_RM_ZERO; /* CPU reset value according to SH4 manual */
69 set_float_rounding_mode(float_round_to_zero, &env->fp_status);
70 set_flush_to_zero(1, &env->fp_status);
71 #endif
72 set_default_nan_mode(1, &env->fp_status);
75 static void superh_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)
77 info->mach = bfd_mach_sh4;
78 info->print_insn = print_insn_sh;
81 static void superh_cpu_list_entry(gpointer data, gpointer user_data)
83 const char *typename = object_class_get_name(OBJECT_CLASS(data));
84 int len = strlen(typename) - strlen(SUPERH_CPU_TYPE_SUFFIX);
86 qemu_printf("%.*s\n", len, typename);
89 void sh4_cpu_list(void)
91 GSList *list;
93 list = object_class_get_list_sorted(TYPE_SUPERH_CPU, false);
94 g_slist_foreach(list, superh_cpu_list_entry, NULL);
95 g_slist_free(list);
98 static ObjectClass *superh_cpu_class_by_name(const char *cpu_model)
100 ObjectClass *oc;
101 char *s, *typename = NULL;
103 s = g_ascii_strdown(cpu_model, -1);
104 if (strcmp(s, "any") == 0) {
105 oc = object_class_by_name(TYPE_SH7750R_CPU);
106 goto out;
109 typename = g_strdup_printf(SUPERH_CPU_TYPE_NAME("%s"), s);
110 oc = object_class_by_name(typename);
111 if (oc != NULL && object_class_is_abstract(oc)) {
112 oc = NULL;
115 out:
116 g_free(s);
117 g_free(typename);
118 return oc;
121 static void sh7750r_cpu_initfn(Object *obj)
123 SuperHCPU *cpu = SUPERH_CPU(obj);
124 CPUSH4State *env = &cpu->env;
126 env->id = SH_CPU_SH7750R;
127 env->features = SH_FEATURE_BCR3_AND_BCR4;
130 static void sh7750r_class_init(ObjectClass *oc, void *data)
132 SuperHCPUClass *scc = SUPERH_CPU_CLASS(oc);
134 scc->pvr = 0x00050000;
135 scc->prr = 0x00000100;
136 scc->cvr = 0x00110000;
139 static void sh7751r_cpu_initfn(Object *obj)
141 SuperHCPU *cpu = SUPERH_CPU(obj);
142 CPUSH4State *env = &cpu->env;
144 env->id = SH_CPU_SH7751R;
145 env->features = SH_FEATURE_BCR3_AND_BCR4;
148 static void sh7751r_class_init(ObjectClass *oc, void *data)
150 SuperHCPUClass *scc = SUPERH_CPU_CLASS(oc);
152 scc->pvr = 0x04050005;
153 scc->prr = 0x00000113;
154 scc->cvr = 0x00110000; /* Neutered caches, should be 0x20480000 */
157 static void sh7785_cpu_initfn(Object *obj)
159 SuperHCPU *cpu = SUPERH_CPU(obj);
160 CPUSH4State *env = &cpu->env;
162 env->id = SH_CPU_SH7785;
163 env->features = SH_FEATURE_SH4A;
166 static void sh7785_class_init(ObjectClass *oc, void *data)
168 SuperHCPUClass *scc = SUPERH_CPU_CLASS(oc);
170 scc->pvr = 0x10300700;
171 scc->prr = 0x00000200;
172 scc->cvr = 0x71440211;
175 static void superh_cpu_realizefn(DeviceState *dev, Error **errp)
177 CPUState *cs = CPU(dev);
178 SuperHCPUClass *scc = SUPERH_CPU_GET_CLASS(dev);
179 Error *local_err = NULL;
181 cpu_exec_realizefn(cs, &local_err);
182 if (local_err != NULL) {
183 error_propagate(errp, local_err);
184 return;
187 cpu_reset(cs);
188 qemu_init_vcpu(cs);
190 scc->parent_realize(dev, errp);
193 static void superh_cpu_initfn(Object *obj)
195 SuperHCPU *cpu = SUPERH_CPU(obj);
196 CPUSH4State *env = &cpu->env;
198 cpu_set_cpustate_pointers(cpu);
200 env->movcal_backup_tail = &(env->movcal_backup);
203 static const VMStateDescription vmstate_sh_cpu = {
204 .name = "cpu",
205 .unmigratable = 1,
208 static void superh_cpu_class_init(ObjectClass *oc, void *data)
210 DeviceClass *dc = DEVICE_CLASS(oc);
211 CPUClass *cc = CPU_CLASS(oc);
212 SuperHCPUClass *scc = SUPERH_CPU_CLASS(oc);
214 device_class_set_parent_realize(dc, superh_cpu_realizefn,
215 &scc->parent_realize);
217 device_class_set_parent_reset(dc, superh_cpu_reset, &scc->parent_reset);
219 cc->class_by_name = superh_cpu_class_by_name;
220 cc->has_work = superh_cpu_has_work;
221 cc->do_interrupt = superh_cpu_do_interrupt;
222 cc->cpu_exec_interrupt = superh_cpu_exec_interrupt;
223 cc->dump_state = superh_cpu_dump_state;
224 cc->set_pc = superh_cpu_set_pc;
225 cc->synchronize_from_tb = superh_cpu_synchronize_from_tb;
226 cc->gdb_read_register = superh_cpu_gdb_read_register;
227 cc->gdb_write_register = superh_cpu_gdb_write_register;
228 cc->tlb_fill = superh_cpu_tlb_fill;
229 #ifndef CONFIG_USER_ONLY
230 cc->do_unaligned_access = superh_cpu_do_unaligned_access;
231 cc->get_phys_page_debug = superh_cpu_get_phys_page_debug;
232 #endif
233 cc->disas_set_info = superh_cpu_disas_set_info;
234 cc->tcg_initialize = sh4_translate_init;
236 cc->gdb_num_core_regs = 59;
238 dc->vmsd = &vmstate_sh_cpu;
241 #define DEFINE_SUPERH_CPU_TYPE(type_name, cinit, initfn) \
243 .name = type_name, \
244 .parent = TYPE_SUPERH_CPU, \
245 .class_init = cinit, \
246 .instance_init = initfn, \
248 static const TypeInfo superh_cpu_type_infos[] = {
250 .name = TYPE_SUPERH_CPU,
251 .parent = TYPE_CPU,
252 .instance_size = sizeof(SuperHCPU),
253 .instance_init = superh_cpu_initfn,
254 .abstract = true,
255 .class_size = sizeof(SuperHCPUClass),
256 .class_init = superh_cpu_class_init,
258 DEFINE_SUPERH_CPU_TYPE(TYPE_SH7750R_CPU, sh7750r_class_init,
259 sh7750r_cpu_initfn),
260 DEFINE_SUPERH_CPU_TYPE(TYPE_SH7751R_CPU, sh7751r_class_init,
261 sh7751r_cpu_initfn),
262 DEFINE_SUPERH_CPU_TYPE(TYPE_SH7785_CPU, sh7785_class_init,
263 sh7785_cpu_initfn),
267 DEFINE_TYPES(superh_cpu_type_infos)