문제

As I knew the AHCI expansion ROM uses IDP(Index/Data pair) to access the AHCI registers(global and Port registers).

The ahci spec v1.3 says:

The IDP mechanism allows host software to access all of the MMIO registers using indirect I/O addressing

Thus even ABAR is above 1MB, expansion ROM still can access MMIO in real mode via this way.

But we found within expansion below way is OK when accessing AHCI MMIO registers:

push 0000h
pop es         ; set es = 0
mov bx, F732h
shl ebx, 16
mov bx, 0000h  ; put ABAR to ebx register
mov eax, es:[ebx]  ; read AHCI CAP registers to eax(4byte)

If above is OK then it implies the memory model now is not real mode(I guess it's big-real mode,that is, access under 4G is ok)

Our question is if the memory model when BIOS transfers control to Expansion is big-real mode nowadays (anyway, not real-mode) ? If yes then we can always use the memory operation to access AHCI's MMIO... It is correct ?

  • The reason why IDP used before might be: at that time when control is passed to expansion is still real mode, right ? So the memory model is dependent on system BIOS, right ?
도움이 되었습니까?

해결책

Is the memory model when BIOS transfers control to the Expansion ROM in big real mode? Not always.

In general, the system will probably be in big real mode, but if you are developing a ROM that will run on an arbitrary BIOS, this is not a safe assumption! If the BIOS supports PMM (Post Memory Manager), then the system is supposed to be in big real mode, otherwise there is no assurance of this. As far as I know, even if the BIOS support PMM, only the initial option ROM execution is guaranteed to be in big real mode.

It would probably be safer to:

  • Only use legacy I/O access for the AHCI registers (this is also the easiest)
  • Check to see if the BIOS supports PMM first, then either use legacy I/O or MMIO (but only during BIOS option ROM init)
  • Go ahead and put the CPU in to big real mode and use MMIO to access those registers (for bonus points, you could put the system back to the state you found it in, but most BIOSs will clean up after you)

The reason why IDP used before might be: at that time when control is passed to expansion is still real mode, right ? Not exactly.

It's mostly likely because it is the safest and easiest option, since there is no assurance the system will be in big real mode (and would therefore be safe to use MMIO access above 1MB).

So the memory model is dependent on system BIOS, right ? No (with a caveat).

The system should be in real mode when the BIOS hands off control (to a boot loader or option ROM). Big real mode is basically an extension of this mode, but the BIOS will not put the system in other other mode (any protected mode, long mode, etc).


Links:

http://bioshacking.blogspot.com/2011/07/memory-management-in-legacy-bios.html
http://lists.ipxe.org/pipermail/ipxe-devel/2012-August/001736.html
http://wiki.osdev.org/Unreal_Mode
http://www.linkedin.com/groups/PCI-extension-memory-allocation-4330449.S.99498421

A short disclaimer: This really only applies to legacy BIOS or UEFI with legacy support. I apologize in advance if there are any errors!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top