qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Pranavkumar Sawargaonkar <pranavkumar@linaro.org>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, patches@apm.com,
	alex.bennee@linaro.org, kvmarm@lists.cs.columbia.edu,
	christoffer.dall@linaro.org,
	Pranavkumar Sawargaonkar <pranavkumar@linaro.org>
Subject: [Qemu-devel] [PATCH V3 2/2] target-arm: Guest cpu endianness determination for virtio KVM ARM/ARM64
Date: Thu,  5 Feb 2015 15:29:42 +0530	[thread overview]
Message-ID: <1423130382-18640-3-git-send-email-pranavkumar@linaro.org> (raw)
In-Reply-To: <1423130382-18640-1-git-send-email-pranavkumar@linaro.org>

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.

Signed-off-by: Pranavkumar Sawargaonkar <pranavkumar@linaro.org>
---
 target-arm/cpu.c | 24 ++++++++++++++++++++++++
 target-arm/cpu.h |  2 ++
 2 files changed, 26 insertions(+)

diff --git a/target-arm/cpu.c b/target-arm/cpu.c
index 285947f..4d9cded 100644
--- a/target-arm/cpu.c
+++ b/target-arm/cpu.c
@@ -320,6 +320,29 @@ static void arm_cpu_kvm_set_irq(void *opaque, int irq, int level)
     kvm_set_irq(kvm_state, kvm_irq, level ? 1 : 0);
 #endif
 }
+
+static bool arm_cpu_is_big_endian(CPUState *cs)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    CPUARMState *env = &cpu->env;
+    int cur_el;
+
+    cpu_synchronize_state(cs);
+
+    /* In 32bit guest endianess is determined by looking at CPSR's E bit */
+    if (!is_a64(env)) {
+        return (env->pstate & 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;
+}
+
 #endif
 
 static inline void set_feature(CPUARMState *env, int feature)
@@ -1189,6 +1212,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)
     cc->do_interrupt = arm_cpu_do_interrupt;
     cc->get_phys_page_debug = arm_cpu_get_phys_page_debug;
     cc->vmsd = &vmstate_arm_cpu;
+    cc->virtio_is_big_endian = arm_cpu_is_big_endian;
 #endif
     cc->gdb_num_core_regs = 26;
     cc->gdb_core_xml_file = "arm-core.xml";
diff --git a/target-arm/cpu.h b/target-arm/cpu.h
index cd7a9e8..317e801 100644
--- a/target-arm/cpu.h
+++ b/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"
-- 
1.9.1

  parent reply	other threads:[~2015-02-05 10:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-05  9:59 [Qemu-devel] [PATCH V3 0/2] Add virtio endianness determination in KVM ARM/ARM64 Pranavkumar Sawargaonkar
2015-02-05  9:59 ` [Qemu-devel] [PATCH V3 1/2] target-arm: KVM64: Get and Sync up guest register state like kvm32 Pranavkumar Sawargaonkar
2015-02-05  9:59 ` Pranavkumar Sawargaonkar [this message]
2015-02-05 11:43   ` [Qemu-devel] [PATCH V3 2/2] target-arm: Guest cpu endianness determination for virtio KVM ARM/ARM64 Peter Maydell
2015-02-05 11:48     ` Peter Maydell
2015-02-06 16:43       ` Pranavkumar Sawargaonkar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1423130382-18640-3-git-send-email-pranavkumar@linaro.org \
    --to=pranavkumar@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=christoffer.dall@linaro.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=patches@apm.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).