Subversion Repositories pentevo

Rev

Blame | Last modification | View Log | Download | RSS feed | ?url?

  1. ; /*--------------------------------------------------*/
  2. ; /*                                                  */
  3. ; /* Module GENSCSI.SS                                */
  4. ; /*                                                  */
  5. ; /* SCRIPTS routines for generic SCSI operations.    */
  6. ; /*                                                  */
  7. ; /* Adapted from Symbios Logic                       */
  8. ; /*    Software Development Kit                      */
  9. ; /*                                                  */
  10. ; /* Project: A Programmer's Guide to SCSI            */
  11. ; /* Copyright (C) 1997, Brian Sawert.                */
  12. ; /* All rights reserved.                             */
  13. ; /* Syntax adapted to AS to serve as a test case     */
  14. ; /*                                                  */
  15. ; /*--------------------------------------------------*/
  16.  
  17.  
  18. ; /*--------------------------------------------------*/
  19. ; /*                                                  */
  20. ; /* This script is a generic skeleton for issuing    */
  21. ; /* SCSI commands. It handles arbitration, message   */
  22. ; /* in and out, status and data in.                  */
  23. ; /*                                                  */
  24. ; /* Uses table indirect mode for command, data, and  */
  25. ; /* other buffers.                                   */
  26. ; /*                                                  */
  27. ; /*--------------------------------------------------*/
  28.  
  29.  
  30. ;---------- set architecture for 53C825
  31.         cpu     sym53c825
  32.  
  33.  
  34. ;---------- set constant values
  35. err_cmd_complete        equ     0x00000000
  36. err_not_msgout          equ     0x00000001
  37. err_bad_reselect        equ     0x00000002
  38. err_bad_phase           equ     0x00000004
  39.  
  40.  
  41. ;---------- set up table definitions
  42.  
  43. scsi_id         db      0x33, 0x00, 0x00, 0x00
  44. msgout_buf      db      0x80, 0x00
  45. cmd_buf         db      0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  46. stat_buf        db      ?
  47. msgin_buf       db      2 dup (?)
  48. exmsgin_buf     db      4 dup (?)
  49. datain_buf      db      0x40 dup (?)
  50.  
  51. GEN_SCRIPT:     align   4
  52.  
  53. ;---------- start SCSI target selection
  54. start_scsi:
  55.  
  56. ; select device from encoded SCSI ID
  57. ; set ATN for message out after select
  58.         SELECT ATN FROM scsi_id, REL(bad_reselect)
  59.  
  60. ;---------- send identify message
  61. ; exit if not message out phase
  62.         INT err_not_msgout, WHEN NOT MSG_OUT
  63.  
  64. ; send identify message
  65.         MOVE FROM msgout_buf, WHEN MSG_OUT
  66.         JUMP REL(handle_phase)
  67.  
  68. ;---------- send SCSI command
  69. send_cmd:
  70.  
  71. ; send command block to target
  72.         MOVE FROM cmd_buf, WHEN CMD
  73.         JUMP REL(handle_phase)
  74.  
  75. ;---------- get SCSI status
  76. get_status:
  77.  
  78. ; read status byte from data bus
  79.         MOVE FROM stat_buf, WHEN STATUS
  80.         JUMP REL(handle_phase)
  81.  
  82. ;---------- get SCSI message input
  83. get_msgin:
  84.  
  85. ; read message byte from data bus
  86.         MOVE FROM msgin_buf, WHEN MSG_IN
  87.         CLEAR ACK
  88.  
  89. ; handle Command Complete message
  90.         JUMP REL(cmd_complete), IF 0x00
  91.  
  92. ; handle Disconnect message
  93.         JUMP REL(wait_disconnect), IF 0x04
  94.  
  95. ; handle extended message
  96.         JUMP REL(ext_msgin), IF 0x01
  97.         JUMP REL(handle_phase)
  98.  
  99. ;---------- handle extended message
  100. ext_msgin:
  101.  
  102. ; read extended message from data bus
  103.         MOVE FROM exmsgin_buf, WHEN MSG_IN
  104.         CLEAR ACK
  105.         JUMP REL(handle_phase)
  106.  
  107. ;---------- get data input
  108. get_datain:
  109.  
  110. ; read data from bus
  111.         MOVE FROM datain_buf, WHEN DATA_IN
  112.         JUMP REL(handle_phase)
  113.  
  114. ;---------- handle SCSI phases
  115. handle_phase:
  116.  
  117. ; jump to appropriate handler for phase
  118.         JUMP REL(get_status), WHEN STATUS
  119.         JUMP REL(get_msgin), WHEN MSG_IN
  120.         JUMP REL(get_datain), WHEN DATA_IN
  121.         JUMP REL(send_cmd), WHEN COMMAND
  122. ; unhandled phase
  123.         INT err_bad_phase
  124.  
  125. ;---------- SCSI command execution complete
  126. cmd_complete:
  127.  
  128. ; command complete - wait for disconnect
  129.         MOVE SCNTL2 & 0x7F to SCNTL2
  130.         CLEAR ACK
  131.         WAIT DISCONNECT
  132.         INT err_cmd_complete
  133.  
  134. ;---------- handle invalid select or reselect
  135. bad_reselect:
  136.  
  137. ; unhandled reselect
  138.         INT err_bad_reselect
  139.  
  140. ;---------- handle disconnect before reselect
  141. wait_disconnect:
  142.  
  143.         MOVE SCNTL2 & 0x7F to SCNTL2
  144.         CLEAR ACK
  145.         WAIT DISCONNECT
  146.  
  147. ; clear DMA and SCSI fifos
  148.         MOVE CTEST3 | 0x04 to CTEST3
  149.         MOVE STEST3 | 0x02 to STEST3
  150.  
  151. ; wait for reselect
  152.         WAIT RESELECT REL(bad_reselect)
  153.  
  154. ; expect identify message
  155.         MOVE FROM msgin_buf, WHEN MSG_IN
  156.         CLEAR ACK
  157.  
  158. ; shortcut to update sync and wide options
  159.         SELECT FROM scsi_id, REL(handle_phase)
  160.  
  161. ;---------- entry point for general SCSI script
  162.         end     start_scsi
  163.