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

Last change on this file since 4333 was 4333, checked in by Sam Hocevar, 10 years ago

Large source code cleanup, getting rid of spaces, tabs, and svn keywords.

File size: 1.9 KB
Line 
1/*
2 *  libcaca       Colour ASCII-Art library
3 *  Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
4 *                2009 Jean-Yves Lamoureux <jylam@lnxscene.org>
5 *                All Rights Reserved
6 *
7 *  This library is free software. It comes without any warranty, to
8 *  the extent permitted by applicable law. You can redistribute it
9 *  and/or modify it under the terms of the Do What The Fuck You Want
10 *  To Public License, Version 2, as published by Sam Hocevar. See
11 *  http://sam.zoy.org/wtfpl/COPYING for more details.
12 */
13
14
15#include "klibc.h"
16
17#define PIC_MASTER_ICW1 0x20
18#define PIC_MASTER_ICW2 0x21
19
20#define PIC_SLAVE_ICW1  0xA0
21#define PIC_SLAVE_ICW2  0xA1
22
23
24void init_pic(void)
25{
26    /* MASTER */
27    outbp(PIC_MASTER_ICW1, 0x11);       // Init 8259A-1
28    /* ICW2 - start vector = 32 */
29    outbp(PIC_MASTER_ICW2, 0x20);       // IRQ 0-7 mapped to 0x20-0x27
30    /* IICW3 */
31    outbp(PIC_MASTER_ICW2, 0x04);       // 8259A-1 has slave
32    /* ICW4 */
33    outbp(PIC_MASTER_ICW2, 0x01);
34    /* Int mask */
35    outbp(PIC_MASTER_ICW2, 0xFF);
36
37    /* SLAVE */
38    outbp(PIC_SLAVE_ICW1, 0x11);
39    /* ICW2 - start vector = 96 */
40    outbp(PIC_SLAVE_ICW2, 0x70);
41    /* ICW3 */
42    outbp(PIC_SLAVE_ICW2, 0x02);
43    /* ICW4 */
44    outbp(PIC_SLAVE_ICW2, 0x01);
45    /* Int Mask */
46    outbp(PIC_SLAVE_ICW2, 0xFF);
47
48
49    /* Unmask irqs */
50    outbp(0x21, 0xFD);
51
52}
53
54static unsigned int cached_irq_mask = 0xffff;
55
56#define __byte(x,y)     (((unsigned char *)&(y))[x])
57#define cached_21       (__byte(0,cached_irq_mask))
58#define cached_A1       (__byte(1,cached_irq_mask))
59
60void disable_interrupt(char irq)
61{
62    unsigned int mask = 1 << irq;
63
64    cached_irq_mask |= mask;
65    if (irq & 8)
66    {
67        outb(0xA1, cached_A1);
68    }
69    else
70    {
71        outb(0x21, cached_21);
72    }
73}
74
75void enable_interrupt(char irq)
76{
77    unsigned int mask = ~(1 << irq);
78
79    cached_irq_mask &= mask;
80    if (irq & 8)
81    {
82        outb(0xA1, cached_A1);
83    }
84    else
85    {
86        outb(0x21, cached_21);
87    }
88
89}
Note: See TracBrowser for help on using the repository browser.