Skip to contentSkip to conversation

Implement VFP context switch for arm32

PATCH Superseded Julien Grall 2 participants 12 messages Jun 3, 2013 – Jun 13, 2013

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover Implement VFP context switch for arm32

Hello,

This is the third version of this patch series.

I have only implemented the VFP context switch support for arm32 and add dummy function to avoid avoid compilation breakage on arm64.

For all the changes see each patch.

Cheers,

Julien Grall (2):
xen/arm: don't enable VFP on XEN during the boot xen/arm32: implement VFP context switch

 xen/arch/arm/Rules.mk           |    2 +-
 xen/arch/arm/arm32/Makefile     |    1 +
 xen/arch/arm/arm32/vfp.c        |   99 +++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/arm64/Makefile     |    1 +
 xen/arch/arm/arm64/vfp.c        |   13 +++++
 xen/arch/arm/domain.c           |    7 ++-
 xen/arch/arm/setup.c            |    3 --
 xen/arch/arm/smpboot.c          |    2 -
 xen/include/asm-arm/arm32/vfp.h |   41 ++++++++++++++++
 xen/include/asm-arm/arm64/vfp.h |   16 +++++++
 xen/include/asm-arm/cpregs.h    |    9 ++++
 xen/include/asm-arm/domain.h    |    4 ++
 xen/include/asm-arm/vfp.h       |   42 +++++------------
 13 files changed, 202 insertions(+), 38 deletions(-)
 create mode 100644 xen/arch/arm/arm32/vfp.c
 create mode 100644 xen/arch/arm/arm64/vfp.c
 create mode 100644 xen/include/asm-arm/arm32/vfp.h
 create mode 100644 xen/include/asm-arm/arm64/vfp.h
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v3 1/2 xen/arm: don't enable VFP on XEN during the boot

We can safely remove VFP support in XEN because:
- the guest will enable VFP support when a process requires it
- XEN doesn't use VFP

Changes in v2:
- Remove asm/vfp.h and all the inclusions of this header

---
 xen/arch/arm/Rules.mk     |    2 +-
 xen/arch/arm/setup.c      |    3 ---
 xen/arch/arm/smpboot.c    |    2 --
 xen/include/asm-arm/vfp.h |   43 -------------------------------------------
 4 files changed, 1 insertion(+), 49 deletions(-)
 delete mode 100644 xen/include/asm-arm/vfp.h
xen/arch/arm/Rules.mk +1 -1
index 422ed04..a18e7fd 100644
@@ -22,7 +22,7 @@ arm := y
 ifeq ($(TARGET_SUBARCH),arm32)
 # Prevent floating-point variables from creeping into Xen.
 CFLAGS += -msoft-float
-CFLAGS += -mcpu=cortex-a15 -mfpu=vfpv3 -mfloat-abi=softfp
+CFLAGS += -mcpu=cortex-a15
 arm32 := y
 arm64 := n
 endif
xen/arch/arm/setup.c +0 -3
index da2a734..b192d15 100644
@@ -38,7 +38,6 @@
 #include <asm/page.h>
 #include <asm/current.h>
 #include <asm/setup.h>
-#include <asm/vfp.h>
 #include <asm/early_printk.h>
 #include <asm/gic.h>
 #include <asm/cpufeature.h>
@@ -457,8 +456,6 @@ void __init start_xen(unsigned long boot_phys_offset,
 
     setup_virt_paging();
 
-    enable_vfp();
-
     softirq_init();
 
     tasklet_subsys_init();
xen/arch/arm/smpboot.c +0 -2
index 8011987..c7421fc 100644
@@ -28,7 +28,6 @@
 #include <xen/softirq.h>
 #include <xen/timer.h>
 #include <xen/irq.h>
-#include <asm/vfp.h>
 #include <asm/gic.h>
 
 cpumask_t cpu_online_map;
@@ -153,7 +152,6 @@ void __cpuinit start_secondary(unsigned long boot_phys_offset,
     setup_virt_paging();
 
     mmu_init_secondary_cpu();
-    enable_vfp();
 
     gic_init_secondary_cpu();
 
xen/include/asm-arm/vfp.h deleted +0 -43

43 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#2 lore raw

PATCH v3 2/2 xen/arm32: implement VFP context switch

In reply to Julien Grall

Add support for VFP context switch on arm32 and a dummy support for arm64

Changes in v3:
- Add vfp_init to check if the processor supports VFP 3
- Add clobber memory
- Remove tmps
- s/COFNIG_ARM64/CONFIG_ARM64/ in include/asm/arm.h

Changes in v2:
- Fix all the small errors (type, lost headers...)
- Add some comments

---
 xen/arch/arm/arm32/Makefile     |    1 +
 xen/arch/arm/arm32/vfp.c        |   99 +++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/arm64/Makefile     |    1 +
 xen/arch/arm/arm64/vfp.c        |   13 +++++
 xen/arch/arm/domain.c           |    7 ++-
 xen/include/asm-arm/arm32/vfp.h |   41 ++++++++++++++++
 xen/include/asm-arm/arm64/vfp.h |   16 +++++++
 xen/include/asm-arm/cpregs.h    |    9 ++++
 xen/include/asm-arm/domain.h    |    4 ++
 xen/include/asm-arm/vfp.h       |   25 ++++++++++
 10 files changed, 214 insertions(+), 2 deletions(-)
 create mode 100644 xen/arch/arm/arm32/vfp.c
 create mode 100644 xen/arch/arm/arm64/vfp.c
 create mode 100644 xen/include/asm-arm/arm32/vfp.h
 create mode 100644 xen/include/asm-arm/arm64/vfp.h
 create mode 100644 xen/include/asm-arm/vfp.h
xen/arch/arm/arm32/Makefile +1 -0
index aaf277a..b903803 100644
@@ -6,5 +6,6 @@ obj-y += proc-ca15.o
 
 obj-y += traps.o
 obj-y += domain.o
+obj-y += vfp.o
 
 obj-$(EARLY_PRINTK) += debug.o
xen/arch/arm/arm32/vfp.c new file +99 -0

99 lines not on this page · raw message

xen/arch/arm/arm64/Makefile +1 -0
index 9484548..e06a0a9 100644
@@ -5,5 +5,6 @@ obj-y += mode_switch.o
 
 obj-y += traps.o
 obj-y += domain.o
+obj-y += vfp.o
 
 obj-$(EARLY_PRINTK) += debug.o
xen/arch/arm/arm64/vfp.c new file +13 -0
new file mode 100644
index 0000000..74e6a50
@@ -0,0 +1,13 @@
+#include <xen/sched.h>
+#include <asm/processor.h>
+#include <asm/vfp.h>
+
+void vfp_save_state(struct vcpu *v)
+{
+    /* TODO: implement it */
+}
+
+void vfp_restore_state(struct vcpu *v)
+{
+    /* TODO: implement it */
+}
xen/arch/arm/domain.c +5 -2
index 4c434a1..f465ab7 100644
@@ -27,6 +27,7 @@
 #include <asm/p2m.h>
 #include <asm/irq.h>
 #include <asm/cpufeature.h>
+#include <asm/vfp.h>
 
 #include <asm/gic.h>
 #include "vtimer.h"
@@ -117,7 +118,8 @@ static void ctxt_switch_from(struct vcpu *p)
 
     /* XXX MPU */
 
-    /* XXX VFP */
+    /* VFP */
+    vfp_save_state(p);
 
     /* VGIC */
     gic_save_state(p);
@@ -143,7 +145,8 @@ static void ctxt_switch_to(struct vcpu *n)
     /* VGIC */
     gic_restore_state(n);
 
-    /* XXX VFP */
+    /* VFP */
+    vfp_restore_state(n);
 
     /* XXX MPU */
 
xen/include/asm-arm/arm32/vfp.h new file +41 -0

41 lines not on this page · raw message

xen/include/asm-arm/arm64/vfp.h new file +16 -0
new file mode 100644
index 0000000..3733d2c
@@ -0,0 +1,16 @@
+#ifndef _ARM_ARM64_VFP_H
+#define _ARM_ARM64_VFP_H
+
+struct vfp_state
+{
+};
+
+#endif /* _ARM_ARM64_VFP_H */
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
xen/include/asm-arm/cpregs.h +9 -0
index f08d59a..122dd1a 100644
@@ -60,6 +60,15 @@
  * arguments, which are cp,opc1,crn,crm,opc2.
  */
 
+/* Coprocessor 10 */
+
+#define FPSID           p10,7,c0,c0,0   /* Floating-Point System ID Register */
+#define FPSCR           p10,7,c1,c0,0   /* Floating-Point Status and Control Register */
+#define MVFR0           p10,7,c7,c0,0   /* Media and VFP Feature Register 0 */
+#define FPEXC           p10,7,c8,c0,0   /* Floating-Point Exception Control Register */
+#define FPINST          p10,7,c9,c0,0   /* Floating-Point Instruction Register */
+#define FPINST2         p10,7,c10,c0,0  /* Floating-point Instruction Register 2 */
+
 /* Coprocessor 14 */
 
 /* CP14 CR0: */
xen/include/asm-arm/domain.h +4 -0
index cb251cc..339b6e6 100644
@@ -6,6 +6,7 @@
 #include <xen/sched.h>
 #include <asm/page.h>
 #include <asm/p2m.h>
+#include <asm/vfp.h>
 #include <public/hvm/params.h>
 
 /* Represents state corresponding to a block of 32 interrupts */
@@ -188,6 +189,9 @@ struct arch_vcpu
     uint32_t joscr, jmcr;
 #endif
 
+    /* Float-pointer */
+    struct vfp_state vfp;
+
     /* CP 15 */
     uint32_t csselr;
 
xen/include/asm-arm/vfp.h new file +25 -0
new file mode 100644
index 0000000..5f10fe5
@@ -0,0 +1,25 @@
+#ifndef _ASM_VFP_H
+#define _ASM_VFP_H
+
+#include <xen/sched.h>
+
+#if defined(CONFIG_ARM_32)
+# include <asm/arm32/vfp.h>
+#elif defined(CONFIG_ARM_64)
+# include <asm/arm64/vfp.h>
+#else
+# error "Unknown ARM variant"
+#endif
+
+void vfp_save_state(struct vcpu *v);
+void vfp_restore_state(struct vcpu *v);
+
+#endif /* _ASM_VFP_H */
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Signature · 1 line
1.7.10.4
#3 lore raw

Re: [PATCH v3 2/2] xen/arm32: implement VFP context switch

Quoted 65 lines · Julien Grall

Add support for VFP context switch on arm32 and a dummy support for arm64

Changes in v3:
- Add vfp_init to check if the processor supports VFP 3
- Add clobber memory
- Remove tmps
- s/COFNIG_ARM64/CONFIG_ARM64/ in include/asm/arm.h

Changes in v2:
- Fix all the small errors (type, lost headers...)
- Add some comments

---
 xen/arch/arm/arm32/Makefile     |    1 +
 xen/arch/arm/arm32/vfp.c        |   99 +++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/arm64/Makefile     |    1 +
 xen/arch/arm/arm64/vfp.c        |   13 +++++
 xen/arch/arm/domain.c           |    7 ++-
 xen/include/asm-arm/arm32/vfp.h |   41 ++++++++++++++++
 xen/include/asm-arm/arm64/vfp.h |   16 +++++++
 xen/include/asm-arm/cpregs.h    |    9 ++++
 xen/include/asm-arm/domain.h    |    4 ++
 xen/include/asm-arm/vfp.h       |   25 ++++++++++
 10 files changed, 214 insertions(+), 2 deletions(-)
 create mode 100644 xen/arch/arm/arm32/vfp.c
 create mode 100644 xen/arch/arm/arm64/vfp.c
 create mode 100644 xen/include/asm-arm/arm32/vfp.h
 create mode 100644 xen/include/asm-arm/arm64/vfp.h
 create mode 100644 xen/include/asm-arm/vfp.h
xen/arch/arm/arm32/Makefile +1 -0
index aaf277a..b903803 100644
@@ -6,5 +6,6 @@ obj-y += proc-ca15.o
 
 obj-y += traps.o
 obj-y += domain.o
+obj-y += vfp.o
 
 obj-$(EARLY_PRINTK) += debug.o
xen/arch/arm/arm32/vfp.c new file +17 -0
new file mode 100644
index 0000000..2ece43d
@@ -0,0 +1,99 @@
+#include <xen/sched.h>
+#include <xen/init.h>
+#include <asm/processor.h>
+#include <asm/vfp.h>
+
+void vfp_save_state(struct vcpu *v)
+{
+    v->arch.vfp.fpexc = READ_CP32(FPEXC);
+
+    WRITE_CP32(v->arch.vfp.fpexc | FPEXC_EN, FPEXC);
+
+    v->arch.vfp.fpscr = READ_CP32(FPSCR);
+
+    if ( v->arch.vfp.fpexc & FPEXC_EX ) /* Check for sub-architecture */
+    {
+        v->arch.vfp.fpinst = READ_CP32(FPINST);
+

xen/arch/arm/arm32/vfp.c line 27

Quoted 10 lines
xen/arch/arm/arm32/vfp.c new file +10 -0
+        if ( v->arch.vfp.fpexc & FPEXC_FP2V )
+            v->arch.vfp.fpinst2 = READ_CP32(FPINST2);
+        /* Disable FPEXC_EX */
+        WRITE_CP32((v->arch.vfp.fpexc | FPEXC_EN) & ~FPEXC_EX, FPEXC);
+    }
+
+    /* Save {d0-d15} */
+    asm volatile("stc p11, cr0, [%0], #32*4"
+                 : : "r" (v->arch.vfp.fpregs1)
+                 : "memory");

http://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html suggests that "=m" (v->arch.vfp.fpregs1) or "=Q" (...) as output constraints might do the job without clobbering the whole of memory.

I can't see any examples of this on ARM though, e.g. in Linux (other than =Qo in the atomics) though and I've expected this patter to be widespread so perhaps that isn't right. Alternatively it's quite a tricky construct to grep for, so maybe I missed all the uses. We do use =m a fair bit in x86 Xen FWIW.

Quoted 8 lines

static __init int vfp_init(void)

xen/arch/arm/arm32/vfp.c new file +7 -0
+{
+    unsigned int vfpsid;
+    unsigned int vfparch;
+
+    vfpsid = READ_CP32(FPSID);
+
+    printk("VFP implementer 0x%02x architecture %d part 0x%02x variant 0x%x "

xen/arch/arm/arm32/vfp.c line 86

Quoted 10 lines
xen/arch/arm/arm32/vfp.c new file +10 -0
+           "rev 0x%x\n",
+           (vfpsid & FPSID_IMPLEMENTER_MASK) >> FPSID_IMPLEMENTER_BIT,
+           (vfpsid & FPSID_ARCH_MASK) >> FPSID_ARCH_BIT,
+           (vfpsid & FPSID_PART_MASK) >> FPSID_PART_BIT,
+           (vfpsid & FPSID_VARIANT_MASK) >> FPSID_VARIANT_BIT,
+           (vfpsid & FPSID_REV_MASK) >> FPSID_REV_BIT);
+
+    vfparch = (vfpsid & FPSID_ARCH_MASK) >> FPSID_ARCH_BIT;
+    if ( vfparch < 2 )
+        panic("Xen only support VFP 3\n");

Should be "supports". Don't bother resending just for that though.

Ian.

#4 lore raw

Re: [PATCH v3 2/2] xen/arm32: implement VFP context switch

Quoted 72 lines · Ian Campbell
Quoted 71 lines · Julien Grall

Add support for VFP context switch on arm32 and a dummy support for arm64

Changes in v3:
- Add vfp_init to check if the processor supports VFP 3
- Add clobber memory
- Remove tmps
- s/COFNIG_ARM64/CONFIG_ARM64/ in include/asm/arm.h

Changes in v2:
- Fix all the small errors (type, lost headers...)
- Add some comments

---
 xen/arch/arm/arm32/Makefile     |    1 +
 xen/arch/arm/arm32/vfp.c        |   99 +++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/arm64/Makefile     |    1 +
 xen/arch/arm/arm64/vfp.c        |   13 +++++
 xen/arch/arm/domain.c           |    7 ++-
 xen/include/asm-arm/arm32/vfp.h |   41 ++++++++++++++++
 xen/include/asm-arm/arm64/vfp.h |   16 +++++++
 xen/include/asm-arm/cpregs.h    |    9 ++++
 xen/include/asm-arm/domain.h    |    4 ++
 xen/include/asm-arm/vfp.h       |   25 ++++++++++
 10 files changed, 214 insertions(+), 2 deletions(-)
 create mode 100644 xen/arch/arm/arm32/vfp.c
 create mode 100644 xen/arch/arm/arm64/vfp.c
 create mode 100644 xen/include/asm-arm/arm32/vfp.h
 create mode 100644 xen/include/asm-arm/arm64/vfp.h
 create mode 100644 xen/include/asm-arm/vfp.h
xen/arch/arm/arm32/Makefile +1 -0
index aaf277a..b903803 100644
@@ -6,5 +6,6 @@ obj-y += proc-ca15.o
 
 obj-y += traps.o
 obj-y += domain.o
+obj-y += vfp.o
 
 obj-$(EARLY_PRINTK) += debug.o
xen/arch/arm/arm32/vfp.c new file +23 -0
new file mode 100644
index 0000000..2ece43d
@@ -0,0 +1,99 @@
+#include <xen/sched.h>
+#include <xen/init.h>
+#include <asm/processor.h>
+#include <asm/vfp.h>
+
+void vfp_save_state(struct vcpu *v)
+{
+    v->arch.vfp.fpexc = READ_CP32(FPEXC);
+
+    WRITE_CP32(v->arch.vfp.fpexc | FPEXC_EN, FPEXC);
+
+    v->arch.vfp.fpscr = READ_CP32(FPSCR);
+
+    if ( v->arch.vfp.fpexc & FPEXC_EX ) /* Check for sub-architecture */
+    {
+        v->arch.vfp.fpinst = READ_CP32(FPINST);
+
+        if ( v->arch.vfp.fpexc & FPEXC_FP2V )
+            v->arch.vfp.fpinst2 = READ_CP32(FPINST2);
+        /* Disable FPEXC_EX */
+        WRITE_CP32((v->arch.vfp.fpexc | FPEXC_EN) & ~FPEXC_EX, FPEXC);
+    }
+
Quoted 8 lines

xen/arch/arm/arm32/vfp.c line 27

Quoted 4 lines
xen/arch/arm/arm32/vfp.c new file +4 -0
+    /* Save {d0-d15} */
+    asm volatile("stc p11, cr0, [%0], #32*4"
+                 : : "r" (v->arch.vfp.fpregs1)
+                 : "memory");

http://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html suggests that "=m" (v->arch.vfp.fpregs1) or "=Q" (...) as output constraints might do the job without clobbering the whole of memory.

I'm not sure to fully understand the concept behind "=m". Does it mean that gcc will clobber all the memory range addressed by fpregs?

Signature · 1 line
Julien
#5 lore raw

Re: [PATCH v3 2/2] xen/arm32: implement VFP context switch

Quoted 83 lines · Julien Grall
Quoted 72 lines · Ian Campbell
Quoted 71 lines · Julien Grall

Add support for VFP context switch on arm32 and a dummy support for arm64

Changes in v3:
- Add vfp_init to check if the processor supports VFP 3
- Add clobber memory
- Remove tmps
- s/COFNIG_ARM64/CONFIG_ARM64/ in include/asm/arm.h

Changes in v2:
- Fix all the small errors (type, lost headers...)
- Add some comments

---
 xen/arch/arm/arm32/Makefile     |    1 +
 xen/arch/arm/arm32/vfp.c        |   99 +++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/arm64/Makefile     |    1 +
 xen/arch/arm/arm64/vfp.c        |   13 +++++
 xen/arch/arm/domain.c           |    7 ++-
 xen/include/asm-arm/arm32/vfp.h |   41 ++++++++++++++++
 xen/include/asm-arm/arm64/vfp.h |   16 +++++++
 xen/include/asm-arm/cpregs.h    |    9 ++++
 xen/include/asm-arm/domain.h    |    4 ++
 xen/include/asm-arm/vfp.h       |   25 ++++++++++
 10 files changed, 214 insertions(+), 2 deletions(-)
 create mode 100644 xen/arch/arm/arm32/vfp.c
 create mode 100644 xen/arch/arm/arm64/vfp.c
 create mode 100644 xen/include/asm-arm/arm32/vfp.h
 create mode 100644 xen/include/asm-arm/arm64/vfp.h
 create mode 100644 xen/include/asm-arm/vfp.h
xen/arch/arm/arm32/Makefile +1 -0
index aaf277a..b903803 100644
@@ -6,5 +6,6 @@ obj-y += proc-ca15.o
 
 obj-y += traps.o
 obj-y += domain.o
+obj-y += vfp.o
 
 obj-$(EARLY_PRINTK) += debug.o
xen/arch/arm/arm32/vfp.c new file +23 -0
new file mode 100644
index 0000000..2ece43d
@@ -0,0 +1,99 @@
+#include <xen/sched.h>
+#include <xen/init.h>
+#include <asm/processor.h>
+#include <asm/vfp.h>
+
+void vfp_save_state(struct vcpu *v)
+{
+    v->arch.vfp.fpexc = READ_CP32(FPEXC);
+
+    WRITE_CP32(v->arch.vfp.fpexc | FPEXC_EN, FPEXC);
+
+    v->arch.vfp.fpscr = READ_CP32(FPSCR);
+
+    if ( v->arch.vfp.fpexc & FPEXC_EX ) /* Check for sub-architecture */
+    {
+        v->arch.vfp.fpinst = READ_CP32(FPINST);
+
+        if ( v->arch.vfp.fpexc & FPEXC_FP2V )
+            v->arch.vfp.fpinst2 = READ_CP32(FPINST2);
+        /* Disable FPEXC_EX */
+        WRITE_CP32((v->arch.vfp.fpexc | FPEXC_EN) & ~FPEXC_EX, FPEXC);
+    }
+
Quoted 8 lines

xen/arch/arm/arm32/vfp.c line 27

Quoted 4 lines
xen/arch/arm/arm32/vfp.c new file +4 -0
+    /* Save {d0-d15} */
+    asm volatile("stc p11, cr0, [%0], #32*4"
+                 : : "r" (v->arch.vfp.fpregs1)
+                 : "memory");

http://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html suggests that "=m" (v->arch.vfp.fpregs1) or "=Q" (...) as output constraints might do the job without clobbering the whole of memory.

Quoted 2 lines

I'm not sure to fully understand the concept behind "=m". Does it mean that gcc will clobber all the memory range addressed by fpregs?

I'm not totally confident in this stuff myself....

Apparently the "=" modified means[0] "this operand is write-only for this instruction: the previous value is discarded and replaced by output data." In the case of a memory constraint you'd want to hope that "discarded and replaced" would be equivalent to clobbering the address, at least in cases where the compiler knows the size of the thing, as it does here.

Ian.

[0] http://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/Modifiers.html#Modifiers

#6 lore raw

Re: [PATCH v3 2/2] xen/arm32: implement VFP context switch

Quoted 96 lines · Ian Campbell
Quoted 83 lines · Julien Grall
Quoted 72 lines · Ian Campbell
Quoted 71 lines · Julien Grall

Add support for VFP context switch on arm32 and a dummy support for arm64

Changes in v3:
- Add vfp_init to check if the processor supports VFP 3
- Add clobber memory
- Remove tmps
- s/COFNIG_ARM64/CONFIG_ARM64/ in include/asm/arm.h

Changes in v2:
- Fix all the small errors (type, lost headers...)
- Add some comments

---
 xen/arch/arm/arm32/Makefile     |    1 +
 xen/arch/arm/arm32/vfp.c        |   99 +++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/arm64/Makefile     |    1 +
 xen/arch/arm/arm64/vfp.c        |   13 +++++
 xen/arch/arm/domain.c           |    7 ++-
 xen/include/asm-arm/arm32/vfp.h |   41 ++++++++++++++++
 xen/include/asm-arm/arm64/vfp.h |   16 +++++++
 xen/include/asm-arm/cpregs.h    |    9 ++++
 xen/include/asm-arm/domain.h    |    4 ++
 xen/include/asm-arm/vfp.h       |   25 ++++++++++
 10 files changed, 214 insertions(+), 2 deletions(-)
 create mode 100644 xen/arch/arm/arm32/vfp.c
 create mode 100644 xen/arch/arm/arm64/vfp.c
 create mode 100644 xen/include/asm-arm/arm32/vfp.h
 create mode 100644 xen/include/asm-arm/arm64/vfp.h
 create mode 100644 xen/include/asm-arm/vfp.h
xen/arch/arm/arm32/Makefile +1 -0
index aaf277a..b903803 100644
@@ -6,5 +6,6 @@ obj-y += proc-ca15.o
 
 obj-y += traps.o
 obj-y += domain.o
+obj-y += vfp.o
 
 obj-$(EARLY_PRINTK) += debug.o
xen/arch/arm/arm32/vfp.c new file +23 -0
new file mode 100644
index 0000000..2ece43d
@@ -0,0 +1,99 @@
+#include <xen/sched.h>
+#include <xen/init.h>
+#include <asm/processor.h>
+#include <asm/vfp.h>
+
+void vfp_save_state(struct vcpu *v)
+{
+    v->arch.vfp.fpexc = READ_CP32(FPEXC);
+
+    WRITE_CP32(v->arch.vfp.fpexc | FPEXC_EN, FPEXC);
+
+    v->arch.vfp.fpscr = READ_CP32(FPSCR);
+
+    if ( v->arch.vfp.fpexc & FPEXC_EX ) /* Check for sub-architecture */
+    {
+        v->arch.vfp.fpinst = READ_CP32(FPINST);
+
+        if ( v->arch.vfp.fpexc & FPEXC_FP2V )
+            v->arch.vfp.fpinst2 = READ_CP32(FPINST2);
+        /* Disable FPEXC_EX */
+        WRITE_CP32((v->arch.vfp.fpexc | FPEXC_EN) & ~FPEXC_EX, FPEXC);
+    }
+
Quoted 8 lines

xen/arch/arm/arm32/vfp.c line 27

Quoted 4 lines
xen/arch/arm/arm32/vfp.c new file +4 -0
+    /* Save {d0-d15} */
+    asm volatile("stc p11, cr0, [%0], #32*4"
+                 : : "r" (v->arch.vfp.fpregs1)
+                 : "memory");

http://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html suggests that "=m" (v->arch.vfp.fpregs1) or "=Q" (...) as output constraints might do the job without clobbering the whole of memory.

Quoted 2 lines

I'm not sure to fully understand the concept behind "=m". Does it mean that gcc will clobber all the memory range addressed by fpregs?

I'm not totally confident in this stuff myself....

Apparently the "=" modified means[0] "this operand is write-only for this instruction: the previous value is discarded and replaced by output data." In the case of a memory constraint you'd want to hope that "discarded and replaced" would be equivalent to clobbering the address, at least in cases where the compiler knows the size of the thing, as it does here.

Quoted 4 lines

Ian.

[0] http://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/Modifiers.html#Modifiers

Shall I use this contrainst for the stc instructions and send a new patch series?

Signature · 1 line
Julien
#7 lore raw

Re: [PATCH v3 2/2] xen/arm32: implement VFP context switch

Quoted 98 lines · Julien Grall
Quoted 96 lines · Ian Campbell
Quoted 83 lines · Julien Grall
Quoted 72 lines · Ian Campbell
Quoted 71 lines · Julien Grall

Add support for VFP context switch on arm32 and a dummy support for arm64

Changes in v3:
- Add vfp_init to check if the processor supports VFP 3
- Add clobber memory
- Remove tmps
- s/COFNIG_ARM64/CONFIG_ARM64/ in include/asm/arm.h

Changes in v2:
- Fix all the small errors (type, lost headers...)
- Add some comments

---
 xen/arch/arm/arm32/Makefile     |    1 +
 xen/arch/arm/arm32/vfp.c        |   99 +++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/arm64/Makefile     |    1 +
 xen/arch/arm/arm64/vfp.c        |   13 +++++
 xen/arch/arm/domain.c           |    7 ++-
 xen/include/asm-arm/arm32/vfp.h |   41 ++++++++++++++++
 xen/include/asm-arm/arm64/vfp.h |   16 +++++++
 xen/include/asm-arm/cpregs.h    |    9 ++++
 xen/include/asm-arm/domain.h    |    4 ++
 xen/include/asm-arm/vfp.h       |   25 ++++++++++
 10 files changed, 214 insertions(+), 2 deletions(-)
 create mode 100644 xen/arch/arm/arm32/vfp.c
 create mode 100644 xen/arch/arm/arm64/vfp.c
 create mode 100644 xen/include/asm-arm/arm32/vfp.h
 create mode 100644 xen/include/asm-arm/arm64/vfp.h
 create mode 100644 xen/include/asm-arm/vfp.h
xen/arch/arm/arm32/Makefile +1 -0
index aaf277a..b903803 100644
@@ -6,5 +6,6 @@ obj-y += proc-ca15.o
 
 obj-y += traps.o
 obj-y += domain.o
+obj-y += vfp.o
 
 obj-$(EARLY_PRINTK) += debug.o
xen/arch/arm/arm32/vfp.c new file +23 -0
new file mode 100644
index 0000000..2ece43d
@@ -0,0 +1,99 @@
+#include <xen/sched.h>
+#include <xen/init.h>
+#include <asm/processor.h>
+#include <asm/vfp.h>
+
+void vfp_save_state(struct vcpu *v)
+{
+    v->arch.vfp.fpexc = READ_CP32(FPEXC);
+
+    WRITE_CP32(v->arch.vfp.fpexc | FPEXC_EN, FPEXC);
+
+    v->arch.vfp.fpscr = READ_CP32(FPSCR);
+
+    if ( v->arch.vfp.fpexc & FPEXC_EX ) /* Check for sub-architecture */
+    {
+        v->arch.vfp.fpinst = READ_CP32(FPINST);
+
+        if ( v->arch.vfp.fpexc & FPEXC_FP2V )
+            v->arch.vfp.fpinst2 = READ_CP32(FPINST2);
+        /* Disable FPEXC_EX */
+        WRITE_CP32((v->arch.vfp.fpexc | FPEXC_EN) & ~FPEXC_EX, FPEXC);
+    }
+
Quoted 8 lines

xen/arch/arm/arm32/vfp.c line 27

Quoted 4 lines
xen/arch/arm/arm32/vfp.c new file +4 -0
+    /* Save {d0-d15} */
+    asm volatile("stc p11, cr0, [%0], #32*4"
+                 : : "r" (v->arch.vfp.fpregs1)
+                 : "memory");

http://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html suggests that "=m" (v->arch.vfp.fpregs1) or "=Q" (...) as output constraints might do the job without clobbering the whole of memory.

Quoted 2 lines

I'm not sure to fully understand the concept behind "=m". Does it mean that gcc will clobber all the memory range addressed by fpregs?

I'm not totally confident in this stuff myself....

Apparently the "=" modified means[0] "this operand is write-only for this instruction: the previous value is discarded and replaced by output data." In the case of a memory constraint you'd want to hope that "discarded and replaced" would be equivalent to clobbering the address, at least in cases where the compiler knows the size of the thing, as it does here.

Quoted 8 lines
Quoted 4 lines

Ian.

[0] http://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/Modifiers.html#Modifiers

Shall I use this contrainst for the stc instructions and send a new patch series?

If you buy my reasoning and if it works then I guess so.

Ian.

#8 lore raw

Re: [PATCH v3 2/2] xen/arm32: implement VFP context switch

Quoted 101 lines · Ian Campbell
Quoted 100 lines · Julien Grall
Quoted 98 lines · Ian Campbell
Quoted 83 lines · Julien Grall
Quoted 72 lines · Ian Campbell
Quoted 71 lines · Julien Grall

Add support for VFP context switch on arm32 and a dummy support for arm64

Changes in v3:
- Add vfp_init to check if the processor supports VFP 3
- Add clobber memory
- Remove tmps
- s/COFNIG_ARM64/CONFIG_ARM64/ in include/asm/arm.h

Changes in v2:
- Fix all the small errors (type, lost headers...)
- Add some comments

---
 xen/arch/arm/arm32/Makefile     |    1 +
 xen/arch/arm/arm32/vfp.c        |   99 +++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/arm64/Makefile     |    1 +
 xen/arch/arm/arm64/vfp.c        |   13 +++++
 xen/arch/arm/domain.c           |    7 ++-
 xen/include/asm-arm/arm32/vfp.h |   41 ++++++++++++++++
 xen/include/asm-arm/arm64/vfp.h |   16 +++++++
 xen/include/asm-arm/cpregs.h    |    9 ++++
 xen/include/asm-arm/domain.h    |    4 ++
 xen/include/asm-arm/vfp.h       |   25 ++++++++++
 10 files changed, 214 insertions(+), 2 deletions(-)
 create mode 100644 xen/arch/arm/arm32/vfp.c
 create mode 100644 xen/arch/arm/arm64/vfp.c
 create mode 100644 xen/include/asm-arm/arm32/vfp.h
 create mode 100644 xen/include/asm-arm/arm64/vfp.h
 create mode 100644 xen/include/asm-arm/vfp.h
xen/arch/arm/arm32/Makefile +1 -0
index aaf277a..b903803 100644
@@ -6,5 +6,6 @@ obj-y += proc-ca15.o
 
 obj-y += traps.o
 obj-y += domain.o
+obj-y += vfp.o
 
 obj-$(EARLY_PRINTK) += debug.o
xen/arch/arm/arm32/vfp.c new file +23 -0
new file mode 100644
index 0000000..2ece43d
@@ -0,0 +1,99 @@
+#include <xen/sched.h>
+#include <xen/init.h>
+#include <asm/processor.h>
+#include <asm/vfp.h>
+
+void vfp_save_state(struct vcpu *v)
+{
+    v->arch.vfp.fpexc = READ_CP32(FPEXC);
+
+    WRITE_CP32(v->arch.vfp.fpexc | FPEXC_EN, FPEXC);
+
+    v->arch.vfp.fpscr = READ_CP32(FPSCR);
+
+    if ( v->arch.vfp.fpexc & FPEXC_EX ) /* Check for sub-architecture */
+    {
+        v->arch.vfp.fpinst = READ_CP32(FPINST);
+
+        if ( v->arch.vfp.fpexc & FPEXC_FP2V )
+            v->arch.vfp.fpinst2 = READ_CP32(FPINST2);
+        /* Disable FPEXC_EX */
+        WRITE_CP32((v->arch.vfp.fpexc | FPEXC_EN) & ~FPEXC_EX, FPEXC);
+    }
+
Quoted 8 lines

xen/arch/arm/arm32/vfp.c line 27

Quoted 4 lines
xen/arch/arm/arm32/vfp.c new file +4 -0
+    /* Save {d0-d15} */
+    asm volatile("stc p11, cr0, [%0], #32*4"
+                 : : "r" (v->arch.vfp.fpregs1)
+                 : "memory");

http://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html suggests that "=m" (v->arch.vfp.fpregs1) or "=Q" (...) as output constraints might do the job without clobbering the whole of memory.

Quoted 2 lines

I'm not sure to fully understand the concept behind "=m". Does it mean that gcc will clobber all the memory range addressed by fpregs?

I'm not totally confident in this stuff myself....

Apparently the "=" modified means[0] "this operand is write-only for this instruction: the previous value is discarded and replaced by output data." In the case of a memory constraint you'd want to hope that "discarded and replaced" would be equivalent to clobbering the address, at least in cases where the compiler knows the size of the thing, as it does here.

Ian.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

[0] http://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/Modifiers.html#Modifiers

Shall I use this contrainst for the stc instructions and send a new patch series?

If you buy my reasoning and if it works then I guess so.

I will give a try.

Signature · 1 line
Julien
#9 lore raw

Re: [PATCH v3 2/2] xen/arm32: implement VFP context switch

In reply to Ian Campbell
Quoted 101 lines · Ian Campbell
Quoted 100 lines · Julien Grall
Quoted 98 lines · Ian Campbell
Quoted 83 lines · Julien Grall
Quoted 72 lines · Ian Campbell
Quoted 71 lines · Julien Grall

Add support for VFP context switch on arm32 and a dummy support for arm64

Changes in v3:
- Add vfp_init to check if the processor supports VFP 3
- Add clobber memory
- Remove tmps
- s/COFNIG_ARM64/CONFIG_ARM64/ in include/asm/arm.h

Changes in v2:
- Fix all the small errors (type, lost headers...)
- Add some comments

---
 xen/arch/arm/arm32/Makefile     |    1 +
 xen/arch/arm/arm32/vfp.c        |   99 +++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/arm64/Makefile     |    1 +
 xen/arch/arm/arm64/vfp.c        |   13 +++++
 xen/arch/arm/domain.c           |    7 ++-
 xen/include/asm-arm/arm32/vfp.h |   41 ++++++++++++++++
 xen/include/asm-arm/arm64/vfp.h |   16 +++++++
 xen/include/asm-arm/cpregs.h    |    9 ++++
 xen/include/asm-arm/domain.h    |    4 ++
 xen/include/asm-arm/vfp.h       |   25 ++++++++++
 10 files changed, 214 insertions(+), 2 deletions(-)
 create mode 100644 xen/arch/arm/arm32/vfp.c
 create mode 100644 xen/arch/arm/arm64/vfp.c
 create mode 100644 xen/include/asm-arm/arm32/vfp.h
 create mode 100644 xen/include/asm-arm/arm64/vfp.h
 create mode 100644 xen/include/asm-arm/vfp.h
xen/arch/arm/arm32/Makefile +1 -0
index aaf277a..b903803 100644
@@ -6,5 +6,6 @@ obj-y += proc-ca15.o
 
 obj-y += traps.o
 obj-y += domain.o
+obj-y += vfp.o
 
 obj-$(EARLY_PRINTK) += debug.o
xen/arch/arm/arm32/vfp.c new file +23 -0
new file mode 100644
index 0000000..2ece43d
@@ -0,0 +1,99 @@
+#include <xen/sched.h>
+#include <xen/init.h>
+#include <asm/processor.h>
+#include <asm/vfp.h>
+
+void vfp_save_state(struct vcpu *v)
+{
+    v->arch.vfp.fpexc = READ_CP32(FPEXC);
+
+    WRITE_CP32(v->arch.vfp.fpexc | FPEXC_EN, FPEXC);
+
+    v->arch.vfp.fpscr = READ_CP32(FPSCR);
+
+    if ( v->arch.vfp.fpexc & FPEXC_EX ) /* Check for sub-architecture */
+    {
+        v->arch.vfp.fpinst = READ_CP32(FPINST);
+
+        if ( v->arch.vfp.fpexc & FPEXC_FP2V )
+            v->arch.vfp.fpinst2 = READ_CP32(FPINST2);
+        /* Disable FPEXC_EX */
+        WRITE_CP32((v->arch.vfp.fpexc | FPEXC_EN) & ~FPEXC_EX, FPEXC);
+    }
+
Quoted 8 lines

xen/arch/arm/arm32/vfp.c line 27

Quoted 4 lines
xen/arch/arm/arm32/vfp.c new file +4 -0
+    /* Save {d0-d15} */
+    asm volatile("stc p11, cr0, [%0], #32*4"
+                 : : "r" (v->arch.vfp.fpregs1)
+                 : "memory");

http://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html suggests that "=m" (v->arch.vfp.fpregs1) or "=Q" (...) as output constraints might do the job without clobbering the whole of memory.

Quoted 2 lines

I'm not sure to fully understand the concept behind "=m". Does it mean that gcc will clobber all the memory range addressed by fpregs?

I'm not totally confident in this stuff myself....

Apparently the "=" modified means[0] "this operand is write-only for this instruction: the previous value is discarded and replaced by output data." In the case of a memory constraint you'd want to hope that "discarded and replaced" would be equivalent to clobbering the address, at least in cases where the compiler knows the size of the thing, as it does here.

Ian.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

[0] http://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/Modifiers.html#Modifiers

Shall I use this contrainst for the stc instructions and send a new patch series?

If you buy my reasoning and if it works then I guess so.

Hi,

So I gave a try and it doesn't work.
The modifiers =m replaces %0 by [rn,imm] which is wrong. So it's not possible to specify the amount of data which the instruction need to read (the #32*4) because pre-index and post-index aren't allowed in a same instruction.

If I remove #32*4, the instruction is different. With objdump on each generate object:
- vstmia r3!, {d0,d15}
- vstr d0, [rn, imm]

--
Julien

#10 lore raw

Re: [PATCH v3 2/2] xen/arm32: implement VFP context switch

Quoted 110 lines · Julien Grall
Quoted 108 lines · Ian Campbell
Quoted 106 lines · Julien Grall
Quoted 96 lines · Ian Campbell
Quoted 83 lines · Julien Grall
Quoted 72 lines · Ian Campbell
Quoted 71 lines · Julien Grall

Add support for VFP context switch on arm32 and a dummy support for arm64

Changes in v3:
- Add vfp_init to check if the processor supports VFP 3
- Add clobber memory
- Remove tmps
- s/COFNIG_ARM64/CONFIG_ARM64/ in include/asm/arm.h

Changes in v2:
- Fix all the small errors (type, lost headers...)
- Add some comments

---
 xen/arch/arm/arm32/Makefile     |    1 +
 xen/arch/arm/arm32/vfp.c        |   99 +++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/arm64/Makefile     |    1 +
 xen/arch/arm/arm64/vfp.c        |   13 +++++
 xen/arch/arm/domain.c           |    7 ++-
 xen/include/asm-arm/arm32/vfp.h |   41 ++++++++++++++++
 xen/include/asm-arm/arm64/vfp.h |   16 +++++++
 xen/include/asm-arm/cpregs.h    |    9 ++++
 xen/include/asm-arm/domain.h    |    4 ++
 xen/include/asm-arm/vfp.h       |   25 ++++++++++
 10 files changed, 214 insertions(+), 2 deletions(-)
 create mode 100644 xen/arch/arm/arm32/vfp.c
 create mode 100644 xen/arch/arm/arm64/vfp.c
 create mode 100644 xen/include/asm-arm/arm32/vfp.h
 create mode 100644 xen/include/asm-arm/arm64/vfp.h
 create mode 100644 xen/include/asm-arm/vfp.h
xen/arch/arm/arm32/Makefile +1 -0
index aaf277a..b903803 100644
@@ -6,5 +6,6 @@ obj-y += proc-ca15.o
 
 obj-y += traps.o
 obj-y += domain.o
+obj-y += vfp.o
 
 obj-$(EARLY_PRINTK) += debug.o
xen/arch/arm/arm32/vfp.c new file +23 -0
new file mode 100644
index 0000000..2ece43d
@@ -0,0 +1,99 @@
+#include <xen/sched.h>
+#include <xen/init.h>
+#include <asm/processor.h>
+#include <asm/vfp.h>
+
+void vfp_save_state(struct vcpu *v)
+{
+    v->arch.vfp.fpexc = READ_CP32(FPEXC);
+
+    WRITE_CP32(v->arch.vfp.fpexc | FPEXC_EN, FPEXC);
+
+    v->arch.vfp.fpscr = READ_CP32(FPSCR);
+
+    if ( v->arch.vfp.fpexc & FPEXC_EX ) /* Check for sub-architecture */
+    {
+        v->arch.vfp.fpinst = READ_CP32(FPINST);
+
+        if ( v->arch.vfp.fpexc & FPEXC_FP2V )
+            v->arch.vfp.fpinst2 = READ_CP32(FPINST2);
+        /* Disable FPEXC_EX */
+        WRITE_CP32((v->arch.vfp.fpexc | FPEXC_EN) & ~FPEXC_EX, FPEXC);
+    }
+
Quoted 8 lines

xen/arch/arm/arm32/vfp.c line 27

Quoted 4 lines
xen/arch/arm/arm32/vfp.c new file +4 -0
+    /* Save {d0-d15} */
+    asm volatile("stc p11, cr0, [%0], #32*4"
+                 : : "r" (v->arch.vfp.fpregs1)
+                 : "memory");

http://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html suggests that "=m" (v->arch.vfp.fpregs1) or "=Q" (...) as output constraints might do the job without clobbering the whole of memory.

Quoted 2 lines

I'm not sure to fully understand the concept behind "=m". Does it mean that gcc will clobber all the memory range addressed by fpregs?

I'm not totally confident in this stuff myself....

Apparently the "=" modified means[0] "this operand is write-only for this instruction: the previous value is discarded and replaced by output data." In the case of a memory constraint you'd want to hope that "discarded and replaced" would be equivalent to clobbering the address, at least in cases where the compiler knows the size of the thing, as it does here.

Quoted 4 lines

Ian.

[0] http://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/Modifiers.html#Modifiers

Shall I use this contrainst for the stc instructions and send a new patch series?

Quoted 6 lines
Quoted 1 line

If you buy my reasoning and if it works then I guess so.

Hi,

So I gave a try and it doesn't work.

That's a shame, oh well we'll have to use the big clobber then -- not the end of the world.

Quoted 13 lines

The modifiers =m replaces %0 by [rn,imm] which is wrong. So it's not possible to specify the amount of data which the instruction need to read (the #32*4) because pre-index and post-index aren't allowed in a same instruction.

If I remove #32*4, the instruction is different. With objdump on each generate object:
- vstmia r3!, {d0,d15}
- vstr d0, [rn, imm]

--
Julien

#11 lore raw

Re: [PATCH v3 2/2] xen/arm32: implement VFP context switch

Quoted 114 lines · Ian Campbell
Quoted 113 lines · Julien Grall
Quoted 109 lines · Ian Campbell
Quoted 98 lines · Julien Grall
Quoted 96 lines · Ian Campbell
Quoted 83 lines · Julien Grall
Quoted 72 lines · Ian Campbell
Quoted 71 lines · Julien Grall

Add support for VFP context switch on arm32 and a dummy support for arm64

Changes in v3:
- Add vfp_init to check if the processor supports VFP 3
- Add clobber memory
- Remove tmps
- s/COFNIG_ARM64/CONFIG_ARM64/ in include/asm/arm.h

Changes in v2:
- Fix all the small errors (type, lost headers...)
- Add some comments

---
 xen/arch/arm/arm32/Makefile     |    1 +
 xen/arch/arm/arm32/vfp.c        |   99 +++++++++++++++++++++++++++++++++++++++
 xen/arch/arm/arm64/Makefile     |    1 +
 xen/arch/arm/arm64/vfp.c        |   13 +++++
 xen/arch/arm/domain.c           |    7 ++-
 xen/include/asm-arm/arm32/vfp.h |   41 ++++++++++++++++
 xen/include/asm-arm/arm64/vfp.h |   16 +++++++
 xen/include/asm-arm/cpregs.h    |    9 ++++
 xen/include/asm-arm/domain.h    |    4 ++
 xen/include/asm-arm/vfp.h       |   25 ++++++++++
 10 files changed, 214 insertions(+), 2 deletions(-)
 create mode 100644 xen/arch/arm/arm32/vfp.c
 create mode 100644 xen/arch/arm/arm64/vfp.c
 create mode 100644 xen/include/asm-arm/arm32/vfp.h
 create mode 100644 xen/include/asm-arm/arm64/vfp.h
 create mode 100644 xen/include/asm-arm/vfp.h
xen/arch/arm/arm32/Makefile +1 -0
index aaf277a..b903803 100644
@@ -6,5 +6,6 @@ obj-y += proc-ca15.o
 
 obj-y += traps.o
 obj-y += domain.o
+obj-y += vfp.o
 
 obj-$(EARLY_PRINTK) += debug.o
xen/arch/arm/arm32/vfp.c new file +23 -0
new file mode 100644
index 0000000..2ece43d
@@ -0,0 +1,99 @@
+#include <xen/sched.h>
+#include <xen/init.h>
+#include <asm/processor.h>
+#include <asm/vfp.h>
+
+void vfp_save_state(struct vcpu *v)
+{
+    v->arch.vfp.fpexc = READ_CP32(FPEXC);
+
+    WRITE_CP32(v->arch.vfp.fpexc | FPEXC_EN, FPEXC);
+
+    v->arch.vfp.fpscr = READ_CP32(FPSCR);
+
+    if ( v->arch.vfp.fpexc & FPEXC_EX ) /* Check for sub-architecture */
+    {
+        v->arch.vfp.fpinst = READ_CP32(FPINST);
+
+        if ( v->arch.vfp.fpexc & FPEXC_FP2V )
+            v->arch.vfp.fpinst2 = READ_CP32(FPINST2);
+        /* Disable FPEXC_EX */
+        WRITE_CP32((v->arch.vfp.fpexc | FPEXC_EN) & ~FPEXC_EX, FPEXC);
+    }
+
Quoted 8 lines

xen/arch/arm/arm32/vfp.c line 27

Quoted 4 lines
xen/arch/arm/arm32/vfp.c new file +4 -0
+    /* Save {d0-d15} */
+    asm volatile("stc p11, cr0, [%0], #32*4"
+                 : : "r" (v->arch.vfp.fpregs1)
+                 : "memory");

http://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html suggests that "=m" (v->arch.vfp.fpregs1) or "=Q" (...) as output constraints might do the job without clobbering the whole of memory.

Quoted 2 lines

I'm not sure to fully understand the concept behind "=m". Does it mean that gcc will clobber all the memory range addressed by fpregs?

I'm not totally confident in this stuff myself....

Apparently the "=" modified means[0] "this operand is write-only for this instruction: the previous value is discarded and replaced by output data." In the case of a memory constraint you'd want to hope that "discarded and replaced" would be equivalent to clobbering the address, at least in cases where the compiler knows the size of the thing, as it does here.

Quoted 8 lines
Quoted 4 lines

Ian.

[0] http://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/Modifiers.html#Modifiers

Shall I use this contrainst for the stc instructions and send a new patch series?

If you buy my reasoning and if it works then I guess so.

Quoted 11 lines
Quoted 3 lines

Hi,

So I gave a try and it doesn't work.

That's a shame, oh well we'll have to use the big clobber then -- not the end of the world.

Quoted 4 lines

The modifiers =m replaces %0 by [rn,imm] which is wrong. So it's not possible to specify the amount of data which the instruction need to read (the #32*4) because pre-index and post-index aren't allowed in a same instruction.

I had a chat with Tim and he pointed out that this is exactly what the =Q output constraint is for. According to
http://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/Machine-Constraints.html#Machine-Constraints
it is:

A memory reference where the exact address is in a single register

In other words it outlaws the [rn,imm] construct.

Does that work?

(that doc goes on to say:
(`‘m’' is preferable for asm statements)
lets ignore that ;-))

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel