From 30f4d72db55fa6b1989d8623825d52d7c4c26d90 Mon Sep 17 00:00:00 2001 From: Pranavkumar Sawargaonkar Date: Mon, 12 Feb 2018 12:02:33 -0500 Subject: [PATCH] target-arm: Guest cpu endianness determination for virtio KVM ARM/ARM64 This patch implements a fucntion pointer "virtio_is_big_endian" from "CPUClass" structure for arm/arm64. Function arm_cpu_is_big_endian() is added to determine and return the guest cpu endianness to virtio. This is required for running cross endian guests with virtio on ARM/ARM64. Backports commit 84f2bed3cf505f90b7918e2de32e11da27160563 from qemu --- qemu/target-arm/cpu.c | 26 ++++++++++++++++++++++++++ qemu/target-arm/cpu.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/qemu/target-arm/cpu.c b/qemu/target-arm/cpu.c index 7dda0e2a..4c4a470a 100644 --- a/qemu/target-arm/cpu.c +++ b/qemu/target-arm/cpu.c @@ -272,6 +272,29 @@ static bool arm_v7m_cpu_exec_interrupt(CPUState *cs, int interrupt_request) } #endif +static bool arm_cpu_is_big_endian(CPUState *cs) +{ + ARMCPU *cpu = ARM_CPU(NULL, cs); + CPUARMState *env = &cpu->env; + int cur_el; + + // UNICORN: Commented out + //cpu_synchronize_state(cs); + + /* In 32bit guest endianness is determined by looking at CPSR's E bit */ + if (!is_a64(env)) { + return (env->uncached_cpsr & CPSR_E) ? 1 : 0; + } + + cur_el = arm_current_el(env); + + if (cur_el == 0) { + return (env->cp15.sctlr_el[1] & SCTLR_E0E) != 0; + } + + return (env->cp15.sctlr_el[cur_el] & SCTLR_EE) != 0; +} + static inline void set_feature(CPUARMState *env, int feature) { env->features |= 1ULL << feature; @@ -1117,6 +1140,9 @@ static void arm_cpu_class_init(struct uc_struct *uc, ObjectClass *oc, void *data #else cc->do_interrupt = arm_cpu_do_interrupt; cc->get_phys_page_debug = arm_cpu_get_phys_page_debug; + // UNICORN: Commented out + //cc->vmsd = &vmstate_arm_cpu; + //cc->virtio_is_big_endian = arm_cpu_is_big_endian; #endif cc->debug_excp_handler = arm_debug_excp_handler; } diff --git a/qemu/target-arm/cpu.h b/qemu/target-arm/cpu.h index 246a5313..8eb8b569 100644 --- a/qemu/target-arm/cpu.h +++ b/qemu/target-arm/cpu.h @@ -32,6 +32,8 @@ # define ELF_MACHINE EM_ARM #endif +#define TARGET_IS_BIENDIAN 1 + #define CPUArchState struct CPUARMState #include "qemu-common.h"