RealView ® CompilationTools Developer Guide

Version 2.2

Table of Contents

About this book
Intended audience
Using this book
Typographical conventions
Further reading
Feedback on RealView Compilation Tools
Feedback on this book
1. Introduction
1.1. About RVCT
1.1.1. Using the examples
1.2. General programming issues
1.2.1. Unaligned pointers
1.2.2. Unaligned fieldsin structures
1.2.3. Unaligned LDR for accessing halfwords
1.2.4. Porting code and detecting unalignedaccesses
1.3. Developing for the ARM processors
1.3.1. Embedded software development
1.3.2. Interworking ARMand Thumb code
1.3.3. Mixing C, C++, and assembly language
1.3.4. Handling processor exceptions
1.3.5. Using the AAPCS
1.3.6. Compatibility with legacy objectsand libraries
1.4. ARM architecture v6 support
1.4.1. Instruction generation
1.4.2. Alignment support
1.4.3. Endian support
1.4.4. Example 1 - instructionsgenerated
1.4.5. Example 2 - instructions generatedfor packed structures
2. Embedded Software Development
2.1. About embedded software development
2.1.1. Example code
2.2. Default compilation tool behaviorin the absence of a target system
2.2.1. Semihosting
2.2.2. C library structure
2.2.3. Default memory map
2.2.4. Linker placement rules
2.2.5. Application startup
2.2.6. Example code for Build 1
2.3. Tailoring the C library to your targethardware
2.3.1. Retargeting the C library
2.3.2. Avoiding C library semihosting
2.3.3. Example code for Build 2
2.4. Tailoring the image memory map to yourtarget hardware
2.4.1. Scatter-loading
2.4.2. Scatter-loading descriptionfile syntax
2.4.3. Scatter-loading descriptionfile example
2.4.4. Placing objects in a scatter-loadingdescription file
2.4.5. Root regions
2.4.6. Placing the stack andheap
2.4.7. Runtime memory models
2.4.8. Example code forBuild 3
2.5. Reset and initialization
2.5.1. Initialization sequence
2.5.2. The vector table
2.5.3. ROM/RAM remapping
2.5.4. Local memory setup considerations
2.5.5. Scatter-loadingand memory setup
2.5.6. Stack pointer initialization
2.5.7. Hardware initialization
2.5.8. Execution mode considerations
2.5.9. Example code for Build 4
2.6. Further memory map considerations
2.6.1. Locating target peripherals in thescatter-loading description file
2.6.2. Placing the stack and heap in thescatter-loading description file
2.6.3. Example code for Build5
3. Writing Position Independent Code and Data
3.1. Position independence
3.1.1. Using the AAPCS
3.2. Read-only position independence
3.2.1. Register usage with ROPI
3.2.2. Writing C and assembler code for ROPI
3.2.3. Linking your code
3.2.4. FPIC addressing
3.2.5. Code example
3.3. Read-write position independence
3.3.1. Reentrant routines
3.3.2. Register usage with RWPI
3.3.3. Position-independentdata addressing
3.3.4. Writing assembly language for RWPI
3.3.5. Linking your code
3.3.6. Code example
4. Interworking ARM and Thumb
4.1. About interworking
4.1.1. Using the AAPCS
4.1.2. When to use interworking
4.1.3. Using the /interwork option
4.1.4. Detecting interworking calls
4.1.5. Linker generated veneers
4.2. Assembly language interworking
4.2.1. The branch and exchange instruction
4.2.2. Changing the assembler mode
4.2.3. Example ARM header
4.2.4. ARM architecture v5T
4.2.5. Labels in Thumb code
4.3. C and C++ interworking and veneers
4.3.1. Compiling code for interworking
4.3.2. Basic rules for C andC++ interworking
4.3.3. Pointers to functions in Thumb state
4.3.4. Using two versions of the same function
4.4. Assembly language interworking usingveneers
4.4.1. Assembly-only interworking using veneers
4.4.2. C, C++, and assembly language interworkingusing veneers
5. Mixing C, C++, and Assembly Language
5.1. Using the inline and embedded assemblers
5.1.1. Features of the inline assembler
5.1.2. Features of the embedded assembler
5.1.3. Differences between inline and embeddedassembly code
5.2. Accessing C global variables fromassembly code
5.3. Using C header files from C++
5.3.1. Including system C header files
5.3.2. Including your own C header files
5.4. Calling between C, C++, and ARM assemblylanguage
5.4.1. General rules for calling betweenlanguages
5.4.2. Information specific to C++
5.4.3. Examples of callingbetween languages
6. Handling Processor Exceptions
6.1. About processor exceptions
6.1.1. Types of exception
6.1.2. The vector table
6.1.3. Use of modes and registers by exceptions
6.1.4. Exception priorities
6.2. Determining the processor state
6.3. Entering and leaving an exception
6.3.1. The processor response to an exception
6.3.2. Returning from an exception handler
6.3.3. The return address and return instruction
6.4. Handling an exception
6.5. Installing an exception handler
6.5.1. Methods of installing exception handlers
6.5.2. Installing the handlers at reset
6.5.3. Installing the handlersfrom C
6.6. SWI handlers
6.6.1. Determining the SWI to be called
6.6.2. SWI handlers in assembly language
6.6.3. SWI handlers in C and assembly language
6.6.4. Using SWIs in Supervisormode
6.6.5. Calling SWIs from an application
6.6.6. Calling SWIs dynamically from an application
6.7. Interrupt handlers
6.7.1. Levels of external interrupt
6.7.2. Simple interrupthandlers in C
6.7.3. Reentrant interrupt handlers
6.7.4. Example interrupt handlers in assemblylanguage
6.8. Reset handlers
6.9. Undefined Instruction handlers
6.10. Prefetch Abort handler
6.11. Data Abort handler
6.12. Chaining exception handlers
6.12.1. A single extended handler
6.12.2. Several chained handlers
6.13. System mode
7. Debug Communications Channel
7.1. About the Debug Communications Channel
7.1.1. Semihosting
7.2. Target transfer of data
7.3. Polled debug communications
7.3.1. Comms data control register
7.3.2. Target to debuggercommunication
7.3.3. Debugger to target communication
7.4. Interrupt-driven debug communications
7.5. Access from Thumb state
A. Using the Procedure Call Standard
A.1. About the AAPCS
A.1.1. PCS variants
A.1.2. ARM C libraries
A.1.3. ARM assembler
A.1.4. Conformance to the AAPCS
A.2. Using AAPCS options
A.2.1. Position independence
A.2.2. Stack checking
A.2.3. Interworking
A.2.4. Floating-point

Proprietary Notice

Words and logos marked with ® or ™ are registered trademarks or trademarksowned by ARM Limited. Other brands and names mentioned herein maybe the trademarks of their respective owners.

Neither the whole nor any part of the information containedin, or the product described in, this document may be adapted orreproduced in any material form except with the prior written permissionof the copyright holder.

The product described in this document is subject to continuousdevelopments and improvements. All particulars of the product andits use contained in this document are given by ARM in good faith.However, all warranties implied or expressed, including but notlimited to implied warranties of merchantability, or fitness forpurpose, are excluded.

This document is intended only to assist the reader in theuse of the product. ARM Limited shall not be liable for any lossor damage arising from the use of any information in this document,or any error or omission in such information, or any incorrect useof the product.


This document is Non-Confidential. The right to use, copyand disclose this document may be subject to license restrictionsin accordance with the terms of the agreement entered into by ARMand the party that ARM delivered this document to.

Product Status

The information in this document is final, that is for a developedproduct.

Revision History
Revision A August2002 Release 1.2
Revision B January2003 Release 2.0
Revision C September2003 Release 2.0.1 for RVDS v2.0
Revision D January2004 Release 2.1 for RVDS v2.1
Revision E December2004 Release 2.2 for RVDS v2.2
Revision F May2005 Release 2.2 for RVDS v2.2 SP1
Copyright © 2002-2005 ARM Limited. All rights reserved. ARM DUI 0203F