Pedro Santos
Pedro Santos

Reputation: 51

Why is EFLAGS bit 1 always set?

I wonder why the undefined second bit of the EFLAGS register is set to 1 by default. All other undefined/reserved bits are set to 0. Does this have a special meaning?

Upvotes: 4

Views: 529

Answers (2)

user2467198
user2467198

Reputation:

Presumably this bit is being reserved for a use where the default/compatible setting would be seen as true.

As an example of where the value assigned to a reserved bit can matter, consider the No-eXecute bit in x86 page tables. Because this bit was defined as reserved with a value of zero, it was not possible to call this an eXecute permission bit (while retaining software compatibility). In addition, with how x86 uses its page table tree, the final permission is generated by the and of the permission settings for all the levels of the page table (except for NX); this makes the each permission bit at least as restrictive as the most restrictive section of virtual memory. However, with NX being 1 as the more restrictive permission, NX must be treated differently (using or instead of and).

Providing a consistent conceptual framework is basic good practice, making memory more reliable (fewer bugs are produced, certain types of bugs are made more obvious, and there is less need to check documentation) and learning easier. By providing a reserved as 1 bit, a value that reasonably defaults to true can have a consistent, straightforward name and representation.

Upvotes: 0

spraff
spraff

Reputation: 33425

It's "reserved", not "undefined". Presumably it reflects some internal state which is simply not exposed to normal applications.

Sometime undocumented behaviour really means "only internally documented".

Upvotes: 2

Related Questions