Linker file
This section covers changes that have to be done to the linker script to use print functions in PXROS-HR.
Placement of library data
The data and bss sections from the Dinkumware library must be collected and inserted into output sections that will occupy a contiguous range of memory. The beginning and end of this memory block must be marked with symbols that are aligned to 8 bytes (general requirement of TriCore™ MPU). Those symbols are then used to configure data access for a task that uses the print functions. The data must be collected prior collection of all remaining common data, i.e., before the .data and .bss sections.
The following code shows where to add the libdnk_c.a and libos.a libraries. The original linker file comes from the TC39x PXROS BSP example.
...
/* ----- Restore CORE_ID ----- */
CORE_ID = GLOBAL;
/* ========================================================================================
* Dinkumware and libos library .data and .bss sections
* ======================================================================================*/
SECTION
{
/* The library data are needed because of the sprintf family functions.
* The .library section will cover data from dinkumware and libos libraries.
*/
.library.data :
{
. = ALIGN(8);
LIBRARY_DATA_BASE = .;
*libdnk_c.a: (*.data*) // All symbols that were originaly placed in .data section
// of the libdnk_c.a will be placed in the .library.data
// output section
*libos.a: (*.data*) // Similar for symbols comming from the libos.a
} > DATA AT > RODATA
.library.bss :
{
*libdnk_c.a: (*.bss*) // All symbols that were originaly placed in .bss section
// of the libdnk_c.a will be placed in the .library.bss
// output section
. = ALIGN(8);
LIBRARY_DATA_END = .;
} > DATA
}
/* ========================================================================================
* Common CODE & DATA sections
* ======================================================================================*/
SECTIONS
{
...
/* All common initialized data not yet collected */
.data : ALIGN(4)
{
*(.data*)
} > DATA AT > RODATA
/* All common non-initialized data not yet collected */
.bss : ALIGN(4)
{
*(.bss*);
*(COMMON);
} > DATA
/* HEAP area for stdlib functions */
.heap : ALIGN(8)
{
__HEAP = .;
. += __HEAP_SIZE;
. = ALIGN(8);
__HEAP_END = .;
} > DATA
}
Initialization of library data
The .library.bss and .library.data sections must be added to the clear and copy tables so that the crt0 routine properly initializes the data. All common data are initialized by CPU0.
The following code shows where to add the clear and copy records. The original linker file comes from the TC39x PXROS BSP example.
/* ========================================================================================
* CLEAR & COPY TABLES with END delimiter to support crt0 init
* Each core has its own table to process during its init to allow multicore execution.
* Shared resources are inserted to Core[0] tables (the RESET core)
* clear_sec:
* data memory ranges to clear to zero
* copy_sec:
* data memory ranges that needs to be value initialized
* (init values are stored in FLASH and copied to RAM)
* ======================================================================================*/
SECTIONS
{
/* ---- CORE 0 ---- */
.CPU0.clear_sec :
{
LONG(ADDR(.library.bss)); LONG(SIZEOF(.library.bss));
LONG(ADDR(.bss)); LONG(SIZEOF(.bss));
LONG(ADDR(.heap)); LONG(SIZEOF(.heap));
LONG(-1); LONG(-1);
} > RODATA_CPU0_
.CPU0.copy_sec :
{
LONG(LOADADDR(.library.data)); LONG(ADDR(.library.data)); LONG(SIZEOF(.library.data));
LONG(LOADADDR(.data)); LONG(ADDR(.data)); LONG(SIZEOF(.data));
LONG(-1); LONG(-1); LONG(-1);
} > RODATA_CPU0_
/* ---- CORE 1 ---- */
.CPU1.clear_sec :
{
LONG(-1); LONG(-1);
} > RODATA_CPU1_
.CPU1.copy_sec :
{
LONG(-1); LONG(-1); LONG(-1);
} > RODATA_CPU1_
...