3 * Physical Memory Manager
5 * Copyright (C) 2009 Pawel Dziepak
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "arch/low/e820.h"
25 #include "manes/manec.h"
28 using namespace resources
;
30 physmem::physmem() : last_p((paddr
)0x300000), available_memory(arch::get_memory_size()), default_region(0) {
31 region kern
= { (paddr
)0, 0x80000000, (paddr
)0x300000, region::kernel
};
34 region usr
= { (paddr
)0x80000000, 0x80000000, (paddr
)0x80000000, region::user
};
38 void physmem::map_page(paddr ppage
, vaddr vpage
) {
42 void *physmem::allocate_space(unsigned int) {
46 if (last_p
>= 0x400000)
47 critical("no more free memory");
49 vaddr vpage
= regions
[default_region
].last
;
50 regions
[default_region
].last
+= 0x1000;
52 map_page(ppage
, vpage
);
57 vaddr
physmem::get_page(region::type t
) {
58 for (int i
= 0; i
< regions
.get_count(); i
++) {
59 if (regions
[i
].rtype
== t
) {
63 if (last_p
>= 0x400000)
64 critical("no more free memory");
66 vaddr vpage
= regions
[i
].last
;
67 regions
[i
].last
+= 0x1000;
69 map_page(ppage
, vpage
);
78 void physmem::deallocate_space(void *page
) {
81 void physmem::register_type() {
82 manes::manec::get()->register_type
<physmem
>("physmem", "manec");