I'll give you a little code:
Code: Select all
init_8259s();
kprintf("[MSG] Installing keyboard interrupt handler...\n");
/* we don't save the old vector */
v.eip = (unsigned)keyboard_irq;
v.access_byte = 0x8E; /* present, ring 0, '386 interrupt gate */
setvect(&v, 0x21);
kprintf("[MSG] Setting Timer Frequency\n");
timer_phase(100000);
vector_t vtimer;
v.eip = (unsigned)timer_irq;
v.access_byte = 0x8E;
setvect(&vtimer, 0x08);
init_tasks();
kprintf("[MSG] Enabling hardware interrupts...\n");
enable();
Next I'll show you init_8259s();
Code: Select all
static void init_8259s(void)
{
static const unsigned irq0_int = 0x20, irq8_int = 0x28;
/**/
/* Initialization Control Word #1 (ICW1) */
outportb(0x20, 0x11);
outportb(0xA0, 0x11);
/* ICW2:
route IRQs 0-7 to INTs 20h-27h */
outportb(0x21, irq0_int);
/* route IRQs 8-15 to INTs 28h-2Fh */
outportb(0xA1, irq8_int);
/* ICW3 */
outportb(0x21, 0x04);
outportb(0xA1, 0x02);
/* ICW4 */
outportb(0x21, 0x01);
outportb(0xA1, 0x01);
/* enable IRQ0 (timer) and IRQ1 (keyboard) */
outportb(0x21, ~0x03);
outportb(0xA1, ~0x00);
}
Code: Select all
void timer_phase(int hz)
{
disable();
int divisor = 1193180 / hz; /* Calculate our divisor */
outportb(0x43, 0x36); /* Set our command byte 0x36 */
outportb(0x40, divisor & 0xFF); /* Set low byte of divisor */
outportb(0x40, divisor >> 8); /* Set high byte of divisor */
enable();
}
Code: Select all
void fault(regs_t *regs)
{
static const char * const msg[] =
{
"divide error", "debug exception", "NMI", "INT3",
"INTO", "BOUND exception", "invalid opcode", "no coprocessor",
"double fault", "coprocessor segment overrun",
"bad TSS", "segment not present",
"stack fault", "GPF", "page fault", "??",
"coprocessor error", "alignment check", "??", "??",
"??", "??", "??", "??",
"??", "??", "??", "??",
"??", "??", "??", "??",
"IRQ0", "IRQ1", "IRQ2", "IRQ3",
"IRQ4", "IRQ5", "IRQ6", "IRQ7",
"IRQ8", "IRQ9", "IRQ10", "IRQ11",
"IRQ12", "IRQ13", "IRQ14", "IRQ15",
"syscall"
};
/**/
switch(regs->which_int)
{
/* this handler installed at compile-time
Keyboard handler is installed at run-time (see below) */
case 0x20: /* timer IRQ 0 */
ticks++;
if (!(ticks % 310)){
blink();
kprintf("[SYS] %u\n", ticks/310);
}
/* reset hardware interrupt at 8259 chip */
outportb(0x20, 0x20);
break;
case 0x08:
blink();
outportb(0x20, 0x20);
break;
default:
kprintf("Exception #%u", regs->which_int);
if(regs->which_int <= sizeof(msg) / sizeof(msg[0]))
kprintf(" (%s)", msg[regs->which_int]);
kprintf("\n");
dump_regs(regs);
panic("Goodbye (system halted, use reset button to end)");
}
}
I tried setting it to fire twice a second, but that didn't seem to work.
I tried looking for int 0x8, like I read on google, but I don't get anything there.
I'm sorry if I've already asked something that's already been asked, I've been doing a lot of searching lately, including google, the forums, and the wiki.
Thanks!