VortixDev
VortixDev

Reputation: 1013

What is the purpose of the AVL bit in a segment descriptor?

What is the AVL bit in the GDT used for? Wikipedia doesn't provide any information that I can find other than "For software use, not used by hardware".

Upvotes: 2

Views: 839

Answers (1)

Peter Cordes
Peter Cordes

Reputation: 365157

Hardware ignores the bit, so it's up to software how to use it.

I doubt that current OSes use those bits for anything; all the mainstream modern x86 OSes use a flat memory model with only a few fixed GDT entries that they don't modify. (I'm ignoring Linux's modify_ldt system call because it's not used anymore for thread-local storage; modern Linux has better mechanisms to get the FS or GS base set correctly. And anyway, I don't think normal use-cases for it used that 1 AVL bit for anything.)


what it was intended for when designed

Intel also reserved some bits in page-table entries for use by the OS (i.e that the HW is guaranteed to ignore, as opposed to the reserved bits which can be used by future HW).

The 32-bit GDT format and paging were both new in 386. (286 has a different GDT format and no paging).

It's generally good practice if there are multiple unused bits in a structure written by software but read by hardware to leave some room for software to do whatever bookkeeping they want in-place within each entry, as well as to reserve some bits for future use.

IDK if Intel had anything specific in mind, or what if any interesting things you could do with the bit.

https://wiki.osdev.org/Descriptors#Code.2FData_Segment_Descriptors doesn't suggest anything, just saying "your OS can use this as you choose".

Possibly you could use it to keep track of whether an entry was in-use or not, if a 1-bit ref counter was sufficient. Or maybe whether it overlapped any other segments. Or maybe a flag to indicate whether or not some other checks and copying had to happen if modifying the base?

Maybe for a code segment, you could use it to record whether the code was position-independent. And if so, you could memmove the code somewhere else and change the segment base and have it still work without fixups, if you were defragmenting physical memory to make room for a large contiguous segment. (But as long as you don't change the offset of anything relative to the segment base, that's a weaker requirement than what PIC normally means in a flat memory map. The same code is at the same CS:EIP, and programs don't normally find out or use linear addresses, only offsets.)

Upvotes: 3

Related Questions