What's the purpose of bsp_start_copy_sections?

Mr. Andrei Chichak groups at chichak.ca
Tue Jan 13 01:50:43 UTC 2015


> On 2015-January-12, at 06:52, Martin Galvan <martin.galvan at tallertechnologies.com> wrote:
> 
> I was looking at the common ARM routines and noticed
> bsp_start_copy_sections appears to copy several sections from their
> LMAs to their VMAs. If we were to have a BSP for a board that stores,
> say, the .text section in ROM, bsp_start_copy_sections seems to be
> copying it to RAM. Is this correct? If so, what would be the purpose
> of doing that?
> 

All of the following examples have the variables declared static so they are not allocated on the stack and I don’t have to get into where things are declared and scoping.

On a desktop box, everything is copied off of disk and stored in RAM. Not so with embedded systems. Your compiler will arrange for all initial values to get stored in ROM and if the target values can be changed they will be copied to RAM. Your code is executed from ROM. (Yes Sheldon, I know that all generalities are wrong and that there are systems that don’t conform to these notes, sometimes things are transferred to RAM for speed)





Assume for the moment that you have:

static char fu[] = “text text text”;

The value “text text text” is stored in ROM and, at startup, copied into RAM because fu is mutable. You may want to say fu[1] = ‘a’; fu[3] = ‘i’; and you get “taxi text text”.

Now, if you have:

static const char bar[] = “sushi sushi”;

The value “sushi sushi” is stored in ROM and NOT copied into RAM because it is a constant and cannot be altered (const). If the memory management units are set up correctly, the ROM is marked as read only and any attempt to modify the value of bar will cause an exception. So, bar[0] = ‘*’; should cause a trap.

The same action happens for;

static uint8_t a;				/* Zerod out at boot time, but don’t count on it, that’s a bad assumption */
static int16_t hhgttg= 42;			/* value 42 copied from ROM */
static const int32_t temperatureNow = -17;	/* used from ROM and not copied to RAM, immutable, nothing can change -17 */



Does this answer your question?

Andrei


> Thanks a lot!
> 
> -- 
> 
> Martín Galván
> 
> Software Engineer
> 
> Taller Technologies Argentina
> 
> San Lorenzo 47, 3rd Floor, Office 5
> 
> Córdoba, Argentina
> 
> Phone: 54 351 4217888 / +54 351 4218211
> _______________________________________________
> users mailing list
> users at rtems.org
> http://lists.rtems.org/mailman/listinfo/users





More information about the users mailing list