Commit d6243e0
authored
Boot UEFI Windows (UEFI Support + ACPI + 8GB RAM) (#708)
# PR: Add UEFI/OVMF boot support (fw_cfg + dynamic ACPI) and robust >3GB
RAM handling
## Summary
This change set enables booting modern UEFI guests (including Windows
Server 2025) under Bochs using OVMF by adding a QEMU-compatible `fw_cfg`
device and generating the ACPI tables firmware expects. In the same
work, it hardens/clarifies >3GB RAM behavior by introducing a PCI/MMIO
“hole” at 3–4GB with RAM remapped above 4GB, and centralizes the address
translation so memory accesses remain correct and safe.
A key constraint throughout is **BIOS-safe defaults**: all UEFI/OVMF
behavior is **opt-in** and gated by the `fw_cfg: enabled=1`
configuration.
## Motivation
- The target `servercore2025.vhd` (Windows Server Core 2025, UEFI
install) boots under QEMU/Hyper-V but historically did not boot under
Bochs.
- OVMF expects:
- QEMU-like `fw_cfg` to provide E820 and ACPI tables
- a modern ACPI environment (RSDP/XSDT/FADT/FACS/DSDT/MADT/HPET)
- sane PCI/MMIO layout (including a reserved MMIO window and correct
memory reporting)
## User-facing changes
### New `fw_cfg` option (UEFI/OVMF support)
- New bochsrc stanza:
- `fw_cfg: enabled=1`
- When enabled, Bochs exposes a QEMU-compatible `fw_cfg` interface at
I/O ports **0x510–0x51B** (including the DMA interface used by OVMF).
- The device provides to firmware:
- E820 memory map (including a reserved 3–4GB PCI/MMIO hole)
- ACPI tables (RSDP, XSDT, FADT, FACS, DSDT, MADT, HPET)
- RAM size and CPU count
### OVMF usage
Minimal UEFI boot configuration example:
```
romimage: file=OVMF.fd, address=0
fw_cfg: enabled=1
pci: enabled=1, chipset=i440fx, slot1=pcivga
```
### Increased max host memory setting
- The configuration option for “host allocated memory size” now allows
up to **8192 MB** (previously **2048 MB**) to support larger-guest
testing.
## Core implementation details
### fw_cfg device (QEMU-compatible)
- Adds a new core plugin implementing the `fw_cfg` selector/data/DMA
protocol.
- Exposes firmware-facing blobs (E820 + ACPI tables) via the fw_cfg file
interface.
### Dynamic ACPI table generation
- Introduces runtime-generated ACPI table blobs aligned with the default
i440fx/PIIX device model.
- Uses an embedded AML blob for DSDT.
### DSDT AML generation and reproducibility
- `bochs/iodev/acpi_dsdt_aml.h` is a **generated** artifact embedding
the compiled AML for the Bochs DSDT.
- Regeneration script:
- `bochs/tools/gen_acpi_dsdt_aml.py`
- Requires ACPICA `iasl` (available on PATH or passed via `--iasl`).
- Temporary outputs from regeneration are ignored via `.gitignore` (e.g.
`bochs/tools/_acpi_dsdt_aml.*`).
### >3GB RAM / PCI hole handling
- Adds a well-defined PCI/MMIO hole at **3–4GB**.
- RAM that would otherwise occupy 3–4GB is remapped above 4GB.
- Introduces/uses a shared helper (`bx_translate_gpa_to_linear()`) so
physical memory operations remain correct across the remap.
### Safety: direct host-pointer access in the PCI/MMIO hole
- The PCI/MMIO hole is treated as “no direct host pointer” by default to
avoid incorrect aliasing into RAM backing store.
- A narrow exception is allowed for ROM-backed fetches in the BIOS/UEFI
ROM window (required for reset-vector fetch correctness) while keeping
MMIO safety guarantees.
### Reset semantics (BIOS-safe by default)
- `fw_cfg` is loaded only when `fw_cfg: enabled=1`.
- On **hardware reset** and only when UEFI is enabled, memory
resets/reloads ROM images because OVMF may modify ROM contents during
execution.
- Device reset behavior was audited where startup invokes `reset()` to
ensure BIOS behavior is not accidentally altered.
## Other correctness/compatibility improvements (touched by this PR)
- CPU reset correctness: clears additional state, invokes mode-change
handlers, and flushes TLB at reset.
- MSR compatibility: adds `MSR_PLATFORM_ID` and returns 0 on read.
- VGA/UEFI graphics: adds QEMU-compatible VBE BAR2 mapping used by OVMF
QemuVideoDxe.
- Several devices gained/reset-aligned initialization to keep init/reset
consistent:
- keyboard controller, serial, ATA controller state, PIC/PIT, DMA I/O
width robustness.
## Documentation updates
- User documentation updated with:
- how to configure OVMF + `fw_cfg`
- how the embedded DSDT AML is produced and how to regenerate it
- note that OVMF graphics works best with `pci: ... slot1=pcivga`
- `CHANGES` updated with new features and the increased max host memory
setting.
## Testing
- BIOS smoke test: confirmed legacy BIOS boot still works with default
settings.
- UEFI smoke test: confirmed OVMF boots and provides visible output with
`fw_cfg` enabled and PCI VGA (`pcivga`).
- Target OS coverage: tested with `servercore2025.vhd` under OVMF to
exercise the UEFI boot path (fw_cfg + ACPI + PCI-hole memory map).
## Files changed (by area)
### New files
- `bochs/iodev/fw_cfg.cc`, `bochs/iodev/fw_cfg.h` (fw_cfg device)
- `bochs/iodev/acpi_tables.cc`, `bochs/iodev/acpi_tables.h` (dynamic
ACPI)
- `bochs/iodev/acpi_dsdt_aml.h` (generated AML blob)
- `bochs/tools/gen_acpi_dsdt_aml.py` (DSDT regen helper)
### Updated files
- Configuration and docs:
- `.gitattributes`, `.gitignore`
- `bochs/CHANGES`
- `bochs/config.cc`
- `bochs/doc/docbook/user/user.dbk`
- Core plumbing:
- `bochs/plugin.h`, `bochs/plugin.cc`, `bochs/param_names.h`
- `bochs/cpu/init.cc`, `bochs/cpu/msr.cc`, `bochs/cpu/msr.h`
- `bochs/memory/memory-bochs.h`, `bochs/memory/memory.cc`,
`bochs/memory/memory_stub.cc`, `bochs/memory/misc_mem.cc`
- Devices:
- `bochs/iodev/devices.cc`, `bochs/iodev/acpi.cc`, `bochs/iodev/hpet.cc`
- `bochs/iodev/display/vga.cc`, `bochs/iodev/display/vga.h`
- `bochs/iodev/dma.cc`, `bochs/iodev/pic.cc`, `bochs/iodev/pit82c54.cc`
- `bochs/iodev/keyboard.cc`, `bochs/iodev/serial.cc`,
`bochs/iodev/serial.h`, `bochs/iodev/harddrv.cc`
## Notes / follow-ups
- This PR intentionally keeps UEFI support **opt-in** to avoid changing
the default BIOS behavior.
- The DSDT AML is committed as a generated artifact to avoid a
build-time dependency on ACPICA; the provided script documents how to
regenerate it deterministically.
- `.gitignore` shows a large diff primarily due to line-ending
normalization (LF) plus a small number of new ignore patterns for local
test artifacts and the DSDT regeneration temporary outputs.
## Sample UEFI BXRC:
```
# Minimal UEFI smoke config (fw_cfg enabled)
plugin_ctrl: unmapped=1, biosdev=1, speaker=0, serial=1, parallel=0, gameport=0, e1000=0, extfpuirq=1
config_interface: textconfig
display_library: win32
memory: host=4096, guest=4096
# OVMF firmware
romimage: file="e:/tmp/VSCODE_PROJ2/RELEASEX64_OVMF.fd", address=0x0, options=none
vgaromimage: file="e:/tmp/bochs_upstream/bochs/bios/VGABIOS-lgpl-latest.bin"
# UEFI boot requires fw_cfg
fw_cfg: enabled=1
boot: disk
floppy_bootsig_check: disabled=0
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata0-master: type=disk, path="e:/tmp/VSCODE_PROJ2/servercore2025.vhd", mode=vpc
ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15
ata1-master: type=none
ata1-slave: type=none
ata2: enabled=0
ata3: enabled=0
# UEFI GOP/video init expects VGA as a PCI device
pci: enabled=1, chipset=i440fx, slot1=pcivga
vga: extension=vbe, update_freq=60, realtime=1
cpu: count=1, ips=100000000, model=corei7_sandy_bridge_2600k, reset_on_triple_fault=0, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=1
print_timestamps: enabled=0
port_e9_hack: enabled=0
private_colormap: enabled=0
clock: sync=none, time0=local, rtc_sync=0
log: e:/tmp/VSCODE_PROJ2/bochsout_smoke_uefi.txt
logprefix: %t%e%d
debug: action=ignore
info: action=report
error: action=report
panic: action=report
# OVMF debug output
com1: enabled=1, mode=file, dev=e:/tmp/VSCODE_PROJ2/serial_smoke_uefi.log
keyboard: type=mf, serial_delay=250, paste_delay=100000, user_shortcut=ctrl-alt-del
mouse: type=ps2, enabled=0, toggle=ctrl+mbutton
```1 parent 190e6b8 commit d6243e0
File tree
29 files changed
+2789
-102
lines changed- bochs
- build/win32/vs2019-workspace
- vs2019-plugins
- vs2019
- doc/docbook/user
- iodev
- display
- memory
- tools
29 files changed
+2789
-102
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
50 | 54 | | |
51 | 55 | | |
52 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
39 | 46 | | |
40 | 47 | | |
41 | 48 | | |
42 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
43 | 64 | | |
44 | 65 | | |
45 | 66 | | |
| |||
3133 | 3154 | | |
3134 | 3155 | | |
3135 | 3156 | | |
3136 | | - | |
| 3157 | + | |
3137 | 3158 | | |
3138 | 3159 | | |
3139 | 3160 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
| 218 | + | |
218 | 219 | | |
| 220 | + | |
219 | 221 | | |
220 | 222 | | |
221 | 223 | | |
222 | 224 | | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
223 | 228 | | |
224 | 229 | | |
225 | 230 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
| 219 | + | |
219 | 220 | | |
220 | 221 | | |
221 | 222 | | |
222 | 223 | | |
223 | 224 | | |
224 | 225 | | |
225 | 226 | | |
| 227 | + | |
226 | 228 | | |
227 | 229 | | |
228 | 230 | | |
| |||
246 | 248 | | |
247 | 249 | | |
248 | 250 | | |
| 251 | + | |
| 252 | + | |
249 | 253 | | |
250 | 254 | | |
251 | 255 | | |
252 | 256 | | |
253 | 257 | | |
254 | 258 | | |
| 259 | + | |
255 | 260 | | |
256 | 261 | | |
257 | 262 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
726 | 726 | | |
727 | 727 | | |
728 | 728 | | |
729 | | - | |
| 729 | + | |
730 | 730 | | |
731 | 731 | | |
732 | 732 | | |
| |||
1627 | 1627 | | |
1628 | 1628 | | |
1629 | 1629 | | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
1630 | 1638 | | |
1631 | 1639 | | |
1632 | 1640 | | |
| |||
3188 | 3196 | | |
3189 | 3197 | | |
3190 | 3198 | | |
| 3199 | + | |
| 3200 | + | |
| 3201 | + | |
| 3202 | + | |
| 3203 | + | |
| 3204 | + | |
3191 | 3205 | | |
3192 | 3206 | | |
3193 | 3207 | | |
| |||
3583 | 3597 | | |
3584 | 3598 | | |
3585 | 3599 | | |
| 3600 | + | |
3586 | 3601 | | |
3587 | 3602 | | |
3588 | 3603 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3180 | 3180 | | |
3181 | 3181 | | |
3182 | 3182 | | |
3183 | | - | |
| 3183 | + | |
| 3184 | + | |
| 3185 | + | |
| 3186 | + | |
| 3187 | + | |
| 3188 | + | |
| 3189 | + | |
| 3190 | + | |
| 3191 | + | |
| 3192 | + | |
| 3193 | + | |
| 3194 | + | |
| 3195 | + | |
| 3196 | + | |
| 3197 | + | |
| 3198 | + | |
| 3199 | + | |
| 3200 | + | |
| 3201 | + | |
| 3202 | + | |
| 3203 | + | |
| 3204 | + | |
| 3205 | + | |
3184 | 3206 | | |
3185 | 3207 | | |
3186 | 3208 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
| 76 | + | |
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
169 | 190 | | |
170 | 191 | | |
171 | 192 | | |
| |||
179 | 200 | | |
180 | 201 | | |
181 | 202 | | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
186 | 222 | | |
187 | 223 | | |
188 | 224 | | |
| |||
203 | 239 | | |
204 | 240 | | |
205 | 241 | | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
206 | 258 | | |
207 | 259 | | |
208 | 260 | | |
| |||
0 commit comments