Hi,
thumble wrote:I'm working on PS/2 keyboard support on my kernel. There are scancodes with "E0, xx", and I'm not too sure how these are supposed to work.
I think this means that I read the scancode, 0xE0, and if it's 0xE0 I read another byte, which is the scancode. This doesn't really work.
Typically you have a state machine, where you have a default state (nothing received yet) and an "0xE0 received" state (and a bunch of other states for other sequences); and when you receive a byte you look at both the state and the byte received to determine what to do and which state to move into next.
The fastest and most flexible way to handle this might be with a table of function pointers; like:
Code: Select all
int state = 0;
int newByte = 0;
void kb_irq_handler(void) {
newByte = inb(0x60);
state = (*functionTable[state << 8 | newByte])();
}
In this case; during initialisation you'd configure the table of function pointers; possibly starting with "pre-configuration" where you add table entries for special bytes (0x00 = keyboard error, 0xAA = self test passed, 0xEE = echo, ...) and set everything else to a generic "invalid sequence" function, and then you'd parse some kind of keyboard layout file to determine how the rest of the table of function pointers should be setup; so that the driver is able to handle radically different keyboards just by providing different keyboard layout files (potentially including being able to support different scan code sets).
thumble wrote:When pressing any keys with an E0 scancode it immediately prints the second part (i.e. 1D for RCTRL) which is correct, but I'm not getting an E0. Why might this be? Am I misunderstanding something?
edit: It works fine for keys without an E0.
How do you know that you're not getting an 0xE0? For example, if you're doing some kind of "printChar(ASCII);" then maybe the problem is that there's no way to convert the 0xE0 byte into valid ASCII, if you're doing some kind of "printHex(byte)" then maybe your "printHex()" function is buggy, ...
Also note that some emulators struggle to emulate keyboards 100% accurately. For example, the host OS might tell the emulator that a control key was pressed (but not which one), so the emulator might tell the guest OS that left control was pressed (0x1D) even though the user actually pressed the right control key (0xE0, 0x1D).
Cheers,
Brendan