3 Copyright (C) 2006-2009 Jörg Pfähler
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <kernel/debug.hpp>
21 #include <kernel/context.hpp>
22 #include <kernel/processor.hpp>
23 #include <kernel/page_allocator.hpp>
24 #include <lightOS/c++utils.hpp>
26 using namespace kernel
;
28 size_t page_allocator::mPageSize
= PAGE_SIZE
;
29 page_allocator
page_allocator::m_instance
= page_allocator();
31 page_allocator::page_allocator()
32 : mCapacity(0), mSize(0), mStack(reinterpret_cast<uintptr_t*>(KERNEL_MEMORY_PAGE_ALLOCATOR_START
))
36 page_allocator::~page_allocator()
40 void *page_allocator::allocate()
44 FATAL("page_allocator: No free pages" << endl
);
51 void *Page
= reinterpret_cast<void*>(*mStack
++);
58 void page_allocator::free(void *page
)
62 if (mSize
== mCapacity
&&
63 (reinterpret_cast<uintptr_t>(mStack
) & (mPageSize
- 1)) == 0)
65 kernelContext
&Context
= kernelContext::instance();
66 if (Context
.create_page_tables( page
,
67 adjust_pointer(mStack
, - mPageSize
),
68 lightOS::context::write
| lightOS::context::global
) == true)
76 if (mSize
> mCapacity
)++mCapacity
;
77 *--mStack
= reinterpret_cast<uintptr_t>(page
);