Uploaded by SnickFreak

ARM Material

advertisement
Architecture Revisions
version
ARMv7
ARM1156T2F-S™
ARM1136JF-S™
ARMv6
ARM102xE XScaleTM
ARM1176JZF-S™
ARM1026EJ-S™
ARMv5
ARM9x6E ARM926EJ-S™
SC200™
ARM92xT
®
ARM7TDMI-S™ StrongARM
V4
SC100™
1994
1996
ARM720T™
1998
2000
2002
2006
2004
time
XScale is a trademark of Intel Corporation
1
Data Sizes and Instruction Sets
 The ARM is a 32-bit architecture.

When used in relation to the ARM:
 Byte means 8 bits
 Halfword means 16 bits (two bytes)
 Word means 32 bits (four bytes)

Most ARM’s implement two instruction sets
 32-bit ARM Instruction Set
 16-bit Thumb Instruction Set

Jazelle cores can also execute Java bytecode
2
ARM States
 ARM architecture define a 16-bit instruction set called the
Thumb instruction set. The functionality of the Thumb
instruction set is a subset of the functionality of the 32-bit ARM
instruction set.

A processor that is executing Thumb instructions is said to be
operating in Thumb state. A Thumb-capable processor that is
executing ARM instructions is said to be operating in ARM
state.

ARM processors always start in ARM state. You must
explicitly change to Thumb state using a BX (Branch and
exchange instruction set) instruction.
3
Processor Modes

The ARM has seven basic operating modes:

User : unprivileged mode under which most tasks run

FIQ : entered when a high priority (fast) interrupt is raised

IRQ : entered when a low priority (normal) interrupt is raised

Supervisor : entered on reset and when a Software Interrupt
instruction is executed

Abort : used to handle memory access violations

Undef : used to handle undefined instructions

System : privileged mode using the same registers as user mode
4
The ARM Register Set
Current Visible Registers
Abort
Mode
Undef
SVC
Mode
IRQ
FIQ
User
Mode
Mode
Mode
r0
r1
r2
r3
r4
r5
Banked out Registers
r6
r7
r8
r9
r10
r11
User
FIQ
r8
r9
r10
r11
r8
r9
r10
r11
r12
r13 (sp)
r14 (lr)
r15 (pc)
r12
r13 (sp)
r14 (lr)
IRQ
SVC
Undef
Abort
r12
r13 (sp)
r14 (lr)
r13 (sp)
r14 (lr)
r13 (sp)
r14 (lr)
r13 (sp)
r14 (lr)
r13 (sp)
r14 (lr)
spsr
spsr
spsr
spsr
spsr
cpsr
spsr
5
Register Usage
Register
Arguments into function
Result(s) from function
otherwise corruptible
(Additional parameters
r0
r1
r2
r3
passed on stack)
Register variables
Must be preserved
Scratch register
(corruptible)
Stack Pointer
Link Register
Program Counter
r4
r5
r6
r7
r8
r9/sb
r10/sl
r11
The compiler has a set of rules known as a
Procedure Call Standard that determine how to
pass parameters to a function (see AAPCS)
CPSR flags may be corrupted by function call.
Assembler code which links with compiled code
must follow the AAPCS at external interfaces
The AAPCS is part of the new ABI for the ARM
Architecture
- Stack base
- Stack limit if software stack checking selected
r12
r13/sp
r14/lr
r15/pc
- SP should always be 8-byte (2 word) aligned
- R14 can be used as a temporary once value stacked
6
Cortex-M4 Devices Processor mode and
privilege levels for software execution
The processor modes are:
 Thread mode

Used to execute application software. The processor enters Thread mode
when it comes out of reset.
 Handler mode

Used to handle exceptions. The processor returns to Thread mode when it
has finished all exception processing.
7
Cortex-M4 Devices Processor mode and
privilege levels for software execution
 The privilege levels for software execution are:

Unprivileged



The software:
 has limited access to the MSR and MRS instructions, and cannot use
the CPS instruction
 cannot access the system timer, NVIC, or system control block
 might have restricted access to memory or peripherals.
Unprivileged software executes at the unprivileged level.
Privileged


The software can use all the instructions and has access to all resources.
Privileged software executes at the privileged level.
8
Exception Handling


When an exception occurs, the ARM:
 Copies CPSR into SPSR_<mode>
 Sets appropriate CPSR bits
0x1C
 Change to ARM state
0x18
Change
to
exception
mode

0x14
 Disable interrupts (if appropriate)
0x10
 Stores the return address in LR_<mode> 0x0C
0x08
 Sets PC to vector address
0x04
To return, exception handler needs to:0x00
 Restore CPSR from SPSR_<mode>
 Restore PC from LR_<mode>
This can only be done in ARM state.
FIQ
IRQ
(Reserved)
Data Abort
Prefetch Abort
Software Interrupt
Undefined Instruction
Reset
Vector Table
Vector table can be at
0xFFFF0000 on ARM720T
and on ARM9/10 family devices
9
Program Status Registers
31
28 27
N Z C V Q
24
J
23
16 15
U
f
n
d
e
f
s
 Condition code flags




N = Negative result from ALU
Z = Zero result from ALU
C = ALU operation Carried out
V = ALU operation oVerflowed
 Sticky Overflow flag - Q flag
 Architecture 5TE/J only
 Indicates if saturation has occurred
i
8
n
e
d
7
6
5
4
0
I F T
x
mode
c
 Interrupt Disable bits.
 I = 1: Disables the IRQ.
 F = 1: Disables the FIQ.
 T Bit
 Architecture xT only
 T = 0: Processor in ARM state
 T = 1: Processor in Thumb state
 Mode bits
 J bit
 Specify the processor mode
 Architecture 5TEJ only
 J = 1: Processor in Jazelle state
039v12
10
Conditional Execution and Flags

ARM instructions can be made to execute conditionally by postfixing them with the
appropriate condition code field.
 This improves code density and performance by reducing the number of
forward branch instructions.
CMP
r3,#0
CMP
r3,#0
BEQ
skip
ADDNE r0,r1,r2
ADD
r0,r1,r2
skip

By default, data processing instructions do not affect the condition code flags but
the flags can be optionally set by using “S”. CMP does not need “S”.
loop
…
decrement r1 and set flags
SUBS r1,r1,#1
BNE loop
if Z flag clear then branch
11
Condition Codes

The possible condition codes are listed below
 Note AL is the default and does not need to be specified
Suffix
EQ
NE
CS/HS
CC/LO
MI
PL
VS
VC
HI
LS
GE
LT
GT
LE
AL
Description
Equal
Not equal
Unsigned higher or same
Unsigned lower
Minus
Positive or Zero
Overflow
No overflow
Unsigned higher
Unsigned lower or same
Greater or equal
Less than
Greater than
Less than or equal
Always
Flags tested
Z=1
Z=0
C=1
C=0
N=1
N=0
V=1
V=0
C=1 & Z=0
C=0 or Z=1
N=V
N!=V
Z=0 & N=V
Z=1 or N=!V
12
Conditional execution examples
C source code
if (r0 == 0)
{
r1 = r1 + 1;
}
else
{
r2 = r2 + 1;
}
ARM instructions
unconditional
conditional
CMP r0, #0
CMP r0, #0
BNE else
ADDEQ r1, r1, #1
ADD r1, r1, #1
ADDNE r2, r2, #1
B end
...
else
ADD r2, r2, #1
end
...
13
Download