add vm probing for x86_64
[lunaix-os.git] / lunaix-os / scripts / gdb / lunadbg / arch / x86 / pte.py
1 class PageTableHelperBase:
2     @staticmethod
3     def null_mapping(pte):
4         return pte == 0
5     
6     @staticmethod
7     def translation_level(level=-1):
8         raise NotImplementedError()
9     
10     @staticmethod
11     def translation_shift_bits(level):
12         raise NotImplementedError()
13     
14     @staticmethod
15     def mapping_present(pte):
16         raise NotImplementedError()
17     
18     @staticmethod
19     def huge_page(pte):
20         raise NotImplementedError()
21     
22     @staticmethod
23     def protections(pte):
24         raise NotImplementedError()
25     
26     @staticmethod
27     def other_attributes(level, pte):
28         raise NotImplementedError()
29     
30     @staticmethod
31     def same_kind(pte1, pte2):
32         raise NotImplementedError()
33     
34     @staticmethod
35     def physical_pfn(pte):
36         raise NotImplementedError()
37     
38     @staticmethod
39     def vaddr_width():
40         raise NotImplementedError()
41     
42     @staticmethod
43     def pte_size():
44         raise NotImplementedError()
45
46 class PageTableHelper32(PageTableHelperBase):
47     @staticmethod
48     def null_mapping(pte):
49         return pte == 0
50     
51     @staticmethod
52     def translation_level(level = -1):
53         return [0, 1][level]
54     
55     @staticmethod
56     def pgtable_len():
57         return (1 << 10)
58     
59     @staticmethod
60     def translation_shift_bits(level):
61         return [10, 0][level] + 12
62     
63     @staticmethod
64     def mapping_present(pte):
65         return bool(pte & 1)
66     
67     @staticmethod
68     def huge_page(pte, po):
69         return bool(pte & (1 << 7)) and po 
70     
71     @staticmethod
72     def protections(pte):
73         prot = ['R'] # RWXUP
74         if (pte & (1 << 1)):
75             prot.append('W')
76         if (pte & -1):
77             prot.append('X')
78         if (pte & (1 << 2)):
79             prot.append('U')
80         if (pte & (1)):
81             prot.append('P')
82         return prot
83     
84     @staticmethod
85     def other_attributes(level, pte):
86         attrs = []
87         if pte & (1 << 5):
88             attrs.append("A")
89         if pte & (1 << 6):
90             attrs.append("D")
91         if pte & (1 << 3):
92             attrs.append("PWT")
93         if pte & (1 << 4):
94             attrs.append("PCD")
95         if PageTableHelper32.translation_level(level) == 1 and pte & (1 << 8):
96             attrs.append("G")
97         return attrs
98     
99     @staticmethod
100     def same_kind(pte1, pte2):
101         attr_mask = 0x19f  # P, R/W, U/S, PWT, PCD, PS, G
102         return (pte1 & attr_mask) == (pte2 & attr_mask)
103     
104     @staticmethod
105     def physical_pfn(pte):
106         return pte >> 12
107     
108     @staticmethod
109     def vaddr_width():
110         return 32
111     
112     @staticmethod
113     def pte_size():
114         return 4
115     
116     @staticmethod
117     def vm_mnt():
118         return 0xFFC00000
119
120 class PageTableHelper64(PageTableHelperBase):
121     @staticmethod
122     def null_mapping(pte):
123         return pte == 0
124     
125     @staticmethod
126     def translation_level(level = -1):
127         return [0, 1, 2, 3][level]
128     
129     @staticmethod
130     def pgtable_len():
131         return (1 << 9)
132     
133     @staticmethod
134     def translation_shift_bits(level):
135         return [9, 9, 9, 0][level] + 12
136     
137     @staticmethod
138     def mapping_present(pte):
139         return bool(pte & 1)
140     
141     @staticmethod
142     def huge_page(pte, po):
143         return bool(pte & (1 << 7)) and po 
144     
145     @staticmethod
146     def protections(pte):
147         prot = ['R'] # RWXUP
148         if (pte & (1 << 1)):
149             prot.append('W')
150         if (pte & -1):
151             prot.append('X')
152         if (pte & (1 << 2)):
153             prot.append('U')
154         if (pte & (1)):
155             prot.append('P')
156         return prot
157     
158     @staticmethod
159     def other_attributes(level, pte):
160         attrs = []
161         if pte & (1 << 5):
162             attrs.append("A")
163         if pte & (1 << 6):
164             attrs.append("D")
165         if pte & (1 << 3):
166             attrs.append("PWT")
167         if pte & (1 << 4):
168             attrs.append("PCD")
169         if PageTableHelper32.translation_level(level) == 1 and pte & (1 << 8):
170             attrs.append("G")
171         return attrs
172     
173     @staticmethod
174     def same_kind(pte1, pte2):
175         attr_mask = 0x19f  # P, R/W, U/S, PWT, PCD, PS, G
176         return (pte1 & attr_mask) == (pte2 & attr_mask)
177     
178     @staticmethod
179     def physical_pfn(pte):
180         return pte >> 12
181     
182     @staticmethod
183     def vaddr_width():
184         return 48
185     
186     @staticmethod
187     def pte_size():
188         return 8
189     
190     @staticmethod
191     def vm_mnt():
192         return 0xffffff0000000000