]> git.proxmox.com Git - mirror_qemu.git/blob - target/hppa/cpu.c
target-hppa: Add framework and enable compilation
[mirror_qemu.git] / target / hppa / cpu.c
1 /*
2 * QEMU HPPA CPU
3 *
4 * Copyright (c) 2016 Richard Henderson <rth@twiddle.net>
5 *
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.
10 *
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.
15 *
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>
19 */
20
21 #include "qemu/osdep.h"
22 #include "qapi/error.h"
23 #include "cpu.h"
24 #include "qemu-common.h"
25 #include "migration/vmstate.h"
26 #include "exec/exec-all.h"
27
28
29 static void hppa_cpu_set_pc(CPUState *cs, vaddr value)
30 {
31 HPPACPU *cpu = HPPA_CPU(cs);
32
33 cpu->env.iaoq_f = value;
34 cpu->env.iaoq_b = value + 4;
35 }
36
37 static void hppa_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
38 {
39 HPPACPU *cpu = HPPA_CPU(cs);
40
41 cpu->env.iaoq_f = tb->pc;
42 cpu->env.iaoq_b = tb->cs_base;
43 cpu->env.psw_n = tb->flags & 1;
44 }
45
46 static void hppa_cpu_disas_set_info(CPUState *cs, disassemble_info *info)
47 {
48 info->mach = bfd_mach_hppa20;
49 info->print_insn = print_insn_hppa;
50 }
51
52 static void hppa_cpu_realizefn(DeviceState *dev, Error **errp)
53 {
54 CPUState *cs = CPU(dev);
55 HPPACPUClass *acc = HPPA_CPU_GET_CLASS(dev);
56 Error *local_err = NULL;
57
58 cpu_exec_realizefn(cs, &local_err);
59 if (local_err != NULL) {
60 error_propagate(errp, local_err);
61 return;
62 }
63
64 qemu_init_vcpu(cs);
65 acc->parent_realize(dev, errp);
66 }
67
68 /* Sort hppabetically by type name. */
69 static gint hppa_cpu_list_compare(gconstpointer a, gconstpointer b)
70 {
71 ObjectClass *class_a = (ObjectClass *)a;
72 ObjectClass *class_b = (ObjectClass *)b;
73 const char *name_a, *name_b;
74
75 name_a = object_class_get_name(class_a);
76 name_b = object_class_get_name(class_b);
77 return strcmp(name_a, name_b);
78 }
79
80 static void hppa_cpu_list_entry(gpointer data, gpointer user_data)
81 {
82 ObjectClass *oc = data;
83 CPUListState *s = user_data;
84
85 (*s->cpu_fprintf)(s->file, " %s\n", object_class_get_name(oc));
86 }
87
88 void hppa_cpu_list(FILE *f, fprintf_function cpu_fprintf)
89 {
90 CPUListState s = {
91 .file = f,
92 .cpu_fprintf = cpu_fprintf,
93 };
94 GSList *list;
95
96 list = object_class_get_list(TYPE_HPPA_CPU, false);
97 list = g_slist_sort(list, hppa_cpu_list_compare);
98 (*cpu_fprintf)(f, "Available CPUs:\n");
99 g_slist_foreach(list, hppa_cpu_list_entry, &s);
100 g_slist_free(list);
101 }
102
103 static void hppa_cpu_initfn(Object *obj)
104 {
105 CPUState *cs = CPU(obj);
106 HPPACPU *cpu = HPPA_CPU(obj);
107 CPUHPPAState *env = &cpu->env;
108
109 cs->env_ptr = env;
110 cpu_hppa_loaded_fr0(env);
111 set_snan_bit_is_one(true, &env->fp_status);
112
113 hppa_translate_init();
114 }
115
116 HPPACPU *cpu_hppa_init(const char *cpu_model)
117 {
118 HPPACPU *cpu;
119
120 cpu = HPPA_CPU(object_new(TYPE_HPPA_CPU));
121
122 object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
123
124 return cpu;
125 }
126
127 static void hppa_cpu_class_init(ObjectClass *oc, void *data)
128 {
129 DeviceClass *dc = DEVICE_CLASS(oc);
130 CPUClass *cc = CPU_CLASS(oc);
131 HPPACPUClass *acc = HPPA_CPU_CLASS(oc);
132
133 acc->parent_realize = dc->realize;
134 dc->realize = hppa_cpu_realizefn;
135
136 cc->do_interrupt = hppa_cpu_do_interrupt;
137 cc->cpu_exec_interrupt = hppa_cpu_exec_interrupt;
138 cc->dump_state = hppa_cpu_dump_state;
139 cc->set_pc = hppa_cpu_set_pc;
140 cc->synchronize_from_tb = hppa_cpu_synchronize_from_tb;
141 cc->gdb_read_register = hppa_cpu_gdb_read_register;
142 cc->gdb_write_register = hppa_cpu_gdb_write_register;
143 cc->handle_mmu_fault = hppa_cpu_handle_mmu_fault;
144 cc->disas_set_info = hppa_cpu_disas_set_info;
145
146 cc->gdb_num_core_regs = 128;
147 }
148
149 static const TypeInfo hppa_cpu_type_info = {
150 .name = TYPE_HPPA_CPU,
151 .parent = TYPE_CPU,
152 .instance_size = sizeof(HPPACPU),
153 .instance_init = hppa_cpu_initfn,
154 .abstract = false,
155 .class_size = sizeof(HPPACPUClass),
156 .class_init = hppa_cpu_class_init,
157 };
158
159 static void hppa_cpu_register_types(void)
160 {
161 type_register_static(&hppa_cpu_type_info);
162 }
163
164 type_init(hppa_cpu_register_types)