00001 // See the end of this file for license information. 00002 00003 #ifndef TORSION_IRQ_H 00004 #define TORSION_IRQ_H 00005 00006 #include "list.h" 00007 #include "types.h" 00008 00009 class Interrupts; 00010 extern Interrupts interrupts; 00011 00013 00014 class Int_descriptor { 00015 public: 00016 unsigned handler_low: 16; 00017 unsigned handler_selector: 16; 00018 unsigned unused: 8; 00019 unsigned access_type: 8; 00020 unsigned handler_high: 16; 00021 static const unsigned short int INTERRUPT_GATE = 0x8e; 00022 static const unsigned short int TRAP_GATE = 0x8f; 00023 00026 inline void 00027 set_handler(void* handler) { 00028 handler_low = ((unsigned)handler & 0xffff); 00029 handler_high = ((unsigned)handler >> 16); 00030 asm volatile("movl %%cs, %0" : "=r" (handler_selector)); 00031 unused = 0; 00032 } 00033 }; 00034 00037 00038 struct Handler_registers { 00040 unsigned edi, esi, ebp, esp, ebx, edx, ecx, eax; 00041 unsigned int_num; 00042 unsigned error_code; 00043 unsigned eip; 00044 unsigned code_seg; 00045 unsigned eflags; 00046 }; 00047 00048 static const unsigned INTERRUPT_COUNT = 48; 00049 typedef bool (*Handler_func)(); 00050 00052 00053 class Int_handler : public List_node { 00054 public: 00055 Handler_func function; 00056 00057 void 00058 init(Handler_func handler_function); 00059 00061 void 00062 print(); 00063 }; 00064 00069 00070 class Interrupts { 00071 protected: 00072 static const Size ISR_SIZE = 9; 00073 Int_descriptor int_table[INTERRUPT_COUNT]; 00074 00075 public: 00077 void 00078 init(); 00079 00081 void 00082 register_handler(unsigned char int_num, Int_handler& handler); 00083 00085 void 00086 unregister_handler(unsigned char int_num, Int_handler& handler); 00087 00089 void 00090 print(); 00091 }; 00092 00094 extern "C" void isr0() asm("isr0"); 00095 00097 extern "C" void 00098 interrupt_dispatcher(volatile Handler_registers reg); 00099 00100 static const unsigned char PAGE_FAULT_INTERRUPT = 0x0e; 00101 static const unsigned char TIMER_INTERRUPT = 0x20; 00102 static const unsigned char KEYBOARD_INTERRUPT = 0x21; 00103 static const unsigned char FLOPPY_INTERRUPT = 0x26; 00104 00105 #endif 00106 00107 /* Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman 00108 * 00109 * This program is free software; you can redistribute it and/or modify it 00110 * under the terms of the GNU General Public License as published by the 00111 * Free Software Foundation; either version 2 of the License, or (at your 00112 * option) any later version. 00113 * 00114 * This program is distributed in the hope that it will be useful, but 00115 * WITHOUT ANY WARRANTY; without even the implied warranty of 00116 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00117 * General Public License for more details (in the COPYING file). 00118 * 00119 * You should have received a copy of the GNU General Public License along 00120 * with this program; if not, write to the Free Software Foundation, Inc., 00121 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00122 */
Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman