I finished the interrupt handler following this (http://www.jamesmolloy.co.uk/tutorial_h ... 20PIT.html) and other tutorials, now I want to implement to PIT.
I have an array of IRQs handlers and in the clock_init() function I register it and set the command port.
Code: Select all
void clock_init(uint32_t frequency) {
// Set the timer as the first IRQ
irq_installHandler(IRQ0, &tickHandler);
// The value sent to the PIT is the value to divide its input clock
// (1193180 Hz) by, to get the required frequency.
// Important to note is that the divisor must be small enough to fit into 16-bits.
uint16_t divisor = (uint16_t) (1193180 / frequency);
// The divisor must be sent 8 bits at a time
uint8_t low = (uint8_t) (divisor & 0xFF);
uint8_t high = (uint8_t) ((divisor >> 8) & 0xFF);
// Send the command byte
outportb(0x43, 0x36);
// Send the frequency divisor
outportb(0x40, low);
outportb(0x40, high);
}
Code: Select all
void tickHandler(regs_t *r) {
tick++;
printf("Tick: %d\n", tick);
}
I tried to use only printf("Tick\n"); and it works printing an infinite list of Ticks, though. Also if I don't print anything, the page fault doesn't occur.
Now, can someone please help me figure out if is that a problem and how can I solve it? Perhaps an error in the printf?
Code: Select all
int printf(const char *format, ...) {
char *s;
va_list list;
va_start(list, format);
while(*format != '\0') {
if (*format == '%') {
// Handle the format specifier
format++;
switch (*format) {
// Character
case 'c':
putc((char)va_arg(list, int));
break;
// String
case 's':
s = (char *)va_arg(list, int);
puts(s);
break;
// Hexadecimal
case 'x':
s = utoa((uint64_t)va_arg(list, int), s, 16);
puts(s);
break;
// Decimal
case 'd':
s = itoa((int)va_arg(list, int), s, 10);
puts(s);
break;
// Unsigned
case 'u':
s = utoa((uint64_t)va_arg(list, int), s, 10);
puts(s);
break;
// Binary
case 'b':
s = utoa((uint64_t)va_arg(list, int), s, 2);
puts(s);
break;
default:
return -1;
}
format++;
} else
putc(*format++);
}
va_end(list);
return 1;
}