Totally awesome to have AHCI working in Windows.
Also, thank you Max for answering most of my questions with your pdf link. It is my understanding that Vista and 7 both support UGA and text-mode (for English language). That 7 also supports and prefers GOP in addition to UGA/text, and that Windows 8 will require GOP exclusively for EFI booting.
This is all just for the pre-NT kernel environment as the EFI equivalent of VESA. I don't know about with the Intel graphics but my EFI nVidia chip already has native driver support built into Windows by default, so I don't think this has anything to do with driver injection.
My first guess was that the Apple EFI simply wasn't correctly performing the EFI equivalent of the BIOS exporting tables. Then I read the link you posted and finally figured it out. It says that to EFI boot without GOP (UGA/text) a CSM is REQUIRED! Not a full BIOS emulation CSM necessarily from what I can tell, but emulation of INTERRUPT 10H is required or there will be no video before NT kernel loads native drivers, a latter stage one is unlikely to reach without first dealing with the former.
Sorry for the long and late reply, I'm on a weekend on the seaside so I might not answer until Monday. This reply is highly technical. For the non-technical audience: the app is 50% done and you should expect it for testing by mid-september. For the ones that have touched PreOS programming, see below.
Actually it's Windows that's at fault not Apple. There are three parts of Windows that need to work:
1) PreOS Windows: bootmgfw.efi and winload.efi. Those require GOP, UGA or VGA (in this order) for localized versions or simple EFI text-output protocol for plain english (export LANG=C equivalent). They both mostly work. The text stuff is actually an emulated console over the graphics EFI. No fixes are required here since it just works.
2) GOP with precisely 1024x768 or 800x600 for the wavy flag logo. Here Windows kernel is absolutely idiotic since you should never make assumptions about the resolution. Apple offers only one GOP resolution, the LCD panel native resolution. On the other hand, we can live without the wavy flag if the rest works. A possible fix is the EFI Edid Override Protocol to force the GOP implementation to use 1024x768 by faking an LCD panel of that resolution.
This is easy to fix but not high on my priority list.
3) The windows GUI which requires drivers. This is a special chapter since this is the ultimate failure of EFI Windows. I understand (but haven't tested) that Windows.Next has this part solved.
The Windows GUI time drivers chapter (aka ultimate redmond failure):
a) In the installer, Windows will try to use any of the bundled drivers. That basically means for modern hardware (for which it has no bundled driver) only VGA. Since VGA is by design a BIOS-only protocol you can't have it in EFI unless you hack around it. Assuming VGA presence on a non-BIOS firmware (regardless of the architecture) is completely idiotic, yet it's what Microsoft expects. VGA implies int10h and VGA BIOS. VGA BIOS implies real mode (aka pre i386) execution of the Option ROM. You don't have Real Mode on a true 64bit firmware. Real mode can't even address over 4Gb.
b) Assuming that to work around that you do the install in unattended mode and bundle the video driver, it still won't work due to another assumption: the VGAE register (0x3E) on the parent pci-bridge. Even if you have the NVidia drivers, you won't see anything on the video card (remote desktop still works if you configured it) unless you get the video card in bus mastering, IO access (PCI Reg 0x04=7) and the parent PCI bridge with VGAE (PCI Reg 0x3E=8). If you go into device manager, the driver work correctly but there are no monitor instances connected to it. I've tried forcing a monitor, but no success. Windows should do those things for the ACTIVE video card (it has DevicePath protocol in EFI to determine it as well as ACPI). We can work around that by setting them in a pre bootloader app that chain loads the Windows boot loader.
c) If you do set those PCI registers (specific to your mac model), and afterwards load bootmgfw.efi it will work like a charm.
----
I wrote an app that does those things manually for my Mac, but I am missing a few things before it comes out. Since I can't expect the end user to use an unattended install with bundled drivers, I need to provide Windows with VGA.
I need to shadow the VGA ROM manually at 0xC0000 and set the correct int10h value (firmware_version/logicboard_model specific hardcoded in the app). On NVidia Chipset Macs it works as the memory address is R/W. On Intel MCH style chipsets (pre Core i7) I also need to unlock the ram address by setting a value of 0x30, 0x33, 0x33, 0x33, 0x33, 0x33 on 90h-96h on the PCI Root Bridge since the address range is RO. On PCH style chipsets (core i5/i7) since the memory controller is in the CPU I need to unlock that RAM range using the fixed range MTRR. I still have a bit of work in order to make that happen.
Furthermore, another part that I'm missing is the source of the VGA BIOS. On some macs the EFI firmware includes the option rom for both discrete and integrated, on others only for the discrete card. On some macs the EFI firmware shadows the option ROM and only a gBS->CopyMem(ShadowAddr, 0xC0000, RomSize) is required once I identify ShadowAddr and RomSize with the PciIo protocol. On other Macs it's not shadowed (for a presumably faster boot) so I need to use the Firmware Volume protocol to scan for RAW files in the EFI Firmware and select the correct one (0xAA 0x55 means it's a ROM, and there is a PCI Description Table in the rom that states for which vendor/device id it's supposed to work). One XServe models there is no Firmware version of the ROM so we need to read it from the disk. I currently only implemented the reading from the boot disk of a vbios.bin file with the ROM.
If anyone wants to test out using Windows in EFI, it's simple: boot using DUET from el-torrito to install it (Windows from USB stick method). Install the BootCamp drivers (while booting through DUET). After that you can boot using the EFI Shell to set the PCI regs (see the 'mm -PCI' command) and afterwards booting the bootmgfw.efi file. I can make a static build of the app that just sets the PCI registers specific to your mac and then loads the bootmgfw.efi file.
What Windows should have done is:
1) Support GOP or UGA for a frame buffer also after the wavy flag. You can't expect VGA in EFI as it's completely as it is being the first 3 letters in 'assumption'.
2) Not assume setting the PCI bus registers by the firmware or not requiring them at all. All the other OSs work without them. All PCI device drivers should set their own bus-mastering rules by themselves and windows should not care about VGAE when using a non-VGA driver.
Watch the thread as it's getting interesting. Technical folks that can get their hands dirty in EDK should give me a PM and we'll cary on over email. Now I'll get back to Jack, Lucky Strike, and naked blondes dancing around the fire. I've been a geek for too long.