Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

irq.h

Go to the documentation of this file.
00001 // See the end of this file for license information.
00002 
00003 #ifndef TORSION_IRQ_H
00004 #define TORSION_IRQ_H
00005 
00007 
00008 class Int_descriptor {
00009 public:                                         
00010   unsigned handler_low: 16;                     
00011   unsigned handler_selector: 16;                
00012   unsigned unused: 8;                           
00013   unsigned access_type: 8;                      
00014   unsigned handler_high: 16;                    
00015   static const unsigned short int INTERRUPT_GATE = 0x8e;
00016   static const unsigned short int TRAP_GATE = 0x8f;
00017 
00020   inline void
00021   set_handler(void* handler) {
00022     handler_low = ((unsigned int)handler & 0xffff);
00023     handler_high = ((unsigned int)handler >> 16);
00024     asm volatile("movl %%cs, %0" : "=r" (handler_selector));
00025     unused = 0;
00026   }
00027 };
00028 
00031 
00032 struct Handler_registers {
00034   unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax;
00035   unsigned int int_num;                         
00036   unsigned int error_code;                      
00037   unsigned int eip;                             
00038   unsigned int code_seg;                        
00039   unsigned int eflags;                          
00040 };
00041 
00042 typedef void (*Handler_func)(volatile Handler_registers&);
00043 static const unsigned int INTERRUPT_COUNT = 48;
00044 
00047 
00048 class Interrupts {
00049 protected:
00050                                         // 2 pushes (4 bytes) + 1 jmp (5 bytes)
00051   static const unsigned int ISR_SIZE = 9;
00052   Int_descriptor int_table[INTERRUPT_COUNT];
00053   
00054 public:
00056   void
00057   init();
00058 
00060   void
00061   register_handler(unsigned char int_num, Handler_func handler);
00062 
00064   void
00065   unregister_handler(unsigned char int_num);
00066 };
00067 
00069 extern "C" void isr0() asm("isr0");
00070 
00072 extern "C" void
00073 interrupt_dispatcher(volatile Handler_registers registers);
00074 
00075 static const unsigned char FLOPPY_INTERRUPT = 0x26;
00076 static const unsigned char TIMER_INTERRUPT = 0x20;
00077 static const unsigned char PAGE_FAULT_INTERRUPT = 0x0e;
00078 
00079 #endif
00080 
00081 /* Torsion Operating System, Copyright (C) 2000-2002 Dan Helfman
00082  *
00083  * This program is free software; you can redistribute it and/or modify it
00084  * under the terms of the GNU General Public License as published by the
00085  * Free Software Foundation; either version 2 of the License, or (at your
00086  * option) any later version.
00087  * 
00088  * This program is distributed in the hope that it will be useful, but
00089  * WITHOUT ANY WARRANTY; without even the implied warranty of
00090  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00091  * General Public License for more details (in the COPYING file).
00092  * 
00093  * You should have received a copy of the GNU General Public License along
00094  * with this program; if not, write to the Free Software Foundation, Inc.,
00095  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00096  */

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