00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef ZYGOMA_H_
00023 #define ZYGOMA_H_
00024
00025 #include <memory.h>
00026
00027 namespace Zygoma
00028 {
00029 namespace ia32
00030 {
00031 class PageBaseEntry
00032 {
00033 public:
00034 enum Protection
00035 {
00036 kREAD_ONLY = 0,
00037 kREAD_WRITE = 1
00038 };
00039
00040 enum Privilege
00041 {
00042 kSUPERVISOR_PRIVILEGE = 0,
00043 kUSER_PRIVILEGE = 1
00044 };
00045
00050 static u32
00051 addressToBase(void* address)
00052 {
00053 return (reinterpret_cast<u32>(address) >> 12) & 0x000fffff;
00054 }
00055
00056 public:
00057 PageBaseEntry(void* baseAddress, Protection protection, Privilege privilege)
00058 : m_baseAddress(addressToBase(baseAddress))
00059 , m_avail(0)
00060 , m_isGlobal(0)
00061 , m_pageSize(0)
00062 , m_isDirty(0)
00063 , m_wasAccessed(0)
00064 , m_cacheDisabled(0)
00065 , m_writeThrough(0)
00066 , m_userMode(privilege)
00067 , m_readWrite(protection)
00068 , m_isPresent(0)
00069 { }
00070
00071 u32
00072 baseAddress() const
00073 { return m_baseAddress << 12; }
00074
00075 void
00076 setBaseAddress(void* baseAddress)
00077 { m_baseAddress = addressToBase(baseAddress); }
00078
00079 void
00080 setIsPresent(bool isPresent)
00081 { m_isPresent = isPresent; }
00082
00083 void
00084 setProtection(Protection protection)
00085 { m_readWrite = protection; }
00086
00087 void
00088 setPrivilege(Privilege privilege)
00089 { m_userMode = privilege; }
00090
00091 bool
00092 wasAccessed() const
00093 { return m_wasAccessed; }
00094
00095 protected:
00096 u32 m_baseAddress: 20;
00097 u32 m_avail: 3;
00098 u32 m_isGlobal: 1;
00099 u32 m_pageSize: 1;
00100 u32 m_isDirty: 1;
00101 u32 m_wasAccessed: 1;
00102 u32 m_cacheDisabled: 1;
00103 u32 m_writeThrough: 1;
00104 u32 m_userMode: 1;
00105 u32 m_readWrite: 1;
00106 u32 m_isPresent: 1;
00107 };
00108
00109 class PageDirectoryEntry
00110 : public PageBaseEntry
00111 {
00112 public:
00113 PageDirectoryEntry(void* baseAddress = 0,
00114 Protection protection = kREAD_WRITE,
00115 Privilege privilege = kSUPERVISOR_PRIVILEGE)
00116 : PageBaseEntry(baseAddress, protection, privilege)
00117 { }
00118 };
00119
00120 class PageTableEntry
00121 : public PageBaseEntry
00122 {
00123 public:
00124 PageTableEntry(void* baseAddress = 0,
00125 Protection protection = kREAD_WRITE,
00126 Privilege privilege = kSUPERVISOR_PRIVILEGE)
00127 : PageBaseEntry(baseAddress, protection, privilege)
00128 { }
00129
00130 bool
00131 isDirty() const
00132 { return m_isDirty; }
00133
00134 };
00135
00136 class PageDirectory
00137 {
00138 public:
00139 static int
00140 findTable(void* address)
00141 { return (reinterpret_cast<int>(address) >> 22) & 0x3ff; }
00142
00143 PageDirectoryEntry&
00144 at(int index)
00145 { return m_entry[index]; }
00146
00147 PageDirectoryEntry&
00148 operator[](int index)
00149 { return this->at(index); }
00150
00151 private:
00152 PageDirectoryEntry m_entry[1024];
00153 };
00154
00155 class PageTable
00156 {
00157 public:
00158 static int
00159 pageSize()
00160 { return 4096; }
00161
00162 static int
00163 findPage(void* address)
00164 { return (reinterpret_cast<int>(address) >> 12) & 0x3ff; }
00165
00166 PageTableEntry&
00167 at(int index)
00168 { return m_entry[index]; }
00169
00170 PageTableEntry&
00171 operator[](int index)
00172 { return this->at(index); }
00173
00174 private:
00175 PageTableEntry m_entry[1024];
00176 };
00177 }
00178 }
00179
00180 #endif // ZYGOMA_H_