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

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