ARM7TDMI Processor
ARM7TDMI Processor
ARM7TDMI Processor
ARM7TDMI processor
The ARM7TDMI processor is a member of the Advanced RISC machine family of general purpose 32-bit microprocessor What does mean ARM7TDMI ?
ARM7 - 32-bit Advanced RISC Machine T - Thumb architecture extension
Two separate instruction sets, 32-bit ARM instructions and 16-bit Thumb instructions
32-bit Data Bus 32-bit Address Bus 37 32-bit registers 32-bit ARM instruction set 16-bit THUMB instruction set 32x8 Multiplier
Barrel Shifter
Switching state
Entering THUMB state
BX instruction with the state bit (bit 0) set in the operand register. Automatically on return from an exception (IRQ, FIQ, ABORT, SWI,), if the exception was entered with the processor in THUMB state.
Mode changes may be made under software control, or may be brought about by external interrupts or exception processing.
Most application programs will execute in User mode. The non-user modes' known as privileged modes-are entered in order to service interrupts or exceptions, or to access protected resources.
5
ARM7TDMI Registers
The ARM7TDMI has a total of 37 registers:
31 general-purpose 32-bit registers 6 status registers
These registers cannot all be seen at once. The processor state and operating mode dictate which registers are available to the programmer.
10
Control Bits
The I, F, T and M[4:0]) bits will be changed when an exception arises. If the processor is operating in a privileged mode, they can also be manipulated by software. T bit:
This reflects the operating state. When this bit is set, the processor is executing in THUMB state, otherwise it is executing in ARM state. This is reflected on the TBIT external signal. Note that the software must never change the state of the TBIT in the CPSR. If this happens, the processor will enter an unpredictable state.
11
Mode bits:
The M4, M3, M2, M1 and M0 bits (M[4:0]) are the mode bits. These determine the processor's operating mode. Not all combinations of the mode bits define a valid processor mode. Only those explicitly described shall be used. The user should be aware that if any illegal value is programmed into the mode bits, M[4:0], then the processor will enter an unrecoverable state. If this occurs, reset should be applied.
12
Exceptions (1/6)
Exceptions arise whenever the normal flow of a program has to be halted temporarily
For example to service an interrupt from a peripheral.
ARM supports 7 types of exception and has a privileged processor mode for each type of exception. ARM Exception vectors
Address 0x00000000 0x00000004 0x00000008 0x0000000C 0x00000010 0x00000014 0x00000018 0x0000001C Reset Undefined instruction Software Interrupt Abort (prefetch) Abort (data) Reserved IRQ FIQ Exception Mode in Entry Supervisor Undefined Supervisor Abort Abort Reserved IRQ FIQ
13
Exceptions (2/6)
When handling an exception, the ARM7TDMI:
Preserves the address of the next instruction in the appropriate Link Register Copies the CPSR into the appropriate SPSR Forces the CPSR mode bits to a value which depends on the exception Forces the PC to fetch the next instruction from the relevant exception vector It may also set the interrupt disable flags to prevent otherwise unmanageable nestings of exceptions. If the processor is in THUMB state when an exception occurs, it will automatically switch into ARM state when the PC is loaded with the exception vector address.
14
Exceptions (3/6)
On completion, the exception handler:
Moves the Link Register, minus an offset where appropriate, to the PC. (The offset will vary depending on the type of exception.) Copies the SPSR back to the CPSR Clears the interrupt disable flags, if they were set on entry
15
Exceptions (4/6)
Reset
When the processors Reset input is asserted
CPSR Supervisor + I + F PC 0x00000000
Undefined Instruction
If an attempt is made to execute an instruction that is undefined
LR_undef Undefined Instruction Address + #4 PC 0x00000004, CPSR Undefined + I Return with : MOVS pc, lr
Prefetch Abort
Instruction fetch memory abort, invalid fetched instruction
LR_abt Aborted Instruction Address + #4, SPSR_abt CPSR PC 0x0000000C, CPSR Abort + I Return with : SUBS pc, lr, #4
16
Exceptions (5/6)
Data Abort
Data access memory abort, invalid data
LR_abt Aborted Instruction + #8, SPSR_abt CPSR PC 0x00000010, CPSR Abort + I Return with : SUBS pc, lr, #4 or SUBS pc, lr, #8
Software Interrupt
Enters Supervisor mode
LR_svc SWI Address + #4, SPSR_svc CPSR PC 0x00000008, CPSR Supervisor + I Return with : MOV pc, lr
17
Exceptions (6/6)
Interrupt Request
Externally generated by asserting the processors IRQ input
LR_irq PC - #4, SPSR_irq CPSR PC 0x00000018, CPSR Interrupt + I Return with : SUBS pc, lr, #4
18
Summary
20
21
22
A subroutine call is a variant of the standard branch, the Branch with Link instruction preserves the address of the instruction after the branch (the return address) in register 14 (link register or LR). A load instruction provides a way to branch anywhere in the 4Gbyte address space. A 32-bit value is loaded directly from memory into the PC, causing a branch. The ARM7TDMI processor that support the Thumb instruction set also support a branch instruction (BX) that jumps to a given address, and optionally switches executing Thumb instructions.
23
Examples
B BCC BEQ label label label ; branch unconditionally to label ; branch to label if carry flag is clear ; branch to label if zero flag is set ; R15 = 0, branch to location zero ; subroutine call to function
func
; R15=R14, return to instruction after the BL ; store the address of the instruction after the next one into R14 ; load a 32-bit value into the program counter
24
25
26
All multiply instructions take two register operands as the input to the multiplier
ARM does not directly support a multiply by constant instruction due to the efficiency of shift and add, or shift and reverse subtract instructions There are two multiply instructions that produce 32-bit results MUL, multiplies the values of two registers together, truncates the result to 32 bits, and stores the result in a third register. MLA, multiplies the values of two registers together, adds the value of a third register, truncates the result to 32 bits, and stores the result into a fourth register (multiply and accumulate)
MUL MULS MLA R4, R2, R1 R4, R2, R1 R7, R8, R9, R3 ; Set R4 to value of R2 multiplied by R1 ; R4 = R2xR1, set N and Z flags ; R7 = R8xR9 + R3
27
28
The bottom 24 bits of the instruction are ignored by the processor, and may be used to communicate information to the supervisor code.
31
Summary
33
The core needs to know whether it is reading Thumb instructions or ARM instructions.
Core has two execution states - ARM and Thumb Core does not have a mixed 16 and 32 bit instruction set.
34
Always condition
Major opcode
Minor opcode
31 1110
28 00 1
24
21 20 19 0
16 15 Rd 0
12 Rd
11 0000
7 Constant
0100 1
I op1+op2 S
ARM: ADDS Rd, Rd, #Constant
35
Branch Instructions
Thumb supports four types of branch instruction:
an unconditional branch that allows a forward or backward branch of up to 2Kbytes a conditional branch to allow forward and backward branches of up to 256 bytes a branch with link is supported with a pair of instructions that allow forward and backwards branches of up to 4Mbytes a branch and exchange instruction branches to an address in a register and optionally switches to ARM code execution
37
38
39
ARM vs THUMB
Code size
Generally, routines in THUMB code are between 65 and 70% the size of the equivalent ARM code.
60%
65%
70%
75%
41
42
Specific memory access instructions with powerful auto-indexing addressing modes 32 bit ,16 bit and 8 bit data types Flexible multiple register load and store instructions
43
Gives....
Long branch range Powerful arithmetic operations Large address space
44