UbixOS  2.0
8259.c
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2002-2018 The UbixOS Project.
3  * All rights reserved.
4  *
5  * This was developed by Christopher W. Olsen for the UbixOS Project.
6  *
7  * Redistribution and use in source and binary forms, with or without modification, are permitted
8  * provided that the following conditions are met:
9  *
10  * 1) Redistributions of source code must retain the above copyright notice, this list of
11  * conditions, the following disclaimer and the list of authors.
12  * 2) Redistributions in binary form must reproduce the above copyright notice, this list of
13  * conditions, the following disclaimer and the list of authors in the documentation and/or
14  * other materials provided with the distribution.
15  * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to
16  * endorse or promote products derived from this software without specific prior written
17  * permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
20  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <isa/8259.h>
30 #include <sys/io.h>
31 #include <lib/kprintf.h>
32 
33 static unsigned int irqMask = 0xFFFF;
34 
41 int i8259_init() {
42  outportByte(mPic, icw1); /* Initialize Master PIC */
43  outportByte(sPic, icw1); /* Initialize Seconary PIC */
44  outportByte(mPic + 1, mVec); /* Master Interrup Vector */
45  outportByte(sPic + 1, sVec); /* Secondary Interrupt Vector */
46  outportByte(mPic + 1, 1 << 2); /* Bitmask for cascade on IRQ 2 */
47  outportByte(sPic + 1, 2); /* Cascade on IRQ 2 */
48  outportByte(mPic + 1, icw4); /* Finish Primary Initialization */
49  outportByte(sPic + 1, icw4); /* Finish Seconary Initialization */
50  outportByte(mImr, 0xff); /* Mask All Primary Interrupts */
51  outportByte(sImr, 0xff); /* Mask All Seconary Interrupts */
52 
53  /* Print out the system info for this */
54  kprintf("pic0 - Port: [0x%X]\n", mPic);
55  kprintf("pic1 - Port: [0x%X]\n", sPic);
56 
57  /* Return so the system knows it went well */
58  return (0x0);
59 }
60 
66 void irqEnable_old(u_int16_t irqNo) {
67  irqMask &= ~(1 << irqNo);
68  if (irqNo >= 8) {
69  irqMask &= ~(1 << 2);
70  }
71  outportByte(mPic + 1, irqMask & 0xFF);
72  outportByte(sPic + 1, (irqMask >> 8) & 0xFF);
73 }
74 
75 void irqEnable(uint16_t irqNo) {
76  uint16_t port;
77  uint8_t value;
78 
79  if (irqNo < 8) {
80  port = mImr;
81  }
82  else {
83  port = sImr;
84  irqNo -= 8;
85  }
86  value = inportByte(port) & ~(1 << irqNo);
87  outportByte(port, value);
88 }
89 
96  irqMask |= (1 << irqNo);
97  if ((irqMask & 0xFF00) == 0xFF00) {
98  irqMask |= (1 << 2);
99  }
100  outportByte(mPic + 1, irqMask & 0xFF);
101  outportByte(sPic + 1, (irqMask >> 8) & 0xFF);
102 }
103 
104 void irqDisable(uint16_t irqNo) {
105  uint16_t port;
106  uint8_t value;
107 
108  if (irqNo < 8) {
109  port = mImr;
110  }
111  else {
112  port = sImr;
113  irqNo -= 8;
114  }
115  value = inportByte(port) | (1 << irqNo);
116  outportByte(port, value);
117 }
118 
119 /***
120  END
121  ***/
8259.h
irqEnable
void irqEnable(uint16_t irqNo)
Definition: 8259.c:75
outportByte
void outportByte(unsigned int, unsigned char)
outputut one byte to specified port
Definition: io.c:72
icw4
#define icw4
Definition: 8259.h:40
irqDisable_old
void irqDisable_old(u_int16_t irqNo)
disable specified IRQ
Definition: 8259.c:95
mImr
#define mImr
Definition: 8259.h:35
icw1
#define icw1
Definition: 8259.h:39
inportByte
unsigned char inportByte(unsigned int)
input one byte from specified port
Definition: io.c:38
u_int16_t
__uint16_t u_int16_t
Definition: types.h:52
uint16_t
__uint16_t uint16_t
Definition: types.h:45
i8259_init
int i8259_init()
initialize the 8259 PIC
Definition: 8259.c:41
kprintf.h
sPic
#define sPic
Definition: 8259.h:36
irqDisable
void irqDisable(uint16_t irqNo)
Definition: 8259.c:104
sImr
#define sImr
Definition: 8259.h:37
irqEnable_old
void irqEnable_old(u_int16_t irqNo)
enable specified IRQ
Definition: 8259.c:66
mVec
#define mVec
Definition: 8259.h:41
sVec
#define sVec
Definition: 8259.h:42
io.h
uint8_t
__uint8_t uint8_t
Definition: types.h:44
kprintf
int kprintf(const char *,...)
Definition: kprintf.c:259
mPic
#define mPic
Definition: 8259.h:34