2 * (c) 2008-2009 Technische Universität Dresden
3 * This file is part of TUD:OS and distributed under the terms of the
4 * GNU General Public License 2.
5 * Please see the COPYING-GPL-2 file for details.
12 #include <l4/util/l4_macros.h>
18 Region_list::test_fit(unsigned long long start, unsigned long long _size)
20 Region r(start, start + _size);
21 for (Region const *c = _reg; c < _end; ++c)
24 printf("test [%p-%p] [%llx-%llx]\n", (char*)start, (char*)start + _size,
25 c->begin(), c->end());
35 Region_list::next_free(unsigned long long start)
37 unsigned long long s = ~0ULL;
38 for (Region const *c = _reg; c < _end; ++c)
39 if (c->end() > start && c->end() < s)
46 Region_list::find_free(Region const &search, unsigned long long _size,
49 unsigned long long start = search.begin();
50 unsigned long long end = search.end();
53 start = (start + (1ULL << align) -1) & ~((1ULL << align)-1);
55 if (start + _size - 1 > end)
58 //printf("try start %p\n", (void*)start);
59 if (test_fit(start, _size))
62 start = next_free(start);
70 Region_list::add_nolimitcheck(Region const ®ion, bool may_overlap)
74 /* Do not add empty regions */
75 if (region.begin() == region.end())
79 panic("Bootstrap: %s: Region overflow\n", __func__);
81 if (!may_overlap && (r = find(region)))
83 printf(" New region for list %s:\t", _name);
85 printf(" overlaps with: \t");
89 panic("region overlap");
97 Region_list::add(Region const ®ion, bool may_overlap)
103 printf(" WARNING: trying to add invalid region to %s list.\n", _name);
107 if (mem.begin() >= _upper_limit)
109 printf(" Dropping %s region ", _name);
111 printf(" due to %lld MB limit\n", _upper_limit >> 20);
115 if (mem.end() >= _upper_limit - 1)
117 printf(" Limiting %s region ", _name);
119 mem.end(_upper_limit - 1);
122 printf(" due to %lld MB limit\n", _upper_limit >> 20);
125 add_nolimitcheck(mem, may_overlap);
129 Region_list::find(Region const &o)
131 for (Region *c = _reg; c < _end; ++c)
139 Region_list::contains(Region const &o)
141 for (Region *c = _reg; c < _end; ++c)
149 Region::print() const
151 printf(" [%9llx, %9llx]", begin(), end());
155 Region::vprint() const
157 static char const *types[] = {"Gap ", "Kern ", "Sigma0",
158 "Boot ", "Root ", "Arch ", "Ram " };
161 printf(" %s ", types[type()]);
165 printf("%s", name() + 1);
167 print_module_name(name(), "");
177 Region const *min_idx;
178 unsigned long long min, mark = 0;
180 printf("Regions of list %s\n", _name);
181 for (i = _reg; i < _end; ++i)
185 for (j = _reg; j < _end; ++j)
186 if (j->begin() < min && j->begin() >= mark)
192 printf("Check region dump\n");
194 mark = min_idx->begin() + 1;
199 Region_list::swap(Region *a, Region *b)
201 Region t = *a; *a = *b; *b = t;
207 if (end() - begin() < 2)
211 Region *e = end() - 1;
216 for (Region *c = begin(); c < e; ++c)
230 Region_list::remove(Region *r)
232 memmove(r, r+1, (end() - r - 1)*sizeof(Region));
237 Region_list::optimize()
247 if (n->type() == c->type() && n->sub_type() == c->sub_type()
248 && n->name() == c->name() &&
249 l4_round_page(c->end()) >= l4_trunc_page(n->begin()))