Annotation of cci/sys/stand/udcformat.c, revision 1.1

1.1     ! root        1: /* format disk - cmd/smd type */
        !             2: 
        !             3: #include "../machine/mtpr.h"
        !             4: #include "../h/param.h"
        !             5: #include "../h/inode.h"
        !             6: #include "../h/fs.h"
        !             7: #include "../vba/udc.h"
        !             8: #include "saio.h"
        !             9: 
        !            10: char disk[50] = "xmd(00,000)";
        !            11: 
        !            12: main()
        !            13: {
        !            14:        int j, c, i, n;
        !            15:        char buf[50];
        !            16:        int output;
        !            17: 
        !            18:        do {
        !            19:                printf("Device to format: ");
        !            20:                gets(disk);
        !            21:                output = open(disk, 1);
        !            22:                if (output <= 0) printf("Cannot open disk\n", disk);
        !            23:                /* dummy call just to get to the local strategy routine */
        !            24:                else {
        !            25:                        printf("Type  <return> to start formatting ");
        !            26:                        gets(buf);
        !            27:                        write(output,buf,0); 
        !            28:                        printf("Formatting completed. \n");
        !            29:                }
        !            30:        } while (output <= 0);
        !            31: 
        !            32: }
        !            33: 
        !            34: /*
        !            35:  *  Universal disk controller driver for the Motorola M68000/IPC.
        !            36:  *     Stand-alone version (no interrupts, etc.)
        !            37:  */
        !            38: 
        !            39: 
        !            40: static struct UDPAC udpkt = {
        !            41:        2, 0, 21, 0, 0, 0, 0, SECTSIZ, {0, 0}, 0, 0, 3
        !            42: } ;
        !            43: 
        !            44: long udstd[] = {       /* May be used some day to boot from any of
        !            45:                         *  several UDC controllers */
        !            46:        0xf0000 
        !            47: };
        !            48: 
        !            49: /*****************************************************
        !            50: /*
        !            51: /*The next layout of major/minor number assignments are for the UDC
        !            52: /*devices.
        !            53: /*
        !            54: /*       1
        !            55: /*       5              8 7     4 3 2   0
        !            56: /*      +----------------+-----+-+-+-----+
        !            57: /*      | Major device # |     |D|R| FLS |
        !            58: /*      +----------------+-----+-+-+-----+
        !            59: /*                              | |   |_____ File system # ( 0-7 )
        !            60: /*                              | |_________ Fixed (0) or removable(1) media
        !            61: /*                              |___________ Drive # (0-1)
        !            62: /*
        !            63: /* For the floppy drives, the major / minor assignment will be
        !            64: /*       1
        !            65: /*       5              8 7     4 3 2   0
        !            66: /*      +----------------+-----+---+-----+
        !            67: /*      |      4         |     | D | FLS |
        !            68: /*      +----------------+-----+---+-----+
        !            69: /*                               |    |_____ File system # ( 0-7 )
        !            70: /*                               |____________ Drive # (0-3)
        !            71: /*     
        !            72: /****************************************************/
        !            73: 
        !            74: #define        UDCUNIT(x)      ((minor(x) & 0x18) >> 3)
        !            75: 
        !            76: udstrategy(io, func)
        !            77: register struct iob *io;
        !            78: long func;             /* Known to be 'read' */
        !            79: {
        !            80: 
        !            81:        register unit = io->i_unit;
        !            82:        register bn = io->i_bn;
        !            83:        register char *cntaddr ;
        !            84:        register char *addr ;
        !            85:        register timeout , retries , i;
        !            86: 
        !            87:        cntaddr = (char *)(udstd[0] + IOBASE); /* Booting from cntrlr 0 */
        !            88:        /*
        !            89:         * prepare a command packet for the controller.
        !            90:         */
        !            91:        retries = 3;
        !            92: loop:
        !            93:        if (cntaddr[OB1]) {
        !            94:                printf("UDC controller not ready, %x=%x\n",OB1+cntaddr,
        !            95:                        cntaddr[OB1] & 0xff);
        !            96:                return(0);
        !            97:        }
        !            98:        udpkt._pksiz = 7 ;
        !            99:        udpkt._pkid = 0xAA ;
        !           100:        udpkt._pkdev = UDCUNIT(unit);
        !           101:        udpkt._pkcmd = 0x40;    /* control command */
        !           102:        if (io->i_ino.i_dev == 1) { 
        !           103:                udpkt._pkdev += 4;  /* Floppy */
        !           104:                udpkt._pkfnc = 2; /* format floppy */
        !           105:        }
        !           106:        else udpkt._pkfnc = 2;  /* format disk */
        !           107:        udpkt._pkcnt = 3 << 8;  /* EOT (sort of) */
        !           108:        if (movep21(&udpkt,cntaddr+0x105,7)) {
        !           109:                cntaddr[OB1] = (char)0x80 ;     /* signal packet transmitted */
        !           110:                cntaddr[IB2] = (char)0 ;        /* clear ACK/NAK field */
        !           111:                cntaddr[INT] = (char)0x0 ;      /* interrupt the controller */
        !           112:        }
        !           113:        else {
        !           114:                printf ("Wrong command packet arrived at UDC\n");
        !           115:                printf ("Original       UDC\n");
        !           116:                for (i = 0; i < sizeof(udpkt); i++ ) 
        !           117:                        printf("   %0x\t%0x\n", ((char *)&udpkt)[i*2] & 0xff,
        !           118:                                cntaddr[0x105+i*2] & 0xff);
        !           119:        }
        !           120: /*
        !           121:  *
        !           122:  * Wait until done (no interrupts now).
        !           123:  *
        !           124:  */
        !           125: wait:
        !           126:        timeout  =  10000;
        !           127:        while (cntaddr[IB2] != (char)0x06 && cntaddr[IB2] != (char)0x15) {
        !           128: /**************
        !           129:                DELAY(10000);           
        !           130:                timeout--;
        !           131:                if (timeout <= 0) {
        !           132:                        printf("UDC controller timeout\n");
        !           133:                        return(0);
        !           134:                }
        !           135: *****************/
        !           136:        }
        !           137:        udpkt._pksiz = 21;
        !           138:        if (cntaddr[IB2] == (char)0x15) {
        !           139:                if (retries-- < 0) {
        !           140:                        printf("Too many NAK from UDC - give up\n");
        !           141:                        return(0);
        !           142:                } else goto loop;
        !           143:        }
        !           144: 
        !           145:        while (cntaddr[IB1] != (char)DEVRDY)
        !           146: /*             DELAY (10000);          /* Wait for his response */;
        !           147: 
        !           148: 
        !           149:        /* Ignore unsolicited status messages */
        !           150:        if (cntaddr[PKID] != (char)udpkt._pkid && cntaddr[PKSTT] == (char)0x80)
        !           151:        {
        !           152:                cntaddr[IB1] = (char)0;
        !           153:                cntaddr[OB2] = (char)6;
        !           154:                cntaddr[INT] = (char)0x80;
        !           155:                goto loop;
        !           156:        }
        !           157:        if (cntaddr[PKID] != (char)udpkt._pkid ||
        !           158:                cntaddr[PKDEV] != (char)udpkt._pkdev ||
        !           159:                cntaddr[PKLEN] != (char)19 ||
        !           160:                cntaddr[PKCMD] != (char)udpkt._pkcmd ||
        !           161:                cntaddr[PKSTT] != (char)0x70 || /* Command completion */
        !           162:                cntaddr[STAT1] != (char)0 ||
        !           163:                cntaddr[STAT2] != (char)0 ) {
        !           164:                        printf ("Strange status from UDC:\n");
        !           165:                        printf("Packet id=%x,unit=%x,original command=%x,status type=%x,status=%x\n", 
        !           166:                        cntaddr[PKID] & 0xff,
        !           167:                        cntaddr[PKDEV] & 0xff,
        !           168:                        cntaddr[PKCMD] & 0xff, 
        !           169:                        cntaddr[PKSTT] & 0xff,
        !           170:                        (cntaddr[STAT1]*256+cntaddr[STAT2]) & 0xffff);
        !           171:                        if  (cntaddr[PKLEN] > 9) {
        !           172:                                printf("More response info : ");
        !           173:                                for (i=1; i<=cntaddr[PKLEN]-9; i++)
        !           174:                                      printf("%x ", cntaddr[STAT2+2*i] & 0xff);
        !           175:                                printf("\n");
        !           176:                        }
        !           177:                        cntaddr[IB1] = (char)0;
        !           178:                        cntaddr[OB2] = (char)6;
        !           179:                        cntaddr[INT] = (char)0x80;
        !           180:                        return(0);
        !           181:        } else {
        !           182:                cntaddr[IB1] = (char)0;
        !           183:                cntaddr[OB2] = (char)6;
        !           184:                cntaddr[INT] = (char)0x80;
        !           185:                mtpr (0, PADC);         /* So data will come in right */
        !           186:                return(io->i_cc);
        !           187:          }
        !           188: }
        !           189: 
        !           190: /*
        !           191:  *     Transfer a 21 bytes packet to the controller.
        !           192:  *  the message is written to odd addresses, starting from
        !           193:  *  the given address.
        !           194:  *     For reliability, read it back and see if it's the same. If not,
        !           195:  *  return an error code.
        !           196:  */
        !           197: movep21(src, dest,cnt)
        !           198: 
        !           199: char   *src, *dest;
        !           200: int cnt;
        !           201: {
        !           202:        register char *running_src,  *running_dest;
        !           203:        register long running_cnt;
        !           204: 
        !           205:        running_src = src;
        !           206:        running_dest = dest;
        !           207:        running_cnt = cnt;
        !           208: 
        !           209:        for (; running_cnt>0; running_cnt--) {
        !           210:                *running_dest++ = *running_src++;
        !           211:                running_dest++;
        !           212:        }
        !           213:        running_src = src;
        !           214:        running_dest = dest;
        !           215:        running_cnt = cnt;
        !           216:        for (; running_cnt>0; running_cnt--) {
        !           217:                if (*running_dest++ != *running_src++) return(0);
        !           218:                running_dest++;
        !           219:        }
        !           220:        return(1);
        !           221: }
        !           222: 
        !           223: udopen(io)
        !           224: struct iob *io;
        !           225: {
        !           226:        register char *cntaddr;
        !           227: /*
        !           228:  * Just clean up any junk in the controller's response buffers.
        !           229:  */    
        !           230:        cntaddr = (char *)(udstd[0] + IOBASE); /* Booting from cntrlr 0 */
        !           231:        while (cntaddr[IB1] == (char)DEVRDY) {
        !           232:                cntaddr[IB1] = (char)0;
        !           233:                cntaddr[OB2] = (char)0x06;  /* ACK */
        !           234:                cntaddr[INT] = (char)0; /* Force him to listen and  respond */
        !           235:                DELAY(50000);
        !           236:        }
        !           237: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.