2 * (c) 2010 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3 * Alexander Warg <warg@os.inf.tu-dresden.de>
4 * economic rights: Technische Universität Dresden (Germany)
6 * This file is part of TUD:OS and distributed under the terms of the
7 * GNU General Public License 2.
8 * Please see the COPYING-GPL-2 file for details.
18 #include "phys_space.h"
20 void *operator new (size_t sz, cxx::Nothrow const &) throw()
21 { return malloc(sz); }
23 Phys_space Phys_space::space;
25 Phys_space::Phys_space()
27 _set.insert(Phys_region(4 << 22, Phys_region::Addr(~0)));
28 //_set.insert(Phys_region(0xd0000000, Phys_region::Addr(~0)));
29 // reserve(Phys_region(0xe0000000, 0xf0000000-1));
31 L4::Kip::Mem_desc *md = L4::Kip::Mem_desc::first(l4re_kip());
32 L4::Kip::Mem_desc *mde = md + L4::Kip::Mem_desc::count(l4re_kip());
34 for (; md < mde; ++md)
41 case L4::Kip::Mem_desc::Arch:
42 case L4::Kip::Mem_desc::Conventional:
43 case L4::Kip::Mem_desc::Reserved:
44 case L4::Kip::Mem_desc::Dedicated:
45 case L4::Kip::Mem_desc::Shared:
46 case L4::Kip::Mem_desc::Bootloader:
48 Phys_region re(l4_trunc_page(md->start()),
49 l4_round_page(md->end())-1);
51 d_printf(DBG_INFO, " reserve phys memory space %014lx-%014lx (%s)\n",
52 md->start(), md->end(), r ? "ok" : "failed");
64 Phys_space::alloc_from(Set::Iterator const &o, Phys_region const &r)
72 if (o->start() >= r.start())
74 o->set_start(r.end() + 1);
78 if (o->end() <= r.end())
80 o->set_end(r.start() - 1);
84 Phys_region nr(r.end() + 1, o->end());
85 o->set_end(r.start() - 1);
91 Phys_space::reserve(Phys_region const &r)
104 while (alloc_from(n, r));
110 Phys_space::alloc(Phys_region const &r)
127 Phys_space::Phys_region
128 Phys_space::alloc(Phys_region::Addr sz, Phys_region::Addr align)
130 for (Set::Iterator i = _set.begin(); i != _set.end(); ++i)
132 if (i->start() > Phys_region::Addr(0) - sz)
135 Phys_region r((i->start() + align) & ~align, 0);
136 r.set_end(r.start() + sz - 1);
145 return Phys_region();
151 printf("unused physical memory space:\n");
152 for (Set::Iterator i = _set.begin(); i != _set.end(); ++i)
153 printf(" [%014lx-%014lx]\n", i->start(), i->end());