0

I've been told that segmentation is required for paging, why is that? AFAIK most systems with UEFI will start in long mode which I assume would not require segmentation at all?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Having some descriptors (like CS) referring to valid GDT entries is necessary for the machine to work at all in long / protected mode even on x86-64. You're not really using segmentation, though, so it depends on your definition of "without segmentation". If you mean "with a flat memory model", yes, the ISA doesn't support anything else in 64-bit mode, except for FS and GS bases. – Peter Cordes Mar 26 '22 at 04:51

1 Answers1

4

In general it's impossible to disable segmentation on 80x86; even in long mode (where fs and gs still work, sort of).

Instead you "fake disable" segmentation by setting the base of segment registers to zero and the limit to max.; so that segmentation does nothing. Modern CPUs are specially optimized for this case (they don't do the addition in the "linear address = segment_base + offset" calculation if they know segment bases are zero anyway).

Because of this it's possible to say that segmentation is required (with or without paging); and that segmentation isn't required (can be "fake disabled") for paging.

Note that most operating systems "fake disable" segmentation and only use paging; except for fs and fs which are often (ab)used as a pointer to thread local or "CPU local" data (and aren't actually used for the properties of segments).

Brendan
  • 35,656
  • 2
  • 39
  • 66