如何解释%gs:0x14? [英] How to interpret %gs:0x14?

查看:131
本文介绍了如何解释%gs:0x14?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对在x86汇编中使用冒号有些困惑.我知道在实模式下,%gs:0x14 将是%gs 的地址左移4位,并加上 0x14 .但是在保护模式下是一样的吗?例如,在保护模式下,

  movl%gs:0x14%eax 

以什么方式访问%gs:0x14 ?就像 0x14(%gs)还是在实模式下一样?

更新:为了使我的问题更清楚,假设%gs = 0x1234 在指令 movl%gs:0x14%eax 后%eax的值是什么.

更多信息:

仅发现此文档对于不同系统中gs和fs的功能很有用 http://www.akkadia.org/drepper/tls.pdf

并且此链接提供有关segment:offset地址的信息.

http://thestarman.pcministry.com/asm/debug/Segments.html

解决方案

首先,让我们处理这些术语.似乎您通常使用的是保护模式",而不是实模式.但是,至少在英特尔手册中,该术语仅适用于32位模式.对于64位模式,他们使用了一个较差的营销术语"IA-32e模式",与AMD的长模式"相比,这是可怕的,但是两者仍然掩盖了64位模式也受到保护的事实.

这一区别很重要,因为在32位和64位保护模式下,处理%gs有所不同.对于32位,它是另一个段寄存器.线程切换代码使用相同虚拟空间中当前线程的段基础来填充它,因此,与{CS,DS,ES,SS}不同,它在平面模式下的基础不为零.对于64位,它只是保留在处理器MSR中的偏移量,并且也由调度程序更改为当前线程TLS地址.(在Linux/* BSD/Windows/etc之间,细节可能有所不同.%fs和%gs中哪个角色起着什么作用.)但是,通常的结果是,当看到%gs:0x14之类的访问时,您应该意识到

  • 获得了GS基址(如上所述,使用32位的通用方法和针对64位环境的基于MSR的特殊处理)
  • 0x14已添加到该地址

这就是所有您需要知道的,除非您开发内核或其他深入系统的东西,例如葡萄酒.

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 http://www.akkadia.org/drepper/tls.pdf

And this link provide information about segment:offset address.

http://thestarman.pcministry.com/asm/debug/Segments.html

解决方案

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.

这篇关于如何解释%gs:0x14?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆