Georg-Johann Lay wrote:

> AVR hardware has basically three address spaces:
[snip]

OK, thanks for the information!

> Of course, RAM and Flash are no subsets of each other when regarded as
> physical memory, but they are subsets when regarded as numbers. This
> lead to my mistake to define RAM and Flash being no subsets of each other:
>    http://gcc.gnu.org/ml/gcc/2010-11/msg00170.html

Right, in your situation those are *not* subsets according to the AS rules,
so your avr_addr_space_subset_p routine needs to always return false
(which of course implies you don't need a avr_addr_space_convert routine).

Getting back to the discussion in the other thread, this also means that
pointer conversions during initialization cannot happen either, so this
discussion is basically moot.

> However, there are situations like the following where you like to take
> the decision at runtime:
> 
> char cast_3 (char in_pgm, void * p)
> {
>      return in_pgm ? (*((char __pgm *) p)) : (*((char *) p));
> }

That's really an abuse of "void *" ... if you have an address in the
Flash space, you should never assign it to a "void *".

Instead, if you just have a address and you don't know ahead of time
whether it refers to Flash or RAM space, you ought to hold that number
in an "int" (or "short" or whatever integer type is most appropriate),
and then convert from that integer type to either a "char *" or a
"char __pgm *".

> Linearizing the address space at compiler level is not wanted because 
> that lead to bulky, slow code and reduced the effective address space
> available for Flash which might be up to 64kWords.

I guess to simplify things like the above, you might have a third
address space (e.g. "__far") that is a superset of both the default
address space and the __pgm address space.  Pointers in the __far
address space might be e.g. 3 bytes wide, with the low 2 bytes
holding the address and the high byte identifying whether the address
is in Flash or RAM.

Then a plain dereference of a __far pointer would do the equivalent
of your cast_3 routine above.

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  ulrich.weig...@de.ibm.com

Reply via email to