What is the FS / GS register intended for?

So, I know what the following registers should be and their use:

  • CS = Code Segment (used for IP)

  • DS = Data Segment (used for MOV)

  • ES = Target segment (used for MOVS, etc.)

  • SS = stack segment (used for SP)

But what are the following registers intended for use?

  • FS = "File Segment"?

  • GS =

Note. I do not ask about any specific operating system - I ask that they are intended to be used by the processor, if anything.

+79
assembly x86 cpu-registers
May 30 '12 at 4:57
source share
4 answers

What are they for and what are they used for by Windows and Linux.

The initial intention of the segment register was to allow the program to access many different (large) memory segments, which were supposed to be independent and part of a permanent virtual storage. The idea was taken from the 1966 Multics operating system , which processed files as simply addressable memory segments. There is no BS “Open file, write record, close file”, just “Save this value in this virtual data segment” with dirty page cleaning.

Our current 2010 operating systems are a giant step backwards, so they are called eunuchs. You can access only one segment of the technological space by providing the so-called "flat (IMHO dim) address space". Segment registers on the x86-32 machine can still be used for real segment registers, but no one was worried (Andy Grove, former president of Intel, had a fairly well-known social approach in the last century, when he realized that all these Intel engineers spent energy and his money to implement this function that no one is going to use it. Go Andy!)

AMD, having switched to 64 bits, decided that it does not matter to them whether they excluded Multics as a choice (that charitable interpretation, homely, they do not know about Multics) and therefore disabled the general capabilities of segment registers in 64-bit Mode. There is still a need for threads to access the local thread store, and each thread needs a pointer ... somewhere in the direct accessible state of the thread (for example, in registers) ... for local storage. Since Windows and Linux used FSand GS (thanks Nick for the clarification) for this purpose in the 32-bit version, AMD decided to use 64-bit segment registers (GS and FS), essentially only for this purpose (I think you can force point them anywhere in your process space; dunno if the application code can load them or not). Intel in their panic did not lose their 64-bit AMD market share, and Andy, who retired, decided to simply copy the AMD circuit.

It would be architecturally prettier IMHO, so that each thread memory card had an absolute virtual address (for example, 0-FFF say), which was its local stream store (register pointer [segment] is not required!); I did this on an 8-bit OS back in the 1970s, and it was very convenient, for example, to have another large register stack to work with.

So, segment registers are now similar to your application. They serve a rudimentary purpose. To our collective loss.

Those who do not know history are not doomed to repeat this; they are doomed to do something ridiculous.

+87
May 30 '12 at 5:15
source share

Registers FS and GS are register registers. They do not have the goals defined by the processor, but instead they are assigned the OS that launches them. In the 64-bit version of Windows, the GS register is used to indicate structures defined by the operating system. FS and GS are commonly used by OS kernels to access streaming memory. In windows, the GS register is used to control streaming memory. The linux kernel uses GS to access processor-specific memory.

+38
May 30 '12 at 5:06
source share

FS is used to indicate a flow information block (TIB) in Windows processes.

A typical example is ( SEH ), which stores a pointer to a callback function in FS:[0x00] .

GS is commonly used as a pointer to a local stream store (TLS). and one example that you may have seen before is protecting the stack of canaries (stackguard), in gcc you can see something like this:

 mov eax,gs:0x14 mov DWORD PTR [ebp-0xc],eax 
+4
Sep 25 '18 at 4:51
source share

According to Intel Guide, in 64-bit mode these registers are intended to be used as additional base registers in some linear address calculations. I pulled this out of section 3.7.4.1 (page 86 in a 4-volume set). Typically, when the CPU is in this mode, the linear address matches the effective address, since segmentation is often not used in this mode.

Thus, in this flat address space, FS & GS play a role not only in local data, but also in certain data structures of the operating system (p. 2793, section 3.2.4), so these registers were intended for use by the operating system, however identify these specific developers.

There are a few interesting tricks when using overrides in 32-bit and 64-bit modes, but this requires the use of privileged software.

From the point of view of “initial intentions,” it is difficult to say, other than just additional registers. When the processor is in real address mode, it looks like the processor is running at a high speed of 8086, and the program should explicitly access these registers. For the sake of true 8086 emulation, you would run the processor in virtual-8086 mode, and these registers would not be used.

0
Apr 26 '19 at 2:04
source share



All Articles