source: libcaca/trunk/kernel/boot/pic.c @ 4154

Last change on this file since 4154 was 4154, checked in by Jean-Yves Lamoureux, 10 years ago
  • Total kernel rewrite
File size: 1.3 KB
Line 
1#include "klibc.h"
2
3#define PIC_MASTER_ICW1 0x20
4#define PIC_MASTER_ICW2 0x21
5
6#define PIC_SLAVE_ICW1  0xA0
7#define PIC_SLAVE_ICW2  0xA1
8
9
10void init_pic(void)
11{
12        /* MASTER */
13    outbp(PIC_MASTER_ICW1,0x11); // Init 8259A-1
14    /* ICW2 - start vector = 32 */
15    outbp(PIC_MASTER_ICW2,0x20); // IRQ 0-7 mapped to 0x20-0x27
16    /* IICW3 */
17    outbp(PIC_MASTER_ICW2,0x04); // 8259A-1 has slave
18    /* ICW4 */
19    outbp(PIC_MASTER_ICW2,0x01);
20    /* Int mask */
21    outbp(PIC_MASTER_ICW2,0xFF);
22   
23        /* SLAVE */
24    outbp(PIC_SLAVE_ICW1,0x11);
25        /* ICW2 - start vector = 96 */
26    outbp(PIC_SLAVE_ICW2,0x70);     
27        /* ICW3 */
28    outbp(PIC_SLAVE_ICW2,0x02);
29        /* ICW4 */
30    outbp(PIC_SLAVE_ICW2,0x01);
31        /* Int Mask */
32    outbp(PIC_SLAVE_ICW2,0xFF);
33   
34   
35        /* Unmask irqs */
36    outbp(0x21,0xFD);
37   
38}
39
40static unsigned int cached_irq_mask = 0xffff;
41
42#define __byte(x,y)     (((unsigned char *)&(y))[x])
43#define cached_21       (__byte(0,cached_irq_mask))
44#define cached_A1       (__byte(1,cached_irq_mask))
45
46void disable_interrupt(char irq)
47{
48        unsigned int mask = 1 << irq;
49       
50        cached_irq_mask |= mask;
51    if (irq & 8) {
52                outb(0xA1, cached_A1);
53    } else {
54                outb(0x21, cached_21);
55    }
56}
57
58void enable_interrupt(char irq)
59{
60        unsigned int mask = ~(1 << irq);
61   
62        cached_irq_mask &= mask;
63        if (irq & 8) {
64                outb(0xA1, cached_A1);
65    } else {
66                outb(0x21, cached_21);
67    }
68
69}
70
71
72
73
Note: See TracBrowser for help on using the repository browser.