Placing a library in RAM

Technical Note 200401

Targets:
Arm

Component:
Linker

Updated:
6/25/2020 11:32 AM

Introduction

This Technical Note describes a method of placing a library in RAM.

Discussion

Download and open the example project from TN_200401.zip (projects built with IAR Embedded Workbench for Arm 8.42.2).

The example (TN_200401.zip) contains two projects:

  • Simplelib – builds a library file (simplelib.a) containing a global array and a function returning a value from the array.
  • Place Lib in RAM – a demo project that places the library in RAM and executes the library function.

To place the library (simplelib.a) in RAM, follow these steps:

  1. Define an address range in RAM for the library code.
define symbol region_RAM_CODE_start = 0x08010000;
define symbol region_RAM_CODE_end = 0x0801FFFF;

 

  1. Define a region for the library code.

 

define region RAM_CODE_region = mem:[from region_RAM_CODE_start to region_RAM_CODE_end];

 

  1. Define a block (placed in RAM) for the library code. The section selector directive collects code content from the library and the section attribute readwrite instructs the linker to link it as code executing from RAM.

 

define block LIB {readwrite code object simplelib.a};

 

  1. Define a block (placed in ROM) for the initializer bytes from the library. The section selection directive collects all the _init sections (the code content) from the library.

 

define block LIB_INIT {readonly code section *_init object simplelib.a};

 

  1. The initialize by copy directive instructs the linker to create *_init sections (containing the code content from the library) to enable copying from ROM to RAM and arrange for the startup code to copy code content from block LIB_INIT to block LIB.

 

initialize by copy { readonly object simplelib.a };

 

  1. The place in directive instructs the linker to place the block for the library code in RAM.

 

place in RAM_CODE_region { block LIB };

 

  1. The place in directive instructs the linker to place the initializer bytes (code content) from the library in ROM.

 

place in ROM_region { block LIB_INIT };

 

Conclusion

To place a library in RAM, define a region in RAM for the library, define and place a block LIB in RAM, define and place a block LIB_INIT in ROM, and finally arrange for the code contents of the library to be copied at startup from ROM to RAM.

 

 

All product names are trademarks or registered trademarks of their respective owners.

© IAR Systems 1995-2020 - All rights reserved.

We use cookies on this website to provide you with a better experience. You need to accept cookies to continue using this site. Cookies