11
Lecture 8
The ARM Architecture
22
In this lecture
ď‚§ Introduction
 ARM Programmer’s Model
ď‚§ ARM Instruction Set
33
ARM Ltd
ď‚§ Founded in November 1990
ď‚§ Spun out of Acorn Computers
ď‚§ Designs the ARM range of RISC processor
cores
ď‚§ Licenses ARM core designs to semiconductor
partners who fabricate and sell to their
customers.
ď‚§ ARM does not fabricate silicon itself
ď‚§ Also develop technologies to assist with the
design-in of the ARM architecture
ď‚§ Software tools, boards, debug hardware,
application software, bus architectures,
peripherals etc
44
Introduction
ď‚§ Many devices are powered by ARM processors
ď‚§ E.g.
ď‚§ Samsung galaxy S4 ----- ARM Cortex-A15/Cortex-A7
ď‚§ IPhone 4 -------- ARM Cortex-A8
ď‚§ Ipad mini ------- ARM Cortex-A9
55
Introduction…cntd
ď‚§ ARM is a Reduced Instruction Set Computer (RISC)
ď‚§ A large uniform register file
ď‚§ A load/store architecture
ď‚§ Simple addressing modes
ď‚§ Uniform and fixed-length instruction fields
ď‚§ Some enhancements of ARM to basic RISC architecture
ď‚§ Conditional execution of all instructions
ď‚§ Load and store multiple instructions
ď‚§ Variable cycle execution for certain instructions
ď‚§ Thumb 16-bit instruction set
ď‚§ Enhanced instructions (e.g. enhanced DSP instructions)
66
ARM Versions
77
ARM Core Block Diagram
88
ARM Registers
ď‚§ General-purpose registers
ď‚§ 37 32-bit registers
 At any one time only 16 of these registers are visible (r0 – r15)
ď‚§ Some of these registers have special functions
ď‚§ Register r13 is used as stack pointer (sp)
ď‚§ Register r14 is called the link register (lr) and is where the core puts
the return address whenever it calls a subroutine
ď‚§ Register r15 is the program counter (pc) and contains the address of
the next instruction
ď‚§ Program status registers
ď‚§ Current Program Status Register (CPSR)
ď‚§ Saved Program Status Register (SPSR)
99
ď‚§ ARM has seven basic operating modes
ď‚§ Each mode has access to its own stack space and a different subset
of registers
ď‚§ Some operations can only be carried out in a privileged mode
ARM Processor Modes
Mode Description
Supervisor
(SVC)
Entered on reset and when a Supervisor call
instruction (SVC) is executed
Privileged
modes
FIQ
Entered when a high priority (fast) interrupt is
raised
IRQ Entered when a normal priority interrupt is raised
Abort Used to handle memory access violations
Undef Used to handle undefined instructions
System
Privileged mode using the same registers as User
mode
User
Mode under which most Applications / OS tasks
run
Unprivileged
mode
Exceptionmodes
1010
The ARM Register Set
r0
r1
r2
r3
r4
r5
r6
r7
r8
r9
r10
r11
r12
r15 (pc)
cpsr
r13 (sp)
r14 (lr)
User mode
spsr
r13 (sp)
r14 (lr)
IRQ FIQ
r8
r9
r10
r11
r12
r13 (sp)
r14 (lr)
spsr spsr
r13 (sp)
r14 (lr)
Undef
spsr
r13 (sp)
r14 (lr)
Abort
spsr
r13 (sp)
r14 (lr)
SVC
Current mode Banked out registers
ARM has 37 registers, all 32-bits long
A subset of these registers is accessible in
each mode
Note: System mode uses the User mode
register set.
SPSR registers are used to save CPSR
of previous mode
1111
CPSR Register
ď‚§ Condition flags
ď‚§ N = Negative result from ALU
ď‚§ Z = Zero result from ALU
ď‚§ C = ALU operation Carried out
ď‚§ V = ALU operation oVerflowed
ď‚§ Interrupt masks
ď‚§ I Disables IRQ interrupt
ď‚§ F Disables FRQ interrupt
ď‚§ T = 1 indicates Thumb execution
ď‚§ Mode bits determine the mode in
Which the processor operates
1212
ARM Exceptions
ď‚§ Exception
ď‚§ Any condition that needs to halt the normal sequential execution of
instructions
ď‚§ Five types of exceptions in ARM
ď‚§ Each exception changes the processor mode
ď‚§ When an exception occurs it is handled by an exception handler routine
1313
Vector Table
Exception Handling
ď‚§ When an exception occurs, the ARM:
ď‚§ Copies CPSR into SPSR_<mode>
ď‚§ Sets appropriate CPSR bits
ď‚§ Change to ARM state
ď‚§ Change to exception mode
ď‚§ Disable interrupts (if appropriate)
ď‚§ Stores the return address in LR_<mode>
ď‚§ Sets PC to vector address
ď‚§ To return, exception handler needs to:
ď‚§ Restore CPSR from SPSR_<mode>
ď‚§ Restore PC from LR_<mode>
This can only be done in ARM state.
Vector table can be at
0xFFFF0000 on ARM720T
and on ARM9/10 family devices
FIQ
IRQ
(Reserved)
Data Abort
Prefetch Abort
Software Interrupt
Undefined Instruction
Reset
0x1C
0x18
0x14
0x10
0x0C
0x08
0x04
0x00
1414
ARM Instruction Set
1515
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 (8-bit instructions)
16039v12
ď‚§ When the processor is executing in ARM state:
ď‚§ All instructions are 32 bits wide
ď‚§ All instructions must be word aligned
ď‚§ Therefore the pc value is stored in bits [31:2] with bits [1:0] undefined (as instruction
cannot be halfword or byte aligned)
ď‚§ When the processor is executing in Thumb state:
ď‚§ All instructions are 16 bits wide
ď‚§ All instructions must be halfword aligned
ď‚§ Therefore the pc value is stored in bits [31:1] with bit [0] undefined (as instruction
cannot be byte aligned)
ď‚§ When the processor is executing in Jazelle state:
ď‚§ All instructions are 8 bits wide
ď‚§ Processor performs a word access to read 4 instructions at once
Program Counter (r15)
17039v12
ď‚§ Different types of instructions
ď‚§ Data processing instructions
ď‚§ Load-store instructions
ď‚§ Branch instructions
ď‚§ Software interrupt instruction
ď‚§ Program status register instructions
ď‚§ Some unique features of arm ISA
ď‚§ Conditional execution
ď‚§ Barrel shifter
Instruction Set
1818
Data Processing Instructions
ď‚§ Consist of :
ď‚§ Arithmetic: ADD ADC SUB SBC RSB RSC
ď‚§ Logical: AND ORR EOR BIC
ď‚§ Comparisons: CMP CMN TST TEQ
ď‚§ Data movement: MOV MVN
ď‚§ These instructions only work on registers, NOT memory.
ď‚§ Syntax:
<Operation>{<cond>}{S} Rd, Rn, Operand2
ď‚§ Comparisons set flags only - they do not specify Rd
ď‚§ Data movement does not specify Rn
ď‚§ Second operand is sent to the ALU via a barrel shifter.
1919
ď‚§ 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
…
SUBS r1,r1,#1
BNE loop if Z flag clear then branch
decrement r1 and set flags
Conditional Execution and Flags
2020
Condition Codes
Not equal
Unsigned higher or same
Unsigned lower
Minus
Equal
Overflow
No overflow
Unsigned higher
Unsigned lower or same
Positive or Zero
Less than
Greater than
Less than or equal
Always
Greater or equal
EQ
NE
CS/HS
CC/LO
PL
VS
HI
LS
GE
LT
GT
LE
AL
MI
VC
Suffix Description
Z=0
C=1
C=0
Z=1
Flags tested
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
ď‚§ The possible condition codes are listed below
ď‚§ Note AL is the default and does not need to be specified
2121
Conditional Execution Examples
if (r0 == 0)
{
r1 = r1 + 1;
}
else
{
r2 = r2 + 1;
}
C source code
ď‚§ 5 instructions
ď‚§ 5 words
ď‚§ 5 or 6 cycles
ď‚§ 3 instructions
ď‚§ 3 words
ď‚§ 3 cycles
CMP r0, #0
BNE else
ADD r1, r1, #1
B end
else
ADD r2, r2, #1
end
...
ARM instructions
unconditional
CMP r0, #0
ADDEQ r1, r1, #1
ADDNE r2, r2, #1
...
conditional
2222
More Examples
ď‚§ Use a sequence of several conditional instructions
if (a==0) func(1);
CMP r0,#0
MOVEQ r0,#1
BLEQ func
ď‚§ Set the flags, then use various condition codes
if (a==0) x=0;
if (a>0) x=1;
CMP r0,#0
MOVEQ r1,#0
MOVGT r1,#1
ď‚§ Use conditional compare instructions
if (a==4 || a==10) x=0;
CMP r0,#4
CMPNE r0,#10
MOVEQ r1,#0
2323
The Barrel Shifter
DestinationCF 0 Destination CF
LSL : Logical Left Shift ASR: Arithmetic Right Shift
Multiplication by a power of 2 Division by a power of 2,
preserving the sign bit
Destination CF...0 Destination CF
LSR : Logical Shift Right ROR: Rotate Right
Division by a power of 2 Bit rotate with wrap around
from LSB to MSB
Destination
RRX: Rotate Right Extended
Single bit rotate with wrap around
from CF to MSB
CF
2424
Register, optionally with shift operation
ď‚§ Shift value can either be:
ď‚§ 5 bit unsigned integer
ď‚§ Specified in bottom byte of
another register.
ď‚§ Used for multiplication by constant
e.g.
MOV r0,r1,LSL#2 (r0 = r1*4)
ADD r0, r1, r1, LSL#3
Result
Operand
1
Barrel
Shifter
Operand
2
ALU
Using a Barrel Shifter:The 2nd Operand
(r0 = r1+r1*8 = 9*r1)
2525
More Readings
 ARM System Developer’s Guide (chapters 2 & 3)
ď‚§ ARM Architecture Reference Manual

Lecture8

  • 1.
  • 2.
    22 In this lecture Introduction  ARM Programmer’s Model  ARM Instruction Set
  • 3.
    33 ARM Ltd ď‚§ Foundedin November 1990 ď‚§ Spun out of Acorn Computers ď‚§ Designs the ARM range of RISC processor cores ď‚§ Licenses ARM core designs to semiconductor partners who fabricate and sell to their customers. ď‚§ ARM does not fabricate silicon itself ď‚§ Also develop technologies to assist with the design-in of the ARM architecture ď‚§ Software tools, boards, debug hardware, application software, bus architectures, peripherals etc
  • 4.
    44 Introduction ď‚§ Many devicesare powered by ARM processors ď‚§ E.g. ď‚§ Samsung galaxy S4 ----- ARM Cortex-A15/Cortex-A7 ď‚§ IPhone 4 -------- ARM Cortex-A8 ď‚§ Ipad mini ------- ARM Cortex-A9
  • 5.
    55 Introduction…cntd  ARM isa Reduced Instruction Set Computer (RISC)  A large uniform register file  A load/store architecture  Simple addressing modes  Uniform and fixed-length instruction fields  Some enhancements of ARM to basic RISC architecture  Conditional execution of all instructions  Load and store multiple instructions  Variable cycle execution for certain instructions  Thumb 16-bit instruction set  Enhanced instructions (e.g. enhanced DSP instructions)
  • 6.
  • 7.
  • 8.
    88 ARM Registers  General-purposeregisters  37 32-bit registers  At any one time only 16 of these registers are visible (r0 – r15)  Some of these registers have special functions  Register r13 is used as stack pointer (sp)  Register r14 is called the link register (lr) and is where the core puts the return address whenever it calls a subroutine  Register r15 is the program counter (pc) and contains the address of the next instruction  Program status registers  Current Program Status Register (CPSR)  Saved Program Status Register (SPSR)
  • 9.
    99 ď‚§ ARM hasseven basic operating modes ď‚§ Each mode has access to its own stack space and a different subset of registers ď‚§ Some operations can only be carried out in a privileged mode ARM Processor Modes Mode Description Supervisor (SVC) Entered on reset and when a Supervisor call instruction (SVC) is executed Privileged modes FIQ Entered when a high priority (fast) interrupt is raised IRQ Entered when a normal priority interrupt is raised Abort Used to handle memory access violations Undef Used to handle undefined instructions System Privileged mode using the same registers as User mode User Mode under which most Applications / OS tasks run Unprivileged mode Exceptionmodes
  • 10.
    1010 The ARM RegisterSet r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r15 (pc) cpsr r13 (sp) r14 (lr) User mode spsr r13 (sp) r14 (lr) IRQ FIQ r8 r9 r10 r11 r12 r13 (sp) r14 (lr) spsr spsr r13 (sp) r14 (lr) Undef spsr r13 (sp) r14 (lr) Abort spsr r13 (sp) r14 (lr) SVC Current mode Banked out registers ARM has 37 registers, all 32-bits long A subset of these registers is accessible in each mode Note: System mode uses the User mode register set. SPSR registers are used to save CPSR of previous mode
  • 11.
    1111 CPSR Register ď‚§ Conditionflags ď‚§ N = Negative result from ALU ď‚§ Z = Zero result from ALU ď‚§ C = ALU operation Carried out ď‚§ V = ALU operation oVerflowed ď‚§ Interrupt masks ď‚§ I Disables IRQ interrupt ď‚§ F Disables FRQ interrupt ď‚§ T = 1 indicates Thumb execution ď‚§ Mode bits determine the mode in Which the processor operates
  • 12.
    1212 ARM Exceptions ď‚§ Exception ď‚§Any condition that needs to halt the normal sequential execution of instructions ď‚§ Five types of exceptions in ARM ď‚§ Each exception changes the processor mode ď‚§ When an exception occurs it is handled by an exception handler routine
  • 13.
    1313 Vector Table Exception Handling ď‚§When an exception occurs, the ARM: ď‚§ Copies CPSR into SPSR_<mode> ď‚§ Sets appropriate CPSR bits ď‚§ Change to ARM state ď‚§ Change to exception mode ď‚§ Disable interrupts (if appropriate) ď‚§ Stores the return address in LR_<mode> ď‚§ Sets PC to vector address ď‚§ To return, exception handler needs to: ď‚§ Restore CPSR from SPSR_<mode> ď‚§ Restore PC from LR_<mode> This can only be done in ARM state. Vector table can be at 0xFFFF0000 on ARM720T and on ARM9/10 family devices FIQ IRQ (Reserved) Data Abort Prefetch Abort Software Interrupt Undefined Instruction Reset 0x1C 0x18 0x14 0x10 0x0C 0x08 0x04 0x00
  • 14.
  • 15.
    1515 Data Sizes andInstruction 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 (8-bit instructions)
  • 16.
    16039v12 ď‚§ When theprocessor is executing in ARM state: ď‚§ All instructions are 32 bits wide ď‚§ All instructions must be word aligned ď‚§ Therefore the pc value is stored in bits [31:2] with bits [1:0] undefined (as instruction cannot be halfword or byte aligned) ď‚§ When the processor is executing in Thumb state: ď‚§ All instructions are 16 bits wide ď‚§ All instructions must be halfword aligned ď‚§ Therefore the pc value is stored in bits [31:1] with bit [0] undefined (as instruction cannot be byte aligned) ď‚§ When the processor is executing in Jazelle state: ď‚§ All instructions are 8 bits wide ď‚§ Processor performs a word access to read 4 instructions at once Program Counter (r15)
  • 17.
    17039v12 ď‚§ Different typesof instructions ď‚§ Data processing instructions ď‚§ Load-store instructions ď‚§ Branch instructions ď‚§ Software interrupt instruction ď‚§ Program status register instructions ď‚§ Some unique features of arm ISA ď‚§ Conditional execution ď‚§ Barrel shifter Instruction Set
  • 18.
    1818 Data Processing Instructions ď‚§Consist of : ď‚§ Arithmetic: ADD ADC SUB SBC RSB RSC ď‚§ Logical: AND ORR EOR BIC ď‚§ Comparisons: CMP CMN TST TEQ ď‚§ Data movement: MOV MVN ď‚§ These instructions only work on registers, NOT memory. ď‚§ Syntax: <Operation>{<cond>}{S} Rd, Rn, Operand2 ď‚§ Comparisons set flags only - they do not specify Rd ď‚§ Data movement does not specify Rn ď‚§ Second operand is sent to the ALU via a barrel shifter.
  • 19.
    1919  ARM instructionscan 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 … SUBS r1,r1,#1 BNE loop if Z flag clear then branch decrement r1 and set flags Conditional Execution and Flags
  • 20.
    2020 Condition Codes Not equal Unsignedhigher or same Unsigned lower Minus Equal Overflow No overflow Unsigned higher Unsigned lower or same Positive or Zero Less than Greater than Less than or equal Always Greater or equal EQ NE CS/HS CC/LO PL VS HI LS GE LT GT LE AL MI VC Suffix Description Z=0 C=1 C=0 Z=1 Flags tested 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 ď‚§ The possible condition codes are listed below ď‚§ Note AL is the default and does not need to be specified
  • 21.
    2121 Conditional Execution Examples if(r0 == 0) { r1 = r1 + 1; } else { r2 = r2 + 1; } C source code ď‚§ 5 instructions ď‚§ 5 words ď‚§ 5 or 6 cycles ď‚§ 3 instructions ď‚§ 3 words ď‚§ 3 cycles CMP r0, #0 BNE else ADD r1, r1, #1 B end else ADD r2, r2, #1 end ... ARM instructions unconditional CMP r0, #0 ADDEQ r1, r1, #1 ADDNE r2, r2, #1 ... conditional
  • 22.
    2222 More Examples ď‚§ Usea sequence of several conditional instructions if (a==0) func(1); CMP r0,#0 MOVEQ r0,#1 BLEQ func ď‚§ Set the flags, then use various condition codes if (a==0) x=0; if (a>0) x=1; CMP r0,#0 MOVEQ r1,#0 MOVGT r1,#1 ď‚§ Use conditional compare instructions if (a==4 || a==10) x=0; CMP r0,#4 CMPNE r0,#10 MOVEQ r1,#0
  • 23.
    2323 The Barrel Shifter DestinationCF0 Destination CF LSL : Logical Left Shift ASR: Arithmetic Right Shift Multiplication by a power of 2 Division by a power of 2, preserving the sign bit Destination CF...0 Destination CF LSR : Logical Shift Right ROR: Rotate Right Division by a power of 2 Bit rotate with wrap around from LSB to MSB Destination RRX: Rotate Right Extended Single bit rotate with wrap around from CF to MSB CF
  • 24.
    2424 Register, optionally withshift operation ď‚§ Shift value can either be: ď‚§ 5 bit unsigned integer ď‚§ Specified in bottom byte of another register. ď‚§ Used for multiplication by constant e.g. MOV r0,r1,LSL#2 (r0 = r1*4) ADD r0, r1, r1, LSL#3 Result Operand 1 Barrel Shifter Operand 2 ALU Using a Barrel Shifter:The 2nd Operand (r0 = r1+r1*8 = 9*r1)
  • 25.
    2525 More Readings  ARMSystem Developer’s Guide (chapters 2 & 3)  ARM Architecture Reference Manual