31.12.2013 Views

Linkage Kit Manual V6-00 - Fujitsu

Linkage Kit Manual V6-00 - Fujitsu

Linkage Kit Manual V6-00 - Fujitsu

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 8 LINKER RESTRICTIONS AND Q&A<br />

● Handling variables with initial values<br />

Q. When developing embedded programs using C/C++ compilers, variables with initial<br />

values are created. Since these variables are rewritten during execution of programs, they<br />

must be on RAM during execution. Tell us the procedure for creating programs and<br />

precautions.<br />

A. In embedded programs, variables with initial values are on ROM first and they must be on<br />

RAM when they are referred. Therefore, programs become inoperable if the reference<br />

address in programs is not set to RAM and a mechanism to transfer initial value data from<br />

ROM to RAM before application execution is not implemented.<br />

This mechanism is implemented by using the ROM -> RAM transfer section function<br />

supported by the linker.<br />

Variables with initial values generated by the C/C++ compilers are gathered in the INIT<br />

section.<br />

There is no need of particular care when creating programs except the total number of<br />

bytes of the variables with initial values and RAM size.<br />

For the ROM > RAM transfer section function, see Section "5.9 Sections to be<br />

Transferred from ROM to RAM".<br />

The user must write a program to transfer initial value data using assembler languages.<br />

Example shows "Program example for transferring initial value data".<br />

Example<br />

[Program example for transferring initial value data :(data transfer in two bytes)]<br />

.import _ROM_INIT, _RAM_INIT ...... (1)<br />

.section INIT,data,align=4 ...... (2)<br />

.section start,code,align=2<br />

LDI # (size of INIT + 1) & ~0x1, R13<br />

CMP #0, R13<br />

BEQ NOT_INIT<br />

LDI #_ROM_INIT,R2<br />

LDI #_RAM_INIT,R3<br />

LOOP:<br />

ADD #-2, R13<br />

LDUH @ (R13, R2), R0<br />

BGT:D LOOP<br />

STH R0, @ (R13, R3)<br />

NOT INIT:<br />

(1) ROM_INIT is a symbol to indicate the start address of the INIT section (transfer<br />

source) on ROM. _RAM_INIT is a symbol to indicate the start address of the INIT<br />

section (transfer destination) on RAM. These symbols are generated automatically by<br />

the sections to be transferred from ROM to RAM. Declare them using the .import<br />

instruction.<br />

(2) Define an INIT section to extract the section size (transfer size).<br />

202 PART II LINKER

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!