changeset cba0f26038b4 in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=cba0f26038b4
description:
        kvm, arm: Add support for aarch64

        This changeset adds support for aarch64 in kvm. The CPU module
        supports both checkpointing and online CPU model switching as long as
        no devices are simulated by the host kernel. It currently has the
        following limitations:

           * The system register based generic timer can only be simulated by
             the host kernel. Workaround: Use a memory mapped timer instead to
             simulate the timer in gem5.

           * Simulating devices (e.g., the generic timer) in the host kernel
             requires that the host kernel also simulates the GIC.

           * ID registers in the host and in gem5 must match for switching
             between simulated CPUs and KVM. This is particularly important
             for ID registers describing memory system capabilities (e.g.,
             ASID size, physical address size).

           * Switching between a virtualized CPU and a simulated CPU is
             currently not supported if in-kernel device emulation is
             used. This could be worked around by adding support for switching
             to the gem5 (e.g., the KvmGic) side of the device models. A
             simpler workaround is to avoid in-kernel device models
             altogether.

diffstat:

 SConstruct                        |    2 +-
 configs/common/CpuConfig.py       |    2 +-
 src/arch/arm/kvm/ArmV8KvmCPU.py   |   43 +++++
 src/arch/arm/kvm/BaseArmKvmCPU.py |   44 +++++
 src/arch/arm/kvm/SConscript       |    6 +
 src/arch/arm/kvm/armv8_cpu.cc     |  326 ++++++++++++++++++++++++++++++++++++++
 src/arch/arm/kvm/armv8_cpu.hh     |  140 ++++++++++++++++
 src/arch/arm/kvm/base_cpu.cc      |  154 +++++++++++++++++
 src/arch/arm/kvm/base_cpu.hh      |  111 ++++++++++++
 src/cpu/kvm/vm.cc                 |   11 +
 src/cpu/kvm/vm.hh                 |   17 +
 11 files changed, 854 insertions(+), 2 deletions(-)

diffs (truncated from 930 to 300 lines):

diff -r 0ba6f47025d1 -r cba0f26038b4 SConstruct
--- a/SConstruct        Mon Jun 01 19:44:17 2015 +0100
+++ b/SConstruct        Mon Jun 01 19:44:19 2015 +0100
@@ -1048,7 +1048,7 @@
         return False
 
     if isa == "arm":
-        return host_isa == "armv7l"
+        return host_isa in ( "armv7l", "aarch64" )
     elif isa == "x86":
         if host_isa != "x86_64":
             return False
diff -r 0ba6f47025d1 -r cba0f26038b4 configs/common/CpuConfig.py
--- a/configs/common/CpuConfig.py       Mon Jun 01 19:44:17 2015 +0100
+++ b/configs/common/CpuConfig.py       Mon Jun 01 19:44:19 2015 +0100
@@ -52,7 +52,7 @@
     ("atomic", "AtomicSimpleCPU"),
     ("minor", "MinorCPU"),
     ("detailed", "DerivO3CPU"),
-    ("kvm", ("ArmKvmCPU", "X86KvmCPU")),
+    ("kvm", ("ArmKvmCPU", "ArmV8KvmCPU", "X86KvmCPU")),
     ]
 
 # Filtered list of aliases. Only aliases for existing CPUs exist in
diff -r 0ba6f47025d1 -r cba0f26038b4 src/arch/arm/kvm/ArmV8KvmCPU.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/arch/arm/kvm/ArmV8KvmCPU.py   Mon Jun 01 19:44:19 2015 +0100
@@ -0,0 +1,43 @@
+# Copyright (c) 2015 ARM Limited
+# All rights reserved.
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder.  You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: Andreas Sandberg
+
+from m5.params import *
+from BaseArmKvmCPU import BaseArmKvmCPU
+
+class ArmV8KvmCPU(BaseArmKvmCPU):
+    type = 'ArmV8KvmCPU'
+    cxx_header = "arch/arm/kvm/armv8_cpu.hh"
diff -r 0ba6f47025d1 -r cba0f26038b4 src/arch/arm/kvm/BaseArmKvmCPU.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/arch/arm/kvm/BaseArmKvmCPU.py Mon Jun 01 19:44:19 2015 +0100
@@ -0,0 +1,44 @@
+# Copyright (c) 2015 ARM Limited
+# All rights reserved.
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder.  You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: Andreas Sandberg
+
+from m5.params import *
+from BaseKvmCPU import BaseKvmCPU
+
+class BaseArmKvmCPU(BaseKvmCPU):
+    type = 'BaseArmKvmCPU'
+    cxx_header = "arch/arm/kvm/base_cpu.hh"
+    abstract = True
diff -r 0ba6f47025d1 -r cba0f26038b4 src/arch/arm/kvm/SConscript
--- a/src/arch/arm/kvm/SConscript       Mon Jun 01 19:44:17 2015 +0100
+++ b/src/arch/arm/kvm/SConscript       Mon Jun 01 19:44:19 2015 +0100
@@ -48,6 +48,12 @@
 SimObject('KvmGic.py')
 Source('gic.cc')
 
+SimObject('BaseArmKvmCPU.py')
+Source('base_cpu.cc')
+
 if host_isa == "armv7l":
     SimObject('ArmKvmCPU.py')
     Source('arm_cpu.cc')
+elif host_isa == "aarch64":
+    SimObject('ArmV8KvmCPU.py')
+    Source('armv8_cpu.cc')
diff -r 0ba6f47025d1 -r cba0f26038b4 src/arch/arm/kvm/armv8_cpu.cc
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/arch/arm/kvm/armv8_cpu.cc     Mon Jun 01 19:44:19 2015 +0100
@@ -0,0 +1,326 @@
+/*
+ * Copyright (c) 2015 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder.  You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Andreas Sandberg
+ */
+
+#include "arch/arm/kvm/armv8_cpu.hh"
+
+#include <linux/kvm.h>
+
+#include "debug/KvmContext.hh"
+#include "params/ArmV8KvmCPU.hh"
+
+// Unlike gem5, kvm doesn't count the SP as a normal integer register,
+// which means we only have 31 normal integer registers.
+constexpr static unsigned NUM_XREGS = NUM_ARCH_INTREGS - 1;
+static_assert(NUM_XREGS == 31, "Unexpected number of aarch64 int. regs.");
+
+// The KVM interface accesses vector registers of 4 single precision
+// floats instead of individual registers.
+constexpr static unsigned NUM_QREGS = NumFloatV8ArchRegs / 4;
+static_assert(NUM_QREGS == 32, "Unexpected number of aarch64 vector regs.");
+
+#define EXTRACT_FIELD(v, name) \
+    (((v) & name ## _MASK) >> name ## _SHIFT)
+
+#define CORE_REG(name, size)                               \
+    (KVM_REG_ARM64 | KVM_REG_ARM_CORE |                    \
+     KVM_REG_SIZE_ ## size |                               \
+     KVM_REG_ARM_CORE_REG(name))
+
+#define INT_REG(name) CORE_REG(name, U64)
+#define SIMD_REG(name) CORE_REG(name, U128)
+
+constexpr uint64_t
+kvmXReg(const int num)
+{
+    return INT_REG(regs.regs[0]) +
+        (INT_REG(regs.regs[1]) - INT_REG(regs.regs[0])) * num;
+}
+
+constexpr uint64_t
+kvmFPReg(const int num)
+{
+    return SIMD_REG(fp_regs.vregs[0]) +
+        (SIMD_REG(fp_regs.vregs[1]) - SIMD_REG(fp_regs.vregs[0])) * num;
+}
+
+union KvmFPReg {
+    union {
+        uint32_t i;
+        float f;
+    } s[4];
+
+    union {
+        uint64_t i;
+        double f;
+    } d[2];
+
+    uint8_t data[32];
+};
+
+#define FP_REGS_PER_VFP_REG 4
+static_assert(sizeof(FloatRegBits) == 4, "Unexpected float reg size");
+
+const std::vector<ArmV8KvmCPU::IntRegInfo> ArmV8KvmCPU::intRegMap = {
+    { INT_REG(regs.sp), INTREG_SP0, "SP(EL0)" },
+    { INT_REG(sp_el1), INTREG_SP1, "SP(EL1)" },
+};
+
+const std::vector<ArmV8KvmCPU::MiscRegInfo> ArmV8KvmCPU::miscRegMap = {
+    MiscRegInfo(INT_REG(regs.pstate), MISCREG_CPSR, "PSTATE"),
+    MiscRegInfo(INT_REG(elr_el1), MISCREG_ELR_EL1, "ELR(EL1)"),
+    MiscRegInfo(INT_REG(spsr[KVM_SPSR_EL1]), MISCREG_SPSR_EL1, "SPSR(EL1)"),
+    MiscRegInfo(INT_REG(spsr[KVM_SPSR_ABT]), MISCREG_SPSR_ABT, "SPSR(ABT)"),
+    MiscRegInfo(INT_REG(spsr[KVM_SPSR_UND]), MISCREG_SPSR_UND, "SPSR(UND)"),
+    MiscRegInfo(INT_REG(spsr[KVM_SPSR_IRQ]), MISCREG_SPSR_IRQ, "SPSR(IRQ)"),
+    MiscRegInfo(INT_REG(spsr[KVM_SPSR_FIQ]), MISCREG_SPSR_FIQ, "SPSR(FIQ)"),
+    MiscRegInfo(INT_REG(fp_regs.fpsr), MISCREG_FPSR, "FPSR"),
+    MiscRegInfo(INT_REG(fp_regs.fpcr), MISCREG_FPCR, "FPCR"),
+};
+
+ArmV8KvmCPU::ArmV8KvmCPU(ArmV8KvmCPUParams *params)
+    : BaseArmKvmCPU(params)
+{
+}
+
+ArmV8KvmCPU::~ArmV8KvmCPU()
+{
+}
+
+void
+ArmV8KvmCPU::dump()
+{
+    inform("Integer registers:\n");
+    inform("  PC: %s\n", getAndFormatOneReg(INT_REG(regs.pc)));
+    for (int i = 0; i < NUM_XREGS; ++i)
+        inform("  X%i: %s\n", i, getAndFormatOneReg(kvmXReg(i)));
+
+    for (int i = 0; i < NUM_QREGS; ++i)
+        inform("  Q%i: %s\n", i, getAndFormatOneReg(kvmFPReg(i)));
+
+    for (const auto &ri : intRegMap)
+        inform("  %s: %s\n", ri.name, getAndFormatOneReg(ri.kvm));
+
+    for (const auto &ri : miscRegMap)
+        inform("  %s: %s\n", ri.name, getAndFormatOneReg(ri.kvm));
+
+    for (const auto &reg : getRegList()) {
+        const uint64_t arch(reg & KVM_REG_ARCH_MASK);
+        if (arch != KVM_REG_ARM64) {
+            inform("0x%x: %s\n", reg, getAndFormatOneReg(reg));
+            continue;
+        }
+
+        const uint64_t type(reg & KVM_REG_ARM_COPROC_MASK);
+        switch (type) {
+          case KVM_REG_ARM_CORE:
+            // These have already been printed
+            break;
+
+          case KVM_REG_ARM64_SYSREG: {
+              const uint64_t op0(EXTRACT_FIELD(reg, KVM_REG_ARM64_SYSREG_OP0));
+              const uint64_t op1(EXTRACT_FIELD(reg, KVM_REG_ARM64_SYSREG_OP1));
+              const uint64_t crn(EXTRACT_FIELD(reg, KVM_REG_ARM64_SYSREG_CRN));
+              const uint64_t crm(EXTRACT_FIELD(reg, KVM_REG_ARM64_SYSREG_CRM));
+              const uint64_t op2(EXTRACT_FIELD(reg, KVM_REG_ARM64_SYSREG_OP2));
+              const MiscRegIndex idx(
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to