Texas Instruments MSP430 Optimizing C/C++ Compiler v 3.2 Development Tools User's Guide
Hirdetés
Hirdetés
MSP430 Optimizing C/C++ Compiler v 3.2
User's Guide
Literature Number: SLAU132D
June 2009
2 SLAU132D – June 2009
Submit Documentation Feedback
Contents
2
2.1
2.2
2.3
1
1.1
1.2
Introduction to the Software Development Tools
..........................................................
Software Development Tools Overview
.................................................................................
1.2.1
................................................................................................
...............................................................................................
1.2.2
Output Files
1.2.3
.................................................................................................
1.2.4
2.4
2.5
2.6
2.7
Using the C/C++ Compiler
.........................................................................................
.............................................................................................
Changing the Compiler's Behavior With Options
......................................................................
2.3.1
Frequently Used Options
.........................................................................................
2.3.2
Function-Specific Command Line Options (--beginopts/--endopts)
.........................................
2.3.3
........................................................................................
2.3.4
Symbolic Debugging and Profiling Options
....................................................................
2.3.5
.............................................................................................
2.3.6
Changing How the Compiler Interprets Filenames
...........................................................
2.3.7
Changing How the Compiler Processes C Files
..............................................................
2.3.8
Changing How the Compiler Interprets and Names Extensions
............................................
2.3.9
Specifying Directories
.............................................................................................
2.3.10
Assembler Options
...............................................................................................
2.3.11
Deprecated Options
..............................................................................................
Controlling the Compiler Through Environment Variables
............................................................
2.4.1
Setting Default Compiler Options (MSP430_C_OPTION)
...................................................
2.4.2
Naming an Alternate Directory (MSP430_C_DIR)
............................................................
Precompiled Header Support
.............................................................................................
2.5.1
.................................................................................
2.5.2
Manual Precompiled Header
....................................................................................
2.5.3
Additional Precompiled Header Options
.......................................................................
Controlling the Preprocessor
.............................................................................................
2.6.1
Predefined Macro Names
........................................................................................
2.6.2
The Search Path for #include Files
.............................................................................
2.6.3
Generating a Preprocessed Listing File (--preproc_only Option)
...........................................
2.6.4
Continuing Compilation After Preprocessing (--preproc_with_compile Option)
2.6.5
Generating a Preprocessed Listing File With Comments (--preproc_with_comments Option)
2.6.6
Generating a Preprocessed Listing File With Line-Control Information (--preproc_with_line Option)
2.6.7
Generating Preprocessed Output for a Make Utility (--preproc_dependency Option)
2.6.8
Generating a List of Files Included With the #include Directive (--preproc_includes Option)
2.6.9
Generating a List of Macros in a File (--preproc_macros Option)
..........................................
Understanding Diagnostic Messages
....................................................................................
SLAU132D – June 2009
Submit Documentation Feedback
Contents
3
4
3.5
3.6
3.7
3.8
3.9
www.ti.com
2.7.1
...........................................................................................
2.7.2
How You Can Use Diagnostic Suppression Options
.........................................................
2.8
2.9
Generating Cross-Reference Listing Information (--gen_acp_xref Option)
.........................................
2.10
Generating a Raw Listing File (--gen_acp_raw Option)
...............................................................
2.11
Using Inline Function Expansion
.........................................................................................
2.11.1
Inlining Intrinsic Operators
......................................................................................
2.11.2
Using the inline Keyword, the --no_inlining Option, and Level 3 Optimization
2.12
Using Interlist
2.13
Enabling Entry Hook and Exit Hook Functions
.........................................................................
3
3.1
3.2
3.3
3.4
4
4.1
4.2
4.3
4.4
Optimizing Your Code
...............................................................................................
Performing File-Level Optimization (--opt_level=3 option)
............................................................
3.2.1
Controlling File-Level Optimization (--std_lib_func_def Options)
...........................................
3.2.2
Creating an Optimization Information File (--gen_opt_info Option)
.........................................
Performing Program-Level Optimization (--program_level_compile and --opt_level=3 options)
3.3.1
Controlling Program-Level Optimization (--call_assumptions Option)
......................................
3.3.2
Optimization Considerations When Mixing C/C++ and Assembly
..........................................
Accessing Aliased Variables in Optimized Code
.......................................................................
3.4.1
Use Caution With asm Statements in Optimized Code
......................................................
Automatic Inline Expansion (--auto_inline Option)
.....................................................................
Using the Interlist Feature With Optimization
...........................................................................
...............................................................................................
Controlling Code Size Versus Speed
...................................................................................
What Kind of Optimization Is Being Performed?
.......................................................................
3.9.1
Cost-Based Register Allocation
.................................................................................
3.9.2
..............................................................................................
3.9.3
Branch Optimizations and Control-Flow Simplification
.......................................................
3.9.4
Data Flow Optimizations
.........................................................................................
3.9.5
.........................................................................................
3.9.6
...................................................................................
3.9.7
Induction Variables and Strength Reduction
..................................................................
3.9.8
.....................................................................................
3.9.9
3.9.10
...........................................................................................
3.9.11
Tail Merging
3.9.12
Integer Division With Constant Divisor
........................................................................
3.9.13
.......................................................................................
Linking C/C++ Code
..................................................................................................
Invoking the Linker Through the Compiler (-z Option)
................................................................
4.1.1
Invoking the Linker Separately
..................................................................................
4.1.2
Invoking the Linker as Part of the Compile Step
..............................................................
4.1.3
Disabling the Linker (--compile_only Compiler Option)
......................................................
Linker Code Optimizations
................................................................................................
4.3.1
Generate List of Dead Functions (--generate_dead_funcs_list Option)
....................................
4.3.2
Generating Function Subsections (--gen_func_subsections Compiler Option)
Controlling the Linking Process
..........................................................................................
Contents
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
4.4.1
Including the Run-Time-Support Library
.......................................................................
4.4.2
Run-Time Initialization
............................................................................................
4.4.3
Initialization by the Interrupt Vector
.............................................................................
4.4.4
Global Object Constructors
......................................................................................
4.4.5
Specifying the Type of Global Variable Initialization
..........................................................
4.4.6
Specifying Where to Allocate Sections in Memory
4.4.7
A Sample Linker Command File
...........................................................
................................................................................
5
5.1
5.2
5.3
5.4
5.5
5.6
5.7
5.8
MSP430 C/C++ Language Implementation
...................................................................
Characteristics of MSP430 C
.............................................................................................
Characteristics of MSP430 C++
..........................................................................................
5.4.1
................................................................................................
5.4.2
............................................................................................
5.4.3
..............................................................................................
5.4.4
The volatile Keyword
..............................................................................................
...................................................................................................
Register Variables and Parameters
......................................................................................
5.8.1
......................................................................................
5.8.2
..................................................................................
5.8.3
The DATA_ALIGN Pragma
......................................................................................
5.8.4
..................................................................................
5.8.5
The Diagnostic Message Pragmas
.............................................................................
5.8.6
The FUNC_CANNOT_INLINE Pragma
........................................................................
5.8.7
The FUNC_EXT_CALLED Pragma
.............................................................................
5.8.8
...................................................................................
5.8.9
The FUNC_NEVER_RETURNS Pragma
......................................................................
5.8.10
The FUNC_NO_GLOBAL_ASG Pragma
.....................................................................
5.8.11
The FUNC_NO_IND_ASG Pragma
............................................................................
5.8.12
.......................................................................................
5.9
5.8.13
The vector Pragma
...............................................................................................
....................................................................................................
5.10
Generating Linknames
5.11
Initializing Static and Global Variables
..................................................................................
5.11.1
Initializing Static and Global Variables With the Linker
.....................................................
5.11.2
Initializing Static and Global Variables With the const Type Qualifier
.....................................
5.12
Changing the ANSI/ISO C Language Mode
............................................................................
5.12.1
Compatibility With K&R C (--kr_compatible Option)
.........................................................
5.12.2
Enabling Strict ANSI/ISO Mode and Relaxed ANSI/ISO Mode (--strict_ansi and --relaxed_ansi
5.12.3
Enabling Embedded C++ Mode (--embedded_cpp Option)
................................................
5.13
GNU C Compiler Extensions
5.13.1
.............................................................................................
...............................................................................................
5.13.2
Built-In Functions
.................................................................................................
5.14
6 Run-Time Environment
.............................................................................................
SLAU132D – June 2009
Submit Documentation Feedback
Contents
5
6
6.1
6.2
6.3
6.4
6.5
6.6
6.7
6.8
6.9
7
7.1
7.2
www.ti.com
6.1.1
Large-Code Memory Model
.....................................................................................
6.1.2
Large-Data Memory Model
6.1.3
Sections
......................................................................................
6.1.4
C/C++ Software Stack
............................................................................................
6.1.5
Dynamic Memory Allocation
.....................................................................................
6.1.6
..........................................................................................
6.2.1
Data Type Storage
................................................................................................
6.2.2
......................................................................................
Function Structure and Calling Conventions
..........................................................................
6.4.1
How a Function Makes a Call
..................................................................................
6.4.2
How a Called Function Responds
.............................................................................
6.4.3
Accessing Arguments and Local Variables
...................................................................
Interfacing C and C++ With Assembly Language
....................................................................
6.5.1
Using Assembly Language Modules With C/C++ Code
....................................................
6.5.2
Accessing Assembly Language Variables From C/C++
....................................................
6.5.3
Sharing C/C++ Header Files With Assembly Source
.......................................................
6.5.4
Using Inline Assembly Language
..............................................................................
6.6.1
Saving Registers During Interrupts
............................................................................
6.6.2
Using C/C++ Interrupt Routines
...............................................................................
6.6.3
Using Assembly Language Interrupt Routines
...............................................................
6.6.4
Interrupt Vectors
.................................................................................................
6.6.5
Other Interrupt Information
.....................................................................................
Using Intrinsics to Access Assembly Language Statements
........................................................
6.7.1
MSP430 Intrinsics
...............................................................................................
6.7.2
.....................................................................................
6.7.3
.................................................................................
6.8.1
System Pre-Initialization
........................................................................................
6.8.2
Run-Time Stack
..................................................................................................
6.8.3
Automatic Initialization of Variables
...........................................................................
6.8.4
Initialization Tables
..............................................................................................
6.8.5
Autoinitialization of Variables at Run Time
...................................................................
6.8.6
Initialization of Variables at Load Time
.......................................................................
6.8.7
.............................................................................................
Compiling for 20-Bit MSP430X Devices
...............................................................................
Using Run-Time-Support Functions and Building Libraries
C and C++ Run-Time Support Libraries
.........................................
...............................................................................
7.1.1
Linking Code With the Object Library
.........................................................................
7.1.2
Header Files
7.1.3
...................................................................................
7.1.4
Changes to the Run-Time-Support Libraries
.................................................................
Run-Time-Support Function Libraries
..................................................................................
7.2.1
Linking Code With the Object Library
.........................................................................
7.2.2
Nonstandard Header Files in rtssrc.zip
.......................................................................
Contents
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
8
8.1
8.2
8.3
7.3
7.4
7.5
7.6
A
7.2.3
...................................................................................
The C I/O Functions
7.3.1
Overview of Low-Level I/O Implementation
..................................................................
7.3.2
......................................................................................
Handling Reentrancy (_register_lock() and _register_unlock() Functions)
........................................
7.5.1
Required Non-Texas Instruments Software
..................................................................
7.5.2
Using the Library-Build Process
7.5.3
Library Naming Conventions
...............................................................................
...................................................................................
MSP430 Run-Time Library Details
.....................................................................................
7.6.1
Library Names
....................................................................................................
7.6.2
Header Files
C++ Name Demangler
..............................................................................................
Invoking the C++ Name Demangler
....................................................................................
.........................................................................................
Sample Usage of the C++ Name Demangler
.........................................................................
Glossary
SLAU132D – June 2009
Submit Documentation Feedback
Contents
7
1-1
6-1
6-2
6-3
6-4
6-5
7-1
7-2 www.ti.com
List of Figures
MSP430 Software Development Flow
...................................................................................
Format of Initialization Records in the .cinit Section
.................................................................
Format of Initialization Records in the .pinit Section
Autoinitialization at Run Time
.................................................................
...........................................................................................
Initialization at Load Time
...............................................................................................
Interaction of Data Structures in I/O Functions
The First Three Streams in the Stream Table
.......................................................................
........................................................................
List of Tables
2-1
2-2
2-3
2-4
2-5
2-6
2-7
2-8
2-9
5-4
6-1
6-2
6-3
6-4
6-5
Options That Control the Compiler
......................................................................................
Options That Control Symbolic Debugging and Profiling
Options That Change the Default File Extensions
.............................................................
.....................................................................
................................................................................................
Options That Specify Directories
.........................................................................................
Options That Are Machine-Specific
......................................................................................
..............................................................................................
Options That Control Parsing
.............................................................................................
Options That Control Preprocessing
.....................................................................................
2-10 Options That Control Diagnostics in Both Compiler and Linker
......................................................
2-11
Options That Control Optimization
.......................................................................................
2-12 Options That Control the Assembler
.....................................................................................
2-13 Options That Control the Linker
..........................................................................................
2-14
Compiler Backwards-Compatibility Options Summary
2-15
................................................................
......................................................................................
2-16
................................................................................................
2-17
Raw Listing File Diagnostic Identifiers
...................................................................................
3-1
3-2
3-3
3-4
3-5
4-1
Options That You Can Use With --opt_level=3
.........................................................................
Selecting a File-Level Optimization Option
.............................................................................
Selecting a Level for the --gen_opt_info Option
........................................................................
Selecting a Level for the --call_assumptions Option
...................................................................
Special Considerations When Using the --call_assumptions Option
................................................
Initialized Sections Created by the Compiler
...........................................................................
4-2
5-1
5-2
5-3
Uninitialized Sections Created by the Compiler
........................................................................
..............................................................................................
...............................................................................................
TI-Supported GCC Function Attributes
..................................................................................
TI-Supported GCC Built-In Functions
....................................................................................
Summary of Sections and Memory Placement
.........................................................................
Data Representation in Registers and Memory
.......................................................................
How Register Types Are Affected by the Conventions
................................................................
Register Usage and Preservation Conventions
.......................................................................
MSP430 Intrinsics
8
List of Figures
SLAU132D – June 2009
Submit Documentation Feedback
Preface
SLAU132D – June 2009
Read This First
About This Manual
The MSP430 Optimizing C/C++ Compiler User's Guide explains how to use these compiler tools:
•
Compiler
•
Library-build process
•
C++ name demangler
The C/C++ compiler accepts C and C++ code conforming to the International Organization for
Standardization (ISO) standards for these languages. The compiler supports the 1989 version of the C language and the 1998 version of the C++ language.
This user's guide discusses the characteristics of the C/C++ compiler. It assumes that you already know how to write C programs. The C Programming Language (second edition), by Brian W. Kernighan and
Dennis M. Ritchie, describes C based on the ISO C standard. You can use the Kernighan and Ritchie
(hereafter referred to as K&R) book as a supplement to this manual. References to K&R C (as opposed to
ISO C) in this manual refer to the C language as defined in the first edition of Kernighan and Ritchie's The
C Programming Language.
Notational Conventions
This document uses the following conventions:
•
Program listings, program examples, and interactive displays are shown in a special typeface
.
Interactive displays use a bold version of the special typeface to distinguish commands that you enter from items that the system displays (such as prompts, command output, error messages, etc.).
Here is a sample of C code:
#include <stdio.h> main() {printf("hello, cruel world\n");}
•
In syntax descriptions, the instruction, command, or directive is in a bold typeface and parameters are in an italic typeface. Portions of a syntax that are in bold should be entered as shown; portions of a syntax that are in italics describe the type of information that should be entered.
•
Square brackets ( [ and ] ) identify an optional parameter. If you use an optional parameter, you specify the information within the brackets. Unless the square brackets are in the bold typeface, do not enter the brackets themselves. The following is an example of a command that has an optional parameter:
cl430 [options] [filenames] [--run_linker [link_options] [object files]]
•
Braces ( { and } ) indicate that you must choose one of the parameters within the braces; you do not enter the braces themselves. This is an example of a command with braces that are not included in the actual syntax but indicate that you must specify either the --rom_model or --ram_model option:
cl430 --run_linker
{--rom_model | --ram_model} filenames [--output_file=name.out]
--library= libraryname
SLAU132D – June 2009
Submit Documentation Feedback
Read This First
9
Related Documentation
www.ti.com
•
In assembler syntax statements, column 1 is reserved for the first character of a label or symbol. If the label or symbol is optional, it is usually not shown. If it is a required parameter, it is shown starting against the left margin of the box, as in the example below. No instruction, command, directive, or parameter, other than a symbol or label, can begin in column 1.
symbol .usect "section name", size in bytes[, alignment]
•
Some directives can have a varying number of parameters. For example, the .byte directive can have up to 100 parameters. This syntax is shown as [, ..., parameter].
Related Documentation
You can use the following books to supplement this user's guide:
ANSI X3.159-1989, Programming Language - C (Alternate version of the 1989 C Standard), American
National Standards Institute
C: A Reference Manual (fourth edition), by Samuel P. Harbison, and Guy L. Steele Jr., published by
Prentice Hall, Englewood Cliffs, New Jersey
DWARF Debugging Information Format Version 3, DWARF Debugging Information Format Workgroup,
Free Standards Group, 2005 ( http://dwarfstd.org
)
ISO/IEC 14882-1998, International Standard - Programming Languages - C++ (The C++ Standard),
International Organization for Standardization
ISO/IEC 9899:1989, International Standard - Programming Languages - C (The 1989 C Standard),
International Organization for Standardization
ISO/IEC 9899:1999, International Standard - Programming Languages - C (The C Standard),
International Organization for Standardization
Programming Embedded Systems in C and C++, by Michael Barr, Andy Oram (Editor), published by
O'Reilly & Associates; ISBN: 1565923545, February 1999
Programming in C, Steve G. Kochan, Hayden Book Company
The Annotated C++ Reference Manual, Margaret A. Ellis and Bjame Stroustrup, published by
Addison-Wesley Publishing Company, Reading, Massachusetts, 1990
The C Programming Language (second edition), by Brian W. Kernighan and Dennis M. Ritchie, published by Prentice-Hall, Englewood Cliffs, New Jersey, 1988
The C++ Programming Language (second edition), Bjame Stroustrup, published by Addison-Wesley
Publishing Company, Reading, Massachusetts, 1990
Tool Interface Standards (TIS) DWARF Debugging Information Format Specification Version 2.0,
TIS Committee, 1995
10
Read This First
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Related Documentation From Texas Instruments
Related Documentation From Texas Instruments
You can use the following books to supplement this user's guide:
SLAU012
— MSP430x3xx Family User's Guide. Describes the MSP430x3xx™ CPU architecture, instruction set, pipeline, and interrupts for these ultra-low power microcontrollers.
SLAU049
— MSP430x1xx Family User's Guide. Describes the MSP430x1xx™ CPU architecture, instruction set, pipeline, and interrupts for these ultra-low power microcontrollers.
SLAU056
— MSP430x4xx Family User's Guide. Describes the MSP430x4xx™ CPU architecture, instruction set, pipeline, and interrupts for these ultra-low power microcontrollers.
SLAU132
— MSP430 Assembly Language Tools User's Guide. Describes the assembly language tools
(the assembler, linker, and other tools used to develop assembly language code), assembler directives, macros, object file format, and symbolic debugging directives for the MSP430 devices.
SLAU134
— MSP430FE42x ESP30CE1 Peripheral Module User's Guide. Describes common peripherals available on the MSP430FE42x and ESP430CE1 ultra-low power microcontrollers. This book includes information on the setup, operation, and registers of the ESP430CE1.
SLAU208
— MSP430x5xx Family User's Guide. Describes the MSP430x5xx™ CPU architecture, instruction set, pipeline, and interrupts for these ultra-low power microcontrollers.
SLAU144
— MSP430x2xx Family User's Guide. Describes the MSP430x2xx™ CPU architecture, instruction set, pipeline, and interrupts for these ultra-low power microcontrollers.
Trademarks
MSP430x3xx, MSP430x1xx, MSP430x4xx, MSP430x5xx, MSP430x2xx are trademarks of Texas
Instruments.
Windows is a registered trademark of Microsoft Corporation.
UNIX is a registered trademark of licensed exclusively through X/Open Company Limited.
SLAU132D – June 2009
Submit Documentation Feedback
Read This First
11
12
Read This First
SLAU132D – June 2009
Submit Documentation Feedback
Chapter 1
SLAU132D – June 2009
Introduction to the Software Development Tools
The MSP430 is supported by a set of software development tools, which includes an optimizing C/C++ compiler, an assembler, a linker, and assorted utilities.
This chapter provides an overview of these tools and introduces the features of the optimizing C/C++ compiler. The assembler and linker are discussed in detail in the MSP430 Assembly Language Tools
User's Guide.
Topic
..................................................................................................
Page
1.1
Software Development Tools Overview
........................................
1.2
..........................................................
SLAU132D – June 2009
Submit Documentation Feedback
Introduction to the Software Development Tools
13
Software Development Tools Overview
www.ti.com
1.1
Software Development Tools Overview
illustrates the software development flow. The shaded portion of the figure highlights the most common path of software development for C language programs. The other portions are peripheral functions that enhance the development process.
Figure 1-1. MSP430 Software Development Flow
C/C++ source files
Macro source files
C/C++ compiler
Archiver
Assembler source
C/C++ name demangling utility
Macro library
Assembler
Archiver
Library of object files
Object files
Linker
Library-build process
Run-timesupport library
Debugging tools
Executable object file
Hex-conversion utility
EPROM programmer
Absolute lister
Cross-reference lister
Object file utilities
MSP430
14
Introduction to the Software Development Tools
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
C/C++ Compiler Overview
The following list describes the tools that are shown in
•
The compiler accepts C/C++ source code and produces MSP430 assembly language source code.
See
•
The assembler translates assembly language source files into machine language object modules. The
MSP430 Assembly Language Tools User's Guide explains how to use the assembler.
•
The linker combines object files into a single executable object module. As it creates the executable module, it performs relocation and resolves external references. The linker accepts relocatable object files and object libraries as input. See
Chapter 4 . The MSP430 Assembly Language Tools User's
Guide provides a complete description of the linker.
•
The archiver allows you to collect a group of files into a single archive file, called a library.
Additionally, the archiver allows you to modify a library by deleting, replacing, extracting, or adding members. One of the most useful applications of the archiver is building a library of object modules.
The MSP430 Assembly Language Tools User's Guide explains how to use the archiver.
•
You can use the library-build process to build your own customized run-time-support library. See
. Standard run-time-support library functions for C and C++ are provided in the
self-contained rtssrc.zip file.
The run-time-support libraries contain the standard ISO run-time-support functions, compiler-utility functions, floating-point arithmetic functions, and C I/O functions that are supported by the compiler.
See
•
The hex conversion utility converts an object file into other object formats. You can download the converted file to an EPROM programmer. The MSP430 Assembly Language Tools User's Guide explains how to use the hex conversion utility and describes all supported formats.
•
The absolute lister accepts linked object files as input and creates .abs files as output. You can assemble these .abs files to produce a listing that contains absolute, rather than relative, addresses.
Without the absolute lister, producing such a listing would be tedious and would require many manual operations. The MSP430 Assembly Language Tools User's Guide explains how to use the absolute lister.
•
The cross-reference lister uses object files to produce a cross-reference listing showing symbols, their definitions, and their references in the linked source files. The MSP430 Assembly Language Tools
User's Guide explains how to use the cross-reference utility.
•
The C++ name demangler is a debugging aid that converts names mangled by the compiler back to their original names as declared in the C++ source code. As shown in
Figure 1-1 , you can use the C++
name demangler on the assembly file that is output by the compiler; you can also use this utility on the assembler listing file and the linker map file. See
•
The disassembler disassembles object files. The MSP430 Assembly Language Tools User's Guide explains how to use the disassembler.
•
The main product of this development process is a module that can be executed in a MSP430 device.
1.2
C/C++ Compiler Overview
The following subsections describe the key features of the compiler.
1.2.1 ANSI/ISO Standard
These features pertain to ISO standards:
•
ISO-standard C
The C/C++ compiler fully conforms to the ISO C standard as defined by the ISO specification and described in the second edition of Kernighan and Ritchie's The C Programming Language (K&R). The
ISO C standard supercedes and is the same as the ANSI C standard.
•
ISO-standard C++
The C/C++ compiler supports C++ as defined by the ISO C++ Standard and described in Ellis and
Stroustrup's The Annotated C++ Reference Manual (ARM). The compiler also supports embedded
C++. For a description of unsupported C++ features, see
•
ISO-standard run-time support
The compiler tools come with a complete run-time library. All library functions conform to the ISO
C/C++ library standard. The library includes functions for standard input and output, string
SLAU132D – June 2009
Submit Documentation Feedback
Introduction to the Software Development Tools
15
C/C++ Compiler Overview
www.ti.com
manipulation, dynamic memory allocation, data conversion, timekeeping, trigonometry, and exponential and hyperbolic functions. Functions for signal handling are not included, because these are target-system specific. The library includes the ISO C subset as well as those components necessary for language support. For more information, see
1.2.2 Output Files
These features pertain to output files created by the compiler:
•
COFF object files
Common object file format (COFF) allows you to define your system's memory map at link time. This maximizes performance by enabling you to link C/C++ code and data objects into specific memory areas. COFF also supports source-level debugging.
•
EPROM programmer data files
For stand-alone embedded applications, the compiler has the ability to place all code and initialization data into ROM, allowing C/C++ code to run from reset. The COFF files output by the compiler can be converted to EPROM programmer data files by using the hex conversion utility, as described in the
MSP430 Assembly Language Tools User's Guide.
1.2.3 Compiler Interface
These features pertain to interfacing with the compiler:
•
Compiler program
The compiler tools include a compiler program that you use to compile, optimize, assemble, and link programs in a single step. For more information, see
•
Flexible assembly language interface
The compiler has straightforward calling conventions, so you can write assembly and C functions that call each other. For more information, see
1.2.4 Utilities
These features pertain to the compiler utilities:
•
Library-build process
The library-build process lets you custom-build object libraries from source for any combination of run-time models. For more information, see
•
C++ name demangler
The C++ name demangler (dem430) is a debugging aid that translates each mangled name it detects to its original name found in the C++ source code. For more information, see
.
16
Introduction to the Software Development Tools
SLAU132D – June 2009
Submit Documentation Feedback
Chapter 2
SLAU132D – June 2009
Using the C/C++ Compiler
The compiler translates your source program into code that the MSP430 can execute. Source code must be compiled, assembled, and linked to create an executable object file. All of these steps are executed at once by using the compiler.
Topic
..................................................................................................
Page
2.1
About the Compiler
...................................................................
2.2
......................................................
2.3
Changing the Compiler's Behavior With Options
2.4
Controlling the Compiler Through Environment Variables
2.5
......................................................
2.6
.....................................................
2.7
Understanding Diagnostic Messages
..........................................
2.8
........................................................................
2.9
Generating Cross-Reference Listing Information (--gen_acp_xref
....................................................................................
2.10
Generating a Raw Listing File (--gen_acp_raw Option)
2.11
Using Inline Function Expansion
................................................
2.12
...........................................................................
2.13
Enabling Entry Hook and Exit Hook Functions
SLAU132D – June 2009
Submit Documentation Feedback
Using the C/C++ Compiler
17
About the Compiler
www.ti.com
2.1
About the Compiler
The compiler lets you compile, assemble, and optionally link in one step. The compiler performs the following steps on one or more source modules:
•
The compiler accepts C/C++ source code and assembly code, and produces object code.
You can compile C, C++, and assembly files in a single command. The compiler uses the filename extensions to distinguish between different file types. See
for more information.
•
The linker combines object files to create an executable object file. The linker is optional, so you can compile and assemble many modules independently and link them later. See
for information about linking the files.
By default, the compiler does not invoke the linker. You can invoke the linker by using the --run_linker compiler option.
For a complete description of the assembler and the linker, see the MSP430 Assembly Language Tools
User's Guide.
2.2
Invoking the C/C++ Compiler
To invoke the compiler, enter:
cl430 [options] [filenames] [--run_linker [link_options] object files]]
cl430
options filenames
--run_linker
link_options object files
Command that runs the compiler and the assembler.
Options that affect the way the compiler processes input files. The options are listed in
through
.
One or more C/C++ source files, assembly language source files, linear assembly files, or object files.
Option that invokes the linker. The --run_linker option's short form is -z. See
for more information.
Options that control the linking process.
Name of the additional object files for the linking process.
The arguments to the compiler are of three types:
•
Compiler options
•
Link options
•
Filenames
The --run_linker option indicates linking is to be performed. If the --run_linker option is used, any compiler options must precede the --run_linker option, and all link options must follow the --run_linker option.
Source code filenames must be placed before the --run_linker option. Additional object file filenames can be placed after the --run_linker option.
For example, if you want to compile two files named symtab.c and file.c, assemble a third file named seek.asm, and link to create an executable program called myprogram.out, you will enter: cl430 symtab.c file.c seek.asm --run_linker --library=lnk.cmd
--library=rts430.lib --output_file=myprogram.out
18
Using the C/C++ Compiler
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Changing the Compiler's Behavior With Options
2.3
Changing the Compiler's Behavior With Options
Options control the operation of the compiler. This section provides a description of option conventions and an option summary table. It also provides detailed descriptions of the most frequently used options, including options used for type-checking and assembling.
For an online summary of the options, enter cl430 with no parameters on the command line.
The following apply to the compiler options:
•
Options are preceded by one or two hyphens.
•
Options are case sensitive.
•
Options are either single letters or sequences of characters.
•
Individual options cannot be combined.
•
An option with a required parameter should be specified with an equal sign before the parameter to clearly associate the parameter with the option. For example, the option to undefine a constant can be expressed as --undefine=name. Although not recommended, you can separate the option and the parameter with or without a space, as in --undefine name or -undefinename.
•
An option with an optional parameter should be specified with an equal sign before the parameter to clearly associate the parameter with the option. For example, the option to specify the maximum amount of optimization can be expressed as -O=3. Although not recommended, you can specify the parameter directly after the option, as in -O3. No space is allowed between the option and the optional parameter, so -O 3 is not accepted.
•
Files and options except the --run_linker option can occur in any order. The --run_linker option must follow all other compile options and precede any link options.
You can define default options for the compiler by using the MSP430_C_DIR environment variable. For a detailed description of the environment variable, see
.
through
summarize all options (including link options). Use the references in the tables for more complete descriptions of the options.
Option
--beginopts
--c_src_interlist
--cmd_file=filename
Table 2-1. Options That Control the Compiler
Alias
-ss
Effect
Begins function-specific options list
Interlists C source and assembly statements
-@
Section
--compile_only -c
Interprets contents of a file as an extension to the command line.
Multiple -@ instances can be used.
Disables linking (negates --run_linker)
--compiler_revision
--define=name[=def]
--endopts
--gen_func_subsections
--help
--include_path=directory
-D
-h
-I
Prints out the compiler release revision and exits
Predefines name
Ends function-specific options list
Puts each function in a separate subsection in the object file
Prints (on the standard device) a description of the options understood by the compiler.
Defines #include search path
–
--no_const_clink
--keep_asm
--preinclude=filename
--quiet
--run_linker
--skip_assembler
--src_interlist
--undefine=name
-k
-q
-z
-n
-s
-U
Stops generation of .clink directives for const global arrays.
Keeps the assembly language (.asm) file
Includes filename at the beginning of compilation
Suppresses progress messages (quiet)
Enables linking
Compiles or assembly optimizes only
Interlists optimizer comments (if available) and assembly source statements; otherwise interlists C and assembly source statements
Undefines name
SLAU132D – June 2009
Submit Documentation Feedback
Using the C/C++ Compiler
19
Changing the Compiler's Behavior With Options
Option
--verbose
--tool_version
Table 2-1. Options That Control the Compiler (continued)
Alias
-version
Effect
Displays a banner and function progress information
Displays version number for each tool www.ti.com
Section
–
Option
--profle:power
--symdebug:coff
--symdebug:dwarf
Table 2-2. Options That Control Symbolic Debugging and Profiling
Alias
-g
Effect
Enables power profiling
Section
Enables symbolic debugging using the alternate STABS debugging
format.
Enables symbolic debugging
Changes how debug information presents in object file
-symdebug:dwarf_subsections=on|off
--symdebug:none
--symdebug:profile_coff
--symdebug:skeletal
Disables all symbolic debugging
Enables profiling using the alternate STABS debugging format.
Enables minimal symbolic debugging that does not hinder optimizations (default behavior)
Option
--asm_extension=[.]extension
--c_extension=[.]extension
--cpp_extension=[.]extension
--listing_extension=[.]extension
--obj_extension=[.]extension
Table 2-3. Options That Change the Default File Extensions
Alias
-ea
-ec
-ep
-es
-eo
Effect
Sets a default extension for assembly source files
Sets a default extension for C source files
Sets a default extension for C++ source files
Sets a default extension for listing files
Sets a default extension for object files
Option
--asm_file=filename
--c_file=filename
--cpp_default
--cpp_file=filename
--obj_file=filename
Section
Alias
-fa
-fc
-fg
-fp
-fo
Table 2-4. Options That Specify Files
Effect Section
Identifies filename as an assembly source file regardless of its extension. By default, the compiler and assembler treat .asm files as assembly source files.
Identifies filename as a C source file regardless of its extension. By
default, the compiler treats .c files as C source files.
Processes all source files with a C extension as C++ source files.
Identifies filename as a C++ file, regardless of its extension. By default, the compiler treats .C, .cpp, .cc and .cxx files as a C++ files.
Identifies filename as an object code file regardless of its extension.
By default, the compiler and linker treat .obj files as object code files.
Option
--abs_directory=directory
--asm_directory=directory
--list_directory=directory
--obj_directory=directory
--temp_directory=directory
-fr
-ft
Table 2-5. Options That Specify Directories
Alias
-fb
-fs
-ff
Effect
Specifies an absolute listing file directory
Specifies an assembly file directory
Specifies an assembly listing file and cross-reference listing file directory
Specifies an object file directory
Specifies a temporary file directory
Section
20
Using the C/C++ Compiler
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Option
--large_memory_model
––plain_char={signed|unsigned}
––printf_support={full|minimal| nofloat}
––silicon_version={msp|mspx}
––small_enum
Changing the Compiler's Behavior With Options
Table 2-6. Options That Are Machine-Specific
Alias
-ml
-mc
Effect
Uses a large memory model when compiling for the MSP430X
Changes variables of type char from unsigned to signed
Enables support for smaller limited versions of printf.
-v Selects the instruction set
Uses the smallest possible size for the enumeration type
Section
Option
--entry_hook[=name]
--entry_param={name|address| none}
--exit_hook[=name]
--exit_param={name|address|none}
--remove_hooks_when_inlining
Alias
Table 2-7. Options That Control Hooks
Effect
Enables entry hooks
Specifies the parameters to the function to the --entry_hook option
Enables exit hooks
Specifies the parameters to the function to the --exit_hook option
Removes entry/exit hooks for auto-inlined functions
Section
Option
--create_pch=filename
--embedded_cpp
--exceptions
--fp_mode={relaxed|strict}
--fp_reassoc={on|off}
--gcc
--gen_asp_raw
--gen_acp_xref
--kr_compatible
--keep_unneeded_statics
--no_inlining
--no_intrinsics
--multibyte_chars
--pch
--pch_dir=directory
--pch_verbose
--program_level_compile
--relaxed_ansi
--rtti
--static_template_instantiation
--strict_ansi
--use_pch=filename
Alias
Table 2-8. Options That Control Parsing
-pe
-pl
-px
-pk
-pi
-pn
-pc
-pm
-pr
-rtti
-ps
Effect
Creates a precompiled header file with the name specified
Enables embedded C++ mode
Enables C++ exception handling
Enables or disables relaxed floating-point mode
Enables or disables the reassociation of floating-point arithmetic
Enables support for GCC extensions
Generates a raw listing file
Generates a cross-reference listing file
Allows K&R compatibility
Keeps unreferenced static variables.
Disables definition-controlled inlining (but --opt_level=3 (or -O3) optimizations still perform automatic inlining)
Disables intrinsic functions. No predefinition of compiler-supplied intrinsic functions.
Enables multibyte character support.
Creates or uses precompiled header files
Specifies the path where the precompiled header file resides
Displays a message for each precompiled header file that is considered but not used
Combines source files to perform program-level optimization
Enables relaxed mode; ignores strict ISO violations
Enables run time type information (RTTI)
Instantiate all template entities with internal linkage
Enables strict ISO mode (for C/C++, not K&R C)
Specifies the precompiled header file to use for this compilation
Section
-
-
–
–
SLAU132D – June 2009
Submit Documentation Feedback
Using the C/C++ Compiler
21
Changing the Compiler's Behavior With Options
www.ti.com
Option
--preproc_dependency[=filename]
--preproc_includes[=filename]
--preproc_macros[=filename]
--preproc_only
--preproc_with_comments
--preproc_with_compile
--preproc_with_line
Table 2-9. Options That Control Preprocessing
Alias
-ppd
-ppi
-ppm
-ppo
-ppc
-ppa
-ppl
Effect
Performs preprocessing only, but instead of writing preprocessed output, writes a list of dependency lines suitable for input to a standard make utility
Performs preprocessing only, but instead of writing preprocessed output, writes a list of files included with the #include directive
Section
Performs preprocessing only. Writes list of predefined and user-defined macros to a file with the same name as the input but with a .pp extension.
Performs preprocessing only. Writes preprocessed output to a file with the same name as the input but with a .pp extension.
Performs preprocessing only. Writes preprocessed output, keeping
the comments, to a file with the same name as the input but with a
.pp extension.
Continues compilation after preprocessing
Performs preprocessing only. Writes preprocessed output with line-control information (#line directives) to a file with the same name as the input but with a .pp extension.
Table 2-10. Options That Control Diagnostics in Both Compiler and Linker
Option
--diag_error=num
--diag_remark=num
--diag_suppress=num
--diag_warning=num
--display_error_number=num
--issue_remarks
--no_warnings
--set_error_limit=num
--verbose_diagnostics
--write_diagnostics_file
(1)
(1)
Compiler only option.
Alias
-pdse
-pdsr
-pds
-pdsw
-pden
-pdr
-pdw
-pdel
-pdv
Effect
Categorizes the diagnostic identified by num as an error
Categorizes the diagnostic identified by num as a remark
Suppresses the diagnostic identified by num
Categorizes the diagnostic identified by num as a warning
Displays a diagnostic's identifiers along with its text
Issues remarks (nonserious warnings)
Suppresses warning diagnostics (errors are still issued)
Sets the error limit to num. The compiler abandons compiling after this number of errors. (The default is 100.)
Provides verbose diagnostics that display the original source with line-wrap
Generates a diagnostics information file
Section
Option
--aliased_variables
--auto_inline=[size]
--call_assumptions=0
--call_assumptions=1
--call_assumptions=2
--call_assumptions=3
--gen_opt_info=0
--gen_opt_info=1
(1)
Table 2-11. Options That Control Optimization
(1)
Alias
-ma
-oi
-op0
-op1
-op2
-op3
-on0
-on1
Note: Machine-specific options (see
Effect
Assumes variables are aliased
Section
Sets automatic inlining size (--opt_level=3 only). If size is not specified, the default is 1.
Specifies that the module contains functions and variables that are
called or modified from outside the source code provided to the compiler
Specifies that the module contains variables modified from outside
the source code provided to the compiler but does not use functions called from outside the source code
Specifies that the module contains no functions or variables that are
called or modified from outside the source code provided to the compiler (default)
Specifies that the module contains functions that are called from outside the source code provided to the compiler but does not use variables modified from outside the source code
Disables the optimization information file
Produces an optimization information file
) can also affect optimization.
22
Using the C/C++ Compiler
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Changing the Compiler's Behavior With Options
Option
--gen_opt_info=2
--opt-for_speed[=n
--opt_level=0
--opt_level=1
--opt_level=2
--opt_level=3
--optimizer_interlist
--optimize_with_debug
--sat_reassoc={on|off}
--single_inline
--std_lib_func_defined
--std_lib_func_not_defined
--std_lib_func_redefined
Table 2-11. Options That Control Optimization (continued)
Alias
-on2
-mf
-O0
-O1
-O2 or -O
-O3
-os
-ol1 or -oL1
-ol2 or -oL2
-ol0 or -oL0
Effect
Produces a verbose optimization information file
Optimizes for speed over space (0-5 range)
Optimizes register usage
Uses -O0 optimizations and optimizes locally
Uses -O1 optimizations and optimizes globally
Uses -O2 optimizations and optimizes the file
Section
Interlists optimizer comments with assembly statements
Reenables optimizations disabled --symdebug:dwarf
Enables or disables the reassociation of saturating arithmetic
Inlines functions that are only called once
Informs the optimizer that your file declares a standard library function
Informs the optimizer that your file does not declare or alter library functions. Overrides the -ol0 and -ol1 options (default).
Informs the optimizer that your file alters a standard library function
Option
--absolute_listing
--asm_define=name[=def]
--asm_dependency
--asm_includes
--asm_listing
--asm_undefine=name
--copy_file=filename
--cross_reference
--include_file=filename
--output_all_syms
--syms_ignore_case
Table 2-12. Options That Control the Assembler
-ahc
-ax
-ahi
-as
-ac
Alias
-aa
-ad
-apd
-api
-al
-au
Effect
Enables absolute listing
Sets the name symbol
Performs preprocessing; lists only assembly dependencies
Performs preprocessing; lists only included #include files
Generates an assembly listing file
Undefines the predefined constant name
Copies the specified file for the assembly module
Generates the cross-reference file
Includes the specified file for the assembly module
Puts labels in the symbol table
Makes case insignificant in assembly source files
Table 2-13. Options That Control the Linker
(1)
Option
--absolute_exe
-ar
Alias
-a
Description
Generates absolute executable output
Generates relocatable, executable output
Allocates memory to be used by the loader to pass arguments
Section
--arg_size=size
--compress_dwarf
--define=name[=val]
--disable_auto_rts
--disable_clink
--disable_pp
--entry_point=global_symbol
--fill_value=value
--generate_dead_funcs_list=
filename
--globalize='pattern'
--args
-j
-e
-f
Aggressively reduces the size of DWARF information from input object files
Predefines name as a preprocessor macro.
Disables the automatic selection of a run-time-support library
Disables conditional linking of COFF object modules
Disables preprocessing for link command files
Defines an entry point
Sets default fill value
Writes a list of the dead functions that were removed by the linker to
filename.
Changes the symbol linkage to global for symbols that match pattern
--heap_size=size
(1)
See
-heap for diagnostics control options.
Sets heap size (bytes)
SLAU132D – June 2009
Submit Documentation Feedback
Using the C/C++ Compiler
Section
23
Changing the Compiler's Behavior With Options
www.ti.com
Option
--hide="pattern"
--library=libraryname
--linker_help
--localize='pattern'
--make_global=global_symbol
--make_static
--map_file=filename
--mapfile_contents=filter[, filter]
--no_demangle
--no_sym_merge
--no_sym_table
--output_file=filename
--priority
--ram_model
--relocatable
--reread_libs
--rom_model
--run_abs
--runtime={c95|cpp|rts}
--scan_libraries
--search_path=directory
--stack_size=size
--strict_compatibility={on|off}
--symbol_map=refname=defname
--undef_sym
--undefine=name[=val]
--unhide="pattern"
--use_hw_mpy[={16|32|F5}]
--warn_sections
--xml_link_info
Table 2-13. Options That Control the Linker (continued)
Alias
-l
-help
-g
-h
-m
-b
-s
-o
-priority
-cr
-r
-x
-c
-abs
-I
-stack
-u
-w
Description
Hides global symbols that match pattern
Section
Supplies library or command filename
Displays usage information
Changes the symbol linkage to local for symbols that match pattern
Keeps a global_symbol global (overrides -h)
Makes all global symbols static
Names the map file
Controls the information that appears in the map file
Disables demangling of symbol names in diagnostics
Disables merge of COFF symbolic debugging information
Strips symbol table information and line number entries from the output module
Names the output file.
Satisfies unresolved references by the first library that contains a definition for that symbol
Initializes variables at load time
Produces nonexecutable, relocatable output
Forces rereading of libraries
Autoinitializes variables at run time
Produces an absolute listing file
Designates the header include path to use different libraries
Scans all libraries for duplicate symbol definitions
Defines library search path
Sets stack size (bytes)
Performs more conservative and rigorous compatibility checking of input object files
Enables symbol mapping
Creates unresolved external symbol
Removes the preprocessor macro name
Reveals (un-hides) global symbols that match pattern
Replaces all references to the default integer/long multiply routine with the version of the multiply routine that uses the hardware multiplier support.
Displays a message when an undefined output section is created
Generates an XML information file
2.3.1 Frequently Used Options
Following are detailed descriptions of options that you will probably use frequently:
--c_src_interlist
Invokes the interlist feature, which interweaves original C/C++ source with compiler-generated assembly language. The interlisted C statements may appear to be out of sequence. You can use the interlist feature with the optimizer by combining the --optimizer_interlist and
--c_src_interlist options. See
. The --c_src_interlist option can
have a negative performance and/or code size impact.
24
Using the C/C++ Compiler
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
--cmd_file=filename
--compile_only
--define=name[=def]
--exceptions
--fp_mode={relaxed|strict}
Changing the Compiler's Behavior With Options
Appends the contents of a file to the option set. You can use this option to avoid limitations on command line length or C style comments imposed by the host operating system. Use a # or ; at the beginning of a line in the command file to include comments. You can also include comments by delimiting them with /* and */. To specify options, surround hyphens with quotation marks. For example, "--"quiet.
You can use the --cmd_file option multiple times to specify multiple files.
For instance, the following indicates that file3 should be compiled as source and file1 and file2 are --cmd_file files: cl430 --cmd_file=file1 --cmd_file=file2 file3
Suppresses the linker and overrides the --run_linker option, which specifies linking. The --compile_only option's short form is -c. Use this option when you have --run_linker specified in the MSP430_C_OPTION environment variable and you do not want to link. See
Predefines the constant name for the preprocessor. This is equivalent to inserting #define name def at the top of each C source file. If the optional[=def] is omitted, the name is set to 1. The --define option's short form is -D.
If you want to define a quoted string and keep the quotation marks, do one of the following:
•
For Windows
®
, use --define=name="\"string def\"". For example,
--define=car="\"sedan\""
•
For UNIX
®
, use --define=name='"string def"'. For example,
--define=car='"sedan"'
•
For Code Composer Studio, enter the definition in a file and include that file with the --cmd_file option.
Enables support of C++ exception handling. The compiler will generate code to handle try/catch/throw statements in C++ code. See
Supports relaxed floating-point mode. In this mode, if the result of a double-precision floating-point expression is assigned to a single-precision floating-point or an integer, the computations in the expression are converted to single-precision computations. Any double-precision constants in the expression are also converted to single-precision if they can be correctly represented as single-precision constants. This behavior does not conform with ISO; but it results in faster code, with some loss in accuracy. In the following example, where
N is a number, iN=integer variable, fN=float variable, dN=double variable: il = f1 + f2 * 5.0
-> +, * are float, 5.0
is converted to 5.0f
il = d1 + d2 * d3 -> +, are float f1 = f2 + f3 * 1.1; -> +, are float, 1.1
is converted to 1
To enable relaxed floating-point mode use the --fp_mode=relaxed option, which also sets --fp_reassoc=on. To disable relaxed floating-point mode use the --fp_mode=strict option, which also sets --fp_reassoc=off. The default behavior is --fp_mode=strict.
If --strict_ansi is specified, --fp_mode=strict is set automatically. You can enable the relaxed floating-point mode with strict ansi mode by specifying --fp_mode=relaxed after --strict_ansi.
SLAU132D – June 2009
Submit Documentation Feedback
Using the C/C++ Compiler
25
Changing the Compiler's Behavior With Options
--fp_reassoc={on|off}
--help
--include_path=directory
--keep_asm
--keep_unneeded_statics
--no_const_clink
--preinclude=filename
--quiet
--run_linker
--sat_reassoc={on|off}
--skip_assembler
www.ti.com
Enables or disables the reassociation of floating-point arithmetic. If
--fp_mode=relaxed is specified, --fp_reassoc=on is set automatically. If
--strict_ansi is set, --fp_reassoc=off is set since reassociation of floating-point arithmetic is an ANSI violation.
Displays the syntax for invoking the compiler and lists available options.
If the --help option is followed by another option or phrase, detailed information about the option or phrase is displayed. For example, to see information about debugging options use --help debug.
Adds directory to the list of directories that the compiler searches for
#include files. The --include_path option's short form is -I. You can use this option several times to define several directories; be sure to separate the --include_path options with spaces. If you do not specify a directory name, the preprocessor ignores the --include_path option. See
.
Retains the assembly language output from the compiler or assembly optimizer. Normally, the compiler deletes the output assembly language file after assembly is complete. The --keep_asm option's short form is -k.
Does not delete unreferenced static variables. The parser by default remarks about and then removes any unreferenced static variables. The
--keep_unneeded_statics option keeps the parser from deleting unreferenced static variables and any static functions that are referenced by these variable definitions.
Tells the compiler to not generated .clink directives for const global arrays. By default, these arrays are placed in a .const subsection and conditionally linked.
Includes the source code of filename at the beginning of the compilation.
This can be used to establish standard macro definitions. The filename is searched for in the directories on the include search list. The files are processed in the order in which they were specified.
Suppresses banners and progress information from all the tools. Only source filenames and error messages are output. The --quiet option's short form is -q.
Runs the linker on the specified object files. The --run_linker option and its parameters follow all other options on the command line. All arguments that follow --run_linker are passed to the linker. The
--run_linker option's short form is -z. See
.
Enables or disables the reassociation of saturating arithmetic.
Compiles only. The specified source files are compiled but not assembled or linked. The --skip_assembler option's short form is -n. This option overrides --run_linker. The output is assembly language output from the compiler.
26
Using the C/C++ Compiler
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
--src_interlist
--tool_version
--undefine=name
--verbose
Changing the Compiler's Behavior With Options
Invokes the interlist feature, which interweaves optimizer comments or
C/C++ source with assembly source. If the optimizer is invoked
(--opt_level=n option), optimizer comments are interlisted with the assembly language output of the compiler, which may rearrange code significantly. If the optimizer is not invoked, C/C++ source statements are interlisted with the assembly language output of the compiler, which allows you to inspect the code generated for each C/C++ statement. The
--src_interlist option implies the --keep_asm option. The --src_interlist option's short form is -s.
Prints the version number for each tool in the compiler. No compiling occurs.
Undefines the predefined constant name. This option overrides any
--define options for the specified constant. The --undefine option's short form is -U.
Displays progress information and toolset version while compiling.
Resets the --quiet option.
2.3.2 Function-Specific Command Line Options (--beginopts/--endopts)
Certain command line options associated with the goal and degree of program optimization can be specified to apply to specific functions using the following new options:
--beginopts [file_name:]function_name option_list --endopts
If the file_name or function_name does not match a file name and function name in the current compilation the option_list is ignored.
The character '-' can be used as the function_name in a beginopts-endopts group to indicate all functions in the file. As with most options, options specified later in the file override/replace conflicting options specified earlier in the file.
The following uses optimization level 3 when compiling the function usedalot and uses the default optimization level for all other functions: cl430 noopt.c --beginopts usedalot -o3 --endopts
A typical way to use this feature is to put a list of beginopts-endopts groups in an indirect command file and then reference the file on the command line.
cl430 file.c -k -mg @funcopts.cmd
Currently the overridable options, that is, options that may appear in the option_list, are only --opt_level and --auto_inline (-o and -oi). The appearance of any other option is an error.
Options appearing outside of beginopts-endopts (global options) apply to all functions except those named in a beginopts-endopts group. For a function named in a beginopts-endopts group, global options that are not overridable apply and overridable options take on their default values or the value given in the beginopts-endopts group. The defaults for the overridable options are -o2 and -oi1. Be careful with this rule for overridable options.
SLAU132D – June 2009
Submit Documentation Feedback
Using the C/C++ Compiler
27
Changing the Compiler's Behavior With Options
www.ti.com
2.3.3 Machine-Specific Options
These options are specific to the MSP430 toolset. Please see the referenced sections for more information.
--large_memory_model
Uses a large memory model for an MSP430X device. The large-data model uses 20-bit data pointers, which allows data to be located anywhere in the address space and not be restricted to the low 64
Kb.
--plain_char={unsigned|signed} Specifies how to treat C/C++ plain char variables, default is unsigned.
--printf_support=version
--silicon_version
--small_enum
Enables support for smaller, limited versions of the printf and sprintf run-time-support functions. The valid version values are full (default), nofloat and minimal.
The printf/sprintf functions use a common low-level routine, _printfi, which processes a given printf format string. The full version of_printfi provides formatting capabilities that are not required in typical embedded applications. To address this the C run-time libraries also include two limited of versions of _printfi that provide a useful subset of the formatting features specified by C library standard.
One version excludes support for printing floating values. All format specifiers except for %f, %g, %G, %e, or %E are supported. You specify this version with ––printf_support=nofloat when compiling and linking.
The other version only supports printing of integer, char, or string values without width or precision flags. Specifically, only the %%, %d,
%o, %c, %s, and %x format specifiers are supported. You specify this version with ––printf_support=minimal when compiling and linking.
There are no run-time error checks if a format specifier is used but is not supported in the version specified by the ––printf_support option.
An upcoming release will add compile-time checks.
The ––printf_support option precedes the ––run_linker option;–– printf_support must be used when performing the final link.
Selects the instruction set version. Using --silicon_version=mspx generates code for MSP430X devices (20-bit code addressing). Using
--silicon_version=msp generates code for 16-bit MSP430 devices.
Modules assembled/compiled for 16-bit MSP430 devices are not compatible with modules that are assembled/compiled for 20-bit
MSPx devices. The linker generates errors if an attempt is made to combine incompatible object files.
By default, the MSP430 compiler uses 16 bits for every enum. When you use the --small-enum option, the smallest possible byte size for the enumeration type is used. For example, enum example_enum
{first = -128, second = 0, third = 127} uses only one byte instead of 16 bits when the --small-enum option is used. Do not link object files compiled with the --small_enum option with object files that have been compiled without it. If you use the --small_enum option, you must use it with all of your C/C++ files; otherwise, you will encounter errors that cannot be detected until run time.
28
Using the C/C++ Compiler
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
2.3.4 Symbolic Debugging and Profiling Options
Changing the Compiler's Behavior With Options
The following options are used to select symbolic debugging or profiling:
--profile:breakpt
--profile:power
--symdebug:coff
--symdebug:dwarf
--symdebug:dwarf_
subsections=on|off
Disables optimizations that would cause incorrect behavior when using a breakpoint-based profiler.
Enables power profiling support by inserting NOPs into the frame code. These NOPs can then be instrumented by the power profiling tooling to track the power usage of functions. If the power profiling tool is not used, this option increases the cycle count of each function because of the NOPs. The --profile:power option also disables optimizations that cannot be handled by the power-profiler.
Enables symbolic debugging using the alternate STABS debugging format. This may be necessary to allow debugging with older debuggers or custom tools, which do not read the DWARF format.
Generates directives that are used by the C/C++ source-level debugger and enables assembly source debugging in the assembler.
The --symdebug:dwarf option's short form is -g. The
--symdebug:dwarf option disables many code generator optimizations, because they disrupt the debugger. You can use the
--symdebug:dwarf option with the --opt_level (aliased as -O) option to maximize the amount of optimization that is compatible with debugging (see
For more information on the DWARF debug format, see The DWARF
Debugging Standard.
Changes the way the debug information is represented in the object file. When the option is set to on, the resulting object file supports a rapid form of type merging in the debugging information that is done in the linker. If you have been using the --no_sym_merge linker option to disable type merging of the debugging information in order to reduce link time at the cost of increased .out file size, recompiling with --symdebug:dwarf_subsections=on can realize a reasonable link time without increasing the .out file size. The default behavior is off.
--symdebug:none
--symdebug:profile_coff
--symdebug:skeletal
Disables all symbolic debugging output. This option is not recommended; it prevents debugging and most performance analysis capabilities.
Adds the necessary debug directives to the object file which are needed by the profiler to allow function level profiling with minimal impact on optimization (when used). Using --symdebug:coff may hinder some optimizations to ensure that debug ability is maintained, while this option will not hinder optimization.
You can set breakpoints and profile on function-level boundaries in
Code Composer Studio, but you cannot single-step through code as with full debug ability.
Generates as much symbolic debugging information as possible without hindering optimization. Generally, this consists of global-scope information only. This option reflects the default behavior of the compiler.
See
for a list of deprecated symbolic debugging options.
SLAU132D – June 2009
Submit Documentation Feedback
Using the C/C++ Compiler
29
Changing the Compiler's Behavior With Options
www.ti.com
2.3.5 Specifying Filenames
The input files that you specify on the command line can be C source files, C++ source files, assembly source files, or object files. The compiler uses filename extensions to determine the file type.
Extension
.asm, .abs, or .s* (extension begins with s)
.c
.C
.cpp, .cxx, .cc
.obj
File Type
Assembly source
C source
Depends on operating system
C++ source
Object
Note: Case Sensitivity in Filename Extensions
Case sensitivity in filename extensions is determined by your operating system. If your operating system is not case sensitive, a file with a .C extension is interpreted as a C file. If your operating system is case sensitive, a file with a .C extension is interpreted as a C++ file.
For information about how you can alter the way that the compiler interprets individual filenames, see
. For information about how you can alter the way that the compiler interprets and names the
extensions of assembly source and object files, see
You can use wildcard characters to compile or assemble multiple files. Wildcard specifications vary by system; use the appropriate form listed in your operating system manual. For example, to compile all of the files in a directory with the extension .cpp, enter the following:
cl430 *.cpp
Note: No Default Extension for Source Files is Assumed
If you list a filename called example on the command line, the compiler assumes that the entire filename is example not example.c. No default extensions are added onto files that do not contain an extension.
2.3.6 Changing How the Compiler Interprets Filenames
You can use options to change how the compiler interprets your filenames. If the extensions that you use are different from those recognized by the compiler, you can use the filename options to specify the type of file. You can insert an optional space between the option and the filename. Select the appropriate option for the type of file you want to specify:
--asm_file=filename
--c_file=filename
--cpp_file=filename
--obj_file=filename for an assembly language source file for a C source file for a C++ source file for an object file
For example, if you have a C source file called file.s and an assembly language source file called assy, use the --asm_file and --c_file options to force the correct interpretation: cl430 --c_file=file.s --asm_file=assy
You cannot use the filename options with wildcard specifications.
30
Using the C/C++ Compiler
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Changing the Compiler's Behavior With Options
2.3.7 Changing How the Compiler Processes C Files
The --cpp_default option causes the compiler to process C files as C++ files. By default, the compiler treats files with a .c extension as C files. See
for more information about filename extension conventions.
2.3.8 Changing How the Compiler Interprets and Names Extensions
You can use options to change how the compiler program interprets filename extensions and names the extensions of the files that it creates. The filename extension options must precede the filenames they apply to on the command line. You can use wildcard specifications with these options. An extension can be up to nine characters in length. Select the appropriate option for the type of extension you want to specify:
--asm_extension=new extension
--c_extension=new extension
--cpp_extension=new extension
--listing_extension=new extension
--obj_extension=new extension for an assembly language file for a C source file for a C++ source file sets default extension for listing files for an object file
The following example assembles the file fit.rrr and creates an object file named fit.o: cl430 --asm_extension=.rrr --obj_extension=.o fit.rrr
The period (.) in the extension is optional. You can also write the example above as: cl430 --asm_extension=rrr --obj_extension=o fit.rrr
2.3.9 Specifying Directories
By default, the compiler program places the object, assembly, and temporary files that it creates into the current directory. If you want the compiler program to place these files in different directories, use the following options:
--abs_directory=directory Specifies the destination directory for absolute listing files. The default is to use the same directory as the object file directory. For example: cl430 --abs_directory=d:\abso_list
--asm_directory=directory Specifies a directory for assembly files. For example: cl430 --asm_directory=d:\assembly
--list_directory=directory Specifies the destination directory for assembly listing files and cross-reference listing files. The default is to use the same directory as the object file directory. For example: cl430 --list_directory=d:\listing
--obj_directory=directory Specifies a directory for object files. For example: cl430 --obj_directory=d:\object
--temp_directory=directory Specifies a directory for temporary intermediate files. For example: cl430 --temp_directory=d:\temp
SLAU132D – June 2009
Submit Documentation Feedback
Using the C/C++ Compiler
31
Changing the Compiler's Behavior With Options
www.ti.com
2.3.10 Assembler Options
Following are assembler options that you can use with the compiler. For more information, see the
MSP430 Assembly Language Tools User's Guide.
--absolute_listing
--asm_define=name[=def] Predefines the constant name for the assembler; produces a .set directive for a constant or a .arg directive for a string. If the optional [=def] is omitted, the name is set to 1. If you want to define a quoted string and keep the quotation marks, do one of the following:
•
For Windows, use --asm_define=name="\"string def\"". For example:
--asm_define=car="\"sedan\""
•
For UNIX, use --asm_define=name='"string def"'. For example:
--asm_define=car='"sedan"'
•
For Code Composer Studio, enter the definition in a file and include that file with the --cmd_file option.
--asm_dependency
Generates a listing with absolute addresses rather than section-relative offsets.
--asm_includes
--asm_listing
Performs preprocessing for assembly files, but instead of writing preprocessed output, writes a list of dependency lines suitable for input to a standard make utility. The list is written to a file with the same name as the source file but with a .ppa extension.
Performs preprocessing for assembly files, but instead of writing preprocessed output, writes a list of files included with the #include directive. The list is written to a file with the same name as the source file but with a .ppa extension.
Produces an assembly listing file.
--asm_undefine=name
--copy_file=filename
--cross_reference
--include_file=filename
Undefines the predefined constant name. This option overrides any
--asm_define options for the specified name.
Copies the specified file for the assembly module; acts like a .copy
directive. The file is inserted before source file statements. The copied file appears in the assembly listing files.
Produces a symbolic cross-reference in the listing file.
--output_all_syms
--syms_ignore_case
Includes the specified file for the assembly module; acts like a .include
directive. The file is included before source file statements. The included file does not appear in the assembly listing files.
Puts labels in the symbol table. Label definitions are written to the COFF symbol table for use with symbolic debugging.
Makes letter case insignificant in the assembly language source files. For example, --syms_ignore_case makes the symbols ABC and abc equivalent. If you do not use this option, case is significant (this is the default).
32
Using the C/C++ Compiler
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Controlling the Compiler Through Environment Variables
2.3.11 Deprecated Options
Several compiler options have been deprecated. The compiler continues to accept these options, but they are not recommended for use. Future releases of the tools will not support these options.
lists the deprecated options and the options that have replaced them.
Table 2-14. Compiler Backwards-Compatibility Options Summary
Old Option Effect
-gp Allows function-level profiling of optimized code
-gt
-gw
New Option
--symdebug:dwarf or -g
Enables symbolic debugging using the alternate STABS debugging format
--symdebug:coff
Enables symbolic debugging using the DWARF debugging --symdebug:dwarf or -g format
Additionally, the --symdebug:profile_coff option has been added to enable function-level profiling of optimized code with symbolic debugging using the STABS debugging format (the --symdebug:coff or -gt option).
2.4
Controlling the Compiler Through Environment Variables
An environment variable is a system symbol that you define and assign a string to. Setting environment variables is useful when you want to run the compiler repeatedly without re-entering options, input filenames, or pathnames.
Note: C_OPTION and C_DIR
The C_OPTION and C_DIR environment variables are deprecated. Use the device-specific environment variables instead.
2.4.1 Setting Default Compiler Options (MSP430_C_OPTION)
You might find it useful to set the compiler, assembler, and linker default options using the
MSP430_C_OPTION environment variable. If you do this, the compiler uses the default options and/or input filenames that you name MSP430_C_OPTION every time you run the compiler.
Setting the default options with these environment variables is useful when you want to run the compiler consecutive times with the same set of options and/or input files. After the compiler reads the command line and the input filenames, it looks for the MSP430_C_OPTION environment variable and processes it.
The table below shows how to set the MSP430_C_OPTION environment variable. Select the command for your operating system:
Operating System
UNIX (Bourne shell)
Windows
Enter
MSP430_C_OPTION="option
1
[option
2
. . .]"; export MSP430_C_OPTION
set MSP430_C_OPTION=option
1
[;option
2
. . .]
Environment variable options are specified in the same way and have the same meaning as they do on the command line. For example, if you want to always run quietly (the --quiet option), enable C/C++ source interlisting (the --src_interlist option), and link (the --run_linker option) for Windows, set up the
MSP430_C_OPTION environment variable as follows:
set MSP430_C_OPTION=--quiet --src_interlist --run_linker
SLAU132D – June 2009
Submit Documentation Feedback
Using the C/C++ Compiler
33
Controlling the Compiler Through Environment Variables
www.ti.com
In the following examples, each time you run the compiler, it runs the linker. Any options following
--run_linker on the command line or in MSP430_C_OPTION are passed to the linker. Thus, you can use the MSP430_C_OPTION environment variable to specify default compiler and linker options and then specify additional compiler and linker options on the command line. If you have set --run_linker in the environment variable and want to compile only, use the compiler --compile_only option. These additional examples assume MSP430_C_OPTION is set as shown above: cl430 *c ; compiles and links cl430 --compile_only *.c
; only compiles cl430 *.c --run_linker lnk.cmd
; compiles and links using a command file cl430 --compile_only *.c --run_linker lnk.cmd
; only compiles (--compile_only overrides --run_linker)
For details on compiler options, see
. For details on linker options, see
.
2.4.2 Naming an Alternate Directory (MSP430_C_DIR)
The linker uses the MSP430_C_DIR environment variable to name alternate directories that contain object libraries. The command syntaxes for assigning the environment variable are:
Operating System
UNIX (Bourne shell)
Windows
Enter
MSP430_C_DIR=" pathname
1
; pathname
2
;..."; export MSP430_C_DIR
set MSP430_C_DIR=pathname
1
;pathname
2
;...
The pathnames are directories that contain input files. The pathnames must follow these constraints:
•
Pathnames must be separated with a semicolon.
•
Spaces or tabs at the beginning or end of a path are ignored. For example, the space before and after the semicolon in the following is ignored: set MSP430_C_DIR=c:\path\one\to\tools ; c:\path\two\to\tools
•
Spaces and tabs are allowed within paths to accommodate Windows directories that contain spaces.
For example, the pathnames in the following are valid: set MSP430_C_DIR=c:\first path\to\tools;d:\second path\to\tools
The environment variable remains set until you reboot the system or reset the variable by entering:
Operating System
UNIX (Bourne shell)
Windows
Enter
unset MSP430_C_DIR set MSP430_C_DIR=
34
Using the C/C++ Compiler
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Precompiled Header Support
2.5
Precompiled Header Support
Precompiled header files may reduce the compile time for applications whose source files share a common set of headers, or a single file which has a large set of header files. Using precompiled headers, some recompilation is avoided thus saving compilation time.
There are two ways to use precompiled header files. One is the automatic precompiled header file processing and the other is called the manual precompiled header file processing.
2.5.1 Automatic Precompiled Header
The option to turn on automatic precompiled header processing is: --pch. Under this option, the compile step takes a snapshot of all the code prior to the header stop point, and dump it out to a file with suffix
.pch. This snapshot does not have to be recompiled in the future compilations of this file or compilations of files with the same header files.
The stop point typically is the first token in the primary source file that does not belong to a preprocessing directive. For example, in the following the stopping point is before int i:
#include "x.h"
#include "y.h" int i
Carefully organizing the include directives across multiple files so that their header files maximize common usage can increase the compile time savings when using precompiled headers.
A precompiled header file is produced only if the header stop point and the code prior to it meet certain requirements.
2.5.2 Manual Precompiled Header
You can manually control the creation and use of precompiled headers by using several command line options. You specify a precompiled header file with a specific filename as follows:
--create_pch=filename
The --use_pch=filename option specifies that the indicated precompiled header file should be used for this compilation. If this precompiled header file is invalid, if its prefix does not match the prefix for the current primary source file for example, a warning is issued and the header file is not used.
If --create_pch=filename or --use_pch=filename is used with --pch_dir, the indicated filename, which can be a path name, is tacked on to the directory name, unless the filename is an absolute path name.
The --create_pch, --use_pch, and --pch options cannot be used together. If more than one of these options is specified, only the last one is applied. In manual mode, the header stop points are determined in the same way as in automatic mode. The precompiled header file applicability is determined in the same manner.
2.5.3 Additional Precompiled Header Options
The --pch_verbose option displays a message for each precompiled header file that is considered but not used. The --pch_dir=pathname option specifies the path where the precompiled header file resides.
SLAU132D – June 2009
Submit Documentation Feedback
Using the C/C++ Compiler
35
Controlling the Preprocessor
www.ti.com
2.6
Controlling the Preprocessor
This section describes specific features that control the preprocessor, which is part of the parser. A general description of C preprocessing is in section A12 of K&R. The C/C++ compiler includes standard
C/C++ preprocessing functions, which are built into the first pass of the compiler. The preprocessor handles:
•
Macro definitions and expansions
•
#include files
•
Conditional compilation
•
Various preprocessor directives, specified in the source file as lines beginning with the # character
The preprocessor produces self-explanatory error messages. The line number and the filename where the error occurred are printed along with a diagnostic message.
2.6.1 Predefined Macro Names
The compiler maintains and recognizes the predefined macro names listed in
Macro Name
_ _DATE_ _
(1)
_ _FILE_ _
(1)
_ _LARGE_CODE_MODEL_ _
_ _LARGE_DATA_MODEL_ _
_ _LINE_ _
(1)
_ _MSP430_ _
_ _MSP430X461X_ _
_ _signed_chars_ _
_ _STDC_ _
(1)
_ _TI_COMPILER_VERSION_ _
_ _TIME_ _
(1)
_ _unsigned_chars_ _
_INLINE
Table 2-15. Predefined MSP430 Macro Names
Description
Expands to the compilation date in the form mmm dd yyyy
Expands to the current source filename
Defined if ––silicon_version=mspx is specified
Defined if ––large_memory_model is specified
Expands to the current line number
Always defined
Defined if --silicon_version=mspx is specified
Defined if char types are signed by default (--plain_char=signed)
Defined to indicate that compiler conforms to ISO C Standard. See
for exceptions to ISO C conformance.
Defined to a 7-digit integer that takes the 3-digit release version number X.Y.Z and generates an integer XXXYYYZZZ where each portion X, Y and Z is expanded to three digits and concatenated together. The number does not contain a decimal. For example, version 3.2.1 is represented as 3002001. The leading zeros are dropped to prevent the number being interpreted as an octal.
Expands to the compilation time in the form hh:mm:ss
Defined if char types are unsigned by default (default or –– plain_char=unsigned)
Expands to 1 if optimization is used (--opt_level or -O option); undefined otherwise.
Regardless of any optimization, always undefined when --no_inlining is used.
(1)
Specified by the ISO standard
You can use the names listed in
in the same manner as any other defined name. For example, printf ( "%s %s" , __TIME__ , __DATE__); translates to a line such as: printf ("%s %s" , "13:58:17", "Jan 14 1997");
36
Using the C/C++ Compiler
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Controlling the Preprocessor
2.6.2 The Search Path for #include Files
The #include preprocessor directive tells the compiler to read source statements from another file. When specifying the file, you can enclose the filename in double quotes or in angle brackets. The filename can be a complete pathname, partial path information, or a filename with no path information.
•
If you enclose the filename in double quotes (" "), the compiler searches for the file in the following directories in this order:
1. The directory of the file that contains the #include directive and in the directories of any files that contain that file.
2. Directories named with the --include_path option.
3. Directories set with the MSP430_C_DIR environment variable.
•
If you enclose the filename in angle brackets (< >), the compiler searches for the file in the following directories in this order:
1. Directories named with the --include_path option.
2. Directories set with the MSP430_C_DIR environment variable.
See
for information on using the --include_path option. See
for more information on input file directories.
2.6.2.1
Changing the #include File Search Path (--include_path Option)
The --include_path option names an alternate directory that contains #include files. The --include_path option's short form is -I. The format of the --include_path option is:
--include_path=directory1 [--include_path=directory2 ...]
There is no limit to the number of --include_path options per invocation of the compiler; each
--include_path option names one directory. In C source, you can use the #include directive without specifying any directory information for the file; instead, you can specify the directory information with the
--include_path option. For example, assume that a file called source.c is in the current directory. The file source.c contains the following directive statement:
#include "alt.h"
Assume that the complete pathname for alt.h is:
UNIX
Windows
/tools/files/alt.h
c:\tools\files\alt.h
The table below shows how to invoke the compiler. Select the command for your operating system:
Operating System
UNIX
Windows
Enter
cl430 --include_path=tools/files source.c
cl430 --include_path=c:\tools\files source.c
SLAU132D – June 2009
Submit Documentation Feedback
Using the C/C++ Compiler
37
Controlling the Preprocessor
Note: Specifying Path Information in Angle Brackets
If you specify the path information in angle brackets, the compiler applies that information relative to the path information specified with --include_path options and the MSP430_C_DIR environment variable.
For example, if you set up MSP430_C_DIR with the following command:
MSP430_C_DIR "/usr/include;/usr/ucb"; export MSP430_C_DIR or invoke the compiler with the following command: cl430 --include_path=/usr/include file.c
and file.c contains this line:
#include <sys/proc.h> the result is that the included file is in the following path:
/usr/include/sys/proc.h
www.ti.com
2.6.3 Generating a Preprocessed Listing File (--preproc_only Option)
The --preproc_only option allows you to generate a preprocessed version of your source file with an extension of .pp. The compiler's preprocessing functions perform the following operations on the source file:
•
Each source line ending in a backslash (\) is joined with the following line.
•
Trigraph sequences are expanded.
•
Comments are removed.
•
#include files are copied into the file.
•
Macro definitions are processed.
•
All macros are expanded.
•
All other preprocessing directives, including #line directives and conditional compilation, are expanded.
2.6.4 Continuing Compilation After Preprocessing (--preproc_with_compile Option)
If you are preprocessing, the preprocessor performs preprocessing only; it does not compile your source code. To override this feature and continue to compile after your source code is preprocessed, use the
--preproc_with_compile option along with the other preprocessing options. For example, use
--preproc_with_compile with --preproc_only to perform preprocessing, write preprocessed output to a file with a .pp extension, and compile your source code.
2.6.5 Generating a Preprocessed Listing File With Comments (--preproc_with_comments
Option)
The --preproc_with_comments option performs all of the preprocessing functions except removing comments and generates a preprocessed version of your source file with a .pp extension. Use the
--preproc_with_comments option instead of the --preproc_only option if you want to keep the comments.
2.6.6 Generating a Preprocessed Listing File With Line-Control Information
(--preproc_with_line Option)
By default, the preprocessed output file contains no preprocessor directives. To include the #line directives, use the --preproc_with_line option. The --preproc_with_line option performs preprocessing only and writes preprocessed output with line-control information (#line directives) to a file named as the source file but with a .pp extension.
38
Using the C/C++ Compiler
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Understanding Diagnostic Messages
2.6.7 Generating Preprocessed Output for a Make Utility (--preproc_dependency Option)
The --preproc_dependency option performs preprocessing only, but instead of writing preprocessed output, writes a list of dependency lines suitable for input to a standard make utility. If you do not supply an optional filename, the list is written to a file with the same name as the source file but with a .pp
extension.
2.6.8 Generating a List of Files Included With the #include Directive (--preproc_includes
Option)
The --preproc_includes option performs preprocessing only, but instead of writing preprocessed output, writes a list of files included with the #include directive. If you do not supply an optional filename, the list is written to a file with the same name as the source file but with a .pp extension.
2.6.9 Generating a List of Macros in a File (--preproc_macros Option)
The --preproc_macros option generates a list of all predefined and user-defined macros. If you do not supply an optional filename, the list is written to a file with the same name as the source file but with a .pp
extension. Predefined macros are listed first and indicated by the comment /* Predefined */. User-defined macros are listed next and indicated by the source filename.
2.7
Understanding Diagnostic Messages
One of the compiler's primary functions is to report diagnostics for the source program. The new linker also reports diagnostics. When the compiler or linker detects a suspect condition, it displays a message in the following format:
"file.c=, line n:diagnostic severity: diagnostic message
"file.c"
line n :
The name of the file involved
The line number where the diagnostic applies
diagnostic severity
The diagnostic message severity (severity category descriptions follow)
diagnostic message
The text that describes the problem
Diagnostic messages have an associated severity, as follows:
•
A fatal error indicates a problem so severe that the compilation cannot continue. Examples of such problems include command-line errors, internal errors, and missing include files. If multiple source files are being compiled, any source files after the current one will not be compiled.
•
An error indicates a violation of the syntax or semantic rules of the C/C++ language. Compilation continues, but object code is not generated.
•
A warning indicates something that is valid but questionable. Compilation continues and object code is generated (if no errors are detected).
•
A remark is less serious than a warning. It indicates something that is valid and probably intended, but may need to be checked. Compilation continues and object code is generated (if no errors are detected). By default, remarks are not issued. Use the --issue_remarks compiler option to enable remarks.
Diagnostics are written to standard error with a form like the following example:
"test.c", line 5: error: a break statement may only be used within a loop or switch break;
^
By default, the source line is omitted. Use the --verbose_diagnostics compiler option to enable the display of the source line and the error position. The above example makes use of this option.
SLAU132D – June 2009
Submit Documentation Feedback
Using the C/C++ Compiler
39
Understanding Diagnostic Messages
www.ti.com
The message identifies the file and line involved in the diagnostic, and the source line itself (with the position indicated by the ^ character) follows the message. If several diagnostics apply to one source line, each diagnostic has the form shown; the text of the source line is displayed several times, with an appropriate position indicated each time.
Long messages are wrapped to additional lines, when necessary.
You can use the --display_error_number command-line option to request that the diagnostic's numeric identifier be included in the diagnostic message. When displayed, the diagnostic identifier also indicates whether the diagnostic can have its severity overridden on the command line. If the severity can be overridden, the diagnostic identifier includes the suffix -D (for discretionary); otherwise, no suffix is present. For example:
"Test_name.c", line 7: error #64-D: declaration does not declare anything struct {};
^
"Test_name.c", line 9: error #77: this declaration has no storage class or type specifier xxxxx;
^
Because an error is determined to be discretionary based on the error severity associated with a specific context, an error can be discretionary in some cases and not in others. All warnings and remarks are discretionary.
For some messages, a list of entities (functions, local variables, source files, etc.) is useful; the entities are listed following the initial error message:
"test.c", line 4: error: more than one instance of overloaded function "f" matches the argument list: function "f(int)" function "f(float)" argument types are: (double) f(1.5);
^
In some cases, additional context information is provided. Specifically, the context information is useful when the front end issues a diagnostic while doing a template instantiation or while generating a constructor, destructor, or assignment operator function. For example:
"test.c", line 7: error: "A::A()" is inaccessible
B x;
^ detected during implicit generation of "B::B()" at line 7
Without the context information, it is difficult to determine to what the error refers.
2.7.1 Controlling Diagnostics
The C/C++ compiler provides diagnostic options to control compiler- and linker-generated diagnostics. The diagnostic options must be specified before the --run_linker option.
--diag_error=num Categorizes the diagnostic identified by num as an error. To determine the numeric identifier of a diagnostic message, use the --display_error_number option first in a separate compile. Then use --diag_error=num to recategorize the diagnostic as an error. You can only alter the severity of discretionary diagnostics.
--diag_remark=num Categorizes the diagnostic identified by num as a remark. To determine the numeric identifier of a diagnostic message, use the --display_error_number option first in a separate compile. Then use --diag_remark=num to recategorize the diagnostic as a remark. You can only alter the severity of discretionary diagnostics.
--diag_suppress=num Suppresses the diagnostic identified by num. To determine the numeric identifier of a diagnostic message, use the --display_error_number option first in a separate compile. Then use --diag_suppress=num to suppress the diagnostic. You can only suppress discretionary diagnostics.
40
Using the C/C++ Compiler
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Understanding Diagnostic Messages
--diag_warning=num Categorizes the diagnostic identified by num as a warning. To determine the numeric identifier of a diagnostic message, use the --display_error_number option first in a separate compile. Then use --diag_warning=num to recategorize the diagnostic as a warning. You can only alter the severity of discretionary diagnostics.
--display_error_number Displays a diagnostic's numeric identifier along with its text. Use this option in determining which arguments you need to supply to the diagnostic suppression options (--diag_suppress, --diag_error, --diag_remark, and
--diag_warning). This option also indicates whether a diagnostic is discretionary. A discretionary diagnostic is one whose severity can be overridden. A discretionary diagnostic includes the suffix -D; otherwise, no suffix is present. See
.
--issue_remarks
--no_warnings
Issues remarks (nonserious warnings), which are suppressed by default.
Suppresses warning diagnostics (errors are still issued).
--set_error_limit=num Sets the error limit to num, which can be any decimal value. The compiler abandons compiling after this number of errors. (The default is 100.)
--verbose_diagnostics
Provides verbose diagnostics that display the original source with line-wrap and indicate the position of the error in the source line
--write_diagnostics_file Produces a diagnostics information file with the same source file name with an
.err extension. (The --write_diagnostics_file option is not supported by the linker.)
2.7.2 How You Can Use Diagnostic Suppression Options
The following example demonstrates how you can control diagnostic messages issued by the compiler.
You control the linker diagnostic messages in a similar manner.
int one(); int I; int main()
{ switch (I){ case 1; return one (); break; default: return 0; break;
}
}
If you invoke the compiler with the --quiet option, this is the result:
"err.c", line 9: warning: statement is unreachable
"err.c", line 12: warning: statement is unreachable
Because it is standard programming practice to include break statements at the end of each case arm to avoid the fall-through condition, these warnings can be ignored. Using the --display_error_number option, you can find out the diagnostic identifier for these warnings. Here is the result:
[err.c]
"err.c", line 9: warning #111-D: statement is unreachable
"err.c", line 12: warning #111-D: statement is unreachable
Next, you can use the diagnostic identifier of 111 as the argument to the --diag_remark option to treat this warning as a remark. This compilation now produces no diagnostic messages (because remarks are disabled by default).
SLAU132D – June 2009
Submit Documentation Feedback
Using the C/C++ Compiler
41
Other Messages
www.ti.com
Although this type of control is useful, it can also be extremely dangerous. The compiler often emits messages that indicate a less than obvious problem. Be careful to analyze all diagnostics emitted before using the suppression options.
2.8
Other Messages
Other error messages that are unrelated to the source, such as incorrect command-line syntax or inability to find specified files, are usually fatal. They are identified by the symbol >> preceding the message.
2.9
Generating Cross-Reference Listing Information (--gen_acp_xref Option)
The --gen_acp_xref option generates a cross-reference listing file that contains reference information for each identifier in the source file. (The --gen_acp_xref option is separate from --cross_reference, which is an assembler rather than a compiler option.) The cross-reference listing file has the same name as the source file with a .crl extension.
The information in the cross-reference listing file is displayed in the following format:
sym-id name X filename line number column number sym-id name
X filename line number column number
An integer uniquely assigned to each identifier
The identifier name
One of the following values:
D Definition d Declaration (not a definition)
M
A
U
Modification
Address taken
Used
C
R
Changed (used and modified in a single operation)
Any other kind of reference
E Error; reference is indeterminate
The source file
The line number in the source file
The column number in the source file
2.10 Generating a Raw Listing File (--gen_acp_raw Option)
The --gen_acp_raw option generates a raw listing file that can help you understand how the compiler is preprocessing your source file. Whereas the preprocessed listing file (generated with the --preproc_only,
--preproc_with_comment, --preproc_with_line, and --preproc_dependency preprocessor options) shows a preprocessed version of your source file, a raw listing file provides a comparison between the original source line and the preprocessed output. The raw listing file has the same name as the corresponding source file with an .rl extension.
The raw listing file contains the following information:
•
Each original source line
•
Transitions into and out of include files
•
Diagnostics
•
Preprocessed source line if nontrivial processing was performed (comment removal is considered trivial; other preprocessing is nontrivial)
42
Using the C/C++ Compiler
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Using Inline Function Expansion
Each source line in the raw listing file begins with one of the identifiers listed in
Identifier
N
X
S
L
Table 2-16. Raw Listing File Identifiers
Definition
Normal line of source
Expanded line of source. It appears immediately following the normal line of source if nontrivial preprocessing occurs.
Skipped source line (false #if clause)
Change in source position, given in the following format:
L line number filename key
Where line number is the line number in the source file. The key is present only when the change is due to entry/exit of an include file. Possible values of key are:
1 = entry into an include file
2 = exit from an include file
The --gen_acp_raw option also includes diagnostic identifiers as defined in
Table 2-17. Raw Listing File Diagnostic Identifiers
Diagnostic Identifier
E
F
R
W
Definition
Error
Fatal
Remark
Warning
Diagnostic raw listing information is displayed in the following format:
S filename line number column number diagnostic
S filename line number column number diagnostic
One of the identifiers in
that indicates the severity of the diagnostic
The source file
The line number in the source file
The column number in the source file
The message text for the diagnostic
Diagnostics after the end of file are indicated as the last line of the file with a column number of 0. When diagnostic message text requires more than one line, each subsequent line contains the same file, line, and column information but uses a lowercase version of the diagnostic identifier. For more information about diagnostic messages, see
.
2.11 Using Inline Function Expansion
When an inline function is called, the C/C++ source code for the function is inserted at the point of the call.
This is known as inline function expansion. Inline function expansion is advantageous in short functions for the following reasons:
•
It saves the overhead of a function call.
•
Once inlined, the optimizer is free to optimize the function in context with the surrounding code.
Inline function expansion is performed in one of the following ways:
•
Intrinsic operators are inlined by default.
•
Code is compiled with definition-controlled inlining.
•
When the optimizer is invoked with the --opt_level=3 option (-O3), automatic inline expansion is
SLAU132D – June 2009
Submit Documentation Feedback
Using the C/C++ Compiler
43
Using Interlist
www.ti.com
performed at call sites to small functions. For more information about automatic inline function expansion, see
Note: Function Inlining Can Greatly Increase Code Size
Expanding functions inline increases code size, especially inlining a function that is called in a number of places. Function inlining is optimal for functions that are called only from a small number of places and for small functions.
2.11.1 Inlining Intrinsic Operators
An operator is intrinsic if it can be implemented very efficiently with the target's instruction set. The compiler automatically inlines the intrinsic operators of the target system by default. Inlining happens whether or not you use the optimizer and whether or not you use any compiler or optimizer options on the command line. These functions are considered the intrinsic operators:
• abs
• labs
• fabs
2.11.2 Using the inline Keyword, the --no_inlining Option, and Level 3 Optimization
Definition-controlled inline function expansion is performed when you invoke the compiler with optimization and the compiler encounters the inline keyword in code. Functions with a variable number of arguments are not inlined. In addition, a limit is placed on the depth of inlining for recursive or nonleaf functions.
Inlining should be used for small functions or functions that are called in a few places (though the compiler does not enforce this). You can control this type of function inlining with the inline keyword.
The inline keyword specifies that a function is expanded inline at the point at which it is called, rather than by using standard calling procedures.
The semantics of the inline keyword follows that described in the C++ standard. The inline keyword is identically supported in C as a language extension. Because it is a language extension that could conflict with a strictly conforming program, however, the keyword is disabled in strict ANSI C mode (when you use the --strict_ansi compiler option). If you want to use definition-controlled inlining while in strict ANSI C mode, use the alternate keyword _ _inline.
When you want to compile without definition-controlled inlining, use the --no_inlining option.
Note: Using the --no_inlining Option With Level 3 Optimizations
When you use the --no_inlining option with --opt_level=3 (aliased as -O3) optimizations, automatic inlining is still performed.
2.12 Using Interlist
The compiler tools include a feature that interlists C/C++ source statements into the assembly language output of the compiler. The interlist feature enables you to inspect the assembly code generated for each
C statement. The interlist behaves differently, depending on whether or not the optimizer is used, and depending on which options you specify.
The easiest way to invoke the interlist feature is to use the --c_src_interlist option. To compile and run the interlist on a program called function.c, enter:
cl430 --c_src_interlist function
The --c_src_interlist option prevents the compiler from deleting the interlisted assembly language output file. The output assembly file, function.asm, is assembled normally.
44
Using the C/C++ Compiler
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Using Interlist
When you invoke the interlist feature without the optimizer, the interlist runs as a separate pass between the code generator and the assembler. It reads both the assembly and C/C++ source files, merges them, and writes the C/C++ statements into the assembly file as comments.
Using the --c_src_interlist option can cause performance and/or code size degradation.
shows a typical interlisted assembly file.
For more information about using the interlist feature with the optimizer, see
.
Example 2-1. An Interlisted Assembly Language File
;******************************************************************************
;* MSP430 C/C++ Codegen
;* Date/Time created: Tue Jun 29 14:54:28 2004
Unix v0.2.0 *
*
;******************************************************************************
.compiler_opts --mem_model:code=flat --mem_model:data=flat --symdebug:none
; acp430 -@/var/tmp/TI764/AAAv0aGVG
.sect
".text"
.align
2
.clink
.global main
;-----------------------------------------------------------------------
; 3 | int main()
;-----------------------------------------------------------------------
;******************************************************************************
;* FUNCTION NAME: main
;*
*
*
;* Regs Modified
;* Regs Used
: SP,SR,r11,r12,r13,r14,r15
: SP,SR,r11,r12,r13,r14,r15
*
*
;* Local Frame Size : 2 Args + 0 Auto + 0 Save = 2 byte *
;****************************************************************************** main:
;* ---------------------------------------------------------------------------*
SUB.W
#2,SP
;-----------------------------------------------------------------------
; 5 | printf("Hello, world\n");
;-----------------------------------------------------------------------
MOV.W
CALL
#$C$SL1+0,0(SP)
#printf
; |5|
; |5|
; |5|
;-----------------------------------------------------------------------
; 7 | return 0;
;-----------------------------------------------------------------------
MOV.W
ADD.W
RET
; |7|
#0,r12
#2,SP
; |7|
; |7|
; |7|
;******************************************************************************
;* STRINGS *
;******************************************************************************
.sect
".const"
.align
2
$C$SL1: .string "Hello, world",10,0
;******************************************************************************
;* UNDEFINED EXTERNAL REFERENCES *
;******************************************************************************
.global printf
SLAU132D – June 2009
Submit Documentation Feedback
Using the C/C++ Compiler
45
Enabling Entry Hook and Exit Hook Functions
www.ti.com
2.13 Enabling Entry Hook and Exit Hook Functions
An entry hook is a routine that is called upon entry to each function in the program. An exit hook is a routine that is called upon exit of each function. Applications for hooks include debugging, trace, profiling, and stack overflow checking.
Entry and exit hooks are enabled using the following options:
--entry_hook[=name] Enables entry hooks. If specified, the hook function is called name. Otherwise, the default entry hook function name is __entry_hook.
--entry_param{=name| Specify the parameters to the hook function. The name parameter specifies address|none} that the name of the calling function is passed to the hook function as an argument. In this case the signature for the hook function is: void hook(const char *name);
The address parameter specifies that the address of the calling function is passed to the hook function. In this case the signature for the hook function is: void hook(void (*addr)());
The none parameter specifies that the hook is called with no parameters. This is the default. In this case the signature for the hook function is: void hook(void);
--exit_hook[=name]
--exit_param{=name| address|none}
Enables exit hooks. If specified, the hook function is called name. Otherwise, the default exit hook function name is __exit_hook.
Specify the parameters to the hook function. The name parameter specifies that the name of the calling function is passed to the hook function as an argument. In this case the signature for the hook function is: void hook(const char *name);
The address parameter specifies that the address of the calling function is passed to the hook function. In this case the signature for the hook function is: void hook(void (*addr)());
The none parameter specifies that the hook is called with no parameters. This is the default. In this case the signature for the hook function is: void hook(void);
The presence of the hook options creates an implicit declaration of the hook function with the given signature. If a declaration or definition of the hook function appears in the compilation unit compiled with the options, it must agree with the signatures listed above.
In C++, the hooks are declared extern "C". Thus you can define them in C (or assembly) without being concerned with name mangling.
Hooks can be declared inline, in which case the compiler tries to inline them using the same criteria as other inline functions.
Entry hooks and exit hooks are independent. You can enable one but not the other, or both. The same function can be used as both the entry and exit hook.
You must take care to avoid recursive calls to hook functions. The hook function should not call any function which itself has hook calls inserted. To help prevent this, hooks are not generated for inline functions, or for the hook functions themselves.
You can use the --remove_hooks_when_inlining option to remove entry/exit hooks for functions that are auto-inlined by the optimizer.
See for information about the NO_HOOKS pragma.
46
Using the C/C++ Compiler
SLAU132D – June 2009
Submit Documentation Feedback
Chapter 3
SLAU132D – June 2009
Optimizing Your Code
The compiler tools can perform many optimizations to improve the execution speed and reduce the size of
C and C++ programs by simplifying loops, software pipelining, rearranging statements and expressions, and allocating variables into registers.
This chapter describes how to invoke different levels of optimization and describes which optimizations are performed at each level. This chapter also describes how you can use the Interlist feature when performing optimization and how you can profile or debug optimized code.
Topic
..................................................................................................
Page
3.1
................................................................
3.2
Performing File-Level Optimization (--opt_level=3 option)
3.3
Performing Program-Level Optimization
(--program_level_compile and --opt_level=3 options)
3.4
Accessing Aliased Variables in Optimized Code
3.5
Automatic Inline Expansion (--auto_inline Option)
3.6
Using the Interlist Feature With Optimization
...............................
3.7
........................................................
3.8
Controlling Code Size Versus Speed
..........................................
3.9
What Kind of Optimization Is Being Performed?
SLAU132D – June 2009
Submit Documentation Feedback
Optimizing Your Code
47
Invoking Optimization
www.ti.com
3.1
Invoking Optimization
The C/C++ compiler is able to perform various optimizations. High-level optimizations are performed in the optimizer and low-level, target-specific optimizations occur in the code generator. Use high-level optimizations to achieve optimal code.
The easiest way to invoke optimization is to use the compiler program, specifying the --opt_level=n option on the compiler command line. You can use -On to alias the --opt_level option. The n denotes the level of optimization (0, 1, 2, and 3), which controls the type and degree of optimization.
•
--opt_level=0 or -O0
– Performs control-flow-graph simplification
– Allocates variables to registers
– Performs loop rotation
– Eliminates unused code
– Simplifies expressions and statements
– Expands calls to functions declared inline
•
--opt_level=1 or -O1
Performs all --opt_level=0 (-O0) optimizations, plus:
– Performs local copy/constant propagation
– Removes unused assignments
– Eliminates local common expressions
•
--opt_level=2 or -O2
Performs all --opt_level=1 (-O1) optimizations, plus:
– Performs loop optimizations
– Eliminates global common subexpressions
– Eliminates global unused assignments
– Performs loop unrolling
The optimizer uses --opt_level=2 (-O2) as the default if you use --opt_level (-O) without an optimization level.
•
--opt_level=3 or -O3
Performs all --opt_level=2 (-O2) optimizations, plus:
– Removes all functions that are never called
– Simplifies functions with return values that are never used
– Inlines calls to small functions
– Reorders function declarations; the called functions attributes are known when the caller is optimized
– Propagates arguments into function bodies when all calls pass the same value in the same argument position
– Identifies file-level variable characteristics
If you use --opt_level=3 (-O3), see
and
for more information.
The levels of optimizations described above are performed by the stand-alone optimization pass. The code generator performs several additional optimizations, particularly processor-specific optimizations. It does so regardless of whether you invoke the optimizer. These optimizations are always enabled, although they are more effective when the optimizer is used.
48
Optimizing Your Code
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Performing File-Level Optimization (--opt_level=3 option)
3.2
Performing File-Level Optimization (--opt_level=3 option)
The --opt_level=3 option (aliased as the -O3 option) instructs the compiler to perform file-level optimization. You can use the --opt_level=3 option alone to perform general file-level optimization, or you can combine it with other options to perform more specific optimizations. The options listed in
work with --opt_level=3 to perform the indicated optimization:
Table 3-1. Options That You Can Use With --opt_level=3
If You ...
Use this Option
Have files that redeclare standard library functions --std_lib_func_defined
--std_lib_func_redefined
Want to create an optimization information file
Want to compile multiple source files
--gen_opt_level=n
--program_level_compile
See
3.2.1 Controlling File-Level Optimization (--std_lib_func_def Options)
When you invoke the compiler with the --opt_level=3 option, some of the optimizations use known properties of the standard library functions. If your file redeclares any of these standard library functions, these optimizations become ineffective. Use
to select the appropriate file-level optimization option.
Table 3-2. Selecting a File-Level Optimization Option
If Your Source File...
Declares a function with the same name as a standard library function
Contains but does not alter functions declared in the standard library
Does not alter standard library functions, but you used the --std_lib_func_redefined or
--std_lib_func_defined option in a command file or an environment variable. The
--std_lib_func_not_defined option restores the default behavior of the optimizer.
Use this Option
--std_lib_func_redefined
--std_lib_func_defined
--std_lib_func_not_defined
3.2.2 Creating an Optimization Information File (--gen_opt_info Option)
When you invoke the compiler with the --opt_level=3 option, you can use the --gen_opt_info option to create an optimization information file that you can read. The number following the option denotes the level (0, 1, or 2). The resulting file has an .nfo extension. Use
to select the appropriate level to append to the option.
Table 3-3. Selecting a Level for the --gen_opt_info Option
If you...
Use this option
Do not want to produce an information file, but you used the --gen_opt_level=1 or --gen_opt_level=2 --gen_opt_level=0 option in a command file or an environment variable. The --gen_opt_level=0 option restores the default behavior of the optimizer.
Want to produce an optimization information file
Want to produce a verbose optimization information file
--gen_opt_level=1
--gen_opt_level=2
SLAU132D – June 2009
Submit Documentation Feedback
Optimizing Your Code
49
Performing Program-Level Optimization (--program_level_compile and --opt_level=3 options)
www.ti.com
3.3
Performing Program-Level Optimization (--program_level_compile and --opt_level=3 options)
You can specify program-level optimization by using the --program_level_compile option with the
--opt_level=3 option (aliased as -O3). With program-level optimization, all of your source files are compiled into one intermediate file called a module. The module moves to the optimization and code generation passes of the compiler. Because the compiler can see the entire program, it performs several optimizations that are rarely applied during file-level optimization:
•
If a particular argument in a function always has the same value, the compiler replaces the argument with the value and passes the value instead of the argument.
•
If a return value of a function is never used, the compiler deletes the return code in the function.
•
If a function is not called directly or indirectly by main(), the compiler removes the function.
To see which program-level optimizations the compiler is applying, use the --gen_opt_level=2 option to generate an information file. See
for more information.
In Code Composer Studio, when the --program_level_compile option is used, C and C++ files that have the same options are compiled together. However, if any file has a file-specific option that is not selected as a project-wide option, that file is compiled separately. For example, if every C and C++ file in your project has a different set of file-specific options, each is compiled separately, even though program-level optimization has been specified. To compile all C and C++ files together, make sure the files do not have file-specific options. Be aware that compiling C and C++ files together may not be safe if previously you used a file-specific option.
Note: Compiling Files With the --program_level_compile and --keep_asm Options
If you compile all files with the --program_level_compile and --keep_asm options, the compiler produces only one .asm file, not one for each corresponding source file.
3.3.1 Controlling Program-Level Optimization (--call_assumptions Option)
You can control program-level optimization, which you invoke with --program_level_compile --opt_level=3, by using the --call_assumptions option. Specifically, the --call_assumptions option indicates if functions in other modules can call a module's external functions or modify a module's external variables. The number following --call_assumptions indicates the level you set for the module that you are allowing to be called or modified. The --opt_level=3 option combines this information with its own file-level analysis to decide whether to treat this module's external function and variable declarations as if they had been declared static. Use
to select the appropriate level to append to the --call_assumptions option.
Table 3-4. Selecting a Level for the --call_assumptions Option
If Your Module
…
Has functions that are called from other modules and global variables that are modified in other modules
Use this Option
--call_assumptions=0
--call_assumptions=1 Does not have functions that are called by other modules but has global variables that are modified in other modules
Does not have functions that are called by other modules or global variables that are modified in other modules
Has functions that are called from other modules but does not have global variables that are modified in other modules
--call_assumptions=2
--call_assumptions=3
In certain circumstances, the compiler reverts to a different --call_assumptions level from the one you specified, or it might disable program-level optimization altogether.
lists the combinations of
--call_assumptions levels and conditions that cause the compiler to revert to other --call_assumptions levels.
50
Optimizing Your Code
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Performing Program-Level Optimization (--program_level_compile and --opt_level=3 options)
Table 3-5. Special Considerations When Using the --call_assumptions Option
If Your Option is...
Not specified
Not specified
Not specified
--call_assumptions=1 or
--call_assumptions=2
--call_assumptions=1 or
--call_assumptions=2
--call_assumptions=1 or
--call_assumptions=2
--call_assumptions=3
Under these Conditions...
The --opt_level=3 optimization level was specified
The compiler sees calls to outside functions under the
--opt_level=3 optimization level
Main is not defined
No function has main defined as an entry point and functions are not identified by the FUNC_EXT_CALLED pragma
No interrupt function is defined
Functions are identified by the FUNC_EXT_CALLED pragma
Any condition
Then the --call_assumptions
Level...
Defaults to --call_assumptions=2
Reverts to --call_assumptions=0
Reverts to --call_assumptions=0
Reverts to --call_assumptions=0
Reverts to --call_assumptions=0
Remains --call_assumptions=1 or --call_assumptions=2
Remains --call_assumptions=3
In some situations when you use --program_level_compile and --opt_level=3, you must use a
--call_assumptions option or the FUNC_EXT_CALLED pragma. See
for information about these situations.
3.3.2 Optimization Considerations When Mixing C/C++ and Assembly
If you have any assembly functions in your program, you need to exercise caution when using the
--program_level_compile option. The compiler recognizes only the C/C++ source code and not any assembly code that might be present. Because the compiler does not recognize the assembly code calls and variable modifications to C/C++ functions, the --program_level_compile option optimizes out those
C/C++ functions. To keep these functions, place the FUNC_EXT_CALLED pragma (see
) before any declaration or reference to a function that you want to keep.
Another approach you can take when you use assembly functions in your program is to use the
--call_assumptions=n option with the --program_level_compile and --opt_level=3 options (see
In general, you achieve the best results through judicious use of the FUNC_EXT_CALLED pragma in combination with --program_level_compile --opt_level=3 and --call_assumptions=1 or
--call_assumptions=2.
If any of the following situations apply to your application, use the suggested solution:
Situation— Your application consists of C/C++ source code that calls assembly functions. Those assembly functions do not call any C/C++ functions or modify any C/C++ variables.
Solution — Compile with --program_level_compile --opt_level=3 --call_assumptions=2 to tell the compiler that outside functions do not call C/C++ functions or modify C/C++ variables. See
for information about the --call_assumptions=2 option.
If you compile with the --program_level_compile --opt_level=3 options only, the compiler reverts from the default optimization level (--call_assumptions=2) to --call_assumptions=0. The compiler uses --call_assumptions=0, because it presumes that the calls to the assembly language functions that have a definition in C/C++ may call other C/C++ functions or modify C/C++ variables.
Situation— Your application consists of C/C++ source code that calls assembly functions. The assembly language functions do not call C/C++ functions, but they modify C/C++ variables.
Solution— Try both of these solutions and choose the one that works best with your code:
•
Compile with --program_level_compile --opt_level=3 --call_assumptions=1.
•
Add the volatile keyword to those variables that may be modified by the assembly functions and compile with --program_level_compile --opt_level=3 --call_assumptions=2.
See
for information about the --call_assumptions=n option.
SLAU132D – June 2009
Submit Documentation Feedback
Optimizing Your Code
51
Accessing Aliased Variables in Optimized Code
www.ti.com
Situation— Your application consists of C/C++ source code and assembly source code. The assembly functions are interrupt service routines that call C/C++ functions; the C/C++ functions that the assembly functions call are never called from C/C++. These C/C++ functions act like main: they function as entry points into C/C++.
Solution— Add the volatile keyword to the C/C++ variables that may be modified by the interrupts. Then, you can optimize your code in one of these ways:
•
You achieve the best optimization by applying the FUNC_EXT_CALLED pragma to all of the entry-point functions called from the assembly language interrupts, and then compiling with
--program_level_compile --opt_level=3 --call_assumptions=2. Be sure that you use the pragma
with all of the entry-point functions. If you do not, the compiler might remove the entry-point functions that are not preceded by the FUNC_EXT_CALLED pragma.
•
Compile with --program_level_compile --opt_level=3 --call_assumptions=3. Because you do not use the FUNC_EXT_CALLED pragma, you must use the --call_assumptions=3 option, which is less aggressive than the --call_assumptions=2 option, and your optimization may not be as effective.
Keep in mind that if you use --program_level_compile --opt_level=3 without additional options, the compiler removes the C functions that the assembly functions call. Use the FUNC_EXT_CALLED pragma to keep these functions.
3.4
Accessing Aliased Variables in Optimized Code
Aliasing occurs when a single object can be accessed in more than one way, such as when two pointers point to the same object or when a pointer points to a named object. Aliasing can disrupt optimization because any indirect reference can refer to another object. The optimizer analyzes the code to determine where aliasing can and cannot occur, then optimizes as much as possible while still preserving the correctness of the program. The optimizer behaves conservatively. If there is a chance that two pointers are pointing to the same object, then the optimizer assumes that the pointers do point to the same object.
The compiler assumes that if the address of a local variable is passed to a function, the function changes the local variable by writing through the pointer. This makes the local variable's address unavailable for use elsewhere after returning. For example, the called function cannot assign the local variable's address to a global variable or return the local variable's address. In cases where this assumption is invalid, use the --aliased_variables compiler option to force the compiler to assume worst-case aliasing. In worst-case aliasing, any indirect reference can refer to such a variable.
3.4.1 Use Caution With asm Statements in Optimized Code
You must be extremely careful when using asm (inline assembly) statements in optimized code. The compiler rearranges code segments, uses registers freely, and can completely remove variables or expressions. Although the compiler never optimizes out an asm statement (except when it is unreachable), the surrounding environment where the assembly code is inserted can differ significantly from the original C/C++ source code.
It is usually safe to use asm statements to manipulate hardware controls such as interrupt masks, but asm statements that attempt to interface with the C/C++ environment or access C/C++ variables can have unexpected results. After compilation, check the assembly output to make sure your asm statements are correct and maintain the integrity of the program.
52
Optimizing Your Code
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Automatic Inline Expansion (--auto_inline Option)
3.5
Automatic Inline Expansion (--auto_inline Option)
When optimizing with the --opt_level=3 option(aliased as -O3), the compiler automatically inlines small functions. A command-line option, --auto_inline=size, specifies the size threshold. Any function larger than the size threshold is not automatically inlined. You can use the --auto_inline=size option in the following ways:
•
If you set the size parameter to 0 (--auto_inline=0), automatic inline expansion is disabled.
•
If you set the size parameter to a nonzero integer, the compiler uses this size threshold as a limit to the size of the functions it automatically inlines. The compiler multiplies the number of times the function is inlined (plus 1 if the function is externally visible and its declaration cannot be safely removed) by the size of the function.
The compiler inlines the function only if the result is less than the size parameter. The compiler measures the size of a function in arbitrary units; however, the optimizer information file (created with the
--gen_opt_level=1 or --gen_opt_level=2 option) reports the size of each function in the same units that the
--auto_inline option uses.
The --auto_inline=size option controls only the inlining of functions that are not explicitly declared as inline.
If you do not use the --auto_inline=size option, the compiler inlines very small functions.
Optimization Level 3 and Inlining
Note:
In order to turn on automatic inlining, you must use the --opt_level=3 option If you desire the
--opt_level=3 optimizations, but not automatic inlining, use --auto_inline=0 with the
--opt_level=3 option.
Inlining and Code Size
Note:
Expanding functions inline increases code size, especially inlining a function that is called in a number of places. Function inlining is optimal for functions that are called only from a small number of places and for small functions. To prevent increases in code size because of inlining, use the --auto_inline=0 and --no_inlining options. These options, used together, cause the compiler to inline intrinsics only.
3.6
Using the Interlist Feature With Optimization
You control the output of the interlist feature when compiling with optimization (the --opt_level=n or -On option) with the --optimizer_interlist and --c_src_interlist options.
•
The --optimizer_interlist option interlists compiler comments with assembly source statements.
•
The --c_src_interlist and --optimizer_interlist options together interlist the compiler comments and the original C/C++ source with the assembly code.
When you use the --optimizer_interlist option with optimization, the interlist feature does not run as a separate pass. Instead, the compiler inserts comments into the code, indicating how the compiler has rearranged and optimized the code. These comments appear in the assembly language file as comments starting with ;**. The C/C++ source code is not interlisted, unless you use the --c_src_interlist option also.
The interlist feature can affect optimized code because it might prevent some optimization from crossing
C/C++ statement boundaries. Optimization makes normal source interlisting impractical, because the compiler extensively rearranges your program. Therefore, when you use the --optimizer_interlist option, the compiler writes reconstructed C/C++ statements.
shows a function that has been compiled with optimization (--opt_level=2) and the
--optimizer_interlist option. The assembly file contains compiler comments interlisted with assembly code.
Note: Impact on Performance and Code Size
The --c_src_interlist option can have a negative effect on performance and code size.
SLAU132D – June 2009
Submit Documentation Feedback
Optimizing Your Code
53
Using the Interlist Feature With Optimization
www.ti.com
When you use the --c_src_interlist and --optimizer_interlist options with optimization, the compiler inserts its comments and the interlist feature runs before the assembler, merging the original C/C++ source into the assembly file.
shows the function from
compiled with the optimization (--opt_level=2) and the
--c_src_interlist and --optimizer_interlist options. The assembly file contains compiler comments and C source interlisted with assembly code.
Example 3-1. The Function From
Compiled With the --opt_level=2 and
--optimizer_interlist Options
main:
;* -----------------------------------------------------------------------*
SUB.W
#2,SP
;** 5 ------------------------printf((const unsigned char *)"Hello, world\n");
MOV.W
#$C$SL1+0,0(SP) ; |5|
CALL #printf ; |5|
; |5|
;** 6 ------------------------return 0;
MOV.W
#0,r12 ; |6|
ADD.W
RET
#2,SP
Example 3-2. The Function From
Compiled with the --opt_level=2, --optimizer_interlist, and --c_src_interlist Options
main:
;* ----------------------------------------------------------------------------*
SUB.W
#2,SP
;** 5 ------------------------printf((const unsigned char *)"Hello, world\n");
;------------------------------------------------------------------------
; 5 | printf ("Hello, world\n");
;------------------------------------------------------------------------
MOV.W
CALL
#$C$SL1+0,0(SP)
#printf
; |5|
; |5|
; |5|
;** 6 ------------------------return 0;
;------------------------------------------------------------------------
; 6 | return 0;
;------------------------------------------------------------------------
MOV.W
#0,r12 ; |6|
ADD.W
RET
#2,SP
54
Optimizing Your Code
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Debugging Optimized Code
3.7
Debugging Optimized Code
Debugging fully optimized code is not recommended, because the compiler's extensive rearrangement of code and the many-to-many allocation of variables to registers often make it difficult to correlate source code with object code. Profiling code that has been built with the --symdebug:dwarf (aliased as -g) option or the --symdebug:coff option (STABS debug) is not recommended as well, because these options can significantly degrade performance. To remedy these problems, you can use the options described in the following sections to optimize your code in such a way that you can still debug or profile the code.
To debug optimized code, use the --opt_level option (aliased as -O) in conjunction with one of the symbolic debugging options (--symdebug:dwarf or --symdebug:coff). The symbolic debugging options generate directives that are used by the C/C++ source-level debugger, but they disable many compiler optimizations. When you use the --opt_level option (which invokes optimization) with the
--symdebug:dwarf or --symdebug:coff option, you turn on the maximum amount of optimization that is compatible with debugging.
If you want to use symbolic debugging and still generate fully optimized code, use the
--optimize_with_debug option. This option reenables the optimizations disabled by --symdebug:dwarf or
--symdebug:coff. However, if you use the --optimize_with_debug option, portions of the debugger's functionality will be unreliable.
Note: Symbolic Debugging Options Affect Performance and Code Size
Using the --symdebug:dwarf or --symdebug:coff option can cause a significant performance and code size degradation of your code. Use these options for debugging only. Using
--symdebug:dwarf or --symdebug:coff when profiling is not recommended.
3.8
Controlling Code Size Versus Speed
The latest mechanism for controlling the goal of optimizations in the compiler is represented by the
--opt_for_speed=num option. The num denotes the level of optimization (0-5), which controls the type and degree of code size or code speed optimization:
•
--opt_for_speed=0
Enables optimizations geared towards improving the code size with a high risk of worsening or impacting performance.
•
--opt_for_speed=1
Enables optimizations geared towards improving the code size with a medium risk of worsening or impacting performance.
•
--opt_for_speed=2
Enables optimizations geared towards improving the code size with a low risk of worsening or impacting performance.
•
--opt_for_speed=3
Enables optimizations geared towards improving the code performance/speed with a low risk of worsening or impacting performance.
•
--opt_for_speed=4
Enables optimizations geared towards improving the code performance/speed with a medium risk of worsening or impacting performance.
•
--opt_for_speed=5
Enables optimizations geared towards improving the code performance/speed with a high risk of worsening or impacting performance.
The default setting is --opt_for_speed=4.
SLAU132D – June 2009
Submit Documentation Feedback
Optimizing Your Code
55
What Kind of Optimization Is Being Performed?
www.ti.com
3.9
What Kind of Optimization Is Being Performed?
The MSP430 C/C++ compiler uses a variety of optimization techniques to improve the execution speed of your C/C++ programs and to reduce their size. See
for more information.
Following are some of the optimizations performed by the compiler:
Optimization
Cost-based register allocation
Alias disambiguation
Branch optimizations and control-flow simplification
Data flow optimizations
•
Copy propagation
•
Common subexpression elimination
•
Redundant assignment elimination
Expression simplification
Inline expansion of functions
Induction variable optimizations and strength reduction
Loop-invariant code motion
Loop rotation
Instruction scheduling
See
MSP430-Specific Optimization
Tail merging
Integer division with constant divisor
_never_executed() intrinsic
See
3.9.1 Cost-Based Register Allocation
The compiler, when optimization is enabled, allocates registers to user variables and compiler temporary values according to their type, use, and frequency. Variables used within loops are weighted to have priority over others, and those variables whose uses do not overlap can be allocated to the same register.
Induction variable elimination and loop test replacement allow the compiler to recognize the loop as a simple counting loop and software pipeline, unroll, or eliminate the loop. Strength reduction turns the array references into efficient pointer references with autoincrements.
3.9.2 Alias Disambiguation
C and C++ programs generally use many pointer variables. Frequently, compilers are unable to determine whether or not two or more I values (lowercase L: symbols, pointer references, or structure references) refer to the same memory location. This aliasing of memory locations often prevents the compiler from retaining values in registers because it cannot be sure that the register and memory continue to hold the same values over time.
Alias disambiguation is a technique that determines when two pointer expressions cannot point to the same location, allowing the compiler to freely optimize such expressions.
3.9.3 Branch Optimizations and Control-Flow Simplification
The compiler analyzes the branching behavior of a program and rearranges the linear sequences of operations (basic blocks) to remove branches or redundant conditions. Unreachable code is deleted, branches to branches are bypassed, and conditional branches over unconditional branches are simplified to a single conditional branch.
56
Optimizing Your Code
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
What Kind of Optimization Is Being Performed?
When the value of a condition is determined at compile time (through copy propagation or other data flow analysis), the compiler can delete a conditional branch. Switch case lists are analyzed in the same way as conditional branches and are sometimes eliminated entirely. Some simple control flow constructs are reduced to conditional instructions, totally eliminating the need for branches.
3.9.4 Data Flow Optimizations
Collectively, the following data flow optimizations replace expressions with less costly ones, detect and remove unnecessary assignments, and avoid operations that produce values that are already computed.
The compiler with optimization enabled performs these data flow optimizations both locally (within basic blocks) and globally (across entire functions).
•
Copy propagation. Following an assignment to a variable, the compiler replaces references to the variable with its value. The value can be another variable, a constant, or a common subexpression.
This can result in increased opportunities for constant folding, common subexpression elimination, or even total elimination of the variable.
•
Common subexpression elimination. When two or more expressions produce the same value, the compiler computes the value once, saves it, and reuses it.
•
Redundant assignment elimination. Often, copy propagation and common subexpression elimination optimizations result in unnecessary assignments to variables (variables with no subsequent reference before another assignment or before the end of the function). The compiler removes these dead assignments.
3.9.5 Expression Simplification
For optimal evaluation, the compiler simplifies expressions into equivalent forms, requiring fewer instructions or registers. Operations between constants are folded into single constants. For example, a =
(b + 4) - (c + 1) becomes a = b - c + 3.
3.9.6 Inline Expansion of Functions
The compiler replaces calls to small functions with inline code, saving the overhead associated with a function call as well as providing increased opportunities to apply other optimizations.
3.9.7 Induction Variables and Strength Reduction
Induction variables are variables whose value within a loop is directly related to the number of executions of the loop. Array indices and control variables for loops are often induction variables.
Strength reduction is the process of replacing inefficient expressions involving induction variables with more efficient expressions. For example, code that indexes into a sequence of array elements is replaced with code that increments a pointer through the array.
Induction variable analysis and strength reduction together often remove all references to your loop-control variable, allowing its elimination.
3.9.8 Loop-Invariant Code Motion
This optimization identifies expressions within loops that always compute to the same value. The computation is moved in front of the loop, and each occurrence of the expression in the loop is replaced by a reference to the precomputed value.
3.9.9 Loop Rotation
The compiler evaluates loop conditionals at the bottom of loops, saving an extra branch out of the loop. In many cases, the initial entry conditional check and the branch are optimized out.
SLAU132D – June 2009
Submit Documentation Feedback
Optimizing Your Code
57
What Kind of Optimization Is Being Performed?
www.ti.com
3.9.10 Instruction Scheduling
The compiler performs instruction scheduling, which is the rearranging of machine instructions in such a way that improves performance while maintaining the semantics of the original order. Instruction scheduling is used to improve instruction parallelism and hide pipeline latencies. It can also be used to reduce code size.
3.9.11 Tail Merging
If you are optimizing for code size, tail merging can be very effective for some functions. Tail merging finds basic blocks that end in an identical sequence of instructions and have a common destination. If such a set of blocks is found, the sequence of identical instructions is made into its own block. These instructions are then removed from the set of blocks and replaced with branches to the newly created block. Thus, there is only one copy of the sequence of instructions, rather than one for each block in the set.
3.9.12 Integer Division With Constant Divisor
The optimizer attempts to rewrite integer divide operations with constant divisors. The integer divides are rewritten as a multiply with the reciprocal of the divisor. This occurs at optimization level 2 (--opt_level=2 or -O2) and higher. You must also compile with the --opt_for_speed option, which selects compile for speed.
3.9.13 _never_executed Intrinsic
The _never_executed( )intrinsic can be used to assert to the compiler that a switch expression can only take on values represented by the case labels within a switch block. This assertion enables the compiler to avoid generating test code for handling values not specified by the switch case labels. This assertion is specifically suited for handling values that characterize a vector generator. See
for details on the _never_executed( ) intrinsic.
58
Optimizing Your Code
SLAU132D – June 2009
Submit Documentation Feedback
Chapter 4
SLAU132D – June 2009
Linking C/C++ Code
The C/C++ compiler and assembly language tools provide two methods for linking your programs:
•
You can compile individual modules and link them together. This method is especially useful when you have multiple source files.
•
You can compile and link in one step. This method is useful when you have a single source module.
This chapter describes how to invoke the linker with each method. It also discusses special requirements of linking C/C++ code, including the run-time-support libraries, specifying the type of initialization, and allocating the program into memory. For a complete description of the linker, see the MSP430 Assembly
Language Tools User's Guide.
Topic
..................................................................................................
Page
4.1
Invoking the Linker Through the Compiler (-z Option)
4.2
..........................................................................
4.3
Linker Code Optimizations
.........................................................
4.4
Controlling the Linking Process
..................................................
SLAU132D – June 2009
Submit Documentation Feedback
Linking C/C++ Code
59
Invoking the Linker Through the Compiler (-z Option)
www.ti.com
4.1
Invoking the Linker Through the Compiler (-z Option)
This section explains how to invoke the linker after you have compiled and assembled your programs: as a separate step or as part of the compile step.
4.1.1 Invoking the Linker Separately
This is the general syntax for linking C/C++ programs as a separate step:
cl430 --run_linker {--rom_model | --ram_model} filenames
[options] [--output_file=name.out] --library=library [lnk.cmd]
cl430 --run_linker
--rom_model | --ram_model
filenames options
--output_file= name.out
--library= library
The command that invokes the linker.
Options that tell the linker to use special conventions defined by the
C/C++ environment. When you use cl430 --run_linker, you must use
--rom_model or --ram_model. The --rom_model option uses automatic variable initialization at run time; the --ram_model option uses variable initialization at load time.
Names of object files, linker command files, or archive libraries. The default extension for all input files is .obj; any other extension must be explicitly specified. The linker can determine whether the input file is an object or ASCII file that contains linker commands. The default output filename is a.out, unless you use the --output_file option to name the output file.
Options affect how the linker handles your object files. Linker options can only appear after the --run_linker option on the command line, but otherwise may be in any order. (Options are discussed in
.)
Names the output file.
Identifies the appropriate archive library containing C/C++ run-time-support and floating-point math functions, or linker command files. If you are linking C/C++ code, you must use a run-time-support library. You can use the libraries included with the compiler, or you can create your own run-time-support library. If you have specified a run-time-support library in a linker command file, you do not need this parameter. The --library option's short form is -l.
Contains options, filenames, directives, or commands for the linker.
lnk.cmd
When you specify a library as linker input, the linker includes and links only those library members that resolve undefined references. The linker uses a default allocation algorithm to allocate your program into memory. You can use the MEMORY and SECTIONS directives in the linker command file to customize the allocation process. For information, see the MSP430 Assembly Language Tools User's Guide.
You can link a C/C++ program consisting of modules prog1.obj, prog2.obj, and prog3.obj, with an executable filename of prog.out with the command: cl430 --run_linker --rom_model prog1 prog2 prog3 --output_file=prog.out
--library=rts430.lib
60
Linking C/C++ Code
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Invoking the Linker Through the Compiler (-z Option)
4.1.2 Invoking the Linker as Part of the Compile Step
This is the general syntax for linking C/C++ programs as part of the compile step:
cl430 filenames [options] --run_linker {--rom_model | --ram_model} filenames
[options] [--output_file=name.out] --library=library [lnk.cmd]
The --run_linker option divides the command line into the compiler options (the options before
--run_linker) and the linker options (the options following --run_linker). The --run_linker option must follow all source files and compiler options on the command line.
All arguments that follow --run_linker on the command line are passed to the linker. These arguments can be linker command files, additional object files, linker options, or libraries. These arguments are the same as described in
All arguments that precede --run_linker on the command line are compiler arguments. These arguments can be C/C++ source files, assembly files, or compiler options. These arguments are described in
.
You can compile and link a C/C++ program consisting of modules prog1.c, prog2.c, and prog3.c, with an executable filename of prog.out with the command: cl430 prog1.c prog2.c prog3.c --run_linker --rom_model --output_file=prog.out --library=rts430.lib
Note: Order of Processing Arguments in the Linker
The order in which the linker processes arguments is important. The compiler passes arguments to the linker in the following order:
1.
Object filenames from the command line
2.
Arguments following the --run_linker option on the command line
3.
Arguments following the --run_linker option from the MSP430_C_OPTION environment variable
4.1.3 Disabling the Linker (--compile_only Compiler Option)
You can override the --run_linker option by using the --compile_only compiler option. The -run_linker option's short form is -z and the --compile_only option's short form is -c.
The --compile_only option is especially helpful if you specify the --run_linker option in the
MSP430_C_OPTION environment variable and want to selectively disable linking with the --compile_only option on the command line.
SLAU132D – June 2009
Submit Documentation Feedback
Linking C/C++ Code
61
Linker Options
www.ti.com
4.2
Linker Options
All command-line input following the --run_linker option (aliased as -z) is passed to the linker as parameters and options. Following are the options that control the linker, along with descriptions of their effects.
--absolute_exe
-ar
--arg_size=size
--compress_dwarf
--define=name[=val]
--diag_error=num
--diag_remark=num
--diag_suppress=num
--diag_warning=num
--disable_auto_rts
--disable_clink
--disable_pp
--display_error_number=num
--entry_point=global_symbol
--fill_value=value
--generate_dead_funcs_list
--globalize='pattern'
--heap_size=size
Produces an absolute, executable module. This is the default; if neither
--absolute_exe nor --relocatable is specified, the linker acts as if
--absolute_exe is specified.
Produces a relocatable, executable object module. The output module contains the special linker symbols, an optional header, and all symbol references. The relocation information is retained.
Allocates memory to be used by the loader to pass arguments from the command line of the loader to the program. The linker allocates size bytes in an uninitialized .args section. The __c_args__ symbol contains the address of the .args section.
Aggressively reduces the size of DWARF information from input object files
Predefines name as a preprocessor macro. This option is distinct from the compiler --define option.
Categorizes the diagnostic identified by num as an error. See
for details.
Categorizes the diagnostic identified by num as a remark. See
for details.
Suppresses the diagnostic identified by num. See
for details.
Categorizes the diagnostic identified by num as a warning. See
for details.
Disables the automatic selection of a run-time-support library. See
for more information.
Disables conditional linking that has been set up with the assembler
.clink directive for COFF object files. By default, all sections are unconditionally linked.
Disables preprocessing for command files. By default, the linker now preprocesses link command files using a standard C preprocessor.
Displays a diagnostic's identifiers along with its text. See
for more information.
Defines a global_symbol that specifies the primary entry point for the output module
Sets the default fill value for null areas within output sections; value is a
16-bit constant
Writes a list of the dead functions that were removed by the linker to file fname for object files
Changes the symbol linkage to global for symbols that match pattern.
The --globalize option only affects symbols that are localized by the
--localize option.
Sets the heap size (for dynamic memory allocation) to size bytes and defines a global symbol that specifies the heap size. The default is 128 bytes.
62
Linking C/C++ Code
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
--hide="pattern"
--issue_remarks
--library= libraryname
--linker_help
--localize='pattern'
--make_global=global_symbol
--make_static
--map_file=filename
--mapfile_contents=filter[,filter]
--no_demangle
--no_sym_merge
--no_sym_table
--no_warnings
--output_file=filename
--priority
--ram_model
--relocatable
--reread_libs
--rom_model
--run_abs
--runtime={c95|cpp|rts}
--scan_libraries
Linker Options
Hides global symbols that match pattern by changing the name to an empty string
Issues remarks (nonserious warnings). See
for more information.
Names an archive library file or linker command filename as linker input.
The libraryname is an archive library name and must follow operating system conventions. The --library option's short form is -l.
Produces a help listing displaying syntax and available options
Changes the symbol linkage to local for symbols that match pattern
Defines global_symbol as global even if the global symbol has been made static with the --make_static option
Makes all global symbols static; global symbols are essentially hidden.
This allows external symbols with the same name (in different files) to be treated as unique.
Produces a map or listing of the input and output sections, including null areas, and places the listing in filename. The filename must follow operating system conventions.
Controls the information that appears in the map file. Enter
--mapfile_contents=help on the command line to produce a listing of available options.
Disables demangling of symbol names in diagnostics
Disables merge of symbolic debugging information in COFF object files.
The linker keeps the duplicate entries of symbolic debugging information commonly generated when a C program is compiled for debugging. (Deprecated option; use the strip utility described in the
MSP430 Assembly Language Tools User's Guide.
Creates a smaller output section by stripping symbol table information and line number entries from the output module.
Suppresses warning diagnostics (errors are still issued). See
for more information.
Names the executable output module. The filename must follow operating system conventions. If the --output_file option is not used, the default filename is a.out.
Satisfies each unresolved reference by the first library that contains a definition for that symbol
Initializes variables at load time. See
for more information.
Retains relocation entries in the output module.
Forces rereading of libraries. The linker continues to reread libraries until no more references can be resolved.
Autoinitializes variables at run time. See
for more information.
Produces an absolute listing file.
Designates the header file include path to use for different libraries
(default is rts). See for more information.
Scans all libraries during a link to look for duplicate symbol definitions to those symbols that are actually included in the link.
SLAU132D – June 2009
Submit Documentation Feedback
Linking C/C++ Code
63
Linker Options
--search_path=directory
--set_error_limit=num
--stack_size=size
--strict_compatibility
--symbol_map=refname=defname
--undef_sym=symbol
--undefine=name
--unhide="pattern"
--use_hw_mpy[={16|32|F5}]
--verbose_diagnostics
--warn_sections
--xml_link_info=file www.ti.com
Alters the library-search algorithm to look in directory before looking in the default location. This option must appear before the --library option.
The directory must follow operating system conventions. You can specify up to 128 --search_path options. The --search_path option's short form is -
I
.
Sets the error limit to num. The linker abandons linking after this number of errors. (The default is 100.) See
for more information.
Sets the C/C++ system stack size to size bytes and defines a global symbol that specifies the stack size. The default is 128 bytes.
Performs more conservative and rigorous compatibility checking of input object files.
Enables symbol mapping, which allows a symbol reference to be resolved by a symbol with a different name.
Places the unresolved external symbol symbol into the output module's symbol table. This forces the linker to search a library and include the member that defines the symbol.
Removes the preprocessor macro name. This option is distinct from the compiler --undefine option.
Reveals (un-hides) global symbols that match pattern that are hidden by the --hide option
Replaces all references to the default integer/long multiply routine with the version of the multiply routine that uses hardware multiplier support.
The optional argument can be 16 for 16-bit hardware multiplier (default);
32 for F4xxx 32-bit hardware multiplier; or F5 for F5xxx 32-bit hardware multiplier.
Provides verbose diagnostics that display the original source with line-wrap. See
for more information.
Displays a message when the linker encounters one or more input sections that do not have a corresponding output section defined in the
SECTIONS directive.
Generates an XML link information file. This option causes the linker to generate a well-formed XML file containing detailed information about the result of a link. The information included in this file includes all of the information that is currently produced in a linker generated map file.
For more information on linker options, see the MSP430 Assembly Language Tools User's Guide.
64
Linking C/C++ Code
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Linker Code Optimizations
4.3
Linker Code Optimizations
These options are used to further optimize your code.
4.3.1 Generate List of Dead Functions (--generate_dead_funcs_list Option)
In order to facilitate the removal of unused code, the linker generates a feedback file containing a list of functions that are never referenced. The feedback file must be used the next time you compile the source files. The syntax for the --generate_dead_funcs_list option is:
--generate_dead_funcs_list= filename
If filename is not specified, a default filename of dead_funcs.txt is used.
Proper creation and use of the feedback file entails the following steps:
1. Compile all source files using the --gen_func_subsections compiler option. For example: cl430 file1.c file2.c --gen_func_subsections
2. During the linker, use the --generate_dead_funcs_list option to generate the feedback file based on the generated object files. For example: cl430 --run_linker file1.obj file2.obj
--generate_dead_funcs_list=feedback.txt
Alternatively, you can combine steps 1 and 2 into one step. When you do this, you are not required to specify --gen_func_subsections when compiling the source files as this is done for you automatically.
For example: cl430 file1.c file2.c --run_linker --generate_dead_funcs_list=feedback.txt
3. Once you have the feedback file, rebuild the source. Give the feedback file to the compiler using the
--use_dead_funcs_list option. This option forces each dead function listed in the file into its own subsection. For example: cl430 file1.c file2.c --use_dead_funcs_list=feedback.txt
4. Invoke the linker with the newly built object files. The linker removes the subsections. For example: cl430 --run_linker file1.obj file2.obj
Alternatively, you can combine steps 3 and 4 into one step. For example: cl430 file1.c file2.c --use_dead_funcs_list=feedback.txt --run_linker
Note: Dead Functions Feedback
The feedback file generated with the -gen_dead_funcs_list option is version controlled. It must be generated by the linker in order to be processed correctly by the compiler.
4.3.2 Generating Function Subsections (--gen_func_subsections Compiler Option)
When the linker places code into an executable file, it allocates all the functions in a single source file as a group. This means that if any function in a file needs to be linked into an executable, then all the functions in the file are linked in. This can be undesirable if a file contains many functions and only a few are required for an executable.
This situation may exist in libraries where a single file contains multiple functions, but the application only needs a subset of those functions. An example is a library .obj file that contains a signed divide routine and an unsigned divide routine. If the application requires only signed division, then only the signed divide routine is required for linking. By default, both the signed and unsigned routines are linked in since they exist in the same .obj file.
The --gen_func_subsections compiler option remedies this problem by placing each function in a file in its own subsection. Thus, only the functions that are referenced in the application are linked into the final executable. This can result in an overall code size reduction.
SLAU132D – June 2009
Submit Documentation Feedback
Linking C/C++ Code
65
Controlling the Linking Process
4.4
Controlling the Linking Process
www.ti.com
Regardless of the method you choose for invoking the linker, special requirements apply when linking
C/C++ programs. You must:
•
Include the compiler's run-time-support library
•
Specify the type of initialization
•
Determine how you want to allocate your program into memory
This section discusses how these factors are controlled and provides an example of the standard default linker command file.
For more information about how to operate the linker, see the linker description in the MSP430 Assembly
Language Tools User's Guide.
4.4.1 Including the Run-Time-Support Library
You must include a run-time-support library in the linker process. The following sections describe two methods for including the run-time-support library.
4.4.1.1
Manual Run-Time-Support Library Selection
You must link all C/C++ programs with a run-time-support library. The library contains standard C/C++ functions as well as functions used by the compiler to manage the C/C++ environment. You must use the
--library linker option to specify which MSP430 run-time-support library to use. The --library option also tells the linker to look at the --search_path options and then the MSP430_C_DIR environment variable to find an archive path or object file. To use the --library linker option, type on the command line:
cl430 --run_linker {--rom_model | --ram_model} filenames --library=libraryname
Generally, you should specify the run-time-support library as the last name on the command line because the linker searches libraries for unresolved references in the order that files are specified on the command line. If any object files follow a library, references from those object files to that library are not resolved.
You can use the --reread_libs option to force the linker to reread all libraries until references are resolved.
Whenever you specify a library as linker input, the linker includes and links only those library members that resolve undefined references.
By default, if a library introduces an unresolved reference and multiple libraries have a definition for it, then the definition from the same library that introduced the unresolved reference is used. Use the --priority option if you want the linker to use the definition from the first library on the command line that contains the definition.
4.4.1.2
Automatic Run-Time-Support Library Selection
If the --rom_model or --ram_model option is specified during the linker and the entry point for the program
(normally c_int00) is not resolved by any specified object file or library, the linker attempts to automatically include the best compatible run-time-support library for your program. The chosen run-time-support library is linked in as if it was specified with the --library option last on the command line. Alternatively, you can always force the linker to choose an appropriate run-time-support library by specifying “libc.a” as an argument to the --library option, or when specifying the run-time-support library name explicitly in a linker command file.
The automatic selection of a run-time-support library can be disabled with the --disable_auto_rts option.
If the --issue_remarks option is specified before the --run_linker option during the linker, a remark is generated indicating which run-time support library was linked in. If a different run-time-support library is desired, you must specify the name of the desired run-time-support library using the --library option and in your linker command files when necessary.
66
Linking C/C++ Code
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
For example: cl430 --issue_remarks main.c --run_linker --rom_model
<Linking> remark: linking in "libc.a" remark: linking in "rts430.lib" in place of "libc.a"
Controlling the Linking Process
4.4.2 Run-Time Initialization
You must link all C/C++ programs with code to initialize and execute the program called a bootstrap routine. The bootstrap routine is responsible for the following tasks:
•
Set up the stack
•
Process the .cinit run-time initialization table to autoinitialize global variables (when using the
--rom_model option)
•
Call all global constructors (.pinit) for C++
•
Call main.com
•
Call exit when main returns
A sample bootstrap routine is _c_int00, provided in boot.obj in the run-time support object libraries. The entry point is usually set to the starting address of the bootstrap routine.
Note: The _c_int00 Symbol
If you use the --ram_model or --rom_model link option, _c_int00 is automatically defined as the entry point for the program.
4.4.3 Initialization by the Interrupt Vector
If your program begins running from load time, you must set up the reset vector to branch to _c_int00.
This causes boot.obj to be loaded from the library and your program is initialized correctly. The boot.obj
places the address of _c_int00 into a section named .reset. This section can then be allocated at the reset vector location using the linker.
4.4.4 Global Object Constructors
Global C++ variables that have constructors and destructors require their constructors to be called during program initialization and their destructors to be called during program termination. The C++ compiler produces a table of constructors to be called at startup.
The constructors are invoked in the order that they occur in the table.
Global constructors are called after initialization of other global variables and before main( ) is called.
Global destructors are invoked during exit( ), similar to functions registered through atexit( ).
discusses the format of the global constructor table.
SLAU132D – June 2009
Submit Documentation Feedback
Linking C/C++ Code
67
Controlling the Linking Process
www.ti.com
4.4.5 Specifying the Type of Global Variable Initialization
The C/C++ compiler produces data tables for initializing global variables. discusses the format of these initialization tables. The initialization tables are used in one of the following ways:
•
Global variables are initialized at run time. Use the --rom_model linker option (see
•
Global variables are initialized at load time. Use the --ram_model linker option (see
).
When you link a C/C++ program, you must use either the --rom_model or --ram_model option. These options tell the linker to select initialization at run time or load time.
When you compile and link programs, the --rom_model option is the default. If used, the --rom_model option must follow the --run_linker option (see
). The following list outlines the linking conventions used with --rom_model or --ram_model:
•
The symbol _c_int00 is defined as the program entry point; it identifies the beginning of the C/C++ boot routine in boot.obj. When you use --rom_model or --ram_model, _c_int00 is automatically referenced, ensuring that boot.obj is automatically linked in from the run-time-support library.
•
The initialization output section is padded with a termination record so that the loader (load-time initialization) or the boot routine (run-time initialization) knows when to stop reading the initialization tables.
•
The global constructor output section is padded with a termination record.
•
When initializing at load time (the --ram_model option), the following occur:
– The linker sets the initialization table symbol to -1. This indicates that the initialization tables are not in memory, so no initialization is performed at run time.
– The STYP_COPY flag is set in the initialization table section header. STYP_COPY is the special attribute that tells the loader to perform autoinitialization directly and not to load the initialization table into memory. The linker does not allocate space in memory for the initialization table.
•
When autoinitializing at run time (--rom_model option), the linker defines the initialization table symbol as the starting address of the initialization table. The boot routine uses this symbol as the starting point for autoinitialization.
•
The linker defines the starting address of the global constructor table. The boot routine uses this symbol as the beginning of the table of global constructors.
Note: Boot Loader
A loader is not included as part of the C/C++ compiler tools.
4.4.6 Specifying Where to Allocate Sections in Memory
The compiler produces relocatable blocks of code and data. These blocks, called sections, are allocated in memory in a variety of ways to conform to a variety of system configurations.
The compiler creates two basic kinds of sections: initialized and uninitialized.
summarizes the initialized sections.
summarizes the uninitialized sections.
Name
.cinit
.const
Table 4-1. Initialized Sections Created by the Compiler
Contents
Tables for explicitly initialized global and static variables
Global and static const variables that are explicitly initialized and contain string literals
.econst
.pinit
.text
Table of constructors to be called at startup
Executable code and constants
68
Linking C/C++ Code
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Controlling the Linking Process
Name
.args
.bss
.stack
.sysmem
Table 4-2. Uninitialized Sections Created by the Compiler
Contents
Linker-created section used to pass arguments from the command line of the loader to the program
Global and static variables
Stack
Memory for malloc functions (heap)
When you link your program, you must specify where to allocate the sections in memory. In general, initialized sections are linked into ROM or RAM; uninitialized sections are linked into RAM. With the exception of .text, the initialized and uninitialized sections created by the compiler cannot be allocated into internal program memory. See
for a complete description of how the compiler uses these sections.
The linker provides MEMORY and SECTIONS directives for allocating sections. For more information about allocating sections into memory, see the MSP430 Assembly Language Tools User's Guide.
4.4.7 A Sample Linker Command File
shows a typical linker command file that links a 32-bit C program. The command file in this example is named lnk32.cmd and lists several link options:
––rom_model
--stack_size
--heap_size
--library
Tells the linker to use autoinitialization at run time
Tells the linker to set the C stack size at 0x140 bytes
Tells the linker to set the heap size to 0x120 bytes
Tells the linker to use an archive library file, rts430.lib
To link the program, enter:
cl430 --run_linker object_file(s) --output_file=file --map_file=file lnk.cmd
SLAU132D – June 2009
Submit Documentation Feedback
Linking C/C++ Code
69
Controlling the Linking Process
Example 4-1. Linker Command File
--rom_model
--stack_size=0x0140
--heap_size=0x120
--library=rts430.lib
/*****************************************************************************/
/* SPECIFY THE SYSTEM MEMORY MAP */
/*****************************************************************************/
MEMORY
{
SFR(R) : origin = 0x0000, length = 0x0010
PERIPHERALS_8BIT : origin = 0x0010, length = 0x00F0
PERIPHERALS_16BIT: origin = 0x0100, length = 0x0100
RAM(RW) : origin = 0x0200, length = 0x0800
INFOA
INFOB
: origin = 0x1080, length = 0x0080
: origin = 0x1000, length = 0x0080
FLASH
VECTORS(R)
RESET
: origin = 0x1100, length = 0xEEE0
: origin = 0xFFE0, length = 0x001E
: origin = 0xFFFE, length = 0x0002
}
/****************************************************************************/
/* SPECIFY THE SECTIONS ALLOCATION INTO MEMORY */
/****************************************************************************/
SECTIONS
{
.bss
: {} > RAM
.sysmem
: {} > RAM
.stack
: {} > RAM
.text
: {} > FLASH
.cinit
: {} > FLASH
.const
: {} > FLASH
.cio
: {} > RAM
.pinit
: {} > RAM
.intvecs : {} > VECTORS
.reset
: {} > RESET
/* GLOBAL & STATIC VARS
/* DYNAMIC MEMORY ALLOCATION AREA
/* SOFTWARE SYSTEM STACK
/* CODE
/* INITIALIZATION TABLES
/* CONSTANT DATA
/* C I/O BUFFER
/* C++ CONSTRUCTOR TABLES
/* MSP430 INTERRUPT VECTORS
/* MSP430 RESET VECTOR
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/ www.ti.com
70
Linking C/C++ Code
SLAU132D – June 2009
Submit Documentation Feedback
Chapter 5
SLAU132D – June 2009
MSP430 C/C++ Language Implementation
The C/C++ compiler supports the C/C++ language standard that was developed by a committee of the
American National Standards Institute (ANSI) and subsequently adopted by the International Standards
Organization (IS0).
The C++ language supported by the MSP430 is defined by the ANSI/ISO/IEC 14882:1998 standard with certain exceptions.
Topic
..................................................................................................
Page
5.1
......................................................
5.2
Characteristics of MSP430 C++
...................................................
5.3
...............................................................................
5.4
Keywords
.................................................................................
5.5
............................................................
5.6
Register Variables and Parameters
.............................................
5.7
...................................................................
5.8
.....................................................................
5.9
...............................................................
5.10
Generating Linknames
...............................................................
5.11
Initializing Static and Global Variables
.........................................
5.12
Changing the ANSI/ISO C Language Mode
...................................
5.13
GNU C Compiler Extensions
.......................................................
5.14
Compiler Limits
........................................................................
SLAU132D – June 2009
Submit Documentation Feedback
MSP430 C/C++ Language Implementation
71
Characteristics of MSP430 C
www.ti.com
5.1
Characteristics of MSP430 C
The compiler supports the C language as defined by ISO/IEC 9899:1990, which is equivalent to American
National Standard for Information Systems-Programming Language C X3.159-1989 standard, commonly referred to as C89, published by the American National Standards Institute. The compiler can also accept many of the language extensions found in the GNU C compiler (see
). The compiler does not support C99.
The ANSI/ISO standard identifies some features of the C language that are affected by characteristics of the target processor, run-time environment, or host environment. For reasons of efficiency or practicality, this set of features can differ among standard compilers.
Unsupported features of the C library are:
•
The run-time library has minimal support for wide and multi-byte characters. The type wchar_t is implemented as int. The wide character set is equivalent to the set of values of type char. The library includes the header files <wchar.h> and <wctype.h>, but does not include all the functions specified in the standard. So-called multi-byte characters are limited to single characters. There are no shift states.
The mapping between multi-byte characters and wide characters is simple equivalence; that is, each wide character maps to and from exactly a single multi-byte character having the same value.
•
The run-time library includes the header file <locale.h>, but with a minimal implementation. The only supported locale is the C locale. That is, library behavior that is specified to vary by locale is hard-coded to the behavior of the C locale, and attempting to install a different locale by way of a call to setlocale() will return NULL.
5.2
Characteristics of MSP430 C++
The MSP430 compiler supports C++ as defined in the ANSI/ISO/IEC 14882:1998 standard, including these features:
•
Complete C++ standard library support, with exceptions noted below.
•
Templates
•
Exceptions, which are enabled with the --exceptions option; see
•
Run-time type information (RTTI), which can be enabled with the --rtti compiler option.
The exceptions to the standard are as follows:
•
The <complex> header and its functions are not included in the library.
•
The library supports wide chars, in that template functions and classes that are defined for char are also available for wide char. For example, wide char stream classes wios, wiostream, wstreambuf and so on (corresponding to char classes ios, iostream, streambuf) are implemented. However, there is no low-level file I/O for wide chars. Also, the C library interface to wide char support (through the C++ headers <cwchar> and <cwctype>) is limited as described above in the C library.
•
If the definition of an inline function contains a static variable, and it appears in multiple compilation units (usually because it’s a member function of a class defined in a header file), the compiler generates multiple copies of the static variable rather than resolving them to a single definition. The compiler emits a warning (#1369) in such cases.
•
The reinterpret_cast type does not allow casting a pointer-to-member of one class to a pointer-to-member of another class if the classes are unrelated.
•
Two-phase name binding in templates, as described in [tesp.res] and [temp.dep] of the standard, is not implemented.
•
Template parameters are not implemented.
•
The export keyword for templates is not implemented.
•
A typedef of a function type cannot include member function cv-qualifiers.
•
A partial specialization of a class member template cannot be added outside of the class definition.
72
MSP430 C/C++ Language Implementation
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Data Types
5.3
Data Types
lists the size, representation, and range of each scalar data type for the MSP430 compiler.
Many of the range values are available as standard macros in the header file limits.h.
Table 5-1. MSP430 C/C++ Data Types
Type
char, signed char unsigned char, bool short, signed short
Size Representation Minimum
8 bits ASCII -128
8 bits ASCII 0
16 bits 2s complement -32 768 unsigned short, wchar_t 16 bits Binary int, signed int unsigned int
16 bits
16 bits
2s complement
Binary
0
-32 768
0 long, signed long unsigned long enum float double long double pointers, references, pointer to data members
32 bits
32 bits
2s complement
Binary
-2 147 483 648
0
16 bits 2s complement -32 768
32 bits IEEE 32-bit 1.175 495e-38
(1)
32 bits IEEE 32-bit 1.175 495e-38
(1)
32 bits IEEE 32-bit 1.175 495e-308
(1)
16 bits Binary 0
MSP430X large-data model pointers, references, pointer to data members
(2)
20 bits Binary
MSP430 function pointers 16 bits Binary
MSP430X function pointers
(3)
20 bits Binary
0
0
0
Range
Maximum
-127
255
32 767
65 535
32 767
65 535
2 147 483 647
4 294 967 295
32 767
3.40 282 35e+38
3.40 282 35e+38
3.40 282 35e+38
0xFFFF
0xFFFFF
0xFFFF
0xFFFFF
(1)
(2)
(3)
Figures are minimum precision.
MSP430X large-data model is specified by --silicon_version=mspx --large_memory_model
MSP430X devices are specified by --silicon_version=mspx
SLAU132D – June 2009
Submit Documentation Feedback
MSP430 C/C++ Language Implementation
73
Keywords
www.ti.com
5.4
Keywords
The MSP430 C/C++ compiler supports the standard const, restrict, and volatile keywords. In addition, the
C/C++ compiler extends the C/C++ language through the support of the interrupt keyword.
5.4.1 The const Keyword
The C/C++ compiler supports the ANSI/ISO standard keyword const. This keyword gives you greater optimization and control over allocation of storage for certain data objects. You can apply the const qualifier to the definition of any variable or array to ensure that its value is not altered.
If you define an object as const, the .const section allocates storage for the object. The const data storage allocation rule has two exceptions:
•
If the keyword volatile is also specified in the definition of an object (for example, volatile const int x).
Volatile keywords are assumed to be allocated to RAM. (The program does not modify a const volatile object, but something external to the program might.)
•
If the object has automatic storage (function scope).
In both cases, the storage for the object is the same as if the const keyword were not used.
The placement of the const keyword within a definition is important. For example, the first statement below defines a constant pointer p to a variable int. The second statement defines a variable pointer q to a constant int: int * const p = &x; const int * q = &x;
Using the const keyword, you can define large constant tables and allocate them into system ROM. For example, to allocate a ROM table, you could use the following definition: const int digits[] = {0,1,2,3,4,5,6,7,8,9};
5.4.2 The interrupt Keyword
The compiler extends the C/C++ language by adding the interrupt keyword, which specifies that a function is treated as an interrupt function.
Functions that handle interrupts follow special register-saving rules and a special return sequence. The implementation stresses safety. The interrupt routine does not assume that the C run-time conventions for the various CPU register and status bits are in effect; instead, it re-establishes any values assumed by the run-time environment. When C/C++ code is interrupted, the interrupt routine must preserve the contents of all machine registers that are used by the routine or by any function called by the routine. When you use the interrupt keyword with the definition of the function, the compiler generates register saves based on the rules for interrupt functions and the special return sequence for interrupts.
You can only use the interrupt keyword with a function that is defined to return void and that has no parameters. The body of the interrupt function can have local variables and is free to use the stack or global variables. For example: interrupt void int_handler()
{ unsigned int flags;
...
}
The name c_int00 is the C/C++ entry point. This name is reserved for the system reset interrupt. This special interrupt routine initializes the system and calls the function main. Because it has no caller, c_int00 does not save any registers.
Use the alternate keyword, __interrupt, if you are writing code for strict ANSI/ISO mode (using the
--strict_ansi compiler option).
74
MSP430 C/C++ Language Implementation
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
HWI Objects and the interrupt Keyword
Note:
The interrupt keyword must not be used when BIOS HWI objects are used in conjunction with C functions. The HWI_enter/HWI_exit macros and the HWI dispatcher contain this functionality, and the use of the C modifier can cause negative results.
Keywords
5.4.3 The restrict Keyword
To help the compiler determine memory dependencies, you can qualify a pointer, reference, or array with the restrict keyword. The restrict keyword is a type qualifier that can be applied to pointers, references, and arrays. Its use represents a guarantee by you, the programmer, that within the scope of the pointer declaration the object pointed to can be accessed only by that pointer. Any violation of this guarantee renders the program undefined. This practice helps the compiler optimize certain sections of code because aliasing information can be more easily determined.
In
the pointers a and b pointing to objects that overlap in memory. You are promising that accesses through a and b will never conflict; therefore, a write through one pointer cannot affect a read from any other pointers. The precise semantics of the restrict keyword are described in the 1999 version of the ANSI/ISO
C Standard.
Example 5-1. Use of the restrict Type Qualifier With Pointers
void func1(int * restrict a, int * restrict b)
{
/* func1's code here */
}
illustrates using the restrict keyword when passing arrays to a function. Here, the arrays c and d should not overlap, nor should c and d point to the same array.
Example 5-2. Use of the restrict Type Qualifier With Arrays
void func2(int c[restrict], int d[restrict])
{ int i;
} for(i = 0; i < 64; i++)
{ c[i] += d[i]; d[i] += 1;
}
5.4.4 The volatile Keyword
The compiler analyzes data flow to avoid memory accesses whenever possible. If you have code that depends on memory accesses exactly as written in the C/C++ code, you must use the volatile keyword to identify these accesses. A variable qualified with a volatile keyword is allocated to an uninitialized section
(as opposed to a register). The compiler does not optimize out any references to volatile variables.
In the following example, the loop intends to wait for a location to be read as 0xFF: unsigned int *ctrl; while (*ctrl !=0xFF);
However, in this example, *ctrl is a loop-invariant expression, so the loop is optimized down to a single-memory read. To get the desired result, define *ctrl as: volatile unsigned int *ctrl;
Here the *ctrl pointer is intended to reference a hardware location, such as an interrupt flag.
SLAU132D – June 2009
Submit Documentation Feedback
MSP430 C/C++ Language Implementation
75
C++ Exception Handling
www.ti.com
5.5
C++ Exception Handling
The compiler supports all the C++ exception handling features as defined by the ANSI/ISO 14882 C++
Standard. More details are discussed in The C++ Programming Language, Third Edition by Bjarne
Stroustrup.
The compiler --exceptions option enables exception handling. The compiler’s default is no exception handling support.
For exceptions to work correctly, all C++ files in the application must be compiled with the --exceptions option, regardless of whether exceptions occur in a particular file. Mixing exception-enabled object files and libraries with object files and libraries that do not have exceptions enabled can lead to undefined behavior. Also, when using --exceptions, you need to link with run-time-support libraries whose name contains _eh. These libraries contain functions that implement exception handling.
Using --exceptions causes code size to increase.
See
for details on the run-time libraries.
5.6
Register Variables and Parameters
The C/C++ compiler treats register variables (variables defined with the register keyword) differently, depending on whether you use the --opt_level (-O) option.
•
Compiling with optimization
The compiler ignores any register definitions and allocates registers to variables and temporary values by using an algorithm that makes the most efficient use of registers.
•
Compiling without optimization
If you use the register keyword, you can suggest variables as candidates for allocation into registers.
The compiler uses the same set of registers for allocating temporary expression results as it uses for allocating register variables.
The compiler attempts to honor all register definitions. If the compiler runs out of appropriate registers, it frees a register by moving its contents to memory. If you define too many objects as register variables, you limit the number of registers the compiler has for temporary expression results. This limit causes excessive movement of register contents to memory.
Any object with a scalar type (integral, floating point, or pointer) can be defined as a register variable. The register designator is ignored for objects of other types, such as arrays.
The register storage class is meaningful for parameters as well as local variables. Normally, in a function, some of the parameters are copied to a location on the stack where they are referenced during the function body. The compiler copies a register parameter to a register instead of the stack, which speeds access to the parameter within the function.
For more information about register conventions, see
76
MSP430 C/C++ Language Implementation
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
The asm Statement
5.7
The asm Statement
The C/C++ compiler can embed assembly language instructions or directives directly into the assembly language output of the compiler. This capability is an extension to the C/C++ language—the asm statement. The asm (or __asm) statement provides access to hardware features that C/C++ cannot provide. The asm statement is syntactically like a call to a function named asm, with one string constant argument:
asm(" assembler text ");
The compiler copies the argument string directly into your output file. The assembler text must be enclosed in double quotes. All the usual character string escape codes retain their definitions. For example, you can insert a .byte directive that contains quotes as follows: asm("STR: .byte \"abc\"");
The inserted code must be a legal assembly language statement. Like all assembly language statements, the line of code inside the quotes must begin with a label, a blank, a tab, or a comment (asterisk or semicolon). The compiler performs no checking on the string; if there is an error, the assembler detects it.
For more information about the assembly language statements, see the MSP430 Assembly Language
Tools User's Guide.
The asm statements do not follow the syntactic restrictions of normal C/C++ statements. Each can appear as a statement or a declaration, even outside of blocks. This is useful for inserting directives at the very beginning of a compiled module.
Use the alternate statement __asm("assembler text") if you are writing code for strict ANSI/ISO C mode
(using the --strict_ansi option).
Note: Avoid Disrupting the C/C++ Environment With asm Statements
Be careful not to disrupt the C/C++ environment with asm statements. The compiler does not check the inserted instructions. Inserting jumps and labels into C/C++ code can cause unpredictable results in variables manipulated in or around the inserted code. Directives that change sections or otherwise affect the assembly environment can also be troublesome.
Be especially careful when you use optimization with asm statements. Although the compiler cannot remove asm statements, it can significantly rearrange the code order near them and cause undesired results.
SLAU132D – June 2009
Submit Documentation Feedback
MSP430 C/C++ Language Implementation
77
Pragma Directives
www.ti.com
5.8
Pragma Directives
Pragma directives tell the compiler how to treat a certain function, object, or section of code. The MSP430
C/C++ compiler supports the following pragmas:
•
BIS_IE1_INTERRUPT
•
CODE_SECTION
•
DATA_ALIGN
•
DATA_SECTION
• diag_suppress, diag_remark, diag_warning and diag_error
•
FUNC_CANNOT_INLINE
•
FUNC_EXT_CALLED
•
FUNC_IS_PURE
•
FUNC_NEVER_RETURNS
•
FUNC_NO_GLOBAL_ASG
•
FUNC_NO_IND_ASG
•
INTERRUPT
•
NO_HOOKS
The arguments func and symbol cannot be defined or declared inside the body of a function. You must specify the pragma outside the body of a function; and the pragma specification must occur before any declaration, definition, or reference to the func or symbol argument. If you do not follow these rules, the compiler issues a warning.
For the pragmas that apply to functions or symbols, the syntax for the pragmas differs between C and
C++. In C, you must supply the name of the object or function to which you are applying the pragma as the first argument. In C++, the name is omitted; the pragma applies to the declaration of the object or function that follows it.
5.8.1 The BIS_IE1_INTERRUPT
The BIS_IE1_INTERRUPT pragma treats the named function as an interrupt routine. Additionally, the compiler generates a BIS operation on the IE1 special function register upon function exit. The mask value, which must be an 8-bit constant literal, is logically OR’ed with the IE1 SFR, just before the RETI instruction. The compiler assumes the IE1 SFR is mapped to address 0x0000.
The syntax of the pragma in C is:
#pragma BIS_IE1_INTERRUPT ( func , mask );
The syntax of the pragma in C++ is:
#pragma BIS_IE1_INTERRUPT (mask);
In C, the argument func is the name of the function that is an interrupt. In C++, the pragma applies to the next function declared.
78
MSP430 C/C++ Language Implementation
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Pragma Directives
5.8.2 The CODE_SECTION Pragma
The CODE_SECTION pragma allocates space for the symbol in C, or the next symbol declared in C++, in a section named section name.
The syntax of the pragma in C is:
#pragma CODE_SECTION ( symbol , " section name ");
The syntax of the pragma in C++ is:
#pragma CODE_SECTION (" section name ");
The CODE_SECTION pragma is useful if you have code objects that you want to link into an area separate from the .text section.
The following examples demonstrate the use of the CODE_SECTION pragma.
Example 5-3. Using the CODE_SECTION Pragma C Source File
#pragma CODE_SECTION(funcA,"codeA") int funcA(int a)
{ int i; return (i = a);
}
Example 5-4. Generated Assembly Code From
.sect "codeA"
.align 2
.clink
.global funcA
;*****************************************************************************
;* FUNCTION NAME: funcA
;*
*
*
;* Regs Modified
;* Regs Used
: SP,SR,r12
: SP,SR,r12
*
*
;* Local Frame Size : 0 Args + 4 Auto + 0 Save = 4 byte *
;***************************************************************************** funcA:
;* --------------------------------------------------------------------------*
SUB.W
MOV.W
#4,SP r12,0(SP) ; |4|
MOV.W
MOV.W
ADD.W
RET
0(SP),2(SP)
2(SP),r12
#4,SP
; |6|
; |6|
Example 5-5. Using the CODE_SECTION Pragma C++ Source File
#pragma CODE_SECTION("codeB") int i_arg(int x) { return 1; } int f_arg(float x) { return 2; }
SLAU132D – June 2009
Submit Documentation Feedback
MSP430 C/C++ Language Implementation
79
Pragma Directives
Example 5-6. Generated Assembly Code From
.sect "codeB"
.align
2
.clink
.global
i_arg__Fi
;*****************************************************************************
;* FUNCTION NAME: i_arg(int) *
;*
;* Regs Modified : SP,SR,r12
*
*
;* Regs Used : SP,SR,r12
;* Local Frame Size : 0 Args + 2 Auto + 0 Save = 2 byte
*
*
;***************************************************************************** i_arg__Fi:
;* --------------------------------------------------------------------------*
SUB.W
#2,SP
MOV.W
MOV.W
r12,0(SP)
#1,r12
; |2|
; |2|
ADD.W
RET
#2,SP
.sect ".text"
.align
2
.clink
.global
f_arg__Ff
;*****************************************************************************
;* FUNCTION NAME: f_arg(float)
;*
*
*
;* Regs Modified
;* Regs Used
: SP,SR,r12
: SP,SR,r12,r13
*
*
;* Local Frame Size : 0 Args + 4 Auto + 0 Save = 4 byte *
;***************************************************************************** f_arg__Ff:
;* --------------------------------------------------------------------------*
SUB.W
MOV.W
#4,SP r12,0(SP) ; |3|
MOV.W
MOV.W
ADD.W
RET r13,2(SP)
#2,r12
#4,SP
; |3|
; |3| www.ti.com
5.8.3 The DATA_ALIGN Pragma
The DATA_ALIGN pragma aligns the symbol in C, or the next symbol declared in C++, to an alignment boundary. The alignment boundary is the maximum of the symbol's default alignment value or the value of the constant in bytes. The constant must be a power of 2.
The syntax of the pragma in C is:
#pragma DATA_ALIGN ( symbol , constant );
The syntax of the pragma in C++ is:
#pragma DATA_ALIGN ( constant );
80
MSP430 C/C++ Language Implementation
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Pragma Directives
5.8.4 The DATA_SECTION Pragma
The DATA_SECTION pragma allocates space for the symbol in C, or the next symbol declared in C++, in a section named section name.
The syntax of the pragma in C is:
#pragma DATA_SECTION ( symbol , " section name ");
The syntax of the pragma in C++ is:
#pragma DATA_SECTION (" section name ");
The DATA_SECTION pragma is useful if you have data objects that you want to link into an area separate from the .bss section. If you allocate a global variable using a DATA_SECTION pragma and you want to reference the variable in C code, you must declare the variable as extern far.
through
demonstrate the use of the DATA_SECTION pragma.
Example 5-7. Using the DATA_SECTION Pragma C Source File
#pragma DATA_SECTION(bufferB, "my_sect") char bufferA[512]; char bufferB[512];
Example 5-8. Using the DATA_SECTION Pragma C++ Source File
char bufferA[512];
#pragma DATA_SECTION("my_sect") char bufferB[512];
Example 5-9. Using the DATA_SECTION Pragma Assembly Source File
.global
bufferA
.bss
bufferA,512,2
.global
bufferB bufferB: .usect "my_sect",512,2
5.8.5 The Diagnostic Message Pragmas
The following pragmas can be used to control diagnostic messages in the same ways as the corresponding command line options:
Pragma
diag_suppress id diag_remark id diag_warning id diag_error id diag_default id
Option
-pds=id
-pdsr=id
-pdsw=id
-pdse=id n/a
Description
Suppress diagnostic id
Treat diagnostic id as a remark
Treat diagnostic id as a warning
Treat diagnostic id as an error
Use default severity of the diagnostic
SLAU132D – June 2009
Submit Documentation Feedback
MSP430 C/C++ Language Implementation
81
Pragma Directives
The syntax of the pragmas in C is:
#pragma diag_xxx)[=]num); www.ti.com
The diagnostic affected (num) is specified using either an error number or an error tag name. The equal sign (=) is optional. Any diagnostic can be overridden to be an error, but only diagnostics with a severity of discretionary error or below can have their severity reduced to a warning or below, or be suppressed. The diag_default pragma is used to return the severity of a diagnostic to the one that was in effect before any pragmas were issued (i.e., the normal severity of the message as modified by any command-line options).
The diagnostic identifier number is output along with the message when the -pden command line option is specified.
5.8.6 The FUNC_CANNOT_INLINE Pragma
The FUNC_CANNOT_INLINE pragma instructs the compiler that the named function cannot be expanded inline. Any function named with this pragma overrides any inlining you designate in any other way, such as using the inline keyword. Automatic inlining is also overridden with this pragma; see
The pragma must appear before any declaration or reference to the function that you want to keep. In C, the argument func is the name of the function that cannot be inlined. In C++, the pragma applies to the next function declared.
The syntax of the pragma in C is:
#pragma FUNC_CANNOT_INLINE ( func );
The syntax of the pragma in C++ is:
#pragma FUNC_CANNOT_INLINE;
5.8.7 The FUNC_EXT_CALLED Pragma
When you use the --program_level_compile option, the compiler uses program-level optimization. When you use this type of optimization, the compiler removes any function that is not called, directly or indirectly, by main. You might have C/C++ functions that are called by hand-coded assembly instead of main.
The FUNC_EXT_CALLED pragma specifies to the optimizer to keep these C functions or any other functions that these C/C++ functions call. These functions act as entry points into C/C++.
The pragma must appear before any declaration or reference to the function that you want to keep. In C, the argument func is the name of the function that you do not want removed. In C++, the pragma applies to the next function declared.
The syntax of the pragma in C is:
#pragma FUNC_EXT_CALLED ( func );
The syntax of the pragma in C++ is:
#pragma FUNC_EXT_CALLED;
82
Except for _c_int00, which is the name reserved for the system reset interrupt for C/C++programs, the name of the interrupt (the func argument) does not need to conform to a naming convention.
When you use program-level optimization, you may need to use the FUNC_EXT_CALLED pragma with certain options. See
MSP430 C/C++ Language Implementation
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
5.8.8 The FUNC_IS_PURE Pragma
Pragma Directives
The FUNC_IS_PURE pragma specifies to the compiler that the named function has no side effects. This allows the compiler to do the following:
•
Delete the call to the function if the function's value is not needed
•
Delete duplicate functions
The pragma must appear before any declaration or reference to the function. In C, the argument func is the name of a function. In C++, the pragma applies to the next function declared.
The syntax of the pragma in C is:
#pragma FUNC_IS_PURE ( func );
The syntax of the pragma in C++ is:
#pragma FUNC_IS_PURE;
5.8.9 The FUNC_NEVER_RETURNS Pragma
The FUNC_NEVER_RETURNS pragma specifies to the compiler that the function never returns to its caller.
The pragma must appear before any declaration or reference to the function that you want to keep. In C, the argument func is the name of the function that does not return. In C++, the pragma applies to the next function declared.
The syntax of the pragma in C is:
#pragma FUNC_NEVER_RETURNS ( func );
The syntax of the pragma in C++ is:
#pragma FUNC_NEVER_RETURNS;
5.8.10 The FUNC_NO_GLOBAL_ASG Pragma
The FUNC_NO_GLOBAL_ASG pragma specifies to the compiler that the function makes no assignments to named global variables and contains no asm statements.
The pragma must appear before any declaration or reference to the function that you want to keep. In C, the argument func is the name of the function that makes no assignments. In C++, the pragma applies to the next function declared.
The syntax of the pragma in C is:
#pragma FUNC_NO_GLOBAL_ASG ( func );
The syntax of the pragma in C++ is:
#pragma FUNC_NO_GLOBAL_ASG;
SLAU132D – June 2009
Submit Documentation Feedback
MSP430 C/C++ Language Implementation
83
Pragma Directives
www.ti.com
84
MSP430 C/C++ Language Implementation
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Pragma Directives
5.8.11 The FUNC_NO_IND_ASG Pragma
The FUNC_NO_IND_ASG pragma specifies to the compiler that the function makes no assignments through pointers and contains no asm statements.
The pragma must appear before any declaration or reference to the function that you want to keep. In C, the argument func is the name of the function that makes no assignments. In C++, the pragma applies to the next function declared.
The syntax of the pragma in C is:
#pragma FUNC_NO_IND_ASG ( func );
The syntax of the pragma in C++ is:
#pragma FUNC_NO_IND_ASG;
5.8.12 The INTERRUPT Pragma
The INTERRUPT pragma enables you to handle interrupts directly with C code. In C, the argument func is the name of a function. In C++, the pragma applies to the next function declared.
The syntax of the pragma in C is:
#pragma INTERRUPT ( func );
The syntax of the pragma in C++ is:
#pragma INTERRUPT ;
The code for the function will return via the IRP (interrupt return pointer).
Except for _c_int00, which is the name reserved for the system reset interrupt for C programs, the name of the interrupt (the func argument) does not need to conform to a naming convention.
HWI Objects and the INTERRUPT Pragma
Note:
The INTERRUPT pragma must not be used when BIOS HWI objects are used in conjunction with C functions. The HWI_enter/HWI_exit macros and the HWI dispatcher contain this functionality, and the use of the C modifier can cause negative results.
SLAU132D – June 2009
Submit Documentation Feedback
MSP430 C/C++ Language Implementation
85
Pragma Directives
www.ti.com
5.8.13 The vector Pragma
The vector pragma indicates that the function that follows is to be used as the interrupt vector routine for the listed vectors. The syntax of the pragma is:
#pragma vector =vec1[, vec2, vec3, ...]
The vector pragma requires linker command file support. The command file must specify output sections for each interrupt vector of the form .intxx where xx is the number of the interrupt vector. The output sections mut map to the physical memory location of the appropriate interrupt vector. The standard linker command files are set up to handle the vector pragma.
The __even_in_range intrinsic provides a hint to the compiler when generating switch statements for interrupt vector routines. The intrinsic is usually used as follows:
switch (__even_in_range(x, NUM))
{
...
}
The __even_in_range intrinsic returns the value x to control the switch statement, but also tells the compiler that x must be an even value in the range of 0 to NUM, inclusive.
86
MSP430 C/C++ Language Implementation
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
The _Pragma Operator
5.9
The _Pragma Operator
The MSP430 C/C++ compiler supports the C99 preprocessor _Pragma() operator. This preprocessor operator is similar to #pragma directives. However, _Pragma can be used in preprocessing macros
(#defines).
The syntax of the operator is:
_Pragma (" string_literal ");
The argument string_literal is interpreted in the same way the tokens following a #pragma directive are processed. The string_literal must be enclosed in quotes. A quotation mark that is part of the string_literal must be preceded by a backward slash.
You can use the _Pragma operator to express #pragma directives in macros. For example, the
DATA_SECTION syntax:
#pragma DATA_SECTION( func ," section ");
Is represented by the _Pragma() operator syntax:
_Pragma ("DATA_SECTION( func ,\" section \")")
The following code illustrates using _Pragma to specify the DATA_SECTION pragma in a macro:
...
#define EMIT_PRAGMA(x) _Pragma(#x)
#define COLLECT_DATA(var) EMIT_PRAGMA(DATA_SECTION(var,"mysection"))
COLLECT_DATA(x) int x;
...
The EMIT_PRAGMA macro is needed to properly expand the quotes that are required to surround the section argument to the DATA_SECTION pragma.
5.10 Generating Linknames
The compiler transforms the names of externally visible identifiers when creating their linknames. The algorithm used depends on the scope within which the identifier is declared. For objects and C functions, an underscore (_) is prefixed to the identifier name. C++ functions are prefixed with an underscore also, but the function name is modified further.
Mangling is the process of embedding a function's signature (the number and types of its parameters) into its name. Mangling occurs only in C++ code. The mangling algorithm used closely follows that described in The Annotated Reference Manual (ARM). Mangling allows function overloading, operator overloading, and type-safe linking.
For example, the general form of a C++ linkname for a function named func is:
_func__F parmcodes
Where parmcodes is a sequence of letters that encodes the parameter types of func.
For this simple C++ source file: int foo(int i){ } //global C++ function
This is the resulting assembly code:
_foo__Fi
The linkname of foo is _foo__Fi, indicating that foo is a function that takes a single argument of type int.
To aid inspection and debugging, a name demangling utility is provided that demangles names into those found in the original C++ source. See
for more information.
SLAU132D – June 2009
Submit Documentation Feedback
MSP430 C/C++ Language Implementation
87
Initializing Static and Global Variables
www.ti.com
5.11 Initializing Static and Global Variables
The ANSI/ISO C standard specifies that global (extern) and static variables without explicit initializations must be initialized to 0 before the program begins running. This task is typically done when the program is loaded. Because the loading process is heavily dependent on the specific environment of the target application system, the compiler itself makes no provision for preinitializing variables at run time. It is up to your application to fulfill this requirement.
5.11.1 Initializing Static and Global Variables With the Linker
If your loader does not preinitialize variables, you can use the linker to preinitialize the variables to 0 in the object file. For example, in the linker command file, use a fill value of 0 in the .bss section:
SECTIONS
{
...
.bss: {} = 0x00;
...
}
Because the linker writes a complete load image of the zeroed .bss section into the output COFF file, this method can have the unwanted effect of significantly increasing the size of the output file (but not the program).
If you burn your application into ROM, you should explicitly initialize variables that require initialization.
The preceding method initializes .bss to 0 only at load time, not at system reset or power up. To make these variables 0 at run time, explicitly define them in your code.
For more information about linker command files and the SECTIONS directive, see the linker description information in the MSP430 Assembly Language Tools User's Guide.
5.11.2 Initializing Static and Global Variables With the const Type Qualifier
Static and global variables of type const without explicit initializations are similar to other static and global variables because they might not be preinitialized to 0 (for the same reasons discussed in
).
For example: const int zero; /* may not be initialized to 0 */
However, the initialization of const global and static variables is different because these variables are declared and initialized in a section called .const. For example: const int zero = 0 /* guaranteed to be 0 */
This corresponds to an entry in the .const section:
.sect
.const
_zero
.word
0
This feature is particularly useful for declaring a large table of constants, because neither time nor space is wasted at system startup to initialize the table. Additionally, the linker can be used to place the .const
section in ROM.
You can use the DATA_SECTION pragma to put the variable in a section other than .const. For example, the following C code:
#pragma DATA_SECTION (var, ".mysect"); const int zero=0; is compiled into this assembly code:
.sect
.mysect
_zero
.word
0
88
MSP430 C/C++ Language Implementation
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Changing the ANSI/ISO C Language Mode
5.12 Changing the ANSI/ISO C Language Mode
The --kr_compatible, --relaxed_ansi, and --strict_ansi options let you specify how the C/C++ compiler interprets your source code. You can compile your source code in the following modes:
•
Normal ANSI/ISO mode
•
K&R C mode
•
Relaxed ANSI/ISO mode
•
Strict ANSI/ISO mode
The default is normal ANSI/ISO mode. Under normal ANSI/ISO mode, most ANSI/ISO violations are emitted as errors. Strict ANSI/ISO violations (those idioms and allowances commonly accepted by C/C++ compilers, although violations with a strict interpretation of ANSI/ISO), however, are emitted as warnings.
Language extensions, even those that conflict with ANSI/ISO C, are enabled.
K&R C mode does not apply to C++ code.
5.12.1 Compatibility With K&R C (--kr_compatible Option)
The ANSI/ISO C/C++ language is a superset of the de facto C standard defined in Kernighan and
Ritchie's The C Programming Language. Most programs written for other non-ANSI/ISO compilers correctly compile and run without modification.
There are subtle changes, however, in the language that can affect existing code. Appendix C in The C
Programming Language (second edition, referred to in this manual as K&R) summarizes the differences between ANSI/ISO C and the first edition's C standard (the first edition is referred to in this manual as
K&R C).
To simplify the process of compiling existing C programs with the ANSI/ISO C/C++ compiler, the compiler has a K&R option (--kr_compatible) that modifies some semantic rules of the language for compatibility with older code. In general, the --kr_compatible option relaxes requirements that are stricter for ANSI/ISO
C than for K&R C. The --kr_compatible option does not disable any new features of the language such as function prototypes, enumerations, initializations, or preprocessor constructs. Instead, --kr_compatible simply liberalizes the ANSI/ISO rules without revoking any of the features.
The specific differences between the ANSI/ISO version of C and the K&R version of C are as follows:
•
The integral promotion rules have changed regarding promoting an unsigned type to a wider signed type. Under K&R C, the result type was an unsigned version of the wider type; under ANSI/ISO, the result type is a signed version of the wider type. This affects operations that perform differently when applied to signed or unsigned operands; namely, comparisons, division (and mod), and right shift: unsigned short u; int i; if (u < i) /* SIGNED comparison, unless --kr_compatible used */
•
ANSI/ISO prohibits combining two pointers to different types in an operation. In most K&R compilers, this situation produces only a warning. Such cases are still diagnosed when --kr_compatible is used, but with less severity: int *p; char *q = p; /* error without --kr_compatible, warning with --kr_compatible */
•
External declarations with no type or storage class (only an identifier) are illegal in ANSI/ISO but legal in K&R: a; /* illegal unless --kr_compatible used */
•
ANSI/ISO interprets file scope definitions that have no initializers as tentative definitions. In a single module, multiple definitions of this form are fused together into a single definition. Under K&R, each definition is treated as a separate definition, resulting in multiple definitions of the same object and usually an error. For example: int a; int a; /* illegal if --kr_compatible used, OK if not */
Under ANSI/ISO, the result of these two definitions is a single definition for the object a. For most K&R compilers, this sequence is illegal, because int a is defined twice.
SLAU132D – June 2009
Submit Documentation Feedback
MSP430 C/C++ Language Implementation
89
Changing the ANSI/ISO C Language Mode
www.ti.com
•
ANSI/ISO prohibits, but K&R allows objects with external linkage to be redeclared as static: extern int a; static int a; /* illegal unless --kr_compatible used */
•
Unrecognized escape sequences in string and character constants are explicitly illegal under ANSI/ISO but ignored under K&R: char c = '\q'; /* same as 'q' if --kr_compatible used, error if not */
•
ANSI/ISO specifies that bit fields must be of type int or unsigned. With --kr_compatible, bit fields can be legally defined with any integral type. For example: struct s
{ short f : 2; /* illegal unless --kr_compatible used */
};
•
K&R syntax allows a trailing comma in enumerator lists: enum { a, b, c, }; /* illegal unless --kr_compatible used */
•
K&R syntax allows trailing tokens on preprocessor directives:
#endif NAME /* illegal unless --kr_compatible used */
5.12.2 Enabling Strict ANSI/ISO Mode and Relaxed ANSI/ISO Mode (--strict_ansi and
--relaxed_ansi Options)
Use the --strict_ansi option when you want to compile under strict ANSI/ISO mode. In this mode, error messages are provided when non-ANSI/ISO features are used, and language extensions that could invalidate a strictly conforming program are disabled. Examples of such extensions are the inline and asm keywords.
Use the --relaxed_ansi option when you want the compiler to ignore strict ANSI/ISO violations rather than emit a warning (as occurs in normal ANSI/ISO mode) or an error message (as occurs in strict ANSI/ISO mode). In relaxed ANSI/ISO mode, the compiler accepts extensions to the ANSI/ISO C standard, even when they conflict with ANSI/ISO C.
5.12.3 Enabling Embedded C++ Mode (--embedded_cpp Option)
The compiler supports the compilation of embedded C++. In this mode, some features of C++ are removed that are of less value or too expensive to support in an embedded system. When compiling for embedded C++, the compiler generates diagnostics for the use of omitted features.
Embedded C++ is enabled by compiling with the --embedded_cpp option.
Embedded C++ omits these C++ features:
•
Templates
•
Exception handling
•
Run-time type information
•
The new cast syntax
•
The keyword mutable
•
Multiple inheritance
•
Virtual inheritance
Under the standard definition of embedded C++, namespaces and using-declarations are not supported.
The MSP430 compiler nevertheless allows these features under embedded C++ because the C++ run-time-support library makes use of them. Furthermore, these features impose no run-time penalty.
90
MSP430 C/C++ Language Implementation
SLAU132D – June 2009
Submit Documentation Feedback
Extensions
Statement expressions
Local labels
Naming types typeof operator
Generalized lvalues
Conditionals
Hex floats
Zero length
Macro varargs
Subscripting
Pointer arithmetic
Initializers
Cast constructors
Labeled elements
Cast to union
Case ranges
Function attributes
Function prototypes
C++ comments
Dollar signs
Character escapes
Alignment
Variable attributes
Type attributes
Inline
Assembly labels
Alternate keywords
Incomplete enum types
Function names
Return address www.ti.com
GNU C Compiler Extensions
5.13 GNU C Compiler Extensions
The GNU compiler, GCC, provides a number of language features not found in the ANSI standard C. The definition and official examples of these extensions can be found at http://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/C-Extensions.html#C-Extensions . To enable GNU extension support, use the --gcc compiler option.
The extensions that the TI C compiler supports are listed in
.
Other built-ins
Table 5-2. GCC Extensions Supported
Descriptions
Putting statements and declarations inside expressions (useful for creating smart 'safe' macros)
Labels local to a statement expression
Giving a name to the type of an expression typeof referring to the type of an expression
Using question mark (?) and comma (,) and casts in lvalues
Omitting the middle operand of a ? expression
Hexadecimal floating-point constants
Zero-length arrays
Macros with a variable number of arguments
Any array can be subscripted, even if it is not an lvalue.
Arithmetic on void pointers and function pointers
Nonconstant initializers
Constructor expressions give structures, unions, or arrays as values
Labeling elements of initializers
Casting to union type from any member of the union
'Case 1 ... 9' and such
Declaring that functions have no side effects, or that they can never return
Prototype declarations and old-style definitions
C++ comments are recognized.
A dollar sign is allowed in identifiers.
The character ESC is represented as \'e'
Inquiring about the alignment of a type or variable
Specifying the attributes of variables
Specifying the attributes of types
Defining inline functions (as fast as macros)
Specifying the assembler name to use for a C symbol
Header files can use __const__, __asm__, etc
Define an enum tag without specifying its possible values
Printable strings which are the name of the current function
Getting the return or frame address of a function
__builtin_return_address
__builtin_frame_address
Other built-in functions include:
__builtin_constant_p
__builtin_expect
SLAU132D – June 2009
Submit Documentation Feedback
MSP430 C/C++ Language Implementation
91
Compiler Limits
www.ti.com
5.13.1 Function Attributes
The GNU extension support provides a number of attributes about functions to help the C compiler’s optimization. The TI compiler accepts only three of these attributes. All others are simply ignored.
lists the attributes that are supported.
Attributes
deprecated section unused
Table 5-3. TI-Supported GCC Function Attributes
Description
This function exists but the compiler generates a warning if it is used.
Place this function in the specified section.
The function is meant to be possibly not used.
5.13.2 Built-In Functions
TI provides support for only the four built-in functions in
.
Table 5-4. TI-Supported GCC Built-In Functions
Function
__builtin_constant_p(expr)
__builtin_expect(expr, CONST)
Description
Returns true only if expr is a constant at compile time.
Returns expr. The compiler uses this function to optimize along paths determined by conditional statements such as if-else. While this function can be used anywhere in your code, it only conveys useful information to the compiler if it is the entire predicate of an if statement and CONST is 0 or 1. For example, the following indicates that you expect the predicate "a ==
3" to be true most of the time: if (__builtin_expect(a == 3, 1))
__builtin_return_address(int level) Returns 0.
__builtin_frame_address(int level) Returns 0.
5.14 Compiler Limits
Due to the variety of host systems supported by the C/C++ compiler and the limitations of some of these systems, the compiler may not be able to successfully compile source files that are excessively large or complex. In general, exceeding such a system limit prevents continued compilation, so the compiler aborts immediately after printing the error message. Simplify the program to avoid exceeding a system limit.
Some systems do not allow filenames longer than 500 characters. Make sure your filenames are shorter than 500.
The compiler has no arbitrary limits but is limited by the amount of memory available on the host system.
On smaller host systems such as PCs, the optimizer may run out of memory. If this occurs, the optimizer terminates and the shell continues compiling the file with the code generator. This results in a file compiled with no optimization. The optimizer compiles one function at a time, so the most likely cause of this is a large or extremely complex function in your source module. To correct the problem, your options are:
•
Don't optimize the module in question.
•
Identify the function that caused the problem and break it down into smaller functions.
•
Extract the function from the module and place it in a separate module that can be compiled without optimization so that the remaining functions can be optimized.
92
MSP430 C/C++ Language Implementation
SLAU132D – June 2009
Submit Documentation Feedback
Chapter 6
SLAU132D – June 2009
Run-Time Environment
This chapter describes the MSP430 C/C++ run-time environment. To ensure successful execution of
C/C++ programs, it is critical that all run-time code maintain this environment. It is also important to follow the guidelines in this chapter if you write assembly language functions that interface with C/C++ code.
Topic
..................................................................................................
Page
6.1
..........................................................................
6.2
...............................................................
6.3
................................................................
6.4
Function Structure and Calling Conventions
..............................
6.5
Interfacing C and C++ With Assembly Language
6.6
...................................................................
6.7
Using Intrinsics to Access Assembly Language Statements
6.8
System Initialization
.................................................................
6.9
Compiling for 20-Bit MSP430X Devices
......................................
SLAU132D – June 2009
Submit Documentation Feedback
Run-Time Environment
93
Memory Model
www.ti.com
6.1
Memory Model
The MSP430 compiler treats memory as a single linear block that is partitioned into subblocks of code and data. Each subblock of code or data generated by a C program is placed in its own continuous memory space. The compiler assumes that a full 16-bit address space is available in target memory.
6.1.1 Large-Code Memory Model
When the --silicon_version=mspx option is specified, the compiler supports a large-code memory model while generating code for MSP430X devices. The size of function pointers is 20-bits. As for MSP430 devices, the size of data pointers is 16-bits. A large-code memory model allows unrestricted placement of programs in the 20-bit address space with the exception of interrupt service routines (see
However, data is still required to be placed into the low 64K of memory. Accessing data located in memory above 64K requires interfacing to assembly routines from C.
Modules assembled/compiled for 16-bit MSP430 devices are not compatible with modules that are assembled/compiled for 20-bit MSPX devices. The linker generates errors if an attempt is made to combine incompatible object files.
6.1.2 Large-Data Memory Model
When the --silicon_version=mspx and --large_memory_model options are specified, the compiler supports a large-data memory model for MSP430X devices. The large-data memory model allows data to be located anywhere in the 20-bit address space of the device. This permits applications with larger amounts of data to be run on the MSP430X. The option is only available with a MSP430X device.
Large-data model programs frequently require the use of larger instructions, and require more space to store data pointers. Consequently, large-data model programs are larger than equivalent small-data model programs and small-data model should still be used when possible.
Object files compiled using the large-data model are not compatible with small model object files.
Therefore, when building large-data model applications all files must be compiled using the large-data model option. Large-data model run-time-support libraries must be used as well (rts430xl.lib and rts430xl_eh.lib).
The maximum size of an object (size_t) and the maximum difference between two pointers (ptrdiff_t) are increased from 16-bits to 32-bits in large-data model. Applications that rely on size_t or ptrdiff_t to be a specific size may need to be updated.
Note: The Linker Defines the Memory Map
The linker, not the compiler, defines the memory map and allocates code and data into target memory. The compiler assumes nothing about the types of memory available, about any locations not available for code or data (holes), or about any locations reserved for I/O or control purposes. The compiler produces relocatable code that allows the linker to allocate code and data into the appropriate memory spaces.
For example, you can use the linker to allocate global variables into on-chip RAM or to allocate executable code into external ROM. You can allocate each block of code or data individually into memory, but this is not a general practice (an exception to this is memory-mapped I/O, although you can access physical memory locations with C/C++ pointer types).
94
Run-Time Environment
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Memory Model
6.1.3 Sections
The compiler produces relocatable blocks of code and data called sections. The sections are allocated into memory in a variety of ways to conform to a variety of system configurations. For more information about sections and allocating them, see the introductory object module information in the MSP430
Assembly Language Tools User's Guide.
There are two basic types of sections:
•
Initialized sections contain data or executable code. The C/C++ compiler creates the following initialized sections:
– The .cinit section and the .pinit section contain tables for initializing variables and constants.
– The .const section contains string constants, switch tables, and data defined with the C/C++ qualifier const (provided the constant is not also defined as volatile).
– The .text section contains all the executable code as well as string literals and compiler-generated constants.
•
Uninitialized sections reserve space in memory (usually RAM). A program can use this space at run time to create and store variables. The compiler creates the following uninitialized sections:
– The .stack section reserves memory for the C/C++ software stack.
– The .sysmem section reserves space for dynamic memory allocation. The reserved space is used by dynamic memory allocation routines, such as malloc, calloc, realloc, or new. If a C/C++ program does not use these functions, the compiler does not create the .sysmem section.
The assembler creates the default sections .text, .bss, and .data. The C/C++ compiler, however, does not use the .data section. You can instruct the compiler to create additional sections by using the
CODE_SECTION and DATA_SECTION pragmas (see
and
The linker takes the individual sections from different modules and combines sections that have the same name. The resulting output sections and the appropriate placement in memory for each section are listed in
Table 6-1 . You can place these output sections anywhere in the address space as needed to meet
system requirements.
Section
.bss
.cinit
.const
.data
Table 6-1. Summary of Sections and Memory Placement
Type of Memory
RAM
ROM or RAM
ROM or RAM
ROM or RAM
Section
.pinit
.stack
.sysmem
.text
Type of Memory
ROM or RAM
RAM
RAM
ROM or RAM
You can use the SECTIONS directive in the linker command file to customize the section-allocation process. For more information about allocating sections into memory, see the linker description chapter in the MSP430 Assembly Language Tools User's Guide.
6.1.4 C/C++ Software Stack
The C/C++ compiler uses a stack to:
•
Allocate local variables
•
Pass arguments to functions
•
Save register contents
The run-time stack grows from the high addresses to the low addresses. The compiler uses the R13 register to manage this stack. R13 is the stack pointer (SP), which points to the next unused location on the stack.
The linker sets the stack size, creates a global symbol, __STACK_SIZE, and assigns it a value equal to the stack size in bytes. The default stack size is 2048 bytes. You can change the stack size at link time by using the --stack_size option with the linker command. For more information on the --stack_size option, see
SLAU132D – June 2009
Submit Documentation Feedback
Run-Time Environment
95
Memory Model
www.ti.com
Save-On-Entry Registers and C/C+ Stack Size
Note:
Since register sizes increase for MSP430X devices (specified with --silicon_version=mspx), saving and restoring save-on-entry registers requires 32-bits of stack space for each register saved on the stack. When you are porting code originally written for 16-bit MSP430 devices, you may need to increase the C stack size from previous values.
At system initialization, SP is set to a designated address for the top of the stack. This address if the first location past the end of the .stack section. Since the position of the stack depends on where the .stack
section is allocated, the actual address of the stack is determined at link time.
The C/C++ environment automatically decrements SP at the entry to a function to reserve all the space necessary for the execution of that function. The stack pointer is incremented at the exit of the function to restore the stack to the state before the function was entered. If you interface assembly language routines to C/C++ programs, be sure to restore the stack pointer to the same state it was in before the function was entered.
For more information about using the stack pointer, see
; for more information about the stack, see
Note: Stack Overflow
The compiler provides no means to check for stack overflow during compilation or at run time. A stack overflow disrupts the run-time environment, causing your program to fail. Be sure to allow enough space for the stack to grow.
6.1.5 Dynamic Memory Allocation
The run-time-support library supplied with the MSP430 compiler contains several functions (such as malloc, calloc, and realloc) that allow you to allocate memory dynamically for variables at run time.
Memory is allocated from a global pool, or heap, that is defined in the .sysmem section. You can set the size of the .sysmem section by using the --heap_size=size option with the linker command. The linker also creates a global symbol, __SYSMEM_SIZE, and assigns it a value equal to the size of the heap in bytes.
The default size is 128 bytes. For more information on the --heap_size option, see
Dynamically allocated objects are not addressed directly (they are always accessed with pointers) and the memory pool is in a separate section (.sysmem); therefore, the dynamic memory pool can have a size limited only by the amount of available memory in your system. To conserve space in the .bss section, you can allocate large arrays from the heap instead of defining them as global or static. For example, instead of a definition such as: struct big table[100]; use a pointer and call the malloc function: struct big *table table = (struct big *)malloc(100*sizeof(struct big));
6.1.6 Initialization of Variables
The C/C++ compiler produces code that is suitable for use as firmware in a ROM-based system. In such a system, the initialization tables in the .cinit section are stored in ROM. At system initialization time, the
C/C++ boot routine copies data from these tables (in ROM) to the initialized variables in .bss (RAM).
In situations where a program is loaded directly from an object file into memory and run, you can avoid having the .cinit section occupy space in memory. A loader can read the initialization tables directly from the object file (instead of from ROM) and perform the initialization directly at load time instead of at run time. You can specify this to the linker by using the --ram_model link option. For more information, see
.
96
Run-Time Environment
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
6.2
Object Representation
This section explains how various data objects are sized, aligned, and accessed.
Object Representation
6.2.1 Data Type Storage
lists register and memory storage for various data types:
Table 6-2. Data Representation in Registers and Memory
Data Type
char, signed char unsigned char, bool short, signed short unsigned short, wchar_t int, signed int unsigned int enum long. signed long unsigned long
Register Storage
Bits 0-7 of register
(1)
Bits 0-7 of register
Bits 0-15 of register
(1)
Bits 0-15 of register
Bits 0-15 of register
Bits 0-15 of register
Bits 0-15 of register
Register pair
Register pair
Memory Storage
8 bits aligned to 8-bit boundary
8 bits aligned to 8-bit boundary
16 bits aligned to 16-bit (word) boundary
16 bits aligned to 16-bit (word) boundary
16 bits aligned to 16-bit (word) boundary
16 bits aligned to 16-bit (word) boundary
16 bits aligned to 16-bit (word) boundary
32 bits aligned to 16-bit (word) boundary
32 bits aligned to 16-bit (word) boundary float double long double struct
Register pair
Register pair
Register pair
Members are stored as their individual types require.
32 bits aligned to 16-bit (word) boundary
32 bits aligned to 16-bit (word) boundary
32 bits aligned to 16-bit (word) boundary array Members are stored as their individual types require.
Members are stored as their individual types require; aligned according to the member with the most restrictive alignment requirement.
Members are stored as their individual types require; aligned to 32-bit (word) boundary. All arrays inside a structure are aligned according to the type of each element in the array.
16 bits aligned to 16-bit (word) boundary pointer to data member Bits 0-15 of register
MSP430X large-data model pointer to data member
(2)
Bits 0-20 of register 32 bits aligned to 16-bit (word) boundary
MSP430 pointer to function Bits 0-15 of register 16 bits aligned to 16-bit (word) boundary
MSP430X
(3) pointer to function Bits 0-20 of register
(1)
(2)
(3)
32 bits aligned to 16-bit (word) boundary
Negative values are sign-extended to bit 15.
MSP430X large-data model is specified by --silicon_version=mspx --large_memory_model
MSP430X is specified with the ––silicon_version=mspx option.
6.2.1.1
Pointer to Member Function Types
Pointer to member function objects are stored as a structure with three members, and the layout is equivalent to: struct { short int d; short int I; union { void (f) (); long 0; }
};
The parameter d is the offset to be added to the beginning of the class object for this pointer. The parameter I is the index into the virtual function table, offset by 1. The index enables the NULL pointer to be represented. Its value is -1 if the function is nonvirtual. The parameter f is the pointer to the member function if it is nonvirtual, when I is 0. The 0 is the offset to the virtual function pointer within the class object.
SLAU132D – June 2009
Submit Documentation Feedback
Run-Time Environment
97
Object Representation
www.ti.com
6.2.1.2
Structure and Array Alignment
Structures are aligned according to the member with the most restrictive alignment requirement.
Structures do not contain padding after the last member. Arrays are always word aligned. Elements of arrays are stored in the same manner as if they were individual objects.
6.2.1.3
Field/Structure Alignment
When the compiler allocates space for a structure, it allocates as many words as are needed to hold all of the structure's members and to comply with alignment constraints for each member.
When a structure contains a 32-bit (long) member, the long is aligned to a 1-word (16-bit) boundary. This may require padding before, inside, or at the end of the structure to ensure that the long is aligned accordingly and that the sizeof value for the structure is an even value.
All non-field types are aligned on wordor byte boundaries. Fields are allocated as many bits as requested.
Adjacent fields are packed into adjacent bits of a word, but they do not overlap words. If a field would overlap into the next word, the entire field is placed into the next word.
Fields are packed as they are encountered; the least significant bits of the structure word are filled
shows the C code definition of var while
shows the memory layout of var.
Example 6-1. C Code Definition of var
struct example { char c; long l; int bf1:1; int bf2:2; int bf3:3; int bf4:4; int bf5:5; int bf6:6;
};
Figure 6-1. Memory Layout of var
16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 var + 0 var + 2 var + 4 var + 6 var + 8
1
<pad> long long
5
<pad 10 bits>
4 char c
(low)
(high)
3
6
2 1
98
Run-Time Environment
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
6.2.2 Character String Constants
Register Conventions
In C, a character string constant is used in one of the following ways:
•
To initialize an array of characters. For example: char s[] = "abc";
When a string is used as an initializer, it is simply treated as an initialized array; each character is a separate initializer. For more information about initialization, see
•
In an expression. For example: strcpy (s, "abc");
When a string is used in an expression, the string itself is defined in the .const section with the .string
assembler directive, along with a unique label that points to the string; the terminating 0 byte is included.
For example, the following lines define the string abc, and the terminating 0 byte (the label SL5 points to the string):
.sect
".const"
SL5: .string "abc",0
String labels have the form SLn, where n is a number assigned by the compiler to make the label unique. The number begins at 0 and is increased by 1 for each string defined. All strings used in a source module are defined at the end of the compiled assembly language module.
The label SLn represents the address of the string constant. The compiler uses this label to reference the string expression.
Because strings are stored in the .const section (possibly in ROM) and shared, it is bad practice for a program to modify a string constant. The following code is an example of incorrect string use: const char *a = "abc" a[1] = 'x'; /* Incorrect! */
6.3
Register Conventions
Strict conventions associate specific registers with specific operations in the C/C++ environment. If you plan to interface an assembly language routine to a C/C++ program, you must understand and follow these register conventions.
The register conventions dictate how the compiler uses registers and how values are preserved across function calls.
shows the types of registers affected by these conventions.
summarizes how the compiler uses registers and whether their values are preserved across calls. For information about how values are preserved across calls, see
Table 6-3. How Register Types Are Affected by the Conventions
Register Type
Argument register
Return register
Expression register
Argument pointer
Stack pointer
Program counter
Description
Passes arguments during a function call
Holds the return value from a function call
Holds a value
Used as a base value from which a function's parameters (incoming arguments) are accessed
Holds the address of the top of the software stack
Contains the current address of code being executed
SLAU132D – June 2009
Submit Documentation Feedback
Run-Time Environment
99
Function Structure and Calling Conventions
www.ti.com
Register
R0
R1
R2
R3
R4-R10
R11
R12
R13
(1)
(2)
R14
R15
Table 6-4. Register Usage and Preservation Conventions
Alias
PC
SP
SR
Usage
Program counter
Stack pointer
Status register
Constant generator
Preserved by Function
(1)
N/A
N/A
(2)
N/A
N/A
Expression register Child
Expression register Parent
Expression register, argument pointer, Parent return register
Expression register, argument pointer, Parent return register
Expression register, argument pointer Parent
Expression register, argument pointer Parent
The parent function refers to the function making the function call. The child function refers to the function being called.
The SP is preserved by the convention that everything pushed on the stack is popped off before returning.
6.4
Function Structure and Calling Conventions
The C/C++ compiler imposes a strict set of rules on function calls. Except for special run-time support functions, any function that calls or is called by a C/C++ function must follow these rules. Failure to adhere to these rules can disrupt the C/C++ environment and cause a program to fail.
The following sections use this terminology to describe the function-calling conventions of the C/C++ compiler:
•
Argument block. The part of the local frame used to pass arguments to other functions. Arguments are passed to a function by moving them into the argument block rather than pushing them on the stack. The local frame and argument block are allocated at the same time.
•
Register save area. The part of the local frame that is used to save the registers when the program calls the function and restore them when the program exits the function.
•
Save-on-call registers. Registers R11-R15. The called function does not preserve the values in these registers; therefore, the calling function must save them if their values need to be preserved.
•
Save-on-entry registers. Registers R4-R10. It is the called function's responsibility to preserve the values in these registers. If the called function modifies these registers, it saves them when it gains control and preserves them when it returns control to the calling function.
illustrates a typical function call. In this example, arguments are passed to the function, and the function uses local variables and calls another function. The first four arguments are passed to registers R12-R15.
This example also shows allocation of a local frame and argument block for the called function. Functions that have no local variables and do not require an argument block do not allocate a local frame.
6.4.1 How a Function Makes a Call
A function (parent function) performs the following tasks when it calls another function (child function).
1. The calling function (parent) is responsible for preserving any save-on-call registers across the call that are live across the call. (The save-on-call registers are R11-R15.)
2. If the called function (child) returns a structure, the caller allocates space for the structure and passes the address of that space to the called function as the first argument.
3. The caller places the first arguments in registers R12-R15, in that order. The caller moves the remaining arguments to the argument block in reverse order, placing the leftmost remaining argument at the lowest address. Thus, the leftmost remaining argument is placed at the top of the stack.
4. The caller calls the function.
100
Run-Time Environment
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Function Structure and Calling Conventions
6.4.2 How a Called Function Responds
A called function (child function) must perform the following tasks:
1. If the function is declared with an ellipsis, it can be called with a variable number of arguments. The called function pushes these arguments on the stack if they meet both of these criteria:
•
The argument includes or follows the last explicitly declared argument.
•
The argument is passed in a register.
2. The called function pushes register values of all the registers that are modified by the function and that must be preserved upon exit of the function onto the stack. Normally, these registers are the save-on-entry registers (R4-R10) if the function contains calls. If the function is an interrupt, additional registers may need to be preserved. For more information, see
.
3. The called function allocates memory for the local variables and argument block by subtracting a constant from the SP. This constant is computed with the following formula:
size of all local variables + max = constant
The max argument specifies the size of all parameters placed in the argument block for each call.
4. The called function executes the code for the function.
5. If the called function returns a value, it places the value in R12 (or R12 and R13 values).
6. If the called function returns a structure, it copies the structure to the memory block that the first argument, R12, points to. If the caller does not use the return value, R12 is set to 0. This directs the called function not to copy the return structure.
In this way, the caller can be smart about telling the called function where to return the structure. For example, in the statement s = f(x), where s is a structure and f is a function that returns a structure, the caller can simply pass the address of s as the first argument and call f. The function f then copies the return structure directly into s, performing the assignment automatically.
You must be careful to properly declare functions that return structures, both at the point where they are called (so the caller properly sets up the first argument) and at the point where they are declared
(so the function knows to copy the result).
7. The called function deallocates the frame and argument block by adding the constant computed in
.
8. The called function restores all registers saved in
9. The called function ( _f) returns.
The following example is typical of how a called function responds to a call: func:
PUSH.W
PUSH.W
SUB.W
:
:
:
ADD.W
POP
POP
RET
; Called function entry point r10 r9 ; Save SOE registers
#2,SP ; Allocate the frame
; Body of function
#2,SP ; Deallocate the frame r9 ; Restore SOE registers r10
; Return
6.4.3 Accessing Arguments and Local Variables
A function accesses its local nonregister variables indirectly through the stack pointer (SP or R1) and its stack arguments. The SP always points to the top of the stack (points to the most recently pushed value).
Since the stack grows toward smaller addresses, the local data on the stack for the C/C++ function is accessed with a positive offset from the SP register.
SLAU132D – June 2009
Submit Documentation Feedback
Run-Time Environment
101
Interfacing C and C++ With Assembly Language
www.ti.com
6.5
Interfacing C and C++ With Assembly Language
The following are ways to use assembly language with C/C++ code:
•
Use separate modules of assembled code and link them with compiled C/C++ modules (see
).
•
Use assembly language variables and constants in C/C++ source (see
•
Use inline assembly language embedded directly in the C/C++ source (see
6.5.1 Using Assembly Language Modules With C/C++ Code
Interfacing C/C++ with assembly language functions is straightforward if you follow the calling conventions defined in
, and the register conventions defined in
variables and call functions defined in assembly language, and assembly code can access C/C++ variables and call C/C++ functions.
Follow these guidelines to interface assembly language and C:
•
You must preserve any dedicated registers modified by a function. Dedicated registers include:
– Save-on-entry registers (R4-R10)
– Stack pointer (SP or R1)
If the SP is used normally, it does not need to be explicitly preserved. In other words, the assembly function is free to use the stack as long as anything that is pushed onto the stack is popped back off before the function returns (thus preserving SP).
Any register that is not dedicated can be used freely without first being saved.
•
Interrupt routines must save all the registers they use. For more information, see
•
When you call a C/C++ function from assembly language, load the designated registers with arguments and push the remaining arguments onto the stack as described in
Remember that a function can alter any register not designated as being preserved without having to restore it. If the contents of any of these registers must be preserved across the call, you must explicitly save them.
•
Functions must return values correctly according to their C/C++ declarations. Double values are returned in R12 and R13, and structures are returned as described in
of
. Any other values are returned in R12.
•
No assembly module should use the .cinit section for any purpose other than autoinitialization of global variables. The C/C++ startup routine assumes that the .cinit section consists entirely of initialization tables. Disrupting the tables by putting other information in .cinit can cause unpredictable results.
•
The compiler assigns linknames to all external objects. Thus, when you are writing assembly language code, you must use the same linknames as those assigned by the compiler. See
for more information.
•
Any object or function declared in assembly language that is accessed or called from C/C++ must be declared with the .def or .global directive in the assembly language modifier. This declares the symbol as external and allows the linker to resolve references to it.
Likewise, to access a C/C++ function or object from assembly language, declare the C/C++ object with the .ref or .global directive in the assembly language module. This creates an undeclared external reference that the linker resolves.
•
Any assembly routines that interface with MSP430x C programs are required to conform to the large-code model:
– Use CALLA/RETA instead of CALL/RET
– Use PUSHM.A/POPM.A to save and restore any used save-on-entry registers. The entire 20-bit register must be saved/restored.
– Manipulation of function pointers requires 20-bit operations (OP.A)
– If interfacing with C code compiled for the large-data model, data pointer manipulation must be performed using 20-bit operations (OP.A).
102
Run-Time Environment
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Interfacing C and C++ With Assembly Language
illustrates a C++ function called main, which calls an assembly language function called asmfunc,
Example 6-3 . The asmfunc function takes its single argument, adds it to the C++ global variable
called gvar, and returns the result.
Example 6-2. Calling an Assembly Language Function From C/C++ C Program
extern "C" { extern int asmfunc(int a); /* declare external asm function */ int gvar = 0;
}
/* define global variable */ void main()
{ int I = 5;
I = asmfunc(I); /* call function normally */
Example 6-3. Assembly Language Program Called by
.global asmfunc
.global gvar asmfunc:
MOV &gvar,R11
ADD R11,R12
RET
In the C++ program in
, the extern "C" declaration tells the compiler to use C naming conventions (i.e., no name mangling). When the linker resolves the .global asmfunc reference, the corresponding definition in the assembly file will match.
The parameter I is passed in R12, and the result is returned in R12.
6.5.2 Accessing Assembly Language Variables From C/C++
It is sometimes useful for a C/C++ program to access variables or constants defined in assembly language. There are several methods that you can use to accomplish this, depending on where and how the item is defined: a variable defined in the .bss section, a variable not defined in the .bss section, or a constant.
6.5.2.1
Accessing Assembly Language Global Variables
Accessing uninitialized variables from the .bss section or a section named with .usect is straightforward:
1. Use the .bss or .usect directive to define the variable.
2. Use the .def or .global directive to make the definition external.
3. Use the appropriate linkname in assembly language.
4. In C/C++, declare the variable as extern and access it normally.
and
show how you can access a variable defined in .bss.
Example 6-4. Assembly Language Variable Program
* Note the use of underscores in the following lines
.bss
var,4,4
.global
var
; Define the variable
; Declare it as external
SLAU132D – June 2009
Submit Documentation Feedback
Run-Time Environment
103
Interfacing C and C++ With Assembly Language
Example 6-5. C Program to Access Assembly Language From
extern int var; var = 1;
/* External variable */
/* Use the variable */ www.ti.com
6.5.2.2
Accessing Assembly Language Constants
You can define global constants in assembly language by using the .set, .def, and .global directives, or you can define them in a linker command file using a linker assignment statement. These constants are accessible from C/C++ only with the use of special operators.
For normal variables defined in C/C++ or assembly language, the symbol table contains the address of
the value of the variable. For assembler constants, however, the symbol table contains the value of the constant. The compiler cannot tell which items in the symbol table are values and which are addresses.
If you try to access an assembler (or linker) constant by name, the compiler attempts to fetch a value from the address represented in the symbol table. To prevent this unwanted fetch, you must use the & (address of) operator to get the value. In other words, if x is an assembly language constant, its value in C/C++ is
&x.
You can use casts and #defines to ease the use of these symbols in your program, as in
and
Example 6-6. Accessing an Assembly Language Constant From C
extern int table_size; /*external ref */
#define TABLE_SIZE ((int) (&table_size))
.
/* use cast to hide address-of */
.
.
for (I=0; i<TABLE_SIZE; ++I) /* use like normal symbol */
Example 6-7. Assembly Language Program for
_table_size .set
10000 ; define the constant
.global _table_size ; make it global
Because you are referencing only the symbol's value as stored in the symbol table, the symbol's declared type is unimportant. In
Example 6-6 , int is used. You can reference linker-defined symbols in a similar
manner.
6.5.3 Sharing C/C++ Header Files With Assembly Source
You can use the .cdecls assembler directive to share C headers containing declarations and prototypes between C and assembly code. Any legal C/C++ can be used in a .cdecls block and the C/C++ declarations will cause suitable assembly to be generated automatically, allowing you to reference the
C/C++ constructs in assembly code. For more information, see the C/C++ header files chapter in the
MSP430 Assembly Language Tools User's Guide.
104
Run-Time Environment
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Interrupt Handling
6.5.4 Using Inline Assembly Language
Within a C/C++ program, you can use the asm statement to insert a single line of assembly language into the assembly language file created by the compiler. A series of asm statements places sequential lines of assembly language into the compiler output with no intervening code. For more information, see
.
The asm statement is useful for inserting comments in the compiler output. Simply start the assembly code string with a semicolon (;) as shown below: asm(";*** this is an assembly language comment");
Note: Using the asm Statement
Keep the following in mind when using the asm statement:
•
Be extremely careful not to disrupt the C/C++ environment. The compiler does not check or analyze the inserted instructions.
•
Avoid inserting jumps or labels into C/C++ code because they can produce unpredictable results by confusing the register-tracking algorithms that the code generator uses.
•
Do not change the value of a C/C++ variable when using an asm statement. This is because the compiler does not verify such statements. They are inserted as is into the assembly code, and potentially can cause problems if you are not sure of their effect.
•
Do not use the asm statement to insert assembler directives that change the assembly environment.
•
Avoid creating assembly macros in C code and compiling with the --symdebug:dwarf (or
-g) option. The C environment’s debug information and the assembly macro expansion are not compatible.
6.6
Interrupt Handling
As long as you follow the guidelines in this section, you can interrupt and return to C/C++ code without disrupting the C/C++ environment. When the C/C++ environment is initialized, the startup routine does not enable or disable interrupts. If the system is initialized by way of a hardware reset, interrupts are disabled.
If your system uses interrupts, you must handle any required enabling or masking of interrupts. Such operations have no effect on the C/C++ environment and are easily incorporated with asm statements or calling an assembly language function.
6.6.1 Saving Registers During Interrupts
When C/C++ code is interrupted, the interrupt routine must preserve the contents of all machine registers that are used by the routine or by any functions called by the routine. Register preservation must be explicitly handled by the interrupt routine.
SLAU132D – June 2009
Submit Documentation Feedback
Run-Time Environment
105
Interrupt Handling
www.ti.com
6.6.2 Using C/C++ Interrupt Routines
A C/C++ interrupt routine is like any other C/C++ function in that it can have local variables and register variables. Except for software interrupt routines, an interrupt routine must be declared with no arguments and must return void. For example: interrupt void example (void)
{
...
}
If a C/C++ interrupt routine does not call any other functions, only those registers that the interrupt handler uses are saved and restored. However, if a C/C++ interrupt routine does call other functions, these functions can modify unknown registers that the interrupt handler does not use. For this reason, the routine saves all the save-on-call registers if any other functions are called. (This excludes banked registers.) Do not call interrupt handling functions directly.
Interrupts can be handled directly with C/C++ functions by using the interrupt pragma or the interrupt keyword. For information, see
and
6.6.3 Using Assembly Language Interrupt Routines
You can handle interrupts with assembly language code as long as you follow the same register conventions the compiler does. Like all assembly functions, interrupt routines can use the stack, access global C/C++ variables, and call C/C++ functions normally. When calling C/C++ functions, be sure that any save-on-call registers are preserved before the call because the C/C++ function can modify any of these registers. You do not need to save save-on-entry registers because they are preserved by the called
C/C++ function.
6.6.4 Interrupt Vectors
The interrupt vectors for the MSP430 and MSP430X devices are 16 bits. Therefore, interrupt service routines (ISR’s) must be placed into the low 64K of memory. Convenience macros are provided in the
MSP430X device headers file to declare interrupts to ensure 16-bit placement when linking.
Alternatively, use the CODE_SECTIONS pragma to place the code for ISRs into sections separate from the default .text sections. Use the linker command file and the SECTIONS directive to ensure the code sections associated with ISRs are placed into low memory.
6.6.5 Other Interrupt Information
An interrupt routine can perform any task performed by any other function, including accessing global variables, allocating local variables, and calling other functions.
When you write interrupt routines, keep the following points in mind:
•
It is your responsibility to handle any special masking of interrupts.
•
A C/C++ interrupt routine cannot be called explicitly.
•
In a system reset interrupt, such as c_int00, you cannot assume that the run-time environment is set up; therefore, you cannot allocate local variables, and you cannot save any information on the run-time
stack.
•
In assembly language, remember to precede the name of a C/C++ interrupt with the appropriate linkname. For example, refer to c_int00 as _c_int00.
106
Run-Time Environment
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Using Intrinsics to Access Assembly Language Statements
6.7
Using Intrinsics to Access Assembly Language Statements
The compiler recognizes a number of intrinsic operators. Intrinsics are used like functions and produce assembly language statements that would otherwise be inexpressible in C/C++. You can use C/C++ variables with these intrinsics, just as you would with any normal function. The intrinsics are specified with a leading underscore, and are accessed by calling them as you do a function. For example: short state;
: state = _get_SR_register();
No declaration of the intrinsic functions is necessary.
6.7.1 MSP430 Intrinsics
lists all of the intrinsic operators in the MSP430 C/C++ compiler. A function-like prototype is presented for each intrinsic that shows the expected type for each parameter. If the argument type does not match the parameter, type conversions are performed on the argument.
For more information on the resulting assembly language mnemonics, see the MSP430x1xx Family User’s
Guide, the MSP430x3xx Family User’s Guide, and the MSP430x4xx Family User’s Guide.
Table 6-5. MSP430 Intrinsics
Intrinsic
unsigned short unsigned long unsigned short unsigned short unsigned short unsigned short unsigned long void unsigned char unsigned long unsigned short void void void void void
_bcd_add_short(unsigned short op1, unsigned short op2);
_bcd_add_long(unsigned long op1, unsigned long op2);
_bic_SR_register(unsigned short mask);
_bic_SR_register_on_exit(unsigned short mask);
_bis_SR_register(unsigned short mask);
_bis_SR_register_on_exit(unsigned short mask);
_data16_read_addr(unsigned short addr);
_data16_write_addr (unsigned short addr, unsigned long src);
_data20_read_char(unsigned long addr);
(1)
_data20_read_long(unsigned long addr);
(1)
_data20_read_short(unsigned long addr);
(1)
_data20_write_char(unsigned long addr, unsigned char src);
(1)
_data20_write_long(unsigned long addr, unsigned long src);
(1)
_data20_write_short(unsigned long addr, unsigned short src);
(1)
_delay_cycles(unsigned long);
_disable_interrupt(void);
OR
_disable_interrupts(void);
Generated Assembly
MOV op1, dst
CLRC
DADD op2, dst
MOV op1_low, dst_low
MOV op1_hi, dst_hi
CLRC
DADD op2_low, dst_low
DADD op2_hi, dst_hi
BIC mask, SR
BIC mask, saved_SR
BIS mask, SR
BIS mask, saved_SR
MOV.W addr, Rx
MOVA 0(Rx), dst
MOV.W addr, Rx
MOVA src, 0(Rx)
MOVA addr, Rx
MOVX.B 0(Rx), dst
MOVA addr, Rx
MOVX.W 0(Rx), dst.lo
MOVX.W 2(Rx), dst.hi
MOVA addr, Rx
MOVX.W 0(Rx), dst
MOVA addr, Rx
MOVX.B src, 0(Rx)
MOVA addr, Rx
MOVX.W src.lo, 0(Rx)
MOVX.W src.hi, 2(Rx)
MOVA addr, Rx
MOVX.W src, 0(Rx)
See
DINT
(1)
Instrinsic encodes multiple instructions depending on the code. The most common instructions produced are presented here.
SLAU132D – June 2009
Submit Documentation Feedback
Run-Time Environment
107
Using Intrinsics to Access Assembly Language Statements
Intrinsic
void void void void void void void unsigned int unsigned short unsigned short unsigned short unsigned short unsigned short unsigned short void void void void void void void unsigned short www.ti.com
Table 6-5. MSP430 Intrinsics (continued)
Generated Assembly
EINT _enable_interrupt(void);
OR
_enable_interrupts(void);
_even_in_range(unsigned int, unsigned int);
_get_interrupt_state(void);
_get_R4_register(void);
_get_R5_register(void);
_get_SP_register(void);
_get_SR_register(void);
_get_SR_register_on_exit(void);
_low_power_mode_0(void);
_low_power_mode_1(void);
_low_power_mode_2(void);
_low_power_mode_3(void);
_low_power_mode_4(void);
_low_power_mode_off_on_exit(void);
_never_executed(void);
_no_operation(void);
_op_code(unsigned short);
_set_interrupt_state(unsigned short src);
_set_R4_register(unsigned short src);
_set_R5_register(unsigned short src);
_set_SP_register(unsigned short src);
_swap_bytes(unsigned short src);
See
.
MOV SR, dst
MOV.W R4, dst
MOV.W R5, dst
MOV SP, dst
MOV SR, dst
MOV saved_SR, dst
BIS.W #0x18, SR
BIS.W #0x58, SR
BIS.W #0x98, SR
BIS.W #0xD8, SR
BIS.W #0xF8, SR
BIC.W #0xF0, saved_SR
See
NOP
Encodes whatever instruction corresponds to the argument.
MOV src, SR
MOV.W src, R4
MOV.W src, R5
MOV src, SP
MOV src, dst
SWPB dst
6.7.2 The __delay_cycle Intrinsic
The __delay_cycles intrinsic inserts code to consume precisely the number of specified cycles with no side effects. The number of cycles delayed must be a compile-time constant.
6.7.3 The _never_executed Intrinsic
The MSP430 C/C++ Compiler supports a _never_executed( ) intrinsic that can be used to assert that a default label in a switch block is never executed. If you assert that a default label is never executed the compiler can generate more efficient code based on the values specified in the case labels within a switch block.
6.7.3.1
Using _never_executed With a Vector Generator
The _never_executed( ) intrinsic is specifically useful for testing the values of an MSP430 interrupt vector generator such as the vector generator for Timer A (TAIV). MSP430 vector generator values are mapped to an interrupt source and are characterized in that they fall within a specific range and can only take on even values. A common way to handle a particular interrupt source represented in a vector generator is to use a switch statement. However, a compiler is constrained by the C language in that it can make no assumptions about what values a switch expression may have. The compiler will have to generate code to handle every possible value, which leads to what would appear to be inefficient code.
108
Run-Time Environment
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Using Intrinsics to Access Assembly Language Statements
The _never_executed( ) intrinsic can be used to assert to the compiler that a switch expression can only take on values represented by the case labels within a switch block. Having this assertion, the compiler can avoid generating test code for handling values not specified by the switch case labels. Having this assertion is specifically suited for handling values that characterize a vector generator.
illustrates a switch block that handles the values of the Timer B (TBIV) vector generator.
Example 6-8. TBIV Vector Generator
__interrupt void Timer_B1 (void)
{ switch( TBIV )
{ case 0: break; /* Do nothing */ case 2: TBCCR1 += 255; state +=1; break; case 4: TBCCR0 = 254;
TBCCR1 = 159; state =200; break; case 6: break; case 8: break; case 10: break; case 12: break; case 14: break; default: _never_executed();
}
}
In
using the _never_executed( ) intrinsic asserts that the value of TBIV can only take on the values specified by the case labels, namely the even values from 0 to 14. Normally, the compiler would have to generate code to handle any value which would result in extra range checks. Instead, for this example, the compiler will generate a switch table where the value of TBIV is simply added to the PC to jump to the appropriate code block handling each value represented by the case labels.
6.7.3.2
Using _never_executed With General Switch Expressions
Using the _never_executed( ) intrinsic at the default label can also improve the generated switch code for more general switch expressions that do not involve vector generator type values.
Example 6-9. General Switch Statement
switch( val)
{ case 0: case 5: action(a); break; case 14: action(b); break;
} default: _never_executed();
Normally, for the switch expression values 0 and 5, the compiler generates code to test for both 0 and 5 since the compiler must handle the possible values 1–4. The _never_executed( ) intrinsic in
asserts that val cannot take on the values 1–4 and therefore the compiler only needs to generate a single test (val < 6) to handle both case labels.
Additionally, using the _never_executed( ) intrinsic results in the assertion that if val is not 0 or 5 then it has to be 14 and the compiler has no need to generate code to test for val == 14.
The _never_executed( ) intrinsic is only defined when specified as the single statement following a default case label. The compiler ignores the use of the intrinsic in any other context.
SLAU132D – June 2009
Submit Documentation Feedback
Run-Time Environment
109
System Initialization
www.ti.com
6.8
System Initialization
Before you can run a C/C++ program, you must create the C/C++ run-time environment. The C/C++ boot routine performs this task using a function called c_int00 (or _c_int00). The run-time-support source library, rts.src, contains the source to this routine in a module named boot.c (or boot.asm).
To begin running the system, the c_int00 function can be called by reset hardware. You must link the c_int00 function with the other object modules. This occurs automatically when you use the --rom_model or --ram_model link option and include a standard run-time-support library as one of the linker input files.
When C/C++ programs are linked, the linker sets the entry point value in the executable output module to the symbol c_int00.
The c_int00 function performs the following tasks to initialize the environment:
1. Reserves space for the user mode run-time stack, and sets up the initial value of the stack pointer (SP)
2. It initializes global variables by copying the data from the initialization tables to the storage allocated for the variables in the .bss section. If you are initializing variables at load time (--ram_model option), a loader performs this step before the program runs (it is not performed by the boot routine). For more information, see
3. Executes the global constructors found in the global constructors table. For more information, see
.
4. Calls the function main to run the C/C++ program
You can replace or modify the boot routine to meet your system requirements. However, the boot routine
must perform the operations listed above to correctly initialize the C/C++ environment.
6.8.1 System Pre-Initialization
The _c_int00( ) initialization routine also provides a mechanism for an application to perform the MSP430 setup (set I/O registers, enable/disable timers, etc.) before the C/C++ environment is initialized.
Before calling the routine that initializes C/C++ global data and calls any C++ constructors, the boot routine makes a call to the function _system_pre_init( ). A developer can implement a customized version of _system_pre_init( ) to perform any application-specific initialization before proceeding with C/C++ environment setup. In addition, the default C/C++ data initialization can be bypassed if _system_pre_init( ) returns a 0. By default, _system_pre_init( ) should return a non-zero value.
In order to perform application-specific initializations, you can create a customized version of
_system_pre_init( ) and add it to the application project. The customized version will replace the default definition included in the run-time library if it is linked in before the run-time library.
The default stubbed version of _system_pre_init( ) is included with the run-time library. It is located in the file pre_init.c and is included in the run-time source library (rts.src). The archiver utility (ar430) can be used to extract pre_init.c from the source library.
6.8.2 Run-Time Stack
The run-time stack is allocated in a single continuous block of memory and grows down from high addresses to lower addresses. The SP points to the top of the stack.
The code does not check to see if the run-time stack overflows. Stack overflow occurs when the stack grows beyond the limits of the memory space that was allocated for it. Be sure to allocate adequate memory for the stack.
The stack size can be changed at link time by using the --stack_size link option on the linker command line and specifying the stack size as a constant directly after the option.
The C/C++ boot routine shipped with the compiler sets up the user/thread mode run-time stack. If your program uses a run-time stack when it is in other operating modes, you must also allocate space and set up the run-time stack corresponding to those modes.
110
Run-Time Environment
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
System Initialization
6.8.3 Automatic Initialization of Variables
Some global variables must have initial values assigned to them before a C/C++ program starts running.
The process of retrieving these variables' data and initializing the variables with the data is called autoinitialization.
The compiler builds tables in a special section called .cinit that contains data for initializing global and static variables. Each compiled module contains these initialization tables. The linker combines them into a single table (a single .cinit section). The boot routine or a loader uses this table to initialize all the system variables.
Note: Initializing Variables
In ANSI/ISO C, global and static variables that are not explicitly initialized must be set to 0 before program execution. The C/C++ compiler does not perform any preinitialization of uninitialized variables. Explicitly initialize any variable that must have an initial value of 0.
Global variables are either autoinitialized at run time or at load time; see
and
Also see
6.8.4 Initialization Tables
The tables in the .cinit section consist of variable-size initialization records. Each variable that must be autoinitialized has a record in the .cinit section.
shows the format of the .cinit section and the initialization records.
Figure 6-2. Format of Initialization Records in the .cinit Section
.cinit section
Initialization record 1
Initialization record 2
Initialization record
Initialization record 3
Size in bytes
Pointer to
.bss area
Initialization data
Initialization record n
The fields of an initialization record contain the following information:
•
The first field of an initialization record contains the size (in bytes) of the initialization data. The width of this field is one word (16-bit).
•
The second field contains the starting address of the area within the .bss section where the initialization data must be copied. The width of this field is one word.
•
The third field contains the data that is copied into the .bss section to initialize the variable. The width of this field is variable.
Each variable that must be autoinitialized has an initialization record in the .cinit section.
shows initialized global variables defined in C.
shows the corresponding initialization table.
Example 6-10. Initialized Variables Defined in C
int i = 23; int a[5] = { 1, 2, 3, 4, 5 };
SLAU132D – June 2009
Submit Documentation Feedback
Run-Time Environment
111
System Initialization
Example 6-11. Initialized Information for Variables Defined in
.sect
".cinit"
.align
2
.field
2,16
.field
i+0,16
.field
23,16
.sect
".cinit"
.align
2
.field
$C$IR_1,16
.field
a+0,16
.field
1,16
.field
2,16
.field
3,16
.field
4,16
.field
5,16
$C$IR_1: .set 10
.global
i
.bss
i,2,2
.global
a
.bss
a,10,2
; i @ 0
; a[0] @ 0
; a[1] @ 16
; a[2] @ 32
; a[3] @ 48
; a[4] @ 64 www.ti.com
The .cinit section must contain only initialization tables in this format. When interfacing assembly language modules, do not use the .cinit section for any other purpose.
The table in the .pinit section simply consists of a list of addresses of constructors to be called (see
Figure 6-3 ). The constructors appear in the table after the .cinit initialization.
Figure 6-3. Format of Initialization Records in the .pinit Section
.pinit section
Address of constructor 1
Address of constructor 2
Address of constructor 3
Address of constructor n
When you use the --rom_model or --ram_model option, the linker combines the .cinit sections from all the
C modules and appends a null word to the end of the composite .cinit section. This terminating record appears as a record with a size field of 0 and marks the end of the initialization tables.
Likewise, the --rom_model or --ram_model link option causes the linker to combine all of the .pinit sections from all C/C++ modules and append a null word to the end of the composite .pinit section. The boot routine knows the end of the global constructor table when it encounters a null constructor address.
The const-qualified variables are initialized differently; see
112
Run-Time Environment
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
System Initialization
6.8.5 Autoinitialization of Variables at Run Time
Autoinitializing variables at run time is the default method of autoinitialization. To use this method, invoke the linker with the --rom_model option.
Using this method, the .cinit section is loaded into memory along with all the other initialized sections, and global variables are initialized at run time. The linker defines a special symbol called cinit that points to the beginning of the initialization tables in memory. When the program begins running, the C/C++ boot routine copies data from the tables (pointed to by .cinit) into the specified variables in the .bss section. This allows initialization data to be stored in ROM and copied to RAM each time the program starts.
illustrates autoinitialization at run time. Use this method in any system where your application runs from code burned into ROM.
Figure 6-4. Autoinitialization at Run Time
Object file Memory
.cinit
section
Loader cint
Initialization tables
(EXT_MEM)
Boot routine
.bss
section
(D_MEM)
6.8.6 Initialization of Variables at Load Time
Initialization of variables at load time enhances performance by reducing boot time and by saving the memory used by the initialization tables. To use this method, invoke the linker with the --ram_model option.
When you use the --ram_model link option, the linker sets the STYP_COPY bit in the .cinit section's header. This tells the loader not to load the .cinit section into memory. (The .cinit section occupies no space in the memory map.) The linker also sets the cinit symbol to -1 (normally, cinit points to the beginning of the initialization tables). This indicates to the boot routine that the initialization tables are not present in memory; accordingly, no run-time initialization is performed at boot time.
A loader (which is not part of the compiler package) must be able to perform the following tasks to use initialization at load time:
•
Detect the presence of the .cinit section in the object file
•
Determine that STYP_COPY is set in the .cinit section header, so that it knows not to copy the .cinit
section into memory
•
Understand the format of the initialization tables
illustrates the initialization of variables at load time.
SLAU132D – June 2009
Submit Documentation Feedback
Run-Time Environment
113
Compiling for 20-Bit MSP430X Devices
Figure 6-5. Initialization at Load Time
Object file Memory
.cinit
Loader www.ti.com
.bss
Regardless of the use of the --rom_model or --ram_model options, the .pinit section is always loaded and processed at run time.
6.8.7 Global Constructors
All global C++ variables that have constructors must have their constructor called before main (). The compiler builds a table of global constructor addresses that must be called, in order, before main () in a section called .pinit. The linker combines the .pinit section form each input file to form a single table in the
.pinit section. The boot routine uses this table to execute the constructors.
6.9
Compiling for 20-Bit MSP430X Devices
The MSP430 tools support compiling and linking code for MSP430 and MSP430X (MSP430X) devices.
See the following for more information on options and topics that apply to compiling for the MSP430X devices:
•
Use the --silicon_version=mspx option to compile for MSP430X devices. See
•
Function pointers are 20-bits. See and .
•
The compiler supports a large-code memory model while generating code for MSP430X devices. See
.
•
The compiler supports a large-data memory model while generating code for MSP430X devices. See
.
•
Any assembly routines that interface with MSP430X C programs must fit the large code model. See
.
•
Interrupt service routines must be placed into low memory. See
.
•
Link with the rts430x.lib or rts430x_eh.lib run-time-support library.
114
Run-Time Environment
SLAU132D – June 2009
Submit Documentation Feedback
Chapter 7
SLAU132D – June 2009
Using Run-Time-Support Functions and Building Libraries
Some of the tasks that a C/C++ program performs (such as I/O, dynamic memory allocation, string operations, and trigonometric functions) are not part of the C/C++ language itself. However, the ANSI/ISO
C standard defines a set of run-time-support functions that perform these tasks. The C/C++ compiler implements the complete ISO standard library except for those facilities that handle exception conditions and locale issues (properties that depend on local language, nationality, or culture). Using the ANSI/ISO standard library ensures a consistent set of functions that provide for greater portability.
In addition to the ANSI/ISO-specified functions, the run-time-support library includes routines that give you processor-specific commands and direct C language I/O requests. These are detailed in
and
.
A library-build process is provided with the code generation tools that lets you create customized run-time-support libraries. This process is described in
.
Topic
..................................................................................................
Page
7.1
C and C++ Run-Time Support Libraries
......................................
7.2
Run-Time-Support Function Libraries
........................................
7.3
The C I/O Functions
.................................................................
7.4
Handling Reentrancy (_register_lock() and _register_unlock()
Functions)
..............................................................................
7.5
..............................................................
7.6
MSP430 Run-Time Library Details
.............................................
SLAU132D – June 2009
Submit Documentation Feedback
Using Run-Time-Support Functions and Building Libraries
115
C and C++ Run-Time Support Libraries
www.ti.com
7.1
C and C++ Run-Time Support Libraries
The standard run-time library includes code for both the C and C++ libraries, as well as compiler helper functions and initialization code. The library includes all the features of the C++ Library, including the
Standard Template Library (STL), streams, and strings. The following exceptions and caveats are noted:
•
The <complex> header and its functions are not included in the library.
•
The C++ library supports wide chars, in that template functions and classes that are defined for char are also available for wide char. For example, wide char stream classes wios, wiostream, wstreambuf and so on (corresponding to char classes ios, iostream, streambuf) are implemented. However, there is no low-level file I/O for wide chars. Also, the C library interface to wide char support (through the
C++ headers <cwchar> and <cwctype>) is limited as described in
The C++ library included with the compiler is licensed from Dinkumware, Ltd . The Dinkumware C++ library is a fully conforming, industry-leading implementation of the standard C++ library.
TI does not provide documentation that covers the functionality of the C++ library. We suggest referring to one of the following sources:
•
The Standard C++ Library: A Tutorial and Reference,Nicolai M. Josuttis, Addison-Wesley, ISBN
0-201-37926-0
•
The C++ Programming Language (Third or Special Editions), Bjarne Stroustrup, Addison-Wesley,
ISBN 0-201-88954-4 or 0-201-70073-5
•
Dinkumware's online reference at http://dinkumware.com/manuals
7.1.1 Linking Code With the Object Library
When you link your program, you must specify the object library as one of the linker input files so that references to the I/O and run-time-support functions can be resolved. You can either specify the library or allow the compiler to select one for you. See
for further information.
You should specify libraries last on the linker command line because the linker searches a library for unresolved references when it encounters the library on the command line. You can also use the
--reread_libs linker option to force repeated searches of each library until the linker can resolve no more references.
When a library is linked, the linker includes only those library members required to resolve undefined references. For more information about linking, see the MSP430 Assembly Language Tools User's Guide.
C, C++, and mixed C and C++ programs can use the same run-time-support library. Run-time-support functions and variables that can be called and referenced from both C and C++ will have the same linkage.
7.1.2 Header Files
To include the correct set of header files depending on which library you are using, you can set the
MSP_C_DIR environment variable to the specific include directory: "include\lib". The source support for libraries is included in the rtssrc.zip file. See
for details on rebuilding libraries.
7.1.3 Modifying a Library Function
You can inspect or modify library functions by unzipping the source file (rtssrc.zip), changing the specific function file, and rebuilding the library. When extracted (with any standard unzip tool on windows, linux, or unix), this zip file will recreate the run-time source tree for the run-time library.
You can also build a new library this way, rather than rebuilding into rts430.lib. See
116
Using Run-Time-Support Functions and Building Libraries
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
C and C++ Run-Time Support Libraries
7.1.4 Changes to the Run-Time-Support Libraries
The following changes and additions apply to the runtime support libraries in the /lib subdirectory of the release package.
7.1.4.1
Minimal Support for Internationalization
The library now includes the header files <locale.h>, <wchar.h>, and <wctype.h>, which provide APIs to support non-ASCII character sets and conventions. Our implementation of these APIs is limited in the following ways:
•
The library has minimal support for wide and multi-byte characters. The type wchar_t is implemented as int. The wide character set is equivalent to the set of values of type char. The library includes the header files <wchar.h> and <wctype.h> but does not include all the functions specified in the standard.
So-called multi-byte characters are limited to single characters. There are no shift states. The mapping between multi-byte characters and wide characters is simple equivalence; that is, each wide character maps to and from exactly a single multi-byte character having the same value.
•
The C library includes the header file <locale.h> but with a minimal implementation. The only supported locale is the C locale. That is, library behavior that is specified to vary by locale is hard-coded to the behavior of the C locale, and attempting to install a different locale via a call to setlocale() will return NULL.
7.1.4.2
Allowable Number of Open Files
In the <stdio.h> header file, the value for the macro FOPEN_MAX has been changed from 12 to the value of the macro _NFILE, which is set to 10. The impact is that you can only have 10 files simultaneously open at one time (including the pre-defined streams - stdin, stdout, stderr).
The C standard requires that the minimum value for the FOPEN_MAX macro is 8. The macro determines the maximum number of files that can be opened at one time. The macro is defined in the stdio.h header file and can be modified by changing the value of the _NFILE macro.
SLAU132D – June 2009
Submit Documentation Feedback
Using Run-Time-Support Functions and Building Libraries
117
Run-Time-Support Function Libraries
www.ti.com
7.2
Run-Time-Support Function Libraries
MSP430 compiler releases include pre-built run-time libraries that provide all the standard capabilities.
Separate libraries are provided for , and C++ exception support. See
for information on the library-naming conventions.
The run-time-support library contains the following:
•
ANSI/ISO C/C++ standard library
•
C I/O library
•
Low-level support functions that provide I/O to the host operating system
•
Intrinsic arithmetic routines
•
System startup routine, _c_int00
•
Functions and macros that allow C/C++ to access specific instructions
The classic run-time-support libraries do not contain functions involving signals and locale issues.
7.2.1 Linking Code With the Object Library
When you link your program, you must specify the object library as one of the linker input files so that references to the I/O and run-time-support functions can be resolved. You can either specify the library or allow the compiler to select one for you. See
for further information.
You should specify libraries last on the linker command line because the linker searches a library for unresolved references when it encounters the library on the command line. You can also use the
--reread_libs linker option to force repeated searches of each library until the linker can resolve no more references.
When a library is linked, the linker includes only those library members required to resolve undefined references. For more information about linking, see the MSP430 Assembly Language Tools User's Guide.
C, C++, and mixed C and C++ programs can use the same run-time-support library. Run-time-support functions and variables that can be called and referenced from both C and C++ will have the same linkage.
7.2.2 Nonstandard Header Files in rtssrc.zip
The rtssrc.zip self-processing zip file contains these non-ANSI include files that are used to build the library:
•
The values.h file contains the definitions necessary for recompiling the trigonometric and transcendental math functions. If necessary, you can customize the functions in values.h.
•
The file.h file includes macros and definitions used for low-level I/O functions.
•
The format.h file includes structures and macros used in printf and scanf.
•
The 430cio.h file includes low-level, target-specific C I/O macro definitions. If necessary, you can customize 430cio.h.
•
The rtti.h file includes internal function prototypes necessary to implement run-time type identification.
•
The vtbl.h file contains the definition of a class's virtual function table format.
7.2.3 Modifying a Library Function
You can inspect or modify library functions by unzipping the source file (rtssrc.zip), changing the specific function file, and rebuilding the library.
You can also build a new library this way, rather than rebuilding into rts430.lib. See
118
Using Run-Time-Support Functions and Building Libraries
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
The C I/O Functions
7.3
The C I/O Functions
The C I/O functions make it possible to access the host's operating system to perform I/O. The capability to perform I/O on the host gives you more options when debugging and testing code.
To use the I/O functions, include the header file stdio.h, or cstdio for C++ code, for each module that references a C I/O function.
For example, given the following C program in a file named main.c:
#include <stdio.h>; main()
{
FILE *fid; fid = fopen("myfile","w"); fprintf(fid,"Hello, world\n"); fclose(fid); printf("Hello again, world\n");
}
Issuing the following compiler command compiles, links, and creates the file main.out from the run-time-support library: cl430 main.c --run_linker --heap_size=400 --library=rts430.lib --output_file=main.out
Executing main.out results in
Hello, world being output to a file and
Hello again, world being output to your host's stdout window.
With properly written device drivers, the library also offers facilities to perform I/O on a user-specified device.
Note: C I/O Buffer Failure
If there is not enough space on the heap for a C I/O buffer, buffered operations on the file will fail. If a call to printf() mysteriously fails, this may be the reason. Check the size of the heap. To set the heap size, use the --heap_size option when linking (see
7.3.1 Overview of Low-Level I/O Implementation
The code that implements I/O is logically divided into layers: high level, low level, and device level.
The high-level functions are the standard C library of stream I/O routines (printf, scanf, fopen, getchar, and so on). These routines map an I/O request to one or more of the I/O commands that are handled by the low-level routines.
The low-level routines are comprised of basic I/O functions: open, read, write, close, lseek, rename, and unlink. These low-level routines provide the interface between the high-level functions and the device-level drivers that actually perform the I/O command on the specified device.
The low-level functions also define and maintain a stream table that associates a file descriptor with a device. The stream table interacts with the device table to ensure that an I/O command performed on a stream executes the correct device-level routine.
The data structures interact as shown in
SLAU132D – June 2009
Submit Documentation Feedback
Using Run-Time-Support Functions and Building Libraries
119
The C I/O Functions
Figure 7-1. Interaction of Data Structures in I/O Functions
Stream table Device table file_descriptor1 file_descriptor2 open read open read www.ti.com
The first three streams in the stream table are predefined to be stdin, stdout, and stderr and they point to the host device and associated device drivers.
Figure 7-2. The First Three Streams in the Stream Table
Stream table Device table file_descriptor1 file_descriptor2 file_descriptor3 stdin stdout stderr
Host open read open read
At the next level are the user-definable device-level drivers. They map directly to the low-level I/O functions. The run-time-support library includes the device drivers necessary to perform I/O on the host on which the debugger is running.
The specifications for writing device-level routines to interface with the low-level routines follow. Each function must set up and maintain its own data structures as needed. Some function definitions perform no action and should just return.
120
Using Run-Time-Support Functions and Building Libraries
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
add_device
Syntax for C
Defined in
Description
Return Value
Example
add_device — Add Device to Device Table
Add Device to Device Table
#include <file.h>
int add_device(char *name,
unsigned flags,
int (*dopen)( ),
int (*dclose)( ),
int (*dread)( ),
int (*dwrite)( ),
fpos_t (*dlseek)( ),
int (*dunlink)( ),
int (*drename)( )); lowlev.c in rtssrc.zip
The add_device function adds a device record to the device table allowing that device to be used for input/output from C. The first entry in the device table is predefined to be the host device on which the debugger is running. The function add_device() finds the first empty position in the device table and initializes the fields of the structure that represent a device.
To open a stream on a newly added device use fopen( ) with a string of the format
devicename:filename as the first argument.
•
The name is a character string denoting the device name. The name is limited to 8 characters.
•
The flags are device characteristics. The flags are as follows:
_SSA Denotes that the device supports only one open stream at a time
_MSA Denotes that the device supports multiple open streams
More flags can be added by defining them in stdio.h.
•
The dopen, dclose, dread, dwrite, dlseek, dunlink, and drename specifiers are function pointers to the device drivers that are called by the low-level functions to perform I/O on the specified device. You must declare these functions with the interface specified in
. The device drivers for the host that the MSP430 debugger is run on are included in the C I/O library.
The function returns one of the following values:
0
1 if successful if fails
does the following:
•
Adds the device mydevice to the device table
•
Opens a file named test on that device and associates it with the file *fid
•
Writes the string Hello, world into the file
•
Closes the file
SLAU132D – June 2009
Submit Documentation Feedback
Using Run-Time-Support Functions and Building Libraries
121
close — Close File or Device for I/O
close
Syntax for C
Syntax for C++
Description
Return Value
www.ti.com
Close File or Device for I/O
#include <stdio.h>
#include <file.h>
int close (int file_descriptor );
#include <cstdio>
#include <file.h>
int std::close (int file_descriptor );
The close function closes the device or file associated with file_descriptor.
The file_descriptor is the stream number assigned by the low-level routines that is associated with the opened device or file.
The return value is one of the following:
0
1 if successful if fails
lseek
Syntax for C
Syntax for C++
Description
Return Value
Set File Position Indicator
#include <stdio.h>
#include <file.h>
long lseek (intfile_descriptor, long offset, intorigin);
#include <cstdio>
#include <file.h>
long std::lseek (int file_descriptor , long offset , int origin );
The lseek function sets the file position indicator for the given file to origin + offset. The file position indicator measures the position in characters from the beginning of the file.
•
The file_descriptor is the stream number assigned by the low-level routines that the device-level driver must associate with the opened file or device.
•
The offset indicates the relative offset from the origin in characters.
•
The origin is used to indicate which of the base locations the offset is measured from.
The origin must be a value returned by one of the following macros:
SEEK_SET (0x0000) Beginning of file
SEEK_CUR (0x0001) Current value of the file position indicator
SEEK_END (0x0002) End of file
The return function is one of the following:
# new value of the file-position indicator if successful
EOF if fails
122
Using Run-Time-Support Functions and Building Libraries
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
open
Syntax for C
Syntax for C++
Description
Return Value
open — Open File or Device for I/O
Open File or Device for I/O
#include <stdio.h>
#include <file.h>
int open (const char * path , unsigned flags , int file_descriptor );
#include <cstdio>
#include <file.h>
int std::open (const char * path , unsigned flags , int file_descriptor );
The open function opens the device or file specified by path and prepares it for I/O.
•
The path is the filename of the file to be opened, including path information.
•
The flags are attributes that specify how the device or file is manipulated. The flags are specified using the following symbols:
O_RDONLY (0x0000) /* open for reading */
O_WRONLY (0x0001) /* open for writing */
O_RDWR (0x0002) /* open for read & write */
O_APPEND (0x0008) /* append on each write */
O_CREAT (0x0200) /* open with file create */
O_TRUNC (0x0400) /* open with truncation */
O_BINARY (0x8000) /* open in binary mode */
These parameters can be ignored in some cases, depending on how data is interpreted by the device. However, the high-level I/O calls look at how the file was opened in an fopen statement and prevent certain actions, depending on the open attributes.
•
The file_descriptor is the stream number assigned by the low-level routines that is associated with the opened file or device.
The next available file_descriptor (in order from 3 to 20) is assigned to each new device opened. You can use the finddevice() function to return the device structure and use this pointer to search the _stream array for the same pointer. The file_descriptor number is the other member of the _stream array.
The function returns one of the following values:
#-1
-1 if successful if fails
SLAU132D – June 2009
Submit Documentation Feedback
Using Run-Time-Support Functions and Building Libraries
123
read — Read Characters from Buffer
read
Syntax for C
Syntax for C++
Description
Return Value
www.ti.com
Read Characters from Buffer
0
#
-1
#include <stdio.h>
#include <file.h>
int read (int file_descriptor , char * buffer , unsigned count );
#include <cstdio>
#include <file.h>
int std::read (int file_descriptor , char *buffer , unsigned count );
The read function reads the number of characters specified by count to the buffer from the device or file associated with file_descriptor.
•
The file_descriptor is the stream number assigned by the low-level routines that is associated with the opened file or device.
•
The buffer is the location of the buffer where the read characters are placed.
•
The count is the number of characters to read from the device or file.
The function returns one of the following values: if EOF was encountered before the read was complete number of characters read in every other instance if fails
rename
Syntax for C
Syntax for C++
Description
Return Value
Rename File
#include <stdio.h>
#include <file.h>
int rename (const char * old_name , const char * new_name );
#include <cstdio>
#include <file.h>
int std::rename (const char * old_name , const char * new_name );
The rename function changes the name of a file.
•
The old_name is the current name of the file.
•
The new_name is the new name for the file.
The function returns one of the following values:
0 if successful
Non-0 if not successful
124
Using Run-Time-Support Functions and Building Libraries
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
unlink
Syntax for C
Syntax for C++
Description
Return Value
write
Syntax for C
Syntax for C++
Description
Return Value
unlink — Delete File
Delete File
#include <stdio.h>
#include <file.h>
int unlink (const char * path );
#include <cstdio>
#include <file.h>
int std::unlink (const char * path );
The unlink function deletes the file specified by path.
The path is the filename of the file to be opened, including path information.
The function returns one of the following values:
0
1 if successful if fails
Write Characters to Buffer
#include <stdio.h>
#include <file.h>
int write (int file_descriptor , const char * buffer , unsigned count );
#include <cstdio>
#include <file.h>
int write (int file_descriptor , const char * buffer , unsigned count );
The write function writes the number of characters specified by count from the buffer to the device or file associated with file_descriptor.
•
The file_descriptor is the stream number assigned by the low-level routines. It is associated with the opened file or device.
•
The buffer is the location of the buffer where the write characters are placed.
•
The count is the number of characters to write to the device or file.
The function returns one of the following values:
#
1 number of characters written if successful if fails
SLAU132D – June 2009
Submit Documentation Feedback
Using Run-Time-Support Functions and Building Libraries
125
write — Write Characters to Buffer www.ti.com
7.3.2 Adding a Device for C I/O
The low-level functions provide facilities that allow you to add and use a device for I/O at run time. The procedure for using these facilities is:
1. Define the device-level functions as described in
Note: Use Unique Function Names
The function names open, close, read, and so on, are used by the low-level routines. Use other names for the device-level functions that you write.
2. Use the low-level function add_device() to add your device to the device_table. The device table is a statically defined array that supports n devices, where n is defined by the macro _NDEVICE found in stdio.h/cstdio. The structure representing a device is also defined in stdio.h/cstdio and is composed of the following fields:
name flags function pointers
String for device name
Flags that specify whether the device supports multiple streams or not
Pointers to the device-level functions:
•
CLOSE
•
RENAME
•
LSEEK
•
WRITE
•
OPEN
•
UNLINK
•
READ
The first entry in the device table is predefined to be the host device on which the debugger is running.
The low-level routine add_device() finds the first empty position in the device table and initializes the device fields with the passed-in arguments. For a complete description, see
.
3. Once the device is added, call fopen() to open a stream and associate it with that device. Use
devicename:filename as the first argument to fopen().
illustrates adding and using a device for C I/O:
Example 7-1. Program for C I/O Device
#include <stdio.h>
/****************************************************************************/
/* Declarations of the user-defined device drivers */
/****************************************************************************/ extern int my_open(const char *path, unsigned flags, int fno); extern int my_close(int fno); extern int my_read(int fno, char *buffer, unsigned count); extern int my_write(int fno, const char *buffer, unsigned count); extern long my_lseek(int fno, long offset, int origin); extern int my_unlink(const char *path); extern int my_rename(const char *old_name, char *new_name); main()
{
FILE *fid; add_device("mydevice", _MSA, my_open, my_close, my_read, my_write, my_lseek, my_unlink, my_rename); fid = fopen("mydevice:test","w"); fprintf(fid,"Hello, world\n"); fclose(fid);
}
126
Using Run-Time-Support Functions and Building Libraries
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Handling Reentrancy (_register_lock() and _register_unlock() Functions)
7.4
Handling Reentrancy (_register_lock() and _register_unlock() Functions)
The C standard assumes only one thread of execution, with the only exception being extremly narrow support for signal handlers. The issue of reentrancy is avoided by not allowing you to do much of anything in a signal handler. However, BIOS applications have multiple threads which need to modify the same global program state, such as the CIO buffer, so reentrancy is a concern.
Part of the problem of reentrancy remains your responsibility, but the run-time-support environment does provide rudimentary support for multi-threaded reentrancy by providing support for critical sections. This implementation does not protect you from reentrancy issues such as calling run-time-support functions from inside interrupts; this remains your responsibility.
The run-time-support environment provides hooks to install critical section primitives. By default, a single-threaded model is assumed, and the critical section primitives are not employed. In a multi-threaded system such as BIOS, the kernel arranges to install semaphore lock primitive functions in these hooks, which are then called when the run-time-support enters code that needs to be protected by a critical section.
Throughout the run-time-support environment where a global state is accessed, and thus needs to be protected with a critical section, there are calls to the function _lock(). This calls the provided primitive, if installed, and acquires the semaphore before proceeding. Once the critical section is finished, _unlock() is called to release the semaphore.
Usually BIOS is responsible for creating and installing the primitives, so you do not need to take any action. However, this mechanism can be used in multi-threaded applications which do not use the BIOS
LCK mechanism.
You should not define the functions _lock() and _unlock() functions directly; instead, the installation functions are called to instruct the run-time-support environment to use these new primitives: void _register_lock (void ( *lock)()); void _register_unlock(void (*unlock)());
The arguments to _register_lock() and _register_unlock() should be functions which take no arguments and return no values, and which implement some sort of global semaphore locking: extern volatile sig_atomic_t *sema = SHARED_SEMAPHORE_LOCATION; static int sema_depth = 0; static void my_lock(void)
{ while (ATOMIC_TEST_AND_SET(sema, MY_UNIQUE_ID) != MY_UNIQUE_ID); sema_depth++;
} static void my_unlock(void)
{ if (!--sema_depth) ATOMIC_CLEAR(sema);
}
The run-time-support nests calls to _lock(), so the primitives must keep track of the nesting level.
SLAU132D – June 2009
Submit Documentation Feedback
Using Run-Time-Support Functions and Building Libraries
127
Library-Build Process
www.ti.com
7.5
Library-Build Process
When using the C/C++ compiler, you can compile your code under a number of different configurations and options that are not necessarily compatible with one another. Because it would be cumbersome to include all possible combinations in individual run-time-support libraries, this package includes a basic run-time-support library, rts430.lib. Also included are library versions that support various MSP430 devices and versions that support C++ exception handling.
You can also build your own run-time-support libraries using the self-contained run-time-support build process, which is found in rtssrc.zip. This process is described in this chapter and the archiver described in the MSP430 Assembly Language Tools User's Guide.
7.5.1 Required Non-Texas Instruments Software
To use the self-contained run-time-support build process to rebuild a library with custom options, the following support items are required:
•
Perl version 5.6 or later available as perl
Perl is a high-level programming language designed for process, file, and text manipulation. It is:
– Generally available from http://www.perl.org/get.htm
– Available from ActiveState.com as ActivePerl for the PC
– Available as part of the Cygwin package for the PC
It must be installed and added to PATH so it is available at the command-line prompt as perl. To ensure perl is available, open a Command Prompt window and execute: perl -v
No special or additional Perl modules are required beyond the standard perl module distribution.
•
GNU-compatible command-line make tool, such as gmake
More information is available from GNU at http://www.gnu.org/software/ make. This file requires a host
C compiler to build. GNU make (gmake) is shipped as part of Code Composer Studio on Windows.
GNU make is also included in some Unix support packages for Windows, such as the MKS Toolkit,
Cygwin, and Interix. The GNU make used on Windows platforms should explicitly report This program built for Windows32 when the following is executed from the Command Prompt window: gmake -h
7.5.2 Using the Library-Build Process
Once the perl and gmake tools are available, unzip the rtssrc.zip into a new, empty directory. See the
Makefile for additional information on how to customize a library build by modifying the LIBLIST and/or the
OPT_XXX macros
Once the desired changes have been made, simply use the following syntax from the command-line while in the rtssrc.zip top level directory to rebuild the selected rtsname library.
gmake rtsname
To use custom options to rebuild a library, simply change the list of options for the appropriate base listed in
and then rebuild the library. See the tables in
for a summary of available generic and MSP430-specific options.
To build an library with a completely different set of options, define a new OPT_XXX base, choose the type of library per
, and then rebuild the library. Not all library types are supported by all targets. You may need to make changes to targets_rts_cfg.pm to ensure the proper files are included in your custom library.
128
Using Run-Time-Support Functions and Building Libraries
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
MSP430 Run-Time Library Details
7.5.3 Library Naming Conventions
The names of the MSP430 run-time support libraries have been changed to improve the clarity and uniformity of the names given the large number of libraries that now exist. Library names from prior releases will be deprecated, but still supplied for compatibility.
The classic run-time support libraries now have the following naming scheme:
rts430[x[l]][_eh].lib
rts430
x l
_eh
Indicates an MSP430 library.
Optional x indicates an MSP430X library.
Optional l after x indicates a large-data model MSP430X library.
Indicates the library has exception handling support
7.6
MSP430 Run-Time Library Details
The compiler release now contains two different run-time library packages. One set is the TI written C, and minimal C++, library. This is the run-time source package that has been included with past TI ARM compilers. The second package is the Dinkumware Unabridged Library. This includes a Standard C
Library and Standard C++ Library including a Standard Template Library. The Standard C Library includes
C95 support. It does not include C99 support. Additional details on Dinkumware libraries are available at: http://www.dinkum.com/libraries_ref.html
.
7.6.1 Library Names
The classic TI libraries continue to use the rts prefix. For example:
?.lib
>.lib
?, TI library
?, TI library
The Dinkumware libraries use a lib prefix and an .a file suffix. For example:
?.a
?.a
, Dinkumware library
, Dinkumware library
See
for details on the library naming conventions.
SLAU132D – June 2009
Submit Documentation Feedback
Using Run-Time-Support Functions and Building Libraries
129
MSP430 Run-Time Library Details
www.ti.com
7.6.2 Header Files
To support multiple library packages the include directory structure has been changed in the release package. This directory now includes two directories: rts\ Directory that contains header files for the TI written run-time library lib\ Directory that contains header files for the Dinkumware libraries
There are two ways to include the correct set of header files depending on which library you are using.
You can set the MSP_C_DIR environment variable to the specific include directory: "include\rts" or
"include\lib". You can also keep your MSP_C_DIR variable set to the top-level include directory and use the --runtime option to direct the linker to the correct sub-directory to find the header files. The option settings are:
--runtime=cpp Tells the compiler to use the Dinkumware standard C++ library.
--runtime=c95 Tells the compiler to use the Dinkumware standard C library.
--runtime=rts Tells the compiler to use the TI headers (default). The --runtime option is not needed if the TI library is used.
The source support for both libraries is included in the rtssrc.zip file. See
for details on rebuilding libraries.
130
Using Run-Time-Support Functions and Building Libraries
SLAU132D – June 2009
Submit Documentation Feedback
Chapter 8
SLAU132D – June 2009
C++ Name Demangler
The C++ compiler implements function overloading, operator overloading, and type-safe linking by encoding a function's signature in its link-level name. The process of encoding the signature into the linkname is often referred to as name mangling. When you inspect mangled names, such as in assembly files or linker output, it can be difficult to associate a mangled name with its corresponding name in the
C++ source code. The C++ name demangler is a debugging aid that translates each mangled name it detects to its original name found in the C++ source code.
These topics tell you how to invoke and use the C++ name demangler. The C++ name demangler reads in input, looking for mangled names. All unmangled text is copied to output unaltered. All mangled names are demangled before being copied to output.
Topic
..................................................................................................
Page
8.1
Invoking the C++ Name Demangler
............................................
8.2
C++ Name Demangler Options
..................................................
8.3
Sample Usage of the C++ Name Demangler
................................
SLAU132D – June 2009
Submit Documentation Feedback
C++ Name Demangler
131
Invoking the C++ Name Demangler
www.ti.com
8.1
Invoking the C++ Name Demangler
The syntax for invoking the C++ name demangler is:
dem430 [options ] [filenames]
dem430
options filenames
Command that invokes the C++ name demangler.
Options affect how the name demangler behaves. Options can appear anywhere on the command line. (Options are discussed in
.)
Text input files, such as the assembly file output by the compiler, the assembler listing file, and the linker map file. If no filenames are specified on the command line, dem430 uses standard in.
By default, the C++ name demangler outputs to standard out. You can use the -o file option if you want to output to a file.
8.2
C++ Name Demangler Options
The following options apply only to the C++ name demangler:
-h
-o file
-u
-v
Prints a help screen that provides an online summary of the C++ name demangler options
Outputs to the given file rather than to standard out
Specifies that external names do not have a C++ prefix
Enables verbose mode (outputs a banner)
132
C++ Name Demangler
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Sample Usage of the C++ Name Demangler
8.3
Sample Usage of the C++ Name Demangler
The examples in this section illustrate the demangling process.
shows a sample C++ program.
shows the resulting assembly that is output by the compiler. In this example, the linknames of all the functions are mangled; that is, their signature information is encoded into their names.
Example 8-1. C++ Code for calories_in_a_banana
class banana { public: int calories(void); banana();
~banana();
}; int calories_in_a_banana(void)
{ banana x; return x.calories();
}
Example 8-2. Resulting Assembly for calories_in_a_banana
calories_in_a_banana__Fv:
;* ----------------------------------------------------------------------------*
SUB.W
#4,SP
MOV.W
ADD.W
CALL
SP,r12
#2,r12
#__ct__6bananaFv
; |10|
; |10|
; |10|
; |10|
MOV.W
ADD.W
CALL
MOV.W
MOV.W
ADD.W
MOV.W
CALL
MOV.W
ADD.W
RET
SP,r12
#2,r12
; |11|
; |11|
#calories__6bananaFv ; |11|
; |11| r12,0(SP)
SP,r12
#2,r12
#2,r13
#__dt__6bananaFv
; |11|
; |11|
; |11|
; |11|
0(SP),r12
#4,SP
; |11|
; |11|
; |11|
Executing the C++ name demangler demangles all names that it believes to be mangled. Enter: dem430 calories_in_a_banana.asm
The result is shown in
. The linknames in
___ct__6bananaFv,
_calories__6bananaFv, and ___dt__6bananaFv are demangled.
SLAU132D – June 2009
Submit Documentation Feedback
C++ Name Demangler
133
Sample Usage of the C++ Name Demangler
Example 8-3. Result After Running the C++ Name Demangler
calories_in_a_banana():
;* ----------------------------------------------------------------------------*
SUB.W
MOV.W
#4,SP
SP,r12 ; |10|
ADD.W
CALL
MOV.W
ADD.W
CALL
#2,r12
#banana::banana()
; |10|
; |10|
; |10|
; |11| SP,r12
#2,r12 ; |11|
#banana::calories() ; |11|
MOV.W
MOV.W
ADD.W
MOV.W
CALL
MOV.W
ADD.W
RET r12,0(SP)
SP,r12
#2,r12
#2,r13
#banana::~banana()
0(SP),r12
#4,SP
; |11|
; |11|
; |11|
; |11|
; |11|
; |11|
; |11|
; |11| www.ti.com
134
C++ Name Demangler
SLAU132D – June 2009
Submit Documentation Feedback
Appendix A
SLAU132D – June 2009
Glossary
absolute lister— A debugging tool that allows you to create assembler listings that contain absolute addresses.
assignment statement— A statement that initializes a variable with a value.
autoinitialization— The process of initializing global C variables (contained in the .cinit section) before program execution begins.
autoinitialization at run time— An autoinitialization method used by the linker when linking C code. The linker uses this method when you invoke it with the --rom_model link option. The linker loads the
.cinit section of data tables into memory, and variables are initialized at run time.
alias disambiguation— A technique that determines when two pointer expressions cannot point to the same location, allowing the compiler to freely optimize such expressions.
aliasing— The ability for a single object to be accessed in more than one way, such as when two pointers point to a single object. It can disrupt optimization, because any indirect reference could refer to any other object.
allocation— A process in which the linker calculates the final memory addresses of output sections.
ANSI— American National Standards Institute; an organization that establishes standards voluntarily followed by industries.
archive library— A collection of individual files grouped into a single file by the archiver.
archiver— A software program that collects several individual files into a single file called an archive library. With the archiver, you can add, delete, extract, or replace members of the archive library.
assembler— A software program that creates a machine-language program from a source file that contains assembly language instructions, directives, and macro definitions. The assembler substitutes absolute operation codes for symbolic operation codes and absolute or relocatable addresses for symbolic addresses.
assignment statement— A statement that initializes a variable with a value.
autoinitialization— The process of initializing global C variables (contained in the .cinit section) before program execution begins.
autoinitialization at run time— An autoinitialization method used by the linker when linking C code. The linker uses this method when you invoke it with the --rom_model link option. The linker loads the
.cinit section of data tables into memory, and variables are initialized at run time.
big endian— An addressing protocol in which bytes are numbered from left to right within a word. More significant bytes in a word have lower numbered addresses. Endian ordering is hardware-specific and is determined at reset. See also little endian
BIS— Bit instruction set.
block— A set of statements that are grouped together within braces and treated as an entity.
.bss section— One of the default object file sections. You use the assembler .bss directive to reserve a specified amount of space in the memory map that you can use later for storing data. The .bss
section is uninitialized.
SLAU132D – June 2009
Submit Documentation Feedback
Glossary
135
Appendix A
byte— Per ANSI/ISO C, the smallest addressable unit that can hold a character.
www.ti.com
C/C++ compiler— A software program that translates C source statements into assembly language source statements.
code generator— A compiler tool that takes the file produced by the parser or the optimizer and produces an assembly language source file.
COFF— Common object file format; a system of object files configured according to a standard developed by AT&T. These files are relocatable in memory space.
command file— A file that contains options, filenames, directives, or commands for the linker or hex conversion utility.
comment— A source statement (or portion of a source statement) that documents or improves readability of a source file. Comments are not compiled, assembled, or linked; they have no effect on the object file.
compiler program— A utility that lets you compile, assemble, and optionally link in one step. The compiler runs one or more source modules through the compiler (including the parser, optimizer, and code generator), the assembler, and the linker.
configured memory— Memory that the linker has specified for allocation.
constant— A type whose value cannot change.
cross-reference listing— An output file created by the assembler that lists the symbols that were defined, what line they were defined on, which lines referenced them, and their final values.
.data section— One of the default object file sections. The .data section is an initialized section that contains initialized data. You can use the .data directive to assemble code into the .data section.
direct call— A function call where one function calls another using the function's name.
directives— Special-purpose commands that control the actions and functions of a software tool (as opposed to assembly language instructions, which control the actions of a device).
disambiguation— See alias disambiguation
dynamic memory allocation— A technique used by several functions (such as malloc, calloc, and realloc) to dynamically allocate memory for variables at run time. This is accomplished by defining a large memory pool (heap) and using the functions to allocate memory from the heap.
ELF— Executable and linking format; a system of object files configured according to the System V
Application Binary Interface specification.
emulator— A hardware development system that duplicates the MSP430 operation.
entry point— A point in target memory where execution starts.
environment variable— A system symbol that you define and assign to a string. Environmental variables are often included in Windows batch files or UNIX shell scripts such as .cshrc or .profile.
epilog— The portion of code in a function that restores the stack and returns.
executable module— A linked object file that can be executed in a target system.
expression— A constant, a symbol, or a series of constants and symbols separated by arithmetic operators.
external symbol— A symbol that is used in the current program module but defined or declared in a different program module.
file-level optimization— A level of optimization where the compiler uses the information that it has about the entire file to optimize your code (as opposed to program-level optimization, where the compiler uses information that it has about the entire program to optimize your code).
136
Glossary
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Appendix A
function inlining— The process of inserting code for a function at the point of call. This saves the overhead of a function call and allows the optimizer to optimize the function in the context of the surrounding code.
global symbol— A symbol that is either defined in the current module and accessed in another, or accessed in the current module but defined in another.
high-level language debugging— The ability of a compiler to retain symbolic and high-level language information (such as type and function definitions) so that a debugging tool can use this information.
indirect call— A function call where one function calls another function by giving the address of the called function.
initialization at load time— An autoinitialization method used by the linker when linking C/C++ code. The linker uses this method when you invoke it with the --ram_model link option. This method initializes variables at load time instead of run time.
initialized section— A section from an object file that will be linked into an executable module.
input section— A section from an object file that will be linked into an executable module.
integrated preprocessor— A C/C++ preprocessor that is merged with the parser, allowing for faster compilation. Stand-alone preprocessing or preprocessed listing is also available.
interlist feature— A feature that inserts as comments your original C/C++ source statements into the assembly language output from the assembler. The C/C++ statements are inserted next to the equivalent assembly instructions.
intrinsics— Operators that are used like functions and produce assembly language code that would otherwise be inexpressible in C, or would take greater time and effort to code.
ISO— International Organization for Standardization; a worldwide federation of national standards bodies, which establishes international standards voluntarily followed by industries.
K&R C— Kernighan and Ritchie C, the de facto standard as defined in the first edition of The C
Programming Language (K&R). Most K&R C programs written for earlier, non-ISO C compilers should correctly compile and run without modification.
label— A symbol that begins in column 1 of an assembler source statement and corresponds to the address of that statement. A label is the only assembler statement that can begin in column 1.
linker— A software program that combines object files to form an object module that can be allocated into system memory and executed by the device.
listing file— An output file, created by the assembler, that lists source statements, their line numbers, and their effects on the section program counter (SPC).
little endian— An addressing protocol in which bytes are numbered from right to left within a word. More significant bytes in a word have higher numbered addresses. Endian ordering is hardware-specific and is determined at reset. See also big endian
loader— A device that places an executable module into system memory.
loop unrolling— An optimization that expands small loops so that each iteration of the loop appears in your code. Although loop unrolling increases code size, it can improve the performance of your code.
macro— A user-defined routine that can be used as an instruction.
macro call— The process of invoking a macro.
macro definition— A block of source statements that define the name and the code that make up a macro.
SLAU132D – June 2009
Submit Documentation Feedback
Glossary
137
Appendix A
www.ti.com
macro expansion— The process of inserting source statements into your code in place of a macro call.
map file— An output file, created by the linker, that shows the memory configuration, section composition, section allocation, symbol definitions and the addresses at which the symbols were defined for your program.
memory map— A map of target system memory space that is partitioned into functional blocks.
name mangling— A compiler-specific feature that encodes a function name with information regarding the function's arguments return types.
object file— An assembled or linked file that contains machine-language object code.
object library— An archive library made up of individual object files.
object module— A linked, executable object file that can be downloaded and executed on a target system.
operand— An argument of an assembly language instruction, assembler directive, or macro directive that supplies information to the operation performed by the instruction or directive.
optimizer— A software tool that improves the execution speed and reduces the size of C programs.
options— Command-line parameters that allow you to request additional or specific functions when you invoke a software tool.
output module— A linked, executable object file that is downloaded and executed on a target system.
output section— A final, allocated section in a linked, executable module.
parser— A software tool that reads the source file, performs preprocessing functions, checks the syntax, and produces an intermediate file used as input for the optimizer or code generator.
partitioning— The process of assigning a data path to each instruction.
pipelining— A technique where a second instruction begins executing before the first instruction has been completed. You can have several instructions in the pipeline, each at a different processing stage.
pop— An operation that retrieves a data object from a stack.
pragma— A preprocessor directive that provides directions to the compiler about how to treat a particular statement.
preprocessor— A software tool that interprets macro definitions, expands macros, interprets header files, interprets conditional compilation, and acts upon preprocessor directives.
program-level optimization— An aggressive level of optimization where all of the source files are compiled into one intermediate file. Because the compiler can see the entire program, several optimizations are performed with program-level optimization that are rarely applied during file-level optimization.
prolog— The portion of code in a function that sets up the stack.
push— An operation that places a data object on a stack for temporary storage.
quiet run— An option that suppresses the normal banner and the progress information.
raw data— Executable code or initialized data in an output section.
relocation— A process in which the linker adjusts all the references to a symbol when the symbol's address changes.
run-time environment— The run time parameters in which your program must function. These parameters are defined by the memory and register conventions, stack organization, function call conventions, and system initialization.
138
Glossary
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
Appendix A
run-time-support functions— Standard ISO functions that perform tasks that are not part of the C language (such as memory allocation, string conversion, and string searches).
run-time-support library— A library file, rts.src, that contains the source for the run time-support functions.
section— A relocatable block of code or data that ultimately will be contiguous with other sections in the memory map.
sign extend— A process that fills the unused MSBs of a value with the value's sign bit.
simulator— A software development system that simulates MSP430 operation.
source file— A file that contains C/C++ code or assembly language code that is compiled or assembled to form an object file.
stand-alone preprocessor— A software tool that expands macros, #include files, and conditional compilation as an independent program. It also performs integrated preprocessing, which includes parsing of instructions.
static variable— A variable whose scope is confined to a function or a program. The values of static variables are not discarded when the function or program is exited; their previous value is resumed when the function or program is reentered.
storage class— An entry in the symbol table that indicates how to access a symbol.
string table— A table that stores symbol names that are longer than eight characters (symbol names of eight characters or longer cannot be stored in the symbol table; instead they are stored in the string table). The name portion of the symbol's entry points to the location of the string in the string table.
structure— A collection of one or more variables grouped together under a single name.
subsection— A relocatable block of code or data that ultimately will occupy continuous space in the memory map. Subsections are smaller sections within larger sections. Subsections give you tighter control of the memory map.
symbol— A string of alphanumeric characters that represents an address or a value.
symbolic debugging— The ability of a software tool to retain symbolic information that can be used by a debugging tool such as a simulator or an emulator.
target system— The system on which the object code you have developed is executed.
.text section— One of the default object file sections. The .text section is initialized and contains executable code. You can use the .text directive to assemble code into the .text section.
trigraph sequence— A 3-character sequence that has a meaning (as defined by the ISO 646-1983
Invariant Code Set). These characters cannot be represented in the C character set and are expanded to one character. For example, the trigraph ??' is expanded to ^.
unconfigured memory— Memory that is not defined as part of the memory map and cannot be loaded with code or data.
uninitialized section— A object file section that reserves space in the memory map but that has no actual contents. These sections are built with the .bss and .usect directives.
unsigned value— A value that is treated as a nonnegative number, regardless of its actual sign.
variable— A symbol representing a quantity that can assume any of a set of values.
veneer— A sequence of instructions that serves as an alternate entry point into a routine if a state change is required.
word— A 16-bit addressable location in target memory
SLAU132D – June 2009
Submit Documentation Feedback
Glossary
139
Index
430cio.h header described
__COMPILER_VERSION__ macro
__LARGE_CODE_MODEL__ macro
__LARGE_DATA_MODEL__ macro
__MSP430__ macro
__MSP430X461X__ macro
__register_lock() function
__register_unlock() function
__signed_chars__ macro
__STACK_SIZE using
__unsigned_chars__ macro
_c_int00 described
_f_DATE_f_ macro
_f_FILE_f_ macro
_f_LINE_f_ macro
_f_STDC_f_ macro
_f_TIME_f_ macro
_INLINE macro
_never_executed intrinsic
_SYSMEM_SIZE
A
-aa alias for --absolute_listing assembler option
-a alias for --absolute_exe linker option
--abs_directory compiler option
-abs alias for --run_abs linker option
.abs extension
abs function
--absolute_exe linker option
--absolute_listing assembler option
absolute lister defined
described
absolute listing creating
-ac alias for --syms_ignore_case assembler option
-ad alias for --asm_define assembler option
add_device function
-ahc alias for --copy_file assembler option
-ahi alias for --include_file assembler option
-al alias for --asm_listing assembler option
alias disambiguation defined
described
140
--aliased_variables compiler option
aliased variables
-@ alias for --cmd_file compiler option
aliasing
defined
allocate memory sections
allocation defined
alt.h pathname
ANSI
C
changing the language mode
compatibility with K&R C
ANSI/ISO
MSP430 differences from
from standard C++
-apd alias for --asm_dependency assembler option
-api alias for --asm_includes assembler option
archive library defined
linking
archiver defined
described
--arg_size linker option
-args alias for --arg_size linker option
.args section allocating in memory
arguments accessing
-ar linker option
-as alias for --output_all_syms assembler option
--asm_define assembler option
--asm_dependency assembler option
--asm_directory compiler option
--asm_extension compiler option
--asm_file compiler option
--asm_includes assembler option
--asm_listing assembler option
--asm_undefine assembler option
.asm extension
asm statement described
in optimized code
using
assembler
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
controlling with compiler
defined
described
options summary
assembly language accessing
constants
global variables
variables
code interfacing
embedding
including
interlisting with C/C++ code
interrupt routines
module interfacing
retaining output
assembly listing file creation
assembly source debugging
assignment statement defined
-au alias for --asm_undefine assembler option
--auto_inline compiler option
autoinitialization at run time
defined
described
defined
initialization tables
of variables
types of
-ax alias for --cross_reference assembler option
B
-b alias for --no_sym_merge linker option
banner suppressing
big endian defined
BIS defined
bit fields size and type
block defined
memory allocation
branch optimizations
.bss section allocating in memory
defined
described
byte defined
C
--c_extension compiler option
--c_file compiler option
c_int00 symbol
SLAU132D – June 2009
Submit Documentation Feedback
Appendix A
C_OPTION
--c_src_interlist compiler option
--c_src_interlist option compiler
-c alias for --compile_only compiler option
-c alias for --rom_model linker option
--call_assumptions compiler option
calling conventions accessing arguments and local variables
how a called function responds
how a function makes a call
calloc function dynamic memory allocation
C/C++ compiler defined
described
C/C++ language accessing assembler constants
accessing assembler global variables
accessing assembler variables
const keyword
global constructors and destructors
interlisting with assembly
interrupt keyword
placing assembler statements in
pragma directives
restrict keyword
volatile keyword
.c extension
character escape sequences in
string constants
.cinit section allocating in memory
assembly module use of
described
C I/O library
cl6x command
cl430 invoking
cl430 --run_linker command
C language interrupt routines
C++ language characteristics
close I/O function
--cmd_fle compiler option
C++ name demangler described
example
invoking
options
CODE_SECTION pragma
code generator defined
COFF defined
Index
141
Appendix A
command file appending to command line
defined
linker
comments defined
common object file format defined
compatibility with K&R C
--compile_only compiler option
compiler defined
diagnostic messages
diagnostic options
frequently used options
invoking
optimizer
options
assembler
compiler
conventions
deprecated
diagnostics
input file extension
input files
linker
optimizer
output files
parser
profiling
summary
symbolic debugging
overview
preprocessor options
sections
setting default options with MSP430_C_OPTION
compiling C/C++ code after preprocessing
compile only
overview, commands, and options
with the optimizer
--compress_dwarf linker option
configured memory defined
constant accessing assembler constants from C/C++
character strings
defined
escape sequences in character constants
string
const keyword
.const section allocating in memory
described
control-flow simplification
142
Index
www.ti.com
controlling diagnostic messages
conventions function calls
register
--copy_file assembler option
copy file using -ahc assembler option
cost-based register allocation optimization
--cpp_default compiler option
--cpp_extension compiler option
--cpp_file compiler option
-cr alias for --ram_model linker option
--create_pch compiler option
--cross_reference assembler option
cross-reference lister described
cross-reference listing defined
generating with assembler
generating with compiler shell
D
-D alias for --define compiler option
DATA_ALIGN pragma
DATA_SECTION pragma
data flow optimizations
data object representation
.data section
defined
data types how stored in memory
list of
storage
pointer to member function
debugging optimized code
--define compiler option
--define linker option
dem430
deprecated compiler options
development flow diagram
device adding
functions
--diag_error compiler option
--diag_error linker option
--diag_remark compiler option
--diag_remark linker option
--diag_suppress compiler option
--diag_suppress linker option
--diag_warning compiler option
--diag_warning linker option
diagnostic identifiers in raw listing file
diagnostic messages controlling
description
errors
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
fatal errors
format
generating
other messages
remarks
suppressing
warnings
Dinkumware unabridged library
direct call defined
directives defined
directories alternate for include files
for include files
naming alternates with environment variables
specifying
disable automatic inline expansion
automatic selection of run-time-support library
conditional linking
linking
merge of symbolic debugging information
optimization information file
symbolic debugging
--disable_auto_rts linker option
--disable_clink linker option
--disable_pp linker option
--display_error_number compiler option
--display_error_number linker option
display compiler syntax and options
--help compiler option
display progress and toolset data
--verbose compiler option
DWARF debug format
dynamic memory allocation defined
described
E
-ea alias for --asm_extension compiler option
-e alias for --entry_point linker option
-ec alias for --c_extension compiler option
.econst section allocating in memory
ELF defined
--embedded_cpp compiler option
embedded C++ mode
emulator defined
--entry_hook compiler option
--entry_param compiler option
--entry_point linker option
entry hooks
--entry_hook option
SLAU132D – June 2009
Submit Documentation Feedback
Appendix A
entry hooks parameters
--entry_param option
entry point defined
environment variable defined
MSP430_C_DIR
MSP430_C_OPTION
-eo alias for --obj_extension compiler option
-ep alias for --cpp_extension compiler option
epilog defined
EPROM programmer
error messages
handling with options
preprocessor
-es alias for --listing_extension compiler option
escape sequences
establishing standard macro definitions
exception handling
--exceptions compiler option
--exceptions compiler option
executable and linking format defined
executable module defined
--exit_hook compiler option
--exit_param compiler option
exit hooks
--exit_hook option
exit hooks parameters
--exit_param option
expression defined
simplification
extensions abs
asm
c
cc
cpp
cxx
nfo
obj
s
sa
specifying
external declarations
external symbol defined
F
-fa alias for --asm_file compiler option
fabs function
-f alias for --fill_value linker option
Index
143
Appendix A
fatal error
-fb alias for --abs_directory compiler option
-fc alias for --c_file compiler option
-ff alias for --list_directory compiler option
-fg alias for --cpp_default compiler option
file copy
include
file-level optimization
defined
filename extension specification
specifying
files.h header described
--fill_value linker option
-fo alias for --obj_file compiler option
format.h header described
--fp_mode compiler option
--fp_reassoc compiler option
-fp alias for --cpp_file compiler option
-fr alias for --obj_directory compiler option
-fs alias for --asm_directory compiler option
-ft alias for --temp_directory compiler option
FUNC_CANNOT_INLINE pragma
FUNC_EXT_CALLED pragma described
use with --program_level_compile option
FUNC_IS_PURE pragma
FUNC_NEVER_RETURNS pragma
FUNC_NO_GLOBAL_ASG pragma
FUNC_NO_IND_ASG pragma
function call
conventions
using the stack
inline expansion
inlining defined
prototype
effects of --kr_compatible option
responsibilities of called function
responsibilities of calling function
structure
subsections
G
-g alias for --make_global linker option
GCC extensions to C built-in functions
function attributes
list supported by TI
-g compiler option
--gen_acp_raw compiler option
--gen_acp_xref compiler option
--gen_func_subsections compiler option
144
Index
www.ti.com
--gen_opt_info compiler option
--generate_dead_funcs_list linker option
generating linknames
list of #include files
list of predefined and user-defined macros
symbolic debugging directives
global constructors and destructors
--globalize linker option
global symbol defined
global variables accessing assembler variables from C/C++
autoinitialization
initializing
reserved space
GNU compiler extensions
H
-h alias for --help compiler option
-h alias for --make_static linker option
handling reentrancy
--register_lock() and __register_unlock()
-h C++ name demangler option
header files
430cio.h header
files.h header
format.h header
rtti.h header
values.h header
vtbl.h header
heap described
reserved space
--heap_size linker option
-heap alias for --heap_size linker option
-help alias for --linker_help linker option
--help compiler option
hex conversion utility described
--hide linker option
high-level language debugging defined
I
-I alias for --include_path compiler option
-i alias for --search_path linker option
-
I compiler option
#include files
adding a directory to be searched
specifying a search path
preprocessor directive
generating list of files included
--include_file assembler option
--include_path compiler option
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
include files using --include_file assembler option
indirect call defined
initialization at load time
defined
described
of variables
at load time
at run time
types
initialization tables
initialized sections allocating in memory
defined
described
initializing static and global variables
with const type qualifier
with the linker
inline assembly language
automatic expansion
definition-controlled function expansion
function expansion
intrinsic operators
keyword and alternate keyword __inline
input file changing default extensions
changing interpretation of filenames
default extensions
extensions
summary of options
summary of options
input section defined
integrated preprocessor defined
interfacing C and assembly
interlist utility
C/C++ source with generated assembly
defined
described
invoking with compiler
optimizer comments or C/C++ source with assembly
used with the optimizer
interrupt handling
described
saving registers
routines
assembly language
C/C++ language
interrupt keyword
INTERRUPT pragma
intrinsics
SLAU132D – June 2009
Submit Documentation Feedback
defined
inlining operators
invoking
C++ name demangler
compiler
linker
through compiler
invoking the library-build process
I/O adding a device
functions
close
lseek
open
read
rename
unlink
write
implementation overview
library
ISO defined
standards overview
--issue_remarks compiler option
--issue_remarks linker option
J
-j alias for --disable_clink linker option
K
-k alias for --keep_asm compiler option
K&R C compatibility with ANSI C
defined
--keep_asm compiler option
--keep_unneeded_statics compiler option
keyword const
interrupt
restrict
volatile
--kr_compatible compiler option
L
label case sensitivity
--syms_ignore_case compiler option
defined
retaining
labs function
-l alias for --library linker option
--large_memory_model compiler option
libraries run-time support
library
Appendix A
Index
145
Appendix A
building
modifying a function
library-build process
described
non-TI software
using
-library linker option
linker command file
controlling
defined
described
disabling
invoking
invoking through the compiler
as part of the compile step
as separate step
options
summary of options
suppressing
--linker_help linker option
linking
C/C++ code
object library
run-time-support libraries
automatic selection
with run-time-support libraries
linknames and interrupts
linknames generated by the compiler
-list_directory compiler option
--listing_extension compiler option
listing file creating cross-reference
defined
generating with preprocessor
little endian defined
loader defined
using with linker
--localize linker option
local variables accessing
loop-invariant optimizations
loop rotation optimization
loops optimization
loop unrolling defined
lseek I/O function
M
-ma alias for --aliased_variables compiler option
macro defined
146
Index
www.ti.com
expansions
macro call defined
macro definition defined
macro expansion defined
predefined names
--make_global linker option
--make_static linker option
-m alias for --map_file linker option
malloc function dynamic memory allocation
--map_file linker option
map file defined
--mapfile_contents linker option
-mc alias for --plain_char compiler option
-mc compiler option
memory map defined
memory model described
dynamic memory allocation
sections
stack
variable initialization
memory pool reserved space
-ml alias for --large_memory_model compiler option
MSP430_C_DIR
MSP430_C_DIR environment variable
MSP430_C_OPTION
N
-n alias for --skip_assembler compiler option
name demangler described
name mangling defined
.nfo extension
--no_demangle linker option
--no_inlining compiler option
--no_sym_merge linker option
--no_sym_table option linker
--no_warnings compiler option
--no_warnings linker option
nonstandard header files in run-time-support libraries
O
-O3 alias for --opt_level=3 compiler option
-O alias for --opt_level compiler option
-o alias for --output_file linker option
--obj_directory compiler option
--obj_extension compiler option
--obj_file compiler option
object file defined
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
object library defined
linking code with
object module defined
.obj extension
-o C++ name demangler option
-oi alias for --auto_inline compiler option
-ol0 alias for --std_lib_func_redefined compiler option
-ol1 alias for --std_lib_func_defined compiler option
-ol2 alias for --std_lib_func_not_defined compiler option
-on alias for --gen_opt_info compiler option
-op alias for --call_assumptions compiler option
open I/O function
operand defined
--opt_level=3 compiler option
--opt_level compiler option
optimization accessing aliased variables
optimizations alias disambiguation
branch
considerations when mixing C/C++ and assembly
control-flow simplification
controlling the level of
cost based register allocation
data flow
expression simplification
file-level
defined
described
induction variables
information file options
inline expansion
levels
list of
loop-invariant code motion
loop rotation
MSP430-specific
integer division with constant divisor
tail merging
program-level
defined
described
-specific
Never_Executed intrinsic
strength reduction
optimized code debugging
profiling
optimizer defined
described
invoking with compiler options
SLAU132D – June 2009
Submit Documentation Feedback
Appendix A
performing file-level optimization
summary of options
--optimizer_interlist compiler option
options aliases
compiler
linker
assembler
C++ name demangler
compiler summary
controlling hooks
conventions
defined
diagnostics
linker
preprocessor
-os alias for --optimizer_interlist compiler option
output file options summary
module
defined
overview of files
section
defined
--output_all_syms assembler option
-output_file linker option
overflow run-time stack
P
parameters compiling register parameters
parser defined
summary of options
partitioning defined
--pch_dir compiler option
--pch_verbose compiler option
--pch compiler option
-pdel alias for --set_error_limit compiler option
-pden alias for --diag_error_number compiler option
-pdf alias for --write_diagnostics_file compiler option
-pdr alias for --issue_remarks compiler option
-pds alias for --diag_suppress compiler option
-pdse alias for --diag_error compiler option
-pdsr alias for --diag_remark compiler option
-pdsw alias for --diag_warning compiler option
-pdv alias for --verbose_diagnostics compiler option
-pdw alias for --no_warnings compiler option
-pe alias for --embedded_cpp compiler option
performing file-level optimization
-pi alias for --no_inlining compiler option
.pinit section allocating in memory
described
Index
147
Appendix A
pinit symbol
pipelining defined
-pk alias for --kr_compatible compiler option
-pl alias for --gen_acp_raw compiler option
-pm alias for --program_level_compile compiler option
pointer combinations
pop defined
-ppa alias for --preproc_with_compile compiler option
-ppc alias for --preproc_with_comments compiler option
-ppd alias for --preproc_dependency compiler option
-ppi alias for --preproc_includes compiler option
-ppl alias for --preproc_with_line compiler option
-ppm alias for --preproc_macros compiler option
-ppo alias for --preproc_only compiler option
pragma defined
pragma directives
CODE_SECTION
DATA_ALIGN
DATA_SECTION
FUNC_CANNOT_INLINE
FUNC_EXT_CALLED
FUNC_IS_PURE
FUNC_NEVER_RETURNS
FUNC_NO_GLOBAL_ASG
FUNC_NO_IND_ASG
INTERRUPT
vector
-pr alias for --relaxed_ansi compiler option
precompiled header support
automatic
manual
predefining a constant
--preinclude compiler option
preinitialized variables global and static
--preproc_dependency compiler option
--preproc_includes compiler option
--preproc_macros compiler option
--preproc_only compiler option
--preproc_with_comments compiler option
--preproc_with_compile compiler option
--preproc_with_line compiler option
preprocessed listing file assembly dependency lines
assembly include files
generating raw information
generating with comments
generating with #line directives
preprocessor controlling
defined
148
Index
error messages
options
predefining constant names for option
symbols
--printf_support compiler option
printing tool version numbers
--tool_version compiler option
-priority alias for --priority linker option
--priority linker option
--profile:breakpt compiler option
--profile:power compiler option
--program_level_compile compiler option
program-level optimization controlling
defined
performing
progress information suppressing
prolog defined
-ps alias for --strict_ansi compiler option
push defined
-px alias for --gen_acp_xref compiler option
Q
-q alias for --quiet compiler option
--quiet compiler option
quiet run defined
R
-r alias for --relocatable linker option
--ram_model linker option
--ram_model link option system initialization
raw data defined
raw listing file generating with -pl option
identifiers
read I/O function
realloc function
reassociation of floating-point arithmetic
--fp_reassoc option
reassociation of saturating arithmetic
--sat_reassoc option
register parameters compiling
registers allocation
conventions
saving during interrupts
register variables compiling
--relaxed_ansi compiler option
relaxed ANSI/ISO mode
relaxed ANSI mode
www.ti.com
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
relaxed floating-point mode
--fp_mode option
--relocatable linker option
relocation defined
remarks
--remove_hooks_when_inlining compiler option
rename I/O function
--reread_libs linker option
restrict keyword
--rom_model linker option
--rom_model link option system initialization
rtscpp.src
rtsc.src
rtti.h header described
--run_abs linker option
--run_linker compiler option
overriding with --rom_model compiler option
run-time environment defined
function call conventions
interfacing C with assembly language
interrupt handling
described
saving registers
introduction
memory model
during autoinitialization
dynamic memory allocation
sections
register conventions
stack
system initialization
run-time initialization of variables
--runtime linker option
run-time-support functions
defined
introduction
libraries
described
functionality summarized
library-build process
linking C code
nonstandard header files
library
defined
described
S
.sa extension
-s alias for --no_sym_table linker option
-s alias for --src_interlist compiler option
SLAU132D – June 2009
Submit Documentation Feedback
Appendix A
--sat_reassoc compiler option
saving registers during interrupts
saving registers during interrupts
--scan_libraries linker option
--search_path linker option
section allocating memory
.bss
.cinit
.const
created by the compiler
.data
defined
described
initialized
.pinit
.stack
.sysmem
.text
uninitialized
--set_error_limit compiler option
--set_error_limit linker option
.s extension
sign extend defined
--silicon_version compiler option
simulator defined
--skip_assembler compiler option
--small_enum compiler option
software development tools overview
source file defined
extensions
--src_interlist compiler option
-ss alias for --c_src_interlist compiler option
STABS debugging format
stack changing the size
overflow
run-time stack
pointer
reserved space
--stack_size linker option
--stack_size link option
-stack alias for --stack_size linker option
.stack section allocating in memory
described
stand-alone preprocessor defined
static variable defined
initializing
--std_lib_func_defined compiler option
Index
149
Appendix A
--std_lib_func_not_defined compiler option
--std_lib_func_redefined compiler option
storage class defined
strength reduction optimization
--strict_ansi compiler option
--strict_compatibility linker option
strict ANSI/ISO mode
strict ANSI mode
string constants
string table defined
structure defined
STYP_COPY flag
subsection defined
suppressing diagnostic messages
symbol defined
--symbol_map linker option
symbolic cross-reference in listing file
symbolic debugging defined
disabling
minimal (default)
rapid type merging
using DWARF format
using STABS format
symbols case sensitivity
symbol table creating labels
--symdebug:coff compiler option
--symdebug:dwarf_subsections compiler option
--symdebug:dwarf compiler option
--symdebug:none compiler option
--symdebug:profile_coff compiler option
--symdebug:skeletal compiler option
--syms_ignore_case assembler option
.sysmem section allocating in memory
described
system constraints
_SYSMEM_SIZE
system initialization described
initialization tables
stack
system stack
T
target system defined
-temp_directory compiler option
.text section allocating in memory
150
Index
www.ti.com
defined
described
--tool_version compiler option
trigraph sequence defined
U
-u alias for --undef_sym linker option
-U alias for --undefine compiler option
-u C++ name demangler option
unconfigured memory defined
--undef_sym linker option
--undefine compiler option
--undefine linker option
undefining a constant
--unhide linker option
uninitialized sections allocating in memory
defined
list
unlink I/O function
unsigned defined
--use_pch compiler option
using smallest byte size for enum type
--small_enum compiler option
utilities overview
V
-v alias for --silicon_version compiler option
-v alias for --verbose compiler option
values.h header file
variables accessing assembler variables from C/C++
accessing local variables
autoinitialization
compiling register variables
defined
initializing
global
static
-v C++ name demangler option
vector pragma
veneer defined
--verbose_diagnostics compiler option
--verbose_diagnostics linker option
--verbose compiler option
-version alias for --tool_version compiler option
volatile keyword
vtbl.h header described
W
SLAU132D – June 2009
Submit Documentation Feedback
www.ti.com
-w alias for --warn_sections linker option
--warn_sections linker option
warning messages
wildcards use
compiler
word defined
--write_diagnostics_file compiler option
write I/O function
X
>> symbol
-x alias for --reread_libs linker option
-- xml_link_info linker option
Z
-z alias for --run_linker compiler option
Appendix A
SLAU132D – June 2009
Submit Documentation Feedback
Index
151
IMPORTANT NOTICE
Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, modifications, enhancements, improvements, and other changes to its products and services at any time and to discontinue any product or service without notice. Customers should obtain the latest relevant information before placing orders and should verify that such information is current and complete. All products are sold subject to TI’s terms and conditions of sale supplied at the time of order acknowledgment.
TI warrants performance of its hardware products to the specifications applicable at the time of sale in accordance with TI’s standard warranty. Testing and other quality control techniques are used to the extent TI deems necessary to support this warranty. Except where mandated by government requirements, testing of all parameters of each product is not necessarily performed.
TI assumes no liability for applications assistance or customer product design. Customers are responsible for their products and applications using TI components. To minimize the risks associated with customer products and applications, customers should provide adequate design and operating safeguards.
TI does not warrant or represent that any license, either express or implied, is granted under any TI patent right, copyright, mask work right, or other TI intellectual property right relating to any combination, machine, or process in which TI products or services are used. Information published by TI regarding third-party products or services does not constitute a license from TI to use such products or services or a warranty or endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectual property of the third party, or a license from TI under the patents or other intellectual property of TI.
Reproduction of TI information in TI data books or data sheets is permissible only if reproduction is without alteration and is accompanied by all associated warranties, conditions, limitations, and notices. Reproduction of this information with alteration is an unfair and deceptive business practice. TI is not responsible or liable for such altered documentation. Information of third parties may be subject to additional restrictions.
Resale of TI products or services with statements different from or beyond the parameters stated by TI for that product or service voids all express and any implied warranties for the associated TI product or service and is an unfair and deceptive business practice. TI is not responsible or liable for any such statements.
TI products are not authorized for use in safety-critical applications (such as life support) where a failure of the TI product would reasonably be expected to cause severe personal injury or death, unless officers of the parties have executed an agreement specifically governing such use. Buyers represent that they have all necessary expertise in the safety and regulatory ramifications of their applications, and acknowledge and agree that they are solely responsible for all legal, regulatory and safety-related requirements concerning their products and any use of TI products in such safety-critical applications, notwithstanding any applications-related information or support that may be provided by TI. Further, Buyers must fully indemnify TI and its representatives against any damages arising out of the use of TI products in such safety-critical applications.
TI products are neither designed nor intended for use in military/aerospace applications or environments unless the TI products are specifically designated by TI as military-grade or "enhanced plastic." Only products designated by TI as military-grade meet military specifications. Buyers acknowledge and agree that any such use of TI products which TI has not designated as military-grade is solely at the Buyer's risk, and that they are solely responsible for compliance with all legal and regulatory requirements in connection with such use.
TI products are neither designed nor intended for use in automotive applications or environments unless the specific TI products are designated by TI as compliant with ISO/TS 16949 requirements. Buyers acknowledge and agree that, if they use any non-designated products in automotive applications, TI will not be responsible for any failure to meet such requirements.
Following are URLs where you can obtain information on other Texas Instruments products and application solutions:
Products
Amplifiers
Data Converters
DLP® Products
DSP
Clocks and Timers
Interface
Logic
Power Mgmt
Microcontrollers
RFID amplifier.ti.com
dataconverter.ti.com
www.dlp.com
dsp.ti.com
www.ti.com/clocks interface.ti.com
logic.ti.com
power.ti.com
microcontroller.ti.com
www.ti-rfid.com
RF/IF and ZigBee® Solutions www.ti.com/lprf
Applications
Audio
Automotive
Broadband
Digital Control
Medical
Military
Optical Networking
Security
Telephony
Video & Imaging
Wireless www.ti.com/audio www.ti.com/automotive www.ti.com/broadband www.ti.com/digitalcontrol www.ti.com/medical www.ti.com/military www.ti.com/opticalnetwork www.ti.com/security www.ti.com/telephony www.ti.com/video www.ti.com/wireless
Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265
Copyright © 2009, Texas Instruments Incorporated
Letöltés
Hirdetés