3 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
4 * Alexander Warg <warg@os.inf.tu-dresden.de>,
5 * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
6 * economic rights: Technische Universität Dresden (Germany)
8 * This file is part of TUD:OS and distributed under the terms of the
9 * GNU General Public License 2.
10 * Please see the COPYING-GPL-2 file for details.
12 * As a special exception, you may use this file as part of a free software
13 * library without restriction. Specifically, if other files instantiate
14 * templates or use macros or inline functions from this file, or you compile
15 * this file and link it with other files to produce an executable, this
16 * file does not by itself cause the resulting executable to be covered by
17 * the GNU General Public License. This exception does not however
18 * invalidate any other reasons why the executable file might be covered by
19 * the GNU General Public License.
24 #include <l4/sys/types.h>
25 #include <l4/cxx/list>
26 #include <l4/cxx/minmax>
27 #include <l4/re/dataspace>
28 #include <l4/re/dataspace-sys.h>
29 #include <l4/re/util/dataspace_svr>
33 L4::Ipc::Ostream &operator << (L4::Ipc_ostream &s,
34 L4Re::Dataspace::Stats const &st)
35 { s.put(st); return s; }
38 namespace L4Re { namespace Util {
41 Dataspace_svr::map(l4_addr_t offs, l4_addr_t hot_spot, unsigned long flags,
42 l4_addr_t min, l4_addr_t max, L4::Ipc::Snd_fpage &memory)
44 int err = map_hook(offs, flags, min, max);
48 memory = L4::Ipc::Snd_fpage();
50 offs = l4_trunc_page(offs);
51 hot_spot = l4_trunc_page(hot_spot);
53 if (!check_limit(offs))
56 printf("limit failed: off=%lx sz=%lx\n", offs, size());
61 min = l4_trunc_page(min);
62 max = l4_round_page(max);
64 l4_addr_t addr = _ds_start + offs;
65 unsigned char order = L4_PAGESHIFT;
67 while (order < 30 /* limit to 1GB flexpage */)
69 l4_addr_t map_base = l4_trunc_size(addr, order + 1);
70 if (map_base < _ds_start)
73 if (map_base + (1UL << (order + 1)) -1 > (_ds_start + round_size() - 1))
76 map_base = l4_trunc_size(hot_spot, order + 1);
80 if (map_base + (1UL << (order + 1)) -1 > max -1)
83 l4_addr_t mask = ~(~0UL << (order + 1));
84 if (hot_spot == ~0UL || ((addr ^ hot_spot) & mask))
90 l4_addr_t map_base = l4_trunc_size(addr, order);
91 //l4_addr_t map_offs = addr & ~(~0UL << order);
93 l4_fpage_t fpage = l4_fpage(map_base, order, flags && is_writable() ? L4_FPAGE_RWX : L4_FPAGE_RX);
95 memory = L4::Ipc::Snd_fpage(fpage, hot_spot, _map_flags, _cache_flags);
101 Dataspace_svr::clear(l4_addr_t offs, unsigned long _size) const throw()
103 if (!check_limit(offs))
106 unsigned long sz = _size = cxx::min(_size, round_size()-offs);
110 unsigned long b_addr = _ds_start + offs;
111 unsigned long b_sz = cxx::min(_size - offs, sz);
113 memset((void *)b_addr, 0, b_sz);
123 Dataspace_svr::phys(l4_addr_t /*offset*/, l4_addr_t &/*phys_addr*/, l4_size_t &/*phys_size*/) throw()