I'm really running out of patience for your blathering. You clearly have no idea what you're talking about, so please just can it. I can only hope that this will be my last post to correct your obvious misconceptions.
(FYI, I have discovered the hard way that you can't let that asm sourced program you posted run very long - it's a very tight loop that produces output far faster than Windows can display it; I had to hard power my system to kill it. This is arguably a Windows bug, but I figured I'd let people know if they want to try this stuff for themselves)
I have no idea where you get all your misconceptions but you definitely have a ton of them.... Today, USB doesn't go to port 0x60 in windows nor does it get "converted" to ps/2 protocol.
a.) My "old" program works on your "modern" computer, yes?
b.) http://wiki.osdev.org/PS2_Keyboard
- "The Keyboard Controller (KBC) is located on the mainboard. The name is misleading because the Controller does more than controlling the communication with the hardware on the keyboard. In the early days the controller was a single chip (8042). As of today it is part of the Advanced Integrated Peripheral."
- "USB Legacy Support... To remain compatible with old software, the mainboard emulates USB Keyboards and Mouses as PS/2 devices. This is called USB Legacy Support."
a) Only when built as a DOS application and running inside NTVDM.
Note that NTVDM does not exist on 64-bit versions of Windows. You'll get a "does not support this computer" error when trying to run it (yes, I tried it on 64-bit Windows 7 - screencap of the dialog attached since you won't believe anybody).
b) The keyboard controller is now part of what is commonly referred to as the "SuperIO" chip, usually living on the LPC bus (used to be the ISA bus, but those are gone, now) but sometimes integrated into the "southbridge".
USB legacy support is a BIOS function. Basically, when a "real" OS that talks directly to the USB HCI doesn't exist, the BIOS will emulate port 0x6n accesses and stuff USB HID keyboard data into it merged with PS/2 port keyboard data. Once a "real" OS (like Windows or Linux, but NOT DOS) loads, it takes over control of the USB HCI and handles input merging on its own since the OS will have its own APIs to grant userspace processes access to keyboard data. For applications running in NTVDM (DOS applications), this just happens to be the port 0x6n interface the BIOS originally provided (this is for compatibility). For native Windows applications, the interface is different.
Are you saying there is any chance "inportb(0x60)" might not work on some PC?
It doesn't work at all how you'd intend on my 64-bit Windows 7 system. The DOS version of the program can't be run at all due to the lack of NTVDM (and really, does an OS really need to support 20 year old DOS applications?), and the Win32 version crashes due to the attempt to use a privileged instruction (and bypassing this restriction doesn't do what you want, either: see below). Given that Windows 7 is current, and 64-bit is becoming popular (with good reason), I'd say yeah, there's a good chance "inportb(0x60)" won't work on some PCs.
Note that the Windows API doesn't include "inportb" and hasn't for years. I had to define it to use it. If your intent is to say that "inportb" will or won't compile, it won't on anything remotely modern.
Either way ("does it compile?" or "does it work?"), you're sunk. It doesn't work, at least not how you seem to be wanting it to.
The USB specification already determines the maximum rate that a USB keyboard controller can supply scan codes.
Nonsense. By the way, you are contradicting MonMotha, he said USB does not use keyboard controller at all.
No, he's not. He's referring to something else. He's referring to the controller chip on the USB keyboard (the source of the data, rather that the sink). At least, that's how I read it, and it makes sense in that context.
Simply put in order to find out the absolute maximum a keyboard controller can read its own inputs you will have to make your own and then the information will only apply to that device. I don't think any of the manufacturers will let you read the source code for their devices. I know I wouldn't.
We are not talking about keyboard encoder anymore. We are now talking only about the "keyboard controller", which is located on computer motherboard. Anyway, shell we trust this document then, or not:
ftp://ftp.compaq.com/pub/supportinformation/papers/hcir1_0a.pdf
Keyboard/Mouse Input
The Interrupt Transfer Descriptor for the USB keyboard and/or mouse is processed at the rate established by the Endpoint Descriptor’s location(s) in the interrupt list (a 1-ms rate is the recommended rate for emulation). The Transfer Descriptors are processed as normal by the Host Controller. When a successful transfer of data has occurred from the keyboard, the Transfer Descriptor is moved to the Done Queue by the Host Controller. At the beginning of the next frame when the interrupt associated with the transfer completion is to be signaled, an interrupt is generated. System software should ensure that the Interrupt Routing bit in HcControl is set to 1 so that these interrupts will result in an SMI. Upon receipt of the SMI, the emulation software removes the Transfer Descriptor from the Done Queue, clears the HC IRQ, and translates the keyboard/mouse data into a equivalent PS/2-compatible sequence for presentation to the application software.
For each byte of PS/2-compatible data that is to be presented to the applications software, the emulation code writes to the HceOutput register. The emulation code then sets the appropriate bits in the HceStatus register. If keyboard/mouse interrupts are enabled, setting the HceStatus register bits cause the generation of an IRQ1 for keyboard data and IRQ12 for mouse data. The emulation code then exits and waits for the next emulation interrupt. When the host CPU exits from SMM, it can service the pending IRQ1/IRQ12. This normally results in a read from I/O port 60h. When I/O port 60h is read, the Host Controller intercepts the access and returns the current contents of HceOutput. The Host Controller then also clears the OutputFull bit in HceStatus and de-asserts IRQ1/IRQ12. If the emulation software has multiple characters to send to the application software, it sets the CharacterPending bit in the HceControl register. This causes the Host Controller to generate an emulation interrupt on the next frame boundary after the application has read from port 60h.
--- END QUOTE
The section you're quoting simply describes how emulation software in the BIOS should operate. Most BIOSes do provide this emulation so that DOS can be used. Bootloaders (e.g. LILO, GRUB, the Windows boot menu, etc.) that need a user interface also commonly use the BIOS on PCs to do that I/O since it's one of the few standard methods available without needing lots of driver code. The BIOS needs this code to support USB keyboards in its configuration menus, anyway, so it's not a big deal to pass this support on.
Windows (and Linux, and any other "real" OS) kick the BIOS emulation to the curb (turn it off). They provide their own input APIs that don't involve applications directly accessing IO port 0x60, so this emulation is not needed and would conflict with direct access to the USB HCI (necessary for non-boot HID devices). They are aware of the multiple sources of keyboard data on modern PCs and don't need the data merged into the ancient interface DOS expects. These OSes *do* still talk to port 60, but only to retrieve actual PS/2 keyboard data. They *also* talk to the USB HCI directly to receive HID data (and other USB data). This HID data is then merged with data from other sources (PS/2 port, Bluetooth HID, onscreen keyboard, etc.) and presented to userspace applications in whatever manner the OS uses. Typically, this is a kernel syscall or a file stream (standard input).
So, to settle this (or at least attempt to, since I'm sure you won't believe me, anyway), I did some further testing:
For grins, I unblocked access to port 0x60 on my 32-bit Windows XP SP3 machine using the "userport" program I mentioned in a previous post to Derrick Renaud. All this program (which includes a kernel-mode driver) does is enable userspace processes to access the IO ports you specify. The system a laptop, and Linux says that the onboard keyboard is on the PS/2 port (this is typical). I ran the Win32 native application that bangs directly on port 0x60. It got data from the onboard PS/2 keyboard but neither of the USB keyboards I had attached. This is consistent with what I just said: Windows reads port 0x60 for PS/2 keyboard data but gets USB data from elsewhere (directly from the HCI) and merges it together itself for presentation to userspace applications via the Win32 API. Since reading port 0x60 bypasses the Win32 API, it will only get data actually present on port 0x60 which is PS/2 data.
The DOS version *DOES* get data from all sources because it's running inside NTVDM. NTVDM uses the conventional Windows APIs to get keyboard data before stuffing it into an emulated port 0x60 interface. Hence, any keyboard Windows knows about will be passed to a DOS application inside NTVDM via port 0x60. This ONLY happens because that DOS application is running inside an EMULATION LAYER to emulate DOS. That emulation layer is NOT present for native Win32 applications, and it's not necessary because native Win32 applications don't bang directly on the hardware.