]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/arm/paging-arm.cpp
update
[l4.git] / kernel / fiasco / src / kern / arm / paging-arm.cpp
1 INTERFACE [arm]:
2
3 #include "pages.h"
4
5 class PF {};
6
7 //-----------------------------------------------------------------------------
8 INTERFACE [arm && armv5]:
9
10 #include "types.h"
11
12
13 namespace Page
14 {
15   typedef Unsigned32 Attribs;
16
17   enum Attribs_enum
18   {
19     KERN_RW  = 0x0400, ///< User No access
20     USER_RO  = 0x0000, ///< User Read only
21     USER_RW  = 0x0c00, ///< User Read/Write
22
23     USER_BIT = 0x00800,
24
25     Cache_mask    = 0x0c,
26     NONCACHEABLE  = 0x00, ///< Caching is off
27     CACHEABLE     = 0x0c, ///< Cache is enabled
28
29     // The next are ARM specific
30     WRITETHROUGH = 0x08, ///< Write through cached
31     BUFFERED     = 0x04, ///< Write buffer enabled
32
33     MAX_ATTRIBS  = 0x0dec,
34     Local_page   = 0,
35   };
36 };
37
38
39
40
41
42 //----------------------------------------------------------------------------
43 INTERFACE [arm && (armv6 || armv7)]:
44
45 #include "types.h"
46
47 namespace Page
48 {
49   typedef Unsigned32 Attribs;
50
51   enum Attribs_enum
52   {
53     KERN_RO  = 0x0210,
54     KERN_RW  = 0x0010, ///< User No access
55     USER_RO  = 0x0230, ///< User Read only
56     USER_RW  = 0x0030, ///< User Read/Write
57
58     USER_BIT = 0x0020,
59
60     Cache_mask    = 0x1cc,
61     NONCACHEABLE  = 0x000, ///< Caching is off
62     CACHEABLE     = 0x144, ///< Cache is enabled
63
64     // The next are ARM specific
65     WRITETHROUGH = 0x08, ///< Write through cached
66     BUFFERED     = 0x04, ///< Write buffer enabled
67
68     MAX_ATTRIBS  = 0x0ffc,
69     Local_page   = 0x800,
70   };
71 };
72
73
74 //-----------------------------------------------------------------------------
75 INTERFACE [arm]:
76
77 #include "mapped_alloc.h"
78 #include "ptab_base.h"
79
80
81 // dummy for JDB
82 class Pte_base
83 {
84 public:
85   enum
86   {
87     Super_level    = 0,
88     Valid          = 0x3,
89     Type_mask      = 0x3,
90     Type_1MB       = 0x2,
91     Type_4KB       = 0x2,
92     Type_coarse_pt = 0x1,
93   };
94   typedef Mword Raw;
95   Raw raw() const  { return _raw; }
96   Address addr() const { return _raw & (~0UL << 12); }
97
98 protected:
99   Raw _raw;
100 };
101
102 class Pd_entry : public Pte_base
103 {
104 public:
105   enum { Page_shift = Config::SUPERPAGE_SHIFT };
106   Mword leaf() const { return (_raw & Type_mask) == Type_1MB; }
107   void set(Address p, bool intermed, bool present, unsigned long attrs = 0)
108   {
109     _raw = (p & (~0UL << Page_shift))
110       | (present ? (intermed ? Type_coarse_pt : Type_1MB) : 0) | attrs;
111   }
112 };
113
114 class Pt_entry : public Pte_base
115 {
116 public:
117   enum { Page_shift = Config::PAGE_SHIFT };
118   Mword leaf() const { return true; }
119   void set(Address p, bool, bool present, unsigned long attrs = 0)
120   {
121     _raw = (p & (~0UL << Page_shift)) | (present ? Type_4KB : 0) | attrs;
122   }
123 };
124
125 typedef Ptab::List< Ptab::Traits< Pd_entry, 20, 12, true>,
126                     Ptab::Traits< Pt_entry, 12, 8, true> > Ptab_traits;
127
128 typedef Ptab_traits Ptab_traits_vpn;
129 typedef Ptab::Page_addr_wrap<Virt_addr, 0> Ptab_va_vpn;
130
131 //---------------------------------------------------------------------------
132 IMPLEMENTATION [arm && armv5]:
133
134 PUBLIC static inline
135 Mword PF::is_alignment_error(Mword error)
136 { return (error & 0xf0000d) == 0x400001; }
137
138 //---------------------------------------------------------------------------
139 IMPLEMENTATION [arm && (armv6 || armv7)]:
140
141 PUBLIC static inline
142 Mword PF::is_alignment_error(Mword error)
143 { return (error & 0xf0040f) == 0x400001; }
144
145 //---------------------------------------------------------------------------
146 IMPLEMENTATION [arm]:
147
148 PUBLIC inline
149 void
150 Pte_base::clear()
151 { _raw = 0; }
152
153 PUBLIC inline
154 int
155 Pte_base::valid() const
156 {
157   return _raw & Valid;
158 }
159
160 IMPLEMENT inline
161 Mword PF::is_translation_error( Mword error )
162 {
163   return (error & 0x0d/*FSR_STATUS_MASK*/) == 0x05/*FSR_TRANSL*/;
164 }
165
166 IMPLEMENT inline
167 Mword PF::is_usermode_error( Mword error )
168 {
169   return (error & 0x00010000/*PF_USERMODE*/);
170 }
171
172 IMPLEMENT inline
173 Mword PF::is_read_error( Mword error )
174 {
175   return !(error & (1UL << 11));
176 }
177
178 IMPLEMENT inline
179 Mword PF::addr_to_msgword0( Address pfa, Mword error )
180 {
181   Mword a = pfa & ~3;
182   if(is_translation_error( error ))
183     a |= 1;
184   if(!is_read_error(error))
185     a |= 2;
186   return a;
187 }
188