Windows 7 UEFI Install Without CSM
It’s a well-known fact that Windows 7 works best in CSM mode, which, unfortunately, is not supported by the firmware of many modern motherboards and laptops.
Contrary to the popular belief, it’s possible to install Windows 7 x64 to the pure UEFI systems without CSM support. Read below to find out how.
A really good counter-example why CSM support is not really necessary for Windows 7 installation is bhyve virtual machine manager in FreeBSD which supports 64-bit editions of Windows 7 and Windows 2008 Server R2, despite the complete lack of CSM support.
Also it's possible to run Windows 7 x64 in the UEFI-based virtual machine of Oracle VirtualBox (which apparently has no CSM support), which was configured for Windows 8 x64 guest OS, by pre-integrating VirtualBox paravirtual VBoxVGA/VBoxSVGA drivers to the Windows 7 x64 installation image (install.wim).
2. History of our research and development
Virtual machine counter-examples listed above indicate that what is really important for Windows 7 is a VGA-compatible GPU with properly mapped I/O ports and INT 10H handler (the former depends mostly on the chipset and the latter is usually provided by firmware when CSM mode is enabled in the settings). By the way, Windows 7 and Windows 2008 Server R2 never directly run the INT 10H handler installed by BIOS/CSM, instead they contain an emulator in the VGA miniport driver (VIDEOPRT.SYS) which runs 16-bit BIOS code in a sandbox, without leaving 64-bit protected mode and without halting other CPU cores.
Starting from Windows 8, everything has changed: INT 10H handler is no longer required by Windows to boot, BIOS emulator and entire VGA miniport driver both are gone, instead Windows basic display driver relies upon UEFI Graphics Output Protocol aka GOP.
So, the main question is: will it be enough to provide a custom INT 10H handler (by implementing a specialized UEFI preloader) to boot Windows 7 successfully on the modern pure UEFI systems? This custom INT 10H handler can rely on UEFI GOP to provide some sort of "mini CSM" (not a real thing, but just enough for VIDEOPRT.SYS to boot Windows 7).
As our experiments demonstrated, this, unfortunately, is not enough. In addition to invoking VGA BIOS via INT 10H in VIDEOPRT.SYS, Windows 7 makes direct reads and writes to/from VGA I/O ports right from the OS kernel (NTOSKRNL.EXE). First of all, Windows 7 OS kernel has VgaIsPresent() function which may halt boot process indefinitely on the "glowing logo" phase if VGA-compatible GPU does not respond on the standard I/O ports (0x3C0-0x3DF). Also, Windows 7 OS kernel has several other functions, such as VidInitialize(), VgaInterpretCmdStream(), VidSolidColorFill(), SetPixel() etc, which perform direct I/O on VGA ports for drawing BSoD (blue screen of death).
Therefore, we continued development of our preloader for Windows 7 by introducing a patch for NTOSKRNL.EXE to replace all instances of direct I/O via VGA ports with updates of framebuffer provided by UEFI GOP (in similar manner to Windows 8+). This patch is activated every time Windows boots, so NTOSKRNL.EXE is updated on the fly, only in the RAM, and on-disk version of this file is not affected (it may undergo any Windows 7 updates, it may be contained inside BOOT.WIM etc).
3. Final result of our effors
Final result of our efforts: Windows 7 x64 with preloader boots fine on pure UEFI systems (without CSM and without properly mapped VGA I/O ports): we successfully tested it and confirmed to work on ASUS C8HM70-I, Dell Inspiron 3584, HP OMEN X 17-ap001ur, Atomic Pi, bhyve virtual machine with VGA emulation disabled, VirtualBox virtual machine configured in UEFI mode for Windows 8 x64 guest OS. Thus, it is no longer necessary to disable Vga and VgaSave services in registry. It's no longer necessary to set "novesa on" option via bcdedit. Safe Mode and Windows Recovery work as expected. Last but not least: Windows 7 BSoD works as expected! :)
The only drawback of this approach is that screen resolution is fixed at 1024x768 with black sidebars added as necessary to fill in for the native resolution of the LCD screen. But after installation of the native GPU drivers (from Intel, AMD or NVIDIA) everything goes back to normal. Black sidebars remain at boot time only, when animated OS logo is displayed by Windows 7 via standard VGA driver.
"Windows 7 x64 preloader to provide VGA emulation on the pure UEFI systems" has become a feature of our software product (FlashBoot Pro). In addition to patching the loader, FlashBoot Pro provides a set of prepackages drivers for USB 3.x, NVMe and AHCI RAID controllers, which can be integrated to Windows 7 Setup just by a few checkboxes ticked on (which greatly simplifies installation of Windows 7 to modern computers for beginners).