Documente Academic
Documente Profesional
Documente Cultură
Processors
OUTLINE
-Background
-ARM Microprocessor
ARM Architecture,
Assembly Language Programming
Instruction Set
BACKGROUND
Architectural features of embedded processor
General rules (with exceptions):
1. Designed for efficiency (vs. ease of programming)
2. Huge variety of processors (resulting from 1.)
3. Harvard architecture
4. Heterogeneous register sets
5. Limited instruction-level parallelism or VLIW ISA
6. Different operation modes (saturating arithmetic, fixed point)
7. Specialised microcontroller & DSP instructions (bit-field
addressing, multiply/accumulate, bit-reversal, modulo addressing)
8. Multiple memory banks
9. No
fat(MMU, caches, memory protection, target buffers,
complex pipeline logic, ...)
These features have to be known to the compiler!
ARM Concept
What is ARM?
ARM IP Core,
IP
ITARM
TI, Intel
IP Core
T.I. PHILIPSINTEL
RISC Microcontroller
ARM7ARM9ARM9E-SStrongARM
ARM10..
4
ARM Concept
Why ARM?
Low powerLow costTiny
8/16/32 bit microprocessor
Thumb mode
Namely
TThumb Mode
DDebug interface (JTAG)
MMultiplier
IICE interface (TraceBreak point)
5
ARM processor
ARM is a family of RISC architectures.
IC
IC
Ex:
LAN controller
LCD controller
8
Intel Xscale
10
fetch
3
instruction
decode execute
fetch
decode execute
fetch
decode execute
time
11
ARM busses
Open standard.
Many external
devices.
Two varieties:
AMBA HighPerformance Bus
(AHB).
AMBA Peripherals
Bus (APB).
memory
CPU
AHB
bridge
AMBA:
I/O
APB
12
14
15
22
21
20
19
18
17
16
word16
15
14
half-word14
11
13
12
half-word12
10
word8
7
byte6
3
half-word4
1
byte
address
16
Operating Modes
The ARM7TDMI processor has seven modes of operations:
User mode(usr)
- Normal program execution mode
Fast Interrupt mode(fiq)
- Supports a high-speed data transfer or channel process.
Interrupt mode(irq)
- Used for general-purpose interrupt handling.
Supervisor mode(svc)
- Protected mode for the operating system.
Abort mode(abt)
- implements virtual memory and/or memory protection
System mode(sys)
- A privileged user mode for the operating system. (runs OS
tasks)
Undefined mode(und)
- supports a software emulation of hardware coprocessors
Except user mode, all are known as privileged mode.
17
r8
r9
r10
r11
r12
r13
r14
r15 (PC)
31
CPSR
NZCV
Registers
37 registers
19
CPSR
user mode
r8_fiq
r9_fiq
r10_fiq
r11_fiq
r12_fiq
r13_fiq
r14_fiq
SPSR_fiq
fiq
mode
r13_svc
r14_svc
r13_abt
r14_abt
SPSR_svc
SPSR_abt
svc
mode
abort
mode
r13_irq
r14_irq
r13_und
r14_und
SPSR_irq SPSR_und
irq
mode
undefined
mode
20
Registers
R0 to R15 are directly accessible
R0 to R14 are general purpose
R13: Stack point (sp) (in common)
Individual stack for each processor mode
R14: Linked register (lr)
R15 holds the Program Counter (PC)
CPSR - Current Program Status Register contains
condition code flags and the current mode bits
5 SPSRs (Saved Program Status Registers) which
are loaded with CPSR when an exceptions occurs
21
22
23
24
25
bit 0
23
22
21
20
19
18
17
16
word16
15
14
13
12
half-word14 half-word12
11
10
word8
7
byte6 half-word4
3
byte
address
26
Little endian
27
Exceptions
Exceptions are
usually used to
handle unexpected
events which arise
during the execution
of a program
(Task)
(ISR)
(Event)
(Flag)
()
From -ARM
SoC
28
Exception
System Exception
CPU
Interrupt Exception
ARM CPU
29
Exception Groups
Direct effect of executing an instruction
SWI
Undefined instructions
Prefetch aborts (memory fault occurring during fetch)
A side-effect of an instruction
Data abort (a memory fault during a load or store data
access)
Exceptions generated externally
Reset
IRQ
FIQ
30
Exception Entry
Change to the corresponding mode
Save the address of the instruction following the
exception instruction in r14 of the new mode
Save the old value of CPSR in the SPSR of the
new mode
Disable IRQ
If the exception is a FIQ, disables further FIQ
Force PC to execute at the relevant vector
address
31
Mo de
SVC
UND
SVC
Abort
Abort
IRQ
FIQ
Vecto r addres s
0x00000000
0x00000004
0x00000008
0x0000000C
0x00000010
0x00000018
0x0000001C
32
Exception Return
Any modified user registers must be restored
Restore CPSR
Resume PC in the correct instruction stream
33
Exception Priorities
Reset
Data abort
FIQ
IRQ
Prefetch abort
SWI, undefined instruction
Highest priority
34
1
2
Halfword
and signed
halfword /
byte support
System
mode
Early ARM
architectures
ARM7TDMI
ARM720T
5TE
CLZ
Jazelle
5TEJ
Java bytecode
execution
SA-110
Saturated maths
ARM9EJ-S
ARM926EJ-S
SA-1110
DSP multiplyaccumulate
instructions
ARM7EJ-S
ARM1026EJ-S
3
Thumb
instruction
set
Improved
ARM/Thumb
Interworking
ARM1020E
4T
ARM9TDMI
ARM940T
SIMD Instructions
Multi-processing
XScale
ARM9E-S
ARM966E-S
V6 Memory
architecture (VMSA)
Unaligned data
support
ARM1136EJ-S
reference: http://www.intel.com/education/highered/modelcurriculum.htm
label
37
Instruction Set
The ARM processor is very easy to program at
the assembly level
In this part, we will
Look at ARM instruction set and assembly
language programming at the user level
39
40
r0, #5
BYPASS
r1, r1, r0
r1, r1, r2
CMP
ADDNE
SUBNE
r0, #5
r1, r1, r0
r1, r1, r2
41
is
is
is
is
is
in
in
in
in
in
CMP
CMPEQ
ADDEQ
register
register
register
register
register
e++;
r0
r1
r2
r3
r4
r0, r1
r2, r3
r4, r4, #1
42
28 27
cond
N: Negative
Z: Zero
C: Carry
V: oVerflow
43
Mn e mo n i c
ex tens i o n
EQ
NE
CS/HS
CC/LO
MI
PL
VS
VC
HI
LS
GE
LT
GT
LE
AL
NV
In t e rp re t at i o n
Equal / equals zero
Not equal
Carry set / unsigned higher or same
Carry clear / unsigned lower
Minus / negative
Plus / positive or zero
Overflow
No overflow
Unsigned higher
Unsigned lower or same
Signed greater than or equal
Signed less than
Signed greater than
Signed less than or equal
Always
Never (do not use!)
S t at us f l ag s t at e f o r
e x e c ut i o n
Z set
Z clear
C set
C clear
N set
N clear
V set
V clear
C set and Z clear
C clear or Z set
N equals V
N is not equal to V
Z clear and N equals V
Z set or N is not equal to V
any
none
44
Condition Field
In ARM state, all instructions are conditionally executed
according to the CPSR condition codes and the
instruction
s condition field
Fifteen different conditions may be used
Alwayscondition
Default condition
May be omitted
Nevercondition
The sixteen (1111) is reserved, and must not be used
May use this area for other purposes in the future
45
46
47
48
r0, r1, r2
; r0 := r1 + r2
49
Arithmetic Operations
These instructions perform binary arithmetic on two 32bit operands
The carry-in, when used, is the current value of the C bit
in the CPSR
ADD
r0, r1, r2
r0 := r1 + r2
ADC
r0, r1, r2
r0 := r1 + r2 + C
SUB
r0, r1, r2
r0 := r1 r2
SBC
r0, r1, r2
r0 := r1 r2 + C 1
RSB
r0, r1, r2
r0 := r2 r1
RSC
r0, r1, r2
r0 := r2 r1 + C 1
50
r0, r1, r2
r0 := r1 AND r2
ORR
r0, r1, r2
r0 := r1 OR r2
EOR
r0, r1, r2
r0 := r1 XOR r2
BIC
r0, r1, r2
for i in [0..31]
52
r0, r2
r0 := r2
MVN
r0, r2
r0 := NOT r2
The
MVN
mnemonic stands for
move negated
53
Comparison Operations
These instructions do not produce a result, but just set
the condition code bits (N, Z, C, and V) in the CPSR
according to the selected operation
set cc on r1 r2
CMP
r1, r2
compare
CMN
r1, r2
TST
r1, r2
bit test
set cc on r1 AND r2
TEQ
r1, r2
test equal
set cc on r1 XOR r2
54
Immediate Operands
If we wish to add a constant to a register, we can replace
the second source operand with an immediate value
ADD
AND
r3, r3, #1
r8, r7, #&ff
; r3 := r3 + 1
; r8 := r7[7:0]
A constant preceded by
#
A hexadecimal by putting
&after the
#
55
; r3 := r2 + 8 * r1
31
XXXXX
00000
LSL #5
57
31
0
XXXXX
00000
LSR #5
58
31
00000 0
ASR #5 ;positive operand
59
31
11111 1
ASR #5 ;negative operand
60
31
ROR #5
61
31
C
RRX
62
; r5:=r5+r3*2^r2
63
r1
r0
r3
r2
r3
r2
ADDS
ADC
Adding
S
to the opcode, standing for
Set
condition codes
64
Multiplies (1)
A special form of the data processing instruction
supports multiplication
Some important differences
Immediate second operands are not supported
The result register must not be the same as the first source
register
If the
S
bit is set, the C flag is meaningless
MUL
r4, r3, r2
; r4 := (r3 x r2)[31:0]
65
Multiplies (2)
The multiply-accumulate instruction
MLA
; r4 := (r3 x r2 + r1)[31:0]
67
Addressing mode
The ARM data transfer instructions are all based
around register-indirect addressing
Based-plus-offset addressing
Based-plus-index addressing
LDR
STR
r0, [r1]
r0, [r1]
; r0 := mem32[r1]
; mem32[r1] := r0
Register-indirect addressing
68
69
r0, [r1]
r0, [r1]
; r0 := mem32[r1]
; mem32[r1] := r0
Register-indirect addressing
70
Rd mem32[address]
STR
Mem32[address] Rd
LDRB
Rd mem8[address]
STRB
Mem8[address] Rd
LDRH
Rd mem16[address]
STRH
Mem16[address] Rd
LDRSB
Rd signExtend(mem8[address])
LDRSH
Rd signExtend(mem16[address])
71
; r0 := mem32[r1 + 4]
72
The exclamation
!mark indicates that the instruction should
update the base register after initiating the data transfer
73
r0, [r1], #4
; r0 := mem32[r1]
; r1 := r1 + 4
74
Application
LOOP
LOOP
ADR
r1, table
LDR
r0, [r1]
; r0 := mem32[r1]
ADD
r1, r1, #4
; r1 := r1 + 4
;do some operation on r0
ADR
LDR
r1, table
r0, [r1], #4
; r0 := mem32[r1]
; r1 := r1 + 4
;do some operation on r0
75
; r0 := mem32[r1]
; r2 := mem32[r1 + 4]
; r5 := mem32[r1 + 8]
STM
Addressing mode
Description
Starting address
End address
Rn!
IA
Increment
After
Rn
Rn+4*N-4
Rn+4*N
IB
Increment
Before
Rn+4
Rn+4*N
Rn+4*N
DA
Decrement
After
Rn-4*Rn+4
Rn
Rn-4*N
DB
Decrement
Before
Rn-4*N
Rn-4
Rn-4*N
Example (1)
LDMIA
OR
LDMIA
r1 := 10
r2 := 20
r3 := 30
r0 := 0x100
78
Example (2)
LDMIA
r1 := 10
r2 := 20
r3 := 30
r0 := 0x10C
79
Example (3)
LDMIB
r1 := 20
r2 := 30
r3 := 40
r0 := 0x10C
80
Example (4)
LDMDA
r1 := 40
r2 := 50
r3 := 60
r0 := 0x108
81
Example (5)
LDMDB
r1 := 30
r2 := 40
r3 := 50
r0 := 0x108
82
Application
High address
r11
r9
LOOP
LDMIA
STMIA
CMP
BNE
Copy
r9! , {r0-r7}
r10!, {r0-r7}
r9 , r11
LOOP
r10
Low address
83
84
85
POP
=LDM
PUSH
=STM
FA
LDMFA
LFMFA
STMFA
STMIB
FD
LDMFD
LDMIA
STMFD
STMDB
EA
LDMEA
LDMDB
STMEA
STMIA
ED
LDMED
LDMIB
STMED
STMDA
86
87
SWP
SWPB
WORD exchange
tmp = mem32[Rn]
mem32[Rn] = Rm
Rd = tmp
Byte exchange
tmp = mem8[Rn]
mem8[Rn] = Rm
Rd = tmp
88
Example
SWP
89
90
91
92
93
LABEL
LOOP
MOV
ADD
CMP
BNE
LABEL
r0, #0
; initialize counter
Branch Conditions
B ran c h
B
BAL
BEQ
BNE
BPL
BMI
BCC
BLO
BCS
BHS
BVC
BVS
BGT
BGE
BLT
BLE
BHI
BLS
In t e rp re t at i o n
Unconditional
Always
Equal
Not equal
Plus
Minus
Carry clear
Lower
Carry set
Higher or same
Overflow clear
Overflow set
Greater than
Greater or equal
Less than
Less or equal
Higher
Lower or same
No rmal us e s
Always take this branch
Always take this branch
Comparison equal or zero result
Comparison not equal or non-zero result
Result positive or zero
Result minus or negative
Arithmetic operation did not give carry-out
Unsigned comparison gave lower
Arithmetic operation gave carry-out
Unsigned comparison gave higher or same
Signed integer operation; no overflow occurred
Signed integer operation; overflow occurred
Signed integer comparison gave greater than
Signed integer comparison gave greater or equal
Signed integer comparison gave less than
Signed integer comparison gave less than or equal
Unsigned comparison gave higher
Unsigned comparison gave lower or same
95
Branch Instructions
B
PC=label
BL
PC=label
LR=BL
BX
BLX
PC=label, T=1
PC=Rm & 0xfffffffe, T=Rm & 1
LR = BLX
96
subroutine
MOV
subroutine
r1, #5
r1, #0
; branch to subroutine
; return to here
; return
97
Solution
Push r14 into a stack
The subroutine will often also require some work
registers, the old values in these registers can be
saved at the same time using a store multiple
instruction
98
SUB1
STMFD
BL
LDMFD
SUB2
MOV
SUB1
pc, r14
BL
..
JUMPTAB
CMP
BEQ
CMP
BEQ
CMP
BEQ
..
JUMPTAB
r0, #0
SUB0
r0, #1
SUB1
r0, #2
SUB2
100
JUMPTAB
r1, SUBTAB
r0, #SUBMAX
pc, [r1, r0, LSL #2]
ERROR
SUB0
SUB1
SUB2
101
Supervisor Calls
SWI: SoftWare Interrupt
The supervisor calls are implemented in system software
They are probably different from one ARM system to
another
Most ARM systems implement a common subset of
calls in addition to any specific calls required by the
particular application
; This routine sends the character in the bottom
; byte of r0 to the use display device
SWI
SWI_WriteC
; output r0[7:0]
102
103
0x00
0x04
0x08
0x0c
0x10
0x14
0x18
0x1c
Vector Table
Reset
Undef instr.
SWI
Prefetch abort
Data abort
Reserved
IRQ
FIQ
SWI handler
SWI handler
...
104
0x00
0x04
0x08
0x0c
0x10
0x14
0x18
0x1c
Vector Table
Reset
Undef instr.
SWI
Prefetch abort
Data abort
Reserved
IRQ
FIQ
SWI handler
switch (rn) {
case 0x1:
case 0x6:
...
}
105
106
START
LOOP
TEXT
ENTRY
ADR
LDRB
CMP
SWINE
BNE
SWI
=
END
r1, TEXT
r0, [r1], #1
r0, #0
DCB: allocate one or more bytes of
SWI_WriteC
memory and define initial runtime
LOOP
content of memory (=)
SWI_Exit
"Hello World",&0a,&0d,0
108
Filename: test.s
109
Filename: test.s
110
main:
MOV r0, #100
ADD r0, r0, r0
.end
Filename: test.s
.enddirective
111
LABEL
:
armasm
Filename: test.s
Comments
/* your comments... */
@ your comments (line comment)
112
114
115
Thumb Applications
Thumb properties
Thumb requires 70% space of the ARM code
Thumb uses 40% more instructions than the ARM
code
With 32-bit memory, the ARM code is 40% faster
than the Thumb code
With 16-bit memory, the Thumb code is 45%
faster than the ARM code
Thumb uses 30% less external memory power
than ARM code
116
DSP Extensions
DSP Extensions
E
16bit Multiply and Multiply-Accumulate instructions
Saturated, signed arithmetic
Introduced in v5TE
Available in ARM9E, ARM10E and Jaguar families
117
118
ARM Architectures
Feature Set
Architecture
v4T
v5TE
v5TEJ
v6
THUMBTM
DSP
JazelleTM
Media
Outline
Introduction
Programmers model
Instruction set
System design
Development tools
121
122
AMBA
Arbiter
Reset
ARM
TIC
External
RAM
Timer
Bus Interface
External
Bus
Interface
Remap/
Pause
Bridge
External
ROM
Decoder
On-chip
RAM
Interrupt
Controller
AHB or ASB
APB
System Bus
Peripheral Bus
AMBA
ACT
Advanced Microcontroller Bus
AMBA Compliance Testbench
Architecture
PrimeCell
ADK
ARM
s AMBA compliant
Complete AMBA Design Kit
peripherals
reference: http://www.intel.com/education/highered/modelcurriculum.htm
Outline
Introduction
Programmers model
Instruction set
System design
Development tools
126
Open source
GNU
127
GNU
Compiler
armcc
gcc
Assembler
armasm
binutils
Linker
armlink
binutils
Format
converter
fromelf
binutils
C library
C library
newlib
Debugger
Armsd, AXD
GDB, Insight
Simulator
ARMulator
Simulator in GDB
128
C libraries
asm source
C compiler
as sembler
.aof
object
libraries
linker
.axf
system model
ARMulator
debug
ARMsd
development
board
129
ADS-Assembler
CompilerObject
LinkerELF
130
ADS- Pre-assembler
Pre-assembler
Pseudo code -> assembler -> Object
131
Example
Example of pr-compiler
132
Example
Example of pr-compiler
133