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 1AM1Ky-0005IE-HS for qemu-devel@nongnu.org; Tue, 18 Nov 2003 03:35:52 -0500 Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AM1KK-0004Lk-0M for qemu-devel@nongnu.org; Tue, 18 Nov 2003 03:35:43 -0500 Received: from [62.210.158.41] (helo=moscou.magic.fr) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AM1KG-0004G9-SP for qemu-devel@nongnu.org; Tue, 18 Nov 2003 03:35:09 -0500 Received: from 10.0.0.2 (ppp-181.net-555.magic.fr [62.210.255.181]) by moscou.magic.fr (8.11.6/8.10.1) with ESMTP id hAI7XfO02776 for ; Tue, 18 Nov 2003 08:33:41 +0100 (CET) Subject: Re: [Qemu-devel] [ADD] floppy disk emulation From: "J. Mayer" In-Reply-To: <1069140120.13658.2160.camel@rapid> References: <20031117105133.7e856e56.Jens.Arm@gmx.de> <1069140120.13658.2160.camel@rapid> Content-Type: text/plain Message-Id: <1069141105.13658.2196.camel@rapid> Mime-Version: 1.0 Date: 18 Nov 2003 08:38:25 +0100 Content-Transfer-Encoding: 7bit Reply-To: qemu-devel@nongnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org vl.c.diff Add helper to register floppy drives in CMOS memory. Make qemu able to boot from floppy Add floppy init. diff -urNbB -x CVS qemu-current/vl.c qemu/vl.c --- qemu-current/vl.c Tue Nov 18 06:51:10 2003 +++ qemu/vl.c Tue Nov 18 02:19:33 2003 @@ -49,6 +50,8 @@ #include "thunk.h" #include "vl.h" + +#define USE_FLOPPY #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup" #define BIOS_FILENAME "bios.bin" @@ -210,7 +217,7 @@ 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; @@ -577,9 +584,12 @@ cmos_data[0x35] = val >> 8; switch(boot_device) { +#ifdef USE_FLOPPY case 'a': + case 'b': cmos_data[0x3d] = 0x01; /* floppy boot */ break; +#endif default: case 'c': cmos_data[0x3d] = 0x02; /* hard drive boot */ @@ -593,6 +603,57 @@ register_ioport_read(0x70, 2, cmos_ioport_read, 1); } +#ifdef USE_FLOPPY +void cmos_register_fd (uint8_t fd0, uint8_t fd1) +{ + int nb = 0; + + cmos_data[0x10] = 0; + switch (fd0) { + case 0: + /* 1.44 Mb 3"5 drive */ + cmos_data[0x10] |= 0x40; + break; + case 1: + /* 2.88 Mb 3"5 drive */ + cmos_data[0x10] |= 0x60; + break; + case 2: + /* 1.2 Mb 5"5 drive */ + cmos_data[0x10] |= 0x20; + break; + } + switch (fd1) { + case 0: + /* 1.44 Mb 3"5 drive */ + cmos_data[0x10] |= 0x04; + break; + case 1: + /* 2.88 Mb 3"5 drive */ + cmos_data[0x10] |= 0x06; + break; + case 2: + /* 1.2 Mb 5"5 drive */ + cmos_data[0x10] |= 0x02; + break; + } + if (fd0 < 3) + nb++; + if (fd1 < 3) + nb++; + switch (nb) { + case 0: + break; + case 1: + cmos_data[REG_EQUIPMENT_BYTE] |= 0x01; /* 1 drive, ready for boot */ + break; + case 2: + cmos_data[REG_EQUIPMENT_BYTE] |= 0x41; /* 2 drives, ready for boot */ + break; + } +} +#endif + /***********************************************************/ /* 8259 pic emulation */ @@ -1952,6 +2127,26 @@ } /***********************************************************/ +/* PC floppy disk controler emulation glue */ +#define PC_FDC_DMA 0x2 +#define PC_FDC_IRQ 0x6 +#define PC_FDC_BASE 0x3F0 + +static void fdctrl_register (unsigned char **disknames, int ro, + char boot_device) +{ +#ifdef USE_FLOPPY + int i; + + fdctrl_init(PC_FDC_IRQ, PC_FDC_DMA, 0, PC_FDC_BASE, boot_device); + for (i = 0; i < MAX_FD; i++) { + if (disknames[i] != NULL) + fdctrl_disk_change(i, disknames[i], ro); + } +#endif +} + +/***********************************************************/ /* keyboard emulation */ /* Keyboard Controller Commands */ @@ -2853,6 +3053,8 @@ "'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" @@ -2907,6 +3109,8 @@ { "hdd", 1, NULL, 0, }, { "cdrom", 1, NULL, 0, }, { "boot", 1, NULL, 0, }, + { "fda", 1, NULL, 0, }, + { "fdb", 1, NULL, 0, }, { NULL, 0, NULL, 0 }, }; @@ -2931,13 +3135,15 @@ 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; @@ -3012,11 +3218,18 @@ break; case 12: boot_device = optarg[0]; - if (boot_device != 'c' && boot_device != 'd') { + if (boot_device != 'a' && boot_device != 'b' && + 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': @@ -3056,7 +3269,8 @@ 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(); /* boot to cd by default if no hard disk */ @@ -3268,7 +3482,8 @@ AUD_init(); DMA_init(); SB16_init(); + fdctrl_register((unsigned char **)fd_filename, snapshot, boot_device); /* setup cpu signal handlers for MMU / self modifying code handling */ sigfillset(&act.sa_mask); act.sa_flags = SA_SIGINFO;