Support to multi-threading and pthread interface (POSIX.1-2008) (#23)
[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 class PageTableHelper32(PageTableHelperBase):
43     @staticmethod
44     def translation_level(level = -1):
45         return [0, 1][level]
46     
47     @staticmethod
48     def translation_shift_bits(level):
49         return [9, 0][level] + 12
50     
51     @staticmethod
52     def mapping_present(pte):
53         return bool(pte & 1)
54     
55     @staticmethod
56     def huge_page(pte):
57         return bool(pte & (1 << 7))
58     
59     @staticmethod
60     def protections(pte):
61         prot = ['R'] # RWXUP
62         if (pte & (1 << 1)):
63             prot.append('W')
64         if (pte & -1):
65             prot.append('X')
66         if (pte & (1 << 2)):
67             prot.append('U')
68         if (pte & (1)):
69             prot.append('P')
70         return prot
71     
72     @staticmethod
73     def other_attributes(level, pte):
74         attrs = []
75         if pte & (1 << 5):
76             attrs.append("A")
77         if pte & (1 << 6):
78             attrs.append("D")
79         if pte & (1 << 3):
80             attrs.append("PWT")
81         if pte & (1 << 4):
82             attrs.append("PCD")
83         if PageTableHelper32.translation_level(level) == 1 and pte & (1 << 8):
84             attrs.append("G")
85         return attrs
86     
87     @staticmethod
88     def same_kind(pte1, pte2):
89         attr_mask = 0x19f  # P, R/W, U/S, PWT, PCD, PS, G
90         return (pte1 & attr_mask) == (pte2 & attr_mask)
91     
92     @staticmethod
93     def physical_pfn(pte):
94         return pte >> 12
95     
96     @staticmethod
97     def vaddr_width():
98         return 32
99
100 class PageTableHelper64(PageTableHelperBase):
101     pass