I. Overview
Borrow a wiki (http://wiki.osdev.org/%228042%22_PS/2_Controller) diagram:
The yellow one is Ps/2 KBC (KeyBoard Controller). As can be seen here, KBC and keyboard (hereafter referred to as KBD) are two completely different things, KBC is a simple chip,kbd is a common external device that we often use.
You can also see that the PS/2 keyboard mouse is exchanging data with the PS/2 KBC. Only KBC finally report the data to the CPU, which will eventually feed back to the user (for example, displaying our keystrokes on the screen, etc.). Simply put, KBC is the "intermediary" that ps/2 the keyboard and mouse to communicate with the system.
Here insert a discussion, our notebook basically does not have PS/2 interface, that also need KBC ?
The answer is need. Because in the Legacy OS (such as Dos,legacy Win7 and so on) environment, even the USB keyboard mouse, their data is converted to PS/2 data, back to the KBC, and then notify the CPU. Specifically here is not detailed, we know why the present KBC is good ~ wait until which day completely eliminated Legacyos, or we only do uefi BIOS, probably can happily with KBC say goodbye.
second, from the KBC two modes of operation to understand low-speed equipment (=)
before introducing the mode of work, it is necessary to understand how KBC works.
First of all, KBC internal can refer to the following, there are probably so several registers: Input/output buffer,status register. Buffer is used to stage the data, the status of the main is to record the state of the buffer.
Know KBC structure, and then combined with the diagram in the overview, KBC Basic workflow is clear: PS/2 keyboard and mouse data sent to KBC, the existence of KBC buffer, and then transferred to the CPU by KBC.
From this workflow analysis, the keyboard and mouse data is generated by the user, once the production is sent to KBC, this part of the behavior is more determined by the firmware of the device. And when does KBC transfer the data to the CPU? Finally, we can talk about its two modes of work.
KBC's working mode is divided into polling and interrupts two kinds. In detail you can refer to the "recieving Bytes from device/s" section of the wiki (it may be more appropriate, as I understand it, to call the ready-to-send Bytes to System), which is mainly about what I understand. Polling more dependent on the system software (that is, bios) behavior, in the BIOS section through the timer, regular check KBC status register, once marked as output buffer full, it means that something to output, You can now read the data through the KBC data port. The interrupt mode of operation is that once the data port has data, the CPU is sent irq,cpu through the IRQ number to know from what device, this part is more hardware behavior.
As can be seen, polling mode is limited by KBC buffer space, interrupt mode is limited by the interrupt itself.
Iii. experience in practical applications (incomplete, to be supplemented)
First, if you need KBC to work in interrupt mode, you need to pay special attention to the configuration of the IRQ. Recently the new platform DOS keyboard is not available, the problem is the IRQ. To clarify this question, you need to add the diagram on the wiki first. It is late, another day to continue ~
8042 PS/2 Controller's work note