Main Page   Class Hierarchy   Compound List   File List   Compound 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 "physmem.h"
00007 #include "virtmem.h"
00008 #include "asm.h"
00009 
00010 extern Physical_memory physical_mem;
00011 
00014 
00035 class Address_map {
00036 public:
00037   unsigned int* directory;                      
00038   unsigned int* disk_directory;                 
00039   static const unsigned int ENTRY_PRESENT = 0x1;
00040   static const unsigned int ENTRY_READ_WRITE = 0x2;
00041   static const unsigned int ENTRY_DIRTY = 0x40;
00042   static const unsigned int DIR_ENTRY_SHIFT = 22;
00043   static const unsigned int TABLE_ENTRY_SHIFT = 12; 
00044   static const unsigned int ENTRY_INDEX_MASK = 0x3ff;
00045   static const unsigned int ENTRIES_PER_TABLE = 1024;
00046   static const unsigned int ENTRY_FRAME_ADDRESS = 0xfffff000;
00047   static const unsigned int PAYLOAD_SHIFT = 1;
00048 
00050   void
00051   init();
00052 
00057   inline unsigned int*
00058   virtual_to_dir_entry(void* virtual_addr) const {
00059     unsigned int index = ((unsigned int)virtual_addr >> DIR_ENTRY_SHIFT) &
00060                          ENTRY_INDEX_MASK;
00061     return directory + index;
00062   }
00063   
00064   inline unsigned int
00065   virtual_to_dir_index(void* virtual_addr) const {
00066     return ((unsigned int)virtual_addr >> DIR_ENTRY_SHIFT) & ENTRY_INDEX_MASK;
00067   }
00068 
00071   static inline unsigned int*
00072   virtual_to_table_entry(void* virtual_addr, unsigned int* table) {
00073     unsigned int index = ((unsigned int)virtual_addr >> TABLE_ENTRY_SHIFT) &
00074                          ENTRY_INDEX_MASK;
00075     return table + index;
00076   }
00077 
00080   inline void*
00081   table_entry_to_virtual(unsigned int* dir_entry, unsigned int* physical_table,
00082                          unsigned int* physical_table_entry) {
00083     unsigned int dir_index = dir_entry - directory;
00084     unsigned int table_index = physical_table_entry - physical_table;
00085     return (void*)((dir_index << DIR_ENTRY_SHIFT) |
00086                    (table_index << TABLE_ENTRY_SHIFT));
00087   }
00088 
00090   static inline unsigned int*
00091   dir_entry_to_table(unsigned int* dir_entry) {
00092     return (unsigned int*)(*dir_entry & ENTRY_FRAME_ADDRESS);
00093   }
00094 
00097   unsigned int*
00098   virtual_to_table_entry(void* virtual_addr);
00099 
00104   unsigned int*
00105   clear_table(unsigned int* physical_table);
00106 
00109   inline void
00110   set_table_block_number(unsigned int disk_dir_index,
00111                          unsigned int block_number) {
00112     disk_directory[disk_dir_index] = block_number;
00113   }
00114   
00116   inline unsigned int
00117   get_table_block_number(unsigned int disk_dir_index) {
00118     return disk_directory[disk_dir_index];
00119   }
00120 
00123   inline void
00124   set_table_address(unsigned int dir_index, unsigned int* physical_table) {
00125     directory[dir_index] = (unsigned int)physical_table | ENTRY_PRESENT |
00126                            ENTRY_READ_WRITE;
00127   }
00128 };
00129 
00130 #endif
00131 
00132 /* Torsion Operating System, Copyright (C) 2000-2002 Dan Helfman
00133  *
00134  * This program is free software; you can redistribute it and/or modify it
00135  * under the terms of the GNU General Public License as published by the
00136  * Free Software Foundation; either version 2 of the License, or (at your
00137  * option) any later version.
00138  * 
00139  * This program is distributed in the hope that it will be useful, but
00140  * WITHOUT ANY WARRANTY; without even the implied warranty of
00141  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00142  * General Public License for more details (in the COPYING file).
00143  * 
00144  * You should have received a copy of the GNU General Public License along
00145  * with this program; if not, write to the Free Software Foundation, Inc.,
00146  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00147  */

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