Revision 99a0949b hw/fdc.c

b/hw/fdc.c
61 61
#define FD_RESET_SENSEI_COUNT  4   /* Number of sense interrupts on RESET */
62 62

  
63 63
/* Floppy disk drive emulation */
64
typedef enum fdisk_type_t {
64
typedef enum fdisk_type {
65 65
    FDRIVE_DISK_288   = 0x01, /* 2.88 MB disk           */
66 66
    FDRIVE_DISK_144   = 0x02, /* 1.44 MB disk           */
67 67
    FDRIVE_DISK_720   = 0x03, /* 720 kB disk            */
68 68
    FDRIVE_DISK_USER  = 0x04, /* User defined geometry  */
69 69
    FDRIVE_DISK_NONE  = 0x05, /* No disk                */
70
} fdisk_type_t;
70
} e_fdisk_type;
71 71

  
72
typedef enum fdrive_type_t {
72
typedef enum fdrive_type {
73 73
    FDRIVE_DRV_144  = 0x00,   /* 1.44 MB 3"5 drive      */
74 74
    FDRIVE_DRV_288  = 0x01,   /* 2.88 MB 3"5 drive      */
75 75
    FDRIVE_DRV_120  = 0x02,   /* 1.2  MB 5"25 drive     */
76 76
    FDRIVE_DRV_NONE = 0x03,   /* No drive connected     */
77
} fdrive_type_t;
77
} e_fdrive_type;
78 78

  
79
typedef enum fdisk_flags_t {
79
typedef enum fdisk_flags {
80 80
    FDISK_DBL_SIDES  = 0x01,
81
} fdisk_flags_t;
81
} e_fdisk_flags;
82 82

  
83
typedef struct fdrive_t {
83
typedef struct fdrive {
84 84
    BlockDriverState *bs;
85 85
    /* Drive status */
86
    fdrive_type_t drive;
86
    e_fdrive_type drive;
87 87
    uint8_t perpendicular;    /* 2.88 MB access mode    */
88 88
    /* Position */
89 89
    uint8_t head;
90 90
    uint8_t track;
91 91
    uint8_t sect;
92 92
    /* Media */
93
    fdisk_flags_t flags;
93
    e_fdisk_flags flags;
94 94
    uint8_t last_sect;        /* Nb sector per track    */
95 95
    uint8_t max_track;        /* Nb of tracks           */
96 96
    uint16_t bps;             /* Bytes per sector       */
97 97
    uint8_t ro;               /* Is read-only           */
98
} fdrive_t;
98
} a_fdrive;
99 99

  
100
static void fd_init (fdrive_t *drv, BlockDriverState *bs)
100
static void fd_init (a_fdrive *drv, BlockDriverState *bs)
101 101
{
102 102
    /* Drive */
103 103
    drv->bs = bs;
......
115 115
}
116 116

  
117 117
/* Returns current position, in sectors, for given drive */
118
static int fd_sector (fdrive_t *drv)
118
static int fd_sector (a_fdrive *drv)
119 119
{
120 120
    return _fd_sector(drv->head, drv->track, drv->sect, drv->last_sect);
121 121
}
......
127 127
 * returns 3 if sector is invalid
128 128
 * returns 4 if seek is disabled
129 129
 */
130
static int fd_seek (fdrive_t *drv, uint8_t head, uint8_t track, uint8_t sect,
130
static int fd_seek (a_fdrive *drv, uint8_t head, uint8_t track, uint8_t sect,
131 131
                    int enable_seek)
132 132
{
133 133
    uint32_t sector;
......
169 169
}
170 170

  
171 171
/* Set drive back to track 0 */
172
static void fd_recalibrate (fdrive_t *drv)
172
static void fd_recalibrate (a_fdrive *drv)
173 173
{
174 174
    FLOPPY_DPRINTF("recalibrate\n");
175 175
    drv->head = 0;
......
178 178
}
179 179

  
180 180
/* Recognize floppy formats */
181
typedef struct fd_format_t {
182
    fdrive_type_t drive;
183
    fdisk_type_t  disk;
181
typedef struct fd_format {
182
    e_fdrive_type drive;
183
    e_fdisk_type  disk;
184 184
    uint8_t last_sect;
185 185
    uint8_t max_track;
186 186
    uint8_t max_head;
187 187
    const char *str;
188
} fd_format_t;
188
} a_fd_format;
189 189

  
190
static const fd_format_t fd_formats[] = {
190
static const a_fd_format fd_formats[] = {
191 191
    /* First entry is default format */
192 192
    /* 1.44 MB 3"1/2 floppy disks */
193 193
    { FDRIVE_DRV_144, FDRIVE_DISK_144, 18, 80, 1, "1.44 MB 3\"1/2", },
......
235 235
};
236 236

  
237 237
/* Revalidate a disk drive after a disk change */
238
static void fd_revalidate (fdrive_t *drv)
238
static void fd_revalidate (a_fdrive *drv)
239 239
{
240
    const fd_format_t *parse;
240
    const a_fd_format *parse;
241 241
    uint64_t nb_sectors, size;
242 242
    int i, first_match, match;
243 243
    int nb_heads, max_track, last_sect, ro;
......
302 302
/********************************************************/
303 303
/* Intel 82078 floppy disk controller emulation          */
304 304

  
305
static void fdctrl_reset (fdctrl_t *fdctrl, int do_irq);
306
static void fdctrl_reset_fifo (fdctrl_t *fdctrl);
305
static void fdctrl_reset (a_fdctrl *fdctrl, int do_irq);
306
static void fdctrl_reset_fifo (a_fdctrl *fdctrl);
307 307
static int fdctrl_transfer_handler (void *opaque, int nchan,
308
                                    int dma_pos, int dma_len);
309
static void fdctrl_raise_irq (fdctrl_t *fdctrl, uint8_t status0);
310

  
311
static uint32_t fdctrl_read_statusA (fdctrl_t *fdctrl);
312
static uint32_t fdctrl_read_statusB (fdctrl_t *fdctrl);
313
static uint32_t fdctrl_read_dor (fdctrl_t *fdctrl);
314
static void fdctrl_write_dor (fdctrl_t *fdctrl, uint32_t value);
315
static uint32_t fdctrl_read_tape (fdctrl_t *fdctrl);
316
static void fdctrl_write_tape (fdctrl_t *fdctrl, uint32_t value);
317
static uint32_t fdctrl_read_main_status (fdctrl_t *fdctrl);
318
static void fdctrl_write_rate (fdctrl_t *fdctrl, uint32_t value);
319
static uint32_t fdctrl_read_data (fdctrl_t *fdctrl);
320
static void fdctrl_write_data (fdctrl_t *fdctrl, uint32_t value);
321
static uint32_t fdctrl_read_dir (fdctrl_t *fdctrl);
308
                                      int dma_pos, int dma_len);
309
static void fdctrl_raise_irq (a_fdctrl *fdctrl, uint8_t status0);
310

  
311
static uint32_t fdctrl_read_statusA (a_fdctrl *fdctrl);
312
static uint32_t fdctrl_read_statusB (a_fdctrl *fdctrl);
313
static uint32_t fdctrl_read_dor (a_fdctrl *fdctrl);
314
static void fdctrl_write_dor (a_fdctrl *fdctrl, uint32_t value);
315
static uint32_t fdctrl_read_tape (a_fdctrl *fdctrl);
316
static void fdctrl_write_tape (a_fdctrl *fdctrl, uint32_t value);
317
static uint32_t fdctrl_read_main_status (a_fdctrl *fdctrl);
318
static void fdctrl_write_rate (a_fdctrl *fdctrl, uint32_t value);
319
static uint32_t fdctrl_read_data (a_fdctrl *fdctrl);
320
static void fdctrl_write_data (a_fdctrl *fdctrl, uint32_t value);
321
static uint32_t fdctrl_read_dir (a_fdctrl *fdctrl);
322 322

  
323 323
enum {
324 324
    FD_DIR_WRITE   = 0,
......
470 470
#define FD_DID_SEEK(state) ((state) & FD_STATE_SEEK)
471 471
#define FD_FORMAT_CMD(state) ((state) & FD_STATE_FORMAT)
472 472

  
473
struct fdctrl_t {
473
struct fdctrl {
474 474
    /* Controller's identification */
475 475
    uint8_t version;
476 476
    /* HW */
......
511 511
    int sun4m;
512 512
    /* Floppy drives */
513 513
    uint8_t num_floppies;
514
    fdrive_t drives[MAX_FD];
514
    a_fdrive drives[MAX_FD];
515 515
    int reset_sensei;
516 516
};
517 517

  
518
typedef struct fdctrl_sysbus_t {
518
typedef struct fdctrl_sysbus {
519 519
    SysBusDevice busdev;
520
    struct fdctrl_t state;
521
} fdctrl_sysbus_t;
520
    struct fdctrl state;
521
} a_fdctrl_sysbus;
522 522

  
523
typedef struct fdctrl_isabus_t {
523
typedef struct fdctrl_isabus {
524 524
    ISADevice busdev;
525
    struct fdctrl_t state;
526
} fdctrl_isabus_t;
525
    struct fdctrl state;
526
} a_fdctrl_isabus;
527 527

  
528 528
static uint32_t fdctrl_read (void *opaque, uint32_t reg)
529 529
{
530
    fdctrl_t *fdctrl = opaque;
530
    a_fdctrl *fdctrl = opaque;
531 531
    uint32_t retval;
532 532

  
533 533
    switch (reg) {
......
563 563

  
564 564
static void fdctrl_write (void *opaque, uint32_t reg, uint32_t value)
565 565
{
566
    fdctrl_t *fdctrl = opaque;
566
    a_fdctrl *fdctrl = opaque;
567 567

  
568 568
    FLOPPY_DPRINTF("write reg%d: 0x%02x\n", reg & 7, value);
569 569

  
......
595 595
    fdctrl_write(opaque, reg & 7, value);
596 596
}
597 597

  
598
static uint32_t fdctrl_read_mem (void *opaque, target_phys_addr_t reg)
598
static uint32_t fdctrl_read_mem (void *opaque, a_target_phys_addr reg)
599 599
{
600 600
    return fdctrl_read(opaque, (uint32_t)reg);
601 601
}
602 602

  
603 603
static void fdctrl_write_mem (void *opaque,
604
                              target_phys_addr_t reg, uint32_t value)
604
                              a_target_phys_addr reg, uint32_t value)
605 605
{
606 606
    fdctrl_write(opaque, (uint32_t)reg, value);
607 607
}
......
636 636
    .minimum_version_id = 1,
637 637
    .minimum_version_id_old = 1,
638 638
    .fields      = (VMStateField []) {
639
        VMSTATE_UINT8(head, fdrive_t),
640
        VMSTATE_UINT8(track, fdrive_t),
641
        VMSTATE_UINT8(sect, fdrive_t),
639
        VMSTATE_UINT8(head, a_fdrive),
640
        VMSTATE_UINT8(track, a_fdrive),
641
        VMSTATE_UINT8(sect, a_fdrive),
642 642
        VMSTATE_END_OF_LIST()
643 643
    }
644 644
};
645 645

  
646 646
static void fdc_pre_save(const void *opaque)
647 647
{
648
    fdctrl_t *s = (void *)opaque;
648
    a_fdctrl *s = (void *)opaque;
649 649

  
650 650
    s->dor_vmstate = s->dor | GET_CUR_DRV(s);
651 651
}
652 652

  
653 653
static int fdc_post_load(void *opaque)
654 654
{
655
    fdctrl_t *s = opaque;
655
    a_fdctrl *s = opaque;
656 656

  
657 657
    SET_CUR_DRV(s, s->dor_vmstate & FD_DOR_SELMASK);
658 658
    s->dor = s->dor_vmstate & ~FD_DOR_SELMASK;
......
668 668
    .post_load = fdc_post_load,
669 669
    .fields      = (VMStateField []) {
670 670
        /* Controller State */
671
        VMSTATE_UINT8(sra, fdctrl_t),
672
        VMSTATE_UINT8(srb, fdctrl_t),
673
        VMSTATE_UINT8(dor_vmstate, fdctrl_t),
674
        VMSTATE_UINT8(tdr, fdctrl_t),
675
        VMSTATE_UINT8(dsr, fdctrl_t),
676
        VMSTATE_UINT8(msr, fdctrl_t),
677
        VMSTATE_UINT8(status0, fdctrl_t),
678
        VMSTATE_UINT8(status1, fdctrl_t),
679
        VMSTATE_UINT8(status2, fdctrl_t),
671
        VMSTATE_UINT8(sra, a_fdctrl),
672
        VMSTATE_UINT8(srb, a_fdctrl),
673
        VMSTATE_UINT8(dor_vmstate, a_fdctrl),
674
        VMSTATE_UINT8(tdr, a_fdctrl),
675
        VMSTATE_UINT8(dsr, a_fdctrl),
676
        VMSTATE_UINT8(msr, a_fdctrl),
677
        VMSTATE_UINT8(status0, a_fdctrl),
678
        VMSTATE_UINT8(status1, a_fdctrl),
679
        VMSTATE_UINT8(status2, a_fdctrl),
680 680
        /* Command FIFO */
681
        VMSTATE_VARRAY(fifo, fdctrl_t, fifo_size, 0, vmstate_info_uint8, uint8),
682
        VMSTATE_UINT32(data_pos, fdctrl_t),
683
        VMSTATE_UINT32(data_len, fdctrl_t),
684
        VMSTATE_UINT8(data_state, fdctrl_t),
685
        VMSTATE_UINT8(data_dir, fdctrl_t),
686
        VMSTATE_UINT8(eot, fdctrl_t),
681
        VMSTATE_VARRAY(fifo, a_fdctrl, fifo_size, 0, vmstate_info_uint8, uint8),
682
        VMSTATE_UINT32(data_pos, a_fdctrl),
683
        VMSTATE_UINT32(data_len, a_fdctrl),
684
        VMSTATE_UINT8(data_state, a_fdctrl),
685
        VMSTATE_UINT8(data_dir, a_fdctrl),
686
        VMSTATE_UINT8(eot, a_fdctrl),
687 687
        /* States kept only to be returned back */
688
        VMSTATE_UINT8(timer0, fdctrl_t),
689
        VMSTATE_UINT8(timer1, fdctrl_t),
690
        VMSTATE_UINT8(precomp_trk, fdctrl_t),
691
        VMSTATE_UINT8(config, fdctrl_t),
692
        VMSTATE_UINT8(lock, fdctrl_t),
693
        VMSTATE_UINT8(pwrd, fdctrl_t),
694
        VMSTATE_UINT8_EQUAL(num_floppies, fdctrl_t),
695
        VMSTATE_STRUCT_ARRAY(drives, fdctrl_t, MAX_FD, 1,
696
                             vmstate_fdrive, fdrive_t),
688
        VMSTATE_UINT8(timer0, a_fdctrl),
689
        VMSTATE_UINT8(timer1, a_fdctrl),
690
        VMSTATE_UINT8(precomp_trk, a_fdctrl),
691
        VMSTATE_UINT8(config, a_fdctrl),
692
        VMSTATE_UINT8(lock, a_fdctrl),
693
        VMSTATE_UINT8(pwrd, a_fdctrl),
694
        VMSTATE_UINT8_EQUAL(num_floppies, a_fdctrl),
695
        VMSTATE_STRUCT_ARRAY(drives, a_fdctrl, MAX_FD, 1,
696
                             vmstate_fdrive, a_fdrive),
697 697
        VMSTATE_END_OF_LIST()
698 698
    }
699 699
};
700 700

  
701 701
static void fdctrl_external_reset(void *opaque)
702 702
{
703
    fdctrl_t *s = opaque;
703
    a_fdctrl *s = opaque;
704 704

  
705 705
    fdctrl_reset(s, 0);
706 706
}
707 707

  
708 708
static void fdctrl_handle_tc(void *opaque, int irq, int level)
709 709
{
710
    //fdctrl_t *s = opaque;
710
    //a_fdctrl *s = opaque;
711 711

  
712 712
    if (level) {
713 713
        // XXX
......
716 716
}
717 717

  
718 718
/* XXX: may change if moved to bdrv */
719
int fdctrl_get_drive_type(fdctrl_t *fdctrl, int drive_num)
719
int fdctrl_get_drive_type(a_fdctrl *fdctrl, int drive_num)
720 720
{
721 721
    return fdctrl->drives[drive_num].drive;
722 722
}
723 723

  
724 724
/* Change IRQ state */
725
static void fdctrl_reset_irq (fdctrl_t *fdctrl)
725
static void fdctrl_reset_irq (a_fdctrl *fdctrl)
726 726
{
727 727
    if (!(fdctrl->sra & FD_SRA_INTPEND))
728 728
        return;
......
731 731
    fdctrl->sra &= ~FD_SRA_INTPEND;
732 732
}
733 733

  
734
static void fdctrl_raise_irq (fdctrl_t *fdctrl, uint8_t status0)
734
static void fdctrl_raise_irq (a_fdctrl *fdctrl, uint8_t status0)
735 735
{
736 736
    /* Sparc mutation */
737 737
    if (fdctrl->sun4m && (fdctrl->msr & FD_MSR_CMDBUSY)) {
......
751 751
}
752 752

  
753 753
/* Reset controller */
754
static void fdctrl_reset (fdctrl_t *fdctrl, int do_irq)
754
static void fdctrl_reset (a_fdctrl *fdctrl, int do_irq)
755 755
{
756 756
    int i;
757 757

  
......
780 780
    }
781 781
}
782 782

  
783
static inline fdrive_t *drv0 (fdctrl_t *fdctrl)
783
static inline a_fdrive *drv0 (a_fdctrl *fdctrl)
784 784
{
785 785
    return &fdctrl->drives[(fdctrl->tdr & FD_TDR_BOOTSEL) >> 2];
786 786
}
787 787

  
788
static inline fdrive_t *drv1 (fdctrl_t *fdctrl)
788
static inline a_fdrive *drv1 (a_fdctrl *fdctrl)
789 789
{
790 790
    if ((fdctrl->tdr & FD_TDR_BOOTSEL) < (1 << 2))
791 791
        return &fdctrl->drives[1];
......
794 794
}
795 795

  
796 796
#if MAX_FD == 4
797
static inline fdrive_t *drv2 (fdctrl_t *fdctrl)
797
static inline a_fdrive *drv2 (a_fdctrl *fdctrl)
798 798
{
799 799
    if ((fdctrl->tdr & FD_TDR_BOOTSEL) < (2 << 2))
800 800
        return &fdctrl->drives[2];
......
802 802
        return &fdctrl->drives[1];
803 803
}
804 804

  
805
static inline fdrive_t *drv3 (fdctrl_t *fdctrl)
805
static inline a_fdrive *drv3 (a_fdctrl *fdctrl)
806 806
{
807 807
    if ((fdctrl->tdr & FD_TDR_BOOTSEL) < (3 << 2))
808 808
        return &fdctrl->drives[3];
......
811 811
}
812 812
#endif
813 813

  
814
static fdrive_t *get_cur_drv (fdctrl_t *fdctrl)
814
static a_fdrive *get_cur_drv (a_fdctrl *fdctrl)
815 815
{
816 816
    switch (fdctrl->cur_drv) {
817 817
        case 0: return drv0(fdctrl);
......
825 825
}
826 826

  
827 827
/* Status A register : 0x00 (read-only) */
828
static uint32_t fdctrl_read_statusA (fdctrl_t *fdctrl)
828
static uint32_t fdctrl_read_statusA (a_fdctrl *fdctrl)
829 829
{
830 830
    uint32_t retval = fdctrl->sra;
831 831

  
......
835 835
}
836 836

  
837 837
/* Status B register : 0x01 (read-only) */
838
static uint32_t fdctrl_read_statusB (fdctrl_t *fdctrl)
838
static uint32_t fdctrl_read_statusB (a_fdctrl *fdctrl)
839 839
{
840 840
    uint32_t retval = fdctrl->srb;
841 841

  
......
845 845
}
846 846

  
847 847
/* Digital output register : 0x02 */
848
static uint32_t fdctrl_read_dor (fdctrl_t *fdctrl)
848
static uint32_t fdctrl_read_dor (a_fdctrl *fdctrl)
849 849
{
850 850
    uint32_t retval = fdctrl->dor;
851 851

  
......
856 856
    return retval;
857 857
}
858 858

  
859
static void fdctrl_write_dor (fdctrl_t *fdctrl, uint32_t value)
859
static void fdctrl_write_dor (a_fdctrl *fdctrl, uint32_t value)
860 860
{
861 861
    FLOPPY_DPRINTF("digital output register set to 0x%02x\n", value);
862 862

  
......
895 895
}
896 896

  
897 897
/* Tape drive register : 0x03 */
898
static uint32_t fdctrl_read_tape (fdctrl_t *fdctrl)
898
static uint32_t fdctrl_read_tape (a_fdctrl *fdctrl)
899 899
{
900 900
    uint32_t retval = fdctrl->tdr;
901 901

  
......
904 904
    return retval;
905 905
}
906 906

  
907
static void fdctrl_write_tape (fdctrl_t *fdctrl, uint32_t value)
907
static void fdctrl_write_tape (a_fdctrl *fdctrl, uint32_t value)
908 908
{
909 909
    /* Reset mode */
910 910
    if (!(fdctrl->dor & FD_DOR_nRESET)) {
......
918 918
}
919 919

  
920 920
/* Main status register : 0x04 (read) */
921
static uint32_t fdctrl_read_main_status (fdctrl_t *fdctrl)
921
static uint32_t fdctrl_read_main_status (a_fdctrl *fdctrl)
922 922
{
923 923
    uint32_t retval = fdctrl->msr;
924 924

  
......
931 931
}
932 932

  
933 933
/* Data select rate register : 0x04 (write) */
934
static void fdctrl_write_rate (fdctrl_t *fdctrl, uint32_t value)
934
static void fdctrl_write_rate (a_fdctrl *fdctrl, uint32_t value)
935 935
{
936 936
    /* Reset mode */
937 937
    if (!(fdctrl->dor & FD_DOR_nRESET)) {
......
951 951
    fdctrl->dsr = value;
952 952
}
953 953

  
954
static int fdctrl_media_changed(fdrive_t *drv)
954
static int fdctrl_media_changed(a_fdrive *drv)
955 955
{
956 956
    int ret;
957 957

  
......
965 965
}
966 966

  
967 967
/* Digital input register : 0x07 (read-only) */
968
static uint32_t fdctrl_read_dir (fdctrl_t *fdctrl)
968
static uint32_t fdctrl_read_dir (a_fdctrl *fdctrl)
969 969
{
970 970
    uint32_t retval = 0;
971 971

  
......
984 984
}
985 985

  
986 986
/* FIFO state control */
987
static void fdctrl_reset_fifo (fdctrl_t *fdctrl)
987
static void fdctrl_reset_fifo (a_fdctrl *fdctrl)
988 988
{
989 989
    fdctrl->data_dir = FD_DIR_WRITE;
990 990
    fdctrl->data_pos = 0;
......
992 992
}
993 993

  
994 994
/* Set FIFO status for the host to read */
995
static void fdctrl_set_fifo (fdctrl_t *fdctrl, int fifo_len, int do_irq)
995
static void fdctrl_set_fifo (a_fdctrl *fdctrl, int fifo_len, int do_irq)
996 996
{
997 997
    fdctrl->data_dir = FD_DIR_READ;
998 998
    fdctrl->data_len = fifo_len;
......
1003 1003
}
1004 1004

  
1005 1005
/* Set an error: unimplemented/unknown command */
1006
static void fdctrl_unimplemented (fdctrl_t *fdctrl, int direction)
1006
static void fdctrl_unimplemented (a_fdctrl *fdctrl, int direction)
1007 1007
{
1008 1008
    FLOPPY_ERROR("unimplemented command 0x%02x\n", fdctrl->fifo[0]);
1009 1009
    fdctrl->fifo[0] = FD_SR0_INVCMD;
......
1011 1011
}
1012 1012

  
1013 1013
/* Seek to next sector */
1014
static int fdctrl_seek_to_next_sect (fdctrl_t *fdctrl, fdrive_t *cur_drv)
1014
static int fdctrl_seek_to_next_sect (a_fdctrl *fdctrl, a_fdrive *cur_drv)
1015 1015
{
1016 1016
    FLOPPY_DPRINTF("seek to next sector (%d %02x %02x => %d)\n",
1017 1017
                   cur_drv->head, cur_drv->track, cur_drv->sect,
......
1045 1045
}
1046 1046

  
1047 1047
/* Callback for transfer end (stop or abort) */
1048
static void fdctrl_stop_transfer (fdctrl_t *fdctrl, uint8_t status0,
1048
static void fdctrl_stop_transfer (a_fdctrl *fdctrl, uint8_t status0,
1049 1049
                                  uint8_t status1, uint8_t status2)
1050 1050
{
1051
    fdrive_t *cur_drv;
1051
    a_fdrive *cur_drv;
1052 1052

  
1053 1053
    cur_drv = get_cur_drv(fdctrl);
1054 1054
    FLOPPY_DPRINTF("transfer status: %02x %02x %02x (%02x)\n",
......
1071 1071
}
1072 1072

  
1073 1073
/* Prepare a data transfer (either DMA or FIFO) */
1074
static void fdctrl_start_transfer (fdctrl_t *fdctrl, int direction)
1074
static void fdctrl_start_transfer (a_fdctrl *fdctrl, int direction)
1075 1075
{
1076
    fdrive_t *cur_drv;
1076
    a_fdrive *cur_drv;
1077 1077
    uint8_t kh, kt, ks;
1078 1078
    int did_seek = 0;
1079 1079

  
......
1173 1173
}
1174 1174

  
1175 1175
/* Prepare a transfer of deleted data */
1176
static void fdctrl_start_transfer_del (fdctrl_t *fdctrl, int direction)
1176
static void fdctrl_start_transfer_del (a_fdctrl *fdctrl, int direction)
1177 1177
{
1178 1178
    FLOPPY_ERROR("fdctrl_start_transfer_del() unimplemented\n");
1179 1179

  
......
1187 1187
static int fdctrl_transfer_handler (void *opaque, int nchan,
1188 1188
                                    int dma_pos, int dma_len)
1189 1189
{
1190
    fdctrl_t *fdctrl;
1191
    fdrive_t *cur_drv;
1190
    a_fdctrl *fdctrl;
1191
    a_fdrive *cur_drv;
1192 1192
    int len, start_pos, rel_pos;
1193 1193
    uint8_t status0 = 0x00, status1 = 0x00, status2 = 0x00;
1194 1194

  
......
1294 1294
}
1295 1295

  
1296 1296
/* Data register : 0x05 */
1297
static uint32_t fdctrl_read_data (fdctrl_t *fdctrl)
1297
static uint32_t fdctrl_read_data (a_fdctrl *fdctrl)
1298 1298
{
1299
    fdrive_t *cur_drv;
1299
    a_fdrive *cur_drv;
1300 1300
    uint32_t retval = 0;
1301 1301
    int pos;
1302 1302

  
......
1342 1342
    return retval;
1343 1343
}
1344 1344

  
1345
static void fdctrl_format_sector (fdctrl_t *fdctrl)
1345
static void fdctrl_format_sector (a_fdctrl *fdctrl)
1346 1346
{
1347
    fdrive_t *cur_drv;
1347
    a_fdrive *cur_drv;
1348 1348
    uint8_t kh, kt, ks;
1349 1349

  
1350 1350
    SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
......
1404 1404
    }
1405 1405
}
1406 1406

  
1407
static void fdctrl_handle_lock (fdctrl_t *fdctrl, int direction)
1407
static void fdctrl_handle_lock (a_fdctrl *fdctrl, int direction)
1408 1408
{
1409 1409
    fdctrl->lock = (fdctrl->fifo[0] & 0x80) ? 1 : 0;
1410 1410
    fdctrl->fifo[0] = fdctrl->lock << 4;
1411 1411
    fdctrl_set_fifo(fdctrl, 1, fdctrl->lock);
1412 1412
}
1413 1413

  
1414
static void fdctrl_handle_dumpreg (fdctrl_t *fdctrl, int direction)
1414
static void fdctrl_handle_dumpreg (a_fdctrl *fdctrl, int direction)
1415 1415
{
1416
    fdrive_t *cur_drv = get_cur_drv(fdctrl);
1416
    a_fdrive *cur_drv = get_cur_drv(fdctrl);
1417 1417

  
1418 1418
    /* Drives position */
1419 1419
    fdctrl->fifo[0] = drv0(fdctrl)->track;
......
1436 1436
    fdctrl_set_fifo(fdctrl, 10, 0);
1437 1437
}
1438 1438

  
1439
static void fdctrl_handle_version (fdctrl_t *fdctrl, int direction)
1439
static void fdctrl_handle_version (a_fdctrl *fdctrl, int direction)
1440 1440
{
1441 1441
    /* Controller's version */
1442 1442
    fdctrl->fifo[0] = fdctrl->version;
1443 1443
    fdctrl_set_fifo(fdctrl, 1, 1);
1444 1444
}
1445 1445

  
1446
static void fdctrl_handle_partid (fdctrl_t *fdctrl, int direction)
1446
static void fdctrl_handle_partid (a_fdctrl *fdctrl, int direction)
1447 1447
{
1448 1448
    fdctrl->fifo[0] = 0x41; /* Stepping 1 */
1449 1449
    fdctrl_set_fifo(fdctrl, 1, 0);
1450 1450
}
1451 1451

  
1452
static void fdctrl_handle_restore (fdctrl_t *fdctrl, int direction)
1452
static void fdctrl_handle_restore (a_fdctrl *fdctrl, int direction)
1453 1453
{
1454
    fdrive_t *cur_drv = get_cur_drv(fdctrl);
1454
    a_fdrive *cur_drv = get_cur_drv(fdctrl);
1455 1455

  
1456 1456
    /* Drives position */
1457 1457
    drv0(fdctrl)->track = fdctrl->fifo[3];
......
1472 1472
    fdctrl_reset_fifo(fdctrl);
1473 1473
}
1474 1474

  
1475
static void fdctrl_handle_save (fdctrl_t *fdctrl, int direction)
1475
static void fdctrl_handle_save (a_fdctrl *fdctrl, int direction)
1476 1476
{
1477
    fdrive_t *cur_drv = get_cur_drv(fdctrl);
1477
    a_fdrive *cur_drv = get_cur_drv(fdctrl);
1478 1478

  
1479 1479
    fdctrl->fifo[0] = 0;
1480 1480
    fdctrl->fifo[1] = 0;
......
1502 1502
    fdctrl_set_fifo(fdctrl, 15, 1);
1503 1503
}
1504 1504

  
1505
static void fdctrl_handle_readid (fdctrl_t *fdctrl, int direction)
1505
static void fdctrl_handle_readid (a_fdctrl *fdctrl, int direction)
1506 1506
{
1507
    fdrive_t *cur_drv = get_cur_drv(fdctrl);
1507
    a_fdrive *cur_drv = get_cur_drv(fdctrl);
1508 1508

  
1509 1509
    /* XXX: should set main status register to busy */
1510 1510
    cur_drv->head = (fdctrl->fifo[1] >> 2) & 1;
......
1512 1512
                   qemu_get_clock(vm_clock) + (get_ticks_per_sec() / 50));
1513 1513
}
1514 1514

  
1515
static void fdctrl_handle_format_track (fdctrl_t *fdctrl, int direction)
1515
static void fdctrl_handle_format_track (a_fdctrl *fdctrl, int direction)
1516 1516
{
1517
    fdrive_t *cur_drv;
1517
    a_fdrive *cur_drv;
1518 1518

  
1519 1519
    SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
1520 1520
    cur_drv = get_cur_drv(fdctrl);
......
1541 1541
    fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00);
1542 1542
}
1543 1543

  
1544
static void fdctrl_handle_specify (fdctrl_t *fdctrl, int direction)
1544
static void fdctrl_handle_specify (a_fdctrl *fdctrl, int direction)
1545 1545
{
1546 1546
    fdctrl->timer0 = (fdctrl->fifo[1] >> 4) & 0xF;
1547 1547
    fdctrl->timer1 = fdctrl->fifo[2] >> 1;
......
1553 1553
    fdctrl_reset_fifo(fdctrl);
1554 1554
}
1555 1555

  
1556
static void fdctrl_handle_sense_drive_status (fdctrl_t *fdctrl, int direction)
1556
static void fdctrl_handle_sense_drive_status (a_fdctrl *fdctrl, int direction)
1557 1557
{
1558
    fdrive_t *cur_drv;
1558
    a_fdrive *cur_drv;
1559 1559

  
1560 1560
    SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
1561 1561
    cur_drv = get_cur_drv(fdctrl);
......
1569 1569
    fdctrl_set_fifo(fdctrl, 1, 0);
1570 1570
}
1571 1571

  
1572
static void fdctrl_handle_recalibrate (fdctrl_t *fdctrl, int direction)
1572
static void fdctrl_handle_recalibrate (a_fdctrl *fdctrl, int direction)
1573 1573
{
1574
    fdrive_t *cur_drv;
1574
    a_fdrive *cur_drv;
1575 1575

  
1576 1576
    SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
1577 1577
    cur_drv = get_cur_drv(fdctrl);
......
1581 1581
    fdctrl_raise_irq(fdctrl, FD_SR0_SEEK);
1582 1582
}
1583 1583

  
1584
static void fdctrl_handle_sense_interrupt_status (fdctrl_t *fdctrl, int direction)
1584
static void fdctrl_handle_sense_interrupt_status (a_fdctrl *fdctrl, int direction)
1585 1585
{
1586
    fdrive_t *cur_drv = get_cur_drv(fdctrl);
1586
    a_fdrive *cur_drv = get_cur_drv(fdctrl);
1587 1587

  
1588 1588
    if(fdctrl->reset_sensei > 0) {
1589 1589
        fdctrl->fifo[0] =
......
1603 1603
    fdctrl->status0 = FD_SR0_RDYCHG;
1604 1604
}
1605 1605

  
1606
static void fdctrl_handle_seek (fdctrl_t *fdctrl, int direction)
1606
static void fdctrl_handle_seek (a_fdctrl *fdctrl, int direction)
1607 1607
{
1608
    fdrive_t *cur_drv;
1608
    a_fdrive *cur_drv;
1609 1609

  
1610 1610
    SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
1611 1611
    cur_drv = get_cur_drv(fdctrl);
......
1619 1619
    }
1620 1620
}
1621 1621

  
1622
static void fdctrl_handle_perpendicular_mode (fdctrl_t *fdctrl, int direction)
1622
static void fdctrl_handle_perpendicular_mode (a_fdctrl *fdctrl, int direction)
1623 1623
{
1624
    fdrive_t *cur_drv = get_cur_drv(fdctrl);
1624
    a_fdrive *cur_drv = get_cur_drv(fdctrl);
1625 1625

  
1626 1626
    if (fdctrl->fifo[1] & 0x80)
1627 1627
        cur_drv->perpendicular = fdctrl->fifo[1] & 0x7;
......
1629 1629
    fdctrl_reset_fifo(fdctrl);
1630 1630
}
1631 1631

  
1632
static void fdctrl_handle_configure (fdctrl_t *fdctrl, int direction)
1632
static void fdctrl_handle_configure (a_fdctrl *fdctrl, int direction)
1633 1633
{
1634 1634
    fdctrl->config = fdctrl->fifo[2];
1635 1635
    fdctrl->precomp_trk =  fdctrl->fifo[3];
......
1637 1637
    fdctrl_reset_fifo(fdctrl);
1638 1638
}
1639 1639

  
1640
static void fdctrl_handle_powerdown_mode (fdctrl_t *fdctrl, int direction)
1640
static void fdctrl_handle_powerdown_mode (a_fdctrl *fdctrl, int direction)
1641 1641
{
1642 1642
    fdctrl->pwrd = fdctrl->fifo[1];
1643 1643
    fdctrl->fifo[0] = fdctrl->fifo[1];
1644 1644
    fdctrl_set_fifo(fdctrl, 1, 1);
1645 1645
}
1646 1646

  
1647
static void fdctrl_handle_option (fdctrl_t *fdctrl, int direction)
1647
static void fdctrl_handle_option (a_fdctrl *fdctrl, int direction)
1648 1648
{
1649 1649
    /* No result back */
1650 1650
    fdctrl_reset_fifo(fdctrl);
1651 1651
}
1652 1652

  
1653
static void fdctrl_handle_drive_specification_command (fdctrl_t *fdctrl, int direction)
1653
static void fdctrl_handle_drive_specification_command (a_fdctrl *fdctrl, int direction)
1654 1654
{
1655
    fdrive_t *cur_drv = get_cur_drv(fdctrl);
1655
    a_fdrive *cur_drv = get_cur_drv(fdctrl);
1656 1656

  
1657 1657
    if (fdctrl->fifo[fdctrl->data_pos - 1] & 0x80) {
1658 1658
        /* Command parameters done */
......
1672 1672
    }
1673 1673
}
1674 1674

  
1675
static void fdctrl_handle_relative_seek_out (fdctrl_t *fdctrl, int direction)
1675
static void fdctrl_handle_relative_seek_out (a_fdctrl *fdctrl, int direction)
1676 1676
{
1677
    fdrive_t *cur_drv;
1677
    a_fdrive *cur_drv;
1678 1678

  
1679 1679
    SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
1680 1680
    cur_drv = get_cur_drv(fdctrl);
......
1688 1688
    fdctrl_raise_irq(fdctrl, FD_SR0_SEEK);
1689 1689
}
1690 1690

  
1691
static void fdctrl_handle_relative_seek_in (fdctrl_t *fdctrl, int direction)
1691
static void fdctrl_handle_relative_seek_in (a_fdctrl *fdctrl, int direction)
1692 1692
{
1693
    fdrive_t *cur_drv;
1693
    a_fdrive *cur_drv;
1694 1694

  
1695 1695
    SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
1696 1696
    cur_drv = get_cur_drv(fdctrl);
......
1709 1709
    uint8_t mask;
1710 1710
    const char* name;
1711 1711
    int parameters;
1712
    void (*handler)(fdctrl_t *fdctrl, int direction);
1712
    void (*handler)(a_fdctrl *fdctrl, int direction);
1713 1713
    int direction;
1714 1714
} handlers[] = {
1715 1715
    { FD_CMD_READ, 0x1f, "READ", 8, fdctrl_start_transfer, FD_DIR_READ },
......
1748 1748
/* Associate command to an index in the 'handlers' array */
1749 1749
static uint8_t command_to_handler[256];
1750 1750

  
1751
static void fdctrl_write_data (fdctrl_t *fdctrl, uint32_t value)
1751
static void fdctrl_write_data (a_fdctrl *fdctrl, uint32_t value)
1752 1752
{
1753
    fdrive_t *cur_drv;
1753
    a_fdrive *cur_drv;
1754 1754
    int pos;
1755 1755

  
1756 1756
    /* Reset mode */
......
1815 1815

  
1816 1816
static void fdctrl_result_timer(void *opaque)
1817 1817
{
1818
    fdctrl_t *fdctrl = opaque;
1819
    fdrive_t *cur_drv = get_cur_drv(fdctrl);
1818
    a_fdctrl *fdctrl = opaque;
1819
    a_fdrive *cur_drv = get_cur_drv(fdctrl);
1820 1820

  
1821 1821
    /* Pretend we are spinning.
1822 1822
     * This is needed for Coherent, which uses READ ID to check for
......
1829 1829
}
1830 1830

  
1831 1831
/* Init functions */
1832
static void fdctrl_connect_drives(fdctrl_t *fdctrl, BlockDriverState **fds)
1832
static void fdctrl_connect_drives(a_fdctrl *fdctrl, BlockDriverState **fds)
1833 1833
{
1834 1834
    unsigned int i;
1835 1835

  
......
1839 1839
    }
1840 1840
}
1841 1841

  
1842
fdctrl_t *fdctrl_init_isa(BlockDriverState **fds)
1842
a_fdctrl *fdctrl_init_isa(BlockDriverState **fds)
1843 1843
{
1844
    fdctrl_t *fdctrl;
1844
    a_fdctrl *fdctrl;
1845 1845
    ISADevice *dev;
1846 1846
    int dma_chann = 2;
1847 1847

  
1848 1848
    dev = isa_create_simple("isa-fdc");
1849
    fdctrl = &(DO_UPCAST(fdctrl_isabus_t, busdev, dev)->state);
1849
    fdctrl = &(DO_UPCAST(a_fdctrl_isabus, busdev, dev)->state);
1850 1850

  
1851 1851
    fdctrl->dma_chann = dma_chann;
1852 1852
    DMA_register_channel(dma_chann, &fdctrl_transfer_handler, fdctrl);
......
1856 1856
    return fdctrl;
1857 1857
}
1858 1858

  
1859
fdctrl_t *fdctrl_init_sysbus(qemu_irq irq, int dma_chann,
1860
                             target_phys_addr_t mmio_base,
1859
a_fdctrl *fdctrl_init_sysbus(qemu_irq irq, int dma_chann,
1860
                             a_target_phys_addr mmio_base,
1861 1861
                             BlockDriverState **fds)
1862 1862
{
1863
    fdctrl_t *fdctrl;
1863
    a_fdctrl *fdctrl;
1864 1864
    DeviceState *dev;
1865
    fdctrl_sysbus_t *sys;
1865
    a_fdctrl_sysbus *sys;
1866 1866

  
1867 1867
    dev = qdev_create(NULL, "sysbus-fdc");
1868 1868
    qdev_init(dev);
1869
    sys = DO_UPCAST(fdctrl_sysbus_t, busdev.qdev, dev);
1869
    sys = DO_UPCAST(a_fdctrl_sysbus, busdev.qdev, dev);
1870 1870
    fdctrl = &sys->state;
1871 1871
    sysbus_connect_irq(&sys->busdev, 0, irq);
1872 1872
    sysbus_mmio_map(&sys->busdev, 0, mmio_base);
......
1878 1878
    return fdctrl;
1879 1879
}
1880 1880

  
1881
fdctrl_t *sun4m_fdctrl_init (qemu_irq irq, target_phys_addr_t io_base,
1881
a_fdctrl *sun4m_fdctrl_init (qemu_irq irq, a_target_phys_addr io_base,
1882 1882
                             BlockDriverState **fds, qemu_irq *fdc_tc)
1883 1883
{
1884 1884
    DeviceState *dev;
1885
    fdctrl_sysbus_t *sys;
1886
    fdctrl_t *fdctrl;
1885
    a_fdctrl_sysbus *sys;
1886
    a_fdctrl *fdctrl;
1887 1887

  
1888 1888
    dev = qdev_create(NULL, "SUNW,fdtwo");
1889 1889
    qdev_init(dev);
1890
    sys = DO_UPCAST(fdctrl_sysbus_t, busdev.qdev, dev);
1890
    sys = DO_UPCAST(a_fdctrl_sysbus, busdev.qdev, dev);
1891 1891
    fdctrl = &sys->state;
1892 1892
    sysbus_connect_irq(&sys->busdev, 0, irq);
1893 1893
    sysbus_mmio_map(&sys->busdev, 0, io_base);
......
1900 1900
    return fdctrl;
1901 1901
}
1902 1902

  
1903
static int fdctrl_init_common(fdctrl_t *fdctrl)
1903
static int fdctrl_init_common(a_fdctrl *fdctrl)
1904 1904
{
1905 1905
    int i, j;
1906 1906
    static int command_tables_inited = 0;
......
1935 1935

  
1936 1936
static int isabus_fdc_init1(ISADevice *dev)
1937 1937
{
1938
    fdctrl_isabus_t *isa = DO_UPCAST(fdctrl_isabus_t, busdev, dev);
1939
    fdctrl_t *fdctrl = &isa->state;
1938
    a_fdctrl_isabus *isa = DO_UPCAST(a_fdctrl_isabus, busdev, dev);
1939
    a_fdctrl *fdctrl = &isa->state;
1940 1940
    int iobase = 0x3f0;
1941 1941
    int isairq = 6;
1942 1942

  
......
1955 1955

  
1956 1956
static int sysbus_fdc_init1(SysBusDevice *dev)
1957 1957
{
1958
    fdctrl_t *fdctrl = &(FROM_SYSBUS(fdctrl_sysbus_t, dev)->state);
1958
    a_fdctrl *fdctrl = &(FROM_SYSBUS(a_fdctrl_sysbus, dev)->state);
1959 1959
    int io;
1960 1960

  
1961 1961
    io = cpu_register_io_memory(fdctrl_mem_read, fdctrl_mem_write, fdctrl);
......
1968 1968

  
1969 1969
static int sun4m_fdc_init1(SysBusDevice *dev)
1970 1970
{
1971
    fdctrl_t *fdctrl = &(FROM_SYSBUS(fdctrl_sysbus_t, dev)->state);
1971
    a_fdctrl *fdctrl = &(FROM_SYSBUS(a_fdctrl_sysbus, dev)->state);
1972 1972
    int io;
1973 1973

  
1974 1974
    io = cpu_register_io_memory(fdctrl_mem_read_strict,
......
1984 1984
static ISADeviceInfo isa_fdc_info = {
1985 1985
    .init = isabus_fdc_init1,
1986 1986
    .qdev.name  = "isa-fdc",
1987
    .qdev.size  = sizeof(fdctrl_isabus_t),
1987
    .qdev.size  = sizeof(a_fdctrl_isabus),
1988 1988
};
1989 1989

  
1990 1990
static SysBusDeviceInfo sysbus_fdc_info = {
1991 1991
    .init = sysbus_fdc_init1,
1992 1992
    .qdev.name  = "sysbus-fdc",
1993
    .qdev.size  = sizeof(fdctrl_sysbus_t),
1993
    .qdev.size  = sizeof(a_fdctrl_sysbus),
1994 1994
};
1995 1995

  
1996 1996
static SysBusDeviceInfo sun4m_fdc_info = {
1997 1997
    .init = sun4m_fdc_init1,
1998 1998
    .qdev.name  = "SUNW,fdtwo",
1999
    .qdev.size  = sizeof(fdctrl_sysbus_t),
1999
    .qdev.size  = sizeof(a_fdctrl_sysbus),
2000 2000
};
2001 2001

  
2002 2002
static void fdc_register_devices(void)

Also available in: Unified diff