[coreboot] About Paging, Realmode and what is going on

Peter Stuge peter at stuge.se
Tue Aug 1 16:49:27 CEST 2017


Philipp Stanner wrote:
> the more I want to contribute and learn about low-level-code the less I 
> understand, it seems.

The x86 is a true rabbit hole. :)


>  2. When CB switches to PM - who generates and administrates the Page
>     Tables and where?

Note that PM != paging. Neither coreboot nor proprietary BIOS
products used paging traditionally. Ron pushed for paging, there was
a bit of support. I don't know the current situation though.

Also note that PM != "flat real mode" or "32-bit real mode", it's not
really documented as a feature, so I don't know if it has an official
name.

What you do is prepare a GDT with most or all entries having base 0
size 4GB, then enable PM in CR0, ldgdt, set at least cs and ds
(usually more) to the 4GB GDT selectors, then disable PM in CR0 -
*and do not reload cs, ds and other selectors/segment registers*
once back in RM. This then allows 32-bit memory access in RM on 386 up.


>  4. Once CB is in PM it can't access physical addresses anymore? It
>     doesn't need to, too?

That's a policy decision made in the GDT and the page tables. If
base=0 and paging disabled and/or page tables are set the right way,
then virtual == physical.


>  5. PM means RAM-access is only possible through virtual addresses
>     which are translated by the MMU using the Page Tables.

If you stay in PM and enable paging, yes.


> If coreboot generates the Page Tables and the payload would start
> in PM as well (is this even possible? At least the Linux-Kernel has
> entry points for RM and PM) this would mean the payload needs to
> use the Page Tables generated by CB. That wouldn't be a problem as
> they're linked in the register CR3 anyways?

A few different bootloader binary interfaces exist on x86. There are
at least BIOS, UEFI, multiboot and coreboot. The general rule has
always been to not make very many assumptions, so expect every
bootloader and/or libpayload to set up their own flat real mode GDT.


> * Why does every modern CPU still start in RM?

Many industries run on DOS. Many system developers have created
in-house BIOS extensions. x86 will never fully lose its 16-bit legacy.


//Peter



More information about the coreboot mailing list