3

Reviewing my bare-metal code which switches to long mode after loading by multiboot-compliant loader I realized that some CPUs don't support 1G-pages so I cannot simply use PML4 table + 1 PDP table entry to map 1:1 first 1G-page. Can I be sure that code which uses PML4 + PDP tables + 1 PD entry to map 1:1 first 2M page will work on EVERY AMD64-compliant CPU?

In other words, are 2-M pages supported by all AMD64 CPUs? Thanks.

ababo
  • 1,490
  • 1
  • 10
  • 24

2 Answers2

2

Yes.

Long mode requires (or rather, is an extension of) PAE so it can map 64 bit physical addresses, and PAE always supports the PS bit to short-circuit translation to generate a 2MiB page. (As you note, Intel CPUs don't support this short-circuiting to generate 1GiB pages.)

You are perhaps thinking of PSE, described in https://en.wikipedia.org/wiki/Page_Size_Extension, which as you can see dates back to the Pentium, although some mid-2000s embedded CPUs based on Pentium-era designs also lack PSE support. None of these CPUs support x86-64 extensions.

There's no simple citation of chapter and verse, but the whole of Chapter 4 in Volume 3A of Intel® 64 and IA-32 Architectures Software Developer’s Manual covers paging and all of the various flags in depth. AMD has a similar reference, but can be considered a superset of Intel here (e.g. with 1GiB page support).

A hypothetical perverse CPU could provide long mode but not PSE, but the lack of PSE would only affect the interpretation of the PS bit in 32 bit page tables, which merely means that one can't create a 4MiB page in 32 bit mode, but can create a 2MiB page in long mode.

pndc
  • 3,710
  • 2
  • 23
  • 34
1

Support for 2 MB pages is indicated by CPUID Fn0000_0001_EDX bit 3 (Page Size Extensions). It seems that AMD64 compliant CPU may not support this because this kind of check exists.

Actually found that 2 MB pages are automatically supported in long mode. PSE support only refers to 4 MB page support in 32-bit mode. From AMD64 Architecture Programmer’s Manual Volume 2:

Page-Size Extensions (PSE). Page-size extensions (CR4.PSE) are ignored in long mode. Long mode does not support the 4-Mbyte page size enabled by page-size extensions. Long mode does, however, support 4-Kbyte and 2-Mbyte page sizes.

Mika Lammi
  • 1,278
  • 9
  • 21
  • 1
    The PSE bit indicates support for 4MB pages in 32bit mode, it has nothing to do with 2MB pages in 64bit mode (which is always supported) – harold Dec 19 '14 at 12:28
  • 1
    @harold Are you sure? To my understanding PSE is for 4 MB pages in 32-bit mode and 2 MB pages in 64-bit mode. – Mika Lammi Dec 19 '14 at 12:31
  • 1
    I'm sure. I've looking through the manual now to find something to quote, but so far it's only there "by omission" (for ex. you have to check for 1GB page support, it says nothing about 2MB page support) edit: an other indication, you don't have to touch CR4.PSE to use 2MB pages. The best so far; "If CPUID.01H:EDX.PSE [bit 3] = 1, CR4.PSE may be set to 1, enabling support for 4-MByte pages with 32-bit paging (see Section 4.3)." – harold Dec 19 '14 at 12:38