22 static inline void wait_execution(
struct fdc_context *ctx)
24 volatile unsigned char reg;
30 static inline int send_byte(
struct fdc_context *ctx,
unsigned char byte)
43 static inline int read_byte(
struct fdc_context *ctx,
unsigned char *byte)
55 static inline int configure(
struct fdc_context *ctx)
64 ret = send_byte(ctx, 0);
69 ret = send_byte(ctx, 0x20 | 0x10 | 0x01);
74 ret = send_byte(ctx, 0);
86 static inline int sense_interrupt(
struct fdc_context *ctx,
87 unsigned char *st0,
unsigned char *cyl)
97 ret = read_byte(ctx, st0);
109 ret = read_byte(ctx, cyl);
117 static inline int calibrate(
struct fdc_context *ctx)
135 assert(sem &&
"Invalid sem");
138 ret = sense_interrupt(ctx, &st0, &cyl);
139 assert((st0 & 0x20) &&
"Failed to calibrate");
140 if (ret < 0 || cyl != 0) {
163 ret = send_byte(ctx, ((srt & 0x0F) << 4) | (hut & 0xf));
168 ret = send_byte(ctx, (hlt << 1) | !
DMA);
181 static inline int dump_reg(
struct fdc_context *ctx)
191 static inline void decode_status(
unsigned long status)
193 static const char *interrupt_code[] = {
194 "Normal termination",
195 "Abnormal termination",
197 "Abnormal caused by polling",
200 static const char *drive[] = {
207 printf(
"IC: %s\n", interrupt_code[status >> 30]);
208 printf(
"Seek: %s\n", ((status >> 29) & 0x01) ?
"End" :
"None");
209 printf(
"Head: %d\n", ((status >> 26) & 0x01));
210 printf(
"Drive: %s\n", drive[(status >> 24) & 0x03]);
211 printf(
"End of cylinder: %s\n",
212 ((status >> 23) & 0x01) ?
"True" :
"False");
215 #define dump_reg(ctx)
216 #define decode_status(status)
219 static inline int fdc_reset(
struct fdc_context *ctx)
231 assert(sem &&
"Invalid sem");
236 for (i = 0; i < 4; i++) {
237 ret = sense_interrupt(ctx, &st0, &cyl);
258 ret = configure(ctx);
268 ret = calibrate(ctx);
290 ret = send_byte(ctx, cyl);
296 assert(sem &&
"Invalid sem");
299 ret = sense_interrupt(ctx, &st0, &_cyl);
300 assert((st0 & 0x20) &&
"Failed to seek");
312 ret = send_byte(ctx, 0x80 |
CMD_LOCK);
318 ret = read_byte(ctx, &byte);
323 return (byte & 0x10) == 0x10 ? 0 : -
EIO;
337 ret = read_byte(ctx, &byte);
342 return (byte & 0x10) == 0x10 ? 0 : -
EIO;
364 ret = send_byte(ctx, c);
369 ret = send_byte(ctx, h);
374 ret = send_byte(ctx, r);
385 ret = send_byte(ctx, r);
390 ret = send_byte(ctx, 27);
395 ret = send_byte(ctx, 0xFF);
401 assert(sem &&
"Invalid sem");
404 ret = read_byte(ctx, &byte);
409 ret = read_byte(ctx, &byte);
414 ret = read_byte(ctx, &byte);
419 ret = read_byte(ctx, &byte);
424 ret = read_byte(ctx, &byte);
429 ret = read_byte(ctx, &byte);
434 ret = read_byte(ctx, &byte);
460 assert(sem &&
"Invalid sem");
463 ret = read_byte(ctx, &byte);
468 ret = read_byte(ctx, &byte);
473 ret = read_byte(ctx, &byte);
478 ret = read_byte(ctx, &byte);
483 ret = read_byte(ctx, &byte);
488 ret = read_byte(ctx, &byte);
493 ret = read_byte(ctx, &byte);
520 ret = send_byte(ctx, c);
525 ret = send_byte(ctx, h);
530 ret = send_byte(ctx, r);
545 ret = send_byte(ctx, r);
550 ret = send_byte(ctx, 0x1B);
555 ret = send_byte(ctx, 0xFF);
561 assert(sem &&
"Invalid sem");
564 ret = read_byte(ctx, &byte);
569 ret = read_byte(ctx, &byte);
575 assert(!
"Floppy had too few sectors");
578 assert(!
"Too slow to get byte in or out of FIFO port");
582 ret = read_byte(ctx, &byte);
587 ret = read_byte(ctx, &byte);
592 ret = read_byte(ctx, &byte);
597 ret = read_byte(ctx, &byte);
602 ret = read_byte(ctx, &byte);
603 assert((byte == 2) &&
"result != 2");
613 unsigned char c,
unsigned char h,
unsigned char r)
630 ret = send_byte(ctx, c);
635 ret = send_byte(ctx, h);
640 ret = send_byte(ctx, r);
651 ret = send_byte(ctx, r);
656 ret = send_byte(ctx, 0x1B);
661 ret = send_byte(ctx, 0xFF);
667 assert(sem &&
"Invalid sem");
670 ret = read_byte(ctx, &byte);
675 ret = read_byte(ctx, &byte);
681 assert(!
"Floppy had too few sectors");
684 assert(!
"Too slow to get byte in or out of FIFO port");
687 assert(!
"Write protected");
691 ret = read_byte(ctx, &byte);
696 ret = read_byte(ctx, &byte);
701 ret = read_byte(ctx, &byte);
706 ret = read_byte(ctx, &byte);
711 ret = read_byte(ctx, &byte);
721 unsigned char c,
unsigned char h,
unsigned char r)
738 ret = send_byte(ctx, c);
743 ret = send_byte(ctx, h);
748 ret = send_byte(ctx, r);
759 ret = send_byte(ctx, r);
764 ret = send_byte(ctx, 0x1B);
769 ret = send_byte(ctx, 0xFF);
775 assert(sem &&
"Invalid sem");
778 ret = read_byte(ctx, &byte);
783 ret = read_byte(ctx, &byte);
788 ret = read_byte(ctx, &byte);
793 ret = read_byte(ctx, &byte);
798 ret = read_byte(ctx, &byte);
803 ret = read_byte(ctx, &byte);
808 ret = read_byte(ctx, &byte);
818 unsigned char c,
unsigned char h,
unsigned char r)
834 ret = send_byte(ctx, c);
839 ret = send_byte(ctx, h);
844 ret = send_byte(ctx, r);
855 ret = send_byte(ctx, r);
860 ret = send_byte(ctx, 0x1B);
865 ret = send_byte(ctx, 0xFF);
871 assert(sem &&
"Invalid sem");
874 ret = read_byte(ctx, &byte);
879 ret = read_byte(ctx, &byte);
884 ret = read_byte(ctx, &byte);
889 ret = read_byte(ctx, &byte);
894 ret = read_byte(ctx, &byte);
899 ret = read_byte(ctx, &byte);
904 ret = read_byte(ctx, &byte);
914 unsigned char c,
unsigned char h,
unsigned char r)
931 ret = send_byte(ctx, c);
936 ret = send_byte(ctx, h);
941 ret = send_byte(ctx, r);
947 ret = send_byte(ctx, r);
952 ret = send_byte(ctx, 0x1B);
957 ret = send_byte(ctx, 0xFF);
963 assert(sem &&
"Invalid sem");
966 ret = read_byte(ctx, &byte);
971 ret = read_byte(ctx, &byte);
976 ret = read_byte(ctx, &byte);
981 ret = read_byte(ctx, &byte);
986 ret = read_byte(ctx, &byte);
991 ret = read_byte(ctx, &byte);
996 ret = read_byte(ctx, &byte);
1015 ret = read_byte(ctx, ver);
1063 if (ret < 0 || ver != 0x90) {
1064 assert(ver == 0x90 &&
"Not supported FDC");