Page 1 of 1

what is GCC compiler option to get Segment Override in x86

Posted: Mon Feb 25, 2013 1:34 pm
by RajivKumarSrivastav
Hi,
I have memory layout (In Increasing memory addr) like :
Code Section (0-4k), Data Section(4k-8k), Stack Section(8k-12k), CustomData Section(12k-16k).

I have put some special arrays, structs in Custom Data Section.

As i know, Data Segment (#DS)Selector will be used for any Data related compiler code.
So Data Section(4k-8k) will have #DS by default for all operation.

But, I want to use Extra Segment(#ES) selector for CustomData access. I would define a new GDT entry for ES with different Base and Limit.

So my question is:
Does GCC has any x86 compiler flag, which can be used to tell compiler that use #ES for CustomData Section code access.?
Means, compiler flag which will generate code using #ES for CustomData Section.?

Thanks in advance !!

Re: what is GCC compiler option to get Segment Override in x

Posted: Mon Feb 25, 2013 1:53 pm
by Brendan
Hi,
RajivKumarSrivastav wrote:As i know, Data Segment (#DS)Selector will be used for any Data related compiler code.
Not really. Different instructions have different "default" segments, depending on a bunch of things. GCC doesn't care and just assumes that all segments are the same and ends up using the default segment for each instruction (whatever it happens to be); which means that it could end up using SS, DS or ES to access data in your Data Section (or your Stack Section, or your CustomData Section).
RajivKumarSrivastav wrote:But, I want to use Extra Segment(#ES) selector for CustomData access. I would define a new GDT entry for ES with different Base and Limit.
Too bad. GCC is designed for a "flat" address space where segments aren't really used (and paging is used to enforce section permissions if needed instead).

Note: There's a small chance that you might be able to use FS or GS (e.g. maybe with inline assembly getters/setters) to access data in a special section; which wouldn't interfere with code generated by GCC as neither FS nor GS is a default segment for anything. However there's a larger chance that it's a waste of time and you should just use "flat" anyway. ;)


Cheers,

Brendan

Re: what is GCC compiler option to get Segment Override in x

Posted: Wed Feb 27, 2013 11:06 pm
by RajivKumarSrivastav
Thanks Brendan.

Is it possible by any other method?

Re: what is GCC compiler option to get Segment Override in x

Posted: Thu Feb 28, 2013 1:13 am
by Combuster
Use a different compiler, like OpenWatcom