Commit b86bda5bb193aa47ee95c43ec31d899b52b45645

Authored by bellard
1 parent e2731add

adde TLB dump


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1069 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 117 additions and 0 deletions
monitor.c
... ... @@ -695,6 +695,117 @@ static void do_system_reset(void)
695 695 qemu_system_reset_request();
696 696 }
697 697  
  698 +#if defined(TARGET_I386)
  699 +static void print_pte(uint32_t addr, uint32_t pte, uint32_t mask)
  700 +{
  701 + term_printf("%08x: %08x %c%c%c%c%c%c%c%c\n",
  702 + addr,
  703 + pte & mask,
  704 + pte & PG_GLOBAL_MASK ? 'G' : '-',
  705 + pte & PG_PSE_MASK ? 'P' : '-',
  706 + pte & PG_DIRTY_MASK ? 'D' : '-',
  707 + pte & PG_ACCESSED_MASK ? 'A' : '-',
  708 + pte & PG_PCD_MASK ? 'C' : '-',
  709 + pte & PG_PWT_MASK ? 'T' : '-',
  710 + pte & PG_USER_MASK ? 'U' : '-',
  711 + pte & PG_RW_MASK ? 'W' : '-');
  712 +}
  713 +
  714 +static void tlb_info(void)
  715 +{
  716 + CPUState *env = cpu_single_env;
  717 + int l1, l2;
  718 + uint32_t pgd, pde, pte;
  719 +
  720 + if (!(env->cr[0] & CR0_PG_MASK)) {
  721 + term_printf("PG disabled\n");
  722 + return;
  723 + }
  724 + pgd = env->cr[3] & ~0xfff;
  725 + for(l1 = 0; l1 < 1024; l1++) {
  726 + cpu_physical_memory_read(pgd + l1 * 4, (uint8_t *)&pde, 4);
  727 + pde = le32_to_cpu(pde);
  728 + if (pde & PG_PRESENT_MASK) {
  729 + if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
  730 + print_pte((l1 << 22), pde, ~((1 << 20) - 1));
  731 + } else {
  732 + for(l2 = 0; l2 < 1024; l2++) {
  733 + cpu_physical_memory_read((pde & ~0xfff) + l2 * 4,
  734 + (uint8_t *)&pte, 4);
  735 + pte = le32_to_cpu(pte);
  736 + if (pte & PG_PRESENT_MASK) {
  737 + print_pte((l1 << 22) + (l2 << 12),
  738 + pte & ~PG_PSE_MASK,
  739 + ~0xfff);
  740 + }
  741 + }
  742 + }
  743 + }
  744 + }
  745 +}
  746 +
  747 +static void mem_print(uint32_t *pstart, int *plast_prot,
  748 + uint32_t end, int prot)
  749 +{
  750 + if (prot != *plast_prot) {
  751 + if (*pstart != -1) {
  752 + term_printf("%08x-%08x %08x %c%c%c\n",
  753 + *pstart, end, end - *pstart,
  754 + prot & PG_USER_MASK ? 'u' : '-',
  755 + 'r',
  756 + prot & PG_RW_MASK ? 'w' : '-');
  757 + }
  758 + if (prot != 0)
  759 + *pstart = end;
  760 + else
  761 + *pstart = -1;
  762 + *plast_prot = prot;
  763 + }
  764 +}
  765 +
  766 +static void mem_info(void)
  767 +{
  768 + CPUState *env = cpu_single_env;
  769 + int l1, l2, prot, last_prot;
  770 + uint32_t pgd, pde, pte, start, end;
  771 +
  772 + if (!(env->cr[0] & CR0_PG_MASK)) {
  773 + term_printf("PG disabled\n");
  774 + return;
  775 + }
  776 + pgd = env->cr[3] & ~0xfff;
  777 + last_prot = 0;
  778 + start = -1;
  779 + for(l1 = 0; l1 < 1024; l1++) {
  780 + cpu_physical_memory_read(pgd + l1 * 4, (uint8_t *)&pde, 4);
  781 + pde = le32_to_cpu(pde);
  782 + end = l1 << 22;
  783 + if (pde & PG_PRESENT_MASK) {
  784 + if ((pde & PG_PSE_MASK) && (env->cr[4] & CR4_PSE_MASK)) {
  785 + prot = pde & (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK);
  786 + mem_print(&start, &last_prot, end, prot);
  787 + } else {
  788 + for(l2 = 0; l2 < 1024; l2++) {
  789 + cpu_physical_memory_read((pde & ~0xfff) + l2 * 4,
  790 + (uint8_t *)&pte, 4);
  791 + pte = le32_to_cpu(pte);
  792 + end = (l1 << 22) + (l2 << 12);
  793 + if (pte & PG_PRESENT_MASK) {
  794 + prot = pte & (PG_USER_MASK | PG_RW_MASK | PG_PRESENT_MASK);
  795 + } else {
  796 + prot = 0;
  797 + }
  798 + mem_print(&start, &last_prot, end, prot);
  799 + }
  800 + }
  801 + } else {
  802 + prot = 0;
  803 + mem_print(&start, &last_prot, end, prot);
  804 + }
  805 + }
  806 +}
  807 +#endif
  808 +
698 809 static term_cmd_t term_cmds[] = {
699 810 { "help|?", "s?", do_help,
700 811 "[cmd]", "show the help" },
... ... @@ -755,6 +866,12 @@ static term_cmd_t info_cmds[] = {
755 866 "", "show i8259 (PIC) state", },
756 867 { "pci", "", pci_info,
757 868 "", "show PCI info", },
  869 +#if defined(TARGET_I386)
  870 + { "tlb", "", tlb_info,
  871 + "", "show virtual to physical memory mappings", },
  872 + { "mem", "", mem_info,
  873 + "", "show the active virtual memory mappings", },
  874 +#endif
758 875 { NULL, NULL, },
759 876 };
760 877  
... ...