Patchwork [2/3] target-arm: Implement cp15 VA->PA translation

login
register
mail settings
Submitter Adam Lackorzynski
Date Feb. 21, 2011, 11:19 p.m.
Message ID <1298330372-1254-3-git-send-email-adam@os.inf.tu-dresden.de>
Download mbox | patch
Permalink /patch/83888/
State New
Headers show

Comments

Adam Lackorzynski - Feb. 21, 2011, 11:19 p.m.
Implement VA->PA translations by cp15-c7 that went through unchanged
previously.

Signed-off-by: Adam Lackorzynski <adam@os.inf.tu-dresden.de>
---
 target-arm/cpu.h     |    1 +
 target-arm/helper.c  |   48 ++++++++++++++++++++++++++++++++++++++++++++++--
 target-arm/machine.c |    2 ++
 3 files changed, 49 insertions(+), 2 deletions(-)
Peter Maydell - Feb. 25, 2011, 6:25 p.m.
On 21 February 2011 23:19, Adam Lackorzynski <adam@os.inf.tu-dresden.de> wrote:
> Implement VA->PA translations by cp15-c7 that went through unchanged
> previously.
>
> Signed-off-by: Adam Lackorzynski <adam@os.inf.tu-dresden.de>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

(Sorry for the delay, I only got time to knock up a test program
for this functionality this afternoon.)

Note that without the patch I posted today that cleans up
cp15 wfi decoding, you won't be able to get at one of
the translation types.

-- PMM
Peter Maydell - March 3, 2011, 10:59 p.m.
On 21 February 2011 23:19, Adam Lackorzynski <adam@os.inf.tu-dresden.de> wrote:
> diff --git a/target-arm/machine.c b/target-arm/machine.c
> index 3925d3a..a18b7dc 100644
> --- a/target-arm/machine.c
> +++ b/target-arm/machine.c
> @@ -41,6 +41,7 @@ void cpu_save(QEMUFile *f, void *opaque)
>     }
>     qemu_put_be32(f, env->cp15.c6_insn);
>     qemu_put_be32(f, env->cp15.c6_data);
> +    qemu_put_be32(f, env->cp15.c7_par);
>     qemu_put_be32(f, env->cp15.c9_insn);
>     qemu_put_be32(f, env->cp15.c9_data);
>     qemu_put_be32(f, env->cp15.c13_fcse);
> @@ -148,6 +149,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)
>     }
>     env->cp15.c6_insn = qemu_get_be32(f);
>     env->cp15.c6_data = qemu_get_be32(f);
> +    env->cp15.c7_par = qemu_get_be32(f);
>     env->cp15.c9_insn = qemu_get_be32(f);
>     env->cp15.c9_data = qemu_get_be32(f);
>     env->cp15.c13_fcse = qemu_get_be32(f);

Comments on another patch left me wondering whether we should
be bumping a version number here somewhere[*], since we're changing
the load/store state format by adding another field. Anybody
care to agree/disagree?

[*] CPU_SAVE_VERSION in target-arm/cpu.h I guess.

-- PMM
Adam Lackorzynski - March 3, 2011, 11:09 p.m.
On Thu Mar 03, 2011 at 22:59:03 +0000, Peter Maydell wrote:
> On 21 February 2011 23:19, Adam Lackorzynski <adam@os.inf.tu-dresden.de> wrote:
> > diff --git a/target-arm/machine.c b/target-arm/machine.c
> > index 3925d3a..a18b7dc 100644
> > --- a/target-arm/machine.c
> > +++ b/target-arm/machine.c
> > @@ -41,6 +41,7 @@ void cpu_save(QEMUFile *f, void *opaque)
> >     }
> >     qemu_put_be32(f, env->cp15.c6_insn);
> >     qemu_put_be32(f, env->cp15.c6_data);
> > +    qemu_put_be32(f, env->cp15.c7_par);
> >     qemu_put_be32(f, env->cp15.c9_insn);
> >     qemu_put_be32(f, env->cp15.c9_data);
> >     qemu_put_be32(f, env->cp15.c13_fcse);
> > @@ -148,6 +149,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)
> >     }
> >     env->cp15.c6_insn = qemu_get_be32(f);
> >     env->cp15.c6_data = qemu_get_be32(f);
> > +    env->cp15.c7_par = qemu_get_be32(f);
> >     env->cp15.c9_insn = qemu_get_be32(f);
> >     env->cp15.c9_data = qemu_get_be32(f);
> >     env->cp15.c13_fcse = qemu_get_be32(f);
> 
> Comments on another patch left me wondering whether we should
> be bumping a version number here somewhere[*], since we're changing
> the load/store state format by adding another field. Anybody
> care to agree/disagree?

Looks like a reasonable thing to do. I'll add it to my patch set.
 

Adam

Patch

diff --git a/target-arm/cpu.h b/target-arm/cpu.h
index c9febfa..603574b 100644
--- a/target-arm/cpu.h
+++ b/target-arm/cpu.h
@@ -126,6 +126,7 @@  typedef struct CPUARMState {
         uint32_t c6_region[8]; /* MPU base/size registers.  */
         uint32_t c6_insn; /* Fault address registers.  */
         uint32_t c6_data;
+        uint32_t c7_par;  /* Translation result. */
         uint32_t c9_insn; /* Cache lockdown registers.  */
         uint32_t c9_data;
         uint32_t c13_fcse; /* FCSE PID.  */
diff --git a/target-arm/helper.c b/target-arm/helper.c
index 7f63a28..23c719b 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -1456,8 +1456,49 @@  void HELPER(set_cp15)(CPUState *env, uint32_t insn, uint32_t val)
     case 7: /* Cache control.  */
         env->cp15.c15_i_max = 0x000;
         env->cp15.c15_i_min = 0xff0;
-        /* No cache, so nothing to do.  */
-        /* ??? MPCore has VA to PA translation functions.  */
+        if (op1 != 0) {
+            goto bad_reg;
+        }
+        /* No cache, so nothing to do except VA->PA translations. */
+        if (arm_feature(env, ARM_FEATURE_V6K)) {
+            switch (crm) {
+            case 4:
+                if (arm_feature(env, ARM_FEATURE_V7)) {
+                    env->cp15.c7_par = val & 0xfffff6ff;
+                } else {
+                    env->cp15.c7_par = val & 0xfffff1ff;
+                }
+                break;
+            case 8: {
+                uint32_t phys_addr;
+                target_ulong page_size;
+                int prot;
+                int ret, is_user = op2 & 2;
+                int access_type = op2 & 1;
+
+                if (op2 & 4) {
+                    /* Other states are only available with TrustZone */
+                    goto bad_reg;
+                }
+                ret = get_phys_addr(env, val, access_type, is_user,
+                                    &phys_addr, &prot, &page_size);
+                if (ret == 0) {
+                    /* We do not set any attribute bits in the PAR */
+                    if (page_size == (1 << 24)
+                        && arm_feature(env, ARM_FEATURE_V7)) {
+                        env->cp15.c7_par = (phys_addr & 0xff000000) | 1 << 1;
+                    } else {
+                        env->cp15.c7_par = phys_addr & 0xfffff000;
+                    }
+                } else {
+                    env->cp15.c7_par = ((ret & (10 << 1)) >> 5) |
+                                       ((ret & (12 << 1)) >> 6) |
+                                       ((ret & 0xf) << 1) | 1;
+                }
+                break;
+            }
+            }
+        }
         break;
     case 8: /* MMU TLB control.  */
         switch (op2) {
@@ -1789,6 +1830,9 @@  uint32_t HELPER(get_cp15)(CPUState *env, uint32_t insn)
 	    }
         }
     case 7: /* Cache control.  */
+        if (crm == 4 && op1 == 0 && op2 == 0) {
+            return env->cp15.c7_par;
+        }
         /* FIXME: Should only clear Z flag if destination is r15.  */
         env->ZF = 0;
         return 0;
diff --git a/target-arm/machine.c b/target-arm/machine.c
index 3925d3a..a18b7dc 100644
--- a/target-arm/machine.c
+++ b/target-arm/machine.c
@@ -41,6 +41,7 @@  void cpu_save(QEMUFile *f, void *opaque)
     }
     qemu_put_be32(f, env->cp15.c6_insn);
     qemu_put_be32(f, env->cp15.c6_data);
+    qemu_put_be32(f, env->cp15.c7_par);
     qemu_put_be32(f, env->cp15.c9_insn);
     qemu_put_be32(f, env->cp15.c9_data);
     qemu_put_be32(f, env->cp15.c13_fcse);
@@ -148,6 +149,7 @@  int cpu_load(QEMUFile *f, void *opaque, int version_id)
     }
     env->cp15.c6_insn = qemu_get_be32(f);
     env->cp15.c6_data = qemu_get_be32(f);
+    env->cp15.c7_par = qemu_get_be32(f);
     env->cp15.c9_insn = qemu_get_be32(f);
     env->cp15.c9_data = qemu_get_be32(f);
     env->cp15.c13_fcse = qemu_get_be32(f);