home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_03 / JAG_DOX.ZIP / risc_doc.txt < prev    next >
Text File  |  1996-01-28  |  30KB  |  990 lines

  1. # -------------------------------------------------------------------
  2. # GPU/DSP                                  (c) Copyright 1995 KKP & Nat!
  3. # -------------------------------------------------------------------
  4. # These are some of the results/guesses that Klaus and I (Nat!) found
  5. # out about the Jaguar with a few helpful hints by other people, 
  6. # who'd prefer to remain anonymous. 
  7. #
  8. # Since we are not under NDA or anything from Atari we feel free to 
  9. # give this to you for educational purposes only.
  10. #
  11. # Please note, that this is not official documentation from Atari
  12. # or derived work thereof (both of us have never seen the Atari docs)
  13. # and Atari isn't connected with this in any way.
  14. #
  15. # Please use this informationphile as a starting point for your own
  16. # exploration and not as a reference. If you find anything innacurate,
  17. # missing, needing more explanation etc. by all means please write
  18. # to us:
  19. #      nat@zumdick.rhein-main.de
  20. # or
  21. #      kkp@gamma.dou.dk
  22. #
  23. # If you could do us a small favor, don't use this information for
  24. # those lame flamewars on r.g.v.a or the mailing list.
  25. #
  26. # HTML soon ?
  27. # -------------------------------------------------------------------
  28. # $Id: risc_doc.txt,v 1.10 1996/01/28 20:35:56 nat Exp $                 
  29. # -------------------------------------------------------------------
  30.  
  31. This now contains lots of stuff, that are cryptic because I just
  32. incorporated third source knowledge. There's quite a bit I don't 
  33. understand yet :) [nat/1995]
  34. Please note the high bullshit content when it comes to the
  35. description of the pipeline business.
  36.  
  37.  
  38. 1 RISCy Business
  39. =-=-=-=-=-=-=-=-=
  40.  
  41. The RISC's has 2 register banks of 32 registers each. There are
  42. the Current and the Alternative register bank. Register R31 is the
  43. stack pointer and normally R0 is initilized to 0 (Zero).
  44.  
  45. G_FLAGS and D_FLAGS are the status register. The first 5 bits 
  46. contains the Carry, Zero and Minus flags (I THINK).
  47.  
  48.  
  49. GPU_FLAGS:
  50. =-=-=-=-=
  51.  
  52.  32       28        24        20       16       12        8        4        0
  53.   +--------^---------^---------^--------+---+----^------+-^--------+-+------+
  54. 1 |                unused               |aux| irq_pend  | irq_enab |m|flags |
  55.   +-------------------------------------+---+-----------+----------+-+------+
  56.  
  57. flags:
  58.    bit 0:   zero
  59.    bit 1:   carry
  60.    bit 2:   negative
  61.  
  62.    These are the GPU status flags that are set on arithmetic and logical
  63.    instructions (except irq_mask)
  64.  
  65. mask (m):
  66.    bit 3:   IMASK
  67.  
  68.    IMASK (Interupt disable?)
  69.  
  70. irq_enable:
  71.    bit 4:  IRQ 0 enable
  72.    bit 5:  IRQ 1 enable
  73.    bit 6:  IRQ 2 enable
  74.    bit 7:  IRQ 3 enable
  75.    bit 8:  IRQ 4 enable
  76.    
  77.    You can enable any of the 5 interrupts by setting the appropriate
  78.    bit. (?)
  79.  
  80. irq_clear:
  81.    bit 9:  IRQ 0 clear
  82.    bit 10: IRQ 1 clear
  83.    bit 11: IRQ 2 clear
  84.    bit 12: IRQ 3 clear
  85.    bit 13: IRQ 4 clear
  86.  
  87.    When through with an interrupt processing, you probably have to clear
  88.    the appropriate bit here. 
  89.  
  90. aux:
  91.    bit 14:  register bank selection
  92.    bit 15:  DMA
  93.  
  94.    Switching between the registerbanks is done like this:
  95.  
  96.         movei   #G_FLAGS,r1       ; Status flags
  97.       or
  98.         movei   #D_FLAGS,r1       ; Status flags
  99.         load    (r1),r0
  100.         bset    #14,r0
  101.         store   r0,(r1)           ; Switch the GPU/DSP to bank 1
  102.  
  103.    Normally the GPU is running on Bank 1, since on an IRQ Bank 0
  104.    becomes automatically active.
  105.  
  106.    bit 15 seems to control the way the GPU load/store instructions
  107.    access memory. If set they run at DMA priority. If cleared ??
  108.  
  109.  
  110. GPU_CONTROL:
  111. =-=-=-=-=-=
  112.  
  113.  32       28        24        20       16       12        8        4        0
  114.   +--------^---------^---------^--------^--------+--+-----^---+--+-^--------+
  115. 1 |                      unused                  | h| irq_lat | d| control  |
  116.   +----------------------------------------------+--+---------+--+----------+
  117.  
  118. control:
  119.    bit 0:   start the GPU / run status
  120.    bit 1:   allow GPU to interrupt the 68K (?)
  121.    bit 2:   generate a GPU type 0 interrupt (on the 68K (?))
  122.    bit 3:   enable single step
  123.    bit 4:   perform a single step
  124.  
  125. Setting bit 0 starts the GPU. When reading this register this bit will
  126. tell you whether the GPU is running or not. You can stop the GPU by 
  127. clearing this bit.
  128.  
  129.  
  130. dma (d):
  131.    bit 5:   set external DMA ACK (?)
  132.  
  133. int_lat:
  134.    bit 6:   IRQ 0 pending  VI-IRQ (VBLANK)
  135.    bit 7:   IRQ 1 pending
  136.    bit 8:   IRQ 2 pending 
  137.    bit 9:   IRQ 3 pending
  138.    bit 10:  IRQ 4 pending
  139.  
  140.    Clear or poll any pending interrupts with these bits. (?)
  141.  
  142. bus_hog (h) :
  143.    bit 11:  hog mode on
  144.  
  145.    Allows the GPU to 'hog' the bus. When the GPU code uses a lot of 
  146.    load/store instructions consecutively it could be that the OP does
  147.    not get enough time to do its processing. Use with care.
  148.  
  149.  
  150. Register R31 is used by the RISC's as stack pointers. They only 
  151. seems to be used by interupts. See the section on interupts.
  152.  
  153.  
  154. GPU_MATRIX_CONTROL:
  155. =-=-=-=-=-=-=-=-=-=
  156.  
  157.  32       28        24        20       16       12        8        4        0
  158.   +--------^---------^---------^--------^--------^--------^-----+--+--------+
  159. 1 |                          unused                             | t|  size  |
  160.   +-------------------------------------------------------------+--+--------+
  161.  
  162. size:
  163.    bits 0-3:   size as a binary number
  164.  
  165.    Size of one row of the matrix.
  166.  
  167. type  (t):
  168.    bit 4:      row order
  169.  
  170.    Specifiy whether your matrix is Row Major (0) or Column Major (1).
  171.  
  172.  
  173. GPU_MATRIX_ADDRESS:
  174. =-=-=-=-=-=-=-=-=-=
  175.  
  176.  32       28        24        20       16       12        8        4        0
  177.   +--------^---------^---------^--------^--------^--------^--------^--------+
  178. 1 |                                  address                                |
  179.   +-------------------------------------------------------------------------+
  180.    
  181.   Points to the matrix in memory.
  182.  
  183.  
  184. DIV_CONTROL:
  185. =-=-=-=-=-=
  186.  
  187.  32       28        24        20       16       12        8        4        0
  188.   +--------^---------^---------^--------^--------^--------^--------^-----+--+
  189. 1 |                             unknown                                  |c |
  190.   +----------------------------------------------------------------------+--+
  191.  
  192.    This register is write only
  193.   
  194. control (c)
  195.    bit #0      division control
  196.  
  197.    If bit #0 is set, then the division operation will assume a unsigned (?) 
  198.    16.16 integer fractional representation for the divide. 
  199.    Else you get a straight 32 bit unsigned integer divide 
  200.    (like on the 68000 DIVU).
  201.  
  202.  
  203.  
  204. DIV_REMAINDER:
  205. =-=-=-=-=-=-=
  206.  
  207.  32       28        24        20       16       12        8        4        0
  208.   +--------^---------^---------^--------+--------^--------^--------^--------+
  209. 1 |               unused                |               value               |
  210.   +-------------------------------------+-----------------------------------+
  211.  
  212.    This register can be read only.
  213.    Remainder of the division operation. Guess: only 16 bits wide.
  214.  
  215.  
  216. ############################################################################
  217.  
  218. Architecture:
  219. =-=-=-=-=-=-=
  220.  
  221. Ingredients:
  222.  
  223. GPU/DSP: two load/store units
  224.          one ALU
  225.          one divisor unit
  226.          various control logic for branching et.c.
  227.  
  228. The GPU and the DSP are both pipeline processor, employing a 
  229. triple stage forwarding pipeline. The pipeline is:  (???)
  230.  
  231. Stage 1:   Load   (LAS1/LAS2)
  232. Stage 2:   Arithmetic and Logic Unit
  233. Stage 3:   Store  (LAS1/LAS2)
  234.  
  235.  
  236. Load an Store Unit (LAS)
  237. =-=-=-=-=-=-=-=-=-=-=-=
  238.  
  239. The LAS aren't just called LAS because they can Load and Store,
  240. but because they can also Load and Store at the same time. 
  241. To the same register that is... Therefore writing a register
  242. back, still retains the register value in the LAS for usage by
  243. the ALU again.
  244.  
  245.  
  246. Arithmetic and Logic Unit  (ALU)
  247. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  248.  
  249. add, mult, shift all 'atomic' instruction excecute one cycle
  250.  
  251.  
  252.  
  253. Registers
  254. =-=-=-=-=
  255.  
  256. 64 registers, each 32 bits wide, stored in two banks of r0..r31
  257. interrupts always execute out of bank 0  (i.e. your code should
  258. always execute in bank 1..)
  259.  
  260.  
  261.  
  262.               I M P O R T A N T     N O T I C E 
  263. ******************************************************************
  264.      I got lots problems with the following treatment.
  265.                   Don't take it as gospel.
  266. *******************************************************************
  267.               I M P O R T A N T     N O T I C E 
  268.  
  269.  
  270. Currently I favor this as the way the Jaguar does an add. This
  271. a completely unsubstantiated guess on my part solely based on some
  272. outsider info (the code with the STALLs)
  273.  
  274.  
  275. 0:   nop
  276. 1:   add   r0,r1
  277. 2:   nop
  278. 3:   nop
  279.  
  280.  
  281.       INSTR       LAS1       ALU      LAS2
  282. ---------------------------------------------
  283. 0:    nop           -         -        -
  284. 1:    add r0,r1   fetch r0    -      fetch r1
  285. 2:    nop           -        add     write r1
  286. 3:    nop           -         -        -    
  287.  
  288.  
  289. Instructions that need registers which aren't yet update with the new
  290. values force the processor to stall (like on any good pipelined system)
  291. The processor keeps track of the register states, and introduced stalls
  292. when appropriate.
  293.  
  294. Here's a few more complex example: (Thanks, you know who!)
  295.  
  296. Ex 1:
  297.    div r0,r1;     (r1 is not available now!)
  298.    STALL STALL STALL*12
  299.    add r1,r2;    (yay, we can use r1 again :-)
  300.  
  301. You could replace the STALLs with code that did not need to
  302. access r1 and the divison wouldn't slow you down more than
  303. any other instruction. (Of course a second division is 
  304. impossible, when the DIV unit is already in use)
  305.  
  306. Ex.2:
  307.    nop
  308.    nop
  309.    nop                         (LS1)    (LS2)     (ALU)
  310.    add r0,r1                  (load  r0, load r1,  nop)
  311.    add r2,r3                  (load  r2, load r3,  add r0,r1)
  312.    add r4,r5                  (store r1, load r4,  add r2,r3
  313.                               (load  r5,  nop   ,  STALL)
  314.    add r6,r7                  (load  r6, load r7,  add r4,r5)
  315.    add r8,r9                  (store r5, load r8,  add r6,r7)
  316.                               (load  r9, nop    ,  STALL)
  317.    add r0,r1                  (load  r0, load r1,  add r8,r9)
  318.    nop                        (store r9,nop        add r0,r1)   
  319.    nop                        (store r1,nop        nop)
  320.  
  321.  
  322.  
  323. 1.0 Move instructions
  324. =-=-=-=-=-=-=-=-=-=-=
  325.  
  326.        move    Rn,Rn
  327.        move    PC,Rn
  328.        movei   #xxxxxxxx,Rn
  329.  
  330.        load    (Rn),Rn
  331.        load    (Rm+n),Rn    * Rm = R14 | R15 !
  332.        load    (Rm+Ri),Rn   * Rm = R14 | R15 !
  333.        loadb   (Rn),Rn      * load byte
  334.        loadw   (Rn),Rn      * Load word
  335.        loadp   (Rn),Rn      * Load Phrase (GPU only)
  336.        
  337.        store   Rn,(Rn)      
  338.        store   Rn,(Rm+n)    * Rm = R14 | R15 !
  339.        store   Rn,(Rm+Ri)   * Rm = R14 | R15 !
  340.        storeb  Rn,(Rn)      * Store Byte
  341.        storew  Rn,(Rn)      * Store Word
  342.        storep  Rn,(Rn)      * Store Phrase (GPU only)
  343.        
  344.        moveta  Rn,Rn        * move to alternative register bank
  345.        movefa  Rn,Rn        * move from alternative register bank
  346.  
  347.  
  348. 1.1 Logical Instructions
  349. =-=-=-=-=-=-=-=-=-=-=-=-=
  350.  
  351.        or      Rn,Rn
  352.        xor     Rn,Rn
  353.        and     Rn,Rn
  354.  
  355.  
  356. 1.2 Bitoperation Instructions
  357. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  358.  
  359.        bset    #,Rn
  360.        bclr    #,Rn
  361.        btst    #,Rn
  362.        
  363.  
  364. 1.3 Shift Instructions
  365. =-=-=-=-=-=-=-=-=-=-=-=
  366.        
  367.        shlq    #xx,Rn
  368.        shrq    #xx,Rn
  369.        
  370.        sharq   #xx,Rn
  371.        
  372.        ror     Rn,Rn 
  373.        rorq    #xx,Rn
  374.        
  375.        
  376. 1.4 Arith. Instructions
  377. =-=-=-=-=-=-=-=-=-=-=-=
  378.  
  379.        mult    Rn,Rn
  380.        imult   Rn,Rn
  381.        mmult   Rn,Rn
  382.        imultn  Rn,Rn
  383.        imacn   Rn,Rn
  384.        resmac  Rn
  385.        
  386.        div     Rn,Rn          * exec seems to use max 4 i-cycles
  387.        
  388.        add     Rn,Rn
  389.        addc    Rn,Rn          * add with carry
  390.        addq    #xx,Rn
  391.        addqt   #xx,Rn         * add quick, test result
  392.        addqmod #xx,Rn         * add quick, take modulo
  393.        
  394.        sub     Rn,Rn
  395.        subc    Rn,Rn          * add with carry
  396.        subq    #xx,Rn
  397.        subqt   #xx,Rn         * sub quick, test result
  398.        subqmod #xx,Rn         * sub quick, take modulo
  399.  
  400.        cmp     Rn,Rn
  401.        cmpq    #xx,Rn
  402.  
  403.        neg     Rn
  404.        not     Rn
  405.        abs     Rn
  406.        
  407.         
  408. 1.5 Program Structure Instructions
  409. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  410.  
  411.        jump     CC,(Rn)
  412.        jump     (Rn)
  413.        
  414.        jr       CC,xxxxxx
  415.        jr       xxxxxxx
  416.        
  417.        nop
  418.  
  419.  
  420. 1.6 Condition Codes
  421. =-=-=-=-=-=-=-=-=-=
  422.  
  423. Condition codes CC can be any of 
  424.  
  425.     CC (%00100)    CS (%01000)    EQ (%00010)    MI (%11000)
  426.     NE (%00001)    PL (%10100)    HI (%00101)     T (%00000).
  427.  
  428. They are used together with the jump instructions...
  429.  
  430.  
  431. 2.0 Restrictions
  432. =-=-=-=-=-=-=-=-=
  433.  
  434.   'JR+MOVEI', 'JUMP+MOVEI', 'JR+JR', 'JR+JUMP', 'JUMP+JR', 'JUMP+JUMP',
  435.   'JR+MOVE PC', 'JUMP+MOVE PC' 
  436.  
  437.     IMULTN must be followed by a IMACN (Error displayed)
  438.     IMACN must be followed by a IMACN or RESMAC (Error displayed)
  439.     RESMAC must be preceed by a IMACN (Error displayed)
  440.     a NOP is inserted between LOAD+MMULT and STORE+MMULT (Warning displayed).
  441.     I don't know if LOADB+MMULT, LOADW+MMULT, LOADP+MMULT, ... are valid or
  442.     not. Currently, it's not tested...
  443.  
  444.  
  445. 3.0 Instruction Encoding
  446. =-=-=-=-=-=-=-=-=-=-=-=-=
  447.  
  448. Most instructions are only 2 bytes long. This means that 4 
  449. instructions can be pulled from RAM in one memory access!! This also
  450. makes the code extremly tight, which is of optimum concern when 
  451. writing cartridge based programs.
  452. One more than 2 byte instruction is the movei #x,Rn which have the
  453. 32 bit constant just after the 2 byte instruction, this saves a lot
  454. of time and space over other RISC's. The ARM forexample uses 4 32 bit
  455. instructions to fill a register (8 bit at a time). The SPARC 2 32 bit
  456. instructions.
  457.  
  458.  
  459. 3.2 Instruction Encoding
  460. =-=-=-=-=-=-=-=-=-=-=-=-=
  461.  
  462. All instructions uses the top 6 bits to encode the instruction.
  463.  
  464. The 2 operand instructions split the remainder of the 16 bits into
  465. 2 5 bit fields, the source (quick or register) and the destination
  466. register.
  467.  
  468.  
  469. 3.2.1 The Implied Instructions
  470. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  471.  
  472.             iiiiii 0000000000 
  473.               /\       /\
  474.               ||       |_============== room for extensions
  475.               ||
  476.               \`======================= instruction
  477.  
  478. The Implied instruction are nop!
  479.  
  480.  
  481.  
  482. 3.2.2 The 1 Operand Instructions
  483. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  484.  
  485.             iiiiii 00000 ddddd  <====== destination register
  486.               /\     /\
  487.               ||     |_================ room for extensions
  488.               ||
  489.               \`======================= instruction
  490.  
  491. The one operand instructions are:
  492.  
  493.              neg    R0
  494.              not    R1
  495.              abs    R2
  496.              resmac R3
  497.  
  498.  
  499.  
  500. 3.2.3 The 2 Operand Instructions
  501. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  502.  
  503. Most instructions are 2 operand and follow this pattern. The register
  504. to register instructions use the sssss and ddddd to specify source
  505. and destination registers, as add r1,r0. In the quick to register
  506. instructions the sssss field is used to hold a constant, as 
  507. asl #3,r0 where the constans is between 1 and 32 and moveq #0,d2
  508. where the constant is between 0 and 31.
  509.  
  510.             iiiiii sssss ddddd  <====== destination register
  511.               /\     /\
  512.               ||     |_================ source (quick or register)
  513.               ||
  514.               \`======================= instruction
  515.  
  516. Examples of 2 operand instructions are:
  517.  
  518.             move  R1,R2
  519.             bset  #31,R2
  520.             etc...
  521.  
  522.  
  523. 3.2.4 The movei Instruction
  524. =-=-=-=-=-=-=-=-=-=-=-=-=-=
  525.  
  526. The movei instruction are very special! This instruction is the 
  527. only 6 byte instruction, that is what makes it special.
  528. The instruction word follow the general structure,
  529.  
  530.             iiiiii 00000 ddddd  <====== destination register
  531.               /\     /\
  532.               ||     |_================ room for extensions
  533.               ||
  534.               \`======================= instruction ($98)
  535.  
  536. but the 32 bit constant that is to be loaded into the destination
  537. register followes the instruction
  538.  
  539.            +-------------+ +------------+ +------------+
  540.            |   Movei Rn  | | Lower word | | Upper word |
  541.            +-------------+ +------------+ +------------+
  542.  
  543.  
  544. 3.2.5 The Load & Store Instructions
  545. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  546.  
  547. Most instructions are 2 operand and follow this pattern.
  548.  
  549.             iiiiii ppppp ddddd  <====== destination register
  550.               /\     /\
  551.               ||     |_================ indirect register
  552.               ||
  553.               \`======================= instruction
  554.  
  555.  
  556. 3.2.5.1 Addressing Modes For Load/Store Byte/Word/Phrase
  557. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  558.  
  559. All load and store instructions support register indirect addressing,
  560. which is written (Rn).
  561. This means that you can load the memory location pointed to by a 
  562. register into yet another register (or the same).
  563.  
  564.  
  565. 3.2.5.2 Addressing Modes For Load/Store Longword
  566. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  567.  
  568. Together with the Load/Store longword instructions, there are other
  569. addressing modes. Called:
  570.  
  571.   * indexed register indirect addressing, which is written (Rn+Rm),
  572.   * register indirect addressing w. offset, which is written (Rn+xx),
  573.  
  574. In these addressing modes Rn _have_ to be R14 or R15!
  575.  
  576. fx:          load  (r1+r2),r0
  577.              store r0,(r1+16)
  578.                     
  579.  
  580. 3.2.5.3 Load/Store Phrase (GPU Only)
  581. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  582.  
  583. The GPU has an direct 64 bit (Phrase) interface to the main memory.
  584. The loadp/storep instructions access this memorys full width.
  585. The lower part of the phrase pointed to by the (Rp) goes from/to the
  586. register specified, the other part of the phrase is in G_HIDATA
  587. ( 0xF02118 )  /* GPU Bus Interface high data  */
  588.  
  589. fx:          store r0,(rp)
  590.  
  591.  
  592. 3.2.6 The Program Control Instructions
  593. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  594.  
  595. Most Program Control instructions follow this pattern:
  596.  
  597.             iiiiii ddddd ccccc  <====== Condition Vector
  598.               /\     /\
  599.               ||     |_================ source (quick or register)
  600.               ||
  601.               \`======================= instruction
  602.  
  603. The ddddd field can either speify an offset (jr instruction) or 
  604. a register containing a absolute address (jump instruction), all
  605. jump instructions are conditional.
  606.  
  607.  
  608. 3.2.6.1 Condition Codes
  609. =-=-=-=-=-=-=-=-=-=-=-=
  610.  
  611. Condition codes ccccc can be any 5 bit vector, here are some ready 
  612. defined usefull values:
  613.  
  614.        CC (%00100    CS (%01000)   EQ (%00010)  MI (%11000)
  615.        NE (%00001)   PL (%10100)   HI (%00101)  T  (%00000)
  616.  
  617. Examples of Program Control instructions:
  618.  
  619.             jump  mi, (r5)
  620.             jr    ne, exit
  621.             jr    t, loop   ; loop forever
  622.             jr    loop      ; loop forever            
  623.             jump  (r5)
  624.             
  625.             
  626. 3.2.7 Modulo Aritimetics (DSP only)
  627. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  628.  
  629. The instructions addqmod and subqmod are modular with the size
  630. specified in the D_MOD (0xF1A118) /* DSP Modulo Instruction Mask */
  631. The mask register contains a mask that is applied to the register
  632. after the add operation, as in the following two step
  633.  
  634.                     movei #%111111,r1
  635.               loop: addq #4,r0
  636.                     and  r1,r0
  637.                     ...
  638.                     jr loop
  639.                     
  640. With the modulo register this can be written:
  641.  
  642.                     movei #D_MOD,r3
  643.                     movei #~%111111,r1
  644.                     store r1,(r3)
  645.               loop: addq #4,r0
  646.                     ...
  647.                     jr loop                 
  648.  
  649. This is an obvious win! - you save a cycle each loop!
  650.  
  651. Instructions are 
  652.                    subqmod, addqmod
  653.                    
  654.  
  655. 3.2.8 Multiply and Multiply-Accumulate Locations
  656. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  657.  
  658. D_MACHI         EQU     BASE+$1A120     ; DSP Hi byte of MAC operations
  659.  
  660.  
  661. 3.2.9 Matrix Multiply Locations
  662. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  663.  
  664. D_MTXC          EQU     BASE+$1A104     ; DSP Matrix Control
  665. D_MTXA          EQU     BASE+$1A108     ; DSP Matrix Address
  666. G_MTXC          EQU     BASE+$2104      ; GPU Matrix Control
  667. G_MTXA          EQU     BASE+$2108      ; GPU Matrix Address
  668.  
  669.  
  670. 3.2.10 Divide Locations
  671. =-=-=-=-=-=-=-=-=-=-=-=
  672.  
  673. D_REMAIN        EQU     BASE+$1A11C     ; DSP Division Remainder
  674. D_DIVCTRL       EQU     BASE+$1A11C     ; DSP Divider control
  675. G_REMAIN        EQU     BASE+$211C      ; GPU Division Remainder
  676. G_DIVCTRL       EQU     BASE+$211C      ; GPU Divider control 
  677.  
  678.  
  679.  
  680. 3.3 Instruction numbers
  681. =-=-=-=-=-=-=-=-=-=-=-=
  682.  
  683.    Mnemonic  Mode     iiiiii sssss ddddd  hex  Notes
  684.    --------------------------------------------------------------
  685.      ADD     Rs,Rd    000000 sssss ddddd  $00
  686.      ADDC    Rs,Rd    000001 sssss ddddd  $04
  687.      ADDQ    #q,Rd    000010 qqqqq ddddd  $08  q is [32, 1..31]
  688.      ADDQT   #q,Rd    000011 qqqqq ddddd  $0C  q is [32, 1..31]
  689.  
  690.      SUB     Rs,Rd    000100 sssss ddddd  $10
  691.      SUBC    Rs,Rd    000101 sssss ddddd  $14
  692.      SUBQ    #q,Rd    000110 qqqqq ddddd  $18  q is [32, 1..31]
  693.      SUBQT   #q,Rd    000111 qqqqq ddddd  $1C  q is [32, 1..31]
  694.  
  695.      NEG     Rd       001000 00000 ddddd  $20
  696.  
  697.      AND     Rs,Rd    001001 sssss ddddd  $24
  698.      OR      Rs,Rd    001010 sssss ddddd  $28
  699.      XOR     Rs,Rd    001011 sssss ddddd  $2C
  700.  
  701.      NOT     Rd       001100 00000 ddddd  $30
  702.  
  703.      BTST    #q,Rd    001101 qqqqq ddddd  $34  q is [0..31]
  704.      BSET    #q,Rd    001110 qqqqq ddddd  $38  q is [0..31]
  705.      BCLR    #q,Rd    001111 qqqqq ddddd  $3C  q is [0..31]
  706.  
  707.      MULT    Rs,Rd    010000 sssss ddddd  $40
  708.      IMULT   Rs,Rd    010001 sssss ddddd  $44
  709.      IMULTN  Rs,Rd    010010 sssss ddddd  $48
  710.      RESMAC  Rd       010011 00000 ddddd  $4C
  711.      IMACN   Rs,Rd    010100 sssss ddddd  $50
  712.  
  713.      DIV     Rs,Rd    010101 sssss ddddd  $54
  714.  
  715.      ABS     Rd       010110 00000 ddddd  $58
  716.                                           $5C
  717.      SHLQ    #q,Rd    011000 qqqqq ddddd  $60  q is [32, 1..31]
  718.      SHRQ    #q,Rd    011001 qqqqq ddddd  $64  q is [32, 1..31]
  719.                                           $68 
  720.      SHARQ   #q,Rd    011011 qqqqq ddddd  $6C  q is [32, 1..31]
  721.      ROR     Rs,Rd    011100 sssss ddddd  $70  
  722.      RORQ    #q,Rd    011101 qqqqq ddddd  $74  q is [32, 1..31]
  723.  
  724.      CMP     Rs,Rd    011110 sssss ddddd  $78
  725.      CMPQ    #q,Rd    011111 qqqqq ddddd  $7C  q is [0..31]
  726.  
  727. DSP  SUBQMOD #q,Rd    100000 qqqqq ddddd  $80  q is [32, 1..31]
  728.                                           $84
  729.      MOVE    Rs,Rd    100010 sssss ddddd  $88
  730.      MOVEQ   #q,Rd    100011 qqqqq ddddd  $8C  q is [0..31]    
  731.      MOVETA  Rs,Rd    100100 sssss ddddd  $90
  732.      MOVEFA  Rs,Rd    100101 sssss ddddd  $94
  733.      MOVEI   #c32,Rd  100110 00000 ddddd  $98  followed by a 32 bit const
  734.      
  735.      LOADB   (Rp),Rd  100111 ppppp ddddd  $9C
  736.      LOADW   (Rp),Rd  101000 ppppp ddddd  $A0
  737.      LOAD    (Rp),Rd  101001 ppppp ddddd  $A4
  738. GPU  LOADP   (Rp),Rd  101010 ppppp ddddd  $A8  Load Phrase
  739.      LOAD  (R14+n),Rd 101011 nnnnn ddddd  $AC
  740.      LOAD  (R15+n),Rd 101100 nnnnn ddddd  $B0
  741.      
  742.      STOREB  Rs,(Rp)  101101 ppppp sssss  $B4
  743.      STOREW  Rs,(Rp)  101110 ppppp sssss  $B8
  744.      STORE   Rs,(Rp)  101111 ppppp sssss  $BC
  745. GPU  STOREP  Rs,(Rp)  110000 ppppp sssss  $C0  Store Phrase
  746.      STORE Rs,(R14+n) 110001 nnnnn sssss  $C4
  747.      STORE Rs,(R15+n) 110010 nnnnn sssss  $C8
  748.  
  749.      MOVE    PC,Rn    110011 00000 ddddd  $CC
  750.  
  751.      JUMP    CC,(Rd)  110100 ddddd ccccc  $D0
  752.      JR      CC,q     110101 qqqqq ccccc  $D4  
  753.  
  754.      MMULT   Rs,Rd    110110 sssss ddddd  $D8
  755.                                           $DC
  756.                                           $E0
  757.      NOP              111001 00000 00000  $E4
  758.  
  759.      LOAD (R14+Ri),Rd 111010 iiiii ddddd  $E8
  760.      LOAD (R15+Ri),Rd 111010 iiiii ddddd  $EC
  761.     STORE Rs,(R14+Ri) 110001 iiiii sssss  $F0
  762.     STORE Rs,(R15+Ri) 110010 iiiii sssss  $F4
  763.                                           $F8    
  764. DSP  ADDQMOD #q,Rd    111111 qqqqq ddddd  $FC  q is [32, 1..31]
  765.  
  766.  
  767. 3.4    Move instructions
  768. =-=-=-=-=-=-=-=-=-=-=-=
  769.  
  770. None of the move instructions affect the status flags of the GPU,
  771. except when moving data into the status register itself.
  772.  
  773.  
  774. 3.5    Arithmetic instructions
  775. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  776.  
  777. ABS        sets the carry flag if a negative value was transformed to a 
  778.          positive    else clears it
  779.  
  780. ADDQT    does not affect the status flags
  781.  
  782. DIV      takes 16 cyles to execute. Supposedly you can do either
  783.          16.16 integer, fractional division or 32 bit integer
  784.          division. The DIV does a 2 bit divide each cycle, hence 16
  785.          cycles total for 32 bit. The remainder of the divison is 
  786.          saved in a special register.
  787.  
  788. IMACN    they don't have a register write back (so they're easier to
  789.          optimize) and you'll find if you get in the habit of using 
  790.          them, you can normally structure your code a bit faster by 
  791.          using them..
  792.  
  793.  
  794. 3.6    Logical instructions
  795. =-=-=-=-=-=-=-=-=-=-=-=-=-=
  796.  
  797. SHLQ    affects the status flags
  798. SHRQ    affects the status flags
  799.  
  800.  
  801. 4.0   Matrix multiplication
  802. =-=-=-=-=-=-=-=-=-=-=-=-=-=
  803.  
  804.  
  805.  
  806.    MMULT    starting_register,destination_register
  807.          
  808. You have to setup the matrix control register and the matrix address
  809. register before executing the MMULT instruction. The MMULT instruction
  810. will then multiply the values contained in the interrupt (alternate ?) 
  811. register bank (0) starting at register "starting_register" with the 
  812. matrix pointed to by the matrix address register.
  813.  
  814. The values used for the multiplication are 16 bit values (sign extended ?)
  815. and are arranged in this slightly peculiar fashion (for a 5x1 Matrix):
  816.  
  817.  
  818.                Register bank #0  (RB)
  819.          +-------------+------------+
  820.          |      1      |      0     |  Rn
  821.          +-------------+------------+
  822.          |      3      |      2     |  Rn+1
  823.          +-------------+------------+
  824.          |    unused   |      4     |  Rn+2
  825.          +-------------+------------+
  826.  
  827.  
  828. These values are then multiplied with a 32 bit table in memory
  829. and the results of these added together:
  830.  
  831.  
  832.                   Main memory    (MM)
  833. $020000  +--------------------------+
  834.          |             0            | $020003
  835. $020004  +--------------------------+
  836.          |             1            | $020007
  837. $020008  +--------------------------+
  838.          |             2            | $02000B
  839. $02000C  +--------------------------+
  840.          |             3            | $02000F
  841. $020010  +--------------------------+
  842.          |             4            | $020013
  843.          +--------------------------+
  844.  
  845.  
  846.    result = MM0 * RB0 + MM1 * RB1 + MM2 * RB2 + MM3 * RB3 + MM4 * RB4;
  847.  
  848. The result 32 bit is stored into "destination_register" in the current 
  849. bank (or bank 1?).
  850.  
  851.  
  852. Brief internal description of MMULT:  strips program instruction fetchs 
  853. and forces instructions straight into the pipeline.. getting a through put
  854. of one (16 bit) multiply per tick.. (25 million per second :-)
  855.  
  856. Supposedly the MMULT is performed by inserting generated instructions 
  857. into the instruction stream.  Supposedly fot a MMULT the instructions
  858. inserted are a leading IMULTN, the middle ones IMACN, and finally a 
  859. RESMAC. 
  860.  
  861. ???  These have their operands modified in the manner described above. ???
  862. i.e. that funky packed thingy, two elements per register, that
  863. allows all of an eightxeight matrix to be stored in the secondary
  864. register bank and is the rasen d'e^tre of the second bank".. (woosh)
  865.  
  866.      
  867. 5.0 Interupts
  868. =-=-=-=-=-=-=
  869.  
  870. The GPU and the DSP uses an interupt scheme that looks a lot like
  871. the 56000's way of handling interupts.
  872.  
  873. In the lowest part of each processors memory the interupt entry
  874. points are. There are 16 bytes for each interupt. This should
  875. be enough to jump into the real interupt handler.
  876.  
  877.    ( If this works like on the 56000 it should be possible 
  878.      to have Fast Interupts, where the CPU returns automatically
  879.      when the 16 bytes have been executed and no jump 
  880.      instructions have been executed ).
  881.  
  882. For the DSP it looks like this:
  883.  
  884. 000000        Reset          (or DSP control interupt)
  885. 000010        I2S Interupt
  886.  
  887.  
  888. Enable interupts I2S:
  889.  
  890.     movei    #D_FLAGS,r1        ; load dsp flags to go to bank 1
  891.     load    (r1),r0
  892.     bset    #5,r0            ; enable I2S interrupt
  893.     store    r0,(r1)         ; save dsp flags
  894.  
  895.  
  896. Handle i2s interupts
  897.  
  898. i2s_isr:
  899.     movei    #D_FLAGS,r30            ; get flags ptr
  900.     load    (r30),r12
  901.     bclr    #3,r12            ; clear IMASK
  902.     load    (r31),r28        ; get last instruction address
  903.     bset    #10,r12            ; clear I2S interrupt
  904.     addq    #2,r28            ; point at next to be executed
  905.     addq    #4,r31            ; update the stack pointer
  906.    ...
  907.     jump    T,(r28)            ; and return
  908.     store    r12,(r30)        ; restore flags
  909.  
  910.  
  911.  
  912. BUGS:
  913. =-=-=
  914.  
  915. There are also apparently some bugs (pretty heavy ones IMO) in the
  916. GPU/DSP that you should be aware of:
  917.  
  918. 1) INDEXED STORES NEVER STALL
  919.   e.g
  920.      div r0,r3
  921.      store r3,(r14+6)
  922.  
  923.    should be
  924.  
  925.      div r0,r3
  926.      or r3,r3
  927.      store r3,(r14+6)
  928.  
  929.    Here the OR is used to 'touch' the register for the scoreboard. If you 
  930.    wouldn't touch the r3 register you would most likely (but not always,
  931.    think of those IRQs!) write the old value of r3 back.
  932.  
  933.  
  934. 2) TWO CONSECUTIVE WRITES TO THE SAME REGISTER MIGHT BE PROBLEMATIC
  935.  
  936.    Although writing code like this is a bug anyway, you should be careful
  937.    that if you write to same reg with no intermittent read, and the
  938.    second instruction finishes first garbage will result:
  939.  
  940.       load  (r3),r2
  941.       moveq #3,r2
  942.  
  943. should be
  944.       load  (r3),r2
  945.       or    r2,r2
  946.       moveq #3,r2
  947.  
  948.  
  949. 3)  NEITHER THE DSP NOR THE GPU CAN EXECUTE 'jr' OR 'jump' FROM EXTERNAL
  950.     RAM
  951.  
  952.  
  953. 4)  NEITHER THE DSP NOR THE GPU MAX BE USED IN HIGH PRIORITY 
  954.  
  955. 5)  A mmult INSTRUCTION MUST NEVER BE INTERRUPTED
  956.     how very convenient...
  957.  
  958. 6)  THE DSP (ONLY) MUST NOT DO AN EXTERNAL WRITE UNLESS PRECEDED BY AN 
  959.     EXTERNAL READ THAT COMPLETES BEFORE THE WRITE STARTS.
  960.  
  961.     The saying goes, that this bug is only spurious and can remain 
  962.     undetected for quite some time.
  963.     Hint for external I/O use the Blitter (as always :))
  964.  
  965.    e.g.
  966.    A:
  967.       load  (r1),r2
  968.       or    r10,r11
  969.       store r11,(r3)
  970.  
  971.    B:
  972.      load   (r1),r2
  973.      or     r2,11
  974.      store  r11,(r3)
  975.  
  976.    C:
  977.      load   (r1),r2
  978.      or     r2,r2
  979.      or     r10,r11
  980.      store  r11,(r3)
  981.  
  982.    [A] will no work but [B] will, this is because the result of the load 
  983.    is required for the 'or' operation to be performed. To make [A] work, 
  984.    change it to [C]...
  985.  
  986.  
  987.  
  988.  
  989.  
  990.