2 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3 * Alexander Warg <warg@os.inf.tu-dresden.de>,
4 * Frank Mehnert <fm3@os.inf.tu-dresden.de>
5 * economic rights: Technische Universität Dresden (Germany)
7 * This file is part of TUD:OS and distributed under the terms of the
8 * GNU General Public License 2.
9 * Please see the COPYING-GPL-2 file for details.
16 #include <l4/util/l4_macros.h>
22 Region_list::test_fit(unsigned long long start, unsigned long long _size)
24 Region r(start, start + _size);
25 for (Region const *c = _reg; c < _end; ++c)
28 printf("test [%p-%p] [%llx-%llx]\n", (char*)start, (char*)start + _size,
29 c->begin(), c->end());
39 Region_list::next_free(unsigned long long start)
41 unsigned long long s = ~0ULL;
42 for (Region const *c = _reg; c < _end; ++c)
43 if (c->end() > start && c->end() < s)
50 Region_list::find_free(Region const &search, unsigned long long _size,
53 unsigned long long start = search.begin();
54 unsigned long long end = search.end();
57 start = (start + (1ULL << align) -1) & ~((1ULL << align)-1);
59 if (start + _size - 1 > end)
62 //printf("try start %p\n", (void*)start);
63 if (test_fit(start, _size))
66 start = next_free(start);
74 Region_list::add_nolimitcheck(Region const ®ion, bool may_overlap)
78 /* Do not add empty regions */
79 if (region.begin() == region.end())
83 panic("Bootstrap: %s: Region overflow\n", __func__);
85 if (!may_overlap && (r = find(region)))
87 printf(" New region for list %s:\t", _name);
89 printf(" overlaps with: \t");
93 panic("region overlap");
101 Region_list::add(Region const ®ion, bool may_overlap)
107 printf(" WARNING: trying to add invalid region to %s list.\n", _name);
111 if (mem.begin() >= _upper_limit)
113 printf(" Dropping %s region ", _name);
115 printf(" due to %lld MB limit\n", _upper_limit >> 20);
119 if (mem.end() >= _upper_limit - 1)
121 printf(" Limiting %s region ", _name);
123 mem.end(_upper_limit - 1);
126 printf(" due to %lld MB limit\n", _upper_limit >> 20);
129 add_nolimitcheck(mem, may_overlap);
133 Region_list::find(Region const &o)
135 for (Region *c = _reg; c < _end; ++c)
143 Region_list::contains(Region const &o)
145 for (Region *c = _reg; c < _end; ++c)
153 Region::print() const
155 printf(" [%9llx, %9llx] {%9llx}", begin(), end(), end() - begin() + 1);
159 Region::vprint() const
161 static char const *types[] = {"Gap ", "Kern ", "Sigma0",
162 "Boot ", "Root ", "Arch ", "Ram " };
165 printf(" %s ", types[type()]);
169 printf("%s", name() + 1);
171 print_module_name(name(), "");
181 Region const *min_idx;
182 unsigned long long min, mark = 0;
184 printf("Regions of list %s\n", _name);
185 for (i = _reg; i < _end; ++i)
189 for (j = _reg; j < _end; ++j)
190 if (j->begin() < min && j->begin() >= mark)
196 printf("Check region dump\n");
198 mark = min_idx->begin() + 1;
203 Region_list::swap(Region *a, Region *b)
205 Region t = *a; *a = *b; *b = t;
211 if (end() - begin() < 2)
215 Region *e = end() - 1;
220 for (Region *c = begin(); c < e; ++c)
234 Region_list::remove(Region *r)
236 memmove(r, r+1, (end() - r - 1)*sizeof(Region));
241 Region_list::optimize()
251 if (n->type() == c->type() && n->sub_type() == c->sub_type()
252 && n->name() == c->name() &&
253 l4_round_page(c->end()) >= l4_trunc_page(n->begin()))