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