2004-01-05 00:09:06 +00:00
|
|
|
/*
|
2004-10-07 23:10:29 +00:00
|
|
|
* QEMU Floppy disk emulator (Intel 82078)
|
2007-09-16 21:08:06 +00:00
|
|
|
*
|
2007-04-14 13:01:31 +00:00
|
|
|
* Copyright (c) 2003, 2007 Jocelyn Mayer
|
2011-12-02 09:30:41 +00:00
|
|
|
* Copyright (c) 2008 Hervé Poussineau
|
2007-09-16 21:08:06 +00:00
|
|
|
*
|
2004-01-05 00:09:06 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2004-12-19 23:18:01 +00:00
|
|
|
/*
|
|
|
|
* The controller is used in Sun4m systems in a slightly different
|
|
|
|
* way. There are changes in DOR register and DMA is not available.
|
|
|
|
*/
|
2009-07-15 14:41:54 +00:00
|
|
|
|
2016-01-18 18:01:42 +00:00
|
|
|
#include "qemu/osdep.h"
|
2013-02-05 16:06:20 +00:00
|
|
|
#include "hw/block/fdc.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 08:01:28 +00:00
|
|
|
#include "qapi/error.h"
|
2012-12-17 17:20:00 +00:00
|
|
|
#include "qemu/error-report.h"
|
|
|
|
#include "qemu/timer.h"
|
2019-08-12 05:23:42 +00:00
|
|
|
#include "hw/irq.h"
|
2013-02-05 16:06:20 +00:00
|
|
|
#include "hw/isa/isa.h"
|
2019-08-12 05:23:51 +00:00
|
|
|
#include "hw/qdev-properties.h"
|
2020-12-11 22:05:12 +00:00
|
|
|
#include "hw/qdev-properties-system.h"
|
2019-08-12 05:23:45 +00:00
|
|
|
#include "migration/vmstate.h"
|
2016-10-27 20:29:13 +00:00
|
|
|
#include "hw/block/block.h"
|
2014-10-07 11:59:13 +00:00
|
|
|
#include "sysemu/block-backend.h"
|
2012-12-17 17:20:04 +00:00
|
|
|
#include "sysemu/blockdev.h"
|
|
|
|
#include "sysemu/sysemu.h"
|
2012-12-17 17:20:00 +00:00
|
|
|
#include "qemu/log.h"
|
Include qemu/main-loop.h less
In my "build everything" tree, changing qemu/main-loop.h triggers a
recompile of some 5600 out of 6600 objects (not counting tests and
objects that don't depend on qemu/osdep.h). It includes block/aio.h,
which in turn includes qemu/event_notifier.h, qemu/notify.h,
qemu/processor.h, qemu/qsp.h, qemu/queue.h, qemu/thread-posix.h,
qemu/thread.h, qemu/timer.h, and a few more.
Include qemu/main-loop.h only where it's needed. Touching it now
recompiles only some 1700 objects. For block/aio.h and
qemu/event_notifier.h, these numbers drop from 5600 to 2800. For the
others, they shrink only slightly.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20190812052359.30071-21-armbru@redhat.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
2019-08-12 05:23:50 +00:00
|
|
|
#include "qemu/main-loop.h"
|
2019-05-23 14:35:07 +00:00
|
|
|
#include "qemu/module.h"
|
2018-06-21 17:12:56 +00:00
|
|
|
#include "trace.h"
|
2020-09-03 20:43:22 +00:00
|
|
|
#include "qom/object.h"
|
2021-06-14 19:32:17 +00:00
|
|
|
#include "fdc-internal.h"
|
2004-01-05 00:09:06 +00:00
|
|
|
|
|
|
|
/********************************************************/
|
|
|
|
/* debug Floppy devices */
|
|
|
|
|
2016-02-10 18:29:40 +00:00
|
|
|
#define DEBUG_FLOPPY 0
|
|
|
|
|
2009-05-13 17:53:17 +00:00
|
|
|
#define FLOPPY_DPRINTF(fmt, ...) \
|
2016-02-10 18:29:40 +00:00
|
|
|
do { \
|
|
|
|
if (DEBUG_FLOPPY) { \
|
|
|
|
fprintf(stderr, "FLOPPY: " fmt , ## __VA_ARGS__); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2004-01-05 00:09:06 +00:00
|
|
|
|
2016-10-27 20:29:13 +00:00
|
|
|
|
2021-11-24 16:15:34 +00:00
|
|
|
/* Anonymous BlockBackend for empty drive */
|
|
|
|
static BlockBackend *blk_create_empty_drive(void)
|
|
|
|
{
|
|
|
|
return blk_new(qemu_get_aio_context(), 0, BLK_PERM_ALL);
|
|
|
|
}
|
|
|
|
|
2016-10-27 20:29:13 +00:00
|
|
|
/********************************************************/
|
|
|
|
/* qdev floppy bus */
|
|
|
|
|
|
|
|
#define TYPE_FLOPPY_BUS "floppy-bus"
|
2020-09-16 18:25:19 +00:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(FloppyBus, FLOPPY_BUS)
|
2016-10-27 20:29:13 +00:00
|
|
|
|
2016-10-27 20:29:13 +00:00
|
|
|
static FDrive *get_drv(FDCtrl *fdctrl, int unit);
|
2016-10-27 20:29:13 +00:00
|
|
|
|
|
|
|
static const TypeInfo floppy_bus_info = {
|
|
|
|
.name = TYPE_FLOPPY_BUS,
|
|
|
|
.parent = TYPE_BUS,
|
|
|
|
.instance_size = sizeof(FloppyBus),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void floppy_bus_create(FDCtrl *fdc, FloppyBus *bus, DeviceState *dev)
|
|
|
|
{
|
2021-09-23 12:11:51 +00:00
|
|
|
qbus_init(bus, sizeof(FloppyBus), TYPE_FLOPPY_BUS, dev, NULL);
|
2016-10-27 20:29:13 +00:00
|
|
|
bus->fdc = fdc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-05 00:09:06 +00:00
|
|
|
/********************************************************/
|
|
|
|
/* Floppy drive emulation */
|
|
|
|
|
2016-01-22 20:51:02 +00:00
|
|
|
/* In many cases, the total sector size of a format is enough to uniquely
|
|
|
|
* identify it. However, there are some total sector collisions between
|
|
|
|
* formats of different physical size, and these are noted below by
|
|
|
|
* highlighting the total sector size for entries with collisions. */
|
2021-06-14 19:32:17 +00:00
|
|
|
const FDFormat fd_formats[] = {
|
2012-07-10 09:12:27 +00:00
|
|
|
/* First entry is default format */
|
|
|
|
/* 1.44 MB 3"1/2 floppy disks */
|
2016-01-22 20:51:02 +00:00
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 18, 80, 1, FDRIVE_RATE_500K, }, /* 3.5" 2880 */
|
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 20, 80, 1, FDRIVE_RATE_500K, }, /* 3.5" 3200 */
|
2016-01-22 20:50:56 +00:00
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 21, 80, 1, FDRIVE_RATE_500K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 21, 82, 1, FDRIVE_RATE_500K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 21, 83, 1, FDRIVE_RATE_500K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 22, 80, 1, FDRIVE_RATE_500K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 23, 80, 1, FDRIVE_RATE_500K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 24, 80, 1, FDRIVE_RATE_500K, },
|
2012-07-10 09:12:27 +00:00
|
|
|
/* 2.88 MB 3"1/2 floppy disks */
|
2016-01-22 20:50:56 +00:00
|
|
|
{ FLOPPY_DRIVE_TYPE_288, 36, 80, 1, FDRIVE_RATE_1M, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_288, 39, 80, 1, FDRIVE_RATE_1M, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_288, 40, 80, 1, FDRIVE_RATE_1M, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_288, 44, 80, 1, FDRIVE_RATE_1M, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_288, 48, 80, 1, FDRIVE_RATE_1M, },
|
2012-07-10 09:12:27 +00:00
|
|
|
/* 720 kB 3"1/2 floppy disks */
|
2016-01-22 20:51:02 +00:00
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 9, 80, 1, FDRIVE_RATE_250K, }, /* 3.5" 1440 */
|
2016-01-22 20:50:56 +00:00
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 10, 80, 1, FDRIVE_RATE_250K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 10, 82, 1, FDRIVE_RATE_250K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 10, 83, 1, FDRIVE_RATE_250K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 13, 80, 1, FDRIVE_RATE_250K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 14, 80, 1, FDRIVE_RATE_250K, },
|
2012-07-10 09:12:27 +00:00
|
|
|
/* 1.2 MB 5"1/4 floppy disks */
|
2016-01-22 20:50:56 +00:00
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 15, 80, 1, FDRIVE_RATE_500K, },
|
2016-01-22 20:51:02 +00:00
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 18, 80, 1, FDRIVE_RATE_500K, }, /* 5.25" 2880 */
|
2016-01-22 20:50:56 +00:00
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 18, 82, 1, FDRIVE_RATE_500K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 18, 83, 1, FDRIVE_RATE_500K, },
|
2016-01-22 20:51:02 +00:00
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 20, 80, 1, FDRIVE_RATE_500K, }, /* 5.25" 3200 */
|
2012-07-10 09:12:27 +00:00
|
|
|
/* 720 kB 5"1/4 floppy disks */
|
2016-01-22 20:51:02 +00:00
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 9, 80, 1, FDRIVE_RATE_250K, }, /* 5.25" 1440 */
|
2016-01-22 20:50:56 +00:00
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 11, 80, 1, FDRIVE_RATE_250K, },
|
2012-07-10 09:12:27 +00:00
|
|
|
/* 360 kB 5"1/4 floppy disks */
|
2016-01-22 20:51:02 +00:00
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 9, 40, 1, FDRIVE_RATE_300K, }, /* 5.25" 720 */
|
2016-01-22 20:50:56 +00:00
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 9, 40, 0, FDRIVE_RATE_300K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 10, 41, 1, FDRIVE_RATE_300K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 10, 42, 1, FDRIVE_RATE_300K, },
|
2012-07-10 09:12:27 +00:00
|
|
|
/* 320 kB 5"1/4 floppy disks */
|
2016-01-22 20:50:56 +00:00
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 8, 40, 1, FDRIVE_RATE_250K, },
|
|
|
|
{ FLOPPY_DRIVE_TYPE_120, 8, 40, 0, FDRIVE_RATE_250K, },
|
2012-07-10 09:12:27 +00:00
|
|
|
/* 360 kB must match 5"1/4 better than 3"1/2... */
|
2016-01-22 20:51:02 +00:00
|
|
|
{ FLOPPY_DRIVE_TYPE_144, 9, 80, 0, FDRIVE_RATE_250K, }, /* 3.5" 720 */
|
2012-07-10 09:12:27 +00:00
|
|
|
/* end */
|
2016-01-22 20:50:56 +00:00
|
|
|
{ FLOPPY_DRIVE_TYPE_NONE, -1, -1, 0, 0, },
|
2012-07-10 09:12:27 +00:00
|
|
|
};
|
|
|
|
|
2016-01-22 20:51:02 +00:00
|
|
|
static FDriveSize drive_size(FloppyDriveType drive)
|
|
|
|
{
|
|
|
|
switch (drive) {
|
|
|
|
case FLOPPY_DRIVE_TYPE_120:
|
|
|
|
return FDRIVE_SIZE_525;
|
|
|
|
case FLOPPY_DRIVE_TYPE_144:
|
|
|
|
case FLOPPY_DRIVE_TYPE_288:
|
|
|
|
return FDRIVE_SIZE_350;
|
|
|
|
default:
|
|
|
|
return FDRIVE_SIZE_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-29 16:18:58 +00:00
|
|
|
#define GET_CUR_DRV(fdctrl) ((fdctrl)->cur_drv)
|
|
|
|
#define SET_CUR_DRV(fdctrl, drive) ((fdctrl)->cur_drv = (drive))
|
|
|
|
|
2004-01-05 00:09:06 +00:00
|
|
|
/* Will always be a fixed parameter for us */
|
2009-01-24 12:09:52 +00:00
|
|
|
#define FD_SECTOR_LEN 512
|
|
|
|
#define FD_SECTOR_SC 2 /* Sector size code */
|
|
|
|
#define FD_RESET_SENSEI_COUNT 4 /* Number of sense interrupts on RESET */
|
2004-01-05 00:09:06 +00:00
|
|
|
|
2016-01-22 20:51:00 +00:00
|
|
|
|
|
|
|
static FloppyDriveType get_fallback_drive_type(FDrive *drv);
|
|
|
|
|
fdc: fix detection under Linux
Accidentally, I removed a "feature" where empty drives had geometry
values applied to them, which allows seek on empty drives to work
"by accident," as QEMU actually tries to disallow that.
Seeks on empty drives should work, though, but the easiest thing is to
restore the misfeature where empty drives have non-zero geometries
applied.
Document the hack accordingly.
[Maintainer edit]
This fix corrects a regression introduced in d5d47efc, where
pick_geometry was modified such that it would not operate on empty
drives, and as a result if there is no diskette inserted, QEMU
no longer populates it with geometry bounds. As a result, seek fails
when QEMU denies to move the current track, but reports success anyway.
This can confuse the guest, leading to kernel panics in the guest.
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1454106932-17236-1-git-send-email-jsnow@redhat.com
2016-02-03 16:28:55 +00:00
|
|
|
/* Hack: FD_SEEK is expected to work on empty drives. However, QEMU
|
|
|
|
* currently goes through some pains to keep seeks within the bounds
|
|
|
|
* established by last_sect and max_track. Correcting this is difficult,
|
|
|
|
* as refactoring FDC code tends to expose nasty bugs in the Linux kernel.
|
|
|
|
*
|
|
|
|
* For now: allow empty drives to have large bounds so we can seek around,
|
|
|
|
* with the understanding that when a diskette is inserted, the bounds will
|
|
|
|
* properly tighten to match the geometry of that inserted medium.
|
|
|
|
*/
|
|
|
|
static void fd_empty_seek_hack(FDrive *drv)
|
|
|
|
{
|
|
|
|
drv->last_sect = 0xFF;
|
|
|
|
drv->max_track = 0xFF;
|
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fd_init(FDrive *drv)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
|
|
|
/* Drive */
|
|
|
|
drv->perpendicular = 0;
|
|
|
|
/* Disk */
|
2016-01-22 20:50:57 +00:00
|
|
|
drv->disk = FLOPPY_DRIVE_TYPE_NONE;
|
2004-03-19 23:05:34 +00:00
|
|
|
drv->last_sect = 0;
|
2004-01-05 00:09:06 +00:00
|
|
|
drv->max_track = 0;
|
2016-01-22 20:50:59 +00:00
|
|
|
drv->ro = true;
|
|
|
|
drv->media_changed = 1;
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
|
2012-02-06 21:29:02 +00:00
|
|
|
#define NUM_SIDES(drv) ((drv)->flags & FDISK_DBL_SIDES ? 2 : 1)
|
|
|
|
|
2010-02-07 09:13:51 +00:00
|
|
|
static int fd_sector_calc(uint8_t head, uint8_t track, uint8_t sect,
|
2012-02-06 21:29:02 +00:00
|
|
|
uint8_t last_sect, uint8_t num_sides)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
2012-02-06 21:29:02 +00:00
|
|
|
return (((track * num_sides) + head) * last_sect) + sect - 1;
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns current position, in sectors, for given drive */
|
2010-02-07 09:01:18 +00:00
|
|
|
static int fd_sector(FDrive *drv)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
2012-02-06 21:29:02 +00:00
|
|
|
return fd_sector_calc(drv->head, drv->track, drv->sect, drv->last_sect,
|
|
|
|
NUM_SIDES(drv));
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-06 16:26:35 +00:00
|
|
|
/* Returns current position, in bytes, for given drive */
|
|
|
|
static int fd_offset(FDrive *drv)
|
|
|
|
{
|
|
|
|
g_assert(fd_sector(drv) < INT_MAX >> BDRV_SECTOR_BITS);
|
|
|
|
return fd_sector(drv) << BDRV_SECTOR_BITS;
|
|
|
|
}
|
|
|
|
|
2008-04-29 16:17:08 +00:00
|
|
|
/* Seek to a new position:
|
|
|
|
* returns 0 if already on right track
|
|
|
|
* returns 1 if track changed
|
|
|
|
* returns 2 if track is invalid
|
|
|
|
* returns 3 if sector is invalid
|
|
|
|
* returns 4 if seek is disabled
|
|
|
|
*/
|
2010-02-07 09:01:18 +00:00
|
|
|
static int fd_seek(FDrive *drv, uint8_t head, uint8_t track, uint8_t sect,
|
|
|
|
int enable_seek)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
|
|
|
uint32_t sector;
|
2004-03-19 23:05:34 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (track > drv->max_track ||
|
2007-11-05 03:11:37 +00:00
|
|
|
(head != 0 && (drv->flags & FDISK_DBL_SIDES) == 0)) {
|
2004-05-08 13:14:18 +00:00
|
|
|
FLOPPY_DPRINTF("try to read %d %02x %02x (max=%d %d %02x %02x)\n",
|
|
|
|
head, track, sect, 1,
|
|
|
|
(drv->flags & FDISK_DBL_SIDES) == 0 ? 0 : 1,
|
|
|
|
drv->max_track, drv->last_sect);
|
2004-01-05 00:09:06 +00:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
if (sect > drv->last_sect) {
|
2004-05-08 13:14:18 +00:00
|
|
|
FLOPPY_DPRINTF("try to read %d %02x %02x (max=%d %d %02x %02x)\n",
|
|
|
|
head, track, sect, 1,
|
|
|
|
(drv->flags & FDISK_DBL_SIDES) == 0 ? 0 : 1,
|
|
|
|
drv->max_track, drv->last_sect);
|
2004-01-05 00:09:06 +00:00
|
|
|
return 3;
|
|
|
|
}
|
2012-02-06 21:29:02 +00:00
|
|
|
sector = fd_sector_calc(head, track, sect, drv->last_sect, NUM_SIDES(drv));
|
2004-03-19 23:05:34 +00:00
|
|
|
ret = 0;
|
2004-01-05 00:09:06 +00:00
|
|
|
if (sector != fd_sector(drv)) {
|
|
|
|
#if 0
|
|
|
|
if (!enable_seek) {
|
2012-06-03 17:16:14 +00:00
|
|
|
FLOPPY_DPRINTF("error: no implicit seek %d %02x %02x"
|
|
|
|
" (max=%d %02x %02x)\n",
|
|
|
|
head, track, sect, 1, drv->max_track,
|
|
|
|
drv->last_sect);
|
2004-01-05 00:09:06 +00:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
drv->head = head;
|
2012-06-22 10:33:54 +00:00
|
|
|
if (drv->track != track) {
|
Revert "hw/block/fdc: Implement tray status"
This reverts the changes that commit
2e1280e8ff95b3145bc6262accc9d447718e5318 applied to hw/block/fdc.c;
also, an additional case of drv->media_inserted use has crept in since,
which is replaced by a call to blk_is_inserted().
That commit changed tests/fdc-test.c, too, because after it, one less
TRAY_MOVED event would be emitted when executing 'change' on an empty
drive. However, now, no TRAY_MOVED events will be emitted at all, and
the tray_open status returned by query-block will always be false,
necessitating (different) changes to tests/fdc-test.c and iotest 118,
which is why this patch is not a pure revert of said commit.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 1454096953-31773-4-git-send-email-mreitz@redhat.com
Reviewed-by: Eric Blake <eblake@redhat.com>
2016-01-29 19:49:12 +00:00
|
|
|
if (drv->blk != NULL && blk_is_inserted(drv->blk)) {
|
2012-06-22 10:33:54 +00:00
|
|
|
drv->media_changed = 0;
|
|
|
|
}
|
2007-11-05 03:11:37 +00:00
|
|
|
ret = 1;
|
2012-06-22 10:33:54 +00:00
|
|
|
}
|
2004-01-05 00:09:06 +00:00
|
|
|
drv->track = track;
|
|
|
|
drv->sect = sect;
|
|
|
|
}
|
|
|
|
|
Revert "hw/block/fdc: Implement tray status"
This reverts the changes that commit
2e1280e8ff95b3145bc6262accc9d447718e5318 applied to hw/block/fdc.c;
also, an additional case of drv->media_inserted use has crept in since,
which is replaced by a call to blk_is_inserted().
That commit changed tests/fdc-test.c, too, because after it, one less
TRAY_MOVED event would be emitted when executing 'change' on an empty
drive. However, now, no TRAY_MOVED events will be emitted at all, and
the tray_open status returned by query-block will always be false,
necessitating (different) changes to tests/fdc-test.c and iotest 118,
which is why this patch is not a pure revert of said commit.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 1454096953-31773-4-git-send-email-mreitz@redhat.com
Reviewed-by: Eric Blake <eblake@redhat.com>
2016-01-29 19:49:12 +00:00
|
|
|
if (drv->blk == NULL || !blk_is_inserted(drv->blk)) {
|
2012-06-13 13:43:11 +00:00
|
|
|
ret = 2;
|
|
|
|
}
|
|
|
|
|
2004-03-19 23:05:34 +00:00
|
|
|
return ret;
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set drive back to track 0 */
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fd_recalibrate(FDrive *drv)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
|
|
|
FLOPPY_DPRINTF("recalibrate\n");
|
2012-06-22 10:33:54 +00:00
|
|
|
fd_seek(drv, 0, 0, 1, 1);
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
|
2016-01-22 20:50:59 +00:00
|
|
|
/**
|
|
|
|
* Determine geometry based on inserted diskette.
|
|
|
|
* Will not operate on an empty drive.
|
|
|
|
*
|
|
|
|
* @return: 0 on success, -1 if the drive is empty.
|
|
|
|
*/
|
|
|
|
static int pick_geometry(FDrive *drv)
|
2016-01-22 20:50:54 +00:00
|
|
|
{
|
2016-01-22 20:50:55 +00:00
|
|
|
BlockBackend *blk = drv->blk;
|
2016-01-22 20:50:54 +00:00
|
|
|
const FDFormat *parse;
|
|
|
|
uint64_t nb_sectors, size;
|
2016-01-22 20:51:03 +00:00
|
|
|
int i;
|
|
|
|
int match, size_match, type_match;
|
|
|
|
bool magic = drv->drive == FLOPPY_DRIVE_TYPE_AUTO;
|
2016-01-22 20:50:54 +00:00
|
|
|
|
2016-01-22 20:50:59 +00:00
|
|
|
/* We can only pick a geometry if we have a diskette. */
|
Revert "hw/block/fdc: Implement tray status"
This reverts the changes that commit
2e1280e8ff95b3145bc6262accc9d447718e5318 applied to hw/block/fdc.c;
also, an additional case of drv->media_inserted use has crept in since,
which is replaced by a call to blk_is_inserted().
That commit changed tests/fdc-test.c, too, because after it, one less
TRAY_MOVED event would be emitted when executing 'change' on an empty
drive. However, now, no TRAY_MOVED events will be emitted at all, and
the tray_open status returned by query-block will always be false,
necessitating (different) changes to tests/fdc-test.c and iotest 118,
which is why this patch is not a pure revert of said commit.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 1454096953-31773-4-git-send-email-mreitz@redhat.com
Reviewed-by: Eric Blake <eblake@redhat.com>
2016-01-29 19:49:12 +00:00
|
|
|
if (!drv->blk || !blk_is_inserted(drv->blk) ||
|
|
|
|
drv->drive == FLOPPY_DRIVE_TYPE_NONE)
|
|
|
|
{
|
2016-01-22 20:50:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-01-22 20:51:03 +00:00
|
|
|
/* We need to determine the likely geometry of the inserted medium.
|
|
|
|
* In order of preference, we look for:
|
|
|
|
* (1) The same drive type and number of sectors,
|
|
|
|
* (2) The same diskette size and number of sectors,
|
|
|
|
* (3) The same drive type.
|
|
|
|
*
|
|
|
|
* In all cases, matches that occur higher in the drive table will take
|
|
|
|
* precedence over matches that occur later in the table.
|
|
|
|
*/
|
2016-01-22 20:50:54 +00:00
|
|
|
blk_get_geometry(blk, &nb_sectors);
|
2016-01-22 20:51:03 +00:00
|
|
|
match = size_match = type_match = -1;
|
2016-01-22 20:50:54 +00:00
|
|
|
for (i = 0; ; i++) {
|
|
|
|
parse = &fd_formats[i];
|
2016-01-22 20:50:56 +00:00
|
|
|
if (parse->drive == FLOPPY_DRIVE_TYPE_NONE) {
|
2016-01-22 20:50:54 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-01-22 20:51:03 +00:00
|
|
|
size = (parse->max_head + 1) * parse->max_track * parse->last_sect;
|
|
|
|
if (nb_sectors == size) {
|
|
|
|
if (magic || parse->drive == drv->drive) {
|
|
|
|
/* (1) perfect match -- nb_sectors and drive type */
|
|
|
|
goto out;
|
|
|
|
} else if (drive_size(parse->drive) == drive_size(drv->drive)) {
|
|
|
|
/* (2) size match -- nb_sectors and physical medium size */
|
|
|
|
match = (match == -1) ? i : match;
|
|
|
|
} else {
|
|
|
|
/* This is suspicious -- Did the user misconfigure? */
|
|
|
|
size_match = (size_match == -1) ? i : size_match;
|
2016-01-22 20:50:54 +00:00
|
|
|
}
|
2016-01-22 20:51:03 +00:00
|
|
|
} else if (type_match == -1) {
|
|
|
|
if ((parse->drive == drv->drive) ||
|
|
|
|
(magic && (parse->drive == get_fallback_drive_type(drv)))) {
|
|
|
|
/* (3) type match -- nb_sectors mismatch, but matches the type
|
|
|
|
* specified explicitly by the user, or matches the fallback
|
|
|
|
* default type when using the drive autodetect mechanism */
|
|
|
|
type_match = i;
|
2016-01-22 20:50:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-22 20:51:03 +00:00
|
|
|
|
|
|
|
/* No exact match found */
|
2016-01-22 20:50:54 +00:00
|
|
|
if (match == -1) {
|
2016-01-22 20:51:03 +00:00
|
|
|
if (size_match != -1) {
|
|
|
|
parse = &fd_formats[size_match];
|
|
|
|
FLOPPY_DPRINTF("User requested floppy drive type '%s', "
|
|
|
|
"but inserted medium appears to be a "
|
2016-02-10 18:29:40 +00:00
|
|
|
"%"PRId64" sector '%s' type\n",
|
2017-08-24 08:46:08 +00:00
|
|
|
FloppyDriveType_str(drv->drive),
|
2016-01-22 20:51:03 +00:00
|
|
|
nb_sectors,
|
2017-08-24 08:46:08 +00:00
|
|
|
FloppyDriveType_str(parse->drive));
|
2016-01-22 20:50:54 +00:00
|
|
|
}
|
2018-06-29 14:11:00 +00:00
|
|
|
assert(type_match != -1 && "misconfigured fd_format");
|
2016-01-22 20:51:03 +00:00
|
|
|
match = type_match;
|
2016-01-22 20:50:54 +00:00
|
|
|
}
|
2016-01-22 20:51:03 +00:00
|
|
|
parse = &(fd_formats[match]);
|
|
|
|
|
|
|
|
out:
|
2016-01-22 20:50:55 +00:00
|
|
|
if (parse->max_head == 0) {
|
|
|
|
drv->flags &= ~FDISK_DBL_SIDES;
|
|
|
|
} else {
|
|
|
|
drv->flags |= FDISK_DBL_SIDES;
|
|
|
|
}
|
|
|
|
drv->max_track = parse->max_track;
|
|
|
|
drv->last_sect = parse->last_sect;
|
2016-01-22 20:50:59 +00:00
|
|
|
drv->disk = parse->drive;
|
2016-01-22 20:50:55 +00:00
|
|
|
drv->media_rate = parse->rate;
|
2016-01-22 20:50:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pick_drive_type(FDrive *drv)
|
|
|
|
{
|
2016-01-22 20:51:01 +00:00
|
|
|
if (drv->drive != FLOPPY_DRIVE_TYPE_AUTO) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-22 20:50:59 +00:00
|
|
|
if (pick_geometry(drv) == 0) {
|
|
|
|
drv->drive = drv->disk;
|
|
|
|
} else {
|
2016-01-22 20:51:00 +00:00
|
|
|
drv->drive = get_fallback_drive_type(drv);
|
2016-01-22 20:50:59 +00:00
|
|
|
}
|
2016-01-22 20:51:01 +00:00
|
|
|
|
|
|
|
g_assert(drv->drive != FLOPPY_DRIVE_TYPE_AUTO);
|
2016-01-22 20:50:54 +00:00
|
|
|
}
|
|
|
|
|
2004-01-05 00:09:06 +00:00
|
|
|
/* Revalidate a disk drive after a disk change */
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fd_revalidate(FDrive *drv)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
2016-01-22 20:50:59 +00:00
|
|
|
int rc;
|
|
|
|
|
2004-01-05 00:09:06 +00:00
|
|
|
FLOPPY_DPRINTF("revalidate\n");
|
2014-10-07 11:59:18 +00:00
|
|
|
if (drv->blk != NULL) {
|
2021-01-18 12:34:47 +00:00
|
|
|
drv->ro = !blk_is_writable(drv->blk);
|
Revert "hw/block/fdc: Implement tray status"
This reverts the changes that commit
2e1280e8ff95b3145bc6262accc9d447718e5318 applied to hw/block/fdc.c;
also, an additional case of drv->media_inserted use has crept in since,
which is replaced by a call to blk_is_inserted().
That commit changed tests/fdc-test.c, too, because after it, one less
TRAY_MOVED event would be emitted when executing 'change' on an empty
drive. However, now, no TRAY_MOVED events will be emitted at all, and
the tray_open status returned by query-block will always be false,
necessitating (different) changes to tests/fdc-test.c and iotest 118,
which is why this patch is not a pure revert of said commit.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 1454096953-31773-4-git-send-email-mreitz@redhat.com
Reviewed-by: Eric Blake <eblake@redhat.com>
2016-01-29 19:49:12 +00:00
|
|
|
if (!blk_is_inserted(drv->blk)) {
|
2012-05-24 09:02:29 +00:00
|
|
|
FLOPPY_DPRINTF("No disk in drive\n");
|
2016-01-22 20:50:59 +00:00
|
|
|
drv->disk = FLOPPY_DRIVE_TYPE_NONE;
|
fdc: fix detection under Linux
Accidentally, I removed a "feature" where empty drives had geometry
values applied to them, which allows seek on empty drives to work
"by accident," as QEMU actually tries to disallow that.
Seeks on empty drives should work, though, but the easiest thing is to
restore the misfeature where empty drives have non-zero geometries
applied.
Document the hack accordingly.
[Maintainer edit]
This fix corrects a regression introduced in d5d47efc, where
pick_geometry was modified such that it would not operate on empty
drives, and as a result if there is no diskette inserted, QEMU
no longer populates it with geometry bounds. As a result, seek fails
when QEMU denies to move the current track, but reports success anyway.
This can confuse the guest, leading to kernel panics in the guest.
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1454106932-17236-1-git-send-email-jsnow@redhat.com
2016-02-03 16:28:55 +00:00
|
|
|
fd_empty_seek_hack(drv);
|
2016-01-22 20:50:59 +00:00
|
|
|
} else if (!drv->media_validated) {
|
|
|
|
rc = pick_geometry(drv);
|
|
|
|
if (rc) {
|
|
|
|
FLOPPY_DPRINTF("Could not validate floppy drive media");
|
|
|
|
} else {
|
|
|
|
drv->media_validated = true;
|
|
|
|
FLOPPY_DPRINTF("Floppy disk (%d h %d t %d s) %s\n",
|
|
|
|
(drv->flags & FDISK_DBL_SIDES) ? 2 : 1,
|
|
|
|
drv->max_track, drv->last_sect,
|
|
|
|
drv->ro ? "ro" : "rw");
|
|
|
|
}
|
2007-11-05 03:11:37 +00:00
|
|
|
}
|
2004-01-05 00:09:06 +00:00
|
|
|
} else {
|
2012-05-24 09:02:29 +00:00
|
|
|
FLOPPY_DPRINTF("No drive connected\n");
|
2004-03-19 23:05:34 +00:00
|
|
|
drv->last_sect = 0;
|
2007-11-05 03:11:37 +00:00
|
|
|
drv->max_track = 0;
|
|
|
|
drv->flags &= ~FDISK_DBL_SIDES;
|
2016-01-22 20:50:59 +00:00
|
|
|
drv->drive = FLOPPY_DRIVE_TYPE_NONE;
|
|
|
|
drv->disk = FLOPPY_DRIVE_TYPE_NONE;
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
2004-03-14 21:40:43 +00:00
|
|
|
}
|
|
|
|
|
2017-01-24 13:21:41 +00:00
|
|
|
static void fd_change_cb(void *opaque, bool load, Error **errp)
|
2016-10-27 20:29:13 +00:00
|
|
|
{
|
|
|
|
FDrive *drive = opaque;
|
2017-01-24 12:43:31 +00:00
|
|
|
|
|
|
|
if (!load) {
|
|
|
|
blk_set_perm(drive->blk, 0, BLK_PERM_ALL, &error_abort);
|
|
|
|
} else {
|
2017-11-22 03:08:45 +00:00
|
|
|
if (!blkconf_apply_backend_options(drive->conf,
|
2021-01-18 12:34:47 +00:00
|
|
|
!blk_supports_write_perm(drive->blk),
|
|
|
|
false, errp)) {
|
2017-01-24 12:43:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-10-27 20:29:13 +00:00
|
|
|
|
|
|
|
drive->media_changed = 1;
|
|
|
|
drive->media_validated = false;
|
|
|
|
fd_revalidate(drive);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const BlockDevOps fd_block_ops = {
|
|
|
|
.change_media_cb = fd_change_cb,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define TYPE_FLOPPY_DRIVE "floppy"
|
2020-09-16 18:25:19 +00:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(FloppyDrive, FLOPPY_DRIVE)
|
2016-10-27 20:29:13 +00:00
|
|
|
|
2020-09-03 20:43:22 +00:00
|
|
|
struct FloppyDrive {
|
2016-10-27 20:29:13 +00:00
|
|
|
DeviceState qdev;
|
|
|
|
uint32_t unit;
|
|
|
|
BlockConf conf;
|
|
|
|
FloppyDriveType type;
|
2020-09-03 20:43:22 +00:00
|
|
|
};
|
2016-10-27 20:29:13 +00:00
|
|
|
|
|
|
|
static Property floppy_drive_properties[] = {
|
|
|
|
DEFINE_PROP_UINT32("unit", FloppyDrive, unit, -1),
|
2016-10-27 20:29:13 +00:00
|
|
|
DEFINE_BLOCK_PROPERTIES(FloppyDrive, conf),
|
2017-06-07 16:36:07 +00:00
|
|
|
DEFINE_PROP_SIGNED("drive-type", FloppyDrive, type,
|
2016-10-27 20:29:13 +00:00
|
|
|
FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type,
|
|
|
|
FloppyDriveType),
|
2016-10-27 20:29:13 +00:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2017-09-18 14:05:14 +00:00
|
|
|
static void floppy_drive_realize(DeviceState *qdev, Error **errp)
|
2016-10-27 20:29:13 +00:00
|
|
|
{
|
|
|
|
FloppyDrive *dev = FLOPPY_DRIVE(qdev);
|
|
|
|
FloppyBus *bus = FLOPPY_BUS(qdev->parent_bus);
|
|
|
|
FDrive *drive;
|
2019-07-30 13:37:08 +00:00
|
|
|
bool read_only;
|
2016-10-27 20:29:13 +00:00
|
|
|
int ret;
|
2016-10-27 20:29:13 +00:00
|
|
|
|
|
|
|
if (dev->unit == -1) {
|
|
|
|
for (dev->unit = 0; dev->unit < MAX_FD; dev->unit++) {
|
|
|
|
drive = get_drv(bus->fdc, dev->unit);
|
|
|
|
if (!drive->blk) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dev->unit >= MAX_FD) {
|
2017-09-18 14:05:14 +00:00
|
|
|
error_setg(errp, "Can't create floppy unit %d, bus supports "
|
|
|
|
"only %d units", dev->unit, MAX_FD);
|
|
|
|
return;
|
2016-10-27 20:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
drive = get_drv(bus->fdc, dev->unit);
|
|
|
|
if (drive->blk) {
|
2017-09-18 14:05:14 +00:00
|
|
|
error_setg(errp, "Floppy unit %d is in use", dev->unit);
|
|
|
|
return;
|
2016-10-27 20:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!dev->conf.blk) {
|
2021-11-24 16:15:34 +00:00
|
|
|
dev->conf.blk = blk_create_empty_drive();
|
2016-10-27 20:29:13 +00:00
|
|
|
ret = blk_attach_dev(dev->conf.blk, qdev);
|
|
|
|
assert(ret == 0);
|
2019-07-30 13:37:08 +00:00
|
|
|
|
|
|
|
/* Don't take write permissions on an empty drive to allow attaching a
|
|
|
|
* read-only node later */
|
|
|
|
read_only = true;
|
|
|
|
} else {
|
2021-01-18 12:34:47 +00:00
|
|
|
read_only = !blk_bs(dev->conf.blk) ||
|
|
|
|
!blk_supports_write_perm(dev->conf.blk);
|
2016-10-27 20:29:13 +00:00
|
|
|
}
|
|
|
|
|
2020-05-28 22:55:10 +00:00
|
|
|
if (!blkconf_blocksizes(&dev->conf, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-27 20:29:13 +00:00
|
|
|
if (dev->conf.logical_block_size != 512 ||
|
|
|
|
dev->conf.physical_block_size != 512)
|
|
|
|
{
|
2017-09-18 14:05:14 +00:00
|
|
|
error_setg(errp, "Physical and logical block size must "
|
|
|
|
"be 512 for floppy");
|
|
|
|
return;
|
2016-10-27 20:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* rerror/werror aren't supported by fdc and therefore not even registered
|
|
|
|
* with qdev. So set the defaults manually before they are used in
|
|
|
|
* blkconf_apply_backend_options(). */
|
|
|
|
dev->conf.rerror = BLOCKDEV_ON_ERROR_AUTO;
|
|
|
|
dev->conf.werror = BLOCKDEV_ON_ERROR_AUTO;
|
2017-01-24 12:43:31 +00:00
|
|
|
|
2019-07-30 13:37:08 +00:00
|
|
|
if (!blkconf_apply_backend_options(&dev->conf, read_only, false, errp)) {
|
2017-09-18 14:05:14 +00:00
|
|
|
return;
|
2017-01-24 12:43:31 +00:00
|
|
|
}
|
2016-10-27 20:29:13 +00:00
|
|
|
|
|
|
|
/* 'enospc' is the default for -drive, 'report' is what blk_new() gives us
|
|
|
|
* for empty drives. */
|
|
|
|
if (blk_get_on_error(dev->conf.blk, 0) != BLOCKDEV_ON_ERROR_ENOSPC &&
|
|
|
|
blk_get_on_error(dev->conf.blk, 0) != BLOCKDEV_ON_ERROR_REPORT) {
|
2017-09-18 14:05:14 +00:00
|
|
|
error_setg(errp, "fdc doesn't support drive option werror");
|
|
|
|
return;
|
2016-10-27 20:29:13 +00:00
|
|
|
}
|
2016-10-27 20:29:13 +00:00
|
|
|
if (blk_get_on_error(dev->conf.blk, 1) != BLOCKDEV_ON_ERROR_REPORT) {
|
2017-09-18 14:05:14 +00:00
|
|
|
error_setg(errp, "fdc doesn't support drive option rerror");
|
|
|
|
return;
|
2016-10-27 20:29:13 +00:00
|
|
|
}
|
|
|
|
|
2017-01-24 12:43:31 +00:00
|
|
|
drive->conf = &dev->conf;
|
2016-10-27 20:29:13 +00:00
|
|
|
drive->blk = dev->conf.blk;
|
|
|
|
drive->fdctrl = bus->fdc;
|
|
|
|
|
|
|
|
fd_init(drive);
|
|
|
|
blk_set_dev_ops(drive->blk, &fd_block_ops, drive);
|
|
|
|
|
|
|
|
/* Keep 'type' qdev property and FDrive->drive in sync */
|
|
|
|
drive->drive = dev->type;
|
|
|
|
pick_drive_type(drive);
|
|
|
|
dev->type = drive->drive;
|
|
|
|
|
2016-10-27 20:29:13 +00:00
|
|
|
fd_revalidate(drive);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void floppy_drive_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *k = DEVICE_CLASS(klass);
|
2017-09-18 14:05:14 +00:00
|
|
|
k->realize = floppy_drive_realize;
|
2016-10-27 20:29:13 +00:00
|
|
|
set_bit(DEVICE_CATEGORY_STORAGE, k->categories);
|
|
|
|
k->bus_type = TYPE_FLOPPY_BUS;
|
2020-01-10 15:30:32 +00:00
|
|
|
device_class_set_props(k, floppy_drive_properties);
|
2016-10-27 20:29:13 +00:00
|
|
|
k->desc = "virtual floppy drive";
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo floppy_drive_info = {
|
|
|
|
.name = TYPE_FLOPPY_DRIVE,
|
|
|
|
.parent = TYPE_DEVICE,
|
|
|
|
.instance_size = sizeof(FloppyDrive),
|
|
|
|
.class_init = floppy_drive_class_init,
|
|
|
|
};
|
|
|
|
|
2004-01-05 00:09:06 +00:00
|
|
|
/********************************************************/
|
2004-10-09 16:44:33 +00:00
|
|
|
/* Intel 82078 floppy disk controller emulation */
|
2004-01-05 00:09:06 +00:00
|
|
|
|
2015-05-21 13:19:31 +00:00
|
|
|
static void fdctrl_to_command_phase(FDCtrl *fdctrl);
|
2012-08-19 08:21:14 +00:00
|
|
|
static void fdctrl_raise_irq(FDCtrl *fdctrl);
|
2012-02-06 21:29:12 +00:00
|
|
|
static FDrive *get_cur_drv(FDCtrl *fdctrl);
|
2010-02-07 09:01:18 +00:00
|
|
|
|
|
|
|
static uint32_t fdctrl_read_statusA(FDCtrl *fdctrl);
|
|
|
|
static uint32_t fdctrl_read_statusB(FDCtrl *fdctrl);
|
|
|
|
static uint32_t fdctrl_read_dor(FDCtrl *fdctrl);
|
|
|
|
static void fdctrl_write_dor(FDCtrl *fdctrl, uint32_t value);
|
|
|
|
static uint32_t fdctrl_read_tape(FDCtrl *fdctrl);
|
|
|
|
static void fdctrl_write_tape(FDCtrl *fdctrl, uint32_t value);
|
|
|
|
static uint32_t fdctrl_read_main_status(FDCtrl *fdctrl);
|
|
|
|
static void fdctrl_write_rate(FDCtrl *fdctrl, uint32_t value);
|
|
|
|
static uint32_t fdctrl_read_data(FDCtrl *fdctrl);
|
|
|
|
static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t value);
|
|
|
|
static uint32_t fdctrl_read_dir(FDCtrl *fdctrl);
|
2012-02-06 21:29:06 +00:00
|
|
|
static void fdctrl_write_ccr(FDCtrl *fdctrl, uint32_t value);
|
2004-01-05 00:09:06 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
FD_DIR_WRITE = 0,
|
|
|
|
FD_DIR_READ = 1,
|
|
|
|
FD_DIR_SCANE = 2,
|
|
|
|
FD_DIR_SCANL = 3,
|
|
|
|
FD_DIR_SCANH = 4,
|
2012-09-18 21:04:10 +00:00
|
|
|
FD_DIR_VERIFY = 5,
|
2004-01-05 00:09:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2008-04-29 16:16:30 +00:00
|
|
|
FD_STATE_MULTI = 0x01, /* multi track flag */
|
|
|
|
FD_STATE_FORMAT = 0x02, /* format flag */
|
2004-01-05 00:09:06 +00:00
|
|
|
};
|
|
|
|
|
2008-02-29 19:24:00 +00:00
|
|
|
enum {
|
2008-04-29 16:14:15 +00:00
|
|
|
FD_REG_SRA = 0x00,
|
|
|
|
FD_REG_SRB = 0x01,
|
2008-02-29 19:24:00 +00:00
|
|
|
FD_REG_DOR = 0x02,
|
|
|
|
FD_REG_TDR = 0x03,
|
|
|
|
FD_REG_MSR = 0x04,
|
|
|
|
FD_REG_DSR = 0x04,
|
|
|
|
FD_REG_FIFO = 0x05,
|
|
|
|
FD_REG_DIR = 0x07,
|
2012-02-06 21:29:06 +00:00
|
|
|
FD_REG_CCR = 0x07,
|
2008-02-29 19:24:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2008-04-08 17:18:53 +00:00
|
|
|
FD_CMD_READ_TRACK = 0x02,
|
2008-02-29 19:24:00 +00:00
|
|
|
FD_CMD_SPECIFY = 0x03,
|
|
|
|
FD_CMD_SENSE_DRIVE_STATUS = 0x04,
|
2008-04-08 17:18:53 +00:00
|
|
|
FD_CMD_WRITE = 0x05,
|
|
|
|
FD_CMD_READ = 0x06,
|
2008-02-29 19:24:00 +00:00
|
|
|
FD_CMD_RECALIBRATE = 0x07,
|
|
|
|
FD_CMD_SENSE_INTERRUPT_STATUS = 0x08,
|
2008-04-08 17:18:53 +00:00
|
|
|
FD_CMD_WRITE_DELETED = 0x09,
|
|
|
|
FD_CMD_READ_ID = 0x0a,
|
|
|
|
FD_CMD_READ_DELETED = 0x0c,
|
|
|
|
FD_CMD_FORMAT_TRACK = 0x0d,
|
2008-02-29 19:24:00 +00:00
|
|
|
FD_CMD_DUMPREG = 0x0e,
|
|
|
|
FD_CMD_SEEK = 0x0f,
|
|
|
|
FD_CMD_VERSION = 0x10,
|
2008-04-08 17:18:53 +00:00
|
|
|
FD_CMD_SCAN_EQUAL = 0x11,
|
2008-02-29 19:24:00 +00:00
|
|
|
FD_CMD_PERPENDICULAR_MODE = 0x12,
|
|
|
|
FD_CMD_CONFIGURE = 0x13,
|
2008-04-08 17:18:53 +00:00
|
|
|
FD_CMD_LOCK = 0x14,
|
|
|
|
FD_CMD_VERIFY = 0x16,
|
2008-02-29 19:24:00 +00:00
|
|
|
FD_CMD_POWERDOWN_MODE = 0x17,
|
|
|
|
FD_CMD_PART_ID = 0x18,
|
2008-04-08 17:18:53 +00:00
|
|
|
FD_CMD_SCAN_LOW_OR_EQUAL = 0x19,
|
|
|
|
FD_CMD_SCAN_HIGH_OR_EQUAL = 0x1d,
|
2010-06-11 14:02:34 +00:00
|
|
|
FD_CMD_SAVE = 0x2e,
|
2008-02-29 19:24:00 +00:00
|
|
|
FD_CMD_OPTION = 0x33,
|
2010-06-11 14:02:34 +00:00
|
|
|
FD_CMD_RESTORE = 0x4e,
|
2008-02-29 19:24:00 +00:00
|
|
|
FD_CMD_DRIVE_SPECIFICATION_COMMAND = 0x8e,
|
|
|
|
FD_CMD_RELATIVE_SEEK_OUT = 0x8f,
|
|
|
|
FD_CMD_FORMAT_AND_WRITE = 0xcd,
|
|
|
|
FD_CMD_RELATIVE_SEEK_IN = 0xcf,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FD_CONFIG_PRETRK = 0xff, /* Pre-compensation set to track 0 */
|
|
|
|
FD_CONFIG_FIFOTHR = 0x0f, /* FIFO threshold set to 1 byte */
|
|
|
|
FD_CONFIG_POLL = 0x10, /* Poll enabled */
|
|
|
|
FD_CONFIG_EFIFO = 0x20, /* FIFO disabled */
|
|
|
|
FD_CONFIG_EIS = 0x40, /* No implied seeks */
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2012-06-22 10:33:55 +00:00
|
|
|
FD_SR0_DS0 = 0x01,
|
|
|
|
FD_SR0_DS1 = 0x02,
|
|
|
|
FD_SR0_HEAD = 0x04,
|
2008-02-29 19:24:00 +00:00
|
|
|
FD_SR0_EQPMT = 0x10,
|
|
|
|
FD_SR0_SEEK = 0x20,
|
|
|
|
FD_SR0_ABNTERM = 0x40,
|
|
|
|
FD_SR0_INVCMD = 0x80,
|
|
|
|
FD_SR0_RDYCHG = 0xc0,
|
|
|
|
};
|
|
|
|
|
2008-04-29 16:17:08 +00:00
|
|
|
enum {
|
2012-02-06 21:29:10 +00:00
|
|
|
FD_SR1_MA = 0x01, /* Missing address mark */
|
2012-02-06 21:29:05 +00:00
|
|
|
FD_SR1_NW = 0x02, /* Not writable */
|
2008-04-29 16:17:08 +00:00
|
|
|
FD_SR1_EC = 0x80, /* End of cylinder */
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FD_SR2_SNS = 0x04, /* Scan not satisfied */
|
|
|
|
FD_SR2_SEH = 0x08, /* Scan equal hit */
|
|
|
|
};
|
|
|
|
|
2008-04-29 16:14:15 +00:00
|
|
|
enum {
|
|
|
|
FD_SRA_DIR = 0x01,
|
|
|
|
FD_SRA_nWP = 0x02,
|
|
|
|
FD_SRA_nINDX = 0x04,
|
|
|
|
FD_SRA_HDSEL = 0x08,
|
|
|
|
FD_SRA_nTRK0 = 0x10,
|
|
|
|
FD_SRA_STEP = 0x20,
|
|
|
|
FD_SRA_nDRV2 = 0x40,
|
|
|
|
FD_SRA_INTPEND = 0x80,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FD_SRB_MTR0 = 0x01,
|
|
|
|
FD_SRB_MTR1 = 0x02,
|
|
|
|
FD_SRB_WGATE = 0x04,
|
|
|
|
FD_SRB_RDATA = 0x08,
|
|
|
|
FD_SRB_WDATA = 0x10,
|
|
|
|
FD_SRB_DR0 = 0x20,
|
|
|
|
};
|
|
|
|
|
2008-02-29 19:24:00 +00:00
|
|
|
enum {
|
2008-04-29 16:18:26 +00:00
|
|
|
#if MAX_FD == 4
|
|
|
|
FD_DOR_SELMASK = 0x03,
|
|
|
|
#else
|
2008-02-29 19:24:00 +00:00
|
|
|
FD_DOR_SELMASK = 0x01,
|
2008-04-29 16:18:26 +00:00
|
|
|
#endif
|
2008-02-29 19:24:00 +00:00
|
|
|
FD_DOR_nRESET = 0x04,
|
|
|
|
FD_DOR_DMAEN = 0x08,
|
|
|
|
FD_DOR_MOTEN0 = 0x10,
|
|
|
|
FD_DOR_MOTEN1 = 0x20,
|
|
|
|
FD_DOR_MOTEN2 = 0x40,
|
|
|
|
FD_DOR_MOTEN3 = 0x80,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2008-04-29 16:18:26 +00:00
|
|
|
#if MAX_FD == 4
|
2008-02-29 19:24:00 +00:00
|
|
|
FD_TDR_BOOTSEL = 0x0c,
|
2008-04-29 16:18:26 +00:00
|
|
|
#else
|
|
|
|
FD_TDR_BOOTSEL = 0x04,
|
|
|
|
#endif
|
2008-02-29 19:24:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FD_DSR_DRATEMASK= 0x03,
|
|
|
|
FD_DSR_PWRDOWN = 0x40,
|
|
|
|
FD_DSR_SWRESET = 0x80,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FD_MSR_DRV0BUSY = 0x01,
|
|
|
|
FD_MSR_DRV1BUSY = 0x02,
|
|
|
|
FD_MSR_DRV2BUSY = 0x04,
|
|
|
|
FD_MSR_DRV3BUSY = 0x08,
|
|
|
|
FD_MSR_CMDBUSY = 0x10,
|
|
|
|
FD_MSR_NONDMA = 0x20,
|
|
|
|
FD_MSR_DIO = 0x40,
|
|
|
|
FD_MSR_RQM = 0x80,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FD_DIR_DSKCHG = 0x80,
|
|
|
|
};
|
|
|
|
|
2015-05-21 13:19:33 +00:00
|
|
|
/*
|
|
|
|
* See chapter 5.0 "Controller phases" of the spec:
|
|
|
|
*
|
|
|
|
* Command phase:
|
|
|
|
* The host writes a command and its parameters into the FIFO. The command
|
|
|
|
* phase is completed when all parameters for the command have been supplied,
|
|
|
|
* and execution phase is entered.
|
|
|
|
*
|
|
|
|
* Execution phase:
|
|
|
|
* Data transfers, either DMA or non-DMA. For non-DMA transfers, the FIFO
|
|
|
|
* contains the payload now, otherwise it's unused. When all bytes of the
|
|
|
|
* required data have been transferred, the state is switched to either result
|
|
|
|
* phase (if the command produces status bytes) or directly back into the
|
|
|
|
* command phase for the next command.
|
|
|
|
*
|
|
|
|
* Result phase:
|
|
|
|
* The host reads out the FIFO, which contains one or more result bytes now.
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
/* Only for migration: reconstruct phase from registers like qemu 2.3 */
|
|
|
|
FD_PHASE_RECONSTRUCT = 0,
|
|
|
|
|
|
|
|
FD_PHASE_COMMAND = 1,
|
|
|
|
FD_PHASE_EXECUTION = 2,
|
|
|
|
FD_PHASE_RESULT = 3,
|
|
|
|
};
|
|
|
|
|
2004-01-05 00:09:06 +00:00
|
|
|
#define FD_MULTI_TRACK(state) ((state) & FD_STATE_MULTI)
|
2004-03-19 23:05:34 +00:00
|
|
|
#define FD_FORMAT_CMD(state) ((state) & FD_STATE_FORMAT)
|
2004-01-05 00:09:06 +00:00
|
|
|
|
2016-01-22 20:51:00 +00:00
|
|
|
static FloppyDriveType get_fallback_drive_type(FDrive *drv)
|
|
|
|
{
|
|
|
|
return drv->fdctrl->fallback;
|
|
|
|
}
|
|
|
|
|
2021-06-14 19:32:17 +00:00
|
|
|
uint32_t fdctrl_read(void *opaque, uint32_t reg)
|
2004-03-19 23:05:34 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDCtrl *fdctrl = opaque;
|
2004-03-19 23:05:34 +00:00
|
|
|
uint32_t retval;
|
|
|
|
|
2011-10-18 14:41:45 +00:00
|
|
|
reg &= 7;
|
2008-12-02 17:47:02 +00:00
|
|
|
switch (reg) {
|
2008-04-29 16:14:15 +00:00
|
|
|
case FD_REG_SRA:
|
|
|
|
retval = fdctrl_read_statusA(fdctrl);
|
2007-11-05 03:11:37 +00:00
|
|
|
break;
|
2008-04-29 16:14:15 +00:00
|
|
|
case FD_REG_SRB:
|
2007-11-05 03:11:37 +00:00
|
|
|
retval = fdctrl_read_statusB(fdctrl);
|
|
|
|
break;
|
2008-02-29 19:24:00 +00:00
|
|
|
case FD_REG_DOR:
|
2007-11-05 03:11:37 +00:00
|
|
|
retval = fdctrl_read_dor(fdctrl);
|
|
|
|
break;
|
2008-02-29 19:24:00 +00:00
|
|
|
case FD_REG_TDR:
|
2004-03-19 23:05:34 +00:00
|
|
|
retval = fdctrl_read_tape(fdctrl);
|
2007-11-05 03:11:37 +00:00
|
|
|
break;
|
2008-02-29 19:24:00 +00:00
|
|
|
case FD_REG_MSR:
|
2004-03-19 23:05:34 +00:00
|
|
|
retval = fdctrl_read_main_status(fdctrl);
|
2007-11-05 03:11:37 +00:00
|
|
|
break;
|
2008-02-29 19:24:00 +00:00
|
|
|
case FD_REG_FIFO:
|
2004-03-19 23:05:34 +00:00
|
|
|
retval = fdctrl_read_data(fdctrl);
|
2007-11-05 03:11:37 +00:00
|
|
|
break;
|
2008-02-29 19:24:00 +00:00
|
|
|
case FD_REG_DIR:
|
2004-03-19 23:05:34 +00:00
|
|
|
retval = fdctrl_read_dir(fdctrl);
|
2007-11-05 03:11:37 +00:00
|
|
|
break;
|
2004-04-12 20:39:29 +00:00
|
|
|
default:
|
2007-11-05 03:11:37 +00:00
|
|
|
retval = (uint32_t)(-1);
|
|
|
|
break;
|
2004-04-12 20:39:29 +00:00
|
|
|
}
|
2018-06-21 17:12:56 +00:00
|
|
|
trace_fdc_ioport_read(reg, retval);
|
2004-03-19 23:05:34 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2021-06-14 19:32:17 +00:00
|
|
|
void fdctrl_write(void *opaque, uint32_t reg, uint32_t value)
|
2004-03-19 23:05:34 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDCtrl *fdctrl = opaque;
|
2004-03-19 23:05:34 +00:00
|
|
|
|
2011-10-18 14:41:45 +00:00
|
|
|
reg &= 7;
|
2018-06-21 17:12:56 +00:00
|
|
|
trace_fdc_ioport_write(reg, value);
|
2008-12-02 17:47:02 +00:00
|
|
|
switch (reg) {
|
2008-02-29 19:24:00 +00:00
|
|
|
case FD_REG_DOR:
|
2007-11-05 03:11:37 +00:00
|
|
|
fdctrl_write_dor(fdctrl, value);
|
|
|
|
break;
|
2008-02-29 19:24:00 +00:00
|
|
|
case FD_REG_TDR:
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl_write_tape(fdctrl, value);
|
2007-11-05 03:11:37 +00:00
|
|
|
break;
|
2008-02-29 19:24:00 +00:00
|
|
|
case FD_REG_DSR:
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl_write_rate(fdctrl, value);
|
2007-11-05 03:11:37 +00:00
|
|
|
break;
|
2008-02-29 19:24:00 +00:00
|
|
|
case FD_REG_FIFO:
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl_write_data(fdctrl, value);
|
2007-11-05 03:11:37 +00:00
|
|
|
break;
|
2012-02-06 21:29:06 +00:00
|
|
|
case FD_REG_CCR:
|
|
|
|
fdctrl_write_ccr(fdctrl, value);
|
|
|
|
break;
|
2004-04-12 20:39:29 +00:00
|
|
|
default:
|
2007-11-05 03:11:37 +00:00
|
|
|
break;
|
2004-04-12 20:39:29 +00:00
|
|
|
}
|
2004-03-19 23:05:34 +00:00
|
|
|
}
|
|
|
|
|
2011-04-06 10:34:31 +00:00
|
|
|
static bool fdrive_media_changed_needed(void *opaque)
|
|
|
|
{
|
|
|
|
FDrive *drive = opaque;
|
|
|
|
|
Revert "hw/block/fdc: Implement tray status"
This reverts the changes that commit
2e1280e8ff95b3145bc6262accc9d447718e5318 applied to hw/block/fdc.c;
also, an additional case of drv->media_inserted use has crept in since,
which is replaced by a call to blk_is_inserted().
That commit changed tests/fdc-test.c, too, because after it, one less
TRAY_MOVED event would be emitted when executing 'change' on an empty
drive. However, now, no TRAY_MOVED events will be emitted at all, and
the tray_open status returned by query-block will always be false,
necessitating (different) changes to tests/fdc-test.c and iotest 118,
which is why this patch is not a pure revert of said commit.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 1454096953-31773-4-git-send-email-mreitz@redhat.com
Reviewed-by: Eric Blake <eblake@redhat.com>
2016-01-29 19:49:12 +00:00
|
|
|
return (drive->blk != NULL && drive->media_changed != 1);
|
2011-04-06 10:34:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_fdrive_media_changed = {
|
|
|
|
.name = "fdrive/media_changed",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 12:09:54 +00:00
|
|
|
.needed = fdrive_media_changed_needed,
|
2014-04-16 13:32:32 +00:00
|
|
|
.fields = (VMStateField[]) {
|
2011-04-06 10:34:31 +00:00
|
|
|
VMSTATE_UINT8(media_changed, FDrive),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-06 21:29:10 +00:00
|
|
|
static const VMStateDescription vmstate_fdrive_media_rate = {
|
|
|
|
.name = "fdrive/media_rate",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-04-16 13:32:32 +00:00
|
|
|
.fields = (VMStateField[]) {
|
2012-02-06 21:29:10 +00:00
|
|
|
VMSTATE_UINT8(media_rate, FDrive),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-28 11:18:41 +00:00
|
|
|
static bool fdrive_perpendicular_needed(void *opaque)
|
|
|
|
{
|
|
|
|
FDrive *drive = opaque;
|
|
|
|
|
|
|
|
return drive->perpendicular != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_fdrive_perpendicular = {
|
|
|
|
.name = "fdrive/perpendicular",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 12:09:54 +00:00
|
|
|
.needed = fdrive_perpendicular_needed,
|
2014-08-28 11:18:41 +00:00
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT8(perpendicular, FDrive),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int fdrive_post_load(void *opaque, int version_id)
|
|
|
|
{
|
|
|
|
fd_revalidate(opaque);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-10 01:04:37 +00:00
|
|
|
static const VMStateDescription vmstate_fdrive = {
|
|
|
|
.name = "fdrive",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-08-28 11:18:41 +00:00
|
|
|
.post_load = fdrive_post_load,
|
2014-04-16 13:32:32 +00:00
|
|
|
.fields = (VMStateField[]) {
|
2010-02-07 09:01:18 +00:00
|
|
|
VMSTATE_UINT8(head, FDrive),
|
|
|
|
VMSTATE_UINT8(track, FDrive),
|
|
|
|
VMSTATE_UINT8(sect, FDrive),
|
2009-09-10 01:04:37 +00:00
|
|
|
VMSTATE_END_OF_LIST()
|
2011-04-06 10:34:31 +00:00
|
|
|
},
|
2014-09-23 12:09:54 +00:00
|
|
|
.subsections = (const VMStateDescription*[]) {
|
|
|
|
&vmstate_fdrive_media_changed,
|
|
|
|
&vmstate_fdrive_media_rate,
|
|
|
|
&vmstate_fdrive_perpendicular,
|
|
|
|
NULL
|
2009-09-10 01:04:37 +00:00
|
|
|
}
|
|
|
|
};
|
2007-04-14 13:01:31 +00:00
|
|
|
|
2015-05-21 13:19:33 +00:00
|
|
|
/*
|
|
|
|
* Reconstructs the phase from register values according to the logic that was
|
|
|
|
* implemented in qemu 2.3. This is the default value that is used if the phase
|
|
|
|
* subsection is not present on migration.
|
|
|
|
*
|
|
|
|
* Don't change this function to reflect newer qemu versions, it is part of
|
|
|
|
* the migration ABI.
|
|
|
|
*/
|
|
|
|
static int reconstruct_phase(FDCtrl *fdctrl)
|
|
|
|
{
|
|
|
|
if (fdctrl->msr & FD_MSR_NONDMA) {
|
|
|
|
return FD_PHASE_EXECUTION;
|
|
|
|
} else if ((fdctrl->msr & FD_MSR_RQM) == 0) {
|
|
|
|
/* qemu 2.3 disabled RQM only during DMA transfers */
|
|
|
|
return FD_PHASE_EXECUTION;
|
|
|
|
} else if (fdctrl->msr & FD_MSR_DIO) {
|
|
|
|
return FD_PHASE_RESULT;
|
|
|
|
} else {
|
|
|
|
return FD_PHASE_COMMAND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-25 11:29:12 +00:00
|
|
|
static int fdc_pre_save(void *opaque)
|
2007-04-14 13:01:31 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDCtrl *s = opaque;
|
2007-04-14 13:01:31 +00:00
|
|
|
|
2009-09-10 01:04:37 +00:00
|
|
|
s->dor_vmstate = s->dor | GET_CUR_DRV(s);
|
2017-09-25 11:29:12 +00:00
|
|
|
|
|
|
|
return 0;
|
2007-04-14 13:01:31 +00:00
|
|
|
}
|
|
|
|
|
2015-05-21 13:19:33 +00:00
|
|
|
static int fdc_pre_load(void *opaque)
|
|
|
|
{
|
|
|
|
FDCtrl *s = opaque;
|
|
|
|
s->phase = FD_PHASE_RECONSTRUCT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-29 20:48:21 +00:00
|
|
|
static int fdc_post_load(void *opaque, int version_id)
|
2007-04-14 13:01:31 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDCtrl *s = opaque;
|
2007-04-14 13:01:31 +00:00
|
|
|
|
2009-09-10 01:04:37 +00:00
|
|
|
SET_CUR_DRV(s, s->dor_vmstate & FD_DOR_SELMASK);
|
|
|
|
s->dor = s->dor_vmstate & ~FD_DOR_SELMASK;
|
2015-05-21 13:19:33 +00:00
|
|
|
|
|
|
|
if (s->phase == FD_PHASE_RECONSTRUCT) {
|
|
|
|
s->phase = reconstruct_phase(s);
|
|
|
|
}
|
|
|
|
|
2007-04-14 13:01:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-08-28 11:18:41 +00:00
|
|
|
static bool fdc_reset_sensei_needed(void *opaque)
|
|
|
|
{
|
|
|
|
FDCtrl *s = opaque;
|
|
|
|
|
|
|
|
return s->reset_sensei != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_fdc_reset_sensei = {
|
|
|
|
.name = "fdc/reset_sensei",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 12:09:54 +00:00
|
|
|
.needed = fdc_reset_sensei_needed,
|
2014-08-28 11:18:41 +00:00
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_INT32(reset_sensei, FDCtrl),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool fdc_result_timer_needed(void *opaque)
|
|
|
|
{
|
|
|
|
FDCtrl *s = opaque;
|
|
|
|
|
|
|
|
return timer_pending(s->result_timer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_fdc_result_timer = {
|
|
|
|
.name = "fdc/result_timer",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 12:09:54 +00:00
|
|
|
.needed = fdc_result_timer_needed,
|
2014-08-28 11:18:41 +00:00
|
|
|
.fields = (VMStateField[]) {
|
2015-01-08 09:18:59 +00:00
|
|
|
VMSTATE_TIMER_PTR(result_timer, FDCtrl),
|
2014-08-28 11:18:41 +00:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-21 13:19:33 +00:00
|
|
|
static bool fdc_phase_needed(void *opaque)
|
|
|
|
{
|
|
|
|
FDCtrl *fdctrl = opaque;
|
|
|
|
|
|
|
|
return reconstruct_phase(fdctrl) != fdctrl->phase;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_fdc_phase = {
|
|
|
|
.name = "fdc/phase",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-09-23 12:09:54 +00:00
|
|
|
.needed = fdc_phase_needed,
|
2015-05-21 13:19:33 +00:00
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT8(phase, FDCtrl),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-14 19:32:17 +00:00
|
|
|
const VMStateDescription vmstate_fdc = {
|
2009-12-15 13:34:34 +00:00
|
|
|
.name = "fdc",
|
2009-09-10 01:04:37 +00:00
|
|
|
.version_id = 2,
|
|
|
|
.minimum_version_id = 2,
|
|
|
|
.pre_save = fdc_pre_save,
|
2015-05-21 13:19:33 +00:00
|
|
|
.pre_load = fdc_pre_load,
|
2009-09-10 01:04:37 +00:00
|
|
|
.post_load = fdc_post_load,
|
2014-04-16 13:32:32 +00:00
|
|
|
.fields = (VMStateField[]) {
|
2009-09-10 01:04:37 +00:00
|
|
|
/* Controller State */
|
2010-02-07 09:01:18 +00:00
|
|
|
VMSTATE_UINT8(sra, FDCtrl),
|
|
|
|
VMSTATE_UINT8(srb, FDCtrl),
|
|
|
|
VMSTATE_UINT8(dor_vmstate, FDCtrl),
|
|
|
|
VMSTATE_UINT8(tdr, FDCtrl),
|
|
|
|
VMSTATE_UINT8(dsr, FDCtrl),
|
|
|
|
VMSTATE_UINT8(msr, FDCtrl),
|
|
|
|
VMSTATE_UINT8(status0, FDCtrl),
|
|
|
|
VMSTATE_UINT8(status1, FDCtrl),
|
|
|
|
VMSTATE_UINT8(status2, FDCtrl),
|
2009-09-10 01:04:37 +00:00
|
|
|
/* Command FIFO */
|
2010-03-21 12:30:46 +00:00
|
|
|
VMSTATE_VARRAY_INT32(fifo, FDCtrl, fifo_size, 0, vmstate_info_uint8,
|
|
|
|
uint8_t),
|
2010-02-07 09:01:18 +00:00
|
|
|
VMSTATE_UINT32(data_pos, FDCtrl),
|
|
|
|
VMSTATE_UINT32(data_len, FDCtrl),
|
|
|
|
VMSTATE_UINT8(data_state, FDCtrl),
|
|
|
|
VMSTATE_UINT8(data_dir, FDCtrl),
|
|
|
|
VMSTATE_UINT8(eot, FDCtrl),
|
2009-09-10 01:04:37 +00:00
|
|
|
/* States kept only to be returned back */
|
2010-02-07 09:01:18 +00:00
|
|
|
VMSTATE_UINT8(timer0, FDCtrl),
|
|
|
|
VMSTATE_UINT8(timer1, FDCtrl),
|
|
|
|
VMSTATE_UINT8(precomp_trk, FDCtrl),
|
|
|
|
VMSTATE_UINT8(config, FDCtrl),
|
|
|
|
VMSTATE_UINT8(lock, FDCtrl),
|
|
|
|
VMSTATE_UINT8(pwrd, FDCtrl),
|
2017-06-23 14:48:23 +00:00
|
|
|
VMSTATE_UINT8_EQUAL(num_floppies, FDCtrl, NULL),
|
2010-02-07 09:01:18 +00:00
|
|
|
VMSTATE_STRUCT_ARRAY(drives, FDCtrl, MAX_FD, 1,
|
|
|
|
vmstate_fdrive, FDrive),
|
2009-09-10 01:04:37 +00:00
|
|
|
VMSTATE_END_OF_LIST()
|
2014-08-28 11:18:41 +00:00
|
|
|
},
|
2014-09-23 12:09:54 +00:00
|
|
|
.subsections = (const VMStateDescription*[]) {
|
|
|
|
&vmstate_fdc_reset_sensei,
|
|
|
|
&vmstate_fdc_result_timer,
|
|
|
|
&vmstate_fdc_phase,
|
|
|
|
NULL
|
2008-04-29 16:18:26 +00:00
|
|
|
}
|
2009-09-10 01:04:37 +00:00
|
|
|
};
|
2007-04-14 13:01:31 +00:00
|
|
|
|
2004-01-05 00:09:06 +00:00
|
|
|
/* Change IRQ state */
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_reset_irq(FDCtrl *fdctrl)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
2012-08-19 08:21:14 +00:00
|
|
|
fdctrl->status0 = 0;
|
2008-04-29 16:14:15 +00:00
|
|
|
if (!(fdctrl->sra & FD_SRA_INTPEND))
|
|
|
|
return;
|
2004-05-08 13:14:18 +00:00
|
|
|
FLOPPY_DPRINTF("Reset interrupt\n");
|
2007-04-07 18:14:41 +00:00
|
|
|
qemu_set_irq(fdctrl->irq, 0);
|
2008-04-29 16:14:15 +00:00
|
|
|
fdctrl->sra &= ~FD_SRA_INTPEND;
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
|
2012-08-19 08:21:14 +00:00
|
|
|
static void fdctrl_raise_irq(FDCtrl *fdctrl)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
2008-04-29 16:14:15 +00:00
|
|
|
if (!(fdctrl->sra & FD_SRA_INTPEND)) {
|
2007-04-07 18:14:41 +00:00
|
|
|
qemu_set_irq(fdctrl->irq, 1);
|
2008-04-29 16:14:15 +00:00
|
|
|
fdctrl->sra |= FD_SRA_INTPEND;
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
2012-05-05 17:43:28 +00:00
|
|
|
|
2009-01-24 12:09:52 +00:00
|
|
|
fdctrl->reset_sensei = 0;
|
2008-04-29 16:17:08 +00:00
|
|
|
FLOPPY_DPRINTF("Set interrupt status to 0x%02x\n", fdctrl->status0);
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
|
2004-10-09 16:44:33 +00:00
|
|
|
/* Reset controller */
|
2021-06-14 19:32:17 +00:00
|
|
|
void fdctrl_reset(FDCtrl *fdctrl, int do_irq)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2004-10-09 16:44:33 +00:00
|
|
|
FLOPPY_DPRINTF("reset controller\n");
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl_reset_irq(fdctrl);
|
2004-10-09 16:44:33 +00:00
|
|
|
/* Initialise controller */
|
2008-04-29 16:14:15 +00:00
|
|
|
fdctrl->sra = 0;
|
|
|
|
fdctrl->srb = 0xc0;
|
2014-10-07 11:59:18 +00:00
|
|
|
if (!fdctrl->drives[1].blk) {
|
2008-04-29 16:14:15 +00:00
|
|
|
fdctrl->sra |= FD_SRA_nDRV2;
|
2014-10-07 11:59:18 +00:00
|
|
|
}
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl->cur_drv = 0;
|
2008-04-29 16:15:53 +00:00
|
|
|
fdctrl->dor = FD_DOR_nRESET;
|
2008-04-29 16:15:12 +00:00
|
|
|
fdctrl->dor |= (fdctrl->dma_chann != -1) ? FD_DOR_DMAEN : 0;
|
2008-04-29 16:16:30 +00:00
|
|
|
fdctrl->msr = FD_MSR_RQM;
|
2014-08-28 11:18:41 +00:00
|
|
|
fdctrl->reset_sensei = 0;
|
|
|
|
timer_del(fdctrl->result_timer);
|
2004-01-05 00:09:06 +00:00
|
|
|
/* FIFO state */
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl->data_pos = 0;
|
|
|
|
fdctrl->data_len = 0;
|
2008-04-29 16:16:30 +00:00
|
|
|
fdctrl->data_state = 0;
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl->data_dir = FD_DIR_WRITE;
|
2004-01-05 00:09:06 +00:00
|
|
|
for (i = 0; i < MAX_FD; i++)
|
2008-04-29 16:15:53 +00:00
|
|
|
fd_recalibrate(&fdctrl->drives[i]);
|
2015-05-21 13:19:31 +00:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2008-04-29 16:17:08 +00:00
|
|
|
if (do_irq) {
|
2012-08-19 08:21:14 +00:00
|
|
|
fdctrl->status0 |= FD_SR0_RDYCHG;
|
|
|
|
fdctrl_raise_irq(fdctrl);
|
2009-01-24 12:09:52 +00:00
|
|
|
fdctrl->reset_sensei = FD_RESET_SENSEI_COUNT;
|
2008-04-29 16:17:08 +00:00
|
|
|
}
|
2004-03-19 23:05:34 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static inline FDrive *drv0(FDCtrl *fdctrl)
|
2004-03-19 23:05:34 +00:00
|
|
|
{
|
2008-04-29 16:17:42 +00:00
|
|
|
return &fdctrl->drives[(fdctrl->tdr & FD_TDR_BOOTSEL) >> 2];
|
2004-03-19 23:05:34 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static inline FDrive *drv1(FDCtrl *fdctrl)
|
2004-03-19 23:05:34 +00:00
|
|
|
{
|
2008-04-29 16:17:42 +00:00
|
|
|
if ((fdctrl->tdr & FD_TDR_BOOTSEL) < (1 << 2))
|
|
|
|
return &fdctrl->drives[1];
|
|
|
|
else
|
|
|
|
return &fdctrl->drives[0];
|
2004-03-19 23:05:34 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 16:18:26 +00:00
|
|
|
#if MAX_FD == 4
|
2010-02-07 09:01:18 +00:00
|
|
|
static inline FDrive *drv2(FDCtrl *fdctrl)
|
2008-04-29 16:18:26 +00:00
|
|
|
{
|
|
|
|
if ((fdctrl->tdr & FD_TDR_BOOTSEL) < (2 << 2))
|
|
|
|
return &fdctrl->drives[2];
|
|
|
|
else
|
|
|
|
return &fdctrl->drives[1];
|
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static inline FDrive *drv3(FDCtrl *fdctrl)
|
2008-04-29 16:18:26 +00:00
|
|
|
{
|
|
|
|
if ((fdctrl->tdr & FD_TDR_BOOTSEL) < (3 << 2))
|
|
|
|
return &fdctrl->drives[3];
|
|
|
|
else
|
|
|
|
return &fdctrl->drives[2];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-10-27 20:29:13 +00:00
|
|
|
static FDrive *get_drv(FDCtrl *fdctrl, int unit)
|
2004-03-19 23:05:34 +00:00
|
|
|
{
|
2016-10-27 20:29:13 +00:00
|
|
|
switch (unit) {
|
2008-04-29 16:18:26 +00:00
|
|
|
case 0: return drv0(fdctrl);
|
|
|
|
case 1: return drv1(fdctrl);
|
|
|
|
#if MAX_FD == 4
|
|
|
|
case 2: return drv2(fdctrl);
|
|
|
|
case 3: return drv3(fdctrl);
|
|
|
|
#endif
|
|
|
|
default: return NULL;
|
|
|
|
}
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
|
2016-10-27 20:29:13 +00:00
|
|
|
static FDrive *get_cur_drv(FDCtrl *fdctrl)
|
|
|
|
{
|
2021-11-24 16:15:35 +00:00
|
|
|
FDrive *cur_drv = get_drv(fdctrl, fdctrl->cur_drv);
|
|
|
|
|
|
|
|
if (!cur_drv->blk) {
|
|
|
|
/*
|
|
|
|
* Kludge: empty drive line selected. Create an anonymous
|
|
|
|
* BlockBackend to avoid NULL deref with various BlockBackend
|
|
|
|
* API calls within this model (CVE-2021-20196).
|
|
|
|
* Due to the controller QOM model limitations, we don't
|
|
|
|
* attach the created to the controller device.
|
|
|
|
*/
|
|
|
|
cur_drv->blk = blk_create_empty_drive();
|
|
|
|
}
|
|
|
|
return cur_drv;
|
2016-10-27 20:29:13 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 16:14:15 +00:00
|
|
|
/* Status A register : 0x00 (read-only) */
|
2010-02-07 09:01:18 +00:00
|
|
|
static uint32_t fdctrl_read_statusA(FDCtrl *fdctrl)
|
2008-04-29 16:14:15 +00:00
|
|
|
{
|
|
|
|
uint32_t retval = fdctrl->sra;
|
|
|
|
|
|
|
|
FLOPPY_DPRINTF("status register A: 0x%02x\n", retval);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2004-01-05 00:09:06 +00:00
|
|
|
/* Status B register : 0x01 (read-only) */
|
2010-02-07 09:01:18 +00:00
|
|
|
static uint32_t fdctrl_read_statusB(FDCtrl *fdctrl)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
2008-04-29 16:14:15 +00:00
|
|
|
uint32_t retval = fdctrl->srb;
|
|
|
|
|
|
|
|
FLOPPY_DPRINTF("status register B: 0x%02x\n", retval);
|
|
|
|
|
|
|
|
return retval;
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Digital output register : 0x02 */
|
2010-02-07 09:01:18 +00:00
|
|
|
static uint32_t fdctrl_read_dor(FDCtrl *fdctrl)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
2008-04-29 16:15:53 +00:00
|
|
|
uint32_t retval = fdctrl->dor;
|
2004-01-05 00:09:06 +00:00
|
|
|
|
|
|
|
/* Selected drive */
|
2004-03-19 23:05:34 +00:00
|
|
|
retval |= fdctrl->cur_drv;
|
2004-01-05 00:09:06 +00:00
|
|
|
FLOPPY_DPRINTF("digital output register: 0x%02x\n", retval);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_write_dor(FDCtrl *fdctrl, uint32_t value)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
|
|
|
FLOPPY_DPRINTF("digital output register set to 0x%02x\n", value);
|
2008-04-29 16:14:15 +00:00
|
|
|
|
|
|
|
/* Motors */
|
|
|
|
if (value & FD_DOR_MOTEN0)
|
|
|
|
fdctrl->srb |= FD_SRB_MTR0;
|
|
|
|
else
|
|
|
|
fdctrl->srb &= ~FD_SRB_MTR0;
|
|
|
|
if (value & FD_DOR_MOTEN1)
|
|
|
|
fdctrl->srb |= FD_SRB_MTR1;
|
|
|
|
else
|
|
|
|
fdctrl->srb &= ~FD_SRB_MTR1;
|
|
|
|
|
|
|
|
/* Drive */
|
|
|
|
if (value & 1)
|
|
|
|
fdctrl->srb |= FD_SRB_DR0;
|
|
|
|
else
|
|
|
|
fdctrl->srb &= ~FD_SRB_DR0;
|
|
|
|
|
2004-01-05 00:09:06 +00:00
|
|
|
/* Reset */
|
2008-02-29 19:24:00 +00:00
|
|
|
if (!(value & FD_DOR_nRESET)) {
|
2008-04-29 16:15:53 +00:00
|
|
|
if (fdctrl->dor & FD_DOR_nRESET) {
|
2004-10-09 16:44:33 +00:00
|
|
|
FLOPPY_DPRINTF("controller enter RESET state\n");
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
2008-04-29 16:15:53 +00:00
|
|
|
if (!(fdctrl->dor & FD_DOR_nRESET)) {
|
2004-10-09 16:44:33 +00:00
|
|
|
FLOPPY_DPRINTF("controller out of RESET state\n");
|
2004-05-04 02:04:17 +00:00
|
|
|
fdctrl_reset(fdctrl, 1);
|
2008-04-29 16:16:30 +00:00
|
|
|
fdctrl->dsr &= ~FD_DSR_PWRDOWN;
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Selected drive */
|
2008-02-29 19:24:00 +00:00
|
|
|
fdctrl->cur_drv = value & FD_DOR_SELMASK;
|
2008-04-29 16:15:12 +00:00
|
|
|
|
|
|
|
fdctrl->dor = value;
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Tape drive register : 0x03 */
|
2010-02-07 09:01:18 +00:00
|
|
|
static uint32_t fdctrl_read_tape(FDCtrl *fdctrl)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
2008-04-29 16:17:42 +00:00
|
|
|
uint32_t retval = fdctrl->tdr;
|
2004-01-05 00:09:06 +00:00
|
|
|
|
|
|
|
FLOPPY_DPRINTF("tape drive register: 0x%02x\n", retval);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_write_tape(FDCtrl *fdctrl, uint32_t value)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
|
|
|
/* Reset mode */
|
2008-04-29 16:15:53 +00:00
|
|
|
if (!(fdctrl->dor & FD_DOR_nRESET)) {
|
2004-10-09 16:44:33 +00:00
|
|
|
FLOPPY_DPRINTF("Floppy controller in RESET state !\n");
|
2004-01-05 00:09:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
FLOPPY_DPRINTF("tape drive register set to 0x%02x\n", value);
|
|
|
|
/* Disk boot selection indicator */
|
2008-04-29 16:17:42 +00:00
|
|
|
fdctrl->tdr = value & FD_TDR_BOOTSEL;
|
2004-01-05 00:09:06 +00:00
|
|
|
/* Tape indicators: never allow */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Main status register : 0x04 (read) */
|
2010-02-07 09:01:18 +00:00
|
|
|
static uint32_t fdctrl_read_main_status(FDCtrl *fdctrl)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
2008-04-29 16:16:30 +00:00
|
|
|
uint32_t retval = fdctrl->msr;
|
2004-01-05 00:09:06 +00:00
|
|
|
|
2008-04-29 16:16:30 +00:00
|
|
|
fdctrl->dsr &= ~FD_DSR_PWRDOWN;
|
2008-04-29 16:15:53 +00:00
|
|
|
fdctrl->dor |= FD_DOR_nRESET;
|
2008-04-29 16:16:30 +00:00
|
|
|
|
2004-01-05 00:09:06 +00:00
|
|
|
FLOPPY_DPRINTF("main status register: 0x%02x\n", retval);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Data select rate register : 0x04 (write) */
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_write_rate(FDCtrl *fdctrl, uint32_t value)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
|
|
|
/* Reset mode */
|
2008-04-29 16:15:53 +00:00
|
|
|
if (!(fdctrl->dor & FD_DOR_nRESET)) {
|
2007-11-05 03:11:37 +00:00
|
|
|
FLOPPY_DPRINTF("Floppy controller in RESET state !\n");
|
|
|
|
return;
|
|
|
|
}
|
2004-01-05 00:09:06 +00:00
|
|
|
FLOPPY_DPRINTF("select rate register set to 0x%02x\n", value);
|
|
|
|
/* Reset: autoclear */
|
2008-02-29 19:24:00 +00:00
|
|
|
if (value & FD_DSR_SWRESET) {
|
2008-04-29 16:15:53 +00:00
|
|
|
fdctrl->dor &= ~FD_DOR_nRESET;
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl_reset(fdctrl, 1);
|
2008-04-29 16:15:53 +00:00
|
|
|
fdctrl->dor |= FD_DOR_nRESET;
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
2008-02-29 19:24:00 +00:00
|
|
|
if (value & FD_DSR_PWRDOWN) {
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl_reset(fdctrl, 1);
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
2008-04-29 16:16:30 +00:00
|
|
|
fdctrl->dsr = value;
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
|
2012-02-06 21:29:06 +00:00
|
|
|
/* Configuration control register: 0x07 (write) */
|
|
|
|
static void fdctrl_write_ccr(FDCtrl *fdctrl, uint32_t value)
|
|
|
|
{
|
|
|
|
/* Reset mode */
|
|
|
|
if (!(fdctrl->dor & FD_DOR_nRESET)) {
|
|
|
|
FLOPPY_DPRINTF("Floppy controller in RESET state !\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
FLOPPY_DPRINTF("configuration control register set to 0x%02x\n", value);
|
|
|
|
|
|
|
|
/* Only the rate selection bits used in AT mode, and we
|
|
|
|
* store those in the DSR.
|
|
|
|
*/
|
|
|
|
fdctrl->dsr = (fdctrl->dsr & ~FD_DSR_DRATEMASK) |
|
|
|
|
(value & FD_DSR_DRATEMASK);
|
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static int fdctrl_media_changed(FDrive *drv)
|
2006-08-19 11:43:22 +00:00
|
|
|
{
|
2012-05-05 17:43:28 +00:00
|
|
|
return drv->media_changed;
|
2006-08-19 11:43:22 +00:00
|
|
|
}
|
|
|
|
|
2004-01-05 00:09:06 +00:00
|
|
|
/* Digital input register : 0x07 (read-only) */
|
2010-02-07 09:01:18 +00:00
|
|
|
static uint32_t fdctrl_read_dir(FDCtrl *fdctrl)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
|
|
|
uint32_t retval = 0;
|
|
|
|
|
2012-02-06 21:29:12 +00:00
|
|
|
if (fdctrl_media_changed(get_cur_drv(fdctrl))) {
|
2008-02-29 19:24:00 +00:00
|
|
|
retval |= FD_DIR_DSKCHG;
|
2012-02-06 21:29:12 +00:00
|
|
|
}
|
2010-04-18 08:45:03 +00:00
|
|
|
if (retval != 0) {
|
2004-03-19 23:05:34 +00:00
|
|
|
FLOPPY_DPRINTF("Floppy digital input register: 0x%02x\n", retval);
|
2010-04-18 08:45:03 +00:00
|
|
|
}
|
2004-01-05 00:09:06 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2015-05-21 13:19:31 +00:00
|
|
|
/* Clear the FIFO and update the state for receiving the next command */
|
|
|
|
static void fdctrl_to_command_phase(FDCtrl *fdctrl)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
2015-05-21 13:19:33 +00:00
|
|
|
fdctrl->phase = FD_PHASE_COMMAND;
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl->data_dir = FD_DIR_WRITE;
|
|
|
|
fdctrl->data_pos = 0;
|
2015-05-21 13:19:37 +00:00
|
|
|
fdctrl->data_len = 1; /* Accept command byte, adjust for params later */
|
2008-04-29 16:16:30 +00:00
|
|
|
fdctrl->msr &= ~(FD_MSR_CMDBUSY | FD_MSR_DIO);
|
2015-05-21 13:19:37 +00:00
|
|
|
fdctrl->msr |= FD_MSR_RQM;
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
|
2015-05-21 13:19:32 +00:00
|
|
|
/* Update the state to allow the guest to read out the command status.
|
|
|
|
* @fifo_len is the number of result bytes to be read out. */
|
|
|
|
static void fdctrl_to_result_phase(FDCtrl *fdctrl, int fifo_len)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
2015-05-21 13:19:33 +00:00
|
|
|
fdctrl->phase = FD_PHASE_RESULT;
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl->data_dir = FD_DIR_READ;
|
|
|
|
fdctrl->data_len = fifo_len;
|
|
|
|
fdctrl->data_pos = 0;
|
2008-04-29 16:16:30 +00:00
|
|
|
fdctrl->msr |= FD_MSR_CMDBUSY | FD_MSR_RQM | FD_MSR_DIO;
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set an error: unimplemented/unknown command */
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_unimplemented(FDCtrl *fdctrl, int direction)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
2012-06-03 17:16:14 +00:00
|
|
|
qemu_log_mask(LOG_UNIMP, "fdc: unimplemented command 0x%02x\n",
|
|
|
|
fdctrl->fifo[0]);
|
2008-02-29 19:24:00 +00:00
|
|
|
fdctrl->fifo[0] = FD_SR0_INVCMD;
|
2015-05-21 13:19:32 +00:00
|
|
|
fdctrl_to_result_phase(fdctrl, 1);
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
|
2012-06-22 10:33:54 +00:00
|
|
|
/* Seek to next sector
|
|
|
|
* returns 0 when end of track reached (for DBL_SIDES on head 1)
|
|
|
|
* otherwise returns 1
|
|
|
|
*/
|
2010-02-07 09:01:18 +00:00
|
|
|
static int fdctrl_seek_to_next_sect(FDCtrl *fdctrl, FDrive *cur_drv)
|
2008-04-29 16:13:36 +00:00
|
|
|
{
|
|
|
|
FLOPPY_DPRINTF("seek to next sector (%d %02x %02x => %d)\n",
|
|
|
|
cur_drv->head, cur_drv->track, cur_drv->sect,
|
|
|
|
fd_sector(cur_drv));
|
|
|
|
/* XXX: cur_drv->sect >= cur_drv->last_sect should be an
|
|
|
|
error in fact */
|
2012-06-22 10:33:54 +00:00
|
|
|
uint8_t new_head = cur_drv->head;
|
|
|
|
uint8_t new_track = cur_drv->track;
|
|
|
|
uint8_t new_sect = cur_drv->sect;
|
|
|
|
|
|
|
|
int ret = 1;
|
|
|
|
|
|
|
|
if (new_sect >= cur_drv->last_sect ||
|
|
|
|
new_sect == fdctrl->eot) {
|
|
|
|
new_sect = 1;
|
2008-04-29 16:13:36 +00:00
|
|
|
if (FD_MULTI_TRACK(fdctrl->data_state)) {
|
2012-06-22 10:33:54 +00:00
|
|
|
if (new_head == 0 &&
|
2008-04-29 16:13:36 +00:00
|
|
|
(cur_drv->flags & FDISK_DBL_SIDES) != 0) {
|
2012-06-22 10:33:54 +00:00
|
|
|
new_head = 1;
|
2008-04-29 16:13:36 +00:00
|
|
|
} else {
|
2012-06-22 10:33:54 +00:00
|
|
|
new_head = 0;
|
|
|
|
new_track++;
|
2012-09-20 20:50:17 +00:00
|
|
|
fdctrl->status0 |= FD_SR0_SEEK;
|
2012-06-22 10:33:54 +00:00
|
|
|
if ((cur_drv->flags & FDISK_DBL_SIDES) == 0) {
|
|
|
|
ret = 0;
|
|
|
|
}
|
2008-04-29 16:13:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-09-20 20:50:17 +00:00
|
|
|
fdctrl->status0 |= FD_SR0_SEEK;
|
2012-06-22 10:33:54 +00:00
|
|
|
new_track++;
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
if (ret == 1) {
|
|
|
|
FLOPPY_DPRINTF("seek to next track (%d %02x %02x => %d)\n",
|
|
|
|
new_head, new_track, new_sect, fd_sector(cur_drv));
|
2008-04-29 16:13:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-06-22 10:33:54 +00:00
|
|
|
new_sect++;
|
2008-04-29 16:13:36 +00:00
|
|
|
}
|
2012-06-22 10:33:54 +00:00
|
|
|
fd_seek(cur_drv, new_head, new_track, new_sect, 1);
|
|
|
|
return ret;
|
2008-04-29 16:13:36 +00:00
|
|
|
}
|
|
|
|
|
2004-01-05 00:09:06 +00:00
|
|
|
/* Callback for transfer end (stop or abort) */
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_stop_transfer(FDCtrl *fdctrl, uint8_t status0,
|
|
|
|
uint8_t status1, uint8_t status2)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDrive *cur_drv;
|
2004-03-19 23:05:34 +00:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
2012-09-20 21:07:53 +00:00
|
|
|
|
|
|
|
fdctrl->status0 &= ~(FD_SR0_DS0 | FD_SR0_DS1 | FD_SR0_HEAD);
|
|
|
|
fdctrl->status0 |= GET_CUR_DRV(fdctrl);
|
|
|
|
if (cur_drv->head) {
|
|
|
|
fdctrl->status0 |= FD_SR0_HEAD;
|
|
|
|
}
|
|
|
|
fdctrl->status0 |= status0;
|
2012-06-22 10:33:55 +00:00
|
|
|
|
2004-01-05 00:09:06 +00:00
|
|
|
FLOPPY_DPRINTF("transfer status: %02x %02x %02x (%02x)\n",
|
2012-06-22 10:33:55 +00:00
|
|
|
status0, status1, status2, fdctrl->status0);
|
|
|
|
fdctrl->fifo[0] = fdctrl->status0;
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl->fifo[1] = status1;
|
|
|
|
fdctrl->fifo[2] = status2;
|
|
|
|
fdctrl->fifo[3] = cur_drv->track;
|
|
|
|
fdctrl->fifo[4] = cur_drv->head;
|
|
|
|
fdctrl->fifo[5] = cur_drv->sect;
|
|
|
|
fdctrl->fifo[6] = FD_SECTOR_SC;
|
|
|
|
fdctrl->data_dir = FD_DIR_READ;
|
2018-11-11 09:40:23 +00:00
|
|
|
if (fdctrl->dma_chann != -1 && !(fdctrl->msr & FD_MSR_NONDMA)) {
|
2016-02-03 16:28:58 +00:00
|
|
|
IsaDmaClass *k = ISADMA_GET_CLASS(fdctrl->dma);
|
|
|
|
k->release_DREQ(fdctrl->dma, fdctrl->dma_chann);
|
2004-05-08 13:14:18 +00:00
|
|
|
}
|
2008-04-29 16:16:30 +00:00
|
|
|
fdctrl->msr |= FD_MSR_RQM | FD_MSR_DIO;
|
2008-04-29 16:15:12 +00:00
|
|
|
fdctrl->msr &= ~FD_MSR_NONDMA;
|
2012-09-03 23:46:54 +00:00
|
|
|
|
2015-05-21 13:19:32 +00:00
|
|
|
fdctrl_to_result_phase(fdctrl, 7);
|
2012-08-19 08:21:14 +00:00
|
|
|
fdctrl_raise_irq(fdctrl);
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Prepare a data transfer (either DMA or FIFO) */
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_start_transfer(FDCtrl *fdctrl, int direction)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDrive *cur_drv;
|
2004-01-05 00:09:06 +00:00
|
|
|
uint8_t kh, kt, ks;
|
|
|
|
|
2008-04-29 16:18:58 +00:00
|
|
|
SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
|
2004-03-19 23:05:34 +00:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
|
|
|
kt = fdctrl->fifo[2];
|
|
|
|
kh = fdctrl->fifo[3];
|
|
|
|
ks = fdctrl->fifo[4];
|
2004-10-09 16:44:33 +00:00
|
|
|
FLOPPY_DPRINTF("Start transfer at %d %d %02x %02x (%d)\n",
|
2008-04-29 16:18:58 +00:00
|
|
|
GET_CUR_DRV(fdctrl), kh, kt, ks,
|
2012-02-06 21:29:02 +00:00
|
|
|
fd_sector_calc(kh, kt, ks, cur_drv->last_sect,
|
|
|
|
NUM_SIDES(cur_drv)));
|
2008-04-29 16:17:08 +00:00
|
|
|
switch (fd_seek(cur_drv, kh, kt, ks, fdctrl->config & FD_CONFIG_EIS)) {
|
2004-01-05 00:09:06 +00:00
|
|
|
case 2:
|
|
|
|
/* sect too big */
|
2008-02-29 19:24:00 +00:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl->fifo[3] = kt;
|
|
|
|
fdctrl->fifo[4] = kh;
|
|
|
|
fdctrl->fifo[5] = ks;
|
2004-01-05 00:09:06 +00:00
|
|
|
return;
|
|
|
|
case 3:
|
|
|
|
/* track too big */
|
2008-04-29 16:17:08 +00:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_EC, 0x00);
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl->fifo[3] = kt;
|
|
|
|
fdctrl->fifo[4] = kh;
|
|
|
|
fdctrl->fifo[5] = ks;
|
2004-01-05 00:09:06 +00:00
|
|
|
return;
|
|
|
|
case 4:
|
|
|
|
/* No seek enabled */
|
2008-02-29 19:24:00 +00:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl->fifo[3] = kt;
|
|
|
|
fdctrl->fifo[4] = kh;
|
|
|
|
fdctrl->fifo[5] = ks;
|
2004-01-05 00:09:06 +00:00
|
|
|
return;
|
|
|
|
case 1:
|
2012-09-20 21:01:58 +00:00
|
|
|
fdctrl->status0 |= FD_SR0_SEEK;
|
2004-01-05 00:09:06 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-04-29 16:16:30 +00:00
|
|
|
|
2012-02-06 21:29:10 +00:00
|
|
|
/* Check the data rate. If the programmed data rate does not match
|
|
|
|
* the currently inserted medium, the operation has to fail. */
|
2021-02-03 17:18:30 +00:00
|
|
|
if ((fdctrl->dsr & FD_DSR_DRATEMASK) != cur_drv->media_rate) {
|
2012-02-06 21:29:10 +00:00
|
|
|
FLOPPY_DPRINTF("data rate mismatch (fdc=%d, media=%d)\n",
|
|
|
|
fdctrl->dsr & FD_DSR_DRATEMASK, cur_drv->media_rate);
|
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_MA, 0x00);
|
|
|
|
fdctrl->fifo[3] = kt;
|
|
|
|
fdctrl->fifo[4] = kh;
|
|
|
|
fdctrl->fifo[5] = ks;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-01-05 00:09:06 +00:00
|
|
|
/* Set the FIFO state */
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl->data_dir = direction;
|
|
|
|
fdctrl->data_pos = 0;
|
2012-08-19 20:04:43 +00:00
|
|
|
assert(fdctrl->msr & FD_MSR_CMDBUSY);
|
2004-03-19 23:05:34 +00:00
|
|
|
if (fdctrl->fifo[0] & 0x80)
|
|
|
|
fdctrl->data_state |= FD_STATE_MULTI;
|
|
|
|
else
|
|
|
|
fdctrl->data_state &= ~FD_STATE_MULTI;
|
2012-08-20 11:50:34 +00:00
|
|
|
if (fdctrl->fifo[5] == 0) {
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl->data_len = fdctrl->fifo[8];
|
|
|
|
} else {
|
2007-11-05 03:11:37 +00:00
|
|
|
int tmp;
|
2006-12-10 23:07:39 +00:00
|
|
|
fdctrl->data_len = 128 << (fdctrl->fifo[5] > 7 ? 7 : fdctrl->fifo[5]);
|
2008-05-01 19:05:12 +00:00
|
|
|
tmp = (fdctrl->fifo[6] - ks + 1);
|
2004-03-19 23:05:34 +00:00
|
|
|
if (fdctrl->fifo[0] & 0x80)
|
2008-05-01 19:05:12 +00:00
|
|
|
tmp += fdctrl->fifo[6];
|
2007-11-05 03:11:37 +00:00
|
|
|
fdctrl->data_len *= tmp;
|
2004-03-19 23:05:34 +00:00
|
|
|
}
|
2004-10-07 23:10:29 +00:00
|
|
|
fdctrl->eot = fdctrl->fifo[6];
|
2008-04-29 16:15:12 +00:00
|
|
|
if (fdctrl->dor & FD_DOR_DMAEN) {
|
2019-11-01 16:55:13 +00:00
|
|
|
/* DMA transfer is enabled. */
|
2016-02-03 16:28:58 +00:00
|
|
|
IsaDmaClass *k = ISADMA_GET_CLASS(fdctrl->dma);
|
2019-11-01 16:55:13 +00:00
|
|
|
|
|
|
|
FLOPPY_DPRINTF("direction=%d (%d - %d)\n",
|
|
|
|
direction, (128 << fdctrl->fifo[5]) *
|
2007-11-05 03:11:37 +00:00
|
|
|
(cur_drv->last_sect - ks + 1), fdctrl->data_len);
|
2019-11-01 16:55:13 +00:00
|
|
|
|
|
|
|
/* No access is allowed until DMA transfer has completed */
|
|
|
|
fdctrl->msr &= ~FD_MSR_RQM;
|
|
|
|
if (direction != FD_DIR_VERIFY) {
|
|
|
|
/*
|
|
|
|
* Now, we just have to wait for the DMA controller to
|
|
|
|
* recall us...
|
|
|
|
*/
|
|
|
|
k->hold_DREQ(fdctrl->dma, fdctrl->dma_chann);
|
|
|
|
k->schedule(fdctrl->dma);
|
2004-03-19 23:05:34 +00:00
|
|
|
} else {
|
2019-11-01 16:55:13 +00:00
|
|
|
/* Start transfer */
|
|
|
|
fdctrl_transfer_handler(fdctrl, fdctrl->dma_chann, 0,
|
|
|
|
fdctrl->data_len);
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
2019-11-01 16:55:13 +00:00
|
|
|
return;
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
FLOPPY_DPRINTF("start non-DMA transfer\n");
|
2015-05-21 13:19:37 +00:00
|
|
|
fdctrl->msr |= FD_MSR_NONDMA | FD_MSR_RQM;
|
2008-04-29 16:16:30 +00:00
|
|
|
if (direction != FD_DIR_WRITE)
|
|
|
|
fdctrl->msr |= FD_MSR_DIO;
|
2004-01-05 00:09:06 +00:00
|
|
|
/* IO based transfer: calculate len */
|
2012-08-19 08:21:14 +00:00
|
|
|
fdctrl_raise_irq(fdctrl);
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Prepare a transfer of deleted data */
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_start_transfer_del(FDCtrl *fdctrl, int direction)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
2012-06-03 17:16:14 +00:00
|
|
|
qemu_log_mask(LOG_UNIMP, "fdctrl_start_transfer_del() unimplemented\n");
|
2008-04-29 16:17:08 +00:00
|
|
|
|
2004-01-05 00:09:06 +00:00
|
|
|
/* We don't handle deleted data,
|
|
|
|
* so we don't return *ANYTHING*
|
|
|
|
*/
|
2008-02-29 19:24:00 +00:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* handlers for DMA transfers */
|
2021-06-14 19:32:17 +00:00
|
|
|
int fdctrl_transfer_handler(void *opaque, int nchan, int dma_pos, int dma_len)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDCtrl *fdctrl;
|
|
|
|
FDrive *cur_drv;
|
2004-03-19 23:05:34 +00:00
|
|
|
int len, start_pos, rel_pos;
|
2004-01-05 00:09:06 +00:00
|
|
|
uint8_t status0 = 0x00, status1 = 0x00, status2 = 0x00;
|
2016-02-03 16:28:58 +00:00
|
|
|
IsaDmaClass *k;
|
2004-01-05 00:09:06 +00:00
|
|
|
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl = opaque;
|
2008-04-29 16:16:30 +00:00
|
|
|
if (fdctrl->msr & FD_MSR_RQM) {
|
2004-01-05 00:09:06 +00:00
|
|
|
FLOPPY_DPRINTF("Not in DMA transfer mode !\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2016-02-03 16:28:58 +00:00
|
|
|
k = ISADMA_GET_CLASS(fdctrl->dma);
|
2004-03-19 23:05:34 +00:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
|
|
|
if (fdctrl->data_dir == FD_DIR_SCANE || fdctrl->data_dir == FD_DIR_SCANL ||
|
|
|
|
fdctrl->data_dir == FD_DIR_SCANH)
|
2008-04-29 16:17:08 +00:00
|
|
|
status2 = FD_SR2_SNS;
|
2004-11-07 18:04:02 +00:00
|
|
|
if (dma_len > fdctrl->data_len)
|
|
|
|
dma_len = fdctrl->data_len;
|
2014-10-07 11:59:18 +00:00
|
|
|
if (cur_drv->blk == NULL) {
|
2007-11-05 03:11:37 +00:00
|
|
|
if (fdctrl->data_dir == FD_DIR_WRITE)
|
2008-02-29 19:24:00 +00:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
|
2007-11-05 03:11:37 +00:00
|
|
|
else
|
2008-02-29 19:24:00 +00:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
|
2007-11-05 03:11:37 +00:00
|
|
|
len = 0;
|
2004-10-07 23:10:29 +00:00
|
|
|
goto transfer_error;
|
|
|
|
}
|
2004-03-19 23:05:34 +00:00
|
|
|
rel_pos = fdctrl->data_pos % FD_SECTOR_LEN;
|
2004-11-07 18:04:02 +00:00
|
|
|
for (start_pos = fdctrl->data_pos; fdctrl->data_pos < dma_len;) {
|
|
|
|
len = dma_len - fdctrl->data_pos;
|
2004-03-19 23:05:34 +00:00
|
|
|
if (len + rel_pos > FD_SECTOR_LEN)
|
|
|
|
len = FD_SECTOR_LEN - rel_pos;
|
2005-03-13 09:43:36 +00:00
|
|
|
FLOPPY_DPRINTF("copy %d bytes (%d %d %d) %d pos %d %02x "
|
|
|
|
"(%d-0x%08x 0x%08x)\n", len, dma_len, fdctrl->data_pos,
|
2008-04-29 16:18:58 +00:00
|
|
|
fdctrl->data_len, GET_CUR_DRV(fdctrl), cur_drv->head,
|
2004-03-19 23:05:34 +00:00
|
|
|
cur_drv->track, cur_drv->sect, fd_sector(cur_drv),
|
2008-02-29 19:24:00 +00:00
|
|
|
fd_sector(cur_drv) * FD_SECTOR_LEN);
|
2004-03-19 23:05:34 +00:00
|
|
|
if (fdctrl->data_dir != FD_DIR_WRITE ||
|
2007-11-05 03:11:37 +00:00
|
|
|
len < FD_SECTOR_LEN || rel_pos != 0) {
|
2004-03-19 23:05:34 +00:00
|
|
|
/* READ & SCAN commands and realign to a sector for WRITE */
|
2016-05-06 16:26:35 +00:00
|
|
|
if (blk_pread(cur_drv->blk, fd_offset(cur_drv),
|
|
|
|
fdctrl->fifo, BDRV_SECTOR_SIZE) < 0) {
|
2004-01-05 00:09:06 +00:00
|
|
|
FLOPPY_DPRINTF("Floppy: error getting sector %d\n",
|
|
|
|
fd_sector(cur_drv));
|
|
|
|
/* Sure, image size is too small... */
|
2004-03-19 23:05:34 +00:00
|
|
|
memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
2004-10-07 23:10:29 +00:00
|
|
|
}
|
2007-11-05 03:11:37 +00:00
|
|
|
switch (fdctrl->data_dir) {
|
|
|
|
case FD_DIR_READ:
|
|
|
|
/* READ commands */
|
2016-02-03 16:28:58 +00:00
|
|
|
k->write_memory(fdctrl->dma, nchan, fdctrl->fifo + rel_pos,
|
|
|
|
fdctrl->data_pos, len);
|
2007-11-05 03:11:37 +00:00
|
|
|
break;
|
|
|
|
case FD_DIR_WRITE:
|
2004-03-19 23:05:34 +00:00
|
|
|
/* WRITE commands */
|
2012-02-06 21:29:05 +00:00
|
|
|
if (cur_drv->ro) {
|
|
|
|
/* Handle readonly medium early, no need to do DMA, touch the
|
|
|
|
* LED or attempt any writes. A real floppy doesn't attempt
|
|
|
|
* to write to readonly media either. */
|
|
|
|
fdctrl_stop_transfer(fdctrl,
|
|
|
|
FD_SR0_ABNTERM | FD_SR0_SEEK, FD_SR1_NW,
|
|
|
|
0x00);
|
|
|
|
goto transfer_error;
|
|
|
|
}
|
|
|
|
|
2016-02-03 16:28:58 +00:00
|
|
|
k->read_memory(fdctrl->dma, nchan, fdctrl->fifo + rel_pos,
|
|
|
|
fdctrl->data_pos, len);
|
2016-05-06 16:26:35 +00:00
|
|
|
if (blk_pwrite(cur_drv->blk, fd_offset(cur_drv),
|
|
|
|
fdctrl->fifo, BDRV_SECTOR_SIZE, 0) < 0) {
|
2012-06-03 17:16:14 +00:00
|
|
|
FLOPPY_DPRINTF("error writing sector %d\n",
|
|
|
|
fd_sector(cur_drv));
|
2008-02-29 19:24:00 +00:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
|
2004-03-19 23:05:34 +00:00
|
|
|
goto transfer_error;
|
2004-10-07 23:10:29 +00:00
|
|
|
}
|
2007-11-05 03:11:37 +00:00
|
|
|
break;
|
2012-09-18 21:04:10 +00:00
|
|
|
case FD_DIR_VERIFY:
|
|
|
|
/* VERIFY commands */
|
|
|
|
break;
|
2007-11-05 03:11:37 +00:00
|
|
|
default:
|
|
|
|
/* SCAN commands */
|
2004-03-19 23:05:34 +00:00
|
|
|
{
|
2007-11-05 03:11:37 +00:00
|
|
|
uint8_t tmpbuf[FD_SECTOR_LEN];
|
2004-03-19 23:05:34 +00:00
|
|
|
int ret;
|
2016-02-03 16:28:58 +00:00
|
|
|
k->read_memory(fdctrl->dma, nchan, tmpbuf, fdctrl->data_pos,
|
|
|
|
len);
|
2004-03-19 23:05:34 +00:00
|
|
|
ret = memcmp(tmpbuf, fdctrl->fifo + rel_pos, len);
|
2004-01-05 00:09:06 +00:00
|
|
|
if (ret == 0) {
|
2008-04-29 16:17:08 +00:00
|
|
|
status2 = FD_SR2_SEH;
|
2004-01-05 00:09:06 +00:00
|
|
|
goto end_transfer;
|
|
|
|
}
|
2004-03-19 23:05:34 +00:00
|
|
|
if ((ret < 0 && fdctrl->data_dir == FD_DIR_SCANL) ||
|
|
|
|
(ret > 0 && fdctrl->data_dir == FD_DIR_SCANH)) {
|
2004-01-05 00:09:06 +00:00
|
|
|
status2 = 0x00;
|
|
|
|
goto end_transfer;
|
|
|
|
}
|
|
|
|
}
|
2007-11-05 03:11:37 +00:00
|
|
|
break;
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
2007-11-05 03:11:37 +00:00
|
|
|
fdctrl->data_pos += len;
|
|
|
|
rel_pos = fdctrl->data_pos % FD_SECTOR_LEN;
|
2004-03-19 23:05:34 +00:00
|
|
|
if (rel_pos == 0) {
|
2004-01-05 00:09:06 +00:00
|
|
|
/* Seek to next sector */
|
2008-04-29 16:13:36 +00:00
|
|
|
if (!fdctrl_seek_to_next_sect(fdctrl, cur_drv))
|
|
|
|
break;
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-05 03:11:37 +00:00
|
|
|
end_transfer:
|
2004-03-19 23:05:34 +00:00
|
|
|
len = fdctrl->data_pos - start_pos;
|
|
|
|
FLOPPY_DPRINTF("end transfer %d %d %d\n",
|
2007-11-05 03:11:37 +00:00
|
|
|
fdctrl->data_pos, len, fdctrl->data_len);
|
2004-03-19 23:05:34 +00:00
|
|
|
if (fdctrl->data_dir == FD_DIR_SCANE ||
|
|
|
|
fdctrl->data_dir == FD_DIR_SCANL ||
|
|
|
|
fdctrl->data_dir == FD_DIR_SCANH)
|
2008-04-29 16:17:08 +00:00
|
|
|
status2 = FD_SR2_SEH;
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl->data_len -= len;
|
2004-10-07 23:10:29 +00:00
|
|
|
fdctrl_stop_transfer(fdctrl, status0, status1, status2);
|
2007-11-05 03:11:37 +00:00
|
|
|
transfer_error:
|
2004-01-05 00:09:06 +00:00
|
|
|
|
2004-03-19 23:05:34 +00:00
|
|
|
return len;
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Data register : 0x05 */
|
2010-02-07 09:01:18 +00:00
|
|
|
static uint32_t fdctrl_read_data(FDCtrl *fdctrl)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDrive *cur_drv;
|
2004-01-05 00:09:06 +00:00
|
|
|
uint32_t retval = 0;
|
2015-05-06 07:48:59 +00:00
|
|
|
uint32_t pos;
|
2004-01-05 00:09:06 +00:00
|
|
|
|
2004-03-19 23:05:34 +00:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
2008-04-29 16:16:30 +00:00
|
|
|
fdctrl->dsr &= ~FD_DSR_PWRDOWN;
|
|
|
|
if (!(fdctrl->msr & FD_MSR_RQM) || !(fdctrl->msr & FD_MSR_DIO)) {
|
2012-06-03 17:16:14 +00:00
|
|
|
FLOPPY_DPRINTF("error: controller not ready for reading\n");
|
2004-01-05 00:09:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-05-21 13:19:36 +00:00
|
|
|
|
|
|
|
/* If data_len spans multiple sectors, the current position in the FIFO
|
|
|
|
* wraps around while fdctrl->data_pos is the real position in the whole
|
|
|
|
* request. */
|
2004-03-19 23:05:34 +00:00
|
|
|
pos = fdctrl->data_pos;
|
2015-05-06 07:48:59 +00:00
|
|
|
pos %= FD_SECTOR_LEN;
|
2015-05-21 13:19:36 +00:00
|
|
|
|
|
|
|
switch (fdctrl->phase) {
|
|
|
|
case FD_PHASE_EXECUTION:
|
|
|
|
assert(fdctrl->msr & FD_MSR_NONDMA);
|
2004-01-05 00:09:06 +00:00
|
|
|
if (pos == 0) {
|
2008-04-29 16:13:36 +00:00
|
|
|
if (fdctrl->data_pos != 0)
|
|
|
|
if (!fdctrl_seek_to_next_sect(fdctrl, cur_drv)) {
|
|
|
|
FLOPPY_DPRINTF("error seeking to next sector %d\n",
|
|
|
|
fd_sector(cur_drv));
|
|
|
|
return 0;
|
|
|
|
}
|
2016-05-06 16:26:35 +00:00
|
|
|
if (blk_pread(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo,
|
|
|
|
BDRV_SECTOR_SIZE)
|
2014-10-07 11:59:18 +00:00
|
|
|
< 0) {
|
2008-04-29 16:17:08 +00:00
|
|
|
FLOPPY_DPRINTF("error getting sector %d\n",
|
|
|
|
fd_sector(cur_drv));
|
|
|
|
/* Sure, image size is too small... */
|
|
|
|
memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
|
|
|
|
}
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
2015-05-21 13:19:36 +00:00
|
|
|
|
|
|
|
if (++fdctrl->data_pos == fdctrl->data_len) {
|
2015-05-21 13:19:37 +00:00
|
|
|
fdctrl->msr &= ~FD_MSR_RQM;
|
2012-09-20 20:50:17 +00:00
|
|
|
fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00);
|
2015-05-21 13:19:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FD_PHASE_RESULT:
|
|
|
|
assert(!(fdctrl->msr & FD_MSR_NONDMA));
|
|
|
|
if (++fdctrl->data_pos == fdctrl->data_len) {
|
2015-05-21 13:19:37 +00:00
|
|
|
fdctrl->msr &= ~FD_MSR_RQM;
|
2015-05-21 13:19:31 +00:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2004-05-08 13:14:18 +00:00
|
|
|
fdctrl_reset_irq(fdctrl);
|
|
|
|
}
|
2015-05-21 13:19:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FD_PHASE_COMMAND:
|
|
|
|
default:
|
|
|
|
abort();
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
2015-05-21 13:19:36 +00:00
|
|
|
|
|
|
|
retval = fdctrl->fifo[pos];
|
2004-01-05 00:09:06 +00:00
|
|
|
FLOPPY_DPRINTF("data register: 0x%02x\n", retval);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_format_sector(FDCtrl *fdctrl)
|
2004-01-05 00:09:06 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDrive *cur_drv;
|
2004-03-19 23:05:34 +00:00
|
|
|
uint8_t kh, kt, ks;
|
2004-01-05 00:09:06 +00:00
|
|
|
|
2008-04-29 16:18:58 +00:00
|
|
|
SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
|
2004-03-19 23:05:34 +00:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
|
|
|
kt = fdctrl->fifo[6];
|
|
|
|
kh = fdctrl->fifo[7];
|
|
|
|
ks = fdctrl->fifo[8];
|
|
|
|
FLOPPY_DPRINTF("format sector at %d %d %02x %02x (%d)\n",
|
2008-04-29 16:18:58 +00:00
|
|
|
GET_CUR_DRV(fdctrl), kh, kt, ks,
|
2012-02-06 21:29:02 +00:00
|
|
|
fd_sector_calc(kh, kt, ks, cur_drv->last_sect,
|
|
|
|
NUM_SIDES(cur_drv)));
|
2008-02-29 19:24:00 +00:00
|
|
|
switch (fd_seek(cur_drv, kh, kt, ks, fdctrl->config & FD_CONFIG_EIS)) {
|
2004-03-19 23:05:34 +00:00
|
|
|
case 2:
|
|
|
|
/* sect too big */
|
2008-02-29 19:24:00 +00:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl->fifo[3] = kt;
|
|
|
|
fdctrl->fifo[4] = kh;
|
|
|
|
fdctrl->fifo[5] = ks;
|
|
|
|
return;
|
|
|
|
case 3:
|
|
|
|
/* track too big */
|
2008-04-29 16:17:08 +00:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_EC, 0x00);
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl->fifo[3] = kt;
|
|
|
|
fdctrl->fifo[4] = kh;
|
|
|
|
fdctrl->fifo[5] = ks;
|
|
|
|
return;
|
|
|
|
case 4:
|
|
|
|
/* No seek enabled */
|
2008-02-29 19:24:00 +00:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl->fifo[3] = kt;
|
|
|
|
fdctrl->fifo[4] = kh;
|
|
|
|
fdctrl->fifo[5] = ks;
|
|
|
|
return;
|
|
|
|
case 1:
|
2012-09-20 21:11:58 +00:00
|
|
|
fdctrl->status0 |= FD_SR0_SEEK;
|
2004-03-19 23:05:34 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
|
2014-10-07 11:59:18 +00:00
|
|
|
if (cur_drv->blk == NULL ||
|
2016-05-06 16:26:35 +00:00
|
|
|
blk_pwrite(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo,
|
|
|
|
BDRV_SECTOR_SIZE, 0) < 0) {
|
2012-06-03 17:16:14 +00:00
|
|
|
FLOPPY_DPRINTF("error formatting sector %d\n", fd_sector(cur_drv));
|
2008-02-29 19:24:00 +00:00
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
|
2004-03-19 23:05:34 +00:00
|
|
|
} else {
|
2007-11-05 03:11:37 +00:00
|
|
|
if (cur_drv->sect == cur_drv->last_sect) {
|
|
|
|
fdctrl->data_state &= ~FD_STATE_FORMAT;
|
|
|
|
/* Last sector done */
|
2012-09-20 21:11:58 +00:00
|
|
|
fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00);
|
2007-11-05 03:11:37 +00:00
|
|
|
} else {
|
|
|
|
/* More to do */
|
|
|
|
fdctrl->data_pos = 0;
|
|
|
|
fdctrl->data_len = 4;
|
|
|
|
}
|
2004-03-19 23:05:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_handle_lock(FDCtrl *fdctrl, int direction)
|
2008-04-08 17:18:53 +00:00
|
|
|
{
|
|
|
|
fdctrl->lock = (fdctrl->fifo[0] & 0x80) ? 1 : 0;
|
|
|
|
fdctrl->fifo[0] = fdctrl->lock << 4;
|
2015-05-21 13:19:32 +00:00
|
|
|
fdctrl_to_result_phase(fdctrl, 1);
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_handle_dumpreg(FDCtrl *fdctrl, int direction)
|
2008-04-08 17:18:53 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDrive *cur_drv = get_cur_drv(fdctrl);
|
2008-04-08 17:18:53 +00:00
|
|
|
|
|
|
|
/* Drives position */
|
|
|
|
fdctrl->fifo[0] = drv0(fdctrl)->track;
|
|
|
|
fdctrl->fifo[1] = drv1(fdctrl)->track;
|
2008-04-29 16:18:26 +00:00
|
|
|
#if MAX_FD == 4
|
|
|
|
fdctrl->fifo[2] = drv2(fdctrl)->track;
|
|
|
|
fdctrl->fifo[3] = drv3(fdctrl)->track;
|
|
|
|
#else
|
2008-04-08 17:18:53 +00:00
|
|
|
fdctrl->fifo[2] = 0;
|
|
|
|
fdctrl->fifo[3] = 0;
|
2008-04-29 16:18:26 +00:00
|
|
|
#endif
|
2008-04-08 17:18:53 +00:00
|
|
|
/* timers */
|
|
|
|
fdctrl->fifo[4] = fdctrl->timer0;
|
2008-04-29 16:15:12 +00:00
|
|
|
fdctrl->fifo[5] = (fdctrl->timer1 << 1) | (fdctrl->dor & FD_DOR_DMAEN ? 1 : 0);
|
2008-04-08 17:18:53 +00:00
|
|
|
fdctrl->fifo[6] = cur_drv->last_sect;
|
|
|
|
fdctrl->fifo[7] = (fdctrl->lock << 7) |
|
|
|
|
(cur_drv->perpendicular << 2);
|
|
|
|
fdctrl->fifo[8] = fdctrl->config;
|
|
|
|
fdctrl->fifo[9] = fdctrl->precomp_trk;
|
2015-05-21 13:19:32 +00:00
|
|
|
fdctrl_to_result_phase(fdctrl, 10);
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_handle_version(FDCtrl *fdctrl, int direction)
|
2008-04-08 17:18:53 +00:00
|
|
|
{
|
|
|
|
/* Controller's version */
|
|
|
|
fdctrl->fifo[0] = fdctrl->version;
|
2015-05-21 13:19:32 +00:00
|
|
|
fdctrl_to_result_phase(fdctrl, 1);
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_handle_partid(FDCtrl *fdctrl, int direction)
|
2008-04-08 17:18:53 +00:00
|
|
|
{
|
|
|
|
fdctrl->fifo[0] = 0x41; /* Stepping 1 */
|
2015-05-21 13:19:32 +00:00
|
|
|
fdctrl_to_result_phase(fdctrl, 1);
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_handle_restore(FDCtrl *fdctrl, int direction)
|
2008-04-08 17:18:53 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDrive *cur_drv = get_cur_drv(fdctrl);
|
2008-04-08 17:18:53 +00:00
|
|
|
|
|
|
|
/* Drives position */
|
|
|
|
drv0(fdctrl)->track = fdctrl->fifo[3];
|
|
|
|
drv1(fdctrl)->track = fdctrl->fifo[4];
|
2008-04-29 16:18:26 +00:00
|
|
|
#if MAX_FD == 4
|
|
|
|
drv2(fdctrl)->track = fdctrl->fifo[5];
|
|
|
|
drv3(fdctrl)->track = fdctrl->fifo[6];
|
|
|
|
#endif
|
2008-04-08 17:18:53 +00:00
|
|
|
/* timers */
|
|
|
|
fdctrl->timer0 = fdctrl->fifo[7];
|
|
|
|
fdctrl->timer1 = fdctrl->fifo[8];
|
|
|
|
cur_drv->last_sect = fdctrl->fifo[9];
|
|
|
|
fdctrl->lock = fdctrl->fifo[10] >> 7;
|
|
|
|
cur_drv->perpendicular = (fdctrl->fifo[10] >> 2) & 0xF;
|
|
|
|
fdctrl->config = fdctrl->fifo[11];
|
|
|
|
fdctrl->precomp_trk = fdctrl->fifo[12];
|
|
|
|
fdctrl->pwrd = fdctrl->fifo[13];
|
2015-05-21 13:19:31 +00:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_handle_save(FDCtrl *fdctrl, int direction)
|
2008-04-08 17:18:53 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDrive *cur_drv = get_cur_drv(fdctrl);
|
2008-04-08 17:18:53 +00:00
|
|
|
|
|
|
|
fdctrl->fifo[0] = 0;
|
|
|
|
fdctrl->fifo[1] = 0;
|
|
|
|
/* Drives position */
|
|
|
|
fdctrl->fifo[2] = drv0(fdctrl)->track;
|
|
|
|
fdctrl->fifo[3] = drv1(fdctrl)->track;
|
2008-04-29 16:18:26 +00:00
|
|
|
#if MAX_FD == 4
|
|
|
|
fdctrl->fifo[4] = drv2(fdctrl)->track;
|
|
|
|
fdctrl->fifo[5] = drv3(fdctrl)->track;
|
|
|
|
#else
|
2008-04-08 17:18:53 +00:00
|
|
|
fdctrl->fifo[4] = 0;
|
|
|
|
fdctrl->fifo[5] = 0;
|
2008-04-29 16:18:26 +00:00
|
|
|
#endif
|
2008-04-08 17:18:53 +00:00
|
|
|
/* timers */
|
|
|
|
fdctrl->fifo[6] = fdctrl->timer0;
|
|
|
|
fdctrl->fifo[7] = fdctrl->timer1;
|
|
|
|
fdctrl->fifo[8] = cur_drv->last_sect;
|
|
|
|
fdctrl->fifo[9] = (fdctrl->lock << 7) |
|
|
|
|
(cur_drv->perpendicular << 2);
|
|
|
|
fdctrl->fifo[10] = fdctrl->config;
|
|
|
|
fdctrl->fifo[11] = fdctrl->precomp_trk;
|
|
|
|
fdctrl->fifo[12] = fdctrl->pwrd;
|
|
|
|
fdctrl->fifo[13] = 0;
|
|
|
|
fdctrl->fifo[14] = 0;
|
2015-05-21 13:19:32 +00:00
|
|
|
fdctrl_to_result_phase(fdctrl, 15);
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_handle_readid(FDCtrl *fdctrl, int direction)
|
2008-04-08 17:18:53 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDrive *cur_drv = get_cur_drv(fdctrl);
|
2008-04-08 17:18:53 +00:00
|
|
|
|
|
|
|
cur_drv->head = (fdctrl->fifo[1] >> 2) & 1;
|
2016-03-21 16:02:30 +00:00
|
|
|
timer_mod(fdctrl->result_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
|
|
|
|
(NANOSECONDS_PER_SECOND / 50));
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_handle_format_track(FDCtrl *fdctrl, int direction)
|
2008-04-08 17:18:53 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDrive *cur_drv;
|
2008-04-08 17:18:53 +00:00
|
|
|
|
2008-04-29 16:18:58 +00:00
|
|
|
SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
|
2008-04-08 17:18:53 +00:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
|
|
|
fdctrl->data_state |= FD_STATE_FORMAT;
|
|
|
|
if (fdctrl->fifo[0] & 0x80)
|
|
|
|
fdctrl->data_state |= FD_STATE_MULTI;
|
|
|
|
else
|
|
|
|
fdctrl->data_state &= ~FD_STATE_MULTI;
|
|
|
|
cur_drv->bps =
|
|
|
|
fdctrl->fifo[2] > 7 ? 16384 : 128 << fdctrl->fifo[2];
|
|
|
|
#if 0
|
|
|
|
cur_drv->last_sect =
|
|
|
|
cur_drv->flags & FDISK_DBL_SIDES ? fdctrl->fifo[3] :
|
|
|
|
fdctrl->fifo[3] / 2;
|
|
|
|
#else
|
|
|
|
cur_drv->last_sect = fdctrl->fifo[3];
|
|
|
|
#endif
|
|
|
|
/* TODO: implement format using DMA expected by the Bochs BIOS
|
|
|
|
* and Linux fdformat (read 3 bytes per sector via DMA and fill
|
|
|
|
* the sector with the specified fill byte
|
|
|
|
*/
|
|
|
|
fdctrl->data_state &= ~FD_STATE_FORMAT;
|
|
|
|
fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00);
|
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_handle_specify(FDCtrl *fdctrl, int direction)
|
2008-04-08 17:18:53 +00:00
|
|
|
{
|
|
|
|
fdctrl->timer0 = (fdctrl->fifo[1] >> 4) & 0xF;
|
|
|
|
fdctrl->timer1 = fdctrl->fifo[2] >> 1;
|
2008-04-29 16:15:12 +00:00
|
|
|
if (fdctrl->fifo[2] & 1)
|
|
|
|
fdctrl->dor &= ~FD_DOR_DMAEN;
|
|
|
|
else
|
|
|
|
fdctrl->dor |= FD_DOR_DMAEN;
|
2008-04-08 17:18:53 +00:00
|
|
|
/* No result back */
|
2015-05-21 13:19:31 +00:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_handle_sense_drive_status(FDCtrl *fdctrl, int direction)
|
2008-04-08 17:18:53 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDrive *cur_drv;
|
2008-04-08 17:18:53 +00:00
|
|
|
|
2008-04-29 16:18:58 +00:00
|
|
|
SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
|
2008-04-08 17:18:53 +00:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
|
|
|
cur_drv->head = (fdctrl->fifo[1] >> 2) & 1;
|
|
|
|
/* 1 Byte status back */
|
|
|
|
fdctrl->fifo[0] = (cur_drv->ro << 6) |
|
|
|
|
(cur_drv->track == 0 ? 0x10 : 0x00) |
|
|
|
|
(cur_drv->head << 2) |
|
2008-04-29 16:18:58 +00:00
|
|
|
GET_CUR_DRV(fdctrl) |
|
2008-04-08 17:18:53 +00:00
|
|
|
0x28;
|
2015-05-21 13:19:32 +00:00
|
|
|
fdctrl_to_result_phase(fdctrl, 1);
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_handle_recalibrate(FDCtrl *fdctrl, int direction)
|
2008-04-08 17:18:53 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDrive *cur_drv;
|
2008-04-08 17:18:53 +00:00
|
|
|
|
2008-04-29 16:18:58 +00:00
|
|
|
SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
|
2008-04-08 17:18:53 +00:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
|
|
|
fd_recalibrate(cur_drv);
|
2015-05-21 13:19:31 +00:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2008-04-08 17:18:53 +00:00
|
|
|
/* Raise Interrupt */
|
2012-08-19 08:21:14 +00:00
|
|
|
fdctrl->status0 |= FD_SR0_SEEK;
|
|
|
|
fdctrl_raise_irq(fdctrl);
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_handle_sense_interrupt_status(FDCtrl *fdctrl, int direction)
|
2008-04-08 17:18:53 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDrive *cur_drv = get_cur_drv(fdctrl);
|
2008-04-08 17:18:53 +00:00
|
|
|
|
2012-06-22 10:33:55 +00:00
|
|
|
if (fdctrl->reset_sensei > 0) {
|
2009-01-24 12:09:52 +00:00
|
|
|
fdctrl->fifo[0] =
|
|
|
|
FD_SR0_RDYCHG + FD_RESET_SENSEI_COUNT - fdctrl->reset_sensei;
|
|
|
|
fdctrl->reset_sensei--;
|
2012-06-22 10:33:55 +00:00
|
|
|
} else if (!(fdctrl->sra & FD_SRA_INTPEND)) {
|
|
|
|
fdctrl->fifo[0] = FD_SR0_INVCMD;
|
2015-05-21 13:19:32 +00:00
|
|
|
fdctrl_to_result_phase(fdctrl, 1);
|
2012-06-22 10:33:55 +00:00
|
|
|
return;
|
2009-01-24 12:09:52 +00:00
|
|
|
} else {
|
|
|
|
fdctrl->fifo[0] =
|
2012-06-22 10:33:55 +00:00
|
|
|
(fdctrl->status0 & ~(FD_SR0_HEAD | FD_SR0_DS1 | FD_SR0_DS0))
|
|
|
|
| GET_CUR_DRV(fdctrl);
|
2009-01-24 12:09:52 +00:00
|
|
|
}
|
|
|
|
|
2008-04-08 17:18:53 +00:00
|
|
|
fdctrl->fifo[1] = cur_drv->track;
|
2015-05-21 13:19:32 +00:00
|
|
|
fdctrl_to_result_phase(fdctrl, 2);
|
2008-04-08 17:18:53 +00:00
|
|
|
fdctrl_reset_irq(fdctrl);
|
2008-04-29 16:17:08 +00:00
|
|
|
fdctrl->status0 = FD_SR0_RDYCHG;
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_handle_seek(FDCtrl *fdctrl, int direction)
|
2008-04-08 17:18:53 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDrive *cur_drv;
|
2008-04-08 17:18:53 +00:00
|
|
|
|
2008-04-29 16:18:58 +00:00
|
|
|
SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
|
2008-04-08 17:18:53 +00:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
2015-05-21 13:19:31 +00:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2012-02-06 21:29:11 +00:00
|
|
|
/* The seek command just sends step pulses to the drive and doesn't care if
|
|
|
|
* there is a medium inserted of if it's banging the head against the drive.
|
|
|
|
*/
|
2012-06-22 10:33:54 +00:00
|
|
|
fd_seek(cur_drv, cur_drv->head, fdctrl->fifo[2], cur_drv->sect, 1);
|
2012-02-06 21:29:11 +00:00
|
|
|
/* Raise Interrupt */
|
2012-08-19 08:21:14 +00:00
|
|
|
fdctrl->status0 |= FD_SR0_SEEK;
|
|
|
|
fdctrl_raise_irq(fdctrl);
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_handle_perpendicular_mode(FDCtrl *fdctrl, int direction)
|
2008-04-08 17:18:53 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDrive *cur_drv = get_cur_drv(fdctrl);
|
2008-04-08 17:18:53 +00:00
|
|
|
|
|
|
|
if (fdctrl->fifo[1] & 0x80)
|
|
|
|
cur_drv->perpendicular = fdctrl->fifo[1] & 0x7;
|
|
|
|
/* No result back */
|
2015-05-21 13:19:31 +00:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_handle_configure(FDCtrl *fdctrl, int direction)
|
2008-04-08 17:18:53 +00:00
|
|
|
{
|
|
|
|
fdctrl->config = fdctrl->fifo[2];
|
|
|
|
fdctrl->precomp_trk = fdctrl->fifo[3];
|
|
|
|
/* No result back */
|
2015-05-21 13:19:31 +00:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_handle_powerdown_mode(FDCtrl *fdctrl, int direction)
|
2008-04-08 17:18:53 +00:00
|
|
|
{
|
|
|
|
fdctrl->pwrd = fdctrl->fifo[1];
|
|
|
|
fdctrl->fifo[0] = fdctrl->fifo[1];
|
2015-05-21 13:19:32 +00:00
|
|
|
fdctrl_to_result_phase(fdctrl, 1);
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_handle_option(FDCtrl *fdctrl, int direction)
|
2008-04-08 17:18:53 +00:00
|
|
|
{
|
|
|
|
/* No result back */
|
2015-05-21 13:19:31 +00:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_handle_drive_specification_command(FDCtrl *fdctrl, int direction)
|
2008-04-08 17:18:53 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDrive *cur_drv = get_cur_drv(fdctrl);
|
2015-05-06 07:48:59 +00:00
|
|
|
uint32_t pos;
|
2008-04-08 17:18:53 +00:00
|
|
|
|
2015-05-06 07:48:59 +00:00
|
|
|
pos = fdctrl->data_pos - 1;
|
|
|
|
pos %= FD_SECTOR_LEN;
|
|
|
|
if (fdctrl->fifo[pos] & 0x80) {
|
2008-04-08 17:18:53 +00:00
|
|
|
/* Command parameters done */
|
2015-05-06 07:48:59 +00:00
|
|
|
if (fdctrl->fifo[pos] & 0x40) {
|
2008-04-08 17:18:53 +00:00
|
|
|
fdctrl->fifo[0] = fdctrl->fifo[1];
|
|
|
|
fdctrl->fifo[2] = 0;
|
|
|
|
fdctrl->fifo[3] = 0;
|
2015-05-21 13:19:32 +00:00
|
|
|
fdctrl_to_result_phase(fdctrl, 4);
|
2008-04-08 17:18:53 +00:00
|
|
|
} else {
|
2015-05-21 13:19:31 +00:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
|
|
|
} else if (fdctrl->data_len > 7) {
|
|
|
|
/* ERROR */
|
|
|
|
fdctrl->fifo[0] = 0x80 |
|
2008-04-29 16:18:58 +00:00
|
|
|
(cur_drv->head << 2) | GET_CUR_DRV(fdctrl);
|
2015-05-21 13:19:32 +00:00
|
|
|
fdctrl_to_result_phase(fdctrl, 1);
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-16 13:48:26 +00:00
|
|
|
static void fdctrl_handle_relative_seek_in(FDCtrl *fdctrl, int direction)
|
2008-04-08 17:18:53 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDrive *cur_drv;
|
2008-04-08 17:18:53 +00:00
|
|
|
|
2008-04-29 16:18:58 +00:00
|
|
|
SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
|
2008-04-08 17:18:53 +00:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
|
|
|
if (fdctrl->fifo[2] + cur_drv->track >= cur_drv->max_track) {
|
2012-06-22 10:33:54 +00:00
|
|
|
fd_seek(cur_drv, cur_drv->head, cur_drv->max_track - 1,
|
|
|
|
cur_drv->sect, 1);
|
2008-04-08 17:18:53 +00:00
|
|
|
} else {
|
2012-07-16 13:48:26 +00:00
|
|
|
fd_seek(cur_drv, cur_drv->head,
|
|
|
|
cur_drv->track + fdctrl->fifo[2], cur_drv->sect, 1);
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
2015-05-21 13:19:31 +00:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2008-04-29 16:17:08 +00:00
|
|
|
/* Raise Interrupt */
|
2012-08-19 08:21:14 +00:00
|
|
|
fdctrl->status0 |= FD_SR0_SEEK;
|
|
|
|
fdctrl_raise_irq(fdctrl);
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
|
|
|
|
2012-07-16 13:48:26 +00:00
|
|
|
static void fdctrl_handle_relative_seek_out(FDCtrl *fdctrl, int direction)
|
2008-04-08 17:18:53 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDrive *cur_drv;
|
2008-04-08 17:18:53 +00:00
|
|
|
|
2008-04-29 16:18:58 +00:00
|
|
|
SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
|
2008-04-08 17:18:53 +00:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
|
|
|
if (fdctrl->fifo[2] > cur_drv->track) {
|
2012-06-22 10:33:54 +00:00
|
|
|
fd_seek(cur_drv, cur_drv->head, 0, cur_drv->sect, 1);
|
2008-04-08 17:18:53 +00:00
|
|
|
} else {
|
2012-07-16 13:48:26 +00:00
|
|
|
fd_seek(cur_drv, cur_drv->head,
|
|
|
|
cur_drv->track - fdctrl->fifo[2], cur_drv->sect, 1);
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
2015-05-21 13:19:31 +00:00
|
|
|
fdctrl_to_command_phase(fdctrl);
|
2008-04-08 17:18:53 +00:00
|
|
|
/* Raise Interrupt */
|
2012-08-19 08:21:14 +00:00
|
|
|
fdctrl->status0 |= FD_SR0_SEEK;
|
|
|
|
fdctrl_raise_irq(fdctrl);
|
2008-04-08 17:18:53 +00:00
|
|
|
}
|
|
|
|
|
2015-05-21 13:19:33 +00:00
|
|
|
/*
|
|
|
|
* Handlers for the execution phase of each command
|
|
|
|
*/
|
2015-05-21 13:19:35 +00:00
|
|
|
typedef struct FDCtrlCommand {
|
2008-04-29 16:12:30 +00:00
|
|
|
uint8_t value;
|
|
|
|
uint8_t mask;
|
|
|
|
const char* name;
|
|
|
|
int parameters;
|
2010-02-07 09:01:18 +00:00
|
|
|
void (*handler)(FDCtrl *fdctrl, int direction);
|
2008-04-29 16:12:30 +00:00
|
|
|
int direction;
|
2015-05-21 13:19:35 +00:00
|
|
|
} FDCtrlCommand;
|
|
|
|
|
|
|
|
static const FDCtrlCommand handlers[] = {
|
2008-04-29 16:12:30 +00:00
|
|
|
{ FD_CMD_READ, 0x1f, "READ", 8, fdctrl_start_transfer, FD_DIR_READ },
|
|
|
|
{ FD_CMD_WRITE, 0x3f, "WRITE", 8, fdctrl_start_transfer, FD_DIR_WRITE },
|
|
|
|
{ FD_CMD_SEEK, 0xff, "SEEK", 2, fdctrl_handle_seek },
|
|
|
|
{ FD_CMD_SENSE_INTERRUPT_STATUS, 0xff, "SENSE INTERRUPT STATUS", 0, fdctrl_handle_sense_interrupt_status },
|
|
|
|
{ FD_CMD_RECALIBRATE, 0xff, "RECALIBRATE", 1, fdctrl_handle_recalibrate },
|
|
|
|
{ FD_CMD_FORMAT_TRACK, 0xbf, "FORMAT TRACK", 5, fdctrl_handle_format_track },
|
|
|
|
{ FD_CMD_READ_TRACK, 0xbf, "READ TRACK", 8, fdctrl_start_transfer, FD_DIR_READ },
|
|
|
|
{ FD_CMD_RESTORE, 0xff, "RESTORE", 17, fdctrl_handle_restore }, /* part of READ DELETED DATA */
|
|
|
|
{ FD_CMD_SAVE, 0xff, "SAVE", 0, fdctrl_handle_save }, /* part of READ DELETED DATA */
|
|
|
|
{ FD_CMD_READ_DELETED, 0x1f, "READ DELETED DATA", 8, fdctrl_start_transfer_del, FD_DIR_READ },
|
|
|
|
{ FD_CMD_SCAN_EQUAL, 0x1f, "SCAN EQUAL", 8, fdctrl_start_transfer, FD_DIR_SCANE },
|
2012-09-18 21:04:10 +00:00
|
|
|
{ FD_CMD_VERIFY, 0x1f, "VERIFY", 8, fdctrl_start_transfer, FD_DIR_VERIFY },
|
2008-04-29 16:12:30 +00:00
|
|
|
{ FD_CMD_SCAN_LOW_OR_EQUAL, 0x1f, "SCAN LOW OR EQUAL", 8, fdctrl_start_transfer, FD_DIR_SCANL },
|
|
|
|
{ FD_CMD_SCAN_HIGH_OR_EQUAL, 0x1f, "SCAN HIGH OR EQUAL", 8, fdctrl_start_transfer, FD_DIR_SCANH },
|
|
|
|
{ FD_CMD_WRITE_DELETED, 0x3f, "WRITE DELETED DATA", 8, fdctrl_start_transfer_del, FD_DIR_WRITE },
|
|
|
|
{ FD_CMD_READ_ID, 0xbf, "READ ID", 1, fdctrl_handle_readid },
|
|
|
|
{ FD_CMD_SPECIFY, 0xff, "SPECIFY", 2, fdctrl_handle_specify },
|
|
|
|
{ FD_CMD_SENSE_DRIVE_STATUS, 0xff, "SENSE DRIVE STATUS", 1, fdctrl_handle_sense_drive_status },
|
|
|
|
{ FD_CMD_PERPENDICULAR_MODE, 0xff, "PERPENDICULAR MODE", 1, fdctrl_handle_perpendicular_mode },
|
|
|
|
{ FD_CMD_CONFIGURE, 0xff, "CONFIGURE", 3, fdctrl_handle_configure },
|
|
|
|
{ FD_CMD_POWERDOWN_MODE, 0xff, "POWERDOWN MODE", 2, fdctrl_handle_powerdown_mode },
|
|
|
|
{ FD_CMD_OPTION, 0xff, "OPTION", 1, fdctrl_handle_option },
|
|
|
|
{ FD_CMD_DRIVE_SPECIFICATION_COMMAND, 0xff, "DRIVE SPECIFICATION COMMAND", 5, fdctrl_handle_drive_specification_command },
|
|
|
|
{ FD_CMD_RELATIVE_SEEK_OUT, 0xff, "RELATIVE SEEK OUT", 2, fdctrl_handle_relative_seek_out },
|
|
|
|
{ FD_CMD_FORMAT_AND_WRITE, 0xff, "FORMAT AND WRITE", 10, fdctrl_unimplemented },
|
|
|
|
{ FD_CMD_RELATIVE_SEEK_IN, 0xff, "RELATIVE SEEK IN", 2, fdctrl_handle_relative_seek_in },
|
|
|
|
{ FD_CMD_LOCK, 0x7f, "LOCK", 0, fdctrl_handle_lock },
|
|
|
|
{ FD_CMD_DUMPREG, 0xff, "DUMPREG", 0, fdctrl_handle_dumpreg },
|
|
|
|
{ FD_CMD_VERSION, 0xff, "VERSION", 0, fdctrl_handle_version },
|
|
|
|
{ FD_CMD_PART_ID, 0xff, "PART ID", 0, fdctrl_handle_partid },
|
|
|
|
{ FD_CMD_WRITE, 0x1f, "WRITE (BeOS)", 8, fdctrl_start_transfer, FD_DIR_WRITE }, /* not in specification ; BeOS 4.5 bug */
|
|
|
|
{ 0, 0, "unknown", 0, fdctrl_unimplemented }, /* default handler */
|
|
|
|
};
|
|
|
|
/* Associate command to an index in the 'handlers' array */
|
|
|
|
static uint8_t command_to_handler[256];
|
|
|
|
|
2015-05-21 13:19:35 +00:00
|
|
|
static const FDCtrlCommand *get_command(uint8_t cmd)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
idx = command_to_handler[cmd];
|
|
|
|
FLOPPY_DPRINTF("%s command\n", handlers[idx].name);
|
|
|
|
return &handlers[idx];
|
|
|
|
}
|
|
|
|
|
2010-02-07 09:01:18 +00:00
|
|
|
static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t value)
|
2004-03-19 23:05:34 +00:00
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDrive *cur_drv;
|
2015-05-21 13:19:35 +00:00
|
|
|
const FDCtrlCommand *cmd;
|
2015-05-06 07:48:59 +00:00
|
|
|
uint32_t pos;
|
2004-03-19 23:05:34 +00:00
|
|
|
|
2004-01-05 00:09:06 +00:00
|
|
|
/* Reset mode */
|
2008-04-29 16:15:53 +00:00
|
|
|
if (!(fdctrl->dor & FD_DOR_nRESET)) {
|
2004-10-09 16:44:33 +00:00
|
|
|
FLOPPY_DPRINTF("Floppy controller in RESET state !\n");
|
2004-01-05 00:09:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-04-29 16:16:30 +00:00
|
|
|
if (!(fdctrl->msr & FD_MSR_RQM) || (fdctrl->msr & FD_MSR_DIO)) {
|
2012-06-03 17:16:14 +00:00
|
|
|
FLOPPY_DPRINTF("error: controller not ready for writing\n");
|
2004-01-05 00:09:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-04-29 16:16:30 +00:00
|
|
|
fdctrl->dsr &= ~FD_DSR_PWRDOWN;
|
2015-05-21 13:19:34 +00:00
|
|
|
|
2015-05-21 13:19:35 +00:00
|
|
|
FLOPPY_DPRINTF("%s: %02x\n", __func__, value);
|
|
|
|
|
|
|
|
/* If data_len spans multiple sectors, the current position in the FIFO
|
|
|
|
* wraps around while fdctrl->data_pos is the real position in the whole
|
|
|
|
* request. */
|
|
|
|
pos = fdctrl->data_pos++;
|
|
|
|
pos %= FD_SECTOR_LEN;
|
|
|
|
fdctrl->fifo[pos] = value;
|
|
|
|
|
2015-05-21 13:19:37 +00:00
|
|
|
if (fdctrl->data_pos == fdctrl->data_len) {
|
|
|
|
fdctrl->msr &= ~FD_MSR_RQM;
|
|
|
|
}
|
|
|
|
|
2015-05-21 13:19:34 +00:00
|
|
|
switch (fdctrl->phase) {
|
|
|
|
case FD_PHASE_EXECUTION:
|
|
|
|
/* For DMA requests, RQM should be cleared during execution phase, so
|
|
|
|
* we would have errored out above. */
|
|
|
|
assert(fdctrl->msr & FD_MSR_NONDMA);
|
2015-05-21 13:19:35 +00:00
|
|
|
|
2004-01-05 00:09:06 +00:00
|
|
|
/* FIFO data write */
|
2008-05-01 19:03:31 +00:00
|
|
|
if (pos == FD_SECTOR_LEN - 1 ||
|
2004-03-19 23:05:34 +00:00
|
|
|
fdctrl->data_pos == fdctrl->data_len) {
|
2008-04-29 16:17:08 +00:00
|
|
|
cur_drv = get_cur_drv(fdctrl);
|
2016-05-06 16:26:35 +00:00
|
|
|
if (blk_pwrite(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo,
|
|
|
|
BDRV_SECTOR_SIZE, 0) < 0) {
|
2012-06-03 17:16:14 +00:00
|
|
|
FLOPPY_DPRINTF("error writing sector %d\n",
|
|
|
|
fd_sector(cur_drv));
|
2015-05-21 13:19:34 +00:00
|
|
|
break;
|
2008-04-29 16:17:08 +00:00
|
|
|
}
|
2008-04-29 16:13:36 +00:00
|
|
|
if (!fdctrl_seek_to_next_sect(fdctrl, cur_drv)) {
|
|
|
|
FLOPPY_DPRINTF("error seeking to next sector %d\n",
|
|
|
|
fd_sector(cur_drv));
|
2015-05-21 13:19:34 +00:00
|
|
|
break;
|
2008-04-29 16:13:36 +00:00
|
|
|
}
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
2015-05-21 13:19:35 +00:00
|
|
|
|
|
|
|
/* Switch to result phase when done with the transfer */
|
|
|
|
if (fdctrl->data_pos == fdctrl->data_len) {
|
2012-09-20 20:50:17 +00:00
|
|
|
fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00);
|
2015-05-21 13:19:35 +00:00
|
|
|
}
|
2015-05-21 13:19:34 +00:00
|
|
|
break;
|
2008-04-29 16:12:30 +00:00
|
|
|
|
2015-05-21 13:19:34 +00:00
|
|
|
case FD_PHASE_COMMAND:
|
|
|
|
assert(!(fdctrl->msr & FD_MSR_NONDMA));
|
2015-05-21 13:19:35 +00:00
|
|
|
assert(fdctrl->data_pos < FD_SECTOR_LEN);
|
2015-05-21 13:19:34 +00:00
|
|
|
|
2015-05-21 13:19:35 +00:00
|
|
|
if (pos == 0) {
|
|
|
|
/* The first byte specifies the command. Now we start reading
|
|
|
|
* as many parameters as this command requires. */
|
|
|
|
cmd = get_command(value);
|
|
|
|
fdctrl->data_len = cmd->parameters + 1;
|
2015-05-21 13:19:37 +00:00
|
|
|
if (cmd->parameters) {
|
|
|
|
fdctrl->msr |= FD_MSR_RQM;
|
|
|
|
}
|
2015-05-21 13:19:34 +00:00
|
|
|
fdctrl->msr |= FD_MSR_CMDBUSY;
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
2008-04-08 17:18:53 +00:00
|
|
|
|
2015-05-21 13:19:34 +00:00
|
|
|
if (fdctrl->data_pos == fdctrl->data_len) {
|
2015-05-21 13:19:35 +00:00
|
|
|
/* We have all parameters now, execute the command */
|
2015-05-21 13:19:34 +00:00
|
|
|
fdctrl->phase = FD_PHASE_EXECUTION;
|
2015-05-21 13:19:35 +00:00
|
|
|
|
2015-05-21 13:19:34 +00:00
|
|
|
if (fdctrl->data_state & FD_STATE_FORMAT) {
|
|
|
|
fdctrl_format_sector(fdctrl);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-05-21 13:19:35 +00:00
|
|
|
cmd = get_command(fdctrl->fifo[0]);
|
|
|
|
FLOPPY_DPRINTF("Calling handler for '%s'\n", cmd->name);
|
|
|
|
cmd->handler(fdctrl, cmd->direction);
|
2015-05-21 13:19:34 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FD_PHASE_RESULT:
|
|
|
|
default:
|
|
|
|
abort();
|
2004-01-05 00:09:06 +00:00
|
|
|
}
|
|
|
|
}
|
2004-05-08 13:14:18 +00:00
|
|
|
|
|
|
|
static void fdctrl_result_timer(void *opaque)
|
|
|
|
{
|
2010-02-07 09:01:18 +00:00
|
|
|
FDCtrl *fdctrl = opaque;
|
|
|
|
FDrive *cur_drv = get_cur_drv(fdctrl);
|
2007-11-05 03:11:37 +00:00
|
|
|
|
2007-09-13 12:40:37 +00:00
|
|
|
/* Pretend we are spinning.
|
|
|
|
* This is needed for Coherent, which uses READ ID to check for
|
|
|
|
* sector interleaving.
|
|
|
|
*/
|
|
|
|
if (cur_drv->last_sect != 0) {
|
|
|
|
cur_drv->sect = (cur_drv->sect % cur_drv->last_sect) + 1;
|
|
|
|
}
|
2012-02-06 21:29:10 +00:00
|
|
|
/* READ_ID can't automatically succeed! */
|
2021-02-03 17:18:30 +00:00
|
|
|
if ((fdctrl->dsr & FD_DSR_DRATEMASK) != cur_drv->media_rate) {
|
2012-02-06 21:29:10 +00:00
|
|
|
FLOPPY_DPRINTF("read id rate mismatch (fdc=%d, media=%d)\n",
|
|
|
|
fdctrl->dsr & FD_DSR_DRATEMASK, cur_drv->media_rate);
|
|
|
|
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_MA, 0x00);
|
|
|
|
} else {
|
|
|
|
fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00);
|
|
|
|
}
|
2004-05-08 13:14:18 +00:00
|
|
|
}
|
2008-04-29 16:12:30 +00:00
|
|
|
|
|
|
|
/* Init functions */
|
fdc: Reject clash between -drive if=floppy and -global isa-fdc
The floppy controller devices desugar their drive properties into
floppy devices (since commit a92bd191a4 "fdc: Move qdev properties to
FloppyDrive", v2.8.0). This involves some bad magic in
fdctrl_connect_drives(), and exists for backward compatibility.
The functions for boards to create floppy controller devices
fdctrl_init_isa(), fdctrl_init_sysbus(), and sun4m_fdctrl_init()
desugar -drive if=floppy to these floppy controller drive properties.
If you use both -drive if=floppy (or its -fda / -fdb sugar) and
-global isa-fdc for the same floppy device, -global silently loses the
conflict, and both backends involved end up with the floppy device
frontend attached, as demonstrated by iotest 172 (see commit before
previous). This is wrong.
Desugar -drive if=floppy straight to floppy devices instead, with
helper fdctrl_init_drives(). The conflict now gets rejected cleanly:
first, fdctrl_connect_drives() creates the floppy for the controller's
property, then fdctrl_init_drives() attempts to create the floppy for
-drive if=floppy, but fails because the unit is already in use.
Output of iotest 172 changes in three ways:
1. The clash gets rejected.
2. In one test case, "info qtree" has the floppy devices swapped, and
"info block" has their QOM paths swapped. This is because the
floppy device for -fda now gets created after the one for -global
isa-fdc.driveB.
3. The error message for -global floppy.drive=floppy0 changes. Before
the patch, we set isa-fdc.driveA to -fda's block backend, then
create the floppy device for it, then move the backend from
isa-fdc.driveA to floppy.drive. Floppy creation fails when
applying -global floppy.drive=floppy0, because floppy0 is still
attached to isa-fdc. After the patch, we create the floppy for
-fda, then set its drive property to floppy0. Now floppy creation
succeeds, but setting the drive property fails, because -global
already set it. Yes, this is exasperatingly complicated.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200622094227.1271650-5-armbru@redhat.com>
2020-06-22 09:42:15 +00:00
|
|
|
|
2021-06-14 19:32:17 +00:00
|
|
|
void fdctrl_init_drives(FloppyBus *bus, DriveInfo **fds)
|
fdc: Reject clash between -drive if=floppy and -global isa-fdc
The floppy controller devices desugar their drive properties into
floppy devices (since commit a92bd191a4 "fdc: Move qdev properties to
FloppyDrive", v2.8.0). This involves some bad magic in
fdctrl_connect_drives(), and exists for backward compatibility.
The functions for boards to create floppy controller devices
fdctrl_init_isa(), fdctrl_init_sysbus(), and sun4m_fdctrl_init()
desugar -drive if=floppy to these floppy controller drive properties.
If you use both -drive if=floppy (or its -fda / -fdb sugar) and
-global isa-fdc for the same floppy device, -global silently loses the
conflict, and both backends involved end up with the floppy device
frontend attached, as demonstrated by iotest 172 (see commit before
previous). This is wrong.
Desugar -drive if=floppy straight to floppy devices instead, with
helper fdctrl_init_drives(). The conflict now gets rejected cleanly:
first, fdctrl_connect_drives() creates the floppy for the controller's
property, then fdctrl_init_drives() attempts to create the floppy for
-drive if=floppy, but fails because the unit is already in use.
Output of iotest 172 changes in three ways:
1. The clash gets rejected.
2. In one test case, "info qtree" has the floppy devices swapped, and
"info block" has their QOM paths swapped. This is because the
floppy device for -fda now gets created after the one for -global
isa-fdc.driveB.
3. The error message for -global floppy.drive=floppy0 changes. Before
the patch, we set isa-fdc.driveA to -fda's block backend, then
create the floppy device for it, then move the backend from
isa-fdc.driveA to floppy.drive. Floppy creation fails when
applying -global floppy.drive=floppy0, because floppy0 is still
attached to isa-fdc. After the patch, we create the floppy for
-fda, then set its drive property to floppy0. Now floppy creation
succeeds, but setting the drive property fails, because -global
already set it. Yes, this is exasperatingly complicated.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200622094227.1271650-5-armbru@redhat.com>
2020-06-22 09:42:15 +00:00
|
|
|
{
|
|
|
|
DeviceState *dev;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_FD; i++) {
|
|
|
|
if (fds[i]) {
|
|
|
|
dev = qdev_new("floppy");
|
|
|
|
qdev_prop_set_uint32(dev, "unit", i);
|
|
|
|
qdev_prop_set_enum(dev, "drive-type", FLOPPY_DRIVE_TYPE_AUTO);
|
qdev: Make qdev_prop_set_drive() match the other helpers
qdev_prop_set_drive() can fail. None of the other qdev_prop_set_FOO()
can; they abort on error.
To clean up this inconsistency, rename qdev_prop_set_drive() to
qdev_prop_set_drive_err(), and create a qdev_prop_set_drive() that
aborts on error.
Coccinelle script to update callers:
@ depends on !(file in "hw/core/qdev-properties-system.c")@
expression dev, name, value;
symbol error_abort;
@@
- qdev_prop_set_drive(dev, name, value, &error_abort);
+ qdev_prop_set_drive(dev, name, value);
@@
expression dev, name, value, errp;
@@
- qdev_prop_set_drive(dev, name, value, errp);
+ qdev_prop_set_drive_err(dev, name, value, errp);
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200622094227.1271650-14-armbru@redhat.com>
2020-06-22 09:42:24 +00:00
|
|
|
qdev_prop_set_drive_err(dev, "drive", blk_by_legacy_dinfo(fds[i]),
|
|
|
|
&error_fatal);
|
fdc: Reject clash between -drive if=floppy and -global isa-fdc
The floppy controller devices desugar their drive properties into
floppy devices (since commit a92bd191a4 "fdc: Move qdev properties to
FloppyDrive", v2.8.0). This involves some bad magic in
fdctrl_connect_drives(), and exists for backward compatibility.
The functions for boards to create floppy controller devices
fdctrl_init_isa(), fdctrl_init_sysbus(), and sun4m_fdctrl_init()
desugar -drive if=floppy to these floppy controller drive properties.
If you use both -drive if=floppy (or its -fda / -fdb sugar) and
-global isa-fdc for the same floppy device, -global silently loses the
conflict, and both backends involved end up with the floppy device
frontend attached, as demonstrated by iotest 172 (see commit before
previous). This is wrong.
Desugar -drive if=floppy straight to floppy devices instead, with
helper fdctrl_init_drives(). The conflict now gets rejected cleanly:
first, fdctrl_connect_drives() creates the floppy for the controller's
property, then fdctrl_init_drives() attempts to create the floppy for
-drive if=floppy, but fails because the unit is already in use.
Output of iotest 172 changes in three ways:
1. The clash gets rejected.
2. In one test case, "info qtree" has the floppy devices swapped, and
"info block" has their QOM paths swapped. This is because the
floppy device for -fda now gets created after the one for -global
isa-fdc.driveB.
3. The error message for -global floppy.drive=floppy0 changes. Before
the patch, we set isa-fdc.driveA to -fda's block backend, then
create the floppy device for it, then move the backend from
isa-fdc.driveA to floppy.drive. Floppy creation fails when
applying -global floppy.drive=floppy0, because floppy0 is still
attached to isa-fdc. After the patch, we create the floppy for
-fda, then set its drive property to floppy0. Now floppy creation
succeeds, but setting the drive property fails, because -global
already set it. Yes, this is exasperatingly complicated.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20200622094227.1271650-5-armbru@redhat.com>
2020-06-22 09:42:15 +00:00
|
|
|
qdev_realize_and_unref(dev, &bus->bus, &error_fatal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-14 19:32:17 +00:00
|
|
|
void fdctrl_realize_common(DeviceState *dev, FDCtrl *fdctrl, Error **errp)
|
2009-07-15 14:41:54 +00:00
|
|
|
{
|
2009-07-20 06:56:23 +00:00
|
|
|
int i, j;
|
2021-03-09 16:12:12 +00:00
|
|
|
FDrive *drive;
|
2009-07-20 06:56:23 +00:00
|
|
|
static int command_tables_inited = 0;
|
2009-07-15 14:41:54 +00:00
|
|
|
|
2016-01-22 20:51:00 +00:00
|
|
|
if (fdctrl->fallback == FLOPPY_DRIVE_TYPE_AUTO) {
|
|
|
|
error_setg(errp, "Cannot choose a fallback FDrive type of 'auto'");
|
2020-04-22 13:07:11 +00:00
|
|
|
return;
|
2016-01-22 20:51:00 +00:00
|
|
|
}
|
|
|
|
|
2009-07-20 06:56:23 +00:00
|
|
|
/* Fill 'command_to_handler' lookup table */
|
|
|
|
if (!command_tables_inited) {
|
|
|
|
command_tables_inited = 1;
|
|
|
|
for (i = ARRAY_SIZE(handlers) - 1; i >= 0; i--) {
|
|
|
|
for (j = 0; j < sizeof(command_to_handler); j++) {
|
|
|
|
if ((j & handlers[i].mask) == handlers[i].value) {
|
|
|
|
command_to_handler[j] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FLOPPY_DPRINTF("init controller\n");
|
|
|
|
fdctrl->fifo = qemu_memalign(512, FD_SECTOR_LEN);
|
2019-05-29 18:20:27 +00:00
|
|
|
memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
|
2009-09-10 01:04:37 +00:00
|
|
|
fdctrl->fifo_size = 512;
|
2013-08-21 15:03:08 +00:00
|
|
|
fdctrl->result_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
|
2013-07-17 12:14:41 +00:00
|
|
|
fdctrl_result_timer, fdctrl);
|
2009-07-20 06:56:23 +00:00
|
|
|
|
|
|
|
fdctrl->version = 0x90; /* Intel 82078 controller */
|
|
|
|
fdctrl->config = FD_CONFIG_EIS | FD_CONFIG_EFIFO; /* Implicit seek, polling & FIFO enabled */
|
2009-09-10 01:04:37 +00:00
|
|
|
fdctrl->num_floppies = MAX_FD;
|
2009-07-20 06:56:23 +00:00
|
|
|
|
2016-10-27 20:29:13 +00:00
|
|
|
floppy_bus_create(fdctrl, &fdctrl->bus, dev);
|
2021-03-09 16:12:12 +00:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_FD; i++) {
|
|
|
|
drive = &fdctrl->drives[i];
|
|
|
|
drive->fdctrl = fdctrl;
|
|
|
|
fd_init(drive);
|
|
|
|
fd_revalidate(drive);
|
|
|
|
}
|
2009-07-15 14:41:54 +00:00
|
|
|
}
|
|
|
|
|
2012-02-09 14:20:55 +00:00
|
|
|
static void fdc_register_types(void)
|
2009-07-15 14:41:54 +00:00
|
|
|
{
|
2016-10-27 20:29:13 +00:00
|
|
|
type_register_static(&floppy_bus_info);
|
2016-10-27 20:29:13 +00:00
|
|
|
type_register_static(&floppy_drive_info);
|
2009-07-15 14:41:54 +00:00
|
|
|
}
|
|
|
|
|
2012-02-09 14:20:55 +00:00
|
|
|
type_init(fdc_register_types)
|