Rev 40 | Go to most recent revision | 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 | |||
24 | #include <ll/i386/stdlib.h> |
||
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 | cli(); /* Warning!!! Need to be changed... |
||
66 | Protect or not to protect??? |
||
67 | Probably save_flags??? */ |
||
68 | if ((irqs[irq].status != INTSTAT_FREE) && |
||
69 | ((flags & INT_FORCE) != INT_FORCE)) { |
||
70 | return -1; |
||
71 | } |
||
72 | |||
73 | irqs[irq].status = INTSTAT_ASSIGNED; |
||
74 | sti(); |
||
75 | |||
76 | if (handler != NULL) { |
||
77 | irqs[irq].handler = handler; |
||
78 | irqs[irq].par = &(irqs[irq].index); |
||
79 | irqs[irq].flags = flags; |
||
80 | } else { |
||
81 | irqs[irq].status = INTSTAT_FREE; |
||
82 | } |
||
83 | |||
84 | return 1; |
||
85 | } |
||
86 | |||
87 | void act_int(BYTE n) |
||
88 | { |
||
89 | static int ai_called = 0; |
||
90 | |||
40 | pj | 91 | if ((n >= PIC1_BASE) && (n < PIC1_BASE + 8)) { |
92 | n = n - PIC1_BASE; |
||
93 | } else if ((n >= PIC2_BASE) && (n < PIC2_BASE + 8)) { |
||
94 | n = n - PIC2_BASE + 8; |
||
95 | } else { |
||
96 | /* Wow... Here, we are in error... Return? */ |
||
97 | return; |
||
98 | } |
||
99 | |||
2 | pj | 100 | activeInt++; |
101 | if (activeInt == 1 && evt_prol != NULL) { |
||
102 | evt_prol(); |
||
103 | } |
||
104 | if (irqs[n].status == INTSTAT_ASSIGNED) { |
||
105 | irqs[n].status = INTSTAT_BUSY; |
||
106 | if (irqs[n].flags & INT_PREEMPTABLE) { |
||
107 | sti(); |
||
108 | } |
||
109 | irqs[n].handler(irqs[n].par); |
||
110 | if (irqs[n].flags & INT_PREEMPTABLE) { |
||
111 | cli(); |
||
112 | } |
||
113 | irqs[n].status = INTSTAT_ASSIGNED; |
||
114 | } |
||
115 | ai_called++; |
||
116 | if (activeInt == 1 && evt_epil != NULL) { |
||
117 | evt_epil(); |
||
118 | } |
||
119 | activeInt--; |
||
120 | } |
||
40 | pj | 121 | |
122 |