target-arm: Implement cp15 VA->PA translation
PATCH 3/3 target-arm: Implement cp15 VA->PA translation
Implement VA->PA translations by cp15-c7 that went through unchanged previously.
--- target-arm/cpu.h | 1 + target-arm/helper.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-)
target-arm/cpu.h +1 -0
@@ -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. */
target-arm/helper.c +49 -2
63 lines not on this page · raw message
Signature · 7 lines
1.7.2.3 Adam -- Adam [email protected] Lackorzynski http://os.inf.tu-dresden.de/~adam/
Quoted 4 lines · Adam Lackorzynski
Implement
VA->PAtranslations by cp15-c7 that went through unchanged previously.+ uint32_t
c7_par; /* Translation result. */
I think this new env field needs extra code so it is saved and loaded by machine.c:cpu_save() and cpu_load().
Quoted 1 line
case 7: /* Cache control. */
We should be insisting that op1 == 0 (otherwise bad_reg).
Quoted 6 lines
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. */
+ /* No cache, so nothing to do exceptVA->PAtranslations. */
+ if (arm_feature(env, ARM_FEATURE_V6)) {
This is the wrong feature switch. The VA-PA translation registers are only architectural in v7. Before that, they exist in 11MPcore and 1176 but not 1136. So we should be testing for v7 or 11MPcore (since we don't model 1176).
Also, the format of the PAR is different in 1176/11MPcore! (in the comments below I'm generally talking about the v7 format, not 1176/mpcore).
Quoted 3 lines
+ switch (crm) {
+ case 4:
+ env->cp15.c7_par = val;
We shouldn't be allowing the reserved and impdef bits to be set here.
Quoted 20 lines
+ break;
+ case 8: {
+ uint32_tphys_addr;
+ target_ulongpage_size;
+ int prot;
+ int ret,is_user;
+ intaccess_type;
+
+ switch (op2) {
+ case 0: /* priv read */
+ is_user = 0;
+ access_type = 0;
+ break;
+ case 1: /* priv write */
+ is_user = 0;
+ access_type = 1;
+ break;
+ case 2: /* user read */
+ is_user = 1;
+ access_type = 0;
Quoted 8 lines
+ break;
+ case 3: /* user write */
+ is_user = 1;
+ access_type = 1;
+ break;
+ default: /* 4-7 are only available with TZ */
+ gotobad_reg;
+ }
I think it would be cleaner to write:
access_type = op2 & 1;
is_user = op2 & 2;
other_sec_state = op2 & 4;
if (other_sec_state) {
/* Only supported with TrustZone */
goto bad_reg;}
rather than have this big switch statement.
Quoted 2 lines
+ ret = get_phys_addr_v6(env, val,
access_type,is_user,
+&phys_addr, &prot,&page_size);
This will do the wrong thing when the MMU is disabled, and it doesn't account for the FSCE either. I think that just using get_phys_addr() will fix both of these.
Quoted 2 lines
+ if (ret == 0) {
+ env->cp15.c7_par =phys_addr;
You need to mask out bits [11..0] of phys_addr here:
if the caller passed in a VA with them set then get_phys_addr* will pass them back out to you again.
Also we ought ideally to be setting the various attributes bits based on the TLB entry, although I appreciate that since qemu doesn't currently do any of that decoding it would be a bit tedious to have to add it just for the benefit of VA-PA translation.
Quoted 2 lines
+ if (
page_size>TARGET_PAGE_SIZE)
+ env->cp15.c7_par |= 1 << 1;
This isn't correct: the SS bit should only be set if this was a SuperSection, not for anything larger than a page. (And if it is a SuperSection then the meaning of the PAR PA field changes, which for us means that we need to zero bits [23:12] since we don't support
Quoted 1 line
32bit physaddrs.)
Also, coding style mandates braces.
Quoted 2 lines
+ } else {
+ env->cp15.c7_par = ret | 1;
This isn't quite right -- the return value from get_phys_addr*() is in the same format as the DFSR (eg with the domain in bits [7:4]), and
the PAR bits [6:1] should be the equivalent
of DFSR bits [12,10,3:0]. So you need a bit
of shifting and masking here.
Quoted 7 lines
(quoted diff) +0
-0@@ -1789,6 +1833,9 @@ uint32_t HELPER(get_cp15)(CPUState *env, uint32_t insn) } }case 7: /* Cache control. */
+ if (crm == 4 && op2 == 0) {
+ returnenv->cp15.c7_par;
+ }
Again, we want op1 == 0 as well.
-- PMM
Hi,
thanks for the review!
Quoted 8 lines · Peter Maydell
Quoted 4 lines · Adam Lackorzynski
Implement
VA->PAtranslations by cp15-c7 that went through unchanged previously.+ uint32_t
c7_par; /* Translation result. */I think this new env field needs extra code so it is saved and loaded by machine.c:cpu_save() and
cpu_load().
Yes, noticed already myself.
Quoted 3 lines
Quoted 1 line
case 7: /* Cache control. */
We should be insisting that op1 == 0 (otherwise
bad_reg).
Ok.
Quoted 7 lines
Quoted 6 lines
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. */
+ /* No cache, so nothing to do exceptVA->PAtranslations. */
+ if (arm_feature(env, ARM_FEATURE_V6)) {
Quoted 8 lines
This is the wrong feature switch. The VA-PA translation registers are only architectural in v7. Before that, they exist in 11MPcore and 1176 but not 1136. So we should be testing for v7 or 11MPcore (since we don't model 1176).
Also, the format of the PAR is different in 1176/11MPcore! (in the comments below I'm generally talking about the v7 format, not 1176/mpcore).
I tried to add this too, should just be two more if expressions.
Quoted 6 lines
Quoted 3 lines
+ switch (crm) {
+ case 4:
+ env->cp15.c7_par = val;We shouldn't be allowing the reserved and impdef bits to be set here.
Ok.
Quoted 10 lines
I think it would be cleaner to write:
access_type= op2 & 1;
is_user= op2 & 2;
other_sec_state= op2 & 4;if (other_sec_state) { /* Only supported with TrustZone */ goto bad_reg;}
rather than have this big switch statement.
Good idea.
Quoted 14 lines
Quoted 2 lines
+ ret = get_phys_addr_v6(env, val,
access_type,is_user,
+&phys_addr, &prot,&page_size);This will do the wrong thing when the MMU is disabled, and it doesn't account for the FSCE either. I think that just using
get_phys_addr()will fix both of these.Quoted 2 lines
+ if (ret == 0) {
+ env->cp15.c7_par =phys_addr;You need to mask out bits [11..0] of
phys_addrhere:
if the caller passed in a VA with them set then get_phys_addr* will pass them back out to you again.
Quoted 5 lines
Also we ought ideally to be setting the various attributes bits based on the TLB entry, although I appreciate that since qemu doesn't currently do any of that decoding it would be a bit tedious to have to add it just for the benefit of VA-PA translation.
So for the time being a comment is ok?
Quoted 11 lines
Quoted 2 lines
+ if (
page_size>TARGET_PAGE_SIZE)
+ env->cp15.c7_par |= 1 << 1;This isn't correct: the SS bit should only be set if this was a SuperSection, not for anything larger than a page. (And if it is a SuperSection then the meaning of the PAR PA field changes, which for us means that we need to zero bits [23:12] since we don't support
Quoted 1 line
32bit physaddrs.)
Also, coding style mandates braces.
Ok.
Quoted 10 lines
Quoted 2 lines
+ } else {
+ env->cp15.c7_par = ret | 1;This isn't quite right -- the return value from get_phys_addr*() is in the same format as the DFSR (eg with the domain in bits [7:4]), and
the PAR bits [6:1] should be the equivalent
of DFSR bits [12,10,3:0]. So you need a bit
of shifting and masking here.
Quoted 9 lines
Quoted 7 lines
(quoted diff) +0
-0@@ -1789,6 +1833,9 @@ uint32_t HELPER(get_cp15)(CPUState *env, uint32_t insn) } }case 7: /* Cache control. */
+ if (crm == 4 && op2 == 0) {
+ returnenv->cp15.c7_par;
+ }Again, we want op1 == 0 as well.
Ok.
I'm not really sure about the cp15.c15_i_max and cp15.c15_i_min, they only seem to be used with ARM_FEATURE_OMAPCP so an if could be put around them.
New version:
Subject: [PATCH 2/3] target-arm: Implement cp15 VA->PA translation
Implement VA->PA translations by cp15-c7 that went through unchanged previously.
--- target-arm/cpu.h | 1 + target-arm/helper.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- target-arm/machine.c | 2 ++ 3 files changed, 49 insertions(+), 2 deletions(-)
target-arm/cpu.h +1 -0
@@ -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. */
target-arm/helper.c +46 -2
60 lines not on this page · raw message
target-arm/machine.c +2 -0
@@ -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);
Signature · 8 lines
1.7.2.3 Adam -- Adam [email protected] Lackorzynski http://os.inf.tu-dresden.de/~adam/