User guide

1.3 Developing for the ARM
This book gives information and example code for some of the most common ARM programing tasks. The following
sections summarize the subject of each chapter:
Using the Procedure call standards
Interworking ARM and Thumb code
Mixing C, C++, and Assembly Language
Handling Processor Exceptions
Writing Code for ROM
Caches and tightly coupled memory
Using the Debug Communications Channel.
1.3.1 Using the Procedure call standards
The ARM-Thumb procedure call standard defines register usage and stack conventions that must be followed to
enable separately compiled and assembled modules to work together. There are a number of variants on the base
standard. The ARM C and C++ compilers always generate code that conforms to the selected ATPCS variant. The
linker selects an appropriate standard C or C++ library to link with, if required.
When developing code for the ARM, you must select an appropriate ATPCS variant. For example, if you are writing
code that interworks between ARM and Thumb state you must select the -apcs /interwork option in the
compiler and assembler.
If you are writing code in C or C++, you must ensure that you have selected compatible ATPCS options for each
compiled module.
If you are writing your own assembly language routines, you must ensure that you conform to the appropriate ATPCS
variant. See Chapter 2 Using the Procedure Call Standard for more information.
If you are mixing C and assembly language, ensure that you understand the ATPCS implications.
1.3.2 Interworking ARM and Thumb code
If you are writing code for ARM processors that support the Thumb 16-bit instruction set, you can mix ARM and
Thumb code as required. If you are writing C or C++ code you must compile with the -atpcs /interwork option.
The linker detects when an ARM function is called from Thumb state, or a Thumb function is called from ARM state
and alters call and return sequences, or inserts interworking veneers to change processor state as necessary.
If you are writing assembly language code you must ensure that you comply with the interworking ATPCS variant.
There are a number of ways to change processor state, depending on the target architecture version. See Chapter 3
Interworking ARM and Thumb for more information.
1.3.3 Mixing C, C++, and Assembly Language
You can mix separately compiled and assembled C, C++, and ARM assembly language modules in your program.
You can use the inline assemblers in the C and C++ compilers to write small assembly language routines within your
C or C++ code. However, there are a number of restrictions to the assembly language code you can write if you are
using the inline assemblers. These are described in Using the inline assemblers. In addition, Chapter 4 Mixing C,
C++, and Assembly Language gives general guidelines and examples of how to call between C, C++, and assembly
language modules.
1.3.4 Handling Processor Exceptions
The ARM processor recognizes seven exception types:
Reset
Occurs when the processor reset pin is asserted. This exception is only expected to occur for
signalling power-up, or for resetting as if the processor has just powered up. A soft reset can be
done by branching to the reset vector (0x0000).
Undefined Instruction
Occurs if neither the processor, or any attached coprocessor, recognizes the currently executing
instruction.
Software Interrupt (SWI)
This is a user-defined interrupt instruction. It allows a program running in User mode, for example,
to request privileged operations that run in Supervisor mode, such as an RTOS function.
Prefetch Abort
Occurs when the processor attempts to execute an instruction that has been prefetched from an
illegal address. An illegal address is one at which memory does not exist, or one that the memory
management subsystem has determined is inaccessible to the processor in its current mode.
Introduction
Copyright ?1999 2001 ARM Limited 1-3