Can I get m68k gcc to generate 16-bit variable references?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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!


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux