Skip to contentSkip to conversation

target-i386: honor CR0_PG_MASK in cpu_get_phys_page_debug

PATCH In review Max Filippov 2 participants 4 messages Nov 17, 2012 – Dec 5, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target-i386: honor CR0_PG_MASK in cpu_get_phys_page_debug

cpu_get_phys_page_debug is not in sync with cpu_x86_handle_mmu_fault:
the latter first checks CR0_PG_MASK and only after CR4_PAE_MASK.

This fixes odd gdb code display with PAE enabled.

---
 target-i386/helper.c |   37 ++++++++++++++++++++-----------------
 1 files changed, 20 insertions(+), 17 deletions(-)
target-i386/helper.c +20 -17
index bf206cf..7f5e8e3 100644
@@ -877,7 +877,11 @@ hwaddr cpu_get_phys_page_debug(CPUX86State *env, target_ulong addr)
     uint32_t page_offset;
     int page_size;
 
-    if (env->cr[4] & CR4_PAE_MASK) {
+    if (!(env->cr[0] & CR0_PG_MASK)) {
+        pte = addr;
+        page_size = 4096;
+        pte = pte & env->a20_mask;
+    } else if (env->cr[4] & CR4_PAE_MASK) {
         target_ulong pdpe_addr;
         uint64_t pde, pdpe;
 
@@ -935,26 +939,25 @@ hwaddr cpu_get_phys_page_debug(CPUX86State *env, target_ulong addr)
     } else {
         uint32_t pde;
 
-        if (!(env->cr[0] & CR0_PG_MASK)) {
-            pte = addr;
-            page_size = 4096;
+        /* page directory entry */
+        pde_addr = ((env->cr[3] & ~0xfff) + ((addr >> 20) & 0xffc)) &
+                env->a20_mask;
+        pde = ldl_phys(pde_addr);
+        if (!(pde & PG_PRESENT_MASK)) {
+            return -1;
+        }
+        if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
+            pte = pde & ~0x003ff000; /* align to 4MB */
+            page_size = 4096 * 1024;
         } else {
             /* page directory entry */
-            pde_addr = ((env->cr[3] & ~0xfff) + ((addr >> 20) & 0xffc)) & env->a20_mask;
-            pde = ldl_phys(pde_addr);
-            if (!(pde & PG_PRESENT_MASK))
+            pte_addr = ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) &
+                    env->a20_mask;
+            pte = ldl_phys(pte_addr);
+            if (!(pte & PG_PRESENT_MASK)) {
                 return -1;
-            if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
-                pte = pde & ~0x003ff000; /* align to 4MB */
-                page_size = 4096 * 1024;
-            } else {
-                /* page directory entry */
-                pte_addr = ((pde & ~0xfff) + ((addr >> 10) & 0xffc)) & env->a20_mask;
-                pte = ldl_phys(pte_addr);
-                if (!(pte & PG_PRESENT_MASK))
-                    return -1;
-                page_size = 4096;
             }
+            page_size = 4096;
         }
         pte = pte & env->a20_mask;
     }
Signature · 1 line
1.7.7.6
#1 lore raw
Quoted 9 lines · Max Filippov

cpu_get_phys_page_debug is not in sync with cpu_x86_handle_mmu_fault:
the latter first checks CR0_PG_MASK and only after CR4_PAE_MASK.

This fixes odd gdb code display with PAE enabled.

---
 target-i386/helper.c |   37 ++++++++++++++++++++-----------------
 1 files changed, 20 insertions(+), 17 deletions(-)

Ping?

Signature · 2 lines
Thanks.
-- Max
#2 lore raw
In reply to Max Filippov

Am 17.11.2012 21:52, schrieb Max Filippov:

Quoted 6 lines

cpu_get_phys_page_debug is not in sync with cpu_x86_handle_mmu_fault:
the latter first checks CR0_PG_MASK and only after CR4_PAE_MASK.

This fixes odd gdb code display with PAE enabled.

You write, they are "not in sync". Would it be possible to share code to assure this, e.g., by calling a helper function from both?

Regards,
Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#3 lore raw
Quoted 10 lines · Andreas Färber

Am 17.11.2012 21:52, schrieb Max Filippov:

Quoted 6 lines

cpu_get_phys_page_debug is not in sync with cpu_x86_handle_mmu_fault:
the latter first checks CR0_PG_MASK and only after CR4_PAE_MASK.

This fixes odd gdb code display with PAE enabled.

You write, they are "not in sync". Would it be possible to share code to assure this, e.g., by calling a helper function from both?

I'd say yes though that'd be a bigger change. I'll try to do it.

Signature · 2 lines
Thanks.
-- Max