2013-08-26

2013-08-26 Interrupts and Printf

As part of the ongoing effort to get the Hello World program loading and running, I've been reimplementing the interrupt system.  This is needed to allow my OS to reply to the interrupt request which the program makes in order to get the first hook into the kernel.

The interrupt system comprises 48 assembly routines, one for each interrupt, which build a consistent stack frame, then push all the relevant registers of the state to the stack, including the number of the interrupt thrown.  A generic C handler for the interrupts is then called which dispatches messages to the various required handlers.

For three days I've been trying to work out why the interrupt number being printed from the interrupt handler wasn't correct.  I've put test values in the assembly, added infinite loops, examined the registers in Bochs,  even suspended the emulator and examined the memory by hand to check the stack frame.  I couldn't find anything wrong except that the wrong values were being printed to the screen.

I finally figured out what was wrong and tested the printf routine itself.  It failed the test.  Printf is, of course, a variadic function and the actual function itself is actualled called kstdio_printf().  I had created another function called kprintf() which then called it, but I messed up the call so it only passed the format parameter and not all the following parameters :(

Oh well, at least it's all working now.

No comments:

Post a Comment