00001 00006 /* 00007 * Copyright (C) 2003 Bregmasoft 00008 * 00009 * This program is free software; you can redistribute it and/or modify it under 00010 * the terms of the GNU General Public License as published by the Free Software 00011 * Foundation; either version 2 of the License, or (at your option) any later 00012 * version. 00013 * 00014 * This program is distributed in the hope that it will be useful, but WITHOUT ANY 00015 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 00016 * PARTICULAR PURPOSE. See the GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License along with 00019 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00020 * Place, Suite 330, Boston, MA 02111-1307 USA 00021 */ 00022 #ifndef ZYGOMA_IA32_DESCRIPTOR_H_ 00023 #define ZYGOMA_IA32_DESCRIPTOR_H_ 00024 00025 #include <config.h> 00026 00027 namespace Zygoma 00028 { 00029 namespace ia32 00030 { 00044 class Descriptor 00045 { 00046 public: 00050 enum Type 00051 { 00052 kTYPE_RESERVED_0 = 0, 00053 kTYPE_TSS_AVAILABLE = 1, 00054 kTYPE_LDT = 2, 00055 kTYPE_TSS_BUSY = 3, 00056 kTYPE_CALL_GATE = 4, 00057 kTYPE_TASK_GATE = 5, 00058 kTYPE_INT_GATE = 6, 00059 kTYPE_TRAP_GATE = 7 00060 }; 00061 00065 enum Granularity 00066 { 00067 kGRANULARITY_BYTE = 0, 00068 kGRANULARITY_4K = 1 00069 }; 00070 00074 enum OperationSize 00075 { 00076 kOP_SIZE_16 = 0, 00077 kOP_SIZE_32 = 1 00078 }; 00079 00080 public: 00086 Type 00087 type() const 00088 { return static_cast<Type>(m_type); } 00089 00094 bool 00095 isSystemDescriptor() const 00096 { return m_flags1.m_system.m_isSystemDescriptor; } 00097 00102 int 00103 privilegeLevel() const 00104 { return m_flags1.m_code.m_privilegeLevel; } 00105 00116 u32 00117 base() const 00118 { 00119 return (m_base24_31 & 0xfe) << 24 00120 + m_base16_23 << 16 00121 + m_base00_15; 00122 } 00123 00133 u32 00134 limit() const 00135 { 00136 return (m_flags2 & 0x0f) << 16 00137 + m_limit00_15; 00138 } 00139 00144 Granularity 00145 granularity() const 00146 { return static_cast<Granularity>(m_granularity); } 00147 00153 OperationSize 00154 operationSize() const 00155 { return static_cast<OperationSIze>(m_operationSize); } 00156 00162 bool 00163 isPresent() const 00164 { return m_flags1.m_code.m_segmentIsPresent; } 00165 00166 int 00167 limit() const 00168 { return m_segmentLimit; } 00169 00170 private: 00171 struct DataSegment 00172 { 00173 u08 m_accessed:1; 00174 u08 m_write:1; 00175 u08 m_read:1; 00176 u08 m_selector:1; 00177 u08 m_isSystemDescriptor:1; 00178 u08 m_privilegeLevel:2; 00179 u08 m_segmentIsPresent:1; 00180 }; 00181 00182 struct CodeSegment 00183 { 00184 u08 m_accessed:1; 00185 u08 m_execute:1; 00186 u08 m_conforming:1; 00187 u08 m_selector:1; 00188 u08 m_isSystemDescriptor:1; 00189 u08 m_privilegeLevel:2; 00190 u08 m_segmentIsPresent:1; 00191 }; 00192 00193 struct SystemSegment 00194 { 00195 u08 m_type:3; 00196 u08 m_size:1; 00197 u08 m_isSystemDescriptor:1; 00198 u08 m_privilegeLevel:2; 00199 u08 m_segmentIsPresent:1; 00200 }; 00201 00202 union TypeUnion { 00203 CodeSegment m_code; 00204 DataSegment m_data; 00205 SystemSegment m_system; 00206 }; 00207 00208 protected: 00209 u16 m_limit00_15; 00210 u16 m_base00_15; 00211 u08 m_base16_23; 00212 TypeUnion m_flags1; 00213 u08 m_segmentLimit:4; 00214 u08 m_useMe:1; 00215 u08 m_reserved:1; 00216 u08 m_operationSize:1; 00217 u08 m_granularity:1; 00218 u08 m_base24_31; 00219 } ZYGOMA_PACKED; 00220 00221 class TaskGate 00222 { 00223 public: 00224 u16 m_unused1; 00225 u16 m_segmentSelector; 00226 u08 m_unused2; 00227 u08 m_type:3; /* 5 */ 00228 u08 m_size:1; /* 0 */ 00229 u08 m_isSystemDescriptor:1; /* 0 */ 00230 u08 m_privilegeLevel:2; 00231 u08 m_segmentIsPresent:1; 00232 u16 m_unused3 00233 }; 00234 00235 class InterruptGate 00236 { 00237 public: 00238 u16 m_offset00_15; 00239 u16 m_segmentSelector; 00240 u08 m_unused2; 00241 u08 m_type:3; /* 6 */ 00242 u08 m_size:1; /* 0 */ 00243 u08 m_isSystemDescriptor:1; /* 0 */ 00244 u08 m_privilegeLevel:2; 00245 u08 m_segmentIsPresent:1; /* 1 */ 00246 u16 m_offset16_31; 00247 }; 00248 00252 class TrapGate 00253 { 00254 public: 00255 u16 m_offset00_15; 00256 u16 m_segmentSelector; 00257 u08 m_unused2; 00258 u08 m_type:3; /* 7 */ 00259 u08 m_size:1; /* 0 */ 00260 u08 m_isSystemDescriptor:1; /* 0 */ 00261 u08 m_privilegeLevel:2; 00262 u08 m_segmentIsPresent:1; /* 1 */ 00263 u16 m_offset16_31; 00264 }; 00265 } // namespace ia32 00266 } // namespace Zygoma 00267 00268 #endif // ZYGOMA_IA32_DESCRIPTOR_H_