00001 // See the end of this file for license information. 00002 00003 #ifndef TORSION_PHYSMEM_H 00004 #define TORSION_PHYSMEM_H 00005 00006 static const unsigned int PAGE_SIZE = 4096; 00007 00010 00016 typedef enum { 00017 MEM_CLASS_BELOW_1MB, 00018 MEM_CLASS_ABOVE_1MB, 00019 MEM_CLASS_ANY 00020 } Memory_class; 00021 00024 00046 class Physical_memory { 00047 protected: 00048 unsigned int* map_begin; 00049 unsigned int* map_end; 00050 unsigned int* heads[MEM_CLASS_ANY]; 00051 unsigned int* tails[MEM_CLASS_ANY]; 00052 unsigned int mem_size; 00053 00056 void 00057 calc_memory_size(); 00058 00059 public: 00061 inline unsigned int* 00062 get_map_begin() const { 00063 return map_begin; 00064 } 00065 00067 inline unsigned int* 00068 get_map_end() const { 00069 return map_end; 00070 } 00071 00073 inline unsigned int 00074 get_mem_size() const { 00075 return mem_size; 00076 } 00077 00080 inline unsigned int* 00081 phys_to_map(void* physical_address) const { 00082 return map_begin + (unsigned int)(physical_address) / PAGE_SIZE; 00083 } 00084 00087 inline void* 00088 map_to_phys(unsigned int* map_entry) const { 00089 return (unsigned int*)((map_entry - map_begin) * PAGE_SIZE); 00090 } 00091 00097 inline unsigned int* 00098 get_first_free_page_entry(Memory_class mem_class) const { 00099 return heads[mem_class]; 00100 } 00101 00105 unsigned int* 00106 get_next_free_page_entry(unsigned int* entry, Memory_class mem_class) const; 00107 00110 void* 00111 alloc_page(Memory_class mem_class = MEM_CLASS_ANY); 00112 00115 void 00116 free_page(void* page); 00117 00120 void 00121 init(unsigned short int kernel_size); 00122 }; 00123 00124 #endif 00125 00126 /* Torsion Operating System, Copyright (C) 2000-2002 Dan Helfman 00127 * 00128 * This program is free software; you can redistribute it and/or modify it 00129 * under the terms of the GNU General Public License as published by the 00130 * Free Software Foundation; either version 2 of the License, or (at your 00131 * option) any later version. 00132 * 00133 * This program is distributed in the hope that it will be useful, but 00134 * WITHOUT ANY WARRANTY; without even the implied warranty of 00135 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00136 * General Public License for more details (in the COPYING file). 00137 * 00138 * You should have received a copy of the GNU General Public License along 00139 * with this program; if not, write to the Free Software Foundation, Inc., 00140 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00141 */
Torsion Operating System, Copyright (C) 2000-2002 Dan Helfman