File: pic.c

package info (click to toggle)
libcaca 0.99.beta20-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,540 kB
  • sloc: ansic: 25,091; php: 2,763; python: 2,637; cs: 1,213; cpp: 1,127; java: 916; objc: 836; makefile: 545; perl: 505; sh: 472; asm: 297; ruby: 215; xml: 33
file content (89 lines) | stat: -rw-r--r-- 1,984 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 *  libcaca       Colour ASCII-Art library
 *  Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
 *                2009 Jean-Yves Lamoureux <jylam@lnxscene.org>
 *                All Rights Reserved
 *
 *  This library is free software. It comes without any warranty, to
 *  the extent permitted by applicable law. You can redistribute it
 *  and/or modify it under the terms of the Do What the Fuck You Want
 *  to Public License, Version 2, as published by Sam Hocevar. See
 *  http://www.wtfpl.net/ for more details.
 */


#include "klibc.h"

#define PIC_MASTER_ICW1 0x20
#define PIC_MASTER_ICW2 0x21

#define PIC_SLAVE_ICW1  0xA0
#define PIC_SLAVE_ICW2  0xA1


void init_pic(void)
{
    /* MASTER */
    outbp(PIC_MASTER_ICW1, 0x11);       // Init 8259A-1
    /* ICW2 - start vector = 32 */
    outbp(PIC_MASTER_ICW2, 0x20);       // IRQ 0-7 mapped to 0x20-0x27
    /* IICW3 */
    outbp(PIC_MASTER_ICW2, 0x04);       // 8259A-1 has slave
    /* ICW4 */
    outbp(PIC_MASTER_ICW2, 0x01);
    /* Int mask */
    outbp(PIC_MASTER_ICW2, 0xFF);

    /* SLAVE */
    outbp(PIC_SLAVE_ICW1, 0x11);
    /* ICW2 - start vector = 96 */
    outbp(PIC_SLAVE_ICW2, 0x70);
    /* ICW3 */
    outbp(PIC_SLAVE_ICW2, 0x02);
    /* ICW4 */
    outbp(PIC_SLAVE_ICW2, 0x01);
    /* Int Mask */
    outbp(PIC_SLAVE_ICW2, 0xFF);


    /* Unmask irqs */
    outbp(0x21, 0xFD);

}

static unsigned int cached_irq_mask = 0xffff;

#define __byte(x,y) 	(((unsigned char *)&(y))[x])
#define cached_21	(__byte(0,cached_irq_mask))
#define cached_A1	(__byte(1,cached_irq_mask))

void disable_interrupt(char irq)
{
    unsigned int mask = 1 << irq;

    cached_irq_mask |= mask;
    if (irq & 8)
    {
        outb(0xA1, cached_A1);
    }
    else
    {
        outb(0x21, cached_21);
    }
}

void enable_interrupt(char irq)
{
    unsigned int mask = ~(1 << irq);

    cached_irq_mask &= mask;
    if (irq & 8)
    {
        outb(0xA1, cached_A1);
    }
    else
    {
        outb(0x21, cached_21);
    }

}