]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/kern/mapping.cpp
a7d4090aa2f61fdcb7df961dae64d938baeb54dc
[l4.git] / kernel / fiasco / src / kern / mapping.cpp
1 INTERFACE:
2
3 #include "types.h"
4
5 class Space;
6 /** Represents one mapping in a mapping tree.
7     Instances of Mapping ("mappings") work as an iterator over a
8     mapping tree.  Mapping trees are never visible on the user level.
9     Mappings are looked up directly in the mapping database (class
10     Mapdb) using Mapdb::lookup().  When carrying out such a
11     lookup, the mapping database locks the corresponding mapping tree
12     before returning the mapping.  This mapping can the be used to
13     iterate over the tree and to look up other mappings in the tree.
14     The mapping tree is unlocked (and all mappings pointing into it
15     become invalid) when Mapdb::free is called with any one of its
16     mappings.
17  */
18 class Mapping 
19 {
20   friend class Jdb_mapdb;
21 public:
22   enum Mapping_depth 
23   {
24     Depth_root = 0, Depth_max = 252, 
25     Depth_submap = 253, Depth_empty = 254, Depth_end = 255 
26   };
27
28   enum { Alignment = Mapping_entry::Alignment };
29
30   // CREATORS
31   Mapping(const Mapping&);      // this constructor is undefined.
32
33   // DATA
34   Mapping_entry _data;
35 } __attribute__((packed));
36
37
38 IMPLEMENTATION:
39
40 #include "config.h"
41
42 PUBLIC inline 
43 Mapping::Mapping()
44 {}
45
46 inline 
47 Mapping_entry *
48 Mapping::data()
49 {
50   return &_data;
51 }
52
53 inline 
54 const Mapping_entry *
55 Mapping::data() const
56 {
57   return &_data;
58 }
59
60 /** Address space.
61     @return the address space into which the frame is mapped. 
62  */
63 PUBLIC inline NEEDS [Mapping::data]
64 Space *
65 Mapping::space() const
66 {
67   return data()->space();
68 }
69
70 /** Set address space.
71     @param space the address space into which the frame is mapped. 
72  */
73 PUBLIC inline NEEDS [Mapping::data]
74 void
75 Mapping::set_space(Space *space)
76 {
77   data()->set_space(space);
78 }
79
80 /** Virtual address.
81     @return the virtual address at which the frame is mapped.
82  */
83 PUBLIC inline NEEDS[Mapping::data]
84 Page_number
85 Mapping::page() const
86 {
87   return Page_number::create(data()->data.address);
88 }
89
90 /** Set virtual address.
91     @param address the virtual address at which the frame is mapped.
92  */
93 PUBLIC inline NEEDS[Mapping::data]
94 void 
95 Mapping::set_page(Page_number address) 
96 {
97   data()->data.address = address.value();
98 }
99
100 /** Depth of mapping in mapping tree. */
101 PUBLIC inline
102 unsigned 
103 Mapping::depth() const
104 {
105   return data()->_depth;
106 }
107
108 /** Set depth of mapping in mapping tree. */
109 PUBLIC inline
110 void 
111 Mapping::set_depth(unsigned depth)
112 {
113   data()->_depth = depth;
114 }
115
116 /** free entry?.
117     @return true if this is unused.
118  */
119 PUBLIC inline NEEDS [Mapping::data]
120 bool
121 Mapping::unused() const
122 {
123   return depth() >= Depth_empty;
124 }
125
126 PUBLIC inline 
127 bool
128 Mapping::is_end_tag() const
129 {
130   return depth() == Depth_end;
131 }
132
133 PUBLIC inline
134 Treemap *
135 Mapping::submap() const
136 {
137   return (data()->_depth == Depth_submap) 
138     ? data()->_submap
139     : 0;
140 }
141
142 PUBLIC inline
143 void
144 Mapping::set_submap(Treemap *treemap)
145 {
146   data()->_submap = treemap;
147   data()->_depth = Depth_submap;
148 }
149
150 PUBLIC inline
151 void
152 Mapping::set_unused()
153 {
154   data()->_depth = Depth_empty;
155 }
156
157 /** Parent.
158     @return parent mapping of this mapping.
159  */
160 PUBLIC Mapping *
161 Mapping::parent()
162 {
163   if (depth() <= Depth_root)
164     return 0;                   // Sigma0 mappings don't have a parent.
165
166   // Iterate over mapping entries of this tree backwards until we find
167   // an entry with a depth smaller than ours.  (We assume here that
168   // "special" depths (empty, end) are larger than Depth_max.)
169   Mapping *m = this - 1;
170
171   // NOTE: Depth_unused / Depth_submap are high, so no need to test
172   // for them
173   while (m->depth() >= depth())
174     m--;
175
176   return m;
177 }
178