This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Can I get m68k gcc to generate 16-bit variable references?
- From: steven at horizon dot com
- To: gcc-help at gcc dot gnu dot org
- Date: 22 Sep 2003 23:46:32 -0000
- Subject: Can I get m68k gcc to generate 16-bit variable references?
I'm using gcc to compile some embedded C code (m68k-elf, unless someone
has any other suggestion), and I'm trying to avoid the code bloat cuased
by using 32-bit absolute addresses for all static variables.
I'd like to generate either offsets off a base register or use the m68k
absolute short (_variable:w) addressing mode.
Ideally, I could choose (on the command line) one of the three as the
default and use an attribute on a variable to select the other.
That is, I could have three kinds of "static" variables:
- Per-process globals, based on (%a5) (up to 64K). The asm output
for a reference to "foo" should look like "_foo-a5$base(%a5)",
with the run-time to initialize %a5 to hold a5$base
- System-wide globals using the absolute short addressing mode (careful
linking required to get the right segment in the first or last 32K of
memory, of course).
- Big system-wide globals using 32-bit absolute addresses.
-fpic generates a table of pointers to objects which can be accessed
off %a5, but doesn't put the objects themselves there.
I suppose as long as I'm wishing, I'd also like a PC-realtive attribute
which, combined with putting the variable in the code section, could be
used for short references to const data.
For really small applications, I could just do hacks with structures, e.g.
struct lowmem { int foo; /*...*/ };
#define lowmem (*(struct lowmem *)1024)
int count_foo(void) { return ++lowmem.foo; }
but that really distorts the code. I'd like to be able to declare static
variables in functions and have the linker assign addresses automatically.
Surely I'm not the first person to want this. Has anyone implemented
anything similar? Can anyone point me to where to hack it in?
Thanks!