scsi request, part usb mass storage class driver, bulk transfers
[quarnos.git] / resources / physmem.cpp
blobe6fc1549b18a332a98fef477c5114c5d94fac496
1 /* Quarn OS
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"
26 #include "physmem.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 };
32 regions.add(kern);
34 region usr = { (paddr)0x80000000, 0x80000000, (paddr)0x80000000, region::user };
35 regions.add(usr);
38 void physmem::map_page(paddr ppage, vaddr vpage) {
42 void *physmem::allocate_space(unsigned int) {
43 paddr ppage = last_p;
44 last_p += 0x1000;
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);
54 return (void*)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) {
60 paddr ppage = last_p;
61 last_p += 0x1000;
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);
71 return vpage;
74 /* throw */
75 return (vaddr)0;
78 void physmem::deallocate_space(void *page) {
81 void physmem::register_type() {
82 manes::manec::get()->register_type<physmem>("physmem", "manec");