| plan 9 kernel history: overview | file list | diff list |
1991/0924/pc/devfloppy.c (diff list | history)
| 1991/0921/sys/src/9/pc/devfloppy.c:6,41 – 1991/0924/sys/src/9/pc/devfloppy.c:6,47 (short | long | prev | next) | ||
| 1991/0727 | #include "io.h" | |
| 1991/0802 | #include "errno.h" | |
| 1991/0727 | ||
| 1991/0920 |
| |
| 1991/0924 | /* Intel 82077A (8272A compatible) floppy controller */ | |
| 1991/0920 | ||
| 1991/0802 | typedef struct Drive Drive; | |
| 1991/0727 | typedef struct Controller Controller; | |
| 1991/0802 | typedef struct Type Type; | |
| 1991/0727 | ||
| 1991/0924 | /* bits in the registers */ | |
| 1991/0727 | enum { | |
| 1991/0924 | /* digital output register */ Pdor= 0x3f2, Fintena= 0x8, /* enable floppy interrupt */ Fena= 0x4, /* 0 == reset controller */ | |
| 1991/0727 |
| |
| 1991/0924 | /* main status register */ Pmsr= 0x3f4, Fready= 0x80, /* ready to be touched */ Ffrom= 0x40, /* data from controller */ Fbusy= 0x10, /* operation not over */ | |
| 1991/0727 |
| |
| 1991/0831 |
| |
| 1991/0727 |
| |
| 1991/0924 | /* data register */ Pdata= 0x3f5, Frecal= 0x07, /* recalibrate cmd */ Fseek= 0x0f, /* seek cmd */ Fsense= 0x08, /* sense cmd */ Fread= 0x66, /* read cmd */ Freadid= 0x4a, /* read track id */ Fspec= 0x03, /* set hold times */ Fwrite= 0x45, /* write cmd */ Fmulti= 0x80, /* or'd with Fread or Fwrite for multi-head */ Fdumpreg= 0x0e, /* dump internal registers */ | |
| 1991/0727 | ||
| 1991/0831 |
| |
| 1991/0924 | /* digital input register */ Pdir= 0x3F7, /* disk changed port */ Fchange= 0x80, /* disk has changed */ | |
| 1991/0831 | ||
| 1991/0728 |
| |
| 1991/0727 | /* status 0 byte */ Drivemask= 3<<0, Seekend= 1<<5, | |
| 1991/0921/sys/src/9/pc/devfloppy.c:46,51 – 1991/0924/sys/src/9/pc/devfloppy.c:52,59 | ||
| 1991/0802 | Qdata= (1<<2), | |
| 1991/0920 | Qctl= (2<<2), | |
| 1991/0802 | Qmask= (3<<2), | |
| 1991/0924 | DMAchan= 2, /* floppy dma channel */ | |
| 1991/0727 | }; /* | |
| 1991/0921/sys/src/9/pc/devfloppy.c:68,78 – 1991/0924/sys/src/9/pc/devfloppy.c:76,88 | ||
| 1991/0731 | */ int bcode; /* coded version of bytes for the controller */ | |
| 1991/0727 | long cap; /* drive capacity in bytes */ | |
| 1991/0924 | long tsize; /* track size in bytes */ | |
| 1991/0727 | }; Type floppytype[] = { | |
| 1991/0731 | { "MF2HD", 512, 18, 2, 1, 80, 0x1B, 0x54, }, | |
| 1991/0924 | { "MF1DD", 512, 9, 2, 1, 80, 0x1B, 0x54, }, { "MF4HD", 1024, 18, 2, 1, 80, 0x1B, 0x54, }, | |
| 1991/0731 | { "F2HD", 512, 15, 2, 1, 80, 0x2A, 0x50, }, { "F2DD", 512, 8, 2, 2, 40, 0x2A, 0x50, }, { "F1DD", 512, 8, 1, 2, 40, 0x2A, 0x50, }, | |
| 1991/0921/sys/src/9/pc/devfloppy.c:111,117 – 1991/0924/sys/src/9/pc/devfloppy.c:121,127 | ||
| 1991/0727 | ulong lasttouched; /* time last touched */ int cyl; /* current cylinder */ | |
| 1991/0924 | int confused; /* needs to be recalibrated */ | |
| 1991/0727 | int tcyl; /* target cylinder */ int thead; /* target head */ | |
| 1991/0921/sys/src/9/pc/devfloppy.c:118,131 – 1991/0924/sys/src/9/pc/devfloppy.c:128,142 | ||
| 1991/0727 | int tsec; /* target sector */ | |
| 1991/0731 | long len; /* size of xfer */ | |
| 1991/0727 | ||
| 1991/0731 |
| |
| 1991/0924 | uchar *cache; /* track cache */ int ccyl; int chead; | |
| 1991/0809 |
| |
| 1991/0924 | Rendez r; /* waiting here for motor to spin up */ | |
| 1991/0727 | }; /* | |
| 1991/0924 | * controller for 4 floppys | |
| 1991/0727 | */ struct Controller { | |
| 1991/0921/sys/src/9/pc/devfloppy.c:132,147 – 1991/0924/sys/src/9/pc/devfloppy.c:143,159 | ||
| 1991/0731 | QLock; /* exclusive access to the contoller */ | |
| 1991/0809 | Drive *d; /* the floppy drives */ | |
| 1991/0727 |
| |
| 1991/0731 |
| |
| 1991/0924 | uchar cmd[14]; /* command */ int ncmd; /* # command bytes */ uchar stat[14]; /* command status */ int nstat; /* # status bytes */ int confused; /* controler needs to be reset */ | |
| 1991/0731 | Rendez r; /* wait here for command termination */ | |
| 1991/0921 |
| |
| 1991/0802 | ||
| 1991/0924 | int motor; /* bit mask of spinning disks */ | |
| 1991/0802 | Rendez kr; /* for motor watcher */ | |
| 1991/0727 | }; | |
| 1991/0728 |
| |
| 1991/0924 | Controller fl; | |
| 1991/0727 | ||
| 1991/0921 | #define MOTORBIT(i) (1<<((i)+4)) | |
| 1991/0921/sys/src/9/pc/devfloppy.c:148,167 – 1991/0924/sys/src/9/pc/devfloppy.c:160,180 | ||
| 1991/0727 | /* | |
| 1991/0731 | * predeclared */ | |
| 1991/0924 | static int floppycmd(void); static void floppyeject(Drive*); | |
| 1991/0731 | static void floppykproc(void*); | |
| 1991/0924 | static void floppyon(Drive*); static void floppyoff(Drive*); | |
| 1991/0802 | static void floppypos(Drive*,long); | |
| 1991/0731 |
| |
| 1991/0924 | static int floppyresult(void); | |
| 1991/0731 | static void floppyrevive(void); | |
| 1991/0924 | static long floppyseek(Drive*, long); static int floppysense(void); static void floppywait(void); | |
| 1991/0802 | static long floppyxfer(Drive*, int, void*, long, long); | |
| 1991/0731 |
| |
| 1991/0924 | static int cmddone(void*); void Xdelay(int); | |
| 1991/0731 | ||
| 1991/0802 | Dirtab floppydir[]={ | |
| 1991/0823 | "fd0disk", {Qdata + 0}, 0, 0600, | |
| 1991/0921/sys/src/9/pc/devfloppy.c:175,181 – 1991/0924/sys/src/9/pc/devfloppy.c:188,193 | ||
| 1991/0802 | }; | |
| 1991/0811 | #define NFDIR 2 /* directory entries/drive */ | |
| 1991/0731 | ||
| 1991/0809 |
| |
| 1991/0731 | void floppyreset(void) { | |
| 1991/0921/sys/src/9/pc/devfloppy.c:182,187 – 1991/0924/sys/src/9/pc/devfloppy.c:194,201 | ||
| 1991/0731 | Drive *dp; | |
| 1991/0802 | Type *t; | |
| 1991/0810 | int n; | |
| 1991/0924 | ulong p; long l; | |
| 1991/0731 | ||
| 1991/0802 | /* * init dependent parameters | |
| 1991/0921/sys/src/9/pc/devfloppy.c:189,224 – 1991/0924/sys/src/9/pc/devfloppy.c:203,240 | ||
| 1991/0802 | for(t = floppytype; t < &floppytype[NTYPES]; t++){ t->cap = t->bytes * t->heads * t->sectors * t->tracks; t->bcode = b2c[t->bytes/128]; | |
| 1991/0924 | t->tsize = t->bytes * t->sectors; | |
| 1991/0802 | } /* | |
| 1991/0809 | * allocate the drive storage */ | |
| 1991/0924 | fl.d = ialloc(conf.nfloppy*sizeof(Drive), 0); | |
| 1991/0809 | /* | |
| 1991/0802 | * stop the motors */ | |
| 1991/0809 |
| |
| 1991/0731 |
| |
| 1991/0924 | fl.motor = 0; delay(10); outb(Pdor, fl.motor | Fintena | Fena); delay(10); /* * init drives */ for(dp = fl.d; dp < &fl.d[conf.nfloppy]; dp++){ dp->dev = dp - fl.d; | |
| 1991/0731 | dp->t = &floppytype[0]; /* default type */ | |
| 1991/0811 | floppydir[NFDIR*dp->dev].length = dp->t->cap; | |
| 1991/0921 |
| |
| 1991/0802 | dp->cyl = -1; /* because we don't know */ | |
| 1991/0731 |
| |
| 1991/0924 | dp->cache = (uchar*)ialloc(dp->t->tsize, 1); dp->ccyl = -1; | |
| 1991/0731 | } | |
| 1991/0809 | /* | |
| 1991/0924 | * first operation will recalibrate | |
| 1991/0809 | */ | |
| 1991/0810 |
| |
| 1991/0809 |
| |
| 1991/0731 |
| |
| 1991/0924 | fl.confused = 1; | |
| 1991/0731 | } void | |
| 1991/0921/sys/src/9/pc/devfloppy.c:288,380 – 1991/0924/sys/src/9/pc/devfloppy.c:304,419 | ||
| 1991/0802 | error(Eperm); } | |
| 1991/0809 |
| |
| 1991/0831 |
| |
| 1991/0902 |
| |
| 1991/0831 |
| |
| 1991/0920 |
| |
| 1991/0831 |
| |
| 1991/0809 |
| |
| 1991/0731 | long floppyread(Chan *c, void *a, long n) { Drive *dp; | |
| 1991/0809 |
| |
| 1991/0731 |
| |
| 1991/0924 | long rv, i; int nn, sec, head, cyl; long len; long noff; uchar *aa; | |
| 1991/0731 | ||
| 1991/0802 | if(c->qid.path == CHDIR) | |
| 1991/0811 | return devdirread(c, a, n, floppydir, conf.nfloppy*NFDIR, devgen); | |
| 1991/0802 | rv = 0; | |
| 1991/0924 | dp = &fl.d[c->qid.path & ~Qmask]; | |
| 1991/0802 | switch ((int)(c->qid.path & Qmask)) { case Qdata: | |
| 1991/0831 |
| |
| 1991/0809 | if(c->offset % dp->t->bytes) errors("bad offset"); if(n % dp->t->bytes) errors("bad len"); | |
| 1991/0924 | aa = a; nn = dp->t->tsize; | |
| 1991/0809 | for(rv = 0; rv < n; rv += len){ /* | |
| 1991/0924 | * truncate xfer at track boundary | |
| 1991/0809 | */ dp->len = n - rv; floppypos(dp, c->offset+rv); cyl = dp->tcyl; | |
| 1991/0924 | head = dp->thead; | |
| 1991/0809 | len = dp->len; | |
| 1991/0924 | sec = dp->tsec; | |
| 1991/0809 | /* | |
| 1991/0924 | * read the track | |
| 1991/0809 | */ | |
| 1991/0924 | if(dp->ccyl!=cyl || dp->chead!=head){ | |
| 1991/0809 | dp->ccyl = -1; | |
| 1991/0924 | i = floppyxfer(dp, Fread, dp->cache, (cyl*dp->t->heads+head)*nn, nn); if(i != nn){ if(i == 0) break; | |
| 1991/0809 | errors("floppy read err"); | |
| 1991/0924 | } | |
| 1991/0809 | dp->ccyl = cyl; | |
| 1991/0924 | dp->chead = head; | |
| 1991/0809 | } | |
| 1991/0924 | memmove(aa+rv, dp->cache + (sec-1)*dp->t->bytes, len); | |
| 1991/0802 | } break; | |
| 1991/0924 | case Qctl: break; | |
| 1991/0802 | default: panic("floppyread: bad qid"); | |
| 1991/0731 | } | |
| 1991/0924 | ||
| 1991/0731 | return rv; } | |
| 1991/0924 | #define SNCMP(a, b) strncmp(a, b, sizeof(b)-1) | |
| 1991/0731 | long floppywrite(Chan *c, void *a, long n) { Drive *dp; long rv, i; | |
| 1991/0924 | char *aa = a; int dev; | |
| 1991/0731 | ||
| 1991/0802 | rv = 0; | |
| 1991/0924 | dp = &fl.d[c->qid.path & ~Qmask]; | |
| 1991/0802 | switch ((int)(c->qid.path & Qmask)) { case Qdata: | |
| 1991/0831 |
| |
| 1991/0924 | if(c->offset % dp->t->bytes) errors("bad offset"); if(n % dp->t->bytes) errors("bad len"); | |
| 1991/0802 | for(rv = 0; rv < n; rv += i){ | |
| 1991/0924 | floppypos(dp, c->offset+rv); if(dp->tcyl == dp->ccyl) dp->ccyl = -1; i = floppyxfer(dp, Fwrite, aa+rv, c->offset+rv, n-rv); | |
| 1991/0802 | if(i <= 0) break; } break; | |
| 1991/0924 | case Qctl: if(SNCMP(aa, "eject") == 0){ floppyeject(dp); } else if(SNCMP(aa, "seek") == 0){ aa += 5; floppyseek(dp, strtoul(aa, 0, 0)); } else if(SNCMP(aa, "den") == 0){ aa += 4; i = strtoul(aa, 0, 0); USED(i); /* devp->dsr = i; devp->ccr = i;/**/ } else if(SNCMP(aa, "reset") == 0){ floppyon(dp); } break; | |
| 1991/0802 | default: panic("floppywrite: bad qid"); | |
| 1991/0731 | } | |
| 1991/0924 | ||
| 1991/0731 | return rv; } | |
| 1991/0921/sys/src/9/pc/devfloppy.c:382,434 – 1991/0924/sys/src/9/pc/devfloppy.c:421,473 | ||
| 1991/0731 | floppykproc(void *a) | |
| 1991/0727 | { Drive *dp; | |
| 1991/0803 |
| |
| 1991/0924 | int i; static int last; | |
| 1991/0727 | ||
| 1991/0919 | while(waserror()) ; | |
| 1991/0802 | for(;;){ | |
| 1991/0809 |
| |
| 1991/0921 |
| |
| 1991/0924 | i = inb(Pdir) & 0x80; if(i != last) print("fromn %d to %d\n", last, i); last = i; for(dp = fl.d; dp < &fl.d[conf.nfloppy]; dp++){ if((fl.motor&MOTORBIT(dp->dev)) | |
| 1991/0921 | && TK2SEC(m->ticks - dp->lasttouched) > 5 | |
| 1991/0802 | && canqlock(dp)){ if(TK2SEC(m->ticks - dp->lasttouched) > 5) | |
| 1991/0924 | floppyoff(dp); | |
| 1991/0802 | qunlock(dp); } | |
| 1991/0728 | } | |
| 1991/0803 |
| |
| 1991/0802 |
| |
| 1991/0803 | ||
| 1991/0924 | tsleep(&fl.kr, return0, 0, 5*100); | |
| 1991/0727 | } } | |
| 1991/0921 |
| |
| 1991/0731 | /* | |
| 1991/0921 |
| |
| 1991/0924 | * start a floppy drive's motor. | |
| 1991/0921 | */ static void | |
| 1991/0924 | floppyon(Drive *dp) | |
| 1991/0921 | { int alreadyon; | |
| 1991/0924 | int tries; | |
| 1991/0921 |
| |
| 1991/0924 | if(fl.confused) floppyrevive(); /* start motor and select drive */ alreadyon = fl.motor & MOTORBIT(dp->dev); fl.motor |= MOTORBIT(dp->dev); outb(Pdor, fl.motor | Fintena | Fena | dp->dev); | |
| 1991/0921 | if(!alreadyon) tsleep(&dp->r, return0, 0, 750); | |
| 1991/0924 | /* get drive to a known cylinder */ if(dp->confused) for(tries = 0; tries < 4; tries++) if(floppyrecal(dp) >= 0) break; | |
| 1991/0921 | dp->lasttouched = m->ticks; } | |
| 1991/0921/sys/src/9/pc/devfloppy.c:436,584 – 1991/0924/sys/src/9/pc/devfloppy.c:475,613 | ||
| 1991/0921 | * stop the floppy if it hasn't been used in 5 seconds */ static void | |
| 1991/0924 | floppyoff(Drive *dp) | |
| 1991/0921 | { | |
| 1991/0924 | fl.motor &= ~MOTORBIT(dp->dev); outb(Pdor, fl.motor | Fintena | Fena | dp->dev); | |
| 1991/0921 | } /* | |
| 1991/0731 |
| |
| 1991/0924 | * eject disk ( unknown on safari ) | |
| 1991/0731 | */ | |
| 1991/0727 |
| |
| 1991/0924 | static void floppyeject(Drive *dp) | |
| 1991/0727 | { | |
| 1991/0924 | floppyon(dp); floppyoff(dp); | |
| 1991/0727 | } | |
| 1991/0731 | /* | |
| 1991/0924 | * send a command to the floppy | |
| 1991/0731 | */ static int | |
| 1991/0727 |
| |
| 1991/0924 | floppycmd(void) | |
| 1991/0727 | { | |
| 1991/0924 | int i; | |
| 1991/0727 | int tries; | |
| 1991/0924 | for(i = 0; i < fl.ncmd; i++){ for(tries = 0; ; tries++){ if(tries > 1000){ print("cmd %ux can't be sent (%d %ux)\n", fl.cmd[0], i, inb(Pmsr)); fl.confused = 1; return -1; } if((inb(Pmsr)&(Ffrom|Fready)) == Fready) break; } outb(Pdata, fl.cmd[i]); | |
| 1991/0727 | } | |
| 1991/0924 | return 0; | |
| 1991/0727 | } | |
| 1991/0731 | /* | |
| 1991/0924 | * get a command result from the floppy * * when the controller goes ready waiting for a command * (instead of sending results), we're done * | |
| 1991/0731 | */ static int | |
| 1991/0924 | floppyresult(void) | |
| 1991/0727 | { | |
| 1991/0924 | int i, s; int tries; | |
| 1991/0727 |
| |
| 1991/0924 | for(i = 0; i < sizeof(fl.stat); i++){ for(tries = 0; ; tries++){ if(tries > 1000){ fl.confused = 1; return -1; } s = inb(Pmsr)&(Ffrom|Fready); if(s == Fready){ fl.nstat = i; return i; } if(s == (Ffrom|Fready)) break; } fl.stat[i] = inb(Pdata); | |
| 1991/0727 | } | |
| 1991/0924 | fl.nstat = i; return i; | |
| 1991/0727 | } | |
| 1991/0731 | /* * calculate physical address of a logical byte offset into the disk * | |
| 1991/0924 | * truncate dp->length if it crosses a track boundary | |
| 1991/0731 | */ static void | |
| 1991/0802 | floppypos(Drive *dp, long off) | |
| 1991/0727 | { int lsec; | |
| 1991/0924 | int ltrack; | |
| 1991/0727 | int end; int cyl; | |
| 1991/0924 | int track; | |
| 1991/0727 | ||
| 1991/0802 | lsec = off/dp->t->bytes; | |
| 1991/0727 |
| |
| 1991/0924 | ltrack = lsec/dp->t->sectors; dp->tcyl = ltrack/dp->t->heads; | |
| 1991/0727 | dp->tsec = (lsec % dp->t->sectors) + 1; dp->thead = (lsec/dp->t->sectors) % dp->t->heads; /* | |
| 1991/0924 | * can't read across track boundaries. | |
| 1991/0727 | * if so, decrement the bytes to be read. */ | |
| 1991/0802 |
| |
| 1991/0727 |
| |
| 1991/0731 |
| |
| 1991/0727 |
| |
| 1991/0924 | end = (ltrack+1)*dp->t->sectors*dp->t->bytes; if(off+dp->len > end) dp->len = end - off; | |
| 1991/0727 | } | |
| 1991/0731 | /* | |
| 1991/0924 | * get the interrupt cause from the floppy. | |
| 1991/0731 | */ static int | |
| 1991/0727 |
| |
| 1991/0924 | floppysense(void) | |
| 1991/0727 | { | |
| 1991/0924 | fl.ncmd = 0; fl.cmd[fl.ncmd++] = Fsense; if(floppycmd() < 0) | |
| 1991/0727 | return -1; | |
| 1991/0731 |
| |
| 1991/0727 |
| |
| 1991/0924 | if(floppyresult() < 2){ print("can't read sense response\n"); fl.confused = 1; | |
| 1991/0727 | return -1; } | |
| 1991/0802 |
| |
| 1991/0727 |
| |
| 1991/0924 | static int cmddone(void *a) { return fl.ncmd == 0; } | |
| 1991/0731 | /* | |
| 1991/0924 | * wait for a floppy interrupt | |
| 1991/0731 | */ | |
| 1991/0924 | static void floppywait(void) | |
| 1991/0731 | { | |
| 1991/0924 | tsleep(&fl.r, cmddone, 0, 2000); | |
| 1991/0731 | } /* | |
| 1991/0921/sys/src/9/pc/devfloppy.c:587,621 – 1991/0924/sys/src/9/pc/devfloppy.c:616,641 | ||
| 1991/0731 | static int | |
| 1991/0727 | floppyrecal(Drive *dp) { | |
| 1991/0731 |
| |
| 1991/0924 | int type; | |
| 1991/0727 |
| |
| 1991/0924 | dp->ccyl = -1; | |
| 1991/0727 |
| |
| 1991/0924 | fl.ncmd = 0; fl.cmd[fl.ncmd++] = Frecal; fl.cmd[fl.ncmd++] = dp->dev; if(floppycmd() < 0) return -1; floppywait(); if(fl.nstat < 2){ fl.confused = 1; return -1; } if((fl.stat[0] & (Codemask|Seekend)) != Seekend){ | |
| 1991/0727 | dp->confused = 1; return -1; } | |
| 1991/0924 | dp->cyl = fl.stat[1]/dp->t->steps; if(dp->cyl != 0){ | |
| 1991/0727 | print("recalibrate went to wrong cylinder %d\n", dp->cyl); dp->confused = 1; return -1; | |
| 1991/0921/sys/src/9/pc/devfloppy.c:635,714 – 1991/0924/sys/src/9/pc/devfloppy.c:655,714 | ||
| 1991/0727 | Drive *dp; /* | |
| 1991/0731 |
| |
| 1991/0924 | * reset the controller if it's confused | |
| 1991/0727 | */ | |
| 1991/0924 | if(fl.confused){ | |
| 1991/0727 | /* reset controller and turn all motors off */ | |
| 1991/0924 | fl.cmd[0] = 0; outb(Pdor, 0); | |
| 1991/0727 | delay(1); | |
| 1991/0924 | outb(Pdor, Fintena|Fena); | |
| 1991/0727 | spllo(); | |
| 1991/0809 |
| |
| 1991/0924 | for(dp = fl.d; dp < &fl.d[conf.nfloppy]; dp++) | |
| 1991/0727 | dp->confused = 1; | |
| 1991/0921 |
| |
| 1991/0731 |
| |
| 1991/0727 |
| |
| 1991/0924 | fl.motor = 0; floppywait(); fl.confused = 0; /* devp->dsr = 0; devp->ccr = 0; /**/ | |
| 1991/0727 | } | |
| 1991/0809 |
| |
| 1991/0727 |
| |
| 1991/0924 | /* * seek to the target cylinder * * interrupt, no results */ | |
| 1991/0731 | static long | |
| 1991/0924 | floppyseek(Drive *dp, long off) | |
| 1991/0727 | { | |
| 1991/0924 | floppyon(dp); floppypos(dp, off); | |
| 1991/0802 | if(dp->cyl == dp->tcyl) return dp->cyl; | |
| 1991/0727 |
| |
| 1991/0802 |
| |
| 1991/0727 |
| |
| 1991/0731 |
| |
| 1991/0727 |
| |
| 1991/0924 | /* print("seeking tcyl %d, thead %d\n", dp->tcyl, dp->thead); /**/ fl.ncmd = 0; fl.cmd[fl.ncmd++] = Fseek; fl.cmd[fl.ncmd++] = (dp->thead<<2) | dp->dev; fl.cmd[fl.ncmd++] = dp->tcyl * dp->t->steps; if(floppycmd() < 0){ | |
| 1991/0727 | print("seek cmd failed\n"); | |
| 1991/0731 |
| |
| 1991/0727 |
| |
| 1991/0924 | floppywait(); if(fl.nstat < 2){ fl.confused = 1; | |
| 1991/0727 | return -1; | |
| 1991/0924 | } if((fl.stat[0] & (Codemask|Seekend)) != Seekend){ | |
| 1991/0727 | print("seek failed\n"); dp->confused = 1; return -1; } | |
| 1991/0924 | dp->cyl = dp->tcyl; | |
| 1991/0802 | return dp->cyl; | |
| 1991/0727 | } | |
| 1991/0921/sys/src/9/pc/devfloppy.c:716,800 – 1991/0924/sys/src/9/pc/devfloppy.c:716,812 | ||
| 1991/0802 | floppyxfer(Drive *dp, int cmd, void *a, long off, long n) | |
| 1991/0727 | { long offset; | |
| 1991/0924 | ulong up; | |
| 1991/0727 | ||
| 1991/0731 |
| |
| 1991/0924 | if(off >= dp->t->cap) return 0; if(off + n > dp->t->cap) n = dp->t->cap - off; qlock(&fl); | |
| 1991/0731 | qlock(dp); | |
| 1991/0802 | if(waserror()){ | |
| 1991/0731 |
| |
| 1991/0924 | dmaend(DMAchan); qunlock(&fl); | |
| 1991/0731 | qunlock(dp); | |
| 1991/0924 | fl.confused = 1; nexterror(); | |
| 1991/0731 | } | |
| 1991/0727 | /* | |
| 1991/0731 |
| |
| 1991/0727 |
| |
| 1991/0731 |
| |
| 1991/0921 |
| |
| 1991/0727 | ||
| 1991/0731 |
| |
| 1991/0727 | dp->len = n; | |
| 1991/0802 |
| |
| 1991/0731 |
| |
| 1991/0924 | if(floppyseek(dp, off) < 0) | |
| 1991/0731 | errors("seeking floppy"); | |
| 1991/0727 | ||
| 1991/0906 | ||
| 1991/0823 | /*print("tcyl %d, thead %d, tsec %d, addr %lux, n %d\n", | |
| 1991/0906 |
| |
| 1991/0924 | dp->tcyl, dp->thead, dp->tsec, a, dp->len);/**/ | |
| 1991/0727 | /* | |
| 1991/0731 | * set up the dma (dp->len may be trimmed) | |
| 1991/0727 | */ | |
| 1991/0731 |
| |
| 1991/0924 | dp->len = dmasetup(DMAchan, a, dp->len, cmd==Fread); | |
| 1991/0727 | /* | |
| 1991/0731 | * start operation | |
| 1991/0727 | */ | |
| 1991/0802 |
| |
| 1991/0727 |
| |
| 1991/0802 |
| |
| 1991/0727 |
| |
| 1991/0731 |
| |
| 1991/0727 |
| |
| 1991/0924 | /* cmd = cmd | (dp->t->heads > 1 ? Fmulti : 0);/**/ fl.ncmd = 0; fl.cmd[fl.ncmd++] = cmd; fl.cmd[fl.ncmd++] = (dp->thead<<2) | dp->dev; fl.cmd[fl.ncmd++] = dp->tcyl * dp->t->steps; fl.cmd[fl.ncmd++] = dp->thead; fl.cmd[fl.ncmd++] = dp->tsec; fl.cmd[fl.ncmd++] = dp->t->bcode; fl.cmd[fl.ncmd++] = dp->tsec + dp->len/dp->t->bytes - 1; fl.cmd[fl.ncmd++] = dp->t->gpl; fl.cmd[fl.ncmd++] = 0xFF; if(floppycmd() < 0){ spllo(); | |
| 1991/0727 | print("xfer cmd failed\n"); | |
| 1991/0731 | errors("floppy command failed"); | |
| 1991/0727 | } | |
| 1991/0731 |
| |
| 1991/0727 | /* | |
| 1991/0731 |
| |
| 1991/0727 |
| |
| 1991/0924 | * give bus to DMA, floppyintr() will read result */ floppywait(); dmaend(DMAchan); /* * check for errors */ if(fl.nstat < 7){ print("xfer result failed %lux\n", inb(Pmsr)); fl.confused = 1; | |
| 1991/0731 | errors("floppy result failed"); | |
| 1991/0727 | } | |
| 1991/0731 |
| |
| 1991/0924 | if((fl.stat[0] & Codemask)!=0 || fl.stat[1] || fl.stat[2]){ if(fl.stat[1] != 0x80){ print("xfer failed %lux %lux %lux\n", fl.stat[0], fl.stat[1], fl.stat[2]); print("offset %lud len %d\n", off, dp->len); dp->confused = 1; errors("floppy drive lost"); } else fl.stat[5]++; | |
| 1991/0727 | } | |
| 1991/0731 |
| |
| 1991/0924 | /* * check for correct cylinder */ offset = (fl.stat[3]/dp->t->steps) * dp->t->heads + fl.stat[4]; offset = offset*dp->t->sectors + fl.stat[5] - 1; offset = offset * c2b[fl.stat[6]]; | |
| 1991/0802 | if(offset != off+dp->len){ | |
| 1991/0924 | print("new offset %d instead of %d\n", offset, off+dp->len); | |
| 1991/0727 | dp->confused = 1; | |
| 1991/0731 | errors("floppy drive lost"); | |
| 1991/0727 | } | |
| 1991/0802 | dp->lasttouched = m->ticks; | |
| 1991/0731 |
| |
| 1991/0924 | qunlock(&fl); | |
| 1991/0731 | qunlock(dp); poperror(); | |
| 1991/0921/sys/src/9/pc/devfloppy.c:801,810 – 1991/0924/sys/src/9/pc/devfloppy.c:813,835 | ||
| 1991/0727 | return dp->len; } | |
| 1991/0731 |
| |
| 1991/0727 |
| |
| 1991/0924 | void floppyintr(void) | |
| 1991/0727 | { | |
| 1991/0823 |
| |
| 1991/0727 |
| |
| 1991/0731 |
| |
| 1991/0924 | switch(fl.cmd[0]&~Fmulti){ case Fread: case Fwrite: floppyresult(); break; case Freadid: floppyresult(); break; case Fseek: case Frecal: default: floppysense(); /* to clear interrupt */ break; } fl.ncmd = 0; wakeup(&fl.r); | |
| 1991/0727 | } | |