Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
I'm trying to get basic keyboard input working in x86 protected mode.
I'm primarily confused about how this works. My first guess was to assume that there was a special hardware interrupt--the interrupt handler would save some state in some globals, and then the OS would process the key when it got a chance later.
However, I have not found any such examples of this happening, and in the examples I have found, I'm having trouble seeing how interrupts fit into it at all. For example, one OS simple asks for a key with inportb (as defined here):
You can do it both ways. A single-tasking OS / application might just busy-poll the keyboard IO-ports instead of relying on a functional IRQ-system (I use this in the crash-debugger, where interrupts might be non-functional). In a multitasking OS, you need to use the interrupt method in order to be able to do other things than waiting for keyboard input.
I'm trying to get basic keyboard input working in x86 protected mode.
I'm primarily confused about how this works. My first guess was to assume that there was a special hardware interrupt--the interrupt handler would save some state in some globals, and then the OS would process the key when it got a chance later.
However, I have not found any such examples of this happening, and in the examples I have found, I'm having trouble seeing how interrupts fit into it at all. For example, one OS simple asks for a key with inportb (as defined here):
while (!(inportb(0x64)&0x01)); // 0x64 is for reading the 8042 status register
rawkey = inportb(0x60);
Is this how it's generally supposed to be done? How do interrupts enter into it? Is there a code example that demonstrates?
Thanks,
Well, keyboard is a bit confusing and you need to do several things to use it. First you have to realize that the keyboard is connected to the PS/2 controler (or USB, but I wonb't go there). And the PS/2 controler is connected to the PIC (programmable interrupt controler) and the PIC is connected to the CPU. When all is setup correctly the PS/2 controler sends a clock pulse to the keyboard, the keyboard checks if you have pressed any key. If so it sends the scan code to the PS/2 controler. The PS/2 controller sends an interrupt to the PIC, the PIC sends an interrupt to the CPU and the CPU invokes the programmed interrupt. The ISR (interrupt service routine) then needs to read the keyboard scancode from the PS/2 controler (rawkey = inportb(0x60);) and needs to signal end-of-interrupt to the PIC before calling iret.
Look for the articles about keyboard, PS/2 and PIC on http://wiki.osdev.org. But note one left out bit: You need to enable the clock signal for the port on the PS/2 controler. The wiki assumes it is on which isn't always the case,
Life - Don't talk to me about LIFE!
So long and thanks for all the fish.