interrupts mechanisms, serial port data receiver
[quarnos.git] / arch / x86 / serial_port.cpp
blob55f8fd8b2b7646459c8ad896766600af21d248f5
1 #include "arch_asm.h"
2 #include "serial_port.h"
3 #include "interrupts.h"
5 using namespace arch;
6 namespace arch {
7 delegate<void, const char> serialport_handler;
9 extern "C" void serialport_irq(void);
10 void arch::serialport_init(delegate<void, const char> sp_hndl) {
12 serialport_handler = sp_hndl;
14 /* Get access to the clock registers */
15 outb(0x3fb,inb(0x3fb)|(1<<7));
17 /* Set transmission speed (the highest possible) */
18 outb(0x3f8, 1);
19 outb(0x3f9, 0);
21 /* Restore default registers access */
22 outb(0x3fb,inb(0x3fb)& ~(1<<7));
24 /* Set 8bit data format */
25 outb(0x3fb, 3);
27 /* Call interrupt at every received byte */
28 outb(0x3f9, 1);
30 /* Set IRQ4 */
31 set_irq(0x24, serialport_irq);
34 void arch::serialport_send(const char sign) {
35 outb(0x3f8, sign);
38 extern "C" void arch::serialport_received() {
39 unlock_irqs(4);
40 serialport_handler(inb(0x3f8));
43 __asm__ __volatile__("serialport_irq:\n\tcall serialport_received\n\tiret");