Page 1 of 1

Another stack question

Posted: Sun Aug 24, 2003 3:39 pm
by Ozguxxx
Hi,is gcc expecting ds and ss have same value? Even though they are mapped to same place. I mean do they have to have same selector values even though the memory they are mapped onto showing are the same?

Re:Another stack question

Posted: Mon Aug 25, 2003 2:57 am
by Pype.Clicker
GCC doesn't care about the selector values (actually, gcc-generated code will never touch segment selectors except for GS in the thread-local storage extension). All it does is assuming a valid offset for ds is also a valid offset for ss.

btw, do someone know whether the x86 assumptions that [bp+offset] is SS-related and [di+offset] is DS-related still apply on ia-32 with [ebp+offset] and [edi+offset] or do they all relate to ds? (doh, too busy to check the Holly Intel Manuals . Shame on my family to the 2**8 th generation :p)

Re:Another stack question

Posted: Mon Aug 25, 2003 4:33 pm
by Tim
Note that although gcc doesn't know about segments, it expects a flat memory model. That is, it expects that a byte accessed through DS is the same as accessed through SS. This lets you pass functions pointers to local variables and pointers to global variables in the same way. The function will always dereference the pointer through DS, so SS had better address the same memory as DS.