00001 // See the end of this file for license information. 00002 00003 #ifndef TORSION_PHYSMEM_H 00004 #define TORSION_PHYSMEM_H 00005 00006 #include "types.h" 00007 #include "pagealloc.h" 00008 00009 class Physical_memory; 00010 extern Physical_memory physical_pages; 00011 00012 typedef enum { 00013 MEM_CLASS_BELOW_1MB, 00014 MEM_CLASS_1MB_TO_16MB, 00015 MEM_CLASS_ABOVE_16MB 00016 } Memory_class; 00017 00018 const unsigned MEM_CLASSES_COUNT = 3; 00019 const unsigned MEM_1MB = 0x100000; 00020 const unsigned MEM_16MB = MEM_1MB * 16; 00021 00024 00025 class Physical_memory { 00026 protected: 00027 Size mem_size; 00028 unsigned char* page_after_kernel; 00029 bool allocator_enabled; 00030 00033 void 00034 calc_memory_size(); 00035 00036 public: 00037 Page_allocator page_allocator; 00038 00040 inline Size 00041 get_mem_size() const { 00042 return mem_size; 00043 } 00044 00046 void 00047 init(); 00048 00050 void 00051 enable_allocator(unsigned& last_available_address); 00052 00059 void* 00060 alloc_page(Memory_class mem_class = MEM_CLASS_ABOVE_16MB, 00061 Size request_size = PAGE_SIZE); 00062 00065 void 00066 free_page(void* page); 00067 00069 void* 00070 resize(void* page, Memory_class mem_class, Size new_size); 00071 00073 inline void* 00074 get_allocator_metadata_start() { 00075 return page_allocator.get_metadata_start(); 00076 } 00077 00080 inline void* 00081 get_allocator_max_metadata_start() { 00082 return page_allocator.get_max_metadata_start(); 00083 } 00084 00086 void 00087 unit_test(); 00088 00090 void 00091 print(); 00092 }; 00093 00094 #endif 00095 00096 /* Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman 00097 * 00098 * This program is free software; you can redistribute it and/or modify it 00099 * under the terms of the GNU General Public License as published by the 00100 * Free Software Foundation; either version 2 of the License, or (at your 00101 * option) any later version. 00102 * 00103 * This program is distributed in the hope that it will be useful, but 00104 * WITHOUT ANY WARRANTY; without even the implied warranty of 00105 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00106 * General Public License for more details (in the COPYING file). 00107 * 00108 * You should have received a copy of the GNU General Public License along 00109 * with this program; if not, write to the Free Software Foundation, Inc., 00110 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00111 */
Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman