![]() |
|
If you can't view the Datasheet, Please click here to try to view without PDF Reader . |
|
Datasheet File OCR Text: |
regarding the change of names mentioned in the document, such as hitachi electric and hitachi xx, to renesas technology corp. the semiconductor operations of mitsubishi electric and hitachi were transferred to renesas technology corporation on april 1st 2003. these operations include microcomputer, logic, analog and discrete devices, and memory chips other than drams (flash memory, srams etc.) accordingly, although hitachi, hitachi, ltd., hitachi semiconductors, and other hitachi brand names are mentioned in the document, these names have in fact all been changed to renesas technology corp. thank you for your understanding. except for our corporate trademark, logo and corporate statement, no changes whatsoever have been made to the contents of the document, and these changes do not constitute any alteration to the contents of the document itself. renesas technology home page: http://www.renesas.com renesas technology corp. customer support dept. april 1, 2003 to all our customers
cautions keep safety first in your circuit designs! 1. renesas technology corporation puts the maximum effort into making semiconductor products better and more reliable, but there is always the possibility that trouble may occur with them. trouble with semiconductors may lead to personal injury, fire or property damage. remember to give due consideration to safety when making your circuit designs, with appropriate measures such as (i) placement of substitutive, auxiliary circuits, (ii) use of nonflammable material or (iii) prevention against any malfunction or mishap. notes regarding these materials 1. these materials are intended as a reference to assist our customers in the selection of the renesas technology corporation product best suited to the customer's application; they do not convey any license under any intellectual property rights, or any other rights, belonging to renesas technology corporation or a third party. 2. renesas technology corporation assumes no responsibility for any damage, or infringement of any third-party's rights, originating in the use of any product data, diagrams, charts, programs, algorithms, or circuit application examples contained in these materials. 3. all information contained in these materials, including product data, diagrams, charts, programs and algorithms represents information on products at the time of publication of these materials, and are subject to change by renesas technology corporation without notice due to product improvements or other reasons. it is therefore recommended that customers contact renesas technology corporation or an authorized renesas technology corporation product distributor for the latest product information before purchasing a product listed herein. the information described here may contain technical inaccuracies or typographical errors. renesas technology corporation assumes no responsibility for any damage, liability, or other loss rising from these inaccuracies or errors. please also pay attention to information published by renesas technology corporation by various means, including the renesas technology corporation semiconductor home page (http://www.renesas.com). 4. when using any or all of the information contained in these materials, including product data, diagrams, charts, programs, and algorithms, please be sure to evaluate all information as a total system before making a final decision on the applicability of the information and products. renesas technology corporation assumes no responsibility for any damage, liability or other loss resulting from the information contained herein. 5. renesas technology corporation semiconductors are not designed or manufactured for use in a device or system that is used under circumstances in which human life is potentially at stake. please contact renesas technology corporation or an authorized renesas technology corporation product distributor when considering the use of a product contained herein for any specific purposes, such as apparatus or systems for transportation, vehicular, medical, aerospace, nuclear, or undersea repeater use. 6. the prior written approval of renesas technology corporation is n ecessary to reprint or reproduce in whole or in part these materials. 7. if these products or technologies are subject to the japanese export control restrictions, they must be exported under a license from the japanese government and cannot be imported into a country other than the approved destination. any diversion or reexport contrary to the export control laws and regulations of japan and/or the country of destination is prohibited. 8. please contact renesas technology corporation for further details on these materials or the products contained therein. superh ? risc engine sh-4 programming manual ade-602-156d rev. 5.0 4/19/2001 hitachi, ltd. cautions 1. hitachi neither warrants nor grants licenses of any rights of hitachi?s or any third party?s patent, copyright, trademark, or other intellectual property rights for information contained in this document. hitachi bears no responsibility for problems that may arise with third party?s rights, including intellectual property rights, in connection with use of the information contained in this document. 2. products and product specifications may be subject to change without notice. confirm that you have received the latest product standards or specifications before final design, purchase or use. 3. hitachi makes every attempt to ensure that its products are of high quality and reliability. however, contact hitachi?s sales office before using the product in an application that demands especially high quality and reliability or where its failure or malfunction may directly threaten human life or cause risk of bodily injury, such as aerospace, aeronautics, nuclear power, combustion control, transportation, traffic, safety equipment or medical equipment for life support. 4. design your application so that the product is used within the ranges guaranteed by hitachi particularly for maximum rating, operating supply voltage range, heat radiation characteristics, installation conditions and other characteristics. hitachi bears no responsibility for failure or damage when used beyond the guaranteed ranges. even within the guaranteed ranges, consider normally foreseeable failure rates or failure modes in semiconductor devices and employ systemic measures such as fail-safes, so that the equipment incorporating hitachi product does not cause bodily injury, fire or other consequential damage due to operation of the hitachi product. 5. this product is not designed to be radiation resistant. 6. no one is permitted to reproduce or duplicate, in any form, the whole or part of this document without written approval from hitachi. 7. contact hitachi?s sales office for any questions regarding this document or hitachi semiconductor products. rev. 5.0, 04/01, page iii of 12 preface the sh-4 has been developed as the top-end model in the superh?* risc engine family, featuring a 128-bit graphic engine for multimedia applications and 360 mips performance. the sh-4 cpu has a risc type instruction set, and features upward-compatibility at the object code level with sh-1, sh-2, sh-3 microcomputers. in addition to single- and double-precision floating-point operation capability, the on-chip fpu has a 128-bit graphic engine that enables 32-bit floating-point data to be processed 128 bits at a time. it also supports 4 4 array operations and inner product operations. a superscalar architecture is employed that enables simultaneous execution of two instructions (including fpu instructions), providing performance of up to twice that of conventional architectures at the same frequency. this programming manual gives details of the sh-4 instructions. for hardware details, refer to the relevant hardware manual. related manual: sh7750 series hardware manual sh7751 hardware manual please consult your hitachi sales representative for information on development environment systems. note: * superh? is a trademark of hitachi, ltd. rev. 5.0, 04/01, page iv of 12 rev. 5.0, 04/01, page v of 12 main revisions and additions in this version page item revision (see manual for details) 13 2.2.4 control registers ? imask: interrupt mask level external interrupts of a same level or a lower level than imask are masked. 16 2.3 memory-mapped registers description amended 26 3.2 register descriptions 3. page table entry assistance register (ptea) in the sh7750 series and sh7751, access to a pcmcia interface area by the dmac is always performed using the dmac?s chcrn.ssan, chcrn.dsan, chcrn.stc, and chcrn.dtc values. 112 5.6.4 priority order with multiple exceptions 2. indivisible delayed branch instruction and delay slot instruction descriptions (a) to (f) totally revised 280 9.47 ftrv 1. multiplies all terms. the results are 28 bits long. 2. aligns these results, rounding them to fit within 30 bits. rev. 5.0, 04/01, page vi of 12 rev. 5.0, 04/01, page vii of 12 contents section 1 overview ............................................................................................................. 1 1.1 sh-4 features............................................................................................................... ..... 1 section 2 programming model ........................................................................................ 5 2.1 data formats................................................................................................................ ..... 5 2.2 register configuration...................................................................................................... 6 2.2.1 privileged mode and banks ................................................................................. 6 2.2.2 general registers ................................................................................................. 9 2.2.3 floating-point registers....................................................................................... 11 2.2.4 control registers ................................................................................................. 13 2.2.5 system registers.................................................................................................. 14 2.3 memory-mapped registers............................................................................................... 16 2.4 data format in registers................................................................................................... 1 7 2.5 data formats in memory .................................................................................................. 17 2.6 processor states............................................................................................................ ..... 18 2.7 processor modes ............................................................................................................. .. 20 section 3 memory management unit (mmu) ........................................................... 21 3.1 overview.................................................................................................................... ....... 21 3.1.1 features................................................................................................................ 21 3.1.2 role of the mmu................................................................................................. 21 3.1.3 register configuration......................................................................................... 24 3.1.4 caution................................................................................................................. 24 3.2 register descriptions ....................................................................................................... .25 3.3 memory space ................................................................................................................ .. 28 3.3.1 physical memory space....................................................................................... 28 3.3.2 external memory space....................................................................................... 31 3.3.3 virtual memory space......................................................................................... 32 3.3.4 on-chip ram space........................................................................................... 33 3.3.5 address translation ............................................................................................. 33 3.3.6 single virtual memory mode and multiple virtual memory mode ................... 34 3.3.7 address space identifier (asid) ......................................................................... 34 3.4 tlb functions ............................................................................................................... ... 34 3.4.1 unified tlb (utlb) configuration ................................................................... 34 3.4.2 instruction tlb (itlb) configuration................................................................ 38 3.4.3 address translation method................................................................................ 38 3.5 mmu functions............................................................................................................... .41 3.5.1 mmu hardware management ............................................................................. 41 3.5.2 mmu software management .............................................................................. 41 rev. 5.0, 04/01, page viii of 12 3.5.3 mmu instruction (ldtlb)................................................................................. 41 3.5.4 hardware itlb miss handling ........................................................................... 42 3.5.5 avoiding synonym problems .............................................................................. 43 3.6 mmu exceptions.............................................................................................................. 44 3.6.1 instruction tlb multiple hit exception.............................................................. 44 3.6.2 instruction tlb miss exception.......................................................................... 45 3.6.3 instruction tlb protection violation exception ................................................. 46 3.6.4 data tlb multiple hit exception ....................................................................... 47 3.6.5 data tlb miss exception ................................................................................... 47 3.6.6 data tlb protection violation exception........................................................... 48 3.6.7 initial page write exception ................................................................................ 49 3.7 memory-mapped tlb configuration............................................................................... 50 3.7.1 itlb address array ............................................................................................ 51 3.7.2 itlb data array 1............................................................................................... 52 3.7.3 itlb data array 2............................................................................................... 53 3.7.4 utlb address array........................................................................................... 53 3.7.5 utlb data array 1 ............................................................................................. 55 3.7.6 utlb data array 2 ............................................................................................. 56 section 4 caches .................................................................................................................. 57 4.1 overview.................................................................................................................... ....... 57 4.1.1 features................................................................................................................ 57 4.1.2 register configuration......................................................................................... 58 4.2 register descriptions ....................................................................................................... .58 4.3 operand cache (oc)......................................................................................................... 6 1 4.3.1 configuration ....................................................................................................... 61 4.3.2 read operation .................................................................................................... 62 4.3.3 write operation ................................................................................................... 63 4.3.4 write-back buffer ............................................................................................... 65 4.3.5 write-through buffer.......................................................................................... 65 4.3.6 ram mode .......................................................................................................... 65 4.3.7 oc index mode ................................................................................................... 66 4.3.8 coherency between cache and external memory ............................................... 67 4.3.9 prefetch operation ............................................................................................... 67 4.4 instruction cache (ic)...................................................................................................... .68 4.4.1 configuration ....................................................................................................... 68 4.4.2 read operation .................................................................................................... 69 4.4.3 ic index mode ..................................................................................................... 70 4.5 memory-mapped cache configuration ............................................................................ 70 4.5.1 ic address array ................................................................................................. 70 4.5.2 ic data array....................................................................................................... 71 4.5.3 oc address array................................................................................................ 72 4.5.4 oc data array ..................................................................................................... 74 rev. 5.0, 04/01, page ix of 12 4.6 store queues ................................................................................................................ ..... 75 4.6.1 sq configuration................................................................................................. 75 4.6.2 sq writes............................................................................................................. 75 4.6.3 transfer to external memory............................................................................... 75 4.6.4 sq protection....................................................................................................... 77 section 5 exceptions ........................................................................................................... 79 5.1 overview.................................................................................................................... ....... 79 5.1.1 features................................................................................................................ 79 5.1.2 register configuration......................................................................................... 79 5.2 register descriptions ....................................................................................................... .80 5.3 exception handling functions.......................................................................................... 81 5.3.1 exception handling flow .................................................................................... 81 5.3.2 exception handling vector addresses ................................................................ 81 5.4 exception types and priorities ......................................................................................... 82 5.5 exception flow .............................................................................................................. ... 85 5.5.1 exception flow .................................................................................................... 85 5.5.2 exception source acceptance.............................................................................. 86 5.5.3 exception requests and bl bit ........................................................................... 88 5.5.4 return from exception handling......................................................................... 88 5.6 description of exceptions................................................................................................. 88 5.6.1 resets ................................................................................................................... 8 8 5.6.2 general exceptions .............................................................................................. 95 5.6.3 interrupts.............................................................................................................. 10 9 5.6.4 priority order with multiple exceptions.............................................................. 112 5.7 usage notes ................................................................................................................. ..... 113 5.8 restrictions ................................................................................................................ ....... 114 section 6 floating-point unit .......................................................................................... 115 6.1 overview.................................................................................................................... ....... 115 6.2 data formats................................................................................................................ ..... 115 6.2.1 floating-point format.......................................................................................... 115 6.2.2 non-numbers (nan) ........................................................................................... 117 6.2.3 denormalized numbers ....................................................................................... 118 6.3 registers................................................................................................................... ......... 119 6.3.1 floating-point registers....................................................................................... 119 6.3.2 floating-point status/control register (fpscr)................................................. 121 6.3.3 floating-point communication register (fpul) ................................................ 122 6.4 rounding.................................................................................................................... ....... 122 6.5 floating-point exceptions................................................................................................. 12 3 6.6 graphics support functions.............................................................................................. 124 6.6.1 geometric operation instructions........................................................................ 124 6.6.2 pair single-precision data transfer..................................................................... 126 rev. 5.0, 04/01, page x of 12 section 7 instruction set .................................................................................................... 127 7.1 execution environment..................................................................................................... 12 7 7.2 addressing modes ............................................................................................................ 129 7.3 instruction set ............................................................................................................. ...... 133 section 8 pipelining ............................................................................................................ 147 8.1 pipelines................................................................................................................... ......... 147 8.2 parallel-executability...................................................................................................... .. 154 8.3 execution cycles and pipeline stalling ............................................................................ 158 section 9 instruction descriptions .................................................................................. 175 9.1 add ............ add binary ............................................... arithmetic instruction ........... 188 9.2 addc ......... add with carry ........................................ arithmetic instruction ........... 190 9.3 addv ......... add with (v flag) overflow check ........... arithmetic instruction ........... 191 9.4 and ............ and logical .............................................. logical instruction ................ 193 9.5 bf ................ branch if false ........................................... branch instruction ................. 195 9.6 bf/s ............ branch if false with delay slot ................. branch instruction ................. 197 9.7 bra ............ branch ..................................................... branch instruction ................. 199 9.8 braf .......... branch far ............................................... branch instruction ................. 201 9.9 bsr ............. branch to subroutine ............................... branch instruction ................. 202 9.10 bsrf ........... branch to subroutine far ......................... branch instruction ................. 204 9.11 bt ............... branch if true ........................................... branch instruction ................. 206 9.12 bt/s ............ branch if true with delay slot .................. branch instruction ................. 208 9.13 clrmac .... clear mac register .................................. system control instruction.... 210 9.14 clrs ........... clear s bit ................................................ system control instruction.... 211 9.15 clrt .......... clear t bit ................................................ system control instruction.... 212 9.16 cmp/cond ... compare conditionally .............................. arithmetic instruction ........... 213 9.17 div0s ......... divide (step 0) as signed .......................... arithmetic instruction ........... 217 9.18 div0u ........ divide (step 0) as unsigned ..................... arithmetic instruction ........... 218 9.19 div1 ........... divide 1 step ............................................ arithmetic instruction ........... 219 9.20 dmuls.l ... double-length multiply as signed .......... arithmetic instruction ........... 224 9.21 dmulu.l .. double-length multiply as unsigned ...... arithmetic instruction ........... 226 9.22 dt ............... decrement and test ................................... arithmetic instruction ........... 228 9.23 exts .......... extend as signed ..................................... arithmetic instruction ........... 229 9.24 extu .......... extend as unsigned ................................. arithmetic instruction ........... 231 9.25 fabs ........... floating-point absolute value .................. floating-point instruction...... 232 9.26 fadd .......... floating-point add .................................. floating-point instruction...... 233 9.27 fcmp .......... floating-point compare ............................ floating-point instruction...... 235 9.28 fcnvds ..... floating-point convert double to single precision ......................... floating-point instruction...... 238 9.29 fcnvsd ..... floating-point convert single to double precision ......................... floating-point instruction...... 240 9.30 fdiv ........... floating-point divide ............................... floating-point instruction...... 242 rev. 5.0, 04/01, page xi of 12 9.31 fipr ............ floating-point inner product .................... floating-point instruction...... 246 9.32 fldi0 .......... floating-point load immediate 0.0 .......... floating-point instruction...... 248 9.33 fldi1 .......... floating-point load immediate 1.0 .......... floating-point instruction...... 249 9.34 flds ........... floating-point load to system register .... floating-point instruction...... 250 9.35 float ........ floating-point convert from integer .......... floating-point instruction...... 251 9.36 fmac ......... floating-point multiply and accumulate . floating-point instruction...... 253 9.37 fmov ......... floating-point move ................................ floating-point instruction...... 259 9.38 fmov ......... floating-point move extension ................ floating-point instruction...... 263 9.39 fmul ......... floating-point multiply ........................... floating-point instruction...... 266 9.40 fneg .......... floating-point negate value ..................... floating-point instruction...... 268 9.41 frchg ....... fr-bit change .......................................... floating-point instruction...... 269 9.42 fschg ........ sz-bit change .......................................... floating-point instruction...... 270 9.43 fsqrt ........ floating-point square root ..................... floating-point instruction...... 271 9.44 fsts ........... floating-point store system register ........ floating-point instruction...... 274 9.45 fsub ........... floating-point subtract ............................ floating-point instruction...... 275 9.46 ftrc ........... floating-point truncate and convert to integer .......................................................................................... floating-point instruction...... 277 9.47 ftrv .......... floating-point transform vector ............. floating-point instruction...... 280 9.48 jmp ............. jump .......................................................... branch instruction ................. 283 9.49 jsr .............. jump to subroutine .................................. branch instruction ................. 284 9.50 ldc ............ load to control register ............................ system control instruction.... 286 9.51 lds ............. load to fpu system register .................... system control instruction.... 290 9.52 lds ............. load to system register ............................ system control instruction.... 292 9.53 ldtlb ........ load pteh/ptel/ptea to tlb ............. system control instruction.... 294 9.54 mac.l ........ multiply and accumulate long ................ arithmetic instruction ........... 296 9.55 mac.w ....... multiply and accumulate word ............... arithmetic instruction ........... 300 9.56 mov ........... move data ................................................ data transfer instruction....... 303 9.57 mov ........... move constant value ................................ data transfer instruction....... 308 9.58 mov ........... move global data ..................................... data transfer instruction....... 311 9.59 mov ........... move structure data ................................. data transfer instruction....... 314 9.60 mova ........ move effective address ........................... data transfer instruction....... 317 9.61 movca.l .. move with cache block allocation ......... data transfer instruction....... 318 9.62 movt ......... move t bit ............................................... data transfer instruction....... 319 9.63 mul.l ........ multiply long ......................................... arithmetic instruction ........... 320 9.64 muls.w ..... multiply as signed word ........................ arithmetic instruction ........... 321 9.65 mulu.w .... multiply as unsigned word .................... arithmetic instruction ........... 322 9.66 neg ............ negate ...................................................... arithmetic instruction ........... 323 9.67 negc .......... negate with carry .................................... arithmetic instruction ........... 324 9.68 nop ............ no operation ............................................. system control instruction.... 325 9.69 not ............ not-logical complement .......................... logical instruction ................ 326 9.70 ocbi ........... operand cache block invalidate ............... data transfer instruction....... 327 9.71 ocbp .......... operand cache block purge ..................... data transfer instruction....... 329 9.72 ocbwb ...... operand cache block write back ............. data transfer instruction....... 329 rev. 5.0, 04/01, page xii of 12 9.73 or ............... or logical ................................................. logical instruction ................ 330 9.74 pref ........... prefetch data to cache ............................. data transfer instruction....... 332 9.75 rotcl ....... rotate with carry left ............................. shift instruction..................... 333 9.76 rotcr ....... rotate with carry right .......................... shift instruction..................... 334 9.77 rotl .......... rotate left ............................................... shift instruction..................... 335 9.78 rotr .......... rotate right ............................................ shift instruction..................... 336 9.79 rte ............. return from exception ............................. system control instruction.... 337 9.80 rts ............. return from subroutine ........................... branch instruction ................. 339 9.81 sets ........... set s bit ................................................... system control instruction.... 341 9.82 sett ........... set t bit ................................................... system control instruction.... 342 9.83 shad .......... shift arithmetic dynamically .................. shift instruction..................... 343 9.84 shal .......... shift arithmetic left ................................ shift instruction..................... 345 9.85 shar .......... shift arithmetic right .............................. shift instruction..................... 346 9.86 shld .......... shift logical dynamically ........................ shift instruction..................... 347 9.87 shll .......... shift logical left ..................................... shift instruction..................... 349 9.88 shlln ........ n bits shift logical left ............................ shift instruction..................... 350 9.89 shlr .......... shift logical right ................................... shift instruction..................... 352 9.90 shlrn ........ n bits shift logical right .......................... shift instruction..................... 353 9.91 sleep ......... sleep ....................................................... system control instruction.... 355 9.92 stc ............. store control register ............................... system control instruction.... 356 9.93 sts .............. store system register ............................... system control instruction.... 361 9.94 sts .............. store from fpu system register ............... system control instruction.... 363 9.95 sub ............. subtract binary ......................................... arithmetic instruction ........... 365 9.96 subc .......... subtract with carry .................................. arithmetic instruction ........... 366 9.97 subv .......... subtract with (v flag) underflow check.... arithmetic instruction ........... 367 9.98 swap ......... swap register halves ................................ data transfer instruction....... 369 9.99 tas ............. test and set .............................................. logical instruction ................ 371 9.100 trapa ....... trap always ............................................ system control instruction.... 373 9.101 tst ............. test logical .............................................. logical instruction ................ 374 9.102 xor ............ exclusive or logical ................................. logical instruction ................ 376 9.103 xtrct ....... extract .................................................. data transfer instruction....... 378 appendix a instruction codes ........................................................................................ 379 a.1 instruction set by addressing mode................................................................................. 379 appendix b instruction prefetch side effects ............................................................ 393 rev. 5.0, 04/01, page 1 of 394 section 1 overview 1.1 sh-4 features the sh-4 is a 32-bit risc (reduced instruction set computer) microprocessor, featuring object code upward-compatibility with sh-1, sh-2, sh-3, and sh-3e microcomputers. its 16-bit fixed- length instruction set enables program code size to be reduced by almost 50% compared with 32- bit instructions. the features of the sh-4 are summarized in table 1.1. table 1.1 sh-4 features item features architecture ? original hitachi sh architecture ? 32-bit internal data bus ? general register file: ? sixteen 32-bit general registers (and eight 32-bit shadow registers) ? seven 32-bit control registers ? four 32-bit system registers ? risc-type instruction set (upward-compatible with sh series) ? fixed 16-bit instruction length for improved code efficiency ? load-store architecture ? delayed branch instructions ? conditional execution ? c-based instruction set ? superscalar architecture (providing simultaneous execution of two instructions) including fpu ? instruction execution time: maximum 2 instructions/cycle ? virtual address space: 4 gbytes (448-mbyte external memory space) ? space identifier asids: 8 bits, 256 virtual address spaces ? on-chip multiplier ? five-stage pipeline rev. 5.0, 04/01, page 2 of 394 table 1.1 sh-4 features (cont) item features fpu ? on-chip floating-point coprocessor ? supports single-precision (32 bits) and double-precision (64 bits) ? supports ieee754-compliant data types and exceptions ? two rounding modes: round to nearest and round to zero ? handling of denormalized numbers: truncation to zero or interrupt generation for compliance with ieee754 ? floating-point registers: 32 bits 16 words 2 banks (single-precision 16 words or double-precision 8 words) 2 banks ? 32-bit cpu-fpu floating-point communication register (fpul) ? supports fmac (multiply-and-accumulate) instruction ? supports fdiv (divide) and fsqrt (square root) instructions ? supports fldi0/fldi1 (load constant 0/1) instructions ? instruction execution times ? latency (fmac/fadd/fsub/fmul): 3 cycles (single-precision), 8 cycles (double-precision) ? pitch (fmac/fadd/fsub/fmul): 1 cycle (single-precision), 6 cycles (double-precision) note: fmac is supported for single-precision only. ? 3-d graphics instructions (single-precision only): ? 4-dimensional vector conversion and matrix operations (ftrv): 4 cycles (pitch), 7 cycles (latency) ? 4-dimensional vector (fipr) inner product: 1 cycle (pitch), 4 cycles (latency) ? five-stage pipeline memory management unit (mmu) ? 4-gbyte address space, 256 address space identifiers (8-bit asids) ? single virtual mode and multiple virtual memory mode ? supports multiple page sizes: 1 kbyte, 4 kbytes, 64 kbytes, 1 mbyte ? 4-entry fully-associative tlb for instructions ? 64-entry fully-associative tlb for instructions and operands ? supports software-controlled replacement and random-counter replacement algorithm ? tlb contents can be accessed directly by address mapping rev. 5.0, 04/01, page 3 of 394 table 1.1 sh-4 features (cont) item features cache memory ? instruction cache (ic) ? 8 kbytes, direct mapping ? 256 entries, 32-byte block length ? normal mode (8-kbyte cache) ? index mode ? operand cache (oc) ? 16 kbytes, direct mapping ? 512 entries, 32-byte block length ? normal mode (16-kbyte cache) ? index mode ? ram mode (8-kbyte cache + 8-kbyte ram) ? choice of write method (copy-back or write-through) ? single-stage copy-back buffer, single-stage write-through buffer ? cache memory contents can be accessed directly by address mapping (usable as on-chip memory) ? store queue (32 bytes 2 entries) rev. 5.0, 04/01, page 4 of 394 rev. 5.0, 04/01, page 5 of 394 section 2 programming model 2.1 data formats the data formats handled by the sh-4 are shown in figure 2.1. byte (8 bits) word (16 bits) longword (32 bits) single-precision floating-point (32 bits) double-precision floating-point (64 bits) 0 7 0 15 0 31 0 31 30 22 fraction exp s 0 63 62 51 exp s fraction figure 2.1 data formats rev. 5.0, 04/01, page 6 of 394 2.2 register configuration 2.2.1 privileged mode and banks processor modes: the sh-4 has two processor modes, user mode and privileged mode. the sh-4 normally operates in user mode, and switches to privileged mode when an exception occurs or an interrupt is accepted. there are four kinds of registers?general registers, system registers, control registers, and floating-point registers?and the registers that can be accessed differ in the two processor modes. general registers: there are 16 general registers, designated r0 to r15. general registers r0 to r7 are banked registers which are switched by a processor mode change. in privileged mode, the register bank bit (rb) in the status register (sr) defines which banked register set is accessed as general registers, and which set is accessed only through the load control register (ldc) and store control register (stc) instructions. when the rb bit is 1 (that is, when bank 1 is selected), the 16 registers comprising bank 1 general registers r0_bank1 to r7_bank1 and non-banked general registers r8 to r15 can be accessed as general registers r0 to r15. in this case, the eight registers comprising bank 0 general registers r0_bank0 to r7_bank0 are accessed by the ldc/stc instructions. when the rb bit is 0 (that is, when bank 0 is selected), the 16 registers comprising bank 0 general registers r0_bank0 to r7_bank0 and non-banked general registers r8 to r15 can be accessed as general registers r0 to r15. in this case, the eight registers comprising bank 1 general registers r0_bank1 to r7_bank1 are accessed by the ldc/stc instructions. in user mode, the 16 registers comprising bank 0 general registers r0_bank0 to r7_bank0 and non-banked general registers r8 to r15 can be accessed as general registers r0 to r15. the eight registers comprising bank 1 general registers r0_bank1 to r7_bank1 cannot be accessed. control registers: control registers comprise the global base register (gbr) and status register (sr), which can be accessed in both processor modes, and the saved status register (ssr), saved program counter (spc), vector base register (vbr), saved general register 15 (sgr), and debug base register (dbr), which can only be accessed in privileged mode. some bits of the status register (such as the rb bit) can only be accessed in privileged mode. system registers: system registers comprise the multiply-and-accumulate registers (mach/macl), the procedure register (pr), the program counter (pc), the floating-point status/control register (fpscr), and the floating-point communication register (fpul). access to these registers does not depend on the processor mode. rev. 5.0, 04/01, page 7 of 394 floating-point registers: there are thirty-two floating-point registers, fr0?fr15 and xf0? xf15. fr0?fr15 and xf0?xf15 can be assigned to either of two banks (fpr0_bank0? fpr15_bank0 or fpr0_bank1?fpr15_bank1). fr0?fr15 can be used as the eight registers dr0/2/4/6/8/10/12/14 (double-precision floating- point registers, or pair registers) or the four registers fv0/4/8/12 (register vectors), while xf0? xf15 can be used as the eight registers xd0/2/4/6/8/10/12/14 (register pairs) or register matrix xmtrx. register values after a reset are shown in table 2.1. table 2.1 initial register values type registers initial value* general registers r0_bank0?r7_bank0, r0_bank1?r7_bank1, r8?r15 undefined sr md bit = 1, rb bit = 1, bl bit = 1, fd bit = 0, i3?i0 = 1111 (h'f), reserved bits = 0, others undefined gbr, ssr, spc, sgr, dbr undefined control registers vbr h'00000000 mach, macl, pr, fpul undefined pc h'a0000000 system registers fpscr h'00040001 floating-point registers fr0?fr15, xf0?xf15 undefined note: * initialized by a power-on reset and manual reset. the register configuration in each processor is shown in figure 2.2. switching between user mode and privileged mode is controlled by the processor mode bit (md) in the status register. rev. 5.0, 04/01, page 8 of 394 31 0 r0 _ bank0* 1, * 2 r1 _ bank0* 2 r2 _ bank0* 2 r3 _ bank0* 2 r4 _ bank0* 2 r5 _ bank0* 2 r6 _ bank0* 2 r7 _ bank0* 2 r8 r9 r10 r11 r12 r13 r14 r15 sr gbr mach macl pr pc (a) register configuration in user mode 31 0 r0 _ bank1* 1, * 3 r1 _ bank1* 3 r2 _ bank1* 3 r3 _ bank1* 3 r4 _ bank1* 3 r5 _ bank1* 3 r6 _ bank1* 3 r7 _ bank1* 3 r8 r9 r10 r11 r12 r13 r14 r15 r0 _ bank0* 1, * 4 r1 _ bank0* 4 r2 _ bank0* 4 r3 _ bank0* 4 r4 _ bank0* 4 r5 _ bank0* 4 r6 _ bank0* 4 r7 _ bank0* 4 (b) register configuration in privileged mode (rb = 1) gbr mach macl vbr pr sr ssr pc spc 31 0 r0 _ bank1* 1, * 3 r1 _ bank1* 3 r2 _ bank1* 3 r3 _ bank1* 3 r4 _ bank1* 3 r5 _ bank1* 3 r6 _ bank1* 3 r7 _ bank1* 3 r8 r9 r10 r11 r12 r13 r14 r15 r0 _ bank0* 1, * 4 r1 _ bank0* 4 r2 _ bank0* 4 r3 _ bank0* 4 r4 _ bank0* 4 r5 _ bank0* 4 r6 _ bank0* 4 r7 _ bank0* 4 (c) register configuration in privileged mode (rb = 0) gbr mach macl vbr pr sr ssr pc spc sgr dbr sgr dbr notes: 1. the r0 register is used as the index register in indexed register-indirect addressing mode and indexed gbr indirect addressing mode. 2. banked registers 3. banked registers accessed as general registers when the rb bit is set to 1 in the sr register. accessed only by ldc/stc instructions when the rb bit is cleared to 0. 4. banked registers accessed as general registers when the rb bit is cleared to 0 in the sr register. accessed only by ldc/stc instructions when the rb bit is set to 1. figure 2.2 cpu register configuration in each processor mode rev. 5.0, 04/01, page 9 of 394 2.2.2 general registers figure 2.3 shows the relationship between the processor modes and general registers. the sh-4 has twenty-four 32-bit general registers (r0_bank0?r7_bank0, r0_bank1?r7_bank1, and r8?r15). however, only 16 of these can be accessed as general registers r0?r15 in one processor mode. the sh-4 has two processor modes, user mode and privileged mode, in which r0?r7 are assigned as shown below. ? r0_bank0?r7_bank0 in user mode (sr.md = 0), r0?r7 are always assigned to r0_bank0?r7_bank0. in privileged mode (sr.md = 1), r0?r7 are assigned to r0_bank0?r7_bank0 only when sr.rb = 0. ? r0_bank1?r7_bank1 in user mode, r0_bank1?r7_bank1 cannot be accessed. in privileged mode, r0?r7 are assigned to r0_bank1?r7_bank1 only when sr.rb = 1. rev. 5.0, 04/01, page 10 of 394 sr.md = 0 or (sr.md = 1, sr.rb = 0) r0_bank0 r1_bank0 r2_bank0 r3_bank0 r4_bank0 r5_bank0 r6_bank0 r7_bank0 r0_bank0 r1_bank0 r2_bank0 r3_bank0 r4_bank0 r5_bank0 r6_bank0 r7_bank0 r0_bank1 r1_bank1 r2_bank1 r3_bank1 r4_bank1 r5_bank1 r6_bank1 r7_bank1 r0_bank1 r1_bank1 r2_bank1 r3_bank1 r4_bank1 r5_bank1 r6_bank1 r7_bank1 r0 r1 r2 r3 r4 r5 r6 r7 r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 r8 r9 r10 r11 r12 r13 r14 r15 r8 r9 r10 r11 r12 r13 r14 r15 (sr.md = 1, sr.rb = 1) figure 2.3 general registers programming note: as the user?s r0?r7 are assigned to r0_bank0?r7_bank0, and after an exception or interrupt r0?r7 are assigned to r0_bank1?r7_bank1, it is not necessary for the interrupt handler to save and restore the user?s r0?r7 (r0_bank0?r7_bank0). after a reset, the values of r0_bank0?r7_bank0, r0_bank1?r7_bank1, and r8?r15 are undefined. rev. 5.0, 04/01, page 11 of 394 2.2.3 floating-point registers figure 2.4 shows the floating-point registers. there are thirty-two 32-bit floating-point registers, divided into two banks (fpr0_bank0?fpr15_bank0 and fpr0_bank1?fpr15_bank1). these 32 registers are referenced as fr0?fr15, dr0/2/4/6/8/10/12/14, fv0/4/8/12, xf0?xf15, xd0/2/4/6/8/10/12/14, or xmtrx. the correspondence between fprn_banki and the reference name is determined by the fr bit in fpscr (see figure 2.4). ? floating-point registers, fprn_banki (32 registers) fpr0_bank0, fpr1_bank0, fpr2_bank0, fpr3_bank0, fpr4_bank0, fpr5_bank0, fpr6_bank0, fpr7_bank0, fpr8_bank0, fpr9_bank0, fpr10_bank0, fpr11_bank0, fpr12_bank0, fpr13_bank0, fpr14_bank0, fpr15_bank0 fpr0_bank1, fpr1_bank1, fpr2_bank1, fpr3_bank1, fpr4_bank1, fpr5_bank1, fpr6_bank1, fpr7_bank1, fpr8_bank1, fpr9_bank1, fpr10_bank1, fpr11_bank1, fpr12_bank1, fpr13_bank1, fpr14_bank1, fpr15_bank1 ? single-precision floating-point registers, fri (16 registers) when fpscr.fr = 0, fr0?fr15 are assigned to fpr0_bank0?fpr15_bank0. when fpscr.fr = 1, fr0?fr15 are assigned to fpr0_bank1?fpr15_bank1. ? double-precision floating-point registers or single-precision floating-point register pairs, dri (8 registers): a dr register comprises two fr registers. dr0 = {fr0, fr1}, dr2 = {fr2, fr3}, dr4 = {fr4, fr5}, dr6 = {fr6, fr7}, dr8 = {fr8, fr9}, dr10 = {fr10, fr11}, dr12 = {fr12, fr13}, dr14 = {fr14, fr15} ? single-precision floating-point vector registers, fvi (4 registers): an fv register comprises four fr registers fv0 = {fr0, fr1, fr2, fr3}, fv4 = {fr4, fr5, fr6, fr7}, fv8 = {fr8, fr9, fr10, fr11}, fv12 = {fr12, fr13, fr14, fr15} ? single-precision floating-point extended registers, xfi (16 registers) when fpscr.fr = 0, xf0?xf15 are assigned to fpr0_bank1?fpr15_bank1. when fpscr.fr = 1, xf0?xf15 are assigned to fpr0_bank0?fpr15_bank0. ? single-precision floating-point extended register pairs, xdi (8 registers): an xd register comprises two xf registers xd0 = {xf0, xf1}, xd2 = {xf2, xf3}, xd4 = {xf4, xf5}, xd6 = {xf6, xf7}, xd8 = {xf8, xf9}, xd10 = {xf10, xf11}, xd12 = {xf12, xf13}, xd14 = {xf14, xf15} rev. 5.0, 04/01, page 12 of 394 ? single-precision floating-point extended register matrix, xmtrx: xmtrx comprises all 16 xf registers xmtrx = xf0 xf4 xf8 xf12 xf1 xf5 xf9 xf13 xf2 xf6 xf10 xf14 xf3 xf7 xf11 xf15 fpr0_bank0 fpr1_bank0 fpr2_bank0 fpr3_bank0 fpr4_bank0 fpr5_bank0 fpr6_bank0 fpr7_bank0 fpr8_bank0 fpr9_bank0 fpr10_bank0 fpr11_bank0 fpr12_bank0 fpr13_bank0 fpr14_bank0 fpr15_bank0 xf0 xf1 xf2 xf3 xf4 xf5 xf6 xf7 xf8 xf9 xf10 xf11 xf12 xf13 xf14 xf15 fr0 fr1 fr2 fr3 fr4 fr5 fr6 fr7 fr8 fr9 fr10 fr11 fr12 fr13 fr14 fr15 dr0 dr2 dr4 dr6 dr8 dr10 dr12 dr14 fv0 fv4 fv8 fv12 xd0 xmtrx xd2 xd4 xd6 xd8 xd10 xd12 xd14 fpr0_bank1 fpr1_bank1 fpr2_bank1 fpr3_bank1 fpr4_bank1 fpr5_bank1 fpr6_bank1 fpr7_bank1 fpr8_bank1 fpr9_bank1 fpr10_bank1 fpr11_bank1 fpr12_bank1 fpr13_bank1 fpr14_bank1 fpr15_bank1 xf0 xf1 xf2 xf3 xf4 xf5 xf6 xf7 xf8 xf9 xf10 xf11 xf12 xf13 xf14 xf15 fr0 fr1 fr2 fr3 fr4 fr5 fr6 fr7 fr8 fr9 fr10 fr11 fr12 fr13 fr14 fr15 dr0 dr2 dr4 dr6 dr8 dr10 dr12 dr14 fv0 fv4 fv8 fv12 xd0 xmtrx xd2 xd4 xd6 xd8 xd10 xd12 xd14 fpscr.fr = 0 fpscr.fr = 1 figure 2.4 floating-point registers rev. 5.0, 04/01, page 13 of 394 programming note: after a reset, the values of fpr0_bank0?fpr15_bank0 and fpr0_bank1?fpr15_bank1 are undefined. 2.2.4 control registers status register, sr (32 bits, privilege protection, initial value = 0111 0000 0000 0000 0000 00xx 1111 00xx (x: undefined)) 31 30 29 28 27 16 15 14 10 9 8 7 4 3 2 1 0 ? md rb bl ? fd ? m q imask ? s t note: ?: reserved. these bits are always read as 0, and should only be written with 0. ? md: processor mode md = 0: user mode (some instructions cannot be executed, and some resources cannot be accessed) md = 1: privileged mode ? rb: general register bank specifier in privileged mode (set to 1 by a reset, exception, or interrupt) rb = 0: r0_bank0?r7_bank0 are accessed as general registers r0?r7. (r0_bank1? r7_bank1 can be accessed using ldc/stc r0_bank?r7_bank instructions.) rb = 1: r0_bank1?r7_bank1 are accessed as general registers r0?r7. (r0_bank0? r7_bank0 can be accessed using ldc/stc r0_bank?r7_bank instructions.) ? bl: exception/interrupt block bit (set to 1 by a reset, exception, or interrupt) bl = 1: interrupt requests are masked. if a general exception other than a user break occurs while bl = 1, the processor switches to the reset state. ? fd: fpu disable bit (cleared to 0 by a reset) fd = 1: an fpu instruction causes a general fpu disable exception, and if the fpu instruction is in a delay slot, a slot fpu disable exception is generated. (fpu instructions: h'f*** instructions, ldc(.l)/sts(.l) instructions for fpul/fpscr) ? m, q: used by the div0s, div0u, and div1 instructions. ? imask: interrupt mask level external interrupts of a same level or a lower level than imask are masked. ? s: specifies a saturation operation for a mac instruction. ? t: true/false condition or carry/borrow bit rev. 5.0, 04/01, page 14 of 394 saved status register, ssr (32 bits, privilege protection, initial value undefined): the current contents of sr are saved to ssr in the event of an exception or interrupt. saved program counter, spc (32 bits, privilege protection, initial value undefined): the address of an instruction at which an interrupt or exception occurs is saved to spc. global base register, gbr (32 bits, initial value undefined): gbr is referenced as the base address in a gbr-referencing mov instruction. vector base register, vbr (32 bits, privilege protection, initial value = h'0000 0000): vbr is referenced as the branch destination base address in the event of an exception or interrupt. for details, see section 5, exceptions. saved general register 15, sgr (32 bits, privilege protection, initial value undefined): the contents of r15 are saved to sgr in the event of an exception or interrupt. debug base register, dbr (32 bits, privilege protection, initial value undefined): when the user break debug function is enabled (brcr.ubde = 1), dbr is referenced as the user break handler branch destination address instead of vbr. 2.2.5 system registers multiply-and-accumulate register high, mach (32 bits, initial value undefined) multiply-and-accumulate register low, macl (32 bits, initial value undefined) mach/macl is used for the added value in a mac instruction, and to store a mac instruction or mul operation result. procedure register, pr (32 bits, initial value undefined): the return address is stored in pr in a subroutine call using a bsr, bsrf, or jsr instruction, and pr is referenced by the subroutine return instruction (rts). program counter, pc (32 bits, initial value = h'a000 0000): pc indicates the instruction fetch address. rev. 5.0, 04/01, page 15 of 394 floating-point status/control register, fpscr (32 bits, initial value = h'0004 0001) 31 22 21 20 19 18 17 12 11 7 6 2 1 0 ? fr sz pr dn cause enable flag rm note: ?: reserved. these bits are always read as 0, and should only be written with 0. ? fr: floating-point register bank fr = 0: fpr0_bank0?fpr15_bank0 are assigned to fr0?fr15; fpr0_bank1? fpr15_bank1 are assigned to xf0?xf15. fr = 1: fpr0_bank0?fpr15_bank0 are assigned to xf0?xf15; fpr0_bank1? fpr15_bank1 are assigned to fr0?fr15. ? sz: transfer size mode sz = 0: the data size of the fmov instruction is 32 bits. sz = 1: the data size of the fmov instruction is a 32-bit register pair (64 bits). ? pr: precision mode pr = 0: floating-point instructions are executed as single-precision operations. pr = 1: floating-point instructions are executed as double-precision operations (the result of instructions for which double-precision is not supported is undefined). do not set sz and pr to 1 simultaneously; this setting is reserved. [sz, pr = 11]: reserved (fpu operation instruction is undefined.) ? dn: denormalization mode dn = 0: a denormalized number is treated as such. dn = 1: a denormalized number is treated as zero. ? cause: fpu exception cause field ? enable: fpu exception enable field ? flag: fpu exception flag field fpu error (e) invalid operation (v) division by zero (z) overflow (o) underflow (u) inexact (i) cause fpu exception cause field bit 17 bit 16 bit 15 bit 14 bit 13 bit 12 enable fpu exception enable field none bit 11 bit 10 bit 9 bit 8 bit 7 flag fpu exception flag field none bit 6 bit 5 bit 4 bit 3 bit 2 rev. 5.0, 04/01, page 16 of 394 when an fpu operation instruction is executed, the fpu exception cause field is cleared to zero first. when the next fpu exception is occured, the corresponding bits in the fpu exception cause field and fpu exception flag field are set to 1. the fpu exception flag field holds the status of the exception generated after the field was last cleared. ? rm: rounding mode rm = 00: round to nearest rm = 01: round to zero rm = 10: reserved rm = 11: reserved ? bits 22 to 31: reserved floating-point communication register, fpul (32 bits, initial value undefined): data transfer between fpu registers and cpu registers is carried out via the fpul register. programming note: when sz = 1 and big endian mode is selected, fmov can be used for double-precision floating-point load or store operations. in little endian mode, two 32-bit data size moves must be executed, with sz = 0, to load or store a double-precision floating-point number. 2.3 memory-mapped registers the control registers are double-mapped to the following two memory areas. all registers have two addresses. h'1c00 0000?h'1fff ffff h'fc00 0000?h'ffff ffff these two areas are used as follows. ? h'1c00 0000?h'1fff ffff this area must be accessed using the mmu's address translation function. a memory-mapped register can be accessed by setting the page number of this area in the corresponding field of the tlb. operation is not guaranteed if this area is accessed without using the mmu's address translation function. ? h'fc00 0000?h'ffff ffff access to area h'fc00 0000?h'ffff ffff in user mode will cause an address error. memory- mapped registers can be referenced in user mode by means of access that involves address translation. note: do not access undefined locations in either area the operation of an access to an undefined location is undefined. also, memory-mapped registers must be accessed using a fixed data size. the operation of an access using an invalid data size is undefined. rev. 5.0, 04/01, page 17 of 394 2.4 data format in registers register operands are always longwords (32 bits). when a memory operand is only a byte (8 bits) or a word (16 bits), it is sign-extended into a longword when loaded into a register. 31 0 longword 2.5 data formats in memory memory data formats are classified into bytes, words, and longwords. memory can be accessed in 8-bit byte, 16-bit word, or 32-bit longword form. a memory operand less than 32 bits in length is sign-extended before being loaded into a register. a word operand must be accessed starting from a word boundary (even address of a 2-byte unit: address 2n), and a longword operand starting from a longword boundary (even address of a 4-byte unit: address 4n). an address error will result if this rule is not observed. a byte operand can be accessed from any address. big endian or little endian byte order can be selected for the data format. the endian should be set with the md5 external pin in a power-on reset. big endian is selected when the md5 pin is low, and little endian when high. the endian cannot be changed dynamically. bit positions are numbered left to right from most-significant to least-significant. thus, in a 32-bit longword, the leftmost bit, bit 31, is the most significant bit and the rightmost bit, bit 0, is the least significant bit. the data format in memory is shown in figure 2.5. address a a 70707070 31 15 0 15 0 31 0 15 0 31 0 23 15 7 0 a + 1 a + 2 a + 3 byte 0 word 0 longword word 1 byte 1 byte 2 byte 3 a + 11 70707070 31 15 0 23 15 7 0 a + 10 a + 9 a + 8 byte 3 word 1 longword word 0 byte 2 byte 1 byte 0 address a + 4 address a + 8 address a + 8 address a + 4 address a big endian little endian figure 2.5 data formats in memory rev. 5.0, 04/01, page 18 of 394 note: the sh-4 does not support endian conversion for the 64-bit data format. therefore, if double-precision floating-point format (64-bit) access is performed in little endian mode, the upper and lower 32 bits will be reversed. 2.6 processor states the sh-4 has five processor states: the reset state, exception-handling state, bus-released state, program execution state, and power-down state. reset state: in this state the cpu is reset. there are two kinds of reset state, power-on reset and manual reset, defined as shown in table 2.6 according to the relevant external pin states. table 2.6 reset state power-on reset state manual reset state sh7750 series reset = 0 and mreset = 1 reset = 0 and mreset = 0 sh7751 reset = 0 reset = 1 and mreset = 0 for more information on resets, see section 5, exceptions. in the power-on reset state, the internal state of the cpu and the on-chip peripheral module registers are initialized. in the manual reset state, the internal state of the cpu and registers of on- chip peripheral modules other than the bus state controller (bsc) are initialized. since the bus state controller (bsc) is not initialized in the manual reset state, refreshing operations continue. refer to the register configurations in the relevant sections for further details. exception-handling state: this is a transient state during which the cpu?s processor state flow is altered by a reset, general exception, or interrupt exception handling source. in the case of a reset, the cpu branches to address h'a000 0000 and starts executing the user- coded exception handling program. in the case of a general exception or interrupt, the program counter (pc) contents are saved in the saved program counter (spc), the status register (sr) contents are saved in the saved status register (ssr), and the r15 contents are saved in saved general register 15 (sgr). the cpu branches to the start address of the user-coded exception service routine found from the sum of the contents of the vector base address and the vector offset. see section 5, exceptions, for more information on resets, general exceptions, and interrupts. program execution state: in this state the cpu executes program instructions in sequence. rev. 5.0, 04/01, page 19 of 394 power-down state: in the power-down state, cpu operation halts and power consumption is reduced. the power-down state is entered by executing a sleep instruction. there are two modes in the power-down state: sleep mode and standby mode. for details, see hardware manual, power- down modes. bus-released state: in this state the cpu has released the bus to a device that requested it. sh7750 series state transitions are shown in figure 2.6, and sh7751 state transitions in figure 2.7. reset = 0, mreset = 1 reset = 1, mreset = 0 reset = 1, mreset = 1 power-on reset state manual reset state program execution state bus-released state exception-handling state interrupt interrupt end of exception transition processing bus request clearance exception interrupt bus request clearance bus request bus request clearance sleep instruction with stby bit cleared sleep instruction with stby bit set from any state when reset = 0 and mreset = 1 from any state when reset = 0 and mreset = 0 reset state power-down state bus request bus request standby mode sleep mode figure 2.6 processor state transitions (sh7750 series) rev. 5.0, 04/01, page 20 of 394 reset = 0 reset = 1, mreset = 1 reset = 1 power-on reset state manual reset state program execution state bus-released state exception-handling state interrupt interrupt end of exception transition processing bus request clearance exception interrupt bus request clearance bus request bus request clearance sleep instruction with stby bit cleared sleep instruction with stby bit set from any state when reset = 0 from any state when reset = 1 and mreset = 0 reset state power-down state bus request bus request standby mode sleep mode figure 2.7 processor state transitions (sh7751) 2.7 processor modes there are two processor modes: user mode and privileged mode. the processor mode is determined by the processor mode bit (md) in the status register (sr). user mode is selected when the md bit is cleared to 0, and privileged mode when the md bit is set to 1. when the reset state or exception state is entered, the md bit is set to 1. when exception handling ends, the md bit is cleared to 0 and user mode is entered. there are certain registers and bits which can only be accessed in privileged mode. rev. 5.0, 04/01, page 21 of 394 section 3 memory management unit (mmu) 3.1 overview 3.1.1 features the sh-4 can handle 29-bit external memory space from an 8-bit address space identifier and 32- bit logical (virtual) address space. address translation from virtual address to physical address is performed using the memory management unit (mmu) built into the sh-4. the mmu performs high-speed address translation by caching user-created address translation table information in an address translation buffer (translation lookaside buffer: tlb). the sh-4 has four instruction tlb (itlb) entries and 64 unified tlb (utlb) entries. utlb copies are stored in the itlb by hardware. a paging system is used for address translation, with support for four page sizes (1, 4, and 64 kbytes, and 1 mbyte). it is possible to set the virtual address space access right and implement storage protection independently for privileged mode and user mode. 3.1.2 role of the mmu the mmu was conceived as a means of making efficient use of physical memory. as shown in figure 3.1, when a process is smaller in size than the physical memory, the entire process can be mapped onto physical memory, but if the process increases in size to the point where it does not fit into physical memory, it becomes necessary to divide the process into smaller parts, and map the parts requiring execution onto physical memory on an ad hoc basis ((1)). having this mapping onto physical memory executed consciously by the process itself imposes a heavy burden on the process. the virtual memory system was devised as a means of handling all physical memory mapping to reduce this burden ((2)). with a virtual memory system, the size of the available virtual memory is much larger than the actual physical memory, and processes are mapped onto this virtual memory. thus processes only have to consider their operation in virtual memory, and mapping from virtual memory to physical memory is handled by the mmu. the mmu is normally managed by the os, and physical memory switching is carried out so as to enable the virtual memory required by a task to be mapped smoothly onto physical memory. physical memory switching is performed via secondary storage, etc. the virtual memory system that came into being in this way works to best effect in a time sharing system (tss) that allows a number of processes to run simultaneously ((3)). running a number of processes in a tss did not increase efficiency since each process had to take account of physical memory mapping. efficiency is improved and the load on each process reduced by the use of a virtual memory system ((4)). in this system, virtual memory is allocated to each process. the task of the mmu is to map a number of virtual memory areas onto physical memory in an efficient manner. it is also provided with memory protection functions to prevent a process from inadvertently accessing another process?s physical memory. rev. 5.0, 04/01, page 22 of 394 when address translation from virtual memory to physical memory is performed using the mmu, it may happen that the translation information has not been recorded in the mmu, or the virtual memory of a different process is accessed by mistake. in such cases, the mmu will generate an exception, change the physical memory mapping, and record the new address translation information. although the functions of the mmu could be implemented by software alone, having address translation performed by software each time a process accessed physical memory would be very inefficient. for this reason, a buffer for address translation (the translation lookaside buffer: tlb) is provided in hardware, and frequently used address translation information is placed here. the tlb can be described as a cache for address translation information. however, unlike a cache, if address translation fails?that is, if an exception occurs?switching of the address translation information is normally performed by software. thus memory management can be performed in a flexible manner by software. there are two methods by which the mmu can perform mapping from virtual memory to physical memory: the paging method, using fixed-length address translation, and the segment method, using variable-length address translation. with the paging method, the unit of translation is a fixed-size address space called a page (usually from 1 to 64 kbytes in size). in the following descriptions, the address space in virtual memory in the sh-4 is referred to as virtual address space, and the address space in physical memory as physical address space. rev. 5.0, 04/01, page 23 of 394 (2) process 1 process 1 physical memory process 1 process 2 process 3 virtual memory process 1 process 1 process 2 process 3 mmu mmu (4) (3) (1) physical memory physical memory physical memory physical memory virtual memory figure 3.1 role of the mmu rev. 5.0, 04/01, page 24 of 394 3.1.3 register configuration the mmu registers are shown in table 3.1. table 3.1 mmu registers name abbrevia- tion r/w initial value* 1 p4 address* 2 area 7 address* 2 access size page table entry high register pteh r/w undefined h'ff00 0000 h'1f00 0000 32 page table entry low register ptel r/w undefined h'ff00 0004 h'1f00 0004 32 page table entry assistance register ptea r/w undefined h'ff00 0034 h'1f00 0034 32 translation table base register ttb r/w undefined h'ff00 0008 h'1f00 0008 32 tlb exception address register tea r/w undefined h'ff00 000c h'1f00 000c 32 mmu control register mmucr r/w h'0000 0000 h'ff00 0010 h'1f00 0010 32 notes: 1. the initial value is the value after a power-on reset or manual reset. 2. this is the address when using the virtual/physical address space p4 area. the area 7 address is the address used when making an access from physical address space area 7 using the tlb. 3.1.4 caution operation is not guaranteed if an area designated as a reserved area in this manual is accessed. rev. 5.0, 04/01, page 25 of 394 3.2 register descriptions there are six mmu-related registers. 31 10 9 8 70 vpn ppn ? ? asid 1. pteh 31 30 29 28 10 9 8 7 65 4 3 2 1 0 ??? ?vszprszcdsh wt 2. ptel 31 4 3 20 tc sa 3. ptea 31 0 ttb 4. ttb 31 virtual address at which mmu exception or address error occurred 5. tea 31 26 24 23 18 17 16 15 10 9 8 7 6 5 4 3 2 1 0 lrui ? ? ? ? urc sqmd sv?????ti?at 6. mmucr ? indicates a reserved bit: the write value must be 0, and a read will return an undefined value. urb 25 figure 3.2 mmu-related registers rev. 5.0, 04/01, page 26 of 394 1. page table entry high register (pteh): longword access to pteh can be performed from h'ff00 0000 in the p4 area and h'1f00 0000 in area 7. pteh consists of the virtual page number (vpn) and address space identifier (asid). when an mmu exception or address error exception occurs, the vpn of the virtual address at which the exception occurred is set in the vpn field by hardware. vpn varies according to the page size, but the vpn set by hardware when an exception occurs consists of the upper 22 bits of the virtual address which caused the exception. vpn setting can also be carried out by software. the number of the currently executing process is set in the asid field by software. asid is not updated by hardware. vpn and asid are recorded in the utlb by means of the ldltb instruction. 2. page table entry low register (ptel): longword access to ptel can be performed from h'ff00 0004 in the p4 area and h'1f00 0004 in area 7. ptel is used to hold the physical page number and page management information to be recorded in the utlb by means of the ldtlb instruction. the contents of this register are not changed unless a software directive is issued. 3. page table entry assistance register (ptea): longword access to ptea can be performed from h'ff00 0034 in the p4 area and h'1f00 0034 in area 7. ptel is used to store assistance bits for pcmcia access to the utlb by means of the ldtlb instruction. in the sh7750s and sh7751, when access to a pcmcia interface area is performed from the cpu with mmucr.at = 0, access is always performed using the values of the sa bit and tc bit in this register. in the sh7750, it is not possible to access a pcmcia interface area with mmucr.at = 0. in the sh7750 series and sh7751, access to a pcmcia interface area by the dmac is always performed using the dmac?s chcrn.ssan, chcrn.dsan, chcrn.stc, and chcrn.dtc values. see the dmac section in hardware manual for details. the contents of this register are not changed unless a software directive is issued. 4. translation table base register (ttb): longword access to ttb can be performed from h'ff00 0008 in the p4 area and h'1f00 0008 in area 7. ttb is used, for example, to hold the base address of the currently used page table. the contents of ttb are not changed unless a software directive is issued. this register can be freely used by software. 5. tlb exception address register (tea): longword access to tea can be performed from h'ff00 000c in the p4 area and h'1f00 000c in area 7. after an mmu exception or address error exception occurs, the virtual address at which the exception occurred is set in tea by hardware. the contents of this register can be changed by software. 6. mmu control register (mmucr): mmucr contains the following bits: lrui: least recently used itlb urb: utlb replace boundary urc: utlb replace counter sqmd: store queue mode bit rev. 5.0, 04/01, page 27 of 394 sv: single virtual mode bit ti: tlb invalidate at: address translation bit longword access to mmucr can be performed from h'ff00 0010 in the p4 area and h'1f00 0010 in area 7. the individual bits perform mmu settings as shown below. therefore, mmucr rewriting should be performed by a program in the p1 or p2 area. after mmucr is updated, an instruction that performs data access to the p0, p3, u0, or store queue area should be located at least four instructions after the mmucr update instruction. also, a branch instruction to the p0, p3, or u0 area should be located at least eight instructions after the mmucr update instruction. mmucr contents can be changed by software. the lrui bits and urc bits may also be updated by hardware. ? lrui: the lru (least recently used) method is used to decide the itlb entry to be replaced in the event of an itlb miss. the entry to be purged from the itlb can be confirmed using the lrui bits. lrui is updated by means of the algorithm shown below. a dash in this table means that updating is not performed. lrui [5] [4] [3] [2] [1] [0] when itlb entry 0 is used 0 0 0 ? ? ? when itlb entry 1 is used 1 ? ? 0 0 ? when itlb entry 2 is used ? 1 ? 1 ? 0 when itlb entry 3 is used ? ? 1 ? 1 1 other than the above ? ? ? ? ? ? when the lrui bit settings are as shown below, the corresponding itlb entry is updated by an itlb miss. an asterisk in this table means ?don?t care?. lrui [5] [4] [3] [2] [1] [0] itlb entry 0 is updated 1 1 1 *** itlb entry 1 is updated 0 ** 11 * itlb entry 2 is updated * 0 * 0 * 1 itlb entry 3 is updated ** 0 * 00 other than the above setting prohibited ensure that values for which ?setting prohibited? is indicated in the above table are not set at the discretion of software. after a power-on or manual reset the lrui bits are initialized to 0, and therefore a prohibited setting is never made by a hardware update. rev. 5.0, 04/01, page 28 of 394 ? urb: bits that indicate the utlb entry boundary at which replacement is to be performed. valid only when urb > 0. ? urc: random counter for indicating the utlb entry for which replacement is to be performed with an ldtlb instruction. urc is incremented each time the utlb is accessed. when urb > 0, urc is reset to 0 when the condition urc = urb occurs. also note that, if a value is written to urc by software which results in the condition urc > urb, incrementing is first performed in excess of urb until urc = h'3f. urc is not incremented by an ldtlb instruction. ? sqmd: store queue mode bit. specifies the right of access to the store queues. 0: user/privileged access possible 1: privileged access possible (address error exception in case of user access) ? sv: bit that switches between single virtual memory mode and multiple virtual memory mode. 0: multiple virtual memory mode 1: single virtual memory mode when this bit is changed, ensure that 1 is also written to the ti bit. ? ti: writing 1 to this bit invalidates (clears to 0) all valid utlb/itlb bits. this bit always returns 0 when read. ? at: specifies mmu enabling or disabling. 0: mmu disabled 1: mmu enabled mmu exceptions are not generated when the at bit is 0. in the case of software that does not use the mmu, therefore, the at bit should be cleared to 0. 3.3 memory space 3.3.1 physical memory space the sh-4 supports a 32-bit physical memory space, and can access a 4-gbyte address space. when the mmucr.at bit is cleared to 0 and the mmu is disabled, the address space is this physical memory space. the physical memory space is divided into a number of areas, as shown in figure 3.3. the physical memory space is permanently mapped onto 29-bit external memory space; this correspondence can be implemented by ignoring the upper 3 bits of the physical memory space addresses. in privileged mode, the 4-gbyte space from the p0 area to the p4 area can be accessed. in user mode, a 2-gbyte space in the u0 area can be accessed. accessing the p1 to p4 areas (except the store queue area) in user mode will cause an address error. rev. 5.0, 04/01, page 29 of 394 area 0 area 1 area 2 area 3 area 4 area 5 area 6 area 7 external memory space address error address error store queue area user mode privileged mode p1 area cacheable p0 area cacheable p2 area non-cacheable p3 area cacheable u0 area cacheable h'0000 0000 h'8000 0000 h'e000 0000 h'e400 0000 h'ffff ffff h'0000 0000 h'8000 0000 h'ffff ffff h'a000 0000 h'c000 0000 h'e000 0000 p4 area non-cacheable figure 3.3 physical memory space (mmucr.at = 0) in the sh7750, it is not possible to access a pcmcia interface area from the cpu. in the sh7750s and sh7751, when access to a pcmcia interface area is performed from the cpu, the sa and tc values set in the ptea register are always used for the access. access to a pcmcia interface area by the dmac is always performed using the dmac?s chcrn.ssan and chcrn.stcn values. see the dmac section for details. p0, p1, p3, u0 areas: the p0, p1, p3, and u0 areas can be accessed using the cache. whether or not the cache is used is determined by the cache control register (ccr). when the cache is used, with the exception of the p1 area, switching between the copy-back method and the write-through method for write accesses is specified by the ccr.wt bit. for the p1 area, switching is specified by the ccr.cb bit. zeroizing the upper 3 bits of an address in these areas gives the corresponding external memory space address. however, since area 7 in the external memory space is a reserved area, a reserved area also appears in these areas. p2 area: the p2 area cannot be accessed using the cache. in the p2 area, zeroizing the upper 3 bits of an address gives the corresponding external memory space address. however, since area 7 in the external memory space is a reserved area, a reserved area also appears in this area. rev. 5.0, 04/01, page 30 of 394 p4 area: the p4 area is mapped onto sh-4 on-chip i/o channels. this area cannot be accessed using the cache. the p4 area is shown in detail in figure 3.4. h'e000 0000 h'e400 0000 h'f000 0000 h'f100 0000 h'f200 0000 h'f300 0000 h'f400 0000 h'f500 0000 h'f600 0000 h'f700 0000 h'f800 0000 h'fc00 0000 h'ffff ffff store queue reserved area instruction cache address array instruction cache data array instruction tlb address array instruction tlb data arrays 1 and 2 operand cache address array operand cache data array unified tlb address array unified tlb data arrays 1 and 2 reserved area control register area figure 3.4 p4 area the area from h'e000 0000 to h'e3ff ffff comprises addresses for accessing the store queues (sqs). when the mmu is disabled (mmucr.at = 0), the sq access right is specified by the mmucr.sqmd bit. for details, see section 4.6, store queues. the area from h'f000 0000 to h'f0ff ffff is used for direct access to the instruction cache address array. for details, see section 4.5.1, ic address array. the area from h'f100 0000 to h'f1ff ffff is used for direct access to the instruction cache data array. for details, see section 4.5.2, ic data array. the area from h'f200 0000 to h'f2ff ffff is used for direct access to the instruction tlb address array. for details, see section 3.7.1, itlb address array. rev. 5.0, 04/01, page 31 of 394 the area from h'f300 0000 to h'f3ff ffff is used for direct access to instruction tlb data arrays 1 and 2. for details, see sections 3.7.2, itlb data array 1, and 3.7.3, itlb data array 2. the area from h'f400 0000 to h'f4ff ffff is used for direct access to the operand cache address array. for details, see section 4.5.3, oc address array. the area from h'f500 0000 to h'f5ff ffff is used for direct access to the operand cache data array. for details, see section 4.5.4, oc data array. the area from h'f600 0000 to h'f6ff ffff is used for direct access to the unified tlb address array. for details, see section 3.7.4, utlb address array. the area from h'f700 0000 to h'f7ff ffff is used for direct access to unified tlb data arrays 1 and 2. for details, see sections 3.7.5, utlb data array 1, and 3.7.6, utlb data array 2. the area from h'fc00 0000 to h'ffff ffff is the control register area. 3.3.2 external memory space the sh-4 supports a 29-bit external memory space. the external memory space is divided into eight areas as shown in figure 3.5. areas 0 to 6 relate to memory, such as sram, synchronous dram, dram, and pcmcia. area 7 is a reserved area. for details, see section 13, bus state controller (bsc), in the hardware manual. h'0000 0000 h'0400 0000 h'0800 0000 h'0c00 0000 h'1000 0000 h'1400 0000 h'1800 0000 h'1c00 0000 h'1fff ffff area 0 area 1 area 2 area 3 area 4 area 5 area 6 area 7 (reserved area) figure 3.5 external memory space rev. 5.0, 04/01, page 32 of 394 3.3.3 virtual memory space setting the mmucr.at bit to 1 enables the p0, p3, and u0 areas of the physical memory space in the sh-4 to be mapped onto any external memory space in 1-, 4-, or 64-kbyte, or 1-mbyte, page units. by using an 8-bit address space identifier, the p0, u0, p3, and store queue areas can be increased to a maximum of 256. this is called the virtual memory space. mapping from virtual memory space to 29-bit external memory space is carried out using the tlb. only when area 7 in external memory space is accessed using virtual memory space, addresses h'1c00 0000 to h'1fff ffff of area 7 are not designated as a reserved area, but are equivalent to the p4 area control register area in the physical memory space. virtual memory space is illustrated in figure 3.6. area 0 area 1 area 2 area 3 area 4 area 5 area 6 area 7 external memory space 256 256 u0 area cacheable address translation possible address error address error store queue area p0 area cacheable address translation possible user mode privileged mode p1 area cacheable address translation not possible p2 area non-cacheable address translation not possible p3 area cacheable address translation possible p4 area non-cacheable address translation not possible figure 3.6 virtual memory space (mmucr.at = 1) when areas p0, p3, and u0 are mapped onto pcmcia interface areas by the tlb in the cache- enabled state, it is necessary to specify 1 for the wt bit of that page, or to clear the c bit to 0. access is performed using the sa and tc values set for individual tlb pages. it is not possible to access a pcmcia interface area from the cpu by access to area p1, p2, or p4. rev. 5.0, 04/01, page 33 of 394 access to a pcmcia interface area by the dmac is always performed using the dmac?s chcrn.ssan and chcrn.stcn values. see the dmac section for details. p0, p3, u0 areas: the p0 area (excluding addresses h'7c00 0000 to h'7fff ffff), p3 area, and u0 area allow access using the cache and address translation using the tlb. these areas can be mapped onto any external memory space in 1-, 4-, or 64-kbyte, or 1-mbyte, page units. when ccr is in the cache-enabled state and the tlb enable bit (c bit) is 1, accesses can be performed using the cache. in write accesses to the cache, switching between the copy-back method and the write-through method is indicated by the tlb write-through bit (wt bit), and is specified in page units. only when the p0, p3, and u0 areas are mapped onto external memory space by means of the tlb, addresses h'1c00 0000 to h'1fff ffff of area 7 in external memory space are allocated to the control register area. this enables control registers to be accessed from the u0 area in user mode. in this case, the c bit for the corresponding page must be cleared to 0. p1, p2, p4 areas: address translation using the tlb cannot be performed for the p1, p2, or p4 area (except for the store queue area). accesses to these areas are the same as for physical memory space. the store queue area can be mapped onto any external memory space by the mmu. however, operation in the case of an exception differs from that for normal p0, u0, and p3 spaces. for details, see section 4.6, store queues. 3.3.4 on-chip ram space in the sh-4, half (8 kbytes) of the instruction cache (16 kbytes) can be used as on-chip ram. this can be done by changing the ccr settings. when the operand cache is used as on-chip ram (ccr.ora = 1), p0 area addresses h'7c00 0000 to h'7fff ffff are an on-chip ram area. data accesses (byte/word/longword/quadword) can be used in this area. this area can only be used in ram mode. 3.3.5 address translation when the mmu is used, the virtual address space is divided into units called pages, and translation to physical addresses is carried out in these page units. the address translation table in external memory contains the physical addresses corresponding to virtual addresses and additional information such as memory protection codes. fast address translation is achieved by caching the contents of the address translation table located in external memory into the tlb. in the sh-4, basically, the itlb is used for instruction accesses and the utlb for data accesses. in the event of an access to an area other than the p4 area, the accessed virtual address is translated to a physical address. if the virtual address belongs to the p1 or p2 area, the physical address is uniquely determined without accessing the tlb. if the virtual address belongs to the p0, u0, or p3 area, the tlb is searched using the virtual address, and if the virtual address is recorded in the rev. 5.0, 04/01, page 34 of 394 tlb, a tlb hit is made and the corresponding physical address is read from the tlb. if the accessed virtual address is not recorded in the tlb, a tlb miss exception is generated and processing switches to the tlb miss exception routine. in the tlb miss exception routine, the address translation table in external memory is searched, and the corresponding physical address and page management information are recorded in the tlb. after the return from the exception handling routine, the instruction which caused the tlb miss exception is re-executed. 3.3.6 single virtual memory mode and multiple virtual memory mode there are two virtual memory systems, single virtual memory and multiple virtual memory, either of which can be selected with the mmucr.sv bit. in the single virtual memory system, a number of processes run simultaneously, using virtual address space on an exclusive basis, and the physical address corresponding to a particular virtual address is uniquely determined. in the multiple virtual memory system, a number of processes run while sharing the virtual address space, and a particular virtual address may be translated into different physical addresses depending on the process. the only difference between the single virtual memory and multiple virtual memory systems in terms of operation is in the tlb address comparison method (see section 3.4.3, address translation method). 3.3.7 address space identifier (asid) in multiple virtual memory mode, the 8-bit address space identifier (asid) is used to distinguish between processes running simultaneously while sharing the virtual address space. software can set the asid of the currently executing process in pteh in the mmu. the tlb does not have to be purged when processes are switched by means of asid. in single virtual memory mode, asid is used to provide memory protection for processes running simultaneously while using the virtual memory space on an exclusive basis. 3.4 tlb functions 3.4.1 unified tlb (utlb) configuration the unified tlb (utlb) is so called because of its use for the following two purposes: 1. to translate a virtual address to a physical address in a data access 2. as a table of address translation information to be recorded in the instruction tlb in the event of an itlb miss rev. 5.0, 04/01, page 35 of 394 information in the address translation table located in external memory is cached into the utlb. the address translation table contains virtual page numbers and address space identifiers, and corresponding physical page numbers and page management information. figure 3.7 shows the overall configuration of the utlb. the utlb consists of 64 fully-associative type entries. figure 3.8 shows the relationship between the address format and page size. ppn [28:10] ppn [28:10] ppn [28:10] sz [1:0] sz [1:0] sz [1:0] sh sh sh c c c pr [1:0] pr [1:0] pr [1:0] asid [7:0] asid [7:0] asid [7:0] vpn [31:10] vpn [31:10] vpn [31:10] v v v entry 0 entry 1 entry 2 d d d wt wt wt ppn [28:10] sz [1:0] sh c pr [1:0] sa [2:0] sa [2:0] sa [2:0] tc tc tc sa [2:0] tc asid [7:0] vpn [31:10] v entry 63 d wt figure 3.7 utlb configuration 31 1-kbyte page 10 9 0 virtual address 31 4-kbyte page 12 11 0 virtual address 31 64-kbyte page 16 15 0 virtual address 31 1-mbyte page 20 19 0 virtual address vpn offset vpn offset vpn offset vpn offset 28 10 9 0 physical address 28 12 11 0 physical address 28 16 15 0 physical address 28 20 19 0 physical address ppn offset ppn offset ppn offset ppn offset figure 3.8 relationship between page size and address format rev. 5.0, 04/01, page 36 of 394 ? vpn: virtual page number for 1-kbyte page: upper 22 bits of virtual address for 4-kbyte page: upper 20 bits of virtual address for 64-kbyte page: upper 16 bits of virtual address for 1-mbyte page: upper 12 bits of virtual address ? asid: address space identifier indicates the process that can access a virtual page. in single virtual memory mode and user mode, or in multiple virtual memory mode, if the sh bit is 0, this identifier is compared with the asid in pteh when address comparison is performed. ? sh: share status bit when 0, pages are not shared by processes. when 1, pages are shared by processes. ? sz: page size bits specify the page size. 00: 1-kbyte page 01: 4-kbyte page 10: 64-kbyte page 11: 1-mbyte page ? v: validity bit indicates whether the entry is valid. 0: invalid 1: valid cleared to 0 by a power-on reset. not affected by a manual reset. ? ppn: physical page number upper 22 bits of the physical address. with a 1-kbyte page, ppn bits [28:10] are valid. with a 4-kbyte page, ppn bits [28:12] are valid. with a 64-kbyte page, ppn bits [28:16] are valid. with a 1-mbyte page, ppn bits [28:20] are valid. the synonym problem must be taken into account when setting the ppn (see section 3.5.5, avoiding synonym problems). rev. 5.0, 04/01, page 37 of 394 ? pr: protection key data 2-bit data expressing the page access right as a code. 00: can be read only, in privileged mode 01: can be read and written in privileged mode 10: can be read only, in privileged or user mode 11: can be read and written in privileged mode or user mode ? c: cacheability bit indicates whether a page is cacheable. 0: not cacheable 1: cacheable when control register space is mapped, this bit must be cleared to 0. when performing pcmcia space mapping in the cache enabled state, either clear this bit to 0 or set the wt bit to 1. ? d: dirty bit indicates whether a write has been performed to a page. 0: write has not been performed 1: write has been performed ? wt: write-through bit specifies the cache write mode. 0: copy-back mode 1: write-through mode when performing pcmcia space mapping in the cache enabled state, either set this bit to 1 or clear the c bit to 0. ? sa: space attribute bits valid only when the page is mapped onto pcmcia connected to area 5 or 6. 000: undefined 001: variable-size i/o space (base size according to iois16 signal) 010: 8-bit i/o space 011: 16-bit i/o space 100: 8-bit common memory space 101: 16-bit common memory space 110: 8-bit attribute memory space 111: 16-bit attribute memory space rev. 5.0, 04/01, page 38 of 394 ? tc: timing control bit used to select wait control register bits in the bus control unit for areas 5 and 6. 0: wcr2 (a5w2?a5w0) and pcr (a5pcw1?a5pcw0, a5ted2?a5ted0, a5teh2? a5teh0) are used 1: wcr2 (a6w2?a6w0) and pcr (a6pcw1?a6pcw0, a6ted2?a6ted0, a6teh2? a6teh0) are used 3.4.2 instruction tlb (itlb) configuration the itlb is used to translate a virtual address to a physical address in an instruction access. information in the address translation table located in the utlb is cached into the itlb. figure 3.9 shows the overall configuration of the itlb. the itlb consists of 4 fully-associative type entries. ppn [28:10] ppn [28:10] ppn [28:10] ppn [28:10] sz [1:0] sz [1:0] sz [1:0] sz [1:0] sh sh sh sh c c c c pr pr pr pr asid [7:0] asid [7:0] asid [7:0] asid [7:0] vpn [31:10] vpn [31:10] vpn [31:10] vpn [31:10] v v v v entry 0 entry 1 entry 2 entry 3 sa [2:0] sa [2:0] sa [2:0] sa [2:0] tc tc tc tc notes: 1. d and wt bits are not supported. 2. there is only one pr bit, corresponding to the upper of the pr bits in the utlb. figure 3.9 itlb configuration 3.4.3 address translation method figures 3.10 and 3.11 show flowcharts of memory accesses using the utlb and itlb. rev. 5.0, 04/01, page 39 of 394 mmucr.at = 1 sh = 0 and (mmucr.sv = 0 or sr.md = 0) vpns match and asids match and v = 1 only one entry matches sr.md? ccr.oce? ccr.cb? ccr.wt? vpns match and v = 1 cache access in write-through mode memory access memory access data tlb multiple hit exception data tlb protection violation exception data tlb miss exception initial page write exception data tlb protection violation exception cache access in copy-back mode data access to virtual address (va) on-chip i/o access r/w? r/w? va is in p4 area va is in p2 area va is in p1 area va is in p0, u0, or p3 area yes no 1 0 yes yes no no yes yes yes no no 1 (privileged) 1 0 0 pr? 0 (user) d? r/w? w w w r r rr w r/w? (non-cacheable) wt? c = 1 and ccr.oce = 1 no 1 1 0 0 00 or 01 10 11 01 or 11 00 or 10 figure 3.10 flowchart of memory access using utlb rev. 5.0, 04/01, page 40 of 394 mmucr.at = 1 sh = 0 and (mmucr.sv = 0 or sr.md = 0) vpns match and asids match and v = 1 only one entry matches sr.md? ccr.ice? vpns match and v = 1 memory access instruction tlb multiple hit exception instruction tlb miss exception instruction access to virtual address (va) va is in p4 area va is in p2 area va is in p1 area va is in p0, u0, or p3 area yes no 1 0 yes yes no no yes yes no (non-cacheable) c = 1 and ccr.ice = 1 no pr? instruction tlb protection violation exception match? record in itlb access prohibited 0 1 no yes yes no hardware itlb miss handling 0 (user) 1 (privileged) search utlb cache access figure 3.11 flowchart of memory access using itlb rev. 5.0, 04/01, page 41 of 394 3.5 mmu functions 3.5.1 mmu hardware management the sh-4 supports the following mmu functions. 1. the mmu decodes the virtual address to be accessed by software, and performs address translation by controlling the utlb/itlb in accordance with the mmucr settings. 2. the mmu determines the cache access status on the basis of the page management information read during address translation (c, wt, sa, and tc bits). 3. if address translation cannot be performed normally in a data access or instruction access, the mmu notifies software by means of an mmu exception. 4. if address translation information is not recorded in the itlb in an instruction access, the mmu searches the utlb, and if the necessary address translation information is recorded in the utlb, the mmu copies this information into the itlb in accordance with mmucr.lrui. 3.5.2 mmu software management software processing for the mmu consists of the following: 1. setting of mmu-related registers. some registers are also partially updated by hardware automatically. 2. recording, deletion, and reading of tlb entries. there are two methods of recording utlb entries: by using the ldtlb instruction, or by writing directly to the memory-mapped utlb. itlb entries can only be recorded by writing directly to the memory-mapped itlb. for deleting or reading utlb/itlb entries, it is possible to access the memory-mapped utlb/itlb. 3. mmu exception handling. when an mmu exception occurs, processing is performed based on information set by hardware. 3.5.3 mmu instruction (ldtlb) a tlb load instruction (ldtlb) is provided for recording utlb entries. when an ldtlb instruction is issued, the sh-4 copies the contents of pteh, ptel, and ptea to the utlb entry indicated by mmucr.urc. itlb entries are not updated by the ldtlb instruction, and therefore address translation information purged from the utlb entry may still remain in the itlb entry. as the ldtlb instruction changes address translation information, ensure that it is issued by a program in the p1 or p2 area. the operation of the ldtlb instruction is shown in figure 3.12. rev. 5.0, 04/01, page 42 of 394 ppn [28:10] ppn [28:10] ppn [28:10] sz [1:0] sz [1:0] sz [1:0] sh sh sh c c c pr [1:0] pr [1:0] pr [1:0] asid [7:0] asid [7:0] asid [7:0] vpn [31:10] vpn [31:10] vpn [31:10] v v v entry 0 entry 1 entry 2 d d d wt wt wt ppn [28:10] sz [1:0] sh c pr [1:0] sa [2:0] sa [2:0] sa [2:0] tc tc tc sa [2:0] tc asid [7:0] vpn [31:10] v entry 63 d wt 31 29 28 9 8 7 65 4 3 2 1 0 ??vszprszcdsh wt ptel write utlb 31 10 98 70 ? asid pteh 31 26 25 24 23 18 17 16 15 10 9 8 73 2 1 0 lrui ? urb ? urc sv sqmd ?ti?at mmucr vpn 10 ppn 31 4 32 0 ?sa tc ptea entry specification figure 3.12 operation of ldtlb instruction 3.5.4 hardware itlb miss handling in an instruction access, the sh-4 searches the itlb. if it cannot find the necessary address translation information (i.e. in the event of an itlb miss), the utlb is searched by hardware, and if the necessary address translation information is present, it is recorded in the itlb. this procedure is known as hardware itlb miss handling. if the necessary address translation information is not found in the utlb search, an instruction tlb miss exception is generated and processing passes to software. rev. 5.0, 04/01, page 43 of 394 3.5.5 avoiding synonym problems when 1- or 4-kbyte pages are recorded in tlb entries, a synonym problem may arise. the problem is that, when a number of virtual addresses are mapped onto a single physical address, the same physical address data is recorded in a number of cache entries, and it becomes impossible to guarantee data integrity. this problem does not occur with the instruction tlb or instruction cache . in the sh-4, entry specification is performed using bits [13:5] of the virtual address in order to achieve fast operand cache operation. however, bits [13:10] of the virtual address in the case of a 1-kbyte page, and bits [13:12] of the virtual address in the case of a 4-kbyte page, are subject to address translation. as a result, bits [13:10] of the physical address after translation may differ from bits [13:10] of the virtual address. consequently, the following restrictions apply to the recording of address translation information in utlb entries. 1. when address translation information whereby a number of 1-kbyte page utlb entries are translated into the same physical address is recorded in the utlb, ensure that the vpn [13:10] values are the same. 2. when address translation information whereby a number of 4-kbyte page utlb entries are translated into the same physical address is recorded in the utlb, ensure that the vpn [13:12] values are the same. 3. do not use 1-kbyte page utlb entry physical addresses with utlb entries of a different page size. 4. do not use 4-kbyte page utlb entry physical addresses with utlb entries of a different page size. the above restrictions apply only when performing accesses using the cache. when cache index mode is used, vpn [25] is used for the entry address instead of vpn [13], and therefore the above restrictions apply to vpn [25]. note: when multiple items of address translation information use the same physical memory to provide for future superh risc engine family expansion, ensure that the vpn [20:10] values are the same. also, do not use the same physical address for address translation information of different page sizes. rev. 5.0, 04/01, page 44 of 394 3.6 mmu exceptions there are seven mmu exceptions: the instruction tlb multiple hit exception, instruction tlb miss exception, instruction tlb protection violation exception, data tlb multiple hit exception, data tlb miss exception, data tlb protection violation exception, and initial page write exception. refer to figures 3.10 and 3.11 for the conditions under which each of these exceptions occurs. 3.6.1 instruction tlb multiple hit exception an instruction tlb multiple hit exception occurs when more than one itlb entry matches the virtual address to which an instruction access has been made. if multiple hits occur when the utlb is searched by hardware in hardware itlb miss handling, a data tlb multiple hit exception will result. when an instruction tlb multiple hit exception occurs a reset is executed, and cache coherency is not guaranteed. hardware processing: in the event of an instruction tlb multiple hit exception, hardware carries out the following processing: 1. sets the virtual address at which the exception occurred in tea. 2. sets exception code h'140 in expevt. 3. branches to the reset handling routine (h'a000 0000). software processing (reset routine): the itlb entries which caused the multiple hit exception are checked in the reset handling routine. this exception is intended for use in program debugging, and should not normally be generated. rev. 5.0, 04/01, page 45 of 394 3.6.2 instruction tlb miss exception an instruction tlb miss exception occurs when address translation information for the virtual address to which an instruction access is made is not found in the utlb entries by the hardware itlb miss handling procedure. the instruction tlb miss exception processing carried out by hardware and software is shown below. this is the same as the processing for a data tlb miss exception. hardware processing: in the event of an instruction tlb miss exception, hardware carries out the following processing: 1. sets the vpn of the virtual address at which the exception occurred in pteh. 2. sets the virtual address at which the exception occurred in tea. 3. sets exception code h'040 in expevt. 4. sets the pc value indicating the address of the instruction at which the exception occurred in spc. if the exception occurred at a delay slot, sets the pc value indicating the address of the delayed branch instruction in spc. 5. sets the sr contents at the time of the exception in ssr. the r15 contents at this time are saved in sgr. 6. sets the md bit in sr to 1, and switches to privileged mode. 7. sets the bl bit in sr to 1, and masks subsequent exception requests. 8. sets the rb bit in sr to 1. 9. branches to the address obtained by adding offset h'0000 0400 to the contents of vbr, and starts the instruction tlb miss exception handling routine. software processing (instruction tlb miss exception handling routine): software is responsible for searching the external memory page table and assigning the necessary page table entry. software should carry out the following processing in order to find and assign the necessary page table entry. 1. write to ptel the values of the ppn, pr, sz, c, d, sh, v, and wt bits in the page table entry recorded in the external memory address translation table. if necessary, the values of the sa and tc bits should be written to ptea. 2. when the entry to be replaced in entry replacement is specified by software, write that value to urc in the mmucr register. if urc is greater than urb at this time, the value should be changed to an appropriate value after issuing an ldtlb instruction. 3. execute the ldtlb instruction and write the contents of pteh, ptel, and ptea to the tlb. 4. finally, execute the exception handling return instruction (rte), terminate the exception handling routine, and return control to the normal flow. the rte instruction should be issued at least one instruction after the ldtlb instruction. rev. 5.0, 04/01, page 46 of 394 3.6.3 instruction tlb protection violation exception an instruction tlb protection violation exception occurs when, even though an itlb entry contains address translation information matching the virtual address to which an instruction access is made, the actual access type is not permitted by the access right specified by the pr bit. the instruction tlb protection violation exception processing carried out by hardware and software is shown below. hardware processing: in the event of an instruction tlb protection violation exception, hardware carries out the following processing: 1. sets the vpn of the virtual address at which the exception occurred in pteh. 2. sets the virtual address at which the exception occurred in tea. 3. sets exception code h'0a0 in expevt. 4. sets the pc value indicating the address of the instruction at which the exception occurred in spc. if the exception occurred at a delay slot, sets the pc value indicating the address of the delayed branch instruction in spc. 5. sets the sr contents at the time of the exception in ssr. the r15 contents at this time are saved in sgr. 6. sets the md bit in sr to 1, and switches to privileged mode. 7. sets the bl bit in sr to 1, and masks subsequent exception requests. 8. sets the rb bit in sr to 1. 9. branches to the address obtained by adding offset h'0000 0100 to the contents of vbr, and starts the instruction tlb protection violation exception handling routine. software processing (instruction tlb protection violation exception handling routine): resolve the instruction tlb protection violation, execute the exception handling return instruction (rte), terminate the exception handling routine, and return control to the normal flow. the rte instruction should be issued at least one instruction after the ldtlb instruction. rev. 5.0, 04/01, page 47 of 394 3.6.4 data tlb multiple hit exception a data tlb multiple hit exception occurs when more than one utlb entry matches the virtual address to which a data access has been made. a data tlb multiple hit exception is also generated if multiple hits occur when the utlb is searched in hardware itlb miss handling. when a data tlb multiple hit exception occurs a reset is executed, and cache coherency is not guaranteed. the contents of ppn in the utlb prior to the exception may also be corrupted. hardware processing: in the event of a data tlb multiple hit exception, hardware carries out the following processing: 1. sets the virtual address at which the exception occurred in tea. 2. sets exception code h'140 in expevt. 3. branches to the reset handling routine (h'a000 0000). software processing (reset routine): the utlb entries which caused the multiple hit exception are checked in the reset handling routine. this exception is intended for use in program debugging, and should not normally be generated. 3.6.5 data tlb miss exception a data tlb miss exception occurs when address translation information for the virtual address to which a data access is made is not found in the utlb entries. the data tlb miss exception processing carried out by hardware and software is shown below. hardware processing: in the event of a data tlb miss exception, hardware carries out the following processing: 1. sets the vpn of the virtual address at which the exception occurred in pteh. 2. sets the virtual address at which the exception occurred in tea. 3. sets exception code h'040 in the case of a read, or h'060 in the case of a write, in expevt (ocbp, ocbwb: read; ocbi, movca.l: write). 4. sets the pc value indicating the address of the instruction at which the exception occurred in spc. if the exception occurred at a delay slot, sets the pc value indicating the address of the delayed branch instruction in spc. 5. sets the sr contents at the time of the exception in ssr. the r15 contents at this time are saved in sgr. 6. sets the md bit in sr to 1, and switches to privileged mode. 7. sets the bl bit in sr to 1, and masks subsequent exception requests. 8. sets the rb bit in sr to 1. 9. branches to the address obtained by adding offset h'0000 0400 to the contents of vbr, and starts the data tlb miss exception handling routine. rev. 5.0, 04/01, page 48 of 394 software processing (data tlb miss exception handling routine): software is responsible for searching the external memory page table and assigning the necessary page table entry. software should carry out the following processing in order to find and assign the necessary page table entry. 1. write to ptel the values of the ppn, pr, sz, c, d, sh, v, and wt bits in the page table entry recorded in the external memory address translation table. if necessary, the values of the sa and tc bits should be written to ptea. 2. when the entry to be replaced in entry replacement is specified by software, write that value to urc in the mmucr register. if urc is greater than urb at this time, the value should be changed to an appropriate value after issuing an ldtlb instruction. 3. execute the ldtlb instruction and write the contents of pteh, ptel, and ptea to the utlb. 4. finally, execute the exception handling return instruction (rte), terminate the exception handling routine, and return control to the normal flow. the rte instruction should be issued at least one instruction after the ldtlb instruction. 3.6.6 data tlb protection violation exception a data tlb protection violation exception occurs when, even though a utlb entry contains address translation information matching the virtual address to which a data access is made, the actual access type is not permitted by the access right specified by the pr bit. the data tlb protection violation exception processing carried out by hardware and software is shown below. hardware processing: in the event of a data tlb protection violation exception, hardware carries out the following processing: 1. sets the vpn of the virtual address at which the exception occurred in pteh. 2. sets the virtual address at which the exception occurred in tea. 3. sets exception code h'0a0 in the case of a read, or h'0c0 in the case of a write, in expevt (ocbp, ocbwb: read; ocbi, movca.l: write). 4. sets the pc value indicating the address of the instruction at which the exception occurred in spc. if the exception occurred at a delay slot, sets the pc value indicating the address of the delayed branch instruction in spc. 5. sets the sr contents at the time of the exception in ssr. the r15 contents at this time are saved in sgr. 6. sets the md bit in sr to 1, and switches to privileged mode. 7. sets the bl bit in sr to 1, and masks subsequent exception requests. 8. sets the rb bit in sr to 1. 9. branches to the address obtained by adding offset h'0000 0100 to the contents of vbr, and starts the data tlb protection violation exception handling routine. rev. 5.0, 04/01, page 49 of 394 software processing (data tlb protection violation exception handling routine): resolve the data tlb protection violation, execute the exception handling return instruction (rte), terminate the exception handling routine, and return control to the normal flow. the rte instruction should be issued at least one instruction after the ldtlb instruction. 3.6.7 initial page write exception an initial page write exception occurs when the d bit is 0 even though a utlb entry contains address translation information matching the virtual address to which a data access (write) is made, and the access is permitted. the initial page write exception processing carried out by hardware and software is shown below. hardware processing: in the event of an initial page write exception, hardware carries out the following processing: 1. sets the vpn of the virtual address at which the exception occurred in pteh. 2. sets the virtual address at which the exception occurred in tea. 3. sets exception code h'080 in expevt. 4. sets the pc value indicating the address of the instruction at which the exception occurred in spc. if the exception occurred at a delay slot, sets the pc value indicating the address of the delayed branch instruction in spc. 5. sets the sr contents at the time of the exception in ssr. the r15 contents at this time are saved in sgr. 6. sets the md bit in sr to 1, and switches to privileged mode. 7. sets the bl bit in sr to 1, and masks subsequent exception requests. 8. sets the rb bit in sr to 1. 9. branches to the address obtained by adding offset h'0000 0100 to the contents of vbr, and starts the initial page write exception handling routine. rev. 5.0, 04/01, page 50 of 394 software processing (initial page write exception handling routine): the following processing should be carried out as the responsibility of software: 1. retrieve the necessary page table entry from external memory. 2. write 1 to the d bit in the external memory page table entry. 3. write to ptel the values of the ppn, pr, sz, c, d, wt, sh, and v bits in the page table entry recorded in external memory. if necessary, the values of the sa and tc bits should be written to ptea. 4. when the entry to be replaced in entry replacement is specified by software, write that value to urc in the mmucr register. if urc is greater than urb at this time, the value should be changed to an appropriate value after issuing an ldtlb instruction. 5. execute the ldtlb instruction and write the contents of pteh, ptel, and ptea to the utlb. 6. finally, execute the exception handling return instruction (rte), terminate the exception handling routine, and return control to the normal flow. the rte instruction should be issued at least one instruction after the ldtlb instruction. 3.7 memory-mapped tlb configuration to enable the itlb and utlb to be managed by software, their contents can be read and written by a p2 area program with a mov instruction in privileged mode. operation is not guaranteed if access is made from a program in another area. a branch to an area other than the p2 area should be made at least 8 instructions after this mov instruction. the itlb and utlb are allocated to the p4 area in physical memory space. vpn, v, and asid in the itlb can be accessed as an address array, ppn, v, sz, pr, c, and sh as data array 1, and sa and tc as data array 2. vpn, d, v, and asid in the utlb can be accessed as an address array, ppn, v, sz, pr, c, d, wt, and sh as data array 1, and sa and tc as data array 2. v and d can be accessed from both the address array side and the data array side. only longword access is possible. instruction fetches cannot be performed in these areas. for reserved bits, a write value of 0 should be specified; their read value is undefined. rev. 5.0, 04/01, page 51 of 394 3.7.1 itlb address array the itlb address array is allocated to addresses h'f200 0000 to h'f2ff ffff in the p4 area. an address array access requires a 32-bit address field specification (when reading or writing) and a 32-bit data field specification (when writing). information for selecting the entry to be accessed is specified in the address field, and vpn, v, and asid to be written to the address array are specified in the data field. in the address field, bits [31:24] have the value h'f2 indicating the itlb address array, and the entry is selected by bits [9:8]. as longword access is used, 0 should be specified for address field bits [1:0]. in the data field, vpn is indicated by bits [31:10], v by bit [8], and asid by bits [7:0]. the following two kinds of operation can be used on the itlb address array: 1. itlb address array read vpn, v, and asid are read into the data field from the itlb entry corresponding to the entry set in the address field. 2. itlb address array write vpn, v, and asid specified in the data field are written to the itlb entry corresponding to the entry set in the address field. address field 31 23 0 11110010 e data field 31 10 9 0 v vpn vpn: v: e: 24 virtual page number validity bit entry 10987 987 asid asid: : address space identifier reserved bits (0 write value, undefined read value) figure 3.13 memory-mapped itlb address array rev. 5.0, 04/01, page 52 of 394 3.7.2 itlb data array 1 itlb data array 1 is allocated to addresses h'f300 0000 to h'f37f ffff in the p4 area. a data array access requires a 32-bit address field specification (when reading or writing) and a 32-bit data field specification (when writing). information for selecting the entry to be accessed is specified in the address field, and ppn, v, sz, pr, c, and sh to be written to the data array are specified in the data field. in the address field, bits [31:23] have the value h'f30 indicating itlb data array 1, and the entry is selected by bits [9:8]. in the data field, ppn is indicated by bits [28:10], v by bit [8], sz by bits [7] and [4], pr by bit [6], c by bit [3], and sh by bit [1]. the following two kinds of operation can be used on itlb data array 1: 1. itlb data array 1 read ppn, v, sz, pr, c, and sh are read into the data field from the itlb entry corresponding to the entry set in the address field. 2. itlb data array 1 write ppn, v, sz, pr, c, and sh specified in the data field are written to the itlb entry corresponding to the entry set in the address field. address field 31 23 0 111100 0 11 e data field ppn: v: e: sz: 24 physical page number validity bit entry page size bits 10 9 8 7 pr: c: sh: : protection key data cacheability bit share status bit reserved bits (0 write value, undefined read value) 31 210 v 10 9 8 7 30 29 28 43 65 sz sh pr c ppn figure 3.14 memory-mapped itlb data array 1 rev. 5.0, 04/01, page 53 of 394 3.7.3 itlb data array 2 itlb data array 2 is allocated to addresses h'f380 0000 to h'f3ff ffff in the p4 area. a data array access requires a 32-bit address field specification (when reading or writing) and a 32-bit data field specification (when writing). information for selecting the entry to be accessed is specified in the address field, and sa and tc to be written to data array 2 are specified in the data field. in the address field, bits [31:23] have the value h'f38 indicating itlb data array 2, and the entry is selected by bits [9:8]. in the data field, sa is indicated by bits [2:0], and tc by bit [3]. the following two kinds of operation can be used on itlb data array 2: 1. itlb data array 2 read sa and tc are read into the data field from the itlb entry corresponding to the entry set in the address field. 2. itlb data array 2 write sa and tc specified in the data field are written to the itlb entry corresponding to the entry set in the address field. address field 31 23 0 11110011 1e data field 31 40 tc: e: 24 timing control bit entry 8 97 32 sa: : space attribute bits reserved bits (0 write value, undefined read value) 10 sa tc figure 3.15 memory-mapped itlb data array 2 3.7.4 utlb address array the utlb address array is allocated to addresses h'f600 0000 to h'f6ff ffff in the p4 area. an address array access requires a 32-bit address field specification (when reading or writing) and a 32-bit data field specification (when writing). information for selecting the entry to be accessed is specified in the address field, and vpn, d, v, and asid to be written to the address array are specified in the data field. rev. 5.0, 04/01, page 54 of 394 in the address field, bits [31:24] have the value h'f6 indicating the utlb address array, and the entry is selected by bits [13:8]. the address array bit [7] association bit (a bit) specifies whether or not address comparison is performed when writing to the utlb address array. in the data field, vpn is indicated by bits [31:10], d by bit [9], v by bit [8], and asid by bits [7:0]. the following three kinds of operation can be used on the utlb address array: 1. utlb address array read vpn, d, v, and asid are read into the data field from the utlb entry corresponding to the entry set in the address field. in a read, associative operation is not performed regardless of whether the association bit specified in the address field is 1 or 0. 2. utlb address array write (non-associative) vpn, d, v, and asid specified in the data field are written to the utlb entry corresponding to the entry set in the address field. the a bit in the address field should be cleared to 0. 3. utlb address array write (associative) when a write is performed with the a bit in the address field set to 1, comparison of all the utlb entries is carried out using the vpn specified in the data field and pteh.asid. the usual address comparison rules are followed, but if a utlb miss occurs, the result is no operation, and an exception is not generated. if the comparison identifies a utlb entry corresponding to the vpn specified in the data field, d and v specified in the data field are written to that entry. if there is more than one matching entry, a data tlb multiple hit exception results. this associative operation is simultaneously carried out on the itlb, and if a matching entry is found in the itlb, v is written to that entry. even if the utlb comparison results in no operation, a write to the itlb side only is performed as long as there is an itlb match. if there is a match in both the utlb and itlb, the utlb information is also written to the itlb. address field data field vpn: v: e: d: virtual page number validity bit entry dirty bit asid: a: : address space identifier association bit reserved bits (0 write value, undefined read value) 31 0 v d 10987 30 29 28 a 87 asid vpn 31 23 210 11110110 e 24 14 13 figure 3.16 memory-mapped utlb address array rev. 5.0, 04/01, page 55 of 394 3.7.5 utlb data array 1 utlb data array 1 is allocated to addresses h'f700 0000 to h'f77f ffff in the p4 area. a data array access requires a 32-bit address field specification (when reading or writing) and a 32-bit data field specification (when writing). information for selecting the entry to be accessed is specified in the address field, and ppn, v, sz, pr, c, d, sh, and wt to be written to the data array are specified in the data field. in the address field, bits [31:23] have the value h'f70 indicating utlb data array 1, and the entry is selected by bits [13:8]. in the data field, ppn is indicated by bits [28:10], v by bit [8], sz by bits [7] and [4], pr by bits [6:5], c by bit [3], d by bit [2], sh by bit [1], and wt by bit [0]. the following two kinds of operation can be used on utlb data array 1: 1. utlb data array 1 read ppn, v, sz, pr, c, d, sh, and wt are read into the data field from the utlb entry corresponding to the entry set in the address field. 2. utlb data array 1 write ppn, v, sz, pr, c, d, sh, and wt specified in the data field are written to the utlb entry corresponding to the entry set in the address field. address field data field ppn: v: e: sz: d: physical page number validity bit entry page size bits dirty bit pr: c: sh: wt: : protection key data cacheability bit share status bit write-through bit reserved bits (0 write value, undefined read value) 31 210 v 10987 30 29 28 43 65 pr c ppn 31 23 0 11110111 0 e 24 87 14 13 d sz sh wt figure 3.17 memory-mapped utlb data array 1 rev. 5.0, 04/01, page 56 of 394 3.7.6 utlb data array 2 utlb data array 2 is allocated to addresses h'f780 0000 to h'f7ff ffff in the p4 area. a data array access requires a 32-bit address field specification (when reading or writing) and a 32-bit data field specification (when writing). information for selecting the entry to be accessed is specified in the address field, and sa and tc to be written to data array 2 are specified in the data field. in the address field, bits [31:23] have the value h'f78 indicating utlb data array 2, and the entry is selected by bits [13:8]. in the data field, tc is indicated by bit [3], and sa by bits [2:0]. the following two kinds of operation can be used on utlb data array 2: 1. utlb data array 2 read sa and tc are read into the data field from the utlb entry corresponding to the entry set in the address field. 2. utlb data array 2 write sa and tc specified in the data field are written to the utlb entry corresponding to the entry set in the address field. address field 31 23 0 11110111 1e data field 31 4 0 tc 24 8 13 7 32 14 sa tc: e: timing control bit entry sa: : space attribute bits reserved bits (0 write value, undefined read value) figure 3.18 memory-mapped utlb data array 2 rev. 5.0, 04/01, page 57 of 394 section 4 caches 4.1 overview 4.1.1 features the sh-4 has an on-chip 8-kbyte instruction cache (ic) for instructions and 16-kbyte operand cache (oc) for data. half of the memory of the operand cache (8 kbytes) can also be used as on- chip ram. the features of these caches are summarized in table 4.1. table 4.1 cache features item instruction cache operand cache capacity 8-kbyte cache 16-kbyte cache or 8-kbyte cache + 8-kbyte ram type direct mapping direct mapping line size 32 bytes 32 bytes entries 256 512 write method copy-back/write-through selectable item store queues capacity 2 32 bytes addresses h'e000 0000 to h'e3ff ffff write store instruction (1-cycle write) write-back prefetch instruction access right mmu off: according to mmucr.sqmd mmu on: according to individual page pr rev. 5.0, 04/01, page 58 of 394 4.1.2 register configuration table 4.2 shows the cache control registers. table 4.2 cache control registers name abbreviation r/w initial value* 1 p4 address* 2 area 7 address* 2 access size cache control register ccr r/w h'0000 0000 h'ff00 001c h'1f00 001c 32 queue address control register 0 qacr0 r/w undefined h'ff00 0038 h'1f00 0038 32 queue address control register 1 qacr1 r/w undefined h'ff00 003c h'1f00 003c 32 notes: 1. the initial value is the value after a power-on or manual reset. 2. this is the address when using the virtual/physical address space p4 area. when making an access from physical address space area 7 using the tlb, the upper 3 bits of the address are ignored. 4.2 register descriptions there are three cache and store queue related control registers, as shown in figure 4.1. ccr 31 14 1615 12111098765432 cb 10 ici ice ora oix oci area indicates reserved bits: 0 must be specified in a write; the read value is undefined. wt oce iix qacr0 31 54 210 area qacr1 31 54 210 figure 4.1 cache and store queue control registers rev. 5.0, 04/01, page 59 of 394 (1) cache control register (ccr): ccr contains the following bits: iix: ic index enable ici: ic invalidation ice: ic enable oix: oc index enable ora: oc ram enable oci: oc invalidation cb: copy-back enable wt: write-through enable oce: oc enable longword access to ccr can be performed from h'ff00 001c in the p4 area and h'1f00 001c in area 7. the ccr bits are used for the cache settings described below. consequently, ccr modifications must only be made by a program in the non-cached p2 area. after ccr is updated, an instruction that performs data access to the p0, p1, p3, or u0 area should be located at least four instructions after the ccr update instruction. also, a branch instruction to the p0, p1, p3, or u0 area should be located at least eight instructions after the ccr update instruction. ? iix: ic index enable bit 0: address bits [12:5] used for ic entry selection 1: address bits [25] and [11:5] used for ic entry selection ? ici: ic invalidation bit when 1 is written to this bit, the v bits of all ic entries are cleared to 0. this bit always returns 0 when read. ? ice: ic enable bit indicates whether or not the ic is to be used. when address translation is performed, the ic cannot be used unless the c bit in the page management information is also 1. 0: ic not used 1: ic used ? oix: oc index enable bit 0: address bits [13:5] used for oc entry selection 1: address bits [25] and [12:5] used for oc entry selection ? ora: oc ram enable bit when the oc is enabled (oce = 1), the ora bit specifies whether the 8 kbytes from entry 128 to entry 255 and from entry 384 to entry 511 of the oc are to be used as ram. when the oc is not enabled (oce = 0), the ora bit should be cleared to 0. 0: 16 kbytes used as cache 1: 8 kbytes used as cache, and 8 kbytes as ram rev. 5.0, 04/01, page 60 of 394 ? oci: oc invalidation bit when 1 is written to this bit, the v and u bits of all oc entries are cleared to 0. this bit always returns 0 when read. ? cb: copy-back bit indicates the p1 area cache write mode. 0: write-through mode 1: copy-back mode ? wt: write-through bit indicates the p0, u0, and p3 area cache write mode. when address translation is performed, the value of the wt bit in the page management information has priority. 0: copy-back mode 1: write-through mode ? oce: oc enable bit indicates whether or not the oc is to be used. when address translation is performed, the oc cannot be used unless the c bit in the page management information is also 1. 0: oc not used 1: oc used (2) queue address control register 0 (qacr0): longword access to qacr0 can be performed from h'ff00 0038 in the p4 area and h'1f00 0038 in area 7. qacr0 specifies the area onto which store queue 0 (sq0) is mapped when the mmu is off. (3) queue address control register 1 (qacr1): longword access to qacr1 can be performed from h'ff00 003c in the p4 area and h'1f00 003c in area 7. qacr1 specifies the area onto which store queue 1 (sq1) is mapped when the mmu is off. rev. 5.0, 04/01, page 61 of 394 4.3 operand cache (oc) 4.3.1 configuration figure 4.2 shows the configuration of the operand cache. 31 26 25 5 4 3 2 1 lw0 32 bits lw1 32 bits lw2 32 bits lw3 32 bits lw4 32 bits lw5 32 bits lw6 32 bits lw7 32 bits mmu ram area determination ora oix [13] [12] [11:5] 511 19 bits 1 bit 1 bit tag u v address array data array entry selection longword (lw) selection effective address 3 9 22 19 0 write data read data hit signal compare 13 12 11 10 9 0 figure 4.2 configuration of operand cache rev. 5.0, 04/01, page 62 of 394 the operand cache consists of 512 cache lines, each composed of a 19-bit tag, v bit, u bit, and 32- byte data. ? tag stores the upper 19 bits of the 29-bit external memory address of the data line to be cached. the tag is not initialized by a power-on or manual reset. ? v bit (validity bit) indicates that valid data is stored in the cache line. when this bit is 1, the cache line data is valid. the v bit is initialized to 0 by a power-on reset, but retains its value in a manual reset. ? u bit (dirty bit) the u bit is set to 1 if data is written to the cache line while the cache is being used in copy- back mode. that is, the u bit indicates a mismatch between the data in the cache line and the data in external memory. the u bit is never set to 1 while the cache is being used in write- through mode, unless it is modified by accessing the memory-mapped cache (see section 4.5, memory-mapped cache configuration). the u bit is initialized to 0 by a power-on reset, but retains its value in a manual reset. ? data field the data field holds 32 bytes (256 bits) of data per cache line. the data array is not initialized by a power-on or manual reset. 4.3.2 read operation when the oc is enabled (ccr.oce = 1) and data is read by means of an effective address from a cacheable area, the cache operates as follows: 1. the tag, v bit, and u bit are read from the cache line indexed by effective address bits [13:5]. 2. the tag is compared with bits [28:10] of the address resulting from effective address translation by the mmu: ? if the tag matches and the v bit is 1 (3a) ? if the tag matches and the v bit is 0 (3b) ? if the tag does not match and the v bit is 0 (3b) ? if the tag does not match, the v bit is 1, and the u bit is 0 (3b) ? if the tag does not match, the v bit is 1, and the u bit is 1 (3c) rev. 5.0, 04/01, page 63 of 394 3a. cache hit the data indexed by effective address bits [4:0] is read from the data field of the cache line indexed by effective address bits [13:5] in accordance with the access size (quadword/longword/word/byte). 3b. cache miss (no write-back) data is read into the cache line from the external memory space corresponding to the effective address. data reading is performed, using the wraparound method, in order from the longword data corresponding to the effective address, and when the corresponding data arrives in the cache, the read data is returned to the cpu. while the remaining one cache line of data is being read, the cpu can execute the next processing. when reading of one line of data is completed, the tag corresponding to the effective address is recorded in the cache, and 1 is written to the v bit. 3c. cache miss (with write-back) the tag and data field of the cache line indexed by effective address bits [13:5] are saved in the write-back buffer. then data is read into the cache line from the external memory space corresponding to the effective address. data reading is performed, using the wraparound method, in order from the longword data corresponding to the effective address, and when the corresponding data arrives in the cache, the read data is returned to the cpu. while the remaining one cache line of data is being read, the cpu can execute the next processing. when reading of one line of data is completed, the tag corresponding to the effective address is recorded in the cache, 1 is written to the v bit, and 0 to the u bit. the data in the write-back buffer is then written back to external memory. 4.3.3 write operation when the oc is enabled (ccr.oce = 1) and data is written by means of an effective address to a cacheable area, the cache operates as follows: 1. the tag, v bit, and u bit are read from the cache line indexed by effective address bits [13:5]. 2. the tag is compared with bits [28:10] of the address resulting from effective address translation by the mmu: copy-back write-through ? if the tag matches and the v bit is 1 (3a) (3b) ? if the tag matches and the v bit is 0 (3c) (3d) ? if the tag does not match and the v bit is 0 (3c) (3d) ? if the tag does not match, the v bit is 1, and the u bit is 0 (3c) (3d) ? if the tag does not match, the v bit is 1, and the u bit is 1 (3e) (3d) rev. 5.0, 04/01, page 64 of 394 3a. cache hit (copy-back) a data write in accordance with the access size (quadword/longword/word/byte) is performed for the data indexed by bits [4:0] of the effective address of the data field of the cache line indexed by effective address bits [13:5]. then 1 is set in the u bit. 3b. cache hit (write-through) a data write in accordance with the access size (quadword/longword/word/byte) is performed for the data indexed by bits [4:0] of the effective address of the data field of the cache line indexed by effective address bits [13:5]. a write is also performed to the corresponding external memory using the specified access size. 3c. cache miss (no copy-back/write-back) a data write in accordance with the access size (quadword/longword/word/byte) is performed for the data indexed by bits [4:0] of the effective address of the data field of the cache line indexed by effective address bits [13:5]. then, data is read into the cache line from the external memory space corresponding to the effective address. data reading is performed, using the wraparound method, in order from the longword data corresponding to the effective address, and one cache line of data is read excluding the written data. during this time, the cpu can execute the next processing. when reading of one line of data is completed, the tag corresponding to the effective address is recorded in the cache, and 1 is written to the v bit and u bit. 3d. cache miss (write-through) a write of the specified access size is performed to the external memory corresponding to the effective address. in this case, a write to cache is not performed. 3e. cache miss (with copy-back/write-back) the tag and data field of the cache line indexed by effective address bits [13:5] are first saved in the write-back buffer, and then a data write in accordance with the access size (quadword/longword/word/byte) is performed for the data indexed by bits [4:0] of the effective address of the data field of the cache line indexed by effective address bits [13:5]. then, data is read into the cache line from the external memory space corresponding to the effective address. data reading is performed, using the wraparound method, in order from the longword data corresponding to the effective address, and one cache line of data is read excluding the written data. during this time, the cpu can execute the next processing. when reading of one line of data is completed, the tag corresponding to the effective address is recorded in the cache, and 1 is written to the v bit and u bit. the data in the write-back buffer is then written back to external memory. rev. 5.0, 04/01, page 65 of 394 4.3.4 write-back buffer in order to give priority to data reads to the cache and improve performance, the sh-4 has a write- back buffer which holds the relevant cache entry when it becomes necessary to purge a dirty cache entry into external memory as the result of a cache miss. the write-back buffer contains one cache line of data and the physical address of the purge destination. lw7 physical address bits [28:5] lw6 lw5 lw4 lw3 lw2 lw1 lw0 figure 4.3 configuration of write-back buffer 4.3.5 write-through buffer the sh-4 has a 64-bit buffer for holding write data when writing data in write-through mode or writing to a non-cacheable area. this allows the cpu to proceed to the next operation as soon as the write to the write-through buffer is completed, without waiting for completion of the write to external memory. physical address bits [28:0] lw1 lw0 figure 4.4 configuration of write-through buffer 4.3.6 ram mode setting ccr.ora to 1 enables 8 kbytes of the operand cache to be used as ram. the operand cache entries used as ram are entries 128 to 255 and 384 to 511 . other entries can still be used as cache. ram can be accessed using addresses h'7c00 0000 to h'7fff ffff. byte-, word-, longword-, and quadword-size data reads and writes can be performed in the operand cache ram area. instruction fetches cannot be performed in this area. an example of ram use is shown below. here, the 4 kbytes comprising oc entries 128 to 256 are designated as ram area 1, and the 4 kbytes comprising oc entries 384 to 511 as ram area 2. rev. 5.0, 04/01, page 66 of 394 ? when oc index mode is off (ccr.oix = 0) h'7c00 0000 to h'7c00 0fff (4 kb): corresponds to ram area 1 h'7c00 1000 to h'7c00 1fff (4 kb): corresponds to ram area 1 h'7c00 2000 to h'7c00 2fff (4 kb): corresponds to ram area 2 h'7c00 3000 to h'7c00 3fff (4 kb): corresponds to ram area 2 h'7c00 4000 to h'7c00 4fff (4 kb): corresponds to ram area 1 :: : ram areas 1 and 2 then repeat every 8 kbytes up to h'7fff ffff. thus, to secure a continuous 8-kbyte ram area, the area from h'7c00 1000 to h'7c00 2fff can be used, for example. ? when oc index mode is on (ccr.oix = 1) h'7c00 0000 to h'7c00 0fff (4 kb): corresponds to ram area 1 h'7c00 1000 to h'7c00 1fff (4 kb): corresponds to ram area 1 h'7c00 2000 to h'7c00 2fff (4 kb): corresponds to ram area 1 :: : h'7dff f000 to h'7dff ffff (4 kb): corresponds to ram area 1 h'7e00 0000 to h'7e00 0fff (4 kb): corresponds to ram area 2 h'7e00 1000 to h'7e00 1fff (4 kb): corresponds to ram area 2 :: : h'7fff f000 to h'7fff ffff (4 kb): corresponds to ram area 2 as the distinction between ram areas 1 and 2 is indicated by address bit [25], the area from h'7dff f000 to h'7e00 0fff should be used to secure a continuous 8-kbyte ram area. 4.3.7 oc index mode setting ccr.oix to 1 enables oc indexing to be performed using bit [25] of the effective address. this is called oc index mode. in normal mode, with ccr.oix cleared to 0, oc indexing is performed using bits [13:5] of the effective address; therefore, when 16 kbytes or more of consecutive data is handled, the oc is fully used by this data. this results in frequent cache misses. using index mode allows the oc to be handled as two 8-kbyte areas by means of effective address bit [25], providing efficient use of the cache. rev. 5.0, 04/01, page 67 of 394 4.3.8 coherency between cache and external memory coherency between cache and external memory should be assured by software. in the sh-4, the following four new instructions are supported for cache operations. for details of these instructions, see section 9, instruction descriptions. invalidate instruction: ocbi @rn cache invalidation (no write-back) purge instruction: ocbp @rn cache invalidation (with write-back) write-back instruction: ocbwb @rn cache write-back allocate instruction: movca.l r0,@rn cache allocation 4.3.9 prefetch operation the sh-4 supports a prefetch instruction to reduce the cache fill penalty incurred as the result of a cache miss. if it is known that a cache miss will result from a read or write operation, it is possible to fill the cache with data beforehand by means of the prefetch instruction to prevent a cache miss due to the read or write operation, and so improve software performance. if a prefetch instruction is executed for data already held in the cache, or if the prefetch address results in a utlb miss or a protection violation, the result is no operation, and an exception is not generated. for details of the prefetch instruction, see section 9.74, pref. prefetch instruction: pref @rn rev. 5.0, 04/01, page 68 of 394 4.4 instruction cache (ic) 4.4.1 configuration figure 4.5 shows the configuration of the instruction cache. lw0 32 bits lw1 32 bits lw2 32 bits lw3 32 bits lw4 32 bits lw5 32 bits lw6 32 bits lw7 32 bits 255 19 bits 1 bit tag v address array longword (lw) selection data array 0 read data hit signal compare 31 26 25 5 4 3 2 1 mmu iix [12] [11:5] entry selection effective address 8 3 22 19 13 12 11 10 9 0 figure 4.5 configuration of instruction cache rev. 5.0, 04/01, page 69 of 394 the instruction cache consists of 256 cache lines, each composed of a 19-bit tag, v bit, and 32- byte data (16 instructions). ? tag stores the upper 19 bits of the 29-bit external address of the data line to be cached. the tag is not initialized by a power-on or manual reset. ? v bit (validity bit) indicates that valid data is stored in the cache line. when this bit is 1, the cache line data is valid. the v bit is initialized to 0 by a power-on reset, but retains its value in a manual reset. ? data array the data field holds 32 bytes (256 bits) of data per cache line. the data array is not initialized by a power-on or manual reset. 4.4.2 read operation when the ic is enabled (ccr.ice = 1) and instruction fetches are performed by means of an effective address from a cacheable area, the instruction cache operates as follows: 1. the tag and v bit are read from the cache line indexed by effective address bits [12:5]. 2. the tag is compared with bits [28:10] of the address resulting from effective address translation by the mmu: ? if the tag matches and the v bit is 1 (3a) if the tag matches and the v bit is 0 (3b) if the tag does not match and the v bit is 0 (3b) if the tag does not match and the v bit is 1 (3b) 3a. cache hit the data indexed by effective address bits [4:2] is read as an instruction from the data field of the cache line indexed by effective address bits [12:5]. 3b. cache miss data is read into the cache line from the external memory space corresponding to the effective address. data reading is performed, using the wraparound method, in order from the longword data corresponding to the effective address, and when the corresponding data arrives in the cache, the read data is returned to the cpu as an instruction. when reading of one line of data is completed, the tag corresponding to the effective address is recorded in the cache, and 1 is written to the v bit. rev. 5.0, 04/01, page 70 of 394 4.4.3 ic index mode setting ccr.iix to 1 enables ic indexing to be performed using bit [25] of the effective address. this is called ic index mode. in normal mode, with ccr.iix cleared to 0, ic indexing is performed using bits [12:5] of the effective address; therefore, when 8 kbytes or more of consecutive program instructions are handled, the ic is fully used by this program. this results in frequent cache misses. using index mode allows the ic to be handled as two 4-kbyte areas by means of effective address bit [25], providing efficient use of the cache. 4.5 memory-mapped cache configuration in the sh7750 series, to enable the ic and oc to be managed by software, their contents can be read and written by a p2 area program with a mov instruction in privileged mode. in privileged mode in the sh7751, the contents of oc can be read and written by a p1 or p2 area program with a mov instruction, and the contents of ic can be read and written by a p2 area program with a mov instruction. operation is not guaranteed if access is made from a program in another area. in this case, a branch to the other area should be made at least 8 instructions after this mov instruction. the ic and oc are allocated to the p4 area in physical memory space. only data accesses can be used on both the ic address array and data array and the oc address array and data array, and accesses are always longword-size. instruction fetches cannot be performed in these areas. for reserved bits, a write value of 0 should be specified; their read value is undefined. 4.5.1 ic address array the ic address array is allocated to addresses h'f000 0000 to h'f0ff ffff in the p4 area. an address array access requires a 32-bit address field specification (when reading or writing) and a 32-bit data field specification. the entry to be accessed is specified in the address field, and the write tag and v bit are specified in the data field. in the address field, bits [31:24] have the value h'f0 indicating the ic address array, and the entry is specified by bits [12:5]. ccr.iix has no effect on this entry specification. the address array bit [3] association bit (a bit) specifies whether or not association is performed when writing to the ic address array. as only longword access is used, 0 should be specified for address field bits [1:0]. in the data field, the tag is indicated by bits [31:10], and the v bit by bit [0]. as the ic address array tag is 19 bits in length, data field bits [31:29] are not used in the case of a write in which association is not performed. data field bits [31:29] are used for the virtual address specification only in the case of a write in which association is performed. the following three kinds of operation can be used on the ic address array: rev. 5.0, 04/01, page 71 of 394 1. ic address array read the tag and v bit are read into the data field from the ic entry corresponding to the entry set in the address field. in a read, associative operation is not performed regardless of whether the association bit specified in the address field is 1 or 0. 2. ic address array write (non-associative) the tag and v bit specified in the data field are written to the ic entry corresponding to the entry set in the address field. the a bit in the address field should be cleared to 0. 3. ic address array write (associative) when a write is performed with the a bit in the address field set to 1, the tag stored in the entry specified in the address field is compared with the tag specified in the data field. if the mmu is enabled at this time, comparison is performed after the virtual address specified by data field bits [31:10] has been translated to a physical address using the itlb. if the addresses match and the v bit is 1, the v bit specified in the data field is written into the ic entry. this operation is used to invalidate a specific ic entry. if an itlb miss occurs during address translation, or the comparison shows a mismatch, no operation results and the write is not performed. if an instruction tlb multiple hit exception occurs during address translation, processing switches to the instruction tlb multiple hit exception handling routine. address field 31 23 12 543210 1 1 1 1 0 0 0 0 entry a data field 31 10 9 1 0 v tag address v a 24 13 : validity bit : association bit : reserved bits (0 write value, undefined read value) figure 4.6 memory-mapped ic address array 4.5.2 ic data array the ic data array is allocated to addresses h'f100 0000 to h'f1ff ffff in the p4 area. a data array access requires a 32-bit address field specification (when reading or writing) and a 32-bit data field specification. the entry to be accessed is specified in the address field, and the longword data to be written is specified in the data field. in the address field, bits [31:24] have the value h'f1 indicating the ic data array, and the entry is specified by bits [12:5]. ccr.iix has no effect on this entry specification. address field bits [4:2] are used for the longword data specification in the entry. as only longword access is used, 0 should be specified for address field bits [1:0]. rev. 5.0, 04/01, page 72 of 394 the data field is used for the longword data specification. the following two kinds of operation can be used on the ic data array: 1. ic data array read longword data is read into the data field from the data specified by the longword specification bits in the address field in the ic entry corresponding to the entry set in the address field. 2. ic data array write the longword data specified in the data field is written for the data specified by the longword specification bits in the address field in the ic entry corresponding to the entry set in the address field. address field 31 23 12 5 4 2 1 0 11110001 e ntry l data field 31 0 longword data l 24 13 : longword specification bits : reserved bits (0 write value, undefined read value) figure 4.7 memory-mapped ic data array 4.5.3 oc address array the oc address array is allocated to addresses h'f400 0000 to h'f4ff ffff in the p4 area. an address array access requires a 32-bit address field specification (when reading or writing) and a 32-bit data field specification. the entry to be accessed is specified in the address field, and the write tag, u bit, and v bit are specified in the data field. in the address field, bits [31:24] have the value h'f4 indicating the oc address array, and the entry is specified by bits [13:5]. ccr.oix and ccr.ora have no effect on this entry specification. the address array bit [3] association bit (a bit) specifies whether or not association is performed when writing to the oc address array. as only longword access is used, 0 should be specified for address field bits [1:0]. in the data field, the tag is indicated by bits [31:10], the u bit by bit [1], and the v bit by bit [0]. as the oc address array tag is 19 bits in length, data field bits [31:29] are not used in the case of a write in which association is not performed. data field bits [31:29] are used for the virtual address specification only in the case of a write in which association is performed. rev. 5.0, 04/01, page 73 of 394 the following three kinds of operation can be used on the oc address array: 1. oc address array read the tag, u bit, and v bit are read into the data field from the oc entry corresponding to the entry set in the address field. in a read, associative operation is not performed regardless of whether the association bit specified in the address field is 1 or 0. 2. oc address array write (non-associative) the tag, u bit, and v bit specified in the data field are written to the oc entry corresponding to the entry set in the address field. the a bit in the address field should be cleared to 0. when a write is performed to a cache line for which the u bit and v bit are both 1, after write- back of that cache line, the tag, u bit, and v bit specified in the data field are written. 3. oc address array write (associative) when a write is performed with the a bit in the address field set to 1, the tag stored in the entry specified in the address field is compared with the tag specified in the data field. if the mmu is enabled at this time, comparison is performed after the virtual address specified by data field bits [31:10] has been translated to a physical address using the utlb. if the addresses match and the v bit is 1, the u bit and v bit specified in the data field are written into the oc entry. this operation is used to invalidate a specific oc entry. if the oc entry u bit is 1, and 0 is written to the v bit or to the u bit, write-back is performed. if an utlb miss occurs during address translation, or the comparison shows a mismatch, no operation results and the write is not performed. if a data tlb multiple hit exception occurs during address translation, processing switches to the data tlb multiple hit exception handling routine. address field 31 23 543210 11110100 e ntry a data field 31 10 9 1 0 v tag 24 13 14 2 u v u a : validity bit : dirty bit : association bit : reserved bits (0 write value, undefined read value) figure 4.8 memory-mapped oc address array rev. 5.0, 04/01, page 74 of 394 4.5.4 oc data array the oc data array is allocated to addresses h'f500 0000 to h'f5ff ffff in the p4 area. a data array access requires a 32-bit address field specification (when reading or writing) and a 32-bit data field specification. the entry to be accessed is specified in the address field, and the longword data to be written is specified in the data field. in the address field, bits [31:24] have the value h'f5 indicating the oc data array, and the entry is specified by bits [13:5]. ccr.oix and ccr.ora have no effect on this entry specification. address field bits [4:2] are used for the longword data specification in the entry. as only longword access is used, 0 should be specified for address field bits [1:0]. the data field is used for the longword data specification. the following two kinds of operation can be used on the oc data array: 1. oc data array read longword data is read into the data field from the data specified by the longword specification bits in the address field in the oc entry corresponding to the entry set in the address field. 2. oc data array write the longword data specified in the data field is written for the data specified by the longword specification bits in the address field in the oc entry corresponding the entry set in the address field. this write does not set the u bit to 1 on the address array side. address field 31 23 54 210 11110101 e ntry l data field 31 0 longword data 24 13 14 l : longword specification bits : reserved bits (0 write value, undefined read value) figure 4.9 memory-mapped oc data array rev. 5.0, 04/01, page 75 of 394 4.6 store queues two 32-byte store queues (sqs) are supported to perform high-speed writes to external memory. in the sh7750s and sh7751, when not using the sqs, the low power dissipation power-down modes, in which sq functions are stopped, can be used. the queue address control registers (qacr0 and qacr1) cannot be accessed while sq functions are stopped. see section 9, power- down modes, for the procedure for stopping sq functions. 4.6.1 sq configuration there are two 32-byte store queues, sq0 and sq1, as shown in figure 4.10. these two store queues can be set independently. sq0 sq0[0] sq0[1] sq0[2] sq0[3] sq0[4] sq0[5] sq0[6] sq0[7] sq1 sq1[0] sq1[1] sq1[2] sq1[3] sq1[4] sq1[5] sq1[6] sq1[7] 4b 4b 4b 4b 4b 4b 4b 4b figure 4.10 store queue configuration 4.6.2 sq writes a write to the sqs can be performed using a store instruction on p4 area h'e000 0000 to h'e3ff fffc. a longword or quadword access size can be used. the meaning of the address bits is as follows: [31:26]: 111000 store queue specification [25:6]: don?t care used for external memory transfer/access right [5]: 0/1 0: sq0 specification 1: sq1 specification [4:2]: lw specification specifies longword position in sq0/sq1 [1:0] 00 fixed at 0 4.6.3 transfer to external memory transfer from the sqs to external memory can be performed with a prefetch instruction (pref). issuing a pref instruction for p4 area h'e000 0000 to h'e3ff fffc starts a transfer from the sqs to external memory. the transfer length is fixed at 32 bytes, and the start address is always at a 32-byte boundary. while the contents of one sq are being transferred to external memory, the other sq can be written to without a penalty cycle, but writing to the sq involved in the transfer to external memory is deferred until the transfer is completed. rev. 5.0, 04/01, page 76 of 394 the sq transfer destination external memory address bit [28:0] specification is as shown below, according to whether the mmu is on or off. ? when mmu is on (mmucr.at = 1) the sq area (h'e000 0000 to h'e3ff ffff) is set in vpn of the utlb, and the transfer destination external memory address in ppn. the asid, v, sz, sh, pr, and d bits have the same meaning as for normal address translation, but the c and wt bits have no meaning with regard to this page. it is not possible to perform data transfer to a pcmcia interface area using the sqs. when a prefetch instruction is issued for the sq area, address translation is performed and external memory address bits [28:10] are generated in accordance with the sz bit specification. for external memory address bits [9:5], the address prior to address translation is generated in the same way as when the mmu is off. external memory address bits [4:0] are fixed at 0. transfer from the sqs to external memory is performed to this address. ? when mmu is off (mmucr.at = 0) the sq area (h'e000 0000 to h'e3ff ffff) is specified as the address at which a prefetch is performed. the meaning of address bits [31:0] is as follows: [31:26]: 111000 store queue specification [25:6]: address external memory address bits [25:6] [5]: 0/1 0: sq0 specification 1: sq1 specification and external memory address bit [5] [4:2]: don?t care no meaning in a prefetch [1:0] 00 fixed at 0 external memory address bits [28:26], which cannot be generated from the above address, are generated from the qacr0/1 registers. qacr0 [4:2]: external memory address bits [28:26] corresponding to sq0 qacr1 [4:2]: external memory address bits [28:26] corresponding to sq1 external memory address bits [4:0] are always fixed at 0 since burst transfer starts at a 32-byte boundary. in the sh7750, it is not possible to perform data transfer to a pcmcia interface area using the sqs. in the sh7750s and sh7751, data transfer to a pcmcia interface area is always performed using the values of the sa bit and tc bit in ptea. rev. 5.0, 04/01, page 77 of 394 4.6.4 sq protection it is possible to set protection against sq writes and transfers to external memory. if an sq write violates the protection setting, an exception will be generated but the sq contents will be corrupted. if a transfer from the sqs to external memory (prefetch instruction) violates the protection setting, the transfer to external memory will be inhibited and an exception will be generated. ? when mmu is on operation is in accordance with the address translation information recorded in the utlb, and mmucr.sqmd. write type exception judgment is performed for writes to the sqs, and read type for transfer from the sqs to external memory (pref instruction), and a tlb miss exception, protection violation exception, or initial page write exception is generated. however, if sq access is enabled, in privileged mode only, by mmucr.sqmd, an address error will be flagged in user mode even if address translation is successful. ? when mmu is off operation is in accordance with mmucr.sqmd. 0: privileged/user access possible 1: privileged access possible if the sq area is accessed in user mode when mmucr.sqmd is set to 1, an address error will be flagged. rev. 5.0, 04/01, page 78 of 394 rev. 5.0, 04/01, page 79 of 394 section 5 exceptions 5.1 overview 5.1.1 features exception handling is processing handled by a special routine, separate from normal program processing, that is executed by the cpu in case of abnormal events. for example, if the executing instruction ends abnormally, appropriate action must be taken in order to return to the original program sequence, or report the abnormality before terminating the processing. the process of generating an exception handling request in response to abnormal termination, and passing control to a user-written exception handling routine, in order to support such functions, is given the generic name of exception handling. sh-4 exception handling is of three kinds: for resets, general exceptions, and interrupts. 5.1.2 register configuration the registers used in exception handling are shown in table 5.1. table 5.1 exception-related registers name abbrevia- tion r/w initial value* 1 p4 address* 2 area 7 address* 2 access size trapa exception register tra r/w undefined h'ff00 0020 h'1f00 0020 32 exception event register expevt r/w h'0000 0000/ h'0000 0020* 1 h'ff00 0024 h'1f00 0024 32 interrupt event register intevt r/w undefined h'ff00 0028 h'1f00 0028 32 notes: 1. h'0000 0000 is set in a power-on reset, and h'0000 0020 in a manual reset. 2. this is the address when using the virtual/physical address space p4 area. when making an access from physical address space area 7 using the tlb, the upper 3 bits of the address are ignored. rev. 5.0, 04/01, page 80 of 394 5.2 register descriptions there are three registers related to exception handling. these are allocated to memory, and can be accessed by specifying the p4 address or area 7 address. 1. the exception event register (expevt) resides at p4 address h'ff00 0024, and contains a 12- bit exception code. the exception code set in expevt is that for a reset or general exception event. the exception code is set automatically by hardware when an exception occurs. expevt can also be modified by software. 2. the interrupt event register (intevt) resides at p4 address h'ff00 0028, and contains a 12- bit (sh7750 series) or 14-bit (sh7751) exception code. the exception code set in intevt is that for an interrupt request. the exception code is set automatically by hardware when an exception occurs. intevt can also be modified by software. 3. the trapa exception register (tra) resides at p4 address h'ff00 0020, and contains 8-bit immediate data (imm) for the trapa instruction. tra is set automatically by hardware when a trapa instruction is executed. tra can also be modified by software. the bit configurations of expevt, intevt, and tra are shown in figure 5.1. 31 0 0 0 0 0 0 0 31 10 9 1 0 0: imm: reserved bits. these bits are always read as 0, and should only be written with 0. 8-bit immediate data of the trapa instruction 12 11 2 expevt (sh7750 series, sh7751), intevt (sh7750 series) tra imm exception code 31 0 0 0 14 13 intevt (sh7751) exception code figure 5.1 register bit configurations rev. 5.0, 04/01, page 81 of 394 5.3 exception handling functions 5.3.1 exception handling flow in exception handling, the contents of the program counter (pc), status register (sr), and r15 are saved in the saved program counter (spc), saved status register (ssr), and saved general register15 (sgr), and the cpu starts execution of the appropriate exception handling routine according to the vector address. an exception handling routine is a program written by the user to handle a specific exception. the exception handling routine is terminated and control returned to the original program by executing a return-from-exception instruction (rte). this instruction restores the pc and sr contents and returns control to the normal processing routine at the point at which the exception occurred. the sgr contents are not written back to r15 by an rte instruction. the basic processing flow is as follows. see section 2, data formats and registers, for the meaning of the individual sr bits. 1. the pc, sr, and r15 contents are saved in spc, ssr, and sgr. 2. the block bit (bl) in sr is set to 1. 3. the mode bit (md) in sr is set to 1. 4. the register bank bit (rb) in sr is set to 1. 5. in a reset, the fpu disable bit (fd) in sr is cleared to 0. 6. the exception code is written to bits 11?0 of the exception event register (expevt): sh7750 series, bits 13?0 of the exception event register (expevt): sh7751 or interrupt event register (intevt). 7. the cpu branches to the determined exception handling vector address, and the exception handling routine begins. 5.3.2 exception handling vector addresses the reset vector address is fixed at h'a000 0000. exception and interrupt vector addresses are determined by adding the offset for the specific event to the vector base address, which is set by software in the vector base register (vbr). in the case of the tlb miss exception, for example, the offset is h'0000 0400, so if h'9c08 0000 is set in vbr, the exception handling vector address will be h'9c08 0400. if a further exception occurs at the exception handling vector address, a duplicate exception will result, and recovery will be difficult; therefore, fixed physical addresses (p1, p2) should be specified for vector addresses. rev. 5.0, 04/01, page 82 of 394 5.4 exception types and priorities table 5.2 shows the types of exceptions, with their relative priorities, vector addresses, and exception/interrupt codes. table 5.2 exceptions exception category execution mode exception priority level priority order vector address offset exception code power-on reset 1 1 h'a000 0000 ? h?000 manual reset 1 2 h'a000 0000 ? h?020 hitachi-udi reset 1 1 h'a000 0000 ? h?000 instruction tlb multiple-hit exception 1 3 h'a000 0000 ? h?140 reset abort type data tlb multiple-hit exception 1 4 h'a000 0000 ? h?140 user break before instruction execution* 1 2 0 (vbr/dbr) h'100/? h'1e0 instruction address error 2 1 (vbr) h'100 h'0e0 instruction tlb miss exception 2 2 (vbr) h'400 h'040 instruction tlb protection violation exception 2 3 (vbr) h'100 h'0a0 general illegal instruction exception 2 4 (vbr) h'100 h'180 slot illegal instruction exception 2 4 (vbr) h'100 h'1a0 general fpu disable exception 2 4 (vbr) h'100 h'800 slot fpu disable exception 2 4 (vbr) h'100 h'820 data address error (read) 2 5 (vbr) h'100 h'0e0 data address error (write) 2 5 (vbr) h'100 h'100 data tlb miss exception (read) 2 6 (vbr) h'400 h'040 data tlb miss exception (write) 2 6 (vbr) h'400 h'060 data tlb protection violation exception (read) 2 7 (vbr) h'100 h'0a0 data tlb protection violation exception (write) 2 7 (vbr) h'100 h'0c0 fpu exception 2 8 (vbr) h'100 h'120 re- execution type initial page write exception 2 9 (vbr) h'100 h'080 unconditional trap (trapa) 2 4 (vbr) h'100 h'160 general exception completion type user break after instruction execution* 1 2 10 (vbr/dbr) h'100/? h'1e0 rev. 5.0, 04/01, page 83 of 394 table 5.2 exceptions (cont) exception category execution mode exception priority level priority order vector address offset exception code nonmaskable interrupt 3 ? (vbr) h'600 h'1c0 0 h'200 1 h'220 2 h'240 3 h'260 4 h'280 5h'2a0 6h'2c0 7h'2e0 8 h'300 9 h'320 a h'340 b h'360 c h'380 dh'3a0 external interrupts irl3? irl0 e 4* 2 (vbr) h'600 h'3c0 tmu0 tuni0 h'400 tmu1 tuni1 h'420 tuni2 h'440 tmu2 ticpi2 h'460 tmu3* 3 tuni3 h'b00 tmu4* 3 tuni4 h'b80 ati h'480 pri h'4a0 rtc cui h'4c0 sci eri h'4e0 rxi h'500 txi h'520 tei h'540 wdt iti h'560 rcmi h'580 ref rovi 4* 2 (vbr) h'600 h'5a0 interrupt completion type peripheral module interrupt (module/ source) h-udi h-udi h'600 gpio gpioi h'620 rev. 5.0, 04/01, page 84 of 394 table 5.2 exceptions (cont) exception category execution mode exception priority level priority order vector address offset exception code dmte0 h'640 dmte1 h'660 dmte2 h'680 dmte3 h'6a0 dmac dmae h'6c0 eri h'700 rxi h'720 bri h'740 scif txi h'760 pciserr h'a00 pcierr h'ae0 pcipwdwn h'ac0 pcipwon h'aa0 pcidma0 h'a80 pcidma1 h'a60 pcidma2 h'a40 interrupt completion type peripheral module interrupt (module/ source) pcic* 3 pcidma3 4* 2 (vbr) h'600 h'a20 priority: priority is first assigned by priority level, then by priority order within each level (the lowest number represents the highest priority). exception transition destination: control passes to h'a000 0000 in a reset, and to [vbr + offset] in other cases. exception code: stored in expevt for a reset or general exception, and in intevt for an interrupt. irl: interrupt request level (pins irl3?irl0). module/source: see the sections on the relevant peripheral modules. notes: 1. when brcr.ubde = 1, pc = dbr. in other cases, pc = vbr + h'100. 2. the priority order of external interrupts and peripheral module interrupts can be set by software. 3. sh7751 exceptions only. not provided in the sh7750 series. rev. 5.0, 04/01, page 85 of 394 5.5 exception flow 5.5.1 exception flow figure 5.2 shows an outline flowchart of the basic operations in instruction execution and exception handling. for the sake of clarity, the following description assumes that instructions are executed sequentially, one by one. figure 5.2 shows the relative priority order of the different kinds of exceptions (reset/general exception/interrupt). register settings in the event of an exception are shown only for ssr, spc, sgr, expevt/intevt, sr, and pc, but other registers may be set automatically by hardware, depending on the exception. for details, see section 5.6, description of exceptions. also, see section 5.6.4, priority order with multiple exceptions, for exception handling during execution of a delayed branch instruction and a delay slot instruction, and in the case of instructions in which two data accesses are performed. execute next instruction is highest- priority exception re-exception type? cancel instruction execution result yes yes yes no no no no yes ssr sr spc pc sgr r15 expevt/intevt exception code sr.{md,rb,bl} 111 pc (brcr.ubde=1 && user_break? dbr: (vbr + offset)) expevt exception code sr. {md, rb, bl, fd, imask} 11101111 pc h'a000 0000 interrupt requested? general exception requested? reset requested? figure 5.2 instruction execution and exception handling rev. 5.0, 04/01, page 86 of 394 5.5.2 exception source acceptance a priority ranking is provided for all exceptions for use in determining which of two or more simultaneously generated exceptions should be accepted. five of the general exceptions?the general illegal instruction exception, slot illegal instruction exception, general fpu disable exception, slot fpu disable exception, and unconditional trap exception?are detected in the process of instruction decoding, and do not occur simultaneously in the instruction pipeline. these exceptions therefore all have the same priority. general exceptions are detected in the order of instruction execution. however, exception handling is performed in the order of instruction flow (program order). thus, an exception for an earlier instruction is accepted before that for a later instruction. an example of the order of acceptance for general exceptions is shown in figure 5.3. rev. 5.0, 04/01, page 87 of 394 if if id id ex ex ma ma wb wb tlb miss (data access) pipeline flow: order of detection: instruction n instruction n+1 general illegal instruction exception (instruction n+1) and tlb miss (instruction n+2) are detected simultaneously order of exception handling: tlb miss (instruction n) program order 1 instruction n+2 general illegal instruction exception if id ex ma wb if id ex ma wb tlb miss (instruction access) 2 3 4 if: instruction fetch id: instruction decode ex: instruction execution ma: memory access wb: write-back instruction n+3 tlb miss (instruction n) re-execution of instruction n general illegal instruction exception (instruction n+1) re-execution of instruction n+1 tlb miss (instruction n+2) re-execution of instruction n+2 execution of instruction n+3 figure 5.3 example of general exception acceptance order rev. 5.0, 04/01, page 88 of 394 5.5.3 exception requests and bl bit when the bl bit in sr is 0, exceptions and interrupts are accepted. when the bl bit in sr is 1 and an exception other than a user break is generated, the cpu?s internal registers and the registers of the other modules are set to their states following a manual reset, and the cpu branches to the same address as in a reset (h'a000 0000). for the operation in the event of a user break, see user break controller in the hardware manual. if an ordinary interrupt occurs, the interrupt request is held pending and is accepted after the bl bit has been cleared to 0 by software. if a nonmaskable interrupt (nmi) occurs, it can be held pending or accepted according to the setting made by software. thus, normally, spc and ssr are saved and then the bl bit in sr is cleared to 0, to enable multiple exception state acceptance. 5.5.4 return from exception handling the rte instruction is used to return from exception handling. when the rte instruction is executed, the spc contents are restored to pc and the ssr contents to sr, and the cpu returns from the exception handling routine by branching to the spc address. if spc and ssr were saved to external memory, set the bl bit in sr to 1 before restoring the spc and ssr contents and issuing the rte instruction. 5.6 description of exceptions the various exception handling operations are described here, covering exception sources, transition addresses, and processor operation when a transition is made. 5.6.1 resets (1) power-on reset ? sources: ? sck2 pin high level and reset pin low level (sh7750 series)/ reset pin low level (sh7751) ? when the watchdog timer overflows while the wt/ it bit is set to 1 and the rsts bit is cleared to 0 in wtcsr. for details, see clock oscillation circuits in hardware manual. ? transition address: h'a000 0000 ? transition operations: exception code h'000 is set in expevt, initialization of vbr and sr is performed, and a branch is made to pc = h'a000 0000. rev. 5.0, 04/01, page 89 of 394 in the initialization processing, the vbr register is set to h'0000 0000, and in sr, the md, rb, and bl bits are set to 1, the fd bit is cleared to 0, and the interrupt mask bits (i3?i0) are set to b?1111. cpu and on-chip peripheral module initialization is performed. for details, see the register descriptions in the relevant sections. for some cpu functions, the trst pin and reset pin must be driven low. it is therefore essential to execute a power-on reset and drive the trst pin low when powering on. if the sck2 pin is changed to the low level while the reset pin is low, a manual reset may occur after the power-on reset operation. do not drive the sck2 pin low during this interval (see electrical characteristics in the hardware manual). in the sh7750 series, if the sck2 pin is changed to the low level while the reset pin is low, a manual reset may occur after the power-on reset operation. do not drive the sck2 pin low during this interval. for details, see electrical characteristics in the hardware manual. in the sh7751, if the reset pin is driven high before the mreset pin while both these pins are low, a manual reset may occur after the power-on reset operation. the reset pin must be driven high at the same time as, or after, the mreset pin. power_on_reset() { expevt = h'00000000; vbr = h'00000000; sr.md = 1; sr.rb = 1; sr.bl = 1; sr.(i0-i3) = b'1111; sr.fd=0; initialize_cpu(); initialize_module(poweron); pc = h'a0000000; } rev. 5.0, 04/01, page 90 of 394 (2) manual reset ? sources: ? sck2 pin low level and reset pin low level (sh7750 series)/ mreset pin low level and reset pin high level (sh7751) ? when a general exception other than a user break occurs while the bl bit is set to 1 in sr ? when the watchdog timer overflows while the wt/ it bit is set to 1 and the rsts bit is set to 1 in wtcsr. for details, see clock oscillation circuits in the hardware manual. ? transition address: h'a000 0000 ? transition operations: exception code h'020 is set in expevt, initialization of vbr and sr is performed, and a branch is made to pc = h'a000 0000. in the initialization processing, the vbr register is set to h'0000 0000, and in sr, the md, rb, and bl bits are set to 1, the fd bit is cleared to 0, and the interrupt mask bits (i3?i0) are set to b'1111. cpu and on-chip peripheral module initialization is performed. for details, see the register descriptions in the relevant sections. manual_reset() { expevt = h'00000020; vbr = h'00000000; sr.md = 1; sr.rb = 1; sr.bl = 1; sr.(i0-i3) = b'1111; sr.fd = 0; initialize_cpu(); initialize_module(manual); pc = h'a0000000; } rev. 5.0, 04/01, page 91 of 394 table 5.3 types of reset (sh7750 series) reset state transition conditions internal states type sck2 sck2 sck2 sck2 reset reset reset reset cpu on-chip peripheral modules power-on reset high low initialized manual reset low low initialized see register configuration in individual sections of the hardware manual table 5.4 types of reset (sh7751) reset state transition conditions internal states type mreset mreset mreset mreset reset reset reset reset cpu on-chip peripheral modules power-on reset ? low initialized manual reset low high initialized see register configuration in individual sections of the hardware manual rev. 5.0, 04/01, page 92 of 394 (3) h-udi reset ? source: sdir.ti3?ti0 = b'0110 (negation) or b'0111 (assertion) ? transition address: h'a000 0000 ? transition operations: exception code h'000 is set in expevt, initialization of vbr and sr is performed, and a branch is made to pc = h'a000 0000. in the initialization processing, the vbr register is set to h'0000 0000, and in sr, the md, rb, and bl bits are set to 1, the fd bit is cleared to 0, and the interrupt mask bits (i3?i0) are set to b'1111. cpu and on-chip peripheral module initialization is performed. for details, see the register descriptions in the relevant sections. h-udi_reset() { expevt = h'00000000; vbr = h'00000000; sr.md = 1; sr.rb = 1; sr.bl = 1; sr.(i0-i3) = b'1111; sr.fd = 0; initialize_cpu(); initialize_module(poweron); pc = h'a0000000; } rev. 5.0, 04/01, page 93 of 394 (4) instruction tlb multiple-hit exception ? source: multiple itlb address matches ? transition address: h'a000 0000 ? transition operations: the virtual address (32 bits) at which this exception occurred is set in tea, and the corresponding virtual page number (22 bits) is set in pteh [31:10]. asid in pteh indicates the asid when this exception occurred. exception code h'140 is set in expevt, initialization of vbr and sr is performed, and a branch is made to pc = h'a000 0000. in the initialization processing, the vbr register is set to h'0000 0000, and in sr, the md, rb, and bl bits are set to 1, the fd bit is cleared to 0, and the interrupt mask bits (i3?i0) are set to b'1111. cpu and on-chip peripheral module initialization is performed in the same way as in a manual reset. for details, see the register descriptions in the relevant sections. tlb_multi_hit() { tea = exception_address; pteh.vpn = page_number; expevt = h'00000140; vbr = h'00000000; sr.md = 1; sr.rb = 1; sr.bl = 1; sr.(i0-i3) = b'1111; sr.fd = 0; initialize_cpu(); initialize_module(manual); pc = h'a0000000; } rev. 5.0, 04/01, page 94 of 394 (5) operand tlb multiple-hit exception ? source: multiple utlb address matches ? transition address: h'a000 0000 ? transition operations: the virtual address (32 bits) at which this exception occurred is set in tea, and the corresponding virtual page number (22 bits) is set in pteh [31:10]. asid in pteh indicates the asid when this exception occurred. exception code h'140 is set in expevt, initialization of vbr and sr is performed, and a branch is made to pc = h'a000 0000. in the initialization processing, the vbr register is set to h'0000 0000, and in sr, the md, rb, and bl bits are set to 1, the fd bit is cleared to 0, and the interrupt mask bits (i3?i0) are set to b'1111. cpu and on-chip peripheral module initialization is performed in the same way as in a manual reset. for details, see the register descriptions in the relevant sections. tlb_multi_hit() { tea = exception_address; pteh.vpn = page_number; expevt = h'00000140; vbr = h'00000000; sr.md = 1; sr.rb = 1; sr.bl = 1; sr.(i0-i3) = b'1111; sr.fd = 0; initialize_cpu(); initialize_module(manual); pc = h'a0000000; } rev. 5.0, 04/01, page 95 of 394 5.6.2 general exceptions (1) data tlb miss exception ? source: address mismatch in utlb address comparison ? transition address: vbr + h'0000 0400 ? transition operations: the virtual address (32 bits) at which this exception occurred is set in tea, and the corresponding virtual page number (22 bits) is set in pteh [31:10]. asid in pteh indicates the asid when this exception occurred. the pc and sr contents for the instruction at which this exception occurred are saved in spc and ssr, and the contents of r15 are saved in sgr. exception code h'040 (for a read access) or h'060 (for a write access) is set in expevt. the bl, md, and rb bits are set to 1 in sr, and a branch is made to pc = vbr + h'0400. to speed up tlb miss processing, the offset is separate from that of other exceptions. data_tlb_miss_exception() { tea = exception_address; pteh.vpn = page_number; spc = pc; ssr = sr; sgr = r15; expevt = read_access ? h'00000040 : h'00000060; sr.md = 1; sr.rb = 1; sr.bl = 1; pc = vbr + h'00000400; } rev. 5.0, 04/01, page 96 of 394 (2) instruction tlb miss exception ? source: address mismatch in itlb address comparison ? transition address: vbr + h'0000 0400 ? transition operations: the virtual address (32 bits) at which this exception occurred is set in tea, and the corresponding virtual page number (22 bits) is set in pteh [31:10]. asid in pteh indicates the asid when this exception occurred. the pc and sr contents for the instruction at which this exception occurred are saved in spc and ssr, and the contents of r15 are saved in sgr. exception code h'040 is set in expevt. the bl, md, and rb bits are set to 1 in sr, and a branch is made to pc = vbr + h'0400. to speed up tlb miss processing, the offset is separate from that of other exceptions. itlb_miss_exception() { tea = exception_address; pteh.vpn = page_number; spc = pc; ssr = sr; sgr = r15; expevt = h'00000040; sr.md = 1; sr.rb = 1; sr.bl = 1; pc = vbr + h'00000400; } rev. 5.0, 04/01, page 97 of 394 (3) initial page write exception ? source: tlb is hit in a store access, but dirty bit d = 0 ? transition address: vbr + h'0000 0100 ? transition operations: the virtual address (32 bits) at which this exception occurred is set in tea, and the corresponding virtual page number (22 bits) is set in pteh [31:10]. asid in pteh indicates the asid when this exception occurred. the pc and sr contents for the instruction at which this exception occurred are saved in spc and ssr, and the contents of r15 are saved in sgr. exception code h'080 is set in expevt. the bl, md, and rb bits are set to 1 in sr, and a branch is made to pc = vbr + h'0100. initial_write_exception() { tea = exception_address; pteh.vpn = page_number; spc = pc; ssr = sr; sgr = r15; expevt = h'00000080; sr.md = 1; sr.rb = 1; sr.bl = 1; pc = vbr + h'00000100; } rev. 5.0, 04/01, page 98 of 394 (4) data tlb protection violation exception ? source: the access does not accord with the utlb protection information (pr bits) shown below. pr privileged mode user mode 00 only read access possible access not possible 01 read/write access possible access not possible 10 only read access possible only read access possible 11 read/write access possible read/write access possible ? transition address: vbr + h'0000 0100 ? transition operations: the virtual address (32 bits) at which this exception occurred is set in tea, and the corresponding virtual page number (22 bits) is set in pteh [31:10]. asid in pteh indicates the asid when this exception occurred. the pc and sr contents for the instruction at which this exception occurred are saved in spc and ssr, and the contents of r15 are saved in sgr. exception code h'0a0 (for a read access) or h'0c0 (for a write access) is set in expevt. the bl, md, and rb bits are set to 1 in sr, and a branch is made to pc = vbr + h'0100. data_tlb_protection_violation_exception() { tea = exception_address; pteh.vpn = page_number; spc = pc; ssr = sr; sgr = r15; expevt = read_access ? h'000000a0 : h'000000c0; sr.md = 1; sr.rb = 1; sr.bl = 1; pc = vbr + h'00000100; } rev. 5.0, 04/01, page 99 of 394 (5) instruction tlb protection violation exception ? source: the access does not accord with the itlb protection information (pr bits) shown below. pr privileged mode user mode 0 access possible access not possible 1 access possible access possible ? transition address: vbr + h'0000 0100 ? transition operations: the virtual address (32 bits) at which this exception occurred is set in tea, and the corresponding virtual page number (22 bits) is set in pteh [31:10]. asid in pteh indicates the asid when this exception occurred. the pc and sr contents for the instruction at which this exception occurred are saved in spc and ssr, and the contents of r15 are saved in sgr. exception code h'0a0 is set in expevt. the bl, md, and rb bits are set to 1 in sr, and a branch is made to pc = vbr + h'0100. itlb_protection_violation_exception() { tea = exception_address; pteh.vpn = page_number; spc = pc; ssr = sr; sgr = r15; expevt = h'000000a0; sr.md = 1; sr.rb = 1; sr.bl = 1; pc = vbr + h'00000100; } rev. 5.0, 04/01, page 100 of 394 (6) data address error ? sources: ? word data access from other than a word boundary (2n +1) ? longword data access from other than a longword data boundary (4n +1, 4n + 2, or 4n +3) ? quadword data access from other than a quadword data boundary (8n +1, 8n + 2, 8n +3, 8n + 4, 8n + 5, 8n + 6, or 8n + 7) ? access to area h'8000 0000?h'ffff ffff in user mode ? transition address: vbr + h'0000 0100 ? transition operations: the virtual address (32 bits) at which this exception occurred is set in tea, and the corresponding virtual page number (22 bits) is set in pteh [31:10]. asid in pteh indicates the asid when this exception occurred. the pc and sr contents for the instruction at which this exception occurred are saved in spc and ssr, and the contents of r15 are saved in sgr. exception code h'0e0 (for a read access) or h'100 (for a write access) is set in expevt. the bl, md, and rb bits are set to 1 in sr, and a branch is made to pc = vbr + h'0100. for details, see section 3, memory management unit (mmu). data_address_error() { tea = exception_address; pten.vpn = page_number; spc = pc; ssr = sr; sgr = r15; expevt = read_access? h'000000e0: h'00000100; sr.md = 1; sr.rb = 1; sr.bl = 1; pc = vbr + h'00000100; } rev. 5.0, 04/01, page 101 of 394 (7) instruction address error ? sources: ? instruction fetch from other than a word boundary (2n +1) ? instruction fetch from area h'8000 0000?h'ffff ffff in user mode ? transition address: vbr + h'0000 0100 ? transition operations: the virtual address (32 bits) at which this exception occurred is set in tea, and the corresponding virtual page number (22 bits) is set in pteh [31:10]. asid in pteh indicates the asid when this exception occurred. the pc and sr contents for the instruction at which this exception occurred are saved in spc and ssr, and the contents of r15 are saved in sgr. exception code h'0e0 is set in expevt. the bl, md, and rb bits are set to 1 in sr, and a branch is made to pc = vbr + h'0100. for details, see section 3, memory management unit (mmu). instruction_address_error() { tea = exception_address; pten.vpn = page_number; spc = pc; ssr = sr; sgr = r15; expevt = h'000000e0; sr.md = 1; sr.rb = 1; sr.bl = 1; pc = vbr + h'00000100; } rev. 5.0, 04/01, page 102 of 394 (8) unconditional trap ? source: execution of trapa instruction ? transition address: vbr + h'0000 0100 ? transition operations: as this is a processing-completion-type exception, the pc contents for the instruction following the trapa instruction are saved in spc. the values of sr and r15 when the trapa instruction is executed are saved in ssr and sgr. the 8-bit immediate value in the trapa instruction is multiplied by 4, and the result is set in tra [9:0]. exception code h'160 is set in expevt. the bl, md, and rb bits are set to 1 in sr, and a branch is made to pc = vbr + h'0100. trapa_exception() { spc = pc + 2; ssr = sr; sgr = r15; tra = imm << 2; expevt = h'00000160; sr.md = 1; sr.rb = 1; sr.bl = 1; pc = vbr + h'00000100; } rev. 5.0, 04/01, page 103 of 394 (9) general illegal instruction exception ? sources: ? decoding of an undefined instruction not in a delay slot delayed branch instructions: jmp, jsr, bra, braf, bsr, bsrf, rts, rte, bt/s, bf/s undefined instruction: h'fffd ? decoding in user mode of a privileged instruction not in a delay slot privileged instructions: ldc, stc, rte, ldtlb, sleep, but excluding ldc/stc instructions that access gbr ? transition address: vbr + h'0000 0100 ? transition operations: the pc and sr contents for the instruction at which this exception occurred are saved in spc and ssr, and the contents of r15 are saved in sgr. exception code h'180 is set in expevt. the bl, md, and rb bits are set to 1 in sr, and a branch is made to pc = vbr + h'0100. operation is not guaranteed if an undefined code other than h'fffd is decoded. general_illegal_instruction_exception() { spc = pc; ssr = sr; sgr = r15; expevt = h'00000180; sr.md = 1; sr.rb = 1; sr.bl = 1; pc = vbr + h'00000100; } rev. 5.0, 04/01, page 104 of 394 (10) slot illegal instruction exception ? sources: ? decoding of an undefined instruction in a delay slot delayed branch instructions: jmp, jsr, bra, braf, bsr, bsrf, rts, rte, bt/s, bf/s undefined instruction: h'fffd ? decoding of an instruction that modifies pc in a delay slot instructions that modify pc: jmp, jsr, bra, braf, bsr, bsrf, rts, rte, bt, bf, bt/s, bf/s, trapa, ldc rm, sr, ldc.l @rm+,sr ? decoding in user mode of a privileged instruction in a delay slot privileged instructions: ldc, stc, rte, ldtlb, sleep, but excluding ldc/stc instructions that access gbr ? decoding of a pc-relative mov instruction or mova instruction in a delay slot ? transition address: vbr + h'0000 0100 ? transition operations: the pc contents for the preceding delayed branch instruction are saved in spc. the sr and r15 contents when this exception occurred are saved in ssr and sgr. exception code h'1a0 is set in expevt. the bl, md, and rb bits are set to 1 in sr, and a branch is made to pc = vbr + h'0100. operation is not guaranteed if an undefined code other than h'fffd is decoded. slot_illegal_instruction_exception() { spc = pc - 2; ssr = sr; sgr = r15; expevt = h'000001a0; sr.md = 1; sr.rb = 1; sr.bl = 1; pc = vbr + h'00000100; } rev. 5.0, 04/01, page 105 of 394 (11) general fpu disable exception ? source: decoding of an fpu instruction* not in a delay slot with sr.fd =1 ? transition address: vbr + h'0000 0100 ? transition operations: the pc and sr contents for the instruction at which this exception occurred are saved in spc and ssr, and the contents of r15 are saved in sgr. exception code h'800 is set in expevt. the bl, md, and rb bits are set to 1 in sr, and a branch is made to pc = vbr + h'0100. note: * fpu instructions are instructions in which the first 4 bits of the instruction code are f (but excluding undefined instruction h'fffd), and the lds, sts, lds.l, and sts.l instructions corresponding to fpul and fpscr. general_fpu_disable_exception() { spc = pc; ssr = sr; sgr = r15; expevt = h'00000800; sr.md = 1; sr.rb = 1; sr.bl = 1; pc = vbr + h'00000100; } rev. 5.0, 04/01, page 106 of 394 (12) slot fpu disable exception ? source: decoding of an fpu instruction in a delay slot with sr.fd =1 ? transition address: vbr + h'0000 0100 ? transition operations: the pc contents for the preceding delayed branch instruction are saved in spc. the sr and r15 contents when this exception occurred are saved in ssr and sgr. exception code h'820 is set in expevt. the bl, md, and rb bits are set to 1 in sr, and a branch is made to pc = vbr + h'0100. slot_fpu_disable_exception() { spc = pc - 2; ssr = sr; sgr = r15; expevt = h'00000820; sr.md = 1; sr.rb = 1; sr.bl = 1; pc = vbr + h'00000100; } rev. 5.0, 04/01, page 107 of 394 (13) user breakpoint trap ? source: fulfilling of a break condition set in the user break controller ? transition address: vbr + h'0000 0100, or dbr ? transition operations: in the case of a post-execution break, the pc contents for the instruction following the instruction at which the breakpoint is set are set in spc. in the case of a pre-execution break, the pc contents for the instruction at which the breakpoint is set are set in spc. the sr and r15 contents when the break occurred are saved in ssr and sgr. exception code h'1e0 is set in expevt. the bl, md, and rb bits are set to 1 in sr, and a branch is made to pc = vbr + h'0100. it is also possible to branch to pc = dbr. for details of pc, etc., when a data break is set, see user break controller in the hardware manual. user_break_exception() { spc = (pre_execution break? pc : pc + 2); ssr = sr; sgr = r15; expevt = h'000001e0; sr.md = 1; sr.rb = 1; sr.bl = 1; pc = (brcr.ubde==1 ? dbr : vbr + h?00000100); } rev. 5.0, 04/01, page 108 of 394 (14) fpu exception ? source: exception due to execution of a floating-point operation ? transition address: vbr + h'0000 0100 ? transition operations: the pc and sr contents for the instruction at which this exception occurred are saved in spc and ssr, and the contents of r15 are saved in sgr. exception code h'120 is set in expevt. the bl, md, and rb bits are set to 1 in sr, and a branch is made to pc = vbr + h'0100. fpu_exception() { spc = pc; ssr = sr; sgr = r15; expevt = h'00000120; sr.md = 1; sr.rb = 1; sr.bl = 1; pc = vbr + h'00000100; } rev. 5.0, 04/01, page 109 of 394 5.6.3 interrupts (1) nmi ? source: nmi pin edge detection ? transition address: vbr + h'0000 0600 ? transition operations: the contents of pc and sr immediately after the instruction at which this interrupt was accepted are saved in spc and ssr, and the contents of r15 are saved in sgr. exception code h'1c0 is set in intevt. the bl, md, and rb bits are set to 1 in sr, and a branch is made to pc = vbr + h'0600. when the bl bit in sr is 0, this interrupt is not masked by the interrupt mask bits in sr, and is accepted at the highest priority level. when the bl bit in sr is 1, a software setting can specify whether this interrupt is to be masked or accepted. for details, see interrupt controller in the hardware manual. nmi() { spc = pc; ssr = sr; sgr = r15; intevt = h'000001c0; sr.md = 1; sr.rb = 1; sr.bl = 1; pc = vbr + h'00000600; } rev. 5.0, 04/01, page 110 of 394 (2) irl interrupts ? source: the interrupt mask bit setting in sr is smaller than the irl (3?0) level, and the bl bit in sr is 0 (accepted at instruction boundary). ? transition address: vbr + h'0000 0600 ? transition operations: the pc contents immediately after the instruction at which the interrupt is accepted are set in spc. the sr and r15 contents at the time of acceptance are set in ssr and sgr. the code corresponding to the irl (3?0) level is set in intevt. see table 19.5, interrupt exception handling sources and priority order, for the corresponding codes. the bl, md, and rb bits are set to 1 in sr, and a branch is made to vbr + h'0600. the acceptance level is not set in the interrupt mask bits in sr. when the bl bit in sr is 1, the interrupt is masked. for details, see interrupt controller in the hardware manual. irl() { spc = pc; ssr = sr; sgr = r15; intevt = h'00000200 ~ h'000003c0; sr.md = 1; sr.rb = 1; sr.bl = 1; pc = vbr + h'00000600; } rev. 5.0, 04/01, page 111 of 394 (3) peripheral module interrupts ? source: the interrupt mask bit setting in sr is smaller than the peripheral module (h-udi, gpio, dmac, pcic*, tmu, rtc, sci, scif, wdt, or ref) interrupt level, and the bl bit in sr is 0 (accepted at instruction boundary). note: * sh7751 only ? transition address: vbr + h'0000 0600 ? transition operations: the pc contents immediately after the instruction at which the interrupt is accepted are set in spc. the sr and r15 contents at the time of acceptance are set in ssr and sgr. the code corresponding to the interrupt source is set in intevt. the bl, md, and rb bits are set to 1 in sr, and a branch is made to vbr + h'0600. the module interrupt levels should be set as values between b?0000 and b?1111 in the interrupt priority registers (ipra?iprc) in the interrupt controller. for details, see interrupt controller in the hardware manual. module_interruption() { spc = pc; ssr = sr; sgr = r15; intevt = h'00000400 ~ h'00000760; sr.md = 1; sr.rb = 1; sr.bl = 1; pc = vbr + h'00000600; } rev. 5.0, 04/01, page 112 of 394 5.6.4 priority order with multiple exceptions with some instructions, such as instructions that make two accesses to memory, and the indivisible pair comprising a delayed branch instruction and delay slot instruction, multiple exceptions occur. care is required in these cases, as the exception priority order differs from the normal order. 1. instructions that make two accesses to memory with mac instructions, memory-to-memory arithmetic/logic instructions, and tas instructions, two data transfers are performed by a single instruction, and an exception will be detected for each of these data transfers. in these cases, therefore, the following order is used to determine priority. a. data address error in first data transfer b. tlb miss in first data transfer c. tlb protection violation in first data transfer d. initial page write exception in first data transfer e. data address error in second data transfer f. tlb miss in second data transfer g. tlb protection violation in second data transfer h. initial page write exception in second data transfer 2. indivisible delayed branch instruction and delay slot instruction as a delayed branch instruction and its associated delay slot instruction are indivisible, they are treated as a single instruction. consequently, the priority order for exceptions that occur in these instructions differs from the usual priority order. the priority order shown below is for the case where the delay slot instruction has only one data transfer. a. the delayed branch instruction is checked for priority level 1 and 2 abort type and re- execution type exceptions. b. the delay slot instruction is checked for priority level 1 and 2 abort type and re-execution type exceptions. c. the delayed branch instruction is checked for a priority level 2 completion type exception. d. the delay slot instruction is checked for a priority level 2 completion type exception. e. a check is performed for priority level 3 in the delayed branch instruction and priority level 3 in the delay slot instruction. (there is no priority ranking between these two.) f. a check is performed for priority level 4 in the delayed branch instruction and priority level 4 in the delay slot instruction. (there is no priority ranking between these two.) if the delay slot instruction has a second data transfer, two checks are performed in step b, as in 1 above. rev. 5.0, 04/01, page 113 of 394 if the accepted exception (the highest-priority exception) is a delay slot instruction re- execution type exception, the branch instruction pr register write operation (pc pr operation performed in bsr, bsrf, jsr) is inhibited. 5.7 usage notes 1. return from exception handling a. check the bl bit in sr with software. if spc and ssr have been saved to external memory, set the bl bit in sr to 1 before restoring them. b. issue an rte instruction. when rte is executed, the spc contents are set in pc, the ssr contents are set in sr, and branch is made to the spc address to return from the exception handling routine. 2. if an exception or interrupt occurs when sr.bl = 1 a. exception when an exception other than a user break occurs, a manual reset is executed. the value in expevt at this time is h'0000 0020; the value of the spc and ssr registers is undefined. b. interrupt if an ordinary interrupt occurs, the interrupt request is held pending and is accepted after the bl bit in sr has been cleared to 0 by software. if a nonmaskable interrupt (nmi) occurs, it can be held pending or accepted according to the setting made by software. in the sleep or standby state, however, an interrupt is accepted even if the bl bit in sr is set to 1. 3. spc when an exception occurs a. re-execution type exception the pc value for the instruction in which the exception occurred is set in spc, and the instruction is re-executed after returning from exception handling. if an exception occurs in a delay slot instruction, however, the pc value for the delay slot instruction is saved in spc regardless of whether or not the preceding delay slot instruction condition is satisfied. b. completion type exception or interrupt the pc value for the instruction following that in which the exception occurred is set in spc. if an exception occurs in a branch instruction with delay slot, however, the pc value for the branch destination is saved in spc. 4. an exception must not be generated in an rte instruction delay slot, as the operation will be undefined in this case. rev. 5.0, 04/01, page 114 of 394 5.8 restrictions 1. restrictions on first instruction of exception handling routine do not locate a bt, bf, bt/s, bf/s, bra, or bsr instruction at address vbr + h'100, vbr + h'400, or vbr + h'600. when the ubde bit in the brcr register is set to 1 and the user break debug support function* is used, do not locate a bt, bf, bt/s, bf/s, bra, or bsr instruction at the address indicated by the dbr register. note: * see user break debug support function in the hardware manual. rev. 5.0, 04/01, page 115 of 394 section 6 floating-point unit 6.1 overview the floating-point unit (fpu) has the following features: ? conforms to ieee754 standard ? 32 single-precision floating-point registers (can also be referenced as 16 double-precision registers) ? two rounding modes: round to nearest and round to zero ? two denormalization modes: flush to zero and treat denormalized number ? six exception sources: fpu error, invalid operation, divide by zero, overflow, underflow, and inexact ? comprehensive instructions: single-precision, double-precision, graphics support, system control when the fd bit in sr is set to 1, the fpu cannot be used, and an attempt to execute an fpu instruction will cause an fpu disable exception. 6.2 data formats 6.2.1 floating-point format a floating-point number consists of the following three fields: ? sign (s) ? exponent (e) ? fraction (f) the sh-4 can handle single-precision and double-precision floating-point numbers, using the formats shown in figures 6.1 and 6.2. 31 se f 30 23 22 0 figure 6.1 format of single-precision floating-point number rev. 5.0, 04/01, page 116 of 394 63 se f 62 52 51 0 figure 6.2 format of double-precision floating-point number the exponent is expressed in biased form, as follows: e = e + bias the range of unbiased exponent e is e min ? 1 to e max + 1. the two values e min ? 1 and e max + 1 are distinguished as follows. e min ? 1 indicates zero (both positive and negative sign) and a denormalized number, and e max + 1 indicates positive or negative infinity or a non-number (nan). table 6.1 shows bias, e min , and e max values. table 6.1 floating-point number formats and parameters parameter single-precision double-precision total bit width 32 bits 64 bits sign bit 1 bit 1 bit exponent field 8 bits 11 bits fraction field 23 bits 52 bits precision 24 bits 53 bits bias +127 +1023 e max +127 +1023 e min ?126 ?1022 floating-point number value v is determined as follows: if e = e max + 1 and f 0, v is a non-number (nan) irrespective of sign s if e = e max + 1 and f = 0, v = (?1) s (infinity) [positive or negative infinity] if e min e e max , v = (?1) s 2 e (1.f) [normalized number] if e = e min ? 1 and f 0, v = (?1) s 2 emin (0.f) [denormalized number] if e = e min ? 1 and f = 0, v = (?1) s 0 [positive or negative zero] table 6.2 shows the ranges of the various numbers in hexadecimal notation. rev. 5.0, 04/01, page 117 of 394 table 6.2 floating-point ranges type single-precision double-precision signaling non-number h'7fffffff to h'7fc00000 h'7fffffff ffffffff to h'7ff80000 00000000 quiet non-number h'7fbfffff to h'7f800001 h'7ff7ffff ffffffff to h'7ff00000 00000001 positive infinity h'7f800000 h'7ff00000 00000 positive normalized number h'7f7fffff to h'00800000 h'7fefffff ffffffff to h'00100000 00000000 positive denormalized number h'007fffff to h'00000001 h'000fffff ffffffff to h'00000000 00000001 positive zero h'00000000 h'00000000 00000000 negative zero h'80000000 h'80000000 00000000 negative denormalized number h'80000001 to h'807fffff h'80000000 00000001 to h'800fffff ffffffff negative normalized number h'80800000 to h'ff7fffff h'80100000 00000000 to h'ffefffff ffffffff negative infinity h'ff800000 h'fff00000 00000000 quiet non-number h'ff800001 to h'ffbfffff h'fff00000 00000001 to h'fff7ffff ffffffff signaling non-number h'ffc00000 to h'ffffffff h'fff80000 00000000 to h'ffffffff ffffffff 6.2.2 non-numbers (nan) figure 6.3 shows the bit pattern of a non-number (nan). a value is nan in the following case: ? sign bit: don?t care ? exponent field: all bits are 1 ? fraction field: at least one bit is 1 the nan is a signaling nan (snan) if the msb of the fraction field is 1, and a quiet nan (qnan) if the msb is 0. rev. 5.0, 04/01, page 118 of 394 31 x 11111111 nxxxxxxxxxxxxxxxxxxxxxx 30 23 22 0 n = 1: snan n = 0: qnan figure 6.3 single-precision nan bit pattern an snan is input in an operation, except copy, fabs, and fneg, that generates a floating-point value. ? when the en.v bit in the fpscr register is 0, the operation result (output) is a qnan. ? when the en.v bit in the fpscr register is 1, an invalid operation exception will be generated. in this case, the contents of the operation destination register are unchanged. if a qnan is input in an operation that generates a floating-point value, and an snan has not been input in that operation, the output will always be a qnan irrespective of the setting of the en.v bit in the fpscr register. an exception will not be generated in this case. the qnan values generated by the sh-4 as operation results are as follows: ? single-precision qnan: h'7fbfffff ? double-precision qnan: h'7ff7ffff ffffffff see section 9, instruction descriptions, for details of floating-point operations when a non-number (nan) is input. 6.2.3 denormalized numbers for a denormalized number floating-point value, the exponent field is expressed as 0, and the fraction field as a non-zero value. when the dn bit in the fpu?s status register fpscr is 1, a denormalized number (source operand or operation result) is always flushed to 0 in a floating-point operation that generates a value (an operation other than copy, fneg, or fabs). when the dn bit in fpscr is 0, a denormalized number (source operand or operation result) is processed as it is. see section 9, description of instructions, for details of floating-point operations when a denormalized number is input. rev. 5.0, 04/01, page 119 of 394 6.3 registers 6.3.1 floating-point registers figure 6.4 shows the floating-point register configuration. there are thirty-two 32-bit floating- point registers, referenced by specifying fr0?fr15, dr0/2/4/6/8/10/12/14, fv0/4/8/12, xf0? xf15, xd0/2/4/6/8/10/12/14, or xmtrx. 1. floating-point registers, fpri_bankj (32 registers) fpr0_bank0?fpr15_bank0 fpr0_bank1?fpr15_bank1 2. single-precision floating-point registers, fri (16 registers) when fpscr.fr = 0, fr0?fr15 indicate fpr0_bank0?fpr15_bank0; when fpscr.fr = 1, fr0?fr15 indicate fpr0_bank1?fpr15_bank1. 3. double-precision floating-point registers, dri (8 registers): a dr register comprises two fr registers dr0 = {fr0, fr1}, dr2 = {fr2, fr3}, dr4 = {fr4, fr5}, dr6 = {fr6, fr7}, dr8 = {fr8, fr9}, dr10 = {fr10, fr11}, dr12 = {fr12, fr13}, dr14 = {fr14, fr15} 4. single-precision floating-point vector registers, fvi (4 registers): an fv register comprises four fr registers fv0 = {fr0, fr1, fr2, fr3}, fv4 = {fr4, fr5, fr6, fr7}, fv8 = {fr8, fr9, fr10, fr11}, fv12 = {fr12, fr13, fr14, fr15} 5. single-precision floating-point extended registers, xfi (16 registers) when fpscr.fr = 0, xf0?xf15 indicate fpr0_bank1?fpr15_bank1; when fpscr.fr = 1, xf0?xf15 indicate fpr0_bank0?fpr15_bank0. 6. double-precision floating-point extended registers, xdi (8 registers): an xd register comprises two xf registers xd0 = {xf0, xf1}, xd2 = {xf2, xf3}, xd4 = {xf4, xf5}, xd6 = {xf6, xf7}, xd8 = {xf8, xf9}, xd10 = {xf10, xf11}, xd12 = {xf12, xf13}, xd14 = {xf14, xf15} 7. single-precision floating-point extended register matrix, xmtrx: xmtrx comprises all 16 xf registers xmtrx = xf0 xf4 xf8 xf12 xf1 xf5 xf9 xf13 xf2 xf6 xf10 xf14 xf3 xf7 xf11 xf15 rev. 5.0, 04/01, page 120 of 394 fpr0_bank0 fpr1_bank0 fpr2_bank0 fpr3_bank0 fpr4_bank0 fpr5_bank0 fpr6_bank0 fpr7_bank0 fpr8_bank0 fpr9_bank0 fpr10_bank0 fpr11_bank0 fpr12_bank0 fpr13_bank0 fpr14_bank0 fpr15_bank0 xf0 xf1 xf2 xf3 xf4 xf5 xf6 xf7 xf8 xf9 xf10 xf11 xf12 xf13 xf14 xf15 fr0 fr1 fr2 fr3 fr4 fr5 fr6 fr7 fr8 fr9 fr10 fr11 fr12 fr13 fr14 fr15 dr0 dr2 dr4 dr6 dr8 dr10 dr12 dr14 fv0 fv4 fv8 fv12 xd0 xmtrx xd2 xd4 xd6 xd8 xd10 xd12 xd14 fpr0_bank1 fpr1_bank1 fpr2_bank1 fpr3_bank1 fpr4_bank1 fpr5_bank1 fpr6_bank1 fpr7_bank1 fpr8_bank1 fpr9_bank1 fpr10_bank1 fpr11_bank1 fpr12_bank1 fpr13_bank1 fpr14_bank1 fpr15_bank1 xf0 xf1 xf2 xf3 xf4 xf5 xf6 xf7 xf8 xf9 xf10 xf11 xf12 xf13 xf14 xf15 fr0 fr1 fr2 fr3 fr4 fr5 fr6 fr7 fr8 fr9 fr10 fr11 fr12 fr13 fr14 fr15 dr0 dr2 dr4 dr6 dr8 dr10 dr12 dr14 fv0 fv4 fv8 fv12 xd0 xmtrx xd2 xd4 xd6 xd8 xd10 xd12 xd14 fpscr.fr = 0 fpscr.fr = 1 figure 6.4 floating-point registers rev. 5.0, 04/01, page 121 of 394 6.3.2 floating-point status/control register (fpscr) floating-point status/control register, fpscr (32 bits, initial value = h'0004 0001) 31 22 21 20 19 18 17 12 11 7 6 2 1 0 ? fr sz pr dn cause enable flag rm note: ?: reserved. these bits are always read as 0, and should only be written with 0. ? fr: floating-point register bank fr = 0: fpr0_bank0?fpr15_bank0 are assigned to fr0?fr15; fpr0_bank1? fpr15_bank1 are assigned to xf0?xf15. fr = 1: fpr0_bank0?fpr15_bank0 are assigned to xf0?xf15; fpr0_bank1? fpr15_bank1 are assigned to fr0?fr15. ? sz: transfer size mode sz = 0: the data size of the fmov instruction is 32 bits. sz = 1: the data size of the fmov instruction is a 32-bit register pair (64 bits). ? pr: precision mode pr = 0: floating-point instructions are executed as single-precision operations. pr = 1: floating-point instructions are executed as double-precision operations (graphics support instructions are undefined). do not set sz and pr to 1 simultaneously; this setting is reserved. [sz, pr = 11]: reserved (fpu operation instruction is undefined.) ? dn: denormalization mode dn = 0: a denormalized number is treated as such. dn = 1: a denormalized number is treated as zero. ? cause: fpu exception cause field ? enable: fpu exception enable field ? flag: fpu exception flag field fpu error (e) invalid operation (v) division by zero (z) overflow (o) underflow (u) inexact (i) cause fpu exception cause field bit 17 bit 16 bit 15 bit 14 bit 13 bit 12 enable fpu exception enable field none bit 11 bit 10 bit 9 bit 8 bit 7 flag fpu exception flag field none bit 6 bit 5 bit 4 bit 3 bit 2 rev. 5.0, 04/01, page 122 of 394 when an fpu operation instruction is executed, the fpu exception cause field is cleared to zero first. when the next fpu exception is occured, the corresponding bits in the fpu exception cause field and fpu exception flag field are set to 1. the fpu exception flag field holds the status of the exception generated after the field was last cleared. ? rm: rounding mode rm = 00: round to nearest rm = 01: round to zero rm = 10: reserved rm = 11: reserved ? bits 22 to 31: reserved these bits are always read as 0, and should only be written with 0. notes: the following functions have been added to the fpu of the sh-4 (not provided in the fpu of the sh7718): 1. the fr, sz, and pr bits have been added. 2. exception o (overflow), u (underflow), and i (inexact) bits have been added to the cause, enable, and flag fields. 3. an exception e (fpu error) bit has been added to the cause field. 6.3.3 floating-point communication register (fpul) information is transferred between the fpu and cpu via the fpul register. the 32-bit fpul register is a system register, and is accessed from the cpu side by means of lds and sts instructions. for example, to convert the integer stored in general register r1 to a single-precision floating-point number, the processing flow is as follows: r1 (lds instruction) fpul (single-precision float instruction) fr1 6.4 rounding in a floating-point instruction, rounding is performed when generating the final operation result from the intermediate result. therefore, the result of combination instructions such as fmac, ftrv, and fipr will differ from the result when using a basic instruction such as fadd, fsub, or fmul. rounding is performed once in fmac, but twice in fadd, fsub, and fmul. there are two rounding methods, the method to be used being determined by the rm field in fpscr. ? rm = 00: round to nearest ? rm = 01: round to zero rev. 5.0, 04/01, page 123 of 394 round to nearest: the value is rounded to the nearest expressible value. if there are two nearest expressible values, the one with an lsb of 0 is selected. if the unrounded value is 2 emax (2 ? 2 ?p ) or more, the result will be infinity with the same sign as the unrounded value. the values of emax and p, respectively, are 127 and 24 for single-precision, and 1023 and 53 for double-precision. round to zero: the digits below the round bit of the unrounded value are discarded. if the unrounded value is larger than the maximum expressible absolute value, the value will be the maximum expressible absolute value. 6.5 floating-point exceptions fpu-related exceptions are as follows: ? general illegal instruction/slot illegal instruction exception the exception occurs if an fpu instruction is executed when sr.fd = 1. ? fpu exceptions the exception sources are as follows: ? fpu error (e): when fpscr.dn = 0 and a denormalized number is input ? invalid operation (v): in case of an invalid operation, such as nan input ? division by zero (z): division with a zero divisor ? overflow (o): when the operation result overflows ? underflow (u): when the operation result underflows ? inexact exception (i): when overflow, underflow, or rounding occurs the fpscr cause field contains bits corresponding to all of above sources e, v, z, o, u, and i, and the fpscr flag and enable fields contain bits corresponding to sources v, z, o, u, and i, but not e. thus, fpu errors cannot be disabled. when an exception source occurs, the corresponding bit in the cause field is set to 1, and 1 is added to the corresponding bit in the flag field. when an exception source does not occur, the corresponding bit in the cause field is cleared to 0, but the corresponding bit in the flag field remains unchanged. ? fpu exception handling fpu exception occurs in the following cases: ? fpu error (e): fpscr.dn = 0 and a denormalized number is input ? invalid operation (v): fpscr.en.v = 1 and (instruction = ftrv or invalid operation) ? division by zero (z): fpscr.en.z = 1 and division with a zero divisor ? overflow (o): fpscr.en.o = 1 and instruction with possibility of operation result overflow rev. 5.0, 04/01, page 124 of 394 ? underflow (u): fpscr.en.u = 1 and instruction with possibility of operation result underflow ? inexact exception (i): fpscr.en.i = 1 and instruction with possibility of inexact operation result these possibilities are shown in the individual instruction descriptions. all exception events that originate in the fpu are assigned as the same exception event. the meaning of an exception is determined by software by reading system register fpscr and interpreting the information it contains. if no bits are set in the cause field of fpscr when one or more of bits o, u, i, and v (in case of ftrv only) are set in the enable field, this indicates that an actual fpu exception is not generated. also, the destination register is not changed by any fpu exception handling operation. except for the above, the bit corresponding to source v, z, o, u, or i is set to 1, and a default value is generated as the operation result. ? invalid operation (v): qnan is generated as the result. ? division by zero (z): infinity with the same sign as the unrounded value is generated. ? overflow (o): when rounding mode = rz, the maximum normalized number, with the same sign as the unrounded value, is generated. when rounding mode = rn, infinity with the same sign as the unrounded value is generated. ? underflow (u): when fpscr.dn = 0, a denormalized number with the same sign as the unrounded value, or zero with the same sign as the unrounded value, is generated. when fpscr.dn = 1, zero with the same sign as the unrounded value, is generated. ? inexact exception (i): an inexact result is generated. 6.6 graphics support functions the supports two kinds of graphics functions: new instructions for geometric operations, and pair single-precision transfer instructions that enable high-speed data transfer. 6.6.1 geometric operation instructions geometric operation instructions perform approximate-value computations. to enable high-speed computation with a minimum of hardware, the sh-4 ignores comparatively small values in the partial computation results of four multiplications. consequently, the error shown below is produced in the result of the computation: maximum error = max (individual multiplication result 2 ?min (number of multiplier significant digits?1, number of multiplicand significant digits?1) ) + max (result value 2 ?23 , 2 ?149 ) rev. 5.0, 04/01, page 125 of 394 the number of significant digits is 24 for a normalized number and 23 for a denormalized number (number of leading zeros in the fractional part). in future version of sh series, the above error is guaranteed, but the same result as sh-4 is not guaranteed. fipr fvm, fvn (m, n: 0, 4, 8, 12): examples of the use of this instruction are shown below. ? inner product (m n): this operation is generally used for surface/rear surface determination for polygon surfaces. ? sum of square of elements (m = n): this operation is generally used to find the length of a vector. since approximate-value computations are performed to enable high-speed computation, the inexact exception (i) bit in the cause field and flag field is always set to 1 when an fipr instruction is executed. therefore, if the corresponding bit is set in the enable field, enable exception handling will be executed. ftrv xmtrx, fvn (n: 0, 4, 8, 12): examples of the use of this instruction are shown below. ? matrix (4 4) ? vector (4): this operation is generally used for viewpoint changes, angle changes, or movements called vector transformations (4-dimensional). since affine transformation processing for angle + parallel movement basically requires a 4 4 matrix, the sh-4 supports 4-dimensional operations. ? matrix (4 4) matrix (4 4): this operation requires the execution of four ftrv instructions. since approximate-value computations are performed to enable high-speed computation, the inexact exception (i) bit in the cause field and flag field is always set to 1 when an ftrv instruction is executed. therefore, if the corresponding bit is set in the enable field, fpu exception handling will be executed. for the same reason, it is not possible to check all data types in the registers beforehand when executing an ftrv instruction. if the v bit is set in the enable field, fpu exception handling will be executed. frchg: this instruction modifies banked registers. for example, when the ftrv instruction is executed, matrix elements must be set in an array in the background bank. however, to create the actual elements of a translation matrix, it is easier to use registers in the foreground bank. when the ldc instruction is used on fpscr, this instruction expends 4 to 5 cycles in order to maintain the fpu state. with the frchg instruction, an fpscr.fr bit modification can be performed in one cycle. rev. 5.0, 04/01, page 126 of 394 6.6.2 pair single-precision data transfer in addition to the powerful new geometric operation instructions, the sh-4 also supports high- speed data transfer instructions. when fpscr.sz = 1, the sh-4 can perform data transfer by means of pair single-precision data transfer instructions. ? fmov drm/xdm, drn/xdrn (m, n: 0, 2, 4, 6, 8, 10, 12, 14) ? fmov drm/xdm, @rn (m: 0, 2, 4, 6, 8, 10, 12, 14; n: 0 to 15) these instructions enable two single-precision (2 32-bit) data items to be transferred; that is, the transfer performance of these instructions is doubled. ? fschg this instruction changes the value of the sz bit in fpscr, enabling fast switching between use and non-use of pair single-precision data transfer. programming note when fpscr.sz = 1 and big-endian mode is used, fmov can be used for a double-precision floating-point load or store. in little-endian mode, a double-precision floating-point load or store requires execution of two 32-bit data size operations with fpscr.sz = 0. rev. 5.0, 04/01, page 127 of 394 section 7 instruction set 7.1 execution environment pc: at the start of instruction execution, pc indicates the address of the instruction itself. data sizes and data types: the sh-4?s instruction set is implemented with 16-bit fixed-length instructions. the sh-4 can use byte (8-bit), word (16-bit), longword (32-bit), and quadword (64- bit) data sizes for memory access. single-precision floating-point data (32 bits) can be moved to and from memory using longword or quadword size. double-precision floating-point data (64 bits) can be moved to and from memory using longword size. when a double-precision floating-point operation is specified (fpscr.pr = 1), the result of an operation using quadword access will be undefined. when the sh-4 moves byte-size or word-size data from memory to a register, the data is sign-extended. load-store architecture: the sh-4 features a load-store architecture in which operations are basically executed using registers. except for bit-manipulation operations such as logical and that are executed directly in memory, operands in an operation that requires memory access are loaded into registers and the operation is executed between the registers. delayed branches: except for the two branch instructions bf and bt, the sh-4?s branch instructions and rte are delayed branches. in a delayed branch, the instruction following the branch is executed before the branch destination instruction. this execution slot following a delayed branch is called a delay slot. for example, the bra execution sequence is as follows: static sequence dynamic sequence bra target bra target add r1, r0 next_2 add r1, r0 target_instr add in delay slot is executed before branching to target delay slot: an illegal instruction exception may occur when a specific instruction is executed in a delay slot. see section 5, exceptions. the instruction following bf/s or bt/s for which the branch is not taken is also a delay slot instruction. t bit: the t bit in the status register (sr) is used to show the result of a compare operation, and is referenced by a conditional branch instruction. an example of the use of a conditional branch instruction is shown below. add #1, r0 ; t bit is not changed by add operation cmp/eq r1, r0 ; if r0 = r1, t bit is set to 1 bt target ; branches to target if t bit = 1 (r0 = r1) rev. 5.0, 04/01, page 128 of 394 in an rte delay slot, status register (sr) bits are referenced as follows. in instruction access, the md bit is used before modification, and in data access, the md bit is accessed after modification. the other bits?s, t, m, q, fd, bl, and rb?after modification are used for delay slot instruction execution. the stc and stc.l sr instructions access all sr bits after modification. constant values: an 8-bit constant value can be specified by the instruction code and an immediate value. 16-bit and 32-bit constant values can be defined as literal constant values in memory, and can be referenced by a pc-relative load instruction. mov.w @(disp, pc), rn mov.l @(disp, pc), rn there are no pc-relative load instructions for floating-point operations. however, it is possible to set 0.0 or 1.0 by using the fldi0 or fldi1 instruction on a single-precision floating-point register. rev. 5.0, 04/01, page 129 of 394 7.2 addressing modes addressing modes and effective address calculation methods are shown in table 7.1. when a location in virtual memory space is accessed (mmucr.at = 1), the effective address is translated into a physical memory address. if multiple virtual memory space systems are selected (mmucr.sv = 0), the least significant bit of pteh is also referenced as the access asid. see section 3, memory management unit (mmu). table 7.1 addressing modes and effective addresses addressing mode instruction format effective address calculation method calculation formula register direct rn effective address is register rn. (operand is register rn contents.) ? register indirect @rn effective address is register rn contents. rn rn rn ea (ea: effective address) register indirect with post- increment @rn+ effective address is register rn contents. a constant is added to rn after instruction execution: 1 for a byte operand, 2 for a word operand, 4 for a longword operand, 8 for a quadword operand. rn rn 1/2/4/8 + rn + 1/2/4/8 rn ea after instruction execution byte: rn + 1 rn word: rn + 2 rn longword: rn + 4 rn quadword: rn + 8 rn register indirect with pre- decrement @?rn effective address is register rn contents, decremented by a constant beforehand: 1 for a byte operand, 2 for a word operand, 4 for a longword operand, 8 for a quadword operand. rn 1/2/4/8 rn ? 1/2/4/8 ? rn ? 1/2/4/8 byte: rn ? 1 rn word: rn ? 2 rn longword: rn ? 4 rn quadword: rn ? 8 rn rn ea (instruction executed with rn after calculation) rev. 5.0, 04/01, page 130 of 394 table 7.1 addressing modes and effective addresses (cont) addressing mode instruction format effective address calculation method calculation formula register indirect with displacement @(disp:4, rn) effective address is register rn contents with 4-bit displacement disp added. after disp is zero-extended, it is multiplied by 1 (byte), 2 (word), or 4 (longword), according to the operand size. rn rn + disp 1/2/4 + 1/2/4 disp (zero-extended) byte: rn + disp ea word: rn + disp 2 ea longword: rn + disp 4 ea indexed register indirect @(r0, rn) effective address is sum of register rn and r0 contents. rn r0 rn + r0 + rn + r0 ea gbr indirect with displacement @(disp:8, gbr) effective address is register gbr contents with 8-bit displacement disp added. after disp is zero-extended, it is multiplied by 1 (byte), 2 (word), or 4 (longword), according to the operand size. gbr 1/2/4 gbr + disp 1/2/4 + disp (zero-extended) byte: gbr + disp ea word: gbr + disp 2 ea longword: gbr + disp 4 ea indexed gbr indirect @(r0, gbr) effective address is sum of register gbr and r0 contents. gbr r0 gbr + r0 + gbr + r0 ea rev. 5.0, 04/01, page 131 of 394 table 7.1 addressing modes and effective addresses (cont) addressing mode instruction format effective address calculation method calculation formula pc-relative with displacement @(disp:8, pc) effective address is pc+4 with 8-bit displacement disp added. after disp is zero-extended, it is multiplied by 2 (word), or 4 (longword), according to the operand size. with a longword operand, the lower 2 bits of pc are masked. pc h'fffffffc pc + 4 + disp 2 or pc & h'fffffffc + 4 + disp 4 + 4 2/4 + & * disp (zero-extended) * with longword operand word: pc + 4 + disp 2 ea longword: pc & h'fffffffc + 4 + disp 4 ea pc-relative disp:8 effective address is pc+4 with 8-bit displacement disp added after being sign-extended and multiplied by 2. 2 + disp (sign-extended) 4 + pc pc + 4 + disp 2 pc + 4 + disp 2 branch- target rev. 5.0, 04/01, page 132 of 394 table 7.1 addressing modes and effective addresses (cont) addressing mode instruction format effective address calculation method calculation formula pc-relative disp:12 effective address is pc+4 with 12-bit displacement disp added after being sign-extended and multiplied by 2. 2 + disp (sign-extended) 4 + pc pc + 4 + disp 2 pc + 4 + disp 2 branch- target rn effective address is sum of pc+4 and rn. pc 4 rn + + pc + 4 + rn pc + 4 + rn branch- target immediate #imm:8 8-bit immediate data imm of tst, and, or, or xor instruction is zero-extended. ? #imm:8 8-bit immediate data imm of mov, add, or cmp/eq instruction is sign-extended. ? #imm:8 8-bit immediate data imm of trapa instruction is zero-extended and multiplied by 4. ? note: for the addressing modes below that use a displacement (disp), the assembler descriptions in this manual show the value before scaling ( 1, 2, or 4) is performed according to the operand size. this is done to clarify the operation of the chip. refer to the relevant assembler notation rules for the actual assembler descriptions. @ (disp:4, rn) ; register indirect with displacement @ (disp:8, gbr) ; gbr indirect with displacement @ (disp:8, pc) ; pc-relative with displacement disp:8, disp:12 ; pc-relative rev. 5.0, 04/01, page 133 of 394 7.3 instruction set table 7.2 shows the notation used in the following sh instruction list. table 7.2 notation used in instruction list item format description instruction mnemonic op.sz src, dest op: operation code sz: size src: source dest: source and/or destination operand summary of operation , transfer direction (xx) memory operand m/q/t sr flag bits & logical and of individual bits | logical or of individual bits logical exclusive-or of individual bits ~ logical not of individual bits < rev. 5.0, 04/01, page 134 of 394 table 7.3 fixed-point transfer instructions instruction operation instruction code privileged t bit mov #imm,rn imm sign extension rn 1110nnnniiiiiiii ?? mov.w @(disp,pc),rn (disp 2 + pc + 4) sign extension rn 1001nnnndddddddd ?? mov.l @(disp,pc),rn (disp 4 + pc & h'fffffffc + 4) rn 1101nnnndddddddd ?? mov rm,rn rm rn 0110nnnnmmmm0011 ?? mov.b rm,@rn rm (rn) 0010nnnnmmmm0000 ?? mov.w rm,@rn rm (rn) 0010nnnnmmmm0001 ?? mov.l rm,@rn rm (rn) 0010nnnnmmmm0010 ?? mov.b @rm,rn (rm) sign extension rn 0110nnnnmmmm0000 ?? mov.w @rm,rn (rm) sign extension rn 0110nnnnmmmm0001 ?? mov.l @rm,rn (rm) rn 0110nnnnmmmm0010 ?? mov.b rm,@-rn rn-1 rn, rm (rn) 0010nnnnmmmm0100 ?? mov.w rm,@-rn rn-2 rn, rm (rn) 0010nnnnmmmm0101 ?? mov.l rm,@-rn rn-4 rn, rm (rn) 0010nnnnmmmm0110 ?? mov.b @rm+,rn (rm) sign extension rn, rm + 1 rm 0110nnnnmmmm0100 ?? mov.w @rm+,rn (rm) sign extension rn, rm + 2 rm 0110nnnnmmmm0101 ?? mov.l @rm+,rn (rm) rn, rm + 4 rm 0110nnnnmmmm0110 ?? mov.b r0,@(disp,rn) r0 (disp + rn) 10000000nnnndddd ?? mov.w r0,@(disp,rn) r0 (disp 2 + rn) 10000001nnnndddd ?? mov.l rm,@(disp,rn) rm (disp 4 + rn) 0001nnnnmmmmdddd ?? mov.b @(disp,rm),r0 (disp + rm) sign extension r0 10000100mmmmdddd ?? mov.w @(disp,rm),r0 (disp 2 + rm) sign extension r0 10000101mmmmdddd ?? mov.l @(disp,rm),rn (disp 4 + rm) rn 0101nnnnmmmmdddd ?? mov.b rm,@(r0,rn) rm (r0 + rn) 0000nnnnmmmm0100 ?? mov.w rm,@(r0,rn) rm (r0 + rn) 0000nnnnmmmm0101 ?? mov.l rm,@(r0,rn) rm (r0 + rn) 0000nnnnmmmm0110 ?? mov.b @(r0,rm),rn (r0 + rm) sign extension rn 0000nnnnmmmm1100 ?? mov.w @(r0,rm),rn (r0 + rm) sign extension rn 0000nnnnmmmm1101 ?? mov.l @(r0,rm),rn (r0 + rm) rn 0000nnnnmmmm1110 ?? rev. 5.0, 04/01, page 135 of 394 table 7.3 fixed-point transfer instructions (cont) instruction operation instruction code privileged t bit mov.b r0,@(disp,gbr) r0 (disp + gbr) 11000000dddddddd ?? mov.w r0,@(disp,gbr) r0 (disp 2 + gbr) 11000001dddddddd ?? mov.l r0,@(disp,gbr) r0 (disp 4 + gbr) 11000010dddddddd ?? mov.b @(disp,gbr),r0 (disp + gbr) sign extension r0 11000100dddddddd ?? mov.w @(disp,gbr),r0 (disp 2 + gbr) sign extension r0 11000101dddddddd ?? mov.l @(disp,gbr),r0 (disp 4 + gbr) r0 11000110dddddddd ?? mova @(disp,pc),r0 disp 4 + pc & h'fffffffc + 4 r0 11000111dddddddd ?? movt rn t rn 0000nnnn00101001 ?? swap.b rm,rn rm swap lower 2 bytes rn 0110nnnnmmmm1000 ?? swap.w rm,rn rm swap upper/lower words rn 0110nnnnmmmm1001 ?? xtrct rm,rn rm:rn middle 32 bits rn 0010nnnnmmmm1101 ?? rev. 5.0, 04/01, page 136 of 394 table 7.4 arithmetic operation instructions instruction operation instruction code privileged t bit add rm,rn rn + rm rn 0011nnnnmmmm1100 ?? add #imm,rn rn + imm rn 0111nnnniiiiiiii ?? addc rm,rn rn + rm + t rn, carry t 0011nnnnmmmm1110 ? carry addv rm,rn rn + rm rn, overflow t 0011nnnnmmmm1111 ?overflow cmp/eq #imm,r0 when r0 = imm, 1 t otherwise, 0 t 10001000iiiiiiii ? comparison result cmp/eq rm,rn when rn = rm, 1 t otherwise, 0 t 0011nnnnmmmm0000 ? comparison result cmp/hs rm,rn when rn rm (unsigned), 1 t otherwise, 0 t 0011nnnnmmmm0010 ? comparison result cmp/ge rm,rn when rn rm (signed), 1 t otherwise, 0 t 0011nnnnmmmm0011 ? comparison result cmp/hi rm,rn when rn > rm (unsigned), 1 t otherwise, 0 t 0011nnnnmmmm0110 ? comparison result cmp/gt rm,rn when rn > rm (signed), 1 t otherwise, 0 t 0011nnnnmmmm0111 ? comparison result cmp/pz rn when rn 0, 1 t otherwise, 0 t 0100nnnn00010001 ? comparison result cmp/pl rn when rn > 0, 1 t otherwise, 0 t 0100nnnn00010101 ? comparison result cmp/str rm,rn when any bytes are equal, 1 t otherwise, 0 t 0010nnnnmmmm1100 ? comparison result div1 rm,rn 1-step division (rn rm) 0011nnnnmmmm0100 ? calculation result div0s rm,rn msb of rn q, msb of rm m, m^q t 0010nnnnmmmm0111 ? calculation result div0u 0 m/q/t 0000000000011001 ?0 dmuls.l rm,rn signed, rn rm mac, 32 32 64 bits 0011nnnnmmmm1101 ?? dmulu.l rm,rn unsigned, rn rm mac, 32 32 64 bits 0011nnnnmmmm0101 ?? dt rn rn ? 1 rn; when rn = 0, 1 t when rn 0, 0 t 0100nnnn00010000 ? comparison result exts.b rm,rn rm sign-extended from byte rn 0110nnnnmmmm1110 ?? rev. 5.0, 04/01, page 137 of 394 table 7.4 arithmetic operation instructions (cont) instruction operation instruction code privileged t bit exts.w rm,rn rm sign-extended from word rn 0110nnnnmmmm1111 ?? extu.b rm,rn rm zero-extended from byte rn 0110nnnnmmmm1100 ?? extu.w rm,rn rm zero-extended from word rn 0110nnnnmmmm1101 ?? mac.l @rm+,@rn+ signed, (rn) (rm) + mac mac rn + 4 rn, rm + 4 rm 32 32 + 64 64 bits 0000nnnnmmmm1111 ?? mac.w @rm+,@rn+ signed, (rn) (rm) + mac mac rn + 2 rn, rm + 2 rm 16 16 + 64 64 bits 0100nnnnmmmm1111 ?? mul.l rm,rn rn rm macl 32 32 32 bits 0000nnnnmmmm0111 ?? muls.w rm,rn signed, rn rm macl 16 16 32 bits 0010nnnnmmmm1111 ?? mulu.w rm,rn unsigned, rn rm macl 16 16 32 bits 0010nnnnmmmm1110 ?? neg rm,rn 0 ? rm rn 0110nnnnmmmm1011 ?? negc rm,rn 0 ? rm ? t rn, borrow t 0110nnnnmmmm1010 ? borrow sub rm,rn rn ? rm rn 0011nnnnmmmm1000 ?? subc rm,rn rn ? rm ? t rn, borrow t 0011nnnnmmmm1010 ? borrow subv rm,rn rn ? rm rn, underflow t 0011nnnnmmmm1011 ? underflow rev. 5.0, 04/01, page 138 of 394 table 7.5 logic operation instructions instruction operation instruction code privileged t bit and rm,rn rn & rm rn 0010nnnnmmmm1001 ?? and #imm,r0 r0 & imm r0 11001001iiiiiiii ?? and.b #imm,@(r0,gbr) (r0 + gbr) & imm (r0 + gbr) 11001101iiiiiiii ?? not rm,rn ~rm rn 0110nnnnmmmm0111 ?? or rm,rn rn | rm rn 0010nnnnmmmm1011 ?? or #imm,r0 r0 | imm r0 11001011iiiiiiii ?? or.b #imm,@(r0,gbr) (r0 + gbr) | imm (r0 + gbr) 11001111iiiiiiii ? tas.b @rn when (rn) = 0, 1 t otherwise, 0 t in both cases, 1 msb of (rn) 0100nnnn00011011 ?test result tst rm,rn rn & rm; when result = 0, 1 t otherwise, 0 t 0010nnnnmmmm1000 ?test result tst #imm,r0 r0 & imm; when result = 0, 1 t otherwise, 0 t 11001000iiiiiiii ?test result tst.b #imm,@(r0,gbr) (r0 + gbr) & imm; when result = 0, 1 t otherwise, 0 t 11001100iiiiiiii ?test result xor rm,rn rn rm rn 0010nnnnmmmm1010 ?? xor #imm,r0 r0 imm r0 11001010iiiiiiii ?? xor.b #imm,@(r0,gbr) (r0 + gbr) imm (r0 + gbr) 11001110iiiiiiii ?? rev. 5.0, 04/01, page 139 of 394 table 7.6 shift instructions instruction operation instruction code privileged t bit rotl rn t rn msb 0100nnnn00000100 ?msb rotr rn lsb rn t 0100nnnn00000101 ?lsb rotcl rn t rn t 0100nnnn00100100 ?msb rotcr rn t rn t 0100nnnn00100101 ?lsb shad rm,rn when rn 0, rn << rm rn when rn < 0, rn >> rm [msb rn] 0100nnnnmmmm1100 ?? shal rn t rn 0 0100nnnn00100000 ?msb shar rn msb rn t 0100nnnn00100001 ?lsb shld rm,rn when rn 0, rn << rm rn when rn < 0, rn >> rm [0 rn] 0100nnnnmmmm1101 ?? shll rn t rn 0 0100nnnn00000000 ?msb shlr rn 0 rn t 0100nnnn00000001 ?lsb shll2 rn rn << 2 rn 0100nnnn00001000 ?? shlr2 rn rn >> 2 rn 0100nnnn00001001 ?? shll8 rn rn << 8 rn 0100nnnn00011000 ?? shlr8 rn rn >> 8 rn 0100nnnn00011001 ?? shll16 rn rn << 16 rn 0100nnnn00101000 ?? shlr16 rn rn >> 16 rn 0100nnnn00101001 ?? rev. 5.0, 04/01, page 140 of 394 table 7.7 branch instructions instruction operation instruction code privileged t bit bf label when t = 0, disp 2 + pc + 4 pc when t = 1, nop 10001011dddddddd ?? bf/s label delayed branch; when t = 0, disp 2 + pc + 4 pc when t = 1, nop 10001111dddddddd ?? bt label when t = 1, disp 2 + pc + 4 pc when t = 0, nop 10001001dddddddd ?? bt/s label delayed branch; when t = 1, disp 2 + pc + 4 pc when t = 0, nop 10001101dddddddd ?? bra label delayed branch, disp 2 + pc + 4 pc 1010dddddddddddd ?? braf rn rn + pc + 4 pc 0000nnnn00100011 ?? bsr label delayed branch, pc + 4 pr, disp 2 + pc + 4 pc 1011dddddddddddd ?? bsrf rn delayed branch, pc + 4 pr, rn + pc + 4 pc 0000nnnn00000011 ?? jmp @rn delayed branch, rn pc 0100nnnn00101011 ?? jsr @rn delayed branch, pc + 4 pr, rn pc 0100nnnn00001011 ?? rts delayed branch, pr pc 0000000000001011 ?? rev. 5.0, 04/01, page 141 of 394 table 7.8 system control instructions instruction operation instruction code privileged t bit clrmac 0 mach, macl 0000000000101000 ?? clrs 0 s 0000000001001000 ?? clrt 0 t 0000000000001000 ?0 ldc rm,sr rm sr 0100mmmm00001110 privileged lsb ldc rm,gbr rm gbr 0100mmmm00011110 ?? ldc rm,vbr rm vbr 0100mmmm00101110 privileged ? ldc rm,ssr rm ssr 0100mmmm00111110 privileged ? ldc rm,spc rm spc 0100mmmm01001110 privileged ? ldc rm,dbr rm dbr 0100mmmm11111010 privileged ? ldc rm,rn_bank rm rn_bank (n = 0 to 7) 0100mmmm1nnn1110 privileged ? ldc.l @rm+,sr (rm) sr, rm + 4 rm 0100mmmm00000111 privileged lsb ldc.l @rm+,gbr (rm) gbr, rm + 4 rm 0100mmmm00010111 ?? ldc.l @rm+,vbr (rm) vbr, rm + 4 rm 0100mmmm00100111 privileged ? ldc.l @rm+,ssr (rm) ssr, rm + 4 rm 0100mmmm00110111 privileged ? ldc.l @rm+,spc (rm) spc, rm + 4 rm 0100mmmm01000111 privileged ? ldc.l @rm+,dbr (rm) dbr, rm + 4 rm 0100mmmm11110110 privileged ? ldc.l @rm+,rn_bank (rm) rn_bank, rm + 4 rm 0100mmmm1nnn0111 privileged ? lds rm,mach rm mach 0100mmmm00001010 ?? lds rm,macl rm macl 0100mmmm00011010 ?? lds rm,pr rm pr 0100mmmm00101010 ?? lds.l @rm+,mach (rm) mach, rm + 4 rm 0100mmmm00000110 ?? lds.l @rm+,macl (rm) macl, rm + 4 rm 0100mmmm00010110 ?? lds.l @rm+,pr (rm) pr, rm + 4 rm 0100mmmm00100110 ?? ldtlb pteh/ptel tlb 0000000000111000 privileged ? movca.l r0,@rn r0 (rn) (without fetching cache block) 0000nnnn11000011 ?? nop no operation 0000000000001001 ?? ocbi @rn invalidates operand cache block 0000nnnn10010011 ?? ocbp @rn writes back and invalidates operand cache block 0000nnnn10100011 ?? ocbwb @rn writes back operand cache block 0000nnnn10110011 ?? pref @rn (rn) operand cache 0000nnnn10000011 ?? rte delayed branch, ssr/spc sr/pc 0000000000101011 privileged ? rev. 5.0, 04/01, page 142 of 394 table 7.8 system control instructions (cont) instruction operation instruction code privileged t bit sets 1 s 0000000001011000 ?? sett 1 t 0000000000011000 ?1 sleep sleep or standby 0000000000011011 privileged ? stc sr,rn sr rn 0000nnnn00000010 privileged ? stc gbr,rn gbr rn 0000nnnn00010010 ?? stc vbr,rn vbr rn 0000nnnn00100010 privileged ? stc ssr,rn ssr rn 0000nnnn00110010 privileged ? stc spc,rn spc rn 0000nnnn01000010 privileged ? stc sgr,rn sgr rn 0000nnnn00111010 privileged ? stc dbr,rn dbr rn 0000nnnn11111010 privileged ? stc rm_bank,rn rm_bank rn (m = 0 to 7) 0000nnnn1mmm0010 privileged ? stc.l sr,@-rn rn ? 4 rn, sr (rn) 0100nnnn00000011 privileged ? stc.l gbr,@-rn rn ? 4 rn, gbr (rn) 0100nnnn00010011 ?? stc.l vbr,@-rn rn ? 4 rn, vbr (rn) 0100nnnn00100011 privileged ? stc.l ssr,@-rn rn ? 4 rn, ssr (rn) 0100nnnn00110011 privileged ? stc.l spc,@-rn rn ? 4 rn, spc (rn) 0100nnnn01000011 privileged ? stc.l sgr,@-rn rn ? 4 rn, sgr (rn) 0100nnnn00110010 privileged ? stc.l dbr,@-rn rn ? 4 rn, dbr (rn) 0100nnnn11110010 privileged ? stc.l rm_bank,@-rn rn ? 4 rn, rm_bank (rn) (m = 0 to 7) 0100nnnn1mmm0011 privileged ? sts mach,rn mach rn 0000nnnn00001010 ?? sts macl,rn macl rn 0000nnnn00011010 ?? sts pr,rn pr rn 0000nnnn00101010 ?? sts.l mach,@-rn rn ? 4 rn, mach (rn) 0100nnnn00000010 ?? sts.l macl,@-rn rn ? 4 rn, macl (rn) 0100nnnn00010010 ?? sts.l pr,@-rn rn ? 4 rn, pr (rn) 0100nnnn00100010 ?? trapa #imm pc + 2 spc, sr ssr, #imm << 2 tra, h'160 expevt, vbr + h'0100 pc 11000011iiiiiiii ?? rev. 5.0, 04/01, page 143 of 394 table 7.9 floating-point single-precision instructions instruction operation instruction code privileged t bit fldi0 frn h'00000000 frn 1111nnnn10001101 ?? fldi1 frn h'3f800000 frn 1111nnnn10011101 ?? fmov frm,frn frm frn 1111nnnnmmmm1100 ?? fmov.s @rm,frn (rm) frn 1111nnnnmmmm1000 ?? fmov.s @(r0,rm),frn (r0 + rm) frn 1111nnnnmmmm0110 ?? fmov.s @rm+,frn (rm) frn, rm + 4 rm 1111nnnnmmmm1001 ?? fmov.s frm,@rn frm (rn) 1111nnnnmmmm1010 ?? fmov.s frm,@-rn rn-4 rn, frm (rn) 1111nnnnmmmm1011 ?? fmov.s frm,@(r0,rn) frm (r0 + rn) 1111nnnnmmmm0111 ?? fmov drm,drn drm drn 1111nnn0mmm01100 ?? fmov @rm,drn (rm) drn 1111nnn0mmmm1000 ?? fmov @(r0,rm),drn (r0 + rm) drn 1111nnn0mmmm0110 ?? fmov @rm+,drn (rm) drn, rm + 8 rm 1111nnn0mmmm1001 ?? fmov drm,@rn drm (rn) 1111nnnnmmm01010 ?? fmov drm,@-rn rn-8 rn, drm (rn) 1111nnnnmmm01011 ?? fmov drm,@(r0,rn) drm (r0 + rn) 1111nnnnmmm00111 ?? flds frm,fpul frm fpul 1111mmmm00011101 ?? fsts fpul,frn fpul frn 1111nnnn00001101 ?? fabs frn frn & h'7fff ffff frn 1111nnnn01011101 ?? fadd frm,frn frn + frm frn 1111nnnnmmmm0000 ?? fcmp/eq frm,frn when frn = frm, 1 t otherwise, 0 t 1111nnnnmmmm0100 ? comparison result fcmp/gt frm,frn when frn > frm, 1 t otherwise, 0 t 1111nnnnmmmm0101 ? comparison result fdiv frm,frn frn/frm frn 1111nnnnmmmm0011 ?? float fpul,frn (float) fpul frn 1111nnnn00101101 ?? fmac fr0,frm,frn fr0*frm + frn frn 1111nnnnmmmm1110 ?? fmul frm,frn frn*frm frn 1111nnnnmmmm0010 ?? fneg frn frn h'80000000 frn 1111nnnn01001101 ?? fsqrt frn frn frn 1111nnnn01101101 ?? fsub frm,frn frn ? frm frn 1111nnnnmmmm0001 ?? ftrc frm,fpul (long) frm fpul 1111mmmm00111101 ?? rev. 5.0, 04/01, page 144 of 394 table 7.10 floating-point double-precision instructions instruction operation instruction code privileged t bit fabs drn drn & h'7fff ffff ffff ffff drn 1111nnn001011101 ?? fadd drm,drn drn + drm drn 1111nnn0mmm00000 ?? fcmp/eq drm,drn when drn = drm, 1 t otherwise, 0 t 1111nnn0mmm00100 ? comparison result fcmp/gt drm,drn when drn > drm, 1 t otherwise, 0 t 1111nnn0mmm00101 ? comparison result fdiv drm,drn drn /drm drn 1111nnn0mmm00011 ?? fcnvds drm,fpul double_to_ float[drm] fpul 1111mmm010111101 ?? fcnvsd fpul,drn float_to_ double [fpul] drn 1111nnn010101101 ?? float fpul,drn (float)fpul drn 1111nnn000101101 ?? fmul drm,drn drn *drm drn 1111nnn0mmm00010 ?? fneg drn drn ^ h'8000 0000 0000 0000 drn 1111nnn001001101 ?? fsqrt drn drn drn 1111nnn001101101 ?? fsub drm,drn drn ? drm drn 1111nnn0mmm00001 ?? ftrc drm,fpul (long) drm fpul 1111mmm000111101 ?? table 7.11 floating-point control instructions instruction operation instruction code privileged t bit lds rm,fpscr rm fpscr 0100mmmm01101010 ?? lds rm,fpul rm fpul 0100mmmm01011010 ?? lds.l @rm+,fpscr (rm) fpscr, rm+4 rm 0100mmmm01100110 ?? lds.l @rm+,fpul (rm) fpul, rm+4 rm 0100mmmm01010110 ?? sts fpscr,rn fpscr rn 0000nnnn01101010 ?? sts fpul,rn fpul rn 0000nnnn01011010 ?? sts.l fpscr,@-rn rn ? 4 rn, fpscr (rn) 0100nnnn01100010 ?? sts.l fpul,@-rn rn ? 4 rn, fpul (rn) 0100nnnn01010010 ?? rev. 5.0, 04/01, page 145 of 394 table 7.12 floating-point graphics acceleration instructions instruction operation instruction code privileged t bit fmov drm,xdn drm xdn 1111nnn1mmm01100 ?? fmov xdm,drn xdm drn 1111nnn0mmm11100 ?? fmov xdm,xdn xdm xdn 1111nnn1mmm11100 ?? fmov @rm,xdn (rm) xdn 1111nnn1mmmm1000 ?? fmov @rm+,xdn (rm) xdn, rm + 8 rm 1111nnn1mmmm1001 ?? fmov @(r0,rm),drn (r0 + rm) drn 1111nnn1mmmm0110 ?? fmov xdm,@rn xdm (rn) 1111nnnnmmm11010 ?? fmov xdm,@-rn rn ? 8 rn, xdm (rn) 1111nnnnmmm11011 ?? fmov xdm,@(r0,rn) xdm (r0+rn) 1111nnnnmmm10111 ?? fipr fvm,fvn inner_product [fvm, fvn] fr[n+3] 1111nnmm11101101 ?? ftrv xmtrx,fvn transform_vector [xmtrx, fvn] fvn 1111nn0111111101 ?? frchg ~fpscr.fr fpscr.fr 1111101111111101 ?? fschg ~fpscr.sz fpscr.sz 1111001111111101 ?? rev. 5.0, 04/01, page 146 of 394 rev. 5.0, 04/01, page 147 of 394 section 8 pipelining the sh-4 is a 2-ilp (instruction-level-parallelism) superscalar pipelining microprocessor. instruction execution is pipelined, and two instructions can be executed in parallel. the execution cycles depend on the implementation of a processor. definitions in this section may not be applicable to sh-4 series models other than the sh-4. 8.1 pipelines figure 8.1 shows the basic pipelines. normally, a pipeline consists of five or six stages: instruction fetch (i), decode and register read (d), execution (ex/sx/f0/f1/f2/f3), data access (na/ma), and write-back (s/fs). an instruction is executed as a combination of basic pipelines. figure 8.2 shows the instruction execution patterns. rev. 5.0, 04/01, page 148 of 394 1. general pipeline ? instruction fetch instruction decode issue register read destination address calculation for pc-relative branch non-memory data access write-back i d ex operation na s 2. general load/store pipeline instruction fetch instruction decode issue register read memory data access write-back i d ex address calculation ma s 3. special pipeline instruction fetch instruction decode issue register read non-memory data access write-back i d sx operation na s 4. special load/store pipeline instruction fetch instruction decode issue register read memory data access write-back i d sx address calculation ma s 5. floating-point pipeline instruction fetch instruction decode issue register read computation 2 computation 3 write-back i d f1 computation 1 f2 fs 6. floating-point extended pipeline instruction fetch instruction decode issue register read computation 1 computation 3 write-back i d f0 computation 0 f1 f2 fs computation 2 f3 computation: takes several cycles 7. fdiv/fsqrt pipeline figure 8.1 basic pipelines rev. 5.0, 04/01, page 149 of 394 1. 1-step operation: 1 issue cycle ext[su].[bw], mov, mov#, mova, movt, swap.[bw], xtrct, add*, cmp*, div*, dt, neg*, sub*, and, and#, not, or, or#, tst, tst#, xor, xor#, rot*, sha*, shl*, bf*, bt*, bra, nop, clrs, clrt, sets, sett, lds to fpul, sts from fpul/fpscr, fldi0, fldi1, fmov, flds, fsts, single-/double-precision fabs/fneg i d ex na s 2. load/store: 1 issue cycle mov.[bwl]. fmov*@, lds.l to fpul, ldtlb, pref, sts.l from fpul/fpscr i d ex ma s 3. gbr-based load/store: 1 issue cycle mov.[bwl]@(d,gbr) i d sx ma s 4. jmp, rts, braf: 2 issue cycles i d ex na s d ex na s 5. tst.b: 3 issue cycles i d sx ma s d sx na s d sx na s 6. and.b, or.b, xor.b: 4 issue cycles i d sx ma s d sx na s d sx na s d sx ma s 7. tas.b: 5 issue cycles i d ex ma s d ex ma s d ex na s d ex na s d ex ma s 8. rte: 5 issue cycles i d ex na s d ex na s d ex na s d ex na s d ex na s 9. sleep: 4 issue cycles i d ex na s d ex na s d ex na s d ex na s figure 8.2 instruction execution patterns rev. 5.0, 04/01, page 150 of 394 10. ocbi: 1 issue cycle i d ex ma s ma 11. ocbp, ocbwb: 1 issue cycle i d ex ma s ma ma ma ma 12. movca.l: 1 issue cycle i d ex ma s ma ma ma ma ma ma 13. trapa: 7 issue cycles i d ex na s d ex na s d ex na s d ex na s d ex na s d ex na s d ex na s 14. ldc to dbr/rp_bank/ssr/spc/vbr, bsr: 1 issue cycle i d ex na s sx sx 15. ldc to gbr: 3 issue cycles i d ex na s d d sx sx 16. ldc to sr: 4 issue cycles i d ex na s d d d sx sx sx i d ex ma s 17. ldc.l to dbr/rp_bank/ssr/spc/vbr: 1 issue cycle sx sx 18. ldc.l to gbr: 3 issue cycles i d ex ma s d d sx sx figure 8.2 instruction execution patterns (cont) rev. 5.0, 04/01, page 151 of 394 19. ldc.l to sr: 4 issue cycles i d ex ma s d d d sx sx sx 20. stc from dbr/gbr/rp_bank/sr/ssr/spc/vbr: 2 issue cycles i d sx na s d sx na s 21. stc.l from sgr: 3 issue cycles i d sx na s d sx na s d sx na s 22. stc.l from dbr/gbr/rp_bank/sr/ssr/spc/vbr: 2 issue cycles i d sx na s d sx ma s 23. stc.l from sgr: 3 issue cycles i d sx na s d sx na s d sx ma s 24. lds to pr, jsr, bsrf: 2 issue cycles i d ex na s d sx sx 25. lds.l to pr: 2 issue cycles i d ex ma s d sx sx 26. sts from pr: 2 issue cycles i d sx na s d sx na s 27. sts.l from pr: 2 issue cycles i d sx na s d sx ma s 28. clrmac, lds to mach/l: 1 issue cycle i d ex na s f1 f1 f2 fs 29. lds.l to mach/l: 1 issue cycle i d ex ma s f1 f1 f2 fs 30. sts from mach/l: 1 issue cycle i d ex na s figure 8.2 instruction execution patterns (cont) rev. 5.0, 04/01, page 152 of 394 31. sts.l from mach/l: 1 issue cycle i d ex ma s 32. lds to fpscr: 1 issue cycle i d ex na s f1 f1 f1 f1 f1 f1 33. lds.l to fpscr: 1 issue cycle i d ex ma s 34. fixed-point multiplication: 2 issue cycles dmuls.l, dmulu.l, mul.l, muls.w, mulu.w i d ex na (cpu) d ex na s f1 (fpu) f1 f1 f1 f2 fs 35. mac.w, mac.l: 2 issue cycles i d ex ma s (cpu) d ex ma s f1 (fpu) f1 f1 f1 f2 fs 36. single-precision floating-point computation: 1 issue cycle fcmp/eq,fcmp/gt, fadd,float,fmac,fmul,fsub,ftrc,frchg,fschg i d f1 f2 fs 37. single-precision fdiv/sqrt: 1 issue cycle i d f1 f2 fs f3 f1 f2 fs 38. double-precision floating-point computation 1: 1 issue cycle fcnvds, fcnvsd, float, ftrc i d f1 f2 fs d f1 f2 fs 39. double-precision floating-point computation 2: 1 issue cycle fadd, fmul, fsub i d f1 f2 fs d f1 f2 fs d f1 f2 fs d f1 f2 fs d f1 f2 fs f1 f2 fs figure 8.2 instruction execution patterns (cont) rev. 5.0, 04/01, page 153 of 394 i d f1 f2 fs d f1 f2 fs 40. double-precision fcmp: 2 issue cycles fcmp/eq,fcmp/gt i d f1 f2 fs f3 f1 f2 fs 41. double-precision fdiv/sqrt: 1 issue cycle fdiv, fsqrt f1 f2 d f1 f2 fs f1 f2 fs 42. fipr: 1 issue cycle i d f0 f1 f2 fs 43. ftrv: 1 issue cycle f1 f2 fs d f0 i f1 f2 fs d f0 f1 f2 fs d f0 f1 f2 fs d f0 notes: ?? : locks d-stage : register read only : locks, but no operation is executed. : can overlap another f1, but not another f1. d d ?? f1 : cannot overlap a stage of the same kind, except when two instructions are executed in parallel. figure 8.2 instruction execution patterns (cont) rev. 5.0, 04/01, page 154 of 394 8.2 parallel-executability instructions are categorized into six groups according to the internal function blocks used, as shown in table 8.1. table 8.2 shows the parallel-executability of pairs of instructions in terms of groups. for example, add in the ex group and bra in the br group can be executed in parallel. table 8.1 instruction groups 1. mt group clrt cmp/hi rm,rn mov rm,rn cmp/eq #imm,r0 cmp/hs rm,rn nop cmp/eq rm,rn cmp/pl rn sett cmp/ge rm,rn cmp/pz rn tst #imm,r0 cmp/gt rm,rn cmp/str rm,rn tst rm,rn 2. ex group add #imm,rn movt rn shll2 rn add rm,rn neg rm,rn shll8 rn addc rm,rn negc rm,rn shlr rn addv rm,rn not rm,rn shlr16 rn and #imm,r0 or #imm,r0 shlr2 rn and rm,rn or rm,rn shlr8 rn div0s rm,rn rotcl rn sub rm,rn div0u rotcr rn subc rm,rn div1 rm,rn rotl rn subv rm,rn dt rn rotr rn swap.b rm,rn exts.b rm,rn shad rm,rn swap.w rm,rn exts.w rm,rn shal rn xor #imm,r0 extu.b rm,rn shar rn xor rm,rn extu.w rm,rn shld rm,rn xtrct rm,rn mov #imm,rn shll rn mova @(disp,pc),r0 shll16 rn 3. br group bf disp bra disp bt disp bf/s disp bsr disp bt/s disp rev. 5.0, 04/01, page 155 of 394 table 8.1 instruction groups (cont) 4. ls group fabs drn fmov.s @rm+,frn mov.l r0,@(disp,gbr) fabs frn fmov.s frm,@(r0,rn) mov.l rm,@(disp,rn) fldi0 frn fmov.s frm,@-rn mov.l rm,@(r0,rn) fldi1 frn fmov.s frm,@rn mov.l rm,@-rn flds frm,fpul fneg drn mov.l rm,@rn fmov @(r0,rm),drn fneg frn mov.w @(disp,gbr),r0 fmov @(r0,rm),xdn fsts fpul,frn mov.w @(disp,pc),rn fmov @rm,drn lds rm,fpul mov.w @(disp,rm),r0 fmov @rm,xdn mov.b @(disp,gbr),r0 mov.w @(r0,rm),rn fmov @rm+,drn mov.b @(disp,rm),r0 mov.w @rm,rn fmov @rm+,xdn mov.b @(r0,rm),rn mov.w @rm+,rn fmov drm,@(r0,rn) mov.b @rm,rn mov.w r0,@(disp,gbr) fmov drm,@-rn mov.b @rm+,rn mov.w r0,@(disp,rn) fmov drm,@rn mov.b r0,@(disp,gbr) mov.w rm,@(r0,rn) fmov drm,drn mov.b r0,@(disp,rn) mov.w rm,@-rn fmov drm,xdn mov.b rm,@(r0,rn) mov.w rm,@rn fmov frm,frn mov.b rm,@-rn movca.l r0,@rn fmov xdm,@(r0,rn) mov.b rm,@rn ocbi @rn fmov xdm,@-rn mov.l @(disp,gbr),r0 ocbp @rn fmov xdm,@rn mov.l @(disp,pc),rn ocbwb @rn fmov xdm,drn mov.l @(disp,rm),rn pref @rn fmov xdm,xdn mov.l @(r0,rm),rn sts fpul,rn fmov.s @(r0,rm),frn mov.l @rm,rn fmov.s @rm,frn mov.l @rm+,rn rev. 5.0, 04/01, page 156 of 394 table 8.1 instruction groups (cont) 5. fe group fadd drm,drn fipr fvm,fvn fsqrt drn fadd frm,frn float fpul,drn fsqrt frn fcmp/eq frm,frn float fpul,frn fsub drm,drn fcmp/gt frm,frn fmac fr0,frm,frn fsub frm,frn fcnvds drm,fpul fmul drm,drn ftrc drm,fpul fcnvsd fpul,drn fmul frm,frn ftrc frm,fpul fdiv drm,drn frchg ftrv xmtrx,fvn fdiv frm,frn fschg rev. 5.0, 04/01, page 157 of 394 table 8.1 instruction groups (cont) 6. co group and.b #imm,@(r0,gbr) lds rm,fpscr stc sr,rn braf rn lds rm,mach stc ssr,rn bsrf rn lds rm,macl stc vbr,rn clrmac lds rm,pr stc.l dbr,@-rn clrs lds.l @rm+,fpscr stc.l gbr,@-rn dmuls.l rm,rn lds.l @rm+,fpul stc.l rp_bank,@-rn dmulu.l rm,rn lds.l @rm+,mach stc.l sgr,@-rn fcmp/eq drm,drn lds.l @rm+,macl stc.l spc,@-rn fcmp/gt drm,drn lds.l @rm+,pr stc.l sr,@-rn jmp @rn ldtlb stc.l ssr,@-rn jsr @rn mac.l @rm+,@rn+ stc.l vbr,@-rn ldc rm,dbr mac.w @rm+,@rn+ sts fpscr,rn ldc rm,gbr mul.l rm,rn sts mach,rn ldc rm,rp_bank muls.w rm,rn sts macl,rn ldc rm,spc mulu.w rm,rn sts pr,rn ldc rm,sr or.b #imm,@(r0,gbr) sts.l fpscr,@-rn ldc rm,ssr rte sts.l fpul,@-rn ldc rm,vbr rts sts.l mach,@-rn ldc.l @rm+,dbr sets sts.l macl,@-rn ldc.l @rm+,gbr sleep sts.l pr,@-rn ldc.l @rm+,rp_bank stc dbr,rn tas.b @rn ldc.l @rm+,spc stc gbr,rn trapa #imm ldc.l @rm+,sr stc rp_bank,rn tst.b #imm,@(r0,gbr) ldc.l @rm+,ssr stc sgr,rn xor.b #imm,@(r0,gbr) ldc.l @rm+,vbr stc spc,rn rev. 5.0, 04/01, page 158 of 394 table 8.2 parallel-executability 2nd instruction mt ex br ls fe co mt ooooox ex oxooox br o o x o o x ls o o o x o x fe ooooxx 1st instruction co xxxxxx o: can be executed in parallel x: cannot be executed in parallel 8.3 execution cycles and pipeline stalling there are three basic clocks in this processor: the i-clock, b-clock, and p-clock. each hardware unit operates on one of these clocks, as follows: ? i-clock: cpu, fpu, mmu, caches ? b-clock: external bus controller ? p-clock: peripheral units the frequency ratios of the three clocks are determined with the frequency control register (frqcr). in this section, machine cycles are based on the i-clock unless otherwise specified. for details of frqcr, see clock oscillation circuits in the hardware manual. instruction execution cycles are summarized in table 8.3. penalty cycles due to a pipeline stall or freeze are not considered in this table. ? issue rate: interval between the issue of an instruction and that of the next instruction ? latency: interval between the issue of an instruction and the generation of its result (completion) ? instruction execution pattern (see figure 8.2) ? locked pipeline stages ? interval between the issue of an instruction and the start of locking ? lock time: period of locking in machine cycle units rev. 5.0, 04/01, page 159 of 394 the instruction execution sequence is expressed as a combination of the execution patterns shown in figure 8.2. one instruction is separated from the next by the number of machine cycles for its issue rate. normally, execution, data access, and write-back stages cannot be overlapped onto the same stages of another instruction; the only exception is when two instructions are executed in parallel under parallel-executability conditions. refer to (a) through (d) in figure 8.3 for some simple examples. latency is the interval between issue and completion of an instruction, and is also the interval between the execution of two instructions with an interdependent relationship. when there is interdependency between two instructions fetched simultaneously, the latter of the two is stalled for the following number of cycles: ? (latency) cycles when there is flow dependency (read-after-write) ? (latency ? 1) or (latency ? 2) cycles when there is output dependency (write-after-write) ? single/double-precision fdiv, fsqrt is the preceding instruction (latency ? 1) cycles ? the other fe group is the preceding instruction (latency ? 2) cycles ? 5 or 2 cycles when there is anti-flow dependency (write-after-read), as in the following cases: ? ftrv is the preceding instruction (5 cycle) ? a double-precision fadd, fsub, or fmul is the preceding instruction (2 cycles) in the case of flow dependency, latency may be exceptionally increased or decreased, depending on the combination of sequential instructions (figure 8.3 (e)). ? when a floating-point (fpu) computation is followed by an fpu register store, the latency of the floating-point computation may be decreased by 1 cycle. ? if there is a load of the shift amount immediately before an shad/shld instruction, the latency of the load is increased by 1 cycle. ? if an instruction with a latency of less than 2 cycles, including write-back to an fpu register, is followed by a double-precision fpu instruction, fipr, or ftrv, the latency of the first instruction is increased to 2 cycles. the number of cycles in a pipeline stall due to flow dependency will vary depending on the combination of interdependent instructions or the fetch timing (see figure 8.3. (e)). output dependency occurs when the destination operands are the same in a preceding fe group instruction and a following ls group instruction. for the stall cycles of an instruction with output dependency, the longest latency to the last write- back among all the destination operands must be applied instead of ?latency? (see figure 8.3 (f)). a stall due to output dependency with respect to fpscr, which reflects the result of a floating- point operation, never occurs. for example, when fadd follows fdiv with no dependency between fpu registers, fadd is not stalled even if both instructions update the cause field of fpscr. rev. 5.0, 04/01, page 160 of 394 anti-flow dependency can occur only between a preceding double-precision fadd, fmul, fsub, or ftrv and a following fmov, fldi0, fldi1, fabs, fneg, or fsts. see figure 8.3 (g). if an executing instruction locks any resource?i.e. a function block that performs a basic operation?a following instruction that attempts to use the locked resource must be stalled (figure 8.3 (h)). this kind of stall can be compensated by inserting one or more instructions independent of the locked resource to separate the interfering instructions. for example, when a load instruction and an add instruction that references the loaded value are consecutive, the 2-cycle stall of the add is eliminated by inserting three instructions without dependency. software performance can be improved by such instruction scheduling. other penalties arise in the event of exceptions or external data accesses, as follows. ? instruction tlb miss ? instruction access to external memory (instruction cache miss, etc.) ? data access to external memory (operand cache miss, etc.) ? data access to a memory-mapped control register during the penalty cycles of an instruction tlb miss or external instruction access, no instruction is issued, but execution of instructions that have already been issued continues. the penalty for a data access is a pipeline freeze: that is, the execution of uncompleted instructions is interrupted until the arrival of the requested data. the number of penalty cycles for instruction and data accesses is largely dependent on the user?s memory subsystems. rev. 5.0, 04/01, page 161 of 394 (a) serial execution: non-parallel-executable instructions add r2,r1 mov.l @r4,r5 mov r1,r2 next shad r0,r1 add r2,r3 next i d ex na s i d ex na s id ... 1 stall cycle (b) parallel execution: parallel-executable and no dependency i d ex na s i d ex ma s (c) issue rate: multi-step instruction and.b#1,@(r0,gbr) i d sx ma s d sx ma s d sx na s d sx na s i i (d) branch 1 issue cycle 1 issue cycle 4 issue cycles ... i d ex na s i d ex na s 2-cycle latency for i-stage of branch destination 1 stall cycle i d i d ex na s i d ex na s i d ex na s bt/s l_far add r0,r1 sub r2,r3 bt/s l_far add r0,r1 l_far i d ex na s i d i d ? ?? ... no stall bt l_skip add #1,r0 l_skip: ... i d e a s 4 stall cycles ex-group shad and ex-group add cannot be executed in parallel. therefore, shad is issued first, and the following add is recombined with the next instruction. ex-group add and ls-group mov.l can be executed in parallel. overlapping of stages in the 2nd instruction is possible. and.b and mov are fetched simultaneously, but mov is stalled due to resource locking. after the lock is released, mov is refetched together with the next instruction. no stall occurs if the branch is not taken. if the branch is taken, the i-stage of the branch destination is stalled for the period of latency. this stall can be covered with a delay slot instruction which is not parallel- executable with the branch instruction. even if the bt/bf branch is taken, the i- stage of the branch destination is not stalled if the displacement is zero. figure 8.3 examples of pipelined execution rev. 5.0, 04/01, page 162 of 394 (e) flow dependency i d ex na s i d ex na s mov r0,r1 add r2,r1 add r2,r1 mov.l @r1,r1 next i d ex na s i d ex ma s i i ... ... ... zero-cycle latency 1-cycle latency 1 stall cycle mov.l @r1,r1 add r0,r1 next i d ex ma s i d i ex na s d ex na s 2-cycle latency 1 stall cycle mov.l @r1,r1 shad r1,r2 next fadd fr1,fr2 sts fpul,r1 sts fpscr,r2 i d ex na s i 4-cycle latency for fpscr 2 stall cycles i d f1 f2 fs i d ex ma s i d i 2-cycle latency 2 stall cycles ex na s d 1-cycle increase i i i d f1 f2 fs d f1 f2 fs d f1 f2 fs d f1 f2 fs f1 f2 fs d f1 f2 fs ex na s d ex na s d fadd dr0,dr2 7-cycle latency for lower fr 8-cycle latency for upper fr fmov fr3,fr5 fmov fr2,fr4 float fpul,dr0 fmov.s fr0,@-r15 fr3 write fr2 write i d f1 f2 fs d f1 f2 fs i d ex ma s 3-cycle latency for upper/lower fr fr1 write fr0 write fldi1 fr3 fipr fv0,fv4 fmov @r1,xd14 ftrv xmtrx,fv0 i d ex na s i d d f0 f1 f2 fs zero-cycle latency 3-cycle increase 3 stall cycles i d ex ma s i d d f0 f1 f2 fs d f0 f1 fs f2 d f0 f2 f1 fs d f1 f0 f2 fs 2-cycle latency 1-cycle increase 3 stall cycles the following instruction, add, is not stalled when executed after an instruction with zero-cycle latency, even if there is dependency. add and mov.l are not executed in parallel, since mov.l references the result of add as its destination address. because mov.l and add are not fetched simultaneously in this example, add is stalled for only 1 cycle even though the latency of mov.l is 2 cycles. due to the flow dependency between the load and the shad/shld shift amount, the latency of the load is increased to 3 cycles. figure 8.3 examples of pipelined execution (cont) rev. 5.0, 04/01, page 163 of 394 i d ex na s i d ex na s d f1 f2 fs d f1 f2 fs (e) flow dependency (cont) i i lds r0,fpul float fpul,fr0 lds r1,fpul float fpul,r1 effectively 1-cycle latency for consecutive lds/float instructions i d ex na s d f1 f2 fs i d f1 f2 fs i i d ex na s effectively 1-cycle latency for consecutive ftrc/sts instructions ftrc fr0,fpul sts fpul,r0 ftrc fr1,fpul sts fpul,r1 (f) output dependency d f1 f2 fs i i d f1 f2 fs f1 f2 fs 11-cycle latency 10 stall cycles = latency (11) - 1 the registers are written-back in program order. d f1 f2 fs i d f1 f2 fs d f1 f2 fs d f1 f2 fs d f1 f2 fs f1 f2 fs ex na s i d 7-cycle latency for lower fr 8-cycle latency for upper fr 6 stall cycles = longest latency (8) - 2 fr2 write fr3 write d f1 f2 fs i d f1 f2 fs d f1 f2 fs d f1 f0 f0 f0 f0 f2 fs (g) anti-flow dependency ex ma s i d 5 stall cycles d f1 f2 fs i d f1 f2 fs d f1 f2 fs d f1 f2 fs ex na s i d 2 stall cycles d f1 f2 fs f1 f2 fs fsqrt fr4 fmov fr0,fr4 fadd dr0,dr2 fmov fr0,fr3 ftrv xmtrx,fv0 fmov @r1,xd0 fadd dr0,dr2 fmov fr4,fr1 f3 figure 8.3 examples of pipelined execution (cont) rev. 5.0, 04/01, page 164 of 394 (h) resource conflict f1 stage locked for 1 cycle latency 1 cycle/issue 1 stall cycle (f1 stage resource conflict) fdiv fr6,fr7 fmac fr0,fr8,fr9 fmac fr0,fr10,fr11 fmac fr0,fr12,fr13 fipr fv8,fv0 fadd fr15,fr4 i d f1 f0 f2 fs i d f1 f2 fs 1 stall cycle lds.l @r15+,pr i d ex ma fs dsx sx sx na s sx na s d i 3 stall cycles stc gbr,r2 fadd dr0,dr2 i d f1 f2 fs d f1 f2 fs d f1 f2 fs d f1 f2 fs d f1 f2 fs f1 f2 fs ex ma s f1 ex ma s d f1 f1 f2 fs f1 f2 fs i d 5 stall cycles mac.w @r1+,@r2+ i d ex ma s f1 f1 f1 f2 fs f1 f2 fs i f1 d ex ma s f1 d ex ma s f1 f2 fs f1 f2 fs f1 f2 fs d f1 f2 fs d f1 f2 fs d f1 f2 fs d f1 f2 fs f1 ... i d 3 stall cycles 1 stall cycle 2 stall cycles mac.w @r1+,@r2+ mac.w @r1+,@r2+ fadd dr4,dr6 f1 stage can overlap preceding f1, but f1 cannot overlap f1. d ex ma s d i d f1 f2 fs i d f1 f2 fs f1 f2 fs f1 f2 i dfs f3 i d f1 f2 fs #1 #2 #3 .................................................. #10 #11 #8 #9 #12 ... : figure 8.3 examples of pipelined execution (cont) rev. 5.0, 04/01, page 165 of 394 table 8.3 execution cycles lock functional category no. instruction instruc- tion group issue rate latency execu- tion pattern stage start cycles 1 exts.b rm,rn ex 1 1 #1 ? ? ? 2 exts.w rm,rn ex 1 1 #1 ? ? ? 3 extu.b rm,rn ex 1 1 #1 ? ? ? 4 extu.w rm,rn ex 1 1 #1 ? ? ? 5mov rm,rn mt 1 0 #1 ? ?? 6mov #imm,rn ex 1 1 #1 ? ?? 7 mova @(disp,pc),r0 ex 1 1 #1 ? ? ? 8 mov.w @(disp,pc),rn ls 1 2 #2 ? ? ? 9 mov.l @(disp,pc),rn ls 1 2 #2 ? ? ? 10 mov.b @rm,rn ls 1 2 #2 ? ? ? 11 mov.w @rm,rn ls 1 2 #2 ? ? ? 12 mov.l @rm,rn ls 1 2 #2 ? ? ? 13 mov.b @rm+,rn ls 1 1/2 #2 ? ? ? 14 mov.w @rm+,rn ls 1 1/2 #2 ? ? ? 15 mov.l @rm+,rn ls 1 1/2 #2 ? ? ? 16 mov.b @(disp,rm),r0 ls 1 2 #2 ? ? ? 17 mov.w @(disp,rm),r0 ls 1 2 #2 ? ? ? 18 mov.l @(disp,rm),rn ls 1 2 #2 ? ? ? 19 mov.b @(r0,rm),rn ls 1 2 #2 ? ? ? 20 mov.w @(r0,rm),rn ls 1 2 #2 ? ? ? 21 mov.l @(r0,rm),rn ls 1 2 #2 ? ? ? 22 mov.b @(disp,gbr),r0 ls 1 2 #3 ? ? ? 23 mov.w @(disp,gbr),r0 ls 1 2 #3 ? ? ? 24 mov.l @(disp,gbr),r0 ls 1 2 #3 ? ? ? 25 mov.b rm,@rn ls 1 1 #2 ? ? ? 26 mov.w rm,@rn ls 1 1 #2 ? ? ? 27 mov.l rm,@rn ls 1 1 #2 ? ? ? 28 mov.b rm,@-rn ls 1 1/1 #2 ? ? ? 29 mov.w rm,@-rn ls 1 1/1 #2 ? ? ? 30 mov.l rm,@-rn ls 1 1/1 #2 ? ? ? data transfer instructions 31 mov.b r0,@(disp,rn) ls 1 1 #2 ? ? ? rev. 5.0, 04/01, page 166 of 394 table 8.3 execution cycles (cont) lock functional category no. instruction instruc- tion group issue rate latency execu- tion pattern stage start cycles 32 mov.w r0,@(disp,rn) ls 1 1 #2 ? ? ? 33 mov.l rm,@(disp,rn) ls 1 1 #2 ? ? ? 34 mov.b rm,@(r0,rn) ls 1 1 #2 ? ? ? 35 mov.w rm,@(r0,rn) ls 1 1 #2 ? ? ? 36 mov.l rm,@(r0,rn) ls 1 1 #2 ? ? ? 37 mov.b r0,@(disp,gbr) ls 1 1 #3 ? ? ? 38 mov.w r0,@(disp,gbr) ls 1 1 #3 ? ? ? 39 mov.l r0,@(disp,gbr) ls 1 1 #3 ? ? ? 40 movca.l r0,@rn ls 1 3?7 #12 ma 4 3?7 41 movt rn ex 1 1 #1 ? ? ? 42 ocbi @rn ls 1 1?2 #10 ma 4 1?2 43 ocbp @rn ls 1 1?5 #11 ma 4 1?5 44 ocbwb @rn ls 1 1?5 #11 ma 4 1?5 45 pref @rn ls 1 1 #2 ? ? ? 46 swap.b rm,rn ex 1 1 #1 ? ? ? 47 swap.w rm,rn ex 1 1 #1 ? ? ? data transfer instructions 48 xtrct rm,rn ex 1 1 #1 ? ? ? 49 add rm,rn ex 1 1 #1 ? ? ? 50 add #imm,rn ex 1 1 #1 ? ? ? 51 addc rm,rn ex 1 1 #1 ? ? ? 52 addv rm,rn ex 1 1 #1 ? ? ? 53 cmp/eq #imm,r0 mt 1 1 #1 ? ? ? 54 cmp/eq rm,rn mt 1 1 #1 ? ? ? 55 cmp/ge rm,rn mt 1 1 #1 ? ? ? 56 cmp/gt rm,rn mt 1 1 #1 ? ? ? 57 cmp/hi rm,rn mt 1 1 #1 ? ? ? 58 cmp/hs rm,rn mt 1 1 #1 ? ? ? 59 cmp/pl rn mt 1 1 #1 ? ? ? 60 cmp/pz rn mt 1 1 #1 ? ? ? 61 cmp/str rm,rn mt 1 1 #1 ? ? ? fixed-point arithmetic instructions 62 div0s rm,rn ex 1 1 #1 ? ? ? rev. 5.0, 04/01, page 167 of 394 table 8.3 execution cycles (cont) lock functional category no. instruction instruc- tion group issue rate latency execu- tion pattern stage start cycles 63 div0u ex 1 1 #1 ? ? ? 64 div1 rm,rn ex 1 1 #1 ? ? ? 65 dmuls.l rm,rn co 2 4/4 #34 f1 4 2 66 dmulu.l rm,rn co 2 4/4 #34 f1 4 2 67 dt rn ex 1 1 #1 ? ? ? 68 mac.l @rm+,@rn+ co 2 2/2/4/4 #35 f1 4 2 69 mac.w @rm+,@rn+ co 2 2/2/4/4 #35 f1 4 2 70 mul.l rm,rn co 2 4/4 #34 f1 4 2 71 muls.w rm,rn co 2 4/4 #34 f1 4 2 72 mulu.w rm,rn co 2 4/4 #34 f1 4 2 73 neg rm,rn ex 1 1 #1 ? ? ? 74 negc rm,rn ex 1 1 #1 ? ? ? 75 sub rm,rn ex 1 1 #1 ? ? ? 76 subc rm,rn ex 1 1 #1 ? ? ? fixed-point arithmetic instructions 77 subv rm,rn ex 1 1 #1 ? ? ? 78 and rm,rn ex 1 1 #1 ? ? ? 79 and #imm,r0 ex 1 1 #1 ? ? ? 80 and.b #imm,@(r0,gbr) co 4 4 #6 ? ? ? 81 not rm,rn ex 1 1 #1 ? ? ? 82 or rm,rn ex 1 1 #1 ? ? ? 83 or #imm,r0 ex 1 1 #1 ? ? ? 84 or.b #imm,@(r0,gbr) co 4 4 #6 ? ? ? 85 tas.b @rn co 5 5 #7 ? ? ? 86 tst rm,rn mt 1 1 #1 ? ? ? 87 tst #imm,r0 mt 1 1 #1 ? ? ? 88 tst.b #imm,@(r0,gbr) co 3 3 #5 ? ? ? 89 xor rm,rn ex 1 1 #1 ? ? ? 90 xor #imm,r0 ex 1 1 #1 ? ? ? logical instructions 91 xor.b #imm,@(r0,gbr) co 4 4 #6 ? ? ? rev. 5.0, 04/01, page 168 of 394 table 8.3 execution cycles (cont) lock functional category no. instruction instruc- tion group issue rate latency execu- tion pattern stage start cycles 92 rotl rn ex 1 1 #1 ? ? ? 93 rotr rn ex 1 1 #1 ? ? ? 94 rotcl rn ex 1 1 #1 ? ? ? 95 rotcr rn ex 1 1 #1 ? ? ? 96 shad rm,rn ex 1 1 #1 ? ? ? 97 shal rn ex 1 1 #1 ? ? ? 98 shar rn ex 1 1 #1 ? ? ? 99 shld rm,rn ex 1 1 #1 ? ? ? 100 shll rn ex 1 1 #1 ? ? ? 101 shll2 rn ex 1 1 #1 ? ? ? 102 shll8 rn ex 1 1 #1 ? ? ? 103 shll16 rn ex 1 1 #1 ? ? ? 104 shlr rn ex 1 1 #1 ? ? ? 105 shlr2 rn ex 1 1 #1 ? ? ? 106 shlr8 rn ex 1 1 #1 ? ? ? shift instructions 107 shlr16 rn ex 1 1 #1 ? ? ? 108 bf disp br 1 2 (or 1) #1 ? ? ? 109 bf/s disp br 1 2 (or 1) #1 ? ? ? 110 bt disp br 1 2 (or 1) #1 ? ? ? 111 bt/s disp br 1 2 (or 1) #1 ? ? ? 112 bra disp br 1 2 #1 ? ? ? 113 braf rn co 2 3 #4 ? ? ? 114 bsr disp br 1 2 #14 sx 3 2 115 bsrf rn co 2 3 #24 sx 3 2 116 jmp @rn co 2 3 #4 ? ? ? 117 jsr @rn co 2 3 #24 sx 3 2 branch instructions 118 rts co 2 3 #4 ? ? ? rev. 5.0, 04/01, page 169 of 394 table 8.3 execution cycles (cont) lock functional category no. instruction instruc- tion group issue rate latency execu- tion pattern stage start cycles 119 nop mt 1 0 #1 ? ? ? 120 clrmac co 1 3 #28 f1 3 2 121 clrs co 1 1 #1 ? ? ? 122 clrt mt 1 1 #1 ? ? ? 123 sets co 1 1 #1 ? ? ? 124 sett mt 1 1 #1 ? ? ? 125 trapa #imm co 7 7 #13 ? ? ? 126 rte co 5 5 #8 ? ? ? 127 sleep co 4 4 #9 ? ? ? 128 ldtlb co 1 1 #2 ? ? ? 129 ldc rm,dbr co 1 3 #14 sx 3 2 130 ldc rm,gbr co 3 3 #15 sx 3 2 131 ldc rm,rp_bank co 1 3 #14 sx 3 2 132 ldc rm,sr co 4 4 #16 sx 3 2 133 ldc rm,ssr co 1 3 #14 sx 3 2 134 ldc rm,spc co 1 3 #14 sx 3 2 135 ldc rm,vbr co 1 3 #14 sx 3 2 136 ldc.l @rm+,dbr co 1 1/3 #17 sx 3 2 137 ldc.l @rm+,gbr co 3 3/3 #18 sx 3 2 138 ldc.l @rm+,rp_bank co 1 1/3 #17 sx 3 2 139 ldc.l @rm+,sr co 4 4/4 #19 sx 3 2 140 ldc.l @rm+,ssr co 1 1/3 #17 sx 3 2 141 ldc.l @rm+,spc co 1 1/3 #17 sx 3 2 142 ldc.l @rm+,vbr co 1 1/3 #17 sx 3 2 143 lds rm,mach co 1 3 #28 f1 3 2 144 lds rm,macl co 1 3 #28 f1 3 2 145 lds rm,pr co 2 3 #24 sx 3 2 146 lds.l @rm+,mach co 1 1/3 #29 f1 3 2 147 lds.l @rm+,macl co 1 1/3 #29 f1 3 2 148 lds.l @rm+,pr co 2 2/3 #25 sx 3 2 149 stc dbr,rn co 2 2 #20 ? ? ? system control instructions 150 stc sgr,rn co 3 3 #21 ? ? ? rev. 5.0, 04/01, page 170 of 394 table 8.3 execution cycles (cont) lock functional category no. instruction instruc- tion group issue rate latency execu- tion pattern stage start cycles 151 stc gbr,rn co 2 2 #20 ? ? ? 152 stc rp_bank,rn co 2 2 #20 ? ? ? 153 stc sr,rn co 2 2 #20 ? ? ? 154 stc ssr,rn co 2 2 #20 ? ? ? 155 stc spc,rn co 2 2 #20 ? ? ? 156 stc vbr,rn co 2 2 #20 ? ? ? 157 stc.l dbr,@-rn co 2 2/2 #22 ? ? ? 158 stc.l sgr,@-rn co 3 3/3 #23 ? ? ? 159 stc.l gbr,@-rn co 2 2/2 #22 ? ? ? 160 stc.l rp_bank,@-rn co 2 2/2 #22 ? ? ? 161 stc.l sr,@-rn co 2 2/2 #22 ? ? ? 162 stc.l ssr,@-rn co 2 2/2 #22 ? ? ? 163 stc.l spc,@-rn co 2 2/2 #22 ? ? ? 164 stc.l vbr,@-rn co 2 2/2 #22 ? ? ? 165 sts mach,rn co 1 3 #30 ? ? ? 166 sts macl,rn co 1 3 #30 ? ? ? 167 sts pr,rn co 2 2 #26 ? ? ? 168 sts.l mach,@-rn co 1 1/1 #31 ? ? ? 169 sts.l macl,@-rn co 1 1/1 #31 ? ? ? system control instructions 170 sts.l pr,@-rn co 2 2/2 #27 ? ? ? 171 fldi0 frn ls 1 0 #1 ? ? ? 172 fldi1 frn ls 1 0 #1 ? ? ? 173 fmov frm,frn ls 1 0 #1 ? ? ? 174 fmov.s @rm,frn ls 1 2 #2 ? ? ? 175 fmov.s @rm+,frn ls 1 1/2 #2 ? ? ? 176 fmov.s @(r0,rm),frn ls 1 2 #2 ? ? ? 177 fmov.s frm,@rn ls 1 1 #2 ? ? ? 178 fmov.s frm,@-rn ls 1 1/1 #2 ? ? ? 179 fmov.s frm,@(r0,rn) ls 1 1 #2 ? ? ? 180 flds frm,fpul ls 1 0 #1 ? ? ? single- precision floating-point instructions 181 fsts fpul,frn ls 1 0 #1 ? ? ? rev. 5.0, 04/01, page 171 of 394 table 8.3 execution cycles (cont) lock functional category no. instruction instruc- tion group issue rate latency execu- tion pattern stage start cycles 182 fabs frn ls 1 0 #1 ? ? ? 183 fadd frm,frn fe 1 3/4 #36 ? ? ? 184 fcmp/eq frm,frn fe 1 2/4 #36 ? ? ? 185 fcmp/gt frm,frn fe 1 2/4 #36 ? ? ? 186 fdiv frm,frn fe 1 12/13 #37 f3 2 10 f1 11 1 187 float fpul,frn fe 1 3/4 #36 ? ? ? 188 fmac fr0,frm,frn fe 1 3/4 #36 ? ? ? 189 fmul frm,frn fe 1 3/4 #36 ? ? ? 190 fneg frn ls 1 0 #1 ? ? ? 191 fsqrt frn fe 1 11/12 #37 f3 2 9 f1 10 1 192 fsub frm,frn fe 1 3/4 #36 ? ? ? 193 ftrc frm,fpul fe 1 3/4 #36 ? ? ? 194 fmov drm,drn ls 1 0 #1 ? ? ? 195 fmov @rm,drn ls 1 2 #2 ? ? ? 196 fmov @rm+,drn ls 1 1/2 #2 ? ? ? 197 fmov @(r0,rm),drn ls 1 2 #2 ? ? ? 198 fmov drm,@rn ls 1 1 #2 ? ? ? 199 fmov drm,@-rn ls 1 1/1 #2 ? ? ? single- precision floating-point instructions 200 fmov drm,@(r0,rn) ls 1 1 #2 ? ? ? 201 fabs drn ls 1 0 #1 ? ? ? 202 fadd drm,drn fe 1 (7, 8)/9 #39 f1 2 6 203 fcmp/eq drm,drn co 2 3/5 #40 f1 2 2 204 fcmp/gt drm,drn co 2 3/5 #40 f1 2 2 205 fcnvds drm,fpul fe 1 4/5 #38 f1 2 2 206 fcnvsd fpul,drn fe 1 (3, 4)/5 #38 f1 2 2 f3 2 23 f1 22 3 207 fdiv drm,drn fe 1 (24, 25)/ 26 #41 f1 2 2 208 float fpul,drn fe 1 (3, 4)/5 #38 f1 2 2 double- precision floating-point instructions 209 fmul drm,drn fe 1 (7, 8)/9 #39 f1 2 6 rev. 5.0, 04/01, page 172 of 394 table 8.3 execution cycles (cont) lock functional category no. instruction instruc- tion group issue rate latency execu- tion pattern stage start cycles 210 fneg drn ls 1 0 #1 ? ? ? f3 2 22 f1 21 3 211 fsqrt drn fe 1 (23, 24)/ 25 #41 f1 2 2 212 fsub drm,drn fe 1 (7, 8)/9 #39 f1 2 6 double- precision floating-point instructions 213 ftrc drm,fpul fe 1 4/5 #38 f1 2 2 214 lds rm,fpul ls 1 1 #1 ? ? ? 215 lds rm,fpscr co 1 4 #32 f1 3 3 216 lds.l @rm+,fpul co 1 1/2 #2 ? ? ? 217 lds.l @rm+,fpscr co 1 1/4 #33 f1 3 3 218 sts fpul,rn ls 1 3 #1 ? ? ? 219 sts fpscr,rn co 1 3 #1 ? ? ? 220 sts.l fpul,@-rn co 1 1/1 #2 ? ? ? fpu system control instructions 221 sts.l fpscr,@-rn co 1 1/1 #2 ? ? ? 222 fmov drm,xdn ls 1 0 #1 ? ? ? 223 fmov xdm,drn ls 1 0 #1 ? ? ? 224 fmov xdm,xdn ls 1 0 #1 ? ? ? 225 fmov @rm,xdn ls 1 2 #2 ? ? ? 226 fmov @rm+,xdn ls 1 1/2 #2 ? ? ? 227 fmov @(r0,rm),xdn ls 1 2 #2 ? ? ? 228 fmov xdm,@rn ls 1 1 #2 ? ? ? 229 fmov xdm,@-rm ls 1 1/1 #2 ? ? ? 230 fmov xdm,@(r0,rn) ls 1 1 #2 ? ? ? 231 fipr fvm,fvn fe 1 4/5 #42 f1 3 1 232 frchg fe 1 1/4 #36 ? ? ? 233 fschg fe 1 1/4 #36 ? ? ? f0 2 4 graphics acceleration instructions 234 ftrv xmtrx,fvn fe 1 (5, 5, 6, 7)/8 #43 f1 3 4 notes: 1. see table 8.1 for the instruction groups. 2. latency ?l1/l2...?: latency corresponding to a write to each register, including mach/macl/fpscr. example: mov.b @rm+, rn ?1/2?: the latency for rm is 1 cycle, and the latency for rn is 2 cycles. 3. branch latency: interval until the branch destination instruction is fetched rev. 5.0, 04/01, page 173 of 394 4. conditional branch latency ?2 (or 1)?: the latency is 2 for a nonzero displacement, and 1 for a zero displacement. 5. double-precision floating-point instruction latency ?(l1, l2)/l3?: l1 is the latency for fr [n+1], l2 that for fr [n], and l3 that for fpscr. 6. ftrv latency ?(l1, l2, l3, l4)/l5?: l1 is the latency for fr [n], l2 that for fr [n+1], l3 that for fr [n+2], l4 that for fr [n+3], and l5 that for fpscr. 7. latency ?l1/l2/l3/l4? of mac.l and mac.w instructions: l1 is the latency for rm, l2 that for rn, l3 that for mach, and l4 that for macl. 8. latency ?l1/l2? of mul.l, muls.w, mulu.w, dmuls.l, and dmulu.l instructions: l1 is the latency for mach, and l2 that for macl. 9. execution pattern: the instruction execution pattern number (see figure 8.2) 10. lock/stage: stage locked by the instruction 11. lock/start: locking start cycle; 1 is the first d-stage of the instruction. 12. lock/cycles: number of cycles locked exceptions: 1. when a floating-point computation instruction is followed by an fmov store, an sts fpul, rn instruction, or an sts.l fpul, @-rn instruction, the latency of the floating- point computation is decreased by 1 cycle. 2. when the preceding instruction loads the shift amount of the following shad/shld, the latency of the load is increased by 1 cycle. 3. when an ls group instruction with a latency of less than 3 cycles is followed by a double-precision floating-point instruction, fipr, or ftrv, the latency of the first instruction is increased to 3 cycles. example: in the case of fmov fr4,fr0 and fipr fv0,fv4, fipr is stalled for 2 cycles. 4. when mac*/mul*/dmul* is followed by an sts.l mac*, @-rn instruction, the latency of mac*/mul*/dmul* is 5 cycles. 5. in the case of consecutive executions of mac*/mul*/dmul*, the latency is decreased to 2 cycles. 6. when an lds to mac* is followed by an sts.l mac*, @-rn instruction, the latency of the lds to mac* is 4 cycles. 7. when an lds to mac* is followed by mac*/mul*/dmul*, the latency of the lds to mac* is 1 cycle. 8. when an fschg or frchg instruction is followed by an ls group instruction that reads or writes to a floating-point register, the aforementioned ls group instruction[s] cannot be executed in parallel. 9. when a single-precision ftrc instruction is followed by an sts fpul, rn instruction, the latency of the single-precision ftrc instruction is 1 cycle. rev. 5.0, 04/01, page 174 of 394 rev. 5.0, 04/01, page 175 of 394 section 9 instruction descriptions instructions are listed in this section in alphabetical order. the following format is used for the instruction descriptions. instruction name full name instruction type function (indication of delayed branch instruction or interrupt-disabling instruction) format summary of operation instruction code execution states t bit the assembler input format is shown. imm and disp are numeric values, expressions, or symbols. summarizes the operation of the instruction. shown in msb lsb order. the no- wait value is shown. shows the t bit value after execution of the instruction. description describes the operation of the instruction. notes identifies points to be noted when using the instruction. operation shows the operation in c. this is given as reference material to help understand the operation of the instruction. use of the following resources is assumed. char 8-bit integer short 16-bit integer int 32-bit integer long 64-bit integer float single-precision floating point number(32 bits) double double-precision floating point number(64 bits) these are data types. rev. 5.0, 04/01, page 176 of 394 unsigned char read_byte(unsigned long addr); unsigned short read_word(unsigned long addr); unsigned long read_long(unsigned long addr); these reflect the respective sizes of address addr. a word read from other than a 2n address, or a longword read from other than a 4n address, will be detected as an address error. unsigned char write_byte(unsigned long addr, unsigned long data); unsigned short write_word(unsigned long addr, unsigned long data); unsigned long write_long(unsigned long addr, unsigned long data); these write data data to address addr, using the respective sizes. a word write to other than a 2n address, or a longword write to other than a 4n address, will be detected as an address error. delay_slot(unsigned long addr); shifts to execution of the slot instruction at address (addr). unsigned long r[16]; unsigned long sr,gbr,vbr; unsigned long mach,macl,pr; unsigned long pc; registers struct sr0 { unsigned long dummy0:22; unsigned long m0:1; unsigned long q0:1; unsigned long i0:4; unsigned long dummy1:2; unsigned long s0:1; unsigned long t0:1; }; sr structure definitions define m ((*(struct sr0 *)(&sr)).m0) #define q ((*(struct sr0 *)(&sr)).q0) #define s ((*(struct sr0 *)(&sr)).s0) #define t ((*(struct sr0 *)(&sr)).t0) definitions of bits in sr rev. 5.0, 04/01, page 177 of 394 error( char *er ); error display function these are floating-point number definition statements. #define pzero 0 #define nzero 1 #define denorm 2 #define norm 3 #define pinf 4 #define ninf 5 #define qnan 6 #define snan 7 #define eq 0 #define gt 1 #define lt 2 #define uo 3 #define invalid 4 #define fadd 0 #define fsub 1 #define cause 0x0003f000 /* fpscr(bit17-12) */ #define set_e 0x00020000 /* fpscr(bit17) */ #define set_v 0x00010040 /* fpscr(bit16,6) */ #define set_z 0x00008020 /* fpscr(bit15,5) */ #define set_o 0x00004010 /* fpscr(bit14,4) */ #define set_u 0x00002008 /* fpscr(bit13,3) */ #define set_i 0x00001004 /* fpscr(bit12,2) */ #define enable_voui 0x00000b80 /* fpscr(bit11,9-7) */ #define enable_v 0x00000800 /* fpscr(bit11) */ #define enable_z 0x00000400 /* fpscr(bit10) */ #define enable_oui 0x00000380 /* fpscr(bit9-7) */ #define enable_i 0x00000080 /* fpscr(bit7) */ #define flag 0x0000007c /* fpscr(bit6-2) */ #define fpscr_fr fpscr>>21&1 #define fpscr_pr fpscr>>19&1 #define fpscr_dn fpscr>>18&1 rev. 5.0, 04/01, page 178 of 394 #define fpscr_i fpscr>>12&1 #define fpscr_rm fpscr&1 #define fr_hex frf.l[ fpscr_fr] #define fr frf.f[ fpscr_fr] #define dr frf.d[ fpscr_fr] #define xf_hex frf.l[~fpscr_fr] #define xf frf.f[~fpscr_fr] #define xd frf.d[~fpscr_fr] union { int l[2][16]; float f[2][16]; double d[2][8]; } frf; int fpscr; int sign_of(int n) { return(fr_hex[n]>>31); } int data_type_of(int n) { int abs; abs = fr_hex[n] & 0x7fffffff; if(fpscr_pr == 0) { /* single-precision */ if(abs < 0x00800000){ if((fpscr_dn == 1) || (abs == 0x00000000)){ if(sign_of(n) == 0) {zero(n, 0); return(pzero);} else {zero(n, 1); return(nzero);} } else return(denorm); } else if(abs < 0x7f800000) return(norm); else if(abs == 0x7f800000) { if(sign_of(n) == 0) return(pinf); else return(ninf); } else if(abs < 0x7fc00000) return(qnan); rev. 5.0, 04/01, page 179 of 394 else return(snan); } else { /* double-precision */ if(abs < 0x00100000){ if((fpscr_dn == 1) || ((abs == 0x00000000) && (fr_hex[n+1] == 0x00000000)){ if(sign_of(n) == 0) {zero(n, 0); return(pzero);} else {zero(n, 1); return(nzero);} } else return(denorm); } else if(abs < 0x7ff00000) return(norm); else if((abs == 0x7ff00000) && (fr_hex[n+1] == 0x00000000)) { if(sign_of(n) == 0) return(pinf); else return(ninf); } else if(abs < 0x7ff80000) return(qnan); else return(snan); } } void register_copy(int m,n) { fr[n] = fr[m]; if(fpscr_pr == 1) fr[n+1] = fr[m+1]; } void normal_faddsub(int m,n,type) { union { float f; int l; } dstf,srcf; union { long d; int l[2]; } dstd,srcd; union { /* ?long double? format: */ rev. 5.0, 04/01, page 180 of 394 long double x; /* 1-bit sign */ int l[4]; /* 15-bit exponent */ } dstx; /* 112-bit mantissa */ if(fpscr_pr == 0) { if(type == fadd) srcf.f = fr[m]; else srcf.f = -fr[m]; dstd.d = fr[n]; /* conversion from single-precision to double-precision */ dstd.d += srcf.f; if(((dstd.d == fr[n]) && (srcf.f != 0.0)) || ((dstd.d == srcf.f) && (fr[n] != 0.0))) { set_i(); if(sign_of(m)^ sign_of(n)) { dstd.l[1] -= 1; if(dstd.l[1] == 0xffffffff) dstd.l[0] -= 1; } } if(dstd.l[1] & 0x1fffffff) set_i(); dstf.f += srcf.f; /* round to nearest */ if(fpscr_rm == 1) { dstd.l[1] &= 0xe0000000; /* round to zero */ dstf.f = dstd.d; } check_single_exception(&fr[n],dstf.f); } else { if(type == fadd) srcd.d = dr[m>>1]; else srcd.d = -dr[m>>1]; dstx.x = dr[n>>1]; /* conversion from double-precision to extended double-precision */ dstx.x += srcd.d; if(((dstx.x == dr[n>>1]) && (srcd.d != 0.0)) || ((dstx.x == srcd.d) && (dr[n>>1] != 0.0)) ) { set_i(); if(sign_of(m)^ sign_of(n)) { dstx.l[3] -= 1; if(dstx.l[3] == 0xffffffff) {dstx.l[2] -= 1; if(dstx.l[2] == 0xffffffff) {dstx.l[1] -= 1; if(dstx.l[1] == 0xffffffff) {dstx.l[0] -= 1;}}} rev. 5.0, 04/01, page 181 of 394 } } if((dstx.l[2] & 0x0fffffff) || dstx.l[3]) set_i(); dst.d += srcd.d; /* round to nearest */ if(fpscr_rm == 1) { dstx.l[2] &= 0xf0000000; /* round to zero */ dstx.l[3] = 0x00000000; dst.d = dstx.x; } check_double_exception(&dr[n>>1] ,dst.d); } } void normal_fmul(int m,n) { union { float f; int l; } tmpf; union { double d; int l[2]; } tmpd; union { long double x; int l[4]; } tmpx; if(fpscr_pr == 0) { tmpd.d = fr[n]; /* single-precision to double-precision */ tmpd.d *= fr[m]; /* precise creation */ tmpf.f *= fr[m]; /* round to nearest */ if(tmpf.f != tmpd.d) set_i(); if((tmpf.f > tmpd.d) && (fpscr_rm == 1)) { tmpf.l -= 1; /* round to zero */ } check_single_exception(&fr[n],tmpf.f); } else { tmpx.x = dr[n>>1]; /* single-precision to double-precision */ rev. 5.0, 04/01, page 182 of 394 tmpx.x *= dr[m>>1]; /* precise creation */ tmpd.d *= dr[m>>1]; /* round to nearest */ if(tmpd.d != tmpx.x) set_i(); if(tmpd.d > tmpx.x) && (fpscr_rm == 1)) { tmpd.l[1] -= 1; /* round to zero */ if(tmpd.l[1] == 0xffffffff) tmpd.l[0] -= 1; } check_double_exception(&dr[n>>1], tmpd.d); } } void fipr(int m,n) { union { double d; int l[2]; } mlt[4]; float dstf; if((data_type_of(m) == snan) || (data_type_of(n) == snan) || (data_type_of(m+1) == snan) || (data_type_of(n+1) == snan) || (data_type_of(m+2) == snan) || (data_type_of(n+2) == snan) || (data_type_of(m+3) == snan) || (data_type_of(n+3) == snan) || (check_product_invalid(m,n)) || (check_product_invalid(m+1,n+1)) || (check_product_invalid(m+2,n+2)) || (check_product_invalid(m+3,n+3)) ) invalid(n+3); else if((data_type_of(m) == qnan)|| (data_type_of(n) == qnan)|| (data_type_of(m+1) == qnan) || (data_type_of(n+1) == qnan) || (data_type_of(m+2) == qnan) || (data_type_of(n+2) == qnan) || (data_type_of(m+3) == qnan) || (data_type_of(n+3) == qnan)) qnan(n+3); else if (check_ positive_infinity() && (check_ negative_infinity()) invalid(n+3); else if (check_ positive_infinity()) inf(n+3,0); else if (check_ negative_infinity()) inf(n+3,1); else { for(i=0;i<4;i++) { /* if fpscr_dn == 1, zeroize */ if (data_type_of(m+i) == pzero) fr[m+i] = +0.0; rev. 5.0, 04/01, page 183 of 394 else if(data_type_of(m+i) == nzero) fr[m+i] = -0.0; if (data_type_of(n+i) == pzero) fr[n+i] = +0.0; else if(data_type_of(n+i) == nzero) fr[n+i] = -0.0; mlt[i].d = fr[m+i]; mlt[i].d *= fr[n+i]; /* to be precise, with fipr, the lower 18 bits are discarded; therefore, this description is simplified, and differs from the hardware. */ mlt[i].l[1] &= 0xff000000; mlt[i].l[1] |= 0x00800000; } mlt[0].d += mlt[1].d + mlt[2].d + mlt[3].d; mlt[0].l[1] &= 0xff800000; dstf = mlt[0].d; set_i(); check_single_exception(&fr[n+3],dstf); } } void check_single_exception(float *dst,result) { union { float f; int l; } tmp; float abs; if(result < 0.0) tmp.l = 0xff800000; /* ? infinity */ else tmp.l = 0x7f800000; /* + infinity */ if(result == tmp.f) { set_o(); set_i(); if(fpscr_rm == 1) { tmp.l -= 1; /* maximum value of normalized number */ result = tmp.f; } } if(result < 0.0) abs = -result; else abs = result; tmp.l = 0x00800000; /* minimum value of normalized number */ rev. 5.0, 04/01, page 184 of 394 if(abs < tmp.f) { if((fpscr_dn == 1) && (abs != 0.0)) { set_i(); if(result < 0.0) result = -0.0; /* zeroize denormalized number */ else result = 0.0; } if(fpscr_i == 1) set_u(); } if(fpscr & enable_oui) fpu_exception_trap(); else *dst = result; } void check_double_exception(double *dst,result) { union { double d; int l[2]; } tmp; double abs; if(result < 0.0) tmp.l[0] = 0xfff00000; /* ? infinity */ else tmp.l[0] = 0x7ff00000; /* + infinity */ tmp.l[1] = 0x00000000; if(result == tmp.d) set_o(); set_i(); if(fpscr_rm == 1) { tmp.l[0] -= 1; tmp.l[1] = 0xffffffff; result = tmp.d; /* maximum value of normalized number */ } } if(result < 0.0) abs = -result; else abs = result; tmp.l[0] = 0x00100000; /* minimum value of normalized number */ tmp.l[1] = 0x00000000; if(abs < tmp.d) { if((fpscr_dn == 1) && (abs != 0.0)) { set_i(); if(result < 0.0) result = -0.0; rev. 5.0, 04/01, page 185 of 394 /* zeroize denormalized number */ else result = 0.0; } if(fpscr_i == 1) set_u(); } if(fpscr & enable_oui) fpu_exception_trap(); else *dst = result; } int check_product_invalid(int m,n) { return(check_product_infinity(m,n) && ((data_type_of(m) == pzero) || (data_type_of(n) == pzero) || (data_type_of(m) == nzero) || (data_type_of(n) == nzero))); } int check_ product_infinity(int m,n) { return((data_type_of(m) == pinf) || (data_type_of(n) == pinf) || (data_type_of(m) == ninf) || (data_type_of(n) == ninf)); } int check_ positive_infinity(int m,n) { return(((check_ product_infinity(m,n) && (~sign_of(m)^ sign_of(n))) || ((check_ product_infinity(m+1,n+1) && (~sign_of(m+1)^ sign_of(n+1))) || ((check_ product_infinity(m+2,n+2) && (~sign_of(m+2)^ sign_of(n+2))) || ((check_ product_infinity(m+3,n+3) && (~sign_of(m+3)^ sign_of(n+3)))); } int check_ negative_infinity(int m,n) { return(((check_ product_infinity(m,n) && (sign_of(m)^ sign_of(n))) || ((check_ product_infinity(m+1,n+1) && (sign_of(m+1)^ sign_of(n+1))) || ((check_ product_infinity(m+2,n+2) && (sign_of(m+2)^ sign_of(n+2))) || ((check_ product_infinity(m+3,n+3) && (sign_of(m+3)^ sign_of(n+3)))); rev. 5.0, 04/01, page 186 of 394 } void clear_cause () {fpscr &= ~cause;} void set_e() {fpscr |= set_e; fpu_exception_trap();} void set_v() {fpscr |= set_v;} void set_z() {fpscr |= set_z;} void set_o() {fpscr |= set_o;} void set_u() {fpscr |= set_u;} void set_i() {fpscr |= set_i;} void invalid(int n) { set_v(); if((fpscr & enable_v) == 0 qnan(n); else fpu_exception_trap(); } void dz(int n,sign) { set_z(); if((fpscr & enable_z) == 0 inf(n,sign); else fpu_exception_trap(); } void zero(int n,sign) { if(sign == 0) fr_hex [n] = 0x00000000; else fr_hex [n] = 0x80000000; if (fpscr_pr==1) fr_hex [n+1] = 0x00000000; } void inf(int n,sign) { if (fpscr_pr==0) { if(sign == 0) fr_hex [n] = 0x7f800000; else fr_hex [n] = 0xff800000; } else { if(sign == 0) fr_hex [n] = 0x7ff00000; else fr_hex [n] = 0xfff00000; fr_hex [n+1] = 0x00000000; } } rev. 5.0, 04/01, page 187 of 394 void qnan(int n) { if (fpscr_pr==0) fr[n] = 0x7fbfffff; else { fr[n] = 0x7ff7ffff; fr[n+1] = 0xffffffff; } } example an example is shown using assembler mnemonics, indicating the states before and after execution of the instruction. italics (e.g., .align ) indicate an assembler control instruction. the meaning of the assembler control instructions is given below. for details, refer to the cross-assembler user?s manual. .org location counter setting .data.w word integer data allocation .data.l longword integer data allocation .sdata string data allocation .align 2 2-byte boundary alignment .align 4 4-byte boundary alignment .align 32 32-byte boundary alignment .arepeat 16 16-times repeat expansion .arepea t 32 32-times repeat expansion .aendr count-specification repeat expansion end note: sh series cross-assembler version 1.0 does not support conditional assembler functions. rev. 5.0, 04/01, page 188 of 394 9.1 add add binary arithmetic instruction binary addition format summary of operation instruction code execution states t bit add rm,rn rn+rm rn 0011nnnnmmmm1100 1? add #imm,rn rn+imm rn 0111nnnniiiiiiii 1? description this instruction adds together the contents of general registers rn and rm and stores the result in rn. 8-bit immediate data can also be added to the contents of general register rn. 8-bit immediate data is sign-extended to 32 bits, allowing use in decrement operations. operation add(long m, long n) /* add rm,rn */ { r[n]+=r[m]; pc+=2; } addi(long i, long n) /* add #imm,rn */ { if ((i&0x80)==0) r[n]+=(0x000000ff & (long)i); else r[n]+=(0xffffff00 | (long)i); pc+=2; } rev. 5.0, 04/01, page 189 of 394 example add r0,r1 ; before execution r0 = h'7fffffff, r1 = h'00000001 ; after execution r1 = h'80000000 add #h'01,r2 ; before execution r2 = h'00000000 ; after execution r2 = h'00000001 add #h'fe,r3 ; before execution r3 = h'00000001 ; after execution r3 = h'ffffffff rev. 5.0, 04/01, page 190 of 394 9.2 addc add with carry arithmetic instruction binary addition with carry format summary of operation instruction code execution states t bit addc rm,rn rn+rm+t rn, carry t 0011nnnnmmmm1110 1 carry description this instruction adds together the contents of general registers rn and rm and the t bit, and stores the result in rn. a carry resulting from the operation is reflected in the t bit. this instruction is used for additions exceeding 32 bits. operation addc(long m, long n) /* addc rm,rn */ { unsigned long tmp0,tmp1; tmp1=r[n]+r[m]; tmp0=r[n]; r[n]=tmp1+t; if (tmp0>tmp1) t=1; else t=0; if (tmp1>r[n]) t=1; pc+=2; } example clrt ; r0:r1(64 bits) + r2:r3(64 bits) = r0:r1(64 bits) addc r3,r1 ; before execution t = 0, r1 = h'00000001, r3 = h'ffffffff ; after execution t = 1, r1 = h'00000000 addc r2,r0 ; before execution t = 1, r0 = h'00000000, r2 = h'00000000 ; after execution t = 0, r0 = h'00000001 rev. 5.0, 04/01, page 191 of 394 9.3 addv add with (v flag) overflow check arithmetic instruction binary addition with overflow check format summary of operation instruction code execution states t bit addv rm,rn rn+rm rn, overflow t 0011nnnnmmmm1111 1overflow description this instruction adds together the contents of general registers rn and rm and stores the result in rn. if overflow occurs, the t bit is set. operation addv(long m, long n) /* addv rm,rn */ { long dest,src,ans; if ((long)r[n]>=0) dest=0; else dest=1; if ((long)r[m]>=0) src=0; else src=1; src+=dest; r[n]+=r[m]; if ((long)r[n]>=0) ans=0; else ans=1; ans+=dest; if (src==0 || src==2) { if (ans==1) t=1; else t=0; } else t=0; pc+=2; } rev. 5.0, 04/01, page 192 of 394 example addv r0,r1 ; before execution r0 = h'00000001, r1 = h'7ffffffe, t=0 ; after execution r1 = h'7fffffff, t=0 addv r0,r1 ; before execution r0 = h'00000002, r1 = h'7ffffffe, t=0 ; after execution r1 = h'80000000, t=1 rev. 5.0, 04/01, page 193 of 394 9.4 and and logical logical instruction logical and format summary of operation instruction code execution states t bit and rm,rn rm & rm rn 0010nnnnmmmm1001 1? and #imm,r0 r0 & imm r0 11001001iiiiiiii 1? and.b #imm,@(r0,gbr) (r0+gbr) & imm (r0+gbr) 11001101iiiiiiii 4? description this instruction ands the contents of general registers rn and rm and stores the result in rn. this instruction can be used to and general register r0 contents with zero-extended 8-bit immediate data, or, in indexed gbr indirect addressing mode, to and 8-bit memory with 8-bit immediate data. notes with and #imm,r0, the upper 24 bits of r0 are always cleared as a result of the operation. operation and(long m, long n) /* and rm,rn */ { r[n]&=r[m]; pc+=2; } andi(long i) /* and #imm,r0 */ { r[0]&=(0x000000ff & (long)i); pc+=2; } andm(long i) /* and.b #imm,@(r0,gbr) */ { long temp; temp=(long)read_byte(gbr+r[0]); rev. 5.0, 04/01, page 194 of 394 temp&=(0x000000ff & (long)i); write_byte(gbr+r[0],temp); pc+=2; } example and r0,r1 ; before execution r0 = h'aaaaaaaa, r1=h'55555555 ; after execution r1 = h'00000000 and #h'0f,r0 ; before execution r0 = h'ffffffff ; after execution r0 = h'0000000f and.b #h'80,@(r0,gbr) ; before execution (r0,gbr) = h'a5 ; after execution (r0,gbr) = h'80 rev. 5.0, 04/01, page 195 of 394 9.5 bf branch if false branch instruction conditional branch format summary of operation instruction code execution states t bit bf label if t = 0 pc + 4 + disp 2 pc if t = 1, nop 10001011dddddddd 1? description this is a conditional branch instruction that references the t bit. the branch is taken if t = 0, and not taken if t = 1. the branch destination is address (pc + 4 + displacement 2). the pc source value is the bf instruction address. as the 8-bit displacement is multiplied by two after sign- extension, the branch destination can be located in the range from ?256 to +254 bytes from the bf instruction. notes if the branch destination cannot be reached, the branch must be handled by using bf in combination with a bra or jmp instruction, for example. operation bf(int d) /* bf disp */ { int disp; if ((d&0x80)==0) disp=(0x000000ff & d); else disp=(0xffffff00 | d); if (t==0) pc=pc+4+(disp<<1); else pc+=2; } rev. 5.0, 04/01, page 196 of 394 example clrt ; normally t = 0 bt trget_t ; t = 0, so branch is not taken. bf trget_f ; t = 0, so branch to trget_f. nop ; nop ; trget_f: ; bf instruction branch destination rev. 5.0, 04/01, page 197 of 394 9.6 bf/s branch if false with delay slot branch instruction conditional branch with delay delayed branch instruction format summary of operation instruction code execution states t bit bf/s label if t = 0 pc + 4 + disp 2 pc if t = 1, nop 10001111dddddddd 1? description this is a delayed conditional branch instruction that references the t bit. if t = 1, the next instruction is executed and the branch is not taken. if t = 0, the branch is taken after execution of the next instruction. the branch destination is address (pc + 4 + displacement 2). the pc source value is the bf/s instruction address. as the 8-bit displacement is multiplied by two after sign-extension, the branch destination can be located in the range from ?256 to +254 bytes from the bf/s instruction. notes as this is a delayed branch instruction, when the branch condition is satisfied, the instruction following this instruction is executed before the branch destination instruction. interrupts are not accepted between this instruction and the following instruction. if the following instruction is a branch instruction, it is identified as a slot illegal instruction. if this instruction is located in the delay slot immediately following a delayed branch instruction, it is identified as a slot illegal instruction. if the branch destination cannot be reached, the branch must be handled by using bf/s in combination with a bf, bra, or jmp instruction, for example. rev. 5.0, 04/01, page 198 of 394 operation bfs(int d) /* bfs disp */ { int disp; unsigned int temp; temp=pc; if ((d&0x80)==0) disp=(0x000000ff & d); else disp=(0xffffff00 | d); if (t==0) pc=pc+4+(disp<<1); else pc+=4; delay_slot(temp+2); } example clrt ; normally t = 0 bt/s trget_t ; t = 0, so branch is not taken. nop ; bf/s trget_f ; t = 0, so branch to trget. add r0,r1 ; executed before branch. nop ; trget_f: ; bf/s instruction branch destination rev. 5.0, 04/01, page 199 of 394 9.7 bra branch branch instruction unconditional branch delayed branch instruction format summary of operation instruction code execution states t bit bra label pc+4+disp 2 pc 1010dddddddddddd 1? description this is an unconditional branch instruction. the branch destination is address (pc + 4 + displacement 2). the pc source value is the bra instruction address. as the 12-bit displacement is multiplied by two after sign-extension, the branch destination can be located in the range from ?4096 to +4094 bytes from the bra instruction. if the branch destination cannot be reached, this branch can be performed with a jmp instruction. notes as this is a delayed branch instruction, the instruction following this instruction is executed before the branch destination instruction. interrupts are not accepted between this instruction and the following instruction. if the following instruction is a branch instruction, it is identified as a slot illegal instruction. operation bra(int d) /* bra disp */ { int disp; unsigned int temp; temp=pc; if ((d&0x800)==0) disp=(0x00000fff & d); else disp=(0xfffff000 | d); pc=pc+4+(disp<<1); delay_slot(temp+2); } rev. 5.0, 04/01, page 200 of 394 example bra trget ; branch to trget. add r0,r1 ; add executed before branch. nop ; trget: ; bra instruction branch destination rev. 5.0, 04/01, page 201 of 394 9.8 braf branch far branch instruction unconditional branch delayed branch instruction format summary of operation instruction code execution states t bit braf rn pc+4+rn pc 0000nnnn00100011 2? description this is an unconditional branch instruction. the branch destination is address (pc + 4 + rn). the branch destination address is the result of adding 4 plus the 32-bit contents of general register rn to pc. notes as this is a delayed branch instruction, the instruction following this instruction is executed before the branch destination instruction. interrupts are not accepted between this instruction and the following instruction. if the following instruction is a branch instruction, it is identified as a slot illegal instruction. operation braf(int n) /* braf rn */ { unsigned int temp; temp=pc; pc=pc+4+r[n]; delay_slot(temp+2); } example mov.l #(trget-braf_pc),r0 ; set displacement. braf r0 ; branch to trget. add r0,r1 ; add executed before branch. braf_pc: ; nop trget: ; braf instruction branch destination rev. 5.0, 04/01, page 202 of 394 9.9 bsr branch to subroutine branch instruction branch to subroutine procedure delayed branch instruction format summary of operation instruction code execution states t bit bsr label pc+4 pr, pc+4+disp 2 pc 1011dddddddddddd 1? description this instruction branches to address (pc + 4 + displacement 2), and stores address (pc + 4) in pr. the pc source value is the bsr instruction address. as the 12-bit displacement is multiplied by two after sign-extension, the branch destination can be located in the range from ?4096 to +4094 bytes from the bsr instruction. if the branch destination cannot be reached, this branch can be performed with a jsr instruction. notes as this is a delayed branch instruction, the instruction following this instruction is executed before the branch destination instruction. interrupts are not accepted between this instruction and the following instruction. if the following instruction is a branch instruction, it is identified as a slot illegal instruction. operation bsr(int d) /* bsr disp */ { int disp; unsigned int temp; temp=pc; if ((d&0x800)==0) disp=(0x00000fff & d); else disp=(0xfffff000 | d); pr=pc+4; pc=pc+4+(disp<<1); delay_slot(temp+2); } rev. 5.0, 04/01, page 203 of 394 example bsr trget ; branch to trget. mov r3,r4 ; mov executed before branch. add r0,r1 ; subroutine procedure return destination (contents of pr) ..... ..... trget: ; entry to procedure mov r2,r3 ; rts ; return to above add instruction. mov #1,r0 ; mov executed before branch. rev. 5.0, 04/01, page 204 of 394 9.10 bsrf branch to subroutine far branch instruction branch to subroutine procedure delayed branch instruction format summary of operation instruction code execution states t bit bsrf rn pc+4 pr, pc+4+rn pc 0000nnnn00000011 2? description this instruction branches to address (pc + 4 + rn), and stores address (pc + 4) in pr. the pc source value is the bsrf instruction address. the branch destination address is the result of adding the 32-bit contents of general register rn to pc + 4. notes as this is a delayed branch instruction, the instruction following this instruction is executed before the branch destination instruction. interrupts are not accepted between this instruction and the following instruction. if the following instruction is a branch instruction, it is identified as a slot illegal instruction. operation bsrf(int n) /* bsrf rn */ { unsigned int temp; temp=pc; pr=pc+4; pc=pc+4+r[n]; delay_slot(temp+2); } rev. 5.0, 04/01, page 205 of 394 example mov.l #(trget-bsrf_pc),r0 ; set displacement. bsrf r0 ; branch to trget. mov r3,r4 ; mov executed before branch. bsrf_pc: ; add r0,r1 ; ..... trget: ; entry to procedure mov r2,r3 ; rts ; return to above add instruction. mov #1,r0 ; mov executed before branch. rev. 5.0, 04/01, page 206 of 394 9.11 bt branch if true branch instruction conditional branch format summary of operation instruction code execution states t bit bt label if t = 1 pc + 4 + disp 2 pc if t = 0, nop 10001001dddddddd 1? description this is a conditional branch instruction that references the t bit. the branch is taken if t = 1, and not taken if t = 0. the branch destination is address (pc + 4 + displacement 2). the pc source value is the bt instruction address. as the 8-bit displacement is multiplied by two after sign-extension, the branch destination can be located in the range from ?256 to +254 bytes from the bt instruction. notes if the branch destination cannot be reached, the branch must be handled by using bt in combination with a bra or jmp instruction, for example. operation bt(int d) /* bt disp */ { int disp; if ((d&0x80)==0) disp=(0x000000ff & d); else disp=(0xffffff00 | d); if (t==1) pc=pc+4+(disp<<1); else pc+=2; } rev. 5.0, 04/01, page 207 of 394 example sett ; normally t = 1 bf trget_f ; t = 1, so branch is not taken. bt trget_t ; t = 1, so branch to trget_t. nop ; nop ; trget_t: ; bt instruction branch destination rev. 5.0, 04/01, page 208 of 394 9.12 bt/s branch if true with delay slot branch instruction conditional branch with delay delayed branch instruction format summary of operation instruction code execution states t bit bt/s label if t = 1 pc + 4 + disp 2 pc if t = 0, nop 10001101dddddddd 1? description this is a conditional branch instruction that references the t bit. the branch is taken if t = 1, and not taken if t = 0. the pc source value is the bt/s instruction address. as the 8-bit displacement is multiplied by two after sign-extension, the branch destination can be located in the range from ?256 to +254 bytes from the bt/s instruction. if the branch destination cannot be reached, the branch must be handled by using bt/s in combination with a bra or jmp instruction, for example. notes as this is a delayed branch instruction, when the branch condition is satisfied, the instruction following this instruction is executed before the branch destination instruction. interrupts are not accepted between this instruction and the following instruction. if the following instruction is a branch instruction, it is identified as a slot illegal instruction. rev. 5.0, 04/01, page 209 of 394 operation bts(int d) /* bts disp */ { int disp; unsigned temp; temp=pc; if ((d&0x80)==0) disp=(0x000000ff & d); else disp=(0xffffff00 | d); if (t==1) pc=pc+4+(disp<<1); else pc+=4; delay_slot(temp+2); } example sett ; normally t = 1 bf/s trget_f ; t = 1, so branch is not taken. nop ; bt/s trget_t ; t = 1, so branch to trget_t. add r0,r1 ; executed before branch. nop ; trget_t: ; bt/s instruction branch destination rev. 5.0, 04/01, page 210 of 394 9.13 clrmac clear mac register system control instruction mac register clear format summary of operation instruction code execution states t bit clrmac 0 mach, macl 0000000000101000 1? description this instruction clears the mach and macl registers. operation clrmac( ) /* clrmac */ { mach=0; macl=0; pc+=2; } example clrmac ; clear mac register to initialize. mac.w @r0+,@r1+ ; multiply-and-accumulate operation mac.w @r0+,@r1+ ; rev. 5.0, 04/01, page 211 of 394 9.14 clrs clear s bit system control instruction s bit clear format summary of operation instruction code execution states t bit clrs 0 s 0000000001001000 1? description this instruction clears the s bit to 0. operation clrs( ) /* clrs */ { s=0; pc+=2; } example clrs ; before execution s = 1 ; after execution s = 0 rev. 5.0, 04/01, page 212 of 394 9.15 clrt clear t bit system control instruction t bit clear format summary of operation instruction code execution states t bit clrt 0 t 0000000000001000 10 description this instruction clears the t bit. operation clrt( ) /* clrt */ { t=0; pc+=2; } example clrt ; before execution t = 1 ; after execution t = 0 rev. 5.0, 04/01, page 213 of 394 9.16 cmp/cond compare conditionally arithmetic instruction compare format summary of operation instruction code execution states t bit cmp/eq rm,rn if rn = rm, 1 t 0011nnnnmmmm0000 1 result of comparison cmp/ge rm,rn if rn rm, signed, 1 t 0011nnnnmmmm0011 1 result of comparison cmp/gt rm,rn if rn > rm, signed, 1 t 0011nnnnmmmm0111 1 result of comparison cmp/hi rm,rn if rn > rm, unsigned, 1 t 0011nnnnmmmm0110 1 result of comparison cmp/hs rm,rn if rn rm, unsigned, 1 t 0011nnnnmmmm0010 1 result of comparison cmp/pl rn if rn > 0, 1 t 0100nnnn00010101 1 result of comparison cmp/pz rn if rn 0, 1 t 0100nnnn00010001 1 result of comparison cmp/str rm,rn if any bytes are equal, 1 t 0010nnnnmmmm1100 1 result of comparison cmp/eq #imm,r0 if r0 = imm, 1 t 10001000iiiiiiii 1 result of comparison description this instruction compares general registers rn and rm, and sets the t bit if the specified condition (cond) is true. if the condition is false, the t bit is cleared. the contents of rn are not changed. nine conditions can be specified. for the two conditions pz and pl, rn is compared with 0. with the eq condition, sign-extended 8-bit immediate data can be compared with r0. the contents of r0 are not changed. rev. 5.0, 04/01, page 214 of 394 mnemonic description cmp/eq rm,rn if rn = rm, t = 1 cmp/ge rm,rn if rn rm as signed values, t = 1 cmp/gt rm,rn if rn > rm as signed values, t = 1 cmp/hi rm,rn if rn > rm as unsigned values, t = 1 cmp/hs rm,rn if rn rm as unsigned values, t = 1 cmp/pl rn if rn > 0, t = 1 cmp/pz rn if rn 0, t = 1 cmp/str rm,rn if any bytes are equal, t = 1 cmp/eq #imm,r0 if r0 = imm, t = 1 operation cmpeq(long m, long n) /* cmp_eq rm,rn */ { if (r[n]==r[m]) t=1; else t=0; pc+=2; } cmpge(long m, long n) /* cmp_ge rm,rn */ { if ((long)r[n]>=(long)r[m]) t=1; else t=0; pc+=2; } cmpgt(long m, long n) /* cmp_gt rm,rn */ { if ((long)r[n]>(long)r[m]) t=1; else t=0; pc+=2; } cmphi(long m, long n) /* cmp_hi rm,rn */ { if ((unsigned long)r[n]>(unsigned long)r[m]) t=1; else t=0; rev. 5.0, 04/01, page 215 of 394 pc+=2; } cmphs(long m, long n) /* cmp_hs rm,rn */ { if ((unsigned long)r[n]>=(unsigned long)r[m]) t=1; else t=0; pc+=2; } cmppl(long n) /* cmp_pl rn */ { if ((long)r[n]>0) t=1; else t=0; pc+=2; } cmppz(long n) /* cmp_pz rn */ { if ((long)r[n]>=0) t=1; else t=0; pc+=2; } cmpstr(long m, long n) /* cmp_str rm,rn */ { unsigned long temp; long hh,hl,lh,ll; temp=r[n]^r[m]; hh=(temp&0xff000000)>>24; hl=(temp&0x00ff0000)>>16; lh=(temp&0x0000ff00)>>8; ll=temp&0x000000ff; hh=hh&&hl&&lh&≪ if (hh==0) t=1; else t=0; rev. 5.0, 04/01, page 216 of 394 pc+=2; } cmpim(long i) /* cmp_eq #imm,r0 */ { long imm; if ((i&0x80)==0) imm=(0x000000ff & (long i)); else imm=(0xffffff00 | (long i)); if (r[0]==imm) t=1; else t=0; pc+=2; } example cmp/ge r0,r1 ; r0 = h'7fffffff, r1 = h'80000000 bt trget_t ; t = 0, so branch is not taken. cmp/hs r0,r1 ; r0 = h'7fffffff, r1 = h'80000000 bt trget_t ; t = 1, so branch is taken. cmp/str r2,r3 ; r2 = "abcd", r3 = "xycz" bt trget_t ; t = 1, so branch is taken. rev. 5.0, 04/01, page 217 of 394 9.17 div0s divide (step 0) as signed arithmetic instruction initialization for signed division format summary of operation instruction code execution states t bit div0s rm,rn msb of rn q, msb of rm m, m^q t 0010nnnnmmmm0111 1 result of calculation description this instruction performs initial settings for signed division. this instruction is followed by a div1 instruction that executes 1-digit division, for example, and repeated divisions are executed to find the quotient. see the description of the div1 instruction for details. operation div0s(long m, long n) /* div0s rm,rn */ { if ((r[n] & 0x80000000)==0) q=0; else q=1; if ((r[m] & 0x80000000)==0) m=0; else m=1; t=!(m==q); pc+=2; } example see the examples for the div1 instruction. rev. 5.0, 04/01, page 218 of 394 9.18 div0u divide (step 0) as unsigned arithmetic instruction initialization for unsigned division format summary of operation instruction code execution states t bit div0u 0 m/q/t 0000000000011001 10 description this instruction performs initial settings for unsigned division. this instruction is followed by a div1 instruction that executes 1-digit division, for example, and repeated divisions are executed to find the quotient. see the description of the div1 instruction for details. operation div0u( ) /* div0u */ { m=q=t=0; pc+=2; } example see the examples for the div1 instruction. rev. 5.0, 04/01, page 219 of 394 9.19 div1 divide 1 step arithmetic instruction division format summary of operation instruction code execution states t bit div1 rm,rn 1-step division (rn rm) 0011nnnnmmmm0100 1 result of calculation description this instruction performs 1-digit division (1-step division) of the 32-bit contents of general register rn (dividend) by the contents of rm (divisor). the quotient is obtained by repeated execution of this instruction alone or in combination with other instructions. the specified registers and the m, q, and t bits must not be modified during these repeated executions. in 1-step division, the dividend is shifted 1 bit to the left, the divisor is subtracted from this, and the quotient bit is reflected in the q bit according to whether the result is positive or negative. the remainder can be found as follows after first finding the quotient using the div1 instruction: (remainder) = (dividend) ? (divisor) (quotient) detection of division by zero or overflow is not provided. check for division by zero and overflow division before executing the division. a remainder operation is not provided. find the remainder by finding the product of the divisor and the obtained quotient, and subtracting this value from the dividend. initial settings should first be made with the div0s or div0u instruction. div1 is executed once for each bit of the divisor. if a quotient of more than 17 bits is required, place an rotcl instruction before the div1 instruction. see the examples for details of the division sequence. operation div1(long m, long n) /* div1 rm,rn */ { unsigned long tmp0, tmp2; unsigned char old_q, tmp1; old_q=q; q=(unsigned char)((0x80000000 & r[n])!=0); tmp2= r[m]; r[n]<<=1; r[n]|=(unsigned long)t; rev. 5.0, 04/01, page 220 of 394 switch(old_q){ case 0:switch(m){ case 0:tmp0=r[n]; r[n]-=tmp2; tmp1=(r[n]>tmp0); switch(q){ case 0:q=tmp1; break; case 1:q=(unsigned char)(tmp1==0); break; } break; case 1:tmp0=r[n]; r[n]+=tmp2; tmp1=(r[n] rev. 5.0, 04/01, page 222 of 394 example 2 ; r1:r2 (64 bits) r0 (32 bits) = r2 (32 bits); unsigned tst r0,r0 ; check for division by zero bt zero_div ; cmp/hs r0,r1 ; check for overflow bt over_div ; div0u ; flag initialization .arepeat 32 ; rotcl r2 ; repeat 32 times div1 r0,r1 ; .aendr ; rotcl r2 ; r2 = quotient example 3 ; r1 (16 bits) r0 (16 bits) = r1 (16 bits); signed shll16 r0 ; set divisor in upper 16 bits, clear lower 16 bits to 0 exts.w r1,r1 ; dividend sign-extended to 32 bits xor r2,r2 ; r2 = 0 mov r1,r3 ; rotcl r3 ; subc r2,r1 ; if dividend is negative, subtract 1 div0s r0,r1 ; flag initialization .arepeat 16 ; div1 r0,r1 ; repeat 16 times .aendr ; exts.w r1,r1 ; rotcl r1 ; r1 = quotient (one?s complement notation) addc r2,r1 ; if msb of quotient is 1, add 1 to convert to two?s complement notation exts.w r1,r1 ; r1 = quotient (two?s complement notation) rev. 5.0, 04/01, page 223 of 394 example 4 ; r2 (32 bits) r0 (32 bits) = r2 (32 bits); signed mov r2,r3 ; rotcl r3 ; subc r1,r1 ; dividend sign-extended to 64 bits (r1:r2) xor r3,r3 ; r3 = 0 subc r3,r2 ; if dividend is negative, subtract 1 to convert to one?s complement notation div0s r0,r1 ; flag initialization .arepeat 32 ; rotcl r2 ; repeat 32 times div1 r0,r1 ; .aendr ; rotcl r2 ; r2 = quotient (one?s complement notation) addc r3,r2 ; if msb of quotient is 1, add 1 to convert to two?s complement notation ; r2 = quotient (two?s complement notation) rev. 5.0, 04/01, page 224 of 394 9.20 dmuls.l double-length multiply as signed arithmetic instruction signed double-length multiplication format summary of operation instruction code execution states t bit dmuls.l rm,rn signed, rn rm mach, macl 0011nnnnmmmm1101 2?5 ? description this instruction performs 32-bit multiplication of the contents of general register rn by the contents of rm, and stores the 64-bit result in the mach and macl registers. the multiplication is performed as a signed arithmetic operation. operation dmuls(long m, long n) /* dmuls.l rm,rn */ { unsigned long rnl,rnh,rml,rmh,res0,res1,res2; unsigned long temp0,temp1,temp2,temp3; long tempm,tempn,fnlml; tempn=(long)r[n]; tempm=(long)r[m]; if (tempn<0) tempn=0-tempn; if (tempm<0) tempm=0-tempm; if ((long)(r[n]^r[m])<0) fnlml=-1; else fnlml=0; temp1=(unsigned long)tempn; temp2=(unsigned long)tempm; rnl=temp1&0x0000ffff; rnh=(temp1>>16)&0x0000ffff; rml=temp2&0x0000ffff; rmh=(temp2>>16)&0x0000ffff; rev. 5.0, 04/01, page 225 of 394 temp0=rml*rnl; temp1=rmh*rnl; temp2=rml*rnh; temp3=rmh*rnh; res2=0; res1=temp1+temp2; if (res1 rev. 5.0, 04/01, page 226 of 394 9.21 dmulu.l double-length multiply as unsigned arithmetic instruction unsigned double-length multiplication format summary of operation instruction code execution states t bit dmulu.l rm,rn unsigned, rn rm mach, macl 0011nnnnmmmm0101 2?5 ? description this instruction performs 32-bit multiplication of the contents of general register rn by the contents of rm, and stores the 64-bit result in the mach and macl registers. the multiplication is performed as an unsigned arithmetic operation. operation dmulu(long m, long n) /* dmulu.l rm,rn */ { unsigned long rnl,rnh,rml,rmh,res0,res1,res2; unsigned long temp0,temp1,temp2,temp3; rnl=r[n]&0x0000ffff; rnh=(r[n]>>16)&0x0000ffff; rml=r[m]&0x0000ffff; rmh=(r[m]>>16)&0x0000ffff; temp0=rml*rnl; temp1=rmh*rnl; temp2=rml*rnh; temp3=rmh*rnh; res2=0 res1=temp1+temp2; if (res1 rev. 5.0, 04/01, page 228 of 394 9.22 dt decrement and test arithmetic instruction decrement and test format summary of operation instruction code execution states t bit dt rn rn ? 1 rn; if rn = 0, 1 t if rn 0, 0 t 0100nnnn00010000 1test result description this instruction decrements the contents of general register rn by 1 and compares the result with zero. if the result is zero, the t bit is set to 1. if the result is nonzero, the t bit is cleared to 0. operation dt(long n)/* dt rn */ { r[n]--; if (r[n]==0) t=1; else t=0; pc+=2; } example mov #4,r5 ; set loop count loop: add r0,r1 ; dt r5 ; decrement r5 value and check for 0. bf loop ; if t = 0, branch to loop (in this example, 4 loops are executed). rev. 5.0, 04/01, page 229 of 394 9.23 exts extend as signed arithmetic instruction sign extension format summary of operation instruction code execution states t bit exts.b rm,rn rm sign-extended from byte rn 0110nnnnmmmm1110 1? exts.w rm,rn rm sign-extended from word rn 0110nnnnmmmm1111 1? description this instruction sign-extends the contents of general register rm and stores the result in rn. for a byte specification, the value of rm bit 7 is transferred to rn bits 8 to 31. for a word specification, the value of rm bit 15 is transferred to rn bits 16 to 31. operation extsb(long m, long n) /* exts.b rm,rn */ { r[n]=r[m]; if ((r[m]&0x00000080)==0) r[n]&=0x000000ff; else r[n]|=0xffffff00; pc+=2; } extsw(long m, long n) /* exts.w rm,rn */ { r[n]=r[m]; if ((r[m]&0x00008000)==0) r[n]&=0x0000ffff; else r[n]|=0xffff0000; pc+=2; } rev. 5.0, 04/01, page 230 of 394 example exts.b r0,r1 ; before execution r0 = h'00000080 ; after execution r1 = h'ffffff80 exts.w r0,r1 ; before execution r0 = h'00008000 ; after execution r1 = h'ffff8000 rev. 5.0, 04/01, page 231 of 394 9.24 extu extend as unsigned arithmetic instruction zero extension format summary of operation instruction code execution states t bit extu.b rm,rn rm zero-extended from byte rn 0110nnnnmmmm1100 1? extu.w rm,rn rm zero-extended from word rn 0110nnnnmmmm1101 1? description this instruction zero-extends the contents of general register rm and stores the result in rn. for a byte specification, 0 is transferred to rn bits 8 to 31. for a word specification, 0 is transferred to rn bits 16 to 31. operation extub(long m, long n) /* extu.b rm,rn */ { r[n]=r[m]; r[n]&=0x000000ff; pc+=2; } extuw(long m, long n) /* extu.w rm,rn */ { r[n]=r[m]; r[n]&=0x0000ffff; pc+=2; } example extu.b r0,r1 ; before execution r0 = h'ffffff80 ; after execution r1 = h'00000080 extu.w r0,r1 ; before execution r0 = h'ffff8000 ; after execution r1 = h'00008000 rev. 5.0, 04/01, page 232 of 394 9.25 fabs floating-point absolute value floating-point instruction floating-point absolute value pr format summary of operation instruction code execution states t bit 0 fabs frn |frn| frn 1111nnnn01011101 1? 1 fabs drn |drn| drn 1111nnn001011101 1? description this instruction clears the most significant bit of the contents of floating-point register frn/drn to 0, and stores the result in frn/drn. the cause and flag fields in fpscr are not updated. operation void fabs (int n){ fr[n] = fr[n] & 0x7fffffff; pc += 2; } /* same operation is performed regardless of precision. */ possible exceptions: none rev. 5.0, 04/01, page 233 of 394 9.26 fadd floating-point add floating-point instruction floating-point addition pr format summary of operation instruction code execution states t bit 0 fadd frm,frn frn+frm frn 1111nnnnmmmm0000 1? 1 fadd drm,drn drn+drm drn 1111nnn0mmm00000 6? description when fpscr.pr = 0: arithmetically adds the two single-precision floating-point numbers in frn and frm, and stores the result in frn. when fpscr.pr = 1: arithmetically adds the two double-precision floating-point numbers in drn and drm, and stores the result in drn. when fpscr.enable.o/u/i is set, an fpu exception trap is generated regardless of whether or not an exception has occurred. when an exception occurs, correct exception information is reflected in fpscr.cause and fpscr.flag, and frn or drn is not updated. appropriate processing should therefore be performed by software. operation void fadd (int m,n) { pc += 2; clear_cause(); if((data_type_of(m) == snan) || (data_type_of(n) == snan)) invalid(n); else if((data_type_of(m) == qnan) || (data_type_of(n) == qnan)) qnan(n); else if((data_type_of(m) == denorm) || (data_type_of(n) == denorm)) set_e(); else switch (data_type_of(m)){ case norm: switch (data_type_of(n)){ case norm: normal_faddsub(m,n,add); break; case pzero: case nzero:register_copy(m,n); break; default: break; } break; rev. 5.0, 04/01, page 234 of 394 case pzero: switch (data_type_of(n)){ case nzero: zero(n,0); break; default: break; } break; case nzero: break; case pinf: switch (data_type_of(n)){ case ninf: invalid(n); break; default: inf(n,0); break; } break; case ninf: switch (data_type_of(n)){ case pinf: invalid(n); break; default: inf(n,1); break; } break; } } fadd special cases frm,drm frn,drn norm +0 ?0 +inf ?inf denorm qnan snan norm add ?inf +0 +0 ?0 ?0 +inf +inf invalid ?inf ?inf invalid ?inf denorm error qnan qnan snan invalid note: when dn = 1, the value of a denormalized number is treated as 0. possible exceptions: ? fpu error ? invalid operation ? overflow ? underflow ? inexact rev. 5.0, 04/01, page 235 of 394 9.27 fcmp floating-point compare floating-point instruction floating-point comparison no. pr format summary of operation instruction code execution states t bit 1. 0 fcmp/eq frm,frn (frn==frm)?1:0 t 1111nnnnmmmm0100 11/0 2. 1 fcmp/eq drm,drn (drn==drm)?1:0 t 1111nnn0mmm00100 11/0 3. 0 fcmp/gt frm,frn (frn>frm)?1:0 t 1111nnnnmmmm0101 21/0 4. 1 fcmp/gt drm,drn (drn>drm)?1:0 t 1111nnn0mmm00101 21/0 description 1. when fpscr.pr = 0: arithmetically compares the two single-precision floating-point numbers in frn and frm, and stores 1 in the t bit if they are equal, or 0 otherwise. 2. when fpscr.pr = 1: arithmetically compares the two double-precision floating-point numbers in drn and drm, and stores 1 in the t bit if they are equal, or 0 otherwise. 3. when fpscr.pr = 0: arithmetically compares the two single-precision floating-point numbers in frn and frm, and stores 1 in the t bit if frn > frm, or 0 otherwise. 4. when fpscr.pr = 1: arithmetically compares the two double-precision floating-point numbers in drn and drm, and stores 1 in the t bit if drn > drm, or 0 otherwise. operation void fcmp_eq(int m,n) /* fcmp/eq frm,frn */ { pc += 2; clear_cause(); if(fcmp_chk (m,n) == invalid) fcmp_invalid(); else if(fcmp_chk (m,n) == eq) t = 1; else t = 0; } void fcmp_gt(int m,n) /* fcmp/gt frm,frn */ { pc += 2; clear_cause(); if ((fcmp_chk (m,n) == invalid) || (fcmp_chk (m,n) == uo)) fcmp_invalid(); else if(fcmp_chk (m,n) == gt) t = 1; rev. 5.0, 04/01, page 236 of 394 else t = 0; } int fcmp_chk (int m,n) { if((data_type_of(m) == snan) || (data_type_of(n) == snan)) return(invalid); else if((data_type_of(m) == qnan) || (data_type_of(n) == qnan)) return(uo); else switch(data_type_of(m)){ case norm: switch(data_type_of(n)){ case pinf :return(gt); break; case ninf :return(lt); break; default: break; } break; case pzero: case nzero: switch(data_type_of(n)){ case pzero : case nzero :return(eq); break; default: break; } break; case pinf : switch(data_type_of(n)){ case pinf :return(eq); break; default:return(lt); break; } break; case ninf : switch(data_type_of(n)){ case ninf :return(eq); break; default:return(gt); break; } break; } if(fpscr_pr == 0) { if(fr[n] == fr[m]) return(eq); else if(fr[n] > fr[m]) return(gt); else return(lt); }else { if(dr[n>>1] == dr[m>>1]) return(eq); else if(dr[n>>1] > dr[m>>1]) return(gt); rev. 5.0, 04/01, page 237 of 394 else return(lt); } } void fcmp_invalid() { set_v(); if((fpscr & enable_v) == 0) t = 0; else fpu_exception_trap(); } fcmp special cases fcmp/eq frn,drn frm,drm norm dnorm +0 ?0 +inf ?inf qnan snan norm cmp dnorm +0 eq ?0 +inf eq ?inf eq qnan !eq snan invalid note: when dn = 1, the value of a denormalized number is treated as 0. fcmp/gt frn,drn frm,drm norm denorm +0 ?0 +inf ?inf qnan snan norm cmp gt !gt denorm +0 !gt ?0 +inf !gt !gt ?inf gt !gt qnan uo snan invalid note: when dn = 1, the value of a denormalized number is treated as 0. uo means unordered. unordered is treated as false (!gt). possible exceptions: invalid operation rev. 5.0, 04/01, page 238 of 394 9.28 fcnvds floating-point convert double to single precision floating-point instruction double-precision to single-precision conversion pr format summary of operation instruction code execution states t bit 0? ? ? ? ? 1 fcnvds drm,fpul (float)drm fpul 1111mmm010111101 2? description when fpscr.pr = 1: this instruction converts the double-precision floating-point number in drm to a single-precision floating-point number, and stores the result in fpul. when fpscr.enable.o/u/i is set, an fpu exception trap is generated regardless of whether or not an exception has occurred. when an exception occurs, correct exception information is reflected in fpscr.cause and fpscr.flag, and fpul is not updated. appropriate processing should therefore be performed by software. operation void fcnvds(int m, float *fpul){ case((fpscr.pr){ 0: undefined_operation(); /* reserved */ 1: fcnvds(m, *fpul); break; /* fcnvds */ } } void fcnvds(int m, float *fpul) { pc += 2; clear_cause(); case(data_type_of(m, *fpul)){ norm : pzero : nzero : normal_ fcnvds(m, *fpul); break; denorm : set_e(); pinf : *fpul = 0x7f800000; break; ninf : *fpul = 0xff800000; break; rev. 5.0, 04/01, page 239 of 394 qnan : *fpul = 0x7fbfffff; break; snan : set_v(); if((fpscr & enable_v) == 0) *fpul = 0x7fbfffff; else fpu_exception_trap(); break; } } void normal_fcnvds(int m, float *fpul) { int sign; float abs; union { float f; int l; } dstf,tmpf; union { double d; int l[2]; } dstd; dstd.d = dr[m>>1]; if(dstd.l[1] & 0x1fffffff)) set_i(); if(fpscr_rm == 1) dstd.l[1] &= 0xe0000000; /* round toward zero*/ dstf.f = dstd.d; check_single_exception(fpul, dstf.f); } fcnvds special cases frn +norm ?norm +0 ?0 +inf ?inf qnan snan fcnvds(frn fpul) fcnvds fcnvds +0 ?0 +inf ?inf qnan invalid note: when dn = 1, the value of a denormalized number is treated as 0. possible exceptions: ? fpu error ? invalid operation ? overflow ? underflow ? inexact rev. 5.0, 04/01, page 240 of 394 9.29 fcnvsd floating-point convert single to double precision floating-point instruction single-precision to double-precision conversion pr format summary of operation instruction code execution states t bit 0? ? ? ? ? 1 fcnvsd fpul, drn (double) fpul drn 1111nnn010101101 2? description when fpscr.pr = 1: this instruction converts the single-precision floating-point number in fpul to a double-precision floating-point number, and stores the result in drn. operation void fcnvsd(int n, float *fpul){ pc += 2; clear_cause(); case((fpscr_pr){ 0: undefined_operation(); /* reserved */ 1: fcnvsd (n, *fpul); break; /* fcnvsd */ } } void fcnvsd(int n, float *fpul) { case(fpul_type(fpul)){ pzero : nzero : pinf : ninf : dr[n>>1] = *fpul; break; denorm : set_e(); break; qnan : qnan(n); break; snan : invalid(n); break; } } int fpul_type(int *fpul) rev. 5.0, 04/01, page 241 of 394 { int abs; abs = *fpul & 0x7fffffff; if(abs < 0x00800000){ if((fpscr_dn == 1) || (abs == 0x00000000)){ if(sign_of(src) == 0) return(pzero); else return(nzero); } else return(denorm); } else if(abs < 0x7f800000) return(norm); else if(abs == 0x7f800000) { if(sign_of(src) == 0) return(pinf); else return(ninf); } else if(abs < 0x7fc00000) return(qnan); else return(snan); } fcnvsd special cases frn +norm ?norm +0 ?0 +inf ?inf qnan snan fcnvsd(fpul frn) +norm ?norm +0 ?0 +inf ?inf qnan invalid note: when dn = 1, the value of a denormalized number is treated as 0. possible exceptions: ? fpu error ? invalid operation rev. 5.0, 04/01, page 242 of 394 9.30 fdiv floating-point divide floating-point instruction floating-point division pr format summary of operation instruction code execution states t bit 0 fdiv frm,frn frn/frm frn 1111nnnnmmmm0011 10 ? 1 fdiv drm,drn drn/drm drn 1111nnn0mmm00011 23 ? description when fpscr.pr = 0: arithmetically divides the single-precision floating-point number in frn by the single-precision floating-point number in frm, and stores the result in frn. when fpscr.pr = 1: arithmetically divides the double-precision floating-point number in drn by the double-precision floating-point number in drm, and stores the result in drn. when fpscr.enable.o/u/i is set, an fpu exception trap is generated regardless of whether or not an exception has occurred. when an exception occurs, correct exception information is reflected in fpscr.cause and fpscr.flag, and frn or drn is not updated. appropriate processing should therefore be performed by software. operation void fdiv(int m,n) /* fdiv frm,frn */ { pc += 2; clear_cause(); if((data_type_of(m) == snan) || (data_type_of(n) == snan)) invalid(n); else if((data_type_of(m) == qnan) || (data_type_of(n) == qnan)) qnan(n); else switch (data_type_of(m)){ case norm: switch (data_type_of(n)){ case pinf: case ninf: inf(n,sign_of(m)^sign_of(n));break; case pzero: case nzero: zero(n,sign_of(m)^sign_of(n));break; case denorm:set_e(); break; default: normal_fdiv(m,n); break; } break; rev. 5.0, 04/01, page 243 of 394 case pzero: switch (data_type_of(n)){ case pzero: case nzero: invalid(n);break; case pinf: case ninf: break; default: dz(n,sign_of(m)^sign_of(n));break; } break; case nzero: switch (data_type_of(n)){ case pzero: case nzero: invalid(n); break; case pinf: inf(n,1); break; case ninf: inf(n,0); break; default: dz(fr[n],sign_of(m)^sign_of(n)); break; } break; case denorm: set_e(); break; case pinf : case ninf : switch (data_type_of(n)){ case denorm: set_e(); break; case pinf: case ninf: invalid(n); break; default: zero(n,sign_of(m)^sign_of(n));break } break; } } void normal_fdiv(int m,n) { union { float f; int l; } dstf,tmpf; union { double d; int l[2]; } dstd,tmpd; union { int double x; int l[4]; rev. 5.0, 04/01, page 244 of 394 } tmpx; if(fpscr_pr == 0) { tmpf.f = fr[n]; /* save destination value */ dstf.f /= fr[m]; /* round toward nearest or even */ tmpd.d = dstf.f; /* convert single to double */ tmpd.d *= fr[m]; if(tmpf.f != tmpd.d) set_i(); if((tmpf.f < tmpd.d) && (spscr_rm == 1)) dstf.l -= 1; /* round toward zero */ check_single_exception(&fr[n], dstf.f); } else { tmpd.d = dr[n>>1]; /* save destination value */ dstd.d /= dr[m>>1]; /* round toward nearest or even */ tmpx.x = dstd.d; /* convert double to int double */ tmpx.x *= dr[m>>1]; if(tmpd.d != tmpx.x) set_i(); if((tmpd.d < tmpx.x) && (spscr_rm == 1)) { dstd.l[1] -= 1; /* round toward zero */ if(dstd.l[1] == 0xffffffff) dstd.l[0] -= 1; } check_double_exception(&dr[n>>1], dstd.d); } } fdiv special cases frm,drm frn,drn norm +0 ?0 +inf ?inf denorm qnan snan norm div 0 inf error +0 dz invalid +inf ?inf dz ?0 ?inf +inf +inf 0 +0 ?0 invalid ?inf ?0 +0 denorm error qnan qnan snan invalid note: when dn = 1, the value of a denormalized number is treated as 0. rev. 5.0, 04/01, page 245 of 394 possible exceptions: ? fpu error ? invalid operation ? divide by zero ? overflow ? underflow ? inexact rev. 5.0, 04/01, page 246 of 394 9.31 fipr floating-point inner product floating-point instruction floating-point inner product pr format summary of operation instruction code execution states t bit 0 fipr fvm,fvn fvn ? fvm fr[n+3] 1111nnmm11101101 1? ?? ? ? ? ? notes: fv0 = {fr0, fr1, fr2, fr3} fv4 = {fr4, fr5, fr6, fr7} fv8 = {fr8, fr9, fr10, fr11} fv12 = {fr12, fr13, fr14, fr15} description when fpscr.pr = 0: this instruction calculates the inner products of the 4-dimensional single- precision floating-point vector indicated by fvn and fvm, and stores the results in fr[n + 3]. the fipr instruction is intended for speed rather than accuracy, and therefore the results will differ from those obtained by using a combination of fadd and fmul instructions. the fipr execution sequence is as follows: 1. multiplies all terms. the results are 28 bits long. 2. aligns these results, rounding them to fit within 30 bits. 3. adds the aligned values. 4. performs normalization and rounding. special processing is performed in the following cases: 1. if an input value is an snan, an invalid exception is generated. 2. if the input values to be multiplied include a combination of 0 and infinity, an invalid exception is generated. 3. in cases other than the above, if the input values include a qnan, the result will be a qnan. 4. in cases other than the above, if the input values include infinity: a. if multiplication results in two or more infinities and the signs are different, an invalid exception will be generated. b. otherwise, correct infinities will be stored. 5. if the input values do not include an snan, qnan, or infinity, processing is performed in the normal way. rev. 5.0, 04/01, page 247 of 394 when fpscr.enable.o/u/i is set, an fpu exception trap is generated regardless of whether or not an exception has occurred. when an exception occurs, correct exception information is reflected in fpscr.cause and fpscr.flag, and frn or drn is not updated. appropriate processing should therefore be performed by software. operation void fipr(int m,n) /* fipr fvm,fvn */ { if(fpscr_pr == 0) { pc += 2; clear_cause(); fipr(m,n); } else undefined_operation(); } possible exceptions: ? invalid operation ? overflow ? underflow ? inexact rev. 5.0, 04/01, page 248 of 394 9.32 fldi0 floating-point load immediate 0.0 floating-point instruction 0.0 load pr format summary of operation instruction code execution states t bit 0 fldi0 frn 0x00000000 frn 1111nnnn10001101 1? 1? ? ? ? ? description when fpscr.pr = 0, this instruction loads floating-point 0.0 (0x00000000) into frn. operation void fldi0(int n) { fr[n] = 0x00000000; pc += 2; } possible exceptions: none rev. 5.0, 04/01, page 249 of 394 9.33 fldi1 floating-point load immediate 1.0 floating-point instruction 1.0 load format summary of operation instruction code execution states t bit fldi1 frn 0x3f800000 frn 1111nnnn10011101 1? ?? ??? description when fpscr.pr = 0, this instruction loads floating-point 1.0 (0x3f800000) into frn. operation void fldi1(int n) { fr[n] = 0x3f800000; pc += 2; } possible exceptions: none rev. 5.0, 04/01, page 250 of 394 9.34 flds floating-point load to system register floating-point instruction transfer to system register format summary of operation instruction code execution states t bit flds frm,fpul frm fpul 1111mmmm00011101 1? description this instruction loads the contents of floating-point register frm into system register fpul. operation void flds(int m, float *fpul) { *fpul = fr[m]; pc += 2; } possible exceptions: none rev. 5.0, 04/01, page 251 of 394 9.35 float floating-point convert from integer floating-point instruction integer to floating-point conversion pr format summary of operation instruction code execution states t bit 0 float fpul,frn (float)fpul frn 1111nnnn00101101 1? 1 float fpul,drn (double)fpul drn 1111nnn000101101 2? description when fpscr.pr = 0: taking the contents of fpul as a 32-bit integer, converts this integer to a single-precision floating-point number and stores the result in frn. when fpscr.pr = 1: taking the contents of fpul as a 32-bit integer, converts this integer to a double-precision floating-point number and stores the result in drn. when fpscr.enable.i = 1, an fpu exception trap is generated regardless of whether or not an exception has occurred. when an exception occurs, correct exception information is reflected in fpscr.cause and fpscr.flag, and frn or drn is not updated. appropriate processing should therefore be performed by software. rev. 5.0, 04/01, page 252 of 394 operation void float(int n, float *fpul) { union { double d; int l[2]; } tmp; pc += 2; clear_cause(); if(fpscr.pr==0){ fr[n] = *fpul; /* convert from integer to float */ tmp.d = *fpul; if(tmp.l[1] & 0x1fffffff) inexact(); } else { dr[n>>1] = *fpul; /* convert from integer to double */ } } possible exceptions: inexact: not generated when fpscr.pr = 1. rev. 5.0, 04/01, page 253 of 394 9.36 fmac floating-point multiply and accumulate floating-point instruction floating-point multiply and accumulate pr format summary of operation instruction code execution states t bit 0 fmac fr0,frm,frn fr0*frm+frn frn 1111nnnnmmmm1110 1? 1? ? ? ? ? description when fpscr.pr = 0: this instruction arithmetically multiplies the two single-precision floating- point numbers in fr0 and frm, arithmetically adds the contents of frn, and stores the result in frn. when fpscr.enable.o/u/i is set, an fpu exception trap is generated regardless of whether or not an exception has occurred. when an exception occurs, correct exception information is reflected in fpscr.cause and fpscr.flag, and frn or drn is not updated. appropriate processing should therefore be performed by software. operation void fmac(int m,n) { pc += 2; clear_cause(); if(fpscr_pr == 1) undefined_operation(); else if((data_type_of(0) == snan) || (data_type_of(m) == snan) || (data_type_of(n) == snan)) invalid(n); else if((data_type_of(0) == qnan) || (data_type_of(m) == qnan)) qnan(n); else if((data_type_of(0) == denorm) || (data_type_of(m) == denorm)) set_e(); else switch (data_type_of(0){ case norm: switch (data_type_of(m)){ case pzero: case nzero: switch (data_type_of(n)){ case denorm: set_e(); break; rev. 5.0, 04/01, page 254 of 394 case qnan: qnan(n); break; case pzero: case nzero: zero(n,sign_of(0)^ sign_of(m)^sign_of(n)); break; default: break; } case pinf: case ninf: switch (data_type_of(n)){ case denorm: set_e(); break; case qnan: qnan(n); break; case pinf: case ninf: if(sign_of(0)^ sign_of(m)^sign_of(n)) invalid(n); else inf(n,sign_of(0)^ sign_of(m)); break; default: inf(n,sign_of(0)^ sign_of(m)); break; } case norm: switch (data_type_of(n)){ case denorm: set_e(); break; case qnan: qnan(n); break; case pinf: case ninf: inf(n,sign_of(n)); break; case pzero: case nzero: case norm: normal_fmac(m,n); break; } break; case pzero: case nzero: switch (data_type_of(m)){ case pinf: case ninf: invalid(n); break; case pzero: case nzero: case norm: switch (data_type_of(n)){ case denorm: set_e(); break; case qnan: qnan(n); break; case pzero: case nzero: zero(n,sign_of(0)^ sign_of(m)^sign_of(n)); break; default: break; } break; } break; rev. 5.0, 04/01, page 255 of 394 case pinf : case ninf : switch (data_type_of(m)){ case pzero: case nzero:invalid(n); break; default: switch (data_type_of(n)){ case denorm: set_e(); break; case qnan: qnan(n); break; default: inf(n,sign_of(0)^sign_of(m)^sign_of(n));break } break; } break; } } void normal_fmac(int m,n) { union { int double x; int l[4]; } dstx,tmpx; float dstf,srcf; if((data_type_of(n) == pzero)|| (data_type_of(n) == nzero)) srcf = 0.0; /* flush denormalized value */ else srcf = fr[n]; tmpx.x = fr[0]; /* convert single to int double */ tmpx.x *= fr[m]; /* exact product */ dstx.x = tmpx.x + srcf; if(((dstx.x == srcf) && (tmpx.x != 0.0)) || ((dstx.x == tmpx.x) && (srcf != 0.0))) { set_i(); if(sign_of(0)^ sign_of(m)^ sign_of(n)) { dstx.l[3] -= 1; /* correct result */ if(dstx.l[3] == 0xffffffff) dstx.l[2] -= 1; if(dstx.l[2] == 0xffffffff) dstx.l[1] -= 1; if(dstx.l[1] == 0xffffffff) dstx.l[0] -= 1; } else dstx.l[3] |= 1; } if((dstx.l[1] & 0x01ffffff) || dstx.l[2] || dstx.l[3]) set_i(); rev. 5.0, 04/01, page 256 of 394 if(fpscr_rm == 1) { dstx.l[1] &= 0xfe000000; /* round toward zero */ dstx.l[2] = 0x00000000; dstx.l[3] = 0x00000000; } dstf = dstx.x; check_single_exception(&fr[n],dstf); } rev. 5.0, 04/01, page 257 of 394 fmac special cases frn fr0 frm +norm ?norm +0 ?0 +inf ?inf denorm qnan snan norm norm mac inf 0 invalid inf inf invalid inf +0 norm mac 0 +0 invalid inf inf invalid inf ?0 +norm mac +0 ?0 +inf ?inf ?norm ?0 +0 ?inf +inf +0 +0 ?0 +0 ?0 invalid ?0 ?0 +0 ?0 +0 inf inf invalid inf +inf +norm +inf invalid ?norm +inf 0 invalid +inf invalid +inf ?inf invalid +inf +inf ?inf +norm ?inf ?inf ?norm 0 +inf invalid invalid ?inf ?inf ?inf ?inf invalid denorm norm 0 invalid inf invalid !snan denorm error qnan 0 invalid inf invalid norm !snan qnan qnan all types snan snan all types invalid note: when dn = 1, the value of a denormalized number is treated as 0. rev. 5.0, 04/01, page 258 of 394 possible exceptions: ? fpu error ? invalid operation ? overflow ? underflow ? inexact rev. 5.0, 04/01, page 259 of 394 9.37 fmov floating-point move floating-point instruction floating-point transfer no. sz format summary of operation instruction code execution states t bit 1. 0 fmov frm,frn frm frn 1111nnnnmmmm1100 1? 2. 1 fmov drm,drn drm drn 1111nnn0mmm01100 1? 3. 0 fmov.s frm,@rn frm (rn) 1111nnnnmmmm1010 1? 4. 1 fmov drm,@rn drm (rn) 1111nnnnmmm01010 1? 5. 0 fmov.s @rm,frn (rm) frn 1111nnnnmmmm1000 1? 6. 1 fmov @rm,drn (rm) drn 1111nnn0mmmm1000 1? 7. 0 fmov.s @rm+,frn (rm) frn,rm+=4 1111nnnnmmmm1001 1? 8. 1 fmov @rm+,drn (rm) drn,rm+=8 1111nnn0mmmm1001 1? 9. 0 fmov.s frm,@-rn rn-=4,frm (rn) 1111nnnnmmmm1011 1? 10. 1 fmov drm,@-rn rn-=8,drm (rn) 1111nnnnmmm01011 1? 11. 0 fmov.s @(r0,rm),frn (r0+rm) frn 1111nnnnmmmm0110 1? 12. 1 fmov @(r0,rm),drn (r0+rm) drn 1111nnn0mmmm0110 1? 13. 0 fmov.s frm, @(r0,rn) frm (r0+rn) 1111nnnnmmmm0111 1? 14. 1 fmov drm, @(r0,rn) drm (r0+rn) 1111nnnnmmm00111 1? description 1. this instruction transfers frm contents to frn. 2. this instruction transfers drm contents to drn. 3. this instruction transfers frm contents to memory at address indicated by rn. 4. this instruction transfers drm contents to memory at address indicated by rn. 5. this instruction transfers contents of memory at address indicated by rm to frn. 6. this instruction transfers contents of memory at address indicated by rm to drn. 7. this instruction transfers contents of memory at address indicated by rm to frn, and adds 4 to rm. 8. this instruction transfers contents of memory at address indicated by rm to drn, and adds 8 to rm. 9. this instruction subtracts 4 from rn, and transfers frm contents to memory at address indicated by resulting rn value. 10. this instruction subtracts 8 from rn, and transfers drm contents to memory at address indicated by resulting rn value. 11. this instruction transfers contents of memory at address indicated by (r0 + rm) to frn. rev. 5.0, 04/01, page 260 of 394 12. this instruction transfers contents of memory at address indicated by (r0 + rm) to drn. 13. this instruction transfers frm contents to memory at address indicated by (r0 + rn). 14. this instruction transfers drm contents to memory at address indicated by (r0 + rn). operation void fmov(int m,n) /* fmov frm,frn */ { fr[n] = fr[m]; pc += 2; } void fmov_dr(int m,n) /* fmov drm,drn */ { dr[n>>1] = dr[m>>1]; pc += 2; } void fmov_store(int m,n) /* fmov.s frm,@rn */ { store_int(fr[m],r[n]); pc += 2; } void fmov_store_dr(int m,n) /* fmov drm,@rn */ { store_quad(dr[m>>1],r[n]); pc += 2; } void fmov_load(int m,n) /* fmov.s @rm,frn */ { load_int(r[m],fr[n]); pc += 2; } void fmov_load_dr(int m,n) /* fmov @rm,drn */ { load_quad(r[m],dr[n>>1]); pc += 2; } void fmov_restore(int m,n) /* fmov.s @rm+,frn */ { rev. 5.0, 04/01, page 261 of 394 load_int(r[m],fr[n]); r[m] += 4; pc += 2; } void fmov_restore_dr(int m,n) /* fmov @rm+,drn */ { load_quad(r[m],dr[n>>1]) ; r[m] += 8; pc += 2; } void fmov_save(int m,n) /* fmov.s frm,@?rn */ { store_int(fr[m],r[n]-4); r[n] -= 4; pc += 2; } void fmov_save_dr(int m,n) /* fmov drm,@?rn */ { store_quad(dr[m>>1],r[n]-8); r[n] -= 8; pc += 2; } void fmov_index_load(int m,n) /* fmov.s @(r0,rm),frn */ { load_int(r[0] + r[m],fr[n]); pc += 2; } void fmov_index_load_dr(int m,n) /*fmov @(r0,rm),drn */ { load_quad(r[0] + r[m],dr[n>>1]); pc += 2; } void fmov_index_store(int m,n) /*fmov.s frm,@(r0,rn)*/ { store_int(fr[m], r[0] + r[n]); pc += 2; } rev. 5.0, 04/01, page 262 of 394 void fmov_index_store_dr(int m,n)/*fmov drm,@(r0,rn)*/ { store_quad(dr[m>>1], r[0] + r[n]); pc += 2; } possible exceptions: ? data tlb miss exception ? data protection violation exception ? initial write exception ? address error rev. 5.0, 04/01, page 263 of 394 9.38 fmov floating-point move extension floating-point instruction floating-point transfer no. pr format summary of operation instruction code execution states t bit 1. 1 fmov xdm,@rn xrm (rn) 1111nnnnmmm11010 1? 2. 1 fmov @rm,xdn (rm) xdn 1111nnn1mmmm1000 1? 3. 1 fmov @rm+,xdn (rm) xdn,rm+=8 1111nnn1mmmm1001 1? 4. 1 fmov xdm,@-rn rn-=8,xdm (rn) 1111nnnnmmm11011 1? 5. 1 fmov @(r0,rm),xdn (r0+rm) xdn 1111nnn1mmmm0110 1? 6. 1 fmov xdm,@(r0,rn) xdm (r0+rn) 1111nnnnmmm10111 1? 7. 1 fmov xdm,xdn xdm xdn 1111nnn1mmm11100 1? 8. 1 fmov xdm,drn xdm drn 1111nnn0mmm11100 1? 9. 1 fmov drm,xdn drm xdn 1111nnn1mmm01100 1? description 1. this instruction transfers xdm contents to memory at address indicated by rn. 2. this instruction transfers contents of memory at address indicated by rm to xdn. 3. this instruction transfers contents of memory at address indicated by rm to xdn, and adds 8 to rm. 4. this instruction subtracts 8 from rn, and transfers xdm contents to memory at address indicated by resulting rn value. 5. this instruction transfers contents of memory at address indicated by (r0 + rm) to xdn. 6. this instruction transfers xdm contents to memory at address indicated by (r0 + rn). 7. this instruction transfers xdm contents to xdn. 8. this instruction transfers xdm contents to drn. 9. this instruction transfers drm contents to xdn. rev. 5.0, 04/01, page 264 of 394 operation void fmov_store_xd(int m,n) /* fmov xdm,@rn */ { store_quad(xd[m>>1],r[n]); pc += 2; } void fmov_load_xd(int m,n) /* fmov @rm,xdn */ { load_quad(r[m],xd[n>>1]); pc += 2; } void fmov_restore_xd(int m,n) /* fmov @rm+,dbn */ { load_quad(r[m],xd[n>>1]); r[m] += 8; pc += 2; } void fmov_save_xd(int m,n) /* fmov xdm,@?rn */ { store_quad(xd[m>>1],r[n]-8); r[n] -= 8; pc += 2; } void fmov_index_load_xd(int m,n) /* fmov @(r0,rm),xdn */ { load_quad(r[0] + r[m],xd[n>>1]); pc += 2; } void fmov_index_store_xd(int m,n) /* fmov xdm,@(r0,rn) */ { store_quad(xd[m>>1], r[0] + r[n]); pc += 2; } void fmov_xdxd(int m,n) /* fmov xdm,xdn */ { xd[n>>1] = xd[m>>1]; pc += 2; rev. 5.0, 04/01, page 265 of 394 } void fmov_xddr(int m,n) /* fmov xdm,drn */ { dr[n>>1] = xd[m>>1]; pc += 2; } void fmov_drxd(int m,n) /* fmov drm,xdn */ { xd[n>>1] = dr[m>>1]; pc += 2; } possible exceptions: ? data tlb miss exception ? data protection violation exception ? initial write exception ? address error rev. 5.0, 04/01, page 266 of 394 9.39 fmul floating-point multiply floating-point instruction floating-point multiplication pr format summary of operation instruction code execution states t bit 0 fmul frm,frn frn*frm frn 1111nnnnmmmm0010 1? 1 fmul drm,drn drn*drm drn 1111nnn0mmm00010 6? description when fpscr.pr = 0: arithmetically multiplies the two single-precision floating-point numbers in frn and frm, and stores the result in frn. when fpscr.pr = 1: arithmetically multiplies the two double-precision floating-point numbers in drn and drm, and stores the result in drn. when fpscr.enable.o/u/i is set, an fpu exception trap is generated regardless of whether or not an exception has occurred. when an exception occurs, correct exception information is reflected in fpscr.cause and fpscr.flag, and frn or drn is not updated. appropriate processing should therefore be performed by software. operation void fmul(int m,n) { pc += 2; clear_cause(); if((data_type_of(m) == snan) || (data_type_of(n) == snan)) invalid(n); else if((data_type_of(m) == qnan) || (data_type_of(n) == qnan)) qnan(n); else if((data_type_of(m) == denorm) || (data_type_of(n) == denorm)) set_e(); else switch (data_type_of(m){ case norm: switch (data_type_of(n)){ case pzero: case nzero: zero(n,sign_of(m)^sign_of(n)); break; case pinf: case ninf: inf(n,sign_of(m)^sign_of(n)); break; default: normal_fmul(m,n); break; rev. 5.0, 04/01, page 267 of 394 } break; case pzero: case nzero: switch (data_type_of(n)){ case pinf: case ninf: invalid(n); break; default: zero(n,sign_of(m)^sign_of(n));break; } break; case pinf : case ninf : switch (data_type_of(n)){ case pzero: case nzero: invalid(n); break; default: inf(n,sign_of(m)^sign_of(n));break } break; } } fmul special cases frm,drm frn,drn norm +0 ?0 +inf ?inf denorm qnan snan norm mul 0 inf +0 0 +0 ?0 invalid ?0 ?0 +0 +inf inf invalid +inf ?inf ?inf ?inf +inf denorm error qnan qnan snan invalid note: when dn = 1, the value of a denormalized number is treated as 0. possible exceptions: ? fpu error ? invalid operation ? overflow ? underflow ? inexact rev. 5.0, 04/01, page 268 of 394 9.40 fneg floating-point negate value floating-point instruction floating-point sign inversion pr format summary of operation instruction code execution states t bit 0 fneg frn -frn frn 1111nnnn01001101 1? 1 fneg drn -drn drn 1111nnn001001101 1? description this instruction inverts the most significant bit (sign bit) of the contents of floating-point register frn/drn, and stores the result in frn/drn. the cause and flag fields in fpscr are not updated. operation void fneg (int n){ fr[n] = -fr[n]; pc += 2; } /* same operation is performed regardless of precision. */ possible exceptions: none rev. 5.0, 04/01, page 269 of 394 9.41 frchg fr-bit change floating-point instruction fr bit inversion pr format summary of operation instruction code execution states t bit 0 frchg fpscr.fr=~fpscr.fr 1111101111111101 1? 1? ? ? ? ? description this instruction inverts the fr bit in floating-point register fpscr. when the fr bit in fpscr is changed, fr0 to fr15 in fpr0_bank0 to fpr15_bank0 and fpr0_bank1 to fpr15_bank1 become xr0 to xr15, and xr0 to xr15 become fr0 to fr15. when fpscr.fr = 0, fpr0_bank0 to fpr15_bank0 correspond to fr0 to fr15, and fpr0_bank1 to fpr15_bank1 correspond to xr0 to xr15. when fpscr.fr = 1, fpr0_bank1 to fpr15_bank1 correspond to fr0 to fr15, and fpr0_bank0 to fpr15_bank0 correspond to xr0 to xr15. operation void frchg() /* frchg */ { if(fpscr_pr == 0){ fpscr ^= 0x00200000; /* bit 21 */ pc += 2; } else undefined_operation(); } possible exceptions: none rev. 5.0, 04/01, page 270 of 394 9.42 fschg sz-bit change floating-point instruction sz bit inversion pr format summary of operation instruction code execution states t bit 0 fschg fpscr.sz=~fpscr.sz 1111001111111101 1? 1? ? ? ? ? description this instruction inverts the sz bit in floating-point register fpscr. changing the sz bit in fpscr switches fmov instruction data transfer between one single-precision data unit and a data pair. when fpscr.sz = 0, the fmov instruction transfers one single-precision data unit. when fpscr.sz = 1, the fmov instruction transfers two single-precision data units as a pair. operation void fschg() /* fschg */ { if(fpscr_pr == 0){ fpscr ^= 0x00100000; /* bit 20 */ pc += 2; } else undefined_operation(); } possible exceptions: none rev. 5.0, 04/01, page 271 of 394 9.43 fsqrt floating-point square root floating-point instruction floating-point square root pr format summary of operation instruction code execution states t bit 0fsqrtfrn frn frn 1111nnnn01101101 9? 1 fsqrt drn drn drn 1111nnnn01101101 22 ? description when fpscr.pr = 0: finds the arithmetical square root of the single-precision floating-point number in frn, and stores the result in frn. when fpscr.pr = 1: finds the arithmetical square root of the double-precision floating-point number in drn, and stores the result in drn. when fpscr.enable.i is set, an fpu exception trap is generated regardless of whether or not an exception has occurred. when an exception occurs, correct exception information is reflected in fpscr.cause and fpscr.flag, and frn or drn is not updated. appropriate processing should therefore be performed by software. operation void fsqrt(int n){ pc += 2; clear_cause(); switch(data_type_of(n)){ case norm : if(sign_of(n) == 0) normal_ fsqrt(n); else invalid(n); break; case denorm: if(sign_of(n) == 0) set_e(); else invalid(n); break; case pzero : case nzero : case pinf : break; case ninf : invalid(n); break; case qnan : qnan(n); break; case snan : invalid(n); break; } } void normal_fsqrt(int n) rev. 5.0, 04/01, page 272 of 394 { union { float f; int l; } dstf,tmpf; union { double d; int l[2]; } dstd,tmpd; union { int double x; int l[4]; } tmpx; if(fpscr_pr == 0) { tmpf.f = fr[n]; /* save destination value */ dstf.f = sqrt(fr[n]); /* round toward nearest or even */ tmpd.d = dstf.f; /* convert single to double */ tmpd.d *= dstf.f; if(tmpf.f != tmpd.d) set_i(); if((tmpf.f < tmpd.d) && (spscr_rm == 1)) dstf.l -= 1; /* round toward zero */ if(fpscr & enable_i) fpu_exception_trap(); else fr[n] = dstf.f; } else { tmpd.d = dr[n>>1]; /* save destination value */ dstd.d = sqrt(dr[n>>1]); /* round toward nearest or even */ tmpx.x = dstd.d; /* convert double to int double */ tmpx.x *= dstd.d; if(tmpd.d != tmpx.x) set_i(); if((tmpd.d < tmpx.x) && (spscr_rm == 1)) { dstd.l[1] -= 1; /* round toward zero */ if(dstd.l[1] == 0xffffffff) dstd.l[0] -= 1; } if(fpscr & enable_i) fpu_exception_trap(); else dr[n>>1] = dstd.d; } } rev. 5.0, 04/01, page 273 of 394 fsqrt special cases frn +norm ?norm +0 ?0 +inf ?inf qnan snan fsqrt(frn) sqrt invalid +0 ?0 +inf invalid qnan invalid note: when dn = 1, the value of a denormalized number is treated as 0. possible exceptions: ? fpu error ? invalid operation ? inexact rev. 5.0, 04/01, page 274 of 394 9.44 fsts floating-point store system register floating-point instruction transfer from system register format summary of operation instruction code execution states t bit fsts fpul,frn fpul frn 1111nnnn00001101 1? description this instruction transfers the contents of system register fpul to floating-point register frn. operation void fsts(int n, float *fpul) { fr[n] = *fpul; pc += 2; } possible exceptions: none rev. 5.0, 04/01, page 275 of 394 9.45 fsub floating-point subtract floating-point instruction floating-point subtraction pr format summary of operation instruction code execution states t bit 0 fsub frm,frn frn-frm frn 1111nnnnmmmm0001 1? 1 fsub drm,drn drn-drm drn 1111nnn0mmm00001 6 description when fpscr.pr = 0: arithmetically subtracts the single-precision floating-point number in frm from the single-precision floating-point number in frn, and stores the result in frn. when fpscr.pr = 1: arithmetically subtracts the double-precision floating-point number in drm from the double-precision floating-point number in drn, and stores the result in drn. when fpscr.enable.o/u/i is set, an fpu exception trap is generated regardless of whether or not an exception has occurred. when an exception occurs, correct exception information is reflected in fpscr.cause and fpscr.flag, and frn or drn is not updated. appropriate processing should therefore be performed by software. operation void fsub (int m,n) { pc += 2; clear_cause(); if((data_type_of(m) == snan) || (data_type_of(n) == snan)) invalid(n); else if((data_type_of(m) == qnan) || (data_type_of(n) == qnan)) qnan(n); else if((data_type_of(m) == denorm) || (data_type_of(n) == denorm)) set_e(); else switch (data_type_of(m)){ case norm: switch (data_type_of(n)){ case norm: normal_faddsub(m,n,sub); break; case pzero: case nzero: register_copy(m,n); fr[n] = -fr[n];break; default: break; rev. 5.0, 04/01, page 276 of 394 } break; case pzero: break; case nzero: switch (data_type_of(n)){ case nzero: zero(n,0); break; default: break; } break; case pinf: switch (data_type_of(n)){ case pinf: invalid(n); break; default: inf(n,1); break; } break; case ninf: switch (data_type_of(n)){ case ninf: invalid(n); break; default: inf(n,0); break; } break; } } fsub special cases frm,drm frn,drn norm +0 ?0 +inf ?inf denorm qnan snan norm sub +inf ?inf +0 ?0 ?0 +0 +inf ?inf invalid ?inf +inf invalid denorm error qnan qnan snan invalid note: when dn = 1, the value of a denormalized number is treated as 0. possible exceptions: ? fpu error ? invalid operation ? overflow ? underflow ? inexact rev. 5.0, 04/01, page 277 of 394 9.46 ftrc floating-point truncate and convert to integer floating-point instruction conversion to integer pr format summary of operation instruction code execution states t bit 0 ftrc frm,fpul (long)frm fpul 1111mmmm00111101 1? 1 ftrc drm,fpul (long)drm fpul 1111mmm000111101 2? description when fpscr.pr = 0: converts the single-precision floating-point number in frm to a 32-bit integer, and stores the result in fpul. when fpscr.pr = 1: converts the double-precision floating-point number in frm to a 32-bit integer, and stores the result in fpul. the rounding mode is always truncation. operation #define n_int_single_range 0xcf000000 & 0x7fffffff /* -1.000000 * 2^31 */ #define p_int_single_range 0x4effffff /* 1.fffffe * 2^30 */ #define n_int_double_range 0xc1e0000000200000 & 0x7fffffffffffffff #define p_int_double_range 0x41e0000000000000 void ftrc(int m, int *fpul) { pc += 2; clear_cause(); if(fpscr.pr==0){ case(ftrc_single_ type_of(m)){ norm: *fpul = fr[m]; break; pinf: ftrc_invalid(0); break; ninf: ftrc_invalid(1); break; } } else{ /* case fpscr.pr=1 */ case(ftrc_double_type_of(m)){ rev. 5.0, 04/01, page 278 of 394 norm: *fpul = dr[m>>1]; break; pinf: ftrc_invalid(0); break; ninf: ftrc_invalid(1); break; } } } int ftrc_signle_type_of(int m) { if(sign_of(m) == 0){ if(fr_hex[m] > 0x7f800000) return(ninf); /* nan */ else if(fr_hex[m] > p_int_single_range) return(pinf); /* out of range,+inf */ else return(norm); /* +0,+norm */ } else { if((fr_hex[m] & 0x7fffffff) > n_int_single_range) return(ninf); /* out of range ,+inf,nan*/ else return(norm); /* -0,-norm */ } } int ftrc_double_type_of(int m) { if(sign_of(m) == 0){ if((fr_hex[m] > 0x7ff00000) || ((fr_hex[m] == 0x7ff00000) && (fr_hex[m+1] != 0x00000000))) return(ninf); /* nan */ else if(dr_hex[m>>1] >= p_int_double_range) return(pinf); /* out of range,+inf */ else return(norm); /* +0,+norm */ } else { if((dr_hex[m>>1] & 0x7fffffffffffffff) >= n_int_double_range) return(ninf); /* out of range ,+inf,nan*/ else return(norm); /* -0,-norm */ } } void ftrc_invalid(int sign, int *fpul) { set_v(); rev. 5.0, 04/01, page 279 of 394 if((fpscr & enable_v) == 0){ if(sign == 0) *fpul = 0x7fffffff; else *fpul = 0x80000000; } else fpu_exception_trap(); } ftrc special cases frn,drn norm +0 ?0 positive out of range negative out of range +inf ?inf qnan snan ftrc (frn,drn) trc 0 0 invalid +max invalid ?max invalid +max invalid ?max invalid ?max invalid ?max note: when dn = 1, the value of a denormalized number is treated as 0. possible exceptions: ? invalid operation rev. 5.0, 04/01, page 280 of 394 9.47 ftrv floating-point transform vector floating-point instruction vector transformation pr format summary of operation instruction code execution states t bit 0 ftrv xmtrx,fvn xmtrx*fvn fvn 1111nn0111111101 4? 1? ? ? ? ? description when fpscr.pr = 0: this instruction takes the contents of floating-point registers xf0 to xf15 indicated by xmtrx as a 4-row 4-column matrix, takes the contents of floating-point registers fr[n] to fr[n + 3] indicated by fvn as a 4-dimensional vector, multiplies the array by the vector, and stores the results in fv[n]. xmtrx fvn fvn xf[0] xf[4] xf[8] xf[12] fr[n] fr[n] xf[1] xf[5] xf[9] xf[13] fr[n+1] fr[n+1] xf[2] xf[6] xf[10] xf[14] fr[n+2] fr[n+2] xf[3] xf[7] xf[11] xf[15] fr[n+3] fr[n+3] the ftrv instruction is intended for speed rather than accuracy, and therefore the results will differ from those obtained by using a combination of fadd and fmul instructions. the ftrv execution sequence is as follows: 1. multiplies all terms. the results are 28 bits long. 2. aligns these results, rounding them to fit within 30 bits. 3. adds the aligned values. 4. performs normalization and rounding. special processing is performed in the following cases: 1. if an input value is an snan, an invalid exception is generated. 2. if the input values to be multiplied include a combination of 0 and infinity, an invalid operation exception is generated. 3. in cases other than the above, if the input values include a qnan, the result will be a qnan. 4. in cases other than the above, if the input values include infinity: a. if multiplication results in two or more infinities and the signs are different, an invalid exception will be generated. b. otherwise, correct infinities will be stored. rev. 5.0, 04/01, page 281 of 394 5. if the input values do not include an snan, qnan, or infinity, processing is performed in the normal way. when fpscr.enable.v/o/u/i is set, an fpu exception trap is generated regardless of whether or not an exception has occurred. when an exception occurs, correct exception information is reflected in fpscr.cause and fpscr.flag, and frn or drn is not updated. appropriate processing should therefore be performed by software. operation void ftrv (int n) /* ftrv fvn */ { float saved_vec[4],result_vec[4]; int saved_fpscr; int dst,i; if(fpscr_pr == 0) { pc += 2; clear_cause(); saved_fpscr = fpscr; fpscr &= ~enable_voui; /* mask voui enable */ dst = 12 - n; /* select other vector than fvn */ for(i=0;i<4;i++)saved_vec [i] = fr[dst+i]; for(i=0;i<4;i++){ for(j=0;j<4;j++) fr[dst+j] = xf[i+4j]; fipr(n,dst); saved_fpscr |= fpscr & (cause|flag) ; result_vec [i] = fr[dst+3]; } for(i=0;i<4;i++)fr[dst+i] = saved_vec [i]; fpscr = saved_fpscr; if(fpscr & enable_voui) fpu_exception_trap(); else for(i=0;i<4;i++) fr[n+i] = result_vec [i]; } else undefined_operation(); } rev. 5.0, 04/01, page 282 of 394 possible exceptions: ? invalid operation ? overflow ? underflow ? inexact rev. 5.0, 04/01, page 283 of 394 9.48 jmp jump branch instruction unconditional branch delayed branch instruction format summary of operation instruction code execution states t bit jmp @rn rn pc 0100nnnn00101011 2? description unconditionally makes a delayed branch to the address specified by rn. notes as this is a delayed branch instruction, the instruction following this instruction is executed before the branch destination instruction. interrupts are not accepted between this instruction and the following instruction. if the following instruction is a branch instruction, it is identified as a slot illegal instruction. operation jmp(int n)/* jmp @rn */ { unsigned int temp; temp=pc; pc=r[n]; delay_slot(temp+2); } example mov.l jmp_table,r0 ; r0 = trget address jmp @r0 ; branch to trget. mov r0,r1 ; mov executed before branch. .align 4 jmp_table: . data.l trget ; jump table ........... trget: add #1,r1 ; branch destination rev. 5.0, 04/01, page 284 of 394 9.49 jsr jump to subroutine branch instruction branch to subroutine procedure delayed branch instruction format summary of operation instruction code execution states t bit jsr @rn pc+4 pr, rn pc 0100nnnn00001011 2? description this instruction makes a delayed branch to the subroutine procedure at the specified address after execution of the following instruction. return address (pc + 4) is saved in pr, and a branch is made to the address indicated by general register rn. jsr is used in combination with rts for subroutine procedure calls. notes as this is a delayed branch instruction, the instruction following this instruction is executed before the branch destination instruction. interrupts are not accepted between this instruction and the following instruction. if the following instruction is a branch instruction, it is identified as a slot illegal instruction. operation jsr(int n)/* jsr @rn */ { unsigned int temp; temp=pc; pr=pc+4; pc=r[n]; delay_slot(temp+2); } rev. 5.0, 04/01, page 285 of 394 example mov.l jsr_table,r0 ; r0 = trget address jsr @r0 ; branch to trget. xor r1,r1 ; xor executed before branch. add r0,r1 ; procedure return destination (pr contents) ....... .align 4 jsr_table: . data.l trget ; jump table trget: nop ; entry to procedure mov r2,r3 ; rts ; return to above add instruction. mov #70,r1 ; mov executed before rts. rev. 5.0, 04/01, page 286 of 394 9.50 ldc load to control register system control instruction load to control register (privileged instruction) format summary of operation instruction code execution states t bit ldc rm, sr rm sr 0100mmmm00001110 4lsb ldc rm, gbr rm gbr 0100mmmm00011110 3? ldc rm, vbr rm vbr 0100mmmm00101110 1? ldc rm, ssr rm ssr 0100mmmm00111110 1? ldc rm, spc rm spc 0100mmmm01001110 1 ldc rm, dbr rm dbr 0100mmmm11111010 1? ldc rm, r0_bank rm r0_bank 0100mmmm10001110 1? ldc rm, r1_bank rm r1_bank 0100mmmm10011110 1? ldc rm, r2_bank rm r2_bank 0100mmmm10101110 1? ldc rm, r3_bank rm r3_bank 0100mmmm10111110 1? ldc rm, r4_bank rm r4_bank 0100mmmm11001110 1? ldc rm, r5_bank rm r5_bank 0100mmmm11011110 1? ldc rm, r6_bank rm r6_bank 0100mmmm11101110 1? ldc rm, r7_bank rm r7_bank 0100mmmm11111110 1? ldc.l @rm+, sr (rm) sr, rm+4 rm 0100mmmm00000111 4lsb ldc.l @rm+, gbr (rm) gbr, rm+4 rm 0100mmmm00010111 3? ldc.l @rm+, vbr (rm) vbr, rm+4 rm 0100mmmm00100111 1? ldc.l @rm+, ssr (rm) ssr, rm+4 rm 0100mmmm00110111 1? ldc.l @rm+, spc (rm) spc, rm+4 rm 0100mmmm01000111 1? ldc.l @rm+, dbr (rm) dbr, rm+4 rm 0100mmmm11110110 1? ldc.l @rm+, r0_bank (rm) r0_bank, rm+4 rm 0100mmmm10000111 1? ldc.l @rm+, r1_bank (rm) r1_bank, rm+4 rm 0100mmmm10010111 1? ldc.l @rm+, r2_bank (rm) r2_bank, rm+4 rm 0100mmmm10100111 1? ldc.l @rm+, r3_bank (rm) r3_bank, rm+4 rm 0100mmmm10110111 1? ldc.l @rm+, r4_bank (rm) r4_bank, rm+4 rm 0100mmmm11000111 1? ldc.l @rm+, r5_bank (rm) r5_bank, rm+4 rm 0100mmmm11010111 1? ldc.l @rm+, r6_bank (rm) r6_bank, rm+4 rm 0100mmmm11100111 1? ldc.l @rm+, r7_bank (rm) r7_bank, rm+4 rm 0100mmmm11110111 1? description these instructions store the source operand in the control register sr, gbr, vbr, ssr, spc, dbr, or r0_bank to r7_bank. rev. 5.0, 04/01, page 287 of 394 notes with the exception of ldc rm,gbr and ldc.l @rm+,gbr, the ldc/ldc.l instructions are privileged instructions and can only be used in privileged mode. use in user mode will cause an illegal instruction exception. however, ldc rm,gbr and ldc.l @rm+,gbr can also be used in user mode. with the ldc rm, rn_bank and ldc.l @rm, rn_bank instructions, rn_bank0 is accessed when the rb bit in the sr register is 1, and rn_bank1 is accessed when this bit is 0. operation ldcsr(int m) /* ldc rm,sr : privileged */ { sr=r[m]&0x700083f3; pc+=2; } ldcgbr(int m) /* ldc rm,gbr */ { gbr=r[m]; pc+=2; } ldcvbr(int m) /* ldc rm,vbr : privileged */ { vbr=r[m]; pc+=2; } ldcssr(int m) /* ldc rm,ssr : privileged */ { ssr=r[m], pc+=2; } ldcspc(int m) /* ldc rm,spc : privileged */ { spc=r[m]; rev. 5.0, 04/01, page 288 of 394 pc+=2; } ldcdbr(int m) /* ldc rm,dbr : privileged */ { dbr=r[m]; pc+=2; } ldcrn_bank(int m) /* ldc rm,rn_bank : privileged */ /* n=0?7 */ { rn_bank=r[m]; pc+=2; } ldcmsr(int m) /* ldc.l @rm+,sr : privileged */ { sr=read_long(r[m])&0x700083f3; r[m]+=4; pc+=2; } ldcmgbr(int m) /* ldc.l @rm+,gbr */ { gbr=read_long(r[m]); r[m]+=4; pc+=2; } ldcmvbr(int m) /* ldc.l @rm+,vbr : privileged */ { vbr=read_long(r[m]); r[m]+=4; pc+=2; } rev. 5.0, 04/01, page 289 of 394 ldcmssr(int m) /* ldc.l @rm+,ssr : privileged */ { ssr=read_long(r[m]); r[m]+=4; pc+=2; } ldcmspc(int m) /* ldc.l @rm+,spc : privileged */ { spc=read_long(r[m]); r[m]+=4; pc+=2; } ldcmdbr(int m) /* ldc.l @rm+,dbr : privileged */ { dbr=read_long(r[m]); r[m]+=4; pc+=2; } ldcmrn_bank(long m) /* ldc.l @rm+,rn_bank : privileged */ /* n=0?7 */ { rn_bank=read_long(r[m]); r[m]+=4; pc+=2; } possible exceptions: ? general illegal instruction exception ? illegal slot instruction exception ? data tlb miss exception ? data tlb protection violation exception ? address error rev. 5.0, 04/01, page 290 of 394 9.51 lds load to fpu system register system control instruction load to fpu system register format summary of operation instruction code execution states t bit lds rm,fpul rm fpul 0100mmmm01011010 1? lds.l @rm+,fpul (rm) fpul, rm+4 rm 0100mmmm01010110 1? lds rm,fpscr rm fpscr 0100mmmm01101010 1? lds.l @rm+,fpscr (rm) fpscr, rm+4 rm 0100mmmm01100110 1? description this instruction loads the source operand into fpu system registers fpul and fpscr. operation #define fpscr_mask 0x003fffff ldsfpul(int m, int *fpul) /* lds rm,fpul */ { *fpul=r[m]; pc+=2; } ldsmfpul(int m, int *fpul) /* lds.l @rm+,fpul */ { *fpul=read_long(r[m]); r[m]+=4; pc+=2; } ldsfpscr(int m) /* lds rm,fpscr */ { fpscr=r[m] & fpscr_mask; pc+=2; } ldsmfpscr(int m) /* lds.l @rm+,fpscr */ { fpscr=read_long(r[m]) & fpscr_mask; rev. 5.0, 04/01, page 291 of 394 r[m]+=4; pc+=2; } possible exceptions: ? data tlb miss exception ? data access protection exception ? address error rev. 5.0, 04/01, page 292 of 394 9.52 lds load to system register system control instruction load to system register format summary of operation instruction code execution states t bit lds rm,mach rm mach 0100mmmm00001010 1? lds rm,macl rm macl 0100mmmm00011010 1? lds rm,pr rm pr 0100mmmm00101010 2? lds.l @rm+,mach (rm) mach, rm + 4 rm 0100mmmm00000110 1? lds.l @rm+,macl (rm) macl, rm + 4 rm 0100mmmm00010110 1? lds.l @rm+,pr (rm) pr, rm + 4 rm 0100mmmm00100110 2? description stores the source operand into the system registers mach, macl, or pr. operation ldsmach(int m) /* lds rm,mach */ { mach=r[m]; pc+=2; } ldsmacl(int m) /* lds rm,macl */ { macl=r[m]; pc+=2; } ldspr(int m) /* lds rm,pr */ { pr=r[m]; pc+=2; } ldsmmach(int m) /* lds.l @rm+,mach */ { rev. 5.0, 04/01, page 293 of 394 mach=read_long(r[m]); r[m]+=4; pc+=2; } ldsmmacl(int m) /* lds.l @rm+,macl */ { macl=read_long(r[m]); r[m]+=4; pc+=2; } ldsmpr(int m) /* lds.l @rm+,pr */ { pr=read_long(r[m]); r[m]+=4; pc+=2; } example lds r0,pr ; before execution r0 = h'12345678, pr = h'00000000 ; after execution pr = h'12345678 lds.l @r15+,macl ; before execution r15 = h'10000000 ; after execution r15 = h'10000004, macl = (h'10000000) rev. 5.0, 04/01, page 294 of 394 9.53 ldtlb load pteh/ptel/ptea to tlb system control instruction load to tlb (privileged instruction) format summary of operation instruction code execution states t bit ldtlb pteh/ptel/ptea tlb 0000000000111000 1? description this instruction loads the contents of the pteh/ptel/ptea registers into the tlb (translation lookaside buffer) specified by mmucr.urc (random counter field in the mmc control register). ldtlb is a privileged instruction, and can only be used in privileged mode. use of this instruction in user mode will cause an illegal instruction exception. notes as this instruction loads the contents of the pteh/ptel/ptea registers into a tlb, it should be used either with the mmu disabled, or in the p1 or p2 virtual space with the mmu enabled (see section 3, memory management unit, for details). after this instruction is issued, there must be at least one instruction between the ldtlb instruction and issuance of an instruction relating to address to areas p0, u0, and p3 (i.e. braf, bsrf, jmp, jsr, rts, or rte). rev. 5.0, 04/01, page 295 of 394 operation ldtlb( ) /*ldtlb */ { tlb[mmucr. urc] .asid=pteh & 0x000000ff; tlb[mmucr. urc] .vpn=(pteh & 0xfffffc00)>>10; tlb[mmucr. urc] .ppn=(pteh & 0x1ffffc00)>>10; tlb[mmucr. urc] .sz=(ptel & 0x00000080)>>6 | (ptel & 0x00000010)>>4; tlb[mmucr. urc] .sh=(pteh & 0x00000002)>>1; tlb[mmucr. urc] .pr=(pteh & 0x00000060)>>5; tlb[mmucr. urc] .wt=(pteh & 0x00000001); tlb[mmucr. urc] .c=(pteh & 0x00000008)>>3; tlb[mmucr. urc] .d=(pteh & 0x00000004)>>2; tlb[mmucr. urc] .v=(pteh & 0x00000100)>>8; tlb[mmucr. urc] .sa=(ptea & 0x00000007); tlb[mmucr. urc] .tc=(ptea & 0x00000008)>>3; pc+=2; } example mov @r0,r1 ; load page table entry (upper) into r1 mov r1,@r2 ; load r1 into pteh; r2 is pteh address (h'ff000000) ldtlb ; load pteh, ptel, ptea registers into tlb rev. 5.0, 04/01, page 296 of 394 9.54 mac.l multiply and accumulate long arithmetic instruction double-precision multiply-and-accumulate operation format summary of operation instruction code execution states t bit mac.l @rm+,@rn+ signed, (rn) (rm) + mac mac rn + 4 rn, rm + 4 rm 0000nnnnmmmm1111 2?5 ? description this instruction performs signed multiplication of the 32-bit operands whose addresses are the contents of general registers rm and rn, adds the 64-bit result to the mac register contents, and stores the result in the mac register. operands rm and rn are each incremented by 4 each time they are read. if the s bit is 0, the 64-bit result is stored in the linked mach and macl registers. if the s bit is 1, the addition to the mac register contents is a saturation operation at the 48th bit from the lsb. in a saturation operation, only the lower 48 bits of the mac register are valid, and the result range is limited to h'ffff800000000000 (minimum value) to h'00007fffffffffff (maximum value). operation macl(long m, long n) /* mac.l @rm+,@rn+ */ { unsigned long rnl,rnh,rml,rmh,res0,res1,res2; unsigned long temp0,temp1,temp2,temp3; long tempm,tempn,fnlml; tempn=(long)read_long(r[n]); r[n]+=4; tempm=(long)read_long(r[m]); r[m]+=4; if ((long)(tempn^tempm)<0) fnlml=-1; else fnlml=0; rev. 5.0, 04/01, page 297 of 394 if (tempn<0) tempn=0-tempn; if (tempm<0) tempm=0-tempm; temp1=(unsigned long)tempn; temp2=(unsigned long)tempm; rnl=temp1&0x0000ffff; rnh=(temp1>>16)&0x0000ffff; rml=temp2&0x0000ffff; rmh=(temp2>>16)&0x0000ffff; temp0=rml*rnl; temp1=rmh*rnl; temp2=rml*rnh; temp3=rmh*rnh; res2=0; res1=temp1+temp2; if (res1 rev. 5.0, 04/01, page 298 of 394 res2+=mach&0x00007fff; if(((long)res2<0)&&(res2<0xffff8000)){ res2=0xffff8000; res0=0x00000000; } if(((long)res2>0)&&(res2>0x00007fff)){ res2=0x00007fff; res0=0xffffffff; }; mach=(res2&0x0000ffff)|(mach&0xffff0000); macl=res0; } else { res0=macl+res0; if (macl>res0) res2++; res2+=mach; mach=res2; macl=res0; } pc+=2; } rev. 5.0, 04/01, page 299 of 394 example mova tblm,r0 ; get table address mov r0,r1 ; mova tbln,r0 ; get table address clrmac ; mac register initialization mac.l @r0+,@r1+ ; mac.l @r0+,@r1+ ; sts macl,r0 ; get result in r0 ......... .align 2; tblm .data.l h'1234abcd ; .data.l h'5678ef01 ; tbln .data.l h'0123abcd ; .data.l h'4567def0 ; rev. 5.0, 04/01, page 300 of 394 9.55 mac.w multiply and accumulate word arithmetic instruction single-precision multiply-and-accumulate operation format summary of operation instruction code execution states t bit mac.w @rm+,@rn+ mac @rm+,@rn+ signed, (rn) (rm) + mac mac rn + 2 rn, rm + 2 rm 0100nnnnmmmm1111 2?5 ? description this instruction performs signed multiplication of the 16-bit operands whose addresses are the contents of general registers rm and rn, adds the 32-bit result to the mac register contents, and stores the result in the mac register. operands rm and rn are each incremented by 2 each time they are read. if the s bit is 0, a 16 16 + 64 64-bit multiply-and-accumulate operation is performed, and the 64-bit result is stored in the linked mach and macl registers. if the s bit is 1, a 16 16 + 32 32-bit multiply-and-accumulate operation is performed, and the addition to the mac register contents is a saturation operation. in a saturation operation, only the macl register is valid, and the result range is limited to h'80000000 (minimum value) to h'7fffffff (maximum value). if overflow occurs, the lsb of the mach register is set to 1. h'80000000 (minimum value) is stored in the macl register if the result overflows in the negative direction, and h'7fffffff (maximum value) is stored if the result overflows in the positive direction notes if the s bit is 0, a 16 16 + 64 64-bit multiply-and-accumulate operation is performed. rev. 5.0, 04/01, page 301 of 394 operation macw(long m, long n) /* mac.w @rm+,@rn+ */ { long tempm,tempn,dest,src,ans; unsigned long templ; tempn=(long)read_word(r[n]); r[n]+=2; tempm=(long)read_word(r[m]); r[m]+=2; templ=macl; tempm=((long)(short)tempn*(long)(short)tempm); if ((long)macl>=0) dest=0; else dest=1; if ((long)tempm>=0) { src=0; tempn=0; } else { src=1; tempn=0xffffffff; } src+=dest; macl+=tempm; if ((long)macl>=0) ans=0; else ans=1; ans+=dest; if (s==1) { if (ans==1) { if (src==0) macl=0x7fffffff; if (src==2) macl=0x80000000; } } else { mach+=tempn; if (templ>macl) mach+=1; } rev. 5.0, 04/01, page 302 of 394 pc+=2; } example mova tblm,r0 ; get table address mov r0,r1 ; mova tbln,r0 ; get table address clrmac ; mac register initialization mac.w @r0+,@r1+ ; mac.w @r0+,@r1+ ; sts macl,r0 ; get result in r0 ........... .align 2; tblm .data.w h'1234 ; .data.w h'5678 ; tbln .data.w h'0123 ; .data.w h'4567 ; rev. 5.0, 04/01, page 303 of 394 9.56 mov move data data transfer instruction data transfer format summary of operation instruction code execution states t bit mov rm,rn rm rn 0110nnnnmmmm0011 1? mov.b rm,@rn rm (rn) 0010nnnnmmmm0000 1? mov.w rm,@rn rm (rn) 0010nnnnmmmm0001 1? mov.l rm,@rn rm (rn) 0010nnnnmmmm0010 1? mov.b @rm,rn (rm) sign extension rn 0110nnnnmmmm0000 1? mov.w @rm,rn (rm) sign extension rn 0110nnnnmmmm0001 1? mov.l @rm,rn (rm) rn 0110nnnnmmmm0010 1? mov.b rm,@-rn rn-1 rn, rm (rn ) 0010nnnnmmmm0100 1? mov.w rm,@-rn rn-2 rn, rm (rn ) 0010nnnnmmmm0101 1? mov.l rm,@-rn rn-4 rn, rm (rn) 0010nnnnmmmm0110 1? mov.b @rm+,rn (rm) sign extension rn, rm+1 rm 0110nnnnmmmm0100 1? mov.w @rm+,rn (rm) sign extension rn, rm+2 rm 0110nnnnmmmm0101 1? mov.l @rm+,rn (rm) rn, rm+4 rm 0110nnnnmmmm0110 1? mov.b rm,@(r0,rn) rm (r0+rn) 0000nnnnmmmm0100 1? mov.w rm,@(r0,rn) rm (r0+rn) 0000nnnnmmmm0101 1? mov.l rm,@(r0,rn) rm (r0+rn) 0000nnnnmmmm0110 1? mov.b @(r0,rm),rn (r0+rm) sign extension rn 0000nnnnmmmm1100 1? mov.w @(r0,rm),rn (r0+rm) sign extension rn 0000nnnnmmmm1101 1? mov.l @(r0,rm),rn (r0+rm) rn 0000nnnnmmmm1110 1? description this instruction transfers the source operand to the destination. when an operand is memory, the data size can be specified as byte, word, or longword. when the source operand is memory, the loaded data is sign-extended to longword before being stored in the register. rev. 5.0, 04/01, page 304 of 394 operation mov(long m, long n) /* mov rm,rn */ { r[n]=r[m]; pc+=2; } movbs(long m, long n) /* mov.b rm,@rn */ { write_byte(r[n],r[m]); pc+=2; } movws(long m, long n) /* mov.w rm,@rn */ { write_word(r[n],r[m]); pc+=2; } movls(long m, long n) /* mov.l rm,@rn */ { write_long(r[n],r[m]); pc+=2; } movbl(long m, long n) /* mov.b @rm,rn */ { r[n]=(long)read_byte(r[m]); if ((r[n]&0x80)==0) r[n]&=0x000000ff; else r[n]|=0xffffff00; pc+=2; } movwl(long m, long n) /* mov.w @rm,rn */ { r[n]=(long)read_word(r[m]); if ((r[n]&0x8000)==0) r[n]&=0x0000ffff; rev. 5.0, 04/01, page 305 of 394 else r[n]|=0xffff0000; pc+=2; } movll(long m, long n) /* mov.l @rm,rn */ } r[n]=read_long(r[m]); pc+=2; } movbm(long m, long n) /* mov.b rm,@-rn */ { write_byte(r[n]-1,r[m]); r[n]-=1; pc+=2; } movwm(long m, long n) /* mov.w rm,@-rn */ { write_word(r[n]-2,r[m]); r[n]-=2; pc+=2; } movlm(long m, long n) /* mov.l rm,@-rn */ { write_long(r[n]-4,r[m]); r[n]-=4; pc+=2; } movbp(long m, long n) /* mov.b @rm+,rn */ { r[n]=(long)read_byte(r[m]); if ((r[n]&0x80)==0) r[n]&=0x000000ff; else r[n]|=0xffffff00; if (n!=m) r[m]+=1; rev. 5.0, 04/01, page 306 of 394 pc+=2; } movwp(long m, long n) /* mov.w @rm+,rn */ { r[n]=(long)read_word(r[m]); if ((r[n]&0x8000)==0) r[n]&=0x0000ffff; else r[n]|=0xffff0000; if (n!=m) r[m]+=2; pc+=2; } movlp(long m, long n) /* mov.l @rm+,rn */ { r[n]=read_long(r[m]); if (n!=m) r[m]+=4; pc+=2; } movbs0(long m, long n) /* mov.b rm,@(r0,rn) */ { write_byte(r[n]+r[0],r[m]); pc+=2; } movws0(long m, long n) /* mov.w rm,@(r0,rn) */ { write_word(r[n]+r[0],r[m]); pc+=2; } movls0(long m, long n) /* mov.l rm,@(r0,rn) */ { write_long(r[n]+r[0],r[m]); pc+=2; } movbl0(long m, long n) /* mov.b @(r0,rm),rn */ rev. 5.0, 04/01, page 307 of 394 { r[n]=(long)read_byte(r[m]+r[0]); if ((r[n]&0x80)==0) r[n]&=0x000000ff; else r[n]|=0xffffff00; pc+=2; } movwl0(long m, long n) /* mov.w @(r0,rm),rn */ { r[n]=(long)read_word(r[m]+r[0]); if ((r[n]&0x8000)==0) r[n]&=0x0000ffff; else r[n]|=0xffff0000; pc+=2; } movll0(long m, long n) /* mov.l @(r0,rm),rn */ { r[n]=read_long(r[m]+r[0]); pc+=2; } example mov r0,r1 ; before execution r0 = h'ffffffff, r1 = h'00000000 ; after execution r1 = h'ffffffff mov.w r0,@r1 ; before execution r0 = h'ffff7f80 ; after execution (r1) = h'7f80 mov.b @r0,r1 ; before execution (r0) = h'80, r1 = h'00000000 ; after execution r1 = h'ffffff80 mov.w r0,@-r1 ; before execution r0 = h'aaaaaaaa, (r1) = h'ffff7f80 ; after execution r1 = h'ffff7f7e, (r1) = h'aaaa mov.l @r0+,r1 ; before execution r0 = h'12345670 ; after execution r0 = h'12345674, r1 = (h'12345670) mov.b r1,@(r0,r2) ; before execution r2 = h'00000004, r0 = h'10000000 ; after execution r1 = (h'10000004) mov.w @(r0,r2),r1 ; before execution r2 = h'00000004, r0 = h'10000000 ; after execution r1 = (h'10000004) rev. 5.0, 04/01, page 308 of 394 9.57 mov move constant value data transfer instruction immediate data transfer format summary of operation instruction code execution states t bit mov #imm,rn imm sign extension rn 1110nnnniiiiiiii 1? mov.w @(disp,pc),rn (disp 2+pc+4) sign extension rn 1001nnnndddddddd 1? mov.l @(disp,pc),rn (disp 4+pc+4) rn 1101nnnndddddddd 1? description this instruction stores immediate data, sign-extended to longword, in general register rn. in the case of word or longword data, the data is stored from memory address (pc + 4 + displacement 2) or (pc + 4 + displacement 4). with word data, the 8-bit displacement is multiplied by two after zero-extension, and so the relative distance from the table is in the range up to pc + 4 + 510 bytes. the pc value is the address of this instruction. with longword data, the 8-bit displacement is multiplied by four after zero-extension, and so the relative distance from the operand is in the range up to pc + 4 + 1020 bytes. the pc value is the address of this instruction. a value with the lower 2 bits adjusted to b'00 is used in address calculation. notes if a pc-relative load instruction is executed in a delay slot, an illegal slot instruction exception will be generated. rev. 5.0, 04/01, page 309 of 394 operation movi(int i, int n) /* mov #imm,rn */ { if ((i&0x80)==0) r[n]=(0x000000ff & i); else r[n]=(0xffffff00 | i); pc+=2; } movwi(d, n) /* mov.w @(disp,pc),rn */ { unsigned int disp; disp=(unsigned int)(0x000000ff & d); r[n]=(int)read_word(pc+4+(disp<<1)); if ((r[n]&0x8000)==0) r[n]&=0x0000ffff; else r[n]|=0xffff0000; pc+=2; } movli(int d, int n)/* mov.l @(disp,pc),rn */ { unsigned int disp; disp=(unsigned int)(0x000000ff & (int)d); r[n]=read_long((pc&0xfffffffc)+4+(disp<<2)); pc+=2; } rev. 5.0, 04/01, page 310 of 394 example address 1000 mov #h'80,r1 ; r1 = h'ffffff80 1002 mov.w imm,r2 ; r2 = h'ffff9abc imm means (pc + 4 + h'08) 1004 add #-1,r0 ; 1006 tst r0,r0 ; 1008 mov.l @(3,pc),r3 ; r3 = h'12345678 100a bra next ; delayed branch instruction 100c nop 100e imm .data.w h'9abc ; 1010 .data.w h'1234 ; 1012 next jmp @r3 ; bra branch instruction 1014 cmp/eq #0,r0 ; .align 4 ; 1018 .data.l h'12345678 ; 101c .data.l h'9abcdef0 ; rev. 5.0, 04/01, page 311 of 394 9.58 mov move global data data transfer instruction global data transfer format summary of operation instruction code execution states t bit mov.b @(disp,gbr),r0 (disp+gbr) sign extension r0 11000100dddddddd 1? mov.w @(disp,gbr), r0 (disp 2+gbr) sign extension r0 11000101dddddddd 1? mov.l @(disp,gbr),r0 (disp 4+gbr) r0 11000110dddddddd 1? mov.b r0,@(disp,gbr) r0 (disp+gbr) 11000000dddddddd 1? mov.w r0,@(disp,gbr) r0 (disp 2+gbr) 11000001dddddddd 1? mov.l r0,@(disp,gbr) r0 (disp 4+gbr) 11000010dddddddd 1? description this instruction transfers the source operand to the destination. byte, word, or longword can be specified as the data size, but the register is always r0. if the transfer data is byte-size, the 8-bit displacement is only zero-extended, so a range up to +255 bytes can be specified. if the transfer data is word-size, the 8-bit displacement is multiplied by two after zero-extension, enabling a range up to +510 bytes to be specified. with longword transfer data, the 8-bit displacement is multiplied by four after zero-extension, enabling a range up to +1020 bytes to be specified. when the source operand is memory, the loaded data is sign-extended to longword before being stored in the register. notes when loading, the destination register is always r0. rev. 5.0, 04/01, page 312 of 394 operation movblg(int d) /* mov.b @(disp,gbr),r0 */ { unsigned int disp; disp=(unsigned int)(0x000000ff & d); r[0]=(int)read_byte(gbr+disp); if ((r[0]&0x80)==0) r[0]&=0x000000ff; else r[0]|=0xffffff00; pc+=2; } movwlg(int d) /* mov.w @(disp,gbr),r0 */ { unsigned int disp; disp=(unsigned int)(0x000000ff & d); r[0]=(int)read_word(gbr+(disp<<1)); if ((r[0]&0x8000)==0) r[0]&=0x0000ffff; else r[0]|=0xffff0000; pc+=2; } movllg(int d) /* mov.l @(disp,gbr),r0 */ { unsigned int disp; disp=(unsigned int)(0x000000ff & d); r[0]=read_long(gbr+(disp<<2)); pc+=2; } movbsg(int d) /* mov.b r0,@(disp,gbr) */ { unsigned int disp; rev. 5.0, 04/01, page 313 of 394 disp=(unsigned int)(0x000000ff & d); write_byte(gbr+disp,r[0]); pc+=2; } movwsg(int d) /* mov.w r0,@(disp,gbr) */ { unsigned int disp; disp=(unsigned int)(0x000000ff & d); write_word(gbr+(disp<<1),r[0]); pc+=2; } movlsg(int d) /* mov.l r0,@(disp,gbr) */ { unsigned int disp; disp=(unsigned int)(0x000000ff & (long)d); write_long(gbr+(disp<<2),r[0]); pc+=2; } example mov.l @(2,gbr),r0 ; before execution (gbr+8) = h'12345670 ; after execution r0 = (h'12345670) mov.b r0,@(1,gbr) ; before execution r0 = h'ffff7f80 ; after execution (gbr+1) = h'80 rev. 5.0, 04/01, page 314 of 394 9.59 mov move structure data data transfer instruction structure data transfer format summary of operation instruction code execution states t bit mov.b r0,@(disp,rn) r0 (disp+rn) 10000000nnnndddd 1? mov.w r0,@(disp,rn) r0 (disp2+rn) 10000001nnnndddd 1? mov.l rm,@(disp,rn) rm (disp4+rn) 0001nnnnmmmmdddd 1? mov.b @(disp,rm),r0 (disp+rm) sign extension r0 10000100mmmmdddd 1? mov.w @(disp,rm),r0 (disp2+rm) sign extension r0 10000101mmmmdddd 1? mov.l @(disp,rm),rn (disp4+rm) rn 0101nnnnmmmmdddd 1? description this instruction transfers the source operand to the destination. it is ideal for accessing data inside a structure or stack. byte, word, or longword can be specified as the data size, but with byte or word data the register is always r0. if the data is byte-size, the 4-bit displacement is only zero-extended, so a range up to +15 bytes can be specified. if the data is word-size, the 4-bit displacement is multiplied by two after zero- extension, enabling a range up to +30 bytes to be specified. with longword data, the 4-bit displacement is multiplied by four after zero-extension, enabling a range up to +60 bytes to be specified. if a memory operand cannot be reached, the previously described @(r0,rn) mode must be used. when the source operand is memory, the loaded data is sign-extended to longword before being stored in the register. notes when loading byte or word data, the destination register is always r0. therefore, if the following instruction attempts to reference r0, it is kept waiting until completion of the load instruction. this allows optimization by changing the order of instructions. mov.b and add @(2,r1),r0 #80,r0 #20,r1 mov.b add and @(2,r1),r0 #20,r1 #80,r0 rev. 5.0, 04/01, page 315 of 394 operation movbs4(long d, long n /* mov.b r0,@(disp,rn) */ { long disp; disp=(0x0000000f & (long)d); write_byte(r[n]+disp,r[0]); pc+=2; } movws4(long d, long n) /* mov.w r0,@(disp,rn) */ { long disp; disp=(0x0000000f & (long)d); write_word(r[n]+(disp<<1),r[0]); pc+=2; } movls4(long m, long d, long n) /* mov.l rm,@(disp,rn) */ { long disp; disp=(0x0000000f & (long)d); write_long(r[n]+(disp<<2),r[m]); pc+=2; } movbl4(long m, long d) /* mov.b @(disp,rm),r0 */ { long disp; disp=(0x0000000f & (long)d); r[0]=read_byte(r[m]+disp); if ((r[0]&0x80)==0) r[0]&=0x000000ff; else r[0]|=0xffffff00; pc+=2; } rev. 5.0, 04/01, page 316 of 394 movwl4(long m, long d) /* mov.w @(disp,rm),r0 */ { long disp; disp=(0x0000000f & (long)d); r[0]=read_word(r[m]+(disp<<1)); if ((r[0]&0x8000)==0) r[0]&=0x0000ffff; else r[0]|=0xffff0000; pc+=2; } movll4(long m, long d, long n) /* mov.l @(disp,rm),rn */ { long disp; disp=(0x0000000f & (long)d); r[n]=read_long(r[m]+(disp<<2)); pc+=2; } example mov.l @(2,r0),r1 ; before execution (r0+8) = h'12345670 ; after execution r1 = (h'12345670) mov.l r0,@(h'f,r1) ; before execution r0 = h'ffff7f80 ; after execution (r1+60) = h'ffff7f80 rev. 5.0, 04/01, page 317 of 394 9.60 mova move effective address data transfer instruction effective address transfer format summary of operation instruction code execution states t bit mova @(disp,pc),r0 disp 4+pc+4 r0 11000111dddddddd 1? description this instruction stores the source operand effective address in general register r0. the 8-bit displacement is multiplied by four after zero-extension. the pc value is the address of this instruction, but a value with the lower 2 bits adjusted to b'00 is used in address calculation. notes if this instruction is executed in a delay slot, an illegal slot instruction exception will be generated. operation mova(int d) /* mova @(disp,pc),r0 */ { unsigned int disp; disp=(unsigned int)(0x000000ff & d); r[0]=(pc&0xfffffffc)+4+(disp<<2); pc+=2; } example address .org h'1006 1006 mova str,r0 ; str address r0 1008 mov.b @r0,r1 ; r1 = ?x? position after adjustment of lower 2 bits of pc 100a add r4,r5 ; original pc position in mova instruction address calculation .align 4 100c str: .sdata "xyzp12" rev. 5.0, 04/01, page 318 of 394 9.61 movca.l move with cache block allocation data transfer instruction cache block allocation format summary of operation instruction code execution states t bit movca.l r0,@rn r0 (rn) 0000nnnn11000011 1? description this instruction stores the contents of general register r0 in the memory location indicated by effective address rn. this instruction differs from other store instructions as follows. if write-back is selected for the accessed memory, and a cache miss occurs, the cache block will be allocated but an r0 data write will be performed to that cache block without performing a block read. other cache block contents are undefined. operation movcal(int n) /*movca.l r0,@rn */ { if ((is_write_back_memory(r[n])) && (look_up_in_operand_cache(r[n]) == miss)) allocate_operand_cache_block(r[n]); write_long(r[n], r[0]); pc+=2; } possible exceptions: ? data tlb miss exception ? data tlb protection violation exception ? initial page write exception ? address error rev. 5.0, 04/01, page 319 of 394 9.62 movt move t bit data transfer instruction t bit transfer format summary of operation instruction code execution states t bit movt rn t rn 0000nnnn00101001 1? description this instruction stores the t bit in general register rn. when t = 1, rn = 1; when t = 0, rn = 0. operation movt(long n) /* movt rn */ { r[n]=(0x00000001 & sr); pc+=2; } example xor r2,r2 ; r2 = 0 cmp/pz r2 ; t = 1 movt r0 ; r0 = 1 clrt ; t = 0 movt r1 ; r1 = 0 rev. 5.0, 04/01, page 320 of 394 9.63 mul.l multiply long arithmetic instruction double-precision multiplication format summary of operation instruction code execution states t bit mul.l rm,rn rnrm macl 0000nnnnmmmm0111 2?5 ? description this instruction performs 32-bit multiplication of the contents of general registers rn and rm, and stores the lower 32 bits of the result in the macl register. the contents of mach are not changed. operation mull(long m, long n) /* mul.l rm,rn */ { macl=r[n]*r[m]; pc+=2; } example mul.l r0,r1 ; before execution r0 = h'fffffffe, r1 = h'00005555 ; after execution macl = h'ffff5556 sts macl,r0 ; get operation result rev. 5.0, 04/01, page 321 of 394 9.64 muls.w multiply as signed word arithmetic instruction signed multiplication format summary of operation instruction code execution states t bit muls.w rm,rn muls rm,rn signed, rn rm macl 0010nnnnmmmm1111 2?5 ? description this instruction performs 16-bit multiplication of the contents of general registers rn and rm, and stores the 32-bit result in the macl register. the multiplication is performed as a signed arithmetic operation. the contents of mach are not changed. operation muls(long m, long n) /* muls rm,rn */ { macl=((long)(short)r[n]*(long)(short)r[m]); pc+=2; } example muls.w r0,r 1 ; before execution r0 = h'fffffffe, r1 = h'00005555 ; after execution macl = h'ffff5556 sts macl,r0 ; get operation result rev. 5.0, 04/01, page 322 of 394 9.65 mulu.w multiply as unsigned word arithmetic instruction unsigned multiplication format summary of operation instruction code execution states t bit mulu.w rm,rn mulu rm,rn unsigned, rn rm macl 0010nnnnmmmm1110 2?5 ? description this instruction performs 16-bit multiplication of the contents of general registers rn and rm, and stores the 32-bit result in the macl register. the multiplication is performed as an unsigned arithmetic operation. the contents of mach are not changed. operation mulu(long m, long n) /* mulu rm,rn */ { macl=((unsigned long)(unsigned short)r[n]* (unsigned long)(unsigned short)r[m]; pc+=2; } example mulu.w r0,r1 ; before execution r0 = h'00000002, r1 = h'ffffaaaa ; after execution macl = h'00015554 sts macl,r0 ; get operation result rev. 5.0, 04/01, page 323 of 394 9.66 neg negate arithmetic instruction sign inversion format summary of operation instruction code execution states t bit neg rm,rn 0-rm rn 0110nnnnmmmm1011 1? description this instruction finds the two?s complement of the contents of general register rm and stores the result in rn. that is, it subtracts rm from 0 and stores the result in rn. operation neg(long m, long n) /* neg rm,rn */ { r[n]=0-r[m]; pc+=2; } example neg r0,r1 ; before execution r0 = h'00000001 ; after execution r1 = h'ffffffff rev. 5.0, 04/01, page 324 of 394 9.67 negc negate with carry arithmetic instruction sign inversion with borrow format summary of operation instruction code execution states t bit negc rm,rn 0 ? rm ? t rn, borrow t 0110nnnnmmmm1010 1 borrow description this instruction subtracts the contents of general register and the t bit from 0 and stores the result in rn. a borrow resulting from the operation is reflected in the t bit. the negc instruction is used for sign inversion of a value exceeding 32 bits. operation negc(long m, long n) /* negc rm,rn */ { unsigned long temp; temp=0-r[m]; r[n]=temp-t; if (0 rev. 5.0, 04/01, page 326 of 394 9.69 not not-logical complement logical instruction bit inversion format summary of operation instruction code execution states t bit not rm,rn rm rn 0110nnnnmmmm0111 1? description this instruction finds the one?s complement of the contents of general register rm and stores the result in rn. that is, it inverts the rm bits and stores the result in rn. operation not(long m, long n) /* not rm,rn */ { r[n]= r[m]; pc+=2; } example not r0,r1 ; before execution r0 = h'aaaaaaaa ; after execution r1 = h'55555555 rev. 5.0, 04/01, page 327 of 394 9.70 ocbi operand cache block invalidate data transfer instruction cache block invalidation format summary of operation instruction code execution states t bit ocbi @rn operand cache block invalidation 0000nnnn10010011 1? description this instruction accesses data using the contents indicated by effective address rn. in the case of a hit in the cache, the corresponding cache block is invalidated (the v bit is cleared to 0). if there is unwritten information (u bit = 1), write-back is not performed even if write-back mode is selected. no operation is performed in the case of a cache miss or an access to a non-cache area. operation ocbi(int n) /* ocbi @rn */ { invalidate_operand_cache_block(r[n]); pc+=2; } possible exceptions: ? data tlb miss exception ? data tlb protection violation exception ? initial page write exception ? address error note that the above exceptions are generated even if ocbi does not operate. rev. 5.0, 04/01, page 328 of 394 9.71 ocbp operand cache block purge data transfer instruction cache block purge format summary of operation instruction code execution states t bit ocbp @rn operand cache block purge 0000nnnn10100011 1? description this instruction accesses data using the contents indicated by effective address rn. if the cache is hit and there is unwritten information (u bit = 1), the corresponding cache block is written back to external memory and that block is invalidated (the v bit is cleared to 0). if there is no unwritten information (u bit = 0), the block is simply invalidated. no operation is performed in the case of a cache miss or an access to a non-cache area. operation ocbp(int n) /* ocbp @rn */ { if(is_dirty_block(r[n])) write_back(r[n]) invalidate_operand_cache_block(r[n]); pc+=2; } possible exceptions: ? data tlb miss exception ? data tlb protection violation exception ? address error note that the above exceptions are generated even if ocbp does not operate. rev. 5.0, 04/01, page 329 of 394 9.72 ocbwb operand cache block write back data transfer instruction cache block write-back format summary of operation instruction code execution states t bit ocbwb @rn operand cache block write- back 0000nnnn10110011 1? description this instruction accesses data using the contents indicated by effective address rn. if the cache is hit and there is unwritten information (u bit = 1), the corresponding cache block is written back to external memory and that block is cleaned (the u bit is cleared to 0). in other cases (i.e. in the case of a cache miss or an access to a non-cache area, or if the block is already clean), no operation is performed. operation ocbwb(int n) /* ocbwb @rn */ { if(is_dirty_block(r[n])) write_back(r[n]); pc+=2; } possible exceptions: ? data tlb miss exception ? data tlb protection violation exception ? address error note that the above exceptions are generated even if ocbwb does not operate. rev. 5.0, 04/01, page 330 of 394 9.73 or or logical logical instruction logical or format summary of operation instruction code execution states t bit or rm,rn rn | rm rn 0010nnnnmmmm1011 1? or #imm,r0 r0 | imm r0 11001011iiiiiiii 1? or.b #imm,@(r0,gbr) (r0+gbr) | imm (r0+gbr) 11001111iiiiiiii 4? description this instruction ors the contents of general registers rn and rm and stores the result in rn. this instruction can be used to or general register r0 contents with zero-extended 8-bit immediate data, or, in indexed gbr indirect addressing mode, to or 8-bit memory with 8-bit immediate data. rev. 5.0, 04/01, page 331 of 394 operation or(long m, long n) /* or rm,rn */ { r[n]|=r[m]; pc+=2; } ori(long i) /* or #imm,r0 */ { r[0]|=(0x000000ff & (long)i); pc+=2; } orm(long i) /* or.b #imm,@(r0,gbr) */ { long temp; temp=(long)read_byte(gbr+r[0]); temp|=(0x000000ff & (long)i); write_byte(gbr+r[0],temp); pc+=2; } example or r0,r1 ; before execution r0 = h'aaaa5555, r1 = h'55550000 ; after execution r1 = h'ffff5555 or #h'f0,r0 ; before execution r0 = h'00000008 ; after execution r0 = h'000000f8 or.b #h'50,@(r0,gbr) ; before execution (r0,gbr) = h'a5 ; after execution (r0,gbr) = h'f5 rev. 5.0, 04/01, page 332 of 394 9.74 pref prefetch data to cache data transfer instruction prefetch to data cache format summary of operation nstruction code execution states t bit pref @rn prefetch cache block 0000nnnn10000011 1 ? description this instruction reads a 32-byte data block starting at a 32-byte boundary into the operand cache. the lower 5 bits of the address specified by rn are masked to zero. this instruction does not generate address-related errors. in the event of an error, the pref instruction is treated as an nop (no operation) instruction. operation pref(int n) /* pref */ { pc+=2; } example mov.l #soft_pf,r1 ; r1 address is soft_pf pref @r1 ; load soft_pf data into on-chip cache . align 32 soft_pf: . data . l h'12345678 . data . l h'9abcdef0 . data . l h'aaaa5555 . data . l h'5555aaaa . data . l h'11111111 . data . l h'22222222 . data . l h'33333333 . data . l h'44444444 rev. 5.0, 04/01, page 333 of 394 9.75 rotcl rotate with carry left shift instruction one-bit left rotation through t bit format summary of operation instruction code execution states t bit rotcl rn t rn t 0100nnnn00100100 1msb description this instruction rotates the contents of general register rn one bit to the left through the t bit, and stores the result in rn. the bit rotated out of the operand is transferred to the t bit. msb lsb rotcl t operation rotcl(long n) /* rotcl rn */ { long temp; if ((r[n]&0x80000000)==0) temp=0; else temp=1; r[n]<<=1; if (t==1) r[n]|=0x00000001; else r[n]&=0xfffffffe; if (temp==1) t=1; else t=0; pc+=2; } example rotcl r0 ; before execution r0 = h'80000000, t = 0 ; after execution r0 = h'00000000, t = 1 rev. 5.0, 04/01, page 334 of 394 9.76 rotcr rotate with carry right shift instruction one-bit right rotation through t bit format summary of operation instruction code execution states t bit rotcr rn t rn t 0100nnnn00100101 1lsb description this instruction rotates the contents of general register rn one bit to the right through the t bit, and stores the result in rn. the bit rotated out of the operand is transferred to the t bit. t msb lsb rotcr operation rotcr(long n) /* rotcr rn */ { long temp; if ((r[n]&0x00000001)==0) temp=0; else temp=1; r[n]>>=1; if (t==1) r[n]|=0x80000000; else r[n]&=0x7fffffff; if (temp==1) t=1; else t=0; pc+=2; } example rotcr r0 ; before execution r0 = h'00000001, t = 1 ; after execution r0 = h'80000000, t = 1 rev. 5.0, 04/01, page 335 of 394 9.77 rotl rotate left shift instruction one-bit left rotation format summary of operation instruction code execution states t bit rotl rn t rn msb 0100nnnn00000100 1msb description this instruction rotates the contents of general register rn one bit to the left, and stores the result in rn. the bit rotated out of the operand is transferred to the t bit. msb lsb rotl t operation rotl(long n) /* rotl rn */ { if ((r[n]&0x80000000)==0) t=0; else t=1; r[n]<<=1; if (t==1) r[n]|=0x00000001; else r[n]&=0xfffffffe; pc+=2; } example rotl r0 ; before execution r0 = h'80000000, t = 0 ; after execution r0 = h'00000001, t = 1 rev. 5.0, 04/01, page 336 of 394 9.78 rotr rotate right shift instruction one-bit right rotation format summary of operation instruction code execution states t bit rotr rn lsb rn t 0100nnnn00000101 1lsb description this instruction rotates the contents of general register rn one bit to the right, and stores the result in rn. the bit rotated out of the operand is transferred to the t bit. msb lsb rotr t operation rotr(long n) /* rotr rn */ { if ((r[n]&0x00000001)==0) t=0; else t=1; r[n]>>=1; if (t==1) r[n]|=0x80000000; else r[n]&=0x7fffffff; pc+=2; } example rotr r0 ; before execution r0 = h'00000001, t = 0 ; after execution r0 = h'80000000, t = 1 rev. 5.0, 04/01, page 337 of 394 9.79 rte return from exception system control instruction return from exception handling (privileged instruction) delayed branch instruction format summary of operation instruction code execution states t bit rte ssr sr, spc pc 0000000000101011 5? description this instruction returns from an exception or interrupt handling routine by restoring the pc and sr values from spc and ssr. program execution continues from the address specified by the restored pc value. rte is a privileged instruction, and can only be used in privileged mode. use of this instruction in user mode will cause an illegal instruction exception. notes as this is a delayed branch instruction, the instruction following the rte instruction is executed before the branch destination instruction. interrupts are not accepted between this instruction and the following instruction. an exception must not be generated by the instruction in this instruction?s delay slot. if the following instruction is a branch instruction, it is identified as a slot illegal instruction. if this instruction is located in the delay slot immediately following a delayed branch instruction, it is identified as a slot illegal instruction. the sr value accessed by the instruction in the rte delay slot is the value restored from ssr by the rte instruction. the sr and md values defined prior to rte execution are used to fetch the instruction in the rte delay slot. rev. 5.0, 04/01, page 338 of 394 operation rte( ) /* rte */ { unsigned int temp; temp=pc; sr=ssr; pc=spc; delay_slot(temp+2); } example rte ; return to original routine. add #8,r14 ; executed before branch. note: in a delayed branch, the actual branch operation occurs after execution of the slot instruction, but instruction execution (register updating, etc.) is in fact performed in delayed branch instruction delay slot instruction order. for example, even if the register holding the branch destination address is modified in the delay slot, the branch destination address will still be the register contents prior to the modification. rev. 5.0, 04/01, page 339 of 394 9.80 rts return from subroutine branch instruction return from subroutine procedure delayed branch instruction format summary of operation instruction code execution states t bit rts pr pc 0000000000001011 2? description this instruction returns from a subroutine procedure by restoring the pc from pr. processing continues from the address indicated by the restored pc value. this instruction can be used to return from a subroutine procedure called by a bsr or jsr instruction to the source of the call. notes as this is a delayed branch instruction, the instruction following this instruction is executed before the branch destination instruction. interrupts are not accepted between this instruction and the following instruction. if the following instruction is a branch instruction, it is identified as a slot illegal instruction. the instruction that restores pr must be executed before the rts instruction. this restore instruction cannot be in the rts delay slot. operation rts( ) /* rts */ { unsigned int temp; temp=pc; pc=pr; delay_slot(temp+2); } rev. 5.0, 04/01, page 340 of 394 example mov.l table,r3 ; r3 = trget address jsr @r3 ; branch to trget. nop ; nop executed before branch. add r0,r1 ; subroutine procedure return destination (pr contents) ........ table: .data.l trget ; jump table ........ trget: mov r1,r0 ; entry to procedure rts ; pr contents pc mov #12,r0 ; mov executed before branch. rev. 5.0, 04/01, page 341 of 394 9.81 sets set s bit system control instruction s bit setting format summary of operation instruction code execution states t bit sets 1 s 0000000001011000 1? description this instruction sets the s bit to 1. operation sets( ) /* sets */ { s=1; pc+=2; } example sets ; before execution s = 0 ; after execution s = 1 rev. 5.0, 04/01, page 342 of 394 9.82 sett set t bit system control instruction t bit setting format summary of operation instruction code execution states t bit sett 1 t 0000000000011000 11 description this instruction sets the t bit to 1. operation sett( ) /* sett */ { t=1; pc+=2; } example sett ; before execution t = 0 ; after execution t = 1 rev. 5.0, 04/01, page 343 of 394 9.83 shad shift arithmetic dynamically shift instruction dynamic arithmetic shift format summary of operation instruction code execution states t bit shad rm, rn when rm 0, rn << rm rn when rm < 0, rn >> rm [msb rn] 0100nnnnmmmm1100 1? description this instruction arithmetically shifts the contents of general register rn. general register rm specifies the shift direction and the number of bits to be shifted. rn register contents are shifted to the left if the rm register value is positive, and to the right if negative. in a shift to the right, the msb is added at the upper end. the number of bits to be shifted is specified by the lower 5 bits (bits 4 to 0) of the rm register. if the value is negative (msb = 1), the rm register is represented as a two?s complement. the left shift range is 0 to 31, and the right shift range, 1 to 32. msb lsb msb msb lsb 0 rm 0 rm 0 rev. 5.0, 04/01, page 344 of 394 operation shad(int m,n) /*shad rm,rn */ { int sgn=r[m] & 0x80000000; if (sgn==0) r[n] <<= (r[m] & 0x1f); else if ((r[m] & 0x1f) == 0) { if ((r[n] & 0x80000000) == 0) r[n] = 0; else r[n] = 0xffffffff; } else r[n]=(long)r[n] >> ((~r[m] & 0x1f)+1); pc+=2; } example shad r1,r2 ; before execution r1 = h'ffffffec, r2 = h'80180000 ; after execution r1 = h'ffffffec, r2 = h'fffff801 shad r3,r4 ; before execution r3 = h'00000014, r4 = h'fffff801 ; after execution r3 = h'00000014, r4 = h'80100000 rev. 5.0, 04/01, page 345 of 394 9.84 shal shift arithmetic left shift instruction one-bit left arithmetic shift format summary of operation instruction code execution states t bit shal rn t rn 0 0100nnnn00100000 1msb description this instruction arithmetically shifts the contents of general register rn one bit to the left, and stores the result in rn. the bit shifted out of the operand is transferred to the t bit. msb lsb shal t0 operation shal(long n) /* shal rn (same as shll) */ { if ((r[n]&0x80000000)==0) t=0; else t=1; r[n]<<=1; pc+=2; } example shal r0 ; before execution r0 = h'80000001, t = 0 ; after execution r0 = h'00000002, t = 1 rev. 5.0, 04/01, page 346 of 394 9.85 shar shift arithmetic right shift instruction one-bit right arithmetic shift format summary of operation instruction code execution states t bit shar rn msb rn t 0100nnnn00100001 1lsb description this instruction arithmetically shifts the contents of general register rn one bit to the right, and stores the result in rn. the bit shifted out of the operand is transferred to the t bit. msb lsb shar t operation shar(long n) /* shar rn */ { long temp; if ((r[n]&0x00000001)==0) t=0; else t=1; if ((r[n]&0x80000000)==0) temp=0; else temp=1; r[n]>>=1; if (temp==1) r[n]|=0x80000000; else r[n]&=0x7fffffff; pc+=2; } example shar r0 ; before execution r0 = h'80000001, t = 0 ; after execution r0 = h'c0000000, t = 1 rev. 5.0, 04/01, page 347 of 394 9.86 shld shift logical dynamically shift instruction dynamic logical shift format summary of operation instruction code execution states t bit shld rm, rn when rm 0, rn << rm rn when rm < 0, rn >> rm [0 rn] 0100nnnnmmmm1101 1? description this instruction logically shifts the contents of general register rn. general register rm specifies the shift direction and the number of bits to be shifted. rn register contents are shifted to the left if the rm register value is positive, and to the right if negative. in a shift to the right, 0s are added at the upper end. the number of bits to be shifted is specified by the lower 5 bits (bits 4 to 0) of the rm register. if the value is negative (msb = 1), the rm register is represented as a two?s complement. the left shift range is 0 to 31, and the right shift range, 1 to 32. msb lsb msb 0 lsb 0 rm 0 rm 0 rev. 5.0, 04/01, page 348 of 394 operation shld(int m,n)/*shld rm,rn */ { int sgn = r[m] & 0x80000000; if (sgn == 0) r[n] <<= (r[m] & 0x1f); else if ((r[m] & 0x1f) == 0) r[n] = 0; else r[n]=(unsigned)r[n] >> ((~r[m] & 0x1f)+1); pc+=2; } example shld r1, r2 ; before execution r1 = h'ffffffec, r2 = h'80180000 ; after execution r1 = h'ffffffec, r2 = h'00000801 shld r3, r4 ; before execution r3 = h'00000014, r4 = h'fffff801 ; after execution r3 = h'00000014, r4 = h'80100000 rev. 5.0, 04/01, page 349 of 394 9.87 shll shift logical left shift instruction one-bit left logical shift format summary of operation instruction code execution states t bit shll rn t rn 0 0100nnnn00000000 1msb description this instruction logically shifts the contents of general register rn one bit to the left, and stores the result in rn. the bit shifted out of the operand is transferred to the t bit. msb lsb 0 shll t operation shll(long n) /* shll rn (same as shal) */ { if ((r[n]&0x80000000)==0) t=0; else t=1; r[n]<<=1; pc+=2; } example shll r0 ; before execution r0 = h'80000001, t = 0 ; after execution r0 = h'00000002, t = 1 rev. 5.0, 04/01, page 350 of 394 9.88 shlln n bits shift logical left shift instruction n-bit left logical shift format summary of operation instruction code execution states t bit shll2 rn rn<<2 rn 0100nnnn00001000 1? shll8 rn rn<<8 rn 0100nnnn00011000 1? shll16 rn rn<<16 rn 0100nnnn00101000 1? description this instruction logically shifts the contents of general register rn 2, 8, or 16 bits to the left, and stores the result in rn. the bits shifted out of the operand are discarded. msb lsb 0 shll8 shll16 msb lsb 0 msb lsb 0 shll2 rev. 5.0, 04/01, page 351 of 394 operation shll2(long n) /* shll2 rn */ { r[n]<<=2; pc+=2; } shll8(long n) /* shll8 rn */ { r[n]<<=8; pc+=2; } shll16(long n) /* shll16 rn */ { r[n]<<=16; pc+=2; } example shll2 r0 ; before execution r0 = h'12345678 ; after execution r0 = h'48d159e0 shll8 r0 ; before execution r0 = h'12345678 ; after execution r0 = h'34567800 shll16 r0 ; before execution r0 = h'12345678 ; after execution r0 = h'56780000 rev. 5.0, 04/01, page 352 of 394 9.89 shlr shift logical right shift instruction one-bit right logical shift format summary of operation instruction code execution states t bit shlr rn 0 rn t 0100nnnn00000001 1lsb description this instruction logically shifts the contents of general register rn one bit to the right, and stores the result in rn. the bit shifted out of the operand is transferred to the t bit. msb lsb shlr t 0 operation shlr(long n) /* shlr rn */ { if ((r[n]&0x00000001)==0) t=0; else t=1; r[n]>>=1; r[n]&=0x7fffffff; pc+=2; } example shlr r0 ; before execution r0 = h'80000001, t = 0 ; after execution r0 = h'40000000, t = 1 rev. 5.0, 04/01, page 353 of 394 9.90 shlrn n bits shift logical right shift instruction n-bit right logical shift format summary of operation instruction code execution states t bit shlr2 rn rn>>2 rn 0100nnnn00001001 1? shlr8 rn rn>>8 rn 0100nnnn00011001 1? shlr16 rn rn>>16 rn 0100nnnn00101001 1? description this instruction logically shifts the contents of general register rn 2, 8, or 16 bits to the right, and stores the result in rn. the bits shifted out of the operand are discarded. msb lsb 0 shlr8 shlr16 msb lsb 0 msb lsb 0 shlr2 rev. 5.0, 04/01, page 354 of 394 operation shlr2(long n) /* shlr2 rn */ { r[n]>>=2; r[n]&=0x3fffffff; pc+=2; } shlr8(long n) /* shlr8 rn */ { r[n]>>=8; r[n]&=0x00ffffff; pc+=2; } shlr16(long n) /* shlr16 rn */ { r[n]>>=16; r[n]&=0x0000ffff; pc+=2; } example shlr2 r0 ; before execution r0 = h'12345678 ; after execution r0 = h'048d159e shlr8 r0 ; before execution r0 = h'12345678 ; after execution r0 = h'00123456 shlr16 r0 ; before execution r0 = h'12345678 ; after execution r0 = h'00001234 rev. 5.0, 04/01, page 355 of 394 9.91 sleep sleep system control instruction transition to power-down mode (privileged instruction) format summary of operation instruction code execution states t bit sleep sleep 0000000000011011 4? description this instruction places the cpu in the power-down state. in power-down mode, the cpu retains its internal state, but immediately stops executing instructions and waits for an interrupt request. when it receives an interrupt request, the cpu exits the power-down state. sleep is a privileged instruction, and can only be used in privileged mode. use of this instruction in user mode will cause an illegal instruction exception. notes sleep performance depends on the standby control register (stbcr). see power-down modes in hardware manual, for details. operation sleep( ) /* sleep */ { sleep_standby(); } example sleep ; transition to power-down mode rev. 5.0, 04/01, page 356 of 394 9.92 stc store control register system control instruction store from control register (privileged instruction) format summary of operation instruction code execution states t bit stc sr, rn sr rn 0000nnnn00000010 2? stc gbr, rn gbr rn 0000nnnn00010010 2? stc vbr, rn vbr rn 0000nnnn00100010 2? stc ssr , rn ssr rn 0000nnnn00110010 2? stc spc, rn spc rn 0000nnnn01000010 2? stc sgr, rn sgr rn 0000nnnn00111010 3? stc dbr , rn dbr rn 0000nnnn11111010 2? stc r0_bank, rn r0_bank rn 0000nnnn10000010 2? stc r1_bank, rn r1_bank rn 0000nnnn10010010 2? stc r2_bank, rn r2_bank rn 0000nnnn10100010 2? stc r3_bank, rn r3_bank rn 0000nnnn10110010 2? stc r4_bank, rn r4_bank rn 0000nnnn11000010 2? stc r5_bank, rn r5_bank rn 0000nnnn11010010 2? stc r6_bank, rn r6_bank rn 0000nnnn11100010 2? stc r7_bank, rn r7_bank rn 0000nnnn11110010 2? stc.l sr, @-rn rn-4 rn, sr (rn) 0100nnnn00000011 2? stc.l gbr, @-rn rn-4 rn, gbr (rn) 0100nnnn00010011 2? stc.l vbr, @-rn rn-4 rn, vbr (rn) 0100nnnn00100011 2? stc.l ssr, @-rn rn-4 rn, ssr (rn) 0100nnnn00110011 2? stc.l spc, @-rn rn-4 rn, spc (rn) 0100nnnn01000011 2? stc.l sgr, @-rn rn-4 rn, sgr (rn) 0100nnnn00110010 3? stc.l dbr, @-rn rn-4 rn, dbr (rn) 0100nnnn11110010 2? stc.l r0_bank, @-rn rn-4 rn, r0_bank (rn) 0100nnnn10000011 2? stc.l r1_bank, @-rn rn-4 rn, r1_bank (rn) 0100nnnn10010011 2? stc.l r2_bank, @-rn rn-4 rn, r2_bank (rn) 0100nnnn10100011 2? stc.l r3_bank, @-rn rn-4 rn, r3_bank (rn) 0100nnnn10110011 2? stc.l r4_bank, @-rn rn-4 rn, r4_bank (rn) 0100nnnn11000011 2? stc.l r5_bank, @-rn rn-4 rn, r5_bank (rn) 0100nnnn11010011 2? stc.l r6_bank, @-rn rn-4 rn, r6_bank (rn) 0100nnnn11100011 2? stc.l r7_bank, @-rn rn-4 rn, r7_bank (rn) 0100nnnn11110011 2? rev. 5.0, 04/01, page 357 of 394 description this instruction stores control register sr, gbr, vbr, ssr, spc, sgr, dbr or rm_bank (m = 0?7) in the destination. rm_bank operands are specified by the rb bit of the sr register: when the rb bit is 1 rm_bank0 is accessed, when the rb bit is 0 rm_bank1 is accessed. notes stc/stc.l can only be used in privileged mode excepting stc gbr, rn/stc.l gbr, @-rn. use of these instructions in user mode will cause illegal instruction exceptions. operation stcsr(int n) /* stc sr,rn : privileged */ { r[n]=sr; pc+=2; } stcgbr(int n) /* stc gbr,rn */ { r[n]=sgr; pc+=2; } stcvbr(int n) /* stc vbr,rn : privileged */ { r[n]=vbr; pc+=2; } stcssr(int n) /* stc ssr,rn : privileged */ { r[n]=ssr; pc+=2; } rev. 5.0, 04/01, page 358 of 394 stcspc(int n) /* stc spc,rn : privileged */ { r[n]=spc; pc+=2; } stcsgr(int n) /* stc sgr,rn : privileged */ { r[n]=sgr; pc+=2; } stcdbr(int n) /* stc dbr,rn : privileged */ { r[n]=dbr; pc+=2; } stcrm_bank(int n) /* stc rm_bank,rn : privileged */ /* m=0?7 */ { r[n]=rm_bank; pc+=2; } stcmsr(int n) /* stc.l sr,@-rn : privileged */ { r[n]?=4; write_long(r[n],sr); pc+=2; } stcmgbr(int n) /* stc.l gbr,@?rn */ { r[n]?=4; write_long(r[n],gbr); pc+=2; rev. 5.0, 04/01, page 359 of 394 } stcmvbr(int n) /* stc.l vbr,@-rn : privileged */ { r[n]?=4; write_long(r[n],vbr); pc+=2; } stcmssr(int n) /* stc.l ssr,@-rn : privileged */ { r[n]?=4; write_long(r[n],ssr); pc+=2; } stcmspc(int n) /* stc.l spc,@-rn : privileged */ { r[n]?=4; write_long(r[n],spc); pc+=2; } stcmsgr(int n) /* stc.l sgr,@-rn : privileged */ { r[n]?=4; write_long(r[n],sgr); pc+=2; } stcmdbr(int n) /* stc.l dbr,@-rn : privileged */ { r[n]?=4; write_long(r[n],dbr); pc+=2; } rev. 5.0, 04/01, page 360 of 394 stcmrm_bank(int n) /* stc.l rm_bank,@-rn : privileged */ /* m=0?7 */ { r[n]?=4; write_long(r[n],rm_bank); pc+=2; } possible exceptions: ? general illegal instruction exception ? slot illegal instruction exception ? data tlb miss exception ? data tlb protection violation exception ? address error rev. 5.0, 04/01, page 361 of 394 9.93 sts store system register system control instruction store from system register format summary of operation instruction code execution states t bit sts mach,rn mach rn 0000nnnn00001010 1? sts macl,rn macl rn 0000nnnn00011010 1? sts pr,rn pr rn 0000nnnn00101010 1? sts.l mach,@-rn rn-4 rn, mach (rn) 0100nnnn00000010 1? sts.l macl,@-rn rn-4 rn, macl (rn) 0100nnnn00010010 1? sts.l pr,@-rn rn-4 rn, pr (rn) 0100nnnn00100010 1? description this instruction stores system register mach, macl, or pr in the destination. operation stsmach(int n) /* sts mach,rn */ { r[n]=mach; pc+=2; } stsmacl(int n) /* sts macl,rn */ { r[n]=macl; pc+=2; } stspr(int n) /* sts pr,rn */ { r[n]=pr; pc+=2; } stsmmach(int n) /* sts.l mach,@-rn */ { rev. 5.0, 04/01, page 362 of 394 r[n]?=4; write_long(r[n],mach); pc+=2; } stsmmacl(int n) /* sts.l macl,@-rn */ { r[n]?=4; write_long(r[n],macl); pc+=2; } stsmpr(int n) /* sts.l pr,@-rn */ { r[n]?=4; write_long(r[n],pr); pc+=2; } possible exceptions: ? data tlb miss exception ? data tlb protection violation exception ? address error example sts mach,r0 ; before execution r0 = h'ffffffff, mach = h'00000000 ; after execution r0 = h'00000000 sts.l pr,@-r15 ; before execution r15 = h'10000004 ; after execution r15 = h'10000000, (r15) = pr rev. 5.0, 04/01, page 363 of 394 9.94 sts store from fpu system register system control instruction store from fpu system register format summary of operation instruction code execution states t bit sts fpul,rn fpul rn 0000nnnn01011010 1? sts fpscr,rn fpscr rn 0000nnnn01101010 1? sts.l fpul,@-rn rn-4 rn, fpul (rn) 0100nnnn01010010 1? sts.l fpscr,@-rn rn-4 rn, fpscr (rn) 0100nnnn01100010 1? description this instruction stores fpu system register fpul or fpscr in the destination. operation sts(int n, int *fpul) /* sts fpul,rn */ { r[n]= *fpul; pc+=2; } sts_save(int n, int *fpul) /* sts.l fpul,@-rn */ { r[n]-=4; write_long(r[n],*fpul) ; pc+=2; } sts(int n) /* sts fpscr,rn */ { r[n]=fpscr&0x003fffff; pc+=2; } sts_restore(int n) /* sts.l fpscr,@-rn */ { r[n]-=4; write_long(r[n],fpscr&0x003fffff) rev. 5.0, 04/01, page 364 of 394 pc+=2; } possible exceptions: ? data tlb miss exception ? data tlb protection violation exception ? address error example s ? sts example 1: mov.l #h'12abcdef, r12 lds r12, fpul sts fpul, r13 ; after executing the sts instruction: ; r13 = 12abcdef example 2: sts fpscr, r2 ; after executing the sts instruction: ; the current content of fpscr is stored in register r2 ? sts.l example 1: mov.l #h'0c700148, r7 sts.l fpul, @-r7 ; before executing the sts.l instruction: ; r7 = 0c700148 ; after executing the sts.l instruction: ; r7 = 0c700144, and the content of fpul is saved at memory ; locatio\n 0c700144. example 2: mov.l #h'0c700154, r8 sts.l fpscr, @-r8 ; after executing the sts.l instruction: ; the content of fpscr is saved at memory location 0c700150. rev. 5.0, 04/01, page 365 of 394 9.95 sub subtract binary arithmetic instruction binary subtraction format summary of operation instruction code execution states t bit sub rm,rn rn-rm rn 0011nnnnmmmm1000 1? description this instruction subtracts the contents of general register rm from the contents of general register rn and stores the result in rn. for immediate data subtraction, add #imm,rn should be used. operation sub(long m, long n) /* sub rm,rn */ { r[n]-=r[m]; pc+=2; } example sub r0,r1 ; before execution r0 = h'00000001, r1 = h'80000000 ; after execution r1 = h'7fffffff rev. 5.0, 04/01, page 366 of 394 9.96 subc subtract with carry arithmetic instruction binary subtraction with borrow format summary of operation instruction code execution states t bit subc rm,rn rn-rm-t rn, borrow t 0011nnnnmmmm1010 1 borrow description this instruction subtracts the contents of general register rm and the t bit from the contents of general register rn, and stores the result in rn. a borrow resulting from the operation is reflected in the t bit. this instruction is used for subtractions exceeding 32 bits. operation subc(long m, long n) /* subc rm,rn */ { unsigned long tmp0,tmp1; tmp1=r[n]-r[m]; tmp0=r[n]; r[n]=tmp1-t; if (tmp0 rev. 5.0, 04/01, page 368 of 394 example subv r0,r1 ; before execution r0 = h'00000002, r1 = h'80000001 ; after execution r1 = h'7fffffff, t = 1 subv r2,r3 ; before execution r2 = h'fffffffe, r3 = h'7ffffffe ; after execution r3 = h'80000000, t = 1 rev. 5.0, 04/01, page 369 of 394 9.98 swap swap register halves data transfer instruction upper-/lower-half swap format summary of operation instruction code execution states t bit swap.b rm,rn rm lower-2-byte upper-/ lower-byte swap rn 0110nnnnmmmm1000 1? swap.w rm,rn rm upper-/lower-word swap rn 0110nnnnmmmm1001 1 description this instruction swaps the upper and lower parts of the contents of general register rm, and stores the result in rn. in the case of a byte specification, the 8 bits from bit 15 to bit 8 of rm are swapped with the 8 bits from bit 7 to bit 0. the upper 16 bits of rm are transferred directly to the upper 16 bits of rn. in the case of a word specification, the 16 bits from bit 31 to bit 16 of rm are swapped with the 16 bits from bit 15 to bit 0. operation swapb(long m, long n) /* swap.b rm,rn */ { unsigned long temp0,temp1; temp0=r[m]&0xffff0000; temp1=(r[m]&0x000000ff)<<8; r[n]=(r[m]&0x0000ff00)>>8; r[n]=r[n]|temp1|temp0; pc+=2; } swapw(long m, long n) /* swap.w rm,rn */ { unsigned long temp; temp=(r[m]>>16)&0x0000ffff; r[n]=r[m]<<16; rev. 5.0, 04/01, page 370 of 394 r[n]|=temp; pc+=2; } example swap.b r0,r1 ; before execution r0 = h'12345678 ; after execution r1 = h'12347856 swap.w r0,r1 ; before execution r0 = h'12345678 ; after execution r1 = h'56781234 rev. 5.0, 04/01, page 371 of 394 9.99 tas test and set logical instruction memory test and bit setting format summary of operation instruction code execution states t bit tas.b @rn if (rn) = 0, 1 t, else 0 t 1 msb of (rn) 0100nnnn00011011 5test result description this instruction purges the cache block corresponding to the memory area specified by the contents of general register rn, reads the byte data indicated by that address, and sets the t bit to 1 if that data is zero, or clears the t bit to 0 if the data is nonzero. the instruction then sets bit 7 to 1 and writes to the same address. the bus is not released during this period. the purge operation is executed as follows. in a purge operation, data is accessed using the contents of general register rn as the effective address. if there is a cache hit and the corresponding cache block is dirty (u bit = 1), the contents of that cache block are written back to external memory, and the cache block is then invalidated (by clearing the v bit to 0). if there is a cache hit and the corresponding cache block is clean (u bit = 0), the cache block is simply invalidated (by clearing the v bit to 0). a purge is not executed in the event of a cache miss, or if the accessed memory location is non-cacheable. the two tas.b memory accesses are executed automatically. another memory access is not executed between the two tas.b accesses. operation tas(int n) /* tas.b @rn */ { int temp; temp=(int)read_byte(r[n]); /* bus lock */ if (temp==0) t=1; else t=0; temp|=0x00000080; write_byte(r[n],temp); /* bus unlock */ pc+=2; } rev. 5.0, 04/01, page 372 of 394 possible exceptions: ? data tlb miss exception ? data tlb protection violation exception ? initial page write exception ? address error exceptions are checked taking a data access by this instruction as a byte store. rev. 5.0, 04/01, page 373 of 394 9.100 trapa trap always system control instruction trap exception handling format summary of operation instruction code execution states t bit trapa #imm imm tra, pc+2 spc, sr ssr, r15 sgr, 1 sr.md/bl/rb, 0x160 expevt, vbr+h'00000100 pc 11000011iiiiiiii 7? description this instruction starts trap exception handling. the values of (pc + 2), sr, and r15 are saved to spc and ssr, and 8-bit immediate data is stored in the tra register (bits 9 to 2). the processor mode is switched to privileged mode (the md bit in sr is set to 1), and the bl bit and rb bit in sr are set to 1. as a result, exception and interrupt requests are masked (not accepted), and the bank1 registers (r0_bank1 to r7_bank1) are selected. exception code 0x160 is written to the expevt register (bits 11 to 0). the program branches to address (vbr + h'00000100), indicated by the sum of the vbr register contents and offset h'00000100. operation trapa(int i) /* trapa #imm */ { int imm; imm=(0x000000ff & i); tra=imm<<2; ssr=sr; spc=pc+2; sgr=r15; sr.md=1; sr.bl=1; sr.rb=1; expevt=0x00000160; pc=vbr+h'00000100; } rev. 5.0, 04/01, page 374 of 394 9.101 tst test logical logical instruction and operation t bit setting format summary of operation instruction code execution states t bit tst rm,rn rn & rm; if result is 0, 1 t, else 0 t 0010nnnnmmmm1000 1test result tst #imm,r0 r0 & imm; if result is 0, 1 t, else 0 t 11001000iiiiiiii 1test result tst.b #imm,@(r0,gbr) (r0 + gbr) & imm; if result is 0, 1 t, else 0 t 11001100iiiiiiii 3test result description this instruction ands the contents of general registers rn and rm, and sets the t bit if the result is zero. if the result is nonzero, the t bit is cleared. the contents of rn are not changed. this instruction can be used to and general register r0 contents with zero-extended 8-bit immediate data, or, in indexed gbr indirect addressing mode, to and 8-bit memory with 8-bit immediate data. the contents of r0 or the memory are not changed. operation tst(long m, long n) /* tst rm,rn */ { if ((r[n]&r[m])==0) t=1; else t=0; pc+=2; } tsti(long i) /* tst #imm,r0 */ { long temp; temp=r[0]&(0x000000ff & (long)i); if (temp==0) t=1; else t=0; pc+=2; } rev. 5.0, 04/01, page 375 of 394 tstm(long i) /* tst.b #imm,@(r0,gbr) */ { long temp; temp=(long)read_byte(gbr+r[0]); temp&=(0x000000ff & (long)i); if (temp==0) t=1; else t=0; pc+=2; } example tst r0,r0 ; before execution r0 = h'00000000 ; after execution t = 1 tst #h'80,r0 ; before execution r0 = h'ffffff7f ; after execution t = 1 tst.b #h'a5,@(r0,gbr) ; before execution (r0,gbr) = h'a5 ; after execution t = 0 rev. 5.0, 04/01, page 376 of 394 9.102 xor exclusive or logical logical instruction exclusive logical or format summary of operation instruction code execution states t bit xor rm,rn rn ^ rm rn 0010nnnnmmmm1010 1? xor #imm,r0 r0 ^ imm r0 11001010iiiiiiii 1? xor.b #imm,@(r0,gbr) (r0+gbr)^imm (r0+gbr) 11001110iiiiiiii 4? description this instruction exclusively ors the contents of general registers rn and rm, and stores the result in rn. this instruction can be used to exclusively or register r0 contents with zero-extended 8-bit immediate data, or, in indexed gbr indirect addressing mode, to exclusively or 8-bit memory with 8-bit immediate data. operation xor(long m, long n) /* xor rm,rn */ { r[n]^=r[m]; pc+=2; } xori(long i) /* xor #imm,r0 */ { r[0]^=(0x000000ff & (long)i); pc+=2; } xorm(long i) /* xor.b #imm,@(r0,gbr) */ { int temp; temp=(long)read_byte(gbr+r[0]); temp^=(0x000000ff &(long)i); rev. 5.0, 04/01, page 377 of 394 write_byte(gbr+r[0],temp); pc+=2; } example xor r0,r1 ; before execution r0 = h'aaaaaaaa, r1 = h'55555555 ; after execution r1 = h'ffffffff xor #h'f0,r0 ; before execution r0 = h'ffffffff ; after execution r0 = h'ffffff0f xor.b #h'a5,@(r0,gbr) ; before execution (r0,gbr) = h'a5 ; after execution (r0,gbr) = h'00 rev. 5.0, 04/01, page 378 of 394 9.103 xtrct extract data transfer instruction middle extraction from linked registers format summary of operation instruction code execution states t bit xtrct rm,rn middle 32 bits of rm:rn rn 0010nnnnmmmm1101 1? description this instruction extracts the middle 32 bits from the 64-bit contents of linked general registers rm and rn, and stores the result in rn. msb rn rm rn lsb msb lsb operation xtrct(long m, long n) /* xtrct rm,rn */ { unsigned long temp; temp=(r[m]<<16)&0xffff0000; r[n]=(r[n]>>16)&0x0000ffff; r[n]|=temp; pc+=2; } example xtrct r0,r1 ; before execution r0 = h'01234567, r1 = h'89abcdef ; after execution r1 = h'456789ab rev. 5.0, 04/01, page 379 of 394 appendix a instruction codes a.1 instruction set by addressing mode table a.1 instruction set by addressing mode addressing mode category sample instruction type no operand ? nop 13 destination operand only movt rn 24 source and destination operands add rm,rn 56 transfer to control register or system register ldc rm,sr 16 register direct transfer from control register or system register sts mach,rn 17 destination operand only jmp @rn 7 register indirect register direct data transfer mov.l rm,@rn 13 multiply-and-accumulate operation mac.w @rm+,@rn+ 2 direct data transfer from register mov.l @rm+,rn 6 register indirect with post-increment load to control register or system register ldc.l @rm+sr 12 direct data transfer from register mov.l rm,@-rn 6 register indirect with pre-decrement store from control register or system register stc.l sr,@-rn 13 register indirect with displacement register direct data transfer mov.l rm,@(disp,rn) 6 indexed register indirect register direct data transfer mov.l rm,@(r0,rn) 12 gbr indirect with displacement register direct data transfer mov.l r0,@(disp,gbr) 6 indexed gbr indirect immediate data transfer and.b #imm,@(r0,gbr) 4 pc relative with displacement direct data transfer to register mov.l @(disp,pc),rn 3 pc relative using rn branch instruction braf rn 2 pc relative branch instruction bra label 6 rev. 5.0, 04/01, page 380 of 394 table a.1 instruction set by addressing mode (cont) addressing mode category sample instruction type load to register fldi0 frn 2 register direct arithmetic/logic operation add #imm,rn 7 immediate exception vector specification trapa #imm 1 total 234 (1) no operand table a.2 no operand instruction operation instruction code privileged t bit div0u 0 m/q/t 0000000000011001 ?0 rts delayed branch, pr pc 0000000000001011 ?? clrmac 0 mach, macl 0000000000101000 ?? clrs 0 s 0000000001001000 ?? clrt 0 t 0000000000001000 ?0 ldtlb pteh/ptel tlb 0000000000111000 privileged ? nop no operation 0000000000001001 ?? rte delayed branch, ssr/spc sr/pc 0000000000101011 privileged ? sets 1 s 0000000001011000 ?? sett 1 t 0000000000011000 ?1 sleep sleep or standby 0000000000011011 privileged ? frchg ~fpscr.fr fpscr.fr 1111101111111101 ?? fschg ~fpscr.sz fpscr.sz 1111001111111101 ?? rev. 5.0, 04/01, page 381 of 394 (2) register direct table a.3 destination operand only instruction operation instruction code privileged t bit movt rn t rn 0000nnnn00101001 ?? cmp/pz rn when rn 0, 1 t otherwise, 0 t 0100nnnn00010001 ? comparison result cmp/pl rn when rn > 0, 1 t otherwise, 0 t 0100nnnn00010101 ? comparison result dt rn rn ? 1 rn; when rn = 0, 1 t when rn 0, 0 t 0100nnnn00010000 ? comparison result rotl rn t rn msb 0100nnnn00000100 ?msb rotr rn lsb rn t 0100nnnn00000101 ?lsb rotcl rn t rn t 0100nnnn00100100 ?msb rotcr rn t rn t 0100nnnn00100101 ?lsb shal rn t rn 0 0100nnnn00100000 ?msb shar rn msb rn t 0100nnnn00100001 ?lsb shll rn t rn 0 0100nnnn00000000 ?msb shlr rn 0 rn t 0100nnnn00000001 ?lsb shll2 rn rn << 2 rn 0100nnnn00001000 ?? shlr2 rn rn >> 2 rn 0100nnnn00001001 ?? shll8 rn rn << 8 rn 0100nnnn00011000 ?? shlr8 rn rn >> 8 rn 0100nnnn00011001 ?? shll16 rn rn << 16 rn 0100nnnn00101000 ?? shlr16 rn rn >> 16 rn 0100nnnn00101001 ?? fabs frn frn & h'7fff ffff frn 1111nnnn01011101 ?? fneg frn frn h'80000000 frn 1111nnnn01001101 ?? fsqrt frn frn frn 1111nnnn01101101 ?? fabs drn drn & h'7fff ffff ffff ffff drn 1111nnn001011101 ?? fneg drn drn ^ h'8000 0000 0000 0000 drn 1111nnn001001101 ?? fsqrt drn drn drn 1111nnn001101101 ?? rev. 5.0, 04/01, page 382 of 394 table a.4 source and destination operands instruction operation instruction code privileged t bit mov rm,rn rm rn 0110nnnnmmmm0011 ?? swap.b rm,rn rm swap lower 2 bytes rn 0110nnnnmmmm1000 ?? swap.w rm,rn rm swap upper/lower words rn 0110nnnnmmmm1001 ?? xtrct rm,rn rm:rn middle 32 bits rn 0010nnnnmmmm1101 ?? add rm,rn rn + rm rn 0011nnnnmmmm1100 ?? addc rm,rn rn + rm + t rn, carry t 0011nnnnmmmm1110 ? carry addv rm,rn rn + rm rn, overflow t 0011nnnnmmmm1111 ?overflow cmp/eq rm,rn when rn = rm, 1 t otherwise, 0 t 0011nnnnmmmm0000 ? comparison result cmp/hs rm,rn when rn rm (unsigned), 1 t otherwise, 0 t 0011nnnnmmmm0010 ? comparison result cmp/ge rm,rn when rn rm (signed), 1 t otherwise, 0 t 0011nnnnmmmm0011 ? comparison result cmp/hi rm,rn when rn > rm (unsigned), 1 t otherwise, 0 t 0011nnnnmmmm0110 ? comparison result cmp/gt rm,rn when rn > rm (signed), 1 t otherwise, 0 t 0011nnnnmmmm0111 ? comparison result cmp/str rm,rn when any bytes are equal, 1 t otherwise, 0 t 0010nnnnmmmm1100 ? comparison result div1 rm,rn 1-step division (rn rm) 0011nnnnmmmm0100 ? calculation result div0s rm,rn msb of rn q, msb of rm m, m^q t 0010nnnnmmmm0111 ? calculation result dmuls.l rm,rn signed, rn rm mac, 32 32 64 bits 0011nnnnmmmm1101 ?? dmulu.l rm,rn unsigned, rn rm mac, 32 32 64 bits 0011nnnnmmmm0101 ?? exts.b rm,rn rm sign-extended from byte rn 0110nnnnmmmm1110 ?? exts.w rm,rn rm sign-extended from word rn 0110nnnnmmmm1111 ?? extu.b rm,rn rm zero-extended from byte rn 0110nnnnmmmm1100 ?? extu.w rm,rn rm zero-extended from word rn 0110nnnnmmmm1101 ?? rev. 5.0, 04/01, page 383 of 394 table a.4 source and destination operands (cont) instruction operation instruction code privileged t bit mul.l rm,rn rn rm macl 32 32 32 bits 0000nnnnmmmm0111 ?? muls.w rm,rn signed, rn rm macl 16 16 32 bits 0010nnnnmmmm1111 ?? mulu.w rm,rn unsigned, rn rm macl 16 16 32 bits 0010nnnnmmmm1110 ?? neg rm,rn 0 ? rm rn 0110nnnnmmmm1011 ?? negc rm,rn 0 ? rm ? t rn, borrow t 0110nnnnmmmm1010 ? borrow sub rm,rn rn ? rm rn 0011nnnnmmmm1000 ?? subc rm,rn rn ? rm ? t rn, borrow t 0011nnnnmmmm1010 ? borrow subv rm,rn rn ? rm rn, underflow t 0011nnnnmmmm1011 ? underflow and rm,rn rn & rm rn 0010nnnnmmmm1001 ?? not rm,rn ~rm rn 0110nnnnmmmm0111 ?? or rm,rn rn | rm rn 0010nnnnmmmm1011 ?? tst rm,rn rn & rm; when result = 0, 1 t otherwise, 0 t 0010nnnnmmmm1000 ?test result xor rm,rn rn rm rn 0010nnnnmmmm1010 ?? shad rm,rn when rn 0, rn << rm rn when rn < 0, rn >> rm [msb rn] 0100nnnnmmmm1100 ?? shld rm,rn when rn 0, rn << rm rn when rn < 0, rn >> rm [0 rn] 0100nnnnmmmm1101 ?? fmov frm,frn frm frn 1111nnnnmmmm1100 ?? fmov drm,drn drm drn 1111nnn0mmm01100 ?? fadd frm,frn frn + frm frn 1111nnnnmmmm0000 ?? fcmp/eq frm,frn when frn = frm, 1 t otherwise, 0 t 1111nnnnmmmm0100 ? comparison result fcmp/gt frm,frn when frn > frm, 1 t otherwise, 0 t 1111nnnnmmmm0101 ? comparison result fdiv frm,frn frn/frm frn 1111nnnnmmmm0011 ?? fmac fr0,frm,frn fr0*frm + frn frn 1111nnnnmmmm1110 ?? fmul frm,frn frn*frm frn 1111nnnnmmmm0010 ?? fsub frm,frn frn ? frm frn 1111nnnnmmmm0001 ?? fadd drm,drn drn + drm drn 1111nnn0mmm00000 ?? fcmp/eq drm,drn when drn = drm, 1 t otherwise, 0 t 1111nnn0mmm00100 ? comparison result rev. 5.0, 04/01, page 384 of 394 table a.4 source and destination operands (cont) instruction operation instruction code privileged t bit fcmp/gt drm,drn when drn > drm, 1 t otherwise, 0 t 1111nnn0mmm00101 ? comparison result fdiv drm,drn drn /drm drn 1111nnn0mmm00011 ?? fmul drm,drn drn *drm drn 1111nnn0mmm00010 ?? fsub drm,drn drn ? drm drn 1111nnn0mmm00001 ?? fmov drm,xdn drm xdn 1111nnn1mmm01100 ?? fmov xdm,drn xdm drn 1111nnn0mmm11100 ?? fmov xdm,xdn xdm xdn 1111nnn1mmm11100 ?? fipr fvm,fvn inner_product [fvm, fvn] fr[n+3] 1111nnmm11101101 ?? ftrv xmtrx,fvn transform_vector [xmtrx, fvn] fvn 1111nn0111111101 ?? table a.5 transfer to control register or system register instruction operation instruction code privileged t bit ldc rm,sr rm sr 0100mmmm00001110 privileged lsb ldc rm,gbr rm gbr 0100mmmm00011110 ?? ldc rm,vbr rm vbr 0100mmmm00101110 privileged ? ldc rm,ssr rm ssr 0100mmmm00111110 privileged ? ldc rm,spc rm spc 0100mmmm01001110 privileged ? ldc rm,dbr rm dbr 0100mmmm11111010 privileged ? ldc rm,rn_bank rm rn_bank (n = 0 to 7) 0100mmmm1nnn1110 privileged ? lds rm,mach rm mach 0100mmmm00001010 ?? lds rm,macl rm macl 0100mmmm00011010 ?? lds rm,pr rm pr 0100mmmm00101010 ?? flds frm,fpul frm fpul 1111mmmm00011101 ?? ftrc frm,fpul (long) frm fpul 1111mmmm00111101 ?? fcnvds drm,fpul double_to_ float[drm] fpul 1111mmm010111101 ?? ftrc drm,fpul (long) drm fpul 1111mmm000111101 ?? lds rm,fpscr rm fpscr 0100mmmm01101010 ?? lds rm,fpul rm fpul 0100mmmm01011010 ?? rev. 5.0, 04/01, page 385 of 394 table a.6 transfer from control register or system register instruction operation instruction code privileged t bit stc sr,rn sr rn 0000nnnn00000010 privileged ? stc gbr,rn gbr rn 0000nnnn00010010 ?? stc vbr,rn vbr rn 0000nnnn00100010 privileged ? stc ssr,rn ssr rn 0000nnnn00110010 privileged ? stc spc,rn spc rn 0000nnnn01000010 privileged ? stc sgr,rn sgr rn 0000nnnn00111010 privileged ? stc dbr,rn dbr rn 0000nnnn11111010 privileged ? stc rm_bank,rn rm_bank rn (m = 0 to 7) 0000nnnn1mmm0010 privileged ? sts mach,rn mach rn 0000nnnn00001010 ?? sts macl,rn macl rn 0000nnnn00011010 ?? sts pr,rn pr rn 0000nnnn00101010 ?? fsts fpul,frn fpul frn 1111nnnn00001101 ?? float fpul,frn (float) fpul frn 1111nnnn00101101 ?? fcnvsd fpul,drn float_to_ double [fpul] drn 1111nnn010101101 ?? float fpul,drn (float)fpul drn 1111nnn000101101 ?? sts fpscr,rn fpscr rn 0000nnnn01101010 ?? sts fpul,rn fpul rn 0000nnnn01011010 ?? (3) register indirect table a.7 destination operand only instruction operation instruction code privileged t bit tas.b @rn when (rn) = 0, 1 t otherwise, 0 t in both cases, 1 msb of (rn) 0100nnnn00011011 ?test result jmp @rn delayed branch, rn pc 0100nnnn00101011 ?? jsr @rn delayed branch, pc + 4 pr, rn pc 0100nnnn00001011 ?? ocbi @rn invalidates operand cache block 0000nnnn10010011 ?? ocbp @rn writes back and invalidates operand cache block 0000nnnn10100011 ?? ocbwb @rn writes back operand cache block 0000nnnn10110011 ?? pref @rn (rn) operand cache 0000nnnn10000011 ?? rev. 5.0, 04/01, page 386 of 394 table a.8 register direct data transfer instruction operation instruction code privileged t bit mov.b rm,@rn rm (rn) 0010nnnnmmmm0000 ?? mov.w rm,@rn rm (rn) 0010nnnnmmmm0001 ?? mov.l rm,@rn rm (rn) 0010nnnnmmmm0010 ?? mov.b @rm,rn (rm) sign extension rn 0110nnnnmmmm0000 ?? mov.w @rm,rn (rm) sign extension rn 0110nnnnmmmm0001 ?? mov.l @rm,rn (rm) rn 0110nnnnmmmm0010 ?? movca.l r0,@rn r0 (rn) (without fetching cache block) 0000nnnn11000011 ?? fmov.s @rm,frn (rm) frn 1111nnnnmmmm1000 ?? fmov.s frm,@rn frm (rn) 1111nnnnmmmm1010 ?? fmov @rm,drn (rm) drn 1111nnn0mmmm1000 ?? fmov drm,@rn drm (rn) 1111nnnnmmm01010 ?? fmov @rm,xdn (rm) xdn 1111nnn1mmmm1000 ?? fmov xdm,@rn xdm (rn) 1111nnnnmmm11010 ?? (4) register indirect with post-increment table a.9 multiply-and-accumulate operation instruction operation instruction code privileged t bit mac.l @rm+,@rn+ signed, (rn) (rm) + mac mac rn + 4 rn, rm + 4 rm 32 32 + 64 64 bits 0000nnnnmmmm1111 ?? mac.w @rm+,@rn+ signed, (rn) (rm) + mac mac rn + 2 rn, rm + 2 rm 16 16 + 64 64 bits 0100nnnnmmmm1111 ?? table a.10 direct data transfer from register instruction operation instruction code privileged t bit mov.b @rm+,rn (rm) sign extension rn, rm + 1 rm 0110nnnnmmmm0100 ?? mov.w @rm+,rn (rm) sign extension rn, rm + 2 rm 0110nnnnmmmm0101 ?? mov.l @rm+,rn (rm) rn, rm + 4 rm 0110nnnnmmmm0110 ?? fmov.s @rm+,frn (rm) frn, rm + 4 rm 1111nnnnmmmm1001 ?? fmov @rm+,drn (rm) drn, rm + 8 rm 1111nnn0mmmm1001 ?? fmov @rm+,xdn (rm) xdn, rm + 8 rm 1111nnn1mmmm1001 ?? rev. 5.0, 04/01, page 387 of 394 table a.11 load to control register or system register instruction operation instruction code privileged t bit ldc.l @rm+,sr (rm) sr, rm + 4 rm 0100mmmm00000111 privileged lsb ldc.l @rm+,gbr (rm) gbr, rm + 4 rm 0100mmmm00010111 ?? ldc.l @rm+,vbr (rm) vbr, rm + 4 rm 0100mmmm00100111 privileged ? ldc.l @rm+,ssr (rm) ssr, rm + 4 rm 0100mmmm00110111 privileged ? ldc.l @rm+,spc (rm) spc, rm + 4 rm 0100mmmm01000111 privileged ? ldc.l @rm+,dbr (rm) dbr, rm + 4 rm 0100mmmm11110110 privileged ? ldc.l @rm+,rn_bank (rm) rn_bank, rm + 4 rm 0100mmmm1nnn0111 privileged ? lds.l @rm+,mach (rm) mach, rm + 4 rm 0100mmmm00000110 ?? lds.l @rm+,macl (rm) macl, rm + 4 rm 0100mmmm00010110 ?? lds.l @rm+,pr (rm) pr, rm + 4 rm 0100mmmm00100110 ?? lds.l @rm+,fpscr (rm) fpscr, rm+4 rm 0100mmmm01100110 ?? lds.l @rm+,fpul (rm) fpul, rm+4 rm 0100mmmm01010110 ?? (5) register indirect with pre-decrement table a.12 direct data transfer from register instruction operation instruction code privileged t bit mov.b rm,@-rn rn-1 rn, rm (rn) 0010nnnnmmmm0100 ?? mov.w rm,@-rn rn-2 rn, rm (rn) 0010nnnnmmmm0101 ?? mov.l rm,@-rn rn-4 rn, rm (rn) 0010nnnnmmmm0110 ?? fmov.s frm,@-rn rn-4 rn, frm (rn) 1111nnnnmmmm1011 ?? fmov drm,@-rn rn-8 rn, drm (rn) 1111nnnnmmm01011 ?? fmov xdm,@-rn rn ? 8 rn, xdm (rn) 1111nnnnmmm11011 ?? rev. 5.0, 04/01, page 388 of 394 table a.13 store from control register or system register instruc tion operation instruction code privileged t bit stc.l sr,@-rn rn ? 4 rn, sr (rn) 0100nnnn00000011 privileged ? stc.l gbr,@-rn rn ? 4 rn, gbr (rn) 0100nnnn00010011 ?? stc.l vbr,@-rn rn ? 4 rn, vbr (rn) 0100nnnn00100011 privileged ? stc.l ssr,@-rn rn ? 4 rn, ssr (rn) 0100nnnn00110011 privileged ? stc.l spc,@-rn rn ? 4 rn, spc (rn) 0100nnnn01000011 privileged ? stc.l sgr,@-rn rn ? 4 rn, sgr (rn) 0100nnnn00110010 privileged ? stc.l dbr,@-rn rn ? 4 rn, dbr (rn) 0100nnnn11110010 privileged ? stc.l rm_bank,@-rn rn ? 4 rn, rm_bank (rn) (m = 0 to 7) 0100nnnn1mmm0011 privileged ? sts.l mach,@-rn rn ? 4 rn, mach (rn) 0100nnnn00000010 ?? sts.l macl,@-rn rn ? 4 rn, macl (rn) 0100nnnn00010010 ?? sts.l pr,@-rn rn ? 4 rn, pr (rn) 0100nnnn00100010 ?? sts.l fpscr,@-rn rn ? 4 rn, fpscr (rn) 0100nnnn01100010 ?? sts.l fpul,@-rn rn ? 4 rn, fpul (rn) 0100nnnn01010010 ?? (6) register indirect with displacement table a.14 register direct data transfer instruction operation instruction code privileged t bit mov.b r0,@(disp,rn) r0 (disp + rn) 10000000nnnndddd ?? mov.w r0,@(disp,rn) r0 (disp 2 + rn) 10000001nnnndddd ?? mov.l rm,@(disp,rn) rm (disp 4 + rn) 0001nnnnmmmmdddd ?? mov.b @(disp,rm),r0 (disp + rm) sign extension r0 10000100mmmmdddd ?? mov.w @(disp,rm),r0 (disp 2 + rm) sign extension r0 10000101mmmmdddd ?? mov.l @(disp,rm),rn (disp 4 + rm) rn 0101nnnnmmmmdddd ?? rev. 5.0, 04/01, page 389 of 394 (7) indexed register indirect table a.15 register direct data transfer instruction operation instruction code privileged t bit mov.b rm,@(r0,rn) rm (r0 + rn) 0000nnnnmmmm0100 ?? mov.w rm,@(r0,rn) rm (r0 + rn) 0000nnnnmmmm0101 ?? mov.l rm,@(r0,rn) rm (r0 + rn) 0000nnnnmmmm0110 ?? mov.b @(r0,rm),rn (r0 + rm) sign extension rn 0000nnnnmmmm1100 ?? mov.w @(r0,rm),rn (r0 + rm) sign extension rn 0000nnnnmmmm1101 ?? mov.l @(r0,rm),rn (r0 + rm) rn 0000nnnnmmmm1110 ?? fmov.s @(r0,rm),frn (r0 + rm) frn 1111nnnnmmmm0110 ?? fmov.s frm,@(r0,rn) frm (r0 + rn) 1111nnnnmmmm0111 ?? fmov @(r0,rm),drn (r0 + rm) drn 1111nnn0mmmm0110 ?? fmov drm,@(r0,rn) drm (r0 + rn) 1111nnnnmmm00111 ?? fmov @(r0,rm),drn (r0 + rm) drn 1111nnn1mmmm0110 ?? fmov xdm,@(r0,rn) xdm (r0+rn) 1111nnnnmmm10111 ?? (8) gbr indirect with displacement table a.16 register direct data transfer instructi on operation instruction code privileged t bit mov.b r0,@(disp,gbr) r0 (disp + gbr) 11000000dddddddd ?? mov.w r0,@(disp,gbr) r0 (disp 2 + gbr) 11000001dddddddd ?? mov.l r0,@(disp,gbr) r0 (disp 4 + gbr) 11000010dddddddd ?? mov.b @(disp,gbr),r0 (disp + gbr) sign extension r0 11000100dddddddd ?? mov.w @(disp,gbr),r0 (disp 2 + gbr) sign extension r0 11000101dddddddd ?? mov.l @(disp,gbr),r0 (disp 4 + gbr) r0 11000110dddddddd ?? rev. 5.0, 04/01, page 390 of 394 (9) indexed gbr indirect table a.17 immediate data transfer instructi on operation instruction code privileged t bit and.b #imm,@(r0,gbr) (r0 + gbr) & imm (r0 + gbr) 11001101iiiiiiii ?? or.b #imm,@(r0,gbr) (r0 + gbr) | imm (r0 + gbr) 11001111iiiiiiii ? tst.b #imm,@(r0,gbr) (r0 + gbr) & imm; when result = 0, 1 t otherwise, 0 t 11001100iiiiiiii ?test result xor.b #imm,@(r0,gbr) (r0 + gbr) imm (r0 + gbr) 11001110iiiiiiii ?? (10) pc relative with displacement table a.18 direct data transfer to register instruction operation instruction code privileged t bit mov.w @(disp,pc),rn (disp 2 + pc + 4) sign extension rn 1001nnnndddddddd ?? mov.l @(disp,pc),rn (disp 4 + pc & h'fffffffc + 4) rn 1101nnnndddddddd ?? mova @(disp,pc),r0 disp 4 + pc & h'fffffffc + 4 r0 11000111dddddddd ?? (11) pc relative using rn table a.19 branch instructions instruction operation instruction code privileged t bit braf rn rn + pc + 4 pc 0000nnnn00100011 ?? bsrf rn delayed branch, pc + 4 pr, rn + pc + 4 pc 0000nnnn00000011 ?? rev. 5.0, 04/01, page 391 of 394 (12) pc relative table a.20 branch instructions instruction operation instruction code privileged t bit bf label when t = 0, disp 2 + pc + 4 pc when t = 1, nop 10001011dddddddd ?? bf/s label delayed branch; when t = 0, disp 2 + pc + 4 pc when t = 1, nop 10001111dddddddd ?? bt label when t = 1, disp 2 + pc + 4 pc when t = 0, nop 10001001dddddddd ?? bt/s label delayed branch; when t = 1, disp 2 + pc + 4 pc when t = 0, nop 10001101dddddddd ?? bra label delayed branch, disp 2 + pc + 4 pc 1010dddddddddddd ?? bsr label delayed branch, pc + 4 pr, disp 2 + pc + 4 pc 1011dddddddddddd ?? (13) immediate table a.21 load to register instruction operation instruction code privileged t bit fldi0 frn h'00000000 frn 1111nnnn10001101 ?? fldi1 frn h'3f800000 frn 1111nnnn10011101 ?? table a.22 register direct arithmetic/logic operation instruction operation instruction code privileged t bit mov #imm,rn imm sign extension rn 1110nnnniiiiiiii ?? add #imm,rn rn + imm rn 0111nnnniiiiiiii ?? cmp/eq #imm,r0 when r0 = imm, 1 t otherwise, 0 t 10001000iiiiiiii ? comparison result and #imm,r0 r0 & imm r0 11001001iiiiiiii ?? or #imm,r0 r0 | imm r0 11001011iiiiiiii ?? tst #imm,r0 r0 & imm; when result = 0, 1 t otherwise, 0 t 11001000iiiiiiii ?test result xor #imm,r0 r0 imm r0 11001010iiiiiiii ?? rev. 5.0, 04/01, page 392 of 394 table a.23 exception vector specification instruction operation instruction code privileged t bit trapa #imm pc + 2 spc, sr ssr, #imm << 2 tra, h'160 expevt, vbr + h'0100 pc 11000011iiiiiiii ?? rev. 5.0, 04/01, page 393 of 394 appendix b instruction prefetch side effects the sh-4 is provided with an internal buffer for holding pre-read instructions, and always performs pre-reading. therefore, program code must not be located in the last 20-byte area of any memory space. if program code is located in these areas, the memory area will be exceeded and a bus access for instruction pre-reading may be initiated. a case in which this is a problem is shown below. address h'03fffff8 h'03fffffa h'03fffffc h'03fffffe h'04000000 h'04000002 area 0 area 1 add r1,r4 jmp @r2 nop nop . . . . . pc (program counter) instruction prefetch address figure b.1 instruction prefetch figure b.1 presupposes a case in which the instruction (add) indicated by the program counter (pc) and the address h'0400002 instruction prefetch are executed simultaneously. it is also assumed that the program branches to an area outside area 1 after executing the following jmp instruction and delay slot instruction. in this case, the program flow is unpredictable, and a bus access (instruction prefetch) to area 1 may be initiated. instruction prefetch side effects 1. it is possible that an external bus access caused by an instruction prefetch may result in misoperation of an external device, such as a fifo, connected to the area concerned. 2. if there is no device to reply to an external bus request caused by an instruction prefetch, hangup will occur. remedies 1. these illegal instruction fetches can be avoided by using the mmu. 2. the problem can be avoided by not locating program code in the last 20 bytes of any area. rev. 5.0, 04/01, page 394 of 394 sh-4 programming manual publication date: 1st edition, august 1998 5th edition, april 2001 published by: customer service division semiconductor & integrated circuits hitachi, ltd. edited by: technical documentation group hitachi kodaira semiconductor co., ltd. copyright ? hitachi, ltd., 1998. all rights reserved. printed in japan. |
Price & Availability of HD6417750SV
![]() |
|
|
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] |