Skip to contentSkip to conversation

Add fdc emulation continued...

PATCH New J. Mayer 1 participant 1 message Nov 13, 2003 Kbuild

lore
Share & tools
lore

J. Mayer

author
#0 lore raw

PATCH 1/1 Add fdc emulation continued...

Here are the patches that make floppy disk emulation available for everyone.
If you feel fdc.c make sense, please apply those patches while adding it to repository.

Makefile.target +0 -0
@@ -176,7 +180,7 @@ ifeq ($(ARCH),alpha)
 endif
 
 # must use static linking to avoid leaving stuff in virtual address

space
-VL_OBJS=vl.o block.o ide.o vga.o sb16.o dma.o oss.o +VL_OBJS=vl.o block.o ide.o vga.o sb16.o fdc.o dma.o oss.o
ifdef CONFIG_SDL
VL_OBJS+=sdl.o
SDL_LIBS+=-L/usr/X11R6/lib -lX11 -lXext -lXv -ldl -lm

vl.c +13 -1
@@ -50,6 +50,8 @@
 
 #include "vl.h"
 
+#define USE_FLOPPY
+
 #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
 #define BIOS_FILENAME "bios.bin"
 #define VGABIOS_FILENAME "vgabios.bin"
@@ -205,7 +210,7 @@ CPUX86State *global_env;
 CPUX86State *cpu_single_env;
 IOPortReadFunc *ioport_read_table[3][MAX_IOPORTS];
 IOPortWriteFunc *ioport_write_table[3][MAX_IOPORTS];
-BlockDriverState *bs_table[MAX_DISKS];
+BlockDriverState *bs_table[MAX_DISKS], *fd_table[MAX_FD];
 int vga_ram_size;
 static DisplayState display_state;
 int nographic;
@@ -529,10 +534,24 @@ void cmos_init(void)
     cmos_data[0x34] = val;
     cmos_data[0x35] = val >> 8;
     
+    /* First floppy drive */
+#ifdef USE_FLOPPY
+#if 0
+    cmos_data[0x10] |= 0x50; // 2.88 Mo drive
+    cmos_data[0x10] |= 0x05; // 2.88 Mo drive
+#else
+    cmos_data[0x10] |= 0x40; // 1.44 Mo drive
+    cmos_data[0x10] |= 0x04; // 1.44 Mo drive
+#endif
+    cmos_data[REG_EQUIPMENT_BYTE] |= 0x41; /* 2 drives, ready for boot

*/
+#endif
+

     switch(boot_device) {
+#ifdef USE_FLOPPY
     case 'a':
         cmos_data[0x3d] = 0x01; /* floppy boot */
         break;
+#endif
     default:
     case 'c':
         cmos_data[0x3d] = 0x02; /* hard drive boot */

@@ -1859,6 +1878,40 @@ void ne2000_init(void)
}

/***********************************************************/
+/* PC floppy disk controler emulation glue */
+#define PC_FDC_DMA 0x2
+#define PC_FDC_IRQ 0x0E
+
+#ifdef USE_FLOPPY
+static void fdctrl_ioport_write(CPUX86State *env, uint32_t addr, uint32_t val)
+{
+ fdctrl_write_register(addr & 0xF, val);
+}
+
+static uint32_t fdctrl_ioport_read(CPUX86State *env, uint32_t addr) +{
+ return fdctrl_read_register(addr & 0xF);
+}
+#endif
+
+static void fdctrl_register (unsigned char **disknames, int ro) +{
+#ifdef USE_FLOPPY
+ int i;
+
+ fdctrl_init(PC_FDC_IRQ, PC_FDC_DMA);
+ for (i = 0; i < MAX_FD; i++) {
+ if (disknames[i] != NULL)
+ fdctrl_disk_change(i, disknames[i], ro);

+    }
+    register_ioport_read(0x3F1, 5, fdctrl_ioport_read, 1);
+    register_ioport_write(0x3F1, 5, fdctrl_ioport_write, 1);
+    /* The digital input register is read-only */
+    register_ioport_read(0x3F7, 1, fdctrl_ioport_read, 1);

+#endif
+}
+ +/***********************************************************/
/* keyboard emulation */

/* Keyboard Controller Commands */
@@ -2750,6 +2803,8 @@ void help(void)
"'disk_image' is a raw hard image image for IDE hard disk
0\n"

            "\n"
            "Standard options:\n"
+           "-fda file       use 'file' as floppy disk 0 image\n"
+           "-fdb file       use 'file' as floppy disk 1 image\n"
            "-hda/-hdb file  use 'file' as IDE hard disk 0/1 image\n"
            "-hdc/-hdd file  use 'file' as IDE hard disk 2/3 image\n"
            "-cdrom file     use 'file' as IDE cdrom 2 image\n"
@@ -2804,6 +2859,8 @@ struct option long_options[] = {
     { "hdd", 1, NULL, 0, },
     { "cdrom", 1, NULL, 0, },
     { "boot", 1, NULL, 0, },
+    { "fda", 1, NULL, 0, },
+    { "fdb", 1, NULL, 0, },
     { NULL, 0, NULL, 0 },

};

@@ -2828,13 +2885,15 @@ int main(int argc, char **argv)

     struct itimerval itv;
     CPUX86State *env;
     const char *initrd_filename;
-    const char *hd_filename[MAX_DISKS];
+    const char *hd_filename[MAX_DISKS], *fd_filename[MAX_FD];
     const char *kernel_filename, *kernel_cmdline;
     DisplayState *ds = &display_state;
 
     /* we never want that malloc() uses mmap() */
     mallopt(M_MMAP_THRESHOLD, 4096 * 1024);
     initrd_filename = NULL;
+    for(i = 0; i < MAX_FD; i++)
+        fd_filename[i] = NULL;
     for(i = 0; i < MAX_DISKS; i++)
         hd_filename[i] = NULL;
     phys_ram_size = 32 * 1024 * 1024;
@@ -2909,11 +2968,18 @@ int main(int argc, char **argv)
                 break;
             case 12:
                 boot_device = optarg[0];

- if (boot_device != 'c' && boot_device != 'd') {
+ if (boot_device != 'a' && boot_device != 'c' &&
+ boot_device != 'd') {
fprintf(stderr, "qemu: invalid boot device '%c'\n",

boot_device);
                     exit(1);
                 }
                 break;

+ case 13:
+ fd_filename[0] = optarg;
+ break;
+ case 14:
+ fd_filename[1] = optarg;

+                break;
             }
             break;
         case 'h':

@@ -2953,7 +3019,8 @@ int main(int argc, char **argv)

     linux_boot = (kernel_filename != NULL);

- if (!linux_boot && hd_filename[0] == '\0' && hd_filename[2] ==
'\0')
+ if (!linux_boot && hd_filename[0] == '\0' && hd_filename[2] == '\0'
&&
+ fd_filename[0] == '\0')

         help();
 
     /* init debug */
@@ -3158,7 +3225,7 @@ int main(int argc, char **argv)
     AUD_init();
     DMA_init();
     SB16_init();
-    
+    fdctrl_register((unsigned char **)fd_filename, snapshot);
     /* setup cpu signal handlers for MMU / self modifying code handling
*/
     sigfillset(&act.sa_mask);
     act.sa_flags = SA_SIGINFO;
vl.h +6 -0
@@ -143,5 +143,13 @@ void DMA_register_channel (int nchan,
 /* sb16.c */
 void SB16_run (void);
 void SB16_init (void);
+
+/* fdc.c */
+#define MAX_FD 2
+extern BlockDriverState *fd_table[MAX_FD];
+void fdctrl_init (int irq_lvl, int dma_chann);
+int fdctrl_disk_change (int idx, const unsigned char *filename, int

ro);
+void fdctrl_write_register (uint32_t reg, uint32_t value); +uint32_t fdctrl_read_register (uint32_t reg);

#endif /* VL_H */

Signature · 2 lines
J. Mayer <[email protected]>
Never organized