I read in "INTEL 80386 PROGRAMMER'S REFERENCE MANUAL" (p112, S 6.3.1.3) that
An internal processor register records the current privilege level (CPL).
I am curious as to what register it refers to. Does it even have a name? What's the size of the register? Does it have any other use?
The current privilege level (CPL) of the processor is stored in the lowest 2 bits of the code segment selector (CS). The highest privilege level is number zero. This level is commonly known as Kernel Mode for Linux and Ring 0 for Windows-based operating systems.
CR0. The CR0 register is 32 bits long on the 386 and higher processors. On x64 processors in long mode, it (and the other control registers) is 64 bits long. CR0 has various control flags that modify the basic operation of the processor. Register CR0 is the 32 Bit version of the old Machine Status Word (MSW) register.
x86 Switching to protected mode from real mode CPL (Current Privilege Level)
The segment registers stores the starting addresses of a segment. To get the exact location of data or instruction within a segment, an offset value (or displacement) is required.
The Current Privilege Level (CPL) can always be found in the lower 2 bits of the Code Segment (CS) register. Those 2 bits can be the value 0b00 (ring 0), 0b01 (ring 1), 0b10 (ring 2), 0b11 (ring 3).
It should be noted that the old documentations use of "An internal processor register records the current privilege level (CPL)" is a bit deceptive and has caused some head scratching for others as well. CS always contains the CPL in the lower 2 bits but obviously it isn't an internal register.
The microarchitecture may have a copy of the CPL internally as well, but it is always accessible programmatically by looking at CS.
Not directly related to your question, but may be useful to know. If you transitioned between different rings and the destination code segment selector had a descriptor that is a conforming segment, it's possible for the Descriptor Privilege Level (DPL) != CPL. This is because with a conforming segment you continue to run with the previous privilege level. With non-conforming segments DPL == CPL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With