1#include "vspace_dump.h" 2 3#include <barrelfish/vregion.h> 4#include <stdio.h> 5 6void dump_my_vregions(void) 7{ 8 struct vspace *vspace = get_current_vspace(); 9 struct vregion *walk = vspace->head; 10 11 while (walk != NULL) { 12 genvaddr_t base = vregion_get_base_addr(walk); 13 genvaddr_t size = vregion_get_size(walk); 14 printf("vregion at %"PRIxGENVADDR", size = %"PRIxGENVADDR"\n", base, size); 15 walk = walk->next; 16 } 17} 18 19#ifdef TARGET_X86_64_BARRELFISH_PMAP_H 20static int cmp_dump_info(const void *arg1, const void *arg2) 21{ 22 struct pmap_dump_info *info1, *info2; 23 info1 = (struct pmap_dump_info *)arg1; 24 info2 = (struct pmap_dump_info *)arg2; 25 26 if (info1->pml4_index < info2->pml4_index) 27 return -1; 28 if (info1->pml4_index > info2->pml4_index) 29 return 1; 30 31 // pml indices equal 32 33 if (info1->pdpt_index < info2->pdpt_index) 34 return -1; 35 if (info1->pdpt_index > info2->pdpt_index) 36 return 1; 37 38 // pdpt indices equal 39 40 if (info1->pdir_index < info2->pdir_index) 41 return -1; 42 if (info1->pdir_index > info2->pdir_index) 43 return 1; 44 45 // pdir indices equal 46 47 if (info1->pt_index < info2->pt_index) 48 return -1; 49 if (info1->pt_index > info2->pt_index) 50 return 1; 51 52 // pt indices equal 53 return 0; 54} 55#elif defined(TARGET_X86_32_BARRELFISH_PMAP_H) 56static int cmp_dump_info(const void *arg1, const void *arg2) 57{ 58 struct pmap_dump_info *info1, *info2; 59 info1 = (struct pmap_dump_info *)arg1; 60 info2 = (struct pmap_dump_info *)arg2; 61 62#if CONFIG_PAE 63 if (info1->pdpt_index < info2->pdpt_index) 64 return -1; 65 if (info1->pdpt_index > info2->pdpt_index) 66 return 1; 67 68 // pdpt indices equal 69#endif 70 71 if (info1->pdir_index < info2->pdir_index) 72 return -1; 73 if (info1->pdir_index > info2->pdir_index) 74 return 1; 75 76 // pdir indices equal 77 78 if (info1->pt_index < info2->pt_index) 79 return -1; 80 if (info1->pt_index > info2->pt_index) 81 return 1; 82 83 // pt indices equal 84 return 0; 85} 86#else 87static int cmp_dump_info(const void *arg1, const void *arg2) 88{ 89 return 0; 90} 91#endif 92 93#define BUFSIZE 8192 94void dump_pmap(struct pmap *pmap) 95{ 96 struct pmap_dump_info *buf = calloc(BUFSIZE, sizeof(struct pmap_dump_info)); 97 size_t items_written; 98 99 pmap->f.dump(pmap, buf, BUFSIZE, &items_written); 100 101 printf("items_written=%zd\n", items_written); 102 103 qsort(buf, items_written, sizeof(struct pmap_dump_info), cmp_dump_info); 104 105 for (size_t i = 0; i < items_written; i++) { 106 struct pmap_dump_info *info = buf+i; 107 struct frame_identity fi; 108 invoke_frame_identify(info->cap, &fi); 109 printf(PRIfmtPTIDX": 0x%"PRIxGENPADDR", 0x%"PRIxGENVADDR", 0x%zx\n", 110 GET_PTIDX(info), 111 fi.base, info->offset, ((size_t)1)<<fi.bits); 112 } 113 printf("\n"); 114 115 //puts(buf); 116} 117 118void dump_page_tables(void) 119{ 120 struct pmap *pmap = get_current_pmap(); 121 122 dump_pmap(pmap); 123} 124