Question: I'm working on keyboard input for a very basic kernel that I'm developing and I'm completely stuck. I can't seem to find any information online that can show me the information I need to know.

My kernel is running in protected mode right now, so I can't use the real mode keyboard routines without jumping into real mode and back, which I'm trying to avoid. I want to be able to access my keyboard from protected mode. Does anyone know how to do this? The only thing I have found so far is that it involves talking to the controller directly using in/out ports, but beyond that I'm stumped. This is, of course, is not something that comes up very often. Normally, Assembly tutorials assume you're running an operating system underneath.

I'm very new to the x86 assembly, so I'm just looking for some good resources for working with the standard hardware from protected mode. I'm compiling the Assembly source code with NASM and linking it to the C source code compiled with DJGPP. Any suggestions?

Answer: 
The [MIT operating systems class](http://course.mit.edu/6.828) has lots of good references. In particular, check out [Adam Chapweske's resources](http://www.computer-engineering.org/index.html) on keyboard and mouse programming.

In short, yes, you will be using the raw in/out ports, which requires either running in kernel mode, or having the I/O permission bits (IOPL) set in the EFLAGS register. See [this page](http://pdos.csail.mit.edu/6.828/2008/readings/i386/s08_03.htm) for more details on I/O permissions.
The **8042 PS/2 Controller** looks like the simplest possibility.

The oszur11 OS tutorial contains a working example under <https://sourceforge.net/p/oszur11/code/ci/master/tree/Chapter_06_Shell/04_Makepp/arch/i386/arch/devices/i8042.c>

Just:

```
sudo apt-get install build-essential qemu
sudo ln -s /usr/bin/qemu-system-i386 /usr/bin/qemu
git clone git://git.code.sf.net/p/oszur11/code oszur11
cd oszur11/Chapter_06_Shell/04_Makepp
make qemu

```

Tested on Ubuntu 14.04 AMD64.

My GitHub mirror (upstream inactive): <https://github.com/cirosantilli/oszur11-operating-system-examples>

Not reproducing it here because the code it too long, will update if I manage to isolate the keyboard part in a minimal example.