xref: /openbmc/qemu/target/arm/cpu.c (revision 750245ed7ce2a426a4eaf026f1af3a21fbdc19dc)
1fcf5ef2aSThomas Huth /*
2fcf5ef2aSThomas Huth  * QEMU ARM CPU
3fcf5ef2aSThomas Huth  *
4fcf5ef2aSThomas Huth  * Copyright (c) 2012 SUSE LINUX Products GmbH
5fcf5ef2aSThomas Huth  *
6fcf5ef2aSThomas Huth  * This program is free software; you can redistribute it and/or
7fcf5ef2aSThomas Huth  * modify it under the terms of the GNU General Public License
8fcf5ef2aSThomas Huth  * as published by the Free Software Foundation; either version 2
9fcf5ef2aSThomas Huth  * of the License, or (at your option) any later version.
10fcf5ef2aSThomas Huth  *
11fcf5ef2aSThomas Huth  * This program is distributed in the hope that it will be useful,
12fcf5ef2aSThomas Huth  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13fcf5ef2aSThomas Huth  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14fcf5ef2aSThomas Huth  * GNU General Public License for more details.
15fcf5ef2aSThomas Huth  *
16fcf5ef2aSThomas Huth  * You should have received a copy of the GNU General Public License
17fcf5ef2aSThomas Huth  * along with this program; if not, see
18fcf5ef2aSThomas Huth  * <http://www.gnu.org/licenses/gpl-2.0.html>
19fcf5ef2aSThomas Huth  */
20fcf5ef2aSThomas Huth 
21fcf5ef2aSThomas Huth #include "qemu/osdep.h"
2286480615SPhilippe Mathieu-Daudé #include "qemu/qemu-print.h"
23b8012ecfSPhilippe Mathieu-Daudé #include "qemu/timer.h"
248cc2246cSPeter Maydell #include "qemu/log.h"
25ec5f7ca8SMarc-André Lureau #include "exec/page-vary.h"
26181962fdSPeter Maydell #include "target/arm/idau.h"
270b8fa32fSMarkus Armbruster #include "qemu/module.h"
28fcf5ef2aSThomas Huth #include "qapi/error.h"
29fcf5ef2aSThomas Huth #include "cpu.h"
3078271684SClaudio Fontana #ifdef CONFIG_TCG
3178271684SClaudio Fontana #include "hw/core/tcg-cpu-ops.h"
3278271684SClaudio Fontana #endif /* CONFIG_TCG */
33fcf5ef2aSThomas Huth #include "internals.h"
345a534314SPeter Maydell #include "cpu-features.h"
35fcf5ef2aSThomas Huth #include "exec/exec-all.h"
36fcf5ef2aSThomas Huth #include "hw/qdev-properties.h"
37fcf5ef2aSThomas Huth #if !defined(CONFIG_USER_ONLY)
38fcf5ef2aSThomas Huth #include "hw/loader.h"
39cc7d44c2SLike Xu #include "hw/boards.h"
40165876f2SPhilippe Mathieu-Daudé #ifdef CONFIG_TCG
418f4e07c9SPhilippe Mathieu-Daudé #include "hw/intc/armv7m_nvic.h"
42165876f2SPhilippe Mathieu-Daudé #endif /* CONFIG_TCG */
43165876f2SPhilippe Mathieu-Daudé #endif /* !CONFIG_USER_ONLY */
4414a48c1dSMarkus Armbruster #include "sysemu/tcg.h"
45045e5064SAlexander Graf #include "sysemu/qtest.h"
46b3946626SVincent Palatin #include "sysemu/hw_accel.h"
47fcf5ef2aSThomas Huth #include "kvm_arm.h"
48110f6c70SRichard Henderson #include "disas/capstone.h"
4924f91e81SAlex Bennée #include "fpu/softfloat.h"
50cf7c6d10SRichard Henderson #include "cpregs.h"
51fcf5ef2aSThomas Huth 
52fcf5ef2aSThomas Huth static void arm_cpu_set_pc(CPUState *cs, vaddr value)
53fcf5ef2aSThomas Huth {
54fcf5ef2aSThomas Huth     ARMCPU *cpu = ARM_CPU(cs);
5542f6ed91SJulia Suvorova     CPUARMState *env = &cpu->env;
56fcf5ef2aSThomas Huth 
5742f6ed91SJulia Suvorova     if (is_a64(env)) {
5842f6ed91SJulia Suvorova         env->pc = value;
59063bbd80SRichard Henderson         env->thumb = false;
6042f6ed91SJulia Suvorova     } else {
6142f6ed91SJulia Suvorova         env->regs[15] = value & ~1;
6242f6ed91SJulia Suvorova         env->thumb = value & 1;
6342f6ed91SJulia Suvorova     }
6442f6ed91SJulia Suvorova }
6542f6ed91SJulia Suvorova 
66e4fdf9dfSRichard Henderson static vaddr arm_cpu_get_pc(CPUState *cs)
67e4fdf9dfSRichard Henderson {
68e4fdf9dfSRichard Henderson     ARMCPU *cpu = ARM_CPU(cs);
69e4fdf9dfSRichard Henderson     CPUARMState *env = &cpu->env;
70e4fdf9dfSRichard Henderson 
71e4fdf9dfSRichard Henderson     if (is_a64(env)) {
72e4fdf9dfSRichard Henderson         return env->pc;
73e4fdf9dfSRichard Henderson     } else {
74e4fdf9dfSRichard Henderson         return env->regs[15];
75e4fdf9dfSRichard Henderson     }
76e4fdf9dfSRichard Henderson }
77e4fdf9dfSRichard Henderson 
78ec62595bSEduardo Habkost #ifdef CONFIG_TCG
7978271684SClaudio Fontana void arm_cpu_synchronize_from_tb(CPUState *cs,
8004a37d4cSRichard Henderson                                  const TranslationBlock *tb)
8142f6ed91SJulia Suvorova {
8203a648c4SAnton Johansson     /* The program counter is always up to date with CF_PCREL. */
8303a648c4SAnton Johansson     if (!(tb_cflags(tb) & CF_PCREL)) {
84b77af26eSRichard Henderson         CPUARMState *env = cpu_env(cs);
8542f6ed91SJulia Suvorova         /*
8642f6ed91SJulia Suvorova          * It's OK to look at env for the current mode here, because it's
8742f6ed91SJulia Suvorova          * never possible for an AArch64 TB to chain to an AArch32 TB.
8842f6ed91SJulia Suvorova          */
8942f6ed91SJulia Suvorova         if (is_a64(env)) {
90f51a1dd7SAnton Johansson             env->pc = tb->pc;
9142f6ed91SJulia Suvorova         } else {
92f51a1dd7SAnton Johansson             env->regs[15] = tb->pc;
9342f6ed91SJulia Suvorova         }
94fcf5ef2aSThomas Huth     }
95abb80995SRichard Henderson }
9656c6c98dSRichard Henderson 
97475e56b6SEvgeny Ermakov void arm_restore_state_to_opc(CPUState *cs,
9856c6c98dSRichard Henderson                               const TranslationBlock *tb,
9956c6c98dSRichard Henderson                               const uint64_t *data)
10056c6c98dSRichard Henderson {
101b77af26eSRichard Henderson     CPUARMState *env = cpu_env(cs);
10256c6c98dSRichard Henderson 
10356c6c98dSRichard Henderson     if (is_a64(env)) {
10403a648c4SAnton Johansson         if (tb_cflags(tb) & CF_PCREL) {
10556c6c98dSRichard Henderson             env->pc = (env->pc & TARGET_PAGE_MASK) | data[0];
10656c6c98dSRichard Henderson         } else {
10756c6c98dSRichard Henderson             env->pc = data[0];
10856c6c98dSRichard Henderson         }
10956c6c98dSRichard Henderson         env->condexec_bits = 0;
11056c6c98dSRichard Henderson         env->exception.syndrome = data[2] << ARM_INSN_START_WORD2_SHIFT;
11156c6c98dSRichard Henderson     } else {
11203a648c4SAnton Johansson         if (tb_cflags(tb) & CF_PCREL) {
11356c6c98dSRichard Henderson             env->regs[15] = (env->regs[15] & TARGET_PAGE_MASK) | data[0];
11456c6c98dSRichard Henderson         } else {
11556c6c98dSRichard Henderson             env->regs[15] = data[0];
11656c6c98dSRichard Henderson         }
11756c6c98dSRichard Henderson         env->condexec_bits = data[1];
11856c6c98dSRichard Henderson         env->exception.syndrome = data[2] << ARM_INSN_START_WORD2_SHIFT;
11956c6c98dSRichard Henderson     }
12056c6c98dSRichard Henderson }
121ec62595bSEduardo Habkost #endif /* CONFIG_TCG */
122fcf5ef2aSThomas Huth 
123fcf5ef2aSThomas Huth static bool arm_cpu_has_work(CPUState *cs)
124fcf5ef2aSThomas Huth {
125fcf5ef2aSThomas Huth     ARMCPU *cpu = ARM_CPU(cs);
126fcf5ef2aSThomas Huth 
127062ba099SAlex Bennée     return (cpu->power_state != PSCI_OFF)
128fcf5ef2aSThomas Huth         && cs->interrupt_request &
129fcf5ef2aSThomas Huth         (CPU_INTERRUPT_FIQ | CPU_INTERRUPT_HARD
1303c29632fSRichard Henderson          | CPU_INTERRUPT_VFIQ | CPU_INTERRUPT_VIRQ | CPU_INTERRUPT_VSERR
131fcf5ef2aSThomas Huth          | CPU_INTERRUPT_EXITTB);
132fcf5ef2aSThomas Huth }
133fcf5ef2aSThomas Huth 
134b5c53d1bSAaron Lindsay void arm_register_pre_el_change_hook(ARMCPU *cpu, ARMELChangeHookFn *hook,
135b5c53d1bSAaron Lindsay                                  void *opaque)
136b5c53d1bSAaron Lindsay {
137b5c53d1bSAaron Lindsay     ARMELChangeHook *entry = g_new0(ARMELChangeHook, 1);
138b5c53d1bSAaron Lindsay 
139b5c53d1bSAaron Lindsay     entry->hook = hook;
140b5c53d1bSAaron Lindsay     entry->opaque = opaque;
141b5c53d1bSAaron Lindsay 
142b5c53d1bSAaron Lindsay     QLIST_INSERT_HEAD(&cpu->pre_el_change_hooks, entry, node);
143b5c53d1bSAaron Lindsay }
144b5c53d1bSAaron Lindsay 
14508267487SAaron Lindsay void arm_register_el_change_hook(ARMCPU *cpu, ARMELChangeHookFn *hook,
146fcf5ef2aSThomas Huth                                  void *opaque)
147fcf5ef2aSThomas Huth {
14808267487SAaron Lindsay     ARMELChangeHook *entry = g_new0(ARMELChangeHook, 1);
14908267487SAaron Lindsay 
15008267487SAaron Lindsay     entry->hook = hook;
15108267487SAaron Lindsay     entry->opaque = opaque;
15208267487SAaron Lindsay 
15308267487SAaron Lindsay     QLIST_INSERT_HEAD(&cpu->el_change_hooks, entry, node);
154fcf5ef2aSThomas Huth }
155fcf5ef2aSThomas Huth 
156fcf5ef2aSThomas Huth static void cp_reg_reset(gpointer key, gpointer value, gpointer opaque)
157fcf5ef2aSThomas Huth {
158fcf5ef2aSThomas Huth     /* Reset a single ARMCPRegInfo register */
159fcf5ef2aSThomas Huth     ARMCPRegInfo *ri = value;
160fcf5ef2aSThomas Huth     ARMCPU *cpu = opaque;
161fcf5ef2aSThomas Huth 
16287c3f0f2SRichard Henderson     if (ri->type & (ARM_CP_SPECIAL_MASK | ARM_CP_ALIAS)) {
163fcf5ef2aSThomas Huth         return;
164fcf5ef2aSThomas Huth     }
165fcf5ef2aSThomas Huth 
166fcf5ef2aSThomas Huth     if (ri->resetfn) {
167fcf5ef2aSThomas Huth         ri->resetfn(&cpu->env, ri);
168fcf5ef2aSThomas Huth         return;
169fcf5ef2aSThomas Huth     }
170fcf5ef2aSThomas Huth 
171fcf5ef2aSThomas Huth     /* A zero offset is never possible as it would be regs[0]
172fcf5ef2aSThomas Huth      * so we use it to indicate that reset is being handled elsewhere.
173fcf5ef2aSThomas Huth      * This is basically only used for fields in non-core coprocessors
174fcf5ef2aSThomas Huth      * (like the pxa2xx ones).
175fcf5ef2aSThomas Huth      */
176fcf5ef2aSThomas Huth     if (!ri->fieldoffset) {
177fcf5ef2aSThomas Huth         return;
178fcf5ef2aSThomas Huth     }
179fcf5ef2aSThomas Huth 
180fcf5ef2aSThomas Huth     if (cpreg_field_is_64bit(ri)) {
181fcf5ef2aSThomas Huth         CPREG_FIELD64(&cpu->env, ri) = ri->resetvalue;
182fcf5ef2aSThomas Huth     } else {
183fcf5ef2aSThomas Huth         CPREG_FIELD32(&cpu->env, ri) = ri->resetvalue;
184fcf5ef2aSThomas Huth     }
185fcf5ef2aSThomas Huth }
186fcf5ef2aSThomas Huth 
187fcf5ef2aSThomas Huth static void cp_reg_check_reset(gpointer key, gpointer value,  gpointer opaque)
188fcf5ef2aSThomas Huth {
189fcf5ef2aSThomas Huth     /* Purely an assertion check: we've already done reset once,
190fcf5ef2aSThomas Huth      * so now check that running the reset for the cpreg doesn't
191fcf5ef2aSThomas Huth      * change its value. This traps bugs where two different cpregs
192fcf5ef2aSThomas Huth      * both try to reset the same state field but to different values.
193fcf5ef2aSThomas Huth      */
194fcf5ef2aSThomas Huth     ARMCPRegInfo *ri = value;
195fcf5ef2aSThomas Huth     ARMCPU *cpu = opaque;
196fcf5ef2aSThomas Huth     uint64_t oldvalue, newvalue;
197fcf5ef2aSThomas Huth 
19887c3f0f2SRichard Henderson     if (ri->type & (ARM_CP_SPECIAL_MASK | ARM_CP_ALIAS | ARM_CP_NO_RAW)) {
199fcf5ef2aSThomas Huth         return;
200fcf5ef2aSThomas Huth     }
201fcf5ef2aSThomas Huth 
202fcf5ef2aSThomas Huth     oldvalue = read_raw_cp_reg(&cpu->env, ri);
203fcf5ef2aSThomas Huth     cp_reg_reset(key, value, opaque);
204fcf5ef2aSThomas Huth     newvalue = read_raw_cp_reg(&cpu->env, ri);
205fcf5ef2aSThomas Huth     assert(oldvalue == newvalue);
206fcf5ef2aSThomas Huth }
207fcf5ef2aSThomas Huth 
2089130cadeSPeter Maydell static void arm_cpu_reset_hold(Object *obj)
209fcf5ef2aSThomas Huth {
2109130cadeSPeter Maydell     CPUState *s = CPU(obj);
211fcf5ef2aSThomas Huth     ARMCPU *cpu = ARM_CPU(s);
212fcf5ef2aSThomas Huth     ARMCPUClass *acc = ARM_CPU_GET_CLASS(cpu);
213fcf5ef2aSThomas Huth     CPUARMState *env = &cpu->env;
214fcf5ef2aSThomas Huth 
2159130cadeSPeter Maydell     if (acc->parent_phases.hold) {
2169130cadeSPeter Maydell         acc->parent_phases.hold(obj);
2179130cadeSPeter Maydell     }
218fcf5ef2aSThomas Huth 
2191f5c00cfSAlex Bennée     memset(env, 0, offsetof(CPUARMState, end_reset_fields));
2201f5c00cfSAlex Bennée 
221fcf5ef2aSThomas Huth     g_hash_table_foreach(cpu->cp_regs, cp_reg_reset, cpu);
222fcf5ef2aSThomas Huth     g_hash_table_foreach(cpu->cp_regs, cp_reg_check_reset, cpu);
223fcf5ef2aSThomas Huth 
224fcf5ef2aSThomas Huth     env->vfp.xregs[ARM_VFP_FPSID] = cpu->reset_fpsid;
22547576b94SRichard Henderson     env->vfp.xregs[ARM_VFP_MVFR0] = cpu->isar.mvfr0;
22647576b94SRichard Henderson     env->vfp.xregs[ARM_VFP_MVFR1] = cpu->isar.mvfr1;
22747576b94SRichard Henderson     env->vfp.xregs[ARM_VFP_MVFR2] = cpu->isar.mvfr2;
228fcf5ef2aSThomas Huth 
229c1b70158SThiago Jung Bauermann     cpu->power_state = s->start_powered_off ? PSCI_OFF : PSCI_ON;
230fcf5ef2aSThomas Huth 
231fcf5ef2aSThomas Huth     if (arm_feature(env, ARM_FEATURE_IWMMXT)) {
232fcf5ef2aSThomas Huth         env->iwmmxt.cregs[ARM_IWMMXT_wCID] = 0x69051000 | 'Q';
233fcf5ef2aSThomas Huth     }
234fcf5ef2aSThomas Huth 
235fcf5ef2aSThomas Huth     if (arm_feature(env, ARM_FEATURE_AARCH64)) {
236fcf5ef2aSThomas Huth         /* 64 bit CPUs always start in 64 bit mode */
23753221552SRichard Henderson         env->aarch64 = true;
238fcf5ef2aSThomas Huth #if defined(CONFIG_USER_ONLY)
239fcf5ef2aSThomas Huth         env->pstate = PSTATE_MODE_EL0t;
240fcf5ef2aSThomas Huth         /* Userspace expects access to DC ZVA, CTL_EL0 and the cache ops */
241fcf5ef2aSThomas Huth         env->cp15.sctlr_el[1] |= SCTLR_UCT | SCTLR_UCI | SCTLR_DZE;
242276c6e81SRichard Henderson         /* Enable all PAC keys.  */
243276c6e81SRichard Henderson         env->cp15.sctlr_el[1] |= (SCTLR_EnIA | SCTLR_EnIB |
244276c6e81SRichard Henderson                                   SCTLR_EnDA | SCTLR_EnDB);
245cda86e2bSRichard Henderson         /* Trap on btype=3 for PACIxSP. */
246cda86e2bSRichard Henderson         env->cp15.sctlr_el[1] |= SCTLR_BT0;
247d03396a8SRichard Henderson         /* Trap on implementation defined registers. */
248d03396a8SRichard Henderson         if (cpu_isar_feature(aa64_tidcp1, cpu)) {
249d03396a8SRichard Henderson             env->cp15.sctlr_el[1] |= SCTLR_TIDCP;
250d03396a8SRichard Henderson         }
251fcf5ef2aSThomas Huth         /* and to the FP/Neon instructions */
252fab8ad39SRichard Henderson         env->cp15.cpacr_el1 = FIELD_DP64(env->cp15.cpacr_el1,
253fab8ad39SRichard Henderson                                          CPACR_EL1, FPEN, 3);
25446303535SRichard Henderson         /* and to the SVE instructions, with default vector length */
25546303535SRichard Henderson         if (cpu_isar_feature(aa64_sve, cpu)) {
256fab8ad39SRichard Henderson             env->cp15.cpacr_el1 = FIELD_DP64(env->cp15.cpacr_el1,
257fab8ad39SRichard Henderson                                              CPACR_EL1, ZEN, 3);
25887252bdeSRichard Henderson             env->vfp.zcr_el[1] = cpu->sve_default_vq - 1;
2597b6a2198SAlex Bennée         }
26078011586SRichard Henderson         /* and for SME instructions, with default vector length, and TPIDR2 */
26178011586SRichard Henderson         if (cpu_isar_feature(aa64_sme, cpu)) {
26278011586SRichard Henderson             env->cp15.sctlr_el[1] |= SCTLR_EnTP2;
26378011586SRichard Henderson             env->cp15.cpacr_el1 = FIELD_DP64(env->cp15.cpacr_el1,
26478011586SRichard Henderson                                              CPACR_EL1, SMEN, 3);
26578011586SRichard Henderson             env->vfp.smcr_el[1] = cpu->sme_default_vq - 1;
26678011586SRichard Henderson             if (cpu_isar_feature(aa64_sme_fa64, cpu)) {
26778011586SRichard Henderson                 env->vfp.smcr_el[1] = FIELD_DP64(env->vfp.smcr_el[1],
26878011586SRichard Henderson                                                  SMCR, FA64, 1);
26978011586SRichard Henderson             }
27078011586SRichard Henderson         }
271f6a148feSRichard Henderson         /*
272691f1ffdSRichard Henderson          * Enable 48-bit address space (TODO: take reserved_va into account).
27316c84978SRichard Henderson          * Enable TBI0 but not TBI1.
27416c84978SRichard Henderson          * Note that this must match useronly_clean_ptr.
275f6a148feSRichard Henderson          */
276cb4a0a34SPeter Maydell         env->cp15.tcr_el[1] = 5 | (1ULL << 37);
277e3232864SRichard Henderson 
278e3232864SRichard Henderson         /* Enable MTE */
279e3232864SRichard Henderson         if (cpu_isar_feature(aa64_mte, cpu)) {
280e3232864SRichard Henderson             /* Enable tag access, but leave TCF0 as No Effect (0). */
281e3232864SRichard Henderson             env->cp15.sctlr_el[1] |= SCTLR_ATA0;
282e3232864SRichard Henderson             /*
283e3232864SRichard Henderson              * Exclude all tags, so that tag 0 is always used.
284e3232864SRichard Henderson              * This corresponds to Linux current->thread.gcr_incl = 0.
285e3232864SRichard Henderson              *
286e3232864SRichard Henderson              * Set RRND, so that helper_irg() will generate a seed later.
287e3232864SRichard Henderson              * Here in cpu_reset(), the crypto subsystem has not yet been
288e3232864SRichard Henderson              * initialized.
289e3232864SRichard Henderson              */
290e3232864SRichard Henderson             env->cp15.gcr_el1 = 0x1ffff;
291e3232864SRichard Henderson         }
2927cb1e618SRichard Henderson         /*
2937cb1e618SRichard Henderson          * Disable access to SCXTNUM_EL0 from CSV2_1p2.
2947cb1e618SRichard Henderson          * This is not yet exposed from the Linux kernel in any way.
2957cb1e618SRichard Henderson          */
2967cb1e618SRichard Henderson         env->cp15.sctlr_el[1] |= SCTLR_TSCXT;
297f9ac7788SZhuojia Shen         /* Disable access to Debug Communication Channel (DCC). */
298f9ac7788SZhuojia Shen         env->cp15.mdscr_el1 |= 1 << 12;
299a6b2c5a0SPeter Maydell         /* Enable FEAT_MOPS */
300a6b2c5a0SPeter Maydell         env->cp15.sctlr_el[1] |= SCTLR_MSCEN;
301fcf5ef2aSThomas Huth #else
302fcf5ef2aSThomas Huth         /* Reset into the highest available EL */
303fcf5ef2aSThomas Huth         if (arm_feature(env, ARM_FEATURE_EL3)) {
304fcf5ef2aSThomas Huth             env->pstate = PSTATE_MODE_EL3h;
305fcf5ef2aSThomas Huth         } else if (arm_feature(env, ARM_FEATURE_EL2)) {
306fcf5ef2aSThomas Huth             env->pstate = PSTATE_MODE_EL2h;
307fcf5ef2aSThomas Huth         } else {
308fcf5ef2aSThomas Huth             env->pstate = PSTATE_MODE_EL1h;
309fcf5ef2aSThomas Huth         }
3104a7319b7SEdgar E. Iglesias 
3114a7319b7SEdgar E. Iglesias         /* Sample rvbar at reset.  */
3124a7319b7SEdgar E. Iglesias         env->cp15.rvbar = cpu->rvbar_prop;
3134a7319b7SEdgar E. Iglesias         env->pc = env->cp15.rvbar;
314fcf5ef2aSThomas Huth #endif
315fcf5ef2aSThomas Huth     } else {
316fcf5ef2aSThomas Huth #if defined(CONFIG_USER_ONLY)
317fcf5ef2aSThomas Huth         /* Userspace expects access to cp10 and cp11 for FP/Neon */
318fab8ad39SRichard Henderson         env->cp15.cpacr_el1 = FIELD_DP64(env->cp15.cpacr_el1,
319fab8ad39SRichard Henderson                                          CPACR, CP10, 3);
320fab8ad39SRichard Henderson         env->cp15.cpacr_el1 = FIELD_DP64(env->cp15.cpacr_el1,
321fab8ad39SRichard Henderson                                          CPACR, CP11, 3);
322fcf5ef2aSThomas Huth #endif
323910e4f24STobias Röhmel         if (arm_feature(env, ARM_FEATURE_V8)) {
324910e4f24STobias Röhmel             env->cp15.rvbar = cpu->rvbar_prop;
325910e4f24STobias Röhmel             env->regs[15] = cpu->rvbar_prop;
326910e4f24STobias Röhmel         }
327fcf5ef2aSThomas Huth     }
328fcf5ef2aSThomas Huth 
329fcf5ef2aSThomas Huth #if defined(CONFIG_USER_ONLY)
330fcf5ef2aSThomas Huth     env->uncached_cpsr = ARM_CPU_MODE_USR;
331fcf5ef2aSThomas Huth     /* For user mode we must enable access to coprocessors */
332fcf5ef2aSThomas Huth     env->vfp.xregs[ARM_VFP_FPEXC] = 1 << 30;
333fcf5ef2aSThomas Huth     if (arm_feature(env, ARM_FEATURE_IWMMXT)) {
334fcf5ef2aSThomas Huth         env->cp15.c15_cpar = 3;
335fcf5ef2aSThomas Huth     } else if (arm_feature(env, ARM_FEATURE_XSCALE)) {
336fcf5ef2aSThomas Huth         env->cp15.c15_cpar = 1;
337fcf5ef2aSThomas Huth     }
338fcf5ef2aSThomas Huth #else
339060a65dfSPeter Maydell 
340060a65dfSPeter Maydell     /*
341060a65dfSPeter Maydell      * If the highest available EL is EL2, AArch32 will start in Hyp
342060a65dfSPeter Maydell      * mode; otherwise it starts in SVC. Note that if we start in
343060a65dfSPeter Maydell      * AArch64 then these values in the uncached_cpsr will be ignored.
344060a65dfSPeter Maydell      */
345060a65dfSPeter Maydell     if (arm_feature(env, ARM_FEATURE_EL2) &&
346060a65dfSPeter Maydell         !arm_feature(env, ARM_FEATURE_EL3)) {
347060a65dfSPeter Maydell         env->uncached_cpsr = ARM_CPU_MODE_HYP;
348060a65dfSPeter Maydell     } else {
349fcf5ef2aSThomas Huth         env->uncached_cpsr = ARM_CPU_MODE_SVC;
350060a65dfSPeter Maydell     }
351fcf5ef2aSThomas Huth     env->daif = PSTATE_D | PSTATE_A | PSTATE_I | PSTATE_F;
3521426f244SPeter Maydell 
3531426f244SPeter Maydell     /* AArch32 has a hard highvec setting of 0xFFFF0000.  If we are currently
3541426f244SPeter Maydell      * executing as AArch32 then check if highvecs are enabled and
3551426f244SPeter Maydell      * adjust the PC accordingly.
3561426f244SPeter Maydell      */
3571426f244SPeter Maydell     if (A32_BANKED_CURRENT_REG_GET(env, sctlr) & SCTLR_V) {
3581426f244SPeter Maydell         env->regs[15] = 0xFFFF0000;
3591426f244SPeter Maydell     }
3601426f244SPeter Maydell 
3611426f244SPeter Maydell     env->vfp.xregs[ARM_VFP_FPEXC] = 0;
362b62ceeafSPeter Maydell #endif
363dc7abe4dSMichael Davidsaver 
364531c60a9SPeter Maydell     if (arm_feature(env, ARM_FEATURE_M)) {
365b62ceeafSPeter Maydell #ifndef CONFIG_USER_ONLY
366fcf5ef2aSThomas Huth         uint32_t initial_msp; /* Loaded from 0x0 */
367fcf5ef2aSThomas Huth         uint32_t initial_pc; /* Loaded from 0x4 */
368fcf5ef2aSThomas Huth         uint8_t *rom;
36938e2a77cSPeter Maydell         uint32_t vecbase;
370b62ceeafSPeter Maydell #endif
371fcf5ef2aSThomas Huth 
3728128c8e8SPeter Maydell         if (cpu_isar_feature(aa32_lob, cpu)) {
3738128c8e8SPeter Maydell             /*
3748128c8e8SPeter Maydell              * LTPSIZE is constant 4 if MVE not implemented, and resets
3758128c8e8SPeter Maydell              * to an UNKNOWN value if MVE is implemented. We choose to
3768128c8e8SPeter Maydell              * always reset to 4.
3778128c8e8SPeter Maydell              */
3788128c8e8SPeter Maydell             env->v7m.ltpsize = 4;
37999c7834fSPeter Maydell             /* The LTPSIZE field in FPDSCR is constant and reads as 4. */
38099c7834fSPeter Maydell             env->v7m.fpdscr[M_REG_NS] = 4 << FPCR_LTPSIZE_SHIFT;
38199c7834fSPeter Maydell             env->v7m.fpdscr[M_REG_S] = 4 << FPCR_LTPSIZE_SHIFT;
3828128c8e8SPeter Maydell         }
3838128c8e8SPeter Maydell 
3841e577cc7SPeter Maydell         if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
3851e577cc7SPeter Maydell             env->v7m.secure = true;
3863b2e9344SPeter Maydell         } else {
3873b2e9344SPeter Maydell             /* This bit resets to 0 if security is supported, but 1 if
3883b2e9344SPeter Maydell              * it is not. The bit is not present in v7M, but we set it
3893b2e9344SPeter Maydell              * here so we can avoid having to make checks on it conditional
3903b2e9344SPeter Maydell              * on ARM_FEATURE_V8 (we don't let the guest see the bit).
3913b2e9344SPeter Maydell              */
3923b2e9344SPeter Maydell             env->v7m.aircr = R_V7M_AIRCR_BFHFNMINS_MASK;
39302ac2f7fSPeter Maydell             /*
39402ac2f7fSPeter Maydell              * Set NSACR to indicate "NS access permitted to everything";
39502ac2f7fSPeter Maydell              * this avoids having to have all the tests of it being
39602ac2f7fSPeter Maydell              * conditional on ARM_FEATURE_M_SECURITY. Note also that from
39702ac2f7fSPeter Maydell              * v8.1M the guest-visible value of NSACR in a CPU without the
39802ac2f7fSPeter Maydell              * Security Extension is 0xcff.
39902ac2f7fSPeter Maydell              */
40002ac2f7fSPeter Maydell             env->v7m.nsacr = 0xcff;
4011e577cc7SPeter Maydell         }
4021e577cc7SPeter Maydell 
4039d40cd8aSPeter Maydell         /* In v7M the reset value of this bit is IMPDEF, but ARM recommends
4042c4da50dSPeter Maydell          * that it resets to 1, so QEMU always does that rather than making
4059d40cd8aSPeter Maydell          * it dependent on CPU model. In v8M it is RES1.
4062c4da50dSPeter Maydell          */
4079d40cd8aSPeter Maydell         env->v7m.ccr[M_REG_NS] = R_V7M_CCR_STKALIGN_MASK;
4089d40cd8aSPeter Maydell         env->v7m.ccr[M_REG_S] = R_V7M_CCR_STKALIGN_MASK;
4099d40cd8aSPeter Maydell         if (arm_feature(env, ARM_FEATURE_V8)) {
4109d40cd8aSPeter Maydell             /* in v8M the NONBASETHRDENA bit [0] is RES1 */
4119d40cd8aSPeter Maydell             env->v7m.ccr[M_REG_NS] |= R_V7M_CCR_NONBASETHRDENA_MASK;
4129d40cd8aSPeter Maydell             env->v7m.ccr[M_REG_S] |= R_V7M_CCR_NONBASETHRDENA_MASK;
4139d40cd8aSPeter Maydell         }
41422ab3460SJulia Suvorova         if (!arm_feature(env, ARM_FEATURE_M_MAIN)) {
41522ab3460SJulia Suvorova             env->v7m.ccr[M_REG_NS] |= R_V7M_CCR_UNALIGN_TRP_MASK;
41622ab3460SJulia Suvorova             env->v7m.ccr[M_REG_S] |= R_V7M_CCR_UNALIGN_TRP_MASK;
41722ab3460SJulia Suvorova         }
4182c4da50dSPeter Maydell 
4197fbc6a40SRichard Henderson         if (cpu_isar_feature(aa32_vfp_simd, cpu)) {
420d33abe82SPeter Maydell             env->v7m.fpccr[M_REG_NS] = R_V7M_FPCCR_ASPEN_MASK;
421d33abe82SPeter Maydell             env->v7m.fpccr[M_REG_S] = R_V7M_FPCCR_ASPEN_MASK |
422d33abe82SPeter Maydell                 R_V7M_FPCCR_LSPEN_MASK | R_V7M_FPCCR_S_MASK;
423d33abe82SPeter Maydell         }
424b62ceeafSPeter Maydell 
425b62ceeafSPeter Maydell #ifndef CONFIG_USER_ONLY
426056f43dfSPeter Maydell         /* Unlike A/R profile, M profile defines the reset LR value */
427056f43dfSPeter Maydell         env->regs[14] = 0xffffffff;
428056f43dfSPeter Maydell 
42938e2a77cSPeter Maydell         env->v7m.vecbase[M_REG_S] = cpu->init_svtor & 0xffffff80;
4307cda2149SPeter Maydell         env->v7m.vecbase[M_REG_NS] = cpu->init_nsvtor & 0xffffff80;
43138e2a77cSPeter Maydell 
43238e2a77cSPeter Maydell         /* Load the initial SP and PC from offset 0 and 4 in the vector table */
43338e2a77cSPeter Maydell         vecbase = env->v7m.vecbase[env->v7m.secure];
43475ce72b7SPeter Maydell         rom = rom_ptr_for_as(s->as, vecbase, 8);
435fcf5ef2aSThomas Huth         if (rom) {
436fcf5ef2aSThomas Huth             /* Address zero is covered by ROM which hasn't yet been
437fcf5ef2aSThomas Huth              * copied into physical memory.
438fcf5ef2aSThomas Huth              */
439fcf5ef2aSThomas Huth             initial_msp = ldl_p(rom);
440fcf5ef2aSThomas Huth             initial_pc = ldl_p(rom + 4);
441fcf5ef2aSThomas Huth         } else {
442fcf5ef2aSThomas Huth             /* Address zero not covered by a ROM blob, or the ROM blob
443fcf5ef2aSThomas Huth              * is in non-modifiable memory and this is a second reset after
444fcf5ef2aSThomas Huth              * it got copied into memory. In the latter case, rom_ptr
445fcf5ef2aSThomas Huth              * will return a NULL pointer and we should use ldl_phys instead.
446fcf5ef2aSThomas Huth              */
44738e2a77cSPeter Maydell             initial_msp = ldl_phys(s->as, vecbase);
44838e2a77cSPeter Maydell             initial_pc = ldl_phys(s->as, vecbase + 4);
449fcf5ef2aSThomas Huth         }
450fcf5ef2aSThomas Huth 
4518cc2246cSPeter Maydell         qemu_log_mask(CPU_LOG_INT,
4528cc2246cSPeter Maydell                       "Loaded reset SP 0x%x PC 0x%x from vector table\n",
4538cc2246cSPeter Maydell                       initial_msp, initial_pc);
4548cc2246cSPeter Maydell 
455fcf5ef2aSThomas Huth         env->regs[13] = initial_msp & 0xFFFFFFFC;
456fcf5ef2aSThomas Huth         env->regs[15] = initial_pc & ~1;
457fcf5ef2aSThomas Huth         env->thumb = initial_pc & 1;
458b62ceeafSPeter Maydell #else
459b62ceeafSPeter Maydell         /*
460b62ceeafSPeter Maydell          * For user mode we run non-secure and with access to the FPU.
461b62ceeafSPeter Maydell          * The FPU context is active (ie does not need further setup)
462b62ceeafSPeter Maydell          * and is owned by non-secure.
463b62ceeafSPeter Maydell          */
464b62ceeafSPeter Maydell         env->v7m.secure = false;
465b62ceeafSPeter Maydell         env->v7m.nsacr = 0xcff;
466b62ceeafSPeter Maydell         env->v7m.cpacr[M_REG_NS] = 0xf0ffff;
467b62ceeafSPeter Maydell         env->v7m.fpccr[M_REG_S] &=
468b62ceeafSPeter Maydell             ~(R_V7M_FPCCR_LSPEN_MASK | R_V7M_FPCCR_S_MASK);
469b62ceeafSPeter Maydell         env->v7m.control[M_REG_S] |= R_V7M_CONTROL_FPCA_MASK;
470b62ceeafSPeter Maydell #endif
471fcf5ef2aSThomas Huth     }
472fcf5ef2aSThomas Huth 
473dc3c4c14SPeter Maydell     /* M profile requires that reset clears the exclusive monitor;
474dc3c4c14SPeter Maydell      * A profile does not, but clearing it makes more sense than having it
475dc3c4c14SPeter Maydell      * set with an exclusive access on address zero.
476dc3c4c14SPeter Maydell      */
477dc3c4c14SPeter Maydell     arm_clear_exclusive(env);
478dc3c4c14SPeter Maydell 
4790e1a46bbSPeter Maydell     if (arm_feature(env, ARM_FEATURE_PMSA)) {
48069ceea64SPeter Maydell         if (cpu->pmsav7_dregion > 0) {
4810e1a46bbSPeter Maydell             if (arm_feature(env, ARM_FEATURE_V8)) {
48262c58ee0SPeter Maydell                 memset(env->pmsav8.rbar[M_REG_NS], 0,
48362c58ee0SPeter Maydell                        sizeof(*env->pmsav8.rbar[M_REG_NS])
48462c58ee0SPeter Maydell                        * cpu->pmsav7_dregion);
48562c58ee0SPeter Maydell                 memset(env->pmsav8.rlar[M_REG_NS], 0,
48662c58ee0SPeter Maydell                        sizeof(*env->pmsav8.rlar[M_REG_NS])
48762c58ee0SPeter Maydell                        * cpu->pmsav7_dregion);
48862c58ee0SPeter Maydell                 if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
48962c58ee0SPeter Maydell                     memset(env->pmsav8.rbar[M_REG_S], 0,
49062c58ee0SPeter Maydell                            sizeof(*env->pmsav8.rbar[M_REG_S])
49162c58ee0SPeter Maydell                            * cpu->pmsav7_dregion);
49262c58ee0SPeter Maydell                     memset(env->pmsav8.rlar[M_REG_S], 0,
49362c58ee0SPeter Maydell                            sizeof(*env->pmsav8.rlar[M_REG_S])
49462c58ee0SPeter Maydell                            * cpu->pmsav7_dregion);
49562c58ee0SPeter Maydell                 }
4960e1a46bbSPeter Maydell             } else if (arm_feature(env, ARM_FEATURE_V7)) {
49769ceea64SPeter Maydell                 memset(env->pmsav7.drbar, 0,
49869ceea64SPeter Maydell                        sizeof(*env->pmsav7.drbar) * cpu->pmsav7_dregion);
49969ceea64SPeter Maydell                 memset(env->pmsav7.drsr, 0,
50069ceea64SPeter Maydell                        sizeof(*env->pmsav7.drsr) * cpu->pmsav7_dregion);
50169ceea64SPeter Maydell                 memset(env->pmsav7.dracr, 0,
50269ceea64SPeter Maydell                        sizeof(*env->pmsav7.dracr) * cpu->pmsav7_dregion);
50369ceea64SPeter Maydell             }
5040e1a46bbSPeter Maydell         }
505761c4642STobias Röhmel 
506761c4642STobias Röhmel         if (cpu->pmsav8r_hdregion > 0) {
507761c4642STobias Röhmel             memset(env->pmsav8.hprbar, 0,
508761c4642STobias Röhmel                    sizeof(*env->pmsav8.hprbar) * cpu->pmsav8r_hdregion);
509761c4642STobias Röhmel             memset(env->pmsav8.hprlar, 0,
510761c4642STobias Röhmel                    sizeof(*env->pmsav8.hprlar) * cpu->pmsav8r_hdregion);
511761c4642STobias Röhmel         }
512761c4642STobias Röhmel 
5131bc04a88SPeter Maydell         env->pmsav7.rnr[M_REG_NS] = 0;
5141bc04a88SPeter Maydell         env->pmsav7.rnr[M_REG_S] = 0;
5154125e6feSPeter Maydell         env->pmsav8.mair0[M_REG_NS] = 0;
5164125e6feSPeter Maydell         env->pmsav8.mair0[M_REG_S] = 0;
5174125e6feSPeter Maydell         env->pmsav8.mair1[M_REG_NS] = 0;
5184125e6feSPeter Maydell         env->pmsav8.mair1[M_REG_S] = 0;
51969ceea64SPeter Maydell     }
52069ceea64SPeter Maydell 
5219901c576SPeter Maydell     if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
5229901c576SPeter Maydell         if (cpu->sau_sregion > 0) {
5239901c576SPeter Maydell             memset(env->sau.rbar, 0, sizeof(*env->sau.rbar) * cpu->sau_sregion);
5249901c576SPeter Maydell             memset(env->sau.rlar, 0, sizeof(*env->sau.rlar) * cpu->sau_sregion);
5259901c576SPeter Maydell         }
5269901c576SPeter Maydell         env->sau.rnr = 0;
5279901c576SPeter Maydell         /* SAU_CTRL reset value is IMPDEF; we choose 0, which is what
5289901c576SPeter Maydell          * the Cortex-M33 does.
5299901c576SPeter Maydell          */
5309901c576SPeter Maydell         env->sau.ctrl = 0;
5319901c576SPeter Maydell     }
5329901c576SPeter Maydell 
533fcf5ef2aSThomas Huth     set_flush_to_zero(1, &env->vfp.standard_fp_status);
534fcf5ef2aSThomas Huth     set_flush_inputs_to_zero(1, &env->vfp.standard_fp_status);
535fcf5ef2aSThomas Huth     set_default_nan_mode(1, &env->vfp.standard_fp_status);
536aaae563bSPeter Maydell     set_default_nan_mode(1, &env->vfp.standard_fp_status_f16);
537fcf5ef2aSThomas Huth     set_float_detect_tininess(float_tininess_before_rounding,
538fcf5ef2aSThomas Huth                               &env->vfp.fp_status);
539fcf5ef2aSThomas Huth     set_float_detect_tininess(float_tininess_before_rounding,
540fcf5ef2aSThomas Huth                               &env->vfp.standard_fp_status);
541bcc531f0SPeter Maydell     set_float_detect_tininess(float_tininess_before_rounding,
542bcc531f0SPeter Maydell                               &env->vfp.fp_status_f16);
543aaae563bSPeter Maydell     set_float_detect_tininess(float_tininess_before_rounding,
544aaae563bSPeter Maydell                               &env->vfp.standard_fp_status_f16);
545fcf5ef2aSThomas Huth #ifndef CONFIG_USER_ONLY
546fcf5ef2aSThomas Huth     if (kvm_enabled()) {
547fcf5ef2aSThomas Huth         kvm_arm_reset_vcpu(cpu);
548fcf5ef2aSThomas Huth     }
549fcf5ef2aSThomas Huth #endif
550fcf5ef2aSThomas Huth 
551fa05d1abSFabiano Rosas     if (tcg_enabled()) {
552fcf5ef2aSThomas Huth         hw_breakpoint_update_all(cpu);
553fcf5ef2aSThomas Huth         hw_watchpoint_update_all(cpu);
5542b77ad4dSFabiano Rosas 
555a8a79c7aSRichard Henderson         arm_rebuild_hflags(env);
556fcf5ef2aSThomas Huth     }
5572b77ad4dSFabiano Rosas }
558fcf5ef2aSThomas Huth 
5593a45f4f5SPeter Maydell void arm_emulate_firmware_reset(CPUState *cpustate, int target_el)
5603a45f4f5SPeter Maydell {
5613a45f4f5SPeter Maydell     ARMCPU *cpu = ARM_CPU(cpustate);
5623a45f4f5SPeter Maydell     CPUARMState *env = &cpu->env;
5633a45f4f5SPeter Maydell     bool have_el3 = arm_feature(env, ARM_FEATURE_EL3);
5643a45f4f5SPeter Maydell     bool have_el2 = arm_feature(env, ARM_FEATURE_EL2);
5653a45f4f5SPeter Maydell 
5663a45f4f5SPeter Maydell     /*
5673a45f4f5SPeter Maydell      * Check we have the EL we're aiming for. If that is the
5683a45f4f5SPeter Maydell      * highest implemented EL, then cpu_reset has already done
5693a45f4f5SPeter Maydell      * all the work.
5703a45f4f5SPeter Maydell      */
5713a45f4f5SPeter Maydell     switch (target_el) {
5723a45f4f5SPeter Maydell     case 3:
5733a45f4f5SPeter Maydell         assert(have_el3);
5743a45f4f5SPeter Maydell         return;
5753a45f4f5SPeter Maydell     case 2:
5763a45f4f5SPeter Maydell         assert(have_el2);
5773a45f4f5SPeter Maydell         if (!have_el3) {
5783a45f4f5SPeter Maydell             return;
5793a45f4f5SPeter Maydell         }
5803a45f4f5SPeter Maydell         break;
5813a45f4f5SPeter Maydell     case 1:
5823a45f4f5SPeter Maydell         if (!have_el3 && !have_el2) {
5833a45f4f5SPeter Maydell             return;
5843a45f4f5SPeter Maydell         }
5853a45f4f5SPeter Maydell         break;
5863a45f4f5SPeter Maydell     default:
5873a45f4f5SPeter Maydell         g_assert_not_reached();
5883a45f4f5SPeter Maydell     }
5893a45f4f5SPeter Maydell 
5903a45f4f5SPeter Maydell     if (have_el3) {
5913a45f4f5SPeter Maydell         /*
5923a45f4f5SPeter Maydell          * Set the EL3 state so code can run at EL2. This should match
5933a45f4f5SPeter Maydell          * the requirements set by Linux in its booting spec.
5943a45f4f5SPeter Maydell          */
5953a45f4f5SPeter Maydell         if (env->aarch64) {
5963a45f4f5SPeter Maydell             env->cp15.scr_el3 |= SCR_RW;
5973a45f4f5SPeter Maydell             if (cpu_isar_feature(aa64_pauth, cpu)) {
5983a45f4f5SPeter Maydell                 env->cp15.scr_el3 |= SCR_API | SCR_APK;
5993a45f4f5SPeter Maydell             }
6003a45f4f5SPeter Maydell             if (cpu_isar_feature(aa64_mte, cpu)) {
6013a45f4f5SPeter Maydell                 env->cp15.scr_el3 |= SCR_ATA;
6023a45f4f5SPeter Maydell             }
6033a45f4f5SPeter Maydell             if (cpu_isar_feature(aa64_sve, cpu)) {
6043a45f4f5SPeter Maydell                 env->cp15.cptr_el[3] |= R_CPTR_EL3_EZ_MASK;
6053a45f4f5SPeter Maydell                 env->vfp.zcr_el[3] = 0xf;
6063a45f4f5SPeter Maydell             }
6073a45f4f5SPeter Maydell             if (cpu_isar_feature(aa64_sme, cpu)) {
6083a45f4f5SPeter Maydell                 env->cp15.cptr_el[3] |= R_CPTR_EL3_ESM_MASK;
6093a45f4f5SPeter Maydell                 env->cp15.scr_el3 |= SCR_ENTP2;
6103a45f4f5SPeter Maydell                 env->vfp.smcr_el[3] = 0xf;
6113a45f4f5SPeter Maydell             }
6123a45f4f5SPeter Maydell             if (cpu_isar_feature(aa64_hcx, cpu)) {
6133a45f4f5SPeter Maydell                 env->cp15.scr_el3 |= SCR_HXEN;
6143a45f4f5SPeter Maydell             }
6153a45f4f5SPeter Maydell             if (cpu_isar_feature(aa64_fgt, cpu)) {
6163a45f4f5SPeter Maydell                 env->cp15.scr_el3 |= SCR_FGTEN;
6173a45f4f5SPeter Maydell             }
6183a45f4f5SPeter Maydell         }
6193a45f4f5SPeter Maydell 
6203a45f4f5SPeter Maydell         if (target_el == 2) {
6213a45f4f5SPeter Maydell             /* If the guest is at EL2 then Linux expects the HVC insn to work */
6223a45f4f5SPeter Maydell             env->cp15.scr_el3 |= SCR_HCE;
6233a45f4f5SPeter Maydell         }
6243a45f4f5SPeter Maydell 
6253a45f4f5SPeter Maydell         /* Put CPU into non-secure state */
6263a45f4f5SPeter Maydell         env->cp15.scr_el3 |= SCR_NS;
6273a45f4f5SPeter Maydell         /* Set NSACR.{CP11,CP10} so NS can access the FPU */
6283a45f4f5SPeter Maydell         env->cp15.nsacr |= 3 << 10;
6293a45f4f5SPeter Maydell     }
6303a45f4f5SPeter Maydell 
6313a45f4f5SPeter Maydell     if (have_el2 && target_el < 2) {
6323a45f4f5SPeter Maydell         /* Set EL2 state so code can run at EL1. */
6333a45f4f5SPeter Maydell         if (env->aarch64) {
6343a45f4f5SPeter Maydell             env->cp15.hcr_el2 |= HCR_RW;
6353a45f4f5SPeter Maydell         }
6363a45f4f5SPeter Maydell     }
6373a45f4f5SPeter Maydell 
6383a45f4f5SPeter Maydell     /* Set the CPU to the desired state */
6393a45f4f5SPeter Maydell     if (env->aarch64) {
6403a45f4f5SPeter Maydell         env->pstate = aarch64_pstate_mode(target_el, true);
6413a45f4f5SPeter Maydell     } else {
6423a45f4f5SPeter Maydell         static const uint32_t mode_for_el[] = {
6433a45f4f5SPeter Maydell             0,
6443a45f4f5SPeter Maydell             ARM_CPU_MODE_SVC,
6453a45f4f5SPeter Maydell             ARM_CPU_MODE_HYP,
6463a45f4f5SPeter Maydell             ARM_CPU_MODE_SVC,
6473a45f4f5SPeter Maydell         };
6483a45f4f5SPeter Maydell 
6493a45f4f5SPeter Maydell         cpsr_write(env, mode_for_el[target_el], CPSR_M, CPSRWriteRaw);
6503a45f4f5SPeter Maydell     }
6513a45f4f5SPeter Maydell }
6523a45f4f5SPeter Maydell 
6533a45f4f5SPeter Maydell 
6549e406eeaSPhilippe Mathieu-Daudé #if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
655083afd18SPhilippe Mathieu-Daudé 
656310cedf3SRichard Henderson static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx,
657be879556SRichard Henderson                                      unsigned int target_el,
658be879556SRichard Henderson                                      unsigned int cur_el, bool secure,
659be879556SRichard Henderson                                      uint64_t hcr_el2)
660310cedf3SRichard Henderson {
661b77af26eSRichard Henderson     CPUARMState *env = cpu_env(cs);
662310cedf3SRichard Henderson     bool pstate_unmasked;
66316e07f78SRichard Henderson     bool unmasked = false;
664310cedf3SRichard Henderson 
665310cedf3SRichard Henderson     /*
666310cedf3SRichard Henderson      * Don't take exceptions if they target a lower EL.
667310cedf3SRichard Henderson      * This check should catch any exceptions that would not be taken
668310cedf3SRichard Henderson      * but left pending.
669310cedf3SRichard Henderson      */
670310cedf3SRichard Henderson     if (cur_el > target_el) {
671310cedf3SRichard Henderson         return false;
672310cedf3SRichard Henderson     }
673310cedf3SRichard Henderson 
674310cedf3SRichard Henderson     switch (excp_idx) {
675310cedf3SRichard Henderson     case EXCP_FIQ:
676310cedf3SRichard Henderson         pstate_unmasked = !(env->daif & PSTATE_F);
677310cedf3SRichard Henderson         break;
678310cedf3SRichard Henderson 
679310cedf3SRichard Henderson     case EXCP_IRQ:
680310cedf3SRichard Henderson         pstate_unmasked = !(env->daif & PSTATE_I);
681310cedf3SRichard Henderson         break;
682310cedf3SRichard Henderson 
683310cedf3SRichard Henderson     case EXCP_VFIQ:
684cc974d5cSRémi Denis-Courmont         if (!(hcr_el2 & HCR_FMO) || (hcr_el2 & HCR_TGE)) {
685cc974d5cSRémi Denis-Courmont             /* VFIQs are only taken when hypervized.  */
686310cedf3SRichard Henderson             return false;
687310cedf3SRichard Henderson         }
688310cedf3SRichard Henderson         return !(env->daif & PSTATE_F);
689310cedf3SRichard Henderson     case EXCP_VIRQ:
690cc974d5cSRémi Denis-Courmont         if (!(hcr_el2 & HCR_IMO) || (hcr_el2 & HCR_TGE)) {
691cc974d5cSRémi Denis-Courmont             /* VIRQs are only taken when hypervized.  */
692310cedf3SRichard Henderson             return false;
693310cedf3SRichard Henderson         }
694310cedf3SRichard Henderson         return !(env->daif & PSTATE_I);
6953c29632fSRichard Henderson     case EXCP_VSERR:
6963c29632fSRichard Henderson         if (!(hcr_el2 & HCR_AMO) || (hcr_el2 & HCR_TGE)) {
6973c29632fSRichard Henderson             /* VIRQs are only taken when hypervized.  */
6983c29632fSRichard Henderson             return false;
6993c29632fSRichard Henderson         }
7003c29632fSRichard Henderson         return !(env->daif & PSTATE_A);
701310cedf3SRichard Henderson     default:
702310cedf3SRichard Henderson         g_assert_not_reached();
703310cedf3SRichard Henderson     }
704310cedf3SRichard Henderson 
705310cedf3SRichard Henderson     /*
706310cedf3SRichard Henderson      * Use the target EL, current execution state and SCR/HCR settings to
707310cedf3SRichard Henderson      * determine whether the corresponding CPSR bit is used to mask the
708310cedf3SRichard Henderson      * interrupt.
709310cedf3SRichard Henderson      */
710310cedf3SRichard Henderson     if ((target_el > cur_el) && (target_el != 1)) {
711310cedf3SRichard Henderson         /* Exceptions targeting a higher EL may not be maskable */
712310cedf3SRichard Henderson         if (arm_feature(env, ARM_FEATURE_AARCH64)) {
713c939a7c7SAke Koomsin             switch (target_el) {
714c939a7c7SAke Koomsin             case 2:
715310cedf3SRichard Henderson                 /*
716c939a7c7SAke Koomsin                  * According to ARM DDI 0487H.a, an interrupt can be masked
717c939a7c7SAke Koomsin                  * when HCR_E2H and HCR_TGE are both set regardless of the
718c939a7c7SAke Koomsin                  * current Security state. Note that we need to revisit this
719c939a7c7SAke Koomsin                  * part again once we need to support NMI.
720310cedf3SRichard Henderson                  */
721c939a7c7SAke Koomsin                 if ((hcr_el2 & (HCR_E2H | HCR_TGE)) != (HCR_E2H | HCR_TGE)) {
72216e07f78SRichard Henderson                         unmasked = true;
723310cedf3SRichard Henderson                 }
724c939a7c7SAke Koomsin                 break;
725c939a7c7SAke Koomsin             case 3:
726c939a7c7SAke Koomsin                 /* Interrupt cannot be masked when the target EL is 3 */
727c939a7c7SAke Koomsin                 unmasked = true;
728c939a7c7SAke Koomsin                 break;
729c939a7c7SAke Koomsin             default:
730c939a7c7SAke Koomsin                 g_assert_not_reached();
731c939a7c7SAke Koomsin             }
732310cedf3SRichard Henderson         } else {
733310cedf3SRichard Henderson             /*
734310cedf3SRichard Henderson              * The old 32-bit-only environment has a more complicated
735310cedf3SRichard Henderson              * masking setup. HCR and SCR bits not only affect interrupt
736310cedf3SRichard Henderson              * routing but also change the behaviour of masking.
737310cedf3SRichard Henderson              */
738310cedf3SRichard Henderson             bool hcr, scr;
739310cedf3SRichard Henderson 
740310cedf3SRichard Henderson             switch (excp_idx) {
741310cedf3SRichard Henderson             case EXCP_FIQ:
742310cedf3SRichard Henderson                 /*
743310cedf3SRichard Henderson                  * If FIQs are routed to EL3 or EL2 then there are cases where
744310cedf3SRichard Henderson                  * we override the CPSR.F in determining if the exception is
745310cedf3SRichard Henderson                  * masked or not. If neither of these are set then we fall back
746310cedf3SRichard Henderson                  * to the CPSR.F setting otherwise we further assess the state
747310cedf3SRichard Henderson                  * below.
748310cedf3SRichard Henderson                  */
749310cedf3SRichard Henderson                 hcr = hcr_el2 & HCR_FMO;
750310cedf3SRichard Henderson                 scr = (env->cp15.scr_el3 & SCR_FIQ);
751310cedf3SRichard Henderson 
752310cedf3SRichard Henderson                 /*
753310cedf3SRichard Henderson                  * When EL3 is 32-bit, the SCR.FW bit controls whether the
754310cedf3SRichard Henderson                  * CPSR.F bit masks FIQ interrupts when taken in non-secure
755310cedf3SRichard Henderson                  * state. If SCR.FW is set then FIQs can be masked by CPSR.F
756310cedf3SRichard Henderson                  * when non-secure but only when FIQs are only routed to EL3.
757310cedf3SRichard Henderson                  */
758310cedf3SRichard Henderson                 scr = scr && !((env->cp15.scr_el3 & SCR_FW) && !hcr);
759310cedf3SRichard Henderson                 break;
760310cedf3SRichard Henderson             case EXCP_IRQ:
761310cedf3SRichard Henderson                 /*
762310cedf3SRichard Henderson                  * When EL3 execution state is 32-bit, if HCR.IMO is set then
763310cedf3SRichard Henderson                  * we may override the CPSR.I masking when in non-secure state.
764310cedf3SRichard Henderson                  * The SCR.IRQ setting has already been taken into consideration
765310cedf3SRichard Henderson                  * when setting the target EL, so it does not have a further
766310cedf3SRichard Henderson                  * affect here.
767310cedf3SRichard Henderson                  */
768310cedf3SRichard Henderson                 hcr = hcr_el2 & HCR_IMO;
769310cedf3SRichard Henderson                 scr = false;
770310cedf3SRichard Henderson                 break;
771310cedf3SRichard Henderson             default:
772310cedf3SRichard Henderson                 g_assert_not_reached();
773310cedf3SRichard Henderson             }
774310cedf3SRichard Henderson 
775310cedf3SRichard Henderson             if ((scr || hcr) && !secure) {
77616e07f78SRichard Henderson                 unmasked = true;
777310cedf3SRichard Henderson             }
778310cedf3SRichard Henderson         }
779310cedf3SRichard Henderson     }
780310cedf3SRichard Henderson 
781310cedf3SRichard Henderson     /*
782673d8215SMichael Tokarev      * The PSTATE bits only mask the interrupt if we have not overridden the
783310cedf3SRichard Henderson      * ability above.
784310cedf3SRichard Henderson      */
785310cedf3SRichard Henderson     return unmasked || pstate_unmasked;
786310cedf3SRichard Henderson }
787310cedf3SRichard Henderson 
788083afd18SPhilippe Mathieu-Daudé static bool arm_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
789fcf5ef2aSThomas Huth {
790fcf5ef2aSThomas Huth     CPUClass *cc = CPU_GET_CLASS(cs);
791b77af26eSRichard Henderson     CPUARMState *env = cpu_env(cs);
792fcf5ef2aSThomas Huth     uint32_t cur_el = arm_current_el(env);
793fcf5ef2aSThomas Huth     bool secure = arm_is_secure(env);
794be879556SRichard Henderson     uint64_t hcr_el2 = arm_hcr_el2_eff(env);
795fcf5ef2aSThomas Huth     uint32_t target_el;
796fcf5ef2aSThomas Huth     uint32_t excp_idx;
797d63d0ec5SRichard Henderson 
798d63d0ec5SRichard Henderson     /* The prioritization of interrupts is IMPLEMENTATION DEFINED. */
799fcf5ef2aSThomas Huth 
800fcf5ef2aSThomas Huth     if (interrupt_request & CPU_INTERRUPT_FIQ) {
801fcf5ef2aSThomas Huth         excp_idx = EXCP_FIQ;
802fcf5ef2aSThomas Huth         target_el = arm_phys_excp_target_el(cs, excp_idx, cur_el, secure);
803be879556SRichard Henderson         if (arm_excp_unmasked(cs, excp_idx, target_el,
804be879556SRichard Henderson                               cur_el, secure, hcr_el2)) {
805d63d0ec5SRichard Henderson             goto found;
806fcf5ef2aSThomas Huth         }
807fcf5ef2aSThomas Huth     }
808fcf5ef2aSThomas Huth     if (interrupt_request & CPU_INTERRUPT_HARD) {
809fcf5ef2aSThomas Huth         excp_idx = EXCP_IRQ;
810fcf5ef2aSThomas Huth         target_el = arm_phys_excp_target_el(cs, excp_idx, cur_el, secure);
811be879556SRichard Henderson         if (arm_excp_unmasked(cs, excp_idx, target_el,
812be879556SRichard Henderson                               cur_el, secure, hcr_el2)) {
813d63d0ec5SRichard Henderson             goto found;
814fcf5ef2aSThomas Huth         }
815fcf5ef2aSThomas Huth     }
816fcf5ef2aSThomas Huth     if (interrupt_request & CPU_INTERRUPT_VIRQ) {
817fcf5ef2aSThomas Huth         excp_idx = EXCP_VIRQ;
818fcf5ef2aSThomas Huth         target_el = 1;
819be879556SRichard Henderson         if (arm_excp_unmasked(cs, excp_idx, target_el,
820be879556SRichard Henderson                               cur_el, secure, hcr_el2)) {
821d63d0ec5SRichard Henderson             goto found;
822fcf5ef2aSThomas Huth         }
823fcf5ef2aSThomas Huth     }
824fcf5ef2aSThomas Huth     if (interrupt_request & CPU_INTERRUPT_VFIQ) {
825fcf5ef2aSThomas Huth         excp_idx = EXCP_VFIQ;
826fcf5ef2aSThomas Huth         target_el = 1;
827be879556SRichard Henderson         if (arm_excp_unmasked(cs, excp_idx, target_el,
828be879556SRichard Henderson                               cur_el, secure, hcr_el2)) {
829d63d0ec5SRichard Henderson             goto found;
830d63d0ec5SRichard Henderson         }
831d63d0ec5SRichard Henderson     }
8323c29632fSRichard Henderson     if (interrupt_request & CPU_INTERRUPT_VSERR) {
8333c29632fSRichard Henderson         excp_idx = EXCP_VSERR;
8343c29632fSRichard Henderson         target_el = 1;
8353c29632fSRichard Henderson         if (arm_excp_unmasked(cs, excp_idx, target_el,
8363c29632fSRichard Henderson                               cur_el, secure, hcr_el2)) {
8373c29632fSRichard Henderson             /* Taking a virtual abort clears HCR_EL2.VSE */
8383c29632fSRichard Henderson             env->cp15.hcr_el2 &= ~HCR_VSE;
8393c29632fSRichard Henderson             cpu_reset_interrupt(cs, CPU_INTERRUPT_VSERR);
8403c29632fSRichard Henderson             goto found;
8413c29632fSRichard Henderson         }
8423c29632fSRichard Henderson     }
843d63d0ec5SRichard Henderson     return false;
844d63d0ec5SRichard Henderson 
845d63d0ec5SRichard Henderson  found:
846fcf5ef2aSThomas Huth     cs->exception_index = excp_idx;
847fcf5ef2aSThomas Huth     env->exception.target_el = target_el;
84878271684SClaudio Fontana     cc->tcg_ops->do_interrupt(cs);
849d63d0ec5SRichard Henderson     return true;
850fcf5ef2aSThomas Huth }
8519e406eeaSPhilippe Mathieu-Daudé 
8529e406eeaSPhilippe Mathieu-Daudé #endif /* CONFIG_TCG && !CONFIG_USER_ONLY */
853fcf5ef2aSThomas Huth 
85489430fc6SPeter Maydell void arm_cpu_update_virq(ARMCPU *cpu)
85589430fc6SPeter Maydell {
85689430fc6SPeter Maydell     /*
85789430fc6SPeter Maydell      * Update the interrupt level for VIRQ, which is the logical OR of
85889430fc6SPeter Maydell      * the HCR_EL2.VI bit and the input line level from the GIC.
85989430fc6SPeter Maydell      */
86089430fc6SPeter Maydell     CPUARMState *env = &cpu->env;
86189430fc6SPeter Maydell     CPUState *cs = CPU(cpu);
86289430fc6SPeter Maydell 
86389430fc6SPeter Maydell     bool new_state = (env->cp15.hcr_el2 & HCR_VI) ||
86489430fc6SPeter Maydell         (env->irq_line_state & CPU_INTERRUPT_VIRQ);
86589430fc6SPeter Maydell 
86689430fc6SPeter Maydell     if (new_state != ((cs->interrupt_request & CPU_INTERRUPT_VIRQ) != 0)) {
86789430fc6SPeter Maydell         if (new_state) {
86889430fc6SPeter Maydell             cpu_interrupt(cs, CPU_INTERRUPT_VIRQ);
86989430fc6SPeter Maydell         } else {
87089430fc6SPeter Maydell             cpu_reset_interrupt(cs, CPU_INTERRUPT_VIRQ);
87189430fc6SPeter Maydell         }
87289430fc6SPeter Maydell     }
87389430fc6SPeter Maydell }
87489430fc6SPeter Maydell 
87589430fc6SPeter Maydell void arm_cpu_update_vfiq(ARMCPU *cpu)
87689430fc6SPeter Maydell {
87789430fc6SPeter Maydell     /*
87889430fc6SPeter Maydell      * Update the interrupt level for VFIQ, which is the logical OR of
87989430fc6SPeter Maydell      * the HCR_EL2.VF bit and the input line level from the GIC.
88089430fc6SPeter Maydell      */
88189430fc6SPeter Maydell     CPUARMState *env = &cpu->env;
88289430fc6SPeter Maydell     CPUState *cs = CPU(cpu);
88389430fc6SPeter Maydell 
88489430fc6SPeter Maydell     bool new_state = (env->cp15.hcr_el2 & HCR_VF) ||
88589430fc6SPeter Maydell         (env->irq_line_state & CPU_INTERRUPT_VFIQ);
88689430fc6SPeter Maydell 
88789430fc6SPeter Maydell     if (new_state != ((cs->interrupt_request & CPU_INTERRUPT_VFIQ) != 0)) {
88889430fc6SPeter Maydell         if (new_state) {
88989430fc6SPeter Maydell             cpu_interrupt(cs, CPU_INTERRUPT_VFIQ);
89089430fc6SPeter Maydell         } else {
89189430fc6SPeter Maydell             cpu_reset_interrupt(cs, CPU_INTERRUPT_VFIQ);
89289430fc6SPeter Maydell         }
89389430fc6SPeter Maydell     }
89489430fc6SPeter Maydell }
89589430fc6SPeter Maydell 
8963c29632fSRichard Henderson void arm_cpu_update_vserr(ARMCPU *cpu)
8973c29632fSRichard Henderson {
8983c29632fSRichard Henderson     /*
8993c29632fSRichard Henderson      * Update the interrupt level for VSERR, which is the HCR_EL2.VSE bit.
9003c29632fSRichard Henderson      */
9013c29632fSRichard Henderson     CPUARMState *env = &cpu->env;
9023c29632fSRichard Henderson     CPUState *cs = CPU(cpu);
9033c29632fSRichard Henderson 
9043c29632fSRichard Henderson     bool new_state = env->cp15.hcr_el2 & HCR_VSE;
9053c29632fSRichard Henderson 
9063c29632fSRichard Henderson     if (new_state != ((cs->interrupt_request & CPU_INTERRUPT_VSERR) != 0)) {
9073c29632fSRichard Henderson         if (new_state) {
9083c29632fSRichard Henderson             cpu_interrupt(cs, CPU_INTERRUPT_VSERR);
9093c29632fSRichard Henderson         } else {
9103c29632fSRichard Henderson             cpu_reset_interrupt(cs, CPU_INTERRUPT_VSERR);
9113c29632fSRichard Henderson         }
9123c29632fSRichard Henderson     }
9133c29632fSRichard Henderson }
9143c29632fSRichard Henderson 
915fcf5ef2aSThomas Huth #ifndef CONFIG_USER_ONLY
916fcf5ef2aSThomas Huth static void arm_cpu_set_irq(void *opaque, int irq, int level)
917fcf5ef2aSThomas Huth {
918fcf5ef2aSThomas Huth     ARMCPU *cpu = opaque;
919fcf5ef2aSThomas Huth     CPUARMState *env = &cpu->env;
920fcf5ef2aSThomas Huth     CPUState *cs = CPU(cpu);
921fcf5ef2aSThomas Huth     static const int mask[] = {
922fcf5ef2aSThomas Huth         [ARM_CPU_IRQ] = CPU_INTERRUPT_HARD,
923fcf5ef2aSThomas Huth         [ARM_CPU_FIQ] = CPU_INTERRUPT_FIQ,
924fcf5ef2aSThomas Huth         [ARM_CPU_VIRQ] = CPU_INTERRUPT_VIRQ,
925fcf5ef2aSThomas Huth         [ARM_CPU_VFIQ] = CPU_INTERRUPT_VFIQ
926fcf5ef2aSThomas Huth     };
927fcf5ef2aSThomas Huth 
9289acd2d33SPeter Maydell     if (!arm_feature(env, ARM_FEATURE_EL2) &&
9299acd2d33SPeter Maydell         (irq == ARM_CPU_VIRQ || irq == ARM_CPU_VFIQ)) {
9309acd2d33SPeter Maydell         /*
9319acd2d33SPeter Maydell          * The GIC might tell us about VIRQ and VFIQ state, but if we don't
9329acd2d33SPeter Maydell          * have EL2 support we don't care. (Unless the guest is doing something
9339acd2d33SPeter Maydell          * silly this will only be calls saying "level is still 0".)
9349acd2d33SPeter Maydell          */
9359acd2d33SPeter Maydell         return;
9369acd2d33SPeter Maydell     }
9379acd2d33SPeter Maydell 
938ed89f078SPeter Maydell     if (level) {
939ed89f078SPeter Maydell         env->irq_line_state |= mask[irq];
940ed89f078SPeter Maydell     } else {
941ed89f078SPeter Maydell         env->irq_line_state &= ~mask[irq];
942ed89f078SPeter Maydell     }
943ed89f078SPeter Maydell 
944fcf5ef2aSThomas Huth     switch (irq) {
945fcf5ef2aSThomas Huth     case ARM_CPU_VIRQ:
94689430fc6SPeter Maydell         arm_cpu_update_virq(cpu);
94789430fc6SPeter Maydell         break;
948fcf5ef2aSThomas Huth     case ARM_CPU_VFIQ:
94989430fc6SPeter Maydell         arm_cpu_update_vfiq(cpu);
95089430fc6SPeter Maydell         break;
951fcf5ef2aSThomas Huth     case ARM_CPU_IRQ:
952fcf5ef2aSThomas Huth     case ARM_CPU_FIQ:
953fcf5ef2aSThomas Huth         if (level) {
954fcf5ef2aSThomas Huth             cpu_interrupt(cs, mask[irq]);
955fcf5ef2aSThomas Huth         } else {
956fcf5ef2aSThomas Huth             cpu_reset_interrupt(cs, mask[irq]);
957fcf5ef2aSThomas Huth         }
958fcf5ef2aSThomas Huth         break;
959fcf5ef2aSThomas Huth     default:
960fcf5ef2aSThomas Huth         g_assert_not_reached();
961fcf5ef2aSThomas Huth     }
962fcf5ef2aSThomas Huth }
963fcf5ef2aSThomas Huth 
964fcf5ef2aSThomas Huth static void arm_cpu_kvm_set_irq(void *opaque, int irq, int level)
965fcf5ef2aSThomas Huth {
966fcf5ef2aSThomas Huth #ifdef CONFIG_KVM
967fcf5ef2aSThomas Huth     ARMCPU *cpu = opaque;
968ed89f078SPeter Maydell     CPUARMState *env = &cpu->env;
969fcf5ef2aSThomas Huth     CPUState *cs = CPU(cpu);
970ed89f078SPeter Maydell     uint32_t linestate_bit;
971f6530926SEric Auger     int irq_id;
972fcf5ef2aSThomas Huth 
973fcf5ef2aSThomas Huth     switch (irq) {
974fcf5ef2aSThomas Huth     case ARM_CPU_IRQ:
975f6530926SEric Auger         irq_id = KVM_ARM_IRQ_CPU_IRQ;
976ed89f078SPeter Maydell         linestate_bit = CPU_INTERRUPT_HARD;
977fcf5ef2aSThomas Huth         break;
978fcf5ef2aSThomas Huth     case ARM_CPU_FIQ:
979f6530926SEric Auger         irq_id = KVM_ARM_IRQ_CPU_FIQ;
980ed89f078SPeter Maydell         linestate_bit = CPU_INTERRUPT_FIQ;
981fcf5ef2aSThomas Huth         break;
982fcf5ef2aSThomas Huth     default:
983fcf5ef2aSThomas Huth         g_assert_not_reached();
984fcf5ef2aSThomas Huth     }
985ed89f078SPeter Maydell 
986ed89f078SPeter Maydell     if (level) {
987ed89f078SPeter Maydell         env->irq_line_state |= linestate_bit;
988ed89f078SPeter Maydell     } else {
989ed89f078SPeter Maydell         env->irq_line_state &= ~linestate_bit;
990ed89f078SPeter Maydell     }
991f6530926SEric Auger     kvm_arm_set_irq(cs->cpu_index, KVM_ARM_IRQ_TYPE_CPU, irq_id, !!level);
992fcf5ef2aSThomas Huth #endif
993fcf5ef2aSThomas Huth }
994fcf5ef2aSThomas Huth 
995fcf5ef2aSThomas Huth static bool arm_cpu_virtio_is_big_endian(CPUState *cs)
996fcf5ef2aSThomas Huth {
997fcf5ef2aSThomas Huth     ARMCPU *cpu = ARM_CPU(cs);
998fcf5ef2aSThomas Huth     CPUARMState *env = &cpu->env;
999fcf5ef2aSThomas Huth 
1000fcf5ef2aSThomas Huth     cpu_synchronize_state(cs);
1001fcf5ef2aSThomas Huth     return arm_cpu_data_is_big_endian(env);
1002fcf5ef2aSThomas Huth }
1003fcf5ef2aSThomas Huth 
1004fcf5ef2aSThomas Huth #endif
1005fcf5ef2aSThomas Huth 
1006fcf5ef2aSThomas Huth static void arm_disas_set_info(CPUState *cpu, disassemble_info *info)
1007fcf5ef2aSThomas Huth {
1008fcf5ef2aSThomas Huth     ARMCPU *ac = ARM_CPU(cpu);
1009fcf5ef2aSThomas Huth     CPUARMState *env = &ac->env;
10107bcdbf51SRichard Henderson     bool sctlr_b;
1011fcf5ef2aSThomas Huth 
1012fcf5ef2aSThomas Huth     if (is_a64(env)) {
1013110f6c70SRichard Henderson         info->cap_arch = CS_ARCH_ARM64;
101415fa1a0aSRichard Henderson         info->cap_insn_unit = 4;
101515fa1a0aSRichard Henderson         info->cap_insn_split = 4;
1016110f6c70SRichard Henderson     } else {
1017110f6c70SRichard Henderson         int cap_mode;
1018110f6c70SRichard Henderson         if (env->thumb) {
101915fa1a0aSRichard Henderson             info->cap_insn_unit = 2;
102015fa1a0aSRichard Henderson             info->cap_insn_split = 4;
1021110f6c70SRichard Henderson             cap_mode = CS_MODE_THUMB;
1022fcf5ef2aSThomas Huth         } else {
102315fa1a0aSRichard Henderson             info->cap_insn_unit = 4;
102415fa1a0aSRichard Henderson             info->cap_insn_split = 4;
1025110f6c70SRichard Henderson             cap_mode = CS_MODE_ARM;
1026fcf5ef2aSThomas Huth         }
1027110f6c70SRichard Henderson         if (arm_feature(env, ARM_FEATURE_V8)) {
1028110f6c70SRichard Henderson             cap_mode |= CS_MODE_V8;
1029110f6c70SRichard Henderson         }
1030110f6c70SRichard Henderson         if (arm_feature(env, ARM_FEATURE_M)) {
1031110f6c70SRichard Henderson             cap_mode |= CS_MODE_MCLASS;
1032110f6c70SRichard Henderson         }
1033110f6c70SRichard Henderson         info->cap_arch = CS_ARCH_ARM;
1034110f6c70SRichard Henderson         info->cap_mode = cap_mode;
1035fcf5ef2aSThomas Huth     }
10367bcdbf51SRichard Henderson 
10377bcdbf51SRichard Henderson     sctlr_b = arm_sctlr_b(env);
10387bcdbf51SRichard Henderson     if (bswap_code(sctlr_b)) {
1039ee3eb3a7SMarc-André Lureau #if TARGET_BIG_ENDIAN
1040fcf5ef2aSThomas Huth         info->endian = BFD_ENDIAN_LITTLE;
1041fcf5ef2aSThomas Huth #else
1042fcf5ef2aSThomas Huth         info->endian = BFD_ENDIAN_BIG;
1043fcf5ef2aSThomas Huth #endif
1044fcf5ef2aSThomas Huth     }
1045f7478a92SJulian Brown     info->flags &= ~INSN_ARM_BE32;
10467bcdbf51SRichard Henderson #ifndef CONFIG_USER_ONLY
10477bcdbf51SRichard Henderson     if (sctlr_b) {
1048f7478a92SJulian Brown         info->flags |= INSN_ARM_BE32;
1049f7478a92SJulian Brown     }
10507bcdbf51SRichard Henderson #endif
1051fcf5ef2aSThomas Huth }
1052fcf5ef2aSThomas Huth 
105386480615SPhilippe Mathieu-Daudé #ifdef TARGET_AARCH64
105486480615SPhilippe Mathieu-Daudé 
105586480615SPhilippe Mathieu-Daudé static void aarch64_cpu_dump_state(CPUState *cs, FILE *f, int flags)
105686480615SPhilippe Mathieu-Daudé {
105786480615SPhilippe Mathieu-Daudé     ARMCPU *cpu = ARM_CPU(cs);
105886480615SPhilippe Mathieu-Daudé     CPUARMState *env = &cpu->env;
105986480615SPhilippe Mathieu-Daudé     uint32_t psr = pstate_read(env);
1060a9d84070SRichard Henderson     int i, j;
106186480615SPhilippe Mathieu-Daudé     int el = arm_current_el(env);
1062bde0e60bSPeter Maydell     uint64_t hcr = arm_hcr_el2_eff(env);
106386480615SPhilippe Mathieu-Daudé     const char *ns_status;
10647a867dd5SRichard Henderson     bool sve;
106586480615SPhilippe Mathieu-Daudé 
106686480615SPhilippe Mathieu-Daudé     qemu_fprintf(f, " PC=%016" PRIx64 " ", env->pc);
106786480615SPhilippe Mathieu-Daudé     for (i = 0; i < 32; i++) {
106886480615SPhilippe Mathieu-Daudé         if (i == 31) {
106986480615SPhilippe Mathieu-Daudé             qemu_fprintf(f, " SP=%016" PRIx64 "\n", env->xregs[i]);
107086480615SPhilippe Mathieu-Daudé         } else {
107186480615SPhilippe Mathieu-Daudé             qemu_fprintf(f, "X%02d=%016" PRIx64 "%s", i, env->xregs[i],
107286480615SPhilippe Mathieu-Daudé                          (i + 2) % 3 ? " " : "\n");
107386480615SPhilippe Mathieu-Daudé         }
107486480615SPhilippe Mathieu-Daudé     }
107586480615SPhilippe Mathieu-Daudé 
107686480615SPhilippe Mathieu-Daudé     if (arm_feature(env, ARM_FEATURE_EL3) && el != 3) {
107786480615SPhilippe Mathieu-Daudé         ns_status = env->cp15.scr_el3 & SCR_NS ? "NS " : "S ";
107886480615SPhilippe Mathieu-Daudé     } else {
107986480615SPhilippe Mathieu-Daudé         ns_status = "";
108086480615SPhilippe Mathieu-Daudé     }
108186480615SPhilippe Mathieu-Daudé     qemu_fprintf(f, "PSTATE=%08x %c%c%c%c %sEL%d%c",
108286480615SPhilippe Mathieu-Daudé                  psr,
108386480615SPhilippe Mathieu-Daudé                  psr & PSTATE_N ? 'N' : '-',
108486480615SPhilippe Mathieu-Daudé                  psr & PSTATE_Z ? 'Z' : '-',
108586480615SPhilippe Mathieu-Daudé                  psr & PSTATE_C ? 'C' : '-',
108686480615SPhilippe Mathieu-Daudé                  psr & PSTATE_V ? 'V' : '-',
108786480615SPhilippe Mathieu-Daudé                  ns_status,
108886480615SPhilippe Mathieu-Daudé                  el,
108986480615SPhilippe Mathieu-Daudé                  psr & PSTATE_SP ? 'h' : 't');
109086480615SPhilippe Mathieu-Daudé 
10917a867dd5SRichard Henderson     if (cpu_isar_feature(aa64_sme, cpu)) {
10927a867dd5SRichard Henderson         qemu_fprintf(f, "  SVCR=%08" PRIx64 " %c%c",
10937a867dd5SRichard Henderson                      env->svcr,
10947a867dd5SRichard Henderson                      (FIELD_EX64(env->svcr, SVCR, ZA) ? 'Z' : '-'),
10957a867dd5SRichard Henderson                      (FIELD_EX64(env->svcr, SVCR, SM) ? 'S' : '-'));
10967a867dd5SRichard Henderson     }
109786480615SPhilippe Mathieu-Daudé     if (cpu_isar_feature(aa64_bti, cpu)) {
109886480615SPhilippe Mathieu-Daudé         qemu_fprintf(f, "  BTYPE=%d", (psr & PSTATE_BTYPE) >> 10);
109986480615SPhilippe Mathieu-Daudé     }
1100bde0e60bSPeter Maydell     qemu_fprintf(f, "%s%s%s",
1101bde0e60bSPeter Maydell                  (hcr & HCR_NV) ? " NV" : "",
1102bde0e60bSPeter Maydell                  (hcr & HCR_NV1) ? " NV1" : "",
1103bde0e60bSPeter Maydell                  (hcr & HCR_NV2) ? " NV2" : "");
110486480615SPhilippe Mathieu-Daudé     if (!(flags & CPU_DUMP_FPU)) {
110586480615SPhilippe Mathieu-Daudé         qemu_fprintf(f, "\n");
110686480615SPhilippe Mathieu-Daudé         return;
110786480615SPhilippe Mathieu-Daudé     }
110886480615SPhilippe Mathieu-Daudé     if (fp_exception_el(env, el) != 0) {
110986480615SPhilippe Mathieu-Daudé         qemu_fprintf(f, "    FPU disabled\n");
111086480615SPhilippe Mathieu-Daudé         return;
111186480615SPhilippe Mathieu-Daudé     }
111286480615SPhilippe Mathieu-Daudé     qemu_fprintf(f, "     FPCR=%08x FPSR=%08x\n",
111386480615SPhilippe Mathieu-Daudé                  vfp_get_fpcr(env), vfp_get_fpsr(env));
111486480615SPhilippe Mathieu-Daudé 
11157a867dd5SRichard Henderson     if (cpu_isar_feature(aa64_sme, cpu) && FIELD_EX64(env->svcr, SVCR, SM)) {
11167a867dd5SRichard Henderson         sve = sme_exception_el(env, el) == 0;
11177a867dd5SRichard Henderson     } else if (cpu_isar_feature(aa64_sve, cpu)) {
11187a867dd5SRichard Henderson         sve = sve_exception_el(env, el) == 0;
11197a867dd5SRichard Henderson     } else {
11207a867dd5SRichard Henderson         sve = false;
11217a867dd5SRichard Henderson     }
11227a867dd5SRichard Henderson 
11237a867dd5SRichard Henderson     if (sve) {
1124a9d84070SRichard Henderson         int zcr_len = sve_vqm1_for_el(env, el);
112586480615SPhilippe Mathieu-Daudé 
112686480615SPhilippe Mathieu-Daudé         for (i = 0; i <= FFR_PRED_NUM; i++) {
112786480615SPhilippe Mathieu-Daudé             bool eol;
112886480615SPhilippe Mathieu-Daudé             if (i == FFR_PRED_NUM) {
112986480615SPhilippe Mathieu-Daudé                 qemu_fprintf(f, "FFR=");
113086480615SPhilippe Mathieu-Daudé                 /* It's last, so end the line.  */
113186480615SPhilippe Mathieu-Daudé                 eol = true;
113286480615SPhilippe Mathieu-Daudé             } else {
113386480615SPhilippe Mathieu-Daudé                 qemu_fprintf(f, "P%02d=", i);
113486480615SPhilippe Mathieu-Daudé                 switch (zcr_len) {
113586480615SPhilippe Mathieu-Daudé                 case 0:
113686480615SPhilippe Mathieu-Daudé                     eol = i % 8 == 7;
113786480615SPhilippe Mathieu-Daudé                     break;
113886480615SPhilippe Mathieu-Daudé                 case 1:
113986480615SPhilippe Mathieu-Daudé                     eol = i % 6 == 5;
114086480615SPhilippe Mathieu-Daudé                     break;
114186480615SPhilippe Mathieu-Daudé                 case 2:
114286480615SPhilippe Mathieu-Daudé                 case 3:
114386480615SPhilippe Mathieu-Daudé                     eol = i % 3 == 2;
114486480615SPhilippe Mathieu-Daudé                     break;
114586480615SPhilippe Mathieu-Daudé                 default:
114686480615SPhilippe Mathieu-Daudé                     /* More than one quadword per predicate.  */
114786480615SPhilippe Mathieu-Daudé                     eol = true;
114886480615SPhilippe Mathieu-Daudé                     break;
114986480615SPhilippe Mathieu-Daudé                 }
115086480615SPhilippe Mathieu-Daudé             }
115186480615SPhilippe Mathieu-Daudé             for (j = zcr_len / 4; j >= 0; j--) {
115286480615SPhilippe Mathieu-Daudé                 int digits;
115386480615SPhilippe Mathieu-Daudé                 if (j * 4 + 4 <= zcr_len + 1) {
115486480615SPhilippe Mathieu-Daudé                     digits = 16;
115586480615SPhilippe Mathieu-Daudé                 } else {
115686480615SPhilippe Mathieu-Daudé                     digits = (zcr_len % 4 + 1) * 4;
115786480615SPhilippe Mathieu-Daudé                 }
115886480615SPhilippe Mathieu-Daudé                 qemu_fprintf(f, "%0*" PRIx64 "%s", digits,
115986480615SPhilippe Mathieu-Daudé                              env->vfp.pregs[i].p[j],
116086480615SPhilippe Mathieu-Daudé                              j ? ":" : eol ? "\n" : " ");
116186480615SPhilippe Mathieu-Daudé             }
116286480615SPhilippe Mathieu-Daudé         }
116386480615SPhilippe Mathieu-Daudé 
116486480615SPhilippe Mathieu-Daudé         if (zcr_len == 0) {
1165a9d84070SRichard Henderson             /*
1166a9d84070SRichard Henderson              * With vl=16, there are only 37 columns per register,
1167a9d84070SRichard Henderson              * so output two registers per line.
1168a9d84070SRichard Henderson              */
1169a9d84070SRichard Henderson             for (i = 0; i < 32; i++) {
117086480615SPhilippe Mathieu-Daudé                 qemu_fprintf(f, "Z%02d=%016" PRIx64 ":%016" PRIx64 "%s",
117186480615SPhilippe Mathieu-Daudé                              i, env->vfp.zregs[i].d[1],
117286480615SPhilippe Mathieu-Daudé                              env->vfp.zregs[i].d[0], i & 1 ? "\n" : " ");
1173a9d84070SRichard Henderson             }
117486480615SPhilippe Mathieu-Daudé         } else {
1175a9d84070SRichard Henderson             for (i = 0; i < 32; i++) {
1176a9d84070SRichard Henderson                 qemu_fprintf(f, "Z%02d=", i);
117786480615SPhilippe Mathieu-Daudé                 for (j = zcr_len; j >= 0; j--) {
117886480615SPhilippe Mathieu-Daudé                     qemu_fprintf(f, "%016" PRIx64 ":%016" PRIx64 "%s",
117986480615SPhilippe Mathieu-Daudé                                  env->vfp.zregs[i].d[j * 2 + 1],
1180a9d84070SRichard Henderson                                  env->vfp.zregs[i].d[j * 2 + 0],
1181a9d84070SRichard Henderson                                  j ? ":" : "\n");
118286480615SPhilippe Mathieu-Daudé                 }
118386480615SPhilippe Mathieu-Daudé             }
118486480615SPhilippe Mathieu-Daudé         }
118586480615SPhilippe Mathieu-Daudé     } else {
118686480615SPhilippe Mathieu-Daudé         for (i = 0; i < 32; i++) {
118786480615SPhilippe Mathieu-Daudé             uint64_t *q = aa64_vfp_qreg(env, i);
118886480615SPhilippe Mathieu-Daudé             qemu_fprintf(f, "Q%02d=%016" PRIx64 ":%016" PRIx64 "%s",
118986480615SPhilippe Mathieu-Daudé                          i, q[1], q[0], (i & 1 ? "\n" : " "));
119086480615SPhilippe Mathieu-Daudé         }
119186480615SPhilippe Mathieu-Daudé     }
1192270bea47SRichard Henderson 
1193270bea47SRichard Henderson     if (cpu_isar_feature(aa64_sme, cpu) &&
1194270bea47SRichard Henderson         FIELD_EX64(env->svcr, SVCR, ZA) &&
1195270bea47SRichard Henderson         sme_exception_el(env, el) == 0) {
1196270bea47SRichard Henderson         int zcr_len = sve_vqm1_for_el_sm(env, el, true);
1197270bea47SRichard Henderson         int svl = (zcr_len + 1) * 16;
1198270bea47SRichard Henderson         int svl_lg10 = svl < 100 ? 2 : 3;
1199270bea47SRichard Henderson 
1200270bea47SRichard Henderson         for (i = 0; i < svl; i++) {
1201270bea47SRichard Henderson             qemu_fprintf(f, "ZA[%0*d]=", svl_lg10, i);
1202270bea47SRichard Henderson             for (j = zcr_len; j >= 0; --j) {
1203270bea47SRichard Henderson                 qemu_fprintf(f, "%016" PRIx64 ":%016" PRIx64 "%c",
1204270bea47SRichard Henderson                              env->zarray[i].d[2 * j + 1],
1205270bea47SRichard Henderson                              env->zarray[i].d[2 * j],
1206270bea47SRichard Henderson                              j ? ':' : '\n');
1207270bea47SRichard Henderson             }
1208270bea47SRichard Henderson         }
1209270bea47SRichard Henderson     }
121086480615SPhilippe Mathieu-Daudé }
121186480615SPhilippe Mathieu-Daudé 
121286480615SPhilippe Mathieu-Daudé #else
121386480615SPhilippe Mathieu-Daudé 
121486480615SPhilippe Mathieu-Daudé static inline void aarch64_cpu_dump_state(CPUState *cs, FILE *f, int flags)
121586480615SPhilippe Mathieu-Daudé {
121686480615SPhilippe Mathieu-Daudé     g_assert_not_reached();
121786480615SPhilippe Mathieu-Daudé }
121886480615SPhilippe Mathieu-Daudé 
121986480615SPhilippe Mathieu-Daudé #endif
122086480615SPhilippe Mathieu-Daudé 
122186480615SPhilippe Mathieu-Daudé static void arm_cpu_dump_state(CPUState *cs, FILE *f, int flags)
122286480615SPhilippe Mathieu-Daudé {
122386480615SPhilippe Mathieu-Daudé     ARMCPU *cpu = ARM_CPU(cs);
122486480615SPhilippe Mathieu-Daudé     CPUARMState *env = &cpu->env;
122586480615SPhilippe Mathieu-Daudé     int i;
122686480615SPhilippe Mathieu-Daudé 
122786480615SPhilippe Mathieu-Daudé     if (is_a64(env)) {
122886480615SPhilippe Mathieu-Daudé         aarch64_cpu_dump_state(cs, f, flags);
122986480615SPhilippe Mathieu-Daudé         return;
123086480615SPhilippe Mathieu-Daudé     }
123186480615SPhilippe Mathieu-Daudé 
123286480615SPhilippe Mathieu-Daudé     for (i = 0; i < 16; i++) {
123386480615SPhilippe Mathieu-Daudé         qemu_fprintf(f, "R%02d=%08x", i, env->regs[i]);
123486480615SPhilippe Mathieu-Daudé         if ((i % 4) == 3) {
123586480615SPhilippe Mathieu-Daudé             qemu_fprintf(f, "\n");
123686480615SPhilippe Mathieu-Daudé         } else {
123786480615SPhilippe Mathieu-Daudé             qemu_fprintf(f, " ");
123886480615SPhilippe Mathieu-Daudé         }
123986480615SPhilippe Mathieu-Daudé     }
124086480615SPhilippe Mathieu-Daudé 
124186480615SPhilippe Mathieu-Daudé     if (arm_feature(env, ARM_FEATURE_M)) {
124286480615SPhilippe Mathieu-Daudé         uint32_t xpsr = xpsr_read(env);
124386480615SPhilippe Mathieu-Daudé         const char *mode;
124486480615SPhilippe Mathieu-Daudé         const char *ns_status = "";
124586480615SPhilippe Mathieu-Daudé 
124686480615SPhilippe Mathieu-Daudé         if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
124786480615SPhilippe Mathieu-Daudé             ns_status = env->v7m.secure ? "S " : "NS ";
124886480615SPhilippe Mathieu-Daudé         }
124986480615SPhilippe Mathieu-Daudé 
125086480615SPhilippe Mathieu-Daudé         if (xpsr & XPSR_EXCP) {
125186480615SPhilippe Mathieu-Daudé             mode = "handler";
125286480615SPhilippe Mathieu-Daudé         } else {
125386480615SPhilippe Mathieu-Daudé             if (env->v7m.control[env->v7m.secure] & R_V7M_CONTROL_NPRIV_MASK) {
125486480615SPhilippe Mathieu-Daudé                 mode = "unpriv-thread";
125586480615SPhilippe Mathieu-Daudé             } else {
125686480615SPhilippe Mathieu-Daudé                 mode = "priv-thread";
125786480615SPhilippe Mathieu-Daudé             }
125886480615SPhilippe Mathieu-Daudé         }
125986480615SPhilippe Mathieu-Daudé 
126086480615SPhilippe Mathieu-Daudé         qemu_fprintf(f, "XPSR=%08x %c%c%c%c %c %s%s\n",
126186480615SPhilippe Mathieu-Daudé                      xpsr,
126286480615SPhilippe Mathieu-Daudé                      xpsr & XPSR_N ? 'N' : '-',
126386480615SPhilippe Mathieu-Daudé                      xpsr & XPSR_Z ? 'Z' : '-',
126486480615SPhilippe Mathieu-Daudé                      xpsr & XPSR_C ? 'C' : '-',
126586480615SPhilippe Mathieu-Daudé                      xpsr & XPSR_V ? 'V' : '-',
126686480615SPhilippe Mathieu-Daudé                      xpsr & XPSR_T ? 'T' : 'A',
126786480615SPhilippe Mathieu-Daudé                      ns_status,
126886480615SPhilippe Mathieu-Daudé                      mode);
126986480615SPhilippe Mathieu-Daudé     } else {
127086480615SPhilippe Mathieu-Daudé         uint32_t psr = cpsr_read(env);
127186480615SPhilippe Mathieu-Daudé         const char *ns_status = "";
127286480615SPhilippe Mathieu-Daudé 
127386480615SPhilippe Mathieu-Daudé         if (arm_feature(env, ARM_FEATURE_EL3) &&
127486480615SPhilippe Mathieu-Daudé             (psr & CPSR_M) != ARM_CPU_MODE_MON) {
127586480615SPhilippe Mathieu-Daudé             ns_status = env->cp15.scr_el3 & SCR_NS ? "NS " : "S ";
127686480615SPhilippe Mathieu-Daudé         }
127786480615SPhilippe Mathieu-Daudé 
127886480615SPhilippe Mathieu-Daudé         qemu_fprintf(f, "PSR=%08x %c%c%c%c %c %s%s%d\n",
127986480615SPhilippe Mathieu-Daudé                      psr,
128086480615SPhilippe Mathieu-Daudé                      psr & CPSR_N ? 'N' : '-',
128186480615SPhilippe Mathieu-Daudé                      psr & CPSR_Z ? 'Z' : '-',
128286480615SPhilippe Mathieu-Daudé                      psr & CPSR_C ? 'C' : '-',
128386480615SPhilippe Mathieu-Daudé                      psr & CPSR_V ? 'V' : '-',
128486480615SPhilippe Mathieu-Daudé                      psr & CPSR_T ? 'T' : 'A',
128586480615SPhilippe Mathieu-Daudé                      ns_status,
128686480615SPhilippe Mathieu-Daudé                      aarch32_mode_name(psr), (psr & 0x10) ? 32 : 26);
128786480615SPhilippe Mathieu-Daudé     }
128886480615SPhilippe Mathieu-Daudé 
128986480615SPhilippe Mathieu-Daudé     if (flags & CPU_DUMP_FPU) {
129086480615SPhilippe Mathieu-Daudé         int numvfpregs = 0;
1291a6627f5fSRichard Henderson         if (cpu_isar_feature(aa32_simd_r32, cpu)) {
1292a6627f5fSRichard Henderson             numvfpregs = 32;
12937fbc6a40SRichard Henderson         } else if (cpu_isar_feature(aa32_vfp_simd, cpu)) {
1294a6627f5fSRichard Henderson             numvfpregs = 16;
129586480615SPhilippe Mathieu-Daudé         }
129686480615SPhilippe Mathieu-Daudé         for (i = 0; i < numvfpregs; i++) {
129786480615SPhilippe Mathieu-Daudé             uint64_t v = *aa32_vfp_dreg(env, i);
129886480615SPhilippe Mathieu-Daudé             qemu_fprintf(f, "s%02d=%08x s%02d=%08x d%02d=%016" PRIx64 "\n",
129986480615SPhilippe Mathieu-Daudé                          i * 2, (uint32_t)v,
130086480615SPhilippe Mathieu-Daudé                          i * 2 + 1, (uint32_t)(v >> 32),
130186480615SPhilippe Mathieu-Daudé                          i, v);
130286480615SPhilippe Mathieu-Daudé         }
130386480615SPhilippe Mathieu-Daudé         qemu_fprintf(f, "FPSCR: %08x\n", vfp_get_fpscr(env));
1304aa291908SPeter Maydell         if (cpu_isar_feature(aa32_mve, cpu)) {
1305aa291908SPeter Maydell             qemu_fprintf(f, "VPR: %08x\n", env->v7m.vpr);
1306aa291908SPeter Maydell         }
130786480615SPhilippe Mathieu-Daudé     }
130886480615SPhilippe Mathieu-Daudé }
130986480615SPhilippe Mathieu-Daudé 
1310*750245edSRichard Henderson uint64_t arm_build_mp_affinity(int idx, uint8_t clustersz)
131146de5913SIgor Mammedov {
131246de5913SIgor Mammedov     uint32_t Aff1 = idx / clustersz;
131346de5913SIgor Mammedov     uint32_t Aff0 = idx % clustersz;
131446de5913SIgor Mammedov     return (Aff1 << ARM_AFF1_SHIFT) | Aff0;
131546de5913SIgor Mammedov }
131646de5913SIgor Mammedov 
1317fcf5ef2aSThomas Huth static void arm_cpu_initfn(Object *obj)
1318fcf5ef2aSThomas Huth {
1319fcf5ef2aSThomas Huth     ARMCPU *cpu = ARM_CPU(obj);
1320fcf5ef2aSThomas Huth 
13215860362dSRichard Henderson     cpu->cp_regs = g_hash_table_new_full(g_direct_hash, g_direct_equal,
1322c27f5d3aSRichard Henderson                                          NULL, g_free);
1323fcf5ef2aSThomas Huth 
1324b5c53d1bSAaron Lindsay     QLIST_INIT(&cpu->pre_el_change_hooks);
132508267487SAaron Lindsay     QLIST_INIT(&cpu->el_change_hooks);
132608267487SAaron Lindsay 
1327b3d52804SRichard Henderson #ifdef CONFIG_USER_ONLY
1328b3d52804SRichard Henderson # ifdef TARGET_AARCH64
1329b3d52804SRichard Henderson     /*
1330e74c0976SRichard Henderson      * The linux kernel defaults to 512-bit for SVE, and 256-bit for SME.
1331e74c0976SRichard Henderson      * These values were chosen to fit within the default signal frame.
1332e74c0976SRichard Henderson      * See documentation for /proc/sys/abi/{sve,sme}_default_vector_length,
1333e74c0976SRichard Henderson      * and our corresponding cpu property.
1334b3d52804SRichard Henderson      */
1335b3d52804SRichard Henderson     cpu->sve_default_vq = 4;
1336e74c0976SRichard Henderson     cpu->sme_default_vq = 2;
1337b3d52804SRichard Henderson # endif
1338b3d52804SRichard Henderson #else
1339fcf5ef2aSThomas Huth     /* Our inbound IRQ and FIQ lines */
1340fcf5ef2aSThomas Huth     if (kvm_enabled()) {
1341fcf5ef2aSThomas Huth         /* VIRQ and VFIQ are unused with KVM but we add them to maintain
1342fcf5ef2aSThomas Huth          * the same interface as non-KVM CPUs.
1343fcf5ef2aSThomas Huth          */
1344fcf5ef2aSThomas Huth         qdev_init_gpio_in(DEVICE(cpu), arm_cpu_kvm_set_irq, 4);
1345fcf5ef2aSThomas Huth     } else {
1346fcf5ef2aSThomas Huth         qdev_init_gpio_in(DEVICE(cpu), arm_cpu_set_irq, 4);
1347fcf5ef2aSThomas Huth     }
1348fcf5ef2aSThomas Huth 
1349fcf5ef2aSThomas Huth     qdev_init_gpio_out(DEVICE(cpu), cpu->gt_timer_outputs,
1350fcf5ef2aSThomas Huth                        ARRAY_SIZE(cpu->gt_timer_outputs));
1351aa1b3111SPeter Maydell 
1352aa1b3111SPeter Maydell     qdev_init_gpio_out_named(DEVICE(cpu), &cpu->gicv3_maintenance_interrupt,
1353aa1b3111SPeter Maydell                              "gicv3-maintenance-interrupt", 1);
135407f48730SAndrew Jones     qdev_init_gpio_out_named(DEVICE(cpu), &cpu->pmu_interrupt,
135507f48730SAndrew Jones                              "pmu-interrupt", 1);
1356fcf5ef2aSThomas Huth #endif
1357fcf5ef2aSThomas Huth 
1358fcf5ef2aSThomas Huth     /* DTB consumers generally don't in fact care what the 'compatible'
1359fcf5ef2aSThomas Huth      * string is, so always provide some string and trust that a hypothetical
1360fcf5ef2aSThomas Huth      * picky DTB consumer will also provide a helpful error message.
1361fcf5ef2aSThomas Huth      */
1362fcf5ef2aSThomas Huth     cpu->dtb_compatible = "qemu,unknown";
13630dc71c70SAkihiko Odaki     cpu->psci_version = QEMU_PSCI_VERSION_0_1; /* By default assume PSCI v0.1 */
1364fcf5ef2aSThomas Huth     cpu->kvm_target = QEMU_KVM_ARM_TARGET_NONE;
1365fcf5ef2aSThomas Huth 
13662c9c0bf9SAlexander Graf     if (tcg_enabled() || hvf_enabled()) {
13670dc71c70SAkihiko Odaki         /* TCG and HVF implement PSCI 1.1 */
13680dc71c70SAkihiko Odaki         cpu->psci_version = QEMU_PSCI_VERSION_1_1;
1369fcf5ef2aSThomas Huth     }
1370fcf5ef2aSThomas Huth }
1371fcf5ef2aSThomas Huth 
137296eec6b2SAndrew Jeffery static Property arm_cpu_gt_cntfrq_property =
137396eec6b2SAndrew Jeffery             DEFINE_PROP_UINT64("cntfrq", ARMCPU, gt_cntfrq_hz,
137496eec6b2SAndrew Jeffery                                NANOSECONDS_PER_SECOND / GTIMER_SCALE);
137596eec6b2SAndrew Jeffery 
1376fcf5ef2aSThomas Huth static Property arm_cpu_reset_cbar_property =
1377fcf5ef2aSThomas Huth             DEFINE_PROP_UINT64("reset-cbar", ARMCPU, reset_cbar, 0);
1378fcf5ef2aSThomas Huth 
1379fcf5ef2aSThomas Huth static Property arm_cpu_reset_hivecs_property =
1380fcf5ef2aSThomas Huth             DEFINE_PROP_BOOL("reset-hivecs", ARMCPU, reset_hivecs, false);
1381fcf5ef2aSThomas Huth 
138245ca3a14SRichard Henderson #ifndef CONFIG_USER_ONLY
1383c25bd18aSPeter Maydell static Property arm_cpu_has_el2_property =
1384c25bd18aSPeter Maydell             DEFINE_PROP_BOOL("has_el2", ARMCPU, has_el2, true);
1385c25bd18aSPeter Maydell 
1386fcf5ef2aSThomas Huth static Property arm_cpu_has_el3_property =
1387fcf5ef2aSThomas Huth             DEFINE_PROP_BOOL("has_el3", ARMCPU, has_el3, true);
138845ca3a14SRichard Henderson #endif
1389fcf5ef2aSThomas Huth 
13903a062d57SJulian Brown static Property arm_cpu_cfgend_property =
13913a062d57SJulian Brown             DEFINE_PROP_BOOL("cfgend", ARMCPU, cfgend, false);
13923a062d57SJulian Brown 
139397a28b0eSPeter Maydell static Property arm_cpu_has_vfp_property =
139497a28b0eSPeter Maydell             DEFINE_PROP_BOOL("vfp", ARMCPU, has_vfp, true);
139597a28b0eSPeter Maydell 
139642bea956SCédric Le Goater static Property arm_cpu_has_vfp_d32_property =
139742bea956SCédric Le Goater             DEFINE_PROP_BOOL("vfp-d32", ARMCPU, has_vfp_d32, true);
139842bea956SCédric Le Goater 
139997a28b0eSPeter Maydell static Property arm_cpu_has_neon_property =
140097a28b0eSPeter Maydell             DEFINE_PROP_BOOL("neon", ARMCPU, has_neon, true);
140197a28b0eSPeter Maydell 
1402ea90db0aSPeter Maydell static Property arm_cpu_has_dsp_property =
1403ea90db0aSPeter Maydell             DEFINE_PROP_BOOL("dsp", ARMCPU, has_dsp, true);
1404ea90db0aSPeter Maydell 
1405fcf5ef2aSThomas Huth static Property arm_cpu_has_mpu_property =
1406fcf5ef2aSThomas Huth             DEFINE_PROP_BOOL("has-mpu", ARMCPU, has_mpu, true);
1407fcf5ef2aSThomas Huth 
14088d92e26bSPeter Maydell /* This is like DEFINE_PROP_UINT32 but it doesn't set the default value,
14098d92e26bSPeter Maydell  * because the CPU initfn will have already set cpu->pmsav7_dregion to
14108d92e26bSPeter Maydell  * the right value for that particular CPU type, and we don't want
14118d92e26bSPeter Maydell  * to override that with an incorrect constant value.
14128d92e26bSPeter Maydell  */
1413fcf5ef2aSThomas Huth static Property arm_cpu_pmsav7_dregion_property =
14148d92e26bSPeter Maydell             DEFINE_PROP_UNSIGNED_NODEFAULT("pmsav7-dregion", ARMCPU,
14158d92e26bSPeter Maydell                                            pmsav7_dregion,
14168d92e26bSPeter Maydell                                            qdev_prop_uint32, uint32_t);
1417fcf5ef2aSThomas Huth 
1418ae502508SAndrew Jones static bool arm_get_pmu(Object *obj, Error **errp)
1419ae502508SAndrew Jones {
1420ae502508SAndrew Jones     ARMCPU *cpu = ARM_CPU(obj);
1421ae502508SAndrew Jones 
1422ae502508SAndrew Jones     return cpu->has_pmu;
1423ae502508SAndrew Jones }
1424ae502508SAndrew Jones 
1425ae502508SAndrew Jones static void arm_set_pmu(Object *obj, bool value, Error **errp)
1426ae502508SAndrew Jones {
1427ae502508SAndrew Jones     ARMCPU *cpu = ARM_CPU(obj);
1428ae502508SAndrew Jones 
1429ae502508SAndrew Jones     if (value) {
14307d20e681SPhilippe Mathieu-Daudé         if (kvm_enabled() && !kvm_arm_pmu_supported()) {
1431ae502508SAndrew Jones             error_setg(errp, "'pmu' feature not supported by KVM on this host");
1432ae502508SAndrew Jones             return;
1433ae502508SAndrew Jones         }
1434ae502508SAndrew Jones         set_feature(&cpu->env, ARM_FEATURE_PMU);
1435ae502508SAndrew Jones     } else {
1436ae502508SAndrew Jones         unset_feature(&cpu->env, ARM_FEATURE_PMU);
1437ae502508SAndrew Jones     }
1438ae502508SAndrew Jones     cpu->has_pmu = value;
1439ae502508SAndrew Jones }
1440ae502508SAndrew Jones 
14417def8754SAndrew Jeffery unsigned int gt_cntfrq_period_ns(ARMCPU *cpu)
14427def8754SAndrew Jeffery {
144396eec6b2SAndrew Jeffery     /*
144496eec6b2SAndrew Jeffery      * The exact approach to calculating guest ticks is:
144596eec6b2SAndrew Jeffery      *
144696eec6b2SAndrew Jeffery      *     muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), cpu->gt_cntfrq_hz,
144796eec6b2SAndrew Jeffery      *              NANOSECONDS_PER_SECOND);
144896eec6b2SAndrew Jeffery      *
144996eec6b2SAndrew Jeffery      * We don't do that. Rather we intentionally use integer division
145096eec6b2SAndrew Jeffery      * truncation below and in the caller for the conversion of host monotonic
145196eec6b2SAndrew Jeffery      * time to guest ticks to provide the exact inverse for the semantics of
145296eec6b2SAndrew Jeffery      * the QEMUTimer scale factor. QEMUTimer's scale facter is an integer, so
145396eec6b2SAndrew Jeffery      * it loses precision when representing frequencies where
145496eec6b2SAndrew Jeffery      * `(NANOSECONDS_PER_SECOND % cpu->gt_cntfrq) > 0` holds. Failing to
145596eec6b2SAndrew Jeffery      * provide an exact inverse leads to scheduling timers with negative
145696eec6b2SAndrew Jeffery      * periods, which in turn leads to sticky behaviour in the guest.
145796eec6b2SAndrew Jeffery      *
145896eec6b2SAndrew Jeffery      * Finally, CNTFRQ is effectively capped at 1GHz to ensure our scale factor
145996eec6b2SAndrew Jeffery      * cannot become zero.
146096eec6b2SAndrew Jeffery      */
14617def8754SAndrew Jeffery     return NANOSECONDS_PER_SECOND > cpu->gt_cntfrq_hz ?
14627def8754SAndrew Jeffery       NANOSECONDS_PER_SECOND / cpu->gt_cntfrq_hz : 1;
14637def8754SAndrew Jeffery }
14647def8754SAndrew Jeffery 
1465b8f7959fSPeter Maydell static void arm_cpu_propagate_feature_implications(ARMCPU *cpu)
1466b8f7959fSPeter Maydell {
1467b8f7959fSPeter Maydell     CPUARMState *env = &cpu->env;
1468b8f7959fSPeter Maydell     bool no_aa32 = false;
1469b8f7959fSPeter Maydell 
1470b8f7959fSPeter Maydell     /*
1471b8f7959fSPeter Maydell      * Some features automatically imply others: set the feature
1472b8f7959fSPeter Maydell      * bits explicitly for these cases.
1473b8f7959fSPeter Maydell      */
1474b8f7959fSPeter Maydell 
1475b8f7959fSPeter Maydell     if (arm_feature(env, ARM_FEATURE_M)) {
1476b8f7959fSPeter Maydell         set_feature(env, ARM_FEATURE_PMSA);
1477b8f7959fSPeter Maydell     }
1478b8f7959fSPeter Maydell 
1479b8f7959fSPeter Maydell     if (arm_feature(env, ARM_FEATURE_V8)) {
1480b8f7959fSPeter Maydell         if (arm_feature(env, ARM_FEATURE_M)) {
1481b8f7959fSPeter Maydell             set_feature(env, ARM_FEATURE_V7);
1482b8f7959fSPeter Maydell         } else {
1483b8f7959fSPeter Maydell             set_feature(env, ARM_FEATURE_V7VE);
1484b8f7959fSPeter Maydell         }
1485b8f7959fSPeter Maydell     }
1486b8f7959fSPeter Maydell 
1487b8f7959fSPeter Maydell     /*
1488b8f7959fSPeter Maydell      * There exist AArch64 cpus without AArch32 support.  When KVM
1489b8f7959fSPeter Maydell      * queries ID_ISAR0_EL1 on such a host, the value is UNKNOWN.
1490b8f7959fSPeter Maydell      * Similarly, we cannot check ID_AA64PFR0 without AArch64 support.
1491b8f7959fSPeter Maydell      * As a general principle, we also do not make ID register
1492b8f7959fSPeter Maydell      * consistency checks anywhere unless using TCG, because only
1493b8f7959fSPeter Maydell      * for TCG would a consistency-check failure be a QEMU bug.
1494b8f7959fSPeter Maydell      */
1495b8f7959fSPeter Maydell     if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
1496b8f7959fSPeter Maydell         no_aa32 = !cpu_isar_feature(aa64_aa32, cpu);
1497b8f7959fSPeter Maydell     }
1498b8f7959fSPeter Maydell 
1499b8f7959fSPeter Maydell     if (arm_feature(env, ARM_FEATURE_V7VE)) {
1500b8f7959fSPeter Maydell         /*
1501b8f7959fSPeter Maydell          * v7 Virtualization Extensions. In real hardware this implies
1502b8f7959fSPeter Maydell          * EL2 and also the presence of the Security Extensions.
1503b8f7959fSPeter Maydell          * For QEMU, for backwards-compatibility we implement some
1504b8f7959fSPeter Maydell          * CPUs or CPU configs which have no actual EL2 or EL3 but do
1505b8f7959fSPeter Maydell          * include the various other features that V7VE implies.
1506b8f7959fSPeter Maydell          * Presence of EL2 itself is ARM_FEATURE_EL2, and of the
1507b8f7959fSPeter Maydell          * Security Extensions is ARM_FEATURE_EL3.
1508b8f7959fSPeter Maydell          */
1509b8f7959fSPeter Maydell         assert(!tcg_enabled() || no_aa32 ||
1510b8f7959fSPeter Maydell                cpu_isar_feature(aa32_arm_div, cpu));
1511b8f7959fSPeter Maydell         set_feature(env, ARM_FEATURE_LPAE);
1512b8f7959fSPeter Maydell         set_feature(env, ARM_FEATURE_V7);
1513b8f7959fSPeter Maydell     }
1514b8f7959fSPeter Maydell     if (arm_feature(env, ARM_FEATURE_V7)) {
1515b8f7959fSPeter Maydell         set_feature(env, ARM_FEATURE_VAPA);
1516b8f7959fSPeter Maydell         set_feature(env, ARM_FEATURE_THUMB2);
1517b8f7959fSPeter Maydell         set_feature(env, ARM_FEATURE_MPIDR);
1518b8f7959fSPeter Maydell         if (!arm_feature(env, ARM_FEATURE_M)) {
1519b8f7959fSPeter Maydell             set_feature(env, ARM_FEATURE_V6K);
1520b8f7959fSPeter Maydell         } else {
1521b8f7959fSPeter Maydell             set_feature(env, ARM_FEATURE_V6);
1522b8f7959fSPeter Maydell         }
1523b8f7959fSPeter Maydell 
1524b8f7959fSPeter Maydell         /*
1525b8f7959fSPeter Maydell          * Always define VBAR for V7 CPUs even if it doesn't exist in
1526b8f7959fSPeter Maydell          * non-EL3 configs. This is needed by some legacy boards.
1527b8f7959fSPeter Maydell          */
1528b8f7959fSPeter Maydell         set_feature(env, ARM_FEATURE_VBAR);
1529b8f7959fSPeter Maydell     }
1530b8f7959fSPeter Maydell     if (arm_feature(env, ARM_FEATURE_V6K)) {
1531b8f7959fSPeter Maydell         set_feature(env, ARM_FEATURE_V6);
1532b8f7959fSPeter Maydell         set_feature(env, ARM_FEATURE_MVFR);
1533b8f7959fSPeter Maydell     }
1534b8f7959fSPeter Maydell     if (arm_feature(env, ARM_FEATURE_V6)) {
1535b8f7959fSPeter Maydell         set_feature(env, ARM_FEATURE_V5);
1536b8f7959fSPeter Maydell         if (!arm_feature(env, ARM_FEATURE_M)) {
1537b8f7959fSPeter Maydell             assert(!tcg_enabled() || no_aa32 ||
1538b8f7959fSPeter Maydell                    cpu_isar_feature(aa32_jazelle, cpu));
1539b8f7959fSPeter Maydell             set_feature(env, ARM_FEATURE_AUXCR);
1540b8f7959fSPeter Maydell         }
1541b8f7959fSPeter Maydell     }
1542b8f7959fSPeter Maydell     if (arm_feature(env, ARM_FEATURE_V5)) {
1543b8f7959fSPeter Maydell         set_feature(env, ARM_FEATURE_V4T);
1544b8f7959fSPeter Maydell     }
1545b8f7959fSPeter Maydell     if (arm_feature(env, ARM_FEATURE_LPAE)) {
1546b8f7959fSPeter Maydell         set_feature(env, ARM_FEATURE_V7MP);
1547b8f7959fSPeter Maydell     }
1548b8f7959fSPeter Maydell     if (arm_feature(env, ARM_FEATURE_CBAR_RO)) {
1549b8f7959fSPeter Maydell         set_feature(env, ARM_FEATURE_CBAR);
1550b8f7959fSPeter Maydell     }
1551b8f7959fSPeter Maydell     if (arm_feature(env, ARM_FEATURE_THUMB2) &&
1552b8f7959fSPeter Maydell         !arm_feature(env, ARM_FEATURE_M)) {
1553b8f7959fSPeter Maydell         set_feature(env, ARM_FEATURE_THUMB_DSP);
1554b8f7959fSPeter Maydell     }
1555b8f7959fSPeter Maydell }
1556b8f7959fSPeter Maydell 
155751e5ef45SMarc-André Lureau void arm_cpu_post_init(Object *obj)
1558fcf5ef2aSThomas Huth {
1559fcf5ef2aSThomas Huth     ARMCPU *cpu = ARM_CPU(obj);
1560fcf5ef2aSThomas Huth 
1561b8f7959fSPeter Maydell     /*
1562b8f7959fSPeter Maydell      * Some features imply others. Figure this out now, because we
1563b8f7959fSPeter Maydell      * are going to look at the feature bits in deciding which
1564b8f7959fSPeter Maydell      * properties to add.
1565790a1150SPeter Maydell      */
1566b8f7959fSPeter Maydell     arm_cpu_propagate_feature_implications(cpu);
1567790a1150SPeter Maydell 
1568fcf5ef2aSThomas Huth     if (arm_feature(&cpu->env, ARM_FEATURE_CBAR) ||
1569fcf5ef2aSThomas Huth         arm_feature(&cpu->env, ARM_FEATURE_CBAR_RO)) {
157094d912d1SMarc-André Lureau         qdev_property_add_static(DEVICE(obj), &arm_cpu_reset_cbar_property);
1571fcf5ef2aSThomas Huth     }
1572fcf5ef2aSThomas Huth 
1573fcf5ef2aSThomas Huth     if (!arm_feature(&cpu->env, ARM_FEATURE_M)) {
157494d912d1SMarc-André Lureau         qdev_property_add_static(DEVICE(obj), &arm_cpu_reset_hivecs_property);
1575fcf5ef2aSThomas Huth     }
1576fcf5ef2aSThomas Huth 
1577910e4f24STobias Röhmel     if (arm_feature(&cpu->env, ARM_FEATURE_V8)) {
15784a7319b7SEdgar E. Iglesias         object_property_add_uint64_ptr(obj, "rvbar",
15794a7319b7SEdgar E. Iglesias                                        &cpu->rvbar_prop,
15804a7319b7SEdgar E. Iglesias                                        OBJ_PROP_FLAG_READWRITE);
1581fcf5ef2aSThomas Huth     }
1582fcf5ef2aSThomas Huth 
158345ca3a14SRichard Henderson #ifndef CONFIG_USER_ONLY
1584fcf5ef2aSThomas Huth     if (arm_feature(&cpu->env, ARM_FEATURE_EL3)) {
1585fcf5ef2aSThomas Huth         /* Add the has_el3 state CPU property only if EL3 is allowed.  This will
1586fcf5ef2aSThomas Huth          * prevent "has_el3" from existing on CPUs which cannot support EL3.
1587fcf5ef2aSThomas Huth          */
158894d912d1SMarc-André Lureau         qdev_property_add_static(DEVICE(obj), &arm_cpu_has_el3_property);
1589fcf5ef2aSThomas Huth 
1590fcf5ef2aSThomas Huth         object_property_add_link(obj, "secure-memory",
1591fcf5ef2aSThomas Huth                                  TYPE_MEMORY_REGION,
1592fcf5ef2aSThomas Huth                                  (Object **)&cpu->secure_memory,
1593fcf5ef2aSThomas Huth                                  qdev_prop_allow_set_link_before_realize,
1594d2623129SMarkus Armbruster                                  OBJ_PROP_LINK_STRONG);
1595fcf5ef2aSThomas Huth     }
1596fcf5ef2aSThomas Huth 
1597c25bd18aSPeter Maydell     if (arm_feature(&cpu->env, ARM_FEATURE_EL2)) {
159894d912d1SMarc-André Lureau         qdev_property_add_static(DEVICE(obj), &arm_cpu_has_el2_property);
1599c25bd18aSPeter Maydell     }
160045ca3a14SRichard Henderson #endif
1601c25bd18aSPeter Maydell 
1602fcf5ef2aSThomas Huth     if (arm_feature(&cpu->env, ARM_FEATURE_PMU)) {
1603ae502508SAndrew Jones         cpu->has_pmu = true;
1604d2623129SMarkus Armbruster         object_property_add_bool(obj, "pmu", arm_get_pmu, arm_set_pmu);
1605fcf5ef2aSThomas Huth     }
1606fcf5ef2aSThomas Huth 
160797a28b0eSPeter Maydell     /*
160897a28b0eSPeter Maydell      * Allow user to turn off VFP and Neon support, but only for TCG --
160997a28b0eSPeter Maydell      * KVM does not currently allow us to lie to the guest about its
161097a28b0eSPeter Maydell      * ID/feature registers, so the guest always sees what the host has.
161197a28b0eSPeter Maydell      */
16124315f7c6SRichard Henderson     if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
16134315f7c6SRichard Henderson         if (cpu_isar_feature(aa64_fp_simd, cpu)) {
161497a28b0eSPeter Maydell             cpu->has_vfp = true;
161542bea956SCédric Le Goater             cpu->has_vfp_d32 = true;
16164315f7c6SRichard Henderson             if (tcg_enabled() || qtest_enabled()) {
16174315f7c6SRichard Henderson                 qdev_property_add_static(DEVICE(obj),
16184315f7c6SRichard Henderson                                          &arm_cpu_has_vfp_property);
16194315f7c6SRichard Henderson             }
16204315f7c6SRichard Henderson         }
16214315f7c6SRichard Henderson     } else if (cpu_isar_feature(aa32_vfp, cpu)) {
16224315f7c6SRichard Henderson         cpu->has_vfp = true;
16234315f7c6SRichard Henderson         if (cpu_isar_feature(aa32_simd_r32, cpu)) {
16244315f7c6SRichard Henderson             cpu->has_vfp_d32 = true;
162542bea956SCédric Le Goater             /*
162642bea956SCédric Le Goater              * The permitted values of the SIMDReg bits [3:0] on
162742bea956SCédric Le Goater              * Armv8-A are either 0b0000 and 0b0010. On such CPUs,
162842bea956SCédric Le Goater              * make sure that has_vfp_d32 can not be set to false.
162942bea956SCédric Le Goater              */
16304315f7c6SRichard Henderson             if ((tcg_enabled() || qtest_enabled())
16314315f7c6SRichard Henderson                 && !(arm_feature(&cpu->env, ARM_FEATURE_V8)
16324315f7c6SRichard Henderson                      && !arm_feature(&cpu->env, ARM_FEATURE_M))) {
163342bea956SCédric Le Goater                 qdev_property_add_static(DEVICE(obj),
163442bea956SCédric Le Goater                                          &arm_cpu_has_vfp_d32_property);
163542bea956SCédric Le Goater             }
163642bea956SCédric Le Goater         }
163742bea956SCédric Le Goater     }
163842bea956SCédric Le Goater 
163997a28b0eSPeter Maydell     if (arm_feature(&cpu->env, ARM_FEATURE_NEON)) {
164097a28b0eSPeter Maydell         cpu->has_neon = true;
164197a28b0eSPeter Maydell         if (!kvm_enabled()) {
164294d912d1SMarc-André Lureau             qdev_property_add_static(DEVICE(obj), &arm_cpu_has_neon_property);
164397a28b0eSPeter Maydell         }
164497a28b0eSPeter Maydell     }
164597a28b0eSPeter Maydell 
1646ea90db0aSPeter Maydell     if (arm_feature(&cpu->env, ARM_FEATURE_M) &&
1647ea90db0aSPeter Maydell         arm_feature(&cpu->env, ARM_FEATURE_THUMB_DSP)) {
164894d912d1SMarc-André Lureau         qdev_property_add_static(DEVICE(obj), &arm_cpu_has_dsp_property);
1649ea90db0aSPeter Maydell     }
1650ea90db0aSPeter Maydell 
1651452a0955SPeter Maydell     if (arm_feature(&cpu->env, ARM_FEATURE_PMSA)) {
165294d912d1SMarc-André Lureau         qdev_property_add_static(DEVICE(obj), &arm_cpu_has_mpu_property);
1653fcf5ef2aSThomas Huth         if (arm_feature(&cpu->env, ARM_FEATURE_V7)) {
1654fcf5ef2aSThomas Huth             qdev_property_add_static(DEVICE(obj),
165594d912d1SMarc-André Lureau                                      &arm_cpu_pmsav7_dregion_property);
1656fcf5ef2aSThomas Huth         }
1657fcf5ef2aSThomas Huth     }
1658fcf5ef2aSThomas Huth 
1659181962fdSPeter Maydell     if (arm_feature(&cpu->env, ARM_FEATURE_M_SECURITY)) {
1660181962fdSPeter Maydell         object_property_add_link(obj, "idau", TYPE_IDAU_INTERFACE, &cpu->idau,
1661181962fdSPeter Maydell                                  qdev_prop_allow_set_link_before_realize,
1662d2623129SMarkus Armbruster                                  OBJ_PROP_LINK_STRONG);
1663f9f62e4cSPeter Maydell         /*
1664f9f62e4cSPeter Maydell          * M profile: initial value of the Secure VTOR. We can't just use
1665f9f62e4cSPeter Maydell          * a simple DEFINE_PROP_UINT32 for this because we want to permit
1666f9f62e4cSPeter Maydell          * the property to be set after realize.
1667f9f62e4cSPeter Maydell          */
166864a7b8deSFelipe Franciosi         object_property_add_uint32_ptr(obj, "init-svtor",
166964a7b8deSFelipe Franciosi                                        &cpu->init_svtor,
1670d2623129SMarkus Armbruster                                        OBJ_PROP_FLAG_READWRITE);
1671181962fdSPeter Maydell     }
16727cda2149SPeter Maydell     if (arm_feature(&cpu->env, ARM_FEATURE_M)) {
16737cda2149SPeter Maydell         /*
16747cda2149SPeter Maydell          * Initial value of the NS VTOR (for cores without the Security
16757cda2149SPeter Maydell          * extension, this is the only VTOR)
16767cda2149SPeter Maydell          */
16777cda2149SPeter Maydell         object_property_add_uint32_ptr(obj, "init-nsvtor",
16787cda2149SPeter Maydell                                        &cpu->init_nsvtor,
16797cda2149SPeter Maydell                                        OBJ_PROP_FLAG_READWRITE);
16807cda2149SPeter Maydell     }
1681181962fdSPeter Maydell 
1682bddd892eSPeter Maydell     /* Not DEFINE_PROP_UINT32: we want this to be settable after realize */
1683bddd892eSPeter Maydell     object_property_add_uint32_ptr(obj, "psci-conduit",
1684bddd892eSPeter Maydell                                    &cpu->psci_conduit,
1685bddd892eSPeter Maydell                                    OBJ_PROP_FLAG_READWRITE);
1686bddd892eSPeter Maydell 
168794d912d1SMarc-André Lureau     qdev_property_add_static(DEVICE(obj), &arm_cpu_cfgend_property);
168896eec6b2SAndrew Jeffery 
168996eec6b2SAndrew Jeffery     if (arm_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER)) {
169094d912d1SMarc-André Lureau         qdev_property_add_static(DEVICE(cpu), &arm_cpu_gt_cntfrq_property);
169196eec6b2SAndrew Jeffery     }
16929e6f8d8aSfangying 
16939e6f8d8aSfangying     if (kvm_enabled()) {
1694cac675b5SPhilippe Mathieu-Daudé         kvm_arm_add_vcpu_properties(cpu);
16959e6f8d8aSfangying     }
16968bce44a2SRichard Henderson 
16978bce44a2SRichard Henderson #ifndef CONFIG_USER_ONLY
16988bce44a2SRichard Henderson     if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64) &&
16998bce44a2SRichard Henderson         cpu_isar_feature(aa64_mte, cpu)) {
17008bce44a2SRichard Henderson         object_property_add_link(obj, "tag-memory",
17018bce44a2SRichard Henderson                                  TYPE_MEMORY_REGION,
17028bce44a2SRichard Henderson                                  (Object **)&cpu->tag_memory,
17038bce44a2SRichard Henderson                                  qdev_prop_allow_set_link_before_realize,
17048bce44a2SRichard Henderson                                  OBJ_PROP_LINK_STRONG);
17058bce44a2SRichard Henderson 
17068bce44a2SRichard Henderson         if (arm_feature(&cpu->env, ARM_FEATURE_EL3)) {
17078bce44a2SRichard Henderson             object_property_add_link(obj, "secure-tag-memory",
17088bce44a2SRichard Henderson                                      TYPE_MEMORY_REGION,
17098bce44a2SRichard Henderson                                      (Object **)&cpu->secure_tag_memory,
17108bce44a2SRichard Henderson                                      qdev_prop_allow_set_link_before_realize,
17118bce44a2SRichard Henderson                                      OBJ_PROP_LINK_STRONG);
17128bce44a2SRichard Henderson         }
17138bce44a2SRichard Henderson     }
17148bce44a2SRichard Henderson #endif
1715fcf5ef2aSThomas Huth }
1716fcf5ef2aSThomas Huth 
1717fcf5ef2aSThomas Huth static void arm_cpu_finalizefn(Object *obj)
1718fcf5ef2aSThomas Huth {
1719fcf5ef2aSThomas Huth     ARMCPU *cpu = ARM_CPU(obj);
172008267487SAaron Lindsay     ARMELChangeHook *hook, *next;
172108267487SAaron Lindsay 
1722fcf5ef2aSThomas Huth     g_hash_table_destroy(cpu->cp_regs);
172308267487SAaron Lindsay 
1724b5c53d1bSAaron Lindsay     QLIST_FOREACH_SAFE(hook, &cpu->pre_el_change_hooks, node, next) {
1725b5c53d1bSAaron Lindsay         QLIST_REMOVE(hook, node);
1726b5c53d1bSAaron Lindsay         g_free(hook);
1727b5c53d1bSAaron Lindsay     }
172808267487SAaron Lindsay     QLIST_FOREACH_SAFE(hook, &cpu->el_change_hooks, node, next) {
172908267487SAaron Lindsay         QLIST_REMOVE(hook, node);
173008267487SAaron Lindsay         g_free(hook);
173108267487SAaron Lindsay     }
17324e7beb0cSAaron Lindsay OS #ifndef CONFIG_USER_ONLY
17334e7beb0cSAaron Lindsay OS     if (cpu->pmu_timer) {
17344e7beb0cSAaron Lindsay OS         timer_free(cpu->pmu_timer);
17354e7beb0cSAaron Lindsay OS     }
17364e7beb0cSAaron Lindsay OS #endif
1737fcf5ef2aSThomas Huth }
1738fcf5ef2aSThomas Huth 
17390df9142dSAndrew Jones void arm_cpu_finalize_features(ARMCPU *cpu, Error **errp)
17400df9142dSAndrew Jones {
17410df9142dSAndrew Jones     Error *local_err = NULL;
17420df9142dSAndrew Jones 
174307301161SRichard Henderson #ifdef TARGET_AARCH64
17440df9142dSAndrew Jones     if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
17450df9142dSAndrew Jones         arm_cpu_sve_finalize(cpu, &local_err);
17460df9142dSAndrew Jones         if (local_err != NULL) {
17470df9142dSAndrew Jones             error_propagate(errp, local_err);
17480df9142dSAndrew Jones             return;
17490df9142dSAndrew Jones         }
1750eb94284dSRichard Henderson 
1751f7767ca3SPeter Maydell         /*
1752f7767ca3SPeter Maydell          * FEAT_SME is not architecturally dependent on FEAT_SVE (unless
1753f7767ca3SPeter Maydell          * FEAT_SME_FA64 is present). However our implementation currently
1754f7767ca3SPeter Maydell          * assumes it, so if the user asked for sve=off then turn off SME also.
1755f7767ca3SPeter Maydell          * (KVM doesn't currently support SME at all.)
1756f7767ca3SPeter Maydell          */
1757f7767ca3SPeter Maydell         if (cpu_isar_feature(aa64_sme, cpu) && !cpu_isar_feature(aa64_sve, cpu)) {
1758f7767ca3SPeter Maydell             object_property_set_bool(OBJECT(cpu), "sme", false, &error_abort);
1759f7767ca3SPeter Maydell         }
1760f7767ca3SPeter Maydell 
1761e74c0976SRichard Henderson         arm_cpu_sme_finalize(cpu, &local_err);
1762e74c0976SRichard Henderson         if (local_err != NULL) {
1763e74c0976SRichard Henderson             error_propagate(errp, local_err);
1764e74c0976SRichard Henderson             return;
1765e74c0976SRichard Henderson         }
1766e74c0976SRichard Henderson 
1767eb94284dSRichard Henderson         arm_cpu_pauth_finalize(cpu, &local_err);
1768eb94284dSRichard Henderson         if (local_err != NULL) {
1769eb94284dSRichard Henderson             error_propagate(errp, local_err);
1770eb94284dSRichard Henderson             return;
1771eb94284dSRichard Henderson         }
177269b2265dSRichard Henderson 
177369b2265dSRichard Henderson         arm_cpu_lpa2_finalize(cpu, &local_err);
177469b2265dSRichard Henderson         if (local_err != NULL) {
177569b2265dSRichard Henderson             error_propagate(errp, local_err);
177669b2265dSRichard Henderson             return;
177769b2265dSRichard Henderson         }
1778eb94284dSRichard Henderson     }
177907301161SRichard Henderson #endif
178068970d1eSAndrew Jones 
178168970d1eSAndrew Jones     if (kvm_enabled()) {
178268970d1eSAndrew Jones         kvm_arm_steal_time_finalize(cpu, &local_err);
178368970d1eSAndrew Jones         if (local_err != NULL) {
178468970d1eSAndrew Jones             error_propagate(errp, local_err);
178568970d1eSAndrew Jones             return;
178668970d1eSAndrew Jones         }
178768970d1eSAndrew Jones     }
17880df9142dSAndrew Jones }
17890df9142dSAndrew Jones 
1790fcf5ef2aSThomas Huth static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
1791fcf5ef2aSThomas Huth {
1792fcf5ef2aSThomas Huth     CPUState *cs = CPU(dev);
1793fcf5ef2aSThomas Huth     ARMCPU *cpu = ARM_CPU(dev);
1794fcf5ef2aSThomas Huth     ARMCPUClass *acc = ARM_CPU_GET_CLASS(dev);
1795fcf5ef2aSThomas Huth     CPUARMState *env = &cpu->env;
1796fcf5ef2aSThomas Huth     int pagebits;
1797fcf5ef2aSThomas Huth     Error *local_err = NULL;
1798fcf5ef2aSThomas Huth 
1799b94b8c60SPhilippe Mathieu-Daudé #if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
1800e607ea39SAnton Johansson     /* Use pc-relative instructions in system-mode */
1801e607ea39SAnton Johansson     cs->tcg_cflags |= CF_PCREL;
1802e607ea39SAnton Johansson #endif
1803e607ea39SAnton Johansson 
1804c4487d76SPeter Maydell     /* If we needed to query the host kernel for the CPU features
1805c4487d76SPeter Maydell      * then it's possible that might have failed in the initfn, but
1806c4487d76SPeter Maydell      * this is the first point where we can report it.
1807c4487d76SPeter Maydell      */
1808c4487d76SPeter Maydell     if (cpu->host_cpu_probe_failed) {
1809585df85eSPeter Maydell         if (!kvm_enabled() && !hvf_enabled()) {
1810585df85eSPeter Maydell             error_setg(errp, "The 'host' CPU type can only be used with KVM or HVF");
1811c4487d76SPeter Maydell         } else {
1812c4487d76SPeter Maydell             error_setg(errp, "Failed to retrieve host CPU features");
1813c4487d76SPeter Maydell         }
1814c4487d76SPeter Maydell         return;
1815c4487d76SPeter Maydell     }
1816c4487d76SPeter Maydell 
181795f87565SPeter Maydell #ifndef CONFIG_USER_ONLY
181895f87565SPeter Maydell     /* The NVIC and M-profile CPU are two halves of a single piece of
181995f87565SPeter Maydell      * hardware; trying to use one without the other is a command line
182095f87565SPeter Maydell      * error and will result in segfaults if not caught here.
182195f87565SPeter Maydell      */
182295f87565SPeter Maydell     if (arm_feature(env, ARM_FEATURE_M)) {
182395f87565SPeter Maydell         if (!env->nvic) {
182495f87565SPeter Maydell             error_setg(errp, "This board cannot be used with Cortex-M CPUs");
182595f87565SPeter Maydell             return;
182695f87565SPeter Maydell         }
182795f87565SPeter Maydell     } else {
182895f87565SPeter Maydell         if (env->nvic) {
182995f87565SPeter Maydell             error_setg(errp, "This board can only be used with Cortex-M CPUs");
183095f87565SPeter Maydell             return;
183195f87565SPeter Maydell         }
183295f87565SPeter Maydell     }
1833397cd31fSPeter Maydell 
1834045e5064SAlexander Graf     if (!tcg_enabled() && !qtest_enabled()) {
183549e7f191SPeter Maydell         /*
1836045e5064SAlexander Graf          * We assume that no accelerator except TCG (and the "not really an
1837045e5064SAlexander Graf          * accelerator" qtest) can handle these features, because Arm hardware
1838045e5064SAlexander Graf          * virtualization can't virtualize them.
1839045e5064SAlexander Graf          *
184049e7f191SPeter Maydell          * Catch all the cases which might cause us to create more than one
184149e7f191SPeter Maydell          * address space for the CPU (otherwise we will assert() later in
184249e7f191SPeter Maydell          * cpu_address_space_init()).
184349e7f191SPeter Maydell          */
184449e7f191SPeter Maydell         if (arm_feature(env, ARM_FEATURE_M)) {
184549e7f191SPeter Maydell             error_setg(errp,
1846045e5064SAlexander Graf                        "Cannot enable %s when using an M-profile guest CPU",
1847045e5064SAlexander Graf                        current_accel_name());
184849e7f191SPeter Maydell             return;
184949e7f191SPeter Maydell         }
185049e7f191SPeter Maydell         if (cpu->has_el3) {
185149e7f191SPeter Maydell             error_setg(errp,
1852045e5064SAlexander Graf                        "Cannot enable %s when guest CPU has EL3 enabled",
1853045e5064SAlexander Graf                        current_accel_name());
185449e7f191SPeter Maydell             return;
185549e7f191SPeter Maydell         }
185649e7f191SPeter Maydell         if (cpu->tag_memory) {
185749e7f191SPeter Maydell             error_setg(errp,
1858d009607dSPeter Maydell                        "Cannot enable %s when guest CPUs has MTE enabled",
1859045e5064SAlexander Graf                        current_accel_name());
186049e7f191SPeter Maydell             return;
186149e7f191SPeter Maydell         }
186249e7f191SPeter Maydell     }
186349e7f191SPeter Maydell 
186496eec6b2SAndrew Jeffery     {
186596eec6b2SAndrew Jeffery         uint64_t scale;
186696eec6b2SAndrew Jeffery 
186796eec6b2SAndrew Jeffery         if (arm_feature(env, ARM_FEATURE_GENERIC_TIMER)) {
186896eec6b2SAndrew Jeffery             if (!cpu->gt_cntfrq_hz) {
186996eec6b2SAndrew Jeffery                 error_setg(errp, "Invalid CNTFRQ: %"PRId64"Hz",
187096eec6b2SAndrew Jeffery                            cpu->gt_cntfrq_hz);
187196eec6b2SAndrew Jeffery                 return;
187296eec6b2SAndrew Jeffery             }
187396eec6b2SAndrew Jeffery             scale = gt_cntfrq_period_ns(cpu);
187496eec6b2SAndrew Jeffery         } else {
187596eec6b2SAndrew Jeffery             scale = GTIMER_SCALE;
187696eec6b2SAndrew Jeffery         }
187796eec6b2SAndrew Jeffery 
187896eec6b2SAndrew Jeffery         cpu->gt_timer[GTIMER_PHYS] = timer_new(QEMU_CLOCK_VIRTUAL, scale,
1879397cd31fSPeter Maydell                                                arm_gt_ptimer_cb, cpu);
188096eec6b2SAndrew Jeffery         cpu->gt_timer[GTIMER_VIRT] = timer_new(QEMU_CLOCK_VIRTUAL, scale,
1881397cd31fSPeter Maydell                                                arm_gt_vtimer_cb, cpu);
188296eec6b2SAndrew Jeffery         cpu->gt_timer[GTIMER_HYP] = timer_new(QEMU_CLOCK_VIRTUAL, scale,
1883397cd31fSPeter Maydell                                               arm_gt_htimer_cb, cpu);
188496eec6b2SAndrew Jeffery         cpu->gt_timer[GTIMER_SEC] = timer_new(QEMU_CLOCK_VIRTUAL, scale,
1885397cd31fSPeter Maydell                                               arm_gt_stimer_cb, cpu);
18868c94b071SRichard Henderson         cpu->gt_timer[GTIMER_HYPVIRT] = timer_new(QEMU_CLOCK_VIRTUAL, scale,
18878c94b071SRichard Henderson                                                   arm_gt_hvtimer_cb, cpu);
188896eec6b2SAndrew Jeffery     }
188995f87565SPeter Maydell #endif
189095f87565SPeter Maydell 
1891fcf5ef2aSThomas Huth     cpu_exec_realizefn(cs, &local_err);
1892fcf5ef2aSThomas Huth     if (local_err != NULL) {
1893fcf5ef2aSThomas Huth         error_propagate(errp, local_err);
1894fcf5ef2aSThomas Huth         return;
1895fcf5ef2aSThomas Huth     }
1896fcf5ef2aSThomas Huth 
18970df9142dSAndrew Jones     arm_cpu_finalize_features(cpu, &local_err);
18980df9142dSAndrew Jones     if (local_err != NULL) {
18990df9142dSAndrew Jones         error_propagate(errp, local_err);
19000df9142dSAndrew Jones         return;
19010df9142dSAndrew Jones     }
19020df9142dSAndrew Jones 
19039719f125SJohn Högberg #ifdef CONFIG_USER_ONLY
19049719f125SJohn Högberg     /*
19059719f125SJohn Högberg      * User mode relies on IC IVAU instructions to catch modification of
19069719f125SJohn Högberg      * dual-mapped code.
19079719f125SJohn Högberg      *
19089719f125SJohn Högberg      * Clear CTR_EL0.DIC to ensure that software that honors these flags uses
19099719f125SJohn Högberg      * IC IVAU even if the emulated processor does not normally require it.
19109719f125SJohn Högberg      */
19119719f125SJohn Högberg     cpu->ctr = FIELD_DP64(cpu->ctr, CTR_EL0, DIC, 0);
19129719f125SJohn Högberg #endif
19139719f125SJohn Högberg 
191497a28b0eSPeter Maydell     if (arm_feature(env, ARM_FEATURE_AARCH64) &&
191597a28b0eSPeter Maydell         cpu->has_vfp != cpu->has_neon) {
191697a28b0eSPeter Maydell         /*
191797a28b0eSPeter Maydell          * This is an architectural requirement for AArch64; AArch32 is
191897a28b0eSPeter Maydell          * more flexible and permits VFP-no-Neon and Neon-no-VFP.
191997a28b0eSPeter Maydell          */
192097a28b0eSPeter Maydell         error_setg(errp,
192197a28b0eSPeter Maydell                    "AArch64 CPUs must have both VFP and Neon or neither");
192297a28b0eSPeter Maydell         return;
192397a28b0eSPeter Maydell     }
192497a28b0eSPeter Maydell 
192542bea956SCédric Le Goater     if (cpu->has_vfp_d32 != cpu->has_neon) {
192642bea956SCédric Le Goater         error_setg(errp, "ARM CPUs must have both VFP-D32 and Neon or neither");
192742bea956SCédric Le Goater         return;
192842bea956SCédric Le Goater     }
192942bea956SCédric Le Goater 
193042bea956SCédric Le Goater    if (!cpu->has_vfp_d32) {
193142bea956SCédric Le Goater         uint32_t u;
193242bea956SCédric Le Goater 
193342bea956SCédric Le Goater         u = cpu->isar.mvfr0;
193442bea956SCédric Le Goater         u = FIELD_DP32(u, MVFR0, SIMDREG, 1); /* 16 registers */
193542bea956SCédric Le Goater         cpu->isar.mvfr0 = u;
193642bea956SCédric Le Goater     }
193742bea956SCédric Le Goater 
193897a28b0eSPeter Maydell     if (!cpu->has_vfp) {
193997a28b0eSPeter Maydell         uint64_t t;
194097a28b0eSPeter Maydell         uint32_t u;
194197a28b0eSPeter Maydell 
194297a28b0eSPeter Maydell         t = cpu->isar.id_aa64isar1;
194397a28b0eSPeter Maydell         t = FIELD_DP64(t, ID_AA64ISAR1, JSCVT, 0);
194497a28b0eSPeter Maydell         cpu->isar.id_aa64isar1 = t;
194597a28b0eSPeter Maydell 
194697a28b0eSPeter Maydell         t = cpu->isar.id_aa64pfr0;
194797a28b0eSPeter Maydell         t = FIELD_DP64(t, ID_AA64PFR0, FP, 0xf);
194897a28b0eSPeter Maydell         cpu->isar.id_aa64pfr0 = t;
194997a28b0eSPeter Maydell 
195097a28b0eSPeter Maydell         u = cpu->isar.id_isar6;
195197a28b0eSPeter Maydell         u = FIELD_DP32(u, ID_ISAR6, JSCVT, 0);
19523c93dfa4SRichard Henderson         u = FIELD_DP32(u, ID_ISAR6, BF16, 0);
195397a28b0eSPeter Maydell         cpu->isar.id_isar6 = u;
195497a28b0eSPeter Maydell 
195597a28b0eSPeter Maydell         u = cpu->isar.mvfr0;
195697a28b0eSPeter Maydell         u = FIELD_DP32(u, MVFR0, FPSP, 0);
195797a28b0eSPeter Maydell         u = FIELD_DP32(u, MVFR0, FPDP, 0);
195897a28b0eSPeter Maydell         u = FIELD_DP32(u, MVFR0, FPDIVIDE, 0);
195997a28b0eSPeter Maydell         u = FIELD_DP32(u, MVFR0, FPSQRT, 0);
196097a28b0eSPeter Maydell         u = FIELD_DP32(u, MVFR0, FPROUND, 0);
1961532a3af5SPeter Maydell         if (!arm_feature(env, ARM_FEATURE_M)) {
1962532a3af5SPeter Maydell             u = FIELD_DP32(u, MVFR0, FPTRAP, 0);
1963532a3af5SPeter Maydell             u = FIELD_DP32(u, MVFR0, FPSHVEC, 0);
1964532a3af5SPeter Maydell         }
196597a28b0eSPeter Maydell         cpu->isar.mvfr0 = u;
196697a28b0eSPeter Maydell 
196797a28b0eSPeter Maydell         u = cpu->isar.mvfr1;
196897a28b0eSPeter Maydell         u = FIELD_DP32(u, MVFR1, FPFTZ, 0);
196997a28b0eSPeter Maydell         u = FIELD_DP32(u, MVFR1, FPDNAN, 0);
197097a28b0eSPeter Maydell         u = FIELD_DP32(u, MVFR1, FPHP, 0);
1971532a3af5SPeter Maydell         if (arm_feature(env, ARM_FEATURE_M)) {
1972532a3af5SPeter Maydell             u = FIELD_DP32(u, MVFR1, FP16, 0);
1973532a3af5SPeter Maydell         }
197497a28b0eSPeter Maydell         cpu->isar.mvfr1 = u;
197597a28b0eSPeter Maydell 
197697a28b0eSPeter Maydell         u = cpu->isar.mvfr2;
197797a28b0eSPeter Maydell         u = FIELD_DP32(u, MVFR2, FPMISC, 0);
197897a28b0eSPeter Maydell         cpu->isar.mvfr2 = u;
197997a28b0eSPeter Maydell     }
198097a28b0eSPeter Maydell 
198197a28b0eSPeter Maydell     if (!cpu->has_neon) {
198297a28b0eSPeter Maydell         uint64_t t;
198397a28b0eSPeter Maydell         uint32_t u;
198497a28b0eSPeter Maydell 
198597a28b0eSPeter Maydell         unset_feature(env, ARM_FEATURE_NEON);
198697a28b0eSPeter Maydell 
198797a28b0eSPeter Maydell         t = cpu->isar.id_aa64isar0;
1988eb851c11SDamien Hedde         t = FIELD_DP64(t, ID_AA64ISAR0, AES, 0);
1989eb851c11SDamien Hedde         t = FIELD_DP64(t, ID_AA64ISAR0, SHA1, 0);
1990eb851c11SDamien Hedde         t = FIELD_DP64(t, ID_AA64ISAR0, SHA2, 0);
1991eb851c11SDamien Hedde         t = FIELD_DP64(t, ID_AA64ISAR0, SHA3, 0);
1992eb851c11SDamien Hedde         t = FIELD_DP64(t, ID_AA64ISAR0, SM3, 0);
1993eb851c11SDamien Hedde         t = FIELD_DP64(t, ID_AA64ISAR0, SM4, 0);
199497a28b0eSPeter Maydell         t = FIELD_DP64(t, ID_AA64ISAR0, DP, 0);
199597a28b0eSPeter Maydell         cpu->isar.id_aa64isar0 = t;
199697a28b0eSPeter Maydell 
199797a28b0eSPeter Maydell         t = cpu->isar.id_aa64isar1;
199897a28b0eSPeter Maydell         t = FIELD_DP64(t, ID_AA64ISAR1, FCMA, 0);
19993c93dfa4SRichard Henderson         t = FIELD_DP64(t, ID_AA64ISAR1, BF16, 0);
2000f8680aaaSRichard Henderson         t = FIELD_DP64(t, ID_AA64ISAR1, I8MM, 0);
200197a28b0eSPeter Maydell         cpu->isar.id_aa64isar1 = t;
200297a28b0eSPeter Maydell 
200397a28b0eSPeter Maydell         t = cpu->isar.id_aa64pfr0;
200497a28b0eSPeter Maydell         t = FIELD_DP64(t, ID_AA64PFR0, ADVSIMD, 0xf);
200597a28b0eSPeter Maydell         cpu->isar.id_aa64pfr0 = t;
200697a28b0eSPeter Maydell 
200797a28b0eSPeter Maydell         u = cpu->isar.id_isar5;
2008eb851c11SDamien Hedde         u = FIELD_DP32(u, ID_ISAR5, AES, 0);
2009eb851c11SDamien Hedde         u = FIELD_DP32(u, ID_ISAR5, SHA1, 0);
2010eb851c11SDamien Hedde         u = FIELD_DP32(u, ID_ISAR5, SHA2, 0);
201197a28b0eSPeter Maydell         u = FIELD_DP32(u, ID_ISAR5, RDM, 0);
201297a28b0eSPeter Maydell         u = FIELD_DP32(u, ID_ISAR5, VCMA, 0);
201397a28b0eSPeter Maydell         cpu->isar.id_isar5 = u;
201497a28b0eSPeter Maydell 
201597a28b0eSPeter Maydell         u = cpu->isar.id_isar6;
201697a28b0eSPeter Maydell         u = FIELD_DP32(u, ID_ISAR6, DP, 0);
201797a28b0eSPeter Maydell         u = FIELD_DP32(u, ID_ISAR6, FHM, 0);
20183c93dfa4SRichard Henderson         u = FIELD_DP32(u, ID_ISAR6, BF16, 0);
2019f8680aaaSRichard Henderson         u = FIELD_DP32(u, ID_ISAR6, I8MM, 0);
202097a28b0eSPeter Maydell         cpu->isar.id_isar6 = u;
202197a28b0eSPeter Maydell 
2022532a3af5SPeter Maydell         if (!arm_feature(env, ARM_FEATURE_M)) {
202397a28b0eSPeter Maydell             u = cpu->isar.mvfr1;
202497a28b0eSPeter Maydell             u = FIELD_DP32(u, MVFR1, SIMDLS, 0);
202597a28b0eSPeter Maydell             u = FIELD_DP32(u, MVFR1, SIMDINT, 0);
202697a28b0eSPeter Maydell             u = FIELD_DP32(u, MVFR1, SIMDSP, 0);
202797a28b0eSPeter Maydell             u = FIELD_DP32(u, MVFR1, SIMDHP, 0);
202897a28b0eSPeter Maydell             cpu->isar.mvfr1 = u;
202997a28b0eSPeter Maydell 
203097a28b0eSPeter Maydell             u = cpu->isar.mvfr2;
203197a28b0eSPeter Maydell             u = FIELD_DP32(u, MVFR2, SIMDMISC, 0);
203297a28b0eSPeter Maydell             cpu->isar.mvfr2 = u;
203397a28b0eSPeter Maydell         }
2034532a3af5SPeter Maydell     }
203597a28b0eSPeter Maydell 
203697a28b0eSPeter Maydell     if (!cpu->has_neon && !cpu->has_vfp) {
203797a28b0eSPeter Maydell         uint64_t t;
203897a28b0eSPeter Maydell         uint32_t u;
203997a28b0eSPeter Maydell 
204097a28b0eSPeter Maydell         t = cpu->isar.id_aa64isar0;
204197a28b0eSPeter Maydell         t = FIELD_DP64(t, ID_AA64ISAR0, FHM, 0);
204297a28b0eSPeter Maydell         cpu->isar.id_aa64isar0 = t;
204397a28b0eSPeter Maydell 
204497a28b0eSPeter Maydell         t = cpu->isar.id_aa64isar1;
204597a28b0eSPeter Maydell         t = FIELD_DP64(t, ID_AA64ISAR1, FRINTTS, 0);
204697a28b0eSPeter Maydell         cpu->isar.id_aa64isar1 = t;
204797a28b0eSPeter Maydell 
204897a28b0eSPeter Maydell         u = cpu->isar.mvfr0;
204997a28b0eSPeter Maydell         u = FIELD_DP32(u, MVFR0, SIMDREG, 0);
205097a28b0eSPeter Maydell         cpu->isar.mvfr0 = u;
2051c52881bbSRichard Henderson 
2052c52881bbSRichard Henderson         /* Despite the name, this field covers both VFP and Neon */
2053c52881bbSRichard Henderson         u = cpu->isar.mvfr1;
2054c52881bbSRichard Henderson         u = FIELD_DP32(u, MVFR1, SIMDFMAC, 0);
2055c52881bbSRichard Henderson         cpu->isar.mvfr1 = u;
205697a28b0eSPeter Maydell     }
205797a28b0eSPeter Maydell 
2058ea90db0aSPeter Maydell     if (arm_feature(env, ARM_FEATURE_M) && !cpu->has_dsp) {
2059ea90db0aSPeter Maydell         uint32_t u;
2060ea90db0aSPeter Maydell 
2061ea90db0aSPeter Maydell         unset_feature(env, ARM_FEATURE_THUMB_DSP);
2062ea90db0aSPeter Maydell 
2063ea90db0aSPeter Maydell         u = cpu->isar.id_isar1;
2064ea90db0aSPeter Maydell         u = FIELD_DP32(u, ID_ISAR1, EXTEND, 1);
2065ea90db0aSPeter Maydell         cpu->isar.id_isar1 = u;
2066ea90db0aSPeter Maydell 
2067ea90db0aSPeter Maydell         u = cpu->isar.id_isar2;
2068ea90db0aSPeter Maydell         u = FIELD_DP32(u, ID_ISAR2, MULTU, 1);
2069ea90db0aSPeter Maydell         u = FIELD_DP32(u, ID_ISAR2, MULTS, 1);
2070ea90db0aSPeter Maydell         cpu->isar.id_isar2 = u;
2071ea90db0aSPeter Maydell 
2072ea90db0aSPeter Maydell         u = cpu->isar.id_isar3;
2073ea90db0aSPeter Maydell         u = FIELD_DP32(u, ID_ISAR3, SIMD, 1);
2074ea90db0aSPeter Maydell         u = FIELD_DP32(u, ID_ISAR3, SATURATE, 0);
2075ea90db0aSPeter Maydell         cpu->isar.id_isar3 = u;
2076ea90db0aSPeter Maydell     }
2077ea90db0aSPeter Maydell 
2078fcf5ef2aSThomas Huth 
2079ea7ac69dSPeter Maydell     /*
2080ea7ac69dSPeter Maydell      * We rely on no XScale CPU having VFP so we can use the same bits in the
2081ea7ac69dSPeter Maydell      * TB flags field for VECSTRIDE and XSCALE_CPAR.
2082ea7ac69dSPeter Maydell      */
20837d63183fSRichard Henderson     assert(arm_feature(&cpu->env, ARM_FEATURE_AARCH64) ||
20847d63183fSRichard Henderson            !cpu_isar_feature(aa32_vfp_simd, cpu) ||
20857d63183fSRichard Henderson            !arm_feature(env, ARM_FEATURE_XSCALE));
2086ea7ac69dSPeter Maydell 
2087fcf5ef2aSThomas Huth     if (arm_feature(env, ARM_FEATURE_V7) &&
2088fcf5ef2aSThomas Huth         !arm_feature(env, ARM_FEATURE_M) &&
2089452a0955SPeter Maydell         !arm_feature(env, ARM_FEATURE_PMSA)) {
2090fcf5ef2aSThomas Huth         /* v7VMSA drops support for the old ARMv5 tiny pages, so we
2091fcf5ef2aSThomas Huth          * can use 4K pages.
2092fcf5ef2aSThomas Huth          */
2093fcf5ef2aSThomas Huth         pagebits = 12;
2094fcf5ef2aSThomas Huth     } else {
2095fcf5ef2aSThomas Huth         /* For CPUs which might have tiny 1K pages, or which have an
2096fcf5ef2aSThomas Huth          * MPU and might have small region sizes, stick with 1K pages.
2097fcf5ef2aSThomas Huth          */
2098fcf5ef2aSThomas Huth         pagebits = 10;
2099fcf5ef2aSThomas Huth     }
2100fcf5ef2aSThomas Huth     if (!set_preferred_target_page_bits(pagebits)) {
2101fcf5ef2aSThomas Huth         /* This can only ever happen for hotplugging a CPU, or if
2102fcf5ef2aSThomas Huth          * the board code incorrectly creates a CPU which it has
2103fcf5ef2aSThomas Huth          * promised via minimum_page_size that it will not.
2104fcf5ef2aSThomas Huth          */
2105fcf5ef2aSThomas Huth         error_setg(errp, "This CPU requires a smaller page size than the "
2106fcf5ef2aSThomas Huth                    "system is using");
2107fcf5ef2aSThomas Huth         return;
2108fcf5ef2aSThomas Huth     }
2109fcf5ef2aSThomas Huth 
2110fcf5ef2aSThomas Huth     /* This cpu-id-to-MPIDR affinity is used only for TCG; KVM will override it.
2111fcf5ef2aSThomas Huth      * We don't support setting cluster ID ([16..23]) (known as Aff2
2112fcf5ef2aSThomas Huth      * in later ARM ARM versions), or any of the higher affinity level fields,
2113fcf5ef2aSThomas Huth      * so these bits always RAZ.
2114fcf5ef2aSThomas Huth      */
2115fcf5ef2aSThomas Huth     if (cpu->mp_affinity == ARM64_AFFINITY_INVALID) {
2116*750245edSRichard Henderson         cpu->mp_affinity = arm_build_mp_affinity(cs->cpu_index,
211746de5913SIgor Mammedov                                                  ARM_DEFAULT_CPUS_PER_CLUSTER);
2118fcf5ef2aSThomas Huth     }
2119fcf5ef2aSThomas Huth 
2120fcf5ef2aSThomas Huth     if (cpu->reset_hivecs) {
2121fcf5ef2aSThomas Huth             cpu->reset_sctlr |= (1 << 13);
2122fcf5ef2aSThomas Huth     }
2123fcf5ef2aSThomas Huth 
21243a062d57SJulian Brown     if (cpu->cfgend) {
21253a062d57SJulian Brown         if (arm_feature(&cpu->env, ARM_FEATURE_V7)) {
21263a062d57SJulian Brown             cpu->reset_sctlr |= SCTLR_EE;
21273a062d57SJulian Brown         } else {
21283a062d57SJulian Brown             cpu->reset_sctlr |= SCTLR_B;
21293a062d57SJulian Brown         }
21303a062d57SJulian Brown     }
21313a062d57SJulian Brown 
213240188188SPeter Maydell     if (!arm_feature(env, ARM_FEATURE_M) && !cpu->has_el3) {
2133fcf5ef2aSThomas Huth         /* If the has_el3 CPU property is disabled then we need to disable the
2134fcf5ef2aSThomas Huth          * feature.
2135fcf5ef2aSThomas Huth          */
2136fcf5ef2aSThomas Huth         unset_feature(env, ARM_FEATURE_EL3);
2137fcf5ef2aSThomas Huth 
2138b13c91c0SRichard Henderson         /*
2139b13c91c0SRichard Henderson          * Disable the security extension feature bits in the processor
2140b13c91c0SRichard Henderson          * feature registers as well.
2141fcf5ef2aSThomas Huth          */
2142b13c91c0SRichard Henderson         cpu->isar.id_pfr1 = FIELD_DP32(cpu->isar.id_pfr1, ID_PFR1, SECURITY, 0);
2143033a4f15SRichard Henderson         cpu->isar.id_dfr0 = FIELD_DP32(cpu->isar.id_dfr0, ID_DFR0, COPSDBG, 0);
2144b13c91c0SRichard Henderson         cpu->isar.id_aa64pfr0 = FIELD_DP64(cpu->isar.id_aa64pfr0,
2145b13c91c0SRichard Henderson                                            ID_AA64PFR0, EL3, 0);
2146b9f335c2SRichard Henderson 
2147b9f335c2SRichard Henderson         /* Disable the realm management extension, which requires EL3. */
2148b9f335c2SRichard Henderson         cpu->isar.id_aa64pfr0 = FIELD_DP64(cpu->isar.id_aa64pfr0,
2149b9f335c2SRichard Henderson                                            ID_AA64PFR0, RME, 0);
2150fcf5ef2aSThomas Huth     }
2151fcf5ef2aSThomas Huth 
2152c25bd18aSPeter Maydell     if (!cpu->has_el2) {
2153c25bd18aSPeter Maydell         unset_feature(env, ARM_FEATURE_EL2);
2154c25bd18aSPeter Maydell     }
2155c25bd18aSPeter Maydell 
2156d6f02ce3SWei Huang     if (!cpu->has_pmu) {
2157fcf5ef2aSThomas Huth         unset_feature(env, ARM_FEATURE_PMU);
215857a4a11bSAaron Lindsay     }
215957a4a11bSAaron Lindsay     if (arm_feature(env, ARM_FEATURE_PMU)) {
2160bf8d0969SAaron Lindsay OS         pmu_init(cpu);
216157a4a11bSAaron Lindsay 
216257a4a11bSAaron Lindsay         if (!kvm_enabled()) {
2163033614c4SAaron Lindsay             arm_register_pre_el_change_hook(cpu, &pmu_pre_el_change, 0);
2164033614c4SAaron Lindsay             arm_register_el_change_hook(cpu, &pmu_post_el_change, 0);
2165fcf5ef2aSThomas Huth         }
21664e7beb0cSAaron Lindsay OS 
21674e7beb0cSAaron Lindsay OS #ifndef CONFIG_USER_ONLY
21684e7beb0cSAaron Lindsay OS         cpu->pmu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, arm_pmu_timer_cb,
21694e7beb0cSAaron Lindsay OS                 cpu);
21704e7beb0cSAaron Lindsay OS #endif
217157a4a11bSAaron Lindsay     } else {
21722a609df8SPeter Maydell         cpu->isar.id_aa64dfr0 =
21732a609df8SPeter Maydell             FIELD_DP64(cpu->isar.id_aa64dfr0, ID_AA64DFR0, PMUVER, 0);
2174a6179538SPeter Maydell         cpu->isar.id_dfr0 = FIELD_DP32(cpu->isar.id_dfr0, ID_DFR0, PERFMON, 0);
217557a4a11bSAaron Lindsay         cpu->pmceid0 = 0;
217657a4a11bSAaron Lindsay         cpu->pmceid1 = 0;
217757a4a11bSAaron Lindsay     }
2178fcf5ef2aSThomas Huth 
2179fcf5ef2aSThomas Huth     if (!arm_feature(env, ARM_FEATURE_EL2)) {
2180b13c91c0SRichard Henderson         /*
2181b13c91c0SRichard Henderson          * Disable the hypervisor feature bits in the processor feature
2182b13c91c0SRichard Henderson          * registers if we don't have EL2.
2183fcf5ef2aSThomas Huth          */
2184b13c91c0SRichard Henderson         cpu->isar.id_aa64pfr0 = FIELD_DP64(cpu->isar.id_aa64pfr0,
2185b13c91c0SRichard Henderson                                            ID_AA64PFR0, EL2, 0);
2186b13c91c0SRichard Henderson         cpu->isar.id_pfr1 = FIELD_DP32(cpu->isar.id_pfr1,
2187b13c91c0SRichard Henderson                                        ID_PFR1, VIRTUALIZATION, 0);
2188fcf5ef2aSThomas Huth     }
2189fcf5ef2aSThomas Huth 
21907134cb07SRichard Henderson     if (cpu_isar_feature(aa64_mte, cpu)) {
21917134cb07SRichard Henderson         /*
21927134cb07SRichard Henderson          * The architectural range of GM blocksize is 2-6, however qemu
21937134cb07SRichard Henderson          * doesn't support blocksize of 2 (see HELPER(ldgm)).
21947134cb07SRichard Henderson          */
21957134cb07SRichard Henderson         if (tcg_enabled()) {
21967134cb07SRichard Henderson             assert(cpu->gm_blocksize >= 3 && cpu->gm_blocksize <= 6);
21977134cb07SRichard Henderson         }
21987134cb07SRichard Henderson 
21996f4e1405SRichard Henderson #ifndef CONFIG_USER_ONLY
22006f4e1405SRichard Henderson         /*
2201cd305b5fSRichard Henderson          * If we do not have tag-memory provided by the machine,
2202cd305b5fSRichard Henderson          * reduce MTE support to instructions enabled at EL0.
2203cd305b5fSRichard Henderson          * This matches Cortex-A710 BROADCASTMTE input being LOW.
22046f4e1405SRichard Henderson          */
22057134cb07SRichard Henderson         if (cpu->tag_memory == NULL) {
22066f4e1405SRichard Henderson             cpu->isar.id_aa64pfr1 =
2207cd305b5fSRichard Henderson                 FIELD_DP64(cpu->isar.id_aa64pfr1, ID_AA64PFR1, MTE, 1);
22086f4e1405SRichard Henderson         }
22096f4e1405SRichard Henderson #endif
22107134cb07SRichard Henderson     }
22116f4e1405SRichard Henderson 
22122daf518dSPeter Maydell     if (tcg_enabled()) {
22132daf518dSPeter Maydell         /*
22147d8c283eSPeter Maydell          * Don't report some architectural features in the ID registers
22157d8c283eSPeter Maydell          * where TCG does not yet implement it (not even a minimal
22167d8c283eSPeter Maydell          * stub version). This avoids guests falling over when they
22177d8c283eSPeter Maydell          * try to access the non-existent system registers for them.
22182daf518dSPeter Maydell          */
22197d8c283eSPeter Maydell         /* FEAT_SPE (Statistical Profiling Extension) */
22202daf518dSPeter Maydell         cpu->isar.id_aa64dfr0 =
22212daf518dSPeter Maydell             FIELD_DP64(cpu->isar.id_aa64dfr0, ID_AA64DFR0, PMSVER, 0);
22223d5f45ecSRichard Henderson         /* FEAT_TRBE (Trace Buffer Extension) */
22233d5f45ecSRichard Henderson         cpu->isar.id_aa64dfr0 =
22243d5f45ecSRichard Henderson             FIELD_DP64(cpu->isar.id_aa64dfr0, ID_AA64DFR0, TRACEBUFFER, 0);
22257d8c283eSPeter Maydell         /* FEAT_TRF (Self-hosted Trace Extension) */
22267d8c283eSPeter Maydell         cpu->isar.id_aa64dfr0 =
22277d8c283eSPeter Maydell             FIELD_DP64(cpu->isar.id_aa64dfr0, ID_AA64DFR0, TRACEFILT, 0);
22287d8c283eSPeter Maydell         cpu->isar.id_dfr0 =
22297d8c283eSPeter Maydell             FIELD_DP32(cpu->isar.id_dfr0, ID_DFR0, TRACEFILT, 0);
22307d8c283eSPeter Maydell         /* Trace Macrocell system register access */
22317d8c283eSPeter Maydell         cpu->isar.id_aa64dfr0 =
22327d8c283eSPeter Maydell             FIELD_DP64(cpu->isar.id_aa64dfr0, ID_AA64DFR0, TRACEVER, 0);
22337d8c283eSPeter Maydell         cpu->isar.id_dfr0 =
22347d8c283eSPeter Maydell             FIELD_DP32(cpu->isar.id_dfr0, ID_DFR0, COPTRC, 0);
22357d8c283eSPeter Maydell         /* Memory mapped trace */
22367d8c283eSPeter Maydell         cpu->isar.id_dfr0 =
22377d8c283eSPeter Maydell             FIELD_DP32(cpu->isar.id_dfr0, ID_DFR0, MMAPTRC, 0);
22387d8c283eSPeter Maydell         /* FEAT_AMU (Activity Monitors Extension) */
22397d8c283eSPeter Maydell         cpu->isar.id_aa64pfr0 =
22407d8c283eSPeter Maydell             FIELD_DP64(cpu->isar.id_aa64pfr0, ID_AA64PFR0, AMU, 0);
22417d8c283eSPeter Maydell         cpu->isar.id_pfr0 =
22427d8c283eSPeter Maydell             FIELD_DP32(cpu->isar.id_pfr0, ID_PFR0, AMU, 0);
22437d8c283eSPeter Maydell         /* FEAT_MPAM (Memory Partitioning and Monitoring Extension) */
22447d8c283eSPeter Maydell         cpu->isar.id_aa64pfr0 =
22457d8c283eSPeter Maydell             FIELD_DP64(cpu->isar.id_aa64pfr0, ID_AA64PFR0, MPAM, 0);
22462daf518dSPeter Maydell     }
22472daf518dSPeter Maydell 
2248f50cd314SPeter Maydell     /* MPU can be configured out of a PMSA CPU either by setting has-mpu
2249f50cd314SPeter Maydell      * to false or by setting pmsav7-dregion to 0.
2250f50cd314SPeter Maydell      */
2251761c4642STobias Röhmel     if (!cpu->has_mpu || cpu->pmsav7_dregion == 0) {
2252f50cd314SPeter Maydell         cpu->has_mpu = false;
2253761c4642STobias Röhmel         cpu->pmsav7_dregion = 0;
2254761c4642STobias Röhmel         cpu->pmsav8r_hdregion = 0;
2255fcf5ef2aSThomas Huth     }
2256fcf5ef2aSThomas Huth 
2257452a0955SPeter Maydell     if (arm_feature(env, ARM_FEATURE_PMSA) &&
2258fcf5ef2aSThomas Huth         arm_feature(env, ARM_FEATURE_V7)) {
2259fcf5ef2aSThomas Huth         uint32_t nr = cpu->pmsav7_dregion;
2260fcf5ef2aSThomas Huth 
2261fcf5ef2aSThomas Huth         if (nr > 0xff) {
2262fcf5ef2aSThomas Huth             error_setg(errp, "PMSAv7 MPU #regions invalid %" PRIu32, nr);
2263fcf5ef2aSThomas Huth             return;
2264fcf5ef2aSThomas Huth         }
2265fcf5ef2aSThomas Huth 
2266fcf5ef2aSThomas Huth         if (nr) {
22670e1a46bbSPeter Maydell             if (arm_feature(env, ARM_FEATURE_V8)) {
22680e1a46bbSPeter Maydell                 /* PMSAv8 */
226962c58ee0SPeter Maydell                 env->pmsav8.rbar[M_REG_NS] = g_new0(uint32_t, nr);
227062c58ee0SPeter Maydell                 env->pmsav8.rlar[M_REG_NS] = g_new0(uint32_t, nr);
227162c58ee0SPeter Maydell                 if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
227262c58ee0SPeter Maydell                     env->pmsav8.rbar[M_REG_S] = g_new0(uint32_t, nr);
227362c58ee0SPeter Maydell                     env->pmsav8.rlar[M_REG_S] = g_new0(uint32_t, nr);
227462c58ee0SPeter Maydell                 }
22750e1a46bbSPeter Maydell             } else {
2276fcf5ef2aSThomas Huth                 env->pmsav7.drbar = g_new0(uint32_t, nr);
2277fcf5ef2aSThomas Huth                 env->pmsav7.drsr = g_new0(uint32_t, nr);
2278fcf5ef2aSThomas Huth                 env->pmsav7.dracr = g_new0(uint32_t, nr);
2279fcf5ef2aSThomas Huth             }
2280fcf5ef2aSThomas Huth         }
2281761c4642STobias Röhmel 
2282761c4642STobias Röhmel         if (cpu->pmsav8r_hdregion > 0xff) {
2283761c4642STobias Röhmel             error_setg(errp, "PMSAv8 MPU EL2 #regions invalid %" PRIu32,
2284761c4642STobias Röhmel                               cpu->pmsav8r_hdregion);
2285761c4642STobias Röhmel             return;
2286761c4642STobias Röhmel         }
2287761c4642STobias Röhmel 
2288761c4642STobias Röhmel         if (cpu->pmsav8r_hdregion) {
2289761c4642STobias Röhmel             env->pmsav8.hprbar = g_new0(uint32_t,
2290761c4642STobias Röhmel                                         cpu->pmsav8r_hdregion);
2291761c4642STobias Röhmel             env->pmsav8.hprlar = g_new0(uint32_t,
2292761c4642STobias Röhmel                                         cpu->pmsav8r_hdregion);
2293761c4642STobias Röhmel         }
22940e1a46bbSPeter Maydell     }
2295fcf5ef2aSThomas Huth 
22969901c576SPeter Maydell     if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
22979901c576SPeter Maydell         uint32_t nr = cpu->sau_sregion;
22989901c576SPeter Maydell 
22999901c576SPeter Maydell         if (nr > 0xff) {
23009901c576SPeter Maydell             error_setg(errp, "v8M SAU #regions invalid %" PRIu32, nr);
23019901c576SPeter Maydell             return;
23029901c576SPeter Maydell         }
23039901c576SPeter Maydell 
23049901c576SPeter Maydell         if (nr) {
23059901c576SPeter Maydell             env->sau.rbar = g_new0(uint32_t, nr);
23069901c576SPeter Maydell             env->sau.rlar = g_new0(uint32_t, nr);
23079901c576SPeter Maydell         }
23089901c576SPeter Maydell     }
23099901c576SPeter Maydell 
231091db4642SCédric Le Goater     if (arm_feature(env, ARM_FEATURE_EL3)) {
231191db4642SCédric Le Goater         set_feature(env, ARM_FEATURE_VBAR);
231291db4642SCédric Le Goater     }
231391db4642SCédric Le Goater 
2314f6fc36deSJean-Philippe Brucker #ifndef CONFIG_USER_ONLY
2315f6fc36deSJean-Philippe Brucker     if (tcg_enabled() && cpu_isar_feature(aa64_rme, cpu)) {
2316f6fc36deSJean-Philippe Brucker         arm_register_el_change_hook(cpu, &gt_rme_post_el_change, 0);
2317f6fc36deSJean-Philippe Brucker     }
2318f6fc36deSJean-Philippe Brucker #endif
2319f6fc36deSJean-Philippe Brucker 
2320fcf5ef2aSThomas Huth     register_cp_regs_for_features(cpu);
2321fcf5ef2aSThomas Huth     arm_cpu_register_gdb_regs_for_features(cpu);
2322fcf5ef2aSThomas Huth 
2323fcf5ef2aSThomas Huth     init_cpreg_list(cpu);
2324fcf5ef2aSThomas Huth 
2325fcf5ef2aSThomas Huth #ifndef CONFIG_USER_ONLY
2326cc7d44c2SLike Xu     MachineState *ms = MACHINE(qdev_get_machine());
2327cc7d44c2SLike Xu     unsigned int smp_cpus = ms->smp.cpus;
23288bce44a2SRichard Henderson     bool has_secure = cpu->has_el3 || arm_feature(env, ARM_FEATURE_M_SECURITY);
2329cc7d44c2SLike Xu 
23308bce44a2SRichard Henderson     /*
23318bce44a2SRichard Henderson      * We must set cs->num_ases to the final value before
23328bce44a2SRichard Henderson      * the first call to cpu_address_space_init.
23338bce44a2SRichard Henderson      */
23348bce44a2SRichard Henderson     if (cpu->tag_memory != NULL) {
23358bce44a2SRichard Henderson         cs->num_ases = 3 + has_secure;
23368bce44a2SRichard Henderson     } else {
23378bce44a2SRichard Henderson         cs->num_ases = 1 + has_secure;
23388bce44a2SRichard Henderson     }
23391d2091bcSPeter Maydell 
23408bce44a2SRichard Henderson     if (has_secure) {
2341fcf5ef2aSThomas Huth         if (!cpu->secure_memory) {
2342fcf5ef2aSThomas Huth             cpu->secure_memory = cs->memory;
2343fcf5ef2aSThomas Huth         }
234480ceb07aSPeter Xu         cpu_address_space_init(cs, ARMASIdx_S, "cpu-secure-memory",
234580ceb07aSPeter Xu                                cpu->secure_memory);
2346fcf5ef2aSThomas Huth     }
23478bce44a2SRichard Henderson 
23488bce44a2SRichard Henderson     if (cpu->tag_memory != NULL) {
23498bce44a2SRichard Henderson         cpu_address_space_init(cs, ARMASIdx_TagNS, "cpu-tag-memory",
23508bce44a2SRichard Henderson                                cpu->tag_memory);
23518bce44a2SRichard Henderson         if (has_secure) {
23528bce44a2SRichard Henderson             cpu_address_space_init(cs, ARMASIdx_TagS, "cpu-tag-memory",
23538bce44a2SRichard Henderson                                    cpu->secure_tag_memory);
23548bce44a2SRichard Henderson         }
23558bce44a2SRichard Henderson     }
23568bce44a2SRichard Henderson 
235780ceb07aSPeter Xu     cpu_address_space_init(cs, ARMASIdx_NS, "cpu-memory", cs->memory);
2358f9a69711SAlistair Francis 
2359f9a69711SAlistair Francis     /* No core_count specified, default to smp_cpus. */
2360f9a69711SAlistair Francis     if (cpu->core_count == -1) {
2361f9a69711SAlistair Francis         cpu->core_count = smp_cpus;
2362f9a69711SAlistair Francis     }
2363fcf5ef2aSThomas Huth #endif
2364fcf5ef2aSThomas Huth 
2365a4157b80SRichard Henderson     if (tcg_enabled()) {
2366a4157b80SRichard Henderson         int dcz_blocklen = 4 << cpu->dcz_blocksize;
2367a4157b80SRichard Henderson 
2368a4157b80SRichard Henderson         /*
2369a4157b80SRichard Henderson          * We only support DCZ blocklen that fits on one page.
2370a4157b80SRichard Henderson          *
2371a4157b80SRichard Henderson          * Architectually this is always true.  However TARGET_PAGE_SIZE
2372a4157b80SRichard Henderson          * is variable and, for compatibility with -machine virt-2.7,
2373a4157b80SRichard Henderson          * is only 1KiB, as an artifact of legacy ARMv5 subpage support.
2374a4157b80SRichard Henderson          * But even then, while the largest architectural DCZ blocklen
2375a4157b80SRichard Henderson          * is 2KiB, no cpu actually uses such a large blocklen.
2376a4157b80SRichard Henderson          */
2377a4157b80SRichard Henderson         assert(dcz_blocklen <= TARGET_PAGE_SIZE);
2378a4157b80SRichard Henderson 
2379a4157b80SRichard Henderson         /*
2380a4157b80SRichard Henderson          * We only support DCZ blocksize >= 2*TAG_GRANULE, which is to say
2381a4157b80SRichard Henderson          * both nibbles of each byte storing tag data may be written at once.
2382a4157b80SRichard Henderson          * Since TAG_GRANULE is 16, this means that blocklen must be >= 32.
2383a4157b80SRichard Henderson          */
2384a4157b80SRichard Henderson         if (cpu_isar_feature(aa64_mte, cpu)) {
2385a4157b80SRichard Henderson             assert(dcz_blocklen >= 2 * TAG_GRANULE);
2386a4157b80SRichard Henderson         }
2387a4157b80SRichard Henderson     }
2388a4157b80SRichard Henderson 
2389fcf5ef2aSThomas Huth     qemu_init_vcpu(cs);
2390fcf5ef2aSThomas Huth     cpu_reset(cs);
2391fcf5ef2aSThomas Huth 
2392fcf5ef2aSThomas Huth     acc->parent_realize(dev, errp);
2393fcf5ef2aSThomas Huth }
2394fcf5ef2aSThomas Huth 
2395fcf5ef2aSThomas Huth static ObjectClass *arm_cpu_class_by_name(const char *cpu_model)
2396fcf5ef2aSThomas Huth {
2397fcf5ef2aSThomas Huth     ObjectClass *oc;
2398fcf5ef2aSThomas Huth     char *typename;
2399fcf5ef2aSThomas Huth     char **cpuname;
2400a0032cc5SPeter Maydell     const char *cpunamestr;
2401fcf5ef2aSThomas Huth 
2402fcf5ef2aSThomas Huth     cpuname = g_strsplit(cpu_model, ",", 1);
2403a0032cc5SPeter Maydell     cpunamestr = cpuname[0];
2404a0032cc5SPeter Maydell #ifdef CONFIG_USER_ONLY
2405a0032cc5SPeter Maydell     /* For backwards compatibility usermode emulation allows "-cpu any",
2406a0032cc5SPeter Maydell      * which has the same semantics as "-cpu max".
2407a0032cc5SPeter Maydell      */
2408a0032cc5SPeter Maydell     if (!strcmp(cpunamestr, "any")) {
2409a0032cc5SPeter Maydell         cpunamestr = "max";
2410a0032cc5SPeter Maydell     }
2411a0032cc5SPeter Maydell #endif
2412a0032cc5SPeter Maydell     typename = g_strdup_printf(ARM_CPU_TYPE_NAME("%s"), cpunamestr);
2413fcf5ef2aSThomas Huth     oc = object_class_by_name(typename);
2414fcf5ef2aSThomas Huth     g_strfreev(cpuname);
2415fcf5ef2aSThomas Huth     g_free(typename);
2416d5be19f5SPhilippe Mathieu-Daudé 
2417fcf5ef2aSThomas Huth     return oc;
2418fcf5ef2aSThomas Huth }
2419fcf5ef2aSThomas Huth 
2420fcf5ef2aSThomas Huth static Property arm_cpu_properties[] = {
2421e544f800SPhilippe Mathieu-Daudé     DEFINE_PROP_UINT64("midr", ARMCPU, midr, 0),
2422fcf5ef2aSThomas Huth     DEFINE_PROP_UINT64("mp-affinity", ARMCPU,
2423fcf5ef2aSThomas Huth                         mp_affinity, ARM64_AFFINITY_INVALID),
242415f8b142SIgor Mammedov     DEFINE_PROP_INT32("node-id", ARMCPU, node_id, CPU_UNSET_NUMA_NODE_ID),
2425f9a69711SAlistair Francis     DEFINE_PROP_INT32("core-count", ARMCPU, core_count, -1),
2426fcf5ef2aSThomas Huth     DEFINE_PROP_END_OF_LIST()
2427fcf5ef2aSThomas Huth };
2428fcf5ef2aSThomas Huth 
2429a6506838SAkihiko Odaki static const gchar *arm_gdb_arch_name(CPUState *cs)
2430fcf5ef2aSThomas Huth {
2431fcf5ef2aSThomas Huth     ARMCPU *cpu = ARM_CPU(cs);
2432fcf5ef2aSThomas Huth     CPUARMState *env = &cpu->env;
2433fcf5ef2aSThomas Huth 
2434fcf5ef2aSThomas Huth     if (arm_feature(env, ARM_FEATURE_IWMMXT)) {
2435a6506838SAkihiko Odaki         return "iwmmxt";
2436fcf5ef2aSThomas Huth     }
2437a6506838SAkihiko Odaki     return "arm";
2438fcf5ef2aSThomas Huth }
2439fcf5ef2aSThomas Huth 
24408b80bd28SPhilippe Mathieu-Daudé #ifndef CONFIG_USER_ONLY
24418b80bd28SPhilippe Mathieu-Daudé #include "hw/core/sysemu-cpu-ops.h"
24428b80bd28SPhilippe Mathieu-Daudé 
24438b80bd28SPhilippe Mathieu-Daudé static const struct SysemuCPUOps arm_sysemu_ops = {
244408928c6dSPhilippe Mathieu-Daudé     .get_phys_page_attrs_debug = arm_cpu_get_phys_page_attrs_debug,
2445faf39e82SPhilippe Mathieu-Daudé     .asidx_from_attrs = arm_asidx_from_attrs,
2446715e3c1aSPhilippe Mathieu-Daudé     .write_elf32_note = arm_cpu_write_elf32_note,
2447715e3c1aSPhilippe Mathieu-Daudé     .write_elf64_note = arm_cpu_write_elf64_note,
2448da383e02SPhilippe Mathieu-Daudé     .virtio_is_big_endian = arm_cpu_virtio_is_big_endian,
2449feece4d0SPhilippe Mathieu-Daudé     .legacy_vmsd = &vmstate_arm_cpu,
24508b80bd28SPhilippe Mathieu-Daudé };
24518b80bd28SPhilippe Mathieu-Daudé #endif
24528b80bd28SPhilippe Mathieu-Daudé 
245378271684SClaudio Fontana #ifdef CONFIG_TCG
245411906557SRichard Henderson static const struct TCGCPUOps arm_tcg_ops = {
245578271684SClaudio Fontana     .initialize = arm_translate_init,
245678271684SClaudio Fontana     .synchronize_from_tb = arm_cpu_synchronize_from_tb,
245778271684SClaudio Fontana     .debug_excp_handler = arm_debug_excp_handler,
245856c6c98dSRichard Henderson     .restore_state_to_opc = arm_restore_state_to_opc,
245978271684SClaudio Fontana 
24609b12b6b4SRichard Henderson #ifdef CONFIG_USER_ONLY
24619b12b6b4SRichard Henderson     .record_sigsegv = arm_cpu_record_sigsegv,
246239a099caSRichard Henderson     .record_sigbus = arm_cpu_record_sigbus,
24639b12b6b4SRichard Henderson #else
24649b12b6b4SRichard Henderson     .tlb_fill = arm_cpu_tlb_fill,
2465083afd18SPhilippe Mathieu-Daudé     .cpu_exec_interrupt = arm_cpu_exec_interrupt,
246678271684SClaudio Fontana     .do_interrupt = arm_cpu_do_interrupt,
246778271684SClaudio Fontana     .do_transaction_failed = arm_cpu_do_transaction_failed,
246878271684SClaudio Fontana     .do_unaligned_access = arm_cpu_do_unaligned_access,
246978271684SClaudio Fontana     .adjust_watchpoint_address = arm_adjust_watchpoint_address,
247078271684SClaudio Fontana     .debug_check_watchpoint = arm_debug_check_watchpoint,
2471b00d86bcSRichard Henderson     .debug_check_breakpoint = arm_debug_check_breakpoint,
247278271684SClaudio Fontana #endif /* !CONFIG_USER_ONLY */
247378271684SClaudio Fontana };
247478271684SClaudio Fontana #endif /* CONFIG_TCG */
247578271684SClaudio Fontana 
2476fcf5ef2aSThomas Huth static void arm_cpu_class_init(ObjectClass *oc, void *data)
2477fcf5ef2aSThomas Huth {
2478fcf5ef2aSThomas Huth     ARMCPUClass *acc = ARM_CPU_CLASS(oc);
2479fcf5ef2aSThomas Huth     CPUClass *cc = CPU_CLASS(acc);
2480fcf5ef2aSThomas Huth     DeviceClass *dc = DEVICE_CLASS(oc);
24819130cadeSPeter Maydell     ResettableClass *rc = RESETTABLE_CLASS(oc);
2482fcf5ef2aSThomas Huth 
2483bf853881SPhilippe Mathieu-Daudé     device_class_set_parent_realize(dc, arm_cpu_realizefn,
2484bf853881SPhilippe Mathieu-Daudé                                     &acc->parent_realize);
2485fcf5ef2aSThomas Huth 
24864f67d30bSMarc-André Lureau     device_class_set_props(dc, arm_cpu_properties);
24879130cadeSPeter Maydell 
24889130cadeSPeter Maydell     resettable_class_set_parent_phases(rc, NULL, arm_cpu_reset_hold, NULL,
24899130cadeSPeter Maydell                                        &acc->parent_phases);
2490fcf5ef2aSThomas Huth 
2491fcf5ef2aSThomas Huth     cc->class_by_name = arm_cpu_class_by_name;
2492fcf5ef2aSThomas Huth     cc->has_work = arm_cpu_has_work;
2493fcf5ef2aSThomas Huth     cc->dump_state = arm_cpu_dump_state;
2494fcf5ef2aSThomas Huth     cc->set_pc = arm_cpu_set_pc;
2495e4fdf9dfSRichard Henderson     cc->get_pc = arm_cpu_get_pc;
2496fcf5ef2aSThomas Huth     cc->gdb_read_register = arm_cpu_gdb_read_register;
2497fcf5ef2aSThomas Huth     cc->gdb_write_register = arm_cpu_gdb_write_register;
24987350d553SRichard Henderson #ifndef CONFIG_USER_ONLY
24998b80bd28SPhilippe Mathieu-Daudé     cc->sysemu_ops = &arm_sysemu_ops;
2500fcf5ef2aSThomas Huth #endif
2501fcf5ef2aSThomas Huth     cc->gdb_num_core_regs = 26;
2502fcf5ef2aSThomas Huth     cc->gdb_arch_name = arm_gdb_arch_name;
2503200bf5b7SAbdallah Bouassida     cc->gdb_get_dynamic_xml = arm_gdb_get_dynamic_xml;
2504fcf5ef2aSThomas Huth     cc->gdb_stop_before_watchpoint = true;
2505fcf5ef2aSThomas Huth     cc->disas_set_info = arm_disas_set_info;
250678271684SClaudio Fontana 
250774d7fc7fSRichard Henderson #ifdef CONFIG_TCG
250878271684SClaudio Fontana     cc->tcg_ops = &arm_tcg_ops;
2509cbc183d2SClaudio Fontana #endif /* CONFIG_TCG */
2510fcf5ef2aSThomas Huth }
2511fcf5ef2aSThomas Huth 
251251e5ef45SMarc-André Lureau static void arm_cpu_instance_init(Object *obj)
251351e5ef45SMarc-André Lureau {
251451e5ef45SMarc-André Lureau     ARMCPUClass *acc = ARM_CPU_GET_CLASS(obj);
251551e5ef45SMarc-André Lureau 
251651e5ef45SMarc-André Lureau     acc->info->initfn(obj);
251751e5ef45SMarc-André Lureau     arm_cpu_post_init(obj);
251851e5ef45SMarc-André Lureau }
251951e5ef45SMarc-André Lureau 
252051e5ef45SMarc-André Lureau static void cpu_register_class_init(ObjectClass *oc, void *data)
252151e5ef45SMarc-André Lureau {
252251e5ef45SMarc-André Lureau     ARMCPUClass *acc = ARM_CPU_CLASS(oc);
252348de6462SAkihiko Odaki     CPUClass *cc = CPU_CLASS(acc);
252451e5ef45SMarc-André Lureau 
252551e5ef45SMarc-André Lureau     acc->info = data;
252648de6462SAkihiko Odaki     cc->gdb_core_xml_file = "arm-core.xml";
252751e5ef45SMarc-André Lureau }
252851e5ef45SMarc-André Lureau 
252937bcf244SThomas Huth void arm_cpu_register(const ARMCPUInfo *info)
2530fcf5ef2aSThomas Huth {
2531fcf5ef2aSThomas Huth     TypeInfo type_info = {
2532fcf5ef2aSThomas Huth         .parent = TYPE_ARM_CPU,
253351e5ef45SMarc-André Lureau         .instance_init = arm_cpu_instance_init,
253451e5ef45SMarc-André Lureau         .class_init = info->class_init ?: cpu_register_class_init,
253551e5ef45SMarc-André Lureau         .class_data = (void *)info,
2536fcf5ef2aSThomas Huth     };
2537fcf5ef2aSThomas Huth 
2538fcf5ef2aSThomas Huth     type_info.name = g_strdup_printf("%s-" TYPE_ARM_CPU, info->name);
2539fcf5ef2aSThomas Huth     type_register(&type_info);
2540fcf5ef2aSThomas Huth     g_free((void *)type_info.name);
2541fcf5ef2aSThomas Huth }
2542fcf5ef2aSThomas Huth 
2543fcf5ef2aSThomas Huth static const TypeInfo arm_cpu_type_info = {
2544fcf5ef2aSThomas Huth     .name = TYPE_ARM_CPU,
2545fcf5ef2aSThomas Huth     .parent = TYPE_CPU,
2546fcf5ef2aSThomas Huth     .instance_size = sizeof(ARMCPU),
2547d03087bdSRichard Henderson     .instance_align = __alignof__(ARMCPU),
2548fcf5ef2aSThomas Huth     .instance_init = arm_cpu_initfn,
2549fcf5ef2aSThomas Huth     .instance_finalize = arm_cpu_finalizefn,
2550fcf5ef2aSThomas Huth     .abstract = true,
2551fcf5ef2aSThomas Huth     .class_size = sizeof(ARMCPUClass),
2552fcf5ef2aSThomas Huth     .class_init = arm_cpu_class_init,
2553fcf5ef2aSThomas Huth };
2554fcf5ef2aSThomas Huth 
2555fcf5ef2aSThomas Huth static void arm_cpu_register_types(void)
2556fcf5ef2aSThomas Huth {
2557fcf5ef2aSThomas Huth     type_register_static(&arm_cpu_type_info);
2558fcf5ef2aSThomas Huth }
2559fcf5ef2aSThomas Huth 
2560fcf5ef2aSThomas Huth type_init(arm_cpu_register_types)
2561