This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Allocate a variable in a known physical location
- From: isuru herath <isuru81 at yahoo dot com>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 31 Jan 2011 13:01:44 -0800 (PST)
- Subject: Re: Allocate a variable in a known physical location
Hi Ian,
Thanks a lot for your quick response and I am sorry for not explaining the
problem correctly.
I have a separate piece of memory for which I have given physical address
range 0x10001000 to 0x10101000. I want to allocate variables in this
address range. To achieve this I create a structure with variables I need
to allocate there. For example if I need to allocate i and j in the above
address range, I define a structure like following.
struct my
{
int i;
int j;
};
and then allocate memory for the structure using mmap like below.(bear with
me if syntax are wrong).
struct my *p = mmap(........);
when ever I need to access i, j in my code I access them via pointer p like
following.
p->i or p->j
All what I need is to allocate i and j in the above address range. Due to
lack of my knowledge in compiler and gcc this is how I did it. The
drawback of this is that to access i, it has to access p first. This
introduces an unnecessary access to my statistics. Therefore if I could
allocate i and j without using the above method I thought my problem will
be solved.
As you mentioned in your reply can I use section attribute to achieve this or do you have any other suggestion.
Any help/advice is greatly appreciated.
regards,
Isuru
--- On Mon, 1/31/11, Ian Lance Taylor <iant@google.com> wrote:
> From: Ian Lance Taylor <iant@google.com>
> Subject: Re: Allocate a variable in a known physical location
> To: "isuru herath" <isuru81@yahoo.com>
> Cc: gcc-help@gcc.gnu.org
> Date: Monday, January 31, 2011, 11:21 AM
> isuru herath <isuru81@yahoo.com>
> writes:
>
> > I need to allocate a variable in a known physical
> location, let's say I need
> > to allocate void *p in location 0x10001000.? I
> was using mmap to to do this,
> > but in that manner I can only allocate p[0],
> p[1]...p[n] in that physical
> > address range. Therefore when I access p[i], accesses
> to p results in
> > outside {0x10001000,? 0x10001000+offset} and p[i]
> results as an access in
> > the range I am interested in.
>
> I don't understand the last sentence there.
>
> > I was wondering is there a was for me to force
> > to allocate variable p in that address range or I am
> looking for something
> > totally unrealistic. Because of the nature of my
> research I can use any
> > optimization(-O2, O3).
>
> If you don't want to use mmap, the simplest way to put a
> variable at a
> specific location is to put it in a specific section using
> __attribute__
> ((section ("..."))) and then put that section at a specific
> address
> using a linker script.
>
> Ian
>