home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / demos / baah / Articles / SpeedWar / Instr_Set < prev    next >
Encoding:
Text File  |  1996-07-12  |  47.6 KB  |  1,519 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.                     ARM Instruction Formats and Timings
  9.  
  10.  
  11.  
  12. Last revised: 15th November 1995
  13.  
  14. The  information  included here is provided in good faith, but no responsi-
  15. bility can be accepted for any damage or loss caused from the use of infor-
  16. mation  contained  within this document even if the author has been advised
  17. of the possibility of such loss.
  18.  
  19. This is not an official document from ARM Ltd; in fact other than a  couple
  20. of  nice people from ARM limited pointing out some of the corrections, they
  21. have no connection with this document at all. They do not guarantee to have
  22. found  all  the  mistakes  in  this, so don't blame them when you find some
  23. more.
  24.  
  25. Corrections/amendments for this document would be most welcome. They should
  26. be reported to Robin Watts at the address below.
  27.  
  28. Throughout  this  document,  a  `word' refers to 32 bits (thats 4 bytes) of
  29. memory. If you don't like this, tough.
  30.  
  31. This document is available in several forms.  An index to them can be found
  32. it   http://www.comlab.ox.ac.uk/oucl/users/robin.watts/ARMinstrs/   on  the
  33. World  Wide  Web,  or  via  anonymous   FTP   to   ftp.comlab.ox.ac.uk   in
  34. /tmp/Robin.Watts/ARMinstrs/README.
  35.  
  36.  
  37. 1.  Processor Modes
  38.  
  39. ARM  processors  have  a  user  mode  and a number of privileged supervisor
  40. modes.  These are used as follows:
  41.  
  42.      IRQ    Entered when an Interrupt Request (IRQ) is triggered.
  43.  
  44.      FIQ    Entered when a Fast Interrupt Request (FIQ) is triggered.
  45.  
  46.      SVC    Entered when a Software Interrupt (SWI) is executed.
  47.  
  48.      Undef  Entered when an Undefined instruction is executed  (Not  ARM  2
  49.             and 3, where SVC mode is entered).
  50.  
  51.      Abt    Entered  when  a memory access attempt is aborted by the memory
  52.             manager (e.g. MEMC or MMU), usually because an attempt is  made
  53.             to  access  non-existent  memory  or  to  access memory from an
  54.             insufficiently privileged mode (Not ARM 2 and 3, where SVC mode
  55.             is entered).
  56.  
  57. In each case the appropriate hardware vector is also called.
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.                              November 15, 1995
  65.  
  66.  
  67.  
  68.  
  69.  
  70.                                    - 2 -
  71.  
  72.  
  73. 2.  Registers
  74.  
  75. The ARM 2 and 3 have 27 32 bit processor registers, 16 of which are visible
  76. at any given time (which sixteen varies according to the  processor  mode).
  77. These are referred to as R0-R15.
  78.  
  79. The  ARM  6 and later have 31 32 bit processor registers, again 16 of which
  80. are visible at any given time.
  81.  
  82. R15 has special significance. On the ARM 2 and 3, 24 bits are used  as  the
  83. program  counter, and the remaining 8 bits are used to hold processor mode,
  84. status flags and interrupt modes. R15 is therefore often referred to as PC.
  85.  
  86.                    R15 = PC = NZCVIFpp pppppppp pppppppp ppppMM
  87.  
  88. Bits  0-1  and 26-31 are known as the PSR (processor status register). Bits
  89. 2-25 give the address (in words) of the instruction currently being fetched
  90. into  the  execution  pipeline (see below). Thus instructions are only ever
  91. executed from word aligned addresses.
  92.  
  93.                M   Current processor mode
  94.  
  95.                0   User Mode
  96.                1   Fast interrupt processing mode (FIQ mode)
  97.                2   Interrupt processing mode (IRQ mode)
  98.                3   Supervisor mode (SVC mode)
  99.  
  100.  
  101.                    Name   Meaning
  102.  
  103.                    N      Negative flag
  104.                    Z      Zero flag
  105.                    C      Carry flag
  106.                    V      oVerflow flag
  107.                    I      Interrupt request disable
  108.                    F      Fast interrupt request disable
  109.  
  110.  
  111. R14, R14_FIQ, R14_IRQ, and R14_SVC are sometimes known as `link'  registers
  112. due to their behaviour during the branch with link instructions.
  113.  
  114. The  ARM  6  and later processor cores support a 32 bit address space. Such
  115. processors can operate in both 26 bit and 32 bit PC modes.  In  26  bit  PC
  116. mode, R15 acts as on previous processors, and hence code can only be run in
  117. the lowest 64MBytes of the address space. In 32 bit PC mode, all 32 bits of
  118. R15  are used as the program counter. Separate status registers are used to
  119. store the processor mode and status flags. These are defined as follows:
  120.  
  121.                         NZCVxxxx xxxxxxxx xxxxxxxx IFxMMMMM
  122.  
  123. Note that the bottom two bits of R15 are always zero  in  32-bit  modes  --
  124. i.e.  you  can  still  only  get word-aligned instructions. Any attempts to
  125. write non-zeros to these bits will be ignored.
  126.  
  127.  
  128.  
  129.  
  130.                              November 15, 1995
  131.  
  132.  
  133.  
  134.  
  135.  
  136.                                    - 3 -
  137.  
  138.  
  139. The following modes are currently defined:
  140.  
  141.                      M      Name    Meaning
  142.  
  143.                    00000   usr_26   26 bit PC User Mode
  144.                    00001   fiq_26   26 bit PC FIQ Mode
  145.                    00010   irq_26   26 bit PC IRQ Mode
  146.                    00011   svc_26   26 bit PC SVC Mode
  147.  
  148.                    10000   usr_32   32 bit PC User Mode
  149.                    10001   fiq_32   32 bit PC FIQ Mode
  150.                    10010   irq_32   32 bit PC IRQ Mode
  151.                    10011   svc_32   32 bit PC SVC Mode
  152.                    10111   abt_32   32 bit PC Abt Mode
  153.                    11011   und_32   32 bit PC Und Mode
  154.  
  155.  
  156. Extrapolating from the above table, it might be expected that the following
  157. two modes are also defined:
  158.  
  159.                       M      Name    Meaning
  160.  
  161.                     00111   abt_26   26 bit PC Abt Mode
  162.                     01011   und_26   26 bit PC Und Mode
  163.  
  164. These are in fact undefined (and if you do write 00111 or 01011 to the mode
  165. bits, the resulting chip state won't be what you might expect  --  i.e.  it
  166. won't  be a 26-bit privileged mode with the appropriate R13 and R14 swapped
  167. in).
  168.  
  169. The following table shows which registers are available in which  processor
  170. modes:
  171.  
  172.    Mode Registers available
  173.  
  174.    USR  R0 -- R14 R15
  175.    FIQ  R0     --     R7  R8_FIQ  -- R14_FIQ R15
  176.    IRQ  R0     --     R12 R13_IRQ -- R14_IRQ R15
  177.    SVC  R0     --     R12 R13_SVC -- R14_SVC R15
  178.    ABT  R0     --     R12 R13_ABT -- R14_ABT R15 (ARM 6 and later only)
  179.    UND  R0     --     R12 R13_UND -- R14_UND R15 (ARM 6 and later only)
  180.  
  181.  
  182. There are six status registers on the ARM6 and later processors. One is the
  183. current processor status register (CPSR) and holds  information  about  the
  184. current state of the processor. The other five are the saved processor sta-
  185. tus registers (SPSRs): there is one of these for each privileged  mode,  to
  186. hold  information  about  the  state the processor must be returned to when
  187. exception handling in that mode is complete.
  188.  
  189. These registers are set and read using the MSR and MRS instructions respec-
  190. tively.
  191.  
  192.  
  193.  
  194.  
  195.  
  196.                              November 15, 1995
  197.  
  198.  
  199.  
  200.  
  201.  
  202.                                    - 4 -
  203.  
  204.  
  205. 3.  Pipeline
  206.  
  207. Rather  than  being a microcoded processor, the ARM is (in keeping with its
  208. RISCness) entirely hardwired.
  209.  
  210. To speed execution the ARM 2 and 3 have 3 stage pipelines. The first  stage
  211. holds  the  instruction  being  fetched  from memory. The second starts the
  212. decoding, and the third is where it is actually executed. Due to this,  the
  213. program  counter  is  always  2 instructions beyond the currently executing
  214. instruction. (This must be taken account of when  calculating  offsets  for
  215. branch instructions).
  216.  
  217. Because of this pipeline, 2 instruction cycles are lost on a branch (as the
  218. pipeline must refill). It is therefore often preferable to make use of con-
  219. ditional instructions to avoid wasting cycles. For example:
  220.  
  221.  
  222.         ...
  223.         CMP R0,#0
  224.         BEQ over
  225.         MOV R1,#1
  226.         MOV R2,#2
  227. over
  228.         ...
  229.  
  230.  
  231. can be more efficiently written as:
  232.  
  233.  
  234.         ...
  235.         CMP R0,#0
  236.         MOVNE R1,#1
  237.         MOVNE R2,#2
  238.         ...
  239.  
  240.  
  241.  
  242. 4.  Timings
  243.  
  244. ARM instructions are timed in a mixture of S, N, I and C cycles.
  245.  
  246. An  S-cycle  is a cycle in which the ARM accesses a sequential memory loca-
  247. tion.
  248.  
  249. An N-cycle is a cycle in which the ARM  accesses  a  non-sequential  memory
  250. location.
  251.  
  252. An I-cycle is a cycle in which the ARM doesn't try to access a memory loca-
  253. tion or to transfer a word to or from a coprocessor.
  254.  
  255. A C-cycle is a cycle in which a word is transferred between the ARM  and  a
  256. coprocessor  on  either the data bus (for uncached ARMs) or the coprocessor
  257. bus (for cached ARMs).
  258.  
  259.  
  260.  
  261.  
  262.                              November 15, 1995
  263.  
  264.  
  265.  
  266.  
  267.  
  268.                                    - 5 -
  269.  
  270.  
  271. The different types of cycle must all be at least  as  long  as  the  ARM's
  272. clock  rating. The memory system can stretch them: with a typical DRAM sys-
  273. tem, this results in:
  274.  
  275.      o    N-cycles being twice  the  minimum  length  (essentially  because
  276.           DRAMs  require a longer access protocol when the memory access is
  277.           non-sequential).
  278.  
  279.      o    S-cycles usually being the minimum length, but occasionally being
  280.           stretched  to N-cycle length (when you've just moved sequentially
  281.           from the last word of one memory "row" to the first of  the  next
  282.           one[1]).
  283.  
  284.      o    I- and C-cycles always being the minimum length.
  285.  
  286. With a typical SRAM system, all four types of cycle are typically the mini-
  287. mum length.
  288.  
  289. On  the  8MHz  ARM2  used in the Acorn Archimedes A440/1, an S (sequential)
  290. cycle is 125ns and an N (non-sequential) cycle is 250ns. It should be noted
  291. that these timings are not attributes of the ARM, but of the memory system.
  292. E.g. an 8MHz ARM2 can be connected to a static RAM  system  which  gives  a
  293. 125ns  N  cycle.  The fact that the processor is rated at 8MHz simply means
  294. that it isn't guaranteed to work if you make any  of  the  types  of  cycle
  295. shorter than 125ns in length.
  296.  
  297. Cached  processors:  All  the  information  given  is in terms of the clock
  298. cycles seen by the ARM. These do not occur at a constant  rate:  the  cache
  299. control  logic  changes the source of the clock cycles presented to the ARM
  300. when cache misses occur.
  301.  
  302. Generally, a cached ARM has two clock inputs: the "fast clock" FCLK and the
  303. "memory clock" MCLK. When operating normally from cache, the ARM is clocked
  304. at FCLK speed and all types of cycle  are  the  minimum  length:  cache  is
  305. effectively  a  type  of  SRAM  from  this point of view. When a cache miss
  306. occurs, the ARM's clock is synchronised to MCLK, then the cache  line  fill
  307. takes  place  at  MCLK  speed  (taking either N+3S or N+7S depending on the
  308. length of cache lines in the processor involved), then the ARM's  clock  is
  309. resynchronised back to FCLK.
  310.  
  311. _________________________
  312.   [1] Memory  controllers  tend  to use this simple strategy: if an N-
  313. cycle is requested, treat the access as not being in the same row;  if
  314. an S-cycle is requested, treat the access as being in the same row un-
  315. less it is effectively the last word in the row (which can be detected
  316. quickly). The net result is that some S-cycles will last the same time
  317. as an N-cycle; if I remember correctly, on an Archimedes these are  S-
  318. cycle  accesses  to an address which is divisible by 16. The practical
  319. consequences of this for Archimedes code are: (a) that about 1 in 4 S-
  320. cycles  becomes  an N-cycle, since for this purpose, all addresses are
  321. word addresses and so divisible by 4;  (b)  that  it  is  occasionally
  322. worth taking care to align code carefully to avoid this effect and get
  323. some extra performance.)
  324.  
  325.  
  326.  
  327.  
  328.                              November 15, 1995
  329.  
  330.  
  331.  
  332.  
  333.  
  334.                                    - 6 -
  335.  
  336.  
  337. While the memory access is taking place, the ARM is being clocked: however,
  338. an input called NWAIT is used to cause the ARM cycles involved  not  to  do
  339. anything  until the correct word arrives from memory, and usually not to do
  340. anything while the remaining words arrive (to avoid getting further  memory
  341. requests  while  the  cache  is still busy with the cache line refill). The
  342. situation is also complicated by the fact that the cached ARM can  be  con-
  343. figured  either  for FCLK and MCLK to be synchronous to each other (so FCLK
  344. is an exact multiple of MCLK, and every MCLK clock  cycle  starts  at  just
  345. about  the  same time as an FCLK cycle) or asynchronous (in which case FCLK
  346. and MCLK cycles can have any relationship to each other).
  347.  
  348. All in all, the situation is therefore quite complicated. An  approximation
  349. to  the behaviour is that when a cache line miss occurs, the cycle involved
  350. takes the cache line refill time (i.e. N+3S or N+7S) in MCLK  cycles,  with
  351. N-cycles and S-cycles probably being stretched as described above for DRAM,
  352. plus a few more cycles to allow for the resynchronisation periods. For  any
  353. more  details,  you  really  need  to  get  a  datasheet  for the processor
  354. involved.
  355.  
  356.  
  357. 5.  Instructions
  358.  
  359. Each ARM instruction is 32 bits wide, and  are  explained  in  more  detail
  360. below.  For  each  instruction class we give the instruction bitmap, and an
  361. example of the syntax used by a typical assembler.
  362.  
  363. It should of course be noted that the mnemonic syntax is not fixed; it is a
  364. property of the assembler, not the ARM machine code.
  365.  
  366.  
  367. 5.1.  Condition Code
  368.  
  369. The  top  nibble  of every instruction is a condition code, so every single
  370. ARM instruction can be run conditionally.
  371.  
  372.  
  373.                                     Cond
  374. Instruction Bitmap                   No  Cond Code            Executes if
  375.  
  376. 0000xxxx xxxxxxxx xxxxxxxx xxxxxxxx  0   EQ(Equal)            Z
  377. 0001xxxx xxxxxxxx xxxxxxxx xxxxxxxx  1   NE(Not Equal)        ~Z
  378. 0010xxxx xxxxxxxx xxxxxxxx xxxxxxxx  2   CS(Carry Set)        C
  379. 0011xxxx xxxxxxxx xxxxxxxx xxxxxxxx  3   CC(Carry Clear)      ~C
  380.  
  381. 0100xxxx xxxxxxxx xxxxxxxx xxxxxxxx  4   MI(MInus)            N
  382. 0101xxxx xxxxxxxx xxxxxxxx xxxxxxxx  5   PL(PLus)             ~N
  383. 0110xxxx xxxxxxxx xxxxxxxx xxxxxxxx  6   VS(oVerflow Set)     V
  384. 0111xxxx xxxxxxxx xxxxxxxx xxxxxxxx  7   VC(oVerflow Clear)   ~V
  385.  
  386. 1000xxxx xxxxxxxx xxxxxxxx xxxxxxxx  8   HI(HIgher)           C and ~Z
  387. 1001xxxx xxxxxxxx xxxxxxxx xxxxxxxx  9   LS(Lower or Same)    ~C or Z
  388. 1010xxxx xxxxxxxx xxxxxxxx xxxxxxxx  A   GE(Greater or equal) N = V
  389. 1011xxxx xxxxxxxx xxxxxxxx xxxxxxxx  B   LT(Less Than)        N = ~V
  390.  
  391.  
  392.  
  393.  
  394.                              November 15, 1995
  395.  
  396.  
  397.  
  398.  
  399.  
  400.                                    - 7 -
  401.  
  402.  
  403.  
  404. 1100xxxx xxxxxxxx xxxxxxxx xxxxxxxx  C   GT(Greater Than)     (N = V) and ~Z
  405. 1101xxxx xxxxxxxx xxxxxxxx xxxxxxxx  D   LE(Less or equal)    (N = ~V) or Z
  406. 1110xxxx xxxxxxxx xxxxxxxx xxxxxxxx  E   AL(Always)           True
  407. 1111xxxx xxxxxxxx xxxxxxxx xxxxxxxx  F   NV(Never)            False
  408.  
  409.  
  410. In most assemblers, the condition code is inserted  immediately  after  the
  411. mnemonic stub; omitting a condition code defaults to AL being used.
  412.  
  413. HS  (Higher  or  Same) and LO (LOwer) can be used as synonyms for CS and CC
  414. (respectively) in some assemblers.
  415.  
  416. The conditions GT, GE, LT, LE refer to signed comparisons whereas  HS,  HI,
  417. LS, LO refer to unsigned.
  418.  
  419. EORing a condition code with 1 gives the opposite condition code.
  420.  
  421. NB:  ARM  have  deprecated  the use of the NV condition code -- you are now
  422. supposed to use MOV R0,R0 as a noop rather than MOVNV R0,R0 as  was  previ-
  423. ously  recommended. Future processors may have the NV condition code reused
  424. to do other things.
  425.  
  426. Instructions with false conditions execute in 1S cycle, and no time penalty
  427. is incurred by making an instruction conditional.
  428.  
  429.  
  430. 5.2.  Data Processing Instructions
  431.  
  432.  
  433. xxxx000a aaaSnnnn ddddcccc ctttmmmm  Register form
  434. xxxx001a aaaSnnnn ddddrrrr bbbbbbbb  Immediate form
  435.  
  436.  
  437. Typical Assembler Syntax:
  438.  
  439.  
  440.         MOV    Rd,#0
  441.         ADDEQS Rd,Rn,Rm,ASL Rc
  442.         ANDEQ  Rd,Rn,Rm
  443.         TEQP   Pn,#&80000000
  444.         CMP    Rn,Rm
  445.  
  446.  
  447. Combine  contents of Rn with Op2, under operation a, placing the results in
  448. Rd.
  449.  
  450. If the register form is used, then Op2 is set to  be  the  contents  of  Rm
  451. shifted according to t as below.  If the immediate form is used, then Op2 =
  452. #b, ROR #2r.
  453.  
  454.        t    Assembler               Interpretation
  455.  
  456.  
  457.  
  458.  
  459.  
  460.                              November 15, 1995
  461.  
  462.  
  463.  
  464.  
  465.  
  466.                                    - 8 -
  467.  
  468.  
  469.       000   LSL #c                  Logical Shift Left
  470.       001   LSL Rc                  Logical Shift Left
  471.       010   LSR #c    for c != 0    Logical Shift Right
  472.             LSR #32   for c  = 0
  473.       011   LSR Rc                  Logical Shift Right
  474.       100   ASR #c    for c != 0    Arithmetic Shift Right
  475.             ASR #32   for c  = 0
  476.       101   ASR Rc                  Arithmetic Shift Right
  477.       110   ROR #c    for c != 0    Rotate Right.
  478.             RRX       for c  = 0    Rotate Right one bit with extend.
  479.       111   ROR Rc                  Rotate Right
  480.  
  481.  
  482. In the register form, Rc is signified by bits 8-11; bit 7 must be clear  if
  483. Rc is used. (If you code a 1 instead, you'll get a multiply, a SWP or some-
  484. thing unallocated instead of a data processing instruction.)
  485.  
  486. Also, only the bottom byte of Rc is used -- If Rc = 256,  then  the  shifts
  487. will be by zero.
  488.  
  489. "MOV[S]  Ra,Rb,RLX" can be done by ADC[S] Ra,Rb,Rb, with RLX meaning Rotate
  490. Left one bit with extend.
  491.  
  492. Most assemblers allow ASL to be used as a synonym for LSL.  Since  opinions
  493. differ on what an arithmetic left shift is, LSL is the preferred term.
  494.  
  495. By  setting  the S bit in a MOV, MVN or logical instruction, (in either the
  496. register or immediate form) the carry flag  is  set  to  be  the  last  bit
  497. shifted out.
  498.  
  499. If no shift is done, the carry flag will be unaffected.
  500.  
  501. If  there  is  a  choice of forms for an immediate (e.g. #1 could be repre-
  502. sented as 1 ROR #0, 4 ROR #2, 16 ROR #4 or 64 ROR  #6),  the  assembler  is
  503. expected  to  use  the one involving a zero rotation, if available. So MOVS
  504. Rn,#const will leave the carry flag unaffected if 0 <= const  <=  255,  but
  505. will change it otherwise.
  506.  
  507.  
  508.      aaaa   Assembler   Meaning                P-Code
  509.  
  510.      0000   AND         Boolean And            Rd = Rn AND Op2
  511.      0001   EOR         Boolean Eor            Rd = Rn EOR Op2
  512.      0010   SUB         Subtract               Rd = Rn  -  Op2
  513.      0011   RSB         Reverse Subtract       Rd = Op2 -  Rn
  514.      0100   ADD         Addition               Rd = Rn  +  Op2
  515.      0101   ADC         Add with Carry         Rd = Rn  +  Op2 + C
  516.      0110   SBC         Subtract with carry    Rd = Rn  -  Op2 - (1-C)
  517.      0111   RSC         Reverse sub w/carry    Rd = Op2 -  Rn  - (1-C)
  518.      1000   TST         Test bit               Rn AND Op2
  519.      1001   TEQ         Test equality          Rn EOR Op2
  520.      1010   CMP         Compare                Rn  -  Op2
  521.      1011   CMN         Compare Negative       Rn  + Op2
  522.  
  523.  
  524.  
  525.  
  526.                              November 15, 1995
  527.  
  528.  
  529.  
  530.  
  531.  
  532.                                    - 9 -
  533.  
  534.  
  535.      1100   ORR         Boolean Or             Rd = Rn OR  Op2
  536.      1101   MOV         Move value             Rd =        Op2
  537.      1110   BIC         Bit clear              Rd = Rn AND NOT Op2
  538.      1111   MVN         Move Not               Rd =    NOT Op2
  539.  
  540. Note  that  MVN  and  CMN are not as related as they first appear; MVN uses
  541. straight bitwise negation, setting Rn to the 1's  complement  of  Op2.  CMN
  542. compares Rn with the 2's complement of Op2.
  543.  
  544. These instructions fall broadly into 4 subsets:
  545.  
  546.      MOV, MVN
  547.         Rn is ignored, and should be 0000. If the S bit is set, N and Z are
  548.         set on the result, and if the shifter is used, C is set to  be  the
  549.         last bit shifted out. V is unaffected.
  550.  
  551.      CMN, CMP, TEQ, TST
  552.         Rd  is  not  set  by the instruction, and should be 0000. The S bit
  553.         must be set (most assemblers do this automatically; if  it  weren't
  554.         set, the instruction would be MRS, MSR, or an unallocated one.)
  555.  
  556.         The  arithmetic operations (CMN, CMP) set N, Z on result, and C and
  557.         V from the ALU.
  558.  
  559.         The logical operations (TEQ, TST) set N and Z on the result, C from
  560.         the  shifter  if  it is used (in which case it becomes the last bit
  561.         shifted out), and V is unaffected.
  562.  
  563.         As a special case (for ARMs >= 6,  this  only  applies  to  26  bit
  564.         code),  the  dddd  field being 1111 causes flags (in user mode), or
  565.         the entire 26 bit PSR (in privileged modes) to be set from the cor-
  566.         responding  bits  of the result. This is indicated by a P suffix to
  567.         the instruction -- CMNP, CMPP, TEQP, TSTP. This  is  most  commonly
  568.         used  to  change  mode  via  TEQP  PC,#(new mode number). In 32 bit
  569.         modes, MSR should be used instead (as TEQP etc will not work).
  570.  
  571.      ADC, ADD, RSB, RSC, SBC, SUB
  572.         If the S bit is set, then N and Z are set on result, and  C  and  V
  573.         are set from the ALU.
  574.  
  575.      AND, BIC, EOR, ORR
  576.         If  the S bit is set, then N and Z are set on result, C is set from
  577.         the shifter if used (in which case it becomes the last bit  shifted
  578.         out) and V is unaffected.
  579.  
  580. ADD and SUB can be used to make registers point to data in a position inde-
  581. pendent way, eg. ADD R0,PC,#24. This is so useful that some assemblers have
  582. a  special  directive called ADR which generates the appropriate ADD or SUB
  583. automatically. (ADR R0, fred typically puts the address of  fred  into  R0,
  584. assuming fred is within range).
  585.  
  586. In 26-bit modes, special cases occur when R15 is one of the registers being
  587. used:
  588.  
  589.  
  590.  
  591.  
  592.                              November 15, 1995
  593.  
  594.  
  595.  
  596.  
  597.  
  598.                                    - 10 -
  599.  
  600.  
  601.      +o    If Rn = R15 then the value used is R15  with  all  the  PSR  bits
  602.           masked out.
  603.  
  604.      +o    If Op2 involves R15, then all 32 bits are used.
  605.  
  606. In 32-bit modes, all the bits of R15 are used.
  607.  
  608. In 26-bit modes, if Rd = R15 then:
  609.  
  610.      o    If the S bit is not set, only the 24 bits of the PC are set.
  611.  
  612.      o    If  the S bit is set, both the PC and PSR are overwritten (though
  613.           the Mode, I and F bits will not be altered unless  we  are  in  a
  614.           non-user mode.)
  615.  
  616. For  32-bit  modes,  if  Rd=15, all the bits of the PC will be overwritten,
  617. except the two least significant bits, which are always zero.  If the S bit
  618. is not set, that is all that happens; if the S bit is set, the SPSR for the
  619. current mode is copied to the CPSR. You should not execute a data  process-
  620. ing instruction with the PC as destination and the S bit set in 32-bit user
  621. mode, since user mode does not have an SPSR. (By the way, you  won't  break
  622. the  processor by doing so -- it's just that the results of doing so aren't
  623. defined, and may differ between processors.)
  624.  
  625. These instructions take the following number of cycles to execute: 1S + (1S
  626. if register controlled shift used) + (1S + 1N if PC changed)
  627.  
  628.  
  629. 5.3.  Branch Instructions
  630.  
  631.  
  632. xxxx101L oooooooo oooooooo oooooooo
  633.  
  634.  
  635. Typical Assembler Syntax:
  636.  
  637.  
  638.         BEQ  address
  639.         BLNE subroutine
  640.  
  641.  
  642. These  instructions  are used to force a jump to a new address, given as an
  643. offset in words from the value of the PC as this instruction is executed.
  644.  
  645. Due to the pipeline, the PC is always 2 instructions (8 bytes) ahead of the
  646. address  at  which  this  instruction was stored, so a branch with offset =
  647. (sign extended version of bits 0-23):
  648.  
  649.              destination address = current address + 8 + (4 * offset)
  650.  
  651. In 26-bit modes, the top 6 bits of the destination address are cleared.
  652.  
  653. If the L flag is set, then the current contents of PC are copied  into  R14
  654. before  the  branch is taken. Thus R14 holds the address of the instruction
  655.  
  656.  
  657.  
  658.                              November 15, 1995
  659.  
  660.  
  661.  
  662.  
  663.  
  664.                                    - 11 -
  665.  
  666.  
  667. after the branch, and the called routine can return with MOV PC,R14.
  668.  
  669. In 26-bit modes, using MOVS PC,R14, to return from a branch with link,  the
  670. PSR  flags  can  be restored automatically on return. The behaviour of MOVS
  671. PC,R14 is different in 32-bit modes, and only suitable for return  from  an
  672. exception.
  673.  
  674. Both branch and branch with links, take 2S+1N cycles to execute.
  675.  
  676.  
  677. 5.4.  Multiplication
  678.  
  679.  
  680. xxxx0000 00ASdddd nnnnssss 1001mmmm
  681.  
  682.  
  683. Typical Assembler Syntax:
  684.  
  685.  
  686.         MULEQS Rd,Rm,Rs
  687.         MLA    Rd,Rm,Rs,Rn
  688.  
  689.  
  690. These instructions multiply the values of 2 registers, and optionally add a
  691. third, placing the result in another register.
  692.  
  693. If the S bit is set, the N and Z flags are set on the result,  C  is  unde-
  694. fined, and V is unaffected.
  695.  
  696. If  the  A  bit is set, then the effect of the operation is Rd = Rm.Rs + Rn
  697. otherwise, Rd = Rm.Rs.
  698.  
  699. The destination register shall not be the same as the operand register  Rm.
  700. R15 shall not be used as an operand or as the destination register.
  701.  
  702. These  instructions  take 1S + 16I cycles to execute in the worst case, and
  703. may be less depending on arguement values. The exact time  depends  on  the
  704. value of Rs, according to the following table:
  705.  
  706.                       Range of Rs            Number of cycles
  707.  
  708.                          &0 -- &1            1S + 1I
  709.                          &2 -- &7            1S + 2I
  710.                          &8 -- &1F           1S + 3I
  711.                         &20 -- &7F           1S + 4I
  712.                         &80 -- &1FF          1S + 5I
  713.                        &200 -- &7FF          1S + 6I
  714.                        &800 -- &1FFF         1S + 7I
  715.                       &2000 -- &7FFF         1S + 8I
  716.                       &8000 -- &1FFFF        1S + 9I
  717.                      &20000 -- &7FFFF        1S + 10I
  718.                      &80000 -- &1FFFFF       1S + 11I
  719.                     &200000 -- &7FFFFF       1S + 12I
  720.  
  721.  
  722.  
  723.  
  724.                              November 15, 1995
  725.  
  726.  
  727.  
  728.  
  729.  
  730.                                    - 12 -
  731.  
  732.  
  733.                     &800000 -- &1FFFFFF      1S + 13I
  734.                    &2000000 -- &7FFFFFF      1S + 14I
  735.                    &8000000 -- &1FFFFFFF     1S + 15I
  736.                   &20000000 -- &FFFFFFFF     1S + 16I
  737.  
  738.  
  739. These  multiplication  timings  don't  apply  to ARM7DM. ARM7DM timings are
  740. given by the following table.
  741.  
  742.                                          MLA/
  743.               Range of Rs        MUL     SMULL   SMLAL   UMULL   UMLAL
  744.  
  745.                &0 -- &FF         1S+1I   1S+2I   1S+3I   1S+2I   1S+3I
  746.              &100 -- &FFFF       1S+2I   1S+3I   1S+4I   1S+3I   1S+4I
  747.            &10000 -- &FFFFFF     1S+3I   1S+4I   1S+5I   1S+4I   1S+5I
  748.          &1000000 -- &FEFFFFFF   1S+4I   1S+5I   1S+6I   1S+5I   1S+6I
  749.         &FF000000 -- &FFFEFFFF   1S+3I   1S+4I   1S+5I   1S+5I   1S+6I
  750.         &FFFF0000 -- &FFFFFEFF   1S+2I   1S+3I   1S+4I   1S+5I   1S+6I
  751.         &FFFFFF00 -- &FFFFFFFF   1S+1I   1S+2I   1S+3I   1S+5I   1S+6I
  752.  
  753.  
  754.  
  755. 5.5.  Long Multiplication (ARM7DM)
  756.  
  757.  
  758. xxxx0000 1UAShhhh llllssss 1001mmmm
  759.  
  760.  
  761. Typical Assembler Syntax:
  762.  
  763.  
  764.         UMULL  Rl,Rh,Rm,Rs
  765.         UMLAL  Rl,Rh,Rm,Rs
  766.         SMULL  Rl,Rh,Rm,Rs
  767.         SMLAL  Rl,Rh,Rm,Rs
  768.  
  769.  
  770. These instructions multiply the values of registers Rm and Rs to  obtain  a
  771. 64-bit product.
  772.  
  773. When  the  U bit is clear the multiply is unsigned (UMULL or UMLAL), other-
  774. wise signed (SMULL, SMLAL).  When the A bit is clear the result  is  stored
  775. with  its least significant half in Rl and its most significant half in Rh.
  776. When A is set, the result is instead added to the contents of Rh,Rl.
  777.  
  778. The program counter, R15 should not be used.  Rh, Rl and Rm should be  dif-
  779. ferent.
  780.  
  781. If  the S bit is set, the N and Z flags are set on the 64-bit result, C and
  782. V are undefined.
  783.  
  784. Timings for these can be found above in the multiplication section.
  785.  
  786.  
  787.  
  788.  
  789.  
  790.                              November 15, 1995
  791.  
  792.  
  793.  
  794.  
  795.  
  796.                                    - 13 -
  797.  
  798.  
  799. 5.6.  Single Data Transfer
  800.  
  801.  
  802. xxxx010P UBWLnnnn ddddoooo oooooooo  Immediate form
  803. xxxx011P UBWLnnnn ddddcccc ctt0mmmm  Register form
  804.  
  805.  
  806. Typical Assembler Syntax:
  807.  
  808.  
  809.         LDR  Rd,[Rn,Rm,ASL#1]!
  810.         STR  Rd,[Rn],#2
  811.         LDRT Rd,[Rn]
  812.         LDRB Rd,[Rn]
  813.  
  814.  
  815. These instructions load/store a word of  memory  from/to  a  register.  The
  816. first  register used in specifying the address is termed the base register.
  817.  
  818. If the L bit is set, then a load is performed. If not, a store.
  819.  
  820. If the P bit is set, then Pre-indexed addressing is used,  otherwise  post-
  821. indexed addressing is used.
  822.  
  823. If the U bit is set, then the offset given is added to the base register --
  824. otherwise it is subtracted.
  825.  
  826. If the B bit is set, then a byte of memory is transferred, otherwise a word
  827. is  transferred. This is signified to assemblers by postfixing the mnemonic
  828. stub with a `B'.
  829.  
  830. The interpretation of the W bit depends on the addressing mode used:
  831.  
  832.      o    For pre-indexed addressing, W being set forces the  writing  back
  833.           of  the  final  address used for the address translation into the
  834.           base register. (i.e.  A side effect of the transfer is Rn  :=  Rn
  835.           +/-  offset.  This  is  signified to assemblers by postfixing the
  836.           instruction with !.)
  837.  
  838.      o    For post-indexed addressing, the address is always written  back,
  839.           and  the  bit  being  set  indicates  that an address translation
  840.           should be forced before the transfer takes place. This is  signi-
  841.           fied to assmeblers by postfixing the mnemonic stub with `T'.
  842.  
  843. An  address translation causes the chip to tell the memory system that this
  844. is a user mode transfer, regardless of whether the chip is in a  user  mode
  845. or  a  privileged mode at the time. This is useful e.g. when writing emula-
  846. tors: suppose for instance  that  a  user  mode  program  executes  an  STF
  847. instruction to an area of memory that may not be written by user mode code.
  848. If this is executed by an FPA, it will abort. If it is executed by the FPE,
  849. it  should also abort. But the FPE runs in a privileged mode, so if it were
  850. to use normal stores, they wouldn't abort. To make aborts work properly, it
  851. instead  uses  normal  stores  if it was called from a privileged mode, but
  852. STRTs if it was called from a user mode.
  853.  
  854.  
  855.  
  856.                              November 15, 1995
  857.  
  858.  
  859.  
  860.  
  861.  
  862.                                    - 14 -
  863.  
  864.  
  865. If the immediate form of the instruction is  used,  the  o  field  gives  a
  866. 12-bit  offset. If the register form is used, then it is decoded as for the
  867. data processing instructions, with the restriction that shifts by  register
  868. amounts are not allowed.
  869.  
  870. If R15 is used as Rd, the PSR is not modified. The PC should not be used in
  871. Op2.
  872.  
  873. Other restrictions:
  874.  
  875.      o    Don't use writeback or post-indexing when the  base  register  is
  876.           the PC.
  877.  
  878.      o    Don't use the PC as Rd for an LDRB or STRB.
  879.  
  880.      o    When  using  post-indexing  with a register offset, don't make Rn
  881.           and Rm the same register (doing so  makes  recovery  from  aborts
  882.           impossible).
  883.  
  884. A  load  takes  1S  + 1N + 1I + (1S + 1N if PC changed) cycles, and a store
  885. takes 2N cycles.
  886.  
  887.  
  888. 5.7.  Block Data Transfer
  889.  
  890.  
  891. xxxx100P USWLnnnn llllllll llllllll
  892.  
  893.  
  894. Typical Assembler Syntax:
  895.  
  896.  
  897.         LDMFD   Rn!,{R0-R4,R8,R12}
  898.         STMEQIA Rn,{R0-R3}
  899.         STMIB   Rn,{R0-R3}^
  900.  
  901.  
  902. These instructions are  used  to  load/store  large  numbers  of  registers
  903. from/to  memory  at a time. The memory addresses used are either increasing
  904. or decreasing in memory from a value held in a base  register,  Rn,  (which
  905. may  itself  be stored), and the final address can be written back into the
  906. base. These instructions are  ideal  for  implementing  stacks,  and  stor-
  907. ing/restoring the contents of registers on entry/exit from a subroutine.
  908.  
  909. The U bit indicates whether the address will be modified by +4 (set), or -4
  910. (clear) for each register.
  911.  
  912. The W bit always indicates writeback.
  913.  
  914. If set, the L bit indicates a load operation should be performed. If clear,
  915. a save.
  916.  
  917. The  P  bit is used indicate whether to increment/decrement the base before
  918. or after each load/store (see the table below).
  919.  
  920.  
  921.  
  922.                              November 15, 1995
  923.  
  924.  
  925.  
  926.  
  927.  
  928.                                    - 15 -
  929.  
  930.  
  931. Bit l is set if Rl is to be loaded/stored by this operation.
  932.  
  933. Assemblers typically follow the mnemonic stub with a  condition  code,  and
  934. then a two letter code to indicate the settings of the U and W bits.
  935.  
  936.             Stub   Meaning                               P   U
  937.  
  938.             DA     Decrement Rn After each store/load    0   0
  939.             DB     Decrement Rn Before each store/load   1   0
  940.             IA     Increment Rn After each store/load    0   1
  941.             IB     Increment Rn Before each store/load   1   1
  942.  
  943.  
  944. Synonyms for these exist which are clearer when implementing stacks:
  945.  
  946.                        Stub   Meaning
  947.  
  948.                        EA     Empty Ascending stack
  949.                        ED     Empty Decending stack
  950.                        FA     Full Ascending stack
  951.                        FD     Full Decending stack
  952.  
  953.  
  954. In  an empty stack, the stack pointer points to the next empty position. In
  955. a full one the stack pointer points to the topmost full position. Ascending
  956. stacks  grow towards high locations, and descending stacks grow towards low
  957. locations.
  958.  
  959. The registers are always stored so that the lowest numbered register is  at
  960. the lowest address in memory. This can affect stacking and unstacking code.
  961. For instance, if I want to push R1-R4 on to a stack, then  load  them  back
  962. two  at  a time, to get them back to the same registers, I need to do some-
  963. thing like:
  964.  
  965.  
  966.    STMFD R13!,{R1,R2,R3,R4}  ;Puts R1 low in memory, i.e. at end of stack
  967.    LDMFD R13!,{R1,R2}
  968.    LDMFD R13!,{R3,R4}
  969.  
  970.  
  971. for a descending stack, but something like:
  972.  
  973.  
  974.    STMFA R13!,{R1,R2,R3,R4}  ;Puts R4 high in memory, i.e. at end of stack
  975.    LDMFA R13!,{R3,R4}
  976.    LDMFA R13!,{R1,R2}
  977.  
  978.  
  979. for an ascending stack.
  980.  
  981. The codes are synonyms as follows:
  982.  
  983.                             Code   Load   Store
  984.  
  985.  
  986.  
  987.  
  988.                              November 15, 1995
  989.  
  990.  
  991.  
  992.  
  993.  
  994.                                    - 16 -
  995.  
  996.  
  997.  
  998.                              EA     DB     IA
  999.                              ED     IB     DA
  1000.                              FA     DA     IB
  1001.                              FD     IA     DB
  1002.  
  1003. The S bit controls two special functions, both of which  are  indicated  to
  1004. the assembler by putting "^" at the end of the instruction:
  1005.  
  1006.      o    If  the  S  bit  is set, the instruction is LDM and R15 is in the
  1007.           register list, then:
  1008.  
  1009.           *    In 26-bit privileged modes, all  32  bits  of  R15  will  be
  1010.                loaded.
  1011.  
  1012.           *    In  26-bit user mode, the 4 flags and 24 PC bits of R15 will
  1013.                be loaded.  Bits 27, 26, 1 and 0 of the loaded value will be
  1014.                ignored.
  1015.  
  1016.           *    In  32-bit  modes, all 32 bits of R15 will be loaded, though
  1017.                note that the two bottom bits are always zero, so  any  ones
  1018.                loaded to them will be ignored. In addition, the SPSR of the
  1019.                current mode will be transferred to  the  CPSR;  since  user
  1020.                mode  does not have an SPSR, this type of instruction should
  1021.                not be used in 32-bit user mode.
  1022.  
  1023.      o    If the S bit is set and either the instruction is STM or  R15  is
  1024.           not  in  the  register list, then the user mode registers will be
  1025.           transferred rather than those for the current mode. This type  of
  1026.           instruction should not be used in user mode.
  1027.  
  1028. Special cases occur when the base register is used in the list of registers
  1029. to be transferred.
  1030.  
  1031.      o    The base register can always  be  loaded  without  any  problems.
  1032.           However,  don't  specify  writeback if the base register is being
  1033.           loaded -- you can't end up with both a written-back value  and  a
  1034.           loaded value in the base register!
  1035.  
  1036.      o    The  base register can be stored with no complications as long as
  1037.           writeback is not used.
  1038.  
  1039.      o    Storing a list of registers including  the  base  register  using
  1040.           writeback will write the value of the base register before write-
  1041.           back to memory only if the base register  is  the  first  in  the
  1042.           list. Otherwise, the value which is used is not defined.
  1043.  
  1044. Further  special  cases occur if the program counter is present in the list
  1045. of registers to load and save.
  1046.  
  1047.      o    The PSR is always saved with the PC (in 26 bit modes) (and the PC
  1048.           will  always  be 12 bytes further on, rather than the usual 8 (in
  1049.           all modes)).
  1050.  
  1051.  
  1052.  
  1053.  
  1054.                              November 15, 1995
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.                                    - 17 -
  1061.  
  1062.  
  1063.      o    On a load, only the bits of the PSR that  are  alterable  in  the
  1064.           current  mode can be affected, and then only if the S bit is set.
  1065.  
  1066. The PC should not be used as the base register.
  1067.  
  1068. A block data load, takes nS + 1N + 1I + (1S + 1N if PC changed) cycles, and
  1069. a  block  data  store  takes (n-1)S + 2N cycles, where "n" is the number of
  1070. words being transferred.
  1071.  
  1072.  
  1073. 5.8.  Software interrupt
  1074.  
  1075.  
  1076. xxxx1111 yyyyyyyy yyyyyyyy yyyyyyyy
  1077.  
  1078.  
  1079. Typical Assembler Syntax:
  1080.  
  1081.  
  1082.        SWI   "OS_WriteI"
  1083.        SWINE &400C0
  1084.  
  1085.  
  1086. On encountering a software interrupt, the ARM switches into SVC mode, saves
  1087. the  current  value of R15 into R14_SVC, and jumps to location 8 in memory,
  1088. where it assumes it will find a SWI handling routine to decode the lower 24
  1089. bits  of  the  SWI  just executed, and do whatever the SWI number concerned
  1090. means on that particular operating system.
  1091.  
  1092. An operating system written on the ARM will typically use SWIs  to  provide
  1093. miscellaneous routines for programmers.
  1094.  
  1095. A  SWI  takes  2S + 1N cycles to execute (plus whatever time is required to
  1096. decode the SWI number and execute the appropriate routines).
  1097.  
  1098.  
  1099. 5.9.  Co-processor data operations
  1100.  
  1101.  
  1102. xxxx1110 oooonnnn ddddpppp qqq0mmmm
  1103.  
  1104.  
  1105. Typical Assembler Syntax:
  1106.  
  1107.  
  1108.        CDP p,o,CRd,CRn,CRm,q
  1109.        CDP p,o,CRd,CRn,CRm
  1110.  
  1111.  
  1112. This instruction is passed on to co-processor  p,  telling  it  to  perform
  1113. operation  o,  on  co-processor registers CRn and CRm, and place the result
  1114. into Crd.
  1115.  
  1116. qqq may supply additional information about the operation concerned.
  1117.  
  1118.  
  1119.  
  1120.                              November 15, 1995
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.                                    - 18 -
  1127.  
  1128.  
  1129. The exact meaning of these  instructions  depends  on  the  particular  co-
  1130. processor  in  use; The above is only a recommended usage for the bits (and
  1131. indeed the FPA doesn't conform to it). The only part which is obligatory is
  1132. that  pppp must be the coprocessor number: the coprocessor designer is free
  1133. to allocate oooo, nnnn, dddd, qqq and mmmm as desired.
  1134.  
  1135. If the coprocessor uses the bits in a different way  than  the  recommended
  1136. one,  assembler macros will probably be needed to translate the instruction
  1137. syntax that makes sense to people into the  correct  CDP  instruction.  For
  1138. commonly  used coprocessors such as the FPA, many assemblers have the extra
  1139. mnemonics built in and do this  translation  automatically.  (For  example,
  1140. assembling MUFEZ F0,F1,#10 as its equivalent CDP 1,1,CR0,CR9,CR15,3.)
  1141.  
  1142. Currently defined co-processor numbers include:
  1143.  
  1144.                        1 and 2   Floating Point unit
  1145.                        15        Cache Controller
  1146.  
  1147.  
  1148. If  a  call  to  a coprocessor is made and the coprocessor does not respond
  1149. (normally becuase it isn't there!), the  undefined  instruction  vector  is
  1150. called (exactly as for one of the undefined instructions given later). This
  1151. is used to transparently provide FP support on machines without an FPA.
  1152.  
  1153. These instructions take 1S + bI cycles to execute, where b is the number of
  1154. cycles  that  the coprocessor causes the ARM to busy-wait before it accepts
  1155. the instruction: again, this is under the coprocessor's control.
  1156.  
  1157.  
  1158. 5.10.  Co-processor data transfer and register transfers
  1159.  
  1160.  
  1161. xxxx110P UNWLnnnn DDDDpppp oooooooo LDC/STC
  1162. xxxx1110 oooLNNNN ddddpppp qqq1MMMM MRC/MCR
  1163.  
  1164.  
  1165. Again these depend on the particular co-processor p in use.
  1166.  
  1167. N and D signify co-processor register numbers, n and d  are  ARM  processor
  1168. numbers.  o  is  the  co-processor  operation  to use. M signifies bits the
  1169. coprocessor is free to use as it wants.
  1170.  
  1171. The first form, denotes LDC if L=1, STC otherwise. The instruction  behaves
  1172. like  LDR  or STR respectively, in each case with an immediate offset, with
  1173. the following exceptions.
  1174.  
  1175.      o    The offset is 4*(oooooooo), not a general 12-bit constant.
  1176.  
  1177.      o    If P=0 (post-indexing) is specified, W must be 1, and W  being  1
  1178.           just  indicates  that  writeback is required, not that the memory
  1179.           system should be told that this is a user mode transfer. Instruc-
  1180.           tions with P=0 and W=0 are reserved for future expansion.
  1181.  
  1182.      o    One  or  more  coprocessor  registers  are  loaded or stored. The
  1183.  
  1184.  
  1185.  
  1186.                              November 15, 1995
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.                                    - 19 -
  1193.  
  1194.  
  1195.           coprocessor determines how many and which  registers  are  to  be
  1196.           loaded  or  stored  from the DDDD and N bits: all the ARM does is
  1197.           transfer a word to or from the indicated address, then another to
  1198.           or  from the indicated address + 4, then one to or from the indi-
  1199.           cated address + 8, etc., until the coprocessor tells it to  stop.
  1200.  
  1201.      o    By  convention,  DDDD denotes the (first) coprocessor register to
  1202.           load or store and N denotes the length  in  some  way,  with  N=1
  1203.           indicating  a  "long"  form.  Coprocessor  designers  are free to
  1204.           ignore this...
  1205.  
  1206.      o    The assembler syntax is along the lines of:
  1207.  
  1208.  
  1209.           LDC    p,CRd,[Rn,#20]   ;short form (N=0), pre-indexed
  1210.           STCL   p,CRd,[Rn,#-32]! ;long form (N=1), pre-indexed with writeback
  1211.           LDCNEL p,CRd,[Rn],#-100 ;long form (N=1), post-indexed
  1212.  
  1213.  
  1214. The second form denotes, MRC, if  L=1,  MCR  otherwise.   MRC  transfers  a
  1215. coprocessor register to an ARM register, MCR the other way around (the let-
  1216. ters may seem the wrong way around, but remember that destinations are usu-
  1217. ally written on the left in ARM assembler).
  1218.  
  1219. MCR  transfers  the  contents  of  ARM  register Rd to the coprocessor. The
  1220. coprocessor is free to do whatever it wants with it based on the values  of
  1221. the  ooo,  dddd, qqq and MMMM fields, though as usual there is a "standard"
  1222. interpretation: write it to coprocessor register CRN, using operation  ooo,
  1223. with  possible  additional  control  provided by CRM and qqq. The assembler
  1224. syntax is:
  1225.  
  1226.  
  1227.        MCR   p,o,Rd,CRN,CRM,q
  1228.  
  1229.  
  1230. Rd should not be R15 for an MCR instruction.
  1231.  
  1232. MRC transfers a single word from the coprocessor and puts it in ARM  regis-
  1233. ter  Rd.  The coprocessor is free to generate this word in any way it likes
  1234. using the same fields as for MCR, with the standard interpretation that  it
  1235. comes  from  CRN using operation ooo, with possible additional control pro-
  1236. vided by CRM and qqq. The assembler syntax is:
  1237.  
  1238.  
  1239.        MRC   p,o,Rd,CRN,CRM,q
  1240.  
  1241.  
  1242. If Rd is R15 for an MRC instruction, the top 4 bits of the word transferred
  1243. are  used  to  set the flags; the remaining 28 bits are discarded. (This is
  1244. the mechanism used e.g. by floating point comparison instructions.)
  1245.  
  1246. LDC and STC take (n-1)S + 2N + bI cycles to  execute,  MRC  takes  1S+bI+1C
  1247. cycles,  and  MCR  takes  1S + (b+1)I + 1C cycles, where b is the number of
  1248. cycles that the coprocessor causes the ARM to busy-wait before  it  accepts
  1249.  
  1250.  
  1251.  
  1252.                              November 15, 1995
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.                                    - 20 -
  1259.  
  1260.  
  1261. the  instruction:  again, this is under the coprocessor's control, and n is
  1262. the number of words being transferred (Note this is under the coprocessor's
  1263. control, not the ARM's)
  1264.  
  1265.  
  1266. 5.11.  Single Data Swap (ARM 3 and later including ARM 2aS)
  1267.  
  1268.  
  1269. xxxx0001 0B00nnnn dddd0000 1001mmmm
  1270.  
  1271.  
  1272. Typical Assembler Syntax:
  1273.  
  1274.  
  1275.        SWP Rd,Rm,[Rn]
  1276.  
  1277.  
  1278. These  instructions load a word of memory (address given by register Rn) to
  1279. a register Rd and store the contents of register Rm to the same address. Rm
  1280. and  Rd may be the same register, in which case the contents of this regis-
  1281. ter and of the memory location are swapped. The load and  store  operations
  1282. are  locked  together  by setting the LOCK pin high during the operation to
  1283. indicate to the memory manager that they  should  be  allowed  to  complete
  1284. without interruption.
  1285.  
  1286. If the B bit is set, then a byte of memory is transferred, otherwise a word
  1287. is transferred.
  1288.  
  1289. None of Rd, Rn, and Rm may be R15.
  1290.  
  1291. This instruction takes 1S + 2N + 1I cycles to execute.
  1292.  
  1293.  
  1294. 5.12.  Status Register transfer (ARM 6 and later)
  1295.  
  1296.  
  1297. xxxx0001 0s10aaaa 11110000 0000mmmm  MSR Register form
  1298. xxxx0011 0s10aaaa 1111rrrr bbbbbbbb  MSR Immediate form
  1299. xxxx0001 0s001111 dddd0000 00000000  MRS
  1300.  
  1301.  
  1302. Typical Assembler Syntax:
  1303.  
  1304.  
  1305.        MSR   SPSR_all,Rm          ;aaaa = 1001
  1306.        MSR   CPSR_flg,#&F0000000  ;aaaa = 1000
  1307.        MSRNE CPSR_ctl,Rm          ;aaaa = 0001
  1308.        MRS   Rd,CPSR
  1309.  
  1310.  
  1311. The s bit, when set means access the SPSR of the current  privileged  mode,
  1312. rather  than the CPSR. This bit must only be set when executing the command
  1313. in a privileged mode.
  1314.  
  1315.  
  1316.  
  1317.  
  1318.                              November 15, 1995
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.                                    - 21 -
  1325.  
  1326.  
  1327. MSR is used for transfering a register or constant to a status register.
  1328.  
  1329. The aaaa bits can take the following values:
  1330.  
  1331.  Value   Meaning
  1332.  
  1333.  0001    Set the control bits of the PSR concerned.
  1334.  1000    Set the flag bits of the PSR concerned.
  1335.  1001    Set the control and flag bits of the PSR concerned (i.e. all the
  1336.          bits at present).
  1337.  
  1338. Other values of aaaa are reserved for future expansion.
  1339.  
  1340. In the register form, the source register is Rm. In the immediate form, the
  1341. source is #b, ROR #2r.
  1342.  
  1343. R15 should not be specified as the source register of an MRS instruction.
  1344.  
  1345. MRS is used for transfering processor status to a register.
  1346.  
  1347. The d bits store the destination register number; Rd must not be R15.
  1348.  
  1349. N.B.  The  instruction encodings correspond to the data processing instruc-
  1350. tions with opcodes 10xx (i.e. the test instructions) and the S bit clear.
  1351.  
  1352. These instruction always execute in 1-S cycle.
  1353.  
  1354.  
  1355. 5.13.  Undefined instructions
  1356.  
  1357.  
  1358. xxxx0001 yyyyyyyy yyyyyyyy 1yy1yyyy ARM 2 only
  1359. xxxx011y yyyyyyyy yyyyyyyy yyy1yyyy
  1360.  
  1361.  
  1362. These instructions are currently undefined. On  encountering  an  undefined
  1363. instruction,  the  ARM  switches  to SVC mode (on ARM 3 and below) or Undef
  1364. mode (on ARM 6 and above), puts the old  value  of  R15  into  R14_SVC  (or
  1365. R14_UND) and jumps to location, where it expects to find code to decode the
  1366. undefined instruction and behave accordingly.
  1367.  
  1368. Notes:
  1369.  
  1370.      o    These instructions are documented  as  "undefined"  because  they
  1371.           enter  the  undefined  instruction  processor  trap  in this way.
  1372.           Plenty of other instructions are undefined in  the  looser  sense
  1373.           that nothing says what they do. For instance, bit patterns of the
  1374.           form:
  1375.  
  1376.                                 xxxx0000 01xxxxxx xxxxxxxx 1001xxxx
  1377.  
  1378.           are related to data  processing  instructions,  multiplies,  long
  1379.           multiplies and SWPs, but are none of these because:
  1380.  
  1381.  
  1382.  
  1383.  
  1384.                              November 15, 1995
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.                                    - 22 -
  1391.  
  1392.  
  1393.           *    Data  processing  instructions with bit 25 = 0 and bit 4 = 1
  1394.                have register controlled shifts, and so must have bit 7 = 0.
  1395.  
  1396.           *    Multiply instructions have bits 23:22 = 00.
  1397.  
  1398.           *    Long multiply instructions have bits 23:22 = 1U.
  1399.  
  1400.           *    SWPs have bit 24 = 1.
  1401.           What these instructions do simply isn't defined, whereas the ones
  1402.           listed above are actually defined to enter the undefined instruc-
  1403.           tion trap, at least until some future use is found for them.
  1404.  
  1405.      o    Note  that  the  "ARM2 only" undefined instructions include those
  1406.           that became SWP instructions on ARM3/ARM2as and later.
  1407.  
  1408.  
  1409. 6.  Credits
  1410.  
  1411. This document was originally written by Robin Watts, with considerable con-
  1412. sultation  with  Steven  Singer. It was then later updated by Mark Smith to
  1413. include more information on ARMs later than 2.
  1414.  
  1415. David Seal provided a huge list of corrections and amendments,  and  unwit-
  1416. tingly  provided  the  basis  for  the  timing  information in a posting to
  1417. usenet.
  1418.  
  1419. Various corrections were also submitted/posted by Olly Betts, Clive  Jones,
  1420. Alain Noullez, John Veness, Sverker Wiberg and Mark Wooding.
  1421.  
  1422. Thanks  to  everyone that helped (and if I have missed you here, please let
  1423. me know.)
  1424.  
  1425. Just because I have included peoples addresses here,  please  do  not  take
  1426. this as an invitation to mail them any questions you may have!
  1427.  
  1428.  
  1429.               Olly Betts       olly@mantis.co.uk
  1430.               Paul Hankin      pdh13@cus.cam.ac.uk
  1431.               Robert Harley    robert@edu.caltech.cs
  1432.               Clive Jones      Clive.Jones@armltd.co.uk
  1433.               Alain Noullez    anoullez@zig.inria.fr
  1434.               David Seal       <address withheld by request>
  1435.               Steven Singer    s.singer@ph.surrey.ac.uk
  1436.               Mark Smith       ee91mds2@brunel.ac.uk
  1437.               John Veness      john@uk.ac.ox.drl
  1438.               Robin Watts      Robin.Watts@comlab.ox.ac.uk
  1439.               Sverker Wiberg   sverkerw@Student.csd.UU.SE
  1440.               Mark Wooding     csuov@csv.warwick.ac.uk
  1441.  
  1442.  
  1443. For those not on the internet, messages can be sent by snail mail to:
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.                              November 15, 1995
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.                                    - 23 -
  1457.  
  1458.  
  1459.                           Robin Watts
  1460.                           St Catherines College,
  1461.                           Oxford,
  1462.                           OX1 3UJ
  1463.  
  1464.  
  1465.  
  1466.  
  1467.  
  1468.  
  1469.  
  1470.  
  1471.  
  1472.  
  1473.  
  1474.  
  1475.  
  1476.  
  1477.  
  1478.  
  1479.  
  1480.  
  1481.  
  1482.  
  1483.  
  1484.  
  1485.  
  1486.  
  1487.  
  1488.  
  1489.  
  1490.  
  1491.  
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.                              November 15, 1995
  1517.  
  1518.  
  1519.