public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Address assignment
@ 2005-09-14  4:20 shreyas krishnan
  2005-09-14  5:38 ` DJ Delorie
  0 siblings, 1 reply; 13+ messages in thread
From: shreyas krishnan @ 2005-09-14  4:20 UTC (permalink / raw)
  To: binutils

Hi all, 
     I am trying to assign my own addresses to the different program
objects - data variables and functions. Is this done on the assembler
or the linker ? Can anybody give me pointers as to how I can do it.
Out of curiosity, do any checks happens to guard again address
portions overlapping.

I will appreciate any ideas 
thanks
shrey

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Address assignment
  2005-09-14  4:20 Address assignment shreyas krishnan
@ 2005-09-14  5:38 ` DJ Delorie
  2005-09-14 10:47   ` shreyas krishnan
  0 siblings, 1 reply; 13+ messages in thread
From: DJ Delorie @ 2005-09-14  5:38 UTC (permalink / raw)
  To: shreyas76; +Cc: binutils


If what you mean is something like "I have this structure, but it exists
at a specific address" you can easily do this in the assembler like this:

	.global _my_struct
_my_struct = 0xa0001028

The linker doesn't care *what* a symbol is, just *where* it is.  The
above gives it an absolute address (it shows up in the "*ABS*"
section) but doesn't allocate any space for it (sorry, no overlap
protection).


If what you mean is "I want code in this block of flash, and data in
this block of RAM" then you want to look up the MEMORY directive for
link scripts in the linker manual ("info ld").  If you download the
latest newlib from CVS and look at libgloss/m32c you'll see a number
of examples of how to manage all that.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Address assignment
  2005-09-14  5:38 ` DJ Delorie
@ 2005-09-14 10:47   ` shreyas krishnan
  2005-09-14 13:17     ` Dave Korn
  0 siblings, 1 reply; 13+ messages in thread
From: shreyas krishnan @ 2005-09-14 10:47 UTC (permalink / raw)
  To: DJ Delorie; +Cc: binutils

Thanks for taking my question. My intention is the earlier that is to
assign addresses to variables, like you have shown with my_struct. But
currently I see my assembly file  containing .comm directives for all
the global variables or .bss for static variable. So In this case is
there a directive that I can add to the assembly file which will
additionally specify the address of each variable. My addresses  are
generated insider the compiler, so I would like something which works
automatically -perhaps just additions to the assembler file or
modifications in the assembler.

thanks again
Shrey 

On 9/14/05, DJ Delorie <dj@redhat.com> wrote:
> 
> If what you mean is something like "I have this structure, but it exists
> at a specific address" you can easily do this in the assembler like this:
> 
>         .global _my_struct
> _my_struct = 0xa0001028
> 
> The linker doesn't care *what* a symbol is, just *where* it is.  The
> above gives it an absolute address (it shows up in the "*ABS*"
> section) but doesn't allocate any space for it (sorry, no overlap
> protection).
> 
> 
> If what you mean is "I want code in this block of flash, and data in
> this block of RAM" then you want to look up the MEMORY directive for
> link scripts in the linker manual ("info ld").  If you download the
> latest newlib from CVS and look at libgloss/m32c you'll see a number
> of examples of how to manage all that.
>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: Address assignment
  2005-09-14 10:47   ` shreyas krishnan
@ 2005-09-14 13:17     ` Dave Korn
  2005-09-14 16:50       ` DJ Delorie
  2005-09-14 23:23       ` shreyas krishnan
  0 siblings, 2 replies; 13+ messages in thread
From: Dave Korn @ 2005-09-14 13:17 UTC (permalink / raw)
  To: shreyas76, 'DJ Delorie'; +Cc: binutils

----Original Message----
>From: shreyas krishnan
>Sent: 14 September 2005 05:20

> Thanks for taking my question. My intention is the earlier that is to
> assign addresses to variables, like you have shown with my_struct. But
> currently I see my assembly file  containing .comm directives for all
> the global variables or .bss for static variable. So In this case is
> there a directive that I can add to the assembly file which will
> additionally specify the address of each variable. My addresses  are
> generated insider the compiler, so I would like something which works
> automatically -perhaps just additions to the assembler file or
> modifications in the assembler.

  Ah, you're using a compiler rather than writing assembly?  Well, in C,
rather than

>>         .global _my_struct
>> _my_struct = 0xa0001028

you'd want to use a pointer variable:

struct my_struct_type * const my_struct = (struct my_struct_type
*)0xa0001028;

  Putting const after the '*' like this means that the _pointer_ is constant
- always points to the same place - rather than the thing that it points to,
and that should be all the compiler needs to know to optimise references
through the pointer to direct memory operations.

  General questions about _using_ the compiler are best sent to the gcc-help
list; the main binutils and gcc lists are about modifying the source code of
the tools, understanding their internal operations, debugging them, and so
on; in other words, working _on_ them rather than _with_ them.

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Address assignment
  2005-09-14 13:17     ` Dave Korn
@ 2005-09-14 16:50       ` DJ Delorie
  2005-09-14 19:37         ` Dave Korn
  2005-09-14 22:16         ` shreyas krishnan
  2005-09-14 23:23       ` shreyas krishnan
  1 sibling, 2 replies; 13+ messages in thread
From: DJ Delorie @ 2005-09-14 16:50 UTC (permalink / raw)
  To: dave.korn; +Cc: shreyas76, binutils


>   Ah, you're using a compiler rather than writing assembly?

You use the compiler to define the structure, and assembly to place
it.

> >>         .global _my_struct
> >> _my_struct = 0xa0001028
> 
> you'd want to use a pointer variable:
> 
> struct my_struct_type * const my_struct = (struct my_struct_type
> *)0xa0001028;

Why add an unneeded level of indirection?  Especially on time-critical
embedded systems?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Address assignment
  2005-09-14 22:16         ` shreyas krishnan
@ 2005-09-14 19:23           ` DJ Delorie
  0 siblings, 0 replies; 13+ messages in thread
From: DJ Delorie @ 2005-09-14 19:23 UTC (permalink / raw)
  To: shreyas76; +Cc: binutils


> Thanks Delorie, your solutions works. I just need to follow the
> lcomm/comm/any other directive with the address assignment.

No, take the .lcomm/.comm out completely, if the structure corresponds
to some hardware device.  If you just want to assign some structures
to a chunk of RAM somewhere, use the MEMORY directive instead (no asm
required, see below).

> But what can you do to place functions, can such an assigment be
> used again?

No, this is where the MEMORY link directive comes into play.  You'd
use __attribute__((section(""))) to have gcc put the function in a
named section, then use MEMORY to tell the linker where in memory to
put that section.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: Address assignment
  2005-09-14 16:50       ` DJ Delorie
@ 2005-09-14 19:37         ` Dave Korn
  2005-09-14 20:53           ` Paul Koning
  2005-09-14 22:16         ` shreyas krishnan
  1 sibling, 1 reply; 13+ messages in thread
From: Dave Korn @ 2005-09-14 19:37 UTC (permalink / raw)
  To: 'DJ Delorie'; +Cc: shreyas76, binutils

----Original Message----
>From: DJ Delorie
>Sent: 14 September 2005 14:17

>>   Ah, you're using a compiler rather than writing assembly?
> 
> You use the compiler to define the structure, and assembly to place
> it.

  I just wanted to suggest an all-in-one-place solution.  There are many
ways to do most things.
  
>>>>         .global _my_struct
>>>> _my_struct = 0xa0001028
>> 
>> you'd want to use a pointer variable:
>> 
>> struct my_struct_type * const my_struct = (struct my_struct_type
>> *)0xa0001028;
> 
> Why add an unneeded level of indirection?  Especially on time-critical
> embedded systems?

  These days, I really have *lots* of faith in the compiler to be able to
optimise that away[*].  But I guess you could always write

#define my_struct (*(struct my_struct_type *)0xa0001028)

and treat it just like an object

   my_struct.x = 3;

    cheers,
      DaveK

[*]   And I tested it as well; with cygwin's x86 gcc-3.4.4, -O0 still loads
the pointer into a register and accesses through it, but at -O1 the pointer
load is eliminated and gcc just emits an absolute memory address in the
instruction.
-- 
Can't think of a witty .sigline today....

^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: Address assignment
  2005-09-14 19:37         ` Dave Korn
@ 2005-09-14 20:53           ` Paul Koning
  2005-09-14 21:20             ` Dave Korn
  0 siblings, 1 reply; 13+ messages in thread
From: Paul Koning @ 2005-09-14 20:53 UTC (permalink / raw)
  To: dave.korn; +Cc: dj, shreyas76, binutils

>>>>> "Dave" == Dave Korn <dave.korn@artimi.com> writes:

 >> Why add an unneeded level of indirection?  Especially on
 >> time-critical embedded systems?

 Dave> These days, I really have *lots* of faith in the compiler to be
 Dave> able to optimise that away[*].  But I guess you could always
 Dave> write

 Dave> #define my_struct (*(struct my_struct_type *)0xa0001028)

 Dave> and treat it just like an object

 Dave> my_struct.x = 3;

If you don't want accesses optimized away, you need "volatile".

   paul

^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: Address assignment
  2005-09-14 20:53           ` Paul Koning
@ 2005-09-14 21:20             ` Dave Korn
  0 siblings, 0 replies; 13+ messages in thread
From: Dave Korn @ 2005-09-14 21:20 UTC (permalink / raw)
  To: 'Paul Koning'; +Cc: dj, shreyas76, binutils

----Original Message----
>From: Paul Koning
>Sent: 14 September 2005 20:23

>>>>>> "Dave" == Dave Korn <dave.korn@artimi.com> writes:
> 
>  >> Why add an unneeded level of indirection?  Especially on
>  >> time-critical embedded systems?
> 
>  Dave> These days, I really have *lots* of faith in the compiler to be
>  Dave> able to optimise that away[*].  But I guess you could always
>  Dave> write
> 
>  Dave> #define my_struct (*(struct my_struct_type *)0xa0001028)
> 
>  Dave> and treat it just like an object
> 
>  Dave> my_struct.x = 3;
> 
> If you don't want accesses optimized away, you need "volatile".
> 
>    paul


  You've missed the point.  I _do_ want accesses optimised away.  Accesses
to the pointer variable; not accesses to the thing it points at.  Yes, for
most memory-mapped h/w, you would want the object to be volatile.  But you
and I are talking about things on opposite sides of the '*':

volatile my_struct_type * const my_struct_ptr = blablablaaaa;



    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Address assignment
  2005-09-14 16:50       ` DJ Delorie
  2005-09-14 19:37         ` Dave Korn
@ 2005-09-14 22:16         ` shreyas krishnan
  2005-09-14 19:23           ` DJ Delorie
  1 sibling, 1 reply; 13+ messages in thread
From: shreyas krishnan @ 2005-09-14 22:16 UTC (permalink / raw)
  To: DJ Delorie; +Cc: dave.korn, binutils

Thanks Delorie, your solutions works. I just need to follow the
lcomm/comm/any other
directive with the address assignment. I wasnt  aware you could do
some thing like that hence my confusion.  But what can you do to place
functions, can such an assigment be used again? I found some other
directives like .org but that seems to advance the pointer for ever, I
only want to be able to change the address for some functions.

regards
shrey 


On 9/14/05, DJ Delorie <dj@redhat.com> wrote:
> 
> >   Ah, you're using a compiler rather than writing assembly?
> 
> You use the compiler to define the structure, and assembly to place
> it.
> 
> > >>         .global _my_struct
> > >> _my_struct = 0xa0001028
> >
> > you'd want to use a pointer variable:
> >
> > struct my_struct_type * const my_struct = (struct my_struct_type
> > *)0xa0001028;
> 
> Why add an unneeded level of indirection?  Especially on time-critical
> embedded systems?
>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Address assignment
  2005-09-14 13:17     ` Dave Korn
  2005-09-14 16:50       ` DJ Delorie
@ 2005-09-14 23:23       ` shreyas krishnan
  2005-09-14 23:43         ` DJ Delorie
  1 sibling, 1 reply; 13+ messages in thread
From: shreyas krishnan @ 2005-09-14 23:23 UTC (permalink / raw)
  To: Dave Korn; +Cc: DJ Delorie, binutils

Just to clarify my question again, I am looking for steps the compiler
can do at the end assembly file generation. So source file
modifications would not help. In other words,  I have modified the
compiler to analyze and find offsets. Now I want to change the default
addresses to the new addrsses So the input to my process is a C file.
Now I want to assign addresses by modifying the assembly file that the
compiler generates inside the compiler itself or do that some where
else. But  I find that the assembly file generated already has .comm,
.lcomm or .bss generated based on the kind of  global variable and it
would not take the 2 lines  ( .global mystruct ....). My target is
mcore-elf.

Any pointers to what I can do ? 

thanks again 
Shrey 

On 9/14/05, Dave Korn <dave.korn@artimi.com> wrote:
> ----Original Message----
> >From: shreyas krishnan
> >Sent: 14 September 2005 05:20
> 
> > Thanks for taking my question. My intention is the earlier that is to
> > assign addresses to variables, like you have shown with my_struct. But
> > currently I see my assembly file  containing .comm directives for all
> > the global variables or .bss for static variable. So In this case is
> > there a directive that I can add to the assembly file which will
> > additionally specify the address of each variable. My addresses  are
> > generated insider the compiler, so I would like something which works
> > automatically -perhaps just additions to the assembler file or
> > modifications in the assembler.
> 
>   Ah, you're using a compiler rather than writing assembly?  Well, in C,
> rather than
> 
> >>         .global _my_struct
> >> _my_struct = 0xa0001028
> 
> you'd want to use a pointer variable:
> 
> struct my_struct_type * const my_struct = (struct my_struct_type
> *)0xa0001028;
> 
>   Putting const after the '*' like this means that the _pointer_ is constant
> - always points to the same place - rather than the thing that it points to,
> and that should be all the compiler needs to know to optimise references
> through the pointer to direct memory operations.
> 
>   General questions about _using_ the compiler are best sent to the gcc-help
> list; the main binutils and gcc lists are about modifying the source code of
> the tools, understanding their internal operations, debugging them, and so
> on; in other words, working _on_ them rather than _with_ them.
> 
>     cheers,
>       DaveK
> --
> Can't think of a witty .sigline today....
> 
>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Address assignment
  2005-09-14 23:23       ` shreyas krishnan
@ 2005-09-14 23:43         ` DJ Delorie
  2005-09-15  2:23           ` shreyas krishnan
  0 siblings, 1 reply; 13+ messages in thread
From: DJ Delorie @ 2005-09-14 23:43 UTC (permalink / raw)
  To: shreyas76; +Cc: binutils


Just out of curiosity, and perhaps to help us help you, *why* are you
trying to assign addresses to C variables?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Address assignment
  2005-09-14 23:43         ` DJ Delorie
@ 2005-09-15  2:23           ` shreyas krishnan
  0 siblings, 0 replies; 13+ messages in thread
From: shreyas krishnan @ 2005-09-15  2:23 UTC (permalink / raw)
  To: DJ Delorie; +Cc: binutils

:) thats my line ( just out of curiosity)....I am implementing  a
memory management scheme but which is decided at compile time. The
contents of the devices are changed at specific points in the program,
like caching. So the address of a variable keeps changing. So the way
I have thought of handling this is have one variable for each address
a particular variable can take. And so i need a way to assign address
to the variable. IHope this makes sense. I can refer you to the paper
that I am using if you would like.
            All your suggestions have been helpful. I am trying to
figure out how to use overlays, so that I can do an address assignent
for functions. One or more function can take the same address  but
their addresses may not be totally same, just partial overlap.

Shrey 

On 9/14/05, DJ Delorie <dj@redhat.com> wrote:
> 
> Just out of curiosity, and perhaps to help us help you, *why* are you
> trying to assign addresses to C variables?
>

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2005-09-14 23:43 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-14  4:20 Address assignment shreyas krishnan
2005-09-14  5:38 ` DJ Delorie
2005-09-14 10:47   ` shreyas krishnan
2005-09-14 13:17     ` Dave Korn
2005-09-14 16:50       ` DJ Delorie
2005-09-14 19:37         ` Dave Korn
2005-09-14 20:53           ` Paul Koning
2005-09-14 21:20             ` Dave Korn
2005-09-14 22:16         ` shreyas krishnan
2005-09-14 19:23           ` DJ Delorie
2005-09-14 23:23       ` shreyas krishnan
2005-09-14 23:43         ` DJ Delorie
2005-09-15  2:23           ` shreyas krishnan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).