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.
The source code is available at the public github repository.
Boot monitor provides an entry point to the operating system. In this checkpoint, the boot monitor waits user's interaction to choose the boot option. After the boot option is specified, the software tries to enter 32/64-bit mode unless the option is power off. In the 64-bit mode, we can use “C”!
The status register contains status flags of the keyboard controller; bit 0: Output buffer full, bit 1: Input buffer full, bit 2: System flag (cleared after a power-on reset), bit 3: Command/data (0: data byte, 1: command byte), bit 4: Inhibit switch (0: keyboard is inhibited, 1: keyboard is not inhibited), bit 5: Transmit time out (0: no transmit time out error, 1: transmit time out error), bit 6: Receive time out (0: no receive time out error, 1: receive time out error), and bit 7: Parity error (0: odd parity (no error), 1: even parity (error)).
The history of A20 is found at A20 - a pain from the past. As described above, the most classical way to enable/disable A20 is done through the output port of the 8042 (PS/2) keyboard controller. In SMSC Keyboard controller, output port is defined as follows; bit 0: System reset, bit 1: Gate A20, bit 2: Undefined, bit 3: Undefined, bit 4: Output buffer full, bit 5: Input buffer empty, bit 6: Keyboard clock (output), and bit 7: Keyboard data (output). A20 is enabled/disabled by setting/clearing the bit 1. The system reset (bit 0) must be set, otherwise the machine will be reset. As for the other bits of this port, it may not effect the system, but DFh and DDh are usually used as enable and disable commands, respectively.
In the procedure, first, the OUT instruction with the D1h command (Write Output Port) is written to the port 64h, the command register of the keyboard controller, and then DFh (all bits except input buffer empty are set) is written to the output port through 60h output port.
Basically, peripheral devices provide its I/O access through in/out instructions and/or memory mapped I/O. We have used in/out instructions to access PIC, PIT, and keyboard controller in the previous checkpoints. In this checkpoint, we use the memory mapped I/O instead of BIOS calls to display a message text on the video screen. In bootmon.s, we have setup the video mode to the 16 bit color text mode through the INT 10h BIOS call. In this mode, it displays 80x25 characters on the screen, and each character is represented in 16 bit value (8 bit attribute (foreground and background color) and 8 bit ASCII code) The physical address range from 0xb8000 to 0xb8f9f is mapped to the video screen, i.e., the top left and bottom right characters are mapped to 0xb8000 and 0xb8f9e, respectively.