4

Reading the description of the SYSENTER instruction, I came across the following:

IA32_SYSENTER_CS Contains ring 0 code segment (CS)

I thought that 64 bit systems now use virtual memory address scheme (pagination), which basically no longer relies on the code segment (CS) register. Can somebody please explain what is exactly contained in the IA32_SYSENTER_CS register?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Rustam Issabekov
  • 3,279
  • 6
  • 24
  • 31

1 Answers1

5

There are two things:

First of all, the segment registers are still used in 64-bit long mode. As stated in Intel's architectural manuals (System Programming Guide; Section 3.2.4, "Segmentation in IA-32e Mode"):

In 64-bit mode, segmentation is generally (but not completely) disabled, creating a flat 64-bit linear-address space. The processor treats the segment base of CS, DS, ES, SS as zero, creating a linear address that is equal to the effective address. The FS and GS segments are exceptions. These segment registers (which hold the segment base) can be used as additional base registers in linear address calculations. They facilitate addressing local data and certain operating system data structures.

fs and gs provide a base address; the other segment registers are only used to look up access rights. So if cs contains the value 0x20, you are in ring 0 privilege mode; if it contains 0x33, you are in ring 3 mode.

The second thing is that sysenter was originally designed for 32-bit mode. The instruction is not even supported on all CPUs in 64-bit mode (in particular, AMD chips do not support it). For maximum compatibility, a kernel running in 64-bit long-mode would use syscall and sysret instructions.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Martin Rosenau
  • 17,897
  • 3
  • 19
  • 38
  • "So if cs contains the value 0x20, you are in ring 0 privilege mode; if it contains 0x33, you are in ring 3 mode", where did you get those values? – Trey Nov 22 '17 at 01:24
  • 1
    I don't see how this answers either of the questions about IA32_SYSENTER_CS or about SYSENTER on 64-bit. – Evan Carroll Oct 03 '18 at 00:20