Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

addrmap.h

Go to the documentation of this file.
00001 // See the end of this file for license information.
00002 
00003 #ifndef TORSION_ADDRMAP_H
00004 #define TORSION_ADDRMAP_H
00005 
00006 #include "arch.h"
00007 #include "virtmem.h"
00008 #include "asm.h"
00009 #include "array.h"
00010 
00031 
00032 class Address_map {
00033 public:
00034   unsigned* directory;        
00035   unsigned* disk_directory;     
00036 //  unsigned* table_entry_counts;   ///< per-table number of entries
00037   static const unsigned ENTRY_PRESENT = 0x1;
00038   static const unsigned ENTRY_READ_WRITE = 0x2;
00039   static const unsigned ENTRY_DIRTY = 0x40;
00040   static const unsigned DIR_ENTRY_SHIFT = 22;
00041   static const unsigned TABLE_ENTRY_SHIFT = 12; 
00042   static const unsigned ENTRY_INDEX_MASK = 0x3ff;
00043   static const unsigned ENTRIES_PER_TABLE = 1024;
00044   static const unsigned ENTRY_FRAME_ADDRESS = 0xfffff000;
00045   static const unsigned PAYLOAD_SHIFT = 1;
00046 
00048   void
00049   init();
00050 
00054   inline unsigned*
00055   virtual_to_dir_entry(void* virtual_addr) const {
00056     unsigned index = ((Address)virtual_addr >> DIR_ENTRY_SHIFT) &
00057                      ENTRY_INDEX_MASK;
00058     return directory + index;
00059   }
00060   
00062   inline unsigned
00063   virtual_to_dir_index(void* virtual_addr) const {
00064     return ((Address)virtual_addr >> DIR_ENTRY_SHIFT) & ENTRY_INDEX_MASK;
00065   }
00066 
00069   static inline unsigned*
00070   virtual_to_table_entry(void* virtual_addr, unsigned* table) {
00071     unsigned index = ((Address)virtual_addr >> TABLE_ENTRY_SHIFT) &
00072                      ENTRY_INDEX_MASK;
00073     return table + index;
00074   }
00075   
00078   unsigned
00079   get_table_entry(void* virtual_addr);
00080 
00083   bool
00084   set_table_entry(void* virtual_addr, unsigned entry_value);
00085 
00088   inline void*
00089   table_entry_to_virtual(unsigned* dir_entry, unsigned* physical_table,
00090                          unsigned* physical_table_entry) {
00091     unsigned dir_index = dir_entry - directory;
00092     unsigned table_index = physical_table_entry - physical_table;
00093     return (void*)((dir_index << DIR_ENTRY_SHIFT) |
00094                    (table_index << TABLE_ENTRY_SHIFT));
00095   }
00096 
00098   static inline unsigned*
00099   dir_entry_to_table(unsigned* dir_entry) {
00100     return (unsigned*)(*dir_entry & ENTRY_FRAME_ADDRESS);
00101   }
00102   
00104   inline unsigned*
00105   dir_index_to_table(unsigned dir_index) {
00106     unsigned* dir_entry = directory + dir_index;
00107     return (unsigned*)(*dir_entry & ENTRY_FRAME_ADDRESS);
00108   }
00109   
00114   unsigned*
00115   virtual_to_table_entry(void* virtual_addr);
00116 
00120   unsigned*
00121   get_table(unsigned dir_index);
00122 
00128   unsigned*
00129   clear_table(unsigned* physical_table);
00130 
00132   void
00133   get_dirty_dir_entries(Array<unsigned*>& dirty_dir_entries);
00134 
00137   inline void
00138   set_table_block_number(unsigned disk_dir_index,
00139                          unsigned block_number) {
00140     disk_directory[disk_dir_index] = block_number;
00141   }
00142   
00144   inline unsigned
00145   get_table_block_number(unsigned disk_dir_index) {
00146     return disk_directory[disk_dir_index];
00147   }
00148 
00151   inline void
00152   set_table_address(unsigned dir_index, unsigned* physical_table) {
00153     directory[dir_index] = (Address)physical_table | ENTRY_PRESENT |
00154                            ENTRY_READ_WRITE;
00155   }
00156 };
00157 
00158 #endif
00159 
00160 /* Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman
00161  *
00162  * This program is free software; you can redistribute it and/or modify it
00163  * under the terms of the GNU General Public License as published by the
00164  * Free Software Foundation; either version 2 of the License, or (at your
00165  * option) any later version.
00166  * 
00167  * This program is distributed in the hope that it will be useful, but
00168  * WITHOUT ANY WARRANTY; without even the implied warranty of
00169  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00170  * General Public License for more details (in the COPYING file).
00171  * 
00172  * You should have received a copy of the GNU General Public License along
00173  * with this program; if not, write to the Free Software Foundation, Inc.,
00174  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00175  */

Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman