Part Number Hot Search : 
SMAJ400A E007933 22001 E002701 22001 ZTX650 S5295J 4608U102
Product Description
Full Text Search
 

To Download ARM7TDMI Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  advanced risc machines arm document number:arm ddi 0029e issued: august 1995 copyright advanced risc machines ltd (arm) 1995 all rights reserved arm 7tdmi data sheet open access proprietary notice arm, the arm powered logo, embeddedice, blackice and icebreaker are trademarks of advanced risc machines ltd. neither the whole nor any part of the information contained in, or the product described in, this datasheet may be adapted or reproduced in any material form except with the prior written permission of the copyright holder. the product described in this datasheet is subject to continuous developments and improvements. all particulars of the product and its use contained in this datasheet are given by arm in good faith. however, all warranties implied or expressed, including but not limited to implied warranties or merchantability, or fitness for purpose, are excluded. this datasheet is intended only to assist the reader in the use of the product. arm ltd shall not be liable for any loss or damage arising from the use of any information in this datasheet, or any error or omission in such information, or any incorrect use of the product. change log issue date by change a (draft 0.1) sept 1994 eh/bjh created. (draft 0.2) oct 1994 eh first pass review comments added. b dec 1994 eh/aw first formal release c dec 1994 aw further review comments mar 1995 aw reissued with open access status. no change to the content. d draft1 mar 1995 aw changes in line with the arm7tdm datasheet. further technical changes. d mar 1995 aw review comments added. e aug 1995 ap signals added plus minor changes.
ii ARM7TDMI data sheet arm ddi 0029e open access key: open access no confidentiality to enable document tracking, the document number has two codes: major release - pre-release a first release b second release etc etc draft status full and complete draft1 first draft draft2 second draft etc etc e embargoed (date given)
ARM7TDMI data sheet arm ddi 0029e contents-i 11 1 open access 1 introduction 1-1 1.1 introduction 1-2 1.2 ARM7TDMI architecture 1-2 1.3 ARM7TDMI block diagram 1-4 1.4 ARM7TDMI core diagram 1-5 1.5 ARM7TDMI functional diagram 1-6 2 signal description 2-1 2.1 signal description 2-2 3 programmers model 3-1 3.1 processor operating states 3-2 3.2 switching state 3-2 3.3 memory formats 3-2 3.4 instruction length 3-3 3.5 data types 3-3 3.6 operating modes 3-4 3.7 registers 3-4 3.8 the program status registers 3-8 3.9 exceptions 3-10 3.10 interrupt latencies 3-14 3.11 reset 3-15 contents toc
contents ARM7TDMI data sheet arm ddi 0029e contents-ii open access 4 arm instruction set 4-1 4.1 instruction set summary 4-2 4.2 the condition field 4-5 4.3 branch and exchange (bx) 4-6 4.4 branch and branch with link (b, bl) 4-8 4.5 data processing 4-10 4.6 psr transfer (mrs, msr) 4-18 4.7 multiply and multiply-accumulate (mul, mla) 4-23 4.8 multiply long and multiply-accumulate long (mull,mlal) 4-25 4.9 single data transfer (ldr, str) 4-28 4.10 halfword and signed data transfer 4-34 4.11 block data transfer (ldm, stm) 4-40 4.12 single data swap (swp) 4-47 4.13 software interrupt (swi) 4-49 4.14 coprocessor data operations (cdp) 4-51 4.15 coprocessor data transfers (ldc, stc) 4-53 4.16 coprocessor register transfers (mrc, mcr) 4-57 4.17 undefined instruction 4-60 4.18 instruction set examples 4-61 5 thumb instruction set 5-1 5.1 format 1: move shifted register 5-5 5.2 format 2: add/subtract 5-7 5.3 format 3: move/compare/add/subtract immediate 5-9 5.4 format 4: alu operations 5-11 5.5 format 5: hi register operations/branch exchange 5-13 5.6 format 6: pc-relative load 5-16 5.7 format 7: load/store with register offset 5-18 5.8 format 8: load/store sign-extended byte/halfword 5-20 5.9 format 9: load/store with immediate offset 5-22 5.10 format 10: load/store halfword 5-24 5.11 format 11: sp-relative load/store 5-26 5.12 format 12: load address 5-28 5.13 format 13: add offset to stack pointer 5-30 5.14 format 14: push/pop registers 5-32 5.15 format 15: multiple load/store 5-34 5.16 format 16: conditional branch 5-36 5.17 format 17: software interrupt 5-38
contents ARM7TDMI data sheet arm ddi 0029e contents-iii open access 5.18 format 18: unconditional branch 5-39 5.19 format 19: long branch with link 5-40 5.20 instruction set examples 5-42 6 memory interface 6-1 6.1 overview 6-2 6.2 cycle types 6-2 6.3 address timing 6-4 6.4 data transfer size 6-9 6.5 instruction fetch 6-10 6.6 memory management 6-12 6.7 locked operations 6-12 6.8 stretching access times 6-12 6.9 the arm data bus 6-13 6.10 the external data bus 6-15 7 coprocessor interface 7-1 7.1 overview 7-2 7.2 interface signals 7-2 7.3 register transfer cycle 7-3 7.4 privileged instructions 7-3 7.5 idempotency 7-4 7.6 undefined instructions 7-4 8 debug interface 8-1 8.1 overview 8-2 8.2 debug systems 8-2 8.3 debug interface signals 8-3 8.4 scan chains and jtag interface 8-6 8.5 reset 8-8 8.6 pullup resistors 8-9 8.7 instruction register 8-9 8.8 public instructions 8-9 8.9 test data registers 8-12 8.10 ARM7TDMI core clocks 8-18 8.11 determining the core and system state 8-19 8.12 the pcs behaviour during debug 8-23 8.13 priorities / exceptions 8-25 8.14 scan interface timing 8-26 8.15 debug timing 8-30
contents ARM7TDMI data sheet arm ddi 0029e contents-iv open access 9 icebreaker module 9-1 9.1 overview 9-2 9.2 the watchpoint registers 9-3 9.3 programming breakpoints 9-6 9.4 programming watchpoints 9-8 9.5 the debug control register 9-9 9.6 debug status register 9-10 9.7 coupling breakpoints and watchpoints 9-11 9.8 disabling icebreaker 9-13 9.9 icebreaker timing 9-13 9.10 programming restriction 9-13 9.11 debug communications channel 9-14 10 instruction cycle operations 10-1 10.1 introduction 10-2 10.2 branch and branch with link 10-2 10.3 thumb branch with link 10-3 10.4 branch and exchange (bx) 10-3 10.5 data operations 10-4 10.6 multiply and multiply accumulate 10-6 10.7 load register 10-8 10.8 store register 10-9 10.9 load multiple registers 10-9 10.10 store multiple registers 10-11 10.11 data swap 10-11 10.12 software interrupt and exception entry 10-12 10.13 coprocessor data operation 10-13 10.14 coprocessor data transfer (from memory to coprocessor) 10-14 10.15 coprocessor data transfer (from coprocessor to memory) 10-15 10.16 coprocessor register transfer (load from coprocessor) 10-16 10.17 coprocessor register transfer (store to coprocessor) 10-17 10.18 undefined instructions and coprocessor absent 10-18 10.19 unexecuted instructions 10-18 10.20 instruction speed summary 10-19 11 dc parameters 11-1 11.1 absolute maximum ratings 11-2 11.2 dc operating conditions 11-2
contents ARM7TDMI data sheet arm ddi 0029e contents-v open access 12 ac parameters 12-1 12.1 introduction 12-2 12.2 notes on ac parameters 12-11
contents ARM7TDMI data sheet arm ddi 0029e contents-vi open access
ARM7TDMI data sheet arm ddi 0029e 1-1 11 1 open access introduction this chapter introduces the ARM7TDMI architecture, and shows block, core, and functional diagrams for the ARM7TDMI. 1.1 introduction 1-2 1.2 ARM7TDMI architecture 1-2 1.3 ARM7TDMI block diagram 1-4 1.4 ARM7TDMI core diagram 1-5 1.5 ARM7TDMI functional diagram 1-6 1
introduction ARM7TDMI data sheet arm ddi 0029e 1-2 open access 1.1 introduction the ARM7TDMI is a member of the advanced risc machines (arm) family of general purpose 32-bit microprocessors, which offer high performance for very low power consumption and price. the arm architecture is based on reduced instruction set computer (risc) principles, and the instruction set and related decode mechanism are much simpler than those of microprogrammed complex instruction set computers. this simplicity results in a high instruction throughput and impressive real-time interrupt response from a small and cost-effective chip. pipelining is employed so that all parts of the processing and memory systems can operate continuously. typically , while one instruction is being executed, its successor is being decoded, and a third instruction is being fetched from memory. the arm memory interface has been designed to allow the performance potential to be realised without incurring high costs in the memory system. speed-critical control signals are pipelined to allow system control functions to be implemented in standard low-power logic, and these control signals facilitate the exploitation of the fast local access modes offered by industry standard dynamic rams. 1.2 ARM7TDMI architecture the ARM7TDMI processor employs a unique architectural strategy known as thumb , which makes it ideally suited to high-volume applications with memory restrictions, or applications where code density is an issue. 1.2.1 the thumb concept the key idea behind thumb is that of a super-reduced instruction set. essentially , the ARM7TDMI processor has two instruction sets: ? the standard 32-bit arm set ? a 16-bit thumb set the thumb sets 16-bit instruction length allows it to approach twice the density of standard arm code while retaining most of the arm s performance advantage over a traditional 16-bit processor using 16-bit registers. this is possible because thumb code operates on the same 32-bit register set as arm code. thumb code is able to provide up to 65% of the code size of arm, and 160% of the performance of an equivalent arm processor connected to a 16-bit memory system.
introduction ARM7TDMI data sheet arm ddi 0029e 1-3 open access 1.2.2 thumbs advantages thumb instructions operate with the standard arm register con?guration, allowing excellent interoperability between arm and thumb states. each 16-bit thumb instruction has a corresponding 32-bit arm instruction with the same effect on the processor model. the major advantage of a 32-bit (arm) architecture over a 16-bit architecture is its ability to manipulate 32-bit integers with single instructions, and to address a large address space ef?ciently . when processing 32-bit data, a 16-bit architecture will take at least two instructions to perform the same task as a single arm instruction. however , not all the code in a program will process 32-bit data (for example, code that performs character string handling), and some instructions, like branches, do not process any data at all. if a 16-bit architecture only has 16-bit instructions, and a 32-bit architecture only has 32-bit instructions, then overall the 16-bit architecture will have better code density, and better than one half the performance of the 32-bit architecture. clearly 32-bit performance comes at the cost of code density. thumb breaks this constraint by implementing a 16-bit instruction length on a 32-bit architecture, making the processing of 32-bit data ef ?cient with a compact instruction coding. this provides far better performance than a 16-bit architecture, with better code density than a 32-bit architecture. thumb also has a major advantage over other 32-bit architectures with 16-bit instructions. this is the ability to switch back to full arm code and execute at full speed. thus critical loops for applications such as ? fast interrupts ? dsp algorithms can be coded using the full arm instruction set, and linked with thumb code. the overhead of switching from thumb code to arm code is folded into sub-routine entry time. various portions of a system can be optimised for speed or for code density by switching between thumb and arm execution as appropriate.
introduction ARM7TDMI data sheet arm ddi 0029e 1-4 open access 1.3 ARM7TDMI block diagram figure 1-1: ARM7TDMI block diagram ? ? scan chain 0 a[31:0] core scan chain 1 d[31:0] nopc nrw all other signals tck tms tdi ntrst tdo extern1 extern0 ntrans nmreq scan chain 2 icebreaker tap controller mas[1:0] bus splitter din[31:0] dout[31:0] rangeout1 rangeout0 tapsm[3:0] ir[3:0] screg[3:0]
introduction ARM7TDMI data sheet arm ddi 0029e 1-5 open access 1.4 ARM7TDMI core diagram figure 1-2: ARM7TDMI core nreset nmreq seq abort nirq nfiq nrw lock ncpi cpa cpb nwait mclk nopc ntrans instruction decoder & control logic instruction pipeline & read data register dbe d[31:0] 32-bit alu barrel shifter address incrementer address register register bank (31 x 32-bit registers) (6 status registers) a[31:0] ale multiplier abe write data register nm[4:0] 32 x 8 nenout nenin tbe scan control breakpti dbgrqi nexec dbgack eclk isync b b u s a l u b u s a b u s p c b u s i n c r e m e n t e r b u s ape bl[3:0] mas[1:0] tbit highz & thumb instruction decoder
introduction ARM7TDMI data sheet arm ddi 0029e 1-6 open access 1.5 ARM7TDMI functional diagram figure 1-3: ARM7TDMI functional diagram lock a[31:0] abort memory management nopc ncpi cpa cpb coprocessor interface ntrans memory interface interface d[31:0] tck tms tdi ntrst boundary scan tdo processor mode nrw nmreq seq bl[3:0] mas[1:0] ape tbit processor state nm[4:0] ARM7TDMI din[31:0] dout[31:0] tapsm[3:0] ir[3:0] boundary scan tck1 tck2 11 control signals ntdoen screg[3:0] abe ale nirq nfiq bus interrupts isync nreset mclk nwait clocks vdd vss power dbgrq breakpt dbgack nexec debug controls extern 1 dbe tbe extern 0 nenout nenin eclk dbgen ape highz bigend busen rangeout0 rangeout1 dbgrqi commrx commtx nenouti ecapclk busdis
ARM7TDMI data sheet arm ddi 0029e 2-1 11 1 open access signal description this chapter lists and describes the signals for the ARM7TDMI. 2.1 signal description 2-2 2
signal description ARM7TDMI data sheet arm ddi 0029e 2-2 open access 2.1 signal description the following table lists and describes all the signals for the ARM7TDMI. transistor sizes for a 0.6 m m ARM7TDMI: inv4 driver has transistor sizes of p = 22.32 m m/0.6 m m n = 12.6 m m/0.6 m m inv8 driver has transistor sizes of p = 44.64 m m/0.6 m m n = 25.2 m m/0.6 m m key to signal types ic input cmos thresholds p power o4 output with inv4 driver o8 output with inv8 driver name type description a[31:0] addresses 08 this is the processor address bus. if ale (address latch enable) is high and ape (address pipeline enable) is low, the addresses become valid during phase 2 of the cycle before the one to which they refer and remain so during phase 1 of the referenced cycle. their stable period may be controlled by ale or ape as described below. abe address bus enable ic this is an input signal which, when low, puts the address bus drivers into a high impedance state. this signal has a similar effect on the following control signals: mas[1:0] , nrw , lock , nopc and ntrans . abe must be tied high when there is no system requirement to turn off the address drivers. abort memory abort ic this is an input which allows the memory system to tell the processor that a requested access is not allowed. ale address latch enable. ic this input is used to control transparent latches on the address outputs. normally the addresses change during phase 2 to the value required during the next cycle, but for direct interfacing to roms they are required to be stable to the end of phase 2. taking ale low until the end of phase 2 will ensure that this happens. this signal has a similar effect on the following control signals: mas[1:0] , nrw , lock , nopc and ntrans . if the system does not require address lines to be held in this way, ale must be tied high. the address latch is static, so ale may be held low for long periods to freeze addresses. table 2-1: signal description
signal description ARM7TDMI data sheet arm ddi 0029e 2-3 open access ape address pipeline enable. ic when high, this signal enables the address timing pipeline. in this state, the address bus plus mas[1:0] , nrw , ntrans , lock and nopc change in the phase 2 prior to the memory cycle to which they refer. when ape is low, these signals change in the phase 1 of the actual cycle. please refer to chapter 6, memory interface for details of this timing. bigend big endian configuration. ic when this signal is high the processor treats bytes in memory as being in big endian format. when it is low, memory is treated as little endian. bl[3:0] byte latch control. ic these signals control when data and instructions are latched from the external data bus. when bl[3] is high, the data on d[31:24] is latched on the falling edge of mclk . when bl[2 ] is high, the data on d[23:16] is latched and so on. please refer to chapter 6, memory interface for details on the use of these signals. breakpt breakpoint. ic this signal allows external hardware to halt the execution of the processor for debug purposes. when high causes the current memory access to be breakpointed. if the memory access is an instruction fetch, ARM7TDMI will enter debug state if the instruction reaches the execute stage of the ARM7TDMI pipeline. if the memory access is for data, ARM7TDMI will enter debug state after the current instruction completes execution.this allows extension of the internal breakpoints provided by the icebreaker module. see chapter 9, icebreaker module . busdis bus disable o this signal is high when intest is selected on scan chain 0 or 4 and may be used to disable external logic driving onto the bidirectional data bus during scan testing. this signal changes on the falling edge of tck . busen data bus configuration ic this is a static configuration signal which determines whether the bidirectional data bus, d[31:0] , or the unidirectional data busses, din[31:0] and dout[31:0] , are to be used for transfer of data between the processor and memory. refer also to chapter 6, memory interface . when busen is low, the bidirectional data bus, d[31:0] is used. in this case, dout[31:0] is driven to value 0x00000000, and any data presented on din[31:0] is ignored. when busen is high, the bidirectional data bus, d[31:0] is ignored and must be left unconnected. input data and instructions are presented on the input data bus, din[31:0] , output data appears on dout[31:0] . commrx communications channel receive o when high, this signal denotes that the comms channel receive buffer is empty. this signal changes on the rising edge of mclk . see 9.11 debug communications channel on page 9-14 for more information on the debug comms channel. name type description table 2-1: signal description (continued)
signal description ARM7TDMI data sheet arm ddi 0029e 2-4 open access commtx communications channel transmit o when high, this signal denotes that the comms channel transmit buffer is empty. this signal changes on the rising edge of mclk . see 9.11 debug communications channel on page 9-14 for more information on the debug comms channel. cpa coprocessor absent. ic a coprocessor which is capable of performing the operation that ARM7TDMI is requesting (by asserting ncpi ) should take cpa low immediately. if cpa is high at the end of phase 1 of the cycle in which ncpi went low, ARM7TDMI will abort the coprocessor handshake and take the undefined instruction trap. if cpa is low and remains low, ARM7TDMI will busy-wait until cpb is low and then complete the coprocessor instruction. cpb coprocessor busy. ic a coprocessor which is capable of performing the operation which ARM7TDMI is requesting (by asserting ncpi ), but cannot commit to starting it immediately, should indicate this by driving cpb high. when the coprocessor is ready to start it should take cpb low. ARM7TDMI samples cpb at the end of phase 1 of each cycle in which ncpi is low. d[31:0] data bus. ic 08 these are bidirectional signal paths which are used for data transfers between the processor and external memory. during read cycles (when nrw is low), the input data must be valid before the end of phase 2 of the transfer cycle. during write cycles (when nrw is high), the output data will become valid during phase 1 and remain valid throughout phase 2 of the transfer cycle. note that this bus is driven at all times, irrespective of whether busen is high or low. when d[31:0] is not being used to connect to the memory system it must be left unconnected. see chapter 6, memory interface . dbe data bus enable. ic this is an input signal which, when driven low, puts the data bus d[31:0] into the high impedance state. this is included for test purposes, and should be tied high at all times. dbgack debug acknowledge. 04 when high indicates arm is in debug state. dbgen debug enable. ic this input signal allows the debug features of ARM7TDMI to be disabled. this signal should be driven low when debugging is not required. dbgrq debug request. ic this is a level-sensitive input, which when high causes ARM7TDMI to enter debug state after executing the current instruction. this allows external hardware to force ARM7TDMI into the debug state, in addition to the debugging features provided by the icebreaker block. see chapter 9, icebreaker module for details. name type description table 2-1: signal description (continued)
signal description ARM7TDMI data sheet arm ddi 0029e 2-5 open access dbgrqi internal debug reques t 04 this signal represents the debug request signal which is presented to the processor. this is the combination of external dbgrq , as presented to the ARM7TDMI macrocell, and bit 1 of the debug control register. thus there are two conditions where this signal can change. firstly, when dbgrq changes, dbgrqi will change after a propagation delay. when bit 1 of the debug control register has been written, this signal will change on the falling edge of tck when the tap controller state machine is in the run-test/idle state. see chapter 9, icebreaker module for details. din[31:0] data input bus ic this is the input data bus which may be used to transfer instructions and data between the processor and memory.this data input bus is only used when busen is high. the data on this bus is sampled by the processor at the end of phase 2 during read cycles (i.e. when nrw is low). dout[31:0] data output bus 08 this is the data out bus, used to transfer data from the processor to the memory system. output data only appears on this bus when busen is high. at all other times, this bus is driven to value 0x00000000. when in use, data on this bus changes during phase 1 of store cycles (i.e. when nrw is high) and remains valid throughout phase 2. drivebs boundary scan cell enable 04 this signal is used to control the multiplexers in the scan cells of an external boundary scan chain. this signal changes in the update-ir state when scan chain 3 is selected and either the intest, extest, clamp or clampz instruction is loaded. when an external boundary scan chain is not connected, this output should be left unconnected. ecapclk extest capture clock o this signal removes the need for the external logic in the test chip which was required to enable the internal tristate bus during scan testing. this need not be brought out as an external pin on the test chip. ecapclkbs extest capture clock for boundary scan 04 this is a tck2 wide pulse generated when the tap controller state machine is in the capture-dr state, the current instruction is extest and scan chain 3 is selected. this is used to capture the macrocell outputs during extest. when an external boundary scan chain is not connected, this output should be left unconnected. eclk external clock output. 04 in normal operation, this is simply mclk (optionally stretched with nwait ) exported from the core. when the core is being debugged, this is dclk . this allows external hardware to track when the arm7dm core is clocked. extern0 external input 0. ic this is an input to the icebreaker logic in the ARM7TDMI which allows breakpoints and/or watchpoints to be dependent on an external condition. name type description table 2-1: signal description (continued)
signal description ARM7TDMI data sheet arm ddi 0029e 2-6 open access extern1 external input 1. ic this is an input to the icebreaker logic in the ARM7TDMI which allows breakpoints and/or watchpoints to be dependent on an external condition. highz 04 this signal denotes that the highz instruction has been loaded into the tap controller. see chapter 8, debug interface for details. icapclkbs intest capture clock 04 this is a tck2 wide pulse generated when the tap controller state machine is in the capture-dr state, the current instruction is intest and scan chain 3 is selected. this is used to capture the macrocell outputs during intest. when an external boundary scan chain is not connected, this output should be left unconnected. ir[3:0] tap controller instruction register 04 these 4 bits reflect the current instruction loaded into the tap controller instruction register. the instruction encoding is as described in 8.8 public instructions on page 8-9 . these bits change on the falling edge of tck when the state machine is in the update-ir state. isync synchronous interrupts. ic when low indicates that the nirq and nfiq inputs are to be synchronised by the arm core. when high disables this synchronisation for inputs that are already synchronous. lock locked operation. 08 when lock is high, the processor is performing a locked memory access, and the memory controller must wait until lock goes low before allowing another device to access the memory. lock changes while mclk is high, and remains high for the duration of the locked memory accesses. it is active only during the data swap (swp) instruction. the timing of this signal may be modified by the use of ale and ape in a similar way to the address, please refer to the ale and ape descriptions. this signal may also be driven to a high impedance state by driving abe low. mas[1:0] memory access size. 08 these are output signals used by the processor to indicate to the external memory system when a word transfer or a half-word or byte length is required. the signals take the value 10 (binary) for words, 01 for half-words and 00 for bytes. 11 is reserved. these values are valid for both read and write cycles. the signals will normally become valid during phase 2 of the cycle before the one in which the transfer will take place. they will remain stable throughout phase 1 of the transfer cycle. the timing of the signals may be modified by the use of ale and ape in a similar way to the address, please refer to the ale and ape descriptions. the signals may also be driven to high impedance state by driving abe low. name type description table 2-1: signal description (continued)
signal description ARM7TDMI data sheet arm ddi 0029e 2-7 open access mclk memory clock input. ic this clock times all ARM7TDMI memory accesses and internal operations. the clock has two distinct phases - phase 1 in which mclk is low and phase 2 in which mclk (and nwait ) is high. the clock may be stretched indefinitely in either phase to allow access to slow peripherals or memory. alternatively, the nwait input may be used with a free running mclk to achieve the same effect. ncpi not coprocessor instruction. 04 when ARM7TDMI executes a coprocessor instruction, it will take this output low and wait for a response from the coprocessor. the action taken will depend on this response, which the coprocessor signals on the cpa and cpb inputs. nenin not enable input. ic this signal may be used in conjunction with nenout to control the data bus during write cycles. see chapter 6, memory interface . nenout not enable output. 04 during a data write cycle, this signal is driven low during phase 1, and remains low for the entire cycle. this may be used to aid arbitration in shared bus applications. see chapter 6, memory interface . nenouti not enable output. o during a coprocessor register transfer c-cycle from the icebreaker comms channel coprocessor to the arm core, this signal goes low during phase 1 and stays low for the entire cycle. this may be used to aid arbitration in shared bus systems. nexec not executed. 04 when high indicates that the instruction in the execution unit is not being executed, because for example it has failed its condition code check. nfiq not fast interrupt request. ic this is an interrupt request to the processor which causes it to be interrupted if taken low when the appropriate enable in the processor is active. the signal is level-sensitive and must be held low until a suitable response is received from the processor. nfiq may be synchronous or asynchronous, depending on the state of isync . nhighz not highz 04 this signal is generated by the tap controller when the current instruction is highz. this is used to place the scan cells of that scan chain in the high impedance state. when a external boundary scan chain is not connected, this output should be left unconnected. nirq not interrupt request. ic as nfiq , but with lower priority. may be taken low to interrupt the processor when the appropriate enable is active. nirq may be synchronous or asynchronous, depending on the state of isync . nm[4:0] not processor mode. 04 these are output signals which are the inverses of the internal status bits indicating the processor operation mode. name type description table 2-1: signal description (continued)
signal description ARM7TDMI data sheet arm ddi 0029e 2-8 open access nmreq not memory request. 04 this signal, when low, indicates that the processor requires memory access during the following cycle. the signal becomes valid during phase 1, remaining valid through phase 2 of the cycle preceding that to which it refers. nopc not op-code fetch. 08 when low this signal indicates that the processor is fetching an instruction from memory; when high, data (if present) is being transferred. the signal becomes valid during phase 2 of the previous cycle, remaining valid through phase 1 of the referenced cycle. the timing of this signal may be modified by the use of ale and ape in a similar way to the address, please refer to the ale and ape descriptions. this signal may also be driven to a high impedance state by driving abe low. nreset not reset. ic this is a level sensitive input signal which is used to start the processor from a known address. a low level will cause the instruction being executed to terminate abnormally. when nreset becomes high for at least one clock cycle, the processor will re-start from address 0. nreset must remain low (and nwait must remain high) for at least two clock cycles. during the low period the processor will perform dummy instruction fetches with the address incrementing from the point where reset was activated. the address will overflow to zero if nreset is held beyond the maximum address limit. nrw not read/write. 08 when high this signal indicates a processor write cycle; when low, a read cycle. it becomes valid during phase 2 of the cycle before that to which it refers, and remains valid to the end of phase 1 of the referenced cycle. the timing of this signal may be modified by the use of ale and ape in a similar way to the address, please refer to the ale and ape descriptions. this signal may also be driven to a high impedance state by driving abe low. ntdoen not tdo enable. 04 when low, this signal denotes that serial data is being driven out on the tdo output. ntdoen would normally be used as an output enable for a tdo pin in a packaged part. ntrans not memory translate. 08 when this signal is low it indicates that the processor is in user mode. it may be used to tell memory management hardware when translation of the addresses should be turned on, or as an indicator of non-user mode activity. the timing of this signal may be modified by the use of ale and ape in a similar way to the address, please refer to the ale and ape description. this signal may also be driven to a high impedance state by driving abe low. ntrst not test reset. ic active-low reset signal for the boundary scan logic. this pin must be pulsed or driven low to achieve normal device operation, in addition to the normal device reset (nreset) . for more information, see chapter 8, debug interface . name type description table 2-1: signal description (continued)
signal description ARM7TDMI data sheet arm ddi 0029e 2-9 open access nwait not wait. ic when accessing slow peripherals, ARM7TDMI can be made to wait for an integer number of mclk cycles by driving nwait low. internally, nwait is anded with mclk and must only change when mclk is low. if nwait is not used it must be tied high. pclkbs boundary scan update clock 04 this is a tck2 wide pulse generated when the tap controller state machine is in the update-dr state and scan chain 3 is selected. this is used by an external boundary scan chain as the update clock. when an external boundary scan chain is not connected, this output should be left unconnected. rangeout0 icebreaker rangeout0 04 this signal indicates that icebreaker watchpoint register 0 has matched the conditions currently present on the address, data and control busses. this signal is independent of the state of the watchpoints enable control bit. rangeout0 changes when eclk is low. rangeout1 icebreaker rangeout1 04 as rangeout0 but corresponds to icebreakers watchpoint register 1. rstclkbs boundary scan reset clock o this signal denotes that either the tap controller state machine is in the reset state or that ntrst has been asserted. this may be used to reset external boundary scan cells. screg[3:0] scan chain register o these 4 bits reflect the id number of the scan chain currently selected by the tap controller. these bits change on the falling edge of tck when the tap state machine is in the update-dr state. sdinbs boundary scan serial input data o this signal contains the serial data to be applied to an external scan chain and is valid around the falling edge of tck . sdoutbs boundary scan serial output data ic this control signal is provided to ease the connection of an external boundary scan chain. this is the serial data out of the boundary scan chain. it should be set up to the rising edge of tck . when an external boundary scan chain is not connected, this input should be tied low. seq sequential address. o4 this output signal will become high when the address of the next memory cycle will be related to that of the last memory access. the new address will either be the same as the previous one or 4 greater in arm state, or 2 greater in thumb state. the signal becomes valid during phase 1 and remains so through phase 2 of the cycle before the cycle whose address it anticipates. it may be used, in combination with the low-order address lines, to indicate that the next cycle can use a fast memory mode (for example dram page mode) and/or to bypass the address translation system. name type description table 2-1: signal description (continued)
signal description ARM7TDMI data sheet arm ddi 0029e 2-10 open access shclkbs boundary scan shift clock, phase 1 04 this control signal is provided to ease the connection of an external boundary scan chain. shclkbs is used to clock the master half of the external scan cells. when in the shift-dr state of the state machine and scan chain 3 is selected, shclkbs follows tck1 . when not in the shift-dr state or when scan chain 3 is not selected, this clock is low. when an external boundary scan chain is not connected, this output should be left unconnected. shclk2bs boundary scan shift clock, phase 2 04 this control signal is provided to ease the connection of an external boundary scan chain. shclk2bs is used to clock the master half of the external scan cells. when in the shift-dr state of the state machine and scan chain 3 is selected, shclk2bs follows tck2 . when not in the shift-dr state or when scan chain 3 is not selected, this clock is low. when an external boundary scan chain is not connected, this output should be left unconnected. tapsm[3:0] tap controller state machine 04 this bus reflects the current state of the tap controller state machine, as shown in 8.4.2 the jtag state machine on page 8-8 . these bits change off the rising edge of tck . tbe test bus enable. ic when driven low, tbe forces the data bus d[31:0] , the address bus a[31:0] , plus lock , mas[1:0] , nrw , ntrans and nopc to high impedance. this is as if both abe and dbe had both been driven low. however, tbe does not have an associated scan cell and so allows external signals to be driven high impedance during scan testing. under normal operating conditions, tbe should be held high at all times. tbit o4 when high, this signal denotes that the processor is executing the thumb instruction set. when low, the processor is executing the arm instruction set. this signal changes in phase 2 in the first execute cycle of a bx instruction. tck ic test clock. tck1 tck, phase 1 04 this clock represents phase 1 of tck . tck1 is high when tck is high, although there is a slight phase lag due to the internal clock non-overlap. tck2 tck, phase 2 04 this clock represents phase 2 of tck . tck2 is high when tck is low, although there is a slight phase lag due to the internal clock non-overlap. tck2 is the non-overlapping compliment of tck1 . tdi ic test data input. tdo test data output. o4 output from the boundary scan logic. tms ic test mode select. name type description table 2-1: signal description (continued)
signal description ARM7TDMI data sheet arm ddi 0029e 2-11 open access vdd power supply. p these connections provide power to the device. vss ground. p these connections are the ground reference for all signals. name type description table 2-1: signal description (continued)
signal description ARM7TDMI data sheet arm ddi 0029e 2-12 open access
ARM7TDMI data sheet arm ddi 0029e 3-1 11 1 open access programmers model this chapter describes the two operating states of the ARM7TDMI. 3.1 processor operating states 3-2 3.2 switching state 3-2 3.3 memory formats 3-2 3.4 instruction length 3-3 3.5 data types 3-3 3.6 operating modes 3-4 3.7 registers 3-4 3.8 the program status registers 3-8 3.9 exceptions 3-10 3.11 reset 3-15 3
programmers model ARM7TDMI data sheet arm ddi 0029e 3-2 open access 3.1 processor operating states from the programmers point of view, the ARM7TDMI can be in one of two states: arm state which executes 32-bit, word-aligned arm instructions. thumb state which operates with 16-bit, halfword-aligned thumb instructions. in this state, the pc uses bit 1 to select between alternate halfwords. note transition between these two states does not affect the processor mode or the contents of the registers. 3.2 switching state entering thumb state entry into thumb state can be achieved by executing a bx instruction with the state bit (bit 0) set in the operand register. transition to thumb state will also occur automatically on return from an exception (irq, fiq, undef , abor t , swi etc.), if the exception was entered with the processor in thumb state. entering arm state entry into arm state happens: 1 on execution of the bx instruction with the state bit clear in the operand register. 2 on the processor taking an exception (irq, fiq, reset, undef, abort, swi etc.). in this case, the pc is placed in the exception modes link register, and execution commences at the exceptions vector address. 3.3 memory formats ARM7TDMI views memory as a linear collection of bytes numbered upwards from zero. bytes 0 to 3 hold the ?rst stored word, bytes 4 to 7 the second and so on. ARM7TDMI can treat words in memory as being stored either in big endian or little endian format.
programmers model ARM7TDMI data sheet arm ddi 0029e 3-3 open access 3.3.1 big endian format in big endian format, the most signi?cant byte of a word is stored at the lowest numbered byte and the least signi?cant byte at the highest numbered byte. byte 0 of the memory system is therefore connected to data lines 31 through 24. 3.3.2 little endian format in little endian format, the lowest numbered byte in a word is considered the words least signi?cant byte, and the highest numbered byte the most signi?cant. byte 0 of the memory system is therefore connected to data lines 7 through 0. 3.4 instruction length instructions are either 32 bits long (in arm state) or 16 bits long (in thumb state). 3.5 data types ARM7TDMI supports byte (8-bit), halfword (16-bit) and word (32-bit) data types. w ords must be aligned to four-byte boundaries and half words to two-byte boundaries. higher address 31 24 23 16 15 8 7 0 word address 8 9 10 11 8 4 5 6 7 4 0 1 2 3 0 lower address ? most significant byte is at lowest address ? word is addressed by byte address of most significant byte figure 3-1: big endian addresses of bytes within words higher address 31 24 23 16 15 8 7 0 word address 11 10 9 8 8 7 6 5 4 4 3 2 1 0 0 lower address ? least significant byte is at lowest address ? word is addressed by byte address of least significant byte figure 3-2: little endian addresses of bytes within words
programmers model ARM7TDMI data sheet arm ddi 0029e 3-4 open access 3.6 operating modes ARM7TDMI supports seven modes of operation: user (usr): the normal arm program execution state fiq (?q): designed to support a data transfer or channel process irq (irq): used for general-purpose interrupt handling supervisor (svc): protected mode for the operating system abort mode (abt): entered after a data or instruction prefetch abort system (sys): a privileged user mode for the operating system unde?ned (und): entered when an unde?ned instruction is executed 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. 3.7 registers ARM7TDMI has a total of 37 registers - 31 general-purpose 32-bit registers and six status registers - but these cannot all be seen at once. the processor state and operating mode dictate which registers are available to the programmer. 3.7.1 the arm state register set in arm state, 16 general registers and one or two status registers are visible at any one time. in privileged (non-user) modes, mode-speci?c banked registers are switched in. figure 3-3: register organization in arm state shows which registers are available in each mode: the banked registers are marked with a shaded triangle. the arm state register set contains 16 directly accessible registers: r0 to r15. all of these except r15 are general-purpose, and may be used to hold either data or address values. in addition to these, there is a seventeenth register used to store status information register 14 is used as the subroutine link register . this receives a copy of r15 when a branch and link (bl) instruction is executed. at all other times it may be treated as a general-purpose register. the corresponding banked registers r14_svc, r14_irq, r14_?q, r14_abt and r14_und are similarly used to hold the return values of r15 when interrupts and exceptions arise, or when branch and link instructions are executed within interrupt or exception routines. register 15 holds the program counter (pc). in arm state, bits [1:0] of r15 are zero and bits [31:2] contain the pc. in thumb state, bit [0] is zero and bits [31:1] contain the pc. register 16 is the cpsr (current program status register). this contains condition code ?ags and the current mode bits.
programmers model ARM7TDMI data sheet arm ddi 0029e 3-5 open access fiq mode has seven banked registers mapped to r8-14 (r8_?q-r14_?q). in arm state, many fiq handlers do not need to save any registers. user, irq, supervisor, abort and unde?ned each have two banked registers mapped to r13 and r14, allowing each of these modes to have a private stack pointer and link registers. figure 3-3: register organization in arm state arm state general registers and program counter r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 (pc) r0 r1 r2 r3 r4 r5 r6 r7 r8_?q r9_?q r10_?q r11_?q r12_?q r13_?q r14_?q r15 (pc) r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13_svc r14_svc r15 (pc) r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13_abt r14_abt r15 (pc) r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13_irq r14_irq r15 (pc) r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13_und r14_und r15 (pc) system & user fiq supervisor abort irq unde?ned cpsr cpsr spsr_?q cpsr spsr_svc cpsr spsr_abt cpsr spsr_irq cpsr spsr_und arm state program status registers = banked register
programmers model ARM7TDMI data sheet arm ddi 0029e 3-6 open access 3.7.2 the thumb state register set the thumb state register set is a subset of the arm state set. the programmer has direct access to eight general registers, r0-r7, as well as the program counter (pc), a stack pointer register (sp), a link register (lr), and the cpsr. there are banked stack pointers, link registers and saved process status registers (spsrs) for each privileged mode. this is shown in figure 3-4: register organization in thumb state . figure 3-4: register organization in thumb state 3.7.3 the relationship between arm and thumb state registers the thumb state registers relate to the arm state registers in the following way: ? thumb state r0-r7 and arm state r0-r7 are identical ? thumb state cpsr and spsrs and arm state cpsr and spsrs are identical ? thumb state sp maps onto arm state r13 r0 r1 r2 r3 r4 r5 r6 r7 sp lr pc system & user fiq supervisor abort irq unde?ned cpsr cpsr spsr_?q cpsr spsr_svc cpsr spsr_abt cpsr spsr_irq cpsr spsr_und r0 r1 r2 r3 r4 r5 r6 r7 sp_?q lr_?q pc r0 r1 r2 r3 r4 r5 r6 r7 sp_svc lr_svc pc r0 r1 r2 r3 r4 r5 r6 r7 sp_abt lr_abt pc r0 r1 r2 r3 r4 r5 r6 r7 sp_irq lr_irq pc r0 r1 r2 r3 r4 r5 r6 r7 sp_und lr_und pc thumb state general registers and program counter thumb state program status registers = banked register
programmers model ARM7TDMI data sheet arm ddi 0029e 3-7 open access ? thumb state lr maps onto arm state r14 ? the thumb state program counter maps onto the arm state program counter (r15) this relationship is shown in figure 3-5: mapping of thumb state registers onto arm state registers . figure 3-5: mapping of thumb state registers onto arm state registers 3.7.4 accessing hi registers in thumb state in thumb state, registers r8-r15 (the hi registers ) are not part of the standard register set. however, the assembly language programmer has limited access to them, and can use them for fast temporary storage. a value may be transferred from a register in the range r0-r7 (a lo register ) to a hi register, and from a hi register to a lo register, using special variants of the mov instruction. hi register values can also be compared against or added to lo register values with the cmp and add instructions. see 5.5 format 5: hi register operations/ branch exchange on page 5-13. r0 r1 r2 r3 r5 r6 r7 r8 r9 r10 r11 r12 stack pointer (r13) link register (r14) program counter (r15) r0 r1 r2 r3 r5 r6 r7 stack pointer (sp) link register (lr) program counter (pc) cpsr cpsr spsr spsr thumb state arm state r4 r4 lo registers hi registers
programmers model ARM7TDMI data sheet arm ddi 0029e 3-8 open access 3.8 the program status registers the ARM7TDMI contains a current program status register (cpsr), plus ?ve saved program status registers (spsrs) for use by exception handlers. these registers ? hold information about the most recently performed alu operation ? control the enabling and disabling of interrupts ? set the processor operating mode the arrangement of bits is shown in figure 3-6: program status register format . figure 3-6: program status register format 3.8.1 the condition code ?ags the n, z, c and v bits are the condition code ?ags. these may be changed as a result of arithmetic and logical operations, and may be tested to determine whether an instruction should be executed. in arm state, all instructions may be executed conditionally: see 4.2 the condition field on page 4-5 for details. in thumb state, only the branch instruction is capable of conditional execution: see 5.17 format 17: software interrupt on page 5-38 3.8.2 the control bits the bottom 8 bits of a psr (incorporating i, f , t and m[4:0]) are known collectively as the control bits. these will change when an exception arises. if the processor is operating in a privileged mode, they can also be manipulated by software. the t bit this re?ects the operating state. when this bit is set, the processor is executing in thumb state, otherwise it is executing in arm state. this is re?ected 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. 0 1 2 3 4 5 6 7 8 27 28 29 30 31 m0 m1 m2 m3 m4 . f i v c z n overflow carry / borrow zero negative / less than mode bits fiq disable irq disable . . condition code flags control bits state bit (reserved) 23 . . 24 t 25 . 26 . / extend
programmers model ARM7TDMI data sheet arm ddi 0029e 3-9 open access interrupt disable bits the i and f bits are the interrupt disable bits. when set, these disable the irq and fiq interrupts respectively. the mode bits the m4, m3, m2, m1 and m0 bits (m[4:0]) are the mode bits. these determine the processors operating mode, as shown in table 3-1: psr mode bit values on page 3-9. not all combinations of the mode bits de?ne 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. reserved bits the remaining bits in the psrs are reserved. when changing a psrs ?ag or control bits, you must ensure that these unused bits are not altered. also, your program should not rely on them containing speci?c values, since in future processors they may read as one or zero. m[4:0] mode visible thumb state registers visible arm state registers 10000 user r7..r0, lr, sp pc, cpsr r14..r0, pc, cpsr 10001 fiq r7..r0, lr_fiq, sp_fiq pc, cpsr, spsr_fiq r7..r0, r14_fiq..r8_fiq, pc, cpsr, spsr_fiq 10010 irq r7..r0, lr_irq, sp_irq pc, cpsr, spsr_irq r12..r0, r14_irq..r13_irq, pc, cpsr, spsr_irq 10011 supervisor r7..r0, lr_svc, sp_svc, pc, cpsr, spsr_svc r12..r0, r14_svc..r13_svc, pc, cpsr, spsr_svc 10111 abort r7..r0, lr_abt, sp_abt, pc, cpsr, spsr_abt r12..r0, r14_abt..r13_abt, pc, cpsr, spsr_abt 11011 undefined r7..r0 lr_und, sp_und, pc, cpsr, spsr_und r12..r0, r14_und..r13_und, pc, cpsr 11111 system r7..r0, lr, sp pc, cpsr r14..r0, pc, cpsr table 3-1: psr mode bit values
programmers model ARM7TDMI data sheet arm ddi 0029e 3-10 open access 3.9 exceptions exceptions arise whenever the normal ?ow of a program has to be halted temporarily , for example to service an interrupt from a peripheral. before an exception can be handled, the current processor state must be preserved so that the original program can resume when the handler routine has ?nished. it is possible for several exceptions to arise at the same time. if this happens, they are dealt with in a ?xed order - see 3.9.10 exception priorities on page 3-14. 3.9.1 action on entering an exception when handling an exception, the ARM7TDMI: 1 preserves the address of the next instruction in the appropriate link register . if the exception has been entered from arm state, then the address of the next instruction is copied into the link register (that is, current pc + 4 or pc + 8 depending on the exception. see table 3-2: exception entry/exit on page 3-11 for details). if the exception has been entered from thumb state, then the value written into the link register is the current pc of fset by a value such that the program resumes from the correct place on return from the exception. this means that the exception handler need not determine which state the exception was entered from. for example, in the case of swi, movs pc, r14_svc will always return to the next instruction regardless of whether the swi was executed in arm or thumb state. 2 copies the cpsr into the appropriate spsr 3 forces the cpsr mode bits to a value which depends on the exception 4 forces the pc to fetch the next instruction from the relevant exception vector it may also set the interrupt disable ?ags 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. 3.9.2 action on leaving an exception on completion, the exception handler: 1 moves the link register, minus an of fset where appropriate, to the pc. (the offset will vary depending on the type of exception.) 2 copies the spsr back to the cpsr 3 clears the interrupt disable ?ags, if they were set on entry note an explicit switch back to thumb state is never needed, since restoring the cpsr from the spsr automatically sets the t bit to the value it held immediately prior to the exception.
programmers model ARM7TDMI data sheet arm ddi 0029e 3-11 open access 3.9.3 exception entry/exit summary table 3-2: exception entry/exit summarises the pc value preserved in the relevant r14 on exception entry, and the recommended instruction for exiting the exception handler. notes 1 where pc is the address of the bl/swi/unde?ned instruction fetch which had the prefetch abort. 2 where pc is the address of the instruction which did not get executed since the fiq or irq took priority. 3 where pc is the address of the load or store instruction which generated the data abort. 4 the value saved in r14_svc upon reset is unpredictable. 3.9.4 fiq the fiq (fast interrupt request) exception is designed to support a data transfer or channel process, and in arm state has suf ?cient private registers to remove the need for register saving (thus minimising the overhead of context switching). fiq is externally generated by taking the nfiq input low . this input can except either synchronous or asynchronous transitions, depending on the state of the isync input signal. when isync is low, nfiq and nirq are considered asynchronous, and a cycle delay for synchronization is incurred before the interrupt can af fect the processor ?ow. irrespective of whether the exception was entered from arm or thumb state, a fiq handler should leave the interrupt by executing subs pc,r14_fiq,#4 return instruction previous state arm thumb r14_x r14_x notes bl mov pc, r14 pc + 4 pc + 2 1 swi movs pc, r14_svc pc + 4 pc + 2 1 udef movs pc, r14_und pc + 4 pc + 2 1 fiq subs pc, r14_fiq, #4 pc + 4 pc + 4 2 irq subs pc, r14_irq, #4 pc + 4 pc + 4 2 pabt subs pc, r14_abt, #4 pc + 4 pc + 4 1 dabt subs pc, r14_abt, #8 pc + 8 pc + 8 3 reset na - - 4 table 3-2: exception entry/exit
programmers model ARM7TDMI data sheet arm ddi 0029e 3-12 open access fiq may be disabled by setting the cpsrs f ?ag (but note that this is not possible from user mode). if the f ?ag is clear, ARM7TDMI checks for a low level on the output of the fiq synchroniser at the end of each instruction. 3.9.5 irq the irq (interrupt request) exception is a normal interrupt caused by a low level on the nirq input. irq has a lower priority than fiq and is masked out when a fiq sequence is entered. it may be disabled at any time by setting the i bit in the cpsr, though this can only be done from a privileged (non-user) mode. irrespective of whether the exception was entered from arm or thumb state, an irq handler should return from the interrupt by executing subs pc,r14_irq,#4 3.9.6 abort an abort indicates that the current memory access cannot be completed. it can be signalled by the external abort input. ARM7TDMI checks for the abort exception during memory access cycles. there are two types of abort: prefetch abort occurs during an instruction prefetch. data abort occurs during a data access. if a prefetch abort occurs, the prefetched instruction is marked as invalid, but the exception will not be taken until the instruction reaches the head of the pipeline. if the instruction is not executed - for example because a branch occurs while it is in the pipeline - the abort does not take place. if a data abort occurs, the action taken depends on the instruction type: 1 single data transfer instructions (ldr, str) write back modi?ed base registers: the abort handler must be aware of this. 2 the swap instruction (swp) is aborted as though it had not been executed. 3 block data transfer instructions (ldm, stm) complete. if write-back is set, the base is updated. if the instruction would have overwritten the base with data (ie it has the base in the transfer list), the overwriting is prevented. all register overwriting is prevented after an abort is indicated, which means in particular that r15 (always the last register to be transferred) is preserved in an aborted ldm instruction. the abort mechanism allows the implementation of a demand paged virtual memory system. in such a system the processor is allowed to generate arbitrary addresses. when the data at an address is unavailable, the memory management unit (mmu) signals an abort. the abort handler must then work out the cause of the abort, make the requested data available, and retry the aborted instruction. the application program needs no knowledge of the amount of memory available to it, nor is its state in any way affected by the abort.
programmers model ARM7TDMI data sheet arm ddi 0029e 3-13 open access after ?xing the reason for the abort, the handler should execute the following irrespective of the state (arm or thumb): subs pc,r14_abt,#4 for a prefetch abort, or subs pc,r14_abt,#8 for a data abort this restores both the pc and the cpsr, and retries the aborted instruction. 3.9.7 software interrupt the software interrupt instruction (swi) is used for entering supervisor mode, usually to request a particular supervisor function. a swi handler should return by executing the following irrespective of the state (arm or thumb): mov pc, r14_svc this restores the pc and cpsr, and returns to the instruction following the swi. 3.9.8 unde?ned instruction when ARM7TDMI comes across an instruction which it cannot handle, it takes the unde?ned instruction trap. this mechanism may be used to extend either the thumb or arm instruction set by software emulation. after emulating the failed instruction, the trap handler should execute the following irrespective of the state (arm or thumb): movs pc,r14_und this restores the cpsr and returns to the instruction following the unde?ned instruction. 3.9.9 exception vectors the following table shows the exception vector addresses. address exception mode on entry 0x00000000 reset supervisor 0x00000004 undefined instruction undefined 0x00000008 software interrupt supervisor 0x0000000c abort (prefetch) abort 0x00000010 abort (data) abort 0x00000014 reserved reserved 0x00000018 irq irq 0x0000001c fiq fiq table 3-3: exception vectors
programmers model ARM7TDMI data sheet arm ddi 0029e 3-14 open access 3.9.10 exception priorities when multiple exceptions arise at the same time, a ?xed priority system determines the order in which they are handled: highest priority: 1 reset 2 data abort 3 fiq 4 irq 5 prefetch abort lowest priority: 6 unde?ned instruction, software interrupt. not all exceptions can occur at once: unde?ned instruction and software interrupt are mutually exclusive, since they each correspond to particular (non-overlapping) decodings of the current instruction. if a data abort occurs at the same time as a fiq, and fiqs are enabled (ie the cpsr s f ?ag is clear), ARM7TDMI enters the data abort handler and then immediately proceeds to the fiq vector . a normal return from fiq will cause the data abort handler to resume execution. placing data abort at a higher priority than fiq is necessary to ensure that the transfer error does not escape detection. the time for this exception entry should be added to worst-case fiq latency calculations. 3.10 interrupt latencies the worst case latency for fiq, assuming that it is enabled, consists of the longest time the request can take to pass through the synchroniser ( tsyncmax if asynchronous), plus the time for the longest instruction to complete ( tldm , the longest instruction is an ldm which loads all the registers including the pc), plus the time for the data abort entry ( texc ), plus the time for fiq entry ( t?q ). at the end of this time ARM7TDMI will be executing the instruction at 0x1c. tsyncmax is 3 processor cycles, tldm is 20 cycles, texc is 3 cycles, and t?q is 2 cycles. the total time is therefore 28 processor cycles. this is just over 1.4 microseconds in a system which uses a continuous 20 mhz processor clock. the maximum irq latency calculation is similar, but must allow for the fact that fiq has higher priority and could delay entry into the irq handling routine for an arbitrary length of time. the minimum latency for fiq or irq consists of the shortest time the request can take through the synchroniser ( tsyncmin ) plus t?q . this is 4 processor cycles.
programmers model ARM7TDMI data sheet arm ddi 0029e 3-15 open access 3.11 reset when the nreset signal goes low , ARM7TDMI abandons the executing instruction and then continues to fetch instructions from incrementing word addresses. when nreset goes high again, ARM7TDMI: 1 overwrites r14_svc and spsr_svc by copying the current values of the pc and cpsr into them. the value of the saved pc and spsr is not de?ned. 2 forces m[4:0] to 1001 1 (supervisor mode), sets the i and f bits in the cpsr, and clears the cpsrs t bit. 3 forces the pc to fetch the next instruction from address 0x00. 4 execution resumes in arm state.
programmers model ARM7TDMI data sheet arm ddi 0029e 3-16 open access
ARM7TDMI data sheet arm ddi 0029e 4-1 11 1 open access arm instruction set this chapter describes the arm instruction set. 4.1 instruction set summary 4-2 4.2 the condition field 4-5 4.3 branch and exchange (bx) 4-6 4.4 branch and branch with link (b, bl) 4-8 4.5 data processing 4-10 4.6 psr transfer (mrs, msr) 4-18 4.7 multiply and multiply-accumulate (mul, mla) 4-23 4.8 multiply long and multiply-accumulate long (mull,mlal) 4-25 4.9 single data transfer (ldr, str) 4-28 4.10 halfword and signed data transfer 4-34 4.11 block data transfer (ldm, stm) 4-40 4.12 single data swap (swp) 4-47 4.13 software interrupt (swi) 4-49 4.14 coprocessor data operations (cdp) 4-51 4.15 coprocessor data transfers (ldc, stc) 4-53 4.16 coprocessor register transfers (mrc, mcr) 4-57 4.17 unde?ned instruction 4-60 4.18 instruction set examples 4-61 4
arm instruction set - summary ARM7TDMI data sheet arm ddi 0029e 4-2 open access 4.1 instruction set summary 4.1.1 format summary the arm instruction set formats are shown below. figure 4-1: arm instruction set formats note some instruction codes are not defined but do not cause the undefined instruction trap to be taken, for instance a multiply instruction with bit 6 changed to a 1. these instructions should not be used, as their action may change in future arm implementations. 31 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 cond 0 0 i opcode s rn rd operand 2 data processing / psr transfer cond 0 0 0 0 0 0 a s rd rn rs 1 0 0 1 rm multiply cond 0 0 0 0 1 u a s rdhi rdlo rn 1 0 0 1 rm multiply long cond 0 0 0 1 0 b 0 0 rn rd 0 0 0 0 1 0 0 1 rm single data swap cond 0 0 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 rn branch and exchange cond 0 0 0 p u 0 w l rn rd 0 0 0 0 1 s h 1 rm halfword data transfer: register offset cond 0 0 0 p u 1 w l rn rd offset 1 s h 1 offset halfword data transfer: immediate offset cond 0 1 i p u b w l rn rd offset single data transfer cond 0 1 1 1 undefined cond 1 0 0 p u s w l rn register list block data transfer cond 1 0 1 l offset branch cond 1 1 0 p u n w l rn crd cp# offset coprocessor data transfer cond 1 1 1 0 cp opc crn crd cp# cp 0 crm coprocessor data operation cond 1 1 1 0 cp opc l crn rd cp# cp 1 crm coprocessor register transfer cond 1 1 1 1 ignored by processor software interrupt 31 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
arm instruction set - summary ARM7TDMI data sheet arm ddi 0029e 4-3 open access 4.1.2 instruction summary mnemonic instruction action see section: adc add with carry rd := rn + op2 + carry 4.5 add add rd := rn + op2 4.5 and and rd := rn and op2 4.5 b branch r15 := address 4.4 bic bit clear rd := rn and not op2 4.5 bl branch with link r14 := r15, r15 := address 4.4 bx branch and exchange r15 := rn, t bit := rn[0] 4.3 cdp coprocesor data processing (coprocessor-specific) 4.14 cmn compare negative cpsr flags := rn + op2 4.5 cmp compare cpsr flags := rn - op2 4.5 eor exclusive or rd := (rn and not op2) or (op2 and not rn) 4.5 ldc load coprocessor from memory coprocessor load 4.15 ldm load multiple registers stack manipulation (pop) 4.11 ldr load register from memory rd := (address) 4.9, 4.10 mcr move cpu register to coprocessor register crn := rrn {crm} 4.16 mla multiply accumulate rd := (rm * rs) + rn 4.7, 4.8 mov move register or constant rd : = op2 4.5 mrc move from coprocessor register to cpu register rn := crn {crm} 4.16 mrs move psr status/flags to register rn := psr 4.6 msr move register to psr status/flags psr := rm 4.6 mul multiply rd := rm * rs 4.7, 4.8 mvn move negative register rd := 0xffffffff eor op2 4.5 orr or rd := rn or op2 4.5 table 4-1: the arm instruction set
arm instruction set - summary ARM7TDMI data sheet arm ddi 0029e 4-4 open access rsb reverse subtract rd := op2 - rn 4.5 rsc reverse subtract with carry rd := op2 - rn - 1 + carry 4.5 sbc subtract with carry rd := rn - op2 - 1 + carry 4.5 stc store coprocessor register to memory address := crn 4.15 stm store multiple stack manipulation (push) 4.11 str store register to memory
:= rd 4.9, 4.10 sub subtract rd := rn - op2 4.5 swi software interrupt os call 4.13 swp swap register with memory rd := [rn], [rn] := rm 4.12 teq test bitwise equality cpsr flags := rn eor op2 4.5 tst test bits cpsr flags := rn and op2 4.5 mnemonic instruction action see section: table 4-1: the arm instruction set (continued)
arm instruction set - condition field ARM7TDMI data sheet arm ddi 0029e 4-5 open access 4.2 the condition field in arm state, all instructions are conditionally executed according to the state of the cpsr condition codes and the instructions condition ?eld. this ?eld (bits 31:28) determines the circumstances under which an instruction is to be executed. if the state of the c, n, z and v ?ags ful?ls the conditions encoded by the ?eld, the instruction is executed, otherwise it is ignored. there are sixteen possible conditions, each represented by a two-character suf ?x that can be appended to the instruction s mnemonic. for example, a branch ( b in assembly language) becomes beq for "branch if equal", which means the branch will only be taken if the z ?ag is set. in practice, ?fteen different conditions may be used: these are listed in table 4-2: condition code summary . the sixteenth (1111) is reserved, and must not be used. in the absence of a suf?x, the condition ?eld of most instructions is set to "always" (su?x al). this means the instruction will always be executed regardless of the cpsr condition codes. code suffix flags meaning 0000 eq z set equal 0001 ne z clear not equal 0010 cs c set unsigned higher or same 0011 cc c clear unsigned lower 0100 mi n set negative 0101 pl n clear positive or zero 0110 vs v set overflow 0111 vc v clear no overflow 1000 hi c set and z clear unsigned higher 1001 ls c clear or z set unsigned lower or same 1010 ge n equals v greater or equal 1011 lt n not equal to v less than 1100 gt z clear and (n equals v) greater than 1101 le z set or (n not equal to v) less than or equal 1110 al (ignored) always table 4-2: condition code summary
arm instruction set - condition field ARM7TDMI data sheet arm ddi 0029e 4-6 open access 4.3 branch and exchange (bx) this instruction is only executed if the condition is true. the various conditions are de?ned in table 4-2: condition code summary on page 4-5. this instruction performs a branch by copying the contents of a general register, rn, into the program counter, pc. the branch causes a pipeline ?ush and re?ll from the address speci?ed by rn. this instruction also permits the instruction set to be exchanged. when the instruction is executed, the value of rn[0] determines whether the instruction stream will be decoded as arm or thumb instructions. figure 4-2: branch and exchange instructions 4.3.1 instruction cycle times the bx instruction takes 2s + 1n cycles to execute, where s and n are as de?ned in 6.2 cycle types on page 6-2. 4.3.2 assembler syntax bx - branch and exchange. bx{cond} rn {cond} t wo character condition mnemonic. see table 4-2: condition code summary on page 4-5. rn is an expression evaluating to a valid register number. 4.3.3 using r15 as an operand if r15 is used as an operand, the behaviour is unde?ned. cond 0 0 0 1 0 0 1 0 0 0 0 1 rn 0 3 4 7 8 11 12 15 16 19 20 23 24 27 28 31 operand register if bit 0 of rn = 1, subsequent instructions decoded as thumb instructions if bit 0 of rn = 0, subsequent instructions decoded as arm instructions condition field 1 1 1 1 1 1 1 1 1 1 1 1
arm instruction set - condition field ARM7TDMI data sheet arm ddi 0029e 4-7 open access 4.3.4 examples adr r0, into_thumb + 1 ; generate branch target address ; and set bit 0 high - hence ; arrive in thumb state. bx r0 ; branch and change to thumb ; state. code16 ; assemble subsequent code as into_thumb ; thumb instructions . . adr r5, back_to_arm : generate branch target to word : aligned ; address - hence bit 0 ; is low and so change back to arm ; state. bx r5 ; branch and change back to arm ; state. . . align ; word align code32 ; assemble subsequent code as arm back_to_arm ; instructions . .
arm instruction set - b, bl ARM7TDMI data sheet arm ddi 0029e 4-8 open access 4.4 branch and branch with link (b, bl) the instruction is only executed if the condition is true. the various conditions are de?ned table 4-2: condition code summary on page 4-5. the instruction encoding is shown in figure 4-3: branch instructions , below. figure 4-3: branch instructions branch instructions contain a signed 2's complement 24 bit offset. this is shifted left two bits, sign extended to 32 bits, and added to the pc. the instruction can therefore specify a branch of +/- 32mbytes. the branch of fset must take account of the prefetch operation, which causes the pc to be 2 words (8 bytes) ahead of the current instruction. branches beyond +/- 32mbytes must use an of fset or absolute destination which has been previously loaded into a register . in this case the pc should be manually saved in r14 if a branch with link type operation is required. 4.4.1 the link bit branch with link (bl) writes the old pc into the link register (r14) of the current bank. the pc value written into r14 is adjusted to allow for the prefetch, and contains the address of the instruction following the branch and link instruction. note that the cpsr is not saved with the pc and r14[1:0] are always cleared. t o return from a routine called by branch with link use mov pc,r14 if the link register is still valid or ldm rn!,{..pc} if the link register has been saved onto a stack pointed to by rn. 4.4.2 instruction cycle times branch and branch with link instructions take 2s + 1n incremental cycles, where s and n are as de?ned in 6.2 cycle types on page 6-2. cond 101 l offset 31 28 27 25 24 23 0 link bit 0 = branch 1 = branch with link condition field
arm instruction set - b, bl ARM7TDMI data sheet arm ddi 0029e 4-9 open access 4.4.3 assembler syntax items in {} are optional. items in <> must be present. b{l}{cond} {l} is used to request the branch with link form of the instruction. if absent, r14 will not be affected by the instruction. {cond} is a two-character mnemonic as shown in table 4-2: condition code summary on page 4-5. if absent then al (always) will be used. is the destination. the assembler calculates the offset. 4.4.4 examples here bal here ; assembles to 0xeafffffe (note effect of ; pc offset). b there ; always condition used as default. cmp r1,#0 ; compare r1 with zero and branch to fred ; if r1 was zero, otherwise continue beq fred ; continue to next instruction. bl sub+rom ; call subroutine at computed address. adds r1,#1 ; add 1 to register 1, setting cpsr flags ; on the result then call subroutine if blcc sub ; the c flag is clear, which will be the ; case unless r1 held 0xffffffff.
arm instruction set - data processing ARM7TDMI data sheet arm ddi 0029e 4-10 open access 4.5 data processing the data processing instruction is only executed if the condition is true. the conditions are de?ned in table 4-2: condition code summary on page 4-5. the instruction encoding is shown in figure 4-4: data processing instructions below. figure 4-4: data processing instructions the instruction produces a result by performing a speci?ed arithmetic or logical operation on one or two operands. the ?rst operand is always a register (rn). cond 00 i opcode rn rd operand 2 0 11 12 15 16 19 20 21 24 25 26 27 28 31 destination register 1st operand register set condition codes operation code 0 = do not alter condition codes 1 = set condition codes 0000 = and - rd:= op1 and op2 0010 = sub - rd:= op1 - op2 0011 = rsb - rd:= op2 - op1 0100 = add - rd:= op1 + op2 0101 = adc - rd:= op1 + op2 + c 0110 = sbc - rd:= op1 - op2 + c 0111 = rsc - rd:= op2 - op1 + c 1000 = tst - set condition codes on op1 and op2 1001 = teq - set condition codes on op1 eor op2 1010 = cmp - set condition codes on op1 - op2 1011 = cmn - set condition codes on op1 + op2 1100 = orr - rd:= op1 or op2 1101 = mov - rd:= op2 1110 = bic - rd:= op1 and not op2 1111 = mvn - rd:= not op2 immediate operand 0 = operand 2 is a register 1 = operand 2 is an immediate value shift rm rotate s unsigned 8 bit immediate value 2nd operand register shift applied to rm shift applied to imm imm condition field 11 8 7 0 0 3 4 11 0001 = eor - rd:= op1 eor op2 - 1 - 1
arm instruction set - data processing ARM7TDMI data sheet arm ddi 0029e 4-11 open access the second operand may be a shifted register (rm) or a rotated 8 bit immediate value (imm) according to the value of the i bit in the instruction. the condition codes in the cpsr may be preserved or updated as a result of this instruction, according to the value of the s bit in the instruction. certain operations (tst , teq, cmp , cmn) do not write the result to rd. they are used only to perform tests and to set the condition codes on the result and always have the s bit set. the instructions and their effects are listed in table 4-3: arm data processing instructions on page 4-11 . 4.5.1 cpsr ?ags the data processing operations may be classi?ed as logical or arithmetic. the logical operations (and, eor, tst, teq, orr, mov , bic, mvn) perform the logical action on all corresponding bits of the operand or operands to produce the result. if the s bit is set (and rd is not r15, see below) the v ?ag in the cpsr will be unaf fected, the c ?ag will be set to the carry out from the barrel shifter (or preserved when the shift operation is lsl #0), the z ?ag will be set if and only if the result is all zeros, and the n ?ag will be set to the logical value of bit 31 of the result . assembler mnemonic opcode action and 0000 operand1 and operand2 eor 0001 operand1 eor operand2 sub 0010 operand1 - operand2 rsb 0011 operand2 - operand1 add 0100 operand1 + operand2 adc 0101 operand1 + operand2 + carry sbc 0110 operand1 - operand2 + carry - 1 rsc 0111 operand2 - operand1 + carry - 1 tst 1000 as and, but result is not written teq 1001 as eor, but result is not written cmp 1010 as sub, but result is not written cmn 1011 as add, but result is not written orr 1100 operand1 or operand2 mov 1101 operand2 (operand1 is ignored) bic 1110 operand1 and not operand2 (bit clear) mvn 1111 not operand2 (operand1 is ignored) table 4-3: arm data processing instructions
arm instruction set - shifts ARM7TDMI data sheet arm ddi 0029e 4-12 open access the arithmetic operations (sub, rsb, add, adc, sbc, rsc, cmp , cmn) treat each operand as a 32 bit integer (either unsigned or 2's complement signed, the two are equivalent). if the s bit is set (and rd is not r15) the v ?ag in the cpsr will be set if an over?ow occurs into bit 31 of the result; this may be ignored if the operands were considered unsigned, but warns of a possible error if the operands were 2's complement signed. the c ?ag will be set to the carry out of bit 31 of the alu, the z ?ag will be set if and only if the result was zero, and the n ?ag will be set to the value of bit 31 of the result (indicating a negative result if the operands are considered to be 2's complement signed). 4.5.2 shifts when the second operand is speci?ed to be a shifted register, the operation of the barrel shifter is controlled by the shift ?eld in the instruction. this ?eld indicates the type of shift to be performed (logical left or right, arithmetic right or rotate right). the amount by which the register should be shifted may be contained in an immediate ?eld in the instruction, or in the bottom byte of another register (other than r15). the encoding for the different shift types is shown in figure 4-5: arm shift operations . figure 4-5: arm shift operations instruction speci?ed shift amount when the shift amount is speci?ed in the instruction, it is contained in a 5 bit ?eld which may take any value from 0 to 31. a logical shift left (lsl) takes the contents of rm and moves each bit by the speci?ed amount to a more signi?cant position. the least signi?cant bits of the result are ?lled with zeros, and the high bits of rm which do not map into the result are discarded, except that the least signi?cant discarded bit becomes the shifter carry output which may be latched into the c bit of the cpsr when the alu operation is in the logical class (see above). for example, the ef fect of lsl #5 is shown in figure 4-6: logical shift left . 0 0 1 rs 11 8 7 6 5 4 11 7 6 5 4 shift type shift amount 5 bit unsigned integer 00 = logical left 01 = logical right 10 = arithmetic right 11 = rotate right shift type shift register 00 = logical left 01 = logical right 10 = arithmetic right 11 = rotate right shift amount specified in bottom byte of rs
arm instruction set - shifts ARM7TDMI data sheet arm ddi 0029e 4-13 open access figure 4-6: logical shift left note lsl #0 is a special case, where the shifter carry out is the old value of the cpsr c flag. the contents of rm are used directly as the second operand. a logical shift right (lsr) is similar, but the contents of rm are moved to less signi?cant positions in the result. lsr #5 has the ef fect shown in figure 4-7: logical shift right . figure 4-7: logical shift right the form of the shift ?eld which might be expected to correspond to lsr #0 is used to encode lsr #32, which has a zero result with bit 31 of rm as the carry output. logical shift right zero is redundant as it is the same as logical shift left zero, so the assembler will convert lsr #0 (and asr #0 and ror #0) into lsl #0, and allow lsr #32 to be speci?ed. an arithmetic shift right (asr) is similar to logical shift right, except that the high bits are ?lled with bit 31 of rm instead of zeros. this preserves the sign in 2's complement notation. for example, asr #5 is shown in figure 4-8: arithmetic shift right . 0 0 0 0 0 contents of rm value of operand 2 31 27 26 0 carry out contents of rm value of operand 2 31 0 carry out 0 0 0 0 0 5 4
arm instruction set - shifts ARM7TDMI data sheet arm ddi 0029e 4-14 open access figure 4-8: arithmetic shift right the form of the shift ?eld which might be expected to give asr #0 is used to encode asr #32. bit 31 of rm is again used as the carry output, and each bit of operand 2 is also equal to bit 31 of rm. the result is therefore all ones or all zeros, according to the value of bit 31 of rm. rotate right (ror) operations reuse the bits which overshoot in a logical shift right operation by reintroducing them at the high end of the result, in place of the zeros used to ?ll the high end in logical right operations. for example, ror #5 is shown in figure 4-9: rotate right on page 4-14. figure 4-9: rotate right the form of the shift ?eld which might be expected to give ror #0 is used to encode a special function of the barrel shifter , rotate right extended (rrx). this is a rotate right by one bit position of the 33 bit quantity formed by appending the cpsr c ?ag to the most signi?cant end of the contents of rm as shown in figure 4-10: rotate right extended . contents of rm value of operand 2 31 0 carry out 5 4 30 contents of rm value of operand 2 31 0 carry out 5 4
arm instruction set - shifts ARM7TDMI data sheet arm ddi 0029e 4-15 open access figure 4-10: rotate right extended register speci?ed shift amount only the least signi?cant byte of the contents of rs is used to determine the shift amount. rs can be any general register other than r15. if this byte is zero, the unchanged contents of rm will be used as the second operand, and the old value of the cpsr c ?ag will be passed on as the shifter carry output. if the byte has a value between 1 and 31, the shifted result will exactly match that of an instruction speci?ed shift with the same value and shift operation. if the value in the byte is 32 or more, the result will be a logical extension of the shift described above: 1 lsl by 32 has result zero, carry out equal to bit 0 of rm. 2 lsl by more than 32 has result zero, carry out zero. 3 lsr by 32 has result zero, carry out equal to bit 31 of rm. 4 lsr by more than 32 has result zero, carry out zero. 5 asr by 32 or more has result ?lled with and carry out equal to bit 31 of rm. 6 ror by 32 has result equal to rm, carry out equal to bit 31 of rm. 7 ror by n where n is greater than 32 will give the same result and carry out as ror by n-32; therefore repeatedly subtract 32 from n until the amount is in the range 1 to 32 and see above. note the zero in bit 7 of an instruction with a register controlled shift is compulsory; a one in this bit will cause the instruction to be a multiply or unde?ned instruction. 4.5.3 immediate operand rotates the immediate operand rotate ?eld is a 4 bit unsigned integer which speci?es a shift operation on the 8 bit immediate value. this value is zero extended to 32 bits, and then subject to a rotate right by twice the value in the rotate ?eld. this enables many common constants to be generated, for example all powers of 2. contents of rm value of operand 2 31 0 carry out 1 c in
arm instruction set - teq, tst, cmp & cmn ARM7TDMI data sheet arm ddi 0029e 4-16 open access 4.5.4 writing to r15 when rd is a register other than r15, the condition code ?ags in the cpsr may be updated from the alu ?ags as described above. when rd is r15 and the s ?ag in the instruction is not set the result of the operation is placed in r15 and the cpsr is unaffected. when rd is r15 and the s ?ag is set the result of the operation is placed in r15 and the spsr corresponding to the current mode is moved to the cpsr. this allows state changes which atomically restore both pc and cpsr. this form of instruction should not be used in user mode. 4.5.5 using r15 as an operand if r15 (the pc) is used as an operand in a data processing instruction the register is used directly. the pc value will be the address of the instruction, plus 8 or 12 bytes due to instruction prefetching. if the shift amount is speci?ed in the instruction, the pc will be 8 bytes ahead. if a register is used to specify the shift amount the pc will be 12 bytes ahead. 4.5.6 teq, tst, cmp and cmn opcodes note teq, tst, cmp and cmn do not write the result of their operation but do set flags in the cpsr. an assembler should always set the s flag for these instructions even if this is not specified in the mnemonic. the teqp form of the teq instruction used in earlier arm processors must not be used: the psr transfer operations should be used instead. the action of teqp in the ARM7TDMI is to move spsr_ to the cpsr if the processor is in a privileged mode and to do nothing if in user mode. 4.5.7 instruction cycle times data processing instructions vary in the number of incremental cycles taken as follows: s, n and i are as de?ned in 6.2 cycle types on page 6-2. processing type cycles normal data processing 1s data processing with register specified shift 1s + 1i data processing with pc written 2s + 1n data processing with register specified shift and pc written 2s + 1n + 1i table 4-4: incremental cycle times
arm instruction set - teq, tst, cmp & cmn ARM7TDMI data sheet arm ddi 0029e 4-17 open access 4.5.8 assembler syntax 1 mov,mvn (single operand instructions.) {cond}{s} rd, 2 cmp,cmn,teq,tst (instructions which do not produce a result.) {cond} rn, 3 and,eor,sub,rsb,add,adc,sbc,rsc,orr,bic {cond}{s} rd,rn, where: is rm{,} or,<#expression> {cond} is a two-character condition mnemonic. see table 4-2: condition code summary on page 4-5. {s} set condition codes if s present (implied for cmp , cmn, teq, tst). rd, rn and rm are expressions evaluating to a register number. <#expression> if this is used, the assembler will attempt to generate a shifted immediate 8-bit ?eld to match the expression. if this is impossible, it will give an error. is or #expression, or rrx (rotate right one bit with extend). s are: asl, lsl, lsr, asr, ror. (asl is a synonym for lsl, they assemble to the same code.) 4.5.9 examples addeq r2,r4,r5 ; if the z flag is set make r2:=r4+r5 teqs r4,#3 ; test r4 for equality with 3. ; (the s is in fact redundant as the ; assembler inserts it automatically.) sub r4,r5,r7,lsr r2 ; logical right shift r7 by the number in ; the bottom byte of r2, subtract result ; from r5, and put the answer into r4. mov pc,r14 ; return from subroutine. movs pc,r14 ; return from exception and restore cpsr ; from spsr_mode.
arm instruction set - mrs, msr ARM7TDMI data sheet arm ddi 0029e 4-18 open access 4.6 psr transfer (mrs, msr) the instruction is only executed if the condition is true. the various conditions are de?ned in table 4-2: condition code summary on page 4-5. the mrs and msr instructions are formed from a subset of the data processing operations and are implemented using the teq, tst, cmn and cmp instructions without the s ?ag set. the encoding is shown in figure 4-11: psr transfer on page 4-19. these instructions allow access to the cpsr and spsr registers. the mrs instruction allows the contents of the cpsr or spsr_ to be moved to a general register. the msr instruction allows the contents of a general register to be moved to the cpsr or spsr_ register. the msr instruction also allows an immediate value or register contents to be transferred to the condition code ?ags (n,z,c and v) of cpsr or spsr_ without af fecting the control bits. in this case, the top four bits of the speci?ed register contents or 32 bit immediate value are written to the top four bits of the relevant psr. 4.6.1 operand restrictions ? in user mode, the control bits of the cpsr are protected from change, so only the condition code flags of the cpsr can be changed. in other (privileged) modes the entire cpsr can be changed. note that the software must never change the state of the t bit in the cpsr. if this happens, the processor will enter an unpredictable state. ? the spsr register which is accessed depends on the mode at the time of execution. for example, only spsr_fiq is accessible when the processor is in fiq mode. ? you must not specify r15 as the source or destination register. ? also, do not attempt to access an spsr in user mode, since no such register exists.
arm instruction set - mrs, msr ARM7TDMI data sheet arm ddi 0029e 4-19 open access figure 4-11: psr transfer cond 0 000000000000 rd p 00010 s 001111 16 15 12 11 22 28 21 31 23 27 mrs (transfer psr contents to a register) destination register source psr condition field 0=cpsr 1=spsr_ cond 0 00000000 rm p 00010 d 1010011111 4 3 12 11 22 28 21 31 23 27 msr (transfer register contents to psr) source register destination psr condition field 0=cpsr 1=spsr_ cond 0 source operand p 00 d 1010001111 12 11 22 28 21 31 23 27 msr (transfer register contents or immdiate value to psr flag bits only) destination psr immediate operand 0=cpsr 1=spsr_ i 10 11 4 3 0 0=source operand is a register 1=source operand is an immediate value 11 8 7 0 condition field 00000000 rotate imm rm source register unsigned 8 bit immediate value shift applied to imm
arm instruction set - mrs, msr ARM7TDMI data sheet arm ddi 0029e 4-20 open access 4.6.2 reserved bits only twelve bits of the psr are de?ned in ARM7TDMI (n,z,c,v,i,f, t & m[4:0]); the remaining bits are reserved for use in future versions of the processor. refer to figure 3-6: program status register format on page 3-8 for a full description of the psr bits. to ensure the maximum compatibility between ARM7TDMI programs and future processors, the following rules should be observed: ? the reserved bits should be preserved when changing the value in a psr. ? programs should not rely on specific values from the reserved bits when checking the psr status, since they may read as one or zero in future processors. a read-modify-write strategy should therefore be used when altering the control bits of any psr register; this involves transferring the appropriate psr register to a general register using the mrs instruction, changing only the relevant bits and then transferring the modi?ed value back to the psr register using the msr instruction. example the following sequence performs a mode change: mrs r0,cpsr ; take a copy of the cpsr. bic r0,r0,#0x1f ; clear the mode bits. orr r0,r0,#new_mode ; select new mode msr cpsr,r0 ; write back the modified ; cpsr. when the aim is simply to change the condition code ?ags in a psr, a value can be written directly to the ?ag bits without disturbing the control bits. the following instruction sets the n,z,c and v ?ags: msr cpsr_flg,#0xf0000000 ; set all the flags ; regardless of their ; previous state (does not ; affect any control bits). no attempt should be made to write an 8 bit immediate value into the whole psr since such an operation cannot preserve the reserved bits. 4.6.3 instruction cycle times psr t ransfers take 1s incremental cycles, where s is as de?ned in 6.2 cycle types on page 6-2.
arm instruction set - mrs, msr ARM7TDMI data sheet arm ddi 0029e 4-21 open access 4.6.4 assembler syntax 1 mrs - transfer psr contents to a register mrs{cond} rd, 2 msr - transfer register contents to psr msr{cond} ,rm 3 msr - transfer register contents to psr ?ag bits only msr{cond} ,rm the most significant four bits of the register contents are written to the n,z,c & v flags respectively. 4 msr - transfer immediate value to psr ?ag bits only msr{cond} ,<#expression> the expression should symbolise a 32 bit value of which the most significant four bits are written to the n,z,c and v flags respectively. key: {cond} two-character condition mnemonic. see table 4-2: condition code summary on page 4-5. rd and rm are expressions evaluating to a register number other than r15 is cpsr, cpsr_all, spsr or spsr_all. (cpsr and cpsr_all are synonyms as are spsr and spsr_all) is cpsr_?g or spsr_?g <#expression> where this is used, the assembler will attempt to generate a shifted immediate 8-bit ?eld to match the expression. if this is impossible, it will give an error.
arm instruction set - mrs, msr ARM7TDMI data sheet arm ddi 0029e 4-22 open access 4.6.5 examples in user mode the instructions behave as follows: msr cpsr_all,rm ; cpsr[31:28] <- rm[31:28] msr cpsr_flg,rm ; cpsr[31:28] <- rm[31:28] msr cpsr_flg,#0xa0000000 ; cpsr[31:28] <- 0xa ;(set n,c; clear z,v) mrs rd,cpsr ; rd[31:0] <- cpsr[31:0] in privileged modes the instructions behave as follows: msr cpsr_all,rm ; cpsr[31:0] <- rm[31:0] msr cpsr_flg,rm ; cpsr[31:28] <- rm[31:28] msr cpsr_flg,#0x50000000 ; cpsr[31:28] <- 0x5 ;(set z,v; clear n,c) mrs rd,cpsr ; rd[31:0] <- cpsr[31:0] msr spsr_all,rm ;spsr_[31:0]<- rm[31:0] msr spsr_flg,rm ; spsr_[31:28] <- rm[31:28] msr spsr_flg,#0xc0000000 ; spsr_[31:28] <- 0xc ;(set n,z; clear c,v) mrs rd,spsr ; rd[31:0] <- spsr_[31:0]
arm instruction set - mul, mla ARM7TDMI data sheet arm ddi 0029e 4-23 open access 4.7 multiply and multiply-accumulate (mul, mla) the instruction is only executed if the condition is true. the various conditions are de?ned in table 4-2: condition code summary on page 4-5 . the instruction encoding is shown in figure 4-12: multiply instructions . the multiply and multiply-accumulate instructions use an 8 bit booth's algorithm to perform integer multiplication. figure 4-12: multiply instructions the multiply form of the instruction gives rd:=rm*rs. rn is ignored, and should be set to zero for compatibility with possible future upgrades to the instruction set. the multiply-accumulate form gives rd:=rm*rs+rn, which can save an explicit add instruction in some circumstances. both forms of the instruction work on operands which may be considered as signed (2s complement) or unsigned integers. the results of a signed multiply and of an unsigned multiply of 32 bit operands differ only in the upper 32 bits - the low 32 bits of the signed and unsigned results are identical. as these instructions only produce the low 32 bits of a multiply , they can be used for both signed and unsigned multiplies. for example consider the multiplication of the operands: operand a operand b result 0xfffffff6 0x0000001 0xffffff38 if the operands are interpreted as signed operand a has the value -10, operand b has the value 20, and the result is -200 which is correctly represented as 0xffffff38 if the operands are interpreted as unsigned operand a has the value 4294967286, operand b has the value 20 and the result is 85899345720, which is represented as 0x13ffffff38, so the least signi?cant 32 bits are 0xffffff38. cond 0 0 0 0 0 0 a s rd rn rs 1 0 0 1 rm 0 3 4 7 8 11 12 15 16 19 20 21 22 27 28 31 operand registers destination register set condition code accumulate 0 = do not alter condition codes 1 = set condition codes 0 = multiply only 1 = multiply and accumulate condition field
arm instruction set - mul, mla ARM7TDMI data sheet arm ddi 0029e 4-24 open access 4.7.1 operand restrictions the destination register rd must not be the same as the operand register rm. r15 must not be used as an operand or as the destination register. all other register combinations will give correct results, and rd, rn and rs may use the same register when required. 4.7.2 cpsr ?ags setting the cpsr ?ags is optional, and is controlled by the s bit in the instruction. the n (negative) and z (zero) ?ags are set correctly on the result (n is made equal to bit 31 of the result, and z is set if and only if the result is zero). the c (carry) ?ag is set to a meaningless value and the v (over?ow) ?ag is unaffected. 4.7.3 instruction cycle times mul takes 1s + mi and mla 1s + (m+1)i cycles to execute, where s and i are as de?ned in 6.2 cycle types on page 6-2. m is the number of 8 bit multiplier array cycles required to complete the multiply, which is controlled by the value of the multiplier operand speci?ed by rs. its possible values are as follows 1 if bits [32:8] of the multiplier operand are all zero or all one. 2 if bits [32:16] of the multiplier operand are all zero or all one. 3 if bits [32:24] of the multiplier operand are all zero or all one. 4 in all other cases. 4.7.4 assembler syntax mul{cond}{s} rd,rm,rs mla{cond}{s} rd,rm,rs,rn {cond} two-character condition mnemonic. see table 4-2: condition code summary on page 4-5. {s} set condition codes if s present rd, rm, rs and rn are expressions evaluating to a register number other than r15. 4.7.5 examples mul r1,r2,r3 ; r1:=r2*r3 mlaeqs r1,r2,r3,r4 ; conditionally r1:=r2*r3+r4, ; setting condition codes.
arm instruction set - mull,mlal ARM7TDMI data sheet arm ddi 0029e 4-25 open access 4.8 multiply long and multiply-accumulate long (mull,mlal) the instruction is only executed if the condition is true. the various conditions are de?ned in table 4-2: condition code summary on page 4-5 . the instruction encoding is shown in figure 4-13: multiply long instructions . the multiply long instructions perform integer multiplication on two 32 bit operands and produce 64 bit results. signed and unsigned multiplication each with optional accumulate give rise to four variations. figure 4-13: multiply long instructions the multiply forms (umull and smull) take two 32 bit numbers and multiply them to produce a 64 bit result of the form rdhi,rdlo := rm * rs. the lower 32 bits of the 64 bit result are written to rdlo, the upper 32 bits of the result are written to rdhi. the multiply-accumulate forms (umlal and smlal) take two 32 bit numbers, multiply them and add a 64 bit number to produce a 64 bit result of the form rdhi,rdlo := rm * rs + rdhi,rdlo. the lower 32 bits of the 64 bit number to add is read from rdlo. the upper 32 bits of the 64 bit number to add is read from rdhi. the lower 32 bits of the 64 bit result are written to rdlo. the upper 32 bits of the 64 bit result are written to rdhi. the umull and umlal instructions treat all of their operands as unsigned binary numbers and write an unsigned 64 bit result. the smull and smlal instructions treat all of their operands as two's-complement signed numbers and write a two's- complement signed 64 bit result. 4.8.1 operand restrictions ? r15 must not be used as an operand or as a destination register. ? rdhi, rdlo, and rm must all specify different registers. cond 0 0 0 0 1 u a s rdhi rdlo rs 1 0 0 1 rm 0 3 4 7 8 11 12 15 16 19 20 21 22 23 27 28 31 operand registers source destination registers set condition code accumulate unsigned 0 = do not alter condition codes 1 = set condition codes 0 = multiply only 1 = multiply and accumulate 0 = unsigned 1 = signed condition field
arm instruction set - mull,mlal ARM7TDMI data sheet arm ddi 0029e 4-26 open access 4.8.2 cpsr ?ags setting the cpsr ?ags is optional, and is controlled by the s bit in the instruction. the n and z ?ags are set correctly on the result (n is equal to bit 63 of the result, z is set if and only if all 64 bits of the result are zero). both the c and v ?ags are set to meaningless values. 4.8.3 instruction cycle times mull takes 1s + (m+1)i and mlal 1s + (m+2)i cycles to execute, where m is the number of 8 bit multiplier array cycles required to complete the multiply, which is controlled by the value of the multiplier operand speci?ed by rs. its possible values are as follows: for signed instructions smull, smlal: 1 if bits [31:8] of the multiplier operand are all zero or all one. 2 if bits [31:16] of the multiplier operand are all zero or all one. 3 if bits [31:24] of the multiplier operand are all zero or all one. 4 in all other cases. for unsigned instructions umull, umlal: 1 if bits [31:8] of the multiplier operand are all zero. 2 if bits [31:16] of the multiplier operand are all zero. 3 if bits [31:24] of the multiplier operand are all zero. 4 in all other cases. s and i are as de?ned in 6.2 cycle types on page 6-2. 4.8.4 assembler syntax mnemonic description purpose umull{cond}{s} rdlo,rdhi,rm,rs unsigned multiply long 32 x 32 = 64 umlal{cond}{s} rdlo,rdhi,rm,rs unsigned multiply & accumulate long 32 x 32 + 64 = 64 smull{cond}{s} rdlo,rdhi,rm,rs signed multiply long 32 x 32 = 64 smlal{cond}{s} rdlo,rdhi,rm,rs signed multiply & accumulate long 32 x 32 + 64 = 64 table 4-5: assembler syntax descriptions
arm instruction set - mull,mlal ARM7TDMI data sheet arm ddi 0029e 4-27 open access where: {cond} two-character condition mnemonic. see table 4-2: condition code summary on page 4-5. {s} set condition codes if s present rdlo, rdhi, rm, rs are expressions evaluating to a register number other than r15. 4.8.5 examples umull r1,r4,r2,r3 ; r4,r1:=r2*r3 umlals r1,r5,r2,r3 ; r5,r1:=r2*r3+r5,r1 also setting ; condition codes
arm instruction set - ldr, str ARM7TDMI data sheet arm ddi 0029e 4-28 open access 4.9 single data transfer (ldr, str) the instruction is only executed if the condition is true. the various conditions are de?ned in table 4-2: condition code summary on page 4-5 . the instruction encoding is shown in figure 4-14: single data transfer instructions on page 4-28. the single data transfer instructions are used to load or store single bytes or words of data. the memory address used in the transfer is calculated by adding an of fset to or subtracting an offset from a base register. the result of this calculation may be written back into the base register if auto-indexing is required. figure 4-14: single data transfer instructions cond i rn rd 0 11 12 15 16 19 20 21 24 25 26 27 28 31 01 p u b w l offset 22 23 0 11 source/destination register base register load/store bit 0 = store to memory 1 = load from memory write-back bit byte/word bit 0 = no write-back 1 = write address into base 0 = transfer word quantity 1 = transfer byte quantity up/down bit pre/post indexing bit 0 = offset is an immediate value immediate offset immediate offset unsigned 12 bit immediate offset 1 = offset is a register 11 0 shift applied to rm 3 4 condition field 0 = down; subtract offset from base 1 = up; add offset to base 0 = post; add offset after transfer 1 = pre; add offset before transfer offset register shift rm
arm instruction set - ldr, str ARM7TDMI data sheet arm ddi 0029e 4-29 open access 4.9.1 offsets and auto-indexing the offset from the base may be either a 12 bit unsigned binary immediate value in the instruction, or a second register (possibly shifted in some way). the of fset may be added to (u=1) or subtracted from (u=0) the base register rn. the of fset modi?cation may be performed either before (pre-indexed, p=1) or after (post-indexed, p=0) the base is used as the transfer address. the w bit gives optional auto increment and decrement addressing modes. the modi?ed base value may be written back into the base (w=1), or the old base value may be kept (w=0). in the case of post-indexed addressing, the write back bit is redundant and is always set to zero, since the old base value can be retained by setting the of fset to zero. therefore post-indexed data transfers always write back the modi?ed base. the only use of the w bit in a post-indexed data transfer is in privileged mode code, where setting the w bit forces non-privileged mode for the transfer, allowing the operating system to generate a user address in a system where the memory management hardware makes suitable use of this hardware. 4.9.2 shifted register offset the 8 shift control bits are described in the data processing instructions section. however , the register speci?ed shift amounts are not available in this instruction class. see 4.5.2 shifts on page 4-12. 4.9.3 bytes and words this instruction class may be used to transfer a byte (b=1) or a word (b=0) between an ARM7TDMI register and memory. the action of ldr(b) and str(b) instructions is in?uenced by the bigend control signal. the two possible con?gurations are described below. little endian con?guration a byte load (ldrb) expects the data on data bus inputs 7 through 0 if the supplied address is on a word boundary , on data bus inputs 15 through 8 if it is a word address plus one byte, and so on. the selected byte is placed in the bottom 8 bits of the destination register , and the remaining bits of the register are ?lled with zeros. please see figure 3-2: little endian addresses of bytes within words on page 3-3. a byte store (strb) repeats the bottom 8 bits of the source register four times across data bus outputs 31 through 0. the external memory system should activate the appropriate byte subsystem to store the data. a word load (ldr) will normally use a word aligned address. however, an address of fset from a word boundary will cause the data to be rotated into the register so that the addressed byte occupies bits 0 to 7. this means that half-words accessed at of fsets 0 and 2 from the word boundary will be correctly loaded into bits 0 through 15 of the register. two shift operations are then required to clear or to sign extend the upper 16 bits. this is illustrated in figure 4-15: little endian offset addressing on page 4-30.
arm instruction set - ldr, str ARM7TDMI data sheet arm ddi 0029e 4-30 open access figure 4-15: little endian offset addressing a word store (str) should generate a word aligned address. the word presented to the data bus is not affected if the address is not word aligned. that is, bit 31 of the register being stored always appears on data bus output 31. big endian con?guration a byte load (ldrb) expects the data on data bus inputs 31 through 24 if the supplied address is on a word boundary , on data bus inputs 23 through 16 if it is a word address plus one byte, and so on. the selected byte is placed in the bottom 8 bits of the destination register and the remaining bits of the register are ?lled with zeros. please see figure 3-1: big endian addresses of bytes within words on page 3-3. a byte store (strb) repeats the bottom 8 bits of the source register four times across data bus outputs 31 through 0. the external memory system should activate the appropriate byte subsystem to store the data. a word load (ldr) should generate a word aligned address. an address of fset of 0 or 2 from a word boundary will cause the data to be rotated into the register so that the addressed byte occupies bits 31 through 24. this means that half-words accessed at these offsets will be correctly loaded into bits 16 through 31 of the register. a shift operation is then required to move (and optionally sign extend) the data into the bottom 16 bits. an address offset of 1 or 3 from a word boundary will cause the data to be rotated into the register so that the addressed byte occupies bits 15 through 8. a b c d memory a+3 a+2 a+1 a 24 16 8 0 a b c d register 24 16 8 0 ldr from word aligned address a b c d a+3 a+2 a+1 a 24 16 8 0 a b c d 24 16 8 0 ldr from address offset by 2
arm instruction set - ldr, str ARM7TDMI data sheet arm ddi 0029e 4-31 open access a word store (str) should generate a word aligned address. the word presented to the data bus is not affected if the address is not word aligned. that is, bit 31 of the register being stored always appears on data bus output 31. 4.9.4 use of r15 write-back must not be speci?ed if r15 is speci?ed as the base register (rn). when using r15 as the base register you must remember it contains an address 8 bytes on from the address of the current instruction. r15 must not be speci?ed as the register offset (rm). when r15 is the source register (rd) of a register store (str) instruction, the stored value will be address of the instruction plus 12. 4.9.5 restriction on the use of base register when con?gured for late aborts, the following example code is dif?cult to unwind as the base register , rn, gets updated before the abort handler starts. sometimes it may be impossible to calculate the initial value. after an abort, the following example code is dif?cult to unwind as the base register, rn, gets updated before the abort handler starts. sometimes it may be impossible to calculate the initial value. example: ldr r0,[r1],r1 therefore a post-indexed ldr or str where rm is the same register as rn should not be used. 4.9.6 data aborts a transfer to or from a legal address may cause problems for a memory management system. for instance, in a system which uses virtual memory the required data may be absent from main memory. the memory manager can signal a problem by taking the processor abort input high whereupon the data abort trap will be taken. it is up to the system software to resolve the cause of the problem, then the instruction can be restarted and the original program continued. 4.9.7 instruction cycle times normal ldr instructions take 1s + 1n + 1i and ldr pc take 2s + 2n +1i incremental cycles, where s,n and i are as de?ned in 6.2 cycle types on page 6-2. str instructions take 2n incremental cycles to execute.
arm instruction set - ldr, str ARM7TDMI data sheet arm ddi 0029e 4-32 open access 4.9.8 assembler syntax {cond}{b}{t} rd,
where: ldr load from memory into a register str store from a register into memory {cond} two-character condition mnemonic. see table 4-2: condition code summary on page 4-5. {b} if b is present then byte transfer, otherwise word transfer {t} if t is present the w bit will be set in a post-indexed instruction, forcing non-privileged mode for the transfer cycle. t is not allowed when a pre-indexed addressing mode is speci?ed or implied. rd is an expression evaluating to a valid register number. rn and rm are expressions evaluating to a register number . if rn is r15 then the assembler will subtract 8 from the of fset value to allow for ARM7TDMI pipelining. in this case base write-back should not be speci?ed.
can be: 1 an expression which generates an address: the assembler will attempt to generate an instruction using the pc as a base and a corrected immediate of fset to address the location given by evaluating the expression. this will be a pc relative, pre-indexed address. if the address is out of range, an error will be generated. 2 a pre-indexed addressing speci?cation: [rn] offset of zero [rn,<#expression>]{!} offset of bytes [rn,{+/-}rm{,}]{!} offset of +/- contents of index register, shifted by 3 a post-indexed addressing speci?cation: [rn],<#expression> offset of bytes [rn],{+/-}rm{,} offset of +/- contents of index register, shifted as by .
arm instruction set - ldr, str ARM7TDMI data sheet arm ddi 0029e 4-33 open access general shift operation (see data processing instructions) but you cannot specify the shift amount by a register. {!} writes back the base register (set the w bit) if! is present. 4.9.9 examples str r1,[r2,r4]! ; store r1 at r2+r4 (both of which are ; registers) and write back address to ; r2. str r1,[r2],r4 ; store r1 at r2 and write back ; r2+r4 to r2. ldr r1,[r2,#16] ; load r1 from contents of r2+16, but ; don't write back. ldr r1,[r2,r3,lsl#2] ; load r1 from contents of r2+r3*4. ldreqbr1,[r6,#5] ; conditionally load byte at r6+5 into ; r1 bits 0 to 7, filling bits 8 to 31 ; with zeros. str r1,place ; generate pc relative offset to ; address place. ? place
arm instruction set - ldr, str ARM7TDMI data sheet arm ddi 0029e 4-34 open access 4.10 halfword and signed data transfer (ldrh/strh/ldrsb/ldrsh) the instruction is only executed if the condition is true. the various conditions are de?ned in table 4-2: condition code summary on page 4-5 . the instruction encoding is shown in figure 4-16: halfword and signed data transfer with register offset , below, and figure 4-17: halfword and signed data transfer with immediate offset on page 4-35. these instructions are used to load or store half-words of data and also load sign- extended bytes or half-words of data. the memory address used in the transfer is calculated by adding an of fset to or subtracting an of fset from a base register . the result of this calculation may be written back into the base register if auto-indexing is required. figure 4-16: halfword and signed data transfer with register offset cond 0 0 0 p u 0 w l rn rd 0 0 0 0 rm 0 3 4 7 8 11 12 15 16 19 20 21 22 27 28 31 offset register base register s h source/destination 00 = swp instruction 01 = unsigned halfwords 0 = store to memory 1 = load from memory load/store 1 s h 1 10 = signed byte 11 = signed halfwords register 0 = no write-back 1 = write address into base write-back 0 = down: subtract offset from base up/down 1 = up: add offset to base 0 = post: add/subtract offset pre/post indexing after transfer 1 = pre: add/subtract offset before transfer condition field 23 24 25 5 6
arm instruction set - ldr, str ARM7TDMI data sheet arm ddi 0029e 4-35 open access figure 4-17: halfword and signed data transfer with immediate offset 4.10.1 offsets and auto-indexing the of fset from the base may be either a 8- bit unsigned binary immediate value in the instruction, or a second register . the 8-bit of fset is formed by concatenating bits 1 1 to 8 and bits 3 to 0 of the instruction word, such that bit 11 becomes the msb and bit 0 becomes the lsb. the offset may be added to (u=1) or subtracted from (u=0) the base register rn. the offset modi?cation may be performed either before (pre- indexed, p=1) or after (post-indexed, p=0) the base register is used as the transfer address. the w bit gives optional auto-increment and decrement addressing modes. the modi?ed base value may be written back into the base (w=1), or the old base may be kept (w=0). in the case of post-indexed addressing, the write back bit is redundant and is always set to zero, since the old base value can be retained if necessary by setting the offset to zero. therefore post-indexed data transfers always write back the modi?ed base. the write-back bit should not be set high (w=1) when post-indexed addressing is selected. cond 0 0 0 p u 1 w l rn rd offset 0 3 4 7 8 11 12 15 16 19 20 21 22 27 28 31 immediate offset base register s h source/destination 00 = swp instruction 01 = unsigned halfwords 0 = store to memory 1 = load from memory load/store 1 s h 1 10 = signed byte 11 = signed halfwords register 0 = no write-back 1 = write address into base write-back 0 = down: subtract offset from base up/down 1 = up: add offset to base 0 = post: add/subtract offset pre/post indexing after transfer 1 = pre: add/subtract offset before transfer condition field 23 24 25 5 6 offset immediate offset (high nibble) (low nibble)
arm instruction set - ldr, str ARM7TDMI data sheet arm ddi 0029e 4-36 open access 4.10.2 halfword load and stores setting s=0 and h=1 may be used to transfer unsigned half-words between an ARM7TDMI register and memory. the action of ldrh and strh instructions is in?uenced by the bigend control signal. the two possible con?gurations are described in the section below. 4.10.3 signed byte and halfword loads the s bit controls the loading of sign-extended data. when s=1 the h bit selects between bytes (h=0) and half-words (h=1). the l bit should not be set low (store) when signed (s=1) operations have been selected. the ldrsb instruction loads the selected byte into bits 7 to 0 of the destination register and bits 31 to 8 of the destination register are set to the value of bit 7, the sign bit. the ldrsh instruction loads the selected half-word into bits 15 to 0 of the destination register and bits 31 to 16 of the destination register are set to the value of bit 15, the sign bit. the action of the ldrsb and ldrsh instructions is in?uenced by the bigend control signal. the two possible con?gurations are described in the following section. 4.10.4 endianness and byte/halfword selection little endian con?guration a signed byte load (ldrsb) expects data on data bus inputs 7 through to 0 if the supplied address is on a word boundary, on data bus inputs 15 through to 8 if it is a word address plus one byte, and so on. the selected byte is placed in the bottom 8 bit of the destination register , and the remaining bits of the register are ?lled with the sign bit, bit 7 of the byte. please see figure 3-2: little endian addresses of bytes within words on page 3-3 a halfword load (ldrsh or ldrh) expects data on data bus inputs 15 through to 0 if the supplied address is on a word boundary and on data bus inputs 31 through to 16 if it is a halfword boundary, (a[1]=1).the supplied address should always be on a halfword boundary. if bit 0 of the supplied address is high then the ARM7TDMI will load an unpredictable value. the selected halfword is placed in the bottom 16 bits of the destination register . for unsigned half-words (ldrh), the top 16 bits of the register are ?lled with zeros and for signed half-words (ldrsh) the top 16 bits are ?lled with the sign bit, bit 15 of the halfword. a halfword store (strh) repeats the bottom 16 bits of the source register twice across the data bus outputs 31 through to 0. the external memory system should activate the appropriate halfword subsystem to store the data. note that the address must be halfword aligned, if bit 0 of the address is high this will cause unpredictable behaviour.
arm instruction set - ldr, str ARM7TDMI data sheet arm ddi 0029e 4-37 open access big endian con?guration a signed byte load (ldrsb) expects data on data bus inputs 31 through to 24 if the supplied address is on a word boundary, on data bus inputs 23 through to 16 if it is a word address plus one byte, and so on. the selected byte is placed in the bottom 8 bit of the destination register , and the remaining bits of the register are ?lled with the sign bit, bit 7 of the byte. please see figure 3-1: big endian addresses of bytes within words on page 3-3 a halfword load (ldrsh or ldrh) expects data on data bus inputs 31 through to 16 if the supplied address is on a word boundary and on data bus inputs 15 through to 0 if it is a halfword boundary, (a[1]=1). the supplied address should always be on a halfword boundary. if bit 0 of the supplied address is high then the ARM7TDMI will load an unpredictable value. the selected halfword is placed in the bottom 16 bits of the destination register . for unsigned half-words (ldrh), the top 16 bits of the register are ?lled with zeros and for signed half-words (ldrsh) the top 16 bits are ?lled with the sign bit, bit 15 of the halfword. a halfword store (strh) repeats the bottom 16 bits of the source register twice across the data bus outputs 31 through to 0. the external memory system should activate the appropriate halfword subsystem to store the data. note that the address must be halfword aligned, if bit 0 of the address is high this will cause unpredictable behaviour. 4.10.5 use of r15 w rite-back should not be speci?ed if r15 is speci?ed as the base register (rn). when using r15 as the base register you must remember it contains an address 8 bytes on from the address of the current instruction. r15 should not be speci?ed as the register offset (rm). when r15 is the source register (rd) of a half-word store (strh) instruction, the stored address will be address of the instruction plus 12. 4.10.6 data aborts a transfer to or from a legal address may cause problems for a memory management system. for instance, in a system which uses virtual memory the required data may be absent from the main memory. the memory manager can signal a problem by taking the processor abor t input high whereupon the data abort trap will be taken. it is up to the system software to resolve the cause of the problem, then the instruction can be restarted and the original program continued. 4.10.7 instruction cycle times normal ldr(h,sh,sb) instructions take 1s + 1n + 1i ldr(h,sh,sb) pc take 2s + 2n + 1i incremental cycles. s,n and i are de?ned in 6.2 cycle types on page 6-2 . strh instructions take 2n incremental cycles to execute.
arm instruction set - ldr, str ARM7TDMI data sheet arm ddi 0029e 4-38 open access 4.10.8 assembler syntax {cond} rd,
ldr load from memory into a register str store from a register into memory {cond} two-character condition mnemonic. see table 4-2: condition code summary on page 4-5. h transfer halfword quantity sb load sign extended byte (only valid for ldr) sh load sign extended halfword (only valid for ldr) rd is an expression evaluating to a valid register number.
can be: 1 an expression which generates an address: the assembler will attempt to generate an instruction using the pc as a base and a corrected immediate of fset to address the location given by evaluating the expression. this will be a pc relative, pre-indexed address. if the address is out of range, an error will be generated. 2 a pre-indexed addressing speci?cation: [rn] offset of zero [rn,<#expression>]{!} of fset of bytes [rn,{+/-}rm]{!} offset of +/- contents of index register 3 a post-indexed addressing speci?cation: [rn],<#expression> of fset of bytes [rn],{+/-}rm offset of +/- contents of index register. rn and rm are expressions evaluating to a register number . if rn is r15 then the assembler will subtract 8 from the of fset value to allow for ARM7TDMI pipelining. in this case base write-back should not be speci?ed. {!} writes back the base register (set the w bit) if ! is present.
arm instruction set - ldr, str ARM7TDMI data sheet arm ddi 0029e 4-39 open access 4.10.9 examples ldrh r1,[r2,-r3]! ; load r1 from the contents of the ; halfword address contained in ; r2-r3 (both of which are registers) ; and write back address to r2 strh r3,[r4,#14] ; store the halfword in r3 at r14+14 ; but don't write back. ldrsb r8,[r2],#-223 ; load r8 with the sign extended ; contents of the byte address ; contained in r2 and write back ; r2-223 to r2. ldrnesh r11,[r0] ; conditionally load r11 with the sign ; extended contents of the halfword ; address contained in r0. here ; generate pc relative offset to ; address fred. ; store the halfword in r5 at address ; fred. strh r5, [pc, #(fred-here-8)] . fred
arm instruction set - ldm, stm ARM7TDMI data sheet arm ddi 0029e 4-40 open access 4.11 block data transfer (ldm, stm) the instruction is only executed if the condition is true. the various conditions are de?ned in table 4-2: condition code summary on page 4-5 . the instruction encoding is shown in figure 4-18: block data transfer instructions . block data transfer instructions are used to load (ldm) or store (stm) any subset of the currently visible registers. they support all possible stacking modes, maintaining full or empty stacks which can grow up or down memory, and are very ef?cient instructions for saving or restoring context, or for moving large blocks of data around main memory. 4.11.1 the register list the instruction can cause the transfer of any registers in the current bank (and non- user mode programs can also transfer to and from the user bank, see below). the register list is a 16 bit ?eld in the instruction, with each bit corresponding to a register . a 1 in bit 0 of the register ?eld will cause r0 to be transferred, a 0 will cause it not to be transferred; similarly bit 1 controls the transfer of r1, and so on. any subset of the registers, or all the registers, may be speci?ed. the only restriction is that the register list should not be empty. whenever r15 is stored to memory the stored value is the address of the stm instruction plus 12. figure 4-18: block data transfer instructions cond rn 0 15 16 19 20 21 24 25 27 28 31 p u w l 22 23 100 s register list base register load/store bit 0 = store to memory 1 = load from memory write-back bit 0 = no write-back 1 = write address into base up/down bit pre/post indexing bit 0 = down; subtract offset from base 1 = up; add offset to base 0 = post; add offset after transfer 1 = pre; add offset before transfer psr & force user bit 0 = do not load psr or force user mode 1 = load psr or force user mode condition field
arm instruction set - ldm, stm ARM7TDMI data sheet arm ddi 0029e 4-41 open access 4.11.2 addressing modes the transfer addresses are determined by the contents of the base register (rn), the pre/post bit (p) and the up/down bit (u). the registers are transferred in the order lowest to highest, so r15 (if in the list) will always be transferred last. the lowest register also gets transferred to/from the lowest memory address. by way of illustration, consider the transfer of r1, r5 and r7 in the case where rn=0x1000 and write back of the modi?ed base is required (w=1). figure 4-19: post-increment addressing , figure 4-20: pre-increment addressing , figure 4-21: post-decrement addressing and figure 4-22: pre-decrement addressing show the sequence of register transfers, the addresses used, and the value of rn after the instruction has completed. in all cases, had write back of the modi?ed base not been required (w=0), rn would have retained its initial value of 0x1000 unless it was also in the transfer list of a load multiple register instruction, when it would have been overwritten with the loaded value. 4.11.3 address alignment the address should normally be a word aligned quantity and non-word aligned addresses do not af fect the instruction. however , the bottom 2 bits of the address will appear on a[1:0] and might be interpreted by the memory system. figure 4-19: post-increment addressing 0x100c 0x1000 0x0ff4 rn 1 0x100c 0x1000 0x0ff4 2 r1 0x100c 0x1000 0x0ff4 3 0x100c 0x1000 0x0ff4 4 r1 r7 r5 r1 r5 rn
arm instruction set - ldm, stm ARM7TDMI data sheet arm ddi 0029e 4-42 open access figure 4-20: pre-increment addressing figure 4-21: post-decrement addressing 0x100c 0x1000 0x0ff4 rn 1 0x100c 0x1000 0x0ff4 2 r1 0x100c 0x1000 0x0ff4 3 0x100c 0x1000 0x0ff4 4 r1 r7 r5 r1 r5 rn 0x100c 0x1000 0x0ff4 rn 1 0x100c 0x1000 0x0ff4 2 r1 0x100c 0x1000 0x0ff4 3 0x100c 0x1000 0x0ff4 4 r1 r7 r5 r1 r5 rn
arm instruction set - ldm, stm ARM7TDMI data sheet arm ddi 0029e 4-43 open access figure 4-22: pre-decrement addressing 4.11.4 use of the s bit when the s bit is set in a ldm/stm instruction its meaning depends on whether or not r15 is in the transfer list and on the type of instruction. the s bit should only be set if the instruction is to execute in a privileged mode. ldm with r15 in transfer list and s bit set (mode changes) if the instruction is a ldm then spsr_ is transferred to cpsr at the same time as r15 is loaded. stm with r15 in transfer list and s bit set (user bank transfer) the registers transferred are taken from the user bank rather than the bank corresponding to the current mode. this is useful for saving the user state on process switches. base write-back should not be used when this mechanism is employed. r15 not in list and s bit set (user bank transfer) for both ldm and stm instructions, the user bank registers are transferred rather than the register bank corresponding to the current mode. this is useful for saving the user state on process switches. base write-back should not be used when this mechanism is employed. when the instruction is ldm, care must be taken not to read from a banked register during the following cycle (inserting a dummy instruction such as mov r0, r0 after the ldm will ensure safety). 0x100c 0x1000 0x0ff4 rn 1 0x100c 0x1000 0x0ff4 2 r1 0x100c 0x1000 0x0ff4 3 0x100c 0x1000 0x0ff4 4 r1 r7 r5 r1 r5 rn
arm instruction set - ldm, stm ARM7TDMI data sheet arm ddi 0029e 4-44 open access 4.11.5 use of r15 as the base r15 should not be used as the base register in any ldm or stm instruction. 4.11.6 inclusion of the base in the register list when write-back is speci?ed, the base is written back at the end of the second cycle of the instruction. during a stm, the ?rst register is written out at the start of the second cycle. a stm which includes storing the base, with the base as the ?rst register to be stored, will therefore store the unchanged value, whereas with the base second or later in the transfer order , will store the modi?ed value. a ldm will always overwrite the updated base if the base is in the list. 4.11.7 data aborts some legal addresses may be unacceptable to a memory management system, and the memory manager can indicate a problem with an address by taking the abort signal high. this can happen on any transfer during a multiple register load or store, and must be recoverable if ARM7TDMI is to be used in a virtual memory system. aborts during stm instructions if the abort occurs during a store multiple instruction, ARM7TDMI takes little action until the instruction completes, whereupon it enters the data abort trap. the memory manager is responsible for preventing erroneous writes to the memory. the only change to the internal state of the processor will be the modi?cation of the base register if write-back was speci?ed, and this must be reversed by software (and the cause of the abort resolved) before the instruction may be retried. aborts during ldm instructions when ARM7TDMI detects a data abort during a load multiple instruction, it modi?es the operation of the instruction to ensure that recovery is possible. 1 overwriting of registers stops when the abort happens. the aborting load will not take place but earlier ones may have overwritten registers. the pc is always the last register to be written and so will always be preserved. 2 the base register is restored, to its modi?ed value if write-back was requested. this ensures recoverability in the case where the base register is also in the transfer list, and may have been overwritten before the abort occurred. the data abort trap is taken when the load multiple has completed, and the system software must undo any base modi?cation (and resolve the cause of the abort) before restarting the instruction. 4.11.8 instruction cycle times normal ldm instructions take ns + 1n + 1i and ldm pc takes (n+1)s + 2n + 1i incremental cycles, where s,n and i are as de?ned in 6.2 cycle types on page 6-2 . stm instructions take (n-1)s + 2n incremental cycles to execute, where n is the number of words transferred.
arm instruction set - ldm, stm ARM7TDMI data sheet arm ddi 0029e 4-45 open access 4.11.9 assembler syntax {cond} rn{!},{^} where: {cond} two character condition mnemonic. see table 4-2: condition code summary on page 4-5. rn is an expression evaluating to a valid register number is a list of registers and register ranges enclosed in {} (e.g. {r0,r2- r7,r10}). {!} if present requests write-back (w=1), otherwise w=0 {^} if present set s bit to load the cpsr along with the pc, or force transfer of user bank when in privileged mode addressing mode names there are different assembler mnemonics for each of the addressing modes, depending on whether the instruction is being used to support stacks or for other purposes. the equivalence between the names and the values of the bits in the instruction are shown in the following table: fd, ed, f a, ea de?ne pre/post indexing and the up/down bit by reference to the form of stack required. the f and e refer to a full or empty stack, i.e. whether a pre-index has to be done (full) before storing to the stack. the a and d refer to whether the stack is ascending or descending. if ascending, a stm will go up and ldm down, if descending, vice-versa. ia, ib, da, db allow control when ldm/stm are not being used for stacks and simply mean increment after, increment before, decrement after, decrement before. name stack other l bit p bit u bit pre-increment load ldmed ldmib 1 1 1 post-increment load ldmfd ldmia 1 0 1 pre-decrement load ldmea ldmdb 1 1 0 post-decrement load ldmfa ldmda 1 0 0 pre-increment store stmfa stmib 0 1 1 post-increment store stmea stmia 0 0 1 pre-decrement store stmfd stmdb 0 1 0 post-decrement store stmed stmda 0 0 0 table 4-6: addressing mode names
arm instruction set - ldm, stm ARM7TDMI data sheet arm ddi 0029e 4-46 open access 4.11.10examples ldmfd sp!,{r0,r1,r2} ; unstack 3 registers. stmia r0,{r0-r15} ; save all registers. ldmfd sp!,{r15} ; r15 <- (sp),cpsr unchanged. ldmfd sp!,{r15}^ ; r15 <- (sp), cpsr <- spsr_mode ; (allowed only in privileged modes). stmfd r13,{r0-r14}^ ; save user mode regs on stack ; (allowed only in privileged modes). these instructions may be used to save state on subroutine entry, and restore it ef?ciently on return to the calling routine: stmed sp!,{r0-r3,r14} ; save r0 to r3 to use as workspace ; and r14 for returning. bl somewhere ; this nested call will overwrite r14 ldmed sp!,{r0-r3,r15} ; restore workspace and return.
arm instruction set - swp ARM7TDMI data sheet arm ddi 0029e 4-47 open access 4.12 single data swap (swp) figure 4-23: swap instruction the instruction is only executed if the condition is true. the various conditions are de?ned in table 4-2: condition code summary on page 4-5 . the instruction encoding is shown in figure 4-23: swap instruction . the data swap instruction is used to swap a byte or word quantity between a register and external memory. this instruction is implemented as a memory read followed by a memory write which are locked together (the processor cannot be interrupted until both operations have completed, and the memory manager is warned to treat them as inseparable). this class of instruction is particularly useful for implementing software semaphores. the swap address is determined by the contents of the base register (rn). the processor ?rst reads the contents of the swap address. then it writes the contents of the source register (rm) to the swap address, and stores the old memory contents in the destination register (rd). the same register may be speci?ed as both the source and destination. the lock output goes high for the duration of the read and write operations to signal to the external memory manager that they are locked together , and should be allowed to complete without interruption. this is important in multi-processor systems where the swap instruction is the only indivisible instruction which may be used to implement semaphores; control of the memory must not be removed from a processor while it is performing a locked operation. 4.12.1 bytes and words this instruction class may be used to swap a byte (b=1) or a word (b=0) between an ARM7TDMI register and memory. the swp instruction is implemented as a ldr followed by a str and the action of these is as described in the section on single data transfers. in particular , the description of big and little endian con?guration applies to the swp instruction. 0 11 12 15 16 19 20 27 28 31 23 7 8 4 3 condition field cond rn rd 1001 0000 rm 00 b 00010 22 21 destination register source register base register byte/word bit 0 = swap word quantity 1 = swap byte quantity
arm instruction set - swp ARM7TDMI data sheet arm ddi 0029e 4-48 open access 4.12.2 use of r15 do not use r15 as an operand (rd, rn or rs) in a swp instruction. 4.12.3 data aborts if the address used for the swap is unacceptable to a memory management system, the memory manager can ?ag the problem by driving abor t high. this can happen on either the read or the write cycle (or both), and in either case, the data abort trap will be taken. it is up to the system software to resolve the cause of the problem, then the instruction can be restarted and the original program continued. 4.12.4 instruction cycle times swap instructions take 1s + 2n +1i incremental cycles to execute, where s,n and i are as de?ned in 6.2 cycle types on page 6-2. 4.12.5 assembler syntax {cond}{b} rd,rm,[rn] {cond} two-character condition mnemonic. see table 4-2: condition code summary on page 4-5. {b} if b is present then byte transfer, otherwise word transfer rd,rm,rn are expressions evaluating to valid register numbers 4.12.6 examples swp r0,r1,[r2] ; load r0 with the word addressed by r2, and ; store r1 at r2. swpb r2,r3,[r4] ; load r2 with the byte addressed by r4, and ; store bits 0 to 7 of r3 at r4. swpeq r0,r0,[r1] ; conditionally swap the contents of the ; word addressed by r1 with r0.
arm instruction set - swi ARM7TDMI data sheet arm ddi 0029e 4-49 open access 4.13 software interrupt (swi) the instruction is only executed if the condition is true. the various conditions are de?ned in table 4-2: condition code summary on page 4-5 . the instruction encoding is shown in figure 4-24: software interrupt instruction , below. figure 4-24: software interrupt instruction the software interrupt instruction is used to enter supervisor mode in a controlled manner. the instruction causes the software interrupt trap to be taken, which effects the mode change. the pc is then forced to a ?xed value (0x08) and the cpsr is saved in spsr_svc. if the swi vector address is suitably protected (by external memory management hardware) from modi?cation by the user, a fully protected operating system may be constructed. 4.13.1 return from the supervisor the pc is saved in r14_svc upon entering the software interrupt trap, with the pc adjusted to point to the word after the swi instruction. movs pc,r14_svc will return to the calling program and restore the cpsr. note that the link mechanism is not re-entrant, so if the supervisor code wishes to use software interrupts within itself it must ?rst save a copy of the return address and spsr. 4.13.2 comment ?eld the bottom 24 bits of the instruction are ignored by the processor, and may be used to communicate information to the supervisor code. for instance, the supervisor may look at this ?eld and use it to index into an array of entry points for routines which perform the various supervisor functions. 4.13.3 instruction cycle times software interrupt instructions take 2s + 1n incremental cycles to execute, where s and n are as de?ned in 6.2 cycle types on page 6-2. 31 28 27 24 23 0 condition field 1111 cond comment field (ignored by processor)
arm instruction set - swi ARM7TDMI data sheet arm ddi 0029e 4-50 open access 4.13.4 assembler syntax swi{cond} {cond} two character condition mnemonic, table 4-2: condition code summary on page 4-5. is evaluated and placed in the comment ?eld (which is ignored by ARM7TDMI). 4.13.5 examples swi readc ; get next character from read stream. swi writei+k ; output a k to the write stream. swine 0 ; conditionally call supervisor ; with 0 in comment field. supervisor code the previous examples assume that suitable supervisor code exists, for instance: 0x08 b supervisor ; swi entry point entrytable ; addresses of supervisor routines dcd zerortn dcd readcrtn dcd writeirtn . . . zero equ 0 readc equ 256 writei equ 512 supervisor ; swi has routine required in bits 8-23 and data (if any) in ; bits 0-7. ; assumes r13_svc points to a suitable stack stmfd r13,{r0-r2,r14} ; save work registers and return ; address. ldr r0,[r14,#-4] ; get swi instruction. bic r0,r0,#0xff000000 ; clear top 8 bits. mov r1,r0,lsr#8 ; get routine offset. adr r2,entrytable ; get start address of entry table. ldr r15,[r2,r1,lsl#2] ; branch to appropriate routine. writeirtn ; enter with character in r0 bits 0-7. . . . . . . ldmfd r13,{r0-r2,r15}^ ; restore workspace and return, ; restoring processor mode and flags.
arm instruction set - cdp ARM7TDMI data sheet arm ddi 0029e 4-51 open access 4.14 coprocessor data operations (cdp) the instruction is only executed if the condition is true. the various conditions are de?ned in table 4-2: condition code summary on page 4-5 . the instruction encoding is shown in figure 4-25: coprocessor data operation instruction . this class of instruction is used to tell a coprocessor to perform some internal operation. no result is communicated back to ARM7TDMI, and it will not wait for the operation to complete. the coprocessor could contain a queue of such instructions awaiting execution, and their execution can overlap other activity, allowing the coprocessor and ARM7TDMI to perform independent tasks in parallel. figure 4-25: coprocessor data operation instruction 4.14.1 the coprocessor ?elds only bit 4 and bits 24 to 31 are signi?cant to ARM7TDMI. the remaining bits are used by coprocessors. the above ?eld names are used by convention, and particular coprocessors may rede?ne the use of all ?elds except cp# as appropriate. the cp# ?eld is used to contain an identifying number (in the range 0 to 15) for each coprocessor , and a coprocessor will ignore any instruction which does not contain its number in the cp# ?eld. the conventional interpretation of the instruction is that the coprocessor should perform an operation speci?ed in the cp opc ?eld (and possibly in the cp ?eld) on the contents of crn and crm, and place the result in crd. 4.14.2 instruction cycle times coprocessor data operations take 1s + bi incremental cycles to execute, where b is the number of cycles spent in the coprocessor busy-wait loop. s and i are as de?ned in 6.2 cycle types on page 6-2. cond 0 11 12 15 16 19 20 24 27 28 31 23 crd cp# 7 8 1110 cp opc crn cp 0 crm 5 4 3 coprocessor number condition field coprocessor information coprocessor operand register coprocessor destination register coprocessor operand register coprocessor operation code
arm instruction set - cdp ARM7TDMI data sheet arm ddi 0029e 4-52 open access 4.14.3 assembler syntax cdp{cond} p#,,cd,cn,cm{,} {cond} two character condition mnemonic. see table 4-2: condition code summary on page 4-5. p# the unique number of the required coprocessor evaluated to a constant and placed in the cp opc ?eld cd, cn and cm evaluate to the valid coprocessor register numbers crd, crn and crm respectively where present is evaluated to a constant and placed in the cp ?eld 4.14.4 examples cdp p1,10,c1,c2,c3 ; request coproc 1 to do operation 10 ; on cr2 and cr3, and put the result ; in cr1. cdpeq p2,5,c1,c2,c3,2 ; if z flag is set request coproc 2 ; to do operation 5 (type 2) on cr2 ; and cr3,and put the result in cr1.
arm instruction set - ldc, stc ARM7TDMI data sheet arm ddi 0029e 4-53 open access 4.15 coprocessor data transfers (ldc, stc) the instruction is only executed if the condition is true. the various conditions are de?ned in table 4-2: condition code summary on page 4-5 . the instruction encoding is shown in figure 4-26: coprocessor data transfer instructions . this class of instruction is used to load (ldc) or store (stc) a subset of a coprocessorss registers directly to memory. ARM7TDMI is responsible for supplying the memory address, and the coprocessor supplies or accepts the data and controls the number of words transferred. figure 4-26: coprocessor data transfer instructions 4.15.1 the coprocessor ?elds the cp# ?eld is used to identify the coprocessor which is required to supply or accept the data, and a coprocessor will only respond if its number matches the contents of this ?eld. the crd ?eld and the n bit contain information for the coprocessor which may be interpreted in different ways by different coprocessors, but by convention crd is the register to be transferred (or the ?rst register where more than one is to be transferred), and the n bit is used to choose one of two transfer length options. for instance n=0 could select the transfer of a single register, and n=1 could select the transfer of all the registers for context switching. cond rn 0 11 12 15 16 19 20 21 24 25 27 28 31 p u w l 22 23 110 n crd cp# offset 7 8 coprocessor number unsigned 8 bit immediate offset base register load/store bit 0 = store to memory 1 = load from memory write-back bit 0 = no write-back 1 = write address into base coprocessor source/destination register pre/post indexing bit up/down bit 0 = down; subtract offset from base 1 = up; add offset to base 0 = post; add offset after transfer transfer length condition field 1 = pre; add offset before transfer
arm instruction set - ldc, stc ARM7TDMI data sheet arm ddi 0029e 4-54 open access 4.15.2 addressing modes ARM7TDMI is responsible for providing the address used by the memory system for the transfer , and the addressing modes available are a subset of those used in single data transfer instructions. note, however, that the immediate offsets are 8 bits wide and specify word of fsets for coprocessor data transfers, whereas they are 12 bits wide and specify byte offsets for single data transfers. the 8 bit unsigned immediate offset is shifted left 2 bits and either added to (u=1) or subtracted from (u=0) the base register (rn); this calculation may be performed either before (p=1) or after (p=0) the base is used as the transfer address. the modi?ed base value may be overwritten back into the base register (if w=1), or the old value of the base may be preserved (w=0). note that post-indexed addressing modes require explicit setting of the w bit, unlike ldr and str which always write-back when post- indexed. the value of the base register, modi?ed by the offset in a pre-indexed instruction, is used as the address for the transfer of the ?rst word. the second word (if more than one is transferred) will go to or come from an address one word (4 bytes) higher than the ?rst transfer, and the address will be incremented by one word for each subsequent transfer. 4.15.3 address alignment the base address should normally be a word aligned quantity . the bottom 2 bits of the address will appear on a[1:0] and might be interpreted by the memory system. 4.15.4 use of r15 if rn is r15, the value used will be the address of the instruction plus 8 bytes. base write-back to r15 must not be speci?ed. 4.15.5 data aborts if the address is legal but the memory manager generates an abort, the data trap will be taken. the write-back of the modi?ed base will take place, but all other processor state will be preserved. the coprocessor is partly responsible for ensuring that the data transfer can be restarted after the cause of the abort has been resolved, and must ensure that any subsequent actions it undertakes can be repeated when the instruction is retried. 4.15.6 instruction cycle times coprocessor data transfer instructions take (n-1)s + 2n + bi incremental cycles to execute, where: n is the number of words transferred. b is the number of cycles spent in the coprocessor busy-wait loop. s, n and i are as de?ned in 6.2 cycle types on page 6-2.
arm instruction set - ldc, stc ARM7TDMI data sheet arm ddi 0029e 4-55 open access 4.15.7 assembler syntax {cond}{l} p#,cd,
ldc load from memory to coprocessor stc store from coprocessor to memory {l} when present perform long transfer (n=1), otherwise perform short transfer (n=0) {cond} two character condition mnemonic. see table 4-2: condition code summary on page 4-5. p# the unique number of the required coprocessor cd is an expression evaluating to a valid coprocessor register number that is placed in the crd ?eld
can be: 1 an expression which generates an address: the assembler will attempt to generate an instruction using the pc as a base and a corrected immediate of fset to address the location given by evaluating the expression. this will be a pc relative, pre-indexed address. if the address is out of range, an error will be generated. 2 a pre-indexed addressing speci?cation: [rn] offset of zero [rn,<#expression>]{!} of fset of bytes 3 a post-indexed addressing speci?cation: [rn],<#expression> of fset of bytes {!} write back the base register (set the w bit) if! is present rn is an expression evaluating to a valid ARM7TDMI register number. note if rn is r15, the assembler will subtract 8 from the offset value to allow for ARM7TDMI pipelining.
arm instruction set - ldc, stc ARM7TDMI data sheet arm ddi 0029e 4-56 open access 4.15.8 examples ldc p1,c2,table ; load c2 of coproc 1 from address ; table, using a pc relative address. stceql p2,c3,[r5,#24]!; conditionally store c3 of coproc 2 ; into an address 24 bytes up from r5, ; write this address back to r5, and use ; long transfer option (probably to ; store multiple words). note although the address offset is expressed in bytes, the instruction offset field is in words. the assembler will adjust the offset appropriately.
arm instruction set - mrc, mcr ARM7TDMI data sheet arm ddi 0029e 4-57 open access 4.16 coprocessor register transfers (mrc, mcr) the instruction is only executed if the condition is true. the various conditions are de?ned in table 4-2: condition code summary on page 4-5 . the instruction encoding is shown in figure 4-27: coprocessor register transfer instructions . this class of instruction is used to communicate information directly between ARM7TDMI and a coprocessor . an example of a coprocessor to ARM7TDMI register transfer (mrc) instruction would be a fix of a ?oating point value held in a coprocessor, where the ?oating point number is converted into a 32 bit integer within the coprocessor , and the result is then transferred to ARM7TDMI register . a floa t of a 32 bit value in ARM7TDMI register into a ?oating point value within the coprocessor illustrates the use of ARM7TDMI register to coprocessor transfer (mcr). an important use of this instruction is to communicate control information directly from the coprocessor into the ARM7TDMI cpsr ?ags. as an example, the result of a comparison of two ?oating point values within a coprocessor can be moved to the cpsr to control the subsequent ?ow of execution. figure 4-27: coprocessor register transfer instructions 4.16.1 the coprocessor ?elds the cp# ?eld is used, as for all coprocessor instructions, to specify which coprocessor is being called upon. the cp opc, crn, cp and crm ?elds are used only by the coprocessor, and the interpretation presented here is derived from convention only. other interpretations are allowed where the coprocessor functionality is incompatible with this one. the conventional interpretation is that the cp opc and cp ?elds specify the operation the coprocessor is required to perform, crn is the coprocessor register which is the 21 cond 0 11 12 15 16 19 20 24 27 28 31 23 cp# 7 8 1110 crn cp crm 5 4 3 1 l cp opc rd coprocessor number coprocessor information coprocessor operand register coprocessor operation mode condition field load/store bit 0 = store to co-processor 1 = load from co-processor arm source/destination register coprocessor source/destination register
arm instruction set - mrc, mcr ARM7TDMI data sheet arm ddi 0029e 4-58 open access source or destination of the transferred information, and crm is a second coprocessor register which may be involved in some way which depends on the particular operation speci?ed. 4.16.2 transfers to r15 when a coprocessor register transfer to ARM7TDMI has r15 as the destination, bits 31, 30, 29 and 28 of the transferred word are copied into the n, z, c and v ?ags respectively . the other bits of the transferred word are ignored, and the pc and other cpsr bits are unaffected by the transfer. 4.16.3 transfers from r15 a coprocessor register transfer from ARM7TDMI with r15 as the source register will store the pc+12. 4.16.4 instruction cycle times mrc instructions take 1s + (b+1)i +1c incremental cycles to execute, where s, i and c are as de?ned in 6.2 cycle types on page 6-2. mcr instructions take 1s + bi +1c incremental cycles to execute, where b is the number of cycles spent in the coprocessor busy-wait loop. 4.16.5 assembler syntax {cond} p#,,rd,cn,cm{,} mrc move from coprocessor to ARM7TDMI register (l=1) mcr move from ARM7TDMI register to coprocessor (l=0) {cond} two character condition mnemonic. see table 4-2: condition code summary on page 4-5. p# the unique number of the required coprocessor evaluated to a constant and placed in the cp opc ?eld rd is an expression evaluating to a valid ARM7TDMI register number cn and cm are expressions evaluating to the valid coprocessor register numbers crn and crm respectively where present is evaluated to a constant and placed in the cp ?eld
arm instruction set - mrc, mcr ARM7TDMI data sheet arm ddi 0029e 4-59 open access 4.16.6 examples mrc p2,5,r3,c5,c6 ; request coproc 2 to perform operation 5 ; on c5 and c6, and transfer the (single ; 32 bit word) result back to r3. mcr p6,0,r4,c5,c6 ; request coproc 6 to perform operation 0 ; on r4 and place the result in c6. mrceq p3,9,r3,c5,c6,2 ; conditionally request coproc 3 to ; perform operation 9 (type 2) on c5 and ; c6, and transfer the result back to r3.
arm instruction set - undefined ARM7TDMI data sheet arm ddi 0029e 4-60 open access 4.17 unde?ned instruction the instruction is only executed if the condition is true. the various conditions are de?ned in table 4-2: condition code summary on page 4-5. the instruction format is shown in figure 4-28: undefined instruction . figure 4-28: undefined instruction if the condition is true, the unde?ned instruction trap will be taken. note that the unde?ned instruction mechanism involves of fering this instruction to any coprocessors which may be present, and all coprocessors must refuse to accept it by driving cpa and cpb high. 4.17.1 instruction cycle times this instruction takes 2s + 1i + 1n cycles, where s, n and i are as de?ned in 6.2 cycle types on page 6-2. 4.17.2 assembler syntax the assembler has no mnemonics for generating this instruction. if it is adopted in the future for some speci?ed use, suitable mnemonics will be added to the assembler. until such time, this instruction must not be used. cond 0 24 27 28 31 5 4 3 1 011 xxxx 25 xxxxxxxxxxxxxxxxxxxx
arm instruction set - examples ARM7TDMI data sheet arm ddi 0029e 4-61 open access 4.18 instruction set examples the following examples show ways in which the basic ARM7TDMI instructions can combine to give ef ?cient code. none of these methods saves a great deal of execution time (although they may save some), mostly they just save code. 4.18.1 using the conditional instructions using conditionals for logical or cmp rn,#p ; if rn=p or rm=q then goto label. beq label cmp rm,#q beq label this can be replaced by cmp rn,#p cmpne rm,#q ; if condition not satisfied try ; other test. beq label absolute value teq rn,#0 ; test sign rsbmi rn,rn,#0 ; and 2's complement if necessary. multiplication by 4, 5 or 6 (run time) mov rc,ra,lsl#2 ; multiply by 4, cmp rb,#5 ; test value, addcs rc,rc,ra ; complete multiply by 5, addhi rc,rc,ra ; complete multiply by 6. combining discrete and range tests teq rc,#127 ; discrete test, cmpne rc,# -1 ; range test movls rc,#. ; if rc<= or rc=ascii(127) ; then rc:=. division and remainder a number of divide routines for speci?c applications are provided in source form as part of the ansi c library provided with the arm cross development t oolkit, available from your supplier. a short general purpose divide routine follows. ; enter with numbers in ra and rb. ; mov rcnt,#1 ; bit to control the division. div1 cmp rb,#0x80000000 ; move rb until greater than ra. cmpcc rb,ra movcc rb,rb,asl#1 movcc rcnt,rcnt,asl#1 bcc div1 mov rc,#0
arm instruction set - examples ARM7TDMI data sheet arm ddi 0029e 4-62 open access div2 cmp ra,rb ; test for possible subtraction. subcs ra,ra,rb ; subtract if ok, addcs rc,rc,rcnt ; put relevant bit into result movs rcnt,rcnt,lsr#1 ; shift control bit movne rb,rb,lsr#1 ; halve unless finished. bne div2 ; ; divide result in rc, ; remainder in ra. over?ow detection in the ARM7TDMI 1 over?ow in unsigned multiply with a 32 bit result umull rd,rt,rm,rn ;3 to 6 cycles teq rt,#0 ;+1 cycle and a register bne overflow 2 over?ow in signed multiply with a 32 bit result smull rd,rt,rm,rn ;3 to 6 cycles teq rt,rd asr#31 ;+1 cycle and a register bne overflow 3 over?ow in unsigned multiply accumulate with a 32 bit result umlal rd,rt,rm,rn ;4 to 7 cycles teq rt,#0 ;+1 cycle and a register bne overflow 4 over?ow in signed multiply accumulate with a 32 bit result smlal rd,rt,rm,rn ;4 to 7 cycles teq rt,rd, asr#31 ;+1 cycle and a register bne overflow 5 over?ow in unsigned multiply accumulate with a 64 bit result umull rl,rh,rm,rn ;3 to 6 cycles adds rl,rl,ra1 ;lower accumulate adc rh,rh,ra2 ;upper accumulate bcs overflow ;1 cycle and 2 registers 6 over?ow in signed multiply accumulate with a 64 bit result smull rl,rh,rm,rn ;3 to 6 cycles adds rl,rl,ra1 ;lower accumulate adc rh,rh,ra2 ;upper accumulate bvs overflow ;1 cycle and 2 registers note over?ow checking is not applicable to unsigned and signed multiplies with a 64-bit result, since over?ow does not occur in such calculations.
arm instruction set - examples ARM7TDMI data sheet arm ddi 0029e 4-63 open access 4.18.2 pseudo-random binary sequence generator it is often necessary to generate (pseudo-) random numbers and the most ef?cient algorithms are based on shift generators with exclusive-or feedback rather like a cyclic redundancy check generator . unfortunately the sequence of a 32 bit generator needs more than one feedback tap to be maximal length (i.e. 2^32-1 cycles before repetition), so this example uses a 33 bit register with taps at bits 33 and 20. the basic algorithm is newbit:=bit 33 eor bit 20, shift left the 33 bit number and put in newbit at the bottom; this operation is performed for all the newbits needed (i.e. 32 bits). the entire operation can be done in 5 s cycles: ; enter with seed in ra (32 bits), rb (1 bit in rb lsb), uses rc. ; tst rb,rb,lsr#1 ; top bit into carry movs rc,ra,rrx ; 33 bit rotate right adc rb,rb,rb ; carry into lsb of rb eor rc,rc,ra,lsl#12 ; (involved!) eor ra,rc,rc,lsr#20 ; (similarly involved!) ; new seed in ra, rb as before 4.18.3 multiplication by constant using the barrel shifter multiplication by 2^n (1,2,4,8,16,32..) mov ra, rb, lsl #n multiplication by 2^n+1 (3,5,9,17..) addra,ra,ra,lsl #n multiplication by 2^n-1 (3,7,15..) rsb ra,ra,ra,lsl #n multiplication by 6 add ra,ra,ra,lsl #1; multiply by 3 mov ra,ra,lsl#1; and then by 2 multiply by 10 and add in extra number add ra,ra,ra,lsl#2; multiply by 5 add ra,rc,ra,lsl#1; multiply by 2 and add in next digit general recursive method for rb := ra*c, c a constant: 1 if c even, say c = 2^n*d, d odd: d=1: mov rb,ra,lsl #n d<>1: {rb := ra*d} mov rb,rb,lsl #n 2 if c mod 4 = 1, say c = 2^n*d+1, d odd, n>1: d=1: add rb,ra,ra,lsl #n
arm instruction set - examples ARM7TDMI data sheet arm ddi 0029e 4-64 open access d<>1: {rb := ra*d} add rb,ra,rb,lsl #n 3 if c mod 4 = 3, say c = 2^n*d-1, d odd, n>1: d=1: rsb rb,ra,ra,lsl #n d<>1: {rb := ra*d} rsb rb,ra,rb,lsl #n this is not quite optimal, but close. an example of its non-optimality is multiply by 45 which is done by: rsb rb,ra,ra,lsl#2 ; multiply by 3 rsb rb,ra,rb,lsl#2 ; multiply by 4*3-1 = 11 add rb,ra,rb,lsl# 2; multiply by 4*11+1 = 45 rather than by: add rb,ra,ra,lsl#3 ; multiply by 9 add rb,rb,rb,lsl#2 ; multiply by 5*9 = 45 4.18.4 loading a word from an unknown alignment ; enter with address in ra (32 bits) ; uses rb, rc; result in rd. ; note d must be less than c e.g. 0,1 ; bic rb,ra,#3 ; get word aligned address ldmia rb,{rd,rc} ; get 64 bits containing answer and rb,ra,#3 ; correction factor in bytes movs rb,rb,lsl#3 ; ...now in bits and test if aligned movne rd,rd,lsr rb ; produce bottom of result word ; (if not aligned) rsbne rb,rb,#32 ; get other shift amount orrne rd,rd,rc,lsl rb; combine two halves to get result
ARM7TDMI data sheet arm ddi 0029e 5-1 11 1 open access thumb instruction set this chapter describes the thumb instruction set. format summary 5-2 opcode summary 5-3 5.1 format 1: move shifted register 5-5 5.2 format 2: add/subtract 5-7 5.3 format 3: move/compare/add/subtract immediate 5-9 5.4 format 4: alu operations 5-11 5.5 format 5: hi register operations/branch exchange 5-13 5.6 format 6: pc-relative load 5-16 5.7 format 7: load/store with register offset 5-18 5.8 format 8: load/store sign-extended byte/halfword 5-20 5.9 format 9: load/store with immediate offset 5-22 5.10 format 10: load/store halfword 5-24 5.11 format 11: sp-relative load/store 5-26 5.12 format 12: load address 5-28 5.13 format 13: add offset to stack pointer 5-30 5.14 format 14: push/pop registers 5-32 5.15 format 15: multiple load/store 5-34 5.16 format 16: conditional branch 5-36 5.17 format 17: software interrupt 5-38 5.18 format 18: unconditional branch 5-39 5.19 format 19: long branch with link 5-40 5.20 instruction set examples 5-42 5
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-2 open access format summary the thumb instruction set formats are shown in the following ?gure. figure 5-1: thumb instruction set formats 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 0 0 0 op offset5 rs rd move shifted register 2 0 0 0 1 1 i op rn/offset3 rs rd add/subtract 3 0 0 1 op rd offset8 move/compare/add /subtract immediate 4 0 1 0 0 0 0 op rs rd alu operations 5 0 1 0 0 0 1 op h1 h2 rs/hs rd/hd hi register operations /branch exchange 6 0 1 0 0 1 rd word8 pc-relative load 7 0 1 0 1 l b 0 ro rb rd load/store with register offset 8 0 1 0 1 h s 1 ro rb rd load/store sign-extended byte/halfword 9 0 1 1 b l offset5 rb rd load/store with immediate offset 10 1 0 0 0 l offset5 rb rd load/store halfword 11 1 0 0 1 l rd word8 sp-relative load/store 12 1 0 1 0 sp rd word8 load address 13 1 0 1 1 0 0 0 0 s sword7 add offset to stack pointer 14 1 0 1 1 l 1 0 r rlist push/pop registers 15 1 1 0 0 l rb rlist multiple load/store 16 1 1 0 1 cond soffset8 conditional branch 17 1 1 0 1 1 1 1 1 value8 software interrupt 18 1 1 1 0 0 offset11 unconditional branch 19 1 1 1 1 h offset long branch with link 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-3 open access opcode summary the following table summarizes the thumb instruction set. for further information about a particular instruction please refer to the sections listed in the right-most column. mnemonic instruction lo register operand hi register operand condition codes set see section: adc add with carry 4 4 5.4 add add 4 4 4 5.1.3, 5.5, 5.12, 5.13 and and 4 4 5.4 asr arithmetic shift right 4 4 5.1, 5.4 b unconditional branch 4 5.16 b xx conditional branch 4 5.17 bic bit clear 4 4 5.4 bl branch and link 5.19 bx branch and exchange 4 4 5.5 cmn compare negative 4 4 5.4 cmp compare 4 4 4 5.3, 5.4, 5.5 eor eor 4 4 5.4 ldmia load multiple 4 5.15 ldr load word 4 5.7, 5.6, 5.9, 5.11 ldrb load byte 4 5.7, 5.9 ldrh load halfword 4 5.8, 5.10 lsl logical shift left 4 4 5.1, 5.4 ldsb load sign-extended byte 4 5.8 ldsh load sign-extended halfword 4 5.8 lsr logical shift right 4 4 5.1, 5.4 mov move register 4 4 4 5.3, 5.5 mul multiply 4 4 5.4 mvn move negative register 4 4 5.4 table 5-1: thumb instruction set opcodes
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-4 open access the condition codes are unaffected by the format 5, 12 and 13 versions of this instruction. the condition codes are unaffected by the format 5 version of this instruction. neg negate 4 4 5.4 orr or 4 4 5.4 pop pop registers 4 5.14 push push registers 4 5.14 ror rotate right 4 4 5.4 sbc subtract with carry 4 4 5.4 stmia store multiple 4 5.15 str store word 4 5.7, 5.9, 5.11 strb store byte 4 5.7 strh store halfword 4 5.8, 5.10 swi software interrupt 5.17 sub subtract 4 4 5.1.3, 5.3 tst test bits 4 4 5.4 mnemonic instruction lo register operand hi register operand condition codes set see section: table 5-1: thumb instruction set opcodes (continued)
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-5 open access 5.1 format 1: move shifted register figure 5-2: format 1 5.1.1 operation these instructions move a shifted value between lo registers. the thumb assembler syntax is shown in table 5-2: summary of format 1 instructions . note all instructions in this group set the cpsr condition codes. op thumb assembler arm equivalent action 00 lsl rd, rs, #offset5 movs rd, rs, lsl #offset5 shift rs left by a 5-bit immediate value and store the result in rd. 01 lsr rd, rs, #offset5 movs rd, rs, lsr #offset5 perform logical shift right on rs by a 5- bit immediate value and store the result in rd. 10 asr rd, rs, #offset5 movs rd, rs, asr #offset5 perform arithmetic shift right on rs by a 5-bit immediate value and store the result in rd. table 5-2: summary of format 1 instructions 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 offset5 rs 0 0 0 destination register source register immediate value opcode op rd 0 - lsl 1 - lsr 2 - asr
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-6 open access 5.1.2 instruction cycle times all instructions in this format have an equivalent arm instruction as shown in table 5-2: summary of format 1 instructions on page 5-5 . the instruction cycle times for the thumb instruction are identical to that of the equivalent arm instruction. for more information on instruction cycle times, please refer to chapter 10, instruction cycle operations . 5.1.3 examples lsr r2, r5, #27 ; logical shift right the contents ; of r5 by 27 and store the result in r2. ; set condition codes on the result.
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-7 open access 5.2 format 2: add/subtract figure 5-3: format 2 5.2.1 operation these instructions allow the contents of a lo register or a 3-bit immediate value to be added to or subtracted from a lo register . the thumb assembler syntax is shown in table 5-3: summary of format 2 instructions . note all instructions in this group set the cpsr condition codes. op i thumb assembler arm equivalent action 0 0 add rd, rs, rn adds rd, rs, rn add contents of rn to contents of rs. place result in rd. 0 1 add rd, rs, #offset3 adds rd, rs, #offset3 add 3-bit immediate value to contents of rs. place result in rd. 1 0 sub rd, rs, rn subs rd, rs, rn subtract contents of rn from contents of rs. place result in rd. 1 1 sub rd, rs, #offset3 subs rd, rs, #offset3 subtract 3-bit immediate value from contents of rs. place result in rd. table 5-3: summary of format 2 instructions 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 rn/offset3 rs 1 0 0 0 destination register opcode source register 0 - add register/ 1 - sub immediate value immediate flag 0 - register operand 1 - immediate operand 1 i op rd
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-8 open access 5.2.2 instruction cycle times all instructions in this format have an equivalent arm instruction as shown in table 5-3: summary of format 2 instructions on page 5-7 . the instruction cycle times for the thumb instruction are identical to that of the equivalent arm instruction. for more information on instruction cycle times, please refer to chapter 10, instruction cycle operations . 5.2.3 examples add r0, r3, r4 ; r0 := r3 + r4 and set condition codes on ; the result. sub r6, r2, #6 ; r6 := r2 - 6 and set condition codes.
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-9 open access 5.3 format 3: move/compare/add/subtract immediate figure 5-4: format 3 5.3.1 operations the instructions in this group perform operations between a lo register and an 8-bit immediate value. the thumb assembler syntax is shown in table 5-4: summary of format 3 instructions . note all instructions in this group set the cpsr condition codes. op thumb assembler arm equivalent action 00 mov rd, #offset8 movs rd, #offset8 move 8-bit immediate value into rd. 01 cmp rd, #offset8 cmp rd, #offset8 compare contents of rd with 8-bit immediate value. 10 add rd, #offset8 adds rd, rd, #offset8 add 8-bit immediate value to contents of rd and place the result in rd. 11 sub rd, #offset8 subs rd, rd, #offset8 subtract 8-bit immediate value from contents of rd and place the result in rd. table 5-4: summary of format 3 instructions 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 rd op 1 0 0 offset8 source/destination register immediate value opcode 0 - mov 1 - cmp 2 - add 3 sub
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-10 open access 5.3.2 instruction cycle times all instructions in this format have an equivalent arm instruction as shown in table 5-4: summary of format 3 instructions on page 5-9 . the instruction cycle times for the thumb instruction are identical to that of the equivalent arm instruction. for more information on instruction cycle times, please refer to chapter 10, instruction cycle operations . 5.3.3 examples mov r0, #128 ; r0 := 128 and set condition codes cmp r2, #62 ; set condition codes on r2 - 62 add r1, #255 ; r1 := r1 + 255 and set condition ; codes sub r6, #145 ; r6 := r6 - 145 and set condition ; codes
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-11 open access 5.4 format 4: alu operations figure 5-5: format 4 5.4.1 operation the following instructions perform alu operations on a lo register pair. note all instructions in this group set the cpsr condition codes. op thumb assembler arm equivalent action 0000 and rd, rs ands rd, rd, rs rd:= rd and rs 0001 eor rd, rs eors rd, rd, rs rd:= rd eor rs 0010 lsl rd, rs movs rd, rd, lsl rs rd := rd << rs 0011 lsr rd, rs movs rd, rd, lsr rs rd := rd >> rs 0100 asr rd, rs movs rd, rd, asr rs rd := rd asr rs 0101 adc rd, rs adcs rd, rd, rs rd := rd + rs + c-bit 0110 sbc rd, rs sbcs rd, rd, rs rd := rd - rs - not c-bit 0111 ror rd, rs movs rd, rd, ror rs rd := rd ror rs 1000 tst rd, rs tst rd, rs set condition codes on rd and rs 1001 neg rd, rs rsbs rd, rs, #0 rd = -rs table 5-5: summary of format 4 instructions 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 op rs 0 1 0 source/destination source register 2 opcode rd register 0 0 0
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-12 open access 5.4.2 instruction cycle times all instructions in this format have an equivalent arm instruction as shown in table 5-5: summary of format 4 instructions on page 5-11. the instruction cycle times for the thumb instruction are identical to that of the equivalent arm instruction. for more information on instruction cycle times, please refer to chapter 10, instruction cycle operations . 5.4.3 examples eor r3, r4 ; r3 := r3 eor r4 and set condition codes ror r1, r0 ; rotate right r1 by the value in r0, store ; the result in r1 and set condition codes neg r5, r3 ; subtract the contents of r3 from zero, ; store the result in r5. set condition codes ; ie r5 = -r3 cmp r2, r6 ; set the condition codes on the result of ; r2 - r6 mul r0, r7 ; r0 := r7 * r0 and set condition codes 1010 cmp rd, rs cmp rd, rs set condition codes on rd - rs 1011 cmn rd, rs cmn rd, rs set condition codes on rd + rs 1100 orr rd, rs orrs rd, rd, rs rd := rd or rs 1101 mul rd, rs muls rd, rs, rd rd := rs * rd 1110 bic rd, rs bics rd, rd, rs rd := rd and not rs 1111 mvn rd, rs mvns rd, rs rd := not rs op thumb assembler arm equivalent action table 5-5: summary of format 4 instructions (continued)
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-13 open access 5.5 format 5: hi register operations/branch exchange figure 5-6: format 5 5.5.1 operation there are four sets of instructions in this group. the ?rst three allow add, cmp and mov operations to be performed between lo and hi registers, or a pair of hi registers. the fourth, bx, allows a branch to be performed which may also be used to switch processor state. the thumb assembler syntax is shown in table 5-6: summary of format 5 instructions note in this group only cmp (op = 01) sets the cpsr condition codes. the action of h1= 0, h2 = 0 for op = 00 (add), op =01 (cmp) and op = 10 (mov) is unde?ned, and should not be used. op h1 h2 thumb assembler arm equivalent action 00 0 1 add rd, hs add rd, rd, hs add a register in the range 8-15 to a register in the range 0-7. 00 1 0 add hd, rs add hd, hd, rs add a register in the range 0-7 to a register in the range 8-15. 00 1 1 add hd, hs add hd, hd, hs add two registers in the range 8-15 table 5-6: summary of format 5 instructions 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 op 0 1 0 rs/hs destination register source register 0 0 h1 opcode 1 h2 hi operand flag 2 hi operand flag 1 rd/hd
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-14 open access 5.5.2 instruction cycle times all instructions in this format have an equivalent arm instruction as shown in table 5-6: summary of format 5 instructions on page 5-13 . the instruction cycle times for the thumb instruction are identical to that of the equivalent arm instruction. for more information on instruction cycle times, please refer to chapter 10, instruction cycle operations . 5.5.3 the bx instruction bx performs a branch to a routine whose start address is speci?ed in a lo or hi register. bit 0 of the address determines the processor state on entry to the routine: bit 0 = 0 causes the processor to enter arm state. bit 0 = 1 causes the processor to enter thumb state. note the action of h1 = 1 for this instruction is unde?ned, and should not be used. 01 0 1 cmp rd, hs cmp rd, hs compare a register in the range 0-7 with a register in the range 8-15. set the condition code flags on the result. 01 1 0 cmp hd, rs cmp hd, rs compare a register in the range 8-15 with a register in the range 0-7. set the condition code flags on the result. 01 1 1 cmp hd, hs cmp hd, hs compare two registers in the range 8- 15. set the condition code flags on the result. 10 0 1 mov rd, hs mov rd, hs move a value from a register in the range 8-15 to a register in the range 0- 7. 10 1 0 mov hd, rs mov hd, rs move a value from a register in the range 0-7 to a register in the range 8- 15. 10 1 1 mov hd, hs mov hd, hs move a value between two registers in the range 8-15. 11 0 0 bx rs bx rs perform branch (plus optional state change) to address in a register in the range 0-7. 11 0 1 bx hs bx hs perform branch (plus optional state change) to address in a register in the range 8-15. op h1 h2 thumb assembler arm equivalent action table 5-6: summary of format 5 instructions (continued)
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-15 open access 5.5.4 examples hi register operations add pc, r5 ; pc := pc + r5 but don't set the ; condition codes. cmp r4, r12 ; set the condition codes on the ; result of r4 - r12. mov r15, r14 ; move r14 (lr) into r15 (pc) ; but don't set the condition codes, ; eg. return from subroutine. branch and exchange ; switch from thumb to arm state. adr r1,outofthumb ; load address of outofthumb ; into r1. mov r11,r1 bx r11 ; transfer the contents of r11 into ; the pc. ; bit 0 of r11 determines whether ; arm or thumb state is entered, ie. ; arm state here. ... align code32 outofthumb ; now processing arm instructions... 5.5.5 using r15 as an operand if r15 is used as an operand, the value will be the address of the instruction + 4 with bit 0 cleared. executing a bx pc in thumb state from a non-word aligned address will result in unpredictable execution.
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-16 open access 5.6 format 6: pc-relative load figure 5-7: format 6 5.6.1 operation this instruction loads a word from an address speci?ed as a 10-bit immediate offset from the pc. the thumb assembler syntax is shown below. note the value speci?ed by #imm is a full 10-bit address, but must always be word-aligned (ie with bits 1:0 set to 0), since the assembler places #imm >> 2 in ?eld word8. note the value of the pc will be 4 bytes greater than the address of this instruction, but bit 1 of the pc is forced to 0 to ensure it is word aligned. thumb assembler arm equivalent action ldr rd, [pc, #imm] ldr rd, [r15, #imm] add unsigned offset (255 words, 1020 bytes) in imm to the current value of the pc. load the word from the resulting address into rd. table 5-7: summary of pc-relative load instruction 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 rd 0 1 0 word8 destination register immediate value 0 1
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-17 open access 5.6.2 instruction cycle times all instructions in this format have an equivalent arm instruction as shown in table 5-7: summary of pc-relative load instruction on page 5-16 . the instruction cycle times for the thumb instruction are identical to that of the equivalent arm instruction. for more information on instruction cycle times, please refer to chapter 10, instruction cycle operations . 5.6.3 examples ldr r3,[pc,#844] ; load into r3 the word found at the ; address formed by adding 844 to pc. ; bit[1] of pc is forced to zero. ; note that the thumb opcode will contain ; 211 as the word8 value.
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-18 open access 5.7 format 7: load/store with register offset figure 5-8: format 7 5.7.1 operation these instructions transfer byte or word values between registers and memory. memory addresses are pre-indexed using an offset register in the range 0-7. the thumb assembler syntax is shown in table 5-8: summary of format 7 instructions . l b thumb assembler arm equivalent action 0 0 str rd, [rb, ro] str rd, [rb, ro] pre-indexed word store: calculate the target address by adding together the value in rb and the value in ro. store the contents of rd at the address. table 5-8: summary of format 7 instructions 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ro rb l 0 1 0 source/destination base register offset register 1 b 0 rd byte/word flag load/store flag 0 - transfer word quantity 1 - transfer byte quantity 0 - store to memory 1 - load from memory register
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-19 open access 5.7.2 instruction cycle times all instructions in this format have an equivalent arm instruction as shown in table 5-8: summary of format 7 instructions on page 5-18 . the instruction cycle times for the thumb instruction are identical to that of the equivalent arm instruction. for more information on instruction cycle times, please refer to chapter 10, instruction cycle operations . 5.7.3 examples str r3, [r2,r6] ; store word in r3 at the address ; formed by adding r6 to r2. ldrb r2, [r0,r7] ; load into r2 the byte found at ; the address formed by adding ; r7 to r0. 0 1 strb rd, [rb, ro] strb rd, [rb, ro] pre-indexed byte store: calculate the target address by adding together the value in rb and the value in ro. store the byte value in rd at the resulting address. 1 0 ldr rd, [rb, ro] ldr rd, [rb, ro] pre-indexed word load: calculate the source address by adding together the value in rb and the value in ro. load the contents of the address into rd. 1 1 ldrb rd, [rb, ro] ldrb rd, [rb, ro] pre-indexed byte load: calculate the source address by adding together the value in rb and the value in ro. load the byte value at the resulting address. l b thumb assembler arm equivalent action table 5-8: summary of format 7 instructions (continued)
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-20 open access 5.8 format 8: load/store sign-extended byte/halfword figure 5-9: format 8 5.8.1 operation these instructions load optionally sign-extended bytes or halfwords, and store halfwords. the thumb assembler syntax is shown below. s h thumb assembler arm equivalent action 0 0 strh rd, [rb, ro] strh rd, [rb, ro] store halfword: add ro to base address in rb. store bits 0- 15 of rd at the resulting address. 0 1 ldrh rd, [rb, ro] ldrh rd, [rb, ro] load halfword: add ro to base address in rb. load bits 0- 15 of rd from the resulting address, and set bits 16-31 of rd to 0. 1 0 ldsb rd, [rb, ro] ldrsb rd, [rb, ro] load sign-extended byte: add ro to base address in rb. load bits 0- 7 of rd from the resulting address, and set bits 8-31 of rd to bit 7. table 5-9: summary of format 8 instructions 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ro rb h 0 1 0 destination register base register offset register h flag 1 s 1 rd sign-extended flag 0 - operand not sign-extended 1 - operand sign-extended
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-21 open access 5.8.2 instruction cycle times all instructions in this format have an equivalent arm instruction as shown in table 5-9: summary of format 8 instructions on page 5-20 . the instruction cycle times for the thumb instruction are identical to that of the equivalent arm instruction. for more information on instruction cycle times, please refer to chapter 10, instruction cycle operations . 5.8.3 examples strh r4, [r3, r0] ; store the lower 16 bits of r4 at the ; address formed by adding r0 to r3. ldsb r2, [r7, r1] ; load into r2 the sign extended byte ; found at the address formed by adding ; r1 to r7. ldsh r3, [r4, r2] ; load into r3 the sign extended halfword ; found at the address formed by adding ; r2 to r4. 1 1 ldsh rd, [rb, ro] ldrsh rd, [rb, ro] load sign-extended halfword: add ro to base address in rb. load bits 0- 15 of rd from the resulting address, and set bits 16-31 of rd to bit 15. s h thumb assembler arm equivalent action table 5-9: summary of format 8 instructions (continued)
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-22 open access 5.9 format 9: load/store with immediate offset figure 5-10: format 9 5.9.1 operation these instructions transfer byte or word values between registers and memory using an immediate 5 or 7-bit offset. the thumb assembler syntax is shown in table 5-10: summary of format 9 instructions . l b thumb assembler arm equivalent action 0 0 str rd, [rb, #imm] str rd, [rb, #imm] calculate the target address by adding together the value in rb and imm. store the contents of rd at the address. 1 0 ldr rd, [rb, #imm] ldr rd, [rb, #imm] calculate the source address by adding together the value in rb and imm. load rd from the address. table 5-10: summary of format 9 instructions 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 offset5 rb l 1 1 0 source/destination base register offset value b rd byte/word flag load/store flag 0 - transfer word quantity 1 - transfer byte quantity 0 - store to memory 1 - load from memory register
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-23 open access note for word accesses (b = 0), the value speci?ed by #imm is a full 7-bit address, but must be word-aligned (ie with bits 1:0 set to 0), since the assembler places #imm >> 2 in the offset5 ?eld. 5.9.2 instruction cycle times all instructions in this format have an equivalent arm instruction as shown in table 5-10: summary of format 9 instructions on page 5-22. the instruction cycle times for the thumb instruction are identical to that of the equivalent arm instruction. for more information on instruction cycle times, please refer to chapter 10, instruction cycle operations . 5.9.3 examples ldr r2, [r5,#116] ; load into r2 the word found at the ; address formed by adding 116 to r5. ; note that the thumb opcode will ; contain 29 as the offset5 value. strb r1, [r0,#13] ; store the lower 8 bits of r1 at the ; address formed by adding 13 to r0. ; note that the thumb opcode will ; contain 13 as the offset5 value. 0 1 strb rd, [rb, #imm] strb rd, [rb, #imm] calculate the target address by adding together the value in rb and imm. store the byte value in rd at the address. 1 1 ldrb rd, [rb, #imm] ldrb rd, [rb, #imm] calculate source address by adding together the value in rb and imm. load the byte value at the address into rd. l b thumb assembler arm equivalent action table 5-10: summary of format 9 instructions (continued)
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-24 open access 5.10 format 10: load/store halfword figure 5-11: format 10 5.10.1 operation these instructions transfer halfword values between a lo register and memory. addresses are pre-indexed, using a 6-bit immediate value. the thumb assembler syntax is shown in table 5-11: halfword data transfer instructions . note #imm is a full 6-bit address but must be halfword-aligned (ie with bit 0 set to 0) since the assembler places #imm >> 1 in the offset5 ?eld. l thumb assembler arm equivalent action 0 strh rd, [rb, #imm] strh rd, [rb, #imm] add #imm to base address in rb and store bits 0-15 of rd at the resulting address. 1 ldrh rd, [rb, #imm] ldrh rd, [rb, #imm] add #imm to base address in rb. load bits 0-15 from the resulting address into rd and set bits 16-31 to zero. table 5-11: halfword data transfer instructions 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 offset5 rb l 0 0 1 source/destination base register immediate value 0 rd register load/store bit 0 - store to memory 1 - load from memory
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-25 open access 5.10.2 instruction cycle times all instructions in this format have an equivalent arm instruction as shown in table 5-11: halfword data transfer instructions on page 5-24 . the instruction cycle times for the thumb instruction are identical to that of the equivalent arm instruction. for more information on instruction cycle times, please refer to chapter 10, instruction cycle operations . 5.10.3 examples strh r6, [r1, #56] ; store the lower 16 bits of r4 at ; the address formed by adding 56 ; r1. ; note that the thumb opcode will ; contain 28 as the offset5 value. ldrh r4, [r7, #4] ; load into r4 the halfword found at ; the address formed by adding 4 to r7. ; note that the thumb opcode will contain ; 2 as the offset5 value.
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-26 open access 5.11 format 11: sp-relative load/store figure 5-12: format 11 5.11.1 operation the instructions in this group perform an sp-relative load or store.the thumb assembler syntax is shown in the following table. note the of fset supplied in #imm is a full 10-bit address, but must always be word-aligned (ie bits 1:0 set to 0), since the assembler places #imm >> 2 in the word8 ?eld. l thumb assembler arm equivalent action 0 str rd, [sp, #imm] str rd, [r13 #imm] add unsigned offset (255 words, 1020 bytes) in imm to the current value of the sp (r7). store the contents of rd at the resulting address. 1 ldr rd, [sp, #imm] ldr rd, [r13 #imm] add unsigned offset (255 words, 1020 bytes) in imm to the current value of the sp (r7). load the word from the resulting address into rd. table 5-12: sp-relative load/store instructions 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 rd 0 0 1 word8 destination register immediate value 1 l load/store bit 0 - store to memory 1 - load from memory
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-27 open access 5.11.2 instruction cycle times all instructions in this format have an equivalent arm instruction as shown in table 5-12: sp-relative load/store instructions on page 5-26 . the instruction cycle times for the thumb instruction are identical to that of the equivalent arm instruction. for more information on instruction cycle times, please refer to chapter 10, instruction cycle operations . 5.11.3 examples str r4, [sp,#492] ; store the contents of r4 at the address ; formed by adding 492 to sp (r13). ; note that the thumb opcode will contain ; 123 as the word8 value.
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-28 open access 5.12 format 12: load address figure 5-13: format 12 5.12.1 operation these instructions calculate an address by adding an 10-bit constant to either the pc or the sp, and load the resulting address into a register. the thumb assembler syntax is shown in the following table. note the value speci?ed by #imm is a full 10-bit value, but this must be word-aligned (ie with bits 1:0 set to 0) since the assembler places #imm >> 2 in ?eld word8. where the pc is used as the source register (sp = 0), bit 1 of the pc is always read as 0. the value of the pc will be 4 bytes greater than the address of the instruction before bit 1 is forced to 0. the cpsr condition codes are unaffected by these instructions. sp thumb assembler arm equivalent action 0 add rd, pc, #imm add rd, r15, #imm add #imm to the current value of the program counter (pc) and load the result into rd. 1 add rd, sp, #imm add rd, r13, #imm add #imm to the current value of the stack pointer (sp) and load the result into rd. table 5-13: load address 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 rd 1 0 1 0 sp word8 8-bit unsigned constant destination register source 0 - pc 1 - sp
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-29 open access 5.12.2 instruction cycle times all instructions in this format have an equivalent arm instruction as shown in table 5-13: load address on page 5-28. the instruction cycle times for the thumb instruction are identical to that of the equivalent arm instruction. for more information on instruction cycle times, please refer to chapter 10, instruction cycle operations . 5.12.3 examples add r2, pc, #572 ; r2 := pc + 572, but don't set the ; condition codes. bit[1] of pc is ; forced to zero. ; note that the thumb opcode will ; contain 143 as the word8 value. add r6, sp, #212 ; r6 := sp (r13) + 212, but don't ; set the condition codes. ; note that the thumb opcode will ; contain 53 as the word8 value.
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-30 open access 5.13 format 13: add offset to stack pointer figure 5-14: format 13 5.13.1 operation this instruction adds a 9-bit signed constant to the stack pointer. the following table shows the thumb assembler syntax. note the offset speci?ed by #imm can be up to -/+ 508, but must be word-aligned (ie with bits 1:0 set to 0) since the assembler converts #imm to an 8-bit sign + magnitude number before placing it in ?eld sword7. note the condition codes are not set by this instruction. 5.13.2 instruction cycle times all instructions in this format have an equivalent arm instruction as shown in table 5-14: the add sp instruction on page 5-30. the instruction cycle times for the thumb instruction are identical to that of the equivalent arm instruction. for more information on instruction cycle times, please refer to chapter 10, instruction cycle operations s thumb assembler arm equivalent action 0 add sp, #imm add r13, r13, #imm add #imm to the stack pointer (sp). 1 add sp, #-imm sub r13, r13, #imm add #-imm to the stack pointer (sp). table 5-14: the add sp instruction 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 0 1 1 7-bit immediate value sword7 0 0 0 0 s sign flag 0 -offset is positive 1 -offset is negative
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-31 open access 5.13.3 examples add sp, #268 ; sp (r13) := sp + 268, but don't set ; the condition codes. ; note that the thumb opcode will ; contain 67 as the word7 value and s=0. add sp, #-104 ; sp (r13) := sp - 104, but don't set ; the condition codes. ; note that the thumb opcode will contain ; 26 as the word7 value and s=1.
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-32 open access 5.14 format 14: push/pop registers figure 5-15: format 14 5.14.1 operation the instructions in this group allow registers 0-7 and optionally lr to be pushed onto the stack, and registers 0-7 and optionally pc to be popped off the stack. the thumb assembler syntax is shown in table 5-15: push and pop instructions . note the stack is always assumed to be full descending. l r thumb assembler arm equivalent action 0 0 push { rlist } stmdb r13!, { rlist } push the registers specified by rlist onto the stack. update the stack pointer. 0 1 push { rlist, lr } stmdb r13!, { rlist, r14 } push the link register and the registers specified by rlist (if any) onto the stack. update the stack pointer. 1 0 pop { rlist } ldmia r13!, { rlist } pop values off the stack into the registers specified by rlist. update the stack pointer. 1 1 pop { rlist, pc } ldmia r13!, { rlist, r15 } pop values off the stack and load into the registers specified by rlist. pop the pc off the stack. update the stack pointer. table 5-15: push and pop instructions 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 0 0 rlist register list pc/lr bit load/store bit 0 - store to memory 1 - load from memory 1 1 l 1 0 - do not store lr/load pc 1 - store lr/load pc r
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-33 open access 5.14.2 instruction cycle times all instructions in this format have an equivalent arm instruction as shown in table 5-15: push and pop instructions on page 5-32. the instruction cycle times for the thumb instruction are identical to that of the equivalent arm instruction. for more information on instruction cycle times, please refer to chapter 10, instruction cycle operations . 5.14.3 examples push {r0-r4,lr} ; store r0,r1,r2,r3,r4 and r14 (lr) at ; the stack pointed to by r13 (sp) and ; update r13. ; useful at start of a sub-routine to ; save workspace and return address. pop {r2,r6,pc} ; load r2,r6 and r15 (pc) from the stack ; pointed to by r13 (sp) and update r13. ; useful to restore workspace and return ; from sub-routine.
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-34 open access 5.15 format 15: multiple load/store figure 5-16: format 15 5.15.1 operation these instructions allow multiple loading and storing of lo registers. the thumb assembler syntax is shown in the following table. 5.15.2 instruction cycle times all instructions in this format have an equivalent arm instruction as shown in table 5-16: the multiple load/store instructions on page 5-34 . the instruction cycle times for the thumb instruction are identical to that of the equivalent arm instruction. for more information on instruction cycle times, please refer to chapter 10, instruction cycle operations l thumb assembler arm equivalent action 0 stmia rb!, { rlist } stmia rb!, { rlist } store the registers specified by rlist, starting at the base address in rb. write back the new base address. 1 ldmia rb!, { rlist } ldmia rb!, { rlist } load the registers specified by rlist, starting at the base address in rb. write back the new base address. table 5-16: the multiple load/store instructions 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 rb 0 1 1 0 l rlist register list base register load/store bit 0 - store to memory 1 - load from memory
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-35 open access 5.15.3 examples stmia r0!, {r3-r7} ; store the contents of registers r3-r7 ; starting at the address specified in ; r0, incrementing the addresses for each ; word. ; write back the updated value of r0.
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-36 open access 5.16 format 16: conditional branch figure 5-17: format 16 5.16.1 operation the instructions in this group all perform a conditional branch depending on the state of the cpsr condition codes. the branch offset must take account of the prefetch operation, which causes the pc to be 1 word (4 bytes) ahead of the current instruction. the thumb assembler syntax is shown in the following table. cond thumb assembler arm equivalent action 0000 beq label beq label branch if z set (equal) 0001 bne label bne label branch if z clear (not equal) 0010 bcs label bcs label branch if c set (unsigned higher or same) 0011 bcc label bcc label branch if c clear (unsigned lower) 0100 bmi label bmi label branch if n set (negative) 0101 bpl label bpl label branch if n clear (positive or zero) 0110 bvs label bvs label branch if v set (overflow) 0111 bvc label bvc label branch if v clear (no overflow) 1000 bhi label bhi label branch if c set and z clear (unsigned higher) 1001 bls label bls label branch if c clear or z set (unsigned lower or same) table 5-17: the conditional branch instructions 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 1 1 8-bit signed immediate condition cond soffset8
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-37 open access note while label speci?es a full 9-bit twos complement address, this must always be halfword-aligned (ie with bit 0 set to 0) since the assembler actually places label >> 1 in ?eld soffset8. note cond = 1110 is unde?ned, and should not be used. cond = 111 1 creates the swi instruction: see 5.17 format 17: software interrupt on page 5-38. 5.16.2 instruction cycle times all instructions in this format have an equivalent arm instruction as shown in table 5-17: the conditional branch instructions on page 5-36 . the instruction cycle times for the thumb instruction are identical to that of the equivalent arm instruction. for more information on instruction cycle times, please refer to chapter 10, instruction cycle operations 5.16.3 examples cmp r0, #45 ; branch to over if r0 > 45. bgt over ; note that the thumb opcode will contain ... ; the number of halfwords to offset. ... ... over ... ; must be halfword aligned. ... 1010 bge label bge label branch if n set and v set, or n clear and v clear (greater or equal) 1011 blt label blt label branch if n set and v clear, or n clear and v set (less than) 1100 bgt label bgt label branch if z clear, and either n set and v set or n clear and v clear (greater than) 1101 ble label ble label branch if z set, or n set and v clear, or n clear and v set (less than or equal) cond thumb assembler arm equivalent action table 5-17: the conditional branch instructions (continued)
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-38 open access 5.17 format 17: software interrupt figure 5-18: format 17 5.17.1 operation the swi instruction performs a software interrupt. on taking the swi, the processor switches into arm state and enters supervisor (svc) mode. the thumb assembler syntax for this instruction is shown below. note value8 is used solely by the swi handler: it is ignored by the processor. 5.17.2 instruction cycle times all instructions in this format have an equivalent arm instruction as shown in table 5-18: the swi instruction on page 5-38. the instruction cycle times for the thumb instruction are identical to that of the equivalent arm instruction. for more information on instruction cycle times, please refer to chapter 10, instruction cycle operations 5.17.3 examples swi 18 ; take the software interrupt exception. ; enter supervisor mode with 18 as the ; requested swi number. thumb assembler arm equivalent action swi value8 swi value8 perform software interrupt: move the address of the next instruction into lr, move cpsr to spsr, load the swi vector address (0x8) into the pc. switch to arm state and enter svc mode. table 5-18: the swi instruction 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 1 1 1 value8 1 1 1 1 comment field
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-39 open access 5.18 format 18: unconditional branch figure 5-19: format 18 5.18.1 operation this instruction performs a pc-relative branch. the thumb assembler syntax is shown below. the branch offset must take account of the prefetch operation, which causes the pc to be 1 word (4 bytes) ahead of the current instruction. note the address speci?ed by label is a full 12-bit twos complement address, but must always be halfword aligned (ie bit 0 set to 0), since the assembler places label >> 1 in the offset11 ?eld. 5.18.2 examples here b here ; branch onto itself. ; assembles to 0xe7fe. ; (note effect of pc offset). b jimmy ; branch to 'jimmy'. ... ; note that the thumb opcode will ; contain the number of halfwords ; to offset. jimmy ... ; must be halfword aligned. thumb assembler arm equivalent action b label bal label (halfword offset) branch pc relative +/- offset11 << 1, where label is pc +/- 2048 bytes. table 5-19: summary of branch instruction 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 1 1 offset11 immediate value 0 0
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-40 open access 5.19 format 19: long branch with link figure 5-20: format 19 5.19.1 operation this format speci?es a long branch with link. the assembler splits the 23-bit twos complement half-word offset specifed by the label into two 1 1-bit halves, ignoring bit 0 (which must be 0), and creates two thumb instructions. instruction 1 (h = 0) in the ?rst instruction the offset ?eld contains the upper 11 bits of the target address. this is shifted left by 12 bits and added to the current pc address. the resulting address is placed in lr. instruction 2 (h =1) in the second instruction the of fset ?eld contains an 1 1-bit representation lower half of the target address. this is shifted left by 1 bit and added to lr. lr, which now contains the full 23-bit address, is placed in pc, the address of the instruction following the bl is placed in lr and bit 0 of lr is set. the branch offset must take account of the prefetch operation, which causes the pc to be 1 word (4 bytes) ahead of the current instruction 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 1 1 1 offset h long branch and link offset high/low low/high offset bit 0 - offset high 1 - offset low
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-41 open access 5.19.2 instruction cycle times this instruction format does not have an equivalent arm instruction. for details of the instruction cycle times, please refer to chapter 10, instruction cycle operations . 5.19.3 examples bl faraway ; unconditionally branch to 'faraway' next ... ; and place following instruction ; address, ie next, in r14,the link ; register and set bit 0 of lr high. ; note that the thumb opcodes will ; contain the number of halfwords to ; offset. faraway ... ; must be half-word aligned. h thumb assembler arm equivalent action 0 bl label none lr := pc + offsethigh << 12 1 temp := next instruction address pc := lr + offsetlow << 1 lr := temp | 1 table 5-20: the bl instruction
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-42 open access 5.20 instruction set examples the following examples show ways in which the thumb instructions may be used to generate small and ef?cient code. each example also shows the arm equivalent so these may be compared. 5.20.1 multiplication by a constant using shifts and adds the following shows code to multiply by various constants using 1, 2 or 3 thumb instructions alongside the arm equivalents. for other constants it is generally better to use the built-in mul instruction rather than using a sequence of 4 or more instructions. thumb arm 1 multiplication by 2^n (1,2,4,8,...) lsl ra, rb, lsl #n mov ra, rb, lsl #n 2 multiplication by 2^n+1 (3,5,9,17,...) lsl rt, rb, #n add ra, rb, rb, lsl #n add ra, rt, rb 3 multiplication by 2^n-1 (3,7,15,...) lsl rt, rb, #n rsb ra, rb, rb, lsl #n sub ra, rt, rb 4 multiplication by -2^n (-2, -4, -8, ...) lsl ra, rb, #n mov ra, rb, lsl #n mvn ra, ra rsb ra, ra, #0 5 multiplication by -2^n-1 (-3, -7, -15, ...) lsl rt, rb, #n sub ra, rb, rb, lsl #n sub ra, rb, rt 6 multiplication by any c = {2^n+1, 2^n-1, -2^n or -2^n-1} * 2^n effectively this is any of the multiplications in 2 to 5 followed by a final shift. this allows the following additional constants to be multiplied. 6, 10, 12, 14, 18, 20, 24, 28, 30, 34, 36, 40, 48, 56, 60, 62 ..... (2..5) (2..5) lsl ra, ra, #n mov ra, ra, lsl #n
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-43 open access 5.20.2 general purpose signed divide this example shows a general purpose signed divide and remainder routine in both thumb and arm code. thumb code signed_divide ; signed divide of r1 by r0: returns quotient in r0, ; remainder in r1 ; get abs value of r0 into r3 asr r2, r0, #31 ; get 0 or -1 in r2 depending on sign of r0 eor r0, r2 ; eor with -1 (0xffffffff) if negative sub r3, r0, r2 ; and add 1 (sub -1) to get abs value ; sub always sets flag so go & report division by 0 if necessary ; beq divide_by_zero ; get abs value of r1 by xoring with 0xffffffff and adding 1 ; if negative asr r0, r1, #31 ; get 0 or -1 in r3 depending on sign of r1 eor r1, r0 ; eor with -1 (0xffffffff) if negative sub r1, r0 ; and add 1 (sub -1) to get abs value ; save signs (0 or -1 in r0 & r2) for later use in determining ; sign of quotient & remainder. push {r0, r2} ; justification, shift 1 bit at a time until divisor (r0 value) ; is just <= than dividend (r1 value). to do this shift dividend ; right by 1 and stop as soon as shifted value becomes >. lsr r0, r1, #1 mov r2, r3 b %ft0 just_l lsl r2, #1 0 cmp r2, r0 bls just_l mov r0, #0 ; set accumulator to 0 b %ft0 ; branch into division loop div_l lsr r2, #1 0 cmp r1, r2 ; test subtract bcc %ft0 sub r1, r2 ; if successful do a real ; subtract
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-44 open access 0 adc r0, r0 ; shift result and add 1 if ; subtract succeeded cmp r2, r3 ; terminate when r2 == r3 (ie we have just bne div_l ; tested subtracting the 'ones' value). ; now fixup the signs of the quotient (r0) and remainder (r1) pop {r2, r3} ; get dividend/divisor signs back eor r3, r2 ; result sign eor r0, r3 ; negate if result sign = -1 sub r0, r3 eor r1, r2 ; negate remainder if dividend sign = -1 sub r1, r2 mov pc, lr arm code signed_divide ; effectively zero a4 as top bit will be shifted out later ands a4, a1, #&80000000 rsbmi a1, a1, #0 eors ip, a4, a2, asr #32 ; ip bit 31 = sign of result ; ip bit 30 = sign of a2 rsbcs a2, a2, #0 ; central part is identical code to udiv ; (without mov a4, #0 which comes for free as part of signed ; entry sequence) movs a3, a1 beq divide_by_zero just_l ; justification stage shifts 1 bit at a time cmp a3, a2, lsr #1 movls a3, a3, lsl #1 ; nb: lsl #1 is always ok if ls succeeds blo s_loop div_l cmp a2, a3 adc a4, a4, a4 subcs a2, a2, a3 teq a3, a1 movne a3, a3, lsr #1
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-45 open access bne s_loop2 mov a1, a4 movs ip, ip, asl #1 rsbcs a1, a1, #0 rsbmi a2, a2, #0 mov pc, lr 5.20.3 division by a constant division by a constant can often be performed by a short ?xed sequence of shifts, adds and subtracts. for an explanation of the algorithm see the arm cookbook (arm duyi-0005b), section entitiled division by a constant . here is an example of a divide by 10 routine based on the algorithm in the arm cookbook in both thumb and arm code. thumb code udiv10 ; takes argument in a1 ; returns quotient in a1, remainder in a2 mov a2, a1 lsr a3, a1, #2 sub a1, a3 lsr a3, a1, #4 add a1, a3 lsr a3, a1, #8 add a1, a3 lsr a3, a1, #16 add a1, a3 lsr a1, #3 asl a3, a1, #2 add a3, a1 asl a3, #1 sub a2, a3 cmp a2, #10 blt %ft0 add a1, #1 sub a2, #10 0 mov pc, lr
thumb instruction set ARM7TDMI data sheet arm ddi 0029e 5-46 open access arm code udiv10 ; takes argument in a1 ; returns quotient in a1, remainder in a2 sub a2, a1, #10 sub a1, a1, a1, lsr #2 add a1, a1, a1, lsr #4 add a1, a1, a1, lsr #8 add a1, a1, a1, lsr #16 mov a1, a1, lsr #3 add a3, a1, a1, asl #2 subs a2, a2, a3, asl #1 addpl a1, a1, #1 addmi a2, a2, #10 mov pc, lr
ARM7TDMI data sheet arm ddi 0029e 6-1 11 1 open access memory interface this chapter describes the ARM7TDMI memory interface. 6.1 overview 6-2 6.2 cycle types 6-2 6.3 address timing 6-4 6.4 data transfer size 6-9 6.5 instruction fetch 6-10 6.6 memory management 6-12 6.7 locked operations 6-12 6.8 stretching access times 6-12 6.9 the arm data bus 6-13 6.10 the external data bus 6-15 6
memory interface ARM7TDMI data sheet arm ddi 0029e 6-2 open access 6.1 overview ARM7TDMIs memory interface consists of the following basic elements: ? 32-bit address bus this specifies to memory the location to be used for the transfer. ? 32-bit data bus instructions and data are transferred across this bus. data may be word, halfword or byte wide in size. ARM7TDMI includes a bidirectional data bus, d[31:0 ], plus separate unidirectional data busses, din[31:0] and dout[31:0] . most of the text in this chapter describes the bus behaviour assuming that the bidirectional is in use. however, the behaviour applies equally to the unidirectional busses. ? control signals these specify, for example, the size of the data to be transferred, and the direction of the transfer together with providing privileged information. this collection of signals allow ARM7TDMI to be simply interfaced to dram, sram and rom. to fully exploit page mode access to dram, information is provided on whether or not the memory accesses are sequential. in general, interfacing to static memories is much simpler than interfacing to dynamic memory. 6.2 cycle types all memory transfer cycles can be placed in one of four categories: 1 non-sequential cycle. ARM7TDMI requests a transfer to or from an address which is unrelated to the address used in the preceding cycle. 2 sequential cycle. ARM7TDMI requests a transfer to or from an address which is either the same as the address in the preceding cycle, or is one word or halfword after the preceding address. 3 internal cycle. ARM7TDMI does not require a transfer, as it is performing an internal function and no useful prefetching can be performed at the same time. 4 coprocessor register transfer. ARM7TDMI wishes to use the data bus to communicate with a coprocessor, but does not require any action by the memory system. these four classes are distinguishable to the memory system by inspection of the nmreq and seq control lines (see table 6-1: memory cycle types ). these control lines are generated during phase 1 of the cycle before the cycle whose characteristics they forecast, and this pipelining of the control information gives the memory system suf?cient time to decide whether or not it can use a page mode access.
memory interface ARM7TDMI data sheet arm ddi 0029e 6-3 open access figure 6-1: arm memory cycle timing on page 6-3 shows the pipelining of the control signals, and suggests how the dram address strobes ( nras and ncas ) might be timed to use page mode for s-cycles. note that the n-cycle is longer than the other cycles. this is to allow for the dram precharge and row access time, and is not an ARM7TDMI requirement. figure 6-1: arm memory cycle timing when an s-cycle follows an n-cycle, the address will always be one word or halfword greater than the address used in the n-cycle. this address (marked a in the above diagram) should be checked to ensure that it is not the last in the dram page before the memory system commits to the s-cycle. if it is at the page end, the s-cycle cannot be performed in page mode and the memory system will have to perform a full access. the processor clock must be stretched to match the full access. when an s-cycle follows an i-cycle, the address will be the same as that used in the i-cycle. this fact may be used to start the dram access during the preceding cycle, which enables the s-cycle to run at page mode speed whilst performing a full dram access. this is shown in figure 6-2: memory cycle optimization. nmreq seq cycle type 0 0 non-sequential (n-cycle) 0 1 sequential (s-cycle) 1 0 internal (i-cycle) 1 1 coprocessor register transfer (c-cycle) table 6-1: memory cycle types mclk a[31:0] nmreq seq ncas a a+4 i-cycle s-cycle c-cycle n-cycle nras d[31:0] a+8
memory interface ARM7TDMI data sheet arm ddi 0029e 6-4 open access . figure 6-2: memory cycle optimization 6.3 address timing ARM7TDMIs address bus can operate in one of two con?gurations - pipelined or depipelined, and this is controlled by the ape input signal. the con?gurability is provided to ease the design in of ARM7TDMI to both sram and dram based systems. it is a requirement srams and roms that the address be held stable throughout the memory cycle. in a system containing sram and rom only, ape may be tied permanently low, producing the desired address timing. this is shown in figure 6-3: ARM7TDMI de-pipelined addresses . note ape effects the timing of the address bus a[31:0] , plus nrw , mas[1:0] , lock , nopc and ntrans . mclk a[31:0] nmreq seq ncas i-cycle s-cycle nras d[31:0]
memory interface ARM7TDMI data sheet arm ddi 0029e 6-5 open access figure 6-3: ARM7TDMI de-pipelined addresses in a dram based system, it is desirable to obtain the address from ARM7TDMI as early as possible. when ape is high, ARM7TDMI's address becomes valid in the mclk high phase before the memory cycle to which it refers. this timing allows longer for address decoding and the generation of dram control signals. figure 6-4: ARM7TDMI pipelined addresses on page 6-5 shows the effect on the timing when ape is high. figure 6-4: ARM7TDMI pipelined addresses mclk ape nmreq seq a[31:0] d[31:0] mclk ape nmreq seq a[31:0] d[31:0]
memory interface ARM7TDMI data sheet arm ddi 0029e 6-6 open access many systems will contain a mixture of dram and sram/rom. to cater for the different address timing requirements, ape may be safely changed during the low phase of mclk . t ypically, ape would be held at one level during a burst of sequential accesses to one type of memory. when a non-sequential access occurs, the timing of most systems enforce a wait state to allow for address decoding. as a result of the address decode, ape can be driven to the correct value for the particular bank of memory being accessed. the value of ape can be held until the memory control signals denote another non-sequential access. by way of an example, figure 6-5: typical system timing , shows a combination of accesses to a mixed dram / sram system. here, the sram has zero wait states, and the dram has a 2:1 n-cycle / s-cycle ratio. a single wait state is inserted for address decode when a non-sequential access occurs. t ypical, externally generated dram control signals are also shown.
memory interface ARM7TDMI data sheet arm ddi 0029e 6-7 open access figure 6-5: typical system timing mclk nmreq seq a[31:0] nrw nwait ape d[31:0] dbe nras ncas sram cycles decode dram cycles decode sram cycles s s s s s s n n a a+4 a+8 b b+4 b+8 c c+4 c+8
memory interface ARM7TDMI data sheet arm ddi 0029e 6-8 open access previous arm processors included the ale signal, and this is retained for backwards compatibility . this signal also allows the address timing to be modi?ed to achieve the same results as ape , but in an asynchronous manner. to obtain clean mclk low timing of the address bus by this mechanism, ale must be driven high with the falling edge of mclk , and low with the rising edge of mclk . ale can simply be the inverse of mclk but the delay from mclk to ale must be carefully controlled such that the tald timing constraint is achieved. figure 6-6: sram compatible address timing shows how ale can be used to achieve sram compatible address timing. refer to chapter 12, ac parameters for details of the exact timing constraints. figure 6-6: sram compatible address timing note if ale is to be used to change address timing, then ape must be tied high. similarly , if ape is to be used, ale must be tied high. mclk ape ale nmreq seq a[31:0] d[31:0]
memory interface ARM7TDMI data sheet arm ddi 0029e 6-9 open access 6.4 data transfer size in an ARM7TDMI system, words, halfwords or bytes may be transferred between the processor and the memory . the size of the transaction taking place is determined by the mas[1:0] pins. these are encoded as follows: mas[1:0] 00 byte 01 halfword 10 word 11 reserved the processor always produces a byte address, but instructions are either words (4 bytes) or halfwords (2 bytes), and data can be any size. note that when word instructions are fetched from memory, a[1:0] are unde?ned and when halfword instructions are fetched, a[0] is unde?ned. the mas[1:0] outputs share the same timing as the address bus and thus can be modi?ed by the use of ale and ape as described in 6.3 address timing on page 6-4. when a data read of byte or halfword size is performed (eg ldrb), the memory system may safely ignore the fact that the request is for a sub-word sized quantity and present the whole word. ARM7TDMI will always correctly extract the addressed byte or halfword from the data. the memory system may also choose just to supply the addressed byte or halfword. this may be desirable in order to save power or to simplify the decode logic. when a byte or halfword write occurs (eg strh), ARM7TDMI will broadcast the byte or halfword across the whole of the bus. the memory system must then decode a[1:0] to enable writing only to the addressed byte or halfword. one way of implementing the byte decode in a dram system is to separate the 32-bit wide block of dram into four byte wide banks, and generate the column address strobes independently as shown in figure 6-7: decoding byte accesses to memory on page 6-11. when the processor is con?gured for little endian operation, byte 0 of the memory system should be connected to data lines 7 through 0 ( d[7:0] ) and strobed by ncas0 . ncas1 drives the bank connected to data lines 15 though 8, and so on. this has the added advantage of reducing the load on each column strobe driver , which improves the precision of this time-critical-signal. in the big endian case, byte 0 of the memory system should be connected to data lines 31 through 24 .
memory interface ARM7TDMI data sheet arm ddi 0029e 6-10 open access 6.5 instruction fetch ARM7TDMI will perform 32- or 16-bit instruction fetches depending on whether the processor is in arm or thumb state. the processor state may be determined externally by the value of the tbit signal. when this is low , the processor is in arm state and 32-bit instructions are fetched. when tbit is high, the processor is in thumb state and 16-bit instructions are fetched. the size of the data being fetched is also indicated on the mas[1:0] bits, as described above. when the processor is in arm state, 32-bit instructions are fetched on d[31:0] . when the processor is in thumb state, 16-bit instructions are fetched from either the upper , d[31:16 ], or the lower d[15:0 ] half of the bus. this is determined by the endianism of the memory system, as con?gured by the bigend input, and the state of a[1] . table 6-2: endianism effect on instruction position shows which half of the data bus is sampled in the different con?gurations. when a 16-bit instruction is fetched, ARM7TDMI ignores the unused half of the data bus. table 6-2: endianism effect on instruction position describes instructions fetched from the bidirectional data bus (i.e. busen is low). when the unidirectional data busses are in use (i.e. busen is high), data will be fetched from the corresponding half of the din[31:0] bus. endianism little bigend = 0 big bigend = 1 a[1] = 0 d[15:0] d[31:16] a[1] = 1 d[31:16] d[15:0] table 6-2: endianism effect on instruction position
memory interface ARM7TDMI data sheet arm ddi 0029e 6-11 open access figure 6-7: decoding byte accesses to memory a[0] a[1] mas[0] mclk cas ncas0 ncas1 ncas2 ncas3 g d q quad latch [1] mas[0] [1]
memory interface ARM7TDMI data sheet arm ddi 0029e 6-12 open access 6.6 memory management the ARM7TDMI address bus may be processed by an address translation unit before being presented to the memory, and ARM7TDMI is capable of running a virtual memory system. the abort input to the processor may be used by the memory manager to inform ARM7TDMI of page faults. various other signals enable different page protection levels to be supported: 1 nrw can be used by the memory manager to protect pages from being written to. 2 ntrans indicates whether the processor is in user or a privileged mode, and may be used to protect system pages from the user , or to support completely separate mappings for the system and the user. address translation will normally only be necessary on an n-cycle, and this fact may be exploited to reduce power consumption in the memory manager and avoid the translation delay at other times. the times when translation is necessary can be deduced by keeping track of the cycle types that the processor uses. 6.7 locked operations the arm instruction set of ARM7TDMI includes a data swap (swp) instruction that allows the contents of a memory location to be swapped with the contents of a processor register. this instruction is implemented as an uninterruptable pair of accesses; the ?rst access reads the contents of the memory, and the second writes the register data to the memory. these accesses must be treated as a contiguous operation by the memory controller to prevent another device from changing the af fected memory location before the swap is completed. ARM7TDMI drives the lock signal high for the duration of the swap operation to warn the memory controller not to give the memory to another device. 6.8 stretching access times all memory timing is de?ned by mclk , and long access times can be accommodated by stretching this clock. it is usual to stretch the low period of mclk , as this allows the memory manager to abort the operation if the access is eventually unsuccessful. either mclk can be stretched before it is applied to ARM7TDMI, or the nwait input can be used together with a free-running mclk . taking nwait low has the same effect as stretching the low period of mclk , and nwait must only change when mclk is low. ARM7TDMI does not contain any dynamic logic which relies upon regular clocking to maintain its internal state. therefore there is no limit upon the maximum period for which mclk may be stretched, or nwait held low.
memory interface ARM7TDMI data sheet arm ddi 0029e 6-13 open access 6.9 the arm data bus t o ease the connection of ARM7TDMI to sub-word sized memory systems, input data and instructions may be latched on a byte by byte basis. this is achieved by use of the bl[3:0] input signals where bl[3] controls the latching of the data present on d[31:24] of the data bus and so on. in a memory system containing word wide memory only, bl[3:0] may be tied high. for sub word wide memory systems, bl[3:0] are used to latch the data as it is read out of memory . for example, a word access to halfword wide memory must take place in two memory cycles. in the ?rst cycle, the data for d[15:0] is obtained from the memory and latched into the processor on the falling edge of mclk when bl[1:0] are both high. in the second cycle, the data for d[31:16] is latched into the processor on the falling edge of mclk when bl[3:2] are both high. a memory access like this is shown in figure 6-8: memory access on page 6-14. here, a word access is performed from halfword wide memory in two cycles.in the ?rst, the data read is applied to the lower half of the bus, in the second cycle the read data is applied to the upper half of the bus. since two memory cycles were required, nwait is used to stretch the internal processor clock. however, nwait does not effect the operation of the data latches. in this way, data may be extracted from memory word, halfword or byte at a time, and the memory may have as many wait states as required. in any multi-cycle memory access, nwait is held low until the ?nal quantum of data is latched. in this example, bl[3:0] were driven to value 0x3 in the ?rst cycle so that only the latches on d[15:0] were opened. in fact, bl[3:0] could have been driven to value 0xf and all the latches opened. since in the second cycle, the latches on d[31:16] were written with the correct data, this would not have effected the processor's operation. note bl[3:0] should all be high during store cycles.
memory interface ARM7TDMI data sheet arm ddi 0029e 6-14 open access figure 6-8: memory access as a further example, a halfword load from 2-wait state byte wide memory is shown in figure 6-9: two-cycle memory access on page 6-15. here, each memory access takes two cycles. in the ?rst, access, bl[3:0] are driven to value 0xf . the correct data is latched from d[7:0] whilst unknown data is latched from d[31:8] . in the second access, the byte for d[15:8] is latched and so the halfword on d[15:0] has been correctly read from the memory. the fact that internally d[31:16] are unknown does not matter because internally the processor will extract only the halfword it is interested in. mclk ape nmreq seq a[31:0] nwait d[15:0] d[31:16] bl[3:0] 0x3 0xc
memory interface ARM7TDMI data sheet arm ddi 0029e 6-15 open access figure 6-9: two-cycle memory access 6.10 the external data bus ARM7TDMI has a bidirectional data bus, d[31:0] . however , since some asic design methodologies prohibit the use of bidirectional buses, unidirectional data in, din[31:0] , and data out, dout[31:0] , busses are also provided. the logical arrangement of these buses is shown in figure 6-10: ARM7TDMI external bus arrangement on page 6-16 mclk ape nmreq seq a[31:0] nwait d[7:0] d[15:8] bl[3:0] 0xf 0x2
memory interface ARM7TDMI data sheet arm ddi 0029e 6-16 open access figure 6-10: ARM7TDMI external bus arrangement when the bidirectional data bus is being used, the unidirectional busses must be disabled by driving busen low. the timing of the bus for three cycles, load-store-load, is shown in figure 6-11: bidirectional bus timing . figure 6-11: bidirectional bus timing icebreaker ARM7TDMI g din[31:0] d[31:0] dout[31:0] mclk d[31:0] read cycle store cycle read cycle
memory interface ARM7TDMI data sheet arm ddi 0029e 6-17 open access figure 6-12: unidirectional bus timing 6.10.1 the unidirectional data bus when the unidirectional data busses are being used, (i.e. when busen is high), the bidirectional bus, d[31:0] , must be left unconnected. when busen is high, all instructions and input data are presented on the input data bus, din[31:0] . the timing of this data is similar to that of the bidirectional bus when in input mode. data must be set up and held to the falling edge of mclk . for the exact timing requirements refer to chapter 12, ac parameters . in this con?guration, all output data is presented on dout[31:0] . the value on this bus only changes when the processor performs a store cycle. again, the timing of the data is similar to that of the bidirectional data bus. the value on dout[31:0] changes off the falling edge of mclk . the bus timing of a read-write-read cycle combination is shown in figure 6-12: unidirectional bus timing on page 6-17. when busen is low, the buffer between din[31:0] and d[31:0] is disabled. any data presented on din[31:0] is ignored. also, when busen is low, the value on dout[31:0] is forced to 0x00000000. typically, the unidirectional busses would be used internally in asic embedded applications. externally , most systems still require a bidirectional data bus to interface to external memory. figure 6-13: external connection of unidirectional busses on page 6-18, shows how the unidirectional busses may be joined up at the pads of an asic to connect to an external bidirectional bus. mclk din[31:0] dout[31:0] d[31:0] read cycle store cycle read cycle d1 d2 dout d1 dout d2
memory interface ARM7TDMI data sheet arm ddi 0029e 6-18 open access figure 6-13: external connection of unidirectional busses 6.10.2 the bidirectional data bus ARM7TDMI has a bidirectional data bus, d[31:0 ]. most of the time, the arm reads from memory and so this bus is con?gured to input. during write cycles however , the ARM7TDMI must output data. during phase 2 of the previous cycle, the signal nrw is driven high to indicate a write cycle. during the actual cycle, nenout is driven low to indicate that the ARM7TDMI is driving d[31:0] as an output. figure 6-14: data write bus cycle shows this bus timing ( dbe has been tied high in this example). figure 6-15: ARM7TDMI data bus control circuit on page 6-21 shows the circuit which exists in ARM7TDMI for controlling exactly when the external bus is driven out. ARM7TDMI nenout dout[31:0] din[31:0] pad xdata[31:0]
memory interface ARM7TDMI data sheet arm ddi 0029e 6-19 open access figure 6-14: data write bus cycle the ARM7TDMI macrocell has an additional bus control signal, nenin, which allows the external system to manually tristate the bus. in the simplest systems, nenin can be tied low and nenout can be ignored. however, in many applications when the external data bus is a shared resource, greater control may be required. in this situation, nenin can be used to delay when the external bus is driven. note that for backwards compatibility , dbe is also included. at the macrocell level, dbe and nenin have almost identical functionality and in most applications one can be tied off. section 6.10.3 example system: the ARM7TDMI testchip on page 6-21 describes how ARM7TDMI may be interfaced to an external data bus, using ARM7TDMI testchip as an example. ARM7TDMI has another output control signal called tbe . this signal is normally only used during test and must be tied high when not in use. when driven low, tbe forces all three-stateable outputs to high impedance. it is as if both dbe and abe have been driven low, causing the data bus, the address bus, and all other signals normally controlled by abe to become high impedance. note, however, that there is no scan cell on tbe . thus, tbe is completely independent of scan data and may be used to put the outputs into a high impedance state while scan testing takes place. table 6-3: output enable control summary , below, shows the tri-state control of ARM7TDMIs outputs. mclk a[31:0] nrw nenout d[31:0] memory cycle
memory interface ARM7TDMI data sheet arm ddi 0029e 6-20 open access signals without 4 in the abe , dbe or tbe column cannot be driven to the high impedance state: ARM7TDMI output abe dbe tbe a[31:0] 4 4 d[31:0] 4 nrw 4 4 lock 4 4 mas[1:0] 4 4 nopc 4 4 ntrans 4 4 dbgack eclk ncpi nenout nexec nm[4:0] tbit nmreq sdoutms sdoutdata seq dout[31:0] table 6-3: output enable control summary
memory interface ARM7TDMI data sheet arm ddi 0029e 6-21 open access figure 6-15: ARM7TDMI data bus control circuit 6.10.3 example system: the ARM7TDMI testchip connecting ARM7TDMIs data bus, d[31:0] to an external shared bus requires some simple additional logic. this will vary from application to application. as an example, the following describes how the ARM7TDMI macrocell was connected to the bi-directional data bus pads of the ARM7TDMI testchip. in this application, care must be taken to prevent bus clash on d[31:0] when the data bus drive changes direction. the timing of nenin , and the pad control signals must be arranged so that when the core starts to drive out, the pad drive onto d[31:0] switches off before the core starts to drive. similarly, when the bus switches back to input, the core must stop driving before the pad switches on. all this can be achieved using a simple non-overlapping clock generator. the actual circuit implemented in the ARM7TDMI testchip is shown in figure 6-16: the ARM7TDMI testchip data bus circuit on page 6-22. note that at the core level, tbe and dbe are tied high (inactive). this is because in a packaged part, there is no need nenout nenin d[31:0] dbe tbe core control scan cell scan cell scan cell
memory interface ARM7TDMI data sheet arm ddi 0029e 6-22 open access to ever manually force the internal buses into a high impedance state. note also that at the pad level, the signal edbe is factored into the bus control logic. this allows the external memory controller to arbitrate the bus and asynchronously disable ARM7TDMI testchip if required. figure 6-16: the ARM7TDMI testchip data bus circuit figure 6-17: data bus control signal timing on page 6-23 shows how the various control signals interact. under normal conditions, when the data bus is con?gured as input, nenout is high, nen1 is low, and nen2 / nenin is high. thus the pads drive xd[31:0] onto d[31:0] . when a write cycle occurs, nrw is driven high to indicate a write during phase 2 of the previous cycle, (ie, with the address). during phase 1 of the actual cycle, nenout is driven low to indicate that ARM7TDMI is about to drive the bus. the falling edge of this signal makes nen1 go high, which disables the input half pad from driving d[31:0] . this in turn makes nen2 go low, which enables the output half of the pad so that the ARM7TDMI is now driving the external data bus, xd[31:0] . nen2 is then buffered and driven back into the core on nenin, so that ?nally the ARM7TDMI macrocell drives d[31:0] . the delay between all the signals ensures that there is no clash on the data bus as it changes direction from input to output. pad nenout nenin d[31:0] nen2 nen1 xd[31:0] ARM7TDMI testchip edbe vdd dbe srl srl srl vdd tbe ARM7TDMI core
memory interface ARM7TDMI data sheet arm ddi 0029e 6-23 open access figure 6-17: data bus control signal timing when the bus turns around to the other direction at the end of the cycle, the various control signals switch the other way. again, the non-overlap ensures that there is never a bus clash. this time, nenout is driven high to denote that ARM7TDMI no longer needs to drive the bus and the cores output is immediately switched off. this causes nen2 to disable the output half of the pad which in turn causes nen1 to switch on the input half. thus, the bus is back to its original input con?guration. note that the data out time of ARM7TDMI is not directly determined by nenout and nenin , and so delaying exactly when the bus is driven will not af fect the propagation delay. please refer to chapter 11, dc parameters for timing details. nenout nen1 nen2 / nenin d[31:0]
memory interface ARM7TDMI data sheet arm ddi 0029e 6-24 open access
ARM7TDMI data sheet arm ddi 0029e 7-1 11 1 open access coprocessor interface the functionality of the ARM7TDMI instruction set can be extended by adding external coprocessors. this chapter describes the ARM7TDMI coprocessor interface. 7.1 overview 7-2 7.2 interface signals 7-2 7.3 register transfer cycle 7-3 7.4 privileged instructions 7-3 7.5 idempotency 7-4 7.6 unde?ned instructions 7-4 7
coprocessor interface ARM7TDMI data sheet arm ddi 0029e 7-2 open access 7.1 overview the functionality of the ARM7TDMI instruction set may be extended by the addition of up to 16 external coprocessors. when the coprocessor is not present, instructions intended for it will trap, and suitable software may be installed to emulate its functions. adding the coprocessor will then increase the system performance in a software compatible way. note that some coprocessor numbers have already been assigned. contact arm ltd for up-to-date information. 7.2 interface signals three dedicated signals control the coprocessor interface, ncpi , cpa and cpb . the cpa and cpb inputs should be driven high except when they are being used for handshaking. 7.2.1 coprocessor present/absent ARM7TDMI takes ncpi low whenever it starts to execute a coprocessor (or unde?ned) instruction. (this will not happen if the instruction fails to be executed because of the condition codes.) each coprocessor will have a copy of the instruction, and can inspect the cp# ?eld to see which coprocessor it is for . every coprocessor in a system must have a unique number and if that number matches the contents of the cp# ?eld the coprocessor should drive the cpa (coprocessor absent) line low . if no coprocessor has a number which matches the cp# ?eld, cpa and cpb will remain high, and ARM7TDMI will take the unde?ned instruction trap. otherwise ARM7TDMI observes the cpa line going low, and waits until the coprocessor is not busy. 7.2.2 busy-waiting if cpa goes low, ARM7TDMI will watch the cpb (coprocessor busy) line. only the coprocessor which is driving cpa low is allowed to drive cpb low , and it should do so when it is ready to complete the instruction. ARM7TDMI will busy-wait while cpb is high, unless an enabled interrupt occurs, in which case it will break off from the coprocessor handshake to process the interrupt. normally ARM7TDMI will return from processing the interrupt to retry the coprocessor instruction. when cpb goes low, the instruction continues to completion. this will involve data transfers taking place between the coprocessor and either ARM7TDMI or memory, except in the case of coprocessor data operations which complete immediately the coprocessor ceases to be busy. all three interface signals are sampled by both ARM7TDMI and the coprocessor(s) on the rising edge of mclk . if all three are low, the instruction is committed to execution, and if transfers are involved they will start on the next cycle. if ncpi has gone high after being low , and before the instruction is committed, ARM7TDMI has broken off from the busy-wait state to service an interrupt. the instruction may be restarted later, but other coprocessor instructions may come sooner, and the instruction should be discarded.
coprocessor interface ARM7TDMI data sheet arm ddi 0029e 7-3 open access 7.2.3 pipeline following in order to respond correctly when a coprocessor instruction arises, each coprocessor must have a copy of the instruction. all ARM7TDMI instructions are fetched from memory via the main data bus, and coprocessors are connected to this bus, so they can keep copies of all instructions as they go into the ARM7TDMI pipeline. the nopc signal indicates when an instruction fetch is taking place, and mclk gives the timing of the transfer , so these may be used together to load an instruction pipeline within the coprocessor. 7.2.4 data transfer cycles once the coprocessor has gone not-busy in a data transfer instruction, it must supply or accept data at the ARM7TDMI bus rate (de?ned by mclk ). it can deduce the direction of transfer by inspection of the l bit in the instruction, but must only drive the bus when permitted to by dbe being high. the coprocessor is responsible for determining the number of words to be transferred; ARM7TDMI will continue to increment the address by one word per transfer until the coprocessor tells it to stop. the termination condition is indicated by the coprocessor driving cpa and cpb high. there is no limit in principle to the number of words which one coprocessor data transfer can move, but by convention no coprocessor should allow more than 16 words in one instruction. more than this would worsen the worst case ARM7TDMI interrupt latency, as the instruction is not interruptible once the transfers have commenced. at 16 words, this instruction is comparable with a block transfer of 16 registers, and therefore does not affect the worst case latency. 7.3 register transfer cycle the coprocessor register transfer cycle is the one case when ARM7TDMI requires the data bus without requiring the memory to be active. the memory system is informed that the bus is required by ARM7TDMI taking both nmreq and seq high. when the bus is free, dbe should be taken high to allow ARM7TDMI or the coprocessor to drive the bus, and an mclk cycle times the transfer. 7.4 privileged instructions the coprocessor may restrict certain instructions for use in privileged modes only . to do this, the coprocessor will have to track the ntrans output. as an example of the use of this facility, consider the case of a ?oating point coprocessor (fpu) in a multi-tasking system. the operating system could save all the ?oating point registers on every task switch, but this is inef?cient in a typical system where only one or two tasks will use ?oating point operations. instead, there could be a privileged instruction which turns the fpu on or off. when a task switch happens, the operating system can turn the fpu of f without saving its registers. if the new task attempts an fpu operation, the fpu will appear to be absent, causing an unde?ned instruction trap. the operating system will then realise that the new task requires the fpu, so it will re-enable it and save fpu registers. the task can then use the fpu as normal. if, however , the new task never attempts an fpu operation (as will be the case for most tasks), the state saving overhead will have been avoided.
coprocessor interface ARM7TDMI data sheet arm ddi 0029e 7-4 open access 7.5 idempotency a consequence of the implementation of the coprocessor interface, with the interruptible busy-wait state, is that all instructions may be interrupted at any point up to the time when the coprocessor goes not-busy. if so interrupted, the instruction will normally be restarted from the beginning after the interrupt has been processed. it is therefore essential that any action taken by the coprocessor before it goes not-busy must be idempotent, ie must be repeatable with identical results. for example, consider a fix operation in a ?oating point coprocessor which returns the integer result to an ARM7TDMI register. the coprocessor must stay busy while it performs the ?oating point to ?xed point conversion, as ARM7TDMI will expect to receive the integer value on the cycle immediately following that where it goes not- busy. the coprocessor must therefore preserve the original ?oating point value and not corrupt it during the conversion, because it will be required again if an interrupt arises during the busy period. the coprocessor data operation class of instruction is not generally subject to idempotency considerations, as the processing activity can take place after the coprocessor goes not-busy. there is no need for ARM7TDMI to be held up until the result is generated, because the result is con?ned to stay within the coprocessor. 7.6 unde?ned instructions unde?ned instructions are treated by ARM7TDMI as coprocessor instructions. all coprocessors must be absent (ie cpa and cpb must be high) when an unde?ned instruction is presented. ARM7TDMI will then take the unde?ned instruction trap. note that the coprocessor need only look at bit 27 of the instruction to differentiate unde?ned instructions (which all have 0 in bit 27) from coprocessor instructions (which all have 1 in bit 27) note that when in thumb state, coprocessor instructions are not supported but unde?ned instructions are. thus, all coprocessors must monitor the state of the tbit output from ARM7TDMI. when ARM7TDMI is in thumb state, coprocessors must appear absent (ie they must drive cpa and cpb high) and the instructions seen on the data bus must be ignored. in this way, coprocessors will not erroneously execute thumb instructions, and all unde?ned instructions will be handled correctly.
ARM7TDMI data sheet arm ddi 0029e 8-1 11 1 open access debug interface this chapter describes the ARM7TDMI advanced debug interface. 8.1 overview 8-2 8.2 debug systems 8-2 8.3 debug interface signals 8-3 8.4 scan chains and jtag interface 8-6 8.5 reset 8-8 8.6 pullup resistors 8-9 8.7 instruction register 8-9 8.8 public instructions 8-9 8.9 test data registers 8-12 8.10 ARM7TDMI core clocks 8-18 8.11 determining the core and system state 8-19 8.12 the pcs behaviour during debug 8-23 8.13 priorities / exceptions 8-25 8.14 scan interface timing 8-26 8
debug interface ARM7TDMI data sheet arm ddi 0029e 8-2 open access 8.1 overview the ARM7TDMI debug interface is based on ieee std. 1 149.1- 1990, standard test access port and boundary-scan architecture . please refer to this standard for an explanation of the terms used in this chapter and for a description of the t ap controller states. ARM7TDMI contains hardware extensions for advanced debugging features. these are intended to ease the users development of application software, operating systems, and the hardware itself. the debug extensions allow the core to be stopped either on a given instruction fetch (breakpoint) or data access (watchpoint), or asynchronously by a debug-request. when this happens, ARM7TDMI is said to be in debug state . at this point, the cores internal state and the system s external state may be examined. once examination is complete, the core and system state may be restored and program execution resumed. ARM7TDMI is forced into debug state either by a request on one of the external debug interface signals, or by an internal functional unit known as icebreaker . once in debug state, the core isolates itself from the memory system. the core can then be examined while all other system activity continues as normal. ARM7TDMI s internal state is examined via a jt ag-style serial interface, which allows instructions to be serially inserted into the cores pipeline without using the external data bus. thus, when in debug state, a store-multiple (stm) could be inserted into the instruction pipeline and this would dump the contents of ARM7TDMI s registers. this data can be serially shifted out without affecting the rest of the system. 8.2 debug systems the ARM7TDMI forms one component of a debug system that interfaces from the high-level debugging performed by the user to the low-level interface supported by ARM7TDMI. such a system typically has three parts: 1 the debug host this is a computer, for example a pc, running a software debugger such as armsd. the debug host allows the user to issue high level commands such as set breakpoint at location xx, or examine the contents of memory from 0x0 to 0x100. 2 the protocol converter the debug host will be connected to the ARM7TDMI development system via an interface (an rs232, for example). the messages broadcast over this connection must be converted to the interface signals of the ARM7TDMI, and this function is performed by the protocol converter. 3 ARM7TDMI ARM7TDMI, with hardware extensions to ease debugging, is the lowest level of the system. the debug extensions allow the user to stall the core from program execution, examine its internal state and the state of the memory system, and then resume program execution.
debug interface ARM7TDMI data sheet arm ddi 0029e 8-3 open access figure 8-1: typical debug system the anatomy of ARM7TDMI is shown in figure 8-3: ARM7TDMI scan chain arrangement on page 8-7. the major blocks are: ARM7TDMI this is the cpu core, with hardware support for debug. icebreaker this is a set of registers and comparators used to generate debug exceptions (eg breakpoints). this unit is described in chapter 9, icebreaker module . tap controller this controls the action of the scan chains via a jtag serial interface. the debug host and the protocol converter are system dependent. the rest of this chapter describes the ARM7TDMIs hardware debug extensions. 8.3 debug interface signals there are three primary external signals associated with the debug interface: ? breakpt and dbgrq with which the system requests ARM7TDMI to enter debug state. ? dbgack which ARM7TDMI uses to flag back to the system that it is in debug state. 8.3.1 entry into debug state ARM7TDMI is forced into debug state after a breakpoint, watchpoint or debug-request has occurred. conditions under which a breakpoint or watchpoint occur can be programmed using icebreaker. alternatively, external logic can monitor the address and data bus, and ?ag breakpoints and watchpoints via the breakpt pin. host computer running armsd protocol converter development system containing ARM7TDMI debug host debug target
debug interface ARM7TDMI data sheet arm ddi 0029e 8-4 open access the timing is the same for externally generated breakpoints and watchpoints. data must always be valid around the falling edge of mclk . if this data is an instruction to be breakpointed, the breakpt signal must be high around the next rising edge of mclk . similarly , if the data is for a load or store, this can be marked as watchpointed by asserting breakpt around the next rising edge of mclk . when a breakpoint or watchpoint is generated, there may be a delay before ARM7TDMI enters debug state. when it does, the dbgack signal is asserted in the high phase of mclk . the timing for an externally generated breakpoint is shown in figure 8-2: debug state entry . figure 8-2: debug state entry entry into debug state on breakpoint after an instruction has been breakpointed, the core does not enter debug state immediately. instructions are marked as being breakpointed as they enter ARM7TDMI's instruction pipeline. thus ARM7TDMI only enters debug state when (and if) the instruction reaches the pipelines execute stage. mclk a[31:0] d[31:0] breakpt dbgack nmreq seq memory cycles internal cycles
debug interface ARM7TDMI data sheet arm ddi 0029e 8-5 open access a breakpointed instruction may not cause ARM7TDMI to enter debug state for one of two reasons: ? a branch precedes the breakpointed instruction. when the branch is executed, the instruction pipeline is flushed and the breakpoint is cancelled. ? an exception has occurred. again, the instruction pipeline is flushed and the breakpoint is cancelled. however, the normal way to exit from an exception is to branch back to the instruction that would have executed next. this involves refilling the pipeline, and so the breakpoint can be re-flagged. when a breakpointed conditional instruction reaches the execute stage of the pipeline, the breakpoint is always taken and ARM7TDMI enters debug state, regardless of whether the condition was met. breakpointed instructions do not get executed: instead, ARM7TDMI enters debug state. thus, when the internal state is examined, the state before the breakpointed instruction is seen. once examination is complete, the breakpoint should be removed and program execution restarted from the previously breakpointed instruction. entry into debug state on watchpoint w atchpoints occur on data accesses. a watchpoint is always taken, but the core may not enter debug state immediately . in all cases, the current instruction will complete. if this is a multi-word load or store (ldm or stm), many cycles may elapse before the watchpoint is taken. watchpoints can be thought of as being similar to data aborts. the difference is however that if a data abort occurs, although the instruction completes, all subsequent changes to ARM7TDMI s state are prevented. this allows the cause of the abort to be cured by the abort handler , and the instruction re-executed. this is not so in the case of a watchpoint. here, the instruction completes and all changes to the cores state occur (ie load data is written into the destination registers, and base write-back occurs). thus the instruction does not need to be restarted. watchpoints are always taken. if an exception is pending when a watchpoint occurs, the core enters debug state in the mode of that exception. entry into debug state on debug-request ARM7TDMI may also be forced into debug state on debug request. this can be done either through icebreaker programming (see chapter 9, icebreaker module ), or by the assertion of the dbgrq pin. this pin is an asynchronous input and is thus synchronised by logic inside ARM7TDMI before it takes effect. following synchronisation, the core will normally enter debug state at the end of the current instruction. however, if the current instruction is a busy-waiting access to a coprocessor, the instruction terminates and ARM7TDMI enters debug state immediately (this is similar to the action of nirq and nfiq ).
debug interface ARM7TDMI data sheet arm ddi 0029e 8-6 open access action of ARM7TDMI in debug state once ARM7TDMI is in debug state, nmreq and seq are forced to indicate internal cycles. this allows the rest of the memory system to ignore ARM7TDMI and function as normal. since the rest of the system continues operation, ARM7TDMI must be forced to ignore aborts and interrupts. the bigend signal should not be changed by the system during debug. if it changes, not only will there be a synchronisation problem, but the programmers view of ARM7TDMI will change without the debuggers knowledge. nreset must also be held stable during debug. if the system applies reset to ARM7TDMI (ie. nreset is driven low) then ARM7TDMIs state will change without the debuggers knowledge. the bl[3:0] signals must remain high while ARM7TDMI is clocked by dclk in debug state to ensure all of the data in the scan cells is correctly latched by the internal logic. when instructions are executed in debug state, ARM7TDMI outputs (except nmreq and seq ) will change asynchronously to the memory system. for example, every time a new instruction is scanned into the pipeline, the address bus will change. although this is asynchronous it should not af fect the system, since nmreq and seq are forced to indicate internal cycles regardless of what the rest of ARM7TDMI is doing. the memory controller must be designed to ensure that this asynchronous behaviour does not affect the rest of the system. 8.4 scan chains and jtag interface there are three jtag style scan chains inside ARM7TDMI. these allow testing, debugging and icebreaker programming. the scan chains are controlled from a jtag style tap (test access port) controller. for further details of the jtag speci?cation, please refer to ieee standard 1 149.1 - 1990 standard t est access port and boundary-scan architecture . in addition, support is provided for an optional fourth scan chain. this is intended to be used for an external boundary scan chain around the pads of a packaged device. the control signals provided for this scan chain are described later. note the scan cells are not fully jtag compliant. the following sections describe the limitations on their use. 8.4.1 scan limitations the three scan paths are referred to as scan chain 0, 1 and 2: these are shown in figure 8-3: ARM7TDMI scan chain arrangement on page 8-7. scan chain 0 scan chain 0 allows access to the entire periphery of the ARM7TDMI core, including the data bus. the scan chain functions allow inter-device testing (extest) and serial testing of the core (intest). the order of the scan chain (from sdin to sdoutms ) is: data bus bits 0 through 31, the control signals, followed by the address bus bits 31 through 0.
debug interface ARM7TDMI data sheet arm ddi 0029e 8-7 open access scan chain 1 scan chain 1 is a subset of the signals that are accessible through scan chain 0. access to the cores data bus d[31:0] , and the breakpt signal is available serially . there are 33 bits in this scan chain, the order being (from serial data in to out): data bus bits 0 through 31, followed by breakpt . scan chain 2 this scan chain simply allows access to the icebreaker registers. refer to chapter 9, icebreaker module for details. figure 8-3: ARM7TDMI scan chain arrangement ARM7TDMI processor ARM7TDMI icebreaker ARM7TDMI tap controller ? ? scan chain 1 scan chain 0 scan chain 2
debug interface ARM7TDMI data sheet arm ddi 0029e 8-8 open access 8.4.2 the jtag state machine the process of serial test and debug is best explained in conjunction with the jtag state machine. figure 8-4: test access port (tap) controller state transitions shows the state transitions that occur in the tap controller. the state numbers are also shown on the diagram. these are output from ARM7TDMI on the tapsm[3:0] bits. figure 8-4: test access port (tap) controller state transitions 8.5 reset the boundary-scan interface includes a state-machine controller (the t ap controller). in order to force the t ap controller into the correct state after power-up of the device, a reset pulse must be applied to the ntrst signal. if the boundary scan interface is to select-ir-scan capture-ir tms=0 shift-ir tms=0 exit1-ir tms=1 pause-ir tms=0 exit2-ir tms=1 update-ir tms=1 tms=0 tms=0 tms=1 tms=1 tms=0 select-dr-scan capture-dr tms=0 shift-dr tms=0 exit1-dr tms=1 pause-dr tms=0 exit2-dr tms=1 update-dr tms=1 test-logic reset run-test/idle tms=0 tms=1 tms=0 tms=0 tms=0 tms=1 tms=1 tms=0 tms=1 tms=1 tms=1 tms=1 tms=1 tms=0 tms=0 0xf 0xc 0x7 0x4 0xe 0xa 0x9 0xb 0x8 0xd 0x5 0x0 0x3 0x1 0x2 0x6
debug interface ARM7TDMI data sheet arm ddi 0029e 8-9 open access be used, ntrst must be driven low, and then high again. if the boundary scan interface is not to be used, the ntrst input may be tied permanently low . note that a clock on tck is not necessary to reset the device. the action of reset is as follows: 1 system mode is selected (ie the boundary scan chain cells do not intercept any of the signals passing between the external system and the core). 2 the idcode instruction is selected. if the tap controller is put into the shift- dr state and tck is pulsed, the contents of the id register will be clocked out of tdo . 8.6 pullup resistors the ieee 1 149.1 standard ef fectively requires that tdi and tms should have internal pullup resistors. in order to minimise static current draw , these resistors are not ?tted to ARM7TDMI. accordingly , the 4 inputs to the test interface (the above 3 signals plus tck ) must all be driven to good logic levels to achieve normal circuit operation. 8.7 instruction register the instruction register is 4 bits in length. there is no parity bit. the ?xed value loaded into the instruction register during the capture-ir controller state is 0001. 8.8 public instructions the following public instructions are supported: instruction binary code extest 0000 scan_n 0010 intest 1100 idcode 1110 bypass 1111 clamp 0101 highz 0111 clampz 1001 sample/preload 0011 restart 0100 table 8-1: public instructions
debug interface ARM7TDMI data sheet arm ddi 0029e 8-10 open access in the descriptions that follow, tdi and tms are sampled on the rising edge of tck and all output transitions on tdo occur as a result of the falling edge of tck . 8.8.1 extest (0000) the selected scan chain is placed in test mode by the extest instruction. the extest instruction connects the selected scan chain between tdi and tdo . when the instruction register is loaded with the extest instruction, all the scan cells are placed in their test mode of operation. in the capture-dr state, inputs from the system logic and outputs from the output scan cells to the system are captured by the scan cells. in the shift-dr state, the previously captured test data is shifted out of the scan chain via tdo , while new test data is shifted in via the tdi input. this data is applied immediately to the system logic and system pins. 8.8.2 scan_n (0010) this instruction connects the scan path select register between tdi and tdo . during the capture-dr state, the ?xed value 1000 is loaded into the register . during the shift-dr state, the id number of the desired scan path is shifted into the scan path select register. in the update-dr state, the scan register of the selected scan chain is connected between tdi and tdo , and remains connected until a subsequent scan_n instruction is issued. on reset, scan chain 3 is selected by default. the scan path select register is 4 bits long in this implementation, although no ?nite length is speci?ed. 8.8.3 intest (1100) the selected scan chain is placed in test mode by the intest instruction. the intest instruction connects the selected scan chain between tdi and tdo . when the instruction register is loaded with the intest instruction, all the scan cells are placed in their test mode of operation. in the capture-dr state, the value of the data applied from the core logic to the output scan cells, and the value of the data applied from the system logic to the input scan cells is captured. in the shift-dr state, the previously captured test data is shifted out of the scan chain via the tdo pin, while new test data is shifted in via the tdi pin. single-step operation is possible using the intest instruction. 8.8.4 idcode (1110) the idcode instruction connects the device identi?cation register (or id register) between tdi and tdo . the id register is a 32-bit register that allows the manufacturer , part number and version of a component to be determined through the tap. see 8.9.2 ARM7TDMI device identification (id) code register on page 8-13 for the details of the id register format.
debug interface ARM7TDMI data sheet arm ddi 0029e 8-11 open access when the instruction register is loaded with the idcode instruction, all the scan cells are placed in their normal (system) mode of operation. in the capture-dr state, the device identi?cation code is captured by the id register. in the shift-dr state, the previously captured device identi?cation code is shifted out of the id register via the tdo pin, while data is shifted in via the tdi pin into the id register. in the update-dr state, the id register is unaffected. 8.8.5 bypass (1111) the byp ass instruction connects a 1 bit shift register (the byp ass register) between tdi and tdo . when the byp ass instruction is loaded into the instruction register , all the scan cells are placed in their normal (system) mode of operation. this instruction has no effect on the system pins. in the capture-dr state, a logic 0 is captured by the bypass register . in the shift - dr state, test data is shifted into the bypass register via tdi and out via tdo after a delay of one tck cycle. note that the ?rst bit shifted out will be a zero. the bypass register is not af fected in the upda te-dr state. note that all unused instruction codes default to the bypass instruction. 8.8.6 clamp (0101) this instruction connects a 1 bit shift register (the byp ass register) between tdi and tdo . when the clamp instruction is loaded into the instruction register , the state of all the output signals is de?ned by the values previously loaded into the currently loaded scan chain. note this instruction should only be used when scan chain 0 is the currently selected scan chain. in the capture-dr state, a logic 0 is captured by the bypass register . in the shift - dr state, test data is shifted into the bypass register via tdi and out via tdo after a delay of one tck cycle. note that the ?rst bit shifted out will be a zero. the bypass register is not affected in the update-dr state. 8.8.7 highz (0111) this instruction connects a 1 bit shift register (the byp ass register) between tdi and tdo . when the highz instruction is loaded into the instruction register, the address bus, a[31:0] , the data bus, d[31:0] , plus nrw , nopc , lock , mas[1:0] and ntrans are all driven to the high impedance state and the external highz signal is driven high. this is as if the signal tbe had been driven low. in the capture-dr state, a logic 0 is captured by the bypass register. in the shift- dr state, test data is shifted into the bypass register via tdi and out via tdo after a delay of one tck cycle. note that the ?rst bit shifted out will be a zero. the bypass register is not affected in the update-dr state.
debug interface ARM7TDMI data sheet arm ddi 0029e 8-12 open access 8.8.8 clampz (1001) this instruction connects a 1 bit shift register (the byp ass register) between tdi and tdo . when the clampz instruction is loaded into the instruction register, all the 3-state outputs (as described above) are placed in their inactive state, but the data supplied to the outputs is derived from the scan cells. the purpose of this instruction is to ensure that, during production test, each output can be disabled when its data value is either a logic 0 or a logic 1. in the capture-dr state, a logic 0 is captured by the bypass register . in the shift - dr state, test data is shifted into the bypass register via tdi and out via tdo after a delay of one tck cycle. note that the ?rst bit shifted out will be a zero. the bypass register is not affected in the update-dr state. 8.8.9 sample/preload (0011) this instruction is included for production test only, and should never be used. 8.8.10 restart (0100) this instruction is used to restart the processor on exit from debug state. the restart instruction connects the bypass register between tdi and tdo and the t ap controller behaves as if the byp ass instruction had been loaded. the processor will resynchronise back to the memory system once the run-test/idle state is entered. 8.9 test data registers there are 6 test data registers which may be connected between tdi and tdo . they are: bypass register , id code register , scan chain select register , scan chain 0, 1 or 2. these are now described in detail. 8.9.1 bypass register purpose: bypasses the device during scan testing by providing a path between tdi and tdo . length: 1 bit operating mode: when the byp ass instruction is the current instruction in the instruction register , serial data is transferred from tdi to tdo in the shift-dr state with a delay of one tck cycle. there is no parallel output from the bypass register. a logic 0 is loaded from the parallel input of the bypass register in the capture-dr state.
debug interface ARM7TDMI data sheet arm ddi 0029e 8-13 open access 8.9.2 ARM7TDMI device identi?cation (id) code register purpose: reads the 32-bit device identi?cation code. no programmable supplementary identi?cation code is provided. length: 32 bits. the format of the id register is as follows: please contact your supplier for the correct device identi?cation code. operating mode: when the idcode instruction is current, the id register is selected as the serial path between tdi and tdo . there is no parallel output from the id register. the 32-bit device identi?cation code is loaded into the id register from its parallel inputs during the capture-dr state. 8.9.3 instruction register purpose: changes the current tap instruction. length: 4 bits operating mode: when in the shift-ir state, the instruction register is selected as the serial path between tdi and tdo . during the capture-ir state, the value 0001 binary is loaded into this register . this is shifted out during shift -ir (lsb ?rst), while a new instruction is shifted in (lsb ?rst). during the upda te-ir state, the value in the instruction register becomes the current instruction. on reset, idcode becomes the current instruction. 8.9.4 scan chain select register purpose: changes the current active scan chain. length: 4 bits operating mode: after scan_n has been selected as the current instruction, when in the shift -dr state, the scan chain select register is selected as the serial path between tdi and tdo . during the capture-dr state, the value 1000 binary is loaded into this register . this is shifted out during shift-dr (lsb ?rst), while a new value is shifted in (lsb ?rst). during the upda te-dr state, the value in the register selects a scan chain to become the currently active scan chain. all further instructions such as intest then apply to that scan chain. 0 1 11 12 27 28 31 1 manufacturer identity part number version
debug interface ARM7TDMI data sheet arm ddi 0029e 8-14 open access the currently selected scan chain only changes when a scan_n instruction is executed, or a reset occurs. on reset, scan chain 3 is selected as the active scan chain. the number of the currently selected scan chain is re?ected on the screg[3:0] outputs. the tap controller may be used to drive external scan chains in addition to those within the ARM7TDMI macrocell. the external scan chain must be assigned a number and control signals for it can be derived from screg[3:0] , ir[3:0] , tapsm[3:0] , tck1 and tck2 . the list of scan chain numbers allocated by arm are shown in table 8-2: scan chain number allocation . an external scan chain may take any other number .the serial data stream to be applied to the external scan chain is made present on sdinbs , the serial data back from the scan chain must be presented to the tap controller on the sdoutbs input. the scan chain present between sdinbs and sdoutbs will be connected between tdi and tdo whenever scan chain 3 is selected, or when any of the unassigned scan chain numbers is selected. if there is more than one external scan chain, a multiplexor must be built externally to apply the desired scan chain output to sdoutbs . the multiplexor can be controlled by decoding screg[3:0] . 8.9.5 scan chains 0,1 and 2 these allow serial access to the core logic, and to icebreaker for programming purposes. they are described in detail below. scan chain 0 and 1 purpose: allows access to the processor core for test and debug. length: scan chain 0: 105 bits scan chain 1: 33 bits each scan chain cell is fairly simple, and consists of a serial register and a multiplexer . the scan cells perform two basic functions, capture and shift . for input cells, the capture stage involves copying the value of the system input to the core into the serial register . during shift, this value is output serially . the value applied to the core from an input cell is either the system input or the contents of the serial register, and this is controlled by the multiplexer. scan chain number function 0 macrocell scan test 1 debug 2 icebreaker programming 3 external boundary scan 4 reserved 8 reserved table 8-2: scan chain number allocation
debug interface ARM7TDMI data sheet arm ddi 0029e 8-15 open access figure 8-5: input scan cell for output cells, capture involves placing the value of a cores output into the serial register. during shift, this value is serially output as before. the value applied to the system from an output cell is either the core output, or the contents of the serial register. all the control signals for the scan cells are generated internally by the t ap controller. the action of the t ap controller is determined by the current instruction, and the state of the tap state machine. this is described below. there are three basic modes of operation of the scan chains, intest, extest and system, and these are selected by the various tap controller instructions. in system mode, the scan cells are idle. system data is applied to inputs, and core outputs are applied to the system. in intest mode, the core is internally tested. the data serially scanned in is applied to the core, and the resulting outputs are captured in the output cells and scanned out. in extest mode, data is scanned onto the core's outputs and applied to the external system. system input data is captured in the input cells and then shifted out. note the scan cells are not fully jt ag compliant in that they do not have an update stage. therefore, while data is being moved around the scan chain, the contents of the scan cell is not isolated from the output. thus the output from the scan cell to the core or to the external system could change on every scan clock. this does not affect ARM7TDMI since its internal state does not change until it is clocked. however, the rest of the system needs to be aware that every output could change asynchronously as data is moved around the scan chain. external logic must ensure that this does not harm the rest of the system. shift register latch system data in shift clock data to core serial data in serial data out capture clock
debug interface ARM7TDMI data sheet arm ddi 0029e 8-16 open access scan chain 0 scan chain 0 is intended primarily for inter-device testing (extest), and testing the core (intest). scan chain 0 is selected via the scan_n instruction: see 8.8.2 scan_n (0010) on page 8-10. intest allows serial testing of the core. the tap controller must be placed in intest mode after scan chain 0 has been selected. during capture-dr, the current outputs from the cores logic are captured in the output cells. during shift- dr, this captured data is shifted out while a new serial test pattern is scanned in, thus applying known stimuli to the inputs. during run-test/idle, the core is clocked. normally , the t ap controller should only spend 1 cycle in run-test/idle. the whole operation may then be repeated. for details of the cores clocks during test and debug, see 8.10 ARM7TDMI core clocks on page 8-18. extest allows inter-device testing, useful for verifying the connections between devices on a circuit board. the t ap controller must be placed in extest mode after scan chain 0 has been selected. during capture-dr, the current inputs to the core's logic from the system are captured in the input cells. during shift -dr, this captured data is shifted out while a new serial test pattern is scanned in, thus applying known values on the core s outputs. during upda te-dr, the value shifted into the data bus d[31:0] scan cells appears on the outputs. for all other outputs, the value appears as the data is shifted round. note, during run-test/idle, the core is not clocked. the operation may then be repeated. scan chain 1 the primary use for scan chain 1 is for debugging, although it can be used for extest on the data bus. scan chain 1 is selected via the scan_n t ap controller instruction. debugging is similar to intest , and the procedure described above for scan chain 0 should be followed. note that this scan chain is 33 bits long - 32 bits for the data value, plus the scan cell on the breakpt core input. this 33rd bit serves four purposes: 1 under normal intest test conditions, it allows a known value to be scanned into the breakpt input. 2 during extest test conditions, the value applied to the breakpt input from the system can be captured. 3 while debugging, the value placed in the 33rd bit determines whether ARM7TDMI synchronises back to system speed before executing the instruction. see 8.12.5 system speed access on page 8-25 for further details. 4 after ARM7TDMI has entered debug state, the ?rst time this bit is captured and scanned out, its value tells the debugger whether the core entered debug state due to a breakpoint (bit 33 low), or a watchpoint (bit 33 high).
debug interface ARM7TDMI data sheet arm ddi 0029e 8-17 open access scan chain 2 purpose: allows icebreaker's registers to be accessed. the order of the scan chain, from tdi to tdo is: read/write, register address bits 4 to 0, followed by data value bits 31 to 0. see figure 9-2: icebreaker block diagram on page 9-4. length: 38 bits. t o access this serial register , scan chain 2 must ?rst be selected via the scan_n t ap controller instruction. the tap controller must then be place in intest mode. no action is taken during capture-dr. during shift-dr, a data value is shifted into the serial register. bits 32 to 36 specify the address of the icebreaker register to be accessed. during upda te-dr, this register is either read or written depending on the value of bit 37 (0 = read). refer to chapter 9, icebreaker module for further details. scan chain 3 purpose: allows ARM7TDMI to control an external boundary scan chain. length: user de?ned. scan chain 3 is provided so that an optional external boundary scan chain may be controlled via ARM7TDMI. typically this would be used for a scan chain around the pad ring of a packaged device. the following control signals are provided which are generated only when scan chain 3 has been selected. these outputs are inactive at all other times. drivebs this would be used to switch the scan cells from system mode to test mode. this signal is asserted whenever either the intest, extest, clamp or clampz instruction is selected. pclkbs this is an update clock, generated in the upda te-dr state. t ypically the value scanned into a chain would be transferred to the cell output on the rising edge of this signal. icapclkbs , ecapclkbs these are capture clocks used to sample data into the scan cells during intest and extest respectively . these clocks are generated in the capture-dr state. shclkbs , shclk2bs these are non-overlapping clocks generated in the shift- dr state used to clock the master and slave element of the scan cells respectively . when the state machine is not in the shift-dr state, both these clocks are low. nhighz this signal may be used to drive the outputs of the scan cells to the high impedance state. this signal is driven low when the highz instruction is loaded into the instruction register, and high at all other times.
debug interface ARM7TDMI data sheet arm ddi 0029e 8-18 open access in addition to these control outputs, sdinbs output and sdoutbs input are also provided. when an external scan chain is in use, sdoutbs should be connected to the serial data output and sdinbs should be connected to the serial data input. 8.10 ARM7TDMI core clocks ARM7TDMI has two clocks, the memory clock, mclk , and an internally tck generated clock, dclk . during normal operation, the core is clocked by mclk , and internal logic holds dclk low. when ARM7TDMI is in the debug state, the core is clocked by dclk under control of the tap state machine, and mclk may free run. the selected clock is output on the signal eclk for use by the external system. note that when the cpu core is being debugged and is running from dclk , nwait has no effect. there are two cases in which the clocks switch: during debugging and during testing. 8.10.1 clock switch during debug when ARM7TDMI enters debug state, it must switch from mclk to dclk . this is handled automatically by logic in the ARM7TDMI. on entry to debug state, ARM7TDMI asserts dbgack in the high phase of mclk . the switch between the two clocks occurs on the next falling edge of mclk . this is shown in figure 8-6: clock switching on entry to debug state . figure 8-6: clock switching on entry to debug state ARM7TDMI is forced to use dclk as the primary clock until debugging is complete. on exit from debug, the core must be allowed to synchronise back to mclk . this must be done in the following sequence. the ?nal instruction of the debug sequence must be shifted into the data bus scan chain and clocked in by asserting dclk . at this point, bypass must be clocked into the tap instruction register. ARM7TDMI will now automatically resynchronise back to mclk and start fetching instructions from memory at mclk speed. please refer also to 8.11.3 exit from debug state on page 8-21. mclk dbgack dclk eclk multiplexer switching point
debug interface ARM7TDMI data sheet arm ddi 0029e 8-19 open access 8.10.2 clock switch during test when under serial test conditionsie when test patterns are being applied to the arm7tm core through the jtag interfaceARM7TDMI must be clocked using dclk . entry into test is less automatic than debug and some care must be taken. on the way into test, mclk must be held low . the t ap controller can now be used to serially test ARM7TDMI. if scan chain 0 and intest are selected, dclk is generated while the state machine is in the run-test/idle state. during extest, dclk is not generated. on exit from test, bypass must be selected as the tap controller instruction. when this is done, mclk can be allowed to resume. after intest testing, care should be taken to ensure that the core is in a sensible state before switching back. the safest way to do this is to either select bypass and then cause a system reset, or to insert mov pc, #0 into the instruction pipeline before switching back. 8.11 determining the core and system state when ARM7TDMI is in debug state, the core and systems state may be examined. this is done by forcing load and store multiples into the instruction pipeline. before the core and system state can be examined, the debugger must ?rst determine whether the processor was in thumb or arm state when it entered debug. this is achieved by examining bit 4 of icebreakers debug status register. if this is high, the core was in thumb state when it entered debug. 8.11.1 determining the cores state if the processor has entered debug state from thumb state, the simplest course of action is for the debugger to force the core back into arm state. once this is done, the debugger can always execute the same sequence of instructions to determine the processor's state. t o force the processor into arm state, the following sequence of thumb instructions should be executed on the core: str r0, [r0] ; save r0 before use mov r0, pc ; copy pc into r0 str r0, [r0] ; now save the pc in r0 bx pc ; jump into arm state mov r8, r8 ; nop mov r8, r8 ; nop note since all thumb instructions are only 16 bits long, the simplest course of action when shifting them into scan chain 1 is to repeat the instruction twice. for example, the encoding for bx r0 is 0x4700. thus if 0x47004700 is shifted into scan chain 1, the debugger does not have to keep track of which half of the bus the processor expects to read the data from.
debug interface ARM7TDMI data sheet arm ddi 0029e 8-20 open access from this point on, the processor's state can be determined by the sequences of arm instructions described below. once the processor is in arm state, typically the ?rst instruction executed would be: stm r0, {r0-r15} this causes the contents of the registers to be made visible on the data bus. these values can then be sampled and shifted out. note the above use of r0 as the base register for the stm is for illustration only, any register could be used. after determining the values in the current bank of registers, it may be desirable to access the banked registers. this can only be done by changing mode. normally, a mode change may only occur if the core is already in a privileged mode. however, while in debug state, a mode change from any mode into any other mode may occur . note that the debugger must restore the original mode before exiting debug state. for example, assume that the debugger had been asked to return the state of the user mode and fiq mode registers, and debug state was entered in supervisor mode. the instruction sequence could be: stm r0, {r0-r15}; save current registers mrs r0, cpsr str r0, r0; save cpsr to determine current mode bic r0, 0x1f; clear mode bits orr r0, 0x10; select user mode msr cpsr, r0; enter user mode stm r0, {r13,r14}; save register not previously visible orr r0, 0x01; select fiq mode msr cpsr, r0; enter fiq mode stm r0, {r8-r14}; save banked fiq registers all these instructions are said to execute at debug speed . debug speed is much slower than system speed since between each core clock, 33 scan clocks occur in order to shift in an instruction, or shift out data. executing instructions more slowly than usual is ?ne for accessing the cores state since ARM7TDMI is fully static. however, this same method cannot be used for determining the state of the rest of the system. while in debug state, only the following instructions may legally be scanned into the instruction pipeline for execution: ? all data processing operations, except teqp ? all load, store, load multiple and store multiple instructions ? msr and mrs
debug interface ARM7TDMI data sheet arm ddi 0029e 8-21 open access 8.11.2 determining system state in order to meet the dynamic timing requirements of the memory system, any attempt to access system state must occur synchronously to it. thus, ARM7TDMI must be forced to synchronise back to system speed. this is controlled by the 33rd bit of scan chain 1. any instruction may be placed in scan chain 1 with bit 33 (the breakpt bit) low. this instruction will then be executed at debug speed. to execute an instruction at system speed, the instruction prior to it must be scanned into scan chain 1 with bit 33 set high. after the system speed instruction has been scanned into the data bus and clocked into the pipeline, the byp ass instruction must be loaded into the t ap controller. this will cause ARM7TDMI to automatically synchronise back to mclk (the system clock), execute the instruction at system speed, and then re-enter debug state and switch itself back to the internally generated dclk . when the instruction has completed, dbgack will be high and the core will have switched back to dclk . at this point, intest can be selected in the tap controller, and debugging can resume. in order to determine that a system speed instruction has completed, the debugger must look at both dbgack and nmreq . in order to access memory, ARM7TDMI drives nmreq low after it has synchronised back to system speed. this transition is used by the memory controller to arbitrate whether ARM7TDMI can have the bus in the next cycle. if the bus is not available, ARM7TDMI may have its clock stalled inde?nitely . therefore, the only way to tell that the memory access has completed, is to examine the state of both nmreq and dbgack . when both are high, the access has completed. usually, the debugger would be using icebreaker to control debugging, and by reading icebreaker's status register, the state of nmreq and dbgack can be determined. refer to chapter 9, icebreaker module for more details. by the use of system speed load multiples and debug speed store multiples, the state of the systems memory can be fed back to the debug host. there are restrictions on which instructions may have the 33rd bit set. the only valid instructions on which to set this bit are loads, stores, load multiple and store multiple. see also 8.11.3 exit from debug state . when ARM7TDMI returns to debug state after a system speed access, bit 33 of scan chain 1 is set high. this gives the debugger information about why the core entered debug state the ?rst time this scan chain is read. 8.11.3 exit from debug state leaving debug state involves restoring ARM7TDMI s internal state, causing a branch to the next instruction to be executed, and synchronising back to mclk . after restoring internal state, a branch instruction must be loaded into the pipeline. see 8.12 the pcs behaviour during debug on page 8-23 for details on calculating the branch. bit 33 of scan chain 1 is used to force ARM7TDMI to resynchronise back to mclk . the penultimate instruction of the debug sequence is scanned in with bit 33 set high. the ?nal instruction of the debug sequence is the branch, and this is scanned in with
debug interface ARM7TDMI data sheet arm ddi 0029e 8-22 open access bit 33 low. the core is then clocked to load the branch into the pipeline. now, the restar t instruction is selected in the t ap controller . when the state machine enters the run-test/idle state, the scan chain will revert back to system mode and clock resynchronisation to mclk will occur within ARM7TDMI. ARM7TDMI will then resume normal operation, fetching instructions from memory. this delay, until the state machine is in the run-test/idle state, allows conditions to be set up in other devices in a multiprocessor system without taking immediate effect. then, when the run-test/idle state is entered, all the processors resume operation simultaneously. the function of dbgack is to tell the rest of the system when ARM7TDMI is in debug state. this can be used to inhibit peripherals such as watchdog timers which have real time characteristics. also, dbgack can be used to mask out memory accesses which are caused by the debugging process. for example, when ARM7TDMI enters debug state after a breakpoint, the instruction pipeline contains the breakpointed instruction plus two other instructions which have been prefetched. on entry to debug state, the pipeline is ?ushed. therefore, on exit from debug state, the pipeline must be re?lled to its previous state. thus, because of the debugging process, more memory accesses occur than would normally be expected. any system peripheral which may be sensitive to the number of memory accesses can be inhibited through the use of dbgack . for example, imagine a ?ctitious peripheral that simply counts the number of memory cycles. this device should return the same answer after a program has been run both with and without debugging. figure 8-7: debug exit sequence on page 8-22 shows the behaviour of ARM7TDMI on exit from the debug state. figure 8-7: debug exit sequence eclk nmreq seq a[31:0] d[31:0] dbgack internal cycles n s s ab ab+4 ab+8
debug interface ARM7TDMI data sheet arm ddi 0029e 8-23 open access it can be seen from figure 8-2: debug state entry on page 8-4 that the ?nal memory access occurs in the cycle after dbgack goes high, and this is the point at which the cycle counter should be disabled. figure 8-7: debug exit sequence shows that the ?rst memory access that the cycle counter has not seen before occurs in the cycle after dbgack goes low, and so this is the point at which the counter should be re- enabled. note that when a system speed access from debug state occurs, ARM7TDMI temporarily drops out of debug state, and so dbgack can go low. if there are peripherals which are sensitive to the number of memory accesses, they must be led to believe that ARM7TDMI is still in debug state. by programming the icebreaker control register, the value on dbgack can be forced to be high. see chapter 9, icebreaker module for more details. 8.12 the pcs behaviour during debug in order that ARM7TDMI may be forced to branch back to the place at which program ?ow was interrupted by debug, the debugger must keep track of what happens to the pc. there are ?ve cases: breakpoint, watchpoint, watchpoint when another exception occurs, debug request and system speed access. 8.12.1 breakpoint entry to the debug state from a breakpoint advances the pc by 4 addresses, or 16 bytes. each instruction executed in debug state advances the pc by 1 address, or 4 bytes. the normal way to exit from debug state after a breakpoint is to remove the breakpoint, and branch back to the previously breakpointed address. for example, if ARM7TDMI entered debug state from a breakpoint set on a given address and 2 debug speed instructions were executed, a branch of -7 addresses must occur (4 for debug entry, +2 for the instructions, +1 for the ?nal branch). the following sequence shows the data scanned into scan chain 1. this is msb ?rst, and so the ?rst digit is the value placed in the breakpt bit, followed by the instruction data. 0 e0802000; add r2, r0, r0 1 e1826001; orr r6, r2, r1 0 eafffff9; b -7 (2s complement) note that once in debug state, a minimum of two instructions must be executed before the branch, although these may both be nops (mov r0, r0). for small branches, the ?nal branch could be replaced with a subtract with the pc as the destination (sub pc, pc, #28 in the above example). 8.12.2 watchpoints returning to program execution after entering debug state from a watchpoint is done in the same way as the procedure described above. debug entry adds 4 addresses to the pc, and every instruction adds 1 address. the difference is that since the instruction that caused the watchpoint has executed, the program returns to the next instruction.
debug interface ARM7TDMI data sheet arm ddi 0029e 8-24 open access 8.12.3 watchpoint with another exception if a watchpointed access simultaneously causes a data abort, ARM7TDMI will enter debug state in abort mode. entry into debug is held of f until the core has changed into abort mode, and fetched the instruction from the abort vector. a similar sequence is followed when an interrupt, or any other exception, occurs during a watchpointed memory access. ARM7TDMI will enter debug state in the exception's mode, and so the debugger must check to see whether this happened. the debugger can deduce whether an exception occurred by looking at the current and previous mode (in the cpsr and spsr), and the value of the pc. if an exception did take place, the user should be given the choice of whether to service the exception before debugging. exiting debug state if an exception occurred is slightly different from the other cases. here, entry to debug state causes the pc to be incremented by 3 addresses rather than 4, and this must be taken into account in the return branch calculation. for example, suppose that an abort occurred on a watchpointed access and 10 instructions had been executed to determine this. the following sequence could be used to return to program execution. 0 e1a00000; mov r0, r0 1 e1a00000; mov r0, r0 0 eafffff0; b -16 this will force a branch back to the abort vector , causing the instruction at that location to be refetched and executed. note that after the abort service routine, the instruction which caused the abort and watchpoint will be reexecuted. this will cause the watchpoint to be generated and hence ARM7TDMI will enter debug state again. 8.12.4 debug request entry into debug state via a debug request is similar to a breakpoint. however , unlike a breakpoint, the last instruction will have completed execution and so must not be refetched on exit from debug state. therefore, it can be thought that entry to debug state adds 3 addresses to the pc, and every instruction executed in debug state adds 1. for example, suppose that the user has invoked a debug request, and decides to return to program execution straight away. the following sequence could be used: 0 e1a00000; mov r0, r0 1 e1a00000; mov r0, r0 0 eafffffa; b -6 this restores the pc, and restarts the program from the next instruction.
debug interface ARM7TDMI data sheet arm ddi 0029e 8-25 open access 8.12.5 system speed access if a system speed access is performed during debug state, the value of the pc is increased by 3 addresses. since system speed instructions access the memory system, it is possible for aborts to take place. if an abort occurs during a system speed memory access, ARM7TDMI enters abort mode before returning to debug state. this is similar to an aborted watchpoint except that the problem is much harder to ?x, because the abort was not caused by an instruction in the main program, and the pc does not point to the instruction which caused the abort. an abort handler usually looks at the pc to determine the instruction which caused the abort, and hence the abort address. in this case, the value of the pc is invalid, but the debugger should know what location was being accessed. thus the debugger can be written to help the abort handler ?x the memory system. 8.12.6 summary of return address calculations the calculation of the branch return address can be summarised as follows: ? for normal breakpoint and watchpoint, the branch is: - (4 + n + 3s) ? for entry through debug request ( dbgrq ), or watchpoint with exception, the branch is: - (3 + n + 3s) where n is the number of debug speed instructions executed (including the ?nal branch), and s is the number of system speed instructions executed. 8.13 priorities / exceptions because the normal program ?ow is broken when a breakpoint or a debug request occurs, debug can be thought of as being another type of exception. some of the interaction with other exceptions has been described above. this section summarises the priorities. 8.13.1 breakpoint with prefetch abort when a breakpointed instruction fetch causes a prefetch abort, the abort is taken and the breakpoint is disregarded. normally , prefetch aborts occur when, for example, an access is made to a virtual address which does not physically exist, and the returned data is therefore invalid. in such a case the operating systems normal action will be to swap in the page of memory and return to the previously invalid address. this time, when the instruction is fetched, and providing the breakpoint is activated (it may be data dependent), ARM7TDMI will enter debug state. thus the prefetch abort takes higher priority than the breakpoint.
debug interface ARM7TDMI data sheet arm ddi 0029e 8-26 open access 8.13.2 interrupts when ARM7TDMI enters debug state, interrupts are automatically disabled. if interrupts are disabled during debug, ARM7TDMI will never be forced into an interrupt mode. interrupts only have this ef fect on watchpointed accesses. they are ignored at all times on breakpoints. if an interrupt was pending during the instruction prior to entering debug state, ARM7TDMI will enter debug state in the mode of the interrupt. thus, on entry to debug state, the debugger cannot assume that ARM7TDMI will be in the expected mode of the user s program. it must check the pc, the cpsr and the spsr to fully determine the reason for the exception. thus, debug takes higher priority than the interrupt, although ARM7TDMI remembers that an interrupt has occurred. 8.13.3 data aborts as described above, when a data abort occurs on a watchpointed access, ARM7TDMI enters debug state in abort mode. thus the watchpoint has higher priority than the abort, although, as in the case of interrupt, ARM7TDMI remembers that the abort happened. 8.14 scan interface timing figure 8-8: scan general timing tck tms tdi tdo data in data out t bscl t bsch t bsis t bsih t bsoh t bsod t bsss t bssh t bsdh t bsdd t bsdh t bsdd
debug interface ARM7TDMI data sheet arm ddi 0029e 8-27 open access notes 1 for correct data latching, the i/o signals (from the core and the pads) must be setup and held with respect to the rising edge of tck in the capture-dr state of the intest and extest instructions. 2 assumes that the data outputs are loaded with the ac test loads (see ac parameter speci?cation). all delays are provisional and assume a process which achieves 33mhz mclk maximum operating frequency. in the above table all units are ns. symbol parameter min typ max notes tbscl tck low period 15.1 tbsch tck high p eriod 15.1 tbsis tdi , tms setup to [tcr] 0 tbsih tdi , tms hold from [tcr] 0.9 tbsoh tdo hold time 2.4 2 tbsod tcr to tdo valid 16.4 2 tbsss i/o signal setup to [tcr] 3.6 1 tbssh i/o signal hold from [tcr] 7.6 1 tbsdh data output hold time 2.4 2 tbsdd tcf to data output valid 17.1 2 tbsr reset period 25 tbse output enable time 16.4 2 tbsz output disable time 14.7 2 table 8-3: ARM7TDMI scan interface timing
debug interface ARM7TDMI data sheet arm ddi 0029e 8-28 open access no signal type no signal type 1 d[0] i/o 29 d[28] i/o 2 d[1] i/o 30 d[29] i/o 3 d[2] i/o 31 d[30] i/o 4 d[3] i/o 32 d[31] i/o 5 d[4] i/o 33 breakpt i 6 d[5] i/o 34 nenin i 7 d[6] i/o 35 nenout o 8 d[7] i/o 36 lock o 9 d[8] i/o 37 bigend i 10 d[9] i/o 38 dbe i 11 d[10] i/o 39 mas[0] o 12 d[11] i/o 40 mas[1] o 13 d[12] i/o 41 bl[0] i 14 d[13] i/o 42 bl[1] i 15 d[14] i/o 43 bl[2] i 16 d[15] i/o 44 bl[3] i 17 d[16] i/o 45 dctl ** o 18 d[17] i/o 46 nrw o 19 d[18] i/o 47 dbgack o 20 d[19] i/o 48 cgendbgack o 21 d[20] i/o 49 nfiq i 22 d[21] i/o 50 nirq i 23 d[22] i/o 51 nreset i 24 d[23] i/o 52 isync i 25 d[24] i/o 53 dbgrq i 26 d[25] i/o 54 abort i 27 d[26] i/o 55 cpa i 28 d[27] i/o 56 nopc o table 8-4: macrocell scan signals and pins
debug interface ARM7TDMI data sheet arm ddi 0029e 8-29 open access 57 ifen i 82 a[23] o 58 ncpi o 83 a[22] o 59 nmreq o 84 a[21] o 60 seq o 85 a[20] o 61 ntrans o 86 a[19] o 62 cpb i 87 a[18] o 63 nm[4] o 88 a[17] o 64 nm[3] o 89 a[16] o 65 nm[2] o 90 a[15] o 66 nm[1] o 91 a[14] o 67 nm[0] o 92 a[13] o 68 nexec o 93 a[12] o 69 ale i 94 a[11] o 70 abe i 95 a[10] o 71 ape i 96 a[9] o 72 tbit o 97 a[8] o 73 nwait i 98 a[7] o 74 a[31] o 99 a[6] o 75 a[30] o 100 a[5] o 76 a[29] o 101 a[4] o 77 a[28] o 102 a[3] o 78 a[27] o 103 a[2] o 79 a[26] o 104 a[1] o 80 a[25] o 105 a[0] o 81 a[24] o no signal type no signal type table 8-4: macrocell scan signals and pins
debug interface ARM7TDMI data sheet arm ddi 0029e 8-30 open access key i - input o - output i/o - input/output note dctl is not described in this datasheet. dctl is an output from the processor used to control the unidirectional data out latch, dout[31:0] . this signal is not visible from the periphery of ARM7TDMI. 8.15 debug timing notes ? all delays are provisional and assume a process which achieves 33mhz mclk maximum operating frequency. ? assumes that the data outputs are loaded with the ac test loads (see ac parameter specification). ? all units are ns. symbol parameter min max ttdbgd tck falling to dbgack, dbgrqi changing 13.3 ttpfd tckf to tap outputs 10.0 ttpfh tap outputs hold time from tckf 2.4 ttprd tckr to tap outputs 8.0 ttprh tap outputs hold time from tckr 2.4 ttckr tck to tck1, tck2 rising 7.8 ttckf tck to tck1, tck2 falling 6.1 tecapd tck to ecapclk changing 8.2 tdckf dclk induced: tckf to various outputs valid 23.8 tdckfh dclk induced: various outputs hold from tckf 6.0 tdckr dclk induced: tckr to various outputs valid 26.6 tdckrh dclk induced: various outputs hold from tckr 6.0 ttrstd ntrstf to tap outputs valid 8.5 ttrsts ntrstr setup to tckr 2.3 tsdtd sdoutbs to tdo valid 10.0 tclkbs tck to boundary scan clocks 8.2 tshbsr tck to shclkbs, shclk2bs rising 5.7 tshbsf tck to shclkbs, shclk2bs falling 4.0 table 8-5: ARM7TDMI debug interface timing
ARM7TDMI data sheet arm ddi 0029e 9-1 11 1 open access icebreaker module this chapter describes the ARM7TDMI icebreaker module. note the name icebreaker has changed. it is now known as the embeddedice macrocell. future versions of the datasheet will re?ect this change. 9.1 overview 9-2 9.2 the watchpoint registers 9-3 9.3 programming breakpoints 9-6 9.4 programming watchpoints 9-8 9.5 the debug control register 9-9 9.6 debug status register 9-10 9.7 coupling breakpoints and watchpoints 9-11 9.8 disabling icebreaker 9-13 9.9 icebreaker timing 9-13 9.10 programming restriction 9-13 9.11 debug communications channel 9-14 9
icebreaker module ARM7TDMI data sheet arm ddi 0029e 9-2 open access 9.1 overview the ARM7TDMI-icebreaker module, hereafter referred to simply as icebreaker , provides integrated on-chip debug support for the ARM7TDMI core. icebreaker is programmed in a serial fashion using the ARM7TDMI t ap controller. it consists of two real-time watchpoint units, together with a control and status register . one or both of the watchpoint units can be programmed to halt the execution of instructions by the ARM7TDMI core via its breakpt signal. execution is halted when a match occurs between the values programmed into icebreaker and the values currently appearing on the address bus, data bus and various control signals. any bit can be masked so that its value does not affect the comparison. figure 9-1: ARM7TDMI block diagram shows the relationship between the core, icebreaker and the tap controller. note only those signals that are pertinent to icebreaker are shown. figure 9-1: ARM7TDMI block diagram mas[1:0] a[31:0] d[31:0] nopc nrw ntrans dbgacki breakpti dbgrqi ifen eclk nmreq extern1 extern0 breakpt dbgrq dbgack tck dbgen tap icebreaker processor tms tdi tdo sdin sdout ntrst tbit rangeout0 rangeout1
icebreaker module ARM7TDMI data sheet arm ddi 0029e 9-3 open access either watchpoint unit can be con?gured to be a watchpoint (monitoring data accesses) or a breakpoint (monitoring instruction fetches). watchpoints and breakpoints can be made to be data-dependent. t wo independent registers, debug control and debug status, provide overall control of icebreaker's operation. 9.2 the watchpoint registers the two watchpoint units, known as watchpoint 0 and watchpoint 1, each contain three pairs of registers: 1 address value and address mask 2 data value and data mask 3 control value and control mask each register is independently programmable, and has its own address: see table 9-1: function and mapping of icebreaker registers . address width function 00000 3 debug control 00001 5 debug status 00100 6 debug comms control register 00101 32 debug comms data register 01000 32 watchpoint 0 address value 01001 32 watchpoint 0 address mask 01010 32 watchpoint 0 data value 01011 32 watchpoint 0 data mask 01100 9 watchpoint 0 control value 01101 8 watchpoint 0 control mask 10000 32 watchpoint 1address value 10001 32 watchpoint 1 address mask 10010 32 watchpoint 1 data value 10011 32 watchpoint 1 data mask 10100 9 watchpoint 1 control value 10101 8 watchpoint 1 control mask table 9-1: function and mapping of icebreaker registers
icebreaker module ARM7TDMI data sheet arm ddi 0029e 9-4 open access 9.2.1 programming and reading watchpoint registers a register is programmed by scanning data into the icebreaker scan chain (scan chain 2). the scan chain consists of a 38-bit shift register comprising a 32-bit data ?eld, a 5-bit address ?eld and a read/write bit. this is shown in figure 9-2: icebreaker block diagram . figure 9-2: icebreaker block diagram the data to be written is scanned into the 32-bit data ?eld, the address of the register into the 5-bit address ?eld and a 1 into the read/write bit. a register is read by scanning its address into the address ?eld and a 0 into the read/ write bit. the 32-bit data ?eld is ignored. the register addresses are shown in table 9-1: function and mapping of icebreaker registers . note a read or write actually takes place when the tap controller enters the update-dr state. address data address decoder update 32 r/w tdi tdo a[31:0] d[31:0] + watchpoint breakpoint 0 31 0 4 control scan chain register registers and comparators comparator value mask
icebreaker module ARM7TDMI data sheet arm ddi 0029e 9-5 open access 9.2.2 using the mask registers for each v alue register in a register pair , there is a mask register of the same format. setting a bit to 1 in the mask register has the ef fect of making the corresponding bit in the value register disregarded in the comparison. for example, if a watchpoint is required on a particular memory location but the data value is irrelevant, the data mask register can be programmed to 0xffffffff (all bits set to 1) to make the entire data bus ?eld ignored. note the mask is an xnor mask rather than a conventional and mask: when a mask bit is set to 1, the comparator for that bit position will always match, irrespective of the value register or the input value. setting the mask bit to 0 means that the comparator will only match if the input value matches the value programmed into the value register. 9.2.3 the control registers the control v alue and control mask registers are mapped identically in the lower eight bits, as shown below. figure 9-3: watchpoint control value and mask format bit 8 of the control value register is the enable bit, which cannot be masked. the bits have the following functions: nrw : compares against the not read/write signal from the core in order to detect the direction of bus activity . nrw is 0 for a read cycle and 1 for a write cycle. mas[1:0] : compares against the mas[1:0] signal from the core in order to detect the size of bus activity. the encoding is shown in the following table. bit 1 bit 0 data size 0 0 byte 0 1 halfword 1 0 word 1 1 (reserved) table 9-2: mas[1:0] signal encoding enable range chain extern ntrans nopc mas[0] nrw 0 1 2 3 4 5 6 7 8 mas[1]
icebreaker module ARM7TDMI data sheet arm ddi 0029e 9-6 open access nopc : is used to detect whether the current cycle is an instruction fetch ( nopc = 0) or a data access ( nopc = 1). ntrans : compares against the not translate signal from the core in order to distinguish between user mode ( ntrans = 0) and non-user mode ( ntrans = 1) accesses. extern : is an external input to icebreaker which allows the watchpoint to be dependent upon some external condition. the extern input for watchpoint 0 is labelled extern0 and the extern input for watchpoint 1 is labelled extern1 . chain : can be connected to the chain output of another watchpoint in order to implement, for example, debugger requests of the form breakpoint on address yyy only when in process xxx. in the ARM7TDMI-icebreaker , the chainout output of w atchpoint 1 is connected to the chain input of watchpoint 0. the chainout output is derived from a latch; the address/control ?eld comparator drives the write enable for the latch and the input to the latch is the value of the data ?eld comparator. the chainout latch is cleared when the control value register is written or when ntrst is low. range : can be connected to the range output of another watchpoint register . in the ARM7TDMI-icebreaker, the rangeout output of w atchpoint 1 is connected to the range input of w atchpoint 0. this allows the two watchpoints to be coupled for detecting conditions that occur simultaneously, eg for range-checking. enable : if a watchpoint match occurs, the breakpt signal will only be asserted when the enable bit is set. this bit only exists in the value register: it cannot be masked. for each of the bits 8:0 in the control v alue register , there is a corresponding bit in the control mask register. this removes the dependency on particular signals. 9.3 programming breakpoints breakpoints can be classi?ed as hardware breakpoints or software breakpoints. hardware breakpoints typically monitor the address value and can be set in any code, even in code that is in rom or code that is self- modifying. software breakpoints monitor a particular bit pattern being fetched from any address. one icebreaker watchpoint can thus be used to support any number of software breakpoints. software breakpoints can normally only be set in ram because an instruction has to be replaced by the special bit pattern chosen to cause a software breakpoint.
icebreaker module ARM7TDMI data sheet arm ddi 0029e 9-7 open access 9.3.1 hardware breakpoints to make a watchpoint unit cause hardware breakpoints (ie on instruction fetches): 1 program its address value register with the address of the instruction to be breakpointed. 2 for a breakpoint in arm state, program bits [1:0] of the address mask register to 1. for a breakpoint in thumb state, program bit 0 of the address mask to 1. in both cases the remaining bits are set to 0. 3 program the data value register only if you require a data-dependent breakpoint: ie only if the actual instruction code fetched must be matched as well as the address. if the data value is not required, program the data mask register to 0xffffffff (all bits to1), otherwise program it to0x00000000. 4 program the control value register with nopc = 0. 5 program the control mask register with nopc =0, all other bits to 1. 6 if you need to make the distinction between user and non-user mode instruction fetches, program the ntrans value and mask bits as above. 7 if required, program the extern , range and chain bits in the same way. 9.3.2 software breakpoints to make a watchpoint unit cause software breakpoints (ie on instruction fetches of a particular bit pattern): 1 program its address mask register to 0xffffffff (all bits set to 1) so that the address is disregarded. 2 program the data value register with the particular bit pattern that has been chosen to represent a software breakpoint. if a thumb software breakpoint is being programmed, the 16- bit pattern must be repeated in both halves of the data value register. for example, if the bit pattern is 0xdfff, then 0xdfffdfff must be programmed. when a 16- bit instruction is fetched, icebreaker only compares the valid half of the data bus against the contents of the data value register. in this way, a single watchpoint register can be used to catch software breakpoints on both the upper and lower halves of the data bus. 3 program the data mask register to 0x00000000. 4 program the control value register with nopc = 0. 5 program the control mask register with nopc = 0, all other bits to 1. 6 if you wish to make the distinction between user and non-user mode instruction fetches, program the ntrans bit in the control v alue and control mask registers accordingly. 7 if required, program the extern , range and chain bits in the same way. note the address value register need not be programmed.
icebreaker module ARM7TDMI data sheet arm ddi 0029e 9-8 open access setting the breakpoint to set the software breakpoint: 1 read the instruction at the desired address and store it away. 2 write the special bit pattern representing a software breakpoint at the address. clearing the breakpoint to clear the software breakpoint, restore the instruction to the address. 9.4 programming watchpoints to make a watchpoint unit cause watchpoints (ie on data accesses): 1 program its address v alue register with the address of the data access to be watchpointed. 2 program the address mask register to 0x00000000. 3 program the data value register only if you require a data-dependent watchpoint; i.e. only if the actual data value read or written must be matched as well as the address. if the data value is irrelevant, program the data mask register to 0xffffffff (all bits set to 1) otherwise program it to 0x00000000. 4 program the control value register with nopc = 1, nrw = 0 for a read or nrw = 1 for a write, mas[1:0] with the value corresponding to the appropriate data size. 5 program the control mask register with nopc = 0, nrw = 0, mas[1:0] = 0, all other bits to 1. note that nrw or mas[1:0] may be set to 1 if both reads and writes or data size accesses are to be watchpointed respectively. 6 if you wish to make the distinction between user and non-user mode data accesses, program the ntrans bit in the control value and control mask registers accordingly. 7 if required, program the extern , range and chain bits in the same way. note the above are just examples of how to program the watchpoint register to generate breakpoints and watchpoints; many other ways of programming the registers are possible. for instance, simple range breakpoints can be provided by setting one or more of the address mask bits.
icebreaker module ARM7TDMI data sheet arm ddi 0029e 9-9 open access 9.5 the debug control register the debug control register is 3 bits wide. if the register is accessed for a write (with the read/write bit high), the control bits are written. if the register is accessed for a read (with the read/write bit low), the control bits are read. the function of each bit in this register is as follows: figure 9-4: debug control register format bits 1 and 0 allow the values on dbgrq and dbgack to be forced. as shown in figure 9-6: structure of tbit, nmreq, dbgack, dbgrq and intdis bits on page 9-11 , the value stored in bit 1 of the control register is synchronised and then ored with the external dbgrq before being applied to the processor. the output of this or gate is the signal dbgrqi which is brought out externally from the macrocell. the synchronisation between control bit 1 and dbgrqi is to assist in multiprocessor environments. the synchronisation latch only opens when the tap controller state machine is in the run-test/idle state. this allows an enter debug condition to be set up in all the processors in the system while they are still running. once the condition is set up in all the processors, it can then be applied to them simultaneously by entering the run-test/idle state. in the case of dbgack , the value of dbgack from the core is ored with the value held in bit 0 to generate the external value of dbgack seen at the periphery of ARM7TDMI. this allows the debug system to signal to the rest of the system that the core is still being debugged even when system-speed accesses are being performed (in which case the internal dbgack signal from the core will be low). if bit 2 ( intdis ) is asserted, the interrupt enable signal ( ifen ) of the core is forced low . thus all interrupts (irq and fiq) are disabled during debugging ( dbgack =1) or if the intdis bit is asserted. the ifen signal is driven according to the following table: dbgack intdis ifen 0 0 1 1 x 0 x 1 0 table 9-3: ifen signal control intdis dbgrq dbgack 0 1 2
icebreaker module ARM7TDMI data sheet arm ddi 0029e 9-10 open access 9.6 debug status register the debug status register is 5 bits wide. if it is accessed for a write (with the read/ write bit set high), the status bits are written. if it is accessed for a read (with the read/ write bit low), the status bits are read. figure 9-5: debug status register format the function of each bit in this register is as follows: bits 1 and 0 allow the values on the synchronised versions of dbgrq and dbgack to be read. bit 2 allows the state of the core interrupt enable signal ( ifen ) to be read. since the capture clock for the scan chain may be asynchronous to the processor clock, the dbgack output from the core is synchronised before being used to generate the ifen status bit. bit 3 allows the state of the nmreq signal from the core (synchronised to tck ) to be read. this allows the debugger to determine that a memory access from the debug state has completed. bit 4 allows tbit to be read. this enables the debugger to determine what state the processor is in, and hence which instructions to execute. the structure of the debug status register bits is shown in figure 9-6: structure of tbit, nmreq, dbgack, dbgrq and intdis bits on page 9-11. ifen dbgrq dbgack 0 1 2 3 nmreq 4 tbit
icebreaker module ARM7TDMI data sheet arm ddi 0029e 9-11 open access figure 9-6: structure of tbit, nmreq, dbgack, dbgrq and intdis bits 9.7 coupling breakpoints and watchpoints w atchpoint units 1 and 0 can be coupled together via the chain and range inputs. the use of chain enables watchpoint 0 to be triggered only if watchpoint 1 has previously matched. the use of range enables simple range checking to be performed by combining the outputs of both watchpoints. dbgrq dbgrq dbgack dbgack bit 1 bit 1 debug control register debug status register (from ARM7TDMI input) (to ARM7TDMI output) (to core and (from core) + bit 0 + bit 2 bit 2 + ifen (to core) dbgack (from core) synch bit 0 synch + bit 3 synch nmreq (from core) bit 4 synch tbit (from core) synch ARM7TDMI output)
icebreaker module ARM7TDMI data sheet arm ddi 0029e 9-12 open access example let a v [31:0] be the value in the address value register a m [31:0] be the value in the address mask register a[31:0] be the address bus from the ARM7TDMI d v [31:0] be the value in the data value register d m [31:0] be the value in the data mask register d[31:0] be the data bus from the ARM7TDMI c v [8:0] be the value in the control value register c m [7:0] be the value in the control mask register c[9:0] be the combined control bus from the ARM7TDMI, other watchpoint registers and the extern signal. chainout signal the chainout signal is then derived as follows: when (({a v [31:0],c v [4:0]} xnor {a[31:0],c[4:0]}) or {a m [31:0],c m [4:0]} == 0xfffffffff) chainout = ((({d v [31:0],c v [6:4]} xnor {d[31:0],c[7:5]}) or {d m [31:0],c m [7:5]}) == 0x7ffffffff) the chainout output of watchpoint register 1 provides the chain input to watchpoint 0. this allows for quite complicated con?gurations of breakpoints and watchpoints. t ake for example the request by a debugger to breakpoint on the instruction at location yyy when running process xxx in a multiprocess system. if the current process id is stored in memory , the above function can be implemented with a watchpoint and breakpoint chained together. the watchpoint address is set to a known memory location containing the current process id, the watchpoint data is set to the required process id and the enable bit is set to off. the address comparator output of the watchpoint is used to drive the write enable for the chainout latch, the input to the latch being the output of the data comparator from the same watchpoint. the output of the latch drives the chain input of the breakpoint comparator . the address yyy is stored in the breakpoint register and when the chain input is asserted, and the breakpoint address matches, the breakpoint triggers correctly. rangeout signal the rangeout signal is then derived as follows: rangeout = ((({a v [31:0],c v [4:0]} xnor {a[31:0],c[4:0]}) or {a m [31:0],c m [4:0]}) == 0xfffffffff) and ((({d v [31:0],c v [7:5]} xnor {d[31:0],c[7:5]}) or {d m [31:0],c m [7:5]}) == 0x7ffffffff)
icebreaker module ARM7TDMI data sheet arm ddi 0029e 9-13 open access the rangeout output of watchpoint register 1 provides the range input to watchpoint register 0. this allows two breakpoints to be coupled together to form range breakpoints. note that selectable ranges are restricted to being powers of 2. this is best illustrated by an example. example if a breakpoint is to occur when the address is in the ?rst 256 bytes of memory , but not in the ?rst 32 bytes, the watchpoint registers should be programmed as follows: 1 watchpoint 1 is programmed with an address value of 0x00000000 and an address mask of 0x0000001f. the enable bit is cleared. all other watchpoint 1 registers are programmed as normal for a breakpoint. an address within the ?rst 32 bytes will cause the range output to go high but the breakpoint will not be triggered. 2 watchpoint 0 is programmed with an address value of 0x00000000 and an address mask of 0x000000ff. the enable bit is set and the range bit programmed to match a 0. all other watchpoint 0 registers are programmed as normal for a breakpoint. if w atchpoint 0 matches but w atchpoint 1 does not (ie the range input to w atchpoint 0 is 0), the breakpoint will be triggered. 9.8 disabling icebreaker icebreaker may be disabled by wiring the dbgen input low. when dbgen is low, breakpt and dbgrq to the core are forced low, dbgack from the ARM7TDMI is also forced low and the ifen input to the core is forced high, enabling interrupts to be detected by ARM7TDMI. when dbgen is low, icebreaker is also put into a low-power mode. 9.9 icebreaker timing the extern1 and extern0 inputs are sampled by icebreaker on the falling edge of eclk . suf?cient set-up and hold time must therefore be allowed for these signals. 9.10 programming restriction the icebreaker watchpoint units should only be programmed when the clock to the core is stopped. this can be achieved by putting the core into the debug state. the reason for this restriction is that if the core continues to run at eclk rates when icebreaker is being programmed at tck rates, it is possible for the breakpt signal to be asserted asynchronously to the core. this restriction does not apply if mclk and tck are driven from the same clock, or if it is known that the breakpoint or watchpoint condition can only occur some time after icebreaker has been programmed. note this restriction does not apply in any event to the debug control or status registers.
icebreaker module ARM7TDMI data sheet arm ddi 0029e 9-14 open access 9.11 debug communications channel ARM7TDMI s icebreaker contains a communication channel for passing information between the target and the host debugger. this is implemented as coprocessor 14. the communications channel consists of a 32- bit wide comms data read register , a 32- bit wide comms data w rite register and a 6- bit wide comms control register for synchronised handshaking between the processor and the asynchronous debugger. these registers live in ?xed locations in icebreakers memory map (as shown in table 9-1: function and mapping of icebreaker registers on page 9-3) and are accessed from the processor via mcr and mrc instructions to coprocessor 14. 9.11.1 debug comms channel registers the debug comms control register is read only and allows synchronised hanshaking between the processor and the debugger. figure 9-7: debug comms control register the function of each register bit is described below: bits 31:28 contain a ?xed pattern which denote the icebreaker version number , in this case 0001. bit 1 denotes whether the comms data write register (from the processor s point of view) is free. from the processor s point of view , if the comms data w rite register is free (w=0) then new data may be written. if it is not free (w=1), then the processor must poll until w=0. from the debuggers point of view, if w=1 then some new data has been written which may then be scanned out. bit 0 denotes whether there is some new data in the comms data read register . from the processor s point of view , if r=1, then there is some new data which may be read via an mrc instruction. from the debugger s point of view , if r=0 then the comms data read register is free and new data may be placed there through the scan chain. if r=1, then this denotes that data previously placed there through the scan chain has not been collected by the processor and so the debugger must wait. from the debugger s point of view , the registers are accessed via the scan chain in the usual way . from the processor , these registers are accessed via coprocessor register transfer instructions. 31 0 30 0 29 0 28 1 0 r 1 w ... ...
icebreaker module ARM7TDMI data sheet arm ddi 0029e 9-15 open access the following instructions should be used: mrc cp14, 0, rd, c0, c0 returns the debug comms control register into rd mcr cp14, 0, rn, c1, c0 writes the value in rn to the comms data write register mrc cp14, 0, rd, c1, c0 returns the debug data read register into rd since the thumb instruction set does not contain coprocessor instructions, it is recommended that these are accessed via swi instructions when in thumb state. 9.11.2 communications via the comms channel communication between the debugger and the processor occurs as follows. when the processor wishes to send a message to icebreaker, it ?rst checks that the comms data w rite register is free for use. this is done by reading the debug comms control register to check that the w bit is clear . if it is clear then the comms data w rite register is empty and a message is written by a register transfer to the coprocessor . the action of this data transfer automatically sets the w bit. if on reading the w bit it is found to be set, then this implys that previously written data has not been picked up by the debugger and thus the processor must poll until the w bit is clear. as the data transfer occurs from the processor to the comms data w rite register, the w bit is set in the debug comms control register. when the debugger polls this register it sees a synchronised version of both the r and w bit. when the debugger sees that the w bit is set it can read the comms data w rite register and scan the data out. the action of reading this data register clears the w bit of the debug comms control register. at this point, the communications process may begin again. message transfer from the debugger to the processor is carried out in a similar fashion. here, the debugger polls the r bit of the debug comms control register . if the r bit is low then the data read register is free and so data can be placed there for the processor to read. if the r bit is set, then previously deposited data has not yet been collected and so the debugger must wait. when the comms data read register is free, data is written there via the scan chain. the action of this write sets the r bit in the debug comms control register . when the processor polls this register , it sees an mclk synchronised version. if the r bit is set then this denotes that there is data waiting to be collected, and this can be read via a cprt load. the action of this load clears the r bit in the debug comms control register. when the debugger polls this register and sees that the r bit is clear, this denotes that the data has been taken and the process may now be repeated.
icebreaker module ARM7TDMI data sheet arm ddi 0029e 9-16 open access
ARM7TDMI data sheet arm ddi 0029e 10-1 11 1 open access instruction cycle operations this chapter describes the ARM7TDMI instruction cycle operations. 10.1 introduction 10-2 10.2 branch and branch with link 10-2 10.3 thumb branch with link 10-3 10.4 branch and exchange (bx) 10-3 10.5 data operations 10-4 10.6 multiply and multiply accumulate 10-6 10.7 load register 10-8 10.8 store register 10-9 10.9 load multiple registers 10-9 10.10 store multiple registers 10-11 10.11 data swap 10-11 10.12 software interrupt and exception entry 10-12 10.13 coprocessor data operation 10-13 10.14 coprocessor data transfer (from memory to coprocessor) 10-14 10.15 coprocessor data transfer (from coprocessor to memory) 10-15 10.16 coprocessor register transfer (load from coprocessor) 10-16 10.17 coprocessor register transfer (store to coprocessor) 10-17 10.18 unde?ned instructions and coprocessor absent 10-18 10.19 unexecuted instructions 10-18 10.20 instruction speed summary 10-19 10
instruction cycle operations ARM7TDMI data sheet arm ddi 0029e 10-2 open access 10.1 introduction in the following tables nmreq and seq (which are pipelined up to one cycle ahead of the cycle to which they apply) are shown in the cycle in which they appear , so they predict the type of the next cycle. the address, mas[1:0] , nrw , nopc, ntrans and tbit (which appear up to half a cycle ahead) are shown in the cycle to which they apply . the address is incremented for prefetching of instructions in most cases. since the instruction width is 4 bytes in arm state and 2 bytes in thumb state, the increment will vary accordingly . hence the letter l is used to indicate instruction length (4 bytes in arm state and 2 bytes in thumb state). similarly, mas[1:0] will indicate the width of the instruction fetch, i=2 in arm state and i=1 in thumb state representing word and halfword accesses respectively. 10.2 branch and branch with link a branch instruction calculates the branch destination in the ?rst cycle, whilst performing a prefetch from the current pc. this prefetch is done in all cases, since by the time the decision to take the branch has been reached it is already too late to prevent the prefetch. during the second cycle a fetch is performed from the branch destination, and the return address is stored in register 14 if the link bit is set. the third cycle performs a fetch from the destination + l, re?lling the instruction pipeline, and if the branch is with link r14 is modi?ed (4 is subtracted from it) to simplify return from sub pc,r14,#4 to mov pc,r14 . this makes the stm..{r14} ldm..{pc} type of subroutine work correctly. the cycle timings are shown below in table 10-1: branch instruction cycle operations : pc is the address of the branch instruction alu is an address calculated by ARM7TDMI (alu) are the contents of that address note this applies to branches in arm and thumb state, and to branch with link in arm state only. cycle address mas[1:0] nrw data nmreq seq nopc 1 pc+2l i 0 (pc + 2l) 0 0 0 2 alu i 0 (alu) 0 1 0 3 alu+l i 0 (alu + l) 0 1 0 alu+2l table 10-1: branch instruction cycle operations
instruction cycle operations ARM7TDMI data sheet arm ddi 0029e 10-3 open access 10.3 thumb branch with link a thumb branch with link operation consists of two consecutive thumb instructions, see 5.19 format 19: long branch with link on page 5-40. the ?rst instruction acts like a simple data operation, taking a single cycle to add the pc to the upper part of the offset, storing the result in register 14 (lr). the second instruction acts in a similar fashion to the arm branch with link instruction, thus its ?rst cycle calculates the ?nal branch destination whilst performing a prefetch from the current pc. the second cycle of the second instruction performs a fetch from the branch destination and the return address is stored in r14. the third cycle of the second instruction performs a fetch from the destination +2, re?lling the instruction pipeline and r14 is modi?ed (2 subtracted from it) to simplify the return to mov pc, r14 . this makes the push {..,lr} ; pop {..,pc} type of subroutine work correctly. the cycle timings of the complete operation are shown in table 10-2: thumb long branch with link pc is the address of the ?rst instruction of the operation. 10.4 branch and exchange (bx) a branch and exchange operation takes 3 cycles and is similar to a branch. in the ?rst cycle, the branch destination and the new core state are extracted from the register source, whilst performing a prefetch from the current pc. this prefetch is performed in all cases, since by the time the decision to take the branch has been reached, it is already too late to prevent the prefetch. during the second cycle, a fetch is performed from the branch destination using the new instruction width, dependent on the state that has been selected. the third cycle performs a fetch from the destination +2 or +4 dependent on the new speci?ed state, re?lling the instruction pipeline. the cycle timings are shown in table 10-3: branch and exchange instruction cycle operations on page 10-4. cycle address mas[1:0] nrw data nmreq seq nopc 1 pc + 4 1 0 (pc + 4) 0 1 0 2 pc + 6 1 0 (pc + 6) 0 0 0 3 alu 1 0 (alu) 0 1 0 4 alu + 2 1 0 (alu + 2) 0 1 0 alu + 4 table 10-2: thumb long branch with link
instruction cycle operations ARM7TDMI data sheet arm ddi 0029e 10-4 open access notes: 1 w and w represent the instruction width before and after the bx respectively . in arm state the width equals 4 bytes and in thumb state the width equals 2 bytes. for example, when changing from arm to thumb state, w would equal 4 and w would equal 2. 2 i and i represent the memory access size before and after the bx respectively . in arm state, the mas[1:0] is 2 and in thumb state mas[1:0] is 1. when changing from thumb to arm state, i would equal 1 and i would equal 2. 3 t and t represent the state of the tbit before and after the bx respectively. in arm state tbit is 0 and in thumb state tbit is 1. when changing from arm to thumb state, t would equal 0 and t would equal 1. 10.5 data operations a data operation executes in a single datapath cycle except where the shift is determined by the contents of a register. a register is read onto the a bus, and a second register or the immediate ?eld onto the b bus. the alu combines the a bus source and the shifted b bus source according to the operation speci?ed in the instruction, and the result (when required) is written to the destination register. (compares and tests do not produce results, only the alu status ?ags are affected.) an instruction prefetch occurs at the same time as the above operation, and the program counter is incremented. when the shift length is speci?ed by a register, an additional datapath cycle occurs before the above operation to copy the bottom 8 bits of that register into a holding latch in the barrel shifter. the instruction prefetch will occur during this ?rst cycle, and the operation cycle will be internal (ie will not request memory). this internal cycle can be merged with the following sequential access by the memory manager as the address remains stable through both cycles. the pc may be one or more of the register operands. when it is the destination, external bus activity may be af fected. if the result is written to the pc, the contents of the instruction pipeline are invalidated, and the address for the next instruction prefetch is taken from the alu rather than the address incrementer. the instruction pipeline is re?lled before any further execution takes place, and during this time exceptions are locked out. cycle address mas [1:0] nrw data nmreq seq nopc tbit 1 pc + 2w i 0 (pc + 2w) 0 0 0 t 2 alu i 0 (alu) 0 1 0 t 3 alu+w i 0 (alu+w) 0 1 0 t alu + 2w table 10-3: branch and exchange instruction cycle operations
instruction cycle operations ARM7TDMI data sheet arm ddi 0029e 10-5 open access psr transfer operations exhibit the same timing characteristics as the data operations except that the pc is never used as a source or destination register. the cycle timings are shown below table 10-4: data operation instruction cycle operations . note shifted registed with destination equals pc is not possible in thumb state. cycle address mas[1:0] nrw data nmreq seq nopc normal 1 pc+2l i 0 (pc+2l) 0 1 0 pc+3l dest=pc 1 pc+2l i 0 (pc+2l) 0 0 0 2 alu i 0 (alu) 0 1 0 3 alu+l i 0 (alu+l) 0 1 0 alu+2l shift(rs) 1 pc+2l i 0 (pc+2l) 1 0 0 2 pc+3l i 0 - 0 1 1 pc+3l shift(rs) 1 pc+8 2 0 (pc+8) 1 0 0 dest=pc 2 pc+12 2 0 - 0 0 1 3 alu 2 0 (alu) 0 1 0 4 alu+4 2 0 (alu+4) 0 1 0 alu+8 table 10-4: data operation instruction cycle operations
instruction cycle operations ARM7TDMI data sheet arm ddi 0029e 10-6 open access 10.6 multiply and multiply accumulate the multiply instructions make use of special hardware which implements integer multiplication with early termination. all cycles except the ?rst are internal. the cycle timings are shown in the following four tables, where m is the number of cycles required by the multiplication algorithm; see 10.20 instruction speed summary on page 10-19. cycle address nrw mas[1:0] data nmreq seq nopc 1 pc+2l 0 i (pc+2l) 1 0 0 2 pc+3l 0 i - 1 0 1 ? pc+3l 0 i - 1 0 1 m pc+3l 0 i - 1 0 1 m+1 pc+3l 0 i - 0 1 1 pc+3l table 10-5: multiply instruction cycle operations cycle address nrw mas[1:0] data nmreq seq nopc 1 pc+8 0 2 (pc+8) 1 0 0 2 pc+8 0 2 - 1 0 1 ? pc+12 0 2 - 1 0 1 m pc+12 0 2 - 1 0 1 m+1 pc+12 0 2 - 1 0 1 m+2 pc+12 0 2 - 0 1 1 pc+12 table 10-6: multiply-accumulate instruction cycle operations
instruction cycle operations ARM7TDMI data sheet arm ddi 0029e 10-7 open access note multiply-accumulate is not possible in thumb state. cycle address nrw mas[1:0] data nmreq seq nopc 1 pc+2l 0 i (pc+2l) 1 0 0 2 pc+3l 0 i - 1 0 1 ? pc+3l 0 i - 1 0 1 m pc+3l 0 i - 1 0 1 m+1 pc+3l 0 i - 1 0 1 m+2 pc+3l 0 i - 0 1 1 pc+3l table 10-7: multiply long instruction cycle operations cycle address nrw mas[1:0] data nmreq seq nopc 1 pc+8 0 2 (pc+8) 1 0 0 2 pc+8 0 2 - 1 0 1 ? pc+12 0 2 - 1 0 1 m pc+12 0 2 - 1 0 1 m+1 pc+12 0 2 - 1 0 1 m+2 pc+12 0 2 - 1 0 1 m+3 pc+12 0 2 - 0 1 1 pc+12 table 10-8: multiply-accumulate long instruction cycle operations
instruction cycle operations ARM7TDMI data sheet arm ddi 0029e 10-8 open access 10.7 load register the ?rst cycle of a load register instruction performs the address calculation. the data is fetched from memory during the second cycle, and the base register modi?cation is performed during this cycle (if required). during the third cycle the data is transferred to the destination register, and external memory is unused. this third cycle may normally be merged with the following prefetch to form one memory n-cycle. the cycle timings are shown below in table 10-9: load register instruction cycle operations . either the base or the destination (or both) may be the pc, and the prefetch sequence will be changed if the pc is affected by the instruction. the data fetch may abort, and in this case the destination modi?cation is prevented. b, h and w are byte, halfword and word as de?ned in table 9-2: mas[1:0] signal encoding on page 9-5. c represents current mode-dependent value. d will either be 0 if the t bit has been speci?ed in the instruction (eg. ldr t), or c at all other times. note destination equals pc is not possible in thumb state. cycle address mas[1:0] nrw data nmreq seq nopc ntrans normal 1 pc+2l i 0 (pc+2l) 0 0 0 c 2 alu b/h/w 0 (alu) 1 0 1 d 3 pc+3l i 0 - 0 1 1 c pc+3l dest=pc 1 pc+8 2 0 (pc+8) 0 0 0 c 2 alu 0 pc 1 0 1 d 3 pc+12 2 0 - 0 0 1 c 4 pc 2 0 (pc) 0 1 0 c 5 pc+4 2 0 (pc+4) 0 1 0 c pc+8 table 10-9: load register instruction cycle operations
instruction cycle operations ARM7TDMI data sheet arm ddi 0029e 10-9 open access 10.8 store register the ?rst cycle of a store register is similar to the ?rst cycle of load register . during the second cycle the base modi?cation is performed, and at the same time the data is written to memory. there is no third cycle. the cycle timings are shown below in table 10-10: store register instruction cycle operations . b, h and w are byte, halfword and word as de?ned in table 9-2: mas[1:0] signal encoding on page 9-5. c represents current mode-dependent value d will either be 0 if the t bit has been speci?ed in the instruction (eg. sdr t), or c at all other times. 10.9 load multiple registers the ?rst cycle of ldm is used to calculate the address of the ?rst word to be transferred, whilst performing a prefetch from memory. the second cycle fetches the ?rst word, and performs the base modi?cation. during the third cycle, the ?rst word is moved to the appropriate destination register while the second word is fetched from memory, and the modi?ed base is latched internally in case it is needed to patch up after an abort. the third cycle is repeated for subsequent fetches until the last data word has been accessed, then the ?nal (internal) cycle moves the last word to its destination register. the cycle timings are shown in table 10-11: load multiple registers instruction cycle operations on page 10-10. the last cycle may be merged with the next instruction prefetch to form a single memory n-cycle. if an abort occurs, the instruction continues to completion, but all register writing after the abort is prevented. the ?nal cycle is altered to restore the modi?ed base register (which may have been overwritten by the load activity before the abort occurred). when the pc is in the list of registers to be loaded the current instruction pipeline must be invalidated. note the pc is always the last register to be loaded, so an abort at any point will prevent the pc from being overwritten. note ldm with destination = pc cannot be executed in thumb state. however pop{rlist,pc} equates to an ldm with destination=pc. cycle address mas[1:0] nrw data nmreq seq nopc ntrans 1 pc+2l i 0 (pc+2l) 0 0 0 c 2 alu b/h/w 1 rd 0 0 1 d pc+3l table 10-10: store register instruction cycle operations
instruction cycle operations ARM7TDMI data sheet arm ddi 0029e 10-10 open access cycle address mas[1:0] nrw data nmreq seq nopc 1 register 1 pc+2l i 0 (pc+2l) 0 0 0 2 alu 2 0 (alu) 1 0 1 3 pc+3l i 0 - 0 1 1 pc+3l 1 register 1 pc+2l i 0 (pc+2l) 0 0 0 dest=pc 2 alu 2 0 pc 1 0 1 3 pc+3l i 0 - 0 0 1 4 pc i 0 (pc) 0 1 0 5 pc+l i 0 (pc+l) 0 1 0 pc+2l n registers 1 pc+2l i 0 (pc+2l) 0 0 0 (n>1) 2 alu 2 0 (alu) 0 1 1 ? alu+? 2 0 (alu+?) 0 1 1 n alu+? 2 0 (alu+?) 0 1 1 n+1 alu+? 2 0 (alu+?) 1 0 1 n+2 pc+3l i 0 - 0 1 1 pc+3l n registers 1 pc+2l i 0 (pc+2l) 0 0 0 (n>1) 2 alu 2 0 (alu) 0 1 1 incl pc ? alu+? 2 0 (alu+?) 0 1 1 n alu+? 2 0 (alu+?) 0 1 1 n+1 alu+? 2 0 pc 1 0 1 n+2 pc+3l i 0 - 0 0 1 n+3 pc i 0 (pc) 0 1 0 n+4 pc+l i 0 (pc+l) 0 1 0 pc+2l table 10-11: load multiple registers instruction cycle operations
instruction cycle operations ARM7TDMI data sheet arm ddi 0029e 10-11 open access 10.10store multiple registers store multiple proceeds very much as load multiple, without the ?nal cycle. the restart problem is much more straightforward here, as there is no wholesale overwriting of registers. the cycle timings are shown in table 10-12: store multiple registers instruction cycle operations , below. 10.11 data swap this is similar to the load and store register instructions, but the actual swap takes place in cycles 2 and 3. in the second cycle, the data is fetched from external memory . in the third cycle, the contents of the source register are written out to the external memory. the data read in cycle 2 is written into the destination register during the fourth cycle. the cycle timings are shown below in table 10-13: data swap instruction cycle operations on page 10-11. the lock output of ARM7TDMI is driven high for the duration of the swap operation (cycles 2 and 3) to indicate that both cycles should be allowed to complete without interruption. the data swapped may be a byte or word quantity (b/w). the swap operation may be aborted in either the read or write cycle, and in both cases the destination register will not be affected. cycle address mas[1:0] nrw data nmreq seq nopc 1 register 1 pc+2l i 0 (pc+2l) 0 0 0 2 alu 2 1 ra 0 0 1 pc+3l n registers 1 pc+8 i 0 (pc+2l) 0 0 0 (n>1) 2 alu 2 1 ra 0 1 1 ? alu+? 2 1 r? 0 1 1 n alu+? 2 1 r? 0 1 1 n+1 alu+? 2 1 r? 0 0 1 pc+12 table 10-12: store multiple registers instruction cycle operations cycle address mas[1:0] nrw data nmreq seq nopc lock 1 pc+8 2 0 (pc+8) 0 0 0 0 2 rn b/w 0 (rn) 0 0 1 1 table 10-13: data swap instruction cycle operations
instruction cycle operations ARM7TDMI data sheet arm ddi 0029e 10-12 open access b and w are byte and word as de?ned in table 9-2: mas[1:0] signal encoding on page 9-5. note data swap cannot be executed in thumb state. 10.12software interrupt and exception entry exceptions (and software interrupts) force the pc to a particular value and re?ll the instruction pipeline from there. during the ?rst cycle the forced address is constructed, and a mode change may take place. the return address is moved to r14 and the cpsr to spsr_svc. during the second cycle the return address is modi?ed to facilitate return, though this modi?cation is less useful than in the case of branch with link. the third cycle is required only to complete the re?lling of the instruction pipeline. the cycle timings are shown below in table 10-14: software interrupt instruction cycle operations . c represents the current mode-dependent value. t represents the current state-dependent value pc for software interrupts is the address of the swi instruction. for exceptions is the address of the instruction following the last one to be executed before entering the exception. for prefetch aborts is the address of the aborting instruction. for data aborts is the address of the instruction following the one which attempted the aborted data transfer. xn is the appropriate trap address. 3 rn b/w 1 rm 1 0 1 1 4 pc+12 2 0 - 0 1 1 0 pc+12 cycle address mas[1:0] nrw data nmreq seq nopc ntrans mode tbit 1 pc+2l i 0 (pc+2l) 0 0 0 c old mode t 2 xn 2 0 (xn) 0 1 0 1 exception mode 0 3 xn+4 2 0 (xn+4) 0 1 0 1 exception mode 0 xn+8 table 10-14: software interrupt instruction cycle operations cycle address mas[1:0] nrw data nmreq seq nopc lock table 10-13: data swap instruction cycle operations
instruction cycle operations ARM7TDMI data sheet arm ddi 0029e 10-13 open access 10.13coprocessor data operation a coprocessor data operation is a request from ARM7TDMI for the coprocessor to initiate some action. the action need not be completed for some time, but the coprocessor must commit to doing it before driving cpb low. if the coprocessor can never do the requested task, it should leave cpa and cpb high. if it can do the task, but cant commit right now, it should drive cpa low but leave cpb high until it can commit. ARM7TDMI will busy-wait until cpb goes low. the cycle timings are shown in table 10-15: coprocessor data operation instruction cycle operations . note this operation cannot occur in thumb state. cycle address nrw mas[1:0] data nmreq seq nopc ncpi cpa cpb ready 1 pc+8 0 2 (pc+8) 0 0 0 0 0 0 pc+12 not ready 1 pc+8 0 2 (pc+8) 1 0 0 0 0 1 2 pc+8 0 2 - 1 0 1 0 0 1 ? pc+8 0 2 - 1 0 1 0 0 1 n pc+8 0 2 - 0 0 1 0 0 0 pc+12 table 10-15: coprocessor data operation instruction cycle operations
instruction cycle operations ARM7TDMI data sheet arm ddi 0029e 10-14 open access 10.14coprocessor data transfer (from memory to coprocessor) here the coprocessor should commit to the transfer only when it is ready to accept the data. when cpb goes low, ARM7TDMI will produce addresses and expect the coprocessor to take the data at sequential cycle rates. the coprocessor is responsible for determining the number of words to be transferred, and indicates the last transfer cycle by driving cpa and cpb high. ARM7TDMI spends the ?rst cycle (and any busy-wait cycles) generating the transfer address, and performs the write-back of the address base during the transfer cycles. the cycle timings are shown in table 10-16: coprocessor data transfer instruction cycle operations on page 10-14 . cycles address mas [1:0] nrw data nmreq seq nopc ncpi cpa cpb 1 register 1 pc+8 2 0 (pc+8) 0 0 0 0 0 0 ready 2 alu 2 0 (alu) 0 0 1 1 1 1 pc+12 1 register 1 pc+8 2 0 (pc+8) 1 0 0 0 0 1 not ready 2 pc+8 2 0 - 1 0 1 0 0 1 ? pc+8 2 0 - 1 0 1 0 0 1 n pc+8 2 0 - 0 0 1 0 0 0 n+1 alu 2 0 (alu) 0 0 1 1 1 1 pc+12 n regis- ters 1 pc+8 2 0 (pc+8) 0 0 0 0 0 0 (n>1) 2 alu 2 0 (alu) 0 1 1 1 0 0 ready ? alu+? 2 0 (alu+?) 0 1 1 1 0 0 n alu+? 2 0 (alu+?) 0 1 1 1 0 0 n+1 alu+? 2 0 (alu+?) 0 0 1 1 1 1 pc+12 table 10-16: coprocessor data transfer instruction cycle operations
instruction cycle operations ARM7TDMI data sheet arm ddi 0029e 10-15 open access note this operation cannot occur in thumb state. 10.15coprocessor data transfer (from coprocessor to memory) the ARM7TDMI controls these instructions exactly as for memory to coprocessor transfers, with the one exception that the nrw line is inverted during the transfer cycle. the cycle timings are show in table 10-17: coprocessor data transfer instruction cycle operations . m regis- ters 1 pc+8 2 0 (pc+8) 1 0 0 0 0 1 (m>1) 2 pc+8 2 0 - 1 0 1 0 0 1 not ready ? pc+8 2 0 - 1 0 1 0 0 1 n pc+8 2 0 - 0 0 1 0 0 0 n+1 alu 2 0 (alu) 0 1 1 1 0 0 ? alu+? 0 (alu+?) 0 1 1 1 0 0 n+m alu+? 2 0 (alu+?) 0 1 1 1 0 0 n+m+1 alu+? 2 0 (alu+?) 0 0 1 1 1 1 pc+12 cycle address mas [1:0] nrw data nmreq seq nopc ncpi cpa cpb 1 register 1 pc+8 2 0 (pc+8) 0 0 0 0 0 0 ready 2 alu 2 1 cpdata 0 0 1 1 1 1 pc+12 1 register 1 pc+8 2 0 (pc+8) 1 0 0 0 0 1 not ready 2 pc+8 2 0 - 1 0 1 0 0 1 ? pc+8 2 0 - 1 0 1 0 0 1 n pc+8 2 0 - 0 0 1 0 0 0 n+1 alu 2 1 cpdata 0 0 1 1 1 1 table 10-17: coprocessor data transfer instruction cycle operations cycles address mas [1:0] nrw data nmreq seq nopc ncpi cpa cpb table 10-16: coprocessor data transfer instruction cycle operations
instruction cycle operations ARM7TDMI data sheet arm ddi 0029e 10-16 open access note this operation cannot occur in thumb state. 10.16coprocessor register transfer (load from coprocessor) here the busy-wait cycles are much as above, but the transfer is limited to one data word, and ARM7TDMI puts the word into the destination register in the third cycle. the third cycle may be merged with the following prefetch cycle into one memory n-cycle as with all ARM7TDMI register load instructions. the cycle timings are shown in table 10-18: coprocessor register transfer (load from coprocessor) . pc+12 n registers 1 pc+8 2 0 (pc+8) 0 0 0 0 0 0 (n>1) 2 alu 2 1 cpdata 0 1 1 1 0 0 ready ? alu+? 2 1 cpdata 0 1 1 1 0 0 n alu+? 2 1 cpdata 0 1 1 1 0 0 n+1 alu+? 2 1 cpdata 0 0 1 1 1 1 pc+12 m registers 1 pc+8 2 0 (pc+8) 1 0 0 0 0 1 (m>1) 2 pc+8 2 0 - 1 0 1 0 0 1 not ready ? pc+8 2 0 - 1 0 1 0 0 1 n pc+8 2 0 - 0 0 1 0 0 0 n+1 alu 2 1 cpdata 0 1 1 1 0 0 ? alu+? 2 1 cpdata 0 1 1 1 0 0 n+m alu+? 2 1 cpdata 0 1 1 1 0 0 n+m+1 alu+? 2 1 cpdata 0 0 1 1 1 1 pc+12 cycle address mas [1:0] nrw data nmreq seq nopc ncpi cpa cpb ready 1 pc+8 2 0 (pc+8) 1 1 0 0 0 0 2 pc+12 2 0 cpdata 1 0 1 1 1 1 3 pc+12 2 0 - 0 1 1 1 - - table 10-18: coprocessor register transfer (load from coprocessor) cycle address mas [1:0] nrw data nmreq seq nopc ncpi cpa cpb table 10-17: coprocessor data transfer instruction cycle operations (continued)
instruction cycle operations ARM7TDMI data sheet arm ddi 0029e 10-17 open access note this operation cannot occur in thumb state. 10.17coprocessor register transfer (store to coprocessor) as for the load from coprocessor, except that the last cycle is omitted. the cycle timings are shown in table 10-19: coprocessor register transfer (store to coprocessor) on page 10-17. note this operation cannot occur in thumb state. pc+12 not ready 1 pc+8 2 0 (pc+8) 1 0 0 0 0 1 2 pc+8 2 0 - 1 0 1 0 0 1 ? pc+8 2 0 - 1 0 1 0 0 1 n pc+8 2 0 - 1 1 1 0 0 0 n+1 pc+12 2 0 cpdata 1 0 1 1 1 1 n+2 pc+12 2 0 - 0 1 1 1 - - pc+12 cycle address mas [1:0] nrw data nmreq seq nopc ncpi cpa cpb ready 1 pc+8 2 0 (pc+8) 1 1 0 0 0 0 2 pc+12 2 1 rd 0 0 1 1 1 1 pc+12 not ready 1 pc+8 2 0 (pc+8) 1 0 0 0 0 1 2 pc+8 2 0 - 1 0 1 0 0 1 ? pc+8 2 0 - 1 0 1 0 0 1 n pc+8 2 0 - 1 1 1 0 0 0 n+1 pc+12 2 1 rd 0 0 1 1 1 1 pc+12 table 10-19: coprocessor register transfer (store to coprocessor) cycle address mas [1:0] nrw data nmreq seq nopc ncpi cpa cpb table 10-18: coprocessor register transfer (load from coprocessor)
instruction cycle operations ARM7TDMI data sheet arm ddi 0029e 10-18 open access 10.18unde?ned instructions and coprocessor absent when a coprocessor detects a coprocessor instruction which it cannot perform, and this must include all unde?ned instructions, it must not drive cpa or cpb low . these will remain high, causing the unde?ned instruction trap to be taken. cycle timings are shown in table 10-20: undefined instruction cycle operations . c represents the current mode-dependent value. t represents the current state-dependent value. note coprocessor instructions cannot occur in thumb state. 10.19unexecuted instructions any instruction whose condition code is not met will fail to execute. it will add one cycle to the execution time of the code segment in which it is embedded (see table 10-21: unexecuted instruction cycle operations ). cycle address mas [1:0] nrw data nmreq seq nopc ncpi cpa cpb ntrans mode tbit 1 pc+2l i 0 (pc+2l) 1 0 0 0 1 1 c old t 2 pc+2l i 0 - 0 0 0 1 1 1 c old t 3 xn 2 0 (xn) 0 1 0 1 1 1 1 00100 0 4 xn+4 2 0 (xn+4) 0 1 0 1 1 1 1 00100 0 xn+8 table 10-20: unde?ned instruction cycle operations cycle address mas[1:0] nrw data nmreq seq nopc 1 pc+2l i 0 (pc+2l) 0 1 0 pc+3l table 10-21: unexecuted instruction cycle operations
instruction cycle operations ARM7TDMI data sheet arm ddi 0029e 10-19 open access 10.20instruction speed summary due to the pipelined architecture of the cpu, instructions overlap considerably. in a typical cycle one instruction may be using the data path while the next is being decoded and the one after that is being fetched. for this reason the following table presents the incremental number of cycles required by an instruction, rather than the total number of cycles for which the instruction uses part of the processor. elapsed time (in cycles) for a routine may be calculated from these ?gures which are shown in table 10-22: arm instruction speed summary on page 10-20 . these ?gures assume that the instruction is actually executed. unexecuted instructions take one cycle. n is the number of words transferred m is 1 if bits [32:8] of the multiplier operand are all zero or one. 2 if bits[32:16] of the multiplier operand are all zero or one. 3if bits[31:24] of the multiplier operand are all zero or all one. 4 otherwise. b is the number of cycles spent in the coprocessor busy-wait loop. if the condition is not met all the instructions take one s-cycle. the cycle types n, s, i, and c are de?ned in chapter 6, memory interface.
instruction cycle operations ARM7TDMI data sheet arm ddi 0029e 10-20 open access instruction cycle count additional data processing 1s + 1i for shift(rs) + 1s + 1n if r15 written msr, mrs 1s ldr 1s+1n+1i + 1s + 1n if r15 loaded str 2n ldm ns+1n+1i + 1s + 1n if r15 loaded stm (n-1)s+2n swp 1s+2n+1i b,bl 2s+1n swi, trap 2s+1n mul 1s+mi mla 1s+(m+1)i mull 1s+(m+1)i mlal 1s+(m+2)i cdp 1s+bi ldc,stc (n-1)s+2n+bi mcr 1n+bi+1c mrc 1s+(b+1)i+1c table 10-22: arm instruction speed summary
ARM7TDMI data sheet arm ddi 0029e 11-1 11 1 open access dc parameters 11.1 absolute maximum ratings 11-2 11.2 dc operating conditions 11-2 11
dc parameters ARM7TDMI data sheet arm ddi 0029e 11-2 open access 11.1 absolute maximum ratings note these are stress ratings only. exceeding the absolute maximum ratings may permanently damage the device. operating the device at absolute maximum ratings for extended periods may affect device reliability. 11.2 dc operating conditions notes 1 voltages measured with respect to vss. 2 ic cmos-level inputs. symbol parameter min max units vdd supply voltage vss-0.3 vss+7.0 v vin input voltage applied to any pin vss-0.3 vdd+0.3 v ts storage temperature -50 150 deg c table 11-1: ARM7TDMI dc maximum ratings symbol parameter min typ max units notes vdd supply voltage 2.7 3.0 3.6 v vihc ic input high voltage .8xvdd vdd v 1,2 vilc ic input low voltage 0.0 .2xvdd v 1,2 ta ambient operating temperature -40 85 ?c table 11-2: ARM7TDMI dc operating conditions
ARM7TDMI data sheet arm ddi 0029e 12-1 11 1 open access ac parameters the timing parameters given here are preliminary data and subject to change. 12.1 introduction 12-2 12.2 notes on ac parameters 12-11 12
ac parameters ARM7TDMI data sheet arm ddi 0029e 12-2 open access 12.1 introduction the ac timing diagrams presented in this section assume that the outputs of the ARM7TDMI have been loaded with the capacitive loads shown in the test load column of table 12-1: ac test loads . these loads have been chosen as typical of the type of system in which ARM7TDMI might be employed. the output drivers of the ARM7TDMI are cmos inverters which exhibit a propagation delay that increases linearly with the increase in load capacitance. an output derating ?gure is given for each output driver, showing the approximate rate of increase of output time with increasing load capacitance. output signal test load (pf) output derating (ns/pf) d[31:0] tbd tbd a[31:0] tbd tbd lock tbd tbd ncpi tbd tbd nmreq tbd tbd seq tbd tbd nrw tbd tbd mas[1:0] tbd tbd nopc tbd tbd ntrans tbd tbd tdo tbd tbd table 12-1: ac test loads
ac parameters ARM7TDMI data sheet arm ddi 0029e 12-3 open access figure 12-1: general timings note nwait, ape, ale and abe are all high during the cycle shown. tcdel is the delay (on either edge) from mclk changing to eclk changing. mclk eclk a[31:0] nrw mas[1:0], lock nm[4:0], ntrans tbit nopc nmreq, seq nexec t cdel t cdel t ah t addr t rwh t rwd t blh t bld t mdh t mdd t opch t opcd t msh t msd t exh t exd
ac parameters ARM7TDMI data sheet arm ddi 0029e 12-4 open access figure 12-2: ale address control note t ald is the time by which ale must be driven low in order to latch the current address in phase 2. if ale is driven low after tald, then a new address will be latched. figure 12-3: ape address control figure 12-4: abe address control mclk ale a[31:0], nrw, lock, nopc, ntrans, mas[1:0] t ald t ale mclk ape a[31:0], nrw, lock, nopc, ntrans, mas[1:0] t aph t aps t ape mclk abe a[31:0], nrw, lock, nopc, ntrans, mas[1:0] t abz t abe t addr
ac parameters ARM7TDMI data sheet arm ddi 0029e 12-5 open access figure 12-5: bidirectional data write cycle note dbe is high and nenin is low during the cycle shown. figure 12-6: bidirectional data read cycle note dbe is high and nenin is low during the cycle shown. mclk nenout d[31:0] t nen t nenh t dout t doh mclk nenout d[31:0] bl[3:0] t nen t dis t dih t bylh t byls
ac parameters ARM7TDMI data sheet arm ddi 0029e 12-6 open access figure 12-7: data bus control note the cycle shown is a data write cycle since nenout was driven low during phase 1. here, dbe has ?rst been used to modify the behaviour of the data bus, and then nenin . figure 12-8: output 3-state time mclk nenout dbe d[31:0] nenin t dbnen t dbnen t dbz t dbe t dout t doh t dbz t dbe mclk tbe a[31:0], d[31:0], nrw, lock, nopc, ntrans mas[1:0] t tbz t tbe
ac parameters ARM7TDMI data sheet arm ddi 0029e 12-7 open access figure 12-9: unidirectional data write cycle figure 12-10: unidirectional data read cycle figure 12-11: configuration pin timing mclk nenout dout[31:0] t nen t dohu t doutu mclk nenout din[31:0] bl[3:0] t nen t disu t dihu t bylh t byls mclk bigend isync t cth t cts t cts t cth
ac parameters ARM7TDMI data sheet arm ddi 0029e 12-8 open access figure 12-12: coprocessor timing note normally, nmreq and seq become valid tmsd after the falling edge of mclk . in this cycle the arm has been busy-waiting, waiting for a coprocessor to complete the instruction. if cpa and cpb change during phase 1, the timing of nmreq and seq will depend on t cpms. most systems should be able to generate cpa and cpb during the previous phase 2, and so the timing of nmreq and seq will always be tmsd. figure 12-13: exception timing note tis/trs guarantee recognition of the interrupt (or reset) source by the corresponding clock edge. t im/t rm guarantee non-recognition by that clock edge. these inputs may be applied fully asynchronously where the exact cycle of recognition is unimportant. mclk ncpi cpa, cpb nmreq, seq t cpi t cpih t cps t cph t cpms mclk abort nfiq, nirq nreset t abts t abth t is t im t rs t rm
ac parameters ARM7TDMI data sheet arm ddi 0029e 12-9 open access figure 12-14: debug timing figure 12-15: breakpoint timing note breakpt changing in the low phase of mclk to signal a watchpointed store can affect ncpi , nexec , nmreq , and seq in the low phase of mclk . figure 12-16: tck-eclk relationship mclk dbgack breakpt dbgrq extern[1:0] t dbgh t dbgd t brks t brkh t rqs t rqh t exts t exth mclk breakpt ncpi, nexec nmreq, seq t bcems tck eclk t ctdel t ctdel
ac parameters ARM7TDMI data sheet arm ddi 0029e 12-10 open access figure 12-17: mclk timing note the arm core is not clocked by the high phase of mclk enveloped by nwait . thus, during the cycles shown, nmreq and seq change once, during the ?rst low phase of mclk , and a[31:0] change once, during the second high phase of mclk . for reference, ph2 is shown. this is the internal clock from which the core times all its activity . this signal is included to show how the high phase of the external mclk has been removed from the internal core clock. mclk nwait eclk nmreq/ seq a[31:0] t mckl t mckh t ws t wh t msd t addr
ac parameters ARM7TDMI data sheet arm ddi 0029e 12-11 open access 12.2 notes on ac parameters all ?gures are provisional and assume a process which achieves 33mhz mclk maximum operating frequency. output load is 0.45pf. symbol parameter min max tmckl mclk low time 15.1 tmckh mclk high time 15.1 tws nwait setup to mclkr 2.3 twh nwait hold from ckf 1.1 tale address latch open 7.5 taleh address latch hold time 2.1 tald address latch time 3.4 taddr mclkr to address valid 14.0 tah address hold time from mclkr 2.4 tabe address bus enable time 6.2 tabz address bus disable time 5.3 taph ape hold time from mclkr 4.9 taps ape set up time to mclkf 0 tape mclkf to address valid 8.9 tapeh address group hold time from mclkf 2.1 tdout mclkf to d[31:0] valid 14.9 tdoh d[31:0] out hold from mclkf 2.2 tdis d[31:0] in setup time to mclkf 0.9 tdih d[31:0] in hold time from mclkf 2.6 tdoutu mclkf to dout[31:0] valid 17 tdohu dout[31:0] hold time from mclkf 2.4 tdisu din[31:0] set up time to mclkf 1.8 tdihu din[hold time to mclkf 1.7 tnen mclkf to nenout valid 11.2 tnenh nenout hold time from mclkf 2.4 table 12-2: provisional ac parameters (units of ns)
ac parameters ARM7TDMI data sheet arm ddi 0029e 12-12 open access tbylh bl[3:0] hold time from mclkf 0.7 tbyls bl[3:0] set up to from mclkr 0.1 tdbe data bus enable time from dber 15.2 tdbz data bus disable time from dbef 14.5 tdbnen dbe to nenout valid 5.5 ttbz address and data bus disable time from tbef 5.5 ttbe address and data bus enable time from tber 7.8 trwd mclkr to nrw valid 14.0 trwh nrw hold time from mclkr 2.4 tmsd mclkf to nmreq & seq valid 17.9 tmsh nmreq & seq hold time from mclkf 2.4 tbld mclkr to mas[1:0] & lock 18.9 tblh mas[1:0] & lock hold from mclkr 2.4 tmdd mclkr to ntrans, nm[4:0], and tbit valid 19.5 tmdh ntrans & nm[4:0] hold time from mclkr 2.4 topcd mclkr to nopc valid 10.6 topch nopc hold time from mclkr 2.4 tcps cpa, cpb setup to mclkr 5.1 tcph cpa,cpb hold time from mclkr 0.2 tcpms cpa, cpb to nmreq, seq 9.9 tcpi mclkf to ncpi valid 17.9 tcpih ncpi hold time from mclkf 2.4 tcts config setup time 2.1 tcth config hold time 3.4 tabts abort set up time to mclkf 0.6 tabth abort hold time from mclkf 1.5 tis asynchronous interrupt set up time to mclkf for guaranteed recognition (isync=0) 0.1 tim asynchronous interrupt guaranteed non-recognition time (isync=0) 3.1 symbol parameter min max table 12-2: provisional ac parameters (units of ns) (continued)
ac parameters ARM7TDMI data sheet arm ddi 0029e 12-13 open access tsis synchronous nfiq, nirq setup to mclkf (isync=1) 9.0 tsih synchronous nfiq, nirq hold from mclkf (isync=1) 1.1 trs reset setup time to mclkr for guaranteed recognition 1.9 trm reset guaranteed non-recognition time 3.7 texd mclkf to nexec valid 17.9 texh nexec hold time from mclkf 2.4 tbrks set up time of breakpt to mclkr 14.6 tbrkh hold time of breakpt from mclkr 2.5 tbcems breakpt to ncpi, nexec, nmreq, seq delay 14.3 tdbgd mclkr to dbgack valid 15.2 tdbgh dgback hold time from mclkr 2.4 trqs dbgrq set up time to mclkr for guaranteed recognition 2.6 trqh dbgrq guaranteed non-recognition time 1.0 tcdel mclk to eclk delay 2.9 tctdel tck to eclk delay 10.4 texts extern[1:0] set up time to mclkf 0 texth extern[1:0] hold time from mclkf 3.8 trg mclkf to rangeout0, rangeout1 valid 15.2 trgh rangeout0, rangeout1 hold time from mclkf 2.4 tdbgrq dbgrq to dbgrqi valid 2.9 trstd nresetf to d[], dbgack, ncpi, nenout, nexec, nmreq, seq valid 13.7 tcommd mclkr to commrx, commtx valid 9.3 ttrstd ntrstf to every output valid 13.7 trstl nreset low for guaranteed reset 2 mclk cycles symbol parameter min max table 12-2: provisional ac parameters (units of ns) (continued)
ac parameters ARM7TDMI data sheet arm ddi 0029e 12-14 open access
ARM7TDMI data sheet arm ddi 0029e index-i 11 1 index index open access a abort data 3-12 during block data transfer 4-44 prefetch 3-12 abort mode 3-4 adc arm instruction 4-11 thumb instruction 5-3 , 5-11 add arm instruction 4-11 thumb instruction 5-3 , 5-7 , 5-9 , 5-28 , 5-30 with hi register operand 5-13 address bus configuring 6-4 advantages of thumb 1-3 and arm instruction 4-11 thumb instruction 5-3 , 5-11 arm state. see operating state asr arm instruction 4-13 thumb instruction 5-3 , 5-5 , 5-11 b b (branch) arm instruction 4-8 thumb instruction conditional 5-3 , 5-36 , 5-37 unconditional 5-3 , 5-39 bic arm instruction 4-11 thumb instruction 5-3 , 5-12 big endian. see memory format bl (branch and link) arm instruction 4-8 thumb instruction 5-3 , 5-41 branch instruction 10-2 branching in arm state 4-8 in thumb state 5-3 , 5-36 , 5-37 , 5-39 to subroutine in arm state 4-8 in thumb state 5-3 , 5-41 breakpoints entering debug state from 8-23 with prefetch abort 8-25 bx (branch and exchange) arm instruction 4-6 thumb instruction 5-3 , 5-14 with hi register operand 5-14
ARM7TDMI ARM7TDMI data sheet arm ddi 0029e index-ii open access bypass public instruction 8-11 bypass register 8-12 byte (data type) 3-3 loading and storing 4-29 , 5-3 , 5-4 , 5-19 , 5-20 , 5-23 c cdp arm instruction 4-51 clamp public instruction 8-11 clampz public instruction 8-12 clock switching debug state 8-18 test state 8-19 cmn arm instruction 4-11 , 4-16 thumb instruction 5-3 , 5-12 cmp arm instruction 4-11 , 4-16 thumb instruction 5-3 , 5-9 , 5-12 with hi register operand 5-14 concepts of thumb 1-2 condition code flags 3-8 condition codes summary of 4-5 conditional execution in arm state 4-5 coprocessor data operations 4-51 data transfer 4-53 action on data abort 4-54 passing instructions to 7-2 pipeline following 7-3 register transfer 4-57 coprocessor interface 7-2 C 7-4 core state determining 8-19 cp# (coprocessor number) field 7-2 cpsr (current processor status register) 3-8 format of 3-8 reading 4-18 writing 4-18 d data bus external 6-18 internal 6-13 data operations 10-4 data transfer block in arm state 4-40 in thumb state 5-3 , 5-4 , 5-34 single in arm state 4-28 in thumb state 5-3 , 5-4 , 5-16 , 5-17 , 5-18 , 5-19 , 5-20 , 5-21 , 5-22 , 5-23 , 5-24 , 5-26 specifying size of 6-9 data types 3-3 debug request entering debug state via 8-24 debug state exiting from 8-21 debug systems 8-2 , 8-3 device identification code register 8-13 e eor arm instruction 4-11 thumb instruction 5-3 , 5-11 exception entering 3-10 leaving 3-10 priorities 3-14 returning to thumb state from 3-10 vectors 3-13 extest 8-10 public instruction 8-10 f fiq mode 3-4 definition of 3-11 see also interrupts
index ARM7TDMI data sheet arm ddi 0029e index-iii open access h halfword loading and storing 4-34 halfword (data type) 3-3 , 4-34 loading and storing 5-3 , 5-4 , 5-20 , 5-21 , 5-24 hi register accessing from thumb state 3-7 description 3-7 operations example code 5-15 operations on 5-13 highz public instruction 8-11 i icebreaker breakpoints 9-6 coupling with watchpoints 9-11 hardware 9-7 software 9-7 breakpt signal 9-2 communications 9-14 control registers 9-5 debug control register 9-9 debug status register 9-10 disabling 9-13 tap controller 9-2 , 9-4 watchpoint registers 9-3 C 9-4 watchpoints coupling with breakpoints 9-11 idcode public instruction 8-10 instruction register 8-13 intest public instruction 8-10 irq mode 3-4 definition of 3-12 see also interrupts j jtag state machine 8-8 l ldc arm instruction 4-53 ldm action on data abort 4-44 arm instruction 4-40 ldmia thumb instruction 5-3 , 5-34 ldr arm instruction 4-28 thumb instruction 5-3 , 5-16 , 5-17 , 5-19 , 5-22 , 5-26 ldrb thumb instruction 5-3 , 5-19 , 5-23 ldrh thumb instruction 5-3 , 5-20 , 5-21 , 5-24 ldsb thumb instruction 5-3 , 5-20 ldsh thumb instruction 5-3 little endian. see memory format lo registers 3-7 lock output 4-47 lsl arm instruction 4-12 , 4-13 thumb instruction 5-3 , 5-5 , 5-11 lsr arm instruction 4-13 thumb instruction 5-3 , 5-5 m memory locking 6-12 protecting 6-12 memory access times 6-12 memory cycle timing 6-3 memory cycle types 6-2 memory format big endian description 3-3 single data transfer in 4-30
ARM7TDMI ARM7TDMI data sheet arm ddi 0029e index-iv open access little endian description 3-3 single data transfer in 4-29 memory transfer cycle non-sequential 6-12 memory transfer cycle types 6-2 mla arm instruction 4-23 mlal arm instruction 4-23 , 4-25 mov arm instruction 4-11 thumb instruction 5-3 , 5-9 with hi register operand 5-14 mrs arm instruction 4-18 msr arm instruction 4-18 mul arm instruction 4-23 thumb instruction 5-3 , 5-12 mull arm instruction 4-23 , 4-25 mvn arm instruction 4-11 thumb instruction 5-3 , 5-12 n neg thumb instruction 5-4 , 5-11 o operating mode reading 3-9 setting 3-9 operating state arm 3-2 reading 3-8 switching 3-2 to arm 3-2 , 5-14 , 5-15 to thumb 3-2 , 4-7 thumb 3-2 orr arm instruction 4-11 thumb instruction 5-4 , 5-12 p pipeline 7-3 pop thumb instruction 5-4 , 5-32 privileged instruction 7-3 public instructions 8-9 push thumb instruction 5-32 r registers arm 3-4 thumb 3-6 reset action of processor on 3-15 return address calculations 8-25 ror arm instruction 4-14 thumb instruction 5-4 , 5-11 rotate operations 4-14 , 4-15 rrx arm instruction 4-14 rsb arm instruction 4-11 rsc arm instruction 4-11 s sample/preload public instruction 8-12 sbc arm instruction 4-11 thumb instruction 5-11 scan chain select register 8-13 scan chains 8-14 scan limitations 8-6 scan_n public instruction 8-10 shift operations 4-12 , 4-15 , 5-5 , 5-11 software interrupt 3-13 , 4-49 , 5-4 spsr (saved processor status register) 3-8 format of 3-8 reading 4-18 writing 4-18
index ARM7TDMI data sheet arm ddi 0029e index-v open access stack operations 5-32 stc arm instruction 4-53 stm arm instruction 4-40 stmia thumb instruction 5-4 , 5-34 str arm instruction 4-28 thumb instruction 5-4 , 5-18 , 5-22 , 5-26 strb thumb instruction 5-4 , 5-19 , 5-23 strh thumb instruction 5-4 , 5-20 , 5-24 sub arm instruction 4-11 thumb instruction 5-4 , 5-7 , 5-9 supervisor mode 3-4 swi 3-13 arm instruction 4-49 thumb instruction 5-4 , 5-38 swp arm instruction 4-47 system mode 3-4 system speed access during debug state 8-25 system state determining 8-21 t t bit (in cpsr) 3-8 teq arm instruction 4-11 , 4-16 thumb branch with link operation 10-3 thumb state. see operating state tst arm instruction 4-11 , 4-16 thumb instruction 5-4 , 5-11 u undefined instruction 7-4 undefined instruction trap 3-13 , 4-2 undefined mode 3-4 user mode 3-4 v virtual memory systems 3-12 w watchpoints entering debug state from 8-23 word (data type) address alignment 3-3 loading and storing 4-29 , 5-3 , 5-4 , 5-16 , 5-18 , 5-19 , 5-22 , 5-26
ARM7TDMI ARM7TDMI data sheet arm ddi 0029e index-vi open access


▲Up To Search▲   

 
Price & Availability of ARM7TDMI

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X