在UEFI系统上恢复PC BIOS
Get PC BIOS back on UEFI only system

原始链接: https://github.com/FlyGoat/csmwrap

CSMWrap 是一款工具,允许在现代基于 UEFI 的系统上通过模拟传统 BIOS 来启动旧版操作系统,例如 FreeDOS、Windows XP 和 Windows 7。它利用来自 SeaBIOS 项目的 CSM(兼容性支持模块)和 VESA VBIOS。 CSMWrap 的工作原理是解锁传统 BIOS 内存区域,加载 SeaBIOS 的 CSM 模块,配置内存映射,设置 VGA BIOS,从 EFI 内存映射构建 E820 内存映射,提供 ACPI 和 SMBIOS 表,然后将控制权转移到旧版启动过程。 要使用 CSMWrap,请在 UEFI 设置中禁用安全启动和 4G 以上解码,并使用 `csmwarp.efi` 作为引导加载程序。CSMWrap 依赖于 `EFI_LEGACY_REGION2_PROTOCOL` 进行内存访问,但如果此协议不可用,它可能会尝试使用 PAM 寄存器。 Windows XP/7 的视频模式设置存在已知问题,可能会导致闪烁或黑屏。将 GPU 驱动程序注入操作系统映像可能会解决此问题。

这个Hacker News帖子讨论了一个项目,该项目通过重新实现BIOS,使得在仅支持UEFI的系统上启动旧版操作系统成为可能。其主要动机是运行DOS、Windows XP/7等缺乏UEFI支持的旧操作系统和实用程序。讨论重点突出了现代硬件兼容性和旧版系统的磁盘布局所面临的挑战。人们对GitHub上泄露的Windows XP源代码以及微软似乎缺乏执法力度表示担忧,这可能是为了维持市场份额和收集威胁情报。讨论还探讨了DOSBox等DOS模拟器的替代方案,以及在需要直接访问硬件时在虚拟机中运行旧操作系统的局限性。还讨论了其他的磁盘分区方案(如全磁盘btrfs)。

原文

CSMWrap is a cool little hack that brings back the good old PC BIOS on those fancy-pants UEFI-only systems. It utilises the CSM (Compatibility Support Module) and VESA VBIOS from SeaBIOS project to emulate a legacy BIOS environment.

Right now, CSMWrap can:

  • Boot FreeDOS, Windows XP, and Windows 7 in QEMU (both q35 and piix4 machines)
  • Run on some real hardware too! (Your mileage may vary)

CSMWrap works by:

  • Unlocking the legacy BIOS memory region (0xC0000-0xFFFFF)
  • Loading the SeaBIOS CSM module into memory
  • Configuring memory mapping for legacy applications
  • Setting up VGA BIOS with information from EFI GOP
  • Building an E820 memory map based on EFI memory map
  • Providing essential compatibility tables (ACPI, SMBIOS)
  • Initializing the CSM module and legacy services
  • Transferring control to the legacy boot process

Simply use csmwarp.efi as your bootloader, you can place it in your EFI partition and boot from it. Remember to disable Secure Boot, and Above 4G Decoding in your BIOS/UEFI settings.

It is almost required to run CSMWrap with above 4G decoding disabled in your BIOS/UEFI. As UEFI firmwares are likely to place GPU's VRAM BAR above 4G, and legacy BIOS are 32bit which means it can only access the first 4G of memory.

Currently csmwrap relies on EFI_LEGACY_REGION2_PROTOCOL to enable writing to the legacy region. This is not available on all systems. For system that do not support this protocol, csmwrap will attempt to use PAM registers in chipset to perform decoding, which is not guaranteed to work.

Windows Video Modesetting Issues

Windows XP/7's video modesetting logic is a bit mysterious. It may try to set a incompatible mode using int10h, which will cause flickering or even black screen after transferring control to the legacy OS.

This is a known issue and may be fixed in the future.

Meanwhile you can try to inject the GPU driver to OS image to avoid using the VESA BIOS.

  • SeaBIOS for the CSM module and VESA VBIOS
  • Nyu-EFI for EFI C runtime, build system, and headers
  • EDK2 for code snippets
  • @CanonKong for test feedback and general knowledge
联系我们 contact @ memedata.com