what is GCC compiler option to get Segment Override in x86

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
RajivKumarSrivastav
Member
Member
Posts: 26
Joined: Wed Sep 28, 2011 6:46 am
Location: Bangalore - India

what is GCC compiler option to get Segment Override in x86

Post 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 !!
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

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

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
RajivKumarSrivastav
Member
Member
Posts: 26
Joined: Wed Sep 28, 2011 6:46 am
Location: Bangalore - India

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

Post by RajivKumarSrivastav »

Thanks Brendan.

Is it possible by any other method?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post by Combuster »

Use a different compiler, like OpenWatcom
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply