# 8259.c

Go to the documentation of this file.

    00001 /*****************************************************************************************
    00002  Copyright (c) 2002-2004 The UbixOS Project
    00003  All rights reserved.
    00004
    00005  Redistribution and use in source and binary forms, with or without modification, are
    00006  permitted provided that the following conditions are met:
    00007
    00008  Redistributions of source code must retain the above copyright notice, this list of
    00009  conditions, the following disclaimer and the list of authors.  Redistributions in binary
    00010  form must reproduce the above copyright notice, this list of conditions, the following
    00011  disclaimer and the list of authors in the documentation and/or other materials provided
    00012  with the distribution. Neither the name of the UbixOS Project nor the names of its
    00013  contributors may be used to endorse or promote products derived from this software
    00014  without specific prior written permission.
    00015
    00016  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
    00017  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00018  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
    00019  THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    00020  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
    00021  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    00022  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
    00023  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    00024  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00025
    00026  $Id: 8259_8c-source.html 88 2016-01-12 00:11:29Z reddawg $
    00027
    00028 *****************************************************************************************/
    00029
    00030 #include <isa/8259.h>
    00031 #include <sys/io.h>
    00032 #include <lib/kprintf.h>
    00033
    00034 static unsigned int irqMask = 0xFFFF;
    00035
    00042 int i8259_init() {
    00043   outportByte(mPic,   icw1); /* Initialize Master PIC           */
    00044   outportByte(sPic,   icw1); /* Initialize Seconary PIC         */
    00045   outportByte(mPic+1, mVec); /* Master Interrup Vector          */
    00046   outportByte(sPic+1, sVec); /* Secondary Interrupt Vector      */
    00047   outportByte(mPic+1, 1<<2); /* Bitmask for cascade on IRQ 2    */
    00048   outportByte(sPic+1, 2);    /* Cascade on IRQ 2                */
    00049   outportByte(mPic+1, icw4); /* Finish Primary Initialization   */
    00050   outportByte(sPic+1, icw4); /* Finish Seconary Initialization  */
    00051   outportByte(mImr,   0xff); /* Mask All Primary Interrupts     */
    00052   outportByte(sImr,   0xff); /* Mask All Seconary Interrupts    */
    00053
    00054   /* Print out the system info for this */
    00055   kprintf("pic0 - Port: [0x%X]\n",mPic);
    00056   kprintf("pic1 - Port: [0x%X]\n",sPic);
    00057
    00058   /* Return so the system knows it went well */
    00059   return(0x0);
    00060   }
    00061
    00067 void irqEnable(u_int16_t irqNo) {
    00068   irqMask &= ~(1 << irqNo);
    00069   if (irqNo >= 8) {
    00070     irqMask &= ~(1 << 2);
    00071     }
    00072   outportByte(mPic+1, irqMask & 0xFF);
    00073   outportByte(sPic+1, (irqMask >> 8) & 0xFF);
    00074   }
    00075
    00081 void irqDisable(u_int16_t irqNo) {
    00082   irqMask |= (1 << irqNo);
    00083   if ((irqMask & 0xFF00)==0xFF00) {
    00084     irqMask |= (1 << 2);
    00085     }
    00086   outportByte(mPic+1, irqMask & 0xFF);
    00087   outportByte(sPic+1, (irqMask >> 8) & 0xFF);
    00088   }
    00089
    00090 /***
    00091  END
    00092  ***/