This chapter contains the following sections:
Introduction
Modules
Modules and Symbols
Sections
Section Names
Absolute Sections
Section Examples
Complex software projects often are divided into smaller program units. These subprograms may be written by a team of programmers in parallel, or they may be programs written for a precious development effort that are going to be reused. The TASKING assembler provides directives to subdivide a program into smaller parts, modules. Symbols can be defined local to a module, so that symbol names can be used without regard to the symbols in other modules. Code and data can be organized in separate sections. These sections can be named in such a way that different modules can implement different parts of these sections. These sections can be located in memory by the locator so that concerns about memory placement are postponed until after the assembly process. By using separate modules, a module can be changed without re-assembling the other modules. This speeds up the turnaround time during the development process.
Modules are the separate implementation parts of a project. Each module is defined in a separate file. A module is assembled separately from other modules. By using the .INCLUDE directive common definitions and macros can be included in each module. Using the mktri utility the module file and include file dependencies can be specified so only the correct modules are re-assembled after changes to one of the files the modules depend upon.
A module can use symbols defined in other modules and in the module itself. Symbols defined in a module can be local (other modules cannot access it) or global (other modules have access to it). Symbols outside of a module can be defined with the .EXTERN directive. Local symbols are symbols defined by the .LOCAL directive or symbols defined with an .SET or .EQU directive. Global symbols are either labels, or symbols explicitly defined global with the .GLOBAL directive.
Sections are relocatable blocks of code and data. Sections are defined with the .SDECL directive and have a name. A section may have attributes to instruct the locator to place it on a predefined starting address, in short or non-short memory or that it may be overlaid with another section. See the .SDECL directive discussion for a complete description of all possible attributes. Sections are defined once and are activated with the .SECT directive. The linker will check between different modules and emits an error message if the section attributes do not match. The linker will also concatenate all matching section definitions into one section. So, all ".text" sections generated by the compiler will be linked into one big ".text" chunk which will be located in one piece. By using this naming scheme it is possible to collect all pieces of code or data belonging together into one bigger section during the linking phase. A .SECT directive referring to an earlier defined section is called a continuation. Only the name can be specified.
The assembler generates object files in relocatable IEEE-695 object format. The assembler groups units of code and data in the object file using sections. All relocatable information is related to the start address of a section. The locator assigns absolute addresses to sections. A section is the smallest unit of code or data that can be moved to a specific address in memory after assembling a source file. The compiler requires that the assembler supports several different sections with appropriate attributes to assign specific characteristics to those sections. (section with read only data, sections with code etc.)
A section must be declared before it can be used. The .SDECL directive declares a section with its attributes. A section name can be any identifier. The '@' character is not allowed in regular section names. The assembler and linker use this character to create overlayable sections. This is explained below.
The section type can be:
This defines in what memory (CODE or DATA) the section is located.
The section attributes can be:
attrib : ABS24 direct addressable code memory
(astri only)
ABS18 direct addressable data memory (astri only)
FPI addressable through FPI bus (aspcp only)
CLEAR clear section during program startup
NOCLEAR section is not cleared during startup
INIT initialization data copied from ROM
to RAM at startup
MAX common, overlay with other parts with
the same name, is implicit a type of
'noclear'
ROMDATA section contains data instead of
executable code
The ABS24 and ABS18 attributes specify direct addressable CODE or DATA memory for the astri assembler. FPI is only valid for the aspcp assembler; this attribute specifies that a section must be accessed through the FPI bus. This section will not be located in PCP internal memory, but in TriCore memory.
Unless disabled, the startup code in the toolchain has to clear data sections with the CLEAR attribute. These sections contain data space allocations for which no initializers have been specified. CLEAR sections are zeroed (cleared) at program startup. Sections can be excluded from this initialization with the NOCLEAR attribute. This is also the default situation for all sections.
The MAX attribute changes the way the linker determines the section size. Normally the linker determines the section size by accumulating the contents and the sizes of sections with the same name in different object modules. When sections with the same name occur in different object modules with the MAX attribute, the linker generates a section of which the size is the maximum of the sizes in the individual object modules.
It is also possible to control the size of MAX sections on a module basis, with the section activation attribute RESET. The assembler starts recounting storage allocation for MAX sections with the same name, when they are re-activated with the RESET section activation attribute. For these sections the assembler generates the maximum size they occupy in the object file. The section activation attribute RESET applies to MAX sections only. Example:
.SDECL ".newdat", DATA, MAX ;section declaration .SECT ".newdat" ;section activation ... .SECT ".newdat", RESET ;section re-activation
Sections become absolute when an address has been specified in the declaration using the AT keyword. The assembler generates information in the object file which instructs the locator to put the section contents at the specified address. It is not allowed to make an overlayable section absolute. The assembler reports an error if the AT keyword is used in combination with the OVERLAY section attribute.
After a section has been declared, it can be activated and re-activated with the .SECT directive:
.SDECL ".STRING", CODE, ROMDATA .SECT ".STRING" _l001: .ASCII "hello world"
All instructions and pseudos which generate data or code must be within an active section. The assembler emits a warning if code or data starts without a section definition and activation.
Absolute sections (i.e. .SDECL directives with a start address) may only be continued in the defining module (continuation). When such a section is defined in the same manner in another module, the locator will try to place the two sections at the same address. This results in a locator error. When an absolute section is defined in more than one module, the section must be defined relocatable and its starting address must be defined in the locator description (.dsc) file. Overlay sections may not be defined absolute.
Some examples of the .SDECL and .SECT directives are as follows:
.SDECL ".CONST", CODE AT 0x1000 .SECT ".CONST"
.SECT ".CONST"
.SDECL ".text", CODE .SECT ".text"
.SDECL ".fardata", DATA, CLEAR .SECT ".fardata"
.SECT ".fardata"