home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_03 / JAGDOX.ZIP / GPU.TXT < prev    next >
Text File  |  1995-12-10  |  17KB  |  516 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. Since we are not under NDA or anything from
  6. # Atari we feel free to give this to you for educational purposes
  7. # only.
  8. #
  9. # Please note, that this is not official documentation from Atari
  10. # or derived work thereof (both of us have never seen the Atari docs)
  11. # and Atari isn't connected with this in any way.
  12. #
  13. # Please use this informationphile as a starting point for your own
  14. # exploration and not as a reference. If you find anything innacurate,
  15. # missing, needing more explanation etc. by all means please write
  16. # to us:
  17. #     nat@zumdick.rhein-main.de
  18. # or
  19. #     kkp@gamma.dou.dk
  20. #
  21. # If you could do us a small favor, don't use this information for
  22. # those lame flamewars on r.g.v.a or the mailing list.
  23. #
  24. # HTML soon ?
  25. # -------------------------------------------------------------------
  26. # $Id: risc_doc.txt,v 1.2 1995/12/08 18:48:09 nat Exp $
  27. # -------------------------------------------------------------------
  28.  
  29. 1 RISCy Buisness
  30.  
  31. The RISC's has 2 register banks of 32 registers each. There are
  32. the Current and the Alternative register bank. Register R31 is the
  33. stack pointer and normally R0 is initilized to 0 (Zero).
  34.  
  35. G_FLAGS and D_FLAGS are the status register. The first 5 bits
  36. contains the Carry, Zero and Minus flags (I THINK).
  37.  
  38. Bit 3  IMASK (Interupt disable?)
  39. Bit 5  Interupt level 1 enable
  40. Bit 10 Interupt level 1 pending?
  41. Bit 14 is the register bank selection.
  42.  
  43. Switch between the registerbanks is done:
  44.  
  45.         movei   #G_FLAGS,r1       ; Status flags
  46.       or
  47.         movei   #D_FLAGS,r1       ; Status flags
  48.         load    (r1),r0
  49.         bset    #14,r0
  50.         store   r0,(r1)           ; Switch the GPU/DSP to bank 1
  51.  
  52. Register R31 is used by the RISC's as stack pointers. They only
  53. seems to be used by interupts. See the section on interupts.
  54.  
  55.  
  56. 1.0 Move instructions
  57.  
  58.        move    Rn,Rm
  59.        move    PC,Rn
  60.        movei   #xxxxxxxx,Rn
  61.  
  62.        load    (Rn),Rn
  63.        load    (Rm+n),Rn    * Rm = R14 | R15 !
  64.        load    (Rm+Ri),Rn   * Rm = R14 | R15 !
  65.        loadb   (Rn),Rn      * load byte
  66.        loadw   (Rn),Rn      * Load word
  67.        loadp   (Rn),Rn      * Load Phrase (GPU only)
  68.  
  69.        store   Rn,(Rn)
  70.        store   Rn,(Rm+n)    * Rm = R14 | R15 !
  71.        store   Rn,(Rm+Ri)   * Rm = R14 | R15 !
  72.        storeb  Rn,(Rn)      * Store Byte
  73.        storew  Rn,(Rn)      * Store Word
  74.        storep  Rn,(Rn)      * Store Phrase (GPU only)
  75.  
  76.        moveta  Rn,Rn        * move to alternative register bank
  77.        movefa  Rn,Rn        * move from alternative register bank
  78.  
  79. 1.1 Logical Instructions
  80.  
  81.        or      Rn,Rn
  82.        xor     Rn,Rn
  83.        and     Rn,Rn
  84.  
  85. 1.2 Bitoperation Instructions
  86.  
  87.        bset    #,Rn
  88.        bclr    #,Rn
  89.        btst    #,Rn
  90.  
  91. 1.3 Shift Instructions
  92.  
  93.        shlq    #xx,Rn
  94.        shrq    #xx,Rn
  95.  
  96.        sharq   #xx,Rn
  97.  
  98.        ror     Rn,Rn
  99.        rorq    #xx,Rn
  100.  
  101.  
  102. 1.4 Arith. Instructions
  103.  
  104.        mult    Rn,Rn
  105.        imult   Rn,Rn
  106.        mmult   Rn,Rn
  107.        imultn  Rn,Rn
  108.        imacn   Rn,Rn
  109.        resmac  Rn
  110.  
  111.        div     Rn,Rn          * exec seems to use max 4 i-cycles
  112.  
  113.        add     Rn,Rn
  114.        addc    Rn,Rn          * add with carry
  115.        addq    #xx,Rn
  116.        addqt   #xx,Rn         * add quick, test result
  117.        addqmod #xx,Rn         * add quick, take modulo
  118.  
  119.        sub     Rn,Rn
  120.        subc    Rn,Rn          * add with carry
  121.        subq    #xx,Rn
  122.        subqt   #xx,Rn         * sub quick, test result
  123.        subqmod #xx,Rn         * sub quick, take modulo
  124.  
  125.        cmp     Rn,Rn
  126.        cmpq    #xx,Rn
  127.  
  128.        neg     Rn
  129.        not     Rn
  130.        abs     Rn
  131.  
  132.  
  133. 1.5 Program Structure Instructions
  134.  
  135.        jump     CC,(Rn)
  136.        jump     (Rn)
  137.  
  138.        jr       CC,xxxxxx
  139.        jr       xxxxxxx
  140.  
  141.        nop
  142.  
  143.  
  144. 1.6 Condition Codes
  145.  
  146. Condition codes CC can be any of
  147.  
  148.     CC (%00100) CS (%01000) EQ (%00010) MI (%11000)
  149.     NE (%00001) PL (%10100) HI (%00101)  T (%00000).
  150.  
  151. They are used together with the jump instructions...
  152.  
  153.  
  154. 2.0 Restrictions
  155.  
  156.  
  157.   'JR+MOVEI', 'JUMP+MOVEI', 'JR+JR', 'JR+JUMP', 'JUMP+JR', 'JUMP+JUMP',
  158.   'JR+MOVE PC', 'JUMP+MOVE PC'
  159.  
  160.     IMULTN must be followed by a IMACN (Error displayed)
  161.     IMACN must be followed by a IMACN or RESMAC (Error displayed)
  162.     RESMAC must be preceed by a IMACN (Error displayed)
  163.     a NOP is inserted between LOAD+MMULT and STORE+MMULT (Warning displayed).
  164.     I don't know if LOADB+MMULT, LOADW+MMULT, LOADP+MMULT, ... are valid or
  165.     not. Currently, it's not tested...
  166.  
  167.  
  168. 3.0 Instruction Encoding
  169.  
  170. Most instructions are only 2 bytes long. This means that 4
  171. instructions can be pulled from RAM in one memory access!! This also
  172. makes the code extremly tight, which is of optimum concern when
  173. writing cartridge based programs.
  174. One more than 2 byte instruction is the movei #x,Rn which have the
  175. 32 bit constant just after the 2 byte instruction, this saves a lot
  176. of time and space over other RISC's. The ARM forexample uses 4 32 bit
  177. instructions to fill a register (8 bit at a time). The SPARC 2 32 bit
  178. instructions.
  179.  
  180.  
  181. 3.2 Instruction Encoding
  182.  
  183. All instructions uses the top 6 bits to encode the instruction.
  184.  
  185. The 2 operand instructions split the remainder of the 16 bits into
  186. 2 5 bit fields, the source (quick or register) and the destination
  187. register.
  188.  
  189.  
  190. 3.2.1 The Implied Instructions
  191.  
  192.             iiiiii 0000000000
  193.               /\       /\
  194.               ||       |_============== room for extensions
  195.               ||
  196.               \`======================= instruction
  197.  
  198. The Implied instruction are nop!
  199.  
  200.  
  201.  
  202. 3.2.2 The 1 Operand Instructions
  203.  
  204.             iiiiii 00000 ddddd  <====== destination register
  205.               /\     /\
  206.               ||     |_================ room for extensions
  207.               ||
  208.               \`======================= instruction
  209.  
  210. The one operand instructions are:
  211.  
  212.              neg    R0
  213.              not    R1
  214.              abs    R2
  215.              resmac R3
  216.  
  217.  
  218.  
  219. 3.2.3 The 2 Operand Instructions
  220.  
  221. Most instructions are 2 operand and follow this pattern. The register
  222. to register instructions use the sssss and ddddd to specify source
  223. and destination registers, as add r1,r0. In the quick to register
  224. instructions the sssss field is used to hold a constant, as
  225. asl #3,r0 where the constans is between 1 and 32 and moveq #0,d2
  226. where the constant is between 0 and 31.
  227.  
  228.             iiiiii sssss ddddd  <====== destination register
  229.               /\     /\
  230.               ||     |_================ source (quick or register)
  231.               ||
  232.               \`======================= instruction
  233.  
  234. Examples of 2 operand instructions are:
  235.  
  236.             move  R1,R2
  237.             bset  #31,R2
  238.             etc...
  239.  
  240.  
  241. 3.2.4 The movei Instruction
  242.  
  243. The movei instruction are very special! This instruction is the
  244. only 6 byte instruction, that is what makes it special.
  245. The instruction word follow the general structure,
  246.  
  247.             iiiiii 00000 ddddd  <====== destination register
  248.               /\     /\
  249.               ||     |_================ room for extensions
  250.               ||
  251.               \`======================= instruction ($98)
  252.  
  253. but the 32 bit constant that is to be loaded into the destination
  254. register followes the instruction
  255.  
  256.            +-------------+ +------------+ +------------+
  257.            |   Movei Rn  | | Lower word | | Upper word |
  258.            +-------------+ +------------+ +------------+
  259.  
  260.  
  261. 3.2.5 The Load & Store Instructions
  262.  
  263. Most instructions are 2 operand and follow this pattern.
  264.  
  265.             iiiiii ppppp ddddd  <====== destination register
  266.               /\     /\
  267.               ||     |_================ indirect register
  268.               ||
  269.               \`======================= instruction
  270.  
  271.  
  272. 3.2.5.1 Addressing Modes For Load/Store Byte/Word/Phrase
  273.  
  274. All load and store instructions support register indirect addressing,
  275. which is written (Rn).
  276. This means that you can load the memory location pointed to by a
  277. register into yet another register (or the same).
  278.  
  279.  
  280. 3.2.5.2 Addressing Modes For Load/Store Longword
  281.  
  282. Together with the Load/Store longword instructions, there are other
  283. addressing modes. Called:
  284.  
  285.   * indexed register indirect addressing, which is written (Rn+Rm),
  286.   * register indirect addressing w. offset, which is written (Rn+xx),
  287.  
  288. In these addressing modes Rn _have_ to be R14 or R15!
  289.  
  290. fx:          load  (r1+r2),r0
  291.              store r0,(r1+16)
  292.  
  293.  
  294. 3.2.5.3 Load/Store Phrase (GPU Only)
  295.  
  296. The GPU has an direct 64 bit (Phrase) interface to the main memory.
  297. The loadp/storep instructions access this memorys full width.
  298. The lower part of the phrase pointed to by the (Rp) goes from/to the
  299. register specified, the other part of the phrase is in G_HIDATA
  300. ( 0xF02118 )  /* GPU Bus Interface high data  */
  301.  
  302. fx:          store r0,(rp)
  303.  
  304.  
  305. 3.2.6 The Program Control Instructions
  306.  
  307. Most Program Control instructions follow this pattern:
  308.  
  309.             iiiiii ddddd ccccc  <====== Condition Vector
  310.               /\     /\
  311.               ||     |_================ source (quick or register)
  312.               ||
  313.               \`======================= instruction
  314.  
  315. The ddddd field can either speify an offset (jr instruction) or
  316. a register containing a absolute address (jump instruction), all
  317. jump instructions are conditional.
  318.  
  319.  
  320. 3.2.6.1 Condition Codes
  321.  
  322. Condition codes ccccc can be any 5 bit vector, here are some ready
  323. defined usefull values:
  324.  
  325.        CC (%00100    CS (%01000)   EQ (%00010)  MI (%11000)
  326.        NE (%00001)   PL (%10100)   HI (%00101)  T  (%00000)
  327.  
  328. Examples of Program Control instructions:
  329.  
  330.             jump  mi, (r5)
  331.             jr    ne, exit
  332.             jr    t, loop   ; loop forever
  333.             jr    loop      ; loop forever
  334.             jump  (r5)
  335.  
  336.  
  337. 3.2.7 Modulo Aritimetics (DSP only)
  338.  
  339. The instructions addqmod and subqmod are modular with the size
  340. specified in the D_MOD (0xF1A118) /* DSP Modulo Instruction Mask */
  341. The mask register contains a mask that is applied to the register
  342. after the add operation, as in the following two step
  343.  
  344.                     movei #%111111,r1
  345.               loop: addq #4,r0
  346.                     and  r1,r0
  347.                     ...
  348.                     jr loop
  349.  
  350. With the modulo register this can be written:
  351.  
  352.                     movei #D_MOD,r3
  353.                     movei #~%111111,r1
  354.                     store r1,(r3)
  355.               loop: addq #4,r0
  356.                     ...
  357.                     jr loop
  358.  
  359. This is an obvious win! - you save a cycle each loop!
  360.  
  361. Instructions are
  362.                    subqmod, addqmod
  363.  
  364.  
  365. 3.2.8 Multiply and Multiply-Accumulate Locations
  366. D_MACHI         EQU     BASE+$1A120     ; DSP Hi byte of MAC operations
  367.  
  368.  
  369. 3.2.9 Matrix Multiply Locations
  370. D_MTXC          EQU     BASE+$1A104     ; DSP Matrix Control
  371. D_MTXA          EQU     BASE+$1A108     ; DSP Matrix Address
  372. G_MTXC          EQU     BASE+$2104      ; GPU Matrix Control
  373. G_MTXA          EQU     BASE+$2108      ; GPU Matrix Address
  374.  
  375.  
  376. 3.2.10 Divide Locations
  377. D_REMAIN        EQU     BASE+$1A11C     ; DSP Division Remainder
  378. D_DIVCTRL       EQU     BASE+$1A11C     ; DSP Divider control
  379. G_REMAIN        EQU     BASE+$211C      ; GPU Division Remainder
  380. G_DIVCTRL       EQU     BASE+$211C      ; GPU Divider control
  381.  
  382.  
  383. 3.2.20 Strange things:
  384.  
  385.  
  386. 3.3 Instruction numbers
  387.  
  388.    Mnemonic  Mode     iiiiii sssss ddddd  hex  Notes
  389.    --------------------------------------------------------------
  390.      ADD     Rs,Rd    000000 sssss ddddd  $00
  391.      ADDC    Rs,Rd    000001 sssss ddddd  $04
  392.      ADDQ    #q,Rd    000010 qqqqq ddddd  $08  q is [32, 1..31]
  393.      ADDQT   #q,Rd    000011 qqqqq ddddd  $0C  q is [32, 1..31]
  394.  
  395.      SUB     Rs,Rd    000100 sssss ddddd  $10
  396.      SUBC    Rs,Rd    000101 sssss ddddd  $14
  397.      SUBQ    #q,Rd    000110 qqqqq ddddd  $18  q is [32, 1..31]
  398.      SUBQT   #q,Rd    000111 qqqqq ddddd  $1C  q is [32, 1..31]
  399.  
  400.      NEG     Rd       001000 00000 ddddd  $20
  401.  
  402.      AND     Rs,Rd    001001 sssss ddddd  $24
  403.      OR      Rs,Rd    001010 sssss ddddd  $28
  404.      XOR     Rs,Rd    001011 sssss ddddd  $2C
  405.  
  406.      NOT     Rd       001100 00000 ddddd  $30
  407.  
  408.      BTST    #q,Rd    001101 qqqqq ddddd  $34  q is [0..31]
  409.      BSET    #q,Rd    001110 qqqqq ddddd  $38  q is [0..31]
  410.      BCLR    #q,Rd    001111 qqqqq ddddd  $3C  q is [0..31]
  411.  
  412.      MULT    Rs,Rd    010000 sssss ddddd  $40
  413.      IMULT   Rs,Rd    010001 sssss ddddd  $44
  414.      IMULTN  Rs,Rd    010010 sssss ddddd  $48
  415.      RESMAC  Rd       010011 00000 ddddd  $4C
  416.      IMACN   Rs,Rd    010100 sssss ddddd  $50
  417.  
  418.      DIV     Rs,Rd    010101 sssss ddddd  $54
  419.  
  420.      ABS     Rd       010110 00000 ddddd  $58
  421.                                           $5C
  422.      SHLQ    #q,Rd    011000 qqqqq ddddd  $60  q is [32, 1..31]
  423.      SHRQ    #q,Rd    011001 qqqqq ddddd  $64  q is [32, 1..31]
  424.                                           $68
  425.      SHARQ   #q,Rd    011011 qqqqq ddddd  $6C  q is [32, 1..31]
  426.      ROR     Rs,Rd    011100 sssss ddddd  $70
  427.      RORQ    #q,Rd    011101 qqqqq ddddd  $74  q is [32, 1..31]
  428.  
  429.      CMP     Rs,Rd    011110 sssss ddddd  $78
  430.      CMPQ    #q,Rd    011111 qqqqq ddddd  $7C  q is [0..31]
  431.  
  432. DSP  SUBQMOD #q,Rd    100000 qqqqq ddddd  $80  q is [32, 1..31]
  433.                                           $84
  434.      MOVE    Rs,Rd    100010 sssss ddddd  $88
  435.      MOVEQ   #q,Rd    100011 qqqqq ddddd  $8C  q is [0..31]
  436.      MOVETA  Rs,Rd    100100 sssss ddddd  $90
  437.      MOVEFA  Rs,Rd    100101 sssss ddddd  $94
  438.      MOVEI   #c32,Rd  100110 00000 ddddd  $98  followed by a 32 bit const
  439.  
  440.      LOADB   (Rp),Rd  100111 ppppp ddddd  $9C
  441.      LOADW   (Rp),Rd  101000 ppppp ddddd  $A0
  442.      LOAD    (Rp),Rd  101001 ppppp ddddd  $A4
  443. GPU  LOADP   (Rp),Rd  101010 ppppp ddddd  $A8  Load Phrase
  444.      LOAD  (R14+n),Rd 101011 nnnnn ddddd  $AC
  445.      LOAD  (R15+n),Rd 101100 nnnnn ddddd  $B0
  446.  
  447.      STOREB  Rs,(Rp)  101101 ppppp sssss  $B4
  448.      STOREW  Rs,(Rp)  101110 ppppp sssss  $B8
  449.      STORE   Rs,(Rp)  101111 ppppp sssss  $BC
  450. GPU  STOREP  Rs,(Rp)  110000 ppppp sssss  $C0  Store Phrase
  451.      STORE Rs,(R14+n) 110001 nnnnn sssss  $C4
  452.      STORE Rs,(R15+n) 110010 nnnnn sssss  $C8
  453.  
  454.      MOVE    PC,Rn    110011 00000 ddddd  $CC
  455.  
  456.      JUMP    CC,(Rd)  110100 ddddd ccccc  $D0
  457.      JR      CC,q     110101 qqqqq ccccc  $D4
  458.  
  459.      MMULT   Rs,Rd    110110 sssss ddddd  $D8
  460.                                           $DC
  461.                                           $E0
  462.      NOP              111001 00000 00000  $E4
  463.  
  464.      LOAD (R14+Ri),Rd 111010 iiiii ddddd  $E8
  465.      LOAD (R15+Ri),Rd 111010 iiiii ddddd  $EC
  466.     STORE Rs,(R14+Ri) 110001 iiiii sssss  $F0
  467.     STORE Rs,(R15+Ri) 110010 iiiii sssss  $F4
  468.                                           $F8
  469. DSP  ADDQMOD #q,Rd    111111 qqqqq ddddd  $FC  q is [32, 1..31]
  470.  
  471.  
  472. 4.0 Interupts
  473.  
  474. The GPU and the DSP uses an interupt scheme that looks a lot like
  475. the 56000's way of handling interupts.
  476.  
  477. In the lowest part of each processors memory the interupt entry
  478. points are. There are 16 bytes for each interupt. This should
  479. be enough to jump into the real interupt handler.
  480.  
  481.    ( If this works like on the 56000 it should be possible
  482.      to have Fast Interupts, where the CPU returns automatically
  483.      when the 16 bytes have been executed and no jump
  484.      instructions have been executed ).
  485.  
  486. For the DSP it looks like this:
  487.  
  488. 000000        Reset          (or DSP control interupt)
  489. 000010        I2S Interupt
  490.  
  491.  
  492. Enable interupts I2S:
  493.  
  494.     movei   #D_FLAGS,r1     ; load dsp flags to go to bank 1
  495.     load    (r1),r0
  496.     bset    #5,r0           ; enable I2S interrupt
  497.     store   r0,(r1)         ; save dsp flags
  498.  
  499.  
  500. Handle i2s interupts
  501.  
  502. i2s_isr:
  503.     movei   #D_FLAGS,r30            ; get flags ptr
  504.     load    (r30),r12
  505.     bclr    #3,r12          ; clear IMASK
  506.     load    (r31),r28       ; get last instruction address
  507.     bset    #10,r12         ; clear I2S interrupt
  508.     addq    #2,r28          ; point at next to be executed
  509.     addq    #4,r31          ; update the stack pointer
  510.    ...
  511.     jump    T,(r28)         ; and return
  512.     store   r12,(r30)       ; restore flags
  513.  
  514. --- uugate 0.40 (SunOS 4.1.3)
  515.  * Origin: Internet gateway [cindy] (2:200/427.1)
  516.