Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

idt.h

Go to the documentation of this file.
00001 
00007 /*
00008  *  Copyright (C) 2003 Bregmasoft
00009  *
00010  * This program is free software; you can redistribute it and/or modify it
00011  * under the terms of the GNU General Public License as published by the Free
00012  * Software Foundation; either version 2 of the License, or (at your option)
00013  * any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful, but WITHOUT
00016  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00017  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00018  * more details.
00019  *
00020  * You should have received a copy of the GNU General Public License along
00021  * with this program; if not, write to the Free Software Foundation, Inc., 59
00022  * Temple Place, Suite 330, Boston, MA 02111-1307 USA
00023  */
00024 #ifndef ZYGOMA_IA32_IDT_H_ 
00025 #define ZYGOMA_IA32_IDT_H_ 
00026 
00027 #include <config.h>
00028 #include <iosfwd>
00029 #include <list>
00030 #include <types.h>
00031 #include <vector>
00032 
00033 namespace Zygoma
00034 {
00035   namespace ia32
00036   {
00040     enum Faults
00041     {
00042       kFAULT_DIVIDE_ERROR = 0,    
00043       kFAULT_RESERVED_1 = 1,      
00044       kFAULT_NMI = 2,             
00045       kFAULT_BREAKPOINT = 3,      
00046       kFAULT_OVERFLOW = 4,        
00047       kFAULT_BOUND_EXCEEDED = 5,  
00048       kFAULT_INVALID_OPCODE = 6,  
00049       kFAULT_DEVICE_NOT_AVAILABLE,
00050       kFAULT_DOUBLE_FAULT = 8,    
00051       kFAULT_SEGMENT_OVERRUN = 9, 
00052       kFAULT_INVALID_TSS = 10,    
00053       kFAULT_SEGMENT_NOT_PRESENT, 
00054       kFAULT_STACK_SEGMENT_FAULT, 
00055       kFAULT_GENERAL_PROTECTION,  
00056       kFAULT_PAGE_FAULT = 14,     
00057       kFAULT_RESERVED_15,
00058       kFAULT_FPU_ERROR = 16,      
00059       kFAULT_ALIGNMENT_CHECK,     
00060       kFAULT_MACHINE_CHECK = 18,  
00061       kFAULT_SIMD_EXCEPTION = 19, 
00062       kFAULT_RESERVED_20
00063     };
00064 
00065 
00076     class InterruptGate
00077     {
00078     public:
00080       InterruptGate(u16 segment = 0,
00081                     u32 offset = 0,
00082                     u08 privilegeLevel = 0,
00083                     bool isTrap = false);
00084 
00086       std::ostream& printStream(std::ostream& ostr) const;
00087 
00088     private:
00089       u16 m_offset00_15;      
00090       u16 m_segment;
00091       u08 m_unused2;
00092       u08 m_type:3;               /* 6 (INT) or 7 (TRAP) */
00093       u08 m_size:1;               /* 0 */
00094       u08 m_isSystemDescriptor:1; /* 0 (16-bit) or 1 (32-bit) */
00095       u08 m_privilegeLevel:2;
00096       u08 m_segmentIsPresent:1;   /* 0 (not present) or 1 (present) */
00097       u16 m_offset16_31;
00098     } ZYGOMA_PACKED;
00099 
00100 
00107     inline std::ostream&
00108     operator<<(std::ostream& ostr, const InterruptGate& gate)
00109     {
00110       return gate.printStream(ostr);
00111     }
00112 
00113 
00118     typedef bool (*InterruptHandlerTrampoline)(int interruptNumber);
00119 
00120 
00168     class IDT
00169     {
00170       typedef std::list<InterruptHandlerTrampoline> InterruptHandlerChain;
00171       typedef std::vector<InterruptHandlerChain>    InterruptHandlerDispatchTable;
00172       typedef std::vector<InterruptGate>            InternalIdt;
00173 
00174     public:
00175       typedef InterruptGate               value_type;
00176       typedef InterruptGate&              reference;
00177       typedef const InterruptGate&        const_reference;
00178       typedef InternalIdt::iterator       iterator;
00179       typedef InternalIdt::const_iterator const_iterator;
00180       typedef std::ptrdiff_t              difference_type;
00181       typedef std::size_t                 size_type;
00182 
00183     public:
00184       IDT(int size);
00185 
00187       /* @{ */
00188 
00194       size_type
00195       size() const
00196       { return m_idt.size(); }
00197 
00203       bool
00204       empty() const
00205       { return m_idt.empty(); }
00206 
00207       /* @} */
00208 
00210       /* @{ */
00211 
00214       iterator
00215       begin()
00216       {
00217         return m_idt.begin();
00218       }
00219 
00222       const_iterator
00223       begin() const
00224       {
00225         return m_idt.begin();
00226       }
00227 
00230       iterator
00231       end()
00232       {
00233         return m_idt.end();
00234       }
00235 
00238       const_iterator
00239       end() const
00240       {
00241         return m_idt.end();
00242       }
00243 
00244       /* @} */
00245 
00246       void
00247       insert(unsigned int irq, const InterruptGate&);
00248 
00249       void
00250       dispatchInterrupt(int interruptNumber);
00251 
00253       void
00254       disableInterrupts();
00255 
00257       void
00258       enableInterrupts();
00259 
00261       std::ostream& printStream(std::ostream& ostr) const;
00262 
00263     private:
00264       IDT(const IDT&);              // not defined
00265       IDT& operator=(const IDT&);   // not defined
00266 
00267     private:
00268       InternalIdt                   m_idt;
00269       InterruptHandlerDispatchTable m_interruptHandlerDispatchTable;
00270     };
00271 
00272 
00279     inline std::ostream&
00280     operator<<(std::ostream& ostr, const IDT& idt)
00281     {
00282       return idt.printStream(ostr);
00283     }
00284 
00290     extern IDT* gIDT;
00291   } // namespace ia32
00292 } // namespace Zygoma
00293 
00294 #endif // ZYGOMA_IA32_IDT_H_ 

Generated on Fri Sep 2 10:44:36 2005 for zygoma by doxygen 1.4.2