home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / src / cmd / standalone / ht.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-03  |  2.5 KB  |  169 lines

  1. /*
  2.  * TJU16 tape driver
  3.  */
  4.  
  5. #include <sys/param.h>
  6. #include <sys/inode.h>
  7. #include "saio.h"
  8.  
  9. struct    device
  10. {
  11.     int    htcs1;
  12.     int    htwc;
  13.     caddr_t    htba;
  14.     int    htfc;
  15.     int    htcs2;
  16.     int    htds;
  17.     int    hter;
  18.     int    htas;
  19.     int    htck;
  20.     int    htdb;
  21.     int    htmr;
  22.     int    htdt;
  23.     int    htsn;
  24.     int    httc;
  25.     int    htbae;    /* 11/70 bus extension */
  26.     int    htcs3;
  27. };
  28.  
  29.  
  30.  
  31. #define    HTADDR    ((struct device *)0172440)
  32.  
  33. #define    GO    01
  34. #define    WCOM    060
  35. #define    RCOM    070
  36. #define    NOP    0
  37. #define    WEOF    026
  38. #define    SFORW    030
  39. #define    SREV    032
  40. #define    ERASE    024
  41. #define    REW    06
  42. #define    DCLR    010
  43. #define CLR    040
  44. #define P800    01300        /* 800 + pdp11 mode */
  45. #define    P1600    02300        /* 1600 + pdp11 mode */
  46. #define    IENABLE    0100
  47. #define    RDY    0200
  48. #define    TM    04
  49. #define    DRY    0200
  50. #define EOT    02000
  51. #define CS    02000
  52. #define COR    0100000
  53. #define PES    040
  54. #define WRL    04000
  55. #define MOL    010000
  56. #define PIP    020000
  57. #define ERR    040000
  58. #define FCE    01000
  59. #define    TRE    040000
  60. #define HARD    064023    /* UNS|OPI|NEF|FMT|RMR|ILR|ILF */
  61.  
  62. #define    SIO    1
  63. #define    SSFOR    2
  64. #define    SSREV    3
  65. #define SRETRY    4
  66. #define SCOM    5
  67. #define SOK    6
  68.  
  69. htopen(io)
  70. register struct iob *io;
  71. {
  72.     register skip;
  73. int i;
  74.  
  75.     htstrategy(io, REW);
  76.     skip = io->i_boff;
  77.     while (skip--) {
  78.         io->i_cc = -1;
  79.         while (htstrategy(io, SFORW))
  80.             ;
  81.         i = 0;
  82.         while (--i)
  83.             ;
  84.         htstrategy(io, NOP);
  85.     }
  86. }
  87.  
  88. htclose(io)
  89. register struct iob *io;
  90. {
  91.     htstrategy(io, REW);
  92. }
  93.  
  94. htstrategy(io, func)
  95. register struct iob *io;
  96. {
  97.     register unit, den, errcnt;
  98.  
  99.     unit = io->i_unit;
  100.     errcnt = 0;
  101. retry:
  102.     HTADDR->htcs2 = unit&03;
  103.     if(unit > 3)
  104.         den = P1600;
  105.     else
  106.         den = P800;
  107.     htquiet();
  108.     if((HTADDR->httc&03777) != den)
  109.         HTADDR->httc = den;
  110.     HTADDR->htba = io->i_ma;
  111.     HTADDR->htfc = -io->i_cc;
  112.     HTADDR->htwc = -(io->i_cc>>1);
  113.     den = ((segflag) << 8) | GO;
  114.     if (func == READ)
  115.         den =| RCOM;
  116.     else if (func == WRITE)
  117.         den =| WCOM;
  118.     else if (func == SREV) {
  119.         HTADDR->htfc = -1;
  120.         HTADDR->htcs1 = den | SREV;
  121.         return(0);
  122.     } else
  123.         den |= func;
  124.     HTADDR->htcs1 = den;
  125.     while ((HTADDR->htcs1&RDY) == 0)
  126.         ;
  127.     if (HTADDR->htds&TM) {
  128.         htinit();
  129.         return(0);
  130.     }
  131.     if (HTADDR->htcs1&TRE) {
  132.         if (errcnt == 0)
  133.             printf("tape error: cs2=%o, er=%o",
  134.                 HTADDR->htcs2, HTADDR->hter);
  135.         htinit();
  136.         if (errcnt == 10) {
  137.             printf("\n");
  138.             return(-1);
  139.         }
  140.         errcnt++;
  141.         htstrategy(io, SREV);
  142.         goto retry;
  143.     }
  144.     if (errcnt)
  145.         printf(" recovered by retry\n");
  146.     return(io->i_cc+HTADDR->htfc);
  147. }
  148.  
  149. htinit()
  150. {
  151.     int omt, ocs2;
  152.  
  153.     omt = HTADDR->httc & 03777;
  154.     ocs2 = HTADDR->htcs2 & 07;
  155.  
  156.     HTADDR->htcs2 = CLR;
  157.     HTADDR->htcs2 = ocs2;
  158.     HTADDR->httc = omt;
  159.     HTADDR->htcs1 = DCLR|GO;
  160. }
  161.  
  162. htquiet()
  163. {
  164.     while ((HTADDR->htcs1&RDY) == 0)
  165.         ;
  166.     while (HTADDR->htds&PIP)
  167.         ;
  168. }
  169.