Print this page
9723 provide support for VMM's GDT handling
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>


 887                         mdb_warn("failed to read feature array %d", ii);
 888                         mdb_free(fset, sz);
 889                         return (DCMD_ERR);
 890                 }
 891 
 892                 if (mdb_readstr(name, sizeof (name), nptr) == -1) {
 893                         mdb_warn("failed to read feature %d", ii);
 894                         mdb_free(fset, sz);
 895                         return (DCMD_ERR);
 896                 }
 897                 mdb_printf("%s\n", name);
 898         }
 899 
 900         mdb_free(fset, sz);
 901         return (DCMD_OK);
 902 }
 903 
 904 #ifdef _KMDB
 905 /* ARGSUSED */
 906 static int
 907 crregs_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
 908 {
 909         ulong_t cr0, cr2, cr3, cr4;


 910         static const mdb_bitmask_t cr0_flag_bits[] = {
 911                 { "PE",         CR0_PE,         CR0_PE },
 912                 { "MP",         CR0_MP,         CR0_MP },
 913                 { "EM",         CR0_EM,         CR0_EM },
 914                 { "TS",         CR0_TS,         CR0_TS },
 915                 { "ET",         CR0_ET,         CR0_ET },
 916                 { "NE",         CR0_NE,         CR0_NE },
 917                 { "WP",         CR0_WP,         CR0_WP },
 918                 { "AM",         CR0_AM,         CR0_AM },
 919                 { "NW",         CR0_NW,         CR0_NW },
 920                 { "CD",         CR0_CD,         CR0_CD },
 921                 { "PG",         CR0_PG,         CR0_PG },
 922                 { NULL,         0,              0 }
 923         };
 924 
 925         static const mdb_bitmask_t cr3_flag_bits[] = {
 926                 { "PCD",        CR3_PCD,        CR3_PCD },
 927                 { "PWT",        CR3_PWT,        CR3_PWT },
 928                 { NULL,         0,              0, }
 929         };


 936                 { "PSE",        CR4_PSE,        CR4_PSE },
 937                 { "PAE",        CR4_PAE,        CR4_PAE },
 938                 { "MCE",        CR4_MCE,        CR4_MCE },
 939                 { "PGE",        CR4_PGE,        CR4_PGE },
 940                 { "PCE",        CR4_PCE,        CR4_PCE },
 941                 { "OSFXSR",     CR4_OSFXSR,     CR4_OSFXSR },
 942                 { "OSXMMEXCPT", CR4_OSXMMEXCPT, CR4_OSXMMEXCPT },
 943                 { "VMXE",       CR4_VMXE,       CR4_VMXE },
 944                 { "SMXE",       CR4_SMXE,       CR4_SMXE },
 945                 { "PCIDE",      CR4_PCIDE,      CR4_PCIDE },
 946                 { "OSXSAVE",    CR4_OSXSAVE,    CR4_OSXSAVE },
 947                 { "SMEP",       CR4_SMEP,       CR4_SMEP },
 948                 { "SMAP",       CR4_SMAP,       CR4_SMAP },
 949                 { NULL,         0,              0 }
 950         };
 951 
 952         cr0 = kmdb_unix_getcr0();
 953         cr2 = kmdb_unix_getcr2();
 954         cr3 = kmdb_unix_getcr3();
 955         cr4 = kmdb_unix_getcr4();



 956         mdb_printf("%%cr0 = 0x%lx <%b>\n", cr0, cr0, cr0_flag_bits);
 957         mdb_printf("%%cr2 = 0x%lx <%a>\n", cr2, cr2);
 958 
 959         if ((cr4 & CR4_PCIDE)) {
 960                 mdb_printf("%%cr3 = 0x%lx <pfn:0x%lx pcid:%lu>\n", cr3,
 961                     cr3 >> MMU_PAGESHIFT, cr3 & MMU_PAGEOFFSET);
 962         } else {
 963                 mdb_printf("%%cr3 = 0x%lx <pfn:0x%lx flags:%b>\n", cr3,
 964                     cr3 >> MMU_PAGESHIFT, cr3, cr3_flag_bits);
 965         }
 966 
 967         mdb_printf("%%cr4 = 0x%lx <%b>\n", cr4, cr4, cr4_flag_bits);
 968 



 969         return (DCMD_OK);
 970 }
 971 #endif
 972 
 973 static const mdb_dcmd_t dcmds[] = {
 974         { "gate_desc", ":", "dump a gate descriptor", gate_desc },
 975         { "idt", ":[-v]", "dump an IDT", idt },
 976         { "ttrace", "[-x] [-t kthread]", "dump trap trace buffers", ttrace },
 977         { "vatopfn", ":[-a as]", "translate address to physical page",
 978             va2pfn_dcmd },
 979         { "report_maps", ":[-m]",
 980             "Given PFN, report mappings / page table usage",
 981             report_maps_dcmd, report_maps_help },
 982         { "htables", "", "Given hat_t *, lists all its htable_t * values",
 983             htables_dcmd, htables_help },
 984         { "ptable", ":[-lm]", "Given PFN, dump contents of a page table",
 985             ptable_dcmd, ptable_help },
 986         { "ptmap", ":", "Given a cr3 value, dump all mappings",
 987             ptmap_dcmd, ptmap_help },
 988         { "pte", ":[-l N]", "print human readable page table entry",
 989             pte_dcmd },
 990         { "pfntomfn", ":", "convert physical page to hypervisor machine page",
 991             pfntomfn_dcmd },
 992         { "mfntopfn", ":", "convert hypervisor machine page to physical page",
 993             mfntopfn_dcmd },
 994         { "memseg_list", ":", "show memseg list", memseg_list },
 995         { "scalehrtime", ":",
 996             "scale an unscaled high-res time", scalehrtime_cmd },
 997         { "x86_featureset", NULL, "dump the x86_featureset vector",
 998                 x86_featureset_cmd },
 999 #ifdef _KMDB
1000         { "crregs", NULL, "dump control registers", crregs_dcmd },
1001 #endif
1002         { NULL }
1003 };
1004 
1005 static const mdb_walker_t walkers[] = {
1006         { "ttrace", "walks trap trace buffers in reverse chronological order",
1007                 ttrace_walk_init, ttrace_walk_step, ttrace_walk_fini },
1008         { "mutex_owner", "walks the owner of a mutex",
1009                 mutex_owner_init, mutex_owner_step },
1010         { "memseg", "walk the memseg structures",
1011                 memseg_walk_init, memseg_walk_step, memseg_walk_fini },
1012         { NULL }
1013 };
1014 
1015 static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers };
1016 
1017 const mdb_modinfo_t *
1018 _mdb_init(void)
1019 {
1020         return (&modinfo);


 887                         mdb_warn("failed to read feature array %d", ii);
 888                         mdb_free(fset, sz);
 889                         return (DCMD_ERR);
 890                 }
 891 
 892                 if (mdb_readstr(name, sizeof (name), nptr) == -1) {
 893                         mdb_warn("failed to read feature %d", ii);
 894                         mdb_free(fset, sz);
 895                         return (DCMD_ERR);
 896                 }
 897                 mdb_printf("%s\n", name);
 898         }
 899 
 900         mdb_free(fset, sz);
 901         return (DCMD_OK);
 902 }
 903 
 904 #ifdef _KMDB
 905 /* ARGSUSED */
 906 static int
 907 sysregs_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
 908 {
 909         ulong_t cr0, cr2, cr3, cr4;
 910         desctbr_t gdtr;
 911 
 912         static const mdb_bitmask_t cr0_flag_bits[] = {
 913                 { "PE",         CR0_PE,         CR0_PE },
 914                 { "MP",         CR0_MP,         CR0_MP },
 915                 { "EM",         CR0_EM,         CR0_EM },
 916                 { "TS",         CR0_TS,         CR0_TS },
 917                 { "ET",         CR0_ET,         CR0_ET },
 918                 { "NE",         CR0_NE,         CR0_NE },
 919                 { "WP",         CR0_WP,         CR0_WP },
 920                 { "AM",         CR0_AM,         CR0_AM },
 921                 { "NW",         CR0_NW,         CR0_NW },
 922                 { "CD",         CR0_CD,         CR0_CD },
 923                 { "PG",         CR0_PG,         CR0_PG },
 924                 { NULL,         0,              0 }
 925         };
 926 
 927         static const mdb_bitmask_t cr3_flag_bits[] = {
 928                 { "PCD",        CR3_PCD,        CR3_PCD },
 929                 { "PWT",        CR3_PWT,        CR3_PWT },
 930                 { NULL,         0,              0, }
 931         };


 938                 { "PSE",        CR4_PSE,        CR4_PSE },
 939                 { "PAE",        CR4_PAE,        CR4_PAE },
 940                 { "MCE",        CR4_MCE,        CR4_MCE },
 941                 { "PGE",        CR4_PGE,        CR4_PGE },
 942                 { "PCE",        CR4_PCE,        CR4_PCE },
 943                 { "OSFXSR",     CR4_OSFXSR,     CR4_OSFXSR },
 944                 { "OSXMMEXCPT", CR4_OSXMMEXCPT, CR4_OSXMMEXCPT },
 945                 { "VMXE",       CR4_VMXE,       CR4_VMXE },
 946                 { "SMXE",       CR4_SMXE,       CR4_SMXE },
 947                 { "PCIDE",      CR4_PCIDE,      CR4_PCIDE },
 948                 { "OSXSAVE",    CR4_OSXSAVE,    CR4_OSXSAVE },
 949                 { "SMEP",       CR4_SMEP,       CR4_SMEP },
 950                 { "SMAP",       CR4_SMAP,       CR4_SMAP },
 951                 { NULL,         0,              0 }
 952         };
 953 
 954         cr0 = kmdb_unix_getcr0();
 955         cr2 = kmdb_unix_getcr2();
 956         cr3 = kmdb_unix_getcr3();
 957         cr4 = kmdb_unix_getcr4();
 958 
 959         kmdb_unix_getgdtr(&gdtr);
 960 
 961         mdb_printf("%%cr0 = 0x%lx <%b>\n", cr0, cr0, cr0_flag_bits);
 962         mdb_printf("%%cr2 = 0x%lx <%a>\n", cr2, cr2);
 963 
 964         if ((cr4 & CR4_PCIDE)) {
 965                 mdb_printf("%%cr3 = 0x%lx <pfn:0x%lx pcid:%lu>\n", cr3,
 966                     cr3 >> MMU_PAGESHIFT, cr3 & MMU_PAGEOFFSET);
 967         } else {
 968                 mdb_printf("%%cr3 = 0x%lx <pfn:0x%lx flags:%b>\n", cr3,
 969                     cr3 >> MMU_PAGESHIFT, cr3, cr3_flag_bits);
 970         }
 971 
 972         mdb_printf("%%cr4 = 0x%lx <%b>\n", cr4, cr4, cr4_flag_bits);
 973 
 974         mdb_printf("%%gdtr.base = 0x%lx, %%gdtr.limit = 0x%hx\n",
 975             gdtr.dtr_base, gdtr.dtr_limit);
 976 
 977         return (DCMD_OK);
 978 }
 979 #endif
 980 
 981 static const mdb_dcmd_t dcmds[] = {
 982         { "gate_desc", ":", "dump a gate descriptor", gate_desc },
 983         { "idt", ":[-v]", "dump an IDT", idt },
 984         { "ttrace", "[-x] [-t kthread]", "dump trap trace buffers", ttrace },
 985         { "vatopfn", ":[-a as]", "translate address to physical page",
 986             va2pfn_dcmd },
 987         { "report_maps", ":[-m]",
 988             "Given PFN, report mappings / page table usage",
 989             report_maps_dcmd, report_maps_help },
 990         { "htables", "", "Given hat_t *, lists all its htable_t * values",
 991             htables_dcmd, htables_help },
 992         { "ptable", ":[-lm]", "Given PFN, dump contents of a page table",
 993             ptable_dcmd, ptable_help },
 994         { "ptmap", ":", "Given a cr3 value, dump all mappings",
 995             ptmap_dcmd, ptmap_help },
 996         { "pte", ":[-l N]", "print human readable page table entry",
 997             pte_dcmd },
 998         { "pfntomfn", ":", "convert physical page to hypervisor machine page",
 999             pfntomfn_dcmd },
1000         { "mfntopfn", ":", "convert hypervisor machine page to physical page",
1001             mfntopfn_dcmd },
1002         { "memseg_list", ":", "show memseg list", memseg_list },
1003         { "scalehrtime", ":",
1004             "scale an unscaled high-res time", scalehrtime_cmd },
1005         { "x86_featureset", NULL, "dump the x86_featureset vector",
1006                 x86_featureset_cmd },
1007 #ifdef _KMDB
1008         { "sysregs", NULL, "dump system registers", sysregs_dcmd },
1009 #endif
1010         { NULL }
1011 };
1012 
1013 static const mdb_walker_t walkers[] = {
1014         { "ttrace", "walks trap trace buffers in reverse chronological order",
1015                 ttrace_walk_init, ttrace_walk_step, ttrace_walk_fini },
1016         { "mutex_owner", "walks the owner of a mutex",
1017                 mutex_owner_init, mutex_owner_step },
1018         { "memseg", "walk the memseg structures",
1019                 memseg_walk_init, memseg_walk_step, memseg_walk_fini },
1020         { NULL }
1021 };
1022 
1023 static const mdb_modinfo_t modinfo = { MDB_API_VERSION, dcmds, walkers };
1024 
1025 const mdb_modinfo_t *
1026 _mdb_init(void)
1027 {
1028         return (&modinfo);