]> git.proxmox.com Git - mirror_qemu.git/blame - target/unicore32/cpu.c
cpu: Introduce cpu_set_cpustate_pointers
[mirror_qemu.git] / target / unicore32 / cpu.c
CommitLineData
ae0f5e9e
AF
1/*
2 * QEMU UniCore32 CPU
3 *
d48813dd 4 * Copyright (c) 2010-2012 Guan Xuetao
ae0f5e9e
AF
5 * Copyright (c) 2012 SUSE LINUX Products GmbH
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * Contributions from 2012-04-01 on are considered under GPL version 2,
12 * or (at your option) any later version.
13 */
14
5af98cc5 15#include "qemu/osdep.h"
da34e65c 16#include "qapi/error.h"
3993c6bd 17#include "cpu.h"
ae0f5e9e 18#include "qemu-common.h"
88e28512 19#include "migration/vmstate.h"
63c91552 20#include "exec/exec-all.h"
24f91e81 21#include "fpu/softfloat.h"
ae0f5e9e 22
b42eab27
AF
23static void uc32_cpu_set_pc(CPUState *cs, vaddr value)
24{
25 UniCore32CPU *cpu = UNICORE32_CPU(cs);
26
27 cpu->env.regs[31] = value;
28}
29
8c2e1b00
AF
30static bool uc32_cpu_has_work(CPUState *cs)
31{
32 return cs->interrupt_request &
33 (CPU_INTERRUPT_HARD | CPU_INTERRUPT_EXITTB);
34}
35
8df9082d
AF
36static inline void set_feature(CPUUniCore32State *env, int feature)
37{
38 env->features |= feature;
39}
40
ae0f5e9e
AF
41/* CPU models */
42
d89e1218
AF
43static ObjectClass *uc32_cpu_class_by_name(const char *cpu_model)
44{
45 ObjectClass *oc;
eeb266de 46 char *typename;
d89e1218 47
6a826866 48 typename = g_strdup_printf(UNICORE32_CPU_TYPE_NAME("%s"), cpu_model);
eeb266de
AF
49 oc = object_class_by_name(typename);
50 g_free(typename);
4933908a
AF
51 if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_UNICORE32_CPU) ||
52 object_class_is_abstract(oc))) {
d89e1218
AF
53 oc = NULL;
54 }
55 return oc;
56}
57
ae0f5e9e
AF
58static void unicore_ii_cpu_initfn(Object *obj)
59{
60 UniCore32CPU *cpu = UNICORE32_CPU(obj);
61 CPUUniCore32State *env = &cpu->env;
62
d48813dd
GX
63 env->cp0.c0_cpuid = 0x4d000863;
64 env->cp0.c0_cachetype = 0x0d152152;
65 env->cp0.c1_sys = 0x2000;
66 env->cp0.c2_base = 0x0;
67 env->cp0.c3_faultstatus = 0x0;
68 env->cp0.c4_faultaddr = 0x0;
69 env->ucf64.xregs[UC32_UCF64_FPSCR] = 0;
8df9082d
AF
70
71 set_feature(env, UC32_HWCAP_CMOV);
72 set_feature(env, UC32_HWCAP_UCF64);
ae0f5e9e
AF
73}
74
75static void uc32_any_cpu_initfn(Object *obj)
76{
77 UniCore32CPU *cpu = UNICORE32_CPU(obj);
78 CPUUniCore32State *env = &cpu->env;
79
80 env->cp0.c0_cpuid = 0xffffffff;
d48813dd 81 env->ucf64.xregs[UC32_UCF64_FPSCR] = 0;
8df9082d
AF
82
83 set_feature(env, UC32_HWCAP_CMOV);
84 set_feature(env, UC32_HWCAP_UCF64);
ae0f5e9e
AF
85}
86
088383e3
AF
87static void uc32_cpu_realizefn(DeviceState *dev, Error **errp)
88{
ce5b1bbf 89 CPUState *cs = CPU(dev);
088383e3 90 UniCore32CPUClass *ucc = UNICORE32_CPU_GET_CLASS(dev);
ce5b1bbf 91 Error *local_err = NULL;
088383e3 92
ce5b1bbf
LV
93 cpu_exec_realizefn(cs, &local_err);
94 if (local_err != NULL) {
95 error_propagate(errp, local_err);
96 return;
97 }
98
99 qemu_init_vcpu(cs);
14a10fc3 100
088383e3
AF
101 ucc->parent_realize(dev, errp);
102}
103
ae0f5e9e
AF
104static void uc32_cpu_initfn(Object *obj)
105{
106 UniCore32CPU *cpu = UNICORE32_CPU(obj);
107 CPUUniCore32State *env = &cpu->env;
108
7506ed90 109 cpu_set_cpustate_pointers(cpu);
ae0f5e9e 110
d48813dd 111#ifdef CONFIG_USER_ONLY
ae0f5e9e
AF
112 env->uncached_asr = ASR_MODE_USER;
113 env->regs[31] = 0;
d48813dd
GX
114#else
115 env->uncached_asr = ASR_MODE_PRIV;
116 env->regs[31] = 0x03000000;
117#endif
ae0f5e9e
AF
118}
119
88e28512
AF
120static const VMStateDescription vmstate_uc32_cpu = {
121 .name = "cpu",
122 .unmigratable = 1,
123};
124
d89e1218
AF
125static void uc32_cpu_class_init(ObjectClass *oc, void *data)
126{
88e28512 127 DeviceClass *dc = DEVICE_CLASS(oc);
d89e1218 128 CPUClass *cc = CPU_CLASS(oc);
088383e3
AF
129 UniCore32CPUClass *ucc = UNICORE32_CPU_CLASS(oc);
130
bf853881
PMD
131 device_class_set_parent_realize(dc, uc32_cpu_realizefn,
132 &ucc->parent_realize);
d89e1218
AF
133
134 cc->class_by_name = uc32_cpu_class_by_name;
8c2e1b00 135 cc->has_work = uc32_cpu_has_work;
97a8ea5a 136 cc->do_interrupt = uc32_cpu_do_interrupt;
d8bb9159 137 cc->cpu_exec_interrupt = uc32_cpu_exec_interrupt;
878096ee 138 cc->dump_state = uc32_cpu_dump_state;
b42eab27 139 cc->set_pc = uc32_cpu_set_pc;
c5d417da 140 cc->tlb_fill = uc32_cpu_tlb_fill;
00b941e5 141 cc->get_phys_page_debug = uc32_cpu_get_phys_page_debug;
55c3ceef 142 cc->tcg_initialize = uc32_translate_init;
88e28512 143 dc->vmsd = &vmstate_uc32_cpu;
d89e1218
AF
144}
145
6a826866
IM
146#define DEFINE_UNICORE32_CPU_TYPE(cpu_model, initfn) \
147 { \
148 .parent = TYPE_UNICORE32_CPU, \
149 .instance_init = initfn, \
150 .name = UNICORE32_CPU_TYPE_NAME(cpu_model), \
151 }
ae0f5e9e 152
6a826866
IM
153static const TypeInfo uc32_cpu_type_infos[] = {
154 {
155 .name = TYPE_UNICORE32_CPU,
156 .parent = TYPE_CPU,
157 .instance_size = sizeof(UniCore32CPU),
158 .instance_init = uc32_cpu_initfn,
159 .abstract = true,
160 .class_size = sizeof(UniCore32CPUClass),
161 .class_init = uc32_cpu_class_init,
162 },
163 DEFINE_UNICORE32_CPU_TYPE("UniCore-II", unicore_ii_cpu_initfn),
164 DEFINE_UNICORE32_CPU_TYPE("any", uc32_any_cpu_initfn),
ae0f5e9e
AF
165};
166
6a826866 167DEFINE_TYPES(uc32_cpu_type_infos)