VirtualBox

source: vbox/trunk/src/VBox/Devices/Storage/DevFdc.cpp@ 48089

Last change on this file since 48089 was 48081, checked in by vboxsync, 11 years ago

DevFdc: Allow reformatting a floppy.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 100.4 KB
Line 
1/* $Id: DevFdc.cpp 48081 2013-08-27 13:03:34Z vboxsync $ */
2/** @file
3 * VBox storage devices: Floppy disk controller
4 */
5
6/*
7 * Copyright (C) 2006-2013 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 * --------------------------------------------------------------------
17 *
18 * This code is based on:
19 *
20 * QEMU Floppy disk emulator (Intel 82078)
21 *
22 * Copyright (c) 2003 Jocelyn Mayer
23 *
24 * Permission is hereby granted, free of charge, to any person obtaining a copy
25 * of this software and associated documentation files (the "Software"), to deal
26 * in the Software without restriction, including without limitation the rights
27 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
28 * copies of the Software, and to permit persons to whom the Software is
29 * furnished to do so, subject to the following conditions:
30 *
31 * The above copyright notice and this permission notice shall be included in
32 * all copies or substantial portions of the Software.
33 *
34 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
37 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
40 * THE SOFTWARE.
41 *
42 */
43
44
45/*******************************************************************************
46* Header Files *
47*******************************************************************************/
48#define LOG_GROUP LOG_GROUP_DEV_FDC
49#include <VBox/vmm/pdmdev.h>
50#include <iprt/assert.h>
51#include <iprt/string.h>
52#include <iprt/uuid.h>
53
54#include "VBoxDD.h"
55#include "vl_vbox.h"
56
57#define FDC_SAVESTATE_CURRENT 2 /* The new and improved saved state. */
58#define FDC_SAVESTATE_OLD 1 /* The original saved state. */
59
60#define MAX_FD 2
61
62
63/********************************************************/
64/* debug Floppy devices */
65/* #define DEBUG_FLOPPY */
66
67#ifndef VBOX
68 #ifdef DEBUG_FLOPPY
69 #define FLOPPY_DPRINTF(fmt, args...) \
70 do { printf("FLOPPY: " fmt , ##args); } while (0)
71 #endif
72#else /* !VBOX */
73 # ifdef LOG_ENABLED
74 static void FLOPPY_DPRINTF (const char *fmt, ...)
75 {
76 if (LogIsEnabled ()) {
77 va_list args;
78 va_start (args, fmt);
79 RTLogLogger (NULL, NULL, "floppy: %N", fmt, &args); /* %N - nested va_list * type formatting call. */
80 va_end (args);
81 }
82 }
83 # else
84 DECLINLINE(void) FLOPPY_DPRINTF(const char *pszFmt, ...) {}
85 # endif
86#endif /* !VBOX */
87
88#ifndef VBOX
89#define FLOPPY_ERROR(fmt, args...) \
90 do { printf("FLOPPY ERROR: %s: " fmt, __func__ , ##args); } while (0)
91#else /* VBOX */
92# define FLOPPY_ERROR RTLogPrintf
93#endif /* VBOX */
94
95#ifdef VBOX
96typedef struct fdctrl_t fdctrl_t;
97#endif /* VBOX */
98
99/********************************************************/
100/* Floppy drive emulation */
101
102#define GET_CUR_DRV(fdctrl) ((fdctrl)->cur_drv)
103#define SET_CUR_DRV(fdctrl, drive) ((fdctrl)->cur_drv = (drive))
104
105/* Will always be a fixed parameter for us */
106#define FD_SECTOR_LEN 512
107#define FD_SECTOR_SC 2 /* Sector size code */
108#define FD_RESET_SENSEI_COUNT 4 /* Number of sense interrupts on RESET */
109
110/* Floppy disk drive emulation */
111typedef enum fdisk_type_t {
112 FDRIVE_DISK_288 = 0x01, /* 2.88 MB disk */
113 FDRIVE_DISK_144 = 0x02, /* 1.44 MB disk */
114 FDRIVE_DISK_720 = 0x03, /* 720 kB disk */
115 FDRIVE_DISK_USER = 0x04, /* User defined geometry */
116 FDRIVE_DISK_NONE = 0x05 /* No disk */
117} fdisk_type_t;
118
119typedef enum fdrive_type_t {
120 FDRIVE_DRV_144 = 0x00, /* 1.44 MB 3"5 drive */
121 FDRIVE_DRV_288 = 0x01, /* 2.88 MB 3"5 drive */
122 FDRIVE_DRV_120 = 0x02, /* 1.2 MB 5"25 drive */
123 FDRIVE_DRV_NONE = 0x03 /* No drive connected */
124#ifdef VBOX
125 , FDRIVE_DRV_FAKE_15_6 = 0x0e /* Fake 15.6 MB drive. */
126 , FDRIVE_DRV_FAKE_63_5 = 0x0f /* Fake 63.5 MB drive. */
127#endif
128} fdrive_type_t;
129
130typedef uint8_t fdrive_flags_t;
131#define FDISK_DBL_SIDES UINT8_C(0x01)
132
133typedef enum fdrive_rate_t {
134 FDRIVE_RATE_500K = 0x00, /* 500 Kbps */
135 FDRIVE_RATE_300K = 0x01, /* 300 Kbps */
136 FDRIVE_RATE_250K = 0x02, /* 250 Kbps */
137 FDRIVE_RATE_1M = 0x03 /* 1 Mbps */
138} fdrive_rate_t;
139
140/**
141 * The status for one drive.
142 *
143 * @implements PDMIBASE
144 * @implements PDMIBLOCKPORT
145 * @implements PDMIMOUNTNOTIFY
146 */
147typedef struct fdrive_t {
148#ifndef VBOX
149 BlockDriverState *bs;
150#else /* VBOX */
151 /** Pointer to the attached driver's base interface. */
152 R3PTRTYPE(PPDMIBASE) pDrvBase;
153 /** Pointer to the attached driver's block interface. */
154 R3PTRTYPE(PPDMIBLOCK) pDrvBlock;
155 /** Pointer to the attached driver's block bios interface. */
156 R3PTRTYPE(PPDMIBLOCKBIOS) pDrvBlockBios;
157 /** Pointer to the attached driver's mount interface.
158 * This is NULL if the driver isn't a removable unit. */
159 R3PTRTYPE(PPDMIMOUNT) pDrvMount;
160 /** The base interface. */
161 PDMIBASE IBase;
162 /** The block port interface. */
163 PDMIBLOCKPORT IPort;
164 /** The mount notify interface. */
165 PDMIMOUNTNOTIFY IMountNotify;
166 /** The LUN #. */
167 RTUINT iLUN;
168 /** The LED for this LUN. */
169 PDMLED Led;
170#endif
171 /* Drive status */
172 fdrive_type_t drive;
173 uint8_t perpendicular; /* 2.88 MB access mode */
174 uint8_t dsk_chg; /* Disk change line */
175 /* Position */
176 uint8_t head;
177 uint8_t track;
178 uint8_t sect;
179 uint8_t ltrk; /* Logical track */
180 /* Media */
181 fdrive_flags_t flags;
182 uint8_t last_sect; /* Nb sector per track */
183 uint8_t max_track; /* Nb of tracks */
184 uint16_t bps; /* Bytes per sector */
185 uint8_t ro; /* Is read-only */
186 uint8_t media_rate; /* Data rate of medium */
187} fdrive_t;
188
189#define NUM_SIDES(drv) (drv->flags & FDISK_DBL_SIDES ? 2 : 1)
190
191static void fd_init(fdrive_t *drv, bool fInit)
192{
193 /* Drive */
194#ifndef VBOX
195 drv->drive = FDRIVE_DRV_NONE;
196#else /* VBOX */
197 if (fInit) {
198 /* Fixate the drive type at init time if possible. */
199 if (drv->pDrvBlock) {
200 PDMBLOCKTYPE enmType = drv->pDrvBlock->pfnGetType(drv->pDrvBlock);
201 switch (enmType) {
202 case PDMBLOCKTYPE_FLOPPY_360:
203 case PDMBLOCKTYPE_FLOPPY_1_20:
204 drv->drive = FDRIVE_DRV_120;
205 break;
206 case PDMBLOCKTYPE_FLOPPY_720:
207 case PDMBLOCKTYPE_FLOPPY_1_44:
208 drv->drive = FDRIVE_DRV_144;
209 break;
210 default:
211 AssertFailed();
212 case PDMBLOCKTYPE_FLOPPY_2_88:
213 drv->drive = FDRIVE_DRV_288;
214 break;
215 case PDMBLOCKTYPE_FLOPPY_FAKE_15_6:
216 drv->drive = FDRIVE_DRV_FAKE_15_6;
217 break;
218 case PDMBLOCKTYPE_FLOPPY_FAKE_63_5:
219 drv->drive = FDRIVE_DRV_FAKE_63_5;
220 break;
221 }
222 } else {
223 drv->drive = FDRIVE_DRV_NONE;
224 }
225 } /* else: The BIOS (and others) get the drive type via the CMOS, so
226 don't change it after the VM has been constructed. */
227#endif /* VBOX */
228 drv->perpendicular = 0;
229 /* Disk */
230 drv->last_sect = 0;
231 drv->max_track = 0;
232}
233
234static int fd_sector_calc(uint8_t head, uint8_t track, uint8_t sect,
235 uint8_t last_sect, uint8_t num_sides)
236{
237 return (((track * num_sides) + head) * last_sect) + sect - 1; /* sect >= 1 */
238}
239
240/* Returns current position, in sectors, for given drive */
241static int fd_sector(fdrive_t *drv)
242{
243 return fd_sector_calc(drv->head, drv->track, drv->sect, drv->last_sect, NUM_SIDES(drv));
244}
245
246/* Seek to a new position:
247 * returns 0 if already on right track
248 * returns 1 if track changed
249 * returns 2 if track is invalid
250 * returns 3 if sector is invalid
251 * returns 4 if seek is disabled
252 */
253static int fd_seek(fdrive_t *drv, uint8_t head, uint8_t track, uint8_t sect,
254 int enable_seek)
255{
256 int sector;
257 int ret;
258
259 if (track > drv->max_track ||
260 (head != 0 && (drv->flags & FDISK_DBL_SIDES) == 0)) {
261 FLOPPY_DPRINTF("try to read %d %02x %02x (max=%d %d %02x %02x)\n",
262 head, track, sect, 1,
263 (drv->flags & FDISK_DBL_SIDES) == 0 ? 0 : 1,
264 drv->max_track, drv->last_sect);
265 return 2;
266 }
267 if (sect > drv->last_sect || sect < 1) {
268 FLOPPY_DPRINTF("try to read %d %02x %02x (max=%d %d %02x %02x)\n",
269 head, track, sect, 1,
270 (drv->flags & FDISK_DBL_SIDES) == 0 ? 0 : 1,
271 drv->max_track, drv->last_sect);
272 return 3;
273 }
274 sector = fd_sector_calc(head, track, sect, drv->last_sect, NUM_SIDES(drv));
275 ret = 0;
276 if (sector != fd_sector(drv)) {
277#if 0
278 if (!enable_seek) {
279 FLOPPY_ERROR("no implicit seek %d %02x %02x (max=%d %02x %02x)\n",
280 head, track, sect, 1, drv->max_track, drv->last_sect);
281 return 4;
282 }
283#endif
284 drv->head = head;
285 if (drv->track != track)
286 ret = 1;
287 drv->track = track;
288 drv->sect = sect;
289 }
290 drv->ltrk = drv->track;
291
292 return ret;
293}
294
295/* Set drive back to track 0 */
296static void fd_recalibrate(fdrive_t *drv)
297{
298 FLOPPY_DPRINTF("recalibrate\n");
299 drv->head = 0;
300 drv->track = 0;
301 drv->ltrk = 0;
302 drv->sect = 1;
303}
304
305/* Recognize floppy formats */
306typedef struct fd_format_t {
307 fdrive_type_t drive;
308 fdisk_type_t disk;
309 uint8_t last_sect; /**< Number of sectors. */
310 uint8_t max_track; /**< Number of tracks. */
311 uint8_t max_head; /**< Max head number. */
312 fdrive_rate_t rate;
313 const char *str;
314} fd_format_t;
315
316/* Note: Low-density disks (160K/180K/320K/360K) use 250 Kbps data rate
317 * in 40-track drives, but 300 Kbps in high-capacity 80-track drives.
318 */
319static fd_format_t fd_formats[] = {
320 /* First entry is default format */
321 /* 1.44 MB 3"1/2 floppy disks */
322 { FDRIVE_DRV_144, FDRIVE_DISK_144, 18, 80, 1, FDRIVE_RATE_500K, "1.44 MB 3\"1/2", },
323 { FDRIVE_DRV_144, FDRIVE_DISK_144, 20, 80, 1, FDRIVE_RATE_500K, "1.6 MB 3\"1/2", },
324 { FDRIVE_DRV_144, FDRIVE_DISK_144, 21, 80, 1, FDRIVE_RATE_500K, "1.68 MB 3\"1/2", },
325 { FDRIVE_DRV_144, FDRIVE_DISK_144, 21, 82, 1, FDRIVE_RATE_500K, "1.72 MB 3\"1/2", },
326 { FDRIVE_DRV_144, FDRIVE_DISK_144, 21, 83, 1, FDRIVE_RATE_500K, "1.74 MB 3\"1/2", },
327 { FDRIVE_DRV_144, FDRIVE_DISK_144, 22, 80, 1, FDRIVE_RATE_500K, "1.76 MB 3\"1/2", },
328 { FDRIVE_DRV_144, FDRIVE_DISK_144, 23, 80, 1, FDRIVE_RATE_500K, "1.84 MB 3\"1/2", },
329 { FDRIVE_DRV_144, FDRIVE_DISK_144, 24, 80, 1, FDRIVE_RATE_500K, "1.92 MB 3\"1/2", },
330 /* 2.88 MB 3"1/2 floppy disks */
331 { FDRIVE_DRV_288, FDRIVE_DISK_288, 36, 80, 1, FDRIVE_RATE_1M, "2.88 MB 3\"1/2", },
332 { FDRIVE_DRV_288, FDRIVE_DISK_288, 39, 80, 1, FDRIVE_RATE_1M, "3.12 MB 3\"1/2", },
333 { FDRIVE_DRV_288, FDRIVE_DISK_288, 40, 80, 1, FDRIVE_RATE_1M, "3.2 MB 3\"1/2", },
334 { FDRIVE_DRV_288, FDRIVE_DISK_288, 44, 80, 1, FDRIVE_RATE_1M, "3.52 MB 3\"1/2", },
335 { FDRIVE_DRV_288, FDRIVE_DISK_288, 48, 80, 1, FDRIVE_RATE_1M, "3.84 MB 3\"1/2", },
336 /* 720 kB 3"1/2 floppy disks */
337 { FDRIVE_DRV_144, FDRIVE_DISK_720, 9, 80, 1, FDRIVE_RATE_250K, "720 kB 3\"1/2", },
338 { FDRIVE_DRV_144, FDRIVE_DISK_720, 10, 80, 1, FDRIVE_RATE_250K, "800 kB 3\"1/2", },
339 { FDRIVE_DRV_144, FDRIVE_DISK_720, 10, 82, 1, FDRIVE_RATE_250K, "820 kB 3\"1/2", },
340 { FDRIVE_DRV_144, FDRIVE_DISK_720, 10, 83, 1, FDRIVE_RATE_250K, "830 kB 3\"1/2", },
341 { FDRIVE_DRV_144, FDRIVE_DISK_720, 13, 80, 1, FDRIVE_RATE_250K, "1.04 MB 3\"1/2", },
342 { FDRIVE_DRV_144, FDRIVE_DISK_720, 14, 80, 1, FDRIVE_RATE_250K, "1.12 MB 3\"1/2", },
343 /* 1.2 MB 5"1/4 floppy disks */
344 { FDRIVE_DRV_120, FDRIVE_DISK_288, 15, 80, 1, FDRIVE_RATE_500K, "1.2 MB 5\"1/4", },
345 { FDRIVE_DRV_120, FDRIVE_DISK_288, 18, 80, 1, FDRIVE_RATE_500K, "1.44 MB 5\"1/4", },
346 { FDRIVE_DRV_120, FDRIVE_DISK_288, 18, 82, 1, FDRIVE_RATE_500K, "1.48 MB 5\"1/4", },
347 { FDRIVE_DRV_120, FDRIVE_DISK_288, 18, 83, 1, FDRIVE_RATE_500K, "1.49 MB 5\"1/4", },
348 { FDRIVE_DRV_120, FDRIVE_DISK_288, 20, 80, 1, FDRIVE_RATE_500K, "1.6 MB 5\"1/4", },
349 /* 720 kB 5"1/4 floppy disks */
350 { FDRIVE_DRV_120, FDRIVE_DISK_288, 9, 80, 1, FDRIVE_RATE_250K, "720 kB 5\"1/4", },
351 { FDRIVE_DRV_120, FDRIVE_DISK_288, 11, 80, 1, FDRIVE_RATE_250K, "880 kB 5\"1/4", },
352 /* 360 kB 5"1/4 floppy disks (newer 9-sector formats) */
353 { FDRIVE_DRV_120, FDRIVE_DISK_288, 9, 40, 1, FDRIVE_RATE_300K, "360 kB 5\"1/4", },
354 { FDRIVE_DRV_120, FDRIVE_DISK_288, 9, 40, 0, FDRIVE_RATE_300K, "180 kB 5\"1/4", },
355 { FDRIVE_DRV_120, FDRIVE_DISK_288, 10, 41, 1, FDRIVE_RATE_300K, "410 kB 5\"1/4", },
356 { FDRIVE_DRV_120, FDRIVE_DISK_288, 10, 42, 1, FDRIVE_RATE_300K, "420 kB 5\"1/4", },
357 /* 320 kB 5"1/4 floppy disks (old 8-sector formats) */
358 { FDRIVE_DRV_120, FDRIVE_DISK_288, 8, 40, 1, FDRIVE_RATE_300K, "320 kB 5\"1/4", },
359 { FDRIVE_DRV_120, FDRIVE_DISK_288, 8, 40, 0, FDRIVE_RATE_300K, "160 kB 5\"1/4", },
360 /* 1.2 MB and low density 3"1/2 floppy 'aliases' */
361 { FDRIVE_DRV_144, FDRIVE_DISK_144, 15, 80, 1, FDRIVE_RATE_500K, " 1.2 MB 3\"1/2", },
362 { FDRIVE_DRV_144, FDRIVE_DISK_720, 9, 40, 1, FDRIVE_RATE_300K, "360 kB 3\"1/2", },
363 { FDRIVE_DRV_144, FDRIVE_DISK_720, 9, 40, 0, FDRIVE_RATE_300K, "180 kB 3\"1/2", },
364 { FDRIVE_DRV_144, FDRIVE_DISK_720, 8, 40, 1, FDRIVE_RATE_300K, "320 kB 3\"1/2", },
365 { FDRIVE_DRV_144, FDRIVE_DISK_720, 8, 40, 0, FDRIVE_RATE_300K, "160 kB 3\"1/2", },
366#ifdef VBOX /* For larger than real life floppy images (see DrvBlock.cpp). */
367 /* 15.6 MB fake floppy disk (just need something big). */
368 { FDRIVE_DRV_FAKE_15_6, FDRIVE_DISK_USER, 63, 255, 1, FDRIVE_RATE_1M, "15.6 MB 3\"1/2", },
369 { FDRIVE_DRV_FAKE_15_6, FDRIVE_DISK_288, 36, 80, 1, FDRIVE_RATE_1M, "2.88 MB 3\"1/2", },
370 { FDRIVE_DRV_FAKE_15_6, FDRIVE_DISK_288, 39, 80, 1, FDRIVE_RATE_1M, "3.12 MB 3\"1/2", },
371 { FDRIVE_DRV_FAKE_15_6, FDRIVE_DISK_288, 40, 80, 1, FDRIVE_RATE_1M, "3.2 MB 3\"1/2", },
372 { FDRIVE_DRV_FAKE_15_6, FDRIVE_DISK_288, 44, 80, 1, FDRIVE_RATE_1M, "3.52 MB 3\"1/2", },
373 { FDRIVE_DRV_FAKE_15_6, FDRIVE_DISK_288, 48, 80, 1, FDRIVE_RATE_1M, "3.84 MB 3\"1/2", },
374 { FDRIVE_DRV_FAKE_15_6, FDRIVE_DISK_144, 18, 80, 1, FDRIVE_RATE_500K, "1.44 MB 3\"1/2", },
375 { FDRIVE_DRV_FAKE_15_6, FDRIVE_DISK_144, 20, 80, 1, FDRIVE_RATE_500K, "1.6 MB 3\"1/2", },
376 { FDRIVE_DRV_FAKE_15_6, FDRIVE_DISK_144, 21, 80, 1, FDRIVE_RATE_500K, "1.68 MB 3\"1/2", },
377 { FDRIVE_DRV_FAKE_15_6, FDRIVE_DISK_144, 21, 82, 1, FDRIVE_RATE_500K, "1.72 MB 3\"1/2", },
378 { FDRIVE_DRV_FAKE_15_6, FDRIVE_DISK_144, 21, 83, 1, FDRIVE_RATE_500K, "1.74 MB 3\"1/2", },
379 { FDRIVE_DRV_FAKE_15_6, FDRIVE_DISK_144, 22, 80, 1, FDRIVE_RATE_500K, "1.76 MB 3\"1/2", },
380 { FDRIVE_DRV_FAKE_15_6, FDRIVE_DISK_144, 23, 80, 1, FDRIVE_RATE_500K, "1.84 MB 3\"1/2", },
381 { FDRIVE_DRV_FAKE_15_6, FDRIVE_DISK_144, 24, 80, 1, FDRIVE_RATE_500K, "1.92 MB 3\"1/2", },
382 { FDRIVE_DRV_FAKE_15_6, FDRIVE_DISK_720, 9, 80, 1, FDRIVE_RATE_250K, "720 kB 3\"1/2", },
383 { FDRIVE_DRV_FAKE_15_6, FDRIVE_DISK_720, 10, 80, 1, FDRIVE_RATE_250K, "800 kB 3\"1/2", },
384 { FDRIVE_DRV_FAKE_15_6, FDRIVE_DISK_720, 10, 82, 1, FDRIVE_RATE_250K, "820 kB 3\"1/2", },
385 { FDRIVE_DRV_FAKE_15_6, FDRIVE_DISK_720, 10, 83, 1, FDRIVE_RATE_250K, "830 kB 3\"1/2", },
386 { FDRIVE_DRV_FAKE_15_6, FDRIVE_DISK_720, 13, 80, 1, FDRIVE_RATE_250K, "1.04 MB 3\"1/2", },
387 { FDRIVE_DRV_FAKE_15_6, FDRIVE_DISK_720, 14, 80, 1, FDRIVE_RATE_250K, "1.12 MB 3\"1/2", },
388 { FDRIVE_DRV_FAKE_15_6, FDRIVE_DISK_720, 9, 80, 0, FDRIVE_RATE_250K, "360 kB 3\"1/2", },
389 /* 63.5 MB fake floppy disk (just need something big). */
390 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_USER, 255, 255, 1, FDRIVE_RATE_1M, "63.5 MB 3\"1/2", },
391 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_USER, 63, 255, 1, FDRIVE_RATE_1M, "15.6 MB 3\"1/2", },
392 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_288, 36, 80, 1, FDRIVE_RATE_1M, "2.88 MB 3\"1/2", },
393 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_288, 39, 80, 1, FDRIVE_RATE_1M, "3.12 MB 3\"1/2", },
394 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_288, 40, 80, 1, FDRIVE_RATE_1M, "3.2 MB 3\"1/2", },
395 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_288, 44, 80, 1, FDRIVE_RATE_1M, "3.52 MB 3\"1/2", },
396 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_288, 48, 80, 1, FDRIVE_RATE_1M, "3.84 MB 3\"1/2", },
397 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_144, 18, 80, 1, FDRIVE_RATE_500K, "1.44 MB 3\"1/2", },
398 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_144, 20, 80, 1, FDRIVE_RATE_500K, "1.6 MB 3\"1/2", },
399 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_144, 21, 80, 1, FDRIVE_RATE_500K, "1.68 MB 3\"1/2", },
400 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_144, 21, 82, 1, FDRIVE_RATE_500K, "1.72 MB 3\"1/2", },
401 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_144, 21, 83, 1, FDRIVE_RATE_500K, "1.74 MB 3\"1/2", },
402 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_144, 22, 80, 1, FDRIVE_RATE_500K, "1.76 MB 3\"1/2", },
403 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_144, 23, 80, 1, FDRIVE_RATE_500K, "1.84 MB 3\"1/2", },
404 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_144, 24, 80, 1, FDRIVE_RATE_500K, "1.92 MB 3\"1/2", },
405 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_720, 9, 80, 1, FDRIVE_RATE_250K, "720 kB 3\"1/2", },
406 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_720, 10, 80, 1, FDRIVE_RATE_250K, "800 kB 3\"1/2", },
407 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_720, 10, 82, 1, FDRIVE_RATE_250K, "820 kB 3\"1/2", },
408 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_720, 10, 83, 1, FDRIVE_RATE_250K, "830 kB 3\"1/2", },
409 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_720, 13, 80, 1, FDRIVE_RATE_250K, "1.04 MB 3\"1/2", },
410 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_720, 14, 80, 1, FDRIVE_RATE_250K, "1.12 MB 3\"1/2", },
411 { FDRIVE_DRV_FAKE_63_5, FDRIVE_DISK_720, 9, 80, 0, FDRIVE_RATE_250K, "360 kB 3\"1/2", },
412#endif
413 /* end */
414 { FDRIVE_DRV_NONE, FDRIVE_DISK_NONE, (uint8_t)-1, (uint8_t)-1, 0, (fdrive_rate_t)0, NULL, },
415};
416
417/* Revalidate a disk drive after a disk change */
418static void fd_revalidate(fdrive_t *drv)
419{
420 const fd_format_t *parse;
421 uint64_t nb_sectors, size;
422 int i, first_match, match;
423 int nb_heads, max_track, last_sect, ro;
424
425 FLOPPY_DPRINTF("revalidate\n");
426#ifndef VBOX
427 if (drv->bs != NULL && bdrv_is_inserted(drv->bs)) {
428 ro = bdrv_is_read_only(drv->bs);
429 bdrv_get_geometry_hint(drv->bs, &nb_heads, &max_track, &last_sect);
430#else /* VBOX */
431 if ( drv->pDrvBlock
432 && drv->pDrvMount
433 && drv->pDrvMount->pfnIsMounted (drv->pDrvMount)) {
434 ro = drv->pDrvBlock->pfnIsReadOnly (drv->pDrvBlock);
435 nb_heads = max_track = last_sect = 0;
436#endif /* VBOX */
437 if (nb_heads != 0 && max_track != 0 && last_sect != 0) {
438 FLOPPY_DPRINTF("User defined disk (%d %d %d)",
439 nb_heads - 1, max_track, last_sect);
440 } else {
441#ifndef VBOX
442 bdrv_get_geometry(drv->bs, &nb_sectors);
443#else /* VBOX */
444 {
445 uint64_t size2 = drv->pDrvBlock->pfnGetSize (drv->pDrvBlock);
446 nb_sectors = size2 / FD_SECTOR_LEN;
447 }
448#endif /* VBOX */
449 match = -1;
450 first_match = -1;
451 for (i = 0;; i++) {
452 parse = &fd_formats[i];
453 if (parse->drive == FDRIVE_DRV_NONE)
454 break;
455 if (drv->drive == parse->drive ||
456 drv->drive == FDRIVE_DRV_NONE) {
457 size = (parse->max_head + 1) * parse->max_track *
458 parse->last_sect;
459 if (nb_sectors == size) {
460 match = i;
461 break;
462 }
463 if (first_match == -1)
464 first_match = i;
465 }
466 }
467 if (match == -1) {
468 if (first_match == -1)
469 match = 1;
470 else
471 match = first_match;
472 parse = &fd_formats[match];
473 }
474 nb_heads = parse->max_head + 1;
475 max_track = parse->max_track;
476 last_sect = parse->last_sect;
477 drv->drive = parse->drive;
478#ifdef VBOX
479 drv->media_rate = parse->rate;
480#endif
481 FLOPPY_DPRINTF("%s floppy disk (%d h %d t %d s) %s\n", parse->str,
482 nb_heads, max_track, last_sect, ro ? "ro" : "rw");
483 LogRel(("%s floppy disk (%d h %d t %d s) %s\n", parse->str,
484 nb_heads, max_track, last_sect, ro ? "ro" : "rw"));
485 }
486 if (nb_heads == 1) {
487 drv->flags &= ~FDISK_DBL_SIDES;
488 } else {
489 drv->flags |= FDISK_DBL_SIDES;
490 }
491 drv->max_track = max_track;
492 drv->last_sect = last_sect;
493 drv->ro = ro;
494 } else {
495 FLOPPY_DPRINTF("No disk in drive\n");
496 drv->last_sect = 0;
497 drv->max_track = 0;
498 drv->flags &= ~FDISK_DBL_SIDES;
499 drv->dsk_chg = true; /* Disk change line active. */
500 }
501}
502
503/********************************************************/
504/* Intel 82078 floppy disk controller emulation */
505
506static void fdctrl_reset(fdctrl_t *fdctrl, int do_irq);
507static void fdctrl_reset_fifo(fdctrl_t *fdctrl);
508#ifndef VBOX
509static int fdctrl_transfer_handler (void *opaque, int nchan,
510 int dma_pos, int dma_len);
511#else /* VBOX: */
512static DECLCALLBACK(uint32_t) fdctrl_transfer_handler (PPDMDEVINS pDevIns,
513 void *opaque,
514 unsigned nchan,
515 uint32_t dma_pos,
516 uint32_t dma_len);
517#endif /* VBOX */
518static void fdctrl_raise_irq(fdctrl_t *fdctrl, uint8_t status0);
519static fdrive_t *get_cur_drv(fdctrl_t *fdctrl);
520
521static void fdctrl_result_timer(void *opaque);
522static uint32_t fdctrl_read_statusA(fdctrl_t *fdctrl);
523static uint32_t fdctrl_read_statusB(fdctrl_t *fdctrl);
524static uint32_t fdctrl_read_dor(fdctrl_t *fdctrl);
525static void fdctrl_write_dor(fdctrl_t *fdctrl, uint32_t value);
526static uint32_t fdctrl_read_tape(fdctrl_t *fdctrl);
527static void fdctrl_write_tape(fdctrl_t *fdctrl, uint32_t value);
528static uint32_t fdctrl_read_main_status(fdctrl_t *fdctrl);
529static void fdctrl_write_rate(fdctrl_t *fdctrl, uint32_t value);
530static uint32_t fdctrl_read_data(fdctrl_t *fdctrl);
531static void fdctrl_write_data(fdctrl_t *fdctrl, uint32_t value);
532static uint32_t fdctrl_read_dir(fdctrl_t *fdctrl);
533static void fdctrl_write_ccr(fdctrl_t *fdctrl, uint32_t value);
534
535enum {
536 FD_DIR_WRITE = 0,
537 FD_DIR_READ = 1,
538 FD_DIR_SCANE = 2,
539 FD_DIR_SCANL = 3,
540 FD_DIR_SCANH = 4,
541 FD_DIR_FORMAT = 5
542};
543
544enum {
545 FD_STATE_MULTI = 0x01, /* multi track flag */
546 FD_STATE_FORMAT = 0x02, /* format flag */
547 FD_STATE_SEEK = 0x04 /* seek flag */
548};
549
550enum {
551 FD_REG_SRA = 0x00,
552 FD_REG_SRB = 0x01,
553 FD_REG_DOR = 0x02,
554 FD_REG_TDR = 0x03,
555 FD_REG_MSR = 0x04,
556 FD_REG_DSR = 0x04,
557 FD_REG_FIFO = 0x05,
558 FD_REG_DIR = 0x07,
559 FD_REG_CCR = 0x07
560};
561
562enum {
563 FD_CMD_READ_TRACK = 0x02,
564 FD_CMD_SPECIFY = 0x03,
565 FD_CMD_SENSE_DRIVE_STATUS = 0x04,
566 FD_CMD_WRITE = 0x05,
567 FD_CMD_READ = 0x06,
568 FD_CMD_RECALIBRATE = 0x07,
569 FD_CMD_SENSE_INTERRUPT_STATUS = 0x08,
570 FD_CMD_WRITE_DELETED = 0x09,
571 FD_CMD_READ_ID = 0x0a,
572 FD_CMD_READ_DELETED = 0x0c,
573 FD_CMD_FORMAT_TRACK = 0x0d,
574 FD_CMD_DUMPREG = 0x0e,
575 FD_CMD_SEEK = 0x0f,
576 FD_CMD_VERSION = 0x10,
577 FD_CMD_SCAN_EQUAL = 0x11,
578 FD_CMD_PERPENDICULAR_MODE = 0x12,
579 FD_CMD_CONFIGURE = 0x13,
580 FD_CMD_LOCK = 0x14,
581 FD_CMD_VERIFY = 0x16,
582 FD_CMD_POWERDOWN_MODE = 0x17,
583 FD_CMD_PART_ID = 0x18,
584 FD_CMD_SCAN_LOW_OR_EQUAL = 0x19,
585 FD_CMD_SCAN_HIGH_OR_EQUAL = 0x1d,
586 FD_CMD_SAVE = 0x2e,
587 FD_CMD_OPTION = 0x33,
588 FD_CMD_RESTORE = 0x4e,
589 FD_CMD_DRIVE_SPECIFICATION_COMMAND = 0x8e,
590 FD_CMD_RELATIVE_SEEK_OUT = 0x8f,
591 FD_CMD_FORMAT_AND_WRITE = 0xcd,
592 FD_CMD_RELATIVE_SEEK_IN = 0xcf
593};
594
595enum {
596 FD_CONFIG_PRETRK = 0xff, /* Pre-compensation set to track 0 */
597 FD_CONFIG_FIFOTHR = 0x0f, /* FIFO threshold set to 1 byte */
598 FD_CONFIG_POLL = 0x10, /* Poll enabled */
599 FD_CONFIG_EFIFO = 0x20, /* FIFO disabled */
600 FD_CONFIG_EIS = 0x40 /* No implied seeks */
601};
602
603enum {
604 FD_SR0_EQPMT = 0x10,
605 FD_SR0_SEEK = 0x20,
606 FD_SR0_ABNTERM = 0x40,
607 FD_SR0_INVCMD = 0x80,
608 FD_SR0_RDYCHG = 0xc0
609};
610
611enum {
612 FD_SR1_MA = 0x01, /* Missing address mark */
613 FD_SR1_NW = 0x02, /* Not writable */
614 FD_SR1_ND = 0x04, /* No data */
615 FD_SR1_EC = 0x80 /* End of cylinder */
616};
617
618enum {
619 FD_SR2_MD = 0x01, /* Missing data address mark */
620 FD_SR2_SNS = 0x04, /* Scan not satisfied */
621 FD_SR2_SEH = 0x08 /* Scan equal hit */
622};
623
624enum {
625 FD_SRA_DIR = 0x01,
626 FD_SRA_nWP = 0x02,
627 FD_SRA_nINDX = 0x04,
628 FD_SRA_HDSEL = 0x08,
629 FD_SRA_nTRK0 = 0x10,
630 FD_SRA_STEP = 0x20,
631 FD_SRA_nDRV2 = 0x40,
632 FD_SRA_INTPEND = 0x80
633};
634
635enum {
636 FD_SRB_MTR0 = 0x01,
637 FD_SRB_MTR1 = 0x02,
638 FD_SRB_WGATE = 0x04,
639 FD_SRB_RDATA = 0x08,
640 FD_SRB_WDATA = 0x10,
641 FD_SRB_DR0 = 0x20
642};
643
644enum {
645#if MAX_FD == 4
646 FD_DOR_SELMASK = 0x03,
647#else
648 FD_DOR_SELMASK = 0x01,
649#endif
650 FD_DOR_nRESET = 0x04,
651 FD_DOR_DMAEN = 0x08,
652 FD_DOR_MOTEN0 = 0x10,
653 FD_DOR_MOTEN1 = 0x20,
654 FD_DOR_MOTEN2 = 0x40,
655 FD_DOR_MOTEN3 = 0x80
656};
657
658enum {
659#if MAX_FD == 4
660 FD_TDR_BOOTSEL = 0x0c
661#else
662 FD_TDR_BOOTSEL = 0x04
663#endif
664};
665
666enum {
667 FD_DSR_DRATEMASK= 0x03,
668 FD_DSR_PWRDOWN = 0x40,
669 FD_DSR_SWRESET = 0x80
670};
671
672enum {
673 FD_MSR_DRV0BUSY = 0x01,
674 FD_MSR_DRV1BUSY = 0x02,
675 FD_MSR_DRV2BUSY = 0x04,
676 FD_MSR_DRV3BUSY = 0x08,
677 FD_MSR_CMDBUSY = 0x10,
678 FD_MSR_NONDMA = 0x20,
679 FD_MSR_DIO = 0x40,
680 FD_MSR_RQM = 0x80
681};
682
683enum {
684 FD_DIR_DSKCHG = 0x80
685};
686
687#define FD_MULTI_TRACK(state) ((state) & FD_STATE_MULTI)
688#define FD_DID_SEEK(state) ((state) & FD_STATE_SEEK)
689#define FD_FORMAT_CMD(state) ((state) & FD_STATE_FORMAT)
690
691#ifdef VBOX
692/**
693 * Floppy controller state.
694 *
695 * @implements PDMILEDPORTS
696 */
697#endif
698struct fdctrl_t {
699#ifndef VBOX
700 fdctrl_t *fdctrl;
701#endif
702 /* Controller's identification */
703 uint8_t version;
704 /* HW */
705#ifndef VBOX
706 int irq;
707 int dma_chann;
708#else
709 uint8_t irq_lvl;
710 uint8_t dma_chann;
711#endif
712 uint32_t io_base;
713 /* Controller state */
714 QEMUTimer *result_timer;
715 uint8_t sra;
716 uint8_t srb;
717 uint8_t dor;
718 uint8_t tdr;
719 uint8_t dsr;
720 uint8_t msr;
721 uint8_t cur_drv;
722 uint8_t status0;
723 uint8_t status1;
724 uint8_t status2;
725 /* Command FIFO */
726 uint8_t fifo[FD_SECTOR_LEN];
727 uint32_t data_pos;
728 uint32_t data_len;
729 uint8_t data_state;
730 uint8_t data_dir;
731 uint8_t eot; /* last wanted sector */
732 /* States kept only to be returned back */
733 /* Timers state */
734 uint8_t timer0;
735 uint8_t timer1;
736 /* precompensation */
737 uint8_t precomp_trk;
738 uint8_t config;
739 uint8_t lock;
740 /* Power down config (also with status regB access mode */
741 uint8_t pwrd;
742 /* Floppy drives */
743 uint8_t num_floppies;
744 fdrive_t drives[MAX_FD];
745 uint8_t reset_sensei;
746#ifdef VBOX
747 /** Pointer to device instance. */
748 PPDMDEVINS pDevIns;
749
750 /** Status LUN: The base interface. */
751 PDMIBASE IBaseStatus;
752 /** Status LUN: The Leds interface. */
753 PDMILEDPORTS ILeds;
754 /** Status LUN: The Partner of ILeds. */
755 PPDMILEDCONNECTORS pLedsConnector;
756#endif
757};
758
759static uint32_t fdctrl_read (void *opaque, uint32_t reg)
760{
761 fdctrl_t *fdctrl = (fdctrl_t *)opaque;
762 uint32_t retval;
763
764 switch (reg) {
765 case FD_REG_SRA:
766 retval = fdctrl_read_statusA(fdctrl);
767 break;
768 case FD_REG_SRB:
769 retval = fdctrl_read_statusB(fdctrl);
770 break;
771 case FD_REG_DOR:
772 retval = fdctrl_read_dor(fdctrl);
773 break;
774 case FD_REG_TDR:
775 retval = fdctrl_read_tape(fdctrl);
776 break;
777 case FD_REG_MSR:
778 retval = fdctrl_read_main_status(fdctrl);
779 break;
780 case FD_REG_FIFO:
781 retval = fdctrl_read_data(fdctrl);
782 break;
783 case FD_REG_DIR:
784 retval = fdctrl_read_dir(fdctrl);
785 break;
786 default:
787 retval = (uint32_t)(-1);
788 break;
789 }
790 FLOPPY_DPRINTF("read reg%d: 0x%02x\n", reg & 7, retval);
791
792 return retval;
793}
794
795static void fdctrl_write (void *opaque, uint32_t reg, uint32_t value)
796{
797 fdctrl_t *fdctrl = (fdctrl_t *)opaque;
798
799 FLOPPY_DPRINTF("write reg%d: 0x%02x\n", reg & 7, value);
800
801 switch (reg) {
802 case FD_REG_DOR:
803 fdctrl_write_dor(fdctrl, value);
804 break;
805 case FD_REG_TDR:
806 fdctrl_write_tape(fdctrl, value);
807 break;
808 case FD_REG_DSR:
809 fdctrl_write_rate(fdctrl, value);
810 break;
811 case FD_REG_FIFO:
812 fdctrl_write_data(fdctrl, value);
813 break;
814 case FD_REG_CCR:
815 fdctrl_write_ccr(fdctrl, value);
816 break;
817 default:
818 break;
819 }
820}
821
822/* Change IRQ state */
823static void fdctrl_reset_irq(fdctrl_t *fdctrl)
824{
825 if (!(fdctrl->sra & FD_SRA_INTPEND))
826 return;
827 FLOPPY_DPRINTF("Reset interrupt\n");
828#ifdef VBOX
829 PDMDevHlpISASetIrq (fdctrl->pDevIns, fdctrl->irq_lvl, 0);
830#else
831 qemu_set_irq(fdctrl->irq, 0);
832#endif
833 fdctrl->sra &= ~FD_SRA_INTPEND;
834}
835
836static void fdctrl_raise_irq(fdctrl_t *fdctrl, uint8_t status0)
837{
838 if (!(fdctrl->sra & FD_SRA_INTPEND)) {
839 FLOPPY_DPRINTF("Raising interrupt...\n");
840#ifdef VBOX
841 PDMDevHlpISASetIrq (fdctrl->pDevIns, fdctrl->irq_lvl, 1);
842#else
843 qemu_set_irq(fdctrl->irq, 1);
844#endif
845 fdctrl->sra |= FD_SRA_INTPEND;
846 }
847 if (status0 & FD_SR0_SEEK) {
848 fdrive_t *cur_drv;
849
850 /* A seek clears the disk change line (if a disk is inserted). */
851 cur_drv = get_cur_drv(fdctrl);
852 if (cur_drv->max_track)
853 cur_drv->dsk_chg = false;
854 }
855
856 fdctrl->reset_sensei = 0;
857 fdctrl->status0 = status0;
858 FLOPPY_DPRINTF("Set interrupt status to 0x%02x\n", fdctrl->status0);
859}
860
861/* Reset controller */
862static void fdctrl_reset(fdctrl_t *fdctrl, int do_irq)
863{
864 int i;
865
866 FLOPPY_DPRINTF("reset controller\n");
867 fdctrl_reset_irq(fdctrl);
868 /* Initialise controller */
869 fdctrl->sra = 0;
870 fdctrl->srb = 0xc0;
871#ifdef VBOX
872 if (!fdctrl->drives[1].pDrvBlock)
873#else
874 if (!fdctrl->drives[1].bs)
875#endif
876 fdctrl->sra |= FD_SRA_nDRV2;
877 fdctrl->cur_drv = 0;
878 fdctrl->dor = FD_DOR_nRESET;
879 fdctrl->dor |= (fdctrl->dma_chann != 0xff) ? FD_DOR_DMAEN : 0;
880 fdctrl->msr = FD_MSR_RQM;
881 /* FIFO state */
882 fdctrl->data_pos = 0;
883 fdctrl->data_len = 0;
884 fdctrl->data_state = 0;
885 fdctrl->data_dir = FD_DIR_WRITE;
886 for (i = 0; i < MAX_FD; i++)
887 fd_recalibrate(&fdctrl->drives[i]);
888 fdctrl_reset_fifo(fdctrl);
889 if (do_irq) {
890 fdctrl_raise_irq(fdctrl, FD_SR0_RDYCHG);
891 fdctrl->reset_sensei = FD_RESET_SENSEI_COUNT;
892 }
893}
894
895static inline fdrive_t *drv0(fdctrl_t *fdctrl)
896{
897 return &fdctrl->drives[(fdctrl->tdr & FD_TDR_BOOTSEL) >> 2];
898}
899
900static inline fdrive_t *drv1(fdctrl_t *fdctrl)
901{
902 if ((fdctrl->tdr & FD_TDR_BOOTSEL) < (1 << 2))
903 return &fdctrl->drives[1];
904 else
905 return &fdctrl->drives[0];
906}
907
908#if MAX_FD == 4
909static inline fdrive_t *drv2(fdctrl_t *fdctrl)
910{
911 if ((fdctrl->tdr & FD_TDR_BOOTSEL) < (2 << 2))
912 return &fdctrl->drives[2];
913 else
914 return &fdctrl->drives[1];
915}
916
917static inline fdrive_t *drv3(fdctrl_t *fdctrl)
918{
919 if ((fdctrl->tdr & FD_TDR_BOOTSEL) < (3 << 2))
920 return &fdctrl->drives[3];
921 else
922 return &fdctrl->drives[2];
923}
924#endif
925
926static fdrive_t *get_cur_drv(fdctrl_t *fdctrl)
927{
928 switch (fdctrl->cur_drv) {
929 case 0: return drv0(fdctrl);
930 case 1: return drv1(fdctrl);
931#if MAX_FD == 4
932 case 2: return drv2(fdctrl);
933 case 3: return drv3(fdctrl);
934#endif
935 default: return NULL;
936 }
937}
938
939/* Status A register : 0x00 (read-only) */
940static uint32_t fdctrl_read_statusA(fdctrl_t *fdctrl)
941{
942 uint32_t retval = fdctrl->sra;
943
944 FLOPPY_DPRINTF("status register A: 0x%02x\n", retval);
945
946 return retval;
947}
948
949/* Status B register : 0x01 (read-only) */
950static uint32_t fdctrl_read_statusB(fdctrl_t *fdctrl)
951{
952 uint32_t retval = fdctrl->srb;
953
954 FLOPPY_DPRINTF("status register B: 0x%02x\n", retval);
955
956 return retval;
957}
958
959/* Digital output register : 0x02 */
960static uint32_t fdctrl_read_dor(fdctrl_t *fdctrl)
961{
962 uint32_t retval = fdctrl->dor;
963
964 /* Selected drive */
965 retval |= fdctrl->cur_drv;
966 FLOPPY_DPRINTF("digital output register: 0x%02x\n", retval);
967
968 return retval;
969}
970
971static void fdctrl_write_dor(fdctrl_t *fdctrl, uint32_t value)
972{
973 FLOPPY_DPRINTF("digital output register set to 0x%02x\n", value);
974
975 /* Motors */
976 if (value & FD_DOR_MOTEN0)
977 fdctrl->srb |= FD_SRB_MTR0;
978 else
979 fdctrl->srb &= ~FD_SRB_MTR0;
980 if (value & FD_DOR_MOTEN1)
981 fdctrl->srb |= FD_SRB_MTR1;
982 else
983 fdctrl->srb &= ~FD_SRB_MTR1;
984
985 /* Drive */
986 if (value & 1)
987 fdctrl->srb |= FD_SRB_DR0;
988 else
989 fdctrl->srb &= ~FD_SRB_DR0;
990
991 /* Reset */
992 if (!(value & FD_DOR_nRESET)) {
993 if (fdctrl->dor & FD_DOR_nRESET) {
994 FLOPPY_DPRINTF("controller enter RESET state\n");
995 }
996 } else {
997 if (!(fdctrl->dor & FD_DOR_nRESET)) {
998 FLOPPY_DPRINTF("controller out of RESET state\n");
999 fdctrl_reset(fdctrl, 1);
1000 fdctrl->dsr &= ~FD_DSR_PWRDOWN;
1001 }
1002 }
1003 /* Selected drive */
1004 fdctrl->cur_drv = value & FD_DOR_SELMASK;
1005
1006 fdctrl->dor = value;
1007}
1008
1009/* Tape drive register : 0x03 */
1010static uint32_t fdctrl_read_tape(fdctrl_t *fdctrl)
1011{
1012 uint32_t retval = fdctrl->tdr;
1013
1014 FLOPPY_DPRINTF("tape drive register: 0x%02x\n", retval);
1015
1016 return retval;
1017}
1018
1019static void fdctrl_write_tape(fdctrl_t *fdctrl, uint32_t value)
1020{
1021 /* Reset mode */
1022 if (!(fdctrl->dor & FD_DOR_nRESET)) {
1023 FLOPPY_DPRINTF("Floppy controller in RESET state !\n");
1024 return;
1025 }
1026 FLOPPY_DPRINTF("tape drive register set to 0x%02x\n", value);
1027 /* Disk boot selection indicator */
1028 fdctrl->tdr = value & FD_TDR_BOOTSEL;
1029 /* Tape indicators: never allow */
1030}
1031
1032/* Main status register : 0x04 (read) */
1033static uint32_t fdctrl_read_main_status(fdctrl_t *fdctrl)
1034{
1035 uint32_t retval = fdctrl->msr;
1036
1037 fdctrl->dsr &= ~FD_DSR_PWRDOWN;
1038 fdctrl->dor |= FD_DOR_nRESET;
1039
1040 FLOPPY_DPRINTF("main status register: 0x%02x\n", retval);
1041
1042 return retval;
1043}
1044
1045/* Data select rate register : 0x04 (write) */
1046static void fdctrl_write_rate(fdctrl_t *fdctrl, uint32_t value)
1047{
1048 /* Reset mode */
1049 if (!(fdctrl->dor & FD_DOR_nRESET)) {
1050 FLOPPY_DPRINTF("Floppy controller in RESET state !\n");
1051 return;
1052 }
1053 FLOPPY_DPRINTF("select rate register set to 0x%02x\n", value);
1054 /* Reset: autoclear */
1055 if (value & FD_DSR_SWRESET) {
1056 fdctrl->dor &= ~FD_DOR_nRESET;
1057 fdctrl_reset(fdctrl, 1);
1058 fdctrl->dor |= FD_DOR_nRESET;
1059 }
1060 if (value & FD_DSR_PWRDOWN) {
1061 fdctrl_reset(fdctrl, 1);
1062 }
1063 fdctrl->dsr = value;
1064}
1065
1066/* Configuration control register : 0x07 (write) */
1067static void fdctrl_write_ccr(fdctrl_t *fdctrl, uint32_t value)
1068{
1069 /* Reset mode */
1070 if (!(fdctrl->dor & FD_DOR_nRESET)) {
1071 FLOPPY_DPRINTF("Floppy controller in RESET state !\n");
1072 return;
1073 }
1074 FLOPPY_DPRINTF("configuration control register set to 0x%02x\n", value);
1075
1076 /* Only the rate selection bits used in AT mode, and we
1077 * store those in the DSR.
1078 */
1079 fdctrl->dsr = (fdctrl->dsr & ~FD_DSR_DRATEMASK) | (value & FD_DSR_DRATEMASK);
1080}
1081
1082static int fdctrl_media_changed(fdrive_t *drv)
1083{
1084#ifdef VBOX
1085 return drv->dsk_chg;
1086#else
1087 int ret;
1088
1089 if (!drv->bs)
1090 return 0;
1091 ret = bdrv_media_changed(drv->bs);
1092 if (ret) {
1093 fd_revalidate(drv);
1094 }
1095 return ret;
1096#endif
1097}
1098
1099/* Digital input register : 0x07 (read-only) */
1100static uint32_t fdctrl_read_dir(fdctrl_t *fdctrl)
1101{
1102 uint32_t retval = 0;
1103
1104#ifdef VBOX
1105 /* The change line signal is reported by the currently selected
1106 * drive. If the corresponding motor on bit is not set, the drive
1107 * is *not* selected!
1108 */
1109 if (fdctrl_media_changed(get_cur_drv(fdctrl))
1110 && (fdctrl->dor & (0x10 << fdctrl->cur_drv)))
1111#else
1112 if (fdctrl_media_changed(drv0(fdctrl))
1113 || fdctrl_media_changed(drv1(fdctrl))
1114#if MAX_FD == 4
1115 || fdctrl_media_changed(drv2(fdctrl))
1116 || fdctrl_media_changed(drv3(fdctrl))
1117#endif
1118 )
1119#endif
1120 retval |= FD_DIR_DSKCHG;
1121 if (retval != 0)
1122 FLOPPY_DPRINTF("Floppy digital input register: 0x%02x\n", retval);
1123
1124 return retval;
1125}
1126
1127/* FIFO state control */
1128static void fdctrl_reset_fifo(fdctrl_t *fdctrl)
1129{
1130 fdctrl->data_dir = FD_DIR_WRITE;
1131 fdctrl->data_pos = 0;
1132 fdctrl->msr &= ~(FD_MSR_CMDBUSY | FD_MSR_DIO);
1133}
1134
1135/* Set FIFO status for the host to read */
1136static void fdctrl_set_fifo(fdctrl_t *fdctrl, int fifo_len, int do_irq)
1137{
1138 fdctrl->data_dir = FD_DIR_READ;
1139 fdctrl->data_len = fifo_len;
1140 fdctrl->data_pos = 0;
1141 fdctrl->msr |= FD_MSR_CMDBUSY | FD_MSR_RQM | FD_MSR_DIO;
1142 if (do_irq)
1143 fdctrl_raise_irq(fdctrl, 0x00);
1144}
1145
1146/* Set an error: unimplemented/unknown command */
1147static void fdctrl_unimplemented(fdctrl_t *fdctrl, int direction)
1148{
1149 FLOPPY_ERROR("unimplemented command 0x%02x\n", fdctrl->fifo[0]);
1150 fdctrl->fifo[0] = FD_SR0_INVCMD;
1151 fdctrl_set_fifo(fdctrl, 1, 0);
1152}
1153
1154/* Seek to next sector */
1155static int fdctrl_seek_to_next_sect(fdctrl_t *fdctrl, fdrive_t *cur_drv)
1156{
1157 FLOPPY_DPRINTF("seek to next sector (%d %02x %02x => %d)\n",
1158 cur_drv->head, cur_drv->track, cur_drv->sect,
1159 fd_sector(cur_drv));
1160 /* XXX: cur_drv->sect >= cur_drv->last_sect should be an
1161 error in fact */
1162 if (cur_drv->sect >= cur_drv->last_sect ||
1163 cur_drv->sect == fdctrl->eot) {
1164 cur_drv->sect = 1;
1165 if (FD_MULTI_TRACK(fdctrl->data_state)) {
1166 if (cur_drv->head == 0 &&
1167 (cur_drv->flags & FDISK_DBL_SIDES) != 0) {
1168 cur_drv->head = 1;
1169 } else {
1170 cur_drv->head = 0;
1171 cur_drv->ltrk++;
1172 if ((cur_drv->flags & FDISK_DBL_SIDES) == 0)
1173 return 0;
1174 }
1175 } else {
1176 cur_drv->ltrk++;
1177 return 0;
1178 }
1179 FLOPPY_DPRINTF("seek to next track (%d %02x %02x => %d)\n",
1180 cur_drv->head, cur_drv->track,
1181 cur_drv->sect, fd_sector(cur_drv));
1182 } else {
1183 cur_drv->sect++;
1184 }
1185 return 1;
1186}
1187
1188/* Callback for transfer end (stop or abort) */
1189static void fdctrl_stop_transfer(fdctrl_t *fdctrl, uint8_t status0,
1190 uint8_t status1, uint8_t status2)
1191{
1192 fdrive_t *cur_drv;
1193
1194 cur_drv = get_cur_drv(fdctrl);
1195 FLOPPY_DPRINTF("transfer status: %02x %02x %02x (%02x)\n",
1196 status0, status1, status2,
1197 status0 | (cur_drv->head << 2) | GET_CUR_DRV(fdctrl));
1198 fdctrl->fifo[0] = status0 | (cur_drv->head << 2) | GET_CUR_DRV(fdctrl);
1199 fdctrl->fifo[1] = status1;
1200 fdctrl->fifo[2] = status2;
1201 fdctrl->fifo[3] = cur_drv->ltrk;
1202 fdctrl->fifo[4] = cur_drv->head;
1203 fdctrl->fifo[5] = cur_drv->sect;
1204 fdctrl->fifo[6] = FD_SECTOR_SC;
1205 FLOPPY_DPRINTF("ST0:%02x ST1:%02x ST2:%02x C:%02x H:%02x R:%02x N:%02x\n",
1206 fdctrl->fifo[0], fdctrl->fifo[1], fdctrl->fifo[2], fdctrl->fifo[3],
1207 fdctrl->fifo[4], fdctrl->fifo[5], fdctrl->fifo[6]);
1208
1209 fdctrl->data_dir = FD_DIR_READ;
1210 if (!(fdctrl->msr & FD_MSR_NONDMA)) {
1211#ifdef VBOX
1212 PDMDevHlpDMASetDREQ (fdctrl->pDevIns, fdctrl->dma_chann, 0);
1213#else
1214 DMA_release_DREQ(fdctrl->dma_chann);
1215#endif
1216 }
1217 fdctrl->msr |= FD_MSR_RQM | FD_MSR_DIO;
1218 fdctrl->msr &= ~FD_MSR_NONDMA;
1219 fdctrl_set_fifo(fdctrl, 7, 1);
1220}
1221
1222/* Prepare a data transfer (either DMA or FIFO) */
1223static void fdctrl_start_transfer(fdctrl_t *fdctrl, int direction)
1224{
1225 fdrive_t *cur_drv;
1226 uint8_t kh, kt, ks;
1227 int did_seek = 0;
1228
1229 SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
1230 cur_drv = get_cur_drv(fdctrl);
1231 kt = fdctrl->fifo[2];
1232 kh = fdctrl->fifo[3];
1233 ks = fdctrl->fifo[4];
1234 FLOPPY_DPRINTF("Start transfer at %d %d %02x %02x (%d)\n",
1235 GET_CUR_DRV(fdctrl), kh, kt, ks,
1236 fd_sector_calc(kh, kt, ks, cur_drv->last_sect, NUM_SIDES(cur_drv)));
1237 FLOPPY_DPRINTF("CMD:%02x SEL:%02x C:%02x H:%02x R:%02x N:%02x EOT:%02x GPL:%02x DTL:%02x\n",
1238 fdctrl->fifo[0], fdctrl->fifo[1], fdctrl->fifo[2],
1239 fdctrl->fifo[3], fdctrl->fifo[4], fdctrl->fifo[5],
1240 fdctrl->fifo[6], fdctrl->fifo[7], fdctrl->fifo[8]);
1241 switch (fd_seek(cur_drv, kh, kt, ks, fdctrl->config & FD_CONFIG_EIS)) {
1242 case 2:
1243 /* sect too big */
1244 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
1245 fdctrl->fifo[3] = kt;
1246 fdctrl->fifo[4] = kh;
1247 fdctrl->fifo[5] = ks;
1248 return;
1249 case 3:
1250 /* track too big */
1251 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_EC, 0x00);
1252 fdctrl->fifo[3] = kt;
1253 fdctrl->fifo[4] = kh;
1254 fdctrl->fifo[5] = ks;
1255 return;
1256 case 4:
1257 /* No seek enabled */
1258 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
1259 fdctrl->fifo[3] = kt;
1260 fdctrl->fifo[4] = kh;
1261 fdctrl->fifo[5] = ks;
1262 return;
1263 case 1:
1264 did_seek = 1;
1265 break;
1266 default:
1267 break;
1268 }
1269 /* Check the data rate. If the programmed data rate does not match
1270 * the currently inserted medium, the operation has to fail.
1271 */
1272#ifdef VBOX
1273 if ((fdctrl->dsr & FD_DSR_DRATEMASK) != cur_drv->media_rate) {
1274 FLOPPY_DPRINTF("data rate mismatch (fdc=%d, media=%d)\n",
1275 fdctrl->dsr & FD_DSR_DRATEMASK, cur_drv->media_rate);
1276 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_MA, FD_SR2_MD);
1277 fdctrl->fifo[3] = kt;
1278 fdctrl->fifo[4] = kh;
1279 fdctrl->fifo[5] = ks;
1280 return;
1281 }
1282#endif
1283 /* Set the FIFO state */
1284 fdctrl->data_dir = direction;
1285 fdctrl->data_pos = 0;
1286 fdctrl->msr |= FD_MSR_CMDBUSY;
1287 if (fdctrl->fifo[0] & 0x80)
1288 fdctrl->data_state |= FD_STATE_MULTI;
1289 else
1290 fdctrl->data_state &= ~FD_STATE_MULTI;
1291 if (did_seek)
1292 fdctrl->data_state |= FD_STATE_SEEK;
1293 else
1294 fdctrl->data_state &= ~FD_STATE_SEEK;
1295 if (fdctrl->fifo[5] == 00) {
1296 fdctrl->data_len = fdctrl->fifo[8];
1297 } else {
1298 int tmp;
1299 fdctrl->data_len = 128 << (fdctrl->fifo[5] > 7 ? 7 : fdctrl->fifo[5]);
1300 tmp = (fdctrl->fifo[6] - ks + 1);
1301 if (fdctrl->fifo[0] & 0x80)
1302 tmp += fdctrl->fifo[6];
1303 fdctrl->data_len *= tmp;
1304 }
1305 fdctrl->eot = fdctrl->fifo[6];
1306 if (fdctrl->dor & FD_DOR_DMAEN) {
1307 int dma_mode;
1308 /* DMA transfer are enabled. Check if DMA channel is well programmed */
1309#ifndef VBOX
1310 dma_mode = DMA_get_channel_mode(fdctrl->dma_chann);
1311#else
1312 dma_mode = PDMDevHlpDMAGetChannelMode (fdctrl->pDevIns, fdctrl->dma_chann);
1313#endif
1314 dma_mode = (dma_mode >> 2) & 3;
1315 FLOPPY_DPRINTF("dma_mode=%d direction=%d (%d - %d)\n",
1316 dma_mode, direction,
1317 (128 << fdctrl->fifo[5]) *
1318 (cur_drv->last_sect - ks + 1), fdctrl->data_len);
1319 if (((direction == FD_DIR_SCANE || direction == FD_DIR_SCANL ||
1320 direction == FD_DIR_SCANH) && dma_mode == 0) ||
1321 (direction == FD_DIR_WRITE && dma_mode == 2) ||
1322 (direction == FD_DIR_READ && (dma_mode == 1 || dma_mode == 0))) {
1323 /* No access is allowed until DMA transfer has completed */
1324 fdctrl->msr &= ~FD_MSR_RQM;
1325 /* Now, we just have to wait for the DMA controller to
1326 * recall us...
1327 */
1328#ifndef VBOX
1329 DMA_hold_DREQ(fdctrl->dma_chann);
1330 DMA_schedule(fdctrl->dma_chann);
1331#else
1332 PDMDevHlpDMASetDREQ (fdctrl->pDevIns, fdctrl->dma_chann, 1);
1333 PDMDevHlpDMASchedule (fdctrl->pDevIns);
1334#endif
1335 return;
1336 } else {
1337 FLOPPY_ERROR("dma_mode=%d direction=%d\n", dma_mode, direction);
1338 }
1339 }
1340 FLOPPY_DPRINTF("start non-DMA transfer\n");
1341 fdctrl->msr |= FD_MSR_NONDMA;
1342 if (direction != FD_DIR_WRITE)
1343 fdctrl->msr |= FD_MSR_DIO;
1344 /* IO based transfer: calculate len */
1345 fdctrl_raise_irq(fdctrl, 0x00);
1346
1347 return;
1348}
1349
1350/* Prepare a format data transfer (either DMA or FIFO) */
1351static void fdctrl_start_format(fdctrl_t *fdctrl)
1352{
1353 fdrive_t *cur_drv;
1354 uint8_t ns, dp, kh, kt, ks;
1355
1356 SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
1357 cur_drv = get_cur_drv(fdctrl);
1358 kt = cur_drv->track;
1359 kh = (fdctrl->fifo[1] & 0x04) >> 2;
1360 ns = fdctrl->fifo[3];
1361 dp = fdctrl->fifo[5];
1362 ks = 1;
1363 FLOPPY_DPRINTF("Start format at %d %d %02x, %d sect, pat %02x (%d)\n",
1364 GET_CUR_DRV(fdctrl), kh, kt, ns, dp,
1365 fd_sector_calc(kh, kt, ks, cur_drv->last_sect, NUM_SIDES(cur_drv)));
1366 switch (fd_seek(cur_drv, kh, kt, ks, false)) {
1367 case 2:
1368 /* sect too big */
1369 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
1370 fdctrl->fifo[3] = kt;
1371 fdctrl->fifo[4] = kh;
1372 fdctrl->fifo[5] = ks;
1373 return;
1374 case 3:
1375 /* track too big */
1376 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_EC, 0x00);
1377 fdctrl->fifo[3] = kt;
1378 fdctrl->fifo[4] = kh;
1379 fdctrl->fifo[5] = ks;
1380 return;
1381 case 4:
1382 /* No seek enabled */
1383 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
1384 fdctrl->fifo[3] = kt;
1385 fdctrl->fifo[4] = kh;
1386 fdctrl->fifo[5] = ks;
1387 return;
1388 case 1:
1389 break;
1390 default:
1391 break;
1392 }
1393 /* It's not clear what should happen if the data rate does not match. */
1394#if 0
1395 /* Check the data rate. If the programmed data rate does not match
1396 * the currently inserted medium, the operation has to fail.
1397 */
1398 if ((fdctrl->dsr & FD_DSR_DRATEMASK) != cur_drv->media_rate) {
1399 FLOPPY_DPRINTF("data rate mismatch (fdc=%d, media=%d)\n",
1400 fdctrl->dsr & FD_DSR_DRATEMASK, cur_drv->media_rate);
1401 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_MA, FD_SR2_MD);
1402 fdctrl->fifo[3] = kt;
1403 fdctrl->fifo[4] = kh;
1404 fdctrl->fifo[5] = ks;
1405 return;
1406 }
1407#endif
1408 /* Set the FIFO state */
1409 fdctrl->data_dir = FD_DIR_FORMAT;
1410 fdctrl->data_pos = 0;
1411 fdctrl->msr |= FD_MSR_CMDBUSY;
1412 fdctrl->data_state &= ~(FD_STATE_MULTI | FD_STATE_SEEK);
1413 fdctrl->data_len = ns * 4;
1414 fdctrl->eot = ns;
1415 if (fdctrl->dor & FD_DOR_DMAEN) {
1416 int dma_mode;
1417 /* DMA transfer are enabled. Check if DMA channel is well programmed */
1418#ifndef VBOX
1419 dma_mode = DMA_get_channel_mode(fdctrl->dma_chann);
1420#else
1421 dma_mode = PDMDevHlpDMAGetChannelMode (fdctrl->pDevIns, fdctrl->dma_chann);
1422#endif
1423 dma_mode = (dma_mode >> 2) & 3;
1424 FLOPPY_DPRINTF("dma_mode=%d direction=%d (%d - %d)\n",
1425 dma_mode, fdctrl->data_dir,
1426 (128 << fdctrl->fifo[2]) *
1427 (cur_drv->last_sect + 1), fdctrl->data_len);
1428 if (fdctrl->data_dir == FD_DIR_FORMAT && dma_mode == 2) {
1429 /* No access is allowed until DMA transfer has completed */
1430 fdctrl->msr &= ~FD_MSR_RQM;
1431 /* Now, we just have to wait for the DMA controller to
1432 * recall us...
1433 */
1434#ifndef VBOX
1435 DMA_hold_DREQ(fdctrl->dma_chann);
1436 DMA_schedule(fdctrl->dma_chann);
1437#else
1438 PDMDevHlpDMASetDREQ (fdctrl->pDevIns, fdctrl->dma_chann, 1);
1439 PDMDevHlpDMASchedule (fdctrl->pDevIns);
1440#endif
1441 return;
1442 } else {
1443 FLOPPY_ERROR("dma_mode=%d direction=%d\n", dma_mode, fdctrl->data_dir);
1444 }
1445 }
1446 FLOPPY_DPRINTF("start non-DMA format\n");
1447 fdctrl->msr |= FD_MSR_NONDMA;
1448 /* IO based transfer: calculate len */
1449 fdctrl_raise_irq(fdctrl, 0x00);
1450
1451 return;
1452}
1453
1454/* Prepare a transfer of deleted data */
1455static void fdctrl_start_transfer_del(fdctrl_t *fdctrl, int direction)
1456{
1457 FLOPPY_ERROR("fdctrl_start_transfer_del() unimplemented\n");
1458
1459 /* We don't handle deleted data,
1460 * so we don't return *ANYTHING*
1461 */
1462 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
1463}
1464
1465#ifdef VBOX
1466/* Block driver read/write wrappers. */
1467
1468static int blk_write(fdrive_t *drv, int64_t sector_num, const uint8_t *buf, int nb_sectors)
1469{
1470 int rc;
1471
1472 drv->Led.Asserted.s.fWriting = drv->Led.Actual.s.fWriting = 1;
1473
1474 rc = drv->pDrvBlock->pfnWrite(drv->pDrvBlock, sector_num * FD_SECTOR_LEN,
1475 buf, nb_sectors * FD_SECTOR_LEN);
1476
1477 drv->Led.Actual.s.fWriting = 0;
1478 if (RT_FAILURE(rc))
1479 AssertMsgFailed(("Floppy: Failure to read sector %d. rc=%Rrc", sector_num, rc));
1480
1481 return rc;
1482}
1483
1484static int blk_read(fdrive_t *drv, int64_t sector_num, uint8_t *buf, int nb_sectors)
1485{
1486 int rc;
1487
1488 drv->Led.Asserted.s.fReading = drv->Led.Actual.s.fReading = 1;
1489
1490 rc = drv->pDrvBlock->pfnRead(drv->pDrvBlock, sector_num * FD_SECTOR_LEN,
1491 buf, nb_sectors * FD_SECTOR_LEN);
1492
1493 drv->Led.Actual.s.fReading = 0;
1494
1495 if (RT_FAILURE(rc))
1496 AssertMsgFailed(("Floppy: Failure to read sector %d. rc=%Rrc", sector_num, rc));
1497
1498 return rc;
1499}
1500
1501#endif
1502
1503/* handlers for DMA transfers */
1504#ifdef VBOX
1505static DECLCALLBACK(uint32_t) fdctrl_transfer_handler (PPDMDEVINS pDevIns,
1506 void *opaque,
1507 unsigned nchan,
1508 uint32_t dma_pos,
1509 uint32_t dma_len)
1510#else
1511static int fdctrl_transfer_handler (void *opaque, int nchan,
1512 int dma_pos, int dma_len)
1513#endif
1514{
1515 fdctrl_t *fdctrl;
1516 fdrive_t *cur_drv;
1517#ifdef VBOX
1518 int rc;
1519 uint32_t len, start_pos, rel_pos;
1520#else
1521 int len, start_pos, rel_pos;
1522#endif
1523 uint8_t status0 = 0x00, status1 = 0x00, status2 = 0x00;
1524
1525 fdctrl = (fdctrl_t *)opaque;
1526 if (fdctrl->msr & FD_MSR_RQM) {
1527 FLOPPY_DPRINTF("Not in DMA transfer mode !\n");
1528 return 0;
1529 }
1530 cur_drv = get_cur_drv(fdctrl);
1531 if (fdctrl->data_dir == FD_DIR_SCANE || fdctrl->data_dir == FD_DIR_SCANL ||
1532 fdctrl->data_dir == FD_DIR_SCANH)
1533 status2 = FD_SR2_SNS;
1534 if (dma_len > fdctrl->data_len)
1535 dma_len = fdctrl->data_len;
1536#ifndef VBOX
1537 if (cur_drv->bs == NULL)
1538#else /* !VBOX */
1539 if (cur_drv->pDrvBlock == NULL)
1540#endif
1541 {
1542 if (fdctrl->data_dir == FD_DIR_WRITE)
1543 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
1544 else
1545 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
1546 len = 0;
1547 goto transfer_error;
1548 }
1549
1550#ifdef VBOX
1551 if (cur_drv->ro)
1552 {
1553 if (fdctrl->data_dir == FD_DIR_WRITE || fdctrl->data_dir == FD_DIR_FORMAT)
1554 {
1555 /* Handle readonly medium early, no need to do DMA, touch the
1556 * LED or attempt any writes. A real floppy doesn't attempt
1557 * to write to readonly media either. */
1558 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, FD_SR1_NW,
1559 0x00);
1560 goto transfer_error;
1561 }
1562 }
1563#endif
1564
1565
1566 rel_pos = fdctrl->data_pos % FD_SECTOR_LEN;
1567 for (start_pos = fdctrl->data_pos; fdctrl->data_pos < dma_len;) {
1568 len = dma_len - fdctrl->data_pos;
1569 if (len + rel_pos > FD_SECTOR_LEN)
1570 len = FD_SECTOR_LEN - rel_pos;
1571 FLOPPY_DPRINTF("copy %d bytes (%d %d %d) %d pos %d %02x "
1572 "(%d-0x%08x 0x%08x)\n", len, dma_len, fdctrl->data_pos,
1573 fdctrl->data_len, GET_CUR_DRV(fdctrl), cur_drv->head,
1574 cur_drv->track, cur_drv->sect, fd_sector(cur_drv),
1575 fd_sector(cur_drv) * FD_SECTOR_LEN);
1576 if (fdctrl->data_dir != FD_DIR_FORMAT &&
1577 (fdctrl->data_dir != FD_DIR_WRITE ||
1578 len < FD_SECTOR_LEN || rel_pos != 0)) {
1579 /* READ & SCAN commands and realign to a sector for WRITE */
1580#ifdef VBOX
1581 rc = blk_read(cur_drv, fd_sector(cur_drv), fdctrl->fifo, 1);
1582 if (RT_FAILURE(rc))
1583#else
1584 if (bdrv_read(cur_drv->bs, fd_sector(cur_drv),
1585 fdctrl->fifo, 1) < 0)
1586#endif
1587 {
1588 FLOPPY_DPRINTF("Floppy: error getting sector %d\n",
1589 fd_sector(cur_drv));
1590 /* Sure, image size is too small... */
1591 memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
1592 }
1593 }
1594 switch (fdctrl->data_dir) {
1595 case FD_DIR_READ:
1596 /* READ commands */
1597#ifdef VBOX
1598 {
1599 uint32_t read;
1600 int rc2 = PDMDevHlpDMAWriteMemory(fdctrl->pDevIns, nchan,
1601 fdctrl->fifo + rel_pos,
1602 fdctrl->data_pos,
1603 len, &read);
1604 AssertMsgRC (rc2, ("DMAWriteMemory -> %Rrc\n", rc2));
1605 }
1606#else
1607 DMA_write_memory (nchan, fdctrl->fifo + rel_pos,
1608 fdctrl->data_pos, len);
1609#endif
1610/* cpu_physical_memory_write(addr + fdctrl->data_pos, */
1611/* fdctrl->fifo + rel_pos, len); */
1612 break;
1613 case FD_DIR_WRITE:
1614 /* WRITE commands */
1615#ifdef VBOX
1616 {
1617 uint32_t written;
1618 int rc2 = PDMDevHlpDMAReadMemory(fdctrl->pDevIns, nchan,
1619 fdctrl->fifo + rel_pos,
1620 fdctrl->data_pos,
1621 len, &written);
1622 AssertMsgRC (rc2, ("DMAReadMemory -> %Rrc\n", rc2));
1623 }
1624
1625 rc = blk_write(cur_drv, fd_sector(cur_drv), fdctrl->fifo, 1);
1626 if (RT_FAILURE(rc))
1627#else
1628 DMA_read_memory (nchan, fdctrl->fifo + rel_pos,
1629 fdctrl->data_pos, len);
1630 if (bdrv_write(cur_drv->bs, fd_sector(cur_drv),
1631 fdctrl->fifo, 1) < 0)
1632#endif
1633 {
1634 FLOPPY_ERROR("writing sector %d\n", fd_sector(cur_drv));
1635 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
1636 goto transfer_error;
1637 }
1638 break;
1639#ifdef VBOX
1640 case FD_DIR_FORMAT:
1641 /* FORMAT command */
1642 {
1643 uint8_t eot = fdctrl->fifo[3];
1644 uint8_t filler = fdctrl->fifo[5];
1645 uint32_t written;
1646 int sct;
1647 int rc2 = PDMDevHlpDMAReadMemory(fdctrl->pDevIns, nchan,
1648 fdctrl->fifo + rel_pos,
1649 fdctrl->data_pos,
1650 len, &written);
1651 AssertMsgRC (rc2, ("DMAReadMemory -> %Rrc\n", rc2));
1652
1653 /* Fill the entire track with desired data pattern. */
1654 FLOPPY_DPRINTF("formatting track: %d sectors, pattern %02x\n",
1655 eot, filler);
1656 memset(fdctrl->fifo, filler, FD_SECTOR_LEN);
1657 for (sct = 0; sct < eot; ++sct)
1658 {
1659 rc = blk_write(cur_drv, fd_sector(cur_drv), fdctrl->fifo, 1);
1660 if (RT_FAILURE(rc))
1661 {
1662 FLOPPY_ERROR("formatting sector %d\n", fd_sector(cur_drv));
1663 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
1664 goto transfer_error;
1665 }
1666 fdctrl_seek_to_next_sect(fdctrl, cur_drv);
1667 }
1668 }
1669 break;
1670#endif
1671 default:
1672 /* SCAN commands */
1673 {
1674 uint8_t tmpbuf[FD_SECTOR_LEN];
1675 int ret;
1676#ifdef VBOX
1677 uint32_t read;
1678 int rc2 = PDMDevHlpDMAReadMemory (fdctrl->pDevIns, nchan, tmpbuf,
1679 fdctrl->data_pos, len, &read);
1680 AssertMsg (RT_SUCCESS (rc2), ("DMAReadMemory -> %Rrc2\n", rc2));
1681#else
1682 DMA_read_memory (nchan, tmpbuf, fdctrl->data_pos, len);
1683#endif
1684 ret = memcmp(tmpbuf, fdctrl->fifo + rel_pos, len);
1685 if (ret == 0) {
1686 status2 = FD_SR2_SEH;
1687 goto end_transfer;
1688 }
1689 if ((ret < 0 && fdctrl->data_dir == FD_DIR_SCANL) ||
1690 (ret > 0 && fdctrl->data_dir == FD_DIR_SCANH)) {
1691 status2 = 0x00;
1692 goto end_transfer;
1693 }
1694 }
1695 break;
1696 }
1697 fdctrl->data_pos += len;
1698 rel_pos = fdctrl->data_pos % FD_SECTOR_LEN;
1699 if (rel_pos == 0) {
1700 /* Seek to next sector */
1701 if (!fdctrl_seek_to_next_sect(fdctrl, cur_drv))
1702 break;
1703 }
1704 }
1705end_transfer:
1706 len = fdctrl->data_pos - start_pos;
1707 FLOPPY_DPRINTF("end transfer %d %d %d\n",
1708 fdctrl->data_pos, len, fdctrl->data_len);
1709 if (fdctrl->data_dir == FD_DIR_SCANE ||
1710 fdctrl->data_dir == FD_DIR_SCANL ||
1711 fdctrl->data_dir == FD_DIR_SCANH)
1712 status2 = FD_SR2_SEH;
1713 if (FD_DID_SEEK(fdctrl->data_state))
1714 status0 |= FD_SR0_SEEK;
1715 fdctrl->data_len -= len;
1716 fdctrl_stop_transfer(fdctrl, status0, status1, status2);
1717transfer_error:
1718
1719 return len;
1720}
1721
1722/* Data register : 0x05 */
1723static uint32_t fdctrl_read_data(fdctrl_t *fdctrl)
1724{
1725 fdrive_t *cur_drv;
1726 uint32_t retval = 0;
1727 unsigned pos;
1728#ifdef VBOX
1729 int rc;
1730#endif
1731
1732 cur_drv = get_cur_drv(fdctrl);
1733 fdctrl->dsr &= ~FD_DSR_PWRDOWN;
1734 if (!(fdctrl->msr & FD_MSR_RQM) || !(fdctrl->msr & FD_MSR_DIO)) {
1735 FLOPPY_ERROR("controller not ready for reading\n");
1736 return 0;
1737 }
1738 pos = fdctrl->data_pos;
1739 if (fdctrl->msr & FD_MSR_NONDMA) {
1740 pos %= FD_SECTOR_LEN;
1741 if (pos == 0) {
1742 if (fdctrl->data_pos != 0)
1743 if (!fdctrl_seek_to_next_sect(fdctrl, cur_drv)) {
1744 FLOPPY_DPRINTF("error seeking to next sector %d\n",
1745 fd_sector(cur_drv));
1746 return 0;
1747 }
1748#ifdef VBOX
1749 rc = blk_read(cur_drv, fd_sector(cur_drv), fdctrl->fifo, 1);
1750 if (RT_FAILURE(rc))
1751#else
1752 if (bdrv_read(cur_drv->bs, fd_sector(cur_drv), fdctrl->fifo, 1) < 0)
1753#endif
1754 {
1755 FLOPPY_DPRINTF("error getting sector %d\n",
1756 fd_sector(cur_drv));
1757 /* Sure, image size is too small... */
1758 memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
1759 }
1760 }
1761 }
1762 retval = fdctrl->fifo[pos];
1763 if (++fdctrl->data_pos == fdctrl->data_len) {
1764 fdctrl->data_pos = 0;
1765 /* Switch from transfer mode to status mode
1766 * then from status mode to command mode
1767 */
1768 if (fdctrl->msr & FD_MSR_NONDMA) {
1769 fdctrl_stop_transfer(fdctrl, FD_SR0_SEEK, 0x00, 0x00);
1770 } else {
1771 fdctrl_reset_fifo(fdctrl);
1772 fdctrl_reset_irq(fdctrl);
1773 }
1774 }
1775 FLOPPY_DPRINTF("data register: 0x%02x\n", retval);
1776
1777 return retval;
1778}
1779
1780static void fdctrl_format_sector(fdctrl_t *fdctrl)
1781{
1782 fdrive_t *cur_drv;
1783 uint8_t kh, kt, ks;
1784#ifdef VBOX
1785 int ok = 0, rc;
1786#endif
1787
1788 SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
1789 cur_drv = get_cur_drv(fdctrl);
1790 kt = fdctrl->fifo[6];
1791 kh = fdctrl->fifo[7];
1792 ks = fdctrl->fifo[8];
1793 FLOPPY_DPRINTF("format sector at %d %d %02x %02x (%d)\n",
1794 GET_CUR_DRV(fdctrl), kh, kt, ks,
1795 fd_sector_calc(kh, kt, ks, cur_drv->last_sect, NUM_SIDES(cur_drv)));
1796 switch (fd_seek(cur_drv, kh, kt, ks, fdctrl->config & FD_CONFIG_EIS)) {
1797 case 2:
1798 /* sect too big */
1799 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
1800 fdctrl->fifo[3] = kt;
1801 fdctrl->fifo[4] = kh;
1802 fdctrl->fifo[5] = ks;
1803 return;
1804 case 3:
1805 /* track too big */
1806 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_EC, 0x00);
1807 fdctrl->fifo[3] = kt;
1808 fdctrl->fifo[4] = kh;
1809 fdctrl->fifo[5] = ks;
1810 return;
1811 case 4:
1812 /* No seek enabled */
1813 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, 0x00, 0x00);
1814 fdctrl->fifo[3] = kt;
1815 fdctrl->fifo[4] = kh;
1816 fdctrl->fifo[5] = ks;
1817 return;
1818 case 1:
1819 fdctrl->data_state |= FD_STATE_SEEK;
1820 break;
1821 default:
1822 break;
1823 }
1824 memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
1825#ifdef VBOX
1826 if (cur_drv->pDrvBlock) {
1827 rc = blk_write(cur_drv, fd_sector(cur_drv), fdctrl->fifo, 1);
1828 if (RT_FAILURE (rc)) {
1829 FLOPPY_ERROR("formatting sector %d\n", fd_sector(cur_drv));
1830 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
1831 } else {
1832 ok = 1;
1833 }
1834 }
1835 if (ok) {
1836#else
1837 if (cur_drv->bs == NULL ||
1838 bdrv_write(cur_drv->bs, fd_sector(cur_drv), fdctrl->fifo, 1) < 0) {
1839 FLOPPY_ERROR("formatting sector %d\n", fd_sector(cur_drv));
1840 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
1841 } else {
1842#endif
1843 if (cur_drv->sect == cur_drv->last_sect) {
1844 fdctrl->data_state &= ~FD_STATE_FORMAT;
1845 /* Last sector done */
1846 if (FD_DID_SEEK(fdctrl->data_state))
1847 fdctrl_stop_transfer(fdctrl, FD_SR0_SEEK, 0x00, 0x00);
1848 else
1849 fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00);
1850 } else {
1851 /* More to do */
1852 fdctrl->data_pos = 0;
1853 fdctrl->data_len = 4;
1854 }
1855 }
1856}
1857
1858static void fdctrl_handle_lock(fdctrl_t *fdctrl, int direction)
1859{
1860 fdctrl->lock = (fdctrl->fifo[0] & 0x80) ? 1 : 0;
1861 fdctrl->fifo[0] = fdctrl->lock << 4;
1862 fdctrl_set_fifo(fdctrl, 1, 0);
1863}
1864
1865static void fdctrl_handle_dumpreg(fdctrl_t *fdctrl, int direction)
1866{
1867 fdrive_t *cur_drv = get_cur_drv(fdctrl);
1868
1869 /* Drives position */
1870 fdctrl->fifo[0] = drv0(fdctrl)->track;
1871 fdctrl->fifo[1] = drv1(fdctrl)->track;
1872#if MAX_FD == 4
1873 fdctrl->fifo[2] = drv2(fdctrl)->track;
1874 fdctrl->fifo[3] = drv3(fdctrl)->track;
1875#else
1876 fdctrl->fifo[2] = 0;
1877 fdctrl->fifo[3] = 0;
1878#endif
1879 /* timers */
1880 fdctrl->fifo[4] = fdctrl->timer0;
1881 fdctrl->fifo[5] = (fdctrl->timer1 << 1) | (fdctrl->dor & FD_DOR_DMAEN ? 1 : 0);
1882 fdctrl->fifo[6] = cur_drv->last_sect;
1883 fdctrl->fifo[7] = (fdctrl->lock << 7) |
1884 (cur_drv->perpendicular << 2);
1885 fdctrl->fifo[8] = fdctrl->config;
1886 fdctrl->fifo[9] = fdctrl->precomp_trk;
1887 fdctrl_set_fifo(fdctrl, 10, 0);
1888}
1889
1890static void fdctrl_handle_version(fdctrl_t *fdctrl, int direction)
1891{
1892 /* Controller's version */
1893 fdctrl->fifo[0] = fdctrl->version;
1894 fdctrl_set_fifo(fdctrl, 1, 0);
1895}
1896
1897static void fdctrl_handle_partid(fdctrl_t *fdctrl, int direction)
1898{
1899 fdctrl->fifo[0] = 0x01; /* Stepping 1 */
1900 fdctrl_set_fifo(fdctrl, 1, 0);
1901}
1902
1903static void fdctrl_handle_restore(fdctrl_t *fdctrl, int direction)
1904{
1905 fdrive_t *cur_drv = get_cur_drv(fdctrl);
1906
1907 /* Drives position */
1908 drv0(fdctrl)->track = fdctrl->fifo[3];
1909 drv1(fdctrl)->track = fdctrl->fifo[4];
1910#if MAX_FD == 4
1911 drv2(fdctrl)->track = fdctrl->fifo[5];
1912 drv3(fdctrl)->track = fdctrl->fifo[6];
1913#endif
1914 /* timers */
1915 fdctrl->timer0 = fdctrl->fifo[7];
1916 fdctrl->timer1 = fdctrl->fifo[8];
1917 cur_drv->last_sect = fdctrl->fifo[9];
1918 fdctrl->lock = fdctrl->fifo[10] >> 7;
1919 cur_drv->perpendicular = (fdctrl->fifo[10] >> 2) & 0xF;
1920 fdctrl->config = fdctrl->fifo[11];
1921 fdctrl->precomp_trk = fdctrl->fifo[12];
1922 fdctrl->pwrd = fdctrl->fifo[13];
1923 fdctrl_reset_fifo(fdctrl);
1924}
1925
1926static void fdctrl_handle_save(fdctrl_t *fdctrl, int direction)
1927{
1928 fdrive_t *cur_drv = get_cur_drv(fdctrl);
1929
1930 fdctrl->fifo[0] = 0;
1931 fdctrl->fifo[1] = 0;
1932 /* Drives position */
1933 fdctrl->fifo[2] = drv0(fdctrl)->track;
1934 fdctrl->fifo[3] = drv1(fdctrl)->track;
1935#if MAX_FD == 4
1936 fdctrl->fifo[4] = drv2(fdctrl)->track;
1937 fdctrl->fifo[5] = drv3(fdctrl)->track;
1938#else
1939 fdctrl->fifo[4] = 0;
1940 fdctrl->fifo[5] = 0;
1941#endif
1942 /* timers */
1943 fdctrl->fifo[6] = fdctrl->timer0;
1944 fdctrl->fifo[7] = fdctrl->timer1;
1945 fdctrl->fifo[8] = cur_drv->last_sect;
1946 fdctrl->fifo[9] = (fdctrl->lock << 7) |
1947 (cur_drv->perpendicular << 2);
1948 fdctrl->fifo[10] = fdctrl->config;
1949 fdctrl->fifo[11] = fdctrl->precomp_trk;
1950 fdctrl->fifo[12] = fdctrl->pwrd;
1951 fdctrl->fifo[13] = 0;
1952 fdctrl->fifo[14] = 0;
1953 fdctrl_set_fifo(fdctrl, 15, 0);
1954}
1955
1956static void fdctrl_handle_readid(fdctrl_t *fdctrl, int direction)
1957{
1958 fdrive_t *cur_drv = get_cur_drv(fdctrl);
1959
1960 FLOPPY_DPRINTF("CMD:%02x SEL:%02x\n", fdctrl->fifo[0], fdctrl->fifo[1]);
1961
1962 /* XXX: should set main status register to busy */
1963 cur_drv->head = (fdctrl->fifo[1] >> 2) & 1;
1964#ifdef VBOX
1965 TMTimerSetMillies(fdctrl->result_timer, 1000 / 50);
1966#else
1967 qemu_mod_timer(fdctrl->result_timer,
1968 qemu_get_clock(vm_clock) + (get_ticks_per_sec() / 50));
1969#endif
1970}
1971
1972static void fdctrl_handle_format_track(fdctrl_t *fdctrl, int direction)
1973{
1974 fdrive_t *cur_drv;
1975 uint8_t ns, dp;
1976
1977 SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
1978 cur_drv = get_cur_drv(fdctrl);
1979 fdctrl->data_state &= ~(FD_STATE_MULTI | FD_STATE_SEEK);
1980 ns = fdctrl->fifo[3];
1981 dp = fdctrl->fifo[5];
1982
1983 FLOPPY_DPRINTF("Format track %d at %d, %d sectors, filler %02x\n",
1984 cur_drv->track, GET_CUR_DRV(fdctrl), ns, dp);
1985 FLOPPY_DPRINTF("CMD:%02x SEL:%02x N:%02x SC:%02x GPL:%02x D:%02x\n",
1986 fdctrl->fifo[0], fdctrl->fifo[1], fdctrl->fifo[2],
1987 fdctrl->fifo[3], fdctrl->fifo[4], fdctrl->fifo[5]);
1988
1989 /* Since we cannot actually format anything, we have to make sure that
1990 * whatever new format the guest is trying to establish matches the
1991 * existing format of the medium.
1992 */
1993 if (cur_drv->last_sect != ns || fdctrl->fifo[2] != 2)
1994 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_NW, 0);
1995 else
1996 {
1997 cur_drv->bps = fdctrl->fifo[2] > 7 ? 16384 : 128 << fdctrl->fifo[2];
1998 cur_drv->last_sect = ns;
1999
2000 fdctrl_start_format(fdctrl);
2001 }
2002}
2003
2004static void fdctrl_handle_specify(fdctrl_t *fdctrl, int direction)
2005{
2006 fdctrl->timer0 = (fdctrl->fifo[1] >> 4) & 0xF;
2007 fdctrl->timer1 = fdctrl->fifo[2] >> 1;
2008 if (fdctrl->fifo[2] & 1)
2009 fdctrl->dor &= ~FD_DOR_DMAEN;
2010 else
2011 fdctrl->dor |= FD_DOR_DMAEN;
2012 /* No result back */
2013 fdctrl_reset_fifo(fdctrl);
2014}
2015
2016static void fdctrl_handle_sense_drive_status(fdctrl_t *fdctrl, int direction)
2017{
2018 fdrive_t *cur_drv;
2019
2020 SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
2021 cur_drv = get_cur_drv(fdctrl);
2022 cur_drv->head = (fdctrl->fifo[1] >> 2) & 1;
2023 /* 1 Byte status back */
2024 fdctrl->fifo[0] = (cur_drv->ro << 6) |
2025 (cur_drv->track == 0 ? 0x10 : 0x00) |
2026 (cur_drv->head << 2) |
2027 GET_CUR_DRV(fdctrl) |
2028 0x28;
2029 fdctrl_set_fifo(fdctrl, 1, 0);
2030}
2031
2032static void fdctrl_handle_recalibrate(fdctrl_t *fdctrl, int direction)
2033{
2034 fdrive_t *cur_drv;
2035 uint8_t st0;
2036
2037 SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
2038 cur_drv = get_cur_drv(fdctrl);
2039 fd_recalibrate(cur_drv);
2040 fdctrl_reset_fifo(fdctrl);
2041 st0 = FD_SR0_SEEK | GET_CUR_DRV(fdctrl);
2042 /* No drive means no TRK0 signal. */
2043 if (cur_drv->drive == FDRIVE_DRV_NONE)
2044 st0 |= FD_SR0_ABNTERM | FD_SR0_EQPMT;
2045 /* Raise Interrupt */
2046 fdctrl_raise_irq(fdctrl, st0);
2047}
2048
2049static void fdctrl_handle_sense_interrupt_status(fdctrl_t *fdctrl, int direction)
2050{
2051 fdrive_t *cur_drv = get_cur_drv(fdctrl);
2052
2053 FLOPPY_DPRINTF("CMD:%02x\n", fdctrl->fifo[0]);
2054 if(fdctrl->reset_sensei > 0) {
2055 fdctrl->fifo[0] =
2056 FD_SR0_RDYCHG + FD_RESET_SENSEI_COUNT - fdctrl->reset_sensei;
2057 fdctrl->reset_sensei--;
2058 } else {
2059 /* XXX: status0 handling is broken for read/write
2060 commands, so we do this hack. It should be suppressed
2061 ASAP */
2062 fdctrl->fifo[0] =
2063 FD_SR0_SEEK | (cur_drv->head << 2) | GET_CUR_DRV(fdctrl);
2064 /* Hack to preserve SR0 on equipment check failures (no drive). */
2065 if (fdctrl->status0 & FD_SR0_EQPMT)
2066 fdctrl->fifo[0] = fdctrl->status0;
2067 }
2068
2069 fdctrl->fifo[1] = cur_drv->track;
2070 fdctrl_set_fifo(fdctrl, 2, 0);
2071 FLOPPY_DPRINTF("ST0:%02x PCN:%02x\n", fdctrl->fifo[0], fdctrl->fifo[1]);
2072 fdctrl->status0 = FD_SR0_RDYCHG;
2073}
2074
2075static void fdctrl_handle_seek(fdctrl_t *fdctrl, int direction)
2076{
2077 fdrive_t *cur_drv;
2078
2079 FLOPPY_DPRINTF("CMD:%02x SEL:%02x NCN:%02x\n", fdctrl->fifo[0],
2080 fdctrl->fifo[1], fdctrl->fifo[2]);
2081
2082 SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
2083 cur_drv = get_cur_drv(fdctrl);
2084 fdctrl_reset_fifo(fdctrl);
2085#ifdef VBOX
2086 /* The seek command just sends step pulses to the drive and doesn't care if
2087 * there's a medium inserted or if it's banging the head against the drive.
2088 */
2089 cur_drv->track = fdctrl->fifo[2];
2090 cur_drv->ltrk = cur_drv->track;
2091 /* Raise Interrupt */
2092 fdctrl_raise_irq(fdctrl, FD_SR0_SEEK | GET_CUR_DRV(fdctrl));
2093#else
2094 if (fdctrl->fifo[2] > cur_drv->max_track) {
2095 fdctrl_raise_irq(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK);
2096 } else {
2097 cur_drv->track = fdctrl->fifo[2];
2098 /* Raise Interrupt */
2099 fdctrl_raise_irq(fdctrl, FD_SR0_SEEK);
2100 }
2101#endif
2102}
2103
2104static void fdctrl_handle_perpendicular_mode(fdctrl_t *fdctrl, int direction)
2105{
2106 fdrive_t *cur_drv = get_cur_drv(fdctrl);
2107
2108 if (fdctrl->fifo[1] & 0x80)
2109 cur_drv->perpendicular = fdctrl->fifo[1] & 0x7;
2110 /* No result back */
2111 fdctrl_reset_fifo(fdctrl);
2112}
2113
2114static void fdctrl_handle_configure(fdctrl_t *fdctrl, int direction)
2115{
2116 fdctrl->config = fdctrl->fifo[2];
2117 fdctrl->precomp_trk = fdctrl->fifo[3];
2118 /* No result back */
2119 fdctrl_reset_fifo(fdctrl);
2120}
2121
2122static void fdctrl_handle_powerdown_mode(fdctrl_t *fdctrl, int direction)
2123{
2124 fdctrl->pwrd = fdctrl->fifo[1];
2125 fdctrl->fifo[0] = fdctrl->fifo[1];
2126 fdctrl_set_fifo(fdctrl, 1, 0);
2127}
2128
2129static void fdctrl_handle_option(fdctrl_t *fdctrl, int direction)
2130{
2131 /* No result back */
2132 fdctrl_reset_fifo(fdctrl);
2133}
2134
2135static void fdctrl_handle_drive_specification_command(fdctrl_t *fdctrl, int direction)
2136{
2137 fdrive_t *cur_drv = get_cur_drv(fdctrl);
2138
2139 if (fdctrl->fifo[fdctrl->data_pos - 1] & 0x80) {
2140 /* Command parameters done */
2141 if (fdctrl->fifo[fdctrl->data_pos - 1] & 0x40) {
2142 fdctrl->fifo[0] = fdctrl->fifo[1];
2143 fdctrl->fifo[2] = 0;
2144 fdctrl->fifo[3] = 0;
2145 fdctrl_set_fifo(fdctrl, 4, 0);
2146 } else {
2147 fdctrl_reset_fifo(fdctrl);
2148 }
2149 } else if (fdctrl->data_len > 7) {
2150 /* ERROR */
2151 fdctrl->fifo[0] = 0x80 |
2152 (cur_drv->head << 2) | GET_CUR_DRV(fdctrl);
2153 fdctrl_set_fifo(fdctrl, 1, 0);
2154 }
2155}
2156
2157static void fdctrl_handle_relative_seek_out(fdctrl_t *fdctrl, int direction)
2158{
2159 fdrive_t *cur_drv;
2160
2161 SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
2162 cur_drv = get_cur_drv(fdctrl);
2163 if (fdctrl->fifo[2] + cur_drv->track >= cur_drv->max_track) {
2164 cur_drv->track = cur_drv->max_track - 1;
2165 } else {
2166 cur_drv->track += fdctrl->fifo[2];
2167 }
2168 fdctrl_reset_fifo(fdctrl);
2169 /* Raise Interrupt */
2170 fdctrl_raise_irq(fdctrl, FD_SR0_SEEK);
2171}
2172
2173static void fdctrl_handle_relative_seek_in(fdctrl_t *fdctrl, int direction)
2174{
2175 fdrive_t *cur_drv;
2176
2177 SET_CUR_DRV(fdctrl, fdctrl->fifo[1] & FD_DOR_SELMASK);
2178 cur_drv = get_cur_drv(fdctrl);
2179 if (fdctrl->fifo[2] > cur_drv->track) {
2180 cur_drv->track = 0;
2181 } else {
2182 cur_drv->track -= fdctrl->fifo[2];
2183 }
2184 fdctrl_reset_fifo(fdctrl);
2185 /* Raise Interrupt */
2186 fdctrl_raise_irq(fdctrl, FD_SR0_SEEK);
2187}
2188
2189static const struct {
2190 uint8_t value;
2191 uint8_t mask;
2192 const char* name;
2193 int parameters;
2194 void (*handler)(fdctrl_t *fdctrl, int direction);
2195 int direction;
2196} handlers[] = {
2197 { FD_CMD_READ, 0x1f, "READ", 8, fdctrl_start_transfer, FD_DIR_READ },
2198 { FD_CMD_WRITE, 0x3f, "WRITE", 8, fdctrl_start_transfer, FD_DIR_WRITE },
2199 { FD_CMD_SEEK, 0xff, "SEEK", 2, fdctrl_handle_seek },
2200 { FD_CMD_SENSE_INTERRUPT_STATUS, 0xff, "SENSE INTERRUPT STATUS", 0, fdctrl_handle_sense_interrupt_status },
2201 { FD_CMD_RECALIBRATE, 0xff, "RECALIBRATE", 1, fdctrl_handle_recalibrate },
2202 { FD_CMD_FORMAT_TRACK, 0xbf, "FORMAT TRACK", 5, fdctrl_handle_format_track },
2203 { FD_CMD_READ_TRACK, 0xbf, "READ TRACK", 8, fdctrl_start_transfer, FD_DIR_READ },
2204 { FD_CMD_RESTORE, 0xff, "RESTORE", 17, fdctrl_handle_restore }, /* part of READ DELETED DATA */
2205 { FD_CMD_SAVE, 0xff, "SAVE", 0, fdctrl_handle_save }, /* part of READ DELETED DATA */
2206 { FD_CMD_READ_DELETED, 0x1f, "READ DELETED DATA", 8, fdctrl_start_transfer_del, FD_DIR_READ },
2207 { FD_CMD_SCAN_EQUAL, 0x1f, "SCAN EQUAL", 8, fdctrl_start_transfer, FD_DIR_SCANE },
2208 { FD_CMD_VERIFY, 0x1f, "VERIFY", 8, fdctrl_unimplemented },
2209 { FD_CMD_SCAN_LOW_OR_EQUAL, 0x1f, "SCAN LOW OR EQUAL", 8, fdctrl_start_transfer, FD_DIR_SCANL },
2210 { FD_CMD_SCAN_HIGH_OR_EQUAL, 0x1f, "SCAN HIGH OR EQUAL", 8, fdctrl_start_transfer, FD_DIR_SCANH },
2211 { FD_CMD_WRITE_DELETED, 0x3f, "WRITE DELETED DATA", 8, fdctrl_start_transfer_del, FD_DIR_WRITE },
2212 { FD_CMD_READ_ID, 0xbf, "READ ID", 1, fdctrl_handle_readid },
2213 { FD_CMD_SPECIFY, 0xff, "SPECIFY", 2, fdctrl_handle_specify },
2214 { FD_CMD_SENSE_DRIVE_STATUS, 0xff, "SENSE DRIVE STATUS", 1, fdctrl_handle_sense_drive_status },
2215 { FD_CMD_PERPENDICULAR_MODE, 0xff, "PERPENDICULAR MODE", 1, fdctrl_handle_perpendicular_mode },
2216 { FD_CMD_CONFIGURE, 0xff, "CONFIGURE", 3, fdctrl_handle_configure },
2217 { FD_CMD_POWERDOWN_MODE, 0xff, "POWERDOWN MODE", 2, fdctrl_handle_powerdown_mode },
2218 { FD_CMD_OPTION, 0xff, "OPTION", 1, fdctrl_handle_option },
2219 { FD_CMD_DRIVE_SPECIFICATION_COMMAND, 0xff, "DRIVE SPECIFICATION COMMAND", 5, fdctrl_handle_drive_specification_command },
2220 { FD_CMD_RELATIVE_SEEK_OUT, 0xff, "RELATIVE SEEK OUT", 2, fdctrl_handle_relative_seek_out },
2221 { FD_CMD_FORMAT_AND_WRITE, 0xff, "FORMAT AND WRITE", 10, fdctrl_unimplemented },
2222 { FD_CMD_RELATIVE_SEEK_IN, 0xff, "RELATIVE SEEK IN", 2, fdctrl_handle_relative_seek_in },
2223 { FD_CMD_LOCK, 0x7f, "LOCK", 0, fdctrl_handle_lock },
2224 { FD_CMD_DUMPREG, 0xff, "DUMPREG", 0, fdctrl_handle_dumpreg },
2225 { FD_CMD_VERSION, 0xff, "VERSION", 0, fdctrl_handle_version },
2226 { FD_CMD_PART_ID, 0xff, "PART ID", 0, fdctrl_handle_partid },
2227 { FD_CMD_WRITE, 0x1f, "WRITE (BeOS)", 8, fdctrl_start_transfer, FD_DIR_WRITE }, /* not in specification ; BeOS 4.5 bug */
2228 { 0, 0, "unknown", 0, fdctrl_unimplemented }, /* default handler */
2229};
2230/* Associate command to an index in the 'handlers' array */
2231static uint8_t command_to_handler[256];
2232
2233static void fdctrl_write_data(fdctrl_t *fdctrl, uint32_t value)
2234{
2235 fdrive_t *cur_drv;
2236 int pos;
2237
2238 cur_drv = get_cur_drv(fdctrl);
2239 /* Reset mode */
2240 if (!(fdctrl->dor & FD_DOR_nRESET)) {
2241 FLOPPY_DPRINTF("Floppy controller in RESET state !\n");
2242 return;
2243 }
2244 if (!(fdctrl->msr & FD_MSR_RQM) || (fdctrl->msr & FD_MSR_DIO)) {
2245 FLOPPY_ERROR("controller not ready for writing\n");
2246 return;
2247 }
2248 fdctrl->dsr &= ~FD_DSR_PWRDOWN;
2249 /* Is it write command time ? */
2250 if (fdctrl->msr & FD_MSR_NONDMA) {
2251 /* FIFO data write */
2252 pos = fdctrl->data_pos++;
2253 pos %= FD_SECTOR_LEN;
2254 fdctrl->fifo[pos] = value;
2255 if (pos == FD_SECTOR_LEN - 1 ||
2256 fdctrl->data_pos == fdctrl->data_len) {
2257#ifdef VBOX
2258 blk_write(cur_drv, fd_sector(cur_drv), fdctrl->fifo, 1);
2259#else
2260 bdrv_write(cur_drv->bs, fd_sector(cur_drv),
2261 fdctrl->fifo, 1);
2262#endif
2263 }
2264 /* Switch from transfer mode to status mode
2265 * then from status mode to command mode
2266 */
2267 if (fdctrl->data_pos == fdctrl->data_len)
2268 fdctrl_stop_transfer(fdctrl, FD_SR0_SEEK, 0x00, 0x00);
2269 return;
2270 }
2271 if (fdctrl->data_pos == 0) {
2272 /* Command */
2273 fdctrl_reset_irq(fdctrl); /* If pending from previous seek/recalibrate. */
2274 pos = command_to_handler[value & 0xff];
2275 FLOPPY_DPRINTF("%s command\n", handlers[pos].name);
2276 fdctrl->data_len = handlers[pos].parameters + 1;
2277 fdctrl->msr |= FD_MSR_CMDBUSY;
2278 }
2279
2280 FLOPPY_DPRINTF("%s: %02x\n", __func__, value);
2281 fdctrl->fifo[fdctrl->data_pos++] = value;
2282 if (fdctrl->data_pos == fdctrl->data_len) {
2283 /* We now have all parameters
2284 * and will be able to treat the command
2285 */
2286 if (fdctrl->data_state & FD_STATE_FORMAT) {
2287 fdctrl_format_sector(fdctrl);
2288 return;
2289 }
2290
2291 pos = command_to_handler[fdctrl->fifo[0] & 0xff];
2292 FLOPPY_DPRINTF("treat %s command\n", handlers[pos].name);
2293 (*handlers[pos].handler)(fdctrl, handlers[pos].direction);
2294 }
2295}
2296
2297static void fdctrl_result_timer(void *opaque)
2298{
2299 fdctrl_t *fdctrl = (fdctrl_t *)opaque;
2300 fdrive_t *cur_drv = get_cur_drv(fdctrl);
2301
2302 /* Pretend we are spinning.
2303 * This is needed for Coherent, which uses READ ID to check for
2304 * sector interleaving.
2305 */
2306 if (cur_drv->last_sect != 0) {
2307 cur_drv->sect = (cur_drv->sect % cur_drv->last_sect) + 1;
2308 }
2309 /* READ_ID can't automatically succeed! */
2310#ifdef VBOX
2311 if (!cur_drv->max_track) {
2312 FLOPPY_DPRINTF("read id when no disk in drive\n");
2313 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_MA | FD_SR1_ND, FD_SR2_MD);
2314 } else if ((fdctrl->dsr & FD_DSR_DRATEMASK) != cur_drv->media_rate) {
2315 FLOPPY_DPRINTF("read id rate mismatch (fdc=%d, media=%d)\n",
2316 fdctrl->dsr & FD_DSR_DRATEMASK, cur_drv->media_rate);
2317 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_MA | FD_SR1_ND, FD_SR2_MD);
2318 } else if (cur_drv->track >= cur_drv->max_track) {
2319 FLOPPY_DPRINTF("read id past last track (%d >= %d)\n",
2320 cur_drv->track, cur_drv->max_track);
2321 cur_drv->ltrk = 0;
2322 fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM, FD_SR1_MA | FD_SR1_ND, FD_SR2_MD);
2323 }
2324 else
2325#endif
2326 fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00);
2327}
2328
2329
2330#ifdef VBOX
2331
2332/* -=-=-=-=-=-=-=-=- Timer Callback -=-=-=-=-=-=-=-=- */
2333
2334/**
2335 * @callback_method_impl{FNTMTIMERDEV}
2336 */
2337static DECLCALLBACK(void) fdcTimerCallback(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
2338{
2339 fdctrl_t *fdctrl = (fdctrl_t *)pvUser;
2340 fdctrl_result_timer(fdctrl);
2341}
2342
2343
2344/* -=-=-=-=-=-=-=-=- I/O Port Access Handlers -=-=-=-=-=-=-=-=- */
2345
2346/**
2347 * @callback_method_impl{FNIOMIOPORTOUT}
2348 */
2349static DECLCALLBACK(int) fdcIoPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
2350{
2351 if (cb == 1)
2352 fdctrl_write (pvUser, Port & 7, u32);
2353 else
2354 AssertMsgFailed(("Port=%#x cb=%d u32=%#x\n", Port, cb, u32));
2355 return VINF_SUCCESS;
2356}
2357
2358
2359/**
2360 * @callback_method_impl{FNIOMIOPORTOUT}
2361 */
2362static DECLCALLBACK(int) fdcIoPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
2363{
2364 if (cb == 1)
2365 {
2366 *pu32 = fdctrl_read (pvUser, Port & 7);
2367 return VINF_SUCCESS;
2368 }
2369 return VERR_IOM_IOPORT_UNUSED;
2370}
2371
2372
2373/* -=-=-=-=-=-=-=-=- Saved state -=-=-=-=-=-=-=-=- */
2374
2375/**
2376 * @callback_method_impl{FNSSMDEVSAVEEXEC}
2377 */
2378static DECLCALLBACK(int) fdcSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
2379{
2380 fdctrl_t *pThis = PDMINS_2_DATA(pDevIns, fdctrl_t *);
2381 unsigned int i;
2382
2383 /* Save the FDC I/O registers... */
2384 SSMR3PutU8(pSSM, pThis->sra);
2385 SSMR3PutU8(pSSM, pThis->srb);
2386 SSMR3PutU8(pSSM, pThis->dor);
2387 SSMR3PutU8(pSSM, pThis->tdr);
2388 SSMR3PutU8(pSSM, pThis->dsr);
2389 SSMR3PutU8(pSSM, pThis->msr);
2390 /* ...the status registers... */
2391 SSMR3PutU8(pSSM, pThis->status0);
2392 SSMR3PutU8(pSSM, pThis->status1);
2393 SSMR3PutU8(pSSM, pThis->status2);
2394 /* ...the command FIFO... */
2395 SSMR3PutU32(pSSM, sizeof(pThis->fifo));
2396 SSMR3PutMem(pSSM, &pThis->fifo, sizeof(pThis->fifo));
2397 SSMR3PutU32(pSSM, pThis->data_pos);
2398 SSMR3PutU32(pSSM, pThis->data_len);
2399 SSMR3PutU8(pSSM, pThis->data_state);
2400 SSMR3PutU8(pSSM, pThis->data_dir);
2401 /* ...and miscellaneous internal FDC state. */
2402 SSMR3PutU8(pSSM, pThis->reset_sensei);
2403 SSMR3PutU8(pSSM, pThis->eot);
2404 SSMR3PutU8(pSSM, pThis->timer0);
2405 SSMR3PutU8(pSSM, pThis->timer1);
2406 SSMR3PutU8(pSSM, pThis->precomp_trk);
2407 SSMR3PutU8(pSSM, pThis->config);
2408 SSMR3PutU8(pSSM, pThis->lock);
2409 SSMR3PutU8(pSSM, pThis->pwrd);
2410 SSMR3PutU8(pSSM, pThis->version);
2411
2412 /* Save the number of drives and per-drive state. Note that the media
2413 * states will be updated in fd_revalidate() and need not be saved.
2414 */
2415 SSMR3PutU8(pSSM, pThis->num_floppies);
2416 Assert(RT_ELEMENTS(pThis->drives) == pThis->num_floppies);
2417 for (i = 0; i < pThis->num_floppies; ++i)
2418 {
2419 fdrive_t *d = &pThis->drives[i];
2420
2421 SSMR3PutMem(pSSM, &d->Led, sizeof(d->Led));
2422 SSMR3PutU32(pSSM, d->drive);
2423 SSMR3PutU8(pSSM, d->dsk_chg);
2424 SSMR3PutU8(pSSM, d->perpendicular);
2425 SSMR3PutU8(pSSM, d->head);
2426 SSMR3PutU8(pSSM, d->track);
2427 SSMR3PutU8(pSSM, d->sect);
2428 }
2429 return TMR3TimerSave (pThis->result_timer, pSSM);
2430}
2431
2432
2433/**
2434 * @callback_method_impl{FNSSMDEVLOADEXEC}
2435 */
2436static DECLCALLBACK(int) fdcLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
2437{
2438 fdctrl_t *pThis = PDMINS_2_DATA(pDevIns, fdctrl_t *);
2439 unsigned int i;
2440 uint32_t val32;
2441 uint8_t val8;
2442
2443 if (uVersion > FDC_SAVESTATE_CURRENT)
2444 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
2445 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
2446
2447 /* The old saved state was significantly different. However, we can get
2448 * back most of the controller state and fix the rest by pretending the
2449 * disk in the drive (if any) has been replaced. At any rate there should
2450 * be no difficulty unless the state was saved during a floppy operation.
2451 */
2452 if (uVersion == FDC_SAVESTATE_OLD)
2453 {
2454 /* First verify a few assumptions. */
2455 AssertMsgReturn(sizeof(pThis->fifo) == FD_SECTOR_LEN,
2456 ("The size of FIFO in saved state doesn't match!\n"),
2457 VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
2458 AssertMsgReturn(RT_ELEMENTS(pThis->drives) == 2,
2459 ("The number of drives in old saved state doesn't match!\n"),
2460 VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
2461 /* Now load the old state. */
2462 SSMR3GetU8(pSSM, &pThis->version);
2463 /* Toss IRQ level, DMA channel, I/O base, and state. */
2464 SSMR3GetU8(pSSM, &val8);
2465 SSMR3GetU8(pSSM, &val8);
2466 SSMR3GetU32(pSSM, &val32);
2467 SSMR3GetU8(pSSM, &val8);
2468 /* Translate dma_en. */
2469 SSMR3GetU8(pSSM, &val8);
2470 if (val8)
2471 pThis->dor |= FD_DOR_DMAEN;
2472 SSMR3GetU8(pSSM, &pThis->cur_drv);
2473 /* Translate bootsel. */
2474 SSMR3GetU8(pSSM, &val8);
2475 pThis->tdr |= val8 << 2;
2476 SSMR3GetMem(pSSM, &pThis->fifo, FD_SECTOR_LEN);
2477 SSMR3GetU32(pSSM, &pThis->data_pos);
2478 SSMR3GetU32(pSSM, &pThis->data_len);
2479 SSMR3GetU8(pSSM, &pThis->data_state);
2480 SSMR3GetU8(pSSM, &pThis->data_dir);
2481 SSMR3GetU8(pSSM, &pThis->status0);
2482 SSMR3GetU8(pSSM, &pThis->eot);
2483 SSMR3GetU8(pSSM, &pThis->timer0);
2484 SSMR3GetU8(pSSM, &pThis->timer1);
2485 SSMR3GetU8(pSSM, &pThis->precomp_trk);
2486 SSMR3GetU8(pSSM, &pThis->config);
2487 SSMR3GetU8(pSSM, &pThis->lock);
2488 SSMR3GetU8(pSSM, &pThis->pwrd);
2489
2490 for (i = 0; i < 2; ++i)
2491 {
2492 fdrive_t *d = &pThis->drives[i];
2493
2494 SSMR3GetMem (pSSM, &d->Led, sizeof (d->Led));
2495 SSMR3GetU32(pSSM, &val32);
2496 d->drive = (fdrive_type_t)val32;
2497 SSMR3GetU32(pSSM, &val32); /* Toss drflags */
2498 SSMR3GetU8(pSSM, &d->perpendicular);
2499 SSMR3GetU8(pSSM, &d->head);
2500 SSMR3GetU8(pSSM, &d->track);
2501 SSMR3GetU8(pSSM, &d->sect);
2502 SSMR3GetU8(pSSM, &val8); /* Toss dir, rw */
2503 SSMR3GetU8(pSSM, &val8);
2504 SSMR3GetU32(pSSM, &val32);
2505 d->flags = (fdrive_flags_t)val32;
2506 SSMR3GetU8(pSSM, &d->last_sect);
2507 SSMR3GetU8(pSSM, &d->max_track);
2508 SSMR3GetU16(pSSM, &d->bps);
2509 SSMR3GetU8(pSSM, &d->ro);
2510 }
2511 }
2512 else /* New state - straightforward. */
2513 {
2514 Assert(uVersion == FDC_SAVESTATE_CURRENT);
2515 /* Load the FDC I/O registers... */
2516 SSMR3GetU8(pSSM, &pThis->sra);
2517 SSMR3GetU8(pSSM, &pThis->srb);
2518 SSMR3GetU8(pSSM, &pThis->dor);
2519 SSMR3GetU8(pSSM, &pThis->tdr);
2520 SSMR3GetU8(pSSM, &pThis->dsr);
2521 SSMR3GetU8(pSSM, &pThis->msr);
2522 /* ...the status registers... */
2523 SSMR3GetU8(pSSM, &pThis->status0);
2524 SSMR3GetU8(pSSM, &pThis->status1);
2525 SSMR3GetU8(pSSM, &pThis->status2);
2526 /* ...the command FIFO, if the size matches... */
2527 SSMR3GetU32(pSSM, &val32);
2528 AssertMsgReturn(sizeof(pThis->fifo) == val32,
2529 ("The size of FIFO in saved state doesn't match!\n"),
2530 VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
2531 SSMR3GetMem(pSSM, &pThis->fifo, sizeof(pThis->fifo));
2532 SSMR3GetU32(pSSM, &pThis->data_pos);
2533 SSMR3GetU32(pSSM, &pThis->data_len);
2534 SSMR3GetU8(pSSM, &pThis->data_state);
2535 SSMR3GetU8(pSSM, &pThis->data_dir);
2536 /* ...and miscellaneous internal FDC state. */
2537 SSMR3GetU8(pSSM, &pThis->reset_sensei);
2538 SSMR3GetU8(pSSM, &pThis->eot);
2539 SSMR3GetU8(pSSM, &pThis->timer0);
2540 SSMR3GetU8(pSSM, &pThis->timer1);
2541 SSMR3GetU8(pSSM, &pThis->precomp_trk);
2542 SSMR3GetU8(pSSM, &pThis->config);
2543 SSMR3GetU8(pSSM, &pThis->lock);
2544 SSMR3GetU8(pSSM, &pThis->pwrd);
2545 SSMR3GetU8(pSSM, &pThis->version);
2546
2547 /* Validate the number of drives. */
2548 SSMR3GetU8(pSSM, &pThis->num_floppies);
2549 AssertMsgReturn(RT_ELEMENTS(pThis->drives) == pThis->num_floppies,
2550 ("The number of drives in saved state doesn't match!\n"),
2551 VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
2552
2553 /* Load the per-drive state. */
2554 for (i = 0; i < pThis->num_floppies; ++i)
2555 {
2556 fdrive_t *d = &pThis->drives[i];
2557
2558 SSMR3GetMem(pSSM, &d->Led, sizeof(d->Led));
2559 SSMR3GetU32(pSSM, &val32);
2560 d->drive = (fdrive_type_t)val32;
2561 SSMR3GetU8(pSSM, &d->dsk_chg);
2562 SSMR3GetU8(pSSM, &d->perpendicular);
2563 SSMR3GetU8(pSSM, &d->head);
2564 SSMR3GetU8(pSSM, &d->track);
2565 SSMR3GetU8(pSSM, &d->sect);
2566 }
2567 }
2568 return TMR3TimerLoad (pThis->result_timer, pSSM);
2569}
2570
2571
2572/* -=-=-=-=-=-=-=-=- Drive level interfaces -=-=-=-=-=-=-=-=- */
2573
2574/**
2575 * @interface_method_impl{PDMIMOUNTNOTIFY,pfnMountNotify}
2576 */
2577static DECLCALLBACK(void) fdMountNotify(PPDMIMOUNTNOTIFY pInterface)
2578{
2579 fdrive_t *pDrv = RT_FROM_MEMBER(pInterface, fdrive_t, IMountNotify);
2580 LogFlow(("fdMountNotify:\n"));
2581 fd_revalidate(pDrv);
2582}
2583
2584
2585/**
2586 * @interface_method_impl{PDMIMOUNTNOTIFY,pfnUnmountNotify}
2587 */
2588static DECLCALLBACK(void) fdUnmountNotify(PPDMIMOUNTNOTIFY pInterface)
2589{
2590 fdrive_t *pDrv = RT_FROM_MEMBER(pInterface, fdrive_t, IMountNotify);
2591 LogFlow(("fdUnmountNotify:\n"));
2592 fd_revalidate(pDrv);
2593}
2594
2595
2596/**
2597 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
2598 */
2599static DECLCALLBACK(void *) fdQueryInterface (PPDMIBASE pInterface, const char *pszIID)
2600{
2601 fdrive_t *pDrv = RT_FROM_MEMBER(pInterface, fdrive_t, IBase);
2602
2603 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrv->IBase);
2604 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBLOCKPORT, &pDrv->IPort);
2605 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUNTNOTIFY, &pDrv->IMountNotify);
2606 return NULL;
2607}
2608
2609
2610/* -=-=-=-=-=-=-=-=- Controller level interfaces -=-=-=-=-=-=-=-=- */
2611
2612/**
2613 * @interface_method_impl{PDMILEDPORTS,pfnQueryStatusLed}
2614 */
2615static DECLCALLBACK(int) fdcStatusQueryStatusLed(PPDMILEDPORTS pInterface, unsigned iLUN, PPDMLED *ppLed)
2616{
2617 fdctrl_t *pThis = RT_FROM_MEMBER (pInterface, fdctrl_t, ILeds);
2618 if (iLUN < RT_ELEMENTS(pThis->drives)) {
2619 *ppLed = &pThis->drives[iLUN].Led;
2620 Assert ((*ppLed)->u32Magic == PDMLED_MAGIC);
2621 return VINF_SUCCESS;
2622 }
2623 return VERR_PDM_LUN_NOT_FOUND;
2624}
2625
2626
2627/**
2628 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
2629 */
2630static DECLCALLBACK(void *) fdcStatusQueryInterface(PPDMIBASE pInterface, const char *pszIID)
2631{
2632 fdctrl_t *pThis = RT_FROM_MEMBER (pInterface, fdctrl_t, IBaseStatus);
2633
2634 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis->IBaseStatus);
2635 PDMIBASE_RETURN_INTERFACE(pszIID, PDMILEDPORTS, &pThis->ILeds);
2636 return NULL;
2637}
2638
2639
2640/**
2641 * Configure a drive.
2642 *
2643 * @returns VBox status code.
2644 * @param drv The drive in question.
2645 * @param pDevIns The driver instance.
2646 * @param fInit Set if we're at init time and can change the drive type.
2647 */
2648static int fdConfig(fdrive_t *drv, PPDMDEVINS pDevIns, bool fInit)
2649{
2650 static const char * const s_apszDesc[] = {"Floppy Drive A:", "Floppy Drive B"};
2651 int rc;
2652
2653 /*
2654 * Reset the LED just to be on the safe side.
2655 */
2656 Assert (RT_ELEMENTS(s_apszDesc) > drv->iLUN);
2657 Assert (drv->Led.u32Magic == PDMLED_MAGIC);
2658 drv->Led.Actual.u32 = 0;
2659 drv->Led.Asserted.u32 = 0;
2660
2661 /*
2662 * Try attach the block device and get the interfaces.
2663 */
2664 rc = PDMDevHlpDriverAttach (pDevIns, drv->iLUN, &drv->IBase, &drv->pDrvBase, s_apszDesc[drv->iLUN]);
2665 if (RT_SUCCESS (rc)) {
2666 drv->pDrvBlock = PDMIBASE_QUERY_INTERFACE(drv->pDrvBase, PDMIBLOCK);
2667 if (drv->pDrvBlock) {
2668 drv->pDrvBlockBios = PDMIBASE_QUERY_INTERFACE(drv->pDrvBase, PDMIBLOCKBIOS);
2669 if (drv->pDrvBlockBios) {
2670 drv->pDrvMount = PDMIBASE_QUERY_INTERFACE(drv->pDrvBase, PDMIMOUNT);
2671 if (drv->pDrvMount) {
2672 fd_init(drv, fInit);
2673 } else {
2674 AssertMsgFailed (("Configuration error: LUN#%d without mountable interface!\n", drv->iLUN));
2675 rc = VERR_PDM_MISSING_INTERFACE;
2676 }
2677
2678 } else {
2679 AssertMsgFailed (("Configuration error: LUN#%d hasn't a block BIOS interface!\n", drv->iLUN));
2680 rc = VERR_PDM_MISSING_INTERFACE;
2681 }
2682
2683 } else {
2684 AssertMsgFailed (("Configuration error: LUN#%d hasn't a block interface!\n", drv->iLUN));
2685 rc = VERR_PDM_MISSING_INTERFACE;
2686 }
2687 } else {
2688 AssertMsg (rc == VERR_PDM_NO_ATTACHED_DRIVER,
2689 ("Failed to attach LUN#%d. rc=%Rrc\n", drv->iLUN, rc));
2690 switch (rc) {
2691 case VERR_ACCESS_DENIED:
2692 /* Error already cached by DrvHostBase */
2693 break;
2694 case VERR_PDM_NO_ATTACHED_DRIVER:
2695 /* Legal on architectures without a floppy controller */
2696 break;
2697 default:
2698 rc = PDMDevHlpVMSetError (pDevIns, rc, RT_SRC_POS,
2699 N_ ("The floppy controller cannot attach to the floppy drive"));
2700 break;
2701 }
2702 }
2703
2704 if (RT_FAILURE (rc)) {
2705 drv->pDrvBase = NULL;
2706 drv->pDrvBlock = NULL;
2707 drv->pDrvBlockBios = NULL;
2708 drv->pDrvMount = NULL;
2709 }
2710 LogFlow (("fdConfig: returns %Rrc\n", rc));
2711 return rc;
2712}
2713
2714
2715/**
2716 * @interface_method_impl{PDMDEVREG,pfnAttach}
2717 *
2718 * This is called when we change block driver for a floppy drive.
2719 */
2720static DECLCALLBACK(int) fdcAttach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
2721{
2722 fdctrl_t *fdctrl = PDMINS_2_DATA(pDevIns, fdctrl_t *);
2723 fdrive_t *drv;
2724 int rc;
2725 LogFlow (("ideDetach: iLUN=%u\n", iLUN));
2726
2727 AssertMsgReturn(fFlags & PDM_TACH_FLAGS_NOT_HOT_PLUG,
2728 ("The FDC device does not support hotplugging\n"),
2729 VERR_INVALID_PARAMETER);
2730
2731 /*
2732 * Validate.
2733 */
2734 if (iLUN >= 2) {
2735 AssertMsgFailed (("Configuration error: cannot attach or detach any but the first two LUNs - iLUN=%u\n",
2736 iLUN));
2737 return VERR_PDM_DEVINS_NO_ATTACH;
2738 }
2739
2740 /*
2741 * Locate the drive and stuff.
2742 */
2743 drv = &fdctrl->drives[iLUN];
2744
2745 /* the usual paranoia */
2746 AssertRelease (!drv->pDrvBase);
2747 AssertRelease (!drv->pDrvBlock);
2748 AssertRelease (!drv->pDrvBlockBios);
2749 AssertRelease (!drv->pDrvMount);
2750
2751 rc = fdConfig (drv, pDevIns, false /*fInit*/);
2752 AssertMsg (rc != VERR_PDM_NO_ATTACHED_DRIVER,
2753 ("Configuration error: failed to configure drive %d, rc=%Rrc\n", rc));
2754 if (RT_SUCCESS(rc)) {
2755 fd_revalidate (drv);
2756 }
2757
2758 LogFlow (("floppyAttach: returns %Rrc\n", rc));
2759 return rc;
2760}
2761
2762
2763/**
2764 * @interface_method_impl{PDMDEVREG,pfnDetach}
2765 *
2766 * The floppy drive has been temporarily 'unplugged'.
2767 */
2768static DECLCALLBACK(void) fdcDetach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
2769{
2770 fdctrl_t *pThis = PDMINS_2_DATA(pDevIns, fdctrl_t *);
2771 LogFlow (("ideDetach: iLUN=%u\n", iLUN));
2772
2773 switch (iLUN)
2774 {
2775 case 0:
2776 case 1:
2777 {
2778 fdrive_t *drv = &pThis->drives[iLUN];
2779 drv->pDrvBase = NULL;
2780 drv->pDrvBlock = NULL;
2781 drv->pDrvBlockBios = NULL;
2782 drv->pDrvMount = NULL;
2783 break;
2784 }
2785
2786 default:
2787 AssertMsgFailed(("Cannot detach LUN#%d!\n", iLUN));
2788 break;
2789 }
2790}
2791
2792
2793/**
2794 * @interface_method_impl{PDMDEVREG,pfnReset}
2795 *
2796 * I haven't check the specs on what's supposed to happen on reset, but we
2797 * should get any 'FATAL: floppy recal:f07 ctrl not ready' when resetting
2798 * at wrong time like we do if this was all void.
2799 */
2800static DECLCALLBACK(void) fdcReset(PPDMDEVINS pDevIns)
2801{
2802 fdctrl_t *pThis = PDMINS_2_DATA (pDevIns, fdctrl_t *);
2803 unsigned i;
2804 LogFlow (("fdcReset:\n"));
2805
2806 fdctrl_reset(pThis, 0);
2807
2808 for (i = 0; i < RT_ELEMENTS(pThis->drives); i++)
2809 fd_revalidate(&pThis->drives[i]);
2810}
2811
2812
2813/**
2814 * @interface_method_impl{PDMDEVREG,pfnConstruct}
2815 */
2816static DECLCALLBACK(int) fdcConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
2817{
2818 fdctrl_t *pThis = PDMINS_2_DATA(pDevIns, fdctrl_t *);
2819 int rc;
2820 unsigned i, j;
2821 int ii;
2822 bool mem_mapped;
2823 uint16_t io_base;
2824 uint8_t irq_lvl, dma_chann;
2825 PPDMIBASE pBase;
2826
2827 Assert(iInstance == 0);
2828 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
2829
2830 /*
2831 * Validate configuration.
2832 */
2833 if (!CFGMR3AreValuesValid(pCfg, "IRQ\0DMA\0MemMapped\0IOBase\0"))
2834 return VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES;
2835
2836 /*
2837 * Read the configuration.
2838 */
2839 rc = CFGMR3QueryU8Def(pCfg, "IRQ", &irq_lvl, 6);
2840 AssertMsgRCReturn(rc, ("Configuration error: Failed to read U8 IRQ, rc=%Rrc\n", rc), rc);
2841
2842 rc = CFGMR3QueryU8Def(pCfg, "DMA", &dma_chann, 2);
2843 AssertMsgRCReturn(rc, ("Configuration error: Failed to read U8 DMA, rc=%Rrc\n", rc), rc);
2844
2845 rc = CFGMR3QueryU16Def(pCfg, "IOBase", &io_base, 0x3f0);
2846 AssertMsgRCReturn(rc, ("Configuration error: Failed to read U16 IOBase, rc=%Rrc\n", rc), rc);
2847
2848 rc = CFGMR3QueryBoolDef(pCfg, "MemMapped", &mem_mapped, false);
2849 AssertMsgRCReturn(rc, ("Configuration error: Failed to read bool value MemMapped rc=%Rrc\n", rc), rc);
2850
2851 /*
2852 * Initialize data.
2853 */
2854 LogFlow(("fdcConstruct: irq_lvl=%d dma_chann=%d io_base=%#x\n", irq_lvl, dma_chann, io_base));
2855 pThis->pDevIns = pDevIns;
2856 pThis->version = 0x90; /* Intel 82078 controller */
2857 pThis->irq_lvl = irq_lvl;
2858 pThis->dma_chann = dma_chann;
2859 pThis->io_base = io_base;
2860 pThis->config = FD_CONFIG_EIS | FD_CONFIG_EFIFO; /* Implicit seek, polling & FIFO enabled */
2861 pThis->num_floppies = MAX_FD;
2862
2863 /* Fill 'command_to_handler' lookup table */
2864 for (ii = RT_ELEMENTS(handlers) - 1; ii >= 0; ii--)
2865 for (j = 0; j < sizeof(command_to_handler); j++)
2866 if ((j & handlers[ii].mask) == handlers[ii].value)
2867 command_to_handler[j] = ii;
2868
2869 pThis->IBaseStatus.pfnQueryInterface = fdcStatusQueryInterface;
2870 pThis->ILeds.pfnQueryStatusLed = fdcStatusQueryStatusLed;
2871
2872 for (i = 0; i < RT_ELEMENTS(pThis->drives); ++i)
2873 {
2874 fdrive_t *pDrv = &pThis->drives[i];
2875
2876 pDrv->drive = FDRIVE_DRV_NONE;
2877 pDrv->iLUN = i;
2878
2879 pDrv->IBase.pfnQueryInterface = fdQueryInterface;
2880 pDrv->IMountNotify.pfnMountNotify = fdMountNotify;
2881 pDrv->IMountNotify.pfnUnmountNotify = fdUnmountNotify;
2882 pDrv->Led.u32Magic = PDMLED_MAGIC;
2883 }
2884
2885 /*
2886 * Create the FDC timer.
2887 */
2888 rc = PDMDevHlpTMTimerCreate(pDevIns, TMCLOCK_VIRTUAL, fdcTimerCallback, pThis,
2889 TMTIMER_FLAGS_DEFAULT_CRIT_SECT, "FDC Timer", &pThis->result_timer);
2890 if (RT_FAILURE(rc))
2891 return rc;
2892
2893 /*
2894 * Register DMA channel.
2895 */
2896 if (pThis->dma_chann != 0xff)
2897 {
2898 rc = PDMDevHlpDMARegister(pDevIns, dma_chann, &fdctrl_transfer_handler, pThis);
2899 if (RT_FAILURE(rc))
2900 return rc;
2901 }
2902
2903 /*
2904 * IO / MMIO.
2905 */
2906 if (mem_mapped)
2907 {
2908 AssertMsgFailed(("Memory mapped floppy not support by now\n"));
2909 return VERR_NOT_SUPPORTED;
2910#if 0
2911 FLOPPY_ERROR("memory mapped floppy not supported by now !\n");
2912 io_mem = cpu_register_io_memory(0, fdctrl_mem_read, fdctrl_mem_write);
2913 cpu_register_physical_memory(base, 0x08, io_mem);
2914#endif
2915 }
2916 else
2917 {
2918 rc = PDMDevHlpIOPortRegister(pDevIns, io_base + 0x1, 5, pThis,
2919 fdcIoPortWrite, fdcIoPortRead, NULL, NULL, "FDC#1");
2920 if (RT_FAILURE(rc))
2921 return rc;
2922
2923 rc = PDMDevHlpIOPortRegister(pDevIns, io_base + 0x7, 1, pThis,
2924 fdcIoPortWrite, fdcIoPortRead, NULL, NULL, "FDC#2");
2925 if (RT_FAILURE(rc))
2926 return rc;
2927 }
2928
2929 /*
2930 * Register the saved state data unit.
2931 */
2932 rc = PDMDevHlpSSMRegister(pDevIns, FDC_SAVESTATE_CURRENT, sizeof(*pThis), fdcSaveExec, fdcLoadExec);
2933 if (RT_FAILURE(rc))
2934 return rc;
2935
2936 /*
2937 * Attach the status port (optional).
2938 */
2939 rc = PDMDevHlpDriverAttach(pDevIns, PDM_STATUS_LUN, &pThis->IBaseStatus, &pBase, "Status Port");
2940 if (RT_SUCCESS (rc))
2941 pThis->pLedsConnector = PDMIBASE_QUERY_INTERFACE(pBase, PDMILEDCONNECTORS);
2942 else if (rc != VERR_PDM_NO_ATTACHED_DRIVER)
2943 {
2944 AssertMsgFailed(("Failed to attach to status driver. rc=%Rrc\n", rc));
2945 return rc;
2946 }
2947
2948 /*
2949 * Initialize drives.
2950 */
2951 for (i = 0; i < RT_ELEMENTS(pThis->drives); i++)
2952 {
2953 fdrive_t *pDrv = &pThis->drives[i];
2954 rc = fdConfig(pDrv, pDevIns, true /*fInit*/);
2955 if ( RT_FAILURE(rc)
2956 && rc != VERR_PDM_NO_ATTACHED_DRIVER)
2957 {
2958 AssertMsgFailed(("Configuration error: failed to configure drive %d, rc=%Rrc\n", rc));
2959 return rc;
2960 }
2961 }
2962
2963 fdctrl_reset(pThis, 0);
2964
2965 for (i = 0; i < RT_ELEMENTS(pThis->drives); i++)
2966 fd_revalidate(&pThis->drives[i]);
2967
2968 return VINF_SUCCESS;
2969}
2970
2971
2972/**
2973 * The device registration structure.
2974 */
2975const PDMDEVREG g_DeviceFloppyController =
2976{
2977 /* u32Version */
2978 PDM_DEVREG_VERSION,
2979 /* szName */
2980 "i82078",
2981 /* szRCMod */
2982 "",
2983 /* szR0Mod */
2984 "",
2985 /* pszDescription */
2986 "Floppy drive controller (Intel 82078)",
2987 /* fFlags */
2988 PDM_DEVREG_FLAGS_DEFAULT_BITS,
2989 /* fClass */
2990 PDM_DEVREG_CLASS_STORAGE,
2991 /* cMaxInstances */
2992 1,
2993 /* cbInstance */
2994 sizeof(fdctrl_t),
2995 /* pfnConstruct */
2996 fdcConstruct,
2997 /* pfnDestruct */
2998 NULL,
2999 /* pfnRelocate */
3000 NULL,
3001 /* pfnMemSetup */
3002 NULL,
3003 /* pfnPowerOn */
3004 NULL,
3005 /* pfnReset */
3006 fdcReset,
3007 /* pfnSuspend */
3008 NULL,
3009 /* pfnResume */
3010 NULL,
3011 /* pfnAttach */
3012 fdcAttach,
3013 /* pfnDetach */
3014 fdcDetach,
3015 /* pfnQueryInterface. */
3016 NULL,
3017 /* pfnInitComplete */
3018 NULL,
3019 /* pfnPowerOff */
3020 NULL,
3021 /* pfnSoftReset */
3022 NULL,
3023 /* u32VersionEnd */
3024 PDM_DEVREG_VERSION
3025};
3026
3027#endif /* VBOX */
3028
3029/*
3030 * Local Variables:
3031 * mode: c
3032 * c-file-style: "k&r"
3033 * indent-tabs-mode: nil
3034 * End:
3035 */
3036
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette