EmbeddedRelated.com
Forums

Force variable address / C / Crossworks

Started by Jakub Szumacher September 7, 2010
Hello.

I'm wondering if is possible to force variable address in definition.

For example: I've got 3 variables: var1, var2, var3. I want place 'var1' in 0x40000100 and others variables ('var2', 'var3') linker decides. How to do this (code example)?

regards
Jakub

An Engineer's Guide to the LPC2100 Series

Am 07.09.2008 15:19, schrieb Jakub Szumacher:
> Hello.
>
> I'm wondering if is possible to force variable address in definition.

What does CrossWorks manual tell about this ? I doubt it is not mentioned
there or in the FAQ.
--
42Bastian
+
| http://www.sciopta.com
| Fastest direct message passing kernel.
| IEC61508 certified.
+
I've read manual and asked uncle google and I did not find satisfy answer -
so I wrote.

So please response only if you know how to do this.

regards
Jakub

> Am 07.09.2008 15:19, schrieb Jakub Szumacher:
>> Hello.
>>
>> I'm wondering if is possible to force variable address in definition.
>
> What does CrossWorks manual tell about this ? I doubt it is not mentioned
> there or in the FAQ.
> --
> 42Bastian
> +
> | http://www.sciopta.com
> | Fastest direct message passing kernel.
> | IEC61508 certified.
> +
>
The best way is probably to use the linker script to place a specific
section where you want and then use GCC attributes to put the variable
in that section.

See the GNU LD and GCC manuals for more details.

Pete

--
Pete Vidler
Senior Systems Developer,
TTE Systems Ltd

Work: http://www.tte-systems.com
Home: http://petevidler.com
Sorry Jakub
> I've read manual and asked uncle google and I did not find satisfy answer -
> so I wrote.
>
> So please response only if you know how to do this.

You seem to read the wrong doc or are blind. Look up chapter
5.34 Specifying Attributes of Variables
of the CW online doc for the gcc

So it seems asking you to read the manual wasn't all this wrong.

--
42Bastian
+
| http://www.sciopta.com
| Fastest direct message passing kernel.
| IEC61508 certified.
+
Thanks for your answer. I'm not blind and I found it before, but I still
dont know which attribute use. Probably I'm not so clever as you so could
you give me an example in code?

regards
Jakub

> Sorry Jakub
>> I've read manual and asked uncle google and I did not find satisfy
>> answer -
>> so I wrote.
>>
>> So please response only if you know how to do this.
>
> You seem to read the wrong doc or are blind. Look up chapter
> 5.34 Specifying Attributes of Variables
> of the CW online doc for the gcc
>
> So it seems asking you to read the manual wasn't all this wrong.
>
> --
> 42Bastian
> +

On 08/09/2008 07:35, Jakub Szumacher wrote:
> Thanks for your answer. I'm not blind and I found it before, but I still
> dont know which attribute use. Probably I'm not so clever as you so could
> you give me an example in code?

Without being paid? No, but I will give you this:

http://gcc.gnu.org/onlinedocs/gcc-4.5.0/gcc/Variable-Attributes.html
http://sourceware.org/binutils/docs-2.20/ld/Scripts.html

Should be easy enough from there.

Pete

P.S. Your posts all appear to be coming from 2008 (see first line of
this email)... your date/time settings may need updating.

--
Pete Vidler
Senior Systems Developer,
TTE Systems Ltd

Work: http://www.tte-systems.com
Home: http://petevidler.com
Am 08.09.2008 08:35, schrieb Jakub Szumacher:
> Thanks for your answer. I'm not blind and I found it before, but I still
> dont know which attribute use. Probably I'm not so clever as you so could
> you give me an example in code?

Open your eyes. It's all there.

--
42Bastian
+
| http://www.sciopta.com
| Fastest direct message passing kernel.
| IEC61508 certified.
+
This response is also for 42Bastian

I had the same problem, placing stuff in crossworks at specific addresses.

I also went through documents, google searches etc...

Finally after extensive and lengthy searching I did find out how to do it, even though I am not really happy about the exact how in terms of readability and portability, but that is another topic. And I was greatly helped by a colleague of mine at work in doing so...

I have been programming embedded systems for over 20 years, mainly in assembly forth a bit of C many proprietary languages etc and even java... In that respect i am definitely not a novice.

However, you will note that I said "a bit of C" and recently for the location of stuff in memory I was frustrated not by the inability of C to do anything, but by the lack of clarity on how to have more control over what and where C does and puts things....

So, in a nutshell, the OP question is definitely a valid source of frustration, and your responses could have been clear concise and polite, and a lot less arrogant.

I do understand that many here post silly questions, I do understand that many are lazy and expect others to do their work, and I do understand that you among most of us are busy and frustrated by many if not most posts. But I do think this question was not as trivial as you two make it out to be.

And you do have the option to not read what is not of interest and not waste your time being condescendant.

As for me, I would also like some other person's perspective on locating stuff in memory in C and assembly in crossworks.

I defined a section, put my stuff there then defined the section's address, all of which in my mind is tedious and not perfectly straightforward. (That was for the assembly bits... )

My 2 cents and my opinion.

Adrian

--- In l..., Pete Vidler wrote:
>
> On 08/09/2008 07:35, Jakub Szumacher wrote:
> > Thanks for your answer. I'm not blind and I found it before, but I still
> > dont know which attribute use. Probably I'm not so clever as you so could
> > you give me an example in code?
>
> Without being paid? No, but I will give you this:
>
> http://gcc.gnu.org/onlinedocs/gcc-4.5.0/gcc/Variable-Attributes.html
> http://sourceware.org/binutils/docs-2.20/ld/Scripts.html
>
> Should be easy enough from there.
>
> Pete
>
> P.S. Your posts all appear to be coming from 2008 (see first line of
> this email)... your date/time settings may need updating.
>
> --
> Pete Vidler
> Senior Systems Developer,
> TTE Systems Ltd
>
> Work: http://www.tte-systems.com
> Home: http://petevidler.com
>

If whoever whenever will have the same problem - I put my solution here:
Problem (example): Put variable "uiSzum" on address 0x40000000 (begining of SRAM) in Crossworks
1. Modify map file (*.xml), adding new memory segment and changing SRAM memory segment








2. In crossworks - using __attribute__((section("name"))) in variable definition:

unsigned int uiSzum __attribute__((section(".gdata")));

3. Compile and result in *.map:

.gdata 0x40000000 0x4
0x40000000 __gdata_start__ = .
*(.gdata)
.gdata 0x40000000 0x4 ARM Flash Debug/main.o
0x40000000 uiSzum
0x40000004 __gdata_end__ = (__gdata_start__ + SIZEOF (.gdata))

regards
Jakub

----- Original Message -----
From: adrianunderwater
To: l...
Sent: Thursday, September 09, 2010 2:35 AM
Subject: [lpc2000] Re: Force variable address / C / Crossworks

This response is also for 42Bastian

I had the same problem, placing stuff in crossworks at specific addresses.

I also went through documents, google searches etc...

Finally after extensive and lengthy searching I did find out how to do it, even though I am not really happy about the exact how in terms of readability and portability, but that is another topic. And I was greatly helped by a colleague of mine at work in doing so...

I have been programming embedded systems for over 20 years, mainly in assembly forth a bit of C many proprietary languages etc and even java... In that respect i am definitely not a novice.

However, you will note that I said "a bit of C" and recently for the location of stuff in memory I was frustrated not by the inability of C to do anything, but by the lack of clarity on how to have more control over what and where C does and puts things....

So, in a nutshell, the OP question is definitely a valid source of frustration, and your responses could have been clear concise and polite, and a lot less arrogant.

I do understand that many here post silly questions, I do understand that many are lazy and expect others to do their work, and I do understand that you among most of us are busy and frustrated by many if not most posts. But I do think this question was not as trivial as you two make it out to be.

And you do have the option to not read what is not of interest and not waste your time being condescendant.

As for me, I would also like some other person's perspective on locating stuff in memory in C and assembly in crossworks.

I defined a section, put my stuff there then defined the section's address, all of which in my mind is tedious and not perfectly straightforward. (That was for the assembly bits... )

My 2 cents and my opinion.

Adrian

--- In l..., Pete Vidler wrote:
>
> On 08/09/2008 07:35, Jakub Szumacher wrote:
> > Thanks for your answer. I'm not blind and I found it before, but I still
> > dont know which attribute use. Probably I'm not so clever as you so could
> > you give me an example in code?
>
> Without being paid? No, but I will give you this:
>
> http://gcc.gnu.org/onlinedocs/gcc-4.5.0/gcc/Variable-Attributes.html
> http://sourceware.org/binutils/docs-2.20/ld/Scripts.html
>
> Should be easy enough from there.
>
> Pete
>
> P.S. Your posts all appear to be coming from 2008 (see first line of
> this email)... your date/time settings may need updating.
>
> --
> Pete Vidler
> Senior Systems Developer,
> TTE Systems Ltd
>
> Work: http://www.tte-systems.com
> Home: http://petevidler.com
>