updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / qemu-6828 / info-pg
blob8351d5c00dd35bb0dae3e305641bf99c02b988b2
1 # HG changeset patch
2 # Parent 4a8ebab4db51ea6b64c53788092f9565f0d4236a
4 diff -r 4a8ebab4db51 monitor.c
5 --- a/monitor.c Fri Aug 27 03:15:33 2010 -0400
6 +++ b/monitor.c Fri Aug 27 04:06:18 2010 -0400
7 @@ -1841,6 +1841,112 @@
8          }
9      }
10  }
12 +static void pg_print(Monitor *mon, uint32_t *pstart, int *plast_prot,
13 +                     uint32_t end, int prot,
14 +                     uint32_t *pde_next, int *pde_last_prot,
15 +                     int pde_prot)
17 +    int prot1;
18 +    prot1 = *plast_prot;
19 +    if (prot != prot1) {
20 +        if (*pstart != -1) {
21 +            uint32_t pde_start = *pstart & ~((1 << 22) - 1);
22 +            if (*pde_last_prot != pde_prot && pde_start >= *pde_next &&
23 +                !(prot1 & PG_PSE_MASK)) {
24 +                *pde_next = (end + ((1 << 22) - 1)) & ~((1 << 22) - 1);
25 +                monitor_printf(mon, "PDE(%03x) %08x-%08x %08x %c%c%c\n",
26 +                               (*pde_next - pde_start) / (1 << 22),
27 +                               pde_start, *pde_next, *pde_next - pde_start,
28 +                               pde_prot & PG_USER_MASK ? 'u' : '-',
29 +                               'r',
30 +                               pde_prot & PG_RW_MASK ? 'w' : '-');
31 +                *pde_last_prot = 0;
32 +            }
34 +            if (prot1 & PG_PSE_MASK) {
35 +                monitor_printf(mon, " PDES(%03x) %08x-%08x %08x %c%c%c\n",
36 +                               (end - *pstart) / (1 << 22),
37 +                               *pstart, end, end - *pstart,
38 +                               prot1 & PG_USER_MASK ? 'u' : '-',
39 +                               'r',
40 +                               prot1 & PG_RW_MASK ? 'w' : '-');
41 +            } else {
42 +                monitor_printf(mon, " |-- PTE(%06x) %08x-%08x %08x %c%c%c\n",
43 +                               (end - *pstart) / (1 << 12),
44 +                               *pstart, end, end - *pstart,
45 +                               prot1 & PG_USER_MASK ? 'u' : '-',
46 +                               'r',
47 +                               prot1 & PG_RW_MASK ? 'w' : '-');
48 +            }
49 +        }
50 +        if (prot != 0)
51 +            *pstart = end;
52 +        else
53 +            *pstart = -1;
54 +        *plast_prot = prot;
55 +    }
58 +static void pg_info(Monitor *mon)
60 +    CPUState *env;
61 +    int l1, l2, prot, last_prot;
62 +    uint32_t pgd, pde, pte, start, end;
64 +    int pde_prot, pde_last_prot;
65 +    uint32_t pde_start, pde_end;
67 +    env = mon_get_cpu();
68 +    if (!env)
69 +        return;
71 +    if (!(env->cr[0] & CR0_PG_MASK)) {
72 +        monitor_printf(mon, "PG disabled\n");
73 +        return;
74 +    }
75 +    pgd = env->cr[3] & ~0xfff;
76 +    last_prot = 0;
77 +    pde_last_prot = 0;
78 +    start = -1;
79 +    pde_start = 0;
80 +    for(l1 = 0; l1 < 1024; l1++) {
81 +        cpu_physical_memory_read(pgd + l1 * 4, (uint8_t *)&pde, 4);
82 +        pde = le32_to_cpu(pde);
83 +        end = l1 << 22;
84 +        pde_end = l1 << 22;
85 +        pde_prot = pde & (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK);
86 +        if (pde & PG_PRESENT_MASK) {
87 +            if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
88 +                prot = pde & (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK |
89 +                              PG_PSE_MASK);
90 +                pg_print(mon, &start, &last_prot, end, prot,
91 +                         &pde_start, &pde_last_prot, pde_prot);
92 +            } else {
93 +                for(l2 = 0; l2 < 1024; l2++) {
94 +                    cpu_physical_memory_read((pde & ~0xfff) + l2 * 4,
95 +                                             (uint8_t *)&pte, 4);
96 +                    pte = le32_to_cpu(pte);
97 +                    end = (l1 << 22) + (l2 << 12);
98 +                    if (pte & PG_PRESENT_MASK) {
99 +                        prot = pte & (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK);
100 +                    } else {
101 +                        prot = 0;
102 +                    }
103 +                    pg_print(mon, &start, &last_prot, end, prot,
104 +                             &pde_start, &pde_last_prot, pde_prot);
105 +                }
106 +            }
107 +        } else {
108 +            prot = 0;
109 +            pg_print(mon, &start, &last_prot, end, prot,
110 +                     &pde_start, &pde_last_prot, pde_prot);
111 +        }
112 +    }
114 +    pg_print(mon, &start, &last_prot, 1024 << 22, 0,
115 +             &pde_start, &pde_last_prot, pde_prot);
117  #endif
119  #if defined(TARGET_SH4)
120 @@ -2459,6 +2565,13 @@
121          .mhandler.info = mem_info,
122      },
123      {
124 +        .name       = "pg",
125 +        .args_type  = "",
126 +        .params     = "",
127 +        .help       = "show the page table",
128 +        .mhandler.info = pg_info,
129 +    },
130 +    {
131          .name       = "hpet",
132          .args_type  = "",
133          .params     = "",