Re: Emulating BIOS for VBE
Posted: Mon Dec 30, 2013 7:00 am
Hi,
If the device does have a ROM, then you map that option ROM anywhere you like (typically somewhere in the "PCI hole") and search for the "ROM image" you want. Then (if the "ROM image" you want exists) you need to:
Please note that you may be lazy and skip some or all of the steps above (e.g. merely hope that the firmware left various things in various states). This will significantly increase the risk of it not working (especially for future UEFI systems).
Also note that the amount of work involved to make it "hopefully reliable maybe (if hardware supports it at all)" is mostly wasted effort. It doesn't get you any closer to having "video mode switching only" native video drivers (which are a necessary first step towards "full function" native video drivers, which should be the long term goal).
Cheers,
Brendan
For systems that have video built into the motherboard or CPU (lots of them), it's relatively normal for the PCI device itself to have no ROM at all. In this case the code that would've been in the video device's ROM is normally in the system's flash memory somewhere instead (possibly anywhere, and possibly compressed somehow).rdos wrote:No. When I read PCI register 0x30, it always returns 0. This is regardless of what I write to it, like 0xFFFFF000 or 0xFFFFF001 to detect depth. On the machine that does support register 0x30, it returns 0xFFFE0000.Owen wrote:For those machines which no option ROM in PCI space (but instead one at 0xC0000), do they have PCI expansion headers? If so, that would seem like a good cross check (you might also want to scan the entire option ROM space).
No.rdos wrote:Given this, I think the algorithm will be to first search for option ROMs, and if those are found, map them to physical address 0xC0000, allocate space for the RAM copy, and copy contents of the BIOS ROM version. Then map this RAM copy to 0xC0000 linear. If an option ROM is not found, map physical address 0xC0000 to linear address 0xC0000. After that, check for a value AA55 signature, and if found, do the VBE initialization.
If the device does have a ROM, then you map that option ROM anywhere you like (typically somewhere in the "PCI hole") and search for the "ROM image" you want. Then (if the "ROM image" you want exists) you need to:
- Ensure the "fixed range MTTRs" (in all CPUs) have the area from 0x000A0000 configured as "uncached". For a pure UEFI system there's no guarantee that this area isn't normal RAM configured as "write-back" caching.
- Mess with the memory controller to configure the area at 0x000C0000 as "reads and writes go to RAM". Note that the PCI specification will tell you that the option ROM's code will expect to be able to write to itself (which is why you can't just map the ROM itself at 0x000C0000). For a "BIOS system" this area will probably be left as "reads go to RAM, writes go to PCI" by the firmware, which isn't what you need.
- Mess with the memory controller again to configure the area from 0x000A0000 to 0x00BFFFF as "reads and writes go to PCI". Be warned that in a lot of systems the firmware hides the "SMM RAM" underneath this area (so that when the CPU is in SMM mode reads and writes to this area go to RAM, and when the CPU is not in SMM mode reads and writes go to wherever the memory controller says). Accidentally messing up the firmware's ability to access its own SMM code would be very bad; so don't be too surprised if your ability to mess with the memory controller is hampered by "write once" chipset lock/s.
- Copy the "ROM image" to the RAM at 0x000C0000, so it is where it expects to be
- Make sure the "VGA enable" bit is set in the configuration space for all PCI bridges in the path from the host controller to the video device; and make sure the "VGA enable" bit is clear for any bridges that aren't on this path (otherwise the same IO port or memory access can get forwarded to multiple different video cards and cause large quantities of confusion).
- Reset the video device to its "power on" state. If the video device has already been configured by firmware during boot, then it may be in a "native mode" state (e.g. where memory mapped registers are enabled and "legacy VGA IO port registers" are disabled) and no longer compatible with its own VBE ROM.
- Call the "ROM image" entry point.
- After this, you should reconfigure the RAM at 0x000C0000 as "reads go to RAM and writes go to PCI". I'm not sure that this is strictly required for your case (where you hopefully don't need to worry about other code trashing the video ROM), but it's at least theoretically possible for the video ROM to contain code that does an "am I being called during ROM initialisation test" where the same code behaves differently depending on if the ROM can modify itself or not.
Please note that you may be lazy and skip some or all of the steps above (e.g. merely hope that the firmware left various things in various states). This will significantly increase the risk of it not working (especially for future UEFI systems).
Also note that the amount of work involved to make it "hopefully reliable maybe (if hardware supports it at all)" is mostly wasted effort. It doesn't get you any closer to having "video mode switching only" native video drivers (which are a necessary first step towards "full function" native video drivers, which should be the long term goal).
Cheers,
Brendan