什么是“FS"/“GS"?注册的目的? [英] What is the "FS"/"GS" register intended for?

查看:37
本文介绍了什么是“FS"/“GS"?注册的目的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我知道以下寄存器及其用途应该是什么:

So I know what the following registers and their uses are supposed to be:

  • CS = 代码段(用于 IP)

  • CS = Code Segment (used for IP)

DS = 数据段(用于 MOV)

DS = Data Segment (used for MOV)

ES = 目标段(用于 MOVS 等)

ES = Destination Segment (used for MOVS, etc.)

SS = 堆栈段(用于 SP)

SS = Stack Segment (used for SP)

但是以下寄存器的用途是什么?

But what are the following registers intended to be used for?

  • FS = "文件段"?

  • FS = "File Segment"?

GS = ???

注意:我不是询问任何特定的操作系统——我询问的是它们打算被 CPU 用来做什么,如果有的话.

Note: I'm not asking about any particular operating system -- I'm asking about what they were intended to be used for by the CPU, if anything.

推荐答案

有它们的用途,以及它们被 Windows 和 Linux 用于什么.

There is what they were intended for, and what they are used for by Windows and Linux.

段寄存器背后的初衷是允许程序访问许多不同的(大)内存段,这些段是独立的并且是持久虚拟存储的一部分.这个想法来自 1966 Multics 操作系统,它将文件视为简单的可寻址内存段.没有BS打开文件,写入记录,关闭文件",只是将此值存储到那个虚拟数据段中"带有脏页刷新.

The original intention behind the segment registers was to allow a program to access many different (large) segments of memory that were intended to be independent and part of a persistent virtual store. The idea was taken from the 1966 Multics operating system, that treated files as simply addressable memory segments. No BS "Open file, write record, close file", just "Store this value into that virtual data segment" with dirty page flushing.

我们当前的 2010 操作系统是一个巨大的倒退,这就是为什么它们被称为Eunuchs".您只能寻址您的进程空间的单个段,从而提供所谓的扁平(恕我直言)地址空间".x86-32机器上的段寄存器仍然可以用于真正的段寄存器,但没有人打扰(前英特尔总裁安迪格罗夫上个世纪有一个相当有名的公众场合,当他发现所有英特尔工程师花费精力和精力后他的钱来实现这个功能,没有人会使用它.去吧,安迪!)

Our current 2010 operating systems are a giant step backwards, which is why they are called "Eunuchs". You can only address your process space's single segment, giving a so-called "flat (IMHO dull) address space". The segment registers on the x86-32 machine can still be used for real segment registers, but nobody has bothered (Andy Grove, former Intel president, had a rather famous public fit last century when he figured out after all those Intel engineers spent energy and his money to implement this feature, that nobody was going to use it. Go, Andy!)

AMD 在转向 64 位时决定他们不在乎是否取消 Multics 作为一种选择(这是慈善解释;无情的一个是他们对 Multics 一无所知),因此禁用了 64 位段寄存器的一般功能模式.线程仍然需要访问线程本地存储,并且每个线程都需要一个指针......在可立即访问的线程状态中的某处(例如,在寄存器中)......指向线程本地存储.由于 Windows 和 Linux 在 32 位版本中都为此目的使用了 FS 和 GS(感谢 Nick 的澄清),因此 AMD 决定让 64 位段寄存器(GS 和 FS)基本上仅用于此目的(我认为您可以让它们指向你的进程空间中的任何地方;我不知道应用程序代码是否可以加载它们).英特尔担心 64 位市场份额不会被 AMD 抢走,而安迪退休后,决定照搬 AMD 的计划.

AMD in going to 64 bits decided they didn't care if they eliminated Multics as a choice (that's the charitable interpretation; the uncharitable one is they were clueless about Multics) and so disabled the general capability of segment registers in 64 bit mode. There was still a need for threads to access thread local store, and each thread needed a a pointer ... somewhere in the immediately accessible thread state (e.g, in the registers) ... to thread local store. Since Windows and Linux both used FS and GS (thanks Nick for the clarification) for this purpose in the 32 bit version, AMD decided to let the 64 bit segment registers (GS and FS) be used essentially only for this purpose (I think you can make them point anywhere in your process space; I don't know if the application code can load them or not). Intel in their panic to not lose market share to AMD on 64 bits, and Andy being retired, decided to just copy AMD's scheme.

如果让每个线程的内存映射有一个绝对虚拟地址(例如 0-FFF),这是它的线程本地存储(不需要 [segment] 寄存器指针!);早在 1970 年代,我就在 8 位操作系统中完成了这项工作,它非常方便,就像有一大堆寄存器可以工作一样.

It would have been architecturally prettier IMHO to make each thread's memory map have an absolute virtual address (e.g, 0-FFF say) that was its thread local storage (no [segment] register pointer needed!); I did this in an 8 bit OS back in the 1970s and it was extremely handy, like having another big stack of registers to work in.

所以,段寄存器现在有点像你的附录.他们服务于一个残余的目的.致我们的集体损失.

So, the segment registers are now kind of like your appendix. They serve a vestigial purpose. To our collective loss.

不了解历史的人注定不会重蹈覆辙;他们注定会做一些更愚蠢的事情.

Those that don't know history aren't doomed to repeat it; they're doomed to doing something dumber.

这篇关于什么是“FS"/“GS"?注册的目的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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