Annotation of qemu/hw/fdc.c, revision 1.1.1.14

1.1       root        1: /*
                      2:  * QEMU Floppy disk emulator (Intel 82078)
1.1.1.3   root        3:  *
                      4:  * Copyright (c) 2003, 2007 Jocelyn Mayer
1.1.1.14! root        5:  * Copyright (c) 2008 HervĂ© Poussineau
1.1.1.3   root        6:  *
1.1       root        7:  * Permission is hereby granted, free of charge, to any person obtaining a copy
                      8:  * of this software and associated documentation files (the "Software"), to deal
                      9:  * in the Software without restriction, including without limitation the rights
                     10:  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
                     11:  * copies of the Software, and to permit persons to whom the Software is
                     12:  * furnished to do so, subject to the following conditions:
                     13:  *
                     14:  * The above copyright notice and this permission notice shall be included in
                     15:  * all copies or substantial portions of the Software.
                     16:  *
                     17:  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
                     18:  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
                     19:  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
                     20:  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
                     21:  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
                     22:  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
                     23:  * THE SOFTWARE.
                     24:  */
                     25: /*
                     26:  * The controller is used in Sun4m systems in a slightly different
                     27:  * way. There are changes in DOR register and DMA is not available.
                     28:  */
1.1.1.5   root       29: 
1.1.1.3   root       30: #include "hw.h"
                     31: #include "fdc.h"
1.1.1.10  root       32: #include "qemu-error.h"
1.1.1.3   root       33: #include "qemu-timer.h"
                     34: #include "isa.h"
1.1.1.5   root       35: #include "sysbus.h"
                     36: #include "qdev-addr.h"
1.1.1.11  root       37: #include "blockdev.h"
                     38: #include "sysemu.h"
1.1       root       39: 
                     40: /********************************************************/
                     41: /* debug Floppy devices */
                     42: //#define DEBUG_FLOPPY
                     43: 
                     44: #ifdef DEBUG_FLOPPY
1.1.1.5   root       45: #define FLOPPY_DPRINTF(fmt, ...)                                \
                     46:     do { printf("FLOPPY: " fmt , ## __VA_ARGS__); } while (0)
1.1       root       47: #else
1.1.1.5   root       48: #define FLOPPY_DPRINTF(fmt, ...)
1.1       root       49: #endif
                     50: 
1.1.1.5   root       51: #define FLOPPY_ERROR(fmt, ...)                                          \
                     52:     do { printf("FLOPPY ERROR: %s: " fmt, __func__ , ## __VA_ARGS__); } while (0)
1.1       root       53: 
                     54: /********************************************************/
                     55: /* Floppy drive emulation                               */
                     56: 
1.1.1.4   root       57: #define GET_CUR_DRV(fdctrl) ((fdctrl)->cur_drv)
                     58: #define SET_CUR_DRV(fdctrl, drive) ((fdctrl)->cur_drv = (drive))
                     59: 
1.1       root       60: /* Will always be a fixed parameter for us */
1.1.1.4   root       61: #define FD_SECTOR_LEN          512
                     62: #define FD_SECTOR_SC           2   /* Sector size code */
                     63: #define FD_RESET_SENSEI_COUNT  4   /* Number of sense interrupts on RESET */
1.1       root       64: 
1.1.1.14! root       65: typedef struct FDCtrl FDCtrl;
        !            66: 
1.1       root       67: /* Floppy disk drive emulation */
1.1.1.10  root       68: typedef enum FDiskFlags {
1.1       root       69:     FDISK_DBL_SIDES  = 0x01,
1.1.1.10  root       70: } FDiskFlags;
1.1       root       71: 
1.1.1.10  root       72: typedef struct FDrive {
1.1.1.14! root       73:     FDCtrl *fdctrl;
1.1       root       74:     BlockDriverState *bs;
                     75:     /* Drive status */
1.1.1.10  root       76:     FDriveType drive;
1.1       root       77:     uint8_t perpendicular;    /* 2.88 MB access mode    */
                     78:     /* Position */
                     79:     uint8_t head;
                     80:     uint8_t track;
                     81:     uint8_t sect;
                     82:     /* Media */
1.1.1.10  root       83:     FDiskFlags flags;
1.1       root       84:     uint8_t last_sect;        /* Nb sector per track    */
                     85:     uint8_t max_track;        /* Nb of tracks           */
                     86:     uint16_t bps;             /* Bytes per sector       */
                     87:     uint8_t ro;               /* Is read-only           */
1.1.1.13  root       88:     uint8_t media_changed;    /* Is media changed       */
1.1.1.14! root       89:     uint8_t media_rate;       /* Data rate of medium    */
1.1.1.10  root       90: } FDrive;
1.1       root       91: 
1.1.1.10  root       92: static void fd_init(FDrive *drv)
1.1       root       93: {
                     94:     /* Drive */
                     95:     drv->drive = FDRIVE_DRV_NONE;
                     96:     drv->perpendicular = 0;
                     97:     /* Disk */
                     98:     drv->last_sect = 0;
                     99:     drv->max_track = 0;
                    100: }
                    101: 
1.1.1.14! root      102: #define NUM_SIDES(drv) ((drv)->flags & FDISK_DBL_SIDES ? 2 : 1)
        !           103: 
1.1.1.10  root      104: static int fd_sector_calc(uint8_t head, uint8_t track, uint8_t sect,
1.1.1.14! root      105:                           uint8_t last_sect, uint8_t num_sides)
1.1       root      106: {
1.1.1.14! root      107:     return (((track * num_sides) + head) * last_sect) + sect - 1;
1.1       root      108: }
                    109: 
                    110: /* Returns current position, in sectors, for given drive */
1.1.1.10  root      111: static int fd_sector(FDrive *drv)
1.1       root      112: {
1.1.1.14! root      113:     return fd_sector_calc(drv->head, drv->track, drv->sect, drv->last_sect,
        !           114:                           NUM_SIDES(drv));
1.1       root      115: }
                    116: 
1.1.1.4   root      117: /* Seek to a new position:
                    118:  * returns 0 if already on right track
                    119:  * returns 1 if track changed
                    120:  * returns 2 if track is invalid
                    121:  * returns 3 if sector is invalid
                    122:  * returns 4 if seek is disabled
                    123:  */
1.1.1.10  root      124: static int fd_seek(FDrive *drv, uint8_t head, uint8_t track, uint8_t sect,
                    125:                    int enable_seek)
1.1       root      126: {
                    127:     uint32_t sector;
                    128:     int ret;
                    129: 
                    130:     if (track > drv->max_track ||
1.1.1.3   root      131:         (head != 0 && (drv->flags & FDISK_DBL_SIDES) == 0)) {
1.1       root      132:         FLOPPY_DPRINTF("try to read %d %02x %02x (max=%d %d %02x %02x)\n",
                    133:                        head, track, sect, 1,
                    134:                        (drv->flags & FDISK_DBL_SIDES) == 0 ? 0 : 1,
                    135:                        drv->max_track, drv->last_sect);
                    136:         return 2;
                    137:     }
                    138:     if (sect > drv->last_sect) {
                    139:         FLOPPY_DPRINTF("try to read %d %02x %02x (max=%d %d %02x %02x)\n",
                    140:                        head, track, sect, 1,
                    141:                        (drv->flags & FDISK_DBL_SIDES) == 0 ? 0 : 1,
                    142:                        drv->max_track, drv->last_sect);
                    143:         return 3;
                    144:     }
1.1.1.14! root      145:     sector = fd_sector_calc(head, track, sect, drv->last_sect, NUM_SIDES(drv));
1.1       root      146:     ret = 0;
                    147:     if (sector != fd_sector(drv)) {
                    148: #if 0
                    149:         if (!enable_seek) {
                    150:             FLOPPY_ERROR("no implicit seek %d %02x %02x (max=%d %02x %02x)\n",
                    151:                          head, track, sect, 1, drv->max_track, drv->last_sect);
                    152:             return 4;
                    153:         }
                    154: #endif
                    155:         drv->head = head;
1.1.1.3   root      156:         if (drv->track != track)
                    157:             ret = 1;
1.1       root      158:         drv->track = track;
                    159:         drv->sect = sect;
                    160:     }
                    161: 
1.1.1.14! root      162:     if (drv->bs == NULL || !bdrv_is_inserted(drv->bs)) {
        !           163:         ret = 2;
        !           164:     }
        !           165: 
1.1       root      166:     return ret;
                    167: }
                    168: 
                    169: /* Set drive back to track 0 */
1.1.1.10  root      170: static void fd_recalibrate(FDrive *drv)
1.1       root      171: {
                    172:     FLOPPY_DPRINTF("recalibrate\n");
                    173:     drv->head = 0;
                    174:     drv->track = 0;
                    175:     drv->sect = 1;
                    176: }
                    177: 
                    178: /* Revalidate a disk drive after a disk change */
1.1.1.10  root      179: static void fd_revalidate(FDrive *drv)
1.1       root      180: {
                    181:     int nb_heads, max_track, last_sect, ro;
1.1.1.12  root      182:     FDriveType drive;
1.1.1.14! root      183:     FDriveRate rate;
1.1       root      184: 
                    185:     FLOPPY_DPRINTF("revalidate\n");
1.1.1.14! root      186:     if (drv->bs != NULL) {
1.1.1.3   root      187:         ro = bdrv_is_read_only(drv->bs);
1.1.1.12  root      188:         bdrv_get_floppy_geometry_hint(drv->bs, &nb_heads, &max_track,
1.1.1.14! root      189:                                       &last_sect, drv->drive, &drive, &rate);
        !           190:         if (!bdrv_is_inserted(drv->bs)) {
        !           191:             FLOPPY_DPRINTF("No disk in drive\n");
        !           192:         } else if (nb_heads != 0 && max_track != 0 && last_sect != 0) {
        !           193:             FLOPPY_DPRINTF("User defined disk (%d %d %d)\n",
1.1       root      194:                            nb_heads - 1, max_track, last_sect);
1.1.1.3   root      195:         } else {
1.1.1.12  root      196:             FLOPPY_DPRINTF("Floppy disk (%d h %d t %d s) %s\n", nb_heads,
                    197:                            max_track, last_sect, ro ? "ro" : "rw");
1.1.1.3   root      198:         }
                    199:         if (nb_heads == 1) {
                    200:             drv->flags &= ~FDISK_DBL_SIDES;
                    201:         } else {
                    202:             drv->flags |= FDISK_DBL_SIDES;
                    203:         }
                    204:         drv->max_track = max_track;
                    205:         drv->last_sect = last_sect;
                    206:         drv->ro = ro;
1.1.1.12  root      207:         drv->drive = drive;
1.1.1.14! root      208:         drv->media_rate = rate;
1.1       root      209:     } else {
1.1.1.14! root      210:         FLOPPY_DPRINTF("No drive connected\n");
1.1       root      211:         drv->last_sect = 0;
1.1.1.3   root      212:         drv->max_track = 0;
                    213:         drv->flags &= ~FDISK_DBL_SIDES;
1.1       root      214:     }
                    215: }
                    216: 
                    217: /********************************************************/
                    218: /* Intel 82078 floppy disk controller emulation          */
                    219: 
1.1.1.10  root      220: static void fdctrl_reset(FDCtrl *fdctrl, int do_irq);
                    221: static void fdctrl_reset_fifo(FDCtrl *fdctrl);
1.1       root      222: static int fdctrl_transfer_handler (void *opaque, int nchan,
                    223:                                     int dma_pos, int dma_len);
1.1.1.10  root      224: static void fdctrl_raise_irq(FDCtrl *fdctrl, uint8_t status0);
1.1.1.14! root      225: static FDrive *get_cur_drv(FDCtrl *fdctrl);
1.1       root      226: 
1.1.1.10  root      227: static uint32_t fdctrl_read_statusA(FDCtrl *fdctrl);
                    228: static uint32_t fdctrl_read_statusB(FDCtrl *fdctrl);
                    229: static uint32_t fdctrl_read_dor(FDCtrl *fdctrl);
                    230: static void fdctrl_write_dor(FDCtrl *fdctrl, uint32_t value);
                    231: static uint32_t fdctrl_read_tape(FDCtrl *fdctrl);
                    232: static void fdctrl_write_tape(FDCtrl *fdctrl, uint32_t value);
                    233: static uint32_t fdctrl_read_main_status(FDCtrl *fdctrl);
                    234: static void fdctrl_write_rate(FDCtrl *fdctrl, uint32_t value);
                    235: static uint32_t fdctrl_read_data(FDCtrl *fdctrl);
                    236: static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t value);
                    237: static uint32_t fdctrl_read_dir(FDCtrl *fdctrl);
1.1.1.14! root      238: static void fdctrl_write_ccr(FDCtrl *fdctrl, uint32_t value);
1.1       root      239: 
                    240: enum {
                    241:     FD_DIR_WRITE   = 0,
                    242:     FD_DIR_READ    = 1,
                    243:     FD_DIR_SCANE   = 2,
                    244:     FD_DIR_SCANL   = 3,
                    245:     FD_DIR_SCANH   = 4,
                    246: };
                    247: 
                    248: enum {
1.1.1.4   root      249:     FD_STATE_MULTI  = 0x01,    /* multi track flag */
                    250:     FD_STATE_FORMAT = 0x02,    /* format flag */
                    251:     FD_STATE_SEEK   = 0x04,    /* seek flag */
                    252: };
                    253: 
                    254: enum {
                    255:     FD_REG_SRA = 0x00,
                    256:     FD_REG_SRB = 0x01,
                    257:     FD_REG_DOR = 0x02,
                    258:     FD_REG_TDR = 0x03,
                    259:     FD_REG_MSR = 0x04,
                    260:     FD_REG_DSR = 0x04,
                    261:     FD_REG_FIFO = 0x05,
                    262:     FD_REG_DIR = 0x07,
1.1.1.14! root      263:     FD_REG_CCR = 0x07,
1.1.1.4   root      264: };
                    265: 
                    266: enum {
                    267:     FD_CMD_READ_TRACK = 0x02,
                    268:     FD_CMD_SPECIFY = 0x03,
                    269:     FD_CMD_SENSE_DRIVE_STATUS = 0x04,
                    270:     FD_CMD_WRITE = 0x05,
                    271:     FD_CMD_READ = 0x06,
                    272:     FD_CMD_RECALIBRATE = 0x07,
                    273:     FD_CMD_SENSE_INTERRUPT_STATUS = 0x08,
                    274:     FD_CMD_WRITE_DELETED = 0x09,
                    275:     FD_CMD_READ_ID = 0x0a,
                    276:     FD_CMD_READ_DELETED = 0x0c,
                    277:     FD_CMD_FORMAT_TRACK = 0x0d,
                    278:     FD_CMD_DUMPREG = 0x0e,
                    279:     FD_CMD_SEEK = 0x0f,
                    280:     FD_CMD_VERSION = 0x10,
                    281:     FD_CMD_SCAN_EQUAL = 0x11,
                    282:     FD_CMD_PERPENDICULAR_MODE = 0x12,
                    283:     FD_CMD_CONFIGURE = 0x13,
                    284:     FD_CMD_LOCK = 0x14,
                    285:     FD_CMD_VERIFY = 0x16,
                    286:     FD_CMD_POWERDOWN_MODE = 0x17,
                    287:     FD_CMD_PART_ID = 0x18,
                    288:     FD_CMD_SCAN_LOW_OR_EQUAL = 0x19,
                    289:     FD_CMD_SCAN_HIGH_OR_EQUAL = 0x1d,
1.1.1.9   root      290:     FD_CMD_SAVE = 0x2e,
1.1.1.4   root      291:     FD_CMD_OPTION = 0x33,
1.1.1.9   root      292:     FD_CMD_RESTORE = 0x4e,
1.1.1.4   root      293:     FD_CMD_DRIVE_SPECIFICATION_COMMAND = 0x8e,
                    294:     FD_CMD_RELATIVE_SEEK_OUT = 0x8f,
                    295:     FD_CMD_FORMAT_AND_WRITE = 0xcd,
                    296:     FD_CMD_RELATIVE_SEEK_IN = 0xcf,
                    297: };
                    298: 
                    299: enum {
                    300:     FD_CONFIG_PRETRK = 0xff, /* Pre-compensation set to track 0 */
                    301:     FD_CONFIG_FIFOTHR = 0x0f, /* FIFO threshold set to 1 byte */
                    302:     FD_CONFIG_POLL  = 0x10, /* Poll enabled */
                    303:     FD_CONFIG_EFIFO = 0x20, /* FIFO disabled */
                    304:     FD_CONFIG_EIS   = 0x40, /* No implied seeks */
                    305: };
                    306: 
                    307: enum {
                    308:     FD_SR0_EQPMT    = 0x10,
                    309:     FD_SR0_SEEK     = 0x20,
                    310:     FD_SR0_ABNTERM  = 0x40,
                    311:     FD_SR0_INVCMD   = 0x80,
                    312:     FD_SR0_RDYCHG   = 0xc0,
                    313: };
                    314: 
                    315: enum {
1.1.1.14! root      316:     FD_SR1_MA       = 0x01, /* Missing address mark */
        !           317:     FD_SR1_NW       = 0x02, /* Not writable */
1.1.1.4   root      318:     FD_SR1_EC       = 0x80, /* End of cylinder */
                    319: };
                    320: 
                    321: enum {
                    322:     FD_SR2_SNS      = 0x04, /* Scan not satisfied */
                    323:     FD_SR2_SEH      = 0x08, /* Scan equal hit */
                    324: };
                    325: 
                    326: enum {
                    327:     FD_SRA_DIR      = 0x01,
                    328:     FD_SRA_nWP      = 0x02,
                    329:     FD_SRA_nINDX    = 0x04,
                    330:     FD_SRA_HDSEL    = 0x08,
                    331:     FD_SRA_nTRK0    = 0x10,
                    332:     FD_SRA_STEP     = 0x20,
                    333:     FD_SRA_nDRV2    = 0x40,
                    334:     FD_SRA_INTPEND  = 0x80,
                    335: };
                    336: 
                    337: enum {
                    338:     FD_SRB_MTR0     = 0x01,
                    339:     FD_SRB_MTR1     = 0x02,
                    340:     FD_SRB_WGATE    = 0x04,
                    341:     FD_SRB_RDATA    = 0x08,
                    342:     FD_SRB_WDATA    = 0x10,
                    343:     FD_SRB_DR0      = 0x20,
                    344: };
                    345: 
                    346: enum {
                    347: #if MAX_FD == 4
                    348:     FD_DOR_SELMASK  = 0x03,
                    349: #else
                    350:     FD_DOR_SELMASK  = 0x01,
                    351: #endif
                    352:     FD_DOR_nRESET   = 0x04,
                    353:     FD_DOR_DMAEN    = 0x08,
                    354:     FD_DOR_MOTEN0   = 0x10,
                    355:     FD_DOR_MOTEN1   = 0x20,
                    356:     FD_DOR_MOTEN2   = 0x40,
                    357:     FD_DOR_MOTEN3   = 0x80,
                    358: };
                    359: 
                    360: enum {
                    361: #if MAX_FD == 4
                    362:     FD_TDR_BOOTSEL  = 0x0c,
                    363: #else
                    364:     FD_TDR_BOOTSEL  = 0x04,
                    365: #endif
                    366: };
                    367: 
                    368: enum {
                    369:     FD_DSR_DRATEMASK= 0x03,
                    370:     FD_DSR_PWRDOWN  = 0x40,
                    371:     FD_DSR_SWRESET  = 0x80,
                    372: };
                    373: 
                    374: enum {
                    375:     FD_MSR_DRV0BUSY = 0x01,
                    376:     FD_MSR_DRV1BUSY = 0x02,
                    377:     FD_MSR_DRV2BUSY = 0x04,
                    378:     FD_MSR_DRV3BUSY = 0x08,
                    379:     FD_MSR_CMDBUSY  = 0x10,
                    380:     FD_MSR_NONDMA   = 0x20,
                    381:     FD_MSR_DIO      = 0x40,
                    382:     FD_MSR_RQM      = 0x80,
                    383: };
                    384: 
                    385: enum {
                    386:     FD_DIR_DSKCHG   = 0x80,
1.1       root      387: };
                    388: 
                    389: #define FD_MULTI_TRACK(state) ((state) & FD_STATE_MULTI)
                    390: #define FD_DID_SEEK(state) ((state) & FD_STATE_SEEK)
                    391: #define FD_FORMAT_CMD(state) ((state) & FD_STATE_FORMAT)
                    392: 
1.1.1.10  root      393: struct FDCtrl {
1.1.1.14! root      394:     MemoryRegion iomem;
1.1.1.3   root      395:     qemu_irq irq;
1.1       root      396:     /* Controller state */
                    397:     QEMUTimer *result_timer;
1.1.1.13  root      398:     int dma_chann;
                    399:     /* Controller's identification */
                    400:     uint8_t version;
                    401:     /* HW */
1.1.1.4   root      402:     uint8_t sra;
                    403:     uint8_t srb;
                    404:     uint8_t dor;
1.1.1.6   root      405:     uint8_t dor_vmstate; /* only used as temp during vmstate */
1.1.1.4   root      406:     uint8_t tdr;
                    407:     uint8_t dsr;
                    408:     uint8_t msr;
1.1       root      409:     uint8_t cur_drv;
1.1.1.4   root      410:     uint8_t status0;
                    411:     uint8_t status1;
                    412:     uint8_t status2;
1.1       root      413:     /* Command FIFO */
1.1.1.3   root      414:     uint8_t *fifo;
1.1.1.6   root      415:     int32_t fifo_size;
1.1       root      416:     uint32_t data_pos;
                    417:     uint32_t data_len;
                    418:     uint8_t data_state;
                    419:     uint8_t data_dir;
                    420:     uint8_t eot; /* last wanted sector */
                    421:     /* States kept only to be returned back */
                    422:     /* precompensation */
                    423:     uint8_t precomp_trk;
                    424:     uint8_t config;
                    425:     uint8_t lock;
                    426:     /* Power down config (also with status regB access mode */
                    427:     uint8_t pwrd;
                    428:     /* Floppy drives */
1.1.1.6   root      429:     uint8_t num_floppies;
1.1.1.13  root      430:     /* Sun4m quirks? */
                    431:     int sun4m;
1.1.1.10  root      432:     FDrive drives[MAX_FD];
1.1.1.4   root      433:     int reset_sensei;
1.1.1.14! root      434:     uint32_t check_media_rate;
1.1.1.13  root      435:     /* Timers state */
                    436:     uint8_t timer0;
                    437:     uint8_t timer1;
1.1       root      438: };
                    439: 
1.1.1.10  root      440: typedef struct FDCtrlSysBus {
1.1.1.6   root      441:     SysBusDevice busdev;
1.1.1.10  root      442:     struct FDCtrl state;
                    443: } FDCtrlSysBus;
1.1.1.6   root      444: 
1.1.1.10  root      445: typedef struct FDCtrlISABus {
1.1.1.6   root      446:     ISADevice busdev;
1.1.1.14! root      447:     uint32_t iobase;
        !           448:     uint32_t irq;
        !           449:     uint32_t dma;
1.1.1.10  root      450:     struct FDCtrl state;
1.1.1.11  root      451:     int32_t bootindexA;
                    452:     int32_t bootindexB;
1.1.1.10  root      453: } FDCtrlISABus;
1.1.1.6   root      454: 
1.1       root      455: static uint32_t fdctrl_read (void *opaque, uint32_t reg)
                    456: {
1.1.1.10  root      457:     FDCtrl *fdctrl = opaque;
1.1       root      458:     uint32_t retval;
                    459: 
1.1.1.13  root      460:     reg &= 7;
1.1.1.4   root      461:     switch (reg) {
                    462:     case FD_REG_SRA:
                    463:         retval = fdctrl_read_statusA(fdctrl);
1.1.1.3   root      464:         break;
1.1.1.4   root      465:     case FD_REG_SRB:
1.1.1.3   root      466:         retval = fdctrl_read_statusB(fdctrl);
                    467:         break;
1.1.1.4   root      468:     case FD_REG_DOR:
1.1.1.3   root      469:         retval = fdctrl_read_dor(fdctrl);
                    470:         break;
1.1.1.4   root      471:     case FD_REG_TDR:
1.1       root      472:         retval = fdctrl_read_tape(fdctrl);
1.1.1.3   root      473:         break;
1.1.1.4   root      474:     case FD_REG_MSR:
1.1       root      475:         retval = fdctrl_read_main_status(fdctrl);
1.1.1.3   root      476:         break;
1.1.1.4   root      477:     case FD_REG_FIFO:
1.1       root      478:         retval = fdctrl_read_data(fdctrl);
1.1.1.3   root      479:         break;
1.1.1.4   root      480:     case FD_REG_DIR:
1.1       root      481:         retval = fdctrl_read_dir(fdctrl);
1.1.1.3   root      482:         break;
1.1       root      483:     default:
1.1.1.3   root      484:         retval = (uint32_t)(-1);
                    485:         break;
1.1       root      486:     }
                    487:     FLOPPY_DPRINTF("read reg%d: 0x%02x\n", reg & 7, retval);
                    488: 
                    489:     return retval;
                    490: }
                    491: 
                    492: static void fdctrl_write (void *opaque, uint32_t reg, uint32_t value)
                    493: {
1.1.1.10  root      494:     FDCtrl *fdctrl = opaque;
1.1       root      495: 
                    496:     FLOPPY_DPRINTF("write reg%d: 0x%02x\n", reg & 7, value);
                    497: 
1.1.1.13  root      498:     reg &= 7;
1.1.1.4   root      499:     switch (reg) {
                    500:     case FD_REG_DOR:
1.1.1.3   root      501:         fdctrl_write_dor(fdctrl, value);
                    502:         break;
1.1.1.4   root      503:     case FD_REG_TDR:
1.1       root      504:         fdctrl_write_tape(fdctrl, value);
1.1.1.3   root      505:         break;
1.1.1.4   root      506:     case FD_REG_DSR:
1.1       root      507:         fdctrl_write_rate(fdctrl, value);
1.1.1.3   root      508:         break;
1.1.1.4   root      509:     case FD_REG_FIFO:
1.1       root      510:         fdctrl_write_data(fdctrl, value);
1.1.1.3   root      511:         break;
1.1.1.14! root      512:     case FD_REG_CCR:
        !           513:         fdctrl_write_ccr(fdctrl, value);
        !           514:         break;
1.1       root      515:     default:
1.1.1.3   root      516:         break;
1.1       root      517:     }
                    518: }
                    519: 
1.1.1.14! root      520: static uint64_t fdctrl_read_mem (void *opaque, target_phys_addr_t reg,
        !           521:                                  unsigned ize)
1.1       root      522: {
1.1.1.3   root      523:     return fdctrl_read(opaque, (uint32_t)reg);
1.1       root      524: }
                    525: 
1.1.1.14! root      526: static void fdctrl_write_mem (void *opaque, target_phys_addr_t reg,
        !           527:                               uint64_t value, unsigned size)
1.1       root      528: {
1.1.1.3   root      529:     fdctrl_write(opaque, (uint32_t)reg, value);
1.1       root      530: }
                    531: 
1.1.1.14! root      532: static const MemoryRegionOps fdctrl_mem_ops = {
        !           533:     .read = fdctrl_read_mem,
        !           534:     .write = fdctrl_write_mem,
        !           535:     .endianness = DEVICE_NATIVE_ENDIAN,
1.1       root      536: };
                    537: 
1.1.1.14! root      538: static const MemoryRegionOps fdctrl_mem_strict_ops = {
        !           539:     .read = fdctrl_read_mem,
        !           540:     .write = fdctrl_write_mem,
        !           541:     .endianness = DEVICE_NATIVE_ENDIAN,
        !           542:     .valid = {
        !           543:         .min_access_size = 1,
        !           544:         .max_access_size = 1,
        !           545:     },
1.1.1.3   root      546: };
                    547: 
1.1.1.13  root      548: static bool fdrive_media_changed_needed(void *opaque)
                    549: {
                    550:     FDrive *drive = opaque;
                    551: 
                    552:     return (drive->bs != NULL && drive->media_changed != 1);
                    553: }
                    554: 
                    555: static const VMStateDescription vmstate_fdrive_media_changed = {
                    556:     .name = "fdrive/media_changed",
                    557:     .version_id = 1,
                    558:     .minimum_version_id = 1,
                    559:     .minimum_version_id_old = 1,
                    560:     .fields      = (VMStateField[]) {
                    561:         VMSTATE_UINT8(media_changed, FDrive),
                    562:         VMSTATE_END_OF_LIST()
                    563:     }
                    564: };
                    565: 
1.1.1.14! root      566: static bool fdrive_media_rate_needed(void *opaque)
        !           567: {
        !           568:     FDrive *drive = opaque;
        !           569: 
        !           570:     return drive->fdctrl->check_media_rate;
        !           571: }
        !           572: 
        !           573: static const VMStateDescription vmstate_fdrive_media_rate = {
        !           574:     .name = "fdrive/media_rate",
        !           575:     .version_id = 1,
        !           576:     .minimum_version_id = 1,
        !           577:     .minimum_version_id_old = 1,
        !           578:     .fields      = (VMStateField[]) {
        !           579:         VMSTATE_UINT8(media_rate, FDrive),
        !           580:         VMSTATE_END_OF_LIST()
        !           581:     }
        !           582: };
        !           583: 
1.1.1.6   root      584: static const VMStateDescription vmstate_fdrive = {
                    585:     .name = "fdrive",
                    586:     .version_id = 1,
                    587:     .minimum_version_id = 1,
                    588:     .minimum_version_id_old = 1,
1.1.1.13  root      589:     .fields      = (VMStateField[]) {
1.1.1.10  root      590:         VMSTATE_UINT8(head, FDrive),
                    591:         VMSTATE_UINT8(track, FDrive),
                    592:         VMSTATE_UINT8(sect, FDrive),
1.1.1.6   root      593:         VMSTATE_END_OF_LIST()
1.1.1.13  root      594:     },
                    595:     .subsections = (VMStateSubsection[]) {
                    596:         {
                    597:             .vmsd = &vmstate_fdrive_media_changed,
                    598:             .needed = &fdrive_media_changed_needed,
                    599:         } , {
1.1.1.14! root      600:             .vmsd = &vmstate_fdrive_media_rate,
        !           601:             .needed = &fdrive_media_rate_needed,
        !           602:         } , {
1.1.1.13  root      603:             /* empty */
                    604:         }
1.1.1.6   root      605:     }
                    606: };
1.1.1.3   root      607: 
1.1.1.6   root      608: static void fdc_pre_save(void *opaque)
1.1.1.3   root      609: {
1.1.1.10  root      610:     FDCtrl *s = opaque;
1.1.1.4   root      611: 
1.1.1.6   root      612:     s->dor_vmstate = s->dor | GET_CUR_DRV(s);
1.1.1.3   root      613: }
                    614: 
1.1.1.6   root      615: static int fdc_post_load(void *opaque, int version_id)
1.1.1.3   root      616: {
1.1.1.10  root      617:     FDCtrl *s = opaque;
1.1.1.3   root      618: 
1.1.1.6   root      619:     SET_CUR_DRV(s, s->dor_vmstate & FD_DOR_SELMASK);
                    620:     s->dor = s->dor_vmstate & ~FD_DOR_SELMASK;
1.1.1.3   root      621:     return 0;
                    622: }
                    623: 
1.1.1.6   root      624: static const VMStateDescription vmstate_fdc = {
                    625:     .name = "fdc",
                    626:     .version_id = 2,
                    627:     .minimum_version_id = 2,
                    628:     .minimum_version_id_old = 2,
                    629:     .pre_save = fdc_pre_save,
                    630:     .post_load = fdc_post_load,
                    631:     .fields      = (VMStateField []) {
                    632:         /* Controller State */
1.1.1.10  root      633:         VMSTATE_UINT8(sra, FDCtrl),
                    634:         VMSTATE_UINT8(srb, FDCtrl),
                    635:         VMSTATE_UINT8(dor_vmstate, FDCtrl),
                    636:         VMSTATE_UINT8(tdr, FDCtrl),
                    637:         VMSTATE_UINT8(dsr, FDCtrl),
                    638:         VMSTATE_UINT8(msr, FDCtrl),
                    639:         VMSTATE_UINT8(status0, FDCtrl),
                    640:         VMSTATE_UINT8(status1, FDCtrl),
                    641:         VMSTATE_UINT8(status2, FDCtrl),
1.1.1.6   root      642:         /* Command FIFO */
1.1.1.10  root      643:         VMSTATE_VARRAY_INT32(fifo, FDCtrl, fifo_size, 0, vmstate_info_uint8,
                    644:                              uint8_t),
                    645:         VMSTATE_UINT32(data_pos, FDCtrl),
                    646:         VMSTATE_UINT32(data_len, FDCtrl),
                    647:         VMSTATE_UINT8(data_state, FDCtrl),
                    648:         VMSTATE_UINT8(data_dir, FDCtrl),
                    649:         VMSTATE_UINT8(eot, FDCtrl),
1.1.1.6   root      650:         /* States kept only to be returned back */
1.1.1.10  root      651:         VMSTATE_UINT8(timer0, FDCtrl),
                    652:         VMSTATE_UINT8(timer1, FDCtrl),
                    653:         VMSTATE_UINT8(precomp_trk, FDCtrl),
                    654:         VMSTATE_UINT8(config, FDCtrl),
                    655:         VMSTATE_UINT8(lock, FDCtrl),
                    656:         VMSTATE_UINT8(pwrd, FDCtrl),
                    657:         VMSTATE_UINT8_EQUAL(num_floppies, FDCtrl),
                    658:         VMSTATE_STRUCT_ARRAY(drives, FDCtrl, MAX_FD, 1,
                    659:                              vmstate_fdrive, FDrive),
1.1.1.6   root      660:         VMSTATE_END_OF_LIST()
1.1.1.4   root      661:     }
1.1.1.6   root      662: };
1.1.1.3   root      663: 
1.1.1.6   root      664: static void fdctrl_external_reset_sysbus(DeviceState *d)
                    665: {
1.1.1.10  root      666:     FDCtrlSysBus *sys = container_of(d, FDCtrlSysBus, busdev.qdev);
                    667:     FDCtrl *s = &sys->state;
1.1.1.6   root      668: 
                    669:     fdctrl_reset(s, 0);
1.1.1.3   root      670: }
                    671: 
1.1.1.6   root      672: static void fdctrl_external_reset_isa(DeviceState *d)
1.1.1.3   root      673: {
1.1.1.10  root      674:     FDCtrlISABus *isa = container_of(d, FDCtrlISABus, busdev.qdev);
                    675:     FDCtrl *s = &isa->state;
1.1.1.3   root      676: 
                    677:     fdctrl_reset(s, 0);
                    678: }
                    679: 
1.1.1.4   root      680: static void fdctrl_handle_tc(void *opaque, int irq, int level)
1.1.1.3   root      681: {
1.1.1.10  root      682:     //FDCtrl *s = opaque;
1.1.1.3   root      683: 
1.1.1.4   root      684:     if (level) {
                    685:         // XXX
                    686:         FLOPPY_DPRINTF("TC pulsed\n");
1.1       root      687:     }
1.1.1.3   root      688: }
                    689: 
1.1       root      690: /* Change IRQ state */
1.1.1.10  root      691: static void fdctrl_reset_irq(FDCtrl *fdctrl)
1.1       root      692: {
1.1.1.4   root      693:     if (!(fdctrl->sra & FD_SRA_INTPEND))
                    694:         return;
1.1       root      695:     FLOPPY_DPRINTF("Reset interrupt\n");
1.1.1.3   root      696:     qemu_set_irq(fdctrl->irq, 0);
1.1.1.4   root      697:     fdctrl->sra &= ~FD_SRA_INTPEND;
1.1       root      698: }
                    699: 
1.1.1.10  root      700: static void fdctrl_raise_irq(FDCtrl *fdctrl, uint8_t status0)
1.1       root      701: {
1.1.1.4   root      702:     /* Sparc mutation */
                    703:     if (fdctrl->sun4m && (fdctrl->msr & FD_MSR_CMDBUSY)) {
                    704:         /* XXX: not sure */
                    705:         fdctrl->msr &= ~FD_MSR_CMDBUSY;
                    706:         fdctrl->msr |= FD_MSR_RQM | FD_MSR_DIO;
                    707:         fdctrl->status0 = status0;
1.1.1.3   root      708:         return;
1.1       root      709:     }
1.1.1.4   root      710:     if (!(fdctrl->sra & FD_SRA_INTPEND)) {
1.1.1.3   root      711:         qemu_set_irq(fdctrl->irq, 1);
1.1.1.4   root      712:         fdctrl->sra |= FD_SRA_INTPEND;
1.1       root      713:     }
1.1.1.14! root      714:     if (status0 & FD_SR0_SEEK) {
        !           715:         FDrive *cur_drv;
        !           716:         /* A seek clears the disk change line (if a disk is inserted) */
        !           717:         cur_drv = get_cur_drv(fdctrl);
        !           718:         if (cur_drv->bs != NULL && bdrv_is_inserted(cur_drv->bs)) {
        !           719:             cur_drv->media_changed = 0;
        !           720:         }
        !           721:     }
        !           722: 
1.1.1.4   root      723:     fdctrl->reset_sensei = 0;
                    724:     fdctrl->status0 = status0;
                    725:     FLOPPY_DPRINTF("Set interrupt status to 0x%02x\n", fdctrl->status0);
1.1       root      726: }
                    727: 
                    728: /* Reset controller */
1.1.1.10  root      729: static void fdctrl_reset(FDCtrl *fdctrl, int do_irq)
1.1       root      730: {
                    731:     int i;
                    732: 
                    733:     FLOPPY_DPRINTF("reset controller\n");
                    734:     fdctrl_reset_irq(fdctrl);
                    735:     /* Initialise controller */
1.1.1.4   root      736:     fdctrl->sra = 0;
                    737:     fdctrl->srb = 0xc0;
                    738:     if (!fdctrl->drives[1].bs)
                    739:         fdctrl->sra |= FD_SRA_nDRV2;
1.1       root      740:     fdctrl->cur_drv = 0;
1.1.1.4   root      741:     fdctrl->dor = FD_DOR_nRESET;
                    742:     fdctrl->dor |= (fdctrl->dma_chann != -1) ? FD_DOR_DMAEN : 0;
                    743:     fdctrl->msr = FD_MSR_RQM;
1.1       root      744:     /* FIFO state */
                    745:     fdctrl->data_pos = 0;
                    746:     fdctrl->data_len = 0;
1.1.1.4   root      747:     fdctrl->data_state = 0;
1.1       root      748:     fdctrl->data_dir = FD_DIR_WRITE;
                    749:     for (i = 0; i < MAX_FD; i++)
1.1.1.4   root      750:         fd_recalibrate(&fdctrl->drives[i]);
1.1       root      751:     fdctrl_reset_fifo(fdctrl);
1.1.1.4   root      752:     if (do_irq) {
                    753:         fdctrl_raise_irq(fdctrl, FD_SR0_RDYCHG);
                    754:         fdctrl->reset_sensei = FD_RESET_SENSEI_COUNT;
                    755:     }
1.1       root      756: }
                    757: 
1.1.1.10  root      758: static inline FDrive *drv0(FDCtrl *fdctrl)
1.1       root      759: {
1.1.1.4   root      760:     return &fdctrl->drives[(fdctrl->tdr & FD_TDR_BOOTSEL) >> 2];
1.1       root      761: }
                    762: 
1.1.1.10  root      763: static inline FDrive *drv1(FDCtrl *fdctrl)
1.1       root      764: {
1.1.1.4   root      765:     if ((fdctrl->tdr & FD_TDR_BOOTSEL) < (1 << 2))
                    766:         return &fdctrl->drives[1];
                    767:     else
                    768:         return &fdctrl->drives[0];
                    769: }
                    770: 
                    771: #if MAX_FD == 4
1.1.1.10  root      772: static inline FDrive *drv2(FDCtrl *fdctrl)
1.1.1.4   root      773: {
                    774:     if ((fdctrl->tdr & FD_TDR_BOOTSEL) < (2 << 2))
                    775:         return &fdctrl->drives[2];
                    776:     else
                    777:         return &fdctrl->drives[1];
                    778: }
                    779: 
1.1.1.10  root      780: static inline FDrive *drv3(FDCtrl *fdctrl)
1.1.1.4   root      781: {
                    782:     if ((fdctrl->tdr & FD_TDR_BOOTSEL) < (3 << 2))
                    783:         return &fdctrl->drives[3];
                    784:     else
                    785:         return &fdctrl->drives[2];
1.1       root      786: }
1.1.1.4   root      787: #endif
1.1       root      788: 
1.1.1.10  root      789: static FDrive *get_cur_drv(FDCtrl *fdctrl)
1.1       root      790: {
1.1.1.4   root      791:     switch (fdctrl->cur_drv) {
                    792:         case 0: return drv0(fdctrl);
                    793:         case 1: return drv1(fdctrl);
                    794: #if MAX_FD == 4
                    795:         case 2: return drv2(fdctrl);
                    796:         case 3: return drv3(fdctrl);
                    797: #endif
                    798:         default: return NULL;
                    799:     }
                    800: }
                    801: 
                    802: /* Status A register : 0x00 (read-only) */
1.1.1.10  root      803: static uint32_t fdctrl_read_statusA(FDCtrl *fdctrl)
1.1.1.4   root      804: {
                    805:     uint32_t retval = fdctrl->sra;
                    806: 
                    807:     FLOPPY_DPRINTF("status register A: 0x%02x\n", retval);
                    808: 
                    809:     return retval;
1.1       root      810: }
                    811: 
                    812: /* Status B register : 0x01 (read-only) */
1.1.1.10  root      813: static uint32_t fdctrl_read_statusB(FDCtrl *fdctrl)
1.1       root      814: {
1.1.1.4   root      815:     uint32_t retval = fdctrl->srb;
                    816: 
                    817:     FLOPPY_DPRINTF("status register B: 0x%02x\n", retval);
                    818: 
                    819:     return retval;
1.1       root      820: }
                    821: 
                    822: /* Digital output register : 0x02 */
1.1.1.10  root      823: static uint32_t fdctrl_read_dor(FDCtrl *fdctrl)
1.1       root      824: {
1.1.1.4   root      825:     uint32_t retval = fdctrl->dor;
1.1       root      826: 
                    827:     /* Selected drive */
                    828:     retval |= fdctrl->cur_drv;
                    829:     FLOPPY_DPRINTF("digital output register: 0x%02x\n", retval);
                    830: 
                    831:     return retval;
                    832: }
                    833: 
1.1.1.10  root      834: static void fdctrl_write_dor(FDCtrl *fdctrl, uint32_t value)
1.1       root      835: {
                    836:     FLOPPY_DPRINTF("digital output register set to 0x%02x\n", value);
1.1.1.4   root      837: 
                    838:     /* Motors */
                    839:     if (value & FD_DOR_MOTEN0)
                    840:         fdctrl->srb |= FD_SRB_MTR0;
1.1       root      841:     else
1.1.1.4   root      842:         fdctrl->srb &= ~FD_SRB_MTR0;
                    843:     if (value & FD_DOR_MOTEN1)
                    844:         fdctrl->srb |= FD_SRB_MTR1;
1.1       root      845:     else
1.1.1.4   root      846:         fdctrl->srb &= ~FD_SRB_MTR1;
                    847: 
                    848:     /* Drive */
                    849:     if (value & 1)
                    850:         fdctrl->srb |= FD_SRB_DR0;
                    851:     else
                    852:         fdctrl->srb &= ~FD_SRB_DR0;
                    853: 
1.1       root      854:     /* Reset */
1.1.1.4   root      855:     if (!(value & FD_DOR_nRESET)) {
                    856:         if (fdctrl->dor & FD_DOR_nRESET) {
1.1       root      857:             FLOPPY_DPRINTF("controller enter RESET state\n");
                    858:         }
                    859:     } else {
1.1.1.4   root      860:         if (!(fdctrl->dor & FD_DOR_nRESET)) {
1.1       root      861:             FLOPPY_DPRINTF("controller out of RESET state\n");
                    862:             fdctrl_reset(fdctrl, 1);
1.1.1.4   root      863:             fdctrl->dsr &= ~FD_DSR_PWRDOWN;
1.1       root      864:         }
                    865:     }
                    866:     /* Selected drive */
1.1.1.4   root      867:     fdctrl->cur_drv = value & FD_DOR_SELMASK;
                    868: 
                    869:     fdctrl->dor = value;
1.1       root      870: }
                    871: 
                    872: /* Tape drive register : 0x03 */
1.1.1.10  root      873: static uint32_t fdctrl_read_tape(FDCtrl *fdctrl)
1.1       root      874: {
1.1.1.4   root      875:     uint32_t retval = fdctrl->tdr;
1.1       root      876: 
                    877:     FLOPPY_DPRINTF("tape drive register: 0x%02x\n", retval);
                    878: 
                    879:     return retval;
                    880: }
                    881: 
1.1.1.10  root      882: static void fdctrl_write_tape(FDCtrl *fdctrl, uint32_t value)
1.1       root      883: {
                    884:     /* Reset mode */
1.1.1.4   root      885:     if (!(fdctrl->dor & FD_DOR_nRESET)) {
1.1       root      886:         FLOPPY_DPRINTF("Floppy controller in RESET state !\n");
                    887:         return;
                    888:     }
                    889:     FLOPPY_DPRINTF("tape drive register set to 0x%02x\n", value);
                    890:     /* Disk boot selection indicator */
1.1.1.4   root      891:     fdctrl->tdr = value & FD_TDR_BOOTSEL;
1.1       root      892:     /* Tape indicators: never allow */
                    893: }
                    894: 
                    895: /* Main status register : 0x04 (read) */
1.1.1.10  root      896: static uint32_t fdctrl_read_main_status(FDCtrl *fdctrl)
1.1       root      897: {
1.1.1.4   root      898:     uint32_t retval = fdctrl->msr;
                    899: 
                    900:     fdctrl->dsr &= ~FD_DSR_PWRDOWN;
                    901:     fdctrl->dor |= FD_DOR_nRESET;
1.1       root      902: 
1.1.1.7   root      903:     /* Sparc mutation */
                    904:     if (fdctrl->sun4m) {
                    905:         retval |= FD_MSR_DIO;
                    906:         fdctrl_reset_irq(fdctrl);
                    907:     };
                    908: 
1.1       root      909:     FLOPPY_DPRINTF("main status register: 0x%02x\n", retval);
                    910: 
                    911:     return retval;
                    912: }
                    913: 
                    914: /* Data select rate register : 0x04 (write) */
1.1.1.10  root      915: static void fdctrl_write_rate(FDCtrl *fdctrl, uint32_t value)
1.1       root      916: {
                    917:     /* Reset mode */
1.1.1.4   root      918:     if (!(fdctrl->dor & FD_DOR_nRESET)) {
1.1.1.3   root      919:         FLOPPY_DPRINTF("Floppy controller in RESET state !\n");
                    920:         return;
                    921:     }
1.1       root      922:     FLOPPY_DPRINTF("select rate register set to 0x%02x\n", value);
                    923:     /* Reset: autoclear */
1.1.1.4   root      924:     if (value & FD_DSR_SWRESET) {
                    925:         fdctrl->dor &= ~FD_DOR_nRESET;
1.1       root      926:         fdctrl_reset(fdctrl, 1);
1.1.1.4   root      927:         fdctrl->dor |= FD_DOR_nRESET;
1.1       root      928:     }
1.1.1.4   root      929:     if (value & FD_DSR_PWRDOWN) {
1.1       root      930:         fdctrl_reset(fdctrl, 1);
                    931:     }
1.1.1.4   root      932:     fdctrl->dsr = value;
1.1       root      933: }
                    934: 
1.1.1.14! root      935: /* Configuration control register: 0x07 (write) */
        !           936: static void fdctrl_write_ccr(FDCtrl *fdctrl, uint32_t value)
1.1.1.2   root      937: {
1.1.1.14! root      938:     /* Reset mode */
        !           939:     if (!(fdctrl->dor & FD_DOR_nRESET)) {
        !           940:         FLOPPY_DPRINTF("Floppy controller in RESET state !\n");
        !           941:         return;
1.1.1.2   root      942:     }
1.1.1.14! root      943:     FLOPPY_DPRINTF("configuration control register set to 0x%02x\n", value);
        !           944: 
        !           945:     /* Only the rate selection bits used in AT mode, and we
        !           946:      * store those in the DSR.
        !           947:      */
        !           948:     fdctrl->dsr = (fdctrl->dsr & ~FD_DSR_DRATEMASK) |
        !           949:                   (value & FD_DSR_DRATEMASK);
        !           950: }
        !           951: 
        !           952: static int fdctrl_media_changed(FDrive *drv)
        !           953: {
        !           954:     return drv->media_changed;
1.1.1.2   root      955: }
                    956: 
1.1       root      957: /* Digital input register : 0x07 (read-only) */
1.1.1.10  root      958: static uint32_t fdctrl_read_dir(FDCtrl *fdctrl)
1.1       root      959: {
                    960:     uint32_t retval = 0;
                    961: 
1.1.1.14! root      962:     if (fdctrl_media_changed(get_cur_drv(fdctrl))) {
1.1.1.4   root      963:         retval |= FD_DIR_DSKCHG;
1.1.1.14! root      964:     }
1.1.1.10  root      965:     if (retval != 0) {
1.1       root      966:         FLOPPY_DPRINTF("Floppy digital input register: 0x%02x\n", retval);
1.1.1.10  root      967:     }
1.1       root      968: 
                    969:     return retval;
                    970: }
                    971: 
                    972: /* FIFO state control */
1.1.1.10  root      973: static void fdctrl_reset_fifo(FDCtrl *fdctrl)
1.1       root      974: {
                    975:     fdctrl->data_dir = FD_DIR_WRITE;
                    976:     fdctrl->data_pos = 0;
1.1.1.4   root      977:     fdctrl->msr &= ~(FD_MSR_CMDBUSY | FD_MSR_DIO);
1.1       root      978: }
                    979: 
                    980: /* Set FIFO status for the host to read */
1.1.1.10  root      981: static void fdctrl_set_fifo(FDCtrl *fdctrl, int fifo_len, int do_irq)
1.1       root      982: {
                    983:     fdctrl->data_dir = FD_DIR_READ;
                    984:     fdctrl->data_len = fifo_len;
                    985:     fdctrl->data_pos = 0;
1.1.1.4   root      986:     fdctrl->msr |= FD_MSR_CMDBUSY | FD_MSR_RQM | FD_MSR_DIO;
1.1       root      987:     if (do_irq)
                    988:         fdctrl_raise_irq(fdctrl, 0x00);
                    989: }
                    990: 
                    991: /* Set an error: unimplemented/unknown command */
1.1.1.10  root      992: static void fdctrl_unimplemented(FDCtrl *fdctrl, int direction)
1.1       root      993: {
1.1.1.4   root      994:     FLOPPY_ERROR("unimplemented command 0x%02x\n", fdctrl->fifo[0]);
                    995:     fdctrl->fifo[0] = FD_SR0_INVCMD;
1.1       root      996:     fdctrl_set_fifo(fdctrl, 1, 0);
1.1.1.4   root      997: }
                    998: 
                    999: /* Seek to next sector */
1.1.1.10  root     1000: static int fdctrl_seek_to_next_sect(FDCtrl *fdctrl, FDrive *cur_drv)
1.1.1.4   root     1001: {
                   1002:     FLOPPY_DPRINTF("seek to next sector (%d %02x %02x => %d)\n",
                   1003:                    cur_drv->head, cur_drv->track, cur_drv->sect,
                   1004:                    fd_sector(cur_drv));
                   1005:     /* XXX: cur_drv->sect >= cur_drv->last_sect should be an
                   1006:        error in fact */
                   1007:     if (cur_drv->sect >= cur_drv->last_sect ||
                   1008:         cur_drv->sect == fdctrl->eot) {
                   1009:         cur_drv->sect = 1;
                   1010:         if (FD_MULTI_TRACK(fdctrl->data_state)) {
                   1011:             if (cur_drv->head == 0 &&
                   1012:                 (cur_drv->flags & FDISK_DBL_SIDES) != 0) {
                   1013:                 cur_drv->head = 1;
                   1014:             } else {
                   1015:                 cur_drv->head = 0;
                   1016:                 cur_drv->track++;
                   1017:                 if ((cur_drv->flags & FDISK_DBL_SIDES) == 0)
                   1018:                     return 0;
                   1019:             }
                   1020:         } else {
                   1021:             cur_drv->track++;
                   1022:             return 0;
                   1023:         }
                   1024:         FLOPPY_DPRINTF("seek to next track (%d %02x %02x => %d)\n",
                   1025:                        cur_drv->head, cur_drv->track,
                   1026:                        cur_drv->sect, fd_sector(cur_drv));
                   1027:     } else {
                   1028:         cur_drv->sect++;
                   1029:     }
                   1030:     return 1;
1.1       root     1031: }
                   1032: 
                   1033: /* Callback for transfer end (stop or abort) */
1.1.1.10  root     1034: static void fdctrl_stop_transfer(FDCtrl *fdctrl, uint8_t status0,
                   1035:                                  uint8_t status1, uint8_t status2)
1.1       root     1036: {
1.1.1.10  root     1037:     FDrive *cur_drv;
1.1       root     1038: 
                   1039:     cur_drv = get_cur_drv(fdctrl);
                   1040:     FLOPPY_DPRINTF("transfer status: %02x %02x %02x (%02x)\n",
                   1041:                    status0, status1, status2,
1.1.1.4   root     1042:                    status0 | (cur_drv->head << 2) | GET_CUR_DRV(fdctrl));
                   1043:     fdctrl->fifo[0] = status0 | (cur_drv->head << 2) | GET_CUR_DRV(fdctrl);
1.1       root     1044:     fdctrl->fifo[1] = status1;
                   1045:     fdctrl->fifo[2] = status2;
                   1046:     fdctrl->fifo[3] = cur_drv->track;
                   1047:     fdctrl->fifo[4] = cur_drv->head;
                   1048:     fdctrl->fifo[5] = cur_drv->sect;
                   1049:     fdctrl->fifo[6] = FD_SECTOR_SC;
                   1050:     fdctrl->data_dir = FD_DIR_READ;
1.1.1.4   root     1051:     if (!(fdctrl->msr & FD_MSR_NONDMA)) {
1.1       root     1052:         DMA_release_DREQ(fdctrl->dma_chann);
                   1053:     }
1.1.1.4   root     1054:     fdctrl->msr |= FD_MSR_RQM | FD_MSR_DIO;
                   1055:     fdctrl->msr &= ~FD_MSR_NONDMA;
1.1       root     1056:     fdctrl_set_fifo(fdctrl, 7, 1);
                   1057: }
                   1058: 
                   1059: /* Prepare a data transfer (either DMA or FIFO) */
1.1.1.10  root     1060: static void fdctrl_start_transfer(FDCtrl *fdctrl, int direction)
1.1       root     1061: {
1.1.1.10  root     1062:     FDrive *cur_drv;
1.1       root     1063:     uint8_t kh, kt, ks;
1.1.1.4   root     1064:     int did_seek = 0;
1.1       root     1065: 
1.1.1.4   root     1066:     SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
1.1       root     1067:     cur_drv = get_cur_drv(fdctrl);
                   1068:     kt = fdctrl->fifo[2];
                   1069:     kh = fdctrl->fifo[3];
                   1070:     ks = fdctrl->fifo[4];
                   1071:     FLOPPY_DPRINTF("Start transfer at %d %d %02x %02x (%d)\n",
1.1.1.4   root     1072:                    GET_CUR_DRV(fdctrl), kh, kt, ks,
1.1.1.14! root     1073:                    fd_sector_calc(kh, kt, ks, cur_drv->last_sect,
        !          1074:                                   NUM_SIDES(cur_drv)));
1.1.1.4   root     1075:     switch (fd_seek(cur_drv, kh, kt, ks, fdctrl->config & FD_CONFIG_EIS)) {
1.1       root     1076:     case 2:
                   1077:         /* sect too big */
1.1.1.4   root     1078:         fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
1.1       root     1079:         fdctrl->fifo[3] = kt;
                   1080:         fdctrl->fifo[4] = kh;
                   1081:         fdctrl->fifo[5] = ks;
                   1082:         return;
                   1083:     case 3:
                   1084:         /* track too big */
1.1.1.4   root     1085:         fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_EC, 0x00);
1.1       root     1086:         fdctrl->fifo[3] = kt;
                   1087:         fdctrl->fifo[4] = kh;
                   1088:         fdctrl->fifo[5] = ks;
                   1089:         return;
                   1090:     case 4:
                   1091:         /* No seek enabled */
1.1.1.4   root     1092:         fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
1.1       root     1093:         fdctrl->fifo[3] = kt;
                   1094:         fdctrl->fifo[4] = kh;
                   1095:         fdctrl->fifo[5] = ks;
                   1096:         return;
                   1097:     case 1:
                   1098:         did_seek = 1;
                   1099:         break;
                   1100:     default:
                   1101:         break;
                   1102:     }
1.1.1.4   root     1103: 
1.1.1.14! root     1104:     /* Check the data rate. If the programmed data rate does not match
        !          1105:      * the currently inserted medium, the operation has to fail. */
        !          1106:     if (fdctrl->check_media_rate &&
        !          1107:         (fdctrl->dsr & FD_DSR_DRATEMASK) != cur_drv->media_rate) {
        !          1108:         FLOPPY_DPRINTF("data rate mismatch (fdc=%d, media=%d)\n",
        !          1109:                        fdctrl->dsr & FD_DSR_DRATEMASK, cur_drv->media_rate);
        !          1110:         fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_MA, 0x00);
        !          1111:         fdctrl->fifo[3] = kt;
        !          1112:         fdctrl->fifo[4] = kh;
        !          1113:         fdctrl->fifo[5] = ks;
        !          1114:         return;
        !          1115:     }
        !          1116: 
1.1       root     1117:     /* Set the FIFO state */
                   1118:     fdctrl->data_dir = direction;
                   1119:     fdctrl->data_pos = 0;
1.1.1.4   root     1120:     fdctrl->msr |= FD_MSR_CMDBUSY;
1.1       root     1121:     if (fdctrl->fifo[0] & 0x80)
                   1122:         fdctrl->data_state |= FD_STATE_MULTI;
                   1123:     else
                   1124:         fdctrl->data_state &= ~FD_STATE_MULTI;
                   1125:     if (did_seek)
                   1126:         fdctrl->data_state |= FD_STATE_SEEK;
                   1127:     else
                   1128:         fdctrl->data_state &= ~FD_STATE_SEEK;
                   1129:     if (fdctrl->fifo[5] == 00) {
                   1130:         fdctrl->data_len = fdctrl->fifo[8];
                   1131:     } else {
1.1.1.3   root     1132:         int tmp;
1.1.1.2   root     1133:         fdctrl->data_len = 128 << (fdctrl->fifo[5] > 7 ? 7 : fdctrl->fifo[5]);
1.1.1.4   root     1134:         tmp = (fdctrl->fifo[6] - ks + 1);
1.1       root     1135:         if (fdctrl->fifo[0] & 0x80)
1.1.1.4   root     1136:             tmp += fdctrl->fifo[6];
1.1.1.3   root     1137:         fdctrl->data_len *= tmp;
1.1       root     1138:     }
                   1139:     fdctrl->eot = fdctrl->fifo[6];
1.1.1.4   root     1140:     if (fdctrl->dor & FD_DOR_DMAEN) {
1.1       root     1141:         int dma_mode;
                   1142:         /* DMA transfer are enabled. Check if DMA channel is well programmed */
                   1143:         dma_mode = DMA_get_channel_mode(fdctrl->dma_chann);
                   1144:         dma_mode = (dma_mode >> 2) & 3;
                   1145:         FLOPPY_DPRINTF("dma_mode=%d direction=%d (%d - %d)\n",
1.1.1.3   root     1146:                        dma_mode, direction,
1.1       root     1147:                        (128 << fdctrl->fifo[5]) *
1.1.1.3   root     1148:                        (cur_drv->last_sect - ks + 1), fdctrl->data_len);
1.1       root     1149:         if (((direction == FD_DIR_SCANE || direction == FD_DIR_SCANL ||
                   1150:               direction == FD_DIR_SCANH) && dma_mode == 0) ||
                   1151:             (direction == FD_DIR_WRITE && dma_mode == 2) ||
                   1152:             (direction == FD_DIR_READ && dma_mode == 1)) {
                   1153:             /* No access is allowed until DMA transfer has completed */
1.1.1.4   root     1154:             fdctrl->msr &= ~FD_MSR_RQM;
1.1       root     1155:             /* Now, we just have to wait for the DMA controller to
                   1156:              * recall us...
                   1157:              */
                   1158:             DMA_hold_DREQ(fdctrl->dma_chann);
                   1159:             DMA_schedule(fdctrl->dma_chann);
                   1160:             return;
                   1161:         } else {
1.1.1.3   root     1162:             FLOPPY_ERROR("dma_mode=%d direction=%d\n", dma_mode, direction);
1.1       root     1163:         }
                   1164:     }
                   1165:     FLOPPY_DPRINTF("start non-DMA transfer\n");
1.1.1.4   root     1166:     fdctrl->msr |= FD_MSR_NONDMA;
                   1167:     if (direction != FD_DIR_WRITE)
                   1168:         fdctrl->msr |= FD_MSR_DIO;
1.1       root     1169:     /* IO based transfer: calculate len */
                   1170:     fdctrl_raise_irq(fdctrl, 0x00);
                   1171: 
                   1172:     return;
                   1173: }
                   1174: 
                   1175: /* Prepare a transfer of deleted data */
1.1.1.10  root     1176: static void fdctrl_start_transfer_del(FDCtrl *fdctrl, int direction)
1.1       root     1177: {
1.1.1.4   root     1178:     FLOPPY_ERROR("fdctrl_start_transfer_del() unimplemented\n");
                   1179: 
1.1       root     1180:     /* We don't handle deleted data,
                   1181:      * so we don't return *ANYTHING*
                   1182:      */
1.1.1.4   root     1183:     fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
1.1       root     1184: }
                   1185: 
                   1186: /* handlers for DMA transfers */
                   1187: static int fdctrl_transfer_handler (void *opaque, int nchan,
                   1188:                                     int dma_pos, int dma_len)
                   1189: {
1.1.1.10  root     1190:     FDCtrl *fdctrl;
                   1191:     FDrive *cur_drv;
1.1       root     1192:     int len, start_pos, rel_pos;
                   1193:     uint8_t status0 = 0x00, status1 = 0x00, status2 = 0x00;
                   1194: 
                   1195:     fdctrl = opaque;
1.1.1.4   root     1196:     if (fdctrl->msr & FD_MSR_RQM) {
1.1       root     1197:         FLOPPY_DPRINTF("Not in DMA transfer mode !\n");
                   1198:         return 0;
                   1199:     }
                   1200:     cur_drv = get_cur_drv(fdctrl);
                   1201:     if (fdctrl->data_dir == FD_DIR_SCANE || fdctrl->data_dir == FD_DIR_SCANL ||
                   1202:         fdctrl->data_dir == FD_DIR_SCANH)
1.1.1.4   root     1203:         status2 = FD_SR2_SNS;
1.1       root     1204:     if (dma_len > fdctrl->data_len)
                   1205:         dma_len = fdctrl->data_len;
                   1206:     if (cur_drv->bs == NULL) {
1.1.1.3   root     1207:         if (fdctrl->data_dir == FD_DIR_WRITE)
1.1.1.4   root     1208:             fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
1.1.1.3   root     1209:         else
1.1.1.4   root     1210:             fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
1.1.1.3   root     1211:         len = 0;
1.1       root     1212:         goto transfer_error;
                   1213:     }
                   1214:     rel_pos = fdctrl->data_pos % FD_SECTOR_LEN;
                   1215:     for (start_pos = fdctrl->data_pos; fdctrl->data_pos < dma_len;) {
                   1216:         len = dma_len - fdctrl->data_pos;
                   1217:         if (len + rel_pos > FD_SECTOR_LEN)
                   1218:             len = FD_SECTOR_LEN - rel_pos;
                   1219:         FLOPPY_DPRINTF("copy %d bytes (%d %d %d) %d pos %d %02x "
                   1220:                        "(%d-0x%08x 0x%08x)\n", len, dma_len, fdctrl->data_pos,
1.1.1.4   root     1221:                        fdctrl->data_len, GET_CUR_DRV(fdctrl), cur_drv->head,
1.1       root     1222:                        cur_drv->track, cur_drv->sect, fd_sector(cur_drv),
1.1.1.4   root     1223:                        fd_sector(cur_drv) * FD_SECTOR_LEN);
1.1       root     1224:         if (fdctrl->data_dir != FD_DIR_WRITE ||
1.1.1.3   root     1225:             len < FD_SECTOR_LEN || rel_pos != 0) {
1.1       root     1226:             /* READ & SCAN commands and realign to a sector for WRITE */
                   1227:             if (bdrv_read(cur_drv->bs, fd_sector(cur_drv),
1.1.1.3   root     1228:                           fdctrl->fifo, 1) < 0) {
1.1       root     1229:                 FLOPPY_DPRINTF("Floppy: error getting sector %d\n",
                   1230:                                fd_sector(cur_drv));
                   1231:                 /* Sure, image size is too small... */
                   1232:                 memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
                   1233:             }
                   1234:         }
1.1.1.3   root     1235:         switch (fdctrl->data_dir) {
                   1236:         case FD_DIR_READ:
                   1237:             /* READ commands */
1.1       root     1238:             DMA_write_memory (nchan, fdctrl->fifo + rel_pos,
                   1239:                               fdctrl->data_pos, len);
1.1.1.3   root     1240:             break;
                   1241:         case FD_DIR_WRITE:
1.1       root     1242:             /* WRITE commands */
1.1.1.14! root     1243:             if (cur_drv->ro) {
        !          1244:                 /* Handle readonly medium early, no need to do DMA, touch the
        !          1245:                  * LED or attempt any writes. A real floppy doesn't attempt
        !          1246:                  * to write to readonly media either. */
        !          1247:                 fdctrl_stop_transfer(fdctrl,
        !          1248:                                      FD_SR0_ABNTERM | FD_SR0_SEEK, FD_SR1_NW,
        !          1249:                                      0x00);
        !          1250:                 goto transfer_error;
        !          1251:             }
        !          1252: 
1.1       root     1253:             DMA_read_memory (nchan, fdctrl->fifo + rel_pos,
                   1254:                              fdctrl->data_pos, len);
                   1255:             if (bdrv_write(cur_drv->bs, fd_sector(cur_drv),
1.1.1.3   root     1256:                            fdctrl->fifo, 1) < 0) {
1.1.1.4   root     1257:                 FLOPPY_ERROR("writing sector %d\n", fd_sector(cur_drv));
                   1258:                 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
1.1       root     1259:                 goto transfer_error;
                   1260:             }
1.1.1.3   root     1261:             break;
                   1262:         default:
                   1263:             /* SCAN commands */
1.1       root     1264:             {
1.1.1.3   root     1265:                 uint8_t tmpbuf[FD_SECTOR_LEN];
1.1       root     1266:                 int ret;
                   1267:                 DMA_read_memory (nchan, tmpbuf, fdctrl->data_pos, len);
                   1268:                 ret = memcmp(tmpbuf, fdctrl->fifo + rel_pos, len);
                   1269:                 if (ret == 0) {
1.1.1.4   root     1270:                     status2 = FD_SR2_SEH;
1.1       root     1271:                     goto end_transfer;
                   1272:                 }
                   1273:                 if ((ret < 0 && fdctrl->data_dir == FD_DIR_SCANL) ||
                   1274:                     (ret > 0 && fdctrl->data_dir == FD_DIR_SCANH)) {
                   1275:                     status2 = 0x00;
                   1276:                     goto end_transfer;
                   1277:                 }
                   1278:             }
1.1.1.3   root     1279:             break;
1.1       root     1280:         }
1.1.1.3   root     1281:         fdctrl->data_pos += len;
                   1282:         rel_pos = fdctrl->data_pos % FD_SECTOR_LEN;
1.1       root     1283:         if (rel_pos == 0) {
                   1284:             /* Seek to next sector */
1.1.1.4   root     1285:             if (!fdctrl_seek_to_next_sect(fdctrl, cur_drv))
                   1286:                 break;
1.1       root     1287:         }
                   1288:     }
1.1.1.3   root     1289:  end_transfer:
1.1       root     1290:     len = fdctrl->data_pos - start_pos;
                   1291:     FLOPPY_DPRINTF("end transfer %d %d %d\n",
1.1.1.3   root     1292:                    fdctrl->data_pos, len, fdctrl->data_len);
1.1       root     1293:     if (fdctrl->data_dir == FD_DIR_SCANE ||
                   1294:         fdctrl->data_dir == FD_DIR_SCANL ||
                   1295:         fdctrl->data_dir == FD_DIR_SCANH)
1.1.1.4   root     1296:         status2 = FD_SR2_SEH;
1.1       root     1297:     if (FD_DID_SEEK(fdctrl->data_state))
1.1.1.4   root     1298:         status0 |= FD_SR0_SEEK;
1.1       root     1299:     fdctrl->data_len -= len;
                   1300:     fdctrl_stop_transfer(fdctrl, status0, status1, status2);
1.1.1.3   root     1301:  transfer_error:
1.1       root     1302: 
                   1303:     return len;
                   1304: }
                   1305: 
                   1306: /* Data register : 0x05 */
1.1.1.10  root     1307: static uint32_t fdctrl_read_data(FDCtrl *fdctrl)
1.1       root     1308: {
1.1.1.10  root     1309:     FDrive *cur_drv;
1.1       root     1310:     uint32_t retval = 0;
1.1.1.4   root     1311:     int pos;
1.1       root     1312: 
                   1313:     cur_drv = get_cur_drv(fdctrl);
1.1.1.4   root     1314:     fdctrl->dsr &= ~FD_DSR_PWRDOWN;
                   1315:     if (!(fdctrl->msr & FD_MSR_RQM) || !(fdctrl->msr & FD_MSR_DIO)) {
                   1316:         FLOPPY_ERROR("controller not ready for reading\n");
1.1       root     1317:         return 0;
                   1318:     }
                   1319:     pos = fdctrl->data_pos;
1.1.1.4   root     1320:     if (fdctrl->msr & FD_MSR_NONDMA) {
1.1       root     1321:         pos %= FD_SECTOR_LEN;
                   1322:         if (pos == 0) {
1.1.1.4   root     1323:             if (fdctrl->data_pos != 0)
                   1324:                 if (!fdctrl_seek_to_next_sect(fdctrl, cur_drv)) {
                   1325:                     FLOPPY_DPRINTF("error seeking to next sector %d\n",
                   1326:                                    fd_sector(cur_drv));
                   1327:                     return 0;
                   1328:                 }
                   1329:             if (bdrv_read(cur_drv->bs, fd_sector(cur_drv), fdctrl->fifo, 1) < 0) {
                   1330:                 FLOPPY_DPRINTF("error getting sector %d\n",
                   1331:                                fd_sector(cur_drv));
                   1332:                 /* Sure, image size is too small... */
                   1333:                 memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
                   1334:             }
1.1       root     1335:         }
                   1336:     }
                   1337:     retval = fdctrl->fifo[pos];
                   1338:     if (++fdctrl->data_pos == fdctrl->data_len) {
                   1339:         fdctrl->data_pos = 0;
                   1340:         /* Switch from transfer mode to status mode
                   1341:          * then from status mode to command mode
                   1342:          */
1.1.1.4   root     1343:         if (fdctrl->msr & FD_MSR_NONDMA) {
                   1344:             fdctrl_stop_transfer(fdctrl, FD_SR0_SEEK, 0x00, 0x00);
1.1       root     1345:         } else {
                   1346:             fdctrl_reset_fifo(fdctrl);
                   1347:             fdctrl_reset_irq(fdctrl);
                   1348:         }
                   1349:     }
                   1350:     FLOPPY_DPRINTF("data register: 0x%02x\n", retval);
                   1351: 
                   1352:     return retval;
                   1353: }
                   1354: 
1.1.1.10  root     1355: static void fdctrl_format_sector(FDCtrl *fdctrl)
1.1       root     1356: {
1.1.1.10  root     1357:     FDrive *cur_drv;
1.1       root     1358:     uint8_t kh, kt, ks;
                   1359: 
1.1.1.4   root     1360:     SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
1.1       root     1361:     cur_drv = get_cur_drv(fdctrl);
                   1362:     kt = fdctrl->fifo[6];
                   1363:     kh = fdctrl->fifo[7];
                   1364:     ks = fdctrl->fifo[8];
                   1365:     FLOPPY_DPRINTF("format sector at %d %d %02x %02x (%d)\n",
1.1.1.4   root     1366:                    GET_CUR_DRV(fdctrl), kh, kt, ks,
1.1.1.14! root     1367:                    fd_sector_calc(kh, kt, ks, cur_drv->last_sect,
        !          1368:                                   NUM_SIDES(cur_drv)));
1.1.1.4   root     1369:     switch (fd_seek(cur_drv, kh, kt, ks, fdctrl->config & FD_CONFIG_EIS)) {
1.1       root     1370:     case 2:
                   1371:         /* sect too big */
1.1.1.4   root     1372:         fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
1.1       root     1373:         fdctrl->fifo[3] = kt;
                   1374:         fdctrl->fifo[4] = kh;
                   1375:         fdctrl->fifo[5] = ks;
                   1376:         return;
                   1377:     case 3:
                   1378:         /* track too big */
1.1.1.4   root     1379:         fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_EC, 0x00);
1.1       root     1380:         fdctrl->fifo[3] = kt;
                   1381:         fdctrl->fifo[4] = kh;
                   1382:         fdctrl->fifo[5] = ks;
                   1383:         return;
                   1384:     case 4:
                   1385:         /* No seek enabled */
1.1.1.4   root     1386:         fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
1.1       root     1387:         fdctrl->fifo[3] = kt;
                   1388:         fdctrl->fifo[4] = kh;
                   1389:         fdctrl->fifo[5] = ks;
                   1390:         return;
                   1391:     case 1:
                   1392:         fdctrl->data_state |= FD_STATE_SEEK;
                   1393:         break;
                   1394:     default:
                   1395:         break;
                   1396:     }
                   1397:     memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
                   1398:     if (cur_drv->bs == NULL ||
                   1399:         bdrv_write(cur_drv->bs, fd_sector(cur_drv), fdctrl->fifo, 1) < 0) {
1.1.1.3   root     1400:         FLOPPY_ERROR("formatting sector %d\n", fd_sector(cur_drv));
1.1.1.4   root     1401:         fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
1.1       root     1402:     } else {
1.1.1.3   root     1403:         if (cur_drv->sect == cur_drv->last_sect) {
                   1404:             fdctrl->data_state &= ~FD_STATE_FORMAT;
                   1405:             /* Last sector done */
                   1406:             if (FD_DID_SEEK(fdctrl->data_state))
1.1.1.4   root     1407:                 fdctrl_stop_transfer(fdctrl, FD_SR0_SEEK, 0x00, 0x00);
1.1.1.3   root     1408:             else
                   1409:                 fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00);
                   1410:         } else {
                   1411:             /* More to do */
                   1412:             fdctrl->data_pos = 0;
                   1413:             fdctrl->data_len = 4;
                   1414:         }
1.1       root     1415:     }
                   1416: }
                   1417: 
1.1.1.10  root     1418: static void fdctrl_handle_lock(FDCtrl *fdctrl, int direction)
1.1       root     1419: {
1.1.1.4   root     1420:     fdctrl->lock = (fdctrl->fifo[0] & 0x80) ? 1 : 0;
                   1421:     fdctrl->fifo[0] = fdctrl->lock << 4;
1.1.1.14! root     1422:     fdctrl_set_fifo(fdctrl, 1, 0);
1.1.1.4   root     1423: }
1.1       root     1424: 
1.1.1.10  root     1425: static void fdctrl_handle_dumpreg(FDCtrl *fdctrl, int direction)
1.1.1.4   root     1426: {
1.1.1.10  root     1427:     FDrive *cur_drv = get_cur_drv(fdctrl);
1.1.1.4   root     1428: 
                   1429:     /* Drives position */
                   1430:     fdctrl->fifo[0] = drv0(fdctrl)->track;
                   1431:     fdctrl->fifo[1] = drv1(fdctrl)->track;
                   1432: #if MAX_FD == 4
                   1433:     fdctrl->fifo[2] = drv2(fdctrl)->track;
                   1434:     fdctrl->fifo[3] = drv3(fdctrl)->track;
1.1       root     1435: #else
1.1.1.4   root     1436:     fdctrl->fifo[2] = 0;
                   1437:     fdctrl->fifo[3] = 0;
1.1       root     1438: #endif
1.1.1.4   root     1439:     /* timers */
                   1440:     fdctrl->fifo[4] = fdctrl->timer0;
                   1441:     fdctrl->fifo[5] = (fdctrl->timer1 << 1) | (fdctrl->dor & FD_DOR_DMAEN ? 1 : 0);
                   1442:     fdctrl->fifo[6] = cur_drv->last_sect;
                   1443:     fdctrl->fifo[7] = (fdctrl->lock << 7) |
                   1444:         (cur_drv->perpendicular << 2);
                   1445:     fdctrl->fifo[8] = fdctrl->config;
                   1446:     fdctrl->fifo[9] = fdctrl->precomp_trk;
                   1447:     fdctrl_set_fifo(fdctrl, 10, 0);
                   1448: }
                   1449: 
1.1.1.10  root     1450: static void fdctrl_handle_version(FDCtrl *fdctrl, int direction)
1.1.1.4   root     1451: {
                   1452:     /* Controller's version */
                   1453:     fdctrl->fifo[0] = fdctrl->version;
1.1.1.14! root     1454:     fdctrl_set_fifo(fdctrl, 1, 0);
1.1.1.4   root     1455: }
                   1456: 
1.1.1.10  root     1457: static void fdctrl_handle_partid(FDCtrl *fdctrl, int direction)
1.1.1.4   root     1458: {
                   1459:     fdctrl->fifo[0] = 0x41; /* Stepping 1 */
                   1460:     fdctrl_set_fifo(fdctrl, 1, 0);
                   1461: }
                   1462: 
1.1.1.10  root     1463: static void fdctrl_handle_restore(FDCtrl *fdctrl, int direction)
1.1.1.4   root     1464: {
1.1.1.10  root     1465:     FDrive *cur_drv = get_cur_drv(fdctrl);
1.1.1.4   root     1466: 
                   1467:     /* Drives position */
                   1468:     drv0(fdctrl)->track = fdctrl->fifo[3];
                   1469:     drv1(fdctrl)->track = fdctrl->fifo[4];
                   1470: #if MAX_FD == 4
                   1471:     drv2(fdctrl)->track = fdctrl->fifo[5];
                   1472:     drv3(fdctrl)->track = fdctrl->fifo[6];
                   1473: #endif
                   1474:     /* timers */
                   1475:     fdctrl->timer0 = fdctrl->fifo[7];
                   1476:     fdctrl->timer1 = fdctrl->fifo[8];
                   1477:     cur_drv->last_sect = fdctrl->fifo[9];
                   1478:     fdctrl->lock = fdctrl->fifo[10] >> 7;
                   1479:     cur_drv->perpendicular = (fdctrl->fifo[10] >> 2) & 0xF;
                   1480:     fdctrl->config = fdctrl->fifo[11];
                   1481:     fdctrl->precomp_trk = fdctrl->fifo[12];
                   1482:     fdctrl->pwrd = fdctrl->fifo[13];
                   1483:     fdctrl_reset_fifo(fdctrl);
                   1484: }
                   1485: 
1.1.1.10  root     1486: static void fdctrl_handle_save(FDCtrl *fdctrl, int direction)
1.1.1.4   root     1487: {
1.1.1.10  root     1488:     FDrive *cur_drv = get_cur_drv(fdctrl);
1.1.1.4   root     1489: 
                   1490:     fdctrl->fifo[0] = 0;
                   1491:     fdctrl->fifo[1] = 0;
                   1492:     /* Drives position */
                   1493:     fdctrl->fifo[2] = drv0(fdctrl)->track;
                   1494:     fdctrl->fifo[3] = drv1(fdctrl)->track;
                   1495: #if MAX_FD == 4
                   1496:     fdctrl->fifo[4] = drv2(fdctrl)->track;
                   1497:     fdctrl->fifo[5] = drv3(fdctrl)->track;
                   1498: #else
                   1499:     fdctrl->fifo[4] = 0;
                   1500:     fdctrl->fifo[5] = 0;
                   1501: #endif
                   1502:     /* timers */
                   1503:     fdctrl->fifo[6] = fdctrl->timer0;
                   1504:     fdctrl->fifo[7] = fdctrl->timer1;
                   1505:     fdctrl->fifo[8] = cur_drv->last_sect;
                   1506:     fdctrl->fifo[9] = (fdctrl->lock << 7) |
                   1507:         (cur_drv->perpendicular << 2);
                   1508:     fdctrl->fifo[10] = fdctrl->config;
                   1509:     fdctrl->fifo[11] = fdctrl->precomp_trk;
                   1510:     fdctrl->fifo[12] = fdctrl->pwrd;
                   1511:     fdctrl->fifo[13] = 0;
                   1512:     fdctrl->fifo[14] = 0;
1.1.1.14! root     1513:     fdctrl_set_fifo(fdctrl, 15, 0);
1.1.1.4   root     1514: }
                   1515: 
1.1.1.10  root     1516: static void fdctrl_handle_readid(FDCtrl *fdctrl, int direction)
1.1.1.4   root     1517: {
1.1.1.10  root     1518:     FDrive *cur_drv = get_cur_drv(fdctrl);
1.1.1.4   root     1519: 
                   1520:     cur_drv->head = (fdctrl->fifo[1] >> 2) & 1;
                   1521:     qemu_mod_timer(fdctrl->result_timer,
1.1.1.12  root     1522:                    qemu_get_clock_ns(vm_clock) + (get_ticks_per_sec() / 50));
1.1.1.4   root     1523: }
                   1524: 
1.1.1.10  root     1525: static void fdctrl_handle_format_track(FDCtrl *fdctrl, int direction)
1.1.1.4   root     1526: {
1.1.1.10  root     1527:     FDrive *cur_drv;
1.1.1.4   root     1528: 
                   1529:     SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
                   1530:     cur_drv = get_cur_drv(fdctrl);
                   1531:     fdctrl->data_state |= FD_STATE_FORMAT;
                   1532:     if (fdctrl->fifo[0] & 0x80)
                   1533:         fdctrl->data_state |= FD_STATE_MULTI;
                   1534:     else
                   1535:         fdctrl->data_state &= ~FD_STATE_MULTI;
                   1536:     fdctrl->data_state &= ~FD_STATE_SEEK;
                   1537:     cur_drv->bps =
                   1538:         fdctrl->fifo[2] > 7 ? 16384 : 128 << fdctrl->fifo[2];
                   1539: #if 0
                   1540:     cur_drv->last_sect =
                   1541:         cur_drv->flags & FDISK_DBL_SIDES ? fdctrl->fifo[3] :
                   1542:         fdctrl->fifo[3] / 2;
                   1543: #else
                   1544:     cur_drv->last_sect = fdctrl->fifo[3];
                   1545: #endif
                   1546:     /* TODO: implement format using DMA expected by the Bochs BIOS
                   1547:      * and Linux fdformat (read 3 bytes per sector via DMA and fill
                   1548:      * the sector with the specified fill byte
                   1549:      */
                   1550:     fdctrl->data_state &= ~FD_STATE_FORMAT;
                   1551:     fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00);
                   1552: }
                   1553: 
1.1.1.10  root     1554: static void fdctrl_handle_specify(FDCtrl *fdctrl, int direction)
1.1.1.4   root     1555: {
                   1556:     fdctrl->timer0 = (fdctrl->fifo[1] >> 4) & 0xF;
                   1557:     fdctrl->timer1 = fdctrl->fifo[2] >> 1;
                   1558:     if (fdctrl->fifo[2] & 1)
                   1559:         fdctrl->dor &= ~FD_DOR_DMAEN;
                   1560:     else
                   1561:         fdctrl->dor |= FD_DOR_DMAEN;
                   1562:     /* No result back */
                   1563:     fdctrl_reset_fifo(fdctrl);
                   1564: }
                   1565: 
1.1.1.10  root     1566: static void fdctrl_handle_sense_drive_status(FDCtrl *fdctrl, int direction)
1.1.1.4   root     1567: {
1.1.1.10  root     1568:     FDrive *cur_drv;
1.1.1.4   root     1569: 
                   1570:     SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
                   1571:     cur_drv = get_cur_drv(fdctrl);
                   1572:     cur_drv->head = (fdctrl->fifo[1] >> 2) & 1;
                   1573:     /* 1 Byte status back */
                   1574:     fdctrl->fifo[0] = (cur_drv->ro << 6) |
                   1575:         (cur_drv->track == 0 ? 0x10 : 0x00) |
                   1576:         (cur_drv->head << 2) |
                   1577:         GET_CUR_DRV(fdctrl) |
                   1578:         0x28;
                   1579:     fdctrl_set_fifo(fdctrl, 1, 0);
                   1580: }
                   1581: 
1.1.1.10  root     1582: static void fdctrl_handle_recalibrate(FDCtrl *fdctrl, int direction)
1.1.1.4   root     1583: {
1.1.1.10  root     1584:     FDrive *cur_drv;
1.1.1.4   root     1585: 
                   1586:     SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
                   1587:     cur_drv = get_cur_drv(fdctrl);
                   1588:     fd_recalibrate(cur_drv);
                   1589:     fdctrl_reset_fifo(fdctrl);
                   1590:     /* Raise Interrupt */
                   1591:     fdctrl_raise_irq(fdctrl, FD_SR0_SEEK);
                   1592: }
                   1593: 
1.1.1.10  root     1594: static void fdctrl_handle_sense_interrupt_status(FDCtrl *fdctrl, int direction)
1.1.1.4   root     1595: {
1.1.1.10  root     1596:     FDrive *cur_drv = get_cur_drv(fdctrl);
1.1.1.4   root     1597: 
                   1598:     if(fdctrl->reset_sensei > 0) {
                   1599:         fdctrl->fifo[0] =
                   1600:             FD_SR0_RDYCHG + FD_RESET_SENSEI_COUNT - fdctrl->reset_sensei;
                   1601:         fdctrl->reset_sensei--;
                   1602:     } else {
                   1603:         /* XXX: status0 handling is broken for read/write
                   1604:            commands, so we do this hack. It should be suppressed
                   1605:            ASAP */
                   1606:         fdctrl->fifo[0] =
                   1607:             FD_SR0_SEEK | (cur_drv->head << 2) | GET_CUR_DRV(fdctrl);
                   1608:     }
                   1609: 
                   1610:     fdctrl->fifo[1] = cur_drv->track;
                   1611:     fdctrl_set_fifo(fdctrl, 2, 0);
                   1612:     fdctrl_reset_irq(fdctrl);
                   1613:     fdctrl->status0 = FD_SR0_RDYCHG;
                   1614: }
                   1615: 
1.1.1.10  root     1616: static void fdctrl_handle_seek(FDCtrl *fdctrl, int direction)
1.1.1.4   root     1617: {
1.1.1.10  root     1618:     FDrive *cur_drv;
1.1.1.4   root     1619: 
                   1620:     SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
                   1621:     cur_drv = get_cur_drv(fdctrl);
                   1622:     fdctrl_reset_fifo(fdctrl);
1.1.1.14! root     1623:     /* The seek command just sends step pulses to the drive and doesn't care if
        !          1624:      * there is a medium inserted of if it's banging the head against the drive.
        !          1625:      */
1.1.1.4   root     1626:     if (fdctrl->fifo[2] > cur_drv->max_track) {
1.1.1.14! root     1627:         cur_drv->track = cur_drv->max_track;
1.1.1.4   root     1628:     } else {
                   1629:         cur_drv->track = fdctrl->fifo[2];
                   1630:     }
1.1.1.14! root     1631:     /* Raise Interrupt */
        !          1632:     fdctrl_raise_irq(fdctrl, FD_SR0_SEEK);
1.1.1.4   root     1633: }
                   1634: 
1.1.1.10  root     1635: static void fdctrl_handle_perpendicular_mode(FDCtrl *fdctrl, int direction)
1.1.1.4   root     1636: {
1.1.1.10  root     1637:     FDrive *cur_drv = get_cur_drv(fdctrl);
1.1.1.4   root     1638: 
                   1639:     if (fdctrl->fifo[1] & 0x80)
                   1640:         cur_drv->perpendicular = fdctrl->fifo[1] & 0x7;
                   1641:     /* No result back */
                   1642:     fdctrl_reset_fifo(fdctrl);
                   1643: }
                   1644: 
1.1.1.10  root     1645: static void fdctrl_handle_configure(FDCtrl *fdctrl, int direction)
1.1.1.4   root     1646: {
                   1647:     fdctrl->config = fdctrl->fifo[2];
                   1648:     fdctrl->precomp_trk =  fdctrl->fifo[3];
                   1649:     /* No result back */
                   1650:     fdctrl_reset_fifo(fdctrl);
                   1651: }
                   1652: 
1.1.1.10  root     1653: static void fdctrl_handle_powerdown_mode(FDCtrl *fdctrl, int direction)
1.1.1.4   root     1654: {
                   1655:     fdctrl->pwrd = fdctrl->fifo[1];
                   1656:     fdctrl->fifo[0] = fdctrl->fifo[1];
1.1.1.14! root     1657:     fdctrl_set_fifo(fdctrl, 1, 0);
1.1.1.4   root     1658: }
                   1659: 
1.1.1.10  root     1660: static void fdctrl_handle_option(FDCtrl *fdctrl, int direction)
1.1.1.4   root     1661: {
                   1662:     /* No result back */
                   1663:     fdctrl_reset_fifo(fdctrl);
                   1664: }
                   1665: 
1.1.1.10  root     1666: static void fdctrl_handle_drive_specification_command(FDCtrl *fdctrl, int direction)
1.1.1.4   root     1667: {
1.1.1.10  root     1668:     FDrive *cur_drv = get_cur_drv(fdctrl);
1.1.1.4   root     1669: 
                   1670:     if (fdctrl->fifo[fdctrl->data_pos - 1] & 0x80) {
                   1671:         /* Command parameters done */
                   1672:         if (fdctrl->fifo[fdctrl->data_pos - 1] & 0x40) {
                   1673:             fdctrl->fifo[0] = fdctrl->fifo[1];
                   1674:             fdctrl->fifo[2] = 0;
                   1675:             fdctrl->fifo[3] = 0;
1.1.1.14! root     1676:             fdctrl_set_fifo(fdctrl, 4, 0);
1.1.1.4   root     1677:         } else {
                   1678:             fdctrl_reset_fifo(fdctrl);
1.1       root     1679:         }
1.1.1.4   root     1680:     } else if (fdctrl->data_len > 7) {
                   1681:         /* ERROR */
                   1682:         fdctrl->fifo[0] = 0x80 |
                   1683:             (cur_drv->head << 2) | GET_CUR_DRV(fdctrl);
1.1.1.14! root     1684:         fdctrl_set_fifo(fdctrl, 1, 0);
1.1.1.4   root     1685:     }
                   1686: }
                   1687: 
1.1.1.10  root     1688: static void fdctrl_handle_relative_seek_out(FDCtrl *fdctrl, int direction)
1.1.1.4   root     1689: {
1.1.1.10  root     1690:     FDrive *cur_drv;
1.1.1.4   root     1691: 
                   1692:     SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
                   1693:     cur_drv = get_cur_drv(fdctrl);
                   1694:     if (fdctrl->fifo[2] + cur_drv->track >= cur_drv->max_track) {
                   1695:         cur_drv->track = cur_drv->max_track - 1;
                   1696:     } else {
                   1697:         cur_drv->track += fdctrl->fifo[2];
1.1       root     1698:     }
1.1.1.4   root     1699:     fdctrl_reset_fifo(fdctrl);
                   1700:     /* Raise Interrupt */
                   1701:     fdctrl_raise_irq(fdctrl, FD_SR0_SEEK);
                   1702: }
                   1703: 
1.1.1.10  root     1704: static void fdctrl_handle_relative_seek_in(FDCtrl *fdctrl, int direction)
1.1.1.4   root     1705: {
1.1.1.10  root     1706:     FDrive *cur_drv;
1.1.1.4   root     1707: 
                   1708:     SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
                   1709:     cur_drv = get_cur_drv(fdctrl);
                   1710:     if (fdctrl->fifo[2] > cur_drv->track) {
                   1711:         cur_drv->track = 0;
                   1712:     } else {
                   1713:         cur_drv->track -= fdctrl->fifo[2];
                   1714:     }
                   1715:     fdctrl_reset_fifo(fdctrl);
                   1716:     /* Raise Interrupt */
                   1717:     fdctrl_raise_irq(fdctrl, FD_SR0_SEEK);
                   1718: }
                   1719: 
                   1720: static const struct {
                   1721:     uint8_t value;
                   1722:     uint8_t mask;
                   1723:     const char* name;
                   1724:     int parameters;
1.1.1.10  root     1725:     void (*handler)(FDCtrl *fdctrl, int direction);
1.1.1.4   root     1726:     int direction;
                   1727: } handlers[] = {
                   1728:     { FD_CMD_READ, 0x1f, "READ", 8, fdctrl_start_transfer, FD_DIR_READ },
                   1729:     { FD_CMD_WRITE, 0x3f, "WRITE", 8, fdctrl_start_transfer, FD_DIR_WRITE },
                   1730:     { FD_CMD_SEEK, 0xff, "SEEK", 2, fdctrl_handle_seek },
                   1731:     { FD_CMD_SENSE_INTERRUPT_STATUS, 0xff, "SENSE INTERRUPT STATUS", 0, fdctrl_handle_sense_interrupt_status },
                   1732:     { FD_CMD_RECALIBRATE, 0xff, "RECALIBRATE", 1, fdctrl_handle_recalibrate },
                   1733:     { FD_CMD_FORMAT_TRACK, 0xbf, "FORMAT TRACK", 5, fdctrl_handle_format_track },
                   1734:     { FD_CMD_READ_TRACK, 0xbf, "READ TRACK", 8, fdctrl_start_transfer, FD_DIR_READ },
                   1735:     { FD_CMD_RESTORE, 0xff, "RESTORE", 17, fdctrl_handle_restore }, /* part of READ DELETED DATA */
                   1736:     { FD_CMD_SAVE, 0xff, "SAVE", 0, fdctrl_handle_save }, /* part of READ DELETED DATA */
                   1737:     { FD_CMD_READ_DELETED, 0x1f, "READ DELETED DATA", 8, fdctrl_start_transfer_del, FD_DIR_READ },
                   1738:     { FD_CMD_SCAN_EQUAL, 0x1f, "SCAN EQUAL", 8, fdctrl_start_transfer, FD_DIR_SCANE },
                   1739:     { FD_CMD_VERIFY, 0x1f, "VERIFY", 8, fdctrl_unimplemented },
                   1740:     { FD_CMD_SCAN_LOW_OR_EQUAL, 0x1f, "SCAN LOW OR EQUAL", 8, fdctrl_start_transfer, FD_DIR_SCANL },
                   1741:     { FD_CMD_SCAN_HIGH_OR_EQUAL, 0x1f, "SCAN HIGH OR EQUAL", 8, fdctrl_start_transfer, FD_DIR_SCANH },
                   1742:     { FD_CMD_WRITE_DELETED, 0x3f, "WRITE DELETED DATA", 8, fdctrl_start_transfer_del, FD_DIR_WRITE },
                   1743:     { FD_CMD_READ_ID, 0xbf, "READ ID", 1, fdctrl_handle_readid },
                   1744:     { FD_CMD_SPECIFY, 0xff, "SPECIFY", 2, fdctrl_handle_specify },
                   1745:     { FD_CMD_SENSE_DRIVE_STATUS, 0xff, "SENSE DRIVE STATUS", 1, fdctrl_handle_sense_drive_status },
                   1746:     { FD_CMD_PERPENDICULAR_MODE, 0xff, "PERPENDICULAR MODE", 1, fdctrl_handle_perpendicular_mode },
                   1747:     { FD_CMD_CONFIGURE, 0xff, "CONFIGURE", 3, fdctrl_handle_configure },
                   1748:     { FD_CMD_POWERDOWN_MODE, 0xff, "POWERDOWN MODE", 2, fdctrl_handle_powerdown_mode },
                   1749:     { FD_CMD_OPTION, 0xff, "OPTION", 1, fdctrl_handle_option },
                   1750:     { FD_CMD_DRIVE_SPECIFICATION_COMMAND, 0xff, "DRIVE SPECIFICATION COMMAND", 5, fdctrl_handle_drive_specification_command },
                   1751:     { FD_CMD_RELATIVE_SEEK_OUT, 0xff, "RELATIVE SEEK OUT", 2, fdctrl_handle_relative_seek_out },
                   1752:     { FD_CMD_FORMAT_AND_WRITE, 0xff, "FORMAT AND WRITE", 10, fdctrl_unimplemented },
                   1753:     { FD_CMD_RELATIVE_SEEK_IN, 0xff, "RELATIVE SEEK IN", 2, fdctrl_handle_relative_seek_in },
                   1754:     { FD_CMD_LOCK, 0x7f, "LOCK", 0, fdctrl_handle_lock },
                   1755:     { FD_CMD_DUMPREG, 0xff, "DUMPREG", 0, fdctrl_handle_dumpreg },
                   1756:     { FD_CMD_VERSION, 0xff, "VERSION", 0, fdctrl_handle_version },
                   1757:     { FD_CMD_PART_ID, 0xff, "PART ID", 0, fdctrl_handle_partid },
                   1758:     { FD_CMD_WRITE, 0x1f, "WRITE (BeOS)", 8, fdctrl_start_transfer, FD_DIR_WRITE }, /* not in specification ; BeOS 4.5 bug */
                   1759:     { 0, 0, "unknown", 0, fdctrl_unimplemented }, /* default handler */
                   1760: };
                   1761: /* Associate command to an index in the 'handlers' array */
                   1762: static uint8_t command_to_handler[256];
                   1763: 
1.1.1.10  root     1764: static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t value)
1.1.1.4   root     1765: {
1.1.1.10  root     1766:     FDrive *cur_drv;
1.1.1.4   root     1767:     int pos;
                   1768: 
                   1769:     /* Reset mode */
                   1770:     if (!(fdctrl->dor & FD_DOR_nRESET)) {
                   1771:         FLOPPY_DPRINTF("Floppy controller in RESET state !\n");
                   1772:         return;
                   1773:     }
                   1774:     if (!(fdctrl->msr & FD_MSR_RQM) || (fdctrl->msr & FD_MSR_DIO)) {
                   1775:         FLOPPY_ERROR("controller not ready for writing\n");
                   1776:         return;
                   1777:     }
                   1778:     fdctrl->dsr &= ~FD_DSR_PWRDOWN;
                   1779:     /* Is it write command time ? */
                   1780:     if (fdctrl->msr & FD_MSR_NONDMA) {
                   1781:         /* FIFO data write */
                   1782:         pos = fdctrl->data_pos++;
                   1783:         pos %= FD_SECTOR_LEN;
                   1784:         fdctrl->fifo[pos] = value;
                   1785:         if (pos == FD_SECTOR_LEN - 1 ||
                   1786:             fdctrl->data_pos == fdctrl->data_len) {
                   1787:             cur_drv = get_cur_drv(fdctrl);
                   1788:             if (bdrv_write(cur_drv->bs, fd_sector(cur_drv), fdctrl->fifo, 1) < 0) {
                   1789:                 FLOPPY_ERROR("writing sector %d\n", fd_sector(cur_drv));
                   1790:                 return;
                   1791:             }
                   1792:             if (!fdctrl_seek_to_next_sect(fdctrl, cur_drv)) {
                   1793:                 FLOPPY_DPRINTF("error seeking to next sector %d\n",
                   1794:                                fd_sector(cur_drv));
                   1795:                 return;
                   1796:             }
                   1797:         }
                   1798:         /* Switch from transfer mode to status mode
                   1799:          * then from status mode to command mode
                   1800:          */
                   1801:         if (fdctrl->data_pos == fdctrl->data_len)
                   1802:             fdctrl_stop_transfer(fdctrl, FD_SR0_SEEK, 0x00, 0x00);
                   1803:         return;
                   1804:     }
                   1805:     if (fdctrl->data_pos == 0) {
                   1806:         /* Command */
                   1807:         pos = command_to_handler[value & 0xff];
                   1808:         FLOPPY_DPRINTF("%s command\n", handlers[pos].name);
                   1809:         fdctrl->data_len = handlers[pos].parameters + 1;
1.1.1.14! root     1810:         fdctrl->msr |= FD_MSR_CMDBUSY;
1.1.1.4   root     1811:     }
                   1812: 
1.1       root     1813:     FLOPPY_DPRINTF("%s: %02x\n", __func__, value);
1.1.1.4   root     1814:     fdctrl->fifo[fdctrl->data_pos++] = value;
                   1815:     if (fdctrl->data_pos == fdctrl->data_len) {
1.1       root     1816:         /* We now have all parameters
                   1817:          * and will be able to treat the command
                   1818:          */
1.1.1.3   root     1819:         if (fdctrl->data_state & FD_STATE_FORMAT) {
                   1820:             fdctrl_format_sector(fdctrl);
1.1       root     1821:             return;
                   1822:         }
1.1.1.4   root     1823: 
                   1824:         pos = command_to_handler[fdctrl->fifo[0] & 0xff];
                   1825:         FLOPPY_DPRINTF("treat %s command\n", handlers[pos].name);
                   1826:         (*handlers[pos].handler)(fdctrl, handlers[pos].direction);
1.1       root     1827:     }
                   1828: }
                   1829: 
                   1830: static void fdctrl_result_timer(void *opaque)
                   1831: {
1.1.1.10  root     1832:     FDCtrl *fdctrl = opaque;
                   1833:     FDrive *cur_drv = get_cur_drv(fdctrl);
1.1.1.3   root     1834: 
                   1835:     /* Pretend we are spinning.
                   1836:      * This is needed for Coherent, which uses READ ID to check for
                   1837:      * sector interleaving.
                   1838:      */
                   1839:     if (cur_drv->last_sect != 0) {
                   1840:         cur_drv->sect = (cur_drv->sect % cur_drv->last_sect) + 1;
                   1841:     }
1.1.1.14! root     1842:     /* READ_ID can't automatically succeed! */
        !          1843:     if (fdctrl->check_media_rate &&
        !          1844:         (fdctrl->dsr & FD_DSR_DRATEMASK) != cur_drv->media_rate) {
        !          1845:         FLOPPY_DPRINTF("read id rate mismatch (fdc=%d, media=%d)\n",
        !          1846:                        fdctrl->dsr & FD_DSR_DRATEMASK, cur_drv->media_rate);
        !          1847:         fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_MA, 0x00);
        !          1848:     } else {
        !          1849:         fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00);
        !          1850:     }
1.1       root     1851: }
1.1.1.4   root     1852: 
1.1.1.13  root     1853: static void fdctrl_change_cb(void *opaque, bool load)
                   1854: {
                   1855:     FDrive *drive = opaque;
                   1856: 
                   1857:     drive->media_changed = 1;
1.1.1.14! root     1858:     fd_revalidate(drive);
1.1.1.13  root     1859: }
                   1860: 
                   1861: static const BlockDevOps fdctrl_block_ops = {
                   1862:     .change_media_cb = fdctrl_change_cb,
                   1863: };
                   1864: 
1.1.1.4   root     1865: /* Init functions */
1.1.1.10  root     1866: static int fdctrl_connect_drives(FDCtrl *fdctrl)
1.1.1.6   root     1867: {
                   1868:     unsigned int i;
1.1.1.10  root     1869:     FDrive *drive;
1.1.1.6   root     1870: 
                   1871:     for (i = 0; i < MAX_FD; i++) {
1.1.1.10  root     1872:         drive = &fdctrl->drives[i];
1.1.1.14! root     1873:         drive->fdctrl = fdctrl;
1.1.1.10  root     1874: 
                   1875:         if (drive->bs) {
                   1876:             if (bdrv_get_on_error(drive->bs, 0) != BLOCK_ERR_STOP_ENOSPC) {
                   1877:                 error_report("fdc doesn't support drive option werror");
                   1878:                 return -1;
                   1879:             }
                   1880:             if (bdrv_get_on_error(drive->bs, 1) != BLOCK_ERR_REPORT) {
                   1881:                 error_report("fdc doesn't support drive option rerror");
                   1882:                 return -1;
                   1883:             }
                   1884:         }
                   1885: 
                   1886:         fd_init(drive);
1.1.1.14! root     1887:         fdctrl_change_cb(drive, 0);
1.1.1.10  root     1888:         if (drive->bs) {
1.1.1.13  root     1889:             bdrv_set_dev_ops(drive->bs, &fdctrl_block_ops, drive);
1.1.1.10  root     1890:         }
1.1.1.6   root     1891:     }
1.1.1.10  root     1892:     return 0;
1.1.1.6   root     1893: }
                   1894: 
1.1.1.12  root     1895: void fdctrl_init_sysbus(qemu_irq irq, int dma_chann,
                   1896:                         target_phys_addr_t mmio_base, DriveInfo **fds)
1.1.1.6   root     1897: {
1.1.1.10  root     1898:     FDCtrl *fdctrl;
1.1.1.6   root     1899:     DeviceState *dev;
1.1.1.10  root     1900:     FDCtrlSysBus *sys;
1.1.1.6   root     1901: 
                   1902:     dev = qdev_create(NULL, "sysbus-fdc");
1.1.1.10  root     1903:     sys = DO_UPCAST(FDCtrlSysBus, busdev.qdev, dev);
1.1.1.6   root     1904:     fdctrl = &sys->state;
                   1905:     fdctrl->dma_chann = dma_chann; /* FIXME */
1.1.1.8   root     1906:     if (fds[0]) {
1.1.1.10  root     1907:         qdev_prop_set_drive_nofail(dev, "driveA", fds[0]->bdrv);
1.1.1.8   root     1908:     }
                   1909:     if (fds[1]) {
1.1.1.10  root     1910:         qdev_prop_set_drive_nofail(dev, "driveB", fds[1]->bdrv);
1.1.1.8   root     1911:     }
1.1.1.6   root     1912:     qdev_init_nofail(dev);
                   1913:     sysbus_connect_irq(&sys->busdev, 0, irq);
                   1914:     sysbus_mmio_map(&sys->busdev, 0, mmio_base);
                   1915: }
                   1916: 
1.1.1.12  root     1917: void sun4m_fdctrl_init(qemu_irq irq, target_phys_addr_t io_base,
                   1918:                        DriveInfo **fds, qemu_irq *fdc_tc)
1.1.1.6   root     1919: {
                   1920:     DeviceState *dev;
1.1.1.10  root     1921:     FDCtrlSysBus *sys;
1.1.1.6   root     1922: 
                   1923:     dev = qdev_create(NULL, "SUNW,fdtwo");
1.1.1.8   root     1924:     if (fds[0]) {
1.1.1.10  root     1925:         qdev_prop_set_drive_nofail(dev, "drive", fds[0]->bdrv);
1.1.1.8   root     1926:     }
1.1.1.6   root     1927:     qdev_init_nofail(dev);
1.1.1.10  root     1928:     sys = DO_UPCAST(FDCtrlSysBus, busdev.qdev, dev);
1.1.1.6   root     1929:     sysbus_connect_irq(&sys->busdev, 0, irq);
                   1930:     sysbus_mmio_map(&sys->busdev, 0, io_base);
                   1931:     *fdc_tc = qdev_get_gpio_in(dev, 0);
                   1932: }
                   1933: 
1.1.1.10  root     1934: static int fdctrl_init_common(FDCtrl *fdctrl)
1.1.1.4   root     1935: {
                   1936:     int i, j;
1.1.1.6   root     1937:     static int command_tables_inited = 0;
1.1.1.4   root     1938: 
                   1939:     /* Fill 'command_to_handler' lookup table */
1.1.1.6   root     1940:     if (!command_tables_inited) {
                   1941:         command_tables_inited = 1;
                   1942:         for (i = ARRAY_SIZE(handlers) - 1; i >= 0; i--) {
                   1943:             for (j = 0; j < sizeof(command_to_handler); j++) {
                   1944:                 if ((j & handlers[i].mask) == handlers[i].value) {
                   1945:                     command_to_handler[j] = i;
                   1946:                 }
                   1947:             }
1.1.1.4   root     1948:         }
                   1949:     }
                   1950: 
                   1951:     FLOPPY_DPRINTF("init controller\n");
                   1952:     fdctrl->fifo = qemu_memalign(512, FD_SECTOR_LEN);
1.1.1.6   root     1953:     fdctrl->fifo_size = 512;
1.1.1.12  root     1954:     fdctrl->result_timer = qemu_new_timer_ns(vm_clock,
1.1.1.4   root     1955:                                           fdctrl_result_timer, fdctrl);
                   1956: 
                   1957:     fdctrl->version = 0x90; /* Intel 82078 controller */
                   1958:     fdctrl->config = FD_CONFIG_EIS | FD_CONFIG_EFIFO; /* Implicit seek, polling & FIFO enabled */
1.1.1.6   root     1959:     fdctrl->num_floppies = MAX_FD;
                   1960: 
                   1961:     if (fdctrl->dma_chann != -1)
                   1962:         DMA_register_channel(fdctrl->dma_chann, &fdctrl_transfer_handler, fdctrl);
1.1.1.10  root     1963:     return fdctrl_connect_drives(fdctrl);
1.1.1.4   root     1964: }
                   1965: 
1.1.1.13  root     1966: static const MemoryRegionPortio fdc_portio_list[] = {
                   1967:     { 1, 5, 1, .read = fdctrl_read, .write = fdctrl_write },
                   1968:     { 7, 1, 1, .read = fdctrl_read, .write = fdctrl_write },
                   1969:     PORTIO_END_OF_LIST(),
                   1970: };
                   1971: 
1.1.1.6   root     1972: static int isabus_fdc_init1(ISADevice *dev)
1.1.1.4   root     1973: {
1.1.1.10  root     1974:     FDCtrlISABus *isa = DO_UPCAST(FDCtrlISABus, busdev, dev);
                   1975:     FDCtrl *fdctrl = &isa->state;
1.1.1.6   root     1976:     int ret;
1.1.1.4   root     1977: 
1.1.1.14! root     1978:     isa_register_portio_list(dev, isa->iobase, fdc_portio_list, fdctrl, "fdc");
1.1.1.11  root     1979: 
1.1.1.14! root     1980:     isa_init_irq(&isa->busdev, &fdctrl->irq, isa->irq);
        !          1981:     fdctrl->dma_chann = isa->dma;
1.1.1.4   root     1982: 
1.1.1.14! root     1983:     qdev_set_legacy_instance_id(&dev->qdev, isa->iobase, 2);
1.1.1.10  root     1984:     ret = fdctrl_init_common(fdctrl);
1.1.1.5   root     1985: 
1.1.1.11  root     1986:     add_boot_device_path(isa->bootindexA, &dev->qdev, "/floppy@0");
                   1987:     add_boot_device_path(isa->bootindexB, &dev->qdev, "/floppy@1");
                   1988: 
1.1.1.6   root     1989:     return ret;
1.1.1.4   root     1990: }
                   1991: 
1.1.1.6   root     1992: static int sysbus_fdc_init1(SysBusDevice *dev)
1.1.1.4   root     1993: {
1.1.1.10  root     1994:     FDCtrlSysBus *sys = DO_UPCAST(FDCtrlSysBus, busdev, dev);
                   1995:     FDCtrl *fdctrl = &sys->state;
1.1.1.6   root     1996:     int ret;
1.1.1.4   root     1997: 
1.1.1.14! root     1998:     memory_region_init_io(&fdctrl->iomem, &fdctrl_mem_ops, fdctrl, "fdc", 0x08);
        !          1999:     sysbus_init_mmio(dev, &fdctrl->iomem);
1.1.1.6   root     2000:     sysbus_init_irq(dev, &fdctrl->irq);
                   2001:     qdev_init_gpio_in(&dev->qdev, fdctrl_handle_tc, 1);
                   2002:     fdctrl->dma_chann = -1;
1.1.1.5   root     2003: 
1.1.1.14! root     2004:     qdev_set_legacy_instance_id(&dev->qdev, 0 /* io */, 2); /* FIXME */
1.1.1.10  root     2005:     ret = fdctrl_init_common(fdctrl);
1.1.1.4   root     2006: 
1.1.1.6   root     2007:     return ret;
1.1.1.4   root     2008: }
1.1.1.5   root     2009: 
1.1.1.6   root     2010: static int sun4m_fdc_init1(SysBusDevice *dev)
1.1.1.5   root     2011: {
1.1.1.10  root     2012:     FDCtrl *fdctrl = &(FROM_SYSBUS(FDCtrlSysBus, dev)->state);
1.1.1.5   root     2013: 
1.1.1.14! root     2014:     memory_region_init_io(&fdctrl->iomem, &fdctrl_mem_strict_ops, fdctrl,
        !          2015:                           "fdctrl", 0x08);
        !          2016:     sysbus_init_mmio(dev, &fdctrl->iomem);
1.1.1.6   root     2017:     sysbus_init_irq(dev, &fdctrl->irq);
                   2018:     qdev_init_gpio_in(&dev->qdev, fdctrl_handle_tc, 1);
                   2019: 
                   2020:     fdctrl->sun4m = 1;
1.1.1.14! root     2021:     qdev_set_legacy_instance_id(&dev->qdev, 0 /* io */, 2); /* FIXME */
1.1.1.10  root     2022:     return fdctrl_init_common(fdctrl);
1.1.1.5   root     2023: }
                   2024: 
1.1.1.13  root     2025: void fdc_get_bs(BlockDriverState *bs[], ISADevice *dev)
                   2026: {
                   2027:     FDCtrlISABus *isa = DO_UPCAST(FDCtrlISABus, busdev, dev);
                   2028:     FDCtrl *fdctrl = &isa->state;
                   2029:     int i;
                   2030: 
                   2031:     for (i = 0; i < MAX_FD; i++) {
                   2032:         bs[i] = fdctrl->drives[i].bs;
                   2033:     }
                   2034: }
                   2035: 
                   2036: 
1.1.1.10  root     2037: static const VMStateDescription vmstate_isa_fdc ={
                   2038:     .name = "fdc",
                   2039:     .version_id = 2,
                   2040:     .minimum_version_id = 2,
                   2041:     .fields = (VMStateField []) {
                   2042:         VMSTATE_STRUCT(state, FDCtrlISABus, 0, vmstate_fdc, FDCtrl),
                   2043:         VMSTATE_END_OF_LIST()
                   2044:     }
                   2045: };
                   2046: 
1.1.1.14! root     2047: static Property isa_fdc_properties[] = {
        !          2048:     DEFINE_PROP_HEX32("iobase", FDCtrlISABus, iobase, 0x3f0),
        !          2049:     DEFINE_PROP_UINT32("irq", FDCtrlISABus, irq, 6),
        !          2050:     DEFINE_PROP_UINT32("dma", FDCtrlISABus, dma, 2),
        !          2051:     DEFINE_PROP_DRIVE("driveA", FDCtrlISABus, state.drives[0].bs),
        !          2052:     DEFINE_PROP_DRIVE("driveB", FDCtrlISABus, state.drives[1].bs),
        !          2053:     DEFINE_PROP_INT32("bootindexA", FDCtrlISABus, bootindexA, -1),
        !          2054:     DEFINE_PROP_INT32("bootindexB", FDCtrlISABus, bootindexB, -1),
        !          2055:     DEFINE_PROP_BIT("check_media_rate", FDCtrlISABus, state.check_media_rate,
        !          2056:                     0, true),
        !          2057:     DEFINE_PROP_END_OF_LIST(),
        !          2058: };
        !          2059: 
        !          2060: static void isabus_fdc_class_init1(ObjectClass *klass, void *data)
        !          2061: {
        !          2062:     DeviceClass *dc = DEVICE_CLASS(klass);
        !          2063:     ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
        !          2064:     ic->init = isabus_fdc_init1;
        !          2065:     dc->fw_name = "fdc";
        !          2066:     dc->no_user = 1;
        !          2067:     dc->reset = fdctrl_external_reset_isa;
        !          2068:     dc->vmsd = &vmstate_isa_fdc;
        !          2069:     dc->props = isa_fdc_properties;
        !          2070: }
        !          2071: 
        !          2072: static TypeInfo isa_fdc_info = {
        !          2073:     .name          = "isa-fdc",
        !          2074:     .parent        = TYPE_ISA_DEVICE,
        !          2075:     .instance_size = sizeof(FDCtrlISABus),
        !          2076:     .class_init    = isabus_fdc_class_init1,
1.1.1.6   root     2077: };
1.1.1.5   root     2078: 
1.1.1.10  root     2079: static const VMStateDescription vmstate_sysbus_fdc ={
                   2080:     .name = "fdc",
                   2081:     .version_id = 2,
                   2082:     .minimum_version_id = 2,
                   2083:     .fields = (VMStateField []) {
                   2084:         VMSTATE_STRUCT(state, FDCtrlSysBus, 0, vmstate_fdc, FDCtrl),
                   2085:         VMSTATE_END_OF_LIST()
                   2086:     }
                   2087: };
                   2088: 
1.1.1.14! root     2089: static Property sysbus_fdc_properties[] = {
        !          2090:     DEFINE_PROP_DRIVE("driveA", FDCtrlSysBus, state.drives[0].bs),
        !          2091:     DEFINE_PROP_DRIVE("driveB", FDCtrlSysBus, state.drives[1].bs),
        !          2092:     DEFINE_PROP_END_OF_LIST(),
1.1.1.6   root     2093: };
                   2094: 
1.1.1.14! root     2095: static void sysbus_fdc_class_init(ObjectClass *klass, void *data)
        !          2096: {
        !          2097:     DeviceClass *dc = DEVICE_CLASS(klass);
        !          2098:     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
        !          2099: 
        !          2100:     k->init = sysbus_fdc_init1;
        !          2101:     dc->reset = fdctrl_external_reset_sysbus;
        !          2102:     dc->vmsd = &vmstate_sysbus_fdc;
        !          2103:     dc->props = sysbus_fdc_properties;
        !          2104: }
        !          2105: 
        !          2106: static TypeInfo sysbus_fdc_info = {
        !          2107:     .name          = "sysbus-fdc",
        !          2108:     .parent        = TYPE_SYS_BUS_DEVICE,
        !          2109:     .instance_size = sizeof(FDCtrlSysBus),
        !          2110:     .class_init    = sysbus_fdc_class_init,
        !          2111: };
        !          2112: 
        !          2113: static Property sun4m_fdc_properties[] = {
        !          2114:     DEFINE_PROP_DRIVE("drive", FDCtrlSysBus, state.drives[0].bs),
        !          2115:     DEFINE_PROP_END_OF_LIST(),
        !          2116: };
        !          2117: 
        !          2118: static void sun4m_fdc_class_init(ObjectClass *klass, void *data)
        !          2119: {
        !          2120:     DeviceClass *dc = DEVICE_CLASS(klass);
        !          2121:     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
        !          2122: 
        !          2123:     k->init = sun4m_fdc_init1;
        !          2124:     dc->reset = fdctrl_external_reset_sysbus;
        !          2125:     dc->vmsd = &vmstate_sysbus_fdc;
        !          2126:     dc->props = sun4m_fdc_properties;
        !          2127: }
        !          2128: 
        !          2129: static TypeInfo sun4m_fdc_info = {
        !          2130:     .name          = "SUNW,fdtwo",
        !          2131:     .parent        = TYPE_SYS_BUS_DEVICE,
        !          2132:     .instance_size = sizeof(FDCtrlSysBus),
        !          2133:     .class_init    = sun4m_fdc_class_init,
1.1.1.5   root     2134: };
                   2135: 
1.1.1.14! root     2136: static void fdc_register_types(void)
1.1.1.5   root     2137: {
1.1.1.14! root     2138:     type_register_static(&isa_fdc_info);
        !          2139:     type_register_static(&sysbus_fdc_info);
        !          2140:     type_register_static(&sun4m_fdc_info);
1.1.1.5   root     2141: }
                   2142: 
1.1.1.14! root     2143: type_init(fdc_register_types)

unix.superglobalmegacorp.com

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