Another stack question

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Ozguxxx

Another stack question

Post 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?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Another stack question

Post 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)
Tim

Re:Another stack question

Post 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.
Post Reply