Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

pic.h

Go to the documentation of this file.
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 class PIC;
00009 extern PIC pic;
00010 
00011 typedef enum {
00012   PIC_IO_BASE_0 = 0x20,
00013   PIC_IO_BASE_1 = 0xA0
00014 } PIC_io_base;
00015 
00016 typedef enum {
00017   PIC_REGISTER_DATA             = 0,
00018   PIC_REGISTER_COMMAND          = 0,
00019   PIC_REGISTER_INITIALIZE       = 1,
00020   PIC_REGISTER_INTERRUPT_ENABLE = 1
00021 } PIC_register;
00022 
00023 typedef enum {
00024   PIC_COMMAND_READ_INTERRUPT_REQUESTS            = 0x0A,
00025   PIC_COMMAND_READ_INTERRUPTS_IN_SERVICE         = 0x0B,
00026         
00027   PIC_COMMAND_END_OF_INTERRUPT                   = 0x20,
00028   PIC_COMMAND_ROTATIN_PRIORITY_END_OF_INTERRUPT  = 0xA0,
00029 
00030   PIC_COMMAND_CLEAR_SPECIAL_MASK_MODE            = 0x48,
00031   PIC_COMMAND_SET_SPECIAL_MASK_MODE              = 0x68,
00032         
00033   PIC_COMMAND_END_OF_INTERRUPT_0                 = 0x60,
00034   PIC_COMMAND_END_OF_INTERRUPT_1                 = 0x61,
00035   PIC_COMMAND_END_OF_INTERRUPT_2                 = 0x62,
00036   PIC_COMMAND_END_OF_INTERRUPT_3                 = 0x63,
00037   PIC_COMMAND_END_OF_INTERRUPT_4                 = 0x64,
00038   PIC_COMMAND_END_OF_INTERRUPT_5                 = 0x65,
00039   PIC_COMMAND_END_OF_INTERRUPT_6                 = 0x66,
00040   PIC_COMMAND_END_OF_INTERRUPT_7                 = 0x67,
00041         
00042   PIC_COMMAND_SELECT_IRQ_PRIORITY_0              = 0xC0,
00043   PIC_COMMAND_SELECT_IRQ_PRIORITY_1              = 0xC1,
00044   PIC_COMMAND_SELECT_IRQ_PRIORITY_2              = 0xC2,
00045   PIC_COMMAND_SELECT_IRQ_PRIORITY_3              = 0xC3,
00046   PIC_COMMAND_SELECT_IRQ_PRIORITY_4              = 0xC4,
00047   PIC_COMMAND_SELECT_IRQ_PRIORITY_5              = 0xC5,
00048   PIC_COMMAND_SELECT_IRQ_PRIORITY_6              = 0xC6,
00049   PIC_COMMAND_SELECT_IRQ_PRIORITY_7              = 0xC7,
00050 
00051   PIC_COMMAND_INITIALIZATION_MODE                = 0x11
00052 } PIC_command;
00053 
00057 
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     if (int_num >= 0x20) {
00087       unsigned char irq_num = int_to_irq(int_num);
00088       write_register((irq_num < 8) ? PIC_IO_BASE_0 : PIC_IO_BASE_1,
00089                      PIC_REGISTER_COMMAND, PIC_COMMAND_END_OF_INTERRUPT);
00090     }
00091   }
00092 
00094   void
00095   mask_irq(unsigned char int_num);
00096 
00098   void
00099   unmask_irq(unsigned char int_num);
00100 
00102   static inline unsigned char
00103   int_to_irq(unsigned char irq_num) {
00104     return irq_num - 0x20;
00105   }
00106 
00108   void
00109   print();
00110 };
00111 
00112 #endif
00113 
00114 /* Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman
00115  *
00116  * This program is free software; you can redistribute it and/or modify it
00117  * under the terms of the GNU General Public License as published by the
00118  * Free Software Foundation; either version 2 of the License, or (at your
00119  * option) any later version.
00120  * 
00121  * This program is distributed in the hope that it will be useful, but
00122  * WITHOUT ANY WARRANTY; without even the implied warranty of
00123  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00124  * General Public License for more details (in the COPYING file).
00125  * 
00126  * You should have received a copy of the GNU General Public License along
00127  * with this program; if not, write to the Free Software Foundation, Inc.,
00128  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00129  */

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