2 * (c) 2008-2009 Alexander Warg <warg@os.inf.tu-dresden.de>
3 * economic rights: Technische Universität Dresden (Germany)
5 * This file is part of TUD:OS and distributed under the terms of the
6 * GNU General Public License 2.
7 * Please see the COPYING-GPL-2 file for details.
9 #include <l4/util/util.h>
11 #include <l4/cxx/iostream>
12 #include <l4/cxx/list_alloc>
13 #include <l4/cxx/exceptions>
14 #include <l4/sys/kdebug.h>
15 #include "page_alloc.h"
19 enum { page_alloc_debug = 0 };
21 unsigned page_alloc_debug = 0;
24 class LA : public cxx::List_alloc
30 L4::cout << "~LA(): avail = " << avail() << '\n';
35 void *alloc(unsigned long size, unsigned long align)
37 L4::cout << "PA::alloc: " << L4::hex << size << '(' << align << ") -> \n";
38 void *p = cxx::List_alloc::alloc(size, align);
39 L4::cout << p << "\n";
45 void free(void *p, unsigned long size)
47 L4::cout << "free: " << p << '(' << size << ") -> ";
48 cxx::List_alloc::free(p, size);
49 L4::cout << avail() << "\n";
54 static LA *page_alloc()
60 Single_page_alloc_base::Single_page_alloc_base()
63 unsigned long Single_page_alloc_base::_avail()
65 return page_alloc()->avail();
68 void *Single_page_alloc_base::_alloc(Nothrow)
70 void *ret = page_alloc()->alloc(L4_PAGESIZE, L4_PAGESIZE);
73 L4::cout << "pa(" << __builtin_return_address(0) << "): alloc(PAGE) @" << ret << '\n';
77 void Single_page_alloc_base::_free(void *p)
80 L4::cout << "pa(" << __builtin_return_address(0) << "): free(PAGE) @" << p << '\n';
81 page_alloc()->free(p, L4_PAGESIZE);
84 void *Single_page_alloc_base::_alloc_max(unsigned long min,
89 void *ret = page_alloc()->alloc_max(min, max, align, granularity);
91 L4::cout << "pa(" << __builtin_return_address(0) << "): alloc(" << *max << ") @" << ret << '\n';
95 void *Single_page_alloc_base::_alloc(Nothrow, unsigned long size,
98 void *ret = page_alloc()->alloc(size, align);
100 L4::cout << "pa(" << __builtin_return_address(0) << "): alloc(" << size << ") @" << ret << '\n';
104 void Single_page_alloc_base::_free(void *p, unsigned long size, bool initial_mem)
106 if (page_alloc_debug)
107 L4::cout << "pa(" << __builtin_return_address(0) << "): free(" << size << ") @" << p << '\n';
108 page_alloc()->free(p, size, initial_mem);
112 void Single_page_alloc_base::_dump_free(Dbg &dbg)
114 page_alloc()->dump_free_list(dbg);