Annotation of driverkit/tests/fx.m, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
                      7:  * Reserved.  This file contains Original Code and/or Modifications of
                      8:  * Original Code as defined in and that are subject to the Apple Public
                      9:  * Source License Version 1.1 (the "License").  You may not use this file
                     10:  * except in compliance with the License.  Please obtain a copy of the
                     11:  * License at http://www.apple.com/publicsource and read it before using
                     12:  * this file.
                     13:  * 
                     14:  * The Original Code and all software distributed under the License are
                     15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.  Please see the
                     19:  * License for the specific language governing rights and limitations
                     20:  * under the License.
                     21:  * 
                     22:  * @APPLE_LICENSE_HEADER_END@
                     23:  */
                     24: /* 
                     25:  *  fx - DiskObject-type Floppy exerciser
                     26:  *
                     27:  *     Linked with FloppyDisk and FloppyController objects.
                     28:  *
                     29:  */
                     30: 
                     31: #import <bsd/dev/FloppyDisk.h>
                     32: #import <driverkit/return.h>
                     33: #import <bsd/dev/FloppyTypes.h>
                     34: #import <bsd/dev/nrw/FloppyCnt.h>
                     35: #import <architecture/m88k/floppy_channel.h>
                     36: #import <bsd/sys/types.h>
                     37: #import <bsd/sys/param.h>
                     38: #import <bsd/dev/disk.h>
                     39: #import <bsd/dev/fd_extern.h>
                     40: #import <driverkit/align.h>
                     41: #import <driverkit/generalFuncs.h>
                     42: #import <bsd/libc.h>
                     43: #import <mach/mach.h>
                     44: #import "fd_lib.h"
                     45: #import "buflib.h"
                     46: #import <mach/mach_error.h>
                     47: #import <machdep/m88k/xpr.h>
                     48: #import <driverkit/volCheck.h>
                     49: #import <mach/cthreads.h>
                     50: 
                     51: #undef FAKE_HARDWARE
                     52: #define FAKE_HARDWARE  1
                     53: 
                     54: void usage(char **argv);
                     55: 
                     56: #define MAX_IOSIZE     0x40
                     57: 
                     58: struct menu_entry {
                     59:        char    menu_c;
                     60:        char    *name;
                     61:        void    (*men_fcn)();
                     62: };
                     63: 
                     64: 
                     65: void fx_read();
                     66: void fx_write();
                     67: void fx_slc();
                     68: void fx_sbyc();
                     69: void fx_sbn();
                     70: void fx_dump_rb();
                     71: void fx_zwb();
                     72: void fx_iwb();
                     73: void fx_compare();
                     74: void fx_readlp();
                     75: void print_menu();
                     76: void fx_eject();
                     77: void fx_motoroff();
                     78: void fx_quit();
                     79: void fx_seek();
                     80: void fx_readid();
                     81: void fx_strack();
                     82: void fx_recal();
                     83: void fx_setformat();
                     84: void fx_getformat();
                     85: void fx_format();
                     86: void fx_cwb();
                     87: void fx_sad();
                     88: void fx_dumpreg();
                     89: void fx_sboff();
                     90: int fx_setformatparms();
                     91: void fx_setretry();
                     92: void fx_getretry();
                     93: void fx_sblkccnt();
                     94: 
                     95: struct menu_entry me_array[] = {
                     96: 
                     97:     {'r', "Read               ", fx_read      }, {'i', "wbuf = Incrementing", fx_iwb       },
                     98:     {'w', "Write              ", fx_write     }, {'z', "Zero Write Buffer  ", fx_zwb       },
                     99:     {'L', "Read Loop          ", fx_readlp    }, {'1', "Set Data = sect #  ", fx_sad       },
                    100:     {'c', "Set Loop Count     ", fx_slc              }, {'k', "Set Constant Data  ", fx_cwb       },
                    101:     {'y', "Set Byte Count     ", fx_sbyc      }, {'d', "Dump Read Buffer   ", fx_dump_rb   },
                    102:     {'b', "Set Block Number   ", fx_sbn       }, {'m', "Compare w/r Buffers", fx_compare   },
                    103:     {'t', "Set Track          ", fx_strack    }, {'S', "Set Format         ", fx_setformat },
                    104:     {'B', "Set Block Count    ", fx_sblkccnt  }, {'g', "Get Format         ", fx_getformat },
                    105:     {'C', "Recalibrate        ", fx_recal     }, {'F', "Format Track       ", fx_format    },
                    106:     {'o', "Motor Off          ", fx_motoroff  }, {'R', "Read ID            ", fx_readid    },
                    107:     {'e', "Eject Disk         ", fx_eject     }, {'D', "Dump Registers     ", fx_dumpreg   },
                    108:     {'f', "Set Buffer Offset  ", fx_sboff     }, {'2', "Get Retry Counts   ", fx_getretry  },
                    109:     {'s', "Seek               ", fx_seek      }, {'3', "Set Retry Counts   ", fx_setretry  },
                    110:     {'x', "Exit Program       ", fx_quit      }, {'h', "Print This menu    ", print_menu   }, 
                    111:     {0,    NULL,                      NULL        },
                    112:      
                    113: }; /* me_array */
                    114: 
                    115: #define SIZEOF_REGS    10
                    116: 
                    117: #define SECTSIZE_DEF   512
                    118: #define BUFSIZE                0x8000
                    119: 
                    120: id                     fd;
                    121: u_char                 *wbuffer;
                    122: u_char                 *rbuffer;
                    123: u_char                 *wbuf;
                    124: u_char                 *rbuf;
                    125: int                    rtn;
                    126: int                    loop_count=1;
                    127: int                    byte_count=SECTSIZE_DEF;
                    128: int                    block_count = 1;
                    129: int                    block_num=0;
                    130: int                    loop_count;
                    131: int                    track;
                    132: struct fd_format_info  format_info;
                    133: boolean_t              use_rawio=TRUE;
                    134: int                    lblocksize;             /* logical block size */
                    135: u_int                  fmt_gap_length = -1;
                    136: port_name_t            ownerPort;
                    137: 
                    138: int main(int argc, char *argv[]) {
                    139: 
                    140:        char            c[80];
                    141:        struct          menu_entry *mep;
                    142:        char            ok, ch;
                    143:        int             arg;
                    144:        id              cntrlId;
                    145:        port_name_t     dev_port;
                    146:        kern_return_t   krtn;
                    147:        
                    148:        for(arg=1; arg<argc; arg++) {
                    149:                ch = argv[arg][0];
                    150:                switch(ch) {
                    151:                    default:
                    152:                        ASSERT(0);
                    153:                        usage(argv);
                    154:                }
                    155:        }
                    156: 
                    157:        /*
                    158:         * Init libraries.
                    159:         */
                    160: #ifdef DDM_DEBUG
                    161:        IOInitDDM(1000, "FloppyXpr");
                    162:        /* 
                    163:         * Maybe pass this in in argv...
                    164:         */
                    165:        IOSetDDMMask(XPR_IODEVICE_INDEX,
                    166:                 XPR_FDD | XPR_FC | XPR_DEVICE | XPR_DISK | XPR_ERR | 
                    167:                 XPR_VC | XPR_NDMA);
                    168: #endif DDM_DEBUG
                    169:        IOInitGeneralFuncs();
                    170:        volCheckInit();
                    171: 
                    172:        krtn = port_allocate(task_self(), &dev_port);
                    173:        if(krtn) {
                    174:                mach_error("port_allocate", krtn);
                    175:                exit(1);
                    176:        }
                    177:        cntrlId = [FloppyController probe:0 deviceMaster:PORT_NULL];
                    178:        if(cntrlId == nil) {
                    179:                printf("FloppyController probe: returned nil; exiting\n");
                    180:                exit(1);
                    181:        }
                    182:        fd = [FloppyDisk probe:cntrlId sender:nil];
                    183:        if(cntrlId == nil) {
                    184:                printf("FloppyDisk probe: returned nil; exiting\n");
                    185:                exit(1);
                    186:        }
                    187:        
                    188:        /*
                    189:         * Set up for well-aligned transfers
                    190:         */
                    191:        wbuffer = malloc(BUFSIZE + 2 * FLOPPY_BUFSIZE);
                    192:        rbuffer = malloc(BUFSIZE + 2 * FLOPPY_BUFSIZE);
                    193:        wbuf = IOAlign(u_char *, wbuffer, FLOPPY_BUFSIZE);
                    194:        rbuf = IOAlign(u_char *, rbuffer, FLOPPY_BUFSIZE);
                    195:        
                    196:        /*
                    197:         * get the physical block size
                    198:         */
                    199:        fx_setformatparms();
                    200:        print_menu();
                    201:        while(1) {
                    202:                printf("Enter Selection: ");
                    203:                gets(c);
                    204:                mep = me_array;
                    205:                ok = 0;
                    206:                while(mep->menu_c) {
                    207:                        if(mep->menu_c == c[0]) {
                    208:                                ok = 1;
                    209:                                (*mep->men_fcn)();
                    210:                                break;
                    211:                        }
                    212:                        else
                    213:                                mep++;
                    214:                }
                    215:                if(!ok)
                    216:                        printf("***Illegal Selection\n");
                    217:        }
                    218: 
                    219: } /* main() */
                    220: 
                    221: void usage(char **argv) {
                    222:        printf("usage: %s\n", argv[0]);
                    223:        exit(1);
                    224: }
                    225: 
                    226: void print_menu() {
                    227:        
                    228:        struct menu_entry *mep;
                    229:        
                    230:        printf("\n");
                    231:        mep = me_array;
                    232:        while(mep->menu_c) {
                    233:                printf(" %c: %s        ",mep->menu_c,mep->name);
                    234:                mep++;
                    235:                if(mep->menu_c) {
                    236:                        printf(" %c: %s\n",mep->menu_c,mep->name);
                    237:                        mep++;
                    238:                }
                    239:                else
                    240:                        printf("\n\n");
                    241:        }
                    242: 
                    243: } /* print_menu() */
                    244: 
                    245: 
                    246: void fx_read() {
                    247: 
                    248:        fd_rw(fd,
                    249:                block_num,
                    250:                byte_count / lblocksize,
                    251:                rbuf,
                    252:                TRUE,                           /* read */
                    253:                lblocksize,
                    254:                FALSE);                         /* io_trace */
                    255: }
                    256: 
                    257: void fx_readlp() {
                    258: 
                    259:        /* 
                    260:         * read block block_num, length = 1 sector, for loop_count loops 
                    261:         */
                    262:        int loop;
                    263:        
                    264:        for(loop=0; loop<loop_count; loop++) {
                    265:                if(fd_rw(fd,
                    266:                        block_num,
                    267:                        byte_count / lblocksize,
                    268:                        rbuf,
                    269:                        TRUE,                   /* read */
                    270:                        lblocksize,
                    271:                        FALSE))                 /* io_trace */
                    272:                                return;
                    273:        }
                    274:        return;
                    275: }
                    276: 
                    277: void fx_write() {
                    278: 
                    279:        fd_rw(fd,
                    280:                block_num,
                    281:                byte_count / lblocksize,
                    282:                wbuf,
                    283:                FALSE,                          /* read */
                    284:                lblocksize,
                    285:                FALSE);                         /* io_trace */
                    286: }
                    287: 
                    288: 
                    289: void fx_seek() {
                    290:        int rtn;
                    291:        int density;
                    292:        
                    293:        if(format_info.density_info.density == FD_DENS_NONE)
                    294:                density = FD_DENS_4;
                    295:        else
                    296:                density = format_info.density_info.density;
                    297:        rtn = seek_com(fd, track, &format_info, TRUE, density);
                    298:        if(rtn == FDR_SUCCESS)
                    299:                printf("...OK\n");
                    300:        return;
                    301: }
                    302: 
                    303: void fx_readid() {
                    304:        struct fd_ioreq ioreq;
                    305:        struct fd_readid_cmd *cmdp = (struct fd_readid_cmd *)ioreq.cmd_blk;
                    306:        struct fd_rw_stat *statp = (struct fd_rw_stat *)ioreq.stat_blk;
                    307:        int density;
                    308:        
                    309:        if(format_info.density_info.density == FD_DENS_NONE)
                    310:                density = FD_DENS_4;
                    311:        else
                    312:                density = format_info.density_info.density;
                    313:        
                    314:        bzero(&ioreq, sizeof(struct fd_ioreq));
                    315:        cmdp->opcode = FCCMD_READID;
                    316:        cmdp->mfm = 1;
                    317:        cmdp->hds = track & 1;          /* lsb of track */
                    318:        
                    319:        ioreq.timeout = 2000;
                    320:        ioreq.density = density;
                    321:        ioreq.command = FDCMD_CMD_XFR;
                    322:        ioreq.num_cmd_bytes = sizeof(struct fd_readid_cmd);
                    323:        ioreq.num_stat_bytes = SIZEOF_RW_STAT;  /* expect a fd_rw_stat */
                    324:        if(do_ioc(fd, &ioreq, TRUE))
                    325:                return;
                    326:        printf("\tcyl    = %d(d)\n", statp->cylinder);
                    327:        printf("\thead   = %d(d)\n", statp->head);
                    328:        printf("\tsector = %d(d)\n", statp->sector);
                    329:        return;
                    330: }
                    331: 
                    332: void fx_recal() {
                    333:        struct fd_ioreq ioreq;
                    334:        struct fd_seek_cmd *cmdp = (struct fd_seek_cmd *)ioreq.cmd_blk;
                    335:        int rtn;
                    336:        int density;
                    337:        
                    338:        if(format_info.density_info.density == FD_DENS_NONE)
                    339:                density = FD_DENS_4;
                    340:        else
                    341:                density = format_info.density_info.density;
                    342:        bzero(&ioreq, sizeof(struct fd_ioreq));
                    343:        cmdp->opcode = FCCMD_RECAL;
                    344:        ioreq.density = density;
                    345:        ioreq.timeout = 2000;
                    346:        ioreq.command = FDCMD_CMD_XFR;
                    347:        ioreq.num_cmd_bytes = sizeof(struct fd_recal_cmd);
                    348:        ioreq.addrs = 0;
                    349:        ioreq.byte_count = 0;
                    350:        ioreq.num_stat_bytes = sizeof(struct fd_int_stat);
                    351:        rtn = do_ioc(fd, &ioreq, TRUE);
                    352:        if(rtn == FDR_SUCCESS)
                    353:                printf("...OK\n");
                    354:        return;
                    355: }
                    356: 
                    357: 
                    358: void fx_slc() {
                    359: 
                    360:        while(1) {
                    361:                printf("Enter loop count (CR = %d(d)): ", loop_count);
                    362:                loop_count = get_num(loop_count, DEC);
                    363:                if(loop_count < 1)
                    364:                        printf("Loop Count must be > 0\n");
                    365:                else 
                    366:                        return;
                    367:        }
                    368: }
                    369: 
                    370: void fx_sbyc() {
                    371:        
                    372:        int sectsize;
                    373:        
                    374:        printf("Enter byte count (CR = 0x%x): ",byte_count);
                    375:        byte_count = get_num(byte_count, HEX);
                    376:        sectsize = format_info.sectsize_info.sect_size;
                    377:        if(sectsize == 0)
                    378:                sectsize = 512;
                    379:        block_count = byte_count / format_info.sectsize_info.sect_size;
                    380: }
                    381: 
                    382: void fx_sbn() {
                    383: 
                    384:        printf("Enter block number (CR = %d(d)): ",block_num);
                    385:        block_num = get_num(block_num, DEC);
                    386: }
                    387: 
                    388: void fx_sblkccnt()
                    389: {
                    390:        int sectsize;
                    391:        
                    392:        printf("Enter Block count (CR = 0x%x): ", block_count);
                    393:        block_count = get_num(byte_count, HEX);
                    394:        sectsize = format_info.sectsize_info.sect_size;
                    395:        if(sectsize == 0)
                    396:                sectsize = 512;
                    397:        byte_count = sectsize * block_count;
                    398: 
                    399: }
                    400: 
                    401: void fx_sboff() {
                    402:        char instr[80];
                    403:        int offset;
                    404:        
                    405:        while(1) {
                    406:                printf("Enter new offset (0..15): ");
                    407:                gets(instr);
                    408:                offset = atoi(instr);
                    409:                if((offset < 0) || (offset > 15)) 
                    410:                        printf("try again.\n");
                    411:                else
                    412:                        break;
                    413:        }
                    414:        rbuf = IOAlign(u_char *, rbuffer, FLOPPY_BUFSIZE) + offset;
                    415:        wbuf = IOAlign(u_char *, wbuffer, FLOPPY_BUFSIZE) + offset;
                    416:        printf("...rbuf = 0x%x   wbuf = 0x%x\n", rbuf, wbuf);
                    417: 
                    418: }
                    419: void fx_strack() {
                    420:        printf("Enter track (CR = %d(d)): ",track);
                    421:        track = get_num(track, DEC);
                    422: }
                    423: 
                    424: void fx_setretry() {
                    425:        int retry;
                    426:        IOReturn rtn;
                    427: 
                    428:        retry =  [fd innerRetry];
                    429:        printf("Inner Retry Count: (CR=%d(d)): ", retry);
                    430:        retry = get_num(retry, DEC);
                    431:        rtn = [fd fdSetInnerRetry:retry];
                    432:        if(rtn) {
                    433:                pr_iortn_text(fd, "setInnerRetry", rtn);
                    434:                return;
                    435:        }
                    436: 
                    437:        retry = [fd outerRetry];
                    438:        printf("Outer Retry Count: (CR=%d(d)): ", retry);
                    439:        retry = get_num(retry, DEC);
                    440:        rtn = [fd fdSetOuterRetry:retry];
                    441:        if(rtn) {
                    442:                pr_iortn_text(fd, "setOuterRetry", rtn);
                    443:                return;
                    444:        }
                    445:        return;
                    446: }
                    447: 
                    448: void fx_getretry() {
                    449:        int retry;
                    450:        
                    451:        retry = [fd innerRetry];
                    452:        printf("Inner Retry Count: %d\n", retry);
                    453:        retry = [fd outerRetry];
                    454:        printf("Outer Retry Count: %d\n", retry);
                    455:        return;
                    456: }
                    457: 
                    458: void dump_format_info(struct fd_format_info *fip)
                    459: {
                    460:        printf("\tmedia_id        %d\n",   fip->disk_info.media_id);
                    461:        printf("\tdensity         %d\n",   fip->density_info.density);
                    462:        printf("\tformatted       ");
                    463:        if(fip->flags & FFI_FORMATTED)
                    464:                printf("TRUE\n");
                    465:        else
                    466:                printf("FALSE\n");
                    467:        printf("\tlabel valid     ");
                    468:        if(fip->flags & FFI_LABELVALID)
                    469:                printf("TRUE\n");
                    470:        else
                    471:                printf("FALSE\n");
                    472:        printf("\twrite protect   ");
                    473:        if(fip->flags & FFI_WRITEPROTECT)
                    474:                printf("TRUE\n");
                    475:        else
                    476:                printf("FALSE\n");
                    477:        printf("\tsect_size       %xH\n",   fip->sectsize_info.sect_size);
                    478:        printf("\tsects_per_trk   %d(d)\n", fip->sectsize_info.sects_per_trk);
                    479:        printf("\ttracks_per_cyl  %d(d)\n", fip->disk_info.tracks_per_cyl);
                    480:        printf("\tnum_cylinders   %d(d)\n", fip->disk_info.num_cylinders);
                    481:        printf("\ttotal_sects     %d(d)\n", fip->total_sects);
                    482:        printf("\tmfm             ");
                    483:        if(fip->density_info.mfm)
                    484:                printf("TRUE\n");
                    485:        else
                    486:                printf("FALSE\n");
                    487:        printf("\trw gap length   %d(d)\n", 
                    488:                fip->sectsize_info.rw_gap_length);
                    489:        printf("\tfmt gap length  %d(d)\n", 
                    490:                fip->sectsize_info.fmt_gap_length);
                    491: }
                    492: 
                    493: void fx_getformat() {
                    494: 
                    495:        IOReturn rtn;
                    496:        
                    497:        rtn = [fd fdGetFormatInfo:&format_info];
                    498:        if(rtn) {
                    499:                pr_iortn_text(fd, "getFormatInfo", rtn);
                    500:                return;
                    501:        }
                    502:        printf("\nFormat information:\n");
                    503:        dump_format_info(&format_info);
                    504:        printf("\n");
                    505: }
                    506: 
                    507: void fx_setformat() {
                    508: 
                    509:        char instr[80];
                    510:        struct fd_format_info *fip = &format_info;
                    511:        struct fd_density_info *dip = &fip->density_info;
                    512:        IOReturn rtn;
                    513:        
                    514:        /*
                    515:         * allow user to set density, sector size, gap length. We assume
                    516:         * that out format_info has been obtained from the driver.
                    517:         */
                    518:        printf("Enter density (CR = %d(d)): ", dip->density);
                    519:        dip->density = get_num(dip->density, DEC);
                    520:        printf("Enter sect_size (CR = %d(d)): ", fip->sectsize_info.sect_size);
                    521:        fip->sectsize_info.sect_size = 
                    522:                get_num(fip->sectsize_info.sect_size, DEC);
                    523: 
                    524:        /*
                    525:         * Since the gap default gap lengths are really a function
                    526:         * of both the density and the sector size, it's impossible
                    527:         * to print out what the default is until both the density
                    528:         * and sector size have been set.  So rather than print a
                    529:         * value for the default, this just says "DEFAULT" and prints
                    530:         * the new gap values after the density and sector size have
                    531:         * been set.
                    532:         */
                    533:        printf("Enter rw gap3 length (CR = %d(d)): ",
                    534:                fip->sectsize_info.rw_gap_length);
                    535:        fip->sectsize_info.rw_gap_length = 
                    536:                get_num(fip->sectsize_info.rw_gap_length, DEC);
                    537:        printf("Enter fmt gap3 length (CR = DEFAULT): ");
                    538:        fmt_gap_length = get_num(fmt_gap_length, DEC);
                    539:        printf("\n...Send To Driver (y/anything)? ");
                    540:        gets(instr);
                    541:        if(instr[0] != 'y') {
                    542:                return;
                    543:        }
                    544:        rtn = [fd fdSetDensity:dip->density];
                    545:        if(rtn) {
                    546:                pr_iortn_text(fd, "fdSetDensity", rtn);
                    547:                return;
                    548:        }
                    549:        rtn = [fd fdSetSectSize:fip->sectsize_info.sect_size];
                    550:        if(rtn) {
                    551:                pr_iortn_text(fd, "fdSetSectSize", rtn);
                    552:                return;
                    553:        }
                    554:        rtn = [fd fdSetGapLength:fip->sectsize_info.rw_gap_length];
                    555:        if(rtn) {
                    556:                pr_iortn_text(fd, "fdSetGapLength", rtn);
                    557:                return;
                    558:        }
                    559: 
                    560:        /*
                    561:         * Now get remainder of physical parameters from driver.
                    562:         */
                    563:        if(fx_setformatparms() == 0) {
                    564:                printf("...Format Parameters Stored by Driver\n");
                    565:                printf("Rw gap length  = %d(d)\n",
                    566:                    format_info.sectsize_info.rw_gap_length);
                    567:                printf("Fmt gap length = %d(d)\n", fmt_gap_length);
                    568:                return;
                    569:        }
                    570: }
                    571: 
                    572: void fx_format() {
                    573:        struct format_data *fdp, *fdp_align;
                    574:        int sector;
                    575:        struct fd_ioreq ioreq;
                    576:        struct fd_format_cmd *cmdp = (struct fd_format_cmd *)ioreq.cmd_blk;
                    577:        int data_size;
                    578:        int rtn=0;
                    579:        int fmt_cyl;
                    580:        int fmt_head;
                    581:        
                    582:        data_size = sizeof(struct format_data) *
                    583:            format_info.sectsize_info.sects_per_trk;
                    584:        fdp = malloc(data_size + (2 * FLOPPY_BUFSIZE));
                    585:        if(fdp == 0) {
                    586:                printf("Couldn't malloc memory for format data\n");
                    587:                return;
                    588:        }
                    589:        fdp_align = IOAlign(struct format_data *, fdp, FLOPPY_BUFSIZE);
                    590:        fmt_cyl  = track / format_info.disk_info.tracks_per_cyl;
                    591:        fmt_head = track % format_info.disk_info.tracks_per_cyl;
                    592:        for(sector = 1;
                    593:            sector <= format_info.sectsize_info.sects_per_trk;
                    594:            sector++) {
                    595:                fdp_align->cylinder = fmt_cyl;
                    596:                fdp_align->head = fmt_head;
                    597:                fdp_align->sector = sector;
                    598:                fdp_align->n = format_info.sectsize_info.n;
                    599:                fdp_align++;
                    600:        }
                    601:        if(seek_com(fd, track, &format_info, TRUE,
                    602:            format_info.density_info.density)) {
                    603:                printf("Seek Failed\n");
                    604:                free(fdp);
                    605:                return;
                    606:        }
                    607:        usleep(20000);          /* head settling time - 20 ms */
                    608:        
                    609:        /*
                    610:         * Build a format command 
                    611:         */
                    612:        bzero(&ioreq, sizeof (struct fd_ioreq));
                    613:        
                    614:        ioreq.density = format_info.density_info.density;
                    615:        ioreq.timeout = 5000;
                    616:        ioreq.command = FDCMD_CMD_XFR;
                    617:        ioreq.num_cmd_bytes = sizeof(struct fd_format_cmd);
                    618:        ioreq.addrs = (caddr_t)fdp_align;
                    619:        
                    620:        /*
                    621:         * Note we can't do a DMA write using the actual byte count we want.
                    622:         * Even worse, we won't really know how many bytes moved! Hardware
                    623:         * feature...
                    624:         */
                    625:        ioreq.byte_count = IOAlign(int, data_size, FLOPPY_BUFSIZE);
                    626:        ioreq.num_stat_bytes = SIZEOF_RW_STAT;
                    627:        ioreq.flags = FD_IOF_DMA_WR;
                    628:        
                    629:        cmdp->mfm = format_info.density_info.mfm;
                    630:        cmdp->opcode =FCCMD_FORMAT;
                    631:        cmdp->hds = fmt_head;
                    632:        cmdp->n = format_info.sectsize_info.n;
                    633:        cmdp->sects_per_trk = format_info.sectsize_info.sects_per_trk;
                    634:        cmdp->gap_length = fmt_gap_length;
                    635:        cmdp->filler_data = 0x5a;
                    636:        rtn = do_ioc(fd, &ioreq, TRUE);
                    637:        free(fdp);
                    638:        if(rtn == FDR_SUCCESS)
                    639:                printf("...OK\n");
                    640: }
                    641: 
                    642: void fx_dumpreg() {
                    643:        struct fd_ioreq ioreq;
                    644:        int rtn;
                    645:        int i;
                    646:        struct fd_82077_regs *regptr = (struct fd_82077_regs *)ioreq.stat_blk;
                    647:        int density;
                    648:        
                    649:        if(format_info.density_info.density == FD_DENS_NONE)
                    650:                density = FD_DENS_4;
                    651:        else
                    652:                density = format_info.density_info.density;
                    653:        bzero(&ioreq, sizeof(struct fd_ioreq));
                    654:        ioreq.cmd_blk[0] = FCCMD_DUMPREG;
                    655:        ioreq.density = density;
                    656:        ioreq.timeout = 2000;
                    657:        ioreq.command = FDCMD_CMD_XFR;
                    658:        ioreq.num_cmd_bytes = 1;
                    659:        ioreq.addrs = 0;
                    660:        ioreq.byte_count = 0;
                    661:        ioreq.num_stat_bytes = SIZEOF_REGS;
                    662:        rtn = do_ioc(fd, &ioreq, TRUE);
                    663:        if(rtn != FDR_SUCCESS)
                    664:                return;
                    665:        /*
                    666:         * Print registers 
                    667:         */
                    668:        printf("82077 Register Dump (all base 10):\n");
                    669:        for(i=0; i<4; i++)
                    670:                printf("   pcn%d   : %d\n", i, regptr->pcn[i]);
                    671:        printf("   srt    : %d\n", regptr->srt);
                    672:        printf("   hut    : %d\n", regptr->hut);
                    673:        printf("   hlt    : %d\n", regptr->hlt);
                    674:        printf("   nd     : %d\n", regptr->nd);
                    675:        printf("   sc_eot : %d\n", regptr->sc_eot);
                    676:        printf("   eis    : %d\n", regptr->eis);
                    677:        printf("   efifo  : %d\n", regptr->efifo);
                    678:        printf("   poll   : %d\n", regptr->poll);
                    679:        printf("   fifothr: %d\n", regptr->fifothr);
                    680:        printf("   pretrk : %d\n", regptr->pretrk);
                    681:        printf("\n");
                    682: }
                    683: void fx_dump_rb() {    
                    684:        printf("Read Buffer:");
                    685:        dump_buf(rbuf, BUFSIZE);
                    686: }
                    687: 
                    688: 
                    689: void fx_zwb() {
                    690: 
                    691:        register int i;
                    692:        register unsigned char *p;
                    693:        
                    694:        p = wbuf;
                    695:        for(i=0; i<BUFSIZE; i++)
                    696:                *p++ = 0;
                    697:        printf("...OK\n");
                    698: }
                    699: 
                    700: void fx_cwb() {
                    701: 
                    702:        register int i;
                    703:        register int *p;
                    704:        int dp=0;
                    705:        
                    706:        printf("Enter data pattern (CR=0x0): ");
                    707:        dp = get_num(0, HEX);
                    708:        p = (int *)wbuf;
                    709:        for(i=0; i<BUFSIZE/4; i++)
                    710:                *p++ = dp;
                    711: }
                    712: 
                    713: void fx_sad() {
                    714: 
                    715:        register int i;
                    716:        register int *p;
                    717:        int sect_num=0;
                    718:        int word_win_sect=0;
                    719:        int words_per_sect = format_info.sectsize_info.sect_size / 4;
                    720:        
                    721:        printf("Enter starting sector # (CR=0x0): ");
                    722:        sect_num = get_num(0, HEX);
                    723:        p = (int *)wbuf;
                    724:        for(i=0; i<BUFSIZE/4; i++) {
                    725:                *p++ = sect_num;
                    726:                if(++word_win_sect == words_per_sect) {
                    727:                        sect_num++;
                    728:                        word_win_sect = 0;
                    729:                }
                    730:        }
                    731: }
                    732: 
                    733: 
                    734: void fx_iwb() {
                    735: 
                    736:        register int i;
                    737:        register unsigned char *p;
                    738:        
                    739:        p = wbuf;
                    740:        for(i=0; i<BUFSIZE; i++)
                    741:                *p++ = (char)(i & 0xFF);
                    742:        printf("...OK\n");
                    743: }
                    744: 
                    745: void fx_compare() {
                    746:        buf_comp(byte_count, wbuf, rbuf);
                    747: }
                    748: 
                    749: void fx_eject() 
                    750: {
                    751:        IOReturn rtn;
                    752:        
                    753:        rtn = [fd ejectPhysical];
                    754:        if(rtn) 
                    755:                pr_iortn_text(fd, "ejectPhysical", rtn);
                    756:        else
                    757:                printf("...OK\n");
                    758:        return;
                    759: }
                    760: 
                    761: void fx_motoroff() {
                    762: 
                    763:        struct fd_ioreq ioreq;
                    764:        int density;
                    765:        
                    766:        if(format_info.density_info.density == FD_DENS_NONE)
                    767:                density = FD_DENS_4;
                    768:        else
                    769:                density = format_info.density_info.density;     
                    770:        bzero(&ioreq, sizeof (struct fd_ioreq));
                    771:        ioreq.density = density;
                    772:        ioreq.timeout = 1000;
                    773:        ioreq.command = FDCMD_MOTOR_OFF;
                    774:        ioreq.byte_count = 0;
                    775:        if(!do_ioc(fd, &ioreq, FALSE))
                    776:                printf("...OK\n");
                    777:        return;
                    778: }
                    779: 
                    780: void fx_quit() {
                    781: #ifdef notdef
                    782:        if (close(fd) < 0) {
                    783:                perror("close");
                    784:                exit(1);
                    785:        }
                    786: #endif notdef
                    787:        exit(0);
                    788: }
                    789: 
                    790: int fx_setformatparms() {
                    791: 
                    792:        IOReturn rtn;
                    793:        
                    794:        rtn = [fd fdGetFormatInfo:&format_info];
                    795:        if(rtn) {
                    796:                pr_iortn_text(fd, "fdGetFormatInfo", rtn);
                    797:                return(1);
                    798:        }
                    799:        lblocksize = format_info.sectsize_info.sect_size;
                    800:        byte_count = lblocksize;
                    801:        fmt_gap_length = format_info.sectsize_info.fmt_gap_length;
                    802:        return(0);
                    803: }
                    804: 
                    805: /* end of fx.m */

unix.superglobalmegacorp.com

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