ELEC 2142 (2016) Week 1
ELEC 2142 (2016) Week 1
ELEC 2142 (2016) Week 1
ARM7TDMI Architecture
Outline
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 2/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
EMBEDDED
Embedded Systems SYSTEMS
- Applications
Application Area Examples
In this course:
Applica1ons
and
OS
ARM7TDMI processor
High
level
languages
architecture
Instruc1on
Set
Architecture
ARMv4T instruction set
(ISA)
LPC2478 microcontroller
and QVGA development
Microarchitecture
board
Gates
Keil Microvision 4 IDE
Assembly language
Transistors
programming
Apple iphone 3 had ARM7 processor core
ARM7TDMI - T:Thumb, D:on-chip debug, M:multiplier,
I:in-circuit emulation
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 6/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 8/40
THE PROCESSOR
ARM7TDMI - Processor Core (ARM7TDMI)
ARM 7
Thumb
On-chip
Debug
Multipl
Embedd
ICE ( In
Circuit
Emulat
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
Memory
Memory hierarchy includes
Registers (general purpose and special purpose)
Internal cache
External cache
MEMORY SYSTEM
Main (primary) memory - data and program
Secondary memory, virtual memory
• The caches are managed automatically by the- hard disks etc
hardware and effectively
Typically, invisible
the low-level to the
programmer needs to access registers
application.
and main memory
Caches are managed automatically by the hardware
• VirtualVirtual
memory is handled
memory by Operating
is handled by the system
operating system
Speed Size
Registers A few ns 128 bytes
On-chip Cache Ten ns 8-32 Kbytes
2nd Cache A few tens of ns Hundreds of Kbytes
Main Memory 100ns Mega bytes
Virtual memory tens of 100 Gbytes
(Hard disk) milliseconds
Fast memory
• Introduction is Systems
to Embedded moreand expensive per bitELEC
ARM Architecture than2142slow
- Week 1 10/40
ments that hold
Introduction
data, where each element
ARM7TDMI Programmer’s Model
has a
Instructions & Tools Assembly Examples
edMemory
number of bits and an address.
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 11/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
Memory
and R1.
2 Perform the ALU operation R1+R2
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 12/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
Data Types
Basic element is a binary digit (a bit)
Bits are organized into
Byte - 8 bits
Halfword - 16 bits or 2 bytes
Word - 32 bits or 4 bytes
ARM instructions are 32 bits wide.
The alternative instruction set known as Thumb instructions
are 16 bits wide
Data is typically handled at word, halfword, and/or byte levels
Reading or writing data at word level must occur at word-aligned
memory addresses. i.e. addresses aligned to 4-byte boundaries
such as 0xXXXXXXX0, 0xXXXXXXX4, 0xXXXXXXX8,
0xXXXXXXXC.
Reading or writing data at halfword level must occur at
halfword-aligned memory addresses. i.e. addresses aligned to
2-byte boundaries such as 0xXXXXXXX0, 0xXXXXXXX2.
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 13/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
PROCESSOR
Processor Modes MODES
• Version 4T (ARM7TDMI) cores support seven
processorprocessor
ARM7TDMI modes: User,
core has 7FIQ, IRQ
processor , Supervisor,
modes. 6 privileged
Abort, Undef, and System.
modes and 1 unprivileged mode.
Mode Description
Supervisor Entered on reset and when a Software Interrupt
(SVC) (SWI) instruction is executed
FIQ Entered when a high priority (Fast) interrupt is Privileged
raised modes/
IRQ Entered when a low priority (normal) interrupt is Exception
raised modes
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
13
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 14/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
Processor Modes
User mode is the normal mode of operation where most
applications run.
Operational mode of the processor can be changed due to
external events such as interrupts, exceptions (such as trying
to access invalid memory location, trying to execute an
undefined instruction) or due to a software trigger within the
program.
Low priority interrupts - IRQ mode
Fast (high priority) interrupts - FIQ mode
Supervisor mode - allows the processor to access restricted
resources
Undefined mode - can be used to software emulate an
instruction not in the instruction set
Abort mode - allows the processor to recover from memory
access violation
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 15/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
Registers
Basic storage unit within the data path of the processor.
An N-bit register is a series of N D-type flip-flops.
Each register is 32 bits wide (1 word or 4 bytes).
There are 37 physical registers in total, divided as
30 general purpose registers
6 status registers
1 program counter (PC)
These registers are organized in a partially overlapped
configuration among the different processor modes.
That is, at any given time, the programmer can access 15
general purpose registers (r0,r1,...,r14), program counter (PC
or r15), and one/two status registers.
User mode and system mode share the same set of registers
When the processor mode is changed some of the registers are
swapped with a set of physically different registers dedicated
to the new mode.
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 16/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
REGISTERS
Registers
Mode
User/System Supervisor Abort Undefined Interrupt -IRQ Fast Interrupt - FIQ
R0 , A1 R0 R0 R0 R0 R0
R1, A2 R1 R1 R1 R1 R1
R2, A3 R2 R2 R2 R2 R2
R3, A4 R3 R3 R3 R3 R3
R4, V1 R4 R4 R4 R4 R4
R5, V2 R5 R5 R5 R5 R5
R6, V3 R6 R6 R6 R6 R6
R7,V4 R7 R7 R7 R7 R7
R8,V5 R8 R8 R8 R8 R8 _FIQ
R9, V6 R9 R9 R9 R9 R9_ FIQ
R10,V7 R10 R10 R10 R10 R10_ FIQ
R11, V8 R11 R11 R11 R11 R11_ FIQ
R12, ip R12 R12 R12 R12 R12_ FIQ
R13, sp R13_ SVC R13_ ABORT R13 _UNDEF R13_ IRQ R13_ FIQ
R14, lr R14 _SVC R14_ ABORT R14 _UNDEF R14_ IRQ R14_ FIQ
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 17/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
Registers
REGISTERS
REGISTERS
Program counter (PC or R15) is accessible to all the modes. PC
• Program
points counter being
to the instruction is seen by allfrom
fetched modes
the memory. PC is
Programbycounter
•incremented is
4 after eachseen by all
instructionmodes
fetch.
Mode
User/System Supervisor Mode
Abort Undefined Interrupt Fast Interrupt
User/System
R15(PC) Supervisor
R15(PC) Abort
R15(PC) Undefined
R15(PC) Interrupt
R15(PC) FastR15(PC)
Interrupt
R15(PC) R15(PC) R15(PC) R15(PC) R15(PC) R15(PC)
•modes.
modes. CPSR stores useful information about the current status of
the Supervisor,
processor. All 5Abort, Undefined,
privileged Interrupt,
modes except the systemand Fasthave
mode
Supervisor,
•theirInterrupt Abort,
modes Undefined,
have their Interrupt,
own Saved
own Saved Program Status Register (SPSR) whose
and
ProgramFast
Interrupt
Status
purpose
modes have their
is toRegister(SPSR)
preserve the current
own Saved
in status
addition Program
to processor
of the access toduring
Status
CPSR,
switching
Register(SPSR)
whichmodes.
between
in addition
common to all modes. to access to
CPSR, which common to all modes.
Mode
User/System Supervisor Mode
Abort Undefined Interrupt Fast Interrupt
User/System
CPSR Supervisor
CPSR Abort
CPSR Undefined
CPSR Interrupt
CPSR FastCPSR
Interrupt
CPSR CPSR
SPSR _SVC CPSR
SPSR_ABORTCPSR
SPSR _UNDEF CPSR
SPSR_ IRQ CPSR
SPSR_ FIQ
19 SPSRSystems
_SVC and ARM
SPSR_ABORT
Introduction to Embedded Architecture SPSR ELEC
_UNDEF
2142 - SPSR_
Week 1IRQ SPSR_ FIQ 18/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
Registers
Example 1
If the processor switches from user mode to supervisor mode (e.g.
due to a power reset or software interrupt)- R0-R12 will be kept
intact, R13 and R14 in the user mode will be swapped with two
different registers R13 SVC and R14 SVC, respectively. PC will be
the same. CPSR is copied to SPSR SVC for later retrieval.
Example 2
Now, while the processor is in the supervisor mode, if a fast
interrupt comes along the mode will be switched to FIQ. R0-R7
will be kept intact, R8-R14 will be swapped with R8 FIQ -
R14 FIQ, respectively, and CPSR will be saved in the SPSR FIQ.
Q: Why does the FIQ mode have more registers swapping?
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 19/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 20/40
Program Counter (PC) and 3-Stage Pipeline
Pipelining is the process of dividing a given task into a number
of sub-tasks of lower complexity that can be performed in
parallel to achieve increased real-time throughput.
ARM7TDMI is a 3-stage pipelined architecture. The 3 stages
are Fetch, Decode, and Execute.
During cycle i, instruction pointed by PC is fetched, while the
REGISTERS
instruction fetched during the cycle i − 1 is being decoded and
The ARM7TDMI
the• instruction decodedisduring
a pipelined
cyclearchitecture,
i − 1 (that isthat is,
fetched
while one instruction is being fetched,
during the cycle i − 2) is being executed. another is
being decode, and yet again another one is being
Uponexecuted
each fetch, PC is automatically incremented by 4.
Program
Program Status
Status Registers Register
- CPSR/SPSR
• Both CPSR and SPSR have the following format
gram 31Status Register
30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Vector Table
Vector table contains vector addresses that contain instructions
relevant to exception handling. When an exception occurs, the PC
is changed to the corresponding vector address, thereby fetching
the nextTHE VECTOR
instruction TABLE
from the vector table. For ARM7TDMI
architecture, these vector addresses contain branch instructions to
• The vector table ( exception vector table) shows
the corresponding exception
external memory handler,
address except for
locations thatthe exceptions of
hold
type fastinformation that is necessary to handle exceptions.
interrupt (FIQ).
The Exception Vector Table
Exception Type Mode Vector Address
Reset SVC 0x00000000
Undefined instructions UNDEF 0x00000004
Software Interrupt (SWI) SVC 0x00000008
Prefetch abort (instruction fetch memory ABORT 0x0000000C
abort)
Data abort (data access memory abort) ABORT 0x00000010
IRQ (interrupt) IRQ 0x00000018
FIQ (fast interrupt) FIQ 0x0000001C
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 23/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
ARM Tools
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 26/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
stop B stop
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 28/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
ASSEMBLY
Assembly PROGRAM
Language Examples EXAMPLE
• After
Assembly being assembled
to machine and converted to machine
code mapping
code,
0x00000011
MOV r0, #0x11 0x00000000
0x00000000
36
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 29/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
Onto B BUS (
from decode
stage) through a
barrel shifter ( No
shift occurs in this
case) then
through 32-bit
ALU and ALU BUS
to r0
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 30/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
r0 from register
bank onto B BUS
through a barrel
shifter (shift
occurs in this
case, shift by one
position to left)
then through 32-
bit ALU and ALU
BUS to r1
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 31/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
r1 from register
bank onto B BUS
through a barrel
shifter (shift
occurs in this
case, shift by one
position to left)
then through 32-
bit ALU and ALU
BUS to r2
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 32/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
0xFFFFFE onto B
BUS through a
barrel shifter ( shift
left by 2 positions)
and PC value onto A
BUS then through
32-bit ALU and ALU
BUS to the address
register
Assembler uses
the PC value to
create an address (
that replaces label)
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 33/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
Note that the label stop refers to the memory address 0x0000000C
(labels are resolved into actual addresses by the linker). In order to
branch back to the label stop, PC should be changed to
0x0000000C from its current value 0x00000014. That is, PC
should become PC-8. We call this as a PC relative branch with
effective offset -8.
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 34/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 35/40
ASSEMBLY PROGRAM EXAMPLE
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
stop B stop No
END
END
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 36/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 38/40
ASSEMBLY PROGRAM EXAMPLE
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
stop B stop
END
46
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 39/40
Introduction ARM7TDMI Programmer’s Model Instructions & Tools Assembly Examples
0xF631024C
LDR r0, =0XF631024C 0x00000000
0xF631024C
LDR r1, =0X17539ABD
0x17539ABD
0xE16298F1
EOR r0, r0, r1
0x17539ABD
Introduction to Embedded Systems and ARM Architecture ELEC 2142 - Week 1 40/40