ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU Code Development Code Development Speaker: Lung-Hao Chang 張龍豪 Directed by Prof. Andy Wu 吳安宇 March, 19, 2003
ACCESS IC LAB
Graduate Institute of Electronics Engineering, NTU
Code DevelopmentCode Development
Speaker: Lung-Hao Chang 張龍豪Directed by Prof. Andy Wu 吳安宇
March, 19, 2003
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 103/19/2003
Goal of This LabGoal of This LabØ Familiarize with ARM software development tools: ARM
Development Suite (ADS)qProject managementqConfiguring the settings of build targets for your project
Ø Writing code for ARM-based platform designØ Mixed instruction sets, ARM and Thumb interworking, is
learned to balance the performance and code density of an application.
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 203/19/2003
OutlineOutlineØ Basic Code DevelopmentØ ARM/Thumb Interworking
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 303/19/2003
The Structure of ARM ToolsThe Structure of ARM ToolsC/C++ source C libraries asm source
object libraries
C compiler assembler
linker Librarian
.oELF object file
With DWARF2 debug tables
.axfELF/DWARF2 image
debug
ARMsd
ARMulator
System models
developmentboard
ELF: Executable and linking formatDWARF: Debug With Arbitrary Record Format
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 403/19/2003
Main Components in ADS (1/2)Main Components in ADS (1/2)Ø ANSI C compilers – armcc and tccØ ISO/Embedded C++ compilers – armcpp and tcppØ ARM/Thumb assembler - armasmØ Linker - armlinkØ Project management tool for windows - CodeWarriorØ Instruction set simulator - ARMulatorØ Debuggers - AXD, ADW, ADU and armsdØ Format converter - fromelfØ Librarian – armarØ ARM profiler - armprof
ADS: ARM Developer Suite
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 503/19/2003
Main Components in ADS (2/2)Main Components in ADS (2/2)Ø C and C++ librariesØ ROM-based debug tools (ARM Firmware Suite, AFS)Ø Real Time Debug and Trace support Ø Support for all ARM cores and processors including
ARM9E, ARM10, Jazelle, StrongARM and Intel Xscale
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 603/19/2003
View in View in CodeWarrierCodeWarrierØ The CodeWarrior IDE provides a simple, versatile,
graphical user interface for managing your software development projects.
Ø Develop C, C++, and ARM assembly language codeØ targeted at ARM and Thumb processors.Ø It speeds up your build cycle by providing:qcomprehensive project management capabilitiesqcode navigation routines to help you locate routines
quickly.
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 703/19/2003
CodeWarrior DesktopCodeWarrior DesktopToolbarMenu Create a new project
Project Files view
Target Settings
Editor windows
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 803/19/2003
Views in AXDViews in AXDØ Various views allow you to examine and control the
processes you are debugging.Ø In the main menu bar, two menus contain items that
display views:qThe items in the Processor Views menu display views
that apply to the current processor onlyqThe items in the System Views menu display views that
apply to the entire, possibly multiprocessor, target system
AXD: the ARM eXtended Debugger
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 903/19/2003
AXD DesktopAXD DesktopToolbarMenu
Status bar
Disassembly processor view
Source processor view
Console processor view
Control System view
Control System view
Variable processor view
Watch processor view
Watch system view
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 1003/19/2003
ARM Emulator: ARM Emulator: ARMulatorARMulator (1/2)(1/2)Ø A suite of programs that models the behavior of various
ARM processor cores and system architecture in software on a host system
Ø Can be operates at various levels of accuracyq Instruction accurateqCycle accurateqTiming accurate
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 1103/19/2003
ARM Emulator: ARM Emulator: ARMulatorARMulator (2/2)(2/2)Ø Benchmarking before hardware is availableq Instruction count or number of cycles can be measured
for a program.qPerformance analysis.
Ø Run software on ARMulatorqThrough ARMsd or ARM GUI debuggers, e.g., AXDqThe processor core model incorporates the remote
debug interface, so the processor and the system state are visible from the ARM symbolic debugger
qSupports a C library to allow complete C programs to run on the simulated system
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 1203/19/2003
ARM Symbolic DebuggerARM Symbolic DebuggerØ ARMsd: ARM and Thumb symbolic debuggerq can single-step through C or assembly language sources, q set break-points and watch-points, and q examine program variables or memory
Ø It is a front-end interface to debug program running eitherq under emulation (on the ARMulator) orq remotely on a ARM development board (via a serial line or
through JTAG test interface) Ø It allows the setting ofq breakpoints, addresses in the codeq watchpoints, memory address if accessed as data addressè cause exception to halt so that the processor state can be
examined
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 1303/19/2003
Basic Debug RequirementsBasic Debug RequirementsØ Control of program executionqset watchpoints on interesting data accessesqset breakpoints on interesting instructionsqsingle step through code
Ø Examine and change processor stateq read and write register values
Ø Examine and change system stateqaccess to system memoryvdownload initial code
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 1403/19/2003
Debugger (1/2)Debugger (1/2)Ø A debugger is software that enables you to make use of a debug
agent in order to examine and control the execution of software running on a debug target
Ø Different forms of the debug targetq early stage of product development, softwareq prototype, on a PCB including one or more processorsq final product
Ø The debugger issues instructions that canq load software into memory on the targetq start and stop execution of that softwareq display the contents of memory, registers, and variablesq allow you to change stored values
Ø A debug agent performs the actions requested by the debugger, such asq setting breakpointsq reading from / writing to memory
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 1503/19/2003
Debugger (2/2)Debugger (2/2)
Ø Examples of debug agentsq Multi-ICEq Embedded ICEq ARMulatorq BATSq Angle
Ø Remote Debug Interface (RDI) is an open ARM standard procedural interface between a debugger and the debug agent
RDI
Targetemulated in
Software
ARMulatorRDI
Targetemulated in
Software
BATSRDI
ARMdevelopment
board
Multi-ICE
ARMdevelopment
board
RDIRemote_A
Angel
Target (software) Target (hoftware)
Remote Debug Interface (RDI)
ARM debuggerAxD
RDI
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 1603/19/2003
Program DesignProgram DesignØ Start with understanding the requirements, translate the
requirements into an unambiguous specificationsØ Define a program structure, the data structure and the
algorithms that are used to perform the required operations on the data
Ø The algorithms may be expressed in pseudo-codeØ Individual modules should be coded, tested and
documentedØ Nearly all programming is based on high-level
languages, however it may be necessary to develop small software components in assembly language to get the best performance
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 1703/19/2003
OutlineOutlineØ Basic Code DevelopmentØ ARM/Thumb Interworking
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 1803/19/2003
ARM Instruction SetsARM Instruction SetsØ ARM processor is a 32-bit architecture, most ARM’s
implement two instruction setsq32-bit ARM instruction setq16-bit Thumb instruction set
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 1903/19/2003
ARM and Thumb Code SizeARM and Thumb Code Size
Simple C routineif (x>=0)
return x;else
return -x;
The equivalent ARM assemblyIabs CMP r0,#0 ;Compare r0 to zero
RSBLT r0,r0,#0 ;If r0<0 (less than=LT) then do r0= 0-r0MOV pc,lr ;Move Link Register to PC (Return)
The equivalent Thumb assemblyCODE16 ;Directive specifying 16-bit (Thumb) instructions
iabs CMP r0,#0 ;Compare r0 to zeroBGE return ;Jump to Return if greater or
;equal to zeroNEG r0,r0 ;If not, negate r0
return MOV pc,lr ;Move Link register to PC (Return)
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 2003/19/2003
The Need for The Need for InterworkingInterworkingØ The code density of Thumb and its performance from narrow
memory make it ideal for the bulk of C code in many systems. However there is still a need to change between ARM and Thumb state within most applications:q ARM code provides better performance from wide memoryv therefore ideal for speed-critical parts of an application
q some functions can only be performed with ARM instructions, e.g.vaccess to CPSR (to enable/disable interrupts & to change mode)vaccess to coprocessors
q exception HandlingvARM state is automatically entered for exception handling, but
system specification may require usage of Thumb code for main handler
q simple standalone Thumb programs will also need an ARM assembler header to change state and call the Thumb routine
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 2103/19/2003
InterworkingInterworking InstructionsInstructionsØ Interworking is achieved using the Branch Exchange
instructionsq in Thumb state
BX Rnq in ARM state (on Thumb-aware cores only)
BX<condition> Rnwhere Rn can be any registers (r0 to r15)
Ø This performs a branch to an absolute address in 4GB address space by copying Rn to the program counter
Ø Bit 0 of Rn specifies the state to be changed to
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 2203/19/2003
Switching between StatesSwitching between States
For most instruction generated by compiler:• Conditional execution is not used• Source and destination registers identical• Only Low registers used• Constants are of limited size• Inline barrel shifter not used16-bit Thumb instruction
32-bit ARM instructionADDS r2,r2,#1
ADD r2,#1
031
15 0
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 2303/19/2003
ExampleExample;start off in ARM state
CODE32ADR r0,Into_Thumb+1 ;generate branch target
;address & set bit 0,;hence arrive Thumb state
BX r0 ;branch exchange to Thumb…CODE16 ;assemble subsequent as
;ThumbInto_Thumb …
ADR r5,Back_to_ARM ;generate branch target to;word-aligned address,;hence bit 0 is cleared.
BX r5 ;branch exchange to ARM…CODE32 ;assemble subsequent as
;ARMBack_to_ARM …
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 2403/19/2003
ARM/Thumb ARM/Thumb InterworkingInterworking between between C/C++ and ASMC/C++ and ASM
Ø C code compiled to run in one state may call assembler to execute in the other state, and vice-versa. q If the callee is in C, compile it using –apcs /interworkq If the callee is in ASM, assemble it using –apcs
/interwork and return using BX LRØ Any assembler code used in this manner must conform
to ATPCS where appropriate, e.g., function parameters passed in r0-r3 & r12 corruptible
ACCESS IC LAB Graduate Institute of Electronics Engineering, NTU
SoC Design Laboratory PP. 2503/19/2003
InterworkingInterworking CallsCalls
Thumb-Thumb calls permitted
Non-interworkingThumb code
Non-interworkingARM code
InterworkingThumb code
InterworkingARM code
No calls possible
ARM-ARMcalls permitted
ARM-Thumbcalls permitted
Non-interworking to interworkingARM/Thumb calls permitted
Modules that are compiled for interworking generate slightly larger code, typically 2% larger for Thumb and less than 1% larger for ARM.