We are developing an operating system for my personal research
and practical education.
For the academic purpose, this motivation is similar to MINIX,
but we do not focus on theories.
Our main objective is to provide knowledges on hardware-related
programming. This is one of the most difficult and complex parts
when we start the development of operating system from scratch.
Checkpoint 4: Use programmable interrupt controller and read keyboard input
Interrupts from peripheral devices (IRQ: Interrupt Request)
are routed to a processor
by a Programmable Interrupt Controller (PIC), Intel 8259(A).
To handle an interrupt from the keyboard,
the corresponding interrupt handler that reads keyboard input
from the keyboard controller
is setup in the Interrupt Vector Table (IVT) in this checkpoint.
In PC/AT-compatible machines, the data and status/command ports
of the keyboard controller are assigned to 60h and 64h (read for the status register
and write for the command register), respectively.
The scan code that is read via the 60h port is different from the ascii code.
Therefore, we need to translate the scan code using a keymap.
There are three scan code sets; set 1 (IBM PC XT), set 2 (IBM PC AT),
and set 3 (IBM 3270 PC).
PC/AT-compatible machines use the scan code set 2,
but the keyboard controller usually translates it to the scan code set 1
for backward compatibility.
The scan code sets are found in
Keyboard-internal scancodes [external].
Line 228–237 is the simplified keymap for US keyboard
from the scan code set 1 to the ascii code.
Thus, the software now accepts keyboard input and displays it.
Note that the return key is mapped to “\r” (CR: carriage return),
and consequently, this code cannot input new line.