Fix configure test for PBKDF2 in nettle
[qemu.git] / target-tilegx / cpu.c
blobd2d09120348addb3e783e7c270224f9444f4776f
1 /*
2 * QEMU TILE-Gx CPU
4 * Copyright (c) 2015 Chen Gang
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.
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.
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>
21 #include "qemu/osdep.h"
22 #include "qapi/error.h"
23 #include "cpu.h"
24 #include "qemu-common.h"
25 #include "hw/qdev-properties.h"
26 #include "migration/vmstate.h"
27 #include "linux-user/syscall_defs.h"
29 static void tilegx_cpu_dump_state(CPUState *cs, FILE *f,
30 fprintf_function cpu_fprintf, int flags)
32 static const char * const reg_names[TILEGX_R_COUNT] = {
33 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
34 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
35 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
36 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
37 "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39",
38 "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47",
39 "r48", "r49", "r50", "r51", "bp", "tp", "sp", "lr"
42 TileGXCPU *cpu = TILEGX_CPU(cs);
43 CPUTLGState *env = &cpu->env;
44 int i;
46 for (i = 0; i < TILEGX_R_COUNT; i++) {
47 cpu_fprintf(f, "%-4s" TARGET_FMT_lx "%s",
48 reg_names[i], env->regs[i],
49 (i % 4) == 3 ? "\n" : " ");
51 cpu_fprintf(f, "PC " TARGET_FMT_lx " CEX " TARGET_FMT_lx "\n\n",
52 env->pc, env->spregs[TILEGX_SPR_CMPEXCH]);
55 TileGXCPU *cpu_tilegx_init(const char *cpu_model)
57 TileGXCPU *cpu;
59 cpu = TILEGX_CPU(object_new(TYPE_TILEGX_CPU));
61 object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
63 return cpu;
66 static void tilegx_cpu_set_pc(CPUState *cs, vaddr value)
68 TileGXCPU *cpu = TILEGX_CPU(cs);
70 cpu->env.pc = value;
73 static bool tilegx_cpu_has_work(CPUState *cs)
75 return true;
78 static void tilegx_cpu_reset(CPUState *s)
80 TileGXCPU *cpu = TILEGX_CPU(s);
81 TileGXCPUClass *tcc = TILEGX_CPU_GET_CLASS(cpu);
82 CPUTLGState *env = &cpu->env;
84 tcc->parent_reset(s);
86 memset(env, 0, sizeof(CPUTLGState));
87 tlb_flush(s, 1);
90 static void tilegx_cpu_realizefn(DeviceState *dev, Error **errp)
92 CPUState *cs = CPU(dev);
93 TileGXCPUClass *tcc = TILEGX_CPU_GET_CLASS(dev);
95 cpu_reset(cs);
96 qemu_init_vcpu(cs);
98 tcc->parent_realize(dev, errp);
101 static void tilegx_cpu_initfn(Object *obj)
103 CPUState *cs = CPU(obj);
104 TileGXCPU *cpu = TILEGX_CPU(obj);
105 CPUTLGState *env = &cpu->env;
106 static bool tcg_initialized;
108 cs->env_ptr = env;
109 cpu_exec_init(cs, &error_abort);
111 if (tcg_enabled() && !tcg_initialized) {
112 tcg_initialized = true;
113 tilegx_tcg_init();
117 static void tilegx_cpu_do_interrupt(CPUState *cs)
119 cs->exception_index = -1;
122 static int tilegx_cpu_handle_mmu_fault(CPUState *cs, vaddr address, int rw,
123 int mmu_idx)
125 TileGXCPU *cpu = TILEGX_CPU(cs);
127 /* The sigcode field will be filled in by do_signal in main.c. */
128 cs->exception_index = TILEGX_EXCP_SIGNAL;
129 cpu->env.excaddr = address;
130 cpu->env.signo = TARGET_SIGSEGV;
131 cpu->env.sigcode = 0;
133 return 1;
136 static bool tilegx_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
138 if (interrupt_request & CPU_INTERRUPT_HARD) {
139 tilegx_cpu_do_interrupt(cs);
140 return true;
142 return false;
145 static void tilegx_cpu_class_init(ObjectClass *oc, void *data)
147 DeviceClass *dc = DEVICE_CLASS(oc);
148 CPUClass *cc = CPU_CLASS(oc);
149 TileGXCPUClass *tcc = TILEGX_CPU_CLASS(oc);
151 tcc->parent_realize = dc->realize;
152 dc->realize = tilegx_cpu_realizefn;
154 tcc->parent_reset = cc->reset;
155 cc->reset = tilegx_cpu_reset;
157 cc->has_work = tilegx_cpu_has_work;
158 cc->do_interrupt = tilegx_cpu_do_interrupt;
159 cc->cpu_exec_interrupt = tilegx_cpu_exec_interrupt;
160 cc->dump_state = tilegx_cpu_dump_state;
161 cc->set_pc = tilegx_cpu_set_pc;
162 cc->handle_mmu_fault = tilegx_cpu_handle_mmu_fault;
163 cc->gdb_num_core_regs = 0;
166 * Reason: tilegx_cpu_initfn() calls cpu_exec_init(), which saves
167 * the object in cpus -> dangling pointer after final
168 * object_unref().
170 dc->cannot_destroy_with_object_finalize_yet = true;
173 static const TypeInfo tilegx_cpu_type_info = {
174 .name = TYPE_TILEGX_CPU,
175 .parent = TYPE_CPU,
176 .instance_size = sizeof(TileGXCPU),
177 .instance_init = tilegx_cpu_initfn,
178 .class_size = sizeof(TileGXCPUClass),
179 .class_init = tilegx_cpu_class_init,
182 static void tilegx_cpu_register_types(void)
184 type_register_static(&tilegx_cpu_type_info);
187 type_init(tilegx_cpu_register_types)