I am a little confused with the use of colon in x86 assembly. I know that in real mode %gs:0x14 will be the address of %gs shift 4 bits left and adds with 0x14. But it is the same in protected mode? For example in protected mode,

movl %gs:0x14 %eax 

In what way %gs:0x14 is accessed? It is like 0x14(%gs) or same as in real mode?

Update: to make my question clearer, assume %gs = 0x1234 what is the value of %eax after instruction movl %gs:0x14 %eax.

Further information:

Just found this document useful for the function of gs and fs in different system

And this link provide information about segment:offset address.

1

2 Answers

First, let's deal with the terms. Seems you're using "protected mode" in general, as opposed to real mode. But, at least in Intel manuals, this term is applicable only for 32 bits mode. For 64 bits mode they use a poorly marketing term "IA-32e mode", which is horrible compared to "long mode" by AMD, but both are still hiding the fact that 64-bit mode is also protected one.

This difference is important because dealing with %gs is different for 32- and 64-bit protected mode. For 32 bits it's yet another segment register. A thread switching code fills it with a segment base for the current thread in the same virtual space, so, unlike {CS,DS,ES,SS} it's base isn't zero in a flat mode. For 64 bits, it's just a offset kept in a processor MSR and also changed by scheduler to the current thread TLS address. (Details can differ between Linux/*BSD/Windows/etc. which of %fs and %gs is used for what role.) But, as a common result, when see an access like %gs:0x14 you should realize that

  • GS base address is got (using, as explained above, a generic method for 32 bits and special MSR-based handling for 64 bits nvironment)
  • 0x14 is added to this address

and that's all you need to know unless you develop kernel or another deeply system thing as e.g. Wine.

2

You need to carefully read the application binary interface specification for your architecture (probably x86-64), i.e. X86-64 ABI.

You'll find out that %gs is related to thread local storage. See this answer.

So your machine instruction is probably loading the word at offset 0x14 of the current TLS.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.