seccomp: libseccomp version varying according to arch
[qemu/qmp-unstable.git] / target-unicore32 / cpu.c
blob5b3298717312b8168e04811f9da3776174922f01
1 /*
2 * QEMU UniCore32 CPU
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.
15 #include "cpu.h"
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;
37 /* CPU models */
39 static ObjectClass *uc32_cpu_class_by_name(const char *cpu_model)
41 ObjectClass *oc;
42 char *typename;
44 if (cpu_model == NULL) {
45 return NULL;
48 typename = g_strdup_printf("%s-" TYPE_UNICORE32_CPU, cpu_model);
49 oc = object_class_by_name(typename);
50 g_free(typename);
51 if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_UNICORE32_CPU) ||
52 object_class_is_abstract(oc))) {
53 oc = NULL;
55 return oc;
58 typedef struct UniCore32CPUInfo {
59 const char *name;
60 void (*instance_init)(Object *obj);
61 } UniCore32CPUInfo;
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;
111 static bool inited;
113 cs->env_ptr = env;
114 cpu_exec_init(env);
116 #ifdef CONFIG_USER_ONLY
117 env->uncached_asr = ASR_MODE_USER;
118 env->regs[31] = 0;
119 #else
120 env->uncached_asr = ASR_MODE_PRIV;
121 env->regs[31] = 0x03000000;
122 #endif
124 tlb_flush(cs, 1);
126 if (tcg_enabled() && !inited) {
127 inited = true;
128 uc32_translate_init();
132 static const VMStateDescription vmstate_uc32_cpu = {
133 .name = "cpu",
134 .unmigratable = 1,
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;
154 #else
155 cc->get_phys_page_debug = uc32_cpu_get_phys_page_debug;
156 #endif
157 dc->vmsd = &vmstate_uc32_cpu;
160 static void uc32_register_cpu_type(const UniCore32CPUInfo *info)
162 TypeInfo type_info = {
163 .parent = TYPE_UNICORE32_CPU,
164 .instance_init = info->instance_init,
167 type_info.name = g_strdup_printf("%s-" TYPE_UNICORE32_CPU, info->name);
168 type_register(&type_info);
169 g_free((void *)type_info.name);
172 static const TypeInfo uc32_cpu_type_info = {
173 .name = TYPE_UNICORE32_CPU,
174 .parent = TYPE_CPU,
175 .instance_size = sizeof(UniCore32CPU),
176 .instance_init = uc32_cpu_initfn,
177 .abstract = true,
178 .class_size = sizeof(UniCore32CPUClass),
179 .class_init = uc32_cpu_class_init,
182 static void uc32_cpu_register_types(void)
184 int i;
186 type_register_static(&uc32_cpu_type_info);
187 for (i = 0; i < ARRAY_SIZE(uc32_cpus); i++) {
188 uc32_register_cpu_type(&uc32_cpus[i]);
192 type_init(uc32_cpu_register_types)