net: data reception system, fixed bugs in rtl8139
[quarnos.git] / services / interrupt_manager.cpp
blobe234b82e7418c74d1556fa8ad92da58504c998e6
1 /* Quarn OS
3 * Interrupt manager
5 * Copyright (C) 2009 Pawel Dziepak
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "interrupt_manager.h"
24 #include "manes/manec.h"
25 #include "manes/error.h"
26 #include "arch/low/pit.h"
27 #include "arch/low/irq.h"
29 using namespace services;
31 /* Cache Interrupt Manager */
32 p<interrupt_manager> im = p<interrupt_manager>::invalid;
34 void interrupt(int i) {
35 im->interrupt_called(i);
38 interrupt_manager::interrupt_manager() {
39 im = this;
42 void interrupt_manager::register_interrupt(unsigned int i, delegate<void> handler) {
43 if (i == 0x32 || i == 0x33)
44 critical("Can not override 0x32 and 0x33 interrupt handlers.");
46 handlers[i] = handler;
48 arch::unmask_irq(i - 0x20);
51 void interrupt_manager::free_interrupt(unsigned int i) {
52 arch::unlock_irqs(i - 0x20);
55 void interrupt_manager::interrupt_called(unsigned int i) {
56 if (!handlers[i].null())
57 handlers[i]();
58 else
59 /* throw */ critical((string)"Unknown interrupt occured: 0x" + string(i,true));
62 void interrupt_manager::register_type() {
63 manes::manec::get()->register_type<interrupt_manager>("interrupt_manager", "service");