X hits on this document

17 views

0 shares

0 downloads

0 comments

6 / 6

CPSC 410/611: Operating Systems

Projects: Exceptions + Interrupts

+

Hardware Interrupts: High Level

extern _dispatch_interrupt /* similar to ISRs */ irq_common_stub: pusha push ds push es push fs push gs mov ax, 0x10 mov ds, ax mov es, ax mov fs, ax mov gs, ax mov eax, esp push eax m o v e a x , _ d i s p a t c h _ i n t e r r u call eax pop eax pop gs pop fs pop es pop ds popa add esp, 8 iret p

void dispatch_interrupt(REGS * _r) {

unsigned int int_no = _r->int_no - IRQ_BASE; InterruptHandler handler = handler_table[int_no];

if (!handler) { /* --- NO DEFAULT HANDLER REGISTERED. */ abort();

}

handler(_r);

/* This is an interrupt that was raised by the interrupt controller. We need

to send and end-of-interrupt (EOI) signal to the controller after the interrupt has been handled. */ /* Check if the interrupt was generated by the slave interrupt controller.

If so, send an End-of-Interrupt (EOI) message to the slave controller. */ if (generated_by_slave_PIC(int_no)) { /* i.e. int_no < 8 */

outportb(0xA0, 0x20); } /* Send an EOI message to the master interrupt controller. */ outportb(0x20, 0x20);

}

+

Example: Periodic Timer

/* timer interrupt handler*/ void ptimer_handler(REGS *r) { /* Increment our "ticks" count */ ticks++; /* Whenever a second is over, we update counter. */ if (ticks >= hz ) { seconds++; ticks = 0; console_puts("One second has passed\n");

}

}

void main() {

gdt_init(); console_init(); idt_init(); init_exception_dispatcher(); irq_init(); init_interrupt_dispatcher();

/* Set the interrupt frequency for the simple timer. /* Preferably set this before installing the timer handler! void simple_timer_set_frequency(int _hz) {

simple_timer_set_frequency(100); /* timer ticks to 10ms. */ r e g i s t e r _ i n t e r r u p t _ h a n d l e r ( 0 , p t i m e r _ h a n d l e r ) ;

hz = hz;

_

/* Remember the frequen

int divisor = 1193180 / _hz; /* The input clock runs at outportb(0x43, 0x34); /* Set command byte to b outportb(0x40, divisor & 0xFF); /* Set low byte of divis

outportb(0x40, divisor >> 8);

/* Set high byte of divi

}

__

asm

_ _ _ _

volatile

__ ("sti");

console_puts("Hello World!\n");

for (;;);

}

6

Document info
Document views17
Page views17
Page last viewedFri Jan 20 10:00:22 UTC 2017
Pages6
Paragraphs138
Words1665

Comments