[arm-gnu] Placing variable at absolute address in RAM
Tom Evans
tom_usenet at optusnet.com.au
Fri Apr 6 01:13:59 UTC 2012
On 6/04/2012 12:02 AM, JM wrote:
> *From:* Tom Evans <tom_usenet at optusnet.com.au>
>>If you don't have "malloc" then you should have something similar
> managing your heap that could be abused to do this for you.
>
> Intriguing idea, but I actually do not use malloc, but rather
> a replacement I wrote that simply allocates RAM in
> consecutive chunks of the requested size.
A simple sequential allocator for a system that allocates memory but
doesn't free it. That's pretty common.
This question has nothing to do with the compiler, and all of your
questions on use of the linker should be answered in "The Gnu Linker
Manual" which comes with a CodeSourcery distribution.
> If I did this in my case, it would leave 400-500
> bytes unused.
I can think of at least three ways to solve this (before breakfast :-),
but I'll only list two.
The unnecessarily complicated sledgehammer-and-peanut way is to use the
linker to declare THREE separate named memory regions. The "tiny fixed
address region" that you need somewhere in the heap, the chunk before
and the chunk after. You then modify your custom allocater to be smart
enough to allocate from the TWO regions named in the linker. All it has
to do is to try to allocate from the first, and if that fails, to
allocate from the second instead. The first one will eventually fill up
with small requests so you won't be wasting more than a few bytes.
That's so simple it'd only take a few lines of code and two static
variables at most.
The really simple way is to have the Allocator able to handle two
regions, and have it hard-allocate the DMA block during its
initialisation and thereafter allocate from the region before and the
region after like listed previously. That's what I'd do.
Tom
More information about the arm-gnu
mailing list