00001 // See the end of this file for license information. 00002 00003 #ifndef TORSION_PIC_H 00004 #define TORSION_PIC_H 00005 00006 #include "asm.h" 00007 00008 typedef enum { 00009 PIC_IO_BASE_0 = 0x20, 00010 PIC_IO_BASE_1 = 0xA0 00011 } PIC_io_base; 00012 00013 typedef enum { 00014 PIC_REGISTER_DATA = 0, 00015 PIC_REGISTER_COMMAND = 0, 00016 PIC_REGISTER_INITIALIZE = 1, 00017 PIC_REGISTER_INTERRUPT_ENABLE = 1 00018 } PIC_register; 00019 00020 typedef enum { 00021 PIC_COMMAND_READ_INTERRUPT_REQUESTS = 0x0A, 00022 PIC_COMMAND_READ_INTERRUPTS_IN_SERVICE = 0x0B, 00023 00024 PIC_COMMAND_END_OF_INTERRUPT = 0x20, 00025 PIC_COMMAND_ROTATIN_PRIORITY_END_OF_INTERRUPT = 0xA0, 00026 00027 PIC_COMMAND_CLEAR_SPECIAL_MASK_MODE = 0x48, 00028 PIC_COMMAND_SET_SPECIAL_MASK_MODE = 0x68, 00029 00030 PIC_COMMAND_END_OF_INTERRUPT_0 = 0x60, 00031 PIC_COMMAND_END_OF_INTERRUPT_1 = 0x61, 00032 PIC_COMMAND_END_OF_INTERRUPT_2 = 0x62, 00033 PIC_COMMAND_END_OF_INTERRUPT_3 = 0x63, 00034 PIC_COMMAND_END_OF_INTERRUPT_4 = 0x64, 00035 PIC_COMMAND_END_OF_INTERRUPT_5 = 0x65, 00036 PIC_COMMAND_END_OF_INTERRUPT_6 = 0x66, 00037 PIC_COMMAND_END_OF_INTERRUPT_7 = 0x67, 00038 00039 PIC_COMMAND_SELECT_IRQ_PRIORITY_0 = 0xC0, 00040 PIC_COMMAND_SELECT_IRQ_PRIORITY_1 = 0xC1, 00041 PIC_COMMAND_SELECT_IRQ_PRIORITY_2 = 0xC2, 00042 PIC_COMMAND_SELECT_IRQ_PRIORITY_3 = 0xC3, 00043 PIC_COMMAND_SELECT_IRQ_PRIORITY_4 = 0xC4, 00044 PIC_COMMAND_SELECT_IRQ_PRIORITY_5 = 0xC5, 00045 PIC_COMMAND_SELECT_IRQ_PRIORITY_6 = 0xC6, 00046 PIC_COMMAND_SELECT_IRQ_PRIORITY_7 = 0xC7, 00047 00048 PIC_COMMAND_INITIALIZATION_MODE = 0x11 00049 } PIC_command; 00050 00052 00058 class PIC { 00059 protected: 00060 unsigned char masks[2]; 00061 00063 inline unsigned char 00064 read_register(PIC_io_base io_base, PIC_register register_num) { 00065 return inb(io_base + register_num); 00066 } 00067 00069 inline void 00070 write_register(PIC_io_base io_base, PIC_register register_num, 00071 unsigned char data) { 00072 outb(data, io_base + register_num); 00073 } 00074 00075 public: 00078 void 00079 init(); 00080 00084 inline void 00085 signal_end_of_irq(unsigned char int_num) { 00086 unsigned char irq_num = int_to_irq(int_num); 00087 write_register((irq_num < 8) ? PIC_IO_BASE_0 : PIC_IO_BASE_1, 00088 PIC_REGISTER_COMMAND, PIC_COMMAND_END_OF_INTERRUPT); 00089 } 00090 00092 void 00093 mask_irq(unsigned char int_num); 00094 00096 void 00097 unmask_irq(unsigned char int_num); 00098 00100 static inline unsigned char 00101 int_to_irq(unsigned char irq_num) { 00102 return irq_num - 0x20; 00103 } 00104 }; 00105 00106 #endif 00107 00108 /* Torsion Operating System, Copyright (C) 2000-2002 Dan Helfman 00109 * 00110 * This program is free software; you can redistribute it and/or modify it 00111 * under the terms of the GNU General Public License as published by the 00112 * Free Software Foundation; either version 2 of the License, or (at your 00113 * option) any later version. 00114 * 00115 * This program is distributed in the hope that it will be useful, but 00116 * WITHOUT ANY WARRANTY; without even the implied warranty of 00117 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00118 * General Public License for more details (in the COPYING file). 00119 * 00120 * You should have received a copy of the GNU General Public License along 00121 * with this program; if not, write to the Free Software Foundation, Inc., 00122 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00123 */
Torsion Operating System, Copyright (C) 2000-2002 Dan Helfman