4 * Copyright (c) 2010-2012 Guan Xuetao
5 * Copyright (c) 2012 SUSE LINUX Products GmbH
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.
11 * Contributions from 2012-04-01 on are considered under GPL version 2,
12 * or (at your option) any later version.
16 #include "qemu-common.h"
17 #include "migration/vmstate.h"
19 static void uc32_cpu_set_pc(CPUState
*cs
, vaddr value
)
21 UniCore32CPU
*cpu
= UNICORE32_CPU(cs
);
23 cpu
->env
.regs
[31] = value
;
26 static bool uc32_cpu_has_work(CPUState
*cs
)
28 return cs
->interrupt_request
&
29 (CPU_INTERRUPT_HARD
| CPU_INTERRUPT_EXITTB
);
32 static inline void set_feature(CPUUniCore32State
*env
, int feature
)
34 env
->features
|= feature
;
39 static ObjectClass
*uc32_cpu_class_by_name(const char *cpu_model
)
44 if (cpu_model
== NULL
) {
48 typename
= g_strdup_printf("%s-" TYPE_UNICORE32_CPU
, cpu_model
);
49 oc
= object_class_by_name(typename
);
51 if (oc
!= NULL
&& (!object_class_dynamic_cast(oc
, TYPE_UNICORE32_CPU
) ||
52 object_class_is_abstract(oc
))) {
58 typedef struct UniCore32CPUInfo
{
60 void (*instance_init
)(Object
*obj
);
63 static void unicore_ii_cpu_initfn(Object
*obj
)
65 UniCore32CPU
*cpu
= UNICORE32_CPU(obj
);
66 CPUUniCore32State
*env
= &cpu
->env
;
68 env
->cp0
.c0_cpuid
= 0x4d000863;
69 env
->cp0
.c0_cachetype
= 0x0d152152;
70 env
->cp0
.c1_sys
= 0x2000;
71 env
->cp0
.c2_base
= 0x0;
72 env
->cp0
.c3_faultstatus
= 0x0;
73 env
->cp0
.c4_faultaddr
= 0x0;
74 env
->ucf64
.xregs
[UC32_UCF64_FPSCR
] = 0;
76 set_feature(env
, UC32_HWCAP_CMOV
);
77 set_feature(env
, UC32_HWCAP_UCF64
);
80 static void uc32_any_cpu_initfn(Object
*obj
)
82 UniCore32CPU
*cpu
= UNICORE32_CPU(obj
);
83 CPUUniCore32State
*env
= &cpu
->env
;
85 env
->cp0
.c0_cpuid
= 0xffffffff;
86 env
->ucf64
.xregs
[UC32_UCF64_FPSCR
] = 0;
88 set_feature(env
, UC32_HWCAP_CMOV
);
89 set_feature(env
, UC32_HWCAP_UCF64
);
92 static const UniCore32CPUInfo uc32_cpus
[] = {
93 { .name
= "UniCore-II", .instance_init
= unicore_ii_cpu_initfn
},
94 { .name
= "any", .instance_init
= uc32_any_cpu_initfn
},
97 static void uc32_cpu_realizefn(DeviceState
*dev
, Error
**errp
)
99 UniCore32CPUClass
*ucc
= UNICORE32_CPU_GET_CLASS(dev
);
101 qemu_init_vcpu(CPU(dev
));
103 ucc
->parent_realize(dev
, errp
);
106 static void uc32_cpu_initfn(Object
*obj
)
108 CPUState
*cs
= CPU(obj
);
109 UniCore32CPU
*cpu
= UNICORE32_CPU(obj
);
110 CPUUniCore32State
*env
= &cpu
->env
;
114 cpu_exec_init(cs
, &error_abort
);
116 #ifdef CONFIG_USER_ONLY
117 env
->uncached_asr
= ASR_MODE_USER
;
120 env
->uncached_asr
= ASR_MODE_PRIV
;
121 env
->regs
[31] = 0x03000000;
126 if (tcg_enabled() && !inited
) {
128 uc32_translate_init();
132 static const VMStateDescription vmstate_uc32_cpu
= {
137 static void uc32_cpu_class_init(ObjectClass
*oc
, void *data
)
139 DeviceClass
*dc
= DEVICE_CLASS(oc
);
140 CPUClass
*cc
= CPU_CLASS(oc
);
141 UniCore32CPUClass
*ucc
= UNICORE32_CPU_CLASS(oc
);
143 ucc
->parent_realize
= dc
->realize
;
144 dc
->realize
= uc32_cpu_realizefn
;
146 cc
->class_by_name
= uc32_cpu_class_by_name
;
147 cc
->has_work
= uc32_cpu_has_work
;
148 cc
->do_interrupt
= uc32_cpu_do_interrupt
;
149 cc
->cpu_exec_interrupt
= uc32_cpu_exec_interrupt
;
150 cc
->dump_state
= uc32_cpu_dump_state
;
151 cc
->set_pc
= uc32_cpu_set_pc
;
152 #ifdef CONFIG_USER_ONLY
153 cc
->handle_mmu_fault
= uc32_cpu_handle_mmu_fault
;
155 cc
->get_phys_page_debug
= uc32_cpu_get_phys_page_debug
;
157 dc
->vmsd
= &vmstate_uc32_cpu
;
160 * Reason: uc32_cpu_initfn() calls cpu_exec_init(), which saves
161 * the object in cpus -> dangling pointer after final
164 dc
->cannot_destroy_with_object_finalize_yet
= true;
167 static void uc32_register_cpu_type(const UniCore32CPUInfo
*info
)
169 TypeInfo type_info
= {
170 .parent
= TYPE_UNICORE32_CPU
,
171 .instance_init
= info
->instance_init
,
174 type_info
.name
= g_strdup_printf("%s-" TYPE_UNICORE32_CPU
, info
->name
);
175 type_register(&type_info
);
176 g_free((void *)type_info
.name
);
179 static const TypeInfo uc32_cpu_type_info
= {
180 .name
= TYPE_UNICORE32_CPU
,
182 .instance_size
= sizeof(UniCore32CPU
),
183 .instance_init
= uc32_cpu_initfn
,
185 .class_size
= sizeof(UniCore32CPUClass
),
186 .class_init
= uc32_cpu_class_init
,
189 static void uc32_cpu_register_types(void)
193 type_register_static(&uc32_cpu_type_info
);
194 for (i
= 0; i
< ARRAY_SIZE(uc32_cpus
); i
++) {
195 uc32_register_cpu_type(&uc32_cpus
[i
]);
199 type_init(uc32_cpu_register_types
)