Re: Position independent code with position dependent data ?

On Thu, 1 Jul 2010 05:12:36 -0700 (PDT), nono240 <nono240@xxxxxxxxx>

Unless you want to download multiple tasks like this, and have them
stored in arbitrary places in flash (and ram), then there is no need for
position-independent data or code

IT IS my case. It's a (commercial) product, letting the user to load
multiple (so named) "tasklets" into FLASH, but its only allowed to run
ONE at a time. So, we need those "tasklets" to be CODE position
independent, but share DATA.

If you can run only one task at a time, why do you need position
independent code ? Just link each program to the same fixed load
address. You need PIC code only when there are _multiple_ programs to
be loaded somewhere into the RAM.

If you want to share data between these programs, first link the data
area to a fixed address and then link each program to that address.

This is how it was done half a century ago. In FORTRAN, create a
COMMON area, install it into a fixed address (usually at the top of
the core) and then load each "transient program" into low memory,
since the whole program could not fit into the core at once. No
base/stack pointer relative addressing needed, since the data
addresses were known at compile time.

With modern processors with versatile addressing modes, why not
reserve one data area pointer at a known location (such as the first
or last address in RAM or ROM) and use this to access the shared
variables in each program ?

Data = GetPersistentDataAreaPointer() ;
Data->SharedVar1 = Data->SharedVar2 ;