[arm-gnu] Placing variable at absolute address in RAM

Mark Deneen mdeneen+arm at saucontech.com
Thu Apr 5 14:25:58 UTC 2012


I don't think what you are trying to do is possible with GCC.  You can specify that you want a variable at a particular address:

int32 *var = (int32*)0x8000100;

But you can't easily prevent this address from being used by something else.

You could try splitting up the ram into 3 sections in the linker script, with one of the sections being the tiny 16 byte section.

-M

----- Original Message -----
I started implementing your suggestion, but realized I have to split off a piece of RAM for HWMAP, which will waste a considerable amount of RAM...unless I'm misunderstanding something. 
What I need, ideally, is to reserve 16 bytes at an arbitrary place in the RAM space. Unfortunately, since it must be 464 bytes after a 1024 byte boundary, it ends up being "in the middle" somewhere. About 12K of the 96K is global or statically assigned, and the rest is allocated dynamically in fairly large chunks using a proprietary allocation system. 


I had no idea this would be so difficult, but apparently GCC doesn't make this easy, unlike other compilers. Since I'm using the lite (free) compiler, buying one really isn't an option for hobby use. 






From: Alexander Zakharov <azakharov at uniserve.com> 
To: tom_usenet at optusnet.com.au; 'JM' <hondgm at yahoo.com> 
Cc: arm-gnu at codesourcery.com 
Sent: Thursday, April 5, 2012 3:24 AM 
Subject: RE: [arm-gnu] Placing variable at absolute address in RAM 

This is what I used in a past: 

In linker 'helper' file hwmap.ld 

............ 
.dmaRegisters 0X70000000 (NOLOAD): { 
*(.dmaRegisters) } > HWMAP 
............ 

In source file hwmap.c 

....... 
DMA_REGISTERS dmaRegisters 
__attribute__ ((used,section(".dmaRegisters"))); 
....... 

In header file dmaRegisters.h 

....... 
typedef struct 
{ 
/* Something */ 

} DMA_REGISTERS; 


extern DMA_REGISTERS dmaRegisters; 
......... 

And finally, in a main linker file my_board.ld 

...... 
MEMORY 
{ 
RAM (rwx) : ORIGIN = 0x00000000, LENGTH = 16M 
ROM (rwx) : ORIGIN = 0xFFFFFFFF, LENGTH = 0 
ALIASMEM (rwx) : ORIGIN = 0x10000000, LENGTH = 16M 
HWMAP (rw ) : ORIGIN = 0x20000000, LENGTH = 3584M 
} 
...... 
/* Include hardware registers maps */ 

INCLUDE hwmap.ld 
..... 

Then you just use dmaRegisters in your code like " dmaRegisters.field = X; " 

Hope it helps. This way you can 'stick' your variable in any place in a 
memory - this is how I implemented my hardware registers access in a past, 
but should work like a charm for your cause. 

Cheers, 
Alex 






_______________________________________________
arm-gnu mailing list
arm-gnu at codesourcery.com
http://sourcerytools.com/cgi-bin/mailman/listinfo/arm-gnu



More information about the arm-gnu mailing list