Documente Academic
Documente Profesional
Documente Cultură
MultiMarket Semiconductors
BL Standard ICs - Microcontrollers
February 2004
ARM Architecture
• Thumb state
• Instruction set
• Processor Modes
• Register usage
• Interrupt Handling
• 3-stage Pipeline
Semiconductors 2
ARM7TDMI-S
The ARM7TDMI-S is based on ARM7 core
– 3 stage pipeline
– Von Neumann architecture
– CPI ~1.9
– T: Thumb instruction set
– D: includes debug extensions
– M: enhanced multiplier (32x8) with instructions for 64-bit
results
– I: core has EmbeddedICE logic extensions
– S: fully synthesisable (soft IP)
Semiconductors 3
Thumb State
Semiconductors 4
Thumb state
• ARM uses a 32-bit architecture with a subset of 16-bit
instructions, still using 32-bit data and registers.
• Set of instructions re-coded into 16 bits
– Improved code density by ~ 30%
– saving program memory space
Semiconductors 5
ARM and Thumb Interworking
• Switch between ARM state and Thumb state using BX
instruction
– In ARM state: BX<condition> Rn
– In Thumb state: BX Rn
3 1 0
Rn 1
n: 0-15
ARM / Thumb
BX selection
0: ARM state
3 1 0 1: Thumb
Destinatio1 state
n 0
address
Semiconductors 6
Instruction Set
Semiconductors 7
ARM Instruction Set
• All instructions are 32-bits long
• Many instructions execute in a single cycle
• Most of the ARM Instructions can be conditionally executed
• Could be divided into six broad classes of instruction
– Branch instructions
– Data Processing instructions
– Status register transfer instructions
– Load and Store instructions
– Coprocessor instructions
– Exception-generating instructions
Semiconductors 8
Thumb Instruction Set
• All instructions are 16-bits long
Semiconductors 9
Processor Modes
Semiconductors 10
Processor Modes(1)
ARM has seven operating modes
– User unprivileged mode under which most applications
run
– FIQ entered, when a high priority (fast) interrupt is raised
– IRQ general purpose interrupt handling
– Supervisor protected mode for the operating system
entered on reset or software interrupt instruction
– System privileged mode using same registers as user mode
– Abort used to handle memory access violations
– Undefined used to handle undefined instructions
Semiconductors 11
Processor Modes(2)
User
System
FIQ
IRQ
Privileged Modes Exception Modes
Supervisor
Abort
Undefined
Semiconductors 12
Privileged and Exception Modes
FIQ IRQ Supervisor Abort Undefined
Semiconductors 13
User Mode & System Mode
• User Mode:
– User mode has access to limited system resources
– Cannot change modes freely within User mode
– User program can make a supervisor call using the SWI
instruction(SWI- Software Interrupt but is usually called
Supervisor call)
• System Mode:
– System mode is similar to User mode but used by OS which
needs access to system resources (Privileged)
– System mode also used during nested interrupt handling
Semiconductors 14
ARM Registers
Semiconductors 15
Registers (1)
An ARM core has 37 registers (32-bits wide)
• General purpose registers
– 1 program counter
– 30 general purpose registers
• Status registers
– 1 current program status register(CPSR)
– 5 saved program status registers(SPSR)
These registers are not all accessible at the same time. The processor
state and operating mode determine which registers are available to the
programmer.
Semiconductors 16
Registers (II)
• Depending on processor mode one of several banks is
accessible. Each mode can access
– the program counter r15 (PC)
– a particular r13 (stack pointer SP) and r14 (subroutine link register,
LR)
– a particular set of r0-r12 registers
– the current program status register (CPSR)
Semiconductors 17
User and
System
Register Banking
r0
r1
r2
r3
r4
Banked registers
r5
r6 FIQ IRQ Supervisor Abort Undefine
r7 d
r8 r8_fiq
r9 r9_fiq
r10 r10_fiq
r11 r11_fiq
r12 r12_fiq
r13 (SP) r13_fiq r13_irq r13_svc r13_abt r13_und
(SP) (SP) (SP) (SP) (SP)
r14 (LR) r14_fiq r14_irq r14_svc r14_abt r14_und
(LR) (LR) (LR) (LR) (LR)
r15 (PC)
Semiconductors 18
Registers in Thumb State
• The Thumb state register set is a subset of the ARM state
set. The programmer has direct access to:
– eight general registers r0 - r7
– the program counter PC
– a Stack pointer SP
– a Link register LR
– the current program status register CPSR
• In Thumb state, the high registers (r8 - r12) are not part of
the standard register set. The assembly language
programmer has limited access to them, but can use them
for fast temporary storage
Semiconductors 19
Thumb vs. ARM
r0 r0
r1 r1
r2 r2
Thumb r3 r3
state r4 r4
Low r5 r5
registers r6 r6
r7 r7
r8
Thumb ARM
r9
CPSR CPSR
SPSR SPSR
Semiconductors 20
Register Overview
User and FIQ IRQ Supervis Abort Undefine
System or d
r0 r0 r0 r0 r0 r0
r1 r1 r1 r1 r1 r1
Thumb state Low
r2 r2 r2 r2 r2 r2
r3 r3 r3 r3 r3 r3
r4 r4 r4 r4 r4 r4
registers
r5 r5 r5 r5 r5 r5
r6 r6 r6 r6 r6 r6
r7 r7 r7 r7 r7 r7
r8 r8_fiq r8 r8 r8 r8
r9 r9_fiq r9 r9 r9 r9
Thumb state High
Semiconductors 21
Program Status Register (1)
31 30 29 28 27 24 23 16 15 8 7 6 5 4 0
N Z C V Q J I F T mode
Semiconductors 22
Program Status Register (2)
31 30 29 28 27 24 23 16 15 8 7 6 5 4 0
N Z C V Q J I F T mode
Semiconductors 23
Program Counter (r15)
• When the processor is executing in ARM state
– all instructions are 32 bits wide
– all instructions must be word aligned
– bits [31:2] contain the PC, bits [1:0] are zero
(instructions cannot be halfword or byte aligned)
Semiconductors 24
Interrupt Handling
Semiconductors 25
ARM Exception Vectors and processor mode
Reset Supervisor
Interrupt(IRQ) IRQ
Semiconductors 26
Exception Vectors table
.
.
.
0 FIQ
x1C
0 IRQ
x18
0 (Reserved)
x14
0 Data Abort
x10
0 Prefetch Abort
x0C
0 Software
x08
0
Interrupt
Undefined
x04
0 Instruction
Reset
x00
Semiconductors 27
Exception Handling
• Entering an exception the ARM core
– saves the address of the next instruction in the appropriate LR
r15 (PC) r14_<mode>
(LR)
Semiconductors 28
Leaving Exception(1)
• To leave an exception, the exception handler must
– copy SPSR back into CPSR
SPSR_<mode> CPSR
CPSR: I F T mode
Control
bits
Semiconductors 29
Leaving Exception-Example(2)
• After servicing IRQ execute the following instruction
SUBS PC,R14_irq,#4
• This restores both PC and CPSR
SPSR_irq> CPSR
PC - offset
r14_<irq> (LR) r15 (PC)
Semiconductors 30
Multiple Exceptions
• Exception priorities
– When multiple exceptions arise at the same time, a fixed priority
sytem determines the order in which they are handled
Semiconductors 31
FIQ-Why is it called so ?
Semiconductors 32
Interrupt Latency
Semiconductors 33
Instruction Pipeline
Semiconductors 34
Instruction Pipeline
Semiconductors 35
3-Stage Instruction Pipeline
ARM Thum
b
Semiconductors 36
Optimal Pipelining
– In this example it takes 6 clock cycles to execute 6 instructions
– All operations are on registers (single cycle instructions)
– Clock cycles per instruction (CPI) = 1
1 2 3 4 5 6 7
Cycle
Semiconductors 38
Reference
Semiconductors 39