I use FS for setting up exception handlers, anybody know if GS also is used in some equally specific way by Windows, or is it just an alround extra segment register?

I wonder because I never see somebody using GS as register in any win32 source code, I use it as a spare register in tight spots for holding 16bit numbers, is it bad to do so?
Posted on 2002-09-16 16:28:40 by david
David

In early versions of W95 you could change the "unused" segment registers - ES, DS, GS, but in later versions and W98 onwards Windows has outlawed this, by causing an exception.

GS starts off at zero. If you try to change it to anything other than zero you get an exception. This indicates to me that the exception is signalled by the operating system rather than the processor (something must be testing for a change in value).
Posted on 2002-09-17 02:33:27 by jorgon
Thanks.
Hehe, you're right, I only got away with it because I only used the value zero in it as you said.
Now I see why nobody use it.
:stupid:

Then only use I can think of is when you would like to push a WORD sized 0.
But how often is that, like never.
Posted on 2002-09-17 04:55:45 by david
In protected mode, putting a (valid) nonzero value in a segment register causes the processor to pull a descriptor out of a table. For more information, look in the Intel docs.
Posted on 2002-09-17 23:11:04 by tenkey
Hmm, it seems like GS could be used as a simple and quick hack to see if you are running on Win95 or not, it would be easier than doing the API calls then parsing strings.

tenkey,
can't you just look in the docs for me, then post the info here? You know how busy (lazy) i am, and Intel has a lot of docs to go thru :grin:
Posted on 2002-09-18 00:21:25 by sluggy
IIRC, the top 13-bits of the segment register refers to a descriptor, the next bit has some meaning, and the lowest two bits refers to the requested privelage level for the selector. Placing ANY value into a segment register automatically causes the processor to search for that descriptor, check if the segment exists, and check if the privelage level is allowed. In fact IIRC, GS is an 'alias' of a larger structure in the processor which is all of 8-bytes, the size of a descriptor, and as soon as GS is loaded, the descriptor's data is pulled from memory and loaded into this structure (if the descriptor checks out okay). All segment registers have such an alias. In real mode, when a value is loaded into a segment register, the structure register's values are computed based on the loaded value to be compatible with older real mode processors.

So it is the processor which does the checking of any values loaded into any segment registers.
Posted on 2002-09-19 05:55:45 by AmkG