Subversion Repositories shark

Rev

Rev 1621 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/* Project:     OSLib
2
 * Description: The OS Construction Kit
3
 * Date:                1.6.2000
4
 * Idea by:             Luca Abeni & Gerardo Lamastra
5
 *
6
 * OSLib is an SO project aimed at developing a common, easy-to-use
7
 * low-level infrastructure for developing OS kernels and Embedded
8
 * Applications; it partially derives from the HARTIK project but it
9
 * currently is independently developed.
10
 *
11
 * OSLib is distributed under GPL License, and some of its code has
12
 * been derived from the Linux kernel source; also some important
13
 * ideas come from studying the DJGPP go32 extender.
14
 *
15
 * We acknowledge the Linux Community, Free Software Foundation,
16
 * D.J. Delorie and all the other developers who believe in the
17
 * freedom of software and ideas.
18
 *
19
 * For legalese, check out the included GPL license.
20
 */
21
 
22
/*      Interrupt Events */
23
 
1621 fabio 24
#include <arch/i386/stdlib.h>
2 pj 25
#include <ll/i386/mem.h>
26
#include <ll/i386/error.h>
27
#include <ll/i386/hw-arch.h>
28
#include <ll/i386/pit.h>
40 pj 29
#include <ll/i386/pic.h>
2 pj 30
#include <ll/sys/ll/ll-data.h>
31
#include <ll/sys/ll/ll-instr.h>
32
#include <ll/sys/ll/time.h>
33
#include <ll/sys/ll/event.h>
34
 
35
FILE(IntEvent);
36
 
37
extern int activeInt;
38
void (*evt_prol) (void) = NULL;
39
void (*evt_epil) (void) = NULL;
40
 
41
struct intentry irqs[16];
42
 
43
void irq_init(void)
44
{
45
    int i;
46
 
47
    /* Initialize the interrupt handlers list!!! */
48
    for (i = 0; i < 16; i++) {
49
        irqs[i].status = INTSTAT_FREE;
50
        irqs[i].index = i;
51
        irqs[i].handler = NULL; /* Paranoia */
52
        irqs[i].par = NULL;     /* Paranoia */
53
    }
54
    activeInt = 0;
55
}
56
 
57
int ll_ActiveInt(void)
58
{
59
    return activeInt;
60
}
61
 
62
int irq_bind(int irq, void (*handler) (void *p), DWORD flags)
63
{
64
 
65
    if ((irqs[irq].status != INTSTAT_FREE) &&
66
        ((flags & INT_FORCE) != INT_FORCE)) {
67
        return -1;
68
    }
69
 
70
    irqs[irq].status = INTSTAT_ASSIGNED;
71
 
72
    if (handler != NULL) {
73
        irqs[irq].handler = handler;
74
        irqs[irq].par = &(irqs[irq].index);
75
        irqs[irq].flags = flags;
76
    } else {
77
        irqs[irq].status = INTSTAT_FREE;
78
    }
79
 
80
    return 1;
81
}
82
 
83
void act_int(BYTE n)
84
{
85
    static int ai_called = 0;
86
 
40 pj 87
    if ((n >= PIC1_BASE) && (n < PIC1_BASE + 8)) {
88
      n = n - PIC1_BASE;
89
    } else if ((n >= PIC2_BASE) && (n < PIC2_BASE + 8)) {
90
      n = n - PIC2_BASE + 8;
91
    } else {
92
      /* Wow... Here, we are in error... Return? */
93
      return;
94
    }
95
 
2 pj 96
    activeInt++;
97
    if (activeInt == 1 && evt_prol != NULL) {
98
        evt_prol();
99
    }
100
    if (irqs[n].status == INTSTAT_ASSIGNED) {
101
        irqs[n].status = INTSTAT_BUSY;
102
        if (irqs[n].flags & INT_PREEMPTABLE) {
103
            sti();
104
        }
105
        irqs[n].handler(irqs[n].par);
106
        if (irqs[n].flags & INT_PREEMPTABLE) {
107
            cli();
108
        }
109
        irqs[n].status = INTSTAT_ASSIGNED;
110
    }
111
    ai_called++;
112
    if (activeInt == 1 && evt_epil != NULL) {
113
        evt_epil();
114
    }
115
    activeInt--;
116
}
40 pj 117
 
118