From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1H0bMx-00008Z-QB for qemu-devel@nongnu.org; Sat, 30 Dec 2006 05:23:16 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1H0bMu-00005O-NQ for qemu-devel@nongnu.org; Sat, 30 Dec 2006 05:23:14 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1H0bMt-0008Vg-H5 for qemu-devel@nongnu.org; Sat, 30 Dec 2006 05:23:12 -0500 Received: from [212.227.126.179] (helo=moutng.kundenserver.de) by monty-python.gnu.org with esmtp (Exim 4.52) id 1H0bMs-0005hJ-S9 for qemu-devel@nongnu.org; Sat, 30 Dec 2006 05:23:11 -0500 From: Volker Ruppert Date: Sat, 30 Dec 2006 11:24:35 +0100 MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_k5jlFLc4mqBHojW" Message-Id: <200612301124.36125.info@vruppert.de> Subject: [Qemu-devel] Some patches for QEMU Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Qemu Devel --Boundary-00=_k5jlFLc4mqBHojW Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi all, I have created a set of patches for QEMU. Here is the list of changes: * updated block driver for Bochs 2.3 "growing" images. The change was necessary to fix the alignment of 64-bit values on different platforms (e.g. it wasn't possible to share images between Windows and Linux). * fixed comment in the floppy emulation code. The Bochs BIOS format function and the Linux fdformat utility are expecting DMA operations here. * fixed hard disk translation hint when an image formatted with translation active is detected. * standard and Cirrus VGA: implemented vertical retrace timing instead of just toggling the register bits. * implemented refresh clock toggle every 15 usec (used by INT 15h, AH=86h). Please let me know when you need test cases for the changes. -- Thanks Volker --Boundary-00=_k5jlFLc4mqBHojW Content-Type: text/x-diff; charset="us-ascii"; name="patch.qemu-block-bochs" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="patch.qemu-block-bochs" diff -urNX /home/volker/exclude-qemu /home/volker/qemu/block-bochs.c ./block-bochs.c --- /home/volker/qemu/block-bochs.c 2006-08-01 19:04:41.000000000 +0200 +++ ./block-bochs.c 2006-12-30 09:58:56.908199376 +0100 @@ -28,7 +28,8 @@ /**************************************************************/ #define HEADER_MAGIC "Bochs Virtual HD Image" -#define HEADER_VERSION 0x00010000 +#define HEADER_VERSION 0x00020000 +#define HEADER_V1 0x00010000 #define HEADER_SIZE 512 #define REDOLOG_TYPE "Redolog" @@ -37,7 +38,7 @@ // not allocated: 0xffffffff // always little-endian -struct bochs_header { +struct bochs_header_v1 { char magic[32]; // "Bochs Virtual HD Image" char type[16]; // "Redolog" char subtype[16]; // "Undoable" / "Volatile" / "Growing" @@ -56,6 +57,27 @@ } extra; }; +// always little-endian +struct bochs_header { + char magic[32]; // "Bochs Virtual HD Image" + char type[16]; // "Redolog" + char subtype[16]; // "Undoable" / "Volatile" / "Growing" + uint32_t version; + uint32_t header; // size of header + + union { + struct { + uint32_t catalog; // num of entries + uint32_t bitmap; // bitmap size + uint32_t extent; // extent size + uint32_t reserved; // for ??? + uint64_t disk; // disk size + char padding[HEADER_SIZE - 64 - 8 - 24]; + } redolog; + char padding[HEADER_SIZE - 64 - 8]; + } extra; +}; + typedef struct BDRVBochsState { int fd; @@ -79,7 +101,8 @@ if (!strcmp(bochs->magic, HEADER_MAGIC) && !strcmp(bochs->type, REDOLOG_TYPE) && !strcmp(bochs->subtype, GROWING_TYPE) && - (le32_to_cpu(bochs->version) == HEADER_VERSION)) + ((le32_to_cpu(bochs->version) == HEADER_VERSION) || + (le32_to_cpu(bochs->version) == HEADER_V1))) return 100; return 0; @@ -90,6 +113,7 @@ BDRVBochsState *s = bs->opaque; int fd, i; struct bochs_header bochs; + struct bochs_header_v1 header_v1; fd = open(filename, O_RDWR | O_BINARY); if (fd < 0) { @@ -109,11 +133,17 @@ if (strcmp(bochs.magic, HEADER_MAGIC) || strcmp(bochs.type, REDOLOG_TYPE) || strcmp(bochs.subtype, GROWING_TYPE) || - (le32_to_cpu(bochs.version) != HEADER_VERSION)) { + ((le32_to_cpu(bochs.version) != HEADER_VERSION) && + (le32_to_cpu(bochs.version) != HEADER_V1))) { goto fail; } - bs->total_sectors = le64_to_cpu(bochs.extra.redolog.disk) / 512; + if (le32_to_cpu(bochs.version) == HEADER_V1) { + memcpy(&header_v1, &bochs, sizeof(bochs)); + bs->total_sectors = le64_to_cpu(header_v1.extra.redolog.disk) / 512; + } else { + bs->total_sectors = le64_to_cpu(bochs.extra.redolog.disk) / 512; + } lseek(s->fd, le32_to_cpu(bochs.header), SEEK_SET); --Boundary-00=_k5jlFLc4mqBHojW Content-Type: text/x-diff; charset="us-ascii"; name="patch.qemu-fdc-comment" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="patch.qemu-fdc-comment" diff -urNX /home/volker/exclude-qemu /home/volker/qemu/hw/fdc.c ./hw/fdc.c --- /home/volker/qemu/hw/fdc.c 2006-12-11 13:20:25.000000000 +0100 +++ ./hw/fdc.c 2006-12-30 10:48:07.831590832 +0100 @@ -1673,8 +1673,9 @@ #else cur_drv->last_sect = fdctrl->fifo[3]; #endif - /* Bochs BIOS is buggy and don't send format informations - * for each sector. So, pretend all's done right now... + /* 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); --Boundary-00=_k5jlFLc4mqBHojW Content-Type: text/x-diff; charset="us-ascii"; name="patch.qemu-hd-translation" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="patch.qemu-hd-translation" diff -urNX /home/volker/exclude-qemu /home/volker/qemu/hw/ide.c ./hw/ide.c --- /home/volker/qemu/hw/ide.c 2006-12-22 09:01:06.000000000 +0100 +++ ./hw/ide.c 2006-12-30 10:36:29.307782592 +0100 @@ -2069,7 +2069,7 @@ { IDEState *s; static int drive_serial = 1; - int i, cylinders, heads, secs, translation; + int i, cylinders, heads, secs, translation, lba_detected = 0; int64_t nb_sectors; for(i = 0; i < 2; i++) { @@ -2083,6 +2083,7 @@ s->nb_sectors = nb_sectors; /* if a geometry hint is available, use it */ bdrv_get_geometry_hint(s->bs, &cylinders, &heads, &secs); + translation = bdrv_get_translation_hint(s->bs); if (cylinders != 0) { s->cylinders = cylinders; s->heads = heads; @@ -2093,6 +2094,7 @@ /* if heads > 16, it means that a BIOS LBA translation was active, so the default hardware geometry is OK */ + lba_detected = 1; goto default_geometry; } else { s->cylinders = cylinders; @@ -2100,7 +2102,6 @@ s->sectors = secs; /* disable any translation to be in sync with the logical geometry */ - translation = bdrv_get_translation_hint(s->bs); if (translation == BIOS_ATA_TRANSLATION_AUTO) { bdrv_set_translation_hint(s->bs, BIOS_ATA_TRANSLATION_NONE); @@ -2117,6 +2118,15 @@ s->cylinders = cylinders; s->heads = 16; s->sectors = 63; + if ((lba_detected == 1) && (translation == BIOS_ATA_TRANSLATION_AUTO)) { + if ((s->cylinders * s->heads) <= 131072) { + bdrv_set_translation_hint(s->bs, + BIOS_ATA_TRANSLATION_LARGE); + } else { + bdrv_set_translation_hint(s->bs, + BIOS_ATA_TRANSLATION_LBA); + } + } } bdrv_set_geometry_hint(s->bs, s->cylinders, s->heads, s->sectors); } diff -urNX /home/volker/exclude-qemu /home/volker/qemu/vl.h ./vl.h --- /home/volker/qemu/vl.h 2006-12-25 09:12:41.000000000 +0100 +++ ./vl.h 2006-12-30 10:59:39.773399688 +0100 @@ -592,9 +592,11 @@ #define BDRV_TYPE_HD 0 #define BDRV_TYPE_CDROM 1 #define BDRV_TYPE_FLOPPY 2 -#define BIOS_ATA_TRANSLATION_AUTO 0 -#define BIOS_ATA_TRANSLATION_NONE 1 -#define BIOS_ATA_TRANSLATION_LBA 2 +#define BIOS_ATA_TRANSLATION_AUTO 0 +#define BIOS_ATA_TRANSLATION_NONE 1 +#define BIOS_ATA_TRANSLATION_LBA 2 +#define BIOS_ATA_TRANSLATION_LARGE 3 +#define BIOS_ATA_TRANSLATION_RECHS 4 void bdrv_set_geometry_hint(BlockDriverState *bs, int cyls, int heads, int secs); --Boundary-00=_k5jlFLc4mqBHojW Content-Type: text/x-diff; charset="us-ascii"; name="patch.qemu-timers" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="patch.qemu-timers" diff -urNX /home/volker/exclude-qemu /home/volker/qemu/hw/cirrus_vga.c ./hw/cirrus_vga.c --- /home/volker/qemu/hw/cirrus_vga.c 2006-08-18 17:48:26.000000000 +0200 +++ ./hw/cirrus_vga.c 2006-10-01 19:18:43.721496136 +0200 @@ -2649,11 +2649,18 @@ break; case 0x3ba: case 0x3da: - /* just toggle to fool polling */ - s->st01 ^= ST01_V_RETRACE | ST01_DISP_ENABLE; - val = s->st01; - s->ar_flip_flop = 0; - break; + { + uint64_t usec; + usec = muldiv64(qemu_get_clock(vm_clock), 1000000, ticks_per_sec); + if ((usec % 13888) < 70) { + s->st01 |= ST01_V_RETRACE | ST01_DISP_ENABLE; + } else { + s->st01 = 0; + } + val = s->st01; + s->ar_flip_flop = 0; + } + break; default: val = 0x00; break; diff -urNX /home/volker/exclude-qemu /home/volker/qemu/hw/pcspk.c ./hw/pcspk.c --- /home/volker/qemu/hw/pcspk.c 2006-07-05 01:20:54.000000000 +0200 +++ ./hw/pcspk.c 2006-10-01 19:28:43.952247192 +0200 @@ -38,7 +38,7 @@ unsigned int samples; unsigned int play_pos; int data_on; - int dummy_refresh_clock; + int refresh_clock; } PCSpkState; static const char *s_spk = "pcspk"; @@ -117,10 +117,10 @@ PCSpkState *s = opaque; int out; - s->dummy_refresh_clock ^= (1 << 4); + s->refresh_clock = (((qemu_get_clock(vm_clock) / 15000) & 1) << 4); out = pit_get_out(s->pit, 2, qemu_get_clock(vm_clock)) << 5; - return pit_get_gate(s->pit, 2) | (s->data_on << 1) | s->dummy_refresh_clock | out; + return pit_get_gate(s->pit, 2) | (s->data_on << 1) | s->refresh_clock | out; } static void pcspk_ioport_write(void *opaque, uint32_t addr, uint32_t val) diff -urNX /home/volker/exclude-qemu /home/volker/qemu/hw/vga.c ./hw/vga.c --- /home/volker/qemu/hw/vga.c 2006-09-26 18:04:22.000000000 +0200 +++ ./hw/vga.c 2006-10-01 19:17:09.377838552 +0200 @@ -223,10 +223,17 @@ break; case 0x3ba: case 0x3da: - /* just toggle to fool polling */ - s->st01 ^= ST01_V_RETRACE | ST01_DISP_ENABLE; - val = s->st01; - s->ar_flip_flop = 0; + { + uint64_t usec; + usec = muldiv64(qemu_get_clock(vm_clock), 1000000, ticks_per_sec); + if ((usec % 13888) < 70) { + s->st01 |= ST01_V_RETRACE | ST01_DISP_ENABLE; + } else { + s->st01 = 0; + } + val = s->st01; + s->ar_flip_flop = 0; + } break; default: val = 0x00; --Boundary-00=_k5jlFLc4mqBHojW--