1

I know that due to the flat memory model these register have become obsolete and that this was used for addressing in real mode. However, when I look into a program with a debugger I still find the values:

GS: 002B
ES: 002B
CS: 0033
FS: 0053
DS: 002B
SS: 002B

and I wonder why is that, what do the values indicate? Are they still being used in protected mode? OS: Windows I'd like to know for both 64bit and 32bit.

Sawb
  • 67
  • 4
  • 3
    Those are selectors and yes, they are used in protected mode. They index into the GDT or LDT, and specify the privilege level in the low 3 bits. – Jester Aug 03 '20 at 17:05
  • 1
    In Windows 64 bit, FS (or GS?) is used to access the "per thread" variables, such as the seed value for rand(). – rcgldr Aug 03 '20 at 17:15
  • Are you asking about 32-bit (protected mode) or 64-bit (long mode)? – Nate Eldredge Aug 03 '20 at 17:20
  • @rcgldr: It's FS in 32-bit code, GS in 64-bit. From that and the data we can deduce that the above sample data came from a 32-bit app. – 500 - Internal Server Error Aug 03 '20 at 17:26
  • 1
    I've added a few dupes. There are a lot more relevant questions. Check out the [tag:memory-segmentation] for many more interesting questions on the subject. – fuz Aug 03 '20 at 17:29
  • 1
    Note that the segment selectors are still needed to have a usable CPU in long mode. You can't just set them to 0; you must point them at valid GDT or LDT entries of appropriate type. – fuz Aug 03 '20 at 17:31
  • 2
    @fuz: Actually, x86-64 Linux does use `0` (the null selector) for user-space DS/ES/FS/GS, only real selectors for CS and SS. – Peter Cordes Aug 03 '20 at 17:55
  • hi, wanted to add something: the values loaded into the segment registers are called "segment selectors", they're not actual segment addresses but numbers used to index into the GDT (not actual indexes). there is another question where they answer accurately: https://stackoverflow.com/questions/9113310/segment-selector-in-ia-32 – jumpindonuts Aug 13 '20 at 11:03

0 Answers0