Hello everyone,
I've been using MSPGCC for the past several months in a large firmware
project with good success. The version I've been using is v3.2.3, from
the mspgcc-20040723.exe release, running on Win2K.
It took me a while to figure out how to get MSPGCC to actually put
constant data into ROM/FLASH instead of RAM (just declaring as const
didn't do it -- had to use array notation like const AString[]="String"
instead of pointer notation like const *AString="String").
But I've been unsuccessful to get arrays of function pointers to be
placed in ROM/FLASH. The tools want to place arrays of function
pointers, even when declared as const, into RAM. Is this behavior of
MSPGCC correct, or am I missing a command line flag, or is there some
subtle syntax required?
As an example, here is a simple (but contrived) source file that
illustrates the problem:
=========================================================
/*
// Test file -- why are the function pointers placed in RAM instead
// of in a ROM table?
*/
/*
// Two functions to populate the function table. Declaring as const
// is needed to keep gcc from griping.
*/
const int Function1(int);
const int Function2(int);
/*
// Now declare an array of functions. Since they are
// declared as constants, shouldn't they be placed in
// ROM?
*/
const int (*MyFunctions[])(int) = {
Function1,
Function2
};
/*
// Just a dummy main to get the code to compile and link.
// The return(1) is to keep GCC from griping.
*/
int main(void)
{
int a;
a = MyFunctions[0](10);
a = a + MyFunctions[1](32);
return(1);
}
/*
// The dummy functions for the function table. Again, declared
// as const to keep GCC from griping.
*/
const int Function1(int AVar)
{
return(AVar + 7);
}
const int Function2(int AVar)
{
return(AVar * 2);
}
/*
// Done.
*/
=========================================================
Since I've declared the function array MyFunctions as a const, and am
using a syntax consistent with what MSPGCC expects for strings or
structures to be placed in ROM/FLASH, I'd expect MyFunctions to be
placed at an address in ROM/FLASH. But after executing the following
two commands:
msp430-gcc -mmcu=msp430x449 -O2 -Wall -g -c Test.c -o Test.o
msp430-gcc -mmcu=msp430x449 -Wl,-Map=Test.map,--cref -o Test.elf Test.o
I see the following from the Test.map file:
.data 0x00000200 0x4 Test.o
0x00000200 MyFunctions
0x00000204 . = ALIGN (0x2)
*(.gnu.linkonce.d*)
0x00000204 . = ALIGN (0x2)
0x00000204 _edata = .
MyFunctions is placed in the .data segment, at address 0x200, which is
RAM. And the size is consistent with two function pointers -- two
function pointers of two bytes each would indeed consume 4 bytes of RAM.
I've tried compiling for several variants of the MSP430, and obtain the
same results.
So ... what am I missing?
Thanks in advance.
Just further contribution to white noise from Todd...
------======>>>>>>}}}}}}]]]]]]||||||[[[[[[{{{{{{<<<<<<======------
e-mail: hochw...@technical-mandala.com
Some world-views are spacious
And some are merely spaced
- Neil Peart