Search code examples
x86x86-64pagingosdevwindows-kernel

Is it possible to implement paging without segmentation? x86


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?


Solution

  • 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).