Segmentation

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.
pacman
Posts: 17
Joined: Sun Jul 08, 2007 10:23 am

Post by pacman »

What does GCC do with FS and GS?

And is there no way at all of accessing data off another segment in C in pmode?
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post by JAAman »

pacman wrote:What does GCC do with FS and GS?
probably depends on which version, but as i understand, GCC avoids using FS and GS, as some OSs use them for accessing process structures (and one of the fast syscalls (dont remember which one) requires it for something)
And is there no way at all of accessing data off another segment in C in pmode?
there isnt supposed to be... the compiler is supposed to hide all implementation specific details (such as how the CPU handles memory) C itself doesnt even dictate how large pointers are (on some systems for example, a pointer could be 18bits or 84 bits or any other number and any properly conforming c code would compiler without issue)

on x86/RMode, a pointer is 16:16 or 32bits
on x86/PMode, a pointer is 16:32 or 48 bits, however, because of the way the x86 platform handles segmentation, the segment selector isnt normally used (its implied -- you cant even choose to specify it within most instruction encodes), therefore, using it greatly complicates (and bloats) the generated code, and compiler, therefore, since most PMode OSs provide the application with a flat space, most compilers simply ignores segmentation, and assumes DS==SS==ES

this isnt always the case: most RMode C compilers do use segmentation, but in PMode 'segmentation' use is optional, and none of the 'mature' OSes actually use it, so the compiler 'cheats' and ignores it (if it didnt, it would also likely require rewriting parts of the compiler, and certainly parts of the optimizer between OSes)
Post Reply