public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Can I get m68k gcc to generate 16-bit variable references?
@ 2003-09-22 23:46 steven
  2003-09-23  2:24 ` Eljay Love-Jensen
  0 siblings, 1 reply; 2+ messages in thread
From: steven @ 2003-09-22 23:46 UTC (permalink / raw)
  To: gcc-help

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!

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Can I get m68k gcc to generate 16-bit variable references?
  2003-09-22 23:46 Can I get m68k gcc to generate 16-bit variable references? steven
@ 2003-09-23  2:24 ` Eljay Love-Jensen
  0 siblings, 0 replies; 2+ messages in thread
From: Eljay Love-Jensen @ 2003-09-23  2:24 UTC (permalink / raw)
  To: steven, gcc-help

Hi Steve,

C++ has a way to do it (via references), but you want to do it in C.

Hmm.

The usual way of doing it in C is with pointers.

struct lowmem { int foo; /* ... */ };
struct lowmem* gLowmem = (struct lowmem*)0x0400;
int count_foo(void) { return ++gLowmem->foo; }

HTH,
--Eljay


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-09-23  2:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-22 23:46 Can I get m68k gcc to generate 16-bit variable references? steven
2003-09-23  2:24 ` Eljay Love-Jensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).