From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AKNr5-0007ml-7X for qemu-devel@nongnu.org; Thu, 13 Nov 2003 15:14:15 -0500 Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AKNqZ-0007eC-2U for qemu-devel@nongnu.org; Thu, 13 Nov 2003 15:14:14 -0500 Received: from [62.210.158.45] (helo=quito.magic.fr) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AKNqY-0007dy-K8 for qemu-devel@nongnu.org; Thu, 13 Nov 2003 15:13:42 -0500 Received: from 10.0.0.2 (ppp-181.net-555.magic.fr [62.210.255.181]) by quito.magic.fr (8.11.6/8.11.2) with ESMTP id hADJCGF29951 for ; Thu, 13 Nov 2003 20:12:16 +0100 (CET) From: "J. Mayer" Content-Type: text/plain Message-Id: <1068750997.1696.215.camel@rapid> Mime-Version: 1.0 Date: 13 Nov 2003 20:16:38 +0100 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH] Add fdc emulation continued... Reply-To: qemu-devel@nongnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 13 Nov 2003 01:46:15 -0000 1.10 +++ Makefile.target 13 Nov 2003 19:01:20 -0000 @@ -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 Nov 2003 01:45:57 -0000 1.31 +++ vl.c 13 Nov 2003 19:01:30 -0000 @@ -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 13 Nov 2003 01:45:57 -0000 1.6 +++ vl.h 13 Nov 2003 19:01:30 -0000 @@ -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 */ -- J. Mayer Never organized