qemu/target-arm/cpu64.c
<<
>>
Prefs
   1/*
   2 * QEMU AArch64 CPU
   3 *
   4 * Copyright (c) 2013 Linaro Ltd
   5 *
   6 * This program is free software; you can redistribute it and/or
   7 * modify it under the terms of the GNU General Public License
   8 * as published by the Free Software Foundation; either version 2
   9 * of the License, or (at your option) any later version.
  10 *
  11 * This program is distributed in the hope that it will be useful,
  12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14 * GNU General Public License for more details.
  15 *
  16 * You should have received a copy of the GNU General Public License
  17 * along with this program; if not, see
  18 * <http://www.gnu.org/licenses/gpl-2.0.html>
  19 */
  20
  21#include "qemu/osdep.h"
  22#include "qapi/error.h"
  23#include "cpu.h"
  24#include "qemu-common.h"
  25#if !defined(CONFIG_USER_ONLY)
  26#include "hw/loader.h"
  27#endif
  28#include "hw/arm/arm.h"
  29#include "sysemu/sysemu.h"
  30#include "sysemu/kvm.h"
  31
  32static inline void set_feature(CPUARMState *env, int feature)
  33{
  34    env->features |= 1ULL << feature;
  35}
  36
  37static inline void unset_feature(CPUARMState *env, int feature)
  38{
  39    env->features &= ~(1ULL << feature);
  40}
  41
  42#ifndef CONFIG_USER_ONLY
  43static uint64_t a57_a53_l2ctlr_read(CPUARMState *env, const ARMCPRegInfo *ri)
  44{
  45    /* Number of processors is in [25:24]; otherwise we RAZ */
  46    return (smp_cpus - 1) << 24;
  47}
  48#endif
  49
  50static const ARMCPRegInfo cortex_a57_a53_cp_reginfo[] = {
  51#ifndef CONFIG_USER_ONLY
  52    { .name = "L2CTLR_EL1", .state = ARM_CP_STATE_AA64,
  53      .opc0 = 3, .opc1 = 1, .crn = 11, .crm = 0, .opc2 = 2,
  54      .access = PL1_RW, .readfn = a57_a53_l2ctlr_read,
  55      .writefn = arm_cp_write_ignore },
  56    { .name = "L2CTLR",
  57      .cp = 15, .opc1 = 1, .crn = 9, .crm = 0, .opc2 = 2,
  58      .access = PL1_RW, .readfn = a57_a53_l2ctlr_read,
  59      .writefn = arm_cp_write_ignore },
  60#endif
  61    { .name = "L2ECTLR_EL1", .state = ARM_CP_STATE_AA64,
  62      .opc0 = 3, .opc1 = 1, .crn = 11, .crm = 0, .opc2 = 3,
  63      .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
  64    { .name = "L2ECTLR",
  65      .cp = 15, .opc1 = 1, .crn = 9, .crm = 0, .opc2 = 3,
  66      .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
  67    { .name = "L2ACTLR", .state = ARM_CP_STATE_BOTH,
  68      .opc0 = 3, .opc1 = 1, .crn = 15, .crm = 0, .opc2 = 0,
  69      .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
  70    { .name = "CPUACTLR_EL1", .state = ARM_CP_STATE_AA64,
  71      .opc0 = 3, .opc1 = 1, .crn = 15, .crm = 2, .opc2 = 0,
  72      .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
  73    { .name = "CPUACTLR",
  74      .cp = 15, .opc1 = 0, .crm = 15,
  75      .access = PL1_RW, .type = ARM_CP_CONST | ARM_CP_64BIT, .resetvalue = 0 },
  76    { .name = "CPUECTLR_EL1", .state = ARM_CP_STATE_AA64,
  77      .opc0 = 3, .opc1 = 1, .crn = 15, .crm = 2, .opc2 = 1,
  78      .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
  79    { .name = "CPUECTLR",
  80      .cp = 15, .opc1 = 1, .crm = 15,
  81      .access = PL1_RW, .type = ARM_CP_CONST | ARM_CP_64BIT, .resetvalue = 0 },
  82    { .name = "CPUMERRSR_EL1", .state = ARM_CP_STATE_AA64,
  83      .opc0 = 3, .opc1 = 1, .crn = 15, .crm = 2, .opc2 = 2,
  84      .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
  85    { .name = "CPUMERRSR",
  86      .cp = 15, .opc1 = 2, .crm = 15,
  87      .access = PL1_RW, .type = ARM_CP_CONST | ARM_CP_64BIT, .resetvalue = 0 },
  88    { .name = "L2MERRSR_EL1", .state = ARM_CP_STATE_AA64,
  89      .opc0 = 3, .opc1 = 1, .crn = 15, .crm = 2, .opc2 = 3,
  90      .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 },
  91    { .name = "L2MERRSR",
  92      .cp = 15, .opc1 = 3, .crm = 15,
  93      .access = PL1_RW, .type = ARM_CP_CONST | ARM_CP_64BIT, .resetvalue = 0 },
  94    REGINFO_SENTINEL
  95};
  96
  97static void aarch64_a57_initfn(Object *obj)
  98{
  99    ARMCPU *cpu = ARM_CPU(obj);
 100
 101    cpu->dtb_compatible = "arm,cortex-a57";
 102    set_feature(&cpu->env, ARM_FEATURE_V8);
 103    set_feature(&cpu->env, ARM_FEATURE_VFP4);
 104    set_feature(&cpu->env, ARM_FEATURE_NEON);
 105    set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER);
 106    set_feature(&cpu->env, ARM_FEATURE_AARCH64);
 107    set_feature(&cpu->env, ARM_FEATURE_MPIDR);
 108    set_feature(&cpu->env, ARM_FEATURE_CBAR_RO);
 109    set_feature(&cpu->env, ARM_FEATURE_V8_AES);
 110    set_feature(&cpu->env, ARM_FEATURE_V8_SHA1);
 111    set_feature(&cpu->env, ARM_FEATURE_V8_SHA256);
 112    set_feature(&cpu->env, ARM_FEATURE_V8_PMULL);
 113    set_feature(&cpu->env, ARM_FEATURE_CRC);
 114    set_feature(&cpu->env, ARM_FEATURE_EL2);
 115    set_feature(&cpu->env, ARM_FEATURE_EL3);
 116    set_feature(&cpu->env, ARM_FEATURE_AUXCR);
 117    cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A57;
 118    cpu->midr = 0x411fd070;
 119    cpu->revidr = 0x00000000;
 120    cpu->reset_fpsid = 0x41034070;
 121    cpu->mvfr0 = 0x10110222;
 122    cpu->mvfr1 = 0x12111111;
 123    cpu->mvfr2 = 0x00000043;
 124    cpu->ctr = 0x8444c004;
 125    cpu->reset_sctlr = 0x00c50838;
 126    cpu->id_pfr0 = 0x00000131;
 127    cpu->id_pfr1 = 0x00011011;
 128    cpu->id_dfr0 = 0x03010066;
 129    cpu->id_afr0 = 0x00000000;
 130    cpu->id_mmfr0 = 0x10101105;
 131    cpu->id_mmfr1 = 0x40000000;
 132    cpu->id_mmfr2 = 0x01260000;
 133    cpu->id_mmfr3 = 0x02102211;
 134    cpu->id_isar0 = 0x02101110;
 135    cpu->id_isar1 = 0x13112111;
 136    cpu->id_isar2 = 0x21232042;
 137    cpu->id_isar3 = 0x01112131;
 138    cpu->id_isar4 = 0x00011142;
 139    cpu->id_isar5 = 0x00011121;
 140    cpu->id_aa64pfr0 = 0x00002222;
 141    cpu->id_aa64dfr0 = 0x10305106;
 142    cpu->pmceid0 = 0x00000000;
 143    cpu->pmceid1 = 0x00000000;
 144    cpu->id_aa64isar0 = 0x00011120;
 145    cpu->id_aa64mmfr0 = 0x00001124;
 146    cpu->dbgdidr = 0x3516d000;
 147    cpu->clidr = 0x0a200023;
 148    cpu->ccsidr[0] = 0x701fe00a; /* 32KB L1 dcache */
 149    cpu->ccsidr[1] = 0x201fe012; /* 48KB L1 icache */
 150    cpu->ccsidr[2] = 0x70ffe07a; /* 2048KB L2 cache */
 151    cpu->dcz_blocksize = 4; /* 64 bytes */
 152    define_arm_cp_regs(cpu, cortex_a57_a53_cp_reginfo);
 153}
 154
 155static void aarch64_a53_initfn(Object *obj)
 156{
 157    ARMCPU *cpu = ARM_CPU(obj);
 158
 159    cpu->dtb_compatible = "arm,cortex-a53";
 160    set_feature(&cpu->env, ARM_FEATURE_V8);
 161    set_feature(&cpu->env, ARM_FEATURE_VFP4);
 162    set_feature(&cpu->env, ARM_FEATURE_NEON);
 163    set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER);
 164    set_feature(&cpu->env, ARM_FEATURE_AARCH64);
 165    set_feature(&cpu->env, ARM_FEATURE_MPIDR);
 166    set_feature(&cpu->env, ARM_FEATURE_CBAR_RO);
 167    set_feature(&cpu->env, ARM_FEATURE_V8_AES);
 168    set_feature(&cpu->env, ARM_FEATURE_V8_SHA1);
 169    set_feature(&cpu->env, ARM_FEATURE_V8_SHA256);
 170    set_feature(&cpu->env, ARM_FEATURE_V8_PMULL);
 171    set_feature(&cpu->env, ARM_FEATURE_CRC);
 172    set_feature(&cpu->env, ARM_FEATURE_EL2);
 173    set_feature(&cpu->env, ARM_FEATURE_EL3);
 174    set_feature(&cpu->env, ARM_FEATURE_AUXCR);
 175    cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A53;
 176    cpu->midr = 0x410fd034;
 177    cpu->revidr = 0x00000000;
 178    cpu->reset_fpsid = 0x41034070;
 179    cpu->mvfr0 = 0x10110222;
 180    cpu->mvfr1 = 0x12111111;
 181    cpu->mvfr2 = 0x00000043;
 182    cpu->ctr = 0x84448004; /* L1Ip = VIPT */
 183    cpu->reset_sctlr = 0x00c50838;
 184    cpu->id_pfr0 = 0x00000131;
 185    cpu->id_pfr1 = 0x00011011;
 186    cpu->id_dfr0 = 0x03010066;
 187    cpu->id_afr0 = 0x00000000;
 188    cpu->id_mmfr0 = 0x10101105;
 189    cpu->id_mmfr1 = 0x40000000;
 190    cpu->id_mmfr2 = 0x01260000;
 191    cpu->id_mmfr3 = 0x02102211;
 192    cpu->id_isar0 = 0x02101110;
 193    cpu->id_isar1 = 0x13112111;
 194    cpu->id_isar2 = 0x21232042;
 195    cpu->id_isar3 = 0x01112131;
 196    cpu->id_isar4 = 0x00011142;
 197    cpu->id_isar5 = 0x00011121;
 198    cpu->id_aa64pfr0 = 0x00002222;
 199    cpu->id_aa64dfr0 = 0x10305106;
 200    cpu->id_aa64isar0 = 0x00011120;
 201    cpu->id_aa64mmfr0 = 0x00001122; /* 40 bit physical addr */
 202    cpu->dbgdidr = 0x3516d000;
 203    cpu->clidr = 0x0a200023;
 204    cpu->ccsidr[0] = 0x700fe01a; /* 32KB L1 dcache */
 205    cpu->ccsidr[1] = 0x201fe00a; /* 32KB L1 icache */
 206    cpu->ccsidr[2] = 0x707fe07a; /* 1024KB L2 cache */
 207    cpu->dcz_blocksize = 4; /* 64 bytes */
 208    define_arm_cp_regs(cpu, cortex_a57_a53_cp_reginfo);
 209}
 210
 211#ifdef CONFIG_USER_ONLY
 212static void aarch64_any_initfn(Object *obj)
 213{
 214    ARMCPU *cpu = ARM_CPU(obj);
 215
 216    set_feature(&cpu->env, ARM_FEATURE_V8);
 217    set_feature(&cpu->env, ARM_FEATURE_VFP4);
 218    set_feature(&cpu->env, ARM_FEATURE_NEON);
 219    set_feature(&cpu->env, ARM_FEATURE_AARCH64);
 220    set_feature(&cpu->env, ARM_FEATURE_V8_AES);
 221    set_feature(&cpu->env, ARM_FEATURE_V8_SHA1);
 222    set_feature(&cpu->env, ARM_FEATURE_V8_SHA256);
 223    set_feature(&cpu->env, ARM_FEATURE_V8_PMULL);
 224    set_feature(&cpu->env, ARM_FEATURE_CRC);
 225    cpu->ctr = 0x80038003; /* 32 byte I and D cacheline size, VIPT icache */
 226    cpu->dcz_blocksize = 7; /*  512 bytes */
 227}
 228#endif
 229
 230typedef struct ARMCPUInfo {
 231    const char *name;
 232    void (*initfn)(Object *obj);
 233    void (*class_init)(ObjectClass *oc, void *data);
 234} ARMCPUInfo;
 235
 236static const ARMCPUInfo aarch64_cpus[] = {
 237    { .name = "cortex-a57",         .initfn = aarch64_a57_initfn },
 238    { .name = "cortex-a53",         .initfn = aarch64_a53_initfn },
 239#ifdef CONFIG_USER_ONLY
 240    { .name = "any",         .initfn = aarch64_any_initfn },
 241#endif
 242    { .name = NULL }
 243};
 244
 245static bool aarch64_cpu_get_aarch64(Object *obj, Error **errp)
 246{
 247    ARMCPU *cpu = ARM_CPU(obj);
 248
 249    return arm_feature(&cpu->env, ARM_FEATURE_AARCH64);
 250}
 251
 252static void aarch64_cpu_set_aarch64(Object *obj, bool value, Error **errp)
 253{
 254    ARMCPU *cpu = ARM_CPU(obj);
 255
 256    /* At this time, this property is only allowed if KVM is enabled.  This
 257     * restriction allows us to avoid fixing up functionality that assumes a
 258     * uniform execution state like do_interrupt.
 259     */
 260    if (!kvm_enabled()) {
 261        error_setg(errp, "'aarch64' feature cannot be disabled "
 262                         "unless KVM is enabled");
 263        return;
 264    }
 265
 266    if (value == false) {
 267        unset_feature(&cpu->env, ARM_FEATURE_AARCH64);
 268    } else {
 269        set_feature(&cpu->env, ARM_FEATURE_AARCH64);
 270    }
 271}
 272
 273static void aarch64_cpu_initfn(Object *obj)
 274{
 275    object_property_add_bool(obj, "aarch64", aarch64_cpu_get_aarch64,
 276                             aarch64_cpu_set_aarch64, NULL);
 277    object_property_set_description(obj, "aarch64",
 278                                    "Set on/off to enable/disable aarch64 "
 279                                    "execution state ",
 280                                    NULL);
 281}
 282
 283static void aarch64_cpu_finalizefn(Object *obj)
 284{
 285}
 286
 287static void aarch64_cpu_set_pc(CPUState *cs, vaddr value)
 288{
 289    ARMCPU *cpu = ARM_CPU(cs);
 290    /* It's OK to look at env for the current mode here, because it's
 291     * never possible for an AArch64 TB to chain to an AArch32 TB.
 292     * (Otherwise we would need to use synchronize_from_tb instead.)
 293     */
 294    if (is_a64(&cpu->env)) {
 295        cpu->env.pc = value;
 296    } else {
 297        cpu->env.regs[15] = value;
 298    }
 299}
 300
 301static vaddr aarch64_cpu_get_pc(CPUState *cs)
 302{
 303    ARMCPU *cpu = ARM_CPU(cs);
 304
 305    return is_a64(&cpu->env) ? cpu->env.pc : cpu->env.regs[15];
 306}
 307
 308static const char *a64_debug_ctx[] = {
 309       [DEBUG_CURRENT_EL] = "current-el",
 310       [DEBUG_EL0] = "el0",
 311       [DEBUG_EL1] = "el1",
 312       [DEBUG_EL2] = "el2",
 313       [DEBUG_EL3] = "el3",
 314       [DEBUG_PHYS] = "phys",
 315};
 316
 317static gchar *aarch64_gdb_arch_name(CPUState *cs)
 318{
 319    return g_strdup("aarch64");
 320}
 321
 322static void set_debug_context(CPUState *cs, unsigned int ctx)
 323{
 324    ARMCPU *cpu = ARM_CPU(cs);
 325    cpu->env.debug_ctx = ctx;
 326}
 327
 328static void aarch64_cpu_class_init(ObjectClass *oc, void *data)
 329{
 330    CPUClass *cc = CPU_CLASS(oc);
 331
 332    cc->cpu_exec_interrupt = arm_cpu_exec_interrupt;
 333    cc->set_pc = aarch64_cpu_set_pc;
 334    cc->get_pc = aarch64_cpu_get_pc;
 335    cc->debug_contexts = a64_debug_ctx;
 336    cc->set_debug_context = set_debug_context;
 337    cc->gdb_read_register = aarch64_cpu_gdb_read_register;
 338    cc->gdb_write_register = aarch64_cpu_gdb_write_register;
 339    cc->gdb_num_core_regs = 34;
 340    cc->gdb_core_xml_file = "aarch64-core.xml";
 341    cc->gdb_arch_name = aarch64_gdb_arch_name;
 342}
 343
 344static void aarch64_cpu_register(const ARMCPUInfo *info)
 345{
 346    TypeInfo type_info = {
 347        .parent = TYPE_AARCH64_CPU,
 348        .instance_size = sizeof(ARMCPU),
 349        .instance_init = info->initfn,
 350        .class_size = sizeof(ARMCPUClass),
 351        .class_init = info->class_init,
 352    };
 353
 354    type_info.name = g_strdup_printf("%s-" TYPE_ARM_CPU, info->name);
 355    type_register(&type_info);
 356    g_free((void *)type_info.name);
 357}
 358
 359static const TypeInfo aarch64_cpu_type_info = {
 360    .name = TYPE_AARCH64_CPU,
 361    .parent = TYPE_ARM_CPU,
 362    .instance_size = sizeof(ARMCPU),
 363    .instance_init = aarch64_cpu_initfn,
 364    .instance_finalize = aarch64_cpu_finalizefn,
 365    .abstract = true,
 366    .class_size = sizeof(AArch64CPUClass),
 367    .class_init = aarch64_cpu_class_init,
 368};
 369
 370static void aarch64_cpu_register_types(void)
 371{
 372    const ARMCPUInfo *info = aarch64_cpus;
 373
 374    type_register_static(&aarch64_cpu_type_info);
 375
 376    while (info->name) {
 377        aarch64_cpu_register(info);
 378        info++;
 379    }
 380}
 381
 382type_init(aarch64_cpu_register_types)
 383