Microchip Technology SW006023-2N Data Sheet

Page of 238
MPLAB
®
 XC32 C/C++ Compiler User’s Guide
DS51686E-page 148
 2012 Microchip Technology Inc.
In order to clear or initialize these sections, the linker creates a data-initialization 
template, which is loaded into an output section named .dinit. The linker creates 
this special .dinit section, allocated in program memory, to hold the template for 
the run-time initialization of data. The C/C++ start-up module, crt0.o, interprets this 
template and copies initial data values into initialized data sections. This includes 
sections containing ramfunc attributed functions. Other data sections (such as .bss) 
are cleared before the main() function is called. The persistent data section (.pbss) 
is not affected. When the application’s main program takes control, all variables and 
RAM functions in data memory have been initialized.
The data initialization template contains one record for each output section in data 
memory. The template is terminated by a null instruction word. The format of a data 
initialization record is:
/* data init record */
struct data_record {
  char *dst;            /* destination address  */
  unsigned int len;     /* length in bytes      */
  unsigned int format;  /* format code          */
  char dat[0];          /* variable-length data */
};
The first element of the record is a pointer to the section in data memory. The second 
and third elements are the section length and format code, respectively. The last 
element is an optional array of data bytes. For bss-type sections, no data bytes are 
required.
Currently supported format codes are:
• 0 – Fill the output section with zeros
• 1 – Copy each byte of data from the data array
12.3.5
Initialize Bus Matrix Registers
The bus matrix registers (BMXDKPBA, BMXDUDBA, BMXDUPBA) should be initialized by 
the start-up code if any RAM functions exist; otherwise, these registers should not be 
modified. To determine whether any RAM functions exist in the application, the linker 
provides a variable that contains the length of the .ramfunc section
1
. This variable is 
named _ramfunc_length. In addition, the linker provides a 2K-aligned variable 
required for the boundary register (BMXDKPBA). The variable is named 
_bmxdkpba_address
. The default linker script also provides two variables that 
contain the address of the bus matrix registers. These variables are named 
_bmxdkpba_address
, _bmxdudba_address, and _bmxdupba_address. The 
following calculations are used to calculate these addresses:
_bmxdudba_address = LENGTH(${DATA_MEMORY_LOCATION}) ;
_bmxdupba_address = LENGTH(${DATA_MEMORY_LOCATION}) ;
The linker ensures that RAM functions are aligned to a 2K alignment boundary as is 
required by the BMXDKPBA register.
1. All functions attributed with 
__ramfunc__
 or 
__longramfunc__
 are placed in the
.ramfunc
 section.